Skip to content

Commit db0b17a

Browse files
authored
DDO.js library docs (#1509)
* Add publishing flow seq diagram. Create validate README for ddo.js. * Update validate code snippet. * Add instantiating a ddo with ddo.js lib. * Update docs. Created retrieve-fields.md README. * Created edit-fields guide for ddo.js. * Updated SUMMARY and installation step for ddo.js. * Fix typo. * Fix review. Created dedicated section for publishing flow. * Update SUMMARY. * Update vars.
1 parent 19be8ad commit db0b17a

12 files changed

+628
-2
lines changed
195 KB
Loading

.gitbook/assets/cli/flow.puml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
@startuml "DDO Publishing Flow"
2+
title "DDO Publishing Flow"
3+
4+
skinparam sequenceArrowThickness 2
5+
skinparam roundcorner 10
6+
skinparam maxmessagesize 85
7+
skinparam sequenceParticipant underline
8+
9+
actor "End User" as end_user
10+
participant "Consumer\n(Ocean CLI)" as consumer
11+
participant "Ocean.js" as ocean_js
12+
participant "Ocean Node" as ocean_node
13+
database "Ocean Node's Database\n(Typesense/ElasticSearch)" as db
14+
participant "Smart Contracts" as smart_contracts
15+
participant "DDO.js" as ddo_js
16+
17+
group Asset Creation
18+
end_user -> consumer: Requests to publish a dataset with selected file.
19+
note over end_user
20+
Command: **npm run publish <ddo file>**
21+
end note
22+
consumer -> ocean_js: Calls asset creation function
23+
group DataNFT, Datatoken and Pricing Schema Deployment
24+
ocean_js -> smart_contracts: Deploy data NFT & datatoken with pricing schema
25+
note over smart_contracts
26+
Pricing schemas are:
27+
- dispenser
28+
- fixed rate exchange.
29+
end note
30+
smart_contracts --> smart_contracts: Events emmitted
31+
ocean_js -> smart_contracts: Retrieve **NFTCreated** and **DatatokenCreated** events
32+
alt Datatoken is **not** template 4 for EVM credentials
33+
ocean_js -> ocean_node: Requests encryption for DDO services files
34+
alt Encryption is successful
35+
ocean_node --> ocean_js: Returns **200 OK** response
36+
else Encryption is **NOT** successful
37+
ocean_node --> ocean_js: Returns error status code
38+
end
39+
else Datatoken is template 4 for EVM credentials
40+
note over ocean_js
41+
No encryption for service files needed,
42+
because on Oasis the datatoken, which contains
43+
the services, is deployed encrypted form.
44+
end note
45+
end
46+
end group
47+
group DDO Encryption
48+
ocean_js -> ocean_node: Requests encryption for DDO object
49+
alt Encryption is successful
50+
ocean_node --> ocean_js: Returns **200 OK** response
51+
else Encryption is **NOT** successful
52+
ocean_node --> ocean_js: Returns error status code
53+
end
54+
end group
55+
group DDO Validation
56+
ocean_js -> ocean_node: Requests validation for DDO structure
57+
ocean_node -> ddo_js: Validate DDO structure
58+
ddo_js -> ddo_js: Use SHACL schemas depending on DDO version for validation
59+
alt Validation is successful
60+
ddo_js --> ocean_node: Response with success
61+
ocean_node --> ocean_js: Returns **200 OK** response
62+
ocean_js -> smart_contracts: Calls **setMetadata** on chain
63+
ocean_js --> consumer: Returns DID
64+
consumer --> end_user: Returns DID
65+
group Ocean Node indexes new DDOs
66+
smart_contracts --> smart_contracts: Emit event **MetadataCreated**
67+
ocean_node -> smart_contracts: Listens to **MetadataCreated** events
68+
ocean_node -> ocean_node: Indexes DDO from chain in processMetadataEvent
69+
ocean_node -> db: Stores DDO in the database
70+
db --> ocean_node
71+
end group
72+
73+
else Validation is **NOT** successful
74+
ddo_js --> ocean_node: Response with error and log the message
75+
ocean_node --> ocean_js: Returns error status code
76+
end
77+
78+
end group
79+
end group
80+
@enduml
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
@startuml "DDO Validation Flow using DDO.js Library"
3+
title "DDO Publishing Flow using DDO.js Library"
4+
5+
skinparam sequenceArrowThickness 2
6+
skinparam roundcorner 10
7+
skinparam maxmessagesize 85
8+
skinparam sequenceParticipant underline
9+
10+
participant "Ocean.js" as ocean_js
11+
participant "Ocean Node" as ocean_node
12+
database "Ocean Node's Database\n(Typesense/ElasticSearch)" as db
13+
participant "Smart Contracts" as smart_contracts
14+
participant "DDO.js" as ddo_js
15+
16+
group DDO Validation
17+
ocean_js -> ocean_node: Requests validation for DDO structure
18+
ocean_node -> ddo_js: Validate DDO structure
19+
ddo_js -> ddo_js: Use SHACL schemas depending on DDO version for validation
20+
alt Validation is successful
21+
ddo_js --> ocean_node: Response with success
22+
ocean_node --> ocean_js: Returns **200 OK** response
23+
ocean_js -> smart_contracts: Calls **setMetadata** on chain
24+
ocean_js --> ocean_js: Returns DID
25+
group Ocean Node indexes new DDOs
26+
smart_contracts --> smart_contracts: Emit event **MetadataCreated**
27+
ocean_node -> smart_contracts: Listens to **MetadataCreated** events
28+
ocean_node -> ocean_node: Indexes DDO from chain in processMetadataEvent
29+
ocean_node -> db: Stores DDO in the database
30+
db --> ocean_node
31+
end group
32+
else Validation is **NOT** successful
33+
ddo_js --> ocean_node: Response with error and log the message
34+
ocean_node --> ocean_js: Returns error status code
35+
end
36+
37+
end group
38+
39+
@enduml
79.2 KB
Loading

SUMMARY.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@
3434
* [Roles](developers/contracts/roles.md)
3535
* [Pricing Schemas](developers/contracts/pricing-schemas.md)
3636
* [Fees](developers/contracts/fees.md)
37+
* [Publish Flow Overview](developers/publishing-flow-architecture.md)
3738
* [Revenue](developers/contracts/revenue.md)
3839
* [Fractional Ownership](developers/fractional-ownership.md)
3940
* [Community Monetization](developers/community-monetization.md)
4041
* [Metadata](developers/metadata.md)
4142
* [Identifiers (DIDs)](developers/identifiers.md)
42-
* [DDO Specification](developers/ddo-specification.md)
43+
* [New DDO Specification](developers/new-ddo-specification.md)
44+
* [Obsolete DDO Specification](developers/ddo-specification.md)
4345
* [Storage Specifications](developers/storage.md)
4446
* [Fine-Grained Permissions](developers/fg-permissions.md)
4547
* [Retrieve datatoken/data NFT addresses & Chain ID](developers/retrieve-datatoken-address.md)
@@ -61,6 +63,12 @@
6163
* [Edit](developers/ocean-cli/edit.md)
6264
* [Consume](developers/ocean-cli/consume.md)
6365
* [Run C2D Jobs](developers/ocean-cli/run-c2d.md)
66+
* [DDO.js](developers/ddo.js/README.md)
67+
* [Instantiate a DDO](developers/ddo.js/instantiate-ddo.md)
68+
* [DDO Fields interactions](developers/ddo.js/retrieve-fields.md)
69+
* [Validate](developers/ddo.js/validate.md)
70+
* [Edit DDO Fields](developers/ddo.js/edit-fields.md)
71+
* [Compute to data](developers/compute-to-data/README.md)
6472
* [Compute to data](developers/compute-to-data/README.md)
6573
* [Architecture](developers/compute-to-data/compute-to-data-architecture.md)
6674
* [Datasets & Algorithms](developers/compute-to-data/compute-to-data-datasets-algorithms.md)

developers/ddo.js/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
description: >-
3+
Ocean Protocol's JavaScript library to manipulate with DDO and Asset fields and to validate DDO structures depending on version.
4+
---
5+
6+
# DDO.js
7+
8+
Welcome to the DDO.js! Your utility library for working with DDOs and Assets like a pro. 🚀
9+
10+
The DDO.js offers a wide range of functionalities, enabling you to:
11+
12+
* [**Instantiate DDO**](instantiate-ddo.md) 📤 by `DDOManager` depending on version.
13+
* [**Retrieve**](retrieve-fields.md) 📥 DDO data together with Asset fields using defined helper methods.
14+
* [**Validate DDO**](validate.md) 📤 using SHACL schemas.
15+
* [**Edit**](edit-fields.md) ✏️ existing fields of DDO and Asset.
16+
17+
## Installation
18+
19+
It is available as `npm` package, therefore to install in your `js` project, simply run in the console:
20+
21+
```bash
22+
npm install @oceanprotocol/ddo-js
23+
```
24+
25+
## Key Information
26+
27+
Let's dive into the DDO.js's capabilities together! If you're ready to explore each functionality in detail, simply go through the next pages.

developers/ddo.js/edit-fields.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Edit DDO Fields ✏️
2+
3+
To edit fields in the DDO structure, DDO instance from `DDOManager` is required to call `updateFields` method which is present for all types of DDOs, but targets specific DDO fields, according to DDO's version.
4+
5+
**NOTE**: There are some restrictions that need to be taken care of before updating fields which do not exist for certain DDO.
6+
7+
For e.g. `deprecatedDDO`, the update on `services` key is not supported, because a `deprecatedDDO` is not supposed to store `services` information. It is design to support only: `id`, `nftAddress`, `chainId`, `indexedMetadata.nft.state`.
8+
9+
Supported fields to be updated are:
10+
11+
```javascript
12+
13+
export interface UpdateFields {
14+
id?: string;
15+
nftAddress?: string;
16+
chainId?: number;
17+
datatokens?: AssetDatatoken[];
18+
indexedMetadata?: IndexedMetadata;
19+
services?: ServiceV4[] | ServiceV5[];
20+
issuer?: string;
21+
proof?: Proof;
22+
}
23+
```
24+
25+
## Usage of Update Fields Function
26+
27+
Now let's use [DDO V4 example](./instantiate-ddo.md#usage-examples), `DDOExampleV4` into the following javascript code, assuming `@oceanprotocol/ddo-js` has been installed as dependency before:
28+
29+
```javascript
30+
const { DDOManager } = require ('@oceanprotocol/ddo-js');
31+
32+
const ddoInstance = DDOManager.getDDOClass(DDOExampleV4);
33+
const nftAddressToUpdate = "0xfF4AE9869Cafb5Ff725f962F3Bbc22Fb303A8aD8"
34+
ddoInstance.updateFields({ nftAddress: nftAddressToUpdate }) // It supports update on multiple fields
35+
// The same script can be applied on DDO V5 and deprecated DDO from `Instantiate DDO section`.
36+
```
37+
**Execute script**
38+
39+
```bash
40+
node update-ddo-fields.js
41+
```

0 commit comments

Comments
 (0)