elysia 1.4.11 → 1.4.12
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/compose.js +90 -0
- package/dist/adapter/bun/compose.mjs +15 -2661
- package/dist/adapter/bun/handler-native.js +40 -0
- package/dist/adapter/bun/handler-native.mjs +5 -4051
- package/dist/adapter/bun/handler.js +370 -0
- package/dist/adapter/bun/handler.mjs +16 -476
- package/dist/adapter/bun/index.js +380 -0
- package/dist/adapter/bun/index.mjs +66 -3750
- package/dist/adapter/cloudflare-worker/index.js +72 -0
- package/dist/adapter/cloudflare-worker/index.mjs +4 -995
- package/dist/{cjs/adapter → adapter}/index.js +0 -2
- package/dist/{cjs → adapter}/types.js +0 -2
- package/dist/{cjs/adapter → adapter}/utils.js +27 -168
- package/dist/adapter/utils.mjs +22 -151
- package/dist/adapter/web-standard/handler.js +379 -0
- package/dist/adapter/web-standard/handler.mjs +19 -557
- package/dist/adapter/web-standard/index.js +120 -0
- package/dist/adapter/web-standard/index.mjs +10 -899
- package/dist/bun/index.js +3 -3
- package/dist/bun/index.js.map +9 -9
- package/dist/compose.d.ts +1 -1
- package/dist/compose.js +1271 -0
- package/dist/compose.mjs +216 -3558
- package/dist/{cjs/context.js → context.js} +0 -2
- package/dist/{cjs/cookies.js → cookies.js} +16 -158
- package/dist/cookies.mjs +14 -153
- package/dist/dynamic-handle.d.ts +1 -1
- package/dist/dynamic-handle.js +408 -0
- package/dist/dynamic-handle.mjs +63 -629
- package/dist/{cjs/error.js → error.js} +33 -124
- package/dist/error.mjs +31 -120
- package/dist/{cjs/formats.js → formats.js} +19 -21
- package/dist/formats.mjs +18 -19
- package/dist/index.d.ts +12 -1
- package/dist/index.js +1877 -0
- package/dist/index.mjs +197 -6827
- package/dist/{cjs/parse-query.js → parse-query.js} +20 -12
- package/dist/parse-query.mjs +19 -11
- package/dist/schema.js +1043 -0
- package/dist/schema.mjs +119 -1269
- package/dist/sucrose.js +300 -0
- package/dist/sucrose.mjs +49 -1083
- package/dist/trace.js +137 -0
- package/dist/trace.mjs +20 -115
- package/dist/{cjs/type-system → type-system}/format.js +53 -61
- package/dist/type-system/format.mjs +52 -60
- package/dist/type-system/index.d.ts +0 -1
- package/dist/type-system/index.js +392 -0
- package/dist/type-system/index.mjs +55 -792
- package/dist/{cjs/ws → type-system}/types.js +0 -2
- package/dist/type-system/utils.js +138 -0
- package/dist/type-system/utils.mjs +20 -514
- package/dist/types.d.ts +2 -1
- package/dist/{cjs/adapter/types.js → types.js} +0 -2
- package/dist/{cjs/universal → universal}/env.js +2 -8
- package/dist/universal/env.mjs +2 -5
- package/dist/{cjs/universal → universal}/file.js +11 -15
- package/dist/universal/file.mjs +9 -10
- package/dist/universal/index.js +27 -0
- package/dist/universal/index.mjs +2 -133
- package/dist/{cjs/universal → universal}/request.js +13 -15
- package/dist/universal/request.mjs +13 -14
- package/dist/{cjs/universal → universal}/server.js +0 -2
- package/dist/{cjs/universal → universal}/types.js +4 -5
- package/dist/universal/types.mjs +4 -4
- package/dist/{cjs/universal → universal}/utils.js +1 -3
- package/dist/universal/utils.mjs +1 -2
- package/dist/{cjs/utils.js → utils.js} +51 -182
- package/dist/utils.mjs +49 -177
- package/dist/{cjs/ws → ws}/bun.js +0 -2
- package/dist/ws/index.js +164 -0
- package/dist/ws/index.mjs +15 -349
- package/dist/{cjs/type-system → ws}/types.js +0 -2
- package/package.json +34 -33
- package/dist/bun/index.d.ts +0 -2198
- package/dist/cjs/adapter/bun/compose.js +0 -2722
- package/dist/cjs/adapter/bun/handler-native.js +0 -4068
- package/dist/cjs/adapter/bun/handler.js +0 -848
- package/dist/cjs/adapter/bun/index.js +0 -4070
- package/dist/cjs/adapter/cloudflare-worker/index.js +0 -1073
- package/dist/cjs/adapter/web-standard/handler.js +0 -936
- package/dist/cjs/adapter/web-standard/index.js +0 -1024
- package/dist/cjs/compose.d.ts +0 -30
- package/dist/cjs/compose.js +0 -4625
- package/dist/cjs/context.d.ts +0 -130
- package/dist/cjs/cookies.d.ts +0 -153
- package/dist/cjs/dynamic-handle.d.ts +0 -15
- package/dist/cjs/dynamic-handle.js +0 -990
- package/dist/cjs/error.d.ts +0 -170
- package/dist/cjs/formats.d.ts +0 -79
- package/dist/cjs/index.d.ts +0 -2198
- package/dist/cjs/index.js +0 -8574
- package/dist/cjs/manifest.d.ts +0 -0
- package/dist/cjs/parse-query.d.ts +0 -15
- package/dist/cjs/schema.d.ts +0 -119
- package/dist/cjs/schema.js +0 -2190
- package/dist/cjs/sucrose.d.ts +0 -109
- package/dist/cjs/sucrose.js +0 -1346
- package/dist/cjs/trace.d.ts +0 -135
- package/dist/cjs/trace.js +0 -235
- package/dist/cjs/type-system/index.js +0 -1141
- package/dist/cjs/type-system/utils.js +0 -635
- package/dist/cjs/types.d.ts +0 -1196
- package/dist/cjs/universal/index.js +0 -162
- package/dist/cjs/utils.d.ts +0 -198
- package/dist/cjs/ws/bun.d.ts +0 -410
- package/dist/cjs/ws/index.d.ts +0 -76
- package/dist/cjs/ws/index.js +0 -502
- package/dist/cjs/ws/types.d.ts +0 -60
- /package/dist/{cjs/manifest.js → manifest.js} +0 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
16
|
+
var compose_exports = {};
|
|
17
|
+
__export(compose_exports, {
|
|
18
|
+
createBunRouteHandler: () => createBunRouteHandler
|
|
19
|
+
});
|
|
20
|
+
module.exports = __toCommonJS(compose_exports);
|
|
21
|
+
var import_handler = require('./handler.js'), import_sucrose = require('../../sucrose.js'), import_compose = require('../../compose.js'), import_utils = require('../../utils.js'), import_error = require('../../error.js'), import_trace = require('../../trace.js');
|
|
22
|
+
const allocateIf = (value, condition) => condition ? value : "", createContext = (app, route, inference, isInline = !1) => {
|
|
23
|
+
let fnLiteral = "";
|
|
24
|
+
const defaultHeaders = app.setHeaders, hasTrace = !!app.event.trace?.length;
|
|
25
|
+
hasTrace && (fnLiteral += `const id=randomId()
|
|
26
|
+
`);
|
|
27
|
+
const isDynamic = /[:*]/.test(route.path), getQi = `const u=request.url,s=u.indexOf('/',${app.config.handler?.standardHostname ?? !0 ? 11 : 7}),qi=u.indexOf('?', s + 1)
|
|
28
|
+
`, needsQuery = inference.query || !!route.hooks.query || !!route.hooks.standaloneValidator?.find(
|
|
29
|
+
(x) => x.query
|
|
30
|
+
) || app.event.request?.length;
|
|
31
|
+
needsQuery && (fnLiteral += getQi);
|
|
32
|
+
const getPath = inference.path ? isDynamic ? "get path(){" + (needsQuery ? "" : getQi) + `if(qi===-1)return u.substring(s)
|
|
33
|
+
return u.substring(s,qi)
|
|
34
|
+
},` : `path:'${route.path}',` : "";
|
|
35
|
+
fnLiteral += allocateIf("const c=", !isInline) + "{request,store," + allocateIf("qi,", needsQuery) + allocateIf("params:request.params,", isDynamic) + getPath + allocateIf(
|
|
36
|
+
"url:request.url,",
|
|
37
|
+
hasTrace || inference.url || needsQuery
|
|
38
|
+
) + "redirect,status,set:{headers:" + ((0, import_utils.isNotEmpty)(defaultHeaders) ? "Object.assign({},app.setHeaders)" : "Object.create(null)") + ",status:200}", inference.server && (fnLiteral += ",get server(){return app.getServer()}"), hasTrace && (fnLiteral += ",[ELYSIA_REQUEST_ID]:id");
|
|
39
|
+
{
|
|
40
|
+
let decoratorsLiteral = "";
|
|
41
|
+
for (const key of Object.keys(app.singleton.decorator))
|
|
42
|
+
decoratorsLiteral += `,'${key}':decorator['${key}']`;
|
|
43
|
+
fnLiteral += decoratorsLiteral;
|
|
44
|
+
}
|
|
45
|
+
return fnLiteral += `}
|
|
46
|
+
`, fnLiteral;
|
|
47
|
+
}, createBunRouteHandler = (app, route) => {
|
|
48
|
+
const hasTrace = !!app.event.trace?.length, hasHoc = !!app.extender.higherOrderFunctions.length;
|
|
49
|
+
let inference = (0, import_sucrose.sucrose)(
|
|
50
|
+
route.hooks,
|
|
51
|
+
// @ts-expect-error
|
|
52
|
+
app.inference
|
|
53
|
+
);
|
|
54
|
+
inference = (0, import_sucrose.sucrose)(
|
|
55
|
+
{
|
|
56
|
+
handler: route.handler
|
|
57
|
+
},
|
|
58
|
+
inference
|
|
59
|
+
);
|
|
60
|
+
let fnLiteral = "const handler=data.handler,app=data.app,store=data.store,decorator=data.decorator,redirect=data.redirect,route=data.route,mapEarlyResponse=data.mapEarlyResponse," + allocateIf("randomId=data.randomId,", hasTrace) + allocateIf("ELYSIA_REQUEST_ID=data.ELYSIA_REQUEST_ID,", hasTrace) + allocateIf("ELYSIA_TRACE=data.ELYSIA_TRACE,", hasTrace) + allocateIf("trace=data.trace,", hasTrace) + allocateIf("hoc=data.hoc,", hasHoc) + `status=data.status
|
|
61
|
+
`;
|
|
62
|
+
app.event.request?.length && (fnLiteral += `const onRequest=app.event.request.map(x=>x.fn)
|
|
63
|
+
`), fnLiteral += `${app.event.request?.find(import_compose.isAsync) ? "async" : ""} function map(request){`;
|
|
64
|
+
const needsQuery = inference.query || !!route.hooks.query || !!route.hooks.standaloneValidator?.find(
|
|
65
|
+
(x) => x.query
|
|
66
|
+
);
|
|
67
|
+
return hasTrace || needsQuery || app.event.request?.length ? (fnLiteral += createContext(app, route, inference), fnLiteral += (0, import_compose.createOnRequestHandler)(app), fnLiteral += "return handler(c)}") : fnLiteral += `return handler(${createContext(app, route, inference, !0)})}`, fnLiteral += (0, import_compose.createHoc)(app), Function(
|
|
68
|
+
"data",
|
|
69
|
+
fnLiteral
|
|
70
|
+
)({
|
|
71
|
+
app,
|
|
72
|
+
handler: route.compile?.() ?? route.composed,
|
|
73
|
+
redirect: import_utils.redirect,
|
|
74
|
+
status: import_error.status,
|
|
75
|
+
// @ts-expect-error private property
|
|
76
|
+
hoc: app.extender.higherOrderFunctions.map((x) => x.fn),
|
|
77
|
+
store: app.store,
|
|
78
|
+
decorator: app.decorator,
|
|
79
|
+
route: route.path,
|
|
80
|
+
randomId: hasTrace ? import_utils.randomId : void 0,
|
|
81
|
+
ELYSIA_TRACE: hasTrace ? import_trace.ELYSIA_TRACE : void 0,
|
|
82
|
+
ELYSIA_REQUEST_ID: hasTrace ? import_utils.ELYSIA_REQUEST_ID : void 0,
|
|
83
|
+
trace: hasTrace ? app.event.trace?.map((x) => x?.fn ?? x) : void 0,
|
|
84
|
+
mapEarlyResponse: import_handler.mapEarlyResponse
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
88
|
+
0 && (module.exports = {
|
|
89
|
+
createBunRouteHandler
|
|
90
|
+
});
|