wiki-graph-sdk 0.8.2 → 0.8.4

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 (51) hide show
  1. package/README.md +13 -3
  2. package/dist/archives.cjs +382 -25
  3. package/dist/archives.cjs.map +1 -1
  4. package/dist/archives.d.ts +4 -216
  5. package/dist/archives.js +372 -13
  6. package/dist/archives.js.map +1 -1
  7. package/dist/conversions.cjs +11 -12
  8. package/dist/conversions.cjs.map +1 -1
  9. package/dist/conversions.js +6 -7
  10. package/dist/conversions.js.map +1 -1
  11. package/dist/default-worker.cjs +40 -17
  12. package/dist/default-worker.cjs.map +1 -1
  13. package/dist/default-worker.js +37 -14
  14. package/dist/default-worker.js.map +1 -1
  15. package/dist/embedding.cjs +6 -7
  16. package/dist/embedding.cjs.map +1 -1
  17. package/dist/embedding.js +6 -7
  18. package/dist/embedding.js.map +1 -1
  19. package/dist/gc.cjs +61 -9
  20. package/dist/gc.cjs.map +1 -1
  21. package/dist/gc.d.ts +1 -1
  22. package/dist/gc.js +61 -9
  23. package/dist/gc.js.map +1 -1
  24. package/dist/host-IbqJ8WSV.d.ts +18 -0
  25. package/dist/index-DQzLAnjf.d.ts +346 -0
  26. package/dist/index.cjs +622 -40
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.ts +20 -12
  29. package/dist/index.js +601 -31
  30. package/dist/index.js.map +1 -1
  31. package/dist/local-config.cjs +6 -7
  32. package/dist/local-config.cjs.map +1 -1
  33. package/dist/local-config.js +6 -7
  34. package/dist/local-config.js.map +1 -1
  35. package/dist/maintenance.cjs.map +1 -1
  36. package/dist/maintenance.js.map +1 -1
  37. package/dist/runtime-config.cjs +6 -7
  38. package/dist/runtime-config.cjs.map +1 -1
  39. package/dist/runtime-config.js +6 -7
  40. package/dist/runtime-config.js.map +1 -1
  41. package/dist/stage.cjs +6 -7
  42. package/dist/stage.cjs.map +1 -1
  43. package/dist/stage.js +6 -7
  44. package/dist/stage.js.map +1 -1
  45. package/dist/worker.cjs +55 -31
  46. package/dist/worker.cjs.map +1 -1
  47. package/dist/worker.d.ts +1 -1
  48. package/dist/worker.js +61 -37
  49. package/dist/worker.js.map +1 -1
  50. package/package.json +2 -2
  51. package/dist/host-pQiVAKEY.d.ts +0 -10
@@ -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
- return getWikiGraphSDKRuntimeContext().stateDir;
60
+ const context = getWikiGraphSDKRuntimeContext();
61
+ return context.host?.stateDir ?? context.stateDir;
58
62
  }
59
63
  function getWikiGraphSDKProviders() {
60
64
  return getWikiGraphSDKRuntimeContext().providers ?? {};
@@ -768,6 +772,7 @@ async function withNodeWikiGraphStorage(stateRoot, operation) {
768
772
  }
769
773
 
770
774
  // src/local-config.ts
775
+ import { mkdir as mkdir2 } from "fs/promises";
771
776
  import { join as join2 } from "path";
772
777
  import { homedir as homedir2 } from "os";
773
778
  var LOCAL_CONFIG_SCHEMA_SQL = `
@@ -797,13 +802,10 @@ function validateLocalConfigSection(section, value) {
797
802
  }
798
803
  }
799
804
  async function withLocalConfigDatabase(operation) {
805
+ const stateDir = getWikiGraphSDKStateDir() ?? join2(homedir2(), ".wikigraph");
806
+ await mkdir2(stateDir, { recursive: true });
800
807
  const database = await openSharedStateDatabase(
801
- new NodeFile(
802
- join2(
803
- getWikiGraphSDKStateDir() ?? join2(homedir2(), ".wikigraph"),
804
- "core.sqlite"
805
- )
806
- ),
808
+ new NodeFile(join2(stateDir, "core.sqlite")),
807
809
  LOCAL_CONFIG_SCHEMA_SQL
808
810
  );
809
811
  try {
@@ -1493,19 +1495,40 @@ function prepareWikiGraphSDKHost(host) {
1493
1495
  installWikiGraphPlatform2(host.platform);
1494
1496
  }
1495
1497
  function assertWikiGraphSDKHostOptions(options) {
1496
- if (options.host?.storage !== void 0 && options.stateDir !== void 0) {
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)) {
1497
1504
  throw new TypeError(
1498
- "Wiki Graph SDK host.storage and stateDir cannot be used together."
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."
1499
1506
  );
1500
1507
  }
1501
1508
  }
1502
1509
  async function withWikiGraphSDKHost(options, operation) {
1503
- assertWikiGraphSDKHostOptions(options);
1504
- prepareWikiGraphSDKHost(options.host);
1505
- if (options.host?.storage !== void 0) {
1506
- return await withWikiGraphStorage2(options.host.storage, 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);
1507
1527
  }
1508
- return await withNodeWikiGraphStorage(options.stateDir, operation);
1528
+ return await withNodeWikiGraphStorage(
1529
+ effective.host?.stateDir ?? effective.stateDir,
1530
+ runWithContext
1531
+ );
1509
1532
  }
1510
1533
 
1511
1534
  // src/archive/target.ts