elysia 2.0.0-beta.27 → 2.0.0-beta.29
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 +1 -1
- package/dist/adapter/utils.js +4 -10
- package/dist/adapter/utils.mjs +4 -10
- package/dist/adapter/web-standard/handler.js +6 -13
- package/dist/adapter/web-standard/handler.mjs +6 -13
- package/dist/base.d.ts +9 -9
- package/dist/base.js +5 -8
- package/dist/base.mjs +5 -8
- package/dist/compile/aot-capture.js +13 -18
- package/dist/compile/aot-capture.mjs +13 -18
- package/dist/compile/aot-emit.d.ts +1 -2
- package/dist/compile/aot-emit.js +5 -16
- package/dist/compile/aot-emit.mjs +6 -16
- package/dist/compile/aot-reconstruct.js +7 -4
- package/dist/compile/aot-reconstruct.mjs +7 -4
- package/dist/compile/handler/descriptor.d.ts +1 -2
- package/dist/compile/handler/descriptor.js +2 -5
- package/dist/compile/handler/descriptor.mjs +2 -4
- package/dist/compile/handler/index.js +11 -19
- package/dist/compile/handler/index.mjs +12 -20
- package/dist/compile/handler/jit.d.ts +2 -1
- package/dist/compile/handler/jit.js +9 -15
- package/dist/compile/handler/jit.mjs +9 -16
- package/dist/compile/handler/utils.d.ts +2 -1
- package/dist/compile/handler/utils.js +4 -2
- package/dist/compile/handler/utils.mjs +3 -2
- package/dist/constants.js +2 -3
- package/dist/constants.mjs +2 -3
- package/dist/context.js +1 -7
- package/dist/context.mjs +1 -7
- package/dist/cookie/cookie.d.ts +7 -4
- package/dist/cookie/cookie.js +10 -5
- package/dist/cookie/cookie.mjs +10 -5
- package/dist/cookie/types.d.ts +1 -1
- package/dist/cookie/utils.js +5 -5
- package/dist/cookie/utils.mjs +5 -5
- package/dist/error.d.ts +5 -4
- package/dist/handler/error.js +1 -2
- package/dist/handler/error.mjs +1 -2
- package/dist/handler/fetch.js +6 -7
- package/dist/handler/fetch.mjs +6 -7
- package/dist/memory.js +1 -1
- package/dist/memory.mjs +1 -1
- package/dist/package.js +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugin/aot/core.js +4 -4
- package/dist/plugin/aot/core.mjs +4 -4
- package/dist/plugin/aot/hooks.js +2 -4
- package/dist/plugin/aot/hooks.mjs +3 -5
- package/dist/plugin/aot/source.d.ts +1 -1
- package/dist/plugin/aot/source.js +9 -9
- package/dist/plugin/aot/source.mjs +9 -9
- package/dist/plugin/trace.d.ts +16 -0
- package/dist/plugin/websocket.d.ts +21 -0
- package/dist/sucrose.d.ts +1 -1
- package/dist/trace.d.ts +1 -1
- package/dist/type/bridge-live.d.ts +1 -1
- package/dist/type/bridge-live.js +1 -1
- package/dist/type/bridge-live.mjs +1 -1
- package/dist/type/bridge.d.ts +1 -1
- package/dist/type/coerce-plan.d.ts +1 -1
- package/dist/type/coerce-plan.js +19 -11
- package/dist/type/coerce-plan.mjs +19 -11
- package/dist/type/constants.d.ts +1 -1
- package/dist/type/elysia/date.d.ts +2 -1
- package/dist/type/elysia/file-type.js +3 -2
- package/dist/type/elysia/file-type.mjs +3 -2
- package/dist/type/elysia/union-enum.js +0 -1
- package/dist/type/elysia/union-enum.mjs +0 -1
- package/dist/type/elysia/utils.d.ts +2 -2
- package/dist/type/elysia/utils.js +5 -19
- package/dist/type/elysia/utils.mjs +5 -19
- package/dist/type/shared.d.ts +10 -2
- package/dist/type/shared.js +36 -11
- package/dist/type/shared.mjs +34 -11
- package/dist/type/typebox-type.js +1 -1
- package/dist/type/typebox-type.mjs +1 -1
- package/dist/type/typebox-value-live.d.ts +2 -2
- package/dist/type/typebox-value-live.js +2 -2
- package/dist/type/typebox-value-live.mjs +2 -2
- package/dist/type/typebox-value-ops.d.ts +2 -2
- package/dist/type/typebox-value-ops.js +2 -2
- package/dist/type/typebox-value-ops.mjs +2 -2
- package/dist/type/typebox-value.d.ts +6 -6
- package/dist/type/validator/custom-error.js +1 -4
- package/dist/type/validator/custom-error.mjs +1 -4
- package/dist/type/validator/index.js +6 -15
- package/dist/type/validator/index.mjs +7 -16
- package/dist/type/validator/string-codec-aot.js +3 -5
- package/dist/type/validator/string-codec-aot.mjs +3 -5
- package/dist/types.d.ts +11 -19
- package/dist/utils.js +1 -1
- package/dist/utils.mjs +1 -1
- package/dist/validator/route.d.ts +1 -8
- package/dist/ws/route.js +3 -7
- package/dist/ws/route.mjs +3 -7
- package/package.json +3 -8
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
<br>
|
|
17
17
|
|
|
18
|
-

|
|
19
19
|
|
|
20
20
|
<!---
|
|
21
21
|
```bash
|
package/dist/adapter/utils.js
CHANGED
|
@@ -55,10 +55,8 @@ function handleFile(response, set, request, size = response.size) {
|
|
|
55
55
|
}
|
|
56
56
|
const body = "value" in response ? response.value : response;
|
|
57
57
|
const immutable = set && (set.status === 206 || set.status === 304 || set.status === 412 || set.status === 416);
|
|
58
|
-
const defaultHeader = immutable ? require_utils.nullObject() : {
|
|
59
|
-
|
|
60
|
-
"content-range": size ? `bytes 0-${size - 1}/${size}` : void 0
|
|
61
|
-
};
|
|
58
|
+
const defaultHeader = immutable ? require_utils.nullObject() : { "accept-ranges": "bytes" };
|
|
59
|
+
if (!immutable && size) defaultHeader["content-range"] = `bytes 0-${size - 1}/${size}`;
|
|
62
60
|
if (!set && !size) return new Response(body);
|
|
63
61
|
if (!set) return new Response(body, { headers: defaultHeader });
|
|
64
62
|
if (set.headers instanceof Headers) {
|
|
@@ -358,11 +356,6 @@ function mergeHeaders(responseHeaders, setHeaders) {
|
|
|
358
356
|
applySetHeaders(headers, setHeaders, responseHeaders);
|
|
359
357
|
return headers;
|
|
360
358
|
}
|
|
361
|
-
function mergeStatus(responseStatus, setStatus) {
|
|
362
|
-
if (typeof setStatus === "string") setStatus = require_constants.StatusMap[setStatus];
|
|
363
|
-
if (responseStatus === 200) return setStatus;
|
|
364
|
-
return responseStatus;
|
|
365
|
-
}
|
|
366
359
|
function cancelPropagatingBody(clonedBody, orphanedBranch, preserveOrphan = false) {
|
|
367
360
|
const reader = clonedBody.getReader();
|
|
368
361
|
return new ReadableStream({
|
|
@@ -394,7 +387,8 @@ function createResponseHandler(handler) {
|
|
|
394
387
|
if (!borrowed && response.bodyUsed) throw new TypeError("Cannot reuse a consumed Response across requests");
|
|
395
388
|
let status;
|
|
396
389
|
if (set) {
|
|
397
|
-
status =
|
|
390
|
+
status = response.status === 200 ? set.status : response.status;
|
|
391
|
+
if (typeof status === "string") status = require_constants.StatusMap[status];
|
|
398
392
|
const statusUnchanged = status === void 0 || status === response.status;
|
|
399
393
|
if (!mustClone && statusUnchanged && !set.cookie && !require_utils.isNotEmpty(set.headers)) return response;
|
|
400
394
|
} else if (!mustClone) return response;
|
package/dist/adapter/utils.mjs
CHANGED
|
@@ -55,10 +55,8 @@ function handleFile(response, set, request, size = response.size) {
|
|
|
55
55
|
}
|
|
56
56
|
const body = "value" in response ? response.value : response;
|
|
57
57
|
const immutable = set && (set.status === 206 || set.status === 304 || set.status === 412 || set.status === 416);
|
|
58
|
-
const defaultHeader = immutable ? nullObject() : {
|
|
59
|
-
|
|
60
|
-
"content-range": size ? `bytes 0-${size - 1}/${size}` : void 0
|
|
61
|
-
};
|
|
58
|
+
const defaultHeader = immutable ? nullObject() : { "accept-ranges": "bytes" };
|
|
59
|
+
if (!immutable && size) defaultHeader["content-range"] = `bytes 0-${size - 1}/${size}`;
|
|
62
60
|
if (!set && !size) return new Response(body);
|
|
63
61
|
if (!set) return new Response(body, { headers: defaultHeader });
|
|
64
62
|
if (set.headers instanceof Headers) {
|
|
@@ -358,11 +356,6 @@ function mergeHeaders(responseHeaders, setHeaders) {
|
|
|
358
356
|
applySetHeaders(headers, setHeaders, responseHeaders);
|
|
359
357
|
return headers;
|
|
360
358
|
}
|
|
361
|
-
function mergeStatus(responseStatus, setStatus) {
|
|
362
|
-
if (typeof setStatus === "string") setStatus = StatusMap[setStatus];
|
|
363
|
-
if (responseStatus === 200) return setStatus;
|
|
364
|
-
return responseStatus;
|
|
365
|
-
}
|
|
366
359
|
function cancelPropagatingBody(clonedBody, orphanedBranch, preserveOrphan = false) {
|
|
367
360
|
const reader = clonedBody.getReader();
|
|
368
361
|
return new ReadableStream({
|
|
@@ -394,7 +387,8 @@ function createResponseHandler(handler) {
|
|
|
394
387
|
if (!borrowed && response.bodyUsed) throw new TypeError("Cannot reuse a consumed Response across requests");
|
|
395
388
|
let status;
|
|
396
389
|
if (set) {
|
|
397
|
-
status =
|
|
390
|
+
status = response.status === 200 ? set.status : response.status;
|
|
391
|
+
if (typeof status === "string") status = StatusMap[status];
|
|
398
392
|
const statusUnchanged = status === void 0 || status === response.status;
|
|
399
393
|
if (!mustClone && statusUnchanged && !set.cookie && !isNotEmpty(set.headers)) return response;
|
|
400
394
|
} else if (!mustClone) return response;
|
|
@@ -13,7 +13,8 @@ const textPlainInit = { headers: { "content-type": "text/plain" } };
|
|
|
13
13
|
function handleElysiaFile(file, set = { headers: require_utils.nullObject() }, request) {
|
|
14
14
|
const contentType = file.type;
|
|
15
15
|
const headers = require_adapter_utils.materializeSetHeaders(set);
|
|
16
|
-
if (contentType !== "application/octet-stream") headers
|
|
16
|
+
if (contentType !== "application/octet-stream") if (headers instanceof Headers) headers.set("content-type", contentType);
|
|
17
|
+
else headers["content-type"] = contentType;
|
|
17
18
|
const stats = file.stats;
|
|
18
19
|
if (stats) return stats.then((stat) => {
|
|
19
20
|
const size = stat.size;
|
|
@@ -63,7 +64,9 @@ function withStatus(response, set, request, owned) {
|
|
|
63
64
|
status: response.status,
|
|
64
65
|
headers: require_utils.nullObject()
|
|
65
66
|
};
|
|
66
|
-
if (response.headers) Object.
|
|
67
|
+
if (response.headers) if (set.headers instanceof Headers) for (const [key, value] of Object.entries(response.headers)) if (key.toLowerCase() === "set-cookie") for (const cookie of Array.isArray(value) ? value : [value]) set.headers.append(key, cookie);
|
|
68
|
+
else set.headers.set(key, value);
|
|
69
|
+
else Object.assign(require_adapter_utils.materializeSetHeaders(set), response.headers);
|
|
67
70
|
return mapResponseWithSet(response.response, set, request, owned);
|
|
68
71
|
}
|
|
69
72
|
const checkRemovedSetRedirect = !require_universal_is_production.isProduction();
|
|
@@ -127,17 +130,7 @@ function errorToResponse(error, set, request, owned = false) {
|
|
|
127
130
|
function mapFallback(response, set, request, owned = false) {
|
|
128
131
|
if (response instanceof Response) return handleResponse(response, set, request, owned);
|
|
129
132
|
if (response instanceof Error) return errorToResponse(response, set, request, owned);
|
|
130
|
-
if (response instanceof require_error.ElysiaStatus)
|
|
131
|
-
if (set && response.headers) {
|
|
132
|
-
set.status = response.status;
|
|
133
|
-
set.headers = {
|
|
134
|
-
...set.headers,
|
|
135
|
-
...response.headers
|
|
136
|
-
};
|
|
137
|
-
return mapResponse(response.response, set, request, owned);
|
|
138
|
-
}
|
|
139
|
-
return withStatus(response, set, request, owned);
|
|
140
|
-
}
|
|
133
|
+
if (response instanceof require_error.ElysiaStatus) return withStatus(response, set, request, owned);
|
|
141
134
|
if (response instanceof require_universal_file.ElysiaFile) return handleElysiaFile(response, set, request);
|
|
142
135
|
if (require_utils.isElysiaForm(response)) return new Response(require_utils.formToFormData(response), set);
|
|
143
136
|
if (typeof response?.next === "function" || response instanceof ReadableStream) return handleStream(response, set, request, void 0, owned);
|
|
@@ -13,7 +13,8 @@ const textPlainInit = { headers: { "content-type": "text/plain" } };
|
|
|
13
13
|
function handleElysiaFile(file, set = { headers: nullObject() }, request) {
|
|
14
14
|
const contentType = file.type;
|
|
15
15
|
const headers = materializeSetHeaders(set);
|
|
16
|
-
if (contentType !== "application/octet-stream") headers
|
|
16
|
+
if (contentType !== "application/octet-stream") if (headers instanceof Headers) headers.set("content-type", contentType);
|
|
17
|
+
else headers["content-type"] = contentType;
|
|
17
18
|
const stats = file.stats;
|
|
18
19
|
if (stats) return stats.then((stat) => {
|
|
19
20
|
const size = stat.size;
|
|
@@ -63,7 +64,9 @@ function withStatus(response, set, request, owned) {
|
|
|
63
64
|
status: response.status,
|
|
64
65
|
headers: nullObject()
|
|
65
66
|
};
|
|
66
|
-
if (response.headers) Object.
|
|
67
|
+
if (response.headers) if (set.headers instanceof Headers) for (const [key, value] of Object.entries(response.headers)) if (key.toLowerCase() === "set-cookie") for (const cookie of Array.isArray(value) ? value : [value]) set.headers.append(key, cookie);
|
|
68
|
+
else set.headers.set(key, value);
|
|
69
|
+
else Object.assign(materializeSetHeaders(set), response.headers);
|
|
67
70
|
return mapResponseWithSet(response.response, set, request, owned);
|
|
68
71
|
}
|
|
69
72
|
const checkRemovedSetRedirect = !isProduction();
|
|
@@ -127,17 +130,7 @@ function errorToResponse(error, set, request, owned = false) {
|
|
|
127
130
|
function mapFallback(response, set, request, owned = false) {
|
|
128
131
|
if (response instanceof Response) return handleResponse(response, set, request, owned);
|
|
129
132
|
if (response instanceof Error) return errorToResponse(response, set, request, owned);
|
|
130
|
-
if (response instanceof ElysiaStatus)
|
|
131
|
-
if (set && response.headers) {
|
|
132
|
-
set.status = response.status;
|
|
133
|
-
set.headers = {
|
|
134
|
-
...set.headers,
|
|
135
|
-
...response.headers
|
|
136
|
-
};
|
|
137
|
-
return mapResponse(response.response, set, request, owned);
|
|
138
|
-
}
|
|
139
|
-
return withStatus(response, set, request, owned);
|
|
140
|
-
}
|
|
133
|
+
if (response instanceof ElysiaStatus) return withStatus(response, set, request, owned);
|
|
141
134
|
if (response instanceof ElysiaFile) return handleElysiaFile(response, set, request);
|
|
142
135
|
if (isElysiaForm(response)) return new Response(formToFormData(response), set);
|
|
143
136
|
if (typeof response?.next === "function" || response instanceof ReadableStream) return handleStream(response, set, request, void 0, owned);
|
package/dist/base.d.ts
CHANGED
|
@@ -99,7 +99,6 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
99
99
|
'~aotFingerprint'?: AotFingerprint;
|
|
100
100
|
'~compilerSession'?: CompilerSession;
|
|
101
101
|
'~generation'?: Generation;
|
|
102
|
-
'~introspect'?: boolean;
|
|
103
102
|
'~scopeChild'?: boolean;
|
|
104
103
|
'~scopeChildren'?: AnyElysia[];
|
|
105
104
|
constructor(config?: ElysiaConfig<BasePath, Scope>);
|
|
@@ -228,7 +227,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
228
227
|
* ```typescript
|
|
229
228
|
* new Elysia()
|
|
230
229
|
* .setup(({ server }) => {
|
|
231
|
-
* console.log(
|
|
230
|
+
* console.log(`Running at ${server?.url}`)
|
|
232
231
|
* })
|
|
233
232
|
* .listen(3000)
|
|
234
233
|
* ```
|
|
@@ -403,7 +402,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
403
402
|
* .post('/', ({ body }) => body)
|
|
404
403
|
* ```
|
|
405
404
|
*/
|
|
406
|
-
guard<const Input extends Metadata['macro'] & InputSchema<keyof Definitions['typebox'] & string>, const Schema extends MergeSchema<UnwrapRoute<Input, Definitions['typebox'], BasePath>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>> & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Input, Definitions['typebox']>), const BeforeHandle extends MaybeArray<OptionalHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const AfterHandle extends MaybeArray<AfterHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const ErrorHandle extends MaybeArray<ErrorHandler<Definitions['error'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>>(hook: GuardLocalHook<Input, Schema & MacroContext, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>, keyof Metadata['parser'], BeforeHandle, AfterHandle, ErrorHandle> & {
|
|
405
|
+
guard<const Input extends Metadata['macro'] & InputSchema<keyof Definitions['typebox'] & string>, const Schema extends MergeSchema<UnwrapRoute<Input, Definitions['typebox'], BasePath>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>> & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Input, Definitions['typebox']>), const BeforeHandle extends MaybeArray<OptionalHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const AfterHandle extends MaybeArray<AfterHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const ErrorHandle extends MaybeArray<ErrorHandler<Definitions['error'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>>(hook: GuardLocalHook<Input, Schema & MacroContext, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>, keyof Metadata['parser'], BeforeHandle, AfterHandle, ErrorHandle, 'merge'> & {
|
|
407
406
|
schema: 'merge';
|
|
408
407
|
} & MacroOptionContext<Metadata['macroFn'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, {
|
|
409
408
|
derive: {};
|
|
@@ -423,7 +422,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
423
422
|
response: UnionResponseStatus<Volatile['response'], ElysiaHandlerToResponseSchemaAmbiguous<BeforeHandle> & ElysiaHandlerToResponseSchemaAmbiguous<AfterHandle> & ElysiaHandlerToResponseSchemaAmbiguous<ErrorHandle> & MacroContext['return']>;
|
|
424
423
|
error: Volatile['error'];
|
|
425
424
|
}>;
|
|
426
|
-
guard<const Input extends Metadata['macro'] & InputSchema<keyof Definitions['typebox'] & string>, const Schema extends MergeSchema<UnwrapRoute<Input, Definitions['typebox'], BasePath>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>> & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Input, Definitions['typebox']>), const BeforeHandle extends MaybeArray<OptionalHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const AfterHandle extends MaybeArray<AfterHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const ErrorHandle extends MaybeArray<ErrorHandler<Definitions['error'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const NewElysia extends AnyElysia>(hook: GuardLocalHook<Input, Schema & MacroContext, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>, keyof Metadata['parser'], BeforeHandle, AfterHandle, ErrorHandle> & {
|
|
425
|
+
guard<const Input extends Metadata['macro'] & InputSchema<keyof Definitions['typebox'] & string>, const Schema extends MergeSchema<UnwrapRoute<Input, Definitions['typebox'], BasePath>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>> & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Input, Definitions['typebox']>), const BeforeHandle extends MaybeArray<OptionalHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const AfterHandle extends MaybeArray<AfterHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const ErrorHandle extends MaybeArray<ErrorHandler<Definitions['error'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const NewElysia extends AnyElysia>(hook: GuardLocalHook<Input, Schema & MacroContext, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>, keyof Metadata['parser'], BeforeHandle, AfterHandle, ErrorHandle, 'merge'> & {
|
|
427
426
|
schema: 'merge';
|
|
428
427
|
} & MacroOptionContext<Metadata['macroFn'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, {
|
|
429
428
|
derive: {};
|
|
@@ -465,7 +464,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
465
464
|
response: Volatile['response'];
|
|
466
465
|
error: Volatile['error'];
|
|
467
466
|
}>) => NewElysia): Elysia<BasePath, Scope, Singleton, Definitions, Metadata, Routes & NewElysia['~Routes'], Ephemeral, Volatile>;
|
|
468
|
-
guard<const Input extends Metadata['macro'] & InputSchema<keyof Definitions['typebox'] & string>, const Schema extends MergeSchema<UnwrapRoute<Input, Definitions['typebox'], BasePath>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>> & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Input, Definitions['typebox']>), const BeforeHandle extends MaybeArray<OptionalHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const AfterHandle extends MaybeArray<AfterHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const ErrorHandle extends MaybeArray<ErrorHandler<Definitions['error'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>>(scope: 'local', hook: GuardLocalHook<Input, Schema & MacroContext, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>, keyof Metadata['parser'], BeforeHandle, AfterHandle, ErrorHandle> & {
|
|
467
|
+
guard<const Input extends Metadata['macro'] & InputSchema<keyof Definitions['typebox'] & string>, const Schema extends MergeSchema<UnwrapRoute<Input, Definitions['typebox'], BasePath>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>> & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Input, Definitions['typebox']>), const BeforeHandle extends MaybeArray<OptionalHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const AfterHandle extends MaybeArray<AfterHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const ErrorHandle extends MaybeArray<ErrorHandler<Definitions['error'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>>(scope: 'local', hook: GuardLocalHook<Input, Schema & MacroContext, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>, keyof Metadata['parser'], BeforeHandle, AfterHandle, ErrorHandle, 'merge'> & {
|
|
469
468
|
schema: 'merge';
|
|
470
469
|
} & MacroOptionContext<Metadata['macroFn'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, {
|
|
471
470
|
derive: {};
|
|
@@ -485,7 +484,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
485
484
|
response: UnionResponseStatus<Volatile['response'], ElysiaHandlerToResponseSchemaAmbiguous<BeforeHandle> & ElysiaHandlerToResponseSchemaAmbiguous<AfterHandle> & ElysiaHandlerToResponseSchemaAmbiguous<ErrorHandle> & MacroContext['return']>;
|
|
486
485
|
error: Volatile['error'];
|
|
487
486
|
}>;
|
|
488
|
-
guard<const Input extends Metadata['macro'] & InputSchema<keyof Definitions['typebox'] & string>, const Schema extends MergeSchema<UnwrapRoute<Input, Definitions['typebox'], BasePath>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>> & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Input, Definitions['typebox']>), const BeforeHandle extends MaybeArray<OptionalHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const AfterHandle extends MaybeArray<AfterHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const ErrorHandle extends MaybeArray<ErrorHandler<Definitions['error'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>>(scope: 'plugin', hook: GuardLocalHook<Input, Schema & MacroContext, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>, keyof Metadata['parser'], BeforeHandle, AfterHandle, ErrorHandle> & {
|
|
487
|
+
guard<const Input extends Metadata['macro'] & InputSchema<keyof Definitions['typebox'] & string>, const Schema extends MergeSchema<UnwrapRoute<Input, Definitions['typebox'], BasePath>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>> & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Input, Definitions['typebox']>), const BeforeHandle extends MaybeArray<OptionalHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const AfterHandle extends MaybeArray<AfterHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const ErrorHandle extends MaybeArray<ErrorHandler<Definitions['error'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>>(scope: 'plugin', hook: GuardLocalHook<Input, Schema & MacroContext, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>, keyof Metadata['parser'], BeforeHandle, AfterHandle, ErrorHandle, 'merge'> & {
|
|
489
488
|
schema: 'merge';
|
|
490
489
|
} & MacroOptionContext<Metadata['macroFn'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, {
|
|
491
490
|
derive: {};
|
|
@@ -505,7 +504,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
505
504
|
response: UnionResponseStatus<Ephemeral['response'], ElysiaHandlerToResponseSchemaAmbiguous<BeforeHandle> & ElysiaHandlerToResponseSchemaAmbiguous<AfterHandle> & ElysiaHandlerToResponseSchemaAmbiguous<ErrorHandle> & MacroContext['return']>;
|
|
506
505
|
error: Ephemeral['error'];
|
|
507
506
|
}, Volatile>;
|
|
508
|
-
guard<const Input extends Metadata['macro'] & InputSchema<keyof Definitions['typebox'] & string>, const Schema extends MergeSchema<UnwrapRoute<Input, Definitions['typebox'], BasePath>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>> & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Input, Definitions['typebox']>), const BeforeHandle extends MaybeArray<OptionalHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const AfterHandle extends MaybeArray<AfterHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const ErrorHandle extends MaybeArray<ErrorHandler<Definitions['error'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>>(scope: 'global', hook: GuardLocalHook<Input, Schema & MacroContext, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>, keyof Metadata['parser'], BeforeHandle, AfterHandle, ErrorHandle> & {
|
|
507
|
+
guard<const Input extends Metadata['macro'] & InputSchema<keyof Definitions['typebox'] & string>, const Schema extends MergeSchema<UnwrapRoute<Input, Definitions['typebox'], BasePath>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>> & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Input, Definitions['typebox']>), const BeforeHandle extends MaybeArray<OptionalHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const AfterHandle extends MaybeArray<AfterHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const ErrorHandle extends MaybeArray<ErrorHandler<Definitions['error'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>>(scope: 'global', hook: GuardLocalHook<Input, Schema & MacroContext, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>, keyof Metadata['parser'], BeforeHandle, AfterHandle, ErrorHandle, 'merge'> & {
|
|
509
508
|
schema: 'merge';
|
|
510
509
|
} & MacroOptionContext<Metadata['macroFn'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, {
|
|
511
510
|
derive: {};
|
|
@@ -543,7 +542,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
543
542
|
parser: Metadata['parser'];
|
|
544
543
|
response: Metadata['response'];
|
|
545
544
|
}, {}, Ephemeral, Volatile>) => NewElysia): Elysia<BasePath, Scope, Singleton, Definitions, Metadata, Routes & NewElysia['~Routes'], Ephemeral, Volatile>;
|
|
546
|
-
group<const Prefix extends string, const Input extends Metadata['macro'] & InputSchema<keyof Definitions['typebox'] & string>, const Schema extends MergeSchema<UnwrapRoute<Input, Definitions['typebox'], JoinPath<BasePath, Prefix>>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>> & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Input, Definitions['typebox']>), const BeforeHandle extends MaybeArray<OptionalHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const AfterHandle extends MaybeArray<AfterHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const ErrorHandle extends MaybeArray<ErrorHandler<Definitions['error'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const NewElysia extends AnyElysia>(prefix: Prefix, schema: GuardLocalHook<Input, Schema & MacroContext, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>, keyof Metadata['parser'], BeforeHandle, AfterHandle, ErrorHandle> & {
|
|
545
|
+
group<const Prefix extends string, const Input extends Metadata['macro'] & InputSchema<keyof Definitions['typebox'] & string>, const Schema extends MergeSchema<UnwrapRoute<Input, Definitions['typebox'], JoinPath<BasePath, Prefix>>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>> & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Input, Definitions['typebox']>), const BeforeHandle extends MaybeArray<OptionalHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const AfterHandle extends MaybeArray<AfterHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const ErrorHandle extends MaybeArray<ErrorHandler<Definitions['error'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const NewElysia extends AnyElysia>(prefix: Prefix, schema: GuardLocalHook<Input, Schema & MacroContext, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>, keyof Metadata['parser'], BeforeHandle, AfterHandle, ErrorHandle, 'merge'> & {
|
|
547
546
|
schema: 'merge';
|
|
548
547
|
} & MacroOptionContext<Metadata['macroFn'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, {
|
|
549
548
|
derive: {};
|
|
@@ -922,7 +921,8 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
922
921
|
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>>>(path: Path, fn: Handle & Metadata['macro']): this;
|
|
923
922
|
/**
|
|
924
923
|
* ### ws
|
|
925
|
-
* Register a WebSocket route
|
|
924
|
+
* Register a WebSocket route as `(path, options)`, `(path, handler)`, or `(path, options, handler)`.
|
|
925
|
+
* Requires `.use(websocket())` from `elysia/websocket`.
|
|
926
926
|
*/
|
|
927
927
|
ws<const Path extends string, const Input extends Metadata['macro'] & InputSchema<keyof Definitions['typebox'] & string>, const Schema extends IntersectIfObjectSchema<MergeSchema<UnwrapRoute<Input, Definitions['typebox'], JoinPath<BasePath, Path>>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, '', undefined extends Input['params'] ? true : false>, MergeScopedSchemas<Metadata['schemas'], Ephemeral['schemas'], Volatile['schemas']>>, const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Input, Definitions['typebox']>)>(path: Path, options: WSLocalHook<Input, Schema & MacroContext, Singleton & {
|
|
928
928
|
derive: Ephemeral['derive'] & Volatile['derive'] & MacroContext['derive'];
|
package/dist/base.js
CHANGED
|
@@ -178,7 +178,6 @@ var Elysia = class Elysia {
|
|
|
178
178
|
this["~aotFingerprint"] = void 0;
|
|
179
179
|
this["~compilerSession"] = void 0;
|
|
180
180
|
this["~generation"] = void 0;
|
|
181
|
-
this["~introspect"] = void 0;
|
|
182
181
|
this["~scopeChild"] = scopeChild;
|
|
183
182
|
this["~scopeChildren"] = void 0;
|
|
184
183
|
if (config) {
|
|
@@ -191,9 +190,9 @@ var Elysia = class Elysia {
|
|
|
191
190
|
get routes() {
|
|
192
191
|
const generation = this["~generation"];
|
|
193
192
|
if (this.#isCacheable && this.cachedGeneration === generation && this.cachedEpoch === mutationEpoch && this.cachedRoutes !== void 0) return this.cachedRoutes;
|
|
194
|
-
|
|
195
|
-
if (!
|
|
196
|
-
const routes =
|
|
193
|
+
const declared = this["~routes"];
|
|
194
|
+
if (!declared.length) return [];
|
|
195
|
+
const routes = declared.map(([method, path, handler, instance, hook, appHook, inheritedChain, macroScope]) => {
|
|
197
196
|
const merged = require_compile_handler_index.composeRouteHook(instance, hook, appHook, inheritedChain, this, macroScope);
|
|
198
197
|
require_compile_handler_index.runIntrospect(merged);
|
|
199
198
|
if (merged?.schemas?.length) for (const entry of merged.schemas) {
|
|
@@ -367,7 +366,7 @@ var Elysia = class Elysia {
|
|
|
367
366
|
this.#assertMutable("error");
|
|
368
367
|
switch (arguments.length) {
|
|
369
368
|
case 1:
|
|
370
|
-
if (scopeOrFnOrError && typeof scopeOrFnOrError === "object")
|
|
369
|
+
if (scopeOrFnOrError && typeof scopeOrFnOrError === "object" && !Array.isArray(scopeOrFnOrError)) throw new Error("[Elysia] .error({ CODE: Class }) was removed in 2.0 — use .error(Class, handler)");
|
|
371
370
|
return this.#onBranch("error", scopeOrFnOrError);
|
|
372
371
|
case 2:
|
|
373
372
|
if (typeof scopeOrFnOrError === "function" && scopeOrFnOrError.prototype instanceof Object) return this.#onErrorClass(scopeOrFnOrError, fnOrError);
|
|
@@ -656,9 +655,7 @@ var Elysia = class Elysia {
|
|
|
656
655
|
}
|
|
657
656
|
#use(app) {
|
|
658
657
|
let addedByThisCall;
|
|
659
|
-
const
|
|
660
|
-
if (app["~introspect"] || config?.introspect) this["~introspect"] = true;
|
|
661
|
-
const name = config?.name;
|
|
658
|
+
const name = app["~config"]?.name;
|
|
662
659
|
if (name) {
|
|
663
660
|
const hash = app.hash;
|
|
664
661
|
if (this.childrenHash?.has(hash)) return;
|
package/dist/base.mjs
CHANGED
|
@@ -176,7 +176,6 @@ var Elysia = class Elysia {
|
|
|
176
176
|
this["~aotFingerprint"] = void 0;
|
|
177
177
|
this["~compilerSession"] = void 0;
|
|
178
178
|
this["~generation"] = void 0;
|
|
179
|
-
this["~introspect"] = void 0;
|
|
180
179
|
this["~scopeChild"] = scopeChild;
|
|
181
180
|
this["~scopeChildren"] = void 0;
|
|
182
181
|
if (config) {
|
|
@@ -189,9 +188,9 @@ var Elysia = class Elysia {
|
|
|
189
188
|
get routes() {
|
|
190
189
|
const generation = this["~generation"];
|
|
191
190
|
if (this.#isCacheable && this.cachedGeneration === generation && this.cachedEpoch === mutationEpoch && this.cachedRoutes !== void 0) return this.cachedRoutes;
|
|
192
|
-
|
|
193
|
-
if (!
|
|
194
|
-
const routes =
|
|
191
|
+
const declared = this["~routes"];
|
|
192
|
+
if (!declared.length) return [];
|
|
193
|
+
const routes = declared.map(([method, path, handler, instance, hook, appHook, inheritedChain, macroScope]) => {
|
|
195
194
|
const merged = composeRouteHook(instance, hook, appHook, inheritedChain, this, macroScope);
|
|
196
195
|
runIntrospect(merged);
|
|
197
196
|
if (merged?.schemas?.length) for (const entry of merged.schemas) {
|
|
@@ -365,7 +364,7 @@ var Elysia = class Elysia {
|
|
|
365
364
|
this.#assertMutable("error");
|
|
366
365
|
switch (arguments.length) {
|
|
367
366
|
case 1:
|
|
368
|
-
if (scopeOrFnOrError && typeof scopeOrFnOrError === "object")
|
|
367
|
+
if (scopeOrFnOrError && typeof scopeOrFnOrError === "object" && !Array.isArray(scopeOrFnOrError)) throw new Error("[Elysia] .error({ CODE: Class }) was removed in 2.0 \u2014 use .error(Class, handler)");
|
|
369
368
|
return this.#onBranch("error", scopeOrFnOrError);
|
|
370
369
|
case 2:
|
|
371
370
|
if (typeof scopeOrFnOrError === "function" && scopeOrFnOrError.prototype instanceof Object) return this.#onErrorClass(scopeOrFnOrError, fnOrError);
|
|
@@ -654,9 +653,7 @@ var Elysia = class Elysia {
|
|
|
654
653
|
}
|
|
655
654
|
#use(app) {
|
|
656
655
|
let addedByThisCall;
|
|
657
|
-
const
|
|
658
|
-
if (app["~introspect"] || config?.introspect) this["~introspect"] = true;
|
|
659
|
-
const name = config?.name;
|
|
656
|
+
const name = app["~config"]?.name;
|
|
660
657
|
if (name) {
|
|
661
658
|
const hash = app.hash;
|
|
662
659
|
if (this.childrenHash?.has(hash)) return;
|
|
@@ -13,8 +13,8 @@ const require_type_validator_frozen_check = require('../type/validator/frozen-ch
|
|
|
13
13
|
const require_type_validator_custom_error = require('../type/validator/custom-error.js');
|
|
14
14
|
const require_type_validator_exact_mirror = require('../type/validator/exact-mirror.js');
|
|
15
15
|
const require_type_validator_string_codec_aot = require('../type/validator/string-codec-aot.js');
|
|
16
|
-
let typebox_schema = require("typebox/schema");
|
|
17
16
|
let typebox_value = require("typebox/value");
|
|
17
|
+
let typebox_schema = require("typebox/schema");
|
|
18
18
|
|
|
19
19
|
//#region src/compile/aot-capture.ts
|
|
20
20
|
function emptyContainers(node, depth) {
|
|
@@ -57,7 +57,6 @@ function validateMergeSource(schema, source) {
|
|
|
57
57
|
const merger = require_type_validator_default_precompute.createMergerFromSource(source);
|
|
58
58
|
if (!merger) return false;
|
|
59
59
|
for (const probe of mergeProbes(schema)) {
|
|
60
|
-
if (probe === null || typeof probe !== "object") continue;
|
|
61
60
|
let expected;
|
|
62
61
|
try {
|
|
63
62
|
expected = (0, typebox_value.Default)(schema, structuredClone(probe));
|
|
@@ -76,7 +75,6 @@ function validateMergeSource(schema, source) {
|
|
|
76
75
|
}
|
|
77
76
|
const PROBE_SENTINEL = "__elysia_default_probe__";
|
|
78
77
|
function* defaultProbes(pod) {
|
|
79
|
-
if (!pod) return;
|
|
80
78
|
yield {};
|
|
81
79
|
for (const k in pod) {
|
|
82
80
|
yield { [k]: PROBE_SENTINEL };
|
|
@@ -213,23 +211,20 @@ function captureCodecMirror(schema, aot, slot, sanitize, dir) {
|
|
|
213
211
|
const ext = emitted.externals;
|
|
214
212
|
if (ext?.codecs && !ext.hof && require_compile_aot_emit.captureMirrorCodecs(schema, ext.codecs, dir)) {
|
|
215
213
|
let u;
|
|
216
|
-
|
|
217
|
-
if (ext.unions && ext.unions.length) {
|
|
214
|
+
if (ext.unions?.length) {
|
|
218
215
|
u = require_compile_aot_emit.captureMirrorUnions(schema, ext.unions);
|
|
219
|
-
if (!u)
|
|
220
|
-
}
|
|
221
|
-
if (freezable) {
|
|
222
|
-
const mirror = {
|
|
223
|
-
source: emitted.source,
|
|
224
|
-
hasExternals: true,
|
|
225
|
-
u
|
|
226
|
-
};
|
|
227
|
-
require_compile_aot.Capture.set({
|
|
228
|
-
method: aot.method,
|
|
229
|
-
path: aot.path,
|
|
230
|
-
slot
|
|
231
|
-
}, dir === "decode" ? { decodeMirror: mirror } : { encodeMirror: mirror });
|
|
216
|
+
if (!u) return;
|
|
232
217
|
}
|
|
218
|
+
const mirror = {
|
|
219
|
+
source: emitted.source,
|
|
220
|
+
hasExternals: true,
|
|
221
|
+
u
|
|
222
|
+
};
|
|
223
|
+
require_compile_aot.Capture.set({
|
|
224
|
+
method: aot.method,
|
|
225
|
+
path: aot.path,
|
|
226
|
+
slot
|
|
227
|
+
}, dir === "decode" ? { decodeMirror: mirror } : { encodeMirror: mirror });
|
|
233
228
|
}
|
|
234
229
|
}
|
|
235
230
|
} catch {}
|
|
@@ -12,8 +12,8 @@ import { buildFrozenCheck } from "../type/validator/frozen-check.mjs";
|
|
|
12
12
|
import { captureCustomErrors } from "../type/validator/custom-error.mjs";
|
|
13
13
|
import { getExactMirror } from "../type/validator/exact-mirror.mjs";
|
|
14
14
|
import { captureStringCodecEntries, compileWithBuild } from "../type/validator/string-codec-aot.mjs";
|
|
15
|
-
import { Build, Compile } from "typebox/schema";
|
|
16
15
|
import { Default } from "typebox/value";
|
|
16
|
+
import { Build, Compile } from "typebox/schema";
|
|
17
17
|
|
|
18
18
|
//#region src/compile/aot-capture.ts
|
|
19
19
|
function emptyContainers(node, depth) {
|
|
@@ -56,7 +56,6 @@ function validateMergeSource(schema, source) {
|
|
|
56
56
|
const merger = createMergerFromSource(source);
|
|
57
57
|
if (!merger) return false;
|
|
58
58
|
for (const probe of mergeProbes(schema)) {
|
|
59
|
-
if (probe === null || typeof probe !== "object") continue;
|
|
60
59
|
let expected;
|
|
61
60
|
try {
|
|
62
61
|
expected = Default(schema, structuredClone(probe));
|
|
@@ -75,7 +74,6 @@ function validateMergeSource(schema, source) {
|
|
|
75
74
|
}
|
|
76
75
|
const PROBE_SENTINEL = "__elysia_default_probe__";
|
|
77
76
|
function* defaultProbes(pod) {
|
|
78
|
-
if (!pod) return;
|
|
79
77
|
yield {};
|
|
80
78
|
for (const k in pod) {
|
|
81
79
|
yield { [k]: PROBE_SENTINEL };
|
|
@@ -212,23 +210,20 @@ function captureCodecMirror(schema, aot, slot, sanitize, dir) {
|
|
|
212
210
|
const ext = emitted.externals;
|
|
213
211
|
if (ext?.codecs && !ext.hof && captureMirrorCodecs(schema, ext.codecs, dir)) {
|
|
214
212
|
let u;
|
|
215
|
-
|
|
216
|
-
if (ext.unions && ext.unions.length) {
|
|
213
|
+
if (ext.unions?.length) {
|
|
217
214
|
u = captureMirrorUnions(schema, ext.unions);
|
|
218
|
-
if (!u)
|
|
219
|
-
}
|
|
220
|
-
if (freezable) {
|
|
221
|
-
const mirror = {
|
|
222
|
-
source: emitted.source,
|
|
223
|
-
hasExternals: true,
|
|
224
|
-
u
|
|
225
|
-
};
|
|
226
|
-
Capture.set({
|
|
227
|
-
method: aot.method,
|
|
228
|
-
path: aot.path,
|
|
229
|
-
slot
|
|
230
|
-
}, dir === "decode" ? { decodeMirror: mirror } : { encodeMirror: mirror });
|
|
215
|
+
if (!u) return;
|
|
231
216
|
}
|
|
217
|
+
const mirror = {
|
|
218
|
+
source: emitted.source,
|
|
219
|
+
hasExternals: true,
|
|
220
|
+
u
|
|
221
|
+
};
|
|
222
|
+
Capture.set({
|
|
223
|
+
method: aot.method,
|
|
224
|
+
path: aot.path,
|
|
225
|
+
slot
|
|
226
|
+
}, dir === "decode" ? { decodeMirror: mirror } : { encodeMirror: mirror });
|
|
232
227
|
}
|
|
233
228
|
}
|
|
234
229
|
} catch {}
|
|
@@ -5,7 +5,6 @@ declare function reconstructCheck(build: CheckBuildResult): {
|
|
|
5
5
|
defs: string;
|
|
6
6
|
value: string;
|
|
7
7
|
};
|
|
8
|
-
declare function externalsMatch(a: unknown[], b: unknown[]): boolean;
|
|
9
8
|
/**
|
|
10
9
|
* Align a TypeBox build's externals with the layout the runtime rebuilds from
|
|
11
10
|
* the schema (`collectExternals`). Returns the build as is when they already
|
|
@@ -28,4 +27,4 @@ declare function captureMirrorUnions(schema: unknown, truthUnions: any[][]): {
|
|
|
28
27
|
declare function captureMirrorCodecs(schema: unknown, truthCodecs: Function[], dir?: 'decode' | 'encode'): boolean;
|
|
29
28
|
declare function installReconstructImpl(): void;
|
|
30
29
|
//#endregion
|
|
31
|
-
export { Source, alignBuildExternals, captureMirrorCodecs, captureMirrorUnions,
|
|
30
|
+
export { Source, alignBuildExternals, captureMirrorCodecs, captureMirrorUnions, installReconstructImpl, reconstructCheck };
|
package/dist/compile/aot-emit.js
CHANGED
|
@@ -24,20 +24,10 @@ function reconstructCheckCode(build) {
|
|
|
24
24
|
}
|
|
25
25
|
const checkFactorySource = (identifier, code) => `(${identifier})=>{${code}}`;
|
|
26
26
|
const handlerFactorySource = (alias, code) => `function(h${alias ? "," + alias : ""}){return ${code}}`;
|
|
27
|
-
function
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const y = b[i];
|
|
32
|
-
if (x === y) continue;
|
|
33
|
-
if (x instanceof RegExp && y instanceof RegExp) {
|
|
34
|
-
if (x.source !== y.source || x.flags !== y.flags) return false;
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
if (Array.isArray(x) && Array.isArray(y) && x.length === y.length && x.findIndex((v, j) => v !== y[j]) === -1) continue;
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
return true;
|
|
27
|
+
function externalMatches(x, y) {
|
|
28
|
+
if (x === y) return true;
|
|
29
|
+
if (x instanceof RegExp && y instanceof RegExp) return x.source === y.source && x.flags === y.flags;
|
|
30
|
+
return Array.isArray(x) && Array.isArray(y) && x.length === y.length && x.findIndex((v, j) => v !== y[j]) === -1;
|
|
41
31
|
}
|
|
42
32
|
function alignBuildExternals(build, schema) {
|
|
43
33
|
const variables = build.external.variables;
|
|
@@ -49,7 +39,7 @@ function alignBuildExternals(build, schema) {
|
|
|
49
39
|
let same = variables.length === expected.length;
|
|
50
40
|
for (const v of variables) {
|
|
51
41
|
const c = expected[j];
|
|
52
|
-
if (j < expected.length &&
|
|
42
|
+
if (j < expected.length && externalMatches(c, v)) slots.push(`${id}[${j++}]`);
|
|
53
43
|
else if (Array.isArray(c) && c.length === 1 && c[0] === v) {
|
|
54
44
|
slots.push(`${id}[${j++}][0]`);
|
|
55
45
|
same = false;
|
|
@@ -111,6 +101,5 @@ exports.Source = Source;
|
|
|
111
101
|
exports.alignBuildExternals = alignBuildExternals;
|
|
112
102
|
exports.captureMirrorCodecs = captureMirrorCodecs;
|
|
113
103
|
exports.captureMirrorUnions = captureMirrorUnions;
|
|
114
|
-
exports.externalsMatch = externalsMatch;
|
|
115
104
|
exports.installReconstructImpl = installReconstructImpl;
|
|
116
105
|
exports.reconstructCheck = reconstructCheck;
|
|
@@ -24,20 +24,10 @@ function reconstructCheckCode(build) {
|
|
|
24
24
|
}
|
|
25
25
|
const checkFactorySource = (identifier, code) => `(${identifier})=>{${code}}`;
|
|
26
26
|
const handlerFactorySource = (alias, code) => `function(h${alias ? "," + alias : ""}){return ${code}}`;
|
|
27
|
-
function
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const y = b[i];
|
|
32
|
-
if (x === y) continue;
|
|
33
|
-
if (x instanceof RegExp && y instanceof RegExp) {
|
|
34
|
-
if (x.source !== y.source || x.flags !== y.flags) return false;
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
if (Array.isArray(x) && Array.isArray(y) && x.length === y.length && x.findIndex((v, j) => v !== y[j]) === -1) continue;
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
return true;
|
|
27
|
+
function externalMatches(x, y) {
|
|
28
|
+
if (x === y) return true;
|
|
29
|
+
if (x instanceof RegExp && y instanceof RegExp) return x.source === y.source && x.flags === y.flags;
|
|
30
|
+
return Array.isArray(x) && Array.isArray(y) && x.length === y.length && x.findIndex((v, j) => v !== y[j]) === -1;
|
|
41
31
|
}
|
|
42
32
|
function alignBuildExternals(build, schema) {
|
|
43
33
|
const variables = build.external.variables;
|
|
@@ -49,7 +39,7 @@ function alignBuildExternals(build, schema) {
|
|
|
49
39
|
let same = variables.length === expected.length;
|
|
50
40
|
for (const v of variables) {
|
|
51
41
|
const c = expected[j];
|
|
52
|
-
if (j < expected.length &&
|
|
42
|
+
if (j < expected.length && externalMatches(c, v)) slots.push(`${id}[${j++}]`);
|
|
53
43
|
else if (Array.isArray(c) && c.length === 1 && c[0] === v) {
|
|
54
44
|
slots.push(`${id}[${j++}][0]`);
|
|
55
45
|
same = false;
|
|
@@ -107,4 +97,4 @@ function installReconstructImpl() {
|
|
|
107
97
|
}
|
|
108
98
|
|
|
109
99
|
//#endregion
|
|
110
|
-
export { Source, alignBuildExternals, captureMirrorCodecs, captureMirrorUnions,
|
|
100
|
+
export { Source, alignBuildExternals, captureMirrorCodecs, captureMirrorUnions, installReconstructImpl, reconstructCheck };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_type_constants = require('../type/constants.js');
|
|
3
3
|
const require_compile_aot = require('./aot.js');
|
|
4
|
+
const require_type_shared = require('../type/shared.js');
|
|
4
5
|
|
|
5
6
|
//#region src/compile/aot-reconstruct.ts
|
|
6
7
|
const isValueLikeExternal = (v) => v === null || typeof v !== "object" && typeof v !== "function";
|
|
@@ -45,7 +46,7 @@ function collectMirrorUnions(schema, out = []) {
|
|
|
45
46
|
function collectMirrorCodecs(schema, out = [], dir = "decode") {
|
|
46
47
|
if (!schema || typeof schema !== "object") return out;
|
|
47
48
|
const codec = schema["~codec"];
|
|
48
|
-
if (codec && typeof codec[dir] === "function" && out.
|
|
49
|
+
if (codec && typeof codec[dir] === "function" && !out.some((fn) => require_type_shared.originalFunction(fn) === require_type_shared.originalFunction(codec[dir]))) out.push(codec[dir]);
|
|
49
50
|
if (schema.type === "object" && schema.properties) for (const key in schema.properties) collectMirrorCodecs(schema.properties[key], out, dir);
|
|
50
51
|
else if (schema.type === "array" && schema.items) if (Array.isArray(schema.items)) for (const it of schema.items) collectMirrorCodecs(it, out, dir);
|
|
51
52
|
else collectMirrorCodecs(schema.items, out, dir);
|
|
@@ -97,15 +98,17 @@ function reconstructInnerCodecs(ic, schema) {
|
|
|
97
98
|
const innerCheck = entry.c(entry.e ? collectExternals(innerSchema) : []);
|
|
98
99
|
const innerMirror = entry.d.x ? instantiateFrozenDecodeMirror(entry.d, innerSchema) : entry.d.s;
|
|
99
100
|
const open = entry.o;
|
|
100
|
-
node.codec["~refine"][0]
|
|
101
|
+
const refinement = node.codec["~refine"][0];
|
|
102
|
+
refinement.check = require_type_shared.replaceFunction((v) => {
|
|
101
103
|
if (v.charCodeAt(0) !== open) return false;
|
|
102
104
|
try {
|
|
103
105
|
return innerCheck(JSON.parse(v));
|
|
104
106
|
} catch {
|
|
105
107
|
return false;
|
|
106
108
|
}
|
|
107
|
-
};
|
|
108
|
-
node.codec["~codec"]
|
|
109
|
+
}, refinement.check);
|
|
110
|
+
const codec = node.codec["~codec"];
|
|
111
|
+
codec.decode = require_type_shared.replaceFunction((v) => innerMirror(JSON.parse(v)), codec.decode);
|
|
109
112
|
}
|
|
110
113
|
}
|
|
111
114
|
const Reconstruct = {
|