1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

restructure interfaces

This commit is contained in:
Ahmed Ali 2020-06-17 11:31:01 +02:00
parent de09819278
commit 04c75d9314
19 changed files with 316 additions and 322 deletions

View File

@ -1,7 +1,7 @@
import { URL } from 'whatwg-url'
import { DDO } from '../ddo/DDO'
import DID from '../ocean/DID'
import { EditableMetaData } from '../ddo/MetaData'
import { EditableMetadata } from '../ddo/interfaces/EditableMetadata'
import { Logger } from '../utils'
import { WebServiceConnector } from '../ocean/utils/WebServiceConnector'
@ -318,14 +318,14 @@ export class Aquarius {
/**
* Edit Metadata for a DDO.
* @param {did} string DID.
* @param {newMetadata} EditableMetaData Metadata fields & new values.
* @param {newMetadata} EditableMetadata Metadata fields & new values.
* @param {String} updated Updated field of the DDO
* @param {String} signature Signature using updated field to verify that the consumer has rights
* @return {Promise<String>} Result.
*/
public async editMetadata(
did: DID | string,
newMetadata: EditableMetaData,
newMetadata: EditableMetadata,
updated: string,
signature: string
): Promise<string> {

View File

@ -1,15 +1,14 @@
import { File, MetaDataAlgorithm } from '../ddo/MetaData'
import Account from '../ocean/Account'
import { noZeroX, noDidPrefixed } from '../utils'
import { noZeroX } from '../utils'
import { Instantiable, InstantiableConfig } from '../Instantiable.abstract'
import { DDO } from '../ddo/DDO'
import { ServiceType } from '../ddo/Service'
const apiPath = '/api/v1/brizo/services'
/**
* Provides a interface with Brizo.
* Brizo is the technical component executed by the Publishers allowing to them to provide extended data services.
* Provides an interface for provider service.
* Provider service is the technical component executed
* by the Publishers allowing to them to provide extended
* data services.
*/
export class Brizo extends Instantiable {
private get url() {

View File

@ -1,8 +1,8 @@
import { Ocean } from '../ocean/Ocean'
import { Authentication } from './Authentication'
import { Proof } from './Proof'
import { PublicKey } from './PublicKey'
import { Service, ServiceType } from './Service'
import { Authentication } from './interfaces/Authentication'
import { Proof } from './interfaces/Proof'
import { PublicKey } from './interfaces/PublicKey'
import { Service, ServiceType } from './interfaces/Service'
/**
* DID Descriptor Object.

View File

@ -1,303 +0,0 @@
export interface File {
/**
* File name.
* @type {string}
*/
name?: string
/**
* File URL.
* @type {string}
*/
url: string
/**
* File index.
* @type {number}
*/
index?: number
/**
* File format, if applicable.
* @type {string}
* @example "text/csv"
*/
contentType: string
/**
* File checksum.
* @type {[type]}
*/
checksum?: string
/**
* Checksum hash algorithm.
* @type {[type]}
*/
checksumType?: string
/**
* File content length.
* @type {[type]}
*/
contentLength?: string
/**
* Resource ID (depending on the source).
* @type {[type]}
*/
resourceId?: string
/**
* File encoding.
* @type {string}
* @example "UTF-8"
*/
encoding?: string
/**
* File compression (e.g. no, gzip, bzip2, etc).
* @type {string}
* @example "zip"
*/
compression?: string
}
export interface MetaDataAlgorithm {
url?: string
rawcode?: string
language?: string
format?: string
version?: string
container: {
entrypoint: string
image: string
tag: string
}
}
/**
* Main attributes of assets metadata.
* @see https://github.com/oceanprotocol/OEPs/tree/master/8
*/
export interface MetaDataMain {
/**
* Descriptive name of the Asset.
* @type {string}
* @example "UK Weather information 2011"
*/
name: string
/**
* Type of the Asset. Helps to filter by the type of asset ("dataset" or "algorithm").
* @type {string}
* @example "dataset"
*/
type: 'dataset' | 'algorithm'
/**
* The date on which the asset was created by the originator in
* ISO 8601 format, Coordinated Universal Time.
* @type {string}
* @example "2019-01-31T08:38:32Z"
*/
dateCreated: string
/**
* The date on which the asset DDO was registered into the metadata store.
* This value is created automatically by Aquarius upon registering,
* so this value can't be set.
* @type {string}
* @example "2019-01-31T08:38:32Z"
*/
datePublished?: string
/**
* Name of the entity generating this data (e.g. Tfl, Disney Corp, etc.).
* @type {string}
* @example "Met Office"
*/
author: string
/**
* Short name referencing the license of the asset (e.g. Public Domain, CC-0, CC-BY, No License Specified, etc. ).
* If it's not specified, the following value will be added: "No License Specified".
* @type {string}
* @example "CC-BY"
*/
license: string
/**
* Price of the asset in vodka (attoOCEAN). It must be an integer encoded as a string.
* @type {string}
* @example "1000000000000000000"
*/
price: string
/**
* Array of File objects including the encrypted file urls and some additional information.
* @type {File[]}
*/
files: File[]
/**
* Metadata used only for assets with type `algorithm`.
* @type {MetaDataAlgorithm}
*/
algorithm?: MetaDataAlgorithm
}
/**
* Curation attributes of Assets Metadata.
* @see https://github.com/oceanprotocol/OEPs/tree/master/8
*/
export interface Curation {
/**
* Decimal value between 0 and 1. 0 is the default value.
* @type {number}
* @example 0.93
*/
rating: number
/**
* Number of votes. 0 is the default value.
* @type {number}
* @example 123
*/
numVotes: number
/**
* Schema applied to calculate the rating.
* @type {string}
* @example "Binary Voting"
*/
schema?: string
/**
* Flag unsuitable content.
* @type {boolean}
* @example true
*/
isListed?: boolean
}
/**
* Additional Information of Assets Metadata.
* @see https://github.com/oceanprotocol/OEPs/tree/master/8#additional-information
*/
export interface AdditionalInformation {
/**
* Details of what the resource is. For a dataset, this attribute
* explains what the data represents and what it can be used for.
* @type {string}
* @example "Weather information of UK including temperature and humidity"
*/
description?: string
/**
* The party holding the legal copyright. Empty by default.
* @type {string}
* @example "Met Office"
*/
copyrightHolder?: string
/**
* Example of the concept of this asset. This example is part
* of the metadata, not an external link.
* @type {string}
* @example "423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68"
*/
workExample?: string
/**
* Mapping of links for data samples, or links to find out more information.
* Links may be to either a URL or another Asset. We expect marketplaces to
* converge on agreements of typical formats for linked data: The Ocean Protocol
* itself does not mandate any specific formats as these requirements are likely
* to be domain-specific.
* @type {any[]}
* @example
* [
* {
* anotherSample: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/",
* },
* {
* fieldsDescription: "http://data.ceda.ac.uk/badc/ukcp09/",
* },
* ]
*/
links?: { [name: string]: string }[]
/**
* The language of the content. Please use one of the language
* codes from the {@link https://tools.ietf.org/html/bcp47 IETF BCP 47 standard}.
* @type {String}
* @example "en"
*/
inLanguage?: string
/**
* Categories used to describe this content. Empty by default.
* @type {string[]}
* @example ["Economy", "Data Science"]
*/
categories?: string[]
/**
* Keywords or tags used to describe this content. Empty by default.
* @type {string[]}
* @example ["weather", "uk", "2011", "temperature", "humidity"]
*/
tags?: string[]
/**
* An indication of update latency - i.e. How often are updates expected (seldom,
* annually, quarterly, etc.), or is the resource static that is never expected
* to get updated.
* @type {string}
* @example "yearly"
*/
updateFrequency?: string
/**
* A link to machine-readable structured markup (such as ttl/json-ld/rdf)
* describing the dataset.
* @type {StructuredMarkup[]}
*/
structuredMarkup?: {
uri: string
mediaType: string
}[]
}
export interface MetaData {
main: MetaDataMain
encryptedFiles?: string
additionalInformation?: AdditionalInformation
curation?: Curation
}
/** Warning. serviceIndex is the index of a services in Services array, and not service.index attribute.
Let's assume that you have the following services array:
[
{"index":1,"type":"access","main":{"price":3}},
{"index":0,"type":"compute","main":{"price":1}}
]
then calling update with { serviceIndex:1,price:2} will update the 'compute' service, and not the access one
**/
export interface ServicePrices {
serviceIndex: number
price: string
}
export interface EditableMetaDataLinks {
name: string
url: string
type: string
}
export interface EditableMetaData {
description?: string
title?: string
links?: EditableMetaDataLinks[]
servicePrices?: ServicePrices[]
}

View File

@ -0,0 +1,88 @@
/**
* Additional Information of Assets Metadata.
* @see https://github.com/oceanprotocol/OEPs/tree/master/8#additional-information
*/
export interface AdditionalInformation {
/**
* Details of what the resource is. For a dataset, this attribute
* explains what the data represents and what it can be used for.
* @type {string}
* @example "Weather information of UK including temperature and humidity"
*/
description?: string
/**
* The party holding the legal copyright. Empty by default.
* @type {string}
* @example "Met Office"
*/
copyrightHolder?: string
/**
* Example of the concept of this asset. This example is part
* of the metadata, not an external link.
* @type {string}
* @example "423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68"
*/
workExample?: string
/**
* Mapping of links for data samples, or links to find out more information.
* Links may be to either a URL or another Asset. We expect marketplaces to
* converge on agreements of typical formats for linked data: The Ocean Protocol
* itself does not mandate any specific formats as these requirements are likely
* to be domain-specific.
* @type {any[]}
* @example
* [
* {
* anotherSample: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/",
* },
* {
* fieldsDescription: "http://data.ceda.ac.uk/badc/ukcp09/",
* },
* ]
*/
links?: { [name: string]: string }[]
/**
* The language of the content. Please use one of the language
* codes from the {@link https://tools.ietf.org/html/bcp47 IETF BCP 47 standard}.
* @type {String}
* @example "en"
*/
inLanguage?: string
/**
* Categories used to describe this content. Empty by default.
* @type {string[]}
* @example ["Economy", "Data Science"]
*/
categories?: string[]
/**
* Keywords or tags used to describe this content. Empty by default.
* @type {string[]}
* @example ["weather", "uk", "2011", "temperature", "humidity"]
*/
tags?: string[]
/**
* An indication of update latency - i.e. How often are updates expected (seldom,
* annually, quarterly, etc.), or is the resource static that is never expected
* to get updated.
* @type {string}
* @example "yearly"
*/
updateFrequency?: string
/**
* A link to machine-readable structured markup (such as ttl/json-ld/rdf)
* describing the dataset.
* @type {StructuredMarkup[]}
*/
structuredMarkup?: {
uri: string
mediaType: string
}[]
}

View File

@ -0,0 +1,33 @@
/**
* Curation attributes of Assets Metadata.
* @see https://github.com/oceanprotocol/OEPs/tree/master/8
*/
export interface Curation {
/**
* Decimal value between 0 and 1. 0 is the default value.
* @type {number}
* @example 0.93
*/
rating: number
/**
* Number of votes. 0 is the default value.
* @type {number}
* @example 123
*/
numVotes: number
/**
* Schema applied to calculate the rating.
* @type {string}
* @example "Binary Voting"
*/
schema?: string
/**
* Flag unsuitable content.
* @type {boolean}
* @example true
*/
isListed?: boolean
}

View File

@ -0,0 +1,9 @@
import { EditableMetadataLinks } from './EditableMetadataLinks'
import { ServicePrices } from './ServicePrices'
export interface EditableMetadata {
description?: string
title?: string
links?: EditableMetadataLinks[]
servicePrices?: ServicePrices[]
}

View File

@ -0,0 +1,5 @@
export interface EditableMetadataLinks {
name: string
url: string
type: string
}

View File

@ -0,0 +1,64 @@
export interface File {
/**
* File name.
* @type {string}
*/
name?: string
/**
* File URL.
* @type {string}
*/
url: string
/**
* File index.
* @type {number}
*/
index?: number
/**
* File format, if applicable.
* @type {string}
* @example "text/csv"
*/
contentType: string
/**
* File checksum.
* @type {[type]}
*/
checksum?: string
/**
* Checksum hash algorithm.
* @type {[type]}
*/
checksumType?: string
/**
* File content length.
* @type {[type]}
*/
contentLength?: string
/**
* Resource ID (depending on the source).
* @type {[type]}
*/
resourceId?: string
/**
* File encoding.
* @type {string}
* @example "UTF-8"
*/
encoding?: string
/**
* File compression (e.g. no, gzip, bzip2, etc).
* @type {string}
* @example "zip"
*/
compression?: string
}

View File

@ -0,0 +1,10 @@
import { MetadataMain } from './MetadataMain'
import { AdditionalInformation } from './AdditionalInformation'
import { Curation } from './Curation'
export interface Metadata {
main: MetadataMain
encryptedFiles?: string
additionalInformation?: AdditionalInformation
curation?: Curation
}

View File

@ -0,0 +1,12 @@
export interface MetadataAlgorithm {
url?: string
rawcode?: string
language?: string
format?: string
version?: string
container: {
entrypoint: string
image: string
tag: string
}
}

View File

@ -0,0 +1,73 @@
import { MetadataAlgorithm } from './MetadataAlgorithm'
import { File } from './File'
/**
* Main attributes of assets metadata.
* @see https://github.com/oceanprotocol/OEPs/tree/master/8
*/
export interface MetadataMain {
/**
* Descriptive name of the Asset.
* @type {string}
* @example "UK Weather information 2011"
*/
name: string
/**
* Type of the Asset. Helps to filter by the type of asset ("dataset" or "algorithm").
* @type {string}
* @example "dataset"
*/
type: 'dataset' | 'algorithm'
/**
* The date on which the asset was created by the originator in
* ISO 8601 format, Coordinated Universal Time.
* @type {string}
* @example "2019-01-31T08:38:32Z"
*/
dateCreated: string
/**
* The date on which the asset DDO was registered into the metadata store.
* This value is created automatically by Aquarius upon registering,
* so this value can't be set.
* @type {string}
* @example "2019-01-31T08:38:32Z"
*/
datePublished?: string
/**
* Name of the entity generating this data (e.g. Tfl, Disney Corp, etc.).
* @type {string}
* @example "Met Office"
*/
author: string
/**
* Short name referencing the license of the asset (e.g. Public Domain, CC-0, CC-BY, No License Specified, etc. ).
* If it's not specified, the following value will be added: "No License Specified".
* @type {string}
* @example "CC-BY"
*/
license: string
/**
* Price of the asset in vodka (attoOCEAN). It must be an integer encoded as a string.
* @type {string}
* @example "1000000000000000000"
*/
price: string
/**
* Array of File objects including the encrypted file urls and some additional information.
* @type {File[]}
*/
files: File[]
/**
* Metadata used only for assets with type `algorithm`.
* @type {MetaDataAlgorithm}
*/
algorithm?: MetadataAlgorithm
}

View File

@ -1,4 +1,4 @@
import { MetaData } from './MetaData'
import { Metadata } from './Metadata'
export type ServiceType = 'authorization' | 'metadata' | 'access' | 'compute'
@ -69,7 +69,7 @@ export interface ServiceComputeProvider {
export interface ServiceMetadata extends ServiceCommon {
type: 'metadata'
attributes: MetaData
attributes: Metadata
}
export interface ServiceAccess extends ServiceCommon {

View File

@ -0,0 +1,4 @@
export interface ServicePrices {
serviceIndex: number
price: string
}

View File

@ -11,7 +11,7 @@ import * as utils from './utils'
// Exports
export * from './ddo/DDO'
export * from './ddo/MetaData'
export * from './ddo/interfaces/Metadata'
export { CreateProgressStep, OrderProgressStep } from './ocean/Assets'

View File

@ -1,8 +1,8 @@
import { TransactionReceipt } from 'web3-core'
import { SearchQuery } from '../aquarius/Aquarius'
import { DDO } from '../ddo/DDO'
import { MetaData, EditableMetaData } from '../ddo/MetaData'
import { Service, ServiceAccess, ServiceComputePrivacy } from '../ddo/Service'
import { Metadata } from '../ddo/interfaces/Metadata'
import { Service } from '../ddo/interfaces/Service'
import Account from './Account'
import DID from './DID'
import { SubscribablePromise, didZeroX } from '../utils'
@ -63,7 +63,7 @@ export class Assets extends Instantiable {
* @return {Promise<DDO>}
*/
public create(
metadata: MetaData,
metadata: Metadata,
publisher: Account,
services: Service[] = [],
dtAddress?: string