@crvouga/mockingbird-runtime 0.3.2 → 0.5.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.
@@ -7,7 +7,7 @@ import {
7
7
  createMetrics,
8
8
  maskCredential,
9
9
  resolveAdminPrefix
10
- } from "../chunk-M4HUKBLC.js";
10
+ } from "../chunk-GAIPLMRY.js";
11
11
  import "../chunk-U36J5GCB.js";
12
12
 
13
13
  // ../service/core/dist/engine-admin.js
package/dist/service.d.ts CHANGED
@@ -1112,6 +1112,29 @@ type MetricsReport = {
1112
1112
  faults: number;
1113
1113
  totalDurationMs: number;
1114
1114
  };
1115
+ /** What a runtime holds across every namespace: the gauges a long-running mock is watched by. */
1116
+ type ResourceReport = {
1117
+ /** Namespaces that hold state now (`GET /__admin/namespaces`). */
1118
+ namespaces: number;
1119
+ /** Stored records, every collection and branch included. */
1120
+ records: number;
1121
+ /** Journal entries held (`GET /__admin/requests`). */
1122
+ journalEntries: number;
1123
+ /** Named snapshots held. */
1124
+ snapshots: number;
1125
+ /** Webhook deliveries waiting for an attempt or a retry. */
1126
+ webhooksPending: number;
1127
+ /** Heap in use, or `null` where the host cannot say. */
1128
+ heapUsedBytes: number | null;
1129
+ /** Namespaces forgotten for being idle since the runtime started. */
1130
+ namespacesExpired: number;
1131
+ /** Idle namespaces whose drop failed; each is retried on a later request. */
1132
+ idleExpiryFailures: number;
1133
+ /** Requests answered `507` for the record cap, their writes rolled back. */
1134
+ recordLimitRefusals: number;
1135
+ /** Snapshots refused for the snapshot cap. */
1136
+ snapshotLimitRefusals: number;
1137
+ };
1115
1138
  type Metrics = {
1116
1139
  record(entry: RequestLog): void;
1117
1140
  report(namespace?: string): MetricsReport;
@@ -1143,6 +1166,8 @@ type Journal = {
1143
1166
  readonly size: number;
1144
1167
  record(entry: JournalEntry): void;
1145
1168
  list(query?: JournalQuery): JournalEntry[];
1169
+ /** Entries held for one namespace, or for every namespace. */
1170
+ count(namespace?: string): number;
1146
1171
  /** Forget one namespace's entries, or every namespace's. */
1147
1172
  clear(namespace?: string): void;
1148
1173
  };
@@ -1282,6 +1307,8 @@ type NamespaceControlsOptions = {
1282
1307
  onPreset?(preset: FaultPreset, namespace: string, overrides: Partial<FaultRule>): void;
1283
1308
  /** Put a snapshot document into a namespace: the boot `snapshot` control. */
1284
1309
  restoreDocument?(namespace: string, document: SnapshotDocument, scope: BootScope): void;
1310
+ /** A namespace was given controls for the first time: it now holds state of its own. */
1311
+ onStart?(namespace: string): void;
1285
1312
  };
1286
1313
  /**
1287
1314
  * Per-namespace seed, clock settings, latency and faults, and the one place a control
@@ -1428,6 +1455,8 @@ type ControlContext = {
1428
1455
  applyControls?(namespace: string, plan: ControlPlan): void;
1429
1456
  /** Reset a namespace and forget it. Default: reset. */
1430
1457
  dropNamespace?(namespace: string): Promise<void>;
1458
+ /** Runtime-wide gauges, added to an unscoped `GET /metrics?resources=1`. */
1459
+ resources?(): ResourceReport;
1431
1460
  };
1432
1461
  type ControlPlane = {
1433
1462
  /** The control-plane response for `request`, or `undefined` for a vendor request. */
@@ -1538,6 +1567,18 @@ type ListRecordsOptions<T> = {
1538
1567
  /** Sort order; default newest first. */
1539
1568
  order?: "newest" | "oldest";
1540
1569
  };
1570
+ /** A write that would store more records in one namespace than the runtime's `maxRecords`. */
1571
+ declare class RecordLimitError extends RangeError {
1572
+ readonly limit: number;
1573
+ constructor(limit: number);
1574
+ }
1575
+ /**
1576
+ * Cap the records each namespace of `service` may hold in `sqlite`, or lift the cap with
1577
+ * `undefined`. Storage namespaces are `service` and `service:<name>`; another service sharing
1578
+ * the database is not capped. Inserting a new id past it throws {@link RecordLimitError};
1579
+ * replacing a record never does.
1580
+ */
1581
+ declare const setRecordLimit: (sqlite: SqliteClient, service: string, limit: number | undefined) => void;
1541
1582
  /**
1542
1583
  * A SQLite-backed table of JSON records addressed by id. Ordering is by insertion
1543
1584
  * sequence, never by id lexicographic order, so list semantics stay stable.
@@ -1561,6 +1602,7 @@ declare class Collection<T> {
1561
1602
  nextSequence(): number;
1562
1603
  get(id: string): T | undefined;
1563
1604
  has(id: string): boolean;
1605
+ private assertRoom;
1564
1606
  /** Insert a new record, assigning it the next sequence number. */
1565
1607
  insert(id: string, value: T): Stored<T>;
1566
1608
  /** Replace an existing record's value, keeping its position. */
@@ -2271,7 +2313,8 @@ type WebhookHub = {
2271
2313
  deliveryId: string;
2272
2314
  }) => void): () => void;
2273
2315
  setTransportPolicy(policy: OwnedTransport): void;
2274
- pending(namespace: string): number;
2316
+ /** Deliveries waiting in one namespace, or in every namespace. */
2317
+ pending(namespace?: string): number;
2275
2318
  snapshot(namespace: string): unknown;
2276
2319
  exportSnapshot(handle: unknown): unknown;
2277
2320
  importSnapshot(namespace: string, document: unknown): unknown;
@@ -2408,6 +2451,21 @@ type RuntimeOptions<T extends ServiceInstance> = {
2408
2451
  webhooks?: WebhookHub;
2409
2452
  /** Retained time-travel checkpoints per namespace. Default 1,000. */
2410
2453
  maxCheckpoints?: number;
2454
+ /**
2455
+ * Forget a namespace (as `DELETE /__admin/namespaces/<key>` does) once no request has named
2456
+ * it for this many wall-clock milliseconds. `default` is never forgotten, nor is a namespace
2457
+ * with a webhook delivery still waiting or a request still running. Default 0: namespaces are
2458
+ * kept until dropped.
2459
+ */
2460
+ namespaceIdleMs?: number;
2461
+ /**
2462
+ * Records each namespace may hold; a request that would store another answers `507` with
2463
+ * every write it made rolled back. The cap is this runtime's own: another service sharing the
2464
+ * SQLite database is not capped by it. Default: no cap.
2465
+ */
2466
+ maxRecords?: number;
2467
+ /** Named snapshots each namespace may hold; another is refused with `400`. Default: no cap. */
2468
+ maxSnapshots?: number;
2411
2469
  /**
2412
2470
  * Record a time-travel checkpoint after every accepted mutation and stamp its id in
2413
2471
  * `x-mockingbird-checkpoint`. Default true. Each checkpoint reads the whole namespace, so a
@@ -2435,6 +2493,8 @@ type RuntimeIO = {
2435
2493
  monotonicNow(): number;
2436
2494
  /** Wait on the wall clock. Rejects with the signal's reason when it aborts first. */
2437
2495
  sleep(ms: number, signal?: AbortSignal): Promise<void>;
2496
+ /** Bytes of heap in use, for `GET /__admin/metrics`; `undefined` where the host cannot say. */
2497
+ heapUsedBytes(): number | undefined;
2438
2498
  };
2439
2499
  type ServiceTimelineState = Readonly<{
2440
2500
  snapshot: NamespaceSnapshot;
@@ -2489,6 +2549,8 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
2489
2549
  reset(namespace?: string): Promise<void>;
2490
2550
  /** Reset a namespace and forget it, releasing everything it held. */
2491
2551
  dropNamespace(namespace: string): Promise<void>;
2552
+ /** What the runtime holds across every namespace, as `GET /__admin/metrics` reports it. */
2553
+ resources(): ResourceReport;
2492
2554
  /** A namespace's controls: seed, clock, virtual time, latency, faults and snapshots. */
2493
2555
  controls(namespace?: string): ControlState & {
2494
2556
  snapshots: SnapshotInfo[];
@@ -2682,5 +2744,5 @@ declare const UNRELEASED_VERSION = "0.0.0-development";
2682
2744
  /** The published version of the service package this code is bundled into. */
2683
2745
  declare const PACKAGE_VERSION: string;
2684
2746
 
2685
- export { ADMIN_CONTROL_PAGES, ADMIN_DOCS_URL, ADMIN_KEY_HEADER, ADMIN_PREFIX, ADMIN_ROUTE_REFERENCE, AT_HEADER, AwsError, AwsProtocolAPI, BRANCH_HEADER, CHECKPOINT_HEADER, CONTROL_HEADERS, CONTROL_HEADER_REFERENCE, Collection, ControlError, DEFAULT_JOURNAL_SIZE, DEFAULT_NAMESPACE, DroppedConnectionError, FAULT_HEADER, HEALTH_PATH, HttpError, IdSequence, IdempotencyStore, MOCKINGBIRD_HEADER, NAMESPACE_HEADER, OperationRegistryError, OutboxStore, PACKAGE_VERSION, SNAPSHOT_FORMAT, SNAPSHOT_HEADER, STANDARD_ADMIN_ROUTES, STANDARD_FAULT_PRESETS, STATE_FIELD_KINDS, UNRELEASED_VERSION, annotateResponse, anyCredential, assertAdminPrefixAvailable, assertAdminUi, assertSnapshotDocument, awsList, awsMd5, awsPage, awsParseXml, awsRecord, awsRequired, awsXml, awsXmlEscape, basicAuth, bearerToken, bodyIssues, bootSqlite, codePointLength, coerce, controlHeaders, createClock, createControlPlane, createCredentialRegistry, createFaultRegistry, createJournal, createLatencyRegistry, createMetrics, createNamespaceControls, createRng, createRuntime, createService, createWebhookHub, decodeAwsQuery, defineMock, defineOperations, deriveClock, extractCodes, extractLinks, faultEffect, faultEffects, forwardRequestContext, fromBase64, hmac, idBaseOf, inspectState, isAdminPath, issuesByField, jsonRes, jsonRes as jsonResponse, markMutationAccepted, maskCredential, matchNamespacePath, normalizeBootControls, normalizeControls, normalizeFault, normalizeIdBase, opaqueToken, outboxAdminRoutes, ownedTransport, parseControlHeaders, parseDuration, parseFaultHeader, parseForm, parseInstant, parseSince, putObject, recordedIssues, requestBaseUrl, requestFingerprint, resolveAdminPrefix, responseNotes, restoreClock, restoreNamespace, seedFrom, setIdBase, sha, sigV4AccessKeyId, signSvix, signTimestamped, signTwilio, signV4, signers, snapshotNamespace, sortIssues, stableStringify, svixSecretBytes, timingSafeEqual, toBase64, toHex, unsupportedMediaType, upstreamRequest, verifyOperations, webhookAdminRoutes, withNamespaceRollback };
2686
- export type { APIOptions, AdminBrand, AdminExtension, AdminPanel, AdminRequest, AdminRoute, AdminRoutes, AdminUi, AwsInput, AwsOperation, AwsProtocolOptions, BasicCredentials, BodyIssue, ByteEncoding, Clock, ClockControls, ClockState, ControlClock, ControlContext, ControlHeaderInput, ControlHeaderName, ControlPlane, ControlSettings, ControlState, CredentialRegistry, DerivedClock, Duration, FaultCandidate, FaultHit, FaultInput, FaultListing, FaultPreset, FaultPresetList, FaultRegistry, FaultRule, FaultSnapshot, FieldResult, FormIssue, HmacAlgorithm, IdBase, IdempotencyErrors, IdempotencyStoreOptions, InstanceContext, Instant, Journal, JournalEntry, JournalQuery, LatencyControls, LatencyRegistry, LatencyRule, LatencyRuleInput, LatencyState, ListRecordsOptions, Metrics, MetricsReport, MockCheckpoint, MockControlState, MockControls, MockCreateOptions, MockInstanceSurface, MockSnapshotInfo, MockSurface, MountedAPI, NamespaceControls, NamespaceControls$1 as NamespaceControlsInput, NamespaceSnapshot, OperationContext, OperationHandler, OperationHandlers, OutboundPolicy, OutboxItem, OutboxQuery, OwnedTransport, ParsedForm, PublishInput, RejectedRequest, RequestBodyValue, RequestControls, RequestLog, ResponseNotes, Rng, RuntimeIO, RuntimeOptions, S3Target, Service, ServiceCheckpoint, ServiceInstance, ServiceOptions, ServiceRuntime, ServiceTimelineState, SignInput, SnapshotDocument, SnapshotInfo, SnapshotStore, StandardAdminRoute, StateCollectionView, StateDeclaration, StateField, StateFieldKind, StateMeta, StatePage, StateRecord, StateView, Stored, UnsupportedMediaType, UpstreamOptions, UpstreamState, WebhookAttempt, WebhookDelivery, WebhookEndpoint, WebhookFault, WebhookHub, WebhookHubOptions, WebhookMessage, WebhookSigner };
2747
+ export { ADMIN_CONTROL_PAGES, ADMIN_DOCS_URL, ADMIN_KEY_HEADER, ADMIN_PREFIX, ADMIN_ROUTE_REFERENCE, AT_HEADER, AwsError, AwsProtocolAPI, BRANCH_HEADER, CHECKPOINT_HEADER, CONTROL_HEADERS, CONTROL_HEADER_REFERENCE, Collection, ControlError, DEFAULT_JOURNAL_SIZE, DEFAULT_NAMESPACE, DroppedConnectionError, FAULT_HEADER, HEALTH_PATH, HttpError, IdSequence, IdempotencyStore, MOCKINGBIRD_HEADER, NAMESPACE_HEADER, OperationRegistryError, OutboxStore, PACKAGE_VERSION, RecordLimitError, SNAPSHOT_FORMAT, SNAPSHOT_HEADER, STANDARD_ADMIN_ROUTES, STANDARD_FAULT_PRESETS, STATE_FIELD_KINDS, UNRELEASED_VERSION, annotateResponse, anyCredential, assertAdminPrefixAvailable, assertAdminUi, assertSnapshotDocument, awsList, awsMd5, awsPage, awsParseXml, awsRecord, awsRequired, awsXml, awsXmlEscape, basicAuth, bearerToken, bodyIssues, bootSqlite, codePointLength, coerce, controlHeaders, createClock, createControlPlane, createCredentialRegistry, createFaultRegistry, createJournal, createLatencyRegistry, createMetrics, createNamespaceControls, createRng, createRuntime, createService, createWebhookHub, decodeAwsQuery, defineMock, defineOperations, deriveClock, extractCodes, extractLinks, faultEffect, faultEffects, forwardRequestContext, fromBase64, hmac, idBaseOf, inspectState, isAdminPath, issuesByField, jsonRes, jsonRes as jsonResponse, markMutationAccepted, maskCredential, matchNamespacePath, normalizeBootControls, normalizeControls, normalizeFault, normalizeIdBase, opaqueToken, outboxAdminRoutes, ownedTransport, parseControlHeaders, parseDuration, parseFaultHeader, parseForm, parseInstant, parseSince, putObject, recordedIssues, requestBaseUrl, requestFingerprint, resolveAdminPrefix, responseNotes, restoreClock, restoreNamespace, seedFrom, setIdBase, setRecordLimit, sha, sigV4AccessKeyId, signSvix, signTimestamped, signTwilio, signV4, signers, snapshotNamespace, sortIssues, stableStringify, svixSecretBytes, timingSafeEqual, toBase64, toHex, unsupportedMediaType, upstreamRequest, verifyOperations, webhookAdminRoutes, withNamespaceRollback };
2748
+ export type { APIOptions, AdminBrand, AdminExtension, AdminPanel, AdminRequest, AdminRoute, AdminRoutes, AdminUi, AwsInput, AwsOperation, AwsProtocolOptions, BasicCredentials, BodyIssue, ByteEncoding, Clock, ClockControls, ClockState, ControlClock, ControlContext, ControlHeaderInput, ControlHeaderName, ControlPlane, ControlSettings, ControlState, CredentialRegistry, DerivedClock, Duration, FaultCandidate, FaultHit, FaultInput, FaultListing, FaultPreset, FaultPresetList, FaultRegistry, FaultRule, FaultSnapshot, FieldResult, FormIssue, HmacAlgorithm, IdBase, IdempotencyErrors, IdempotencyStoreOptions, InstanceContext, Instant, Journal, JournalEntry, JournalQuery, LatencyControls, LatencyRegistry, LatencyRule, LatencyRuleInput, LatencyState, ListRecordsOptions, Metrics, MetricsReport, MockCheckpoint, MockControlState, MockControls, MockCreateOptions, MockInstanceSurface, MockSnapshotInfo, MockSurface, MountedAPI, NamespaceControls, NamespaceControls$1 as NamespaceControlsInput, NamespaceSnapshot, OperationContext, OperationHandler, OperationHandlers, OutboundPolicy, OutboxItem, OutboxQuery, OwnedTransport, ParsedForm, PublishInput, RejectedRequest, RequestBodyValue, RequestControls, RequestLog, ResourceReport, ResponseNotes, Rng, RuntimeIO, RuntimeOptions, S3Target, Service, ServiceCheckpoint, ServiceInstance, ServiceOptions, ServiceRuntime, ServiceTimelineState, SignInput, SnapshotDocument, SnapshotInfo, SnapshotStore, StandardAdminRoute, StateCollectionView, StateDeclaration, StateField, StateFieldKind, StateMeta, StatePage, StateRecord, StateView, Stored, UnsupportedMediaType, UpstreamOptions, UpstreamState, WebhookAttempt, WebhookDelivery, WebhookEndpoint, WebhookFault, WebhookHub, WebhookHubOptions, WebhookMessage, WebhookSigner };
package/dist/service.js CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  OperationRegistryError,
16
16
  OutboxStore,
17
17
  PACKAGE_VERSION,
18
+ RecordLimitError,
18
19
  SNAPSHOT_HEADER,
19
20
  STATE_FIELD_KINDS,
20
21
  UNRELEASED_VERSION,
@@ -56,6 +57,7 @@ import {
56
57
  requestFingerprint,
57
58
  restoreNamespace,
58
59
  setIdBase,
60
+ setRecordLimit,
59
61
  signV4,
60
62
  signers,
61
63
  snapshotNamespace,
@@ -65,7 +67,7 @@ import {
65
67
  verifyOperations,
66
68
  webhookAdminRoutes,
67
69
  withNamespaceRollback
68
- } from "./chunk-KD6FHYQP.js";
70
+ } from "./chunk-BK5KDNUE.js";
69
71
  import "./chunk-2KDYLZXC.js";
70
72
  import {
71
73
  ADMIN_CONTROL_PAGES,
@@ -127,7 +129,7 @@ import {
127
129
  toBase64,
128
130
  toHex,
129
131
  upstreamRequest
130
- } from "./chunk-M4HUKBLC.js";
132
+ } from "./chunk-GAIPLMRY.js";
131
133
  import {
132
134
  requestBaseUrl
133
135
  } from "./chunk-U36J5GCB.js";
@@ -162,6 +164,7 @@ export {
162
164
  OperationRegistryError,
163
165
  OutboxStore,
164
166
  PACKAGE_VERSION,
167
+ RecordLimitError,
165
168
  SNAPSHOT_FORMAT,
166
169
  SNAPSHOT_HEADER,
167
170
  STANDARD_ADMIN_ROUTES,
@@ -243,6 +246,7 @@ export {
243
246
  restoreNamespace,
244
247
  seedFrom,
245
248
  setIdBase,
249
+ setRecordLimit,
246
250
  sha,
247
251
  sigV4AccessKeyId,
248
252
  signSvix,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crvouga/mockingbird-runtime",
3
- "version": "0.3.2",
3
+ "version": "0.5.0",
4
4
  "description": "The shared Mockingbird runtime every emulator service depends on: router, admin API and page, snapshots, faults and clock, installed once however many emulators an application uses.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -87,10 +87,10 @@
87
87
  },
88
88
  "repository": {
89
89
  "type": "git",
90
- "url": "git+https://github.com/crvouga-organization/mockingbird.git",
90
+ "url": "git+https://github.com/crvouga/mockingbird.git",
91
91
  "directory": "packages/runtime"
92
92
  },
93
- "homepage": "https://github.com/crvouga-organization/mockingbird/tree/main/packages/runtime#readme",
93
+ "homepage": "https://github.com/crvouga/mockingbird/tree/main/packages/runtime#readme",
94
94
  "keywords": [
95
95
  "mockingbird",
96
96
  "emulator",
@@ -114,14 +114,14 @@
114
114
  "pack:check": "bun ../../scripts/pack-check.ts"
115
115
  },
116
116
  "dependencies": {
117
- "@crvouga/mockingbird-service-sqlite": "3.6.0",
117
+ "@crvouga/mockingbird-service-sqlite": "3.7.0",
118
118
  "@noble/hashes": "2.4.0",
119
119
  "buffer": "6.0.3",
120
120
  "graphql": "17.0.0",
121
121
  "hono": "4.13.11",
122
122
  "jose": "6.2.2",
123
- "@crvouga/mockingbird-ui": "0.2.0",
124
- "@crvouga/mockingbird-preview": "0.2.0"
123
+ "@crvouga/mockingbird-ui": "0.5.0",
124
+ "@crvouga/mockingbird-preview": "0.3.0"
125
125
  },
126
126
  "devDependencies": {
127
127
  "@crvouga/mockingbird-adapter-node": "0.0.0-development",