@crvouga/mockingbird-service-fullscript 3.13.0 → 3.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -113,98 +113,6 @@ interface FetchAPI {
113
113
  /** A bare function form of {@link FetchAPI}, compatible with `Bun.serve`, workerd, and Deno. */
114
114
  type FetchHandler = (request: Request) => Promise<Response>;
115
115
 
116
- /** Bind values accepted by Mockingbird's SQLite port (matches sqlite-mem / better-sqlite3). */
117
- type SqliteValue$1 = null | number | bigint | string | Uint8Array | boolean;
118
- /** Mutation counters returned by {@link SqliteStatement.run}. */
119
- type SqliteRunResult$1 = {
120
- changes: number;
121
- lastInsertRowid: number | bigint;
122
- };
123
- /**
124
- * Prepared statement bound to a {@link SqliteClient}.
125
- *
126
- * Pass bind values as rest arguments on each call (no sticky `bind()`).
127
- */
128
- interface SqliteStatement$1 {
129
- run(...params: SqliteValue$1[]): SqliteRunResult$1;
130
- all<T = Record<string, unknown>>(...params: SqliteValue$1[]): T[];
131
- get<T = Record<string, unknown>>(...params: SqliteValue$1[]): T | undefined;
132
- }
133
- /**
134
- * Sync SQLite client port owned by Mockingbird.
135
- *
136
- * Duck-typed so `@crvouga/mockingbird-service-sqlite` `Database`, better-sqlite3, and wrapped
137
- * `bun:sqlite` instances all work when they expose this surface.
138
- */
139
- interface SqliteClient$1 {
140
- exec(sql: string): void;
141
- prepare(sql: string): SqliteStatement$1;
142
- transaction<T>(fn: () => T): T;
143
- }
144
-
145
- /** Every stored record carries a monotonically increasing sequence for stable ordering. */
146
- type Stored<T> = {
147
- seq: number;
148
- value: T;
149
- };
150
- type ListRecordsOptions<T> = {
151
- /** Keep only records passing the predicate. */
152
- where?: (value: T, seq: number) => boolean;
153
- /** Sort order; default newest first. */
154
- order?: "newest" | "oldest";
155
- };
156
- /**
157
- * A SQLite-backed table of JSON records addressed by id. Ordering is by insertion
158
- * sequence, never by id lexicographic order, so list semantics stay stable.
159
- */
160
- declare class Collection<T> {
161
- private readonly sqlite;
162
- /** Storage namespace. Admin introspection uses this to ignore another namespace's tables. */
163
- readonly namespace: string;
164
- /** Table name inside the namespace. Stable across resets of the rows themselves. */
165
- readonly collectionName: string;
166
- private readonly statements;
167
- private prepare;
168
- constructor(sqlite: SqliteClient$1,
169
- /** Storage namespace. Admin introspection uses this to ignore another namespace's tables. */
170
- namespace: string,
171
- /** Table name inside the namespace. Stable across resets of the rows themselves. */
172
- collectionName: string);
173
- private bumpCollectionSeq;
174
- nextSequence(): number;
175
- get(id: string): T | undefined;
176
- has(id: string): boolean;
177
- /** Insert a new record, assigning it the next sequence number. */
178
- insert(id: string, value: T): Stored<T>;
179
- /** Replace an existing record's value, keeping its position. */
180
- update(id: string, value: T): Stored<T> | undefined;
181
- delete(id: string): boolean;
182
- /** How many records the collection holds, without reading them. */
183
- count(): number;
184
- list(options?: ListRecordsOptions<T>): Array<Stored<T> & {
185
- id: string;
186
- }>;
187
- }
188
-
189
- /**
190
- * What names an id base: a non-negative safe integer (or its decimal string) or `"boot"`,
191
- * which derives the base from the wall clock when the runtime is created.
192
- */
193
- type IdBase = number | string;
194
-
195
- /** Options every provider constructor accepts. */
196
- type APIOptions = {
197
- /** Sync SQLite client. Defaults to `@crvouga/mockingbird-service-sqlite`. */
198
- sqlite?: SqliteClient$1;
199
- /** Clock used for `created`-style fields. Default `Date.now`. */
200
- now?: () => number;
201
- /**
202
- * Storage namespace for this instance's records. Instances sharing one SQLite
203
- * client stay isolated when their namespaces differ. Defaults to the service name.
204
- */
205
- namespace?: string;
206
- };
207
-
208
116
  /**
209
117
  * The single source of time for a service.
210
118
  *
@@ -235,6 +143,11 @@ type Clock = {
235
143
  state(): ClockState;
236
144
  };
237
145
 
146
+ type UpstreamState = {
147
+ mode: "emulated" | "forward";
148
+ baseUrl: string;
149
+ };
150
+
238
151
  /**
239
152
  * Seeded pseudo-random numbers, so anything a mock invents — ids, jitter, which
240
153
  * request a percentage fault hits — is reproducible from a seed.
@@ -511,6 +424,7 @@ declare const SNAPSHOT_FORMAT = "mockingbird.snapshot/v1";
511
424
  * `records` are required, so a hand-written seed file is a valid snapshot.
512
425
  */
513
426
  type SnapshotDocument = {
427
+ upstream?: UpstreamState;
514
428
  format: typeof SNAPSHOT_FORMAT;
515
429
  /** The service that wrote it. A snapshot is rejected by any other service. */
516
430
  service?: string;
@@ -584,6 +498,7 @@ type LatencyState = LatencyRule & {
584
498
  };
585
499
  /** What {@link controlHeaders} turns into request headers. */
586
500
  type ControlHeaderInput = {
501
+ upstream?: "emulated" | "forward";
587
502
  namespace?: string;
588
503
  adminKey?: string;
589
504
  branch?: string;
@@ -601,6 +516,48 @@ type ControlHeaderInput = {
601
516
  snapshot?: string;
602
517
  };
603
518
 
519
+ /** Bind values accepted by Mockingbird's SQLite port (matches sqlite-mem / better-sqlite3). */
520
+ type SqliteValue$1 = null | number | bigint | string | Uint8Array | boolean;
521
+ /** Mutation counters returned by {@link SqliteStatement.run}. */
522
+ type SqliteRunResult$1 = {
523
+ changes: number;
524
+ lastInsertRowid: number | bigint;
525
+ };
526
+ /**
527
+ * Prepared statement bound to a {@link SqliteClient}.
528
+ *
529
+ * Pass bind values as rest arguments on each call (no sticky `bind()`).
530
+ */
531
+ interface SqliteStatement$1 {
532
+ run(...params: SqliteValue$1[]): SqliteRunResult$1;
533
+ all<T = Record<string, unknown>>(...params: SqliteValue$1[]): T[];
534
+ get<T = Record<string, unknown>>(...params: SqliteValue$1[]): T | undefined;
535
+ }
536
+ /**
537
+ * Sync SQLite client port owned by Mockingbird.
538
+ *
539
+ * Duck-typed so `@crvouga/mockingbird-service-sqlite` `Database`, better-sqlite3, and wrapped
540
+ * `bun:sqlite` instances all work when they expose this surface.
541
+ */
542
+ interface SqliteClient$1 {
543
+ exec(sql: string): void;
544
+ prepare(sql: string): SqliteStatement$1;
545
+ transaction<T>(fn: () => T): T;
546
+ }
547
+
548
+ /** Options every provider constructor accepts. */
549
+ type APIOptions = {
550
+ /** Sync SQLite client. Defaults to `@crvouga/mockingbird-service-sqlite`. */
551
+ sqlite?: SqliteClient$1;
552
+ /** Clock used for `created`-style fields. Default `Date.now`. */
553
+ now?: () => number;
554
+ /**
555
+ * Storage namespace for this instance's records. Instances sharing one SQLite
556
+ * client stay isolated when their namespaces differ. Defaults to the service name.
557
+ */
558
+ namespace?: string;
559
+ };
560
+
604
561
  /**
605
562
  * One problem with a request body, at a dotted path (`patient.address.city`, `items.0.sku`).
606
563
  * `kind` is `media_type` when the body is present but its media type is not one the operation
@@ -627,6 +584,7 @@ type RejectedRequest = {
627
584
  };
628
585
  /** One handled request, as the structured log sees it. */
629
586
  type RequestLog = {
587
+ upstream?: boolean;
630
588
  service: string;
631
589
  namespace: string;
632
590
  operationId: string | undefined;
@@ -761,8 +719,6 @@ type CredentialRegistry = {
761
719
  }[];
762
720
  };
763
721
 
764
- type OwnedTransport = (request: Request, namespace: string, send: typeof fetch) => Promise<Response>;
765
-
766
722
  /**
767
723
  * A point-in-time copy of everything a service namespace holds.
768
724
  *
@@ -785,6 +741,50 @@ type NamespaceSnapshot = {
785
741
  }[];
786
742
  };
787
743
 
744
+ /** Every stored record carries a monotonically increasing sequence for stable ordering. */
745
+ type Stored<T> = {
746
+ seq: number;
747
+ value: T;
748
+ };
749
+ type ListRecordsOptions<T> = {
750
+ /** Keep only records passing the predicate. */
751
+ where?: (value: T, seq: number) => boolean;
752
+ /** Sort order; default newest first. */
753
+ order?: "newest" | "oldest";
754
+ };
755
+ /**
756
+ * A SQLite-backed table of JSON records addressed by id. Ordering is by insertion
757
+ * sequence, never by id lexicographic order, so list semantics stay stable.
758
+ */
759
+ declare class Collection<T> {
760
+ private readonly sqlite;
761
+ /** Storage namespace. Admin introspection uses this to ignore another namespace's tables. */
762
+ readonly namespace: string;
763
+ /** Table name inside the namespace. Stable across resets of the rows themselves. */
764
+ readonly collectionName: string;
765
+ private readonly statements;
766
+ private prepare;
767
+ constructor(sqlite: SqliteClient$1,
768
+ /** Storage namespace. Admin introspection uses this to ignore another namespace's tables. */
769
+ namespace: string,
770
+ /** Table name inside the namespace. Stable across resets of the rows themselves. */
771
+ collectionName: string);
772
+ private bumpCollectionSeq;
773
+ nextSequence(): number;
774
+ get(id: string): T | undefined;
775
+ has(id: string): boolean;
776
+ /** Insert a new record, assigning it the next sequence number. */
777
+ insert(id: string, value: T): Stored<T>;
778
+ /** Replace an existing record's value, keeping its position. */
779
+ update(id: string, value: T): Stored<T> | undefined;
780
+ delete(id: string): boolean;
781
+ /** How many records the collection holds, without reading them. */
782
+ count(): number;
783
+ list(options?: ListRecordsOptions<T>): Array<Stored<T> & {
784
+ id: string;
785
+ }>;
786
+ }
787
+
788
788
  declare const STATE_FIELD_KINDS: readonly ["string", "number", "boolean", "null", "object", "array", "unknown"];
789
789
  type StateFieldKind = (typeof STATE_FIELD_KINDS)[number];
790
790
  /** JSON-safe annotations a bespoke admin UI may read. The default UI shows them as text. */
@@ -815,6 +815,14 @@ type StateView = {
815
815
  collections: StateCollectionView[];
816
816
  };
817
817
 
818
+ /**
819
+ * What names an id base: a non-negative safe integer (or its decimal string) or `"boot"`,
820
+ * which derives the base from the wall clock when the runtime is created.
821
+ */
822
+ type IdBase = number | string;
823
+
824
+ type OwnedTransport = (request: Request, namespace: string, send: typeof fetch) => Promise<Response>;
825
+
818
826
  type WebhookEndpoint = {
819
827
  /** Stable id; generated when omitted. */
820
828
  id?: string;
package/dist/index.js CHANGED
@@ -18,8 +18,7 @@ import {
18
18
  publicEvent,
19
19
  supportedOperationIds,
20
20
  tokenCredential
21
- } from "./chunk-NEIB5IT4.js";
22
- import "./chunk-RJZUEZVH.js";
21
+ } from "./chunk-CJAYCSOW.js";
23
22
  export {
24
23
  DEFAULT_CLINIC,
25
24
  DEFAULT_PRACTITIONER,
package/dist/server.d.ts CHANGED
@@ -105,41 +105,6 @@ interface FetchAPI {
105
105
  /** A bare function form of {@link FetchAPI}, compatible with `Bun.serve`, workerd, and Deno. */
106
106
  type FetchHandler = (request: Request) => Promise<Response>;
107
107
 
108
- /** Bind values accepted by Mockingbird's SQLite port (matches sqlite-mem / better-sqlite3). */
109
- type SqliteValue = null | number | bigint | string | Uint8Array | boolean;
110
- /** Mutation counters returned by {@link SqliteStatement.run}. */
111
- type SqliteRunResult = {
112
- changes: number;
113
- lastInsertRowid: number | bigint;
114
- };
115
- /**
116
- * Prepared statement bound to a {@link SqliteClient}.
117
- *
118
- * Pass bind values as rest arguments on each call (no sticky `bind()`).
119
- */
120
- interface SqliteStatement {
121
- run(...params: SqliteValue[]): SqliteRunResult;
122
- all<T = Record<string, unknown>>(...params: SqliteValue[]): T[];
123
- get<T = Record<string, unknown>>(...params: SqliteValue[]): T | undefined;
124
- }
125
- /**
126
- * Sync SQLite client port owned by Mockingbird.
127
- *
128
- * Duck-typed so `@crvouga/mockingbird-service-sqlite` `Database`, better-sqlite3, and wrapped
129
- * `bun:sqlite` instances all work when they expose this surface.
130
- */
131
- interface SqliteClient {
132
- exec(sql: string): void;
133
- prepare(sql: string): SqliteStatement;
134
- transaction<T>(fn: () => T): T;
135
- }
136
-
137
- /**
138
- * What names an id base: a non-negative safe integer (or its decimal string) or `"boot"`,
139
- * which derives the base from the wall clock when the runtime is created.
140
- */
141
- type IdBase = number | string;
142
-
143
108
  /**
144
109
  * The single source of time for a service.
145
110
  *
@@ -170,6 +135,11 @@ type Clock = {
170
135
  state(): ClockState;
171
136
  };
172
137
 
138
+ type UpstreamState = {
139
+ mode: "emulated" | "forward";
140
+ baseUrl: string;
141
+ };
142
+
173
143
  /**
174
144
  * Seeded pseudo-random numbers, so anything a mock invents — ids, jitter, which
175
145
  * request a percentage fault hits — is reproducible from a seed.
@@ -433,6 +403,7 @@ declare const SNAPSHOT_FORMAT = "mockingbird.snapshot/v1";
433
403
  * `records` are required, so a hand-written seed file is a valid snapshot.
434
404
  */
435
405
  type SnapshotDocument = {
406
+ upstream?: UpstreamState;
436
407
  format: typeof SNAPSHOT_FORMAT;
437
408
  /** The service that wrote it. A snapshot is rejected by any other service. */
438
409
  service?: string;
@@ -506,6 +477,7 @@ type LatencyState = LatencyRule & {
506
477
  };
507
478
  /** What {@link controlHeaders} turns into request headers. */
508
479
  type ControlHeaderInput = {
480
+ upstream?: "emulated" | "forward";
509
481
  namespace?: string;
510
482
  adminKey?: string;
511
483
  branch?: string;
@@ -523,6 +495,35 @@ type ControlHeaderInput = {
523
495
  snapshot?: string;
524
496
  };
525
497
 
498
+ /** Bind values accepted by Mockingbird's SQLite port (matches sqlite-mem / better-sqlite3). */
499
+ type SqliteValue = null | number | bigint | string | Uint8Array | boolean;
500
+ /** Mutation counters returned by {@link SqliteStatement.run}. */
501
+ type SqliteRunResult = {
502
+ changes: number;
503
+ lastInsertRowid: number | bigint;
504
+ };
505
+ /**
506
+ * Prepared statement bound to a {@link SqliteClient}.
507
+ *
508
+ * Pass bind values as rest arguments on each call (no sticky `bind()`).
509
+ */
510
+ interface SqliteStatement {
511
+ run(...params: SqliteValue[]): SqliteRunResult;
512
+ all<T = Record<string, unknown>>(...params: SqliteValue[]): T[];
513
+ get<T = Record<string, unknown>>(...params: SqliteValue[]): T | undefined;
514
+ }
515
+ /**
516
+ * Sync SQLite client port owned by Mockingbird.
517
+ *
518
+ * Duck-typed so `@crvouga/mockingbird-service-sqlite` `Database`, better-sqlite3, and wrapped
519
+ * `bun:sqlite` instances all work when they expose this surface.
520
+ */
521
+ interface SqliteClient {
522
+ exec(sql: string): void;
523
+ prepare(sql: string): SqliteStatement;
524
+ transaction<T>(fn: () => T): T;
525
+ }
526
+
526
527
  /**
527
528
  * One problem with a request body, at a dotted path (`patient.address.city`, `items.0.sku`).
528
529
  * `kind` is `media_type` when the body is present but its media type is not one the operation
@@ -549,6 +550,7 @@ type RejectedRequest = {
549
550
  };
550
551
  /** One handled request, as the structured log sees it. */
551
552
  type RequestLog = {
553
+ upstream?: boolean;
552
554
  service: string;
553
555
  namespace: string;
554
556
  operationId: string | undefined;
@@ -683,8 +685,6 @@ type CredentialRegistry = {
683
685
  }[];
684
686
  };
685
687
 
686
- type OwnedTransport = (request: Request, namespace: string, send: typeof fetch) => Promise<Response>;
687
-
688
688
  /**
689
689
  * A point-in-time copy of everything a service namespace holds.
690
690
  *
@@ -737,6 +737,14 @@ type StateView = {
737
737
  collections: StateCollectionView[];
738
738
  };
739
739
 
740
+ /**
741
+ * What names an id base: a non-negative safe integer (or its decimal string) or `"boot"`,
742
+ * which derives the base from the wall clock when the runtime is created.
743
+ */
744
+ type IdBase = number | string;
745
+
746
+ type OwnedTransport = (request: Request, namespace: string, send: typeof fetch) => Promise<Response>;
747
+
740
748
  type WebhookEndpoint = {
741
749
  /** Stable id; generated when omitted. */
742
750
  id?: string;
package/dist/server.js CHANGED
@@ -2,9 +2,8 @@ import {
2
2
  DEFAULT_PORT,
3
3
  createServer,
4
4
  serveTarget
5
- } from "./chunk-NYU2CEXU.js";
6
- import "./chunk-NEIB5IT4.js";
7
- import "./chunk-RJZUEZVH.js";
5
+ } from "./chunk-IVB27G3V.js";
6
+ import "./chunk-CJAYCSOW.js";
8
7
  export {
9
8
  DEFAULT_PORT,
10
9
  createServer,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crvouga/mockingbird-service-fullscript",
3
- "version": "3.13.0",
3
+ "version": "3.15.0",
4
4
  "description": "Stateful emulator of the Fullscript lab-ordering API: per-practitioner OAuth, clinic, session grants, forward-only lab orders with results, lab-order events, expiring result PDFs, and Fullscript-Signature webhooks.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -98,7 +98,8 @@
98
98
  "pack:check": "bun ../../../scripts/pack-check.ts"
99
99
  },
100
100
  "dependencies": {
101
- "@crvouga/mockingbird-service-sqlite": "3.4.2",
101
+ "@crvouga/mockingbird-runtime": "0.0.1",
102
+ "@crvouga/mockingbird-service-sqlite": "3.5.0",
102
103
  "hono": "4.13.11"
103
104
  },
104
105
  "devDependencies": {