elysia 1.4.14 → 1.4.16
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/handler.d.ts +1 -1
- package/dist/adapter/bun/handler.js +16 -10
- package/dist/adapter/bun/handler.mjs +16 -10
- package/dist/adapter/bun/index.js +1 -1
- package/dist/adapter/bun/index.mjs +2 -2
- package/dist/adapter/web-standard/handler.d.ts +1 -1
- package/dist/adapter/web-standard/handler.js +16 -10
- package/dist/adapter/web-standard/handler.mjs +16 -10
- package/dist/adapter/web-standard/index.js +1 -4
- package/dist/adapter/web-standard/index.mjs +1 -4
- package/dist/bun/index.js +26 -28
- package/dist/bun/index.js.map +12 -12
- package/dist/compose.js +18 -15
- package/dist/compose.mjs +19 -16
- package/dist/context.d.ts +2 -2
- package/dist/dynamic-handle.js +15 -1
- package/dist/dynamic-handle.mjs +15 -1
- package/dist/error.d.ts +26 -2
- package/dist/error.js +12 -4
- package/dist/error.mjs +12 -4
- package/dist/index.d.ts +10 -28
- package/dist/index.js +23 -15
- package/dist/index.mjs +23 -15
- package/dist/type-system/types.d.ts +1 -1
- package/dist/type-system/utils.d.ts +1 -1
- package/dist/types.d.ts +42 -11
- package/dist/ws/index.js +6 -0
- package/dist/ws/index.mjs +6 -0
- package/package.json +3 -3
|
@@ -3,5 +3,5 @@ import type { AnyLocalHook } from '../../types';
|
|
|
3
3
|
export declare const mapResponse: (response: unknown, set: Context["set"], request?: Request) => Response;
|
|
4
4
|
export declare const mapEarlyResponse: (response: unknown, set: Context["set"], request?: Request) => Response | undefined;
|
|
5
5
|
export declare const mapCompactResponse: (response: unknown, request?: Request) => Response;
|
|
6
|
-
export declare const errorToResponse: (error: Error, set?: Context["set"]) =>
|
|
6
|
+
export declare const errorToResponse: (error: Error, set?: Context["set"]) => any;
|
|
7
7
|
export declare const createStaticHandler: (handle: unknown, hooks: Partial<AnyLocalHook>, setHeaders?: Context["set"]["headers"]) => (() => Response) | undefined;
|
|
@@ -336,17 +336,23 @@ const mapResponse = (response, set2, request) => {
|
|
|
336
336
|
}
|
|
337
337
|
return new Response(response);
|
|
338
338
|
}
|
|
339
|
-
}, errorToResponse = (error, set2) =>
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
cause: error?.cause
|
|
344
|
-
}),
|
|
345
|
-
{
|
|
346
|
-
status: set2?.status !== 200 ? set2?.status ?? 500 : 500,
|
|
347
|
-
headers: set2?.headers
|
|
339
|
+
}, errorToResponse = (error, set2) => {
|
|
340
|
+
if (typeof error?.toResponse == "function") {
|
|
341
|
+
const raw = error.toResponse(), targetSet = set2 ?? { headers: {}, status: 200, redirect: "" }, apply = (resolved) => (resolved instanceof Response && (targetSet.status = resolved.status), mapResponse(resolved, targetSet));
|
|
342
|
+
return typeof raw?.then == "function" ? raw.then(apply) : apply(raw);
|
|
348
343
|
}
|
|
349
|
-
|
|
344
|
+
return new Response(
|
|
345
|
+
JSON.stringify({
|
|
346
|
+
name: error?.name,
|
|
347
|
+
message: error?.message,
|
|
348
|
+
cause: error?.cause
|
|
349
|
+
}),
|
|
350
|
+
{
|
|
351
|
+
status: set2?.status !== 200 ? set2?.status ?? 500 : 500,
|
|
352
|
+
headers: set2?.headers
|
|
353
|
+
}
|
|
354
|
+
);
|
|
355
|
+
}, createStaticHandler = (handle, hooks, setHeaders = {}) => {
|
|
350
356
|
if (typeof handle == "function") return;
|
|
351
357
|
const response = mapResponse(handle, {
|
|
352
358
|
headers: setHeaders
|
|
@@ -320,17 +320,23 @@ const mapResponse = (response, set2, request) => {
|
|
|
320
320
|
}
|
|
321
321
|
return new Response(response);
|
|
322
322
|
}
|
|
323
|
-
}, errorToResponse = (error, set2) =>
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
cause: error?.cause
|
|
328
|
-
}),
|
|
329
|
-
{
|
|
330
|
-
status: set2?.status !== 200 ? set2?.status ?? 500 : 500,
|
|
331
|
-
headers: set2?.headers
|
|
323
|
+
}, errorToResponse = (error, set2) => {
|
|
324
|
+
if (typeof error?.toResponse == "function") {
|
|
325
|
+
const raw = error.toResponse(), targetSet = set2 ?? { headers: {}, status: 200, redirect: "" }, apply = (resolved) => (resolved instanceof Response && (targetSet.status = resolved.status), mapResponse(resolved, targetSet));
|
|
326
|
+
return typeof raw?.then == "function" ? raw.then(apply) : apply(raw);
|
|
332
327
|
}
|
|
333
|
-
|
|
328
|
+
return new Response(
|
|
329
|
+
JSON.stringify({
|
|
330
|
+
name: error?.name,
|
|
331
|
+
message: error?.message,
|
|
332
|
+
cause: error?.cause
|
|
333
|
+
}),
|
|
334
|
+
{
|
|
335
|
+
status: set2?.status !== 200 ? set2?.status ?? 500 : 500,
|
|
336
|
+
headers: set2?.headers
|
|
337
|
+
}
|
|
338
|
+
);
|
|
339
|
+
}, createStaticHandler = (handle, hooks, setHeaders = {}) => {
|
|
334
340
|
if (typeof handle == "function") return;
|
|
335
341
|
const response = mapResponse(handle, {
|
|
336
342
|
headers: setHeaders
|
|
@@ -3,7 +3,7 @@ import { parseSetCookies } from "../utils.mjs";
|
|
|
3
3
|
import { createBunRouteHandler } from "./compose.mjs";
|
|
4
4
|
import { createNativeStaticHandler } from "./handler-native.mjs";
|
|
5
5
|
import { serializeCookie } from "../../cookies.mjs";
|
|
6
|
-
import { isProduction, ValidationError } from "../../error.mjs";
|
|
6
|
+
import { isProduction, status, ValidationError } from "../../error.mjs";
|
|
7
7
|
import { getSchemaValidator } from "../../schema.mjs";
|
|
8
8
|
import {
|
|
9
9
|
hasHeaderShorthand,
|
|
@@ -364,7 +364,7 @@ for(const [k,v] of c.request.headers.entries())c.headers[k]=v
|
|
|
364
364
|
}
|
|
365
365
|
}
|
|
366
366
|
}))
|
|
367
|
-
return
|
|
367
|
+
return status(400, "Expected a websocket connection");
|
|
368
368
|
},
|
|
369
369
|
{
|
|
370
370
|
...rest,
|
|
@@ -3,5 +3,5 @@ import type { AnyLocalHook } from '../../types';
|
|
|
3
3
|
export declare const mapResponse: (response: unknown, set: Context["set"], request?: Request) => Response;
|
|
4
4
|
export declare const mapEarlyResponse: (response: unknown, set: Context["set"], request?: Request) => Response | undefined;
|
|
5
5
|
export declare const mapCompactResponse: (response: unknown, request?: Request) => Response;
|
|
6
|
-
export declare const errorToResponse: (error: Error, set?: Context["set"]) =>
|
|
6
|
+
export declare const errorToResponse: (error: Error, set?: Context["set"]) => any;
|
|
7
7
|
export declare const createStaticHandler: (handle: unknown, hooks: Partial<AnyLocalHook>, setHeaders?: Context["set"]["headers"]) => (() => Response) | undefined;
|
|
@@ -345,17 +345,23 @@ const handleElysiaFile = (file, set2 = {
|
|
|
345
345
|
}
|
|
346
346
|
return new Response(response);
|
|
347
347
|
}
|
|
348
|
-
}, errorToResponse = (error, set2) =>
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
cause: error?.cause
|
|
353
|
-
}),
|
|
354
|
-
{
|
|
355
|
-
status: set2?.status !== 200 ? set2?.status ?? 500 : 500,
|
|
356
|
-
headers: set2?.headers
|
|
348
|
+
}, errorToResponse = (error, set2) => {
|
|
349
|
+
if (typeof error?.toResponse == "function") {
|
|
350
|
+
const raw = error.toResponse(), targetSet = set2 ?? { headers: {}, status: 200, redirect: "" }, apply = (resolved) => (resolved instanceof Response && (targetSet.status = resolved.status), mapResponse(resolved, targetSet));
|
|
351
|
+
return typeof raw?.then == "function" ? raw.then(apply) : apply(raw);
|
|
357
352
|
}
|
|
358
|
-
|
|
353
|
+
return new Response(
|
|
354
|
+
JSON.stringify({
|
|
355
|
+
name: error?.name,
|
|
356
|
+
message: error?.message,
|
|
357
|
+
cause: error?.cause
|
|
358
|
+
}),
|
|
359
|
+
{
|
|
360
|
+
status: set2?.status !== 200 ? set2?.status ?? 500 : 500,
|
|
361
|
+
headers: set2?.headers
|
|
362
|
+
}
|
|
363
|
+
);
|
|
364
|
+
}, createStaticHandler = (handle, hooks, setHeaders = {}) => {
|
|
359
365
|
if (typeof handle == "function") return;
|
|
360
366
|
const response = mapResponse(handle, {
|
|
361
367
|
headers: setHeaders
|
|
@@ -330,17 +330,23 @@ const handleElysiaFile = (file, set2 = {
|
|
|
330
330
|
}
|
|
331
331
|
return new Response(response);
|
|
332
332
|
}
|
|
333
|
-
}, errorToResponse = (error, set2) =>
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
cause: error?.cause
|
|
338
|
-
}),
|
|
339
|
-
{
|
|
340
|
-
status: set2?.status !== 200 ? set2?.status ?? 500 : 500,
|
|
341
|
-
headers: set2?.headers
|
|
333
|
+
}, errorToResponse = (error, set2) => {
|
|
334
|
+
if (typeof error?.toResponse == "function") {
|
|
335
|
+
const raw = error.toResponse(), targetSet = set2 ?? { headers: {}, status: 200, redirect: "" }, apply = (resolved) => (resolved instanceof Response && (targetSet.status = resolved.status), mapResponse(resolved, targetSet));
|
|
336
|
+
return typeof raw?.then == "function" ? raw.then(apply) : apply(raw);
|
|
342
337
|
}
|
|
343
|
-
|
|
338
|
+
return new Response(
|
|
339
|
+
JSON.stringify({
|
|
340
|
+
name: error?.name,
|
|
341
|
+
message: error?.message,
|
|
342
|
+
cause: error?.cause
|
|
343
|
+
}),
|
|
344
|
+
{
|
|
345
|
+
status: set2?.status !== 200 ? set2?.status ?? 500 : 500,
|
|
346
|
+
headers: set2?.headers
|
|
347
|
+
}
|
|
348
|
+
);
|
|
349
|
+
}, createStaticHandler = (handle, hooks, setHeaders = {}) => {
|
|
344
350
|
if (typeof handle == "function") return;
|
|
345
351
|
const response = mapResponse(handle, {
|
|
346
352
|
headers: setHeaders
|
|
@@ -82,10 +82,7 @@ else c.body[key]=value}`;
|
|
|
82
82
|
for (const key of Object.keys(app.decorator))
|
|
83
83
|
decoratorsLiteral += `,'${key}':decorator['${key}']`;
|
|
84
84
|
const standardHostname = app.config.handler?.standardHostname ?? !0, hasTrace = !!app.event.trace?.length;
|
|
85
|
-
return fnLiteral += `const u=r.url,s=u.indexOf('/',${standardHostname ? 11 : 7}),qi=u.indexOf('?',s+1)
|
|
86
|
-
let p
|
|
87
|
-
if(qi===-1)p=u.substring(s)
|
|
88
|
-
else p=u.substring(s, qi)
|
|
85
|
+
return fnLiteral += `const u=r.url,s=u.indexOf('/',${standardHostname ? 11 : 7}),qi=u.indexOf('?',s+1),p=u.substring(s,qi===-1?undefined:qi)
|
|
89
86
|
`, hasTrace && (fnLiteral += `const id=randomId()
|
|
90
87
|
`), fnLiteral += "const c={request:r,store,qi,path:p,url:u,redirect,status,set:{headers:", fnLiteral += Object.keys(defaultHeaders ?? {}).length ? "Object.assign({},app.setHeaders)" : "Object.create(null)", fnLiteral += ",status:200}", app.inference.server && (fnLiteral += ",get server(){return app.getServer()}"), hasTrace && (fnLiteral += ",[ELYSIA_REQUEST_ID]:id"), fnLiteral += decoratorsLiteral, fnLiteral += `}
|
|
91
88
|
`, fnLiteral;
|
|
@@ -67,10 +67,7 @@ else c.body[key]=value}`;
|
|
|
67
67
|
for (const key of Object.keys(app.decorator))
|
|
68
68
|
decoratorsLiteral += `,'${key}':decorator['${key}']`;
|
|
69
69
|
const standardHostname = app.config.handler?.standardHostname ?? !0, hasTrace = !!app.event.trace?.length;
|
|
70
|
-
return fnLiteral += `const u=r.url,s=u.indexOf('/',${standardHostname ? 11 : 7}),qi=u.indexOf('?',s+1)
|
|
71
|
-
let p
|
|
72
|
-
if(qi===-1)p=u.substring(s)
|
|
73
|
-
else p=u.substring(s, qi)
|
|
70
|
+
return fnLiteral += `const u=r.url,s=u.indexOf('/',${standardHostname ? 11 : 7}),qi=u.indexOf('?',s+1),p=u.substring(s,qi===-1?undefined:qi)
|
|
74
71
|
`, hasTrace && (fnLiteral += `const id=randomId()
|
|
75
72
|
`), fnLiteral += "const c={request:r,store,qi,path:p,url:u,redirect,status,set:{headers:", fnLiteral += Object.keys(defaultHeaders ?? {}).length ? "Object.assign({},app.setHeaders)" : "Object.create(null)", fnLiteral += ",status:200}", app.inference.server && (fnLiteral += ",get server(){return app.getServer()}"), hasTrace && (fnLiteral += ",[ELYSIA_REQUEST_ID]:id"), fnLiteral += decoratorsLiteral, fnLiteral += `}
|
|
76
73
|
`, fnLiteral;
|