@kedem/okdb 2.3.5 → 2.5.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.
- package/CHANGELOG.md +427 -0
- package/algorithm-worker-thread.js +1 -1
- package/bin/okdb.js +1 -1
- package/docs/auth-and-sync.md +30 -5
- package/docs/auth-permissions.md +19 -6
- package/docs/change-log.md +79 -59
- package/docs/data-model.md +20 -18
- package/docs/deployment.md +25 -0
- package/docs/diagnostics.md +59 -17
- package/docs/embeddings.md +57 -6
- package/docs/fts.md +50 -5
- package/docs/functions.md +21 -8
- package/docs/http-api.md +139 -98
- package/docs/http-cluster.md +30 -8
- package/docs/indexes.md +5 -4
- package/docs/licensing.md +6 -1
- package/docs/logging.md +18 -0
- package/docs/migration.md +153 -2
- package/docs/pipelines.md +6 -1
- package/docs/plugins.md +12 -18
- package/docs/process-registry.md +50 -39
- package/docs/processors.md +40 -22
- package/docs/querying.md +50 -36
- package/docs/queue.md +110 -14
- package/docs/subscriptions.md +37 -24
- package/docs/sync.md +96 -37
- package/docs/time-machine.md +23 -17
- package/docs/transactions.md +11 -19
- package/docs/ttl.md +118 -67
- package/docs/upgrade-2.0.md +2 -2
- package/docs/views.md +75 -52
- package/okdb-functions-sandbox-worker.js +1 -1
- package/okdb-http-worker-child.js +1 -1
- package/okdb-views-bootstrap-worker.js +1 -1
- package/okdb.js +1 -1
- package/package.json +1 -1
- package/public/sections/db/parts/type-viewer.ok.js +1 -1
- package/public/sections/embeddings/parts/engines-overview.ok.js +1 -1
- package/public/sections/queue/parts/queue-jobs.ok.js +1 -1
- package/public/sections/system/modals/data-ops-modal.ok.js +1 -1
- package/types/environment.d.ts +320 -52
- package/types/features/admin.d.ts +8 -2
- package/types/features/api.d.ts +10 -16
- package/types/features/auth.d.ts +135 -16
- package/types/features/embeddings.d.ts +639 -31
- package/types/features/engines.d.ts +368 -14
- package/types/features/files.d.ts +0 -3
- package/types/features/fts.d.ts +98 -26
- package/types/features/functions.d.ts +175 -15
- package/types/features/mcp.d.ts +23 -10
- package/types/features/pipelines.d.ts +268 -9
- package/types/features/queue.d.ts +230 -34
- package/types/features/sync.d.ts +177 -14
- package/types/features/time-machine.d.ts +117 -16
- package/types/features/views.d.ts +230 -39
- package/types/index.d.ts +357 -254
- package/types/okdb.d.ts +397 -0
- package/types/options.d.ts +309 -48
- package/public/test-cron-input.html +0 -60
- package/public/test-json-input.html +0 -280
|
@@ -1,23 +1,377 @@
|
|
|
1
|
+
import type { OKDB } from '../okdb';
|
|
2
|
+
import type { OKDBEnvironment } from '../environment';
|
|
3
|
+
|
|
4
|
+
// ─── Status / events ──────────────────────────────────────────────────────────
|
|
5
|
+
|
|
6
|
+
/** Node-local runtime status of an engine instance (not synced). */
|
|
7
|
+
export type OKDBEngineStatus = 'created' | 'online' | 'stopped' | 'inactive' | 'error' | 'removed';
|
|
8
|
+
|
|
9
|
+
/** Statuses a driver may set through `ctx.updateStatus()`. */
|
|
10
|
+
export type OKDBEngineUpdatableStatus = 'online' | 'stopped' | 'inactive' | 'error';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Engine lifecycle events, emitted on `okdb.events` as `engine:<event>` with a
|
|
14
|
+
* payload of `{ engine: key, type, name, ...driverPayload }`.
|
|
15
|
+
* (`'error'` is reserved in the enum; the lifecycle itself does not emit it.)
|
|
16
|
+
*/
|
|
17
|
+
export type OKDBEngineEvent = 'started' | 'stopped' | 'error' | 'installed' | 'uninstalled';
|
|
18
|
+
|
|
19
|
+
// ─── Persisted declaration ────────────────────────────────────────────────────
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The persisted engine declaration — the value of an `~engines` record
|
|
23
|
+
* (key `<type>@<name>`), exposed as `engine.doc`. Synced like other env data;
|
|
24
|
+
* runtime state is NOT part of it.
|
|
25
|
+
*/
|
|
1
26
|
export interface OKDBEngineDefinition {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
27
|
+
/** Driver type (e.g. `'processor'`, `'queue-worker'`, `'indexer'`). */
|
|
28
|
+
type: string;
|
|
29
|
+
/** Driver-specific config (validated by `driver.validate`). */
|
|
30
|
+
config: Record<string, unknown>;
|
|
31
|
+
/** Free-form metadata; drivers checkpoint runtime state here via `ctx.updateMeta`. */
|
|
32
|
+
meta: Record<string, unknown>;
|
|
33
|
+
/** Should this engine run where eligible? `false` keeps it dormant (`inactive`). */
|
|
34
|
+
enabled: boolean;
|
|
35
|
+
/** Mirror of `config.source_env` for admin visibility. */
|
|
36
|
+
source_env: string | null;
|
|
37
|
+
/** Epoch ms the one-time `driver.install` hook completed, or `null`. */
|
|
38
|
+
installedAt: number | null;
|
|
39
|
+
created: number;
|
|
40
|
+
updated: number;
|
|
5
41
|
[key: string]: unknown;
|
|
6
42
|
}
|
|
7
43
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
44
|
+
/** `{ key, value, version }` entry of the persisted declaration. */
|
|
45
|
+
export interface OKDBEngineDocEntry {
|
|
46
|
+
key: string;
|
|
47
|
+
value: OKDBEngineDefinition;
|
|
48
|
+
version: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** `engine.runtimeState` — node-local, JSON-safe snapshot. */
|
|
52
|
+
export interface OKDBEngineRuntimeState {
|
|
53
|
+
state: OKDBEngineStatus;
|
|
54
|
+
/** e.g. `'running'`, `'stopped'`, `'disabled'`, `'start_error'`, `'lease_not_acquired'`. */
|
|
55
|
+
reason: string;
|
|
56
|
+
/** Last error message, or `null`. */
|
|
57
|
+
error: string | null;
|
|
58
|
+
running: boolean;
|
|
59
|
+
/** Epoch ms of the last runtime state change. */
|
|
60
|
+
updated: number;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Options for `createEngine` / `createAndStartEngine`. */
|
|
64
|
+
export interface OKDBEngineCreateOptions {
|
|
65
|
+
/** Persist the declaration disabled (`enabled: false`). Default `true`. */
|
|
66
|
+
enabled?: boolean;
|
|
12
67
|
[key: string]: unknown;
|
|
13
68
|
}
|
|
14
69
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
70
|
+
/** Patch accepted by `engine.patchDeclaration()`. */
|
|
71
|
+
export interface OKDBEngineDeclarationPatch {
|
|
72
|
+
enabled?: boolean;
|
|
73
|
+
/** Shallow-merged into `meta`; `null` clears it to `{}`. */
|
|
74
|
+
meta?: Record<string, unknown> | null;
|
|
75
|
+
/**
|
|
76
|
+
* Config patch, applied through the driver's `patchConfig()` (throws
|
|
77
|
+
* `ENGINE_CONFIG_PATCH_UNSUPPORTED` if the driver has none), then re-validated.
|
|
78
|
+
*/
|
|
79
|
+
config?: Record<string, unknown>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// ─── Engine instance ──────────────────────────────────────────────────────────
|
|
83
|
+
|
|
84
|
+
/** Runtime API returned by a driver's `start()`; its methods are driver-defined. */
|
|
85
|
+
export type OKDBEngineApi = { [method: string]: any };
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* A single engine instance (`<type>@<name>`). Obtained from
|
|
89
|
+
* `engines.getEngine()` / `createEngine()` / `list()` — never constructed directly.
|
|
90
|
+
*/
|
|
91
|
+
export interface OKDBEngine<TApi = OKDBEngineApi> {
|
|
92
|
+
/** `<type>@<name>`. */
|
|
93
|
+
readonly key: string;
|
|
94
|
+
readonly type: string;
|
|
95
|
+
readonly name: string;
|
|
96
|
+
/** Same as `type`. */
|
|
97
|
+
readonly engineType: string;
|
|
98
|
+
/** Runtime API from the driver's `start()`; `null` when not running on this node. */
|
|
99
|
+
readonly api: TApi | null;
|
|
100
|
+
/** Persisted declaration, or `null` before `load()`. */
|
|
101
|
+
readonly doc: OKDBEngineDefinition | null;
|
|
102
|
+
readonly docEntry: OKDBEngineDocEntry | null;
|
|
103
|
+
/** Declaration flag (`doc.enabled !== false`). */
|
|
104
|
+
readonly enabled: boolean;
|
|
105
|
+
/** True if started successfully and running on this node. */
|
|
106
|
+
readonly isRunning: boolean;
|
|
107
|
+
/** Node-local runtime status. */
|
|
108
|
+
readonly status: OKDBEngineStatus;
|
|
109
|
+
/** Node-local runtime reason. */
|
|
110
|
+
readonly reason: string;
|
|
111
|
+
/** Error that put the engine into `error` state, or `null`. */
|
|
112
|
+
readonly lastError: Error | null;
|
|
113
|
+
readonly runtimeState: OKDBEngineRuntimeState;
|
|
114
|
+
/** The registered driver object (set by `load()`). */
|
|
115
|
+
readonly driver: OKDBEngineDriver | null;
|
|
116
|
+
|
|
117
|
+
/** (Re)load the persisted declaration and resolve the driver. Idempotent unless `force`. */
|
|
118
|
+
load(options?: { force?: boolean }): Promise<this>;
|
|
119
|
+
/**
|
|
120
|
+
* Start on this node: runs the one-time `install` hook, then `driver.start()`.
|
|
121
|
+
* Never throws on driver failure — the engine enters `error` state (or stays
|
|
122
|
+
* `inactive` with reason `lease_not_acquired`); recover with `engines.restart()`.
|
|
123
|
+
* A disabled declaration goes `inactive` (reason `disabled`).
|
|
124
|
+
*/
|
|
20
125
|
start(): Promise<void>;
|
|
21
|
-
stop()
|
|
22
|
-
|
|
126
|
+
/** Stop on this node (driver `stop()` hook). Safe on a stopped engine. */
|
|
127
|
+
stop(options?: { reason?: string }): Promise<void>;
|
|
128
|
+
/** Persist a declaration patch (enabled / meta / config) with optimistic concurrency. Does not restart. */
|
|
129
|
+
patchDeclaration(patch?: OKDBEngineDeclarationPatch): Promise<this>;
|
|
130
|
+
/** Stop, run `driver.uninstall()`, and delete the declaration. Prefer `engines.uninstallEngine()`. */
|
|
131
|
+
uninstall(): Promise<void>;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// ─── Drivers ──────────────────────────────────────────────────────────────────
|
|
135
|
+
|
|
136
|
+
/** Self-description shown by `engines.catalog()` / the admin UI. */
|
|
137
|
+
export interface OKDBEngineDriverDocs {
|
|
138
|
+
summary?: string;
|
|
139
|
+
description?: string;
|
|
140
|
+
/** Can run outside a pipeline. Default `true`. */
|
|
141
|
+
standalone?: boolean;
|
|
142
|
+
/** Can be a pipeline member. Default `false`. */
|
|
143
|
+
pipelineCompatible?: boolean;
|
|
144
|
+
/** Default `'env'`. */
|
|
145
|
+
scope?: 'global' | 'env';
|
|
146
|
+
configSchema?: Record<string, unknown>;
|
|
147
|
+
configExample?: Record<string, unknown>;
|
|
148
|
+
patchConfigSchema?: Record<string, unknown>;
|
|
149
|
+
patchableConfigKeys?: string[];
|
|
150
|
+
notes?: string[];
|
|
151
|
+
links?: string[];
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Context passed to every driver lifecycle hook. */
|
|
155
|
+
export interface OKDBEngineDriverContext {
|
|
156
|
+
okdb: OKDB;
|
|
157
|
+
/** `<type>@<name>`. */
|
|
158
|
+
key: string;
|
|
159
|
+
type: string;
|
|
160
|
+
name: string;
|
|
161
|
+
/** The env holding this engine's `~engines` record. */
|
|
162
|
+
storeEnv: OKDBEnvironment;
|
|
163
|
+
storeEnvName: string;
|
|
164
|
+
config: Record<string, unknown>;
|
|
165
|
+
meta: Record<string, unknown>;
|
|
166
|
+
/** Emit `engine:<event>` on `okdb.events` (payload gains `engine`, `type`, `name`). */
|
|
167
|
+
emit(event: string, payload?: Record<string, unknown>): void;
|
|
168
|
+
/** Set this node's runtime status (throws `ENGINE_INVALID_STATUS` otherwise). */
|
|
169
|
+
updateStatus(status: OKDBEngineUpdatableStatus, error?: unknown): Promise<void>;
|
|
170
|
+
/** Merge-patch the persisted `meta` (e.g. checkpoint a resume clock). */
|
|
171
|
+
updateMeta(patch: Record<string, unknown>): Promise<void>;
|
|
172
|
+
/** Merge-patch the persisted `config` (e.g. resolved dims). */
|
|
173
|
+
updateConfig(patch: Record<string, unknown>): Promise<void>;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Context passed to `driver.assertCreateAllowed()`. */
|
|
177
|
+
export interface OKDBEngineCreateContext {
|
|
178
|
+
okdb: OKDB;
|
|
179
|
+
key: string;
|
|
180
|
+
type: string;
|
|
181
|
+
name: string;
|
|
182
|
+
config: Record<string, unknown>;
|
|
183
|
+
meta: Record<string, unknown>;
|
|
184
|
+
storeEnv: OKDBEnvironment;
|
|
185
|
+
storeEnvName: string | null;
|
|
186
|
+
options: OKDBEngineCreateOptions;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Context passed to `driver.patchConfig()`. */
|
|
190
|
+
export interface OKDBEngineConfigPatchContext {
|
|
191
|
+
okdb: OKDB;
|
|
192
|
+
key: string;
|
|
193
|
+
type: string;
|
|
194
|
+
name: string;
|
|
195
|
+
storeEnv: OKDBEnvironment;
|
|
196
|
+
storeEnvName: string | null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** A driver registered with `engines.registerDriver(type, driver)`. Only `start` is required. */
|
|
200
|
+
export interface OKDBEngineDriver<TApi = OKDBEngineApi> {
|
|
201
|
+
docs?: OKDBEngineDriverDocs;
|
|
202
|
+
/** Throw to reject an invalid config (runs on load and after config patches). */
|
|
203
|
+
validate?(config: Record<string, unknown>): void;
|
|
204
|
+
/** Throw to refuse creation. */
|
|
205
|
+
assertCreateAllowed?(ctx: OKDBEngineCreateContext): void | Promise<void>;
|
|
206
|
+
/** Throw to refuse a start (an error with code `ENGINE_LEASE_NOT_ACQUIRED` → stays `inactive`, not `error`). */
|
|
207
|
+
assertStartAllowed?(ctx: OKDBEngineDriverContext): void | Promise<void>;
|
|
208
|
+
/** One-time setup, before the first successful start. */
|
|
209
|
+
install?(ctx: OKDBEngineDriverContext): void | Promise<void>;
|
|
210
|
+
/** Required. Returns the runtime API exposed as `engine.api`. */
|
|
211
|
+
start(ctx: OKDBEngineDriverContext): TApi | Promise<TApi>;
|
|
212
|
+
stop?(ctx: OKDBEngineDriverContext): void | Promise<void>;
|
|
213
|
+
uninstall?(ctx: OKDBEngineDriverContext): void | Promise<void>;
|
|
214
|
+
/** Enables `patchDeclaration({ config })`; returns the full next config. */
|
|
215
|
+
patchConfig?(
|
|
216
|
+
current: Record<string, unknown>,
|
|
217
|
+
patch: Record<string, unknown>,
|
|
218
|
+
ctx: OKDBEngineConfigPatchContext,
|
|
219
|
+
): Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** One row of `engines.catalog()` — a registered driver type and its docs. */
|
|
223
|
+
export interface OKDBEngineCatalogEntry {
|
|
224
|
+
type: string;
|
|
225
|
+
summary: string | null;
|
|
226
|
+
description: string | null;
|
|
227
|
+
standalone: boolean;
|
|
228
|
+
pipelineCompatible: boolean;
|
|
229
|
+
scope: 'global' | 'env';
|
|
230
|
+
configSchema: Record<string, unknown> | null;
|
|
231
|
+
configExample: Record<string, unknown> | null;
|
|
232
|
+
patchConfigSchema: Record<string, unknown> | null;
|
|
233
|
+
patchableConfigKeys: string[];
|
|
234
|
+
/** Engine-kind template ids targeting this type. */
|
|
235
|
+
templateIds: string[];
|
|
236
|
+
recommendedTemplateIds: string[];
|
|
237
|
+
notes: string[];
|
|
238
|
+
links: string[];
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// ─── Templates ────────────────────────────────────────────────────────────────
|
|
242
|
+
|
|
243
|
+
/** Plan produced by a template's `build()` — `kind: 'engine'` or `'pipeline'`; rest is template-specific. */
|
|
244
|
+
export interface OKDBEngineTemplatePlan {
|
|
245
|
+
kind: 'engine' | 'pipeline';
|
|
246
|
+
[key: string]: unknown;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** A starter template registered with `engines.registerTemplate()`. */
|
|
250
|
+
export interface OKDBEngineTemplateDefinition {
|
|
251
|
+
id: string;
|
|
252
|
+
kind: 'engine' | 'pipeline';
|
|
253
|
+
/** Expand user input into a concrete plan. Throw on invalid input. */
|
|
254
|
+
build(input: Record<string, unknown>, context: { okdb: OKDB; envName: string | null }): OKDBEngineTemplatePlan;
|
|
255
|
+
family?: string;
|
|
256
|
+
engineType?: string;
|
|
257
|
+
pipelineFamily?: string;
|
|
258
|
+
recommended?: boolean;
|
|
259
|
+
summary?: string;
|
|
260
|
+
description?: string;
|
|
261
|
+
/** JSON schema of `build()` input, or a function computing it. */
|
|
262
|
+
inputSchema?: Record<string, unknown> | ((okdb: OKDB) => Record<string, unknown>);
|
|
263
|
+
defaults?: Record<string, unknown>;
|
|
264
|
+
notes?: string[];
|
|
265
|
+
links?: string[];
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** A template as returned by `listTemplates()` / `getTemplate()`. */
|
|
269
|
+
export interface OKDBEngineTemplate {
|
|
270
|
+
id: string;
|
|
271
|
+
kind: 'engine' | 'pipeline';
|
|
272
|
+
family: string | null;
|
|
273
|
+
engineType: string | null;
|
|
274
|
+
pipelineFamily: string | null;
|
|
275
|
+
recommended: boolean;
|
|
276
|
+
summary: string | null;
|
|
277
|
+
description: string | null;
|
|
278
|
+
inputSchema: Record<string, unknown>;
|
|
279
|
+
defaults: Record<string, unknown>;
|
|
280
|
+
notes: string[];
|
|
281
|
+
links: string[];
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export interface OKDBEngineTemplatePreview {
|
|
285
|
+
template: OKDBEngineTemplate;
|
|
286
|
+
plan: OKDBEngineTemplatePlan;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// ─── OKDBEngines ──────────────────────────────────────────────────────────────
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Engine manager: named, typed, driver-backed persistent services. Declarations
|
|
293
|
+
* live in `~engines` records and are restored/started on `open()` on nodes with
|
|
294
|
+
* the `engines` role; runtime state is node-local.
|
|
295
|
+
*
|
|
296
|
+
* Attached twice, one class:
|
|
297
|
+
* - `db.engines` — the process-wide orchestrator. Sees every engine;
|
|
298
|
+
* `createEngine()` here stores the declaration in `~system` (a shared/global engine).
|
|
299
|
+
* - `env.engines` — env facade over the same driver/template/instance registry.
|
|
300
|
+
* `createEngine()` stores in that env; `getEngine()` / `list()` only see engines
|
|
301
|
+
* stored in that env (`getEngine` returns `null` for others).
|
|
302
|
+
*
|
|
303
|
+
* `registerDriver`/`registerTemplate` always register on the orchestrator.
|
|
304
|
+
* Pipeline members: the HTTP/admin surfaces refuse delete/stop/start/restart of a
|
|
305
|
+
* member with `ENGINE_MANAGED_BY_PIPELINE`; the SDK methods here do not check —
|
|
306
|
+
* operate on the owning pipeline (`db.pipelines.findOwner(type, name)`).
|
|
307
|
+
*
|
|
308
|
+
* Removed: the per-engine `affinity` field (replaced by the engine-level lease; stripped from records on boot).
|
|
309
|
+
*/
|
|
310
|
+
export declare class OKDBEngines {
|
|
311
|
+
/** True for `db.engines`, false for an `env.engines` facade. */
|
|
312
|
+
readonly isOrchestrator: boolean;
|
|
313
|
+
|
|
314
|
+
// ── Drivers & templates ───────────────────────────────────────────────────
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Register a driver for an engine type. Call before `open()` so persisted
|
|
318
|
+
* engines of this type can be restored. Throws `ENGINE_DRIVER_ALREADY_REGISTERED`
|
|
319
|
+
* on a duplicate type, `ENGINE_DRIVER_MISSING_START` without `start()`.
|
|
320
|
+
* Built-in types include `processor`, `materializer`, `queue-worker` and the
|
|
321
|
+
* embeddings family (`embedder`, `indexer`, `vector-search`, `embed-worker`).
|
|
322
|
+
*/
|
|
323
|
+
registerDriver(type: string, driver: OKDBEngineDriver): void;
|
|
324
|
+
/** Register a starter template. Throws `ENGINE_TEMPLATE_ALREADY_REGISTERED` on a duplicate id. */
|
|
325
|
+
registerTemplate(template: OKDBEngineTemplateDefinition): void;
|
|
326
|
+
/** Registered templates sorted by id, optionally filtered by kind. */
|
|
327
|
+
listTemplates(kind?: 'engine' | 'pipeline' | null): OKDBEngineTemplate[];
|
|
328
|
+
getTemplate(id: string): OKDBEngineTemplate | null;
|
|
329
|
+
/**
|
|
330
|
+
* Expand a template into its plan without persisting anything.
|
|
331
|
+
* Throws `ENGINE_TEMPLATE_NOT_FOUND`.
|
|
332
|
+
*/
|
|
333
|
+
previewTemplate(
|
|
334
|
+
id: string,
|
|
335
|
+
input?: Record<string, unknown>,
|
|
336
|
+
context?: { envName?: string | null },
|
|
337
|
+
): OKDBEngineTemplatePreview;
|
|
338
|
+
/** Every registered driver type with its self-declared docs, sorted by type. */
|
|
339
|
+
catalog(): OKDBEngineCatalogEntry[];
|
|
340
|
+
|
|
341
|
+
// ── Engines ───────────────────────────────────────────────────────────────
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Persist a new engine declaration and return the (loaded, not started) instance.
|
|
345
|
+
* Throws `ENGINE_UNKNOWN_TYPE`, `ENGINE_ALREADY_EXISTS`, or a license error
|
|
346
|
+
* (`LICENSE_FEATURE_DISABLED` / `LICENSE_LIMIT_EXCEEDED`).
|
|
347
|
+
*/
|
|
348
|
+
createEngine<TApi = OKDBEngineApi>(
|
|
349
|
+
type: string,
|
|
350
|
+
name: string,
|
|
351
|
+
config: Record<string, unknown>,
|
|
352
|
+
meta?: Record<string, unknown>,
|
|
353
|
+
options?: OKDBEngineCreateOptions,
|
|
354
|
+
): Promise<OKDBEngine<TApi>>;
|
|
355
|
+
/** `createEngine()` + `engine.start()`. A failed start leaves the engine in `error` state rather than throwing. */
|
|
356
|
+
createAndStartEngine<TApi = OKDBEngineApi>(
|
|
357
|
+
type: string,
|
|
358
|
+
name: string,
|
|
359
|
+
config: Record<string, unknown>,
|
|
360
|
+
meta?: Record<string, unknown>,
|
|
361
|
+
options?: OKDBEngineCreateOptions,
|
|
362
|
+
): Promise<OKDBEngine<TApi>>;
|
|
363
|
+
/**
|
|
364
|
+
* Engine by type + name (any runtime state), or `null`. Throws
|
|
365
|
+
* `ENGINE_SYSTEM_NOT_STARTED` if the engine subsystem never started on this
|
|
366
|
+
* node (before `open()`, or an `engines: false` node).
|
|
367
|
+
*/
|
|
368
|
+
getEngine<TApi = OKDBEngineApi>(type: string, name: string): OKDBEngine<TApi> | null;
|
|
369
|
+
/** Like `getEngine()` but `null` unless running on this node; never throws `ENGINE_SYSTEM_NOT_STARTED`. */
|
|
370
|
+
getRunningEngine<TApi = OKDBEngineApi>(type: string, name: string): OKDBEngine<TApi> | null;
|
|
371
|
+
/** Known engine instances on this node, optionally filtered by type (env facade: that env's only). */
|
|
372
|
+
list(type?: string | null): OKDBEngine[];
|
|
373
|
+
/** Stop (if running), reload the declaration, start again. Throws `ENGINE_NOT_FOUND`. */
|
|
374
|
+
restart<TApi = OKDBEngineApi>(type: string, name: string): Promise<OKDBEngine<TApi>>;
|
|
375
|
+
/** Stop, run the driver's uninstall hook and delete the declaration. Throws `ENGINE_NOT_FOUND`. */
|
|
376
|
+
uninstallEngine(type: string, name: string): Promise<void>;
|
|
23
377
|
}
|
package/types/features/fts.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
import type { OKDBEnvironment } from '../environment';
|
|
2
|
+
|
|
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.
|
|
6
|
+
*/
|
|
7
|
+
export type OKDBFtsEnvArg = OKDBEnvironment;
|
|
8
|
+
|
|
9
|
+
/** Tokenizer settings. Defaults: min 2, max 64 (longer tokens truncated), keepNumbers true, toLower true. */
|
|
1
10
|
export interface OKDBFtsTokenizerOptions {
|
|
2
11
|
minTokenLength?: number;
|
|
3
12
|
maxTokenLength?: number;
|
|
@@ -7,13 +16,17 @@ export interface OKDBFtsTokenizerOptions {
|
|
|
7
16
|
}
|
|
8
17
|
|
|
9
18
|
export interface OKDBFtsConfig {
|
|
19
|
+
/** Non-empty list of field paths to index. */
|
|
10
20
|
fields: string[];
|
|
11
21
|
tokenizer?: OKDBFtsTokenizerOptions;
|
|
12
22
|
}
|
|
13
23
|
|
|
24
|
+
/** Persisted status of one FTS index. */
|
|
25
|
+
export type OKDBFtsIndexStatus = 'creating' | 'resetting' | 'ready' | 'waiting' | 'dropping' | 'error';
|
|
26
|
+
|
|
14
27
|
export interface OKDBFtsListEntry {
|
|
15
28
|
name: string;
|
|
16
|
-
status:
|
|
29
|
+
status: OKDBFtsIndexStatus | null;
|
|
17
30
|
config: OKDBFtsConfig | null;
|
|
18
31
|
created: number | null;
|
|
19
32
|
updated: number | null;
|
|
@@ -28,69 +41,128 @@ export interface OKDBFtsListEntry {
|
|
|
28
41
|
* on every entry of the same type. 0 = caught up.
|
|
29
42
|
*/
|
|
30
43
|
lag: number | null;
|
|
44
|
+
/** Approximate bytes stored for this index (excludes env-level shared dictionaries). */
|
|
45
|
+
sizeBytes: number;
|
|
31
46
|
}
|
|
32
47
|
|
|
48
|
+
/** An FTS index as reported by fts.list(). Alias of {@link OKDBFtsListEntry}. */
|
|
49
|
+
export type OKDBFtsIndex = OKDBFtsListEntry;
|
|
50
|
+
|
|
33
51
|
export interface OKDBFtsSearchOptions {
|
|
52
|
+
/** Max results (integer >= 1). Default 50. */
|
|
34
53
|
limit?: number;
|
|
54
|
+
/** 'and' (default): every query token must match; 'or': any token, ranked by score. */
|
|
35
55
|
mode?: 'and' | 'or';
|
|
56
|
+
/** Match query tokens as prefixes (an exact word scores above a prefix-only completion). */
|
|
36
57
|
prefix?: boolean;
|
|
37
58
|
}
|
|
38
59
|
|
|
60
|
+
/** One hydrated hit from fts.searchDocs(). */
|
|
39
61
|
export interface OKDBFtsSearchResult {
|
|
40
62
|
key: string;
|
|
63
|
+
/** The document, or null if it vanished between search and hydration. */
|
|
41
64
|
value: unknown;
|
|
42
65
|
version: number | null;
|
|
66
|
+
/** BM25 relevance score (higher = more relevant). */
|
|
43
67
|
score: number | null;
|
|
68
|
+
/** Number of unique query tokens. */
|
|
44
69
|
numTerms: number;
|
|
70
|
+
/** The query's BM25 upper bound (Σ idf·(k1+1)); score / maxScore ∈ (0, 1). */
|
|
45
71
|
maxScore: number;
|
|
46
72
|
}
|
|
47
73
|
|
|
74
|
+
/** A searchDocs() hit. Alias of {@link OKDBFtsSearchResult}. */
|
|
75
|
+
export type OKDBFtsQueryResult = OKDBFtsSearchResult;
|
|
76
|
+
|
|
77
|
+
/** Return of fts.envSize(). */
|
|
78
|
+
export interface OKDBFtsEnvSize {
|
|
79
|
+
/** ~fts/<env>/ + ~fts/<env>_docs/ data.mdb file sizes. */
|
|
80
|
+
diskBytes: number;
|
|
81
|
+
/** Stored bytes (index payloads + shared dictionaries). */
|
|
82
|
+
payloadBytes: number;
|
|
83
|
+
indexPayloadBytes: number;
|
|
84
|
+
sharedDictBytes: number;
|
|
85
|
+
/** LMDB free pages (reclaimable). */
|
|
86
|
+
slackBytes: number;
|
|
87
|
+
indexes: Array<{ type: string; name: string; sizeBytes: number }>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Return of fts.compactStorage(). */
|
|
91
|
+
export interface OKDBFtsCompactResult {
|
|
92
|
+
ok: true;
|
|
93
|
+
sizeBefore: number;
|
|
94
|
+
sizeAfter: number;
|
|
95
|
+
saved: number;
|
|
96
|
+
savedPct: number;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Full-text search (`db.fts`). Every method takes an optional trailing `env` — an environment
|
|
101
|
+
* OBJECT (e.g. `db.env('name')`), not a name string; omitted = the 'default' env.
|
|
102
|
+
*/
|
|
48
103
|
export declare class OKDBFts {
|
|
49
|
-
/**
|
|
50
|
-
|
|
104
|
+
/**
|
|
105
|
+
* Register a new FTS index on a type. The build runs in the background; await ready(type).
|
|
106
|
+
* Throws ALREADY_EXISTS, INVALID_FTS, or a type-not-registered error.
|
|
107
|
+
*/
|
|
108
|
+
register(type: string, name: string, config: OKDBFtsConfig, timestamp?: number, env?: OKDBFtsEnvArg): Promise<void>;
|
|
51
109
|
|
|
52
|
-
/** Idempotent register — no-op if index already exists. */
|
|
53
|
-
ensure(type: string, name: string, config: OKDBFtsConfig, env?:
|
|
110
|
+
/** Idempotent register — no-op if an index with this name already exists (config is not compared). */
|
|
111
|
+
ensure(type: string, name: string, config: OKDBFtsConfig, env?: OKDBFtsEnvArg): Promise<void>;
|
|
54
112
|
|
|
55
|
-
/** Drop
|
|
56
|
-
drop(type: string, name: string, env?:
|
|
113
|
+
/** Drop an FTS index. No-op if it does not exist. Storage is reclaimed in the background. */
|
|
114
|
+
drop(type: string, name: string, env?: OKDBFtsEnvArg): Promise<void>;
|
|
57
115
|
|
|
58
|
-
/**
|
|
59
|
-
reset(type: string, name: string, clear?: boolean, env?:
|
|
116
|
+
/** Rebuild an FTS index in the background (`clear` defaults to true). Throws NOT_FOUND. */
|
|
117
|
+
reset(type: string, name: string, clear?: boolean, env?: OKDBFtsEnvArg): Promise<void>;
|
|
60
118
|
|
|
61
119
|
/** Returns true if the FTS index exists. */
|
|
62
|
-
has(type: string, name: string, env?:
|
|
120
|
+
has(type: string, name: string, env?: OKDBFtsEnvArg): boolean;
|
|
63
121
|
|
|
64
122
|
/** Returns the index status, or null if not registered. */
|
|
65
|
-
status(type: string, name: string, env?:
|
|
123
|
+
status(type: string, name: string, env?: OKDBFtsEnvArg): OKDBFtsIndexStatus | null;
|
|
66
124
|
|
|
67
125
|
/** List all FTS indexes for a type. */
|
|
68
|
-
list(type: string, env?:
|
|
126
|
+
list(type: string, env?: OKDBFtsEnvArg): OKDBFtsListEntry[];
|
|
69
127
|
|
|
70
128
|
/**
|
|
71
|
-
* Resolves when all FTS indexes
|
|
72
|
-
*
|
|
129
|
+
* Resolves true when all FTS indexes on the type finish their build. Rejects with
|
|
130
|
+
* FTS_BUILD_FAILED if a build failed (reset() retries). `name` is accepted but ignored.
|
|
73
131
|
*/
|
|
74
|
-
ready(type: string, name?: string, env?:
|
|
132
|
+
ready(type: string, name?: string, env?: OKDBFtsEnvArg): Promise<boolean>;
|
|
75
133
|
|
|
76
134
|
/**
|
|
77
|
-
* Waits for the FTS processor to
|
|
78
|
-
*
|
|
135
|
+
* Waits for the type's FTS processor to reach the current write position (or error), then
|
|
136
|
+
* compacts the live tier into the frozen tier. Use when a write must be searchable immediately.
|
|
79
137
|
*/
|
|
80
|
-
flush(type: string, env?:
|
|
138
|
+
flush(type: string, env?: OKDBFtsEnvArg): Promise<void>;
|
|
139
|
+
|
|
140
|
+
/** Roll every live-tier posting of the type's indexes into the frozen tier (flush() does this). */
|
|
141
|
+
compact(type: string, env?: OKDBFtsEnvArg): Promise<void>;
|
|
142
|
+
|
|
143
|
+
/** Env-level FTS storage summary. */
|
|
144
|
+
envSize(env?: OKDBFtsEnvArg): OKDBFtsEnvSize;
|
|
81
145
|
|
|
82
|
-
/**
|
|
83
|
-
|
|
146
|
+
/** Rewrite the env's ~fts store files to reclaim LMDB slack (env.compact() calls this). */
|
|
147
|
+
compactStorage(env?: OKDBFtsEnvArg): Promise<OKDBFtsCompactResult>;
|
|
148
|
+
|
|
149
|
+
/** Search an index. Returns matching document keys (at most `limit`, default 50). Throws NOT_FOUND. */
|
|
150
|
+
search(type: string, name: string, query: string, options?: OKDBFtsSearchOptions, env?: OKDBFtsEnvArg): string[];
|
|
84
151
|
|
|
85
152
|
/** Search and return hydrated documents with scores. */
|
|
86
153
|
searchDocs(
|
|
87
154
|
type: string,
|
|
88
155
|
name: string,
|
|
89
156
|
query: string,
|
|
90
|
-
options?: OKDBFtsSearchOptions & { keysOnly?:
|
|
91
|
-
env?:
|
|
92
|
-
): OKDBFtsSearchResult[]
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
157
|
+
options?: OKDBFtsSearchOptions & { keysOnly?: false },
|
|
158
|
+
env?: OKDBFtsEnvArg,
|
|
159
|
+
): OKDBFtsSearchResult[];
|
|
160
|
+
/** `keysOnly: true` behaves exactly like search(). */
|
|
161
|
+
searchDocs(
|
|
162
|
+
type: string,
|
|
163
|
+
name: string,
|
|
164
|
+
query: string,
|
|
165
|
+
options: OKDBFtsSearchOptions & { keysOnly: true },
|
|
166
|
+
env?: OKDBFtsEnvArg,
|
|
167
|
+
): string[];
|
|
96
168
|
}
|