elysia 1.2.5 → 1.2.7
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.mjs +4 -0
- package/dist/adapter/types.d.ts +6 -0
- package/dist/adapter/web-standard/handler.d.ts +1 -1
- package/dist/adapter/web-standard/handler.mjs +22 -6
- package/dist/bun/index.d.ts +23 -17
- package/dist/bun/index.js +35 -30
- package/dist/bun/index.js.map +8 -8
- package/dist/cjs/adapter/bun/index.js +4 -0
- package/dist/cjs/adapter/web-standard/handler.js +22 -6
- package/dist/cjs/compose.d.ts +1 -1
- package/dist/cjs/compose.js +49 -31
- package/dist/cjs/dynamic-handle.js +7 -5
- package/dist/cjs/index.d.ts +23 -17
- package/dist/cjs/index.js +32 -5
- package/dist/cjs/types.d.ts +8 -5
- package/dist/cjs/utils.d.ts +7 -4
- package/dist/cjs/utils.js +26 -3
- package/dist/compose.d.ts +1 -1
- package/dist/compose.mjs +49 -31
- package/dist/dynamic-handle.mjs +7 -5
- package/dist/index.d.ts +23 -17
- package/dist/index.mjs +36 -8
- package/dist/types.d.ts +8 -5
- package/dist/utils.d.ts +7 -4
- package/dist/utils.mjs +26 -3
- package/package.json +1 -1
|
@@ -89,11 +89,15 @@ const BunAdapter = {
|
|
|
89
89
|
ws(app, path, options) {
|
|
90
90
|
const { parse, body, response, ...rest } = options;
|
|
91
91
|
const validateMessage = getSchemaValidator(body, {
|
|
92
|
+
// @ts-expect-error private property
|
|
93
|
+
modules: app.definitions.typebox,
|
|
92
94
|
// @ts-expect-error private property
|
|
93
95
|
models: app.definitions.type,
|
|
94
96
|
normalize: app.config.normalize
|
|
95
97
|
});
|
|
96
98
|
const validateResponse = getSchemaValidator(response, {
|
|
99
|
+
// @ts-expect-error private property
|
|
100
|
+
modules: app.definitions.typebox,
|
|
97
101
|
// @ts-expect-error private property
|
|
98
102
|
models: app.definitions.type,
|
|
99
103
|
normalize: app.config.normalize
|
package/dist/adapter/types.d.ts
CHANGED
|
@@ -95,6 +95,12 @@ export interface ElysiaAdapter {
|
|
|
95
95
|
inject?: Record<string, unknown>;
|
|
96
96
|
mapResponseContext: string;
|
|
97
97
|
validationError: string;
|
|
98
|
+
/**
|
|
99
|
+
* Handle thrown error which is instance of Error
|
|
100
|
+
*
|
|
101
|
+
* Despite its name of `unknownError`, it also handle named error like `NOT_FOUND`, `VALIDATION_ERROR`
|
|
102
|
+
* It's named `unknownError` because it also catch unknown error
|
|
103
|
+
*/
|
|
98
104
|
unknownError: string;
|
|
99
105
|
};
|
|
100
106
|
ws?(app: AnyElysia, path: string, handler: AnyWSLocalHook): unknown;
|
|
@@ -3,7 +3,7 @@ import type { AnyLocalHook } from '../../types';
|
|
|
3
3
|
export declare const parseSetCookies: (headers: Headers, setCookie: string[]) => Headers;
|
|
4
4
|
export declare function streamResponse(response: Response): AsyncGenerator<string, void, unknown>;
|
|
5
5
|
export declare const handleSet: (set: Context["set"]) => void;
|
|
6
|
-
export declare const mergeResponseWithSetHeaders: (response: Response, set: Context["set"]) =>
|
|
6
|
+
export declare const mergeResponseWithSetHeaders: (response: Response, set: Context["set"]) => Response;
|
|
7
7
|
export declare const mapResponse: (response: unknown, set: Context["set"], request?: Request) => Response;
|
|
8
8
|
export declare const mapEarlyResponse: (response: unknown, set: Context["set"], request?: Request) => Response | undefined;
|
|
9
9
|
export declare const mapCompactResponse: (response: unknown, request?: Request) => Response;
|
|
@@ -165,6 +165,11 @@ const handleSet = (set2) => {
|
|
|
165
165
|
}
|
|
166
166
|
};
|
|
167
167
|
const mergeResponseWithSetHeaders = (response, set2) => {
|
|
168
|
+
if (response.status !== set2.status && set2.status !== 200 && (response.status <= 300 || response.status > 400))
|
|
169
|
+
response = new Response(response.body, {
|
|
170
|
+
headers: response.headers,
|
|
171
|
+
status: set2.status
|
|
172
|
+
});
|
|
168
173
|
let isCookieSet = false;
|
|
169
174
|
if (set2.headers instanceof Headers)
|
|
170
175
|
for (const key of set2.headers.keys()) {
|
|
@@ -178,8 +183,7 @@ const mergeResponseWithSetHeaders = (response, set2) => {
|
|
|
178
183
|
else
|
|
179
184
|
for (const key in set2.headers)
|
|
180
185
|
response.headers.append(key, set2.headers[key]);
|
|
181
|
-
|
|
182
|
-
set2.status = response.status;
|
|
186
|
+
return response;
|
|
183
187
|
};
|
|
184
188
|
const mapResponse = (response, set2, request) => {
|
|
185
189
|
if (isNotEmpty(set2.headers) || set2.status !== 200 || set2.cookie) {
|
|
@@ -223,7 +227,10 @@ const mapResponse = (response, set2, request) => {
|
|
|
223
227
|
if (!response) return new Response("", set2);
|
|
224
228
|
return Response.json(response, set2);
|
|
225
229
|
case "Response":
|
|
226
|
-
mergeResponseWithSetHeaders(
|
|
230
|
+
response = mergeResponseWithSetHeaders(
|
|
231
|
+
response,
|
|
232
|
+
set2
|
|
233
|
+
);
|
|
227
234
|
if (response.headers.get("transfer-encoding") === "chunked")
|
|
228
235
|
return handleStream(
|
|
229
236
|
streamResponse(response),
|
|
@@ -253,7 +260,10 @@ const mapResponse = (response, set2, request) => {
|
|
|
253
260
|
return new Response(response, set2);
|
|
254
261
|
default:
|
|
255
262
|
if (response instanceof Response) {
|
|
256
|
-
mergeResponseWithSetHeaders(
|
|
263
|
+
response = mergeResponseWithSetHeaders(
|
|
264
|
+
response,
|
|
265
|
+
set2
|
|
266
|
+
);
|
|
257
267
|
if (response.headers.get(
|
|
258
268
|
"transfer-encoding"
|
|
259
269
|
) === "chunked")
|
|
@@ -346,7 +356,10 @@ const mapEarlyResponse = (response, set2, request) => {
|
|
|
346
356
|
if (!response) return;
|
|
347
357
|
return Response.json(response, set2);
|
|
348
358
|
case "Response":
|
|
349
|
-
mergeResponseWithSetHeaders(
|
|
359
|
+
response = mergeResponseWithSetHeaders(
|
|
360
|
+
response,
|
|
361
|
+
set2
|
|
362
|
+
);
|
|
350
363
|
if (response.headers.get("transfer-encoding") === "chunked")
|
|
351
364
|
return handleStream(
|
|
352
365
|
streamResponse(response),
|
|
@@ -376,7 +389,10 @@ const mapEarlyResponse = (response, set2, request) => {
|
|
|
376
389
|
return new Response(response?.toString(), set2);
|
|
377
390
|
default:
|
|
378
391
|
if (response instanceof Response) {
|
|
379
|
-
mergeResponseWithSetHeaders(
|
|
392
|
+
response = mergeResponseWithSetHeaders(
|
|
393
|
+
response,
|
|
394
|
+
set2
|
|
395
|
+
);
|
|
380
396
|
if (response.headers.get(
|
|
381
397
|
"transfer-encoding"
|
|
382
398
|
) === "chunked")
|
package/dist/bun/index.d.ts
CHANGED
|
@@ -900,16 +900,16 @@ export default class Elysia<const in out BasePath extends string = '', const in
|
|
|
900
900
|
macroFn: Metadata['macroFn'];
|
|
901
901
|
parser: Metadata['parser'];
|
|
902
902
|
}, {}, Ephemeral, Volatile>) => NewElysia): Elysia<BasePath, Singleton, Definitions, Metadata, Routes & NewElysia['_routes'], Ephemeral, Volatile>;
|
|
903
|
-
guard<const LocalSchema extends InputSchema<keyof UnwrapTypeModule<Definitions['typebox']> & string>, const Schema extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['typebox'], BasePath>, Metadata['schema']>, const Type extends LifeCycleType
|
|
903
|
+
guard<const LocalSchema extends InputSchema<keyof UnwrapTypeModule<Definitions['typebox']> & string>, const Schema extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['typebox'], BasePath>, Metadata['schema']>, const Type extends LifeCycleType, const Macro extends Metadata['macro'], const MacroContext extends MacroToContext<Metadata['macroFn'], Macro>>(hook: {
|
|
904
904
|
as: Type;
|
|
905
905
|
} & LocalHook<LocalSchema, Schema, Singleton & {
|
|
906
906
|
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
907
907
|
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
908
|
-
}, Definitions['error'],
|
|
908
|
+
}, Definitions['error'], Macro, keyof Metadata['parser'] & string>): Type extends 'global' ? Elysia<BasePath, {
|
|
909
909
|
decorator: Singleton['decorator'];
|
|
910
910
|
store: Singleton['store'];
|
|
911
911
|
derive: Singleton['derive'];
|
|
912
|
-
resolve: Singleton['resolve']
|
|
912
|
+
resolve: Prettify<Singleton['resolve'] & MacroContext>;
|
|
913
913
|
}, Definitions, {
|
|
914
914
|
schema: Prettify<MergeSchema<UnwrapRoute<LocalSchema, Definitions['typebox'], BasePath>, Metadata['schema']>>;
|
|
915
915
|
macro: Metadata['macro'];
|
|
@@ -917,44 +917,50 @@ export default class Elysia<const in out BasePath extends string = '', const in
|
|
|
917
917
|
parser: Metadata['parser'];
|
|
918
918
|
}, Routes, Ephemeral, Volatile> : Type extends 'scoped' ? Elysia<BasePath, Singleton, Definitions, Metadata, Routes, {
|
|
919
919
|
derive: Volatile['derive'];
|
|
920
|
-
resolve: Volatile['resolve']
|
|
920
|
+
resolve: Prettify<Volatile['resolve'] & MacroContext>;
|
|
921
921
|
schema: Prettify<MergeSchema<UnwrapRoute<LocalSchema, Definitions['typebox']>, Metadata['schema'] & Ephemeral['schema']>>;
|
|
922
922
|
}, Ephemeral> : Elysia<BasePath, Singleton, Definitions, Metadata, Routes, Ephemeral, {
|
|
923
923
|
derive: Volatile['derive'];
|
|
924
|
-
resolve: Volatile['resolve']
|
|
924
|
+
resolve: Prettify<Volatile['resolve'] & MacroContext>;
|
|
925
925
|
schema: Prettify<MergeSchema<UnwrapRoute<LocalSchema, Definitions['typebox']>, Metadata['schema'] & Ephemeral['schema'] & Volatile['schema']>>;
|
|
926
926
|
}>;
|
|
927
|
-
guard<const LocalSchema extends InputSchema<keyof UnwrapTypeModule<Definitions['typebox']> & string>, const Schema extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['typebox'], BasePath>, Metadata['schema']>>(hook: LocalHook<LocalSchema, Schema, Singleton & {
|
|
927
|
+
guard<const LocalSchema extends InputSchema<keyof UnwrapTypeModule<Definitions['typebox']> & string>, const Schema extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['typebox'], BasePath>, Metadata['schema']>, const Macro extends Metadata['macro'], const MacroContext extends MacroToContext<Metadata['macroFn'], Macro>>(hook: LocalHook<LocalSchema, Schema, Singleton & {
|
|
928
928
|
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
929
|
-
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
930
|
-
}, Definitions['error'],
|
|
929
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'] & MacroContext;
|
|
930
|
+
}, Definitions['error'], Macro, keyof Metadata['parser'] & string>): Elysia<BasePath, Singleton, Definitions, Metadata, Routes, Ephemeral, {
|
|
931
931
|
derive: Volatile['derive'];
|
|
932
|
-
resolve: Volatile['resolve']
|
|
932
|
+
resolve: Prettify<Volatile['resolve'] & MacroContext>;
|
|
933
933
|
schema: Prettify<MergeSchema<UnwrapRoute<LocalSchema, Definitions['typebox'], BasePath>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>>>;
|
|
934
934
|
}>;
|
|
935
|
-
guard<const LocalSchema extends InputSchema<keyof UnwrapTypeModule<Definitions['typebox']> & string>, const NewElysia extends AnyElysia, const Schema extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['typebox'], BasePath>, Metadata['schema']>>(run: (group: Elysia<BasePath,
|
|
935
|
+
guard<const LocalSchema extends InputSchema<keyof UnwrapTypeModule<Definitions['typebox']> & string>, const NewElysia extends AnyElysia, const Schema extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['typebox'], BasePath>, Metadata['schema']>, const Macro extends Metadata['macro'], const MacroContext extends MacroToContext<Metadata['macroFn'], Macro>>(run: (group: Elysia<BasePath, {
|
|
936
|
+
decorator: Singleton['decorator'];
|
|
937
|
+
store: Singleton['store'];
|
|
938
|
+
derive: Singleton['derive'];
|
|
939
|
+
resolve: Singleton['resolve'] & MacroContext;
|
|
940
|
+
}, Definitions, {
|
|
936
941
|
schema: Prettify<Schema>;
|
|
937
942
|
macro: Metadata['macro'];
|
|
938
943
|
macroFn: Metadata['macroFn'];
|
|
939
944
|
parser: Metadata['parser'];
|
|
940
945
|
}, {}, Ephemeral, Volatile>) => NewElysia): Elysia<BasePath, Singleton, Definitions, Metadata, Prettify<Routes & NewElysia['_routes']>, Ephemeral, Volatile>;
|
|
941
|
-
guard<const LocalSchema extends InputSchema<keyof UnwrapTypeModule<Definitions['typebox']> & string>, const NewElysia extends AnyElysia, const Schema extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['typebox'], BasePath>, Metadata['schema']>, const
|
|
942
|
-
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
943
|
-
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
944
|
-
}>>>(schema: LocalHook<LocalSchema, Schema, Singleton & {
|
|
946
|
+
guard<const LocalSchema extends InputSchema<keyof UnwrapTypeModule<Definitions['typebox']> & string>, const NewElysia extends AnyElysia, const Schema extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['typebox'], BasePath>, Metadata['schema']>, const Macro extends Metadata['macro'], const MacroContext extends MacroToContext<Metadata['macroFn'], Macro>>(schema: LocalHook<LocalSchema, Schema, Singleton & {
|
|
945
947
|
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
946
948
|
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
947
|
-
}, Definitions['error'],
|
|
949
|
+
}, Definitions['error'], Macro, keyof Metadata['parser'] & string>, run: (group: Elysia<BasePath, {
|
|
948
950
|
decorator: Singleton['decorator'];
|
|
949
951
|
store: Singleton['store'];
|
|
950
952
|
derive: Singleton['derive'];
|
|
951
|
-
resolve: Singleton['resolve'] &
|
|
953
|
+
resolve: Prettify<Singleton['resolve'] & MacroContext>;
|
|
952
954
|
}, Definitions, {
|
|
953
955
|
schema: Prettify<Schema>;
|
|
954
956
|
macro: Metadata['macro'];
|
|
955
957
|
macroFn: Metadata['macroFn'];
|
|
956
958
|
parser: Metadata['parser'];
|
|
957
|
-
}, {}, Ephemeral, Volatile>) => NewElysia): Elysia<BasePath, Singleton, Definitions, Metadata, Prettify<Routes & NewElysia['_routes']>, Ephemeral,
|
|
959
|
+
}, {}, Ephemeral, Volatile>) => NewElysia): Elysia<BasePath, Singleton, Definitions, Metadata, Prettify<Routes & NewElysia['_routes']>, Ephemeral, {
|
|
960
|
+
derive: Volatile['derive'];
|
|
961
|
+
resolve: Prettify<Volatile['resolve'] & MacroContext>;
|
|
962
|
+
schema: Volatile['schema'];
|
|
963
|
+
}>;
|
|
958
964
|
/**
|
|
959
965
|
* Inline fn
|
|
960
966
|
*/
|