@crvouga/mockingbird-adapter-browser 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 +172 -2
- package/TRANSPORT.md +46 -0
- package/dist/assets.d.ts +3 -0
- package/dist/assets.d.ts.map +1 -0
- package/dist/assets.js +3 -0
- package/dist/assets.js.map +1 -0
- package/dist/async-context.d.ts +29 -0
- package/dist/async-context.d.ts.map +1 -0
- package/dist/async-context.js +74 -0
- package/dist/async-context.js.map +1 -0
- package/dist/build.d.ts +25 -0
- package/dist/build.d.ts.map +1 -0
- package/dist/build.js +275 -0
- package/dist/build.js.map +1 -0
- package/dist/child-process-unsupported.d.ts +18 -0
- package/dist/child-process-unsupported.d.ts.map +1 -0
- package/dist/child-process-unsupported.js +13 -0
- package/dist/child-process-unsupported.js.map +1 -0
- package/dist/globals.d.ts +113 -0
- package/dist/globals.d.ts.map +1 -0
- package/dist/globals.js +58 -0
- package/dist/globals.js.map +1 -0
- package/dist/http-client.d.ts +64 -0
- package/dist/http-client.d.ts.map +1 -0
- package/dist/http-client.js +182 -0
- package/dist/http-client.js.map +1 -0
- package/dist/http.d.ts +143 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +349 -0
- package/dist/http.js.map +1 -0
- package/dist/http2-unsupported.d.ts +4 -0
- package/dist/http2-unsupported.d.ts.map +1 -0
- package/dist/http2-unsupported.js +11 -0
- package/dist/http2-unsupported.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/modules.d.ts +8 -0
- package/dist/modules.d.ts.map +1 -0
- package/dist/modules.js +19 -0
- package/dist/modules.js.map +1 -0
- package/dist/net.d.ts +59 -0
- package/dist/net.d.ts.map +1 -0
- package/dist/net.js +273 -0
- package/dist/net.js.map +1 -0
- package/dist/network/diagnostics-channel.d.ts +34 -0
- package/dist/network/diagnostics-channel.d.ts.map +1 -0
- package/dist/network/diagnostics-channel.js +92 -0
- package/dist/network/diagnostics-channel.js.map +1 -0
- package/dist/network/dns.d.ts +12 -0
- package/dist/network/dns.d.ts.map +1 -0
- package/dist/network/dns.js +44 -0
- package/dist/network/dns.js.map +1 -0
- package/dist/network/tls.d.ts +12 -0
- package/dist/network/tls.d.ts.map +1 -0
- package/dist/network/tls.js +14 -0
- package/dist/network/tls.js.map +1 -0
- package/dist/performance.d.ts +9 -0
- package/dist/performance.d.ts.map +1 -0
- package/dist/performance.js +10 -0
- package/dist/performance.js.map +1 -0
- package/dist/runtime.d.ts +249 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +258 -0
- package/dist/runtime.js.map +1 -0
- package/package.json +108 -4
package/README.md
CHANGED
|
@@ -1,3 +1,173 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @crvouga/mockingbird-adapter-browser
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> Local emulators. Real API contracts. Part of [Mockingbird](https://github.com/crvouga-organization/mockingbird).
|
|
4
|
+
|
|
5
|
+
Run server-oriented JavaScript in static, browser-local system previews. This adapter supplies a
|
|
6
|
+
shared virtual filesystem and network plus a bundler configuration for Node standard-library
|
|
7
|
+
polyfills. It is an explicit compatibility layer, not a complete Node, Bun or Deno implementation.
|
|
8
|
+
Native executables and arbitrary server packages cannot all run through JavaScript polyfills.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install @crvouga/mockingbird-adapter-browser esbuild
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
Build the runtime package, then use its configuration in your esbuild task:
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { build } from "esbuild"
|
|
22
|
+
import { browserRuntimeBuildOptions } from "@crvouga/mockingbird-adapter-browser/build"
|
|
23
|
+
|
|
24
|
+
await build({
|
|
25
|
+
...browserRuntimeBuildOptions(),
|
|
26
|
+
entryPoints: ["src/preview.ts"],
|
|
27
|
+
bundle: true,
|
|
28
|
+
format: "esm",
|
|
29
|
+
splitting: true,
|
|
30
|
+
outdir: "preview-dist",
|
|
31
|
+
})
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Your preview entry installs the runtime **before** importing server entrypoints:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { installBrowserRuntime } from "@crvouga/mockingbird-adapter-browser"
|
|
38
|
+
|
|
39
|
+
const dispose = installBrowserRuntime()
|
|
40
|
+
const entrypoint = "./system.js"
|
|
41
|
+
await import(entrypoint)
|
|
42
|
+
// When the entire preview ends: dispose()
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The lab's standalone preview uses this build configuration. Existing browser-compatible code
|
|
46
|
+
keeps its Fetch API contracts. The docs embed does not install globals into its parent page.
|
|
47
|
+
|
|
48
|
+
## API
|
|
49
|
+
|
|
50
|
+
- `browserRuntime`: the shared world used by bundled Node imports, Bun and Deno.
|
|
51
|
+
- `createBrowserRuntime({ env?, networkFetch? })`: an isolated world with `fs`, `net`, `env`,
|
|
52
|
+
`bun`, `deno`, `fetch`, `mountAssets` and `dispose`. `mountAssets` accepts explicit absolute
|
|
53
|
+
virtual paths and text/bytes; paths containing parent traversal are rejected.
|
|
54
|
+
- `installBrowserRuntime()`: install Bun, Deno and virtual fetch in this realm; returns its disposer.
|
|
55
|
+
- `UnsupportedRuntimeError`: an error with `ERR_BROWSER_RUNTIME_UNSUPPORTED`.
|
|
56
|
+
- `browserRuntimeBuildOptions(options?)` from `/build`: composable esbuild settings described below.
|
|
57
|
+
|
|
58
|
+
## Framework build options
|
|
59
|
+
|
|
60
|
+
`browserRuntimeBuildOptions` accepts explicit configuration rather than scanning an application's
|
|
61
|
+
filesystem or inheriting its environment:
|
|
62
|
+
|
|
63
|
+
- `adapters`: map a module name (bare or `node:`) to an absolute build-time adapter path. This is an
|
|
64
|
+
explicit compatibility choice, including otherwise unsupported builtins. Native `.node` files
|
|
65
|
+
are still refused. Framework imports can use browser implementations of their own dependencies.
|
|
66
|
+
- `optionalModules`: explicit optional imports that throw `ERR_BROWSER_RUNTIME_UNSUPPORTED` when
|
|
67
|
+
evaluated; they never become empty mocks. Use only for capabilities the app does not invoke.
|
|
68
|
+
- `modules`: a finite map of module names to absolute build-time files. `createRequire` from
|
|
69
|
+
`node:module` then loads only that manifest, caches results and rejects unknown names with
|
|
70
|
+
`MODULE_NOT_FOUND`. Its filename argument does not add filesystem resolution. Dependencies are
|
|
71
|
+
bundled, never loaded from the build machine at runtime.
|
|
72
|
+
- `assets`: explicit virtual filenames and public text/bytes, mounted before the entrypoint runs.
|
|
73
|
+
No directory is scanned. Files supplied here are visible to every visitor.
|
|
74
|
+
- `sourceRoot`: replace `__filename`, `__dirname` and `import.meta` locations under this absolute
|
|
75
|
+
root with virtual paths. Use minification and no source maps if build-machine paths must not
|
|
76
|
+
appear in esbuild's own comments or source metadata.
|
|
77
|
+
- `transformSource`: an async source compiler hook returning `{ contents, loader? }` or undefined.
|
|
78
|
+
A host can use TypeScript or SWC to emit legacy decorator metadata before esbuild bundles it.
|
|
79
|
+
- `virtualNetwork: true`: opt into virtual Node sockets, loopback-only DNS and in-memory diagnostic
|
|
80
|
+
channels. TLS imports are allowed but every operation throws explicitly; no OS sockets open.
|
|
81
|
+
- `asyncContext: "zone"`: opt into the execution contract below.
|
|
82
|
+
|
|
83
|
+
App entrypoints, routes, environment allowlists, seed data and application-specific framework
|
|
84
|
+
choices stay with the host. These hooks do not imply arbitrary Nest or Next applications run unchanged.
|
|
85
|
+
|
|
86
|
+
## Async context execution contract
|
|
87
|
+
|
|
88
|
+
By default `node:async_hooks` fails at build time. Opting into `asyncContext: "zone"` supplies
|
|
89
|
+
`AsyncLocalStorage` and `AsyncResource` through Zone.js and forces esbuild to lower **every bundled
|
|
90
|
+
async function and async generator**, including dependencies, into instrumented Promise continuations.
|
|
91
|
+
It refuses options that retain native async functions or mark modules external. This is not a
|
|
92
|
+
Promise.then patch claimed to support native async/await.
|
|
93
|
+
|
|
94
|
+
The bundle must own a dedicated iframe/worker realm. Zone.js patches Promise and scheduling in that
|
|
95
|
+
realm; disposal does not uninstall Zone.js. Destroy the realm when the preview ends. Do not evaluate
|
|
96
|
+
untransformed code, dynamically import external native-async modules, or share the realm with an
|
|
97
|
+
unrelated application. A browser API that schedules callbacks outside Zone's patched integrations
|
|
98
|
+
needs its own verified adapter. Unsupported native async execution has no context-isolation guarantee.
|
|
99
|
+
|
|
100
|
+
Supported context operations are `getStore`, `run`, `exit`, `disable`, static `bind`/`snapshot`, and
|
|
101
|
+
`AsyncResource.runInAsyncScope`/`bind`/`emitDestroy`. `enterWith`, async IDs and lifecycle hooks throw
|
|
102
|
+
explicit unsupported errors. Chromium tests prove overlapping lowered async requests, nested scopes,
|
|
103
|
+
Promise callbacks, timers, errors, bound callbacks, disabled stores and destroyed resources.
|
|
104
|
+
|
|
105
|
+
## Compatibility
|
|
106
|
+
|
|
107
|
+
| Surface | Implementation and scope |
|
|
108
|
+
| --- | --- |
|
|
109
|
+
| `Buffer`, `process`, `global` | Injected into bundled modules; process is the browser implementation, not a host OS process. Environment starts empty, never inherits build-machine secrets. |
|
|
110
|
+
| `fs`, `fs/promises` | memfs: shared in-memory files, directories, streams, synchronous/callback/promise APIs. Data disappears on dispose/reload. |
|
|
111
|
+
| `path`, `path/posix`, `url`, `querystring`, `punycode` | Browser standard-library implementations; no host filesystem access. |
|
|
112
|
+
| `events`, `stream`, `string_decoder`, `util`, `assert` | node-stdlib-browser implementations; `assert/strict` default export supported. |
|
|
113
|
+
| `stream/web` | Native browser Web Streams. |
|
|
114
|
+
| `stream/promises` | Promise wrappers for pipeline and finished; no Node-specific options beyond the underlying implementation. |
|
|
115
|
+
| `crypto` | Browserify hashing, HMAC, PBKDF2, cipher/signature functions; browser Web Crypto, randomUUID and getRandomValues. Not every Node algorithm/API is implemented. |
|
|
116
|
+
| `zlib` | Browserify gzip/deflate; no native Brotli/Zstd guarantee. |
|
|
117
|
+
| `timers`, `timers/promises`, `console`, `os`, `constants`, `domain` | Browser implementations from node-stdlib-browser. OS information is synthetic. Timers use browser time. |
|
|
118
|
+
| `http` outgoing / `https` | Browser HTTP clients; browser CORS, cookie and forbidden-header restrictions still apply. |
|
|
119
|
+
| `http.createServer(handler).listen(port[, hostname][, callback])` | Basic Node Readable request / Writable response contract, streaming response bodies, local virtual listener. Supports request method, URL, headers, response status/headers/body and close. Not a full Node Server/socket implementation or a guarantee that Express/Next run unchanged. |
|
|
120
|
+
| `vm` | Browserify compatibility only; **not a security sandbox**, may require dynamic-code CSP permissions. |
|
|
121
|
+
| `Bun.serve`, `Deno.serve` | Fetch handlers registered as virtual localhost endpoints, no sockets; supports port/hostname, shutdown and finished. TLS, WebSocket upgrades, socket options and runtime-specific handler context are unsupported. |
|
|
122
|
+
| `Bun.file`, `Bun.write`, `Bun.env`, `Bun.sleep` | Virtual-file read facade (text/json/arrayBuffer/stream/slice/exists/size), byte/string/blob/response writes, explicit env and browser timers. The file facade is not a branded Blob for `new Response(Bun.file(...))`; use its stream or bytes. |
|
|
123
|
+
| Deno file APIs | readFile/readTextFile/writeFile/writeTextFile/mkdir/remove/rename (async and sync), stat/statSync, realPath/realPathSync, readDir, cwd, env on the same virtual filesystem. Node-style filesystem errors, not Deno's error classes. |
|
|
124
|
+
|
|
125
|
+
Both `node:` imports and bare Node module imports are mapped. The `bun` module exposes the same implemented Bun functions as the injected global. Unknown `node:` modules, native
|
|
126
|
+
`.node` addons, `bun:` builtins, child_process, cluster, dgram, dns, http2, net, tls, worker_threads,
|
|
127
|
+
async_hooks, module loading, terminal/readline/repl, inspector and v8 are rejected during builds.
|
|
128
|
+
Unknown Bun/Deno properties throw `ERR_BROWSER_RUNTIME_UNSUPPORTED` on access. Runtime version
|
|
129
|
+
probing and feature detection therefore need deliberate adaptation; the layer does not impersonate
|
|
130
|
+
a complete installed runtime. Raw TCP/TLS, OS processes, native addons, runtime compilers, arbitrary
|
|
131
|
+
npm/jsr/URL resolution at runtime and other language interpreters require separate explicit adapters
|
|
132
|
+
or suitable WASM runtimes. They are not supplied here.
|
|
133
|
+
|
|
134
|
+
## Worlds, routing and isolation
|
|
135
|
+
|
|
136
|
+
One bundled realm shares one world across Node fs/process and Bun/Deno. Separate iframes/workers
|
|
137
|
+
give systems separate globals; `createBrowserRuntime()` creates isolated worlds for injected-port
|
|
138
|
+
code and tests without changing globals.
|
|
139
|
+
|
|
140
|
+
The virtual network recognizes localhost, 127.0.0.1, 0.0.0.0 and [::1]. A missing listener rejects
|
|
141
|
+
locally: it never falls through to a real service on the user's machine. Ports cannot collide;
|
|
142
|
+
port zero allocates an available virtual port. Requests preserve method/body/headers and support
|
|
143
|
+
abort. Node response headers and bytes are available before end, with cancellation and stream errors. No cross-tab network, virtual DNS for arbitrary hostnames, service-worker interception or
|
|
144
|
+
websocket transport is implied.
|
|
145
|
+
|
|
146
|
+
Instances created through `createBrowserRuntime()` have external network access disabled unless
|
|
147
|
+
a fetch port is supplied. The installed browser singleton permits normal browser fetch for external
|
|
148
|
+
origins. Its globals are for trusted preview code, not a security boundary. Environment values
|
|
149
|
+
and files delivered to the browser are visible to the visitor; never put production secrets there.
|
|
150
|
+
|
|
151
|
+
## Framework fixtures and limits
|
|
152
|
+
|
|
153
|
+
Chromium fixtures execute an actual Fastify HTTP route and an actual Nest dependency-injected,
|
|
154
|
+
decorated controller over Fastify. The Nest fixture explicitly excludes optional validation,
|
|
155
|
+
microservice, WebSocket, static/view and Express dependencies it never invokes; using those requires
|
|
156
|
+
additional adapters. HTTP/2 has an explicit fail-on-use adapter at `/http2-unsupported`.
|
|
157
|
+
|
|
158
|
+
A Next fixture exercises real `NextRequest`/`NextResponse` and React streamed server rendering with
|
|
159
|
+
overlapping request contexts. It is not a complete Next application build, route loader, image
|
|
160
|
+
optimizer or filesystem router qualification. The host still owns the appropriate framework entrypoint.
|
|
161
|
+
|
|
162
|
+
The `perf_hooks` adapter exposes browser `performance`/`PerformanceObserver`; Node histogram/event-loop
|
|
163
|
+
sampling throws. `process.hrtime` and `uptime` use monotonic browser time. Diagnostic channels support
|
|
164
|
+
subscription, publication, store binding and synchronous tracing; `tracePromise` and `traceCallback`
|
|
165
|
+
throw explicit unsupported errors. Transport-specific exports are `/http`, `/net`, `/network/dns`,
|
|
166
|
+
`/network/tls` and `/network/diagnostics-channel` for hosts using injected worlds or explicit adapters.
|
|
167
|
+
|
|
168
|
+
## Validation
|
|
169
|
+
|
|
170
|
+
`bun test` checks world isolation, shared Bun/Deno files, missing paths, listener collisions,
|
|
171
|
+
shutdown, abort, explicit unsupported APIs and rejected native imports. A bundled Chromium
|
|
172
|
+
contract test runs real Node imports (hashing/compression/events/files) and Node/Bun/Deno servers
|
|
173
|
+
together, rather than accidentally testing the machine's native runtime.
|
package/TRANSPORT.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Browser-local Node transports
|
|
2
|
+
|
|
3
|
+
`browserRuntimeBuildOptions({ virtualNetwork: true })` opts into virtual `node:net` sockets.
|
|
4
|
+
The default build still refuses that import. The virtual network never opens OS sockets,
|
|
5
|
+
performs external DNS, or connects to the visitor's real localhost services.
|
|
6
|
+
|
|
7
|
+
Each `createBrowserRuntime()` owns `net`. Use `world.net.createServer(socket =>
|
|
8
|
+
wireServer.accept(socket)).listen(port)` to bind the existing Postgres or Redis `/transport`
|
|
9
|
+
server. The clients can use the bundled Node `net` API against the singleton, or accept the
|
|
10
|
+
world's `Socket` through their explicit stream injection option. Separate worlds can bind the
|
|
11
|
+
same port. Duplicate listeners fail; port zero chooses a free virtual port; absent listeners
|
|
12
|
+
reject with `ECONNREFUSED`. Bytes and backpressure flow through Node-compatible Duplex streams.
|
|
13
|
+
|
|
14
|
+
`createHttpAdapter(world)` from the HTTP module binds Node handlers to that world's Fetch
|
|
15
|
+
listeners. The default Node HTTP exports use the singleton world. Responses expose headers
|
|
16
|
+
before completion, stream bytes under consumer backpressure, and propagate errors after headers
|
|
17
|
+
to the response body. Request abort and response-body cancellation close the paired streams.
|
|
18
|
+
HEAD, 204, 205 and 304 responses have no body. Repeated Set-Cookie header values are preserved
|
|
19
|
+
by the Node response API; browser Fetch still imposes its normal cookie visibility rules.
|
|
20
|
+
|
|
21
|
+
Closing a virtual server or disposing the world terminates active connections immediately. This
|
|
22
|
+
is deliberate preview teardown behavior, not Node's graceful server-close guarantee. TCP sockets and HTTP listeners share port collision checks within a world. No TLS, Unix socket, TCP congestion-control,
|
|
23
|
+
WebSocket upgrade, HTTP/2, cluster, sentinel or general DNS fidelity is claimed.
|
|
24
|
+
|
|
25
|
+
For clients that eagerly import optional Node capabilities, explicitly supplied adapters may
|
|
26
|
+
be necessary. The included `src/network/tls.ts` throws for every TLS operation; `dns.ts` supports
|
|
27
|
+
only loopback lookup and refuses SRV; `diagnostics-channel.ts` supplies the documented in-memory
|
|
28
|
+
diagnostic channels and rejects unsupported tracing operations. They are never activated by default. A client configured to use TLS must
|
|
29
|
+
fail, not silently downgrade to plaintext. Framework async context is a separate build option.
|
|
30
|
+
|
|
31
|
+
The transport tests cover first-byte delivery before end, backpressure, abort/cancellation,
|
|
32
|
+
pre-header and streamed errors, cookies/no-body responses, TCP byte exchange, isolation,
|
|
33
|
+
collisions and disposal. The Chromium contract additionally bundles real pg, ioredis and Express
|
|
34
|
+
against the emulator transports. This proves the named fixture operations, not complete
|
|
35
|
+
compatibility with every API of those packages.
|
|
36
|
+
|
|
37
|
+
## Outgoing Node requests
|
|
38
|
+
|
|
39
|
+
`createFetchHttpClient(fetch, protocol)` from `./http-client` supplies Node-style `request` and
|
|
40
|
+
`get` over a host-owned Fetch port. Request bodies are buffered until `end`; response bytes stream
|
|
41
|
+
through a Readable with backpressure, cancellation and error propagation. The explicit module
|
|
42
|
+
adapter's default exports use the current global Fetch function and HTTPS as the default protocol.
|
|
43
|
+
The host owns routing and refusal of unmatched destinations; this adapter is not an outbound
|
|
44
|
+
allowlist. It opens no native socket and performs no connection pooling. HTTP/2 and TLS socket
|
|
45
|
+
operations remain unsupported. The FCM Chromium fixture verifies the real Firebase Admin SDK's
|
|
46
|
+
single-send and legacy multicast paths against strict local emulator authentication.
|
package/dist/assets.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAM,CAAA"}
|
package/dist/assets.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets.js","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,MAAM,CAAC,MAAM,YAAY,GAAgD,EAAE,CAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import "zone.js";
|
|
2
|
+
/** Requires the build adapter's whole-bundle async/await lowering contract. */
|
|
3
|
+
export declare class AsyncLocalStorage<Store> {
|
|
4
|
+
private key;
|
|
5
|
+
getStore(): Store | undefined;
|
|
6
|
+
run<Args extends unknown[], Result>(store: Store, callback: (...args: Args) => Result, ...args: Args): Result;
|
|
7
|
+
exit<Args extends unknown[], Result>(callback: (...args: Args) => Result, ...args: Args): Result;
|
|
8
|
+
enterWith(_store: Store): never;
|
|
9
|
+
disable(): void;
|
|
10
|
+
static bind<Args extends unknown[], Result>(callback: (...args: Args) => Result): (this: unknown, ...args: Args) => Result;
|
|
11
|
+
static snapshot(): <Args extends unknown[], Result>(callback: (...args: Args) => Result, ...args: Args) => Result;
|
|
12
|
+
}
|
|
13
|
+
export declare class AsyncResource {
|
|
14
|
+
readonly type: string;
|
|
15
|
+
private readonly zone;
|
|
16
|
+
private destroyed;
|
|
17
|
+
constructor(type: string);
|
|
18
|
+
runInAsyncScope<Args extends unknown[], Result>(callback: (...args: Args) => Result, thisArg?: unknown, ...args: Args): Result;
|
|
19
|
+
bind<Args extends unknown[], Result>(callback: (...args: Args) => Result): (this: unknown, ...args: Args) => Result;
|
|
20
|
+
emitDestroy(): this;
|
|
21
|
+
asyncId(): never;
|
|
22
|
+
triggerAsyncId(): never;
|
|
23
|
+
static bind: typeof AsyncLocalStorage.bind;
|
|
24
|
+
}
|
|
25
|
+
export declare const createHook: () => never;
|
|
26
|
+
export declare const executionAsyncId: () => never;
|
|
27
|
+
export declare const triggerAsyncId: () => never;
|
|
28
|
+
export declare const executionAsyncResource: () => never;
|
|
29
|
+
//# sourceMappingURL=async-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-context.d.ts","sourceRoot":"","sources":["../src/async-context.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,CAAA;AAQhB,+EAA+E;AAC/E,qBAAa,iBAAiB,CAAC,KAAK;IAClC,OAAO,CAAC,GAAG,CAAqC;IAChD,QAAQ,IAAI,KAAK,GAAG,SAAS;IAG7B,GAAG,CAAC,IAAI,SAAS,OAAO,EAAE,EAAE,MAAM,EAChC,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,EACnC,GAAG,IAAI,EAAE,IAAI,GACZ,MAAM;IAKT,IAAI,CAAC,IAAI,SAAS,OAAO,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,EAAE,GAAG,IAAI,EAAE,IAAI,GAAG,MAAM;IAKhG,SAAS,CAAC,MAAM,EAAE,KAAK,GAAG,KAAK;IAG/B,OAAO,IAAI,IAAI;IAGf,MAAM,CAAC,IAAI,CAAC,IAAI,SAAS,OAAO,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,IAE5D,MAAM,OAAO,EAAE,GAAG,MAAM,IAAI,KAAG,MAAM;IAIxD,MAAM,CAAC,QAAQ,KAEL,IAAI,SAAS,OAAO,EAAE,EAAE,MAAM,EACpC,UAAU,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,EACnC,GAAG,MAAM,IAAI,KACZ,MAAM;CAEZ;AAED,qBAAa,aAAa;IAGZ,QAAQ,CAAC,IAAI,EAAE,MAAM;IAFjC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAe;IACpC,OAAO,CAAC,SAAS,CAAQ;gBACJ,IAAI,EAAE,MAAM;IACjC,eAAe,CAAC,IAAI,SAAS,OAAO,EAAE,EAAE,MAAM,EAC5C,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,EACnC,OAAO,CAAC,EAAE,OAAO,EACjB,GAAG,IAAI,EAAE,IAAI,GACZ,MAAM;IAIT,IAAI,CAAC,IAAI,SAAS,OAAO,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,IAErD,MAAM,OAAO,EAAE,GAAG,MAAM,IAAI,KAAG,MAAM;IAIxD,WAAW,IAAI,IAAI;IAInB,OAAO,IAAI,KAAK;IAGhB,cAAc,IAAI,KAAK;IAGvB,MAAM,CAAC,IAAI,gCAAyB;CACrC;AACD,eAAO,MAAM,UAAU,QAAO,KAAkC,CAAA;AAChE,eAAO,MAAM,gBAAgB,QAAO,KAAwC,CAAA;AAC5E,eAAO,MAAM,cAAc,QAAO,KAAsC,CAAA;AACxE,eAAO,MAAM,sBAAsB,QAAO,KAA8C,CAAA"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import "zone.js";
|
|
2
|
+
import { UnsupportedRuntimeError } from "./runtime.js";
|
|
3
|
+
let nextKey = 1;
|
|
4
|
+
const unavailable = (name) => {
|
|
5
|
+
throw new UnsupportedRuntimeError(`async_hooks.${name}`);
|
|
6
|
+
};
|
|
7
|
+
/** Requires the build adapter's whole-bundle async/await lowering contract. */
|
|
8
|
+
export class AsyncLocalStorage {
|
|
9
|
+
key = `mockingbird-context-${nextKey++}`;
|
|
10
|
+
getStore() {
|
|
11
|
+
return Zone.current.get(this.key);
|
|
12
|
+
}
|
|
13
|
+
run(store, callback, ...args) {
|
|
14
|
+
return Zone.current
|
|
15
|
+
.fork({ name: this.key, properties: { [this.key]: store } })
|
|
16
|
+
.run(callback, undefined, args);
|
|
17
|
+
}
|
|
18
|
+
exit(callback, ...args) {
|
|
19
|
+
return Zone.current
|
|
20
|
+
.fork({ name: this.key, properties: { [this.key]: undefined } })
|
|
21
|
+
.run(callback, undefined, args);
|
|
22
|
+
}
|
|
23
|
+
enterWith(_store) {
|
|
24
|
+
return unavailable("AsyncLocalStorage.enterWith; use run");
|
|
25
|
+
}
|
|
26
|
+
disable() {
|
|
27
|
+
this.key = `mockingbird-context-${nextKey++}`;
|
|
28
|
+
}
|
|
29
|
+
static bind(callback) {
|
|
30
|
+
const zone = Zone.current;
|
|
31
|
+
return function (...args) {
|
|
32
|
+
return zone.run(callback, this, args);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
static snapshot() {
|
|
36
|
+
const zone = Zone.current;
|
|
37
|
+
return (callback, ...args) => zone.run(callback, undefined, args);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export class AsyncResource {
|
|
41
|
+
type;
|
|
42
|
+
zone = Zone.current;
|
|
43
|
+
destroyed = false;
|
|
44
|
+
constructor(type) {
|
|
45
|
+
this.type = type;
|
|
46
|
+
}
|
|
47
|
+
runInAsyncScope(callback, thisArg, ...args) {
|
|
48
|
+
if (this.destroyed)
|
|
49
|
+
throw new Error("AsyncResource has been destroyed");
|
|
50
|
+
return this.zone.run(callback, thisArg, args);
|
|
51
|
+
}
|
|
52
|
+
bind(callback) {
|
|
53
|
+
const resource = this;
|
|
54
|
+
return function (...args) {
|
|
55
|
+
return resource.runInAsyncScope(callback, this, ...args);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
emitDestroy() {
|
|
59
|
+
this.destroyed = true;
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
asyncId() {
|
|
63
|
+
return unavailable("AsyncResource.asyncId");
|
|
64
|
+
}
|
|
65
|
+
triggerAsyncId() {
|
|
66
|
+
return unavailable("AsyncResource.triggerAsyncId");
|
|
67
|
+
}
|
|
68
|
+
static bind = AsyncLocalStorage.bind;
|
|
69
|
+
}
|
|
70
|
+
export const createHook = () => unavailable("createHook");
|
|
71
|
+
export const executionAsyncId = () => unavailable("executionAsyncId");
|
|
72
|
+
export const triggerAsyncId = () => unavailable("triggerAsyncId");
|
|
73
|
+
export const executionAsyncResource = () => unavailable("executionAsyncResource");
|
|
74
|
+
//# sourceMappingURL=async-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-context.js","sourceRoot":"","sources":["../src/async-context.ts"],"names":[],"mappings":"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"}
|
package/dist/build.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { BuildOptions, Loader } from "esbuild";
|
|
2
|
+
export type BrowserBuildOptions = {
|
|
3
|
+
/** Explicit replacements, including otherwise unsupported builtins. Values must be absolute. */
|
|
4
|
+
adapters?: Readonly<Record<string, string>>;
|
|
5
|
+
/** Finite manifest for dynamic require/createRequire; nothing is read from the host at runtime. */
|
|
6
|
+
modules?: Readonly<Record<string, string>>;
|
|
7
|
+
/** Explicit optional dependencies that throw when evaluated, never become empty modules. */
|
|
8
|
+
optionalModules?: readonly string[];
|
|
9
|
+
/** Explicit public files mounted before entrypoints evaluate. Never enumerate a host directory. */
|
|
10
|
+
assets?: Readonly<Record<string, string | Uint8Array>>;
|
|
11
|
+
/** Optional source compiler for framework decorators or other syntax esbuild does not support. */
|
|
12
|
+
transformSource?: (source: string, filename: string) => Promise<{
|
|
13
|
+
contents: string;
|
|
14
|
+
loader?: Loader;
|
|
15
|
+
} | undefined>;
|
|
16
|
+
/** Replace source locations by virtual paths relative to this root. */
|
|
17
|
+
sourceRoot?: string;
|
|
18
|
+
/** Enable virtual Node sockets; no OS networking is available. */
|
|
19
|
+
virtualNetwork?: boolean;
|
|
20
|
+
/** Zone context requires every bundled async function to be lowered, including dependencies. */
|
|
21
|
+
asyncContext?: "zone";
|
|
22
|
+
};
|
|
23
|
+
/** esbuild configuration shared by hosts; no environment values are copied from the build machine. */
|
|
24
|
+
export declare function browserRuntimeBuildOptions(options?: BrowserBuildOptions): Pick<BuildOptions, "plugins" | "inject" | "platform" | "target" | "supported">;
|
|
25
|
+
//# sourceMappingURL=build.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAU,MAAM,SAAS,CAAA;AAsC3D,MAAM,MAAM,mBAAmB,GAAG;IAChC,gGAAgG;IAChG,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IAC3C,mGAAmG;IACnG,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IAC1C,4FAA4F;IAC5F,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IACnC,mGAAmG;IACnG,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC,CAAA;IACtD,kGAAkG;IAClG,eAAe,CAAC,EAAE,CAChB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,KACb,OAAO,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC,CAAA;IAC/D,uEAAuE;IACvE,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,kEAAkE;IAClE,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,gGAAgG;IAChG,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,sGAAsG;AACtG,wBAAgB,0BAA0B,CACxC,OAAO,GAAE,mBAAwB,GAChC,IAAI,CAAC,YAAY,EAAE,SAAS,GAAG,QAAQ,GAAG,UAAU,GAAG,QAAQ,GAAG,WAAW,CAAC,CAoPhF"}
|