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