elysia
Advanced tools
Comparing version 1.0.6 to 1.0.7
import { type Elysia } from '.'; | ||
import type { TAnySchema } from '@sinclair/typebox'; | ||
import { Sucrose } from './sucrose'; | ||
import type { ComposedHandler, Handler, LifeCycleStore, SchemaValidator } from './types'; | ||
import type { ComposedHandler, Handler, HookContainer, LifeCycleStore, SchemaValidator } from './types'; | ||
export declare const hasReturn: (fnLiteral: string) => boolean; | ||
@@ -9,3 +9,3 @@ export declare const hasType: (type: string, schema: TAnySchema) => any; | ||
export declare const hasTransform: (schema: TAnySchema) => any; | ||
export declare const isAsync: (fn: Function) => boolean; | ||
export declare const isAsync: (v: Function | HookContainer) => boolean; | ||
export declare const composeHandler: ({ app, path, method, localHook, hooks, validator, handler, allowMeta, appInference: { event: eventInference, trace: traceInference } }: { | ||
@@ -12,0 +12,0 @@ app: Elysia<any, any, any, any, any, any, any, any>; |
@@ -1359,3 +1359,3 @@ "use strict"; | ||
for (let i = 0; i < app.event.request.length; i++) { | ||
const onRequest = app.event.request[i]; | ||
const onRequest = app.event.request[i].fn; | ||
let response2 = onRequest(context); | ||
@@ -1409,3 +1409,4 @@ if (response2 instanceof Promise) | ||
for (let i = 0; i < hooks.parse.length; i++) { | ||
let temp = hooks.parse[i](context, contentType); | ||
const hook = hooks.parse[i].fn; | ||
let temp = hook(context, contentType); | ||
if (temp instanceof Promise) | ||
@@ -1468,4 +1469,5 @@ temp = await temp; | ||
for (let i = 0; i < hooks.transform.length; i++) { | ||
const operation = hooks.transform[i](context); | ||
if (hooks.transform[i].$elysia === "derive") { | ||
const hook = hooks.transform[i]; | ||
const operation = hook.fn(context); | ||
if (hook.subType === "derive") { | ||
if (operation instanceof Promise) | ||
@@ -1517,3 +1519,3 @@ Object.assign(context, await operation); | ||
for (let i = 0; i < hooks.beforeHandle.length; i++) { | ||
let response2 = hooks.beforeHandle[i](context); | ||
let response2 = hooks.beforeHandle[i].fn(context); | ||
if (response2 instanceof Promise) | ||
@@ -1525,3 +1527,3 @@ response2 = await response2; | ||
for (let i2 = 0; i2 < hooks.afterHandle.length; i2++) { | ||
let newResponse = hooks.afterHandle[i2]( | ||
let newResponse = hooks.afterHandle[i2].fn( | ||
context | ||
@@ -1554,3 +1556,3 @@ ); | ||
for (let i = 0; i < hooks.afterHandle.length; i++) { | ||
let newResponse = hooks.afterHandle[i]( | ||
let newResponse = hooks.afterHandle[i].fn( | ||
context | ||
@@ -1602,3 +1604,3 @@ ); | ||
for (const onResponse of app.event.onResponse) | ||
await onResponse(context); | ||
await onResponse.fn(context); | ||
} | ||
@@ -1610,3 +1612,4 @@ }; | ||
for (let i = 0; i < app.event.error.length; i++) { | ||
let response = app.event.error[i](errorContext); | ||
const hook = app.event.error[i]; | ||
let response = hook.fn(errorContext); | ||
if (response instanceof Promise) | ||
@@ -1613,0 +1616,0 @@ response = await response; |
@@ -254,6 +254,4 @@ "use strict"; | ||
inference.query = true; | ||
if (["return"].some( | ||
(type) => accessor(type + " " + alias, "query").some( | ||
(key) => code.includes(key) | ||
) | ||
if (code.includes("return " + alias) || accessor("return " + alias, "query").some( | ||
(key) => code.includes(key) | ||
)) { | ||
@@ -453,3 +451,6 @@ inference.query = true; | ||
events.push(...lifeCycle.onResponse); | ||
for (const event of events) { | ||
for (const e of events) { | ||
if (!e) | ||
continue; | ||
const event = "fn" in e ? e.fn : e; | ||
const [parameter, body] = separateFunction(event.toString()); | ||
@@ -456,0 +457,0 @@ const rootParameters = findParameterReference(parameter, inference); |
@@ -1,2 +0,2 @@ | ||
import type { TraceHandler, TraceReporter, TraceStream } from './types'; | ||
export declare const createTraceListener: (getReporter: () => TraceReporter, totalListener: number, handler: TraceHandler<any, any>) => (trace: TraceStream) => Promise<void>; | ||
import type { HookContainer, TraceHandler, TraceReporter, TraceStream } from './types'; | ||
export declare const createTraceListener: (getReporter: () => TraceReporter, totalListener: number, handler: TraceHandler<any, any> | HookContainer<TraceHandler<any, any>>) => (trace: TraceStream) => Promise<void>; |
@@ -120,2 +120,4 @@ "use strict"; | ||
var createTraceListener = (getReporter, totalListener, handler) => { | ||
if (typeof handler === "object") | ||
handler = handler.fn; | ||
return async function trace(trace) { | ||
@@ -122,0 +124,0 @@ if (trace.event !== "request" || trace.type !== "begin") |
@@ -160,15 +160,21 @@ /// <reference types="bun-types" /> | ||
} | ||
export type HookContainer<T extends Function = Function> = { | ||
checksum?: number; | ||
scope?: LifeCycleType; | ||
subType?: 'derive' | 'resolve' | (string & {}); | ||
fn: T; | ||
}; | ||
export interface LifeCycleStore { | ||
type?: ContentType; | ||
start: GracefulHandler<any>[]; | ||
request: PreHandler<any, any>[]; | ||
parse: BodyHandler<any, any>[]; | ||
transform: TransformHandler<any, any>[]; | ||
beforeHandle: OptionalHandler<any, any>[]; | ||
afterHandle: AfterHandler<any, any>[]; | ||
mapResponse: MapResponse<any, any>[]; | ||
onResponse: VoidHandler<any, any>[]; | ||
trace: TraceHandler<any, any>[]; | ||
error: ErrorHandler<any, any, any>[]; | ||
stop: GracefulHandler<any>[]; | ||
start: HookContainer<GracefulHandler<any>>[]; | ||
request: HookContainer<PreHandler<any, any>>[]; | ||
parse: HookContainer<BodyHandler<any, any>>[]; | ||
transform: HookContainer<TransformHandler<any, any>>[]; | ||
beforeHandle: HookContainer<OptionalHandler<any, any>>[]; | ||
afterHandle: HookContainer<AfterHandler<any, any>>[]; | ||
mapResponse: HookContainer<MapResponse<any, any>>[]; | ||
onResponse: HookContainer<VoidHandler<any, any>>[]; | ||
trace: HookContainer<TraceHandler<any, any>>[]; | ||
error: HookContainer<ErrorHandler<any, any, any>>[]; | ||
stop: HookContainer<GracefulHandler<any>>[]; | ||
} | ||
@@ -258,5 +264,2 @@ export type LifeCycleEvent = 'start' | 'request' | 'parse' | 'transform' | 'beforeHandle' | 'afterHandle' | 'response' | 'error' | 'stop'; | ||
}, BasePath>>): MaybePromise<void>; | ||
$elysiaHookType?: LifeCycleType; | ||
$elysiaChecksum?: number; | ||
$elysia?: 'derive' | 'resolve' | (string & {}); | ||
}; | ||
@@ -300,4 +303,2 @@ export type TraceEvent = 'request' | 'parse' | 'transform' | 'beforeHandle' | 'afterHandle' | 'error' | 'response' extends infer Events extends string ? Events | `${Events}.unit` | 'handle' | 'exit' : never; | ||
}>): MaybePromise<void>; | ||
$elysiaHookType?: LifeCycleType; | ||
$elysiaChecksum?: number; | ||
}; | ||
@@ -471,7 +472,2 @@ export type TraceListener = EventEmitter<{ | ||
}>; | ||
export type ElysiaFn = { | ||
(...a: any[]): any; | ||
$elysiaHookType?: LifeCycleType; | ||
$elysiaChecksum?: number; | ||
}; | ||
export interface MacroManager<in out TypedRoute extends RouteSchema = {}, in out Singleton extends SingletonBase = { | ||
@@ -523,6 +519,3 @@ decorator: {}; | ||
} | ||
export type MacroQueue = { | ||
(manager: MacroManager<any, any, any>): unknown; | ||
$elysiaChecksum?: number; | ||
}[]; | ||
export type MacroQueue = HookContainer<(manager: MacroManager<any, any, any>) => unknown>; | ||
type _CreateEden<Path extends string, Property extends Record<string, unknown> = {}> = Path extends `${infer Start}/${infer Rest}` ? { | ||
@@ -529,0 +522,0 @@ [x in Start]: _CreateEden<Rest, Property>; |
import { TSchema } from '@sinclair/typebox'; | ||
import { TypeCheck } from '@sinclair/typebox/compiler'; | ||
import type { LifeCycleStore, LocalHook, MaybeArray, InputSchema, ElysiaFn, LifeCycleType } from './types'; | ||
import type { LifeCycleStore, LocalHook, MaybeArray, InputSchema, LifeCycleType, HookContainer } from './types'; | ||
import type { CookieOptions } from './cookies'; | ||
@@ -10,3 +10,3 @@ export declare const replaceUrlPath: (url: string, pathname: string) => string; | ||
export declare const mergeCookie: <const A extends Object, const B extends Object>(a: A, b: B) => A & B; | ||
export declare const mergeObjectArray: <T extends ElysiaFn>(a?: T | T[], b?: T | T[]) => T[]; | ||
export declare const mergeObjectArray: <T extends HookContainer>(a?: T | T[], b?: T | T[]) => T[]; | ||
export declare const primitiveHooks: readonly ["start", "request", "parse", "transform", "resolve", "beforeHandle", "afterHandle", "onResponse", "mapResponse", "trace", "error", "stop", "body", "headers", "params", "query", "response", "type", "detail"]; | ||
@@ -16,3 +16,5 @@ export declare const mergeResponse: (a: InputSchema['response'], b: InputSchema['response']) => string | TSchema | { | ||
} | undefined; | ||
export declare const mergeHook: (a?: LocalHook<any, any, any, any, any, any, any> | LifeCycleStore, b?: LocalHook<any, any, any, any, any, any, any>) => LifeCycleStore; | ||
export declare const mergeHook: (a?: LifeCycleStore, b?: LocalHook<any, any, any, any, any, any, any>, { allowMacro }?: { | ||
allowMacro?: boolean | undefined; | ||
}) => LifeCycleStore; | ||
export declare const getSchemaValidator: (s: TSchema | string | undefined, { models, additionalProperties, dynamic }: { | ||
@@ -37,5 +39,5 @@ models?: Record<string, TSchema> | undefined; | ||
export declare const mergeLifeCycle: (a: LifeCycleStore, b: LifeCycleStore | LocalHook<any, any, any, any, any, any, any>, checksum?: number) => LifeCycleStore; | ||
export declare const asHookType: <T extends MaybeArray<ElysiaFn> | undefined>(fn: T, inject: LifeCycleType, { skipIfHasType }?: { | ||
export declare const asHookType: (fn: HookContainer, inject: LifeCycleType, { skipIfHasType }?: { | ||
skipIfHasType?: boolean | undefined; | ||
}) => T; | ||
}) => HookContainer; | ||
export declare const filterGlobalHook: (hook: LocalHook<any, any, any, any, any, any, any>) => LocalHook<any, any, any, any, any, any, any>; | ||
@@ -177,3 +179,3 @@ export declare const StatusMap: { | ||
stack?: 'global' | 'local'; | ||
} | MaybeArray<Function>, fn?: MaybeArray<Function>) => void; | ||
} | MaybeArray<HookContainer>, fn?: MaybeArray<HookContainer>) => void; | ||
export declare const isNumericString: (message: string) => boolean; | ||
@@ -197,1 +199,4 @@ export declare class PromiseGroup implements PromiseLike<void> { | ||
} | ||
export declare const fnToContainer: (fn: MaybeArray<Function | HookContainer>) => MaybeArray<HookContainer>; | ||
export declare const localHookToLifeCycleStore: (a: LocalHook<any, any, any, any, any>) => LifeCycleStore; | ||
export declare const lifeCycleToFn: (a: LifeCycleStore) => LocalHook<any, any, any, any, any, any, any>; |
@@ -40,2 +40,3 @@ "use strict"; | ||
filterGlobalHook: () => filterGlobalHook, | ||
fnToContainer: () => fnToContainer, | ||
getCookieValidator: () => getCookieValidator, | ||
@@ -45,2 +46,4 @@ getResponseSchemaValidator: () => getResponseSchemaValidator, | ||
isNumericString: () => isNumericString, | ||
lifeCycleToFn: () => lifeCycleToFn, | ||
localHookToLifeCycleStore: () => localHookToLifeCycleStore, | ||
mergeCookie: () => mergeCookie, | ||
@@ -476,2 +479,4 @@ mergeDeep: () => mergeDeep, | ||
return []; | ||
if (!b) | ||
return a; | ||
const array = []; | ||
@@ -485,7 +490,7 @@ const checksums = []; | ||
array.push(item); | ||
if (item.$elysiaChecksum) | ||
checksums.push(item.$elysiaChecksum); | ||
if (item.checksum) | ||
checksums.push(item.checksum); | ||
} | ||
for (const item of b) | ||
if (!checksums.includes(item?.$elysiaChecksum)) | ||
if (!checksums.includes(item.checksum)) | ||
array.push(item); | ||
@@ -525,6 +530,9 @@ return array; | ||
}; | ||
var mergeHook = (a, b) => { | ||
var mergeHook = (a, b, { allowMacro = false } = {}) => { | ||
const rest = allowMacro ? { | ||
...a, | ||
...b | ||
} : void 0; | ||
return { | ||
...a, | ||
...b, | ||
...rest, | ||
// Merge local hook first | ||
@@ -681,6 +689,6 @@ // @ts-ignore | ||
const fn = x; | ||
if (checksum2 && !fn.$elysiaChecksum) | ||
fn.$elysiaChecksum = checksum2; | ||
if (fn.$elysiaHookType === "scoped") | ||
fn.$elysiaHookType = "local"; | ||
if (checksum2 && !fn.checksum) | ||
fn.checksum = checksum2; | ||
if (fn.scope === "scoped") | ||
fn.scope = "local"; | ||
return fn; | ||
@@ -690,6 +698,6 @@ } | ||
for (const fn of fns) { | ||
if (checksum2 && !fn.$elysiaChecksum) | ||
fn.$elysiaChecksum = checksum2; | ||
if (fn.$elysiaHookType === "scoped") | ||
fn.$elysiaHookType = "local"; | ||
if (checksum2 && !fn.checksum) | ||
fn.checksum = checksum2; | ||
if (fn.scope === "scoped") | ||
fn.scope = "local"; | ||
} | ||
@@ -699,8 +707,20 @@ return fns; | ||
return { | ||
...a, | ||
...b, | ||
start: mergeObjectArray(a.start, injectChecksum(b?.start)), | ||
request: mergeObjectArray(a.request, injectChecksum(b?.request)), | ||
parse: mergeObjectArray(a.parse, injectChecksum(b?.parse)), | ||
transform: mergeObjectArray(a.transform, injectChecksum(b?.transform)), | ||
// ...a, | ||
// ...b, | ||
start: mergeObjectArray( | ||
a.start, | ||
injectChecksum(b?.start) | ||
), | ||
request: mergeObjectArray( | ||
a.request, | ||
injectChecksum(b?.request) | ||
), | ||
parse: mergeObjectArray( | ||
a.parse, | ||
injectChecksum(b?.parse) | ||
), | ||
transform: mergeObjectArray( | ||
a.transform, | ||
injectChecksum(b?.transform) | ||
), | ||
beforeHandle: mergeObjectArray( | ||
@@ -724,4 +744,10 @@ a.beforeHandle, | ||
trace: a.trace, | ||
error: mergeObjectArray(a.error, injectChecksum(b?.error)), | ||
stop: mergeObjectArray(a.stop, injectChecksum(b?.stop)) | ||
error: mergeObjectArray( | ||
a.error, | ||
injectChecksum(b?.error) | ||
), | ||
stop: mergeObjectArray( | ||
a.stop, | ||
injectChecksum(b?.stop) | ||
) | ||
}; | ||
@@ -732,16 +758,14 @@ }; | ||
return fn; | ||
if (typeof fn === "function") { | ||
if (!Array.isArray(fn)) { | ||
if (skipIfHasType) | ||
fn.$elysiaHookType ??= inject; | ||
fn.scope ??= inject; | ||
else | ||
fn.$elysiaHookType = inject; | ||
fn.scope = inject; | ||
return fn; | ||
} | ||
if (!Array.isArray(fn)) | ||
return fn; | ||
for (const x of fn) | ||
if (skipIfHasType) | ||
x.$elysiaHookType ??= inject; | ||
x.scope ??= inject; | ||
else | ||
x.$elysiaHookType = inject; | ||
x.scope = inject; | ||
return fn; | ||
@@ -752,18 +776,18 @@ }; | ||
return fn; | ||
if (typeof fn === "function") | ||
switch (fn.$elysiaHookType) { | ||
if (!Array.isArray(fn)) | ||
switch (fn.scope) { | ||
case "global": | ||
case "scoped": | ||
return fn; | ||
return { ...fn }; | ||
default: | ||
return void 0; | ||
return { fn }; | ||
} | ||
if (!Array.isArray(fn)) | ||
return []; | ||
const array = []; | ||
for (const x of fn) | ||
switch (x.$elysiaHookType) { | ||
switch (x.scope) { | ||
case "global": | ||
case "scoped": | ||
array.push(x); | ||
array.push({ | ||
...x | ||
}); | ||
break; | ||
@@ -906,3 +930,7 @@ } | ||
}) => (stackName) => (type, fn) => { | ||
if (typeof type === "function" || Array.isArray(type)) { | ||
if (typeof type === "function") | ||
type = { | ||
fn: type | ||
}; | ||
if ("fn" in type || Array.isArray(type)) { | ||
if (!localHook[stackName]) | ||
@@ -919,2 +947,4 @@ localHook[stackName] = []; | ||
const { insert = "after", stack = "local" } = type; | ||
if (typeof fn === "function") | ||
fn = { fn }; | ||
if (stack === "global") { | ||
@@ -1007,2 +1037,52 @@ if (!Array.isArray(fn)) { | ||
}; | ||
var fnToContainer = (fn) => { | ||
if (!fn) | ||
return fn; | ||
if (!Array.isArray(fn)) { | ||
if (typeof fn === "function") | ||
return { fn }; | ||
else if ("fn" in fn) | ||
return fn; | ||
} | ||
const fns = []; | ||
for (const x of fn) { | ||
if (typeof x === "function") | ||
fns.push({ fn: x }); | ||
else if ("fn" in x) | ||
fns.push(x); | ||
} | ||
return fns; | ||
}; | ||
var localHookToLifeCycleStore = (a) => { | ||
return { | ||
...a, | ||
start: fnToContainer(a?.start), | ||
request: fnToContainer(a?.request), | ||
parse: fnToContainer(a?.parse), | ||
transform: fnToContainer(a?.transform), | ||
beforeHandle: fnToContainer(a?.beforeHandle), | ||
afterHandle: fnToContainer(a?.afterHandle), | ||
onResponse: fnToContainer(a?.onResponse), | ||
mapResponse: fnToContainer(a?.mapResponse), | ||
trace: fnToContainer(a?.trace), | ||
error: fnToContainer(a?.error), | ||
stop: fnToContainer(a?.stop) | ||
}; | ||
}; | ||
var lifeCycleToFn = (a) => { | ||
return { | ||
...a, | ||
start: a.start?.map((x) => x.fn), | ||
request: a.request?.map((x) => x.fn), | ||
parse: a.parse?.map((x) => x.fn), | ||
transform: a.transform?.map((x) => x.fn), | ||
beforeHandle: a.beforeHandle?.map((x) => x.fn), | ||
afterHandle: a.afterHandle?.map((x) => x.fn), | ||
onResponse: a.onResponse?.map((x) => x.fn), | ||
mapResponse: a.mapResponse?.map((x) => x.fn), | ||
trace: a.trace?.map((x) => x.fn), | ||
error: a.error?.map((x) => x.fn), | ||
stop: a.stop?.map((x) => x.fn) | ||
}; | ||
}; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -1017,2 +1097,3 @@ 0 && (module.exports = { | ||
filterGlobalHook, | ||
fnToContainer, | ||
getCookieValidator, | ||
@@ -1022,2 +1103,4 @@ getResponseSchemaValidator, | ||
isNumericString, | ||
lifeCycleToFn, | ||
localHookToLifeCycleStore, | ||
mergeCookie, | ||
@@ -1024,0 +1107,0 @@ mergeDeep, |
import { type Elysia } from '.'; | ||
import type { TAnySchema } from '@sinclair/typebox'; | ||
import { Sucrose } from './sucrose'; | ||
import type { ComposedHandler, Handler, LifeCycleStore, SchemaValidator } from './types'; | ||
import type { ComposedHandler, Handler, HookContainer, LifeCycleStore, SchemaValidator } from './types'; | ||
export declare const hasReturn: (fnLiteral: string) => boolean; | ||
@@ -9,3 +9,3 @@ export declare const hasType: (type: string, schema: TAnySchema) => any; | ||
export declare const hasTransform: (schema: TAnySchema) => any; | ||
export declare const isAsync: (fn: Function) => boolean; | ||
export declare const isAsync: (v: Function | HookContainer) => boolean; | ||
export declare const composeHandler: ({ app, path, method, localHook, hooks, validator, handler, allowMeta, appInference: { event: eventInference, trace: traceInference } }: { | ||
@@ -12,0 +12,0 @@ app: Elysia<any, any, any, any, any, any, any, any>; |
@@ -1,2 +0,2 @@ | ||
import type { TraceHandler, TraceReporter, TraceStream } from './types'; | ||
export declare const createTraceListener: (getReporter: () => TraceReporter, totalListener: number, handler: TraceHandler<any, any>) => (trace: TraceStream) => Promise<void>; | ||
import type { HookContainer, TraceHandler, TraceReporter, TraceStream } from './types'; | ||
export declare const createTraceListener: (getReporter: () => TraceReporter, totalListener: number, handler: TraceHandler<any, any> | HookContainer<TraceHandler<any, any>>) => (trace: TraceStream) => Promise<void>; |
@@ -160,15 +160,21 @@ /// <reference types="bun-types" /> | ||
} | ||
export type HookContainer<T extends Function = Function> = { | ||
checksum?: number; | ||
scope?: LifeCycleType; | ||
subType?: 'derive' | 'resolve' | (string & {}); | ||
fn: T; | ||
}; | ||
export interface LifeCycleStore { | ||
type?: ContentType; | ||
start: GracefulHandler<any>[]; | ||
request: PreHandler<any, any>[]; | ||
parse: BodyHandler<any, any>[]; | ||
transform: TransformHandler<any, any>[]; | ||
beforeHandle: OptionalHandler<any, any>[]; | ||
afterHandle: AfterHandler<any, any>[]; | ||
mapResponse: MapResponse<any, any>[]; | ||
onResponse: VoidHandler<any, any>[]; | ||
trace: TraceHandler<any, any>[]; | ||
error: ErrorHandler<any, any, any>[]; | ||
stop: GracefulHandler<any>[]; | ||
start: HookContainer<GracefulHandler<any>>[]; | ||
request: HookContainer<PreHandler<any, any>>[]; | ||
parse: HookContainer<BodyHandler<any, any>>[]; | ||
transform: HookContainer<TransformHandler<any, any>>[]; | ||
beforeHandle: HookContainer<OptionalHandler<any, any>>[]; | ||
afterHandle: HookContainer<AfterHandler<any, any>>[]; | ||
mapResponse: HookContainer<MapResponse<any, any>>[]; | ||
onResponse: HookContainer<VoidHandler<any, any>>[]; | ||
trace: HookContainer<TraceHandler<any, any>>[]; | ||
error: HookContainer<ErrorHandler<any, any, any>>[]; | ||
stop: HookContainer<GracefulHandler<any>>[]; | ||
} | ||
@@ -258,5 +264,2 @@ export type LifeCycleEvent = 'start' | 'request' | 'parse' | 'transform' | 'beforeHandle' | 'afterHandle' | 'response' | 'error' | 'stop'; | ||
}, BasePath>>): MaybePromise<void>; | ||
$elysiaHookType?: LifeCycleType; | ||
$elysiaChecksum?: number; | ||
$elysia?: 'derive' | 'resolve' | (string & {}); | ||
}; | ||
@@ -300,4 +303,2 @@ export type TraceEvent = 'request' | 'parse' | 'transform' | 'beforeHandle' | 'afterHandle' | 'error' | 'response' extends infer Events extends string ? Events | `${Events}.unit` | 'handle' | 'exit' : never; | ||
}>): MaybePromise<void>; | ||
$elysiaHookType?: LifeCycleType; | ||
$elysiaChecksum?: number; | ||
}; | ||
@@ -471,7 +472,2 @@ export type TraceListener = EventEmitter<{ | ||
}>; | ||
export type ElysiaFn = { | ||
(...a: any[]): any; | ||
$elysiaHookType?: LifeCycleType; | ||
$elysiaChecksum?: number; | ||
}; | ||
export interface MacroManager<in out TypedRoute extends RouteSchema = {}, in out Singleton extends SingletonBase = { | ||
@@ -523,6 +519,3 @@ decorator: {}; | ||
} | ||
export type MacroQueue = { | ||
(manager: MacroManager<any, any, any>): unknown; | ||
$elysiaChecksum?: number; | ||
}[]; | ||
export type MacroQueue = HookContainer<(manager: MacroManager<any, any, any>) => unknown>; | ||
type _CreateEden<Path extends string, Property extends Record<string, unknown> = {}> = Path extends `${infer Start}/${infer Rest}` ? { | ||
@@ -529,0 +522,0 @@ [x in Start]: _CreateEden<Rest, Property>; |
import { TSchema } from '@sinclair/typebox'; | ||
import { TypeCheck } from '@sinclair/typebox/compiler'; | ||
import type { LifeCycleStore, LocalHook, MaybeArray, InputSchema, ElysiaFn, LifeCycleType } from './types'; | ||
import type { LifeCycleStore, LocalHook, MaybeArray, InputSchema, LifeCycleType, HookContainer } from './types'; | ||
import type { CookieOptions } from './cookies'; | ||
@@ -10,3 +10,3 @@ export declare const replaceUrlPath: (url: string, pathname: string) => string; | ||
export declare const mergeCookie: <const A extends Object, const B extends Object>(a: A, b: B) => A & B; | ||
export declare const mergeObjectArray: <T extends ElysiaFn>(a?: T | T[], b?: T | T[]) => T[]; | ||
export declare const mergeObjectArray: <T extends HookContainer>(a?: T | T[], b?: T | T[]) => T[]; | ||
export declare const primitiveHooks: readonly ["start", "request", "parse", "transform", "resolve", "beforeHandle", "afterHandle", "onResponse", "mapResponse", "trace", "error", "stop", "body", "headers", "params", "query", "response", "type", "detail"]; | ||
@@ -16,3 +16,5 @@ export declare const mergeResponse: (a: InputSchema['response'], b: InputSchema['response']) => string | TSchema | { | ||
} | undefined; | ||
export declare const mergeHook: (a?: LocalHook<any, any, any, any, any, any, any> | LifeCycleStore, b?: LocalHook<any, any, any, any, any, any, any>) => LifeCycleStore; | ||
export declare const mergeHook: (a?: LifeCycleStore, b?: LocalHook<any, any, any, any, any, any, any>, { allowMacro }?: { | ||
allowMacro?: boolean | undefined; | ||
}) => LifeCycleStore; | ||
export declare const getSchemaValidator: (s: TSchema | string | undefined, { models, additionalProperties, dynamic }: { | ||
@@ -37,5 +39,5 @@ models?: Record<string, TSchema> | undefined; | ||
export declare const mergeLifeCycle: (a: LifeCycleStore, b: LifeCycleStore | LocalHook<any, any, any, any, any, any, any>, checksum?: number) => LifeCycleStore; | ||
export declare const asHookType: <T extends MaybeArray<ElysiaFn> | undefined>(fn: T, inject: LifeCycleType, { skipIfHasType }?: { | ||
export declare const asHookType: (fn: HookContainer, inject: LifeCycleType, { skipIfHasType }?: { | ||
skipIfHasType?: boolean | undefined; | ||
}) => T; | ||
}) => HookContainer; | ||
export declare const filterGlobalHook: (hook: LocalHook<any, any, any, any, any, any, any>) => LocalHook<any, any, any, any, any, any, any>; | ||
@@ -177,3 +179,3 @@ export declare const StatusMap: { | ||
stack?: 'global' | 'local'; | ||
} | MaybeArray<Function>, fn?: MaybeArray<Function>) => void; | ||
} | MaybeArray<HookContainer>, fn?: MaybeArray<HookContainer>) => void; | ||
export declare const isNumericString: (message: string) => boolean; | ||
@@ -197,1 +199,4 @@ export declare class PromiseGroup implements PromiseLike<void> { | ||
} | ||
export declare const fnToContainer: (fn: MaybeArray<Function | HookContainer>) => MaybeArray<HookContainer>; | ||
export declare const localHookToLifeCycleStore: (a: LocalHook<any, any, any, any, any>) => LifeCycleStore; | ||
export declare const lifeCycleToFn: (a: LifeCycleStore) => LocalHook<any, any, any, any, any, any, any>; |
{ | ||
"name": "elysia", | ||
"description": "Ergonomic Framework for Human", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "saltyAom", |
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 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 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
1957129
40676
232