Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ Instead of a DID, you can pass a full `ComputeAsset` (datasets) or `ComputeAlgor

`npm run cli getComputeEnvironments`

Optionally pass a specific Ocean Node URL or peer id to query instead of `NODE_URL`:

`npm run cli getComputeEnvironments <nodeUrlOrPeerId>`

---

**Get Compute Streamable Logs:**
Expand Down Expand Up @@ -431,6 +435,82 @@ Instead of a DID, you can pass a full `ComputeAsset` (datasets) or `ComputeAlgor

---

**Allow Algorithm on Dataset:**

- **Positional:**
`npm run cli allowAlgo did:op:dataset did:op:algo`

- **With named option:**
`npm run cli allowAlgo did:op:dataset did:op:algo --encrypt true`

- The dataset and algorithm DIDs are required positional arguments (`--dataset` / `--algo` may override them, but the positionals must still be supplied). `--encrypt` toggles DDO encryption (default: `true`).

- Approves an algorithm to run on a compute-enabled dataset (signer must be the dataset NFT owner).

---

**Create Bucket:**

`npm run cli createBucket`

- Creates a new persistent-storage bucket on the node. Pass an access-list contract address to gate it; omit for owner-only access:

`npm run cli createBucket 0x1234...accessListAddress`

---

**Add File to Bucket:**

`npm run cli addFileToBucket <bucketId> ./path/to/file.csv`

- Optionally pass a name to store the file under (defaults to the file's basename):

`npm run cli addFileToBucket <bucketId> ./path/to/file.csv results.csv`

---

**List Buckets:**

`npm run cli listBuckets`

- Lists buckets owned by the signer, or by a specific owner:

`npm run cli listBuckets --owner 0x1234...ownerAddress`

---

**List Files in Bucket:**

`npm run cli listFilesInBucket <bucketId>`

---

**Get File Object:**

`npm run cli getFileObject <bucketId> <fileName>`

- Returns the file-object descriptor for a file in a bucket.

---

**Delete File:**

`npm run cli deleteFile <bucketId> <fileName>`

---

**Download Node Logs (admin):**

- **Positional:**
`npm run cli downloadNodeLogs ./logs 24`

- **Named Options:**
`npm run cli downloadNodeLogs --output ./logs --last 24`

- Downloads node logs into `<output>/logs.json`. Use either `last` (hours from now) **or** a `from`/`to` epoch-ms range. `maxLogs` caps the number of entries (default: 100, max: 1000). Requires admin privileges on the node.

---

#### Available Named Options Per Command

- **getDDO:**
Expand All @@ -454,6 +534,11 @@ Instead of a DID, you can pass a full `ComputeAsset` (datasets) or `ComputeAlgor
`-f, --folder [destinationFolder]` (Default: `.`)
`-s, --service <serviceId>` (Optional, target a specific service)

- **allowAlgo:**
`-d, --dataset <datasetDid>`
`-a, --algo <algoDid>`
`-e, --encrypt [boolean]` (Default: `true`)


- **startCompute:**
`-d, --datasets <datasetDids>`
Expand All @@ -477,6 +562,7 @@ Instead of a DID, you can pass a full `ComputeAsset` (datasets) or `ComputeAlgor
`-x, --algo-service [algoServiceId]` (Optional, override algorithm service)

- **getComputeEnvironments:**
`-n, --node [node]` (Optional. Ocean Node URL or peer id to query; defaults to `NODE_URL`)

- **computeStreamableLogs:**

Expand Down Expand Up @@ -544,6 +630,31 @@ Instead of a DID, you can pass a full `ComputeAsset` (datasets) or `ComputeAlgor
`-a, --address <accessListAddress>`
`-u, --users <users>`

- **createBucket:**
Positional only: `[accessListAddress]` (optional; omit for owner-only access)

- **addFileToBucket:**
Positional only: `<bucketId> <filePath> [fileName]`

- **listBuckets:**
`-o, --owner <address>` (Optional; defaults to signer)

- **listFilesInBucket:**
Positional only: `<bucketId>`

- **getFileObject:**
Positional only: `<bucketId> <fileName>`

- **deleteFile:**
Positional only: `<bucketId> <fileName>`

- **downloadNodeLogs:**
`-o, --output <output>`
`-l, --last [last]` (Hours from now; use either `last` or `from`/`to`)
`-f, --from [from]` (Start time, epoch ms)
`-t, --to [to]` (End time, epoch ms)
`-m, --maxLogs [maxLogs]` (Default: 100, max: 1000)

---

**Note:**
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
},
"author": "Ocean Protocol <devops@oceanprotocol.com>",
"license": "Apache-2.0",
"engines": {
"node": ">=22"
},
"bugs": {
"url": "https://github.com/oceanprotocol/ocean.js-cli/issues"
},
Expand Down
9 changes: 7 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
denyDialMultiaddr: () => false,
},
},
} as any);

Check warning on line 72 in src/cli.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
console.log(
chalk.cyan("libp2p node started. Waiting for peer connections...")
);
Expand All @@ -83,7 +83,7 @@
const maxWait = 20_000;
const interval = 500;
let waited = 0;
const libp2p = (ProviderInstance as any).p2pProvider?.libp2pNode;

Check warning on line 86 in src/cli.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
const isTargetConnected = () =>
(libp2p?.getPeers() ?? []).some(
(p: { toString(): string }) => p.toString() === targetPeerId
Expand Down Expand Up @@ -466,11 +466,16 @@
program
.command("getComputeEnvironments")
.alias("getC2DEnvs")
.argument(
"[node]",
"Optional Ocean Node URL or peer id to query (defaults to NODE_URL)"
)
.option("-n, --node <node>", "Ocean Node URL or peer id to query")
.description("Gets the existing compute environments")
.action(async () => {
.action(async (node, options) => {
const { signer, chainId } = await initializeSigner();
const commands = new Commands(signer, chainId);
await commands.getComputeEnvironments();
await commands.getComputeEnvironments(options.node || node);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
});

// computeStreamableLogs command
Expand Down
9 changes: 4 additions & 5 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
indexedMetadata.nft.name,
indexedMetadata.nft.symbol,
this.signer,
(services[0].files as any).files ?? services[0].files,

Check warning on line 95 in src/commands.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
asset,
this.oceanNodeUrl,
this.config,
Expand Down Expand Up @@ -126,7 +126,7 @@
indexedMetadata.nft.name,
indexedMetadata.nft.symbol,
this.signer,
(services[0].files as any).files ?? services[0].files,

Check warning on line 129 in src/commands.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
algoAsset,
this.oceanNodeUrl,
this.config,
Expand Down Expand Up @@ -348,7 +348,7 @@
const algoServiceIdInput = args[9] as string | undefined;
if (typeof algoServiceIdInput === "string" && algoServiceIdInput.trim().length > 0) {
const expectedAlgoServiceId = algoServiceIdInput.trim();
const matchAlgoSvc = servicesAlgo.find((s: any) => s.id === expectedAlgoServiceId);

Check warning on line 351 in src/commands.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
if (!matchAlgoSvc) {
console.error(
`Algorithm Service ID "${expectedAlgoServiceId}" not found in algo DDO ${algoDdo.id}. ` +
Expand Down Expand Up @@ -384,7 +384,7 @@
if (inputServices.length > 0) {
const expectedServiceId = inputServices[i];
if (expectedServiceId) {
const match = servicesDdo.find((s: any) => s.id === expectedServiceId);

Check warning on line 387 in src/commands.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
if (!match) {
console.error(
`Service ID "${expectedServiceId}" not found in dataset ${dataDdo.id}. ` +
Expand Down Expand Up @@ -605,7 +605,7 @@
let chosenAlgoServiceId = algo.serviceId || servicesAlgo[0].id;
if (typeof algoServiceIdInput === "string" && algoServiceIdInput.trim().length > 0) {
const expectedAlgoServiceId = algoServiceIdInput.trim();
const matchAlgoSvc = servicesAlgo.find((s: any) => s.id === expectedAlgoServiceId);

Check warning on line 608 in src/commands.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
if (!matchAlgoSvc) {
console.error(
`Algorithm Service ID "${expectedAlgoServiceId}" not found in algo DDO ${algoDdo.id}. ` +
Expand All @@ -615,7 +615,7 @@
}
chosenAlgoServiceId = expectedAlgoServiceId;
}
algoServiceIndex = servicesAlgo.findIndex((s: any) => s.id === chosenAlgoServiceId);

Check warning on line 618 in src/commands.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
if (algoServiceIndex < 0) {
console.error(
`Could not resolve serviceIndex for algorithm serviceId ${chosenAlgoServiceId}`
Expand Down Expand Up @@ -653,7 +653,7 @@
if (inputServices.length > 0) {
const expectedServiceId = inputServices[i];
if (expectedServiceId) {
const match = servicesDdo.find((s: any) => s.id === expectedServiceId);

Check warning on line 656 in src/commands.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
if (!match) {
console.error(
`Service ID "${expectedServiceId}" not found in dataset ${dataDdo.id}. ` +
Expand All @@ -669,7 +669,7 @@
} else if (i === 0 && servicesDdo[0]?.serviceEndpoint) {
providerURI = servicesDdo[0].serviceEndpoint;
}
const chosenServiceIndex = servicesDdo.findIndex((s: any) => s.id === chosenServiceId);

Check warning on line 672 in src/commands.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
if (chosenServiceIndex < 0) {
console.error(
`Could not resolve serviceIndex for dataset ${dataDdo.id} with serviceId ${chosenServiceId}`
Expand Down Expand Up @@ -1140,10 +1140,9 @@
console.log(jobStatus);
}

public async getComputeEnvironments() {
const computeEnvs = await ProviderInstance.getComputeEnvironments(
this.oceanNodeUrl
);
public async getComputeEnvironments(nodeUrlOverride?: string) {
const nodeUrl = nodeUrlOverride || this.oceanNodeUrl;
const computeEnvs = await ProviderInstance.getComputeEnvironments(nodeUrl);

if (!computeEnvs || computeEnvs.length < 1) {
console.error(
Expand All @@ -1152,7 +1151,7 @@
return;
}

console.log("Exiting compute environments: ", JSON.stringify(computeEnvs));
console.log("Existing compute environments: ", JSON.stringify(computeEnvs));
}

public async computeStreamableLogs(args: string[]) {
Expand Down
Loading
Loading