@databehave/server 0.1.4 → 0.2.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/CHANGELOG.md +17 -0
- package/README.md +85 -83
- package/dist/cors.d.ts +1 -1
- package/dist/cors.js +1 -1
- package/dist/cors.js.map +1 -1
- package/dist/http.d.ts +94 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +23 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +10 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -18
- package/dist/index.js.map +1 -1
- package/dist/log.d.ts +9 -49
- package/dist/log.d.ts.map +1 -1
- package/dist/log.js +16 -92
- package/dist/log.js.map +1 -1
- package/dist/node-authority.d.ts +12 -0
- package/dist/node-authority.d.ts.map +1 -0
- package/dist/node-authority.js +72 -0
- package/dist/node-authority.js.map +1 -0
- package/dist/node-body.d.ts +11 -0
- package/dist/node-body.d.ts.map +1 -0
- package/dist/node-body.js +61 -0
- package/dist/node-body.js.map +1 -0
- package/dist/node-http.d.ts +19 -0
- package/dist/node-http.d.ts.map +1 -0
- package/dist/node-http.js +210 -0
- package/dist/node-http.js.map +1 -0
- package/dist/plugins/access-log.d.ts +11 -0
- package/dist/plugins/access-log.d.ts.map +1 -0
- package/dist/plugins/access-log.js +27 -0
- package/dist/plugins/access-log.js.map +1 -0
- package/dist/plugins/cors.d.ts +5 -0
- package/dist/plugins/cors.d.ts.map +1 -0
- package/dist/plugins/cors.js +35 -0
- package/dist/plugins/cors.js.map +1 -0
- package/dist/plugins/routes.d.ts +5 -0
- package/dist/plugins/routes.d.ts.map +1 -0
- package/dist/plugins/routes.js +10 -0
- package/dist/plugins/routes.js.map +1 -0
- package/dist/request.d.ts +2 -2
- package/dist/request.d.ts.map +1 -1
- package/dist/request.js +6 -4
- package/dist/request.js.map +1 -1
- package/dist/route-key.d.ts +2 -0
- package/dist/route-key.d.ts.map +1 -1
- package/dist/route-key.js +5 -1
- package/dist/route-key.js.map +1 -1
- package/dist/server.d.ts +7 -59
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +289 -466
- package/dist/server.js.map +1 -1
- package/dist/types.d.ts +10 -156
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/package.json +9 -22
- package/dist/admin/admin-routes.d.ts +0 -42
- package/dist/admin/admin-routes.d.ts.map +0 -1
- package/dist/admin/admin-routes.js +0 -472
- package/dist/admin/admin-routes.js.map +0 -1
- package/dist/admin/admin-types.d.ts +0 -170
- package/dist/admin/admin-types.d.ts.map +0 -1
- package/dist/admin/admin-types.js +0 -30
- package/dist/admin/admin-types.js.map +0 -1
- package/dist/admin/banner.d.ts +0 -11
- package/dist/admin/banner.d.ts.map +0 -1
- package/dist/admin/banner.js +0 -5
- package/dist/admin/banner.js.map +0 -1
- package/dist/admin/header-parser.d.ts +0 -14
- package/dist/admin/header-parser.d.ts.map +0 -1
- package/dist/admin/header-parser.js +0 -171
- package/dist/admin/header-parser.js.map +0 -1
- package/dist/admin/inject.d.ts +0 -48
- package/dist/admin/inject.d.ts.map +0 -1
- package/dist/admin/inject.js +0 -167
- package/dist/admin/inject.js.map +0 -1
- package/dist/admin/overrides-store.d.ts +0 -18
- package/dist/admin/overrides-store.d.ts.map +0 -1
- package/dist/admin/overrides-store.js +0 -100
- package/dist/admin/overrides-store.js.map +0 -1
- package/dist/admin/resolve-cors.d.ts +0 -22
- package/dist/admin/resolve-cors.d.ts.map +0 -1
- package/dist/admin/resolve-cors.js +0 -28
- package/dist/admin/resolve-cors.js.map +0 -1
- package/dist/admin/scenarios-store.d.ts +0 -15
- package/dist/admin/scenarios-store.d.ts.map +0 -1
- package/dist/admin/scenarios-store.js +0 -109
- package/dist/admin/scenarios-store.js.map +0 -1
- package/dist/admin/ui.css +0 -1
- package/dist/admin/ui.html +0 -13
- package/dist/admin/ui.js +0 -240
- package/dist/bin-helpers.d.ts +0 -46
- package/dist/bin-helpers.d.ts.map +0 -1
- package/dist/bin-helpers.js +0 -61
- package/dist/bin-helpers.js.map +0 -1
- package/dist/bin.d.ts +0 -3
- package/dist/bin.d.ts.map +0 -1
- package/dist/bin.js +0 -86
- package/dist/bin.js.map +0 -1
- package/dist/define.d.ts +0 -26
- package/dist/define.d.ts.map +0 -1
- package/dist/define.js +0 -55
- package/dist/define.js.map +0 -1
- package/dist/json-config.d.ts +0 -170
- package/dist/json-config.d.ts.map +0 -1
- package/dist/json-config.js +0 -684
- package/dist/json-config.js.map +0 -1
- package/dist/jsonc.d.ts +0 -24
- package/dist/jsonc.d.ts.map +0 -1
- package/dist/jsonc.js +0 -125
- package/dist/jsonc.js.map +0 -1
- package/dist/middleware/request-validation.d.ts +0 -58
- package/dist/middleware/request-validation.d.ts.map +0 -1
- package/dist/middleware/request-validation.js +0 -328
- package/dist/middleware/request-validation.js.map +0 -1
- package/dist/mock-mode.d.ts +0 -95
- package/dist/mock-mode.d.ts.map +0 -1
- package/dist/mock-mode.js +0 -95
- package/dist/mock-mode.js.map +0 -1
- package/dist/openapi/auto-schema.d.ts +0 -83
- package/dist/openapi/auto-schema.d.ts.map +0 -1
- package/dist/openapi/auto-schema.js +0 -232
- package/dist/openapi/auto-schema.js.map +0 -1
- package/dist/openapi/generate.d.ts +0 -20
- package/dist/openapi/generate.d.ts.map +0 -1
- package/dist/openapi/generate.js +0 -121
- package/dist/openapi/generate.js.map +0 -1
- package/dist/openapi/loader.d.ts +0 -18
- package/dist/openapi/loader.d.ts.map +0 -1
- package/dist/openapi/loader.js +0 -25
- package/dist/openapi/loader.js.map +0 -1
- package/dist/openapi/register.d.ts +0 -58
- package/dist/openapi/register.d.ts.map +0 -1
- package/dist/openapi/register.js +0 -166
- package/dist/openapi/register.js.map +0 -1
- package/dist/openapi/seed.d.ts +0 -16
- package/dist/openapi/seed.d.ts.map +0 -1
- package/dist/openapi/seed.js +0 -58
- package/dist/openapi/seed.js.map +0 -1
- package/dist/openapi/translate.d.ts +0 -55
- package/dist/openapi/translate.d.ts.map +0 -1
- package/dist/openapi/translate.js +0 -319
- package/dist/openapi/translate.js.map +0 -1
- package/dist/openapi/walker.d.ts +0 -44
- package/dist/openapi/walker.d.ts.map +0 -1
- package/dist/openapi/walker.js +0 -15
- package/dist/openapi/walker.js.map +0 -1
- package/dist/run.d.ts +0 -27
- package/dist/run.d.ts.map +0 -1
- package/dist/run.js +0 -87
- package/dist/run.js.map +0 -1
- package/dist/validation/validate.d.ts +0 -38
- package/dist/validation/validate.d.ts.map +0 -1
- package/dist/validation/validate.js +0 -372
- package/dist/validation/validate.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
Upcoming package version: **0.2.0**. This section describes planned release contents, not a published release.
|
|
11
|
+
|
|
12
|
+
### Breaking changes
|
|
13
|
+
|
|
14
|
+
- Require Node.js 24 or 26; support and test majors 24 and 26. Drop Node.js 18, 20 and 22.
|
|
15
|
+
- Replace `createServer` and server-owned JSONC/CLI assembly with core host composition and explicit HTTP plugins.
|
|
16
|
+
- Move OpenAPI, request validation, admin UI, fault controls and CLI ownership to their separate packages.
|
|
17
|
+
- Move the shared drain timeout to `httpPlugin`; HTTP owns both in-process requests and response stream lifetimes.
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- Public route, middleware, bind-guard and route-source contracts with registration sealing and staged startup.
|
|
22
|
+
- Explicit Node transport, CORS and access logging plugins, authority validation, bounded shutdown and cancellation.
|
|
23
|
+
- Consistent HEAD fallback, response decoration, route precedence and single-outcome observation.
|
|
24
|
+
|
|
25
|
+
See [migration](../../MIGRATION.md) and [release procedures](../../docs/releasing.md).
|
|
26
|
+
|
|
10
27
|
## [0.1.0] - 2026-06-03
|
|
11
28
|
|
|
12
29
|
Initial public release of `@databehave/server`.
|
package/README.md
CHANGED
|
@@ -1,87 +1,89 @@
|
|
|
1
|
-
<!-- markdownlint-disable MD033 MD041 -->
|
|
2
|
-
|
|
3
|
-
<div align="center">
|
|
4
|
-
|
|
5
1
|
# @databehave/server
|
|
6
2
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
> `@databehave/schema` is declared as an optional peer dependency. Install it alongside `@databehave/server` whenever you enable auto-schema mode.
|
|
27
|
-
|
|
28
|
-
## A 60-second tour
|
|
29
|
-
|
|
30
|
-
**1. OpenAPI specs driven data** — realistic mock data derived from your OpenAPI document, with zero config. See [docs/openapi.md](docs/openapi.md) for the `openapi` field reference.
|
|
31
|
-
|
|
32
|
-
**2. Auto-schema mode (`@databehave/schema`)** — realistic distributions, referential integrity, and deterministic seeding. See [docs/openapi/auto-schema.md](docs/openapi/auto-schema.md) for the `schema` field reference (knobs, defaults, install hint).
|
|
33
|
-
|
|
34
|
-
**3. Full custom data** — hand-write response generators as modules, and point routes to them. The module exports a function that receives the request and returns a response shape. You can use `@databehave/schema` or any other data source.
|
|
35
|
-
|
|
36
|
-
**4. Admin UI** You have a UI to override any route's response, with the override "sticking" until you remove it. No code change required for error injection.
|
|
37
|
-
|
|
38
|
-
```jsonc
|
|
39
|
-
{
|
|
40
|
-
"server": {
|
|
41
|
-
"host": "127.0.0.1",
|
|
42
|
-
"port": "8000"
|
|
43
|
-
},
|
|
44
|
-
// 1. OpenAPI specs driven data
|
|
45
|
-
"openapi": "./openapi.json",
|
|
46
|
-
// 2. Auto-schema mode (Adds @databehave/schema data generation engine to OpenAPI specs)
|
|
47
|
-
"schema": { "enabled": true },
|
|
48
|
-
// 3. Full custom data
|
|
49
|
-
"endpoints": {
|
|
50
|
-
"GET /health": { "response": { "status": 200, "json": { "ok": true } } },
|
|
51
|
-
"GET /products/list": "./src/routes/products/list.js",
|
|
52
|
-
"POST /products/bulk-update": "./src/routes/products/bulk-update.js"
|
|
53
|
-
},
|
|
54
|
-
// 4. Admin UI: http://[server.host]:[server.port]/[admin.path]
|
|
55
|
-
"admin": { "enabled": true, "path": "/databehave" },
|
|
56
|
-
}
|
|
3
|
+
HTTP contracts and explicit HTTP plugins for Databehave. The package has no schema,
|
|
4
|
+
OpenAPI, admin, UI-build or CLI dependency.
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import { createHost } from '@databehave/core'
|
|
8
|
+
import {
|
|
9
|
+
httpPlugin, routesPlugin, corsPlugin, accessLogPlugin, nodeHttpPlugin,
|
|
10
|
+
} from '@databehave/server'
|
|
11
|
+
|
|
12
|
+
const host = createHost({ plugins: [
|
|
13
|
+
httpPlugin(),
|
|
14
|
+
routesPlugin({ 'GET /hello': () => ({ status: 200, json: { hello: 'world' } }) }),
|
|
15
|
+
corsPlugin({ origin: () => '*' }),
|
|
16
|
+
accessLogPlugin(),
|
|
17
|
+
nodeHttpPlugin({ host: '127.0.0.1', port: 3000 }),
|
|
18
|
+
] })
|
|
19
|
+
await host.start()
|
|
20
|
+
// await host.close() when the application shuts down.
|
|
57
21
|
```
|
|
58
22
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
23
|
+
For in-process requests, omit the listener and call
|
|
24
|
+
`host.get(httpCapability).fetch(new Request('http://localhost/hello'))` after startup.
|
|
25
|
+
|
|
26
|
+
External plugins declare `requires: [httpCapability]` and register route sources,
|
|
27
|
+
middleware or bind guards during `setup`. Pass `ctx.order` as the contribution order;
|
|
28
|
+
this preserves explicit composition order independently of capability dependency order.
|
|
29
|
+
Route sources materialize once after every plugin has prepared. Explicit routes replace
|
|
30
|
+
generated routes with the same key; equal-priority duplicates fail with both owners.
|
|
31
|
+
Exact paths precede parameterized paths. Parameterized ties use composition order and
|
|
32
|
+
then declaration order.
|
|
33
|
+
|
|
34
|
+
`http.resolveRoute(method, path)` uses the same precedence and HEAD fallback as dispatch. A route contribution's
|
|
35
|
+
`cors` field can override application CORS, or be `false` when its owner supplies the policy. General CORS only
|
|
36
|
+
handles resolved routes; preflights resolve the `Access-Control-Request-Method` target. Unknown paths receive no
|
|
37
|
+
implicit CORS authorization. This keeps feature-owned admin restrictions effective in either composition order.
|
|
38
|
+
|
|
39
|
+
The middleware pipeline runs preflight, validation, interception, the selected handler,
|
|
40
|
+
response decoration, and final observation. Short circuits and error responses receive
|
|
41
|
+
decoration once. Error handlers are bounded; an error-handler failure yields a generic
|
|
42
|
+
500. Observation cannot replace a response. HEAD calls an explicit HEAD handler or GET
|
|
43
|
+
fallback once, retains `request.method === 'HEAD'`, exposes `effectiveMethod`, and strips
|
|
44
|
+
the body after decoration. One request produces one observation.
|
|
45
|
+
|
|
46
|
+
`terminateTransport()` produces a terminal transport outcome for Node listeners.
|
|
47
|
+
Fetch cannot destroy a connection and reports `UnsupportedTransportError`. Request
|
|
48
|
+
signals cancel on disconnect or host shutdown. Dispatch is admitted only after HTTP's open
|
|
49
|
+
phase and rejects already-aborted callers before executing middleware or handlers. The HTTP
|
|
50
|
+
runtime stops admission synchronously, cancels work, then waits for handlers and returned
|
|
51
|
+
response bodies (EOF, error, or completed cancellation) before dependent resources are disposed.
|
|
52
|
+
HEAD-suppressed bodies are cancelled. Callers must consume or cancel returned bodies.
|
|
53
|
+
|
|
54
|
+
Configure the shared shutdown budget with `httpPlugin({ drainTimeoutMs: 1000 })` (1000 ms
|
|
55
|
+
by default). The deadline begins when admission stops and covers both logical requests and
|
|
56
|
+
Node connections; it is not restarted for each drain. The listener force-closes remaining
|
|
57
|
+
connections at that deadline. Uncooperative handlers or body cancellation report a failed
|
|
58
|
+
close instead of claiming a clean drain; callbacks cannot be forcibly stopped by JavaScript.
|
|
59
|
+
The former `nodeHttpPlugin({ drainTimeoutMs })` option moves to `httpPlugin`.
|
|
60
|
+
|
|
61
|
+
Node validates exactly one Host header and the origin-form request target before dispatch.
|
|
62
|
+
Host must use the actual listener port and match its binding, local socket address, or a
|
|
63
|
+
loopback alias for a loopback endpoint. For custom DNS use
|
|
64
|
+
`nodeHttpPlugin({ allowedHosts: ['app.example.test'] })`; entries are explicit hostnames or
|
|
65
|
+
IP literals, without ports, schemes, credentials, paths, or wildcards. Forwarded headers do
|
|
66
|
+
not grant authority. Malformed requests receive 400; unapproved authorities receive 421.
|
|
67
|
+
In-process Fetch requests remain trusted caller-supplied requests.
|
|
68
|
+
|
|
69
|
+
Incoming Node bodies are pulled in bounded chunks. Cancelling a body stops intake without
|
|
70
|
+
destroying the response socket, allowing early validation errors to reach uploading clients.
|
|
71
|
+
Incomplete uploads receive `Connection: close`, but remain readable while a response stream
|
|
72
|
+
consumes them. Explicit cancellation arms the rejection cleanup deadline immediately. Otherwise,
|
|
73
|
+
response-source completion stops remaining input and arms cleanup before waiting for the response
|
|
74
|
+
to flush. There is no ordinary response-write timeout; an uncancelled stalled duplex exchange
|
|
75
|
+
remains backpressured until completion, disconnection or bounded host shutdown. Fully read bodies
|
|
76
|
+
retain normal keep-alive behavior.
|
|
77
|
+
|
|
78
|
+
Feature packages use this same public boundary:
|
|
79
|
+
|
|
80
|
+
- [OpenAPI](../openapi/README.md): catalogs, selectable generators, validation and mock status policy.
|
|
81
|
+
- [Admin](../admin/README.md): opt-in fault injection, UI/API and scenarios.
|
|
82
|
+
- [CLI](../cli/README.md): explicit ESM composition and process lifecycle.
|
|
83
|
+
- [Core](../core/README.md): capability dependencies and lifecycle.
|
|
84
|
+
|
|
85
|
+
The upcoming 0.2 release removes the former JSONC configuration and monolithic `createServer` API.
|
|
86
|
+
See the [migration guide](../../MIGRATION.md) for the replacement of each option.
|
|
87
|
+
|
|
88
|
+
Requires Node.js 24 or 26; supported majors are 24 and 26. Start with the
|
|
89
|
+
[runnable HTTP example](../../examples/http.mjs) and [plugin author guide](../../docs/plugins.md).
|
package/dist/cors.d.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* migration stays backwards-compatible:
|
|
13
13
|
* - origin: mirror request `Origin`, or `*` when absent
|
|
14
14
|
* - credentials: header omitted by default; set `credentials: true` in
|
|
15
|
-
* `
|
|
15
|
+
* `corsPlugin` to send `Access-Control-Allow-Credentials: true`
|
|
16
16
|
*/
|
|
17
17
|
import type { CorsConfig, MockRequest, MockResponse } from './types.js';
|
|
18
18
|
/**
|
package/dist/cors.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const DEFAULT_METHODS = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'];
|
|
1
|
+
const DEFAULT_METHODS = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'];
|
|
2
2
|
const DEFAULT_HEADERS = ['content-type', 'authorization'];
|
|
3
3
|
const resolveOrigin = (cfg, reqOrigin) => {
|
|
4
4
|
if (cfg.origin)
|
package/dist/cors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cors.js","sourceRoot":"","sources":["../src/cors.ts"],"names":[],"mappings":"AAkBA,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"cors.js","sourceRoot":"","sources":["../src/cors.ts"],"names":[],"mappings":"AAkBA,MAAM,eAAe,GAAG,CAAC,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,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAA;IAC7C,MAAM,YAAY,GAAG,CAAC,GAAG,CAAC,YAAY,IAAI,eAAe,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACrE,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,gCAAgC,CAAC,CAAA;IAC/D,MAAM,YAAY,GAAG,qBAAqB,CAAC,SAAS,EAAE,GAAG,CAAC,YAAY,CAAC,CAAA;IACvE,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,EAAE,SAAS,CAAC,CAAA;IAC7C,MAAM,OAAO,GAA2B;QACtC,8BAA8B,EAAE,YAAY;QAC5C,wBAAwB,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,IAAI,MAAM,CAAC;QACtD,IAAI,EAAE,QAAQ;KACf,CAAA;IACD,4DAA4D;IAC5D,qEAAqE;IACrE,gEAAgE;IAChE,uDAAuD;IACvD,IAAI,YAAY,KAAK,EAAE,EAAE,CAAC;QACxB,OAAO,CAAC,8BAA8B,CAAC,GAAG,YAAY,CAAA;IACxD,CAAC;IACD,IAAI,OAAO,KAAK,EAAE;QAAE,OAAO,CAAC,6BAA6B,CAAC,GAAG,OAAO,CAAA;IACpE,IAAI,GAAG,CAAC,WAAW;QAAE,OAAO,CAAC,kCAAkC,CAAC,GAAG,MAAM,CAAA;IACzE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,CAAA;AAC9C,CAAC,CAAA"}
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { CorsConfig, Handler, Method, MockRequest, MockResponse, RouteKey } from './types.js';
|
|
2
|
+
/** A contributed route; explicit routes replace generated defaults with the same key. */
|
|
3
|
+
export interface RouteDefinition {
|
|
4
|
+
readonly key: RouteKey;
|
|
5
|
+
readonly handler: Handler;
|
|
6
|
+
readonly priority: 'explicit' | 'generated';
|
|
7
|
+
readonly source?: string;
|
|
8
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
9
|
+
/** Override application CORS, or false when the route owner supplies its own policy. */
|
|
10
|
+
readonly cors?: CorsConfig | false;
|
|
11
|
+
}
|
|
12
|
+
/** Registered in setup, materialized exactly once after every plugin has prepared. */
|
|
13
|
+
export interface RouteSource {
|
|
14
|
+
readonly owner: string;
|
|
15
|
+
readonly order: number;
|
|
16
|
+
materialize(): readonly RouteDefinition[];
|
|
17
|
+
}
|
|
18
|
+
/** Frozen resolved route metadata exposed after HTTP activation. Exact paths match first;
|
|
19
|
+
* parameterized ties follow source composition order, then source declaration order. */
|
|
20
|
+
export interface ResolvedRoute extends RouteDefinition {
|
|
21
|
+
readonly owner: string;
|
|
22
|
+
readonly method: Method;
|
|
23
|
+
readonly path: string;
|
|
24
|
+
}
|
|
25
|
+
/** Final outcome, including transport effects which cannot be represented by Fetch responses. */
|
|
26
|
+
export type HttpOutcome = {
|
|
27
|
+
readonly kind: 'response';
|
|
28
|
+
readonly response: Response;
|
|
29
|
+
} | {
|
|
30
|
+
readonly kind: 'terminate';
|
|
31
|
+
readonly reason: string;
|
|
32
|
+
};
|
|
33
|
+
/** One final observation per request, after decoration and HEAD body suppression. */
|
|
34
|
+
export interface HttpObservation {
|
|
35
|
+
readonly request: MockRequest;
|
|
36
|
+
readonly outcome: HttpOutcome;
|
|
37
|
+
readonly durationMs: number;
|
|
38
|
+
readonly error?: unknown;
|
|
39
|
+
}
|
|
40
|
+
/** Fixed pipeline phase with explicit composition order, independent of dependency sorting. */
|
|
41
|
+
export type HttpMiddleware = {
|
|
42
|
+
readonly owner: string;
|
|
43
|
+
readonly order: number;
|
|
44
|
+
} & ({
|
|
45
|
+
readonly stage: 'preflight' | 'validation' | 'interception';
|
|
46
|
+
readonly handle: (request: MockRequest) => MockResponse | void | Promise<MockResponse | void>;
|
|
47
|
+
} | {
|
|
48
|
+
readonly stage: 'decoration';
|
|
49
|
+
readonly handle: (request: MockRequest, response: MockResponse) => MockResponse | void | Promise<MockResponse | void>;
|
|
50
|
+
} | {
|
|
51
|
+
readonly stage: 'error';
|
|
52
|
+
readonly handle: (request: MockRequest, error: unknown) => MockResponse | void | Promise<MockResponse | void>;
|
|
53
|
+
} | {
|
|
54
|
+
readonly stage: 'observation';
|
|
55
|
+
readonly handle: (observation: HttpObservation) => void | Promise<void>;
|
|
56
|
+
});
|
|
57
|
+
/** Listener bind intent passed to every guard before any socket opens. */
|
|
58
|
+
export interface HttpBind {
|
|
59
|
+
readonly host: string;
|
|
60
|
+
readonly port: number;
|
|
61
|
+
}
|
|
62
|
+
/** Feature-owned policy registered before HTTP registration is sealed. */
|
|
63
|
+
export interface BindGuard {
|
|
64
|
+
readonly owner: string;
|
|
65
|
+
check(bind: HttpBind): void | Promise<void>;
|
|
66
|
+
}
|
|
67
|
+
/** HTTP registration, resolved catalog, request dispatch, and pre-bind policy contract. */
|
|
68
|
+
export interface HttpRuntime {
|
|
69
|
+
/** Shared logical/transport shutdown policy; deadline uses performance.now(). */
|
|
70
|
+
readonly drainTimeoutMs: number;
|
|
71
|
+
readonly drainDeadline: number | undefined;
|
|
72
|
+
registerRoutes(source: RouteSource): void;
|
|
73
|
+
registerMiddleware(middleware: HttpMiddleware): void;
|
|
74
|
+
registerBindGuard(guard: BindGuard): void;
|
|
75
|
+
readonly routes: readonly ResolvedRoute[];
|
|
76
|
+
/** Resolve with dispatch precedence, including HEAD fallback; available after activation. */
|
|
77
|
+
resolveRoute(method: string, path: string): ResolvedRoute | undefined;
|
|
78
|
+
checkBind(bind: HttpBind): Promise<void>;
|
|
79
|
+
dispatch(request: Request): Promise<HttpOutcome>;
|
|
80
|
+
fetch(request: Request): Promise<Response>;
|
|
81
|
+
}
|
|
82
|
+
export declare const httpCapability: import("@databehave/core").Capability<HttpRuntime>;
|
|
83
|
+
/** A terminal transport effect; the pipeline observes it without running response decorators. */
|
|
84
|
+
export declare class HttpTransportTermination extends Error {
|
|
85
|
+
constructor(message?: string);
|
|
86
|
+
}
|
|
87
|
+
/** Fetch has no socket to terminate; callers receive this explicit unsupported-effect error. */
|
|
88
|
+
export declare class UnsupportedTransportError extends Error {
|
|
89
|
+
readonly reason: string;
|
|
90
|
+
constructor(reason: string);
|
|
91
|
+
}
|
|
92
|
+
/** Terminate the actual HTTP connection when invoked by a handler or middleware. */
|
|
93
|
+
export declare const terminateTransport: (reason?: string) => never;
|
|
94
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAElG,yFAAyF;AACzF,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAA;IACtB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB,QAAQ,CAAC,QAAQ,EAAE,UAAU,GAAG,WAAW,CAAA;IAC3C,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IACrD,wFAAwF;IACxF,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,GAAG,KAAK,CAAA;CACnC;AAED,sFAAsF;AACtF,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,WAAW,IAAI,SAAS,eAAe,EAAE,CAAA;CAC1C;AAED;wFACwF;AACxF,MAAM,WAAW,aAAc,SAAQ,eAAe;IACpD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,MAAM,E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O,CAAC,QAAQ,CAAC,CAAA;CAC3C;AAED,eAAO,MAAM,cAAc,oDAAgD,CAAA;AAE3E,iGAAiG;AACjG,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,OAAO,SAAyC;CAI7D;AAED,gGAAgG;AAChG,qBAAa,yBAA0B,SAAQ,KAAK;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM;gBAAd,MAAM,EAAE,MAAM;CAIpC;AAED,oFAAoF;AACpF,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,KAAG,KAEpD,CAAA"}
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { capability } from '@databehave/core';
|
|
2
|
+
export const httpCapability = capability('databehave.http', 1);
|
|
3
|
+
/** A terminal transport effect; the pipeline observes it without running response decorators. */
|
|
4
|
+
export class HttpTransportTermination extends Error {
|
|
5
|
+
constructor(message = 'Connection terminated by HTTP policy') {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'HttpTransportTermination';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/** Fetch has no socket to terminate; callers receive this explicit unsupported-effect error. */
|
|
11
|
+
export class UnsupportedTransportError extends Error {
|
|
12
|
+
reason;
|
|
13
|
+
constructor(reason) {
|
|
14
|
+
super(`Transport termination is unsupported by fetch: ${reason}`);
|
|
15
|
+
this.reason = reason;
|
|
16
|
+
this.name = 'UnsupportedTransportError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Terminate the actual HTTP connection when invoked by a handler or middleware. */
|
|
20
|
+
export const terminateTransport = (reason) => {
|
|
21
|
+
throw new HttpTransportTermination(reason);
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=http.js.map
|
package/dist/http.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAiF7C,MAAM,CAAC,MAAM,cAAc,GAAG,UAAU,CAAc,iBAAiB,EAAE,CAAC,CAAC,CAAA;AAE3E,iGAAiG;AACjG,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACjD,YAAY,OAAO,GAAG,sCAAsC;QAC1D,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAA;IACxC,CAAC;CACF;AAED,gGAAgG;AAChG,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAC7B;IAArB,YAAqB,MAAc;QACjC,KAAK,CAAC,kDAAkD,MAAM,EAAE,CAAC,CAAA;QAD9C,WAAM,GAAN,MAAM,CAAQ;QAEjC,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAA;IACzC,CAAC;CACF;AAED,oFAAoF;AACpF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,MAAe,EAAS,EAAE;IAC3D,MAAM,IAAI,wBAAwB,CAAC,MAAM,CAAC,CAAA;AAC5C,CAAC,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* install the DSL package separately and import it directly.
|
|
12
|
-
*/
|
|
13
|
-
export { defineConfig } from './define.js';
|
|
14
|
-
export { run, type RunHandle, type RunOptions } from './run.js';
|
|
15
|
-
export { createServer } from './server.js';
|
|
16
|
-
export { seedFor, type SeedInput } from './openapi/seed.js';
|
|
17
|
-
export { loadConfig, type EndpointResponse, type EndpointSpec, type LoadedConfig, type LoadConfigOptions, type JsonConfig, } from './json-config.js';
|
|
18
|
-
export { resolveStatus, type MockModeConfig, type MockModeLogger, } from './mock-mode.js';
|
|
19
|
-
export type { Config, CorsConfig, Handler, ListenHandle, ListenOptions, Method, MockRequest, MockResponse, MockResponseBody, ObservedMethod, RouteKey, Server, } from './types.js';
|
|
20
|
-
export type { AdminModeConfig, ErrorMode, StickyOverride, OverrideMatcher, AdminModeCors, } from './admin/admin-types.js';
|
|
1
|
+
/** Public HTTP contracts and optional HTTP plugins. Feature packages depend on this boundary. */
|
|
2
|
+
export { httpPlugin, type HttpOptions } from './server.js';
|
|
3
|
+
export { httpCapability, terminateTransport, HttpTransportTermination, UnsupportedTransportError, type HttpRuntime, type HttpMiddleware, type HttpOutcome, type HttpObservation, type HttpBind, type BindGuard, type RouteDefinition, type RouteSource, type ResolvedRoute, } from './http.js';
|
|
4
|
+
export { nodeHttpPlugin, listenerCapability, type HttpListener, type NodeHttpOptions } from './node-http.js';
|
|
5
|
+
export { routesPlugin } from './plugins/routes.js';
|
|
6
|
+
export { corsPlugin } from './plugins/cors.js';
|
|
7
|
+
export { accessLogPlugin, type AccessLogOptions } from './plugins/access-log.js';
|
|
8
|
+
export { parseRouteKey, parseRoutePattern, matchPattern, type RoutePattern, type PatternSegment, type ParsedRouteKey } from './route-key.js';
|
|
9
|
+
export type { LogFormatOptions } from './log.js';
|
|
10
|
+
export type { Handler, Method, MockRequest, MockResponse, MockResponseBody, ObservedMethod, RouteKey, CorsConfig } from './types.js';
|
|
21
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,OAAO,EAAE,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,EACL,cAAc,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,yBAAyB,EACvF,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,KAAK,eAAe,EAC7E,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,KAAK,eAAe,EAAE,KAAK,WAAW,EAAE,KAAK,aAAa,GAC1F,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,KAAK,YAAY,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAC5G,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,eAAe,EAAE,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAChF,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,YAAY,EAAE,KAAK,YAAY,EAAE,KAAK,cAAc,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC5I,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAChD,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* OAS-driven mock generator and pulls no DSL dependency at runtime.
|
|
10
|
-
* For richer mock data (distributions, datasets, FK-aware generation)
|
|
11
|
-
* install the DSL package separately and import it directly.
|
|
12
|
-
*/
|
|
13
|
-
export { defineConfig } from './define.js';
|
|
14
|
-
export { run } from './run.js';
|
|
15
|
-
export { createServer } from './server.js';
|
|
16
|
-
export { seedFor } from './openapi/seed.js';
|
|
17
|
-
export { loadConfig, } from './json-config.js';
|
|
18
|
-
export { resolveStatus, } from './mock-mode.js';
|
|
1
|
+
/** Public HTTP contracts and optional HTTP plugins. Feature packages depend on this boundary. */
|
|
2
|
+
export { httpPlugin } from './server.js';
|
|
3
|
+
export { httpCapability, terminateTransport, HttpTransportTermination, UnsupportedTransportError, } from './http.js';
|
|
4
|
+
export { nodeHttpPlugin, listenerCapability } from './node-http.js';
|
|
5
|
+
export { routesPlugin } from './plugins/routes.js';
|
|
6
|
+
export { corsPlugin } from './plugins/cors.js';
|
|
7
|
+
export { accessLogPlugin } from './plugins/access-log.js';
|
|
8
|
+
export { parseRouteKey, parseRoutePattern, matchPattern } from './route-key.js';
|
|
19
9
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,OAAO,EAAE,UAAU,EAAoB,MAAM,aAAa,CAAA;AAC1D,OAAO,EACL,cAAc,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,yBAAyB,GAGxF,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAA2C,MAAM,gBAAgB,CAAA;AAC5G,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,eAAe,EAAyB,MAAM,yBAAyB,CAAA;AAChF,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,YAAY,EAA+D,MAAM,gBAAgB,CAAA"}
|
package/dist/log.d.ts
CHANGED
|
@@ -1,57 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Opt-in per-request access logger.
|
|
3
|
-
*
|
|
4
|
-
* One line per request, written to **stdout**. Default off — when the
|
|
5
|
-
* top-level `log` config is absent or `false`, no logger is built and
|
|
6
|
-
* the request hot path is untouched.
|
|
7
|
-
*
|
|
8
|
-
* Format `pretty` (default) — ANSI-coloured one-liner like:
|
|
9
|
-
*
|
|
10
|
-
* GET /api/v1/health → 200 4 ms · 56
|
|
11
|
-
*
|
|
12
|
-
* Format `json` — newline-terminated JSON object suitable for piping
|
|
13
|
-
* into structured log collectors:
|
|
14
|
-
*
|
|
15
|
-
* {"t":"2026-05-28T…","method":"GET","path":"/api/v1/health","status":200,"ms":4,"bytes":56}
|
|
16
|
-
*
|
|
17
|
-
* Sticky / header overrides synthesised by the admin inject hook are
|
|
18
|
-
* marked with ` [override:<mode.kind>]` (pretty) or `"override":"<kind>"` (json).
|
|
19
|
-
*
|
|
20
|
-
* Admin-panel traffic is suppressed by default — set `includeAdmin: true`
|
|
21
|
-
* to log it too. The hot-path check is a single `startsWith` against the
|
|
22
|
-
* resolved admin base path.
|
|
23
|
-
*/
|
|
24
|
-
import type { LogConfig } from './types.js';
|
|
25
|
-
export interface ResolvedLogConfig {
|
|
26
|
-
readonly access: boolean;
|
|
27
|
-
readonly includeAdmin: boolean;
|
|
28
|
-
readonly colors: boolean;
|
|
29
|
-
readonly format: 'pretty' | 'json';
|
|
30
|
-
}
|
|
1
|
+
/** One access event, already reduced to fields intended for logging. */
|
|
31
2
|
export interface LogEvent {
|
|
32
3
|
readonly method: string;
|
|
33
4
|
readonly path: string;
|
|
34
|
-
readonly status: number;
|
|
5
|
+
readonly status: number | 'terminated';
|
|
35
6
|
readonly ms: number;
|
|
36
7
|
readonly bytes: string;
|
|
37
|
-
readonly
|
|
38
|
-
readonly error: string | undefined;
|
|
8
|
+
readonly error?: string;
|
|
39
9
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
readonly
|
|
10
|
+
/** Access formatter configuration, independent of request filtering and output. */
|
|
11
|
+
export interface LogFormatOptions {
|
|
12
|
+
readonly format?: 'pretty' | 'json';
|
|
13
|
+
readonly colors?: 'auto' | 'always' | 'never';
|
|
43
14
|
}
|
|
44
|
-
/**
|
|
45
|
-
|
|
46
|
-
* `null` when logging is disabled. Pure — safe to call at construction.
|
|
47
|
-
*/
|
|
48
|
-
export declare const resolveLogConfig: (cfg: LogConfig | undefined) => ResolvedLogConfig | null;
|
|
49
|
-
/**
|
|
50
|
-
* Build an access logger bound to the resolved config + admin path.
|
|
51
|
-
* `adminPath` is the resolved `admin.path` (e.g. `/mock`), or
|
|
52
|
-
* `undefined` when admin mode is off. Returns `null` when logging is
|
|
53
|
-
* disabled — callers should short-circuit on `null` to avoid any
|
|
54
|
-
* per-request allocation.
|
|
55
|
-
*/
|
|
56
|
-
export declare const createAccessLogger: (cfg: LogConfig | undefined, adminPath: string | undefined) => AccessLogger | null;
|
|
15
|
+
/** Format one newline-terminated event without reading or consuming a response body. */
|
|
16
|
+
export declare const formatAccessLog: (event: LogEvent, options: LogFormatOptions) => string;
|
|
57
17
|
//# sourceMappingURL=log.d.ts.map
|
package/dist/log.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAAA;IACtC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,mFAAmF;AACnF,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAA;IACnC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAA;CAC9C;AAcD,wFAAwF;AACxF,eAAO,MAAM,eAAe,GAAI,OAAO,QAAQ,EAAE,SAAS,gBAAgB,KAAG,MAQ5E,CAAA"}
|