@delali/narsil 0.2.2 → 0.2.3-next.32

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 (66) hide show
  1. package/README.md +12 -9
  2. package/dist/adapters/filesystem.d.ts +1 -1
  3. package/dist/adapters/filesystem.mjs +1 -1
  4. package/dist/adapters/indexeddb.d.ts +1 -1
  5. package/dist/adapters/indexeddb.mjs +1 -1
  6. package/dist/adapters/memory.d.ts +1 -1
  7. package/dist/{adapters-CVqI5NBt.d.ts → adapters-79OIa4xm.d.ts} +1 -1
  8. package/dist/brute-force-DbHYCTc3.d.ts +8 -0
  9. package/dist/chunk-BFIH7OV5.mjs +185 -0
  10. package/dist/chunk-C6VVLMRX.mjs +63 -0
  11. package/dist/{chunk-UNJZ7ZDB.mjs → chunk-EMI63EXP.mjs} +33 -2
  12. package/dist/chunk-MFFAJ2NR.mjs +135 -0
  13. package/dist/chunk-OBXS7OZM.mjs +376 -0
  14. package/dist/{chunk-ASI6AOW2.mjs → chunk-RO4EFWE6.mjs} +7833 -3524
  15. package/dist/{chunk-WLR5BFL3.mjs → chunk-TEAJO7CU.mjs} +3067 -2087
  16. package/dist/{chunk-S7RJJMHI.mjs → chunk-WDL632CN.mjs} +699 -222
  17. package/dist/{chunk-BKAI2WXI.mjs → chunk-WTONLDU3.mjs} +5 -0
  18. package/dist/client-DQHB_swQ.d.ts +793 -0
  19. package/dist/client.d.ts +6 -0
  20. package/dist/client.mjs +843 -0
  21. package/dist/{config-DXypXAfN.d.ts → config-ChZ7lfqc.d.ts} +3 -3
  22. package/dist/direct-executor-YARCDMJF.mjs +8 -0
  23. package/dist/distribution/coordinator/etcd.d.ts +3 -3
  24. package/dist/distribution/coordinator/etcd.mjs +471 -2
  25. package/dist/distribution/coordinator/in-memory.d.ts +3 -3
  26. package/dist/distribution/coordinator/in-memory.mjs +286 -1
  27. package/dist/distribution/transport/grpc.d.ts +45 -0
  28. package/dist/distribution/transport/grpc.mjs +586 -0
  29. package/dist/distribution/transport/in-memory.d.ts +118 -0
  30. package/dist/distribution/transport/in-memory.mjs +214 -0
  31. package/dist/distribution/transport/tcp.d.ts +27 -0
  32. package/dist/distribution/transport/tcp.mjs +595 -0
  33. package/dist/distribution.d.ts +241 -192
  34. package/dist/distribution.mjs +6620 -4795
  35. package/dist/embeddings/openai.d.ts +1 -1
  36. package/dist/embeddings/openai.mjs +1 -1
  37. package/dist/{engine-CO9Wnfie.d.ts → engine-DScGlT2Z.d.ts} +30 -3
  38. package/dist/index.browser.mjs +10035 -3914
  39. package/dist/index.d.ts +8 -8
  40. package/dist/index.mjs +8 -5
  41. package/dist/invalidation/broadcast-channel.d.ts +1 -1
  42. package/dist/invalidation/filesystem.d.ts +1 -1
  43. package/dist/invalidation/filesystem.mjs +3 -1
  44. package/dist/invalidation/noop.d.ts +1 -1
  45. package/dist/options-BORJg5XB.d.ts +234 -0
  46. package/dist/persistence/durability/checkpoint-worker.d.ts +4 -2
  47. package/dist/persistence/durability/checkpoint-worker.mjs +8 -5
  48. package/dist/react.d.ts +340 -0
  49. package/dist/react.mjs +687 -0
  50. package/dist/{schema-CE6S_aAr.d.ts → schema-emTQfEiX.d.ts} +21 -7
  51. package/dist/{search-DLBtiPdQ.d.ts → search-CQ-9bKxo.d.ts} +226 -14
  52. package/dist/server.d.ts +42 -356
  53. package/dist/server.mjs +493 -106
  54. package/dist/tasks-CnMLpfk-.d.ts +274 -0
  55. package/dist/types-BQDlIvfS.d.ts +34 -0
  56. package/dist/{types-BV3nAKTL.d.ts → types-Bfhhnh3G.d.ts} +23 -1
  57. package/dist/types-D5OwhtsQ.d.ts +97 -0
  58. package/dist/vector/hnsw-build-worker.d.ts +2 -7
  59. package/dist/vector/hnsw-build-worker.mjs +2 -1
  60. package/dist/vector/search-worker.d.ts +373 -0
  61. package/dist/vector/search-worker.mjs +279 -0
  62. package/dist/workers/entry.mjs +43 -25
  63. package/package.json +42 -2
  64. package/dist/chunk-FKK76OR7.mjs +0 -456
  65. package/dist/chunk-RQLXC2YS.mjs +0 -269
  66. package/dist/direct-executor-3W4QRA4E.mjs +0 -5
@@ -0,0 +1,340 @@
1
+ import { N as NarsilError, L as ListParams, g as ListResult, I as IndexInfo, f as IndexStats, Q as QueryParams, h as PreflightResult, e as QueryResult, i as SuggestParams, j as SuggestResult } from './search-CQ-9bKxo.js';
2
+ export { C as ClientErrorCode, a as ClientErrorCodes, E as ErrorCode, b as ErrorCodes, c as NarsilErrorCode, S as ServerErrorCode, d as ServerErrorCodes } from './search-CQ-9bKxo.js';
3
+ import { e as TaskRecord, d as TaskProgress, b as ImportResult, c as TaskListQuery, T as TaskListPage } from './tasks-CnMLpfk-.js';
4
+ export { I as ImportError, f as TaskStatus, g as TaskType } from './tasks-CnMLpfk-.js';
5
+ import { ReactNode, ReactElement } from 'react';
6
+ import { N as NarsilClient, I as ImportSource } from './client-DQHB_swQ.js';
7
+ import { A as AnyDocument } from './schema-emTQfEiX.js';
8
+ import './adapters-79OIa4xm.js';
9
+
10
+ /**
11
+ * These are the settings {@link NarsilProvider} takes.
12
+ *
13
+ * @public
14
+ */
15
+ interface NarsilProviderProps {
16
+ /** Every hook under the provider sends through this client. Build it once,
17
+ * outside the component tree, because a client built during a render would
18
+ * throw away everything the hooks under it hold. */
19
+ client: NarsilClient;
20
+ /** The hooks keep an answer for this many milliseconds after the last
21
+ * component reading it has gone, and 2000 unless you say otherwise. The wait
22
+ * covers the gap between React unmounting a component and mounting it again,
23
+ * so a quick navigation back shows what it showed before and sends no second
24
+ * request. */
25
+ keepAliveMs?: number;
26
+ /** These are the components the provider covers. */
27
+ children?: ReactNode;
28
+ }
29
+ /**
30
+ * Gives every hook below it the client to send through, and the shared state
31
+ * they read.
32
+ *
33
+ * Two components asking for the same thing under one provider send one request
34
+ * and read one answer. The provider drops that state once it unmounts, and it
35
+ * stops whatever is still in flight.
36
+ *
37
+ * @param props - These name the client and the components the provider covers.
38
+ * @returns The provider renders its children unchanged.
39
+ *
40
+ * @public
41
+ */
42
+ declare function NarsilProvider(props: NarsilProviderProps): ReactElement;
43
+ /**
44
+ * Reads the client the nearest {@link NarsilProvider} holds, which is what any
45
+ * call the hooks leave out goes through.
46
+ *
47
+ * @returns This is the client the provider was given.
48
+ * @throws A `NarsilError` with `CONFIG_INVALID` when no provider stands above
49
+ * the component.
50
+ *
51
+ * @public
52
+ */
53
+ declare function useNarsilClient(): NarsilClient;
54
+
55
+ /**
56
+ * What every hook sends with each request it makes.
57
+ *
58
+ * A hook owns the lifetime of its own request, so it takes no signal. The store
59
+ * behind it stops a request the moment nothing reads the answer.
60
+ *
61
+ * @public
62
+ */
63
+ interface NarsilRequestSettings {
64
+ /** The hook sends these headers with its request. */
65
+ headers?: Record<string, string>;
66
+ /** The hook gives the server this many milliseconds to answer, and 0 waits
67
+ * for as long as the server takes. */
68
+ timeoutMs?: number;
69
+ }
70
+ /**
71
+ * These settings change what a read hook does, and every read hook takes them
72
+ * as its last argument.
73
+ *
74
+ * @public
75
+ */
76
+ interface NarsilReadOptions extends NarsilRequestSettings {
77
+ /** The hook sends nothing while this is false, and it reports no data and no
78
+ * failure, which is how a search waits for a term. */
79
+ enabled?: boolean;
80
+ /** The hook keeps showing the last answer while the next one loads, which
81
+ * holds a result list steady as somebody types. */
82
+ keepPreviousData?: boolean;
83
+ /** The hook asks again this often, in milliseconds, and it pauses while the
84
+ * page is hidden. It asks once and stops unless you set this. */
85
+ refreshIntervalMs?: number;
86
+ }
87
+ /**
88
+ * What a read hook reports.
89
+ *
90
+ * `isLoading` covers the wait for the first answer, so a spinner branches on
91
+ * it, while `isFetching` covers every request including a refresh, so a quieter
92
+ * indicator branches on that one.
93
+ *
94
+ * @typeParam T - This is what the underlying client method answers with.
95
+ *
96
+ * @public
97
+ */
98
+ interface NarsilReadState<T> {
99
+ /** This is the answer, and it stays undefined until the first one arrives. */
100
+ data: T | undefined;
101
+ /** This is the failure the last request ended on, and the next success clears it. */
102
+ error: NarsilError | undefined;
103
+ /** This is true while the hook waits for an answer and has none to show. */
104
+ isLoading: boolean;
105
+ /** This is true while a request is in flight, including a refresh. */
106
+ isFetching: boolean;
107
+ /** Calling this asks the server again, keeping the answer already on screen
108
+ * until the new one arrives. */
109
+ refresh: () => void;
110
+ }
111
+
112
+ /**
113
+ * Reads one stored document, and reads it again whenever the id changes.
114
+ *
115
+ * A document the index does not hold comes back as `data: undefined` with no
116
+ * failure, so read `isLoading` to tell an empty answer from one still on its
117
+ * way. Passing no id switches the hook off, which is what a detail panel does
118
+ * until somebody picks a row.
119
+ *
120
+ * @param indexName - This names the index holding the document.
121
+ * @param docId - This names the document to read, and a nullish or empty id
122
+ * switches the hook off.
123
+ * @param options - These switch the hook off, keep the last document on screen,
124
+ * and set the refresh interval, the headers, and the deadline.
125
+ * @returns The state holds the document, the failure, the loading flags, and
126
+ * the way to read it again.
127
+ *
128
+ * @public
129
+ */
130
+ declare function useDocument(indexName: string, docId: string | null | undefined, options?: NarsilReadOptions): NarsilReadState<AnyDocument | undefined>;
131
+ /**
132
+ * Pages through the stored documents without searching, which is what a table
133
+ * of everything an index holds reads.
134
+ *
135
+ * @typeParam T - This is the shape of the stored documents.
136
+ * @param indexName - This names the index to page through.
137
+ * @param params - These set the page size, the cursor, and any filter, sort, or
138
+ * projection.
139
+ * @param options - These switch the hook off, keep the last page on screen, and
140
+ * set the refresh interval, the headers, and the deadline.
141
+ * @returns The state holds the page and the cursor that reaches the next one.
142
+ *
143
+ * @public
144
+ */
145
+ declare function useDocuments<T = AnyDocument>(indexName: string, params?: ListParams, options?: NarsilReadOptions): NarsilReadState<ListResult<T>>;
146
+
147
+ /**
148
+ * These settings say how {@link useImport} runs a load and follows it.
149
+ *
150
+ * @public
151
+ */
152
+ interface NarsilImportOptions extends NarsilRequestSettings {
153
+ /** The hook asks the server how far the load has gone this often, and every
154
+ * 250 ms unless you say otherwise, which is how often the server writes the
155
+ * figures. It leaves five seconds between attempts while the server is
156
+ * failing. */
157
+ pollIntervalMs?: number;
158
+ /** The hook calls this once the load reaches a final status, whichever status
159
+ * that is. */
160
+ onSettled?: (record: TaskRecord) => void;
161
+ }
162
+ /**
163
+ * What {@link useImport} reports, and what it offers to call.
164
+ *
165
+ * @public
166
+ */
167
+ interface NarsilImportState {
168
+ /**
169
+ * Sends a corpus and returns once the server has read the body and taken the
170
+ * work on. The server loads the documents afterwards, and this hook follows
171
+ * that work.
172
+ *
173
+ * @param source - These are the documents, or the NDJSON you already hold.
174
+ * @returns The record is the task the server started.
175
+ * @throws A `NarsilError` under the code the server sent, and with
176
+ * `NOT_FOUND` where the server predates the asynchronous import.
177
+ */
178
+ start: (source: ImportSource) => Promise<TaskRecord>;
179
+ /** Asks the running load to stop. Calling it while the corpus is still going
180
+ * up stops the upload, and calling it afterwards asks the server to stop the
181
+ * task, which stops between batches, so whatever it had already written stays
182
+ * written. */
183
+ cancel: () => void;
184
+ /** Clears the record and the failure, ready for another load. */
185
+ reset: () => void;
186
+ /** This is the task, from the moment the server takes the load on. */
187
+ task: TaskRecord | undefined;
188
+ /** This is how far the load has gone, which a progress bar reads. */
189
+ progress: TaskProgress | undefined;
190
+ /** This counts what the server accepted and refused, and it arrives once the
191
+ * load finishes. */
192
+ result: ImportResult | undefined;
193
+ /** This is the failure that stopped the load, or the one the last poll ended
194
+ * on. */
195
+ error: NarsilError | undefined;
196
+ /** This is true from the moment you call `start` until the load reaches a
197
+ * final status. */
198
+ isImporting: boolean;
199
+ }
200
+ /**
201
+ * Loads a corpus into an index and reports how far the load has gone.
202
+ *
203
+ * The hook starts the load as a task, so the request returns as soon as the
204
+ * server has read the body. A corpus that would outlast a proxy's response
205
+ * timeout therefore still loads. The hook then polls the task, pausing while
206
+ * the page is hidden, until the load succeeds, fails, or is cancelled.
207
+ *
208
+ * Unmounting the component stops the polling alone, because the server finishes
209
+ * the load either way. Follow it again with {@link useTask}, under the id of the
210
+ * record `start` returned.
211
+ *
212
+ * @param indexName - This names the index that receives the corpus.
213
+ * @param options - These set the poll interval, the callback for the final
214
+ * record, the headers, and the deadline.
215
+ * @returns The state holds the task, the progress, the result, the failure, and
216
+ * the three methods that drive a load.
217
+ *
218
+ * @public
219
+ */
220
+ declare function useImport(indexName: string, options?: NarsilImportOptions): NarsilImportState;
221
+
222
+ /**
223
+ * Lists every index the server holds, with its size and its language.
224
+ *
225
+ * @param options - These switch the hook off, keep the last list on screen, and
226
+ * set the refresh interval, the headers, and the deadline.
227
+ * @returns The state holds the indexes in creation order.
228
+ *
229
+ * @public
230
+ */
231
+ declare function useIndexes(options?: NarsilReadOptions): NarsilReadState<IndexInfo[]>;
232
+ /**
233
+ * Reads one index's document count, partition count, memory estimate, language,
234
+ * and schema.
235
+ *
236
+ * Set `refreshIntervalMs` to watch the figures move while a load runs.
237
+ *
238
+ * @param indexName - This names the index to describe.
239
+ * @param options - These switch the hook off, keep the last figures on screen,
240
+ * and set the refresh interval, the headers, and the deadline.
241
+ * @returns The state holds the figures as they stood when the server answered.
242
+ *
243
+ * @public
244
+ */
245
+ declare function useStats(indexName: string, options?: NarsilReadOptions): NarsilReadState<IndexStats>;
246
+
247
+ /**
248
+ * Searches an index and re-runs the search whenever the parameters change.
249
+ *
250
+ * The parameters are the ones {@link SearchOperations.query} takes, and the
251
+ * answer is the same `QueryResult`. Set `keepPreviousData` for a
252
+ * search-as-you-type box, so that the hits already on screen stay there while
253
+ * the next answer loads.
254
+ *
255
+ * @typeParam T - This is the shape of the stored documents, which flows through
256
+ * to each hit's `document`.
257
+ * @param indexName - This names the index to search.
258
+ * @param params - These carry the text, the filters, the sort, and everything
259
+ * else the search asks for.
260
+ * @param options - These switch the hook off, keep the last answer on screen,
261
+ * and set the refresh interval, the headers, and the deadline.
262
+ * @returns The state holds the result, the failure, the loading flags, and the
263
+ * way to search again.
264
+ *
265
+ * @public
266
+ */
267
+ declare function useQuery<T = AnyDocument>(indexName: string, params: QueryParams, options?: NarsilReadOptions): NarsilReadState<QueryResult<T>>;
268
+ /**
269
+ * Counts what a search would match, without building or ranking a single hit,
270
+ * which is what a result count beside a filter reads.
271
+ *
272
+ * @param indexName - This names the index to count in.
273
+ * @param params - These are the parameters {@link useQuery} takes.
274
+ * @param options - These switch the hook off, keep the last answer, and set the
275
+ * refresh interval, the headers, and the deadline.
276
+ * @returns The state holds the match count and how long the count took.
277
+ *
278
+ * @public
279
+ */
280
+ declare function usePreflight(indexName: string, params: QueryParams, options?: NarsilReadOptions): NarsilReadState<PreflightResult>;
281
+ /**
282
+ * Completes a prefix from the terms an index holds, ready to offer under a
283
+ * search box.
284
+ *
285
+ * @param indexName - This names the index to complete from.
286
+ * @param params - These set the prefix and how many completions come back.
287
+ * @param options - These switch the hook off, keep the last completions on
288
+ * screen, and set the refresh interval, the headers, and the deadline.
289
+ * @returns The state holds the completions, most widely used first.
290
+ *
291
+ * @public
292
+ */
293
+ declare function useSuggest(indexName: string, params: SuggestParams, options?: NarsilReadOptions): NarsilReadState<SuggestResult>;
294
+
295
+ /**
296
+ * These settings say how a task hook follows the work.
297
+ *
298
+ * @public
299
+ */
300
+ interface NarsilTaskOptions extends NarsilReadOptions {
301
+ /** The hook asks again this often while the task runs, and every 250 ms
302
+ * unless you say otherwise, which is how often a running import writes its
303
+ * progress. It stops once the task reaches a final status. */
304
+ pollIntervalMs?: number;
305
+ }
306
+ /**
307
+ * Follows one long-running operation, and stops asking once it finishes.
308
+ *
309
+ * The hook polls while the task is queued or running, pauses while the page is
310
+ * hidden, and reads the figures once more as soon as the page comes back. A
311
+ * failed task arrives as a record carrying its `error`, because a part-finished
312
+ * import still reports what it indexed, so read the status you get.
313
+ *
314
+ * @param taskId - This names the task to follow, and a nullish or empty id
315
+ * switches the hook off.
316
+ * @param options - These set the poll interval, switch the hook off, and carry
317
+ * the headers and the deadline.
318
+ * @returns The state holds the record, and `data: null` says the server no
319
+ * longer holds it.
320
+ *
321
+ * @public
322
+ */
323
+ declare function useTask(taskId: string | null | undefined, options?: NarsilTaskOptions): NarsilReadState<TaskRecord | null>;
324
+ /**
325
+ * Lists the task records the server still holds, newest first.
326
+ *
327
+ * Set `refreshIntervalMs` to keep a table of running work up to date.
328
+ *
329
+ * @param query - This says which records to keep and where the page starts.
330
+ * Omit it for the newest 20 records.
331
+ * @param options - These switch the hook off, keep the last page on screen, and
332
+ * set the refresh interval, the headers, and the deadline.
333
+ * @returns The state holds the records, the total the filters matched, and the
334
+ * offset the next page starts at.
335
+ *
336
+ * @public
337
+ */
338
+ declare function useTasks(query?: TaskListQuery, options?: NarsilReadOptions): NarsilReadState<TaskListPage>;
339
+
340
+ export { ImportResult, NarsilError, type NarsilImportOptions, type NarsilImportState, NarsilProvider, type NarsilProviderProps, type NarsilReadOptions, type NarsilReadState, type NarsilRequestSettings, type NarsilTaskOptions, TaskListPage, TaskListQuery, TaskProgress, TaskRecord, useDocument, useDocuments, useImport, useIndexes, useNarsilClient, usePreflight, useQuery, useStats, useSuggest, useTask, useTasks };