@kedem/okdb 3.0.0 → 3.1.0

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 (64) hide show
  1. package/CHANGELOG.md +114 -3
  2. package/README.md +72 -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 +79 -36
  8. package/docs/data-model.md +35 -9
  9. package/docs/deployment.md +42 -38
  10. package/docs/diagnostics.md +61 -125
  11. package/docs/embeddings.md +143 -51
  12. package/docs/encryption.md +132 -0
  13. package/docs/files.md +64 -27
  14. package/docs/fts.md +48 -23
  15. package/docs/functions.md +109 -56
  16. package/docs/getting-started.md +121 -9
  17. package/docs/http-api.md +66 -11
  18. package/docs/http-cluster.md +80 -88
  19. package/docs/index.md +33 -15
  20. package/docs/indexes.md +53 -17
  21. package/docs/licensing.md +19 -5
  22. package/docs/logging.md +11 -22
  23. package/docs/manifest.json +6 -3
  24. package/docs/migration.md +41 -16
  25. package/docs/pipelines.md +111 -46
  26. package/docs/plugins.md +47 -15
  27. package/docs/process-registry.md +23 -24
  28. package/docs/processors.md +26 -23
  29. package/docs/querying.md +102 -29
  30. package/docs/queue.md +165 -51
  31. package/docs/resolved-fields.md +24 -1
  32. package/docs/subscriptions.md +4 -4
  33. package/docs/sync.md +9 -6
  34. package/docs/time-machine.md +52 -14
  35. package/docs/transactions.md +63 -15
  36. package/docs/ttl.md +34 -13
  37. package/docs/upgrade-2.0.md +32 -15
  38. package/docs/upgrade-2.1.md +10 -12
  39. package/docs/upgrade-3.0.md +144 -0
  40. package/docs/views.md +165 -61
  41. package/index.js +1 -1
  42. package/native/linux-x64-gnu/okdb +0 -0
  43. package/native/linux-x64-gnu/okdb-node.linux-x64-gnu.node +0 -0
  44. package/native-loader.js +1 -1
  45. package/okdb-native.js +1 -1
  46. package/package.json +1 -1
  47. package/public/features/files/parts/files-blob-status.ok.js +1 -1
  48. package/types/environment.d.ts +32 -11
  49. package/types/errors.d.ts +20 -0
  50. package/types/features/admin.d.ts +3 -5
  51. package/types/features/api.d.ts +5 -7
  52. package/types/features/embeddings.d.ts +8 -7
  53. package/types/features/engines.d.ts +9 -1
  54. package/types/features/files.d.ts +2 -1
  55. package/types/features/fts.d.ts +3 -3
  56. package/types/features/functions.d.ts +14 -8
  57. package/types/features/pipelines.d.ts +10 -10
  58. package/types/features/queue.d.ts +15 -10
  59. package/types/features/sync.d.ts +7 -0
  60. package/types/features/time-machine.d.ts +3 -0
  61. package/types/index.d.ts +3 -0
  62. package/types/okdb.d.ts +70 -7
  63. package/types/options.d.ts +12 -8
  64. package/docs/OKDB-ARCHITECTURE.md +0 -1061
package/types/okdb.d.ts CHANGED
@@ -88,7 +88,8 @@ export type OKDBHttpRouteHandler = (req: OKDBHttpRequest & Record<string, any>)
88
88
  export interface OKDBHttp {
89
89
  /**
90
90
  * Start the built-in HTTP server (REST API + admin UI). Single-process only — a
91
- * `{ workers }` option throws HTTP_CLUSTER_REMOVED (use `bin/okdb` or Node `cluster`).
91
+ * `{ workers }` option throws HTTP_CLUSTER_REMOVED (use the `okdb` CLI's cluster, or run
92
+ * several processes behind a load balancer).
92
93
  * `host` binds one address (default: all interfaces); an array binds each address with its
93
94
  * own server sharing one request handler. Returns the Node `http.Server` — for an array, the
94
95
  * one bound to the first address (all of them are on `servers`; an 'error' from any is
@@ -171,6 +172,43 @@ export interface OKDBPressure {
171
172
  score: number;
172
173
  }
173
174
 
175
+ // ── Migration and plugins ─────────────────────────────────────────────────────
176
+
177
+ export interface OKDBMigrate {
178
+ /** Streaming NDJSON export (`{ env?, types?, changes?, blobs? }`). */
179
+ exportToStream(stream: NodeJS.WritableStream, options?: Record<string, unknown>): Promise<unknown>;
180
+ exportToFile(filePath: string, options?: Record<string, unknown>): Promise<unknown>;
181
+ exportEnvsToStream(stream: NodeJS.WritableStream, options?: Record<string, unknown>): Promise<unknown>;
182
+ importFromStream(stream: NodeJS.ReadableStream, options?: Record<string, unknown>): Promise<unknown>;
183
+ importFromFile(filePath: string, options?: Record<string, unknown>): Promise<unknown>;
184
+ /** Hot backup into a new directory (unrestricted from code; HTTP/MCP backups stay under `backup.root`). */
185
+ backup(destDir: string, options?: Record<string, unknown>): Promise<unknown>;
186
+ backupRoot(): string;
187
+ resolveBackupDest(destDir: string): string;
188
+ export(options?: Record<string, unknown>): Promise<unknown>;
189
+ import(data: unknown, options?: Record<string, unknown>): Promise<unknown>;
190
+ exportJSON(options?: Record<string, unknown>): Promise<unknown>;
191
+ importJSON(json: unknown): Promise<unknown>;
192
+ exportBlobs(targetDir: string): Promise<unknown>;
193
+ importBlobs(sourceDir: string): Promise<unknown>;
194
+ validateBlobIntegrity(): Promise<unknown>;
195
+ repairBlobRefs(): Promise<unknown>;
196
+ }
197
+
198
+ /** A plugin module: `register()` runs synchronously at registration (no IO) and may return start/stop hooks. */
199
+ export interface OKDBPluginModule<O = Record<string, unknown>> {
200
+ name: string;
201
+ /** Names of plugins that must be registered first (PLUGIN_DEPENDENCY_MISSING otherwise). */
202
+ requires?: string[];
203
+ register(okdb: OKDB, options: O): void | { start?(okdb: OKDB): unknown; stop?(okdb: OKDB): unknown };
204
+ }
205
+
206
+ export interface OKDBPluginRegistry {
207
+ /** Register before open() (INVALID_STATE after). start() hooks run after open() completes, stop() hooks in reverse
208
+ * order inside close(). */
209
+ register<O>(module: OKDBPluginModule<O>, options?: O): void;
210
+ }
211
+
174
212
  // ── Main class ────────────────────────────────────────────────────────────────
175
213
 
176
214
  /**
@@ -180,7 +218,15 @@ export interface OKDBPressure {
180
218
  * Removed: `db.workers` (throws WORKERS_REMOVED — run more processes with `processors: true`).
181
219
  */
182
220
  export declare class OKDB {
183
- static defaults: OKDBOptions;
221
+ /** Default values of the storage options (`maxDbs`, `pageSize`, `compression`, `mapSize`, `durability`, …). */
222
+ static readonly defaults: OKDBOptions;
223
+ /** Every constructor option name okdb recognizes; an unknown key logs a warning (once per process). */
224
+ static readonly KNOWN_OPTIONS: ReadonlySet<string>;
225
+ /** Which core this process runs: always `'native'` in okdb 3. */
226
+ static readonly implementation: 'native';
227
+ /** Absolute path of the native file this process loaded (`native/<platform>/okdb-node.<platform>.node`, or the
228
+ * `OKDB_NATIVE_BINARY` override). A C-bridge host in the same process dlopens this file. */
229
+ static readonly nativeBinaryPath: string | null;
184
230
  /** Sentinel Buffer for open-ended index range ends: `end: [prefix, OKDB.HIGH_SENTINEL]`. */
185
231
  static HIGH_SENTINEL: Buffer;
186
232
  /**
@@ -229,10 +275,17 @@ export declare class OKDB {
229
275
  readonly http: OKDBHttp;
230
276
  readonly auth: OKDBAuth;
231
277
  readonly log: unknown;
232
- /** UDP bus (null when the shmbuf native binding is missing). */
233
- readonly bus: unknown;
234
- /** null when constructed with `admin: false`. */
278
+ /** The local UDP bus that wakes peer processes on the same store (`{ state, isRunning, emit }`); null before open() /
279
+ * after close() or when the bus is off. */
280
+ readonly bus: {
281
+ readonly state: string;
282
+ readonly isRunning: boolean;
283
+ emit(event: string, data?: string): void;
284
+ } | null;
285
+ /** Not available in okdb 3: any member call throws NOT_IMPLEMENTED_NATIVE (null when constructed with `admin: false`).
286
+ * The admin UI itself is served by `db.http.listen()`. */
235
287
  readonly admin: OKDBAdmin | null;
288
+ /** Not available in okdb 3: any member call throws NOT_IMPLEMENTED_NATIVE. Add routes with `db.http.add()`. */
236
289
  readonly api: OKDBApi;
237
290
  readonly sync: OKDBSync;
238
291
  readonly embeddings: OKDBEmbeddings;
@@ -250,12 +303,19 @@ export declare class OKDB {
250
303
  /** Process registry (the `/api/processes` census). */
251
304
  readonly processes: unknown;
252
305
  readonly meta: unknown;
253
- readonly migrate: unknown;
254
- readonly plugins: unknown;
306
+ /** Export / import / backup (see docs/migration.md). */
307
+ readonly migrate: OKDBMigrate;
308
+ /** Plugin registry (see docs/plugins.md): register before open(). */
309
+ readonly plugins: OKDBPluginRegistry;
255
310
  /** Named cross-process mutexes in `~system`. */
256
311
  readonly locks: unknown;
257
312
  /** The default env's processor. */
258
313
  readonly processor: OKDBEnvProcessor;
314
+ /** The default env's views (`db.env('default').views`). */
315
+ readonly views: import('./features/views').OKDBViews;
316
+ /** C-bridge attach helpers (see docs/c-bridge.md): the handle for `attach()`, the address of this image's
317
+ * `OkdbBridgeV1` table for ABI 1, and the path of the loaded native file. */
318
+ readonly _native: { bridgeHandle(): number; bridgeTable(): bigint; bridgeLibPath(): string };
259
319
 
260
320
  // ── Queue and files are shortcuts to the default env ──────────────────────
261
321
  readonly queue: OKDBQueue;
@@ -278,6 +338,9 @@ export declare class OKDB {
278
338
  diag(): Record<string, unknown>;
279
339
  /** @deprecated Pools were removed; use per-processor pause/resume instead. */
280
340
  setProcessingConfig(config: Record<string, unknown>): Promise<void>;
341
+ /** Boot the stored runtime declarations (engines/pipelines when `engines` is on, views on a participating node) —
342
+ * what open() does unless constructed with `runtimeDeclarations: false`. */
343
+ bootRuntimeDeclarations(): Promise<void>;
281
344
 
282
345
  // ── Environment management ────────────────────────────────────────────────
283
346
  readonly default: OKDBEnvironment;
@@ -14,7 +14,7 @@ export type OKDBIndexSpec = string | string[];
14
14
  /**
15
15
  * `new OKDB(path, options)`.
16
16
  *
17
- * Removed options throw at construction (see docs/upgrade-2.0.md): `asyncProcessors`
17
+ * Removed options throw at construction (see docs/upgrade-2.0.md; unchanged in 3.0): `asyncProcessors`
18
18
  * (ASYNC_PROCESSORS_REMOVED), `processing` (PROCESSING_REMOVED), `bus` (BUS_OPTION_REMOVED),
19
19
  * `envs` (ENVS_REMOVED), `deferProcessing` (DEFER_PROCESSING_REMOVED), `workers` (WORKERS_REMOVED),
20
20
  * `sync: true | false` (SYNC_OPTION_REMOVED — `sync` is only the settings object now),
@@ -25,11 +25,12 @@ export interface OKDBOptions {
25
25
  maxDbs?: number;
26
26
  pageSize?: number;
27
27
  compression?: boolean;
28
- encryptionKey?: string | Buffer;
28
+ /** Encryption key for data at rest (a string; pass the same key on every open). */
29
+ encryptionKey?: string;
29
30
  mapSize?: number;
30
31
  durability?: 'strict' | 'balanced' | 'fast' | 'custom';
31
32
  allowUnsafe?: boolean;
32
- /** Raw lmdb-js options (advanced; validated against `durability`). */
33
+ /** Raw LMDB environment flags (advanced; validated against `durability`). */
33
34
  lmdb?: Record<string, unknown>;
34
35
  auth?: OKDBAuthOptions;
35
36
  /** Sync (replication) settings for `db.sync`. */
@@ -85,8 +86,9 @@ export interface OKDBOptions {
85
86
  subscriptions?: { beatMs?: number; [key: string]: unknown };
86
87
  /** Debug switches (e.g. `{ logRequests: true }`). */
87
88
  debug?: { logRequests?: boolean; [key: string]: unknown };
88
- /** Action when a license expires at runtime. */
89
- onLicenseExpired?: string;
89
+ /** Action when a license expires at runtime: `'log'` (default — drop to the next license / free tier and keep running)
90
+ * or `'shutdown'` (exit the process). */
91
+ onLicenseExpired?: 'log' | 'shutdown';
90
92
  }
91
93
 
92
94
  export interface OKDBAutoCompactOptions {
@@ -162,7 +164,8 @@ export interface OKDBEnvironmentConfig {
162
164
  durability?: 'strict' | 'balanced' | 'fast' | 'custom';
163
165
  lmdb?: Record<string, unknown>;
164
166
  compression?: boolean;
165
- encryptionKey?: string | Buffer;
167
+ /** Encryption key for data at rest (a string; pass the same key on every open). */
168
+ encryptionKey?: string;
166
169
  parentEnv?: string;
167
170
  /** Per-env role overrides (same meaning as the constructor flags). */
168
171
  engines?: boolean;
@@ -196,7 +199,7 @@ export interface OKDBRangeOptions {
196
199
  offset?: number;
197
200
  versions?: boolean;
198
201
  snapshot?: OKDBSnapshotMode;
199
- /** A caller-managed lmdb read transaction (advanced). */
202
+ /** A caller-managed read transaction (advanced). */
200
203
  transaction?: unknown;
201
204
  }
202
205
 
@@ -346,7 +349,7 @@ export interface OKDBTransactionOptions {
346
349
  // ── Result shapes ─────────────────────────────────────────────────────────────
347
350
 
348
351
  /**
349
- * Lazy range result (lmdb-js RangeIterable or okdb's guarded equivalent). Iterate it or chain
352
+ * Lazy range result. Iterate it or chain
350
353
  * `map`/`filter`; materialize with `Array.from(...)`.
351
354
  */
352
355
  export interface OKDBRangeIterable<T> extends Iterable<T> {
@@ -497,6 +500,7 @@ export interface OKDBInfoResult {
497
500
  mapSize: number;
498
501
  clock: number;
499
502
  plugins: string[];
503
+ /** `lmdb` (the 2.x JS binding version) is null in okdb 3; `lmdbNative` is the LMDB library version. */
500
504
  versions: { okdb: string; lmdb: string | null; lmdbNative: string };
501
505
  version: string;
502
506
  ttl: OKDBTtlStats;