wiki-graph-sdk 0.9.0 → 0.9.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/dist/archives.cjs +316 -142
- package/dist/archives.cjs.map +1 -1
- package/dist/archives.js +326 -148
- package/dist/archives.js.map +1 -1
- package/dist/conversions.cjs +268 -99
- package/dist/conversions.cjs.map +1 -1
- package/dist/conversions.js +274 -103
- package/dist/conversions.js.map +1 -1
- package/dist/default-worker.cjs +258 -101
- package/dist/default-worker.cjs.map +1 -1
- package/dist/default-worker.js +264 -105
- package/dist/default-worker.js.map +1 -1
- package/dist/embedding.cjs +214 -54
- package/dist/embedding.cjs.map +1 -1
- package/dist/embedding.js +214 -54
- package/dist/embedding.js.map +1 -1
- package/dist/gc.cjs +214 -54
- package/dist/gc.cjs.map +1 -1
- package/dist/gc.js +214 -54
- package/dist/gc.js.map +1 -1
- package/dist/index.cjs +354 -174
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +369 -184
- package/dist/index.js.map +1 -1
- package/dist/local-config.cjs +214 -54
- package/dist/local-config.cjs.map +1 -1
- package/dist/local-config.js +214 -54
- package/dist/local-config.js.map +1 -1
- package/dist/maintenance.cjs +264 -97
- package/dist/maintenance.cjs.map +1 -1
- package/dist/maintenance.js +270 -101
- package/dist/maintenance.js.map +1 -1
- package/dist/node-platform.cjs +214 -54
- package/dist/node-platform.cjs.map +1 -1
- package/dist/node-platform.d.ts +2 -0
- package/dist/node-platform.js +214 -54
- package/dist/node-platform.js.map +1 -1
- package/dist/runtime-config.cjs +214 -54
- package/dist/runtime-config.cjs.map +1 -1
- package/dist/runtime-config.js +214 -54
- package/dist/runtime-config.js.map +1 -1
- package/dist/stage.cjs +214 -54
- package/dist/stage.cjs.map +1 -1
- package/dist/stage.js +214 -54
- package/dist/stage.js.map +1 -1
- package/dist/worker.cjs +257 -96
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.js +263 -100
- package/dist/worker.js.map +1 -1
- package/package.json +2 -2
package/dist/stage.js
CHANGED
|
@@ -85,6 +85,15 @@ var NodeFile = class {
|
|
|
85
85
|
this.name = name;
|
|
86
86
|
}
|
|
87
87
|
path;
|
|
88
|
+
async getPhysicalIdentity() {
|
|
89
|
+
const value = await fsPromises.stat(this.path).catch((error) => {
|
|
90
|
+
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT")
|
|
91
|
+
return void 0;
|
|
92
|
+
throw error;
|
|
93
|
+
});
|
|
94
|
+
if (value === void 0) return void 0;
|
|
95
|
+
return `${value.dev}:${value.ino}`;
|
|
96
|
+
}
|
|
88
97
|
kind = "file";
|
|
89
98
|
[NODE_RESOURCE_KIND] = "file";
|
|
90
99
|
identity;
|
|
@@ -209,6 +218,15 @@ var NodeDirectory = class _NodeDirectory {
|
|
|
209
218
|
this.name = pathModule.basename(path);
|
|
210
219
|
}
|
|
211
220
|
path;
|
|
221
|
+
async getPhysicalIdentity() {
|
|
222
|
+
const value = await fsPromises.stat(this.path).catch((error) => {
|
|
223
|
+
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT")
|
|
224
|
+
return void 0;
|
|
225
|
+
throw error;
|
|
226
|
+
});
|
|
227
|
+
if (value === void 0) return void 0;
|
|
228
|
+
return `${value.dev}:${value.ino}`;
|
|
229
|
+
}
|
|
212
230
|
kind = "directory";
|
|
213
231
|
[NODE_RESOURCE_KIND] = "directory";
|
|
214
232
|
identity;
|
|
@@ -218,8 +236,10 @@ var NodeDirectory = class _NodeDirectory {
|
|
|
218
236
|
const file = new NodeFile(pathModule.join(this.path, name));
|
|
219
237
|
try {
|
|
220
238
|
return (await fsPromises.stat(file.path)).isFile() ? file : void 0;
|
|
221
|
-
} catch {
|
|
222
|
-
|
|
239
|
+
} catch (error) {
|
|
240
|
+
if (typeof error === "object" && error !== null && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR"))
|
|
241
|
+
return void 0;
|
|
242
|
+
throw error;
|
|
223
243
|
}
|
|
224
244
|
}
|
|
225
245
|
async getLastModified() {
|
|
@@ -237,8 +257,10 @@ var NodeDirectory = class _NodeDirectory {
|
|
|
237
257
|
const directory = new _NodeDirectory(pathModule.join(this.path, name));
|
|
238
258
|
try {
|
|
239
259
|
return (await fsPromises.stat(directory.path)).isDirectory() ? directory : void 0;
|
|
240
|
-
} catch {
|
|
241
|
-
|
|
260
|
+
} catch (error) {
|
|
261
|
+
if (typeof error === "object" && error !== null && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR"))
|
|
262
|
+
return void 0;
|
|
263
|
+
throw error;
|
|
242
264
|
}
|
|
243
265
|
}
|
|
244
266
|
async list() {
|
|
@@ -354,14 +376,23 @@ async function openNativeNodeDatabase(file, flags) {
|
|
|
354
376
|
});
|
|
355
377
|
});
|
|
356
378
|
}
|
|
357
|
-
async function openNodeZip(file) {
|
|
379
|
+
async function openNodeZip(file, options = {}) {
|
|
358
380
|
const path = getBrandedNodeResourcePath(file, "file");
|
|
359
381
|
if (path === void 0) {
|
|
360
382
|
throw new TypeError("The Node ZIP adapter requires a NodeFile");
|
|
361
383
|
}
|
|
362
|
-
const
|
|
363
|
-
|
|
364
|
-
|
|
384
|
+
const handle = await fsPromises.open(path, "r");
|
|
385
|
+
let size;
|
|
386
|
+
try {
|
|
387
|
+
size = (await handle.stat()).size;
|
|
388
|
+
} catch (error) {
|
|
389
|
+
await handle.close();
|
|
390
|
+
throw error;
|
|
391
|
+
}
|
|
392
|
+
const open2 = () => new Promise((resolve2, reject) => {
|
|
393
|
+
yauzl.fromRandomAccessReader(
|
|
394
|
+
new NodeZipSource(handle),
|
|
395
|
+
size,
|
|
365
396
|
{ autoClose: false, lazyEntries: true },
|
|
366
397
|
(error, opened) => {
|
|
367
398
|
if (error || opened === void 0)
|
|
@@ -370,63 +401,192 @@ async function openNodeZip(file) {
|
|
|
370
401
|
}
|
|
371
402
|
);
|
|
372
403
|
});
|
|
373
|
-
|
|
374
|
-
(
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
error instanceof Error ? error : new Error("Cannot scan ZIP central directory")
|
|
380
|
-
);
|
|
381
|
-
};
|
|
382
|
-
const resolveEntries = () => {
|
|
383
|
-
zipFile.off("error", rejectAndClose);
|
|
384
|
-
resolve2(discovered);
|
|
385
|
-
};
|
|
386
|
-
zipFile.on("entry", (entry) => {
|
|
387
|
-
if (!entry.fileName.endsWith("/")) {
|
|
388
|
-
discovered.set(entry.fileName, entry);
|
|
389
|
-
}
|
|
390
|
-
zipFile.readEntry();
|
|
391
|
-
});
|
|
392
|
-
zipFile.once("error", rejectAndClose);
|
|
393
|
-
zipFile.once("end", resolveEntries);
|
|
394
|
-
zipFile.readEntry();
|
|
395
|
-
}
|
|
396
|
-
);
|
|
404
|
+
try {
|
|
405
|
+
(await open2()).close();
|
|
406
|
+
} catch (error) {
|
|
407
|
+
await handle.close();
|
|
408
|
+
throw error;
|
|
409
|
+
}
|
|
397
410
|
let closed = false;
|
|
411
|
+
let pending = Promise.resolve();
|
|
412
|
+
let closing;
|
|
413
|
+
const run = (operation) => {
|
|
414
|
+
if (closed)
|
|
415
|
+
return Promise.reject(new Error("Cannot read a closed ZIP archive"));
|
|
416
|
+
const result = pending.then(async () => {
|
|
417
|
+
const zip = await open2();
|
|
418
|
+
try {
|
|
419
|
+
return await operation(zip);
|
|
420
|
+
} finally {
|
|
421
|
+
zip.close();
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
pending = result.then(
|
|
425
|
+
() => void 0,
|
|
426
|
+
() => void 0
|
|
427
|
+
);
|
|
428
|
+
return result;
|
|
429
|
+
};
|
|
430
|
+
const withEntry = (name, operation) => run(async (zip) => {
|
|
431
|
+
let exact;
|
|
432
|
+
let alias;
|
|
433
|
+
let aliasCollision = false;
|
|
434
|
+
await scanNodeZip(zip, (entry) => {
|
|
435
|
+
if (entry.fileName === name) exact = entry;
|
|
436
|
+
if (normalizeNodeZipName(entry.fileName) === name) {
|
|
437
|
+
if (alias !== void 0 && alias.fileName !== entry.fileName)
|
|
438
|
+
aliasCollision = true;
|
|
439
|
+
alias = entry;
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
if ((exact === void 0 || options.entryNameMode === "normalized") && aliasCollision) {
|
|
443
|
+
let bestPosition = -1;
|
|
444
|
+
const candidates = await open2();
|
|
445
|
+
try {
|
|
446
|
+
await scanNodeZip(candidates, async (entry) => {
|
|
447
|
+
if (normalizeNodeZipName(entry.fileName) !== name) return;
|
|
448
|
+
const probe = await open2();
|
|
449
|
+
let position = 0;
|
|
450
|
+
try {
|
|
451
|
+
await scanNodeZip(probe, (candidate) => {
|
|
452
|
+
if (candidate.fileName === entry.fileName) return false;
|
|
453
|
+
position++;
|
|
454
|
+
});
|
|
455
|
+
} finally {
|
|
456
|
+
probe.close();
|
|
457
|
+
}
|
|
458
|
+
if (position >= bestPosition) {
|
|
459
|
+
bestPosition = position;
|
|
460
|
+
alias = entry;
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
return await operation(candidates, alias);
|
|
464
|
+
} finally {
|
|
465
|
+
candidates.close();
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return await operation(
|
|
469
|
+
zip,
|
|
470
|
+
options.entryNameMode === "normalized" ? alias : exact ?? alias
|
|
471
|
+
);
|
|
472
|
+
});
|
|
398
473
|
return {
|
|
399
474
|
close: () => {
|
|
400
|
-
if (!closed) zipFile.close();
|
|
401
475
|
closed = true;
|
|
402
|
-
|
|
476
|
+
closing ??= pending.then(() => handle.close());
|
|
477
|
+
return closing;
|
|
403
478
|
},
|
|
404
|
-
copyEntry:
|
|
405
|
-
if (closed) throw new Error("Cannot read a closed ZIP archive");
|
|
406
|
-
const entry = entries.get(name);
|
|
479
|
+
copyEntry: (name, target) => withEntry(name, async (zip, entry) => {
|
|
407
480
|
if (entry === void 0) return false;
|
|
408
|
-
await copyNodeZipEntry(
|
|
481
|
+
await copyNodeZipEntry(zip, entry, target);
|
|
409
482
|
return true;
|
|
410
|
-
},
|
|
411
|
-
getEntrySize: (name) =>
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
listEntries: () =>
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
483
|
+
}),
|
|
484
|
+
getEntrySize: (name) => withEntry(
|
|
485
|
+
name,
|
|
486
|
+
(_zip, entry) => Promise.resolve(entry?.uncompressedSize)
|
|
487
|
+
),
|
|
488
|
+
listEntries: () => run(async (zip) => {
|
|
489
|
+
const names = /* @__PURE__ */ new Set();
|
|
490
|
+
await scanNodeZip(zip, (entry) => {
|
|
491
|
+
names.add(entry.fileName);
|
|
492
|
+
});
|
|
493
|
+
return [...names];
|
|
494
|
+
}),
|
|
495
|
+
readEntryRange: (name, offset, length) => withEntry(name, async (zip, entry) => {
|
|
419
496
|
if (entry === void 0) return void 0;
|
|
420
|
-
return await readNodeZipEntryRange(
|
|
421
|
-
},
|
|
422
|
-
readEntry: async (
|
|
423
|
-
if (closed) throw new Error("Cannot read a closed ZIP archive");
|
|
424
|
-
const entry = entries.get(name);
|
|
497
|
+
return await readNodeZipEntryRange(zip, entry, offset, length);
|
|
498
|
+
}),
|
|
499
|
+
readEntry: (name) => withEntry(name, async (zip, entry) => {
|
|
425
500
|
if (entry === void 0) return void 0;
|
|
426
|
-
return await readNodeZipEntry(
|
|
427
|
-
}
|
|
501
|
+
return await readNodeZipEntry(zip, entry);
|
|
502
|
+
})
|
|
428
503
|
};
|
|
429
504
|
}
|
|
505
|
+
var NodeZipSource = class extends yauzl.RandomAccessReader {
|
|
506
|
+
constructor(handle) {
|
|
507
|
+
super();
|
|
508
|
+
this.handle = handle;
|
|
509
|
+
}
|
|
510
|
+
handle;
|
|
511
|
+
read(buffer, offset, length, position, callback) {
|
|
512
|
+
const read2 = (written) => {
|
|
513
|
+
if (written === length) {
|
|
514
|
+
callback(null);
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
fs.read(
|
|
518
|
+
this.handle.fd,
|
|
519
|
+
buffer,
|
|
520
|
+
offset + written,
|
|
521
|
+
length - written,
|
|
522
|
+
position + written,
|
|
523
|
+
(error, bytesRead) => {
|
|
524
|
+
if (error) callback(error);
|
|
525
|
+
else if (bytesRead === 0)
|
|
526
|
+
callback(new Error("Unexpected end of ZIP file"));
|
|
527
|
+
else read2(written + bytesRead);
|
|
528
|
+
}
|
|
529
|
+
);
|
|
530
|
+
};
|
|
531
|
+
read2(0);
|
|
532
|
+
}
|
|
533
|
+
_readStreamForRange(start, end) {
|
|
534
|
+
const handle = this.handle;
|
|
535
|
+
return Readable.from(
|
|
536
|
+
(async function* () {
|
|
537
|
+
for (let position = start; position < end; ) {
|
|
538
|
+
const buffer = Buffer.allocUnsafe(
|
|
539
|
+
Math.min(64 * 1024, end - position)
|
|
540
|
+
);
|
|
541
|
+
const { bytesRead } = await handle.read(
|
|
542
|
+
buffer,
|
|
543
|
+
0,
|
|
544
|
+
buffer.length,
|
|
545
|
+
position
|
|
546
|
+
);
|
|
547
|
+
if (bytesRead === 0) return;
|
|
548
|
+
position += bytesRead;
|
|
549
|
+
yield buffer.subarray(0, bytesRead);
|
|
550
|
+
}
|
|
551
|
+
})()
|
|
552
|
+
);
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
function normalizeNodeZipName(name) {
|
|
556
|
+
const normalized = name.replaceAll("\\", "/").trim().split("/").filter((part) => part !== "" && part !== ".").join("/");
|
|
557
|
+
return normalized.split("/").includes("..") ? void 0 : normalized;
|
|
558
|
+
}
|
|
559
|
+
async function scanNodeZip(zip, visit) {
|
|
560
|
+
await new Promise((resolve2, reject) => {
|
|
561
|
+
const cleanup = () => {
|
|
562
|
+
zip.off("entry", onEntry);
|
|
563
|
+
zip.off("end", onEnd);
|
|
564
|
+
zip.off("error", onError);
|
|
565
|
+
};
|
|
566
|
+
const onError = (error) => {
|
|
567
|
+
cleanup();
|
|
568
|
+
reject(error);
|
|
569
|
+
};
|
|
570
|
+
const onEnd = () => {
|
|
571
|
+
cleanup();
|
|
572
|
+
resolve2();
|
|
573
|
+
};
|
|
574
|
+
const onEntry = (entry) => {
|
|
575
|
+
void Promise.resolve().then(() => entry.fileName.endsWith("/") ? void 0 : visit(entry)).then((keepReading) => {
|
|
576
|
+
if (keepReading === false) onEnd();
|
|
577
|
+
else zip.readEntry();
|
|
578
|
+
}).catch(
|
|
579
|
+
(error) => onError(
|
|
580
|
+
error instanceof Error ? error : new Error("Cannot scan ZIP", { cause: error })
|
|
581
|
+
)
|
|
582
|
+
);
|
|
583
|
+
};
|
|
584
|
+
zip.on("entry", onEntry);
|
|
585
|
+
zip.once("end", onEnd);
|
|
586
|
+
zip.once("error", onError);
|
|
587
|
+
zip.readEntry();
|
|
588
|
+
});
|
|
589
|
+
}
|
|
430
590
|
async function copyNodeZipEntry(zipFile, entry, target) {
|
|
431
591
|
const writer = await target.openWriter();
|
|
432
592
|
try {
|