@delali/narsil 0.3.1-next.71 → 0.3.1-next.73

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 (69) hide show
  1. package/README.md +2 -2
  2. package/dist/adapters/filesystem.mjs +1 -1
  3. package/dist/adapters/indexeddb.mjs +1 -1
  4. package/dist/{capabilities-Dt-7B4Wz.d.ts → capabilities-CYeAWYxQ.d.ts} +19 -4
  5. package/dist/{chunk-3JGWULDF.mjs → chunk-2WLD2NFW.mjs} +5 -5
  6. package/dist/{chunk-LMO5TJUS.mjs → chunk-3YKWSO54.mjs} +642 -196
  7. package/dist/{chunk-HWQLTLNG.mjs → chunk-4MQ5F4IL.mjs} +1 -1
  8. package/dist/{chunk-FVLQ63B7.mjs → chunk-AFKH4ZK3.mjs} +30 -6
  9. package/dist/{chunk-653BNMAF.mjs → chunk-AK3BLGCI.mjs} +195 -25
  10. package/dist/{chunk-IOR2K26O.mjs → chunk-CVFAFZSN.mjs} +8000 -4391
  11. package/dist/{chunk-USKFU7J5.mjs → chunk-I64LXKO3.mjs} +1 -1
  12. package/dist/{chunk-OI42GWLR.mjs → chunk-LJYTW7GT.mjs} +57 -11
  13. package/dist/{chunk-2STVUTNA.mjs → chunk-LPBWCHBE.mjs} +194 -13
  14. package/dist/{chunk-YNVIUGF5.mjs → chunk-PU43WDY4.mjs} +4 -2
  15. package/dist/{chunk-M76V3OGJ.mjs → chunk-THMSFOJO.mjs} +1289 -1405
  16. package/dist/{chunk-YJDQ7NLA.mjs → chunk-WVDFG45M.mjs} +93 -95
  17. package/dist/chunk-XW25X6AU.mjs +614 -0
  18. package/dist/chunk-ZKRV5M2P.mjs +75 -0
  19. package/dist/{chunk-P4DSQ6M4.mjs → chunk-ZULSEZCE.mjs} +68 -28
  20. package/dist/{client-COek5GXK.d.ts → client-D698E5ge.d.ts} +77 -26
  21. package/dist/client.d.ts +9 -9
  22. package/dist/client.mjs +45 -22
  23. package/dist/{config-rBpbgTw8.d.ts → config-Bv8etwUZ.d.ts} +11 -4
  24. package/dist/{config-Dfanyqqt.d.ts → config-QXU3HMpq.d.ts} +26 -2
  25. package/dist/direct-executor-5SRDFZAS.mjs +13 -0
  26. package/dist/distribution/coordinator/etcd.d.ts +29 -16
  27. package/dist/distribution/coordinator/etcd.mjs +163 -76
  28. package/dist/distribution/coordinator/in-memory.d.ts +2 -2
  29. package/dist/distribution/coordinator/in-memory.mjs +1 -1
  30. package/dist/distribution/transport/grpc.d.ts +2 -2
  31. package/dist/distribution/transport/grpc.mjs +22 -2
  32. package/dist/distribution/transport/in-memory.d.ts +2 -2
  33. package/dist/distribution/transport/in-memory.mjs +6 -3
  34. package/dist/distribution/transport/tcp.d.ts +2 -2
  35. package/dist/distribution/transport/tcp.mjs +40 -16
  36. package/dist/distribution.d.ts +9 -9
  37. package/dist/distribution.mjs +682 -388
  38. package/dist/embeddings/openai.mjs +1 -1
  39. package/dist/{engine-igk0aMpQ.d.ts → engine-D_OzKZ-6.d.ts} +97 -188
  40. package/dist/index.browser.mjs +11671 -7427
  41. package/dist/index.d.ts +27 -8
  42. package/dist/index.mjs +13 -14
  43. package/dist/invalidation/filesystem.mjs +1 -1
  44. package/dist/{memory-C7UMCMH3.d.ts → memory-B4jMmygw.d.ts} +279 -27
  45. package/dist/pattern-Cledccbl.d.ts +18 -0
  46. package/dist/pattern.d.ts +22 -0
  47. package/dist/pattern.mjs +7 -0
  48. package/dist/persistence/durability/checkpoint-worker.d.ts +41 -17
  49. package/dist/persistence/durability/checkpoint-worker.mjs +24 -16
  50. package/dist/react.d.ts +7 -7
  51. package/dist/react.mjs +1 -1
  52. package/dist/{schema-Bgzr4g7b.d.ts → schema-BBOCdhND.d.ts} +9 -7
  53. package/dist/server.d.ts +11 -11
  54. package/dist/server.mjs +213 -34
  55. package/dist/{tasks-BZt_zes6.d.ts → tasks-DpgCpW1x.d.ts} +3 -3
  56. package/dist/{thread-JEVAYETR.mjs → thread-3LNVA43V.mjs} +94 -27
  57. package/dist/{types-BQDlIvfS.d.ts → types-B3b68nfF.d.ts} +1 -1
  58. package/dist/{types-gOUqhs2F.d.ts → types-BiUmaiWT.d.ts} +1 -1
  59. package/dist/{types-D5OwhtsQ.d.ts → types-Cb9kiY5P.d.ts} +1 -1
  60. package/dist/vector/search-worker.d.ts +1 -1
  61. package/dist/vector/search-worker.mjs +4 -4
  62. package/dist/workers/entry.mjs +4 -4
  63. package/package.json +15 -7
  64. package/dist/chunk-3L4U6EJQ.mjs +0 -49
  65. package/dist/chunk-GIVAGD3Q.mjs +0 -25
  66. package/dist/chunk-IFBKLBGB.mjs +0 -7
  67. package/dist/direct-executor-GYJEKNV5.mjs +0 -12
  68. package/dist/serialization/crc32-worker.d.ts +0 -20
  69. package/dist/serialization/crc32-worker.mjs +0 -62
package/dist/index.d.ts CHANGED
@@ -1,12 +1,13 @@
1
- import { b as StopWordOverride, C as CustomTokenizer } from './schema-Bgzr4g7b.js';
2
- export { A as AnyDocument, B as BM25Params, E as EmbeddingFieldConfig, F as FieldOptionChain, c as FieldType, I as IndexConfig, a as InsertOptions, P as PartitionConfig, S as SchemaDefinition, d as ScoringMode, T as TextFieldOption, V as VectorIndexConfig, e as VectorQuantizationMode, f as VectorStorageMode, W as WriteOptions } from './schema-Bgzr4g7b.js';
1
+ import { b as StopWordOverride, C as CustomTokenizer } from './schema-BBOCdhND.js';
2
+ export { A as AnyDocument, B as BM25Params, E as EmbeddingFieldConfig, F as FieldOptionChain, c as FieldType, I as IndexConfig, a as InsertOptions, P as PartitionConfig, S as SchemaDefinition, d as ScoringMode, T as TextFieldOption, V as VectorIndexConfig, e as VectorQuantizationMode, f as VectorStorageMode, W as WriteOptions } from './schema-BBOCdhND.js';
3
+ import { P as PatternSearch } from './pattern-Cledccbl.js';
3
4
  import { L as LanguageModule } from './language-DB8KG1z5.js';
4
5
  export { T as TokenizerConfig } from './language-DB8KG1z5.js';
5
- export { A as ArrayFilter, B as BatchResult, C as ClientErrorCode, a as ClientErrorCodes, l as ComparisonFilter, D as DocumentProjection, E as ErrorCode, b as ErrorCodes, F as FacetConfig, m as FacetResult, n as FieldFilter, o as FilterExpression, G as GeoFilter, p as GeoPolygonFilter, q as GeoRadiusFilter, r as GroupConfig, s as GroupReducer, t as GroupResult, H as HighlightConfig, u as HighlightMatch, v as Hit, w as HybridConfig, I as IndexInfo, f as IndexStats, L as ListParams, g as ListResult, x as ListedDocument, M as MemoryStats, N as NarsilError, c as NarsilErrorCode, P as PartitionStatsResult, h as PreflightResult, y as PresenceFilter, z as ProcessMemoryReport, J as QueryCoverage, Q as QueryParams, e as QueryResult, K as ScoreComponents, O as SearchMode, S as ServerErrorCode, d as ServerErrorCodes, R as SortField, T as SortSpec, U as StringFilter, j as SuggestParams, k as SuggestResult, W as TermMatchPolicy, V as VectorMaintenanceResult, X as VectorQueryConfig, Y as WorkerCopyReport, i as isNarsilError } from './memory-C7UMCMH3.js';
6
- import { N as NarsilConfig } from './config-Dfanyqqt.js';
7
- export { A as AnalysisConfig, D as DurabilityConfig, I as IndexContext, a as IndexLifecycleConfig, b as InsertContext, M as MainCopyQueries, c as NarsilPlugin, P as PartitionContext, R as RemoveContext, S as SearchContext, d as StaleAnalysis, U as UpdateContext, W as WorkerConfig, e as WorkerContext } from './config-Dfanyqqt.js';
8
- import { a as Narsil } from './engine-igk0aMpQ.js';
9
- export { D as DocumentWriteOperations, I as IndexLifecycleOperations, N as NarsilEventMap } from './engine-igk0aMpQ.js';
6
+ export { A as ArrayFilter, B as BatchResult, C as ClientErrorCode, a as ClientErrorCodes, n as ComparisonFilter, D as DocumentImportResult, o as DocumentProjection, E as ErrorCode, b as ErrorCodes, F as FacetConfig, p as FacetResult, q as FieldFilter, r as FilterExpression, G as GeoFilter, s as GeoPolygonFilter, t as GeoRadiusFilter, u as GroupConfig, v as GroupReducer, w as GroupResult, H as HighlightConfig, x as HighlightMatch, y as Hit, z as HybridConfig, I as IndexInfo, g as IndexStats, L as ListParams, h as ListResult, J as ListedDocument, M as MemoryStats, N as NarsilError, c as NarsilErrorCode, f as NarsilEventHandlers, m as NarsilEventMap, P as PartitionStatsResult, j as PreflightResult, K as PresenceFilter, O as ProcessMemoryReport, R as QueryCoverage, Q as QueryParams, e as QueryResult, T as ScoreComponents, U as SearchMode, S as ServerErrorCode, d as ServerErrorCodes, W as SortField, X as SortSpec, Y as StringFilter, k as SuggestParams, l as SuggestResult, Z as TermMatchPolicy, V as VectorMaintenanceResult, _ as VectorQueryConfig, $ as WorkerCopyReport, i as isNarsilError } from './memory-B4jMmygw.js';
7
+ import { N as NarsilConfig } from './config-QXU3HMpq.js';
8
+ export { A as AnalysisConfig, D as DurabilityConfig, I as IndexContext, a as IndexLifecycleConfig, b as InsertContext, M as MainCopyQueries, c as NarsilPlugin, P as PartitionContext, R as RemoveContext, S as SearchContext, d as StaleAnalysis, U as UpdateContext, W as WorkerConfig, e as WorkerContext } from './config-QXU3HMpq.js';
9
+ import { N as Narsil } from './engine-D_OzKZ-6.js';
10
+ export { B as ByteSource, D as DocumentWriteOperations, I as IndexLifecycleOperations } from './engine-D_OzKZ-6.js';
10
11
  export { E as EmbeddingAdapter, I as InvalidationAdapter, a as InvalidationEvent, b as PartitionStatistics, P as PersistenceAdapter } from './adapters-79OIa4xm.js';
11
12
  export { i as isSimdAvailable } from './simd-DW5AtJ6B.js';
12
13
 
@@ -81,6 +82,24 @@ declare function getTokenizer(name: string): CustomTokenizer;
81
82
  */
82
83
  declare function getStopWords(name: string): StopWordOverride;
83
84
 
85
+ /**
86
+ * This makes pattern search available to every index whose schema declares a
87
+ * pattern field, meaning a `verbatim` field or a text field whose type
88
+ * includes `pattern`.
89
+ *
90
+ * A Node process needs no such call, because it loads the pattern search code
91
+ * by itself. A browser app has to import `patternSearch` from
92
+ * `@delali/narsil/pattern` and pass it to this function before it creates or
93
+ * loads an index with a pattern field.
94
+ *
95
+ * @param module - The `patternSearch` object that `@delali/narsil/pattern`
96
+ * exports.
97
+ * @throws A `NarsilError` with `CONFIG_INVALID` for any other object.
98
+ *
99
+ * @public
100
+ */
101
+ declare function registerPatternSearch(module: PatternSearch): void;
102
+
84
103
  /**
85
104
  * Sets how many normalised tokens the engine keeps cached.
86
105
  *
@@ -178,4 +197,4 @@ declare function createNarsil(config?: NarsilConfig): Promise<Narsil>;
178
197
  */
179
198
  declare const VERSION = "0.1.0";
180
199
 
181
- export { CustomTokenizer, LanguageModule, Narsil, NarsilConfig, StopWordOverride, VERSION, clearNormalizationCache, configureNormalizationCache, createNarsil, getLanguage, getNormalizationCacheSize, getStopWords, getTokenizer, hasStopWords, hasTokenizer, registerLanguage, registerStopWords, registerTokenizer, resetNormalizationCache };
200
+ export { CustomTokenizer, LanguageModule, Narsil, NarsilConfig, PatternSearch, StopWordOverride, VERSION, clearNormalizationCache, configureNormalizationCache, createNarsil, getLanguage, getNormalizationCacheSize, getStopWords, getTokenizer, hasStopWords, hasTokenizer, registerLanguage, registerPatternSearch, registerStopWords, registerTokenizer, resetNormalizationCache };
package/dist/index.mjs CHANGED
@@ -1,19 +1,18 @@
1
- export { VERSION, createNarsil } from './chunk-IOR2K26O.mjs';
1
+ export { VERSION, createNarsil } from './chunk-CVFAFZSN.mjs';
2
2
  import './chunk-GCM3JFVA.mjs';
3
- import './chunk-FVLQ63B7.mjs';
4
- export { getStopWords, getTokenizer, hasStopWords, hasTokenizer, registerStopWords, registerTokenizer } from './chunk-M76V3OGJ.mjs';
5
- export { getLanguage, registerLanguage } from './chunk-HWQLTLNG.mjs';
6
- import './chunk-P4DSQ6M4.mjs';
7
- import './chunk-GIVAGD3Q.mjs';
8
- export { clearNormalizationCache, configureNormalizationCache, getNormalizationCacheSize, resetNormalizationCache } from './chunk-LMO5TJUS.mjs';
9
- import './chunk-653BNMAF.mjs';
3
+ import './chunk-AFKH4ZK3.mjs';
4
+ export { getStopWords, getTokenizer, hasStopWords, hasTokenizer, registerPatternSearch, registerStopWords, registerTokenizer } from './chunk-THMSFOJO.mjs';
5
+ export { getLanguage, registerLanguage } from './chunk-4MQ5F4IL.mjs';
6
+ import './chunk-ZULSEZCE.mjs';
7
+ export { clearNormalizationCache, configureNormalizationCache, getNormalizationCacheSize, resetNormalizationCache } from './chunk-3YKWSO54.mjs';
8
+ import './chunk-AK3BLGCI.mjs';
10
9
  import './chunk-TGP5M5R7.mjs';
11
- export { isSimdAvailable } from './chunk-YJDQ7NLA.mjs';
10
+ export { isSimdAvailable } from './chunk-WVDFG45M.mjs';
12
11
  import './chunk-ZJ4CSAB2.mjs';
13
- import './chunk-YNVIUGF5.mjs';
14
- import './chunk-3L4U6EJQ.mjs';
15
- import './chunk-IFBKLBGB.mjs';
12
+ import './chunk-PU43WDY4.mjs';
13
+ import './chunk-XW25X6AU.mjs';
14
+ import './chunk-ZKRV5M2P.mjs';
16
15
  import './chunk-U2BKYEC7.mjs';
17
- import './chunk-OI42GWLR.mjs';
16
+ import './chunk-LJYTW7GT.mjs';
18
17
  import './chunk-POWOTUKJ.mjs';
19
- export { ClientErrorCodes, ErrorCodes, NarsilError, ServerErrorCodes, isNarsilError } from './chunk-USKFU7J5.mjs';
18
+ export { ClientErrorCodes, ErrorCodes, NarsilError, ServerErrorCodes, isNarsilError } from './chunk-I64LXKO3.mjs';
@@ -1,4 +1,4 @@
1
- import { compareCodePoints } from '../chunk-OI42GWLR.mjs';
1
+ import { compareCodePoints } from '../chunk-LJYTW7GT.mjs';
2
2
  import { DEFAULT_POLL_INTERVAL_MS, MARKER_MAX_AGE_MS } from '../chunk-YEO6G2NG.mjs';
3
3
 
4
4
  // src/invalidation/filesystem.ts
@@ -1,4 +1,4 @@
1
- import { A as AnyDocument, S as SchemaDefinition, d as ScoringMode } from './schema-Bgzr4g7b.js';
1
+ import { A as AnyDocument, S as SchemaDefinition, d as ScoringMode } from './schema-BBOCdhND.js';
2
2
 
3
3
  /**
4
4
  * Every code a {@link NarsilError} carries, grouped by the part of the engine
@@ -41,6 +41,7 @@ declare const ErrorCodes: {
41
41
  readonly SEARCH_INVALID_MODE: "SEARCH_INVALID_MODE";
42
42
  readonly SEARCH_INVALID_CURSOR: "SEARCH_INVALID_CURSOR";
43
43
  readonly SEARCH_RESULT_WINDOW_EXCEEDED: "SEARCH_RESULT_WINDOW_EXCEEDED";
44
+ readonly SEARCH_WORK_CAP_EXCEEDED: "SEARCH_WORK_CAP_EXCEEDED";
44
45
  readonly LANGUAGE_NOT_SUPPORTED: "LANGUAGE_NOT_SUPPORTED";
45
46
  readonly ENVELOPE_VERSION_MISMATCH: "ENVELOPE_VERSION_MISMATCH";
46
47
  readonly ENVELOPE_INVALID_MAGIC: "ENVELOPE_INVALID_MAGIC";
@@ -81,7 +82,6 @@ declare const ErrorCodes: {
81
82
  readonly SNAPSHOT_SYNC_UNAUTHORIZED: "SNAPSHOT_SYNC_UNAUTHORIZED";
82
83
  readonly SNAPSHOT_SYNC_REQUEST_INVALID: "SNAPSHOT_SYNC_REQUEST_INVALID";
83
84
  readonly SNAPSHOT_SYNC_INDEX_NOT_FOUND: "SNAPSHOT_SYNC_INDEX_NOT_FOUND";
84
- readonly SNAPSHOT_SYNC_TOO_LARGE: "SNAPSHOT_SYNC_TOO_LARGE";
85
85
  readonly SNAPSHOT_SYNC_CAPACITY_EXHAUSTED: "SNAPSHOT_SYNC_CAPACITY_EXHAUSTED";
86
86
  readonly SNAPSHOT_SYNC_SNAPSHOT_FAILED: "SNAPSHOT_SYNC_SNAPSHOT_FAILED";
87
87
  readonly SNAPSHOT_SYNC_DECODE_FAILED: "SNAPSHOT_SYNC_DECODE_FAILED";
@@ -225,6 +225,200 @@ declare class NarsilError extends Error {
225
225
  */
226
226
  declare function isNarsilError(value: unknown): value is NarsilError;
227
227
 
228
+ /**
229
+ * This map lists every event that the engine emits, with the payload of each
230
+ * one.
231
+ *
232
+ * {@link Narsil.on} registers a listener under a key from this map, so that the
233
+ * engine can pass the matching payload to that listener. Most of these events
234
+ * report work that the engine does in the background, away from the call that
235
+ * started it, so a failure that such an event reports never rejects a promise
236
+ * that you are holding.
237
+ *
238
+ * @public
239
+ */
240
+ type NarsilEventMap = {
241
+ /**
242
+ * The engine emits this event after a call changes what a read returns from
243
+ * an index. The calls are the inserts, updates, and removals, singly or in a
244
+ * batch, together with `clear`, `restore`, `rebalance`, `rebuildAnalysis`,
245
+ * `compactVectors`, `optimizeVectors`, `createIndex`, and `dropIndex`. The
246
+ * engine emits the event after a call that throws as well, because a call can
247
+ * change the index before it throws. It also emits the event after it reloads
248
+ * an index, once a shared invalidation adapter reports that another instance
249
+ * saved that index. The engine emits one event per batch, however many
250
+ * documents the batch holds.
251
+ *
252
+ * The engine emits the event once a query can see the change, which means
253
+ * after every worker copy applies the change and after any rebalance in
254
+ * progress replays it. A query that a listener sends from its handler
255
+ * therefore returns results that include the change. The engine waits for the
256
+ * change to become visible only while a listener is registered for the event.
257
+ */
258
+ write: {
259
+ /** This is the name of the index that changed. */
260
+ indexName: string;
261
+ };
262
+ /**
263
+ * A worker thread exited unexpectedly. The pool removes the thread and fails
264
+ * the requests that the thread was serving with `WORKER_CRASHED`. The engine
265
+ * then sends each of those queries again on the main thread, so the caller
266
+ * receives a result with no error. The remaining workers keep serving
267
+ * queries, because each of them holds a full worker copy of every promoted
268
+ * index.
269
+ *
270
+ * After a delay, the engine spawns a replacement and loads every copy onto
271
+ * it before it sends queries to the replacement. Once no worker is left, the
272
+ * main thread serves every query, because it holds every document. The first
273
+ * request after the delay then starts a new pool. The delay starts at one
274
+ * second and doubles up to a minute while replacements keep failing.
275
+ */
276
+ workerCrash: {
277
+ /** This is the id of the worker that exited. */
278
+ workerId: number;
279
+ /** These are the indexes that the worker held. */
280
+ indexNames: string[];
281
+ /** This is the error that ended the worker. */
282
+ error: Error;
283
+ };
284
+ /** An index gained worker copies, either because it reached the copy
285
+ * threshold or because a request loaded its copies again after an idle
286
+ * spell. */
287
+ workerPromote: {
288
+ /** This is the number of workers in the pool. */
289
+ workerCount: number;
290
+ /** This is the reason that the index gained its copies, such as the copy
291
+ * threshold that it reached. */
292
+ reason: string;
293
+ };
294
+ /** An index could not gain worker copies, so the main thread keeps serving
295
+ * its queries. */
296
+ workerPromoteFailure: {
297
+ /** This is the reason that the engine tried to load the copies. */
298
+ reason: string;
299
+ /** This is the error that stopped the load. */
300
+ error: Error;
301
+ /** This is true when the engine will try again at a later threshold. */
302
+ retryable: boolean;
303
+ };
304
+ /** An index finished spreading its documents across a new number of
305
+ * partitions. */
306
+ partitionRebalance: {
307
+ /** This is the name of the index that the engine rebalanced. */
308
+ indexName: string;
309
+ /** This is the number of partitions before the rebalance. */
310
+ oldCount: number;
311
+ /** This is the number of partitions after the rebalance. */
312
+ newCount: number;
313
+ };
314
+ /**
315
+ * An index passed its watermark, so its partitions are close to their
316
+ * capacity. On a cluster node, the engine reports the document count and the
317
+ * capacity of the one partition that `partitionId` identifies, which this
318
+ * node leads.
319
+ */
320
+ partitionWatermark: {
321
+ /** This is the name of the index that crossed the mark. */
322
+ indexName: string;
323
+ /** This is the number of documents in the index, or in the partition on a
324
+ * cluster node. */
325
+ documentCount: number;
326
+ /** This is the number of documents that the current partitions of the
327
+ * index can hold, or that the partition can hold on a cluster node. */
328
+ capacity: number;
329
+ /** This is the number of partitions in the index. */
330
+ partitionCount: number;
331
+ /** On a cluster node, this is the partition that crossed the mark, while
332
+ * outside a cluster the field is absent. */
333
+ partitionId?: number;
334
+ };
335
+ /**
336
+ * The process uses nine tenths of its heap, as measured during a write or a
337
+ * load, so the next large index can end the process with an out-of-memory
338
+ * error.
339
+ *
340
+ * Where `--max-old-space-size` or `--max-old-space-size-percentage` sets a
341
+ * limit, on the command line or in `NODE_OPTIONS`, the engine measures the
342
+ * used bytes against that limit, which `heapLimit` then reports. Where
343
+ * neither flag sets a limit, the engine measures the share of the heap that
344
+ * V8 reports as no longer available. V8 reports a limit about 192 MB above
345
+ * the true ceiling, so a process on a default heap below about 2 GB can end before
346
+ * this event fires.
347
+ *
348
+ * The engine emits the event once per crossing, then arms it again once the
349
+ * free share of the heap recovers to two tenths. Raise the limit with
350
+ * `--max-old-space-size-percentage` or `--max-old-space-size`, or close an
351
+ * idle index; see {@link ProcessMemoryReport.heapLimit}.
352
+ */
353
+ heapPressure: {
354
+ /** This is the index that a write or a load was touching when the heap
355
+ * reached that point. */
356
+ indexName: string;
357
+ /** This is the heap that the process uses, in bytes. */
358
+ heapUsed: number;
359
+ /** This is the size in bytes that the heap can grow to. */
360
+ heapLimit: number;
361
+ /** This is the estimate of the bytes that the index holds. */
362
+ estimatedMemoryBytes: number;
363
+ };
364
+ /** The engine started, completed, or failed a rebuild that brings the terms
365
+ * of an index up to the current analysis of its language module. */
366
+ analysisRebuild: {
367
+ /** This is the name of the index under rebuild. */
368
+ indexName: string;
369
+ /** This is the stage that the rebuild has reached. */
370
+ status: 'started' | 'completed' | 'failed';
371
+ /** This is the number of partitions that the rebuild has covered so far. */
372
+ partitionsRebuilt: number;
373
+ /** This is the number of partitions that the rebuild covers in total. */
374
+ partitionCount: number;
375
+ /** This is the error that stopped the rebuild, which only a `failed`
376
+ * status includes. */
377
+ error?: Error;
378
+ };
379
+ /** The engine started, completed, or failed the rewrite of an index that you
380
+ * saved with an earlier release. The engine rewrites the index as it
381
+ * recovers it, before it serves the index's first request. Because the
382
+ * engine writes the new manifest last, the earlier files stay intact through
383
+ * a failed rewrite. The engine then starts the rewrite again the next time
384
+ * it recovers the index. Without index lifecycle settings, the engine
385
+ * recovers every index before {@link createNarsil} returns, so pass the
386
+ * listener in the `events` setting of {@link createNarsil}. */
387
+ layoutUpgrade: {
388
+ /** This is the name of the index under rewrite. */
389
+ indexName: string;
390
+ /** This is the stage that the rewrite has reached. */
391
+ status: 'started' | 'completed' | 'failed';
392
+ /** This is `manifest` where the earlier index is a segment manifest with
393
+ * its files, and `bundle` where it is a single snapshot bundle. */
394
+ layout: 'manifest' | 'bundle';
395
+ /** This is the error that stopped the rewrite, which only a `failed`
396
+ * status includes. */
397
+ error?: Error;
398
+ };
399
+ /** A write to the write-ahead log or a checkpoint failed, so the writes since
400
+ * the last checkpoint are at risk. */
401
+ durabilityError: {
402
+ /** This is the error that the durability layer threw. */
403
+ error: Error;
404
+ };
405
+ /** The invalidation channel failed, so this instance can serve partitions
406
+ * that another instance has since changed. */
407
+ invalidationError: {
408
+ /** This is the error that the adapter threw. */
409
+ error: Error;
410
+ };
411
+ };
412
+ /**
413
+ * This map holds a listener for any event of {@link NarsilEventMap}, so that
414
+ * the engine can register each listener before it starts.
415
+ *
416
+ * @public
417
+ */
418
+ type NarsilEventHandlers = {
419
+ [K in keyof NarsilEventMap]?: (payload: NarsilEventMap[K]) => void;
420
+ };
421
+
228
422
  /**
229
423
  * What {@link Narsil.query} returns: the ranked hits and everything the query
230
424
  * asked for alongside them.
@@ -424,6 +618,24 @@ interface BatchResult {
424
618
  error: NarsilError;
425
619
  }>;
426
620
  }
621
+ /**
622
+ * What {@link Narsil.importDocumentExport} returns. The engine continues past each
623
+ * refused line, so read the refusals to learn which documents it skipped.
624
+ *
625
+ * @public
626
+ */
627
+ interface DocumentImportResult {
628
+ /** The engine wrote this many documents, counting each one that it replaced. */
629
+ imported: number;
630
+ /** The engine refused this many lines in total. */
631
+ refusedCount: number;
632
+ /** These are the 1,000 refusals with the lowest line numbers. Each entry contains the line number, where the header is line 1, along with the error code and a message. */
633
+ refused: Array<{
634
+ line: number;
635
+ code: NarsilErrorCode;
636
+ message: string;
637
+ }>;
638
+ }
427
639
  /**
428
640
  * What {@link Narsil.getStats} returns about one index.
429
641
  *
@@ -577,9 +789,13 @@ interface ListResult<T = AnyDocument> {
577
789
  * @public
578
790
  */
579
791
  type ComparisonFilter = {
580
- /** This matches a field equal to the value. */
792
+ /** This matches a field equal to the value, or a list field where one element equals it. */
581
793
  eq?: number | string | boolean;
582
- /** This matches a field holding anything other than the value. */
794
+ /**
795
+ * This matches a document that holds the field with a value other than this
796
+ * one, or a list field where every element differs from it, which an empty
797
+ * list does.
798
+ */
583
799
  ne?: number | string | boolean;
584
800
  /** This matches a field greater than the number. */
585
801
  gt?: number;
@@ -596,10 +812,10 @@ type ComparisonFilter = {
596
812
  * The engine tests a text field against this filter for equality, for a text
597
813
  * range, or with the set and prefix tests.
598
814
  *
599
- * The engine compares each element of a `string[]` or `verbatim[]` field, so
600
- * it matches a document with `eq`, `in`, `startsWith`, or `endsWith` where
601
- * one element passes the test, while it matches a document with `ne` or `nin`
602
- * where every element differs from the values.
815
+ * The engine compares each element of a `string[]`, `verbatim[]`, or `enum[]` field, so
816
+ * it matches a document with `eq`, `in`, `startsWith`, `endsWith`, or
817
+ * `contains` where one element passes the test, while it matches a document
818
+ * with `ne` or `nin` where every element differs from the values.
603
819
  *
604
820
  * The engine applies the range tests `gt`, `gte`, `lt`, `lte`, and `between`
605
821
  * to a single `string` or `verbatim` field whose type includes `sortable`,
@@ -607,6 +823,21 @@ type ComparisonFilter = {
607
823
  * It orders the values as a sort on the field does, comparing their case folds
608
824
  * first and their raw code points only where the folds are equal.
609
825
  *
826
+ * A pattern field is a `verbatim` or `verbatim[]` field, or a `string` or
827
+ * `string[]` field whose type includes `pattern`. On such a field, the engine
828
+ * answers `eq`, `ne`, `in`, `nin`, `startsWith`, `endsWith`, and `contains`
829
+ * from the field's pattern index. `caseFold` applies to each of those tests.
830
+ * On an `enum` or `enum[]` field, the engine answers `eq`, `ne`, `in`, `nin`,
831
+ * `startsWith`, and `endsWith` from the field's index of values. It throws
832
+ * `SEARCH_INVALID_FILTER` for `eq`, `ne`, `in`, `nin`, `startsWith`, or
833
+ * `endsWith` on a `string` or `string[]` field whose type leaves out
834
+ * `pattern`, because such a field keeps no index of whole values.
835
+ * The engine compares the code points of each value as stored, with no
836
+ * Unicode normalisation. It throws `SEARCH_INVALID_FILTER` for `contains` or
837
+ * `caseFold` on any other field, for a test text longer than 1,024 code points
838
+ * on a pattern field, and for a `caseFold` test whose text has a case fold
839
+ * longer than 2,048 code points.
840
+ *
610
841
  * @public
611
842
  */
612
843
  type StringFilter = Pick<ComparisonFilter, 'eq' | 'ne'> & {
@@ -620,26 +851,41 @@ type StringFilter = Pick<ComparisonFilter, 'eq' | 'ne'> & {
620
851
  lte?: string;
621
852
  /** This matches a value inside the inclusive range in sort order, given as `[low, high]`. */
622
853
  between?: [string, string];
623
- /** This matches a field equal to any value in the list. */
854
+ /** This matches a field equal to any value in the list, which holds at most 65,536 values. */
624
855
  in?: string[];
625
- /** This matches a field that differs from every value in the list. */
856
+ /** This matches a field that differs from every value in the list, which holds at most 65,536 values. */
626
857
  nin?: string[];
627
858
  /** This matches a field starting with the text. */
628
859
  startsWith?: string;
629
860
  /** This matches a field ending with the text. */
630
861
  endsWith?: string;
862
+ /** This matches a pattern field whose value holds the text anywhere in it. */
863
+ contains?: string;
864
+ /**
865
+ * When this is true, the engine compares the case fold of each value of a
866
+ * pattern field with the case fold of the text, so a test for `error` matches
867
+ * `ERROR`. It applies to `eq`, `ne`, `in`, `nin`, `startsWith`, `endsWith`,
868
+ * and `contains`.
869
+ */
870
+ caseFold?: boolean;
631
871
  };
632
872
  /**
633
- * Tests the contents of an array field.
873
+ * Tests the contents of a list field, which is a `number[]`, `boolean[]`,
874
+ * `enum[]`, `verbatim[]`, or `string[]` field.
875
+ *
876
+ * The engine throws `SEARCH_INVALID_FILTER` for these tests on any other
877
+ * field, for a value whose type differs from the type of the list's elements,
878
+ * and for `containsAll` or `matchesAny` on a `string[]` field whose type leaves
879
+ * out `pattern`.
634
880
  *
635
881
  * @public
636
882
  */
637
883
  type ArrayFilter = {
638
- /** This matches an array holding every one of the values. */
884
+ /** This matches a list holding every one of the values, at most 65,536 of them, so an empty set of values matches every list. */
639
885
  containsAll?: (string | number | boolean)[];
640
- /** This matches an array holding at least one of the values. */
886
+ /** This matches a list holding at least one of the values, at most 65,536 of them. */
641
887
  matchesAny?: (string | number | boolean)[];
642
- /** This compares the array's length. */
888
+ /** This compares the number of elements in the list. */
643
889
  size?: ComparisonFilter;
644
890
  };
645
891
  /**
@@ -649,13 +895,13 @@ type ArrayFilter = {
649
895
  * @public
650
896
  */
651
897
  type PresenceFilter = {
652
- /** This matches a document where the field is present. */
898
+ /** This matches a document where the field holds a value other than null. */
653
899
  exists?: boolean;
654
- /** This matches a document where the field is absent. */
900
+ /** This matches a document where the field is absent or null. */
655
901
  notExists?: boolean;
656
- /** This matches an empty string or an empty array. */
902
+ /** This matches a document where the field is absent, null, an empty string, or an empty list. */
657
903
  isEmpty?: boolean;
658
- /** This matches a string or array holding something. */
904
+ /** This matches a document where the field holds a value other than an empty string or an empty list. */
659
905
  isNotEmpty?: boolean;
660
906
  };
661
907
  /**
@@ -666,9 +912,9 @@ type PresenceFilter = {
666
912
  type GeoRadiusFilter = {
667
913
  /** The engine tests the field against this circle. */
668
914
  radius: {
669
- /** The centre has this latitude, in degrees. */
915
+ /** The centre has this latitude, in degrees from -90 to 90. For any other value, the engine throws `SEARCH_INVALID_FILTER`. */
670
916
  lat: number;
671
- /** The centre has this longitude, in degrees. */
917
+ /** The centre has this longitude, in degrees from -180 to 180. For any other value, the engine throws `SEARCH_INVALID_FILTER`. */
672
918
  lon: number;
673
919
  /** The circle has this radius, measured in `unit`. */
674
920
  distance: number;
@@ -701,9 +947,11 @@ type GeoPolygonFilter = {
701
947
  /**
702
948
  * The engine closes the ring through these corners in the order that you
703
949
  * list them, so you can leave the first point off the end. It throws
704
- * `SEARCH_INVALID_FILTER` for a ring of fewer than three corners, since
705
- * such a ring encloses no area. List the corners counter-clockwise around
706
- * the area, as in an exterior ring of GeoJSON. Where the corners
950
+ * `SEARCH_INVALID_FILTER` for a ring of fewer than three corners, which
951
+ * encloses no area, and for a corner whose latitude is outside -90 to 90
952
+ * or whose longitude is outside -180 to 180. It also throws that error for
953
+ * a ring of more than 65,536 corners. List the corners counter-clockwise
954
+ * around the area, as in an exterior ring of GeoJSON. Where the corners
707
955
  * span 180 degrees of longitude or more, the engine matches the area on
708
956
  * the left of that path, so a ring listed that way can cross the
709
957
  * antimeridian or span more than half the globe.
@@ -730,11 +978,15 @@ type GeoFilter = GeoRadiusFilter | GeoPolygonFilter;
730
978
  */
731
979
  type FieldFilter = ComparisonFilter | StringFilter | ArrayFilter | PresenceFilter | GeoFilter;
732
980
  /**
733
- * The filter a query runs, built from per-field tests and the boolean
981
+ * The filter that a query runs, built from per-field tests and the boolean
734
982
  * operators that combine them.
735
983
  *
736
- * Nest the operators to whatever depth the query needs. The engine applies the
737
- * filter before scoring, so a narrow filter makes a search cheaper.
984
+ * The engine answers every test from an index that it keeps for the field. It
985
+ * applies the filter before scoring, so a narrow filter makes a search
986
+ * cheaper. A filter nests at most 30 levels deep and holds at most 1,024
987
+ * tests, counted across every field and nested expression. Past either limit,
988
+ * the engine throws `SEARCH_INVALID_FILTER`, while it throws
989
+ * `SEARCH_INVALID_FIELD` for a test on a field that the schema leaves out.
738
990
  *
739
991
  * @public
740
992
  */
@@ -1252,4 +1504,4 @@ interface MemoryStats {
1252
1504
  }>;
1253
1505
  }
1254
1506
 
1255
- export { type ArrayFilter as A, type BatchResult as B, type ClientErrorCode as C, type DocumentProjection as D, type ErrorCode as E, type FacetConfig as F, type GeoFilter as G, type HighlightConfig as H, type IndexInfo as I, type QueryCoverage as J, type ScoreComponents as K, type ListParams as L, type MemoryStats as M, NarsilError as N, type SearchMode as O, type PartitionStatsResult as P, type QueryParams as Q, type SortField as R, type ServerErrorCode as S, type SortSpec as T, type StringFilter as U, type VectorMaintenanceResult as V, type TermMatchPolicy as W, type VectorQueryConfig as X, type WorkerCopyReport as Y, ClientErrorCodes as a, ErrorCodes as b, type NarsilErrorCode as c, ServerErrorCodes as d, type QueryResult as e, type IndexStats as f, type ListResult as g, type PreflightResult as h, isNarsilError as i, type SuggestParams as j, type SuggestResult as k, type ComparisonFilter as l, type FacetResult as m, type FieldFilter as n, type FilterExpression as o, type GeoPolygonFilter as p, type GeoRadiusFilter as q, type GroupConfig as r, type GroupReducer as s, type GroupResult as t, type HighlightMatch as u, type Hit as v, type HybridConfig as w, type ListedDocument as x, type PresenceFilter as y, type ProcessMemoryReport as z };
1507
+ export { type WorkerCopyReport as $, type ArrayFilter as A, type BatchResult as B, type ClientErrorCode as C, type DocumentImportResult as D, type ErrorCode as E, type FacetConfig as F, type GeoFilter as G, type HighlightConfig as H, type IndexInfo as I, type ListedDocument as J, type PresenceFilter as K, type ListParams as L, type MemoryStats as M, NarsilError as N, type ProcessMemoryReport as O, type PartitionStatsResult as P, type QueryParams as Q, type QueryCoverage as R, type ServerErrorCode as S, type ScoreComponents as T, type SearchMode as U, type VectorMaintenanceResult as V, type SortField as W, type SortSpec as X, type StringFilter as Y, type TermMatchPolicy as Z, type VectorQueryConfig as _, ClientErrorCodes as a, ErrorCodes as b, type NarsilErrorCode as c, ServerErrorCodes as d, type QueryResult as e, type NarsilEventHandlers as f, type IndexStats as g, type ListResult as h, isNarsilError as i, type PreflightResult as j, type SuggestParams as k, type SuggestResult as l, type NarsilEventMap as m, type ComparisonFilter as n, type DocumentProjection as o, type FacetResult as p, type FieldFilter as q, type FilterExpression as r, type GeoPolygonFilter as s, type GeoRadiusFilter as t, type GroupConfig as u, type GroupReducer as v, type GroupResult as w, type HighlightMatch as x, type Hit as y, type HybridConfig as z };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * This object holds the code with which the engine builds the pattern index of
3
+ * each pattern field and answers `contains` and the other text tests on that
4
+ * field.
5
+ *
6
+ * A Node process loads this code by itself. A browser bundle includes it only
7
+ * where the app imports `patternSearch` from `@delali/narsil/pattern` and
8
+ * passes it to {@link registerPatternSearch}, so a bundler can leave it out of
9
+ * an app that has no pattern field.
10
+ *
11
+ * @public
12
+ */
13
+ interface PatternSearch {
14
+ /** This is always `'pattern'`, the name of the code that the object holds. */
15
+ readonly name: 'pattern';
16
+ }
17
+
18
+ export type { PatternSearch as P };
@@ -0,0 +1,22 @@
1
+ import { P as PatternSearch } from './pattern-Cledccbl.js';
2
+
3
+ /**
4
+ * This object holds the pattern search code, which a browser app has to pass
5
+ * to {@link registerPatternSearch} before it creates or loads an index with a
6
+ * pattern field.
7
+ *
8
+ * ```ts
9
+ * import { registerPatternSearch } from '@delali/narsil'
10
+ * import { patternSearch } from '@delali/narsil/pattern'
11
+ *
12
+ * registerPatternSearch(patternSearch)
13
+ * ```
14
+ *
15
+ * A Node process loads the pattern search code by itself, so it needs no such
16
+ * call.
17
+ *
18
+ * @public
19
+ */
20
+ declare const patternSearch: PatternSearch;
21
+
22
+ export { PatternSearch, patternSearch };
@@ -0,0 +1,7 @@
1
+ import { patternSearchModule } from './chunk-XW25X6AU.mjs';
2
+ import './chunk-ZKRV5M2P.mjs';
3
+
4
+ // src/pattern/index.ts
5
+ var patternSearch = patternSearchModule;
6
+
7
+ export { patternSearch };