@crvouga/mockingbird-service-rxvortex 3.1.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -2
- package/DISCOVERY.md +23 -0
- package/README.md +14 -11
- package/dist/{chunk-QMHFS4QB.js → chunk-DAE44LUH.js} +139 -26
- package/dist/chunk-DAE44LUH.js.map +7 -0
- package/dist/chunk-U2SZUONL.js +6312 -0
- package/dist/chunk-U2SZUONL.js.map +7 -0
- package/dist/cli.js +2 -2
- package/dist/index.d.ts +435 -121
- package/dist/index.js +1 -1
- package/dist/server.d.ts +819 -188
- package/dist/server.js +2 -2
- package/package.json +3 -2
- package/dist/chunk-EQNZ2CZA.js +0 -4432
- package/dist/chunk-EQNZ2CZA.js.map +0 -7
- package/dist/chunk-QMHFS4QB.js.map +0 -7
package/dist/server.d.ts
CHANGED
|
@@ -1,34 +1,16 @@
|
|
|
1
1
|
import { Server } from 'node:http';
|
|
2
2
|
import { Hono } from 'hono';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
type MountedAPI$1 = FetchAPI$2 & {
|
|
5
|
+
readonly prefix: string;
|
|
6
|
+
GET: FetchHandler$1;
|
|
7
|
+
POST: FetchHandler$1;
|
|
8
|
+
PUT: FetchHandler$1;
|
|
9
|
+
PATCH: FetchHandler$1;
|
|
10
|
+
DELETE: FetchHandler$1;
|
|
11
|
+
HEAD: FetchHandler$1;
|
|
12
|
+
OPTIONS: FetchHandler$1;
|
|
10
13
|
};
|
|
11
|
-
/**
|
|
12
|
-
* Prepared statement bound to a {@link SqliteClient}.
|
|
13
|
-
*
|
|
14
|
-
* Pass bind values as rest arguments on each call (no sticky `bind()`).
|
|
15
|
-
*/
|
|
16
|
-
interface SqliteStatement$2 {
|
|
17
|
-
run(...params: SqliteValue$2[]): SqliteRunResult$2;
|
|
18
|
-
all<T = Record<string, unknown>>(...params: SqliteValue$2[]): T[];
|
|
19
|
-
get<T = Record<string, unknown>>(...params: SqliteValue$2[]): T | undefined;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Sync SQLite client port owned by Mockingbird.
|
|
23
|
-
*
|
|
24
|
-
* Duck-typed so `@crvouga/mockingbird-service-sqlite` `Database`, better-sqlite3, and wrapped
|
|
25
|
-
* `bun:sqlite` instances all work when they expose this surface.
|
|
26
|
-
*/
|
|
27
|
-
interface SqliteClient$2 {
|
|
28
|
-
exec(sql: string): void;
|
|
29
|
-
prepare(sql: string): SqliteStatement$2;
|
|
30
|
-
transaction<T>(fn: () => T): T;
|
|
31
|
-
}
|
|
32
14
|
|
|
33
15
|
/** A stable identifier for a point in a {@link Timeline}. */
|
|
34
16
|
type CheckpointId$1 = string;
|
|
@@ -119,6 +101,37 @@ declare class Timeline$1<T> {
|
|
|
119
101
|
interface FetchAPI$2 {
|
|
120
102
|
fetch(request: Request): Promise<Response>;
|
|
121
103
|
}
|
|
104
|
+
/** A bare function form of {@link FetchAPI}, compatible with `Bun.serve`, workerd, and Deno. */
|
|
105
|
+
type FetchHandler$1 = (request: Request) => Promise<Response>;
|
|
106
|
+
|
|
107
|
+
/** Bind values accepted by Mockingbird's SQLite port (matches sqlite-mem / better-sqlite3). */
|
|
108
|
+
type SqliteValue$2 = null | number | bigint | string | Uint8Array | boolean;
|
|
109
|
+
/** Mutation counters returned by {@link SqliteStatement.run}. */
|
|
110
|
+
type SqliteRunResult$2 = {
|
|
111
|
+
changes: number;
|
|
112
|
+
lastInsertRowid: number | bigint;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Prepared statement bound to a {@link SqliteClient}.
|
|
116
|
+
*
|
|
117
|
+
* Pass bind values as rest arguments on each call (no sticky `bind()`).
|
|
118
|
+
*/
|
|
119
|
+
interface SqliteStatement$2 {
|
|
120
|
+
run(...params: SqliteValue$2[]): SqliteRunResult$2;
|
|
121
|
+
all<T = Record<string, unknown>>(...params: SqliteValue$2[]): T[];
|
|
122
|
+
get<T = Record<string, unknown>>(...params: SqliteValue$2[]): T | undefined;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Sync SQLite client port owned by Mockingbird.
|
|
126
|
+
*
|
|
127
|
+
* Duck-typed so `@crvouga/mockingbird-service-sqlite` `Database`, better-sqlite3, and wrapped
|
|
128
|
+
* `bun:sqlite` instances all work when they expose this surface.
|
|
129
|
+
*/
|
|
130
|
+
interface SqliteClient$2 {
|
|
131
|
+
exec(sql: string): void;
|
|
132
|
+
prepare(sql: string): SqliteStatement$2;
|
|
133
|
+
transaction<T>(fn: () => T): T;
|
|
134
|
+
}
|
|
122
135
|
|
|
123
136
|
/**
|
|
124
137
|
* The single source of time for a service.
|
|
@@ -132,7 +145,7 @@ type ClockState$1 = {
|
|
|
132
145
|
now: number;
|
|
133
146
|
/** True while time does not advance on its own. */
|
|
134
147
|
frozen: boolean;
|
|
135
|
-
/** Milliseconds
|
|
148
|
+
/** Milliseconds a running clock adds to its underlying source. `0` while frozen. */
|
|
136
149
|
offsetMs: number;
|
|
137
150
|
};
|
|
138
151
|
type Clock$1 = {
|
|
@@ -168,7 +181,10 @@ type Rng$1 = {
|
|
|
168
181
|
state(): number;
|
|
169
182
|
/** Restore a state previously returned by {@link state}. */
|
|
170
183
|
setState(state: number): void;
|
|
171
|
-
seed
|
|
184
|
+
/** Restart the stream from a new seed. `reset` then returns to this seed. */
|
|
185
|
+
reseed(seed: number | string): void;
|
|
186
|
+
/** The seed the stream currently starts from. */
|
|
187
|
+
readonly seed: number;
|
|
172
188
|
};
|
|
173
189
|
|
|
174
190
|
/**
|
|
@@ -177,44 +193,83 @@ type Rng$1 = {
|
|
|
177
193
|
* This is how a suite reaches the vendor's failure modes without the vendor: the
|
|
178
194
|
* quota error that only appears when a shared sandbox is full, the 429 that only
|
|
179
195
|
* appears under load, the 5xx that proves a retry path works.
|
|
196
|
+
*
|
|
197
|
+
* A rule has three parts. What it **matches** (`operationId`, `method`, `path`, …), **when**
|
|
198
|
+
* it fires among the matching requests (`after`, `every`, `count`, `rate`, `from`, `until`),
|
|
199
|
+
* and what it **does** (`status`, `delay`, `timeout`, `drop`, `truncate`, `effect`).
|
|
180
200
|
*/
|
|
181
201
|
type FaultRule$1 = {
|
|
182
|
-
/** Stable id, so a suite can retire exactly the rule it added. */
|
|
202
|
+
/** Stable id, so a suite can retire exactly the rule it added. Unique within a namespace. */
|
|
183
203
|
id: string;
|
|
184
204
|
/** Fault only this operation. Omit to match every operation. */
|
|
185
205
|
operationId?: string;
|
|
186
206
|
/** Fault only this HTTP method, case-insensitive. Omit to match every method. */
|
|
187
207
|
method?: string;
|
|
208
|
+
/** Fault only this exact path. */
|
|
209
|
+
path?: string;
|
|
188
210
|
/** Fault only paths starting with this prefix. Omit to match every path. */
|
|
189
211
|
pathPrefix?: string;
|
|
212
|
+
/** Fault only paths matching this regular expression (JavaScript syntax, unanchored). */
|
|
213
|
+
pathPattern?: string;
|
|
214
|
+
/** Fault only requests carrying these headers. `"*"` matches any value. */
|
|
215
|
+
requestHeaders?: Record<string, string>;
|
|
216
|
+
/** Fault only requests carrying these query parameters. `"*"` matches any value. */
|
|
217
|
+
query?: Record<string, string>;
|
|
190
218
|
/**
|
|
191
219
|
* Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
|
|
192
220
|
* an in-process caller usually wants, and what a parallel worker usually does not:
|
|
193
221
|
* rules added through `POST /__admin/faults` default to the calling namespace.
|
|
194
222
|
*/
|
|
195
223
|
namespace?: string;
|
|
224
|
+
/** Let this many matching requests through first. */
|
|
225
|
+
after?: number;
|
|
226
|
+
/** Then fault only every nth matching request: `3` faults the 3rd, 6th, 9th. */
|
|
227
|
+
every?: number;
|
|
228
|
+
/** Retire the rule after this many faults. Omit to keep it until removed. */
|
|
229
|
+
count?: number;
|
|
230
|
+
/** Fault this fraction of the remaining requests, `0`–`1`, drawn from the seed. Default `1`. */
|
|
231
|
+
rate?: number;
|
|
196
232
|
/**
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
|
|
233
|
+
* Fault only from this instant on the namespace clock. A duration (`"5m"`) counts from the
|
|
234
|
+
* clock when the rule was added. Listed as epoch ms.
|
|
235
|
+
*/
|
|
236
|
+
from?: Instant$1 | Duration$1;
|
|
237
|
+
/** Stop faulting at this instant on the namespace clock. A duration counts from when added. */
|
|
238
|
+
until?: Instant$1 | Duration$1;
|
|
239
|
+
/**
|
|
240
|
+
* Status of the injected response. Omit for a rule that only delays, times out, drops,
|
|
241
|
+
* truncates, or switches on an `effect`: the request then still reaches the service.
|
|
200
242
|
*/
|
|
201
243
|
status?: number;
|
|
202
244
|
/** Response body, serialized as JSON. A string is sent as-is. */
|
|
203
245
|
body?: unknown;
|
|
246
|
+
/** Response headers. */
|
|
204
247
|
headers?: Record<string, string>;
|
|
205
|
-
/**
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
rate?: number;
|
|
209
|
-
/** Hold the response back this long, to exercise timeouts. */
|
|
248
|
+
/** Hold the response back this long. Listed as `delayMs`. */
|
|
249
|
+
delay?: Duration$1;
|
|
250
|
+
/** `delay`, in milliseconds. */
|
|
210
251
|
delayMs?: number;
|
|
211
252
|
/** Alias of `delayMs`. */
|
|
212
253
|
latencyMs?: number;
|
|
254
|
+
/** Extra seeded delay in `[0, jitter]`. Listed as `jitterMs`. */
|
|
255
|
+
jitter?: Duration$1;
|
|
256
|
+
jitterMs?: number;
|
|
257
|
+
/**
|
|
258
|
+
* Never answer: hold the request this long, then drop the connection. Listed as
|
|
259
|
+
* `timeoutMs`. With virtual time the wait is spent on the mock clock.
|
|
260
|
+
*/
|
|
261
|
+
timeout?: Duration$1;
|
|
262
|
+
timeoutMs?: number;
|
|
213
263
|
/**
|
|
214
264
|
* Drop the connection instead of answering: an in-process `fetch` rejects with a
|
|
215
265
|
* `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
|
|
216
266
|
*/
|
|
217
267
|
drop?: boolean;
|
|
268
|
+
/**
|
|
269
|
+
* Cut the response body off after this many bytes: the status and headers arrive, then
|
|
270
|
+
* the connection dies mid-body.
|
|
271
|
+
*/
|
|
272
|
+
truncate?: number;
|
|
218
273
|
/**
|
|
219
274
|
* A named service behaviour to switch on for the matching request instead of (or
|
|
220
275
|
* before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
|
|
@@ -223,8 +278,8 @@ type FaultRule$1 = {
|
|
|
223
278
|
effect?: string;
|
|
224
279
|
/** Parameters for `effect`. */
|
|
225
280
|
params?: Record<string, unknown>;
|
|
226
|
-
/**
|
|
227
|
-
|
|
281
|
+
/** The preset this rule was expanded from, if any. */
|
|
282
|
+
fromPreset?: string;
|
|
228
283
|
};
|
|
229
284
|
/** A fault that fired for one request. */
|
|
230
285
|
type FaultHit$1 = {
|
|
@@ -232,6 +287,10 @@ type FaultHit$1 = {
|
|
|
232
287
|
/** The injected response; absent when the rule only delays, drops, or sets an effect. */
|
|
233
288
|
response?: Response;
|
|
234
289
|
drop?: boolean;
|
|
290
|
+
/** Set with `drop` when the rule held the request for its `timeout` first. */
|
|
291
|
+
timeout?: boolean;
|
|
292
|
+
/** Bytes of response body to let through before the connection dies. */
|
|
293
|
+
truncate?: number;
|
|
235
294
|
effect?: {
|
|
236
295
|
name: string;
|
|
237
296
|
params: Record<string, unknown>;
|
|
@@ -243,38 +302,200 @@ type FaultCandidate$1 = {
|
|
|
243
302
|
method: string;
|
|
244
303
|
path: string;
|
|
245
304
|
namespace: string;
|
|
305
|
+
/** Request headers and query, for rules that match on them. */
|
|
306
|
+
headers?: Headers;
|
|
307
|
+
query?: URLSearchParams;
|
|
308
|
+
/** The namespace clock, for `from` / `until`. Rules with a window are skipped without it. */
|
|
309
|
+
now?: number;
|
|
310
|
+
/** How to spend a delay for this request. Default: the registry's own sleep. */
|
|
311
|
+
wait?: (ms: number) => Promise<void>;
|
|
312
|
+
};
|
|
313
|
+
/** A stored rule and how often it was consulted. */
|
|
314
|
+
type FaultListing$1 = FaultRule$1 & {
|
|
315
|
+
/** Faults left before the rule retires. `null` when it has no `count`. */
|
|
316
|
+
remaining: number | null;
|
|
317
|
+
/** Times the rule faulted a request. */
|
|
318
|
+
hits: number;
|
|
319
|
+
/** Requests that matched the rule, faulted or not. */
|
|
320
|
+
seen: number;
|
|
321
|
+
};
|
|
322
|
+
/** A namespace's own rules, with their counters, in the order they are tried. */
|
|
323
|
+
type FaultSnapshot$1 = {
|
|
324
|
+
/**
|
|
325
|
+
* `position` is how many `"*"` rules are tried before the rule, which is what its place
|
|
326
|
+
* in the order means to a request and holds in any process.
|
|
327
|
+
*/
|
|
328
|
+
rules: (FaultListing$1 & {
|
|
329
|
+
position?: number;
|
|
330
|
+
})[];
|
|
331
|
+
/** How many `fault_<n>` ids the namespace has handed out. */
|
|
332
|
+
nextId?: number;
|
|
246
333
|
};
|
|
247
334
|
type FaultRegistry$1 = {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
rules: (FaultRule$1 & {
|
|
251
|
-
remaining: number | null;
|
|
252
|
-
hits: number;
|
|
253
|
-
position: number;
|
|
254
|
-
})[];
|
|
255
|
-
rngState: number;
|
|
256
|
-
};
|
|
335
|
+
snapshot(namespace: string): FaultSnapshot$1;
|
|
336
|
+
/** Add a rule, or replace the rule with the same id in the same namespace. */
|
|
257
337
|
add(rule: FaultRule$1): FaultRule$1;
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
})[];
|
|
270
|
-
rngState: number;
|
|
271
|
-
}): void;
|
|
338
|
+
/** The next unused `fault_<n>` id in `namespace`. */
|
|
339
|
+
nextId(namespace: string): string;
|
|
340
|
+
/** Every rule, or the rules a namespace's requests can hit: its own and the global ones. */
|
|
341
|
+
list(namespace?: string): FaultListing$1[];
|
|
342
|
+
get(id: string, namespace?: string): FaultListing$1 | undefined;
|
|
343
|
+
/** Remove a rule by id: from `namespace` (its own, then a global one), or wherever it is. */
|
|
344
|
+
remove(id: string, namespace?: string): boolean;
|
|
345
|
+
/** Remove every rule, or one namespace's own rules. */
|
|
346
|
+
clear(namespace?: string): void;
|
|
347
|
+
/** Replace a namespace's own rules with a snapshot's, wherever the snapshot was taken. */
|
|
348
|
+
restore(namespace: string, state: FaultSnapshot$1): void;
|
|
272
349
|
/**
|
|
273
350
|
* Every fault this request should get, in rule order, stopping at the first that answers
|
|
274
351
|
* or drops (effect-only and delay-only rules let later rules match too). Consumes one of
|
|
275
352
|
* each matching rule's remaining uses.
|
|
276
353
|
*/
|
|
277
354
|
take(candidate: FaultCandidate$1): Promise<FaultHit$1[]>;
|
|
355
|
+
/**
|
|
356
|
+
* Fire these rules at one request without storing them: no matching, no schedule, in order,
|
|
357
|
+
* stopping at the first that answers or drops. Jitter draws from the namespace's stream.
|
|
358
|
+
*/
|
|
359
|
+
fire(rules: readonly FaultRule$1[], candidate: FaultCandidate$1): Promise<FaultHit$1[]>;
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* The admin controls every mock shares, as one document.
|
|
364
|
+
*
|
|
365
|
+
* The same shape is accepted in three places, and means the same thing in each:
|
|
366
|
+
*
|
|
367
|
+
* - at boot: `createRuntime({ adminControls })`, `serve --admin-controls`,
|
|
368
|
+
* `MOCKINGBIRD_ADMIN_CONTROLS`
|
|
369
|
+
* - over HTTP: `PUT /__admin/controls`
|
|
370
|
+
* - per request: the `x-mockingbird-*` headers in {@link CONTROL_HEADERS}
|
|
371
|
+
*
|
|
372
|
+
* Every control is deterministic: given the same seed, clock and requests, a mock answers
|
|
373
|
+
* the same bytes. Nothing here reads the wall clock or `Math.random`.
|
|
374
|
+
*/
|
|
375
|
+
/** Milliseconds, or a string like `"250ms"`, `"2s"`, `"15m"`, `"1h"`, `"3d"`. */
|
|
376
|
+
type Duration$1 = number | string;
|
|
377
|
+
/** Epoch milliseconds, or an ISO-8601 string. */
|
|
378
|
+
type Instant$1 = number | string;
|
|
379
|
+
type ClockControls$1 = {
|
|
380
|
+
/** Move the clock to this instant. */
|
|
381
|
+
now?: Instant$1;
|
|
382
|
+
/** Stop time. A frozen clock moves only when told to, so timestamps replay exactly. */
|
|
383
|
+
frozen?: boolean;
|
|
384
|
+
/**
|
|
385
|
+
* Step the clock forward by this much before every vendor request. With a frozen clock
|
|
386
|
+
* each request still gets its own, reproducible timestamp.
|
|
387
|
+
*/
|
|
388
|
+
autoAdvance?: Duration$1;
|
|
389
|
+
};
|
|
390
|
+
/** How long a response takes: a fixed delay plus seeded jitter in `[0, jitter]`. */
|
|
391
|
+
type LatencyRuleInput$1 = {
|
|
392
|
+
delay?: Duration$1;
|
|
393
|
+
jitter?: Duration$1;
|
|
394
|
+
};
|
|
395
|
+
type LatencyControls$1 = LatencyRuleInput$1 & {
|
|
396
|
+
/** Per-operation overrides, keyed by operationId. A bare duration is its `delay`. */
|
|
397
|
+
operations?: Record<string, Duration$1 | LatencyRuleInput$1>;
|
|
398
|
+
};
|
|
399
|
+
/** A fault to add: a rule (the id is assigned when omitted), or a named preset with overrides. */
|
|
400
|
+
type FaultInput$1 = (Omit<FaultRule$1, "id"> & {
|
|
401
|
+
id?: string;
|
|
402
|
+
}) | ({
|
|
403
|
+
preset: string;
|
|
404
|
+
} & Partial<FaultRule$1>);
|
|
405
|
+
/** Identifies a {@link SnapshotDocument}. */
|
|
406
|
+
declare const SNAPSHOT_FORMAT$1 = "mockingbird.snapshot/v1";
|
|
407
|
+
/**
|
|
408
|
+
* A namespace, as portable JSON: what `GET /__admin/snapshots/:id` returns and what
|
|
409
|
+
* `PUT /__admin/snapshots/:id` and the boot `snapshot` control accept. Only `format` and
|
|
410
|
+
* `records` are required, so a hand-written seed file is a valid snapshot.
|
|
411
|
+
*/
|
|
412
|
+
type SnapshotDocument$1 = {
|
|
413
|
+
format: typeof SNAPSHOT_FORMAT$1;
|
|
414
|
+
/** The service that wrote it. A snapshot is rejected by any other service. */
|
|
415
|
+
service?: string;
|
|
416
|
+
/**
|
|
417
|
+
* Stored rows. `seq` orders a collection; omitted, rows keep their listed order. `raw` is
|
|
418
|
+
* the stored text of a row that is not a plain record, and replaces `value` when present.
|
|
419
|
+
*/
|
|
420
|
+
records: {
|
|
421
|
+
collection: string;
|
|
422
|
+
id: string;
|
|
423
|
+
seq?: number;
|
|
424
|
+
value?: unknown;
|
|
425
|
+
raw?: string;
|
|
426
|
+
}[];
|
|
427
|
+
/** Id counters, so the next generated id continues where the snapshot left off. */
|
|
428
|
+
sequences?: {
|
|
429
|
+
name: string;
|
|
430
|
+
kind: string;
|
|
431
|
+
value: number;
|
|
432
|
+
}[];
|
|
433
|
+
clock?: {
|
|
434
|
+
now: number;
|
|
435
|
+
frozen: boolean;
|
|
436
|
+
autoAdvanceMs?: number;
|
|
437
|
+
};
|
|
438
|
+
seed?: number | string;
|
|
439
|
+
/** Positions of the seeded random streams. */
|
|
440
|
+
rng?: {
|
|
441
|
+
state: number;
|
|
442
|
+
faults?: number;
|
|
443
|
+
latency?: number;
|
|
444
|
+
};
|
|
445
|
+
faults?: unknown;
|
|
446
|
+
latency?: unknown;
|
|
447
|
+
virtualTime?: boolean;
|
|
448
|
+
};
|
|
449
|
+
/** Controls for one namespace. */
|
|
450
|
+
type NamespaceControls$1 = {
|
|
451
|
+
/** Seeds every random choice: fault rates, jitter, and whatever the service invents. */
|
|
452
|
+
seed?: number | string;
|
|
453
|
+
clock?: ClockControls$1;
|
|
454
|
+
/**
|
|
455
|
+
* Spend injected waits (latency, fault delays, timeouts) on the mock clock instead of the
|
|
456
|
+
* wall clock: the request returns at once, the clock has moved, and the journal records
|
|
457
|
+
* the wait exactly. Default `false`: waits are real, so a client's own timeout can fire.
|
|
458
|
+
*/
|
|
459
|
+
virtualTime?: boolean;
|
|
460
|
+
/** Baseline response time for every vendor request. A bare duration is its `delay`. */
|
|
461
|
+
latency?: Duration$1 | LatencyControls$1;
|
|
462
|
+
faults?: readonly FaultInput$1[];
|
|
463
|
+
/** Start from this state instead of the service's own seed data. */
|
|
464
|
+
snapshot?: SnapshotDocument$1;
|
|
465
|
+
};
|
|
466
|
+
/** {@link NamespaceControls} for every namespace, with per-namespace overrides. */
|
|
467
|
+
type MockControls$1 = NamespaceControls$1 & {
|
|
468
|
+
/** Vendor credential → namespace, for SDKs that cannot send a namespace header. */
|
|
469
|
+
credentials?: Record<string, string>;
|
|
470
|
+
/** Overrides for named namespaces. A key given here replaces the shared value. */
|
|
471
|
+
namespaces?: Record<string, NamespaceControls$1>;
|
|
472
|
+
};
|
|
473
|
+
/** A latency rule in milliseconds. */
|
|
474
|
+
type LatencyRule$1 = {
|
|
475
|
+
delayMs: number;
|
|
476
|
+
jitterMs: number;
|
|
477
|
+
};
|
|
478
|
+
/** Baseline latency for a namespace, normalized. */
|
|
479
|
+
type LatencyState$1 = LatencyRule$1 & {
|
|
480
|
+
operations: Record<string, LatencyRule$1>;
|
|
481
|
+
};
|
|
482
|
+
/** What {@link controlHeaders} turns into request headers. */
|
|
483
|
+
type ControlHeaderInput$1 = {
|
|
484
|
+
namespace?: string;
|
|
485
|
+
adminKey?: string;
|
|
486
|
+
branch?: string;
|
|
487
|
+
at?: string;
|
|
488
|
+
reset?: boolean;
|
|
489
|
+
restore?: string;
|
|
490
|
+
seed?: number | string;
|
|
491
|
+
time?: Instant$1 | Date;
|
|
492
|
+
advance?: Duration$1;
|
|
493
|
+
virtualTime?: boolean;
|
|
494
|
+
delay?: Duration$1;
|
|
495
|
+
timeout?: Duration$1;
|
|
496
|
+
/** A status, `"drop"`, a preset name, or a fault rule. */
|
|
497
|
+
fault?: number | string | Record<string, unknown>;
|
|
498
|
+
snapshot?: string;
|
|
278
499
|
};
|
|
279
500
|
|
|
280
501
|
/**
|
|
@@ -314,6 +535,8 @@ type RequestLog$1 = {
|
|
|
314
535
|
unmatched: boolean;
|
|
315
536
|
/** Set when a fault rule produced the response. */
|
|
316
537
|
faultId?: string;
|
|
538
|
+
/** Milliseconds of injected wait: latency, fault delays and timeouts. Absent when none. */
|
|
539
|
+
delayMs?: number;
|
|
317
540
|
/** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
|
|
318
541
|
ids?: Record<string, string>;
|
|
319
542
|
/** Set when the service created a resource the request referred to but that did not exist. */
|
|
@@ -359,6 +582,12 @@ type JournalQuery$1 = {
|
|
|
359
582
|
/** Only this namespace. Omit for every namespace, oldest first across all of them. */
|
|
360
583
|
namespace?: string;
|
|
361
584
|
operationId?: string;
|
|
585
|
+
/** Only this HTTP method, case-insensitive. */
|
|
586
|
+
method?: string;
|
|
587
|
+
/** Only this exact path. */
|
|
588
|
+
path?: string;
|
|
589
|
+
/** Only requests this fault rule answered or shaped. */
|
|
590
|
+
faultId?: string;
|
|
362
591
|
status?: number;
|
|
363
592
|
/** Only entries at or after this instant (epoch ms). */
|
|
364
593
|
since?: number;
|
|
@@ -373,6 +602,50 @@ type Journal$1 = {
|
|
|
373
602
|
clear(namespace?: string): void;
|
|
374
603
|
};
|
|
375
604
|
|
|
605
|
+
/**
|
|
606
|
+
* Baseline response time, per namespace: how long every vendor request takes before any
|
|
607
|
+
* fault is considered. Jitter draws from a stream the caller owns, one per namespace and
|
|
608
|
+
* separate from the fault stream, so adding latency never shifts which requests a `rate`
|
|
609
|
+
* fault hits.
|
|
610
|
+
*/
|
|
611
|
+
type LatencyRegistry$1 = {
|
|
612
|
+
get(namespace: string): LatencyState$1;
|
|
613
|
+
set(namespace: string, state: LatencyState$1): LatencyState$1;
|
|
614
|
+
/** Remove one namespace's latency, or every namespace's. */
|
|
615
|
+
clear(namespace?: string): void;
|
|
616
|
+
/** Milliseconds this request waits. Draws jitter, so call it once per request. */
|
|
617
|
+
take(namespace: string, operationId: string | undefined): number;
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
/** Clock state as the admin API reports it. */
|
|
621
|
+
type ControlClock$1 = ClockState$1 & {
|
|
622
|
+
/** `now`, as ISO-8601. */
|
|
623
|
+
iso: string;
|
|
624
|
+
/** Milliseconds the clock steps before every vendor request. */
|
|
625
|
+
autoAdvanceMs: number;
|
|
626
|
+
};
|
|
627
|
+
/** One namespace's controls: the body of `GET /__admin/controls`. */
|
|
628
|
+
type ControlState$1 = {
|
|
629
|
+
namespace: string;
|
|
630
|
+
seed: number | string;
|
|
631
|
+
clock: ControlClock$1;
|
|
632
|
+
virtualTime: boolean;
|
|
633
|
+
latency: LatencyState$1;
|
|
634
|
+
faults: FaultListing$1[];
|
|
635
|
+
};
|
|
636
|
+
|
|
637
|
+
/** What `GET /__admin/snapshots` lists for each snapshot. */
|
|
638
|
+
type SnapshotInfo$1 = {
|
|
639
|
+
id: string;
|
|
640
|
+
namespace: string;
|
|
641
|
+
/** Stored rows in the snapshot. */
|
|
642
|
+
records: number;
|
|
643
|
+
/** The namespace clock when it was taken, epoch ms. */
|
|
644
|
+
at: number;
|
|
645
|
+
/** Whether `GET /snapshots/:id` can return it as a {@link SnapshotDocument}. */
|
|
646
|
+
portable: boolean;
|
|
647
|
+
};
|
|
648
|
+
|
|
376
649
|
/** Credential → namespace mapping behind `PUT /__admin/credentials`. */
|
|
377
650
|
type CredentialRegistry$1 = {
|
|
378
651
|
set(credential: string, namespace: string): void;
|
|
@@ -527,7 +800,10 @@ type ServiceInstance$1 = FetchAPI$2 & {
|
|
|
527
800
|
};
|
|
528
801
|
type ServiceTimelineState$1 = Readonly<{
|
|
529
802
|
snapshot: NamespaceSnapshot$1;
|
|
530
|
-
clock
|
|
803
|
+
/** `pinned`: the namespace's clock was frozen itself, not just following a frozen base. */
|
|
804
|
+
clock: Readonly<ClockState$1 & {
|
|
805
|
+
pinned?: boolean;
|
|
806
|
+
}>;
|
|
531
807
|
rngState: number;
|
|
532
808
|
}>;
|
|
533
809
|
type ServiceCheckpoint$1 = Checkpoint$1<ServiceTimelineState$1>;
|
|
@@ -535,17 +811,23 @@ type ServiceRuntime$1<T extends ServiceInstance$1> = FetchAPI$2 & {
|
|
|
535
811
|
/** Stop package-owned lifecycle timers when a supervisor closes the runtime. */
|
|
536
812
|
stop?(): void;
|
|
537
813
|
readonly name: string;
|
|
814
|
+
/** Same-origin Fetch handler and App Router method exports, sharing this runtime. */
|
|
815
|
+
mount(prefix: string): MountedAPI$1;
|
|
538
816
|
readonly sqlite: SqliteClient$2;
|
|
539
817
|
readonly clock: Clock$1;
|
|
540
818
|
readonly faults: FaultRegistry$1;
|
|
819
|
+
/** Baseline response time per namespace. */
|
|
820
|
+
readonly latency: LatencyRegistry$1;
|
|
541
821
|
readonly metrics: Metrics$1;
|
|
542
822
|
readonly journal: Journal$1;
|
|
543
823
|
readonly rng: Rng$1;
|
|
544
824
|
readonly credentials: CredentialRegistry$1;
|
|
545
825
|
/** The webhook hub, when the service has outbound webhooks. */
|
|
546
826
|
readonly webhooks: WebhookHub$1 | undefined;
|
|
547
|
-
/**
|
|
548
|
-
|
|
827
|
+
/**
|
|
828
|
+
* A namespace's clock. Each follows the base clock, {@link ServiceRuntime.clock}, with an
|
|
829
|
+
* offset and a freeze of its own, so moving one never moves another.
|
|
830
|
+
*/
|
|
549
831
|
namespaceClock(namespace?: string): Clock$1;
|
|
550
832
|
namespaceOf(request: Request): string;
|
|
551
833
|
/** Opaque in-process checkpoint including records, controls and webhook history. */
|
|
@@ -557,8 +839,38 @@ type ServiceRuntime$1<T extends ServiceInstance$1> = FetchAPI$2 & {
|
|
|
557
839
|
instance(namespace?: string): T;
|
|
558
840
|
/** Public names of every namespace created so far. */
|
|
559
841
|
namespaces(): string[];
|
|
560
|
-
/**
|
|
842
|
+
/** Return one namespace to its boot state, or every namespace with `"*"`. */
|
|
561
843
|
reset(namespace?: string): Promise<void>;
|
|
844
|
+
/** Reset a namespace and forget it, releasing everything it held. */
|
|
845
|
+
dropNamespace(namespace: string): Promise<void>;
|
|
846
|
+
/** A namespace's controls: seed, clock, virtual time, latency, faults and snapshots. */
|
|
847
|
+
controls(namespace?: string): ControlState$1 & {
|
|
848
|
+
snapshots: SnapshotInfo$1[];
|
|
849
|
+
};
|
|
850
|
+
/** Apply a control document to a namespace. A given key replaces that control. */
|
|
851
|
+
configure(controls: NamespaceControls$1, namespace?: string): ControlState$1 & {
|
|
852
|
+
snapshots: SnapshotInfo$1[];
|
|
853
|
+
};
|
|
854
|
+
/** Named snapshots of a namespace: records, clock, random streams, faults and latency. */
|
|
855
|
+
readonly snapshots: {
|
|
856
|
+
/** Capture the namespace now. Reusing a name replaces that snapshot. */
|
|
857
|
+
create(options?: {
|
|
858
|
+
name?: string;
|
|
859
|
+
namespace?: string;
|
|
860
|
+
}): SnapshotInfo$1;
|
|
861
|
+
list(namespace?: string): SnapshotInfo$1[];
|
|
862
|
+
/** The snapshot as portable JSON, to commit beside a suite or boot another mock from. */
|
|
863
|
+
export(id: string, namespace?: string): SnapshotDocument$1;
|
|
864
|
+
/** Store a document as a snapshot without restoring it. */
|
|
865
|
+
import(document: SnapshotDocument$1, options?: {
|
|
866
|
+
name?: string;
|
|
867
|
+
namespace?: string;
|
|
868
|
+
}): SnapshotInfo$1;
|
|
869
|
+
restore(id: string, namespace?: string): void;
|
|
870
|
+
delete(id: string, namespace?: string): boolean;
|
|
871
|
+
};
|
|
872
|
+
/** Request headers that carry controls, checked: spread them into a `fetch` or an SDK's defaults. */
|
|
873
|
+
headers(input: ControlHeaderInput$1): Record<string, string>;
|
|
562
874
|
snapshot(namespace?: string): NamespaceSnapshot$1;
|
|
563
875
|
restore(snapshot: NamespaceSnapshot$1, namespace?: string): void;
|
|
564
876
|
/** Capture the current branch. Mutating HTTP calls do this automatically. */
|
|
@@ -601,6 +913,11 @@ type CommonServeOptions = {
|
|
|
601
913
|
adminKey: string | undefined;
|
|
602
914
|
seed: string | undefined;
|
|
603
915
|
onLog: ((entry: RequestLog$1) => void) | undefined;
|
|
916
|
+
/** Admin controls to boot with: clock, latency, faults, a starting snapshot. */
|
|
917
|
+
adminControls?: MockControls$1;
|
|
918
|
+
/** Synthetic provider fixture objects supplied by a fleet entry. */
|
|
919
|
+
fixtures?: Record<string, unknown>;
|
|
920
|
+
baseUrl?: string;
|
|
604
921
|
};
|
|
605
922
|
/**
|
|
606
923
|
* What a service contributes to `serve`: how to build its runtime from CLI flags,
|
|
@@ -633,88 +950,16 @@ type CatalogItem = {
|
|
|
633
950
|
status: "active" | "inactive";
|
|
634
951
|
};
|
|
635
952
|
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
953
|
+
type MountedAPI = FetchAPI$1 & {
|
|
954
|
+
readonly prefix: string;
|
|
955
|
+
GET: FetchHandler;
|
|
956
|
+
POST: FetchHandler;
|
|
957
|
+
PUT: FetchHandler;
|
|
958
|
+
PATCH: FetchHandler;
|
|
959
|
+
DELETE: FetchHandler;
|
|
960
|
+
HEAD: FetchHandler;
|
|
961
|
+
OPTIONS: FetchHandler;
|
|
642
962
|
};
|
|
643
|
-
/**
|
|
644
|
-
* Prepared statement bound to a {@link SqliteClient}.
|
|
645
|
-
*
|
|
646
|
-
* Pass bind values as rest arguments on each call (no sticky `bind()`).
|
|
647
|
-
*/
|
|
648
|
-
interface SqliteStatement$1 {
|
|
649
|
-
run(...params: SqliteValue$1[]): SqliteRunResult$1;
|
|
650
|
-
all<T = Record<string, unknown>>(...params: SqliteValue$1[]): T[];
|
|
651
|
-
get<T = Record<string, unknown>>(...params: SqliteValue$1[]): T | undefined;
|
|
652
|
-
}
|
|
653
|
-
/**
|
|
654
|
-
* Sync SQLite client port owned by Mockingbird.
|
|
655
|
-
*
|
|
656
|
-
* Duck-typed so `@crvouga/mockingbird-service-sqlite` `Database`, better-sqlite3, and wrapped
|
|
657
|
-
* `bun:sqlite` instances all work when they expose this surface.
|
|
658
|
-
*/
|
|
659
|
-
interface SqliteClient$1 {
|
|
660
|
-
exec(sql: string): void;
|
|
661
|
-
prepare(sql: string): SqliteStatement$1;
|
|
662
|
-
transaction<T>(fn: () => T): T;
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
/** Every stored record carries a monotonically increasing sequence for stable ordering. */
|
|
666
|
-
type Stored<T> = {
|
|
667
|
-
seq: number;
|
|
668
|
-
value: T;
|
|
669
|
-
};
|
|
670
|
-
type ListRecordsOptions<T> = {
|
|
671
|
-
/** Keep only records passing the predicate. */
|
|
672
|
-
where?: (value: T, seq: number) => boolean;
|
|
673
|
-
/** Sort order; default newest first. */
|
|
674
|
-
order?: "newest" | "oldest";
|
|
675
|
-
};
|
|
676
|
-
/**
|
|
677
|
-
* A SQLite-backed table of JSON records addressed by id. Ordering is by insertion
|
|
678
|
-
* sequence, never by id lexicographic order, so list semantics stay stable.
|
|
679
|
-
*/
|
|
680
|
-
declare class Collection<T> {
|
|
681
|
-
private readonly sqlite;
|
|
682
|
-
/** Storage namespace. Admin introspection uses this to ignore another namespace's tables. */
|
|
683
|
-
readonly namespace: string;
|
|
684
|
-
/** Table name inside the namespace. Stable across resets of the rows themselves. */
|
|
685
|
-
readonly collectionName: string;
|
|
686
|
-
constructor(sqlite: SqliteClient$1,
|
|
687
|
-
/** Storage namespace. Admin introspection uses this to ignore another namespace's tables. */
|
|
688
|
-
namespace: string,
|
|
689
|
-
/** Table name inside the namespace. Stable across resets of the rows themselves. */
|
|
690
|
-
collectionName: string);
|
|
691
|
-
private bumpCollectionSeq;
|
|
692
|
-
nextSequence(): number;
|
|
693
|
-
get(id: string): T | undefined;
|
|
694
|
-
has(id: string): boolean;
|
|
695
|
-
/** Insert a new record, assigning it the next sequence number. */
|
|
696
|
-
insert(id: string, value: T): Stored<T>;
|
|
697
|
-
/** Replace an existing record's value, keeping its position. */
|
|
698
|
-
update(id: string, value: T): Stored<T> | undefined;
|
|
699
|
-
delete(id: string): boolean;
|
|
700
|
-
/** How many records the collection holds, without reading them. */
|
|
701
|
-
count(): number;
|
|
702
|
-
list(options?: ListRecordsOptions<T>): Array<Stored<T> & {
|
|
703
|
-
id: string;
|
|
704
|
-
}>;
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
/**
|
|
708
|
-
* Sequential id source persisted in SQLite. Ids are deterministic for a given
|
|
709
|
-
* sequence history (`cus_` + 14 opaque chars), so reproductions stay stable.
|
|
710
|
-
*/
|
|
711
|
-
declare class IdSequence {
|
|
712
|
-
private readonly sqlite;
|
|
713
|
-
private readonly namespace;
|
|
714
|
-
private readonly salt;
|
|
715
|
-
constructor(sqlite: SqliteClient$1, namespace: string, salt?: string);
|
|
716
|
-
next(prefix: string, length?: number): string;
|
|
717
|
-
}
|
|
718
963
|
|
|
719
964
|
/** A stable identifier for a point in a {@link Timeline}. */
|
|
720
965
|
type CheckpointId = string;
|
|
@@ -805,6 +1050,91 @@ declare class Timeline<T> {
|
|
|
805
1050
|
interface FetchAPI$1 {
|
|
806
1051
|
fetch(request: Request): Promise<Response>;
|
|
807
1052
|
}
|
|
1053
|
+
/** A bare function form of {@link FetchAPI}, compatible with `Bun.serve`, workerd, and Deno. */
|
|
1054
|
+
type FetchHandler = (request: Request) => Promise<Response>;
|
|
1055
|
+
|
|
1056
|
+
/** Bind values accepted by Mockingbird's SQLite port (matches sqlite-mem / better-sqlite3). */
|
|
1057
|
+
type SqliteValue$1 = null | number | bigint | string | Uint8Array | boolean;
|
|
1058
|
+
/** Mutation counters returned by {@link SqliteStatement.run}. */
|
|
1059
|
+
type SqliteRunResult$1 = {
|
|
1060
|
+
changes: number;
|
|
1061
|
+
lastInsertRowid: number | bigint;
|
|
1062
|
+
};
|
|
1063
|
+
/**
|
|
1064
|
+
* Prepared statement bound to a {@link SqliteClient}.
|
|
1065
|
+
*
|
|
1066
|
+
* Pass bind values as rest arguments on each call (no sticky `bind()`).
|
|
1067
|
+
*/
|
|
1068
|
+
interface SqliteStatement$1 {
|
|
1069
|
+
run(...params: SqliteValue$1[]): SqliteRunResult$1;
|
|
1070
|
+
all<T = Record<string, unknown>>(...params: SqliteValue$1[]): T[];
|
|
1071
|
+
get<T = Record<string, unknown>>(...params: SqliteValue$1[]): T | undefined;
|
|
1072
|
+
}
|
|
1073
|
+
/**
|
|
1074
|
+
* Sync SQLite client port owned by Mockingbird.
|
|
1075
|
+
*
|
|
1076
|
+
* Duck-typed so `@crvouga/mockingbird-service-sqlite` `Database`, better-sqlite3, and wrapped
|
|
1077
|
+
* `bun:sqlite` instances all work when they expose this surface.
|
|
1078
|
+
*/
|
|
1079
|
+
interface SqliteClient$1 {
|
|
1080
|
+
exec(sql: string): void;
|
|
1081
|
+
prepare(sql: string): SqliteStatement$1;
|
|
1082
|
+
transaction<T>(fn: () => T): T;
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
/** Every stored record carries a monotonically increasing sequence for stable ordering. */
|
|
1086
|
+
type Stored<T> = {
|
|
1087
|
+
seq: number;
|
|
1088
|
+
value: T;
|
|
1089
|
+
};
|
|
1090
|
+
type ListRecordsOptions<T> = {
|
|
1091
|
+
/** Keep only records passing the predicate. */
|
|
1092
|
+
where?: (value: T, seq: number) => boolean;
|
|
1093
|
+
/** Sort order; default newest first. */
|
|
1094
|
+
order?: "newest" | "oldest";
|
|
1095
|
+
};
|
|
1096
|
+
/**
|
|
1097
|
+
* A SQLite-backed table of JSON records addressed by id. Ordering is by insertion
|
|
1098
|
+
* sequence, never by id lexicographic order, so list semantics stay stable.
|
|
1099
|
+
*/
|
|
1100
|
+
declare class Collection<T> {
|
|
1101
|
+
private readonly sqlite;
|
|
1102
|
+
/** Storage namespace. Admin introspection uses this to ignore another namespace's tables. */
|
|
1103
|
+
readonly namespace: string;
|
|
1104
|
+
/** Table name inside the namespace. Stable across resets of the rows themselves. */
|
|
1105
|
+
readonly collectionName: string;
|
|
1106
|
+
constructor(sqlite: SqliteClient$1,
|
|
1107
|
+
/** Storage namespace. Admin introspection uses this to ignore another namespace's tables. */
|
|
1108
|
+
namespace: string,
|
|
1109
|
+
/** Table name inside the namespace. Stable across resets of the rows themselves. */
|
|
1110
|
+
collectionName: string);
|
|
1111
|
+
private bumpCollectionSeq;
|
|
1112
|
+
nextSequence(): number;
|
|
1113
|
+
get(id: string): T | undefined;
|
|
1114
|
+
has(id: string): boolean;
|
|
1115
|
+
/** Insert a new record, assigning it the next sequence number. */
|
|
1116
|
+
insert(id: string, value: T): Stored<T>;
|
|
1117
|
+
/** Replace an existing record's value, keeping its position. */
|
|
1118
|
+
update(id: string, value: T): Stored<T> | undefined;
|
|
1119
|
+
delete(id: string): boolean;
|
|
1120
|
+
/** How many records the collection holds, without reading them. */
|
|
1121
|
+
count(): number;
|
|
1122
|
+
list(options?: ListRecordsOptions<T>): Array<Stored<T> & {
|
|
1123
|
+
id: string;
|
|
1124
|
+
}>;
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
/**
|
|
1128
|
+
* Sequential id source persisted in SQLite. Ids are deterministic for a given
|
|
1129
|
+
* sequence history (`cus_` + 14 opaque chars), so reproductions stay stable.
|
|
1130
|
+
*/
|
|
1131
|
+
declare class IdSequence {
|
|
1132
|
+
private readonly sqlite;
|
|
1133
|
+
private readonly namespace;
|
|
1134
|
+
private readonly salt;
|
|
1135
|
+
constructor(sqlite: SqliteClient$1, namespace: string, salt?: string);
|
|
1136
|
+
next(prefix: string, length?: number): string;
|
|
1137
|
+
}
|
|
808
1138
|
|
|
809
1139
|
/** Options every provider constructor accepts. */
|
|
810
1140
|
type APIOptions = {
|
|
@@ -831,7 +1161,7 @@ type ClockState = {
|
|
|
831
1161
|
now: number;
|
|
832
1162
|
/** True while time does not advance on its own. */
|
|
833
1163
|
frozen: boolean;
|
|
834
|
-
/** Milliseconds
|
|
1164
|
+
/** Milliseconds a running clock adds to its underlying source. `0` while frozen. */
|
|
835
1165
|
offsetMs: number;
|
|
836
1166
|
};
|
|
837
1167
|
type Clock = {
|
|
@@ -867,7 +1197,10 @@ type Rng = {
|
|
|
867
1197
|
state(): number;
|
|
868
1198
|
/** Restore a state previously returned by {@link state}. */
|
|
869
1199
|
setState(state: number): void;
|
|
870
|
-
seed
|
|
1200
|
+
/** Restart the stream from a new seed. `reset` then returns to this seed. */
|
|
1201
|
+
reseed(seed: number | string): void;
|
|
1202
|
+
/** The seed the stream currently starts from. */
|
|
1203
|
+
readonly seed: number;
|
|
871
1204
|
};
|
|
872
1205
|
|
|
873
1206
|
/**
|
|
@@ -876,44 +1209,83 @@ type Rng = {
|
|
|
876
1209
|
* This is how a suite reaches the vendor's failure modes without the vendor: the
|
|
877
1210
|
* quota error that only appears when a shared sandbox is full, the 429 that only
|
|
878
1211
|
* appears under load, the 5xx that proves a retry path works.
|
|
1212
|
+
*
|
|
1213
|
+
* A rule has three parts. What it **matches** (`operationId`, `method`, `path`, …), **when**
|
|
1214
|
+
* it fires among the matching requests (`after`, `every`, `count`, `rate`, `from`, `until`),
|
|
1215
|
+
* and what it **does** (`status`, `delay`, `timeout`, `drop`, `truncate`, `effect`).
|
|
879
1216
|
*/
|
|
880
1217
|
type FaultRule = {
|
|
881
|
-
/** Stable id, so a suite can retire exactly the rule it added. */
|
|
1218
|
+
/** Stable id, so a suite can retire exactly the rule it added. Unique within a namespace. */
|
|
882
1219
|
id: string;
|
|
883
1220
|
/** Fault only this operation. Omit to match every operation. */
|
|
884
1221
|
operationId?: string;
|
|
885
1222
|
/** Fault only this HTTP method, case-insensitive. Omit to match every method. */
|
|
886
1223
|
method?: string;
|
|
1224
|
+
/** Fault only this exact path. */
|
|
1225
|
+
path?: string;
|
|
887
1226
|
/** Fault only paths starting with this prefix. Omit to match every path. */
|
|
888
1227
|
pathPrefix?: string;
|
|
1228
|
+
/** Fault only paths matching this regular expression (JavaScript syntax, unanchored). */
|
|
1229
|
+
pathPattern?: string;
|
|
1230
|
+
/** Fault only requests carrying these headers. `"*"` matches any value. */
|
|
1231
|
+
requestHeaders?: Record<string, string>;
|
|
1232
|
+
/** Fault only requests carrying these query parameters. `"*"` matches any value. */
|
|
1233
|
+
query?: Record<string, string>;
|
|
889
1234
|
/**
|
|
890
1235
|
* Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
|
|
891
1236
|
* an in-process caller usually wants, and what a parallel worker usually does not:
|
|
892
1237
|
* rules added through `POST /__admin/faults` default to the calling namespace.
|
|
893
1238
|
*/
|
|
894
1239
|
namespace?: string;
|
|
1240
|
+
/** Let this many matching requests through first. */
|
|
1241
|
+
after?: number;
|
|
1242
|
+
/** Then fault only every nth matching request: `3` faults the 3rd, 6th, 9th. */
|
|
1243
|
+
every?: number;
|
|
1244
|
+
/** Retire the rule after this many faults. Omit to keep it until removed. */
|
|
1245
|
+
count?: number;
|
|
1246
|
+
/** Fault this fraction of the remaining requests, `0`–`1`, drawn from the seed. Default `1`. */
|
|
1247
|
+
rate?: number;
|
|
895
1248
|
/**
|
|
896
|
-
*
|
|
897
|
-
*
|
|
898
|
-
|
|
1249
|
+
* Fault only from this instant on the namespace clock. A duration (`"5m"`) counts from the
|
|
1250
|
+
* clock when the rule was added. Listed as epoch ms.
|
|
1251
|
+
*/
|
|
1252
|
+
from?: Instant | Duration;
|
|
1253
|
+
/** Stop faulting at this instant on the namespace clock. A duration counts from when added. */
|
|
1254
|
+
until?: Instant | Duration;
|
|
1255
|
+
/**
|
|
1256
|
+
* Status of the injected response. Omit for a rule that only delays, times out, drops,
|
|
1257
|
+
* truncates, or switches on an `effect`: the request then still reaches the service.
|
|
899
1258
|
*/
|
|
900
1259
|
status?: number;
|
|
901
1260
|
/** Response body, serialized as JSON. A string is sent as-is. */
|
|
902
1261
|
body?: unknown;
|
|
1262
|
+
/** Response headers. */
|
|
903
1263
|
headers?: Record<string, string>;
|
|
904
|
-
/**
|
|
905
|
-
|
|
906
|
-
/**
|
|
907
|
-
rate?: number;
|
|
908
|
-
/** Hold the response back this long, to exercise timeouts. */
|
|
1264
|
+
/** Hold the response back this long. Listed as `delayMs`. */
|
|
1265
|
+
delay?: Duration;
|
|
1266
|
+
/** `delay`, in milliseconds. */
|
|
909
1267
|
delayMs?: number;
|
|
910
1268
|
/** Alias of `delayMs`. */
|
|
911
1269
|
latencyMs?: number;
|
|
1270
|
+
/** Extra seeded delay in `[0, jitter]`. Listed as `jitterMs`. */
|
|
1271
|
+
jitter?: Duration;
|
|
1272
|
+
jitterMs?: number;
|
|
1273
|
+
/**
|
|
1274
|
+
* Never answer: hold the request this long, then drop the connection. Listed as
|
|
1275
|
+
* `timeoutMs`. With virtual time the wait is spent on the mock clock.
|
|
1276
|
+
*/
|
|
1277
|
+
timeout?: Duration;
|
|
1278
|
+
timeoutMs?: number;
|
|
912
1279
|
/**
|
|
913
1280
|
* Drop the connection instead of answering: an in-process `fetch` rejects with a
|
|
914
1281
|
* `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
|
|
915
1282
|
*/
|
|
916
1283
|
drop?: boolean;
|
|
1284
|
+
/**
|
|
1285
|
+
* Cut the response body off after this many bytes: the status and headers arrive, then
|
|
1286
|
+
* the connection dies mid-body.
|
|
1287
|
+
*/
|
|
1288
|
+
truncate?: number;
|
|
917
1289
|
/**
|
|
918
1290
|
* A named service behaviour to switch on for the matching request instead of (or
|
|
919
1291
|
* before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
|
|
@@ -922,8 +1294,8 @@ type FaultRule = {
|
|
|
922
1294
|
effect?: string;
|
|
923
1295
|
/** Parameters for `effect`. */
|
|
924
1296
|
params?: Record<string, unknown>;
|
|
925
|
-
/**
|
|
926
|
-
|
|
1297
|
+
/** The preset this rule was expanded from, if any. */
|
|
1298
|
+
fromPreset?: string;
|
|
927
1299
|
};
|
|
928
1300
|
/** A fault that fired for one request. */
|
|
929
1301
|
type FaultHit = {
|
|
@@ -931,6 +1303,10 @@ type FaultHit = {
|
|
|
931
1303
|
/** The injected response; absent when the rule only delays, drops, or sets an effect. */
|
|
932
1304
|
response?: Response;
|
|
933
1305
|
drop?: boolean;
|
|
1306
|
+
/** Set with `drop` when the rule held the request for its `timeout` first. */
|
|
1307
|
+
timeout?: boolean;
|
|
1308
|
+
/** Bytes of response body to let through before the connection dies. */
|
|
1309
|
+
truncate?: number;
|
|
934
1310
|
effect?: {
|
|
935
1311
|
name: string;
|
|
936
1312
|
params: Record<string, unknown>;
|
|
@@ -942,38 +1318,200 @@ type FaultCandidate = {
|
|
|
942
1318
|
method: string;
|
|
943
1319
|
path: string;
|
|
944
1320
|
namespace: string;
|
|
1321
|
+
/** Request headers and query, for rules that match on them. */
|
|
1322
|
+
headers?: Headers;
|
|
1323
|
+
query?: URLSearchParams;
|
|
1324
|
+
/** The namespace clock, for `from` / `until`. Rules with a window are skipped without it. */
|
|
1325
|
+
now?: number;
|
|
1326
|
+
/** How to spend a delay for this request. Default: the registry's own sleep. */
|
|
1327
|
+
wait?: (ms: number) => Promise<void>;
|
|
1328
|
+
};
|
|
1329
|
+
/** A stored rule and how often it was consulted. */
|
|
1330
|
+
type FaultListing = FaultRule & {
|
|
1331
|
+
/** Faults left before the rule retires. `null` when it has no `count`. */
|
|
1332
|
+
remaining: number | null;
|
|
1333
|
+
/** Times the rule faulted a request. */
|
|
1334
|
+
hits: number;
|
|
1335
|
+
/** Requests that matched the rule, faulted or not. */
|
|
1336
|
+
seen: number;
|
|
1337
|
+
};
|
|
1338
|
+
/** A namespace's own rules, with their counters, in the order they are tried. */
|
|
1339
|
+
type FaultSnapshot = {
|
|
1340
|
+
/**
|
|
1341
|
+
* `position` is how many `"*"` rules are tried before the rule, which is what its place
|
|
1342
|
+
* in the order means to a request and holds in any process.
|
|
1343
|
+
*/
|
|
1344
|
+
rules: (FaultListing & {
|
|
1345
|
+
position?: number;
|
|
1346
|
+
})[];
|
|
1347
|
+
/** How many `fault_<n>` ids the namespace has handed out. */
|
|
1348
|
+
nextId?: number;
|
|
945
1349
|
};
|
|
946
1350
|
type FaultRegistry = {
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
rules: (FaultRule & {
|
|
950
|
-
remaining: number | null;
|
|
951
|
-
hits: number;
|
|
952
|
-
position: number;
|
|
953
|
-
})[];
|
|
954
|
-
rngState: number;
|
|
955
|
-
};
|
|
1351
|
+
snapshot(namespace: string): FaultSnapshot;
|
|
1352
|
+
/** Add a rule, or replace the rule with the same id in the same namespace. */
|
|
956
1353
|
add(rule: FaultRule): FaultRule;
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
})[];
|
|
969
|
-
rngState: number;
|
|
970
|
-
}): void;
|
|
1354
|
+
/** The next unused `fault_<n>` id in `namespace`. */
|
|
1355
|
+
nextId(namespace: string): string;
|
|
1356
|
+
/** Every rule, or the rules a namespace's requests can hit: its own and the global ones. */
|
|
1357
|
+
list(namespace?: string): FaultListing[];
|
|
1358
|
+
get(id: string, namespace?: string): FaultListing | undefined;
|
|
1359
|
+
/** Remove a rule by id: from `namespace` (its own, then a global one), or wherever it is. */
|
|
1360
|
+
remove(id: string, namespace?: string): boolean;
|
|
1361
|
+
/** Remove every rule, or one namespace's own rules. */
|
|
1362
|
+
clear(namespace?: string): void;
|
|
1363
|
+
/** Replace a namespace's own rules with a snapshot's, wherever the snapshot was taken. */
|
|
1364
|
+
restore(namespace: string, state: FaultSnapshot): void;
|
|
971
1365
|
/**
|
|
972
1366
|
* Every fault this request should get, in rule order, stopping at the first that answers
|
|
973
1367
|
* or drops (effect-only and delay-only rules let later rules match too). Consumes one of
|
|
974
1368
|
* each matching rule's remaining uses.
|
|
975
1369
|
*/
|
|
976
1370
|
take(candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
1371
|
+
/**
|
|
1372
|
+
* Fire these rules at one request without storing them: no matching, no schedule, in order,
|
|
1373
|
+
* stopping at the first that answers or drops. Jitter draws from the namespace's stream.
|
|
1374
|
+
*/
|
|
1375
|
+
fire(rules: readonly FaultRule[], candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
1376
|
+
};
|
|
1377
|
+
|
|
1378
|
+
/**
|
|
1379
|
+
* The admin controls every mock shares, as one document.
|
|
1380
|
+
*
|
|
1381
|
+
* The same shape is accepted in three places, and means the same thing in each:
|
|
1382
|
+
*
|
|
1383
|
+
* - at boot: `createRuntime({ adminControls })`, `serve --admin-controls`,
|
|
1384
|
+
* `MOCKINGBIRD_ADMIN_CONTROLS`
|
|
1385
|
+
* - over HTTP: `PUT /__admin/controls`
|
|
1386
|
+
* - per request: the `x-mockingbird-*` headers in {@link CONTROL_HEADERS}
|
|
1387
|
+
*
|
|
1388
|
+
* Every control is deterministic: given the same seed, clock and requests, a mock answers
|
|
1389
|
+
* the same bytes. Nothing here reads the wall clock or `Math.random`.
|
|
1390
|
+
*/
|
|
1391
|
+
/** Milliseconds, or a string like `"250ms"`, `"2s"`, `"15m"`, `"1h"`, `"3d"`. */
|
|
1392
|
+
type Duration = number | string;
|
|
1393
|
+
/** Epoch milliseconds, or an ISO-8601 string. */
|
|
1394
|
+
type Instant = number | string;
|
|
1395
|
+
type ClockControls = {
|
|
1396
|
+
/** Move the clock to this instant. */
|
|
1397
|
+
now?: Instant;
|
|
1398
|
+
/** Stop time. A frozen clock moves only when told to, so timestamps replay exactly. */
|
|
1399
|
+
frozen?: boolean;
|
|
1400
|
+
/**
|
|
1401
|
+
* Step the clock forward by this much before every vendor request. With a frozen clock
|
|
1402
|
+
* each request still gets its own, reproducible timestamp.
|
|
1403
|
+
*/
|
|
1404
|
+
autoAdvance?: Duration;
|
|
1405
|
+
};
|
|
1406
|
+
/** How long a response takes: a fixed delay plus seeded jitter in `[0, jitter]`. */
|
|
1407
|
+
type LatencyRuleInput = {
|
|
1408
|
+
delay?: Duration;
|
|
1409
|
+
jitter?: Duration;
|
|
1410
|
+
};
|
|
1411
|
+
type LatencyControls = LatencyRuleInput & {
|
|
1412
|
+
/** Per-operation overrides, keyed by operationId. A bare duration is its `delay`. */
|
|
1413
|
+
operations?: Record<string, Duration | LatencyRuleInput>;
|
|
1414
|
+
};
|
|
1415
|
+
/** A fault to add: a rule (the id is assigned when omitted), or a named preset with overrides. */
|
|
1416
|
+
type FaultInput = (Omit<FaultRule, "id"> & {
|
|
1417
|
+
id?: string;
|
|
1418
|
+
}) | ({
|
|
1419
|
+
preset: string;
|
|
1420
|
+
} & Partial<FaultRule>);
|
|
1421
|
+
/** Identifies a {@link SnapshotDocument}. */
|
|
1422
|
+
declare const SNAPSHOT_FORMAT = "mockingbird.snapshot/v1";
|
|
1423
|
+
/**
|
|
1424
|
+
* A namespace, as portable JSON: what `GET /__admin/snapshots/:id` returns and what
|
|
1425
|
+
* `PUT /__admin/snapshots/:id` and the boot `snapshot` control accept. Only `format` and
|
|
1426
|
+
* `records` are required, so a hand-written seed file is a valid snapshot.
|
|
1427
|
+
*/
|
|
1428
|
+
type SnapshotDocument = {
|
|
1429
|
+
format: typeof SNAPSHOT_FORMAT;
|
|
1430
|
+
/** The service that wrote it. A snapshot is rejected by any other service. */
|
|
1431
|
+
service?: string;
|
|
1432
|
+
/**
|
|
1433
|
+
* Stored rows. `seq` orders a collection; omitted, rows keep their listed order. `raw` is
|
|
1434
|
+
* the stored text of a row that is not a plain record, and replaces `value` when present.
|
|
1435
|
+
*/
|
|
1436
|
+
records: {
|
|
1437
|
+
collection: string;
|
|
1438
|
+
id: string;
|
|
1439
|
+
seq?: number;
|
|
1440
|
+
value?: unknown;
|
|
1441
|
+
raw?: string;
|
|
1442
|
+
}[];
|
|
1443
|
+
/** Id counters, so the next generated id continues where the snapshot left off. */
|
|
1444
|
+
sequences?: {
|
|
1445
|
+
name: string;
|
|
1446
|
+
kind: string;
|
|
1447
|
+
value: number;
|
|
1448
|
+
}[];
|
|
1449
|
+
clock?: {
|
|
1450
|
+
now: number;
|
|
1451
|
+
frozen: boolean;
|
|
1452
|
+
autoAdvanceMs?: number;
|
|
1453
|
+
};
|
|
1454
|
+
seed?: number | string;
|
|
1455
|
+
/** Positions of the seeded random streams. */
|
|
1456
|
+
rng?: {
|
|
1457
|
+
state: number;
|
|
1458
|
+
faults?: number;
|
|
1459
|
+
latency?: number;
|
|
1460
|
+
};
|
|
1461
|
+
faults?: unknown;
|
|
1462
|
+
latency?: unknown;
|
|
1463
|
+
virtualTime?: boolean;
|
|
1464
|
+
};
|
|
1465
|
+
/** Controls for one namespace. */
|
|
1466
|
+
type NamespaceControls = {
|
|
1467
|
+
/** Seeds every random choice: fault rates, jitter, and whatever the service invents. */
|
|
1468
|
+
seed?: number | string;
|
|
1469
|
+
clock?: ClockControls;
|
|
1470
|
+
/**
|
|
1471
|
+
* Spend injected waits (latency, fault delays, timeouts) on the mock clock instead of the
|
|
1472
|
+
* wall clock: the request returns at once, the clock has moved, and the journal records
|
|
1473
|
+
* the wait exactly. Default `false`: waits are real, so a client's own timeout can fire.
|
|
1474
|
+
*/
|
|
1475
|
+
virtualTime?: boolean;
|
|
1476
|
+
/** Baseline response time for every vendor request. A bare duration is its `delay`. */
|
|
1477
|
+
latency?: Duration | LatencyControls;
|
|
1478
|
+
faults?: readonly FaultInput[];
|
|
1479
|
+
/** Start from this state instead of the service's own seed data. */
|
|
1480
|
+
snapshot?: SnapshotDocument;
|
|
1481
|
+
};
|
|
1482
|
+
/** {@link NamespaceControls} for every namespace, with per-namespace overrides. */
|
|
1483
|
+
type MockControls = NamespaceControls & {
|
|
1484
|
+
/** Vendor credential → namespace, for SDKs that cannot send a namespace header. */
|
|
1485
|
+
credentials?: Record<string, string>;
|
|
1486
|
+
/** Overrides for named namespaces. A key given here replaces the shared value. */
|
|
1487
|
+
namespaces?: Record<string, NamespaceControls>;
|
|
1488
|
+
};
|
|
1489
|
+
/** A latency rule in milliseconds. */
|
|
1490
|
+
type LatencyRule = {
|
|
1491
|
+
delayMs: number;
|
|
1492
|
+
jitterMs: number;
|
|
1493
|
+
};
|
|
1494
|
+
/** Baseline latency for a namespace, normalized. */
|
|
1495
|
+
type LatencyState = LatencyRule & {
|
|
1496
|
+
operations: Record<string, LatencyRule>;
|
|
1497
|
+
};
|
|
1498
|
+
/** What {@link controlHeaders} turns into request headers. */
|
|
1499
|
+
type ControlHeaderInput = {
|
|
1500
|
+
namespace?: string;
|
|
1501
|
+
adminKey?: string;
|
|
1502
|
+
branch?: string;
|
|
1503
|
+
at?: string;
|
|
1504
|
+
reset?: boolean;
|
|
1505
|
+
restore?: string;
|
|
1506
|
+
seed?: number | string;
|
|
1507
|
+
time?: Instant | Date;
|
|
1508
|
+
advance?: Duration;
|
|
1509
|
+
virtualTime?: boolean;
|
|
1510
|
+
delay?: Duration;
|
|
1511
|
+
timeout?: Duration;
|
|
1512
|
+
/** A status, `"drop"`, a preset name, or a fault rule. */
|
|
1513
|
+
fault?: number | string | Record<string, unknown>;
|
|
1514
|
+
snapshot?: string;
|
|
977
1515
|
};
|
|
978
1516
|
|
|
979
1517
|
/**
|
|
@@ -1013,6 +1551,8 @@ type RequestLog = {
|
|
|
1013
1551
|
unmatched: boolean;
|
|
1014
1552
|
/** Set when a fault rule produced the response. */
|
|
1015
1553
|
faultId?: string;
|
|
1554
|
+
/** Milliseconds of injected wait: latency, fault delays and timeouts. Absent when none. */
|
|
1555
|
+
delayMs?: number;
|
|
1016
1556
|
/** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
|
|
1017
1557
|
ids?: Record<string, string>;
|
|
1018
1558
|
/** Set when the service created a resource the request referred to but that did not exist. */
|
|
@@ -1058,6 +1598,12 @@ type JournalQuery = {
|
|
|
1058
1598
|
/** Only this namespace. Omit for every namespace, oldest first across all of them. */
|
|
1059
1599
|
namespace?: string;
|
|
1060
1600
|
operationId?: string;
|
|
1601
|
+
/** Only this HTTP method, case-insensitive. */
|
|
1602
|
+
method?: string;
|
|
1603
|
+
/** Only this exact path. */
|
|
1604
|
+
path?: string;
|
|
1605
|
+
/** Only requests this fault rule answered or shaped. */
|
|
1606
|
+
faultId?: string;
|
|
1061
1607
|
status?: number;
|
|
1062
1608
|
/** Only entries at or after this instant (epoch ms). */
|
|
1063
1609
|
since?: number;
|
|
@@ -1072,6 +1618,50 @@ type Journal = {
|
|
|
1072
1618
|
clear(namespace?: string): void;
|
|
1073
1619
|
};
|
|
1074
1620
|
|
|
1621
|
+
/**
|
|
1622
|
+
* Baseline response time, per namespace: how long every vendor request takes before any
|
|
1623
|
+
* fault is considered. Jitter draws from a stream the caller owns, one per namespace and
|
|
1624
|
+
* separate from the fault stream, so adding latency never shifts which requests a `rate`
|
|
1625
|
+
* fault hits.
|
|
1626
|
+
*/
|
|
1627
|
+
type LatencyRegistry = {
|
|
1628
|
+
get(namespace: string): LatencyState;
|
|
1629
|
+
set(namespace: string, state: LatencyState): LatencyState;
|
|
1630
|
+
/** Remove one namespace's latency, or every namespace's. */
|
|
1631
|
+
clear(namespace?: string): void;
|
|
1632
|
+
/** Milliseconds this request waits. Draws jitter, so call it once per request. */
|
|
1633
|
+
take(namespace: string, operationId: string | undefined): number;
|
|
1634
|
+
};
|
|
1635
|
+
|
|
1636
|
+
/** Clock state as the admin API reports it. */
|
|
1637
|
+
type ControlClock = ClockState & {
|
|
1638
|
+
/** `now`, as ISO-8601. */
|
|
1639
|
+
iso: string;
|
|
1640
|
+
/** Milliseconds the clock steps before every vendor request. */
|
|
1641
|
+
autoAdvanceMs: number;
|
|
1642
|
+
};
|
|
1643
|
+
/** One namespace's controls: the body of `GET /__admin/controls`. */
|
|
1644
|
+
type ControlState = {
|
|
1645
|
+
namespace: string;
|
|
1646
|
+
seed: number | string;
|
|
1647
|
+
clock: ControlClock;
|
|
1648
|
+
virtualTime: boolean;
|
|
1649
|
+
latency: LatencyState;
|
|
1650
|
+
faults: FaultListing[];
|
|
1651
|
+
};
|
|
1652
|
+
|
|
1653
|
+
/** What `GET /__admin/snapshots` lists for each snapshot. */
|
|
1654
|
+
type SnapshotInfo = {
|
|
1655
|
+
id: string;
|
|
1656
|
+
namespace: string;
|
|
1657
|
+
/** Stored rows in the snapshot. */
|
|
1658
|
+
records: number;
|
|
1659
|
+
/** The namespace clock when it was taken, epoch ms. */
|
|
1660
|
+
at: number;
|
|
1661
|
+
/** Whether `GET /snapshots/:id` can return it as a {@link SnapshotDocument}. */
|
|
1662
|
+
portable: boolean;
|
|
1663
|
+
};
|
|
1664
|
+
|
|
1075
1665
|
/** Credential → namespace mapping behind `PUT /__admin/credentials`. */
|
|
1076
1666
|
type CredentialRegistry = {
|
|
1077
1667
|
set(credential: string, namespace: string): void;
|
|
@@ -1226,7 +1816,10 @@ type ServiceInstance = FetchAPI$1 & {
|
|
|
1226
1816
|
};
|
|
1227
1817
|
type ServiceTimelineState = Readonly<{
|
|
1228
1818
|
snapshot: NamespaceSnapshot;
|
|
1229
|
-
clock
|
|
1819
|
+
/** `pinned`: the namespace's clock was frozen itself, not just following a frozen base. */
|
|
1820
|
+
clock: Readonly<ClockState & {
|
|
1821
|
+
pinned?: boolean;
|
|
1822
|
+
}>;
|
|
1230
1823
|
rngState: number;
|
|
1231
1824
|
}>;
|
|
1232
1825
|
type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
|
|
@@ -1234,17 +1827,23 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI$1 & {
|
|
|
1234
1827
|
/** Stop package-owned lifecycle timers when a supervisor closes the runtime. */
|
|
1235
1828
|
stop?(): void;
|
|
1236
1829
|
readonly name: string;
|
|
1830
|
+
/** Same-origin Fetch handler and App Router method exports, sharing this runtime. */
|
|
1831
|
+
mount(prefix: string): MountedAPI;
|
|
1237
1832
|
readonly sqlite: SqliteClient$1;
|
|
1238
1833
|
readonly clock: Clock;
|
|
1239
1834
|
readonly faults: FaultRegistry;
|
|
1835
|
+
/** Baseline response time per namespace. */
|
|
1836
|
+
readonly latency: LatencyRegistry;
|
|
1240
1837
|
readonly metrics: Metrics;
|
|
1241
1838
|
readonly journal: Journal;
|
|
1242
1839
|
readonly rng: Rng;
|
|
1243
1840
|
readonly credentials: CredentialRegistry;
|
|
1244
1841
|
/** The webhook hub, when the service has outbound webhooks. */
|
|
1245
1842
|
readonly webhooks: WebhookHub | undefined;
|
|
1246
|
-
/**
|
|
1247
|
-
|
|
1843
|
+
/**
|
|
1844
|
+
* A namespace's clock. Each follows the base clock, {@link ServiceRuntime.clock}, with an
|
|
1845
|
+
* offset and a freeze of its own, so moving one never moves another.
|
|
1846
|
+
*/
|
|
1248
1847
|
namespaceClock(namespace?: string): Clock;
|
|
1249
1848
|
namespaceOf(request: Request): string;
|
|
1250
1849
|
/** Opaque in-process checkpoint including records, controls and webhook history. */
|
|
@@ -1256,8 +1855,38 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI$1 & {
|
|
|
1256
1855
|
instance(namespace?: string): T;
|
|
1257
1856
|
/** Public names of every namespace created so far. */
|
|
1258
1857
|
namespaces(): string[];
|
|
1259
|
-
/**
|
|
1858
|
+
/** Return one namespace to its boot state, or every namespace with `"*"`. */
|
|
1260
1859
|
reset(namespace?: string): Promise<void>;
|
|
1860
|
+
/** Reset a namespace and forget it, releasing everything it held. */
|
|
1861
|
+
dropNamespace(namespace: string): Promise<void>;
|
|
1862
|
+
/** A namespace's controls: seed, clock, virtual time, latency, faults and snapshots. */
|
|
1863
|
+
controls(namespace?: string): ControlState & {
|
|
1864
|
+
snapshots: SnapshotInfo[];
|
|
1865
|
+
};
|
|
1866
|
+
/** Apply a control document to a namespace. A given key replaces that control. */
|
|
1867
|
+
configure(controls: NamespaceControls, namespace?: string): ControlState & {
|
|
1868
|
+
snapshots: SnapshotInfo[];
|
|
1869
|
+
};
|
|
1870
|
+
/** Named snapshots of a namespace: records, clock, random streams, faults and latency. */
|
|
1871
|
+
readonly snapshots: {
|
|
1872
|
+
/** Capture the namespace now. Reusing a name replaces that snapshot. */
|
|
1873
|
+
create(options?: {
|
|
1874
|
+
name?: string;
|
|
1875
|
+
namespace?: string;
|
|
1876
|
+
}): SnapshotInfo;
|
|
1877
|
+
list(namespace?: string): SnapshotInfo[];
|
|
1878
|
+
/** The snapshot as portable JSON, to commit beside a suite or boot another mock from. */
|
|
1879
|
+
export(id: string, namespace?: string): SnapshotDocument;
|
|
1880
|
+
/** Store a document as a snapshot without restoring it. */
|
|
1881
|
+
import(document: SnapshotDocument, options?: {
|
|
1882
|
+
name?: string;
|
|
1883
|
+
namespace?: string;
|
|
1884
|
+
}): SnapshotInfo;
|
|
1885
|
+
restore(id: string, namespace?: string): void;
|
|
1886
|
+
delete(id: string, namespace?: string): boolean;
|
|
1887
|
+
};
|
|
1888
|
+
/** Request headers that carry controls, checked: spread them into a `fetch` or an SDK's defaults. */
|
|
1889
|
+
headers(input: ControlHeaderInput): Record<string, string>;
|
|
1261
1890
|
snapshot(namespace?: string): NamespaceSnapshot;
|
|
1262
1891
|
restore(snapshot: NamespaceSnapshot, namespace?: string): void;
|
|
1263
1892
|
/** Capture the current branch. Mutating HTTP calls do this automatically. */
|
|
@@ -1462,6 +2091,8 @@ type RxVortexRuntimeOptions = {
|
|
|
1462
2091
|
seed?: number | string;
|
|
1463
2092
|
adminPrefix?: string;
|
|
1464
2093
|
adminKey?: string;
|
|
2094
|
+
/** Admin controls to boot with: clock, latency, faults, seed, a starting snapshot. */
|
|
2095
|
+
adminControls?: MockControls;
|
|
1465
2096
|
onLog?: (entry: RequestLog) => void;
|
|
1466
2097
|
/**
|
|
1467
2098
|
* Rows every namespace starts with, and returns to on `POST /__admin/reset` (`serve
|