mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
add docs and fix lint
This commit is contained in:
parent
fa5c8ac260
commit
6776088be3
@ -4,11 +4,7 @@ DIDResolver module to resolve Ocean DID's off the block chain
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// import DIDRegistry from "../keeper/contracts/DIDRegistry"
|
|
||||||
import DIDRecord from "../models/DIDRecord"
|
import DIDRecord from "../models/DIDRecord"
|
||||||
// import ValueType from "../models/ValueType"
|
|
||||||
|
|
||||||
// import * as Web3 from "web3"
|
|
||||||
import * as DIDTools from "../utils/DIDTools"
|
import * as DIDTools from "../utils/DIDTools"
|
||||||
|
|
||||||
export default class DIDResolved {
|
export default class DIDResolved {
|
||||||
@ -18,13 +14,27 @@ export default class DIDResolved {
|
|||||||
public constructor() {
|
public constructor() {
|
||||||
this.items = []
|
this.items = []
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
public addData(data: DIDRecord) {
|
* Add the DIDRecord to the collection of visited DID's
|
||||||
|
*
|
||||||
|
* :param data: DIDRecord to add
|
||||||
|
*/
|
||||||
|
public addData(data: DIDRecord): void {
|
||||||
this.items.push(data)
|
this.items.push(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Number of hops performed
|
||||||
|
* :return hop count
|
||||||
|
*/
|
||||||
public hopCount(): number {
|
public hopCount(): number {
|
||||||
return this.items.length
|
return this.items.length
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get the last DID record added by the resolver
|
||||||
|
*
|
||||||
|
* :return DIDRecord of the last resolved item
|
||||||
|
*/
|
||||||
public getLastItem(): DIDRecord {
|
public getLastItem(): DIDRecord {
|
||||||
let result: DIDRecord = null
|
let result: DIDRecord = null
|
||||||
if ( this.items.length > 0 ) {
|
if ( this.items.length > 0 ) {
|
||||||
@ -33,21 +43,67 @@ export default class DIDResolved {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* :return true if the resolved result is a URL
|
||||||
|
*/
|
||||||
public isURL(): boolean {
|
public isURL(): boolean {
|
||||||
const item = this.getLastItem()
|
const item = this.getLastItem()
|
||||||
return item && item.valueType === "URL"
|
return item && item.valueType === "URL"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* :return true if the resolved result is an on chain DDO
|
||||||
|
*/
|
||||||
public isDDO(): boolean {
|
public isDDO(): boolean {
|
||||||
const item = this.getLastItem()
|
const item = this.getLastItem()
|
||||||
return item && item.valueType === "DDO"
|
return item && item.valueType === "DDO"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* :return true if the resolved result is another DID
|
||||||
|
*/
|
||||||
public isDID(): boolean {
|
public isDID(): boolean {
|
||||||
const item = this.getLastItem()
|
const item = this.getLastItem()
|
||||||
return item && (item.valueType === "DID" || item.valueType === "DIDRef")
|
return item && (item.valueType === "DID" || item.valueType === "DIDRef")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* :return the stored key value for this DID resolved record
|
||||||
|
*/
|
||||||
|
public getKey(): string {
|
||||||
|
const item = this.getLastItem()
|
||||||
|
if ( item ) {
|
||||||
|
return item.key
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* :return the owner of the resolved record
|
||||||
|
*/
|
||||||
|
public getOwner(): string {
|
||||||
|
const item = this.getLastItem()
|
||||||
|
if ( item ) {
|
||||||
|
return item.owner
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* :return the ValueType ( URL, DDO, DID, DIDRef )
|
||||||
|
*/
|
||||||
|
public getValueType(): ValueType {
|
||||||
|
const item = this.getLastItem()
|
||||||
|
if ( item ) {
|
||||||
|
return item.valueType
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* :return the value of the resolved record, if it's a DID
|
||||||
|
* this call will return an ocean DID instead of in internal Id.
|
||||||
|
*/
|
||||||
public getValue(): string {
|
public getValue(): string {
|
||||||
const item = this.getLastItem()
|
const item = this.getLastItem()
|
||||||
let result: string = null
|
let result: string = null
|
||||||
@ -61,8 +117,16 @@ export default class DIDResolved {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Used by the resolver to check to see if the DID record has been
|
||||||
|
* visited before, to stop circular links.
|
||||||
|
*
|
||||||
|
* :param didId: 32 byte id that has been visited
|
||||||
|
*
|
||||||
|
* :return true if this 32 byte value is already in the list of DID records
|
||||||
|
*/
|
||||||
public isDIDIdVisited(didId: string): boolean {
|
public isDIDIdVisited(didId: string): boolean {
|
||||||
for ( let item of this.items) {
|
for ( const item of this.items) {
|
||||||
if ( item.didId === didId ) {
|
if ( item.didId === didId ) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -64,8 +64,7 @@ export default class DIDResolver {
|
|||||||
// only look if we have another id to find
|
// only look if we have another id to find
|
||||||
if ( didId ) {
|
if ( didId ) {
|
||||||
data = await this.getDID(didId)
|
data = await this.getDID(didId)
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
data = null
|
data = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user