elysia 2.0.0-exp.2 → 2.0.0-exp.21

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 (135) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +2 -0
  2. package/dist/adapter/bun/index.d.ts +2 -25
  3. package/dist/adapter/bun/index.js +18 -12
  4. package/dist/adapter/bun/index.mjs +19 -13
  5. package/dist/adapter/bun/router.js +1 -1
  6. package/dist/adapter/bun/router.mjs +1 -1
  7. package/dist/adapter/constants.d.ts +3 -26
  8. package/dist/adapter/index.d.ts +1 -26
  9. package/dist/adapter/index.js +1 -17
  10. package/dist/adapter/index.mjs +1 -17
  11. package/dist/adapter/types.d.ts +1 -0
  12. package/dist/adapter/utils.d.ts +3 -4
  13. package/dist/adapter/utils.js +83 -81
  14. package/dist/adapter/utils.mjs +82 -80
  15. package/dist/adapter/web-standard/handler.js +6 -3
  16. package/dist/adapter/web-standard/handler.mjs +6 -3
  17. package/dist/adapter/web-standard/index.d.ts +2 -26
  18. package/dist/adapter/web-standard/index.js +12 -1
  19. package/dist/adapter/web-standard/index.mjs +12 -1
  20. package/dist/base.d.ts +38 -68
  21. package/dist/base.js +133 -97
  22. package/dist/base.mjs +133 -97
  23. package/dist/compile/aot.d.ts +22 -1
  24. package/dist/compile/aot.js +22 -0
  25. package/dist/compile/aot.mjs +22 -0
  26. package/dist/compile/handler/index.d.ts +2 -2
  27. package/dist/compile/handler/index.js +85 -456
  28. package/dist/compile/handler/index.mjs +86 -457
  29. package/dist/compile/handler/jit.d.ts +35 -0
  30. package/dist/compile/handler/jit.js +445 -0
  31. package/dist/compile/handler/jit.mjs +443 -0
  32. package/dist/compile/handler/params.js +3 -2
  33. package/dist/compile/handler/params.mjs +4 -3
  34. package/dist/compile/handler/reconstruct.d.ts +13 -0
  35. package/dist/compile/handler/reconstruct.js +29 -0
  36. package/dist/compile/handler/reconstruct.mjs +28 -0
  37. package/dist/compile/handler/utils.d.ts +2 -1
  38. package/dist/compile/handler/utils.js +9 -3
  39. package/dist/compile/handler/utils.mjs +9 -4
  40. package/dist/compile/jit-probe.d.ts +19 -0
  41. package/dist/compile/jit-probe.js +38 -0
  42. package/dist/compile/jit-probe.mjs +36 -0
  43. package/dist/cookie/index.d.ts +4 -3
  44. package/dist/cookie/index.js +2 -1
  45. package/dist/cookie/index.mjs +2 -1
  46. package/dist/cookie/serialize.d.ts +6 -0
  47. package/dist/cookie/serialize.js +28 -0
  48. package/dist/cookie/serialize.mjs +27 -0
  49. package/dist/cookie/utils.d.ts +1 -2
  50. package/dist/cookie/utils.js +2 -23
  51. package/dist/cookie/utils.mjs +5 -25
  52. package/dist/handler/error.js +2 -2
  53. package/dist/handler/error.mjs +3 -3
  54. package/dist/handler/fetch.js +49 -42
  55. package/dist/handler/fetch.mjs +50 -43
  56. package/dist/index.d.ts +13 -8
  57. package/dist/index.js +11 -4
  58. package/dist/index.mjs +7 -6
  59. package/dist/parse-query.js +1 -1
  60. package/dist/parse-query.mjs +1 -1
  61. package/dist/plugin/bun.d.ts +10 -0
  62. package/dist/plugin/bun.js +18 -1
  63. package/dist/plugin/bun.mjs +19 -2
  64. package/dist/plugin/core.d.ts +61 -1
  65. package/dist/plugin/core.js +90 -10
  66. package/dist/plugin/core.mjs +90 -12
  67. package/dist/plugin/esbuild.d.ts +10 -0
  68. package/dist/plugin/esbuild.js +18 -1
  69. package/dist/plugin/esbuild.mjs +19 -2
  70. package/dist/plugin/source.d.ts +38 -1
  71. package/dist/plugin/source.js +104 -13
  72. package/dist/plugin/source.mjs +102 -14
  73. package/dist/plugin/vite.d.ts +7 -0
  74. package/dist/plugin/vite.js +22 -1
  75. package/dist/plugin/vite.mjs +23 -2
  76. package/dist/sucrose.js +23 -10
  77. package/dist/sucrose.mjs +23 -10
  78. package/dist/trace.d.ts +1 -1
  79. package/dist/trace.js +4 -6
  80. package/dist/trace.mjs +4 -6
  81. package/dist/type/bridge.d.ts +9 -8
  82. package/dist/type/coerce.d.ts +20 -2
  83. package/dist/type/coerce.js +110 -0
  84. package/dist/type/coerce.mjs +109 -2
  85. package/dist/type/compat.js +4 -3
  86. package/dist/type/compat.mjs +2 -1
  87. package/dist/type/constants.d.ts +1 -1
  88. package/dist/type/elysia/boolean-string.js +1 -1
  89. package/dist/type/elysia/boolean-string.mjs +1 -1
  90. package/dist/type/elysia/file-type.js +1 -1
  91. package/dist/type/elysia/file-type.mjs +1 -1
  92. package/dist/type/elysia/integer-string.js +1 -1
  93. package/dist/type/elysia/integer-string.mjs +1 -1
  94. package/dist/type/exports.js +29 -2059
  95. package/dist/type/exports.mjs +7 -295
  96. package/dist/type/index.d.ts +6 -2
  97. package/dist/type/index.js +4 -0
  98. package/dist/type/index.mjs +3 -1
  99. package/dist/type/types.d.ts +1 -1
  100. package/dist/type/utils.js +4 -4
  101. package/dist/type/utils.mjs +4 -4
  102. package/dist/type/validator/custom-error.d.ts +10 -0
  103. package/dist/type/validator/custom-error.js +113 -0
  104. package/dist/type/validator/custom-error.mjs +110 -0
  105. package/dist/type/validator/default-precompute.d.ts +22 -0
  106. package/dist/type/validator/default-precompute.js +476 -0
  107. package/dist/type/validator/default-precompute.mjs +465 -0
  108. package/dist/type/validator/frozen-check.d.ts +11 -0
  109. package/dist/type/validator/frozen-check.js +19 -0
  110. package/dist/type/validator/frozen-check.mjs +18 -0
  111. package/dist/type/{validator.d.ts → validator/index.d.ts} +7 -20
  112. package/dist/type/validator/index.js +572 -0
  113. package/dist/type/validator/index.mjs +567 -0
  114. package/dist/type/validator/string-codec-aot.d.ts +9 -0
  115. package/dist/type/validator/string-codec-aot.js +106 -0
  116. package/dist/type/validator/string-codec-aot.mjs +102 -0
  117. package/dist/type/validator/validator-cache.d.ts +21 -0
  118. package/dist/type/validator/validator-cache.js +163 -0
  119. package/dist/type/validator/validator-cache.mjs +161 -0
  120. package/dist/types.d.ts +22 -14
  121. package/dist/universal/file.d.ts +1 -1
  122. package/dist/universal/file.js +35 -29
  123. package/dist/universal/file.mjs +35 -29
  124. package/dist/utils.d.ts +12 -1
  125. package/dist/utils.js +89 -45
  126. package/dist/utils.mjs +88 -46
  127. package/dist/validator/index.d.ts +1 -1
  128. package/dist/validator/index.js +15 -2
  129. package/dist/validator/index.mjs +15 -2
  130. package/dist/validator/route.d.ts +0 -1
  131. package/dist/ws/route.js +47 -24
  132. package/dist/ws/route.mjs +48 -25
  133. package/package.json +10 -4
  134. package/dist/type/validator.js +0 -1033
  135. package/dist/type/validator.mjs +0 -1029
package/dist/ws/route.js CHANGED
@@ -5,6 +5,7 @@ const require_error = require('../error.js');
5
5
  const require_parse_query = require('../parse-query.js');
6
6
  const require_validator_route = require('../validator/route.js');
7
7
  const require_compile_handler_utils = require('../compile/handler/utils.js');
8
+ const require_compile_handler_index = require('../compile/handler/index.js');
8
9
  const require_ws_context = require('./context.js');
9
10
  const require_ws_parser = require('./parser.js');
10
11
 
@@ -50,13 +51,22 @@ async function handleWSResponse(ws, value, mapResponses) {
50
51
  }
51
52
  function buildWSRoute(route, app) {
52
53
  const hook = route[4] ?? {};
53
- const validators = new require_validator_route.RouteValidator(hook, { models: app["~ext"]?.models });
54
+ const validators = new require_validator_route.RouteValidator(hook, {
55
+ models: app["~ext"]?.models,
56
+ aot: {
57
+ method: "WS",
58
+ path: route[1]
59
+ }
60
+ });
54
61
  const responseValidator = validators.response;
55
62
  const defaultResponseValidator = responseValidator ? responseValidator[200] ?? responseValidator[Object.keys(responseValidator)[0]] : void 0;
56
63
  const queryChannels = require_compile_handler_utils.getQueryParseChannels(validators.query?.schema);
57
64
  const queryArray = queryChannels?.array;
58
65
  const queryObject = queryChannels?.object;
59
- const flatAppHook = require_utils.flattenChain(app["~hookChain"]) ?? {};
66
+ const instance = route[3] ?? app;
67
+ const appHookChain = route[5];
68
+ const inheritedChain = route[6];
69
+ const flatAppHook = require_compile_handler_index.composeRouteHook(instance, void 0, appHookChain, inheritedChain, app) ?? {};
60
70
  const parseHooks = toArray(hook.parse);
61
71
  const transforms = concatHooks(flatAppHook.transform, hook.transform);
62
72
  const allBeforeHandles = concatHooks(flatAppHook.beforeHandle, hook.beforeHandle);
@@ -106,22 +116,33 @@ function buildWSRoute(route, app) {
106
116
  ws.raw.send(message);
107
117
  } catch {}
108
118
  }
119
+ const bodyValidator = validators.body;
120
+ function validateMessageBody(message) {
121
+ if (!bodyValidator) return message;
122
+ if (bodyValidator.hasCodec) return bodyValidator.From(message, "body");
123
+ if (!bodyValidator.Check(message)) throw new require_error.ValidationError("body", message, bodyValidator.Errors?.(message) ?? []);
124
+ return message;
125
+ }
126
+ function onMessageValidationError(ws, error) {
127
+ if (errorHandlers.length === 0) {
128
+ try {
129
+ ws.raw.send(error instanceof Error ? error.message : error + "");
130
+ } catch {}
131
+ return;
132
+ }
133
+ return handleError(ws, error);
134
+ }
109
135
  const messageTakesBody = !!hook.message && hook.message.length >= 2;
110
136
  async function dispatchMessage(connection, rawMessage) {
111
137
  const ws = Object.create(connection);
112
138
  try {
113
139
  const p = parseMessage(ws.raw, rawMessage);
114
- const message = p instanceof Promise ? await p : p;
115
- if (validators.body) {
116
- const v = validators.body;
117
- if (!v.Check(message)) {
118
- const err = new require_error.ValidationError("body", message, v.Errors?.(message) ?? []);
119
- if (errorHandlers.length === 0) {
120
- ws.raw.send(err.message);
121
- return;
122
- }
123
- return handleError(ws, err);
124
- }
140
+ let message = p instanceof Promise ? await p : p;
141
+ if (bodyValidator) try {
142
+ const decoded = validateMessageBody(message);
143
+ message = decoded instanceof Promise ? await decoded : decoded;
144
+ } catch (err) {
145
+ return onMessageValidationError(ws, err);
125
146
  }
126
147
  ws.body = message;
127
148
  for (let i = 0; i < transforms.length; i++) {
@@ -164,18 +185,20 @@ function buildWSRoute(route, app) {
164
185
  }
165
186
  }
166
187
  function dispatchParsedSync(ws, message) {
167
- try {
168
- if (validators.body) {
169
- const v = validators.body;
170
- if (!v.Check(message)) {
171
- const err = new require_error.ValidationError("body", message, v.Errors?.(message) ?? []);
172
- if (errorHandlers.length === 0) {
173
- ws.raw.send(err.message);
174
- return;
175
- }
176
- return handleError(ws, err);
177
- }
188
+ if (bodyValidator) {
189
+ let decoded;
190
+ try {
191
+ decoded = validateMessageBody(message);
192
+ } catch (error) {
193
+ return onMessageValidationError(ws, error);
178
194
  }
195
+ if (decoded instanceof Promise) return decoded.then((m) => runMessageSync(ws, m), (error) => onMessageValidationError(ws, error));
196
+ message = decoded;
197
+ }
198
+ return runMessageSync(ws, message);
199
+ }
200
+ function runMessageSync(ws, message) {
201
+ try {
179
202
  ws.body = message;
180
203
  const result = messageTakesBody ? hook.message(ws, message) : hook.message(ws);
181
204
  if (result instanceof Promise) return result.then((resolved) => finishMessageResult(ws, resolved), (error) => handleError(ws, error));
package/dist/ws/route.mjs CHANGED
@@ -1,9 +1,10 @@
1
1
  import { isBun } from "../universal/constants.mjs";
2
- import { flattenChain, nullObject } from "../utils.mjs";
2
+ import { nullObject } from "../utils.mjs";
3
3
  import { ValidationError } from "../error.mjs";
4
4
  import { parseQueryFromURL } from "../parse-query.mjs";
5
5
  import { RouteValidator } from "../validator/route.mjs";
6
6
  import { getQueryParseChannels } from "../compile/handler/utils.mjs";
7
+ import { composeRouteHook } from "../compile/handler/index.mjs";
7
8
  import { ElysiaWS, isGeneratorObject } from "./context.mjs";
8
9
  import { createMessageParser } from "./parser.mjs";
9
10
 
@@ -49,13 +50,22 @@ async function handleWSResponse(ws, value, mapResponses) {
49
50
  }
50
51
  function buildWSRoute(route, app) {
51
52
  const hook = route[4] ?? {};
52
- const validators = new RouteValidator(hook, { models: app["~ext"]?.models });
53
+ const validators = new RouteValidator(hook, {
54
+ models: app["~ext"]?.models,
55
+ aot: {
56
+ method: "WS",
57
+ path: route[1]
58
+ }
59
+ });
53
60
  const responseValidator = validators.response;
54
61
  const defaultResponseValidator = responseValidator ? responseValidator[200] ?? responseValidator[Object.keys(responseValidator)[0]] : void 0;
55
62
  const queryChannels = getQueryParseChannels(validators.query?.schema);
56
63
  const queryArray = queryChannels?.array;
57
64
  const queryObject = queryChannels?.object;
58
- const flatAppHook = flattenChain(app["~hookChain"]) ?? {};
65
+ const instance = route[3] ?? app;
66
+ const appHookChain = route[5];
67
+ const inheritedChain = route[6];
68
+ const flatAppHook = composeRouteHook(instance, void 0, appHookChain, inheritedChain, app) ?? {};
59
69
  const parseHooks = toArray(hook.parse);
60
70
  const transforms = concatHooks(flatAppHook.transform, hook.transform);
61
71
  const allBeforeHandles = concatHooks(flatAppHook.beforeHandle, hook.beforeHandle);
@@ -105,22 +115,33 @@ function buildWSRoute(route, app) {
105
115
  ws.raw.send(message);
106
116
  } catch {}
107
117
  }
118
+ const bodyValidator = validators.body;
119
+ function validateMessageBody(message) {
120
+ if (!bodyValidator) return message;
121
+ if (bodyValidator.hasCodec) return bodyValidator.From(message, "body");
122
+ if (!bodyValidator.Check(message)) throw new ValidationError("body", message, bodyValidator.Errors?.(message) ?? []);
123
+ return message;
124
+ }
125
+ function onMessageValidationError(ws, error) {
126
+ if (errorHandlers.length === 0) {
127
+ try {
128
+ ws.raw.send(error instanceof Error ? error.message : error + "");
129
+ } catch {}
130
+ return;
131
+ }
132
+ return handleError(ws, error);
133
+ }
108
134
  const messageTakesBody = !!hook.message && hook.message.length >= 2;
109
135
  async function dispatchMessage(connection, rawMessage) {
110
136
  const ws = Object.create(connection);
111
137
  try {
112
138
  const p = parseMessage(ws.raw, rawMessage);
113
- const message = p instanceof Promise ? await p : p;
114
- if (validators.body) {
115
- const v = validators.body;
116
- if (!v.Check(message)) {
117
- const err = new ValidationError("body", message, v.Errors?.(message) ?? []);
118
- if (errorHandlers.length === 0) {
119
- ws.raw.send(err.message);
120
- return;
121
- }
122
- return handleError(ws, err);
123
- }
139
+ let message = p instanceof Promise ? await p : p;
140
+ if (bodyValidator) try {
141
+ const decoded = validateMessageBody(message);
142
+ message = decoded instanceof Promise ? await decoded : decoded;
143
+ } catch (err) {
144
+ return onMessageValidationError(ws, err);
124
145
  }
125
146
  ws.body = message;
126
147
  for (let i = 0; i < transforms.length; i++) {
@@ -163,18 +184,20 @@ function buildWSRoute(route, app) {
163
184
  }
164
185
  }
165
186
  function dispatchParsedSync(ws, message) {
166
- try {
167
- if (validators.body) {
168
- const v = validators.body;
169
- if (!v.Check(message)) {
170
- const err = new ValidationError("body", message, v.Errors?.(message) ?? []);
171
- if (errorHandlers.length === 0) {
172
- ws.raw.send(err.message);
173
- return;
174
- }
175
- return handleError(ws, err);
176
- }
187
+ if (bodyValidator) {
188
+ let decoded;
189
+ try {
190
+ decoded = validateMessageBody(message);
191
+ } catch (error) {
192
+ return onMessageValidationError(ws, error);
177
193
  }
194
+ if (decoded instanceof Promise) return decoded.then((m) => runMessageSync(ws, m), (error) => onMessageValidationError(ws, error));
195
+ message = decoded;
196
+ }
197
+ return runMessageSync(ws, message);
198
+ }
199
+ function runMessageSync(ws, message) {
200
+ try {
178
201
  ws.body = message;
179
202
  const result = messageTakesBody ? hook.message(ws, message) : hook.message(ws);
180
203
  if (result instanceof Promise) return result.then((resolved) => finishMessageResult(ws, resolved), (error) => handleError(ws, error));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "elysia",
3
3
  "description": "Ergonomic Framework for Human",
4
- "version": "2.0.0-exp.2",
4
+ "version": "2.0.0-exp.21",
5
5
  "author": {
6
6
  "name": "saltyAom",
7
7
  "url": "https://github.com/SaltyAom",
@@ -50,6 +50,11 @@
50
50
  "import": "./dist/base.mjs",
51
51
  "require": "./dist/base.js"
52
52
  },
53
+ "./compiled": {
54
+ "types": "./dist/compiled.d.ts",
55
+ "import": "./dist/compiled.mjs",
56
+ "require": "./dist/compiled.js"
57
+ },
53
58
  "./constants": {
54
59
  "types": "./dist/constants.d.ts",
55
60
  "import": "./dist/constants.mjs",
@@ -198,7 +203,7 @@
198
203
  "dependencies": {
199
204
  "deuri": "^2.0.1",
200
205
  "exact-mirror": "1.2.2",
201
- "memoirist": "^1.0.3"
206
+ "memoirist": "1.1.0"
202
207
  },
203
208
  "devDependencies": {
204
209
  "@eslint/eslintrc": "^3.3.5",
@@ -220,15 +225,16 @@
220
225
  "prettier": "^3.5.3",
221
226
  "rolldown-plugin-dts": "^0.24.0",
222
227
  "tsdown": "^0.21.10",
223
- "typebox": "^1.2.16",
228
+ "typebox": "1.3",
224
229
  "typescript": "^6.0.2",
230
+ "unplugin-macros": "^0.20.2",
225
231
  "valibot": "^1.1.0",
226
232
  "zod": "^4.1.5"
227
233
  },
228
234
  "peerDependencies": {
229
235
  "@types/bun": ">= 1.3.0",
230
236
  "openapi-types": ">= 12.0.0",
231
- "typebox": ">= 1.2.16",
237
+ "typebox": ">= 1.3.0",
232
238
  "typescript": ">= 5.7.0"
233
239
  },
234
240
  "peerDependenciesMeta": {