@crvouga/mockingbird-service-stripe 2.2.1 → 2.3.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.
- package/CHANGELOG.md +26 -1
- package/dist/{chunk-4G5L7P7I.js → chunk-4Q3EJ33E.js} +2 -2
- package/dist/{chunk-7ZVXTTT4.js → chunk-I2MCMD7N.js} +908 -849
- package/dist/chunk-I2MCMD7N.js.map +7 -0
- package/dist/cli.js +2 -2
- package/dist/index.d.ts +149 -145
- package/dist/index.js +1 -1
- package/dist/server.d.ts +281 -273
- package/dist/server.js +2 -2
- package/package.json +2 -2
- package/dist/chunk-7ZVXTTT4.js.map +0 -7
- /package/dist/{chunk-4G5L7P7I.js.map → chunk-4Q3EJ33E.js.map} +0 -0
package/dist/cli.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,35 +1,5 @@
|
|
|
1
1
|
import { Hono } from 'hono';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* The single source of time for a service.
|
|
5
|
-
*
|
|
6
|
-
* Every timestamp a mock writes reads from here, so a suite moves time instead of
|
|
7
|
-
* sleeping: appointment windows, result delays and expiries become reachable in
|
|
8
|
-
* milliseconds. A frozen clock also makes timestamps reproducible from a seed.
|
|
9
|
-
*/
|
|
10
|
-
type ClockState = {
|
|
11
|
-
/** Current epoch milliseconds. */
|
|
12
|
-
now: number;
|
|
13
|
-
/** True while time does not advance on its own. */
|
|
14
|
-
frozen: boolean;
|
|
15
|
-
/** Milliseconds this clock adds to its underlying source. */
|
|
16
|
-
offsetMs: number;
|
|
17
|
-
};
|
|
18
|
-
type Clock = {
|
|
19
|
-
now(): number;
|
|
20
|
-
/** Pin the clock to an exact instant, keeping it frozen if it already was. */
|
|
21
|
-
set(epochMs: number): void;
|
|
22
|
-
/** Move the clock forward, or back with a negative delta. */
|
|
23
|
-
advance(deltaMs: number): void;
|
|
24
|
-
/** Stop time at the current instant. */
|
|
25
|
-
freeze(): void;
|
|
26
|
-
/** Resume from the current instant. */
|
|
27
|
-
unfreeze(): void;
|
|
28
|
-
/** Drop back to the underlying source, live. */
|
|
29
|
-
reset(): void;
|
|
30
|
-
state(): ClockState;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
3
|
/** Bind values accepted by Mockingbird's SQLite port (matches sqlite-mem / better-sqlite3). */
|
|
34
4
|
type SqliteValue$1 = null | number | bigint | string | Uint8Array | boolean;
|
|
35
5
|
/** Mutation counters returned by {@link SqliteStatement.run}. */
|
|
@@ -101,6 +71,151 @@ declare class Collection<T> {
|
|
|
101
71
|
}>;
|
|
102
72
|
}
|
|
103
73
|
|
|
74
|
+
/**
|
|
75
|
+
* Sequential id source persisted in SQLite. Ids are deterministic for a given
|
|
76
|
+
* sequence history (`cus_` + 14 opaque chars), so reproductions stay stable.
|
|
77
|
+
*/
|
|
78
|
+
declare class IdSequence {
|
|
79
|
+
private readonly sqlite;
|
|
80
|
+
private readonly namespace;
|
|
81
|
+
private readonly salt;
|
|
82
|
+
constructor(sqlite: SqliteClient$1, namespace: string, salt?: string);
|
|
83
|
+
next(prefix: string, length?: number): string;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** A stable identifier for a point in a {@link Timeline}. */
|
|
87
|
+
type CheckpointId = string;
|
|
88
|
+
/** An immutable node in a timeline's checkpoint DAG. */
|
|
89
|
+
type Checkpoint<T> = Readonly<{
|
|
90
|
+
id: CheckpointId;
|
|
91
|
+
branch: string;
|
|
92
|
+
parent: CheckpointId | null;
|
|
93
|
+
/** Logical time supplied by the timeline's injected clock. */
|
|
94
|
+
at: number;
|
|
95
|
+
value: T;
|
|
96
|
+
}>;
|
|
97
|
+
type TimelineOptions = {
|
|
98
|
+
/** Logical clock used to stamp checkpoints. Defaults to a deterministic counter. */
|
|
99
|
+
now?: () => number;
|
|
100
|
+
/** Maximum retained checkpoints. Branch heads are never collected. Default 1,000. */
|
|
101
|
+
maxCheckpoints?: number;
|
|
102
|
+
/** Customize deterministic checkpoint IDs. */
|
|
103
|
+
id?: (sequence: number) => CheckpointId;
|
|
104
|
+
};
|
|
105
|
+
type CommitOptions = {
|
|
106
|
+
branch?: string;
|
|
107
|
+
/** Parent checkpoint. Defaults to the selected branch's current head. */
|
|
108
|
+
parent?: CheckpointId | null;
|
|
109
|
+
};
|
|
110
|
+
type ForkOptions = {
|
|
111
|
+
/** Checkpoint to fork from. Defaults to the main branch's head. */
|
|
112
|
+
from?: CheckpointId;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Small, storage-agnostic checkpoint DAG shared by service runtimes. Its values may be immutable
|
|
116
|
+
* records, namespace images, or copy-on-write SQL engine snapshots.
|
|
117
|
+
*
|
|
118
|
+
* Values are retained by reference. Engines can therefore use persistent/COW snapshots while
|
|
119
|
+
* simpler services can use immutable values. IDs and GC order are deterministic, and all IO
|
|
120
|
+
* (the logical clock) is injected.
|
|
121
|
+
*/
|
|
122
|
+
declare class Timeline<T> {
|
|
123
|
+
readonly maxCheckpoints: number;
|
|
124
|
+
private readonly now;
|
|
125
|
+
private readonly makeId;
|
|
126
|
+
private readonly nodes;
|
|
127
|
+
private readonly heads;
|
|
128
|
+
/** Unreferenced nodes in the exact order they became collectible. */
|
|
129
|
+
private readonly evictable;
|
|
130
|
+
/** Branch heads plus explicit retainers. Absent means zero. */
|
|
131
|
+
private readonly references;
|
|
132
|
+
private readonly explicitPins;
|
|
133
|
+
private sequence;
|
|
134
|
+
constructor(options?: TimelineOptions);
|
|
135
|
+
/** Capture a new immutable value and move `branch` to it. */
|
|
136
|
+
commit(value: T, options?: CommitOptions): Checkpoint<T>;
|
|
137
|
+
/** Create a branch pointer without copying its checkpoint value. */
|
|
138
|
+
fork(branch: string, options?: ForkOptions): Checkpoint<T> | undefined;
|
|
139
|
+
/** Move a branch pointer to an existing checkpoint. */
|
|
140
|
+
checkout(branch: string, id: CheckpointId): Checkpoint<T>;
|
|
141
|
+
get(id: CheckpointId): Checkpoint<T>;
|
|
142
|
+
head(branch?: string): Checkpoint<T> | undefined;
|
|
143
|
+
hasBranch(branch: string): boolean;
|
|
144
|
+
branches(): Readonly<Record<string, CheckpointId>>;
|
|
145
|
+
checkpoints(): readonly Checkpoint<T>[];
|
|
146
|
+
/** Number of retained checkpoints without allocating an array. */
|
|
147
|
+
get size(): number;
|
|
148
|
+
/** Pin a checkpoint independently of branch heads (used by compatibility snapshot handles). */
|
|
149
|
+
retain(id: CheckpointId): Checkpoint<T>;
|
|
150
|
+
/** Release one explicit pin. Branch heads remain pinned until moved or deleted. */
|
|
151
|
+
release(id: CheckpointId): boolean;
|
|
152
|
+
deleteBranch(branch: string): boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Deterministically discard oldest unpinned checkpoints. Collection is O(number removed):
|
|
155
|
+
* commits never scan pinned nodes or the retained history. Parents are metadata rather than a
|
|
156
|
+
* storage dependency, so a retained node remains usable after pruning.
|
|
157
|
+
*/
|
|
158
|
+
gc(max?: number): CheckpointId[];
|
|
159
|
+
private collect;
|
|
160
|
+
private moveHead;
|
|
161
|
+
private addReference;
|
|
162
|
+
private removeReference;
|
|
163
|
+
private assertBranch;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Anything that can answer a Fetch `Request` with a `Response`.
|
|
168
|
+
*
|
|
169
|
+
* Every Mockingbird service implements this, and every runtime adapter consumes it.
|
|
170
|
+
* It is the only contract shared across the whole graph.
|
|
171
|
+
*/
|
|
172
|
+
interface FetchAPI$1 {
|
|
173
|
+
fetch(request: Request): Promise<Response>;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Options every provider constructor accepts. */
|
|
177
|
+
type APIOptions = {
|
|
178
|
+
/** Sync SQLite client. Defaults to `@crvouga/mockingbird-service-sqlite`. */
|
|
179
|
+
sqlite?: SqliteClient$1;
|
|
180
|
+
/** Clock used for `created`-style fields. Default `Date.now`. */
|
|
181
|
+
now?: () => number;
|
|
182
|
+
/**
|
|
183
|
+
* Storage namespace for this instance's records. Instances sharing one SQLite
|
|
184
|
+
* client stay isolated when their namespaces differ. Defaults to the service name.
|
|
185
|
+
*/
|
|
186
|
+
namespace?: string;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* The single source of time for a service.
|
|
191
|
+
*
|
|
192
|
+
* Every timestamp a mock writes reads from here, so a suite moves time instead of
|
|
193
|
+
* sleeping: appointment windows, result delays and expiries become reachable in
|
|
194
|
+
* milliseconds. A frozen clock also makes timestamps reproducible from a seed.
|
|
195
|
+
*/
|
|
196
|
+
type ClockState = {
|
|
197
|
+
/** Current epoch milliseconds. */
|
|
198
|
+
now: number;
|
|
199
|
+
/** True while time does not advance on its own. */
|
|
200
|
+
frozen: boolean;
|
|
201
|
+
/** Milliseconds this clock adds to its underlying source. */
|
|
202
|
+
offsetMs: number;
|
|
203
|
+
};
|
|
204
|
+
type Clock = {
|
|
205
|
+
now(): number;
|
|
206
|
+
/** Pin the clock to an exact instant, keeping it frozen if it already was. */
|
|
207
|
+
set(epochMs: number): void;
|
|
208
|
+
/** Move the clock forward, or back with a negative delta. */
|
|
209
|
+
advance(deltaMs: number): void;
|
|
210
|
+
/** Stop time at the current instant. */
|
|
211
|
+
freeze(): void;
|
|
212
|
+
/** Resume from the current instant. */
|
|
213
|
+
unfreeze(): void;
|
|
214
|
+
/** Drop back to the underlying source, live. */
|
|
215
|
+
reset(): void;
|
|
216
|
+
state(): ClockState;
|
|
217
|
+
};
|
|
218
|
+
|
|
104
219
|
/**
|
|
105
220
|
* Seeded pseudo-random numbers, so anything a mock invents — ids, jitter, which
|
|
106
221
|
* request a percentage fault hits — is reproducible from a seed.
|
|
@@ -241,109 +356,6 @@ type FaultRegistry = {
|
|
|
241
356
|
take(candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
242
357
|
};
|
|
243
358
|
|
|
244
|
-
/** A stable identifier for a point in a {@link Timeline}. */
|
|
245
|
-
type CheckpointId = string;
|
|
246
|
-
/** An immutable node in a timeline's checkpoint DAG. */
|
|
247
|
-
type Checkpoint<T> = Readonly<{
|
|
248
|
-
id: CheckpointId;
|
|
249
|
-
branch: string;
|
|
250
|
-
parent: CheckpointId | null;
|
|
251
|
-
/** Logical time supplied by the timeline's injected clock. */
|
|
252
|
-
at: number;
|
|
253
|
-
value: T;
|
|
254
|
-
}>;
|
|
255
|
-
type TimelineOptions = {
|
|
256
|
-
/** Logical clock used to stamp checkpoints. Defaults to a deterministic counter. */
|
|
257
|
-
now?: () => number;
|
|
258
|
-
/** Maximum retained checkpoints. Branch heads are never collected. Default 1,000. */
|
|
259
|
-
maxCheckpoints?: number;
|
|
260
|
-
/** Customize deterministic checkpoint IDs. */
|
|
261
|
-
id?: (sequence: number) => CheckpointId;
|
|
262
|
-
};
|
|
263
|
-
type CommitOptions = {
|
|
264
|
-
branch?: string;
|
|
265
|
-
/** Parent checkpoint. Defaults to the selected branch's current head. */
|
|
266
|
-
parent?: CheckpointId | null;
|
|
267
|
-
};
|
|
268
|
-
type ForkOptions = {
|
|
269
|
-
/** Checkpoint to fork from. Defaults to the main branch's head. */
|
|
270
|
-
from?: CheckpointId;
|
|
271
|
-
};
|
|
272
|
-
/**
|
|
273
|
-
* Small, storage-agnostic checkpoint DAG shared by service runtimes. Its values may be immutable
|
|
274
|
-
* records, namespace images, or copy-on-write SQL engine snapshots.
|
|
275
|
-
*
|
|
276
|
-
* Values are retained by reference. Engines can therefore use persistent/COW snapshots while
|
|
277
|
-
* simpler services can use immutable values. IDs and GC order are deterministic, and all IO
|
|
278
|
-
* (the logical clock) is injected.
|
|
279
|
-
*/
|
|
280
|
-
declare class Timeline<T> {
|
|
281
|
-
readonly maxCheckpoints: number;
|
|
282
|
-
private readonly now;
|
|
283
|
-
private readonly makeId;
|
|
284
|
-
private readonly nodes;
|
|
285
|
-
private readonly heads;
|
|
286
|
-
/** Unreferenced nodes in the exact order they became collectible. */
|
|
287
|
-
private readonly evictable;
|
|
288
|
-
/** Branch heads plus explicit retainers. Absent means zero. */
|
|
289
|
-
private readonly references;
|
|
290
|
-
private readonly explicitPins;
|
|
291
|
-
private sequence;
|
|
292
|
-
constructor(options?: TimelineOptions);
|
|
293
|
-
/** Capture a new immutable value and move `branch` to it. */
|
|
294
|
-
commit(value: T, options?: CommitOptions): Checkpoint<T>;
|
|
295
|
-
/** Create a branch pointer without copying its checkpoint value. */
|
|
296
|
-
fork(branch: string, options?: ForkOptions): Checkpoint<T> | undefined;
|
|
297
|
-
/** Move a branch pointer to an existing checkpoint. */
|
|
298
|
-
checkout(branch: string, id: CheckpointId): Checkpoint<T>;
|
|
299
|
-
get(id: CheckpointId): Checkpoint<T>;
|
|
300
|
-
head(branch?: string): Checkpoint<T> | undefined;
|
|
301
|
-
hasBranch(branch: string): boolean;
|
|
302
|
-
branches(): Readonly<Record<string, CheckpointId>>;
|
|
303
|
-
checkpoints(): readonly Checkpoint<T>[];
|
|
304
|
-
/** Number of retained checkpoints without allocating an array. */
|
|
305
|
-
get size(): number;
|
|
306
|
-
/** Pin a checkpoint independently of branch heads (used by compatibility snapshot handles). */
|
|
307
|
-
retain(id: CheckpointId): Checkpoint<T>;
|
|
308
|
-
/** Release one explicit pin. Branch heads remain pinned until moved or deleted. */
|
|
309
|
-
release(id: CheckpointId): boolean;
|
|
310
|
-
deleteBranch(branch: string): boolean;
|
|
311
|
-
/**
|
|
312
|
-
* Deterministically discard oldest unpinned checkpoints. Collection is O(number removed):
|
|
313
|
-
* commits never scan pinned nodes or the retained history. Parents are metadata rather than a
|
|
314
|
-
* storage dependency, so a retained node remains usable after pruning.
|
|
315
|
-
*/
|
|
316
|
-
gc(max?: number): CheckpointId[];
|
|
317
|
-
private collect;
|
|
318
|
-
private moveHead;
|
|
319
|
-
private addReference;
|
|
320
|
-
private removeReference;
|
|
321
|
-
private assertBranch;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* Anything that can answer a Fetch `Request` with a `Response`.
|
|
326
|
-
*
|
|
327
|
-
* Every Mockingbird service implements this, and every runtime adapter consumes it.
|
|
328
|
-
* It is the only contract shared across the whole graph.
|
|
329
|
-
*/
|
|
330
|
-
interface FetchAPI$1 {
|
|
331
|
-
fetch(request: Request): Promise<Response>;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/** Options every provider constructor accepts. */
|
|
335
|
-
type APIOptions = {
|
|
336
|
-
/** Sync SQLite client. Defaults to `@crvouga/mockingbird-service-sqlite`. */
|
|
337
|
-
sqlite?: SqliteClient$1;
|
|
338
|
-
/** Clock used for `created`-style fields. Default `Date.now`. */
|
|
339
|
-
now?: () => number;
|
|
340
|
-
/**
|
|
341
|
-
* Storage namespace for this instance's records. Instances sharing one SQLite
|
|
342
|
-
* client stay isolated when their namespaces differ. Defaults to the service name.
|
|
343
|
-
*/
|
|
344
|
-
namespace?: string;
|
|
345
|
-
};
|
|
346
|
-
|
|
347
359
|
/**
|
|
348
360
|
* One problem with a request body, at a dotted path (`patient.address.city`, `items.0.sku`).
|
|
349
361
|
* `kind` is `media_type` when the body is present but its media type is not one the operation
|
|
@@ -385,6 +397,10 @@ type RequestLog = {
|
|
|
385
397
|
ids?: Record<string, string>;
|
|
386
398
|
/** Set when the service created a resource the request referred to but that did not exist. */
|
|
387
399
|
adopted?: boolean;
|
|
400
|
+
/** Explicit durable acceptance, independent of response delivery. */
|
|
401
|
+
accepted?: boolean;
|
|
402
|
+
/** Checkpoint captured at explicit acceptance. */
|
|
403
|
+
checkpoint?: string;
|
|
388
404
|
/** Set on a rejection (status ≥ 400) the mock produced itself, never on a scripted fault. */
|
|
389
405
|
request?: RejectedRequest;
|
|
390
406
|
/** The validation issues behind a rejection, when the service found any. */
|
|
@@ -448,18 +464,6 @@ type CredentialRegistry = {
|
|
|
448
464
|
}[];
|
|
449
465
|
};
|
|
450
466
|
|
|
451
|
-
/**
|
|
452
|
-
* Sequential id source persisted in SQLite. Ids are deterministic for a given
|
|
453
|
-
* sequence history (`cus_` + 14 opaque chars), so reproductions stay stable.
|
|
454
|
-
*/
|
|
455
|
-
declare class IdSequence {
|
|
456
|
-
private readonly sqlite;
|
|
457
|
-
private readonly namespace;
|
|
458
|
-
private readonly salt;
|
|
459
|
-
constructor(sqlite: SqliteClient$1, namespace: string, salt?: string);
|
|
460
|
-
next(prefix: string, length?: number): string;
|
|
461
|
-
}
|
|
462
|
-
|
|
463
467
|
/**
|
|
464
468
|
* A point-in-time copy of everything a service namespace holds.
|
|
465
469
|
*
|