elysia 2.0.0-beta.12 → 2.0.0-beta.13

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 (51) hide show
  1. package/dist/adapter/bun/index.js +28 -17
  2. package/dist/adapter/bun/index.mjs +28 -17
  3. package/dist/adapter/utils.js +1 -0
  4. package/dist/adapter/utils.mjs +1 -0
  5. package/dist/adapter/web-standard/handler.js +2 -2
  6. package/dist/adapter/web-standard/handler.mjs +2 -2
  7. package/dist/compile/aot-emit.js +1 -1
  8. package/dist/compile/aot-emit.mjs +1 -1
  9. package/dist/compile/aot.d.ts +1 -1
  10. package/dist/compile/aot.js +2 -2
  11. package/dist/compile/aot.mjs +2 -2
  12. package/dist/compile/handler/descriptor.d.ts +2 -3
  13. package/dist/compile/handler/descriptor.js +6 -16
  14. package/dist/compile/handler/descriptor.mjs +7 -16
  15. package/dist/compile/handler/index.d.ts +1 -1
  16. package/dist/compile/handler/index.js +15 -6
  17. package/dist/compile/handler/index.mjs +15 -6
  18. package/dist/compile/handler/jit.js +71 -66
  19. package/dist/compile/handler/jit.mjs +72 -67
  20. package/dist/compile/handler/params.js +3 -2
  21. package/dist/compile/handler/params.mjs +4 -3
  22. package/dist/compile/handler/static-clone-resolver.d.ts +6 -0
  23. package/dist/compile/handler/static-clone-resolver.js +8 -0
  24. package/dist/compile/handler/static-clone-resolver.mjs +7 -0
  25. package/dist/compile/handler/utils.d.ts +7 -6
  26. package/dist/compile/handler/utils.js +23 -18
  27. package/dist/compile/handler/utils.mjs +23 -19
  28. package/dist/compile/utils.js +7 -4
  29. package/dist/compile/utils.mjs +7 -4
  30. package/dist/cookie/lib.js +2 -1
  31. package/dist/cookie/lib.mjs +2 -1
  32. package/dist/cookie/utils.d.ts +1 -1
  33. package/dist/cookie/utils.js +9 -23
  34. package/dist/cookie/utils.mjs +9 -23
  35. package/dist/handler/error.js +3 -4
  36. package/dist/handler/error.mjs +3 -4
  37. package/dist/handler/fetch.js +17 -13
  38. package/dist/handler/fetch.mjs +17 -13
  39. package/dist/package.js +1 -1
  40. package/dist/package.mjs +1 -1
  41. package/dist/plugin/aot/core.d.ts +2 -0
  42. package/dist/plugin/aot/core.js +6 -0
  43. package/dist/plugin/aot/core.mjs +6 -0
  44. package/dist/plugin/aot/hooks.js +5 -1
  45. package/dist/plugin/aot/hooks.mjs +5 -1
  46. package/dist/trace.js +14 -5
  47. package/dist/trace.mjs +14 -5
  48. package/dist/type/constants.d.ts +1 -1
  49. package/dist/types.d.ts +5 -4
  50. package/dist/utils.d.ts +0 -1
  51. package/package.json +4 -4
@@ -22,6 +22,7 @@ const createAotPluginHooks = (entry, options, moduleCondition = require_plugin_a
22
22
  let virtualType;
23
23
  let stub = { ...require_plugin_aot_core.NO_STUB };
24
24
  let isElysiaModule = (_path) => false;
25
+ let packageRoot = "";
25
26
  return {
26
27
  async buildStart() {
27
28
  const generated = initial ? await require_plugin_aot_core.generateCompiledArtifacts(entry, options, moduleCondition) : await require_plugin_aot_core.generateCompiledArtifactsIsolated(entry, options, moduleCondition);
@@ -29,7 +30,9 @@ const createAotPluginHooks = (entry, options, moduleCondition = require_plugin_a
29
30
  source = generated.source;
30
31
  stub = generated.stub;
31
32
  virtualType = generated.virtualType;
32
- isElysiaModule = require_plugin_aot_core.makeIsElysiaModule(require_plugin_aot_core.resolveElysiaRoot(entryPath));
33
+ const pkgRoot = require_plugin_aot_core.resolveElysiaRoot(entryPath);
34
+ isElysiaModule = require_plugin_aot_core.makeIsElysiaModule(pkgRoot);
35
+ packageRoot = toPosix(pkgRoot);
33
36
  },
34
37
  buildEnd() {
35
38
  if (!entryMatched) throw new Error(`[elysia-aot] entry "${entry}" never appeared in the Vite module graph. Compiled manifest was not injected. Check that the plugin entry matches a build input.`);
@@ -46,6 +49,7 @@ const createAotPluginHooks = (entry, options, moduleCondition = require_plugin_a
46
49
  const cleanId = id.split("?", 1)[0];
47
50
  for (const key of Object.keys(require_plugin_aot_core.STUB_SOURCES)) {
48
51
  if (!stub[key]) continue;
52
+ if (key === "staticClone" && (!isElysiaModule(cleanId) || !/^(dist|src)\/compile\/handler\/static-clone-resolver\.(m?js|ts)$/.test(toPosix(cleanId).slice(packageRoot.length + 1)))) continue;
49
53
  for (const { filter, source: stubSource } of require_plugin_aot_core.STUB_SOURCES[key]) if (filter.test(cleanId)) return require_plugin_aot_core.alignStubExtensions(stubSource, cleanId);
50
54
  }
51
55
  if (stub.adapter !== false && require_plugin_aot_core.ADAPTER_CONSTANTS_FILTER.test(cleanId)) return require_plugin_aot_core.alignStubExtensions(require_plugin_aot_core.adapterConstantsSource(stub.adapter), cleanId);
@@ -21,6 +21,7 @@ const createAotPluginHooks = (entry, options, moduleCondition = resolveEntryModu
21
21
  let virtualType;
22
22
  let stub = { ...NO_STUB };
23
23
  let isElysiaModule = (_path) => false;
24
+ let packageRoot = "";
24
25
  return {
25
26
  async buildStart() {
26
27
  const generated = initial ? await generateCompiledArtifacts(entry, options, moduleCondition) : await generateCompiledArtifactsIsolated(entry, options, moduleCondition);
@@ -28,7 +29,9 @@ const createAotPluginHooks = (entry, options, moduleCondition = resolveEntryModu
28
29
  source = generated.source;
29
30
  stub = generated.stub;
30
31
  virtualType = generated.virtualType;
31
- isElysiaModule = makeIsElysiaModule(resolveElysiaRoot(entryPath));
32
+ const pkgRoot = resolveElysiaRoot(entryPath);
33
+ isElysiaModule = makeIsElysiaModule(pkgRoot);
34
+ packageRoot = toPosix(pkgRoot);
32
35
  },
33
36
  buildEnd() {
34
37
  if (!entryMatched) throw new Error(`[elysia-aot] entry "${entry}" never appeared in the Vite module graph. Compiled manifest was not injected. Check that the plugin entry matches a build input.`);
@@ -45,6 +48,7 @@ const createAotPluginHooks = (entry, options, moduleCondition = resolveEntryModu
45
48
  const cleanId = id.split("?", 1)[0];
46
49
  for (const key of Object.keys(STUB_SOURCES)) {
47
50
  if (!stub[key]) continue;
51
+ if (key === "staticClone" && (!isElysiaModule(cleanId) || !/^(dist|src)\/compile\/handler\/static-clone-resolver\.(m?js|ts)$/.test(toPosix(cleanId).slice(packageRoot.length + 1)))) continue;
48
52
  for (const { filter, source: stubSource } of STUB_SOURCES[key]) if (filter.test(cleanId)) return alignStubExtensions(stubSource, cleanId);
49
53
  }
50
54
  if (stub.adapter !== false && ADAPTER_CONSTANTS_FILTER.test(cleanId)) return alignStubExtensions(adapterConstantsSource(stub.adapter), cleanId);
package/dist/trace.js CHANGED
@@ -4,6 +4,15 @@ const require_compile_lexer = require('./compile/lexer.js');
4
4
  const require_sucrose = require('./sucrose.js');
5
5
 
6
6
  //#region src/trace.ts
7
+ const withResolvers = typeof Promise.withResolvers === "function" ? Promise.withResolvers.bind(Promise) : function withResolvers() {
8
+ let resolve;
9
+ return {
10
+ promise: new Promise((r) => {
11
+ resolve = r;
12
+ }),
13
+ resolve
14
+ };
15
+ };
7
16
  const phaseGetter = {
8
17
  onRequest: "request",
9
18
  onParse: "parse",
@@ -162,7 +171,7 @@ var TraceRecorder = class {
162
171
  listen() {
163
172
  if (this.listenFn) return this.listenFn;
164
173
  if (this.begun) return this.listenFn = (_callback) => Promise.resolve(this.#result());
165
- const { promise, resolve } = Promise.withResolvers();
174
+ const { promise, resolve } = withResolvers();
166
175
  this.pendingPromise = promise;
167
176
  this.pendingResolve = resolve;
168
177
  return this.listenFn = (callback) => {
@@ -193,7 +202,7 @@ var TraceRecorder = class {
193
202
  #end() {
194
203
  if (this.endPromise) return this.endPromise;
195
204
  if (this.ended) return this.endPromise = Promise.resolve(this.endTime);
196
- const { promise, resolve } = Promise.withResolvers();
205
+ const { promise, resolve } = withResolvers();
197
206
  this.endPromise = promise;
198
207
  this.endResolve = resolve;
199
208
  return promise;
@@ -201,7 +210,7 @@ var TraceRecorder = class {
201
210
  #error() {
202
211
  if (this.errorPromise) return this.errorPromise;
203
212
  if (this.ended) return this.errorPromise = Promise.resolve(this.endError);
204
- const { promise, resolve } = Promise.withResolvers();
213
+ const { promise, resolve } = withResolvers();
205
214
  this.errorPromise = promise;
206
215
  this.errorResolve = resolve;
207
216
  return promise;
@@ -232,8 +241,8 @@ var TraceRecorder = class {
232
241
  const index = this.childIndex++;
233
242
  const recorder = this;
234
243
  return (process) => {
235
- const { promise: end, resolve: resolveEnd } = Promise.withResolvers();
236
- const { promise: error, resolve: resolveError } = Promise.withResolvers();
244
+ const { promise: end, resolve: resolveEnd } = withResolvers();
245
+ const { promise: error, resolve: resolveError } = withResolvers();
237
246
  const callbacksEnd = [];
238
247
  const result = {
239
248
  ...process,
package/dist/trace.mjs CHANGED
@@ -3,6 +3,15 @@ import { isIdentCharCode } from "./compile/lexer.mjs";
3
3
  import { findAlias, retrieveRootparameters, separateFunction } from "./sucrose.mjs";
4
4
 
5
5
  //#region src/trace.ts
6
+ const withResolvers = typeof Promise.withResolvers === "function" ? Promise.withResolvers.bind(Promise) : function withResolvers() {
7
+ let resolve;
8
+ return {
9
+ promise: new Promise((r) => {
10
+ resolve = r;
11
+ }),
12
+ resolve
13
+ };
14
+ };
6
15
  const phaseGetter = {
7
16
  onRequest: "request",
8
17
  onParse: "parse",
@@ -161,7 +170,7 @@ var TraceRecorder = class {
161
170
  listen() {
162
171
  if (this.listenFn) return this.listenFn;
163
172
  if (this.begun) return this.listenFn = (_callback) => Promise.resolve(this.#result());
164
- const { promise, resolve } = Promise.withResolvers();
173
+ const { promise, resolve } = withResolvers();
165
174
  this.pendingPromise = promise;
166
175
  this.pendingResolve = resolve;
167
176
  return this.listenFn = (callback) => {
@@ -192,7 +201,7 @@ var TraceRecorder = class {
192
201
  #end() {
193
202
  if (this.endPromise) return this.endPromise;
194
203
  if (this.ended) return this.endPromise = Promise.resolve(this.endTime);
195
- const { promise, resolve } = Promise.withResolvers();
204
+ const { promise, resolve } = withResolvers();
196
205
  this.endPromise = promise;
197
206
  this.endResolve = resolve;
198
207
  return promise;
@@ -200,7 +209,7 @@ var TraceRecorder = class {
200
209
  #error() {
201
210
  if (this.errorPromise) return this.errorPromise;
202
211
  if (this.ended) return this.errorPromise = Promise.resolve(this.endError);
203
- const { promise, resolve } = Promise.withResolvers();
212
+ const { promise, resolve } = withResolvers();
204
213
  this.errorPromise = promise;
205
214
  this.errorResolve = resolve;
206
215
  return promise;
@@ -231,8 +240,8 @@ var TraceRecorder = class {
231
240
  const index = this.childIndex++;
232
241
  const recorder = this;
233
242
  return (process) => {
234
- const { promise: end, resolve: resolveEnd } = Promise.withResolvers();
235
- const { promise: error, resolve: resolveError } = Promise.withResolvers();
243
+ const { promise: end, resolve: resolveEnd } = withResolvers();
244
+ const { promise: error, resolve: resolveError } = withResolvers();
236
245
  const callbacksEnd = [];
237
246
  const result = {
238
247
  ...process,
@@ -17,7 +17,7 @@ declare const ELYSIA_TYPES: {
17
17
  readonly NoValidate: 15;
18
18
  };
19
19
  type ELYSIA_TYPES = typeof ELYSIA_TYPES;
20
- declare const primitiveElysiaTypes: Set<1 | 2 | 6 | 3 | 10 | 11 | 13 | 14>;
20
+ declare const primitiveElysiaTypes: Set<2 | 1 | 6 | 3 | 10 | 11 | 13 | 14>;
21
21
  declare const noEnumerable: {
22
22
  readonly enumerable: false;
23
23
  };
package/dist/types.d.ts CHANGED
@@ -9,7 +9,7 @@ import { Context, ErrorContext, LifecycleContext, PreContext } from "./context.j
9
9
  import { AnySchema, StandardSchemaV1Like, TypeBoxSchema } from "./type/types.js";
10
10
  import { AnyElysia, Elysia } from "./base.js";
11
11
  import { ElysiaAdapter } from "./adapter/index.js";
12
- import { Static, StaticDecode, StaticEncode, TIntersect, TObject, TSchema } from "typebox";
12
+ import { Static, StaticDecode, StaticEncode, TIntersect, TObject, TRef, TSchema } from "typebox";
13
13
  import { OpenAPIV3 } from "openapi-types";
14
14
 
15
15
  //#region src/types.d.ts
@@ -635,11 +635,12 @@ type ContextAppendType = 'append' | 'override';
635
635
  type OptionalField = {
636
636
  '~optional': true;
637
637
  };
638
+ type IsOptionalRoot<Schema, Definitions, Seen extends string = never> = Schema extends OptionalField ? true : Schema extends TRef<infer Ref> ? Ref extends Seen ? false : Ref extends keyof Definitions ? IsOptionalRoot<Definitions[Ref], Definitions, Seen | Ref> : false : false;
638
639
  type StaticCyclic<T extends TypeBoxSchema, Definitions extends Record<string, AnySchema>> = {} extends Definitions ? StaticDecode<T> : StaticDecode<T, Definitions>;
639
- type UnwrapSchema<Schema extends AnySchema | string | undefined, Definitions extends DefinitionBase['typebox'] = {}> = Schema extends undefined ? unknown : Schema extends TypeBoxSchema ? Schema extends OptionalField ? Partial<StaticCyclic<Schema, Definitions>> : StaticCyclic<Schema, Definitions> : Schema extends StandardSchemaV1Like ? NonNullable<Schema['~standard']['types']>['output'] : Schema extends string ? Schema extends keyof Definitions ? Definitions[Schema] extends TypeBoxSchema ? StaticCyclic<Definitions[Schema], Definitions> : Definitions[Schema] extends StandardSchemaV1Like ? NonNullable<Definitions[Schema]['~standard']['types']>['output'] : unknown : unknown : unknown;
640
- type UnwrapBodySchema<Schema extends AnySchema | string | undefined, Definitions extends DefinitionBase['typebox'] = {}> = undefined extends Schema ? unknown : Schema extends TypeBoxSchema ? Schema extends OptionalField ? Partial<StaticCyclic<Schema, Definitions>> | null : StaticCyclic<Schema, Definitions> : Schema extends StandardSchemaV1Like ? NonNullable<Schema['~standard']['types']>['output'] : Schema extends string ? Schema extends keyof Definitions ? Definitions[Schema] extends TypeBoxSchema ? StaticCyclic<Definitions[Schema], Definitions> : Definitions[Schema] extends StandardSchemaV1Like ? NonNullable<Definitions[Schema]['~standard']['types']>['output'] : unknown : unknown : unknown;
640
+ type UnwrapSchema<Schema extends AnySchema | string | undefined, Definitions extends DefinitionBase['typebox'] = {}> = Schema extends undefined ? unknown : Schema extends TypeBoxSchema ? true extends IsOptionalRoot<Schema, Definitions> ? Partial<StaticCyclic<Schema, Definitions>> : StaticCyclic<Schema, Definitions> : Schema extends StandardSchemaV1Like ? NonNullable<Schema['~standard']['types']>['output'] : Schema extends string ? Schema extends keyof Definitions ? Definitions[Schema] extends TypeBoxSchema ? true extends IsOptionalRoot<Definitions[Schema], Definitions> ? Partial<StaticCyclic<Definitions[Schema], Definitions>> : StaticCyclic<Definitions[Schema], Definitions> : Definitions[Schema] extends StandardSchemaV1Like ? NonNullable<Definitions[Schema]['~standard']['types']>['output'] : unknown : unknown : unknown;
641
+ type UnwrapBodySchema<Schema extends AnySchema | string | undefined, Definitions extends DefinitionBase['typebox'] = {}> = undefined extends Schema ? unknown : Schema extends TypeBoxSchema ? true extends IsOptionalRoot<Schema, Definitions> ? Partial<StaticCyclic<Schema, Definitions>> | null | undefined : StaticCyclic<Schema, Definitions> : Schema extends StandardSchemaV1Like ? NonNullable<Schema['~standard']['types']>['output'] : Schema extends string ? Schema extends keyof Definitions ? Definitions[Schema] extends TypeBoxSchema ? true extends IsOptionalRoot<Definitions[Schema], Definitions> ? Partial<StaticCyclic<Definitions[Schema], Definitions>> | null | undefined : StaticCyclic<Definitions[Schema], Definitions> : Definitions[Schema] extends StandardSchemaV1Like ? NonNullable<Definitions[Schema]['~standard']['types']>['output'] : unknown : unknown : unknown;
641
642
  type FormInnerProperties<Schema> = Extract<Schema extends TIntersect<infer Members> ? Members[number] : never, TObject>['properties'];
642
- type UnwrapResponseSchema<Schema extends AnySchema | string | undefined, Definitions extends DefinitionBase['typebox'] = {}> = Schema extends TypeBoxSchema ? StaticEncode<Schema> extends ElysiaFormData<any> ? ElysiaFormData<{ [K in keyof FormInnerProperties<Schema>]: Static<FormInnerProperties<Schema>[K] & TSchema> }> : UnwrapSchema<Schema, Definitions> : Schema extends StandardSchemaV1Like ? NonNullable<Schema['~standard']['types']>['input'] : Schema extends string ? Schema extends keyof Definitions ? Definitions[Schema] extends TypeBoxSchema ? StaticCyclic<Definitions[Schema], Definitions> : Definitions[Schema] extends StandardSchemaV1Like ? NonNullable<Definitions[Schema]['~standard']['types']>['input'] : unknown : unknown : unknown;
643
+ type UnwrapResponseSchema<Schema extends AnySchema | string | undefined, Definitions extends DefinitionBase['typebox'] = {}> = Schema extends TypeBoxSchema ? StaticEncode<Schema> extends ElysiaFormData<any> ? ElysiaFormData<{ [K in keyof FormInnerProperties<Schema>]: Static<FormInnerProperties<Schema>[K] & TSchema> }> : Schema extends OptionalField ? Partial<StaticCyclic<Schema, Definitions>> : StaticCyclic<Schema, Definitions> : Schema extends StandardSchemaV1Like ? NonNullable<Schema['~standard']['types']>['input'] : Schema extends string ? Schema extends keyof Definitions ? Definitions[Schema] extends TypeBoxSchema ? StaticCyclic<Definitions[Schema], Definitions> : Definitions[Schema] extends StandardSchemaV1Like ? NonNullable<Definitions[Schema]['~standard']['types']>['input'] : unknown : unknown : unknown;
643
644
  interface UnwrapRoute<in out Schema extends InputSchema<any>, in out Definitions extends DefinitionBase['typebox'] = {}, in out Path extends string = ''> {
644
645
  body: UnwrapBodySchema<Schema['body'], Definitions>;
645
646
  headers: UnwrapSchema<Schema['headers'], Definitions>;
package/dist/utils.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { AnyLocalHook, AppHook, ElysiaFormData, EventFn, EventScope, GuardSchemaType, InputSchema, Macro, MaybeArray, Prettify, SSEPayload } from "./types.js";
2
2
  import { Context } from "./context.js";
3
3
  import { AnySchema, StandardSchemaV1Like } from "./type/types.js";
4
-
5
4
  //#region src/utils.d.ts
6
5
  type DeriveEntry = Function | readonly [Function, 'mapDerive'];
7
6
  declare const nullObject: () => any;
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-beta.12",
4
+ "version": "2.0.0-beta.13",
5
5
  "author": {
6
6
  "name": "saltyAom",
7
7
  "url": "https://github.com/SaltyAom",
@@ -224,7 +224,7 @@
224
224
  "license": "MIT",
225
225
  "scripts": {
226
226
  "test": "bun run test:functionality && bun run test:types && bun run test:node && bun run test:bundle && bun run test:type-perf",
227
- "test:functionality": "bun run build && bun test test && bun run test:imports",
227
+ "test:functionality": "bun run build && bun test ./test && bun run test:imports",
228
228
  "test:imports": "bun run test/type-system/import.ts",
229
229
  "test:types": "tsc --project tsconfig.test.json",
230
230
  "test:node": "bun run build && npm install --prefix test/node/cjs && npm install --prefix test/node/esm/ && node test/node/cjs/index.js && node test/node/esm/index.js",
@@ -269,7 +269,7 @@
269
269
  "esbuild": "0.25.4",
270
270
  "eslint": "^9.24.0",
271
271
  "eslint-plugin-sonarjs": "^4.0.2",
272
- "exact-mirror": "^1.2.4",
272
+ "exact-mirror": "^1.2.6",
273
273
  "expect-type": "^1.2.1",
274
274
  "file-type": "^22.0.0",
275
275
  "globals": "^17.4.0",
@@ -285,7 +285,7 @@
285
285
  },
286
286
  "peerDependencies": {
287
287
  "@types/bun": ">= 1.3.0",
288
- "exact-mirror": ">= 1.2.2",
288
+ "exact-mirror": ">= 1.2.6",
289
289
  "openapi-types": ">= 12.0.0",
290
290
  "typebox": ">= 1.3.0",
291
291
  "typescript": ">= 5.7.0"