@delali/narsil 0.3.1-next.185 → 0.3.1-next.193

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 (170) hide show
  1. package/README.md +1 -0
  2. package/dist/adapters/filesystem.mjs +2 -2
  3. package/dist/adapters/gcs.mjs +2 -2
  4. package/dist/adapters/indexeddb.mjs +1 -1
  5. package/dist/adapters/s3.mjs +2 -2
  6. package/dist/browser/chunk-4E5APHTM.mjs +1459 -0
  7. package/dist/browser/{chunk-4ZICWS4V.mjs → chunk-QAOVAYAG.mjs} +1 -1
  8. package/dist/browser/{chunk-CPSHS46N.mjs → chunk-UQG4HUGQ.mjs} +82 -50
  9. package/dist/browser/{chunk-2Q45HI5H.mjs → chunk-YINZFPLT.mjs} +7 -0
  10. package/dist/browser/{module-XVLHJ7T7.mjs → module-ZZTNG5JZ.mjs} +26 -3
  11. package/dist/browser/{optional-writes-ZTBHYQMN.mjs → optional-writes-J5BHKEQL.mjs} +21 -8
  12. package/dist/browser/{storage-leaf-4XMCITJ6.mjs → storage-leaf-N3JMQ6CF.mjs} +14569 -13747
  13. package/dist/{capabilities-DAHXphRn.d.ts → capabilities-CLnQHIqV.d.ts} +51 -9
  14. package/dist/{chunk-KLVMK3R5.mjs → chunk-2CKDCC65.mjs} +1 -1
  15. package/dist/{chunk-CODGHJVW.mjs → chunk-2HVQYOOD.mjs} +40 -12
  16. package/dist/{chunk-M5I64AQW.mjs → chunk-3N5GUXBI.mjs} +33 -33
  17. package/dist/{chunk-DU23J5JG.mjs → chunk-5CIHQIA4.mjs} +6 -6
  18. package/dist/{react-native/chunks/chunk-ZUFOYZ5P.mjs → chunk-62X472AC.mjs} +1 -1
  19. package/dist/{chunk-QJGDB3WR.mjs → chunk-6GHX35ZM.mjs} +2 -2
  20. package/dist/{chunk-G3XRHAJA.mjs → chunk-6MC6BCXK.mjs} +3 -3
  21. package/dist/{chunk-X5NHWOXT.mjs → chunk-7P5YWDRQ.mjs} +2 -2
  22. package/dist/{chunk-MHBG33R5.mjs → chunk-7X4IIREW.mjs} +76 -46
  23. package/dist/{chunk-F4OOBPKA.mjs → chunk-AOYQTX6W.mjs} +1 -1
  24. package/dist/{chunk-D6FYUTFN.mjs → chunk-ASZLNVWW.mjs} +1 -1
  25. package/dist/{chunk-LR6JJVML.mjs → chunk-D2EJUM4A.mjs} +764 -699
  26. package/dist/{chunk-FETZYCH7.mjs → chunk-F6F4G322.mjs} +26 -1
  27. package/dist/{chunk-2YWWHMVC.mjs → chunk-FGOGT273.mjs} +2 -2
  28. package/dist/{chunk-5BUEBIXR.mjs → chunk-GLXLSPLO.mjs} +18 -5
  29. package/dist/{chunk-IE3Q62QD.mjs → chunk-GR5GMFJJ.mjs} +1 -1
  30. package/dist/{chunk-Y7QUFIGV.mjs → chunk-GXED6R3Q.mjs} +2 -2
  31. package/dist/{chunk-BVZWWMOU.mjs → chunk-HHYQMGPW.mjs} +2 -2
  32. package/dist/{chunk-SL53DHVE.mjs → chunk-HSA3H3VW.mjs} +121 -68
  33. package/dist/{chunk-YM2HI5N5.mjs → chunk-IL5DRCNU.mjs} +2 -2
  34. package/dist/{chunk-JDG6CCXM.mjs → chunk-JENWA4WX.mjs} +2 -2
  35. package/dist/{chunk-2GONI5HL.mjs → chunk-JXINPXRS.mjs} +5 -4
  36. package/dist/chunk-K5GNK5GE.mjs +602 -0
  37. package/dist/{chunk-WLFOLAQI.mjs → chunk-KBU3ZFJN.mjs} +2 -2
  38. package/dist/{chunk-EDEE7ETQ.mjs → chunk-KOA6T2IC.mjs} +3 -3
  39. package/dist/{chunk-N3M4NPML.mjs → chunk-M2Z5WVWW.mjs} +1 -1
  40. package/dist/{chunk-EWGIF6FQ.mjs → chunk-NJJN4FMM.mjs} +1 -1
  41. package/dist/{chunk-C7YQHCSO.mjs → chunk-P4F4UWLC.mjs} +1 -1
  42. package/dist/{chunk-VYSWVQCE.mjs → chunk-PAPQGC6I.mjs} +2 -2
  43. package/dist/{chunk-I2WJCRIH.mjs → chunk-R2PJKSNL.mjs} +1 -1
  44. package/dist/{chunk-6SZQETSC.mjs → chunk-RORNUNXW.mjs} +5 -2
  45. package/dist/{chunk-FBQYC5OX.mjs → chunk-SB5HCIIO.mjs} +16 -13
  46. package/dist/{chunk-CYCVPTTR.mjs → chunk-SCZI7COG.mjs} +2 -2
  47. package/dist/{chunk-O337MDRJ.mjs → chunk-SHES4VP5.mjs} +38 -13
  48. package/dist/{chunk-H4QYQ5DE.mjs → chunk-SIIDIGKI.mjs} +2 -2
  49. package/dist/{chunk-A3OAFUZI.mjs → chunk-SM2SYVIX.mjs} +2 -2
  50. package/dist/{chunk-II6XF6M4.mjs → chunk-SMLUZGSI.mjs} +9 -8
  51. package/dist/{chunk-2KCCQK4R.mjs → chunk-TSE2VWPX.mjs} +2 -2
  52. package/dist/{chunk-WSIU6YXQ.mjs → chunk-YPEJ6ODL.mjs} +1732 -743
  53. package/dist/{chunk-7WXGUTWK.mjs → chunk-Z6SIJH5O.mjs} +17 -6
  54. package/dist/{chunk-Q3ZZH5Z7.mjs → chunk-ZKOQR7EA.mjs} +7 -0
  55. package/dist/{chunk-CKEOTSF5.mjs → chunk-ZS2YUB2L.mjs} +6 -3
  56. package/dist/{chunk-FCQMZDRI.mjs → chunk-ZVZYJIIP.mjs} +3 -3
  57. package/dist/{client-DpqtT2XG.d.ts → client-uB0kp2yT.d.ts} +88 -5
  58. package/dist/client.d.ts +7 -7
  59. package/dist/client.mjs +3 -1265
  60. package/dist/{config-D9WR3MhO.d.ts → config-BvHQ-C7U.d.ts} +3 -3
  61. package/dist/{config-C687-reW.d.ts → config-PqgNY1H7.d.ts} +1 -1
  62. package/dist/{core-leaf-NEUM7PU3.mjs → core-leaf-TAR3GJVE.mjs} +3 -3
  63. package/dist/{direct-executor-37IH3ISS.mjs → direct-executor-WSZALYCV.mjs} +8 -8
  64. package/dist/distribution/coordinator/etcd.d.ts +1 -1
  65. package/dist/distribution/coordinator/etcd.mjs +35 -15
  66. package/dist/distribution/coordinator/in-memory.d.ts +1 -1
  67. package/dist/distribution/coordinator/in-memory.mjs +16 -6
  68. package/dist/distribution/transport/grpc.mjs +2 -2
  69. package/dist/distribution/transport/tcp.mjs +2 -2
  70. package/dist/distribution.d.ts +70 -9
  71. package/dist/distribution.mjs +1695 -680
  72. package/dist/{durability-config-NWU2G2SJ.mjs → durability-config-VWS2K24E.mjs} +1 -1
  73. package/dist/{react-native/chunks/embed-4LBSQD7U.mjs → embed-4PHHKGBK.mjs} +1 -1
  74. package/dist/embeddings/openai.mjs +2 -2
  75. package/dist/{engine-De6JzTW8.d.ts → engine-qjAxJSKk.d.ts} +206 -7
  76. package/dist/{index-CBUl4z3E.d.ts → index-BaQIAnk0.d.ts} +137 -111
  77. package/dist/index.browser.mjs +3 -3
  78. package/dist/index.d.ts +4 -4
  79. package/dist/index.mjs +8 -8
  80. package/dist/index.react-native.mjs +9 -9
  81. package/dist/{long-query-thread-DIPJBMV7.mjs → long-query-thread-N2DNPEA3.mjs} +21 -21
  82. package/dist/{module-Z3CL4GJ4.mjs → module-UQFIJQMG.mjs} +33 -13
  83. package/dist/{msgpack-leaf-7KBYOVTF.mjs → msgpack-leaf-H5ZYW7S7.mjs} +4 -4
  84. package/dist/{optional-reads-ENKMVQ4Q.mjs → optional-reads-5HFMF2QZ.mjs} +2 -2
  85. package/dist/{optional-writes-YIVJMQ4D.mjs → optional-writes-CGDBJBHQ.mjs} +31 -18
  86. package/dist/{paged-partition-archive-IZ6U7DVN.mjs → paged-partition-archive-UK44CVXG.mjs} +20 -20
  87. package/dist/partial-words.browser.mjs +3 -3
  88. package/dist/partial-words.mjs +8 -8
  89. package/dist/pattern.browser.mjs +2 -2
  90. package/dist/pattern.mjs +3 -3
  91. package/dist/persistence/durability/checkpoint-worker.d.ts +7 -0
  92. package/dist/persistence/durability/checkpoint-worker.mjs +18 -18
  93. package/dist/{phrase-module-ZY3TLTQA.mjs → phrase-module-EFESWOCR.mjs} +2 -2
  94. package/dist/{query-actions-7EOKT3WD.mjs → query-actions-7BL3YZDW.mjs} +8 -8
  95. package/dist/query-suggestions/merge-worker.mjs +11 -11
  96. package/dist/query-suggestions.browser.mjs +3 -3
  97. package/dist/query-suggestions.d.ts +1 -1
  98. package/dist/query-suggestions.mjs +9 -9
  99. package/dist/react-native/chunks/{chunk-TQ26BKBH.mjs → chunk-43R4GCM7.mjs} +7 -0
  100. package/dist/react-native/chunks/{chunk-CBU4M3EU.mjs → chunk-63DZ26X5.mjs} +277 -75
  101. package/dist/react-native/chunks/{chunk-BN6FUB7N.mjs → chunk-AN4HKLB4.mjs} +1 -1
  102. package/dist/react-native/chunks/{chunk-T5HF3FW3.mjs → chunk-BNFGA7TY.mjs} +3 -3
  103. package/dist/react-native/chunks/{chunk-PVMEHBQO.mjs → chunk-CW2ZFXSE.mjs} +1 -1
  104. package/dist/react-native/chunks/{chunk-NLEFMPY3.mjs → chunk-G434H5WG.mjs} +15 -4
  105. package/dist/react-native/chunks/{chunk-SK3DPAI4.mjs → chunk-HTBY4GON.mjs} +2 -2
  106. package/dist/react-native/chunks/{chunk-ZQPSXN6C.mjs → chunk-IP3QLETQ.mjs} +5 -5
  107. package/dist/react-native/chunks/{chunk-7TPO4FLE.mjs → chunk-LOKGE4OQ.mjs} +3 -3
  108. package/dist/react-native/chunks/{chunk-ZDDJVR7X.mjs → chunk-MRH36RN3.mjs} +2 -2
  109. package/dist/react-native/chunks/{chunk-YOTP2FPE.mjs → chunk-UO44MA5M.mjs} +1 -1
  110. package/dist/{chunk-4JBTALUC.mjs → react-native/chunks/chunk-UYAZLGEM.mjs} +1 -1
  111. package/dist/react-native/chunks/{chunk-WFQ6YQZA.mjs → chunk-UYKIV2KT.mjs} +1 -1
  112. package/dist/react-native/chunks/{chunk-IEY4DARA.mjs → chunk-XHYOQ4K4.mjs} +2 -2
  113. package/dist/react-native/chunks/{chunk-OZ3XEM6D.mjs → chunk-ZUJCUPVS.mjs} +1 -1
  114. package/dist/react-native/chunks/{core-leaf-TPBRRWVN.mjs → core-leaf-5PVST5PR.mjs} +4 -4
  115. package/dist/react-native/chunks/{durability-config-RVTWSXPH.mjs → durability-config-FCSD4MXY.mjs} +1 -1
  116. package/dist/{embed-2QMYCD2Q.mjs → react-native/chunks/embed-HA2I7RCF.mjs} +1 -1
  117. package/dist/react-native/chunks/{gzip.react-native-DLO4WW27.mjs → gzip.react-native-CVM4NQG2.mjs} +2 -2
  118. package/dist/react-native/chunks/{module-COLNJNML.mjs → module-QRCYB7QV.mjs} +32 -9
  119. package/dist/react-native/chunks/msgpack-leaf-JMNGSTRW.mjs +7 -0
  120. package/dist/react-native/chunks/{optional-reads-74HYI4DO.mjs → optional-reads-AFPO2FEB.mjs} +3 -3
  121. package/dist/react-native/chunks/{optional-writes-QETIM6BI.mjs → optional-writes-GC6JWMAF.mjs} +31 -18
  122. package/dist/react-native/chunks/{phrase-module-UC4YGEBB.mjs → phrase-module-IGYBK7XH.mjs} +3 -3
  123. package/dist/react-native/chunks/{resolve-vector-text-FU7D4QP5.mjs → resolve-vector-text-GE2CRJKI.mjs} +1 -1
  124. package/dist/react-native/chunks/{restore-queue-3E2MJIJS.mjs → restore-queue-2ACONS4W.mjs} +12 -12
  125. package/dist/react-native/chunks/{segment-codec-leaf-IE4DXUZV.mjs → segment-codec-leaf-SSIWXVUG.mjs} +10 -10
  126. package/dist/react-native/chunks/{segment-merge-leaf-62LQ5WZB.mjs → segment-merge-leaf-I2WDFE6O.mjs} +11 -11
  127. package/dist/react-native/chunks/{storage-leaf-LNOLKWZB.mjs → storage-leaf-YXXMG4VR.mjs} +14727 -13915
  128. package/dist/react-native/chunks/{store-leaf-Y7CBOPFZ.mjs → store-leaf-FS7A4PZA.mjs} +11 -11
  129. package/dist/react-native/chunks/{suggestions-leaf-PSUGL6MI.mjs → suggestions-leaf-PSFCT5EX.mjs} +11 -11
  130. package/dist/react-native/chunks/{worker-copies-MW5O5U3D.mjs → worker-copies-QRMISMEL.mjs} +10 -10
  131. package/dist/react-native/partial-words.mjs +9 -9
  132. package/dist/react-native/pattern.mjs +5 -5
  133. package/dist/react-native/query-suggestions.mjs +9 -9
  134. package/dist/react-native/sync.mjs +433 -51
  135. package/dist/react-native/synonyms.mjs +9 -9
  136. package/dist/react.d.ts +8 -8
  137. package/dist/react.mjs +7 -0
  138. package/dist/{rerank-KTV5L7MZ.mjs → rerank-4GFC26FD.mjs} +8 -8
  139. package/dist/rerankers/http.mjs +2 -2
  140. package/dist/{resolve-vector-text-SD6BEMKZ.mjs → resolve-vector-text-OD4J3WHF.mjs} +2 -2
  141. package/dist/{restore-queue-ES7TDJ5V.mjs → restore-queue-E4EIUYVV.mjs} +11 -11
  142. package/dist/{segment-codec-leaf-DO75VKEV.mjs → segment-codec-leaf-MP6DILVE.mjs} +9 -9
  143. package/dist/{segment-merge-leaf-JGND6LG5.mjs → segment-merge-leaf-ED2NMUC5.mjs} +9 -9
  144. package/dist/server.d.ts +13 -9
  145. package/dist/server.mjs +875 -348
  146. package/dist/{storage-leaf-ZI3H2WJY.mjs → storage-leaf-HQFO37W7.mjs} +5234 -5835
  147. package/dist/{store-leaf-YIH36Y5J.mjs → store-leaf-PL2G7RM5.mjs} +10 -10
  148. package/dist/{suggestions-leaf-FP5HSTFP.mjs → suggestions-leaf-I3MEHACP.mjs} +12 -12
  149. package/dist/sync/filesystem.d.ts +2 -2
  150. package/dist/sync/filesystem.mjs +16 -16
  151. package/dist/sync/indexeddb.browser.mjs +1 -1
  152. package/dist/sync/indexeddb.d.ts +2 -2
  153. package/dist/sync/indexeddb.mjs +3 -3
  154. package/dist/sync.browser.mjs +35 -1108
  155. package/dist/sync.d.ts +3 -3
  156. package/dist/sync.mjs +430 -51
  157. package/dist/synonyms.browser.mjs +3 -3
  158. package/dist/synonyms.mjs +8 -8
  159. package/dist/{tasks-X2IJQc8J.d.ts → tasks-C65V7lIr.d.ts} +3 -3
  160. package/dist/thread-LTFI3RK5.mjs +31 -0
  161. package/dist/{types-D0YasjoX.d.ts → types-CpCg-Gq-.d.ts} +1 -1
  162. package/dist/vector/search-worker.mjs +5 -5
  163. package/dist/{worker-copies-WYPRCNB7.mjs → worker-copies-P7YWXEP5.mjs} +11 -11
  164. package/dist/workers/entry.mjs +14 -14
  165. package/openapi.json +144 -0
  166. package/package.json +5 -7
  167. package/dist/chunk-URVH6BLO.mjs +0 -217
  168. package/dist/react-native/chunks/msgpack-leaf-GTKLF6GJ.mjs +0 -7
  169. package/dist/thread-NQRNW3IH.mjs +0 -31
  170. /package/dist/{chunk-CV3Q2EKO.mjs → chunk-S5QMWECL.mjs} +0 -0
@@ -1,1082 +1,9 @@
1
1
  import { createSerial, KEPT_ENTRY_FLUSH_IDLE_MS, KEPT_ENTRY_OVERHEAD_BYTES, DEFAULT_REPLAY_LIMIT_OF_SNAPSHOT, BACKOFF_DOUBLINGS_LIMIT, KEPT_ENTRY_FLUSH_BYTES, UPLOAD_BATCH_WRITES, RETRY_MAX_DELAY_MS, UPLOAD_RETRY_DELAY_MS, DOWNLOAD_SAVE_BYTES, SNAPSHOT_MEMORY_PER_ARCHIVE_BYTE, SNAPSHOT_RETRY_DELAY_MS, RECONNECT_MIN_DELAY_MS } from './browser/chunk-WC2DEXWU.mjs';
2
- import { hasLanguage, hasTokenizer, hasStopWords, readHeapStatistics, loadStorageCode, getLanguage } from './browser/chunk-CPSHS46N.mjs';
3
- import './browser/chunk-4ZICWS4V.mjs';
2
+ import { hasLanguage, hasTokenizer, hasStopWords, readHeapStatistics, loadStorageCode, getLanguage } from './browser/chunk-UQG4HUGQ.mjs';
3
+ import './browser/chunk-QAOVAYAG.mjs';
4
4
  import { isSyncEpoch } from './browser/chunk-YJHGOJAC.mjs';
5
- import { loadMessagePack, loadedMessagePack, NarsilError, ErrorCodes, requireLoadedMessagePack, getNestedValue, ClientErrorCodes, extractVectorFieldsFromSchema, ServerErrorCodes, describeError } from './browser/chunk-2Q45HI5H.mjs';
6
-
7
- // src/json-encoding.ts
8
- function toPlainNumbers(key, value) {
9
- if (ArrayBuffer.isView(value) && !(value instanceof DataView)) {
10
- return Array.from(value);
11
- }
12
- return value;
13
- }
14
- function encodeJson(value) {
15
- return JSON.stringify(value, toPlainNumbers);
16
- }
17
-
18
- // src/client/constants.ts
19
- var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
20
- var NO_TIMEOUT = 0;
21
- var DEFAULT_TASK_POLL_INTERVAL_MS = 250;
22
- var DEFAULT_URL_SKIP_MS = 1e3;
23
- var DEFAULT_MAX_URL_SKIP_MS = 3e4;
24
-
25
- // src/client/paths.ts
26
- function indexPath(indexName) {
27
- return `/indexes/${encodeURIComponent(indexName)}`;
28
- }
29
- function documentPath(indexName, docId) {
30
- return `${indexPath(indexName)}/documents/${encodeURIComponent(docId)}`;
31
- }
32
- function backupPath(backupName) {
33
- return `/backups/${encodeURIComponent(backupName)}`;
34
- }
35
- function taskPath(taskId) {
36
- return `/tasks/${encodeURIComponent(taskId)}`;
37
- }
38
-
39
- // src/client/response-shape.ts
40
- function isRecord(value) {
41
- return typeof value === "object" && value !== null && !Array.isArray(value);
42
- }
43
- function malformed(path, expected) {
44
- return new NarsilError(ClientErrorCodes.CLIENT_INVALID_RESPONSE, `The answer from ${path} holds no ${expected}`, {
45
- route: path
46
- });
47
- }
48
- function readArray(payload, key, path) {
49
- if (!isRecord(payload) || !Array.isArray(payload[key])) throw malformed(path, `"${key}" array`);
50
- return payload[key];
51
- }
52
- function readNumber(payload, key, path) {
53
- if (!isRecord(payload) || typeof payload[key] !== "number") throw malformed(path, `"${key}" number`);
54
- return payload[key];
55
- }
56
- function readBoolean(payload, key, path) {
57
- if (!isRecord(payload) || typeof payload[key] !== "boolean") throw malformed(path, `"${key}" flag`);
58
- return payload[key];
59
- }
60
- function readString(payload, key, path) {
61
- if (!isRecord(payload) || typeof payload[key] !== "string") throw malformed(path, `"${key}" string`);
62
- return payload[key];
63
- }
64
- function readObject(payload, key, path) {
65
- if (!isRecord(payload) || !isRecord(payload[key])) throw malformed(path, `"${key}" object`);
66
- return payload[key];
67
- }
68
- function readBody(payload, path) {
69
- if (!isRecord(payload)) throw malformed(path, "JSON object");
70
- return payload;
71
- }
72
-
73
- // src/client/admin.ts
74
- function createAdminOperations(transport) {
75
- async function postJson(path, body, options) {
76
- const payload = await transport.json({
77
- method: "POST",
78
- path,
79
- body: encodeJson(body),
80
- contentType: "application/json",
81
- options
82
- });
83
- return readBody(payload, path);
84
- }
85
- return {
86
- async checkpoint(indexName, options) {
87
- await transport.json({ method: "POST", path: `${indexPath(indexName)}/_checkpoint`, options });
88
- },
89
- snapshot(indexName, options) {
90
- const { queryHistory, ...request } = options ?? {};
91
- return transport.stream({
92
- method: "GET",
93
- path: `${indexPath(indexName)}/snapshot`,
94
- ...queryHistory === true ? { query: { queryHistory: "true" } } : {},
95
- defaultTimeoutMs: NO_TIMEOUT,
96
- options: request
97
- });
98
- },
99
- async restore(indexName, data, options) {
100
- const path = `${indexPath(indexName)}/restore`;
101
- const payload = await transport.json({
102
- method: "POST",
103
- path,
104
- body: data,
105
- contentType: "application/octet-stream",
106
- defaultTimeoutMs: NO_TIMEOUT,
107
- options
108
- });
109
- return readBody(payload, path);
110
- },
111
- exportDocuments(indexName, options) {
112
- return transport.stream({
113
- method: "GET",
114
- path: `${indexPath(indexName)}/export`,
115
- defaultTimeoutMs: NO_TIMEOUT,
116
- options
117
- });
118
- },
119
- async importDocumentExport(indexName, data, options) {
120
- const path = `${indexPath(indexName)}/import`;
121
- const payload = await transport.json({
122
- method: "POST",
123
- path,
124
- body: data,
125
- contentType: "application/x-ndjson",
126
- defaultTimeoutMs: NO_TIMEOUT,
127
- options
128
- });
129
- return readBody(payload, path);
130
- },
131
- async vectorMaintenanceStatus(indexName, options) {
132
- const path = `${indexPath(indexName)}/vector-maintenance`;
133
- const payload = await transport.json({ method: "GET", path, options });
134
- return readArray(payload, "fields", path);
135
- },
136
- async compactVectors(indexName, fieldName, options) {
137
- await postJson(
138
- `${indexPath(indexName)}/vectors/_compact`,
139
- fieldName === void 0 ? {} : { field: fieldName },
140
- options
141
- );
142
- },
143
- optimizeVectors(indexName, fieldName, options) {
144
- return postJson(
145
- `${indexPath(indexName)}/vectors/_optimize`,
146
- fieldName === void 0 ? {} : { field: fieldName },
147
- options
148
- );
149
- },
150
- rebalance(indexName, targetPartitionCount, options) {
151
- return postJson(`${indexPath(indexName)}/_rebalance`, { targetPartitionCount }, options);
152
- },
153
- async updatePartitionConfig(indexName, partitionConfig, options) {
154
- await postJson(`${indexPath(indexName)}/partition-config`, partitionConfig, options);
155
- },
156
- async updateSynonyms(indexName, synonyms, options) {
157
- await postJson(`${indexPath(indexName)}/synonyms`, { synonyms }, options);
158
- },
159
- async updateBM25(indexName, bm25, options) {
160
- await postJson(`${indexPath(indexName)}/bm25`, bm25, options);
161
- },
162
- async getSynonyms(indexName, options) {
163
- const path = `${indexPath(indexName)}/synonyms`;
164
- const body = await readBody(
165
- await transport.json({ method: "GET", path, options }),
166
- path
167
- );
168
- return body.synonyms;
169
- },
170
- async rebuildAnalysis(indexName, options) {
171
- const path = `${indexPath(indexName)}/_rebuild-analysis`;
172
- return readBody(await transport.json({ method: "POST", path, options }), path);
173
- },
174
- async changeAnalysis(indexName, change, options) {
175
- const path = `${indexPath(indexName)}/_change-analysis`;
176
- return postJson(path, change, options);
177
- },
178
- async getMemoryStats(options) {
179
- const path = "/stats/memory";
180
- return readBody(await transport.json({ method: "GET", path, options }), path);
181
- }
182
- };
183
- }
184
-
185
- // src/client/backups.ts
186
- function createBackupOperations(transport) {
187
- async function postTask(path, body, options) {
188
- const payload = await transport.json({
189
- method: "POST",
190
- path,
191
- body: encodeJson(body),
192
- contentType: "application/json",
193
- options
194
- });
195
- return readBody(payload, path);
196
- }
197
- return {
198
- createBackup(indexName, backupName, options) {
199
- const { queryHistory, ...request } = options ?? {};
200
- const body = { backup: backupName, ...queryHistory === true ? { queryHistory } : {} };
201
- return postTask(`${indexPath(indexName)}/backups`, body, request);
202
- },
203
- async listBackups(options) {
204
- const path = "/backups";
205
- const payload = await transport.json({ method: "GET", path, defaultTimeoutMs: NO_TIMEOUT, options });
206
- return readArray(payload, "backups", path);
207
- },
208
- restoreBackup(backupName, restore, options) {
209
- return postTask(`${backupPath(backupName)}/_restore`, restore, options);
210
- },
211
- async deleteBackup(backupName, options) {
212
- const path = backupPath(backupName);
213
- return readBody(await transport.json({ method: "DELETE", path, options }), path);
214
- }
215
- };
216
- }
217
-
218
- // src/client/bulk.ts
219
- function toNdjson(source) {
220
- if (typeof source === "string") return source;
221
- if (Array.isArray(source)) return source.map((document) => encodeJson(document)).join("\n");
222
- return source;
223
- }
224
- function toBatchResult(payload, path) {
225
- const failed = readArray(payload, "failed", path);
226
- return {
227
- succeeded: readArray(payload, "succeeded", path),
228
- failed: failed.map((entry) => {
229
- const record2 = readBody(entry, path);
230
- const docId = typeof record2.docId === "string" ? record2.docId : "";
231
- const error = readBody(record2.error, path);
232
- const code = typeof error.code === "string" ? error.code : ServerErrorCodes.INTERNAL_ERROR;
233
- const message = typeof error.message === "string" ? error.message : "The server refused the document";
234
- const details = typeof error.details === "object" && error.details !== null ? error.details : void 0;
235
- return { docId, error: new NarsilError(code, message, details) };
236
- })
237
- };
238
- }
239
- function createBulkOperations(transport) {
240
- function batch(indexName, body, options) {
241
- const path = `${indexPath(indexName)}/documents/_batch`;
242
- return transport.json({ method: "POST", path, body: encodeJson(body), contentType: "application/json", options }).then((payload) => toBatchResult(payload, path));
243
- }
244
- function importBody(indexName, source, asynchronous, options) {
245
- return {
246
- method: "POST",
247
- path: `${indexPath(indexName)}/documents/_import`,
248
- ...asynchronous ? { query: { async: "true" } } : {},
249
- body: toNdjson(source),
250
- contentType: "application/x-ndjson",
251
- defaultTimeoutMs: NO_TIMEOUT,
252
- options
253
- };
254
- }
255
- return {
256
- insertBatch(indexName, documents, insertOptions, options) {
257
- return batch(
258
- indexName,
259
- { action: "insert", documents, ...insertOptions === void 0 ? {} : { options: insertOptions } },
260
- options
261
- );
262
- },
263
- updateBatch(indexName, updates, writeOptions, options) {
264
- return batch(
265
- indexName,
266
- { action: "update", updates, ...writeOptions === void 0 ? {} : { options: writeOptions } },
267
- options
268
- );
269
- },
270
- removeBatch(indexName, docIds, writeOptions, options) {
271
- return batch(
272
- indexName,
273
- { action: "delete", docIds, ...writeOptions === void 0 ? {} : { options: writeOptions } },
274
- options
275
- );
276
- },
277
- async getMultiple(indexName, docIds, options) {
278
- const path = `${indexPath(indexName)}/documents/_multi-get`;
279
- const payload = await transport.json({
280
- method: "POST",
281
- path,
282
- body: encodeJson({ docIds }),
283
- contentType: "application/json",
284
- repeatable: true,
285
- options
286
- });
287
- const documents = readObject(payload, "documents", path);
288
- return new Map(Object.entries(documents));
289
- },
290
- async listDocuments(indexName, params, options) {
291
- const path = `${indexPath(indexName)}/documents/_list`;
292
- const payload = await transport.json({
293
- method: "POST",
294
- path,
295
- body: encodeJson(params ?? {}),
296
- contentType: "application/json",
297
- repeatable: true,
298
- options
299
- });
300
- return readBody(payload, path);
301
- },
302
- async importDocuments(indexName, source, options) {
303
- const spec = importBody(indexName, source, false, options);
304
- return readBody(await transport.json(spec), spec.path);
305
- },
306
- async startImport(indexName, source, options) {
307
- const spec = importBody(indexName, source, true, options);
308
- return readBody(await transport.json(spec), spec.path);
309
- }
310
- };
311
- }
312
-
313
- // src/client/documents.ts
314
- function createDocumentOperations(transport) {
315
- return {
316
- async insert(indexName, document, docId, insertOptions, options) {
317
- const path = `${indexPath(indexName)}/documents`;
318
- const payload = await transport.json({
319
- method: "POST",
320
- path,
321
- body: encodeJson({
322
- document,
323
- ...docId === void 0 ? {} : { id: docId },
324
- ...insertOptions === void 0 ? {} : { options: insertOptions }
325
- }),
326
- contentType: "application/json",
327
- options
328
- });
329
- return readString(payload, "id", path);
330
- },
331
- async get(indexName, docId, options) {
332
- const path = documentPath(indexName, docId);
333
- const payload = await transport.jsonOrNull({ method: "GET", path, options }, ErrorCodes.DOC_NOT_FOUND);
334
- if (payload === null) return void 0;
335
- return readObject(payload, "document", path);
336
- },
337
- async has(indexName, docId, options) {
338
- const path = `${documentPath(indexName, docId)}/_exists`;
339
- return readBoolean(await transport.json({ method: "GET", path, options }), "exists", path);
340
- },
341
- async put(indexName, docId, document, writeOptions, options) {
342
- const path = documentPath(indexName, docId);
343
- const payload = await transport.json({
344
- method: "PUT",
345
- path,
346
- body: encodeJson({ document, ...writeOptions === void 0 ? {} : { options: writeOptions } }),
347
- contentType: "application/json",
348
- options
349
- });
350
- return { id: readString(payload, "id", path), created: readBoolean(payload, "created", path) };
351
- },
352
- async update(indexName, docId, document, writeOptions, options) {
353
- await transport.json({
354
- method: "PATCH",
355
- path: documentPath(indexName, docId),
356
- body: encodeJson({ document, ...writeOptions === void 0 ? {} : { options: writeOptions } }),
357
- contentType: "application/json",
358
- options
359
- });
360
- },
361
- async remove(indexName, docId, writeOptions, options) {
362
- await transport.json({
363
- method: "DELETE",
364
- path: documentPath(indexName, docId),
365
- ...writeOptions?.wait === true ? { query: { wait: "true" } } : {},
366
- options
367
- });
368
- },
369
- async waitForWrites(indexName, options) {
370
- await transport.json({ method: "POST", path: `${indexPath(indexName)}/_wait-for-writes`, options });
371
- },
372
- async countDocuments(indexName, options) {
373
- const path = `${indexPath(indexName)}/count`;
374
- return readNumber(await transport.json({ method: "GET", path, options }), "count", path);
375
- }
376
- };
377
- }
378
-
379
- // src/client/failover.ts
380
- var UNSENT_CONNECTION_CODES = /* @__PURE__ */ new Set(["ECONNREFUSED", "ENOTFOUND", "EAI_AGAIN", "ConnectionRefused"]);
381
- var MAX_CAUSE_DEPTH = 4;
382
- var SKIP_DOUBLING_CEILING = 30;
383
- var RETRIED_STATUSES = /* @__PURE__ */ new Set([502, 503, 504]);
384
- function readSkip(value, fallback, field) {
385
- if (value === void 0) return fallback;
386
- if (!Number.isSafeInteger(value) || value < 0) {
387
- throw new NarsilError(ErrorCodes.CONFIG_INVALID, `"${field}" must be a whole number of milliseconds, 0 or more`, {
388
- [field]: value
389
- });
390
- }
391
- return value;
392
- }
393
- function createUrlPool(bases, options) {
394
- const skipMs = readSkip(options.urlSkipMs, DEFAULT_URL_SKIP_MS, "urlSkipMs");
395
- const maxSkipMs = readSkip(options.maxUrlSkipMs, Math.max(DEFAULT_MAX_URL_SKIP_MS, skipMs), "maxUrlSkipMs");
396
- if (maxSkipMs < skipMs) {
397
- throw new NarsilError(ErrorCodes.CONFIG_INVALID, '"maxUrlSkipMs" must be at least "urlSkipMs"', {
398
- urlSkipMs: skipMs,
399
- maxUrlSkipMs: maxSkipMs
400
- });
401
- }
402
- const entries = bases.map((base, position) => ({ base, position, refusals: 0, skipUntil: 0 }));
403
- let nextStart = 0;
404
- return {
405
- order(now) {
406
- const rotation = [...entries.slice(nextStart), ...entries.slice(0, nextStart)];
407
- const open = rotation.filter((entry) => entry.skipUntil <= now);
408
- const skipped = rotation.filter((entry) => entry.skipUntil > now).sort((a, b) => a.skipUntil - b.skipUntil);
409
- return [...open, ...skipped];
410
- },
411
- took(entry) {
412
- nextStart = (entry.position + 1) % entries.length;
413
- },
414
- answered(entry) {
415
- entry.refusals = 0;
416
- entry.skipUntil = 0;
417
- },
418
- refused(entry, now) {
419
- entry.refusals += 1;
420
- const doublings = Math.min(entry.refusals - 1, SKIP_DOUBLING_CEILING);
421
- entry.skipUntil = now + Math.min(skipMs * 2 ** doublings, maxSkipMs);
422
- }
423
- };
424
- }
425
- function failedBeforeSending(error, depth = 0) {
426
- if (depth > MAX_CAUSE_DEPTH || typeof error !== "object" || error === null) return false;
427
- const { code, cause, errors } = error;
428
- if (typeof code === "string" && UNSENT_CONNECTION_CODES.has(code)) return true;
429
- if (failedBeforeSending(cause, depth + 1)) return true;
430
- return Array.isArray(errors) && errors.length > 0 && errors.every((entry) => failedBeforeSending(entry, depth + 1));
431
- }
432
- function answersUnavailable(status) {
433
- return RETRIED_STATUSES.has(status);
434
- }
435
- function movesOnAfterAnswer(status, code, repeatable) {
436
- if (!answersUnavailable(status)) return false;
437
- return repeatable || code === ErrorCodes.NODE_NOT_READY;
438
- }
439
- function earnsExtraTry(failure) {
440
- return failure.code === ClientErrorCodes.CLIENT_CONNECTION_FAILED;
441
- }
442
- function movesOnAfterFailure(failure, sentNothing, repeatable) {
443
- if (failure.code === ClientErrorCodes.CLIENT_REQUEST_TIMEOUT) return repeatable;
444
- if (failure.code === ClientErrorCodes.CLIENT_CONNECTION_FAILED) return repeatable || sentNothing;
445
- return false;
446
- }
447
-
448
- // src/client/http.ts
449
- function isRecord2(value) {
450
- return typeof value === "object" && value !== null && !Array.isArray(value);
451
- }
452
- function unrefTimer(timer) {
453
- const unrefable = timer;
454
- unrefable.unref?.();
455
- }
456
- function startDeadline(timeoutMs, caller) {
457
- const controller = new AbortController();
458
- let expired = false;
459
- const abortWithCaller = () => controller.abort();
460
- if (caller?.aborted) controller.abort();
461
- else caller?.addEventListener("abort", abortWithCaller);
462
- let timer;
463
- if (timeoutMs > 0 && !controller.signal.aborted) {
464
- timer = setTimeout(() => {
465
- expired = true;
466
- controller.abort();
467
- }, timeoutMs);
468
- unrefTimer(timer);
469
- }
470
- return {
471
- signal: controller.signal,
472
- expired: () => expired,
473
- release: () => {
474
- if (timer !== void 0) clearTimeout(timer);
475
- caller?.removeEventListener("abort", abortWithCaller);
476
- }
477
- };
478
- }
479
- var ResponseTooLargeError = class extends Error {
480
- constructor(limitBytes) {
481
- super(`The answer passed the ${limitBytes} byte ceiling this client reads`);
482
- this.limitBytes = limitBytes;
483
- }
484
- };
485
- async function readStreamCapped(stream, limitBytes) {
486
- const reader = stream.getReader();
487
- const chunks = [];
488
- let total = 0;
489
- try {
490
- for (; ; ) {
491
- const { done, value } = await reader.read();
492
- if (done) break;
493
- total += value.byteLength;
494
- if (total > limitBytes) throw new ResponseTooLargeError(limitBytes);
495
- chunks.push(value);
496
- }
497
- } finally {
498
- reader.releaseLock();
499
- if (total > limitBytes) await stream.cancel().catch(() => void 0);
500
- }
501
- const body = new Uint8Array(total);
502
- let offset = 0;
503
- for (const chunk of chunks) {
504
- body.set(chunk, offset);
505
- offset += chunk.byteLength;
506
- }
507
- return body;
508
- }
509
- async function readAnswer(response, limitBytes) {
510
- const stream = response.body;
511
- if (limitBytes > 0 && stream !== null && stream !== void 0) {
512
- return new TextDecoder().decode(await readStreamCapped(stream, limitBytes));
513
- }
514
- const text = await response.text();
515
- if (limitBytes > 0 && text.length > limitBytes) throw new ResponseTooLargeError(limitBytes);
516
- return text;
517
- }
518
- function invalidResponse(message, details) {
519
- return new NarsilError(ClientErrorCodes.CLIENT_INVALID_RESPONSE, message, details);
520
- }
521
- function errorFromBody(status, payload, url) {
522
- const envelope = isRecord2(payload) && isRecord2(payload.error) ? payload.error : void 0;
523
- if (envelope === void 0 || typeof envelope.code !== "string" || typeof envelope.message !== "string") {
524
- return invalidResponse(`The server answered HTTP ${status} without a Narsil error envelope`, { url, status });
525
- }
526
- const details = isRecord2(envelope.details) ? envelope.details : {};
527
- return new NarsilError(envelope.code, envelope.message, { ...details, status });
528
- }
529
- function isHttpUrl(value) {
530
- try {
531
- const parsed = new URL(value);
532
- return parsed.protocol === "http:" || parsed.protocol === "https:";
533
- } catch {
534
- return false;
535
- }
536
- }
537
- function normaliseBase(url) {
538
- const trimmed = url.trim();
539
- if (trimmed.length === 0) {
540
- throw new NarsilError(ErrorCodes.CONFIG_INVALID, 'The client needs a server address, and "url" is empty');
541
- }
542
- if (!trimmed.startsWith("/") && !isHttpUrl(trimmed)) {
543
- throw new NarsilError(
544
- ErrorCodes.CONFIG_INVALID,
545
- `The client cannot read "${trimmed}" as a server address; pass an http or https URL, or a path starting with "/" that a browser resolves against the page`,
546
- { url: trimmed }
547
- );
548
- }
549
- return trimmed.replace(/\/+$/, "");
550
- }
551
- function normaliseBases(url) {
552
- if (typeof url === "string") return [normaliseBase(url)];
553
- if (!Array.isArray(url) || url.length === 0) {
554
- throw new NarsilError(ErrorCodes.CONFIG_INVALID, 'The client needs a server address, and "url" lists none');
555
- }
556
- return url.map((entry) => {
557
- if (typeof entry !== "string") {
558
- throw new NarsilError(ErrorCodes.CONFIG_INVALID, 'Every server address in "url" must be a string');
559
- }
560
- return normaliseBase(entry);
561
- });
562
- }
563
- function translateFailure(err, url, timeoutMs, expired, caller) {
564
- if (err instanceof ResponseTooLargeError) {
565
- return invalidResponse(`The server at ${url} answered more than this client reads: ${err.message}`, {
566
- url,
567
- maxResponseBytes: err.limitBytes
568
- });
569
- }
570
- if (expired) {
571
- return new NarsilError(
572
- ClientErrorCodes.CLIENT_REQUEST_TIMEOUT,
573
- `The server at ${url} did not answer within ${timeoutMs} ms`,
574
- { url, timeoutMs }
575
- );
576
- }
577
- if (caller?.aborted === true) {
578
- return new NarsilError(ClientErrorCodes.CLIENT_REQUEST_ABORTED, `The caller cancelled the request to ${url}`, {
579
- url
580
- });
581
- }
582
- return new NarsilError(
583
- ClientErrorCodes.CLIENT_CONNECTION_FAILED,
584
- `The client could not reach ${url}: ${describeError(err)}`,
585
- { url }
586
- );
587
- }
588
- function envelopeCodeOf(text) {
589
- try {
590
- const payload = JSON.parse(text);
591
- return isRecord2(payload) && isRecord2(payload.error) && typeof payload.error.code === "string" ? payload.error.code : void 0;
592
- } catch {
593
- return void 0;
594
- }
595
- }
596
- function withQuery(path, query) {
597
- if (query === void 0) return path;
598
- const params = new URLSearchParams();
599
- for (const [key, value] of Object.entries(query)) {
600
- if (value !== void 0) params.set(key, value);
601
- }
602
- const encoded = params.toString();
603
- return encoded.length === 0 ? path : `${path}?${encoded}`;
604
- }
605
- function createTransport(options) {
606
- const pool = createUrlPool(normaliseBases(options.url), options);
607
- const send = options.fetch ?? ((input, init) => fetch(input, init));
608
- const baseHeaders = { ...options.headers };
609
- if (options.apiKey !== void 0 && options.apiKey.length > 0) {
610
- baseHeaders.authorization = `Bearer ${options.apiKey}`;
611
- }
612
- function resolveTimeout(spec) {
613
- const perCall = spec.options?.timeoutMs;
614
- if (perCall !== void 0) return perCall;
615
- if (options.timeoutMs !== void 0) return options.timeoutMs;
616
- return spec.defaultTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
617
- }
618
- function resolveResponseCeiling(spec) {
619
- const perCall = spec.options?.maxResponseBytes;
620
- if (perCall !== void 0) return perCall;
621
- return options.maxResponseBytes ?? 0;
622
- }
623
- function recordAttempt(entry, attempt, repeatable) {
624
- if (attempt.kind === "answer") {
625
- if (!answersUnavailable(attempt.status)) {
626
- pool.answered(entry);
627
- return false;
628
- }
629
- return movesOnAfterAnswer(attempt.status, envelopeCodeOf(attempt.text), repeatable);
630
- }
631
- if (attempt.error.code === ClientErrorCodes.CLIENT_CONNECTION_FAILED) pool.refused(entry, Date.now());
632
- return movesOnAfterFailure(attempt.error, attempt.sentNothing, repeatable);
633
- }
634
- function outcomeOf(attempt) {
635
- if (attempt === null) throw new NarsilError(ErrorCodes.CONFIG_INVALID, "The client holds no server address");
636
- if (attempt.kind === "failure") throw attempt.error;
637
- return attempt;
638
- }
639
- async function exchange(spec, keepsStream = false) {
640
- const repeatable = spec.repeatable === true || spec.method === "GET";
641
- const replayable = !(spec.body instanceof ReadableStream);
642
- const tryOn = async (entry2) => {
643
- pool.took(entry2);
644
- return exchangeOnce(entry2.base, spec, keepsStream);
645
- };
646
- let triesOnceMore = repeatable && replayable;
647
- let last = null;
648
- for (const entry2 of pool.order(Date.now())) {
649
- last = await tryOn(entry2);
650
- const moves = recordAttempt(entry2, last, repeatable);
651
- if (!replayable || !moves) return outcomeOf(last);
652
- if (last.kind === "failure" && !earnsExtraTry(last.error)) triesOnceMore = false;
653
- }
654
- const [entry] = pool.order(Date.now());
655
- if (triesOnceMore && entry !== void 0) {
656
- last = await tryOn(entry);
657
- recordAttempt(entry, last, repeatable);
658
- }
659
- return outcomeOf(last);
660
- }
661
- async function exchangeOnce(base, spec, keepsStream) {
662
- const url = `${base}${withQuery(spec.path, spec.query)}`;
663
- const headers = { ...baseHeaders, ...spec.headers, ...spec.options?.headers };
664
- if (spec.contentType !== void 0) headers["content-type"] = spec.contentType;
665
- const timeoutMs = resolveTimeout(spec);
666
- const deadline = startDeadline(timeoutMs, spec.options?.signal);
667
- let handedOver = false;
668
- try {
669
- const init = { method: spec.method, headers, signal: deadline.signal };
670
- if (spec.body !== void 0) init.body = spec.body;
671
- if (spec.body instanceof ReadableStream) init.duplex = "half";
672
- const response = await send(url, init);
673
- if (keepsStream && response.ok && response.body !== null) {
674
- handedOver = true;
675
- const stream = response.body.pipeThrough(
676
- new TransformStream({ flush: () => deadline.release() })
677
- );
678
- return { kind: "answer", status: response.status, url, text: "", stream, headers: response.headers };
679
- }
680
- const text = await readAnswer(response, resolveResponseCeiling(spec));
681
- return { kind: "answer", status: response.status, url, stream: null, text, headers: response.headers };
682
- } catch (err) {
683
- const error = translateFailure(err, url, timeoutMs, deadline.expired(), spec.options?.signal);
684
- const sentNothing = error.code === ClientErrorCodes.CLIENT_CONNECTION_FAILED && failedBeforeSending(err);
685
- return { kind: "failure", error, sentNothing };
686
- } finally {
687
- if (!handedOver) deadline.release();
688
- }
689
- }
690
- function parse(status, text, path) {
691
- if (text.length === 0) return void 0;
692
- try {
693
- return JSON.parse(text);
694
- } catch {
695
- throw invalidResponse(`The server answered HTTP ${status} with a body that is not JSON`, { url: path, status });
696
- }
697
- }
698
- async function json(spec) {
699
- const { status, text, url } = await exchange(spec);
700
- const payload = parse(status, text, url);
701
- if (status >= 200 && status < 300) return payload;
702
- throw errorFromBody(status, payload, url);
703
- }
704
- return {
705
- json,
706
- async jsonOrNull(spec, absentCode) {
707
- try {
708
- return await json(spec);
709
- } catch (err) {
710
- if (err instanceof NarsilError && err.code === absentCode) return null;
711
- throw err;
712
- }
713
- },
714
- async stream(spec) {
715
- const { status, text, stream, url } = await exchange(spec, true);
716
- if (stream !== null) return stream;
717
- throw errorFromBody(status, parse(status, text, url), url);
718
- },
719
- async download(spec) {
720
- const { status, text, stream, headers, url } = await exchange(spec, true);
721
- if (stream !== null && headers !== null) return { status, headers, stream };
722
- throw errorFromBody(status, parse(status, text, url), url);
723
- },
724
- async probe(spec) {
725
- const { status } = await exchange(spec);
726
- return status;
727
- }
728
- };
729
- }
730
-
731
- // src/client/indexes.ts
732
- function createIndexOperations(transport) {
733
- return {
734
- async createIndex(name, config, options) {
735
- await transport.json({
736
- method: "POST",
737
- path: "/indexes",
738
- body: encodeJson({ name, config }),
739
- contentType: "application/json",
740
- options
741
- });
742
- },
743
- async listIndexes(options) {
744
- const path = "/indexes";
745
- return readArray(await transport.json({ method: "GET", path, options }), "indexes", path);
746
- },
747
- async dropIndex(name, options) {
748
- await transport.json({ method: "DELETE", path: indexPath(name), options });
749
- },
750
- async getStats(indexName, options) {
751
- const path = `${indexPath(indexName)}/stats`;
752
- return readBody(await transport.json({ method: "GET", path, options }), path);
753
- },
754
- async getPartitionStats(indexName, options) {
755
- const path = `${indexPath(indexName)}/partitions`;
756
- const payload = await transport.json({ method: "GET", path, options });
757
- return readArray(payload, "partitions", path);
758
- },
759
- async clear(indexName, options) {
760
- await transport.json({ method: "POST", path: `${indexPath(indexName)}/_clear`, options });
761
- },
762
- async open(indexName, options) {
763
- await transport.json({ method: "POST", path: `${indexPath(indexName)}/_open`, options });
764
- },
765
- async close(indexName, options) {
766
- await transport.json({ method: "POST", path: `${indexPath(indexName)}/_close`, options });
767
- }
768
- };
769
- }
770
-
771
- // src/client/query-suggestions.ts
772
- function createQuerySuggestionOperations(transport) {
773
- const pathOf = (indexName, route = "") => `${indexPath(indexName)}/query-suggestions${route}`;
774
- function send(method, path, body, options) {
775
- return transport.json({
776
- method,
777
- path,
778
- ...body === void 0 ? {} : { body: encodeJson(body), contentType: "application/json" },
779
- options
780
- });
781
- }
782
- return {
783
- async updateQuerySuggestions(indexName, setting, options) {
784
- await send("PUT", pathOf(indexName), setting, options);
785
- },
786
- async querySuggestionsStatus(indexName, options) {
787
- const path = pathOf(indexName);
788
- return readBody(await send("GET", path, void 0, options), path);
789
- },
790
- async recordQuery(indexName, query, options) {
791
- const path = pathOf(indexName, "/record");
792
- return readBody(await send("POST", path, { query }, options), path);
793
- },
794
- async buildQuerySuggestions(indexName, options) {
795
- const path = pathOf(indexName, "/build");
796
- return readBody(await send("POST", path, void 0, options), path);
797
- },
798
- async previewQuerySuggestions(indexName, limit, options) {
799
- const path = pathOf(indexName, "/preview");
800
- const payload = await transport.json({
801
- method: "GET",
802
- path,
803
- ...limit === void 0 ? {} : { query: { limit: String(limit) } },
804
- options
805
- });
806
- return readBody(payload, path);
807
- },
808
- async readQueryBans(indexName, options) {
809
- const path = pathOf(indexName, "/bans");
810
- return readArray(await send("GET", path, void 0, options), "bans", path);
811
- },
812
- async replaceQueryBans(indexName, bans, options) {
813
- const path = pathOf(indexName, "/bans");
814
- return readArray(await send("PUT", path, { bans }, options), "bans", path);
815
- },
816
- async removeQuery(indexName, query, options) {
817
- const path = pathOf(indexName, "/remove");
818
- return readNumber(await send("POST", path, { query }, options), "suggestionIndexes", path);
819
- },
820
- async addManualSuggestion(indexName, suggestion, options) {
821
- const path = pathOf(indexName, "/manual");
822
- return readString(await send("POST", path, suggestion, options), "indexName", path);
823
- }
824
- };
825
- }
826
-
827
- // src/score-encoding.ts
828
- function decodeScore(score) {
829
- if (typeof score === "number") return Number.isFinite(score) ? score : void 0;
830
- if (score === "NaN") return Number.NaN;
831
- if (score === "Infinity") return Number.POSITIVE_INFINITY;
832
- if (score === "-Infinity") return Number.NEGATIVE_INFINITY;
833
- return void 0;
834
- }
835
-
836
- // src/client/query-response.ts
837
- function record(value) {
838
- return typeof value === "object" && value !== null && !Array.isArray(value);
839
- }
840
- function invalid(path) {
841
- throw new NarsilError(ClientErrorCodes.CLIENT_INVALID_RESPONSE, "The search response holds an invalid hit score", {
842
- route: path
843
- });
844
- }
845
- function decodeHits(hits, path) {
846
- if (!Array.isArray(hits)) invalid(path);
847
- for (const hit of hits) {
848
- if (!record(hit)) invalid(path);
849
- if (!Object.hasOwn(hit, "score")) continue;
850
- const score = decodeScore(hit.score);
851
- if (score === void 0) invalid(path);
852
- hit.score = score;
853
- }
854
- }
855
- function decodeQueryResult(payload, path) {
856
- if (!record(payload)) invalid(path);
857
- decodeHits(payload.hits, path);
858
- if (payload.groups !== void 0) {
859
- if (!Array.isArray(payload.groups)) invalid(path);
860
- for (const group of payload.groups) {
861
- if (!record(group)) invalid(path);
862
- decodeHits(group.hits, path);
863
- }
864
- }
865
- return payload;
866
- }
867
-
868
- // src/client/search.ts
869
- function createSearchOperations(transport) {
870
- async function post(path, params, options) {
871
- const payload = await transport.json({
872
- method: "POST",
873
- path,
874
- body: encodeJson(params),
875
- contentType: "application/json",
876
- repeatable: true,
877
- options
878
- });
879
- return readBody(payload, path);
880
- }
881
- return {
882
- async query(indexName, params, options) {
883
- const path = `${indexPath(indexName)}/search`;
884
- return decodeQueryResult(await post(path, params, options), path);
885
- },
886
- preflight(indexName, params, options) {
887
- return post(`${indexPath(indexName)}/search/preflight`, params, options);
888
- },
889
- suggest(indexName, params, options) {
890
- return post(`${indexPath(indexName)}/suggest`, params, options);
891
- }
892
- };
893
- }
894
-
895
- // src/client/server-info.ts
896
- function createServerOperations(transport) {
897
- let announced = null;
898
- async function readCapabilities(options) {
899
- const path = "/capabilities";
900
- const payload = await transport.jsonOrNull({ method: "GET", path, options }, ServerErrorCodes.NOT_FOUND);
901
- if (payload === null) return /* @__PURE__ */ new Set();
902
- return new Set(readArray(payload, "capabilities", path));
903
- }
904
- function load(options) {
905
- if (announced === null) {
906
- announced = readCapabilities(options).catch((err) => {
907
- announced = null;
908
- throw err;
909
- });
910
- }
911
- return announced;
912
- }
913
- return {
914
- async version(options) {
915
- const path = "/version";
916
- return readBody(await transport.json({ method: "GET", path, options }), path);
917
- },
918
- async capabilities(options) {
919
- return [...await load(options)];
920
- },
921
- async supports(capability, options) {
922
- return (await load(options)).has(capability);
923
- },
924
- async isAlive(options) {
925
- return await transport.probe({ method: "GET", path: "/livez", options }) === 200;
926
- },
927
- async isReady(options) {
928
- return await transport.probe({ method: "GET", path: "/readyz", options }) === 200;
929
- }
930
- };
931
- }
932
-
933
- // src/client/sync.ts
934
- var ENTITY_TAG = /^"([0-9a-f]{64})"$/;
935
- var CONTENT_RANGE = /^bytes (\d+)-(\d+)\/(\d+)$/;
936
- function invalidDownload(message, path) {
937
- return new NarsilError(ClientErrorCodes.CLIENT_INVALID_RESPONSE, message, { url: path });
938
- }
939
- function createSyncSettingOperations(transport) {
940
- return {
941
- async getSync(indexName, options) {
942
- const path = `${indexPath(indexName)}/sync`;
943
- return readBody(await transport.json({ method: "GET", path, options }), path);
944
- },
945
- async updateSync(indexName, setting, options) {
946
- const path = `${indexPath(indexName)}/sync`;
947
- await transport.json({ method: "PUT", path, body: encodeJson(setting), contentType: "application/json", options });
948
- },
949
- async syncSnapshot(indexName, resume, options) {
950
- const path = `${indexPath(indexName)}/sync/snapshot`;
951
- const headers = resume === void 0 || resume.offset <= 0 ? {} : { range: `bytes=${resume.offset}-`, "if-range": `"${resume.entityTag}"` };
952
- const answer = await transport.download({ method: "GET", path, headers, defaultTimeoutMs: NO_TIMEOUT, options });
953
- const entityTag = ENTITY_TAG.exec(answer.headers.get("etag") ?? "")?.[1];
954
- if (entityTag === void 0) {
955
- await answer.stream.cancel();
956
- throw invalidDownload("The server sent the snapshot without an entity tag", path);
957
- }
958
- if (answer.status === 206) {
959
- const range = CONTENT_RANGE.exec(answer.headers.get("content-range") ?? "");
960
- if (range === null || Number(range[1]) !== resume?.offset) {
961
- await answer.stream.cancel();
962
- throw invalidDownload("The server sent a byte range other than the one that the client asked for", path);
963
- }
964
- return { entityTag, offset: Number(range[1]), totalBytes: Number(range[3]), stream: answer.stream };
965
- }
966
- const length = Number(answer.headers.get("content-length") ?? Number.NaN);
967
- if (!Number.isSafeInteger(length)) {
968
- await answer.stream.cancel();
969
- throw invalidDownload("The server sent the snapshot without its length", path);
970
- }
971
- return { entityTag, offset: 0, totalBytes: length, stream: answer.stream };
972
- }
973
- };
974
- }
975
-
976
- // src/client/tasks.ts
977
- function isTerminal(record2) {
978
- return record2.status === "succeeded" || record2.status === "failed" || record2.status === "cancelled";
979
- }
980
- function progressKey(record2) {
981
- const progress = record2.progress;
982
- if (progress === void 0) return record2.status;
983
- return `${record2.status}:${progress.bytesProcessed}:${progress.indexed}:${progress.failed}`;
984
- }
985
- function sleep(milliseconds, signal) {
986
- return new Promise((resolve) => {
987
- const timer = setTimeout(() => {
988
- signal?.removeEventListener("abort", stop);
989
- resolve();
990
- }, milliseconds);
991
- function stop() {
992
- clearTimeout(timer);
993
- resolve();
994
- }
995
- signal?.addEventListener("abort", stop, { once: true });
996
- });
997
- }
998
- function listQuery(query) {
999
- return {
1000
- indexName: query?.indexName,
1001
- type: query?.type === void 0 || query.type.length === 0 ? void 0 : query.type.join(","),
1002
- status: query?.status === void 0 || query.status.length === 0 ? void 0 : query.status.join(","),
1003
- from: query?.from === void 0 ? void 0 : String(query.from),
1004
- limit: query?.limit === void 0 ? void 0 : String(query.limit)
1005
- };
1006
- }
1007
- function createTaskOperations(transport) {
1008
- const operations = {
1009
- async getTask(taskId, options) {
1010
- const path = taskPath(taskId);
1011
- const payload = await transport.jsonOrNull({ method: "GET", path, options }, ServerErrorCodes.TASK_NOT_FOUND);
1012
- return payload === null ? null : readBody(payload, path);
1013
- },
1014
- async listTasks(query, options) {
1015
- const path = "/tasks";
1016
- const payload = await transport.json({ method: "GET", path, query: listQuery(query), options });
1017
- return readBody(payload, path);
1018
- },
1019
- async cancelTask(taskId, options) {
1020
- const path = `${taskPath(taskId)}/_cancel`;
1021
- return readBody(await transport.json({ method: "POST", path, options }), path);
1022
- },
1023
- async waitForTask(taskId, options) {
1024
- const interval = options?.pollIntervalMs ?? DEFAULT_TASK_POLL_INTERVAL_MS;
1025
- const waitTimeoutMs = options?.waitTimeoutMs ?? 0;
1026
- const startedAt = Date.now();
1027
- let reported = null;
1028
- for (; ; ) {
1029
- if (options?.signal?.aborted === true) {
1030
- throw new NarsilError(
1031
- ClientErrorCodes.CLIENT_REQUEST_ABORTED,
1032
- `The caller stopped waiting for task "${taskId}"`,
1033
- { taskId }
1034
- );
1035
- }
1036
- const record2 = await operations.getTask(taskId, options);
1037
- if (record2 === null) {
1038
- throw new NarsilError(
1039
- ServerErrorCodes.TASK_NOT_FOUND,
1040
- `The server no longer holds task "${taskId}", so its outcome is unknown`,
1041
- { taskId }
1042
- );
1043
- }
1044
- const key = progressKey(record2);
1045
- if (key !== reported) {
1046
- reported = key;
1047
- options?.onProgress?.(record2);
1048
- }
1049
- if (isTerminal(record2)) return record2;
1050
- if (waitTimeoutMs > 0 && Date.now() - startedAt >= waitTimeoutMs) {
1051
- throw new NarsilError(
1052
- ClientErrorCodes.CLIENT_TASK_TIMEOUT,
1053
- `Task "${taskId}" was still ${record2.status} after ${waitTimeoutMs} ms, and it keeps running`,
1054
- { taskId, waitTimeoutMs, status: record2.status }
1055
- );
1056
- }
1057
- await sleep(interval, options?.signal);
1058
- }
1059
- }
1060
- };
1061
- return operations;
1062
- }
1063
-
1064
- // src/client/client.ts
1065
- function createNarsilClient(options) {
1066
- const transport = createTransport(options);
1067
- return {
1068
- ...createIndexOperations(transport),
1069
- ...createDocumentOperations(transport),
1070
- ...createBulkOperations(transport),
1071
- ...createSearchOperations(transport),
1072
- ...createTaskOperations(transport),
1073
- ...createAdminOperations(transport),
1074
- ...createBackupOperations(transport),
1075
- ...createServerOperations(transport),
1076
- ...createSyncSettingOperations(transport),
1077
- ...createQuerySuggestionOperations(transport)
1078
- };
1079
- }
5
+ import { createNarsilClient } from './browser/chunk-4E5APHTM.mjs';
6
+ import { loadMessagePack, loadedMessagePack, NarsilError, ErrorCodes, requireLoadedMessagePack, getNestedValue, ClientErrorCodes, extractVectorFieldsFromSchema } from './browser/chunk-YINZFPLT.mjs';
1080
7
 
1081
8
  // src/sync/protocol.ts
1082
9
  var SYNC_SUBPROTOCOL = "narsil.sync.v1";
@@ -1104,22 +31,22 @@ function backoffDelayMs(attempt, minimumMs, maximumMs) {
1104
31
 
1105
32
  // src/sync/device/messages.ts
1106
33
  var RESYNC_REASONS = /* @__PURE__ */ new Set(["epoch", "history", "ahead"]);
1107
- function isRecord3(value) {
34
+ function isRecord(value) {
1108
35
  return value !== null && typeof value === "object" && !Array.isArray(value) && !(value instanceof Uint8Array);
1109
36
  }
1110
37
  function isCount(value) {
1111
38
  return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
1112
39
  }
1113
- function malformed2(detail) {
40
+ function malformed(detail) {
1114
41
  return new NarsilError(ClientErrorCodes.CLIENT_INVALID_RESPONSE, `The sync feed sent a malformed message: ${detail}`);
1115
42
  }
1116
43
  function headsOf(raw) {
1117
- if (!Array.isArray(raw)) throw malformed2("heads must be a list");
44
+ if (!Array.isArray(raw)) throw malformed("heads must be a list");
1118
45
  const seqNos = new Array(raw.length).fill(-1);
1119
46
  for (const item of raw) {
1120
- if (!isRecord3(item) || !isCount(item.partitionId) || !isCount(item.seqNo)) throw malformed2("a head is invalid");
47
+ if (!isRecord(item) || !isCount(item.partitionId) || !isCount(item.seqNo)) throw malformed("a head is invalid");
1121
48
  if (item.partitionId >= seqNos.length || seqNos[item.partitionId] !== -1) {
1122
- throw malformed2("heads must name each partition once");
49
+ throw malformed("heads must name each partition once");
1123
50
  }
1124
51
  seqNos[item.partitionId] = item.seqNo;
1125
52
  }
@@ -1129,22 +56,22 @@ function stringList(value) {
1129
56
  return Array.isArray(value) && value.every((item) => typeof item === "string");
1130
57
  }
1131
58
  function settingsOf(raw) {
1132
- if (!isRecord3(raw) || typeof raw.language !== "string") throw malformed2("settings need a language");
59
+ if (!isRecord(raw) || typeof raw.language !== "string") throw malformed("settings need a language");
1133
60
  const optionalString2 = (key) => {
1134
61
  const value = raw[key];
1135
62
  if (value === void 0 || value === null) return void 0;
1136
- if (typeof value !== "string") throw malformed2(`settings.${key} must be a string`);
63
+ if (typeof value !== "string") throw malformed(`settings.${key} must be a string`);
1137
64
  return value;
1138
65
  };
1139
66
  const tokenizer = optionalString2("tokenizer");
1140
67
  const stopWords = optionalString2("stopWords");
1141
68
  const analysisRevision = optionalString2("analysisRevision");
1142
69
  if (raw.stopWordList !== void 0 && raw.stopWordList !== null && !stringList(raw.stopWordList)) {
1143
- throw malformed2("settings.stopWordList must be a list of strings");
70
+ throw malformed("settings.stopWordList must be a list of strings");
1144
71
  }
1145
- if (raw.bm25 !== void 0 && raw.bm25 !== null && !isRecord3(raw.bm25)) throw malformed2("settings.bm25 is invalid");
72
+ if (raw.bm25 !== void 0 && raw.bm25 !== null && !isRecord(raw.bm25)) throw malformed("settings.bm25 is invalid");
1146
73
  if (raw.synonyms !== void 0 && raw.synonyms !== null && !Array.isArray(raw.synonyms)) {
1147
- throw malformed2("settings.synonyms must be a list");
74
+ throw malformed("settings.synonyms must be a list");
1148
75
  }
1149
76
  return {
1150
77
  language: raw.language,
@@ -1152,26 +79,26 @@ function settingsOf(raw) {
1152
79
  ...stopWords !== void 0 ? { stopWords } : {},
1153
80
  ...stringList(raw.stopWordList) ? { stopWordList: raw.stopWordList } : {},
1154
81
  ...analysisRevision !== void 0 ? { analysisRevision } : {},
1155
- ...isRecord3(raw.bm25) ? { bm25: raw.bm25 } : {},
82
+ ...isRecord(raw.bm25) ? { bm25: raw.bm25 } : {},
1156
83
  ...Array.isArray(raw.synonyms) ? { synonyms: raw.synonyms } : {}
1157
84
  };
1158
85
  }
1159
86
  function entriesOf(partitionId, raw) {
1160
- if (!Array.isArray(raw)) throw malformed2("entries must be a list");
87
+ if (!Array.isArray(raw)) throw malformed("entries must be a list");
1161
88
  let previous = -1;
1162
89
  return raw.map((item) => {
1163
- if (!isRecord3(item) || !isCount(item.seqNo) || typeof item.documentId !== "string") {
1164
- throw malformed2("an entry is invalid");
90
+ if (!isRecord(item) || !isCount(item.seqNo) || typeof item.documentId !== "string") {
91
+ throw malformed("an entry is invalid");
1165
92
  }
1166
- if (item.seqNo <= previous) throw malformed2("entries must rise in sequence order");
93
+ if (item.seqNo <= previous) throw malformed("entries must rise in sequence order");
1167
94
  if (item.partitionId !== void 0 && item.partitionId !== partitionId) {
1168
- throw malformed2("an entry belongs to another partition");
95
+ throw malformed("an entry belongs to another partition");
1169
96
  }
1170
97
  previous = item.seqNo;
1171
98
  if (item.operation === "DELETE") {
1172
99
  return { partitionId, seqNo: item.seqNo, documentId: item.documentId, document: null };
1173
100
  }
1174
- if (item.operation !== "INDEX" || !(item.document instanceof Uint8Array)) throw malformed2("an entry is invalid");
101
+ if (item.operation !== "INDEX" || !(item.document instanceof Uint8Array)) throw malformed("an entry is invalid");
1175
102
  return { partitionId, seqNo: item.seqNo, documentId: item.documentId, document: item.document };
1176
103
  });
1177
104
  }
@@ -1181,17 +108,17 @@ function decodeFeedMessage(bytes) {
1181
108
  try {
1182
109
  raw = decode(bytes);
1183
110
  } catch {
1184
- throw malformed2("a frame is not MessagePack");
111
+ throw malformed("a frame is not MessagePack");
1185
112
  }
1186
- if (!isRecord3(raw)) throw malformed2("a frame is not a map");
113
+ if (!isRecord(raw)) throw malformed("a frame is not a map");
1187
114
  switch (raw.type) {
1188
115
  case "subscribed": {
1189
- if (!isSyncEpoch(raw.epoch) || !isCount(raw.partitionCount)) throw malformed2("subscribed is invalid");
116
+ if (!isSyncEpoch(raw.epoch) || !isCount(raw.partitionCount)) throw malformed("subscribed is invalid");
1190
117
  if (!isCount(raw.bytesBehind) || !isCount(raw.snapshotBytes) || !isCount(raw.windowBytes)) {
1191
- throw malformed2("subscribed is invalid");
118
+ throw malformed("subscribed is invalid");
1192
119
  }
1193
120
  const heads = headsOf(raw.heads);
1194
- if (heads.length !== raw.partitionCount) throw malformed2("subscribed needs one head for each partition");
121
+ if (heads.length !== raw.partitionCount) throw malformed("subscribed needs one head for each partition");
1195
122
  return {
1196
123
  type: "subscribed",
1197
124
  epoch: raw.epoch,
@@ -1204,18 +131,18 @@ function decodeFeedMessage(bytes) {
1204
131
  };
1205
132
  }
1206
133
  case "entries":
1207
- if (!isCount(raw.partitionId)) throw malformed2("entries need a partition");
134
+ if (!isCount(raw.partitionId)) throw malformed("entries need a partition");
1208
135
  return { type: "entries", partitionId: raw.partitionId, entries: entriesOf(raw.partitionId, raw.entries) };
1209
136
  case "settings":
1210
137
  return { type: "settings", settings: settingsOf(raw.settings) };
1211
138
  case "checkpoint":
1212
- if (!isCount(raw.id)) throw malformed2("checkpoint needs an id");
139
+ if (!isCount(raw.id)) throw malformed("checkpoint needs an id");
1213
140
  return { type: "checkpoint", id: raw.id, heads: headsOf(raw.heads) };
1214
141
  case "resync":
1215
- if (typeof raw.reason !== "string" || !RESYNC_REASONS.has(raw.reason)) throw malformed2("resync is invalid");
142
+ if (typeof raw.reason !== "string" || !RESYNC_REASONS.has(raw.reason)) throw malformed("resync is invalid");
1216
143
  return { type: "resync", reason: raw.reason };
1217
144
  default:
1218
- throw malformed2(`unknown type ${String(raw.type)}`);
145
+ throw malformed(`unknown type ${String(raw.type)}`);
1219
146
  }
1220
147
  }
1221
148
  function positionsOf(seqNos) {
@@ -2094,16 +1021,16 @@ function createUploader(context, progress, session, state) {
2094
1021
  }
2095
1022
 
2096
1023
  // src/sync/device/index.ts
2097
- function invalid2(message) {
1024
+ function invalid(message) {
2098
1025
  return new NarsilError(ErrorCodes.CONFIG_INVALID, message);
2099
1026
  }
2100
1027
  function validated(options) {
2101
1028
  if (typeof options.indexName !== "string" || options.indexName.length === 0) {
2102
- throw invalid2("Device sync needs an index name");
1029
+ throw invalid("Device sync needs an index name");
2103
1030
  }
2104
1031
  const limit = options.replayLimitOfSnapshot;
2105
1032
  if (limit !== void 0 && (!Number.isFinite(limit) || limit < 0)) {
2106
- throw invalid2("replayLimitOfSnapshot must be a finite number at or above 0");
1033
+ throw invalid("replayLimitOfSnapshot must be a finite number at or above 0");
2107
1034
  }
2108
1035
  }
2109
1036
  function requireDocumentObject(document) {
@@ -2250,12 +1177,12 @@ function createDeviceSync(options) {
2250
1177
  }
2251
1178
  async function waitUntil(condition) {
2252
1179
  while (!condition()) {
2253
- if (stopped) throw invalid2("Device sync stopped before it settled");
1180
+ if (stopped) throw invalid("Device sync stopped before it settled");
2254
1181
  await changes.next();
2255
1182
  }
2256
1183
  }
2257
1184
  function requireRecovered() {
2258
- if (recovered === null) throw invalid2("Call start before writing through device sync");
1185
+ if (recovered === null) throw invalid("Call start before writing through device sync");
2259
1186
  return recovered;
2260
1187
  }
2261
1188
  async function write(documentId, document) {