wiki-graph-sdk 0.8.1 → 0.8.3
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 +30 -0
- package/dist/archives.cjs +25 -19
- package/dist/archives.cjs.map +1 -1
- package/dist/archives.d.ts +2 -0
- package/dist/archives.js +14 -7
- package/dist/archives.js.map +1 -1
- package/dist/conversions.cjs +11 -12
- package/dist/conversions.cjs.map +1 -1
- package/dist/conversions.js +7 -7
- package/dist/conversions.js.map +1 -1
- package/dist/default-worker.cjs +83 -20
- package/dist/default-worker.cjs.map +1 -1
- package/dist/default-worker.js +84 -17
- package/dist/default-worker.js.map +1 -1
- package/dist/embedding.cjs +6 -7
- package/dist/embedding.cjs.map +1 -1
- package/dist/embedding.js +7 -7
- package/dist/embedding.js.map +1 -1
- package/dist/gc.cjs +106 -12
- package/dist/gc.cjs.map +1 -1
- package/dist/gc.d.ts +3 -0
- package/dist/gc.js +110 -12
- package/dist/gc.js.map +1 -1
- package/dist/host-IbqJ8WSV.d.ts +18 -0
- package/dist/index.cjs +127 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -4
- package/dist/index.js +119 -21
- package/dist/index.js.map +1 -1
- package/dist/local-config.cjs +6 -7
- package/dist/local-config.cjs.map +1 -1
- package/dist/local-config.js +7 -7
- package/dist/local-config.js.map +1 -1
- package/dist/maintenance.cjs.map +1 -1
- package/dist/maintenance.js +1 -0
- package/dist/maintenance.js.map +1 -1
- package/dist/node-platform.cjs +18 -4
- package/dist/node-platform.cjs.map +1 -1
- package/dist/node-platform.d.ts +12 -3
- package/dist/node-platform.js +18 -4
- package/dist/node-platform.js.map +1 -1
- package/dist/runtime-config.cjs +6 -7
- package/dist/runtime-config.cjs.map +1 -1
- package/dist/runtime-config.js +7 -7
- package/dist/runtime-config.js.map +1 -1
- package/dist/stage.cjs +6 -7
- package/dist/stage.cjs.map +1 -1
- package/dist/stage.js +7 -7
- package/dist/stage.js.map +1 -1
- package/dist/worker.cjs +113 -50
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.ts +7 -2
- package/dist/worker.js +125 -58
- package/dist/worker.js.map +1 -1
- package/package.json +2 -2
package/dist/default-worker.js
CHANGED
|
@@ -45,6 +45,9 @@ function getRuntimeContextStorage() {
|
|
|
45
45
|
});
|
|
46
46
|
return storage;
|
|
47
47
|
}
|
|
48
|
+
async function withWikiGraphSDKRuntimeContext(context, operation) {
|
|
49
|
+
return await runtimeContext.run(context, operation);
|
|
50
|
+
}
|
|
48
51
|
function getWikiGraphSDKRuntimeContext() {
|
|
49
52
|
return runtimeContext.getStore() ?? {
|
|
50
53
|
cwd: process.cwd(),
|
|
@@ -54,7 +57,8 @@ function getWikiGraphSDKRuntimeContext() {
|
|
|
54
57
|
};
|
|
55
58
|
}
|
|
56
59
|
function getWikiGraphSDKStateDir() {
|
|
57
|
-
|
|
60
|
+
const context = getWikiGraphSDKRuntimeContext();
|
|
61
|
+
return context.host?.stateDir ?? context.stateDir;
|
|
58
62
|
}
|
|
59
63
|
function getWikiGraphSDKProviders() {
|
|
60
64
|
return getWikiGraphSDKRuntimeContext().providers ?? {};
|
|
@@ -75,6 +79,7 @@ import * as yauzl from "yauzl";
|
|
|
75
79
|
import * as yazl from "yazl";
|
|
76
80
|
import { Environment, Loader } from "nunjucks";
|
|
77
81
|
import {
|
|
82
|
+
getWikiGraphPlatform,
|
|
78
83
|
getWikiGraphStorage,
|
|
79
84
|
installWikiGraphPlatform,
|
|
80
85
|
installWikiGraphStorage,
|
|
@@ -736,15 +741,28 @@ function resolveNodeDataDirectory() {
|
|
|
736
741
|
directory = parent;
|
|
737
742
|
}
|
|
738
743
|
}
|
|
739
|
-
function createNodeWikiGraphStorage(
|
|
744
|
+
function createNodeWikiGraphStorage(stateRootOrOptions = pathModule.join(
|
|
745
|
+
os.homedir(),
|
|
746
|
+
".wikigraph"
|
|
747
|
+
)) {
|
|
748
|
+
const libraryRoot = typeof stateRootOrOptions === "string" ? stateRootOrOptions : stateRootOrOptions.libraryRoot;
|
|
749
|
+
const documentStoreRoot = typeof stateRootOrOptions === "string" ? pathModule.join(stateRootOrOptions, "documents") : stateRootOrOptions.documentStoreRoot;
|
|
740
750
|
return {
|
|
741
|
-
library: new NodeDirectory(
|
|
742
|
-
documentStore: new NodeDirectory(
|
|
751
|
+
library: new NodeDirectory(libraryRoot),
|
|
752
|
+
documentStore: new NodeDirectory(documentStoreRoot)
|
|
743
753
|
};
|
|
744
754
|
}
|
|
745
|
-
function
|
|
746
|
-
|
|
747
|
-
|
|
755
|
+
function ensureNodeWikiGraphPlatform() {
|
|
756
|
+
try {
|
|
757
|
+
getWikiGraphPlatform();
|
|
758
|
+
} catch {
|
|
759
|
+
installWikiGraphPlatform(nodeWikiGraphPlatform);
|
|
760
|
+
}
|
|
761
|
+
try {
|
|
762
|
+
getWikiGraphStorage();
|
|
763
|
+
} catch {
|
|
764
|
+
installWikiGraphStorage(createNodeWikiGraphStorage());
|
|
765
|
+
}
|
|
748
766
|
}
|
|
749
767
|
async function withNodeWikiGraphStorage(stateRoot, operation) {
|
|
750
768
|
return await withWikiGraphStorage(
|
|
@@ -754,6 +772,7 @@ async function withNodeWikiGraphStorage(stateRoot, operation) {
|
|
|
754
772
|
}
|
|
755
773
|
|
|
756
774
|
// src/local-config.ts
|
|
775
|
+
import { mkdir as mkdir2 } from "fs/promises";
|
|
757
776
|
import { join as join2 } from "path";
|
|
758
777
|
import { homedir as homedir2 } from "os";
|
|
759
778
|
var LOCAL_CONFIG_SCHEMA_SQL = `
|
|
@@ -783,13 +802,10 @@ function validateLocalConfigSection(section, value) {
|
|
|
783
802
|
}
|
|
784
803
|
}
|
|
785
804
|
async function withLocalConfigDatabase(operation) {
|
|
805
|
+
const stateDir = getWikiGraphSDKStateDir() ?? join2(homedir2(), ".wikigraph");
|
|
806
|
+
await mkdir2(stateDir, { recursive: true });
|
|
786
807
|
const database = await openSharedStateDatabase(
|
|
787
|
-
new NodeFile(
|
|
788
|
-
join2(
|
|
789
|
-
getWikiGraphSDKStateDir() ?? join2(homedir2(), ".wikigraph"),
|
|
790
|
-
"core.sqlite"
|
|
791
|
-
)
|
|
792
|
-
),
|
|
808
|
+
new NodeFile(join2(stateDir, "core.sqlite")),
|
|
793
809
|
LOCAL_CONFIG_SCHEMA_SQL
|
|
794
810
|
);
|
|
795
811
|
try {
|
|
@@ -1466,6 +1482,55 @@ import {
|
|
|
1466
1482
|
WikiGraphArchiveFile as WikiGraphArchiveFile2
|
|
1467
1483
|
} from "wiki-graph-core";
|
|
1468
1484
|
|
|
1485
|
+
// src/host.ts
|
|
1486
|
+
import {
|
|
1487
|
+
installWikiGraphPlatform as installWikiGraphPlatform2,
|
|
1488
|
+
withWikiGraphStorage as withWikiGraphStorage2
|
|
1489
|
+
} from "wiki-graph-core/platform";
|
|
1490
|
+
function prepareWikiGraphSDKHost(host) {
|
|
1491
|
+
if (host?.platform === void 0) {
|
|
1492
|
+
ensureNodeWikiGraphPlatform();
|
|
1493
|
+
return;
|
|
1494
|
+
}
|
|
1495
|
+
installWikiGraphPlatform2(host.platform);
|
|
1496
|
+
}
|
|
1497
|
+
function assertWikiGraphSDKHostOptions(options) {
|
|
1498
|
+
if (options.host?.storage !== void 0 && options.host.stateDir === void 0) {
|
|
1499
|
+
throw new TypeError(
|
|
1500
|
+
"Wiki Graph SDK host.storage requires host.stateDir so SDK configuration cannot fall back to the default user state directory."
|
|
1501
|
+
);
|
|
1502
|
+
}
|
|
1503
|
+
if (options.stateDir !== void 0 && (options.host?.stateDir !== void 0 || options.host?.storage !== void 0)) {
|
|
1504
|
+
throw new TypeError(
|
|
1505
|
+
"Wiki Graph SDK host state/storage and top-level stateDir cannot be used together. Put the state directory in host.stateDir when providing host.storage."
|
|
1506
|
+
);
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
async function withWikiGraphSDKHost(options, operation) {
|
|
1510
|
+
const current = getWikiGraphSDKRuntimeContext();
|
|
1511
|
+
const effective = {
|
|
1512
|
+
...options.host === void 0 ? current.host === void 0 ? {} : { host: current.host } : { host: options.host },
|
|
1513
|
+
...options.stateDir === void 0 ? current.stateDir === void 0 ? {} : { stateDir: current.stateDir } : { stateDir: options.stateDir }
|
|
1514
|
+
};
|
|
1515
|
+
assertWikiGraphSDKHostOptions(effective);
|
|
1516
|
+
prepareWikiGraphSDKHost(effective.host);
|
|
1517
|
+
const runWithContext = async () => await withWikiGraphSDKRuntimeContext(
|
|
1518
|
+
{
|
|
1519
|
+
...current,
|
|
1520
|
+
...effective.host === void 0 ? {} : { host: effective.host },
|
|
1521
|
+
...effective.stateDir === void 0 ? {} : { stateDir: effective.stateDir }
|
|
1522
|
+
},
|
|
1523
|
+
operation
|
|
1524
|
+
);
|
|
1525
|
+
if (effective.host?.storage !== void 0) {
|
|
1526
|
+
return await withWikiGraphStorage2(effective.host.storage, runWithContext);
|
|
1527
|
+
}
|
|
1528
|
+
return await withNodeWikiGraphStorage(
|
|
1529
|
+
effective.host?.stateDir ?? effective.stateDir,
|
|
1530
|
+
runWithContext
|
|
1531
|
+
);
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1469
1534
|
// src/archive/target.ts
|
|
1470
1535
|
import { realpath, stat as stat2 } from "fs/promises";
|
|
1471
1536
|
import { basename as basename2, dirname as dirname2, isAbsolute as isAbsolute3, join as join3, relative, resolve as resolve3 } from "path";
|
|
@@ -1697,10 +1762,12 @@ import {
|
|
|
1697
1762
|
writeChapterJobInputFile as writeChapterJobInputFile2
|
|
1698
1763
|
} from "wiki-graph-core/worker";
|
|
1699
1764
|
async function runBuildJobWorker(options) {
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1765
|
+
const { host, stateDir, ...coreOptions } = options;
|
|
1766
|
+
await withWikiGraphSDKHost(
|
|
1767
|
+
{
|
|
1768
|
+
...host === void 0 ? {} : { host },
|
|
1769
|
+
...stateDir === void 0 ? {} : { stateDir }
|
|
1770
|
+
},
|
|
1704
1771
|
async () => await runCoreBuildJobWorker(coreOptions)
|
|
1705
1772
|
);
|
|
1706
1773
|
}
|