@kedem/okdb 2.3.4 → 2.4.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 (60) hide show
  1. package/CHANGELOG.md +366 -0
  2. package/algorithm-worker-thread.js +1 -1
  3. package/bin/okdb.js +1 -1
  4. package/docs/auth-and-sync.md +28 -4
  5. package/docs/auth-permissions.md +19 -6
  6. package/docs/change-log.md +79 -59
  7. package/docs/data-model.md +20 -18
  8. package/docs/deployment.md +25 -0
  9. package/docs/diagnostics.md +59 -17
  10. package/docs/embeddings.md +57 -6
  11. package/docs/files.md +1 -1
  12. package/docs/fts.md +50 -5
  13. package/docs/functions.md +21 -8
  14. package/docs/http-api.md +139 -98
  15. package/docs/http-cluster.md +30 -8
  16. package/docs/indexes.md +5 -4
  17. package/docs/logging.md +18 -0
  18. package/docs/migration.md +94 -2
  19. package/docs/pipelines.md +6 -1
  20. package/docs/plugins.md +12 -18
  21. package/docs/process-registry.md +50 -39
  22. package/docs/processors.md +40 -22
  23. package/docs/querying.md +50 -36
  24. package/docs/queue.md +110 -14
  25. package/docs/subscriptions.md +35 -24
  26. package/docs/sync.md +96 -37
  27. package/docs/time-machine.md +23 -17
  28. package/docs/transactions.md +11 -19
  29. package/docs/ttl.md +118 -67
  30. package/docs/upgrade-2.0.md +2 -2
  31. package/docs/views.md +71 -52
  32. package/okdb-functions-sandbox-worker.js +1 -1
  33. package/okdb-http-worker-child.js +1 -1
  34. package/okdb-views-bootstrap-worker.js +1 -1
  35. package/okdb.js +1 -1
  36. package/package.json +1 -1
  37. package/public/sections/db/parts/type-viewer.ok.js +1 -1
  38. package/public/sections/embeddings/parts/engines-overview.ok.js +1 -1
  39. package/public/sections/queue/parts/queue-jobs.ok.js +1 -1
  40. package/public/sections/system/modals/data-ops-modal.ok.js +1 -1
  41. package/types/environment.d.ts +320 -52
  42. package/types/features/admin.d.ts +8 -2
  43. package/types/features/api.d.ts +10 -16
  44. package/types/features/auth.d.ts +135 -16
  45. package/types/features/embeddings.d.ts +639 -31
  46. package/types/features/engines.d.ts +368 -14
  47. package/types/features/files.d.ts +2 -4
  48. package/types/features/fts.d.ts +98 -26
  49. package/types/features/functions.d.ts +175 -15
  50. package/types/features/mcp.d.ts +23 -10
  51. package/types/features/pipelines.d.ts +268 -9
  52. package/types/features/queue.d.ts +230 -34
  53. package/types/features/sync.d.ts +177 -14
  54. package/types/features/time-machine.d.ts +117 -16
  55. package/types/features/views.d.ts +230 -39
  56. package/types/index.d.ts +357 -254
  57. package/types/okdb.d.ts +377 -0
  58. package/types/options.d.ts +309 -48
  59. package/public/test-cron-input.html +0 -60
  60. package/public/test-json-input.html +0 -280
@@ -1,23 +1,38 @@
1
+ import type { EventEmitter } from 'events';
1
2
  import type {
2
3
  OKDBPrimaryKey,
3
4
  OKDBIndexKey,
5
+ OKDBIndexSpec,
4
6
  OKDBFilter,
5
7
  OKDBRangeOptions,
6
8
  OKDBQueryOptions,
9
+ OKDBHybridQueryOptions,
7
10
  OKDBIndexRangeOptions,
8
11
  OKDBGeoQueryOptions,
9
12
  OKDBFtsQueryOptions,
10
13
  OKDBWriteOptions,
14
+ OKDBRemoveOptions,
15
+ OKDBTransactionOptions,
11
16
  OKDBEntry,
12
17
  OKDBIndexEntry,
18
+ OKDBQueryEntry,
13
19
  OKDBChangeEntry,
20
+ OKDBRangeIterable,
14
21
  OKDBEnvironmentConfig,
15
22
  OKDBIndexDefinition,
23
+ OKDBRegisterIndexOptions,
24
+ OKDBEnsureDefinition,
16
25
  OKDBTypeSchema,
17
26
  OKDBCompactResult,
18
27
  OKDBTtlListOptions,
28
+ OKDBTtlInfo,
29
+ OKDBTtlListResult,
30
+ OKDBTtlStats,
31
+ OKDBTtlSweepResult,
32
+ OKDBResolvedOptions,
33
+ OKDBRoleFlags,
19
34
  } from './options';
20
-
35
+ import type { OKDBFtsSearchResult } from './features/fts';
21
36
  import type { OKDBQueue } from './features/queue';
22
37
  import type { OKDBFiles } from './features/files';
23
38
  import type { OKDBTimeMachine } from './features/time-machine';
@@ -26,48 +41,265 @@ import type { OKDBPipelines } from './features/pipelines';
26
41
  import type { OKDBFunctions } from './features/functions';
27
42
  import type { OKDBViews } from './features/views';
28
43
 
29
- /** Transaction object for batching writes without auto-commit. */
30
- export interface OKDBTransaction {
44
+ // ── Transactions ──────────────────────────────────────────────────────────────
45
+
46
+ /** Write intents + committed-state reads shared by OKDBTransaction and the txn() facade.
47
+ * Reads see committed state only — writes queued in the same transaction are NOT visible. */
48
+ export interface OKDBTransactionOps {
31
49
  put(type: string, key: OKDBPrimaryKey, value: unknown, options?: OKDBWriteOptions): void;
32
50
  update(type: string, key: OKDBPrimaryKey, value: unknown, options?: OKDBWriteOptions): void;
33
51
  patch(type: string, key: OKDBPrimaryKey, patch: Record<string, unknown>, options?: OKDBWriteOptions): void;
34
52
  create(type: string, key: OKDBPrimaryKey, value: unknown, options?: OKDBWriteOptions): void;
35
- remove(type: string, key: OKDBPrimaryKey, options?: Pick<OKDBWriteOptions, 'ifVersion'>): void;
53
+ remove(type: string, key: OKDBPrimaryKey, options?: OKDBRemoveOptions): void;
54
+ setTTL(type: string, key: OKDBPrimaryKey, ttlMs: number): void;
55
+ clearTTL(type: string, key: OKDBPrimaryKey): void;
56
+
57
+ get<T = unknown>(type: string, key: OKDBPrimaryKey): T | undefined;
58
+ getEntry<T = unknown>(type: string, key: OKDBPrimaryKey): OKDBEntry<T> | undefined;
59
+ getMany<T = unknown>(type: string, keys: OKDBPrimaryKey[]): (T | undefined)[];
60
+ getRange<T = unknown>(type: string, options?: OKDBRangeOptions): OKDBRangeIterable<OKDBEntry<T>>;
61
+ getValues<T = unknown>(type: string, options?: OKDBRangeOptions): OKDBRangeIterable<T>;
62
+ getKeys(type: string, options?: OKDBRangeOptions): OKDBRangeIterable<OKDBPrimaryKey>;
63
+ byIndex<T = unknown>(
64
+ type: string,
65
+ index: OKDBIndexSpec,
66
+ options?: OKDBIndexRangeOptions,
67
+ ): OKDBRangeIterable<OKDBIndexEntry<T>>;
68
+ query<T = unknown>(type: string, filter?: OKDBFilter, options?: OKDBQueryOptions): Iterable<OKDBQueryEntry<T>>;
69
+ getClock(type?: string | null): number;
70
+ getCount(type: string): number;
71
+ }
72
+
73
+ /**
74
+ * Explicit transaction from `transaction()`: queue writes, then `commit()` applies them
75
+ * atomically through the env's single writer. With `useReadTransaction`, reads see a consistent
76
+ * view for the creation turn only (READER_HELD_ACROSS_AWAIT after an await, unless 'tolerant').
77
+ */
78
+ export interface OKDBTransaction extends OKDBTransactionOps {
79
+ readonly id: string;
36
80
  commit(): Promise<void>;
81
+ rollback(): void;
82
+ }
83
+
84
+ /** The frozen facade passed to `txn(work)`; the transaction commits when `work` resolves
85
+ * (don't call `commit()` yourself inside `work`). */
86
+ export interface OKDBTransactionFacade extends OKDBTransactionOps {
87
+ readonly id: string;
88
+ commit(): Promise<void>;
89
+ rollback(): void;
90
+ }
91
+
92
+ /** Declarative op for `txn([...ops])`: `{ action, type, key, value?, patch?, ttl?, options? }`
93
+ * or a tuple `['put', type, key, value, options?]`. */
94
+ export type OKDBTransactionOp =
95
+ | {
96
+ action: 'put' | 'update' | 'create';
97
+ type: string;
98
+ key: OKDBPrimaryKey;
99
+ value: unknown;
100
+ ttl?: number | null;
101
+ options?: OKDBWriteOptions;
102
+ }
103
+ | {
104
+ action: 'patch';
105
+ type: string;
106
+ key: OKDBPrimaryKey;
107
+ patch: Record<string, unknown>;
108
+ ttl?: number | null;
109
+ options?: OKDBWriteOptions;
110
+ }
111
+ | { action: 'remove'; type: string; key: OKDBPrimaryKey; options?: OKDBRemoveOptions }
112
+ | { action: 'setTTL'; type: string; key: OKDBPrimaryKey; ttl: number }
113
+ | { action: 'clearTTL'; type: string; key: OKDBPrimaryKey }
114
+ | [string, ...unknown[]];
115
+
116
+ /** `txn()` resolves with the committed transaction's id and action count. */
117
+ export interface OKDBTxnResult {
118
+ id: string;
119
+ actions: number;
120
+ }
121
+
122
+ // ── Processors ────────────────────────────────────────────────────────────────
123
+
124
+ /** Processor handler: `fn(ctx, changes, info)` with `ctx = { env, payload }`. */
125
+ export type OKDBProcessorHandler = (
126
+ ctx: { env: OKDBEnvironment; payload: unknown; [key: string]: unknown },
127
+ changes: OKDBChangeEntry[],
128
+ info: unknown,
129
+ ) => unknown;
130
+
131
+ /** `env.processor.register(type, options)`. Exactly one of `module` / `handler` is required;
132
+ * bare closures throw. */
133
+ export interface OKDBProcessorRegisterOptions {
134
+ /** File handler: `{ path, export }`, called as `fn(ctx, changes, info)`. */
135
+ module?: { path: string; export?: string };
136
+ /** Name of a handler registered with `OKDBProcessor.registerHandler(name, fn)`. */
137
+ handler?: string;
138
+ payload?: unknown;
139
+ /** `'async'` (default; background drain) | `'sync'` (every writer, inside the commit).
140
+ * Deprecated aliases `'single'` / `'worker'` / `'fanout'` / `'inline'` warn. */
141
+ mode?: 'async' | 'sync' | 'single' | 'worker' | 'fanout' | 'inline';
142
+ /** mode:'async' only: `'single'` (1-of-N, leased, durable cursor) | `'fanout'` (N-of-N). */
143
+ distribution?: 'single' | 'fanout';
144
+ bootstrap?: 'snapshot' | 'log';
145
+ originMode?: 'self' | 'remote' | 'all';
146
+ batchSize?: number;
147
+ hydrateValues?: boolean;
148
+ /** Durable resume position key. */
149
+ cursorKey?: string | null;
150
+ lockMode?: 'exclusive' | null;
151
+ failOnHandlerError?: boolean;
152
+ name?: string | null;
153
+ meta?: Record<string, unknown>;
154
+ leaseTtlMs?: number;
155
+ /** Trailing-edge debounce in ms (0 = flush immediately). */
156
+ flushDebounce?: number;
157
+ /** Periodic poll interval in ms after bootstrap (null = disabled). */
158
+ flushInterval?: number | null;
159
+ /** Tail the whole-env change log instead of one type. */
160
+ envWide?: boolean;
161
+ drainDeadlineMs?: number;
162
+ flushQuantum?: number | null;
163
+ /** `{ durable: true }` marks a sync handler reconstructible on every instance. */
164
+ definition?: { durable?: boolean; [key: string]: unknown } | null;
165
+ }
166
+
167
+ /** A processor's status row. */
168
+ export interface OKDBProcessorStatus {
169
+ id: string;
170
+ type: string | null;
171
+ /** Public mode token: 'single' (1-of-N), 'fanout' (N-of-N) or 'inline'. */
172
+ mode: string;
173
+ state: string;
174
+ paused: boolean;
175
+ unclaimed: boolean;
176
+ claimGated: boolean;
177
+ heldBy: { pid: number | null; hostname: string | null } | null;
178
+ lastClock: number;
179
+ headClock: number;
180
+ logHead: number;
181
+ envClock: number | null;
182
+ /** Pending changes, computed from the durable cursor. */
183
+ lag: number;
184
+ bootstrap: string;
185
+ progress: unknown;
186
+ error: unknown;
187
+ meta: Record<string, unknown>;
188
+ cursorKey: string | null;
189
+ [key: string]: unknown;
190
+ }
191
+
192
+ /** Returned by `processor.register()`: call it (await) to unregister; carries controls. */
193
+ export interface OKDBProcessorHandle {
194
+ (): Promise<void>;
195
+ readonly id: string;
196
+ readonly cursorKey: string | null;
197
+ /** The durable (persisted, cross-process) cursor. */
198
+ durableClock(): number;
199
+ status(): OKDBProcessorStatus | null;
200
+ getStatus(): OKDBProcessorStatus | null;
201
+ pause(): boolean;
202
+ resume(): boolean;
203
+ retry(): boolean;
204
+ kick(): boolean;
205
+ awaitIdle(): Promise<void>;
206
+ }
207
+
208
+ /** Per-env change-subscription primitive (`env.processor`). */
209
+ export interface OKDBEnvProcessor {
210
+ register(type: string | null, options: OKDBProcessorRegisterOptions): OKDBProcessorHandle;
211
+ list(): OKDBProcessorStatus[];
212
+ get(id: string): OKDBProcessorStatus | null;
213
+ pause(id: string): boolean;
214
+ resume(id: string): boolean;
215
+ retry(id: string): boolean;
216
+ kick(id: string): boolean;
217
+ awaitIdle(id: string): Promise<void>;
218
+ getCursor(cursorKey: string): number;
219
+ setCursor(cursorKey: string, clock: number): void;
220
+ resetCursor(cursorKey: string): void;
221
+ /** Flip a processor's mode at runtime (durable, cross-process). `logicalKey` = `env::cursorKey`. */
222
+ setMode(logicalKey: string, mode: string, distribution?: 'single' | 'fanout'): Promise<unknown>;
223
+ restart(logicalKey: string, options?: { reset?: boolean }): boolean;
224
+ [key: string]: unknown;
225
+ }
226
+
227
+ // ── Environment ───────────────────────────────────────────────────────────────
228
+
229
+ export interface OKDBStorageStats {
230
+ fileBytes: number | null;
231
+ usedBytes: number | null;
232
+ liveBytes: number | null;
233
+ reclaimableBytes: number | null;
234
+ reclaimablePct: number | null;
235
+ warn: boolean;
236
+ lastTxnId: number | null;
237
+ readers: {
238
+ count: number;
239
+ maxTxnsBehind: number;
240
+ list: Array<{ pid: number; txnId: number | null; txnsBehind: number }>;
241
+ };
242
+ lastCompact: unknown;
243
+ autoCompact: { enabled: boolean; eligible: boolean };
244
+ }
245
+
246
+ export interface OKDBWriterStatus {
247
+ depth: number;
248
+ /** Age of the oldest pending commit — THE stall signal. */
249
+ oldestPendingMs: number;
250
+ committed?: number;
251
+ commitsPerSec: number;
252
+ commitP99Ms: number;
253
+ draining: boolean;
254
+ drainTs: number;
255
+ activeWriters: number;
256
+ ownWriters: number;
257
+ [key: string]: unknown;
37
258
  }
38
259
 
39
260
  /**
40
261
  * An OKDB environment — a named LMDB database within a single OKDB instance.
41
262
  * All data operations are scoped to this environment.
42
- * Returned by `okdb.env(name)` and `okdb.default`.
263
+ * Returned by `db.env(name)`, `db.openEnv(name)`, `db.createEnvironment(name)` and `db.default`.
43
264
  */
44
265
  export interface OKDBEnvironment {
45
266
  readonly name: string;
46
267
  readonly path: string;
47
268
  readonly config: OKDBEnvironmentConfig;
269
+ /** Instance identity (shared with the owning OKDB). */
48
270
  readonly id: string;
271
+ /** Shared with the owning OKDB (`db.events`). */
272
+ readonly events: EventEmitter;
273
+ /** Role flags for this env (processors mirrors the owner's current participation). */
274
+ readonly role: OKDBRoleFlags;
49
275
 
50
276
  // ── Per-env subsystems ────────────────────────────────────────────────────
51
- queue: OKDBQueue;
52
- files: OKDBFiles;
53
- timeMachine?: OKDBTimeMachine;
54
- engines: OKDBEngines;
55
- pipelines: OKDBPipelines;
56
- functions: OKDBFunctions;
57
- views: OKDBViews;
277
+ readonly queue: OKDBQueue;
278
+ readonly files: OKDBFiles;
279
+ /** Present only when the `timeMachine` constructor option is set (and licensed). */
280
+ readonly timeMachine?: OKDBTimeMachine;
281
+ readonly engines: OKDBEngines;
282
+ readonly pipelines: OKDBPipelines;
283
+ readonly functions: OKDBFunctions;
284
+ readonly views: OKDBViews;
285
+ readonly processor: OKDBEnvProcessor;
58
286
 
59
287
  // ── Transactions ──────────────────────────────────────────────────────────
60
- transaction(options?: Record<string, unknown>): OKDBTransaction;
61
- txn<T = void>(work: (txn: OKDBTransaction) => T | Promise<T>, options?: Record<string, unknown>): Promise<T>;
288
+ transaction(options?: OKDBTransactionOptions): OKDBTransaction;
289
+ /** Run `work` (or apply declarative `ops`) and commit atomically. */
290
+ txn(
291
+ work: ((txn: OKDBTransactionFacade) => unknown) | OKDBTransactionOp[],
292
+ options?: OKDBTransactionOptions,
293
+ ): Promise<OKDBTxnResult>;
62
294
 
63
295
  // ── CRUD ──────────────────────────────────────────────────────────────────
64
296
  put(type: string, key: OKDBPrimaryKey, value: unknown, options?: OKDBWriteOptions): Promise<void>;
65
297
  update(type: string, key: OKDBPrimaryKey, value: unknown, options?: OKDBWriteOptions): Promise<void>;
66
298
  patch(type: string, key: OKDBPrimaryKey, patch: Record<string, unknown>, options?: OKDBWriteOptions): Promise<void>;
67
299
  create(type: string, key: OKDBPrimaryKey, value: unknown, options?: OKDBWriteOptions): Promise<void>;
68
- remove(type: string, key: OKDBPrimaryKey, options?: Pick<OKDBWriteOptions, 'ifVersion'>): Promise<void>;
300
+ remove(type: string, key: OKDBPrimaryKey, options?: OKDBRemoveOptions): Promise<void>;
69
301
 
70
- // ── Read ──────────────────────────────────────────────────────────────────
302
+ // ── Read (synchronous) ────────────────────────────────────────────────────
71
303
  get<T = unknown>(type: string, key: OKDBPrimaryKey, options?: Record<string, unknown>): T | undefined;
72
304
  getMany<T = unknown>(type: string, keys: OKDBPrimaryKey[], options?: Record<string, unknown>): (T | undefined)[];
73
305
  getEntry<T = unknown>(
@@ -75,32 +307,47 @@ export interface OKDBEnvironment {
75
307
  key: OKDBPrimaryKey,
76
308
  options?: Record<string, unknown>,
77
309
  ): OKDBEntry<T> | undefined;
78
- getRange<T = unknown>(type: string, options?: OKDBRangeOptions): Iterable<OKDBEntry<T>>;
79
- getValues<T = unknown>(type: string, options?: OKDBRangeOptions): Iterable<T>;
80
- getKeys(type: string, options?: OKDBRangeOptions): Iterable<OKDBPrimaryKey>;
310
+ getRange<T = unknown>(type: string, options?: OKDBRangeOptions): OKDBRangeIterable<OKDBEntry<T>>;
311
+ getValues<T = unknown>(type: string, options?: OKDBRangeOptions): OKDBRangeIterable<T>;
312
+ getKeys(type: string, options?: OKDBRangeOptions): OKDBRangeIterable<OKDBPrimaryKey>;
81
313
  getCount(type: string, options?: OKDBRangeOptions): number;
82
- getByPrefix<T = unknown>(type: string, prefix: OKDBPrimaryKey, options?: OKDBRangeOptions): Iterable<OKDBEntry<T>>;
83
-
84
- // ── Index queries ─────────────────────────────────────────────────────────
85
- getIndex<T = unknown>(type: string, index: string[], options?: OKDBIndexRangeOptions): Iterable<OKDBIndexEntry<T>>;
86
- byIndex<T = unknown>(type: string, index: string[], options?: OKDBIndexRangeOptions): Iterable<OKDBIndexEntry<T>>;
87
- countByIndex(type: string, index: string[], options?: OKDBIndexRangeOptions): number;
88
- query<T = unknown>(type: string, filter: OKDBFilter, options?: OKDBQueryOptions): Iterable<OKDBIndexEntry<T>>;
89
- geoQuery<T = unknown>(type: string, field: string, options: OKDBGeoQueryOptions): Iterable<OKDBEntry<T>>;
90
- ftsQuery<T = unknown>(
314
+ getByPrefix<T = unknown>(type: string, prefix: string, options?: OKDBRangeOptions): OKDBRangeIterable<OKDBEntry<T>>;
315
+
316
+ // ── Index queries (pinned + guarded: consume synchronously) ───────────────
317
+ /** Raw index scan — yields the primary keys stored in the index. */
318
+ getIndex(type: string, index: string[], options?: OKDBIndexRangeOptions): OKDBRangeIterable<OKDBPrimaryKey>;
319
+ byIndex<T = unknown>(
320
+ type: string,
321
+ index: OKDBIndexSpec,
322
+ options?: OKDBIndexRangeOptions,
323
+ ): OKDBRangeIterable<OKDBIndexEntry<T>>;
324
+ countByIndex(type: string, index: OKDBIndexSpec, options?: OKDBIndexRangeOptions): number;
325
+ /** With an `fts` or `vector` signal, query() is async and resolves to an array. */
326
+ 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>>;
328
+ geoQuery<T = unknown>(
329
+ type: string,
330
+ field: string,
331
+ options: OKDBGeoQueryOptions,
332
+ ): Iterable<OKDBQueryEntry<T> & { distance?: number }>;
333
+ /** FTS search with an optional post-filter; returns hydrated, scored docs. */
334
+ ftsQuery(
91
335
  type: string,
92
336
  name: string,
93
337
  text: string,
94
338
  filter?: OKDBFilter,
95
339
  options?: OKDBFtsQueryOptions,
96
- ): Iterable<OKDBEntry<T>>;
340
+ ): OKDBFtsSearchResult[];
97
341
 
98
342
  // ── Type management ───────────────────────────────────────────────────────
99
343
  registerType(type: string, timestamp?: number): Promise<void>;
344
+ /** Get-or-create a type (race-safe across processes) plus its indexes. */
100
345
  ensureType(
101
346
  type: string,
102
347
  options?: { timestamp?: number; indexes?: Array<string[] | OKDBIndexDefinition> },
103
348
  ): Promise<void>;
349
+ /** Idempotent declaration of a type with its indexes, FTS indexes, views and schema. */
350
+ ensure(definition: OKDBEnsureDefinition): Promise<void>;
104
351
  hasType(type: string): boolean;
105
352
  dropType(type: string, timestamp?: number): Promise<void>;
106
353
 
@@ -134,42 +381,63 @@ export interface OKDBEnvironment {
134
381
  setSchema(type: string, schema: OKDBTypeSchema): Promise<void>;
135
382
  getSchema(type: string): OKDBTypeSchema | null;
136
383
  dropSchema(type: string): Promise<void>;
384
+ /** Schema-violation record for one document (non-enforced schemas), or null. */
385
+ getViolation(type: string, key: OKDBPrimaryKey): unknown;
386
+ listViolations(type?: string | null): unknown[];
387
+ /** Foreign-key violation record, or null. */
388
+ getRefViolation(sourceType: string, sourceKey: OKDBPrimaryKey, fieldPath: string): unknown;
389
+ listRefViolations(sourceType?: string | null): unknown[];
137
390
 
138
391
  // ── Index management ──────────────────────────────────────────────────────
139
- registerIndex(
140
- type: string,
141
- index: string[],
142
- options?: { type?: 'geo'; precision?: number; unique?: boolean; timestamp?: number },
143
- ): Promise<void>;
144
- hasIndex(type: string, index: string[]): boolean;
145
- dropIndex(type: string, index: string[], timestamp?: number): Promise<void>;
146
- resetIndex(type: string, index: string[], clear?: boolean): Promise<void>;
147
- indexReady(type: string, index: string[]): Promise<boolean>;
148
- getIndexStatus(type: string, index: string[]): string;
149
- getUniqueViolations(type: string, index: string[]): unknown[];
150
- hasUniqueViolations(type: string, index: string[]): boolean;
151
- getUniqueViolation(type: string, index: string[], key: OKDBPrimaryKey): unknown;
392
+ registerIndex(type: string, index: OKDBIndexSpec, options?: OKDBRegisterIndexOptions | number): Promise<void>;
393
+ hasIndex(type: string, index: OKDBIndexSpec): boolean;
394
+ dropIndex(type: string, index: OKDBIndexSpec, timestamp?: number): Promise<void>;
395
+ resetIndex(type: string, index: OKDBIndexSpec, clear?: boolean): Promise<void>;
396
+ /** Resolves true once the index build is complete. */
397
+ indexReady(type: string, index: OKDBIndexSpec): Promise<boolean>;
398
+ getIndexStatus(type: string, index: OKDBIndexSpec): string;
399
+ getUniqueViolations(type?: string | null, index?: OKDBIndexSpec): unknown[];
400
+ hasUniqueViolations(type?: string | null, index?: OKDBIndexSpec): boolean;
401
+ getUniqueViolation(type: string, index: OKDBIndexSpec, indexKey: OKDBIndexKey): unknown;
152
402
 
153
403
  // ── Change tracking ───────────────────────────────────────────────────────
154
- getClock(type?: string, options?: Record<string, unknown>): number;
155
- getChanges(type?: string, from?: number, to?: number, options?: Record<string, unknown>): Iterable<OKDBChangeEntry>;
404
+ getClock(type?: string | null, options?: Record<string, unknown>): number;
405
+ /** Change log between two clocks (reverse when from > to). Pinned + guarded. */
406
+ getChanges(
407
+ type?: string | null,
408
+ from?: number,
409
+ to?: number,
410
+ options?: { snapshot?: boolean | 'tolerant'; limit?: number; transaction?: unknown },
411
+ ): Iterable<OKDBChangeEntry>;
156
412
 
157
413
  // ── TTL ───────────────────────────────────────────────────────────────────
158
414
  setTTL(type: string, key: OKDBPrimaryKey, ttlMs: number): Promise<void>;
159
- getTTL(type: string, key: OKDBPrimaryKey): number | null;
415
+ getTTL(type: string, key: OKDBPrimaryKey): OKDBTtlInfo | null;
160
416
  clearTTL(type: string, key: OKDBPrimaryKey): Promise<void>;
161
- sweepExpiredTTL(batchSize?: number): Promise<number>;
162
- listTTL(options?: OKDBTtlListOptions): Iterable<{ type: string; key: OKDBPrimaryKey; expiresAt: number }>;
163
- ttlStats(type?: string): unknown;
417
+ sweepExpiredTTL(batchSize?: number): Promise<OKDBTtlSweepResult>;
418
+ listTTL(options?: OKDBTtlListOptions): OKDBTtlListResult;
419
+ ttlStats(type?: string | null): OKDBTtlStats;
164
420
  setDefaultTTL(type: string, ttlMs: number): Promise<void>;
165
421
  getDefaultTTL(type: string): number | null;
166
422
  clearDefaultTTL(type: string): Promise<void>;
167
423
 
424
+ // ── Maintenance / observability ───────────────────────────────────────────
425
+ /** Compact data.mdb (skips when another process holds the compaction lease). `force` drains
426
+ * harder; `repair` forces a logical rebuild. Concurrent calls reject with REBUILD_IN_PROGRESS. */
427
+ compact(options?: { force?: boolean; repair?: boolean }): Promise<OKDBCompactResult>;
428
+ /** Force a logical rebuild (operator-triggered repair). */
429
+ repair(options?: { force?: boolean }): Promise<OKDBCompactResult>;
430
+ storageStats(): OKDBStorageStats;
431
+ writerStatus(): OKDBWriterStatus;
432
+ /** OKDB_DIAG snapshot (`{ enabled: false, … }` unless OKDB_DIAG=1). */
433
+ diag(): Record<string, unknown>;
434
+ getResolvedOptions(): OKDBResolvedOptions;
435
+ refreshReadTxn(): void;
436
+
168
437
  // ── Utilities ─────────────────────────────────────────────────────────────
169
438
  count(iterable: Iterable<unknown>): number;
170
- range(iterable: Iterable<unknown>): Generator<unknown>;
439
+ /** Yield every item of a range iterable (e.g. a `getRange()` result) or any iterable. */
440
+ range<T>(iterable: Iterable<T>): Generator<T, void, undefined>;
441
+ /** Current HLC time in ms. */
171
442
  now(): number;
172
- getResolvedOptions(): { durability: string; lmdbOptions: unknown; warnings: string[] };
173
- compact(): Promise<OKDBCompactResult>;
174
- refreshReadTxn(): void;
175
443
  }
@@ -1,4 +1,10 @@
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).
7
+ */
1
8
  export declare class OKDBAdmin {
2
- /** Registers admin UI HTTP routes on the parent OKDB's HTTP server. */
3
- start(): void;
9
+ private constructor();
4
10
  }
@@ -1,18 +1,12 @@
1
- export interface OKDBApiSchemaField {
2
- name: string;
3
- types: string[];
4
- }
5
-
6
- export interface OKDBApiTypeSchema {
7
- type: string;
8
- fields: OKDBApiSchemaField[];
9
- indexes: string[][];
10
- count: number;
11
- }
12
-
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).
9
+ */
13
10
  export declare class OKDBApi {
14
- /** Registers REST API HTTP routes on the parent OKDB's HTTP server. */
15
- start(): void;
16
- /** Sample documents from a type and infer a field schema. */
17
- inferSchema(type: string, limit?: number): Promise<OKDBApiTypeSchema>;
11
+ private constructor();
18
12
  }