Comparing version 1.2.12 to 1.2.13
@@ -94,3 +94,3 @@ "use strict"; | ||
if (app.inference.server) | ||
fnLiteral += `,get server(){return getServer()}`; | ||
fnLiteral += `,get server(){return app.getServer()}`; | ||
if (hasTrace) fnLiteral += ",[ELYSIA_REQUEST_ID]:id"; | ||
@@ -97,0 +97,0 @@ fnLiteral += decoratorsLiteral; |
@@ -1275,10 +1275,10 @@ "use strict"; | ||
let switchMap = ``; | ||
for (const [path, { code, all }] of Object.entries( | ||
router.static.http.map | ||
)) { | ||
for (const [path, v] of Object.entries(router.static.http.map)) { | ||
switchMap += `case'${path}':`; | ||
if (app.config.strictPath !== true) | ||
switchMap += `case'${(0, import_utils.getLoosePath)(path)}':`; | ||
switchMap += `switch(r.method){${code} | ||
` + (all ?? `default: break map`) + "}"; | ||
const encoded = (0, import_utils.encodePath)(path); | ||
if (path !== encoded) switchMap += `case'${encoded}':`; | ||
switchMap += `switch(r.method){${v.code} | ||
` + (v.all ?? `default: break map`) + "}"; | ||
} | ||
@@ -1285,0 +1285,0 @@ const maybeAsync = !!app.event.request?.some(isAsync); |
@@ -10,2 +10,3 @@ import type { AnyElysia } from '.'; | ||
validator?: SchemaValidator; | ||
route: string; | ||
}; | ||
@@ -12,0 +13,0 @@ export declare const createDynamicHandler: (app: AnyElysia) => (request: Request) => Promise<Response>; |
@@ -58,2 +58,3 @@ "use strict"; | ||
qi, | ||
error: import_error.error, | ||
redirect: import_utils.redirect | ||
@@ -73,3 +74,3 @@ } | ||
if (!handler) throw new import_error.NotFoundError(); | ||
const { handle, hooks, validator, content } = handler.store; | ||
const { handle, hooks, validator, content, route } = handler.store; | ||
let body; | ||
@@ -150,2 +151,3 @@ if (request.method !== "GET" && request.method !== "HEAD") { | ||
} | ||
context.route = route; | ||
context.body = body; | ||
@@ -343,4 +345,4 @@ context.params = handler?.params || void 0; | ||
return mapResponse(context.response = response, context.set); | ||
} catch (error) { | ||
const reportedError = error instanceof import_value.TransformDecodeError && error.error ? error.error : error; | ||
} catch (error2) { | ||
const reportedError = error2 instanceof import_value.TransformDecodeError && error2.error ? error2.error : error2; | ||
return app.handleError(context, reportedError); | ||
@@ -356,4 +358,4 @@ } finally { | ||
const { mapResponse } = app["~adapter"].handler; | ||
return async (context, error) => { | ||
const errorContext = Object.assign(context, { error, code: error.code }); | ||
return async (context, error2) => { | ||
const errorContext = Object.assign(context, { error: error2, code: error2.code }); | ||
errorContext.set = context.set; | ||
@@ -372,6 +374,6 @@ if (app.event.error) | ||
return new Response( | ||
typeof error.cause === "string" ? error.cause : error.message, | ||
typeof error2.cause === "string" ? error2.cause : error2.message, | ||
{ | ||
headers: context.set.headers, | ||
status: error.status ?? 500 | ||
status: error2.status ?? 500 | ||
} | ||
@@ -378,0 +380,0 @@ ); |
@@ -275,3 +275,3 @@ "use strict"; | ||
* | ||
* ! Do not use unless you now exactly what you are doing | ||
* ! Do not use unless you know exactly what you are doing | ||
* ? Add Higher order function to Elysia.fetch | ||
@@ -534,11 +534,34 @@ */ | ||
content: localHook?.type, | ||
handle | ||
handle, | ||
route: path | ||
}); | ||
if (this.config.strictPath === false) | ||
this.router.dynamic.add(method, (0, import_utils.getLoosePath)(path), { | ||
const encoded = (0, import_utils.encodePath)(path, { dynamic: true }); | ||
if (path !== encoded) { | ||
this.router.dynamic.add(method, encoded, { | ||
validator, | ||
hooks, | ||
content: localHook?.type, | ||
handle | ||
handle, | ||
route: path | ||
}); | ||
} | ||
if (this.config.strictPath === false) { | ||
const loosePath = (0, import_utils.getLoosePath)(path); | ||
this.router.dynamic.add(method, loosePath, { | ||
validator, | ||
hooks, | ||
content: localHook?.type, | ||
handle, | ||
route: path | ||
}); | ||
const encoded2 = (0, import_utils.encodePath)(loosePath); | ||
if (loosePath !== encoded2) | ||
this.router.dynamic.add(method, loosePath, { | ||
validator, | ||
hooks, | ||
content: localHook?.type, | ||
handle, | ||
route: path | ||
}); | ||
} | ||
this.router.history.push({ | ||
@@ -615,9 +638,7 @@ method, | ||
if (isWebSocket) { | ||
const loose = (0, import_utils.getLoosePath)(path); | ||
if (path.indexOf(":") === -1 && path.indexOf("*") === -1) { | ||
this.router.static.ws[path] = index; | ||
} else { | ||
this.router.http.add("ws", path, handler); | ||
if (loose) this.router.http.add("ws", loose, handler); | ||
} | ||
this.router.http.add("ws", path, handler); | ||
if (!this.config.strictPath) | ||
this.router.http.add("ws", (0, import_utils.getLoosePath)(path), handler); | ||
const encoded = (0, import_utils.encodePath)(path, { dynamic: true }); | ||
if (encoded !== path) this.router.http.add("ws", encoded, handler); | ||
return; | ||
@@ -647,2 +668,9 @@ } | ||
} | ||
const encoded = (0, import_utils.encodePath)(path, { dynamic: true }); | ||
if (path !== encoded) { | ||
this.router.http.add(method, encoded, handler); | ||
if (this.config.nativeStaticResponse === true && staticHandler && (method === "GET" || method === "ALL")) | ||
this.router.static.http.static[encoded] = staticHandler(); | ||
this.router.http.add(method, encoded, handler); | ||
} | ||
} | ||
@@ -1310,2 +1338,7 @@ } | ||
return instance; | ||
} else if (plugin.promisedModules.size > 0) { | ||
for (const promise of plugin.promisedModules.promises) | ||
this.promisedModules.add(promise); | ||
this.promisedModules.then(() => this._use(plugin)).then((x) => x.compile()); | ||
return this; | ||
} | ||
@@ -1909,6 +1942,10 @@ const { name, seed } = plugin.config; | ||
const parsedSchemas = {}; | ||
Object.entries(name).forEach(([key, value]) => { | ||
if (!(key in this.definitions.type)) | ||
parsedSchemas[key] = this.definitions.type[key] = coerce(value); | ||
}); | ||
const kvs = Object.entries(name); | ||
for (const [key, value] of kvs) { | ||
if (key in this.definitions.type) continue; | ||
parsedSchemas[key] = this.definitions.type[key] = coerce( | ||
value | ||
); | ||
parsedSchemas[key].$id ??= `#/components/schemas/${key}`; | ||
} | ||
this.definitions.typebox = import_type_system.t.Module({ | ||
@@ -1924,2 +1961,14 @@ ...this.definitions.typebox["$defs"], | ||
return this; | ||
case "string": | ||
if (!model) break; | ||
const newModel = { | ||
...model, | ||
id: model.$id ?? `#/components/schemas/${name}` | ||
}; | ||
this.definitions.type[name] = model; | ||
this.definitions.typebox = import_type_system.t.Module({ | ||
...this.definitions.typebox["$defs"], | ||
...newModel | ||
}); | ||
return this; | ||
} | ||
@@ -1926,0 +1975,0 @@ ; |
@@ -1,3 +0,2 @@ | ||
import { ArrayOptions, DateOptions, Kind, NumberOptions, TArray, TDate, TUnsafe, TInteger, IntegerOptions } from '@sinclair/typebox'; | ||
import { type SchemaOptions, type TSchema, TProperties, ObjectOptions, TObject, TNumber, TBoolean } from '@sinclair/typebox'; | ||
import { ArrayOptions, DateOptions, Kind, NumberOptions, TArray, TDate, TUnsafe, TInteger, IntegerOptions, SchemaOptions, TSchema, TProperties, ObjectOptions, TObject, TNumber, TBoolean } from '@sinclair/typebox'; | ||
import { type ValueError, type TypeCheck } from '@sinclair/typebox/compiler'; | ||
@@ -89,2 +88,3 @@ import type { CookieOptions } from './cookies'; | ||
export { TypeSystemPolicy, TypeSystem, TypeSystemDuplicateFormat, TypeSystemDuplicateTypeKind } from '@sinclair/typebox/system'; | ||
export { TypeRegistry, FormatRegistry } from '@sinclair/typebox'; | ||
export { TypeCompiler, TypeCheck } from '@sinclair/typebox/compiler'; |
@@ -22,8 +22,10 @@ "use strict"; | ||
ElysiaType: () => ElysiaType, | ||
FormatRegistry: () => import_typebox3.FormatRegistry, | ||
TypeCheck: () => import_compiler2.TypeCheck, | ||
TypeCompiler: () => import_compiler2.TypeCompiler, | ||
TypeSystem: () => import_system2.TypeSystem, | ||
TypeSystemDuplicateFormat: () => import_system2.TypeSystemDuplicateFormat, | ||
TypeSystemDuplicateTypeKind: () => import_system2.TypeSystemDuplicateTypeKind, | ||
TypeSystemPolicy: () => import_system2.TypeSystemPolicy, | ||
TypeRegistry: () => import_typebox3.TypeRegistry, | ||
TypeSystem: () => import_system.TypeSystem, | ||
TypeSystemDuplicateFormat: () => import_system.TypeSystemDuplicateFormat, | ||
TypeSystemDuplicateTypeKind: () => import_system.TypeSystemDuplicateTypeKind, | ||
TypeSystemPolicy: () => import_system.TypeSystemPolicy, | ||
t: () => t | ||
@@ -33,3 +35,2 @@ }); | ||
var import_typebox = require("@sinclair/typebox"); | ||
var import_system = require("@sinclair/typebox/system"); | ||
var import_typebox2 = require("@sinclair/typebox"); | ||
@@ -40,3 +41,4 @@ var import_compiler = require("@sinclair/typebox/compiler"); | ||
var import_error = require("./error"); | ||
var import_system2 = require("@sinclair/typebox/system"); | ||
var import_system = require("@sinclair/typebox/system"); | ||
var import_typebox3 = require("@sinclair/typebox"); | ||
var import_compiler2 = require("@sinclair/typebox/compiler"); | ||
@@ -48,4 +50,4 @@ const isISO8601 = /(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/; | ||
const _validateDateTime = import_formats.fullFormats["date-time"]; | ||
if (!import_typebox2.FormatRegistry.Has("date")) | ||
import_system.TypeSystem.Format("date", (value) => { | ||
if (!import_typebox.FormatRegistry.Has("date")) | ||
import_typebox.FormatRegistry.Set("date", (value) => { | ||
const temp = value.replace(/"/g, ""); | ||
@@ -58,4 +60,4 @@ if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDate(temp)) { | ||
}); | ||
if (!import_typebox2.FormatRegistry.Has("date-time")) | ||
import_system.TypeSystem.Format("date-time", (value) => { | ||
if (!import_typebox.FormatRegistry.Has("date-time")) | ||
import_typebox.FormatRegistry.Set("date-time", (value) => { | ||
const temp = value.replace(/"/g, ""); | ||
@@ -70,10 +72,10 @@ if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDateTime(temp)) { | ||
const [formatName, formatValue] = formatEntry; | ||
if (!import_typebox2.FormatRegistry.Has(formatName)) { | ||
if (!import_typebox.FormatRegistry.Has(formatName)) { | ||
if (formatValue instanceof RegExp) | ||
import_system.TypeSystem.Format(formatName, (value) => formatValue.test(value)); | ||
import_typebox.FormatRegistry.Set(formatName, (value) => formatValue.test(value)); | ||
else if (typeof formatValue === "function") | ||
import_system.TypeSystem.Format(formatName, formatValue); | ||
import_typebox.FormatRegistry.Set(formatName, formatValue); | ||
} | ||
}); | ||
const t = Object.assign({}, import_typebox2.Type); | ||
const t = Object.assign({}, import_typebox.Type); | ||
const parseFileUnit = (size) => { | ||
@@ -91,2 +93,7 @@ if (typeof size === "string") | ||
}; | ||
const checkFileExtension = (type, extension) => { | ||
console.log({ type, extension }); | ||
if (type.startsWith(extension)) return true; | ||
return extension.charCodeAt(extension.length - 1) === 42 && extension.charCodeAt(extension.length - 2) === 47 && type.startsWith(extension.slice(0, -1)); | ||
}; | ||
const validateFile = (options, value) => { | ||
@@ -98,21 +105,21 @@ if (!(value instanceof Blob)) return false; | ||
return false; | ||
if (options.extension) | ||
if (typeof options.extension === "string") { | ||
if (!value.type.startsWith(options.extension)) return false; | ||
} else { | ||
for (let i = 0; i < options.extension.length; i++) | ||
if (value.type.startsWith(options.extension[i])) return true; | ||
return false; | ||
} | ||
if (options.extension) { | ||
if (typeof options.extension === "string") | ||
return checkFileExtension(value.type, options.extension); | ||
for (let i = 0; i < options.extension.length; i++) | ||
if (checkFileExtension(value.type, options.extension[i])) | ||
return true; | ||
} | ||
return true; | ||
}; | ||
const File = import_typebox.TypeRegistry.Get("Files") ?? import_system.TypeSystem.Type("File", validateFile); | ||
const Files = import_typebox.TypeRegistry.Get("Files") ?? import_system.TypeSystem.Type( | ||
const File = getOrSetType( | ||
"File", | ||
validateFile | ||
); | ||
const Files = getOrSetType( | ||
"Files", | ||
(options, value) => { | ||
if (!Array.isArray(value)) return validateFile(options, value); | ||
if (options.minItems && value.length < options.minItems) | ||
return false; | ||
if (options.maxItems && value.length > options.maxItems) | ||
return false; | ||
if (options.minItems && value.length < options.minItems) return false; | ||
if (options.maxItems && value.length > options.maxItems) return false; | ||
for (let i = 0; i < value.length; i++) | ||
@@ -123,16 +130,16 @@ if (!validateFile(options, value[i])) return false; | ||
); | ||
if (!import_typebox2.FormatRegistry.Has("numeric")) | ||
import_typebox2.FormatRegistry.Set("numeric", (value) => !!value && !isNaN(+value)); | ||
if (!import_typebox2.FormatRegistry.Has("integer")) | ||
import_typebox2.FormatRegistry.Set( | ||
if (!import_typebox.FormatRegistry.Has("numeric")) | ||
import_typebox.FormatRegistry.Set("numeric", (value) => !!value && !isNaN(+value)); | ||
if (!import_typebox.FormatRegistry.Has("integer")) | ||
import_typebox.FormatRegistry.Set( | ||
"integer", | ||
(value) => !!value && Number.isInteger(+value) | ||
); | ||
if (!import_typebox2.FormatRegistry.Has("boolean")) | ||
import_typebox2.FormatRegistry.Set( | ||
if (!import_typebox.FormatRegistry.Has("boolean")) | ||
import_typebox.FormatRegistry.Set( | ||
"boolean", | ||
(value) => value === "true" || value === "false" | ||
); | ||
if (!import_typebox2.FormatRegistry.Has("ObjectString")) | ||
import_typebox2.FormatRegistry.Set("ObjectString", (value) => { | ||
if (!import_typebox.FormatRegistry.Has("ObjectString")) | ||
import_typebox.FormatRegistry.Set("ObjectString", (value) => { | ||
let start = value.charCodeAt(0); | ||
@@ -149,4 +156,4 @@ if (start === 9 || start === 10 || start === 32) | ||
}); | ||
if (!import_typebox2.FormatRegistry.Has("ArrayString")) | ||
import_typebox2.FormatRegistry.Set("ArrayString", (value) => { | ||
if (!import_typebox.FormatRegistry.Has("ArrayString")) | ||
import_typebox.FormatRegistry.Set("ArrayString", (value) => { | ||
let start = value.charCodeAt(0); | ||
@@ -163,8 +170,9 @@ if (start === 9 || start === 10 || start === 32) | ||
}); | ||
import_typebox.TypeRegistry.Set("UnionEnum", (schema, value) => { | ||
return (typeof value === "number" || typeof value === "string" || value === null) && schema.enum.includes(value); | ||
}); | ||
if (!import_typebox.TypeRegistry.Has("UnionEnum")) | ||
import_typebox.TypeRegistry.Set("UnionEnum", (schema, value) => { | ||
return (typeof value === "number" || typeof value === "string" || value === null) && schema.enum.includes(value); | ||
}); | ||
const ElysiaType = { | ||
Numeric: (property) => { | ||
const schema = import_typebox2.Type.Number(property); | ||
const schema = import_typebox.Type.Number(property); | ||
return t.Transform( | ||
@@ -190,3 +198,3 @@ t.Union( | ||
Integer: (property) => { | ||
const schema = import_typebox2.Type.Integer(property); | ||
const schema = import_typebox.Type.Integer(property); | ||
return t.Transform( | ||
@@ -199,3 +207,3 @@ t.Union( | ||
}), | ||
t.Number(property) | ||
import_typebox.Type.Integer(property) | ||
], | ||
@@ -212,16 +220,17 @@ property | ||
Date: (property) => { | ||
const schema = import_typebox2.Type.Date(property); | ||
const schema = import_typebox.Type.Date(property); | ||
const _default = property?.default ? new Date(property.default) : void 0; | ||
return t.Transform( | ||
t.Union( | ||
[ | ||
import_typebox2.Type.Date(property), | ||
import_typebox.Type.Date(property), | ||
t.String({ | ||
format: "date", | ||
default: (/* @__PURE__ */ new Date()).toISOString() | ||
default: _default?.toISOString() | ||
}), | ||
t.String({ | ||
format: "date-time", | ||
default: (/* @__PURE__ */ new Date()).toISOString() | ||
default: _default?.toISOString() | ||
}), | ||
t.Number() | ||
t.Number({ default: _default?.getTime() }) | ||
], | ||
@@ -248,3 +257,3 @@ property | ||
BooleanString: (property) => { | ||
const schema = import_typebox2.Type.Boolean(property); | ||
const schema = import_typebox.Type.Boolean(property); | ||
return t.Transform( | ||
@@ -409,3 +418,3 @@ t.Union( | ||
...options, | ||
[import_typebox.Kind]: "UnionEnum", | ||
[import_typebox2.Kind]: "UnionEnum", | ||
...type, | ||
@@ -446,7 +455,15 @@ enum: values | ||
t.UnionEnum = ElysiaType.UnionEnum; | ||
function getOrSetType(kind, func) { | ||
if (!import_typebox.TypeRegistry.Has(kind)) { | ||
import_typebox.TypeRegistry.Set(kind, func); | ||
} | ||
return (options = {}) => (0, import_typebox2.Unsafe)({ ...options, [import_typebox2.Kind]: kind }); | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
ElysiaType, | ||
FormatRegistry, | ||
TypeCheck, | ||
TypeCompiler, | ||
TypeRegistry, | ||
TypeSystem, | ||
@@ -453,0 +470,0 @@ TypeSystemDuplicateFormat, |
@@ -219,4 +219,5 @@ import type { Elysia, AnyElysia } from '.'; | ||
}; | ||
export type UnwrapSchema<Schema extends TSchema | string | undefined, Definitions extends DefinitionBase['typebox'] = TModule<{}>> = undefined extends Schema ? unknown : Schema extends TSchema ? Schema extends OptionalField ? Prettify<Partial<Static<Schema>>> : StaticDecode<Schema> : Schema extends string ? StaticDecode<TImport<UnwrapTypeModule<Definitions>, Schema>> : unknown; | ||
export type UnwrapBodySchema<Schema extends TSchema | string | undefined, Definitions extends DefinitionBase['typebox'] = TModule<{}>> = undefined extends Schema ? unknown : Schema extends TSchema ? Schema extends OptionalField ? Prettify<Partial<Static<Schema>>> | null : StaticDecode<Schema> : Schema extends string ? Static<TImport<UnwrapTypeModule<Definitions>, Schema>> : unknown; | ||
type TrimArrayName<T extends string> = T extends `${infer Name}[]` ? Name : T; | ||
export type UnwrapSchema<Schema extends TSchema | string | undefined, Definitions extends DefinitionBase['typebox'] = TModule<{}>> = undefined extends Schema ? unknown : Schema extends TSchema ? Schema extends OptionalField ? Prettify<Partial<Static<Schema>>> : StaticDecode<Schema> : Schema extends `${infer Key}[]` ? Definitions extends Record<Key, infer NamedSchema> ? Array<NamedSchema> : StaticDecode<TImport<UnwrapTypeModule<Definitions>, TrimArrayName<Schema>>>[] : Schema extends string ? Definitions extends Record<Schema, infer NamedSchema> ? NamedSchema : StaticDecode<TImport<UnwrapTypeModule<Definitions>, Schema>> : unknown; | ||
export type UnwrapBodySchema<Schema extends TSchema | string | undefined, Definitions extends DefinitionBase['typebox'] = TModule<{}>> = undefined extends Schema ? unknown : Schema extends TSchema ? Schema extends OptionalField ? Prettify<Partial<Static<Schema>>> | null : StaticDecode<Schema> : Schema extends `${infer Key}[]` ? Definitions extends Record<Key, infer NamedSchema> ? Array<NamedSchema> : Static<TImport<UnwrapTypeModule<Definitions>, TrimArrayName<Schema>>>[] : Schema extends string ? Definitions extends Record<Schema, infer NamedSchema> ? NamedSchema : Static<TImport<UnwrapTypeModule<Definitions>, Schema>> : unknown; | ||
export type IsNull<T> = [T] extends [null] ? true : false; | ||
@@ -270,3 +271,3 @@ export type IsUnknown<T> = unknown extends T ? IsNull<T> extends false ? true : false : false; | ||
export interface InputSchema<Name extends string = string> { | ||
body?: TSchema | Name; | ||
body?: TSchema | Name | `${Name}[]`; | ||
headers?: TObject | TNull | TUndefined | Name; | ||
@@ -276,3 +277,3 @@ query?: TObject | TNull | TUndefined | Name; | ||
cookie?: TObject | TNull | TUndefined | Name; | ||
response?: TSchema | Record<number, TSchema> | Name | Record<number, Name | TSchema>; | ||
response?: TSchema | Record<number, TSchema> | `${Name}[]` | Name | Record<number, `${Name}[]` | Name | TSchema>; | ||
} | ||
@@ -279,0 +280,0 @@ export interface MergeSchema<A extends RouteSchema, B extends RouteSchema, Path extends string = ''> { |
@@ -136,6 +136,9 @@ "use strict"; | ||
}); | ||
this.stats = import("fs/promises").then((fs) => { | ||
stat = fs.stat; | ||
return fs.stat(path); | ||
}); | ||
try { | ||
this.stats = import("fs/promises").then((fs) => { | ||
stat = fs.stat; | ||
return fs.stat(path); | ||
}); | ||
} catch { | ||
} | ||
} else { | ||
@@ -142,0 +145,0 @@ this.value = createReadStream(path); |
@@ -197,2 +197,5 @@ import type { BunFile } from 'bun'; | ||
export declare const decompressHistoryHook: (hook: Partial<LifeCycleStore>) => LifeCycleStore; | ||
export declare const encodePath: (path: string, { dynamic }?: { | ||
dynamic?: boolean | undefined; | ||
}) => string; | ||
export {}; |
@@ -34,2 +34,3 @@ "use strict"; | ||
deduplicateChecksum: () => deduplicateChecksum, | ||
encodePath: () => encodePath, | ||
filterGlobalHook: () => filterGlobalHook, | ||
@@ -441,7 +442,7 @@ fnToContainer: () => fnToContainer, | ||
if (!s) return void 0; | ||
if (typeof s === "string" && !(s in models)) return void 0; | ||
let schema = typeof s === "string" ? ( | ||
let schema = typeof s === "string" ? s.endsWith("[]") ? import_type_system.t.Array(import_type_system.t.Ref(models[s.substring(0, s.length - 2)])) : ( | ||
// @ts-expect-error | ||
modules.Import(s) ?? models[s] | ||
) : s; | ||
if (!schema) return void 0; | ||
if (coerce || additionalCoerce) { | ||
@@ -560,7 +561,4 @@ if (coerce) | ||
if (!s) return; | ||
if (typeof s === "string" && !(s in models)) return; | ||
const maybeSchemaOrRecord = typeof s === "string" ? ( | ||
// @ts-ignore | ||
modules.Import(s) ?? models[s] | ||
) : s; | ||
const maybeSchemaOrRecord = typeof s === "string" ? s.endsWith("[]") ? import_type_system.t.Array(import_type_system.t.Ref(models[s.substring(0, s.length - 2)])) : modules.Import(s) ?? models[s] : s; | ||
if (!maybeSchemaOrRecord) return; | ||
const compile = (schema, references) => { | ||
@@ -586,2 +584,3 @@ if (dynamic) | ||
}; | ||
const modelValues = Object.values(models); | ||
if (import_typebox.Kind in maybeSchemaOrRecord) { | ||
@@ -591,3 +590,3 @@ if ("additionalProperties" in maybeSchemaOrRecord === false) | ||
return { | ||
200: compile(maybeSchemaOrRecord, Object.values(models)) | ||
200: compile(maybeSchemaOrRecord, modelValues) | ||
}; | ||
@@ -602,3 +601,3 @@ } | ||
schema.type === "object" && "additionalProperties" in schema === false; | ||
record[+status] = import_typebox.Kind in schema ? compile(schema, Object.values(models)) : schema; | ||
record[+status] = import_typebox.Kind in schema ? compile(schema, modelValues) : schema; | ||
} | ||
@@ -609,3 +608,3 @@ return void 0; | ||
maybeNameOrSchema.additionalProperties = additionalProperties; | ||
record[+status] = import_typebox.Kind in maybeNameOrSchema ? compile(maybeNameOrSchema, Object.values(models)) : maybeNameOrSchema; | ||
record[+status] = import_typebox.Kind in maybeNameOrSchema ? compile(maybeNameOrSchema, modelValues) : maybeNameOrSchema; | ||
}); | ||
@@ -1213,2 +1212,7 @@ return record; | ||
}; | ||
const encodePath = (path, { dynamic = false } = {}) => { | ||
let encoded = encodeURIComponent(path).replace(/%2F/g, "/"); | ||
if (dynamic) encoded = encoded.replace(/%3A/g, ":").replace(/%3F/g, "?"); | ||
return encoded; | ||
}; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -1229,2 +1233,3 @@ 0 && (module.exports = { | ||
deduplicateChecksum, | ||
encodePath, | ||
filterGlobalHook, | ||
@@ -1231,0 +1236,0 @@ fnToContainer, |
@@ -10,2 +10,3 @@ import type { AnyElysia } from '.'; | ||
validator?: SchemaValidator; | ||
route: string; | ||
}; | ||
@@ -12,0 +13,0 @@ export declare const createDynamicHandler: (app: AnyElysia) => (request: Request) => Promise<Response>; |
@@ -1,3 +0,2 @@ | ||
import { ArrayOptions, DateOptions, Kind, NumberOptions, TArray, TDate, TUnsafe, TInteger, IntegerOptions } from '@sinclair/typebox'; | ||
import { type SchemaOptions, type TSchema, TProperties, ObjectOptions, TObject, TNumber, TBoolean } from '@sinclair/typebox'; | ||
import { ArrayOptions, DateOptions, Kind, NumberOptions, TArray, TDate, TUnsafe, TInteger, IntegerOptions, SchemaOptions, TSchema, TProperties, ObjectOptions, TObject, TNumber, TBoolean } from '@sinclair/typebox'; | ||
import { type ValueError, type TypeCheck } from '@sinclair/typebox/compiler'; | ||
@@ -89,2 +88,3 @@ import type { CookieOptions } from './cookies'; | ||
export { TypeSystemPolicy, TypeSystem, TypeSystemDuplicateFormat, TypeSystemDuplicateTypeKind } from '@sinclair/typebox/system'; | ||
export { TypeRegistry, FormatRegistry } from '@sinclair/typebox'; | ||
export { TypeCompiler, TypeCheck } from '@sinclair/typebox/compiler'; |
@@ -219,4 +219,5 @@ import type { Elysia, AnyElysia } from '.'; | ||
}; | ||
export type UnwrapSchema<Schema extends TSchema | string | undefined, Definitions extends DefinitionBase['typebox'] = TModule<{}>> = undefined extends Schema ? unknown : Schema extends TSchema ? Schema extends OptionalField ? Prettify<Partial<Static<Schema>>> : StaticDecode<Schema> : Schema extends string ? StaticDecode<TImport<UnwrapTypeModule<Definitions>, Schema>> : unknown; | ||
export type UnwrapBodySchema<Schema extends TSchema | string | undefined, Definitions extends DefinitionBase['typebox'] = TModule<{}>> = undefined extends Schema ? unknown : Schema extends TSchema ? Schema extends OptionalField ? Prettify<Partial<Static<Schema>>> | null : StaticDecode<Schema> : Schema extends string ? Static<TImport<UnwrapTypeModule<Definitions>, Schema>> : unknown; | ||
type TrimArrayName<T extends string> = T extends `${infer Name}[]` ? Name : T; | ||
export type UnwrapSchema<Schema extends TSchema | string | undefined, Definitions extends DefinitionBase['typebox'] = TModule<{}>> = undefined extends Schema ? unknown : Schema extends TSchema ? Schema extends OptionalField ? Prettify<Partial<Static<Schema>>> : StaticDecode<Schema> : Schema extends `${infer Key}[]` ? Definitions extends Record<Key, infer NamedSchema> ? Array<NamedSchema> : StaticDecode<TImport<UnwrapTypeModule<Definitions>, TrimArrayName<Schema>>>[] : Schema extends string ? Definitions extends Record<Schema, infer NamedSchema> ? NamedSchema : StaticDecode<TImport<UnwrapTypeModule<Definitions>, Schema>> : unknown; | ||
export type UnwrapBodySchema<Schema extends TSchema | string | undefined, Definitions extends DefinitionBase['typebox'] = TModule<{}>> = undefined extends Schema ? unknown : Schema extends TSchema ? Schema extends OptionalField ? Prettify<Partial<Static<Schema>>> | null : StaticDecode<Schema> : Schema extends `${infer Key}[]` ? Definitions extends Record<Key, infer NamedSchema> ? Array<NamedSchema> : Static<TImport<UnwrapTypeModule<Definitions>, TrimArrayName<Schema>>>[] : Schema extends string ? Definitions extends Record<Schema, infer NamedSchema> ? NamedSchema : Static<TImport<UnwrapTypeModule<Definitions>, Schema>> : unknown; | ||
export type IsNull<T> = [T] extends [null] ? true : false; | ||
@@ -270,3 +271,3 @@ export type IsUnknown<T> = unknown extends T ? IsNull<T> extends false ? true : false : false; | ||
export interface InputSchema<Name extends string = string> { | ||
body?: TSchema | Name; | ||
body?: TSchema | Name | `${Name}[]`; | ||
headers?: TObject | TNull | TUndefined | Name; | ||
@@ -276,3 +277,3 @@ query?: TObject | TNull | TUndefined | Name; | ||
cookie?: TObject | TNull | TUndefined | Name; | ||
response?: TSchema | Record<number, TSchema> | Name | Record<number, Name | TSchema>; | ||
response?: TSchema | Record<number, TSchema> | `${Name}[]` | Name | Record<number, `${Name}[]` | Name | TSchema>; | ||
} | ||
@@ -279,0 +280,0 @@ export interface MergeSchema<A extends RouteSchema, B extends RouteSchema, Path extends string = ''> { |
@@ -197,2 +197,5 @@ import type { BunFile } from 'bun'; | ||
export declare const decompressHistoryHook: (hook: Partial<LifeCycleStore>) => LifeCycleStore; | ||
export declare const encodePath: (path: string, { dynamic }?: { | ||
dynamic?: boolean | undefined; | ||
}) => string; | ||
export {}; |
{ | ||
"name": "elysia", | ||
"description": "Ergonomic Framework for Human", | ||
"version": "1.2.12", | ||
"version": "1.2.13", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "saltyAom", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1862729
29939