@crvouga/mockingbird-service-resource-groups 1.2.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 +8 -2
- package/DISCOVERY.md +23 -0
- package/README.md +32 -3
- package/dist/chunk-3X2I3QJZ.js +9372 -0
- package/dist/chunk-3X2I3QJZ.js.map +7 -0
- package/dist/{chunk-JRC5RYC5.js → chunk-WE6VVUXX.js} +136 -25
- package/dist/chunk-WE6VVUXX.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-JRC5RYC5.js.map +0 -7
- package/dist/chunk-TCYWTMZ5.js +0 -7580
- package/dist/chunk-TCYWTMZ5.js.map +0 -7
package/dist/index.d.ts
CHANGED
|
@@ -244,7 +244,7 @@ type ClockState = {
|
|
|
244
244
|
now: number;
|
|
245
245
|
/** True while time does not advance on its own. */
|
|
246
246
|
frozen: boolean;
|
|
247
|
-
/** Milliseconds
|
|
247
|
+
/** Milliseconds a running clock adds to its underlying source. `0` while frozen. */
|
|
248
248
|
offsetMs: number;
|
|
249
249
|
};
|
|
250
250
|
type Clock = {
|
|
@@ -280,7 +280,10 @@ type Rng = {
|
|
|
280
280
|
state(): number;
|
|
281
281
|
/** Restore a state previously returned by {@link state}. */
|
|
282
282
|
setState(state: number): void;
|
|
283
|
-
seed
|
|
283
|
+
/** Restart the stream from a new seed. `reset` then returns to this seed. */
|
|
284
|
+
reseed(seed: number | string): void;
|
|
285
|
+
/** The seed the stream currently starts from. */
|
|
286
|
+
readonly seed: number;
|
|
284
287
|
};
|
|
285
288
|
|
|
286
289
|
/**
|
|
@@ -289,44 +292,83 @@ type Rng = {
|
|
|
289
292
|
* This is how a suite reaches the vendor's failure modes without the vendor: the
|
|
290
293
|
* quota error that only appears when a shared sandbox is full, the 429 that only
|
|
291
294
|
* appears under load, the 5xx that proves a retry path works.
|
|
295
|
+
*
|
|
296
|
+
* A rule has three parts. What it **matches** (`operationId`, `method`, `path`, …), **when**
|
|
297
|
+
* it fires among the matching requests (`after`, `every`, `count`, `rate`, `from`, `until`),
|
|
298
|
+
* and what it **does** (`status`, `delay`, `timeout`, `drop`, `truncate`, `effect`).
|
|
292
299
|
*/
|
|
293
300
|
type FaultRule = {
|
|
294
|
-
/** Stable id, so a suite can retire exactly the rule it added. */
|
|
301
|
+
/** Stable id, so a suite can retire exactly the rule it added. Unique within a namespace. */
|
|
295
302
|
id: string;
|
|
296
303
|
/** Fault only this operation. Omit to match every operation. */
|
|
297
304
|
operationId?: string;
|
|
298
305
|
/** Fault only this HTTP method, case-insensitive. Omit to match every method. */
|
|
299
306
|
method?: string;
|
|
307
|
+
/** Fault only this exact path. */
|
|
308
|
+
path?: string;
|
|
300
309
|
/** Fault only paths starting with this prefix. Omit to match every path. */
|
|
301
310
|
pathPrefix?: string;
|
|
311
|
+
/** Fault only paths matching this regular expression (JavaScript syntax, unanchored). */
|
|
312
|
+
pathPattern?: string;
|
|
313
|
+
/** Fault only requests carrying these headers. `"*"` matches any value. */
|
|
314
|
+
requestHeaders?: Record<string, string>;
|
|
315
|
+
/** Fault only requests carrying these query parameters. `"*"` matches any value. */
|
|
316
|
+
query?: Record<string, string>;
|
|
302
317
|
/**
|
|
303
318
|
* Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
|
|
304
319
|
* an in-process caller usually wants, and what a parallel worker usually does not:
|
|
305
320
|
* rules added through `POST /__admin/faults` default to the calling namespace.
|
|
306
321
|
*/
|
|
307
322
|
namespace?: string;
|
|
323
|
+
/** Let this many matching requests through first. */
|
|
324
|
+
after?: number;
|
|
325
|
+
/** Then fault only every nth matching request: `3` faults the 3rd, 6th, 9th. */
|
|
326
|
+
every?: number;
|
|
327
|
+
/** Retire the rule after this many faults. Omit to keep it until removed. */
|
|
328
|
+
count?: number;
|
|
329
|
+
/** Fault this fraction of the remaining requests, `0`–`1`, drawn from the seed. Default `1`. */
|
|
330
|
+
rate?: number;
|
|
331
|
+
/**
|
|
332
|
+
* Fault only from this instant on the namespace clock. A duration (`"5m"`) counts from the
|
|
333
|
+
* clock when the rule was added. Listed as epoch ms.
|
|
334
|
+
*/
|
|
335
|
+
from?: Instant | Duration;
|
|
336
|
+
/** Stop faulting at this instant on the namespace clock. A duration counts from when added. */
|
|
337
|
+
until?: Instant | Duration;
|
|
308
338
|
/**
|
|
309
|
-
* Status of the injected response. Omit for a rule that only delays
|
|
310
|
-
*
|
|
311
|
-
* the request then still reaches the service.
|
|
339
|
+
* Status of the injected response. Omit for a rule that only delays, times out, drops,
|
|
340
|
+
* truncates, or switches on an `effect`: the request then still reaches the service.
|
|
312
341
|
*/
|
|
313
342
|
status?: number;
|
|
314
343
|
/** Response body, serialized as JSON. A string is sent as-is. */
|
|
315
344
|
body?: unknown;
|
|
345
|
+
/** Response headers. */
|
|
316
346
|
headers?: Record<string, string>;
|
|
317
|
-
/**
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
rate?: number;
|
|
321
|
-
/** Hold the response back this long, to exercise timeouts. */
|
|
347
|
+
/** Hold the response back this long. Listed as `delayMs`. */
|
|
348
|
+
delay?: Duration;
|
|
349
|
+
/** `delay`, in milliseconds. */
|
|
322
350
|
delayMs?: number;
|
|
323
351
|
/** Alias of `delayMs`. */
|
|
324
352
|
latencyMs?: number;
|
|
353
|
+
/** Extra seeded delay in `[0, jitter]`. Listed as `jitterMs`. */
|
|
354
|
+
jitter?: Duration;
|
|
355
|
+
jitterMs?: number;
|
|
356
|
+
/**
|
|
357
|
+
* Never answer: hold the request this long, then drop the connection. Listed as
|
|
358
|
+
* `timeoutMs`. With virtual time the wait is spent on the mock clock.
|
|
359
|
+
*/
|
|
360
|
+
timeout?: Duration;
|
|
361
|
+
timeoutMs?: number;
|
|
325
362
|
/**
|
|
326
363
|
* Drop the connection instead of answering: an in-process `fetch` rejects with a
|
|
327
364
|
* `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
|
|
328
365
|
*/
|
|
329
366
|
drop?: boolean;
|
|
367
|
+
/**
|
|
368
|
+
* Cut the response body off after this many bytes: the status and headers arrive, then
|
|
369
|
+
* the connection dies mid-body.
|
|
370
|
+
*/
|
|
371
|
+
truncate?: number;
|
|
330
372
|
/**
|
|
331
373
|
* A named service behaviour to switch on for the matching request instead of (or
|
|
332
374
|
* before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
|
|
@@ -335,8 +377,8 @@ type FaultRule = {
|
|
|
335
377
|
effect?: string;
|
|
336
378
|
/** Parameters for `effect`. */
|
|
337
379
|
params?: Record<string, unknown>;
|
|
338
|
-
/**
|
|
339
|
-
|
|
380
|
+
/** The preset this rule was expanded from, if any. */
|
|
381
|
+
fromPreset?: string;
|
|
340
382
|
};
|
|
341
383
|
/** A fault that fired for one request. */
|
|
342
384
|
type FaultHit = {
|
|
@@ -344,6 +386,10 @@ type FaultHit = {
|
|
|
344
386
|
/** The injected response; absent when the rule only delays, drops, or sets an effect. */
|
|
345
387
|
response?: Response;
|
|
346
388
|
drop?: boolean;
|
|
389
|
+
/** Set with `drop` when the rule held the request for its `timeout` first. */
|
|
390
|
+
timeout?: boolean;
|
|
391
|
+
/** Bytes of response body to let through before the connection dies. */
|
|
392
|
+
truncate?: number;
|
|
347
393
|
effect?: {
|
|
348
394
|
name: string;
|
|
349
395
|
params: Record<string, unknown>;
|
|
@@ -355,38 +401,200 @@ type FaultCandidate = {
|
|
|
355
401
|
method: string;
|
|
356
402
|
path: string;
|
|
357
403
|
namespace: string;
|
|
404
|
+
/** Request headers and query, for rules that match on them. */
|
|
405
|
+
headers?: Headers;
|
|
406
|
+
query?: URLSearchParams;
|
|
407
|
+
/** The namespace clock, for `from` / `until`. Rules with a window are skipped without it. */
|
|
408
|
+
now?: number;
|
|
409
|
+
/** How to spend a delay for this request. Default: the registry's own sleep. */
|
|
410
|
+
wait?: (ms: number) => Promise<void>;
|
|
411
|
+
};
|
|
412
|
+
/** A stored rule and how often it was consulted. */
|
|
413
|
+
type FaultListing = FaultRule & {
|
|
414
|
+
/** Faults left before the rule retires. `null` when it has no `count`. */
|
|
415
|
+
remaining: number | null;
|
|
416
|
+
/** Times the rule faulted a request. */
|
|
417
|
+
hits: number;
|
|
418
|
+
/** Requests that matched the rule, faulted or not. */
|
|
419
|
+
seen: number;
|
|
420
|
+
};
|
|
421
|
+
/** A namespace's own rules, with their counters, in the order they are tried. */
|
|
422
|
+
type FaultSnapshot = {
|
|
423
|
+
/**
|
|
424
|
+
* `position` is how many `"*"` rules are tried before the rule, which is what its place
|
|
425
|
+
* in the order means to a request and holds in any process.
|
|
426
|
+
*/
|
|
427
|
+
rules: (FaultListing & {
|
|
428
|
+
position?: number;
|
|
429
|
+
})[];
|
|
430
|
+
/** How many `fault_<n>` ids the namespace has handed out. */
|
|
431
|
+
nextId?: number;
|
|
358
432
|
};
|
|
359
433
|
type FaultRegistry = {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
rules: (FaultRule & {
|
|
363
|
-
remaining: number | null;
|
|
364
|
-
hits: number;
|
|
365
|
-
position: number;
|
|
366
|
-
})[];
|
|
367
|
-
rngState: number;
|
|
368
|
-
};
|
|
434
|
+
snapshot(namespace: string): FaultSnapshot;
|
|
435
|
+
/** Add a rule, or replace the rule with the same id in the same namespace. */
|
|
369
436
|
add(rule: FaultRule): FaultRule;
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
})[];
|
|
382
|
-
rngState: number;
|
|
383
|
-
}): void;
|
|
437
|
+
/** The next unused `fault_<n>` id in `namespace`. */
|
|
438
|
+
nextId(namespace: string): string;
|
|
439
|
+
/** Every rule, or the rules a namespace's requests can hit: its own and the global ones. */
|
|
440
|
+
list(namespace?: string): FaultListing[];
|
|
441
|
+
get(id: string, namespace?: string): FaultListing | undefined;
|
|
442
|
+
/** Remove a rule by id: from `namespace` (its own, then a global one), or wherever it is. */
|
|
443
|
+
remove(id: string, namespace?: string): boolean;
|
|
444
|
+
/** Remove every rule, or one namespace's own rules. */
|
|
445
|
+
clear(namespace?: string): void;
|
|
446
|
+
/** Replace a namespace's own rules with a snapshot's, wherever the snapshot was taken. */
|
|
447
|
+
restore(namespace: string, state: FaultSnapshot): void;
|
|
384
448
|
/**
|
|
385
449
|
* Every fault this request should get, in rule order, stopping at the first that answers
|
|
386
450
|
* or drops (effect-only and delay-only rules let later rules match too). Consumes one of
|
|
387
451
|
* each matching rule's remaining uses.
|
|
388
452
|
*/
|
|
389
453
|
take(candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
454
|
+
/**
|
|
455
|
+
* Fire these rules at one request without storing them: no matching, no schedule, in order,
|
|
456
|
+
* stopping at the first that answers or drops. Jitter draws from the namespace's stream.
|
|
457
|
+
*/
|
|
458
|
+
fire(rules: readonly FaultRule[], candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* The admin controls every mock shares, as one document.
|
|
463
|
+
*
|
|
464
|
+
* The same shape is accepted in three places, and means the same thing in each:
|
|
465
|
+
*
|
|
466
|
+
* - at boot: `createRuntime({ adminControls })`, `serve --admin-controls`,
|
|
467
|
+
* `MOCKINGBIRD_ADMIN_CONTROLS`
|
|
468
|
+
* - over HTTP: `PUT /__admin/controls`
|
|
469
|
+
* - per request: the `x-mockingbird-*` headers in {@link CONTROL_HEADERS}
|
|
470
|
+
*
|
|
471
|
+
* Every control is deterministic: given the same seed, clock and requests, a mock answers
|
|
472
|
+
* the same bytes. Nothing here reads the wall clock or `Math.random`.
|
|
473
|
+
*/
|
|
474
|
+
/** Milliseconds, or a string like `"250ms"`, `"2s"`, `"15m"`, `"1h"`, `"3d"`. */
|
|
475
|
+
type Duration = number | string;
|
|
476
|
+
/** Epoch milliseconds, or an ISO-8601 string. */
|
|
477
|
+
type Instant = number | string;
|
|
478
|
+
type ClockControls = {
|
|
479
|
+
/** Move the clock to this instant. */
|
|
480
|
+
now?: Instant;
|
|
481
|
+
/** Stop time. A frozen clock moves only when told to, so timestamps replay exactly. */
|
|
482
|
+
frozen?: boolean;
|
|
483
|
+
/**
|
|
484
|
+
* Step the clock forward by this much before every vendor request. With a frozen clock
|
|
485
|
+
* each request still gets its own, reproducible timestamp.
|
|
486
|
+
*/
|
|
487
|
+
autoAdvance?: Duration;
|
|
488
|
+
};
|
|
489
|
+
/** How long a response takes: a fixed delay plus seeded jitter in `[0, jitter]`. */
|
|
490
|
+
type LatencyRuleInput = {
|
|
491
|
+
delay?: Duration;
|
|
492
|
+
jitter?: Duration;
|
|
493
|
+
};
|
|
494
|
+
type LatencyControls = LatencyRuleInput & {
|
|
495
|
+
/** Per-operation overrides, keyed by operationId. A bare duration is its `delay`. */
|
|
496
|
+
operations?: Record<string, Duration | LatencyRuleInput>;
|
|
497
|
+
};
|
|
498
|
+
/** A fault to add: a rule (the id is assigned when omitted), or a named preset with overrides. */
|
|
499
|
+
type FaultInput = (Omit<FaultRule, "id"> & {
|
|
500
|
+
id?: string;
|
|
501
|
+
}) | ({
|
|
502
|
+
preset: string;
|
|
503
|
+
} & Partial<FaultRule>);
|
|
504
|
+
/** Identifies a {@link SnapshotDocument}. */
|
|
505
|
+
declare const SNAPSHOT_FORMAT = "mockingbird.snapshot/v1";
|
|
506
|
+
/**
|
|
507
|
+
* A namespace, as portable JSON: what `GET /__admin/snapshots/:id` returns and what
|
|
508
|
+
* `PUT /__admin/snapshots/:id` and the boot `snapshot` control accept. Only `format` and
|
|
509
|
+
* `records` are required, so a hand-written seed file is a valid snapshot.
|
|
510
|
+
*/
|
|
511
|
+
type SnapshotDocument = {
|
|
512
|
+
format: typeof SNAPSHOT_FORMAT;
|
|
513
|
+
/** The service that wrote it. A snapshot is rejected by any other service. */
|
|
514
|
+
service?: string;
|
|
515
|
+
/**
|
|
516
|
+
* Stored rows. `seq` orders a collection; omitted, rows keep their listed order. `raw` is
|
|
517
|
+
* the stored text of a row that is not a plain record, and replaces `value` when present.
|
|
518
|
+
*/
|
|
519
|
+
records: {
|
|
520
|
+
collection: string;
|
|
521
|
+
id: string;
|
|
522
|
+
seq?: number;
|
|
523
|
+
value?: unknown;
|
|
524
|
+
raw?: string;
|
|
525
|
+
}[];
|
|
526
|
+
/** Id counters, so the next generated id continues where the snapshot left off. */
|
|
527
|
+
sequences?: {
|
|
528
|
+
name: string;
|
|
529
|
+
kind: string;
|
|
530
|
+
value: number;
|
|
531
|
+
}[];
|
|
532
|
+
clock?: {
|
|
533
|
+
now: number;
|
|
534
|
+
frozen: boolean;
|
|
535
|
+
autoAdvanceMs?: number;
|
|
536
|
+
};
|
|
537
|
+
seed?: number | string;
|
|
538
|
+
/** Positions of the seeded random streams. */
|
|
539
|
+
rng?: {
|
|
540
|
+
state: number;
|
|
541
|
+
faults?: number;
|
|
542
|
+
latency?: number;
|
|
543
|
+
};
|
|
544
|
+
faults?: unknown;
|
|
545
|
+
latency?: unknown;
|
|
546
|
+
virtualTime?: boolean;
|
|
547
|
+
};
|
|
548
|
+
/** Controls for one namespace. */
|
|
549
|
+
type NamespaceControls = {
|
|
550
|
+
/** Seeds every random choice: fault rates, jitter, and whatever the service invents. */
|
|
551
|
+
seed?: number | string;
|
|
552
|
+
clock?: ClockControls;
|
|
553
|
+
/**
|
|
554
|
+
* Spend injected waits (latency, fault delays, timeouts) on the mock clock instead of the
|
|
555
|
+
* wall clock: the request returns at once, the clock has moved, and the journal records
|
|
556
|
+
* the wait exactly. Default `false`: waits are real, so a client's own timeout can fire.
|
|
557
|
+
*/
|
|
558
|
+
virtualTime?: boolean;
|
|
559
|
+
/** Baseline response time for every vendor request. A bare duration is its `delay`. */
|
|
560
|
+
latency?: Duration | LatencyControls;
|
|
561
|
+
faults?: readonly FaultInput[];
|
|
562
|
+
/** Start from this state instead of the service's own seed data. */
|
|
563
|
+
snapshot?: SnapshotDocument;
|
|
564
|
+
};
|
|
565
|
+
/** {@link NamespaceControls} for every namespace, with per-namespace overrides. */
|
|
566
|
+
type MockControls = NamespaceControls & {
|
|
567
|
+
/** Vendor credential → namespace, for SDKs that cannot send a namespace header. */
|
|
568
|
+
credentials?: Record<string, string>;
|
|
569
|
+
/** Overrides for named namespaces. A key given here replaces the shared value. */
|
|
570
|
+
namespaces?: Record<string, NamespaceControls>;
|
|
571
|
+
};
|
|
572
|
+
/** A latency rule in milliseconds. */
|
|
573
|
+
type LatencyRule = {
|
|
574
|
+
delayMs: number;
|
|
575
|
+
jitterMs: number;
|
|
576
|
+
};
|
|
577
|
+
/** Baseline latency for a namespace, normalized. */
|
|
578
|
+
type LatencyState = LatencyRule & {
|
|
579
|
+
operations: Record<string, LatencyRule>;
|
|
580
|
+
};
|
|
581
|
+
/** What {@link controlHeaders} turns into request headers. */
|
|
582
|
+
type ControlHeaderInput = {
|
|
583
|
+
namespace?: string;
|
|
584
|
+
adminKey?: string;
|
|
585
|
+
branch?: string;
|
|
586
|
+
at?: string;
|
|
587
|
+
reset?: boolean;
|
|
588
|
+
restore?: string;
|
|
589
|
+
seed?: number | string;
|
|
590
|
+
time?: Instant | Date;
|
|
591
|
+
advance?: Duration;
|
|
592
|
+
virtualTime?: boolean;
|
|
593
|
+
delay?: Duration;
|
|
594
|
+
timeout?: Duration;
|
|
595
|
+
/** A status, `"drop"`, a preset name, or a fault rule. */
|
|
596
|
+
fault?: number | string | Record<string, unknown>;
|
|
597
|
+
snapshot?: string;
|
|
390
598
|
};
|
|
391
599
|
|
|
392
600
|
/**
|
|
@@ -426,6 +634,8 @@ type RequestLog = {
|
|
|
426
634
|
unmatched: boolean;
|
|
427
635
|
/** Set when a fault rule produced the response. */
|
|
428
636
|
faultId?: string;
|
|
637
|
+
/** Milliseconds of injected wait: latency, fault delays and timeouts. Absent when none. */
|
|
638
|
+
delayMs?: number;
|
|
429
639
|
/** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
|
|
430
640
|
ids?: Record<string, string>;
|
|
431
641
|
/** Set when the service created a resource the request referred to but that did not exist. */
|
|
@@ -471,6 +681,12 @@ type JournalQuery = {
|
|
|
471
681
|
/** Only this namespace. Omit for every namespace, oldest first across all of them. */
|
|
472
682
|
namespace?: string;
|
|
473
683
|
operationId?: string;
|
|
684
|
+
/** Only this HTTP method, case-insensitive. */
|
|
685
|
+
method?: string;
|
|
686
|
+
/** Only this exact path. */
|
|
687
|
+
path?: string;
|
|
688
|
+
/** Only requests this fault rule answered or shaped. */
|
|
689
|
+
faultId?: string;
|
|
474
690
|
status?: number;
|
|
475
691
|
/** Only entries at or after this instant (epoch ms). */
|
|
476
692
|
since?: number;
|
|
@@ -485,6 +701,50 @@ type Journal = {
|
|
|
485
701
|
clear(namespace?: string): void;
|
|
486
702
|
};
|
|
487
703
|
|
|
704
|
+
/**
|
|
705
|
+
* Baseline response time, per namespace: how long every vendor request takes before any
|
|
706
|
+
* fault is considered. Jitter draws from a stream the caller owns, one per namespace and
|
|
707
|
+
* separate from the fault stream, so adding latency never shifts which requests a `rate`
|
|
708
|
+
* fault hits.
|
|
709
|
+
*/
|
|
710
|
+
type LatencyRegistry = {
|
|
711
|
+
get(namespace: string): LatencyState;
|
|
712
|
+
set(namespace: string, state: LatencyState): LatencyState;
|
|
713
|
+
/** Remove one namespace's latency, or every namespace's. */
|
|
714
|
+
clear(namespace?: string): void;
|
|
715
|
+
/** Milliseconds this request waits. Draws jitter, so call it once per request. */
|
|
716
|
+
take(namespace: string, operationId: string | undefined): number;
|
|
717
|
+
};
|
|
718
|
+
|
|
719
|
+
/** Clock state as the admin API reports it. */
|
|
720
|
+
type ControlClock = ClockState & {
|
|
721
|
+
/** `now`, as ISO-8601. */
|
|
722
|
+
iso: string;
|
|
723
|
+
/** Milliseconds the clock steps before every vendor request. */
|
|
724
|
+
autoAdvanceMs: number;
|
|
725
|
+
};
|
|
726
|
+
/** One namespace's controls: the body of `GET /__admin/controls`. */
|
|
727
|
+
type ControlState = {
|
|
728
|
+
namespace: string;
|
|
729
|
+
seed: number | string;
|
|
730
|
+
clock: ControlClock;
|
|
731
|
+
virtualTime: boolean;
|
|
732
|
+
latency: LatencyState;
|
|
733
|
+
faults: FaultListing[];
|
|
734
|
+
};
|
|
735
|
+
|
|
736
|
+
/** What `GET /__admin/snapshots` lists for each snapshot. */
|
|
737
|
+
type SnapshotInfo = {
|
|
738
|
+
id: string;
|
|
739
|
+
namespace: string;
|
|
740
|
+
/** Stored rows in the snapshot. */
|
|
741
|
+
records: number;
|
|
742
|
+
/** The namespace clock when it was taken, epoch ms. */
|
|
743
|
+
at: number;
|
|
744
|
+
/** Whether `GET /snapshots/:id` can return it as a {@link SnapshotDocument}. */
|
|
745
|
+
portable: boolean;
|
|
746
|
+
};
|
|
747
|
+
|
|
488
748
|
/** Credential → namespace mapping behind `PUT /__admin/credentials`. */
|
|
489
749
|
type CredentialRegistry = {
|
|
490
750
|
set(credential: string, namespace: string): void;
|
|
@@ -639,7 +899,10 @@ type ServiceInstance = FetchAPI & {
|
|
|
639
899
|
};
|
|
640
900
|
type ServiceTimelineState = Readonly<{
|
|
641
901
|
snapshot: NamespaceSnapshot;
|
|
642
|
-
clock
|
|
902
|
+
/** `pinned`: the namespace's clock was frozen itself, not just following a frozen base. */
|
|
903
|
+
clock: Readonly<ClockState & {
|
|
904
|
+
pinned?: boolean;
|
|
905
|
+
}>;
|
|
643
906
|
rngState: number;
|
|
644
907
|
}>;
|
|
645
908
|
type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
|
|
@@ -652,14 +915,18 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
|
|
|
652
915
|
readonly sqlite: SqliteClient$1;
|
|
653
916
|
readonly clock: Clock;
|
|
654
917
|
readonly faults: FaultRegistry;
|
|
918
|
+
/** Baseline response time per namespace. */
|
|
919
|
+
readonly latency: LatencyRegistry;
|
|
655
920
|
readonly metrics: Metrics;
|
|
656
921
|
readonly journal: Journal;
|
|
657
922
|
readonly rng: Rng;
|
|
658
923
|
readonly credentials: CredentialRegistry;
|
|
659
924
|
/** The webhook hub, when the service has outbound webhooks. */
|
|
660
925
|
readonly webhooks: WebhookHub | undefined;
|
|
661
|
-
/**
|
|
662
|
-
|
|
926
|
+
/**
|
|
927
|
+
* A namespace's clock. Each follows the base clock, {@link ServiceRuntime.clock}, with an
|
|
928
|
+
* offset and a freeze of its own, so moving one never moves another.
|
|
929
|
+
*/
|
|
663
930
|
namespaceClock(namespace?: string): Clock;
|
|
664
931
|
namespaceOf(request: Request): string;
|
|
665
932
|
/** Opaque in-process checkpoint including records, controls and webhook history. */
|
|
@@ -671,8 +938,38 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
|
|
|
671
938
|
instance(namespace?: string): T;
|
|
672
939
|
/** Public names of every namespace created so far. */
|
|
673
940
|
namespaces(): string[];
|
|
674
|
-
/**
|
|
941
|
+
/** Return one namespace to its boot state, or every namespace with `"*"`. */
|
|
675
942
|
reset(namespace?: string): Promise<void>;
|
|
943
|
+
/** Reset a namespace and forget it, releasing everything it held. */
|
|
944
|
+
dropNamespace(namespace: string): Promise<void>;
|
|
945
|
+
/** A namespace's controls: seed, clock, virtual time, latency, faults and snapshots. */
|
|
946
|
+
controls(namespace?: string): ControlState & {
|
|
947
|
+
snapshots: SnapshotInfo[];
|
|
948
|
+
};
|
|
949
|
+
/** Apply a control document to a namespace. A given key replaces that control. */
|
|
950
|
+
configure(controls: NamespaceControls, namespace?: string): ControlState & {
|
|
951
|
+
snapshots: SnapshotInfo[];
|
|
952
|
+
};
|
|
953
|
+
/** Named snapshots of a namespace: records, clock, random streams, faults and latency. */
|
|
954
|
+
readonly snapshots: {
|
|
955
|
+
/** Capture the namespace now. Reusing a name replaces that snapshot. */
|
|
956
|
+
create(options?: {
|
|
957
|
+
name?: string;
|
|
958
|
+
namespace?: string;
|
|
959
|
+
}): SnapshotInfo;
|
|
960
|
+
list(namespace?: string): SnapshotInfo[];
|
|
961
|
+
/** The snapshot as portable JSON, to commit beside a suite or boot another mock from. */
|
|
962
|
+
export(id: string, namespace?: string): SnapshotDocument;
|
|
963
|
+
/** Store a document as a snapshot without restoring it. */
|
|
964
|
+
import(document: SnapshotDocument, options?: {
|
|
965
|
+
name?: string;
|
|
966
|
+
namespace?: string;
|
|
967
|
+
}): SnapshotInfo;
|
|
968
|
+
restore(id: string, namespace?: string): void;
|
|
969
|
+
delete(id: string, namespace?: string): boolean;
|
|
970
|
+
};
|
|
971
|
+
/** Request headers that carry controls, checked: spread them into a `fetch` or an SDK's defaults. */
|
|
972
|
+
headers(input: ControlHeaderInput): Record<string, string>;
|
|
676
973
|
snapshot(namespace?: string): NamespaceSnapshot;
|
|
677
974
|
restore(snapshot: NamespaceSnapshot, namespace?: string): void;
|
|
678
975
|
/** Capture the current branch. Mutating HTTP calls do this automatically. */
|
|
@@ -899,6 +1196,8 @@ type RuntimeOptions = {
|
|
|
899
1196
|
accountId?: string;
|
|
900
1197
|
adminPrefix?: string;
|
|
901
1198
|
adminKey?: string;
|
|
1199
|
+
/** Admin controls to boot with: clock, latency, faults, seed, a starting snapshot. */
|
|
1200
|
+
adminControls?: MockControls;
|
|
902
1201
|
onLog?: (entry: RequestLog) => void;
|
|
903
1202
|
};
|
|
904
1203
|
type Runtime = ServiceRuntime<ResourceGroupsAPI>;
|