elysia 2.0.0-exp.37 → 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 +2 -2
- package/dist/compile/lexer.d.ts +1 -1
- package/dist/type/bridge.d.ts +6 -6
- package/dist/type/types.d.ts +1 -1
- package/dist/type/validator/index.d.ts +1 -1
- package/dist/types.d.ts +23 -4
- package/package.json +1 -1
package/dist/base.d.ts
CHANGED
|
@@ -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>>;
|
package/dist/compile/lexer.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region src/compile/lexer.d.ts
|
|
2
|
-
declare const isSpace: (ch: string) => ch is "
|
|
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/type/bridge.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { Intersect as Intersect$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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;
|
package/dist/type/types.d.ts
CHANGED
|
@@ -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'}`;
|
|
@@ -2,8 +2,8 @@ import { MaybePromise } from "../../types.js";
|
|
|
2
2
|
import { Validator as Validator$1, ValidatorOptions } from "../../validator/index.js";
|
|
3
3
|
import { TypeBoxValidatorCache } from "./validator-cache.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
|
@@ -10,8 +10,8 @@ import { Context, ErrorContext, LifecycleContext, PreContext } from "./context.j
|
|
|
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
|
-
|
|
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
|
|
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 ? {
|