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/embedding.js
CHANGED
|
@@ -74,6 +74,15 @@ var NodeFile = class {
|
|
|
74
74
|
this.name = name;
|
|
75
75
|
}
|
|
76
76
|
path;
|
|
77
|
+
async getPhysicalIdentity() {
|
|
78
|
+
const value = await fsPromises.stat(this.path).catch((error) => {
|
|
79
|
+
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT")
|
|
80
|
+
return void 0;
|
|
81
|
+
throw error;
|
|
82
|
+
});
|
|
83
|
+
if (value === void 0) return void 0;
|
|
84
|
+
return `${value.dev}:${value.ino}`;
|
|
85
|
+
}
|
|
77
86
|
kind = "file";
|
|
78
87
|
[NODE_RESOURCE_KIND] = "file";
|
|
79
88
|
identity;
|
|
@@ -198,6 +207,15 @@ var NodeDirectory = class _NodeDirectory {
|
|
|
198
207
|
this.name = pathModule.basename(path);
|
|
199
208
|
}
|
|
200
209
|
path;
|
|
210
|
+
async getPhysicalIdentity() {
|
|
211
|
+
const value = await fsPromises.stat(this.path).catch((error) => {
|
|
212
|
+
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT")
|
|
213
|
+
return void 0;
|
|
214
|
+
throw error;
|
|
215
|
+
});
|
|
216
|
+
if (value === void 0) return void 0;
|
|
217
|
+
return `${value.dev}:${value.ino}`;
|
|
218
|
+
}
|
|
201
219
|
kind = "directory";
|
|
202
220
|
[NODE_RESOURCE_KIND] = "directory";
|
|
203
221
|
identity;
|
|
@@ -207,8 +225,10 @@ var NodeDirectory = class _NodeDirectory {
|
|
|
207
225
|
const file = new NodeFile(pathModule.join(this.path, name));
|
|
208
226
|
try {
|
|
209
227
|
return (await fsPromises.stat(file.path)).isFile() ? file : void 0;
|
|
210
|
-
} catch {
|
|
211
|
-
|
|
228
|
+
} catch (error) {
|
|
229
|
+
if (typeof error === "object" && error !== null && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR"))
|
|
230
|
+
return void 0;
|
|
231
|
+
throw error;
|
|
212
232
|
}
|
|
213
233
|
}
|
|
214
234
|
async getLastModified() {
|
|
@@ -226,8 +246,10 @@ var NodeDirectory = class _NodeDirectory {
|
|
|
226
246
|
const directory = new _NodeDirectory(pathModule.join(this.path, name));
|
|
227
247
|
try {
|
|
228
248
|
return (await fsPromises.stat(directory.path)).isDirectory() ? directory : void 0;
|
|
229
|
-
} catch {
|
|
230
|
-
|
|
249
|
+
} catch (error) {
|
|
250
|
+
if (typeof error === "object" && error !== null && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR"))
|
|
251
|
+
return void 0;
|
|
252
|
+
throw error;
|
|
231
253
|
}
|
|
232
254
|
}
|
|
233
255
|
async list() {
|
|
@@ -343,14 +365,23 @@ async function openNativeNodeDatabase(file, flags) {
|
|
|
343
365
|
});
|
|
344
366
|
});
|
|
345
367
|
}
|
|
346
|
-
async function openNodeZip(file) {
|
|
368
|
+
async function openNodeZip(file, options = {}) {
|
|
347
369
|
const path = getBrandedNodeResourcePath(file, "file");
|
|
348
370
|
if (path === void 0) {
|
|
349
371
|
throw new TypeError("The Node ZIP adapter requires a NodeFile");
|
|
350
372
|
}
|
|
351
|
-
const
|
|
352
|
-
|
|
353
|
-
|
|
373
|
+
const handle = await fsPromises.open(path, "r");
|
|
374
|
+
let size;
|
|
375
|
+
try {
|
|
376
|
+
size = (await handle.stat()).size;
|
|
377
|
+
} catch (error) {
|
|
378
|
+
await handle.close();
|
|
379
|
+
throw error;
|
|
380
|
+
}
|
|
381
|
+
const open2 = () => new Promise((resolve2, reject) => {
|
|
382
|
+
yauzl.fromRandomAccessReader(
|
|
383
|
+
new NodeZipSource(handle),
|
|
384
|
+
size,
|
|
354
385
|
{ autoClose: false, lazyEntries: true },
|
|
355
386
|
(error, opened) => {
|
|
356
387
|
if (error || opened === void 0)
|
|
@@ -359,63 +390,192 @@ async function openNodeZip(file) {
|
|
|
359
390
|
}
|
|
360
391
|
);
|
|
361
392
|
});
|
|
362
|
-
|
|
363
|
-
(
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
error instanceof Error ? error : new Error("Cannot scan ZIP central directory")
|
|
369
|
-
);
|
|
370
|
-
};
|
|
371
|
-
const resolveEntries = () => {
|
|
372
|
-
zipFile.off("error", rejectAndClose);
|
|
373
|
-
resolve2(discovered);
|
|
374
|
-
};
|
|
375
|
-
zipFile.on("entry", (entry) => {
|
|
376
|
-
if (!entry.fileName.endsWith("/")) {
|
|
377
|
-
discovered.set(entry.fileName, entry);
|
|
378
|
-
}
|
|
379
|
-
zipFile.readEntry();
|
|
380
|
-
});
|
|
381
|
-
zipFile.once("error", rejectAndClose);
|
|
382
|
-
zipFile.once("end", resolveEntries);
|
|
383
|
-
zipFile.readEntry();
|
|
384
|
-
}
|
|
385
|
-
);
|
|
393
|
+
try {
|
|
394
|
+
(await open2()).close();
|
|
395
|
+
} catch (error) {
|
|
396
|
+
await handle.close();
|
|
397
|
+
throw error;
|
|
398
|
+
}
|
|
386
399
|
let closed = false;
|
|
400
|
+
let pending = Promise.resolve();
|
|
401
|
+
let closing;
|
|
402
|
+
const run = (operation) => {
|
|
403
|
+
if (closed)
|
|
404
|
+
return Promise.reject(new Error("Cannot read a closed ZIP archive"));
|
|
405
|
+
const result = pending.then(async () => {
|
|
406
|
+
const zip = await open2();
|
|
407
|
+
try {
|
|
408
|
+
return await operation(zip);
|
|
409
|
+
} finally {
|
|
410
|
+
zip.close();
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
pending = result.then(
|
|
414
|
+
() => void 0,
|
|
415
|
+
() => void 0
|
|
416
|
+
);
|
|
417
|
+
return result;
|
|
418
|
+
};
|
|
419
|
+
const withEntry = (name, operation) => run(async (zip) => {
|
|
420
|
+
let exact;
|
|
421
|
+
let alias;
|
|
422
|
+
let aliasCollision = false;
|
|
423
|
+
await scanNodeZip(zip, (entry) => {
|
|
424
|
+
if (entry.fileName === name) exact = entry;
|
|
425
|
+
if (normalizeNodeZipName(entry.fileName) === name) {
|
|
426
|
+
if (alias !== void 0 && alias.fileName !== entry.fileName)
|
|
427
|
+
aliasCollision = true;
|
|
428
|
+
alias = entry;
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
if ((exact === void 0 || options.entryNameMode === "normalized") && aliasCollision) {
|
|
432
|
+
let bestPosition = -1;
|
|
433
|
+
const candidates = await open2();
|
|
434
|
+
try {
|
|
435
|
+
await scanNodeZip(candidates, async (entry) => {
|
|
436
|
+
if (normalizeNodeZipName(entry.fileName) !== name) return;
|
|
437
|
+
const probe = await open2();
|
|
438
|
+
let position = 0;
|
|
439
|
+
try {
|
|
440
|
+
await scanNodeZip(probe, (candidate) => {
|
|
441
|
+
if (candidate.fileName === entry.fileName) return false;
|
|
442
|
+
position++;
|
|
443
|
+
});
|
|
444
|
+
} finally {
|
|
445
|
+
probe.close();
|
|
446
|
+
}
|
|
447
|
+
if (position >= bestPosition) {
|
|
448
|
+
bestPosition = position;
|
|
449
|
+
alias = entry;
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
return await operation(candidates, alias);
|
|
453
|
+
} finally {
|
|
454
|
+
candidates.close();
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return await operation(
|
|
458
|
+
zip,
|
|
459
|
+
options.entryNameMode === "normalized" ? alias : exact ?? alias
|
|
460
|
+
);
|
|
461
|
+
});
|
|
387
462
|
return {
|
|
388
463
|
close: () => {
|
|
389
|
-
if (!closed) zipFile.close();
|
|
390
464
|
closed = true;
|
|
391
|
-
|
|
465
|
+
closing ??= pending.then(() => handle.close());
|
|
466
|
+
return closing;
|
|
392
467
|
},
|
|
393
|
-
copyEntry:
|
|
394
|
-
if (closed) throw new Error("Cannot read a closed ZIP archive");
|
|
395
|
-
const entry = entries.get(name);
|
|
468
|
+
copyEntry: (name, target) => withEntry(name, async (zip, entry) => {
|
|
396
469
|
if (entry === void 0) return false;
|
|
397
|
-
await copyNodeZipEntry(
|
|
470
|
+
await copyNodeZipEntry(zip, entry, target);
|
|
398
471
|
return true;
|
|
399
|
-
},
|
|
400
|
-
getEntrySize: (name) =>
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
listEntries: () =>
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
472
|
+
}),
|
|
473
|
+
getEntrySize: (name) => withEntry(
|
|
474
|
+
name,
|
|
475
|
+
(_zip, entry) => Promise.resolve(entry?.uncompressedSize)
|
|
476
|
+
),
|
|
477
|
+
listEntries: () => run(async (zip) => {
|
|
478
|
+
const names = /* @__PURE__ */ new Set();
|
|
479
|
+
await scanNodeZip(zip, (entry) => {
|
|
480
|
+
names.add(entry.fileName);
|
|
481
|
+
});
|
|
482
|
+
return [...names];
|
|
483
|
+
}),
|
|
484
|
+
readEntryRange: (name, offset, length) => withEntry(name, async (zip, entry) => {
|
|
408
485
|
if (entry === void 0) return void 0;
|
|
409
|
-
return await readNodeZipEntryRange(
|
|
410
|
-
},
|
|
411
|
-
readEntry: async (
|
|
412
|
-
if (closed) throw new Error("Cannot read a closed ZIP archive");
|
|
413
|
-
const entry = entries.get(name);
|
|
486
|
+
return await readNodeZipEntryRange(zip, entry, offset, length);
|
|
487
|
+
}),
|
|
488
|
+
readEntry: (name) => withEntry(name, async (zip, entry) => {
|
|
414
489
|
if (entry === void 0) return void 0;
|
|
415
|
-
return await readNodeZipEntry(
|
|
416
|
-
}
|
|
490
|
+
return await readNodeZipEntry(zip, entry);
|
|
491
|
+
})
|
|
417
492
|
};
|
|
418
493
|
}
|
|
494
|
+
var NodeZipSource = class extends yauzl.RandomAccessReader {
|
|
495
|
+
constructor(handle) {
|
|
496
|
+
super();
|
|
497
|
+
this.handle = handle;
|
|
498
|
+
}
|
|
499
|
+
handle;
|
|
500
|
+
read(buffer, offset, length, position, callback) {
|
|
501
|
+
const read2 = (written) => {
|
|
502
|
+
if (written === length) {
|
|
503
|
+
callback(null);
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
fs.read(
|
|
507
|
+
this.handle.fd,
|
|
508
|
+
buffer,
|
|
509
|
+
offset + written,
|
|
510
|
+
length - written,
|
|
511
|
+
position + written,
|
|
512
|
+
(error, bytesRead) => {
|
|
513
|
+
if (error) callback(error);
|
|
514
|
+
else if (bytesRead === 0)
|
|
515
|
+
callback(new Error("Unexpected end of ZIP file"));
|
|
516
|
+
else read2(written + bytesRead);
|
|
517
|
+
}
|
|
518
|
+
);
|
|
519
|
+
};
|
|
520
|
+
read2(0);
|
|
521
|
+
}
|
|
522
|
+
_readStreamForRange(start, end) {
|
|
523
|
+
const handle = this.handle;
|
|
524
|
+
return Readable.from(
|
|
525
|
+
(async function* () {
|
|
526
|
+
for (let position = start; position < end; ) {
|
|
527
|
+
const buffer = Buffer.allocUnsafe(
|
|
528
|
+
Math.min(64 * 1024, end - position)
|
|
529
|
+
);
|
|
530
|
+
const { bytesRead } = await handle.read(
|
|
531
|
+
buffer,
|
|
532
|
+
0,
|
|
533
|
+
buffer.length,
|
|
534
|
+
position
|
|
535
|
+
);
|
|
536
|
+
if (bytesRead === 0) return;
|
|
537
|
+
position += bytesRead;
|
|
538
|
+
yield buffer.subarray(0, bytesRead);
|
|
539
|
+
}
|
|
540
|
+
})()
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
function normalizeNodeZipName(name) {
|
|
545
|
+
const normalized = name.replaceAll("\\", "/").trim().split("/").filter((part) => part !== "" && part !== ".").join("/");
|
|
546
|
+
return normalized.split("/").includes("..") ? void 0 : normalized;
|
|
547
|
+
}
|
|
548
|
+
async function scanNodeZip(zip, visit) {
|
|
549
|
+
await new Promise((resolve2, reject) => {
|
|
550
|
+
const cleanup = () => {
|
|
551
|
+
zip.off("entry", onEntry);
|
|
552
|
+
zip.off("end", onEnd);
|
|
553
|
+
zip.off("error", onError);
|
|
554
|
+
};
|
|
555
|
+
const onError = (error) => {
|
|
556
|
+
cleanup();
|
|
557
|
+
reject(error);
|
|
558
|
+
};
|
|
559
|
+
const onEnd = () => {
|
|
560
|
+
cleanup();
|
|
561
|
+
resolve2();
|
|
562
|
+
};
|
|
563
|
+
const onEntry = (entry) => {
|
|
564
|
+
void Promise.resolve().then(() => entry.fileName.endsWith("/") ? void 0 : visit(entry)).then((keepReading) => {
|
|
565
|
+
if (keepReading === false) onEnd();
|
|
566
|
+
else zip.readEntry();
|
|
567
|
+
}).catch(
|
|
568
|
+
(error) => onError(
|
|
569
|
+
error instanceof Error ? error : new Error("Cannot scan ZIP", { cause: error })
|
|
570
|
+
)
|
|
571
|
+
);
|
|
572
|
+
};
|
|
573
|
+
zip.on("entry", onEntry);
|
|
574
|
+
zip.once("end", onEnd);
|
|
575
|
+
zip.once("error", onError);
|
|
576
|
+
zip.readEntry();
|
|
577
|
+
});
|
|
578
|
+
}
|
|
419
579
|
async function copyNodeZipEntry(zipFile, entry, target) {
|
|
420
580
|
const writer = await target.openWriter();
|
|
421
581
|
try {
|