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