@emulates/docker 0.0.0-stage → 0.1.1

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,1306 @@
1
+ import { Hono } from 'hono';
2
+
3
+ /**
4
+ * Anything that can answer a Fetch `Request` with a `Response`.
5
+ *
6
+ * Every Emulates service implements this, and every runtime adapter consumes it.
7
+ * It is the only contract shared across the whole graph.
8
+ */
9
+ interface FetchAPI$1 {
10
+ fetch(request: Request): Promise<Response>;
11
+ }
12
+
13
+ /** Bind values accepted by the Emulates SQLite port (matches sqlite-mem / better-sqlite3). */
14
+ type SqliteValue$1 = null | number | bigint | string | Uint8Array | boolean;
15
+ /** Mutation counters returned by {@link SqliteStatement.run}. */
16
+ type SqliteRunResult$1 = {
17
+ changes: number;
18
+ lastInsertRowid: number | bigint;
19
+ };
20
+ /**
21
+ * Prepared statement bound to a {@link SqliteClient}.
22
+ *
23
+ * Pass bind values as rest arguments on each call (no sticky `bind()`).
24
+ */
25
+ interface SqliteStatement$1 {
26
+ run(...params: SqliteValue$1[]): SqliteRunResult$1;
27
+ all<T = Record<string, unknown>>(...params: SqliteValue$1[]): T[];
28
+ get<T = Record<string, unknown>>(...params: SqliteValue$1[]): T | undefined;
29
+ }
30
+ /**
31
+ * Sync SQLite client port owned by Emulates.
32
+ *
33
+ * Duck-typed so `@emulates/sqlite` `Database`, better-sqlite3, and wrapped
34
+ * `bun:sqlite` instances all work when they expose this surface.
35
+ */
36
+ interface SqliteClient$1 {
37
+ exec(sql: string): void;
38
+ prepare(sql: string): SqliteStatement$1;
39
+ transaction<T>(fn: () => T): T;
40
+ }
41
+
42
+ /** Every stored record carries a monotonically increasing sequence for stable ordering. */
43
+ type Stored<T> = {
44
+ seq: number;
45
+ value: T;
46
+ };
47
+ type ListRecordsOptions<T> = {
48
+ /** Keep only records passing the predicate. */
49
+ where?: (value: T, seq: number) => boolean;
50
+ /** Sort order; default newest first. */
51
+ order?: "newest" | "oldest";
52
+ };
53
+ /**
54
+ * A SQLite-backed table of JSON records addressed by id. Ordering is by insertion
55
+ * sequence, never by id lexicographic order, so list semantics stay stable.
56
+ */
57
+ declare class Collection<T> {
58
+ private readonly sqlite;
59
+ /** Storage namespace. Admin introspection uses this to ignore another namespace's tables. */
60
+ readonly namespace: string;
61
+ /** Table name inside the namespace. Stable across resets of the rows themselves. */
62
+ readonly collectionName: string;
63
+ constructor(sqlite: SqliteClient$1,
64
+ /** Storage namespace. Admin introspection uses this to ignore another namespace's tables. */
65
+ namespace: string,
66
+ /** Table name inside the namespace. Stable across resets of the rows themselves. */
67
+ collectionName: string);
68
+ private bumpCollectionSeq;
69
+ nextSequence(): number;
70
+ get(id: string): T | undefined;
71
+ has(id: string): boolean;
72
+ /** Insert a new record, assigning it the next sequence number. */
73
+ insert(id: string, value: T): Stored<T>;
74
+ /** Replace an existing record's value, keeping its position. */
75
+ update(id: string, value: T): Stored<T> | undefined;
76
+ delete(id: string): boolean;
77
+ /** How many records the collection holds, without reading them. */
78
+ count(): number;
79
+ list(options?: ListRecordsOptions<T>): Array<Stored<T> & {
80
+ id: string;
81
+ }>;
82
+ }
83
+
84
+ /** A stable identifier for a point in a {@link Timeline}. */
85
+ type CheckpointId = string;
86
+ /** An immutable node in a timeline's checkpoint DAG. */
87
+ type Checkpoint<T> = Readonly<{
88
+ id: CheckpointId;
89
+ branch: string;
90
+ parent: CheckpointId | null;
91
+ /** Logical time supplied by the timeline's injected clock. */
92
+ at: number;
93
+ value: T;
94
+ }>;
95
+ type TimelineOptions = {
96
+ /** Logical clock used to stamp checkpoints. Defaults to a deterministic counter. */
97
+ now?: () => number;
98
+ /** Maximum retained checkpoints. Branch heads are never collected. Default 1,000. */
99
+ maxCheckpoints?: number;
100
+ /** Customize deterministic checkpoint IDs. */
101
+ id?: (sequence: number) => CheckpointId;
102
+ };
103
+ type CommitOptions = {
104
+ branch?: string;
105
+ /** Parent checkpoint. Defaults to the selected branch's current head. */
106
+ parent?: CheckpointId | null;
107
+ };
108
+ type ForkOptions = {
109
+ /** Checkpoint to fork from. Defaults to the main branch's head. */
110
+ from?: CheckpointId;
111
+ };
112
+ /**
113
+ * Small, storage-agnostic checkpoint DAG shared by service runtimes. Its values may be immutable
114
+ * records, namespace images, or copy-on-write SQL engine snapshots.
115
+ *
116
+ * Values are retained by reference. Engines can therefore use persistent/COW snapshots while
117
+ * simpler services can use immutable values. IDs and GC order are deterministic, and all IO
118
+ * (the logical clock) is injected.
119
+ */
120
+ declare class Timeline<T> {
121
+ readonly maxCheckpoints: number;
122
+ private readonly now;
123
+ private readonly makeId;
124
+ private readonly nodes;
125
+ private readonly heads;
126
+ /** Unreferenced nodes in the exact order they became collectible. */
127
+ private readonly evictable;
128
+ /** Branch heads plus explicit retainers. Absent means zero. */
129
+ private readonly references;
130
+ private readonly explicitPins;
131
+ private sequence;
132
+ constructor(options?: TimelineOptions);
133
+ /** Capture a new immutable value and move `branch` to it. */
134
+ commit(value: T, options?: CommitOptions): Checkpoint<T>;
135
+ /** Create a branch pointer without copying its checkpoint value. */
136
+ fork(branch: string, options?: ForkOptions): Checkpoint<T> | undefined;
137
+ /** Move a branch pointer to an existing checkpoint. */
138
+ checkout(branch: string, id: CheckpointId): Checkpoint<T>;
139
+ get(id: CheckpointId): Checkpoint<T>;
140
+ head(branch?: string): Checkpoint<T> | undefined;
141
+ hasBranch(branch: string): boolean;
142
+ branches(): Readonly<Record<string, CheckpointId>>;
143
+ checkpoints(): readonly Checkpoint<T>[];
144
+ /** Number of retained checkpoints without allocating an array. */
145
+ get size(): number;
146
+ /** Pin a checkpoint independently of branch heads (used by compatibility snapshot handles). */
147
+ retain(id: CheckpointId): Checkpoint<T>;
148
+ /** Release one explicit pin. Branch heads remain pinned until moved or deleted. */
149
+ release(id: CheckpointId): boolean;
150
+ deleteBranch(branch: string): boolean;
151
+ /**
152
+ * Deterministically discard oldest unpinned checkpoints. Collection is O(number removed):
153
+ * commits never scan pinned nodes or the retained history. Parents are metadata rather than a
154
+ * storage dependency, so a retained node remains usable after pruning.
155
+ */
156
+ gc(max?: number): CheckpointId[];
157
+ private collect;
158
+ private moveHead;
159
+ private addReference;
160
+ private removeReference;
161
+ private assertBranch;
162
+ }
163
+
164
+ /**
165
+ * Anything that can answer a Fetch `Request` with a `Response`.
166
+ *
167
+ * Every Emulates service implements this, and every runtime adapter consumes it.
168
+ * It is the only contract shared across the whole graph.
169
+ */
170
+ interface FetchAPI {
171
+ fetch(request: Request): Promise<Response>;
172
+ }
173
+
174
+ /**
175
+ * The slice of OpenAPI 3.1 (and JSON Schema 2020-12) Emulates understands.
176
+ * Unknown keys (including `x-*` extensions) are preserved on every object.
177
+ */
178
+ type JsonPrimitive$1 = string | number | boolean | null;
179
+ type JsonValue$1 = JsonPrimitive$1 | JsonValue$1[] | {
180
+ [key: string]: JsonValue$1;
181
+ };
182
+ type ReferenceObject$1 = {
183
+ $ref: string;
184
+ description?: string;
185
+ summary?: string;
186
+ };
187
+ type SchemaType$1 = "string" | "number" | "integer" | "boolean" | "object" | "array" | "null";
188
+ type SchemaObject$1 = {
189
+ $ref?: string;
190
+ type?: SchemaType$1 | SchemaType$1[];
191
+ title?: string;
192
+ description?: string;
193
+ format?: string;
194
+ enum?: JsonValue$1[];
195
+ const?: JsonValue$1;
196
+ default?: JsonValue$1;
197
+ example?: JsonValue$1;
198
+ examples?: JsonValue$1[];
199
+ nullable?: boolean;
200
+ deprecated?: boolean;
201
+ readOnly?: boolean;
202
+ writeOnly?: boolean;
203
+ minimum?: number;
204
+ maximum?: number;
205
+ exclusiveMinimum?: number;
206
+ exclusiveMaximum?: number;
207
+ multipleOf?: number;
208
+ minLength?: number;
209
+ maxLength?: number;
210
+ pattern?: string;
211
+ minItems?: number;
212
+ maxItems?: number;
213
+ uniqueItems?: boolean;
214
+ items?: SchemaObject$1;
215
+ prefixItems?: SchemaObject$1[];
216
+ minProperties?: number;
217
+ maxProperties?: number;
218
+ required?: string[];
219
+ properties?: Record<string, SchemaObject$1>;
220
+ additionalProperties?: boolean | SchemaObject$1;
221
+ propertyNames?: SchemaObject$1;
222
+ oneOf?: SchemaObject$1[];
223
+ anyOf?: SchemaObject$1[];
224
+ allOf?: SchemaObject$1[];
225
+ not?: SchemaObject$1;
226
+ discriminator?: {
227
+ propertyName: string;
228
+ mapping?: Record<string, string>;
229
+ };
230
+ [extension: `x-${string}`]: unknown;
231
+ };
232
+ type ParameterLocation$1 = "path" | "query" | "header" | "cookie";
233
+ type ParameterObject$1 = {
234
+ name: string;
235
+ in: ParameterLocation$1;
236
+ description?: string;
237
+ required?: boolean;
238
+ deprecated?: boolean;
239
+ style?: string;
240
+ explode?: boolean;
241
+ schema?: SchemaObject$1;
242
+ content?: Record<string, MediaTypeObject$1>;
243
+ example?: JsonValue$1;
244
+ [extension: `x-${string}`]: unknown;
245
+ };
246
+ type MediaTypeObject$1 = {
247
+ schema?: SchemaObject$1;
248
+ example?: JsonValue$1;
249
+ examples?: Record<string, unknown>;
250
+ encoding?: Record<string, unknown>;
251
+ [extension: `x-${string}`]: unknown;
252
+ };
253
+ type RequestBodyObject$1 = {
254
+ description?: string;
255
+ required?: boolean;
256
+ content: Record<string, MediaTypeObject$1>;
257
+ [extension: `x-${string}`]: unknown;
258
+ };
259
+ type HeaderObject$1 = {
260
+ description?: string;
261
+ required?: boolean;
262
+ schema?: SchemaObject$1;
263
+ [extension: `x-${string}`]: unknown;
264
+ };
265
+ type ResponseObject$1 = {
266
+ description: string;
267
+ headers?: Record<string, HeaderObject$1 | ReferenceObject$1>;
268
+ content?: Record<string, MediaTypeObject$1>;
269
+ [extension: `x-${string}`]: unknown;
270
+ };
271
+ type ResponsesObject$1 = Record<string, ResponseObject$1 | ReferenceObject$1>;
272
+ type SecurityRequirementObject$1 = Record<string, string[]>;
273
+ type OperationObject$1 = {
274
+ operationId?: string;
275
+ summary?: string;
276
+ description?: string;
277
+ tags?: string[];
278
+ deprecated?: boolean;
279
+ parameters?: Array<ParameterObject$1 | ReferenceObject$1>;
280
+ requestBody?: RequestBodyObject$1 | ReferenceObject$1;
281
+ responses: ResponsesObject$1;
282
+ security?: SecurityRequirementObject$1[];
283
+ [extension: `x-${string}`]: unknown;
284
+ };
285
+ declare const HTTP_METHODS$1: readonly ["get", "put", "post", "delete", "options", "head", "patch", "trace"];
286
+ type HttpMethod$1 = (typeof HTTP_METHODS$1)[number];
287
+ type PathItemObject$1 = {
288
+ summary?: string;
289
+ description?: string;
290
+ parameters?: Array<ParameterObject$1 | ReferenceObject$1>;
291
+ [extension: `x-${string}`]: unknown;
292
+ } & Partial<Record<HttpMethod$1, OperationObject$1>>;
293
+ type SecuritySchemeObject$1 = {
294
+ type: "apiKey" | "http" | "oauth2" | "openIdConnect" | "mutualTLS";
295
+ description?: string;
296
+ name?: string;
297
+ in?: ParameterLocation$1;
298
+ scheme?: string;
299
+ bearerFormat?: string;
300
+ flows?: Record<string, unknown>;
301
+ openIdConnectUrl?: string;
302
+ [extension: `x-${string}`]: unknown;
303
+ };
304
+ type ComponentsObject$1 = {
305
+ schemas?: Record<string, SchemaObject$1>;
306
+ responses?: Record<string, ResponseObject$1>;
307
+ parameters?: Record<string, ParameterObject$1>;
308
+ requestBodies?: Record<string, RequestBodyObject$1>;
309
+ headers?: Record<string, HeaderObject$1>;
310
+ securitySchemes?: Record<string, SecuritySchemeObject$1>;
311
+ [extension: `x-${string}`]: unknown;
312
+ };
313
+ type ServerObject$1 = {
314
+ url: string;
315
+ description?: string;
316
+ variables?: Record<string, unknown>;
317
+ [extension: `x-${string}`]: unknown;
318
+ };
319
+ type InfoObject$1 = {
320
+ title: string;
321
+ version: string;
322
+ description?: string;
323
+ [extension: `x-${string}`]: unknown;
324
+ };
325
+ type OpenAPIDocument$1 = {
326
+ openapi: string;
327
+ info: InfoObject$1;
328
+ servers?: ServerObject$1[];
329
+ paths: Record<string, PathItemObject$1>;
330
+ components?: ComponentsObject$1;
331
+ security?: SecurityRequirementObject$1[];
332
+ tags?: Array<{
333
+ name: string;
334
+ description?: string;
335
+ }>;
336
+ [extension: `x-${string}`]: unknown;
337
+ };
338
+
339
+ /** Options every provider constructor accepts. */
340
+ type APIOptions = {
341
+ /** Sync SQLite client. Defaults to `@emulates/sqlite`. */
342
+ sqlite?: SqliteClient$1;
343
+ /** Clock used for `created`-style fields. Default `Date.now`. */
344
+ now?: () => number;
345
+ /**
346
+ * Storage namespace for this instance's records. Instances sharing one SQLite
347
+ * client stay isolated when their namespaces differ. Defaults to the service name.
348
+ */
349
+ namespace?: string;
350
+ };
351
+
352
+ /**
353
+ * The single source of time for a service.
354
+ *
355
+ * Every timestamp a mock writes reads from here, so a suite moves time instead of
356
+ * sleeping: appointment windows, result delays and expiries become reachable in
357
+ * milliseconds. A frozen clock also makes timestamps reproducible from a seed.
358
+ */
359
+ type ClockState = {
360
+ /** Current epoch milliseconds. */
361
+ now: number;
362
+ /** True while time does not advance on its own. */
363
+ frozen: boolean;
364
+ /** Milliseconds this clock adds to its underlying source. */
365
+ offsetMs: number;
366
+ };
367
+ type Clock = {
368
+ now(): number;
369
+ /** Pin the clock to an exact instant, keeping it frozen if it already was. */
370
+ set(epochMs: number): void;
371
+ /** Move the clock forward, or back with a negative delta. */
372
+ advance(deltaMs: number): void;
373
+ /** Stop time at the current instant. */
374
+ freeze(): void;
375
+ /** Resume from the current instant. */
376
+ unfreeze(): void;
377
+ /** Drop back to the underlying source, live. */
378
+ reset(): void;
379
+ state(): ClockState;
380
+ };
381
+
382
+ /**
383
+ * Seeded pseudo-random numbers, so anything a mock invents — ids, jitter, which
384
+ * request a percentage fault hits — is reproducible from a seed.
385
+ *
386
+ * mulberry32: small, fast, and stable across runtimes, which matters more here
387
+ * than statistical quality.
388
+ */
389
+ type Rng = {
390
+ /** Next value in `[0, 1)`. */
391
+ next(): number;
392
+ /** Next integer in `[min, max]`. */
393
+ int(min: number, max: number): number;
394
+ /** Restart the stream from its seed. */
395
+ reset(): void;
396
+ /** Serializable engine state used by deterministic checkpoints. */
397
+ state(): number;
398
+ /** Restore a state previously returned by {@link state}. */
399
+ setState(state: number): void;
400
+ seed: number;
401
+ };
402
+
403
+ /**
404
+ * A deliberate failure injected in front of an operation.
405
+ *
406
+ * This is how a suite reaches the vendor's failure modes without the vendor: the
407
+ * quota error that only appears when a shared sandbox is full, the 429 that only
408
+ * appears under load, the 5xx that proves a retry path works.
409
+ */
410
+ type FaultRule = {
411
+ /** Stable id, so a suite can retire exactly the rule it added. */
412
+ id: string;
413
+ /** Fault only this operation. Omit to match every operation. */
414
+ operationId?: string;
415
+ /** Fault only this HTTP method, case-insensitive. Omit to match every method. */
416
+ method?: string;
417
+ /** Fault only paths starting with this prefix. Omit to match every path. */
418
+ pathPrefix?: string;
419
+ /**
420
+ * Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
421
+ * an in-process caller usually wants, and what a parallel worker usually does not:
422
+ * rules added through `POST /__admin/faults` default to the calling namespace.
423
+ */
424
+ namespace?: string;
425
+ /**
426
+ * Status of the injected response. Omit for a rule that only delays (`delayMs` /
427
+ * `latencyMs`), only drops the connection (`drop`), or only switches on an `effect`:
428
+ * the request then still reaches the service.
429
+ */
430
+ status?: number;
431
+ /** Response body, serialized as JSON. A string is sent as-is. */
432
+ body?: unknown;
433
+ headers?: Record<string, string>;
434
+ /** Retire the rule after this many faults. Omit to keep it until removed. */
435
+ count?: number;
436
+ /** Fault this fraction of matching requests, `0`–`1`. Default `1`. */
437
+ rate?: number;
438
+ /** Hold the response back this long, to exercise timeouts. */
439
+ delayMs?: number;
440
+ /** Alias of `delayMs`. */
441
+ latencyMs?: number;
442
+ /**
443
+ * Drop the connection instead of answering: an in-process `fetch` rejects with a
444
+ * `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
445
+ */
446
+ drop?: boolean;
447
+ /**
448
+ * A named service behaviour to switch on for the matching request instead of (or
449
+ * before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
450
+ * read it with `faultEffects(request)`.
451
+ */
452
+ effect?: string;
453
+ /** Parameters for `effect`. */
454
+ params?: Record<string, unknown>;
455
+ /** From the preset this rule was expanded from, if any. */
456
+ preset?: string;
457
+ };
458
+ /** A fault that fired for one request. */
459
+ type FaultHit = {
460
+ id: string;
461
+ /** The injected response; absent when the rule only delays, drops, or sets an effect. */
462
+ response?: Response;
463
+ drop?: boolean;
464
+ effect?: {
465
+ name: string;
466
+ params: Record<string, unknown>;
467
+ };
468
+ };
469
+ /**
470
+ * A named, documented fault a suite switches on by name
471
+ * (`POST /__admin/faults {"preset": "rate_limited"}`): one or more rules, and optionally a
472
+ * webhook delivery fault.
473
+ */
474
+ type FaultPreset = {
475
+ description: string;
476
+ rules?: Omit<FaultRule, "id">[];
477
+ webhook?: {
478
+ mode: "duplicate" | "reorder" | "drop";
479
+ count?: number;
480
+ };
481
+ };
482
+ /** What a request looks like to the fault matcher. */
483
+ type FaultCandidate = {
484
+ operationId: string | undefined;
485
+ method: string;
486
+ path: string;
487
+ namespace: string;
488
+ };
489
+ type FaultRegistry = {
490
+ isolateNamespaces(): void;
491
+ snapshot(namespace: string): {
492
+ rules: (FaultRule & {
493
+ remaining: number | null;
494
+ hits: number;
495
+ position: number;
496
+ })[];
497
+ rngState: number;
498
+ };
499
+ add(rule: FaultRule): FaultRule;
500
+ list(): (FaultRule & {
501
+ remaining: number | null;
502
+ hits: number;
503
+ })[];
504
+ remove(id: string): boolean;
505
+ clear(): void;
506
+ restore(namespace: string, state: {
507
+ rules: (FaultRule & {
508
+ remaining: number | null;
509
+ hits: number;
510
+ position: number;
511
+ })[];
512
+ rngState: number;
513
+ }): void;
514
+ /**
515
+ * Every fault this request should get, in rule order, stopping at the first that answers
516
+ * or drops (effect-only and delay-only rules let later rules match too). Consumes one of
517
+ * each matching rule's remaining uses.
518
+ */
519
+ take(candidate: FaultCandidate): Promise<FaultHit[]>;
520
+ };
521
+
522
+ /**
523
+ * One problem with a request body, at a dotted path (`patient.address.city`, `items.0.sku`).
524
+ * `kind` is `media_type` when the body is present but its media type is not one the operation
525
+ * accepts (a `415` on most vendors), `syntax` when it could not be decoded, `required` when
526
+ * the operation needs a body and none arrived, and `schema` for a contract violation.
527
+ */
528
+ type BodyIssue = {
529
+ path: string;
530
+ message: string;
531
+ kind?: "media_type" | "syntax" | "required" | "schema";
532
+ };
533
+
534
+ /**
535
+ * What the mock received from a request it rejected, so a 4xx can be attributed after the
536
+ * fact (an empty body, a missing `content-type`, a schema violation) without logging the body.
537
+ */
538
+ type RejectedRequest = {
539
+ /** The raw `content-type` header, or `null` when the request sent none. */
540
+ contentType: string | null;
541
+ /** Bytes of body received from `content-length` (`0` for none), or `null` when the client sent no length (a streamed / chunked body). */
542
+ bodyBytes: number | null;
543
+ /** The raw `transfer-encoding` header (`chunked`), or `null`. */
544
+ transferEncoding: string | null;
545
+ };
546
+ /** One handled request, as the structured log sees it. */
547
+ type RequestLog = {
548
+ service: string;
549
+ namespace: string;
550
+ operationId: string | undefined;
551
+ method: string;
552
+ path: string;
553
+ status: number;
554
+ durationMs: number;
555
+ /** True when the path matched no operation in the contract. */
556
+ unmatched: boolean;
557
+ /** Set when a fault rule produced the response. */
558
+ faultId?: string;
559
+ /** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
560
+ ids?: Record<string, string>;
561
+ /** Set when the service created a resource the request referred to but that did not exist. */
562
+ adopted?: boolean;
563
+ /** Explicit durable acceptance, independent of response delivery. */
564
+ accepted?: boolean;
565
+ /** Checkpoint captured at explicit acceptance. */
566
+ checkpoint?: string;
567
+ /** Set on a rejection (status ≥ 400) the mock produced itself, never on a scripted fault. */
568
+ request?: RejectedRequest;
569
+ /** The validation issues behind a rejection, when the service found any. */
570
+ issues?: BodyIssue[];
571
+ };
572
+ type MetricsReport = {
573
+ requests: number;
574
+ /** Counts keyed `<operationId> <status>`. */
575
+ byOperation: Record<string, number>;
576
+ /**
577
+ * Paths that matched no operation, most frequent first.
578
+ *
579
+ * This is the early-warning signal: a consumer calling something the mock does
580
+ * not implement shows up here as a count, before it fails a suite as a 404.
581
+ */
582
+ unmatched: {
583
+ method: string;
584
+ path: string;
585
+ count: number;
586
+ }[];
587
+ faults: number;
588
+ totalDurationMs: number;
589
+ };
590
+ type Metrics = {
591
+ record(entry: RequestLog): void;
592
+ report(namespace?: string): MetricsReport;
593
+ reset(namespace?: string): void;
594
+ };
595
+
596
+ /** One journal entry: a request log stamped with when (on the mock clock) it was handled. */
597
+ type JournalEntry = RequestLog & {
598
+ at: string;
599
+ };
600
+ type JournalQuery = {
601
+ /** Only this namespace. Omit for every namespace, oldest first across all of them. */
602
+ namespace?: string;
603
+ operationId?: string;
604
+ status?: number;
605
+ /** Only entries at or after this instant (epoch ms). */
606
+ since?: number;
607
+ /** At most this many, the most recent kept. */
608
+ limit?: number;
609
+ };
610
+ type Journal = {
611
+ readonly size: number;
612
+ record(entry: JournalEntry): void;
613
+ list(query?: JournalQuery): JournalEntry[];
614
+ /** Forget one namespace's entries, or every namespace's. */
615
+ clear(namespace?: string): void;
616
+ };
617
+
618
+ type AdminRequest = {
619
+ request: Request;
620
+ url: URL;
621
+ /** `:param` segments of the matched route. */
622
+ params: Record<string, string>;
623
+ /** Namespace the request targets: `?namespace=`, then the header, then the default. */
624
+ namespace: string;
625
+ /** Parsed JSON body, or `undefined` when there is none. */
626
+ body: unknown;
627
+ };
628
+ type AdminRoute = (request: AdminRequest) => Response | Promise<Response>;
629
+ /**
630
+ * Service-specific admin routes, keyed `METHOD /path` relative to `/__admin`, with
631
+ * `:param` segments — e.g. `"POST /orders/:id/transition"`.
632
+ */
633
+ type AdminRoutes = Record<string, AdminRoute>;
634
+
635
+ /** Credential → namespace mapping behind `PUT /__admin/credentials`. */
636
+ type CredentialRegistry = {
637
+ set(credential: string, namespace: string): void;
638
+ get(credential: string): string | undefined;
639
+ remove(credential: string): boolean;
640
+ clear(): void;
641
+ entries(): {
642
+ credential: string;
643
+ namespace: string;
644
+ }[];
645
+ };
646
+
647
+ /**
648
+ * A point-in-time copy of everything a service namespace holds.
649
+ *
650
+ * All service state lives in the two core tables keyed by namespace, so a snapshot
651
+ * is generic: any service gets per-test rollback without knowing its own schema.
652
+ * Restoring is much cheaper than rebuilding a namespace from a corpus.
653
+ */
654
+ type NamespaceSnapshot = {
655
+ namespace: string;
656
+ records: {
657
+ collection: string;
658
+ id: string;
659
+ seq: number;
660
+ value: string;
661
+ }[];
662
+ sequences: {
663
+ name: string;
664
+ kind: string;
665
+ value: number;
666
+ }[];
667
+ };
668
+
669
+ declare const STATE_FIELD_KINDS: readonly ["string", "number", "boolean", "null", "object", "array", "unknown"];
670
+ type StateFieldKind = (typeof STATE_FIELD_KINDS)[number];
671
+ /** JSON-safe annotations a bespoke admin UI may read. The default UI shows them as text. */
672
+ type StateMeta = Readonly<Record<string, string | number | boolean | null>>;
673
+ type StateField = {
674
+ name: string;
675
+ kind: StateFieldKind;
676
+ optional: boolean;
677
+ description?: string;
678
+ /** One level of nested object fields. */
679
+ fields?: StateField[];
680
+ meta?: StateMeta;
681
+ };
682
+ /**
683
+ * What a service knows about a collection before any row exists.
684
+ * Stored rows still appear, including fields this declaration does not mention.
685
+ */
686
+ type StateDeclaration = {
687
+ name: string;
688
+ label?: string;
689
+ description?: string;
690
+ fields?: readonly StateField[];
691
+ meta?: StateMeta;
692
+ };
693
+ type StateCollectionView = {
694
+ name: string;
695
+ label: string;
696
+ description?: string;
697
+ count: number;
698
+ /** `mixed` when a declaration and stored rows both contribute fields. */
699
+ source: "declared" | "inferred" | "mixed";
700
+ fields: StateField[];
701
+ meta?: StateMeta;
702
+ };
703
+ /** The shape of one namespace, for an admin UI that has never seen the service before. */
704
+ type StateView = {
705
+ namespace: string;
706
+ storageNamespace: string;
707
+ collections: StateCollectionView[];
708
+ };
709
+
710
+ /**
711
+ * A contribution the admin shell mounts beside the shared views.
712
+ * `panel` is author-owned markup. `sql` turns on the built-in table explorer
713
+ * and query runner, which call `GET /sql/tables` and `POST /sql/query`.
714
+ * `route` presents an admin action with the shell's prebuilt form and response view.
715
+ */
716
+ type AdminExtension = {
717
+ kind: "route";
718
+ id: string;
719
+ title: string;
720
+ description?: string;
721
+ /** An existing admin route, including its method and any path parameters. */
722
+ route: string;
723
+ /** Initial JSON body shown in the request form. */
724
+ body?: unknown;
725
+ } | {
726
+ kind: "panel";
727
+ id: string;
728
+ title: string;
729
+ description?: string;
730
+ html: string;
731
+ script?: string;
732
+ } | {
733
+ kind: "sql";
734
+ /** DOM id suffix. Default `sql`. */
735
+ id?: string;
736
+ title?: string;
737
+ description?: string;
738
+ };
739
+ /** A panel the default admin shell mounts after the shared views. */
740
+ type AdminPanel = {
741
+ /** DOM id suffix. Lowercase letters, digits, and hyphens. */
742
+ id: string;
743
+ title: string;
744
+ description?: string;
745
+ /** Markup placed inside the panel body. The service author owns it. */
746
+ html: string;
747
+ /**
748
+ * Function body called as `(root, api) => void` once the shell has loaded.
749
+ * `root` is the panel body. `api` is `{ get, send, namespace }` against `/__admin`.
750
+ */
751
+ script?: string;
752
+ };
753
+ /**
754
+ * How a service customizes the admin UI without leaving the shared shell.
755
+ * `panels` add views. `render` replaces the document and can call `defaultHtml()`
756
+ * to wrap the shared shell instead of discarding it.
757
+ */
758
+ type AdminUi = {
759
+ panels?: readonly AdminPanel[];
760
+ /** First-class shell contributions. `sql` mounts the shared database explorer. */
761
+ extensions?: readonly AdminExtension[];
762
+ render?: (input: {
763
+ service: string;
764
+ defaultHtml: () => string;
765
+ }) => string;
766
+ };
767
+
768
+ type WebhookEndpoint = {
769
+ /** Stable id; generated when omitted. */
770
+ id?: string;
771
+ url: string;
772
+ secret?: string;
773
+ /** Event types to deliver; omit or include `"*"` for every type. */
774
+ events?: string[];
775
+ /** Deliver only messages whose tags include all of these (e.g. `{ account: "mso" }`). */
776
+ tags?: Record<string, string>;
777
+ /** The public URL the receiver verifies signatures against (Twilio), when it differs. */
778
+ signUrl?: string;
779
+ headers?: Record<string, string>;
780
+ };
781
+ type WebhookMessage = {
782
+ id: string;
783
+ namespace: string;
784
+ type: string;
785
+ body: string;
786
+ contentType: string;
787
+ tags: Record<string, string>;
788
+ headers?: Record<string, string>;
789
+ /** Wall-clock ISO-8601 time of publication. */
790
+ publishedAt: string;
791
+ };
792
+ type WebhookAttempt = {
793
+ attempt: number;
794
+ at: string;
795
+ status: number | null;
796
+ error: string | null;
797
+ durationMs: number;
798
+ /** Exact receiver response body, when one was returned. */
799
+ responseBody?: string | null;
800
+ };
801
+ type WebhookDelivery = {
802
+ id: string;
803
+ messageId: string;
804
+ namespace: string;
805
+ type: string;
806
+ endpointId: string;
807
+ url: string;
808
+ state: "pending" | "delivered" | "failed" | "dropped";
809
+ attempts: WebhookAttempt[];
810
+ };
811
+ /** A delivery-level fault: what happens to the next `count` messages in a namespace. */
812
+ type WebhookFault = {
813
+ mode: "duplicate" | "reorder" | "drop";
814
+ /** Messages affected; default 1. */
815
+ count?: number;
816
+ };
817
+ type PublishInput = {
818
+ namespace: string;
819
+ type: string;
820
+ /** Exact body; objects are JSON-encoded. */
821
+ body: string | Record<string, unknown> | unknown[];
822
+ /** Default `application/json`, or form-encoded when `form` is given. */
823
+ contentType?: string;
824
+ /** Form parameters, when the vendor posts `application/x-www-form-urlencoded`. */
825
+ form?: Record<string, string>;
826
+ tags?: Record<string, string>;
827
+ /** Message-specific delivery headers, captured as part of durable message state. */
828
+ headers?: Record<string, string>;
829
+ /** Message id; generated when omitted. */
830
+ id?: string;
831
+ };
832
+ type WebhookHub = {
833
+ pending(namespace: string): number;
834
+ snapshot(namespace: string): unknown;
835
+ restore(namespace: string, snapshot: unknown): void;
836
+ publish(input: PublishInput): WebhookMessage;
837
+ /** Replace a namespace's own endpoints (`PUT /__admin/webhook-endpoints`). */
838
+ setEndpoints(namespace: string, endpoints: WebhookEndpoint[]): WebhookEndpoint[];
839
+ /** The endpoints a namespace delivers to: its own, plus the global ones. */
840
+ endpoints(namespace: string): WebhookEndpoint[];
841
+ messages(namespace?: string): WebhookMessage[];
842
+ deliveries(namespace?: string): WebhookDelivery[];
843
+ replay(deliveryId: string): Promise<WebhookDelivery | undefined>;
844
+ /** Run every pending retry (and release held reordered messages) now, and every retry those attempts schedule, until nothing is pending. */
845
+ flush(): Promise<void>;
846
+ /** Resolve once nothing is in flight. */
847
+ idle(): Promise<void>;
848
+ fault(namespace: string, fault: WebhookFault): void;
849
+ clear(namespace?: string): void;
850
+ };
851
+
852
+ /** What the runtime needs from a service: a Fetch handler it can reset. */
853
+ type ServiceInstance = FetchAPI & {
854
+ reset(): Promise<void>;
855
+ };
856
+ /** Everything an instance shares with the runtime that owns it. */
857
+ type InstanceContext = {
858
+ /** Storage namespace for this instance's records. */
859
+ namespace: string;
860
+ /** The public namespace name a request selects it by. */
861
+ adminPrefix: string;
862
+ publicNamespace: string;
863
+ sqlite: SqliteClient$1;
864
+ clock: Clock;
865
+ rng: Rng;
866
+ };
867
+ type RuntimeOptions<T extends ServiceInstance> = {
868
+ /** Service name, e.g. `"junction"`. Also the default namespace's storage key. */
869
+ name: string;
870
+ /** Build the instance backing one namespace. Called once per namespace, on first use. */
871
+ create: (context: InstanceContext) => T;
872
+ /** The vendor contract, used to name each request's operation in logs, metrics and faults. */
873
+ document?: OpenAPIDocument$1;
874
+ /** Shared by every namespace. Defaults to a fresh `@emulates/sqlite`. */
875
+ sqlite?: SqliteClient$1;
876
+ /** Defaults to a live clock over `Date.now`. */
877
+ clock?: Clock;
878
+ /** Seeds every random choice the runtime makes (fault rates). Default `0`. */
879
+ seed?: number | string;
880
+ /** Extra `GET /__admin/health` fields, such as the loaded corpus version. */
881
+ describe?: () => Record<string, unknown>;
882
+ /** Service-specific admin routes, given the runtime so they can reach any namespace. */
883
+ admin?: (runtime: ServiceRuntime<T>) => AdminRoutes;
884
+ /** Reserved tree for every internal HTTP endpoint, UI and namespace carrier. Default /__admin. */
885
+ adminPrefix?: string;
886
+ /** Invalidate transient handles before replacing an existing instance's stored state. */
887
+ beforeRestore?: (instance: T) => void;
888
+ /** Require this value in `x-emulates-admin-key` on admin data routes. */
889
+ adminKey?: string;
890
+ /** Structured request log sink, called once per request. */
891
+ onLog?: (entry: RequestLog) => void;
892
+ /** Requests each namespace's journal keeps (`GET /__admin/requests`). Default 1000; 0 turns it off. */
893
+ journalSize?: number;
894
+ /** Reported in the `x-emulates` header. Default: the bundled package's version. */
895
+ version?: string;
896
+ /**
897
+ * The vendor credential a request carries (API key, token, account SID, AWS access key
898
+ * id), for SDKs that cannot send `x-emulates-namespace`: a suite maps credentials to
899
+ * namespaces with `PUT /__admin/credentials`. See `bearerToken`, `basicAuth`,
900
+ * `sigV4AccessKeyId`.
901
+ */
902
+ credential?: (request: Request) => string | undefined;
903
+ /** Named faults, switched on with `POST /__admin/faults {"preset": "<name>"}`. */
904
+ presets?: Record<string, FaultPreset>;
905
+ /** Outbound webhooks; adds the `/__admin/webhooks*` routes and clears on reset. */
906
+ webhooks?: WebhookHub;
907
+ /** Retained time-travel checkpoints per namespace. Default 1,000. */
908
+ maxCheckpoints?: number;
909
+ /** Injectable process IO used for observability and delays; logical service time uses `clock`. */
910
+ io?: Partial<RuntimeIO>;
911
+ /**
912
+ * Collections the admin UI should show even before any row exists.
913
+ * Stored collections are always included, whether or not they are declared.
914
+ * A function may describe collections that depend on the live instance.
915
+ */
916
+ state?: readonly StateDeclaration[] | ((api: T, namespace: string) => readonly StateDeclaration[]);
917
+ /**
918
+ * Panels added to the default admin UI, or a function that replaces the document.
919
+ * `render` receives `defaultHtml()` so a bespoke UI can wrap the shared shell.
920
+ */
921
+ adminUi?: AdminUi;
922
+ };
923
+ type RuntimeIO = {
924
+ wallNow(): number;
925
+ monotonicNow(): number;
926
+ sleep(ms: number): Promise<void>;
927
+ };
928
+ type ServiceTimelineState = Readonly<{
929
+ snapshot: NamespaceSnapshot;
930
+ clock: Readonly<ReturnType<Clock["state"]>>;
931
+ rngState: number;
932
+ }>;
933
+ type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
934
+ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
935
+ /** Stop package-owned lifecycle timers when a supervisor closes the runtime. */
936
+ stop?(): void;
937
+ readonly name: string;
938
+ readonly sqlite: SqliteClient$1;
939
+ readonly clock: Clock;
940
+ readonly faults: FaultRegistry;
941
+ readonly metrics: Metrics;
942
+ readonly journal: Journal;
943
+ readonly rng: Rng;
944
+ readonly credentials: CredentialRegistry;
945
+ /** The webhook hub, when the service has outbound webhooks. */
946
+ readonly webhooks: WebhookHub | undefined;
947
+ /** Enable independent namespace clocks and PRNGs before serving a fleet. */
948
+ isolateNamespaces(): void;
949
+ namespaceClock(namespace?: string): Clock;
950
+ namespaceOf(request: Request): string;
951
+ /** Opaque in-process checkpoint including records, controls and webhook history. */
952
+ fleetSnapshot(namespace: string): object;
953
+ fleetRestore(snapshot: unknown, namespace: string): void;
954
+ /** Expand a named preset into fault rules (and webhook faults) for `namespace`. */
955
+ applyPreset(name: string, namespace?: string, overrides?: Partial<FaultRule>): FaultRule[];
956
+ /** The instance behind `namespace` (the default one when omitted), created on first use. */
957
+ instance(namespace?: string): T;
958
+ /** Public names of every namespace created so far. */
959
+ namespaces(): string[];
960
+ /** Reset one namespace, or every namespace with `"*"`. */
961
+ reset(namespace?: string): Promise<void>;
962
+ snapshot(namespace?: string): NamespaceSnapshot;
963
+ restore(snapshot: NamespaceSnapshot, namespace?: string): void;
964
+ /** Capture the current branch. Mutating HTTP calls do this automatically. */
965
+ checkpoint(namespace?: string, branch?: string): ServiceCheckpoint;
966
+ /** Create an isolated branch, optionally from a historical checkpoint. */
967
+ branch(name: string, options?: {
968
+ namespace?: string;
969
+ at?: string;
970
+ }): ServiceCheckpoint;
971
+ /** Restore a branch, clock, and PRNG to a checkpoint. */
972
+ checkout(checkpoint: string, options?: {
973
+ namespace?: string;
974
+ branch?: string;
975
+ }): void;
976
+ /** Inspect the retained history for a namespace. */
977
+ timeline(namespace?: string): Timeline<ServiceTimelineState>;
978
+ /** Collections in one namespace: declared shape plus what the rows actually hold. */
979
+ state(namespace?: string): StateView;
980
+ };
981
+
982
+ /** Bind values accepted by the Emulates SQLite port (matches sqlite-mem / better-sqlite3). */
983
+ type SqliteValue = null | number | bigint | string | Uint8Array | boolean;
984
+ /** Mutation counters returned by {@link SqliteStatement.run}. */
985
+ type SqliteRunResult = {
986
+ changes: number;
987
+ lastInsertRowid: number | bigint;
988
+ };
989
+ /**
990
+ * Prepared statement bound to a {@link SqliteClient}.
991
+ *
992
+ * Pass bind values as rest arguments on each call (no sticky `bind()`).
993
+ */
994
+ interface SqliteStatement {
995
+ run(...params: SqliteValue[]): SqliteRunResult;
996
+ all<T = Record<string, unknown>>(...params: SqliteValue[]): T[];
997
+ get<T = Record<string, unknown>>(...params: SqliteValue[]): T | undefined;
998
+ }
999
+ /**
1000
+ * Sync SQLite client port owned by Emulates.
1001
+ *
1002
+ * Duck-typed so `@emulates/sqlite` `Database`, better-sqlite3, and wrapped
1003
+ * `bun:sqlite` instances all work when they expose this surface.
1004
+ */
1005
+ interface SqliteClient {
1006
+ exec(sql: string): void;
1007
+ prepare(sql: string): SqliteStatement;
1008
+ transaction<T>(fn: () => T): T;
1009
+ }
1010
+
1011
+ declare const statuses: readonly ["created", "running", "paused", "restarting", "removing", "exited", "dead"];
1012
+ type Status = (typeof statuses)[number];
1013
+ type ImageRecord = {
1014
+ id: string;
1015
+ tags: string[];
1016
+ platform?: string;
1017
+ config?: Record<string, unknown>;
1018
+ };
1019
+ type ContainerRecord = {
1020
+ id: string;
1021
+ name: string;
1022
+ image: string;
1023
+ imageId: string;
1024
+ status: Status;
1025
+ created: string;
1026
+ startedAt: string;
1027
+ finishedAt: string;
1028
+ exitCode: number;
1029
+ labels: Record<string, string>;
1030
+ cmd: string[];
1031
+ entrypoint: string[];
1032
+ env: string[];
1033
+ workingDir: string;
1034
+ user: string;
1035
+ hostConfig: Record<string, unknown>;
1036
+ networkSettings: Record<string, unknown>;
1037
+ sizeRw: number;
1038
+ sizeRootFs: number;
1039
+ config?: Record<string, unknown>;
1040
+ termination?: {
1041
+ operation: "stop" | "kill" | "remove";
1042
+ signal: number;
1043
+ timeout?: number;
1044
+ requestedAt: string;
1045
+ };
1046
+ removalPending?: boolean;
1047
+ stdinClosed?: boolean;
1048
+ };
1049
+ type DaemonSettings = {
1050
+ available: boolean;
1051
+ rootless: boolean;
1052
+ };
1053
+ /** Synthetic records only. No host state, images or processes are accessed. */
1054
+ declare class DockerState {
1055
+ private readonly sqlite;
1056
+ private readonly now;
1057
+ readonly images: Collection<ImageRecord>;
1058
+ readonly containers: Collection<ContainerRecord>;
1059
+ private readonly settings;
1060
+ private readonly ids;
1061
+ constructor(sqlite: SqliteClient, namespace: string, now: () => number);
1062
+ create(value: unknown, url: URL): {
1063
+ Id: string;
1064
+ Warnings: string[];
1065
+ };
1066
+ daemon(): DaemonSettings;
1067
+ updateDaemon(value: unknown): DaemonSettings;
1068
+ seed(value: unknown): {
1069
+ images: number;
1070
+ containers: number;
1071
+ };
1072
+ find(id: string): ContainerRecord;
1073
+ }
1074
+
1075
+ /** Persist transitions; keep only live response handles outside shared storage. */
1076
+ declare class DockerLifecycle {
1077
+ private readonly state;
1078
+ private readonly now;
1079
+ private closed;
1080
+ private readonly exits;
1081
+ onExit(listener: (id: string) => void): () => void;
1082
+ private notifyExit;
1083
+ private readonly waiters;
1084
+ constructor(state: DockerState, now: () => number);
1085
+ get pending(): number;
1086
+ start(id: string, url: URL, accepted?: (id: string) => void): Response;
1087
+ terminate(id: string, url: URL, signal: AbortSignal, operation: "stop" | "kill", accepted?: (id: string) => void): Response | Promise<Response>;
1088
+ remove(id: string, url: URL, signal: AbortSignal, accepted?: (id: string) => void): Response | Promise<Response>;
1089
+ private checkOpen;
1090
+ private terminationReply;
1091
+ private notify;
1092
+ complete(id: string, value: unknown): {
1093
+ id: string;
1094
+ exitCode: number;
1095
+ removed: boolean;
1096
+ simulated: boolean;
1097
+ };
1098
+ wait(id: string, url: URL, signal: AbortSignal): Response;
1099
+ close(): void;
1100
+ cancelWaits(): void;
1101
+ }
1102
+
1103
+ /**
1104
+ * The slice of OpenAPI 3.1 (and JSON Schema 2020-12) Emulates understands.
1105
+ * Unknown keys (including `x-*` extensions) are preserved on every object.
1106
+ */
1107
+ type JsonPrimitive = string | number | boolean | null;
1108
+ type JsonValue = JsonPrimitive | JsonValue[] | {
1109
+ [key: string]: JsonValue;
1110
+ };
1111
+ type ReferenceObject = {
1112
+ $ref: string;
1113
+ description?: string;
1114
+ summary?: string;
1115
+ };
1116
+ type SchemaType = "string" | "number" | "integer" | "boolean" | "object" | "array" | "null";
1117
+ type SchemaObject = {
1118
+ $ref?: string;
1119
+ type?: SchemaType | SchemaType[];
1120
+ title?: string;
1121
+ description?: string;
1122
+ format?: string;
1123
+ enum?: JsonValue[];
1124
+ const?: JsonValue;
1125
+ default?: JsonValue;
1126
+ example?: JsonValue;
1127
+ examples?: JsonValue[];
1128
+ nullable?: boolean;
1129
+ deprecated?: boolean;
1130
+ readOnly?: boolean;
1131
+ writeOnly?: boolean;
1132
+ minimum?: number;
1133
+ maximum?: number;
1134
+ exclusiveMinimum?: number;
1135
+ exclusiveMaximum?: number;
1136
+ multipleOf?: number;
1137
+ minLength?: number;
1138
+ maxLength?: number;
1139
+ pattern?: string;
1140
+ minItems?: number;
1141
+ maxItems?: number;
1142
+ uniqueItems?: boolean;
1143
+ items?: SchemaObject;
1144
+ prefixItems?: SchemaObject[];
1145
+ minProperties?: number;
1146
+ maxProperties?: number;
1147
+ required?: string[];
1148
+ properties?: Record<string, SchemaObject>;
1149
+ additionalProperties?: boolean | SchemaObject;
1150
+ propertyNames?: SchemaObject;
1151
+ oneOf?: SchemaObject[];
1152
+ anyOf?: SchemaObject[];
1153
+ allOf?: SchemaObject[];
1154
+ not?: SchemaObject;
1155
+ discriminator?: {
1156
+ propertyName: string;
1157
+ mapping?: Record<string, string>;
1158
+ };
1159
+ [extension: `x-${string}`]: unknown;
1160
+ };
1161
+ type ParameterLocation = "path" | "query" | "header" | "cookie";
1162
+ type ParameterObject = {
1163
+ name: string;
1164
+ in: ParameterLocation;
1165
+ description?: string;
1166
+ required?: boolean;
1167
+ deprecated?: boolean;
1168
+ style?: string;
1169
+ explode?: boolean;
1170
+ schema?: SchemaObject;
1171
+ content?: Record<string, MediaTypeObject>;
1172
+ example?: JsonValue;
1173
+ [extension: `x-${string}`]: unknown;
1174
+ };
1175
+ type MediaTypeObject = {
1176
+ schema?: SchemaObject;
1177
+ example?: JsonValue;
1178
+ examples?: Record<string, unknown>;
1179
+ encoding?: Record<string, unknown>;
1180
+ [extension: `x-${string}`]: unknown;
1181
+ };
1182
+ type RequestBodyObject = {
1183
+ description?: string;
1184
+ required?: boolean;
1185
+ content: Record<string, MediaTypeObject>;
1186
+ [extension: `x-${string}`]: unknown;
1187
+ };
1188
+ type HeaderObject = {
1189
+ description?: string;
1190
+ required?: boolean;
1191
+ schema?: SchemaObject;
1192
+ [extension: `x-${string}`]: unknown;
1193
+ };
1194
+ type ResponseObject = {
1195
+ description: string;
1196
+ headers?: Record<string, HeaderObject | ReferenceObject>;
1197
+ content?: Record<string, MediaTypeObject>;
1198
+ [extension: `x-${string}`]: unknown;
1199
+ };
1200
+ type ResponsesObject = Record<string, ResponseObject | ReferenceObject>;
1201
+ type SecurityRequirementObject = Record<string, string[]>;
1202
+ type OperationObject = {
1203
+ operationId?: string;
1204
+ summary?: string;
1205
+ description?: string;
1206
+ tags?: string[];
1207
+ deprecated?: boolean;
1208
+ parameters?: Array<ParameterObject | ReferenceObject>;
1209
+ requestBody?: RequestBodyObject | ReferenceObject;
1210
+ responses: ResponsesObject;
1211
+ security?: SecurityRequirementObject[];
1212
+ [extension: `x-${string}`]: unknown;
1213
+ };
1214
+ declare const HTTP_METHODS: readonly ["get", "put", "post", "delete", "options", "head", "patch", "trace"];
1215
+ type HttpMethod = (typeof HTTP_METHODS)[number];
1216
+ type PathItemObject = {
1217
+ summary?: string;
1218
+ description?: string;
1219
+ parameters?: Array<ParameterObject | ReferenceObject>;
1220
+ [extension: `x-${string}`]: unknown;
1221
+ } & Partial<Record<HttpMethod, OperationObject>>;
1222
+ type SecuritySchemeObject = {
1223
+ type: "apiKey" | "http" | "oauth2" | "openIdConnect" | "mutualTLS";
1224
+ description?: string;
1225
+ name?: string;
1226
+ in?: ParameterLocation;
1227
+ scheme?: string;
1228
+ bearerFormat?: string;
1229
+ flows?: Record<string, unknown>;
1230
+ openIdConnectUrl?: string;
1231
+ [extension: `x-${string}`]: unknown;
1232
+ };
1233
+ type ComponentsObject = {
1234
+ schemas?: Record<string, SchemaObject>;
1235
+ responses?: Record<string, ResponseObject>;
1236
+ parameters?: Record<string, ParameterObject>;
1237
+ requestBodies?: Record<string, RequestBodyObject>;
1238
+ headers?: Record<string, HeaderObject>;
1239
+ securitySchemes?: Record<string, SecuritySchemeObject>;
1240
+ [extension: `x-${string}`]: unknown;
1241
+ };
1242
+ type ServerObject = {
1243
+ url: string;
1244
+ description?: string;
1245
+ variables?: Record<string, unknown>;
1246
+ [extension: `x-${string}`]: unknown;
1247
+ };
1248
+ type InfoObject = {
1249
+ title: string;
1250
+ version: string;
1251
+ description?: string;
1252
+ [extension: `x-${string}`]: unknown;
1253
+ };
1254
+ type OpenAPIDocument = {
1255
+ openapi: string;
1256
+ info: InfoObject;
1257
+ servers?: ServerObject[];
1258
+ paths: Record<string, PathItemObject>;
1259
+ components?: ComponentsObject;
1260
+ security?: SecurityRequirementObject[];
1261
+ tags?: Array<{
1262
+ name: string;
1263
+ description?: string;
1264
+ }>;
1265
+ [extension: `x-${string}`]: unknown;
1266
+ };
1267
+
1268
+ declare const document: OpenAPIDocument;
1269
+ type OperationId = "ContainerList" | "ContainerCreate" | "ContainerInspect" | "ContainerStart" | "ContainerStop" | "ContainerKill" | "ContainerAttach" | "ContainerWait" | "ContainerDelete" | "SystemInfo" | "SystemVersion" | "SystemPing" | "SystemPingHead";
1270
+ type SupportedOperationId = "ContainerList" | "ContainerCreate" | "ContainerInspect" | "ContainerStart" | "ContainerStop" | "ContainerKill" | "ContainerWait" | "ContainerDelete" | "SystemInfo" | "SystemVersion" | "SystemPing" | "SystemPingHead";
1271
+ declare const operationIds: readonly ["ContainerList", "ContainerCreate", "ContainerInspect", "ContainerStart", "ContainerStop", "ContainerKill", "ContainerAttach", "ContainerWait", "ContainerDelete", "SystemInfo", "SystemVersion", "SystemPing", "SystemPingHead"];
1272
+ declare const supportedOperationIds: readonly ["ContainerList", "ContainerCreate", "ContainerInspect", "ContainerStart", "ContainerStop", "ContainerKill", "ContainerWait", "ContainerDelete", "SystemInfo", "SystemVersion", "SystemPing", "SystemPingHead"];
1273
+
1274
+ type DockerRuntimeOptions = Pick<RuntimeOptions<DockerAPI>, "sqlite" | "clock" | "seed" | "adminKey" | "onLog" | "journalSize" | "maxCheckpoints"> & Pick<DockerAPIOptions, "onAttach">;
1275
+ type DockerRuntime = ServiceRuntime<DockerAPI> & {
1276
+ close(): void;
1277
+ };
1278
+ /** Standard controls and Timeline coordination; no provider-local history. */
1279
+ declare const createRuntime: (options?: DockerRuntimeOptions) => DockerRuntime;
1280
+
1281
+ declare const DOCKER_NAMESPACE = "docker";
1282
+ type DockerAPIOptions = APIOptions & {
1283
+ /** Transport-owned admission callback; ordinary Fetch attach remains unsupported. */
1284
+ onAttach?: (api: DockerAPI, request: Request) => Response;
1285
+ };
1286
+ declare class DockerAPI implements FetchAPI$1 {
1287
+ readonly app: Hono;
1288
+ readonly sqlite: SqliteClient;
1289
+ readonly namespace: string;
1290
+ readonly state: DockerState;
1291
+ readonly lifecycle: DockerLifecycle;
1292
+ private closed;
1293
+ private readonly invalidators;
1294
+ private epoch;
1295
+ get generation(): number;
1296
+ onInvalidate(listener: () => void): () => void;
1297
+ cancelTransient(): void;
1298
+ private readonly service;
1299
+ constructor(options?: DockerAPIOptions);
1300
+ fetch(request: Request): Promise<Response>;
1301
+ close(): void;
1302
+ reset(): Promise<void>;
1303
+ }
1304
+
1305
+ export { DOCKER_NAMESPACE, DockerAPI, createRuntime, document, operationIds, supportedOperationIds };
1306
+ export type { DockerAPIOptions, DockerRuntime, DockerRuntimeOptions, OperationId, SupportedOperationId };