elysia 2.0.0-exp.36 → 2.0.0-exp.37

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";
@@ -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 };
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,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,6 +1,6 @@
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
5
  import { TLocalizedValidationError } from "typebox/error";
6
6
  import { Validator } from "typebox/schema";
package/dist/types.d.ts CHANGED
@@ -1,10 +1,10 @@
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";
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.37",
5
5
  "author": {
6
6
  "name": "saltyAom",
7
7
  "url": "https://github.com/SaltyAom",