From da5b48e2d289d64667e33a0f819a08ad3eed5d52 Mon Sep 17 00:00:00 2001 From: Aitor <1726644+aaitor@users.noreply.github.com> Date: Wed, 29 Nov 2023 15:53:10 +0100 Subject: [PATCH] fix: filtering by multiple asset types --- package.json | 2 +- src/ddo/types.ts | 12 ++---------- src/models/types.ts | 12 ++++++++++++ src/nevermined/api/SearchApi.ts | 14 +++++++++----- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 2ec36b4d9..bcad86491 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nevermined-io/sdk", - "version": "2.0.7", + "version": "2.0.8", "description": "Javascript SDK for connecting with Nevermined Data Platform ", "main": "./dist/node/sdk.js", "typings": "./dist/node/sdk.d.ts", diff --git a/src/ddo/types.ts b/src/ddo/types.ts index 799d16967..e6db50009 100644 --- a/src/ddo/types.ts +++ b/src/ddo/types.ts @@ -7,6 +7,7 @@ import { Babysig, NFTServiceAttributes, NFTAttributes, + AssetType, } from '../models' export interface Authentication { @@ -240,16 +241,7 @@ export interface MetaDataMain { * initially ("dataset", "algorithm", "compute", "workflow", "model", "file", "subscription", "other"). * @example "dataset" */ - type: - | 'dataset' - | 'algorithm' - | 'compute' - | 'workflow' - | 'service' - | 'subscription' - | 'model' - | 'file' - | 'other' + type: AssetType /** * Sub type asssociated to the main type of the asset. This subtype is open so final users are not restricted to use anything they need. diff --git a/src/models/types.ts b/src/models/types.ts index 654ceb655..995aa1bbe 100644 --- a/src/models/types.ts +++ b/src/models/types.ts @@ -51,6 +51,18 @@ export const defaultNeverminedNFTType = { 1155: NeverminedNFT1155Type.nft1155, } +export enum AssetType { + dataset = 'dataset', + algorithm = 'algorithm', + compute = 'compute', + workflow = 'workflow', + service = 'service', + subscription = 'subscription', + model = 'model', + file = 'file', + other = 'other', +} + export enum ValueType { DID, // DID string e.g. 'did:nv:xxx' DIDRef, // hash of DID same as in parameter (bytes32 _did) in text 0x0123abc.. or 0123abc.. diff --git a/src/nevermined/api/SearchApi.ts b/src/nevermined/api/SearchApi.ts index 8fb482eb5..c5cb0b7cb 100644 --- a/src/nevermined/api/SearchApi.ts +++ b/src/nevermined/api/SearchApi.ts @@ -3,6 +3,7 @@ import { Instantiable, InstantiableConfig } from '../../Instantiable.abstract' import { QueryResult } from '../../services' import { Account, + AssetType, DID, didPrefixed, EventOptions, @@ -631,8 +632,9 @@ export class SearchApi extends Instantiable { * * @returns {@link Promise} */ - public async datasetsByNftContract( + public async assetsByNftContract( nftContractAddress: string, + assetTypes: AssetType[] = [AssetType.dataset], nftType?: NeverminedNFT721Type | NeverminedNFT1155Type, tokenId?: string, customNestedQueries?: SearchQuery['query'][], @@ -674,8 +676,8 @@ export class SearchApi extends Instantiable { }, }, { - match: { - 'service.attributes.main.type': 'dataset', + terms: { + 'service.attributes.main.type': assetTypes, }, }, ], @@ -741,8 +743,9 @@ export class SearchApi extends Instantiable { * * @returns {@link Promise} */ - public async datasetsBySubscription( + public async assetsBySubscription( subscriptionDid: string, + assetTypes: AssetType[] = [AssetType.dataset], nftType?: NeverminedNFT721Type | NeverminedNFT1155Type, customNestedQueries?: SearchQuery['query'][], offset = 100, @@ -767,8 +770,9 @@ export class SearchApi extends Instantiable { const nftContractAddress = DDO.getNftContractAddressFromService(nftSalesService) - return this.datasetsByNftContract( + return this.assetsByNftContract( nftContractAddress, + assetTypes, nftType, subscriptionDid.replace('did:nv:', ''), customNestedQueries,