wiki-graph-sdk 0.8.4 → 0.9.0

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.js CHANGED
@@ -43,6 +43,7 @@ import {
43
43
  getChapterTree,
44
44
  WikiGraph as WikiGraph2,
45
45
  WikiGraphArchiveFile as WikiGraphArchiveFile2,
46
+ WikiGraphDirectoryFile as WikiGraphDirectoryFile2,
46
47
  TOC_FILE_VERSION,
47
48
  writeWikgArchive,
48
49
  ObjectMetadataKind
@@ -1292,6 +1293,9 @@ import {
1292
1293
  resolveWikiGraphLibrary,
1293
1294
  resolveWikiGraphLibraryArchiveFile
1294
1295
  } from "wiki-graph-core";
1296
+ function requireWikiGraphArchiveFile(location) {
1297
+ return location.archiveFile;
1298
+ }
1295
1299
  var WikiGraphArchiveOwnershipError = class extends Error {
1296
1300
  code = "WIKI_GRAPH_ARCHIVE_OWNERSHIP_MISMATCH";
1297
1301
  constructor(message) {
@@ -1408,11 +1412,12 @@ async function findMatchingMembers(libraries, candidate, candidateIdentity) {
1408
1412
  ...library.isDefault ? {} : { publicId: library.publicId }
1409
1413
  });
1410
1414
  for (const archive of archives) {
1411
- if (archive.file === void 0) continue;
1415
+ const physical = archive.file ?? archive.directory;
1416
+ if (physical === void 0) continue;
1412
1417
  members.push({
1413
1418
  archive,
1414
1419
  library,
1415
- memberPath: getNodeResourcePath(archive.file)
1420
+ memberPath: getNodeResourcePath(physical)
1416
1421
  });
1417
1422
  }
1418
1423
  }
@@ -1902,17 +1907,30 @@ function formatLocatedChapterUri(archiveUri, chapter) {
1902
1907
  // src/archive/write.ts
1903
1908
  import {
1904
1909
  WikiGraphArchiveFile,
1910
+ WikiGraphDirectoryFile,
1905
1911
  writeWikiGraphLibraryArchive
1906
1912
  } from "wiki-graph-core";
1907
1913
  async function writeWikiGraphArchiveLocation(location, operation, options = {}) {
1908
1914
  const cacheOnly = options.searchIndexWritebackPolicy === "cache";
1909
- const write = async (archiveFile = location.archiveFile) => await new WikiGraphArchiveFile(archiveFile).write(operation, {
1910
- ...cacheOnly ? {} : { derivedStateKeys: [location.archiveKey, location.archivePath] },
1911
- ...options.invalidateContinuationCursors === void 0 ? {} : {
1912
- invalidateContinuationCursors: options.invalidateContinuationCursors
1913
- },
1914
- ...options.searchIndexWritebackPolicy === void 0 ? {} : { searchIndexWritebackPolicy: options.searchIndexWritebackPolicy }
1915
- });
1915
+ const write = async (archiveFile = location.archiveFile) => {
1916
+ const writeOptions = {
1917
+ ...cacheOnly ? {} : { derivedStateKeys: [location.archiveKey, location.archivePath] },
1918
+ ...options.invalidateContinuationCursors === void 0 ? {} : {
1919
+ invalidateContinuationCursors: options.invalidateContinuationCursors
1920
+ },
1921
+ ...options.searchIndexWritebackPolicy === void 0 ? {} : { searchIndexWritebackPolicy: options.searchIndexWritebackPolicy }
1922
+ };
1923
+ if (archiveFile.kind === "directory") {
1924
+ return await new WikiGraphDirectoryFile(archiveFile).write(
1925
+ operation,
1926
+ writeOptions
1927
+ );
1928
+ }
1929
+ return await new WikiGraphArchiveFile(archiveFile).write(
1930
+ operation,
1931
+ writeOptions
1932
+ );
1933
+ };
1916
1934
  if (location.libraryArchiveTarget === void 0 || cacheOnly || options.refreshLibraryIndex === false) {
1917
1935
  return await write();
1918
1936
  }
@@ -2566,7 +2584,7 @@ var WikiGraphArchiveHandle = class {
2566
2584
  return await this.#writeDocument(async (document) => {
2567
2585
  const chapterId = await resolveChapterPathReadonly(document, path);
2568
2586
  await assertChapterResetAllowed(
2569
- this.#location.archiveFile,
2587
+ requireWikiGraphArchiveFile(this.#location),
2570
2588
  chapterId,
2571
2589
  stage
2572
2590
  );
@@ -2812,14 +2830,18 @@ var WikiGraphArchiveHandle = class {
2812
2830
  }, options);
2813
2831
  }
2814
2832
  async readCover(options = {}) {
2815
- const app = new WikiGraph2({});
2816
- return await this.#runtime.run(
2817
- async () => await app.openSession(
2833
+ return await this.#runtime.run(async () => {
2834
+ if (this.#location.archiveFile.kind === "directory") {
2835
+ return await this.#readDocument(
2836
+ async (document) => await document.readCover()
2837
+ );
2838
+ }
2839
+ const app = new WikiGraph2({});
2840
+ return await app.openSession(
2818
2841
  this.#location.archiveFile,
2819
2842
  async (archive) => await archive.readCover()
2820
- ),
2821
- options.signal
2822
- );
2843
+ );
2844
+ }, options.signal);
2823
2845
  }
2824
2846
  async replaceMetadata(objectPath, value, options = {}) {
2825
2847
  return await this.#writeDocument(async (document) => {
@@ -2860,9 +2882,11 @@ var WikiGraphArchiveHandle = class {
2860
2882
  }
2861
2883
  async #readDocument(operation, options = {}) {
2862
2884
  return await this.#runtime.run(
2863
- async () => await new WikiGraphArchiveFile2(this.#location.archiveFile).readDocument(
2864
- operation
2865
- ),
2885
+ async () => this.#location.archiveFile.kind === "directory" ? await new WikiGraphDirectoryFile2(
2886
+ this.#location.archiveFile
2887
+ ).readDocument(operation) : await new WikiGraphArchiveFile2(
2888
+ this.#location.archiveFile
2889
+ ).readDocument(operation),
2866
2890
  options.signal
2867
2891
  );
2868
2892
  }