wiki-graph-sdk 0.8.3 → 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.
package/README.md CHANGED
@@ -78,6 +78,11 @@ Job event subscriptions observe durable work without coupling observation to
78
78
  cancellation. Call `job.cancel()` explicitly to cancel a job; unsubscribing
79
79
  only stops the current listener.
80
80
 
81
+ `libraries.searchBuckets()` projects one shared search session into typed,
82
+ independently paginated buckets. Continue one bucket with
83
+ `libraries.continueSearchBucket()`; sibling cursors remain unchanged. The
84
+ existing `libraries.search()` API keeps its sequential single-cursor result.
85
+
81
86
  Services that receive chapter job artifacts as files can apply an ordered,
82
87
  lazy sequence through the Node delivery boundary without importing Core:
83
88
 
package/dist/archives.cjs CHANGED
@@ -1900,6 +1900,236 @@ async function writeWikiGraphArchiveLocation(location, operation, options = {})
1900
1900
  });
1901
1901
  }
1902
1902
 
1903
+ // src/pages.ts
1904
+ function createCursor(implementation) {
1905
+ let released = false;
1906
+ const assertLive = () => {
1907
+ if (released) throw new Error("Cursor has been released.");
1908
+ };
1909
+ return {
1910
+ pageClass: implementation.pageClass,
1911
+ async next(options = {}) {
1912
+ assertLive();
1913
+ return await implementation.next(options);
1914
+ },
1915
+ async token() {
1916
+ assertLive();
1917
+ return await implementation.token();
1918
+ },
1919
+ async release() {
1920
+ if (released) return;
1921
+ released = true;
1922
+ await implementation.release?.();
1923
+ }
1924
+ };
1925
+ }
1926
+ function createPageCursor(implementation) {
1927
+ let token;
1928
+ return createCursor({
1929
+ pageClass: implementation.pageClass,
1930
+ next: async (options) => await implementation.next(implementation.rawCursor, options),
1931
+ token: async () => {
1932
+ token ??= await implementation.createToken(implementation.rawCursor);
1933
+ return token;
1934
+ },
1935
+ release: async () => {
1936
+ if (token !== void 0) await implementation.releaseToken?.(token);
1937
+ token = void 0;
1938
+ }
1939
+ });
1940
+ }
1941
+
1942
+ // src/result-pages.ts
1943
+ var ArchiveFindPage = class _ArchiveFindPage {
1944
+ result;
1945
+ chapters;
1946
+ items;
1947
+ lens;
1948
+ lensHint;
1949
+ limit;
1950
+ match;
1951
+ rawNextCursor;
1952
+ order;
1953
+ query;
1954
+ terms;
1955
+ types;
1956
+ #cursor;
1957
+ constructor(result, cursor = null) {
1958
+ this.result = result;
1959
+ this.chapters = result.chapters;
1960
+ this.items = result.items;
1961
+ this.lens = result.lens;
1962
+ this.lensHint = result.lensHint;
1963
+ this.limit = result.limit;
1964
+ this.match = result.match;
1965
+ this.rawNextCursor = result.nextCursor;
1966
+ this.order = result.order;
1967
+ this.query = result.query;
1968
+ this.terms = result.terms;
1969
+ this.types = result.types;
1970
+ this.#cursor = cursor;
1971
+ }
1972
+ static pageClass = _ArchiveFindPage;
1973
+ [Symbol.iterator]() {
1974
+ return this.items[Symbol.iterator]();
1975
+ }
1976
+ nextCursor() {
1977
+ return this.#cursor;
1978
+ }
1979
+ };
1980
+ var ArchiveCollectionPage = class _ArchiveCollectionPage {
1981
+ result;
1982
+ chapters;
1983
+ ids;
1984
+ items;
1985
+ limit;
1986
+ rawNextCursor;
1987
+ order;
1988
+ types;
1989
+ #cursor;
1990
+ constructor(result, cursor = null) {
1991
+ this.result = result;
1992
+ this.chapters = result.chapters;
1993
+ this.ids = result.ids;
1994
+ this.items = result.items;
1995
+ this.limit = result.limit;
1996
+ this.rawNextCursor = result.nextCursor;
1997
+ this.order = result.order;
1998
+ this.types = result.types;
1999
+ this.#cursor = cursor;
2000
+ }
2001
+ static pageClass = _ArchiveCollectionPage;
2002
+ [Symbol.iterator]() {
2003
+ return this.items[Symbol.iterator]();
2004
+ }
2005
+ nextCursor() {
2006
+ return this.#cursor;
2007
+ }
2008
+ };
2009
+ var ArchiveEvidencePage = class _ArchiveEvidencePage {
2010
+ result;
2011
+ items;
2012
+ limit;
2013
+ rawNextCursor;
2014
+ #cursor;
2015
+ constructor(result, cursor = null) {
2016
+ this.result = result;
2017
+ this.items = result.items;
2018
+ this.limit = result.limit;
2019
+ this.rawNextCursor = result.nextCursor;
2020
+ this.#cursor = cursor;
2021
+ }
2022
+ static pageClass = _ArchiveEvidencePage;
2023
+ [Symbol.iterator]() {
2024
+ return this.items[Symbol.iterator]();
2025
+ }
2026
+ nextCursor() {
2027
+ return this.#cursor;
2028
+ }
2029
+ };
2030
+ var ArchiveRelatedPage = class _ArchiveRelatedPage {
2031
+ result;
2032
+ items;
2033
+ limit;
2034
+ rawNextCursor;
2035
+ #cursor;
2036
+ constructor(result, cursor = null) {
2037
+ this.result = result;
2038
+ this.items = result.items;
2039
+ this.limit = result.limit;
2040
+ this.rawNextCursor = result.nextCursor;
2041
+ this.#cursor = cursor;
2042
+ }
2043
+ static pageClass = _ArchiveRelatedPage;
2044
+ [Symbol.iterator]() {
2045
+ return this.items[Symbol.iterator]();
2046
+ }
2047
+ nextCursor() {
2048
+ return this.#cursor;
2049
+ }
2050
+ };
2051
+ var ArchiveSourceLocatorPage = class _ArchiveSourceLocatorPage {
2052
+ result;
2053
+ items;
2054
+ limit;
2055
+ rawNextCursor;
2056
+ #cursor;
2057
+ constructor(result, cursor = null) {
2058
+ this.result = result;
2059
+ this.items = result.items;
2060
+ this.limit = result.limit;
2061
+ this.rawNextCursor = result.nextCursor;
2062
+ this.#cursor = cursor;
2063
+ }
2064
+ static pageClass = _ArchiveSourceLocatorPage;
2065
+ [Symbol.iterator]() {
2066
+ return this.items[Symbol.iterator]();
2067
+ }
2068
+ nextCursor() {
2069
+ return this.#cursor;
2070
+ }
2071
+ };
2072
+ function createArchiveFindPage(result, next, createToken, releaseToken) {
2073
+ return new ArchiveFindPage(
2074
+ result,
2075
+ result.nextCursor === null ? null : createPageCursor({
2076
+ pageClass: ArchiveFindPage,
2077
+ rawCursor: result.nextCursor,
2078
+ next,
2079
+ createToken,
2080
+ releaseToken
2081
+ })
2082
+ );
2083
+ }
2084
+ function createArchiveCollectionPage(result, next, createToken, releaseToken) {
2085
+ return new ArchiveCollectionPage(
2086
+ result,
2087
+ result.nextCursor === null ? null : createPageCursor({
2088
+ pageClass: ArchiveCollectionPage,
2089
+ rawCursor: result.nextCursor,
2090
+ next,
2091
+ createToken,
2092
+ releaseToken
2093
+ })
2094
+ );
2095
+ }
2096
+ function createArchiveEvidencePage(result, next, createToken, releaseToken) {
2097
+ return new ArchiveEvidencePage(
2098
+ result,
2099
+ result.nextCursor === null ? null : createPageCursor({
2100
+ pageClass: ArchiveEvidencePage,
2101
+ rawCursor: result.nextCursor,
2102
+ next,
2103
+ createToken,
2104
+ releaseToken
2105
+ })
2106
+ );
2107
+ }
2108
+ function createArchiveRelatedPage(result, next, createToken, releaseToken) {
2109
+ return new ArchiveRelatedPage(
2110
+ result,
2111
+ result.nextCursor === null ? null : createPageCursor({
2112
+ pageClass: ArchiveRelatedPage,
2113
+ rawCursor: result.nextCursor,
2114
+ next,
2115
+ createToken,
2116
+ releaseToken
2117
+ })
2118
+ );
2119
+ }
2120
+ function createArchiveSourceLocatorPage(result, next, createToken, releaseToken) {
2121
+ return new ArchiveSourceLocatorPage(
2122
+ result,
2123
+ result.nextCursor === null ? null : createPageCursor({
2124
+ pageClass: ArchiveSourceLocatorPage,
2125
+ rawCursor: result.nextCursor,
2126
+ next,
2127
+ createToken,
2128
+ releaseToken
2129
+ })
2130
+ );
2131
+ }
2132
+
1903
2133
  // src/archive/archive.ts
1904
2134
  var WikiGraphArchiveExistsError = class extends Error {
1905
2135
  code = "WIKI_GRAPH_ARCHIVE_EXISTS";
@@ -1987,6 +2217,14 @@ var WikiGraphArchiveHandle = class {
1987
2217
  get target() {
1988
2218
  return this.#location.target;
1989
2219
  }
2220
+ async #persistCursor(cursor) {
2221
+ return await this.#runtime.run(
2222
+ async () => await (0, import_wiki_graph_core7.createContinuationCursor)(cursor)
2223
+ );
2224
+ }
2225
+ async #releaseCursor(cursor) {
2226
+ await this.#runtime.run(async () => await (0, import_wiki_graph_core7.deleteContinuationCursor)(cursor));
2227
+ }
1990
2228
  async inspect(options = {}) {
1991
2229
  return await this.#readDocument(
1992
2230
  async (document) => await inspectWikiGraphArchive(document, {
@@ -2001,7 +2239,7 @@ var WikiGraphArchiveHandle = class {
2001
2239
  options.queryMode,
2002
2240
  options.signal
2003
2241
  );
2004
- return await this.#writeDocument(
2242
+ const result = await this.#writeDocument(
2005
2243
  async (document) => {
2006
2244
  const chapters = await this.#resolveQueryChapters(document, options, {
2007
2245
  embeddingProvider
@@ -2022,9 +2260,38 @@ var WikiGraphArchiveHandle = class {
2022
2260
  ...options.signal === void 0 ? {} : { signal: options.signal }
2023
2261
  }
2024
2262
  );
2263
+ return createArchiveFindPage(
2264
+ result,
2265
+ async (cursor, nextOptions) => await this.search(query, {
2266
+ ...options,
2267
+ cursor,
2268
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
2269
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
2270
+ }),
2271
+ (cursor) => this.#persistCursor({
2272
+ archiveKey: this.archiveKey,
2273
+ archivePath: this.path,
2274
+ chapters: options.chapters ?? null,
2275
+ cursor,
2276
+ format: "json",
2277
+ indexScope: this.indexScope,
2278
+ kind: "search",
2279
+ ...options.backlinks === void 0 ? {} : { backlinks: options.backlinks },
2280
+ ...options.evidenceLimit === void 0 ? {} : { evidenceLimit: options.evidenceLimit },
2281
+ ...options.match === void 0 ? {} : { match: options.match },
2282
+ ...options.order === void 0 ? {} : { order: options.order },
2283
+ query,
2284
+ ...options.queryMode === void 0 ? {} : { queryMode: options.queryMode },
2285
+ ...options.skipUnindexed === void 0 ? {} : { skipUnindexed: options.skipUnindexed },
2286
+ ...options.sourceContext === void 0 ? {} : { sourceContext: options.sourceContext },
2287
+ ...options.triplePattern === void 0 ? {} : { triplePattern: options.triplePattern },
2288
+ types: options.types ?? null
2289
+ }),
2290
+ (token) => this.#releaseCursor(token)
2291
+ );
2025
2292
  }
2026
2293
  async list(options = {}) {
2027
- return await this.#readDocument(async (document) => {
2294
+ const result = await this.#readDocument(async (document) => {
2028
2295
  if ((0, import_wiki_graph_core7.isSourceLocatorScopeUri)(this.objectUri)) {
2029
2296
  return await (0, import_wiki_graph_core7.listArchiveSourceLocators)(document, this.objectUri, {
2030
2297
  ...options.cursor === void 0 ? {} : { cursor: options.cursor },
@@ -2037,6 +2304,53 @@ var WikiGraphArchiveHandle = class {
2037
2304
  ...chapters === void 0 ? {} : { chapters }
2038
2305
  });
2039
2306
  }, options);
2307
+ if ((0, import_wiki_graph_core7.isSourceLocatorScopeUri)(this.objectUri)) {
2308
+ return createArchiveSourceLocatorPage(
2309
+ result,
2310
+ async (cursor, nextOptions) => await this.list({
2311
+ ...options,
2312
+ cursor,
2313
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
2314
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
2315
+ }),
2316
+ (cursor) => this.#persistCursor({
2317
+ archiveKey: this.archiveKey,
2318
+ archivePath: this.path,
2319
+ cursor,
2320
+ format: "json",
2321
+ indexScope: this.indexScope,
2322
+ kind: "source-locators",
2323
+ targetUri: this.objectUri
2324
+ }),
2325
+ (token) => this.#releaseCursor(token)
2326
+ );
2327
+ }
2328
+ return createArchiveCollectionPage(
2329
+ result,
2330
+ async (cursor, nextOptions) => await this.list({
2331
+ ...options,
2332
+ cursor,
2333
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
2334
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
2335
+ }),
2336
+ (cursor) => this.#persistCursor({
2337
+ archiveKey: this.archiveKey,
2338
+ archivePath: this.path,
2339
+ ...options.backlinks === void 0 ? {} : { backlinks: options.backlinks },
2340
+ chapters: options.chapters ?? null,
2341
+ cursor,
2342
+ ...options.evidenceLimit === void 0 ? {} : { evidenceLimit: options.evidenceLimit },
2343
+ format: "json",
2344
+ ids: options.ids ?? null,
2345
+ indexScope: this.indexScope,
2346
+ kind: "collection",
2347
+ order: options.order ?? "doc-asc",
2348
+ ...options.sourceContext === void 0 ? {} : { sourceContext: options.sourceContext },
2349
+ ...options.triplePattern === void 0 ? {} : { triplePattern: options.triplePattern },
2350
+ types: options.types ?? null
2351
+ }),
2352
+ (token) => this.#releaseCursor(token)
2353
+ );
2040
2354
  }
2041
2355
  async ensureSearchIndex(options = {}) {
2042
2356
  const embeddingProvider = await this.#runtime.run(
@@ -2313,19 +2627,30 @@ var WikiGraphArchiveHandle = class {
2313
2627
  if (options.queryMode !== void 0) {
2314
2628
  throw new Error("`queryMode` requires `query`.");
2315
2629
  }
2316
- return await this.#readDocument(async (document) => {
2630
+ const result2 = await this.#readDocument(async (document) => {
2317
2631
  const chapters = await this.#resolveScope(document, {});
2318
2632
  return await (0, import_wiki_graph_core7.listRelatedArchiveObjects)(document, objectUri, {
2319
2633
  ...withoutOperation(options),
2320
2634
  ...chapters === void 0 ? {} : { chapters }
2321
2635
  });
2322
2636
  }, options);
2637
+ return createArchiveRelatedPage(
2638
+ result2,
2639
+ async (cursor, nextOptions) => await this.related(objectUri, {
2640
+ ...options,
2641
+ cursor,
2642
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
2643
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
2644
+ }),
2645
+ (cursor) => Promise.resolve(cursor),
2646
+ () => Promise.resolve()
2647
+ );
2323
2648
  }
2324
2649
  const embeddingProvider = await this.#resolveQueryEmbeddingProvider(
2325
2650
  options.queryMode,
2326
2651
  options.signal
2327
2652
  );
2328
- return await this.#writeDocument(
2653
+ const result = await this.#writeDocument(
2329
2654
  async (document) => {
2330
2655
  const chapters = await this.#resolveQueryChapters(document, options, {
2331
2656
  embeddingProvider
@@ -2345,25 +2670,47 @@ var WikiGraphArchiveHandle = class {
2345
2670
  ...options.signal === void 0 ? {} : { signal: options.signal }
2346
2671
  }
2347
2672
  );
2673
+ return createArchiveRelatedPage(
2674
+ result,
2675
+ async (cursor, nextOptions) => await this.related(objectUri, {
2676
+ ...options,
2677
+ cursor,
2678
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
2679
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
2680
+ }),
2681
+ (cursor) => Promise.resolve(cursor),
2682
+ () => Promise.resolve()
2683
+ );
2348
2684
  }
2349
2685
  async evidence(objectUri = this.objectUri, options = {}) {
2350
2686
  if (options.query === void 0) {
2351
2687
  if (options.queryMode !== void 0) {
2352
2688
  throw new Error("`queryMode` requires `query`.");
2353
2689
  }
2354
- return await this.#readDocument(async (document) => {
2690
+ const result2 = await this.#readDocument(async (document) => {
2355
2691
  const chapters = await this.#resolveScope(document, {});
2356
2692
  return await (0, import_wiki_graph_core7.listArchiveEvidence)(document, objectUri, {
2357
2693
  ...withoutOperation(options),
2358
2694
  ...chapters === void 0 ? {} : { chapters }
2359
2695
  });
2360
2696
  }, options);
2697
+ return createArchiveEvidencePage(
2698
+ result2,
2699
+ async (cursor, nextOptions) => await this.evidence(objectUri, {
2700
+ ...options,
2701
+ cursor,
2702
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
2703
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
2704
+ }),
2705
+ (cursor) => Promise.resolve(cursor),
2706
+ () => Promise.resolve()
2707
+ );
2361
2708
  }
2362
2709
  const embeddingProvider = await this.#resolveQueryEmbeddingProvider(
2363
2710
  options.queryMode,
2364
2711
  options.signal
2365
2712
  );
2366
- return await this.#writeDocument(
2713
+ const result = await this.#writeDocument(
2367
2714
  async (document) => {
2368
2715
  const chapters = await this.#resolveQueryChapters(document, options, {
2369
2716
  embeddingProvider
@@ -2383,6 +2730,17 @@ var WikiGraphArchiveHandle = class {
2383
2730
  ...options.signal === void 0 ? {} : { signal: options.signal }
2384
2731
  }
2385
2732
  );
2733
+ return createArchiveEvidencePage(
2734
+ result,
2735
+ async (cursor, nextOptions) => await this.evidence(objectUri, {
2736
+ ...options,
2737
+ cursor,
2738
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
2739
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
2740
+ }),
2741
+ (cursor) => Promise.resolve(cursor),
2742
+ () => Promise.resolve()
2743
+ );
2386
2744
  }
2387
2745
  async pack(objectUri = this.objectUri, budget = 5e3, options = {}) {
2388
2746
  return await this.#readDocument(