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.
Files changed (110) hide show
  1. package/dist/adapter/bun/compose.js +90 -0
  2. package/dist/adapter/bun/compose.mjs +15 -2661
  3. package/dist/adapter/bun/handler-native.js +40 -0
  4. package/dist/adapter/bun/handler-native.mjs +5 -4051
  5. package/dist/adapter/bun/handler.js +370 -0
  6. package/dist/adapter/bun/handler.mjs +16 -476
  7. package/dist/adapter/bun/index.js +380 -0
  8. package/dist/adapter/bun/index.mjs +66 -3750
  9. package/dist/adapter/cloudflare-worker/index.js +72 -0
  10. package/dist/adapter/cloudflare-worker/index.mjs +4 -995
  11. package/dist/{cjs/adapter → adapter}/index.js +0 -2
  12. package/dist/{cjs → adapter}/types.js +0 -2
  13. package/dist/{cjs/adapter → adapter}/utils.js +27 -168
  14. package/dist/adapter/utils.mjs +22 -151
  15. package/dist/adapter/web-standard/handler.js +379 -0
  16. package/dist/adapter/web-standard/handler.mjs +19 -557
  17. package/dist/adapter/web-standard/index.js +120 -0
  18. package/dist/adapter/web-standard/index.mjs +10 -899
  19. package/dist/bun/index.js +3 -3
  20. package/dist/bun/index.js.map +9 -9
  21. package/dist/compose.d.ts +1 -1
  22. package/dist/compose.js +1271 -0
  23. package/dist/compose.mjs +216 -3558
  24. package/dist/{cjs/context.js → context.js} +0 -2
  25. package/dist/{cjs/cookies.js → cookies.js} +16 -158
  26. package/dist/cookies.mjs +14 -153
  27. package/dist/dynamic-handle.d.ts +1 -1
  28. package/dist/dynamic-handle.js +408 -0
  29. package/dist/dynamic-handle.mjs +63 -629
  30. package/dist/{cjs/error.js → error.js} +33 -124
  31. package/dist/error.mjs +31 -120
  32. package/dist/{cjs/formats.js → formats.js} +19 -21
  33. package/dist/formats.mjs +18 -19
  34. package/dist/index.d.ts +12 -1
  35. package/dist/index.js +1877 -0
  36. package/dist/index.mjs +197 -6827
  37. package/dist/{cjs/parse-query.js → parse-query.js} +20 -12
  38. package/dist/parse-query.mjs +19 -11
  39. package/dist/schema.js +1043 -0
  40. package/dist/schema.mjs +119 -1269
  41. package/dist/sucrose.js +300 -0
  42. package/dist/sucrose.mjs +49 -1083
  43. package/dist/trace.js +137 -0
  44. package/dist/trace.mjs +20 -115
  45. package/dist/{cjs/type-system → type-system}/format.js +53 -61
  46. package/dist/type-system/format.mjs +52 -60
  47. package/dist/type-system/index.d.ts +0 -1
  48. package/dist/type-system/index.js +392 -0
  49. package/dist/type-system/index.mjs +55 -792
  50. package/dist/{cjs/ws → type-system}/types.js +0 -2
  51. package/dist/type-system/utils.js +138 -0
  52. package/dist/type-system/utils.mjs +20 -514
  53. package/dist/types.d.ts +2 -1
  54. package/dist/{cjs/adapter/types.js → types.js} +0 -2
  55. package/dist/{cjs/universal → universal}/env.js +2 -8
  56. package/dist/universal/env.mjs +2 -5
  57. package/dist/{cjs/universal → universal}/file.js +11 -15
  58. package/dist/universal/file.mjs +9 -10
  59. package/dist/universal/index.js +27 -0
  60. package/dist/universal/index.mjs +2 -133
  61. package/dist/{cjs/universal → universal}/request.js +13 -15
  62. package/dist/universal/request.mjs +13 -14
  63. package/dist/{cjs/universal → universal}/server.js +0 -2
  64. package/dist/{cjs/universal → universal}/types.js +4 -5
  65. package/dist/universal/types.mjs +4 -4
  66. package/dist/{cjs/universal → universal}/utils.js +1 -3
  67. package/dist/universal/utils.mjs +1 -2
  68. package/dist/{cjs/utils.js → utils.js} +51 -182
  69. package/dist/utils.mjs +49 -177
  70. package/dist/{cjs/ws → ws}/bun.js +0 -2
  71. package/dist/ws/index.js +164 -0
  72. package/dist/ws/index.mjs +15 -349
  73. package/dist/{cjs/type-system → ws}/types.js +0 -2
  74. package/package.json +34 -33
  75. package/dist/bun/index.d.ts +0 -2198
  76. package/dist/cjs/adapter/bun/compose.js +0 -2722
  77. package/dist/cjs/adapter/bun/handler-native.js +0 -4068
  78. package/dist/cjs/adapter/bun/handler.js +0 -848
  79. package/dist/cjs/adapter/bun/index.js +0 -4070
  80. package/dist/cjs/adapter/cloudflare-worker/index.js +0 -1073
  81. package/dist/cjs/adapter/web-standard/handler.js +0 -936
  82. package/dist/cjs/adapter/web-standard/index.js +0 -1024
  83. package/dist/cjs/compose.d.ts +0 -30
  84. package/dist/cjs/compose.js +0 -4625
  85. package/dist/cjs/context.d.ts +0 -130
  86. package/dist/cjs/cookies.d.ts +0 -153
  87. package/dist/cjs/dynamic-handle.d.ts +0 -15
  88. package/dist/cjs/dynamic-handle.js +0 -990
  89. package/dist/cjs/error.d.ts +0 -170
  90. package/dist/cjs/formats.d.ts +0 -79
  91. package/dist/cjs/index.d.ts +0 -2198
  92. package/dist/cjs/index.js +0 -8574
  93. package/dist/cjs/manifest.d.ts +0 -0
  94. package/dist/cjs/parse-query.d.ts +0 -15
  95. package/dist/cjs/schema.d.ts +0 -119
  96. package/dist/cjs/schema.js +0 -2190
  97. package/dist/cjs/sucrose.d.ts +0 -109
  98. package/dist/cjs/sucrose.js +0 -1346
  99. package/dist/cjs/trace.d.ts +0 -135
  100. package/dist/cjs/trace.js +0 -235
  101. package/dist/cjs/type-system/index.js +0 -1141
  102. package/dist/cjs/type-system/utils.js +0 -635
  103. package/dist/cjs/types.d.ts +0 -1196
  104. package/dist/cjs/universal/index.js +0 -162
  105. package/dist/cjs/utils.d.ts +0 -198
  106. package/dist/cjs/ws/bun.d.ts +0 -410
  107. package/dist/cjs/ws/index.d.ts +0 -76
  108. package/dist/cjs/ws/index.js +0 -502
  109. package/dist/cjs/ws/types.d.ts +0 -60
  110. /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
+ });