@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.
- package/CHANGELOG.md +114 -3
- package/README.md +72 -36
- package/bin/okdb +1 -1
- package/docs/auth-and-sync.md +30 -24
- package/docs/auth-permissions.md +5 -4
- package/docs/c-bridge.md +94 -0
- package/docs/change-log.md +79 -36
- package/docs/data-model.md +35 -9
- package/docs/deployment.md +42 -38
- package/docs/diagnostics.md +61 -125
- package/docs/embeddings.md +143 -51
- package/docs/encryption.md +132 -0
- package/docs/files.md +64 -27
- package/docs/fts.md +48 -23
- package/docs/functions.md +109 -56
- package/docs/getting-started.md +121 -9
- package/docs/http-api.md +66 -11
- package/docs/http-cluster.md +80 -88
- package/docs/index.md +33 -15
- package/docs/indexes.md +53 -17
- package/docs/licensing.md +19 -5
- package/docs/logging.md +11 -22
- package/docs/manifest.json +6 -3
- package/docs/migration.md +41 -16
- package/docs/pipelines.md +111 -46
- package/docs/plugins.md +47 -15
- package/docs/process-registry.md +23 -24
- package/docs/processors.md +26 -23
- package/docs/querying.md +102 -29
- package/docs/queue.md +165 -51
- package/docs/resolved-fields.md +24 -1
- package/docs/subscriptions.md +4 -4
- package/docs/sync.md +9 -6
- package/docs/time-machine.md +52 -14
- package/docs/transactions.md +63 -15
- package/docs/ttl.md +34 -13
- package/docs/upgrade-2.0.md +32 -15
- package/docs/upgrade-2.1.md +10 -12
- package/docs/upgrade-3.0.md +144 -0
- package/docs/views.md +165 -61
- package/index.js +1 -1
- package/native/linux-x64-gnu/okdb +0 -0
- package/native/linux-x64-gnu/okdb-node.linux-x64-gnu.node +0 -0
- package/native-loader.js +1 -1
- package/okdb-native.js +1 -1
- package/package.json +1 -1
- package/public/features/files/parts/files-blob-status.ok.js +1 -1
- package/types/environment.d.ts +32 -11
- package/types/errors.d.ts +20 -0
- package/types/features/admin.d.ts +3 -5
- package/types/features/api.d.ts +5 -7
- package/types/features/embeddings.d.ts +8 -7
- package/types/features/engines.d.ts +9 -1
- package/types/features/files.d.ts +2 -1
- package/types/features/fts.d.ts +3 -3
- package/types/features/functions.d.ts +14 -8
- package/types/features/pipelines.d.ts +10 -10
- package/types/features/queue.d.ts +15 -10
- package/types/features/sync.d.ts +7 -0
- package/types/features/time-machine.d.ts +3 -0
- package/types/index.d.ts +3 -0
- package/types/okdb.d.ts +70 -7
- package/types/options.d.ts +12 -8
- package/docs/OKDB-ARCHITECTURE.md +0 -1061
package/docs/pipelines.md
CHANGED
|
@@ -1,17 +1,61 @@
|
|
|
1
1
|
# Pipelines
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
This is the generic layer above `engines`.
|
|
3
|
+
A **pipeline** is a named, ordered group of [engines](#current-sdk-surface) stored in an
|
|
4
|
+
environment's `~pipelines` registry. It is the generic layer above `engines`.
|
|
6
5
|
|
|
7
6
|
- engines remain standalone runtime units
|
|
8
7
|
- pipelines group engines structurally
|
|
9
8
|
- pipeline records live in the environment that defines them
|
|
10
9
|
- pipeline records sync like other env data
|
|
11
10
|
|
|
11
|
+
> **Licensing.** Generic engines (`queue-worker`, `processor`, `materializer`) are a licensed
|
|
12
|
+
> feature, off on the free tier, so generic pipelines need a license that includes `engines`.
|
|
13
|
+
> **Embeddings pipelines** (created by `okdb.embeddings.createPipeline(...)`, see
|
|
14
|
+
> [Embeddings](./embeddings.md)) are free; the free tier allows up to 2 per environment
|
|
15
|
+
> (`pipelinesPerEnv`). See [Licensing](./licensing.md).
|
|
16
|
+
|
|
17
|
+
Every embeddings pipeline is also a pipeline record, so the registry API works on the free tier:
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
// a tiny deterministic embedder, so the example runs offline
|
|
21
|
+
okdb.embeddings.registerEmbedderFactory('toy', (config) => ({
|
|
22
|
+
async embed(text) {
|
|
23
|
+
const v = new Float32Array(config.dims);
|
|
24
|
+
for (const ch of String(text)) v[ch.charCodeAt(0) % config.dims] += 1;
|
|
25
|
+
return v;
|
|
26
|
+
},
|
|
27
|
+
async health() {
|
|
28
|
+
return { ok: true };
|
|
29
|
+
},
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
await okdb.registerType('articles');
|
|
33
|
+
await okdb.embeddings.createPipeline('articles', {
|
|
34
|
+
source_type: 'articles',
|
|
35
|
+
field: 'body',
|
|
36
|
+
dims: 16,
|
|
37
|
+
embedder: { type: 'toy', dims: 16 },
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const pipelines = okdb.env('default').pipelines;
|
|
41
|
+
const info = await pipelines.get('articles');
|
|
42
|
+
console.log(
|
|
43
|
+
info.health,
|
|
44
|
+
info.engines.map((m) => m.role),
|
|
45
|
+
); // 'online' [ 'embedder', 'indexer', 'search' ]
|
|
46
|
+
|
|
47
|
+
await pipelines.stop('articles'); // status 'stopped'
|
|
48
|
+
await pipelines.start('articles'); // status 'active'
|
|
49
|
+
await pipelines.update('articles', { meta: { label: 'Articles' } });
|
|
50
|
+
console.log((await okdb.pipelines.list()).map((p) => `${p.env}/${p.name}`)); // [ 'default/articles' ]
|
|
51
|
+
await pipelines.remove('articles'); // also removes its env-owned engines
|
|
52
|
+
```
|
|
53
|
+
|
|
12
54
|
---
|
|
13
55
|
|
|
14
|
-
##
|
|
56
|
+
## Record shape
|
|
57
|
+
|
|
58
|
+
<!-- not-runnable: shape fragment -->
|
|
15
59
|
|
|
16
60
|
```javascript
|
|
17
61
|
{
|
|
@@ -29,7 +73,7 @@ This is the generic layer above `engines`.
|
|
|
29
73
|
}
|
|
30
74
|
```
|
|
31
75
|
|
|
32
|
-
Rules
|
|
76
|
+
Rules:
|
|
33
77
|
|
|
34
78
|
- `name` is required and must be a non-empty string
|
|
35
79
|
- `template` must be `null`
|
|
@@ -58,19 +102,30 @@ Unlike env-scoped engines, pipelines do **not** use `~system` by default.
|
|
|
58
102
|
|
|
59
103
|
### Env-local facade
|
|
60
104
|
|
|
105
|
+
<!-- licensed: engines -->
|
|
106
|
+
|
|
61
107
|
```javascript
|
|
62
|
-
const analytics = okdb.
|
|
108
|
+
const analytics = await okdb.createEnvironment('analytics');
|
|
109
|
+
|
|
110
|
+
// Engines must already exist before a pipeline record can be created.
|
|
111
|
+
await analytics.functions.create({ name: 'ingestArticle', source: 'async (ctx) => ({ ok: true })' });
|
|
112
|
+
const handler = { kind: 'function', name: 'ingestArticle' };
|
|
113
|
+
await analytics.engines.createAndStartEngine('queue-worker', 'articles-worker', {
|
|
114
|
+
job_type: 'article-ingest',
|
|
115
|
+
handler,
|
|
116
|
+
});
|
|
117
|
+
// the replaceMember() target below (one consumer per job type, so it reads another one)
|
|
118
|
+
await analytics.engines.createAndStartEngine('queue-worker', 'other-worker', {
|
|
119
|
+
job_type: 'article-ingest-v2',
|
|
120
|
+
handler,
|
|
121
|
+
});
|
|
63
122
|
|
|
64
|
-
// Engines must already exist before a V1 pipeline record can be created.
|
|
65
123
|
await analytics.pipelines.create({
|
|
66
124
|
name: 'articles-ingest',
|
|
67
125
|
template: null,
|
|
68
126
|
status: 'active',
|
|
69
127
|
meta: {},
|
|
70
|
-
engines: [
|
|
71
|
-
{ type: 'embedder', name: 'shared-embedder', role: 'embedder' },
|
|
72
|
-
{ type: 'indexer', name: 'analytics:articles-ingest', role: 'indexer' },
|
|
73
|
-
],
|
|
128
|
+
engines: [{ type: 'queue-worker', name: 'articles-worker', role: 'worker' }],
|
|
74
129
|
});
|
|
75
130
|
|
|
76
131
|
const record = await analytics.pipelines.get('articles-ingest');
|
|
@@ -81,7 +136,7 @@ await analytics.pipelines.start('articles-ingest');
|
|
|
81
136
|
await analytics.pipelines.restart('articles-ingest'); // stop + start
|
|
82
137
|
await analytics.pipelines.update('articles-ingest', { meta: { label: 'Ingest' } }); // meta/status only
|
|
83
138
|
await analytics.pipelines.rebuild('articles-ingest'); // member engines with api.rebuild(), in order
|
|
84
|
-
await analytics.pipelines.replaceMember('articles-ingest', '
|
|
139
|
+
await analytics.pipelines.replaceMember('articles-ingest', 'worker', 'other-worker'); // same-role swap
|
|
85
140
|
await analytics.pipelines.remove('articles-ingest');
|
|
86
141
|
```
|
|
87
142
|
|
|
@@ -153,7 +208,7 @@ In practice that means an MCP client can:
|
|
|
153
208
|
- call `template_preview` to inspect the concrete scaffold or embeddings-create plan
|
|
154
209
|
- call `template_create` to execute that plan in a target environment
|
|
155
210
|
|
|
156
|
-
Direct engine discovery/creation
|
|
211
|
+
Direct engine discovery/creation lives in the dedicated `okdb_engine` tool instead:
|
|
157
212
|
|
|
158
213
|
- `action: "types"` lists registered engine kinds and their self-declared config metadata
|
|
159
214
|
- `action: "create"` creates a direct env-scoped engine without a pipeline record
|
|
@@ -161,9 +216,7 @@ Direct engine discovery/creation now lives in the dedicated `okdb_engine` tool i
|
|
|
161
216
|
|
|
162
217
|
### Generic `queue-worker` engine
|
|
163
218
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
In V1 it is:
|
|
219
|
+
A generic `queue-worker` engine type that can run standalone or participate as a reusable pipeline member. It is:
|
|
167
220
|
|
|
168
221
|
- standalone-capable
|
|
169
222
|
- pipeline-compatible
|
|
@@ -172,8 +225,10 @@ In V1 it is:
|
|
|
172
225
|
|
|
173
226
|
Typical flow:
|
|
174
227
|
|
|
228
|
+
<!-- licensed: engines -->
|
|
229
|
+
|
|
175
230
|
```javascript
|
|
176
|
-
const analytics = okdb.
|
|
231
|
+
const analytics = await okdb.createEnvironment('analytics');
|
|
177
232
|
|
|
178
233
|
await analytics.functions.create({
|
|
179
234
|
name: 'processArticleJob',
|
|
@@ -191,18 +246,12 @@ await analytics.engines.createAndStartEngine('queue-worker', 'articles-worker',
|
|
|
191
246
|
concurrency: 2,
|
|
192
247
|
});
|
|
193
248
|
|
|
194
|
-
await analytics.pipelines.create({
|
|
195
|
-
name: 'articles-ingest',
|
|
196
|
-
template: null,
|
|
197
|
-
status: 'active',
|
|
198
|
-
meta: { label: 'Articles ingest' },
|
|
199
|
-
engines: [{ type: 'queue-worker', name: 'articles-worker', role: 'worker' }],
|
|
200
|
-
});
|
|
201
|
-
|
|
202
249
|
await analytics.queue.enqueue('article-ingest', { id: 'job-1' });
|
|
203
250
|
```
|
|
204
251
|
|
|
205
|
-
`queue-worker` config shape
|
|
252
|
+
`queue-worker` config shape:
|
|
253
|
+
|
|
254
|
+
<!-- not-runnable: shape fragment -->
|
|
206
255
|
|
|
207
256
|
```javascript
|
|
208
257
|
{
|
|
@@ -228,7 +277,7 @@ Config notes:
|
|
|
228
277
|
- `handler.env` — optional env name for the function registry; defaults to the engine owning env
|
|
229
278
|
- `concurrency`, `pollInterval`, `ttl` — forwarded to the underlying queue worker runtime
|
|
230
279
|
|
|
231
|
-
Each claimed payload's function runs in the executing
|
|
280
|
+
Each claimed payload's function runs in the executing process's function sandbox (see [Functions](./functions.md#runtime-model)); `concurrency` bounds in-flight invocations — there is no pool to configure.
|
|
232
281
|
|
|
233
282
|
Behavior:
|
|
234
283
|
|
|
@@ -247,6 +296,8 @@ Runtime stats exposed through `engine.api.stats()` include:
|
|
|
247
296
|
|
|
248
297
|
Minimal pipeline membership example:
|
|
249
298
|
|
|
299
|
+
<!-- continues -->
|
|
300
|
+
|
|
250
301
|
```javascript
|
|
251
302
|
await analytics.pipelines.create({
|
|
252
303
|
name: 'articles-ingest',
|
|
@@ -259,9 +310,7 @@ await analytics.pipelines.create({
|
|
|
259
310
|
|
|
260
311
|
### Generic `processor` engine
|
|
261
312
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
In V1 it is:
|
|
313
|
+
A generic `processor` engine type for change-log driven pipeline members. It is:
|
|
265
314
|
|
|
266
315
|
- standalone-capable
|
|
267
316
|
- pipeline-compatible
|
|
@@ -271,8 +320,10 @@ In V1 it is:
|
|
|
271
320
|
|
|
272
321
|
Typical flow:
|
|
273
322
|
|
|
323
|
+
<!-- licensed: engines -->
|
|
324
|
+
|
|
274
325
|
```javascript
|
|
275
|
-
const analytics = okdb.
|
|
326
|
+
const analytics = await okdb.createEnvironment('analytics');
|
|
276
327
|
|
|
277
328
|
await analytics.registerType('articles');
|
|
278
329
|
|
|
@@ -302,7 +353,9 @@ await analytics.engines.createAndStartEngine('processor', 'article-projector', {
|
|
|
302
353
|
await analytics.put('articles', 'a1', { title: 'Hello' });
|
|
303
354
|
```
|
|
304
355
|
|
|
305
|
-
`processor` config shape
|
|
356
|
+
`processor` config shape:
|
|
357
|
+
|
|
358
|
+
<!-- not-runnable: shape fragment -->
|
|
306
359
|
|
|
307
360
|
```javascript
|
|
308
361
|
{
|
|
@@ -334,10 +387,10 @@ Config notes:
|
|
|
334
387
|
- `source_env` — optional env name for the source type; defaults to the engine owning env
|
|
335
388
|
- `handler.env` — optional env name for the function registry; defaults to the engine owning env
|
|
336
389
|
- `mode`, `bootstrap`, `originMode`, `batchSize`, `hydrateValues`, `cursorKey`, `lockMode`, `flushDebounce`, `flushInterval` — forwarded to the underlying processor runtime
|
|
337
|
-
- `failOnHandlerError` — included in runtime metadata;
|
|
390
|
+
- `failOnHandlerError` — included in runtime metadata; handler failures are treated as engine errors
|
|
338
391
|
- `flushDebounce` — coalesces rapid write bursts into a single handler delivery after the quiet period
|
|
339
392
|
- `flushInterval` — periodic poll; useful for `originMode: 'remote'` subscriptions where local writes don't trigger delivery
|
|
340
|
-
-
|
|
393
|
+
- With `originMode: 'all'` or `'remote'`, the underlying processor wakes on writes made by other processes on the same store; no additional configuration is needed for correct multi-process behavior.
|
|
341
394
|
|
|
342
395
|
Behavior:
|
|
343
396
|
|
|
@@ -361,6 +414,8 @@ Runtime stats exposed through `engine.api.stats()` / `engine.api.status()` inclu
|
|
|
361
414
|
|
|
362
415
|
Minimal pipeline membership example:
|
|
363
416
|
|
|
417
|
+
<!-- continues -->
|
|
418
|
+
|
|
364
419
|
```javascript
|
|
365
420
|
await analytics.pipelines.create({
|
|
366
421
|
name: 'projection-pipeline',
|
|
@@ -373,7 +428,7 @@ await analytics.pipelines.create({
|
|
|
373
428
|
|
|
374
429
|
### `materializer` engine
|
|
375
430
|
|
|
376
|
-
|
|
431
|
+
A `materializer` engine type for deterministic source→target collection projection.
|
|
377
432
|
|
|
378
433
|
Unlike the generic `processor`, a materializer has an **explicit target type** and a **return-ops contract** that enables safe rebuild.
|
|
379
434
|
|
|
@@ -390,6 +445,8 @@ Key differences from `processor`:
|
|
|
390
445
|
|
|
391
446
|
Typical flow:
|
|
392
447
|
|
|
448
|
+
<!-- licensed: engines -->
|
|
449
|
+
|
|
393
450
|
```javascript
|
|
394
451
|
const analytics = await db.createEnvironment('analytics');
|
|
395
452
|
await analytics.registerType('orders');
|
|
@@ -433,6 +490,8 @@ await engine.api.rebuild();
|
|
|
433
490
|
|
|
434
491
|
`materializer` config shape:
|
|
435
492
|
|
|
493
|
+
<!-- not-runnable: shape fragment -->
|
|
494
|
+
|
|
436
495
|
```javascript
|
|
437
496
|
{
|
|
438
497
|
source_type: 'orders',
|
|
@@ -486,15 +545,21 @@ Engine API:
|
|
|
486
545
|
- `engine.api.pause()` / `engine.api.resume()` — pause/resume consumption
|
|
487
546
|
- `engine.api.retry()` — retry after error state
|
|
488
547
|
|
|
548
|
+
### The `db.pipelines` aggregate
|
|
549
|
+
|
|
550
|
+
`okdb.pipelines` is a read-only view across every opened environment (mutations live on
|
|
551
|
+
`okdb.env(name).pipelines`):
|
|
552
|
+
|
|
489
553
|
```javascript
|
|
490
|
-
const all = await okdb.pipelines.list();
|
|
491
|
-
const
|
|
492
|
-
const record = await okdb.pipelines.get('
|
|
554
|
+
const all = await okdb.pipelines.list(); // every opened env; each entry has `env`
|
|
555
|
+
const defaultOnly = await okdb.pipelines.list({ envName: 'default' });
|
|
556
|
+
const record = await okdb.pipelines.get('default', 'articles-ingest'); // null when absent
|
|
557
|
+
const owner = okdb.pipelines.findOwner('indexer', 'default:articles'); // { env, pipeline, role } or null
|
|
493
558
|
```
|
|
494
559
|
|
|
495
560
|
---
|
|
496
561
|
|
|
497
|
-
## Lifecycle behavior
|
|
562
|
+
## Lifecycle behavior
|
|
498
563
|
|
|
499
564
|
The base feature is intentionally narrow.
|
|
500
565
|
|
|
@@ -513,7 +578,7 @@ Supported lifecycle operations:
|
|
|
513
578
|
- `stop`
|
|
514
579
|
- `remove`
|
|
515
580
|
|
|
516
|
-
Topology is structurally immutable
|
|
581
|
+
Topology is structurally immutable:
|
|
517
582
|
|
|
518
583
|
- changing engine membership is rejected
|
|
519
584
|
- changing engine roles is rejected
|
|
@@ -541,7 +606,7 @@ Shared/global engines are preserved.
|
|
|
541
606
|
|
|
542
607
|
### HTTP routes
|
|
543
608
|
|
|
544
|
-
Generic pipelines
|
|
609
|
+
Generic pipelines expose env-scoped routes:
|
|
545
610
|
|
|
546
611
|
- `GET /api/env/:env/pipelines`
|
|
547
612
|
- `GET /api/env/:env/pipelines/:pipeline`
|
|
@@ -561,7 +626,7 @@ Read responses include derived pipeline/member inspection data such as:
|
|
|
561
626
|
|
|
562
627
|
### Admin visibility
|
|
563
628
|
|
|
564
|
-
The admin UI
|
|
629
|
+
The admin UI exposes pipelines and engines through three complementary views:
|
|
565
630
|
|
|
566
631
|
- **Queue → Workers** — create and manage `queue-worker` engines directly for the selected job type
|
|
567
632
|
- **DB → Type detail** — open a type-scoped engines view for embeddings/vector pipelines, including shortcuts from the vector/index drill-ins back to the owning pipeline
|
|
@@ -579,14 +644,14 @@ Current behavior:
|
|
|
579
644
|
|
|
580
645
|
### Sync / runtime activation
|
|
581
646
|
|
|
582
|
-
|
|
647
|
+
With [sync](./sync.md) (a licensed feature), synced pipeline declarations reconcile through the same runtime activation path used for synced engines.
|
|
583
648
|
|
|
584
649
|
That shared activation path runs:
|
|
585
650
|
|
|
586
651
|
- after `OKDB.open()` startup restore
|
|
587
652
|
- after each sync reconcile pass completes
|
|
588
653
|
|
|
589
|
-
Behavior
|
|
654
|
+
Behavior:
|
|
590
655
|
|
|
591
656
|
- env-scoped engine records still restore/start through the engine feature
|
|
592
657
|
- pipeline records add a second reconciliation pass based on persisted pipeline `status`
|
|
@@ -605,7 +670,7 @@ Cluster expectation:
|
|
|
605
670
|
|
|
606
671
|
## Relation to embeddings
|
|
607
672
|
|
|
608
|
-
Embeddings
|
|
673
|
+
Embeddings use this generic pipeline model as their persisted grouping layer while keeping the richer `okdb.embeddings` facade.
|
|
609
674
|
|
|
610
675
|
Current behavior:
|
|
611
676
|
|
|
@@ -613,7 +678,7 @@ Current behavior:
|
|
|
613
678
|
- that record uses the pipeline `storage_key` as its generic name
|
|
614
679
|
- member roles are explicit and ordered: `embedder`, `indexer`, optional `worker`, `search`
|
|
615
680
|
- the record is tagged with `meta.family = 'embeddings'` so specialized embeddings views can recognize it cleanly
|
|
616
|
-
- embeddings lifecycle routes
|
|
681
|
+
- embeddings lifecycle routes delegate to the generic pipeline feature when a generic record exists
|
|
617
682
|
|
|
618
683
|
Embeddings-backed records also use `meta.lifecycleSkipRoles = ['embedder']`.
|
|
619
684
|
|
package/docs/plugins.md
CHANGED
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
# Plugins
|
|
2
2
|
|
|
3
|
-
Plugins are first-class addons that extend OKDB before it opens. They integrate into the lifecycle cleanly: registered before `open()`, started
|
|
3
|
+
Plugins are first-class addons that extend OKDB before it opens. They integrate into the lifecycle cleanly: registered before `open()`, started at the end of `open()`, stopped before `close()`.
|
|
4
|
+
|
|
5
|
+
> **3.0 notes.** The 2.x plugin contract is unchanged, with three differences: `start()` runs after the
|
|
6
|
+
> **whole** `open()` has finished (in 2.x it ran mid-open, before views and runtime declarations
|
|
7
|
+
> booted), so a plugin always sees a fully started instance but can no longer act before those boot;
|
|
8
|
+
> `okdb.api` and `okdb.admin` are stubs whose members throw `NOT_IMPLEMENTED_NATIVE` — drive the
|
|
9
|
+
> server through HTTP routes or the public facades instead; and `_`-prefixed internals of the 2.x
|
|
10
|
+
> JS implementation no longer exist. The standalone `okdb` CLI loads no plugins (as in 2.x):
|
|
11
|
+
> plugins exist where an application embeds okdb in Node.
|
|
4
12
|
|
|
5
13
|
---
|
|
6
14
|
|
|
7
15
|
## Registering a plugin
|
|
8
16
|
|
|
9
17
|
```javascript
|
|
18
|
+
const MyPlugin = { name: 'my-plugin', register: () => ({}) };
|
|
10
19
|
const okdb = new OKDB('./db');
|
|
11
20
|
|
|
12
21
|
okdb.plugins.register(MyPlugin, {/* options */});
|
|
13
22
|
|
|
14
23
|
await okdb.open();
|
|
24
|
+
await okdb.close();
|
|
15
25
|
```
|
|
16
26
|
|
|
17
27
|
Plugins must be registered **before** `okdb.open()`. Attempting to register after open throws `INVALID_STATE`.
|
|
@@ -24,7 +34,7 @@ A plugin module is a plain object with a `name`, an optional `requires` list, an
|
|
|
24
34
|
|
|
25
35
|
```javascript
|
|
26
36
|
// my-plugin.js
|
|
27
|
-
|
|
37
|
+
const MyPlugin = {
|
|
28
38
|
name: 'my-plugin',
|
|
29
39
|
|
|
30
40
|
// Other plugin names that must be registered first
|
|
@@ -51,15 +61,20 @@ module.exports = {
|
|
|
51
61
|
};
|
|
52
62
|
},
|
|
53
63
|
};
|
|
64
|
+
module.exports = MyPlugin;
|
|
54
65
|
```
|
|
55
66
|
|
|
67
|
+
<!-- continues -->
|
|
68
|
+
|
|
56
69
|
```javascript
|
|
57
|
-
const MyPlugin = require('./my-plugin');
|
|
70
|
+
// const MyPlugin = require('./my-plugin');
|
|
71
|
+
const okdb = new OKDB('./db');
|
|
58
72
|
okdb.plugins.register(MyPlugin, {/* options passed to register() */});
|
|
59
|
-
await okdb.open();
|
|
73
|
+
await okdb.open(); // logs 'my-plugin started'
|
|
74
|
+
await okdb.close(); // logs 'my-plugin stopped'
|
|
60
75
|
```
|
|
61
76
|
|
|
62
|
-
The instance is kept internally
|
|
77
|
+
The instance is kept internally — it is **not** attached as a property on `okdb`. If callers need it, keep your own reference (e.g. export it from the plugin module).
|
|
63
78
|
|
|
64
79
|
:::note
|
|
65
80
|
Plugin name must not conflict with existing OKDB properties (`env`, `put`, `get`, `http`, etc.). Registration throws `PLUGIN_NAME_CONFLICT` if there's a clash, `PLUGIN_ALREADY_REGISTERED` for a duplicate name, and `BAD_PLUGIN` when `name` is missing or `register()` doesn't return an object.
|
|
@@ -84,11 +99,19 @@ Plugin name must not conflict with existing OKDB properties (`env`, `put`, `get`
|
|
|
84
99
|
Use `requires` to declare that another plugin must be registered first:
|
|
85
100
|
|
|
86
101
|
```javascript
|
|
87
|
-
|
|
102
|
+
const payments = {
|
|
88
103
|
name: 'payments',
|
|
89
|
-
requires: ['auth'],
|
|
90
|
-
register(okdb, options) {
|
|
104
|
+
requires: ['auth'], // 'auth' plugin must be registered before 'payments'
|
|
105
|
+
register(okdb, options) {
|
|
106
|
+
return {};
|
|
107
|
+
},
|
|
91
108
|
};
|
|
109
|
+
const okdb = new OKDB('./db');
|
|
110
|
+
try {
|
|
111
|
+
okdb.plugins.register(payments);
|
|
112
|
+
} catch (e) {
|
|
113
|
+
console.log(e.code); // PLUGIN_DEPENDENCY_MISSING
|
|
114
|
+
}
|
|
92
115
|
```
|
|
93
116
|
|
|
94
117
|
OKDB checks this at registration time and throws `PLUGIN_DEPENDENCY_MISSING` if the dependency isn't registered yet.
|
|
@@ -100,7 +123,7 @@ OKDB checks this at registration time and throws `PLUGIN_DEPENDENCY_MISSING` if
|
|
|
100
123
|
A common pattern is a plugin that ensures types and indexes exist at startup:
|
|
101
124
|
|
|
102
125
|
```javascript
|
|
103
|
-
|
|
126
|
+
const schemaPlugin = {
|
|
104
127
|
name: 'schema',
|
|
105
128
|
register(okdb, options) {
|
|
106
129
|
return {
|
|
@@ -117,22 +140,31 @@ module.exports = {
|
|
|
117
140
|
};
|
|
118
141
|
},
|
|
119
142
|
};
|
|
143
|
+
module.exports = schemaPlugin;
|
|
144
|
+
|
|
145
|
+
const okdb = new OKDB('./db');
|
|
146
|
+
okdb.plugins.register(schemaPlugin);
|
|
147
|
+
await okdb.open(); // types exist once open() resolves
|
|
148
|
+
await okdb.close();
|
|
120
149
|
```
|
|
121
150
|
|
|
122
151
|
---
|
|
123
152
|
|
|
124
153
|
## Listing registered plugins
|
|
125
154
|
|
|
155
|
+
`okdb.info` (and `GET /api/info`) includes the registered plugin names:
|
|
156
|
+
|
|
126
157
|
```javascript
|
|
127
|
-
const
|
|
128
|
-
|
|
158
|
+
const okdb = new OKDB('./db');
|
|
159
|
+
okdb.plugins.register({ name: 'schema', register: () => ({}) });
|
|
160
|
+
await okdb.open();
|
|
161
|
+
okdb.info.plugins; // → ['schema']
|
|
162
|
+
await okdb.close();
|
|
129
163
|
```
|
|
130
164
|
|
|
131
|
-
|
|
165
|
+
<!-- not-runnable: needs a running server (the network) -->
|
|
132
166
|
|
|
133
167
|
```javascript
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const info = await fetch('/api/info').then((r) => r.json());
|
|
168
|
+
const info = await fetch('http://localhost:8484/api/info').then((r) => r.json());
|
|
137
169
|
info.data.plugins; // → ['schema', 'auth', 'payments']
|
|
138
170
|
```
|
package/docs/process-registry.md
CHANGED
|
@@ -24,7 +24,7 @@ hint. A forged or dropped bus packet can therefore neither trigger nor lose a co
|
|
|
24
24
|
The primary entity is the **process**, not the processor. Each long-lived process publishes one
|
|
25
25
|
`node` row:
|
|
26
26
|
|
|
27
|
-
```
|
|
27
|
+
```text
|
|
28
28
|
{
|
|
29
29
|
nodeKey, // identity: `${pid}:${startedAt}` (wall-clock startedAt — same-host, see Liveness)
|
|
30
30
|
kind, // primary | http-server | cli | standalone | embedded
|
|
@@ -41,8 +41,8 @@ The primary entity is the **process**, not the processor. Each long-lived proces
|
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
A processor (FTS, views, materializer, time-machine, …) is **not** a separate entity — it is summarized
|
|
44
|
-
on the owner's `processing` facet (`processing.processors[]`).
|
|
45
|
-
drains run
|
|
44
|
+
on the owner's `processing` facet (`processing.processors[]`). okdb has no worker pools —
|
|
45
|
+
drains run in the claiming process, so there is nothing pool-shaped to give its own row.
|
|
46
46
|
|
|
47
47
|
### Two stores, split by lifetime
|
|
48
48
|
|
|
@@ -58,8 +58,7 @@ writes emit **no** signal — the panel polls. Only desired-state/command writes
|
|
|
58
58
|
|
|
59
59
|
HTTP-cluster workers (`http-server`) lack a stable cross-restart identity, so they do **not**
|
|
60
60
|
self-register (they open the registry as readers). Their **supervisor** — which already tracks each
|
|
61
|
-
child's pid/slot and heartbeats it — writes the child's `node` row (
|
|
62
|
-
exit. Roots (primary/cli/standalone) and embedded nodes self-publish via their heartbeat.
|
|
61
|
+
child's pid/slot and heartbeats it — writes the child's `node` row and removes it on exit. Roots (primary/cli/standalone) and embedded nodes self-publish via their heartbeat.
|
|
63
62
|
|
|
64
63
|
### Liveness — wall-clock, read-time staleness
|
|
65
64
|
|
|
@@ -87,16 +86,16 @@ All routes require `system:read` (views) or `system:write` (control).
|
|
|
87
86
|
> `GET /api/processes[/tree]` (the former `okdb.fleet` accessor alias was removed). Don't confuse it
|
|
88
87
|
> with **processors** (`/api/processors/*`), the change-subscription primitives a process runs.
|
|
89
88
|
|
|
90
|
-
| Method & path | Purpose
|
|
91
|
-
| ------------------------------------------- |
|
|
92
|
-
| `GET /api/processes` | flat list of live processes (grouped, each with `instances[]`)
|
|
93
|
-
| `GET /api/processes/tree` | nested process → instance → work tree (`supervisorKey`)
|
|
94
|
-
| `POST /api/processors/:id/pause`/`resume` | durable pause/resume of a processor (desired-state)
|
|
95
|
-
| `POST /api/processors/:id/retry` | retry an errored processor (durable command epoch)
|
|
96
|
-
| `POST /api/processors/cursor/reset` | reset a processor cursor to 0 (durable + command epoch)
|
|
97
|
-
| `POST /api/processes/:nodeKey/decommission` | gracefully stop a supervised process and keep it down
|
|
98
|
-
| `POST /api/processes/:nodeKey/recommission` | reverse a decommission/kill — the supervisor
|
|
99
|
-
| `POST /api/processes/:nodeKey/kill?force=1` | hard-kill (guarded; see Control tiers)
|
|
89
|
+
| Method & path | Purpose |
|
|
90
|
+
| ------------------------------------------- | ---------------------------------------------------------------- |
|
|
91
|
+
| `GET /api/processes` | flat list of live processes (grouped, each with `instances[]`) |
|
|
92
|
+
| `GET /api/processes/tree` | nested process → instance → work tree (`supervisorKey`) |
|
|
93
|
+
| `POST /api/processors/:id/pause`/`resume` | durable pause/resume of a processor (desired-state) |
|
|
94
|
+
| `POST /api/processors/:id/retry` | retry an errored processor (durable command epoch) |
|
|
95
|
+
| `POST /api/processors/cursor/reset` | reset a processor cursor to 0 (durable + command epoch) |
|
|
96
|
+
| `POST /api/processes/:nodeKey/decommission` | gracefully stop a supervised process and keep it down |
|
|
97
|
+
| `POST /api/processes/:nodeKey/recommission` | reverse a decommission/kill — the supervisor relaunches the slot |
|
|
98
|
+
| `POST /api/processes/:nodeKey/kill?force=1` | hard-kill (guarded; see Control tiers) |
|
|
100
99
|
|
|
101
100
|
When the registry is off (`processes: false`), `/api/processes[/tree]` returns a degenerate
|
|
102
101
|
single-root node so the API still answers.
|
|
@@ -118,10 +117,10 @@ target's supervisor) reconciles it.
|
|
|
118
117
|
3. **Lifecycle — decommission / hard-kill** (routed through the **supervisor**, not by fighting the
|
|
119
118
|
respawn loop):
|
|
120
119
|
- **Decommission** (`decommissionable` kinds): the supervisor marks the slot dead (no respawn) and
|
|
121
|
-
cleanly
|
|
120
|
+
cleanly disconnects the child so it drains in-flight work. Keyed by the **stable** `slotKey`
|
|
122
121
|
(`cluster:<port>/<slot>`), so it **survives a supervisor restart** — a restarted primary reloads
|
|
123
|
-
the dead slots before
|
|
124
|
-
and
|
|
122
|
+
the dead slots before launching workers and does not revive them. **Recommission** clears the record
|
|
123
|
+
and relaunches the worker.
|
|
125
124
|
- **Hard-kill** (`POST …/kill`): the last resort, guarded. Requires explicit `?force=1`. Rejected
|
|
126
125
|
for non-killable kinds. Killing a **primary** additionally requires `?confirm=1` because it tears
|
|
127
126
|
down the whole cluster (its workers self-exit on the primary's death). The supervisor `SIGKILL`s
|
|
@@ -150,7 +149,7 @@ embedded node is never killable and never self-terminates.
|
|
|
150
149
|
## Scope: same-host processes vs sync peers
|
|
151
150
|
|
|
152
151
|
The registry covers **same-host, same-root** processes — they share the LMDB files, the UDP bus, and
|
|
153
|
-
the
|
|
152
|
+
the per-env shared-memory segment. **Cross-machine sync-replication peers are a separate axis** (no shared
|
|
154
153
|
LMDB; "kill" there would be a sync-protocol RPC) and are surfaced by the Sync view, not the process registry.
|
|
155
154
|
|
|
156
155
|
---
|
|
@@ -159,20 +158,20 @@ LMDB; "kill" there would be a sync-protocol RPC) and are surfaced by the Sync vi
|
|
|
159
158
|
|
|
160
159
|
```js
|
|
161
160
|
// Default: publishes a `standalone` row (killable/controllable per the table above).
|
|
162
|
-
const
|
|
161
|
+
const a = new OKDB('./data');
|
|
163
162
|
|
|
164
163
|
// Observe-only: appear in the registry, expose nothing controllable or killable.
|
|
165
|
-
const
|
|
164
|
+
const b = new OKDB('./data', { processes: { kind: 'embedded', name: 'oasis-worker' } });
|
|
166
165
|
|
|
167
166
|
// Reader only: read the registry, publish no row.
|
|
168
|
-
const
|
|
167
|
+
const c = new OKDB('./data', { processes: { register: false } });
|
|
169
168
|
|
|
170
169
|
// Invisible: no registry at all.
|
|
171
|
-
const
|
|
170
|
+
const d = new OKDB('./data', { processes: false });
|
|
172
171
|
```
|
|
173
172
|
|
|
174
173
|
`processes` also takes `name` (a label shown in the admin), `listenAddr`, and `kill: false` (see
|
|
175
|
-
below). `
|
|
174
|
+
below). The `okdb` CLI sets `kind` automatically (`primary` / `http-server` / `cli`).
|
|
176
175
|
|
|
177
176
|
---
|
|
178
177
|
|