@crvouga/mockingbird-runtime 0.5.0 → 0.7.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.
@@ -0,0 +1,1631 @@
1
+ import { Hono } from 'hono';
2
+
3
+ type MountedAPI = FetchAPI & {
4
+ readonly prefix: string;
5
+ GET: FetchHandler;
6
+ POST: FetchHandler;
7
+ PUT: FetchHandler;
8
+ PATCH: FetchHandler;
9
+ DELETE: FetchHandler;
10
+ HEAD: FetchHandler;
11
+ OPTIONS: FetchHandler;
12
+ };
13
+
14
+ /** A stable identifier for a point in a {@link Timeline}. */
15
+ type CheckpointId = string;
16
+ /** An immutable node in a timeline's checkpoint DAG. */
17
+ type Checkpoint<T> = Readonly<{
18
+ id: CheckpointId;
19
+ branch: string;
20
+ parent: CheckpointId | null;
21
+ /** Logical time supplied by the timeline's injected clock. */
22
+ at: number;
23
+ value: T;
24
+ }>;
25
+ type TimelineOptions = {
26
+ /** Logical clock used to stamp checkpoints. Defaults to a deterministic counter. */
27
+ now?: () => number;
28
+ /** Maximum retained checkpoints. Branch heads are never collected. Default 1,000. */
29
+ maxCheckpoints?: number;
30
+ /** Customize deterministic checkpoint IDs. */
31
+ id?: (sequence: number) => CheckpointId;
32
+ };
33
+ type CommitOptions = {
34
+ branch?: string;
35
+ /** Parent checkpoint. Defaults to the selected branch's current head. */
36
+ parent?: CheckpointId | null;
37
+ };
38
+ type ForkOptions = {
39
+ /** Checkpoint to fork from. Defaults to the main branch's head. */
40
+ from?: CheckpointId;
41
+ };
42
+ /**
43
+ * Small, storage-agnostic checkpoint DAG shared by service runtimes. Its values may be immutable
44
+ * records, namespace images, or copy-on-write SQL engine snapshots.
45
+ *
46
+ * Values are retained by reference. Engines can therefore use persistent/COW snapshots while
47
+ * simpler services can use immutable values. IDs and GC order are deterministic, and all IO
48
+ * (the logical clock) is injected.
49
+ */
50
+ declare class Timeline<T> {
51
+ readonly maxCheckpoints: number;
52
+ private readonly now;
53
+ private readonly makeId;
54
+ private readonly nodes;
55
+ private readonly heads;
56
+ /** Unreferenced nodes in the exact order they became collectible. */
57
+ private readonly evictable;
58
+ /** Branch heads plus explicit retainers. Absent means zero. */
59
+ private readonly references;
60
+ private readonly explicitPins;
61
+ private sequence;
62
+ constructor(options?: TimelineOptions);
63
+ /** Capture a new immutable value and move `branch` to it. */
64
+ commit(value: T, options?: CommitOptions): Checkpoint<T>;
65
+ /** Create a branch pointer without copying its checkpoint value. */
66
+ fork(branch: string, options?: ForkOptions): Checkpoint<T> | undefined;
67
+ /** Move a branch pointer to an existing checkpoint. */
68
+ checkout(branch: string, id: CheckpointId): Checkpoint<T>;
69
+ get(id: CheckpointId): Checkpoint<T>;
70
+ head(branch?: string): Checkpoint<T> | undefined;
71
+ hasBranch(branch: string): boolean;
72
+ branches(): Readonly<Record<string, CheckpointId>>;
73
+ checkpoints(): readonly Checkpoint<T>[];
74
+ /** Number of retained checkpoints without allocating an array. */
75
+ get size(): number;
76
+ /** Pin a checkpoint independently of branch heads (used by compatibility snapshot handles). */
77
+ retain(id: CheckpointId): Checkpoint<T>;
78
+ /** Release one explicit pin. Branch heads remain pinned until moved or deleted. */
79
+ release(id: CheckpointId): boolean;
80
+ deleteBranch(branch: string): boolean;
81
+ /**
82
+ * Deterministically discard oldest unpinned checkpoints. Collection is O(number removed):
83
+ * commits never scan pinned nodes or the retained history. Parents are metadata rather than a
84
+ * storage dependency, so a retained node remains usable after pruning.
85
+ */
86
+ gc(max?: number): CheckpointId[];
87
+ private collect;
88
+ private moveHead;
89
+ private addReference;
90
+ private removeReference;
91
+ private assertBranch;
92
+ }
93
+
94
+ /**
95
+ * Anything that can answer a Fetch `Request` with a `Response`.
96
+ *
97
+ * Every Mockingbird service implements this, and every runtime adapter consumes it.
98
+ * It is the only contract shared across the whole graph.
99
+ */
100
+ interface FetchAPI {
101
+ fetch(request: Request): Promise<Response>;
102
+ }
103
+ /** A bare function form of {@link FetchAPI}, compatible with `Bun.serve`, workerd, and Deno. */
104
+ type FetchHandler = (request: Request) => Promise<Response>;
105
+
106
+ /**
107
+ * The single source of time for a service.
108
+ *
109
+ * Every timestamp a mock writes reads from here, so a suite moves time instead of
110
+ * sleeping: appointment windows, result delays and expiries become reachable in
111
+ * milliseconds. A frozen clock also makes timestamps reproducible from a seed.
112
+ */
113
+ type ClockState = {
114
+ /** Current epoch milliseconds. */
115
+ now: number;
116
+ /** True while time does not advance on its own. */
117
+ frozen: boolean;
118
+ /** Milliseconds a running clock adds to its underlying source. `0` while frozen. */
119
+ offsetMs: number;
120
+ };
121
+ type Clock = {
122
+ now(): number;
123
+ /** Pin the clock to an exact instant, keeping it frozen if it already was. */
124
+ set(epochMs: number): void;
125
+ /** Move the clock forward, or back with a negative delta. */
126
+ advance(deltaMs: number): void;
127
+ /** Stop time at the current instant. */
128
+ freeze(): void;
129
+ /** Resume from the current instant. */
130
+ unfreeze(): void;
131
+ /** Drop back to the underlying source, live. */
132
+ reset(): void;
133
+ state(): ClockState;
134
+ };
135
+
136
+ type UpstreamState = {
137
+ mode: "emulated" | "forward";
138
+ baseUrl: string;
139
+ };
140
+ type UpstreamOptions = {
141
+ fetch: (request: Request) => Response | Promise<Response>;
142
+ baseUrl: string;
143
+ mode?: "emulated" | "forward";
144
+ rewriteAuth?: (request: Request) => Request | Promise<Request>;
145
+ };
146
+
147
+ /** An admission quota applied on the namespace clock. */
148
+ type FaultLimit = {
149
+ requests: number;
150
+ per: Duration;
151
+ key?: "namespace" | "credential";
152
+ window?: "fixed" | "sliding";
153
+ };
154
+ type LimitState = {
155
+ used: number;
156
+ windowStart: number | null;
157
+ windowResetsAt: number | null;
158
+ };
159
+ type LimitBucket = {
160
+ start: number;
161
+ used: number;
162
+ } | {
163
+ arrivals: number[];
164
+ };
165
+
166
+ /**
167
+ * Seeded pseudo-random numbers, so anything a mock invents — ids, jitter, which
168
+ * request a percentage fault hits — is reproducible from a seed.
169
+ *
170
+ * mulberry32: small, fast, and stable across runtimes, which matters more here
171
+ * than statistical quality.
172
+ */
173
+ type Rng = {
174
+ /** Next value in `[0, 1)`. */
175
+ next(): number;
176
+ /** Next integer in `[min, max]`. */
177
+ int(min: number, max: number): number;
178
+ /** Restart the stream from its seed. */
179
+ reset(): void;
180
+ /** Serializable engine state used by deterministic checkpoints. */
181
+ state(): number;
182
+ /** Restore a state previously returned by {@link state}. */
183
+ setState(state: number): void;
184
+ /** Restart the stream from a new seed. `reset` then returns to this seed. */
185
+ reseed(seed: number | string): void;
186
+ /** The seed the stream currently starts from. */
187
+ readonly seed: number;
188
+ };
189
+
190
+ /**
191
+ * A deliberate failure injected in front of an operation.
192
+ *
193
+ * This is how a suite reaches the vendor's failure modes without the vendor: the
194
+ * quota error that only appears when a shared sandbox is full, the 429 that only
195
+ * appears under load, the 5xx that proves a retry path works.
196
+ *
197
+ * A rule has three parts. What it **matches** (`operationId`, `method`, `path`, …), **when**
198
+ * it fires among the matching requests (`after`, `every`, `count`, `rate`, `from`, `until`),
199
+ * and what it **does** (`status`, `delay`, `timeout`, `drop`, `truncate`, `effect`).
200
+ */
201
+ type FaultRule = {
202
+ /** Stable id, so a suite can retire exactly the rule it added. Unique within a namespace. */
203
+ id: string;
204
+ /** Fault only this operation. Omit to match every operation. */
205
+ operationId?: string;
206
+ /** Fault only this HTTP method, case-insensitive. Omit to match every method. */
207
+ method?: string;
208
+ /** Fault only this exact path. */
209
+ path?: string;
210
+ /** Fault only paths starting with this prefix. Omit to match every path. */
211
+ pathPrefix?: string;
212
+ /** Fault only paths matching this regular expression (JavaScript syntax, unanchored). */
213
+ pathPattern?: string;
214
+ /** Fault only requests carrying these headers. `"*"` matches any value. */
215
+ requestHeaders?: Record<string, string>;
216
+ /** Fault only requests carrying these query parameters. `"*"` matches any value. */
217
+ query?: Record<string, string>;
218
+ /**
219
+ * Fault only requests whose JSON body carries these fields. Each key is a dotted path into
220
+ * the parsed body (`"patient_details.email"`; a number steps into an array, `"items.0.sku"`)
221
+ * and each value is what the field must equal: a string, number, boolean or `null`, compared
222
+ * strictly (`3` is not `"3"`). `"*"` matches any value that is present. A request whose body
223
+ * is missing, is not JSON, or is not a JSON object never matches. Not `body`, which is the
224
+ * response a rule injects.
225
+ */
226
+ requestBody?: Record<string, RequestBodyValue>;
227
+ /**
228
+ * Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
229
+ * an in-process caller usually wants, and what a parallel worker usually does not:
230
+ * rules added through `POST /__admin/faults` default to the calling namespace.
231
+ */
232
+ namespace?: string;
233
+ /** Admit at most this many matching requests per window. */
234
+ limit?: FaultLimit;
235
+ /** Let this many matching requests through first. */
236
+ after?: number;
237
+ /** Then fault only every nth matching request: `3` faults the 3rd, 6th, 9th. */
238
+ every?: number;
239
+ /** Retire the rule after this many faults. Omit to keep it until removed. */
240
+ count?: number;
241
+ /** Fault this fraction of the remaining requests, `0`–`1`, drawn from the seed. Default `1`. */
242
+ rate?: number;
243
+ /**
244
+ * Fault only from this instant on the namespace clock. A duration (`"5m"`) counts from the
245
+ * clock when the rule was added. Listed as epoch ms.
246
+ */
247
+ from?: Instant | Duration;
248
+ /** Stop faulting at this instant on the namespace clock. A duration counts from when added. */
249
+ until?: Instant | Duration;
250
+ /**
251
+ * Status of the injected response. Omit for a rule that only delays, times out, drops,
252
+ * truncates, or switches on an `effect`: the request then still reaches the service.
253
+ */
254
+ status?: number;
255
+ /** Response body, serialized as JSON. A string is sent as-is. */
256
+ body?: unknown;
257
+ /** Response headers. */
258
+ headers?: Record<string, string>;
259
+ /** Hold the response back this long. Listed as `delayMs`. */
260
+ delay?: Duration;
261
+ /** `delay`, in milliseconds. */
262
+ delayMs?: number;
263
+ /** Alias of `delayMs`. */
264
+ latencyMs?: number;
265
+ /** Extra seeded delay in `[0, jitter]`. Listed as `jitterMs`. */
266
+ jitter?: Duration;
267
+ jitterMs?: number;
268
+ /**
269
+ * Never answer: hold the request this long, then drop the connection. Listed as
270
+ * `timeoutMs`. With virtual time the wait is spent on the mock clock.
271
+ */
272
+ timeout?: Duration;
273
+ timeoutMs?: number;
274
+ /**
275
+ * Drop the connection instead of answering: an in-process `fetch` rejects with a
276
+ * `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
277
+ */
278
+ drop?: boolean;
279
+ /**
280
+ * Cut the response body off after this many bytes: the status and headers arrive, then
281
+ * the connection dies mid-body.
282
+ */
283
+ truncate?: number;
284
+ /**
285
+ * A named service behaviour to switch on for the matching request instead of (or
286
+ * before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
287
+ * read it with `faultEffects(request)`.
288
+ */
289
+ effect?: string;
290
+ /** Parameters for `effect`. */
291
+ params?: Record<string, unknown>;
292
+ /** The preset this rule was expanded from, if any. */
293
+ fromPreset?: string;
294
+ };
295
+ /** What a field of the request body must equal in {@link FaultRule.requestBody}. */
296
+ type RequestBodyValue = string | number | boolean | null;
297
+ /** A fault that fired for one request. */
298
+ type FaultHit = {
299
+ id: string;
300
+ /** The injected response; absent when the rule only delays, drops, or sets an effect. */
301
+ response?: Response;
302
+ drop?: boolean;
303
+ /** Set with `drop` when the rule held the request for its `timeout` first. */
304
+ timeout?: boolean;
305
+ /** Bytes of response body to let through before the connection dies. */
306
+ truncate?: number;
307
+ effect?: {
308
+ name: string;
309
+ params: Record<string, unknown>;
310
+ };
311
+ };
312
+ /**
313
+ * A named, documented fault a suite switches on by name
314
+ * (`POST /__admin/faults {"preset": "rate_limited"}`): one or more rules, and optionally a
315
+ * webhook delivery fault.
316
+ */
317
+ type FaultPreset = {
318
+ description: string;
319
+ rules?: Omit<FaultRule, "id">[];
320
+ webhook?: {
321
+ mode: "duplicate" | "reorder" | "drop";
322
+ count?: number;
323
+ };
324
+ };
325
+ /** What a request looks like to the fault matcher. */
326
+ type FaultCandidate = {
327
+ operationId: string | undefined;
328
+ method: string;
329
+ path: string;
330
+ namespace: string;
331
+ /** Request headers and query, for rules that match on them. */
332
+ headers?: Headers;
333
+ query?: URLSearchParams;
334
+ /**
335
+ * The request body parsed as JSON, read only when a rule matches on `requestBody`. Resolve
336
+ * `undefined` for a body that is missing or not JSON. It must leave the request readable.
337
+ */
338
+ readJson?: () => Promise<unknown>;
339
+ /** The service-specific credential, if it has one. */
340
+ credential?: () => string | undefined;
341
+ /** The namespace clock, for `from` / `until`. Rules with a window are skipped without it. */
342
+ now?: number;
343
+ /** Read the clock again after asynchronous request matching. */
344
+ clockNow?: () => number;
345
+ /** How to spend a delay for this request. Default: the registry's own sleep. */
346
+ wait?: (ms: number) => Promise<void>;
347
+ };
348
+ /** A stored rule and how often it was consulted. */
349
+ type FaultListing = FaultRule & Partial<LimitState> & {
350
+ /** Faults left before the rule retires. `null` when it has no `count`. */
351
+ remaining: number | null;
352
+ /** Times the rule faulted a request. */
353
+ hits: number;
354
+ /** Requests that matched the rule, faulted or not. */
355
+ seen: number;
356
+ };
357
+ /** A namespace's own rules, with their counters, in the order they are tried. */
358
+ type FaultSnapshot = {
359
+ /**
360
+ * `position` is how many `"*"` rules are tried before the rule, which is what its place
361
+ * in the order means to a request and holds in any process.
362
+ */
363
+ rules: (FaultListing & {
364
+ position?: number;
365
+ limitBuckets?: [string, LimitBucket][];
366
+ })[];
367
+ /** How many `fault_<n>` ids the namespace has handed out. */
368
+ nextId?: number;
369
+ };
370
+ type FaultRegistry = {
371
+ snapshot(namespace: string): FaultSnapshot;
372
+ /** Add a rule, or replace the rule with the same id in the same namespace. */
373
+ add(rule: FaultRule): FaultRule;
374
+ /** The next unused `fault_<n>` id in `namespace`. */
375
+ nextId(namespace: string): string;
376
+ /** Every rule, or the rules a namespace's requests can hit: its own and the global ones. */
377
+ list(namespace?: string): FaultListing[];
378
+ get(id: string, namespace?: string): FaultListing | undefined;
379
+ /** Remove a rule by id: from `namespace` (its own, then a global one), or wherever it is. */
380
+ remove(id: string, namespace?: string): boolean;
381
+ /** Remove every rule, or one namespace's own rules. */
382
+ clear(namespace?: string): void;
383
+ /** Replace a namespace's own rules with a snapshot's, wherever the snapshot was taken. */
384
+ restore(namespace: string, state: FaultSnapshot): void;
385
+ /**
386
+ * Every fault this request should get, in rule order, stopping at the first that answers
387
+ * or drops (effect-only and delay-only rules let later rules match too). Consumes one of
388
+ * each matching rule's remaining uses.
389
+ */
390
+ take(candidate: FaultCandidate): Promise<FaultHit[]>;
391
+ /**
392
+ * Fire these rules at one request without storing them: no matching, no schedule, in order,
393
+ * stopping at the first that answers or drops. Jitter draws from the namespace's stream.
394
+ */
395
+ fire(rules: readonly FaultRule[], candidate: FaultCandidate): Promise<FaultHit[]>;
396
+ };
397
+
398
+ /**
399
+ * The admin controls every mock shares, as one document.
400
+ *
401
+ * The same shape is accepted in three places, and means the same thing in each:
402
+ *
403
+ * - at boot: `createRuntime({ adminControls })`, `serve --admin-controls`,
404
+ * `MOCKINGBIRD_ADMIN_CONTROLS`
405
+ * - over HTTP: `PUT /__admin/controls`
406
+ * - per request: the `x-mockingbird-*` headers in {@link CONTROL_HEADERS}
407
+ *
408
+ * Every control is deterministic: given the same seed, clock and requests, a mock answers
409
+ * the same bytes. Nothing here reads the wall clock or `Math.random`.
410
+ */
411
+ /** Milliseconds, or a string like `"250ms"`, `"2s"`, `"15m"`, `"1h"`, `"3d"`. */
412
+ type Duration = number | string;
413
+ /** Epoch milliseconds, or an ISO-8601 string. */
414
+ type Instant = number | string;
415
+ type ClockControls = {
416
+ /** Move the clock to this instant. */
417
+ now?: Instant;
418
+ /** Stop time. A frozen clock moves only when told to, so timestamps replay exactly. */
419
+ frozen?: boolean;
420
+ /**
421
+ * Step the clock forward by this much before every vendor request. With a frozen clock
422
+ * each request still gets its own, reproducible timestamp.
423
+ */
424
+ autoAdvance?: Duration;
425
+ };
426
+ /** How long a response takes: a fixed delay plus seeded jitter in `[0, jitter]`. */
427
+ type LatencyRuleInput = {
428
+ delay?: Duration;
429
+ jitter?: Duration;
430
+ };
431
+ type LatencyControls = LatencyRuleInput & {
432
+ /** Per-operation overrides, keyed by operationId. A bare duration is its `delay`. */
433
+ operations?: Record<string, Duration | LatencyRuleInput>;
434
+ };
435
+ /** A fault to add: a rule (the id is assigned when omitted), or a named preset with overrides. */
436
+ type FaultInput = (Omit<FaultRule, "id"> & {
437
+ id?: string;
438
+ }) | ({
439
+ preset: string;
440
+ } & Partial<FaultRule>);
441
+ /** Identifies a {@link SnapshotDocument}. */
442
+ declare const SNAPSHOT_FORMAT = "mockingbird.snapshot/v1";
443
+ /**
444
+ * A namespace, as portable JSON: what `GET /__admin/snapshots/:id` returns and what
445
+ * `PUT /__admin/snapshots/:id` and the boot `snapshot` control accept. Only `format` and
446
+ * `records` are required, so a hand-written seed file is a valid snapshot.
447
+ */
448
+ type SnapshotDocument = {
449
+ upstream?: UpstreamState;
450
+ format: typeof SNAPSHOT_FORMAT;
451
+ /** The service that wrote it. A snapshot is rejected by any other service. */
452
+ service?: string;
453
+ /**
454
+ * Stored rows. `seq` orders a collection; omitted, rows keep their listed order. `raw` is
455
+ * the stored text of a row that is not a plain record, and replaces `value` when present.
456
+ */
457
+ records: {
458
+ collection: string;
459
+ id: string;
460
+ seq?: number;
461
+ value?: unknown;
462
+ raw?: string;
463
+ }[];
464
+ /** Id counters, so the next generated id continues where the snapshot left off. */
465
+ sequences?: {
466
+ name: string;
467
+ kind: string;
468
+ value: number;
469
+ }[];
470
+ clock?: {
471
+ now: number;
472
+ frozen: boolean;
473
+ autoAdvanceMs?: number;
474
+ };
475
+ seed?: number | string;
476
+ /** Positions of the seeded random streams. */
477
+ rng?: {
478
+ state: number;
479
+ faults?: number;
480
+ latency?: number;
481
+ };
482
+ faults?: unknown;
483
+ latency?: unknown;
484
+ virtualTime?: boolean;
485
+ /** Quiescent webhook endpoints, delivery history and fault state. Contains private configuration. */
486
+ webhooks?: unknown;
487
+ };
488
+ /** Controls for one namespace. */
489
+ type NamespaceControls = {
490
+ /** Seeds every random choice: fault rates, jitter, and whatever the service invents. */
491
+ seed?: number | string;
492
+ clock?: ClockControls;
493
+ /**
494
+ * Spend injected waits (latency, fault delays, timeouts) on the mock clock instead of the
495
+ * wall clock: the request returns at once, the clock has moved, and the journal records
496
+ * the wait exactly. Default `false`: waits are real, so a client's own timeout can fire.
497
+ */
498
+ virtualTime?: boolean;
499
+ /** Baseline response time for every vendor request. A bare duration is its `delay`. */
500
+ latency?: Duration | LatencyControls;
501
+ faults?: readonly FaultInput[];
502
+ /** Start from this state instead of the service's own seed data. */
503
+ snapshot?: SnapshotDocument;
504
+ };
505
+ /** {@link NamespaceControls} for every namespace, with per-namespace overrides. */
506
+ type MockControls = NamespaceControls & {
507
+ /** Vendor credential → namespace, for SDKs that cannot send a namespace header. */
508
+ credentials?: Record<string, string>;
509
+ /** Overrides for named namespaces. A key given here replaces the shared value. */
510
+ namespaces?: Record<string, NamespaceControls>;
511
+ /**
512
+ * Record a time-travel checkpoint after every accepted write. Default true. The runtime's own
513
+ * `checkpointMutations` option wins over this.
514
+ */
515
+ checkpointMutations?: boolean;
516
+ };
517
+ /** A latency rule in milliseconds. */
518
+ type LatencyRule = {
519
+ delayMs: number;
520
+ jitterMs: number;
521
+ };
522
+ /** Baseline latency for a namespace, normalized. */
523
+ type LatencyState = LatencyRule & {
524
+ operations: Record<string, LatencyRule>;
525
+ };
526
+ /** What {@link controlHeaders} turns into request headers. */
527
+ type ControlHeaderInput = {
528
+ upstream?: "emulated" | "forward";
529
+ namespace?: string;
530
+ adminKey?: string;
531
+ branch?: string;
532
+ at?: string;
533
+ reset?: boolean;
534
+ restore?: string;
535
+ seed?: number | string;
536
+ time?: Instant | Date;
537
+ advance?: Duration;
538
+ virtualTime?: boolean;
539
+ delay?: Duration;
540
+ timeout?: Duration;
541
+ /** A status, `"drop"`, a preset name, or a fault rule. */
542
+ fault?: number | string | Record<string, unknown>;
543
+ snapshot?: string;
544
+ };
545
+
546
+ type DecodedBody = {
547
+ kind: "empty";
548
+ } | {
549
+ kind: "json";
550
+ value: unknown;
551
+ } | {
552
+ kind: "form";
553
+ value: Record<string, unknown>;
554
+ } | {
555
+ kind: "text";
556
+ value: string;
557
+ } | {
558
+ kind: "bytes";
559
+ value: Uint8Array;
560
+ } | {
561
+ kind: "invalid";
562
+ mediaType: string;
563
+ text: string;
564
+ error: string;
565
+ };
566
+
567
+ /**
568
+ * Rails/PHP/Stripe-style bracket notation for `application/x-www-form-urlencoded` bodies and
569
+ * query strings:
570
+ *
571
+ * address[city]=Paris -> { address: { city: "Paris" } }
572
+ * items[0][name]=a -> { items: [{ name: "a" }] }
573
+ * tags[]=x&tags[]=y -> { tags: ["x", "y"] }
574
+ * metadata[k]=v -> { metadata: { k: "v" } }
575
+ *
576
+ * Decoding yields only strings, arrays and plain objects — coercion is the caller's concern,
577
+ * exactly like a real HTTP server.
578
+ */
579
+ type FormValue = string | FormValue[] | {
580
+ [key: string]: FormValue;
581
+ };
582
+ type FormObject = {
583
+ [key: string]: FormValue;
584
+ };
585
+
586
+ /**
587
+ * The slice of OpenAPI 3.1 (and JSON Schema 2020-12) Mockingbird understands.
588
+ * Unknown keys (including `x-*` extensions) are preserved on every object.
589
+ */
590
+ type JsonPrimitive = string | number | boolean | null;
591
+ type JsonValue = JsonPrimitive | JsonValue[] | {
592
+ [key: string]: JsonValue;
593
+ };
594
+ type ReferenceObject = {
595
+ $ref: string;
596
+ description?: string;
597
+ summary?: string;
598
+ };
599
+ type SchemaType = "string" | "number" | "integer" | "boolean" | "object" | "array" | "null";
600
+ type SchemaObject = {
601
+ $ref?: string;
602
+ type?: SchemaType | SchemaType[];
603
+ title?: string;
604
+ description?: string;
605
+ format?: string;
606
+ enum?: JsonValue[];
607
+ const?: JsonValue;
608
+ default?: JsonValue;
609
+ example?: JsonValue;
610
+ examples?: JsonValue[];
611
+ nullable?: boolean;
612
+ deprecated?: boolean;
613
+ readOnly?: boolean;
614
+ writeOnly?: boolean;
615
+ minimum?: number;
616
+ maximum?: number;
617
+ exclusiveMinimum?: number;
618
+ exclusiveMaximum?: number;
619
+ multipleOf?: number;
620
+ minLength?: number;
621
+ maxLength?: number;
622
+ pattern?: string;
623
+ minItems?: number;
624
+ maxItems?: number;
625
+ uniqueItems?: boolean;
626
+ items?: SchemaObject;
627
+ prefixItems?: SchemaObject[];
628
+ minProperties?: number;
629
+ maxProperties?: number;
630
+ required?: string[];
631
+ properties?: Record<string, SchemaObject>;
632
+ additionalProperties?: boolean | SchemaObject;
633
+ propertyNames?: SchemaObject;
634
+ oneOf?: SchemaObject[];
635
+ anyOf?: SchemaObject[];
636
+ allOf?: SchemaObject[];
637
+ not?: SchemaObject;
638
+ discriminator?: {
639
+ propertyName: string;
640
+ mapping?: Record<string, string>;
641
+ };
642
+ [extension: `x-${string}`]: unknown;
643
+ };
644
+ type ParameterLocation = "path" | "query" | "header" | "cookie";
645
+ type ParameterObject = {
646
+ name: string;
647
+ in: ParameterLocation;
648
+ description?: string;
649
+ required?: boolean;
650
+ deprecated?: boolean;
651
+ style?: string;
652
+ explode?: boolean;
653
+ schema?: SchemaObject;
654
+ content?: Record<string, MediaTypeObject>;
655
+ example?: JsonValue;
656
+ [extension: `x-${string}`]: unknown;
657
+ };
658
+ type MediaTypeObject = {
659
+ schema?: SchemaObject;
660
+ example?: JsonValue;
661
+ examples?: Record<string, unknown>;
662
+ encoding?: Record<string, unknown>;
663
+ [extension: `x-${string}`]: unknown;
664
+ };
665
+ type RequestBodyObject = {
666
+ description?: string;
667
+ required?: boolean;
668
+ content: Record<string, MediaTypeObject>;
669
+ [extension: `x-${string}`]: unknown;
670
+ };
671
+ type HeaderObject = {
672
+ description?: string;
673
+ required?: boolean;
674
+ schema?: SchemaObject;
675
+ [extension: `x-${string}`]: unknown;
676
+ };
677
+ type ResponseObject = {
678
+ description: string;
679
+ headers?: Record<string, HeaderObject | ReferenceObject>;
680
+ content?: Record<string, MediaTypeObject>;
681
+ [extension: `x-${string}`]: unknown;
682
+ };
683
+ type ResponsesObject = Record<string, ResponseObject | ReferenceObject>;
684
+ type SecurityRequirementObject = Record<string, string[]>;
685
+ type OperationObject = {
686
+ operationId?: string;
687
+ summary?: string;
688
+ description?: string;
689
+ tags?: string[];
690
+ deprecated?: boolean;
691
+ parameters?: Array<ParameterObject | ReferenceObject>;
692
+ requestBody?: RequestBodyObject | ReferenceObject;
693
+ responses: ResponsesObject;
694
+ security?: SecurityRequirementObject[];
695
+ [extension: `x-${string}`]: unknown;
696
+ };
697
+ declare const HTTP_METHODS: readonly ["get", "put", "post", "delete", "options", "head", "patch", "trace"];
698
+ type HttpMethod = (typeof HTTP_METHODS)[number];
699
+ type PathItemObject = {
700
+ summary?: string;
701
+ description?: string;
702
+ parameters?: Array<ParameterObject | ReferenceObject>;
703
+ [extension: `x-${string}`]: unknown;
704
+ } & Partial<Record<HttpMethod, OperationObject>>;
705
+ type SecuritySchemeObject = {
706
+ type: "apiKey" | "http" | "oauth2" | "openIdConnect" | "mutualTLS";
707
+ description?: string;
708
+ name?: string;
709
+ in?: ParameterLocation;
710
+ scheme?: string;
711
+ bearerFormat?: string;
712
+ flows?: Record<string, unknown>;
713
+ openIdConnectUrl?: string;
714
+ [extension: `x-${string}`]: unknown;
715
+ };
716
+ type ComponentsObject = {
717
+ schemas?: Record<string, SchemaObject>;
718
+ responses?: Record<string, ResponseObject>;
719
+ parameters?: Record<string, ParameterObject>;
720
+ requestBodies?: Record<string, RequestBodyObject>;
721
+ headers?: Record<string, HeaderObject>;
722
+ securitySchemes?: Record<string, SecuritySchemeObject>;
723
+ [extension: `x-${string}`]: unknown;
724
+ };
725
+ type ServerObject = {
726
+ url: string;
727
+ description?: string;
728
+ variables?: Record<string, unknown>;
729
+ [extension: `x-${string}`]: unknown;
730
+ };
731
+ type InfoObject = {
732
+ title: string;
733
+ version: string;
734
+ description?: string;
735
+ [extension: `x-${string}`]: unknown;
736
+ };
737
+ type OpenAPIDocument = {
738
+ openapi: string;
739
+ info: InfoObject;
740
+ servers?: ServerObject[];
741
+ paths: Record<string, PathItemObject>;
742
+ components?: ComponentsObject;
743
+ security?: SecurityRequirementObject[];
744
+ tags?: Array<{
745
+ name: string;
746
+ description?: string;
747
+ }>;
748
+ [extension: `x-${string}`]: unknown;
749
+ };
750
+ /** One concrete HTTP operation discovered in a document. */
751
+ type Operation = {
752
+ operationId: string;
753
+ method: HttpMethod;
754
+ /** OpenAPI path template, e.g. `/v1/customers/{customer}`. */
755
+ path: string;
756
+ operation: OperationObject;
757
+ /** Path-level parameters merged with operation-level ones (operation wins), `$ref`s resolved. */
758
+ parameters: ParameterObject[];
759
+ requestBody: RequestBodyObject | undefined;
760
+ responses: Record<string, ResponseObject>;
761
+ };
762
+
763
+ /** Bind values accepted by Mockingbird's SQLite port (matches sqlite-mem / better-sqlite3). */
764
+ type SqliteValue = null | number | bigint | string | Uint8Array | boolean;
765
+ /** Mutation counters returned by {@link SqliteStatement.run}. */
766
+ type SqliteRunResult = {
767
+ changes: number;
768
+ lastInsertRowid: number | bigint;
769
+ };
770
+ /**
771
+ * Prepared statement bound to a {@link SqliteClient}.
772
+ *
773
+ * Pass bind values as rest arguments on each call (no sticky `bind()`).
774
+ */
775
+ interface SqliteStatement {
776
+ run(...params: SqliteValue[]): SqliteRunResult;
777
+ all<T = Record<string, unknown>>(...params: SqliteValue[]): T[];
778
+ get<T = Record<string, unknown>>(...params: SqliteValue[]): T | undefined;
779
+ }
780
+ /**
781
+ * Sync SQLite client port owned by Mockingbird.
782
+ *
783
+ * Duck-typed so `@crvouga/mockingbird-service-sqlite` `Database`, better-sqlite3, and wrapped
784
+ * `bun:sqlite` instances all work when they expose this surface.
785
+ */
786
+ interface SqliteClient {
787
+ exec(sql: string): void;
788
+ prepare(sql: string): SqliteStatement;
789
+ transaction<T>(fn: () => T): T;
790
+ }
791
+
792
+ type OperationContext = {
793
+ request: Request;
794
+ url: URL;
795
+ /** Path parameters. */
796
+ params: Record<string, string>;
797
+ /** Query string decoded with bracket notation (`created[gte]=1` -> `{ created: { gte: "1" } }`). */
798
+ query: FormObject;
799
+ body: DecodedBody;
800
+ /** Shared SQLite client for this service (already migrated). */
801
+ sqlite: SqliteClient;
802
+ /** Service namespace used for records / sequences. */
803
+ namespace: string;
804
+ operation: Operation;
805
+ /** The vendor contract the service was built from. */
806
+ document: OpenAPIDocument;
807
+ now: () => number;
808
+ };
809
+ type OperationHandler = (context: OperationContext) => Promise<Response> | Response;
810
+ type OperationHandlers = Record<string, OperationHandler>;
811
+ /** Identity helper that keeps handler maps type-checked against a fixed set of operation ids. */
812
+ declare const defineOperations: <Id extends string>(handlers: Record<Id, OperationHandler>) => Record<Id, OperationHandler>;
813
+ type ServiceOptions = {
814
+ document: OpenAPIDocument;
815
+ handlers: OperationHandlers;
816
+ sqlite: SqliteClient;
817
+ /** Namespace isolating this service's records and sequences. */
818
+ namespace: string;
819
+ now?: (() => number) | undefined;
820
+ /** Response for paths/methods outside the contract. */
821
+ notFound: (request: Request) => Response | Promise<Response>;
822
+ /** Response for operations declared but marked `supported: false`. Default: `notFound`. */
823
+ unsupported?: (request: Request, operation: Operation) => Response | Promise<Response>;
824
+ /** Convert handler exceptions into a provider-shaped response. */
825
+ onError: (error: unknown, request: Request) => Response | Promise<Response>;
826
+ /** Runs before every operation; return a Response to short-circuit (e.g. authentication). */
827
+ before?: (context: OperationContext) => Promise<Response | undefined> | Response | undefined;
828
+ };
829
+ type Service = FetchAPI & {
830
+ app: Hono;
831
+ sqlite: SqliteClient;
832
+ namespace: string;
833
+ /** Delete every record and sequence in the service namespace. */
834
+ reset(): Promise<void>;
835
+ };
836
+
837
+ /**
838
+ * One problem with a request body, at a dotted path (`patient.address.city`, `items.0.sku`).
839
+ * `kind` is `media_type` when the body is present but its media type is not one the operation
840
+ * accepts (a `415` on most vendors), `syntax` when it could not be decoded, `required` when
841
+ * the operation needs a body and none arrived, and `schema` for a contract violation.
842
+ */
843
+ type BodyIssue = {
844
+ path: string;
845
+ message: string;
846
+ kind?: "media_type" | "syntax" | "required" | "schema";
847
+ };
848
+ /**
849
+ * Validate the decoded body against the operation's `requestBody` schema in the vendor
850
+ * contract, for the media type the request sent (or `contentType` when it sent none that the
851
+ * contract lists). Returns `[]` when valid, or when the operation declares no such body.
852
+ * Services turn the issues into the vendor's own validation error shape; a `media_type`
853
+ * issue is a body the operation cannot read at all (see `unsupportedMediaType`).
854
+ */
855
+ declare const bodyIssues: (context: OperationContext, contentType?: string) => BodyIssue[];
856
+
857
+ /**
858
+ * What the mock received from a request it rejected, so a 4xx can be attributed after the
859
+ * fact (an empty body, a missing `content-type`, a schema violation) without logging the body.
860
+ */
861
+ type RejectedRequest = {
862
+ /** The raw `content-type` header, or `null` when the request sent none. */
863
+ contentType: string | null;
864
+ /** Bytes of body received from `content-length` (`0` for none), or `null` when the client sent no length (a streamed / chunked body). */
865
+ bodyBytes: number | null;
866
+ /** The raw `transfer-encoding` header (`chunked`), or `null`. */
867
+ transferEncoding: string | null;
868
+ };
869
+ /** One handled request, as the structured log sees it. */
870
+ type RequestLog = {
871
+ upstream?: boolean;
872
+ service: string;
873
+ namespace: string;
874
+ operationId: string | undefined;
875
+ method: string;
876
+ path: string;
877
+ status: number;
878
+ durationMs: number;
879
+ /** True when the path matched no operation in the contract. */
880
+ unmatched: boolean;
881
+ /** Set when a fault rule produced the response. */
882
+ faultId?: string;
883
+ /** Milliseconds of injected wait: latency, fault delays and timeouts. Absent when none. */
884
+ delayMs?: number;
885
+ /** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
886
+ ids?: Record<string, string>;
887
+ /** Set when the service created a resource the request referred to but that did not exist. */
888
+ adopted?: boolean;
889
+ /** Explicit durable acceptance, independent of response delivery. */
890
+ accepted?: boolean;
891
+ /** Checkpoint captured at explicit acceptance. */
892
+ checkpoint?: string;
893
+ /** Set on a rejection (status ≥ 400) the mock produced itself, never on a scripted fault. */
894
+ request?: RejectedRequest;
895
+ /** The validation issues behind a rejection, when the service found any. */
896
+ issues?: BodyIssue[];
897
+ };
898
+ type MetricsReport = {
899
+ requests: number;
900
+ /** Counts keyed `<operationId> <status>`. */
901
+ byOperation: Record<string, number>;
902
+ /**
903
+ * Paths that matched no operation, most frequent first.
904
+ *
905
+ * This is the early-warning signal: a consumer calling something the mock does
906
+ * not implement shows up here as a count, before it fails a suite as a 404.
907
+ */
908
+ unmatched: {
909
+ method: string;
910
+ path: string;
911
+ count: number;
912
+ }[];
913
+ faults: number;
914
+ totalDurationMs: number;
915
+ };
916
+ /** What a runtime holds across every namespace: the gauges a long-running mock is watched by. */
917
+ type ResourceReport = {
918
+ /** Namespaces that hold state now (`GET /__admin/namespaces`). */
919
+ namespaces: number;
920
+ /** Stored records, every collection and branch included. */
921
+ records: number;
922
+ /** Journal entries held (`GET /__admin/requests`). */
923
+ journalEntries: number;
924
+ /** Named snapshots held. */
925
+ snapshots: number;
926
+ /** Webhook deliveries waiting for an attempt or a retry. */
927
+ webhooksPending: number;
928
+ /** Heap in use, or `null` where the host cannot say. */
929
+ heapUsedBytes: number | null;
930
+ /** Namespaces forgotten for being idle since the runtime started. */
931
+ namespacesExpired: number;
932
+ /** Idle namespaces whose drop failed; each is retried on a later request. */
933
+ idleExpiryFailures: number;
934
+ /** Requests answered `507` for the record cap, their writes rolled back. */
935
+ recordLimitRefusals: number;
936
+ /** Snapshots refused for the snapshot cap. */
937
+ snapshotLimitRefusals: number;
938
+ };
939
+ type Metrics = {
940
+ record(entry: RequestLog): void;
941
+ report(namespace?: string): MetricsReport;
942
+ reset(namespace?: string): void;
943
+ };
944
+
945
+ /** One journal entry: a request log stamped with when (on the mock clock) it was handled. */
946
+ type JournalEntry = RequestLog & {
947
+ at: string;
948
+ };
949
+ type JournalQuery = {
950
+ /** Only this namespace. Omit for every namespace, oldest first across all of them. */
951
+ namespace?: string;
952
+ operationId?: string;
953
+ /** Only this HTTP method, case-insensitive. */
954
+ method?: string;
955
+ /** Only this exact path. */
956
+ path?: string;
957
+ /** Only requests this fault rule answered or shaped. */
958
+ faultId?: string;
959
+ status?: number;
960
+ /** Only entries at or after this instant (epoch ms). */
961
+ since?: number;
962
+ /** At most this many, the most recent kept. */
963
+ limit?: number;
964
+ };
965
+ type Journal = {
966
+ readonly size: number;
967
+ record(entry: JournalEntry): void;
968
+ list(query?: JournalQuery): JournalEntry[];
969
+ /** Entries held for one namespace, or for every namespace. */
970
+ count(namespace?: string): number;
971
+ /** Forget one namespace's entries, or every namespace's. */
972
+ clear(namespace?: string): void;
973
+ };
974
+
975
+ /**
976
+ * Baseline response time, per namespace: how long every vendor request takes before any
977
+ * fault is considered. Jitter draws from a stream the caller owns, one per namespace and
978
+ * separate from the fault stream, so adding latency never shifts which requests a `rate`
979
+ * fault hits.
980
+ */
981
+ type LatencyRegistry = {
982
+ get(namespace: string): LatencyState;
983
+ set(namespace: string, state: LatencyState): LatencyState;
984
+ /** Remove one namespace's latency, or every namespace's. */
985
+ clear(namespace?: string): void;
986
+ /** Milliseconds this request waits. Draws jitter, so call it once per request. */
987
+ take(namespace: string, operationId: string | undefined): number;
988
+ };
989
+
990
+ /** Clock state as the admin API reports it. */
991
+ type ControlClock = ClockState & {
992
+ /** `now`, as ISO-8601. */
993
+ iso: string;
994
+ /** Milliseconds the clock steps before every vendor request. */
995
+ autoAdvanceMs: number;
996
+ };
997
+ /** One namespace's controls: the body of `GET /__admin/controls`. */
998
+ type ControlState = {
999
+ namespace: string;
1000
+ seed: number | string;
1001
+ clock: ControlClock;
1002
+ virtualTime: boolean;
1003
+ latency: LatencyState;
1004
+ faults: FaultListing[];
1005
+ };
1006
+
1007
+ type AdminRequest = {
1008
+ request: Request;
1009
+ url: URL;
1010
+ /** `:param` segments of the matched route. */
1011
+ params: Record<string, string>;
1012
+ /** Namespace the request targets: `?namespace=`, then the header, then the default. */
1013
+ namespace: string;
1014
+ /** Parsed JSON body, or `undefined` when there is none. */
1015
+ body: unknown;
1016
+ };
1017
+ type AdminRoute = (request: AdminRequest) => Response | Promise<Response>;
1018
+ /**
1019
+ * Service-specific admin routes, keyed `METHOD /path` relative to `/__admin`, with
1020
+ * `:param` segments — e.g. `"POST /orders/:id/transition"`.
1021
+ */
1022
+ type AdminRoutes = Record<string, AdminRoute>;
1023
+ /** What `GET /__admin/snapshots` lists for each snapshot. */
1024
+ type SnapshotInfo = {
1025
+ id: string;
1026
+ namespace: string;
1027
+ /** Stored rows in the snapshot. */
1028
+ records: number;
1029
+ /** The namespace clock when it was taken, epoch ms. */
1030
+ at: number;
1031
+ /** Whether `GET /snapshots/:id` can return it as a {@link SnapshotDocument}. */
1032
+ portable: boolean;
1033
+ };
1034
+
1035
+ /** Credential → namespace mapping behind `PUT /__admin/credentials`. */
1036
+ type CredentialRegistry = {
1037
+ set(credential: string, namespace: string): void;
1038
+ get(credential: string): string | undefined;
1039
+ remove(credential: string): boolean;
1040
+ clear(): void;
1041
+ entries(): {
1042
+ credential: string;
1043
+ namespace: string;
1044
+ }[];
1045
+ };
1046
+
1047
+ /**
1048
+ * A point-in-time copy of everything a service namespace holds.
1049
+ *
1050
+ * All service state lives in the two core tables keyed by namespace, so a snapshot
1051
+ * is generic: any service gets per-test rollback without knowing its own schema.
1052
+ * Restoring is much cheaper than rebuilding a namespace from a corpus.
1053
+ */
1054
+ type NamespaceSnapshot = {
1055
+ namespace: string;
1056
+ records: {
1057
+ collection: string;
1058
+ id: string;
1059
+ seq: number;
1060
+ value: string;
1061
+ }[];
1062
+ sequences: {
1063
+ name: string;
1064
+ kind: string;
1065
+ value: number;
1066
+ }[];
1067
+ };
1068
+
1069
+ /** Every stored record carries a monotonically increasing sequence for stable ordering. */
1070
+ type Stored<T> = {
1071
+ seq: number;
1072
+ value: T;
1073
+ };
1074
+ type ListRecordsOptions<T> = {
1075
+ /** Keep only records passing the predicate. */
1076
+ where?: (value: T, seq: number) => boolean;
1077
+ /** Sort order; default newest first. */
1078
+ order?: "newest" | "oldest";
1079
+ };
1080
+ /**
1081
+ * A SQLite-backed table of JSON records addressed by id. Ordering is by insertion
1082
+ * sequence, never by id lexicographic order, so list semantics stay stable.
1083
+ */
1084
+ declare class Collection<T> {
1085
+ private readonly sqlite;
1086
+ /** Storage namespace. Admin introspection uses this to ignore another namespace's tables. */
1087
+ readonly namespace: string;
1088
+ /** Table name inside the namespace. Stable across resets of the rows themselves. */
1089
+ readonly collectionName: string;
1090
+ private readonly statements;
1091
+ private prepare;
1092
+ constructor(sqlite: SqliteClient,
1093
+ /** Storage namespace. Admin introspection uses this to ignore another namespace's tables. */
1094
+ namespace: string,
1095
+ /** Table name inside the namespace. Stable across resets of the rows themselves. */
1096
+ collectionName: string);
1097
+ /** Note the record's current row in every open rollback journal that has not seen it yet. */
1098
+ private journalRecord;
1099
+ private bumpCollectionSeq;
1100
+ nextSequence(): number;
1101
+ get(id: string): T | undefined;
1102
+ has(id: string): boolean;
1103
+ private assertRoom;
1104
+ /** Insert a new record, assigning it the next sequence number. */
1105
+ insert(id: string, value: T): Stored<T>;
1106
+ /** Replace an existing record's value, keeping its position. */
1107
+ update(id: string, value: T): Stored<T> | undefined;
1108
+ delete(id: string): boolean;
1109
+ /** How many records the collection holds, without reading them. */
1110
+ count(): number;
1111
+ list(options?: ListRecordsOptions<T>): Array<Stored<T> & {
1112
+ id: string;
1113
+ }>;
1114
+ }
1115
+
1116
+ declare const STATE_FIELD_KINDS: readonly ["string", "number", "boolean", "null", "object", "array", "unknown"];
1117
+ type StateFieldKind = (typeof STATE_FIELD_KINDS)[number];
1118
+ /** JSON-safe annotations a bespoke admin UI may read. The default UI shows them as text. */
1119
+ type StateMeta = Readonly<Record<string, string | number | boolean | null>>;
1120
+ type StateField = {
1121
+ name: string;
1122
+ kind: StateFieldKind;
1123
+ optional: boolean;
1124
+ description?: string;
1125
+ /** One level of nested object fields. */
1126
+ fields?: StateField[];
1127
+ meta?: StateMeta;
1128
+ };
1129
+ /**
1130
+ * What a service knows about a collection before any row exists.
1131
+ * Stored rows still appear, including fields this declaration does not mention.
1132
+ */
1133
+ type StateDeclaration = {
1134
+ name: string;
1135
+ label?: string;
1136
+ description?: string;
1137
+ fields?: readonly StateField[];
1138
+ meta?: StateMeta;
1139
+ };
1140
+ type StateCollectionView = {
1141
+ name: string;
1142
+ label: string;
1143
+ description?: string;
1144
+ count: number;
1145
+ /** `mixed` when a declaration and stored rows both contribute fields. */
1146
+ source: "declared" | "inferred" | "mixed";
1147
+ fields: StateField[];
1148
+ meta?: StateMeta;
1149
+ };
1150
+ /** The shape of one namespace, for an admin UI that has never seen the service before. */
1151
+ type StateView = {
1152
+ namespace: string;
1153
+ storageNamespace: string;
1154
+ collections: StateCollectionView[];
1155
+ };
1156
+
1157
+ /**
1158
+ * What every mock can be called with. A service may accept more fields — accounts,
1159
+ * catalogs, webhook endpoints — and those stay optional so `createRuntime()` and
1160
+ * `createRuntime({ seed, adminKey })` work everywhere.
1161
+ */
1162
+ type MockCreateOptions = {
1163
+ sqlite?: SqliteClient;
1164
+ clock?: Clock;
1165
+ seed?: number | string;
1166
+ /** All internal HTTP paths live below this prefix. Default /__admin. */
1167
+ adminPrefix?: string;
1168
+ adminKey?: string;
1169
+ /**
1170
+ * Admin controls to boot with: clock, latency, faults, seed, a starting snapshot, and
1171
+ * per-namespace overrides. `POST /__admin/reset` returns to exactly this.
1172
+ */
1173
+ adminControls?: MockControls;
1174
+ };
1175
+ /**
1176
+ * A contribution the admin shell mounts beside the shared views.
1177
+ * `panel` is author-owned markup. `sql` turns on the built-in table explorer
1178
+ * and query runner, which call `GET /sql/tables` and `POST /sql/query`.
1179
+ * `route` presents an admin action with the shell's prebuilt form and response view.
1180
+ */
1181
+ type AdminExtension = {
1182
+ kind: "route";
1183
+ id: string;
1184
+ title: string;
1185
+ description?: string;
1186
+ /** An existing admin route, including its method and any path parameters. */
1187
+ route: string;
1188
+ /** Initial JSON body shown in the request form. */
1189
+ body?: unknown;
1190
+ } | {
1191
+ kind: "panel";
1192
+ id: string;
1193
+ title: string;
1194
+ description?: string;
1195
+ html: string;
1196
+ script?: string;
1197
+ } | {
1198
+ kind: "sql";
1199
+ /** DOM id suffix. Default `sql`. */
1200
+ id?: string;
1201
+ title?: string;
1202
+ description?: string;
1203
+ };
1204
+ /** A panel the default admin shell mounts after the shared views. */
1205
+ type AdminPanel = {
1206
+ /** DOM id suffix. Lowercase letters, digits, and hyphens. */
1207
+ id: string;
1208
+ title: string;
1209
+ description?: string;
1210
+ /** Markup placed inside the panel body. The service author owns it. */
1211
+ html: string;
1212
+ /**
1213
+ * Function body called as `(root, api) => void` once the shell has loaded.
1214
+ * `root` is the panel body. `api` is `{ get, send, namespace }` against `/__admin`.
1215
+ */
1216
+ script?: string;
1217
+ };
1218
+ /**
1219
+ * How a service customizes the admin UI without leaving the shared shell.
1220
+ * `panels` add views. `render` replaces the document and can call `defaultHtml()`
1221
+ * to wrap the shared shell instead of discarding it.
1222
+ */
1223
+ type AdminUi = {
1224
+ panels?: readonly AdminPanel[];
1225
+ /** First-class shell contributions. `sql` mounts the shared database explorer. */
1226
+ extensions?: readonly AdminExtension[];
1227
+ render?: (input: {
1228
+ service: string;
1229
+ defaultHtml: () => string;
1230
+ }) => string;
1231
+ };
1232
+
1233
+ /** One service's vendor chip: what `GET <adminPrefix>/ui/brands.json` returns under its name. */
1234
+ type AdminBrand = {
1235
+ vendor: string;
1236
+ website: string;
1237
+ /** Vendor API reference, when there is one. */
1238
+ docs: string | null;
1239
+ /** The service's page on the docs site. A link only; the admin never fetches it. */
1240
+ guide: string;
1241
+ /** A `data:image/…;base64,` URI, so the chip loads nothing from the network; "" for none. */
1242
+ logo: string;
1243
+ color: string | null;
1244
+ description: string | null;
1245
+ };
1246
+
1247
+ /**
1248
+ * What names an id base: a non-negative safe integer (or its decimal string) or `"boot"`,
1249
+ * which derives the base from the wall clock when the runtime is created.
1250
+ */
1251
+ type IdBase = number | string;
1252
+ /**
1253
+ * Sequential id source persisted in SQLite. Ids are deterministic for a given
1254
+ * sequence history (`cus_` + 14 opaque chars), so reproductions stay stable.
1255
+ * A runtime's `idBase` is mixed in, so a different base reissues none of another's ids.
1256
+ */
1257
+ declare class IdSequence {
1258
+ private readonly sqlite;
1259
+ private readonly namespace;
1260
+ private readonly salt;
1261
+ constructor(sqlite: SqliteClient, namespace: string, salt?: string);
1262
+ next(prefix: string, length?: number): string;
1263
+ }
1264
+
1265
+ /** JSON response with a normalised content type. */
1266
+ declare const jsonRes: (status: number, body: unknown, headers?: Record<string, string>) => Response;
1267
+
1268
+ type OwnedTransport = (request: Request, namespace: string, send: typeof fetch) => Promise<Response>;
1269
+
1270
+ type WebhookEndpoint = {
1271
+ /** Stable id; generated when omitted. */
1272
+ id?: string;
1273
+ url: string;
1274
+ secret?: string;
1275
+ /** Event types to deliver; omit or include `"*"` for every type. */
1276
+ events?: string[];
1277
+ /** Deliver only messages whose tags include all of these (e.g. `{ account: "mso" }`). */
1278
+ tags?: Record<string, string>;
1279
+ /** The public URL the receiver verifies signatures against (Twilio), when it differs. */
1280
+ signUrl?: string;
1281
+ /** Disable automatic retry attempts for this endpoint. Explicit replay remains available. */
1282
+ retry?: false;
1283
+ headers?: Record<string, string>;
1284
+ };
1285
+ type WebhookMessage = {
1286
+ id: string;
1287
+ namespace: string;
1288
+ type: string;
1289
+ body: string;
1290
+ contentType: string;
1291
+ tags: Record<string, string>;
1292
+ headers?: Record<string, string>;
1293
+ /** Wall-clock ISO-8601 time of publication. */
1294
+ publishedAt: string;
1295
+ };
1296
+ type WebhookAttempt = {
1297
+ attempt: number;
1298
+ at: string;
1299
+ status: number | null;
1300
+ error: string | null;
1301
+ durationMs: number;
1302
+ /** Exact receiver response body, when one was returned. */
1303
+ responseBody?: string | null;
1304
+ };
1305
+ type WebhookDelivery = {
1306
+ id: string;
1307
+ messageId: string;
1308
+ namespace: string;
1309
+ type: string;
1310
+ endpointId: string;
1311
+ url: string;
1312
+ state: "pending" | "delivered" | "failed" | "dropped";
1313
+ attempts: WebhookAttempt[];
1314
+ };
1315
+ /** A delivery-level fault: what happens to the next `count` messages in a namespace. */
1316
+ type WebhookFault = {
1317
+ mode: "duplicate" | "reorder" | "drop";
1318
+ /** Messages affected; default 1. */
1319
+ count?: number;
1320
+ };
1321
+ type PublishInput = {
1322
+ namespace: string;
1323
+ type: string;
1324
+ /** Exact body; objects are JSON-encoded. */
1325
+ body: string | Record<string, unknown> | unknown[];
1326
+ /** Default `application/json`, or form-encoded when `form` is given. */
1327
+ contentType?: string;
1328
+ /** Form parameters, when the vendor posts `application/x-www-form-urlencoded`. */
1329
+ form?: Record<string, string>;
1330
+ tags?: Record<string, string>;
1331
+ /** Message-specific delivery headers, captured as part of durable message state. */
1332
+ headers?: Record<string, string>;
1333
+ /** Additional delivery endpoint for this message only. */
1334
+ endpoint?: WebhookEndpoint;
1335
+ /** Message id; generated when omitted. */
1336
+ id?: string;
1337
+ };
1338
+ type WebhookHub = {
1339
+ observeDeliveries(listener: (event: {
1340
+ namespace: string;
1341
+ state: string;
1342
+ deliveryId: string;
1343
+ }) => void): () => void;
1344
+ setTransportPolicy(policy: OwnedTransport): void;
1345
+ /** Deliveries waiting in one namespace, or in every namespace. */
1346
+ pending(namespace?: string): number;
1347
+ snapshot(namespace: string): unknown;
1348
+ exportSnapshot(handle: unknown): unknown;
1349
+ importSnapshot(namespace: string, document: unknown): unknown;
1350
+ restore(namespace: string, snapshot: unknown): void;
1351
+ publish(input: PublishInput): WebhookMessage;
1352
+ /** Replace a namespace's own endpoints (`PUT /__admin/webhook-endpoints`). */
1353
+ setEndpoints(namespace: string, endpoints: WebhookEndpoint[]): WebhookEndpoint[];
1354
+ /** The endpoints a namespace delivers to: its own, plus the global ones. */
1355
+ endpoints(namespace: string): WebhookEndpoint[];
1356
+ messages(namespace?: string): WebhookMessage[];
1357
+ deliveries(namespace?: string): WebhookDelivery[];
1358
+ replay(deliveryId: string): Promise<WebhookDelivery | undefined>;
1359
+ /** Run every pending retry (and release held reordered messages) now, and every retry those attempts schedule, until nothing is pending. */
1360
+ flush(): Promise<void>;
1361
+ /** Resolve once nothing is in flight. */
1362
+ idle(namespace?: string): Promise<void>;
1363
+ fault(namespace: string, fault: WebhookFault): void;
1364
+ clear(namespace?: string): void;
1365
+ };
1366
+
1367
+ /** What the runtime needs from a service: a Fetch handler it can reset. */
1368
+ type ServiceInstance = FetchAPI & {
1369
+ reset(): Promise<void>;
1370
+ };
1371
+ /** Everything an instance shares with the runtime that owns it. */
1372
+ type InstanceContext = {
1373
+ /** Storage namespace for this instance's records. */
1374
+ namespace: string;
1375
+ /** The public namespace name a request selects it by. */
1376
+ adminPrefix: string;
1377
+ publicNamespace: string;
1378
+ sqlite: SqliteClient;
1379
+ clock: Clock;
1380
+ rng: Rng;
1381
+ };
1382
+ type RuntimeOptions<T extends ServiceInstance> = {
1383
+ upstream?: UpstreamOptions;
1384
+ /** Capture an accepted real send without invoking an emulated handler. */
1385
+ onForwardResponse?: (instance: T, request: Request, response: Response) => Promise<void>;
1386
+ /** Reject unsupported forwarding surfaces before any network request. */
1387
+ canForward?: (request: Request) => boolean;
1388
+ upstreamRequest?: (request: Request, baseUrl: string) => Request;
1389
+ /** Return an emulated refusal before request fault rules are consumed. Read from a request clone. */
1390
+ beforeFaults?: (instance: T, request: Request) => Response | undefined | Promise<Response | undefined>;
1391
+ /** Service name, e.g. `"junction"`. Also the default namespace's storage key. */
1392
+ name: string;
1393
+ /** Build the instance backing one namespace. Called once per namespace, on first use. */
1394
+ create: (context: InstanceContext) => T;
1395
+ /** The vendor contract, used to name each request's operation in logs, metrics and faults. */
1396
+ document?: OpenAPIDocument;
1397
+ /** Shared by every namespace. Defaults to a fresh `@crvouga/mockingbird-service-sqlite`. */
1398
+ sqlite?: SqliteClient;
1399
+ /** Defaults to a live clock over `Date.now`. */
1400
+ clock?: Clock;
1401
+ /**
1402
+ * Where this boot's generated ids start. Counters restart at 0 on every boot, so by default
1403
+ * every boot reissues the previous boot's ids; a different base gives an unrelated run of ids
1404
+ * (a reset returns to the same run). A non-negative integer, or `"boot"` for one derived from
1405
+ * the wall clock when the runtime is created. Default `0`: the same ids on every boot.
1406
+ */
1407
+ idBase?: IdBase;
1408
+ /** Seeds every random choice the runtime makes (fault rates, jitter). Default `0`. */
1409
+ seed?: number | string;
1410
+ /**
1411
+ * Admin controls to boot with: clock, latency, faults, a starting snapshot, credential
1412
+ * mappings and per-namespace overrides. `reset` returns a namespace to exactly this.
1413
+ */
1414
+ adminControls?: MockControls;
1415
+ /** Extra `GET /__admin/health` fields, such as the loaded corpus version. */
1416
+ describe?: () => Record<string, unknown>;
1417
+ /** Service-specific admin routes, given the runtime so they can reach any namespace. */
1418
+ admin?: (runtime: ServiceRuntime<T>) => AdminRoutes;
1419
+ /** Reserved tree for every internal HTTP endpoint, UI and namespace carrier. Default /__admin. */
1420
+ adminPrefix?: string;
1421
+ /**
1422
+ * A namespace's clock was moved — by `/__admin/clock`, a header, a restore, a reset, or a
1423
+ * wait spent in virtual time. Run whatever the service schedules by that clock, so what
1424
+ * came due is seen at once and not on the next request. Moving the base clock in process
1425
+ * (`runtime.clock`) is the caller's own doing and is not reported here.
1426
+ */
1427
+ onClockChange?: (namespace: string) => void;
1428
+ /** Invalidate transient handles before replacing an existing instance's stored state. */
1429
+ beforeRestore?: (instance: T) => void;
1430
+ /** Require this value in `x-mockingbird-admin-key` on admin data routes. */
1431
+ adminKey?: string;
1432
+ /** Structured request log sink, called once per request. */
1433
+ onLog?: (entry: RequestLog) => void;
1434
+ /** Requests each namespace's journal keeps (`GET /__admin/requests`). Default 1000; 0 turns it off. */
1435
+ journalSize?: number;
1436
+ /** Reported in the `x-mockingbird` header. Default: the bundled package's version. */
1437
+ version?: string;
1438
+ /**
1439
+ * The vendor chip `GET <adminPrefix>/ui/brands.json` serves. Default: the brand bundled into
1440
+ * this build; a service built on the shared `@crvouga/mockingbird-runtime` passes its own
1441
+ * (scripts/bundle-service-runtime.ts).
1442
+ */
1443
+ adminBrand?: AdminBrand;
1444
+ /**
1445
+ * The vendor credential a request carries (API key, token, account SID, AWS access key
1446
+ * id), for SDKs that cannot send `x-mockingbird-namespace`: a suite maps credentials to
1447
+ * namespaces with `PUT /__admin/credentials`. See `bearerToken`, `basicAuth`,
1448
+ * `sigV4AccessKeyId`.
1449
+ */
1450
+ credential?: (request: Request) => string | undefined;
1451
+ /**
1452
+ * Named faults, switched on with `POST /__admin/faults {"preset": "<name>"}`. They join the
1453
+ * standard presets every mock has; one with a standard name replaces it.
1454
+ */
1455
+ presets?: Record<string, FaultPreset>;
1456
+ /** Outbound webhooks; adds the `/__admin/webhooks*` routes and clears on reset. */
1457
+ webhooks?: WebhookHub;
1458
+ /** Retained time-travel checkpoints per namespace. Default 1,000. */
1459
+ maxCheckpoints?: number;
1460
+ /**
1461
+ * Forget a namespace (as `DELETE /__admin/namespaces/<key>` does) once no request has named
1462
+ * it for this many wall-clock milliseconds. `default` is never forgotten, nor is a namespace
1463
+ * with a webhook delivery still waiting or a request still running. Default 0: namespaces are
1464
+ * kept until dropped.
1465
+ */
1466
+ namespaceIdleMs?: number;
1467
+ /**
1468
+ * Records each namespace may hold; a request that would store another answers `507` with
1469
+ * every write it made rolled back. The cap is this runtime's own: another service sharing the
1470
+ * SQLite database is not capped by it. Default: no cap.
1471
+ */
1472
+ maxRecords?: number;
1473
+ /** Named snapshots each namespace may hold; another is refused with `400`. Default: no cap. */
1474
+ maxSnapshots?: number;
1475
+ /**
1476
+ * Record a time-travel checkpoint after every accepted mutation and stamp its id in
1477
+ * `x-mockingbird-checkpoint`. Default true. Each checkpoint reads the whole namespace, so a
1478
+ * long-running mock that never travels back can turn this off to keep a write's cost its own;
1479
+ * `checkpoint`, `snapshot`, `branch` and `checkout` still capture when called. Wins over
1480
+ * `adminControls.checkpointMutations`, which a fleet entry can set for any service.
1481
+ */
1482
+ checkpointMutations?: boolean;
1483
+ /** Injectable process IO used for observability and delays; logical service time uses `clock`. */
1484
+ io?: Partial<RuntimeIO>;
1485
+ /**
1486
+ * Collections the admin UI should show even before any row exists.
1487
+ * Stored collections are always included, whether or not they are declared.
1488
+ * A function may describe collections that depend on the live instance.
1489
+ */
1490
+ state?: readonly StateDeclaration[] | ((api: T, namespace: string) => readonly StateDeclaration[]);
1491
+ /**
1492
+ * Panels added to the default admin UI, or a function that replaces the document.
1493
+ * `render` receives `defaultHtml()` so a bespoke UI can wrap the shared shell.
1494
+ */
1495
+ adminUi?: AdminUi;
1496
+ };
1497
+ type RuntimeIO = {
1498
+ wallNow(): number;
1499
+ monotonicNow(): number;
1500
+ /** Wait on the wall clock. Rejects with the signal's reason when it aborts first. */
1501
+ sleep(ms: number, signal?: AbortSignal): Promise<void>;
1502
+ /** Bytes of heap in use, for `GET /__admin/metrics`; `undefined` where the host cannot say. */
1503
+ heapUsedBytes(): number | undefined;
1504
+ };
1505
+ type ServiceTimelineState = Readonly<{
1506
+ snapshot: NamespaceSnapshot;
1507
+ /** `pinned`: the namespace's clock was frozen itself, not just following a frozen base. */
1508
+ clock: Readonly<ClockState & {
1509
+ pinned?: boolean;
1510
+ }>;
1511
+ rngState: number;
1512
+ }>;
1513
+ type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
1514
+ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
1515
+ /** Stop package-owned lifecycle timers when a supervisor closes the runtime. */
1516
+ stop?(): void;
1517
+ readonly name: string;
1518
+ /** Same-origin Fetch handler and App Router method exports, sharing this runtime. */
1519
+ mount(prefix: string): MountedAPI;
1520
+ readonly sqlite: SqliteClient;
1521
+ readonly clock: Clock;
1522
+ /**
1523
+ * Change the id base ({@link RuntimeOptions.idBase}) for ids generated from now on, and
1524
+ * return the number it resolved to. Set it before the first request so a boot's ids stay
1525
+ * one run.
1526
+ */
1527
+ setIdBase(base: IdBase): number;
1528
+ readonly faults: FaultRegistry;
1529
+ /** Baseline response time per namespace. */
1530
+ readonly latency: LatencyRegistry;
1531
+ readonly metrics: Metrics;
1532
+ readonly journal: Journal;
1533
+ readonly rng: Rng;
1534
+ readonly credentials: CredentialRegistry;
1535
+ /** The webhook hub, when the service has outbound webhooks. */
1536
+ readonly webhooks: WebhookHub | undefined;
1537
+ /**
1538
+ * A namespace's clock. Each follows the base clock, {@link ServiceRuntime.clock}, with an
1539
+ * offset and a freeze of its own, so moving one never moves another.
1540
+ */
1541
+ namespaceClock(namespace?: string): Clock;
1542
+ namespaceOf(request: Request): string;
1543
+ /** Opaque in-process checkpoint including records, controls and webhook history. */
1544
+ fleetSnapshot(namespace: string): object;
1545
+ fleetRestore(snapshot: unknown, namespace: string): void;
1546
+ fleetExport(snapshot: unknown): SnapshotDocument;
1547
+ fleetImport(namespace: string, document: unknown): object;
1548
+ /** Expand a named preset into fault rules (and webhook faults) for `namespace`. */
1549
+ applyPreset(name: string, namespace?: string, overrides?: Partial<FaultRule>): FaultRule[];
1550
+ /** The instance behind `namespace` (the default one when omitted), created on first use. */
1551
+ instance(namespace?: string): T;
1552
+ /** Public names of every namespace created so far. */
1553
+ namespaces(): string[];
1554
+ /** Return one namespace to its boot state, or every namespace with `"*"`. */
1555
+ reset(namespace?: string): Promise<void>;
1556
+ /** Reset a namespace and forget it, releasing everything it held. */
1557
+ dropNamespace(namespace: string): Promise<void>;
1558
+ /** What the runtime holds across every namespace, as `GET /__admin/metrics` reports it. */
1559
+ resources(): ResourceReport;
1560
+ /** A namespace's controls: seed, clock, virtual time, latency, faults and snapshots. */
1561
+ controls(namespace?: string): ControlState & {
1562
+ snapshots: SnapshotInfo[];
1563
+ };
1564
+ /** Apply a control document to a namespace. A given key replaces that control. */
1565
+ configure(controls: NamespaceControls, namespace?: string): ControlState & {
1566
+ snapshots: SnapshotInfo[];
1567
+ };
1568
+ /** Named snapshots of a namespace: records, clock, random streams, faults and latency. */
1569
+ readonly snapshots: {
1570
+ /** Capture the namespace now. Reusing a name replaces that snapshot. */
1571
+ create(options?: {
1572
+ name?: string;
1573
+ namespace?: string;
1574
+ }): SnapshotInfo;
1575
+ list(namespace?: string): SnapshotInfo[];
1576
+ /** The snapshot as portable JSON, to commit beside a suite or boot another mock from. */
1577
+ export(id: string, namespace?: string): SnapshotDocument;
1578
+ /** Store a document as a snapshot without restoring it. */
1579
+ import(document: SnapshotDocument, options?: {
1580
+ name?: string;
1581
+ namespace?: string;
1582
+ }): SnapshotInfo;
1583
+ restore(id: string, namespace?: string): void;
1584
+ delete(id: string, namespace?: string): boolean;
1585
+ };
1586
+ /** Request headers that carry controls, checked: spread them into a `fetch` or an SDK's defaults. */
1587
+ headers(input: ControlHeaderInput): Record<string, string>;
1588
+ snapshot(namespace?: string): NamespaceSnapshot;
1589
+ restore(snapshot: NamespaceSnapshot, namespace?: string): void;
1590
+ /** Capture the current branch. Mutating HTTP calls do this automatically. */
1591
+ checkpoint(namespace?: string, branch?: string): ServiceCheckpoint;
1592
+ /** Create an isolated branch, optionally from a historical checkpoint. */
1593
+ branch(name: string, options?: {
1594
+ namespace?: string;
1595
+ at?: string;
1596
+ }): ServiceCheckpoint;
1597
+ /** Restore a branch, clock, and PRNG to a checkpoint. */
1598
+ checkout(checkpoint: string, options?: {
1599
+ namespace?: string;
1600
+ branch?: string;
1601
+ }): void;
1602
+ /** Inspect the retained history for a namespace. */
1603
+ timeline(namespace?: string): Timeline<ServiceTimelineState>;
1604
+ /** Collections in one namespace: declared shape plus what the rows actually hold. */
1605
+ state(namespace?: string): StateView;
1606
+ };
1607
+
1608
+ type HttpServiceDefinition = Pick<RuntimeOptions<Service>, "name" | "presets" | "credential" | "state" | "admin"> & Pick<ServiceOptions, "document" | "before" | "unsupported"> & Partial<Pick<ServiceOptions, "onError" | "notFound">> & {
1609
+ version: string;
1610
+ defaultPort?: number;
1611
+ handlers(context: InstanceContext): OperationHandlers;
1612
+ };
1613
+ type HttpRuntimeFactory = (options?: MockCreateOptions & Pick<RuntimeOptions<Service>, "onLog">) => ServiceRuntime<Service>;
1614
+ /** Structural subset of the fleet boot options consumed by HTTP services. */
1615
+ type HttpBootControls = {
1616
+ [K in "adminKey" | "adminPrefix" | "seed" | "adminControls" | "onLog"]?: RuntimeOptions<Service>[K] | undefined;
1617
+ };
1618
+ interface HttpServeTarget {
1619
+ name: string;
1620
+ packageVersion: string;
1621
+ defaultPort: number;
1622
+ create(values: unknown, common: HttpBootControls): ServiceRuntime<Service>;
1623
+ }
1624
+ /** Define once for Fetch, a Node listener, or a fleet. Each boot owns its storage and clock. */
1625
+ declare function defineHttpService(definition: HttpServiceDefinition): {
1626
+ createRuntime: HttpRuntimeFactory;
1627
+ serveTarget: HttpServeTarget;
1628
+ };
1629
+
1630
+ export { Collection, IdSequence, bodyIssues, defineHttpService, defineOperations, jsonRes as jsonResponse };
1631
+ export type { HttpRuntimeFactory, HttpServeTarget, HttpServiceDefinition, InstanceContext, OperationHandlers };