elysia 2.0.0-exp.30 → 2.0.0-exp.31

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 (68) hide show
  1. package/dist/adapter/skip-clone.d.ts +4 -0
  2. package/dist/adapter/{transferable.js → skip-clone.js} +1 -1
  3. package/dist/adapter/{transferable.mjs → skip-clone.mjs} +1 -1
  4. package/dist/adapter/utils.js +26 -34
  5. package/dist/adapter/utils.mjs +25 -33
  6. package/dist/adapter/web-standard/handler.js +2 -4
  7. package/dist/adapter/web-standard/handler.mjs +2 -4
  8. package/dist/base.d.ts +6 -4
  9. package/dist/base.js +17 -38
  10. package/dist/base.mjs +17 -38
  11. package/dist/compile/aot.d.ts +1 -6
  12. package/dist/compile/aot.js +1 -7
  13. package/dist/compile/aot.mjs +1 -6
  14. package/dist/compile/handler/frozen-validator.js +3 -35
  15. package/dist/compile/handler/frozen-validator.mjs +1 -33
  16. package/dist/compile/handler/index.d.ts +1 -7
  17. package/dist/compile/handler/index.js +0 -1
  18. package/dist/compile/handler/index.mjs +1 -1
  19. package/dist/compile/handler/utils.d.ts +2 -4
  20. package/dist/compile/handler/utils.js +16 -35
  21. package/dist/compile/handler/utils.mjs +16 -34
  22. package/dist/error.js +4 -4
  23. package/dist/error.mjs +1 -1
  24. package/dist/plugin/core.d.ts +1 -3
  25. package/dist/plugin/core.js +5 -5
  26. package/dist/plugin/core.mjs +6 -4
  27. package/dist/plugin/vite.js +3 -13
  28. package/dist/plugin/vite.mjs +2 -11
  29. package/dist/sucrose.d.ts +1 -23
  30. package/dist/sucrose.js +4 -8
  31. package/dist/sucrose.mjs +5 -7
  32. package/dist/type/coerce.js +1 -2
  33. package/dist/type/coerce.mjs +1 -2
  34. package/dist/type/elysia/intersect.js +3 -3
  35. package/dist/type/elysia/intersect.mjs +1 -1
  36. package/dist/type/elysia/utils.d.ts +1 -2
  37. package/dist/type/elysia/utils.js +0 -5
  38. package/dist/type/elysia/utils.mjs +1 -5
  39. package/dist/type/types.d.ts +1 -1
  40. package/dist/type/validator/clean-safe.d.ts +7 -0
  41. package/dist/type/validator/clean-safe.js +73 -0
  42. package/dist/type/validator/clean-safe.mjs +68 -0
  43. package/dist/type/validator/default-precompute.d.ts +1 -3
  44. package/dist/type/validator/default-precompute.js +0 -2
  45. package/dist/type/validator/default-precompute.mjs +1 -1
  46. package/dist/type/validator/index.d.ts +1 -1
  47. package/dist/type/validator/index.js +3 -58
  48. package/dist/type/validator/index.mjs +1 -56
  49. package/dist/type/validator/validator-cache.d.ts +1 -1
  50. package/dist/type/validator/validator-cache.js +5 -34
  51. package/dist/type/validator/validator-cache.mjs +5 -34
  52. package/dist/types.d.ts +4 -34
  53. package/dist/universal/constants.d.ts +1 -3
  54. package/dist/universal/constants.js +1 -5
  55. package/dist/universal/constants.mjs +1 -3
  56. package/dist/ws/route.js +1 -2
  57. package/dist/ws/route.mjs +1 -2
  58. package/package.json +1 -1
  59. package/dist/adapter/transferable.d.ts +0 -4
  60. package/dist/compile/index.d.ts +0 -3
  61. package/dist/compile/index.js +0 -10
  62. package/dist/compile/index.mjs +0 -4
  63. package/dist/compile/types.d.ts +0 -4
  64. package/dist/compile/types.js +0 -1
  65. package/dist/compile/types.mjs +0 -1
  66. package/dist/universal/types.d.ts +0 -127
  67. package/dist/universal/types.js +0 -20
  68. package/dist/universal/types.mjs +0 -17
@@ -0,0 +1,4 @@
1
+ //#region src/adapter/skip-clone.d.ts
2
+ declare const skipClone: WeakSet<object>;
3
+ //#endregion
4
+ export { skipClone };
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
- //#region src/adapter/transferable.ts
3
+ //#region src/adapter/skip-clone.ts
4
4
  const skipClone = /* @__PURE__ */ new WeakSet();
5
5
 
6
6
  //#endregion
@@ -1,4 +1,4 @@
1
- //#region src/adapter/transferable.ts
1
+ //#region src/adapter/skip-clone.ts
2
2
  const skipClone = /* @__PURE__ */ new WeakSet();
3
3
 
4
4
  //#endregion
@@ -2,7 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_universal_constants = require('../universal/constants.js');
3
3
  const require_constants = require('../constants.js');
4
4
  const require_utils = require('../utils.js');
5
- const require_adapter_transferable = require('./transferable.js');
5
+ const require_adapter_skip_clone = require('./skip-clone.js');
6
6
  const require_cookie_serialize = require('../cookie/serialize.js');
7
7
 
8
8
  //#region src/adapter/utils.ts
@@ -180,6 +180,26 @@ function createStreamHandler({ mapResponse, mapCompactResponse }) {
180
180
  if (r && typeof r.then === "function") r.catch(() => {});
181
181
  } catch {}
182
182
  };
183
+ const closeSafely = (controller) => {
184
+ try {
185
+ controller.close();
186
+ } catch {}
187
+ cleanupAbort();
188
+ };
189
+ const enqueueValue = async (controller, value) => {
190
+ if (value.toSSE) {
191
+ controller.enqueue(encodeChunk(value.toSSE()));
192
+ return;
193
+ }
194
+ const p = enqueueBinaryChunk(controller, value);
195
+ if (p !== false) return void await p;
196
+ if (typeof value === "object") try {
197
+ controller.enqueue(encodeChunk(format(JSON.stringify(value))));
198
+ } catch {
199
+ controller.enqueue(encodeChunk(format(value.toString())));
200
+ }
201
+ else controller.enqueue(encodeChunk(format(value.toString())));
202
+ };
183
203
  return new Response(new ReadableStream({
184
204
  async start(controller) {
185
205
  if (signal) {
@@ -195,49 +215,21 @@ function createStreamHandler({ mapResponse, mapCompactResponse }) {
195
215
  else signal.addEventListener("abort", onAbort, { once: true });
196
216
  }
197
217
  if (!init || init.value instanceof ReadableStream || init.value === void 0 || init.value === null) return;
198
- if (init.value.toSSE) {
199
- controller.enqueue(encodeChunk(init.value.toSSE()));
200
- return;
201
- }
202
- const p = enqueueBinaryChunk(controller, init.value);
203
- if (p !== false) return void await p;
204
- if (typeof init.value === "object") try {
205
- controller.enqueue(encodeChunk(format(JSON.stringify(init.value))));
206
- } catch {
207
- controller.enqueue(encodeChunk(format(init.value.toString())));
208
- }
209
- else controller.enqueue(encodeChunk(format(init.value.toString())));
218
+ await enqueueValue(controller, init.value);
210
219
  },
211
220
  async pull(controller) {
212
221
  if (end) {
213
- try {
214
- controller.close();
215
- } catch {}
216
- cleanupAbort();
222
+ closeSafely(controller);
217
223
  return;
218
224
  }
219
225
  try {
220
226
  const { value: chunk, done } = await iterator.next();
221
227
  if (done || end) {
222
- try {
223
- controller.close();
224
- } catch {}
225
- cleanupAbort();
228
+ closeSafely(controller);
226
229
  return;
227
230
  }
228
231
  if (chunk === void 0 || chunk === null) return;
229
- if (chunk.toSSE) {
230
- controller.enqueue(encodeChunk(chunk.toSSE()));
231
- return;
232
- }
233
- const p = enqueueBinaryChunk(controller, chunk);
234
- if (p !== false) return void await p;
235
- if (typeof chunk === "object") try {
236
- controller.enqueue(encodeChunk(format(JSON.stringify(chunk))));
237
- } catch {
238
- controller.enqueue(encodeChunk(format(chunk.toString())));
239
- }
240
- else controller.enqueue(encodeChunk(format(chunk.toString())));
232
+ await enqueueValue(controller, chunk);
241
233
  } catch (error) {
242
234
  cleanupAbort();
243
235
  controller.error(error);
@@ -315,7 +307,7 @@ function createResponseHandler(handler) {
315
307
  if ((status === void 0 || status === response.status) && !set.cookie && !require_utils.isNotEmpty(set.headers)) return response;
316
308
  }
317
309
  let body = response.body;
318
- if (require_adapter_transferable.skipClone.has(response) && !response.bodyUsed) require_adapter_transferable.skipClone.delete(response);
310
+ if (require_adapter_skip_clone.skipClone.has(response) && !response.bodyUsed) require_adapter_skip_clone.skipClone.delete(response);
319
311
  else {
320
312
  const cloned = response.clone();
321
313
  body = cloned.body && response.body ? cancelPropagatingBody(cloned.body, response.body) : cloned.body;
@@ -1,7 +1,7 @@
1
1
  import { hasHeaderShorthand, isBun } from "../universal/constants.mjs";
2
2
  import { StatusMap } from "../constants.mjs";
3
3
  import { isNotEmpty, nullObject } from "../utils.mjs";
4
- import { skipClone } from "./transferable.mjs";
4
+ import { skipClone } from "./skip-clone.mjs";
5
5
  import { serializeCookie } from "../cookie/serialize.mjs";
6
6
 
7
7
  //#region src/adapter/utils.ts
@@ -179,6 +179,26 @@ function createStreamHandler({ mapResponse, mapCompactResponse }) {
179
179
  if (r && typeof r.then === "function") r.catch(() => {});
180
180
  } catch {}
181
181
  };
182
+ const closeSafely = (controller) => {
183
+ try {
184
+ controller.close();
185
+ } catch {}
186
+ cleanupAbort();
187
+ };
188
+ const enqueueValue = async (controller, value) => {
189
+ if (value.toSSE) {
190
+ controller.enqueue(encodeChunk(value.toSSE()));
191
+ return;
192
+ }
193
+ const p = enqueueBinaryChunk(controller, value);
194
+ if (p !== false) return void await p;
195
+ if (typeof value === "object") try {
196
+ controller.enqueue(encodeChunk(format(JSON.stringify(value))));
197
+ } catch {
198
+ controller.enqueue(encodeChunk(format(value.toString())));
199
+ }
200
+ else controller.enqueue(encodeChunk(format(value.toString())));
201
+ };
182
202
  return new Response(new ReadableStream({
183
203
  async start(controller) {
184
204
  if (signal) {
@@ -194,49 +214,21 @@ function createStreamHandler({ mapResponse, mapCompactResponse }) {
194
214
  else signal.addEventListener("abort", onAbort, { once: true });
195
215
  }
196
216
  if (!init || init.value instanceof ReadableStream || init.value === void 0 || init.value === null) return;
197
- if (init.value.toSSE) {
198
- controller.enqueue(encodeChunk(init.value.toSSE()));
199
- return;
200
- }
201
- const p = enqueueBinaryChunk(controller, init.value);
202
- if (p !== false) return void await p;
203
- if (typeof init.value === "object") try {
204
- controller.enqueue(encodeChunk(format(JSON.stringify(init.value))));
205
- } catch {
206
- controller.enqueue(encodeChunk(format(init.value.toString())));
207
- }
208
- else controller.enqueue(encodeChunk(format(init.value.toString())));
217
+ await enqueueValue(controller, init.value);
209
218
  },
210
219
  async pull(controller) {
211
220
  if (end) {
212
- try {
213
- controller.close();
214
- } catch {}
215
- cleanupAbort();
221
+ closeSafely(controller);
216
222
  return;
217
223
  }
218
224
  try {
219
225
  const { value: chunk, done } = await iterator.next();
220
226
  if (done || end) {
221
- try {
222
- controller.close();
223
- } catch {}
224
- cleanupAbort();
227
+ closeSafely(controller);
225
228
  return;
226
229
  }
227
230
  if (chunk === void 0 || chunk === null) return;
228
- if (chunk.toSSE) {
229
- controller.enqueue(encodeChunk(chunk.toSSE()));
230
- return;
231
- }
232
- const p = enqueueBinaryChunk(controller, chunk);
233
- if (p !== false) return void await p;
234
- if (typeof chunk === "object") try {
235
- controller.enqueue(encodeChunk(format(JSON.stringify(chunk))));
236
- } catch {
237
- controller.enqueue(encodeChunk(format(chunk.toString())));
238
- }
239
- else controller.enqueue(encodeChunk(format(chunk.toString())));
231
+ await enqueueValue(controller, chunk);
240
232
  } catch (error) {
241
233
  cleanupAbort();
242
234
  controller.error(error);
@@ -21,7 +21,6 @@ function handleElysiaFile(file, set = { headers: require_utils.nullObject() }, r
21
21
  });
22
22
  return require_adapter_utils.handleFile(file.value, set, request);
23
23
  }
24
- const isNotBun = !require_universal_constants.isBun;
25
24
  function responseTag(response) {
26
25
  if (response === null || response === void 0) return void 0;
27
26
  const proto = Object.getPrototypeOf(response);
@@ -34,7 +33,7 @@ function mapResponse(response, set, request) {
34
33
  const headers = set.headers;
35
34
  switch (responseTag(response)) {
36
35
  case "String":
37
- if (isNotBun && !headers["content-type"]) headers["content-type"] = "text/plain";
36
+ if (!require_universal_constants.isBun && !headers["content-type"]) headers["content-type"] = "text/plain";
38
37
  return new Response(response, set);
39
38
  case "Array": return Response.json(response, set);
40
39
  case "Object":
@@ -68,10 +67,9 @@ function mapResponse(response, set, request) {
68
67
  if (typeof response?.next === "function" || response instanceof ReadableStream) return handleStream(response, set, request);
69
68
  return mapCompactResponse(response, request);
70
69
  }
71
- const stringHeaders = require_universal_constants.isBun ? void 0 : { headers: { "content-type": "text/plain" } };
72
70
  function mapCompactResponse(response, request) {
73
71
  switch (responseTag(response)) {
74
- case "String": return new Response(response, stringHeaders);
72
+ case "String": return new Response(response, require_universal_constants.isBun ? void 0 : { headers: { "content-type": "text/plain" } });
75
73
  case "Array": return Response.json(response);
76
74
  case "Object":
77
75
  if (response["~ely-form"]) return new Response(require_utils.formToFormData(response));
@@ -20,7 +20,6 @@ function handleElysiaFile(file, set = { headers: nullObject() }, request) {
20
20
  });
21
21
  return handleFile(file.value, set, request);
22
22
  }
23
- const isNotBun = !isBun;
24
23
  function responseTag(response) {
25
24
  if (response === null || response === void 0) return void 0;
26
25
  const proto = Object.getPrototypeOf(response);
@@ -33,7 +32,7 @@ function mapResponse(response, set, request) {
33
32
  const headers = set.headers;
34
33
  switch (responseTag(response)) {
35
34
  case "String":
36
- if (isNotBun && !headers["content-type"]) headers["content-type"] = "text/plain";
35
+ if (!isBun && !headers["content-type"]) headers["content-type"] = "text/plain";
37
36
  return new Response(response, set);
38
37
  case "Array": return Response.json(response, set);
39
38
  case "Object":
@@ -67,10 +66,9 @@ function mapResponse(response, set, request) {
67
66
  if (typeof response?.next === "function" || response instanceof ReadableStream) return handleStream(response, set, request);
68
67
  return mapCompactResponse(response, request);
69
68
  }
70
- const stringHeaders = isBun ? void 0 : { headers: { "content-type": "text/plain" } };
71
69
  function mapCompactResponse(response, request) {
72
70
  switch (responseTag(response)) {
73
- case "String": return new Response(response, stringHeaders);
71
+ case "String": return new Response(response, isBun ? void 0 : { headers: { "content-type": "text/plain" } });
74
72
  case "Array": return Response.json(response);
75
73
  case "Object":
76
74
  if (response["~ely-form"]) return new Response(formToFormData(response));
package/dist/base.d.ts CHANGED
@@ -203,10 +203,12 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
203
203
  derive<const Derivative extends Record<string, unknown> | ElysiaStatus<any, any, any> | void>(scope: 'local', transform: (context: Context<HookContextSchema<Metadata, Ephemeral, Volatile, BasePath>, HookContextSingleton<Singleton, Ephemeral, Volatile>>) => MaybePromise<Derivative>): LocalHookReturn<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, ExtractErrorFromHandle<Derivative>, ExcludeElysiaResponse<Derivative>>;
204
204
  derive<const Derivative extends Record<string, unknown> | ElysiaStatus<any, any, any> | void>(scope: 'plugin', transform: (context: LifecycleContext<HookContextSchema<Metadata, Ephemeral, Volatile, BasePath>, HookContextSingleton<Singleton, Ephemeral, Volatile>, undefined, 'plugin'>) => MaybePromise<Derivative>): PluginHookReturn<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, ExtractErrorFromHandle<Derivative>, ExcludeElysiaResponse<Derivative>>;
205
205
  derive<const Derivative extends Record<string, unknown> | ElysiaStatus<any, any, any> | void>(scope: 'global', transform: (context: LifecycleContext<HookContextSchema<Metadata, Ephemeral, Volatile, BasePath>, HookContextSingleton<Singleton, Ephemeral, Volatile>, undefined, 'global'>) => MaybePromise<Derivative>): GlobalHookReturn<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, ExtractErrorFromHandle<Derivative>, ExcludeElysiaResponse<Derivative>>;
206
- mapDerive<const Derivative extends Record<string, unknown> | ElysiaStatus<any, any, any> | void>(transform: (context: Context<HookContextSchema<Metadata, Ephemeral, Volatile, BasePath>, HookContextSingleton<Singleton, Ephemeral, Volatile>>) => MaybePromise<Derivative>): LocalHookReturn<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, ExtractErrorFromHandle<Derivative>, ExcludeElysiaResponse<Derivative>>;
207
- mapDerive<const Derivative extends Record<string, unknown> | ElysiaStatus<any, any, any> | void>(scope: 'local', transform: (context: Context<HookContextSchema<Metadata, Ephemeral, Volatile, BasePath>, HookContextSingleton<Singleton, Ephemeral, Volatile>>) => MaybePromise<Derivative>): LocalHookReturn<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, ExtractErrorFromHandle<Derivative>, ExcludeElysiaResponse<Derivative>>;
208
- mapDerive<const Derivative extends Record<string, unknown> | ElysiaStatus<any, any, any> | void>(scope: 'plugin', transform: (context: LifecycleContext<HookContextSchema<Metadata, Ephemeral, Volatile, BasePath>, HookContextSingleton<Singleton, Ephemeral, Volatile>, undefined, 'plugin'>) => MaybePromise<Derivative>): PluginHookReturn<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, ExtractErrorFromHandle<Derivative>, ExcludeElysiaResponse<Derivative>>;
209
- mapDerive<const Derivative extends Record<string, unknown> | ElysiaStatus<any, any, any> | void>(scope: 'global', transform: (context: LifecycleContext<HookContextSchema<Metadata, Ephemeral, Volatile, BasePath>, HookContextSingleton<Singleton, Ephemeral, Volatile>, undefined, 'global'>) => MaybePromise<Derivative>): GlobalHookReturn<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, ExtractErrorFromHandle<Derivative>, ExcludeElysiaResponse<Derivative>>;
206
+ /**
207
+ * ### mapDerive
208
+ * Alias of {@link derive}. Shares the same implementation at the
209
+ * prototype level (see `Elysia.prototype.mapDerive` after the class).
210
+ */
211
+ mapDerive: this['derive'];
210
212
  afterHandle<const Handler extends MaybeArray<AfterHandler<HookContextSchema<Metadata, Ephemeral, Volatile, BasePath>, HookContextSingleton<Singleton, Ephemeral, Volatile>>>>(fn: Handler): LocalHookReturn<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, ElysiaHandlerToResponseSchemaAmbiguous<Handler>>;
211
213
  afterHandle<const Handler extends MaybeArray<AfterHandler<HookContextSchema<Metadata, Ephemeral, Volatile, BasePath>, HookContextSingleton<Singleton, Ephemeral, Volatile>>>>(scope: 'local', fn: Handler): LocalHookReturn<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, ElysiaHandlerToResponseSchemaAmbiguous<Handler>>;
212
214
  afterHandle<const Handler extends MaybeArray<AfterHandler<HookContextSchema<Metadata, Ephemeral, Volatile, BasePath>, HookContextSingleton<Singleton, Ephemeral, Volatile>, undefined, 'plugin'>>>(scope: 'plugin', fn: Handler): PluginHookReturn<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, ElysiaHandlerToResponseSchemaAmbiguous<Handler>>;
package/dist/base.js CHANGED
@@ -93,31 +93,35 @@ var Elysia = class Elysia {
93
93
  }
94
94
  return this;
95
95
  }
96
- #decorate(as, name, value) {
96
+ #setField(field, as, name, value) {
97
97
  const ext = this.#ext;
98
- const fresh = !ext.decorator;
99
- const decorator = ext.decorator ??= require_utils.nullObject();
98
+ const fresh = !ext[field];
99
+ const target = ext[field] ??= require_utils.nullObject();
100
100
  switch (typeof value) {
101
101
  case "object":
102
- if (value === null || value === void 0) return this;
102
+ if (!value) return this;
103
+ if (!name && require_utils.isEmpty(value)) return this;
103
104
  if (name) {
104
- if (!fresh && name in decorator) decorator[name] = require_utils.mergeDeep(decorator[name], value, void 0, as === "override");
105
- else decorator[name] = value;
105
+ if (!fresh && name in target) target[name] = require_utils.mergeDeep(target[name], value, void 0, as === "override");
106
+ else target[name] = value;
106
107
  return this;
107
108
  }
108
- if (fresh) Object.assign(decorator, value);
109
- else ext.decorator = require_utils.mergeDeep(decorator, value, void 0, as === "override");
109
+ if (fresh) Object.assign(target, value);
110
+ else ext[field] = require_utils.mergeDeep(target, value, void 0, as === "override");
110
111
  return this;
111
112
  case "function":
112
113
  if (name) {
113
- if (as === "override" || !(name in decorator)) decorator[name] = value;
114
- } else ext.decorator = value(decorator);
114
+ if (as === "override" || !(name in target)) target[name] = value;
115
+ } else ext[field] = value(target);
115
116
  return this;
116
117
  default:
117
- if (as === "override" || !(name in decorator)) decorator[name] = value;
118
+ if (as === "override" || !(name in target)) target[name] = value;
118
119
  return this;
119
120
  }
120
121
  }
122
+ #decorate(as, name, value) {
123
+ return this.#setField("decorator", as, name, value);
124
+ }
121
125
  state(typeOrNameOrStore, nameOrStore, value) {
122
126
  switch (arguments.length) {
123
127
  case 1: return this.#state("append", "", typeOrNameOrStore);
@@ -129,30 +133,7 @@ var Elysia = class Elysia {
129
133
  return this;
130
134
  }
131
135
  #state(as, name, value) {
132
- const ext = this.#ext;
133
- const fresh = !ext.store;
134
- const store = ext.store ??= require_utils.nullObject();
135
- switch (typeof value) {
136
- case "object":
137
- if (!value) return this;
138
- if (!name && require_utils.isEmpty(value)) return this;
139
- if (name) {
140
- if (!fresh && name in store) store[name] = require_utils.mergeDeep(store[name], value, void 0, as === "override");
141
- else store[name] = value;
142
- return this;
143
- }
144
- if (fresh) Object.assign(store, value);
145
- else ext.store = require_utils.mergeDeep(store, value, void 0, as === "override");
146
- return this;
147
- case "function":
148
- if (name) {
149
- if (as === "override" || !(name in store)) store[name] = value;
150
- } else ext.store = value(store);
151
- return this;
152
- default:
153
- if (as === "override" || !(name in store)) store[name] = value;
154
- return this;
155
- }
136
+ return this.#setField("store", as, name, value);
156
137
  }
157
138
  headers(headers) {
158
139
  const ext = this.#ext;
@@ -237,9 +218,6 @@ var Elysia = class Elysia {
237
218
  }
238
219
  return result;
239
220
  }
240
- mapDerive(scopeOrFn, fn) {
241
- return this.derive(scopeOrFn, fn);
242
- }
243
221
  afterHandle(scopeOrFn, fn) {
244
222
  return this.#onBranch("afterHandle", scopeOrFn, fn);
245
223
  }
@@ -1297,6 +1275,7 @@ var Elysia = class Elysia {
1297
1275
  return r;
1298
1276
  }
1299
1277
  };
1278
+ Elysia.prototype.mapDerive = Elysia.prototype.derive;
1300
1279
 
1301
1280
  //#endregion
1302
1281
  exports.Elysia = Elysia;
package/dist/base.mjs CHANGED
@@ -90,31 +90,35 @@ var Elysia = class Elysia {
90
90
  }
91
91
  return this;
92
92
  }
93
- #decorate(as, name, value) {
93
+ #setField(field, as, name, value) {
94
94
  const ext = this.#ext;
95
- const fresh = !ext.decorator;
96
- const decorator = ext.decorator ??= nullObject();
95
+ const fresh = !ext[field];
96
+ const target = ext[field] ??= nullObject();
97
97
  switch (typeof value) {
98
98
  case "object":
99
- if (value === null || value === void 0) return this;
99
+ if (!value) return this;
100
+ if (!name && isEmpty(value)) return this;
100
101
  if (name) {
101
- if (!fresh && name in decorator) decorator[name] = mergeDeep(decorator[name], value, void 0, as === "override");
102
- else decorator[name] = value;
102
+ if (!fresh && name in target) target[name] = mergeDeep(target[name], value, void 0, as === "override");
103
+ else target[name] = value;
103
104
  return this;
104
105
  }
105
- if (fresh) Object.assign(decorator, value);
106
- else ext.decorator = mergeDeep(decorator, value, void 0, as === "override");
106
+ if (fresh) Object.assign(target, value);
107
+ else ext[field] = mergeDeep(target, value, void 0, as === "override");
107
108
  return this;
108
109
  case "function":
109
110
  if (name) {
110
- if (as === "override" || !(name in decorator)) decorator[name] = value;
111
- } else ext.decorator = value(decorator);
111
+ if (as === "override" || !(name in target)) target[name] = value;
112
+ } else ext[field] = value(target);
112
113
  return this;
113
114
  default:
114
- if (as === "override" || !(name in decorator)) decorator[name] = value;
115
+ if (as === "override" || !(name in target)) target[name] = value;
115
116
  return this;
116
117
  }
117
118
  }
119
+ #decorate(as, name, value) {
120
+ return this.#setField("decorator", as, name, value);
121
+ }
118
122
  state(typeOrNameOrStore, nameOrStore, value) {
119
123
  switch (arguments.length) {
120
124
  case 1: return this.#state("append", "", typeOrNameOrStore);
@@ -126,30 +130,7 @@ var Elysia = class Elysia {
126
130
  return this;
127
131
  }
128
132
  #state(as, name, value) {
129
- const ext = this.#ext;
130
- const fresh = !ext.store;
131
- const store = ext.store ??= nullObject();
132
- switch (typeof value) {
133
- case "object":
134
- if (!value) return this;
135
- if (!name && isEmpty(value)) return this;
136
- if (name) {
137
- if (!fresh && name in store) store[name] = mergeDeep(store[name], value, void 0, as === "override");
138
- else store[name] = value;
139
- return this;
140
- }
141
- if (fresh) Object.assign(store, value);
142
- else ext.store = mergeDeep(store, value, void 0, as === "override");
143
- return this;
144
- case "function":
145
- if (name) {
146
- if (as === "override" || !(name in store)) store[name] = value;
147
- } else ext.store = value(store);
148
- return this;
149
- default:
150
- if (as === "override" || !(name in store)) store[name] = value;
151
- return this;
152
- }
133
+ return this.#setField("store", as, name, value);
153
134
  }
154
135
  headers(headers) {
155
136
  const ext = this.#ext;
@@ -234,9 +215,6 @@ var Elysia = class Elysia {
234
215
  }
235
216
  return result;
236
217
  }
237
- mapDerive(scopeOrFn, fn) {
238
- return this.derive(scopeOrFn, fn);
239
- }
240
218
  afterHandle(scopeOrFn, fn) {
241
219
  return this.#onBranch("afterHandle", scopeOrFn, fn);
242
220
  }
@@ -1294,6 +1272,7 @@ var Elysia = class Elysia {
1294
1272
  return r;
1295
1273
  }
1296
1274
  };
1275
+ Elysia.prototype.mapDerive = Elysia.prototype.derive;
1297
1276
 
1298
1277
  //#endregion
1299
1278
  export { Elysia };
@@ -227,10 +227,5 @@ declare const Capture: {
227
227
  readonly isCapturing: () => boolean;
228
228
  readonly isAotBuildEnv: () => boolean;
229
229
  };
230
- /**
231
- * Reset module-level capture lifecycle state.
232
- * FOR TESTS ONLY
233
- */
234
- declare const resetCaptureLifecycleForTests: () => void;
235
230
  //#endregion
236
- export { Capture, CapturedHandler, CapturedMirror, CapturedValidator, CheckBuildResult, Compiled, CompiledSnapshot, EMPTY_EXTERNALS, FrozenBothFactory, FrozenCheckFactory, FrozenHandler, FrozenMirror, FrozenMirrorFactory, FrozenValidator, HandlerManifest, Source, StringCodecNode, ValidatorManifest, ValidatorSlot, beginValidatorCapture, collectExternals, collectMirrorUnions, collectStringCodecNodes, endHandlerCapture, endValidatorCapture, externalsMatch, instantiateFrozenBoth, instantiateFrozenDecodeMirror, instantiateFrozenEncodeMirror, instantiateFrozenMirror, reconstructCheck, reconstructInnerCodecs, resetCaptureLifecycleForTests };
231
+ export { Capture, CapturedHandler, CapturedMirror, CapturedValidator, CheckBuildResult, Compiled, CompiledSnapshot, EMPTY_EXTERNALS, FrozenBothFactory, FrozenCheckFactory, FrozenHandler, FrozenMirror, FrozenMirrorFactory, FrozenValidator, HandlerManifest, Source, StringCodecNode, ValidatorManifest, ValidatorSlot, beginValidatorCapture, collectExternals, collectMirrorUnions, collectStringCodecNodes, endHandlerCapture, endValidatorCapture, externalsMatch, instantiateFrozenBoth, instantiateFrozenDecodeMirror, instantiateFrozenEncodeMirror, instantiateFrozenMirror, reconstructCheck, reconstructInnerCodecs };
@@ -344,11 +344,6 @@ const Capture = {
344
344
  isCapturing: isValidatorCapturing,
345
345
  isAotBuildEnv
346
346
  };
347
- /**
348
- * Reset module-level capture lifecycle state.
349
- * FOR TESTS ONLY
350
- */
351
- const resetCaptureLifecycleForTests = () => void 0;
352
347
 
353
348
  //#endregion
354
349
  exports.Capture = Capture;
@@ -367,5 +362,4 @@ exports.instantiateFrozenDecodeMirror = instantiateFrozenDecodeMirror;
367
362
  exports.instantiateFrozenEncodeMirror = instantiateFrozenEncodeMirror;
368
363
  exports.instantiateFrozenMirror = instantiateFrozenMirror;
369
364
  exports.reconstructCheck = reconstructCheck;
370
- exports.reconstructInnerCodecs = reconstructInnerCodecs;
371
- exports.resetCaptureLifecycleForTests = resetCaptureLifecycleForTests;
365
+ exports.reconstructInnerCodecs = reconstructInnerCodecs;
@@ -343,11 +343,6 @@ const Capture = {
343
343
  isCapturing: isValidatorCapturing,
344
344
  isAotBuildEnv
345
345
  };
346
- /**
347
- * Reset module-level capture lifecycle state.
348
- * FOR TESTS ONLY
349
- */
350
- const resetCaptureLifecycleForTests = () => void 0;
351
346
 
352
347
  //#endregion
353
- export { Capture, Compiled, EMPTY_EXTERNALS, Source, beginValidatorCapture, collectExternals, collectMirrorUnions, collectStringCodecNodes, endHandlerCapture, endValidatorCapture, externalsMatch, instantiateFrozenBoth, instantiateFrozenDecodeMirror, instantiateFrozenEncodeMirror, instantiateFrozenMirror, reconstructCheck, reconstructInnerCodecs, resetCaptureLifecycleForTests };
348
+ export { Capture, Compiled, EMPTY_EXTERNALS, Source, beginValidatorCapture, collectExternals, collectMirrorUnions, collectStringCodecNodes, endHandlerCapture, endValidatorCapture, externalsMatch, instantiateFrozenBoth, instantiateFrozenDecodeMirror, instantiateFrozenEncodeMirror, instantiateFrozenMirror, reconstructCheck, reconstructInnerCodecs };
@@ -3,6 +3,7 @@ const require_utils = require('../../utils.js');
3
3
  const require_type_constants = require('../../type/constants.js');
4
4
  const require_error = require('../../error.js');
5
5
  const require_compile_aot = require('../aot.js');
6
+ const require_type_validator_clean_safe = require('../../type/validator/clean-safe.js');
6
7
 
7
8
  //#region src/compile/handler/frozen-validator.ts
8
9
  const isBridgeNotInitialized = (error) => error instanceof Error && error.message.startsWith("Typebox module isn't initialized");
@@ -22,42 +23,9 @@ function isBridgeFreeComplete(f, schema, raw) {
22
23
  if (codecCoercionBridgeFree(f, schema, raw)) return true;
23
24
  if (f.e === 1 || f.u || f.dm || f.em || f.k === 1 || f.ce || f.ic || f.a === 1) return false;
24
25
  if (f.d === 1 && f.ps !== 1) return false;
25
- if (isFullyClosedObject(schema)) return false;
26
+ if (require_type_validator_clean_safe.isFullyClosedObject(schema)) return false;
26
27
  return true;
27
28
  }
28
- function isCleanSafeNode(node, visiting, clean) {
29
- if (!node || typeof node !== "object") return true;
30
- if (clean.has(node)) return true;
31
- if (visiting.has(node)) return false;
32
- visiting.add(node);
33
- const safe = checkCleanSafeNode(node, visiting, clean);
34
- visiting.delete(node);
35
- if (safe) clean.add(node);
36
- return safe;
37
- }
38
- function checkCleanSafeNode(node, visiting, clean) {
39
- if (node["~codec"] || node["~refine"] || node["~elyTyp"] !== void 0) return false;
40
- const kind = node["~kind"];
41
- if (kind === "Union" || kind === "Intersect" || kind === "Ref" || kind === "This" || kind === "Cyclic" || node.$ref !== void 0 || Array.isArray(node.anyOf) || Array.isArray(node.allOf) || Array.isArray(node.oneOf) || node.not !== void 0 || node.if !== void 0 || node.patternProperties !== void 0) return false;
42
- if (kind === "Object" || node.type === "object") {
43
- if (node.additionalProperties !== false) return false;
44
- if (node.properties) {
45
- for (const k in node.properties) if (Object.hasOwn(node.properties, k) && !isCleanSafeNode(node.properties[k], visiting, clean)) return false;
46
- }
47
- return true;
48
- }
49
- if (kind === "Array" || node.type === "array") {
50
- const items = node.items;
51
- if (Array.isArray(items) || items === void 0) return false;
52
- return isCleanSafeNode(items, visiting, clean);
53
- }
54
- return true;
55
- }
56
- function isFullyClosedObject(schema) {
57
- if (!schema || typeof schema !== "object") return false;
58
- if (schema["~kind"] !== "Object" && schema.type !== "object") return false;
59
- return isCleanSafeNode(schema, /* @__PURE__ */ new WeakSet(), /* @__PURE__ */ new WeakSet());
60
- }
61
29
  var FrozenSlotValidator = class {
62
30
  #check;
63
31
  #clean;
@@ -199,7 +167,7 @@ function isCapturedBridgeFree(c, schema, coerced = schema) {
199
167
  if (c.hasCodec && !!c.decodeMirror && !c.encodeMirror && !c.customErrors?.length && !c.async && !(c.hasDefault && !c.precomputeSafe)) return innerCodecsAligned(c.innerCodecs?.length, coerced) && mirrorUnionsAligned(c.mirror.u, schema) && mirrorUnionsAligned(c.decodeMirror.u, coerced);
200
168
  if (c.external || c.mirror.u || c.decodeMirror || c.encodeMirror || c.hasCodec || c.customErrors?.length || c.innerCodecs?.length || c.async) return false;
201
169
  if (c.hasDefault && !c.precomputeSafe) return false;
202
- if (isFullyClosedObject(schema)) return false;
170
+ if (require_type_validator_clean_safe.isFullyClosedObject(schema)) return false;
203
171
  return true;
204
172
  }
205
173
 
@@ -2,6 +2,7 @@ import { nullObject } from "../../utils.mjs";
2
2
  import { ELYSIA_TYPES } from "../../type/constants.mjs";
3
3
  import { ValidationError } from "../../error.mjs";
4
4
  import { Compiled, EMPTY_EXTERNALS, collectMirrorUnions, collectStringCodecNodes, instantiateFrozenBoth, instantiateFrozenDecodeMirror, reconstructInnerCodecs } from "../aot.mjs";
5
+ import { isFullyClosedObject } from "../../type/validator/clean-safe.mjs";
5
6
 
6
7
  //#region src/compile/handler/frozen-validator.ts
7
8
  const isBridgeNotInitialized = (error) => error instanceof Error && error.message.startsWith("Typebox module isn't initialized");
@@ -24,39 +25,6 @@ function isBridgeFreeComplete(f, schema, raw) {
24
25
  if (isFullyClosedObject(schema)) return false;
25
26
  return true;
26
27
  }
27
- function isCleanSafeNode(node, visiting, clean) {
28
- if (!node || typeof node !== "object") return true;
29
- if (clean.has(node)) return true;
30
- if (visiting.has(node)) return false;
31
- visiting.add(node);
32
- const safe = checkCleanSafeNode(node, visiting, clean);
33
- visiting.delete(node);
34
- if (safe) clean.add(node);
35
- return safe;
36
- }
37
- function checkCleanSafeNode(node, visiting, clean) {
38
- if (node["~codec"] || node["~refine"] || node["~elyTyp"] !== void 0) return false;
39
- const kind = node["~kind"];
40
- if (kind === "Union" || kind === "Intersect" || kind === "Ref" || kind === "This" || kind === "Cyclic" || node.$ref !== void 0 || Array.isArray(node.anyOf) || Array.isArray(node.allOf) || Array.isArray(node.oneOf) || node.not !== void 0 || node.if !== void 0 || node.patternProperties !== void 0) return false;
41
- if (kind === "Object" || node.type === "object") {
42
- if (node.additionalProperties !== false) return false;
43
- if (node.properties) {
44
- for (const k in node.properties) if (Object.hasOwn(node.properties, k) && !isCleanSafeNode(node.properties[k], visiting, clean)) return false;
45
- }
46
- return true;
47
- }
48
- if (kind === "Array" || node.type === "array") {
49
- const items = node.items;
50
- if (Array.isArray(items) || items === void 0) return false;
51
- return isCleanSafeNode(items, visiting, clean);
52
- }
53
- return true;
54
- }
55
- function isFullyClosedObject(schema) {
56
- if (!schema || typeof schema !== "object") return false;
57
- if (schema["~kind"] !== "Object" && schema.type !== "object") return false;
58
- return isCleanSafeNode(schema, /* @__PURE__ */ new WeakSet(), /* @__PURE__ */ new WeakSet());
59
- }
60
28
  var FrozenSlotValidator = class {
61
29
  #check;
62
30
  #clean;