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