@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.
Files changed (118) hide show
  1. package/README.md +24 -11
  2. package/dist/authoring.d.ts +7 -0
  3. package/dist/authoring.d.ts.map +1 -1
  4. package/dist/authoring.js +85 -5
  5. package/dist/authoring.js.map +1 -1
  6. package/dist/builtins/skill.ipab.car +0 -0
  7. package/dist/builtins/template.bundle-viewer.car +0 -0
  8. package/dist/builtins/template.check.car +0 -0
  9. package/dist/builtins/template.node.car +0 -0
  10. package/dist/builtins/template.web-app.car +0 -0
  11. package/dist/bundled-skills.d.ts +1 -1
  12. package/dist/cli.d.ts +2 -1
  13. package/dist/cli.d.ts.map +1 -1
  14. package/dist/cli.js +904 -183
  15. package/dist/cli.js.map +1 -1
  16. package/dist/config-secret.js +1 -1
  17. package/dist/config-secret.js.map +1 -1
  18. package/dist/config.d.ts +4 -0
  19. package/dist/config.d.ts.map +1 -1
  20. package/dist/config.js +17 -2
  21. package/dist/config.js.map +1 -1
  22. package/dist/daemon-ui.d.ts +1 -0
  23. package/dist/daemon-ui.d.ts.map +1 -1
  24. package/dist/daemon-ui.js +2 -0
  25. package/dist/daemon-ui.js.map +1 -1
  26. package/dist/doctor.d.ts.map +1 -1
  27. package/dist/doctor.js +7 -3
  28. package/dist/doctor.js.map +1 -1
  29. package/dist/get.d.ts.map +1 -1
  30. package/dist/get.js +1 -1
  31. package/dist/get.js.map +1 -1
  32. package/dist/history.d.ts +3 -1
  33. package/dist/history.d.ts.map +1 -1
  34. package/dist/history.js +16 -1
  35. package/dist/history.js.map +1 -1
  36. package/dist/kubo-topology.d.ts +2 -0
  37. package/dist/kubo-topology.d.ts.map +1 -1
  38. package/dist/kubo-topology.js +17 -20
  39. package/dist/kubo-topology.js.map +1 -1
  40. package/dist/kubo.d.ts +5 -3
  41. package/dist/kubo.d.ts.map +1 -1
  42. package/dist/kubo.js +83 -13
  43. package/dist/kubo.js.map +1 -1
  44. package/dist/name-reference.d.ts +8 -0
  45. package/dist/name-reference.d.ts.map +1 -0
  46. package/dist/name-reference.js +63 -0
  47. package/dist/name-reference.js.map +1 -0
  48. package/dist/pivot-rpc.d.ts +37 -2
  49. package/dist/pivot-rpc.d.ts.map +1 -1
  50. package/dist/pivot-rpc.js +188 -8
  51. package/dist/pivot-rpc.js.map +1 -1
  52. package/dist/search-index.d.ts.map +1 -1
  53. package/dist/search-index.js +1 -0
  54. package/dist/search-index.js.map +1 -1
  55. package/dist/skill-definition.d.ts +9 -0
  56. package/dist/skill-definition.d.ts.map +1 -1
  57. package/dist/skill-definition.js +26 -2
  58. package/dist/skill-definition.js.map +1 -1
  59. package/dist/skill-source.d.ts +1 -0
  60. package/dist/skill-source.d.ts.map +1 -1
  61. package/dist/skill-source.js +10 -4
  62. package/dist/skill-source.js.map +1 -1
  63. package/dist/skills.d.ts +9 -3
  64. package/dist/skills.d.ts.map +1 -1
  65. package/dist/skills.js +31 -2
  66. package/dist/skills.js.map +1 -1
  67. package/dist/state.d.ts +20 -0
  68. package/dist/state.d.ts.map +1 -1
  69. package/dist/state.js +87 -3
  70. package/dist/state.js.map +1 -1
  71. package/dist/swarm-fs-core.d.ts +217 -0
  72. package/dist/swarm-fs-core.d.ts.map +1 -0
  73. package/dist/swarm-fs-core.js +885 -0
  74. package/dist/swarm-fs-core.js.map +1 -0
  75. package/dist/swarm-fs-path.d.ts +17 -0
  76. package/dist/swarm-fs-path.d.ts.map +1 -0
  77. package/dist/swarm-fs-path.js +46 -0
  78. package/dist/swarm-fs-path.js.map +1 -0
  79. package/dist/swarm-fs.d.ts +9 -0
  80. package/dist/swarm-fs.d.ts.map +1 -0
  81. package/dist/swarm-fs.js +21 -0
  82. package/dist/swarm-fs.js.map +1 -0
  83. package/dist/swarm-observations.d.ts +6 -0
  84. package/dist/swarm-observations.d.ts.map +1 -1
  85. package/dist/swarm-observations.js +28 -8
  86. package/dist/swarm-observations.js.map +1 -1
  87. package/dist/swarm.d.ts +192 -17
  88. package/dist/swarm.d.ts.map +1 -1
  89. package/dist/swarm.js +1360 -442
  90. package/dist/swarm.js.map +1 -1
  91. package/dist/unixfs-tree.d.ts +55 -0
  92. package/dist/unixfs-tree.d.ts.map +1 -1
  93. package/dist/unixfs-tree.js +361 -2
  94. package/dist/unixfs-tree.js.map +1 -1
  95. package/package.json +5 -5
  96. package/src/authoring.ts +125 -8
  97. package/src/cli.ts +1215 -281
  98. package/src/config-secret.ts +1 -1
  99. package/src/config.ts +20 -2
  100. package/src/daemon-ui.ts +3 -0
  101. package/src/doctor.ts +12 -2
  102. package/src/get.ts +2 -1
  103. package/src/history.ts +26 -1
  104. package/src/kubo-topology.ts +25 -22
  105. package/src/kubo.ts +127 -9
  106. package/src/name-reference.ts +91 -0
  107. package/src/pivot-rpc.ts +272 -14
  108. package/src/search-index.ts +1 -0
  109. package/src/skill-definition.ts +45 -3
  110. package/src/skill-source.ts +10 -4
  111. package/src/skills.ts +43 -2
  112. package/src/state.ts +117 -2
  113. package/src/swarm-fs-core.ts +1461 -0
  114. package/src/swarm-fs-path.ts +68 -0
  115. package/src/swarm-fs.ts +104 -0
  116. package/src/swarm-observations.ts +40 -14
  117. package/src/swarm.ts +1950 -727
  118. 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 (row.alias !== null) swarmAlias(row.alias);
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);