@kedem/okdb 2.3.3 → 2.3.4
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 +59 -0
- package/algorithm-worker-thread.js +1 -1
- package/bin/okdb.js +1 -1
- package/docs/auth-and-sync.md +170 -463
- package/docs/auth-permissions.md +3 -1
- package/docs/deployment.md +8 -0
- package/docs/embeddings.md +1 -0
- package/docs/files.md +176 -51
- package/docs/functions.md +1 -1
- package/docs/getting-started.md +40 -13
- package/docs/http-api.md +12 -3
- package/docs/http-cluster.md +25 -0
- package/docs/resolved-fields.md +2 -0
- 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/files/parts/files-file-list.ok.js +1 -1
- package/public/sections/files/parts/files-preview.ok.js +1 -0
- package/types/features/files.d.ts +38 -3
- package/types/index.d.ts +18 -3
package/docs/auth-permissions.md
CHANGED
|
@@ -133,9 +133,11 @@ Write-side operations (`write`, `work`, `run`, `peer`) require `protected:write`
|
|
|
133
133
|
### Cluster peer node
|
|
134
134
|
|
|
135
135
|
```json
|
|
136
|
-
{ "permissions": ["sync:peer"] }
|
|
136
|
+
{ "permissions": ["sync:read", "sync:peer"] }
|
|
137
137
|
```
|
|
138
138
|
|
|
139
|
+
`join()` first reads `GET /api/sync/info` (`sync:read`); `sync:peer` alone does not imply it.
|
|
140
|
+
|
|
139
141
|
## Adding a new permission
|
|
140
142
|
|
|
141
143
|
1. Add the namespace/operation to `src/features/auth/okdb-auth-namespaces.js` in `NAMESPACES`.
|
package/docs/deployment.md
CHANGED
|
@@ -81,6 +81,14 @@ front.http.listen(8080);
|
|
|
81
81
|
const worker = new OKDB(path, { processors: true }); // engines/compaction default true
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
+
With the CLI, the serving node takes the same flags from its config file (they apply to the
|
|
85
|
+
single process and to every cluster worker; see [HTTP Clustering](./http-cluster.md#role-flags-in-kdbconfig)):
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
// front.kdbconfig — okdb --config front.kdbconfig --path /srv/okdb --port 8080
|
|
89
|
+
{ "processors": false, "engines": false, "compaction": false }
|
|
90
|
+
```
|
|
91
|
+
|
|
84
92
|
Workers need no ports: coordination is the shared LMDB + the UDP bus. Placement and respawn
|
|
85
93
|
are your launcher's job (systemd, pm2, docker, k8s, a PowerShell script — anything that can
|
|
86
94
|
start N processes).
|
package/docs/embeddings.md
CHANGED
|
@@ -323,6 +323,7 @@ Every document is reconciled against the vectors actually stored for it: the tex
|
|
|
323
323
|
- **Retries resume**: vectors that landed before a failure are kept and skipped next time.
|
|
324
324
|
- **Requests are batched**: texts are sent `batch` at a time (default 32), across documents in inline mode.
|
|
325
325
|
- **Identical chunks across documents** (boilerplate) embed once per process while they stay in a bounded LRU (`cache`, default 1024 entries; `0` disables).
|
|
326
|
+
- **App registrations missing in a process hold the work, never fail it.** Custom preparers (`registerPreparer`), chunk strategies (`registerChunkStrategy`) and embedder factories (`registerEmbedderFactory`) are code, so every process that runs engines/processors on the store must register them. A process that lacks one — or whose embedder engine is not running — leaves the doc `pending`: the inline drain is held (and hands its lease to a peer that wants it), a queue job is re-queued without using a try, and `indexer.stats().waiting` reports `{ reason: 'REGISTRATION_MISSING', kind: 'preparer' | 'chunk_strategy', name }` or `{ reason: 'EMBEDDER_NOT_RUNNING' }` (plus a warning in the log). The work completes once the registration arrives in that process or a process that has it picks it up. okdb can't tell a misspelled built-in name from one registered elsewhere, so a typo holds too — the `waiting.error` message lists the built-ins. Docs marked `failed` for this reason by earlier versions stay failed until `indexer.retryFailed()` (HTTP: `POST /api/env/:env/type/:type/pipelines/:pipeline/retry-failed`).
|
|
326
327
|
|
|
327
328
|
| Option | Default | Description |
|
|
328
329
|
| ---------- | ------- | --------------------------------------------------------------- |
|
package/docs/files.md
CHANGED
|
@@ -1,104 +1,146 @@
|
|
|
1
1
|
# Files
|
|
2
2
|
|
|
3
|
-
OKDB includes content-addressable blob storage integrated with the database.
|
|
3
|
+
OKDB includes content-addressable blob storage integrated with the database. File bytes are stored once per SHA-256 hash on disk; each file is a metadata record in the `~files` OKDB type.
|
|
4
|
+
|
|
5
|
+
`okdb.files` is the default environment's files API; every user environment has its own at `env.files` (see [Files per environment](#files-per-environment)).
|
|
4
6
|
|
|
5
7
|
---
|
|
6
8
|
|
|
7
|
-
##
|
|
9
|
+
## Uploading a file
|
|
10
|
+
|
|
11
|
+
`upload()` takes a readable stream and an id you choose:
|
|
8
12
|
|
|
9
13
|
```javascript
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
//
|
|
18
|
-
const stream = fs.createReadStream('/local/file.jpg');
|
|
19
|
-
const file = await okdb.files.put(stream, {
|
|
20
|
-
path: '/avatars/alice.jpg',
|
|
21
|
-
mime: 'image/jpeg',
|
|
22
|
-
id: 'avatar-alice', // optional explicit ID (UUID generated if omitted)
|
|
14
|
+
const fs = require('fs');
|
|
15
|
+
const { Readable } = require('stream');
|
|
16
|
+
|
|
17
|
+
const record = await okdb.files.upload({
|
|
18
|
+
id: 'avatar-alice', // required — the ~files key
|
|
19
|
+
stream: fs.createReadStream('/local/alice.jpg'), // required
|
|
20
|
+
mime: 'image/jpeg', // default 'application/octet-stream'
|
|
21
|
+
path: '/avatars/alice.jpg', // optional, full path incl. filename
|
|
23
22
|
});
|
|
23
|
+
// record = { id, hash, size, mime, path, createdAt }
|
|
24
|
+
|
|
25
|
+
// From a Buffer
|
|
26
|
+
await okdb.files.upload({ id: 'notes-1', stream: Readable.from([buffer]), mime: 'text/plain', path: '/notes/1.txt' });
|
|
24
27
|
```
|
|
25
28
|
|
|
26
|
-
The
|
|
29
|
+
The bytes are streamed to disk while hashed, then stored at `<okdb-root>/~blobs/<first2>/<rest>` (the SHA-256 hex). Uploading the same bytes again stores them once — the new record points at the existing blob and its reference count goes up. Uploading again under an existing `id` replaces the file: the record is overwritten and the previous blob's reference is released (its file is deleted once nothing else references it). Re-uploading the same bytes under the same `id` leaves the reference count unchanged.
|
|
30
|
+
|
|
31
|
+
Pass `txn` to make the metadata write part of a transaction: the record is written with the transaction, the reference counts (including the release of a replaced blob) are updated after it commits, and a newly written blob is deleted if it rolls back — a rollback leaves the previous blob untouched.
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
const txn = okdb.transaction();
|
|
35
|
+
await okdb.files.upload({ id: 'invoice-7', stream, mime: 'application/pdf', path: '/invoices/7.pdf', txn });
|
|
36
|
+
txn.put('invoices', '7', { file: 'invoice-7', total: 120 });
|
|
37
|
+
await txn.commit();
|
|
38
|
+
```
|
|
27
39
|
|
|
28
40
|
---
|
|
29
41
|
|
|
30
42
|
## Reading a file
|
|
31
43
|
|
|
32
44
|
```javascript
|
|
33
|
-
//
|
|
45
|
+
// Metadata (sync) — the ~files record or null
|
|
34
46
|
const meta = okdb.files.get('avatar-alice');
|
|
35
|
-
// { id, hash, size, mime, path, createdAt }
|
|
36
47
|
|
|
37
|
-
//
|
|
48
|
+
// The whole blob as a Buffer
|
|
38
49
|
const buf = await okdb.files.read('avatar-alice');
|
|
39
50
|
|
|
40
|
-
// Stream
|
|
41
|
-
const stream = okdb.files.stream('avatar-alice');
|
|
51
|
+
// Stream it
|
|
52
|
+
const { stream, record } = await okdb.files.stream('avatar-alice');
|
|
42
53
|
stream.pipe(response);
|
|
43
54
|
```
|
|
44
55
|
|
|
56
|
+
`read()` and `stream()` reject with `status: 404` when the id is unknown, or when the record exists but its blob is not on this node (`Blob missing for file: <id>`). `get()`, `read()` and `stream()` never create the `~files` type.
|
|
57
|
+
|
|
45
58
|
---
|
|
46
59
|
|
|
47
60
|
## Deleting a file
|
|
48
61
|
|
|
49
62
|
```javascript
|
|
50
63
|
await okdb.files.remove('avatar-alice');
|
|
64
|
+
await okdb.files.remove('invoice-7', { txn }); // inside a transaction
|
|
51
65
|
```
|
|
52
66
|
|
|
53
|
-
|
|
67
|
+
`remove()` deletes the metadata record and decrements the blob's reference count; the blob file is deleted when no `~files` record references that hash any more. It rejects with `status: 404` when the id is unknown.
|
|
54
68
|
|
|
55
69
|
---
|
|
56
70
|
|
|
57
71
|
## Listing files
|
|
58
72
|
|
|
59
73
|
```javascript
|
|
60
|
-
//
|
|
61
|
-
|
|
62
|
-
console.log(meta.path, meta.size, meta.hash);
|
|
63
|
-
}
|
|
74
|
+
// Everything (up to `limit`, default 1000)
|
|
75
|
+
const all = await okdb.files.listPath('/');
|
|
64
76
|
|
|
65
|
-
//
|
|
66
|
-
|
|
77
|
+
// Under a directory prefix
|
|
78
|
+
const docs = await okdb.files.listPath('/docs/'); // recursive by default
|
|
79
|
+
const top = await okdb.files.listPath('/docs', { recursive: false, limit: 100 });
|
|
67
80
|
```
|
|
68
81
|
|
|
82
|
+
`listPath()` returns an array of `~files` records whose `path` is under the prefix. `~files` has secondary indexes on `path` and `hash`, so the ordinary query API works too — e.g. `okdb.query('~files', { hash })`.
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Events
|
|
87
|
+
|
|
88
|
+
Uploads and removals made without `txn` emit `files:uploaded` (`{ id, hash, size, path }`) and `files:removed` (`{ id, hash }`) on `okdb.events`. HTTP uploads also emit `files:http:uploaded`.
|
|
89
|
+
|
|
69
90
|
---
|
|
70
91
|
|
|
71
|
-
## HTTP
|
|
92
|
+
## HTTP API
|
|
93
|
+
|
|
94
|
+
When the HTTP server is running, file routes are mounted for the default environment at `/api/files` and for any environment at `/api/env/:env/files`:
|
|
95
|
+
|
|
96
|
+
| Method | Path | Description |
|
|
97
|
+
| -------- | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
98
|
+
| `POST` | `/api/files?path=…` | Upload. The raw request body is the file; `Content-Type` becomes `mime`; `Content-Length` is required. The id is a generated UUID. → `201 { result: record }` |
|
|
99
|
+
| `GET` | `/api/files` | List. Query: `path` (prefix, default `/`), `recursive` (default `true`), `limit` (default 100, max 10000). → `{ result: [records], meta: { count } }` |
|
|
100
|
+
| `GET` | `/api/files/:id` | Download the bytes (`content-type` from the record, `content-disposition: attachment` with the path's filename) |
|
|
101
|
+
| `GET` | `/api/files/:id?inline=1` | Preview in the browser (`content-disposition: inline`). Only passive media — non-SVG images, audio, video, PDF — keep their type; everything else (HTML, SVG, XML, JS, unknown) is served as `text/plain`, always with `nosniff` and a sandboxing `Content-Security-Policy` |
|
|
102
|
+
| `GET` | `/api/files/:id/status` | Metadata plus `blob: { refs }` |
|
|
103
|
+
| `DELETE` | `/api/files/:id` | Remove → `204` |
|
|
104
|
+
|
|
105
|
+
Blob routes are shared by all environments (blobs are content-addressed):
|
|
106
|
+
|
|
107
|
+
| Method | Path | Description |
|
|
108
|
+
| ------ | ------------------------- | -------------------------------------------------------------------------------------- |
|
|
109
|
+
| `GET` | `/api/files/blobs/status` | The local blob table: `{ hash, refs, nodes, onDisk, sizeBytes }` per blob |
|
|
110
|
+
| `GET` | `/api/files/blobs/:hash` | The raw bytes of one blob (used by peers to replicate blobs) |
|
|
111
|
+
| `POST` | `/api/files/blobs/sync` | Pull missing blobs from sync peers now. Body: `{ peerIds?: string[] }` (`files:write`) |
|
|
72
112
|
|
|
73
|
-
|
|
113
|
+
Downloads honour a single `Range: bytes=…` request (`206`, or `416` when unsatisfiable) for media seeking and partial reads. Reads need the `files:read` permission, writes `files:write`.
|
|
74
114
|
|
|
75
115
|
```bash
|
|
76
|
-
# Upload
|
|
77
|
-
curl -X POST http://localhost:8080/api/files \
|
|
116
|
+
# Upload
|
|
117
|
+
curl -X POST "http://localhost:8080/api/files?path=/docs/report.pdf" \
|
|
78
118
|
-H "Authorization: Bearer my-token" \
|
|
79
|
-
-
|
|
80
|
-
-
|
|
119
|
+
-H "Content-Type: application/pdf" \
|
|
120
|
+
--data-binary @report.pdf
|
|
81
121
|
|
|
82
|
-
# Download by
|
|
83
|
-
curl http://localhost:8080/api/files/
|
|
122
|
+
# Download by id
|
|
123
|
+
curl http://localhost:8080/api/files/3f1c…-uuid \
|
|
84
124
|
-H "Authorization: Bearer my-token" \
|
|
85
|
-
--output
|
|
125
|
+
--output report.pdf
|
|
126
|
+
|
|
127
|
+
# Files of another environment
|
|
128
|
+
curl "http://localhost:8080/api/env/analytics/files?path=/exports/" -H "Authorization: Bearer my-token"
|
|
86
129
|
```
|
|
87
130
|
|
|
88
131
|
---
|
|
89
132
|
|
|
90
133
|
## Files per environment
|
|
91
134
|
|
|
92
|
-
Each OKDB environment has its own `~files` type (metadata lives in that env), but all environments share
|
|
135
|
+
Each OKDB environment has its own `~files` type (metadata lives in that env), but all environments share one blob directory at the OKDB root. This means:
|
|
93
136
|
|
|
94
|
-
-
|
|
137
|
+
- The same bytes stored in `default` and in `analytics` are one file on disk
|
|
95
138
|
- Reference counting tracks how many metadata records point to each hash
|
|
96
139
|
- The blob is only deleted when the ref count drops to zero
|
|
97
140
|
|
|
98
141
|
```javascript
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const file = await analyticsEnv.files.put(buffer, { path: '/exports/data.csv', mime: 'text/csv' });
|
|
142
|
+
const analytics = okdb.env('analytics');
|
|
143
|
+
await analytics.files.upload({ id: 'q3', stream, mime: 'text/csv', path: '/exports/q3.csv' });
|
|
102
144
|
```
|
|
103
145
|
|
|
104
146
|
---
|
|
@@ -106,26 +148,109 @@ const file = await analyticsEnv.files.put(buffer, { path: '/exports/data.csv', m
|
|
|
106
148
|
## Storage layout
|
|
107
149
|
|
|
108
150
|
```
|
|
109
|
-
<okdb-root
|
|
151
|
+
<okdb-root>/~blobs/
|
|
110
152
|
ab/cdef1234... ← blob file (path = first2/rest of SHA-256 hex)
|
|
111
153
|
ff/0123abcd...
|
|
154
|
+
tmp/ ← in-flight uploads
|
|
112
155
|
```
|
|
113
156
|
|
|
114
|
-
In LMDB
|
|
157
|
+
In LMDB:
|
|
115
158
|
|
|
116
159
|
```
|
|
117
|
-
~files
|
|
118
|
-
~file:blob_status
|
|
160
|
+
~files ← metadata records, per env (id → { id, hash, size, mime, path, createdAt })
|
|
161
|
+
~file:blob_status ← ref-counting sub-db on the default env (hash → { refs, nodes })
|
|
119
162
|
```
|
|
120
163
|
|
|
164
|
+
Maintenance helpers: `files.getBlobStatus(hash)` → `{ refs, nodes } | null`, `files.listBlobStatus()` (the blob table), `files.gcOrphanedBlobs()` (deletes blob files whose ref count is 0 or unknown; returns the count).
|
|
165
|
+
|
|
121
166
|
---
|
|
122
167
|
|
|
123
168
|
## Sync
|
|
124
169
|
|
|
125
|
-
`~files` metadata **is
|
|
170
|
+
`~files` metadata **is replicated** across sync peers like any other type. Blob bytes are **not** — they move over HTTP between nodes:
|
|
171
|
+
|
|
172
|
+
- After a local upload, the node asks each peer to pull from it (`POST /api/files/blobs/sync`); the peer then downloads the blobs it lacks.
|
|
173
|
+
- `await okdb.files.syncBlobs({ peerIds? })` pulls every missing blob from the peers now (→ `{ synced, errors }`).
|
|
174
|
+
|
|
175
|
+
So metadata can arrive before the bytes. Until they do, `read()`/`stream()` on that node reject with `Blob missing` (404). Content indexing (below) tries the peers itself.
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## Searching file contents
|
|
180
|
+
|
|
181
|
+
Full-text search and embeddings can index what is **in** the files, not only their paths. Turn it on once per environment:
|
|
182
|
+
|
|
183
|
+
```javascript
|
|
184
|
+
await okdb.files.indexContent(); // or env.files.indexContent({ field, maxBytes })
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
This declares `content` on `~files` as a [resolved field](./resolved-fields.md): nothing is copied into the database — when an index needs a file's content, okdb reads the blob and runs a matching **extractor** to turn the bytes into text. Then index `~files` like any type:
|
|
188
|
+
|
|
189
|
+
```javascript
|
|
190
|
+
// Full-text search over path + content
|
|
191
|
+
await okdb.fts.ensure('~files', 'text', { fields: ['path', 'content'] });
|
|
192
|
+
const hits = okdb.ftsQuery('~files', 'text', 'quarterly revenue');
|
|
193
|
+
for (const { key, value } of hits) console.log(key, value.path);
|
|
194
|
+
|
|
195
|
+
// Semantic search
|
|
196
|
+
const pipeline = await okdb.embeddings.createPipeline('file-search', {
|
|
197
|
+
source_type: '~files',
|
|
198
|
+
field: 'content',
|
|
199
|
+
dims: 1024,
|
|
200
|
+
chunk: { strategy: 'paragraph' },
|
|
201
|
+
embedder: { type: 'ollama', model: 'mxbai-embed-large', url: 'http://localhost:11434' },
|
|
202
|
+
});
|
|
203
|
+
const similar = await pipeline.api.search('how do refunds work?', { limit: 5 });
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Uploads and removals re-index through the normal change feed: a new file is indexed when it lands, and `remove()` drops it from both indexes.
|
|
207
|
+
|
|
208
|
+
Options:
|
|
209
|
+
|
|
210
|
+
| option | default | meaning |
|
|
211
|
+
| ---------- | ----------- | ----------------------------------------------------------------- |
|
|
212
|
+
| `field` | `'content'` | the resolved field name on `~files` |
|
|
213
|
+
| `maxBytes` | 16 MiB | larger files get no content (they stay findable by stored fields) |
|
|
214
|
+
|
|
215
|
+
The setting is durable: every process that opens the store — a restart, a second process on the same path, a clustered worker — serves the built-in resolver on its own; you don't call `indexContent()` again. `env.unresolveField('~files', 'content')` turns it off.
|
|
216
|
+
|
|
217
|
+
### Extractors
|
|
218
|
+
|
|
219
|
+
Built in: `text/*`, `application/json`, `application/xml`, `application/javascript`, `*+json` and `*+xml` are decoded as UTF-8. Nothing else is built in — okdb ships no PDF/Office parsers. For other formats, register an extractor:
|
|
220
|
+
|
|
221
|
+
```javascript
|
|
222
|
+
// Your choice of parser — okdb has no dependency on it.
|
|
223
|
+
const pdfToText = require('./my-pdf-to-text');
|
|
224
|
+
|
|
225
|
+
okdb.files.registerExtractor('application/pdf', async (buffer, record) => {
|
|
226
|
+
return await pdfToText(buffer); // string, or null for "no content"
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// A wildcard or a predicate on the record also works
|
|
230
|
+
okdb.files.registerExtractor('application/vnd.openxmlformats-officedocument.*', docxToText);
|
|
231
|
+
okdb.files.registerExtractor(
|
|
232
|
+
(record) => record.path.endsWith('.log'),
|
|
233
|
+
(buf) => buf.toString('latin1'),
|
|
234
|
+
);
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
- `match` is a mime (`'application/pdf'`), a wildcard (`'text/*'`, `'*+json'`), or a predicate `(record) => boolean`. Mime parameters are ignored (`text/plain; charset=utf-8` matches `text/plain`).
|
|
238
|
+
- `fn(buffer, record)` returns the text (`string`), or `null` for no content; it may be async. Throwing fails that one file (see below).
|
|
239
|
+
- Later registrations win over earlier ones and over the built-ins. `registerExtractor` returns an unregister function.
|
|
240
|
+
- Extractors apply to every environment of that OKDB instance.
|
|
241
|
+
|
|
242
|
+
**Extractors are code, so register them in every process that runs FTS or embeddings processors** — the same rule as for [resolvers](./resolved-fields.md#every-process-that-indexes-needs-the-resolver). The built-in text extractor needs nothing; a process without your PDF extractor simply treats PDFs as having no content.
|
|
243
|
+
|
|
244
|
+
### What gets content
|
|
245
|
+
|
|
246
|
+
| file | indexed as |
|
|
247
|
+
| ------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
|
|
248
|
+
| a matching extractor returned text | its content |
|
|
249
|
+
| no extractor matches its mime (e.g. images) | no `content` — still findable by stored fields (`path`, …); embeddings mark it `empty` |
|
|
250
|
+
| larger than `maxBytes` | no `content` (the blob is not read) |
|
|
251
|
+
| the extractor returned `null` | no `content` |
|
|
252
|
+
| the extractor threw | an error for that file only: FTS keeps its previous postings, embeddings marks it `failed` (retryable) |
|
|
126
253
|
|
|
127
|
-
|
|
254
|
+
### Blob not on this node yet
|
|
128
255
|
|
|
129
|
-
|
|
130
|
-
Blob sync is pull-based. A node will fetch the blob from a peer only when a consumer requests it and the local blob is missing.
|
|
131
|
-
:::
|
|
256
|
+
When metadata has replicated but the bytes haven't, the resolver first tries to pull the blob from the sync peers (the same blob transfer `syncBlobs()` uses). If no peer has it, or no peers are configured, it fails that file with a retryable `FILE_BLOB_MISSING` error — per the resolver contract, FTS keeps the file's previous postings and embeddings marks it `failed` (retryable), rather than indexing it as empty.
|
package/docs/functions.md
CHANGED
|
@@ -278,7 +278,7 @@ Change record notes:
|
|
|
278
278
|
- `transaction(options)` — low-level transaction object
|
|
279
279
|
- `txn(workOrOps, options?)` — convenience write-focused transaction helper
|
|
280
280
|
- `queue` — queue feature for this env
|
|
281
|
-
- `files` — files feature for this env
|
|
281
|
+
- `files` — files feature for this env: `upload`, `stream`, `read`, `remove`, `get`, `listPath`. `read(id)` resolves the whole blob as a Buffer (rejects with `status: 404` for an unknown id). A function's return value is structured-cloned out of the sandbox and stored as JSON, so convert bytes before returning them — e.g. `buf.toString('utf8')` or `buf.toString('base64')`; a raw Buffer comes back as an index-keyed object.
|
|
282
282
|
|
|
283
283
|
Example:
|
|
284
284
|
|
package/docs/getting-started.md
CHANGED
|
@@ -47,21 +47,19 @@ const okdb = new OKDB('./mydb', {
|
|
|
47
47
|
// AES-256 encryption key (optional)
|
|
48
48
|
encryptionKey: undefined,
|
|
49
49
|
|
|
50
|
-
// HTTP
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
},
|
|
50
|
+
// HTTP auth (REST API + admin UI) — see "Authentication" below
|
|
51
|
+
auth: {
|
|
52
|
+
// Open mode: trust these clients without a token. true = localhost only;
|
|
53
|
+
// or an IP / CIDR / '*' string or array, e.g. ['127.0.0.1', '192.168.1.0/24'].
|
|
54
|
+
// Default false = secure (every request needs a token). CLI: --open [ip ...]
|
|
55
|
+
open: false,
|
|
56
|
+
// Session tokens issued at login: HMAC secret (generated and persisted in the
|
|
57
|
+
// store when unset) and TTL in ms
|
|
58
|
+
token: { secret: undefined, ttl: 3_600_000 },
|
|
59
|
+
session: { secure: false, sameSite: 'Lax' }, // session cookie flags
|
|
61
60
|
},
|
|
62
61
|
sync: {
|
|
63
|
-
|
|
64
|
-
address: 'http://localhost:8080', // this node's public address
|
|
62
|
+
address: 'http://localhost:8080', // this node's public sync address
|
|
65
63
|
},
|
|
66
64
|
|
|
67
65
|
// Role flags (okdb 2.0) — what background work THIS process runs.
|
|
@@ -77,6 +75,35 @@ const okdb = new OKDB('./mydb', {
|
|
|
77
75
|
See [Roles & Deployment](./deployment.md) for what the role flags mean and how to run
|
|
78
76
|
multi-process topologies (N capable nodes, dedicated workers + passive serving nodes).
|
|
79
77
|
|
|
78
|
+
### Authentication
|
|
79
|
+
|
|
80
|
+
There are no passwords or API keys in the constructor options: credentials are **tokens** stored
|
|
81
|
+
in the database (the `~tokens` type in `~system`, hashed).
|
|
82
|
+
|
|
83
|
+
- **Secure mode (the default).** Every HTTP request needs a token: send it as
|
|
84
|
+
`Authorization: Bearer <token>`, or log in to the admin UI with a token's name + password.
|
|
85
|
+
- **Bootstrap window.** While `~tokens` is empty, only **localhost** is accepted (with full
|
|
86
|
+
access) and every other client is refused — so a fresh node is usable locally but closed to
|
|
87
|
+
the network until you create the first token.
|
|
88
|
+
- **Creating tokens.** From the CLI, with direct access to the store (no HTTP needed):
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
okdb token create --name admin --password 's3cret' --permissions '*'
|
|
92
|
+
okdb token create --label 'ci reader' --permissions 'data:read' # prints the raw token once
|
|
93
|
+
okdb token list
|
|
94
|
+
okdb token revoke <id>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
or from the admin UI / `POST /api/auth/tokens` (from localhost during the bootstrap window, or
|
|
98
|
+
as an admin).
|
|
99
|
+
|
|
100
|
+
- **Open mode** skips authentication for trusted clients: `auth: { open: true }` (localhost) or
|
|
101
|
+
a list of IPs/CIDRs, `'*'` for everyone — the CLI's `--open [ip ...]`. okdb logs a warning at
|
|
102
|
+
startup while it is on.
|
|
103
|
+
|
|
104
|
+
See [Auth & Sync](./auth-and-sync.md) and [Auth permissions](./auth-permissions.md) for the
|
|
105
|
+
permission model.
|
|
106
|
+
|
|
80
107
|
---
|
|
81
108
|
|
|
82
109
|
## Your first type
|
package/docs/http-api.md
CHANGED
|
@@ -51,11 +51,20 @@ In practice that means:
|
|
|
51
51
|
## Starting the server
|
|
52
52
|
|
|
53
53
|
```javascript
|
|
54
|
-
okdb.http.listen(8080);
|
|
55
|
-
//
|
|
56
|
-
okdb.http.listen(8080, '
|
|
54
|
+
okdb.http.listen(8080); // all interfaces (Node's default)
|
|
55
|
+
// bind one address only:
|
|
56
|
+
okdb.http.listen(8080, { host: '127.0.0.1' }); // a string 2nd argument is shorthand for { host }
|
|
57
|
+
// bind several — one server per address, all sharing one request handler:
|
|
58
|
+
okdb.http.listen(8080, { host: ['127.0.0.1', '10.0.0.5'] });
|
|
57
59
|
```
|
|
58
60
|
|
|
61
|
+
`listen()` returns the Node `http.Server`. With an array it returns the server bound to the
|
|
62
|
+
**first** address; every server is on `okdb.http.servers`, an `'error'` from any of them is
|
|
63
|
+
re-emitted on the returned one, and `okdb.http.close()` closes them all. The process registry's
|
|
64
|
+
`listenAddr` shows the bound address(es) (`:8080` for all interfaces, else `127.0.0.1:8080, …`).
|
|
65
|
+
The CLI takes the same value from its config file: `{ "http": { "host": "127.0.0.1" } }` (string
|
|
66
|
+
or array; single-process and every cluster worker). There is no `--host` flag.
|
|
67
|
+
|
|
59
68
|
The HTTP server is optional. You can use OKDB entirely in-process without it.
|
|
60
69
|
|
|
61
70
|
---
|
package/docs/http-cluster.md
CHANGED
|
@@ -88,6 +88,31 @@ OKDB_HTTP_WORKERS=3 okdb # 3 workers
|
|
|
88
88
|
{ "http": { "workers": 4 } }
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
+
### Bind address: `http.host`
|
|
92
|
+
|
|
93
|
+
By default the CLI listens on every interface. `http.host` (next to `http.workers`) binds the API
|
|
94
|
+
to one address or an array of them — in single-process mode and in every cluster worker; the
|
|
95
|
+
registry's `listenAddr` shows it. There is no `--host` flag.
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
// .kdbconfig — loopback only (e.g. behind a local reverse proxy)
|
|
99
|
+
{ "http": { "host": "127.0.0.1" } }
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Role flags in `.kdbconfig`
|
|
103
|
+
|
|
104
|
+
The config file also takes the constructor role flags as top-level booleans — the same names and
|
|
105
|
+
semantics as `new OKDB(path, { processors, engines, compaction })` (see
|
|
106
|
+
[Roles & Deployment](./deployment.md)). They apply to the single-process node and to **every**
|
|
107
|
+
forked worker; absent keys keep the constructor default (`true`), and a non-boolean value is a
|
|
108
|
+
startup error. (The supervisor is always passive, whatever the config says.) There is no CLI
|
|
109
|
+
flag for them.
|
|
110
|
+
|
|
111
|
+
```json
|
|
112
|
+
// .kdbconfig — a passive serving node: serves HTTP, never claims a lease, never compacts
|
|
113
|
+
{ "processors": false, "engines": false, "compaction": false }
|
|
114
|
+
```
|
|
115
|
+
|
|
91
116
|
---
|
|
92
117
|
|
|
93
118
|
## shmbuf requirement (hard gate)
|
package/docs/resolved-fields.md
CHANGED
|
@@ -33,6 +33,8 @@ await okdb.embeddings.createPipeline('code', {
|
|
|
33
33
|
|
|
34
34
|
Queries work exactly as with stored content — `env.ftsQuery(...)`, `pipeline.api.search(...)` — and match against the indexes, never the text. Search results that carry chunk text read it through the resolver and verify it against the chunk hash, so a changed file never shows the wrong text.
|
|
35
35
|
|
|
36
|
+
For files uploaded with `okdb.files`, you don't need to write this yourself: `files.indexContent()` declares a built-in resolver on `~files` that reads the blob and extracts its text, and installs it in every process automatically — see [Searching file contents](./files.md#searching-file-contents).
|
|
37
|
+
|
|
36
38
|
## Keeping rows in step with the content
|
|
37
39
|
|
|
38
40
|
The row is the **version**: rewrite it when the content changes (a new content hash is the natural choice), and the normal change feed re-indexes it — FTS re-tokenizes, embeddings re-embeds only the chunks whose text changed. Delete the row and both indexes drop the item. Don't rewrite a row whose content didn't change.
|