elysia 2.0.0-exp.36 → 2.0.0-exp.38

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/base.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { ElysiaStatus } from "./error.js";
2
2
  import { TraceHandler } from "./trace.js";
3
- import { AnySchema } from "./type/types.js";
4
3
  import { ListenCallback, Serve, Server } from "./universal/server.js";
5
4
  import { AddRoute, AddWSRoute, AfterHandler, AfterResponseHandler, AnyErrorConstructor, AnyLocalHook, BodyHandler, CompiledHandler, CreateEden, DefaultEphemeral, DefaultMetadata, DefaultSingleton, DefinitionBase, DocumentDecoration, ElysiaConfig, ElysiaHandlerToResponseSchemaAmbiguous, EphemeralType, ErrorDefinitionEntry, ErrorHandler, EventScope, ExcludeElysiaResponse, ExtractErrorFromHandle, GlobalHookReturn, GracefulHandler, GuardHookSingleton, GuardLocalHook, HTTPMethod, HookContextSchema, HookContextSingleton, InlineHandler, InlineHandlerNonMacro, InputSchema, InputSchemaKey, InternalRoute, IntersectIfObjectSchema, JoinPath, LocalHook, LocalHookReturn, Macro, MacroSchemaChannel, MacroToContext, MacroToProperty, MapResponse, MaybeArray, MaybePromise, MergeElysiaInstances, MergeSchema, MergeScopedSchemas, MetadataBase, NonResolvableMacroKey, ObjectMacroDefs, OptionalHandler, PluginHookReturn, PreHandler, Prettify, PublicRoute, ResolveRouteErrors, RouteBase, SingletonBase, TransformHandler, UnionResponseStatus, UnwrapRoute, WrapFn } from "./types.js";
5
+ import { AnySchema } from "./type/types.js";
6
6
  import { ChainNode } from "./utils.js";
7
7
  import { Context, ErrorContext, LifecycleContext } from "./context.js";
8
8
  import { WSHandlerResponse, WSLocalHook, WSMessageHandler } from "./ws/types.js";
@@ -523,9 +523,9 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
523
523
  * .get('/', ({ user }) => user, { auth: true, role: 'admin' })
524
524
  * ```
525
525
  */
526
- macro<const Body extends MacroSchemaChannel<Definitions>, const Headers extends MacroSchemaChannel<Definitions>, const Query extends MacroSchemaChannel<Definitions>, const Params extends MacroSchemaChannel<Definitions>, const Cookie extends MacroSchemaChannel<Definitions>, const NewMacro>(macro: ObjectMacroDefs<Body, Headers, Query, Params, Cookie, NewMacro, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, MergeScopedSchemas<Metadata['schemas'], Ephemeral['schemas'], Volatile['schemas']>, Singleton & {
526
+ macro<const Body extends MacroSchemaChannel<Definitions>, const Headers extends MacroSchemaChannel<Definitions>, const Query extends MacroSchemaChannel<Definitions>, const Params extends MacroSchemaChannel<Definitions>, const Cookie extends MacroSchemaChannel<Definitions>, const NewMacro, const Refs = {}>(macro: ObjectMacroDefs<Body, Headers, Query, Params, Cookie, NewMacro, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, MergeScopedSchemas<Metadata['schemas'], Ephemeral['schemas'], Volatile['schemas']>, Singleton & {
527
527
  derive: Partial<Ephemeral['derive'] & Volatile['derive']>;
528
- }, Definitions, Metadata['macro']>): Elysia<BasePath, Scope, Singleton, Definitions, {
528
+ }, Definitions, Metadata['macro'], Metadata['macroFn'], Refs>): Elysia<BasePath, Scope, Singleton, Definitions, {
529
529
  schema: Metadata['schema'];
530
530
  schemas: Metadata['schemas'];
531
531
  macro: Metadata['macro'] & Partial<MacroToProperty<NewMacro>>;
@@ -1,5 +1,5 @@
1
- import { CapturedValidator, FrozenValidator } from "../aot.js";
2
1
  import { AnyLocalHook, HTTPMethod } from "../../types.js";
2
+ import { CapturedValidator, FrozenValidator } from "../aot.js";
3
3
  import { AnyElysia } from "../../base.js";
4
4
 
5
5
  //#region src/compile/handler/frozen-validator.d.ts
@@ -23,7 +23,9 @@ interface FrozenRouteValidatorShape {
23
23
  cookie?: FrozenSlotValidator;
24
24
  response?: Record<number, FrozenSlotValidator>;
25
25
  }
26
+ declare const isStandardSchema: (schema: unknown) => schema is object & Record<"~standard", unknown>;
27
+ declare function standaloneAllStandard(schemas: Array<Record<string, unknown>> | undefined): boolean;
26
28
  declare function buildFrozenRouteValidator(hook: AnyLocalHook, root: AnyElysia, method: HTTPMethod, path: string): FrozenRouteValidatorShape | undefined;
27
29
  declare function isCapturedBridgeFree(c: CapturedValidator, schema: unknown, coerced?: unknown): boolean;
28
30
  //#endregion
29
- export { buildFrozenRouteValidator, isBridgeNotInitialized, isCapturedBridgeFree };
31
+ export { buildFrozenRouteValidator, isBridgeNotInitialized, isCapturedBridgeFree, isStandardSchema, standaloneAllStandard };
@@ -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_validator_index = require('../../validator/index.js');
6
7
  const require_type_validator_clean_safe = require('../../type/validator/clean-safe.js');
7
8
 
8
9
  //#region src/compile/handler/frozen-validator.ts
@@ -111,6 +112,15 @@ const REQUEST_SLOTS = [
111
112
  "params",
112
113
  "cookie"
113
114
  ];
115
+ const isStandardSchema = (schema) => schema != null && typeof schema === "object" && "~standard" in schema;
116
+ function standaloneAllStandard(schemas) {
117
+ if (!schemas || schemas.length === 0) return true;
118
+ for (const entry of schemas) for (const key in entry) {
119
+ const value = entry[key];
120
+ if (value && !isStandardSchema(value)) return false;
121
+ }
122
+ return true;
123
+ }
114
124
  function resolveModelRef(schema, root) {
115
125
  if (typeof schema !== "string") return schema;
116
126
  const models = root["~ext"]?.models;
@@ -126,6 +136,10 @@ function buildFrozenRouteValidator(hook, root, method, path) {
126
136
  if (!raw) continue;
127
137
  const schema = resolveModelRef(raw, root);
128
138
  if (!schema) return void 0;
139
+ if (isStandardSchema(schema)) {
140
+ out[slot] = new require_validator_index.StandardValidator(schema);
141
+ continue;
142
+ }
129
143
  const frozen = require_compile_aot.Compiled.getValidator(method, path, slot);
130
144
  if (!frozen) return void 0;
131
145
  let coerced = schema;
@@ -146,6 +160,10 @@ function buildFrozenRouteValidator(hook, root, method, path) {
146
160
  if (!raw) continue;
147
161
  const schema = resolveModelRef(raw, root);
148
162
  if (!schema) return void 0;
163
+ if (isStandardSchema(schema)) {
164
+ responseOut[status] = new require_validator_index.StandardValidator(schema);
165
+ continue;
166
+ }
149
167
  const frozen = require_compile_aot.Compiled.getValidator(method, path, `response:${status}`);
150
168
  if (!frozen || !isBridgeFreeComplete(frozen, schema, schema)) return void 0;
151
169
  responseOut[status] = new FrozenSlotValidator(frozen, schema, schema, normalize);
@@ -174,4 +192,6 @@ function isCapturedBridgeFree(c, schema, coerced = schema) {
174
192
  //#endregion
175
193
  exports.buildFrozenRouteValidator = buildFrozenRouteValidator;
176
194
  exports.isBridgeNotInitialized = isBridgeNotInitialized;
177
- exports.isCapturedBridgeFree = isCapturedBridgeFree;
195
+ exports.isCapturedBridgeFree = isCapturedBridgeFree;
196
+ exports.isStandardSchema = isStandardSchema;
197
+ exports.standaloneAllStandard = standaloneAllStandard;
@@ -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, reconstruct } from "../aot.mjs";
5
+ import { StandardValidator } from "../../validator/index.mjs";
5
6
  import { isFullyClosedObject } from "../../type/validator/clean-safe.mjs";
6
7
 
7
8
  //#region src/compile/handler/frozen-validator.ts
@@ -110,6 +111,15 @@ const REQUEST_SLOTS = [
110
111
  "params",
111
112
  "cookie"
112
113
  ];
114
+ const isStandardSchema = (schema) => schema != null && typeof schema === "object" && "~standard" in schema;
115
+ function standaloneAllStandard(schemas) {
116
+ if (!schemas || schemas.length === 0) return true;
117
+ for (const entry of schemas) for (const key in entry) {
118
+ const value = entry[key];
119
+ if (value && !isStandardSchema(value)) return false;
120
+ }
121
+ return true;
122
+ }
113
123
  function resolveModelRef(schema, root) {
114
124
  if (typeof schema !== "string") return schema;
115
125
  const models = root["~ext"]?.models;
@@ -125,6 +135,10 @@ function buildFrozenRouteValidator(hook, root, method, path) {
125
135
  if (!raw) continue;
126
136
  const schema = resolveModelRef(raw, root);
127
137
  if (!schema) return void 0;
138
+ if (isStandardSchema(schema)) {
139
+ out[slot] = new StandardValidator(schema);
140
+ continue;
141
+ }
128
142
  const frozen = Compiled.getValidator(method, path, slot);
129
143
  if (!frozen) return void 0;
130
144
  let coerced = schema;
@@ -145,6 +159,10 @@ function buildFrozenRouteValidator(hook, root, method, path) {
145
159
  if (!raw) continue;
146
160
  const schema = resolveModelRef(raw, root);
147
161
  if (!schema) return void 0;
162
+ if (isStandardSchema(schema)) {
163
+ responseOut[status] = new StandardValidator(schema);
164
+ continue;
165
+ }
148
166
  const frozen = Compiled.getValidator(method, path, `response:${status}`);
149
167
  if (!frozen || !isBridgeFreeComplete(frozen, schema, schema)) return void 0;
150
168
  responseOut[status] = new FrozenSlotValidator(frozen, schema, schema, normalize);
@@ -171,4 +189,4 @@ function isCapturedBridgeFree(c, schema, coerced = schema) {
171
189
  }
172
190
 
173
191
  //#endregion
174
- export { buildFrozenRouteValidator, isBridgeNotInitialized, isCapturedBridgeFree };
192
+ export { buildFrozenRouteValidator, isBridgeNotInitialized, isCapturedBridgeFree, isStandardSchema, standaloneAllStandard };
@@ -1,5 +1,5 @@
1
1
  //#region src/compile/lexer.d.ts
2
- declare const isSpace: (ch: string) => ch is "\n" | " " | "\t" | "\r";
2
+ declare const isSpace: (ch: string) => ch is " " | "\n" | "\t" | "\r";
3
3
  declare const isIdentChar: (ch: string) => boolean;
4
4
  declare const isIdentCharCode: (code: number) => boolean;
5
5
  declare function skipString(src: string, start: number): number;
package/dist/index.d.ts CHANGED
@@ -1,9 +1,12 @@
1
1
  import { StatusMap, StatusMapBack } from "./constants.js";
2
2
  import { ElysiaError, ElysiaStatus, InternalServerError, NotFound, ParseError, Problem, SelectiveStatus, ValidationError, problem, status, validationDetail } from "./error.js";
3
- import { ElysiaFile, file } from "./universal/file.js";
4
3
  import { BaseCookie, CookieOptions } from "./cookie/types.js";
5
4
  import { Cookie } from "./cookie/cookie.js";
6
5
  import { InvalidCookie } from "./cookie/error.js";
6
+ import { ElysiaFile, file } from "./universal/file.js";
7
+ import { env } from "./universal/env.js";
8
+ import { Server } from "./universal/server.js";
9
+ import { HTTPHeaders, InputSchema, Macro, MacroToContext, MacroToProperty, RouteSchema, SSEPayload, UnwrapRoute, UnwrapSchema } from "./types.js";
7
10
  import { AnySchema, BaseSchema, StandardJSONSchemaV1Like, StandardSchemaV1Like } from "./type/types.js";
8
11
  import { TCookieField, TCookieObject } from "./type/elysia/cookie.js";
9
12
  import { FileTypeDetector, fileType, setFileTypeDetector } from "./type/elysia/file-type.js";
@@ -13,9 +16,6 @@ import { Capture, Compiled } from "./compile/aot.js";
13
16
  import { MultiValidator, StandardValidator, Validator } from "./validator/index.js";
14
17
  import { TypeBoxValidator } from "./type/validator/index.js";
15
18
  import { TypeSystem, t } from "./type/index.js";
16
- import { env } from "./universal/env.js";
17
- import { Server } from "./universal/server.js";
18
- import { HTTPHeaders, InputSchema, Macro, MacroToContext, MacroToProperty, RouteSchema, SSEPayload, UnwrapRoute, UnwrapSchema } from "./types.js";
19
19
  import { form, prefix, redirect, sse } from "./utils.js";
20
20
  import { Context, ErrorContext, createBaseContext, createContext } from "./context.js";
21
21
  import { AnyElysia, Elysia } from "./base.js";
@@ -1,5 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_runtime = require('../_virtual/_rolldown/runtime.js');
3
+ const require_compile_handler_frozen_validator = require('../compile/handler/frozen-validator.js');
3
4
  const require_compile_handler_index = require('../compile/handler/index.js');
4
5
  const require_plugin_source = require('./source.js');
5
6
  let node_fs = require("node:fs");
@@ -250,6 +251,14 @@ async function generateCompiledModule(file, options) {
250
251
  return (await generateCompiledArtifacts(file, options)).source;
251
252
  }
252
253
  const _importedEntries = /* @__PURE__ */ new Set();
254
+ function isStandardResponse(response) {
255
+ if (response == null || typeof response !== "object") return false;
256
+ if (require_compile_handler_frozen_validator.isStandardSchema(response)) return true;
257
+ if ("~kind" in response || "~elyAcl" in response) return false;
258
+ const entries = Object.values(response);
259
+ if (entries.length === 0) return false;
260
+ return entries.every((v) => require_compile_handler_frozen_validator.isStandardSchema(v));
261
+ }
253
262
  async function generateCompiledArtifacts(file, options) {
254
263
  const previousAotBuild = process.env.ELYSIA_AOT_BUILD;
255
264
  process.env.ELYSIA_AOT_BUILD = "1";
@@ -299,15 +308,28 @@ async function generateCompiledArtifacts(file, options) {
299
308
  const [, , , instance, hook, appHook, inheritedChain, macroScope] = route;
300
309
  const hooks = require_compile_handler_index.composeRouteHook(instance, hook, appHook, inheritedChain, typedApp, macroScope);
301
310
  if (!hooks) continue;
302
- if (Array.isArray(hooks.schemas) && hooks.schemas.length > 0) routesForbidSeal = true;
311
+ let routeHasTypeBoxDirectSlot = false;
303
312
  for (const slot of [
304
313
  "body",
305
314
  "query",
306
315
  "params",
307
316
  "headers",
308
- "cookie",
309
- "response"
310
- ]) if (hooks[slot] !== void 0) expectedSlots++;
317
+ "cookie"
318
+ ]) {
319
+ const value = hooks[slot];
320
+ if (value === void 0) continue;
321
+ if (require_compile_handler_frozen_validator.isStandardSchema(value)) continue;
322
+ routeHasTypeBoxDirectSlot = true;
323
+ expectedSlots++;
324
+ }
325
+ if (hooks.response !== void 0 && !isStandardResponse(hooks.response)) {
326
+ routeHasTypeBoxDirectSlot = true;
327
+ expectedSlots++;
328
+ }
329
+ const standalone = hooks.schemas;
330
+ if (Array.isArray(standalone) && standalone.length > 0) {
331
+ if (routeHasTypeBoxDirectSlot || !require_compile_handler_frozen_validator.standaloneAllStandard(standalone)) routesForbidSeal = true;
332
+ }
311
333
  }
312
334
  if (typedApp["~config"]?.normalize === "typebox") routesForbidSeal = true;
313
335
  const frozenSlots = artifacts.validators.length;
@@ -1,3 +1,4 @@
1
+ import { isStandardSchema, standaloneAllStandard } from "../compile/handler/frozen-validator.mjs";
1
2
  import { composeRouteHook } from "../compile/handler/index.mjs";
2
3
  import { captureArtifacts, compileToSource, replayStubbability } from "./source.mjs";
3
4
  import { createRequire } from "node:module";
@@ -248,6 +249,14 @@ async function generateCompiledModule(file, options) {
248
249
  return (await generateCompiledArtifacts(file, options)).source;
249
250
  }
250
251
  const _importedEntries = /* @__PURE__ */ new Set();
252
+ function isStandardResponse(response) {
253
+ if (response == null || typeof response !== "object") return false;
254
+ if (isStandardSchema(response)) return true;
255
+ if ("~kind" in response || "~elyAcl" in response) return false;
256
+ const entries = Object.values(response);
257
+ if (entries.length === 0) return false;
258
+ return entries.every((v) => isStandardSchema(v));
259
+ }
251
260
  async function generateCompiledArtifacts(file, options) {
252
261
  const previousAotBuild = process.env.ELYSIA_AOT_BUILD;
253
262
  process.env.ELYSIA_AOT_BUILD = "1";
@@ -297,15 +306,28 @@ async function generateCompiledArtifacts(file, options) {
297
306
  const [, , , instance, hook, appHook, inheritedChain, macroScope] = route;
298
307
  const hooks = composeRouteHook(instance, hook, appHook, inheritedChain, typedApp, macroScope);
299
308
  if (!hooks) continue;
300
- if (Array.isArray(hooks.schemas) && hooks.schemas.length > 0) routesForbidSeal = true;
309
+ let routeHasTypeBoxDirectSlot = false;
301
310
  for (const slot of [
302
311
  "body",
303
312
  "query",
304
313
  "params",
305
314
  "headers",
306
- "cookie",
307
- "response"
308
- ]) if (hooks[slot] !== void 0) expectedSlots++;
315
+ "cookie"
316
+ ]) {
317
+ const value = hooks[slot];
318
+ if (value === void 0) continue;
319
+ if (isStandardSchema(value)) continue;
320
+ routeHasTypeBoxDirectSlot = true;
321
+ expectedSlots++;
322
+ }
323
+ if (hooks.response !== void 0 && !isStandardResponse(hooks.response)) {
324
+ routeHasTypeBoxDirectSlot = true;
325
+ expectedSlots++;
326
+ }
327
+ const standalone = hooks.schemas;
328
+ if (Array.isArray(standalone) && standalone.length > 0) {
329
+ if (routeHasTypeBoxDirectSlot || !standaloneAllStandard(standalone)) routesForbidSeal = true;
330
+ }
309
331
  }
310
332
  if (typedApp["~config"]?.normalize === "typebox") routesForbidSeal = true;
311
333
  const frozenSlots = artifacts.validators.length;
@@ -1,17 +1,17 @@
1
- import { Intersect as Intersect$1 } from "./elysia/intersect.js";
1
+ import { Intersect as Intersect$2 } from "./elysia/intersect.js";
2
2
  import { applyCoercions as applyCoercions$1, coerceBody as coerceBody$1, coerceFormData as coerceFormData$1, coerceQuery as coerceQuery$1, coerceRoot as coerceRoot$1, coerceStringToStructure as coerceStringToStructure$1 } from "./coerce.js";
3
3
  import { hasTypes as hasTypes$1 } from "./utils.js";
4
4
  import { TypeBoxValidatorCache as TypeBoxValidatorCache$1 } from "./validator/validator-cache.js";
5
5
  import { TypeBoxValidator as TypeBoxValidator$1 } from "./validator/index.js";
6
6
  import { Ref as Ref$1, TAny, TSchema } from "typebox/type";
7
7
  import { Compile as Compile$1 } from "typebox/compile";
8
- import { Clone as Clone$1, Create as Create$1, Decode as Decode$1, Default as Default$1, HasCodec as HasCodec$1 } from "typebox/value";
8
+ import { Clone as Clone$1, Create as Create$1, Decode as Decode$2, Default as Default$1, HasCodec as HasCodec$1 } from "typebox/value";
9
9
 
10
10
  //#region src/type/bridge.d.ts
11
11
  interface TypeboxModule {
12
12
  Compile: typeof Compile$1;
13
13
  Create: typeof Create$1;
14
- Decode: typeof Decode$1;
14
+ Decode: typeof Decode$2;
15
15
  applyCoercions: typeof applyCoercions$1;
16
16
  TypeBoxValidator: TypeBoxValidator$1;
17
17
  TypeBoxValidatorCache: TypeBoxValidatorCache$1;
@@ -22,14 +22,14 @@ interface TypeboxModule {
22
22
  coerceBody: typeof coerceBody$1;
23
23
  hasTypes: typeof hasTypes$1;
24
24
  HasCodec: typeof HasCodec$1;
25
- Intersect: typeof Intersect$1;
25
+ Intersect: typeof Intersect$2;
26
26
  Default: typeof Default$1;
27
27
  Ref: typeof Ref$1;
28
28
  Clone: typeof Clone$1;
29
29
  }
30
30
  declare let Compile: typeof Compile$1;
31
31
  declare let Create: typeof Create$1;
32
- declare let Decode: typeof Decode$1;
32
+ declare let Decode: typeof Decode$2;
33
33
  declare let applyCoercions: typeof applyCoercions$1;
34
34
  declare let TypeBoxValidator: TypeBoxValidator$1;
35
35
  type TypeBoxValidator<T extends TSchema = TAny> = TypeBoxValidator$1<T>;
@@ -42,7 +42,7 @@ declare let coerceStringToStructure: typeof coerceStringToStructure$1;
42
42
  declare let coerceBody: typeof coerceBody$1;
43
43
  declare let hasTypes: typeof hasTypes$1;
44
44
  declare let HasCodec: typeof HasCodec$1;
45
- declare let Intersect: typeof Intersect$1;
45
+ declare let Intersect: typeof Intersect$2;
46
46
  declare let Default: typeof Default$1;
47
47
  declare let Ref: typeof Ref$1;
48
48
  declare let Clone: typeof Clone$1;
@@ -1,5 +1,5 @@
1
- import { FileType, FileUnit } from "../types.js";
2
1
  import { MaybeArray, MaybePromise } from "../../types.js";
2
+ import { FileType, FileUnit } from "../types.js";
3
3
 
4
4
  //#region src/type/elysia/file-type.d.ts
5
5
  type FileTypeDetector = (file: File) => MaybePromise<string | {
@@ -1,9 +1,9 @@
1
1
  import { ELYSIA_TYPES } from "./constants.js";
2
2
  import { CookieOptions } from "../cookie/types.js";
3
3
  import { MaybeArray } from "../types.js";
4
+ import { Validator } from "typebox/schema";
4
5
  import { TObjectOptions, TSchemaOptions } from "typebox";
5
6
  import { TLocalizedValidationError } from "typebox/error";
6
- import { Validator } from "typebox/schema";
7
7
 
8
8
  //#region src/type/types.d.ts
9
9
  type FileUnit = number | `${number}${'k' | 'm'}`;
@@ -1,9 +1,9 @@
1
+ import { MaybePromise } from "../../types.js";
1
2
  import { Validator as Validator$1, ValidatorOptions } from "../../validator/index.js";
2
3
  import { TypeBoxValidatorCache } from "./validator-cache.js";
3
- import { MaybePromise } from "../../types.js";
4
4
  import { Static, StaticDecode, StaticEncode, TAny, TSchema } from "typebox/type";
5
- import { TLocalizedValidationError } from "typebox/error";
6
5
  import { Validator } from "typebox/schema";
6
+ import { TLocalizedValidationError } from "typebox/error";
7
7
 
8
8
  //#region src/type/validator/index.d.ts
9
9
  declare function shallowMergeObjects(members: any[]): TSchema | null;
package/dist/types.d.ts CHANGED
@@ -1,17 +1,17 @@
1
1
  import { MethodMap, StatusMapBack } from "./constants.js";
2
2
  import { ElysiaError, ElysiaStatus } from "./error.js";
3
+ import { CookieOptions } from "./cookie/types.js";
3
4
  import { ElysiaFile } from "./universal/file.js";
4
5
  import { TraceHandler } from "./trace.js";
5
- import { CookieOptions } from "./cookie/types.js";
6
- import { AnySchema, StandardSchemaV1Like, TypeBoxSchema } from "./type/types.js";
7
6
  import { Serve } from "./universal/server.js";
7
+ import { AnySchema, StandardSchemaV1Like, TypeBoxSchema } from "./type/types.js";
8
8
  import { ChainNode } from "./utils.js";
9
9
  import { Context, ErrorContext, LifecycleContext, PreContext } from "./context.js";
10
10
  import { WebSocketHandler } from "./ws/types.js";
11
11
  import { AnyElysia, Elysia } from "./base.js";
12
12
  import { ElysiaAdapter } from "./adapter/index.js";
13
- import { Static, StaticDecode, StaticEncode, TIntersect, TObject, TSchema } from "typebox";
14
13
  import { Instruction } from "exact-mirror";
14
+ import { Static, StaticDecode, StaticEncode, TIntersect, TObject, TSchema } from "typebox";
15
15
  import { OpenAPIV3 } from "openapi-types";
16
16
 
17
17
  //#region src/types.d.ts
@@ -496,7 +496,7 @@ interface PublicRoute {
496
496
  websocket?: AnyWSLocalHook;
497
497
  }
498
498
  type MaybeValueOrVoidFunction<T> = T | ((...a: any) => void | T);
499
- interface MacroProperty<in out Macro extends BaseMacro = {}, in out TypedRoute extends RouteSchema = {}, in out Singleton extends SingletonBase = DefaultSingleton, Errors extends ErrorDefinition[] = []> {
499
+ type MacroProperty<Macro extends BaseMacro = {}, TypedRoute extends RouteSchema = {}, Singleton extends SingletonBase = DefaultSingleton, Errors extends ErrorDefinition[] = []> = Macro & {
500
500
  /**
501
501
  * Deduplication similar to Elysia.constructor.seed
502
502
  */
@@ -516,7 +516,7 @@ interface MacroProperty<in out Macro extends BaseMacro = {}, in out TypedRoute e
516
516
  * @param option
517
517
  */
518
518
  introspect?(option: Prettify<Macro>): unknown;
519
- }
519
+ };
520
520
  interface Macro<in out Macro extends BaseMacro = {}, in out Input extends BaseMacro = {}, in out TypedRoute extends RouteSchema = {}, in out Singleton extends SingletonBase = DefaultSingleton, Errors extends ErrorDefinition[] = []> {
521
521
  [K: keyof any]: MaybeValueOrVoidFunction<Input & MacroProperty<Macro, TypedRoute, Singleton, Errors>>;
522
522
  }
@@ -723,6 +723,23 @@ type MacroDefSchema<K, MBody, MHeaders, MQuery, MParams, MCookie> = {
723
723
  };
724
724
  type MacroSchemaChannel<Definitions extends DefinitionBase> = Record<keyof any, AnySchema | (keyof Definitions['typebox'] & string)>;
725
725
  type MacroChannel<Channel, Key extends keyof InputSchema, Definitions extends DefinitionBase> = { [K in keyof Channel]: MaybeValueOrVoidFunction<{ [F in Key]?: Channel[K] | (keyof Definitions['typebox'] & string) } & Record<string, unknown>> };
726
+ /**
727
+ * Captures the verbatim `.macro()` definition record into a separate first-pass
728
+ * generic (mirrors {@link MacroChannel}). This lets each definition's enabled
729
+ * sibling flags (`{ auth: true }`) be read back without reusing the contextually
730
+ * typed `NewMacro`, which would form the record -> handler-typing inference
731
+ * cycle documented on {@link ObjectMacroDefs}.
732
+ */
733
+ type MacroRefChannel<Refs> = { [K in keyof Refs]: MaybeValueOrVoidFunction<{ [M in keyof Refs[K]]?: Refs[K][M] } & Record<string, unknown>> };
734
+ /**
735
+ * `resolve` (derive) context contributed by the sibling macros a definition
736
+ * enables via `{ name: true }`. Extracted through `infer` because
737
+ * {@link MacroToContext} is a mapped type whose `resolve` key cannot be indexed
738
+ * with a plain `['resolve']` on the generic form.
739
+ */
740
+ type MacroRefResolve<MacroFn, SelectedMacro, Definitions> = MacroToContext<MacroFn, SelectedMacro, Definitions> extends {
741
+ resolve: infer Resolve;
742
+ } ? Resolve : {};
726
743
  /**
727
744
  * Parameter type of the object-form `.macro({ name: definition })`
728
745
  *
@@ -735,7 +752,9 @@ type MacroChannel<Channel, Key extends keyof InputSchema, Definitions extends De
735
752
  * still flow into `N` (the verbatim definitions, stored in
736
753
  * `Metadata['macroFn']` for the consuming route)
737
754
  */
738
- type ObjectMacroDefs<Body, Headers, Query, Params, Cookie, N, AmbientSchema extends RouteSchema, ScopedSchemas extends RouteSchema, Singleton extends SingletonBase, Definitions extends DefinitionBase, MacroNames extends BaseMacro> = MacroChannel<Body, 'body', Definitions> & MacroChannel<Headers, 'headers', Definitions> & MacroChannel<Query, 'query', Definitions> & MacroChannel<Params, 'params', Definitions> & MacroChannel<Cookie, 'cookie', Definitions> & { [K in keyof N]: MaybeValueOrVoidFunction<MacroProperty<MacroNames & InputSchema<keyof Definitions['typebox'] & string>, IntersectIfObjectSchema<MergeSchema<UnwrapMacroSchema<MacroDefSchema<K, Body, Headers, Query, Params, Cookie>, Definitions['typebox']>, AmbientSchema>, ScopedSchemas>, Singleton, Definitions['error']>> } & { [K in keyof N]: N[K] extends ((...a: any[]) => any) ? unknown : string extends keyof N[K] ? unknown : { [P in Exclude<keyof N[K], MacroPropertyKey | InputSchemaKey | keyof MacroNames | keyof N>]: `Unknown macro property '${P & string}'` } } & N;
755
+ type ObjectMacroDefs<Body, Headers, Query, Params, Cookie, N, AmbientSchema extends RouteSchema, ScopedSchemas extends RouteSchema, Singleton extends SingletonBase, Definitions extends DefinitionBase, MacroNames extends BaseMacro, MacroFn = {}, Refs = {}> = MacroChannel<Body, 'body', Definitions> & MacroChannel<Headers, 'headers', Definitions> & MacroChannel<Query, 'query', Definitions> & MacroChannel<Params, 'params', Definitions> & MacroChannel<Cookie, 'cookie', Definitions> & MacroRefChannel<Refs> & { [K in keyof N]: MaybeValueOrVoidFunction<MacroProperty<MacroNames & InputSchema<keyof Definitions['typebox'] & string>, IntersectIfObjectSchema<MergeSchema<UnwrapMacroSchema<MacroDefSchema<K, Body, Headers, Query, Params, Cookie>, Definitions['typebox']>, AmbientSchema>, ScopedSchemas>, Singleton & {
756
+ derive: Singleton['derive'] & MacroRefResolve<MacroFn, K extends keyof Refs ? Refs[K] : {}, Definitions['typebox']>;
757
+ }, Definitions['error']>> } & { [K in keyof N]: N[K] extends ((...a: any[]) => any) ? unknown : string extends keyof N[K] ? unknown : { [P in Exclude<keyof N[K], MacroPropertyKey | InputSchemaKey | keyof MacroNames | keyof N>]: `Unknown macro property '${P & string}'` } } & N;
739
758
  type CreateEden<Path extends string, Property extends Record<string, unknown> = {}> = Path extends `/${infer Rest}` ? _CreateEden<Rest, Property> : Path extends '' | '/' ? Property : _CreateEden<Path, Property>;
740
759
  type _CreateEden<Path extends string, Property extends Record<string, unknown> = {}> = Path extends `${infer Start}/${infer Rest}` ? { [x in Start]: _CreateEden<Rest, Property> } : Path extends '' ? Property : { [x in Path]: Property };
741
760
  type CreateEdenResponse<Path extends string, Schema extends RouteSchema, MacroContext extends RouteSchema, Res extends PossibleResponse, Err extends Error = never> = RouteSchema extends MacroContext ? {
package/dist/utils.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { MethodMap } from "./constants.js";
2
- import { AnySchema, StandardSchemaV1Like } from "./type/types.js";
3
2
  import { AnyLocalHook, AppHook, ElysiaFormData, EventFn, EventScope, GuardSchemaType, InputSchema, Macro, MaybeArray, Prettify, SSEPayload } from "./types.js";
3
+ import { AnySchema, StandardSchemaV1Like } from "./type/types.js";
4
4
  import { Context } from "./context.js";
5
5
 
6
6
  //#region src/utils.d.ts
@@ -1,8 +1,8 @@
1
+ import { ElysiaConfig, MaybePromise } from "../types.js";
1
2
  import { AnySchema, StandardSchemaV1Like } from "../type/types.js";
2
3
  import { CoerceOption } from "../type/coerce.js";
3
4
  import { ValidatorSlot } from "../compile/aot.js";
4
5
  import { TypeBoxValidator } from "../type/bridge.js";
5
- import { ElysiaConfig, MaybePromise } from "../types.js";
6
6
  import { TSchema } from "typebox/type";
7
7
  import { TLocalizedValidationError } from "typebox/error";
8
8
 
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.36",
4
+ "version": "2.0.0-exp.38",
5
5
  "author": {
6
6
  "name": "saltyAom",
7
7
  "url": "https://github.com/SaltyAom",