@crvouga/mockingbird-service-junction 3.2.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 +8 -2
- package/DISCOVERY.md +23 -0
- package/README.md +68 -76
- package/dist/chunk-PKEFSWT3.js +12812 -0
- package/dist/chunk-PKEFSWT3.js.map +7 -0
- package/dist/{chunk-R4LSSE3O.js → chunk-YDXAOFS2.js} +136 -25
- package/dist/chunk-YDXAOFS2.js.map +7 -0
- package/dist/cli.js +2 -2
- package/dist/index.d.ts +339 -40
- package/dist/index.js +1 -1
- package/dist/server.d.ts +678 -80
- package/dist/server.js +2 -2
- package/package.json +3 -2
- package/dist/chunk-R4LSSE3O.js.map +0 -7
- package/dist/chunk-WEQDMSPV.js +0 -11020
- package/dist/chunk-WEQDMSPV.js.map +0 -7
package/dist/index.d.ts
CHANGED
|
@@ -157,7 +157,7 @@ type ClockState = {
|
|
|
157
157
|
now: number;
|
|
158
158
|
/** True while time does not advance on its own. */
|
|
159
159
|
frozen: boolean;
|
|
160
|
-
/** Milliseconds
|
|
160
|
+
/** Milliseconds a running clock adds to its underlying source. `0` while frozen. */
|
|
161
161
|
offsetMs: number;
|
|
162
162
|
};
|
|
163
163
|
type Clock = {
|
|
@@ -193,7 +193,10 @@ type Rng = {
|
|
|
193
193
|
state(): number;
|
|
194
194
|
/** Restore a state previously returned by {@link state}. */
|
|
195
195
|
setState(state: number): void;
|
|
196
|
-
seed
|
|
196
|
+
/** Restart the stream from a new seed. `reset` then returns to this seed. */
|
|
197
|
+
reseed(seed: number | string): void;
|
|
198
|
+
/** The seed the stream currently starts from. */
|
|
199
|
+
readonly seed: number;
|
|
197
200
|
};
|
|
198
201
|
|
|
199
202
|
/**
|
|
@@ -202,44 +205,83 @@ type Rng = {
|
|
|
202
205
|
* This is how a suite reaches the vendor's failure modes without the vendor: the
|
|
203
206
|
* quota error that only appears when a shared sandbox is full, the 429 that only
|
|
204
207
|
* appears under load, the 5xx that proves a retry path works.
|
|
208
|
+
*
|
|
209
|
+
* A rule has three parts. What it **matches** (`operationId`, `method`, `path`, …), **when**
|
|
210
|
+
* it fires among the matching requests (`after`, `every`, `count`, `rate`, `from`, `until`),
|
|
211
|
+
* and what it **does** (`status`, `delay`, `timeout`, `drop`, `truncate`, `effect`).
|
|
205
212
|
*/
|
|
206
213
|
type FaultRule = {
|
|
207
|
-
/** Stable id, so a suite can retire exactly the rule it added. */
|
|
214
|
+
/** Stable id, so a suite can retire exactly the rule it added. Unique within a namespace. */
|
|
208
215
|
id: string;
|
|
209
216
|
/** Fault only this operation. Omit to match every operation. */
|
|
210
217
|
operationId?: string;
|
|
211
218
|
/** Fault only this HTTP method, case-insensitive. Omit to match every method. */
|
|
212
219
|
method?: string;
|
|
220
|
+
/** Fault only this exact path. */
|
|
221
|
+
path?: string;
|
|
213
222
|
/** Fault only paths starting with this prefix. Omit to match every path. */
|
|
214
223
|
pathPrefix?: string;
|
|
224
|
+
/** Fault only paths matching this regular expression (JavaScript syntax, unanchored). */
|
|
225
|
+
pathPattern?: string;
|
|
226
|
+
/** Fault only requests carrying these headers. `"*"` matches any value. */
|
|
227
|
+
requestHeaders?: Record<string, string>;
|
|
228
|
+
/** Fault only requests carrying these query parameters. `"*"` matches any value. */
|
|
229
|
+
query?: Record<string, string>;
|
|
215
230
|
/**
|
|
216
231
|
* Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
|
|
217
232
|
* an in-process caller usually wants, and what a parallel worker usually does not:
|
|
218
233
|
* rules added through `POST /__admin/faults` default to the calling namespace.
|
|
219
234
|
*/
|
|
220
235
|
namespace?: string;
|
|
236
|
+
/** Let this many matching requests through first. */
|
|
237
|
+
after?: number;
|
|
238
|
+
/** Then fault only every nth matching request: `3` faults the 3rd, 6th, 9th. */
|
|
239
|
+
every?: number;
|
|
240
|
+
/** Retire the rule after this many faults. Omit to keep it until removed. */
|
|
241
|
+
count?: number;
|
|
242
|
+
/** Fault this fraction of the remaining requests, `0`–`1`, drawn from the seed. Default `1`. */
|
|
243
|
+
rate?: number;
|
|
244
|
+
/**
|
|
245
|
+
* Fault only from this instant on the namespace clock. A duration (`"5m"`) counts from the
|
|
246
|
+
* clock when the rule was added. Listed as epoch ms.
|
|
247
|
+
*/
|
|
248
|
+
from?: Instant | Duration;
|
|
249
|
+
/** Stop faulting at this instant on the namespace clock. A duration counts from when added. */
|
|
250
|
+
until?: Instant | Duration;
|
|
221
251
|
/**
|
|
222
|
-
* Status of the injected response. Omit for a rule that only delays
|
|
223
|
-
*
|
|
224
|
-
* the request then still reaches the service.
|
|
252
|
+
* Status of the injected response. Omit for a rule that only delays, times out, drops,
|
|
253
|
+
* truncates, or switches on an `effect`: the request then still reaches the service.
|
|
225
254
|
*/
|
|
226
255
|
status?: number;
|
|
227
256
|
/** Response body, serialized as JSON. A string is sent as-is. */
|
|
228
257
|
body?: unknown;
|
|
258
|
+
/** Response headers. */
|
|
229
259
|
headers?: Record<string, string>;
|
|
230
|
-
/**
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
rate?: number;
|
|
234
|
-
/** Hold the response back this long, to exercise timeouts. */
|
|
260
|
+
/** Hold the response back this long. Listed as `delayMs`. */
|
|
261
|
+
delay?: Duration;
|
|
262
|
+
/** `delay`, in milliseconds. */
|
|
235
263
|
delayMs?: number;
|
|
236
264
|
/** Alias of `delayMs`. */
|
|
237
265
|
latencyMs?: number;
|
|
266
|
+
/** Extra seeded delay in `[0, jitter]`. Listed as `jitterMs`. */
|
|
267
|
+
jitter?: Duration;
|
|
268
|
+
jitterMs?: number;
|
|
269
|
+
/**
|
|
270
|
+
* Never answer: hold the request this long, then drop the connection. Listed as
|
|
271
|
+
* `timeoutMs`. With virtual time the wait is spent on the mock clock.
|
|
272
|
+
*/
|
|
273
|
+
timeout?: Duration;
|
|
274
|
+
timeoutMs?: number;
|
|
238
275
|
/**
|
|
239
276
|
* Drop the connection instead of answering: an in-process `fetch` rejects with a
|
|
240
277
|
* `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
|
|
241
278
|
*/
|
|
242
279
|
drop?: boolean;
|
|
280
|
+
/**
|
|
281
|
+
* Cut the response body off after this many bytes: the status and headers arrive, then
|
|
282
|
+
* the connection dies mid-body.
|
|
283
|
+
*/
|
|
284
|
+
truncate?: number;
|
|
243
285
|
/**
|
|
244
286
|
* A named service behaviour to switch on for the matching request instead of (or
|
|
245
287
|
* before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
|
|
@@ -248,8 +290,8 @@ type FaultRule = {
|
|
|
248
290
|
effect?: string;
|
|
249
291
|
/** Parameters for `effect`. */
|
|
250
292
|
params?: Record<string, unknown>;
|
|
251
|
-
/**
|
|
252
|
-
|
|
293
|
+
/** The preset this rule was expanded from, if any. */
|
|
294
|
+
fromPreset?: string;
|
|
253
295
|
};
|
|
254
296
|
/** A fault that fired for one request. */
|
|
255
297
|
type FaultHit = {
|
|
@@ -257,6 +299,10 @@ type FaultHit = {
|
|
|
257
299
|
/** The injected response; absent when the rule only delays, drops, or sets an effect. */
|
|
258
300
|
response?: Response;
|
|
259
301
|
drop?: boolean;
|
|
302
|
+
/** Set with `drop` when the rule held the request for its `timeout` first. */
|
|
303
|
+
timeout?: boolean;
|
|
304
|
+
/** Bytes of response body to let through before the connection dies. */
|
|
305
|
+
truncate?: number;
|
|
260
306
|
effect?: {
|
|
261
307
|
name: string;
|
|
262
308
|
params: Record<string, unknown>;
|
|
@@ -268,38 +314,200 @@ type FaultCandidate = {
|
|
|
268
314
|
method: string;
|
|
269
315
|
path: string;
|
|
270
316
|
namespace: string;
|
|
317
|
+
/** Request headers and query, for rules that match on them. */
|
|
318
|
+
headers?: Headers;
|
|
319
|
+
query?: URLSearchParams;
|
|
320
|
+
/** The namespace clock, for `from` / `until`. Rules with a window are skipped without it. */
|
|
321
|
+
now?: number;
|
|
322
|
+
/** How to spend a delay for this request. Default: the registry's own sleep. */
|
|
323
|
+
wait?: (ms: number) => Promise<void>;
|
|
324
|
+
};
|
|
325
|
+
/** A stored rule and how often it was consulted. */
|
|
326
|
+
type FaultListing = FaultRule & {
|
|
327
|
+
/** Faults left before the rule retires. `null` when it has no `count`. */
|
|
328
|
+
remaining: number | null;
|
|
329
|
+
/** Times the rule faulted a request. */
|
|
330
|
+
hits: number;
|
|
331
|
+
/** Requests that matched the rule, faulted or not. */
|
|
332
|
+
seen: number;
|
|
333
|
+
};
|
|
334
|
+
/** A namespace's own rules, with their counters, in the order they are tried. */
|
|
335
|
+
type FaultSnapshot = {
|
|
336
|
+
/**
|
|
337
|
+
* `position` is how many `"*"` rules are tried before the rule, which is what its place
|
|
338
|
+
* in the order means to a request and holds in any process.
|
|
339
|
+
*/
|
|
340
|
+
rules: (FaultListing & {
|
|
341
|
+
position?: number;
|
|
342
|
+
})[];
|
|
343
|
+
/** How many `fault_<n>` ids the namespace has handed out. */
|
|
344
|
+
nextId?: number;
|
|
271
345
|
};
|
|
272
346
|
type FaultRegistry = {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
rules: (FaultRule & {
|
|
276
|
-
remaining: number | null;
|
|
277
|
-
hits: number;
|
|
278
|
-
position: number;
|
|
279
|
-
})[];
|
|
280
|
-
rngState: number;
|
|
281
|
-
};
|
|
347
|
+
snapshot(namespace: string): FaultSnapshot;
|
|
348
|
+
/** Add a rule, or replace the rule with the same id in the same namespace. */
|
|
282
349
|
add(rule: FaultRule): FaultRule;
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
})[];
|
|
295
|
-
rngState: number;
|
|
296
|
-
}): void;
|
|
350
|
+
/** The next unused `fault_<n>` id in `namespace`. */
|
|
351
|
+
nextId(namespace: string): string;
|
|
352
|
+
/** Every rule, or the rules a namespace's requests can hit: its own and the global ones. */
|
|
353
|
+
list(namespace?: string): FaultListing[];
|
|
354
|
+
get(id: string, namespace?: string): FaultListing | undefined;
|
|
355
|
+
/** Remove a rule by id: from `namespace` (its own, then a global one), or wherever it is. */
|
|
356
|
+
remove(id: string, namespace?: string): boolean;
|
|
357
|
+
/** Remove every rule, or one namespace's own rules. */
|
|
358
|
+
clear(namespace?: string): void;
|
|
359
|
+
/** Replace a namespace's own rules with a snapshot's, wherever the snapshot was taken. */
|
|
360
|
+
restore(namespace: string, state: FaultSnapshot): void;
|
|
297
361
|
/**
|
|
298
362
|
* Every fault this request should get, in rule order, stopping at the first that answers
|
|
299
363
|
* or drops (effect-only and delay-only rules let later rules match too). Consumes one of
|
|
300
364
|
* each matching rule's remaining uses.
|
|
301
365
|
*/
|
|
302
366
|
take(candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
367
|
+
/**
|
|
368
|
+
* Fire these rules at one request without storing them: no matching, no schedule, in order,
|
|
369
|
+
* stopping at the first that answers or drops. Jitter draws from the namespace's stream.
|
|
370
|
+
*/
|
|
371
|
+
fire(rules: readonly FaultRule[], candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* The admin controls every mock shares, as one document.
|
|
376
|
+
*
|
|
377
|
+
* The same shape is accepted in three places, and means the same thing in each:
|
|
378
|
+
*
|
|
379
|
+
* - at boot: `createRuntime({ adminControls })`, `serve --admin-controls`,
|
|
380
|
+
* `MOCKINGBIRD_ADMIN_CONTROLS`
|
|
381
|
+
* - over HTTP: `PUT /__admin/controls`
|
|
382
|
+
* - per request: the `x-mockingbird-*` headers in {@link CONTROL_HEADERS}
|
|
383
|
+
*
|
|
384
|
+
* Every control is deterministic: given the same seed, clock and requests, a mock answers
|
|
385
|
+
* the same bytes. Nothing here reads the wall clock or `Math.random`.
|
|
386
|
+
*/
|
|
387
|
+
/** Milliseconds, or a string like `"250ms"`, `"2s"`, `"15m"`, `"1h"`, `"3d"`. */
|
|
388
|
+
type Duration = number | string;
|
|
389
|
+
/** Epoch milliseconds, or an ISO-8601 string. */
|
|
390
|
+
type Instant = number | string;
|
|
391
|
+
type ClockControls = {
|
|
392
|
+
/** Move the clock to this instant. */
|
|
393
|
+
now?: Instant;
|
|
394
|
+
/** Stop time. A frozen clock moves only when told to, so timestamps replay exactly. */
|
|
395
|
+
frozen?: boolean;
|
|
396
|
+
/**
|
|
397
|
+
* Step the clock forward by this much before every vendor request. With a frozen clock
|
|
398
|
+
* each request still gets its own, reproducible timestamp.
|
|
399
|
+
*/
|
|
400
|
+
autoAdvance?: Duration;
|
|
401
|
+
};
|
|
402
|
+
/** How long a response takes: a fixed delay plus seeded jitter in `[0, jitter]`. */
|
|
403
|
+
type LatencyRuleInput = {
|
|
404
|
+
delay?: Duration;
|
|
405
|
+
jitter?: Duration;
|
|
406
|
+
};
|
|
407
|
+
type LatencyControls = LatencyRuleInput & {
|
|
408
|
+
/** Per-operation overrides, keyed by operationId. A bare duration is its `delay`. */
|
|
409
|
+
operations?: Record<string, Duration | LatencyRuleInput>;
|
|
410
|
+
};
|
|
411
|
+
/** A fault to add: a rule (the id is assigned when omitted), or a named preset with overrides. */
|
|
412
|
+
type FaultInput = (Omit<FaultRule, "id"> & {
|
|
413
|
+
id?: string;
|
|
414
|
+
}) | ({
|
|
415
|
+
preset: string;
|
|
416
|
+
} & Partial<FaultRule>);
|
|
417
|
+
/** Identifies a {@link SnapshotDocument}. */
|
|
418
|
+
declare const SNAPSHOT_FORMAT = "mockingbird.snapshot/v1";
|
|
419
|
+
/**
|
|
420
|
+
* A namespace, as portable JSON: what `GET /__admin/snapshots/:id` returns and what
|
|
421
|
+
* `PUT /__admin/snapshots/:id` and the boot `snapshot` control accept. Only `format` and
|
|
422
|
+
* `records` are required, so a hand-written seed file is a valid snapshot.
|
|
423
|
+
*/
|
|
424
|
+
type SnapshotDocument = {
|
|
425
|
+
format: typeof SNAPSHOT_FORMAT;
|
|
426
|
+
/** The service that wrote it. A snapshot is rejected by any other service. */
|
|
427
|
+
service?: string;
|
|
428
|
+
/**
|
|
429
|
+
* Stored rows. `seq` orders a collection; omitted, rows keep their listed order. `raw` is
|
|
430
|
+
* the stored text of a row that is not a plain record, and replaces `value` when present.
|
|
431
|
+
*/
|
|
432
|
+
records: {
|
|
433
|
+
collection: string;
|
|
434
|
+
id: string;
|
|
435
|
+
seq?: number;
|
|
436
|
+
value?: unknown;
|
|
437
|
+
raw?: string;
|
|
438
|
+
}[];
|
|
439
|
+
/** Id counters, so the next generated id continues where the snapshot left off. */
|
|
440
|
+
sequences?: {
|
|
441
|
+
name: string;
|
|
442
|
+
kind: string;
|
|
443
|
+
value: number;
|
|
444
|
+
}[];
|
|
445
|
+
clock?: {
|
|
446
|
+
now: number;
|
|
447
|
+
frozen: boolean;
|
|
448
|
+
autoAdvanceMs?: number;
|
|
449
|
+
};
|
|
450
|
+
seed?: number | string;
|
|
451
|
+
/** Positions of the seeded random streams. */
|
|
452
|
+
rng?: {
|
|
453
|
+
state: number;
|
|
454
|
+
faults?: number;
|
|
455
|
+
latency?: number;
|
|
456
|
+
};
|
|
457
|
+
faults?: unknown;
|
|
458
|
+
latency?: unknown;
|
|
459
|
+
virtualTime?: boolean;
|
|
460
|
+
};
|
|
461
|
+
/** Controls for one namespace. */
|
|
462
|
+
type NamespaceControls = {
|
|
463
|
+
/** Seeds every random choice: fault rates, jitter, and whatever the service invents. */
|
|
464
|
+
seed?: number | string;
|
|
465
|
+
clock?: ClockControls;
|
|
466
|
+
/**
|
|
467
|
+
* Spend injected waits (latency, fault delays, timeouts) on the mock clock instead of the
|
|
468
|
+
* wall clock: the request returns at once, the clock has moved, and the journal records
|
|
469
|
+
* the wait exactly. Default `false`: waits are real, so a client's own timeout can fire.
|
|
470
|
+
*/
|
|
471
|
+
virtualTime?: boolean;
|
|
472
|
+
/** Baseline response time for every vendor request. A bare duration is its `delay`. */
|
|
473
|
+
latency?: Duration | LatencyControls;
|
|
474
|
+
faults?: readonly FaultInput[];
|
|
475
|
+
/** Start from this state instead of the service's own seed data. */
|
|
476
|
+
snapshot?: SnapshotDocument;
|
|
477
|
+
};
|
|
478
|
+
/** {@link NamespaceControls} for every namespace, with per-namespace overrides. */
|
|
479
|
+
type MockControls = NamespaceControls & {
|
|
480
|
+
/** Vendor credential → namespace, for SDKs that cannot send a namespace header. */
|
|
481
|
+
credentials?: Record<string, string>;
|
|
482
|
+
/** Overrides for named namespaces. A key given here replaces the shared value. */
|
|
483
|
+
namespaces?: Record<string, NamespaceControls>;
|
|
484
|
+
};
|
|
485
|
+
/** A latency rule in milliseconds. */
|
|
486
|
+
type LatencyRule = {
|
|
487
|
+
delayMs: number;
|
|
488
|
+
jitterMs: number;
|
|
489
|
+
};
|
|
490
|
+
/** Baseline latency for a namespace, normalized. */
|
|
491
|
+
type LatencyState = LatencyRule & {
|
|
492
|
+
operations: Record<string, LatencyRule>;
|
|
493
|
+
};
|
|
494
|
+
/** What {@link controlHeaders} turns into request headers. */
|
|
495
|
+
type ControlHeaderInput = {
|
|
496
|
+
namespace?: string;
|
|
497
|
+
adminKey?: string;
|
|
498
|
+
branch?: string;
|
|
499
|
+
at?: string;
|
|
500
|
+
reset?: boolean;
|
|
501
|
+
restore?: string;
|
|
502
|
+
seed?: number | string;
|
|
503
|
+
time?: Instant | Date;
|
|
504
|
+
advance?: Duration;
|
|
505
|
+
virtualTime?: boolean;
|
|
506
|
+
delay?: Duration;
|
|
507
|
+
timeout?: Duration;
|
|
508
|
+
/** A status, `"drop"`, a preset name, or a fault rule. */
|
|
509
|
+
fault?: number | string | Record<string, unknown>;
|
|
510
|
+
snapshot?: string;
|
|
303
511
|
};
|
|
304
512
|
|
|
305
513
|
/**
|
|
@@ -339,6 +547,8 @@ type RequestLog = {
|
|
|
339
547
|
unmatched: boolean;
|
|
340
548
|
/** Set when a fault rule produced the response. */
|
|
341
549
|
faultId?: string;
|
|
550
|
+
/** Milliseconds of injected wait: latency, fault delays and timeouts. Absent when none. */
|
|
551
|
+
delayMs?: number;
|
|
342
552
|
/** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
|
|
343
553
|
ids?: Record<string, string>;
|
|
344
554
|
/** Set when the service created a resource the request referred to but that did not exist. */
|
|
@@ -384,6 +594,12 @@ type JournalQuery = {
|
|
|
384
594
|
/** Only this namespace. Omit for every namespace, oldest first across all of them. */
|
|
385
595
|
namespace?: string;
|
|
386
596
|
operationId?: string;
|
|
597
|
+
/** Only this HTTP method, case-insensitive. */
|
|
598
|
+
method?: string;
|
|
599
|
+
/** Only this exact path. */
|
|
600
|
+
path?: string;
|
|
601
|
+
/** Only requests this fault rule answered or shaped. */
|
|
602
|
+
faultId?: string;
|
|
387
603
|
status?: number;
|
|
388
604
|
/** Only entries at or after this instant (epoch ms). */
|
|
389
605
|
since?: number;
|
|
@@ -398,6 +614,50 @@ type Journal = {
|
|
|
398
614
|
clear(namespace?: string): void;
|
|
399
615
|
};
|
|
400
616
|
|
|
617
|
+
/**
|
|
618
|
+
* Baseline response time, per namespace: how long every vendor request takes before any
|
|
619
|
+
* fault is considered. Jitter draws from a stream the caller owns, one per namespace and
|
|
620
|
+
* separate from the fault stream, so adding latency never shifts which requests a `rate`
|
|
621
|
+
* fault hits.
|
|
622
|
+
*/
|
|
623
|
+
type LatencyRegistry = {
|
|
624
|
+
get(namespace: string): LatencyState;
|
|
625
|
+
set(namespace: string, state: LatencyState): LatencyState;
|
|
626
|
+
/** Remove one namespace's latency, or every namespace's. */
|
|
627
|
+
clear(namespace?: string): void;
|
|
628
|
+
/** Milliseconds this request waits. Draws jitter, so call it once per request. */
|
|
629
|
+
take(namespace: string, operationId: string | undefined): number;
|
|
630
|
+
};
|
|
631
|
+
|
|
632
|
+
/** Clock state as the admin API reports it. */
|
|
633
|
+
type ControlClock = ClockState & {
|
|
634
|
+
/** `now`, as ISO-8601. */
|
|
635
|
+
iso: string;
|
|
636
|
+
/** Milliseconds the clock steps before every vendor request. */
|
|
637
|
+
autoAdvanceMs: number;
|
|
638
|
+
};
|
|
639
|
+
/** One namespace's controls: the body of `GET /__admin/controls`. */
|
|
640
|
+
type ControlState = {
|
|
641
|
+
namespace: string;
|
|
642
|
+
seed: number | string;
|
|
643
|
+
clock: ControlClock;
|
|
644
|
+
virtualTime: boolean;
|
|
645
|
+
latency: LatencyState;
|
|
646
|
+
faults: FaultListing[];
|
|
647
|
+
};
|
|
648
|
+
|
|
649
|
+
/** What `GET /__admin/snapshots` lists for each snapshot. */
|
|
650
|
+
type SnapshotInfo = {
|
|
651
|
+
id: string;
|
|
652
|
+
namespace: string;
|
|
653
|
+
/** Stored rows in the snapshot. */
|
|
654
|
+
records: number;
|
|
655
|
+
/** The namespace clock when it was taken, epoch ms. */
|
|
656
|
+
at: number;
|
|
657
|
+
/** Whether `GET /snapshots/:id` can return it as a {@link SnapshotDocument}. */
|
|
658
|
+
portable: boolean;
|
|
659
|
+
};
|
|
660
|
+
|
|
401
661
|
/** Credential → namespace mapping behind `PUT /__admin/credentials`. */
|
|
402
662
|
type CredentialRegistry = {
|
|
403
663
|
set(credential: string, namespace: string): void;
|
|
@@ -552,7 +812,10 @@ type ServiceInstance = FetchAPI$1 & {
|
|
|
552
812
|
};
|
|
553
813
|
type ServiceTimelineState = Readonly<{
|
|
554
814
|
snapshot: NamespaceSnapshot;
|
|
555
|
-
clock
|
|
815
|
+
/** `pinned`: the namespace's clock was frozen itself, not just following a frozen base. */
|
|
816
|
+
clock: Readonly<ClockState & {
|
|
817
|
+
pinned?: boolean;
|
|
818
|
+
}>;
|
|
556
819
|
rngState: number;
|
|
557
820
|
}>;
|
|
558
821
|
type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
|
|
@@ -565,14 +828,18 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI$1 & {
|
|
|
565
828
|
readonly sqlite: SqliteClient$1;
|
|
566
829
|
readonly clock: Clock;
|
|
567
830
|
readonly faults: FaultRegistry;
|
|
831
|
+
/** Baseline response time per namespace. */
|
|
832
|
+
readonly latency: LatencyRegistry;
|
|
568
833
|
readonly metrics: Metrics;
|
|
569
834
|
readonly journal: Journal;
|
|
570
835
|
readonly rng: Rng;
|
|
571
836
|
readonly credentials: CredentialRegistry;
|
|
572
837
|
/** The webhook hub, when the service has outbound webhooks. */
|
|
573
838
|
readonly webhooks: WebhookHub | undefined;
|
|
574
|
-
/**
|
|
575
|
-
|
|
839
|
+
/**
|
|
840
|
+
* A namespace's clock. Each follows the base clock, {@link ServiceRuntime.clock}, with an
|
|
841
|
+
* offset and a freeze of its own, so moving one never moves another.
|
|
842
|
+
*/
|
|
576
843
|
namespaceClock(namespace?: string): Clock;
|
|
577
844
|
namespaceOf(request: Request): string;
|
|
578
845
|
/** Opaque in-process checkpoint including records, controls and webhook history. */
|
|
@@ -584,8 +851,38 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI$1 & {
|
|
|
584
851
|
instance(namespace?: string): T;
|
|
585
852
|
/** Public names of every namespace created so far. */
|
|
586
853
|
namespaces(): string[];
|
|
587
|
-
/**
|
|
854
|
+
/** Return one namespace to its boot state, or every namespace with `"*"`. */
|
|
588
855
|
reset(namespace?: string): Promise<void>;
|
|
856
|
+
/** Reset a namespace and forget it, releasing everything it held. */
|
|
857
|
+
dropNamespace(namespace: string): Promise<void>;
|
|
858
|
+
/** A namespace's controls: seed, clock, virtual time, latency, faults and snapshots. */
|
|
859
|
+
controls(namespace?: string): ControlState & {
|
|
860
|
+
snapshots: SnapshotInfo[];
|
|
861
|
+
};
|
|
862
|
+
/** Apply a control document to a namespace. A given key replaces that control. */
|
|
863
|
+
configure(controls: NamespaceControls, namespace?: string): ControlState & {
|
|
864
|
+
snapshots: SnapshotInfo[];
|
|
865
|
+
};
|
|
866
|
+
/** Named snapshots of a namespace: records, clock, random streams, faults and latency. */
|
|
867
|
+
readonly snapshots: {
|
|
868
|
+
/** Capture the namespace now. Reusing a name replaces that snapshot. */
|
|
869
|
+
create(options?: {
|
|
870
|
+
name?: string;
|
|
871
|
+
namespace?: string;
|
|
872
|
+
}): SnapshotInfo;
|
|
873
|
+
list(namespace?: string): SnapshotInfo[];
|
|
874
|
+
/** The snapshot as portable JSON, to commit beside a suite or boot another mock from. */
|
|
875
|
+
export(id: string, namespace?: string): SnapshotDocument;
|
|
876
|
+
/** Store a document as a snapshot without restoring it. */
|
|
877
|
+
import(document: SnapshotDocument, options?: {
|
|
878
|
+
name?: string;
|
|
879
|
+
namespace?: string;
|
|
880
|
+
}): SnapshotInfo;
|
|
881
|
+
restore(id: string, namespace?: string): void;
|
|
882
|
+
delete(id: string, namespace?: string): boolean;
|
|
883
|
+
};
|
|
884
|
+
/** Request headers that carry controls, checked: spread them into a `fetch` or an SDK's defaults. */
|
|
885
|
+
headers(input: ControlHeaderInput): Record<string, string>;
|
|
589
886
|
snapshot(namespace?: string): NamespaceSnapshot;
|
|
590
887
|
restore(snapshot: NamespaceSnapshot, namespace?: string): void;
|
|
591
888
|
/** Capture the current branch. Mutating HTTP calls do this automatically. */
|
|
@@ -1568,6 +1865,8 @@ type JunctionRuntimeOptions = {
|
|
|
1568
1865
|
adminPrefix?: string;
|
|
1569
1866
|
/** Require `x-mockingbird-admin-key` on `/__admin/*`. */
|
|
1570
1867
|
adminKey?: string;
|
|
1868
|
+
/** Admin controls to boot with: clock, latency, faults, seed, a starting snapshot. */
|
|
1869
|
+
adminControls?: MockControls;
|
|
1571
1870
|
onLog?: (entry: RequestLog) => void;
|
|
1572
1871
|
};
|
|
1573
1872
|
type JunctionRuntime = ServiceRuntime<JunctionAPI> & {
|