@ipab/cli 0.1.0-rc.0 → 0.1.0-rc.1
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 +7 -1
- package/dist/app-authoring.d.ts +1 -2
- package/dist/app-authoring.d.ts.map +1 -1
- package/dist/app-authoring.js +8 -9
- package/dist/app-authoring.js.map +1 -1
- package/dist/app-definition.d.ts +0 -6
- package/dist/app-definition.d.ts.map +1 -1
- package/dist/app-definition.js +1 -7
- package/dist/app-definition.js.map +1 -1
- package/dist/app-templates.d.ts.map +1 -1
- package/dist/app-templates.js +8 -0
- package/dist/app-templates.js.map +1 -1
- package/dist/authoring.d.ts +5 -14
- package/dist/authoring.d.ts.map +1 -1
- package/dist/authoring.js +10 -39
- package/dist/authoring.js.map +1 -1
- package/dist/builtins/template.node.car +0 -0
- package/dist/builtins/template.web-app.car +0 -0
- package/dist/builtins.d.ts.map +1 -1
- package/dist/builtins.js +5 -10
- package/dist/builtins.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +124 -86
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +3 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +15 -17
- package/dist/config.js.map +1 -1
- package/dist/context.d.ts +1 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +10 -0
- package/dist/context.js.map +1 -1
- package/dist/ipc.d.ts +2 -1
- package/dist/ipc.d.ts.map +1 -1
- package/dist/ipc.js +10 -1
- package/dist/ipc.js.map +1 -1
- package/dist/pins.d.ts +9 -9
- package/dist/pins.d.ts.map +1 -1
- package/dist/pins.js +10 -28
- package/dist/pins.js.map +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +1 -1
- package/dist/runtime.js.map +1 -1
- package/dist/source-bundle.d.ts +0 -1
- package/dist/source-bundle.d.ts.map +1 -1
- package/dist/source-bundle.js +0 -1
- package/dist/source-bundle.js.map +1 -1
- package/dist/state.d.ts +20 -10
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +27 -16
- package/dist/state.js.map +1 -1
- package/dist/template-definition.d.ts +0 -17
- package/dist/template-definition.d.ts.map +1 -1
- package/dist/template-definition.js +1 -10
- package/dist/template-definition.js.map +1 -1
- package/package.json +10 -10
- package/src/app-authoring.ts +15 -13
- package/src/app-definition.ts +1 -7
- package/src/app-templates.ts +13 -0
- package/src/authoring.ts +22 -55
- package/src/builtins.ts +5 -11
- package/src/cli.ts +152 -107
- package/src/config.ts +21 -20
- package/src/context.ts +10 -0
- package/src/ipc.ts +8 -0
- package/src/pins.ts +14 -28
- package/src/runtime.ts +1 -0
- package/src/source-bundle.ts +0 -1
- package/src/state.ts +40 -26
- package/src/template-definition.ts +1 -10
package/src/pins.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { CID } from "multiformats/cid";
|
|
3
3
|
import { IpfsStore } from "@ipab/ipfs-store";
|
|
4
|
-
import {
|
|
4
|
+
import { openBundle } from "@ipab/bundle";
|
|
5
5
|
import { HostError, message } from "./errors.js";
|
|
6
6
|
import { alive, type StoreFactory } from "./history.js";
|
|
7
7
|
import {
|
|
8
8
|
exactCid,
|
|
9
9
|
pinName,
|
|
10
|
+
bundlePinMetadata,
|
|
10
11
|
type NamedPin,
|
|
11
12
|
type PinMetadata,
|
|
12
13
|
type State,
|
|
@@ -20,7 +21,7 @@ export function pinDetails(pin: NamedPin) {
|
|
|
20
21
|
return {
|
|
21
22
|
name: pin.name,
|
|
22
23
|
cid: pin.cid,
|
|
23
|
-
...pin
|
|
24
|
+
...bundlePinMetadata(pin),
|
|
24
25
|
...(pin.builtin ? { builtin: true as const } : {}),
|
|
25
26
|
};
|
|
26
27
|
}
|
|
@@ -46,34 +47,19 @@ function idleHold(state: State, pin: NamedPin) {
|
|
|
46
47
|
return hold;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
async function classify(
|
|
50
|
+
async function classify(
|
|
51
|
+
cid: string,
|
|
52
|
+
store: IpfsStore,
|
|
53
|
+
): Promise<Extract<PinMetadata, { kind: "bundle" }>> {
|
|
50
54
|
const root = CID.parse(cid);
|
|
51
55
|
const resolveCid = (cid: CID, options: { signal?: AbortSignal }) =>
|
|
52
56
|
store.block.get(cid.toString(), options);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
if (root.code === 0x70) {
|
|
62
|
-
const node = await store.read(root);
|
|
63
|
-
if (node.type === "directory") {
|
|
64
|
-
for await (const entry of node.entries()) {
|
|
65
|
-
if (entry.name === ".bundle.yaml") {
|
|
66
|
-
const bundle = await openBundle(root, { resolveCid });
|
|
67
|
-
return {
|
|
68
|
-
kind: "bundle",
|
|
69
|
-
typeName: bundle.manifest.name,
|
|
70
|
-
schemaCid: bundle.schemaKey,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return { kind: "content", typeName: null, schemaCid: null };
|
|
57
|
+
const bundle = await openBundle(root, { resolveCid });
|
|
58
|
+
return {
|
|
59
|
+
kind: "bundle",
|
|
60
|
+
typeName: bundle.manifest.name,
|
|
61
|
+
schemaCid: bundle.schemaKey,
|
|
62
|
+
};
|
|
77
63
|
}
|
|
78
64
|
|
|
79
65
|
export async function addPin(
|
|
@@ -121,8 +107,8 @@ export async function addPin(
|
|
|
121
107
|
try {
|
|
122
108
|
store = factory(state.hold(pin.owner)!.backend);
|
|
123
109
|
await store.recoverOwner(pin.owner, () => state.hold(pin.owner)!.roots);
|
|
124
|
-
await store.retain(pin.owner, [cid]);
|
|
125
110
|
const metadata = await classify(cid, store);
|
|
111
|
+
await store.retain(pin.owner, [cid]);
|
|
126
112
|
state.transaction(() => {
|
|
127
113
|
state.savePin({ ...pin, metadata });
|
|
128
114
|
state.saveHold({ ...state.hold(pin.owner)!, roots: [cid] });
|
package/src/runtime.ts
CHANGED
package/src/source-bundle.ts
CHANGED
package/src/state.ts
CHANGED
|
@@ -42,11 +42,10 @@ export interface Hold {
|
|
|
42
42
|
session: string | null;
|
|
43
43
|
recordId: string | null;
|
|
44
44
|
}
|
|
45
|
-
export
|
|
46
|
-
kind: "bundle"
|
|
47
|
-
typeName: string
|
|
48
|
-
|
|
49
|
-
}
|
|
45
|
+
export type PinMetadata =
|
|
46
|
+
| { kind: "bundle"; typeName: string; schemaCid: string }
|
|
47
|
+
| { kind: "schema"; typeName: string; schemaCid: string }
|
|
48
|
+
| { kind: "content"; typeName: null; schemaCid: null };
|
|
50
49
|
export interface NamedPin {
|
|
51
50
|
name: string;
|
|
52
51
|
cid: string;
|
|
@@ -55,6 +54,17 @@ export interface NamedPin {
|
|
|
55
54
|
metadata: PinMetadata | null;
|
|
56
55
|
builtin?: true;
|
|
57
56
|
}
|
|
57
|
+
export function bundlePinMetadata(pin: NamedPin) {
|
|
58
|
+
if (pin.status !== "ready" || !pin.metadata)
|
|
59
|
+
throw new HostError(
|
|
60
|
+
`Pin "${pin.name}" is ${pin.status}; retry pin add/delete before using it.`,
|
|
61
|
+
);
|
|
62
|
+
if (pin.metadata.kind !== "bundle")
|
|
63
|
+
throw new HostError(
|
|
64
|
+
`Pin "${pin.name}" is not a Bundle pin. Its retention is preserved; run ipab pin delete ${pin.name}, then wrap the content in a Bundle before adding a new pin.`,
|
|
65
|
+
);
|
|
66
|
+
return pin.metadata;
|
|
67
|
+
}
|
|
58
68
|
|
|
59
69
|
export function exactCid(value: string, schema = false): string {
|
|
60
70
|
let cid: CID;
|
|
@@ -88,7 +98,13 @@ export function pinName(value: string, builtin = false): void {
|
|
|
88
98
|
function persistedHold(value: string, owner: string): Hold {
|
|
89
99
|
try {
|
|
90
100
|
const data = object(JSON.parse(value) as unknown, "retention metadata");
|
|
91
|
-
object(data.backend, "original Store configuration");
|
|
101
|
+
const backend = object(data.backend, "original Store configuration");
|
|
102
|
+
if (backend.backend === "kubo")
|
|
103
|
+
throw new HostError(
|
|
104
|
+
"This retention record belongs to the removed Kubo RPC Store. It is not migrated or released. Create a new local pin and manage the old daemon pin independently.",
|
|
105
|
+
1,
|
|
106
|
+
"LEGACY_STORE",
|
|
107
|
+
);
|
|
92
108
|
if (
|
|
93
109
|
data.owner !== owner ||
|
|
94
110
|
!Array.isArray(data.roots) ||
|
|
@@ -101,7 +117,9 @@ function persistedHold(value: string, owner: string): Hold {
|
|
|
101
117
|
throw new Error("Invalid retention fields.");
|
|
102
118
|
for (const root of data.roots as string[]) exactCid(root);
|
|
103
119
|
return data as unknown as Hold;
|
|
104
|
-
} catch {
|
|
120
|
+
} catch (error) {
|
|
121
|
+
if (error instanceof HostError && error.code === "LEGACY_STORE")
|
|
122
|
+
throw error;
|
|
105
123
|
throw new HostError(
|
|
106
124
|
"Invalid persisted retention metadata; cleanup is blocked.",
|
|
107
125
|
1,
|
|
@@ -123,7 +141,7 @@ export class State {
|
|
|
123
141
|
.exec(`PRAGMA busy_timeout=5000; PRAGMA journal_mode=WAL; PRAGMA synchronous=FULL;
|
|
124
142
|
CREATE TABLE IF NOT EXISTS identity (id TEXT NOT NULL);
|
|
125
143
|
CREATE TABLE IF NOT EXISTS config (key TEXT PRIMARY KEY, value TEXT NOT NULL);
|
|
126
|
-
|
|
144
|
+
DROP TABLE IF EXISTS aliases;
|
|
127
145
|
CREATE TABLE IF NOT EXISTS named_pins (name TEXT PRIMARY KEY, owner TEXT UNIQUE NOT NULL, value TEXT NOT NULL);
|
|
128
146
|
CREATE TABLE IF NOT EXISTS registrations (schema_cid TEXT PRIMARY KEY, value TEXT NOT NULL);
|
|
129
147
|
CREATE TABLE IF NOT EXISTS runs (id TEXT PRIMARY KEY, value TEXT NOT NULL);
|
|
@@ -152,6 +170,10 @@ export class State {
|
|
|
152
170
|
}
|
|
153
171
|
config(): Partial<Record<ConfigKey, ConfigValue>> {
|
|
154
172
|
const entries = this.db.prepare("SELECT key,value FROM config").all();
|
|
173
|
+
if (entries.some((row) => row.key === "store.rpc"))
|
|
174
|
+
throw new HostError(
|
|
175
|
+
"store.rpc is no longer supported. Run ipab config reset store.rpc, then configure store.gateway with an HTTP gateway URL. Existing Kubo pins are not migrated or released.",
|
|
176
|
+
);
|
|
155
177
|
try {
|
|
156
178
|
return validateUserConfig(
|
|
157
179
|
Object.fromEntries(
|
|
@@ -172,18 +194,9 @@ export class State {
|
|
|
172
194
|
.prepare("INSERT OR REPLACE INTO config VALUES (?,?)")
|
|
173
195
|
.run(key, JSON.stringify(value));
|
|
174
196
|
}
|
|
175
|
-
resetConfig(key: ConfigKey): void {
|
|
197
|
+
resetConfig(key: ConfigKey | "store.rpc"): void {
|
|
176
198
|
this.db.prepare("DELETE FROM config WHERE key=?").run(key);
|
|
177
199
|
}
|
|
178
|
-
aliases(): { name: string; cid: string }[] {
|
|
179
|
-
return this.db
|
|
180
|
-
.prepare("SELECT name,cid FROM aliases ORDER BY name")
|
|
181
|
-
.all()
|
|
182
|
-
.map((row) => ({
|
|
183
|
-
name: String(row.name),
|
|
184
|
-
cid: exactCid(String(row.cid)),
|
|
185
|
-
}));
|
|
186
|
-
}
|
|
187
200
|
resolve(value: string, schema = false): string {
|
|
188
201
|
try {
|
|
189
202
|
return exactCid(value, schema);
|
|
@@ -193,16 +206,10 @@ export class State {
|
|
|
193
206
|
} catch {
|
|
194
207
|
const pin = this.pin(value);
|
|
195
208
|
if (pin) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
`Pin "${value}" is ${pin.status}; retry pin add/delete before using it.`,
|
|
199
|
-
);
|
|
209
|
+
const metadata = bundlePinMetadata(pin);
|
|
210
|
+
if (schema) return metadata.schemaCid;
|
|
200
211
|
return exactCid(pin.cid, schema);
|
|
201
212
|
}
|
|
202
|
-
if (this.db.prepare("SELECT 1 FROM aliases WHERE name=?").get(value))
|
|
203
|
-
throw new HostError(
|
|
204
|
-
`Legacy Alias "${value}" is not a pin. Read its CID from the preserved aliases table and run ipab pin add NAME CID to verify and retain it.`,
|
|
205
|
-
);
|
|
206
213
|
throw new HostError(
|
|
207
214
|
`Unknown CID or pin "${value}". Run ipab pin list.`,
|
|
208
215
|
);
|
|
@@ -210,6 +217,12 @@ export class State {
|
|
|
210
217
|
throw error;
|
|
211
218
|
}
|
|
212
219
|
}
|
|
220
|
+
resolvePin(name: string): string | undefined {
|
|
221
|
+
const pin = this.pin(name);
|
|
222
|
+
if (!pin) return undefined;
|
|
223
|
+
bundlePinMetadata(pin);
|
|
224
|
+
return exactCid(pin.cid);
|
|
225
|
+
}
|
|
213
226
|
pins(): NamedPin[] {
|
|
214
227
|
const user = this.db
|
|
215
228
|
.prepare("SELECT name,owner,value FROM named_pins ORDER BY name")
|
|
@@ -252,6 +265,7 @@ export class State {
|
|
|
252
265
|
if (
|
|
253
266
|
(value.kind !== "bundle" && value.kind !== "schema") ||
|
|
254
267
|
typeof value.typeName !== "string" ||
|
|
268
|
+
!value.typeName.trim() ||
|
|
255
269
|
typeof value.schemaCid !== "string"
|
|
256
270
|
)
|
|
257
271
|
throw new HostError("Invalid persisted pin type metadata.");
|
|
@@ -19,15 +19,6 @@ export const templateSchema = {
|
|
|
19
19
|
entry: {
|
|
20
20
|
path: "template.yaml",
|
|
21
21
|
contentType: "application/yaml",
|
|
22
|
-
defaultValue: {
|
|
23
|
-
version: 1,
|
|
24
|
-
root: "project",
|
|
25
|
-
render: { suffix: ".liquid" },
|
|
26
|
-
parameters: {
|
|
27
|
-
name: { type: "string", required: true },
|
|
28
|
-
description: { type: "string", default: "" },
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
22
|
schema: {
|
|
32
23
|
$id: "urn:ipab:project-template.v1",
|
|
33
24
|
type: "object",
|
|
@@ -74,7 +65,7 @@ export const templateSchema = {
|
|
|
74
65
|
|
|
75
66
|
export const templateBuiltinAlias = "builtin:project-template.v1";
|
|
76
67
|
export const templateSchemaCid = CID.parse(
|
|
77
|
-
"
|
|
68
|
+
"bafyreihydmyx5qvemxlidzyc7yflwxnidllorpaq7xoxlh264ozjnalqra",
|
|
78
69
|
);
|
|
79
70
|
export async function builtinTemplateSchema() {
|
|
80
71
|
const block = await encodeSchema(templateSchema);
|