@delali/narsil 0.2.4-next.47 → 0.2.4-next.49

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 (48) hide show
  1. package/README.md +2 -2
  2. package/dist/adapters/indexeddb.mjs +15 -10
  3. package/dist/{chunk-BFIH7OV5.mjs → chunk-2GWVQWGA.mjs} +3 -1
  4. package/dist/{chunk-UZTT2BKQ.mjs → chunk-56PJBIJ6.mjs} +891 -542
  5. package/dist/chunk-CBLS46IE.mjs +10 -0
  6. package/dist/{chunk-JQUL2T6I.mjs → chunk-GCM3JFVA.mjs} +1 -2
  7. package/dist/{chunk-4COAUBLJ.mjs → chunk-HGJC5L65.mjs} +4 -7
  8. package/dist/{chunk-DFZDV5FV.mjs → chunk-JXHUHFJ5.mjs} +27 -14
  9. package/dist/{chunk-XWICBGYT.mjs → chunk-KGRYQVZ5.mjs} +2 -5
  10. package/dist/{chunk-EV45L35L.mjs → chunk-M6JGMKA5.mjs} +391 -183
  11. package/dist/{chunk-PM52SMBT.mjs → chunk-OOSIDHA3.mjs} +2 -1
  12. package/dist/chunk-ORBLD3EL.mjs +6 -0
  13. package/dist/chunk-OWCFK42Q.mjs +30 -0
  14. package/dist/{chunk-WTONLDU3.mjs → chunk-RDGXYRF4.mjs} +1 -0
  15. package/dist/chunk-UNEEFTEU.mjs +7 -0
  16. package/dist/chunk-YEO6G2NG.mjs +6 -0
  17. package/dist/{client-C5BkUqB8.d.ts → client-DX7xPcNA.d.ts} +1 -1
  18. package/dist/client.d.ts +5 -5
  19. package/dist/client.mjs +224 -222
  20. package/dist/{config-B-ZI-ft5.d.ts → config-B41W23Us.d.ts} +1 -1
  21. package/dist/{config-BZRExglL.d.ts → config-Co-zAXqO.d.ts} +27 -11
  22. package/dist/direct-executor-HRTDWMVB.mjs +9 -0
  23. package/dist/distribution/coordinator/etcd.mjs +4 -7
  24. package/dist/distribution/coordinator/in-memory.mjs +2 -2
  25. package/dist/distribution/transport/grpc.mjs +7 -9
  26. package/dist/distribution/transport/in-memory.mjs +2 -1
  27. package/dist/distribution/transport/tcp.mjs +3 -2
  28. package/dist/distribution.d.ts +5 -5
  29. package/dist/distribution.mjs +121 -97
  30. package/dist/embeddings/openai.mjs +5 -3
  31. package/dist/{engine-Cjr1uBLa.d.ts → engine-CABZg25p.d.ts} +12 -8
  32. package/dist/index.browser.mjs +1514 -894
  33. package/dist/index.d.ts +5 -5
  34. package/dist/index.mjs +9 -8
  35. package/dist/invalidation/broadcast-channel.mjs +2 -1
  36. package/dist/invalidation/filesystem.mjs +3 -4
  37. package/dist/{options-BC68VPoE.d.ts → options-Dtk99qUs.d.ts} +1 -1
  38. package/dist/persistence/durability/checkpoint-worker.mjs +9 -8
  39. package/dist/react.d.ts +3 -3
  40. package/dist/react.mjs +7 -5
  41. package/dist/{search-DDHjfXhJ.d.ts → search-FjWhZN3f.d.ts} +20 -3
  42. package/dist/server.d.ts +6 -6
  43. package/dist/server.mjs +43 -30
  44. package/dist/vector/hnsw-build-worker.mjs +2 -4
  45. package/dist/vector/search-worker.mjs +3 -4
  46. package/dist/workers/entry.mjs +2 -2
  47. package/package.json +1 -1
  48. package/dist/direct-executor-EOTFGXTO.mjs +0 -8
package/dist/index.d.ts CHANGED
@@ -2,11 +2,11 @@ import { c as StopWordOverride, C as CustomTokenizer } from './schema-B7juWg8Q.j
2
2
  export { A as AnyDocument, B as BM25Params, E as EmbeddingFieldConfig, F as FieldType, I as IndexConfig, b as InsertOptions, P as PartitionConfig, S as SchemaDefinition, a as ScoringMode, V as VectorIndexConfig, d as VectorQuantizationMode } from './schema-B7juWg8Q.js';
3
3
  import { L as LanguageModule } from './language-DB8KG1z5.js';
4
4
  export { T as TokenizerConfig } from './language-DB8KG1z5.js';
5
- export { A as ArrayFilter, B as BatchResult, C as ClientErrorCode, a as ClientErrorCodes, k as ComparisonFilter, D as DocumentProjection, E as ErrorCode, b as ErrorCodes, F as FacetConfig, l as FacetResult, m as FieldFilter, n as FilterExpression, G as GeoFilter, o as GeoPolygonFilter, p as GeoRadiusFilter, q as GroupConfig, r as GroupReducer, s as GroupResult, H as HighlightConfig, t as HighlightMatch, u as Hit, v as HybridConfig, I as IndexInfo, f as IndexStats, L as ListParams, g as ListResult, w as ListedDocument, M as MemoryStats, N as NarsilError, c as NarsilErrorCode, P as PartitionStatsResult, h as PreflightResult, x as PresenceFilter, y as ProcessMemoryReport, z as QueryCoverage, Q as QueryParams, e as QueryResult, J as ScoreComponents, K as SearchMode, S as ServerErrorCode, d as ServerErrorCodes, O as SortField, R as SortSpec, T as StringFilter, i as SuggestParams, j as SuggestResult, U as TermMatchPolicy, V as VectorMaintenanceResult, W as VectorQueryConfig } from './search-DDHjfXhJ.js';
6
- import { N as NarsilConfig } from './config-BZRExglL.js';
7
- export { A as AnalysisConfig, D as DurabilityConfig, I as IndexContext, a as IndexLifecycleConfig, b as InsertContext, 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-BZRExglL.js';
8
- import { a as Narsil } from './engine-Cjr1uBLa.js';
9
- export { I as IndexLifecycleOperations, N as NarsilEventMap } from './engine-Cjr1uBLa.js';
5
+ export { A as ArrayFilter, B as BatchResult, C as ClientErrorCode, a as ClientErrorCodes, k as ComparisonFilter, D as DocumentProjection, E as ErrorCode, b as ErrorCodes, F as FacetConfig, l as FacetResult, m as FieldFilter, n as FilterExpression, G as GeoFilter, o as GeoPolygonFilter, p as GeoRadiusFilter, q as GroupConfig, r as GroupReducer, s as GroupResult, H as HighlightConfig, t as HighlightMatch, u as Hit, v as HybridConfig, I as IndexInfo, f as IndexStats, L as ListParams, g as ListResult, w as ListedDocument, M as MemoryStats, N as NarsilError, c as NarsilErrorCode, P as PartitionStatsResult, h as PreflightResult, x as PresenceFilter, y as ProcessMemoryReport, z as QueryCoverage, Q as QueryParams, e as QueryResult, J as ScoreComponents, K as SearchMode, S as ServerErrorCode, d as ServerErrorCodes, O as SortField, R as SortSpec, T as StringFilter, i as SuggestParams, j as SuggestResult, U as TermMatchPolicy, V as VectorMaintenanceResult, W as VectorQueryConfig, X as WorkerCopyReport } from './search-FjWhZN3f.js';
6
+ import { N as NarsilConfig } from './config-Co-zAXqO.js';
7
+ export { A as AnalysisConfig, D as DurabilityConfig, I as IndexContext, a as IndexLifecycleConfig, b as InsertContext, 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-Co-zAXqO.js';
8
+ import { a as Narsil } from './engine-CABZg25p.js';
9
+ export { I as IndexLifecycleOperations, N as NarsilEventMap } from './engine-CABZg25p.js';
10
10
  export { E as EmbeddingAdapter, I as InvalidationAdapter, a as InvalidationEvent, b as PartitionStatistics, P as PersistenceAdapter } from './adapters-79OIa4xm.js';
11
11
 
12
12
  /**
package/dist/index.mjs CHANGED
@@ -1,12 +1,13 @@
1
- export { VERSION, createNarsil } from './chunk-UZTT2BKQ.mjs';
2
- import './chunk-JQUL2T6I.mjs';
3
- import './chunk-XWICBGYT.mjs';
4
- export { clearNormalizationCache, configureNormalizationCache, getLanguage, getNormalizationCacheSize, getStopWords, getTokenizer, hasStopWords, hasTokenizer, registerLanguage, registerStopWords, registerTokenizer, resetNormalizationCache } from './chunk-EV45L35L.mjs';
1
+ export { VERSION, createNarsil } from './chunk-56PJBIJ6.mjs';
2
+ import './chunk-GCM3JFVA.mjs';
3
+ import './chunk-OWCFK42Q.mjs';
4
+ export { clearNormalizationCache, configureNormalizationCache, getLanguage, getNormalizationCacheSize, getStopWords, getTokenizer, hasStopWords, hasTokenizer, registerLanguage, registerStopWords, registerTokenizer, resetNormalizationCache } from './chunk-M6JGMKA5.mjs';
5
+ import './chunk-CBLS46IE.mjs';
5
6
  import './chunk-TGP5M5R7.mjs';
6
- import './chunk-4COAUBLJ.mjs';
7
- export { isSimdAvailable } from './chunk-DFZDV5FV.mjs';
7
+ import './chunk-HGJC5L65.mjs';
8
+ export { isSimdAvailable } from './chunk-JXHUHFJ5.mjs';
8
9
  import './chunk-KMMJMDUA.mjs';
9
10
  import './chunk-U2BKYEC7.mjs';
10
- import './chunk-BFIH7OV5.mjs';
11
- import './chunk-WTONLDU3.mjs';
11
+ import './chunk-2GWVQWGA.mjs';
12
+ import './chunk-RDGXYRF4.mjs';
12
13
  export { ClientErrorCodes, ErrorCodes, NarsilError, ServerErrorCodes } from './chunk-P4ELXVJQ.mjs';
@@ -1,5 +1,6 @@
1
+ import { DEFAULT_CHANNEL_NAME } from '../chunk-YEO6G2NG.mjs';
2
+
1
3
  // src/invalidation/broadcast-channel.ts
2
- var DEFAULT_CHANNEL_NAME = "narsil-invalidation";
3
4
  function isInvalidationEvent(data) {
4
5
  if (typeof data !== "object" || data === null) {
5
6
  return false;
@@ -1,8 +1,7 @@
1
- import { compareCodePoints } from '../chunk-BFIH7OV5.mjs';
1
+ import { compareCodePoints } from '../chunk-2GWVQWGA.mjs';
2
+ import { DEFAULT_POLL_INTERVAL_MS, MARKER_MAX_AGE_MS } from '../chunk-YEO6G2NG.mjs';
2
3
 
3
4
  // src/invalidation/filesystem.ts
4
- var MARKER_MAX_AGE_MS = 6e4;
5
- var DEFAULT_POLL_INTERVAL = 1e3;
6
5
  function generateInstanceId() {
7
6
  if (typeof globalThis.crypto !== "undefined" && typeof globalThis.crypto.randomUUID === "function") {
8
7
  return globalThis.crypto.randomUUID();
@@ -28,7 +27,7 @@ function createFilesystemInvalidation(config) {
28
27
  throw new Error(`Invalid directory path: path traversal detected in "${config.directory}"`);
29
28
  }
30
29
  const directory = config.directory;
31
- const pollInterval = config.pollInterval ?? DEFAULT_POLL_INTERVAL;
30
+ const pollInterval = config.pollInterval ?? DEFAULT_POLL_INTERVAL_MS;
32
31
  const instanceId = config.instanceId ?? generateInstanceId();
33
32
  if (instanceId.includes("/") || instanceId.includes("\\") || instanceId.includes("..") || instanceId.includes("\0")) {
34
33
  throw new Error(`Invalid instanceId: "${instanceId}" contains path separator or traversal characters`);
@@ -1,5 +1,5 @@
1
- import { C as ClusterNamespace } from './config-B-ZI-ft5.js';
2
1
  import { E as EmbeddingAdapter } from './adapters-79OIa4xm.js';
2
+ import { C as ClusterNamespace } from './config-B41W23Us.js';
3
3
  import { h as TaskStore } from './tasks-Bn4R1NPN.js';
4
4
 
5
5
  /**
@@ -1,14 +1,15 @@
1
- import { createDurableDirectory, writeSegmentedCheckpoint } from '../../chunk-UZTT2BKQ.mjs';
2
- import '../../chunk-JQUL2T6I.mjs';
3
- import '../../chunk-XWICBGYT.mjs';
4
- import '../../chunk-EV45L35L.mjs';
1
+ import { createDurableDirectory, writeSegmentedCheckpoint } from '../../chunk-56PJBIJ6.mjs';
2
+ import '../../chunk-GCM3JFVA.mjs';
3
+ import '../../chunk-OWCFK42Q.mjs';
4
+ import '../../chunk-M6JGMKA5.mjs';
5
+ import '../../chunk-CBLS46IE.mjs';
5
6
  import '../../chunk-TGP5M5R7.mjs';
6
- import '../../chunk-4COAUBLJ.mjs';
7
- import '../../chunk-DFZDV5FV.mjs';
7
+ import '../../chunk-HGJC5L65.mjs';
8
+ import '../../chunk-JXHUHFJ5.mjs';
8
9
  import '../../chunk-KMMJMDUA.mjs';
9
10
  import '../../chunk-U2BKYEC7.mjs';
10
- import '../../chunk-BFIH7OV5.mjs';
11
- import '../../chunk-WTONLDU3.mjs';
11
+ import '../../chunk-2GWVQWGA.mjs';
12
+ import '../../chunk-RDGXYRF4.mjs';
12
13
  import '../../chunk-P4ELXVJQ.mjs';
13
14
 
14
15
  // src/persistence/durability/rebuild.ts
package/dist/react.d.ts CHANGED
@@ -1,9 +1,9 @@
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-DDHjfXhJ.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-DDHjfXhJ.js';
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-FjWhZN3f.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-FjWhZN3f.js';
3
3
  import { e as TaskRecord, d as TaskProgress, b as ImportResult, c as TaskListQuery, T as TaskListPage } from './tasks-Bn4R1NPN.js';
4
4
  export { I as ImportError, f as TaskStatus, g as TaskType } from './tasks-Bn4R1NPN.js';
5
5
  import { ReactNode, ReactElement } from 'react';
6
- import { N as NarsilClient, I as ImportSource } from './client-C5BkUqB8.js';
6
+ import { N as NarsilClient, I as ImportSource } from './client-DX7xPcNA.js';
7
7
  import { A as AnyDocument } from './schema-B7juWg8Q.js';
8
8
  import './adapters-79OIa4xm.js';
9
9
 
package/dist/react.mjs CHANGED
@@ -140,6 +140,12 @@ var NarsilError = class extends Error {
140
140
  }
141
141
  };
142
142
 
143
+ // src/react/constants.ts
144
+ var DEFAULT_KEEP_ALIVE_MS = 2e3;
145
+ var DEFAULT_TASK_POLL_INTERVAL_MS = 250;
146
+ var ERROR_RETRY_INTERVAL_MS = 5e3;
147
+ var MAX_QUERY_KEY_DEPTH = 32;
148
+
143
149
  // src/react/failure.ts
144
150
  function asNarsilError(err, whatFailed) {
145
151
  if (err instanceof NarsilError) return err;
@@ -148,7 +154,6 @@ function asNarsilError(err, whatFailed) {
148
154
  }
149
155
 
150
156
  // src/react/store.ts
151
- var DEFAULT_KEEP_ALIVE_MS = 2e3;
152
157
  var LOADING_SNAPSHOT = Object.freeze({
153
158
  data: void 0,
154
159
  error: void 0,
@@ -298,7 +303,6 @@ function useNarsilClient() {
298
303
  }
299
304
 
300
305
  // src/react/key.ts
301
- var MAX_DEPTH = 32;
302
306
  function refuse(reason) {
303
307
  return new NarsilError(
304
308
  ErrorCodes.CONFIG_INVALID,
@@ -351,7 +355,7 @@ function write(value, out, depth, seen) {
351
355
  case "symbol":
352
356
  throw refuse(`is a ${typeof value}, which carries no value a request depends on`);
353
357
  }
354
- if (depth >= MAX_DEPTH) throw refuse(`nests deeper than ${MAX_DEPTH} levels`);
358
+ if (depth >= MAX_QUERY_KEY_DEPTH) throw refuse(`nests deeper than ${MAX_QUERY_KEY_DEPTH} levels`);
355
359
  const held = value;
356
360
  if (seen.includes(held)) throw refuse("holds a reference back to itself");
357
361
  seen.push(held);
@@ -516,8 +520,6 @@ function useDocuments(indexName, params, options) {
516
520
  }
517
521
 
518
522
  // src/react/task-state.ts
519
- var DEFAULT_TASK_POLL_INTERVAL_MS = 250;
520
- var ERROR_RETRY_INTERVAL_MS = 5e3;
521
523
  function pollInterval(interval, failed) {
522
524
  return failed ? Math.max(interval, ERROR_RETRY_INTERVAL_MS) : interval;
523
525
  }
@@ -467,6 +467,21 @@ interface ProcessMemoryReport {
467
467
  /** The process occupies this much physical memory in total. */
468
468
  rss: number;
469
469
  }
470
+ /**
471
+ * Whether one index holds worker copies at the moment
472
+ * {@link Narsil.getMemoryStats} reads it, and how many times it has loaded
473
+ * them again after giving them up while idle.
474
+ *
475
+ * @public
476
+ */
477
+ interface WorkerCopyReport {
478
+ /** This names the index. */
479
+ indexName: string;
480
+ /** This is true while every worker holds a copy of the index. */
481
+ scaledOut: boolean;
482
+ /** The index has loaded its copies again this many times after an idle spell dropped them. */
483
+ reloadCount: number;
484
+ }
470
485
  /**
471
486
  * What {@link Narsil.getMemoryStats} returns, which is what you size a host
472
487
  * from.
@@ -495,9 +510,11 @@ interface MemoryStats {
495
510
  closedIndexCount: number;
496
511
  /** This counts successful index loads since this engine started. */
497
512
  reopenCount: number;
513
+ /** One entry per index, saying whether it holds worker copies now and how many times it has reloaded them. */
514
+ workerCopies: WorkerCopyReport[];
498
515
  /**
499
- * Per-worker V8 heap usage when the engine has been promoted to a worker
500
- * pool. Empty when no workers are active.
516
+ * Per-worker V8 heap usage once the engine has started its worker pool.
517
+ * Empty while no worker is running.
501
518
  */
502
519
  workers: Array<{
503
520
  /** This identifies the worker within the pool. */
@@ -1047,4 +1064,4 @@ interface ListParams {
1047
1064
  document?: DocumentProjection;
1048
1065
  }
1049
1066
 
1050
- 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 ScoreComponents as J, type SearchMode as K, type ListParams as L, type MemoryStats as M, NarsilError as N, type SortField as O, type PartitionStatsResult as P, type QueryParams as Q, type SortSpec as R, type ServerErrorCode as S, type StringFilter as T, type TermMatchPolicy as U, type VectorMaintenanceResult as V, type VectorQueryConfig as W, 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, type SuggestParams as i, type SuggestResult as j, type ComparisonFilter as k, type FacetResult as l, type FieldFilter as m, type FilterExpression as n, type GeoPolygonFilter as o, type GeoRadiusFilter as p, type GroupConfig as q, type GroupReducer as r, type GroupResult as s, type HighlightMatch as t, type Hit as u, type HybridConfig as v, type ListedDocument as w, type PresenceFilter as x, type ProcessMemoryReport as y, type QueryCoverage as z };
1067
+ 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 ScoreComponents as J, type SearchMode as K, type ListParams as L, type MemoryStats as M, NarsilError as N, type SortField as O, type PartitionStatsResult as P, type QueryParams as Q, type SortSpec as R, type ServerErrorCode as S, type StringFilter as T, type TermMatchPolicy as U, type VectorMaintenanceResult as V, type VectorQueryConfig as W, type WorkerCopyReport as X, 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, type SuggestParams as i, type SuggestResult as j, type ComparisonFilter as k, type FacetResult as l, type FieldFilter as m, type FilterExpression as n, type GeoPolygonFilter as o, type GeoRadiusFilter as p, type GroupConfig as q, type GroupReducer as r, type GroupResult as s, type HighlightMatch as t, type Hit as u, type HybridConfig as v, type ListedDocument as w, type PresenceFilter as x, type ProcessMemoryReport as y, type QueryCoverage as z };
package/dist/server.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- import { b as ServerOptions, N as NarsilServer } from './options-BC68VPoE.js';
2
- export { A as ASYNC_IMPORT_CAPABILITY, C as CorsOptions, E as ErrorEnvelope, I as INDEX_LIFECYCLE_CAPABILITY, O as OnRequestHook, R as REBUILD_ANALYSIS_CAPABILITY, c as RequestContext, d as RequestDenial, S as SERVER_CAPABILITIES, e as ServerLimits, T as TASK_CANCEL_CAPABILITY, a as TASK_FILTER_CAPABILITY } from './options-BC68VPoE.js';
3
- import { a as Narsil } from './engine-Cjr1uBLa.js';
1
+ import { b as ServerOptions, N as NarsilServer } from './options-Dtk99qUs.js';
2
+ export { A as ASYNC_IMPORT_CAPABILITY, C as CorsOptions, E as ErrorEnvelope, I as INDEX_LIFECYCLE_CAPABILITY, O as OnRequestHook, R as REBUILD_ANALYSIS_CAPABILITY, c as RequestContext, d as RequestDenial, S as SERVER_CAPABILITIES, e as ServerLimits, T as TASK_CANCEL_CAPABILITY, a as TASK_FILTER_CAPABILITY } from './options-Dtk99qUs.js';
3
+ import { a as Narsil } from './engine-CABZg25p.js';
4
4
  import { h as TaskStore, e as TaskRecord, d as TaskProgress, b as ImportResult } from './tasks-Bn4R1NPN.js';
5
5
  export { C as CapabilitiesResponse, a as CreateIndexEmbedding, i as CreateIndexRequest, H as HttpIndexConfig, I as ImportError, T as TaskListPage, c as TaskListQuery, f as TaskStatus, g as TaskType } from './tasks-Bn4R1NPN.js';
6
- export { d as ServerErrorCodes } from './search-DDHjfXhJ.js';
7
- import './config-B-ZI-ft5.js';
8
- import './config-BZRExglL.js';
6
+ export { d as ServerErrorCodes } from './search-FjWhZN3f.js';
9
7
  import './adapters-79OIa4xm.js';
8
+ import './config-B41W23Us.js';
9
+ import './config-Co-zAXqO.js';
10
10
  import './schema-B7juWg8Q.js';
11
11
  import './types-DsSSjY4d.js';
12
12
  import './types-D5OwhtsQ.js';
package/dist/server.mjs CHANGED
@@ -1,4 +1,6 @@
1
- import { validateIndexName } from './chunk-XWICBGYT.mjs';
1
+ import { validateIndexName } from './chunk-KGRYQVZ5.mjs';
2
+ import './chunk-OWCFK42Q.mjs';
3
+ import { MAX_SORT_FIELDS } from './chunk-CBLS46IE.mjs';
2
4
  import { ServerErrorCodes, NarsilError, ErrorCodes } from './chunk-P4ELXVJQ.mjs';
3
5
  export { ServerErrorCodes } from './chunk-P4ELXVJQ.mjs';
4
6
  import { randomUUID } from 'crypto';
@@ -17,6 +19,25 @@ var SERVER_CAPABILITIES = [
17
19
  INDEX_LIFECYCLE_CAPABILITY
18
20
  ];
19
21
 
22
+ // src/server/constants.ts
23
+ var BYTES_PER_MB = 1024 * 1024;
24
+ var DEFAULT_MAX_BODY_BYTES = 16 * BYTES_PER_MB;
25
+ var DEFAULT_MAX_IMPORT_BYTES = 100 * BYTES_PER_MB;
26
+ var DEFAULT_MAX_LINE_BYTES = 4 * BYTES_PER_MB;
27
+ var DEFAULT_IMPORT_BATCH_SIZE = 1e3;
28
+ var DEFAULT_MAX_CONCURRENT_REQUESTS = 0;
29
+ var DEFAULT_MAX_RESULT_WINDOW = 1e4;
30
+ var DEFAULT_MAX_FETCH_DOCUMENTS = 1e4;
31
+ var DEFAULT_MAX_IMPORT_ERRORS = 100;
32
+ var DEFAULT_MAX_TASK_PAGE_SIZE = 1e3;
33
+ var DEFAULT_MAX_CONCURRENT_TASKS = 4;
34
+ var RESPONSE_STREAM_THRESHOLD_BYTES = 64 * 1024;
35
+ var DEFAULT_MAX_RETAINED_TASKS = 1e3;
36
+ var DEFAULT_TASK_PAGE_SIZE = 20;
37
+ var TASK_PROGRESS_WRITE_INTERVAL_MS = 250;
38
+ var RUNNING_TASK_TTL_MS = 24 * 60 * 60 * 1e3;
39
+ var TERMINAL_TASK_TTL_MS = 60 * 60 * 1e3;
40
+
20
41
  // src/server/cors.ts
21
42
  function resolveCors(cors) {
22
43
  if (!cors) return null;
@@ -196,7 +217,6 @@ var STATUS_TEXT = {
196
217
  500: "500 Internal Server Error",
197
218
  503: "503 Service Unavailable"
198
219
  };
199
- var STREAM_THRESHOLD = 64 * 1024;
200
220
  function statusLine(status) {
201
221
  return STATUS_TEXT[status] ?? `${status}`;
202
222
  }
@@ -217,7 +237,7 @@ function streamBody(res, abort, body, status, contentType) {
217
237
  }
218
238
  function sendJson(res, data, status = 200, abort) {
219
239
  const payload = encodeJson(data);
220
- if (abort && payload !== void 0 && Buffer.byteLength(payload) >= STREAM_THRESHOLD) {
240
+ if (abort && payload !== void 0 && Buffer.byteLength(payload) >= RESPONSE_STREAM_THRESHOLD_BYTES) {
221
241
  streamBody(res, abort, Buffer.from(payload, "utf8"), status, "application/json");
222
242
  return;
223
243
  }
@@ -287,7 +307,6 @@ function serializeBatchResult(result) {
287
307
  }
288
308
 
289
309
  // src/server/validation.ts
290
- var MAX_LIST_SORT_FIELDS = 8;
291
310
  function isPlainObject(value) {
292
311
  return typeof value === "object" && value !== null && !Array.isArray(value);
293
312
  }
@@ -369,10 +388,10 @@ function validateListSort(sort) {
369
388
  const entries = Array.isArray(sort) ? sort.map(
370
389
  (entry) => typeof entry === "object" && entry !== null ? [entry.field, entry.direction] : [entry, void 0]
371
390
  ) : Object.entries(sort);
372
- if (entries.length > MAX_LIST_SORT_FIELDS) {
391
+ if (entries.length > MAX_SORT_FIELDS) {
373
392
  return {
374
- message: `Field "sort" exceeds the maximum of ${MAX_LIST_SORT_FIELDS} fields`,
375
- details: { count: entries.length, limit: MAX_LIST_SORT_FIELDS }
393
+ message: `Field "sort" exceeds the maximum of ${MAX_SORT_FIELDS} fields`,
394
+ details: { count: entries.length, limit: MAX_SORT_FIELDS }
376
395
  };
377
396
  }
378
397
  for (const [field, direction] of entries) {
@@ -1408,7 +1427,6 @@ async function loadUWebSockets() {
1408
1427
  }
1409
1428
 
1410
1429
  // src/server/task-store.ts
1411
- var DEFAULT_MAX_RETAINED = 1e3;
1412
1430
  var InMemoryTaskStore = class {
1413
1431
  /**
1414
1432
  * Builds a store that keeps task records in this process alone.
@@ -1416,7 +1434,7 @@ var InMemoryTaskStore = class {
1416
1434
  * @param maxRetained - Records to keep before the oldest finished ones are
1417
1435
  * dropped. Defaults to 1000.
1418
1436
  */
1419
- constructor(maxRetained = DEFAULT_MAX_RETAINED) {
1437
+ constructor(maxRetained = DEFAULT_MAX_RETAINED_TASKS) {
1420
1438
  this.maxRetained = maxRetained;
1421
1439
  }
1422
1440
  records = /* @__PURE__ */ new Map();
@@ -1464,10 +1482,6 @@ var InMemoryTaskStore = class {
1464
1482
  }
1465
1483
  }
1466
1484
  };
1467
- var RUNNING_TTL_MS = 24 * 60 * 60 * 1e3;
1468
- var TERMINAL_TTL_MS = 60 * 60 * 1e3;
1469
- var PROGRESS_WRITE_INTERVAL_MS = 250;
1470
- var DEFAULT_TASK_PAGE_SIZE = 20;
1471
1485
  function byNewestFirst(left, right) {
1472
1486
  if (left.createdAt !== right.createdAt) return right.createdAt - left.createdAt;
1473
1487
  return left.id.localeCompare(right.id);
@@ -1517,7 +1531,7 @@ var TaskRegistry = class {
1517
1531
  settled: false
1518
1532
  };
1519
1533
  this.live.set(record.id, task);
1520
- await this.enqueueWrite(task, record, RUNNING_TTL_MS);
1534
+ await this.enqueueWrite(task, record, RUNNING_TASK_TTL_MS);
1521
1535
  void this.drive(task, op);
1522
1536
  return record;
1523
1537
  }
@@ -1552,7 +1566,7 @@ var TaskRegistry = class {
1552
1566
  task.controller.abort(new Error("The task was cancelled"));
1553
1567
  const record = { ...task.record, cancelRequestedAt: Date.now() };
1554
1568
  task.record = record;
1555
- await this.enqueueWrite(task, record, RUNNING_TTL_MS);
1569
+ await this.enqueueWrite(task, record, RUNNING_TASK_TTL_MS);
1556
1570
  return { outcome: "cancelling", record };
1557
1571
  }
1558
1572
  /** Fails this instance's previously-running tasks after a restart. A task can
@@ -1578,7 +1592,7 @@ var TaskRegistry = class {
1578
1592
  error: { code: ServerErrorCodes.TASK_INTERRUPTED, message: "The server restarted while this task was running" }
1579
1593
  };
1580
1594
  try {
1581
- await this.store.set(failed, TERMINAL_TTL_MS);
1595
+ await this.store.set(failed, TERMINAL_TASK_TTL_MS);
1582
1596
  } catch {
1583
1597
  }
1584
1598
  }
@@ -1595,9 +1609,9 @@ var TaskRegistry = class {
1595
1609
  if (task.settled) return;
1596
1610
  task.record = { ...task.record, progress };
1597
1611
  const now = Date.now();
1598
- if (now - task.lastProgressWriteAt < PROGRESS_WRITE_INTERVAL_MS) return;
1612
+ if (now - task.lastProgressWriteAt < TASK_PROGRESS_WRITE_INTERVAL_MS) return;
1599
1613
  task.lastProgressWriteAt = now;
1600
- void this.enqueueWrite(task, task.record, RUNNING_TTL_MS);
1614
+ void this.enqueueWrite(task, task.record, RUNNING_TASK_TTL_MS);
1601
1615
  }
1602
1616
  async drive(task, op) {
1603
1617
  const context = {
@@ -1620,25 +1634,24 @@ var TaskRegistry = class {
1620
1634
  }
1621
1635
  task.settled = true;
1622
1636
  task.record = { ...settled, completedAt: Date.now() };
1623
- await this.enqueueWrite(task, task.record, TERMINAL_TTL_MS);
1637
+ await this.enqueueWrite(task, task.record, TERMINAL_TASK_TTL_MS);
1624
1638
  this.live.delete(task.record.id);
1625
1639
  }
1626
1640
  };
1627
1641
 
1628
1642
  // src/server/create-server.ts
1629
- var MB = 1024 * 1024;
1630
1643
  function resolveLimits(limits) {
1631
1644
  return {
1632
- maxBodyBytes: limits?.maxBodyBytes ?? 16 * MB,
1633
- maxImportBytes: limits?.maxImportBytes ?? 100 * MB,
1634
- maxLineBytes: limits?.maxLineBytes ?? 4 * MB,
1635
- importBatchSize: limits?.importBatchSize ?? 1e3,
1636
- maxConcurrentRequests: limits?.maxConcurrentRequests ?? 0,
1637
- maxResultWindow: limits?.maxResultWindow ?? 1e4,
1638
- maxFetchDocuments: limits?.maxFetchDocuments ?? 1e4,
1639
- maxImportErrors: limits?.maxImportErrors ?? 100,
1640
- maxTaskPageSize: limits?.maxTaskPageSize ?? 1e3,
1641
- maxConcurrentTasks: limits?.maxConcurrentTasks ?? 4
1645
+ maxBodyBytes: limits?.maxBodyBytes ?? DEFAULT_MAX_BODY_BYTES,
1646
+ maxImportBytes: limits?.maxImportBytes ?? DEFAULT_MAX_IMPORT_BYTES,
1647
+ maxLineBytes: limits?.maxLineBytes ?? DEFAULT_MAX_LINE_BYTES,
1648
+ importBatchSize: limits?.importBatchSize ?? DEFAULT_IMPORT_BATCH_SIZE,
1649
+ maxConcurrentRequests: limits?.maxConcurrentRequests ?? DEFAULT_MAX_CONCURRENT_REQUESTS,
1650
+ maxResultWindow: limits?.maxResultWindow ?? DEFAULT_MAX_RESULT_WINDOW,
1651
+ maxFetchDocuments: limits?.maxFetchDocuments ?? DEFAULT_MAX_FETCH_DOCUMENTS,
1652
+ maxImportErrors: limits?.maxImportErrors ?? DEFAULT_MAX_IMPORT_ERRORS,
1653
+ maxTaskPageSize: limits?.maxTaskPageSize ?? DEFAULT_MAX_TASK_PAGE_SIZE,
1654
+ maxConcurrentTasks: limits?.maxConcurrentTasks ?? DEFAULT_MAX_CONCURRENT_TASKS
1642
1655
  };
1643
1656
  }
1644
1657
  function resolveBuild(build) {
@@ -1,9 +1,7 @@
1
- import { createVectorStore, createHNSWIndex } from '../chunk-DFZDV5FV.mjs';
2
- import '../chunk-BFIH7OV5.mjs';
1
+ import { createVectorStore, createHNSWIndex, MAX_WORKER_DIMENSION, MAX_WORKER_VECTORS } from '../chunk-JXHUHFJ5.mjs';
2
+ import '../chunk-2GWVQWGA.mjs';
3
3
 
4
4
  // src/vector/hnsw-build-worker.ts
5
- var MAX_WORKER_DIMENSION = 8192;
6
- var MAX_WORKER_VECTORS = 1e6;
7
5
  function validateBuildRequest(request) {
8
6
  if (typeof request.dimension !== "number" || request.dimension <= 0 || request.dimension > MAX_WORKER_DIMENSION) {
9
7
  throw new Error(`Invalid dimension: ${request.dimension} (must be 1..${MAX_WORKER_DIMENSION})`);
@@ -1,6 +1,6 @@
1
- import { createScalarQuantizer, deriveSq8Constants, arenaQuantizedDistance, quantizeVectorInto, quantizedMagnitude, scalarQuantizedDistance } from '../chunk-4COAUBLJ.mjs';
2
- import { searchOrdinals, createVectorStore, createHNSWIndex, createSharedArenaSimd, importAdjacency, createHNSWWorkspace, arenaFloat32Distance, ABSENT_DOCUMENT_RANK } from '../chunk-DFZDV5FV.mjs';
3
- import '../chunk-BFIH7OV5.mjs';
1
+ import { createScalarQuantizer, deriveSq8Constants, arenaQuantizedDistance, quantizeVectorInto, quantizedMagnitude, scalarQuantizedDistance } from '../chunk-HGJC5L65.mjs';
2
+ import { searchOrdinals, MAX_WORKER_COPIES, createVectorStore, createHNSWIndex, createSharedArenaSimd, importAdjacency, createHNSWWorkspace, arenaFloat32Distance, ABSENT_DOCUMENT_RANK } from '../chunk-JXHUHFJ5.mjs';
3
+ import '../chunk-2GWVQWGA.mjs';
4
4
 
5
5
  // src/vector/shared-generation/worker-view.ts
6
6
  function createVectorReader(snapshot, simd, scratchSlot) {
@@ -156,7 +156,6 @@ function restoreWorkerCopy(snapshot) {
156
156
  }
157
157
 
158
158
  // src/vector/search-worker.ts
159
- var MAX_WORKER_COPIES = 64;
160
159
  var copies = /* @__PURE__ */ new Map();
161
160
  function ensureRoom(handle) {
162
161
  if (!copies.has(handle) && copies.size >= MAX_WORKER_COPIES) {
@@ -1,4 +1,4 @@
1
- import { isValidWorkerAction } from '../chunk-WTONLDU3.mjs';
1
+ import { isValidWorkerAction } from '../chunk-RDGXYRF4.mjs';
2
2
  import { NarsilError, ErrorCodes } from '../chunk-P4ELXVJQ.mjs';
3
3
 
4
4
  // src/workers/action-handler.ts
@@ -55,7 +55,7 @@ async function setup() {
55
55
  } catch {
56
56
  parentPort = null;
57
57
  }
58
- const { createDirectExecutor } = await import('../direct-executor-EOTFGXTO.mjs');
58
+ const { createDirectExecutor } = await import('../direct-executor-HRTDWMVB.mjs');
59
59
  const handleAction = createActionHandler(createDirectExecutor());
60
60
  if (parentPort) {
61
61
  const port = parentPort;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delali/narsil",
3
- "version": "0.2.4-next.47",
3
+ "version": "0.2.4-next.49",
4
4
  "type": "module",
5
5
  "description": "A distributed full-text search engine with cross-language portable binary format.",
6
6
  "author": "Delali (https://sondelali.com)",
@@ -1,8 +0,0 @@
1
- export { createDirectExecutor } from './chunk-EV45L35L.mjs';
2
- import './chunk-TGP5M5R7.mjs';
3
- import './chunk-4COAUBLJ.mjs';
4
- import './chunk-DFZDV5FV.mjs';
5
- import './chunk-U2BKYEC7.mjs';
6
- import './chunk-BFIH7OV5.mjs';
7
- import './chunk-WTONLDU3.mjs';
8
- import './chunk-P4ELXVJQ.mjs';