@supacloud/elysia 0.20.0 → 0.20.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 +35 -26
- package/compatibility.json +2 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -8,13 +8,19 @@ is a separately authorized business command, never an assumed rollback.
|
|
|
8
8
|
|
|
9
9
|
## Compatibility and Acceptance Boundary
|
|
10
10
|
|
|
11
|
-
The
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
The Elysia peer and development dependency are pinned to `2.0.0-beta.19`.
|
|
12
|
+
`compatibility.json` records the acceptance target: Bun 1.4.2, Elysia
|
|
13
|
+
2.0.0-beta.19, `typebox` 1.3.34, `exact-mirror` 1.2.6, TypeScript CLI 7.0.2
|
|
14
|
+
and the compiler's separate TypeScript 6 semantic API 6.0.2. The matrix is a
|
|
15
|
+
required target, not proof of an execution. See the dated, commit-specific
|
|
16
|
+
[framework acceptance record](../../docs/framework-acceptance.md) for actual
|
|
17
|
+
results. The contract-upgrade gate checks both TypeScript engines. These tests
|
|
18
|
+
do not establish a wider beta version matrix or Node.js runtime compatibility.
|
|
19
|
+
|
|
20
|
+
Keep the exact Elysia peer until additional versions have their own acceptance
|
|
21
|
+
evidence. A server using this adapter still installs Elysia; application metadata
|
|
22
|
+
and business modules need not import native Elysia types. See the
|
|
23
|
+
[dependency boundary and upgrade policy](../../docs/elysia-compatibility.md).
|
|
18
24
|
|
|
19
25
|
Run `bun run test:conformance` in this package after building the local
|
|
20
26
|
`@supacloud/contracts` and `@supacloud/app` dependencies and installing this
|
|
@@ -99,9 +105,11 @@ for the evidence boundaries and upgrade policy.
|
|
|
99
105
|
|
|
100
106
|
Pass a native Elysia plugin as `http` to `createApplication`, `createTestApp`,
|
|
101
107
|
or the options argument of `createModulePlugin`. `decorate` shares existing
|
|
102
|
-
instances
|
|
103
|
-
|
|
104
|
-
|
|
108
|
+
instances. In Elysia 2, `derive` runs after validation; do not assume the Elysia 1
|
|
109
|
+
pre-validation derive/resolve split. Use `.derive("plugin", callback)` for a
|
|
110
|
+
shared derived context, or finish a guarded context plugin with `.as("plugin")`.
|
|
111
|
+
Global hooks use `.as("global")`. Local hooks retain native encapsulation and
|
|
112
|
+
do not extend the consuming routes.
|
|
105
113
|
|
|
106
114
|
```ts
|
|
107
115
|
import { Elysia, t } from "elysia";
|
|
@@ -109,10 +117,12 @@ import { createApplication } from "@supacloud/elysia";
|
|
|
109
117
|
|
|
110
118
|
const http = new Elysia({ name: "application-context" })
|
|
111
119
|
.decorate("clock", { now: () => Date.now() })
|
|
112
|
-
.derive(({ clock }) => ({ startedAt: clock.now() }))
|
|
113
120
|
.guard({ query: t.Object({ locale: t.Optional(t.String()) }) })
|
|
114
|
-
.
|
|
115
|
-
|
|
121
|
+
.derive(({ clock, query }) => ({
|
|
122
|
+
startedAt: clock.now(),
|
|
123
|
+
locale: query.locale ?? "en",
|
|
124
|
+
}))
|
|
125
|
+
.as("plugin");
|
|
116
126
|
|
|
117
127
|
const app = createApplication({
|
|
118
128
|
http,
|
|
@@ -132,13 +142,13 @@ The second `requestContext` argument contains the validated HTTP inputs and
|
|
|
132
142
|
the inferred native plugin extensions. Existing one-argument factories remain
|
|
133
143
|
valid. Its result is passed to generated request-scoped constructors and the
|
|
134
144
|
controller's `context`/`requestContext` input. It is built once per request;
|
|
135
|
-
early
|
|
145
|
+
early derived-context responses and validation failures do not construct DI scopes.
|
|
136
146
|
Request scopes are created inside the existing governed handler and released
|
|
137
147
|
after the response, including handler failures. They are not application
|
|
138
|
-
singletons or native
|
|
148
|
+
singletons or native context hooks.
|
|
139
149
|
|
|
140
|
-
Native routes added to the returned app retain the HTTP plugin's decorator
|
|
141
|
-
|
|
150
|
+
Native routes added to the returned app retain the HTTP plugin's decorator
|
|
151
|
+
and derived context types. `createModulePlugin` also preserves the concrete
|
|
142
152
|
`services` type supplied by its caller. Module service bags are attached by
|
|
143
153
|
the module-local resolver, not merged into a root `decorator.services` bag;
|
|
144
154
|
the service instances themselves remain shared. This prevents same-named
|
|
@@ -153,13 +163,13 @@ Compiled route schemas are runtime
|
|
|
153
163
|
descriptors: their body/params/query/header/cookie fields in the application-wide
|
|
154
164
|
context factory remain `unknown`-based instead of pretending to infer one
|
|
155
165
|
route's schema for every route. Use shared guards for schema-typed native
|
|
156
|
-
|
|
166
|
+
context derivation and the existing generated contracts for individual compiled routes.
|
|
157
167
|
Do not store per-request identity or transaction handles in decorated singletons.
|
|
158
168
|
|
|
159
169
|
The `http` plugin is composed into each compiled module and subsequently into
|
|
160
170
|
the root for native routes. Keep it focused on reusable context extensions;
|
|
161
171
|
register unrelated endpoints on the returned app. Hook execution is tested
|
|
162
|
-
for named/anonymous plugins and
|
|
172
|
+
for named/anonymous plugins and plugin/global hooks without duplicate work.
|
|
163
173
|
Anonymous extensions receive a stable internal plugin identity for native
|
|
164
174
|
hook deduplication; the caller's plugin configuration is not mutated.
|
|
165
175
|
This is native HTTP composition, not a replacement runtime DI container or
|
|
@@ -298,7 +308,7 @@ Runtime adapter that turns `@supacloud/compiler` output into a production-ready
|
|
|
298
308
|
## Installation
|
|
299
309
|
|
|
300
310
|
```bash
|
|
301
|
-
bun add @supacloud/elysia elysia
|
|
311
|
+
bun add --exact @supacloud/elysia elysia@2.0.0-beta.19
|
|
302
312
|
```
|
|
303
313
|
|
|
304
314
|
## Usage
|
|
@@ -383,7 +393,7 @@ read-back protocol. A custom `errorMapper` can override this public envelope.
|
|
|
383
393
|
|
|
384
394
|
Native `Response` objects are passed through by Elysia, including JSON responses.
|
|
385
395
|
Use `validatedJsonResponse` to opt into validation when constructing a native
|
|
386
|
-
JSON response. Otherwise handlers must validate their JSON
|
|
396
|
+
JSON response. Otherwise handlers must validate their JSON payloads themselves.
|
|
387
397
|
The adapter does not consume or parse binary/streaming responses.
|
|
388
398
|
|
|
389
399
|
Jobs are executed explicitly with `executeJob(compiledModule, services, job,
|
|
@@ -657,9 +667,8 @@ does not add Eden-style client inference to an existing Elysia instance; the
|
|
|
657
667
|
compiler-generated client remains the source of transport types.
|
|
658
668
|
|
|
659
669
|
Response maps may use concrete statuses, `1XX`-`5XX` families, and `default`.
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
statuses take precedence over families, which take precedence over `default`.
|
|
670
|
+
The adapter expands family/default entries to concrete validators before
|
|
671
|
+
registration. Exact statuses take precedence over families, which take precedence over `default`.
|
|
663
672
|
An actual status absent from a structured response map fails the route contract
|
|
664
673
|
before Elysia can silently accept a default `200`; binary/stream routes may
|
|
665
674
|
intentionally leave successful transport statuses unschematized when only their
|
|
@@ -700,12 +709,12 @@ const app = createApplication({
|
|
|
700
709
|
});
|
|
701
710
|
```
|
|
702
711
|
|
|
703
|
-
`identityPlugin` is an application-owned
|
|
712
|
+
`identityPlugin` is an application-owned plugin/global Elysia context plugin that verifies
|
|
704
713
|
credentials and resolves `identity`; the adapter does not trust a raw user/tenant
|
|
705
714
|
header as identity. Policy callbacks preserve its native context types.
|
|
706
715
|
|
|
707
716
|
Policies become native route-local `beforeHandle` hooks. They execute sequentially
|
|
708
|
-
after schema validation, native
|
|
717
|
+
after schema validation, native context derivation and the application request-context
|
|
709
718
|
factory, but before compiled request-scope construction and command execution.
|
|
710
719
|
Return `undefined` to continue or a `Response` to stop; thrown errors use the
|
|
711
720
|
application error mapper. Native earlier hooks can still short-circuit the request.
|
package/compatibility.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supacloud/elysia",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.1",
|
|
4
4
|
"description": "Elysia runtime adapter for SupaCloud compiled modules: application/request scopes, route registration and validation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -59,10 +59,10 @@
|
|
|
59
59
|
"@supacloud/commands": "0.7.0"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
|
-
"elysia": "
|
|
62
|
+
"elysia": "2.0.0-beta.19"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@supacloud/compiler": "0.27.
|
|
65
|
+
"@supacloud/compiler": "0.27.2",
|
|
66
66
|
"@supacloud/delivery": "0.2.0",
|
|
67
67
|
"@supacloud/commands": "0.7.0",
|
|
68
68
|
"@supacloud/db": "0.9.0",
|