wiki-graph-sdk 0.8.2 → 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.
Files changed (49) hide show
  1. package/README.md +8 -3
  2. package/dist/archives.cjs +18 -19
  3. package/dist/archives.cjs.map +1 -1
  4. package/dist/archives.js +6 -7
  5. package/dist/archives.js.map +1 -1
  6. package/dist/conversions.cjs +11 -12
  7. package/dist/conversions.cjs.map +1 -1
  8. package/dist/conversions.js +6 -7
  9. package/dist/conversions.js.map +1 -1
  10. package/dist/default-worker.cjs +40 -17
  11. package/dist/default-worker.cjs.map +1 -1
  12. package/dist/default-worker.js +37 -14
  13. package/dist/default-worker.js.map +1 -1
  14. package/dist/embedding.cjs +6 -7
  15. package/dist/embedding.cjs.map +1 -1
  16. package/dist/embedding.js +6 -7
  17. package/dist/embedding.js.map +1 -1
  18. package/dist/gc.cjs +61 -9
  19. package/dist/gc.cjs.map +1 -1
  20. package/dist/gc.d.ts +1 -1
  21. package/dist/gc.js +61 -9
  22. package/dist/gc.js.map +1 -1
  23. package/dist/host-IbqJ8WSV.d.ts +18 -0
  24. package/dist/index.cjs +48 -28
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.ts +1 -1
  27. package/dist/index.js +36 -16
  28. package/dist/index.js.map +1 -1
  29. package/dist/local-config.cjs +6 -7
  30. package/dist/local-config.cjs.map +1 -1
  31. package/dist/local-config.js +6 -7
  32. package/dist/local-config.js.map +1 -1
  33. package/dist/maintenance.cjs.map +1 -1
  34. package/dist/maintenance.js.map +1 -1
  35. package/dist/runtime-config.cjs +6 -7
  36. package/dist/runtime-config.cjs.map +1 -1
  37. package/dist/runtime-config.js +6 -7
  38. package/dist/runtime-config.js.map +1 -1
  39. package/dist/stage.cjs +6 -7
  40. package/dist/stage.cjs.map +1 -1
  41. package/dist/stage.js +6 -7
  42. package/dist/stage.js.map +1 -1
  43. package/dist/worker.cjs +55 -31
  44. package/dist/worker.cjs.map +1 -1
  45. package/dist/worker.d.ts +1 -1
  46. package/dist/worker.js +61 -37
  47. package/dist/worker.js.map +1 -1
  48. package/package.json +2 -2
  49. package/dist/host-pQiVAKEY.d.ts +0 -10
@@ -65,6 +65,9 @@ function getRuntimeContextStorage() {
65
65
  });
66
66
  return storage;
67
67
  }
68
+ async function withWikiGraphSDKRuntimeContext(context, operation) {
69
+ return await runtimeContext.run(context, operation);
70
+ }
68
71
  function getWikiGraphSDKRuntimeContext() {
69
72
  return runtimeContext.getStore() ?? {
70
73
  cwd: process.cwd(),
@@ -74,7 +77,8 @@ function getWikiGraphSDKRuntimeContext() {
74
77
  };
75
78
  }
76
79
  function getWikiGraphSDKStateDir() {
77
- return getWikiGraphSDKRuntimeContext().stateDir;
80
+ const context = getWikiGraphSDKRuntimeContext();
81
+ return context.host?.stateDir ?? context.stateDir;
78
82
  }
79
83
  function getWikiGraphSDKProviders() {
80
84
  return getWikiGraphSDKRuntimeContext().providers ?? {};
@@ -781,6 +785,7 @@ async function withNodeWikiGraphStorage(stateRoot, operation) {
781
785
  }
782
786
 
783
787
  // src/local-config.ts
788
+ var import_promises2 = require("fs/promises");
784
789
  var import_path = require("path");
785
790
  var import_os = require("os");
786
791
  var LOCAL_CONFIG_SCHEMA_SQL = `
@@ -810,13 +815,10 @@ function validateLocalConfigSection(section, value) {
810
815
  }
811
816
  }
812
817
  async function withLocalConfigDatabase(operation) {
818
+ const stateDir = getWikiGraphSDKStateDir() ?? (0, import_path.join)((0, import_os.homedir)(), ".wikigraph");
819
+ await (0, import_promises2.mkdir)(stateDir, { recursive: true });
813
820
  const database = await (0, import_wiki_graph_core.openSharedStateDatabase)(
814
- new NodeFile(
815
- (0, import_path.join)(
816
- getWikiGraphSDKStateDir() ?? (0, import_path.join)((0, import_os.homedir)(), ".wikigraph"),
817
- "core.sqlite"
818
- )
819
- ),
821
+ new NodeFile((0, import_path.join)(stateDir, "core.sqlite")),
820
822
  LOCAL_CONFIG_SCHEMA_SQL
821
823
  );
822
824
  try {
@@ -1491,23 +1493,44 @@ function prepareWikiGraphSDKHost(host) {
1491
1493
  (0, import_platform2.installWikiGraphPlatform)(host.platform);
1492
1494
  }
1493
1495
  function assertWikiGraphSDKHostOptions(options) {
1494
- if (options.host?.storage !== void 0 && options.stateDir !== void 0) {
1496
+ if (options.host?.storage !== void 0 && options.host.stateDir === void 0) {
1497
+ throw new TypeError(
1498
+ "Wiki Graph SDK host.storage requires host.stateDir so SDK configuration cannot fall back to the default user state directory."
1499
+ );
1500
+ }
1501
+ if (options.stateDir !== void 0 && (options.host?.stateDir !== void 0 || options.host?.storage !== void 0)) {
1495
1502
  throw new TypeError(
1496
- "Wiki Graph SDK host.storage and stateDir cannot be used together."
1503
+ "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."
1497
1504
  );
1498
1505
  }
1499
1506
  }
1500
1507
  async function withWikiGraphSDKHost(options, operation) {
1501
- assertWikiGraphSDKHostOptions(options);
1502
- prepareWikiGraphSDKHost(options.host);
1503
- if (options.host?.storage !== void 0) {
1504
- return await (0, import_platform2.withWikiGraphStorage)(options.host.storage, operation);
1508
+ const current = getWikiGraphSDKRuntimeContext();
1509
+ const effective = {
1510
+ ...options.host === void 0 ? current.host === void 0 ? {} : { host: current.host } : { host: options.host },
1511
+ ...options.stateDir === void 0 ? current.stateDir === void 0 ? {} : { stateDir: current.stateDir } : { stateDir: options.stateDir }
1512
+ };
1513
+ assertWikiGraphSDKHostOptions(effective);
1514
+ prepareWikiGraphSDKHost(effective.host);
1515
+ const runWithContext = async () => await withWikiGraphSDKRuntimeContext(
1516
+ {
1517
+ ...current,
1518
+ ...effective.host === void 0 ? {} : { host: effective.host },
1519
+ ...effective.stateDir === void 0 ? {} : { stateDir: effective.stateDir }
1520
+ },
1521
+ operation
1522
+ );
1523
+ if (effective.host?.storage !== void 0) {
1524
+ return await (0, import_platform2.withWikiGraphStorage)(effective.host.storage, runWithContext);
1505
1525
  }
1506
- return await withNodeWikiGraphStorage(options.stateDir, operation);
1526
+ return await withNodeWikiGraphStorage(
1527
+ effective.host?.stateDir ?? effective.stateDir,
1528
+ runWithContext
1529
+ );
1507
1530
  }
1508
1531
 
1509
1532
  // src/archive/target.ts
1510
- var import_promises2 = require("fs/promises");
1533
+ var import_promises3 = require("fs/promises");
1511
1534
  var import_path3 = require("path");
1512
1535
  var import_wiki_graph_core5 = require("wiki-graph-core");
1513
1536
 
@@ -1635,7 +1658,7 @@ async function resolveLibraryLocation(target) {
1635
1658
  }
1636
1659
  async function canonicalPath(path) {
1637
1660
  try {
1638
- return await (0, import_promises2.realpath)(path);
1661
+ return await (0, import_promises3.realpath)(path);
1639
1662
  } catch {
1640
1663
  const absolute = (0, import_path3.resolve)(path);
1641
1664
  const parent = (0, import_path3.dirname)(absolute);
@@ -1686,7 +1709,7 @@ function requireUnambiguousManagedMatch(path, matches) {
1686
1709
  }
1687
1710
  async function readFileIdentity(path) {
1688
1711
  try {
1689
- const value = await (0, import_promises2.stat)(path);
1712
+ const value = await (0, import_promises3.stat)(path);
1690
1713
  return `${value.dev}:${value.ino}`;
1691
1714
  } catch {
1692
1715
  return void 0;