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
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: CI

on:
pull_request:
push:
branches:
- main

jobs:
cli:
name: CLI
runs-on: ubuntu-latest

defaults:
run:
working-directory: cli

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.3.13

- name: Install dependencies
run: bun install --frozen-lockfile

- name: Run tests
run: bun run test

- name: Check formatting and lint
run: bunx biome check src tests

- name: Typecheck
run: bunx tsc --noEmit

- name: Build
run: bun run build
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Every command supports `-h` for full usage details.
```bash
npx foc-cli upload <path> # Upload with auto provider/dataset
npx foc-cli upload <path> --withCDN --copies 3 # CDN + 3 redundant copies
npx foc-cli multi-upload ./a.pdf,./b.pdf # Batch upload
npx foc-cli multi-upload ./a.pdf,./b.pdf # Batch upload; all paths must be readable
```

### Wallet
Expand All @@ -91,7 +91,7 @@ npx foc-cli wallet costs --extraBytes <n> --extraRunway <months>
```bash
npx foc-cli dataset list # List all datasets
npx foc-cli dataset details -d <id> # Metadata + pieces
npx foc-cli dataset create [providerId] [--cdn] # Create dataset
npx foc-cli dataset create <providerId> [--cdn] # Create dataset
npx foc-cli dataset upload <path> <providerId> # Create + upload
npx foc-cli dataset terminate <dataSetId> # Terminate dataset
```
Expand Down
20 changes: 13 additions & 7 deletions cli/bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"build": "rm -rf dist && tsc",
"prepublishOnly": "rm -rf dist && tsc && cp ../README.md ../LICENSE . && cp -r ../skills .",
"postpublish": "rm -f README.md LICENSE && rm -rf skills",
"test": "bun test",
"lint": "tsc --noEmit && biome check --fix src/"
},
"keywords": [
Expand Down Expand Up @@ -49,8 +50,8 @@
},
"dependencies": {
"@clack/prompts": "^1.0.0",
"@filoz/synapse-core": "^0.3.1",
"@filoz/synapse-sdk": "^0.40.0",
"@filoz/synapse-core": "^0.4.1",
"@filoz/synapse-sdk": "^0.40.4",
"@remix-run/fs": "^0.4.1",
"conf": "^15.0.2",
"incur": "^0.3.1",
Expand Down
4 changes: 1 addition & 3 deletions cli/src/commands/dataset/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ export const createCommand = {
args: z.object({
providerId: z.coerce
.number()
.optional()
.describe('Provider ID (interactive selection if omitted)'),
.describe('Provider ID. Use provider list to choose one.'),
}),
options: z.object({
chain: z
Expand All @@ -28,7 +27,6 @@ export const createCommand = {
providerId: z.string(),
}),
examples: [
{ description: 'Create dataset with interactive provider selection' },
{ args: { providerId: 1 }, description: 'Create dataset with provider #1' },
{
args: { providerId: 1 },
Expand Down
5 changes: 1 addition & 4 deletions cli/src/commands/dataset/details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ export const detailsCommand = {
cid,
scannerUrl: pieceScannerUrl(cid, chain),
url: piece.url,
metadata:
Object.keys(piece.metadata).length > 0
? piece.metadata
: 'No metadata',
metadata: piece.metadata,
}
})

Expand Down
25 changes: 22 additions & 3 deletions cli/src/commands/multi-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ type CopyResult = {

export const multiUploadCommand = {
description:
'Upload multiple files to Filecoin warm storage (high-level, recommended)',
'Upload multiple readable files to Filecoin warm storage (high-level, recommended)',
args: z.object({
paths: z
.preprocess(
(val) => (typeof val === 'string' ? val.split(',') : val),
z.array(z.string())
)
.describe('File paths to upload (comma-separated for CLI)'),
.describe('File paths to upload. All paths must be readable.'),
}),
options: z.object({
chain: z
Expand Down Expand Up @@ -72,7 +72,7 @@ export const multiUploadCommand = {
{
args: { paths: ['./myfile.pdf', './myfile2.pdf'] },
options: { copies: 3, withCDN: true },
description: 'Upload with auto provider/dataset selection',
description: 'Upload readable files with auto provider/dataset selection',
},
{
args: { paths: ['./data.bin', './data2.bin'] },
Expand All @@ -99,6 +99,25 @@ export const multiUploadCommand = {
const fileResultsSettled = await Promise.allSettled(
absolutePaths.map((filePath: string) => readFile(filePath))
)
const fileReadRejected = fileResultsSettled
.map((result, index) => ({ result, path: absolutePaths[index] }))
.filter(({ result }) => result.status === 'rejected')

if (fileReadRejected.length > 0) {
return out.fail(
'FILE_READ_FAILED',
fileReadRejected
.map(({ result, path }) => {
const reason =
result.status === 'rejected' ? result.reason : undefined
return `${path}: ${
reason instanceof Error ? reason.message : String(reason)
}`
})
.join(', ')
)
}

const fileResults = fileResultsSettled
.filter((result) => result.status === 'fulfilled')
.map((result) => result.value)
Expand Down
3 changes: 1 addition & 2 deletions cli/src/commands/piece/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { listCommand } from './list.ts'
import { removeCommand } from './remove.ts'

export const piece = Cli.create('piece', {
description:
'Piece management — upload, browse, and remove pieces from datasets',
description: 'Piece management — browse and remove pieces from datasets',
})

piece.command('list', listCommand)
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/piece/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const listCommand = {

return out.done(
{
dataSetId: c.args.dataSetId,
dataSetId: c.args.dataSetId.toString(),
datasetScannerUrl: datasetScannerUrl(c.args.dataSetId, chain),
pieces: piecesList,
},
Expand Down
4 changes: 0 additions & 4 deletions cli/src/commands/wallet/costs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ export const costsCommand = {
alreadyCovered: z.boolean(),
}),
examples: [
{
options: { extraBytes: 1000000 },
description: 'Get costs for uploading 1MB of data',
},
{
options: { extraBytes: 1000000, extraRunway: 1 },
description: 'Get costs for uploading 1MB with 1 month runway',
Expand Down
Loading
Loading