@emulates/cloudcontrol 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,899 @@
1
+ /** Bind values accepted by the Emulates SQLite port (matches sqlite-mem / better-sqlite3). */
2
+ type SqliteValue$1 = null | number | bigint | string | Uint8Array | boolean;
3
+ /** Mutation counters returned by {@link SqliteStatement.run}. */
4
+ type SqliteRunResult$1 = {
5
+ changes: number;
6
+ lastInsertRowid: number | bigint;
7
+ };
8
+ /**
9
+ * Prepared statement bound to a {@link SqliteClient}.
10
+ *
11
+ * Pass bind values as rest arguments on each call (no sticky `bind()`).
12
+ */
13
+ interface SqliteStatement$1 {
14
+ run(...params: SqliteValue$1[]): SqliteRunResult$1;
15
+ all<T = Record<string, unknown>>(...params: SqliteValue$1[]): T[];
16
+ get<T = Record<string, unknown>>(...params: SqliteValue$1[]): T | undefined;
17
+ }
18
+ /**
19
+ * Sync SQLite client port owned by Emulates.
20
+ *
21
+ * Duck-typed so `@emulates/sqlite` `Database`, better-sqlite3, and wrapped
22
+ * `bun:sqlite` instances all work when they expose this surface.
23
+ */
24
+ interface SqliteClient$1 {
25
+ exec(sql: string): void;
26
+ prepare(sql: string): SqliteStatement$1;
27
+ transaction<T>(fn: () => T): T;
28
+ }
29
+
30
+ /** Every stored record carries a monotonically increasing sequence for stable ordering. */
31
+ type Stored<T> = {
32
+ seq: number;
33
+ value: T;
34
+ };
35
+ type ListRecordsOptions<T> = {
36
+ /** Keep only records passing the predicate. */
37
+ where?: (value: T, seq: number) => boolean;
38
+ /** Sort order; default newest first. */
39
+ order?: "newest" | "oldest";
40
+ };
41
+ /**
42
+ * A SQLite-backed table of JSON records addressed by id. Ordering is by insertion
43
+ * sequence, never by id lexicographic order, so list semantics stay stable.
44
+ */
45
+ declare class Collection<T> {
46
+ private readonly sqlite;
47
+ /** Storage namespace. Admin introspection uses this to ignore another namespace's tables. */
48
+ readonly namespace: string;
49
+ /** Table name inside the namespace. Stable across resets of the rows themselves. */
50
+ readonly collectionName: string;
51
+ constructor(sqlite: SqliteClient$1,
52
+ /** Storage namespace. Admin introspection uses this to ignore another namespace's tables. */
53
+ namespace: string,
54
+ /** Table name inside the namespace. Stable across resets of the rows themselves. */
55
+ collectionName: string);
56
+ private bumpCollectionSeq;
57
+ nextSequence(): number;
58
+ get(id: string): T | undefined;
59
+ has(id: string): boolean;
60
+ /** Insert a new record, assigning it the next sequence number. */
61
+ insert(id: string, value: T): Stored<T>;
62
+ /** Replace an existing record's value, keeping its position. */
63
+ update(id: string, value: T): Stored<T> | undefined;
64
+ delete(id: string): boolean;
65
+ /** How many records the collection holds, without reading them. */
66
+ count(): number;
67
+ list(options?: ListRecordsOptions<T>): Array<Stored<T> & {
68
+ id: string;
69
+ }>;
70
+ }
71
+
72
+ /**
73
+ * Sequential id source persisted in SQLite. Ids are deterministic for a given
74
+ * sequence history (`cus_` + 14 opaque chars), so reproductions stay stable.
75
+ */
76
+ declare class IdSequence {
77
+ private readonly sqlite;
78
+ private readonly namespace;
79
+ private readonly salt;
80
+ constructor(sqlite: SqliteClient$1, namespace: string, salt?: string);
81
+ next(prefix: string, length?: number): string;
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
+ /** Options every provider constructor accepts. */
175
+ type APIOptions$1 = {
176
+ /** Sync SQLite client. Defaults to `@emulates/sqlite`. */
177
+ sqlite?: SqliteClient$1;
178
+ /** Clock used for `created`-style fields. Default `Date.now`. */
179
+ now?: () => number;
180
+ /**
181
+ * Storage namespace for this instance's records. Instances sharing one SQLite
182
+ * client stay isolated when their namespaces differ. Defaults to the service name.
183
+ */
184
+ namespace?: string;
185
+ };
186
+
187
+ type AwsInput = Record<string, unknown>;
188
+ type AwsProtocolOptions = APIOptions$1 & {
189
+ region?: string;
190
+ accountId?: string;
191
+ };
192
+ type AwsOperation = {
193
+ operation: string;
194
+ input: AwsInput;
195
+ request: Request;
196
+ url: URL;
197
+ };
198
+ /** Fetch-native AWS wire transport. Service subclasses own operations and persisted state. */
199
+ declare abstract class AwsProtocolAPI {
200
+ readonly service: string;
201
+ readonly sqlite: SqliteClient$1;
202
+ readonly namespace: string;
203
+ readonly now: () => number;
204
+ readonly region: string;
205
+ readonly accountId: string;
206
+ readonly ids: IdSequence;
207
+ private readonly collections;
208
+ constructor(service: string, options?: AwsProtocolOptions);
209
+ collection(name: string): Collection<AwsInput>;
210
+ arn(type: string, name: string, service?: string): string;
211
+ reset(): Promise<void>;
212
+ abstract dispatch(context: AwsOperation): unknown | Promise<unknown>;
213
+ route(_method: string, _pathname: string): {
214
+ operation: string;
215
+ params: AwsInput;
216
+ } | undefined;
217
+ fetch(request: Request): Promise<Response>;
218
+ unsupported(operation: string): never;
219
+ get(collection: string, id: string, code?: string): AwsInput;
220
+ }
221
+
222
+ /**
223
+ * The single source of time for a service.
224
+ *
225
+ * Every timestamp a mock writes reads from here, so a suite moves time instead of
226
+ * sleeping: appointment windows, result delays and expiries become reachable in
227
+ * milliseconds. A frozen clock also makes timestamps reproducible from a seed.
228
+ */
229
+ type ClockState = {
230
+ /** Current epoch milliseconds. */
231
+ now: number;
232
+ /** True while time does not advance on its own. */
233
+ frozen: boolean;
234
+ /** Milliseconds this clock adds to its underlying source. */
235
+ offsetMs: number;
236
+ };
237
+ type Clock = {
238
+ now(): number;
239
+ /** Pin the clock to an exact instant, keeping it frozen if it already was. */
240
+ set(epochMs: number): void;
241
+ /** Move the clock forward, or back with a negative delta. */
242
+ advance(deltaMs: number): void;
243
+ /** Stop time at the current instant. */
244
+ freeze(): void;
245
+ /** Resume from the current instant. */
246
+ unfreeze(): void;
247
+ /** Drop back to the underlying source, live. */
248
+ reset(): void;
249
+ state(): ClockState;
250
+ };
251
+
252
+ /**
253
+ * Seeded pseudo-random numbers, so anything a mock invents — ids, jitter, which
254
+ * request a percentage fault hits — is reproducible from a seed.
255
+ *
256
+ * mulberry32: small, fast, and stable across runtimes, which matters more here
257
+ * than statistical quality.
258
+ */
259
+ type Rng = {
260
+ /** Next value in `[0, 1)`. */
261
+ next(): number;
262
+ /** Next integer in `[min, max]`. */
263
+ int(min: number, max: number): number;
264
+ /** Restart the stream from its seed. */
265
+ reset(): void;
266
+ /** Serializable engine state used by deterministic checkpoints. */
267
+ state(): number;
268
+ /** Restore a state previously returned by {@link state}. */
269
+ setState(state: number): void;
270
+ seed: number;
271
+ };
272
+
273
+ /**
274
+ * A deliberate failure injected in front of an operation.
275
+ *
276
+ * This is how a suite reaches the vendor's failure modes without the vendor: the
277
+ * quota error that only appears when a shared sandbox is full, the 429 that only
278
+ * appears under load, the 5xx that proves a retry path works.
279
+ */
280
+ type FaultRule = {
281
+ /** Stable id, so a suite can retire exactly the rule it added. */
282
+ id: string;
283
+ /** Fault only this operation. Omit to match every operation. */
284
+ operationId?: string;
285
+ /** Fault only this HTTP method, case-insensitive. Omit to match every method. */
286
+ method?: string;
287
+ /** Fault only paths starting with this prefix. Omit to match every path. */
288
+ pathPrefix?: string;
289
+ /**
290
+ * Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
291
+ * an in-process caller usually wants, and what a parallel worker usually does not:
292
+ * rules added through `POST /__admin/faults` default to the calling namespace.
293
+ */
294
+ namespace?: string;
295
+ /**
296
+ * Status of the injected response. Omit for a rule that only delays (`delayMs` /
297
+ * `latencyMs`), only drops the connection (`drop`), or only switches on an `effect`:
298
+ * the request then still reaches the service.
299
+ */
300
+ status?: number;
301
+ /** Response body, serialized as JSON. A string is sent as-is. */
302
+ body?: unknown;
303
+ headers?: Record<string, string>;
304
+ /** Retire the rule after this many faults. Omit to keep it until removed. */
305
+ count?: number;
306
+ /** Fault this fraction of matching requests, `0`–`1`. Default `1`. */
307
+ rate?: number;
308
+ /** Hold the response back this long, to exercise timeouts. */
309
+ delayMs?: number;
310
+ /** Alias of `delayMs`. */
311
+ latencyMs?: number;
312
+ /**
313
+ * Drop the connection instead of answering: an in-process `fetch` rejects with a
314
+ * `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
315
+ */
316
+ drop?: boolean;
317
+ /**
318
+ * A named service behaviour to switch on for the matching request instead of (or
319
+ * before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
320
+ * read it with `faultEffects(request)`.
321
+ */
322
+ effect?: string;
323
+ /** Parameters for `effect`. */
324
+ params?: Record<string, unknown>;
325
+ /** From the preset this rule was expanded from, if any. */
326
+ preset?: string;
327
+ };
328
+ /** A fault that fired for one request. */
329
+ type FaultHit = {
330
+ id: string;
331
+ /** The injected response; absent when the rule only delays, drops, or sets an effect. */
332
+ response?: Response;
333
+ drop?: boolean;
334
+ effect?: {
335
+ name: string;
336
+ params: Record<string, unknown>;
337
+ };
338
+ };
339
+ /** What a request looks like to the fault matcher. */
340
+ type FaultCandidate = {
341
+ operationId: string | undefined;
342
+ method: string;
343
+ path: string;
344
+ namespace: string;
345
+ };
346
+ type FaultRegistry = {
347
+ isolateNamespaces(): void;
348
+ snapshot(namespace: string): {
349
+ rules: (FaultRule & {
350
+ remaining: number | null;
351
+ hits: number;
352
+ position: number;
353
+ })[];
354
+ rngState: number;
355
+ };
356
+ add(rule: FaultRule): FaultRule;
357
+ list(): (FaultRule & {
358
+ remaining: number | null;
359
+ hits: number;
360
+ })[];
361
+ remove(id: string): boolean;
362
+ clear(): void;
363
+ restore(namespace: string, state: {
364
+ rules: (FaultRule & {
365
+ remaining: number | null;
366
+ hits: number;
367
+ position: number;
368
+ })[];
369
+ rngState: number;
370
+ }): void;
371
+ /**
372
+ * Every fault this request should get, in rule order, stopping at the first that answers
373
+ * or drops (effect-only and delay-only rules let later rules match too). Consumes one of
374
+ * each matching rule's remaining uses.
375
+ */
376
+ take(candidate: FaultCandidate): Promise<FaultHit[]>;
377
+ };
378
+
379
+ /**
380
+ * One problem with a request body, at a dotted path (`patient.address.city`, `items.0.sku`).
381
+ * `kind` is `media_type` when the body is present but its media type is not one the operation
382
+ * accepts (a `415` on most vendors), `syntax` when it could not be decoded, `required` when
383
+ * the operation needs a body and none arrived, and `schema` for a contract violation.
384
+ */
385
+ type BodyIssue = {
386
+ path: string;
387
+ message: string;
388
+ kind?: "media_type" | "syntax" | "required" | "schema";
389
+ };
390
+
391
+ /**
392
+ * What the mock received from a request it rejected, so a 4xx can be attributed after the
393
+ * fact (an empty body, a missing `content-type`, a schema violation) without logging the body.
394
+ */
395
+ type RejectedRequest = {
396
+ /** The raw `content-type` header, or `null` when the request sent none. */
397
+ contentType: string | null;
398
+ /** Bytes of body received from `content-length` (`0` for none), or `null` when the client sent no length (a streamed / chunked body). */
399
+ bodyBytes: number | null;
400
+ /** The raw `transfer-encoding` header (`chunked`), or `null`. */
401
+ transferEncoding: string | null;
402
+ };
403
+ /** One handled request, as the structured log sees it. */
404
+ type RequestLog = {
405
+ service: string;
406
+ namespace: string;
407
+ operationId: string | undefined;
408
+ method: string;
409
+ path: string;
410
+ status: number;
411
+ durationMs: number;
412
+ /** True when the path matched no operation in the contract. */
413
+ unmatched: boolean;
414
+ /** Set when a fault rule produced the response. */
415
+ faultId?: string;
416
+ /** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
417
+ ids?: Record<string, string>;
418
+ /** Set when the service created a resource the request referred to but that did not exist. */
419
+ adopted?: boolean;
420
+ /** Explicit durable acceptance, independent of response delivery. */
421
+ accepted?: boolean;
422
+ /** Checkpoint captured at explicit acceptance. */
423
+ checkpoint?: string;
424
+ /** Set on a rejection (status ≥ 400) the mock produced itself, never on a scripted fault. */
425
+ request?: RejectedRequest;
426
+ /** The validation issues behind a rejection, when the service found any. */
427
+ issues?: BodyIssue[];
428
+ };
429
+ type MetricsReport = {
430
+ requests: number;
431
+ /** Counts keyed `<operationId> <status>`. */
432
+ byOperation: Record<string, number>;
433
+ /**
434
+ * Paths that matched no operation, most frequent first.
435
+ *
436
+ * This is the early-warning signal: a consumer calling something the mock does
437
+ * not implement shows up here as a count, before it fails a suite as a 404.
438
+ */
439
+ unmatched: {
440
+ method: string;
441
+ path: string;
442
+ count: number;
443
+ }[];
444
+ faults: number;
445
+ totalDurationMs: number;
446
+ };
447
+ type Metrics = {
448
+ record(entry: RequestLog): void;
449
+ report(namespace?: string): MetricsReport;
450
+ reset(namespace?: string): void;
451
+ };
452
+
453
+ /** One journal entry: a request log stamped with when (on the mock clock) it was handled. */
454
+ type JournalEntry = RequestLog & {
455
+ at: string;
456
+ };
457
+ type JournalQuery = {
458
+ /** Only this namespace. Omit for every namespace, oldest first across all of them. */
459
+ namespace?: string;
460
+ operationId?: string;
461
+ status?: number;
462
+ /** Only entries at or after this instant (epoch ms). */
463
+ since?: number;
464
+ /** At most this many, the most recent kept. */
465
+ limit?: number;
466
+ };
467
+ type Journal = {
468
+ readonly size: number;
469
+ record(entry: JournalEntry): void;
470
+ list(query?: JournalQuery): JournalEntry[];
471
+ /** Forget one namespace's entries, or every namespace's. */
472
+ clear(namespace?: string): void;
473
+ };
474
+
475
+ /** Credential → namespace mapping behind `PUT /__admin/credentials`. */
476
+ type CredentialRegistry = {
477
+ set(credential: string, namespace: string): void;
478
+ get(credential: string): string | undefined;
479
+ remove(credential: string): boolean;
480
+ clear(): void;
481
+ entries(): {
482
+ credential: string;
483
+ namespace: string;
484
+ }[];
485
+ };
486
+
487
+ /**
488
+ * A point-in-time copy of everything a service namespace holds.
489
+ *
490
+ * All service state lives in the two core tables keyed by namespace, so a snapshot
491
+ * is generic: any service gets per-test rollback without knowing its own schema.
492
+ * Restoring is much cheaper than rebuilding a namespace from a corpus.
493
+ */
494
+ type NamespaceSnapshot = {
495
+ namespace: string;
496
+ records: {
497
+ collection: string;
498
+ id: string;
499
+ seq: number;
500
+ value: string;
501
+ }[];
502
+ sequences: {
503
+ name: string;
504
+ kind: string;
505
+ value: number;
506
+ }[];
507
+ };
508
+
509
+ declare const STATE_FIELD_KINDS: readonly ["string", "number", "boolean", "null", "object", "array", "unknown"];
510
+ type StateFieldKind = (typeof STATE_FIELD_KINDS)[number];
511
+ /** JSON-safe annotations a bespoke admin UI may read. The default UI shows them as text. */
512
+ type StateMeta = Readonly<Record<string, string | number | boolean | null>>;
513
+ type StateField = {
514
+ name: string;
515
+ kind: StateFieldKind;
516
+ optional: boolean;
517
+ description?: string;
518
+ /** One level of nested object fields. */
519
+ fields?: StateField[];
520
+ meta?: StateMeta;
521
+ };
522
+ type StateCollectionView = {
523
+ name: string;
524
+ label: string;
525
+ description?: string;
526
+ count: number;
527
+ /** `mixed` when a declaration and stored rows both contribute fields. */
528
+ source: "declared" | "inferred" | "mixed";
529
+ fields: StateField[];
530
+ meta?: StateMeta;
531
+ };
532
+ /** The shape of one namespace, for an admin UI that has never seen the service before. */
533
+ type StateView = {
534
+ namespace: string;
535
+ storageNamespace: string;
536
+ collections: StateCollectionView[];
537
+ };
538
+
539
+ type WebhookEndpoint = {
540
+ /** Stable id; generated when omitted. */
541
+ id?: string;
542
+ url: string;
543
+ secret?: string;
544
+ /** Event types to deliver; omit or include `"*"` for every type. */
545
+ events?: string[];
546
+ /** Deliver only messages whose tags include all of these (e.g. `{ account: "mso" }`). */
547
+ tags?: Record<string, string>;
548
+ /** The public URL the receiver verifies signatures against (Twilio), when it differs. */
549
+ signUrl?: string;
550
+ headers?: Record<string, string>;
551
+ };
552
+ type WebhookMessage = {
553
+ id: string;
554
+ namespace: string;
555
+ type: string;
556
+ body: string;
557
+ contentType: string;
558
+ tags: Record<string, string>;
559
+ headers?: Record<string, string>;
560
+ /** Wall-clock ISO-8601 time of publication. */
561
+ publishedAt: string;
562
+ };
563
+ type WebhookAttempt = {
564
+ attempt: number;
565
+ at: string;
566
+ status: number | null;
567
+ error: string | null;
568
+ durationMs: number;
569
+ /** Exact receiver response body, when one was returned. */
570
+ responseBody?: string | null;
571
+ };
572
+ type WebhookDelivery = {
573
+ id: string;
574
+ messageId: string;
575
+ namespace: string;
576
+ type: string;
577
+ endpointId: string;
578
+ url: string;
579
+ state: "pending" | "delivered" | "failed" | "dropped";
580
+ attempts: WebhookAttempt[];
581
+ };
582
+ /** A delivery-level fault: what happens to the next `count` messages in a namespace. */
583
+ type WebhookFault = {
584
+ mode: "duplicate" | "reorder" | "drop";
585
+ /** Messages affected; default 1. */
586
+ count?: number;
587
+ };
588
+ type PublishInput = {
589
+ namespace: string;
590
+ type: string;
591
+ /** Exact body; objects are JSON-encoded. */
592
+ body: string | Record<string, unknown> | unknown[];
593
+ /** Default `application/json`, or form-encoded when `form` is given. */
594
+ contentType?: string;
595
+ /** Form parameters, when the vendor posts `application/x-www-form-urlencoded`. */
596
+ form?: Record<string, string>;
597
+ tags?: Record<string, string>;
598
+ /** Message-specific delivery headers, captured as part of durable message state. */
599
+ headers?: Record<string, string>;
600
+ /** Message id; generated when omitted. */
601
+ id?: string;
602
+ };
603
+ type WebhookHub = {
604
+ pending(namespace: string): number;
605
+ snapshot(namespace: string): unknown;
606
+ restore(namespace: string, snapshot: unknown): void;
607
+ publish(input: PublishInput): WebhookMessage;
608
+ /** Replace a namespace's own endpoints (`PUT /__admin/webhook-endpoints`). */
609
+ setEndpoints(namespace: string, endpoints: WebhookEndpoint[]): WebhookEndpoint[];
610
+ /** The endpoints a namespace delivers to: its own, plus the global ones. */
611
+ endpoints(namespace: string): WebhookEndpoint[];
612
+ messages(namespace?: string): WebhookMessage[];
613
+ deliveries(namespace?: string): WebhookDelivery[];
614
+ replay(deliveryId: string): Promise<WebhookDelivery | undefined>;
615
+ /** Run every pending retry (and release held reordered messages) now, and every retry those attempts schedule, until nothing is pending. */
616
+ flush(): Promise<void>;
617
+ /** Resolve once nothing is in flight. */
618
+ idle(): Promise<void>;
619
+ fault(namespace: string, fault: WebhookFault): void;
620
+ clear(namespace?: string): void;
621
+ };
622
+
623
+ /** What the runtime needs from a service: a Fetch handler it can reset. */
624
+ type ServiceInstance = FetchAPI & {
625
+ reset(): Promise<void>;
626
+ };
627
+ type ServiceTimelineState = Readonly<{
628
+ snapshot: NamespaceSnapshot;
629
+ clock: Readonly<ReturnType<Clock["state"]>>;
630
+ rngState: number;
631
+ }>;
632
+ type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
633
+ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
634
+ /** Stop package-owned lifecycle timers when a supervisor closes the runtime. */
635
+ stop?(): void;
636
+ readonly name: string;
637
+ readonly sqlite: SqliteClient$1;
638
+ readonly clock: Clock;
639
+ readonly faults: FaultRegistry;
640
+ readonly metrics: Metrics;
641
+ readonly journal: Journal;
642
+ readonly rng: Rng;
643
+ readonly credentials: CredentialRegistry;
644
+ /** The webhook hub, when the service has outbound webhooks. */
645
+ readonly webhooks: WebhookHub | undefined;
646
+ /** Enable independent namespace clocks and PRNGs before serving a fleet. */
647
+ isolateNamespaces(): void;
648
+ namespaceClock(namespace?: string): Clock;
649
+ namespaceOf(request: Request): string;
650
+ /** Opaque in-process checkpoint including records, controls and webhook history. */
651
+ fleetSnapshot(namespace: string): object;
652
+ fleetRestore(snapshot: unknown, namespace: string): void;
653
+ /** Expand a named preset into fault rules (and webhook faults) for `namespace`. */
654
+ applyPreset(name: string, namespace?: string, overrides?: Partial<FaultRule>): FaultRule[];
655
+ /** The instance behind `namespace` (the default one when omitted), created on first use. */
656
+ instance(namespace?: string): T;
657
+ /** Public names of every namespace created so far. */
658
+ namespaces(): string[];
659
+ /** Reset one namespace, or every namespace with `"*"`. */
660
+ reset(namespace?: string): Promise<void>;
661
+ snapshot(namespace?: string): NamespaceSnapshot;
662
+ restore(snapshot: NamespaceSnapshot, namespace?: string): void;
663
+ /** Capture the current branch. Mutating HTTP calls do this automatically. */
664
+ checkpoint(namespace?: string, branch?: string): ServiceCheckpoint;
665
+ /** Create an isolated branch, optionally from a historical checkpoint. */
666
+ branch(name: string, options?: {
667
+ namespace?: string;
668
+ at?: string;
669
+ }): ServiceCheckpoint;
670
+ /** Restore a branch, clock, and PRNG to a checkpoint. */
671
+ checkout(checkpoint: string, options?: {
672
+ namespace?: string;
673
+ branch?: string;
674
+ }): void;
675
+ /** Inspect the retained history for a namespace. */
676
+ timeline(namespace?: string): Timeline<ServiceTimelineState>;
677
+ /** Collections in one namespace: declared shape plus what the rows actually hold. */
678
+ state(namespace?: string): StateView;
679
+ };
680
+
681
+ /**
682
+ * The slice of OpenAPI 3.1 (and JSON Schema 2020-12) Emulates understands.
683
+ * Unknown keys (including `x-*` extensions) are preserved on every object.
684
+ */
685
+ type JsonPrimitive = string | number | boolean | null;
686
+ type JsonValue = JsonPrimitive | JsonValue[] | {
687
+ [key: string]: JsonValue;
688
+ };
689
+ type ReferenceObject = {
690
+ $ref: string;
691
+ description?: string;
692
+ summary?: string;
693
+ };
694
+ type SchemaType = "string" | "number" | "integer" | "boolean" | "object" | "array" | "null";
695
+ type SchemaObject = {
696
+ $ref?: string;
697
+ type?: SchemaType | SchemaType[];
698
+ title?: string;
699
+ description?: string;
700
+ format?: string;
701
+ enum?: JsonValue[];
702
+ const?: JsonValue;
703
+ default?: JsonValue;
704
+ example?: JsonValue;
705
+ examples?: JsonValue[];
706
+ nullable?: boolean;
707
+ deprecated?: boolean;
708
+ readOnly?: boolean;
709
+ writeOnly?: boolean;
710
+ minimum?: number;
711
+ maximum?: number;
712
+ exclusiveMinimum?: number;
713
+ exclusiveMaximum?: number;
714
+ multipleOf?: number;
715
+ minLength?: number;
716
+ maxLength?: number;
717
+ pattern?: string;
718
+ minItems?: number;
719
+ maxItems?: number;
720
+ uniqueItems?: boolean;
721
+ items?: SchemaObject;
722
+ prefixItems?: SchemaObject[];
723
+ minProperties?: number;
724
+ maxProperties?: number;
725
+ required?: string[];
726
+ properties?: Record<string, SchemaObject>;
727
+ additionalProperties?: boolean | SchemaObject;
728
+ propertyNames?: SchemaObject;
729
+ oneOf?: SchemaObject[];
730
+ anyOf?: SchemaObject[];
731
+ allOf?: SchemaObject[];
732
+ not?: SchemaObject;
733
+ discriminator?: {
734
+ propertyName: string;
735
+ mapping?: Record<string, string>;
736
+ };
737
+ [extension: `x-${string}`]: unknown;
738
+ };
739
+ type ParameterLocation = "path" | "query" | "header" | "cookie";
740
+ type ParameterObject = {
741
+ name: string;
742
+ in: ParameterLocation;
743
+ description?: string;
744
+ required?: boolean;
745
+ deprecated?: boolean;
746
+ style?: string;
747
+ explode?: boolean;
748
+ schema?: SchemaObject;
749
+ content?: Record<string, MediaTypeObject>;
750
+ example?: JsonValue;
751
+ [extension: `x-${string}`]: unknown;
752
+ };
753
+ type MediaTypeObject = {
754
+ schema?: SchemaObject;
755
+ example?: JsonValue;
756
+ examples?: Record<string, unknown>;
757
+ encoding?: Record<string, unknown>;
758
+ [extension: `x-${string}`]: unknown;
759
+ };
760
+ type RequestBodyObject = {
761
+ description?: string;
762
+ required?: boolean;
763
+ content: Record<string, MediaTypeObject>;
764
+ [extension: `x-${string}`]: unknown;
765
+ };
766
+ type HeaderObject = {
767
+ description?: string;
768
+ required?: boolean;
769
+ schema?: SchemaObject;
770
+ [extension: `x-${string}`]: unknown;
771
+ };
772
+ type ResponseObject = {
773
+ description: string;
774
+ headers?: Record<string, HeaderObject | ReferenceObject>;
775
+ content?: Record<string, MediaTypeObject>;
776
+ [extension: `x-${string}`]: unknown;
777
+ };
778
+ type ResponsesObject = Record<string, ResponseObject | ReferenceObject>;
779
+ type SecurityRequirementObject = Record<string, string[]>;
780
+ type OperationObject = {
781
+ operationId?: string;
782
+ summary?: string;
783
+ description?: string;
784
+ tags?: string[];
785
+ deprecated?: boolean;
786
+ parameters?: Array<ParameterObject | ReferenceObject>;
787
+ requestBody?: RequestBodyObject | ReferenceObject;
788
+ responses: ResponsesObject;
789
+ security?: SecurityRequirementObject[];
790
+ [extension: `x-${string}`]: unknown;
791
+ };
792
+ declare const HTTP_METHODS: readonly ["get", "put", "post", "delete", "options", "head", "patch", "trace"];
793
+ type HttpMethod = (typeof HTTP_METHODS)[number];
794
+ type PathItemObject = {
795
+ summary?: string;
796
+ description?: string;
797
+ parameters?: Array<ParameterObject | ReferenceObject>;
798
+ [extension: `x-${string}`]: unknown;
799
+ } & Partial<Record<HttpMethod, OperationObject>>;
800
+ type SecuritySchemeObject = {
801
+ type: "apiKey" | "http" | "oauth2" | "openIdConnect" | "mutualTLS";
802
+ description?: string;
803
+ name?: string;
804
+ in?: ParameterLocation;
805
+ scheme?: string;
806
+ bearerFormat?: string;
807
+ flows?: Record<string, unknown>;
808
+ openIdConnectUrl?: string;
809
+ [extension: `x-${string}`]: unknown;
810
+ };
811
+ type ComponentsObject = {
812
+ schemas?: Record<string, SchemaObject>;
813
+ responses?: Record<string, ResponseObject>;
814
+ parameters?: Record<string, ParameterObject>;
815
+ requestBodies?: Record<string, RequestBodyObject>;
816
+ headers?: Record<string, HeaderObject>;
817
+ securitySchemes?: Record<string, SecuritySchemeObject>;
818
+ [extension: `x-${string}`]: unknown;
819
+ };
820
+ type ServerObject = {
821
+ url: string;
822
+ description?: string;
823
+ variables?: Record<string, unknown>;
824
+ [extension: `x-${string}`]: unknown;
825
+ };
826
+ type InfoObject = {
827
+ title: string;
828
+ version: string;
829
+ description?: string;
830
+ [extension: `x-${string}`]: unknown;
831
+ };
832
+ type OpenAPIDocument = {
833
+ openapi: string;
834
+ info: InfoObject;
835
+ servers?: ServerObject[];
836
+ paths: Record<string, PathItemObject>;
837
+ components?: ComponentsObject;
838
+ security?: SecurityRequirementObject[];
839
+ tags?: Array<{
840
+ name: string;
841
+ description?: string;
842
+ }>;
843
+ [extension: `x-${string}`]: unknown;
844
+ };
845
+
846
+ declare const document: OpenAPIDocument;
847
+ declare const operationIds: readonly ["AwsQuery", "AwsRpc", "AwsRestGet", "AwsRestPut", "AwsRestPost", "AwsRestDelete", "AwsRestPatch"];
848
+ declare const supportedOperationIds: readonly [];
849
+
850
+ /** Bind values accepted by the Emulates SQLite port (matches sqlite-mem / better-sqlite3). */
851
+ type SqliteValue = null | number | bigint | string | Uint8Array | boolean;
852
+ /** Mutation counters returned by {@link SqliteStatement.run}. */
853
+ type SqliteRunResult = {
854
+ changes: number;
855
+ lastInsertRowid: number | bigint;
856
+ };
857
+ /**
858
+ * Prepared statement bound to a {@link SqliteClient}.
859
+ *
860
+ * Pass bind values as rest arguments on each call (no sticky `bind()`).
861
+ */
862
+ interface SqliteStatement {
863
+ run(...params: SqliteValue[]): SqliteRunResult;
864
+ all<T = Record<string, unknown>>(...params: SqliteValue[]): T[];
865
+ get<T = Record<string, unknown>>(...params: SqliteValue[]): T | undefined;
866
+ }
867
+ /**
868
+ * Sync SQLite client port owned by Emulates.
869
+ *
870
+ * Duck-typed so `@emulates/sqlite` `Database`, better-sqlite3, and wrapped
871
+ * `bun:sqlite` instances all work when they expose this surface.
872
+ */
873
+ interface SqliteClient {
874
+ exec(sql: string): void;
875
+ prepare(sql: string): SqliteStatement;
876
+ transaction<T>(fn: () => T): T;
877
+ }
878
+
879
+ type RuntimeOptions = {
880
+ sqlite?: SqliteClient;
881
+ clock?: Clock;
882
+ seed?: number | string;
883
+ region?: string;
884
+ accountId?: string;
885
+ adminPrefix?: string;
886
+ adminKey?: string;
887
+ onLog?: (entry: RequestLog) => void;
888
+ };
889
+ type Runtime = ServiceRuntime<CloudcontrolAPI>;
890
+ declare const createRuntime: (options?: RuntimeOptions) => Runtime;
891
+
892
+ type APIOptions = AwsProtocolOptions;
893
+ declare class CloudcontrolAPI extends AwsProtocolAPI {
894
+ constructor(options?: APIOptions);
895
+ dispatch({ operation }: AwsOperation): unknown;
896
+ }
897
+
898
+ export { CloudcontrolAPI, createRuntime, document, operationIds, supportedOperationIds };
899
+ export type { APIOptions, Runtime, RuntimeOptions };