elysia 2.0.0-exp.13 → 2.0.0-exp.15
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/adapter/bun/index.d.ts +1 -1
- package/dist/adapter/constants.d.ts +1 -1
- package/dist/adapter/index.d.ts +1 -1
- package/dist/adapter/web-standard/index.d.ts +1 -1
- package/dist/base.d.ts +2 -5
- package/dist/base.js +5 -5
- package/dist/base.mjs +5 -5
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -0
- package/dist/index.mjs +2 -2
- package/dist/type/bridge.d.ts +7 -7
- package/dist/type/types.d.ts +1 -1
- package/dist/type/validator/index.d.ts +1 -1
- package/dist/types.d.ts +15 -13
- package/dist/utils.d.ts +5 -1
- package/dist/utils.js +12 -0
- package/dist/utils.mjs +12 -1
- package/package.json +1 -1
|
@@ -6,7 +6,7 @@ import { AnyElysia } from "../../base.js";
|
|
|
6
6
|
declare function collectStaticRoutes(app: AnyElysia): readonly [Record<string, Record<string, Response>>, Promise<void>[]] | undefined;
|
|
7
7
|
declare const BunAdapter: {
|
|
8
8
|
parse: {
|
|
9
|
-
default: (context: Context, contentType: string) => string | unknown[] |
|
|
9
|
+
default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | Promise<unknown[] | Record<string | number | symbol, undefined>> | Promise<ArrayBuffer> | Promise<Record<string, unknown>> | Promise<string> | undefined;
|
|
10
10
|
json: (context: Context) => MaybePromise<Record<keyof any, undefined> | unknown[]>;
|
|
11
11
|
text: (context: Context) => MaybePromise<string>;
|
|
12
12
|
urlencoded: (context: Context) => MaybePromise<Record<string, string | string[]>>;
|
|
@@ -5,7 +5,7 @@ import { AnyElysia } from "../base.js";
|
|
|
5
5
|
//#region src/adapter/constants.d.ts
|
|
6
6
|
declare const defaultAdapter: {
|
|
7
7
|
parse: {
|
|
8
|
-
default: (context: Context, contentType: string) => string | unknown[] |
|
|
8
|
+
default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | Promise<unknown[] | Record<string | number | symbol, undefined>> | Promise<ArrayBuffer> | Promise<Record<string, unknown>> | Promise<string> | undefined;
|
|
9
9
|
json: (context: Context) => MaybePromise<Record<keyof any, undefined> | unknown[]>;
|
|
10
10
|
text: (context: Context) => MaybePromise<string>;
|
|
11
11
|
urlencoded: (context: Context) => MaybePromise<Record<string, string | string[]>>;
|
package/dist/adapter/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { AnyElysia } from "../base.js";
|
|
|
7
7
|
//#region src/adapter/index.d.ts
|
|
8
8
|
declare function createAdapter(adapter: ElysiaAdapterOptions): {
|
|
9
9
|
parse: {
|
|
10
|
-
default: (context: Context, contentType: string) => string | unknown[] |
|
|
10
|
+
default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | Promise<unknown[] | Record<string | number | symbol, undefined>> | Promise<ArrayBuffer> | Promise<Record<string, unknown>> | Promise<string> | undefined;
|
|
11
11
|
json: (context: Context) => MaybePromise<Record<keyof any, undefined> | unknown[]>;
|
|
12
12
|
text: (context: Context) => MaybePromise<string>;
|
|
13
13
|
urlencoded: (context: Context) => MaybePromise<Record<string, string | string[]>>;
|
|
@@ -5,7 +5,7 @@ import { AnyElysia } from "../../base.js";
|
|
|
5
5
|
//#region src/adapter/web-standard/index.d.ts
|
|
6
6
|
declare const WebStandardAdapter: {
|
|
7
7
|
parse: {
|
|
8
|
-
default: (context: Context, contentType: string) => string | unknown[] |
|
|
8
|
+
default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | Promise<unknown[] | Record<string | number | symbol, undefined>> | Promise<ArrayBuffer> | Promise<Record<string, unknown>> | Promise<string> | undefined;
|
|
9
9
|
json: (context: Context) => MaybePromise<Record<keyof any, undefined> | unknown[]>;
|
|
10
10
|
text: (context: Context) => MaybePromise<string>;
|
|
11
11
|
urlencoded: (context: Context) => MaybePromise<Record<string, string | string[]>>;
|
package/dist/base.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ElysiaStatus } from "./error.js";
|
|
|
2
2
|
import { TraceHandler } from "./trace.js";
|
|
3
3
|
import { AnySchema } from "./type/types.js";
|
|
4
4
|
import { ListenCallback, Serve, Server } from "./universal/server.js";
|
|
5
|
-
import { AddRoute, AddWSRoute, AfterHandler, AfterResponseHandler, AnyErrorConstructor, AnyLocalHook, BodyHandler, CompiledHandler, CreateEden, DefaultEphemeral, DefaultMetadata, DefaultSingleton, DefinitionBase, DocumentDecoration, ElysiaConfig, ElysiaHandlerToResponseSchemaAmbiguous, EphemeralType, ErrorDefinitionEntry, ErrorHandler, EventScope, ExcludeElysiaResponse, ExtractErrorFromHandle, GracefulHandler, GuardLocalHook, HTTPMethod, InlineHandler, InlineHandlerNonMacro, InputSchema, InputSchemaKey, InternalRoute, IntersectIfObjectSchema, JoinPath, LocalHook, Macro, MacroToContext, MacroToProperty, MapResponse, MaybeArray, MaybePromise, MergeElysiaInstances, MergeSchema, MergeScopedSchemas, MetadataBase, NonResolvableMacroKey, ObjectMacroDefs, OptionalHandler, PreHandler, Prettify, PublicRoute, ResolveRouteErrors, RouteBase, SingletonBase, TransformHandler, UnionResponseStatus, UnwrapRoute, WrapFn } from "./types.js";
|
|
5
|
+
import { AddRoute, AddWSRoute, AfterHandler, AfterResponseHandler, AnyErrorConstructor, AnyLocalHook, BodyHandler, CompiledHandler, CreateEden, DefaultEphemeral, DefaultMetadata, DefaultSingleton, DefinitionBase, DocumentDecoration, ElysiaConfig, ElysiaHandlerToResponseSchemaAmbiguous, EphemeralType, ErrorDefinitionEntry, ErrorHandler, EventScope, ExcludeElysiaResponse, ExtractErrorFromHandle, GracefulHandler, GuardLocalHook, HTTPMethod, InlineHandler, InlineHandlerNonMacro, InputSchema, InputSchemaKey, InternalRoute, IntersectIfObjectSchema, JoinPath, LocalHook, Macro, MacroSchemaChannel, MacroToContext, MacroToProperty, MapResponse, MaybeArray, MaybePromise, MergeElysiaInstances, MergeSchema, MergeScopedSchemas, MetadataBase, NonResolvableMacroKey, ObjectMacroDefs, OptionalHandler, PreHandler, Prettify, PublicRoute, ResolveRouteErrors, RouteBase, SingletonBase, TransformHandler, UnionResponseStatus, UnwrapRoute, WrapFn } from "./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";
|
|
@@ -151,9 +151,6 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
151
151
|
}, Definitions, Metadata, Routes, Ephemeral, Volatile>;
|
|
152
152
|
headers(headers: Record<string, string>): this;
|
|
153
153
|
request(fn: MaybeArray<PreHandler<{}, Singleton>>): this;
|
|
154
|
-
request(scope: 'local', fn: MaybeArray<PreHandler<{}, Singleton>>): this;
|
|
155
|
-
request(scope: 'plugin', fn: MaybeArray<PreHandler<{}, Singleton>>): this;
|
|
156
|
-
request(scope: 'global', fn: MaybeArray<PreHandler<{}, Singleton>>): this;
|
|
157
154
|
parse(fn: MaybeArray<BodyHandler<MergeSchema<{}, {}, BasePath>, Singleton & {
|
|
158
155
|
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
159
156
|
}>>): this;
|
|
@@ -688,7 +685,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
688
685
|
* .get('/', ({ user }) => user, { auth: true, role: 'admin' })
|
|
689
686
|
* ```
|
|
690
687
|
*/
|
|
691
|
-
macro<const Body
|
|
688
|
+
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 & {
|
|
692
689
|
derive: Partial<Ephemeral['derive'] & Volatile['derive']>;
|
|
693
690
|
}, Definitions, Metadata['macro']>): Elysia<BasePath, Scope, Singleton, Definitions, {
|
|
694
691
|
schema: Metadata['schema'];
|
package/dist/base.js
CHANGED
|
@@ -158,8 +158,8 @@ var Elysia = class Elysia {
|
|
|
158
158
|
#onBranch(type, scopeOrFn, fn) {
|
|
159
159
|
return fn ? this.#on(type, fn, scopeOrFn) : this.#on(type, scopeOrFn);
|
|
160
160
|
}
|
|
161
|
-
request(
|
|
162
|
-
return this.#
|
|
161
|
+
request(fn) {
|
|
162
|
+
return this.#on("request", fn, "global");
|
|
163
163
|
}
|
|
164
164
|
parse(scopeOrFnOrName, fn) {
|
|
165
165
|
if (fn === void 0 && typeof scopeOrFnOrName === "string") {
|
|
@@ -330,9 +330,8 @@ var Elysia = class Elysia {
|
|
|
330
330
|
const finalize = () => {
|
|
331
331
|
const childFlat = require_utils.flattenChain(child["~hookChain"]);
|
|
332
332
|
const lifted = require_utils.nullObject();
|
|
333
|
-
if (childFlat?.request) lifted.request = childFlat.request;
|
|
334
333
|
if (childFlat?.parse) lifted.parse = childFlat.parse;
|
|
335
|
-
if (lifted.
|
|
334
|
+
if (lifted.parse) this.#pushHook(lifted);
|
|
336
335
|
return child;
|
|
337
336
|
};
|
|
338
337
|
if (child.pending) return this.#useAsync(child.modules.then(finalize));
|
|
@@ -466,7 +465,8 @@ var Elysia = class Elysia {
|
|
|
466
465
|
for (const plugin of app) this.#use(plugin);
|
|
467
466
|
return this;
|
|
468
467
|
}
|
|
469
|
-
if (app
|
|
468
|
+
if (app === this) return this;
|
|
469
|
+
if (app.pending) return this.#useAsync(app.modules.then(() => app));
|
|
470
470
|
this.#use(app);
|
|
471
471
|
return this;
|
|
472
472
|
}
|
package/dist/base.mjs
CHANGED
|
@@ -155,8 +155,8 @@ var Elysia = class Elysia {
|
|
|
155
155
|
#onBranch(type, scopeOrFn, fn) {
|
|
156
156
|
return fn ? this.#on(type, fn, scopeOrFn) : this.#on(type, scopeOrFn);
|
|
157
157
|
}
|
|
158
|
-
request(
|
|
159
|
-
return this.#
|
|
158
|
+
request(fn) {
|
|
159
|
+
return this.#on("request", fn, "global");
|
|
160
160
|
}
|
|
161
161
|
parse(scopeOrFnOrName, fn) {
|
|
162
162
|
if (fn === void 0 && typeof scopeOrFnOrName === "string") {
|
|
@@ -327,9 +327,8 @@ var Elysia = class Elysia {
|
|
|
327
327
|
const finalize = () => {
|
|
328
328
|
const childFlat = flattenChain(child["~hookChain"]);
|
|
329
329
|
const lifted = nullObject();
|
|
330
|
-
if (childFlat?.request) lifted.request = childFlat.request;
|
|
331
330
|
if (childFlat?.parse) lifted.parse = childFlat.parse;
|
|
332
|
-
if (lifted.
|
|
331
|
+
if (lifted.parse) this.#pushHook(lifted);
|
|
333
332
|
return child;
|
|
334
333
|
};
|
|
335
334
|
if (child.pending) return this.#useAsync(child.modules.then(finalize));
|
|
@@ -463,7 +462,8 @@ var Elysia = class Elysia {
|
|
|
463
462
|
for (const plugin of app) this.#use(plugin);
|
|
464
463
|
return this;
|
|
465
464
|
}
|
|
466
|
-
if (app
|
|
465
|
+
if (app === this) return this;
|
|
466
|
+
if (app.pending) return this.#useAsync(app.modules.then(() => app));
|
|
467
467
|
this.#use(app);
|
|
468
468
|
return this;
|
|
469
469
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { TypeBoxValidator } from "./type/validator/index.js";
|
|
|
11
11
|
import { TypeSystem, t } from "./type/index.js";
|
|
12
12
|
import { env } from "./universal/env.js";
|
|
13
13
|
import { SSEPayload } from "./types.js";
|
|
14
|
-
import { form, redirect, sse } from "./utils.js";
|
|
14
|
+
import { form, prefix, redirect, sse } from "./utils.js";
|
|
15
15
|
import { Context, ErrorContext, createBaseContext, createContext } from "./context.js";
|
|
16
16
|
import { Elysia } from "./base.js";
|
|
17
|
-
export { type AnySchema, type BaseSchema, Compiled, type Context, Elysia, Elysia as default, ElysiaError, ElysiaFile, ElysiaStatus, type ErrorContext, type FileTypeDetector, InternalServerError, InvalidCookieSignature, Capture as Manifest, MultiValidator, NotFound, ParseError, type SSEPayload, type StandardJSONSchemaV1Like, type StandardSchemaV1Like, StandardValidator, StatusMap, StatusMapBack, type TraceEvent, type TraceHandler, type TraceListener, type TraceProcess, type TraceStream, TypeBoxValidator, TypeSystem, ValidationError, Validator, createBaseContext, createContext, env, file, fileType, form, redirect, setFileTypeDetector, setupTypebox, sse, status, t, validationDetail };
|
|
17
|
+
export { type AnySchema, type BaseSchema, Compiled, type Context, Elysia, Elysia as default, ElysiaError, ElysiaFile, ElysiaStatus, type ErrorContext, type FileTypeDetector, InternalServerError, InvalidCookieSignature, Capture as Manifest, MultiValidator, NotFound, ParseError, type SSEPayload, type StandardJSONSchemaV1Like, type StandardSchemaV1Like, StandardValidator, StatusMap, StatusMapBack, type TraceEvent, type TraceHandler, type TraceListener, type TraceProcess, type TraceStream, TypeBoxValidator, TypeSystem, ValidationError, Validator, createBaseContext, createContext, env, file, fileType, form, prefix, redirect, setFileTypeDetector, setupTypebox, sse, status, t, validationDetail };
|
package/dist/index.js
CHANGED
|
@@ -49,6 +49,7 @@ exports.env = require_universal_env.env;
|
|
|
49
49
|
exports.file = require_universal_file.file;
|
|
50
50
|
exports.fileType = require_type_elysia_file_type.fileType;
|
|
51
51
|
exports.form = require_utils.form;
|
|
52
|
+
exports.prefix = require_utils.prefix;
|
|
52
53
|
exports.redirect = require_utils.redirect;
|
|
53
54
|
exports.setFileTypeDetector = require_type_elysia_file_type.setFileTypeDetector;
|
|
54
55
|
exports.setupTypebox = require_type_compat.setupTypebox;
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StatusMap, StatusMapBack } from "./constants.mjs";
|
|
2
2
|
import { ElysiaFile, file } from "./universal/file.mjs";
|
|
3
|
-
import { form, redirect, sse } from "./utils.mjs";
|
|
3
|
+
import { form, prefix, redirect, sse } from "./utils.mjs";
|
|
4
4
|
import { env } from "./universal/env.mjs";
|
|
5
5
|
import { ElysiaError, ElysiaStatus, InternalServerError, InvalidCookieSignature, NotFound, ParseError, ValidationError, status, validationDetail } from "./error.mjs";
|
|
6
6
|
import { createBaseContext, createContext } from "./context.mjs";
|
|
@@ -16,4 +16,4 @@ import { TypeSystem, t } from "./type/index.mjs";
|
|
|
16
16
|
var src_default = Elysia;
|
|
17
17
|
|
|
18
18
|
//#endregion
|
|
19
|
-
export { Compiled, Elysia, ElysiaError, ElysiaFile, ElysiaStatus, InternalServerError, InvalidCookieSignature, Capture as Manifest, MultiValidator, NotFound, ParseError, StandardValidator, StatusMap, StatusMapBack, TypeBoxValidator, TypeSystem, ValidationError, Validator, createBaseContext, createContext, src_default as default, env, file, fileType, form, redirect, setFileTypeDetector, setupTypebox, sse, status, t, validationDetail };
|
|
19
|
+
export { Compiled, Elysia, ElysiaError, ElysiaFile, ElysiaStatus, InternalServerError, InvalidCookieSignature, Capture as Manifest, MultiValidator, NotFound, ParseError, StandardValidator, StatusMap, StatusMapBack, TypeBoxValidator, TypeSystem, ValidationError, Validator, createBaseContext, createContext, src_default as default, env, file, fileType, form, prefix, redirect, setFileTypeDetector, setupTypebox, sse, status, t, validationDetail };
|
package/dist/type/bridge.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
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
|
-
import { Ref as Ref$1, TAny, TSchema } from "typebox/type";
|
|
7
6
|
import { Compile as Compile$1 } from "typebox/compile";
|
|
8
|
-
import {
|
|
7
|
+
import { Ref as Ref$1, TAny, TSchema } from "typebox/type";
|
|
8
|
+
import { 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
|
-
Decode: typeof Decode$
|
|
13
|
+
Decode: typeof Decode$2;
|
|
14
14
|
applyCoercions: typeof applyCoercions$1;
|
|
15
15
|
TypeBoxValidator: TypeBoxValidator$1;
|
|
16
16
|
TypeBoxValidatorCache: TypeBoxValidatorCache$1;
|
|
@@ -21,12 +21,12 @@ interface TypeboxModule {
|
|
|
21
21
|
coerceBody: typeof coerceBody$1;
|
|
22
22
|
hasTypes: typeof hasTypes$1;
|
|
23
23
|
HasCodec: typeof HasCodec$1;
|
|
24
|
-
Intersect: typeof Intersect$
|
|
24
|
+
Intersect: typeof Intersect$2;
|
|
25
25
|
Default: typeof Default$1;
|
|
26
26
|
Ref: typeof Ref$1;
|
|
27
27
|
}
|
|
28
28
|
declare let Compile: typeof Compile$1;
|
|
29
|
-
declare let Decode: typeof Decode$
|
|
29
|
+
declare let Decode: typeof Decode$2;
|
|
30
30
|
declare let applyCoercions: typeof applyCoercions$1;
|
|
31
31
|
declare let TypeBoxValidator: TypeBoxValidator$1;
|
|
32
32
|
type TypeBoxValidator<T extends TSchema = TAny> = TypeBoxValidator$1<T>;
|
|
@@ -39,7 +39,7 @@ declare let coerceStringToStructure: typeof coerceStringToStructure$1;
|
|
|
39
39
|
declare let coerceBody: typeof coerceBody$1;
|
|
40
40
|
declare let hasTypes: typeof hasTypes$1;
|
|
41
41
|
declare let HasCodec: typeof HasCodec$1;
|
|
42
|
-
declare let Intersect: typeof Intersect$
|
|
42
|
+
declare let Intersect: typeof Intersect$2;
|
|
43
43
|
declare let Default: typeof Default$1;
|
|
44
44
|
declare let Ref: typeof Ref$1;
|
|
45
45
|
declare function useTypebox(mod: TypeboxModule): void;
|
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 { Validator as Validator$1, ValidatorOptions } from "../../validator/inde
|
|
|
2
2
|
import { TypeBoxValidatorCache } from "./validator-cache.js";
|
|
3
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
|
@@ -10,8 +10,8 @@ import { ChainNode } from "./utils.js";
|
|
|
10
10
|
import { Context, ErrorContext, LifecycleContext, PreContext } from "./context.js";
|
|
11
11
|
import { WebSocketHandler } from "./ws/types.js";
|
|
12
12
|
import { AnyElysia, Elysia } from "./base.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
|
|
@@ -742,6 +742,18 @@ type MacroDefSchema<K, MBody, MHeaders, MQuery, MParams, MCookie> = {
|
|
|
742
742
|
cookie: AsMacroSchemaField<K extends keyof MCookie ? MCookie[K] : undefined>;
|
|
743
743
|
response: undefined;
|
|
744
744
|
};
|
|
745
|
+
/**
|
|
746
|
+
* Upper bound for a macro definition's schema channel (`body`/`headers`/…):
|
|
747
|
+
* a registered model name or an inline schema.
|
|
748
|
+
*
|
|
749
|
+
* Used as the `const Body extends …` constraint on `.macro()`. It does not
|
|
750
|
+
* restrict (valid inputs already satisfy it) — it stops `Body[K]` from being a
|
|
751
|
+
* bare `unknown`, which is what lets the `| Name` in the field surface model
|
|
752
|
+
* names to autocomplete (a `unknown | Name` union collapses to `unknown`).
|
|
753
|
+
* `const` still narrows `Body[K]` to the typed literal for `UnwrapRoute`.
|
|
754
|
+
*/
|
|
755
|
+
type MacroSchemaChannel<Definitions extends DefinitionBase> = Record<keyof any, AnySchema | (keyof Definitions['typebox'] & string)>;
|
|
756
|
+
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>> };
|
|
745
757
|
/**
|
|
746
758
|
* Parameter type of the object-form `.macro({ name: definition })`
|
|
747
759
|
*
|
|
@@ -754,17 +766,7 @@ type MacroDefSchema<K, MBody, MHeaders, MQuery, MParams, MCookie> = {
|
|
|
754
766
|
* still flow into `N` (the verbatim definitions, stored in
|
|
755
767
|
* `Metadata['macroFn']` for the consuming route)
|
|
756
768
|
*/
|
|
757
|
-
type ObjectMacroDefs<Body, Headers, Query, Params, Cookie, N, AmbientSchema extends RouteSchema, ScopedSchemas extends RouteSchema, Singleton extends SingletonBase, Definitions extends DefinitionBase, MacroNames extends BaseMacro> = { [K in keyof
|
|
758
|
-
body?: Body[K];
|
|
759
|
-
}> } & { [K in keyof Headers]: MaybeValueOrVoidFunction<{
|
|
760
|
-
headers?: Headers[K];
|
|
761
|
-
}> } & { [K in keyof Query]: MaybeValueOrVoidFunction<{
|
|
762
|
-
query?: Query[K];
|
|
763
|
-
}> } & { [K in keyof Params]: MaybeValueOrVoidFunction<{
|
|
764
|
-
params?: Params[K];
|
|
765
|
-
}> } & { [K in keyof Cookie]: MaybeValueOrVoidFunction<{
|
|
766
|
-
cookie?: Cookie[K];
|
|
767
|
-
}> } & { [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;
|
|
769
|
+
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;
|
|
768
770
|
type CreateEden<Path extends string, Property extends Record<string, unknown> = {}> = Path extends `/${infer Rest}` ? _CreateEden<Rest, Property> : Path extends '' | '/' ? Property : _CreateEden<Path, Property>;
|
|
769
771
|
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 };
|
|
770
772
|
type CreateEdenResponse<Path extends string, Schema extends RouteSchema, MacroContext extends RouteSchema, Res extends PossibleResponse, Err extends Error = never> = RouteSchema extends MacroContext ? {
|
|
@@ -883,4 +885,4 @@ type AddWSRoute<BasePath extends string, Scope extends EventScope, Singleton ext
|
|
|
883
885
|
subscribe: CreateWSEdenResponse<Path, Schema, MacroContext, ComposeElysiaResponse<Schema & MacroContext & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], Response, UnionResponseStatus<Metadata['response'], UnionResponseStatus<Ephemeral['response'], UnionResponseStatus<Volatile['response'], MacroContext['return'] & {}>>>, [...Definitions['error'], ...Ephemeral['error'], ...Volatile['error']]>>;
|
|
884
886
|
}>, Ephemeral, Volatile>;
|
|
885
887
|
//#endregion
|
|
886
|
-
export { AddRoute, AddWSRoute, AfterHandler, AfterResponseHandler, AnyErrorConstructor, AnyLocalHook, type AnySchema, AnyWSLocalHook, AppEvent, AppHook, BaseMacro, BodyHandler, BunHTMLBundlelike, CompiledHandler, ComposeElysiaResponse, ContentType, ContextAppendType, CreateEden, CreateEdenResponse, CreateWSEdenResponse, DefaultEphemeral, DefaultMetadata, DefaultSingleton, DefinitionBase, DocumentDecoration, ElysiaConfig, ElysiaFormData, ElysiaHandlerToResponseSchema, ElysiaHandlerToResponseSchemaAmbiguous, ElysiaHandlerToResponseSchemas, EmptyInputSchema, EphemeralType, Equal, ErrorDefinition, ErrorDefinitionEntry, ErrorHandler, ErrorHandlerResponseSchema, EventFn, EventScope, ExcludeElysiaResponse, ExtractErrorFromHandle, ExtractReturnedError, GetPathParameter, GracefulHandler, GuardLocalHook, GuardSchemaType, HTTPHeaders, HTTPMethod, Handler, InlineHandler, InlineHandlerNonMacro, InlineHandlerResponse, InlineResponse, InlineSchemaResponse, InputSchema, InputSchemaKey, InternalRoute, IntersectIfObject, IntersectIfObjectSchema, IsAny, IsNever, IsTuple, IsUnknown, JoinPath, LocalHook, Macro, MacroProperty, MacroPropertyKey, MacroToContext, MacroToProperty, MapResponse, MaybeArray, MaybePromise, MaybeValueOrVoidFunction, MergeElysiaInstances, MergeSchema, MergeScopedSchemas, MetadataBase, NonResolvableMacroKey, ObjectMacroDefs, OptionalHandler, PossibleResponse, PreHandler, Prettify, PublicRoute, Replace, ResolveHandler, ResolvePath, ResolveRouteErrors, RouteBase, RouteSchema, SSEPayload, SingletonBase, type StandardSchemaV1Like, TraceHandler, TransformHandler, type TypeBoxSchema, UnhandledReturnedError, UnhandledReturnedErrorOf, UnionResponseStatus, UnionToIntersect, UnwrapArray, UnwrapBodySchema, UnwrapMacroSchema, UnwrapRoute, UnwrapSchema, ValueOrFunctionToResponseSchema, ValueToResponseSchema, VoidHandler, WrapFn };
|
|
888
|
+
export { AddRoute, AddWSRoute, AfterHandler, AfterResponseHandler, AnyErrorConstructor, AnyLocalHook, type AnySchema, AnyWSLocalHook, AppEvent, AppHook, BaseMacro, BodyHandler, BunHTMLBundlelike, CompiledHandler, ComposeElysiaResponse, ContentType, ContextAppendType, CreateEden, CreateEdenResponse, CreateWSEdenResponse, DefaultEphemeral, DefaultMetadata, DefaultSingleton, DefinitionBase, DocumentDecoration, ElysiaConfig, ElysiaFormData, ElysiaHandlerToResponseSchema, ElysiaHandlerToResponseSchemaAmbiguous, ElysiaHandlerToResponseSchemas, EmptyInputSchema, EphemeralType, Equal, ErrorDefinition, ErrorDefinitionEntry, ErrorHandler, ErrorHandlerResponseSchema, EventFn, EventScope, ExcludeElysiaResponse, ExtractErrorFromHandle, ExtractReturnedError, GetPathParameter, GracefulHandler, GuardLocalHook, GuardSchemaType, HTTPHeaders, HTTPMethod, Handler, InlineHandler, InlineHandlerNonMacro, InlineHandlerResponse, InlineResponse, InlineSchemaResponse, InputSchema, InputSchemaKey, InternalRoute, IntersectIfObject, IntersectIfObjectSchema, IsAny, IsNever, IsTuple, IsUnknown, JoinPath, LocalHook, Macro, MacroProperty, MacroPropertyKey, MacroSchemaChannel, MacroToContext, MacroToProperty, MapResponse, MaybeArray, MaybePromise, MaybeValueOrVoidFunction, MergeElysiaInstances, MergeSchema, MergeScopedSchemas, MetadataBase, NonResolvableMacroKey, ObjectMacroDefs, OptionalHandler, PossibleResponse, PreHandler, Prettify, PublicRoute, Replace, ResolveHandler, ResolvePath, ResolveRouteErrors, RouteBase, RouteSchema, SSEPayload, SingletonBase, type StandardSchemaV1Like, TraceHandler, TransformHandler, type TypeBoxSchema, UnhandledReturnedError, UnhandledReturnedErrorOf, UnionResponseStatus, UnionToIntersect, UnwrapArray, UnwrapBodySchema, UnwrapMacroSchema, UnwrapRoute, UnwrapSchema, ValueOrFunctionToResponseSchema, ValueToResponseSchema, VoidHandler, WrapFn };
|
package/dist/utils.d.ts
CHANGED
|
@@ -137,5 +137,9 @@ declare function pushField<K extends keyof any>(target: Record<K, unknown>, key:
|
|
|
137
137
|
declare const requestId: any;
|
|
138
138
|
declare function replaceUrlPath(url: string, path: string): string;
|
|
139
139
|
declare function clonePlainDecorators<T extends Record<string, unknown>>(source: T, seen?: WeakMap<object, any>): T;
|
|
140
|
+
declare function prefix<T extends string, Models extends Record<string, AnySchema>>(prefix: T, models: Models): { [k in keyof Models as `${T}.${k & string}`]: Models[k] };
|
|
141
|
+
declare namespace prefix {
|
|
142
|
+
var capitalize: <T extends string, Models extends Record<string, AnySchema>>(prefix: T, models: Models) => { [k in keyof Models as `${T}.${Capitalize<k & string>}`]: Models[k] };
|
|
143
|
+
}
|
|
140
144
|
//#endregion
|
|
141
|
-
export { ChainNode, cloneHook, clonePlainDecorators, coalesceStandaloneSchemas, constantTimeEqual, createErrorEventHandler, dedupedMergeArray, eventProperties, flattenChain, flattenChainMemo, fnOrigin, fnv1a, form, formToFormData, getLoosePath, hookToGuard, isBlob, isDownwardScope, isEmpty, isLocalScope, isNotEmpty, isRecordNumber, joinPath, mapMethodBack, mergeArray, mergeDeep, mergeHook, mergeResponse, nullObject, pushField, redirect, replaceUrlPath, requestId, schemaProperties, sse };
|
|
145
|
+
export { ChainNode, cloneHook, clonePlainDecorators, coalesceStandaloneSchemas, constantTimeEqual, createErrorEventHandler, dedupedMergeArray, eventProperties, flattenChain, flattenChainMemo, fnOrigin, fnv1a, form, formToFormData, getLoosePath, hookToGuard, isBlob, isDownwardScope, isEmpty, isLocalScope, isNotEmpty, isRecordNumber, joinPath, mapMethodBack, mergeArray, mergeDeep, mergeHook, mergeResponse, nullObject, prefix, pushField, redirect, replaceUrlPath, requestId, schemaProperties, sse };
|
package/dist/utils.js
CHANGED
|
@@ -445,6 +445,17 @@ function clonePlainDecorators(source, seen = /* @__PURE__ */ new WeakMap()) {
|
|
|
445
445
|
}
|
|
446
446
|
return out;
|
|
447
447
|
}
|
|
448
|
+
const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
449
|
+
function prefix(prefix, models) {
|
|
450
|
+
const prefixed = nullObject();
|
|
451
|
+
for (const key in models) prefixed[`${prefix}.${key}`] = models[key];
|
|
452
|
+
return prefixed;
|
|
453
|
+
}
|
|
454
|
+
prefix.capitalize = function prefixModelsCapitalize(prefix, models) {
|
|
455
|
+
const prefixed = nullObject();
|
|
456
|
+
for (const key in models) prefixed[`${prefix}.${capitalize(key)}`] = models[key];
|
|
457
|
+
return prefixed;
|
|
458
|
+
};
|
|
448
459
|
|
|
449
460
|
//#endregion
|
|
450
461
|
exports.cloneHook = cloneHook;
|
|
@@ -475,6 +486,7 @@ exports.mergeDeep = mergeDeep;
|
|
|
475
486
|
exports.mergeHook = mergeHook;
|
|
476
487
|
exports.mergeResponse = mergeResponse;
|
|
477
488
|
exports.nullObject = nullObject;
|
|
489
|
+
exports.prefix = prefix;
|
|
478
490
|
exports.pushField = pushField;
|
|
479
491
|
exports.redirect = redirect;
|
|
480
492
|
exports.replaceUrlPath = replaceUrlPath;
|
package/dist/utils.mjs
CHANGED
|
@@ -444,6 +444,17 @@ function clonePlainDecorators(source, seen = /* @__PURE__ */ new WeakMap()) {
|
|
|
444
444
|
}
|
|
445
445
|
return out;
|
|
446
446
|
}
|
|
447
|
+
const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
448
|
+
function prefix(prefix, models) {
|
|
449
|
+
const prefixed = nullObject();
|
|
450
|
+
for (const key in models) prefixed[`${prefix}.${key}`] = models[key];
|
|
451
|
+
return prefixed;
|
|
452
|
+
}
|
|
453
|
+
prefix.capitalize = function prefixModelsCapitalize(prefix, models) {
|
|
454
|
+
const prefixed = nullObject();
|
|
455
|
+
for (const key in models) prefixed[`${prefix}.${capitalize(key)}`] = models[key];
|
|
456
|
+
return prefixed;
|
|
457
|
+
};
|
|
447
458
|
|
|
448
459
|
//#endregion
|
|
449
|
-
export { cloneHook, clonePlainDecorators, coalesceStandaloneSchemas, constantTimeEqual, createErrorEventHandler, dedupedMergeArray, eventProperties, flattenChain, flattenChainMemo, fnOrigin, fnv1a, form, formToFormData, getLoosePath, hookToGuard, isBlob, isDownwardScope, isEmpty, isLocalScope, isNotEmpty, isRecordNumber, joinPath, mapMethodBack, mergeArray, mergeDeep, mergeHook, mergeResponse, nullObject, pushField, redirect, replaceUrlPath, requestId, schemaProperties, sse };
|
|
460
|
+
export { cloneHook, clonePlainDecorators, coalesceStandaloneSchemas, constantTimeEqual, createErrorEventHandler, dedupedMergeArray, eventProperties, flattenChain, flattenChainMemo, fnOrigin, fnv1a, form, formToFormData, getLoosePath, hookToGuard, isBlob, isDownwardScope, isEmpty, isLocalScope, isNotEmpty, isRecordNumber, joinPath, mapMethodBack, mergeArray, mergeDeep, mergeHook, mergeResponse, nullObject, prefix, pushField, redirect, replaceUrlPath, requestId, schemaProperties, sse };
|