@ipab/cli 0.1.0-rc.10 → 0.1.0-rc.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -11
- package/dist/authoring.d.ts +7 -0
- package/dist/authoring.d.ts.map +1 -1
- package/dist/authoring.js +85 -5
- package/dist/authoring.js.map +1 -1
- package/dist/builtins/skill.ipab.car +0 -0
- package/dist/builtins/template.bundle-viewer.car +0 -0
- package/dist/builtins/template.check.car +0 -0
- package/dist/builtins/template.node.car +0 -0
- package/dist/builtins/template.web-app.car +0 -0
- package/dist/bundled-skills.d.ts +1 -1
- package/dist/cli.d.ts +2 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +904 -183
- package/dist/cli.js.map +1 -1
- package/dist/config-secret.js +1 -1
- package/dist/config-secret.js.map +1 -1
- package/dist/config.d.ts +4 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +17 -2
- package/dist/config.js.map +1 -1
- package/dist/daemon-ui.d.ts +1 -0
- package/dist/daemon-ui.d.ts.map +1 -1
- package/dist/daemon-ui.js +2 -0
- package/dist/daemon-ui.js.map +1 -1
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +7 -3
- package/dist/doctor.js.map +1 -1
- package/dist/get.d.ts.map +1 -1
- package/dist/get.js +1 -1
- package/dist/get.js.map +1 -1
- package/dist/history.d.ts +3 -1
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +16 -1
- package/dist/history.js.map +1 -1
- package/dist/kubo-topology.d.ts +2 -0
- package/dist/kubo-topology.d.ts.map +1 -1
- package/dist/kubo-topology.js +17 -20
- package/dist/kubo-topology.js.map +1 -1
- package/dist/kubo.d.ts +5 -3
- package/dist/kubo.d.ts.map +1 -1
- package/dist/kubo.js +83 -13
- package/dist/kubo.js.map +1 -1
- package/dist/name-reference.d.ts +8 -0
- package/dist/name-reference.d.ts.map +1 -0
- package/dist/name-reference.js +63 -0
- package/dist/name-reference.js.map +1 -0
- package/dist/pivot-rpc.d.ts +37 -2
- package/dist/pivot-rpc.d.ts.map +1 -1
- package/dist/pivot-rpc.js +188 -8
- package/dist/pivot-rpc.js.map +1 -1
- package/dist/search-index.d.ts.map +1 -1
- package/dist/search-index.js +1 -0
- package/dist/search-index.js.map +1 -1
- package/dist/skill-definition.d.ts +9 -0
- package/dist/skill-definition.d.ts.map +1 -1
- package/dist/skill-definition.js +26 -2
- package/dist/skill-definition.js.map +1 -1
- package/dist/skill-source.d.ts +1 -0
- package/dist/skill-source.d.ts.map +1 -1
- package/dist/skill-source.js +10 -4
- package/dist/skill-source.js.map +1 -1
- package/dist/skills.d.ts +9 -3
- package/dist/skills.d.ts.map +1 -1
- package/dist/skills.js +31 -2
- package/dist/skills.js.map +1 -1
- package/dist/state.d.ts +20 -0
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +87 -3
- package/dist/state.js.map +1 -1
- package/dist/swarm-fs-core.d.ts +217 -0
- package/dist/swarm-fs-core.d.ts.map +1 -0
- package/dist/swarm-fs-core.js +885 -0
- package/dist/swarm-fs-core.js.map +1 -0
- package/dist/swarm-fs-path.d.ts +17 -0
- package/dist/swarm-fs-path.d.ts.map +1 -0
- package/dist/swarm-fs-path.js +46 -0
- package/dist/swarm-fs-path.js.map +1 -0
- package/dist/swarm-fs.d.ts +9 -0
- package/dist/swarm-fs.d.ts.map +1 -0
- package/dist/swarm-fs.js +21 -0
- package/dist/swarm-fs.js.map +1 -0
- package/dist/swarm-observations.d.ts +6 -0
- package/dist/swarm-observations.d.ts.map +1 -1
- package/dist/swarm-observations.js +28 -8
- package/dist/swarm-observations.js.map +1 -1
- package/dist/swarm.d.ts +192 -17
- package/dist/swarm.d.ts.map +1 -1
- package/dist/swarm.js +1360 -442
- package/dist/swarm.js.map +1 -1
- package/dist/unixfs-tree.d.ts +55 -0
- package/dist/unixfs-tree.d.ts.map +1 -1
- package/dist/unixfs-tree.js +361 -2
- package/dist/unixfs-tree.js.map +1 -1
- package/package.json +5 -5
- package/src/authoring.ts +125 -8
- package/src/cli.ts +1215 -281
- package/src/config-secret.ts +1 -1
- package/src/config.ts +20 -2
- package/src/daemon-ui.ts +3 -0
- package/src/doctor.ts +12 -2
- package/src/get.ts +2 -1
- package/src/history.ts +26 -1
- package/src/kubo-topology.ts +25 -22
- package/src/kubo.ts +127 -9
- package/src/name-reference.ts +91 -0
- package/src/pivot-rpc.ts +272 -14
- package/src/search-index.ts +1 -0
- package/src/skill-definition.ts +45 -3
- package/src/skill-source.ts +10 -4
- package/src/skills.ts +43 -2
- package/src/state.ts +117 -2
- package/src/swarm-fs-core.ts +1461 -0
- package/src/swarm-fs-path.ts +68 -0
- package/src/swarm-fs.ts +104 -0
- package/src/swarm-observations.ts +40 -14
- package/src/swarm.ts +1950 -727
- package/src/unixfs-tree.ts +447 -2
package/src/state.ts
CHANGED
|
@@ -4,6 +4,10 @@ import { DatabaseSync } from "node:sqlite";
|
|
|
4
4
|
import { CID } from "multiformats/cid";
|
|
5
5
|
import type { StoreConfiguration } from "@ipab/ipfs-store";
|
|
6
6
|
import {
|
|
7
|
+
LOCAL_SWARM_ALIAS,
|
|
8
|
+
LOCAL_SWARM_URL,
|
|
9
|
+
isLocalSwarm,
|
|
10
|
+
isReservedLocalHost,
|
|
7
11
|
rejectLegacySwarmCid,
|
|
8
12
|
validateUserConfig,
|
|
9
13
|
swarmUrl,
|
|
@@ -35,6 +39,13 @@ export interface RegisteredSwarm {
|
|
|
35
39
|
// Keep the storage column name, but values are configuration URLs; old CID rows are rejected.
|
|
36
40
|
cid: string;
|
|
37
41
|
alias: string | null;
|
|
42
|
+
local?: boolean;
|
|
43
|
+
}
|
|
44
|
+
export interface LocalSwarmRecord {
|
|
45
|
+
headCid: string;
|
|
46
|
+
valueCid: string;
|
|
47
|
+
createdAt: string;
|
|
48
|
+
updatedAt: string;
|
|
38
49
|
}
|
|
39
50
|
export interface SwarmProjection {
|
|
40
51
|
account: string;
|
|
@@ -271,7 +282,8 @@ export class State {
|
|
|
271
282
|
CREATE INDEX IF NOT EXISTS idx_swarm_search_entries_swarm_kind ON swarm_search_entries (swarm,kind);
|
|
272
283
|
CREATE INDEX IF NOT EXISTS idx_swarm_search_entries_swarm_schema ON swarm_search_entries (swarm,schema_cid);
|
|
273
284
|
CREATE TABLE IF NOT EXISTS runs (id TEXT PRIMARY KEY, value TEXT NOT NULL);
|
|
274
|
-
CREATE TABLE IF NOT EXISTS holds (owner TEXT PRIMARY KEY, value TEXT NOT NULL)
|
|
285
|
+
CREATE TABLE IF NOT EXISTS holds (owner TEXT PRIMARY KEY, value TEXT NOT NULL);
|
|
286
|
+
CREATE TABLE IF NOT EXISTS local_swarm (id INTEGER PRIMARY KEY CHECK (id = 1), head_cid TEXT NOT NULL, value_cid TEXT NOT NULL, created_at TEXT NOT NULL, updated_at TEXT NOT NULL);`);
|
|
275
287
|
this.transaction(() => {
|
|
276
288
|
if (
|
|
277
289
|
this.db
|
|
@@ -396,6 +408,84 @@ export class State {
|
|
|
396
408
|
resetConfig(key: ConfigKey | "store.rpc"): void {
|
|
397
409
|
this.db.prepare("DELETE FROM config WHERE key=?").run(key);
|
|
398
410
|
}
|
|
411
|
+
localSwarmHead(): LocalSwarmRecord | undefined {
|
|
412
|
+
const row = this.db
|
|
413
|
+
.prepare(
|
|
414
|
+
"SELECT head_cid, value_cid, created_at, updated_at FROM local_swarm WHERE id = 1",
|
|
415
|
+
)
|
|
416
|
+
.get();
|
|
417
|
+
if (!row) return undefined;
|
|
418
|
+
if (
|
|
419
|
+
typeof row.head_cid !== "string" ||
|
|
420
|
+
typeof row.value_cid !== "string" ||
|
|
421
|
+
typeof row.created_at !== "string" ||
|
|
422
|
+
typeof row.updated_at !== "string"
|
|
423
|
+
)
|
|
424
|
+
throw new HostError("Invalid persisted local Swarm HEAD.");
|
|
425
|
+
return {
|
|
426
|
+
headCid: exactCid(row.head_cid),
|
|
427
|
+
valueCid: exactCid(row.value_cid),
|
|
428
|
+
createdAt: row.created_at,
|
|
429
|
+
updatedAt: row.updated_at,
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
initLocalSwarmHead(record: LocalSwarmRecord): {
|
|
433
|
+
record: LocalSwarmRecord;
|
|
434
|
+
inserted: boolean;
|
|
435
|
+
} {
|
|
436
|
+
const headCid = exactCid(record.headCid);
|
|
437
|
+
const valCid = exactCid(record.valueCid);
|
|
438
|
+
return this.transaction(() => {
|
|
439
|
+
const result = this.db
|
|
440
|
+
.prepare(
|
|
441
|
+
"INSERT OR IGNORE INTO local_swarm (id, head_cid, value_cid, created_at, updated_at) VALUES (1, ?, ?, ?, ?)",
|
|
442
|
+
)
|
|
443
|
+
.run(headCid, valCid, record.createdAt, record.updatedAt);
|
|
444
|
+
if (result.changes > 0) {
|
|
445
|
+
return {
|
|
446
|
+
record: {
|
|
447
|
+
headCid,
|
|
448
|
+
valueCid: valCid,
|
|
449
|
+
createdAt: record.createdAt,
|
|
450
|
+
updatedAt: record.updatedAt,
|
|
451
|
+
},
|
|
452
|
+
inserted: true,
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
return {
|
|
456
|
+
record: this.localSwarmHead()!,
|
|
457
|
+
inserted: false,
|
|
458
|
+
};
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
compareAndSwapLocalSwarmHead(
|
|
462
|
+
expectedValueCid: string,
|
|
463
|
+
next: { headCid: string; valueCid: string; updatedAt: string },
|
|
464
|
+
): boolean {
|
|
465
|
+
const headCid = exactCid(next.headCid);
|
|
466
|
+
const valCid = exactCid(next.valueCid);
|
|
467
|
+
const expected = exactCid(expectedValueCid);
|
|
468
|
+
return this.transaction(() => {
|
|
469
|
+
const result = this.db
|
|
470
|
+
.prepare(
|
|
471
|
+
"UPDATE local_swarm SET head_cid = ?, value_cid = ?, updated_at = ? WHERE id = 1 AND value_cid = ?",
|
|
472
|
+
)
|
|
473
|
+
.run(headCid, valCid, next.updatedAt, expected);
|
|
474
|
+
return result.changes > 0;
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
private rejectReservedRemoteAlias(alias: string): void {
|
|
478
|
+
if (alias === LOCAL_SWARM_ALIAS)
|
|
479
|
+
throw new HostError(
|
|
480
|
+
`Swarm alias "${LOCAL_SWARM_ALIAS}" is reserved for the built-in local Swarm.`,
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
private rejectReservedRemoteUrl(url: string): void {
|
|
484
|
+
if (isLocalSwarm(url) || isReservedLocalHost(url))
|
|
485
|
+
throw new HostError(
|
|
486
|
+
`Swarm URL "${url}" uses the reserved .invalid domain and cannot be registered as a remote Swarm.`,
|
|
487
|
+
);
|
|
488
|
+
}
|
|
399
489
|
swarms(): RegisteredSwarm[] {
|
|
400
490
|
return this.db
|
|
401
491
|
.prepare("SELECT cid,alias FROM swarms ORDER BY cid")
|
|
@@ -407,11 +497,25 @@ export class State {
|
|
|
407
497
|
)
|
|
408
498
|
throw new HostError("Invalid persisted swarm registration.");
|
|
409
499
|
const cid = swarmUrl(row.cid);
|
|
410
|
-
if (
|
|
500
|
+
if (isLocalSwarm(cid) || isReservedLocalHost(cid))
|
|
501
|
+
throw new HostError("Invalid persisted swarm registration.");
|
|
502
|
+
if (row.alias !== null) {
|
|
503
|
+
swarmAlias(row.alias);
|
|
504
|
+
if (row.alias === LOCAL_SWARM_ALIAS)
|
|
505
|
+
throw new HostError("Invalid persisted swarm registration.");
|
|
506
|
+
}
|
|
411
507
|
return { cid, alias: row.alias };
|
|
412
508
|
});
|
|
413
509
|
}
|
|
510
|
+
allSwarms(): RegisteredSwarm[] {
|
|
511
|
+
return [
|
|
512
|
+
{ cid: LOCAL_SWARM_URL, alias: LOCAL_SWARM_ALIAS, local: true },
|
|
513
|
+
...this.swarms(),
|
|
514
|
+
];
|
|
515
|
+
}
|
|
414
516
|
resolveSwarm(reference: string): string {
|
|
517
|
+
if (reference === LOCAL_SWARM_ALIAS || reference === LOCAL_SWARM_URL)
|
|
518
|
+
return LOCAL_SWARM_URL;
|
|
415
519
|
if (/^https?:/.test(reference)) return swarmUrl(reference);
|
|
416
520
|
const entry = this.swarms().find((entry) => entry.alias === reference);
|
|
417
521
|
if (entry) return entry.cid;
|
|
@@ -422,6 +526,8 @@ export class State {
|
|
|
422
526
|
}
|
|
423
527
|
registeredSwarm(reference: string): RegisteredSwarm {
|
|
424
528
|
const cid = this.resolveSwarm(reference);
|
|
529
|
+
if (isLocalSwarm(cid))
|
|
530
|
+
return { cid: LOCAL_SWARM_URL, alias: LOCAL_SWARM_ALIAS, local: true };
|
|
425
531
|
const entry = this.swarms().find((entry) => entry.cid === cid);
|
|
426
532
|
if (!entry)
|
|
427
533
|
throw new HostError(
|
|
@@ -431,6 +537,7 @@ export class State {
|
|
|
431
537
|
}
|
|
432
538
|
checkSwarmAlias(alias: string, cid?: string): void {
|
|
433
539
|
swarmAlias(alias);
|
|
540
|
+
this.rejectReservedRemoteAlias(alias);
|
|
434
541
|
const existing = this.swarms().find((entry) => entry.alias === alias);
|
|
435
542
|
if (existing && existing.cid !== cid)
|
|
436
543
|
throw new HostError(
|
|
@@ -439,6 +546,7 @@ export class State {
|
|
|
439
546
|
}
|
|
440
547
|
registerSwarm(cid: string, alias?: string): RegisteredSwarm {
|
|
441
548
|
cid = swarmUrl(cid);
|
|
549
|
+
this.rejectReservedRemoteUrl(cid);
|
|
442
550
|
return this.transaction(() => {
|
|
443
551
|
if (alias !== undefined) this.checkSwarmAlias(alias, cid);
|
|
444
552
|
return this.saveSwarmRegistration(cid, alias);
|
|
@@ -450,7 +558,9 @@ export class State {
|
|
|
450
558
|
expectedTarget: string | null,
|
|
451
559
|
): RegisteredSwarm {
|
|
452
560
|
swarmAlias(alias);
|
|
561
|
+
this.rejectReservedRemoteAlias(alias);
|
|
453
562
|
url = swarmUrl(url);
|
|
563
|
+
this.rejectReservedRemoteUrl(url);
|
|
454
564
|
return this.transaction(() => {
|
|
455
565
|
const current = this.swarms().find((entry) => entry.alias === alias);
|
|
456
566
|
if ((current?.cid ?? null) !== expectedTarget)
|
|
@@ -483,6 +593,11 @@ export class State {
|
|
|
483
593
|
}
|
|
484
594
|
removeSwarm(reference: string): string {
|
|
485
595
|
return this.transaction(() => {
|
|
596
|
+
const cid = this.resolveSwarm(reference);
|
|
597
|
+
if (isLocalSwarm(cid))
|
|
598
|
+
throw new HostError(
|
|
599
|
+
`Cannot remove the built-in "${LOCAL_SWARM_ALIAS}" Swarm.`,
|
|
600
|
+
);
|
|
486
601
|
const entry = this.registeredSwarm(reference);
|
|
487
602
|
this.db.prepare("DELETE FROM swarms WHERE cid=?").run(entry.cid);
|
|
488
603
|
this.deleteSwarmCache(entry.cid);
|