wiki-graph-sdk 0.8.4 → 0.9.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/dist/archives.cjs +345 -152
- package/dist/archives.cjs.map +1 -1
- package/dist/archives.js +356 -157
- package/dist/archives.js.map +1 -1
- package/dist/conversions.cjs +269 -99
- package/dist/conversions.cjs.map +1 -1
- package/dist/conversions.js +275 -103
- package/dist/conversions.js.map +1 -1
- package/dist/default-worker.cjs +278 -108
- package/dist/default-worker.cjs.map +1 -1
- package/dist/default-worker.js +285 -112
- 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 +442 -226
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +461 -236
- 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 +265 -97
- package/dist/maintenance.cjs.map +1 -1
- package/dist/maintenance.js +271 -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 +277 -103
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.js +284 -107
- package/dist/worker.js.map +1 -1
- package/package.json +2 -2
package/dist/stage.cjs
CHANGED
|
@@ -109,6 +109,15 @@ var NodeFile = class {
|
|
|
109
109
|
this.name = name;
|
|
110
110
|
}
|
|
111
111
|
path;
|
|
112
|
+
async getPhysicalIdentity() {
|
|
113
|
+
const value = await fsPromises.stat(this.path).catch((error) => {
|
|
114
|
+
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT")
|
|
115
|
+
return void 0;
|
|
116
|
+
throw error;
|
|
117
|
+
});
|
|
118
|
+
if (value === void 0) return void 0;
|
|
119
|
+
return `${value.dev}:${value.ino}`;
|
|
120
|
+
}
|
|
112
121
|
kind = "file";
|
|
113
122
|
[NODE_RESOURCE_KIND] = "file";
|
|
114
123
|
identity;
|
|
@@ -233,6 +242,15 @@ var NodeDirectory = class _NodeDirectory {
|
|
|
233
242
|
this.name = pathModule.basename(path);
|
|
234
243
|
}
|
|
235
244
|
path;
|
|
245
|
+
async getPhysicalIdentity() {
|
|
246
|
+
const value = await fsPromises.stat(this.path).catch((error) => {
|
|
247
|
+
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT")
|
|
248
|
+
return void 0;
|
|
249
|
+
throw error;
|
|
250
|
+
});
|
|
251
|
+
if (value === void 0) return void 0;
|
|
252
|
+
return `${value.dev}:${value.ino}`;
|
|
253
|
+
}
|
|
236
254
|
kind = "directory";
|
|
237
255
|
[NODE_RESOURCE_KIND] = "directory";
|
|
238
256
|
identity;
|
|
@@ -242,8 +260,10 @@ var NodeDirectory = class _NodeDirectory {
|
|
|
242
260
|
const file = new NodeFile(pathModule.join(this.path, name));
|
|
243
261
|
try {
|
|
244
262
|
return (await fsPromises.stat(file.path)).isFile() ? file : void 0;
|
|
245
|
-
} catch {
|
|
246
|
-
|
|
263
|
+
} catch (error) {
|
|
264
|
+
if (typeof error === "object" && error !== null && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR"))
|
|
265
|
+
return void 0;
|
|
266
|
+
throw error;
|
|
247
267
|
}
|
|
248
268
|
}
|
|
249
269
|
async getLastModified() {
|
|
@@ -261,8 +281,10 @@ var NodeDirectory = class _NodeDirectory {
|
|
|
261
281
|
const directory = new _NodeDirectory(pathModule.join(this.path, name));
|
|
262
282
|
try {
|
|
263
283
|
return (await fsPromises.stat(directory.path)).isDirectory() ? directory : void 0;
|
|
264
|
-
} catch {
|
|
265
|
-
|
|
284
|
+
} catch (error) {
|
|
285
|
+
if (typeof error === "object" && error !== null && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR"))
|
|
286
|
+
return void 0;
|
|
287
|
+
throw error;
|
|
266
288
|
}
|
|
267
289
|
}
|
|
268
290
|
async list() {
|
|
@@ -378,14 +400,23 @@ async function openNativeNodeDatabase(file, flags) {
|
|
|
378
400
|
});
|
|
379
401
|
});
|
|
380
402
|
}
|
|
381
|
-
async function openNodeZip(file) {
|
|
403
|
+
async function openNodeZip(file, options = {}) {
|
|
382
404
|
const path = getBrandedNodeResourcePath(file, "file");
|
|
383
405
|
if (path === void 0) {
|
|
384
406
|
throw new TypeError("The Node ZIP adapter requires a NodeFile");
|
|
385
407
|
}
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
|
|
408
|
+
const handle = await fsPromises.open(path, "r");
|
|
409
|
+
let size;
|
|
410
|
+
try {
|
|
411
|
+
size = (await handle.stat()).size;
|
|
412
|
+
} catch (error) {
|
|
413
|
+
await handle.close();
|
|
414
|
+
throw error;
|
|
415
|
+
}
|
|
416
|
+
const open2 = () => new Promise((resolve2, reject) => {
|
|
417
|
+
yauzl.fromRandomAccessReader(
|
|
418
|
+
new NodeZipSource(handle),
|
|
419
|
+
size,
|
|
389
420
|
{ autoClose: false, lazyEntries: true },
|
|
390
421
|
(error, opened) => {
|
|
391
422
|
if (error || opened === void 0)
|
|
@@ -394,63 +425,192 @@ async function openNodeZip(file) {
|
|
|
394
425
|
}
|
|
395
426
|
);
|
|
396
427
|
});
|
|
397
|
-
|
|
398
|
-
(
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
error instanceof Error ? error : new Error("Cannot scan ZIP central directory")
|
|
404
|
-
);
|
|
405
|
-
};
|
|
406
|
-
const resolveEntries = () => {
|
|
407
|
-
zipFile.off("error", rejectAndClose);
|
|
408
|
-
resolve2(discovered);
|
|
409
|
-
};
|
|
410
|
-
zipFile.on("entry", (entry) => {
|
|
411
|
-
if (!entry.fileName.endsWith("/")) {
|
|
412
|
-
discovered.set(entry.fileName, entry);
|
|
413
|
-
}
|
|
414
|
-
zipFile.readEntry();
|
|
415
|
-
});
|
|
416
|
-
zipFile.once("error", rejectAndClose);
|
|
417
|
-
zipFile.once("end", resolveEntries);
|
|
418
|
-
zipFile.readEntry();
|
|
419
|
-
}
|
|
420
|
-
);
|
|
428
|
+
try {
|
|
429
|
+
(await open2()).close();
|
|
430
|
+
} catch (error) {
|
|
431
|
+
await handle.close();
|
|
432
|
+
throw error;
|
|
433
|
+
}
|
|
421
434
|
let closed = false;
|
|
435
|
+
let pending = Promise.resolve();
|
|
436
|
+
let closing;
|
|
437
|
+
const run = (operation) => {
|
|
438
|
+
if (closed)
|
|
439
|
+
return Promise.reject(new Error("Cannot read a closed ZIP archive"));
|
|
440
|
+
const result = pending.then(async () => {
|
|
441
|
+
const zip = await open2();
|
|
442
|
+
try {
|
|
443
|
+
return await operation(zip);
|
|
444
|
+
} finally {
|
|
445
|
+
zip.close();
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
pending = result.then(
|
|
449
|
+
() => void 0,
|
|
450
|
+
() => void 0
|
|
451
|
+
);
|
|
452
|
+
return result;
|
|
453
|
+
};
|
|
454
|
+
const withEntry = (name, operation) => run(async (zip) => {
|
|
455
|
+
let exact;
|
|
456
|
+
let alias;
|
|
457
|
+
let aliasCollision = false;
|
|
458
|
+
await scanNodeZip(zip, (entry) => {
|
|
459
|
+
if (entry.fileName === name) exact = entry;
|
|
460
|
+
if (normalizeNodeZipName(entry.fileName) === name) {
|
|
461
|
+
if (alias !== void 0 && alias.fileName !== entry.fileName)
|
|
462
|
+
aliasCollision = true;
|
|
463
|
+
alias = entry;
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
if ((exact === void 0 || options.entryNameMode === "normalized") && aliasCollision) {
|
|
467
|
+
let bestPosition = -1;
|
|
468
|
+
const candidates = await open2();
|
|
469
|
+
try {
|
|
470
|
+
await scanNodeZip(candidates, async (entry) => {
|
|
471
|
+
if (normalizeNodeZipName(entry.fileName) !== name) return;
|
|
472
|
+
const probe = await open2();
|
|
473
|
+
let position = 0;
|
|
474
|
+
try {
|
|
475
|
+
await scanNodeZip(probe, (candidate) => {
|
|
476
|
+
if (candidate.fileName === entry.fileName) return false;
|
|
477
|
+
position++;
|
|
478
|
+
});
|
|
479
|
+
} finally {
|
|
480
|
+
probe.close();
|
|
481
|
+
}
|
|
482
|
+
if (position >= bestPosition) {
|
|
483
|
+
bestPosition = position;
|
|
484
|
+
alias = entry;
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
return await operation(candidates, alias);
|
|
488
|
+
} finally {
|
|
489
|
+
candidates.close();
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
return await operation(
|
|
493
|
+
zip,
|
|
494
|
+
options.entryNameMode === "normalized" ? alias : exact ?? alias
|
|
495
|
+
);
|
|
496
|
+
});
|
|
422
497
|
return {
|
|
423
498
|
close: () => {
|
|
424
|
-
if (!closed) zipFile.close();
|
|
425
499
|
closed = true;
|
|
426
|
-
|
|
500
|
+
closing ??= pending.then(() => handle.close());
|
|
501
|
+
return closing;
|
|
427
502
|
},
|
|
428
|
-
copyEntry:
|
|
429
|
-
if (closed) throw new Error("Cannot read a closed ZIP archive");
|
|
430
|
-
const entry = entries.get(name);
|
|
503
|
+
copyEntry: (name, target) => withEntry(name, async (zip, entry) => {
|
|
431
504
|
if (entry === void 0) return false;
|
|
432
|
-
await copyNodeZipEntry(
|
|
505
|
+
await copyNodeZipEntry(zip, entry, target);
|
|
433
506
|
return true;
|
|
434
|
-
},
|
|
435
|
-
getEntrySize: (name) =>
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
listEntries: () =>
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
507
|
+
}),
|
|
508
|
+
getEntrySize: (name) => withEntry(
|
|
509
|
+
name,
|
|
510
|
+
(_zip, entry) => Promise.resolve(entry?.uncompressedSize)
|
|
511
|
+
),
|
|
512
|
+
listEntries: () => run(async (zip) => {
|
|
513
|
+
const names = /* @__PURE__ */ new Set();
|
|
514
|
+
await scanNodeZip(zip, (entry) => {
|
|
515
|
+
names.add(entry.fileName);
|
|
516
|
+
});
|
|
517
|
+
return [...names];
|
|
518
|
+
}),
|
|
519
|
+
readEntryRange: (name, offset, length) => withEntry(name, async (zip, entry) => {
|
|
443
520
|
if (entry === void 0) return void 0;
|
|
444
|
-
return await readNodeZipEntryRange(
|
|
445
|
-
},
|
|
446
|
-
readEntry: async (
|
|
447
|
-
if (closed) throw new Error("Cannot read a closed ZIP archive");
|
|
448
|
-
const entry = entries.get(name);
|
|
521
|
+
return await readNodeZipEntryRange(zip, entry, offset, length);
|
|
522
|
+
}),
|
|
523
|
+
readEntry: (name) => withEntry(name, async (zip, entry) => {
|
|
449
524
|
if (entry === void 0) return void 0;
|
|
450
|
-
return await readNodeZipEntry(
|
|
451
|
-
}
|
|
525
|
+
return await readNodeZipEntry(zip, entry);
|
|
526
|
+
})
|
|
452
527
|
};
|
|
453
528
|
}
|
|
529
|
+
var NodeZipSource = class extends yauzl.RandomAccessReader {
|
|
530
|
+
constructor(handle) {
|
|
531
|
+
super();
|
|
532
|
+
this.handle = handle;
|
|
533
|
+
}
|
|
534
|
+
handle;
|
|
535
|
+
read(buffer, offset, length, position, callback) {
|
|
536
|
+
const read2 = (written) => {
|
|
537
|
+
if (written === length) {
|
|
538
|
+
callback(null);
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
fs.read(
|
|
542
|
+
this.handle.fd,
|
|
543
|
+
buffer,
|
|
544
|
+
offset + written,
|
|
545
|
+
length - written,
|
|
546
|
+
position + written,
|
|
547
|
+
(error, bytesRead) => {
|
|
548
|
+
if (error) callback(error);
|
|
549
|
+
else if (bytesRead === 0)
|
|
550
|
+
callback(new Error("Unexpected end of ZIP file"));
|
|
551
|
+
else read2(written + bytesRead);
|
|
552
|
+
}
|
|
553
|
+
);
|
|
554
|
+
};
|
|
555
|
+
read2(0);
|
|
556
|
+
}
|
|
557
|
+
_readStreamForRange(start, end) {
|
|
558
|
+
const handle = this.handle;
|
|
559
|
+
return import_node_stream.Readable.from(
|
|
560
|
+
(async function* () {
|
|
561
|
+
for (let position = start; position < end; ) {
|
|
562
|
+
const buffer = Buffer.allocUnsafe(
|
|
563
|
+
Math.min(64 * 1024, end - position)
|
|
564
|
+
);
|
|
565
|
+
const { bytesRead } = await handle.read(
|
|
566
|
+
buffer,
|
|
567
|
+
0,
|
|
568
|
+
buffer.length,
|
|
569
|
+
position
|
|
570
|
+
);
|
|
571
|
+
if (bytesRead === 0) return;
|
|
572
|
+
position += bytesRead;
|
|
573
|
+
yield buffer.subarray(0, bytesRead);
|
|
574
|
+
}
|
|
575
|
+
})()
|
|
576
|
+
);
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
function normalizeNodeZipName(name) {
|
|
580
|
+
const normalized = name.replaceAll("\\", "/").trim().split("/").filter((part) => part !== "" && part !== ".").join("/");
|
|
581
|
+
return normalized.split("/").includes("..") ? void 0 : normalized;
|
|
582
|
+
}
|
|
583
|
+
async function scanNodeZip(zip, visit) {
|
|
584
|
+
await new Promise((resolve2, reject) => {
|
|
585
|
+
const cleanup = () => {
|
|
586
|
+
zip.off("entry", onEntry);
|
|
587
|
+
zip.off("end", onEnd);
|
|
588
|
+
zip.off("error", onError);
|
|
589
|
+
};
|
|
590
|
+
const onError = (error) => {
|
|
591
|
+
cleanup();
|
|
592
|
+
reject(error);
|
|
593
|
+
};
|
|
594
|
+
const onEnd = () => {
|
|
595
|
+
cleanup();
|
|
596
|
+
resolve2();
|
|
597
|
+
};
|
|
598
|
+
const onEntry = (entry) => {
|
|
599
|
+
void Promise.resolve().then(() => entry.fileName.endsWith("/") ? void 0 : visit(entry)).then((keepReading) => {
|
|
600
|
+
if (keepReading === false) onEnd();
|
|
601
|
+
else zip.readEntry();
|
|
602
|
+
}).catch(
|
|
603
|
+
(error) => onError(
|
|
604
|
+
error instanceof Error ? error : new Error("Cannot scan ZIP", { cause: error })
|
|
605
|
+
)
|
|
606
|
+
);
|
|
607
|
+
};
|
|
608
|
+
zip.on("entry", onEntry);
|
|
609
|
+
zip.once("end", onEnd);
|
|
610
|
+
zip.once("error", onError);
|
|
611
|
+
zip.readEntry();
|
|
612
|
+
});
|
|
613
|
+
}
|
|
454
614
|
async function copyNodeZipEntry(zipFile, entry, target) {
|
|
455
615
|
const writer = await target.openWriter();
|
|
456
616
|
try {
|