@silvermoon-work/task-builder 0.0.0 → 0.1.0-canary-261109-2
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/LICENSE +22 -0
- package/README.md +283 -3
- package/dist/car.d.ts +37 -0
- package/dist/car.d.ts.map +1 -0
- package/dist/car.js +419 -0
- package/dist/car.js.map +1 -0
- package/dist/contract.d.ts +7 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +146 -0
- package/dist/contract.js.map +1 -0
- package/dist/esbuild.d.ts +14 -0
- package/dist/esbuild.d.ts.map +1 -0
- package/dist/esbuild.js +249 -0
- package/dist/esbuild.js.map +1 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +243 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +10 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +100 -0
- package/dist/init.js.map +1 -0
- package/dist/streams.d.ts +3 -0
- package/dist/streams.d.ts.map +1 -0
- package/dist/streams.js +84 -0
- package/dist/streams.js.map +1 -0
- package/dist/tree.d.ts +24 -0
- package/dist/tree.d.ts.map +1 -0
- package/dist/tree.js +196 -0
- package/dist/tree.js.map +1 -0
- package/examples/echo/assets/greeting.txt +1 -0
- package/examples/echo/src/contract.json +15 -0
- package/examples/echo/src/main.ts +18 -0
- package/examples/echo/task.build.yaml +12 -0
- package/package.json +68 -6
package/dist/car.js
ADDED
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
import { CarBlockIterator } from "@ipld/car/iterator";
|
|
2
|
+
import { blockLength, createWriter, headerLength } from "@ipld/car/buffer-writer";
|
|
3
|
+
import * as dagPb from "@ipld/dag-pb";
|
|
4
|
+
import { CID } from "multiformats/cid";
|
|
5
|
+
import { sha256 } from "multiformats/hashes/sha2";
|
|
6
|
+
import { importer } from "ipfs-unixfs-importer";
|
|
7
|
+
import { fixedSize } from "ipfs-unixfs-importer/chunker";
|
|
8
|
+
import { balanced } from "ipfs-unixfs-importer/layout";
|
|
9
|
+
import { exporter } from "ipfs-unixfs-exporter";
|
|
10
|
+
import { createTaskTextNormalizer, isTaskBundlePath, parseTaskBundleYaml, readTaskBundle, taskBundleLimits, validateTaskBundle, validateTaskBundleFiles, } from "@silvermoon-work/task-protocol";
|
|
11
|
+
import { fileTree, iteratorStream, listTree, readBytes, streamChunks, } from "./tree.js";
|
|
12
|
+
function limitsFor(options) {
|
|
13
|
+
const files = {
|
|
14
|
+
bytes: taskBundleLimits.bytes,
|
|
15
|
+
fileBytes: taskBundleLimits.fileBytes,
|
|
16
|
+
files: taskBundleLimits.files,
|
|
17
|
+
paths: taskBundleLimits.paths,
|
|
18
|
+
...options.fileLimits,
|
|
19
|
+
};
|
|
20
|
+
const limits = {
|
|
21
|
+
maxCarBytes: options.maxCarBytes ?? taskBundleLimits.archiveBytes,
|
|
22
|
+
retainedBytes: options.retainedBytes ?? taskBundleLimits.archiveBytes,
|
|
23
|
+
maxBlocks: options.maxBlocks ?? 16_384,
|
|
24
|
+
maxBlockBytes: options.maxBlockBytes ?? 2 * 1024 * 1024,
|
|
25
|
+
files,
|
|
26
|
+
};
|
|
27
|
+
for (const value of [
|
|
28
|
+
limits.maxCarBytes,
|
|
29
|
+
limits.retainedBytes,
|
|
30
|
+
limits.maxBlocks,
|
|
31
|
+
limits.maxBlockBytes,
|
|
32
|
+
...Object.values(files),
|
|
33
|
+
])
|
|
34
|
+
if (!Number.isSafeInteger(value) || value <= 0)
|
|
35
|
+
throw new Error("Invalid CAR byte/block/file limit.");
|
|
36
|
+
for (const key of ["bytes", "fileBytes", "files", "paths"])
|
|
37
|
+
if (files[key] > taskBundleLimits[key])
|
|
38
|
+
throw new Error("CAR file limits cannot exceed the Bundle protocol.");
|
|
39
|
+
if (limits.maxCarBytes > taskBundleLimits.archiveBytes)
|
|
40
|
+
throw new Error("CAR archive limit cannot exceed the Bundle protocol.");
|
|
41
|
+
return limits;
|
|
42
|
+
}
|
|
43
|
+
class BlockStore {
|
|
44
|
+
limits;
|
|
45
|
+
blocks = new Map();
|
|
46
|
+
closed = false;
|
|
47
|
+
retainedBytes = 0;
|
|
48
|
+
constructor(limits) {
|
|
49
|
+
this.limits = limits;
|
|
50
|
+
}
|
|
51
|
+
get size() {
|
|
52
|
+
return this.blocks.size;
|
|
53
|
+
}
|
|
54
|
+
check(options = {}) {
|
|
55
|
+
options.signal?.throwIfAborted();
|
|
56
|
+
if (this.closed)
|
|
57
|
+
throw new Error("CAR blockstore is closed.");
|
|
58
|
+
}
|
|
59
|
+
async put(cid, value, options = {}) {
|
|
60
|
+
this.check(options);
|
|
61
|
+
const parts = [];
|
|
62
|
+
let length = 0;
|
|
63
|
+
for await (const part of value instanceof Uint8Array ? [value] : value) {
|
|
64
|
+
this.check(options);
|
|
65
|
+
length += part.byteLength;
|
|
66
|
+
if (length > this.limits.maxBlockBytes)
|
|
67
|
+
throw new Error("CAR block exceeds byte capacity.");
|
|
68
|
+
parts.push(Uint8Array.from(part));
|
|
69
|
+
}
|
|
70
|
+
const key = cid.toV1().toString();
|
|
71
|
+
if (this.blocks.has(key))
|
|
72
|
+
return cid;
|
|
73
|
+
if (this.blocks.size >= this.limits.maxBlocks)
|
|
74
|
+
throw new Error("CAR exceeds block capacity.");
|
|
75
|
+
if (this.retainedBytes + length > this.limits.retainedBytes)
|
|
76
|
+
throw new Error("CAR retained blocks exceed byte capacity.");
|
|
77
|
+
this.blocks.set(key, Buffer.concat(parts, length));
|
|
78
|
+
this.retainedBytes += length;
|
|
79
|
+
return cid;
|
|
80
|
+
}
|
|
81
|
+
bytes(cid, options = {}) {
|
|
82
|
+
this.check(options);
|
|
83
|
+
const bytes = this.blocks.get(cid.toV1().toString());
|
|
84
|
+
if (!bytes)
|
|
85
|
+
throw new Error(`CAR is missing block ${cid}.`);
|
|
86
|
+
return bytes;
|
|
87
|
+
}
|
|
88
|
+
async *get(cid, options = {}) {
|
|
89
|
+
yield this.bytes(cid, options);
|
|
90
|
+
}
|
|
91
|
+
close() {
|
|
92
|
+
this.closed = true;
|
|
93
|
+
this.blocks.clear();
|
|
94
|
+
this.retainedBytes = 0;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async function treePaths(tree, limits, options) {
|
|
98
|
+
const files = [];
|
|
99
|
+
let paths = 0;
|
|
100
|
+
const walk = async (path) => {
|
|
101
|
+
const entries = await listTree(tree, path, options);
|
|
102
|
+
if (path && !entries.length)
|
|
103
|
+
throw new Error(`Bundle contains an empty directory: ${path}`);
|
|
104
|
+
for (const entry of entries) {
|
|
105
|
+
const child = path ? `${path}/${entry.name}` : entry.name;
|
|
106
|
+
if (!isTaskBundlePath(child))
|
|
107
|
+
throw new Error(`Unsafe Bundle path: ${child}`);
|
|
108
|
+
if (++paths > limits.files.paths)
|
|
109
|
+
throw new Error("Bundle exceeds path capacity.");
|
|
110
|
+
if (entry.kind === "directory")
|
|
111
|
+
await walk(child);
|
|
112
|
+
else {
|
|
113
|
+
files.push(child);
|
|
114
|
+
if (files.length > limits.files.files)
|
|
115
|
+
throw new Error("Bundle exceeds file capacity.");
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
await walk("");
|
|
120
|
+
return files.sort();
|
|
121
|
+
}
|
|
122
|
+
async function importTree(tree, paths, store, limits, options) {
|
|
123
|
+
let total = 0;
|
|
124
|
+
async function* content(path) {
|
|
125
|
+
let length = 0;
|
|
126
|
+
for await (const chunk of streamChunks(await tree.read(path, options), options, (bytes) => {
|
|
127
|
+
length += bytes;
|
|
128
|
+
total += bytes;
|
|
129
|
+
if (length > limits.files.fileBytes || total > limits.files.bytes)
|
|
130
|
+
throw new Error(`Bundle exceeds byte capacity: ${path}`);
|
|
131
|
+
})) {
|
|
132
|
+
yield chunk;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
async function* candidates() {
|
|
136
|
+
for (const path of paths) {
|
|
137
|
+
options.signal?.throwIfAborted();
|
|
138
|
+
yield { path, content: content(path) };
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
let root;
|
|
142
|
+
for await (const entry of importer(candidates(), store, {
|
|
143
|
+
cidVersion: 1,
|
|
144
|
+
rawLeaves: true,
|
|
145
|
+
wrapWithDirectory: true,
|
|
146
|
+
reduceSingleLeafToSelf: true,
|
|
147
|
+
shardSplitThresholdBytes: Number.MAX_SAFE_INTEGER,
|
|
148
|
+
fileImportConcurrency: 1,
|
|
149
|
+
blockWriteConcurrency: 1,
|
|
150
|
+
chunker: fixedSize({ chunkSize: 262_144 }),
|
|
151
|
+
layout: balanced({ maxChildrenPerNode: 174 }),
|
|
152
|
+
})) {
|
|
153
|
+
options.signal?.throwIfAborted();
|
|
154
|
+
root = entry.cid;
|
|
155
|
+
}
|
|
156
|
+
if (!root)
|
|
157
|
+
throw new Error("Bundle requires a nonempty file tree.");
|
|
158
|
+
return root;
|
|
159
|
+
}
|
|
160
|
+
async function* walkBlocks(root, store, options, seen = new Set(), depth = 0) {
|
|
161
|
+
if (depth > 64)
|
|
162
|
+
throw new Error("CAR DAG exceeds depth capacity.");
|
|
163
|
+
const key = root.toV1().toString();
|
|
164
|
+
if (seen.has(key))
|
|
165
|
+
return;
|
|
166
|
+
seen.add(key);
|
|
167
|
+
const bytes = store.bytes(root, options);
|
|
168
|
+
yield { cid: root, bytes };
|
|
169
|
+
if (root.code === dagPb.code)
|
|
170
|
+
for (const link of dagPb.decode(bytes).Links)
|
|
171
|
+
yield* walkBlocks(link.Hash, store, options, seen, depth + 1);
|
|
172
|
+
else if (root.code !== 0x55)
|
|
173
|
+
throw new Error("Unsupported CAR block codec.");
|
|
174
|
+
}
|
|
175
|
+
async function storedTree(root, store, limits, options) {
|
|
176
|
+
const readers = new Map();
|
|
177
|
+
let paths = 0;
|
|
178
|
+
const walk = async (cid, path) => {
|
|
179
|
+
if (path) {
|
|
180
|
+
if (!isTaskBundlePath(path))
|
|
181
|
+
throw new Error(`Unsafe CAR path: ${path}`);
|
|
182
|
+
if (++paths > limits.files.paths)
|
|
183
|
+
throw new Error("CAR tree exceeds path capacity.");
|
|
184
|
+
}
|
|
185
|
+
const entry = await exporter(cid, store, options);
|
|
186
|
+
if (entry.type === "directory") {
|
|
187
|
+
let children = 0;
|
|
188
|
+
for await (const child of entry.entries(options)) {
|
|
189
|
+
if (!child.name || child.name.includes("/") || child.name.includes("\\"))
|
|
190
|
+
throw new Error("CAR contains an unsafe directory name.");
|
|
191
|
+
await walk(child.cid, path ? `${path}/${child.name}` : child.name);
|
|
192
|
+
children++;
|
|
193
|
+
}
|
|
194
|
+
if (path && !children)
|
|
195
|
+
throw new Error("CAR contains an empty directory.");
|
|
196
|
+
if (!path && !children)
|
|
197
|
+
throw new Error("CAR root must not be empty.");
|
|
198
|
+
}
|
|
199
|
+
else if (path &&
|
|
200
|
+
(entry.type === "raw" ||
|
|
201
|
+
(entry.type === "file" && ["file", "raw"].includes(entry.unixfs.type)))) {
|
|
202
|
+
if (readers.has(path))
|
|
203
|
+
throw new Error(`Duplicate CAR file: ${path}`);
|
|
204
|
+
if (readers.size >= limits.files.files)
|
|
205
|
+
throw new Error("CAR tree exceeds file capacity.");
|
|
206
|
+
const size = entry.type === "raw" ? BigInt(entry.size) : entry.unixfs.fileSize();
|
|
207
|
+
if (size > BigInt(limits.files.fileBytes))
|
|
208
|
+
throw new Error(`CAR file exceeds capacity: ${path}`);
|
|
209
|
+
readers.set(path, (readOptions) => {
|
|
210
|
+
store.check(readOptions);
|
|
211
|
+
async function* ranges() {
|
|
212
|
+
const file = await exporter(cid, store, readOptions);
|
|
213
|
+
if (file.type !== "raw" && file.type !== "file")
|
|
214
|
+
throw new Error("CAR file changed kind.");
|
|
215
|
+
for (let offset = 0n; offset < size; offset += 262144n) {
|
|
216
|
+
const length = Number(size - offset > 262144n ? 262144n : size - offset);
|
|
217
|
+
for await (const chunk of file.content({
|
|
218
|
+
...readOptions,
|
|
219
|
+
offset: Number(offset),
|
|
220
|
+
length,
|
|
221
|
+
blockReadConcurrency: 1,
|
|
222
|
+
})) {
|
|
223
|
+
store.check(readOptions);
|
|
224
|
+
yield Uint8Array.from(chunk);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return iteratorStream(ranges(), readOptions);
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
else
|
|
232
|
+
throw new Error("CAR requires a directory of regular UnixFS files.");
|
|
233
|
+
};
|
|
234
|
+
await walk(root, "");
|
|
235
|
+
const tree = fileTree(readers);
|
|
236
|
+
return {
|
|
237
|
+
paths: [...readers.keys()].sort(),
|
|
238
|
+
tree: Object.freeze({
|
|
239
|
+
async list(path, readOptions = {}) {
|
|
240
|
+
store.check(readOptions);
|
|
241
|
+
return tree.list(path, readOptions);
|
|
242
|
+
},
|
|
243
|
+
async read(path, readOptions = {}) {
|
|
244
|
+
store.check(readOptions);
|
|
245
|
+
return tree.read(path, readOptions);
|
|
246
|
+
},
|
|
247
|
+
}),
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
async function inspectTree(tree, paths, limits, options) {
|
|
251
|
+
const manifest = await readBytes(tree, "task.yaml", 65_536, options);
|
|
252
|
+
const declaration = validateTaskBundle(parseTaskBundleYaml(manifest));
|
|
253
|
+
validateTaskBundleFiles(declaration, paths);
|
|
254
|
+
const binary = new Set(declaration.binary);
|
|
255
|
+
const controls = new Map();
|
|
256
|
+
let total = 0;
|
|
257
|
+
for (const path of paths) {
|
|
258
|
+
let length = 0;
|
|
259
|
+
const parts = [];
|
|
260
|
+
const control = path === "task.yaml" || path.startsWith("schemas/");
|
|
261
|
+
const normalizer = binary.has(path) ? undefined : createTaskTextNormalizer(path);
|
|
262
|
+
for await (const chunk of streamChunks(await tree.read(path, options), options)) {
|
|
263
|
+
length += chunk.byteLength;
|
|
264
|
+
total += chunk.byteLength;
|
|
265
|
+
if (length > limits.files.fileBytes || total > limits.files.bytes)
|
|
266
|
+
throw new Error(`Bundle exceeds byte capacity: ${path}`);
|
|
267
|
+
if (normalizer) {
|
|
268
|
+
normalizer.push(chunk);
|
|
269
|
+
if (chunk.includes(13))
|
|
270
|
+
throw new Error(`Non-LF text in Bundle file: ${path}`);
|
|
271
|
+
}
|
|
272
|
+
if (control)
|
|
273
|
+
parts.push(chunk);
|
|
274
|
+
}
|
|
275
|
+
normalizer?.finish();
|
|
276
|
+
if (path === "worker.cjs" && !length)
|
|
277
|
+
throw new Error("Bundle Worker must not be empty.");
|
|
278
|
+
controls.set(path, control
|
|
279
|
+
? Buffer.concat(parts, length)
|
|
280
|
+
: path === "worker.cjs"
|
|
281
|
+
? Uint8Array.of(32)
|
|
282
|
+
: new Uint8Array());
|
|
283
|
+
}
|
|
284
|
+
const checked = readTaskBundle(controls, limits.files);
|
|
285
|
+
return { ...checked, bytes: total, files: paths.length };
|
|
286
|
+
}
|
|
287
|
+
/** Stage bounded UnixFS blocks from file streams, then emit CAR v1 records on demand. */
|
|
288
|
+
export async function encodeTaskBundleCar(input, options = {}) {
|
|
289
|
+
options.signal?.throwIfAborted();
|
|
290
|
+
const limits = limitsFor(options);
|
|
291
|
+
const store = new BlockStore(limits);
|
|
292
|
+
const lifetime = new AbortController();
|
|
293
|
+
const signal = options.signal
|
|
294
|
+
? AbortSignal.any([options.signal, lifetime.signal])
|
|
295
|
+
: lifetime.signal;
|
|
296
|
+
try {
|
|
297
|
+
const paths = await treePaths(input, limits, { signal });
|
|
298
|
+
const root = await importTree(input, paths, store, limits, { signal });
|
|
299
|
+
const stored = await storedTree(root, store, limits, { signal });
|
|
300
|
+
await inspectTree(stored.tree, stored.paths, limits, { signal });
|
|
301
|
+
const headerSize = headerLength({ roots: [root] });
|
|
302
|
+
let size = headerSize;
|
|
303
|
+
for await (const block of walkBlocks(root, store, { signal }))
|
|
304
|
+
size += blockLength(block);
|
|
305
|
+
if (size > limits.maxCarBytes)
|
|
306
|
+
throw new Error("CAR archive exceeds byte capacity.");
|
|
307
|
+
async function* output() {
|
|
308
|
+
signal.throwIfAborted();
|
|
309
|
+
yield createWriter(new ArrayBuffer(headerSize), { roots: [root] }).close();
|
|
310
|
+
for await (const block of walkBlocks(root, store, { signal })) {
|
|
311
|
+
// Encode one record, not a complete archive; only the first record has a header.
|
|
312
|
+
const record = createWriter(new ArrayBuffer(blockLength(block)), { headerSize: 0 });
|
|
313
|
+
record.write(block);
|
|
314
|
+
for (let offset = 0; offset < record.bytes.byteLength; offset += 65_536) {
|
|
315
|
+
signal.throwIfAborted();
|
|
316
|
+
yield record.bytes.slice(offset, offset + 65_536);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
const stream = iteratorStream(output(), { signal }, async () => store.close());
|
|
321
|
+
return Object.freeze({
|
|
322
|
+
cid: root.toString(),
|
|
323
|
+
stream,
|
|
324
|
+
get retainedBytes() {
|
|
325
|
+
return store.retainedBytes;
|
|
326
|
+
},
|
|
327
|
+
async close() {
|
|
328
|
+
lifetime.abort(new Error("CAR output is closed."));
|
|
329
|
+
store.close();
|
|
330
|
+
},
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
catch (error) {
|
|
334
|
+
store.close();
|
|
335
|
+
throw error;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
/** Read a complete CAR stream and verify hashes, exact DAG, canonical tree and Bundle bytes. */
|
|
339
|
+
export async function readTaskBundleCar(input, options = {}) {
|
|
340
|
+
options.signal?.throwIfAborted();
|
|
341
|
+
const limits = limitsFor(options);
|
|
342
|
+
const store = new BlockStore(limits);
|
|
343
|
+
let carBytes = 0;
|
|
344
|
+
const source = streamChunks(input, options, (bytes) => {
|
|
345
|
+
carBytes += bytes;
|
|
346
|
+
if (carBytes > limits.maxCarBytes)
|
|
347
|
+
throw new Error("CAR archive exceeds byte capacity.");
|
|
348
|
+
});
|
|
349
|
+
try {
|
|
350
|
+
const iterator = await CarBlockIterator.fromIterable(source);
|
|
351
|
+
const roots = await iterator.getRoots();
|
|
352
|
+
const root = roots[0];
|
|
353
|
+
if (iterator.version !== 1 || roots.length !== 1 || !root)
|
|
354
|
+
throw new Error("Task CAR requires version 1 and exactly one root.");
|
|
355
|
+
if (options.expectedCid !== undefined &&
|
|
356
|
+
!root.toV1().equals(CID.parse(options.expectedCid).toV1()))
|
|
357
|
+
throw new Error("Task CAR root differs from expected CID.");
|
|
358
|
+
let blocks = 0;
|
|
359
|
+
for await (const block of iterator) {
|
|
360
|
+
if (++blocks > limits.maxBlocks)
|
|
361
|
+
throw new Error("CAR exceeds block capacity.");
|
|
362
|
+
if (block.bytes.byteLength > limits.maxBlockBytes)
|
|
363
|
+
throw new Error("CAR block exceeds byte capacity.");
|
|
364
|
+
if (block.cid.multihash.code !== sha256.code || ![0x55, dagPb.code].includes(block.cid.code))
|
|
365
|
+
throw new Error("Unsupported CAR hash or block codec.");
|
|
366
|
+
const digest = await sha256.digest(block.bytes);
|
|
367
|
+
if (!Buffer.from(digest.digest).equals(Buffer.from(block.cid.multihash.digest)))
|
|
368
|
+
throw new Error("CAR block hash verification failed.");
|
|
369
|
+
const before = store.size;
|
|
370
|
+
await store.put(block.cid, block.bytes, options);
|
|
371
|
+
if (store.size === before)
|
|
372
|
+
throw new Error("CAR contains a duplicate block.");
|
|
373
|
+
}
|
|
374
|
+
const reached = new Set();
|
|
375
|
+
for await (const _block of walkBlocks(root, store, options, reached)) {
|
|
376
|
+
/* Verify full DAG. */
|
|
377
|
+
}
|
|
378
|
+
if (reached.size !== store.size)
|
|
379
|
+
throw new Error("CAR contains blocks outside its root DAG.");
|
|
380
|
+
const stored = await storedTree(root, store, limits, options);
|
|
381
|
+
const checked = await inspectTree(stored.tree, stored.paths, limits, options);
|
|
382
|
+
// Canonical re-import computes CIDs without retaining a second copy of the DAG.
|
|
383
|
+
const canonical = await importTree(stored.tree, stored.paths, {
|
|
384
|
+
async put(cid, value, putOptions) {
|
|
385
|
+
store.check(putOptions);
|
|
386
|
+
if (!(value instanceof Uint8Array))
|
|
387
|
+
for await (const _part of value)
|
|
388
|
+
store.check(putOptions);
|
|
389
|
+
return cid;
|
|
390
|
+
},
|
|
391
|
+
}, limits, options);
|
|
392
|
+
if (!canonical.toV1().equals(root.toV1()))
|
|
393
|
+
throw new Error("CAR root is not a canonical Bundle file tree.");
|
|
394
|
+
return Object.freeze({
|
|
395
|
+
cid: root.toV1().toString(),
|
|
396
|
+
tree: stored.tree,
|
|
397
|
+
...checked,
|
|
398
|
+
get retainedBytes() {
|
|
399
|
+
return store.retainedBytes;
|
|
400
|
+
},
|
|
401
|
+
block: Object.freeze({
|
|
402
|
+
async get(reference, readOptions = {}) {
|
|
403
|
+
return Uint8Array.from(store.bytes(CID.parse(reference), readOptions));
|
|
404
|
+
},
|
|
405
|
+
}),
|
|
406
|
+
async close() {
|
|
407
|
+
store.close();
|
|
408
|
+
},
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
catch (error) {
|
|
412
|
+
store.close();
|
|
413
|
+
throw error;
|
|
414
|
+
}
|
|
415
|
+
finally {
|
|
416
|
+
await source.return(undefined);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
//# sourceMappingURL=car.js.map
|
package/dist/car.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"car.js","sourceRoot":"","sources":["../src/car.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAwB,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,QAAQ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AAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC;gBACzE,CAAC;aACF,CAAC;YACF,KAAK,CAAC,KAAK;gBACT,KAAK,CAAC,KAAK,EAAE,CAAC;YAChB,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,KAAK,CAAC,KAAK,EAAE,CAAC;QACd,MAAM,KAAK,CAAC;IACd,CAAC;YAAS,CAAC;QACT,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACjC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type JsonObject } from "@silvermoon-work/task-protocol";
|
|
2
|
+
export declare function toTaskSchema(value: unknown): unknown;
|
|
3
|
+
export declare function contractSchemas(value: unknown): {
|
|
4
|
+
path: string;
|
|
5
|
+
document: JsonObject;
|
|
6
|
+
}[];
|
|
7
|
+
//# sourceMappingURL=contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AACA,OAAO,EAA0B,KAAK,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAuCzF,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAqDpD;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,UAAU,CAAA;CAAE,EAAE,CAyDxF"}
|
package/dist/contract.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { Kind, OptionalKind, ReadonlyKind } from "@sinclair/typebox";
|
|
2
|
+
import { isTaskBundlePath, json } from "@silvermoon-work/task-protocol";
|
|
3
|
+
const kinds = new Set([
|
|
4
|
+
"Object",
|
|
5
|
+
"String",
|
|
6
|
+
"Number",
|
|
7
|
+
"Integer",
|
|
8
|
+
"Boolean",
|
|
9
|
+
"Null",
|
|
10
|
+
"Literal",
|
|
11
|
+
"Array",
|
|
12
|
+
"Tuple",
|
|
13
|
+
"Union",
|
|
14
|
+
"Intersect",
|
|
15
|
+
"Record",
|
|
16
|
+
"Ref",
|
|
17
|
+
"Never",
|
|
18
|
+
]);
|
|
19
|
+
const maps = new Set([
|
|
20
|
+
"properties",
|
|
21
|
+
"patternProperties",
|
|
22
|
+
"$defs",
|
|
23
|
+
"definitions",
|
|
24
|
+
"dependentSchemas",
|
|
25
|
+
]);
|
|
26
|
+
const singles = new Set([
|
|
27
|
+
"items",
|
|
28
|
+
"additionalProperties",
|
|
29
|
+
"unevaluatedProperties",
|
|
30
|
+
"propertyNames",
|
|
31
|
+
"contains",
|
|
32
|
+
"not",
|
|
33
|
+
"if",
|
|
34
|
+
"then",
|
|
35
|
+
"else",
|
|
36
|
+
"unevaluatedItems",
|
|
37
|
+
]);
|
|
38
|
+
const arrays = new Set(["anyOf", "allOf", "oneOf", "prefixItems"]);
|
|
39
|
+
export function toTaskSchema(value) {
|
|
40
|
+
let nodes = 0;
|
|
41
|
+
function visit(value, schema, depth) {
|
|
42
|
+
if (++nodes > 16_384 || depth > 64)
|
|
43
|
+
throw new Error("Contract Schema budget exceeded.");
|
|
44
|
+
if (value === null || typeof value !== "object") {
|
|
45
|
+
if (["function", "symbol", "undefined", "bigint"].includes(typeof value))
|
|
46
|
+
throw new Error("Contract must contain only JSON semantics.");
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
if (Array.isArray(value))
|
|
50
|
+
return value.map((child) => visit(child, schema, depth + 1));
|
|
51
|
+
const node = value;
|
|
52
|
+
for (const symbol of Object.getOwnPropertySymbols(node))
|
|
53
|
+
if (![Kind, OptionalKind, ReadonlyKind, Symbol.for("TypeBox.Hint")].includes(symbol))
|
|
54
|
+
throw new Error("Unsupported TypeBox metadata or transform.");
|
|
55
|
+
if (node[Kind] !== undefined && !kinds.has(String(node[Kind])))
|
|
56
|
+
throw new Error(`Unsupported TypeBox kind: ${String(node[Kind])}.`);
|
|
57
|
+
if (schema &&
|
|
58
|
+
["format", "contentEncoding", "contentMediaType", "contentSchema"].some((key) => Object.hasOwn(node, key)))
|
|
59
|
+
throw new Error("Engine does not enforce format or content annotations.");
|
|
60
|
+
if (schema &&
|
|
61
|
+
node[Kind] === "Tuple" &&
|
|
62
|
+
node.additionalItems !== undefined &&
|
|
63
|
+
node.additionalItems !== false)
|
|
64
|
+
throw new Error("Unsupported TypeBox Tuple additionalItems override.");
|
|
65
|
+
const output = {};
|
|
66
|
+
for (const [key, child] of Object.entries(node)) {
|
|
67
|
+
if (schema && node[Kind] === "Tuple" && (key === "items" || key === "additionalItems"))
|
|
68
|
+
continue;
|
|
69
|
+
let result;
|
|
70
|
+
if (schema && maps.has(key)) {
|
|
71
|
+
if (!child || typeof child !== "object" || Array.isArray(child))
|
|
72
|
+
throw new Error("Invalid Schema map.");
|
|
73
|
+
result = Object.fromEntries(Object.entries(child).map(([name, entry]) => [name, visit(entry, true, depth + 1)]));
|
|
74
|
+
}
|
|
75
|
+
else
|
|
76
|
+
result = visit(child, schema && (singles.has(key) || arrays.has(key)), depth + 1);
|
|
77
|
+
Object.defineProperty(output, key, { value: result, enumerable: true });
|
|
78
|
+
}
|
|
79
|
+
if (schema && node[Kind] === "Tuple") {
|
|
80
|
+
const items = visit(node.items ?? [], true, depth + 1);
|
|
81
|
+
if (!Array.isArray(items))
|
|
82
|
+
throw new Error("Invalid TypeBox Tuple items.");
|
|
83
|
+
if (items.length)
|
|
84
|
+
output.prefixItems = items;
|
|
85
|
+
output.items = false;
|
|
86
|
+
}
|
|
87
|
+
return output;
|
|
88
|
+
}
|
|
89
|
+
return visit(value, true, 0);
|
|
90
|
+
}
|
|
91
|
+
export function contractSchemas(value) {
|
|
92
|
+
if (!value ||
|
|
93
|
+
typeof value !== "object" ||
|
|
94
|
+
Array.isArray(value) ||
|
|
95
|
+
!("input" in value) ||
|
|
96
|
+
!("result" in value) ||
|
|
97
|
+
!("message" in value) ||
|
|
98
|
+
Object.keys(value).some((key) => !["input", "result", "message", "schemas"].includes(key)))
|
|
99
|
+
throw new Error("Contract must contain { input, result, message, schemas? }.");
|
|
100
|
+
const schemas = "schemas" in value ? value.schemas : {};
|
|
101
|
+
if (!schemas || typeof schemas !== "object" || Array.isArray(schemas))
|
|
102
|
+
throw new Error("Contract schemas must be a name-to-Schema object, not an array.");
|
|
103
|
+
const shared = Object.entries(schemas).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
|
|
104
|
+
const names = new Set();
|
|
105
|
+
for (const [name] of shared) {
|
|
106
|
+
if (!name ||
|
|
107
|
+
name.includes("/") ||
|
|
108
|
+
!isTaskBundlePath(name) ||
|
|
109
|
+
!isTaskBundlePath(`schemas/shared/${name}.json`) ||
|
|
110
|
+
names.has(name.toLowerCase()))
|
|
111
|
+
throw new Error(`Shared Schema names must be unique portable file names: ${name}`);
|
|
112
|
+
names.add(name.toLowerCase());
|
|
113
|
+
}
|
|
114
|
+
const entries = [
|
|
115
|
+
{ path: "schemas/input.json", identity: "0", schema: value.input },
|
|
116
|
+
{ path: "schemas/result.json", identity: "1", schema: value.result },
|
|
117
|
+
{ path: "schemas/message.json", identity: "2", schema: value.message },
|
|
118
|
+
...shared.map(([name, schema]) => ({
|
|
119
|
+
path: `schemas/shared/${name}.json`,
|
|
120
|
+
identity: `shared/${encodeURIComponent(name)}`,
|
|
121
|
+
schema,
|
|
122
|
+
})),
|
|
123
|
+
];
|
|
124
|
+
return entries.map(({ path, identity, schema }, index) => {
|
|
125
|
+
const normalized = json(toTaskSchema(schema));
|
|
126
|
+
const id = `https://task.invalid/schema/${identity}`;
|
|
127
|
+
if (typeof normalized === "boolean") {
|
|
128
|
+
if (!index)
|
|
129
|
+
throw new Error("Task input Schema must be an object.");
|
|
130
|
+
return {
|
|
131
|
+
path,
|
|
132
|
+
document: { $id: id, ...(normalized ? {} : { not: {} }) },
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
if (!normalized || typeof normalized !== "object" || Array.isArray(normalized))
|
|
136
|
+
throw new Error("Contract Schema must be an object or boolean.");
|
|
137
|
+
return {
|
|
138
|
+
path,
|
|
139
|
+
document: {
|
|
140
|
+
...normalized,
|
|
141
|
+
$id: normalized.$id ?? id,
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAmB,MAAM,gCAAgC,CAAC;AAEzF,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC;IACpB,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,SAAS;IACT,MAAM;IACN,SAAS;IACT,OAAO;IACP,OAAO;IACP,OAAO;IACP,WAAW;IACX,QAAQ;IACR,KAAK;IACL,OAAO;CACR,CAAC,CAAC;AACH,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC;IACnB,YAAY;IACZ,mBAAmB;IACnB,OAAO;IACP,aAAa;IACb,kBAAkB;CACnB,CAAC,CAAC;AACH,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC;IACtB,OAAO;IACP,sBAAsB;IACtB,uBAAuB;IACvB,eAAe;IACf,UAAU;IACV,KAAK;IACL,IAAI;IACJ,MAAM;IACN,MAAM;IACN,kBAAkB;CACnB,CAAC,CAAC;AACH,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC;AAEnE,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,IAAI,KAAK,GAAG,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
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ResolvedTaskBundle } from "@silvermoon-work/task-protocol";
|
|
2
|
+
import { type ReadonlyFileTree, type ReadOptions } from "./tree.js";
|
|
3
|
+
export interface CompileOptions extends ReadOptions {
|
|
4
|
+
readonly fileBytes: number;
|
|
5
|
+
readonly sourceBytes: number;
|
|
6
|
+
readonly sourceFiles: number;
|
|
7
|
+
readonly traversalPaths: number;
|
|
8
|
+
readonly binding?: ResolvedTaskBundle;
|
|
9
|
+
readonly callbackExport?: string;
|
|
10
|
+
readonly sdk?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function compileTree(tree: ReadonlyFileTree, entry: string, options: CompileOptions): Promise<Uint8Array>;
|
|
13
|
+
export declare function evaluateContract(bytes: Uint8Array): unknown;
|
|
14
|
+
//# sourceMappingURL=esbuild.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esbuild.d.ts","sourceRoot":"","sources":["../src/esbuild.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAkC,KAAK,gBAAgB,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAiCpG,MAAM,WAAW,cAAe,SAAQ,WAAW;IACjD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC;IACtC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,wBAAsB,WAAW,CAC/B,IAAI,EAAE,gBAAgB,EACtB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,UAAU,CAAC,CA0NrB;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAkB3D"}
|