@delali/narsil 0.2.0 → 0.2.1-next.25

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 (151) hide show
  1. package/dist/adapters/filesystem.d.ts +23 -1
  2. package/dist/adapters/filesystem.mjs +1 -1
  3. package/dist/adapters/indexeddb.d.ts +25 -1
  4. package/dist/adapters/indexeddb.mjs +1 -1
  5. package/dist/adapters/memory.d.ts +14 -1
  6. package/dist/adapters-CVqI5NBt.d.ts +149 -0
  7. package/dist/{chunk-S6IAXOBA.mjs → chunk-ASI6AOW2.mjs} +1 -1
  8. package/dist/{chunk-AUMKFYTG.mjs → chunk-FKK76OR7.mjs} +56 -55
  9. package/dist/{chunk-M2EDG55Y.mjs → chunk-UNJZ7ZDB.mjs} +10 -0
  10. package/dist/{chunk-XAKNSWIK.mjs → chunk-WLR5BFL3.mjs} +16 -14
  11. package/dist/config-CAjTHzkH.d.ts +256 -0
  12. package/dist/{direct-executor-2FV3MEDD.mjs → direct-executor-3W4QRA4E.mjs} +2 -2
  13. package/dist/distribution/coordinator/etcd.d.ts +44 -3
  14. package/dist/distribution/coordinator/etcd.mjs +2 -2
  15. package/dist/distribution/coordinator/in-memory.d.ts +14 -3
  16. package/dist/distribution.d.ts +312 -45
  17. package/dist/distribution.mjs +4 -4
  18. package/dist/embeddings/openai.d.ts +28 -1
  19. package/dist/embeddings/openai.mjs +1 -1
  20. package/dist/engine-CCrlfLyq.d.ts +431 -0
  21. package/dist/index.browser.mjs +24 -12
  22. package/dist/index.d.ts +173 -8
  23. package/dist/index.mjs +3 -3
  24. package/dist/invalidation/broadcast-channel.d.ts +20 -1
  25. package/dist/invalidation/filesystem.d.ts +24 -1
  26. package/dist/invalidation/noop.d.ts +14 -1
  27. package/dist/language-DB8KG1z5.d.ts +53 -0
  28. package/dist/languages/albanian.d.ts +11 -1
  29. package/dist/languages/amharic.d.ts +11 -1
  30. package/dist/languages/arabic.d.ts +10 -1
  31. package/dist/languages/armenian.d.ts +10 -1
  32. package/dist/languages/azerbaijani.d.ts +11 -1
  33. package/dist/languages/bambara.d.ts +11 -1
  34. package/dist/languages/basque.d.ts +10 -1
  35. package/dist/languages/belarusian.d.ts +11 -1
  36. package/dist/languages/bengali.d.ts +11 -1
  37. package/dist/languages/bosnian.d.ts +11 -1
  38. package/dist/languages/breton.d.ts +11 -1
  39. package/dist/languages/bulgarian.d.ts +10 -1
  40. package/dist/languages/burmese.d.ts +11 -1
  41. package/dist/languages/catalan.d.ts +10 -1
  42. package/dist/languages/chinese.d.ts +11 -1
  43. package/dist/languages/croatian.d.ts +11 -1
  44. package/dist/languages/czech.d.ts +10 -1
  45. package/dist/languages/dagbani.d.ts +11 -1
  46. package/dist/languages/danish.d.ts +10 -1
  47. package/dist/languages/dutch.d.ts +10 -1
  48. package/dist/languages/english.d.ts +10 -1
  49. package/dist/languages/esperanto.d.ts +10 -1
  50. package/dist/languages/estonian.d.ts +10 -1
  51. package/dist/languages/ewe.d.ts +11 -1
  52. package/dist/languages/faroese.d.ts +11 -1
  53. package/dist/languages/fijian.d.ts +11 -1
  54. package/dist/languages/finnish.d.ts +10 -1
  55. package/dist/languages/french.d.ts +10 -1
  56. package/dist/languages/ga.d.ts +11 -1
  57. package/dist/languages/galician.d.ts +11 -1
  58. package/dist/languages/georgian.d.ts +11 -1
  59. package/dist/languages/german.d.ts +10 -1
  60. package/dist/languages/greek.d.ts +10 -1
  61. package/dist/languages/guarani.d.ts +11 -1
  62. package/dist/languages/gujarati.d.ts +11 -1
  63. package/dist/languages/haitian-creole.d.ts +11 -1
  64. package/dist/languages/hausa.d.ts +11 -1
  65. package/dist/languages/hawaiian.d.ts +11 -1
  66. package/dist/languages/hebrew.d.ts +11 -1
  67. package/dist/languages/hindi.d.ts +10 -1
  68. package/dist/languages/hungarian.d.ts +10 -1
  69. package/dist/languages/icelandic.d.ts +11 -1
  70. package/dist/languages/igbo.d.ts +11 -1
  71. package/dist/languages/indonesian.d.ts +10 -1
  72. package/dist/languages/irish.d.ts +10 -1
  73. package/dist/languages/italian.d.ts +10 -1
  74. package/dist/languages/japanese.d.ts +11 -1
  75. package/dist/languages/kannada.d.ts +11 -1
  76. package/dist/languages/kazakh.d.ts +11 -1
  77. package/dist/languages/khmer.d.ts +11 -1
  78. package/dist/languages/kinyarwanda.d.ts +11 -1
  79. package/dist/languages/kirundi.d.ts +11 -1
  80. package/dist/languages/korean.d.ts +11 -1
  81. package/dist/languages/kurmanji.d.ts +11 -1
  82. package/dist/languages/kyrgyz.d.ts +11 -1
  83. package/dist/languages/lao.d.ts +11 -1
  84. package/dist/languages/latin.d.ts +11 -1
  85. package/dist/languages/latvian.d.ts +11 -1
  86. package/dist/languages/lingala.d.ts +11 -1
  87. package/dist/languages/lithuanian.d.ts +10 -1
  88. package/dist/languages/luxembourgish.d.ts +11 -1
  89. package/dist/languages/macedonian.d.ts +11 -1
  90. package/dist/languages/malagasy.d.ts +11 -1
  91. package/dist/languages/malay.d.ts +11 -1
  92. package/dist/languages/malayalam.d.ts +11 -1
  93. package/dist/languages/maltese.d.ts +11 -1
  94. package/dist/languages/maori.d.ts +11 -1
  95. package/dist/languages/marathi.d.ts +11 -1
  96. package/dist/languages/nepali.d.ts +10 -1
  97. package/dist/languages/norwegian.d.ts +10 -1
  98. package/dist/languages/oromo.d.ts +11 -1
  99. package/dist/languages/persian.d.ts +10 -1
  100. package/dist/languages/polish.d.ts +10 -1
  101. package/dist/languages/portuguese.d.ts +10 -1
  102. package/dist/languages/punjabi.d.ts +11 -1
  103. package/dist/languages/romanian.d.ts +10 -1
  104. package/dist/languages/russian.d.ts +10 -1
  105. package/dist/languages/samoan.d.ts +11 -1
  106. package/dist/languages/sanskrit.d.ts +10 -1
  107. package/dist/languages/scottish-gaelic.d.ts +11 -1
  108. package/dist/languages/serbian.d.ts +10 -1
  109. package/dist/languages/shona.d.ts +11 -1
  110. package/dist/languages/sinhala.d.ts +11 -1
  111. package/dist/languages/slovak.d.ts +11 -1
  112. package/dist/languages/slovenian.d.ts +10 -1
  113. package/dist/languages/sorani.d.ts +11 -1
  114. package/dist/languages/spanish.d.ts +10 -1
  115. package/dist/languages/swahili.d.ts +10 -1
  116. package/dist/languages/swedish.d.ts +10 -1
  117. package/dist/languages/tagalog.d.ts +11 -1
  118. package/dist/languages/tamil.d.ts +10 -1
  119. package/dist/languages/tatar.d.ts +11 -1
  120. package/dist/languages/telugu.d.ts +11 -1
  121. package/dist/languages/thai.d.ts +11 -1
  122. package/dist/languages/tibetan.d.ts +11 -1
  123. package/dist/languages/tigrinya.d.ts +11 -1
  124. package/dist/languages/tongan.d.ts +11 -1
  125. package/dist/languages/turkish.d.ts +10 -1
  126. package/dist/languages/twi.d.ts +11 -1
  127. package/dist/languages/ukrainian.d.ts +10 -1
  128. package/dist/languages/urdu.d.ts +11 -1
  129. package/dist/languages/vietnamese.d.ts +11 -1
  130. package/dist/languages/welsh.d.ts +11 -1
  131. package/dist/languages/wolof.d.ts +11 -1
  132. package/dist/languages/xhosa.d.ts +11 -1
  133. package/dist/languages/yoruba.d.ts +11 -1
  134. package/dist/languages/zulu.d.ts +11 -1
  135. package/dist/persistence/durability/checkpoint-worker.d.ts +2 -2
  136. package/dist/persistence/durability/checkpoint-worker.mjs +3 -3
  137. package/dist/schema-CE6S_aAr.d.ts +208 -0
  138. package/dist/search-CgQQIciB.d.ts +786 -0
  139. package/dist/server.d.ts +213 -12
  140. package/dist/server.mjs +29 -1
  141. package/dist/types-BV3nAKTL.d.ts +302 -0
  142. package/dist/vector/hnsw-build-worker.d.ts +68 -2
  143. package/dist/vector/hnsw-build-worker.mjs +0 -2
  144. package/dist/workers/entry.mjs +1 -1
  145. package/package.json +5 -2
  146. package/dist/adapters-Bo2JQg8b.d.ts +0 -37
  147. package/dist/config-P27AtSn4.d.ts +0 -502
  148. package/dist/language-CmJBHf1j.d.ts +0 -17
  149. package/dist/narsil-CMZRPDlQ.d.ts +0 -159
  150. package/dist/schema-BnvLvjRp.d.ts +0 -67
  151. package/dist/types-BRTcBgAp.d.ts +0 -73
package/dist/server.d.ts CHANGED
@@ -1,38 +1,72 @@
1
- import { N as Narsil } from './narsil-CMZRPDlQ.js';
2
- import { E as EmbeddingAdapter } from './adapters-Bo2JQg8b.js';
3
- import './schema-BnvLvjRp.js';
4
- import './config-P27AtSn4.js';
1
+ import { N as Narsil } from './engine-CCrlfLyq.js';
2
+ import { E as EmbeddingAdapter } from './adapters-CVqI5NBt.js';
3
+ import './search-CgQQIciB.js';
4
+ import './schema-CE6S_aAr.js';
5
5
 
6
6
  /**
7
7
  * Context handed to {@link OnRequestHook} for every inbound request, captured
8
8
  * synchronously before any body is read. `remoteAddress` is the peer address
9
9
  * decoded from the socket; behind a proxy it is the proxy's address, so trust
10
10
  * forwarded headers only when the proxy is trusted.
11
+ *
12
+ * @public
11
13
  */
12
14
  interface RequestContext {
15
+ /** The request used this HTTP method, in upper case. */
13
16
  method: string;
17
+ /** The request asked for this path, without the query string. */
14
18
  path: string;
19
+ /** These are the request headers, keyed by lower-case name. */
15
20
  headers: Record<string, string>;
21
+ /** The server decoded this peer address from the socket. */
16
22
  remoteAddress: string;
17
23
  }
18
24
  /**
19
25
  * Returned by an {@link OnRequestHook} to reject a request. The `status` is sent
20
26
  * verbatim as the HTTP status; `code` and `message` populate the error envelope.
27
+ *
28
+ * @public
21
29
  */
22
30
  interface RequestDenial {
31
+ /** The server answers with this status. */
23
32
  status: number;
33
+ /** The error envelope carries this machine-readable code. */
24
34
  code: string;
35
+ /** The error envelope carries this description. */
25
36
  message: string;
26
37
  }
38
+ /**
39
+ * Runs before every routed request, which is where authentication, rate
40
+ * limiting, and any other admission rule goes.
41
+ *
42
+ * @param ctx - The request's method, path, headers, and peer address.
43
+ * @returns A {@link RequestDenial} to reject the request, or `undefined` to
44
+ * let it through.
45
+ *
46
+ * @public
47
+ */
27
48
  type OnRequestHook = (ctx: RequestContext) => undefined | RequestDenial | Promise<undefined | RequestDenial>;
49
+ /**
50
+ * Which cross-origin requests the server accepts.
51
+ *
52
+ * Passing `true` for `cors` instead of this object accepts any origin, which
53
+ * suits local development and little else.
54
+ *
55
+ * @public
56
+ */
28
57
  interface CorsOptions {
58
+ /** The server allows these origins, given as one origin or a list. */
29
59
  origin?: string | string[];
60
+ /** The server allows these methods on a cross-origin request. */
30
61
  methods?: string[];
62
+ /** A browser may send these request headers cross-origin. */
31
63
  headers?: string[];
32
64
  }
33
65
  /**
34
66
  * Byte and batch ceilings the server enforces before handing work to the
35
67
  * engine. Every field has a safe default; override only to fit a deployment.
68
+ *
69
+ * @public
36
70
  */
37
71
  interface ServerLimits {
38
72
  /** Cap for JSON request bodies (single doc, batch, search). Excess → 413. */
@@ -54,9 +88,20 @@ interface ServerLimits {
54
88
  * Defaults to 10000. */
55
89
  maxFetchDocuments?: number;
56
90
  }
91
+ /**
92
+ * Everything {@link createServer} accepts.
93
+ *
94
+ * Every field is optional, and a server created without any of them binds to
95
+ * loopback with the default limits and no authentication.
96
+ *
97
+ * @public
98
+ */
57
99
  interface ServerOptions {
100
+ /** The server binds to this address, and to loopback by default. Any other address needs an authentication hook. */
58
101
  host?: string;
102
+ /** The server binds to this port. Pass 0 to let the operating system choose one, then read {@link NarsilServer.listeningPort}. */
59
103
  port?: number;
104
+ /** These settings control which cross-origin requests the server accepts, and `true` accepts any origin. */
60
105
  cors?: boolean | CorsOptions;
61
106
  /** Authentication or admission gate run before every routed request. */
62
107
  onRequest?: OnRequestHook;
@@ -77,6 +122,7 @@ interface ServerOptions {
77
122
  * needs query-time or ingest-time embedding names a server-registered adapter.
78
123
  */
79
124
  embeddingAdapters?: Record<string, EmbeddingAdapter>;
125
+ /** These ceilings apply before the server hands any work to the engine. */
80
126
  limits?: ServerLimits;
81
127
  /**
82
128
  * Backing store for long-running task records. Defaults to an in-memory store
@@ -93,52 +139,127 @@ interface ServerOptions {
93
139
  */
94
140
  instanceId?: string;
95
141
  /**
96
- * Allows binding to a non-loopback address without an {@link onRequest} auth
97
- * hook. The server otherwise refuses to start in that configuration because it
98
- * exposes destructive admin endpoints. Set this only when the address is on a
99
- * trusted private network where access is controlled elsewhere.
142
+ * Allows binding to a non-loopback address without an
143
+ * {@link ServerOptions.onRequest} auth hook. The server otherwise refuses to
144
+ * start in that configuration because it exposes destructive admin endpoints.
145
+ * Set this only when the address is on a trusted private network where access
146
+ * is controlled elsewhere.
100
147
  */
101
148
  allowInsecure?: boolean;
102
149
  }
103
150
  /**
104
151
  * Pluggable backing store for task records. Every method is async so any
105
- * backend works — an in-memory map, Redis, an HTTP key-value service, or a
152
+ * backend works: an in-memory map, Redis, an HTTP key-value service, or a
106
153
  * database. `set` upserts by `record.id`; `get` returns null for an unknown id.
107
154
  * `ttlMs`, when honored by the backend, expires the record so terminal tasks do
108
155
  * not accumulate. The server never calls a method that mutates a record it did
109
156
  * not construct, so a backend may treat records as immutable snapshots.
157
+ *
158
+ * @public
110
159
  */
111
160
  interface TaskStore {
161
+ /**
162
+ * Stores a record, replacing whatever its id already held.
163
+ *
164
+ * @param record - The record to store.
165
+ * @param ttlMs - Milliseconds after which the backend may drop it, which
166
+ * keeps finished tasks from accumulating. Ignore it in a backend without
167
+ * expiry.
168
+ */
112
169
  set(record: TaskRecord, ttlMs?: number): Promise<void>;
170
+ /**
171
+ * Reads one record back.
172
+ *
173
+ * @param id - The task to read.
174
+ * @returns The record, or `null` when the store holds no such id.
175
+ */
113
176
  get(id: string): Promise<TaskRecord | null>;
177
+ /**
178
+ * Lists every record the store holds.
179
+ *
180
+ * @returns Each record the backend still has.
181
+ */
114
182
  list(): Promise<TaskRecord[]>;
183
+ /**
184
+ * Removes one record. An id the store never held is not an error.
185
+ *
186
+ * @param id - The task to remove.
187
+ */
115
188
  delete(id: string): Promise<void>;
189
+ /** Releases whatever the backend holds open, such as a connection pool. */
116
190
  shutdown?(): Promise<void>;
117
191
  }
192
+ /**
193
+ * The running HTTP server, as {@link createServer} returns it.
194
+ *
195
+ * @public
196
+ */
118
197
  interface NarsilServer {
198
+ /**
199
+ * Binds the socket and starts answering requests.
200
+ *
201
+ * @throws An error when the address is already in use, or when a non-loopback
202
+ * address is configured without an authentication hook.
203
+ */
119
204
  listen(): Promise<void>;
205
+ /** Closes the socket and ends the server. The engine keeps running. */
120
206
  close(): Promise<void>;
207
+ /** The server bound to this port, which is what you read after binding to port 0. */
121
208
  readonly listeningPort: number;
122
209
  }
210
+ /**
211
+ * The body every failed response carries, which is what an HTTP client parses
212
+ * on a non-2xx status.
213
+ *
214
+ * @public
215
+ */
123
216
  interface ErrorEnvelope {
217
+ /** This describes the failure. */
124
218
  error: {
219
+ /** This code comes from either {@link ServerErrorCodes} or {@link ErrorCodes}. */
125
220
  code: string;
221
+ /** This describes the failure, for a log or a person. */
126
222
  message: string;
223
+ /** These values are behind the failure, such as the field or limit involved. */
127
224
  details?: Record<string, unknown>;
128
225
  };
129
226
  }
227
+ /**
228
+ * Which long-running operation a task record tracks.
229
+ *
230
+ * @public
231
+ */
130
232
  type TaskType = 'optimizeVectors' | 'rebalance' | 'restore';
233
+ /**
234
+ * Where a long-running operation stands.
235
+ *
236
+ * @public
237
+ */
131
238
  type TaskStatus = 'queued' | 'running' | 'succeeded' | 'failed';
239
+ /**
240
+ * One long-running operation, which the server answers with straight away and
241
+ * you then poll.
242
+ *
243
+ * @public
244
+ */
132
245
  interface TaskRecord {
246
+ /** This identifies the task, and is what you poll by. */
133
247
  id: string;
248
+ /** This says which operation the task runs. */
134
249
  type: TaskType;
250
+ /** The operation runs against this index. */
135
251
  indexName: string;
252
+ /** This says where the operation stands. */
136
253
  status: TaskStatus;
137
254
  /** Identifier of the server instance running this task; see ServerOptions.instanceId. */
138
255
  owner: string;
256
+ /** The server accepted the task at this many milliseconds since the epoch. */
139
257
  createdAt: number;
258
+ /** Work started at this many milliseconds since the epoch, and a queued task omits it. */
140
259
  startedAt?: number;
260
+ /** Work ended at this many milliseconds since the epoch, and a task omits it until it succeeds or fails. */
141
261
  completedAt?: number;
262
+ /** This says why the task failed, and a failed task alone carries it. */
142
263
  error?: {
143
264
  code: string;
144
265
  message: string;
@@ -148,34 +269,70 @@ interface TaskRecord {
148
269
  /** Declarative index configuration accepted over HTTP. Function-valued engine
149
270
  * options (custom tokenizer, stopWords-as-function, group reducer, embedding
150
271
  * adapter object) are not representable here; the embedding adapter is named
151
- * instead via {@link CreateIndexEmbedding}. */
272
+ * instead via {@link CreateIndexEmbedding}.
273
+ *
274
+ * @public */
152
275
  interface CreateIndexRequest {
276
+ /** The server creates the index under this name. */
153
277
  name: string;
278
+ /** This carries the schema and settings, in the subset JSON can express. */
154
279
  config: HttpIndexConfig;
155
280
  }
281
+ /**
282
+ * How a JSON `createIndex` request connects an index to an embedding adapter.
283
+ *
284
+ * An adapter is a function and cannot cross JSON, so the request names one the
285
+ * server registered instead of carrying it.
286
+ *
287
+ * @public
288
+ */
156
289
  interface CreateIndexEmbedding {
290
+ /** This names an adapter the server registered under `embeddingAdapters`. */
157
291
  adapter?: string;
292
+ /** This maps each vector field to the text field, or fields, the server embeds into it. */
158
293
  fields: Record<string, string | string[]>;
159
294
  }
295
+ /**
296
+ * The index settings a JSON request can carry, which is {@link IndexConfig}
297
+ * minus everything that is a function.
298
+ *
299
+ * A custom tokeniser, a stop-word function, and an embedding adapter object
300
+ * have no JSON form, so an HTTP client names a registered one or supplies a
301
+ * plain list instead.
302
+ *
303
+ * @public
304
+ */
160
305
  interface HttpIndexConfig {
306
+ /** This layout gives each value as either a field type or a nested schema. */
161
307
  schema: Record<string, unknown>;
308
+ /** The server tokenises and stems text fields with the language module registered under this name. */
162
309
  language?: string;
310
+ /** These settings control how the index splits documents across partitions as it grows. */
163
311
  partitions?: {
164
312
  maxDocsPerPartition?: number;
165
313
  maxPartitions?: number;
166
314
  watermark?: number;
167
315
  };
316
+ /** A query scores this way unless it asks for another mode. */
168
317
  defaultScoring?: 'local' | 'dfs' | 'broadcast';
318
+ /** These parameters tune BM25 for this index. */
169
319
  bm25?: {
170
320
  k1?: number;
171
321
  b?: number;
172
322
  };
323
+ /** This list replaces the language's stop words. */
173
324
  stopWords?: string[];
325
+ /** Setting this records term positions, which phrase queries and highlighting need. */
174
326
  trackPositions?: boolean;
327
+ /** Setting this returns the words users typed from suggestions and prefix expansion, instead of index stems. */
175
328
  surfaceForms?: boolean;
329
+ /** These settings control when vector fields move to an HNSW graph, and how that graph is built. */
176
330
  vectorPromotion?: Record<string, unknown>;
331
+ /** Setting this rejects a document carrying a field the schema does not declare. */
177
332
  strict?: boolean;
333
+ /** This names a server-registered embedding adapter and the fields it embeds. */
178
334
  embedding?: CreateIndexEmbedding;
335
+ /** The server rejects a document that omits any of these fields. */
179
336
  required?: string[];
180
337
  }
181
338
 
@@ -184,12 +341,21 @@ interface HttpIndexConfig {
184
341
  * (durability, embedding, workers) and hands the live instance in; the server
185
342
  * shares it across requests and never constructs or shuts it down. Start with
186
343
  * `.listen()` and stop with `.close()`; the engine is shut down separately.
344
+ *
345
+ * @param engine - The live engine every request runs against.
346
+ * @param options - Address, CORS, request limits, the authentication hook, and
347
+ * the task store. Omit it to bind to loopback with the default limits.
348
+ * @returns The server, ready for {@link NarsilServer.listen}.
349
+ *
350
+ * @public
187
351
  */
188
352
  declare function createServer(engine: Narsil, options?: ServerOptions): NarsilServer;
189
353
 
190
354
  /** HTTP-layer error codes for failures that arise before or around the engine
191
355
  * call (parsing, limits, routing). Engine failures carry their own
192
- * {@link NarsilError} codes, mapped by {@link httpStatusForNarsilError}. */
356
+ * {@link NarsilError} codes, mapped by {@link httpStatusForNarsilError}.
357
+ *
358
+ * @public */
193
359
  declare const ServerErrorCodes: {
194
360
  readonly INVALID_REQUEST: "INVALID_REQUEST";
195
361
  readonly INVALID_JSON: "INVALID_JSON";
@@ -204,7 +370,12 @@ declare const ServerErrorCodes: {
204
370
  readonly REQUEST_ABORTED: "REQUEST_ABORTED";
205
371
  };
206
372
  /** Maps a {@link NarsilError} code to an HTTP status. Unknown or cluster-only
207
- * codes fall through to 500 so an internal fault never leaks as a client error. */
373
+ * codes fall through to 500 so an internal fault never leaks as a client error.
374
+ *
375
+ * @param code - The code a {@link NarsilError} carried.
376
+ * @returns The status the server answers with.
377
+ *
378
+ * @public */
208
379
  declare function httpStatusForNarsilError(code: string): number;
209
380
 
210
381
  /**
@@ -213,14 +384,44 @@ declare function httpStatusForNarsilError(code: string): number;
213
384
  * terminal records first, so a long-lived server cannot accumulate task state
214
385
  * without bound. `ttlMs` is ignored here; the cap plays that role. Records are
215
386
  * copied in and out so a caller cannot mutate stored state by reference.
387
+ *
388
+ * @public
216
389
  */
217
390
  declare class InMemoryTaskStore implements TaskStore {
218
391
  private readonly maxRetained;
219
392
  private readonly records;
393
+ /**
394
+ * Builds a store that keeps task records in this process alone.
395
+ *
396
+ * @param maxRetained - Records to keep before the oldest finished ones are
397
+ * dropped. Defaults to 1000.
398
+ */
220
399
  constructor(maxRetained?: number);
400
+ /**
401
+ * Stores a record, replacing whatever its id already held.
402
+ *
403
+ * @param record - The record to store. A copy is kept, so changing the
404
+ * object afterwards leaves the store untouched.
405
+ */
221
406
  set(record: TaskRecord): Promise<void>;
407
+ /**
408
+ * Reads one record back.
409
+ *
410
+ * @param id - The task to read.
411
+ * @returns A copy of the record, or `null` when the store holds no such id.
412
+ */
222
413
  get(id: string): Promise<TaskRecord | null>;
414
+ /**
415
+ * Lists every record the store holds.
416
+ *
417
+ * @returns A copy of each record, oldest first.
418
+ */
223
419
  list(): Promise<TaskRecord[]>;
420
+ /**
421
+ * Removes one record. An id the store never held is not an error.
422
+ *
423
+ * @param id - The task to remove.
424
+ */
224
425
  delete(id: string): Promise<void>;
225
426
  private prune;
226
427
  }
package/dist/server.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { NarsilError, ErrorCodes } from './chunk-M2EDG55Y.mjs';
1
+ import { NarsilError, ErrorCodes } from './chunk-UNJZ7ZDB.mjs';
2
2
  import { randomUUID } from 'crypto';
3
3
 
4
4
  // src/server/cors.ts
@@ -1015,21 +1015,49 @@ async function loadUWebSockets() {
1015
1015
  // src/server/task-store.ts
1016
1016
  var DEFAULT_MAX_RETAINED = 1e3;
1017
1017
  var InMemoryTaskStore = class {
1018
+ /**
1019
+ * Builds a store that keeps task records in this process alone.
1020
+ *
1021
+ * @param maxRetained - Records to keep before the oldest finished ones are
1022
+ * dropped. Defaults to 1000.
1023
+ */
1018
1024
  constructor(maxRetained = DEFAULT_MAX_RETAINED) {
1019
1025
  this.maxRetained = maxRetained;
1020
1026
  }
1021
1027
  records = /* @__PURE__ */ new Map();
1028
+ /**
1029
+ * Stores a record, replacing whatever its id already held.
1030
+ *
1031
+ * @param record - The record to store. A copy is kept, so changing the
1032
+ * object afterwards leaves the store untouched.
1033
+ */
1022
1034
  async set(record) {
1023
1035
  this.records.set(record.id, { ...record });
1024
1036
  this.prune();
1025
1037
  }
1038
+ /**
1039
+ * Reads one record back.
1040
+ *
1041
+ * @param id - The task to read.
1042
+ * @returns A copy of the record, or `null` when the store holds no such id.
1043
+ */
1026
1044
  async get(id) {
1027
1045
  const record = this.records.get(id);
1028
1046
  return record ? { ...record } : null;
1029
1047
  }
1048
+ /**
1049
+ * Lists every record the store holds.
1050
+ *
1051
+ * @returns A copy of each record, oldest first.
1052
+ */
1030
1053
  async list() {
1031
1054
  return [...this.records.values()].map((record) => ({ ...record }));
1032
1055
  }
1056
+ /**
1057
+ * Removes one record. An id the store never held is not an error.
1058
+ *
1059
+ * @param id - The task to remove.
1060
+ */
1033
1061
  async delete(id) {
1034
1062
  this.records.delete(id);
1035
1063
  }