@delali/narsil 0.4.1-next.215 → 0.4.2-next.271
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 +1 -1
- package/dist/adapters/filesystem.d.ts +1 -1
- package/dist/adapters/filesystem.mjs +9 -3
- package/dist/adapters/gcs.d.ts +1 -1
- package/dist/adapters/indexeddb.d.ts +6 -1
- package/dist/adapters/indexeddb.mjs +20 -26
- package/dist/adapters/memory.d.ts +1 -1
- package/dist/adapters/s3.d.ts +1 -1
- package/dist/{adapters-pljAqmrC.d.ts → adapters-8LcdNB77.d.ts} +18 -1
- package/dist/browser/{chunk-GBJSEHVJ.mjs → chunk-DPRCAVC2.mjs} +14 -8
- package/dist/browser/{chunk-YINZFPLT.mjs → chunk-WRRXR57N.mjs} +1 -1
- package/dist/browser/{chunk-QAOVAYAG.mjs → chunk-XBWABEL3.mjs} +1 -1
- package/dist/browser/{chunk-4E5APHTM.mjs → chunk-Y5CSZDOH.mjs} +1 -1
- package/dist/browser/{durability-config-75NSFCQN.mjs → durability-config-UP3OTUMB.mjs} +34 -2
- package/dist/browser/{msgpack-leaf-44XNWSSY.mjs → msgpack-leaf-FEPCLXXY.mjs} +7 -1
- package/dist/browser/{optional-reads-6LN3HMUH.mjs → optional-reads-NQO5DKM4.mjs} +18 -16
- package/dist/browser/{optional-writes-76DWMRQH.mjs → optional-writes-HVPPDHSY.mjs} +259 -104
- package/dist/browser/{storage-leaf-5UTR5K7J.mjs → storage-leaf-42IZEOJJ.mjs} +1473 -305
- package/dist/{capabilities-BOFFMx84.d.ts → capabilities-BoWiLNv7.d.ts} +76 -61
- package/dist/{chunk-DBC4EJWB.mjs → chunk-33ZMFOAR.mjs} +1 -1
- package/dist/{chunk-NCIGNQJE.mjs → chunk-4GCHJ3XD.mjs} +930 -387
- package/dist/{chunk-7P5YWDRQ.mjs → chunk-4WQNWAQE.mjs} +1 -1
- package/dist/{chunk-357KIU5E.mjs → chunk-5E3TJ4P3.mjs} +5 -5
- package/dist/{chunk-GXCDWLQI.mjs → chunk-5GYGHPCH.mjs} +7 -1
- package/dist/{chunk-SMQPZHPS.mjs → chunk-ATQ6JR3I.mjs} +1 -1
- package/dist/{chunk-2K24MEYV.mjs → chunk-BBIAUHAB.mjs} +3 -3
- package/dist/{react-native/chunks/chunk-MMPBO4WR.mjs → chunk-DA32WXBT.mjs} +2 -2
- package/dist/{chunk-MSJD74GN.mjs → chunk-EALKCTWH.mjs} +5 -5
- package/dist/{chunk-755NM4PL.mjs → chunk-FOGTBAYN.mjs} +183 -21
- package/dist/{chunk-6GHX35ZM.mjs → chunk-GTBJSNN2.mjs} +1 -1
- package/dist/{chunk-DDUXEJXW.mjs → chunk-H6LWGMPQ.mjs} +45 -22
- package/dist/{chunk-UNEEFTEU.mjs → chunk-HZ3OAUTL.mjs} +2 -1
- package/dist/{chunk-M3B7SGJB.mjs → chunk-KL4ORYJW.mjs} +6 -6
- package/dist/{chunk-IL5DRCNU.mjs → chunk-KQWTS7AM.mjs} +1 -1
- package/dist/{chunk-DKIMHIBC.mjs → chunk-KX3OP6VP.mjs} +2 -2
- package/dist/{chunk-D456ZFPQ.mjs → chunk-MIIJ5O3O.mjs} +2 -2
- package/dist/{chunk-PP3W5PQQ.mjs → chunk-MS746XNY.mjs} +285 -118
- package/dist/{chunk-WM5KJSQV.mjs → chunk-NFA3WHJU.mjs} +1 -1
- package/dist/{react-native/chunks/chunk-ZUJCUPVS.mjs → chunk-OETLM4EH.mjs} +1 -1
- package/dist/{chunk-MYN4K5IS.mjs → chunk-OLXFIUIZ.mjs} +1 -1
- package/dist/{chunk-P4F4UWLC.mjs → chunk-PSO7V7VW.mjs} +17 -3
- package/dist/{chunk-X3EQCQLP.mjs → chunk-Q4NLL66U.mjs} +2 -2
- package/dist/{chunk-WC5KAWXQ.mjs → chunk-QJFKL4NK.mjs} +4 -4
- package/dist/{chunk-MSIN4NM3.mjs → chunk-S3JHYPH7.mjs} +6 -1
- package/dist/{chunk-3IE3A74H.mjs → chunk-SSITKQU6.mjs} +3 -3
- package/dist/{chunk-B3MO37YF.mjs → chunk-TANKI7TG.mjs} +1 -1
- package/dist/{chunk-Z7XSHKOF.mjs → chunk-TI4G3SIG.mjs} +63 -144
- package/dist/{chunk-OGYSPNL2.mjs → chunk-TT3UDDL3.mjs} +7 -7
- package/dist/{react-native/chunks/chunk-4FUCRLSA.mjs → chunk-VHIOGDVD.mjs} +1 -1
- package/dist/{chunk-AXDB6KUQ.mjs → chunk-W3JH2IK6.mjs} +4 -4
- package/dist/{chunk-CERPUGRK.mjs → chunk-WIT6B5OB.mjs} +2 -2
- package/dist/{chunk-MI6UZGUR.mjs → chunk-XGVSG6ZU.mjs} +3 -3
- package/dist/{chunk-6I6OO6B2.mjs → chunk-XWPNRHTG.mjs} +4 -4
- package/dist/{chunk-WTMCGZ74.mjs → chunk-YHZSSPG3.mjs} +2 -2
- package/dist/chunk-ZYEEOZTT.mjs +52 -0
- package/dist/{client-BhNxHtcZ.d.ts → client-B0NPZSKY.d.ts} +4 -4
- package/dist/client.d.ts +9 -9
- package/dist/client.mjs +2 -2
- package/dist/{config-P9zW3Zz7.d.ts → config-B3-sw887.d.ts} +3 -3
- package/dist/{config-BJSL7piq.d.ts → config-DL_nkguq.d.ts} +4 -4
- package/dist/{direct-executor-GWJXDFLD.mjs → direct-executor-PCBB6FCO.mjs} +4 -4
- package/dist/distribution/coordinator/etcd.d.ts +3 -3
- package/dist/distribution/coordinator/etcd.mjs +33 -3
- package/dist/distribution/coordinator/in-memory.d.ts +3 -3
- package/dist/distribution/transport/grpc.mjs +4 -4
- package/dist/distribution/transport/in-memory.mjs +1 -1
- package/dist/distribution/transport/tcp.mjs +12 -7
- package/dist/distribution.d.ts +8 -8
- package/dist/distribution.mjs +167 -91
- package/dist/{durability-config-VWS2K24E.mjs → durability-config-HWKWP35M.mjs} +34 -2
- package/dist/embeddings/openai.d.ts +7 -3
- package/dist/embeddings/openai.mjs +37 -31
- package/dist/{engine-DoFnkRoF.d.ts → engine-DGG_yX0p.d.ts} +3 -3
- package/dist/{index-B_vmxpgW.d.ts → index-fX_FbuRT.d.ts} +1 -1
- package/dist/index.browser.mjs +3 -3
- package/dist/index.d.ts +7 -7
- package/dist/index.mjs +4 -4
- package/dist/index.react-native.mjs +4 -4
- package/dist/invalidation/broadcast-channel.d.ts +1 -1
- package/dist/invalidation/filesystem.d.ts +1 -1
- package/dist/invalidation/noop.d.ts +1 -1
- package/dist/{long-query-thread-GNTDYDOZ.mjs → long-query-thread-4ALYIIC4.mjs} +14 -14
- package/dist/msgpack-leaf-6ZBZWFRD.mjs +9 -0
- package/dist/{optional-reads-UCS23AWP.mjs → optional-reads-ESDVS225.mjs} +18 -16
- package/dist/{optional-writes-2AHJCGTY.mjs → optional-writes-2OK4TOLY.mjs} +9 -8
- package/dist/{paged-partition-archive-GBAHDT55.mjs → paged-partition-archive-Y5OAKNRB.mjs} +13 -13
- package/dist/partial-words.browser.mjs +3 -3
- package/dist/partial-words.mjs +4 -4
- package/dist/pattern.browser.mjs +2 -2
- package/dist/pattern.mjs +2 -2
- package/dist/persistence/durability/checkpoint-worker.d.ts +2 -2
- package/dist/persistence/durability/checkpoint-worker.mjs +14 -14
- package/dist/{query-actions-IDCUA7UV.mjs → query-actions-UQVQZFIJ.mjs} +4 -4
- package/dist/query-suggestions/merge-worker.mjs +7 -7
- package/dist/query-suggestions.browser.mjs +3 -3
- package/dist/query-suggestions.d.ts +3 -3
- package/dist/query-suggestions.mjs +5 -5
- package/dist/{chunk-F26DOOUH.mjs → react-native/chunks/chunk-4OOUY2K7.mjs} +1 -1
- package/dist/react-native/chunks/{chunk-LPX26NNL.mjs → chunk-5MYHYBET.mjs} +286 -118
- package/dist/react-native/chunks/{chunk-MRH36RN3.mjs → chunk-AVCMTWET.mjs} +1 -1
- package/dist/react-native/chunks/{chunk-HTBY4GON.mjs → chunk-GS6LGXY3.mjs} +1 -1
- package/dist/{chunk-UHLFCGZ3.mjs → react-native/chunks/chunk-LE4DTMDL.mjs} +2 -2
- package/dist/react-native/chunks/{chunk-TG56N5JC.mjs → chunk-VIO5IPF7.mjs} +2 -2
- package/dist/react-native/chunks/{chunk-UO44MA5M.mjs → chunk-VRI5XH2M.mjs} +7 -1
- package/dist/{chunk-R2PJKSNL.mjs → react-native/chunks/chunk-XGS2UYVI.mjs} +1 -1
- package/dist/react-native/chunks/{chunk-AJAH6X7W.mjs → chunk-XW6GZQWP.mjs} +4 -4
- package/dist/react-native/chunks/{chunk-SCGBU47K.mjs → chunk-Z44S6WW5.mjs} +2 -2
- package/dist/react-native/chunks/{durability-config-FCSD4MXY.mjs → durability-config-HJETGZVB.mjs} +34 -2
- package/dist/react-native/chunks/msgpack-leaf-4MIGXWZT.mjs +7 -0
- package/dist/react-native/chunks/{optional-reads-4XCJ34QG.mjs → optional-reads-TN3PT6M4.mjs} +18 -16
- package/dist/react-native/chunks/{optional-writes-XYZVTBFB.mjs → optional-writes-LZDHB7FX.mjs} +8 -7
- package/dist/react-native/chunks/{restore-queue-NOKQZJ2Z.mjs → restore-queue-J7SB263E.mjs} +7 -7
- package/dist/react-native/chunks/{segment-codec-leaf-3ZXBJVKH.mjs → segment-codec-leaf-PEKX7TBL.mjs} +5 -5
- package/dist/react-native/chunks/{segment-merge-leaf-3Z7MMPWE.mjs → segment-merge-leaf-I2EC7H6R.mjs} +6 -6
- package/dist/react-native/chunks/{storage-leaf-KJOX3MMW.mjs → storage-leaf-RQXM7HBO.mjs} +1481 -314
- package/dist/react-native/chunks/{store-leaf-QGLVSO5X.mjs → store-leaf-EZGCLSLM.mjs} +6 -6
- package/dist/react-native/chunks/{suggestions-leaf-6GI5ZSW6.mjs → suggestions-leaf-JNGH2JYC.mjs} +6 -6
- package/dist/react-native/chunks/{worker-copies-ALOD7TSP.mjs → worker-copies-2OWLLBCV.mjs} +5 -5
- package/dist/react-native/partial-words.mjs +4 -4
- package/dist/react-native/pattern.mjs +2 -2
- package/dist/react-native/query-suggestions.mjs +4 -4
- package/dist/react-native/sync.mjs +4 -4
- package/dist/react-native/synonyms.mjs +4 -4
- package/dist/react.d.ts +10 -10
- package/dist/react.mjs +0 -2
- package/dist/{rerank-HB6DU6GS.mjs → rerank-TQ4SU76L.mjs} +4 -4
- package/dist/rerankers/http.d.ts +1 -1
- package/dist/rerankers/http.mjs +19 -15
- package/dist/{restore-queue-VUQHGCXE.mjs → restore-queue-W7U2X6V3.mjs} +7 -7
- package/dist/{schema-CzG9OUw5.d.ts → schema-CFnQ-WI3.d.ts} +1 -1
- package/dist/{segment-codec-leaf-TW2FPAAT.mjs → segment-codec-leaf-WGP4FBXF.mjs} +5 -5
- package/dist/{segment-merge-leaf-BS3QV5PZ.mjs → segment-merge-leaf-FYWJQSPL.mjs} +5 -5
- package/dist/server.d.ts +86 -12
- package/dist/server.mjs +2243 -1918
- package/dist/{storage-leaf-5IG2HPNY.mjs → storage-leaf-GRG44RQA.mjs} +1193 -219
- package/dist/{store-leaf-ZWSOK2DV.mjs → store-leaf-YDJVH73G.mjs} +6 -6
- package/dist/{suggestions-leaf-MUZNKQVF.mjs → suggestions-leaf-5UFJV7SC.mjs} +8 -8
- package/dist/sync/filesystem.d.ts +4 -4
- package/dist/sync/filesystem.mjs +12 -12
- package/dist/sync/indexeddb.browser.mjs +1 -1
- package/dist/sync/indexeddb.d.ts +4 -4
- package/dist/sync/indexeddb.mjs +2 -2
- package/dist/sync.browser.mjs +4 -4
- package/dist/sync.d.ts +5 -5
- package/dist/sync.mjs +4 -4
- package/dist/synonyms.browser.mjs +3 -3
- package/dist/synonyms.mjs +4 -4
- package/dist/{tasks-DrLiolTG.d.ts → tasks-B2MDjPL0.d.ts} +4 -4
- package/dist/{thread-6ZBCENAP.mjs → thread-6YLVL2NC.mjs} +13 -13
- package/dist/{types-pS-mAJmX.d.ts → types-DGjk684l.d.ts} +2 -2
- package/dist/vector/search-worker.d.ts +2 -2
- package/dist/{worker-copies-32HWFUH7.mjs → worker-copies-IP4L7KEW.mjs} +7 -7
- package/dist/workers/entry.mjs +16 -16
- package/package.json +12 -10
- package/dist/chunk-HLPRHOSO.mjs +0 -17
- package/dist/msgpack-leaf-H5ZYW7S7.mjs +0 -9
- package/dist/react-native/chunks/msgpack-leaf-JMNGSTRW.mjs +0 -7
package/README.md
CHANGED
|
@@ -129,6 +129,7 @@ Every hit holds the document, its id, and its BM25 score. Beside the hits, `resu
|
|
|
129
129
|
| [Persistence and durability](https://github.com/assetcorp/narsil/blob/main/docs/persistence-and-durability.md) | Storage backends, the write-ahead log, checkpoints, recovery, snapshots, document exports, and indexes from an earlier release |
|
|
130
130
|
| [Partitions and workers](https://github.com/assetcorp/narsil/blob/main/docs/partitions-and-workers.md) | Partition routing, online rebalancing, worker copies, and multi-instance invalidation |
|
|
131
131
|
| [Language support](https://github.com/assetcorp/narsil/blob/main/docs/language-support.md) | Every language module, analysis revisions and rebuilds, and named tokenizers and stop words |
|
|
132
|
+
| [Container image](https://github.com/assetcorp/narsil/blob/main/docs/container-image.md) | Starting a node from the published image with Docker Compose, connecting each client, keeping the data across a restart, and serving from the Rust server under a `-rust` tag |
|
|
132
133
|
| [HTTP server](https://github.com/assetcorp/narsil/blob/main/docs/http-server.md) | Wrapping an engine in a REST API, every route it serves, and long-running tasks |
|
|
133
134
|
| [Cluster mode](https://github.com/assetcorp/narsil/blob/main/docs/cluster.md) | Multi-node indexes: nodes and roles, replication, routed writes, distributed searches and reads, and the calls that fail in a cluster |
|
|
134
135
|
| [Client](https://github.com/assetcorp/narsil/blob/main/docs/client.md) | Reaching a server from a browser or Node, following a task, and the codes it raises |
|
|
@@ -148,7 +149,6 @@ The [specification](https://github.com/assetcorp/narsil/tree/main/packages/spec)
|
|
|
148
149
|
|
|
149
150
|
| Example | What it shows |
|
|
150
151
|
| --- | --- |
|
|
151
|
-
| [HTTP server](https://github.com/assetcorp/narsil/blob/main/packages/ts/examples/http-server/README.md) | The launcher serves the engine as a REST service with durability, API-key auth, and Docker packaging, while every setting comes from the environment. |
|
|
152
152
|
| [Browser](https://github.com/assetcorp/narsil/blob/main/packages/ts/examples/browser/README.md) | The app embeds the engine in a browser with IndexedDB persistence and Web Worker search. |
|
|
153
153
|
| [Server app](https://github.com/assetcorp/narsil/blob/main/packages/ts/examples/server-app/README.md) | The app calls the HTTP server through the client SDK and the React hooks to load corpora as import tasks. In its Ask view, you can ask questions about those corpora. |
|
|
154
154
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { renameReplacing } from '../chunk-ZYEEOZTT.mjs';
|
|
2
|
+
import '../chunk-S3JHYPH7.mjs';
|
|
1
3
|
import { requireStreamLength, countedChunks } from '../chunk-GR5GMFJJ.mjs';
|
|
2
4
|
import '../chunk-4PY4JYMY.mjs';
|
|
3
5
|
import { OBJECT_STORE_PART_BYTES } from '../chunk-K5HSUPYS.mjs';
|
|
@@ -130,11 +132,15 @@ function createFilesystemPersistence(config) {
|
|
|
130
132
|
const tempPath = pathMod.join(dir, unfinishedSaveName(pathMod.basename(resolvedPath)));
|
|
131
133
|
try {
|
|
132
134
|
await writeSyncedFile(fs, tempPath, data, key);
|
|
133
|
-
await
|
|
135
|
+
await renameReplacing(tempPath, resolvedPath);
|
|
134
136
|
await fsyncDirectory(dir, fs);
|
|
135
137
|
} catch (err) {
|
|
136
138
|
await fs.unlink(tempPath).catch(() => void 0);
|
|
137
|
-
throw err;
|
|
139
|
+
if (err instanceof NarsilError) throw err;
|
|
140
|
+
throw new NarsilError(ErrorCodes.PERSISTENCE_SAVE_FAILED, `The adapter could not save "${key}"`, {
|
|
141
|
+
key,
|
|
142
|
+
cause: err instanceof Error ? err.message : String(err)
|
|
143
|
+
});
|
|
138
144
|
}
|
|
139
145
|
},
|
|
140
146
|
async saveIfAbsent(key, data) {
|
|
@@ -178,7 +184,7 @@ function createFilesystemPersistence(config) {
|
|
|
178
184
|
await handle.sync();
|
|
179
185
|
await handle.close();
|
|
180
186
|
handle = null;
|
|
181
|
-
await
|
|
187
|
+
await renameReplacing(tempPath, resolvedPath);
|
|
182
188
|
await fsyncDirectory(dir, fs);
|
|
183
189
|
} catch (err) {
|
|
184
190
|
if (handle !== null) await handle.close().catch(() => void 0);
|
package/dist/adapters/gcs.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as PersistenceAdapter } from '../adapters-
|
|
1
|
+
import { P as PersistenceAdapter } from '../adapters-8LcdNB77.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Which IndexedDB database and object store
|
|
@@ -19,6 +19,11 @@ interface IndexedDBPersistenceConfig {
|
|
|
19
19
|
* The adapter opens the database on its first call and keeps the handle, so
|
|
20
20
|
* creating it costs nothing until the engine writes.
|
|
21
21
|
*
|
|
22
|
+
* An engine on this adapter keeps a write-ahead log in the same object store,
|
|
23
|
+
* so a closed tab keeps every write that the engine acknowledged, and only one
|
|
24
|
+
* engine at a time can open the store. Pass an invalidation adapter, or set
|
|
25
|
+
* `durability.tier` to `'snapshot'`, where several tabs share the store.
|
|
26
|
+
*
|
|
22
27
|
* @param config - The database and object store to use. Omit it to accept the
|
|
23
28
|
* defaults.
|
|
24
29
|
* @returns An adapter you pass as `persistence` when creating an engine.
|
|
@@ -66,22 +66,28 @@ function createIndexedDBPersistence(config) {
|
|
|
66
66
|
};
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
|
+
async function commitWrite(key, code, write) {
|
|
70
|
+
const db = await openDatabase();
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
72
|
+
const tx = db.transaction(storeName, "readwrite", { durability: "strict" });
|
|
73
|
+
const fail = () => reject(
|
|
74
|
+
new NarsilError(
|
|
75
|
+
code,
|
|
76
|
+
`Failed to ${code === ErrorCodes.PERSISTENCE_SAVE_FAILED ? "save" : "delete"} key "${key}": ${tx.error?.message ?? "unknown error"}`
|
|
77
|
+
)
|
|
78
|
+
);
|
|
79
|
+
tx.oncomplete = () => resolve();
|
|
80
|
+
tx.onerror = fail;
|
|
81
|
+
tx.onabort = fail;
|
|
82
|
+
write(tx.objectStore(storeName));
|
|
83
|
+
});
|
|
84
|
+
}
|
|
69
85
|
return {
|
|
86
|
+
indexedDB: { databaseName: dbName, storeName },
|
|
70
87
|
async save(key, data) {
|
|
71
88
|
validateKey(key);
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
const tx = db.transaction(storeName, "readwrite");
|
|
75
|
-
const store = tx.objectStore(storeName);
|
|
76
|
-
const request = store.put(data, key);
|
|
77
|
-
request.onsuccess = () => resolve();
|
|
78
|
-
request.onerror = () => reject(
|
|
79
|
-
new NarsilError(
|
|
80
|
-
ErrorCodes.PERSISTENCE_SAVE_FAILED,
|
|
81
|
-
`Failed to save key "${key}": ${request.error?.message ?? "unknown error"}`
|
|
82
|
-
)
|
|
83
|
-
);
|
|
84
|
-
});
|
|
89
|
+
const ownedBytes = data.byteOffset === 0 && data.byteLength === data.buffer.byteLength ? data : data.slice();
|
|
90
|
+
await commitWrite(key, ErrorCodes.PERSISTENCE_SAVE_FAILED, (store) => store.put(ownedBytes, key));
|
|
85
91
|
},
|
|
86
92
|
async load(key) {
|
|
87
93
|
validateKey(key);
|
|
@@ -108,19 +114,7 @@ function createIndexedDBPersistence(config) {
|
|
|
108
114
|
},
|
|
109
115
|
async delete(key) {
|
|
110
116
|
validateKey(key);
|
|
111
|
-
|
|
112
|
-
return new Promise((resolve, reject) => {
|
|
113
|
-
const tx = db.transaction(storeName, "readwrite");
|
|
114
|
-
const store = tx.objectStore(storeName);
|
|
115
|
-
const request = store.delete(key);
|
|
116
|
-
request.onsuccess = () => resolve();
|
|
117
|
-
request.onerror = () => reject(
|
|
118
|
-
new NarsilError(
|
|
119
|
-
ErrorCodes.PERSISTENCE_DELETE_FAILED,
|
|
120
|
-
`Failed to delete key "${key}": ${request.error?.message ?? "unknown error"}`
|
|
121
|
-
)
|
|
122
|
-
);
|
|
123
|
-
});
|
|
117
|
+
await commitWrite(key, ErrorCodes.PERSISTENCE_DELETE_FAILED, (store) => store.delete(key));
|
|
124
118
|
},
|
|
125
119
|
async list(prefix) {
|
|
126
120
|
const db = await openDatabase();
|
package/dist/adapters/s3.d.ts
CHANGED
|
@@ -71,6 +71,23 @@ interface PersistenceAdapter {
|
|
|
71
71
|
saveIfAbsent?(key: string, data: Uint8Array): Promise<boolean>;
|
|
72
72
|
/** This adapter writes to this directory, when a filesystem backs it. */
|
|
73
73
|
readonly directory?: string;
|
|
74
|
+
/**
|
|
75
|
+
* This adapter writes to this IndexedDB database and object store, when IndexedDB backs it. The engine then keeps
|
|
76
|
+
* its write-ahead log in the same store, so a closed tab keeps every write that the engine acknowledged.
|
|
77
|
+
*/
|
|
78
|
+
readonly indexedDB?: IndexedDBLocation;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The IndexedDB database and object store that a persistence adapter writes to, which
|
|
82
|
+
* {@link PersistenceAdapter.indexedDB} reports.
|
|
83
|
+
*
|
|
84
|
+
* @public
|
|
85
|
+
*/
|
|
86
|
+
interface IndexedDBLocation {
|
|
87
|
+
/** The adapter opens the database with this name. */
|
|
88
|
+
readonly databaseName: string;
|
|
89
|
+
/** The adapter keeps its records in the object store with this name. */
|
|
90
|
+
readonly storeName: string;
|
|
74
91
|
}
|
|
75
92
|
/**
|
|
76
93
|
* Carries partition changes between engine instances that share one store.
|
|
@@ -205,4 +222,4 @@ interface RerankAdapter {
|
|
|
205
222
|
shutdown?(): Promise<void>;
|
|
206
223
|
}
|
|
207
224
|
|
|
208
|
-
export type { EmbeddingAdapter as E, InvalidationAdapter as I, PersistenceAdapter as P, RerankAdapter as R,
|
|
225
|
+
export type { EmbeddingAdapter as E, InvalidationAdapter as I, PersistenceAdapter as P, RerankAdapter as R, IndexedDBLocation as a, InvalidationEvent as b, PartitionStatistics as c };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { PATTERN_EXPRESSION_OPERATORS, PATTERN_TEST_OPERATORS, PATTERN_ELEMENT_OPERATORS, requireTextRangeField, isFiniteNumber, invalid, requireFieldKind, kindOfValue, requireListLength, isObjectRecord, GEO_UNIT_METRES, storedText, DEFAULT_PATTERN_WORK_CAP, MAX_FILTER_DEPTH, discardStoredValues, bitsetIsEmpty, storedValuesOf, bitsetHas, createBitSet, bitsetSet, storedValueBytes, prepareStoredValues, cachedStoredFields, bitsetClear, MAX_FILTER_TESTS, TYPO_CLAIM_SLOTS_PER_WORD, buildStoredValues, bitsetAndNotInto, bitsetAndInto, bitsetOrInto, checkedSize, fuzzyPrefixOf, boundedLevenshtein, installStoredFields, FILTER_OPERAND_COPY_DEPTH, fuzzyTermMatches, PATTERN_WORK_FLUSH_UNITS, MATCHER_STATE_BUDGET_BYTES, bitsetIterator, GrowableUint32, bitsetFromSet } from './chunk-
|
|
1
|
+
import { PATTERN_EXPRESSION_OPERATORS, PATTERN_TEST_OPERATORS, PATTERN_ELEMENT_OPERATORS, requireTextRangeField, isFiniteNumber, invalid, requireFieldKind, kindOfValue, requireListLength, isObjectRecord, GEO_UNIT_METRES, storedText, DEFAULT_PATTERN_WORK_CAP, MAX_FILTER_DEPTH, discardStoredValues, bitsetIsEmpty, storedValuesOf, bitsetHas, createBitSet, bitsetSet, storedValueBytes, prepareStoredValues, cachedStoredFields, bitsetClear, MAX_FILTER_TESTS, TYPO_CLAIM_SLOTS_PER_WORD, buildStoredValues, bitsetAndNotInto, bitsetAndInto, bitsetOrInto, checkedSize, fuzzyPrefixOf, boundedLevenshtein, installStoredFields, FILTER_OPERAND_COPY_DEPTH, fuzzyTermMatches, PATTERN_WORK_FLUSH_UNITS, MATCHER_STATE_BUDGET_BYTES, bitsetIterator, GrowableUint32, bitsetFromSet } from './chunk-XBWABEL3.mjs';
|
|
2
2
|
import { newSyncEpoch, isSyncEpoch } from './chunk-YJHGOJAC.mjs';
|
|
3
|
-
import { parsedTypeOf, NarsilError, ErrorCodes, isLatitude, MAX_LATITUDE_DEGREES, isLongitude, MAX_LONGITUDE_DEGREES, MIN_POLYGON_POINTS, createNarsilError, withUnpairedSurrogatesReplaced, tokenizeOptions, getNestedValue, isPlainObject, MAX_NESTING_DEPTH, loadMessagePack, validateSchema, requireCreatableSchema, validateVectorPromotion, validateVectorStorage, validateTextStorage, extractVectorFieldsFromSchema, loadedMessagePack, flattenSchema, vectorDimensionOf, isSingleStringFieldType, schemaFieldsOf, partialFieldsOf, MIN_PATTERN_VALUE_LIMIT, MAX_PATTERN_VALUE_LIMIT, isStringValuedBase, compareCodePoints, isWordIndexedFieldType, messagePackUpperBoundBytes, toComparableSortValue, exceedsCodePoints, SORT_VALUE_MAX_CODE_POINTS, PROTOTYPE_POLLUTION_KEYS, sortModeOf, defaultSortMode, validateDocument, validateDocumentStrict, textFieldsChanged, getFlatSchema, getOrCreateFieldNameIndex, isWordIndexedBase, holdsUnpairedSurrogate, validateRequiredFields, requireDocumentWithinSizeLimit, isNarsilError, PLACEMENT_ROOM_REQUESTS, NEAREST_LINK_FALLBACK_HOSTS, MIN_M, MAX_M, MAX_LAYER_CAP, MAX_FILE_BYTES, INITIAL_UPPER_SLOTS, INITIAL_LIST_CAPACITY, FARTHEST_REJECTED_LINKS_KEPT, EARLIER_RELEASE_MIN_M, DEFAULT_EF_SEARCH, CONNECT_STEPS_BETWEEN_CLOCK_CHECKS, CONNECT_RESTARTS_BEFORE_ONE_PASS, COMPACTION_TOMBSTONE_RATIO, COMPACTION_ABSOLUTE_THRESHOLD, requireValidFieldTypes, parseVectorDimension, isStorageMode, isQuantizationMode, VALID_HNSW_METRICS, MAX_DOCUMENT_NESTING_DEPTH, NATIVE_CRC32_MIN_BYTES, CHECKSUM_YIELD_CHUNK_BYTES, raiseEarlierReleaseGraphSetting, MAX_DOCUMENT_ENCODING_DEPTH, DOCUMENT_REPLY_ENVELOPE_DEPTH, DOCUMENT_ENCODER_RETAINED_BUFFER_BYTES, BYTE_ORDER_MARK_WALK_BYTES_PER_HEADER, withSortableOption, VECTOR_PATTERN, isListBase, isGeopointOrVectorType, MAX_COVERING_CELLS, LOCATION_CODE_BITS_PER_AXIS, LOCATION_CELLS_PER_AXIS, FULL_TURN_DEGREES, EARTH_RADIUS_METERS, DEG_TO_RAD, ANTIMERIDIAN_SPAN_DEGREES, truncateSortString, SORT_MODES, isSortMode, codePointCount } from './chunk-
|
|
3
|
+
import { parsedTypeOf, NarsilError, ErrorCodes, isLatitude, MAX_LATITUDE_DEGREES, isLongitude, MAX_LONGITUDE_DEGREES, MIN_POLYGON_POINTS, createNarsilError, withUnpairedSurrogatesReplaced, tokenizeOptions, getNestedValue, isPlainObject, MAX_NESTING_DEPTH, loadMessagePack, validateSchema, requireCreatableSchema, validateVectorPromotion, validateVectorStorage, validateTextStorage, extractVectorFieldsFromSchema, loadedMessagePack, flattenSchema, vectorDimensionOf, isSingleStringFieldType, schemaFieldsOf, partialFieldsOf, MIN_PATTERN_VALUE_LIMIT, MAX_PATTERN_VALUE_LIMIT, isStringValuedBase, compareCodePoints, isWordIndexedFieldType, messagePackUpperBoundBytes, toComparableSortValue, exceedsCodePoints, SORT_VALUE_MAX_CODE_POINTS, PROTOTYPE_POLLUTION_KEYS, sortModeOf, defaultSortMode, validateDocument, validateDocumentStrict, textFieldsChanged, getFlatSchema, getOrCreateFieldNameIndex, isWordIndexedBase, holdsUnpairedSurrogate, validateRequiredFields, requireDocumentWithinSizeLimit, isNarsilError, PLACEMENT_ROOM_REQUESTS, NEAREST_LINK_FALLBACK_HOSTS, MIN_M, MAX_M, MAX_LAYER_CAP, MAX_FILE_BYTES, INITIAL_UPPER_SLOTS, INITIAL_LIST_CAPACITY, FARTHEST_REJECTED_LINKS_KEPT, EARLIER_RELEASE_MIN_M, DEFAULT_EF_SEARCH, CONNECT_STEPS_BETWEEN_CLOCK_CHECKS, CONNECT_RESTARTS_BEFORE_ONE_PASS, COMPACTION_TOMBSTONE_RATIO, COMPACTION_ABSOLUTE_THRESHOLD, requireValidFieldTypes, parseVectorDimension, isStorageMode, isQuantizationMode, VALID_HNSW_METRICS, MAX_DOCUMENT_NESTING_DEPTH, NATIVE_CRC32_MIN_BYTES, CHECKSUM_YIELD_CHUNK_BYTES, raiseEarlierReleaseGraphSetting, MAX_DOCUMENT_ENCODING_DEPTH, DOCUMENT_REPLY_ENVELOPE_DEPTH, DOCUMENT_ENCODER_RETAINED_BUFFER_BYTES, BYTE_ORDER_MARK_WALK_BYTES_PER_HEADER, withSortableOption, VECTOR_PATTERN, isListBase, isGeopointOrVectorType, MAX_COVERING_CELLS, LOCATION_CODE_BITS_PER_AXIS, LOCATION_CELLS_PER_AXIS, FULL_TURN_DEGREES, EARTH_RADIUS_METERS, DEG_TO_RAD, ANTIMERIDIAN_SPAN_DEGREES, truncateSortString, SORT_MODES, isSortMode, codePointCount } from './chunk-WRRXR57N.mjs';
|
|
4
4
|
|
|
5
5
|
// src/analysis/registry.ts
|
|
6
6
|
var tokenizers = /* @__PURE__ */ new Map();
|
|
@@ -12387,7 +12387,7 @@ var loadSegmentCodec = segmentCodec.load;
|
|
|
12387
12387
|
|
|
12388
12388
|
// src/engine/optional-writes-code.ts
|
|
12389
12389
|
var optionalWrites = codeLoader(async () => {
|
|
12390
|
-
const [segmentCodec2, code7] = await Promise.all([loadSegmentCodec(), import('./optional-writes-
|
|
12390
|
+
const [segmentCodec2, code7] = await Promise.all([loadSegmentCodec(), import('./optional-writes-HVPPDHSY.mjs')]);
|
|
12391
12391
|
code7.bindOptionalWritesHost(optionalCodeHost(), segmentCodec2);
|
|
12392
12392
|
return code7;
|
|
12393
12393
|
}, "write");
|
|
@@ -19206,7 +19206,7 @@ var storageCode = codeLoader(async () => {
|
|
|
19206
19206
|
loadSegmentMerge(),
|
|
19207
19207
|
loadSuggestionStore(),
|
|
19208
19208
|
loadVectorCore(),
|
|
19209
|
-
import('./storage-leaf-
|
|
19209
|
+
import('./storage-leaf-42IZEOJJ.mjs')
|
|
19210
19210
|
]);
|
|
19211
19211
|
code7.bindStorageHost(optionalCodeHost(), digest2, msgpack, segmentCodec2, segmentMerge2, suggestionStore2, vectorCore2);
|
|
19212
19212
|
return code7;
|
|
@@ -19955,7 +19955,7 @@ var loaded2 = null;
|
|
|
19955
19955
|
var loading3 = null;
|
|
19956
19956
|
function importOptionalReads() {
|
|
19957
19957
|
if (loaded2 !== null) return Promise.resolve(loaded2);
|
|
19958
|
-
loading3 ??= import('./optional-reads-
|
|
19958
|
+
loading3 ??= import('./optional-reads-NQO5DKM4.mjs').then(
|
|
19959
19959
|
(code7) => {
|
|
19960
19960
|
code7.bindOptionalReadsHost(optionalCodeHost());
|
|
19961
19961
|
loaded2 = code7;
|
|
@@ -21022,7 +21022,7 @@ function createAnalysisRebuildCoordinator(config, deps) {
|
|
|
21022
21022
|
|
|
21023
21023
|
// src/engine/durability-config-code.ts
|
|
21024
21024
|
var durabilityConfig = codeLoader(
|
|
21025
|
-
() => import('./durability-config-
|
|
21025
|
+
() => import('./durability-config-UP3OTUMB.mjs').then((code7) => {
|
|
21026
21026
|
code7.bindDurabilityConfigHost(optionalCodeHost());
|
|
21027
21027
|
return code7;
|
|
21028
21028
|
}),
|
|
@@ -21620,7 +21620,7 @@ async function createEngineCore(config, hooks, capacityScope = "index") {
|
|
|
21620
21620
|
throw new NarsilError(ErrorCodes.CONFIG_INVALID, "Index lifecycle settings require durability");
|
|
21621
21621
|
}
|
|
21622
21622
|
const durabilityWiring = durabilityTier === null ? null : (await Promise.all([loadStorageCode(), loadOptionalWrites()]))[0];
|
|
21623
|
-
const filesystemDurability = durabilityTier?.kind === "wal";
|
|
21623
|
+
const filesystemDurability = durabilityTier?.kind === "wal" && durabilityTier.indexedDB === void 0;
|
|
21624
21624
|
const executor = createDirectExecutor({
|
|
21625
21625
|
vectorWorkerCopies: vectorCopyPolicy,
|
|
21626
21626
|
vectorStorage: filesystemDurability ? "disk" : "memory",
|
|
@@ -21895,8 +21895,13 @@ async function shutdownEngine(core2) {
|
|
|
21895
21895
|
await core2.analysisRebuild.shutdown();
|
|
21896
21896
|
await core2.querySuggestionHooks?.shutdown();
|
|
21897
21897
|
core2.indexState.dispose();
|
|
21898
|
+
let durabilityFailure = null;
|
|
21898
21899
|
if (durability) {
|
|
21899
|
-
|
|
21900
|
+
try {
|
|
21901
|
+
await durability.manager.shutdown();
|
|
21902
|
+
} catch (error) {
|
|
21903
|
+
durabilityFailure = { error };
|
|
21904
|
+
}
|
|
21900
21905
|
}
|
|
21901
21906
|
const vectorDisposals = [];
|
|
21902
21907
|
for (const [name] of indexRegistry) {
|
|
@@ -21930,6 +21935,7 @@ async function shutdownEngine(core2) {
|
|
|
21930
21935
|
await Promise.all(vectorDisposals);
|
|
21931
21936
|
eventHandlers.clear();
|
|
21932
21937
|
indexRegistry.clear();
|
|
21938
|
+
if (durabilityFailure !== null) throw durabilityFailure.error;
|
|
21933
21939
|
}
|
|
21934
21940
|
|
|
21935
21941
|
// src/engine/startup-checks.ts
|
|
@@ -1203,7 +1203,7 @@ var loaded = null;
|
|
|
1203
1203
|
var loading = null;
|
|
1204
1204
|
function loadMessagePack() {
|
|
1205
1205
|
if (loaded !== null) return Promise.resolve(loaded);
|
|
1206
|
-
loading ??= import('./msgpack-leaf-
|
|
1206
|
+
loading ??= import('./msgpack-leaf-FEPCLXXY.mjs').then(
|
|
1207
1207
|
(code) => {
|
|
1208
1208
|
code.bindMsgpackHost({
|
|
1209
1209
|
BYTE_ORDER_MARK_WALK_BYTES_PER_HEADER,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NarsilError, ErrorCodes, requireLoadedMessagePack, getNestedValue, parsedTypeOf } from './chunk-
|
|
1
|
+
import { NarsilError, ErrorCodes, requireLoadedMessagePack, getNestedValue, parsedTypeOf } from './chunk-WRRXR57N.mjs';
|
|
2
2
|
|
|
3
3
|
// src/core/stored-values/build.ts
|
|
4
4
|
var ORDINAL_LIMIT = 4294967295;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NarsilError, ErrorCodes, loadMessagePack, ClientErrorCodes, ServerErrorCodes, describeError } from './chunk-
|
|
1
|
+
import { NarsilError, ErrorCodes, loadMessagePack, ClientErrorCodes, ServerErrorCodes, describeError } from './chunk-WRRXR57N.mjs';
|
|
2
2
|
|
|
3
3
|
// src/json-encoding.ts
|
|
4
4
|
function toPlainNumbers(key, value) {
|
|
@@ -56,11 +56,37 @@ function filesystemBackedDirectory(config) {
|
|
|
56
56
|
}
|
|
57
57
|
return null;
|
|
58
58
|
}
|
|
59
|
+
function indexedDBLocationOf(config) {
|
|
60
|
+
const location = config.persistence?.indexedDB;
|
|
61
|
+
if (location === void 0) return null;
|
|
62
|
+
const { databaseName, storeName } = location;
|
|
63
|
+
if (typeof databaseName !== "string" || databaseName.length === 0) {
|
|
64
|
+
throw configError("persistence.indexedDB.databaseName must be a non-empty string");
|
|
65
|
+
}
|
|
66
|
+
if (typeof storeName !== "string" || storeName.length === 0) {
|
|
67
|
+
throw configError("persistence.indexedDB.storeName must be a non-empty string");
|
|
68
|
+
}
|
|
69
|
+
return { databaseName, storeName };
|
|
70
|
+
}
|
|
71
|
+
function requireNoLogFieldsOnSharedStore(durability) {
|
|
72
|
+
for (const field of WAL_ONLY_FIELDS) {
|
|
73
|
+
if (durability?.[field] !== void 0) {
|
|
74
|
+
throw configError(
|
|
75
|
+
`durability.${field} applies to the write-ahead log, which an IndexedDB store that an invalidation adapter shares between tabs cannot keep. Remove durability.${field}, or remove the invalidation adapter`
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
59
80
|
function resolveDurabilityTier(config) {
|
|
60
81
|
const filesystemDirectory = filesystemBackedDirectory(config);
|
|
82
|
+
const indexedDB = filesystemDirectory === null ? indexedDBLocationOf(config) : null;
|
|
61
83
|
if (config.durability) {
|
|
62
84
|
requireValidDurabilityConfig(config.durability);
|
|
63
85
|
}
|
|
86
|
+
if (indexedDB !== null && config.persistence !== void 0 && config.invalidation !== void 0 && config.durability?.tier === void 0) {
|
|
87
|
+
requireNoLogFieldsOnSharedStore(config.durability);
|
|
88
|
+
return { kind: "snapshot", config: { ...config.durability }, adapter: config.persistence };
|
|
89
|
+
}
|
|
64
90
|
if (config.durability?.tier === "snapshot") {
|
|
65
91
|
if (config.persistence === void 0) {
|
|
66
92
|
throw configError(
|
|
@@ -76,13 +102,16 @@ function resolveDurabilityTier(config) {
|
|
|
76
102
|
if (filesystemDirectory !== null) {
|
|
77
103
|
return { kind: "wal", config: { ...config.durability, directory: filesystemDirectory } };
|
|
78
104
|
}
|
|
105
|
+
if (indexedDB !== null) {
|
|
106
|
+
return { kind: "wal", config: { ...config.durability }, indexedDB };
|
|
107
|
+
}
|
|
79
108
|
if (config.persistence !== void 0) {
|
|
80
109
|
throw configError(
|
|
81
|
-
|
|
110
|
+
'WAL durability requires a filesystem directory or the IndexedDB persistence adapter, and the configured persistence adapter is neither. Use one of those adapters, set durability.directory, or set durability.tier to "snapshot"'
|
|
82
111
|
);
|
|
83
112
|
}
|
|
84
113
|
throw configError(
|
|
85
|
-
"Durability requires a directory. Set durability.directory explicitly, or configure a filesystem persistence adapter"
|
|
114
|
+
"Durability requires a directory. Set durability.directory explicitly, or configure a filesystem or IndexedDB persistence adapter"
|
|
86
115
|
);
|
|
87
116
|
}
|
|
88
117
|
if (config.persistence === void 0) {
|
|
@@ -91,6 +120,9 @@ function resolveDurabilityTier(config) {
|
|
|
91
120
|
if (filesystemDirectory !== null) {
|
|
92
121
|
return { kind: "wal", config: { directory: filesystemDirectory } };
|
|
93
122
|
}
|
|
123
|
+
if (indexedDB !== null) {
|
|
124
|
+
return { kind: "wal", config: {}, indexedDB };
|
|
125
|
+
}
|
|
94
126
|
return { kind: "snapshot", config: {}, adapter: config.persistence };
|
|
95
127
|
}
|
|
96
128
|
|
|
@@ -244,6 +244,12 @@ function decode(bytes) {
|
|
|
244
244
|
sharedDecoder ??= new Decoder();
|
|
245
245
|
return sharedDecoder.decode(bytes);
|
|
246
246
|
}
|
|
247
|
+
function decodeBoundedMessage(bytes) {
|
|
248
|
+
if (scanStrings(bytes, 0, null, Number.POSITIVE_INFINITY) === null) {
|
|
249
|
+
throw new RangeError("Invalid MessagePack value header");
|
|
250
|
+
}
|
|
251
|
+
return decode(bytes);
|
|
252
|
+
}
|
|
247
253
|
function decodeMulti(bytes) {
|
|
248
254
|
return new Decoder().decodeMulti(bytes);
|
|
249
255
|
}
|
|
@@ -299,4 +305,4 @@ function restoreVectorFields(document, vectorFieldPaths) {
|
|
|
299
305
|
}
|
|
300
306
|
}
|
|
301
307
|
|
|
302
|
-
export { Decoder, MAP_TAGS, bindMsgpackHost, decode, decodeMulti, encodeDocument, headerAt, restoreVectorFields, setNestedValue };
|
|
308
|
+
export { Decoder, MAP_TAGS, bindMsgpackHost, decode, decodeBoundedMessage, decodeMulti, encodeDocument, headerAt, restoreVectorFields, setNestedValue };
|
|
@@ -1619,8 +1619,11 @@ function hitsKeptPerGroup(maxPerGroup) {
|
|
|
1619
1619
|
return Math.floor(maxPerGroup);
|
|
1620
1620
|
}
|
|
1621
1621
|
function applyGrouping(hits, group, documents) {
|
|
1622
|
+
const keptPerGroup = hitsKeptPerGroup(group.maxPerGroup);
|
|
1623
|
+
const limit = group.limit !== void 0 && Number.isFinite(group.limit) && group.limit >= 0 ? Math.min(Math.floor(group.limit), hits.length) : null;
|
|
1622
1624
|
if (!group.fields || group.fields.length === 0) {
|
|
1623
|
-
|
|
1625
|
+
if (hits.length === 0 || limit === 0) return [];
|
|
1626
|
+
return [reducedGroup({ values: {}, hits: hits.slice(0, keptPerGroup) }, group, hits, documents)];
|
|
1624
1627
|
}
|
|
1625
1628
|
if (hits.length > 4294967295)
|
|
1626
1629
|
throw new NarsilError(ErrorCodes.CONFIG_INVALID, "The hit count exceeds the group layout");
|
|
@@ -1638,8 +1641,6 @@ function applyGrouping(hits, group, documents) {
|
|
|
1638
1641
|
if (at > 0 && hits[order[at - 1]].id !== hits[order[at]].id) rank++;
|
|
1639
1642
|
idRanks[order[at]] = rank;
|
|
1640
1643
|
}
|
|
1641
|
-
const keptPerGroup = hitsKeptPerGroup(group.maxPerGroup);
|
|
1642
|
-
const limit = group.limit !== void 0 && Number.isFinite(group.limit) && group.limit >= 0 ? Math.min(Math.floor(group.limit), hits.length) : null;
|
|
1643
1644
|
const heads = new Uint32Array(hits.length);
|
|
1644
1645
|
const offsets = new Uint32Array(hits.length + 1);
|
|
1645
1646
|
const positions = new Uint32Array(hits.length);
|
|
@@ -1664,23 +1665,24 @@ function applyGrouping(hits, group, documents) {
|
|
|
1664
1665
|
for (let field = 0; field < group.fields.length; field++) values[group.fields[field]] = row?.[field] ?? null;
|
|
1665
1666
|
const everyHit = [];
|
|
1666
1667
|
for (let member = offsets[at]; member < offsets[at + 1]; member++) everyHit.push(hits[positions[member]]);
|
|
1667
|
-
|
|
1668
|
-
if (group.reduce) {
|
|
1669
|
-
const folded = foldGroupReducer(
|
|
1670
|
-
group.reduce,
|
|
1671
|
-
everyHit.map((hit) => ({ document: documents.document(hit.id), score: hit.score ?? 0 }))
|
|
1672
|
-
);
|
|
1673
|
-
if (folded.reducerError !== void 0) {
|
|
1674
|
-
result.reducerError = folded.reducerError;
|
|
1675
|
-
} else {
|
|
1676
|
-
result.reduced = folded.reduced;
|
|
1677
|
-
}
|
|
1678
|
-
}
|
|
1679
|
-
groups.push(result);
|
|
1668
|
+
groups.push(reducedGroup({ values, hits: everyHit.slice(0, keptPerGroup) }, group, everyHit, documents));
|
|
1680
1669
|
}
|
|
1681
1670
|
if (limit !== null && groups.length > limit) groups.length = limit;
|
|
1682
1671
|
return groups;
|
|
1683
1672
|
}
|
|
1673
|
+
function reducedGroup(result, group, everyHit, documents) {
|
|
1674
|
+
if (!group.reduce) return result;
|
|
1675
|
+
const folded = foldGroupReducer(
|
|
1676
|
+
group.reduce,
|
|
1677
|
+
everyHit.map((hit) => ({ document: documents.document(hit.id), score: hit.score ?? 0 }))
|
|
1678
|
+
);
|
|
1679
|
+
if (folded.reducerError !== void 0) {
|
|
1680
|
+
result.reducerError = folded.reducerError;
|
|
1681
|
+
} else {
|
|
1682
|
+
result.reduced = folded.reduced;
|
|
1683
|
+
}
|
|
1684
|
+
return result;
|
|
1685
|
+
}
|
|
1684
1686
|
function foldGroupReducer(reduce, rows) {
|
|
1685
1687
|
try {
|
|
1686
1688
|
let accumulator = reduce.initialValue();
|