@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.
- package/CHANGELOG.md +366 -0
- package/algorithm-worker-thread.js +1 -1
- package/bin/okdb.js +1 -1
- package/docs/auth-and-sync.md +28 -4
- 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/files.md +1 -1
- 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/logging.md +18 -0
- package/docs/migration.md +94 -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 +35 -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 +71 -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 +2 -4
- 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 +377 -0
- package/types/options.d.ts +309 -48
- package/public/test-cron-input.html +0 -60
- package/public/test-json-input.html +0 -280
package/docs/http-api.md
CHANGED
|
@@ -71,31 +71,20 @@ The HTTP server is optional. You can use OKDB entirely in-process without it.
|
|
|
71
71
|
|
|
72
72
|
## Authentication
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
api: { tokens: ['my-secret-token'] },
|
|
79
|
-
});
|
|
80
|
-
```
|
|
74
|
+
Credentials are **tokens stored in the database** (`~tokens` in `~system`) — there are no token
|
|
75
|
+
lists, passwords or API keys in the constructor options. Create one with `okdb token create`, the
|
|
76
|
+
admin UI, or `POST /api/auth/tokens` (while no token exists yet, localhost gets full access — the
|
|
77
|
+
bootstrap window). Then send it as a Bearer token:
|
|
81
78
|
|
|
82
79
|
```bash
|
|
83
|
-
curl http://localhost:8080/api/
|
|
84
|
-
-H "Authorization: Bearer
|
|
80
|
+
curl http://localhost:8080/api/types \
|
|
81
|
+
-H "Authorization: Bearer <raw-token>"
|
|
85
82
|
```
|
|
86
83
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
auth: {
|
|
92
|
-
user: 'admin',
|
|
93
|
-
pass: 'secret',
|
|
94
|
-
cookieSecret: 'change-me-in-production',
|
|
95
|
-
cookieTtlMs: 3_600_000,
|
|
96
|
-
},
|
|
97
|
-
}
|
|
98
|
-
```
|
|
84
|
+
Trusted IPs can skip auth entirely with `auth: { open: true }` (localhost) or an IP / CIDR list.
|
|
85
|
+
The admin UI signs in with a token's name + password (`POST /auth/login` → `okdb_session`
|
|
86
|
+
cookie). See [Auth and Sync](./auth-and-sync.md) for the full model and
|
|
87
|
+
[Auth Permissions](./auth-permissions.md) for what each route requires.
|
|
99
88
|
|
|
100
89
|
---
|
|
101
90
|
|
|
@@ -182,7 +171,9 @@ Supported body projection modes include:
|
|
|
182
171
|
- `remaining-fields`
|
|
183
172
|
- `object`
|
|
184
173
|
- `payload-or-self`
|
|
185
|
-
- `array`
|
|
174
|
+
- `array` — like `remaining-fields`, but a bare JSON-array body is bound to the route's single
|
|
175
|
+
unbound array-typed input field (e.g. `POST /transaction` accepts `{ "operations": [...] }` or
|
|
176
|
+
`[...]`); a route declaring it must have exactly one such field
|
|
186
177
|
- `raw`
|
|
187
178
|
|
|
188
179
|
### Validation rules
|
|
@@ -345,42 +336,79 @@ Feature authors should keep the route's owning feature responsible for its metad
|
|
|
345
336
|
|
|
346
337
|
## CRUD endpoints
|
|
347
338
|
|
|
348
|
-
|
|
339
|
+
### Environment prefix
|
|
340
|
+
|
|
341
|
+
Env-scoped routes take an **optional** `/env/:env` segment after `/api`:
|
|
342
|
+
|
|
343
|
+
```http
|
|
344
|
+
GET /api/env/analytics/type/events/item/e1 → env "analytics"
|
|
345
|
+
GET /api/type/events/item/e1 → the default env
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
Without the segment the request goes to the default env — `default`, or whatever
|
|
349
|
+
`new OKDB(path, { api: { defaultEnv: 'analytics' } })` sets. (`/api/default/...` is **not** a
|
|
350
|
+
valid form — it 404s.) The route lists below write the prefix as `/api[/env/:env]`; a few
|
|
351
|
+
env-admin, pipeline, engine, schema and time-machine routes exist only in the explicit
|
|
352
|
+
`/api/env/:env/...` form and are written that way.
|
|
353
|
+
|
|
354
|
+
### Response envelope
|
|
355
|
+
|
|
356
|
+
Every JSON response is wrapped as `{ data, error, meta }`: `data` is the result (`null` for
|
|
357
|
+
writes), `error` is `null` or `{ code, message, details? }`, and `meta.time` is the server time
|
|
358
|
+
in ms. Write routes that have no result (put, patch, delete, register) answer
|
|
359
|
+
`200 { "data": null, ... }`. Errors use the matching HTTP status (`404 TYPE_NOT_REGISTERED`,
|
|
360
|
+
`404 NOT_FOUND`, `400 VALIDATION_ERROR`, `403 FORBIDDEN`, …).
|
|
349
361
|
|
|
350
362
|
### Records
|
|
351
363
|
|
|
364
|
+
A type must exist before you write to it — register it with `POST /api[/env/:env]/type/:type`
|
|
365
|
+
(writes to an unknown type fail with `404 TYPE_NOT_REGISTERED`).
|
|
366
|
+
|
|
352
367
|
```http
|
|
353
|
-
GET /api/:env/type/:type/item/:key → single record
|
|
354
|
-
PUT /api/:env/type/:type/item/:key → upsert
|
|
355
|
-
PATCH /api/:env/type/:type/item/:key → partial update (body.patch = patch doc)
|
|
356
|
-
DELETE /api/:env/type/:type/item/:key → remove
|
|
357
|
-
POST /api/:env/type/:type/query → query records
|
|
358
|
-
POST /api/:env/
|
|
368
|
+
GET /api[/env/:env]/type/:type/item/:key → single record { key, value, ttl? }
|
|
369
|
+
PUT /api[/env/:env]/type/:type/item/:key → upsert — the JSON body IS the document
|
|
370
|
+
PATCH /api[/env/:env]/type/:type/item/:key → partial update (body.patch = patch doc)
|
|
371
|
+
DELETE /api[/env/:env]/type/:type/item/:key → remove (404 NOT_FOUND if absent)
|
|
372
|
+
POST /api[/env/:env]/type/:type/query → query records { filter, options }
|
|
373
|
+
POST /api[/env/:env]/type/:type/count → count records
|
|
374
|
+
POST /api[/env/:env]/transaction → atomic batch writes
|
|
359
375
|
```
|
|
360
376
|
|
|
361
|
-
**
|
|
377
|
+
- **PUT stores the whole request body as the document.** There is no `value` wrapper — a body of
|
|
378
|
+
`{"value": {...}}` stores a document with a `value` field. If the body has a numeric top-level
|
|
379
|
+
`ttl` > 0, it is also applied as the record's TTL in ms — and, since the body is the document,
|
|
380
|
+
the `ttl` field is stored in the document too. Use `PUT .../item/:key/ttl` (see [TTL](./ttl.md))
|
|
381
|
+
to set a TTL without touching the document.
|
|
382
|
+
- **GET of a missing key is not a 404**: it answers `200` with `data: { key }` and no `value`.
|
|
383
|
+
Test `value === undefined`.
|
|
384
|
+
|
|
385
|
+
**Atomic bulk writes:** `POST /api[/env/:env]/transaction` takes `{ "operations": [...] }` (or the bare operations array) — `put`, `update`, `patch`, and `remove` operations committed in one LMDB transaction — the right primitive for bulk ingest. See [Transactions](./transactions.md#http-api--bulk-writes) for the full body format and examples.
|
|
362
386
|
|
|
363
387
|
**Hybrid search:** The `options` body field now accepts `fts` and `vector` sub-objects alongside `index`. See the querying guide for full documentation. When `fts` or `vector` is provided, the route automatically awaits the async result.
|
|
364
388
|
|
|
365
389
|
```bash
|
|
366
|
-
#
|
|
367
|
-
curl http://localhost:8080/api/
|
|
390
|
+
# Register the type (once)
|
|
391
|
+
curl -X POST http://localhost:8080/api/type/users \
|
|
368
392
|
-H "Authorization: Bearer token"
|
|
369
393
|
|
|
370
|
-
# Upsert by key
|
|
371
|
-
curl -X PUT http://localhost:8080/api/
|
|
394
|
+
# Upsert by key — the body is the document
|
|
395
|
+
curl -X PUT http://localhost:8080/api/type/users/item/alice \
|
|
372
396
|
-H "Authorization: Bearer token" \
|
|
373
397
|
-H "Content-Type: application/json" \
|
|
374
|
-
-d '{"
|
|
398
|
+
-d '{"name": "Alice", "role": "superadmin"}'
|
|
399
|
+
|
|
400
|
+
# Get a record → {"data":{"key":"alice","value":{"name":"Alice","role":"superadmin"}},...}
|
|
401
|
+
curl http://localhost:8080/api/type/users/item/alice \
|
|
402
|
+
-H "Authorization: Bearer token"
|
|
375
403
|
|
|
376
404
|
# Patch an existing record
|
|
377
|
-
curl -X PATCH http://localhost:8080/api/
|
|
405
|
+
curl -X PATCH http://localhost:8080/api/type/users/item/alice \
|
|
378
406
|
-H "Authorization: Bearer token" \
|
|
379
407
|
-H "Content-Type: application/json" \
|
|
380
408
|
-d '{"patch":{"set":{"role":"admin"},"inc":{"loginCount":1},"append":{"tags":["vip"]},"pull":{"tags":["trial"]}},"ifVersion":7}'
|
|
381
409
|
|
|
382
410
|
# Delete
|
|
383
|
-
curl -X DELETE http://localhost:8080/api/
|
|
411
|
+
curl -X DELETE http://localhost:8080/api/type/users/item/alice \
|
|
384
412
|
-H "Authorization: Bearer token"
|
|
385
413
|
```
|
|
386
414
|
|
|
@@ -412,22 +440,20 @@ Notes:
|
|
|
412
440
|
- patch applies to existing object records only
|
|
413
441
|
- arrays are incrementally mutated via `append` and `pull`
|
|
414
442
|
- `ifVersion` enables compare-and-swap writes
|
|
415
|
-
- successful patch calls return `
|
|
443
|
+
- successful patch calls return `200` with `data: null`
|
|
416
444
|
|
|
417
445
|
### List records
|
|
418
446
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
&offset=0
|
|
423
|
-
&start=<key>
|
|
424
|
-
&end=<key>
|
|
425
|
-
&reverse=false
|
|
426
|
-
```
|
|
447
|
+
There is no key-range listing route — `GET /api[/env/:env]/type/:type` returns type info
|
|
448
|
+
(`{ type, count, fields, indexes }`), not records. List records with the query route and its
|
|
449
|
+
`options` (the same options as `env.query()`, e.g. `limit`):
|
|
427
450
|
|
|
428
451
|
```bash
|
|
429
|
-
curl
|
|
430
|
-
-H "Authorization: Bearer token"
|
|
452
|
+
curl -X POST http://localhost:8080/api/type/users/query \
|
|
453
|
+
-H "Authorization: Bearer token" \
|
|
454
|
+
-H "Content-Type: application/json" \
|
|
455
|
+
-d '{"filter": {}, "options": {"limit": 10}}'
|
|
456
|
+
# → {"data":[{"key":"alice","value":{...}}, ...],"error":null,"meta":{"time":2,"count":1}}
|
|
431
457
|
```
|
|
432
458
|
|
|
433
459
|
---
|
|
@@ -435,19 +461,21 @@ curl "http://localhost:8080/api/default/type/users?limit=10&reverse=true" \
|
|
|
435
461
|
## Change log endpoints
|
|
436
462
|
|
|
437
463
|
```http
|
|
438
|
-
GET /api/:env/changelog
|
|
439
|
-
?
|
|
440
|
-
?
|
|
441
|
-
?
|
|
464
|
+
GET /api/env/:env/changelog → all types in the env, newest first
|
|
465
|
+
?after=<clock> → only changes after this clock
|
|
466
|
+
?before=<clock> → only changes up to this clock
|
|
467
|
+
?limit=<n> → default 100, max 1000
|
|
442
468
|
|
|
443
|
-
GET /api/:env/type/:type/changelog
|
|
469
|
+
GET /api[/env/:env]/type/:type/changelog → one type
|
|
444
470
|
?before=<clock>
|
|
445
|
-
?
|
|
471
|
+
?limit=<n> → default 100, max 1000
|
|
472
|
+
|
|
473
|
+
GET /api[/env/:env]/type/:type/item/:key/changelog → one record (?before, ?limit default 50)
|
|
446
474
|
```
|
|
447
475
|
|
|
448
476
|
```bash
|
|
449
|
-
# Get changes
|
|
450
|
-
curl "http://localhost:8080/api/default/changelog?after=100" \
|
|
477
|
+
# Get changes after clock 100
|
|
478
|
+
curl "http://localhost:8080/api/env/default/changelog?after=100" \
|
|
451
479
|
-H "Authorization: Bearer token"
|
|
452
480
|
```
|
|
453
481
|
|
|
@@ -456,30 +484,35 @@ curl "http://localhost:8080/api/default/changelog?after=100" \
|
|
|
456
484
|
## Schema endpoints
|
|
457
485
|
|
|
458
486
|
```http
|
|
459
|
-
GET
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
487
|
+
GET /api[/env/:env]/types → list all registered types
|
|
488
|
+
GET /api[/env/:env]/type/:type → type info (count, fields, indexes)
|
|
489
|
+
POST /api[/env/:env]/type/:type → register a type
|
|
490
|
+
DELETE /api[/env/:env]/type/:type → drop a type
|
|
491
|
+
|
|
492
|
+
GET /api[/env/:env]/type/:type/indexes → list indexes
|
|
493
|
+
POST /api[/env/:env]/type/:type/index/:idx → register an index (body: { type?, precision?, unique? })
|
|
494
|
+
DELETE /api[/env/:env]/type/:type/index/:idx → drop an index
|
|
495
|
+
POST /api[/env/:env]/type/:type/index/:idx/reset → rebuild an index
|
|
496
|
+
GET /api[/env/:env]/type/:type/index/:idx/count?start=<json>&end=<json> → count index entries in range
|
|
466
497
|
```
|
|
467
498
|
|
|
499
|
+
A compound index id joins its fields with `~` (`POST .../index/status~createdAt`).
|
|
500
|
+
|
|
468
501
|
---
|
|
469
502
|
|
|
470
503
|
## Full-text search endpoints
|
|
471
504
|
|
|
472
505
|
```http
|
|
473
|
-
GET /api/:env/fts/size → FTS storage summary for the env
|
|
474
|
-
GET /api/:env/type/:type/fts → list FTS indexes
|
|
475
|
-
POST /api/:env/type/:type/fts/:name → register a new FTS index
|
|
476
|
-
DELETE /api/:env/type/:type/fts/:name → drop an FTS index
|
|
477
|
-
POST /api/:env/type/:type/fts/:name/reset → rebuild an FTS index from scratch
|
|
478
|
-
POST /api/:env/type/:type/fts/:name/search → search an FTS index
|
|
479
|
-
POST /api/:env/type/:type/fts/flush → flush FTS processor (await catch-up)
|
|
506
|
+
GET /api[/env/:env]/fts/size → FTS storage summary for the env
|
|
507
|
+
GET /api[/env/:env]/type/:type/fts → list FTS indexes
|
|
508
|
+
POST /api[/env/:env]/type/:type/fts/:name → register a new FTS index
|
|
509
|
+
DELETE /api[/env/:env]/type/:type/fts/:name → drop an FTS index
|
|
510
|
+
POST /api[/env/:env]/type/:type/fts/:name/reset → rebuild an FTS index from scratch
|
|
511
|
+
POST /api[/env/:env]/type/:type/fts/:name/search → search an FTS index
|
|
512
|
+
POST /api[/env/:env]/type/:type/fts/flush → flush FTS processor (await catch-up)
|
|
480
513
|
```
|
|
481
514
|
|
|
482
|
-
### GET /api/:env/fts/size — env-level storage summary
|
|
515
|
+
### GET /api[/env/:env]/fts/size — env-level storage summary
|
|
483
516
|
|
|
484
517
|
Returns a single object summarizing FTS storage for the environment. Useful for "how much disk is FTS costing me" overviews and for spotting reclaimable slack.
|
|
485
518
|
|
|
@@ -492,7 +525,7 @@ Returns a single object summarizing FTS storage for the environment. Useful for
|
|
|
492
525
|
| `slackBytes` | `number` | `diskBytes - payloadBytes`. Free LMDB pages — reclaimable by future writes or `env.compact`. |
|
|
493
526
|
| `indexes` | `array` | Per-index breakdown: `[{ type, name, sizeBytes }, ...]`. |
|
|
494
527
|
|
|
495
|
-
### GET /api/:env/type/:type/fts — list response
|
|
528
|
+
### GET /api[/env/:env]/type/:type/fts — list response
|
|
496
529
|
|
|
497
530
|
Each entry in the returned array includes:
|
|
498
531
|
|
|
@@ -501,8 +534,8 @@ Each entry in the returned array includes:
|
|
|
501
534
|
| `name` | `string` | Index name |
|
|
502
535
|
| `status` | `'creating' \| 'resetting' \| 'ready' \| 'waiting' \| null` | Per-index lifecycle status |
|
|
503
536
|
| `config` | `object \| null` | Index configuration as registered |
|
|
504
|
-
| `created` | `number \| null` |
|
|
505
|
-
| `updated` | `number \| null` |
|
|
537
|
+
| `created` | `number \| null` | Wall-clock time (ms) at registration |
|
|
538
|
+
| `updated` | `number \| null` | Wall-clock time (ms) at last config update |
|
|
506
539
|
| `error` | `object \| null` | Last per-index error, if any |
|
|
507
540
|
| `processorState` | `'building' \| 'online' \| 'error' \| 'waiting' \| null` | State of the background FTS processor for this type. `null` if no processor is running. |
|
|
508
541
|
| `lag` | `number \| null` | Number of writes the processor has not yet indexed. `0` = fully caught up. `null` if no processor. |
|
|
@@ -510,9 +543,9 @@ Each entry in the returned array includes:
|
|
|
510
543
|
|
|
511
544
|
`processorState` and `lag` are per-type fields — they reflect the single background processor that drives all FTS indexes on a type and are identical on every entry of the same type.
|
|
512
545
|
|
|
513
|
-
### POST /api/:env/type/:type/fts/flush — flush processor
|
|
546
|
+
### POST /api[/env/:env]/type/:type/fts/flush — flush processor
|
|
514
547
|
|
|
515
|
-
Waits for the background FTS processor to catch up to the current write position for this type, then runs the FTS compactor to roll live-tier entries into the compacted Roaring bitmap tier. Responds `
|
|
548
|
+
Waits for the background FTS processor to catch up to the current write position for this type, then runs the FTS compactor to roll live-tier entries into the compacted Roaring bitmap tier. Responds `200` with `data: null` when fully caught up. This is a no-op if no processor is running or if the processor is already caught up.
|
|
516
549
|
|
|
517
550
|
- **Permission:** `schema:read`
|
|
518
551
|
- **Idempotent:** yes
|
|
@@ -521,17 +554,19 @@ Waits for the background FTS processor to catch up to the current write position
|
|
|
521
554
|
Use this after bulk writes when immediate search consistency is required:
|
|
522
555
|
|
|
523
556
|
```bash
|
|
524
|
-
# Bulk-import docs, then flush
|
|
525
|
-
curl -X POST http://localhost:8080/api/
|
|
557
|
+
# Bulk-import docs (type "articles" registered, FTS index "main" on ["body"]), then flush
|
|
558
|
+
curl -X POST http://localhost:8080/api/transaction \
|
|
526
559
|
-H "Authorization: Bearer token" \
|
|
527
|
-
-
|
|
560
|
+
-H "Content-Type: application/json" \
|
|
561
|
+
-d '{ "operations": [{ "action": "put", "type": "articles", "key": "a1", "value": { "body": "hello" } }] }'
|
|
528
562
|
|
|
529
|
-
curl -X POST http://localhost:8080/api/
|
|
563
|
+
curl -X POST http://localhost:8080/api/type/articles/fts/flush \
|
|
530
564
|
-H "Authorization: Bearer token"
|
|
531
565
|
|
|
532
566
|
# Now search is guaranteed up-to-date
|
|
533
|
-
curl -X POST http://localhost:8080/api/
|
|
567
|
+
curl -X POST http://localhost:8080/api/type/articles/fts/main/search \
|
|
534
568
|
-H "Authorization: Bearer token" \
|
|
569
|
+
-H "Content-Type: application/json" \
|
|
535
570
|
-d '{ "query": "hello" }'
|
|
536
571
|
```
|
|
537
572
|
|
|
@@ -550,30 +585,32 @@ Returns node ID, version, clock, type stats, plugin list, and resolved LMDB opti
|
|
|
550
585
|
## Sync endpoint
|
|
551
586
|
|
|
552
587
|
```http
|
|
553
|
-
|
|
554
|
-
Authorization: Bearer <sync-token>
|
|
555
|
-
```
|
|
556
|
-
|
|
557
|
-
Used by peer nodes during reconciliation. Returns a JSON stream of change objects.
|
|
558
|
-
|
|
559
|
-
```http
|
|
560
|
-
POST /api/sync/join
|
|
561
|
-
Authorization: Bearer <sync-token>
|
|
588
|
+
POST /api/sync/delta
|
|
562
589
|
Content-Type: application/json
|
|
563
590
|
|
|
564
|
-
{ "
|
|
591
|
+
{ "from_clocks": { "default": 120, "~system": 40 }, "limit": 500, "envs": null }
|
|
565
592
|
```
|
|
566
593
|
|
|
594
|
+
Used by peer nodes during reconciliation. Returns `{ clock, clocks, changes }` — up to `limit`
|
|
595
|
+
changes after each env's clock, each tagged with `_env`. (`from_clock: N` is accepted as
|
|
596
|
+
shorthand for `{ default: N }`.)
|
|
597
|
+
|
|
598
|
+
Peers authenticate with Ed25519-signed requests, not a shared token; a node joins once with a
|
|
599
|
+
token or name + password on the remote. To connect this node to another, call
|
|
600
|
+
`POST /api/sync/connect` with `{ "address": "http://node-a:8484", "token": "<raw-token-on-A>" }`.
|
|
601
|
+
`POST /api/sync/join` is the peer-to-peer half of that handshake (body `{ node }`), not something
|
|
602
|
+
you call by hand. See [Auth and Sync](./auth-and-sync.md#part-2--sync) for all sync routes.
|
|
603
|
+
|
|
567
604
|
---
|
|
568
605
|
|
|
569
606
|
## File endpoints
|
|
570
607
|
|
|
571
608
|
```http
|
|
572
|
-
POST /api/files
|
|
573
|
-
GET /api/files/:id
|
|
574
|
-
GET /api/files/:id/
|
|
575
|
-
DELETE /api/files/:id
|
|
576
|
-
GET /api/files
|
|
609
|
+
POST /api[/env/:env]/files?path=/docs/a.pdf → upload — raw request body (not multipart); Content-Length required, Content-Type = MIME → 201 + record
|
|
610
|
+
GET /api[/env/:env]/files/:id → download file (streams blob bytes; ?inline=1 for preview)
|
|
611
|
+
GET /api[/env/:env]/files/:id/status → metadata + blob status (no body stream)
|
|
612
|
+
DELETE /api[/env/:env]/files/:id → remove file
|
|
613
|
+
GET /api[/env/:env]/files?path=/docs/ → list file records under a path prefix
|
|
577
614
|
```
|
|
578
615
|
|
|
579
616
|
---
|
|
@@ -766,19 +803,23 @@ When you bring your own server, don't call `okdb.http.listen()`. OKDB's routes a
|
|
|
766
803
|
:::
|
|
767
804
|
|
|
768
805
|
:::note
|
|
769
|
-
`okdb.http.handle()` still runs all registered middleware and guards
|
|
806
|
+
`okdb.http.handle()` still runs all registered middleware and guards — the `/api/*` and `/admin/*` auth guards (Bearer token or `okdb_session` cookie) apply regardless of which HTTP framework is in front.
|
|
770
807
|
:::
|
|
771
808
|
|
|
772
809
|
---
|
|
773
810
|
|
|
774
811
|
## Admin UI
|
|
775
812
|
|
|
776
|
-
|
|
813
|
+
The admin UI is served at (`/` and `/admin` redirect there; pass `admin: false` to the
|
|
814
|
+
constructor to disable it):
|
|
777
815
|
|
|
778
816
|
```
|
|
779
817
|
http://localhost:8080/admin/index.html
|
|
780
818
|
```
|
|
781
819
|
|
|
820
|
+
It requires a signed-in session (token name + password at `/admin/login`) or a Bearer token,
|
|
821
|
+
unless the client is in open mode.
|
|
822
|
+
|
|
782
823
|
It provides:
|
|
783
824
|
|
|
784
825
|
- Type and record browser
|
package/docs/http-cluster.md
CHANGED
|
@@ -24,13 +24,13 @@ workers (this is the same "N capable nodes" shape, just supervised by your balan
|
|
|
24
24
|
```
|
|
25
25
|
┌──────────────────────────────────────────────┐
|
|
26
26
|
│ supervisor (PASSIVE — processors:false, │
|
|
27
|
-
│ engines:false, compaction:
|
|
27
|
+
│ engines:false, compaction:false) │
|
|
28
28
|
│ • forks/respawns/decommissions the workers │
|
|
29
29
|
│ • owns the ~processes registry (publishes a │
|
|
30
30
|
│ row per worker; workers are registry-passive)│
|
|
31
31
|
│ • opens its OKDB BEFORE forking (seeds the │
|
|
32
32
|
│ shared __tokenSecret so workers agree) │
|
|
33
|
-
│ • HTTP
|
|
33
|
+
│ • no HTTP server; does NOT process │
|
|
34
34
|
└───────────────┬──────────────────────────────┘
|
|
35
35
|
│ forks N
|
|
36
36
|
┌───────────────┬───────┴───────┬───────────────┐
|
|
@@ -51,13 +51,35 @@ workers (this is the same "N capable nodes" shape, just supervised by your balan
|
|
|
51
51
|
reports its processing facet to the supervisor over IPC so cluster processing stays visible).
|
|
52
52
|
- **Supervisor = passive.** It opens a passive OKDB (`processors:false`, `engines:false`,
|
|
53
53
|
`compaction:false`) only to seed the shared `__tokenSecret` before forking and to own the
|
|
54
|
-
registry. It
|
|
54
|
+
registry. It runs no HTTP server and never processes — but on Linux/macOS it **does** sit in
|
|
55
|
+
the connection-accept path (see [Connection distribution](#connection-distribution)).
|
|
55
56
|
- **`workers:1`** (or `--no-cluster`) is byte-identical to the single-process path: one full
|
|
56
57
|
capable process serves + processes.
|
|
57
58
|
|
|
58
59
|
A write on any worker is indexed by whichever worker holds the lease (cross-process POKE + the
|
|
59
60
|
shared changelog); bounded quanta keep that indexing from monopolizing the holder's loop.
|
|
60
61
|
|
|
62
|
+
### Connection distribution
|
|
63
|
+
|
|
64
|
+
okdb uses Node `cluster`'s default scheduling. On Linux and macOS that is **round-robin
|
|
65
|
+
(`SCHED_RR`)**: the supervisor process owns the listen socket, `accept()`s every **new**
|
|
66
|
+
connection on its own event loop, and hands the socket to a worker over IPC. Consequences:
|
|
67
|
+
|
|
68
|
+
- Workers are isolated from each other and from the supervisor for **established** connections —
|
|
69
|
+
requests on a kept-alive connection go straight to its worker.
|
|
70
|
+
- Workers are **not** isolated from the supervisor for **new** connections: if the supervisor's
|
|
71
|
+
loop is blocked, every new connection waits until it frees up (measured: a 1.5 s busy-loop in
|
|
72
|
+
the supervisor delayed a new connection by ~1.4 s with 4 idle workers). The supervisor is kept
|
|
73
|
+
thin for this reason — it only forks/respawns workers, relays IPC, and publishes registry rows.
|
|
74
|
+
- Distribution is even (strict rotation).
|
|
75
|
+
|
|
76
|
+
Operators who prefer the OS to distribute connections can set Node's own
|
|
77
|
+
`NODE_CLUSTER_SCHED_POLICY=none` (`SCHED_NONE`) in the `okdb` process environment: each worker
|
|
78
|
+
`accept()`s directly, so a busy supervisor no longer delays new connections — at the cost of
|
|
79
|
+
uneven distribution (measured on Linux with 4 idle workers: 42–209 of 400 serial connections per
|
|
80
|
+
worker; under load the kernel favours whichever workers are waiting in `accept()`, which can
|
|
81
|
+
skew further). Windows always uses `SCHED_NONE`.
|
|
82
|
+
|
|
61
83
|
---
|
|
62
84
|
|
|
63
85
|
## The `workers` knob
|
|
@@ -150,8 +172,8 @@ client on a given worker will and won't see:
|
|
|
150
172
|
ephemeral processing events (view-rebuild progress, FTS/index lifecycle, processor lifecycle) to
|
|
151
173
|
**its own** SSE. The cluster-wide picture is **read** from the durable `~processes` registry:
|
|
152
174
|
each worker reports its processing facet to the supervisor over **cluster IPC**, the supervisor
|
|
153
|
-
stamps it onto the worker's registry row, and any node serves `/api/
|
|
154
|
-
`/api/
|
|
175
|
+
stamps it onto the worker's registry row, and any node serves `/api/processors/status` (and
|
|
176
|
+
its deprecated alias `/api/processing/status`) and `/api/cluster/status` from that shared registry. So a processing
|
|
155
177
|
event on worker A is not mirrored into worker B's live SSE, but A's processor **state** is
|
|
156
178
|
visible cluster-wide via the registry-sourced status routes.
|
|
157
179
|
- **Worker logs are forwarded to the supervisor's log pipeline** over cluster IPC (tagged per
|
|
@@ -198,15 +220,15 @@ const cluster = require('node:cluster');
|
|
|
198
220
|
if (cluster.isPrimary) {
|
|
199
221
|
// Thin supervisor: open a passive node BEFORE forking to seed the shared __tokenSecret,
|
|
200
222
|
// then fork N capable workers. It does not serve or process.
|
|
201
|
-
const supervisor = new OKDB(dbPath, { processors: false,
|
|
223
|
+
const supervisor = new OKDB(dbPath, { processors: false, engines: false, compaction: false });
|
|
202
224
|
await supervisor.open();
|
|
203
225
|
for (let i = 0; i < 4; i++) cluster.fork();
|
|
204
226
|
} else {
|
|
205
227
|
// Each worker = an identical CAPABLE node: serves HTTP AND processes (claims leases,
|
|
206
|
-
//
|
|
228
|
+
// drains them on its own loop in bounded quanta). The lease distributes processing across them.
|
|
207
229
|
const w = new OKDB(dbPath, { processors: true });
|
|
208
230
|
await w.open();
|
|
209
|
-
w.http.listen(port); // shared socket via Node cluster; bus
|
|
231
|
+
w.http.listen(port); // shared socket via Node cluster; bus is on (native shmbuf)
|
|
210
232
|
}
|
|
211
233
|
```
|
|
212
234
|
|
package/docs/indexes.md
CHANGED
|
@@ -52,7 +52,8 @@ Check status without waiting:
|
|
|
52
52
|
|
|
53
53
|
```javascript
|
|
54
54
|
okdb.getIndexStatus('articles', ['author']);
|
|
55
|
-
// → 'creating' | 'resetting' | 'ready'
|
|
55
|
+
// → 'creating' | 'resetting' | 'waiting' | 'ready' | 'dropping' | 'error'
|
|
56
|
+
// ('error' = the build failed; indexReady() rejects instead of hanging, the next reset/open retries)
|
|
56
57
|
```
|
|
57
58
|
|
|
58
59
|
---
|
|
@@ -102,21 +103,21 @@ The trailing `null` sentinel in the LMDB key format ensures that a prefix scan o
|
|
|
102
103
|
|
|
103
104
|
## Counting without loading records
|
|
104
105
|
|
|
105
|
-
`countByIndex` counts matching index entries without touching the data store
|
|
106
|
+
`countByIndex` counts matching index entries without touching the data store. It takes `start`/`end` (end exclusive — hence the `HIGH_SENTINEL` bound below) or, equivalently, `prefix`:
|
|
106
107
|
|
|
107
108
|
```javascript
|
|
108
109
|
await okdb.registerIndex('orders', ['status']);
|
|
109
110
|
|
|
110
111
|
const pending = okdb.countByIndex('orders', ['status'], {
|
|
111
112
|
start: ['pending'],
|
|
112
|
-
end: ['pending',
|
|
113
|
+
end: ['pending', OKDB.HIGH_SENTINEL],
|
|
113
114
|
});
|
|
114
115
|
|
|
115
116
|
// Compound index
|
|
116
117
|
await okdb.registerIndex('orders', ['status', 'createdAt']);
|
|
117
118
|
const open = okdb.countByIndex('orders', ['status', 'createdAt'], {
|
|
118
119
|
start: ['open'],
|
|
119
|
-
end: ['open',
|
|
120
|
+
end: ['open', OKDB.HIGH_SENTINEL],
|
|
120
121
|
});
|
|
121
122
|
```
|
|
122
123
|
|
package/docs/logging.md
CHANGED
|
@@ -107,6 +107,24 @@ A circular buffer of recent log entries is available for inspection:
|
|
|
107
107
|
okdb.logs; // array of recent entries, newest last
|
|
108
108
|
```
|
|
109
109
|
|
|
110
|
+
### Persisted history — `GET /api/system/logs`
|
|
111
|
+
|
|
112
|
+
Every non-debug entry is also written (batched, ≤1 commit/s) to the `~log` env's
|
|
113
|
+
`~log_entry` type, kept for `log.retainDays` (default 2) via TTL. The admin
|
|
114
|
+
**System → Logs → History** tab reads it through:
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
GET /api/system/logs?from=<ms>&to=<ms>&level=error,warn&feature=queue&node=<id>&limit=50&cursor=<next_cursor>
|
|
118
|
+
→ { data: { entries: [{ key, ts, level, msg, feature, node, context }], next_cursor } }
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Entries come newest first. The read is **bounded**: it walks a ts-ordered index in reverse
|
|
122
|
+
(the `[level, ts]` / `[node, ts]` / `[feature, ts]` index when that filter has a single
|
|
123
|
+
value) and examines at most 5 000 rows per call, so a sparse filter can return a short — even
|
|
124
|
+
empty — page with a non-null `next_cursor`. Keep passing `next_cursor` back as `cursor`
|
|
125
|
+
until it is `null`. The cursor is opaque (`"<ts>:<key>"`); a bare numeric cursor from older
|
|
126
|
+
callers still means "strictly older than this ts". `limit` defaults to 50, max 200.
|
|
127
|
+
|
|
110
128
|
---
|
|
111
129
|
|
|
112
130
|
## `attachConsole()` — Console Output
|