@crvouga/mockingbird-service-step-functions 3.2.0 → 3.4.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 +18 -4
- package/DISCOVERY.md +23 -0
- package/README.md +24 -2
- package/dist/chunk-LSHC7AAT.js +4742 -0
- package/dist/chunk-LSHC7AAT.js.map +7 -0
- package/dist/chunk-WM6TYPGJ.js +5400 -0
- package/dist/chunk-WM6TYPGJ.js.map +7 -0
- package/dist/cli.js +2 -2
- package/dist/index.d.ts +354 -41
- package/dist/index.js +1 -1
- package/dist/server.d.ts +709 -82
- package/dist/server.js +2 -2
- package/package.json +3 -2
- package/dist/chunk-3GXULKKO.js +0 -3505
- package/dist/chunk-3GXULKKO.js.map +0 -7
- package/dist/chunk-FF2KA7GZ.js +0 -823
- package/dist/chunk-FF2KA7GZ.js.map +0 -7
package/dist/cli.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -209,7 +209,7 @@ type ClockState = {
|
|
|
209
209
|
now: number;
|
|
210
210
|
/** True while time does not advance on its own. */
|
|
211
211
|
frozen: boolean;
|
|
212
|
-
/** Milliseconds
|
|
212
|
+
/** Milliseconds a running clock adds to its underlying source. `0` while frozen. */
|
|
213
213
|
offsetMs: number;
|
|
214
214
|
};
|
|
215
215
|
type Clock = {
|
|
@@ -245,7 +245,10 @@ type Rng = {
|
|
|
245
245
|
state(): number;
|
|
246
246
|
/** Restore a state previously returned by {@link state}. */
|
|
247
247
|
setState(state: number): void;
|
|
248
|
-
seed
|
|
248
|
+
/** Restart the stream from a new seed. `reset` then returns to this seed. */
|
|
249
|
+
reseed(seed: number | string): void;
|
|
250
|
+
/** The seed the stream currently starts from. */
|
|
251
|
+
readonly seed: number;
|
|
249
252
|
};
|
|
250
253
|
|
|
251
254
|
/**
|
|
@@ -254,44 +257,83 @@ type Rng = {
|
|
|
254
257
|
* This is how a suite reaches the vendor's failure modes without the vendor: the
|
|
255
258
|
* quota error that only appears when a shared sandbox is full, the 429 that only
|
|
256
259
|
* appears under load, the 5xx that proves a retry path works.
|
|
260
|
+
*
|
|
261
|
+
* A rule has three parts. What it **matches** (`operationId`, `method`, `path`, …), **when**
|
|
262
|
+
* it fires among the matching requests (`after`, `every`, `count`, `rate`, `from`, `until`),
|
|
263
|
+
* and what it **does** (`status`, `delay`, `timeout`, `drop`, `truncate`, `effect`).
|
|
257
264
|
*/
|
|
258
265
|
type FaultRule = {
|
|
259
|
-
/** Stable id, so a suite can retire exactly the rule it added. */
|
|
266
|
+
/** Stable id, so a suite can retire exactly the rule it added. Unique within a namespace. */
|
|
260
267
|
id: string;
|
|
261
268
|
/** Fault only this operation. Omit to match every operation. */
|
|
262
269
|
operationId?: string;
|
|
263
270
|
/** Fault only this HTTP method, case-insensitive. Omit to match every method. */
|
|
264
271
|
method?: string;
|
|
272
|
+
/** Fault only this exact path. */
|
|
273
|
+
path?: string;
|
|
265
274
|
/** Fault only paths starting with this prefix. Omit to match every path. */
|
|
266
275
|
pathPrefix?: string;
|
|
276
|
+
/** Fault only paths matching this regular expression (JavaScript syntax, unanchored). */
|
|
277
|
+
pathPattern?: string;
|
|
278
|
+
/** Fault only requests carrying these headers. `"*"` matches any value. */
|
|
279
|
+
requestHeaders?: Record<string, string>;
|
|
280
|
+
/** Fault only requests carrying these query parameters. `"*"` matches any value. */
|
|
281
|
+
query?: Record<string, string>;
|
|
267
282
|
/**
|
|
268
283
|
* Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
|
|
269
284
|
* an in-process caller usually wants, and what a parallel worker usually does not:
|
|
270
285
|
* rules added through `POST /__admin/faults` default to the calling namespace.
|
|
271
286
|
*/
|
|
272
287
|
namespace?: string;
|
|
288
|
+
/** Let this many matching requests through first. */
|
|
289
|
+
after?: number;
|
|
290
|
+
/** Then fault only every nth matching request: `3` faults the 3rd, 6th, 9th. */
|
|
291
|
+
every?: number;
|
|
292
|
+
/** Retire the rule after this many faults. Omit to keep it until removed. */
|
|
293
|
+
count?: number;
|
|
294
|
+
/** Fault this fraction of the remaining requests, `0`–`1`, drawn from the seed. Default `1`. */
|
|
295
|
+
rate?: number;
|
|
296
|
+
/**
|
|
297
|
+
* Fault only from this instant on the namespace clock. A duration (`"5m"`) counts from the
|
|
298
|
+
* clock when the rule was added. Listed as epoch ms.
|
|
299
|
+
*/
|
|
300
|
+
from?: Instant | Duration;
|
|
301
|
+
/** Stop faulting at this instant on the namespace clock. A duration counts from when added. */
|
|
302
|
+
until?: Instant | Duration;
|
|
273
303
|
/**
|
|
274
|
-
* Status of the injected response. Omit for a rule that only delays
|
|
275
|
-
*
|
|
276
|
-
* the request then still reaches the service.
|
|
304
|
+
* Status of the injected response. Omit for a rule that only delays, times out, drops,
|
|
305
|
+
* truncates, or switches on an `effect`: the request then still reaches the service.
|
|
277
306
|
*/
|
|
278
307
|
status?: number;
|
|
279
308
|
/** Response body, serialized as JSON. A string is sent as-is. */
|
|
280
309
|
body?: unknown;
|
|
310
|
+
/** Response headers. */
|
|
281
311
|
headers?: Record<string, string>;
|
|
282
|
-
/**
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
rate?: number;
|
|
286
|
-
/** Hold the response back this long, to exercise timeouts. */
|
|
312
|
+
/** Hold the response back this long. Listed as `delayMs`. */
|
|
313
|
+
delay?: Duration;
|
|
314
|
+
/** `delay`, in milliseconds. */
|
|
287
315
|
delayMs?: number;
|
|
288
316
|
/** Alias of `delayMs`. */
|
|
289
317
|
latencyMs?: number;
|
|
318
|
+
/** Extra seeded delay in `[0, jitter]`. Listed as `jitterMs`. */
|
|
319
|
+
jitter?: Duration;
|
|
320
|
+
jitterMs?: number;
|
|
321
|
+
/**
|
|
322
|
+
* Never answer: hold the request this long, then drop the connection. Listed as
|
|
323
|
+
* `timeoutMs`. With virtual time the wait is spent on the mock clock.
|
|
324
|
+
*/
|
|
325
|
+
timeout?: Duration;
|
|
326
|
+
timeoutMs?: number;
|
|
290
327
|
/**
|
|
291
328
|
* Drop the connection instead of answering: an in-process `fetch` rejects with a
|
|
292
329
|
* `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
|
|
293
330
|
*/
|
|
294
331
|
drop?: boolean;
|
|
332
|
+
/**
|
|
333
|
+
* Cut the response body off after this many bytes: the status and headers arrive, then
|
|
334
|
+
* the connection dies mid-body.
|
|
335
|
+
*/
|
|
336
|
+
truncate?: number;
|
|
295
337
|
/**
|
|
296
338
|
* A named service behaviour to switch on for the matching request instead of (or
|
|
297
339
|
* before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
|
|
@@ -300,8 +342,8 @@ type FaultRule = {
|
|
|
300
342
|
effect?: string;
|
|
301
343
|
/** Parameters for `effect`. */
|
|
302
344
|
params?: Record<string, unknown>;
|
|
303
|
-
/**
|
|
304
|
-
|
|
345
|
+
/** The preset this rule was expanded from, if any. */
|
|
346
|
+
fromPreset?: string;
|
|
305
347
|
};
|
|
306
348
|
/** A fault that fired for one request. */
|
|
307
349
|
type FaultHit = {
|
|
@@ -309,6 +351,10 @@ type FaultHit = {
|
|
|
309
351
|
/** The injected response; absent when the rule only delays, drops, or sets an effect. */
|
|
310
352
|
response?: Response;
|
|
311
353
|
drop?: boolean;
|
|
354
|
+
/** Set with `drop` when the rule held the request for its `timeout` first. */
|
|
355
|
+
timeout?: boolean;
|
|
356
|
+
/** Bytes of response body to let through before the connection dies. */
|
|
357
|
+
truncate?: number;
|
|
312
358
|
effect?: {
|
|
313
359
|
name: string;
|
|
314
360
|
params: Record<string, unknown>;
|
|
@@ -333,38 +379,202 @@ type FaultCandidate = {
|
|
|
333
379
|
method: string;
|
|
334
380
|
path: string;
|
|
335
381
|
namespace: string;
|
|
382
|
+
/** Request headers and query, for rules that match on them. */
|
|
383
|
+
headers?: Headers;
|
|
384
|
+
query?: URLSearchParams;
|
|
385
|
+
/** The namespace clock, for `from` / `until`. Rules with a window are skipped without it. */
|
|
386
|
+
now?: number;
|
|
387
|
+
/** How to spend a delay for this request. Default: the registry's own sleep. */
|
|
388
|
+
wait?: (ms: number) => Promise<void>;
|
|
389
|
+
};
|
|
390
|
+
/** A stored rule and how often it was consulted. */
|
|
391
|
+
type FaultListing = FaultRule & {
|
|
392
|
+
/** Faults left before the rule retires. `null` when it has no `count`. */
|
|
393
|
+
remaining: number | null;
|
|
394
|
+
/** Times the rule faulted a request. */
|
|
395
|
+
hits: number;
|
|
396
|
+
/** Requests that matched the rule, faulted or not. */
|
|
397
|
+
seen: number;
|
|
398
|
+
};
|
|
399
|
+
/** A namespace's own rules, with their counters, in the order they are tried. */
|
|
400
|
+
type FaultSnapshot = {
|
|
401
|
+
/**
|
|
402
|
+
* `position` is how many `"*"` rules are tried before the rule, which is what its place
|
|
403
|
+
* in the order means to a request and holds in any process.
|
|
404
|
+
*/
|
|
405
|
+
rules: (FaultListing & {
|
|
406
|
+
position?: number;
|
|
407
|
+
})[];
|
|
408
|
+
/** How many `fault_<n>` ids the namespace has handed out. */
|
|
409
|
+
nextId?: number;
|
|
336
410
|
};
|
|
337
411
|
type FaultRegistry = {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
rules: (FaultRule & {
|
|
341
|
-
remaining: number | null;
|
|
342
|
-
hits: number;
|
|
343
|
-
position: number;
|
|
344
|
-
})[];
|
|
345
|
-
rngState: number;
|
|
346
|
-
};
|
|
412
|
+
snapshot(namespace: string): FaultSnapshot;
|
|
413
|
+
/** Add a rule, or replace the rule with the same id in the same namespace. */
|
|
347
414
|
add(rule: FaultRule): FaultRule;
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
})[];
|
|
360
|
-
rngState: number;
|
|
361
|
-
}): void;
|
|
415
|
+
/** The next unused `fault_<n>` id in `namespace`. */
|
|
416
|
+
nextId(namespace: string): string;
|
|
417
|
+
/** Every rule, or the rules a namespace's requests can hit: its own and the global ones. */
|
|
418
|
+
list(namespace?: string): FaultListing[];
|
|
419
|
+
get(id: string, namespace?: string): FaultListing | undefined;
|
|
420
|
+
/** Remove a rule by id: from `namespace` (its own, then a global one), or wherever it is. */
|
|
421
|
+
remove(id: string, namespace?: string): boolean;
|
|
422
|
+
/** Remove every rule, or one namespace's own rules. */
|
|
423
|
+
clear(namespace?: string): void;
|
|
424
|
+
/** Replace a namespace's own rules with a snapshot's, wherever the snapshot was taken. */
|
|
425
|
+
restore(namespace: string, state: FaultSnapshot): void;
|
|
362
426
|
/**
|
|
363
427
|
* Every fault this request should get, in rule order, stopping at the first that answers
|
|
364
428
|
* or drops (effect-only and delay-only rules let later rules match too). Consumes one of
|
|
365
429
|
* each matching rule's remaining uses.
|
|
366
430
|
*/
|
|
367
431
|
take(candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
432
|
+
/**
|
|
433
|
+
* Fire these rules at one request without storing them: no matching, no schedule, in order,
|
|
434
|
+
* stopping at the first that answers or drops. Jitter draws from the namespace's stream.
|
|
435
|
+
*/
|
|
436
|
+
fire(rules: readonly FaultRule[], candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* The admin controls every mock shares, as one document.
|
|
441
|
+
*
|
|
442
|
+
* The same shape is accepted in three places, and means the same thing in each:
|
|
443
|
+
*
|
|
444
|
+
* - at boot: `createRuntime({ adminControls })`, `serve --admin-controls`,
|
|
445
|
+
* `MOCKINGBIRD_ADMIN_CONTROLS`
|
|
446
|
+
* - over HTTP: `PUT /__admin/controls`
|
|
447
|
+
* - per request: the `x-mockingbird-*` headers in {@link CONTROL_HEADERS}
|
|
448
|
+
*
|
|
449
|
+
* Every control is deterministic: given the same seed, clock and requests, a mock answers
|
|
450
|
+
* the same bytes. Nothing here reads the wall clock or `Math.random`.
|
|
451
|
+
*/
|
|
452
|
+
/** Milliseconds, or a string like `"250ms"`, `"2s"`, `"15m"`, `"1h"`, `"3d"`. */
|
|
453
|
+
type Duration = number | string;
|
|
454
|
+
/** Epoch milliseconds, or an ISO-8601 string. */
|
|
455
|
+
type Instant = number | string;
|
|
456
|
+
type ClockControls = {
|
|
457
|
+
/** Move the clock to this instant. */
|
|
458
|
+
now?: Instant;
|
|
459
|
+
/** Stop time. A frozen clock moves only when told to, so timestamps replay exactly. */
|
|
460
|
+
frozen?: boolean;
|
|
461
|
+
/**
|
|
462
|
+
* Step the clock forward by this much before every vendor request. With a frozen clock
|
|
463
|
+
* each request still gets its own, reproducible timestamp.
|
|
464
|
+
*/
|
|
465
|
+
autoAdvance?: Duration;
|
|
466
|
+
};
|
|
467
|
+
/** How long a response takes: a fixed delay plus seeded jitter in `[0, jitter]`. */
|
|
468
|
+
type LatencyRuleInput = {
|
|
469
|
+
delay?: Duration;
|
|
470
|
+
jitter?: Duration;
|
|
471
|
+
};
|
|
472
|
+
type LatencyControls = LatencyRuleInput & {
|
|
473
|
+
/** Per-operation overrides, keyed by operationId. A bare duration is its `delay`. */
|
|
474
|
+
operations?: Record<string, Duration | LatencyRuleInput>;
|
|
475
|
+
};
|
|
476
|
+
/** A fault to add: a rule (the id is assigned when omitted), or a named preset with overrides. */
|
|
477
|
+
type FaultInput = (Omit<FaultRule, "id"> & {
|
|
478
|
+
id?: string;
|
|
479
|
+
}) | ({
|
|
480
|
+
preset: string;
|
|
481
|
+
} & Partial<FaultRule>);
|
|
482
|
+
/** Identifies a {@link SnapshotDocument}. */
|
|
483
|
+
declare const SNAPSHOT_FORMAT = "mockingbird.snapshot/v1";
|
|
484
|
+
/**
|
|
485
|
+
* A namespace, as portable JSON: what `GET /__admin/snapshots/:id` returns and what
|
|
486
|
+
* `PUT /__admin/snapshots/:id` and the boot `snapshot` control accept. Only `format` and
|
|
487
|
+
* `records` are required, so a hand-written seed file is a valid snapshot.
|
|
488
|
+
*/
|
|
489
|
+
type SnapshotDocument = {
|
|
490
|
+
format: typeof SNAPSHOT_FORMAT;
|
|
491
|
+
/** The service that wrote it. A snapshot is rejected by any other service. */
|
|
492
|
+
service?: string;
|
|
493
|
+
/**
|
|
494
|
+
* Stored rows. `seq` orders a collection; omitted, rows keep their listed order. `raw` is
|
|
495
|
+
* the stored text of a row that is not a plain record, and replaces `value` when present.
|
|
496
|
+
*/
|
|
497
|
+
records: {
|
|
498
|
+
collection: string;
|
|
499
|
+
id: string;
|
|
500
|
+
seq?: number;
|
|
501
|
+
value?: unknown;
|
|
502
|
+
raw?: string;
|
|
503
|
+
}[];
|
|
504
|
+
/** Id counters, so the next generated id continues where the snapshot left off. */
|
|
505
|
+
sequences?: {
|
|
506
|
+
name: string;
|
|
507
|
+
kind: string;
|
|
508
|
+
value: number;
|
|
509
|
+
}[];
|
|
510
|
+
clock?: {
|
|
511
|
+
now: number;
|
|
512
|
+
frozen: boolean;
|
|
513
|
+
autoAdvanceMs?: number;
|
|
514
|
+
};
|
|
515
|
+
seed?: number | string;
|
|
516
|
+
/** Positions of the seeded random streams. */
|
|
517
|
+
rng?: {
|
|
518
|
+
state: number;
|
|
519
|
+
faults?: number;
|
|
520
|
+
latency?: number;
|
|
521
|
+
};
|
|
522
|
+
faults?: unknown;
|
|
523
|
+
latency?: unknown;
|
|
524
|
+
virtualTime?: boolean;
|
|
525
|
+
/** Quiescent webhook endpoints, delivery history and fault state. Contains private configuration. */
|
|
526
|
+
webhooks?: unknown;
|
|
527
|
+
};
|
|
528
|
+
/** Controls for one namespace. */
|
|
529
|
+
type NamespaceControls = {
|
|
530
|
+
/** Seeds every random choice: fault rates, jitter, and whatever the service invents. */
|
|
531
|
+
seed?: number | string;
|
|
532
|
+
clock?: ClockControls;
|
|
533
|
+
/**
|
|
534
|
+
* Spend injected waits (latency, fault delays, timeouts) on the mock clock instead of the
|
|
535
|
+
* wall clock: the request returns at once, the clock has moved, and the journal records
|
|
536
|
+
* the wait exactly. Default `false`: waits are real, so a client's own timeout can fire.
|
|
537
|
+
*/
|
|
538
|
+
virtualTime?: boolean;
|
|
539
|
+
/** Baseline response time for every vendor request. A bare duration is its `delay`. */
|
|
540
|
+
latency?: Duration | LatencyControls;
|
|
541
|
+
faults?: readonly FaultInput[];
|
|
542
|
+
/** Start from this state instead of the service's own seed data. */
|
|
543
|
+
snapshot?: SnapshotDocument;
|
|
544
|
+
};
|
|
545
|
+
/** {@link NamespaceControls} for every namespace, with per-namespace overrides. */
|
|
546
|
+
type MockControls = NamespaceControls & {
|
|
547
|
+
/** Vendor credential → namespace, for SDKs that cannot send a namespace header. */
|
|
548
|
+
credentials?: Record<string, string>;
|
|
549
|
+
/** Overrides for named namespaces. A key given here replaces the shared value. */
|
|
550
|
+
namespaces?: Record<string, NamespaceControls>;
|
|
551
|
+
};
|
|
552
|
+
/** A latency rule in milliseconds. */
|
|
553
|
+
type LatencyRule = {
|
|
554
|
+
delayMs: number;
|
|
555
|
+
jitterMs: number;
|
|
556
|
+
};
|
|
557
|
+
/** Baseline latency for a namespace, normalized. */
|
|
558
|
+
type LatencyState = LatencyRule & {
|
|
559
|
+
operations: Record<string, LatencyRule>;
|
|
560
|
+
};
|
|
561
|
+
/** What {@link controlHeaders} turns into request headers. */
|
|
562
|
+
type ControlHeaderInput = {
|
|
563
|
+
namespace?: string;
|
|
564
|
+
adminKey?: string;
|
|
565
|
+
branch?: string;
|
|
566
|
+
at?: string;
|
|
567
|
+
reset?: boolean;
|
|
568
|
+
restore?: string;
|
|
569
|
+
seed?: number | string;
|
|
570
|
+
time?: Instant | Date;
|
|
571
|
+
advance?: Duration;
|
|
572
|
+
virtualTime?: boolean;
|
|
573
|
+
delay?: Duration;
|
|
574
|
+
timeout?: Duration;
|
|
575
|
+
/** A status, `"drop"`, a preset name, or a fault rule. */
|
|
576
|
+
fault?: number | string | Record<string, unknown>;
|
|
577
|
+
snapshot?: string;
|
|
368
578
|
};
|
|
369
579
|
|
|
370
580
|
/**
|
|
@@ -404,6 +614,8 @@ type RequestLog = {
|
|
|
404
614
|
unmatched: boolean;
|
|
405
615
|
/** Set when a fault rule produced the response. */
|
|
406
616
|
faultId?: string;
|
|
617
|
+
/** Milliseconds of injected wait: latency, fault delays and timeouts. Absent when none. */
|
|
618
|
+
delayMs?: number;
|
|
407
619
|
/** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
|
|
408
620
|
ids?: Record<string, string>;
|
|
409
621
|
/** Set when the service created a resource the request referred to but that did not exist. */
|
|
@@ -449,6 +661,12 @@ type JournalQuery = {
|
|
|
449
661
|
/** Only this namespace. Omit for every namespace, oldest first across all of them. */
|
|
450
662
|
namespace?: string;
|
|
451
663
|
operationId?: string;
|
|
664
|
+
/** Only this HTTP method, case-insensitive. */
|
|
665
|
+
method?: string;
|
|
666
|
+
/** Only this exact path. */
|
|
667
|
+
path?: string;
|
|
668
|
+
/** Only requests this fault rule answered or shaped. */
|
|
669
|
+
faultId?: string;
|
|
452
670
|
status?: number;
|
|
453
671
|
/** Only entries at or after this instant (epoch ms). */
|
|
454
672
|
since?: number;
|
|
@@ -463,6 +681,50 @@ type Journal = {
|
|
|
463
681
|
clear(namespace?: string): void;
|
|
464
682
|
};
|
|
465
683
|
|
|
684
|
+
/**
|
|
685
|
+
* Baseline response time, per namespace: how long every vendor request takes before any
|
|
686
|
+
* fault is considered. Jitter draws from a stream the caller owns, one per namespace and
|
|
687
|
+
* separate from the fault stream, so adding latency never shifts which requests a `rate`
|
|
688
|
+
* fault hits.
|
|
689
|
+
*/
|
|
690
|
+
type LatencyRegistry = {
|
|
691
|
+
get(namespace: string): LatencyState;
|
|
692
|
+
set(namespace: string, state: LatencyState): LatencyState;
|
|
693
|
+
/** Remove one namespace's latency, or every namespace's. */
|
|
694
|
+
clear(namespace?: string): void;
|
|
695
|
+
/** Milliseconds this request waits. Draws jitter, so call it once per request. */
|
|
696
|
+
take(namespace: string, operationId: string | undefined): number;
|
|
697
|
+
};
|
|
698
|
+
|
|
699
|
+
/** Clock state as the admin API reports it. */
|
|
700
|
+
type ControlClock = ClockState & {
|
|
701
|
+
/** `now`, as ISO-8601. */
|
|
702
|
+
iso: string;
|
|
703
|
+
/** Milliseconds the clock steps before every vendor request. */
|
|
704
|
+
autoAdvanceMs: number;
|
|
705
|
+
};
|
|
706
|
+
/** One namespace's controls: the body of `GET /__admin/controls`. */
|
|
707
|
+
type ControlState = {
|
|
708
|
+
namespace: string;
|
|
709
|
+
seed: number | string;
|
|
710
|
+
clock: ControlClock;
|
|
711
|
+
virtualTime: boolean;
|
|
712
|
+
latency: LatencyState;
|
|
713
|
+
faults: FaultListing[];
|
|
714
|
+
};
|
|
715
|
+
|
|
716
|
+
/** What `GET /__admin/snapshots` lists for each snapshot. */
|
|
717
|
+
type SnapshotInfo = {
|
|
718
|
+
id: string;
|
|
719
|
+
namespace: string;
|
|
720
|
+
/** Stored rows in the snapshot. */
|
|
721
|
+
records: number;
|
|
722
|
+
/** The namespace clock when it was taken, epoch ms. */
|
|
723
|
+
at: number;
|
|
724
|
+
/** Whether `GET /snapshots/:id` can return it as a {@link SnapshotDocument}. */
|
|
725
|
+
portable: boolean;
|
|
726
|
+
};
|
|
727
|
+
|
|
466
728
|
/** Credential → namespace mapping behind `PUT /__admin/credentials`. */
|
|
467
729
|
type CredentialRegistry = {
|
|
468
730
|
set(credential: string, namespace: string): void;
|
|
@@ -475,6 +737,8 @@ type CredentialRegistry = {
|
|
|
475
737
|
}[];
|
|
476
738
|
};
|
|
477
739
|
|
|
740
|
+
type OwnedTransport = (request: Request, namespace: string, send: typeof fetch) => Promise<Response>;
|
|
741
|
+
|
|
478
742
|
/**
|
|
479
743
|
* A point-in-time copy of everything a service namespace holds.
|
|
480
744
|
*
|
|
@@ -592,8 +856,16 @@ type PublishInput = {
|
|
|
592
856
|
id?: string;
|
|
593
857
|
};
|
|
594
858
|
type WebhookHub = {
|
|
859
|
+
observeDeliveries(listener: (event: {
|
|
860
|
+
namespace: string;
|
|
861
|
+
state: string;
|
|
862
|
+
deliveryId: string;
|
|
863
|
+
}) => void): () => void;
|
|
864
|
+
setTransportPolicy(policy: OwnedTransport): void;
|
|
595
865
|
pending(namespace: string): number;
|
|
596
866
|
snapshot(namespace: string): unknown;
|
|
867
|
+
exportSnapshot(handle: unknown): unknown;
|
|
868
|
+
importSnapshot(namespace: string, document: unknown): unknown;
|
|
597
869
|
restore(namespace: string, snapshot: unknown): void;
|
|
598
870
|
publish(input: PublishInput): WebhookMessage;
|
|
599
871
|
/** Replace a namespace's own endpoints (`PUT /__admin/webhook-endpoints`). */
|
|
@@ -606,7 +878,7 @@ type WebhookHub = {
|
|
|
606
878
|
/** Run every pending retry (and release held reordered messages) now, and every retry those attempts schedule, until nothing is pending. */
|
|
607
879
|
flush(): Promise<void>;
|
|
608
880
|
/** Resolve once nothing is in flight. */
|
|
609
|
-
idle(): Promise<void>;
|
|
881
|
+
idle(namespace?: string): Promise<void>;
|
|
610
882
|
fault(namespace: string, fault: WebhookFault): void;
|
|
611
883
|
clear(namespace?: string): void;
|
|
612
884
|
};
|
|
@@ -617,7 +889,10 @@ type ServiceInstance = FetchAPI & {
|
|
|
617
889
|
};
|
|
618
890
|
type ServiceTimelineState = Readonly<{
|
|
619
891
|
snapshot: NamespaceSnapshot;
|
|
620
|
-
clock
|
|
892
|
+
/** `pinned`: the namespace's clock was frozen itself, not just following a frozen base. */
|
|
893
|
+
clock: Readonly<ClockState & {
|
|
894
|
+
pinned?: boolean;
|
|
895
|
+
}>;
|
|
621
896
|
rngState: number;
|
|
622
897
|
}>;
|
|
623
898
|
type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
|
|
@@ -630,27 +905,63 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
|
|
|
630
905
|
readonly sqlite: SqliteClient$1;
|
|
631
906
|
readonly clock: Clock;
|
|
632
907
|
readonly faults: FaultRegistry;
|
|
908
|
+
/** Baseline response time per namespace. */
|
|
909
|
+
readonly latency: LatencyRegistry;
|
|
633
910
|
readonly metrics: Metrics;
|
|
634
911
|
readonly journal: Journal;
|
|
635
912
|
readonly rng: Rng;
|
|
636
913
|
readonly credentials: CredentialRegistry;
|
|
637
914
|
/** The webhook hub, when the service has outbound webhooks. */
|
|
638
915
|
readonly webhooks: WebhookHub | undefined;
|
|
639
|
-
/**
|
|
640
|
-
|
|
916
|
+
/**
|
|
917
|
+
* A namespace's clock. Each follows the base clock, {@link ServiceRuntime.clock}, with an
|
|
918
|
+
* offset and a freeze of its own, so moving one never moves another.
|
|
919
|
+
*/
|
|
641
920
|
namespaceClock(namespace?: string): Clock;
|
|
642
921
|
namespaceOf(request: Request): string;
|
|
643
922
|
/** Opaque in-process checkpoint including records, controls and webhook history. */
|
|
644
923
|
fleetSnapshot(namespace: string): object;
|
|
645
924
|
fleetRestore(snapshot: unknown, namespace: string): void;
|
|
925
|
+
fleetExport(snapshot: unknown): SnapshotDocument;
|
|
926
|
+
fleetImport(namespace: string, document: unknown): object;
|
|
646
927
|
/** Expand a named preset into fault rules (and webhook faults) for `namespace`. */
|
|
647
928
|
applyPreset(name: string, namespace?: string, overrides?: Partial<FaultRule>): FaultRule[];
|
|
648
929
|
/** The instance behind `namespace` (the default one when omitted), created on first use. */
|
|
649
930
|
instance(namespace?: string): T;
|
|
650
931
|
/** Public names of every namespace created so far. */
|
|
651
932
|
namespaces(): string[];
|
|
652
|
-
/**
|
|
933
|
+
/** Return one namespace to its boot state, or every namespace with `"*"`. */
|
|
653
934
|
reset(namespace?: string): Promise<void>;
|
|
935
|
+
/** Reset a namespace and forget it, releasing everything it held. */
|
|
936
|
+
dropNamespace(namespace: string): Promise<void>;
|
|
937
|
+
/** A namespace's controls: seed, clock, virtual time, latency, faults and snapshots. */
|
|
938
|
+
controls(namespace?: string): ControlState & {
|
|
939
|
+
snapshots: SnapshotInfo[];
|
|
940
|
+
};
|
|
941
|
+
/** Apply a control document to a namespace. A given key replaces that control. */
|
|
942
|
+
configure(controls: NamespaceControls, namespace?: string): ControlState & {
|
|
943
|
+
snapshots: SnapshotInfo[];
|
|
944
|
+
};
|
|
945
|
+
/** Named snapshots of a namespace: records, clock, random streams, faults and latency. */
|
|
946
|
+
readonly snapshots: {
|
|
947
|
+
/** Capture the namespace now. Reusing a name replaces that snapshot. */
|
|
948
|
+
create(options?: {
|
|
949
|
+
name?: string;
|
|
950
|
+
namespace?: string;
|
|
951
|
+
}): SnapshotInfo;
|
|
952
|
+
list(namespace?: string): SnapshotInfo[];
|
|
953
|
+
/** The snapshot as portable JSON, to commit beside a suite or boot another mock from. */
|
|
954
|
+
export(id: string, namespace?: string): SnapshotDocument;
|
|
955
|
+
/** Store a document as a snapshot without restoring it. */
|
|
956
|
+
import(document: SnapshotDocument, options?: {
|
|
957
|
+
name?: string;
|
|
958
|
+
namespace?: string;
|
|
959
|
+
}): SnapshotInfo;
|
|
960
|
+
restore(id: string, namespace?: string): void;
|
|
961
|
+
delete(id: string, namespace?: string): boolean;
|
|
962
|
+
};
|
|
963
|
+
/** Request headers that carry controls, checked: spread them into a `fetch` or an SDK's defaults. */
|
|
964
|
+
headers(input: ControlHeaderInput): Record<string, string>;
|
|
654
965
|
snapshot(namespace?: string): NamespaceSnapshot;
|
|
655
966
|
restore(snapshot: NamespaceSnapshot, namespace?: string): void;
|
|
656
967
|
/** Capture the current branch. Mutating HTTP calls do this automatically. */
|
|
@@ -921,6 +1232,8 @@ type StepFunctionsRuntimeOptions = {
|
|
|
921
1232
|
seed?: number | string;
|
|
922
1233
|
adminPrefix?: string;
|
|
923
1234
|
adminKey?: string;
|
|
1235
|
+
/** Admin controls to boot with: clock, latency, faults, seed, a starting snapshot. */
|
|
1236
|
+
adminControls?: MockControls;
|
|
924
1237
|
onLog?: (entry: RequestLog) => void;
|
|
925
1238
|
region?: string;
|
|
926
1239
|
accountId?: string;
|