Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search assets filter using multiple types #618

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
12 changes: 2 additions & 10 deletions src/ddo/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Babysig,
NFTServiceAttributes,
NFTAttributes,
AssetType,
} from '../models'

export interface Authentication {
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions src/models/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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..
Expand Down
14 changes: 9 additions & 5 deletions src/nevermined/api/SearchApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Instantiable, InstantiableConfig } from '../../Instantiable.abstract'
import { QueryResult } from '../../services'
import {
Account,
AssetType,
DID,
didPrefixed,
EventOptions,
Expand Down Expand Up @@ -631,8 +632,9 @@ export class SearchApi extends Instantiable {
*
* @returns {@link Promise<QueryResult>}
*/
public async datasetsByNftContract(
public async assetsByNftContract(
nftContractAddress: string,
assetTypes: AssetType[] = [AssetType.dataset],
nftType?: NeverminedNFT721Type | NeverminedNFT1155Type,
tokenId?: string,
customNestedQueries?: SearchQuery['query'][],
Expand Down Expand Up @@ -674,8 +676,8 @@ export class SearchApi extends Instantiable {
},
},
{
match: {
'service.attributes.main.type': 'dataset',
terms: {
'service.attributes.main.type': assetTypes,
},
},
],
Expand Down Expand Up @@ -741,8 +743,9 @@ export class SearchApi extends Instantiable {
*
* @returns {@link Promise<QueryResult>}
*/
public async datasetsBySubscription(
public async assetsBySubscription(
subscriptionDid: string,
assetTypes: AssetType[] = [AssetType.dataset],
nftType?: NeverminedNFT721Type | NeverminedNFT1155Type,
customNestedQueries?: SearchQuery['query'][],
offset = 100,
Expand All @@ -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,
Expand Down
Loading