mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
added comments on some internal classes #79
This commit is contained in:
parent
b2d2271e50
commit
4074d95f1e
|
@ -1,15 +1,27 @@
|
|||
import Config from "./models/Config"
|
||||
|
||||
/**
|
||||
* Stores the configuration of the library.
|
||||
*/
|
||||
export default class ConfigProvider {
|
||||
|
||||
/**
|
||||
* @return {Config} Library config.
|
||||
*/
|
||||
public static getConfig(): Config {
|
||||
return ConfigProvider.config
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Config} Library config.
|
||||
*/
|
||||
public static setConfig(config: Config) {
|
||||
|
||||
ConfigProvider.config = config
|
||||
}
|
||||
|
||||
/**
|
||||
* Library config.
|
||||
* @type {Config}
|
||||
*/
|
||||
private static config: Config
|
||||
}
|
||||
|
|
|
@ -8,17 +8,18 @@ import SearchQuery from "./query/SearchQuery"
|
|||
|
||||
const apiPath = "/api/v1/aquarius/assets/ddo"
|
||||
|
||||
/**
|
||||
* Provides a interface with Aquarius.
|
||||
* Aquarius provides an off-chain database store for metadata about data assets.
|
||||
*/
|
||||
export default class Aquarius {
|
||||
|
||||
private url: string
|
||||
|
||||
constructor(config: Config) {
|
||||
|
||||
this.url = config.aquariusUri
|
||||
}
|
||||
|
||||
public async getAccessUrl(accessToken: any, payload: any): Promise<string> {
|
||||
|
||||
const accessUrl: string = await WebServiceConnectorProvider.getConnector()
|
||||
.post(`${accessToken.service_endpoint}/${accessToken.resource_id}`, payload)
|
||||
.then((response: any): string => {
|
||||
|
@ -40,8 +41,12 @@ export default class Aquarius {
|
|||
return accessUrl
|
||||
}
|
||||
|
||||
/**
|
||||
* Search over the DDOs using a query.
|
||||
* @param {SearchQuery} query Query to filter the DDOs.
|
||||
* @return {Promise<DDO[]>}
|
||||
*/
|
||||
public async queryMetadata(query: SearchQuery): Promise<DDO[]> {
|
||||
|
||||
const result: DDO[] = await WebServiceConnectorProvider.getConnector()
|
||||
.post(`${this.url}${apiPath}/query`, JSON.stringify(query))
|
||||
.then((response: any) => {
|
||||
|
@ -64,8 +69,12 @@ export default class Aquarius {
|
|||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Search over the DDOs using a query.
|
||||
* @param {SearchQuery} query Query to filter the DDOs.
|
||||
* @return {Promise<DDO[]>}
|
||||
*/
|
||||
public async queryMetadataByText(query: SearchQuery): Promise<DDO[]> {
|
||||
|
||||
const fullUrl = new URL(`${this.url}${apiPath}/query`)
|
||||
fullUrl.searchParams.append("text", query.text)
|
||||
fullUrl.searchParams.append("sort", decodeURIComponent(JSON.stringify(query.sort)))
|
||||
|
@ -93,6 +102,11 @@ export default class Aquarius {
|
|||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores a DDO in Aquarius.
|
||||
* @param {DDO} ddo DDO to be stored.
|
||||
* @return {Promise<DDO>} Final DDO.
|
||||
*/
|
||||
public async storeDDO(ddo: DDO): Promise<DDO> {
|
||||
const fullUrl = `${this.url}${apiPath}`
|
||||
const result: DDO = await WebServiceConnectorProvider.getConnector()
|
||||
|
@ -115,6 +129,11 @@ export default class Aquarius {
|
|||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a DDO by DID.
|
||||
* @param {DID} did DID of the asset.
|
||||
* @return {Promise<DDO>} DDO of the asset.
|
||||
*/
|
||||
public async retrieveDDO(did: DID): Promise<DDO> {
|
||||
const fullUrl = `${this.url}${apiPath}/${did.getDid()}`
|
||||
const result = await WebServiceConnectorProvider.getConnector()
|
||||
|
|
|
@ -1,20 +1,33 @@
|
|||
import ConfigProvider from "../ConfigProvider"
|
||||
import Aquarius from "./Aquarius"
|
||||
|
||||
/**
|
||||
* Provides the Aquarius instance.
|
||||
*/
|
||||
export default class AquariusProvider {
|
||||
|
||||
/**
|
||||
* Set an Aquarius instance.
|
||||
* @param {Aquarius} aquarius New Aquarius instance.
|
||||
*/
|
||||
public static setAquarius(aquarius: Aquarius) {
|
||||
|
||||
AquariusProvider.aquarius = aquarius
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Acuarius instance. It creates a new one if it's not defined.
|
||||
* @returns {Aquarius} Aquarius instance.
|
||||
*/
|
||||
public static getAquarius() {
|
||||
|
||||
if (!AquariusProvider.aquarius) {
|
||||
AquariusProvider.aquarius = new Aquarius(ConfigProvider.getConfig())
|
||||
}
|
||||
return AquariusProvider.aquarius
|
||||
}
|
||||
|
||||
/**
|
||||
* Aquarius instance.
|
||||
* @type {Aquarius}
|
||||
*/
|
||||
private static aquarius: Aquarius = null
|
||||
}
|
||||
|
|
|
@ -3,11 +3,14 @@ import WebServiceConnectorProvider from "../utils/WebServiceConnectorProvider"
|
|||
|
||||
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.
|
||||
*/
|
||||
export default class Brizo {
|
||||
private url: string
|
||||
|
||||
constructor(config: Config) {
|
||||
|
||||
this.url = config.brizoUri
|
||||
}
|
||||
|
||||
|
|
|
@ -1,20 +1,33 @@
|
|||
import ConfigProvider from "../ConfigProvider"
|
||||
import Brizo from "./Brizo"
|
||||
|
||||
/**
|
||||
* Provides the Brizo instance.
|
||||
*/
|
||||
export default class BrizoProvider {
|
||||
|
||||
/**
|
||||
* Set an Brizo instance.
|
||||
* @param {Brizo} brizo New Brizo instance.
|
||||
*/
|
||||
public static setBrizo(brizo: Brizo) {
|
||||
|
||||
BrizoProvider.brizo = brizo
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Acuarius instance. It creates a new one if it's not defined.
|
||||
* @returns {Brizo} brizo instance.
|
||||
*/
|
||||
public static getBrizo() {
|
||||
|
||||
if (!BrizoProvider.brizo) {
|
||||
BrizoProvider.brizo = new Brizo(ConfigProvider.getConfig())
|
||||
}
|
||||
return BrizoProvider.brizo
|
||||
}
|
||||
|
||||
/**
|
||||
* Brizo instance.
|
||||
* @type {Brizo}
|
||||
*/
|
||||
private static brizo: Brizo = null
|
||||
}
|
||||
|
|
|
@ -8,9 +8,20 @@ import OceanToken from "./contracts/Token"
|
|||
|
||||
import Web3Provider from "./Web3Provider"
|
||||
|
||||
/**
|
||||
* Interface with Ocean Keeper contracts.
|
||||
* Ocean Keeper implementation where we put the following modules together:
|
||||
* - TCRs: users create challenges and resolve them through voting to maintain registries.
|
||||
* - Ocean Tokens: the intrinsic tokens circulated inside Ocean network, which is used in the voting of TCRs.
|
||||
* - Marketplace: the core marketplace where people can transact with each other with Ocean tokens.
|
||||
*/
|
||||
export default class Keeper {
|
||||
|
||||
public static async getInstance() {
|
||||
/**
|
||||
* Returns Keeper instance.
|
||||
* @return {Promise<Keeper>}
|
||||
*/
|
||||
public static async getInstance(): Promise<Keeper> {
|
||||
|
||||
if (Keeper.instance === null) {
|
||||
Keeper.instance = new Keeper()
|
||||
|
@ -26,16 +37,58 @@ export default class Keeper {
|
|||
return Keeper.instance
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeper instance.
|
||||
* @type {Keeper}
|
||||
*/
|
||||
private static instance: Keeper = null
|
||||
|
||||
/**
|
||||
* Ocean Token smart contract instance.
|
||||
* @type {OceanToken}
|
||||
*/
|
||||
public token: OceanToken
|
||||
|
||||
/**
|
||||
* Ocean Market smart contract instance.
|
||||
* @type {OceanMarket}
|
||||
*/
|
||||
public market: OceanMarket
|
||||
|
||||
/**
|
||||
* Ocean Auth smart contract instance.
|
||||
* @type {OceanAuth}
|
||||
*/
|
||||
public auth: OceanAuth
|
||||
|
||||
/**
|
||||
* Service agreement smart contract instance.
|
||||
* @type {ServiceAgreement}
|
||||
*/
|
||||
public serviceAgreement: ServiceAgreement
|
||||
|
||||
/**
|
||||
* Access conditions smart contract instance.
|
||||
* @type {AccessConditions}
|
||||
*/
|
||||
public accessConditions: AccessConditions
|
||||
|
||||
/**
|
||||
* Payment conditions smart contract instance.
|
||||
* @type {PaymentConditions}
|
||||
*/
|
||||
public paymentConditions: PaymentConditions
|
||||
|
||||
/**
|
||||
* DID registry smart contract instance.
|
||||
* @type {DIDRegistry}
|
||||
*/
|
||||
public didRegistry: DIDRegistry
|
||||
|
||||
/**
|
||||
* Returns the network by name.
|
||||
* @return {Promise<string>} Network name.
|
||||
*/
|
||||
public async getNetworkName(): Promise<string> {
|
||||
return Web3Provider.getWeb3().eth.net.getId()
|
||||
.then((networkId) => {
|
||||
|
|
|
@ -3,7 +3,11 @@ import ConfigProvider from "../ConfigProvider"
|
|||
|
||||
export default class Web3Provider {
|
||||
|
||||
public static getWeb3() {
|
||||
/**
|
||||
* Returns Web3 instance.
|
||||
* @return {Web3}
|
||||
*/
|
||||
public static getWeb3(): Web3 {
|
||||
if (Web3Provider.web3 === null) {
|
||||
const config = ConfigProvider.getConfig()
|
||||
const web3Provider = config.web3Provider || new Web3.providers.HttpProvider(config.nodeUri)
|
||||
|
@ -12,5 +16,9 @@ export default class Web3Provider {
|
|||
return Web3Provider.web3
|
||||
}
|
||||
|
||||
/**
|
||||
* Web3 instance.
|
||||
* @type {Web3}
|
||||
*/
|
||||
private static web3: Web3 = null
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
import fetch from "node-fetch"
|
||||
import fetch, { Response, RequestInit, BodyInit } from "node-fetch"
|
||||
|
||||
/**
|
||||
* Provides a common interface to web services.
|
||||
*/
|
||||
export default class WebServiceConnector {
|
||||
|
||||
public async post(url, payload): Promise<any> {
|
||||
public async post(url: string, payload: BodyInit): Promise<Response> {
|
||||
return this.fetch(url, {
|
||||
method: "POST",
|
||||
body: payload,
|
||||
|
@ -12,7 +15,7 @@ export default class WebServiceConnector {
|
|||
})
|
||||
}
|
||||
|
||||
public async get(url): Promise<any> {
|
||||
public async get(url: string): Promise<Response> {
|
||||
return this.fetch(url, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
|
@ -21,7 +24,7 @@ export default class WebServiceConnector {
|
|||
})
|
||||
}
|
||||
|
||||
public async put(url, payload): Promise<any> {
|
||||
public async put(url: string, payload: BodyInit): Promise<Response> {
|
||||
return this.fetch(url, {
|
||||
method: "PUT",
|
||||
body: payload,
|
||||
|
@ -31,7 +34,7 @@ export default class WebServiceConnector {
|
|||
})
|
||||
}
|
||||
|
||||
private async fetch(url, opts): Promise<any> {
|
||||
private async fetch(url: string, opts: RequestInit): Promise<Response> {
|
||||
return fetch(url, opts)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user