@mmmnt/feat-adapter-kurrent 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +414 -2
- package/dist/index.d.ts +48 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +607 -0
- package/dist/index.js.map +1 -0
- package/package.json +40 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, Moment
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,415 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @mmmnt/feat-adapter-kurrent
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Service adapter for Feat that turns a **KurrentDB `$all` log into a capture
|
|
4
|
+
window**: every event the system appends to a namespaced stream during a
|
|
5
|
+
scenario becomes a captured record, in log order. An unpredicted append fails
|
|
6
|
+
the suite by prediction inversion. The adapter is built on the official
|
|
7
|
+
`@kurrent/kurrentdb-client`.
|
|
8
|
+
|
|
9
|
+
```jsonc
|
|
10
|
+
// feat.config.json
|
|
11
|
+
"services": {
|
|
12
|
+
"orderStore": {
|
|
13
|
+
"adapter": "@mmmnt/feat-adapter-kurrent",
|
|
14
|
+
"consistency": "eventual",
|
|
15
|
+
"convergenceTimeout": 5000,
|
|
16
|
+
"options": {
|
|
17
|
+
"connectionStringEnv": "FEAT_KURRENT_URL" // or "connectionString": literal
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
predict success:
|
|
25
|
+
response 202 OrderAccepted { orderId: @when.orderId }
|
|
26
|
+
orderStore has [ OrderPlaced with OrderPlacedEvent { orderId: @when.orderId } ]
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Part of [Feature](https://github.com/mmmnt/feature), the `.feat` execution
|
|
30
|
+
specification language.
|
|
31
|
+
|
|
32
|
+
## What it observes, and how
|
|
33
|
+
|
|
34
|
+
The adapter declares `observes = { diff: "native", state: true }`.
|
|
35
|
+
|
|
36
|
+
- **Diff (native).** The `$all` log is the change feed. `startCapture()`
|
|
37
|
+
appends a marker to the fence stream `feat-fence.<ns>` and keeps the marker's
|
|
38
|
+
commit position as an exclusive cursor, so there is no inclusive or exclusive
|
|
39
|
+
ambiguity at the start of the window. `peekCapture()` and `stopCapture()` read
|
|
40
|
+
`$all` forwards from that cursor with a server-side stream-name prefix filter
|
|
41
|
+
(`<ns>.` and `$$<ns>.`) and return what the system wrote, in commit-position
|
|
42
|
+
order. The order is the log's: total, even across streams.
|
|
43
|
+
- **State.** `read()` reads the namespace's streams forwards, so `contains`
|
|
44
|
+
assertions see what is stored, not only what changed.
|
|
45
|
+
- **Settle (a proof, not a timeout).** After the system's writes returned,
|
|
46
|
+
`settle()` appends a fence marker, reads `$all` from the cursor until an event
|
|
47
|
+
at or beyond the marker's position is seen, and answers `true`. Every write
|
|
48
|
+
committed before the marker is then visible to the capture. It also proves an
|
|
49
|
+
absence: an empty window settles `true`. It answers `false` when no window is
|
|
50
|
+
open, when the marker is not read back within `settleTimeoutMs`, or when the
|
|
51
|
+
append or the read fails (a paused or unreachable node answers `false`, never
|
|
52
|
+
`true`). The fence marker is never in a capture.
|
|
53
|
+
- **No `deliver()`.** KurrentDB has no inbound trigger; a stimulus is the
|
|
54
|
+
system's own append.
|
|
55
|
+
|
|
56
|
+
Declare the service `eventual`: `settle()` ends the convergence wait on proof,
|
|
57
|
+
and `convergenceTimeout` is the ceiling when it cannot vouch. `eventual`
|
|
58
|
+
services compare predictions unordered by default; write `has ordered [ ... ]`
|
|
59
|
+
when the log order is part of the prediction.
|
|
60
|
+
|
|
61
|
+
### The captured record
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
{ type: <event type>, key: <stream, without the namespace prefix>,
|
|
65
|
+
payload: <the event's JSON data>, timestamp: <created time, ms>,
|
|
66
|
+
metadata: { revision, commitPosition } }
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
What a capture keeps and drops:
|
|
70
|
+
|
|
71
|
+
- Events of streams outside the namespace are nobody's effect and are not
|
|
72
|
+
captured.
|
|
73
|
+
- Events the adapter itself wrote (metadata `{ "feat": "instrument" }`: fence
|
|
74
|
+
markers and fault placeholders) are never captured, peeked or read.
|
|
75
|
+
- Server-written system events (types starting with `$`) are dropped, except
|
|
76
|
+
`$streamDeleted` and `$metadata`. A soft delete or a metadata change by the
|
|
77
|
+
system is therefore captured, with key `$$<stream>` and type `$metadata`.
|
|
78
|
+
- Events that are not JSON are dropped.
|
|
79
|
+
|
|
80
|
+
### The `$tb` metadata rule
|
|
81
|
+
|
|
82
|
+
On KurrentDB 26.2.3 the first append to a stream after a soft delete makes the
|
|
83
|
+
server write `$$<stream>/$metadata` with a body of exactly `{ "$tb": n }`, where
|
|
84
|
+
`n` is below the Int64 maximum. That record is the server's, not the system's,
|
|
85
|
+
so the capture drops it. A soft delete by the system writes the same body with
|
|
86
|
+
`n` equal to the Int64 maximum (`9223372036854775807`; the client delivers it as
|
|
87
|
+
the JSON number 2^63). That is the system's effect and is captured. A body with
|
|
88
|
+
any other key, or an `n` that is not a non-negative integer below the maximum,
|
|
89
|
+
is captured. (Founder ruling 2026-11-09, "Kurrent $tb A".)
|
|
90
|
+
|
|
91
|
+
## Install
|
|
92
|
+
|
|
93
|
+
```sh
|
|
94
|
+
npm install --save-dev @mmmnt/feature @mmmnt/feat-adapter-kurrent
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
- Node 20 or later (`engines.node` is `>=20`). The adapter is ESM.
|
|
98
|
+
- No peer dependencies. `@kurrent/kurrentdb-client` (pinned at 1.3.2) and
|
|
99
|
+
`@mmmnt/feat-fault-proxy` are regular dependencies.
|
|
100
|
+
- The supported product is KurrentDB. The adapter's tests run against
|
|
101
|
+
`kurrentplatform/kurrentdb:26.2.3`, a single secure dev node
|
|
102
|
+
(`KURRENTDB_DEV=true`, projections off, `tlsVerifyCert=false`) with an
|
|
103
|
+
admin user and non-admin `writer` and `reader` users. The adapter does not
|
|
104
|
+
need projections: streams are found by an `$all` prefix scan, not `$streams`.
|
|
105
|
+
Kurrent Cloud works through `connectionString`; nothing here needs AWS.
|
|
106
|
+
- **A cluster is not verified.** Commit positions are positions in one node's
|
|
107
|
+
log, so `settle()` is a proof only when the append and the read go to the same
|
|
108
|
+
node. A single node is the tested shape.
|
|
109
|
+
- The instrument identity must be able to read `$all`, which KurrentDB allows
|
|
110
|
+
for an admin identity. Any other identity is refused at `setup()` with
|
|
111
|
+
`ALL_READ_DENIED`.
|
|
112
|
+
- The package ships `dist/` only. Its `fixtures/` helpers are internal.
|
|
113
|
+
|
|
114
|
+
## Configuration
|
|
115
|
+
|
|
116
|
+
A complete service entry. Every key under `options` is optional except that a
|
|
117
|
+
connection string must be supplied one way or the other.
|
|
118
|
+
|
|
119
|
+
```jsonc
|
|
120
|
+
"services": {
|
|
121
|
+
"orderStore": {
|
|
122
|
+
"adapter": "@mmmnt/feat-adapter-kurrent",
|
|
123
|
+
"consistency": "eventual",
|
|
124
|
+
"convergenceTimeout": 5000,
|
|
125
|
+
"options": {
|
|
126
|
+
"connectionStringEnv": "FEAT_KURRENT_URL", // name of the variable holding the connection string
|
|
127
|
+
// "connectionString": "kurrentdb://localhost:2113?tls=false", // or a literal; wins over connectionStringEnv
|
|
128
|
+
// "connectionStringFile": "secrets/kurrent-url", // or a PATH to a file holding the string (0.2.0)
|
|
129
|
+
"system": { // env-var NAMES for the instrument's credentials
|
|
130
|
+
"username": "FEAT_KURRENT_USER",
|
|
131
|
+
"password": "FEAT_KURRENT_PASSWORD"
|
|
132
|
+
},
|
|
133
|
+
// "system": { "user": "admin", "passwordFile": "/run/secrets/kurrent" }, // or a literal user and a password FILE (0.2.0)
|
|
134
|
+
"settleTimeoutMs": 5000, // default 5000
|
|
135
|
+
"nodeMajor": 24, // the Node major the TLS host rule judges by; default the running Node's
|
|
136
|
+
"proxy": { // transport faults on the system's path
|
|
137
|
+
"api": "http://127.0.0.1:8474", // Toxiproxy API
|
|
138
|
+
"upstream": "127.0.0.1:2113", // host:port of the node, as Toxiproxy reaches it
|
|
139
|
+
"name": "kurrent", // product label of the proxy name feat-<ns>-<name>; default "kurrent"
|
|
140
|
+
"container": "kurrentdb", // the node's container; without it BrokerLoss is not offered
|
|
141
|
+
"metrics": "http://127.0.0.1:8474/metrics", // Toxiproxy /metrics URL
|
|
142
|
+
"runtime": "docker" // container runtime CLI; default "docker"
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
| Option | Meaning |
|
|
150
|
+
| --- | --- |
|
|
151
|
+
| `connectionString` | A literal `kurrentdb://` or `kurrentdb+discover://` string. |
|
|
152
|
+
| `connectionStringEnv` | The name of an environment variable holding the string. Used when `connectionString` is absent. Neither set, or the variable unset or empty, is a configuration error at `setup()`. |
|
|
153
|
+
| `connectionStringFile` | The path of a file whose content is the whole connection string (0.2.0). Given with `connectionString` or `connectionStringEnv`, it is refused at `setup()` with `OPTIONS_INVALID`. |
|
|
154
|
+
| `system` | Either `{ username, password }`: the **names** of two environment variables, both of which must be set; or `{ user, passwordFile }` (0.2.0): a literal login name and the path of a file whose content is the password. The two forms are never mixed in one `system` (`OPTIONS_INVALID`). The values replace the credentials in the connection string. The config carries references, never secrets. |
|
|
155
|
+
| `settleTimeoutMs` | How long `settle()` may take to read its fence marker back. Default 5000. Keep `convergenceTimeout` at or above it. |
|
|
156
|
+
| `nodeMajor` | An integer, 1 or more (anything else is refused at `setup()` with `OPTIONS_INVALID`), that overrides the Node major the TLS host rule uses, so a scenario can put the adapter "on Node 24 or 26" without a second Node. Default: the running Node's major. |
|
|
157
|
+
| `proxy` | A Toxiproxy in front of KurrentDB for `Connection` faults. `api` and `upstream` are required. See below. |
|
|
158
|
+
|
|
159
|
+
The adapter does not reject unknown keys under `options`; a misspelled option is
|
|
160
|
+
ignored. `connectionString` and `connectionStringEnv` may both appear; the
|
|
161
|
+
literal wins.
|
|
162
|
+
|
|
163
|
+
### Credentials and connection strings in files (SPEC-ADPKUR-005)
|
|
164
|
+
|
|
165
|
+
For secrets that live in files (Docker secrets, a mounted secrets directory), name the file, never the secret:
|
|
166
|
+
|
|
167
|
+
- A relative path is resolved against the working directory of the run (the project root `feat run` starts in).
|
|
168
|
+
- The file is read when the connection is resolved, before any connection. Exactly one trailing line ending (`\n` or
|
|
169
|
+
`\r\n`) is removed; nothing else is trimmed, so a password with leading or inner spaces is kept as written.
|
|
170
|
+
- A file that is missing, is a directory, cannot be read, or is empty after that line ending is removed is refused at
|
|
171
|
+
`setup()` with `CREDENTIAL_FILE_UNREADABLE`, before the adapter connects to anything. The detail names the option, the
|
|
172
|
+
path and the cause, never the content. `connectionRefusal()` reports the same code without connecting.
|
|
173
|
+
- To trust a certificate authority, put the client's own `tlsCAFile=<path>` parameter in the connection string; the
|
|
174
|
+
adapter passes every parameter through unchanged.
|
|
175
|
+
- The instrument's reads pass the decoded credentials on every call, so a password holding a character the connection
|
|
176
|
+
string must percent-encode (a space, `%`) works on the client's read path as well as its append path.
|
|
177
|
+
|
|
178
|
+
The adapter's own client (capture, fence, read, seed, reset) connects to the
|
|
179
|
+
node **directly** and never through the proxy.
|
|
180
|
+
|
|
181
|
+
## A minimal spec
|
|
182
|
+
|
|
183
|
+
```
|
|
184
|
+
feat 1.0
|
|
185
|
+
|
|
186
|
+
spec SPEC-ORD-010 "PlaceOrder appends to the order stream"
|
|
187
|
+
context Orders
|
|
188
|
+
aggregate Order
|
|
189
|
+
type command
|
|
190
|
+
status agreed
|
|
191
|
+
|
|
192
|
+
construct:
|
|
193
|
+
handler at features/place-order/handler.ts
|
|
194
|
+
touches features/place-order/**
|
|
195
|
+
|
|
196
|
+
enforce:
|
|
197
|
+
append OrderPlaced to the stream orders-<orderId>
|
|
198
|
+
rejects CONCURRENCY_CONFLICT when the store reports a wrong expected version
|
|
199
|
+
|
|
200
|
+
contract:
|
|
201
|
+
input PlaceOrderInput
|
|
202
|
+
response OrderAccepted
|
|
203
|
+
event OrderPlacedEvent
|
|
204
|
+
event OrderSeededEvent
|
|
205
|
+
error Refusal
|
|
206
|
+
|
|
207
|
+
scenario "a first order is appended":
|
|
208
|
+
given:
|
|
209
|
+
A customer has an earlier order in another stream.
|
|
210
|
+
seed orderStore [ OrderSeeded with OrderSeededEvent { stream: "orders-o-0", orderId: "o-0" } ]
|
|
211
|
+
when: PlaceOrder { orderId: "o-1" }
|
|
212
|
+
predict success:
|
|
213
|
+
response 202 OrderAccepted { orderId: @when.orderId }
|
|
214
|
+
orderStore has [ OrderPlaced with OrderPlacedEvent { orderId: @when.orderId } ]
|
|
215
|
+
|
|
216
|
+
scenario "a competing writer created the stream first":
|
|
217
|
+
given:
|
|
218
|
+
fault orderStore AppendToStream WRONG_EXPECTED_VERSION { stream: "orders-o-2" } until reset
|
|
219
|
+
when: PlaceOrder { orderId: "o-2" }
|
|
220
|
+
predict rejection CONCURRENCY_CONFLICT:
|
|
221
|
+
response 409 Refusal { code: "CONCURRENCY_CONFLICT" }
|
|
222
|
+
orderStore has []
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
The seed record's event type is `OrderSeeded`. It goes to the stream named in
|
|
226
|
+
`values.stream` (`orders-o-0`), or to a stream named after the record type when
|
|
227
|
+
`values` has no string `stream`. The whole of `values`, `stream` included, is
|
|
228
|
+
the event data. Seeds are written before the window opens, so they are never in
|
|
229
|
+
a capture. The fault line must say `until reset`: a count of `once` or
|
|
230
|
+
`times <n>` is refused (see the fault table).
|
|
231
|
+
|
|
232
|
+
## Namespaces
|
|
233
|
+
|
|
234
|
+
The runner derives a namespace per spec file, exactly `^s[0-9a-f]{12}$`
|
|
235
|
+
(SPEC-RT-006), and hands it to the adapter as the config's top-level
|
|
236
|
+
`namespace`. It is never an option. Because the form is fixed-length with no
|
|
237
|
+
dot, no namespace is a prefix of another.
|
|
238
|
+
|
|
239
|
+
- A stream is stored as `<ns>.<stream>`. The spec writes `orders-o-1`; the
|
|
240
|
+
adapter reports `orders-o-1`. The system under test must write to the prefixed
|
|
241
|
+
names. Seeds, fault details and read hints take the relative name and the
|
|
242
|
+
adapter adds the prefix.
|
|
243
|
+
- Capture, read and reset are all scoped to the prefix. A write outside every
|
|
244
|
+
namespace is nobody's effect.
|
|
245
|
+
- The fence stream is `feat-fence.<ns>`, outside the user prefix.
|
|
246
|
+
- `reset()` soft-deletes the namespace's streams. It does not tombstone them: a
|
|
247
|
+
tombstoned stream name is dead forever.
|
|
248
|
+
|
|
249
|
+
## Seed, read and reset
|
|
250
|
+
|
|
251
|
+
- **`seed(records)`** appends each record to `<ns>.<stream>` with stream state
|
|
252
|
+
`ANY`, before the window.
|
|
253
|
+
- **`read(query)`** reads the namespace's streams forwards and returns the
|
|
254
|
+
events as records (`metadata: { revision }`). With hints, `contains`
|
|
255
|
+
assertions that carry a `key.stream` literal name the streams to read; the
|
|
256
|
+
adapter reads those and may return no others. Without hints it finds every
|
|
257
|
+
stream the namespace has ever held by an `$all` prefix scan. A soft-deleted or
|
|
258
|
+
never-written stream reads as empty, so state is not resurrected from `$all`.
|
|
259
|
+
Instrument events, `$`-typed events and non-JSON events are skipped.
|
|
260
|
+
- **`reset()`** disarms every transport fault and restores a paused or stopped
|
|
261
|
+
container, clears and soft-deletes every stream of the namespace (clearing
|
|
262
|
+
stream metadata first, which removes an `ACCESS_DENIED` ACL), and closes the
|
|
263
|
+
window.
|
|
264
|
+
|
|
265
|
+
## Faults
|
|
266
|
+
|
|
267
|
+
All logical faults are armed `until reset`: the product keeps no record of a
|
|
268
|
+
refusal it issued. `firedFaults` is not implemented, so evidence is
|
|
269
|
+
`unobserved`. A fault line with any other count is refused with
|
|
270
|
+
`FAULT_UNSUPPORTED` before it has an effect.
|
|
271
|
+
|
|
272
|
+
| Fault | Operation | Counts | Detail | What the system sees |
|
|
273
|
+
| --- | --- | --- | --- | --- |
|
|
274
|
+
| `WRONG_EXPECTED_VERSION` | `AppendToStream` | `until reset` | `{ stream }` (required) | The adapter appends an instrument event to the stream, so a stream the system expects **not** to exist now exists, and the server refuses the append with `WRONG_EXPECTED_VERSION`. It fires only for appends that expect `NoStream`; an append with `ANY` succeeds. |
|
|
275
|
+
| `ACCESS_DENIED` | `AppendToStream` | `until reset` | `{ stream }` (required) | The adapter sets the stream's `$acl` write role to one nobody holds, so the server refuses a non-admin writer's append with `ACCESS_DENIED`. `$admins` bypass ACLs, so the **system must connect as a non-admin** user. |
|
|
276
|
+
| `Timeout` | `Connection` | `until reset` | none | Needs `options.proxy`. Toxiproxy stalls the stream and never delivers; the system's call runs into its own deadline. Armed downstream (the library default; the adapter passes no direction), so on an established connection the node may apply a request whose answer the system never hears. |
|
|
277
|
+
| `ConnectionReset` | `Connection` | `until reset` | none | Needs `options.proxy`. Toxiproxy resets the connection (default direction upstream, on the request path). |
|
|
278
|
+
| `Partition` | `Connection` | `until reset` | none | Needs `options.proxy`. The proxy is disabled: the system's connections fail. |
|
|
279
|
+
| `BrokerLoss` | `Connection` | `until reset` | none | Needs `options.proxy.container`. The container is paused with the runtime's CLI. Exclusive and serial. |
|
|
280
|
+
|
|
281
|
+
Under a transport fault the system's gRPC client reports `UNAVAILABLE`,
|
|
282
|
+
`DEADLINE_EXCEEDED` or `CANCELLED`.
|
|
283
|
+
|
|
284
|
+
Not offered: `STREAM_DELETED` (a tombstone is irreversible and would poison the
|
|
285
|
+
namespace), `NOT_LEADER` (no native way to produce it), timeouts on the product
|
|
286
|
+
itself (those are `Connection.Timeout`), and `once` or `times` counts for every
|
|
287
|
+
fault. A race between the system's read and write cannot be produced without
|
|
288
|
+
sitting in the call path.
|
|
289
|
+
|
|
290
|
+
### Transport faults and broker loss
|
|
291
|
+
|
|
292
|
+
Set `options.proxy` and the catalog gains `Connection.Timeout`,
|
|
293
|
+
`Connection.ConnectionReset` and `Connection.Partition`. Adding
|
|
294
|
+
`options.proxy.container` adds `Connection.BrokerLoss`. The mechanism is
|
|
295
|
+
[`@mmmnt/feat-fault-proxy`](https://github.com/mmmnt/feature/blob/main/adapters/fault-proxy/README.md) (SPEC-FPX-001): one
|
|
296
|
+
Toxiproxy proxy per namespace and product, named `feat-<ns>-<name>`.
|
|
297
|
+
|
|
298
|
+
- A transport fault is on the **system's path only**. The adapter observes on
|
|
299
|
+
its own direct connection, so under a fault the capture, the fence and the
|
|
300
|
+
state read still work, and an absence under a fault is still provable.
|
|
301
|
+
- Point the system's client at the proxy's listen address (`proxyListen()` on
|
|
302
|
+
the adapter). KurrentDB's gRPC over HTTP/2 passes through Toxiproxy's TCP
|
|
303
|
+
proxy unchanged.
|
|
304
|
+
- Give the system a **single-node connection string** (no gossip discovery,
|
|
305
|
+
which would hand the client the node's advertised address and bypass the
|
|
306
|
+
proxy), and either a certificate that names the proxy host or
|
|
307
|
+
`tlsVerifyCert=false` on a dev node.
|
|
308
|
+
- Whether a fault was consumed is unobserved: the proxy reports bytes, not
|
|
309
|
+
activations.
|
|
310
|
+
- `BrokerLoss` pauses the node's container, which every namespace and every spec
|
|
311
|
+
file shares. It is an exclusive fault: the harness runs it only in the serial
|
|
312
|
+
pass with one worker and `FEAT_SERIAL=1`, and refuses it elsewhere with
|
|
313
|
+
`FAULT_REQUIRES_SERIAL`. Keep it in a spec file of its own. While the node is
|
|
314
|
+
paused `settle()` answers `false`, not `true`; `reset()` unpauses it.
|
|
315
|
+
- A `Connection` fault without `options.proxy`, or `BrokerLoss` without
|
|
316
|
+
`options.proxy.container`, is not in the catalog and is refused with
|
|
317
|
+
`FAULT_UNSUPPORTED`.
|
|
318
|
+
|
|
319
|
+
## The TLS host rule (SPEC-ADPKUR-004)
|
|
320
|
+
|
|
321
|
+
Node 26 refuses an IP address as the TLS server name
|
|
322
|
+
(`ERR_INVALID_ARG_VALUE`). `@grpc/grpc-js` 1.14.7 sets the server name to the
|
|
323
|
+
remote host unconditionally, and `@kurrent/kurrentdb-client` 1.3.2 has no
|
|
324
|
+
channel option to stop it, so a `kurrentdb://` string with `tls=true` (the
|
|
325
|
+
default when `tls` is absent) and an IP host cannot connect on Node 26.
|
|
326
|
+
`tlsVerifyCert=false` does not help, because the name is still set. The
|
|
327
|
+
upstream issue is
|
|
328
|
+
[grpc/grpc-node#3131](https://github.com/grpc/grpc-node/issues/3131); the rule
|
|
329
|
+
can go when grpc-js stops sending an IP as the server name.
|
|
330
|
+
|
|
331
|
+
The rule applies to the adapter's own connection (the system's client is the
|
|
332
|
+
system's concern), host by host, in order:
|
|
333
|
+
|
|
334
|
+
| Connection string | What the adapter does |
|
|
335
|
+
| --- | --- |
|
|
336
|
+
| Host exactly `127.0.0.1` or `::1`, `tls=true` | Connects as `localhost`. Only the host changes: credentials, port, path and every parameter are as written. This applies on **every** Node major, so one path serves the whole CI matrix. `[0:0:0:0:0:0:0:1]` is the same host as `::1`. |
|
|
337
|
+
| Any other IP literal, `tls=true`, Node 26 or later (or `options.nodeMajor` 26 or later) | `setup()` throws `TLS_HOST_UNSUPPORTED` before connecting. The detail names the host and says to use a hostname the certificate names, or `tls=false`. It carries no credential. |
|
|
338
|
+
| A hostname, `kurrentdb+discover://`, `tls=false`, or a non-loopback IP on Node below 26 | Left exactly as written. |
|
|
339
|
+
|
|
340
|
+
A string with several hosts is judged host by host; the first refused host is
|
|
341
|
+
the one the detail names. The loopback test is exact, not `127.0.0.0/8`:
|
|
342
|
+
`localhost` never resolves to `127.0.0.2`, so that address is refused on Node 26.
|
|
343
|
+
`[::ffff:127.0.0.1]` is an IPv4-mapped IPv6 literal: an IP host, not a loopback
|
|
344
|
+
host, so it is refused on Node 26.
|
|
345
|
+
|
|
346
|
+
Consequences:
|
|
347
|
+
|
|
348
|
+
- If you verify the certificate and relied on an IP SAN for `127.0.0.1`, the
|
|
349
|
+
certificate must now name `localhost`.
|
|
350
|
+
- `@kurrent/kurrentdb-client` 1.3.2 cannot parse a **bracketed IPv6** host. Only
|
|
351
|
+
`::1`, which the rule rewrites to `localhost`, can reach a node over IPv6.
|
|
352
|
+
- `0.0.0.0` reaches a local node on Linux and macOS but is judged by the rule
|
|
353
|
+
like any non-loopback IP, so on Node 26 it is refused.
|
|
354
|
+
|
|
355
|
+
Two methods let a host check the rule without a network: `connectionRefusal()`
|
|
356
|
+
returns the code `setup()` would refuse with (or `undefined`), and
|
|
357
|
+
`connectionTarget()` returns the string the client is created from. Neither
|
|
358
|
+
connects, and neither throws for a refusal.
|
|
359
|
+
|
|
360
|
+
## Errors and refusals
|
|
361
|
+
|
|
362
|
+
Adapter errors are `KurrentAdapterError`, with a `code` and a `detail`.
|
|
363
|
+
|
|
364
|
+
| Code | Raised by | When |
|
|
365
|
+
| --- | --- | --- |
|
|
366
|
+
| `NAMESPACE_INVALID` | construction | The namespace does not match `^s[0-9a-f]{12}$`. Defensive: the runner never passes another. |
|
|
367
|
+
| `ALL_READ_DENIED` | `setup()` | The instrument credentials cannot read `$all`. |
|
|
368
|
+
| `TLS_HOST_UNSUPPORTED` | `setup()` | An IP host other than `127.0.0.1` and `::1`, with `tls=true`, on Node 26 or later. |
|
|
369
|
+
| `OPTIONS_INVALID` | `setup()` | `options.nodeMajor` is present and is not an integer of 1 or more. Refused before any connection. |
|
|
370
|
+
| `FAULT_UNSUPPORTED` | `fault()` | The fault is not in the catalog (including `Connection` without `options.proxy` and `BrokerLoss` without `container`), or the count is not `until reset`, or an `AppendToStream` fault has no `detail.stream`. The detail lists the catalog. |
|
|
371
|
+
|
|
372
|
+
Plain `Error`s (no code) report a missing connection string
|
|
373
|
+
(`connectionString`, or `connectionStringEnv` naming a set variable) and
|
|
374
|
+
`options.system` naming variables that are not both set. Errors from the
|
|
375
|
+
Toxiproxy layer keep the codes of `@mmmnt/feat-fault-proxy`
|
|
376
|
+
(`PROXY_UNREACHABLE`, `PROXY_NOT_OPEN`, `FAULT_UNSUPPORTED`,
|
|
377
|
+
`CONTAINER_NOT_FOUND`, `CONTAINER_RUNTIME_UNAVAILABLE`).
|
|
378
|
+
|
|
379
|
+
## Limitations
|
|
380
|
+
|
|
381
|
+
- `settle()` does not prove writes the system starts after its handler returned
|
|
382
|
+
(the ADR-0021 boundary), and a cluster is not verified (see Install).
|
|
383
|
+
- `read()` without a hint and `reset()` find the namespace's streams by scanning
|
|
384
|
+
`$all` from the start, so their cost grows with the log. `reset()` leaves the
|
|
385
|
+
fence stream `feat-fence.<ns>` in place; it holds only instrument markers.
|
|
386
|
+
- Non-JSON events are not captured or read.
|
|
387
|
+
- `WRONG_EXPECTED_VERSION` fires only for appends that expect `NoStream`.
|
|
388
|
+
`ACCESS_DENIED` needs a non-admin system identity. Neither can be armed
|
|
389
|
+
`once`.
|
|
390
|
+
- The `options.proxy` block needs a Toxiproxy server you run; the adapter does
|
|
391
|
+
not start one. `Timeout` can leave a write applied on an established
|
|
392
|
+
connection (see the fault table).
|
|
393
|
+
- Options are validated only for `nodeMajor`: unknown keys are ignored.
|
|
394
|
+
|
|
395
|
+
## Specs and design
|
|
396
|
+
|
|
397
|
+
- [`observe.feat`](https://github.com/mmmnt/feature/blob/main/adapters/kurrent/observe.feat): SPEC-ADPKUR-001, namespaced capture, state,
|
|
398
|
+
settle, reset and faults.
|
|
399
|
+
- [`transport.feat`](https://github.com/mmmnt/feature/blob/main/adapters/kurrent/transport.feat): SPEC-ADPKUR-002, transport faults on the
|
|
400
|
+
system's path (integration tier).
|
|
401
|
+
- [`broker-loss.feat`](https://github.com/mmmnt/feature/blob/main/adapters/kurrent/broker-loss.feat): SPEC-ADPKUR-003, broker loss
|
|
402
|
+
(integration tier, serial).
|
|
403
|
+
- [`node26-tls-host.feat`](https://github.com/mmmnt/feature/blob/main/adapters/kurrent/node26-tls-host.feat): SPEC-ADPKUR-004, the TLS
|
|
404
|
+
host rule (spec tier).
|
|
405
|
+
- [`DESIGN.md`](https://github.com/mmmnt/feature/blob/main/adapters/kurrent/DESIGN.md): the client choice, the settle proof, the
|
|
406
|
+
namespace, the faults and the TLS host rule, with sources.
|
|
407
|
+
|
|
408
|
+
The generated suites run under `feat run` against throwaway containers
|
|
409
|
+
(`kurrentplatform/kurrentdb:26.2.3`, `ghcr.io/shopify/toxiproxy:2.12.0`) that
|
|
410
|
+
the fixture starts and removes on exit. They are not part of the package's
|
|
411
|
+
`test` script.
|
|
412
|
+
|
|
413
|
+
## License
|
|
414
|
+
|
|
415
|
+
MIT. Docs: https://github.com/mmmnt/feature/wiki
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { FeatServiceAdapter } from "@mmmnt/feat-types";
|
|
2
|
+
export type KurrentAdapterErrorCode = "NAMESPACE_INVALID" | "ALL_READ_DENIED" | "FAULT_UNSUPPORTED" | "TLS_HOST_UNSUPPORTED" | "OPTIONS_INVALID" | "CREDENTIAL_FILE_UNREADABLE";
|
|
3
|
+
export declare class KurrentAdapterError extends Error {
|
|
4
|
+
readonly code: KurrentAdapterErrorCode;
|
|
5
|
+
readonly detail: string;
|
|
6
|
+
constructor(code: KurrentAdapterErrorCode, detail: string);
|
|
7
|
+
}
|
|
8
|
+
export interface KurrentProxyOptions {
|
|
9
|
+
/** Toxiproxy API base URL. */
|
|
10
|
+
api: string;
|
|
11
|
+
/** host:port of the product as Toxiproxy reaches it (it can differ from the instrument's address). */
|
|
12
|
+
upstream: string;
|
|
13
|
+
/** The product label of the proxy name `feat-<ns>-<name>`. Default "kurrent". */
|
|
14
|
+
name?: string;
|
|
15
|
+
/** The product's container, for BrokerLoss. Without it BrokerLoss is not in the catalog. */
|
|
16
|
+
container?: string;
|
|
17
|
+
metrics?: string;
|
|
18
|
+
runtime?: string;
|
|
19
|
+
}
|
|
20
|
+
/** The instrument's credentials named by environment variables (SPEC-ADPKUR-001). */
|
|
21
|
+
export interface KurrentSystemFromEnv {
|
|
22
|
+
/** Name of the environment variable holding the login name. */
|
|
23
|
+
username: string;
|
|
24
|
+
/** Name of the environment variable holding the password. */
|
|
25
|
+
password: string;
|
|
26
|
+
}
|
|
27
|
+
/** The instrument's credentials with the password in a file (SPEC-ADPKUR-005). */
|
|
28
|
+
export interface KurrentSystemFromFile {
|
|
29
|
+
/** The login name itself (not a secret). */
|
|
30
|
+
user: string;
|
|
31
|
+
/** Path of a file whose content is the password; a relative path is resolved against the working directory. */
|
|
32
|
+
passwordFile: string;
|
|
33
|
+
}
|
|
34
|
+
export interface KurrentOptions {
|
|
35
|
+
connectionString?: string;
|
|
36
|
+
/** Name of the environment variable holding the connection string. */
|
|
37
|
+
connectionStringEnv?: string;
|
|
38
|
+
/** Path of a file whose content is the connection string (SPEC-ADPKUR-005); relative to the working directory. */
|
|
39
|
+
connectionStringFile?: string;
|
|
40
|
+
/** The instrument's credentials: environment-variable names, or a literal user and a password file. Never both forms. */
|
|
41
|
+
system?: KurrentSystemFromEnv | KurrentSystemFromFile;
|
|
42
|
+
settleTimeoutMs?: number;
|
|
43
|
+
proxy?: KurrentProxyOptions;
|
|
44
|
+
/** The Node major the TLS host rule judges by (SPEC-ADPKUR-004). Default: the running Node's. */
|
|
45
|
+
nodeMajor?: number;
|
|
46
|
+
}
|
|
47
|
+
export declare function createAdapter(config: Record<string, unknown>): FeatServiceAdapter;
|
|
48
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAIV,kBAAkB,EAGnB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,MAAM,uBAAuB,GAAG,mBAAmB,GAAG,iBAAiB,GAAG,mBAAmB,GAAG,sBAAsB,GAAG,iBAAiB,GAAG,4BAA4B,CAAC;AAEhL,qBAAa,mBAAoB,SAAQ,KAAK;IAE1C,QAAQ,CAAC,IAAI,EAAE,uBAAuB;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM;gBADd,IAAI,EAAE,uBAAuB,EAC7B,MAAM,EAAE,MAAM;CAK1B;AAED,MAAM,WAAW,mBAAmB;IAClC,8BAA8B;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,sGAAsG;IACtG,QAAQ,EAAE,MAAM,CAAC;IACjB,iFAAiF;IACjF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,4FAA4F;IAC5F,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qFAAqF;AACrF,MAAM,WAAW,oBAAoB;IACnC,+DAA+D;IAC/D,QAAQ,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,kFAAkF;AAClF,MAAM,WAAW,qBAAqB;IACpC,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,+GAA+G;IAC/G,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,cAAc;IAC7B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,sEAAsE;IACtE,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,kHAAkH;IAClH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,yHAAyH;IACzH,MAAM,CAAC,EAAE,oBAAoB,GAAG,qBAAqB,CAAC;IACtD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,mBAAmB,CAAC;IAC5B,iGAAiG;IACjG,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAqlBD,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,kBAAkB,CAEjF"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,607 @@
|
|
|
1
|
+
// @mmmnt/feat-adapter-kurrent (SPEC-ADPKUR-001, -002, -003, -004, -005) — KurrentDB as a Feat service.
|
|
2
|
+
//
|
|
3
|
+
// The `$all` log is the change feed: it is totally ordered by log position, and the position of an
|
|
4
|
+
// append (AppendResult.position) is a position in that same log. That is the whole of settle: append a
|
|
5
|
+
// fence marker after the system's writes returned, read `$all` until an event at or beyond the marker's
|
|
6
|
+
// position is seen, and every earlier write is visible to the capture. It proves absence too.
|
|
7
|
+
//
|
|
8
|
+
// The adapter's own (instrument) client is connected to the product directly and never through a
|
|
9
|
+
// proxy; transport faults (Connection.*) are armed on a Toxiproxy proxy in front of the SYSTEM's path
|
|
10
|
+
// through @mmmnt/feat-fault-proxy (SPEC-FPX-001).
|
|
11
|
+
import { ANY, KurrentDBClient, START, jsonEvent, streamNameFilter, } from "@kurrent/kurrentdb-client";
|
|
12
|
+
import { readFileSync, statSync } from "node:fs";
|
|
13
|
+
import { isIP } from "node:net";
|
|
14
|
+
import path from "node:path";
|
|
15
|
+
import { createFaultProxy } from "@mmmnt/feat-fault-proxy";
|
|
16
|
+
export class KurrentAdapterError extends Error {
|
|
17
|
+
code;
|
|
18
|
+
detail;
|
|
19
|
+
constructor(code, detail) {
|
|
20
|
+
super(`${code}: ${detail}`);
|
|
21
|
+
this.code = code;
|
|
22
|
+
this.detail = detail;
|
|
23
|
+
this.name = "KurrentAdapterError";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const NAMESPACE_PATTERN = /^s[0-9a-f]{12}$/;
|
|
27
|
+
const INSTRUMENT_MARKER = { feat: "instrument" };
|
|
28
|
+
const WHOLE_LOG = Number.MAX_SAFE_INTEGER;
|
|
29
|
+
const POLL_MS = 25;
|
|
30
|
+
/** Event types a capture keeps from the system's own stream-level events. */
|
|
31
|
+
const KEPT_SYSTEM_TYPES = new Set(["$streamDeleted", "$metadata"]);
|
|
32
|
+
/** 9223372036854775807 as the JSON number a JS client delivers: 2^63. */
|
|
33
|
+
const INT64_MAX_AS_NUMBER = 2 ** 63;
|
|
34
|
+
const CONNECTION_FAULTS = ["Timeout", "ConnectionReset", "Partition"];
|
|
35
|
+
/** Node refuses an IP address as the TLS servername from this major on (SPEC-ADPKUR-004). */
|
|
36
|
+
const IP_SERVERNAME_REFUSED_FROM = 26;
|
|
37
|
+
function after(a, b) {
|
|
38
|
+
return a.commit > b.commit || (a.commit === b.commit && a.prepare > b.prepare);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The `$metadata` record the server writes on the first append after a soft delete: a body that is exactly
|
|
42
|
+
* `{ $tb: n }` with n below the Int64 maximum (founder ruling 2026-11-09, Kurrent $tb A). A soft delete by the
|
|
43
|
+
* system writes the maximum, which the client delivers as the JSON number 2^63, and is the system's effect.
|
|
44
|
+
*/
|
|
45
|
+
function isServerTruncateBefore(type, data) {
|
|
46
|
+
if (type !== "$metadata" || typeof data !== "object" || data === null || Array.isArray(data))
|
|
47
|
+
return false;
|
|
48
|
+
const keys = Object.keys(data);
|
|
49
|
+
if (keys.length !== 1 || keys[0] !== "$tb")
|
|
50
|
+
return false;
|
|
51
|
+
const n = data.$tb;
|
|
52
|
+
return typeof n === "number" && Number.isInteger(n) && n >= 0 && n < INT64_MAX_AS_NUMBER;
|
|
53
|
+
}
|
|
54
|
+
/** The WHATWG form of an IP literal, so `[0:0:0:0:0:0:0:1]` and `[::1]` are one host; the literal as written when it does not parse. */
|
|
55
|
+
function canonicalIp(literal) {
|
|
56
|
+
try {
|
|
57
|
+
return new URL(`http://${literal.includes(":") ? `[${literal}]` : literal}`).hostname.replace(/^\[|\]$/g, "");
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return literal;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** The authority of a connection string split so each host can be judged and replaced on its own. */
|
|
64
|
+
function splitAuthority(raw) {
|
|
65
|
+
const m = /^([a-z][a-z0-9+.-]*:\/\/)([^/?#]*)(.*)$/is.exec(raw);
|
|
66
|
+
if (m === null)
|
|
67
|
+
return undefined;
|
|
68
|
+
const authority = m[2];
|
|
69
|
+
const at = authority.lastIndexOf("@");
|
|
70
|
+
return { head: m[1] + authority.slice(0, at + 1), hosts: authority.slice(at + 1).split(","), tail: m[3] };
|
|
71
|
+
}
|
|
72
|
+
/** One `host[:port]` entry of the host list: the host without its brackets, and the port with its colon. */
|
|
73
|
+
function splitHost(entry) {
|
|
74
|
+
if (entry.startsWith("[")) {
|
|
75
|
+
const end = entry.indexOf("]");
|
|
76
|
+
if (end > 0)
|
|
77
|
+
return { host: entry.slice(1, end), port: entry.slice(end + 1) };
|
|
78
|
+
}
|
|
79
|
+
const colon = entry.lastIndexOf(":");
|
|
80
|
+
return colon < 0 ? { host: entry, port: "" } : { host: entry.slice(0, colon), port: entry.slice(colon) };
|
|
81
|
+
}
|
|
82
|
+
/** The client's default is tls=true, so only an explicit false turns it off. */
|
|
83
|
+
function tlsOn(raw) {
|
|
84
|
+
const query = raw.split("#")[0].split("?")[1] ?? "";
|
|
85
|
+
for (const [k, v] of new URLSearchParams(query))
|
|
86
|
+
if (k.toLowerCase() === "tls")
|
|
87
|
+
return v.toLowerCase() !== "false";
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* SPEC-ADPKUR-005: a file the options name by path. Relative to the working directory; exactly one trailing LF or CRLF is
|
|
92
|
+
* removed and nothing else. The refusal's detail names the option, the path and the cause, never the content.
|
|
93
|
+
*/
|
|
94
|
+
function readCredentialFile(option, file) {
|
|
95
|
+
const at = path.resolve(process.cwd(), file);
|
|
96
|
+
const refuse = (cause) => ({
|
|
97
|
+
refusal: new KurrentAdapterError("CREDENTIAL_FILE_UNREADABLE", `options.${option} names ${at}, which ${cause}`),
|
|
98
|
+
});
|
|
99
|
+
let content;
|
|
100
|
+
try {
|
|
101
|
+
if (statSync(at).isDirectory())
|
|
102
|
+
return refuse("is a directory");
|
|
103
|
+
content = readFileSync(at, "utf8");
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
const code = typeof e === "object" && e !== null && "code" in e ? String(e.code) : "";
|
|
107
|
+
if (code === "ENOENT")
|
|
108
|
+
return refuse("is missing");
|
|
109
|
+
if (code === "EISDIR")
|
|
110
|
+
return refuse("is a directory");
|
|
111
|
+
return refuse(`cannot be read (${code || "unknown error"})`);
|
|
112
|
+
}
|
|
113
|
+
const value = content.endsWith("\r\n") ? content.slice(0, -2) : content.endsWith("\n") ? content.slice(0, -1) : content;
|
|
114
|
+
if (value === "")
|
|
115
|
+
return refuse("is empty");
|
|
116
|
+
return { value };
|
|
117
|
+
}
|
|
118
|
+
/** The user info of a connection string, percent-decoded; undefined when it names none. */
|
|
119
|
+
function decodedCredentials(raw) {
|
|
120
|
+
const m = /^[a-z][a-z0-9+.-]*:\/\/([^@/?#]*)@/i.exec(raw);
|
|
121
|
+
if (m === null)
|
|
122
|
+
return undefined;
|
|
123
|
+
const colon = m[1].indexOf(":");
|
|
124
|
+
if (colon < 0)
|
|
125
|
+
return undefined;
|
|
126
|
+
try {
|
|
127
|
+
return { username: decodeURIComponent(m[1].slice(0, colon)), password: decodeURIComponent(m[1].slice(colon + 1)) };
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function errorType(e) {
|
|
134
|
+
return typeof e === "object" && e !== null && "type" in e && typeof e.type === "string"
|
|
135
|
+
? e.type
|
|
136
|
+
: undefined;
|
|
137
|
+
}
|
|
138
|
+
function sleep(ms) {
|
|
139
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
140
|
+
}
|
|
141
|
+
/** Reject after `ms` so a call into a product that no longer answers (a paused container) cannot hang the harness. */
|
|
142
|
+
function within(promise, ms) {
|
|
143
|
+
let timer;
|
|
144
|
+
const deadline = new Promise((_, reject) => {
|
|
145
|
+
timer = setTimeout(() => reject(new Error(`no answer within ${ms} ms`)), ms);
|
|
146
|
+
});
|
|
147
|
+
promise.catch(() => { });
|
|
148
|
+
return Promise.race([promise, deadline]).finally(() => clearTimeout(timer));
|
|
149
|
+
}
|
|
150
|
+
class KurrentAdapter {
|
|
151
|
+
observes = { diff: "native", state: true };
|
|
152
|
+
faults;
|
|
153
|
+
namespace;
|
|
154
|
+
options;
|
|
155
|
+
settleTimeoutMs;
|
|
156
|
+
client;
|
|
157
|
+
readCredentials;
|
|
158
|
+
proxy;
|
|
159
|
+
opened;
|
|
160
|
+
/** The window: the last position read (exclusive cursor) and what has been captured since. */
|
|
161
|
+
cursor;
|
|
162
|
+
captured = [];
|
|
163
|
+
windowOpen = false;
|
|
164
|
+
constructor(config) {
|
|
165
|
+
const ns = config.namespace;
|
|
166
|
+
if (typeof ns !== "string" || !NAMESPACE_PATTERN.test(ns)) {
|
|
167
|
+
throw new KurrentAdapterError("NAMESPACE_INVALID", `'${String(ns)}' does not match ${NAMESPACE_PATTERN.source}, the pattern the runner derives`);
|
|
168
|
+
}
|
|
169
|
+
this.namespace = ns;
|
|
170
|
+
this.options = config.options ?? {};
|
|
171
|
+
this.settleTimeoutMs = this.options.settleTimeoutMs ?? 5000;
|
|
172
|
+
const catalog = {
|
|
173
|
+
AppendToStream: { WRONG_EXPECTED_VERSION: ["reset"], ACCESS_DENIED: ["reset"] },
|
|
174
|
+
};
|
|
175
|
+
const proxy = this.options.proxy;
|
|
176
|
+
if (proxy !== undefined) {
|
|
177
|
+
this.proxy = createFaultProxy({
|
|
178
|
+
api: proxy.api,
|
|
179
|
+
product: proxy.name ?? "kurrent",
|
|
180
|
+
upstream: proxy.upstream,
|
|
181
|
+
namespace: ns,
|
|
182
|
+
...(proxy.container !== undefined ? { container: proxy.container } : {}),
|
|
183
|
+
...(proxy.metrics !== undefined ? { metrics: proxy.metrics } : {}),
|
|
184
|
+
...(proxy.runtime !== undefined ? { runtime: proxy.runtime } : {}),
|
|
185
|
+
});
|
|
186
|
+
catalog.Connection = Object.fromEntries(this.proxy.catalog.map((f) => [f, ["reset"]]));
|
|
187
|
+
}
|
|
188
|
+
this.faults = catalog;
|
|
189
|
+
}
|
|
190
|
+
reportedNamespace() {
|
|
191
|
+
return this.namespace;
|
|
192
|
+
}
|
|
193
|
+
/** The address the system under test connects to when `options.proxy` is configured (host side of the proxy). */
|
|
194
|
+
proxyListen() {
|
|
195
|
+
return this.opened?.listen;
|
|
196
|
+
}
|
|
197
|
+
// ── naming ────────────────────────────────────────────────────────────────
|
|
198
|
+
get prefix() {
|
|
199
|
+
return `${this.namespace}.`;
|
|
200
|
+
}
|
|
201
|
+
get metaPrefix() {
|
|
202
|
+
return `$$${this.namespace}.`;
|
|
203
|
+
}
|
|
204
|
+
get fenceStream() {
|
|
205
|
+
return `feat-fence.${this.namespace}`;
|
|
206
|
+
}
|
|
207
|
+
full(stream) {
|
|
208
|
+
return `${this.prefix}${stream}`;
|
|
209
|
+
}
|
|
210
|
+
/** The namespace-relative key of a stream name, or undefined outside the namespace. */
|
|
211
|
+
relative(streamId) {
|
|
212
|
+
if (streamId.startsWith(this.prefix))
|
|
213
|
+
return streamId.slice(this.prefix.length);
|
|
214
|
+
if (streamId.startsWith(this.metaPrefix))
|
|
215
|
+
return `$$${streamId.slice(this.metaPrefix.length)}`;
|
|
216
|
+
return undefined;
|
|
217
|
+
}
|
|
218
|
+
// ── the instrument connection ─────────────────────────────────────────────
|
|
219
|
+
/**
|
|
220
|
+
* SPEC-ADPKUR-004: with tls on, a host that is exactly 127.0.0.1 or ::1 is replaced by `localhost` (only the host),
|
|
221
|
+
* and any other IP literal is refused on a Node that refuses an IP servername. A `+discover` string is left as written.
|
|
222
|
+
*/
|
|
223
|
+
tlsHostRule(raw) {
|
|
224
|
+
const parts = splitAuthority(raw);
|
|
225
|
+
if (parts === undefined || /^kurrentdb\+discover:/i.test(raw) || !tlsOn(raw))
|
|
226
|
+
return { target: raw };
|
|
227
|
+
const major = this.options.nodeMajor ?? Number(process.versions.node.split(".")[0]);
|
|
228
|
+
let refusal;
|
|
229
|
+
const hosts = parts.hosts.map((entry) => {
|
|
230
|
+
const { host, port } = splitHost(entry);
|
|
231
|
+
if (isIP(host) === 0)
|
|
232
|
+
return entry;
|
|
233
|
+
const ip = canonicalIp(host);
|
|
234
|
+
if (ip === "127.0.0.1" || ip === "::1")
|
|
235
|
+
return `localhost${port}`;
|
|
236
|
+
if (major >= IP_SERVERNAME_REFUSED_FROM) {
|
|
237
|
+
refusal ??= new KurrentAdapterError("TLS_HOST_UNSUPPORTED", `the host ${ip} is an IP address and the connection string has tls=true: Node ${major} refuses an IP address as the TLS server name; use a hostname the certificate names, or tls=false`);
|
|
238
|
+
}
|
|
239
|
+
return entry;
|
|
240
|
+
});
|
|
241
|
+
return { target: parts.head + hosts.join(",") + parts.tail, ...(refusal !== undefined ? { refusal } : {}) };
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* SPEC-ADPKUR-005, in this order: two connection sources or a mixed `system` are OPTIONS_INVALID before any file is read;
|
|
245
|
+
* then each named file is read (CREDENTIAL_FILE_UNREADABLE before any connection); then the TLS host rule and the credentials.
|
|
246
|
+
*/
|
|
247
|
+
resolveConnection() {
|
|
248
|
+
const o = this.options;
|
|
249
|
+
const optionsRefusal = this.optionsRule();
|
|
250
|
+
if (optionsRefusal !== undefined)
|
|
251
|
+
return { target: "", refusal: optionsRefusal };
|
|
252
|
+
let raw;
|
|
253
|
+
if (o.connectionStringFile !== undefined) {
|
|
254
|
+
const read = readCredentialFile("connectionStringFile", o.connectionStringFile);
|
|
255
|
+
if (read.refusal !== undefined)
|
|
256
|
+
return { target: "", refusal: read.refusal };
|
|
257
|
+
raw = read.value;
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
raw = o.connectionString ?? (o.connectionStringEnv !== undefined ? process.env[o.connectionStringEnv] : undefined);
|
|
261
|
+
}
|
|
262
|
+
let password;
|
|
263
|
+
if (o.system !== undefined && "passwordFile" in o.system) {
|
|
264
|
+
const read = readCredentialFile("system.passwordFile", o.system.passwordFile);
|
|
265
|
+
if (read.refusal !== undefined)
|
|
266
|
+
return { target: "", refusal: read.refusal };
|
|
267
|
+
password = read.value;
|
|
268
|
+
}
|
|
269
|
+
if (raw === undefined || raw === "") {
|
|
270
|
+
throw new Error(`the kurrent service '${"key"}' has no connectionString (or connectionStringEnv naming a set variable, or connectionStringFile)`);
|
|
271
|
+
}
|
|
272
|
+
const { target, refusal } = this.tlsHostRule(raw);
|
|
273
|
+
return { target: this.withCredentials(target, password), ...(refusal !== undefined ? { refusal } : {}) };
|
|
274
|
+
}
|
|
275
|
+
/** One connection source, and one form of `system` (SPEC-ADPKUR-005); no file is read here. */
|
|
276
|
+
optionsRule() {
|
|
277
|
+
const o = this.options;
|
|
278
|
+
// connectionString and connectionStringEnv together keep SPEC-ADPKUR-001's rule (the literal wins); a file with either is two sources.
|
|
279
|
+
const sources = ["connectionString", "connectionStringEnv", "connectionStringFile"].filter((k) => o[k] !== undefined);
|
|
280
|
+
if (o.connectionStringFile !== undefined && sources.length > 1) {
|
|
281
|
+
return new KurrentAdapterError("OPTIONS_INVALID", `the options name more than one connection source: ${sources.join(", ")}; give exactly one`);
|
|
282
|
+
}
|
|
283
|
+
const s = o.system;
|
|
284
|
+
if (s !== undefined) {
|
|
285
|
+
const env = s.username !== undefined || s.password !== undefined;
|
|
286
|
+
const file = s.user !== undefined || s.passwordFile !== undefined;
|
|
287
|
+
if (env && file) {
|
|
288
|
+
return new KurrentAdapterError("OPTIONS_INVALID", "options.system mixes the variable names (username, password) with user and passwordFile; use one form");
|
|
289
|
+
}
|
|
290
|
+
if (file && (s.user === undefined || s.passwordFile === undefined)) {
|
|
291
|
+
return new KurrentAdapterError("OPTIONS_INVALID", "options.system with a passwordFile needs both user and passwordFile");
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return undefined;
|
|
295
|
+
}
|
|
296
|
+
/** The string the client is created from, no network; a refused host stays as written (setup() throws for it). */
|
|
297
|
+
connectionTarget() {
|
|
298
|
+
return this.resolveConnection().target;
|
|
299
|
+
}
|
|
300
|
+
/** The code setup() would refuse with for the connection string (SPEC-ADPKUR-004), or undefined; no network, never throws. */
|
|
301
|
+
connectionRefusal() {
|
|
302
|
+
return this.resolveConnection().refusal?.code;
|
|
303
|
+
}
|
|
304
|
+
connectionString() {
|
|
305
|
+
const { target, refusal } = this.resolveConnection();
|
|
306
|
+
if (refusal !== undefined)
|
|
307
|
+
throw refusal;
|
|
308
|
+
return target;
|
|
309
|
+
}
|
|
310
|
+
withCredentials(raw, passwordFromFile) {
|
|
311
|
+
const o = this.options;
|
|
312
|
+
if (o.system === undefined)
|
|
313
|
+
return raw;
|
|
314
|
+
let user;
|
|
315
|
+
let pass;
|
|
316
|
+
if ("passwordFile" in o.system) {
|
|
317
|
+
user = o.system.user;
|
|
318
|
+
pass = passwordFromFile;
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
user = process.env[o.system.username];
|
|
322
|
+
pass = process.env[o.system.password];
|
|
323
|
+
}
|
|
324
|
+
if (user === undefined || pass === undefined) {
|
|
325
|
+
const named = "passwordFile" in o.system ? "user and passwordFile" : `the variables ${o.system.username} and ${o.system.password}`;
|
|
326
|
+
throw new Error(`options.system names ${named}, which do not both give a value`);
|
|
327
|
+
}
|
|
328
|
+
const url = new URL(raw);
|
|
329
|
+
url.username = user;
|
|
330
|
+
url.password = pass;
|
|
331
|
+
return url.toString();
|
|
332
|
+
}
|
|
333
|
+
db() {
|
|
334
|
+
if (this.client === undefined) {
|
|
335
|
+
const target = this.connectionString();
|
|
336
|
+
this.client = KurrentDBClient.connectionString(target);
|
|
337
|
+
this.readCredentials = decodedCredentials(target);
|
|
338
|
+
}
|
|
339
|
+
return this.client;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* The instrument's credentials on every read, decoded (SPEC-ADPKUR-005). @kurrent/kurrentdb-client 1.3.2 reads through a native
|
|
343
|
+
* bridge that is handed the connection string and does not percent-decode its user info, so a password holding a character the
|
|
344
|
+
* string must encode (a space, `%`) is refused there although appends, which decode, succeed. Passing the decoded pair per call
|
|
345
|
+
* gives both paths the same identity.
|
|
346
|
+
*/
|
|
347
|
+
readAuth() {
|
|
348
|
+
this.db();
|
|
349
|
+
return this.readCredentials !== undefined ? { credentials: this.readCredentials } : {};
|
|
350
|
+
}
|
|
351
|
+
async setup() {
|
|
352
|
+
// A config refusal, before any connection (SPEC-ADPKUR-004: nodeMajor is an integer, 1 or more).
|
|
353
|
+
const major = this.options.nodeMajor;
|
|
354
|
+
if (major !== undefined && !(typeof major === "number" && Number.isInteger(major) && major >= 1)) {
|
|
355
|
+
throw new KurrentAdapterError("OPTIONS_INVALID", `options.nodeMajor must be an integer, 1 or more; got ${typeof major === "string" ? JSON.stringify(major) : String(major)}`);
|
|
356
|
+
}
|
|
357
|
+
const db = this.db();
|
|
358
|
+
try {
|
|
359
|
+
for await (const _ of db.readAll({ fromPosition: START, maxCount: 1, ...this.readAuth() }))
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
catch (e) {
|
|
363
|
+
if (errorType(e) === "access-denied") {
|
|
364
|
+
throw new KurrentAdapterError("ALL_READ_DENIED", "the instrument credentials cannot read the $all stream");
|
|
365
|
+
}
|
|
366
|
+
throw e;
|
|
367
|
+
}
|
|
368
|
+
if (this.proxy !== undefined)
|
|
369
|
+
this.opened = await this.proxy.open();
|
|
370
|
+
}
|
|
371
|
+
async teardown() {
|
|
372
|
+
this.windowOpen = false;
|
|
373
|
+
this.cursor = undefined;
|
|
374
|
+
try {
|
|
375
|
+
if (this.proxy !== undefined)
|
|
376
|
+
await this.proxy.close();
|
|
377
|
+
}
|
|
378
|
+
finally {
|
|
379
|
+
this.opened = undefined;
|
|
380
|
+
const client = this.client;
|
|
381
|
+
this.client = undefined;
|
|
382
|
+
if (client !== undefined)
|
|
383
|
+
await client.dispose().catch(() => { });
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
// ── reading $all ──────────────────────────────────────────────────────────
|
|
387
|
+
/**
|
|
388
|
+
* Read `$all` forwards from the cursor with a server-side stream-name prefix filter. Namespace events are
|
|
389
|
+
* accumulated as captured records (instrument events and system events other than the kept ones are
|
|
390
|
+
* dropped); the cursor advances past everything seen. Returns the position of the last event seen
|
|
391
|
+
* (the fence stream included when asked for), if any.
|
|
392
|
+
*/
|
|
393
|
+
async drain(withFence, deadlineMs) {
|
|
394
|
+
const db = this.db();
|
|
395
|
+
const prefixes = withFence ? [this.prefix, this.metaPrefix, this.fenceStream] : [this.prefix, this.metaPrefix];
|
|
396
|
+
const from = this.cursor;
|
|
397
|
+
const fromPosition = from ?? START;
|
|
398
|
+
const options = {
|
|
399
|
+
fromPosition,
|
|
400
|
+
maxCount: WHOLE_LOG,
|
|
401
|
+
filter: streamNameFilter({ prefixes }),
|
|
402
|
+
...(deadlineMs !== undefined ? { deadline: deadlineMs } : {}),
|
|
403
|
+
...this.readAuth(),
|
|
404
|
+
};
|
|
405
|
+
let last;
|
|
406
|
+
for await (const resolved of db.readAll(options)) {
|
|
407
|
+
const event = resolved.event;
|
|
408
|
+
if (event === undefined)
|
|
409
|
+
continue;
|
|
410
|
+
const position = event.position;
|
|
411
|
+
// fromPosition is inclusive: skip what the cursor already passed.
|
|
412
|
+
if (from !== undefined && !after(position, from))
|
|
413
|
+
continue;
|
|
414
|
+
last = position;
|
|
415
|
+
this.cursor = position;
|
|
416
|
+
const key = this.relative(event.streamId);
|
|
417
|
+
if (key === undefined)
|
|
418
|
+
continue;
|
|
419
|
+
if (this.isInstrument(event.metadata))
|
|
420
|
+
continue;
|
|
421
|
+
if (event.type.startsWith("$") && !KEPT_SYSTEM_TYPES.has(event.type))
|
|
422
|
+
continue;
|
|
423
|
+
if (isServerTruncateBefore(event.type, event.data))
|
|
424
|
+
continue;
|
|
425
|
+
if (event.isJson === false)
|
|
426
|
+
continue;
|
|
427
|
+
this.captured.push({
|
|
428
|
+
type: event.type,
|
|
429
|
+
key,
|
|
430
|
+
payload: (event.data ?? {}),
|
|
431
|
+
timestamp: new Date(event.created).getTime(),
|
|
432
|
+
metadata: { revision: Number(event.revision), commitPosition: Number(position.commit) },
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
return last;
|
|
436
|
+
}
|
|
437
|
+
isInstrument(metadata) {
|
|
438
|
+
return typeof metadata === "object" && metadata !== null && metadata.feat === "instrument";
|
|
439
|
+
}
|
|
440
|
+
async appendMarker(stream, deadline) {
|
|
441
|
+
const result = await this.db().appendToStream(stream, jsonEvent({ type: "feat.marker", data: {}, metadata: INSTRUMENT_MARKER }), { streamState: ANY, ...(deadline !== undefined ? { deadline } : {}) });
|
|
442
|
+
if (result.position === undefined)
|
|
443
|
+
throw new Error(`the append to '${stream}' reported no log position`);
|
|
444
|
+
return result.position;
|
|
445
|
+
}
|
|
446
|
+
// ── the window ────────────────────────────────────────────────────────────
|
|
447
|
+
async startCapture() {
|
|
448
|
+
this.cursor = await this.appendMarker(this.fenceStream);
|
|
449
|
+
this.captured = [];
|
|
450
|
+
this.windowOpen = true;
|
|
451
|
+
}
|
|
452
|
+
async peekCapture() {
|
|
453
|
+
if (!this.windowOpen)
|
|
454
|
+
return [];
|
|
455
|
+
await this.drain(false);
|
|
456
|
+
return [...this.captured];
|
|
457
|
+
}
|
|
458
|
+
async stopCapture() {
|
|
459
|
+
if (!this.windowOpen)
|
|
460
|
+
return [];
|
|
461
|
+
await this.drain(false);
|
|
462
|
+
const records = this.captured;
|
|
463
|
+
this.captured = [];
|
|
464
|
+
this.windowOpen = false;
|
|
465
|
+
this.cursor = undefined;
|
|
466
|
+
return records;
|
|
467
|
+
}
|
|
468
|
+
async settle() {
|
|
469
|
+
if (!this.windowOpen)
|
|
470
|
+
return false;
|
|
471
|
+
const deadline = Date.now() + this.settleTimeoutMs;
|
|
472
|
+
try {
|
|
473
|
+
const marker = await within(this.appendMarker(this.fenceStream, Math.max(this.settleTimeoutMs, 1)), Math.max(this.settleTimeoutMs, 1));
|
|
474
|
+
while (Date.now() < deadline) {
|
|
475
|
+
const remaining = Math.max(deadline - Date.now(), 1);
|
|
476
|
+
const seen = await within(this.drain(true, remaining), remaining);
|
|
477
|
+
if (seen !== undefined && !after(marker, seen))
|
|
478
|
+
return true;
|
|
479
|
+
await sleep(POLL_MS);
|
|
480
|
+
}
|
|
481
|
+
return false;
|
|
482
|
+
}
|
|
483
|
+
catch {
|
|
484
|
+
return false;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
// ── state ─────────────────────────────────────────────────────────────────
|
|
488
|
+
/** Every stream the namespace has ever held, found by an `$all` prefix scan (projections are not required). */
|
|
489
|
+
async namespaceStreams() {
|
|
490
|
+
const seen = new Set();
|
|
491
|
+
const withMetadata = new Set();
|
|
492
|
+
for await (const resolved of this.db().readAll({
|
|
493
|
+
fromPosition: START,
|
|
494
|
+
maxCount: WHOLE_LOG,
|
|
495
|
+
filter: streamNameFilter({ prefixes: [this.prefix, this.metaPrefix] }),
|
|
496
|
+
...this.readAuth(),
|
|
497
|
+
})) {
|
|
498
|
+
const id = resolved.event?.streamId;
|
|
499
|
+
if (id === undefined)
|
|
500
|
+
continue;
|
|
501
|
+
if (id.startsWith(this.metaPrefix)) {
|
|
502
|
+
const stream = `${this.prefix}${id.slice(this.metaPrefix.length)}`;
|
|
503
|
+
withMetadata.add(stream);
|
|
504
|
+
seen.add(stream);
|
|
505
|
+
}
|
|
506
|
+
else if (id.startsWith(this.prefix))
|
|
507
|
+
seen.add(id);
|
|
508
|
+
}
|
|
509
|
+
return { streams: [...seen], withMetadata };
|
|
510
|
+
}
|
|
511
|
+
async read(query) {
|
|
512
|
+
const hinted = query.expect?.map((e) => e.key?.stream);
|
|
513
|
+
const names = hinted !== undefined && hinted.length > 0 && hinted.every((s) => typeof s === "string")
|
|
514
|
+
? [...new Set(hinted)].map((s) => this.full(s))
|
|
515
|
+
: (await this.namespaceStreams()).streams;
|
|
516
|
+
const records = [];
|
|
517
|
+
for (const name of names) {
|
|
518
|
+
try {
|
|
519
|
+
for await (const resolved of this.db().readStream(name, { maxCount: WHOLE_LOG, ...this.readAuth() })) {
|
|
520
|
+
const event = resolved.event;
|
|
521
|
+
if (event === undefined || this.isInstrument(event.metadata))
|
|
522
|
+
continue;
|
|
523
|
+
if (event.type.startsWith("$") || event.isJson === false)
|
|
524
|
+
continue;
|
|
525
|
+
records.push({
|
|
526
|
+
type: event.type,
|
|
527
|
+
key: name.slice(this.prefix.length),
|
|
528
|
+
payload: (event.data ?? {}),
|
|
529
|
+
timestamp: new Date(event.created).getTime(),
|
|
530
|
+
metadata: { revision: Number(event.revision) },
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
catch (e) {
|
|
535
|
+
// A soft-deleted (or never written) stream reads as empty; state is not resurrected from $all.
|
|
536
|
+
const t = errorType(e);
|
|
537
|
+
if (t !== "stream-not-found" && t !== "stream-deleted")
|
|
538
|
+
throw e;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
return records;
|
|
542
|
+
}
|
|
543
|
+
/** The stream of a seed: `values.stream` when the record names one, else its type. */
|
|
544
|
+
async seed(records) {
|
|
545
|
+
for (const r of records) {
|
|
546
|
+
const stream = typeof r.values.stream === "string" ? r.values.stream : r.type;
|
|
547
|
+
await this.db().appendToStream(this.full(stream), jsonEvent({ type: r.type, data: r.values }), { streamState: ANY });
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
// ── faults ────────────────────────────────────────────────────────────────
|
|
551
|
+
async fault(arm) {
|
|
552
|
+
const where = `${arm.operation}.${arm.fault}`;
|
|
553
|
+
const entry = this.faults[arm.operation]?.[arm.fault];
|
|
554
|
+
if (entry === undefined) {
|
|
555
|
+
throw new KurrentAdapterError("FAULT_UNSUPPORTED", `the fault '${where}' is not in the catalog (${this.describeCatalog()})`);
|
|
556
|
+
}
|
|
557
|
+
if (arm.times !== "reset") {
|
|
558
|
+
const asked = arm.times === 1 ? "once" : `times ${arm.times}`;
|
|
559
|
+
throw new KurrentAdapterError("FAULT_UNSUPPORTED", `the fault '${where}' declares only until reset, not ${asked}`);
|
|
560
|
+
}
|
|
561
|
+
if (arm.operation === "Connection") {
|
|
562
|
+
await this.proxy.arm(arm.fault);
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
const stream = arm.detail?.stream;
|
|
566
|
+
if (typeof stream !== "string" || stream === "") {
|
|
567
|
+
throw new KurrentAdapterError("FAULT_UNSUPPORTED", `the fault '${where}' needs a detail { stream } naming the stream it applies to`);
|
|
568
|
+
}
|
|
569
|
+
const name = this.full(stream);
|
|
570
|
+
if (arm.fault === "WRONG_EXPECTED_VERSION") {
|
|
571
|
+
// A stream the system expects NOT to exist must exist: the instrument's placeholder is never a record.
|
|
572
|
+
await this.db().appendToStream(name, jsonEvent({ type: "feat.fault", data: {}, metadata: INSTRUMENT_MARKER }), { streamState: ANY });
|
|
573
|
+
}
|
|
574
|
+
else {
|
|
575
|
+
// The write role of the stream names a role nobody holds. $admins bypass ACLs, so the system must not be admin.
|
|
576
|
+
await this.db().setStreamMetadata(name, { acl: { writeRoles: ["nobody"] } });
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
describeCatalog() {
|
|
580
|
+
return Object.entries(this.faults)
|
|
581
|
+
.flatMap(([op, faults]) => Object.keys(faults).map((f) => `${op}.${f}`))
|
|
582
|
+
.join(", ");
|
|
583
|
+
}
|
|
584
|
+
async reset() {
|
|
585
|
+
if (this.proxy !== undefined && this.opened !== undefined)
|
|
586
|
+
await this.proxy.disarm();
|
|
587
|
+
const { streams, withMetadata } = await this.namespaceStreams();
|
|
588
|
+
for (const name of streams) {
|
|
589
|
+
if (withMetadata.has(name))
|
|
590
|
+
await this.db().setStreamMetadata(name, {});
|
|
591
|
+
try {
|
|
592
|
+
await this.db().deleteStream(name);
|
|
593
|
+
}
|
|
594
|
+
catch (e) {
|
|
595
|
+
if (errorType(e) !== "stream-not-found")
|
|
596
|
+
throw e;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
this.windowOpen = false;
|
|
600
|
+
this.cursor = undefined;
|
|
601
|
+
this.captured = [];
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
export function createAdapter(config) {
|
|
605
|
+
return new KurrentAdapter(config);
|
|
606
|
+
}
|
|
607
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uGAAuG;AACvG,EAAE;AACF,mGAAmG;AACnG,uGAAuG;AACvG,wGAAwG;AACxG,8FAA8F;AAC9F,EAAE;AACF,iGAAiG;AACjG,sGAAsG;AACtG,kDAAkD;AAElD,OAAO,EACL,GAAG,EACH,eAAe,EACf,KAAK,EACL,SAAS,EACT,gBAAgB,GACjB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,IAAI,MAAM,WA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AAM,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;QACrF,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAChE,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;YAC3B,IAAI,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC;gBAAE,MAAM,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YACxE,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;YACrC,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,IAAI,SAAS,CAAC,CAAC,CAAC,KAAK,kBAAkB;oBAAE,MAAM,CAAC,CAAC;YACnD,CAAC;QACH,CAAC;QACD,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;QACxB,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;IACrB,CAAC;CACF;AAED,MAAM,UAAU,aAAa,CAAC,MAA+B;IAC3D,OAAO,IAAI,cAAc,CAAC,MAAuB,CAAC,CAAC;AACrD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mmmnt/feat-adapter-kurrent",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "KurrentDB service adapter for Feat: the $all log is the capture window, a fence marker read back through it makes settle truthful, and the namespace's streams are the state",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@kurrent/kurrentdb-client": "1.3.2",
|
|
13
|
+
"@mmmnt/feat-fault-proxy": "^0.1.0",
|
|
14
|
+
"@mmmnt/feat-types": "^0.3.0"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"typescript": "^5.8.0",
|
|
18
|
+
"vitest": "^3.2.0",
|
|
19
|
+
"@mmmnt/feat-adapter-kit": "^0.1.7",
|
|
20
|
+
"@mmmnt/feat-runtime": "^0.3.0"
|
|
21
|
+
},
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=20"
|
|
24
|
+
},
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/mmmnt/feature.git",
|
|
29
|
+
"directory": "adapters/kurrent"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/mmmnt/feature#readme",
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/mmmnt/feature/issues"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsc -p tsconfig.json",
|
|
40
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
41
|
+
"test": "vitest run --exclude '**/observe.test.ts' --exclude '**/transport.test.ts' --exclude '**/broker-loss.test.ts' --exclude '**/node26-tls-host.test.ts' --exclude '**/credential-files.test.ts' --passWithNoTests"
|
|
42
|
+
}
|
|
6
43
|
}
|