elysia 2.0.0-exp.0 → 2.0.0-exp.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/dist/adapter/bun/index.d.ts +1 -1
- package/dist/adapter/bun/index.js +6 -1
- package/dist/adapter/bun/index.mjs +6 -1
- package/dist/adapter/constants.d.ts +1 -1
- package/dist/adapter/index.d.ts +1 -1
- package/dist/adapter/utils.js +1 -1
- package/dist/adapter/utils.mjs +1 -1
- package/dist/adapter/web-standard/index.d.ts +1 -1
- package/dist/base.d.ts +10 -26
- package/dist/base.js +2 -1
- package/dist/base.mjs +2 -1
- package/dist/compile/aot.d.ts +12 -2
- package/dist/compile/aot.js +20 -10
- package/dist/compile/aot.mjs +20 -11
- package/dist/compile/handler/index.js +22 -16
- package/dist/compile/handler/index.mjs +23 -17
- package/dist/compile/utils.d.ts +2 -1
- package/dist/compile/utils.js +9 -1
- package/dist/compile/utils.mjs +8 -1
- package/dist/plugin/source.js +6 -0
- package/dist/plugin/source.mjs +6 -0
- package/dist/type/compat.js +2 -0
- package/dist/type/compat.mjs +2 -0
- package/dist/type/constants.d.ts +1 -1
- package/dist/type/elysia/boolean-string.d.ts +1 -1
- package/dist/type/elysia/boolean-string.js +1 -2
- package/dist/type/elysia/boolean-string.mjs +1 -2
- package/dist/type/elysia/date.js +10 -4
- package/dist/type/elysia/date.mjs +10 -4
- package/dist/type/elysia/form.js +2 -2
- package/dist/type/elysia/form.mjs +2 -2
- package/dist/type/elysia/integer-string.js +2 -1
- package/dist/type/elysia/integer-string.mjs +2 -1
- package/dist/type/elysia/numeric-enum.js +1 -0
- package/dist/type/elysia/numeric-enum.mjs +1 -0
- package/dist/type/elysia/numeric.js +2 -1
- package/dist/type/elysia/numeric.mjs +2 -1
- package/dist/type/exports.js +1 -1
- package/dist/type/exports.mjs +1 -1
- package/dist/type/validator.js +64 -0
- package/dist/type/validator.mjs +65 -1
- package/dist/types.d.ts +15 -3
- package/dist/utils.js +4 -2
- package/dist/utils.mjs +4 -2
- package/dist/validator/route.js +8 -8
- package/dist/validator/route.mjs +8 -8
- package/dist/ws/parser.js +6 -1
- package/dist/ws/parser.mjs +6 -1
- package/package.json +3 -3
|
@@ -6,7 +6,7 @@ import { AnyElysia } from "../../base.js";
|
|
|
6
6
|
declare function collectStaticRoutes(app: AnyElysia): readonly [Record<string, Record<string, Response>>, Promise<void>[]] | undefined;
|
|
7
7
|
declare const BunAdapter: {
|
|
8
8
|
parse: {
|
|
9
|
-
default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | Promise<
|
|
9
|
+
default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | Promise<Record<string, unknown>> | Promise<ArrayBuffer> | Promise<string> | Promise<unknown[] | Record<string | number | symbol, undefined>> | undefined;
|
|
10
10
|
json: (context: Context) => MaybePromise<Record<keyof any, undefined> | unknown[]>;
|
|
11
11
|
text: (context: Context) => MaybePromise<string>;
|
|
12
12
|
urlencoded: (context: Context) => MaybePromise<Record<string, string | string[]>>;
|
|
@@ -35,7 +35,12 @@ const BunAdapter = require_adapter_index.createAdapter({
|
|
|
35
35
|
name: "bun",
|
|
36
36
|
runtime: "bun",
|
|
37
37
|
listen(app, options, callback) {
|
|
38
|
-
const
|
|
38
|
+
const _config = app["~config"]?.serve;
|
|
39
|
+
const _options = typeof options === "object" ? options : { port: +options };
|
|
40
|
+
const serve = _config ? {
|
|
41
|
+
..._config,
|
|
42
|
+
..._options
|
|
43
|
+
} : _options;
|
|
39
44
|
const hasWs = app["~hasWS"];
|
|
40
45
|
serve.fetch = (request, server) => app.fetch(request, server);
|
|
41
46
|
app.server = Bun.serve(serve);
|
|
@@ -34,7 +34,12 @@ const BunAdapter = createAdapter({
|
|
|
34
34
|
name: "bun",
|
|
35
35
|
runtime: "bun",
|
|
36
36
|
listen(app, options, callback) {
|
|
37
|
-
const
|
|
37
|
+
const _config = app["~config"]?.serve;
|
|
38
|
+
const _options = typeof options === "object" ? options : { port: +options };
|
|
39
|
+
const serve = _config ? {
|
|
40
|
+
..._config,
|
|
41
|
+
..._options
|
|
42
|
+
} : _options;
|
|
38
43
|
const hasWs = app["~hasWS"];
|
|
39
44
|
serve.fetch = (request, server) => app.fetch(request, server);
|
|
40
45
|
app.server = Bun.serve(serve);
|
|
@@ -5,7 +5,7 @@ import { AnyElysia } from "../base.js";
|
|
|
5
5
|
//#region src/adapter/constants.d.ts
|
|
6
6
|
declare const defaultAdapter: {
|
|
7
7
|
parse: {
|
|
8
|
-
default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | Promise<
|
|
8
|
+
default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | Promise<Record<string, unknown>> | Promise<ArrayBuffer> | Promise<string> | Promise<unknown[] | Record<string | number | symbol, undefined>> | undefined;
|
|
9
9
|
json: (context: Context) => MaybePromise<Record<keyof any, undefined> | unknown[]>;
|
|
10
10
|
text: (context: Context) => MaybePromise<string>;
|
|
11
11
|
urlencoded: (context: Context) => MaybePromise<Record<string, string | string[]>>;
|
package/dist/adapter/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { AnyElysia } from "../base.js";
|
|
|
7
7
|
//#region src/adapter/index.d.ts
|
|
8
8
|
declare function createAdapter(adapter: ElysiaAdapterOptions): {
|
|
9
9
|
parse: {
|
|
10
|
-
default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | Promise<
|
|
10
|
+
default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | Promise<Record<string, unknown>> | Promise<ArrayBuffer> | Promise<string> | Promise<unknown[] | Record<string | number | symbol, undefined>> | undefined;
|
|
11
11
|
json: (context: Context) => MaybePromise<Record<keyof any, undefined> | unknown[]>;
|
|
12
12
|
text: (context: Context) => MaybePromise<string>;
|
|
13
13
|
urlencoded: (context: Context) => MaybePromise<Record<string, string | string[]>>;
|
package/dist/adapter/utils.js
CHANGED
|
@@ -209,7 +209,7 @@ async function* streamResponse(response) {
|
|
|
209
209
|
function handleSet(set) {
|
|
210
210
|
if (typeof set.status === "string") set.status = require_constants.StatusMap[set.status];
|
|
211
211
|
const proto = Object.getPrototypeOf(set.headers);
|
|
212
|
-
if (proto !== null && proto !== Object.prototype) {
|
|
212
|
+
if (proto !== null && proto !== Object.prototype && !(set.headers instanceof Headers)) {
|
|
213
213
|
const flat = Object.create(null);
|
|
214
214
|
for (const key in set.headers) flat[key] = set.headers[key];
|
|
215
215
|
set.headers = flat;
|
package/dist/adapter/utils.mjs
CHANGED
|
@@ -208,7 +208,7 @@ async function* streamResponse(response) {
|
|
|
208
208
|
function handleSet(set) {
|
|
209
209
|
if (typeof set.status === "string") set.status = StatusMap[set.status];
|
|
210
210
|
const proto = Object.getPrototypeOf(set.headers);
|
|
211
|
-
if (proto !== null && proto !== Object.prototype) {
|
|
211
|
+
if (proto !== null && proto !== Object.prototype && !(set.headers instanceof Headers)) {
|
|
212
212
|
const flat = Object.create(null);
|
|
213
213
|
for (const key in set.headers) flat[key] = set.headers[key];
|
|
214
214
|
set.headers = flat;
|
|
@@ -5,7 +5,7 @@ import { AnyElysia } from "../../base.js";
|
|
|
5
5
|
//#region src/adapter/web-standard/index.d.ts
|
|
6
6
|
declare const WebStandardAdapter: {
|
|
7
7
|
parse: {
|
|
8
|
-
default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | Promise<
|
|
8
|
+
default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | Promise<Record<string, unknown>> | Promise<ArrayBuffer> | Promise<string> | Promise<unknown[] | Record<string | number | symbol, undefined>> | undefined;
|
|
9
9
|
json: (context: Context) => MaybePromise<Record<keyof any, undefined> | unknown[]>;
|
|
10
10
|
text: (context: Context) => MaybePromise<string>;
|
|
11
11
|
urlencoded: (context: Context) => MaybePromise<Record<string, string | string[]>>;
|
package/dist/base.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ElysiaStatus } from "./error.js";
|
|
2
2
|
import { TraceHandler } from "./trace.js";
|
|
3
3
|
import { ListenCallback, Serve, Server } from "./universal/server.js";
|
|
4
|
-
import { AfterHandler, AfterResponseHandler, AnyErrorConstructor, AnyLocalHook, AppEvent, BodyHandler, CompiledHandler,
|
|
4
|
+
import { AddRoute, AddWSRoute, AfterHandler, AfterResponseHandler, AnyErrorConstructor, AnyLocalHook, AppEvent, BodyHandler, CompiledHandler, CreateEden, DefaultEphemeral, DefaultMetadata, DefaultSingleton, DefinitionBase, DocumentDecoration, ElysiaConfig, ElysiaHandlerToResponseSchemaAmbiguous, EphemeralType, ErrorDefinitionEntry, ErrorHandler, EventFn, EventScope, ExcludeElysiaResponse, ExtractErrorFromHandle, GuardLocalHook, HTTPMethod, InlineHandler, InlineHandlerNonMacro, InputSchema, InputSchemaKey, InternalRoute, IntersectIfObjectSchema, JoinPath, LocalHook, Macro, MacroToContext, MacroToProperty, MapResponse, MaybeArray, MaybePromise, MergeElysiaInstances, MergeSchema, MergeScopedSchemas, MetadataBase, NonResolvableMacroKey, ObjectMacroDefs, OptionalHandler, PreHandler, Prettify, PublicRoute, ResolveRouteErrors, RouteBase, SingletonBase, TransformHandler, UnionResponseStatus, UnwrapRoute, WrapFn } from "./types.js";
|
|
5
5
|
import { AnySchema } from "./type/types.js";
|
|
6
6
|
import { ChainNode } from "./utils.js";
|
|
7
7
|
import { Context, ErrorContext, LifecycleContext } from "./context.js";
|
|
@@ -11,22 +11,6 @@ import { TRef, TSchema } from "typebox";
|
|
|
11
11
|
|
|
12
12
|
//#region src/base.d.ts
|
|
13
13
|
type AnyElysia = Elysia<any, any, any, any, any, any, any, any>;
|
|
14
|
-
/**
|
|
15
|
-
* Shared return type for the HTTP verb methods' overloads — folds a single
|
|
16
|
-
* route into the instance's Eden tree. Factored out so each verb's two
|
|
17
|
-
* overloads (with-hook / no-hook) don't each re-spell the ~50-line type.
|
|
18
|
-
* `Method` is a literal (`'get'`) for the verbs, or the generic method for
|
|
19
|
-
* `.method()`. `MacroContext` is `{}` on the no-hook overload.
|
|
20
|
-
*/
|
|
21
|
-
type AddRoute<BasePath extends string, Scope extends EventScope, Singleton extends SingletonBase, Definitions extends DefinitionBase, Metadata extends MetadataBase, Routes extends RouteBase, Ephemeral extends EphemeralType, Volatile extends EphemeralType, Method extends string, Path extends string, Schema extends RouteSchema, MacroContext extends RouteSchema, Handle> = Elysia<BasePath, Scope, Singleton, Definitions, Metadata, Routes & CreateEden<JoinPath<BasePath, Path>, { [method in Method]: CreateEdenResponse<Path, Schema, MacroContext, ComposeElysiaResponse<Schema & MacroContext & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], Handle, UnionResponseStatus<Metadata['response'], UnionResponseStatus<Ephemeral['response'], UnionResponseStatus<Volatile['response'], MacroContext['return'] & {}>>>, [...Definitions['error'], ...Ephemeral['error'], ...Volatile['error']]>, UnhandledReturnedErrorOf<Handle, [...Definitions['error'], ...Ephemeral['error'], ...Volatile['error']]>> }>, Ephemeral, Volatile>;
|
|
22
|
-
/**
|
|
23
|
-
* `AddRoute`'s WebSocket sibling — folds a `.ws()` route into the Eden tree
|
|
24
|
-
* under the `subscribe` key. `Response` is `void` for the options-only form,
|
|
25
|
-
* or `WSHandlerResponse<Handler>` when a positional message handler is given.
|
|
26
|
-
*/
|
|
27
|
-
type AddWSRoute<BasePath extends string, Scope extends EventScope, Singleton extends SingletonBase, Definitions extends DefinitionBase, Metadata extends MetadataBase, Routes extends RouteBase, Ephemeral extends EphemeralType, Volatile extends EphemeralType, Path extends string, Schema extends RouteSchema, MacroContext extends RouteSchema, Response> = Elysia<BasePath, Scope, Singleton, Definitions, Metadata, Routes & CreateEden<JoinPath<BasePath, Path>, {
|
|
28
|
-
subscribe: CreateWSEdenResponse<Path, Schema, MacroContext, ComposeElysiaResponse<Schema & MacroContext & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], Response, UnionResponseStatus<Metadata['response'], UnionResponseStatus<Ephemeral['response'], UnionResponseStatus<Volatile['response'], MacroContext['return'] & {}>>>, [...Definitions['error'], ...Ephemeral['error'], ...Volatile['error']]>>;
|
|
29
|
-
}>, Ephemeral, Volatile>;
|
|
30
14
|
declare class Elysia<const in out BasePath extends string = '', const in out Scope extends EventScope = 'local', const in out Singleton extends SingletonBase = DefaultSingleton, const in out Definitions extends DefinitionBase = {
|
|
31
15
|
typebox: {};
|
|
32
16
|
error: [];
|
|
@@ -889,7 +873,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
889
873
|
}, const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Omit<Input, NonResolvableMacroKey>, Definitions['typebox']>), const Handle extends ({} extends MacroContext ? InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>> : InlineHandler<NoInfer<Schema>, NoInfer<Decorator>, MacroContext>)>(path: Path, hook: LocalHook<Input, Schema & MacroContext, Decorator, Definitions['error'], keyof Metadata['parser']>, fn: Handle): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, 'get', Path, Schema, MacroContext, Handle>;
|
|
890
874
|
get<const Path extends string, const Schema extends IntersectIfObjectSchema<MergeSchema<UnwrapRoute<{}, Definitions['typebox'], JoinPath<BasePath, Path>>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, '', true>, MergeScopedSchemas<Metadata['schemas'], Ephemeral['schemas'], Volatile['schemas']>>, const Decorator extends Singleton & {
|
|
891
875
|
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
892
|
-
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator
|
|
876
|
+
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>>>(path: Path, fn: Handle & Metadata['macro']): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, 'get', Path, Schema, {}, Handle>;
|
|
893
877
|
/**
|
|
894
878
|
* ### post
|
|
895
879
|
* Register handler for path with method [POST]
|
|
@@ -909,7 +893,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
909
893
|
}, const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Omit<Input, NonResolvableMacroKey>, Definitions['typebox']>), const Handle extends ({} extends MacroContext ? InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>> : InlineHandler<NoInfer<Schema>, NoInfer<Decorator>, MacroContext>)>(path: Path, hook: LocalHook<Input, Schema & MacroContext, Decorator, Definitions['error'], keyof Metadata['parser']>, fn: Handle): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, 'post', Path, Schema, MacroContext, Handle>;
|
|
910
894
|
post<const Path extends string, const Schema extends IntersectIfObjectSchema<MergeSchema<UnwrapRoute<{}, Definitions['typebox'], JoinPath<BasePath, Path>>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, '', true>, MergeScopedSchemas<Metadata['schemas'], Ephemeral['schemas'], Volatile['schemas']>>, const Decorator extends Singleton & {
|
|
911
895
|
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
912
|
-
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator
|
|
896
|
+
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>>>(path: Path, fn: Handle & Metadata['macro']): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, 'post', Path, Schema, {}, Handle>;
|
|
913
897
|
/**
|
|
914
898
|
* ### put
|
|
915
899
|
* Register handler for path with method [PUT]
|
|
@@ -929,7 +913,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
929
913
|
}, const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Omit<Input, NonResolvableMacroKey>, Definitions['typebox']>), const Handle extends ({} extends MacroContext ? InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>> : InlineHandler<NoInfer<Schema>, NoInfer<Decorator>, MacroContext>)>(path: Path, hook: LocalHook<Input, Schema & MacroContext, Decorator, Definitions['error'], keyof Metadata['parser']>, fn: Handle): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, 'put', Path, Schema, MacroContext, Handle>;
|
|
930
914
|
put<const Path extends string, const Schema extends IntersectIfObjectSchema<MergeSchema<UnwrapRoute<{}, Definitions['typebox'], JoinPath<BasePath, Path>>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, '', true>, MergeScopedSchemas<Metadata['schemas'], Ephemeral['schemas'], Volatile['schemas']>>, const Decorator extends Singleton & {
|
|
931
915
|
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
932
|
-
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator
|
|
916
|
+
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>>>(path: Path, fn: Handle & Metadata['macro']): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, 'put', Path, Schema, {}, Handle>;
|
|
933
917
|
/**
|
|
934
918
|
* ### patch
|
|
935
919
|
* Register handler for path with method [PATCH]
|
|
@@ -949,7 +933,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
949
933
|
}, const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Omit<Input, NonResolvableMacroKey>, Definitions['typebox']>), const Handle extends ({} extends MacroContext ? InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>> : InlineHandler<NoInfer<Schema>, NoInfer<Decorator>, MacroContext>)>(path: Path, hook: LocalHook<Input, Schema & MacroContext, Decorator, Definitions['error'], keyof Metadata['parser']>, fn: Handle): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, 'patch', Path, Schema, MacroContext, Handle>;
|
|
950
934
|
patch<const Path extends string, const Schema extends IntersectIfObjectSchema<MergeSchema<UnwrapRoute<{}, Definitions['typebox'], JoinPath<BasePath, Path>>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, '', true>, MergeScopedSchemas<Metadata['schemas'], Ephemeral['schemas'], Volatile['schemas']>>, const Decorator extends Singleton & {
|
|
951
935
|
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
952
|
-
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator
|
|
936
|
+
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>>>(path: Path, fn: Handle & Metadata['macro']): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, 'patch', Path, Schema, {}, Handle>;
|
|
953
937
|
/**
|
|
954
938
|
* ### delete
|
|
955
939
|
* Register handler for path with method [DELETE]
|
|
@@ -969,7 +953,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
969
953
|
}, const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Omit<Input, NonResolvableMacroKey>, Definitions['typebox']>), const Handle extends ({} extends MacroContext ? InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>> : InlineHandler<NoInfer<Schema>, NoInfer<Decorator>, MacroContext>)>(path: Path, hook: LocalHook<Input, Schema & MacroContext, Decorator, Definitions['error'], keyof Metadata['parser']>, fn: Handle): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, 'delete', Path, Schema, MacroContext, Handle>;
|
|
970
954
|
delete<const Path extends string, const Schema extends IntersectIfObjectSchema<MergeSchema<UnwrapRoute<{}, Definitions['typebox'], JoinPath<BasePath, Path>>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, '', true>, MergeScopedSchemas<Metadata['schemas'], Ephemeral['schemas'], Volatile['schemas']>>, const Decorator extends Singleton & {
|
|
971
955
|
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
972
|
-
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator
|
|
956
|
+
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>>>(path: Path, fn: Handle & Metadata['macro']): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, 'delete', Path, Schema, {}, Handle>;
|
|
973
957
|
/**
|
|
974
958
|
* ### options
|
|
975
959
|
* Register handler for path with method [OPTIONS]
|
|
@@ -989,7 +973,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
989
973
|
}, const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Omit<Input, NonResolvableMacroKey>, Definitions['typebox']>), const Handle extends ({} extends MacroContext ? InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>> : InlineHandler<NoInfer<Schema>, NoInfer<Decorator>, MacroContext>)>(path: Path, hook: LocalHook<Input, Schema & MacroContext, Decorator, Definitions['error'], keyof Metadata['parser']>, fn: Handle): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, 'options', Path, Schema, MacroContext, Handle>;
|
|
990
974
|
options<const Path extends string, const Schema extends IntersectIfObjectSchema<MergeSchema<UnwrapRoute<{}, Definitions['typebox'], JoinPath<BasePath, Path>>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, '', true>, MergeScopedSchemas<Metadata['schemas'], Ephemeral['schemas'], Volatile['schemas']>>, const Decorator extends Singleton & {
|
|
991
975
|
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
992
|
-
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator
|
|
976
|
+
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>>>(path: Path, fn: Handle & Metadata['macro']): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, 'options', Path, Schema, {}, Handle>;
|
|
993
977
|
/**
|
|
994
978
|
* ### head
|
|
995
979
|
* Register handler for path with method [HEAD]
|
|
@@ -1009,13 +993,13 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
1009
993
|
}, const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Omit<Input, NonResolvableMacroKey>, Definitions['typebox']>), const Handle extends ({} extends MacroContext ? InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>> : InlineHandler<NoInfer<Schema>, NoInfer<Decorator>, MacroContext>)>(path: Path, hook: LocalHook<Input, Schema & MacroContext, Decorator, Definitions['error'], keyof Metadata['parser']>, fn: Handle): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, 'head', Path, Schema, MacroContext, Handle>;
|
|
1010
994
|
head<const Path extends string, const Schema extends IntersectIfObjectSchema<MergeSchema<UnwrapRoute<{}, Definitions['typebox'], JoinPath<BasePath, Path>>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, '', true>, MergeScopedSchemas<Metadata['schemas'], Ephemeral['schemas'], Volatile['schemas']>>, const Decorator extends Singleton & {
|
|
1011
995
|
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
1012
|
-
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator
|
|
996
|
+
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>>>(path: Path, fn: Handle & Metadata['macro']): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, 'head', Path, Schema, {}, Handle>;
|
|
1013
997
|
all<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 Decorator extends Singleton & {
|
|
1014
998
|
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
1015
999
|
}, const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Omit<Input, NonResolvableMacroKey>, Definitions['typebox']>), const Handle extends ({} extends MacroContext ? InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>> : InlineHandler<NoInfer<Schema>, NoInfer<Decorator>, MacroContext>)>(path: Path, hook: LocalHook<Input, Schema & MacroContext, Decorator, Definitions['error'], keyof Metadata['parser']>, fn: Handle): this;
|
|
1016
1000
|
all<const Path extends string, const Schema extends IntersectIfObjectSchema<MergeSchema<UnwrapRoute<{}, Definitions['typebox'], JoinPath<BasePath, Path>>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, '', true>, MergeScopedSchemas<Metadata['schemas'], Ephemeral['schemas'], Volatile['schemas']>>, const Decorator extends Singleton & {
|
|
1017
1001
|
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
1018
|
-
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator
|
|
1002
|
+
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>>>(path: Path, fn: Handle & Metadata['macro']): this;
|
|
1019
1003
|
/**
|
|
1020
1004
|
* ### method
|
|
1021
1005
|
* Register a handler for `path` with an arbitrary HTTP `method`
|
|
@@ -1034,7 +1018,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
1034
1018
|
}, const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Omit<Input, NonResolvableMacroKey>, Definitions['typebox']>), const Handle extends ({} extends MacroContext ? InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>> : InlineHandler<NoInfer<Schema>, NoInfer<Decorator>, MacroContext>)>(method: Method, path: Path, hook: LocalHook<Input, Schema & MacroContext, Decorator, Definitions['error'], keyof Metadata['parser']>, fn: Handle): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, Method, Path, Schema, MacroContext, Handle>;
|
|
1035
1019
|
method<const Method extends HTTPMethod, const Path extends string, const Schema extends IntersectIfObjectSchema<MergeSchema<UnwrapRoute<{}, Definitions['typebox'], JoinPath<BasePath, Path>>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, '', true>, MergeScopedSchemas<Metadata['schemas'], Ephemeral['schemas'], Volatile['schemas']>>, const Decorator extends Singleton & {
|
|
1036
1020
|
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
1037
|
-
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator
|
|
1021
|
+
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>>>(method: Method, path: Path, fn: Handle & Metadata['macro']): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, Method, Path, Schema, {}, Handle>;
|
|
1038
1022
|
/**
|
|
1039
1023
|
* ### ws
|
|
1040
1024
|
* Register a WebSocket route. Mirrors `.get`/`.post` ergonomics:
|
package/dist/base.js
CHANGED
|
@@ -585,7 +585,7 @@ var Elysia = class Elysia {
|
|
|
585
585
|
const isGlobal = nodeScope === "global";
|
|
586
586
|
const added = node.added;
|
|
587
587
|
for (const key in added) {
|
|
588
|
-
if (key === "
|
|
588
|
+
if (key === "schemas") {
|
|
589
589
|
const schemas = added.schemas;
|
|
590
590
|
if (!schemas) continue;
|
|
591
591
|
const target = isGlobal ? globalEvents ??= require_utils.nullObject() : pluginEvents ??= require_utils.nullObject();
|
|
@@ -595,6 +595,7 @@ var Elysia = class Elysia {
|
|
|
595
595
|
}
|
|
596
596
|
continue;
|
|
597
597
|
}
|
|
598
|
+
if (key === "schema") continue;
|
|
598
599
|
if (require_utils.eventProperties.has(key)) {
|
|
599
600
|
const raw = added[key];
|
|
600
601
|
const fns = Array.isArray(raw) ? raw : [raw];
|
package/dist/base.mjs
CHANGED
|
@@ -582,7 +582,7 @@ var Elysia = class Elysia {
|
|
|
582
582
|
const isGlobal = nodeScope === "global";
|
|
583
583
|
const added = node.added;
|
|
584
584
|
for (const key in added) {
|
|
585
|
-
if (key === "
|
|
585
|
+
if (key === "schemas") {
|
|
586
586
|
const schemas = added.schemas;
|
|
587
587
|
if (!schemas) continue;
|
|
588
588
|
const target = isGlobal ? globalEvents ??= nullObject() : pluginEvents ??= nullObject();
|
|
@@ -592,6 +592,7 @@ var Elysia = class Elysia {
|
|
|
592
592
|
}
|
|
593
593
|
continue;
|
|
594
594
|
}
|
|
595
|
+
if (key === "schema") continue;
|
|
595
596
|
if (eventProperties.has(key)) {
|
|
596
597
|
const raw = added[key];
|
|
597
598
|
const fns = Array.isArray(raw) ? raw : [raw];
|
package/dist/compile/aot.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ interface FrozenValidator {
|
|
|
19
19
|
c?: FrozenCheckFactory;
|
|
20
20
|
m?: FrozenMirror;
|
|
21
21
|
dm?: FrozenMirror;
|
|
22
|
+
em?: FrozenMirror;
|
|
22
23
|
/** Merged check + clean (present iff a slot froze BOTH; supersedes `c`/`m`). */
|
|
23
24
|
cm?: FrozenBothFactory;
|
|
24
25
|
/** Union branch checks for the merged mirror (entry-level `m.u`). */
|
|
@@ -83,6 +84,7 @@ declare const Source: {
|
|
|
83
84
|
};
|
|
84
85
|
declare function instantiateFrozenMirror(frozen: FrozenMirror, schema: unknown): (value: unknown) => unknown;
|
|
85
86
|
declare function instantiateFrozenDecodeMirror(frozen: FrozenMirror, schema: unknown): (value: unknown) => unknown;
|
|
87
|
+
declare function instantiateFrozenEncodeMirror(frozen: FrozenMirror, schema: unknown): (value: unknown) => unknown;
|
|
86
88
|
declare function instantiateFrozenBoth(frozen: FrozenValidator, checkSchema: unknown, mirrorSchema: unknown): {
|
|
87
89
|
check?: (value: unknown) => boolean;
|
|
88
90
|
clean?: (value: unknown) => unknown;
|
|
@@ -97,7 +99,7 @@ declare function captureMirrorUnions(schema: unknown, truthUnions: any[][]): {
|
|
|
97
99
|
identifier: string;
|
|
98
100
|
code: string;
|
|
99
101
|
}[][] | undefined;
|
|
100
|
-
declare function captureMirrorCodecs(schema: unknown, truthCodecs: Function[]): boolean;
|
|
102
|
+
declare function captureMirrorCodecs(schema: unknown, truthCodecs: Function[], dir?: 'decode' | 'encode'): boolean;
|
|
101
103
|
interface CapturedMirror {
|
|
102
104
|
source: string;
|
|
103
105
|
hasExternals: boolean;
|
|
@@ -120,6 +122,7 @@ interface CapturedValidator {
|
|
|
120
122
|
hasRef?: boolean;
|
|
121
123
|
mirror?: CapturedMirror;
|
|
122
124
|
decodeMirror?: CapturedMirror;
|
|
125
|
+
encodeMirror?: CapturedMirror;
|
|
123
126
|
}
|
|
124
127
|
declare function beginValidatorCapture(): void;
|
|
125
128
|
declare function endValidatorCapture(): CapturedValidator[];
|
|
@@ -156,14 +159,21 @@ declare function captureDecodeMirror(v: {
|
|
|
156
159
|
slot: ValidatorSlot;
|
|
157
160
|
mirror: CapturedMirror;
|
|
158
161
|
}): void;
|
|
162
|
+
declare function captureEncodeMirror(v: {
|
|
163
|
+
method: string;
|
|
164
|
+
path: string;
|
|
165
|
+
slot: ValidatorSlot;
|
|
166
|
+
mirror: CapturedMirror;
|
|
167
|
+
}): void;
|
|
159
168
|
declare const Capture: {
|
|
160
169
|
readonly validator: typeof captureValidator;
|
|
161
170
|
readonly handler: typeof captureHandler;
|
|
162
171
|
readonly mirror: typeof captureMirror;
|
|
163
172
|
readonly mirrorDecode: typeof captureDecodeMirror;
|
|
173
|
+
readonly mirrorEncode: typeof captureEncodeMirror;
|
|
164
174
|
readonly mirrorUnions: typeof captureMirrorUnions;
|
|
165
175
|
readonly mirrorCodecs: typeof captureMirrorCodecs;
|
|
166
176
|
readonly isCapturing: () => boolean;
|
|
167
177
|
};
|
|
168
178
|
//#endregion
|
|
169
|
-
export { Capture, CapturedHandler, CapturedMirror, CapturedValidator, CheckBuildResult, Compiled, FrozenBothFactory, FrozenCheckFactory, FrozenHandler, FrozenMirror, FrozenMirrorFactory, FrozenValidator, HandlerManifest, Source, ValidatorManifest, ValidatorSlot, beginValidatorCapture, collectExternals, endHandlerCapture, endValidatorCapture, externalsMatch, instantiateFrozenBoth, instantiateFrozenDecodeMirror, instantiateFrozenMirror, reconstructCheck };
|
|
179
|
+
export { Capture, CapturedHandler, CapturedMirror, CapturedValidator, CheckBuildResult, Compiled, FrozenBothFactory, FrozenCheckFactory, FrozenHandler, FrozenMirror, FrozenMirrorFactory, FrozenValidator, HandlerManifest, Source, ValidatorManifest, ValidatorSlot, beginValidatorCapture, collectExternals, endHandlerCapture, endValidatorCapture, externalsMatch, instantiateFrozenBoth, instantiateFrozenDecodeMirror, instantiateFrozenEncodeMirror, instantiateFrozenMirror, reconstructCheck };
|
package/dist/compile/aot.js
CHANGED
|
@@ -148,15 +148,14 @@ function collectMirrorUnions(schema, out = []) {
|
|
|
148
148
|
}
|
|
149
149
|
return out;
|
|
150
150
|
}
|
|
151
|
-
|
|
152
|
-
function collectMirrorCodecs(schema, out = []) {
|
|
151
|
+
function collectMirrorCodecs(schema, out = [], dir = "decode") {
|
|
153
152
|
if (!schema || typeof schema !== "object") return out;
|
|
154
|
-
const codec = schema[
|
|
155
|
-
if (codec && typeof codec
|
|
156
|
-
if (schema.type === "object" && schema.properties) for (const key in schema.properties) collectMirrorCodecs(schema.properties[key], out);
|
|
157
|
-
else if (schema.type === "array" && schema.items) if (Array.isArray(schema.items)) for (const it of schema.items) collectMirrorCodecs(it, out);
|
|
158
|
-
else collectMirrorCodecs(schema.items, out);
|
|
159
|
-
else if (Array.isArray(schema.anyOf)) for (const b of schema.anyOf) collectMirrorCodecs(b, out);
|
|
153
|
+
const codec = schema["~codec"];
|
|
154
|
+
if (codec && typeof codec[dir] === "function" && out.indexOf(codec[dir]) === -1) out.push(codec[dir]);
|
|
155
|
+
if (schema.type === "object" && schema.properties) for (const key in schema.properties) collectMirrorCodecs(schema.properties[key], out, dir);
|
|
156
|
+
else if (schema.type === "array" && schema.items) if (Array.isArray(schema.items)) for (const it of schema.items) collectMirrorCodecs(it, out, dir);
|
|
157
|
+
else collectMirrorCodecs(schema.items, out, dir);
|
|
158
|
+
else if (Array.isArray(schema.anyOf)) for (const b of schema.anyOf) collectMirrorCodecs(b, out, dir);
|
|
160
159
|
return out;
|
|
161
160
|
}
|
|
162
161
|
function buildUnions(u, schema) {
|
|
@@ -172,6 +171,11 @@ function instantiateFrozenDecodeMirror(frozen, schema) {
|
|
|
172
171
|
if (frozen.u) d.unions = buildUnions(frozen.u, schema);
|
|
173
172
|
return frozen.s(d);
|
|
174
173
|
}
|
|
174
|
+
function instantiateFrozenEncodeMirror(frozen, schema) {
|
|
175
|
+
const d = { codecs: collectMirrorCodecs(schema, [], "encode") };
|
|
176
|
+
if (frozen.u) d.unions = buildUnions(frozen.u, schema);
|
|
177
|
+
return frozen.s(d);
|
|
178
|
+
}
|
|
175
179
|
const EMPTY_EXTERNALS = [];
|
|
176
180
|
function instantiateFrozenBoth(frozen, checkSchema, mirrorSchema) {
|
|
177
181
|
return frozen.cm(frozen.e ? collectExternals(checkSchema) : EMPTY_EXTERNALS, frozen.u ? { unions: buildUnions(frozen.u, mirrorSchema) } : void 0);
|
|
@@ -202,8 +206,8 @@ function captureMirrorUnions(schema, truthUnions) {
|
|
|
202
206
|
}
|
|
203
207
|
return u;
|
|
204
208
|
}
|
|
205
|
-
function captureMirrorCodecs(schema, truthCodecs) {
|
|
206
|
-
const codecs = collectMirrorCodecs(schema);
|
|
209
|
+
function captureMirrorCodecs(schema, truthCodecs, dir = "decode") {
|
|
210
|
+
const codecs = collectMirrorCodecs(schema, [], dir);
|
|
207
211
|
if (codecs.length !== truthCodecs.length) return false;
|
|
208
212
|
for (let i = 0; i < codecs.length; i++) if (codecs[i] !== truthCodecs[i]) return false;
|
|
209
213
|
return true;
|
|
@@ -261,12 +265,17 @@ function captureDecodeMirror(v) {
|
|
|
261
265
|
const e = captureEntry(v);
|
|
262
266
|
if (e) e.decodeMirror = v.mirror;
|
|
263
267
|
}
|
|
268
|
+
function captureEncodeMirror(v) {
|
|
269
|
+
const e = captureEntry(v);
|
|
270
|
+
if (e) e.encodeMirror = v.mirror;
|
|
271
|
+
}
|
|
264
272
|
const isValidatorCapturing = () => capture !== void 0 || require_universal_env.env.ELYSIA_AOT_BUILD === "1";
|
|
265
273
|
const Capture = {
|
|
266
274
|
validator: captureValidator,
|
|
267
275
|
handler: captureHandler,
|
|
268
276
|
mirror: captureMirror,
|
|
269
277
|
mirrorDecode: captureDecodeMirror,
|
|
278
|
+
mirrorEncode: captureEncodeMirror,
|
|
270
279
|
mirrorUnions: captureMirrorUnions,
|
|
271
280
|
mirrorCodecs: captureMirrorCodecs,
|
|
272
281
|
isCapturing: isValidatorCapturing
|
|
@@ -283,5 +292,6 @@ exports.endValidatorCapture = endValidatorCapture;
|
|
|
283
292
|
exports.externalsMatch = externalsMatch;
|
|
284
293
|
exports.instantiateFrozenBoth = instantiateFrozenBoth;
|
|
285
294
|
exports.instantiateFrozenDecodeMirror = instantiateFrozenDecodeMirror;
|
|
295
|
+
exports.instantiateFrozenEncodeMirror = instantiateFrozenEncodeMirror;
|
|
286
296
|
exports.instantiateFrozenMirror = instantiateFrozenMirror;
|
|
287
297
|
exports.reconstructCheck = reconstructCheck;
|
package/dist/compile/aot.mjs
CHANGED
|
@@ -147,15 +147,14 @@ function collectMirrorUnions(schema, out = []) {
|
|
|
147
147
|
}
|
|
148
148
|
return out;
|
|
149
149
|
}
|
|
150
|
-
|
|
151
|
-
function collectMirrorCodecs(schema, out = []) {
|
|
150
|
+
function collectMirrorCodecs(schema, out = [], dir = "decode") {
|
|
152
151
|
if (!schema || typeof schema !== "object") return out;
|
|
153
|
-
const codec = schema[
|
|
154
|
-
if (codec && typeof codec
|
|
155
|
-
if (schema.type === "object" && schema.properties) for (const key in schema.properties) collectMirrorCodecs(schema.properties[key], out);
|
|
156
|
-
else if (schema.type === "array" && schema.items) if (Array.isArray(schema.items)) for (const it of schema.items) collectMirrorCodecs(it, out);
|
|
157
|
-
else collectMirrorCodecs(schema.items, out);
|
|
158
|
-
else if (Array.isArray(schema.anyOf)) for (const b of schema.anyOf) collectMirrorCodecs(b, out);
|
|
152
|
+
const codec = schema["~codec"];
|
|
153
|
+
if (codec && typeof codec[dir] === "function" && out.indexOf(codec[dir]) === -1) out.push(codec[dir]);
|
|
154
|
+
if (schema.type === "object" && schema.properties) for (const key in schema.properties) collectMirrorCodecs(schema.properties[key], out, dir);
|
|
155
|
+
else if (schema.type === "array" && schema.items) if (Array.isArray(schema.items)) for (const it of schema.items) collectMirrorCodecs(it, out, dir);
|
|
156
|
+
else collectMirrorCodecs(schema.items, out, dir);
|
|
157
|
+
else if (Array.isArray(schema.anyOf)) for (const b of schema.anyOf) collectMirrorCodecs(b, out, dir);
|
|
159
158
|
return out;
|
|
160
159
|
}
|
|
161
160
|
function buildUnions(u, schema) {
|
|
@@ -171,6 +170,11 @@ function instantiateFrozenDecodeMirror(frozen, schema) {
|
|
|
171
170
|
if (frozen.u) d.unions = buildUnions(frozen.u, schema);
|
|
172
171
|
return frozen.s(d);
|
|
173
172
|
}
|
|
173
|
+
function instantiateFrozenEncodeMirror(frozen, schema) {
|
|
174
|
+
const d = { codecs: collectMirrorCodecs(schema, [], "encode") };
|
|
175
|
+
if (frozen.u) d.unions = buildUnions(frozen.u, schema);
|
|
176
|
+
return frozen.s(d);
|
|
177
|
+
}
|
|
174
178
|
const EMPTY_EXTERNALS = [];
|
|
175
179
|
function instantiateFrozenBoth(frozen, checkSchema, mirrorSchema) {
|
|
176
180
|
return frozen.cm(frozen.e ? collectExternals(checkSchema) : EMPTY_EXTERNALS, frozen.u ? { unions: buildUnions(frozen.u, mirrorSchema) } : void 0);
|
|
@@ -201,8 +205,8 @@ function captureMirrorUnions(schema, truthUnions) {
|
|
|
201
205
|
}
|
|
202
206
|
return u;
|
|
203
207
|
}
|
|
204
|
-
function captureMirrorCodecs(schema, truthCodecs) {
|
|
205
|
-
const codecs = collectMirrorCodecs(schema);
|
|
208
|
+
function captureMirrorCodecs(schema, truthCodecs, dir = "decode") {
|
|
209
|
+
const codecs = collectMirrorCodecs(schema, [], dir);
|
|
206
210
|
if (codecs.length !== truthCodecs.length) return false;
|
|
207
211
|
for (let i = 0; i < codecs.length; i++) if (codecs[i] !== truthCodecs[i]) return false;
|
|
208
212
|
return true;
|
|
@@ -260,16 +264,21 @@ function captureDecodeMirror(v) {
|
|
|
260
264
|
const e = captureEntry(v);
|
|
261
265
|
if (e) e.decodeMirror = v.mirror;
|
|
262
266
|
}
|
|
267
|
+
function captureEncodeMirror(v) {
|
|
268
|
+
const e = captureEntry(v);
|
|
269
|
+
if (e) e.encodeMirror = v.mirror;
|
|
270
|
+
}
|
|
263
271
|
const isValidatorCapturing = () => capture !== void 0 || env.ELYSIA_AOT_BUILD === "1";
|
|
264
272
|
const Capture = {
|
|
265
273
|
validator: captureValidator,
|
|
266
274
|
handler: captureHandler,
|
|
267
275
|
mirror: captureMirror,
|
|
268
276
|
mirrorDecode: captureDecodeMirror,
|
|
277
|
+
mirrorEncode: captureEncodeMirror,
|
|
269
278
|
mirrorUnions: captureMirrorUnions,
|
|
270
279
|
mirrorCodecs: captureMirrorCodecs,
|
|
271
280
|
isCapturing: isValidatorCapturing
|
|
272
281
|
};
|
|
273
282
|
|
|
274
283
|
//#endregion
|
|
275
|
-
export { Capture, Compiled, Source, beginValidatorCapture, collectExternals, endHandlerCapture, endValidatorCapture, externalsMatch, instantiateFrozenBoth, instantiateFrozenDecodeMirror, instantiateFrozenMirror, reconstructCheck };
|
|
284
|
+
export { Capture, Compiled, Source, beginValidatorCapture, collectExternals, endHandlerCapture, endValidatorCapture, externalsMatch, instantiateFrozenBoth, instantiateFrozenDecodeMirror, instantiateFrozenEncodeMirror, instantiateFrozenMirror, reconstructCheck };
|
|
@@ -97,15 +97,13 @@ function parse(adapter, parsers, bodyVali, hasHeaders, link, report) {
|
|
|
97
97
|
}
|
|
98
98
|
const isAsyncValidator = (vali) => vali?.isAsync ?? true;
|
|
99
99
|
function applyHook(localHook, appHook, rootHook) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
let hook;
|
|
101
|
+
if (localHook && appHook) hook = require_utils.mergeHook(require_utils.cloneHook(localHook), appHook, true);
|
|
102
|
+
else {
|
|
103
|
+
const base = localHook ?? appHook;
|
|
104
|
+
if (!rootHook) return base;
|
|
105
|
+
hook = require_utils.cloneHook(base ?? require_utils.nullObject());
|
|
103
106
|
}
|
|
104
|
-
if (!appHook) {
|
|
105
|
-
if (rootHook) return require_utils.mergeHook(require_utils.cloneHook(localHook), rootHook, true, true);
|
|
106
|
-
return localHook;
|
|
107
|
-
}
|
|
108
|
-
const hook = require_utils.mergeHook(require_utils.cloneHook(localHook), appHook, true);
|
|
109
107
|
if (rootHook) require_utils.mergeHook(hook, rootHook, true, true);
|
|
110
108
|
return hook;
|
|
111
109
|
}
|
|
@@ -216,6 +214,9 @@ function buildNativeStaticResponse([, , handler, instance, localHook, appHook, i
|
|
|
216
214
|
if (mapped instanceof Response) return mapped;
|
|
217
215
|
if (mapped instanceof Promise) return mapped;
|
|
218
216
|
}
|
|
217
|
+
function toArray(name, hook) {
|
|
218
|
+
if (typeof hook[name] === "function") hook[name] = [hook[name]];
|
|
219
|
+
}
|
|
219
220
|
function compileHandler([_method, path, handler, instance, localHook, appHook, inheritedChain], root, precomputedStatic) {
|
|
220
221
|
const adapter = root["~config"]?.adapter ?? require_adapter_constants.defaultAdapter;
|
|
221
222
|
if (root["~ext"]?.macro) {
|
|
@@ -246,11 +247,13 @@ function compileHandler([_method, path, handler, instance, localHook, appHook, i
|
|
|
246
247
|
}
|
|
247
248
|
if (hook) {
|
|
248
249
|
promoteDerive(hook);
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
250
|
+
toArray("parse", hook);
|
|
251
|
+
toArray("transform", hook);
|
|
252
|
+
toArray("beforeHandle", hook);
|
|
253
|
+
toArray("afterHandle", hook);
|
|
254
|
+
toArray("mapResponse", hook);
|
|
255
|
+
toArray("afterResponse", hook);
|
|
256
|
+
toArray("error", hook);
|
|
254
257
|
}
|
|
255
258
|
const method = require_utils.mapMethodBack(_method);
|
|
256
259
|
const vali = hook ? new require_validator_route.RouteValidator(hook, {
|
|
@@ -359,8 +362,9 @@ function compileHandler([_method, path, handler, instance, localHook, appHook, i
|
|
|
359
362
|
const responseValiAsync = !!(vali?.response && Object.values(vali.response).find(isAsyncValidator));
|
|
360
363
|
const handlerIsAsync = isHandleFunction && require_compile_utils.isAsyncFunction(handler);
|
|
361
364
|
const errorHookForcesAsync = hasErrorHook && (hasAfterHandle || hasMapResponse || hasResponseValidator);
|
|
365
|
+
const responseValiForcesAsync = hasResponseValidator && isHandleFunction && !handlerIsAsync && require_compile_utils.mayReturnPromise(handler);
|
|
362
366
|
const afterResponseForcesAsync = hasAfterResponse && (require_compile_utils.isAsyncLifecycle(hook?.afterResponse) || hasAfterHandle || hasMapResponse || hasResponseValidator || hasErrorHook);
|
|
363
|
-
const isAsync = hasBody || handlerIsAsync || errorHookForcesAsync || afterResponseForcesAsync || hasTrace || hasCookieSign || responseValiAsync || hook && (!!require_compile_utils.isAsyncLifecycle(hook?.afterHandle) || !!require_compile_utils.isAsyncLifecycle(hook?.beforeHandle) || !!require_compile_utils.isAsyncLifecycle(hook?.transform) || !!require_compile_utils.isAsyncLifecycle(hook?.mapResponse) || !!require_compile_utils.isAsyncLifecycle(hook?.error) || bodyValiIsAsync || headersValiIsAsync || paramsValiIsAsync || queryValiIsAsync || cookieValidIsAsync);
|
|
367
|
+
const isAsync = hasBody || handlerIsAsync || errorHookForcesAsync || responseValiForcesAsync || afterResponseForcesAsync || hasTrace || hasCookieSign || responseValiAsync || hook && (!!require_compile_utils.isAsyncLifecycle(hook?.afterHandle) || !!require_compile_utils.isAsyncLifecycle(hook?.beforeHandle) || !!require_compile_utils.isAsyncLifecycle(hook?.transform) || !!require_compile_utils.isAsyncLifecycle(hook?.mapResponse) || !!require_compile_utils.isAsyncLifecycle(hook?.error) || bodyValiIsAsync || headersValiIsAsync || paramsValiIsAsync || queryValiIsAsync || cookieValidIsAsync);
|
|
364
368
|
const callHandlerSyncOnAsync = isAsync && isHandleFunction && !handlerIsAsync;
|
|
365
369
|
const syncErrorHook = hasErrorHook && !isAsync && !hasTrace;
|
|
366
370
|
const syncAfterResponse = hasAfterResponse && !isAsync && !hasTrace && !hasErrorHook;
|
|
@@ -543,11 +547,13 @@ return tee(_r,${teeCount}).then((_s)=>_fin2(c,_s[0],_s[1]))\n}\nreturn _fin2(c,_
|
|
|
543
547
|
const awaitStr = responseValiAsync ? "await " : "";
|
|
544
548
|
code += `if(_r instanceof es){
|
|
545
549
|
const _vr=va.response[_r.code]
|
|
546
|
-
if(_vr)_r.response=${awaitStr}_vr.EncodeFrom(_r.response,'response')\n}else if(!(_r instanceof Response)&&typeof _r?.next!=='function'){\nconst _vr=va.response[c.set.status??200]\nif(_vr)_r=${awaitStr}_vr.EncodeFrom(_r,'response')\n}\n`;
|
|
550
|
+
if(_vr)_r.response=${awaitStr}_vr.EncodeFrom(_r.response,'response')\n}else if(!(_r instanceof Response)&&!(_r instanceof ReadableStream)&&typeof _r?.next!=='function'){\nconst _vr=va.response[c.set.status??200]\nif(_vr)_r=${awaitStr}_vr.EncodeFrom(_r,'response')\n}\n`;
|
|
547
551
|
}
|
|
548
552
|
code += schedule;
|
|
549
553
|
code += signPrefix;
|
|
550
|
-
|
|
554
|
+
const finalMap = hasSet ? `${map}(_r,c.set,c.request)` : `${map}(_r,c.request)`;
|
|
555
|
+
if (syncErrorHook) code += `if(_r instanceof Promise)return ${finalMap}.catch((_e)=>_ce(_e,c))\n`;
|
|
556
|
+
code += `return ${finalMap}\n`;
|
|
551
557
|
}
|
|
552
558
|
} else if (isHandleFunction) {
|
|
553
559
|
if (!isAsync) link(require_handler_utils.forwardError, "fe");
|