wiki-graph-sdk 0.7.1 → 0.8.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/README.md +22 -1
- package/dist/archives.cjs +494 -656
- package/dist/archives.cjs.map +1 -1
- package/dist/archives.d.ts +48 -80
- package/dist/archives.js +431 -585
- package/dist/archives.js.map +1 -1
- package/dist/conversions.cjs +183 -33
- package/dist/conversions.cjs.map +1 -1
- package/dist/conversions.d.ts +8 -1
- package/dist/conversions.js +188 -29
- package/dist/conversions.js.map +1 -1
- package/dist/default-worker.cjs +322 -62
- package/dist/default-worker.cjs.map +1 -1
- package/dist/default-worker.d.ts +1 -0
- package/dist/default-worker.js +336 -60
- package/dist/default-worker.js.map +1 -1
- package/dist/embedding.cjs +2 -1
- package/dist/embedding.cjs.map +1 -1
- package/dist/embedding.d.ts +4 -4
- package/dist/embedding.js +2 -1
- package/dist/embedding.js.map +1 -1
- package/dist/index.cjs +1295 -949
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +58 -24
- package/dist/index.js +1164 -805
- package/dist/index.js.map +1 -1
- package/dist/{jobs-Dd5PMSId.d.ts → jobs-CRK-DZ40.d.ts} +27 -14
- package/dist/local-config.cjs +2 -1
- package/dist/local-config.cjs.map +1 -1
- package/dist/local-config.js +2 -1
- package/dist/local-config.js.map +1 -1
- package/dist/maintenance.cjs +140 -30
- package/dist/maintenance.cjs.map +1 -1
- package/dist/maintenance.d.ts +5 -1
- package/dist/maintenance.js +145 -26
- package/dist/maintenance.js.map +1 -1
- package/dist/runtime-config.cjs +4 -3
- package/dist/runtime-config.cjs.map +1 -1
- package/dist/runtime-config.d.ts +4 -1
- package/dist/runtime-config.js +4 -3
- package/dist/runtime-config.js.map +1 -1
- package/dist/stage-BnWI3Rqt.d.ts +33 -0
- package/dist/stage.cjs +22 -12
- package/dist/stage.cjs.map +1 -1
- package/dist/stage.d.ts +2 -14
- package/dist/stage.js +22 -12
- package/dist/stage.js.map +1 -1
- package/dist/target-CZ7elwmj.d.ts +14 -0
- package/dist/wikispine.cjs +14 -10
- package/dist/wikispine.cjs.map +1 -1
- package/dist/wikispine.js +14 -10
- package/dist/wikispine.js.map +1 -1
- package/dist/worker.cjs +295 -25
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.ts +28 -5
- package/dist/worker.js +313 -28
- package/dist/worker.js.map +1 -1
- package/package.json +2 -2
package/dist/worker.cjs
CHANGED
|
@@ -34,12 +34,13 @@ __export(worker_exports, {
|
|
|
34
34
|
applyChapterJobArtifactFile: () => import_worker2.applyChapterJobArtifactFile,
|
|
35
35
|
applyWikiGraphJobArtifacts: () => applyWikiGraphJobArtifacts,
|
|
36
36
|
createLocalChapterJobFileExecutor: () => import_worker2.createLocalChapterJobFileExecutor,
|
|
37
|
+
extractWikiGraphJobSnapshots: () => extractWikiGraphJobSnapshots,
|
|
37
38
|
runBuildJobWorker: () => runBuildJobWorker,
|
|
38
39
|
writeChapterJobInputFile: () => import_worker2.writeChapterJobInputFile
|
|
39
40
|
});
|
|
40
41
|
module.exports = __toCommonJS(worker_exports);
|
|
41
42
|
var import_worker = require("wiki-graph-core/worker");
|
|
42
|
-
var
|
|
43
|
+
var import_wiki_graph_core3 = require("wiki-graph-core");
|
|
43
44
|
|
|
44
45
|
// src/node-platform.ts
|
|
45
46
|
var asyncHooks = __toESM(require("async_hooks"), 1);
|
|
@@ -48,7 +49,7 @@ var fs = __toESM(require("fs"), 1);
|
|
|
48
49
|
var fsPromises = __toESM(require("fs/promises"), 1);
|
|
49
50
|
var os = __toESM(require("os"), 1);
|
|
50
51
|
var pathModule = __toESM(require("path"), 1);
|
|
51
|
-
var
|
|
52
|
+
var process2 = __toESM(require("process"), 1);
|
|
52
53
|
var import_node_stream = require("stream");
|
|
53
54
|
var import_promises = require("stream/promises");
|
|
54
55
|
var sqlite3 = __toESM(require("sqlite3"), 1);
|
|
@@ -56,7 +57,7 @@ var yauzl = __toESM(require("yauzl"), 1);
|
|
|
56
57
|
var yazl = __toESM(require("yazl"), 1);
|
|
57
58
|
var import_nunjucks = require("nunjucks");
|
|
58
59
|
var import_platform = require("wiki-graph-core/platform");
|
|
59
|
-
var nodeProcess =
|
|
60
|
+
var nodeProcess = process2.default ?? process2;
|
|
60
61
|
var nodeSqlite3 = sqlite3.default ?? sqlite3;
|
|
61
62
|
var NODE_RESOURCE_KIND = /* @__PURE__ */ Symbol.for("wiki-graph-sdk.node-resource.v1");
|
|
62
63
|
var NodeFile = class {
|
|
@@ -268,6 +269,14 @@ function decodeNodeResourceIdentity(identity, kind) {
|
|
|
268
269
|
return void 0;
|
|
269
270
|
}
|
|
270
271
|
}
|
|
272
|
+
function getNodeResourcePath(resource) {
|
|
273
|
+
const brandedPath = getBrandedNodeResourcePath(resource, resource.kind);
|
|
274
|
+
if (brandedPath !== void 0) return brandedPath;
|
|
275
|
+
if (typeof resource === "object" && resource !== null && "path" in resource && typeof resource.path === "string") {
|
|
276
|
+
return resource.path;
|
|
277
|
+
}
|
|
278
|
+
throw new TypeError("Expected a Node File or Directory resource");
|
|
279
|
+
}
|
|
271
280
|
function assertChildName(name) {
|
|
272
281
|
if (name.length === 0 || name === "." || name === ".." || pathModule.isAbsolute(name) || name.includes("/") || name.includes("\\")) {
|
|
273
282
|
throw new TypeError(`Directory child must be a relative name: ${name}`);
|
|
@@ -279,42 +288,42 @@ var NodeDatabaseConnection = class {
|
|
|
279
288
|
}
|
|
280
289
|
database;
|
|
281
290
|
async close() {
|
|
282
|
-
await new Promise((
|
|
291
|
+
await new Promise((resolve4, reject) => {
|
|
283
292
|
this.database.close((error) => {
|
|
284
293
|
if (error) reject(error);
|
|
285
|
-
else
|
|
294
|
+
else resolve4();
|
|
286
295
|
});
|
|
287
296
|
});
|
|
288
297
|
}
|
|
289
298
|
async execute(sql) {
|
|
290
|
-
await new Promise((
|
|
299
|
+
await new Promise((resolve4, reject) => {
|
|
291
300
|
this.database.exec(sql, (error) => {
|
|
292
301
|
if (error) reject(error);
|
|
293
|
-
else
|
|
302
|
+
else resolve4();
|
|
294
303
|
});
|
|
295
304
|
});
|
|
296
305
|
}
|
|
297
306
|
async queryAll(sql, params = []) {
|
|
298
|
-
return await new Promise((
|
|
307
|
+
return await new Promise((resolve4, reject) => {
|
|
299
308
|
this.database.all(sql, [...params], (error, rows) => {
|
|
300
309
|
if (error) reject(error);
|
|
301
|
-
else
|
|
310
|
+
else resolve4(rows);
|
|
302
311
|
});
|
|
303
312
|
});
|
|
304
313
|
}
|
|
305
314
|
async queryOne(sql, params = []) {
|
|
306
|
-
return await new Promise((
|
|
315
|
+
return await new Promise((resolve4, reject) => {
|
|
307
316
|
this.database.get(sql, [...params], (error, row) => {
|
|
308
317
|
if (error) reject(error);
|
|
309
|
-
else
|
|
318
|
+
else resolve4(row);
|
|
310
319
|
});
|
|
311
320
|
});
|
|
312
321
|
}
|
|
313
322
|
async run(sql, params = []) {
|
|
314
|
-
await new Promise((
|
|
323
|
+
await new Promise((resolve4, reject) => {
|
|
315
324
|
this.database.run(sql, [...params], (error) => {
|
|
316
325
|
if (error) reject(error);
|
|
317
|
-
else
|
|
326
|
+
else resolve4();
|
|
318
327
|
});
|
|
319
328
|
});
|
|
320
329
|
}
|
|
@@ -328,10 +337,10 @@ async function openNativeNodeDatabase(file, flags) {
|
|
|
328
337
|
if (path === void 0) {
|
|
329
338
|
throw new TypeError("The Node database adapter requires a NodeFile");
|
|
330
339
|
}
|
|
331
|
-
return await new Promise((
|
|
340
|
+
return await new Promise((resolve4, reject) => {
|
|
332
341
|
const database = new nodeSqlite3.Database(path, flags, (error) => {
|
|
333
342
|
if (error) reject(error);
|
|
334
|
-
else
|
|
343
|
+
else resolve4(database);
|
|
335
344
|
});
|
|
336
345
|
});
|
|
337
346
|
}
|
|
@@ -340,19 +349,19 @@ async function openNodeZip(file) {
|
|
|
340
349
|
if (path === void 0) {
|
|
341
350
|
throw new TypeError("The Node ZIP adapter requires a NodeFile");
|
|
342
351
|
}
|
|
343
|
-
const zipFile = await new Promise((
|
|
352
|
+
const zipFile = await new Promise((resolve4, reject) => {
|
|
344
353
|
yauzl.open(
|
|
345
354
|
path,
|
|
346
355
|
{ autoClose: false, lazyEntries: true },
|
|
347
356
|
(error, opened) => {
|
|
348
357
|
if (error || opened === void 0)
|
|
349
358
|
reject(error ?? new Error("Cannot open ZIP"));
|
|
350
|
-
else
|
|
359
|
+
else resolve4(opened);
|
|
351
360
|
}
|
|
352
361
|
);
|
|
353
362
|
});
|
|
354
363
|
const entries = await new Promise(
|
|
355
|
-
(
|
|
364
|
+
(resolve4, reject) => {
|
|
356
365
|
const discovered = /* @__PURE__ */ new Map();
|
|
357
366
|
const rejectAndClose = (error) => {
|
|
358
367
|
zipFile.close();
|
|
@@ -362,7 +371,7 @@ async function openNodeZip(file) {
|
|
|
362
371
|
};
|
|
363
372
|
const resolveEntries = () => {
|
|
364
373
|
zipFile.off("error", rejectAndClose);
|
|
365
|
-
|
|
374
|
+
resolve4(discovered);
|
|
366
375
|
};
|
|
367
376
|
zipFile.on("entry", (entry) => {
|
|
368
377
|
if (!entry.fileName.endsWith("/")) {
|
|
@@ -472,12 +481,12 @@ async function collectDecodedNodeStreamRange(input, offset, length) {
|
|
|
472
481
|
return Buffer.concat(chunks, collected);
|
|
473
482
|
}
|
|
474
483
|
async function openNodeZipEntryStream(zipFile, entry, options) {
|
|
475
|
-
return await new Promise((
|
|
484
|
+
return await new Promise((resolve4, reject) => {
|
|
476
485
|
const callback = (error, opened) => {
|
|
477
486
|
if (error || opened === void 0) {
|
|
478
487
|
reject(error ?? new Error(`Cannot read ZIP entry: ${entry.fileName}`));
|
|
479
488
|
} else {
|
|
480
|
-
|
|
489
|
+
resolve4(opened);
|
|
481
490
|
}
|
|
482
491
|
};
|
|
483
492
|
if (options === void 0) zipFile.openReadStream(entry, callback);
|
|
@@ -608,11 +617,11 @@ async function writeNodeStream(input, writer) {
|
|
|
608
617
|
);
|
|
609
618
|
}
|
|
610
619
|
async function collectNodeStream(input) {
|
|
611
|
-
return await new Promise((
|
|
620
|
+
return await new Promise((resolve4, reject) => {
|
|
612
621
|
const chunks = [];
|
|
613
622
|
input.on("data", (chunk) => chunks.push(chunk));
|
|
614
623
|
input.once("error", reject);
|
|
615
|
-
input.once("end", () =>
|
|
624
|
+
input.once("end", () => resolve4(Buffer.concat(chunks)));
|
|
616
625
|
});
|
|
617
626
|
}
|
|
618
627
|
var nodeWikiGraphPlatform = {
|
|
@@ -728,13 +737,272 @@ async function withNodeWikiGraphStorage(stateRoot, operation) {
|
|
|
728
737
|
);
|
|
729
738
|
}
|
|
730
739
|
|
|
740
|
+
// src/archive/target.ts
|
|
741
|
+
var import_promises2 = require("fs/promises");
|
|
742
|
+
var import_path2 = require("path");
|
|
743
|
+
var import_wiki_graph_core = require("wiki-graph-core");
|
|
744
|
+
|
|
745
|
+
// src/runtime-path.ts
|
|
746
|
+
var import_os = require("os");
|
|
747
|
+
var import_path = require("path");
|
|
748
|
+
|
|
749
|
+
// src/runtime-context.ts
|
|
750
|
+
var import_async_hooks = require("async_hooks");
|
|
751
|
+
var RUNTIME_CONTEXT_KEY = /* @__PURE__ */ Symbol.for("wiki-graph-sdk.runtime-context.v1");
|
|
752
|
+
var runtimeContext = getRuntimeContextStorage();
|
|
753
|
+
function getRuntimeContextStorage() {
|
|
754
|
+
const runtimeGlobal = globalThis;
|
|
755
|
+
const existing = runtimeGlobal[RUNTIME_CONTEXT_KEY];
|
|
756
|
+
if (existing !== void 0) {
|
|
757
|
+
return existing;
|
|
758
|
+
}
|
|
759
|
+
const storage = new import_async_hooks.AsyncLocalStorage();
|
|
760
|
+
Object.defineProperty(runtimeGlobal, RUNTIME_CONTEXT_KEY, {
|
|
761
|
+
configurable: false,
|
|
762
|
+
enumerable: false,
|
|
763
|
+
value: storage,
|
|
764
|
+
writable: false
|
|
765
|
+
});
|
|
766
|
+
return storage;
|
|
767
|
+
}
|
|
768
|
+
function getWikiGraphSDKRuntimeContext() {
|
|
769
|
+
return runtimeContext.getStore() ?? {
|
|
770
|
+
cwd: process.cwd(),
|
|
771
|
+
env: process.env,
|
|
772
|
+
envPolicy: "production",
|
|
773
|
+
providers: {}
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
// src/runtime-path.ts
|
|
778
|
+
function resolveWikiGraphRuntimePath(path) {
|
|
779
|
+
const context = getWikiGraphSDKRuntimeContext();
|
|
780
|
+
const environmentHome = context.env.HOME?.trim();
|
|
781
|
+
const home = environmentHome === void 0 || environmentHome === "" ? (0, import_os.homedir)() : environmentHome;
|
|
782
|
+
if (path === "~") return home;
|
|
783
|
+
if (path.startsWith("~/")) return (0, import_path.resolve)(home, path.slice(2));
|
|
784
|
+
return (0, import_path.isAbsolute)(path) ? path : (0, import_path.resolve)(context.cwd, path);
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
// src/archive/target.ts
|
|
788
|
+
var WikiGraphArchiveOwnershipError = class extends Error {
|
|
789
|
+
code = "WIKI_GRAPH_ARCHIVE_OWNERSHIP_MISMATCH";
|
|
790
|
+
constructor(message) {
|
|
791
|
+
super(message);
|
|
792
|
+
this.name = "WikiGraphArchiveOwnershipError";
|
|
793
|
+
}
|
|
794
|
+
};
|
|
795
|
+
async function resolveWikiGraphArchiveLocation(target) {
|
|
796
|
+
if (target.kind === "standalone") {
|
|
797
|
+
return await resolveStandaloneLocation(target);
|
|
798
|
+
}
|
|
799
|
+
return await resolveLibraryLocation(target);
|
|
800
|
+
}
|
|
801
|
+
async function assertStandaloneWikiGraphArchivePath(inputPath) {
|
|
802
|
+
const path = resolveWikiGraphRuntimePath(inputPath);
|
|
803
|
+
const candidate = await canonicalPath(path);
|
|
804
|
+
const candidateIdentity = await readFileIdentity(path);
|
|
805
|
+
const libraries = await (0, import_wiki_graph_core.listWikiGraphLibraries)();
|
|
806
|
+
const matches = await findMatchingMembers(
|
|
807
|
+
libraries,
|
|
808
|
+
candidate,
|
|
809
|
+
candidateIdentity
|
|
810
|
+
);
|
|
811
|
+
if (matches.length > 0) {
|
|
812
|
+
const match = requireUnambiguousManagedMatch(path, matches);
|
|
813
|
+
throw new WikiGraphArchiveOwnershipError(
|
|
814
|
+
`Standalone archive path belongs to registered library ${(0, import_wiki_graph_core.formatWikiGraphLibraryUri)(
|
|
815
|
+
match.library.isDefault ? void 0 : match.library.publicId
|
|
816
|
+
)}: ${path}. Use the library UUID URI ${match.archive.uri} instead.`
|
|
817
|
+
);
|
|
818
|
+
}
|
|
819
|
+
for (const library of libraries) {
|
|
820
|
+
const rootPath = getNodeResourcePath(library.folder);
|
|
821
|
+
const root = await canonicalPath(rootPath);
|
|
822
|
+
if (!isWithin(root, candidate)) continue;
|
|
823
|
+
throw new WikiGraphArchiveOwnershipError(
|
|
824
|
+
`Standalone archive path belongs to registered library ${(0, import_wiki_graph_core.formatWikiGraphLibraryUri)(
|
|
825
|
+
library.isDefault ? void 0 : library.publicId
|
|
826
|
+
)}: ${path}. Scan the library, then address the archive by its library UUID URI.`
|
|
827
|
+
);
|
|
828
|
+
}
|
|
829
|
+
return path;
|
|
830
|
+
}
|
|
831
|
+
async function resolveStandaloneLocation(target) {
|
|
832
|
+
if (target.path.startsWith("wikg://lib/")) {
|
|
833
|
+
throw new WikiGraphArchiveOwnershipError(
|
|
834
|
+
`A library archive URI cannot be used as a standalone path: ${target.path}`
|
|
835
|
+
);
|
|
836
|
+
}
|
|
837
|
+
const path = await assertStandaloneWikiGraphArchivePath(target.path);
|
|
838
|
+
const normalized = {
|
|
839
|
+
kind: "standalone",
|
|
840
|
+
path,
|
|
841
|
+
...target.objectUri === void 0 ? {} : { objectUri: target.objectUri }
|
|
842
|
+
};
|
|
843
|
+
return {
|
|
844
|
+
archiveFile: new NodeFile(path),
|
|
845
|
+
archiveKey: path,
|
|
846
|
+
archivePath: path,
|
|
847
|
+
indexScope: { archiveKey: path, archivePath: path, kind: "archive-index" },
|
|
848
|
+
locatedUri: (0, import_wiki_graph_core.formatLocatedWikiGraphUri)(path, target.objectUri),
|
|
849
|
+
target: normalized
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
async function resolveLibraryLocation(target) {
|
|
853
|
+
const parsedLocated = (0, import_wiki_graph_core.parseLocatedWikiGraphUri)(target.uri);
|
|
854
|
+
const archiveUri = parsedLocated.archivePath ?? target.uri;
|
|
855
|
+
const parsed = (0, import_wiki_graph_core.parseWikiGraphLibraryUri)(archiveUri);
|
|
856
|
+
if (parsed?.kind !== "archive") {
|
|
857
|
+
throw new WikiGraphArchiveOwnershipError(
|
|
858
|
+
`Library archive target must be a UUID archive URI: ${target.uri}`
|
|
859
|
+
);
|
|
860
|
+
}
|
|
861
|
+
await (0, import_wiki_graph_core.resolveWikiGraphLibrary)(parsed);
|
|
862
|
+
const archiveFile = await (0, import_wiki_graph_core.resolveWikiGraphLibraryArchiveFile)(archiveUri);
|
|
863
|
+
const normalized = {
|
|
864
|
+
kind: "library",
|
|
865
|
+
uri: target.uri
|
|
866
|
+
};
|
|
867
|
+
return {
|
|
868
|
+
archiveFile,
|
|
869
|
+
archiveKey: archiveUri,
|
|
870
|
+
archivePath: archiveUri,
|
|
871
|
+
indexScope: {
|
|
872
|
+
archiveKey: archiveUri,
|
|
873
|
+
archivePath: archiveUri,
|
|
874
|
+
kind: "archive-index"
|
|
875
|
+
},
|
|
876
|
+
libraryArchiveTarget: parsed,
|
|
877
|
+
locatedUri: target.uri,
|
|
878
|
+
publicArchiveUri: archiveUri,
|
|
879
|
+
target: normalized
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
async function canonicalPath(path) {
|
|
883
|
+
try {
|
|
884
|
+
return await (0, import_promises2.realpath)(path);
|
|
885
|
+
} catch {
|
|
886
|
+
const absolute = (0, import_path2.resolve)(path);
|
|
887
|
+
const parent = (0, import_path2.dirname)(absolute);
|
|
888
|
+
return parent === absolute ? absolute : (0, import_path2.join)(await canonicalPath(parent), (0, import_path2.basename)(absolute));
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
function isWithin(root, candidate) {
|
|
892
|
+
const child = (0, import_path2.relative)(root, candidate);
|
|
893
|
+
return child === "" || !child.startsWith("..") && !(0, import_path2.isAbsolute)(child);
|
|
894
|
+
}
|
|
895
|
+
async function findMatchingMembers(libraries, candidate, candidateIdentity) {
|
|
896
|
+
const members = [];
|
|
897
|
+
for (const library of libraries) {
|
|
898
|
+
const archives = await (0, import_wiki_graph_core.listWikiGraphLibraryArchives)({
|
|
899
|
+
isDefault: library.isDefault,
|
|
900
|
+
kind: "scope",
|
|
901
|
+
...library.isDefault ? {} : { publicId: library.publicId }
|
|
902
|
+
});
|
|
903
|
+
for (const archive of archives) {
|
|
904
|
+
if (archive.file === void 0) continue;
|
|
905
|
+
members.push({
|
|
906
|
+
archive,
|
|
907
|
+
library,
|
|
908
|
+
memberPath: getNodeResourcePath(archive.file)
|
|
909
|
+
});
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
const exact = [];
|
|
913
|
+
for (const member of members) {
|
|
914
|
+
if (await canonicalPath(member.memberPath) === candidate) {
|
|
915
|
+
exact.push(member);
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
if (exact.length > 0 || candidateIdentity === void 0) return exact;
|
|
919
|
+
const identityMatches = [];
|
|
920
|
+
for (const member of members) {
|
|
921
|
+
if (await readFileIdentity(member.memberPath) === candidateIdentity) {
|
|
922
|
+
identityMatches.push(member);
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
return identityMatches;
|
|
926
|
+
}
|
|
927
|
+
function requireUnambiguousManagedMatch(path, matches) {
|
|
928
|
+
if (matches.length === 1) return matches[0];
|
|
929
|
+
throw new WikiGraphArchiveOwnershipError(
|
|
930
|
+
`Archive file identity is ambiguous across managed archives: ${path}. Use an explicit library UUID URI (${matches.map((match) => match.archive.uri).join(", ")}).`
|
|
931
|
+
);
|
|
932
|
+
}
|
|
933
|
+
async function readFileIdentity(path) {
|
|
934
|
+
try {
|
|
935
|
+
const value = await (0, import_promises2.stat)(path);
|
|
936
|
+
return `${value.dev}:${value.ino}`;
|
|
937
|
+
} catch {
|
|
938
|
+
return void 0;
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
// src/archive/write.ts
|
|
943
|
+
var import_wiki_graph_core2 = require("wiki-graph-core");
|
|
944
|
+
async function writeWikiGraphArchiveLocation(location, operation, options = {}) {
|
|
945
|
+
const cacheOnly = options.searchIndexWritebackPolicy === "cache";
|
|
946
|
+
const write = async (archiveFile = location.archiveFile) => await new import_wiki_graph_core2.WikiGraphArchiveFile(archiveFile).write(operation, {
|
|
947
|
+
...cacheOnly ? {} : { derivedStateKeys: [location.archiveKey, location.archivePath] },
|
|
948
|
+
...options.invalidateContinuationCursors === void 0 ? {} : {
|
|
949
|
+
invalidateContinuationCursors: options.invalidateContinuationCursors
|
|
950
|
+
},
|
|
951
|
+
...options.searchIndexWritebackPolicy === void 0 ? {} : { searchIndexWritebackPolicy: options.searchIndexWritebackPolicy }
|
|
952
|
+
});
|
|
953
|
+
if (location.libraryArchiveTarget === void 0 || cacheOnly || options.refreshLibraryIndex === false) {
|
|
954
|
+
return await write();
|
|
955
|
+
}
|
|
956
|
+
return await (0, import_wiki_graph_core2.writeWikiGraphLibraryArchive)({
|
|
957
|
+
additionalDerivedStateKeys: [location.archiveKey, location.archivePath],
|
|
958
|
+
...options.invalidateContinuationCursors === void 0 ? {} : {
|
|
959
|
+
invalidateContinuationCursors: options.invalidateContinuationCursors
|
|
960
|
+
},
|
|
961
|
+
...options.onIndexSyncError === void 0 ? {} : { onIndexSyncError: options.onIndexSyncError },
|
|
962
|
+
operation: async (archiveFile) => await write(archiveFile),
|
|
963
|
+
target: location.libraryArchiveTarget
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
|
|
731
967
|
// src/worker.ts
|
|
732
968
|
var import_worker2 = require("wiki-graph-core/worker");
|
|
969
|
+
async function extractWikiGraphJobSnapshots(options) {
|
|
970
|
+
ensureNodeWikiGraphPlatform();
|
|
971
|
+
return await withNodeWikiGraphStorage(
|
|
972
|
+
options.stateDir,
|
|
973
|
+
async () => await new import_wiki_graph_core3.WikiGraphArchiveFile(
|
|
974
|
+
new NodeFile(options.wikgPath)
|
|
975
|
+
).readDocument(async (document) => {
|
|
976
|
+
const results = [];
|
|
977
|
+
for (const request of options.requests) {
|
|
978
|
+
options.signal?.throwIfAborted();
|
|
979
|
+
const chapterId = await (0, import_wiki_graph_core3.resolveChapterPathReadonly)(
|
|
980
|
+
document,
|
|
981
|
+
request.chapterPath
|
|
982
|
+
);
|
|
983
|
+
const revision = await (0, import_worker.writeChapterJobInputFile)(
|
|
984
|
+
document,
|
|
985
|
+
chapterId,
|
|
986
|
+
request.kind,
|
|
987
|
+
new NodeFile(request.outputPath),
|
|
988
|
+
request.options
|
|
989
|
+
);
|
|
990
|
+
const result = { ...request, chapterId, revision };
|
|
991
|
+
results.push(result);
|
|
992
|
+
await options.onSnapshot?.(result);
|
|
993
|
+
}
|
|
994
|
+
options.signal?.throwIfAborted();
|
|
995
|
+
return results;
|
|
996
|
+
})
|
|
997
|
+
);
|
|
998
|
+
}
|
|
733
999
|
async function applyWikiGraphJobArtifacts(options) {
|
|
734
1000
|
ensureNodeWikiGraphPlatform();
|
|
735
1001
|
return await withNodeWikiGraphStorage(options.stateDir, async () => {
|
|
1002
|
+
const location = await resolveWikiGraphArchiveLocation(options.archive);
|
|
736
1003
|
let applied = 0;
|
|
737
|
-
await
|
|
1004
|
+
await writeWikiGraphArchiveLocation(
|
|
1005
|
+
location,
|
|
738
1006
|
async (document) => {
|
|
739
1007
|
for await (const artifact of options.artifacts) {
|
|
740
1008
|
options.signal?.throwIfAborted();
|
|
@@ -750,7 +1018,8 @@ async function applyWikiGraphJobArtifacts(options) {
|
|
|
750
1018
|
);
|
|
751
1019
|
applied += 1;
|
|
752
1020
|
}
|
|
753
|
-
}
|
|
1021
|
+
},
|
|
1022
|
+
{ invalidateContinuationCursors: true }
|
|
754
1023
|
);
|
|
755
1024
|
options.signal?.throwIfAborted();
|
|
756
1025
|
return { applied };
|
|
@@ -769,6 +1038,7 @@ async function runBuildJobWorker(options) {
|
|
|
769
1038
|
applyChapterJobArtifactFile,
|
|
770
1039
|
applyWikiGraphJobArtifacts,
|
|
771
1040
|
createLocalChapterJobFileExecutor,
|
|
1041
|
+
extractWikiGraphJobSnapshots,
|
|
772
1042
|
runBuildJobWorker,
|
|
773
1043
|
writeChapterJobInputFile
|
|
774
1044
|
});
|