@crvouga/mockingbird-service-posthog 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 +13 -4
- package/dist/chunk-CJW2IXDE.js +6085 -0
- package/dist/chunk-CJW2IXDE.js.map +7 -0
- package/dist/{chunk-I3QG7TBO.js → chunk-PVGI6M5H.js} +135 -24
- package/dist/chunk-PVGI6M5H.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-3R4Y742O.js +0 -4293
- package/dist/chunk-3R4Y742O.js.map +0 -7
- package/dist/chunk-I3QG7TBO.js.map +0 -7
package/dist/index.d.ts
CHANGED
|
@@ -285,7 +285,7 @@ type ClockState = {
|
|
|
285
285
|
now: number;
|
|
286
286
|
/** True while time does not advance on its own. */
|
|
287
287
|
frozen: boolean;
|
|
288
|
-
/** Milliseconds
|
|
288
|
+
/** Milliseconds a running clock adds to its underlying source. `0` while frozen. */
|
|
289
289
|
offsetMs: number;
|
|
290
290
|
};
|
|
291
291
|
type Clock = {
|
|
@@ -321,7 +321,10 @@ type Rng = {
|
|
|
321
321
|
state(): number;
|
|
322
322
|
/** Restore a state previously returned by {@link state}. */
|
|
323
323
|
setState(state: number): void;
|
|
324
|
-
seed
|
|
324
|
+
/** Restart the stream from a new seed. `reset` then returns to this seed. */
|
|
325
|
+
reseed(seed: number | string): void;
|
|
326
|
+
/** The seed the stream currently starts from. */
|
|
327
|
+
readonly seed: number;
|
|
325
328
|
};
|
|
326
329
|
|
|
327
330
|
/**
|
|
@@ -330,44 +333,83 @@ type Rng = {
|
|
|
330
333
|
* This is how a suite reaches the vendor's failure modes without the vendor: the
|
|
331
334
|
* quota error that only appears when a shared sandbox is full, the 429 that only
|
|
332
335
|
* appears under load, the 5xx that proves a retry path works.
|
|
336
|
+
*
|
|
337
|
+
* A rule has three parts. What it **matches** (`operationId`, `method`, `path`, …), **when**
|
|
338
|
+
* it fires among the matching requests (`after`, `every`, `count`, `rate`, `from`, `until`),
|
|
339
|
+
* and what it **does** (`status`, `delay`, `timeout`, `drop`, `truncate`, `effect`).
|
|
333
340
|
*/
|
|
334
341
|
type FaultRule = {
|
|
335
|
-
/** Stable id, so a suite can retire exactly the rule it added. */
|
|
342
|
+
/** Stable id, so a suite can retire exactly the rule it added. Unique within a namespace. */
|
|
336
343
|
id: string;
|
|
337
344
|
/** Fault only this operation. Omit to match every operation. */
|
|
338
345
|
operationId?: string;
|
|
339
346
|
/** Fault only this HTTP method, case-insensitive. Omit to match every method. */
|
|
340
347
|
method?: string;
|
|
348
|
+
/** Fault only this exact path. */
|
|
349
|
+
path?: string;
|
|
341
350
|
/** Fault only paths starting with this prefix. Omit to match every path. */
|
|
342
351
|
pathPrefix?: string;
|
|
352
|
+
/** Fault only paths matching this regular expression (JavaScript syntax, unanchored). */
|
|
353
|
+
pathPattern?: string;
|
|
354
|
+
/** Fault only requests carrying these headers. `"*"` matches any value. */
|
|
355
|
+
requestHeaders?: Record<string, string>;
|
|
356
|
+
/** Fault only requests carrying these query parameters. `"*"` matches any value. */
|
|
357
|
+
query?: Record<string, string>;
|
|
343
358
|
/**
|
|
344
359
|
* Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
|
|
345
360
|
* an in-process caller usually wants, and what a parallel worker usually does not:
|
|
346
361
|
* rules added through `POST /__admin/faults` default to the calling namespace.
|
|
347
362
|
*/
|
|
348
363
|
namespace?: string;
|
|
364
|
+
/** Let this many matching requests through first. */
|
|
365
|
+
after?: number;
|
|
366
|
+
/** Then fault only every nth matching request: `3` faults the 3rd, 6th, 9th. */
|
|
367
|
+
every?: number;
|
|
368
|
+
/** Retire the rule after this many faults. Omit to keep it until removed. */
|
|
369
|
+
count?: number;
|
|
370
|
+
/** Fault this fraction of the remaining requests, `0`–`1`, drawn from the seed. Default `1`. */
|
|
371
|
+
rate?: number;
|
|
372
|
+
/**
|
|
373
|
+
* Fault only from this instant on the namespace clock. A duration (`"5m"`) counts from the
|
|
374
|
+
* clock when the rule was added. Listed as epoch ms.
|
|
375
|
+
*/
|
|
376
|
+
from?: Instant | Duration;
|
|
377
|
+
/** Stop faulting at this instant on the namespace clock. A duration counts from when added. */
|
|
378
|
+
until?: Instant | Duration;
|
|
349
379
|
/**
|
|
350
|
-
* Status of the injected response. Omit for a rule that only delays
|
|
351
|
-
*
|
|
352
|
-
* the request then still reaches the service.
|
|
380
|
+
* Status of the injected response. Omit for a rule that only delays, times out, drops,
|
|
381
|
+
* truncates, or switches on an `effect`: the request then still reaches the service.
|
|
353
382
|
*/
|
|
354
383
|
status?: number;
|
|
355
384
|
/** Response body, serialized as JSON. A string is sent as-is. */
|
|
356
385
|
body?: unknown;
|
|
386
|
+
/** Response headers. */
|
|
357
387
|
headers?: Record<string, string>;
|
|
358
|
-
/**
|
|
359
|
-
|
|
360
|
-
/**
|
|
361
|
-
rate?: number;
|
|
362
|
-
/** Hold the response back this long, to exercise timeouts. */
|
|
388
|
+
/** Hold the response back this long. Listed as `delayMs`. */
|
|
389
|
+
delay?: Duration;
|
|
390
|
+
/** `delay`, in milliseconds. */
|
|
363
391
|
delayMs?: number;
|
|
364
392
|
/** Alias of `delayMs`. */
|
|
365
393
|
latencyMs?: number;
|
|
394
|
+
/** Extra seeded delay in `[0, jitter]`. Listed as `jitterMs`. */
|
|
395
|
+
jitter?: Duration;
|
|
396
|
+
jitterMs?: number;
|
|
397
|
+
/**
|
|
398
|
+
* Never answer: hold the request this long, then drop the connection. Listed as
|
|
399
|
+
* `timeoutMs`. With virtual time the wait is spent on the mock clock.
|
|
400
|
+
*/
|
|
401
|
+
timeout?: Duration;
|
|
402
|
+
timeoutMs?: number;
|
|
366
403
|
/**
|
|
367
404
|
* Drop the connection instead of answering: an in-process `fetch` rejects with a
|
|
368
405
|
* `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
|
|
369
406
|
*/
|
|
370
407
|
drop?: boolean;
|
|
408
|
+
/**
|
|
409
|
+
* Cut the response body off after this many bytes: the status and headers arrive, then
|
|
410
|
+
* the connection dies mid-body.
|
|
411
|
+
*/
|
|
412
|
+
truncate?: number;
|
|
371
413
|
/**
|
|
372
414
|
* A named service behaviour to switch on for the matching request instead of (or
|
|
373
415
|
* before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
|
|
@@ -376,8 +418,8 @@ type FaultRule = {
|
|
|
376
418
|
effect?: string;
|
|
377
419
|
/** Parameters for `effect`. */
|
|
378
420
|
params?: Record<string, unknown>;
|
|
379
|
-
/**
|
|
380
|
-
|
|
421
|
+
/** The preset this rule was expanded from, if any. */
|
|
422
|
+
fromPreset?: string;
|
|
381
423
|
};
|
|
382
424
|
/** A fault that fired for one request. */
|
|
383
425
|
type FaultHit = {
|
|
@@ -385,6 +427,10 @@ type FaultHit = {
|
|
|
385
427
|
/** The injected response; absent when the rule only delays, drops, or sets an effect. */
|
|
386
428
|
response?: Response;
|
|
387
429
|
drop?: boolean;
|
|
430
|
+
/** Set with `drop` when the rule held the request for its `timeout` first. */
|
|
431
|
+
timeout?: boolean;
|
|
432
|
+
/** Bytes of response body to let through before the connection dies. */
|
|
433
|
+
truncate?: number;
|
|
388
434
|
effect?: {
|
|
389
435
|
name: string;
|
|
390
436
|
params: Record<string, unknown>;
|
|
@@ -409,38 +455,200 @@ type FaultCandidate = {
|
|
|
409
455
|
method: string;
|
|
410
456
|
path: string;
|
|
411
457
|
namespace: string;
|
|
458
|
+
/** Request headers and query, for rules that match on them. */
|
|
459
|
+
headers?: Headers;
|
|
460
|
+
query?: URLSearchParams;
|
|
461
|
+
/** The namespace clock, for `from` / `until`. Rules with a window are skipped without it. */
|
|
462
|
+
now?: number;
|
|
463
|
+
/** How to spend a delay for this request. Default: the registry's own sleep. */
|
|
464
|
+
wait?: (ms: number) => Promise<void>;
|
|
465
|
+
};
|
|
466
|
+
/** A stored rule and how often it was consulted. */
|
|
467
|
+
type FaultListing = FaultRule & {
|
|
468
|
+
/** Faults left before the rule retires. `null` when it has no `count`. */
|
|
469
|
+
remaining: number | null;
|
|
470
|
+
/** Times the rule faulted a request. */
|
|
471
|
+
hits: number;
|
|
472
|
+
/** Requests that matched the rule, faulted or not. */
|
|
473
|
+
seen: number;
|
|
474
|
+
};
|
|
475
|
+
/** A namespace's own rules, with their counters, in the order they are tried. */
|
|
476
|
+
type FaultSnapshot = {
|
|
477
|
+
/**
|
|
478
|
+
* `position` is how many `"*"` rules are tried before the rule, which is what its place
|
|
479
|
+
* in the order means to a request and holds in any process.
|
|
480
|
+
*/
|
|
481
|
+
rules: (FaultListing & {
|
|
482
|
+
position?: number;
|
|
483
|
+
})[];
|
|
484
|
+
/** How many `fault_<n>` ids the namespace has handed out. */
|
|
485
|
+
nextId?: number;
|
|
412
486
|
};
|
|
413
487
|
type FaultRegistry = {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
rules: (FaultRule & {
|
|
417
|
-
remaining: number | null;
|
|
418
|
-
hits: number;
|
|
419
|
-
position: number;
|
|
420
|
-
})[];
|
|
421
|
-
rngState: number;
|
|
422
|
-
};
|
|
488
|
+
snapshot(namespace: string): FaultSnapshot;
|
|
489
|
+
/** Add a rule, or replace the rule with the same id in the same namespace. */
|
|
423
490
|
add(rule: FaultRule): FaultRule;
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
})[];
|
|
436
|
-
rngState: number;
|
|
437
|
-
}): void;
|
|
491
|
+
/** The next unused `fault_<n>` id in `namespace`. */
|
|
492
|
+
nextId(namespace: string): string;
|
|
493
|
+
/** Every rule, or the rules a namespace's requests can hit: its own and the global ones. */
|
|
494
|
+
list(namespace?: string): FaultListing[];
|
|
495
|
+
get(id: string, namespace?: string): FaultListing | undefined;
|
|
496
|
+
/** Remove a rule by id: from `namespace` (its own, then a global one), or wherever it is. */
|
|
497
|
+
remove(id: string, namespace?: string): boolean;
|
|
498
|
+
/** Remove every rule, or one namespace's own rules. */
|
|
499
|
+
clear(namespace?: string): void;
|
|
500
|
+
/** Replace a namespace's own rules with a snapshot's, wherever the snapshot was taken. */
|
|
501
|
+
restore(namespace: string, state: FaultSnapshot): void;
|
|
438
502
|
/**
|
|
439
503
|
* Every fault this request should get, in rule order, stopping at the first that answers
|
|
440
504
|
* or drops (effect-only and delay-only rules let later rules match too). Consumes one of
|
|
441
505
|
* each matching rule's remaining uses.
|
|
442
506
|
*/
|
|
443
507
|
take(candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
508
|
+
/**
|
|
509
|
+
* Fire these rules at one request without storing them: no matching, no schedule, in order,
|
|
510
|
+
* stopping at the first that answers or drops. Jitter draws from the namespace's stream.
|
|
511
|
+
*/
|
|
512
|
+
fire(rules: readonly FaultRule[], candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* The admin controls every mock shares, as one document.
|
|
517
|
+
*
|
|
518
|
+
* The same shape is accepted in three places, and means the same thing in each:
|
|
519
|
+
*
|
|
520
|
+
* - at boot: `createRuntime({ adminControls })`, `serve --admin-controls`,
|
|
521
|
+
* `MOCKINGBIRD_ADMIN_CONTROLS`
|
|
522
|
+
* - over HTTP: `PUT /__admin/controls`
|
|
523
|
+
* - per request: the `x-mockingbird-*` headers in {@link CONTROL_HEADERS}
|
|
524
|
+
*
|
|
525
|
+
* Every control is deterministic: given the same seed, clock and requests, a mock answers
|
|
526
|
+
* the same bytes. Nothing here reads the wall clock or `Math.random`.
|
|
527
|
+
*/
|
|
528
|
+
/** Milliseconds, or a string like `"250ms"`, `"2s"`, `"15m"`, `"1h"`, `"3d"`. */
|
|
529
|
+
type Duration = number | string;
|
|
530
|
+
/** Epoch milliseconds, or an ISO-8601 string. */
|
|
531
|
+
type Instant = number | string;
|
|
532
|
+
type ClockControls = {
|
|
533
|
+
/** Move the clock to this instant. */
|
|
534
|
+
now?: Instant;
|
|
535
|
+
/** Stop time. A frozen clock moves only when told to, so timestamps replay exactly. */
|
|
536
|
+
frozen?: boolean;
|
|
537
|
+
/**
|
|
538
|
+
* Step the clock forward by this much before every vendor request. With a frozen clock
|
|
539
|
+
* each request still gets its own, reproducible timestamp.
|
|
540
|
+
*/
|
|
541
|
+
autoAdvance?: Duration;
|
|
542
|
+
};
|
|
543
|
+
/** How long a response takes: a fixed delay plus seeded jitter in `[0, jitter]`. */
|
|
544
|
+
type LatencyRuleInput = {
|
|
545
|
+
delay?: Duration;
|
|
546
|
+
jitter?: Duration;
|
|
547
|
+
};
|
|
548
|
+
type LatencyControls = LatencyRuleInput & {
|
|
549
|
+
/** Per-operation overrides, keyed by operationId. A bare duration is its `delay`. */
|
|
550
|
+
operations?: Record<string, Duration | LatencyRuleInput>;
|
|
551
|
+
};
|
|
552
|
+
/** A fault to add: a rule (the id is assigned when omitted), or a named preset with overrides. */
|
|
553
|
+
type FaultInput = (Omit<FaultRule, "id"> & {
|
|
554
|
+
id?: string;
|
|
555
|
+
}) | ({
|
|
556
|
+
preset: string;
|
|
557
|
+
} & Partial<FaultRule>);
|
|
558
|
+
/** Identifies a {@link SnapshotDocument}. */
|
|
559
|
+
declare const SNAPSHOT_FORMAT = "mockingbird.snapshot/v1";
|
|
560
|
+
/**
|
|
561
|
+
* A namespace, as portable JSON: what `GET /__admin/snapshots/:id` returns and what
|
|
562
|
+
* `PUT /__admin/snapshots/:id` and the boot `snapshot` control accept. Only `format` and
|
|
563
|
+
* `records` are required, so a hand-written seed file is a valid snapshot.
|
|
564
|
+
*/
|
|
565
|
+
type SnapshotDocument = {
|
|
566
|
+
format: typeof SNAPSHOT_FORMAT;
|
|
567
|
+
/** The service that wrote it. A snapshot is rejected by any other service. */
|
|
568
|
+
service?: string;
|
|
569
|
+
/**
|
|
570
|
+
* Stored rows. `seq` orders a collection; omitted, rows keep their listed order. `raw` is
|
|
571
|
+
* the stored text of a row that is not a plain record, and replaces `value` when present.
|
|
572
|
+
*/
|
|
573
|
+
records: {
|
|
574
|
+
collection: string;
|
|
575
|
+
id: string;
|
|
576
|
+
seq?: number;
|
|
577
|
+
value?: unknown;
|
|
578
|
+
raw?: string;
|
|
579
|
+
}[];
|
|
580
|
+
/** Id counters, so the next generated id continues where the snapshot left off. */
|
|
581
|
+
sequences?: {
|
|
582
|
+
name: string;
|
|
583
|
+
kind: string;
|
|
584
|
+
value: number;
|
|
585
|
+
}[];
|
|
586
|
+
clock?: {
|
|
587
|
+
now: number;
|
|
588
|
+
frozen: boolean;
|
|
589
|
+
autoAdvanceMs?: number;
|
|
590
|
+
};
|
|
591
|
+
seed?: number | string;
|
|
592
|
+
/** Positions of the seeded random streams. */
|
|
593
|
+
rng?: {
|
|
594
|
+
state: number;
|
|
595
|
+
faults?: number;
|
|
596
|
+
latency?: number;
|
|
597
|
+
};
|
|
598
|
+
faults?: unknown;
|
|
599
|
+
latency?: unknown;
|
|
600
|
+
virtualTime?: boolean;
|
|
601
|
+
};
|
|
602
|
+
/** Controls for one namespace. */
|
|
603
|
+
type NamespaceControls = {
|
|
604
|
+
/** Seeds every random choice: fault rates, jitter, and whatever the service invents. */
|
|
605
|
+
seed?: number | string;
|
|
606
|
+
clock?: ClockControls;
|
|
607
|
+
/**
|
|
608
|
+
* Spend injected waits (latency, fault delays, timeouts) on the mock clock instead of the
|
|
609
|
+
* wall clock: the request returns at once, the clock has moved, and the journal records
|
|
610
|
+
* the wait exactly. Default `false`: waits are real, so a client's own timeout can fire.
|
|
611
|
+
*/
|
|
612
|
+
virtualTime?: boolean;
|
|
613
|
+
/** Baseline response time for every vendor request. A bare duration is its `delay`. */
|
|
614
|
+
latency?: Duration | LatencyControls;
|
|
615
|
+
faults?: readonly FaultInput[];
|
|
616
|
+
/** Start from this state instead of the service's own seed data. */
|
|
617
|
+
snapshot?: SnapshotDocument;
|
|
618
|
+
};
|
|
619
|
+
/** {@link NamespaceControls} for every namespace, with per-namespace overrides. */
|
|
620
|
+
type MockControls = NamespaceControls & {
|
|
621
|
+
/** Vendor credential → namespace, for SDKs that cannot send a namespace header. */
|
|
622
|
+
credentials?: Record<string, string>;
|
|
623
|
+
/** Overrides for named namespaces. A key given here replaces the shared value. */
|
|
624
|
+
namespaces?: Record<string, NamespaceControls>;
|
|
625
|
+
};
|
|
626
|
+
/** A latency rule in milliseconds. */
|
|
627
|
+
type LatencyRule = {
|
|
628
|
+
delayMs: number;
|
|
629
|
+
jitterMs: number;
|
|
630
|
+
};
|
|
631
|
+
/** Baseline latency for a namespace, normalized. */
|
|
632
|
+
type LatencyState = LatencyRule & {
|
|
633
|
+
operations: Record<string, LatencyRule>;
|
|
634
|
+
};
|
|
635
|
+
/** What {@link controlHeaders} turns into request headers. */
|
|
636
|
+
type ControlHeaderInput = {
|
|
637
|
+
namespace?: string;
|
|
638
|
+
adminKey?: string;
|
|
639
|
+
branch?: string;
|
|
640
|
+
at?: string;
|
|
641
|
+
reset?: boolean;
|
|
642
|
+
restore?: string;
|
|
643
|
+
seed?: number | string;
|
|
644
|
+
time?: Instant | Date;
|
|
645
|
+
advance?: Duration;
|
|
646
|
+
virtualTime?: boolean;
|
|
647
|
+
delay?: Duration;
|
|
648
|
+
timeout?: Duration;
|
|
649
|
+
/** A status, `"drop"`, a preset name, or a fault rule. */
|
|
650
|
+
fault?: number | string | Record<string, unknown>;
|
|
651
|
+
snapshot?: string;
|
|
444
652
|
};
|
|
445
653
|
|
|
446
654
|
/**
|
|
@@ -480,6 +688,8 @@ type RequestLog = {
|
|
|
480
688
|
unmatched: boolean;
|
|
481
689
|
/** Set when a fault rule produced the response. */
|
|
482
690
|
faultId?: string;
|
|
691
|
+
/** Milliseconds of injected wait: latency, fault delays and timeouts. Absent when none. */
|
|
692
|
+
delayMs?: number;
|
|
483
693
|
/** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
|
|
484
694
|
ids?: Record<string, string>;
|
|
485
695
|
/** Set when the service created a resource the request referred to but that did not exist. */
|
|
@@ -525,6 +735,12 @@ type JournalQuery = {
|
|
|
525
735
|
/** Only this namespace. Omit for every namespace, oldest first across all of them. */
|
|
526
736
|
namespace?: string;
|
|
527
737
|
operationId?: string;
|
|
738
|
+
/** Only this HTTP method, case-insensitive. */
|
|
739
|
+
method?: string;
|
|
740
|
+
/** Only this exact path. */
|
|
741
|
+
path?: string;
|
|
742
|
+
/** Only requests this fault rule answered or shaped. */
|
|
743
|
+
faultId?: string;
|
|
528
744
|
status?: number;
|
|
529
745
|
/** Only entries at or after this instant (epoch ms). */
|
|
530
746
|
since?: number;
|
|
@@ -539,6 +755,50 @@ type Journal = {
|
|
|
539
755
|
clear(namespace?: string): void;
|
|
540
756
|
};
|
|
541
757
|
|
|
758
|
+
/**
|
|
759
|
+
* Baseline response time, per namespace: how long every vendor request takes before any
|
|
760
|
+
* fault is considered. Jitter draws from a stream the caller owns, one per namespace and
|
|
761
|
+
* separate from the fault stream, so adding latency never shifts which requests a `rate`
|
|
762
|
+
* fault hits.
|
|
763
|
+
*/
|
|
764
|
+
type LatencyRegistry = {
|
|
765
|
+
get(namespace: string): LatencyState;
|
|
766
|
+
set(namespace: string, state: LatencyState): LatencyState;
|
|
767
|
+
/** Remove one namespace's latency, or every namespace's. */
|
|
768
|
+
clear(namespace?: string): void;
|
|
769
|
+
/** Milliseconds this request waits. Draws jitter, so call it once per request. */
|
|
770
|
+
take(namespace: string, operationId: string | undefined): number;
|
|
771
|
+
};
|
|
772
|
+
|
|
773
|
+
/** Clock state as the admin API reports it. */
|
|
774
|
+
type ControlClock = ClockState & {
|
|
775
|
+
/** `now`, as ISO-8601. */
|
|
776
|
+
iso: string;
|
|
777
|
+
/** Milliseconds the clock steps before every vendor request. */
|
|
778
|
+
autoAdvanceMs: number;
|
|
779
|
+
};
|
|
780
|
+
/** One namespace's controls: the body of `GET /__admin/controls`. */
|
|
781
|
+
type ControlState = {
|
|
782
|
+
namespace: string;
|
|
783
|
+
seed: number | string;
|
|
784
|
+
clock: ControlClock;
|
|
785
|
+
virtualTime: boolean;
|
|
786
|
+
latency: LatencyState;
|
|
787
|
+
faults: FaultListing[];
|
|
788
|
+
};
|
|
789
|
+
|
|
790
|
+
/** What `GET /__admin/snapshots` lists for each snapshot. */
|
|
791
|
+
type SnapshotInfo = {
|
|
792
|
+
id: string;
|
|
793
|
+
namespace: string;
|
|
794
|
+
/** Stored rows in the snapshot. */
|
|
795
|
+
records: number;
|
|
796
|
+
/** The namespace clock when it was taken, epoch ms. */
|
|
797
|
+
at: number;
|
|
798
|
+
/** Whether `GET /snapshots/:id` can return it as a {@link SnapshotDocument}. */
|
|
799
|
+
portable: boolean;
|
|
800
|
+
};
|
|
801
|
+
|
|
542
802
|
/** Credential → namespace mapping behind `PUT /__admin/credentials`. */
|
|
543
803
|
type CredentialRegistry = {
|
|
544
804
|
set(credential: string, namespace: string): void;
|
|
@@ -693,7 +953,10 @@ type ServiceInstance = FetchAPI & {
|
|
|
693
953
|
};
|
|
694
954
|
type ServiceTimelineState = Readonly<{
|
|
695
955
|
snapshot: NamespaceSnapshot;
|
|
696
|
-
clock
|
|
956
|
+
/** `pinned`: the namespace's clock was frozen itself, not just following a frozen base. */
|
|
957
|
+
clock: Readonly<ClockState & {
|
|
958
|
+
pinned?: boolean;
|
|
959
|
+
}>;
|
|
697
960
|
rngState: number;
|
|
698
961
|
}>;
|
|
699
962
|
type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
|
|
@@ -706,14 +969,18 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
|
|
|
706
969
|
readonly sqlite: SqliteClient$1;
|
|
707
970
|
readonly clock: Clock;
|
|
708
971
|
readonly faults: FaultRegistry;
|
|
972
|
+
/** Baseline response time per namespace. */
|
|
973
|
+
readonly latency: LatencyRegistry;
|
|
709
974
|
readonly metrics: Metrics;
|
|
710
975
|
readonly journal: Journal;
|
|
711
976
|
readonly rng: Rng;
|
|
712
977
|
readonly credentials: CredentialRegistry;
|
|
713
978
|
/** The webhook hub, when the service has outbound webhooks. */
|
|
714
979
|
readonly webhooks: WebhookHub | undefined;
|
|
715
|
-
/**
|
|
716
|
-
|
|
980
|
+
/**
|
|
981
|
+
* A namespace's clock. Each follows the base clock, {@link ServiceRuntime.clock}, with an
|
|
982
|
+
* offset and a freeze of its own, so moving one never moves another.
|
|
983
|
+
*/
|
|
717
984
|
namespaceClock(namespace?: string): Clock;
|
|
718
985
|
namespaceOf(request: Request): string;
|
|
719
986
|
/** Opaque in-process checkpoint including records, controls and webhook history. */
|
|
@@ -725,8 +992,38 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
|
|
|
725
992
|
instance(namespace?: string): T;
|
|
726
993
|
/** Public names of every namespace created so far. */
|
|
727
994
|
namespaces(): string[];
|
|
728
|
-
/**
|
|
995
|
+
/** Return one namespace to its boot state, or every namespace with `"*"`. */
|
|
729
996
|
reset(namespace?: string): Promise<void>;
|
|
997
|
+
/** Reset a namespace and forget it, releasing everything it held. */
|
|
998
|
+
dropNamespace(namespace: string): Promise<void>;
|
|
999
|
+
/** A namespace's controls: seed, clock, virtual time, latency, faults and snapshots. */
|
|
1000
|
+
controls(namespace?: string): ControlState & {
|
|
1001
|
+
snapshots: SnapshotInfo[];
|
|
1002
|
+
};
|
|
1003
|
+
/** Apply a control document to a namespace. A given key replaces that control. */
|
|
1004
|
+
configure(controls: NamespaceControls, namespace?: string): ControlState & {
|
|
1005
|
+
snapshots: SnapshotInfo[];
|
|
1006
|
+
};
|
|
1007
|
+
/** Named snapshots of a namespace: records, clock, random streams, faults and latency. */
|
|
1008
|
+
readonly snapshots: {
|
|
1009
|
+
/** Capture the namespace now. Reusing a name replaces that snapshot. */
|
|
1010
|
+
create(options?: {
|
|
1011
|
+
name?: string;
|
|
1012
|
+
namespace?: string;
|
|
1013
|
+
}): SnapshotInfo;
|
|
1014
|
+
list(namespace?: string): SnapshotInfo[];
|
|
1015
|
+
/** The snapshot as portable JSON, to commit beside a suite or boot another mock from. */
|
|
1016
|
+
export(id: string, namespace?: string): SnapshotDocument;
|
|
1017
|
+
/** Store a document as a snapshot without restoring it. */
|
|
1018
|
+
import(document: SnapshotDocument, options?: {
|
|
1019
|
+
name?: string;
|
|
1020
|
+
namespace?: string;
|
|
1021
|
+
}): SnapshotInfo;
|
|
1022
|
+
restore(id: string, namespace?: string): void;
|
|
1023
|
+
delete(id: string, namespace?: string): boolean;
|
|
1024
|
+
};
|
|
1025
|
+
/** Request headers that carry controls, checked: spread them into a `fetch` or an SDK's defaults. */
|
|
1026
|
+
headers(input: ControlHeaderInput): Record<string, string>;
|
|
730
1027
|
snapshot(namespace?: string): NamespaceSnapshot;
|
|
731
1028
|
restore(snapshot: NamespaceSnapshot, namespace?: string): void;
|
|
732
1029
|
/** Capture the current branch. Mutating HTTP calls do this automatically. */
|
|
@@ -1082,6 +1379,8 @@ type PostHogRuntimeOptions = {
|
|
|
1082
1379
|
seed?: number | string;
|
|
1083
1380
|
adminPrefix?: string;
|
|
1084
1381
|
adminKey?: string;
|
|
1382
|
+
/** Admin controls to boot with: clock, latency, faults, seed, a starting snapshot. */
|
|
1383
|
+
adminControls?: MockControls;
|
|
1085
1384
|
onLog?: (entry: RequestLog) => void;
|
|
1086
1385
|
/** Flags every namespace starts with (and returns to on reset). */
|
|
1087
1386
|
flags?: Record<string, FlagSpec>;
|