@crvouga/mockingbird-runtime 0.0.0-stage → 0.0.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/README.md +131 -2
- package/dist/adapter-node.d.ts +2521 -0
- package/dist/adapter-node.js +6920 -0
- package/dist/adapter-node.js.map +7 -0
- package/dist/admin-ui.js +25 -0
- package/dist/admin-ui.js.map +7 -0
- package/dist/chunk-2KDYLZXC.js +118 -0
- package/dist/chunk-2KDYLZXC.js.map +7 -0
- package/dist/chunk-2Y25NPCV.js +1289 -0
- package/dist/chunk-2Y25NPCV.js.map +7 -0
- package/dist/chunk-4SAK6MQT.js +246 -0
- package/dist/chunk-4SAK6MQT.js.map +7 -0
- package/dist/chunk-ANCCZFF2.js +778 -0
- package/dist/chunk-ANCCZFF2.js.map +7 -0
- package/dist/chunk-EBGYPQPA.js +198 -0
- package/dist/chunk-EBGYPQPA.js.map +7 -0
- package/dist/chunk-EQLY2YOA.js +274 -0
- package/dist/chunk-EQLY2YOA.js.map +7 -0
- package/dist/chunk-G62YDIIJ.js +7664 -0
- package/dist/chunk-G62YDIIJ.js.map +7 -0
- package/dist/chunk-HU6IOAFC.js +437 -0
- package/dist/chunk-HU6IOAFC.js.map +7 -0
- package/dist/chunk-RNAHPNUJ.js +97 -0
- package/dist/chunk-RNAHPNUJ.js.map +7 -0
- package/dist/chunk-UP4QOSFD.js +87 -0
- package/dist/chunk-UP4QOSFD.js.map +7 -0
- package/dist/chunk-XNS34BPF.js +2489 -0
- package/dist/chunk-XNS34BPF.js.map +7 -0
- package/dist/core.d.ts +356 -0
- package/dist/core.js +51 -0
- package/dist/core.js.map +7 -0
- package/dist/crypto-XS5XCMRJ.js +21 -0
- package/dist/crypto-XS5XCMRJ.js.map +7 -0
- package/dist/helpers-UD7CG4WQ.js +18 -0
- package/dist/helpers-UD7CG4WQ.js.map +7 -0
- package/dist/http-codec.d.ts +72 -0
- package/dist/http-codec.js +25 -0
- package/dist/http-codec.js.map +7 -0
- package/dist/http-provider.d.ts +3243 -0
- package/dist/http-provider.js +37920 -0
- package/dist/http-provider.js.map +7 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +7 -0
- package/dist/mqtt-broker/node.d.ts +632 -0
- package/dist/mqtt-broker/node.js +355 -0
- package/dist/mqtt-broker/node.js.map +7 -0
- package/dist/mqtt-broker.d.ts +990 -0
- package/dist/mqtt-broker.js +913 -0
- package/dist/mqtt-broker.js.map +7 -0
- package/dist/openapi-metadata.d.ts +290 -0
- package/dist/openapi-metadata.js +28 -0
- package/dist/openapi-metadata.js.map +7 -0
- package/dist/openapi.d.ts +252 -0
- package/dist/openapi.js +45 -0
- package/dist/openapi.js.map +7 -0
- package/dist/preview/artifacts.d.ts +19 -0
- package/dist/preview/artifacts.js +40 -0
- package/dist/preview/artifacts.js.map +7 -0
- package/dist/preview/bridge.d.ts +21 -0
- package/dist/preview/bridge.js +9 -0
- package/dist/preview/bridge.js.map +7 -0
- package/dist/preview/harness.d.ts +12 -0
- package/dist/preview/harness.js +65 -0
- package/dist/preview/harness.js.map +7 -0
- package/dist/preview/host.d.ts +30 -0
- package/dist/preview/host.js +70 -0
- package/dist/preview/host.js.map +7 -0
- package/dist/service/admin.d.ts +106 -0
- package/dist/service/admin.js +340 -0
- package/dist/service/admin.js.map +7 -0
- package/dist/service.d.ts +2665 -0
- package/dist/service.js +264 -0
- package/dist/service.js.map +7 -0
- package/dist/sqlite.d.ts +69 -0
- package/dist/sqlite.js +19 -0
- package/dist/sqlite.js.map +7 -0
- package/dist/ui.d.ts +37 -0
- package/dist/ui.js +702 -0
- package/dist/ui.js.map +7 -0
- package/package.json +135 -4
package/README.md
CHANGED
|
@@ -1,3 +1,132 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @crvouga/mockingbird-runtime
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> Local emulators. Real API contracts. Part of [Mockingbird](https://github.com/crvouga/mockingbird).
|
|
4
|
+
|
|
5
|
+
The runtime every Mockingbird emulator service is built on: the router, the `/__admin` API and
|
|
6
|
+
page, snapshots, faults, the clock, and the HTTP and OpenAPI helpers. Each
|
|
7
|
+
`@crvouga/mockingbird-service-*` package depends on it at the same version, so an application
|
|
8
|
+
that installs or bundles several emulators carries one copy of it, not one per service. The
|
|
9
|
+
admin page's browser client (`dist/admin-ui.js`) is loaded only on the first `/__admin/ui`
|
|
10
|
+
request.
|
|
11
|
+
|
|
12
|
+
Emulators install it automatically. Preview applications can also import the supported system
|
|
13
|
+
harness from `@crvouga/mockingbird-runtime/ui`.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npm install -D @crvouga/mockingbird-runtime
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Install it directly when using the system harness without an emulator, or to pin its version.
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { createRuntime } from "@crvouga/mockingbird-service-sqs"
|
|
27
|
+
|
|
28
|
+
const sqs = createRuntime()
|
|
29
|
+
const response = await sqs.fetch(new Request("http://sqs.local/__admin/health"))
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## API
|
|
33
|
+
|
|
34
|
+
- `RUNTIME_SUBPATHS`: the subpaths this package exports (`core`, `service`, `sqlite`, …), each
|
|
35
|
+
re-exporting the Mockingbird helper of that name.
|
|
36
|
+
|
|
37
|
+
The `ui` entry is a supported public preview API: `mountSystemHarness`, `SystemHarness`,
|
|
38
|
+
`SystemSurface`, `CSS_RESET` and `scopeReset`. The `preview/*` entries below are also supported. Other helper subpaths are internal to emulator
|
|
39
|
+
services; depend on a service's own exports for those capabilities.
|
|
40
|
+
|
|
41
|
+
To leave the admin page's client out of a single-file application bundle, mark it external
|
|
42
|
+
(`esbuild --external:./admin-ui.js`); `/__admin/ui` then answers 503 and everything else works.
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
## System harness for application previews
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { mountSystemHarness, type SystemSurface } from "@crvouga/mockingbird-runtime/ui"
|
|
49
|
+
|
|
50
|
+
const surfaces: SystemSurface[] = [{
|
|
51
|
+
id: "app",
|
|
52
|
+
label: "Application",
|
|
53
|
+
mount(element, signal) {
|
|
54
|
+
element.textContent = "Application preview"
|
|
55
|
+
// Mount your real application here; use signal for pending asynchronous work.
|
|
56
|
+
return () => element.replaceChildren()
|
|
57
|
+
},
|
|
58
|
+
}]
|
|
59
|
+
const root = document.createElement("div")
|
|
60
|
+
root.style.height = "100vh"
|
|
61
|
+
document.body.append(root)
|
|
62
|
+
const harness = mountSystemHarness(root, surfaces, { initial: "app", syncUrl: true })
|
|
63
|
+
await harness.show("system")
|
|
64
|
+
// On teardown: harness.destroy(); root.remove()
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The System home and app switcher are built in. Surfaces mount lazily and stay mounted while
|
|
68
|
+
hidden. Async mounts show loading and retryable error states, receive a teardown signal, and
|
|
69
|
+
return their own cleanup function. Surface IDs must be unique; `system` is reserved. The returned
|
|
70
|
+
handle exposes `show(id)`, `active()` and `destroy()`. URL synchronization is opt-in for standalone
|
|
71
|
+
previews; omit it in embedded hosts.
|
|
72
|
+
|
|
73
|
+
The medical-testing example and its Storybook stories use this same shell. The preview subpaths below add worker hosting, streaming request bridges, artifacts and Node test access. Application configuration, seed data
|
|
74
|
+
and credential policies remain in the consuming project.
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
## Worker hosting and test access
|
|
78
|
+
|
|
79
|
+
These supported subpaths ship in this package; no unpublished adapter is required.
|
|
80
|
+
|
|
81
|
+
| Entry | Exports | Purpose |
|
|
82
|
+
| --- | --- | --- |
|
|
83
|
+
| `/preview/bridge` | `createPreviewClient`, `attachPreviewHost` | MessagePort Fetch bridge with streamed responses, cancellation and deadlines. |
|
|
84
|
+
| `/preview/host` | `createPreviewHost` | Shared app startup, readiness, reset generations and disposal. |
|
|
85
|
+
| `/preview/artifacts` | `loadPreviewArtifact`, `createPreviewWorker` | Versioned SHA-256 manifests, optional gzip and worker disposal. |
|
|
86
|
+
| `/preview/harness` | `startPreviewHarness` | Node-only HTTP endpoint backed by the same bridge Fetch function. |
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import { createPreviewHost } from "@crvouga/mockingbird-runtime/preview/host"
|
|
90
|
+
import { createPreviewClient } from "@crvouga/mockingbird-runtime/preview/bridge"
|
|
91
|
+
|
|
92
|
+
const host = createPreviewHost(() => ({
|
|
93
|
+
fetch: request => new Response(new URL(request.url).pathname),
|
|
94
|
+
dispose() {},
|
|
95
|
+
}))
|
|
96
|
+
await host.ready
|
|
97
|
+
const channel = new MessageChannel()
|
|
98
|
+
const disconnect = host.connect(channel.port1)
|
|
99
|
+
const client = createPreviewClient(channel.port2, { timeoutMs: 30_000 })
|
|
100
|
+
console.log(await (await client.fetch("http://localhost:3000/example")).text())
|
|
101
|
+
client.dispose()
|
|
102
|
+
disconnect()
|
|
103
|
+
await host.dispose()
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
In a dedicated worker, receive a transferred MessageChannel port and call `host.connect(port)`.
|
|
107
|
+
In a SharedWorker, connect each port from its `connect` event to the same host. One disconnected
|
|
108
|
+
client leaves other clients running. Await `host.ready` for startup errors; `host.state()` reports
|
|
109
|
+
status and generation. `host.reset()` disposes the current application and runs the factory again.
|
|
110
|
+
The application owns its servers, routing, seeds and active work, and must close them in `dispose()`.
|
|
111
|
+
|
|
112
|
+
Requests buffer their bodies; responses transfer one chunk per pull. The deadline covers the
|
|
113
|
+
response body lifetime, including SSE. Dispose clients on worker errors and page teardown; an
|
|
114
|
+
unannounced worker death otherwise fails at the deadline. Host disposal errors pending responses.
|
|
115
|
+
Redirects are returned without following them. Cookies are explicit headers, with no inherited
|
|
116
|
+
browser cookie jar or automatic Set-Cookie persistence; keep per-session jars in application code.
|
|
117
|
+
Workers and the bridge run trusted code and are not security sandboxes.
|
|
118
|
+
|
|
119
|
+
Artifact manifests contain `version: 1`, `url`, `sha256` (lowercase hex of decoded JavaScript) and
|
|
120
|
+
optional `compression: "gzip"`. Serve compressed artifacts without HTTP Content-Encoding so they
|
|
121
|
+
are not decompressed twice. Blob workers require a bundled file without relative imports and CSP
|
|
122
|
+
permission for blob workers. Call the returned worker's `dispose()` to terminate and revoke it.
|
|
123
|
+
|
|
124
|
+
A Node host connected to the worker transport can call `startPreviewHarness(client.fetch,
|
|
125
|
+
{ origin: "http://localhost:3000" })`. This exposes the same running application to HTTP test
|
|
126
|
+
clients, with streamed responses, connection failure for post-header errors and no-store caching.
|
|
127
|
+
It does not launch Chromium or establish a cross-process browser connection for you.
|
|
128
|
+
|
|
129
|
+
The packed-consumer test installs local release tarballs into an empty npm project and runs the
|
|
130
|
+
public UI and worker entries in Chromium. Native Node/Bun compatibility, virtual sockets,
|
|
131
|
+
AsyncLocalStorage and framework certification belong to the separate browser-adapter work; these
|
|
132
|
+
helpers do not claim that arbitrary server applications run unchanged in a browser.
|