mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
replace aquarius with metadatastore
This commit is contained in:
parent
89891baa50
commit
d751b47a5f
2
package-lock.json
generated
2
package-lock.json
generated
@ -11917,7 +11917,7 @@
|
||||
"backoff": "^2.5.0",
|
||||
"clone": "^2.0.0",
|
||||
"cross-fetch": "^2.1.0",
|
||||
"eth-block-tracker": "^3.0.0",
|
||||
"eth-block-tracker": "^4.2.0",
|
||||
"eth-json-rpc-infura": "^3.1.0",
|
||||
"eth-sig-util": "^1.4.2",
|
||||
"ethereumjs-block": "^1.2.2",
|
||||
|
14
src/lib.ts
14
src/lib.ts
@ -3,7 +3,7 @@ import Account from './ocean/Account'
|
||||
import DID from './ocean/DID'
|
||||
import { Ocean } from './ocean/Ocean'
|
||||
import { LoggerInstance as Logger } from './utils/Logger'
|
||||
import { Aquarius } from './aquarius/Aquarius'
|
||||
import { MetadataStore } from './metadatastore/MetadataStore'
|
||||
import { DataTokens } from './datatokens/Datatokens'
|
||||
import { ConfigHelper } from './utils/ConfigHelper'
|
||||
|
||||
@ -21,4 +21,14 @@ export {
|
||||
OceanPlatformVersions
|
||||
} from './ocean/Versions'
|
||||
|
||||
export { Ocean, Account, Config, DID, Logger, Aquarius, DataTokens, utils, ConfigHelper }
|
||||
export {
|
||||
Ocean,
|
||||
Account,
|
||||
Config,
|
||||
DID,
|
||||
Logger,
|
||||
MetadataStore,
|
||||
DataTokens,
|
||||
utils,
|
||||
ConfigHelper
|
||||
}
|
||||
|
@ -23,27 +23,27 @@ export interface SearchQuery {
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides an interface with Aquarius.
|
||||
* Aquarius provides an off-chain database store for metadata about data assets.
|
||||
* Provides an interface with Metadata Store.
|
||||
* Metadata Store provides an off-chain database store for metadata about data assets.
|
||||
*/
|
||||
export class Aquarius {
|
||||
export class MetadataStore {
|
||||
public fetch: WebServiceConnector
|
||||
private logger: Logger
|
||||
private aquariusUri: string
|
||||
private metadataStoreUri: string
|
||||
|
||||
private get url() {
|
||||
return this.aquariusUri
|
||||
return this.metadataStoreUri
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate Aquarius (independently of Ocean) for off-chain interaction.
|
||||
* @param {String} aquariusUri
|
||||
* Instantiate Metadata Store (independently of Ocean) for off-chain interaction.
|
||||
* @param {String} metadataStoreUri
|
||||
* @param {Logger} logger
|
||||
*/
|
||||
constructor(aquariusUri: string, logger: Logger) {
|
||||
constructor(metadataStoreUri: string, logger: Logger) {
|
||||
this.fetch = new WebServiceConnector(logger)
|
||||
this.logger = logger
|
||||
this.aquariusUri = aquariusUri
|
||||
this.metadataStoreUri = metadataStoreUri
|
||||
}
|
||||
|
||||
public async getVersionInfo() {
|
||||
@ -145,7 +145,7 @@ export class Aquarius {
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores a DDO in Aquarius.
|
||||
* Stores a DDO in Metadata Store.
|
||||
* @param {DDO} ddo DDO to be stored.
|
||||
* @return {Promise<DDO>} Final DDO.
|
||||
*/
|
@ -9,10 +9,10 @@ export class Config {
|
||||
public nodeUri?: string
|
||||
|
||||
/**
|
||||
* Aquarius URL.
|
||||
* Metadata Store URL.
|
||||
* @type {string}
|
||||
*/
|
||||
public aquariusUri?: string
|
||||
public metadataStoreUri?: string
|
||||
|
||||
/**
|
||||
* Provider URL.
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { SearchQuery, QueryResult } from '../aquarius/Aquarius'
|
||||
import { SearchQuery, QueryResult } from '../metadatastore/MetadataStore'
|
||||
import { DDO } from '../ddo/DDO'
|
||||
import { Metadata } from '../ddo/interfaces/Metadata'
|
||||
import { Service, ServiceAccess, ServiceComputePrivacy } from '../ddo/interfaces/Service'
|
||||
@ -75,7 +75,7 @@ export class Assets extends Instantiable {
|
||||
if (!dtAddress) {
|
||||
this.logger.log('Creating datatoken')
|
||||
observer.next(CreateProgressStep.CreatingDataToken)
|
||||
const metadataStoreURI = this.ocean.aquarius.getURI()
|
||||
const metadataStoreURI = this.ocean.metadatastore.getURI()
|
||||
const jsonBlob = { t: 1, url: metadataStoreURI }
|
||||
const { datatokens } = this.ocean
|
||||
dtAddress = await datatokens.create(JSON.stringify(jsonBlob), publisher)
|
||||
@ -160,7 +160,7 @@ export class Assets extends Instantiable {
|
||||
observer.next(CreateProgressStep.ProofGenerated)
|
||||
this.logger.log('Storing DDO')
|
||||
observer.next(CreateProgressStep.StoringDdo)
|
||||
const storedDdo = await this.ocean.aquarius.storeDDO(ddo)
|
||||
const storedDdo = await this.ocean.metadatastore.storeDDO(ddo)
|
||||
this.logger.log('DDO stored')
|
||||
observer.next(CreateProgressStep.DdoStored)
|
||||
return storedDdo
|
||||
@ -196,7 +196,7 @@ export class Assets extends Instantiable {
|
||||
* @return {Promise<DDO>}
|
||||
*/
|
||||
public async resolve(did: string): Promise<DDO> {
|
||||
return this.ocean.aquarius.retrieveDDO(did)
|
||||
return this.ocean.metadatastore.retrieveDDO(did)
|
||||
}
|
||||
|
||||
public async resolveByDTAddress(
|
||||
@ -216,7 +216,7 @@ export class Assets extends Instantiable {
|
||||
},
|
||||
text: dtAddress
|
||||
} as SearchQuery
|
||||
return (await this.ocean.aquarius.queryMetadata(searchQuery)).results
|
||||
return (await this.ocean.metadatastore.queryMetadata(searchQuery)).results
|
||||
}
|
||||
|
||||
/**
|
||||
@ -231,7 +231,7 @@ export class Assets extends Instantiable {
|
||||
newMetadata: EditableMetadata,
|
||||
account: Account
|
||||
): Promise<string> {
|
||||
const oldDdo = await this.ocean.aquarius.retrieveDDO(did)
|
||||
const oldDdo = await this.ocean.metadatastore.retrieveDDO(did)
|
||||
// get a signature
|
||||
const signature = await this.ocean.utils.signature.signForAquarius(
|
||||
oldDdo.updated,
|
||||
@ -239,7 +239,7 @@ export class Assets extends Instantiable {
|
||||
)
|
||||
let result = null
|
||||
if (signature != null)
|
||||
result = await this.ocean.aquarius.editMetadata(
|
||||
result = await this.ocean.metadatastore.editMetadata(
|
||||
did,
|
||||
newMetadata,
|
||||
oldDdo.updated,
|
||||
@ -263,7 +263,7 @@ export class Assets extends Instantiable {
|
||||
computePrivacy: ServiceComputePrivacy,
|
||||
account: Account
|
||||
): Promise<string> {
|
||||
const oldDdo = await this.ocean.aquarius.retrieveDDO(did)
|
||||
const oldDdo = await this.ocean.metadatastore.retrieveDDO(did)
|
||||
// get a signature
|
||||
const signature = await this.ocean.utils.signature.signForAquarius(
|
||||
oldDdo.updated,
|
||||
@ -271,7 +271,7 @@ export class Assets extends Instantiable {
|
||||
)
|
||||
let result = null
|
||||
if (signature != null)
|
||||
result = await this.ocean.aquarius.updateComputePrivacy(
|
||||
result = await this.ocean.metadatastore.updateComputePrivacy(
|
||||
did,
|
||||
serviceIndex,
|
||||
computePrivacy.allowRawAlgorithm,
|
||||
@ -291,7 +291,7 @@ export class Assets extends Instantiable {
|
||||
* @return {Promise<string>}
|
||||
*/
|
||||
public async retire(did: string, account: Account): Promise<string> {
|
||||
const oldDdo = await this.ocean.aquarius.retrieveDDO(did)
|
||||
const oldDdo = await this.ocean.metadatastore.retrieveDDO(did)
|
||||
// get a signature
|
||||
const signature = await this.ocean.utils.signature.signForAquarius(
|
||||
oldDdo.updated,
|
||||
@ -299,7 +299,7 @@ export class Assets extends Instantiable {
|
||||
)
|
||||
let result = null
|
||||
if (signature != null)
|
||||
result = await this.ocean.aquarius.retire(did, oldDdo.updated, signature)
|
||||
result = await this.ocean.metadatastore.retire(did, oldDdo.updated, signature)
|
||||
return result
|
||||
}
|
||||
|
||||
@ -332,7 +332,7 @@ export class Assets extends Instantiable {
|
||||
* @return {Promise<DDO[]>}
|
||||
*/
|
||||
public async query(query: SearchQuery) {
|
||||
return this.ocean.aquarius.queryMetadata(query)
|
||||
return this.ocean.metadatastore.queryMetadata(query)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -341,7 +341,7 @@ export class Assets extends Instantiable {
|
||||
* @return {Promise<DDO[]>}
|
||||
*/
|
||||
public async search(text: string) {
|
||||
return this.ocean.aquarius.queryMetadataByText({
|
||||
return this.ocean.metadatastore.queryMetadataByText({
|
||||
text,
|
||||
page: 1,
|
||||
offset: 100,
|
||||
|
@ -7,7 +7,7 @@ import { Assets } from './Assets'
|
||||
import { Versions } from './Versions'
|
||||
import { OceanUtils } from './utils/Utils'
|
||||
|
||||
import { Aquarius } from '../aquarius/Aquarius'
|
||||
import { MetadataStore } from '../metadatastore/MetadataStore'
|
||||
import { Provider } from '../provider/Provider'
|
||||
import { DataTokens } from '../datatokens/Datatokens'
|
||||
import { Network } from '../datatokens/Network'
|
||||
@ -39,8 +39,8 @@ export class Ocean extends Instantiable {
|
||||
instance.utils = await OceanUtils.getInstance(instanceConfig)
|
||||
|
||||
instance.provider = new Provider(instanceConfig)
|
||||
instance.aquarius = new Aquarius(
|
||||
instanceConfig.config.aquariusUri,
|
||||
instance.metadatastore = new MetadataStore(
|
||||
instanceConfig.config.metadataStoreUri,
|
||||
instanceConfig.logger
|
||||
)
|
||||
|
||||
@ -78,10 +78,10 @@ export class Ocean extends Instantiable {
|
||||
public web3Provider: any
|
||||
|
||||
/**
|
||||
* Aquarius instance.
|
||||
* @type {Aquarius}
|
||||
* MetadataStore instance.
|
||||
* @type {MetadataStore}
|
||||
*/
|
||||
public aquarius: Aquarius
|
||||
public metadatastore: MetadataStore
|
||||
|
||||
/**
|
||||
* Ocean account submodule
|
||||
|
@ -51,7 +51,10 @@ export class Versions extends Instantiable {
|
||||
|
||||
// MetadataStore
|
||||
try {
|
||||
const { software: name, version } = await this.ocean.aquarius.getVersionInfo()
|
||||
const {
|
||||
software: name,
|
||||
version
|
||||
} = await this.ocean.metadatastore.getVersionInfo()
|
||||
versions.metadataStore = {
|
||||
name,
|
||||
status: OceanPlatformTechStatus.Working,
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { Aquarius } from '../../../src/aquarius/Aquarius'
|
||||
import { MetadataStore } from '../../../src/metadatastore/MetadataStore'
|
||||
import { DDO } from '../../../src/ddo/DDO'
|
||||
import DID from '../../../src/ocean/DID'
|
||||
|
||||
const ddoStore: Map<string, any> = new Map<string, any>()
|
||||
|
||||
export default class AquariusMock extends Aquarius {
|
||||
export default class MetadataStoreMock extends MetadataStore {
|
||||
public async getAccessUrl(accessToken: any, payload: any): Promise<string> {
|
||||
return 'http://test/test'
|
||||
}
|
@ -4,7 +4,7 @@ import { LoggerInstance } from '../../src/utils'
|
||||
LoggerInstance.setLevel(LogLevel.Error)
|
||||
|
||||
export default {
|
||||
aquariusUri: 'http://localhost:5000',
|
||||
metadataStoreUri: 'http://localhost:5000',
|
||||
providerUri: 'http://localhost:8030',
|
||||
nodeUri: `http://localhost:${process.env.ETH_PORT || 8545}`,
|
||||
parityUri: 'http://localhost:9545',
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { assert, spy, use } from 'chai'
|
||||
import spies from 'chai-spies'
|
||||
import { Ocean } from '../../../src/ocean/Ocean'
|
||||
import { Aquarius, SearchQuery } from '../../../src/aquarius/Aquarius'
|
||||
import { MetadataStore, SearchQuery } from '../../../src/metadatastore/MetadataStore'
|
||||
import { DDO } from '../../../src/ddo/DDO'
|
||||
import DID from '../../../src/ocean/DID'
|
||||
import config from '../config'
|
||||
@ -14,9 +14,9 @@ const reponsify = async (data) => ({
|
||||
json: () => Promise.resolve(data)
|
||||
})
|
||||
|
||||
describe('Aquarius', () => {
|
||||
describe('MetadataStore', () => {
|
||||
let ocean: Ocean
|
||||
let aquarius: Aquarius
|
||||
let metadataStore: MetadataStore
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
const getResults = (
|
||||
results: DDO[],
|
||||
@ -33,7 +33,7 @@ describe('Aquarius', () => {
|
||||
|
||||
beforeEach(async () => {
|
||||
ocean = await Ocean.getInstance(config)
|
||||
aquarius = ocean.aquarius // eslint-disable-line prefer-destructuring
|
||||
metadataStore = ocean.metadatastore // eslint-disable-line prefer-destructuring
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
@ -54,9 +54,9 @@ describe('Aquarius', () => {
|
||||
} as SearchQuery
|
||||
|
||||
it('should query metadata', async () => {
|
||||
spy.on(aquarius.fetch, 'post', () => reponsify(getResults([new DDO()])))
|
||||
spy.on(metadataStore.fetch, 'post', () => reponsify(getResults([new DDO()])))
|
||||
|
||||
const result = await aquarius.queryMetadata(query)
|
||||
const result = await metadataStore.queryMetadata(query)
|
||||
assert.typeOf(result.results, 'array')
|
||||
assert.lengthOf(result.results, 1)
|
||||
assert.equal(result.page, 0)
|
||||
@ -65,9 +65,9 @@ describe('Aquarius', () => {
|
||||
})
|
||||
|
||||
it('should query metadata and return real ddo', async () => {
|
||||
spy.on(aquarius.fetch, 'post', () => reponsify(getResults([new DDO()])))
|
||||
spy.on(metadataStore.fetch, 'post', () => reponsify(getResults([new DDO()])))
|
||||
|
||||
const result = await aquarius.queryMetadata(query)
|
||||
const result = await metadataStore.queryMetadata(query)
|
||||
assert.typeOf(result.results, 'array')
|
||||
assert.lengthOf(result.results, 1)
|
||||
assert.isDefined(result.results[0].findServiceById)
|
||||
@ -88,9 +88,10 @@ describe('Aquarius', () => {
|
||||
} as SearchQuery
|
||||
|
||||
it('should query metadata by text', async () => {
|
||||
spy.on(aquarius.fetch, 'get', () => reponsify(getResults([new DDO()])))
|
||||
spy.on(metadataStore.fetch, 'get', () => reponsify(getResults([new DDO()])))
|
||||
const result = await metadataStore.queryMetadataByText(query)
|
||||
console.log(result)
|
||||
|
||||
const result = await aquarius.queryMetadataByText(query)
|
||||
assert.typeOf(result.results, 'array')
|
||||
assert.lengthOf(result.results, 1)
|
||||
assert.equal(result.page, 0)
|
||||
@ -99,10 +100,15 @@ describe('Aquarius', () => {
|
||||
})
|
||||
|
||||
it('should query metadata by text with a new instance', async () => {
|
||||
const aquariusNew = new Aquarius(config.aquariusUri, LoggerInstance)
|
||||
spy.on(aquariusNew.fetch, 'get', () => reponsify(getResults([new DDO()])))
|
||||
const metadatastoreNew = new MetadataStore(
|
||||
config.metadataStoreUri,
|
||||
LoggerInstance
|
||||
)
|
||||
spy.on(metadatastoreNew.fetch, 'get', () =>
|
||||
reponsify(getResults([new DDO()]))
|
||||
)
|
||||
|
||||
const result = await aquariusNew.queryMetadataByText(query)
|
||||
const result = await metadatastoreNew.queryMetadataByText(query)
|
||||
assert.typeOf(result.results, 'array')
|
||||
assert.lengthOf(result.results, 1)
|
||||
assert.equal(result.page, 0)
|
||||
@ -111,9 +117,9 @@ describe('Aquarius', () => {
|
||||
})
|
||||
|
||||
it('should query metadata and return real ddo', async () => {
|
||||
spy.on(aquarius.fetch, 'get', () => reponsify(getResults([new DDO()])))
|
||||
spy.on(metadataStore.fetch, 'get', () => reponsify(getResults([new DDO()])))
|
||||
|
||||
const result = await aquarius.queryMetadataByText(query)
|
||||
const result = await metadataStore.queryMetadataByText(query)
|
||||
assert.typeOf(result.results, 'array')
|
||||
assert.lengthOf(result.results, 1)
|
||||
assert.isDefined(result.results[0].findServiceById)
|
||||
@ -127,9 +133,9 @@ describe('Aquarius', () => {
|
||||
id: did.getId()
|
||||
})
|
||||
|
||||
spy.on(aquarius.fetch, 'post', () => reponsify(ddo))
|
||||
spy.on(metadataStore.fetch, 'post', () => reponsify(ddo))
|
||||
|
||||
const result: DDO = await aquarius.storeDDO(ddo)
|
||||
const result: DDO = await metadataStore.storeDDO(ddo)
|
||||
assert(result)
|
||||
assert(result.id === ddo.id)
|
||||
})
|
||||
@ -142,15 +148,15 @@ describe('Aquarius', () => {
|
||||
id: did.getId()
|
||||
})
|
||||
|
||||
spy.on(aquarius.fetch, 'post', () => reponsify(ddo))
|
||||
spy.on(aquarius.fetch, 'get', () => reponsify(ddo))
|
||||
spy.on(metadataStore.fetch, 'post', () => reponsify(ddo))
|
||||
spy.on(metadataStore.fetch, 'get', () => reponsify(ddo))
|
||||
|
||||
const storageResult: DDO = await aquarius.storeDDO(ddo)
|
||||
const storageResult: DDO = await metadataStore.storeDDO(ddo)
|
||||
assert(storageResult)
|
||||
|
||||
assert(storageResult.id === did.getId())
|
||||
|
||||
const restrieveResult: DDO = await aquarius.retrieveDDO(did)
|
||||
const restrieveResult: DDO = await metadataStore.retrieveDDO(did)
|
||||
assert(restrieveResult)
|
||||
|
||||
assert(restrieveResult.id === did.getId())
|
@ -1,7 +1,7 @@
|
||||
import { assert, spy, use } from 'chai'
|
||||
import spies from 'chai-spies'
|
||||
|
||||
import { SearchQuery } from '../../../src/aquarius/Aquarius'
|
||||
import { SearchQuery } from '../../../src/metadatastore/MetadataStore'
|
||||
import { Ocean } from '../../../src/ocean/Ocean'
|
||||
import config from '../config'
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user