@crvouga/mockingbird-runtime 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,11 +18,11 @@ import {
18
18
  import {
19
19
  Collection,
20
20
  bootSqlite
21
- } from "./chunk-BK5KDNUE.js";
21
+ } from "./chunk-CIJF35LX.js";
22
22
  import {
23
23
  clearNamespace
24
24
  } from "./chunk-2KDYLZXC.js";
25
- import "./chunk-GAIPLMRY.js";
25
+ import "./chunk-MZMSHIAI.js";
26
26
  import {
27
27
  requestBaseUrl
28
28
  } from "./chunk-U36J5GCB.js";
@@ -903,7 +903,7 @@ function parseCookies(header) {
903
903
 
904
904
  // ../http/provider/dist/vendor/core/ui.js
905
905
  async function renderProviderPage(page) {
906
- const { renderProviderPage: render } = await import("./server-SXO3PUBW.js");
906
+ const { renderProviderPage: render } = await import("./server-MIPFZS6D.js");
907
907
  return render(page);
908
908
  }
909
909
  function renderCardPage(title, description, blocks, service) {
package/dist/index.d.ts CHANGED
@@ -5,6 +5,6 @@
5
5
  * copy (scripts/bundle-service-runtime.ts).
6
6
  */
7
7
  /** Every subpath this package exports, in `package.json` order. */
8
- declare const RUNTIME_SUBPATHS: readonly ["core", "openapi", "openapi-metadata", "http-codec", "http-provider", "mqtt-broker", "mqtt-broker/node", "ui", "sqlite", "service", "service/admin", "adapter-node", "preview/bridge", "preview/host", "preview/artifacts", "preview/harness"];
8
+ declare const RUNTIME_SUBPATHS: readonly ["authoring", "core", "openapi", "openapi-metadata", "http-codec", "http-provider", "mqtt-broker", "mqtt-broker/node", "ui", "sqlite", "service", "service/admin", "adapter-node", "preview/bridge", "preview/host", "preview/artifacts", "preview/harness"];
9
9
 
10
10
  export { RUNTIME_SUBPATHS };
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // src/index.ts
2
2
  var RUNTIME_SUBPATHS = [
3
+ "authoring",
3
4
  "core",
4
5
  "openapi",
5
6
  "openapi-metadata",
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
- "sourcesContent": ["/**\n * The shared Mockingbird runtime, published once so every emulator service depends on the same\n * copy. Each subpath re-exports one workspace helper (`@crvouga/mockingbird-runtime/<subpath>` is\n * `@crvouga/mockingbird-<subpath>`); a service's build imports these instead of inlining its own\n * copy (scripts/bundle-service-runtime.ts).\n */\n\n/** Every subpath this package exports, in `package.json` order. */\nexport const RUNTIME_SUBPATHS = [\n \"core\",\n \"openapi\",\n \"openapi-metadata\",\n \"http-codec\",\n \"http-provider\",\n \"mqtt-broker\",\n \"mqtt-broker/node\",\n \"ui\",\n \"sqlite\",\n \"service\",\n \"service/admin\",\n \"adapter-node\",\n \"preview/bridge\",\n \"preview/host\",\n \"preview/artifacts\",\n \"preview/harness\",\n] as const\n"],
5
- "mappings": ";AAQO,IAAM,mBAAmB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;",
4
+ "sourcesContent": ["/**\n * The shared Mockingbird runtime, published once so every emulator service depends on the same\n * copy. Each subpath re-exports one workspace helper (`@crvouga/mockingbird-runtime/<subpath>` is\n * `@crvouga/mockingbird-<subpath>`); a service's build imports these instead of inlining its own\n * copy (scripts/bundle-service-runtime.ts).\n */\n\n/** Every subpath this package exports, in `package.json` order. */\nexport const RUNTIME_SUBPATHS = [\n \"authoring\",\n \"core\",\n \"openapi\",\n \"openapi-metadata\",\n \"http-codec\",\n \"http-provider\",\n \"mqtt-broker\",\n \"mqtt-broker/node\",\n \"ui\",\n \"sqlite\",\n \"service\",\n \"service/admin\",\n \"adapter-node\",\n \"preview/bridge\",\n \"preview/host\",\n \"preview/artifacts\",\n \"preview/harness\",\n] as const\n"],
5
+ "mappings": ";AAQO,IAAM,mBAAmB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  MAX_VARIABLE_BYTE_INTEGER,
3
3
  MQTT_WEBSOCKET_PATH
4
- } from "../chunk-SVG34QFE.js";
5
- import "../chunk-BK5KDNUE.js";
4
+ } from "../chunk-BKXECY5O.js";
5
+ import "../chunk-CIJF35LX.js";
6
6
  import "../chunk-2KDYLZXC.js";
7
- import "../chunk-GAIPLMRY.js";
7
+ import "../chunk-MZMSHIAI.js";
8
8
  import "../chunk-U36J5GCB.js";
9
9
  import "../chunk-EQLY2YOA.js";
10
10
  import "../chunk-HU6IOAFC.js";
@@ -28,6 +28,25 @@ type Clock = {
28
28
  state(): ClockState;
29
29
  };
30
30
 
31
+ /** An admission quota applied on the namespace clock. */
32
+ type FaultLimit = {
33
+ requests: number;
34
+ per: Duration;
35
+ key?: "namespace" | "credential";
36
+ window?: "fixed" | "sliding";
37
+ };
38
+ type LimitState = {
39
+ used: number;
40
+ windowStart: number | null;
41
+ windowResetsAt: number | null;
42
+ };
43
+ type LimitBucket = {
44
+ start: number;
45
+ used: number;
46
+ } | {
47
+ arrivals: number[];
48
+ };
49
+
31
50
  /**
32
51
  * A deliberate failure injected in front of an operation.
33
52
  *
@@ -71,6 +90,8 @@ type FaultRule = {
71
90
  * rules added through `POST /__admin/faults` default to the calling namespace.
72
91
  */
73
92
  namespace?: string;
93
+ /** Admit at most this many matching requests per window. */
94
+ limit?: FaultLimit;
74
95
  /** Let this many matching requests through first. */
75
96
  after?: number;
76
97
  /** Then fault only every nth matching request: `3` faults the 3rd, 6th, 9th. */
@@ -175,13 +196,17 @@ type FaultCandidate = {
175
196
  * `undefined` for a body that is missing or not JSON. It must leave the request readable.
176
197
  */
177
198
  readJson?: () => Promise<unknown>;
199
+ /** The service-specific credential, if it has one. */
200
+ credential?: () => string | undefined;
178
201
  /** The namespace clock, for `from` / `until`. Rules with a window are skipped without it. */
179
202
  now?: number;
203
+ /** Read the clock again after asynchronous request matching. */
204
+ clockNow?: () => number;
180
205
  /** How to spend a delay for this request. Default: the registry's own sleep. */
181
206
  wait?: (ms: number) => Promise<void>;
182
207
  };
183
208
  /** A stored rule and how often it was consulted. */
184
- type FaultListing = FaultRule & {
209
+ type FaultListing = FaultRule & Partial<LimitState> & {
185
210
  /** Faults left before the rule retires. `null` when it has no `count`. */
186
211
  remaining: number | null;
187
212
  /** Times the rule faulted a request. */
@@ -197,6 +222,7 @@ type FaultSnapshot = {
197
222
  */
198
223
  rules: (FaultListing & {
199
224
  position?: number;
225
+ limitBuckets?: [string, LimitBucket][];
200
226
  })[];
201
227
  /** How many `fault_<n>` ids the namespace has handed out. */
202
228
  nextId?: number;
@@ -14,16 +14,16 @@ import {
14
14
  observeClock,
15
15
  takeConnackFault,
16
16
  webSocketNamespace
17
- } from "./chunk-SVG34QFE.js";
17
+ } from "./chunk-BKXECY5O.js";
18
18
  import {
19
19
  Collection,
20
20
  IdSequence
21
- } from "./chunk-BK5KDNUE.js";
21
+ } from "./chunk-CIJF35LX.js";
22
22
  import "./chunk-2KDYLZXC.js";
23
23
  import {
24
24
  fromBase64,
25
25
  toBase64
26
- } from "./chunk-GAIPLMRY.js";
26
+ } from "./chunk-MZMSHIAI.js";
27
27
  import "./chunk-U36J5GCB.js";
28
28
  import "./chunk-EQLY2YOA.js";
29
29
  import "./chunk-HU6IOAFC.js";
@@ -13300,7 +13300,7 @@ function Zg({ children: e7, product: t, brandHref: r, nav: o, actions: a, footer
13300
13300
  var go = P($e(), 1);
13301
13301
  var y5 = { sm: "max-w-sm", md: "max-w-md", lg: "max-w-xl" };
13302
13302
  function Qg({ title: e7, description: t, children: r, footer: o, product: a, notice: n, size: l = "md" }) {
13303
- return (0, go.jsxs)("div", { className: "flex min-h-dvh flex-col items-center justify-center gap-6 bg-background px-4 py-10 text-foreground", "data-mockingbird-centered": true, children: [(0, go.jsx)(ud, { product: a }), (0, go.jsxs)(Oo, { className: `w-full ${y5[l]}`, children: [(0, go.jsxs)(Oo.Header, { children: [(0, go.jsx)(Oo.Title, { className: "text-lg font-semibold", render: (i) => (0, go.jsx)("h1", { ...i }), children: e7 }), t ? (0, go.jsx)(Oo.Description, { children: t }) : null] }), r ? (0, go.jsx)(Oo.Content, { className: "gap-3", children: r }) : null, o ? (0, go.jsx)(Oo.Footer, { className: "flex-wrap gap-2", children: o }) : null] }), n ? (0, go.jsx)("div", { className: `w-full ${y5[l]} text-center text-xs text-muted`, children: n }) : null] });
13303
+ return (0, go.jsxs)("div", { className: "flex min-h-[var(--mb-app-height,100dvh)] flex-col items-center justify-center gap-6 bg-background px-4 py-10 text-foreground", "data-mockingbird-centered": true, children: [(0, go.jsx)(ud, { product: a }), (0, go.jsxs)(Oo, { className: `w-full ${y5[l]}`, children: [(0, go.jsxs)(Oo.Header, { children: [(0, go.jsx)(Oo.Title, { className: "text-lg font-semibold", render: (i) => (0, go.jsx)("h1", { ...i }), children: e7 }), t ? (0, go.jsx)(Oo.Description, { children: t }) : null] }), r ? (0, go.jsx)(Oo.Content, { className: "gap-3", children: r }) : null, o ? (0, go.jsx)(Oo.Footer, { className: "flex-wrap gap-2", children: o }) : null] }), n ? (0, go.jsx)("div", { className: `w-full ${y5[l]} text-center text-xs text-muted`, children: n }) : null] });
13304
13304
  }
13305
13305
  var xo = P($e(), 1);
13306
13306
  var Jg = P(O(), 1);
@@ -16056,4 +16056,4 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
16056
16056
  SOFTWARE.
16057
16057
 
16058
16058
  */
16059
- //# sourceMappingURL=server-SXO3PUBW.js.map
16059
+ //# sourceMappingURL=server-MIPFZS6D.js.map