@kedem/okdb 3.0.0 → 3.0.1

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 (62) hide show
  1. package/CHANGELOG.md +38 -3
  2. package/README.md +68 -36
  3. package/bin/okdb +1 -1
  4. package/docs/auth-and-sync.md +30 -24
  5. package/docs/auth-permissions.md +5 -4
  6. package/docs/c-bridge.md +94 -0
  7. package/docs/change-log.md +78 -35
  8. package/docs/data-model.md +32 -8
  9. package/docs/deployment.md +42 -38
  10. package/docs/diagnostics.md +61 -125
  11. package/docs/embeddings.md +143 -51
  12. package/docs/files.md +53 -18
  13. package/docs/fts.md +48 -23
  14. package/docs/functions.md +107 -56
  15. package/docs/getting-started.md +125 -9
  16. package/docs/http-api.md +68 -11
  17. package/docs/http-cluster.md +80 -88
  18. package/docs/index.md +33 -15
  19. package/docs/indexes.md +53 -17
  20. package/docs/licensing.md +18 -4
  21. package/docs/logging.md +11 -22
  22. package/docs/manifest.json +4 -2
  23. package/docs/migration.md +40 -15
  24. package/docs/pipelines.md +96 -32
  25. package/docs/plugins.md +47 -15
  26. package/docs/process-registry.md +23 -24
  27. package/docs/processors.md +26 -23
  28. package/docs/querying.md +102 -29
  29. package/docs/queue.md +167 -51
  30. package/docs/resolved-fields.md +24 -1
  31. package/docs/subscriptions.md +4 -4
  32. package/docs/sync.md +9 -6
  33. package/docs/time-machine.md +40 -11
  34. package/docs/transactions.md +63 -15
  35. package/docs/ttl.md +34 -13
  36. package/docs/upgrade-2.0.md +32 -15
  37. package/docs/upgrade-2.1.md +10 -12
  38. package/docs/upgrade-3.0.md +144 -0
  39. package/docs/views.md +131 -42
  40. package/index.js +1 -1
  41. package/native/linux-x64-gnu/okdb +0 -0
  42. package/native/linux-x64-gnu/okdb-node.linux-x64-gnu.node +0 -0
  43. package/native-loader.js +1 -1
  44. package/okdb-native.js +1 -1
  45. package/package.json +1 -1
  46. package/types/environment.d.ts +32 -11
  47. package/types/errors.d.ts +20 -0
  48. package/types/features/admin.d.ts +3 -5
  49. package/types/features/api.d.ts +5 -7
  50. package/types/features/embeddings.d.ts +8 -7
  51. package/types/features/engines.d.ts +9 -1
  52. package/types/features/files.d.ts +2 -1
  53. package/types/features/fts.d.ts +3 -3
  54. package/types/features/functions.d.ts +14 -8
  55. package/types/features/pipelines.d.ts +10 -10
  56. package/types/features/queue.d.ts +15 -10
  57. package/types/features/sync.d.ts +7 -0
  58. package/types/features/time-machine.d.ts +3 -0
  59. package/types/index.d.ts +3 -0
  60. package/types/okdb.d.ts +70 -7
  61. package/types/options.d.ts +12 -8
  62. package/docs/OKDB-ARCHITECTURE.md +0 -1061
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kedem/okdb",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "A fast, type-oriented database — strong consistency and rich indexing at the core, with sync, vector embeddings, full-text search, and AI tooling built in. Designed for the AI era.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "engines": {
@@ -18,7 +18,6 @@ import type {
18
18
  OKDBQueryEntry,
19
19
  OKDBChangeEntry,
20
20
  OKDBRangeIterable,
21
- OKDBEnvironmentConfig,
22
21
  OKDBIndexDefinition,
23
22
  OKDBRegisterIndexOptions,
24
23
  OKDBEnsureDefinition,
@@ -32,7 +31,7 @@ import type {
32
31
  OKDBResolvedOptions,
33
32
  OKDBRoleFlags,
34
33
  } from './options';
35
- import type { OKDBFtsSearchResult } from './features/fts';
34
+ import type { OKDBFts, OKDBFtsSearchResult } from './features/fts';
36
35
  import type { OKDBQueue } from './features/queue';
37
36
  import type { OKDBFiles } from './features/files';
38
37
  import type { OKDBTimeMachine } from './features/time-machine';
@@ -65,7 +64,11 @@ export interface OKDBTransactionOps {
65
64
  index: OKDBIndexSpec,
66
65
  options?: OKDBIndexRangeOptions,
67
66
  ): OKDBRangeIterable<OKDBIndexEntry<T>>;
68
- query<T = unknown>(type: string, filter?: OKDBFilter, options?: OKDBQueryOptions): Iterable<OKDBQueryEntry<T>>;
67
+ query<T = unknown>(
68
+ type: string,
69
+ filter?: OKDBFilter,
70
+ options?: OKDBQueryOptions,
71
+ ): OKDBRangeIterable<OKDBQueryEntry<T>>;
69
72
  getClock(type?: string | null): number;
70
73
  getCount(type: string): number;
71
74
  }
@@ -133,7 +136,7 @@ export type OKDBProcessorHandler = (
133
136
  export interface OKDBProcessorRegisterOptions {
134
137
  /** File handler: `{ path, export }`, called as `fn(ctx, changes, info)`. */
135
138
  module?: { path: string; export?: string };
136
- /** Name of a handler registered with `OKDBProcessor.registerHandler(name, fn)`. */
139
+ /** Name of a handler registered with `env.processor.constructor.registerHandler(name, fn)`. */
137
140
  handler?: string;
138
141
  payload?: unknown;
139
142
  /** `'async'` (default; background drain) | `'sync'` (every writer, inside the commit).
@@ -141,7 +144,7 @@ export interface OKDBProcessorRegisterOptions {
141
144
  mode?: 'async' | 'sync' | 'single' | 'worker' | 'fanout' | 'inline';
142
145
  /** mode:'async' only: `'single'` (1-of-N, leased, durable cursor) | `'fanout'` (N-of-N). */
143
146
  distribution?: 'single' | 'fanout';
144
- bootstrap?: 'snapshot' | 'log';
147
+ bootstrap?: 'snapshot' | 'log' | 'none';
145
148
  originMode?: 'self' | 'remote' | 'all';
146
149
  batchSize?: number;
147
150
  hydrateValues?: boolean;
@@ -202,7 +205,7 @@ export interface OKDBProcessorHandle {
202
205
  resume(): boolean;
203
206
  retry(): boolean;
204
207
  kick(): boolean;
205
- awaitIdle(): Promise<void>;
208
+ awaitIdle(timeoutMs?: number): Promise<void>;
206
209
  }
207
210
 
208
211
  /** Per-env change-subscription primitive (`env.processor`). */
@@ -214,7 +217,7 @@ export interface OKDBEnvProcessor {
214
217
  resume(id: string): boolean;
215
218
  retry(id: string): boolean;
216
219
  kick(id: string): boolean;
217
- awaitIdle(id: string): Promise<void>;
220
+ awaitIdle(id: string, timeoutMs?: number): Promise<void>;
218
221
  getCursor(cursorKey: string): number;
219
222
  setCursor(cursorKey: string, clock: number): void;
220
223
  resetCursor(cursorKey: string): void;
@@ -265,7 +268,6 @@ export interface OKDBWriterStatus {
265
268
  export interface OKDBEnvironment {
266
269
  readonly name: string;
267
270
  readonly path: string;
268
- readonly config: OKDBEnvironmentConfig;
269
271
  /** Instance identity (shared with the owning OKDB). */
270
272
  readonly id: string;
271
273
  /** Shared with the owning OKDB (`db.events`). */
@@ -283,6 +285,8 @@ export interface OKDBEnvironment {
283
285
  readonly functions: OKDBFunctions;
284
286
  readonly views: OKDBViews;
285
287
  readonly processor: OKDBEnvProcessor;
288
+ /** The instance-wide FTS API (`db.fts`); pass this env as the last argument to target it. */
289
+ readonly fts: OKDBFts;
286
290
 
287
291
  // ── Transactions ──────────────────────────────────────────────────────────
288
292
  transaction(options?: OKDBTransactionOptions): OKDBTransaction;
@@ -315,7 +319,7 @@ export interface OKDBEnvironment {
315
319
 
316
320
  // ── Index queries (pinned + guarded: consume synchronously) ───────────────
317
321
  /** Raw index scan — yields the primary keys stored in the index. */
318
- getIndex(type: string, index: string[], options?: OKDBIndexRangeOptions): OKDBRangeIterable<OKDBPrimaryKey>;
322
+ getIndex(type: string, index: OKDBIndexSpec, options?: OKDBIndexRangeOptions): OKDBRangeIterable<OKDBPrimaryKey>;
319
323
  byIndex<T = unknown>(
320
324
  type: string,
321
325
  index: OKDBIndexSpec,
@@ -324,12 +328,18 @@ export interface OKDBEnvironment {
324
328
  countByIndex(type: string, index: OKDBIndexSpec, options?: OKDBIndexRangeOptions): number;
325
329
  /** With an `fts` or `vector` signal, query() is async and resolves to an array. */
326
330
  query<T = unknown>(type: string, filter: OKDBFilter, options: OKDBHybridQueryOptions): Promise<OKDBQueryEntry<T>[]>;
327
- query<T = unknown>(type: string, filter?: OKDBFilter, options?: OKDBQueryOptions): Iterable<OKDBQueryEntry<T>>;
331
+ /** A lazy iterable of `{ key, value }` rows (an Array for geo filters / `near`). Non-indexed scans may
332
+ * be iterated across `await`; indexed ones are pinned (READER_HELD_ACROSS_AWAIT). */
333
+ query<T = unknown>(
334
+ type: string,
335
+ filter?: OKDBFilter,
336
+ options?: OKDBQueryOptions,
337
+ ): OKDBRangeIterable<OKDBQueryEntry<T>>;
328
338
  geoQuery<T = unknown>(
329
339
  type: string,
330
340
  field: string,
331
341
  options: OKDBGeoQueryOptions,
332
- ): Iterable<OKDBQueryEntry<T> & { distance?: number }>;
342
+ ): Array<OKDBQueryEntry<T> & { distance?: number }>;
333
343
  /** FTS search with an optional post-filter; returns hydrated, scored docs. */
334
344
  ftsQuery(
335
345
  type: string,
@@ -349,6 +359,8 @@ export interface OKDBEnvironment {
349
359
  /** Idempotent declaration of a type with its indexes, FTS indexes, views and schema. */
350
360
  ensure(definition: OKDBEnsureDefinition): Promise<void>;
351
361
  hasType(type: string): boolean;
362
+ /** Registered user type names of this env. */
363
+ listTypes(): string[];
352
364
  dropType(type: string, timestamp?: number): Promise<void>;
353
365
 
354
366
  // ── Resolved fields (content served by the app, never stored) ────────────
@@ -376,6 +388,12 @@ export interface OKDBEnvironment {
376
388
  resolvedFields(type: string): string[];
377
389
  /** `field` of one row: the stored value, else the resolver's. */
378
390
  readField(type: string, key: string, value: any, field: string): Promise<unknown>;
391
+ /** Several fields of several rows (`items`: `[{ key, value }]`), read like `readField`. */
392
+ readFieldMany(
393
+ type: string,
394
+ items: Array<{ key: string; value: any }>,
395
+ fields: string[],
396
+ ): Promise<Array<{ value: unknown; error?: { message: string; code: string } }>>;
379
397
 
380
398
  // ── Schema ────────────────────────────────────────────────────────────────
381
399
  setSchema(type: string, schema: OKDBTypeSchema): Promise<void>;
@@ -396,6 +414,8 @@ export interface OKDBEnvironment {
396
414
  /** Resolves true once the index build is complete. */
397
415
  indexReady(type: string, index: OKDBIndexSpec): Promise<boolean>;
398
416
  getIndexStatus(type: string, index: OKDBIndexSpec): string;
417
+ /** Stored metadata of one index (by name, e.g. `'author~publishedAt'`), or null. */
418
+ getIndexMeta(type: string, name: string): Record<string, unknown> | null;
399
419
  getUniqueViolations(type?: string | null, index?: OKDBIndexSpec): unknown[];
400
420
  hasUniqueViolations(type?: string | null, index?: OKDBIndexSpec): boolean;
401
421
  getUniqueViolation(type: string, index: OKDBIndexSpec, indexKey: OKDBIndexKey): unknown;
@@ -432,6 +452,7 @@ export interface OKDBEnvironment {
432
452
  /** OKDB_DIAG snapshot (`{ enabled: false, … }` unless OKDB_DIAG=1). */
433
453
  diag(): Record<string, unknown>;
434
454
  getResolvedOptions(): OKDBResolvedOptions;
455
+ /** No-op in 3.0 (reads always use a current read transaction); kept for 2.x callers. */
435
456
  refreshReadTxn(): void;
436
457
 
437
458
  // ── Utilities ─────────────────────────────────────────────────────────────
package/types/errors.d.ts CHANGED
@@ -96,3 +96,23 @@ export declare class OKDBForeignKeyDeleteError extends OKDBError {
96
96
  export declare class OKDBIndexHasConsumersError extends OKDBError {
97
97
  constructor(type: string, index: string, usedBy: Array<{ kind: string; name: string }>);
98
98
  }
99
+
100
+ /** `NOT_IMPLEMENTED_NATIVE`: a member okdb 3 does not provide (`db.api.*`, `db.admin.*`). `details.feature` names it. */
101
+ export declare class OKDBNotImplementedNativeError extends OKDBError {
102
+ constructor(feature: string, detail?: string);
103
+ }
104
+
105
+ /**
106
+ * The argument-validation codes okdb 3 throws (as a plain `OKDBError`) at the API boundary; HTTP answers them with 400,
107
+ * MCP with JSON-RPC -32602.
108
+ */
109
+ export type OKDBArgumentErrorCode = 'INVALID_KEY' | 'INVALID_TYPE_NAME' | 'INVALID_ARGUMENT' | 'INVALID_OPTIONS';
110
+
111
+ /** `err.details` of an argument error: `problem` for INVALID_OPTIONS, `expected` / `got` for the others. `got` is the kind
112
+ * of the value (`'undefined'`, `'null'`, `'object'`, `'empty string'`, `'Date'`, …). */
113
+ export interface OKDBArgumentErrorDetails {
114
+ argument: string;
115
+ expected?: string;
116
+ got?: string;
117
+ problem?: string;
118
+ }
@@ -1,9 +1,7 @@
1
1
  /**
2
- * The Admin UI (`db.admin`; null when constructed with `admin: false`). Constructed with the
3
- * OKDB instance: it registers the admin static-file routes, the admin auth guard and the
4
- * OAuth authorization-server endpoints on `db.http`, and attaches the admin change relay.
5
- * It has no user-callable methods — the UI is served once `db.http.listen(port)` is called.
6
- * Removed: `start()` (registration happens in the constructor).
2
+ * `db.admin` — in okdb 3.0 a stub (null when constructed with `admin: false`): any member call
3
+ * throws `NOT_IMPLEMENTED_NATIVE`. The admin UI, its auth guard and the OAuth endpoints are built
4
+ * into the native HTTP server and served once `db.http.listen(port)` is called.
7
5
  */
8
6
  export declare class OKDBAdmin {
9
7
  private constructor();
@@ -1,11 +1,9 @@
1
1
  /**
2
- * The REST API route set (`db.api`). Constructed with the OKDB instance: it registers the
3
- * `/api/*` auth guard and routes (envs, types, items, indexes, FTS, views, functions,
4
- * subscriptions, processors, auth, system) on `db.http`. It has no user-callable methods —
5
- * the routes are served once `db.http.listen(port)` is called. The default env for routes
6
- * without an `/env/:env` prefix comes from the `api.defaultEnv` constructor option
7
- * (default `'default'`).
8
- * Removed: `start()` and `inferSchema()` (never existed on the 2.x class).
2
+ * `db.api` — in okdb 3.0 a stub: any member call throws `NOT_IMPLEMENTED_NATIVE`. The REST API
3
+ * routes (`/api/*`: envs, types, items, indexes, FTS, views, functions, subscriptions, processors,
4
+ * auth, system) are built into the native HTTP server and served once `db.http.listen(port)` is
5
+ * called; add your own routes with `db.http.add()`. The default env for routes without an
6
+ * `/env/:env` prefix comes from the `api.defaultEnv` constructor option (default `'default'`).
9
7
  */
10
8
  export declare class OKDBApi {
11
9
  private constructor();
@@ -1,4 +1,4 @@
1
- // Embeddings feature — `db.embeddings` (src/features/embeddings/okdb-embeddings.js).
1
+ // Embeddings feature — `db.embeddings`.
2
2
  //
3
3
  // A pipeline is four engines (embedder → indexer → [embed-worker] → vector-search) plus an
4
4
  // env-local generic `~pipelines` record. Engine names are scoped `<env>:<name>`:
@@ -335,7 +335,7 @@ export interface OKDBEmbeddingsSearchOptions {
335
335
 
336
336
  /**
337
337
  * A chunk-level hit. For chunked pipelines `key` is a vec key (`docKey\tchunkHash`,
338
- * decode with `parseVecKey`); otherwise the source doc key. Score ∈ [0, 1], higher = closer.
338
+ * split on the tab); otherwise the source doc key. Score ∈ [0, 1], higher = closer.
339
339
  */
340
340
  export interface OKDBEmbeddingsSearchResult {
341
341
  key: string;
@@ -503,8 +503,8 @@ export declare class OKDBEmbeddings {
503
503
  registerEmbedderFactory(name: string, factory: OKDBEmbedderFactory, schema?: Partial<OKDBEmbedderSchema>): void;
504
504
  /** The factory for an embedder type (built-in `'ollama' | 'openai' | 'fake'` or registered), or null. */
505
505
  getEmbedderFactory(type: string): OKDBEmbedderFactory | null;
506
- /** The `{ label, fields, note }` schema registered with an embedder type, or null. */
507
- getEmbedderSchema(type: string): OKDBEmbedderSchema | null;
506
+ /** The `{ label, fields, note }` schema registered with an embedder type, or `undefined`. */
507
+ getEmbedderSchema(type: string): OKDBEmbedderSchema | undefined;
508
508
  /** Register a search algorithm (built-ins: `'flat'`, `'hnsw'`, `'usearch'`). */
509
509
  registerAlgorithmFactory(name: string, factory: OKDBAlgorithmFactory, schema?: OKDBAlgorithmSchema): void;
510
510
  listAlgorithms(): OKDBEmbeddingsAlgorithmInfo[];
@@ -523,7 +523,8 @@ export declare class OKDBEmbeddings {
523
523
  /**
524
524
  * Create (or repair) a full pipeline: embedder, indexer, optional queue worker, vector-search,
525
525
  * plus an env-local `~pipelines` record named `storage_key`. Rejects if a complete pipeline
526
- * with that `storage_key` already exists. License-gated (`embeddings`).
526
+ * with that `storage_key` already exists. Free tier: at most 2 pipelines per env
527
+ * (`LICENSE_LIMIT_EXCEEDED` for a third).
527
528
  */
528
529
  createPipeline(
529
530
  name: string,
@@ -647,8 +648,8 @@ export declare class OKDBEmbeddings {
647
648
 
648
649
  // ── Model catalog (`~system` `~emb:models`)
649
650
 
650
- /** Catalog dims for a provider/model (falls back to the base name without `:tag`), or null. */
651
- resolveModelDims(provider: string, model: string): number | null;
651
+ /** Catalog dims for a provider/model (falls back to the base name without `:tag`), or `undefined`. */
652
+ resolveModelDims(provider: string, model: string): number | undefined;
652
653
  registerModel(provider: string, model: string, dims: number, description?: string): Promise<void>;
653
654
  listModels(provider?: string | null): OKDBEmbeddingsModel[];
654
655
  /** Registered embedder provider types with their UI schemas. */
@@ -305,11 +305,18 @@ export interface OKDBEngineTemplatePreview {
305
305
  * member with `ENGINE_MANAGED_BY_PIPELINE`; the SDK methods here do not check —
306
306
  * operate on the owning pipeline (`db.pipelines.findOwner(type, name)`).
307
307
  *
308
+ * Licensing: engines are a licensed feature, off on the free tier — `createEngine()` /
309
+ * `createAndStartEngine()` throw `LICENSE_FEATURE_DISABLED` without a license that includes
310
+ * `engines`. The embeddings engines that `okdb.embeddings.createPipeline()` creates are free
311
+ * (free tier: at most 2 embeddings pipelines per env, `LICENSE_LIMIT_EXCEEDED` beyond).
312
+ *
308
313
  * Removed: the per-engine `affinity` field (replaced by the engine-level lease; stripped from records on boot).
309
314
  */
310
315
  export declare class OKDBEngines {
311
316
  /** True for `db.engines`, false for an `env.engines` facade. */
312
317
  readonly isOrchestrator: boolean;
318
+ /** The facade's env name (`null` on `db.engines`). */
319
+ readonly envName: string | null;
313
320
 
314
321
  // ── Drivers & templates ───────────────────────────────────────────────────
315
322
 
@@ -333,7 +340,8 @@ export declare class OKDBEngines {
333
340
  previewTemplate(
334
341
  id: string,
335
342
  input?: Record<string, unknown>,
336
- context?: { envName?: string | null },
343
+ /** Target env for the plan (default: this facade's env). */
344
+ envName?: string | null,
337
345
  ): OKDBEngineTemplatePreview;
338
346
  /** Every registered driver type with its self-declared docs, sorted by type. */
339
347
  catalog(): OKDBEngineCatalogEntry[];
@@ -12,7 +12,8 @@ export interface OKDBFileRecord {
12
12
 
13
13
  export interface OKDBUploadOptions {
14
14
  id: string;
15
- stream: Readable;
15
+ /** The bytes: a readable stream, a Buffer / Uint8Array, or a string. */
16
+ stream: Readable | Buffer | Uint8Array | string;
16
17
  mime?: string;
17
18
  path?: string;
18
19
  txn?: unknown;
@@ -1,10 +1,10 @@
1
1
  import type { OKDBEnvironment } from '../environment';
2
2
 
3
3
  /**
4
- * The trailing `env` argument: an environment OBJECT (e.g. `db.env('name')`); omitted = the
5
- * default env. A name string is NOT accepted.
4
+ * The trailing `env` argument: an environment object (e.g. `db.env('name')`) or an env name;
5
+ * omitted = the default env.
6
6
  */
7
- export type OKDBFtsEnvArg = OKDBEnvironment;
7
+ export type OKDBFtsEnvArg = OKDBEnvironment | string;
8
8
 
9
9
  /** Tokenizer settings. Defaults: min 2, max 64 (longer tokens truncated), keepNumbers true, toLower true. */
10
10
  export interface OKDBFtsTokenizerOptions {
@@ -2,7 +2,10 @@
2
2
  export interface OKDBFunctionRuntime {
3
3
  /** Run deadline in ms (default 5000). Exposed to the script as `ctx.signal`. */
4
4
  timeoutMs: number;
5
- /** Sandbox heap cap in MB (default 32). */
5
+ /**
6
+ * Recorded memory budget in MB (default 32). The enforced sandbox heap cap is process-wide: the
7
+ * `functions.memoryMb` constructor option (default 256, minimum 32); exceeding it fails the run with `FUNCTION_OOM`.
8
+ */
6
9
  memoryMb: number;
7
10
  /** Whether the script may use `fetch` (default true). */
8
11
  allowFetch: boolean;
@@ -11,11 +14,11 @@ export interface OKDBFunctionRuntime {
11
14
 
12
15
  /** Input accepted by `create()`, `update()` (as a patch) and `preview()`. */
13
16
  export interface OKDBFunctionDefinition {
14
- /** Must match `/^[A-Za-z0-9._-]+$/`. Required for `create()`; `update()` uses its `name` argument. */
17
+ /** Must match `/^[A-Za-z0-9._-]+$/`. Required for `create()` and `preview()`; `update()` uses its `name` argument. */
15
18
  name?: string;
16
19
  /**
17
20
  * Script source: a single function expression `[async] (ctx) => { ... }` (max 64 KiB; must not
18
- * reference `require`/`import`/`console`/`module`/`exports`/`process`). Allowed `ctx` props:
21
+ * reference `require`/`import`/`console`/`module`/`exports`/`process`/`child_process`/`worker_threads`). Allowed `ctx` props:
19
22
  * payload, info, signal, log, env, job, processor, materializer (+ `okdb` when `unsafe: true`).
20
23
  */
21
24
  source?: string;
@@ -128,6 +131,8 @@ export interface OKDBFunctionRunOptions {
128
131
  * (`OKDB_FN_MAX_TIMEOUT_MS`).
129
132
  */
130
133
  timeoutMs?: number;
134
+ /** An already-aborted signal cancels the run before it starts. */
135
+ signal?: AbortSignal;
131
136
  }
132
137
 
133
138
  export interface OKDBFunctionPreviewOptions {
@@ -135,15 +140,15 @@ export interface OKDBFunctionPreviewOptions {
135
140
  /** Recorded as `request.trigger` (default `'preview'`). */
136
141
  trigger?: string;
137
142
  runId?: string;
138
- /** Name used when the draft definition has none (default `'__draft__'`). */
143
+ /** Name recorded for the run when the definition's name is empty. */
139
144
  functionName?: string;
140
145
  /** Filename used in compile-error stack traces. */
141
146
  filename?: string;
142
147
  }
143
148
 
144
149
  /**
145
- * Stored, versioned, validated JavaScript functions, executed on the calling node in its
146
- * per-process sandbox thread.
150
+ * Stored, versioned, validated JavaScript functions, executed on the calling process in the
151
+ * native core's embedded JavaScript sandbox (not Node.js: no `require`, `Buffer`, `process`).
147
152
  *
148
153
  * Attached as `env.functions` (registry = that env) and `db.functions` (registry = the `~system`
149
154
  * env). Both expose the same surface; run records go to the owning env's `~function_runs`.
@@ -152,7 +157,7 @@ export interface OKDBFunctionPreviewOptions {
152
157
  */
153
158
  export declare class OKDBFunctions {
154
159
  /** Name of the env that owns this registry (`'~system'` for `db.functions`). */
155
- readonly envName: string | null;
160
+ readonly envName: string;
156
161
 
157
162
  /** All stored functions (empty until the first `create()`). */
158
163
  list(): Promise<Array<OKDBFunctionRegistryEntry<OKDBFunctionRecord>>>;
@@ -166,7 +171,8 @@ export declare class OKDBFunctions {
166
171
 
167
172
  /**
168
173
  * Runs a stored function and resolves with the final run record (`result.value` = return value).
169
- * Rejects on script error / timeout (`err.code` e.g. `FUNCTION_TIMEOUT`, `FUNCTION_DISABLED`).
174
+ * Rejects on script error / timeout (`err.code` e.g. `FUNCTION_TIMEOUT`, `FUNCTION_OOM`, `FUNCTION_DISABLED`);
175
+ * the failed run's record is attached as `err.details.runRecord`.
170
176
  */
171
177
  run(name: string, payload?: unknown, options?: OKDBFunctionRunOptions): Promise<OKDBFunctionRun>;
172
178
  /** Validates and runs an unsaved draft. Persists neither the definition nor a run record. */
@@ -184,10 +184,10 @@ export interface OKDBPipelineApi {
184
184
  opts?: OKDBPipelineSearchOptions,
185
185
  ): Promise<OKDBPipelineDocHit[]>;
186
186
  /**
187
- * Wait (up to 30 s) for the indexer to catch up with the source type's head.
188
- * Throws if the indexer is not running on this node.
187
+ * Wait (up to `timeoutMs`, default 30 s) for the indexer to catch up with the source type's head;
188
+ * rejects with `INDEXER_FLUSH_TIMEOUT` past it. Throws if the indexer is not running on this node.
189
189
  */
190
- flush(): Promise<void>;
190
+ flush(opts?: { timeoutMs?: number }): Promise<void>;
191
191
  /** Combined stats: embedder `health()`, indexer/worker/search `stats()` (`undefined` when not running here). */
192
192
  stats(): Promise<{ embedder: unknown; indexer: unknown; worker: unknown; search: unknown }>;
193
193
  }
@@ -205,6 +205,9 @@ export interface OKDBPipelineHandle {
205
205
  // ─── OKDBPipelines ────────────────────────────────────────────────────────────
206
206
 
207
207
  /**
208
+ * Licensing: generic pipelines group engines, which need a license that includes `engines`;
209
+ * embeddings pipelines (`okdb.embeddings.createPipeline`) are free — at most 2 per env on the free tier.
210
+ *
208
211
  * Generic pipeline registry: env-defined, synced `~pipelines` records grouping
209
212
  * existing engines into an ordered, structurally immutable topology ("the
210
213
  * pipeline is the engine"). Member add/remove is impossible at runtime; use
@@ -232,19 +235,16 @@ export declare class OKDBPipelines {
232
235
  get(name: string): Promise<OKDBPipelineInfo | null>;
233
236
  /** db only: pipeline `name` in env `envName`. */
234
237
  get(envName: string, name: string): Promise<OKDBPipelineInfo | null>;
235
- /** All inspected pipelines. env: that env (options ignored); db: every opened env, or `options.envName`. */
236
- list(options?: { envName?: string | null }): Promise<OKDBPipelineInfo[]>;
238
+ /** All inspected pipelines. env: that env (argument ignored); db: every opened env, or one env (`{ envName }` or its name). */
239
+ list(options?: { envName?: string | null } | string | null): Promise<OKDBPipelineInfo[]>;
237
240
  /** Raw stored record, or `null`. */
238
241
  getRecord(name: string): Promise<OKDBPipelineRecord | null>;
239
242
  /** db only: raw record `name` in env `envName`. */
240
243
  getRecord(envName: string, name: string): Promise<OKDBPipelineRecord | null>;
241
244
  /** Raw records. db entries carry `env`. */
242
245
  listRecords(options?: { envName?: string | null }): Promise<OKDBPipelineRecordEntry[]>;
243
- /** Normalize + validate a definition without persisting (throws on invalid input). */
244
- validate(
245
- definition: OKDBPipelineDefinition,
246
- options?: { previous?: OKDBPipelineRecord | null },
247
- ): OKDBPipelineRecord;
246
+ /** Normalize + validate a definition without persisting (throws on invalid input); `previous` = the record being updated. */
247
+ validate(definition: OKDBPipelineDefinition, previous?: OKDBPipelineRecord | null): OKDBPipelineRecord;
248
248
  /** Which pipeline (in any opened user env) owns engine `type@name` as a member, or `null`. */
249
249
  findOwner(type: string, name: string): OKDBPipelineOwner | null;
250
250
  /** Ensure the `~pipelines` type exists (env: this env; db: `envName`, default `'default'`); returns the env. */
@@ -1,5 +1,4 @@
1
1
  import type { OKDBIndexEntry } from '../options';
2
- import type { EventEmitter } from 'events';
3
2
  import type { OKDB } from '../okdb';
4
3
 
5
4
  export type OKDBJobStatus = 'pending' | 'running' | 'done' | 'failed';
@@ -210,6 +209,8 @@ export interface OKDBJobLogEntry {
210
209
  export interface OKDBQueueHandlerContext {
211
210
  /** The root OKDB instance. */
212
211
  okdb: OKDB;
212
+ /** The environment this queue lives in. */
213
+ env: unknown;
213
214
  /** The claimed job record (includes `payload`). */
214
215
  job: OKDBJob;
215
216
  jobId: string;
@@ -302,8 +303,7 @@ export type OKDBQueueEventName =
302
303
  * Removed: worker(), spawn() — throw QUEUE_WORKER_REMOVED; use process()
303
304
  */
304
305
  export declare class OKDBQueue {
305
- /** Unused: queue events (`OKDBQueueEventName`) are emitted on the root `okdb.events`. */
306
- events: EventEmitter;
306
+ // Queue events (`OKDBQueueEventName`) are emitted on the root `okdb.events`.
307
307
 
308
308
  // ── Core job lifecycle ────────────────────────────────────────────────────
309
309
  /** Resolves to the new job id (or the existing id on an idempotency hit). */
@@ -319,8 +319,10 @@ export declare class OKDBQueue {
319
319
  /** One lane pool over several types (shared concurrency cap, weighted fairness, admission gate). */
320
320
  process(entries: OKDBQueuePoolLane<any>[], poolOptions?: OKDBQueuePoolOptions): OKDBQueueConsumer;
321
321
 
322
- /** Stop every consumer started by `process()` on this queue. */
322
+ /** Stop every consumer started by `process()` on this queue (one shared grace period). */
323
323
  stopAll(timeout?: number): Promise<void>;
324
+ /** Stop every consumer at once (no grace period). */
325
+ killAll(): Promise<void>;
324
326
 
325
327
  // ── Job retrieval / management ────────────────────────────────────────────
326
328
  getJob(id: string): Promise<OKDBJob | null>;
@@ -392,7 +394,8 @@ export declare class OKDBQueue {
392
394
  patch: Partial<Pick<OKDBJobBucketRecord, 'capacity' | 'tokens' | 'refill_amount' | 'refill_every'>>,
393
395
  ): Promise<void>;
394
396
  removeBucket(id: string): Promise<void>;
395
- getBucket(id: string): OKDBJobBucketRecord | null;
397
+ /** Synchronous; `undefined` when the bucket does not exist. */
398
+ getBucket(id: string): OKDBJobBucketRecord | undefined;
396
399
  tryClaimTokens(bucketId: string, tokens?: number): Promise<boolean>;
397
400
 
398
401
  // ── Job types ─────────────────────────────────────────────────────────────
@@ -400,12 +403,14 @@ export declare class OKDBQueue {
400
403
  getJobType(id: string): Promise<OKDBJobType | null>;
401
404
  listJobTypes(): Promise<OKDBJobType[]>;
402
405
  removeJobType(id: string): Promise<boolean>;
403
- pauseJobType(id: string): Promise<OKDBJobType>;
404
- resumeJobType(id: string): Promise<OKDBJobType>;
405
- /** Draining: enqueue throws TYPE_DRAINING; existing jobs still run. */
406
- drainJobType(id: string): Promise<OKDBJobType>;
406
+ /** Synchronous; throws NOT_FOUND for an unregistered type. */
407
+ pauseJobType(id: string): OKDBJobType;
408
+ /** Synchronous; throws NOT_FOUND for an unregistered type. */
409
+ resumeJobType(id: string): OKDBJobType;
410
+ /** Draining: enqueue throws TYPE_DRAINING; existing jobs still run. Synchronous. */
411
+ drainJobType(id: string): OKDBJobType;
407
412
  setJobTypeSchema(id: string, definition: unknown, enforce?: boolean): Promise<OKDBJobType>;
408
413
  removeJobTypeSchema(id: string): Promise<OKDBJobType>;
409
- /** Up to `limit` (≤ 100) recent payloads of a type. */
414
+ /** Up to `limit` (default 5, ≤ 100) recent payloads of a type, latest first. */
410
415
  samplePayloads(type: string, limit?: number): Promise<unknown[]>;
411
416
  }
@@ -151,6 +151,9 @@ export declare class OKDBSyncGC {
151
151
  /** Reset a peer's ACK watermarks to 0 so the log is retained for a full resync. */
152
152
  forceResync(peer_id: string): Promise<void>;
153
153
  getStatus(): OKDBSyncGcStatus;
154
+ /** Start / stop the periodic sweep timer (started automatically on processor-role instances). */
155
+ start(): void;
156
+ stop(): void;
154
157
  }
155
158
 
156
159
  /**
@@ -162,6 +165,8 @@ export declare class OKDBSyncGC {
162
165
  export declare class OKDBSync {
163
166
  /** Changelog GC controller. */
164
167
  readonly gc: OKDBSyncGC;
168
+ /** This node's advertised address (the `sync.address` option, or the one restored from its own record). */
169
+ readonly address: string | undefined;
165
170
 
166
171
  info(): OKDBSyncInfo;
167
172
  /** This node's `~sync_nodes` record (a synthetic one before open). */
@@ -183,6 +188,8 @@ export declare class OKDBSync {
183
188
  /** Create or update the data link between this node and `peer_id`. */
184
189
  upsertLink(peer_id: string, options?: OKDBSyncLinkOptions): Promise<OKDBSyncLink>;
185
190
  removeLink(peer_id: string): Promise<void>;
191
+ /** Stop outbound sync on this instance (auto-reconcile, timers). */
192
+ stop(): void;
186
193
  /**
187
194
  * Low-level: compute the outbound delta after `from_clocks` (per env). `envs: null` = all
188
195
  * changelog-enabled envs. This is what the `/api/sync/delta` endpoint serves. `peer` (the
@@ -130,4 +130,7 @@ export declare class OKDBTimeMachine {
130
130
  fromClock: number,
131
131
  toClock: number,
132
132
  ): Generator<OKDBTimeMachineChange, void, undefined>;
133
+
134
+ /** Drain pending changes of `type` (all tracked types when omitted) now, instead of waiting out `flushDelayMs`. */
135
+ flush(type?: string): Promise<void>;
133
136
  }
package/types/index.d.ts CHANGED
@@ -97,6 +97,9 @@ declare namespace OKDB {
97
97
  export type OKDBForeignKeyError = _errors.OKDBForeignKeyError;
98
98
  export type OKDBForeignKeyDeleteError = _errors.OKDBForeignKeyDeleteError;
99
99
  export type OKDBIndexHasConsumersError = _errors.OKDBIndexHasConsumersError;
100
+ export type OKDBNotImplementedNativeError = _errors.OKDBNotImplementedNativeError;
101
+ export type OKDBArgumentErrorCode = _errors.OKDBArgumentErrorCode;
102
+ export type OKDBArgumentErrorDetails = _errors.OKDBArgumentErrorDetails;
100
103
  // ./environment
101
104
  export import OKDBTransactionOps = _environment.OKDBTransactionOps;
102
105
  export import OKDBTransaction = _environment.OKDBTransaction;