elysia 0.3.0-beta.0 → 0.3.0-beta.2
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/fn.js +1 -1
- package/dist/index.d.ts +111 -12
- package/dist/types.d.ts +38 -15
- package/package.json +1 -1
- package/src/custom-types.ts +1 -0
- package/src/fn.ts +27 -13
- package/src/index.ts +236 -13
- package/src/types.ts +109 -34
package/dist/fn.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EXPOSED as e}from"./utils";import{serialize as n}from"superjson";export const permission=({value:n,allow:
|
|
1
|
+
import{EXPOSED as e}from"./utils";import{serialize as n}from"superjson";export const permission=({value:n,allow:t,deny:r,check:i=!0})=>({[e]:!0,value:n,check:i,allow:t,deny:r});export const runFn=(t,r)=>{let i=[],l=t.body;e:for(let n=0;n<l.length;n++){let o=l[n],u=r,c=o.n;if(!Array.isArray(o.n)){i.push(Error("Invalid procedure"));continue e}let s=c[c.length-1];if(1===c.length){if(s in u&&e in u[s]){if(!1==u[s].check){i.push(Error("Forbidden"));continue e}if(!0!==u[s].check){try{let e=u[s].check({...t,key:s,params:o.p??null,match(e){}});if(e instanceof Error){i.push(e);continue e}}catch(e){i.push(e);continue e}u=u[s],s="value"}}}else for(let n=0;n<c.length-1;n++){if(!(u=u[c[n]])){i.push(Error("Invalid procedure"));continue e}if(e in u){let e=c.slice(n+1).join("."),r="function"==typeof u.check;if(!0===u.allow?.includes(e)&&!r){u=u.value;continue}if(!1!=u.check&&!0!==u.deny?.includes(e)&&(!1!==u.allow?.includes(e)||u.deny||r)){if(!0!==u.check)try{let n;let r=u.check({...t,key:e,params:o.p??null,match(e){n=e}});if(n)try{let t=(n[e]??n.default)?.(o.p??null);if(t instanceof Error)throw t}catch(t){if(!(e in n)&&u.allow?.includes(e)){u=u.value;continue}i.push(t);continue e}if(r instanceof Error){i.push(r);continue e}}catch(e){i.push(e);continue e}}else{i.push(Error("Forbidden"));continue e}u=u.value}}try{"function"!=typeof u[s]?i.push(Error("Invalid procedure")):void 0===o.p?i.push(u[s]()):1===o.p.length?i.push(u[s](o.p[0])):i.push(u[s](...o.p))}catch(e){i.push(e)}}return Promise.allSettled(i).then(e=>{let n=[];for(let t=0;t<e.length;t++){let r=e[t];"fulfilled"===r.status?n.push(r.value):n.push(r.reason)}return n}).then(n)};
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Serve, Server } from 'bun';
|
|
|
3
3
|
import { permission, type Permission } from './fn';
|
|
4
4
|
import { SCHEMA, EXPOSED, DEFS } from './utils';
|
|
5
5
|
import type { Context } from './context';
|
|
6
|
-
import type { Handler, BeforeRequestHandler, TypedRoute, ElysiaInstance, ElysiaConfig, HTTPMethod, InternalRoute, BodyParser, ErrorHandler, TypedSchema, LocalHook, LocalHandler, LifeCycle, LifeCycleEvent, LifeCycleStore, VoidLifeCycle, AfterRequestHandler, IsAny, OverwritableTypeRoute, MergeSchema, ListenCallback, NoReturnHandler,
|
|
6
|
+
import type { Handler, BeforeRequestHandler, TypedRoute, ElysiaInstance, ElysiaConfig, HTTPMethod, InternalRoute, BodyParser, ErrorHandler, TypedSchema, LocalHook, LocalHandler, LifeCycle, LifeCycleEvent, LifeCycleStore, VoidLifeCycle, AfterRequestHandler, IsAny, OverwritableTypeRoute, MergeSchema, ListenCallback, NoReturnHandler, MaybePromise, IsNever, TypedRouteToEden, MergeUnionObjects } from './types';
|
|
7
7
|
import { type TSchema } from '@sinclair/typebox';
|
|
8
8
|
export default class Elysia<Instance extends ElysiaInstance = ElysiaInstance> {
|
|
9
9
|
config: ElysiaConfig;
|
|
@@ -51,17 +51,116 @@ export default class Elysia<Instance extends ElysiaInstance = ElysiaInstance> {
|
|
|
51
51
|
use<NewElysia extends MaybePromise<Elysia<any>> = Elysia<any>, Params extends Elysia = Elysia<any>, LazyLoadElysia extends never | ElysiaInstance = never>(plugin: MaybePromise<(app: Params extends Elysia<infer ParamsInstance> ? IsAny<ParamsInstance> extends true ? this : Params : Params) => MaybePromise<NewElysia>> | Promise<{
|
|
52
52
|
default: (elysia: Elysia<any>) => MaybePromise<Elysia<LazyLoadElysia>>;
|
|
53
53
|
}>): IsNever<LazyLoadElysia> extends false ? Elysia<LazyLoadElysia & Instance> : NewElysia extends Elysia<infer NewInstance> ? IsNever<NewInstance> extends true ? Elysia<Instance> : Elysia<NewInstance & Instance> : NewElysia extends Promise<Elysia<infer NewInstance>> ? Elysia<NewInstance & Instance> : this;
|
|
54
|
-
get<Schema extends TypedSchema<Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>> = {}, Path extends string = string, Response = unknown>(path: Path, handler: LocalHandler<Schema, Instance, Path, Response>, hook?: LocalHook<Schema, Instance, Path>):
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
54
|
+
get<Schema extends TypedSchema<Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>> = {}, Path extends string = string, Response = unknown>(path: Path, handler: LocalHandler<Schema, Instance, Path, Response>, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
|
|
55
|
+
request: Instance['request'];
|
|
56
|
+
store: Instance['store'];
|
|
57
|
+
schema: Instance['schema'];
|
|
58
|
+
meta: Record<typeof DEFS, Instance['meta'][typeof DEFS]> & Record<typeof EXPOSED, Instance['meta'][typeof EXPOSED]> & Record<typeof SCHEMA, MergeUnionObjects<Instance['meta'][typeof SCHEMA] & {
|
|
59
|
+
[path in Path]: {
|
|
60
|
+
[method in 'GET']: TypedRouteToEden<Schema, Instance['meta'][typeof DEFS], Path>;
|
|
61
|
+
};
|
|
62
|
+
}>>;
|
|
63
|
+
}>;
|
|
64
|
+
post<Schema extends TypedSchema<Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>> = {}, Path extends string = string, Response = unknown>(path: Path, handler: LocalHandler<Schema, Instance, Path, Response>, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
|
|
65
|
+
request: Instance['request'];
|
|
66
|
+
store: Instance['store'];
|
|
67
|
+
schema: Instance['schema'];
|
|
68
|
+
meta: Record<typeof DEFS, Instance['meta'][typeof DEFS]> & Record<typeof EXPOSED, Instance['meta'][typeof EXPOSED]> & Record<typeof SCHEMA, MergeUnionObjects<Instance['meta'][typeof SCHEMA] & {
|
|
69
|
+
[path in Path]: {
|
|
70
|
+
[method in 'POST']: TypedRouteToEden<Schema, Instance['meta'][typeof DEFS], Path>;
|
|
71
|
+
};
|
|
72
|
+
}>>;
|
|
73
|
+
}>;
|
|
74
|
+
put<Schema extends TypedSchema<Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>> = {}, Path extends string = string, Response = unknown>(path: Path, handler: LocalHandler<Schema, Instance, Path, Response>, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
|
|
75
|
+
request: Instance['request'];
|
|
76
|
+
store: Instance['store'];
|
|
77
|
+
schema: Instance['schema'];
|
|
78
|
+
meta: Record<typeof DEFS, Instance['meta'][typeof DEFS]> & Record<typeof EXPOSED, Instance['meta'][typeof EXPOSED]> & Record<typeof SCHEMA, MergeUnionObjects<Instance['meta'][typeof SCHEMA] & {
|
|
79
|
+
[path in Path]: {
|
|
80
|
+
[method in 'PUT']: TypedRouteToEden<Schema, Instance['meta'][typeof DEFS], Path>;
|
|
81
|
+
};
|
|
82
|
+
}>>;
|
|
83
|
+
}>;
|
|
84
|
+
patch<Schema extends TypedSchema<Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>> = {}, Path extends string = string, Response = unknown>(path: Path, handler: LocalHandler<Schema, Instance, Path, Response>, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
|
|
85
|
+
request: Instance['request'];
|
|
86
|
+
store: Instance['store'];
|
|
87
|
+
schema: Instance['schema'];
|
|
88
|
+
meta: Record<typeof DEFS, Instance['meta'][typeof DEFS]> & Record<typeof EXPOSED, Instance['meta'][typeof EXPOSED]> & Record<typeof SCHEMA, MergeUnionObjects<Instance['meta'][typeof SCHEMA] & {
|
|
89
|
+
[path in Path]: {
|
|
90
|
+
[method in 'PATCH']: TypedRouteToEden<Schema, Instance['meta'][typeof DEFS], Path>;
|
|
91
|
+
};
|
|
92
|
+
}>>;
|
|
93
|
+
}>;
|
|
94
|
+
delete<Schema extends TypedSchema<Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>> = {}, Path extends string = string, Response = unknown>(path: Path, handler: LocalHandler<Schema, Instance, Path, Response>, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
|
|
95
|
+
request: Instance['request'];
|
|
96
|
+
store: Instance['store'];
|
|
97
|
+
schema: Instance['schema'];
|
|
98
|
+
meta: Record<typeof DEFS, Instance['meta'][typeof DEFS]> & Record<typeof EXPOSED, Instance['meta'][typeof EXPOSED]> & Record<typeof SCHEMA, MergeUnionObjects<Instance['meta'][typeof SCHEMA] & {
|
|
99
|
+
[path in Path]: {
|
|
100
|
+
[method in 'DELETE']: TypedRouteToEden<Schema, Instance['meta'][typeof DEFS], Path>;
|
|
101
|
+
};
|
|
102
|
+
}>>;
|
|
103
|
+
}>;
|
|
104
|
+
options<Schema extends TypedSchema<Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>> = {}, Path extends string = string, Response = unknown>(path: Path, handler: LocalHandler<Schema, Instance, Path, Response>, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
|
|
105
|
+
request: Instance['request'];
|
|
106
|
+
store: Instance['store'];
|
|
107
|
+
schema: Instance['schema'];
|
|
108
|
+
meta: Record<typeof DEFS, Instance['meta'][typeof DEFS]> & Record<typeof EXPOSED, Instance['meta'][typeof EXPOSED]> & Record<typeof SCHEMA, MergeUnionObjects<Instance['meta'][typeof SCHEMA] & {
|
|
109
|
+
[path in Path]: {
|
|
110
|
+
[method in 'OPTIONS']: TypedRouteToEden<Schema, Instance['meta'][typeof DEFS], Path>;
|
|
111
|
+
};
|
|
112
|
+
}>>;
|
|
113
|
+
}>;
|
|
114
|
+
all<Schema extends TypedSchema<Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>> = {}, Path extends string = string, Response = unknown>(path: Path, handler: LocalHandler<Schema, Instance, Path, Response>, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
|
|
115
|
+
request: Instance['request'];
|
|
116
|
+
store: Instance['store'];
|
|
117
|
+
schema: Instance['schema'];
|
|
118
|
+
meta: Record<typeof DEFS, Instance['meta'][typeof DEFS]> & Record<typeof EXPOSED, Instance['meta'][typeof EXPOSED]> & Record<typeof SCHEMA, MergeUnionObjects<Instance['meta'][typeof SCHEMA] & {
|
|
119
|
+
[path in Path]: {
|
|
120
|
+
[method in 'ALL']: TypedRouteToEden<Schema, Instance['meta'][typeof DEFS], Path>;
|
|
121
|
+
};
|
|
122
|
+
}>>;
|
|
123
|
+
}>;
|
|
124
|
+
head<Schema extends TypedSchema<Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>> = {}, Path extends string = string, Response = unknown>(path: Path, handler: LocalHandler<Schema, Instance, Path, Response>, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
|
|
125
|
+
request: Instance['request'];
|
|
126
|
+
store: Instance['store'];
|
|
127
|
+
schema: Instance['schema'];
|
|
128
|
+
meta: Record<typeof DEFS, Instance['meta'][typeof DEFS]> & Record<typeof EXPOSED, Instance['meta'][typeof EXPOSED]> & Record<typeof SCHEMA, MergeUnionObjects<Instance['meta'][typeof SCHEMA] & {
|
|
129
|
+
[path in Path]: {
|
|
130
|
+
[method in 'HEAD']: TypedRouteToEden<Schema, Instance['meta'][typeof DEFS], Path>;
|
|
131
|
+
};
|
|
132
|
+
}>>;
|
|
133
|
+
}>;
|
|
134
|
+
trace<Schema extends TypedSchema<Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>> = {}, Path extends string = string, Response = unknown>(path: Path, handler: LocalHandler<Schema, Instance, Path, Response>, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
|
|
135
|
+
request: Instance['request'];
|
|
136
|
+
store: Instance['store'];
|
|
137
|
+
schema: Instance['schema'];
|
|
138
|
+
meta: Record<typeof DEFS, Instance['meta'][typeof DEFS]> & Record<typeof EXPOSED, Instance['meta'][typeof EXPOSED]> & Record<typeof SCHEMA, MergeUnionObjects<Instance['meta'][typeof SCHEMA] & {
|
|
139
|
+
[path in Path]: {
|
|
140
|
+
[method in 'TRACE']: TypedRouteToEden<Schema, Instance['meta'][typeof DEFS], Path>;
|
|
141
|
+
};
|
|
142
|
+
}>>;
|
|
143
|
+
}>;
|
|
144
|
+
connect<Schema extends TypedSchema<Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>> = {}, Path extends string = string, Response = unknown>(path: Path, handler: LocalHandler<Schema, Instance, Path, Response>, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
|
|
145
|
+
request: Instance['request'];
|
|
146
|
+
store: Instance['store'];
|
|
147
|
+
schema: Instance['schema'];
|
|
148
|
+
meta: Record<typeof DEFS, Instance['meta'][typeof DEFS]> & Record<typeof EXPOSED, Instance['meta'][typeof EXPOSED]> & Record<typeof SCHEMA, MergeUnionObjects<Instance['meta'][typeof SCHEMA] & {
|
|
149
|
+
[path in Path]: {
|
|
150
|
+
[method in 'CONNECT']: TypedRouteToEden<Schema, Instance['meta'][typeof DEFS], Path>;
|
|
151
|
+
};
|
|
152
|
+
}>>;
|
|
153
|
+
}>;
|
|
154
|
+
route<Schema extends TypedSchema<Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>> = {}, Method extends HTTPMethod = HTTPMethod, Path extends string = string, Response = unknown>(method: Method, path: Path, handler: LocalHandler<Schema, Instance, Path, Response>, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
|
|
155
|
+
request: Instance['request'];
|
|
156
|
+
store: Instance['store'];
|
|
157
|
+
schema: Instance['schema'];
|
|
158
|
+
meta: Record<typeof DEFS, Instance['meta'][typeof DEFS]> & Record<typeof EXPOSED, Instance['meta'][typeof EXPOSED]> & Record<typeof SCHEMA, MergeUnionObjects<Instance['meta'][typeof SCHEMA] & {
|
|
159
|
+
[path in Path]: {
|
|
160
|
+
[method in Method]: TypedRouteToEden<Schema, Instance['meta'][typeof DEFS], Path>;
|
|
161
|
+
};
|
|
162
|
+
}>>;
|
|
163
|
+
}>;
|
|
65
164
|
state<Key extends string | number | symbol = keyof Instance['store'], Value = Instance['store'][keyof Instance['store']], NewInstance = Elysia<{
|
|
66
165
|
store: Instance['store'] & {
|
|
67
166
|
[key in Key]: Value;
|
package/dist/types.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { Serve, Server } from 'bun';
|
|
|
4
4
|
import type { Context, PreContext } from './context';
|
|
5
5
|
import type { Static, TObject, TSchema } from '@sinclair/typebox';
|
|
6
6
|
import type { TypeCheck } from '@sinclair/typebox/compiler';
|
|
7
|
-
import
|
|
7
|
+
import { SCHEMA, DEFS, EXPOSED } from './utils';
|
|
8
8
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
9
9
|
export type WithArray<T> = T | T[];
|
|
10
10
|
export type ObjectValues<T extends object> = T[keyof T];
|
|
@@ -26,11 +26,7 @@ export type ElysiaInstance<Instance extends {
|
|
|
26
26
|
schema: Instance['schema'] extends undefined ? TypedSchema : Instance['schema'];
|
|
27
27
|
meta: Instance['meta'];
|
|
28
28
|
};
|
|
29
|
-
export type Handler<Route extends TypedRoute = TypedRoute, Instance extends ElysiaInstance = ElysiaInstance, CatchResponse = Route['response']> = (context: Context<Route, Instance['store']> & Instance['request']
|
|
30
|
-
a: Instance;
|
|
31
|
-
r: Route;
|
|
32
|
-
merged: MergeSchema<Instance['schema'], Route>;
|
|
33
|
-
}) => Route['response'] extends (models: Record<string, TSchema>) => TSchema ? undefined extends ReturnType<Route['response']> ? MaybePromise<CatchResponse> | Response : MaybePromise<ReturnType<Route['response']>> | Response : undefined extends Route['response'] ? MaybePromise<CatchResponse> | Response : MaybePromise<Route['response']> | Response;
|
|
29
|
+
export type Handler<Route extends TypedRoute = TypedRoute, Instance extends ElysiaInstance = ElysiaInstance, CatchResponse = Route['response']> = (context: Context<Route, Instance['store']> & Instance['request']) => Route['response'] extends (models: Record<string, TSchema>) => TSchema ? undefined extends ReturnType<Route['response']> ? MaybePromise<CatchResponse> | Response : MaybePromise<ReturnType<Route['response']>> | Response : undefined extends Route['response'] ? MaybePromise<CatchResponse> | Response : MaybePromise<Route['response']> | Response;
|
|
34
30
|
export type NoReturnHandler<Route extends TypedRoute = TypedRoute, Instance extends ElysiaInstance = ElysiaInstance> = (context: Context<Route, Instance['store']> & Instance['request']) => void | Promise<void>;
|
|
35
31
|
export type LifeCycleEvent = 'start' | 'request' | 'parse' | 'transform' | 'beforeHandle' | 'afterHandle' | 'error' | 'stop';
|
|
36
32
|
export type ListenCallback = ((server: Server) => void) | ((server: Server) => Promise<void>);
|
|
@@ -131,23 +127,50 @@ export interface LocalHook<Schema extends TypedSchema = TypedSchema, Instance ex
|
|
|
131
127
|
export type RouteToSchema<Schema extends TypedSchema, InstanceSchema extends ElysiaInstance['schema'], Definitions extends ElysiaInstance['meta'][typeof DEFS], Path extends string = string, FinalSchema extends MergeSchema<Schema, InstanceSchema> = MergeSchema<Schema, InstanceSchema>> = FinalSchema['params'] extends NonNullable<Schema['params']> ? TypedSchemaToRoute<FinalSchema, Definitions> : Omit<TypedSchemaToRoute<FinalSchema, Definitions>, 'params'> & {
|
|
132
128
|
params: Record<ExtractPath<Path>, string>;
|
|
133
129
|
};
|
|
134
|
-
export type
|
|
130
|
+
export type MergeUnionObjects<T> = {} & {
|
|
131
|
+
[P in keyof T]: T[P];
|
|
132
|
+
};
|
|
133
|
+
export type ElysiaRoute<Method extends string = string, Schema extends TypedSchema = TypedSchema, Instance extends ElysiaInstance<any> = ElysiaInstance, Path extends string = string, CatchResponse = unknown> = Elysia<{
|
|
135
134
|
request: Instance['request'];
|
|
136
135
|
store: Instance['store'];
|
|
137
136
|
schema: Instance['schema'];
|
|
138
|
-
meta: Instance['meta'] & Record<typeof SCHEMA, {
|
|
137
|
+
meta: Record<typeof DEFS, Instance['meta'][typeof DEFS]> & Record<typeof EXPOSED, Instance['meta'][typeof EXPOSED]> & Record<typeof SCHEMA, MergeUnionObjects<Instance['meta'][typeof SCHEMA] & {
|
|
139
138
|
[path in Path]: {
|
|
140
|
-
[method in Method]: TypedRouteToEden<Schema, Instance['
|
|
141
|
-
|
|
139
|
+
[method in Method]: TypedRouteToEden<Schema, Instance['meta'][typeof DEFS], Path> extends {
|
|
140
|
+
body: infer Body extends AnyTypedSchema['body'];
|
|
141
|
+
headers: infer Headers extends AnyTypedSchema['headers'];
|
|
142
|
+
query: infer Query extends AnyTypedSchema['query'];
|
|
143
|
+
params: infer Params extends AnyTypedSchema['params'];
|
|
144
|
+
response: infer Response extends AnyTypedSchema['response'];
|
|
145
|
+
} ? {
|
|
146
|
+
body: Body;
|
|
147
|
+
headers: Headers;
|
|
148
|
+
query: Query;
|
|
149
|
+
params: Params extends NonNullable<Params> ? Params : Record<ExtractPath<Path>, string>;
|
|
150
|
+
response: undefined extends Response ? {
|
|
142
151
|
'200': CatchResponse;
|
|
143
|
-
} :
|
|
152
|
+
} : Response;
|
|
144
153
|
} : never;
|
|
145
154
|
};
|
|
146
|
-
}
|
|
155
|
+
}>>;
|
|
147
156
|
}>;
|
|
148
|
-
export type TypedRouteToEden<Schema extends TypedSchema = TypedSchema,
|
|
149
|
-
|
|
150
|
-
|
|
157
|
+
export type TypedRouteToEden<Schema extends TypedSchema = TypedSchema, Definitions extends TypedSchema<string> = ElysiaInstance['meta'][typeof DEFS], Path extends string = string, Typed extends AnyTypedSchema = TypedSchemaToEden<Schema, Definitions>> = Schema['params'] extends NonNullable<Schema['params']> ? Typed extends AnyTypedSchema ? {
|
|
158
|
+
body: Typed['body'];
|
|
159
|
+
headers: Typed['headers'];
|
|
160
|
+
query: Typed['query'];
|
|
161
|
+
params: Typed['params'] extends NonNullable<Typed['params']> ? Typed['params'] : Record<ExtractPath<Path>, string>;
|
|
162
|
+
response: undefined extends Response ? {
|
|
163
|
+
'200': Response;
|
|
164
|
+
} : Response;
|
|
165
|
+
} : AnyTypedSchema : Typed extends AnyTypedSchema ? {
|
|
166
|
+
body: Typed['body'];
|
|
167
|
+
headers: Typed['headers'];
|
|
168
|
+
query: Typed['query'];
|
|
169
|
+
params: never;
|
|
170
|
+
response: undefined extends Response ? {
|
|
171
|
+
'200': Response;
|
|
172
|
+
} : Response;
|
|
173
|
+
} : AnyTypedSchema;
|
|
151
174
|
export type TypedSchemaToEden<Schema extends TypedSchema, Definitions extends ElysiaInstance['meta'][typeof DEFS]> = {
|
|
152
175
|
body: UnwrapSchema<Schema['body'], Definitions>;
|
|
153
176
|
headers: UnwrapSchema<Schema['headers'], Definitions> extends infer Result extends Record<string, any> ? Result : undefined;
|
package/package.json
CHANGED
package/src/custom-types.ts
CHANGED
package/src/fn.ts
CHANGED
|
@@ -98,9 +98,7 @@ export const runFn = (
|
|
|
98
98
|
continue batch
|
|
99
99
|
} else if (method[caller].check !== true) {
|
|
100
100
|
try {
|
|
101
|
-
const allowance: Permission = method[
|
|
102
|
-
caller
|
|
103
|
-
].check({
|
|
101
|
+
const allowance: Permission = method[caller].check({
|
|
104
102
|
...context,
|
|
105
103
|
key: caller,
|
|
106
104
|
params: procedure.p ?? null,
|
|
@@ -173,7 +171,7 @@ export const runFn = (
|
|
|
173
171
|
}
|
|
174
172
|
})
|
|
175
173
|
|
|
176
|
-
if (cases)
|
|
174
|
+
if (cases)
|
|
177
175
|
try {
|
|
178
176
|
const response = (
|
|
179
177
|
cases[key] ?? cases.default
|
|
@@ -193,7 +191,6 @@ export const runFn = (
|
|
|
193
191
|
results.push(error)
|
|
194
192
|
continue batch
|
|
195
193
|
}
|
|
196
|
-
}
|
|
197
194
|
|
|
198
195
|
if (allowance instanceof Error) {
|
|
199
196
|
results.push(allowance)
|
|
@@ -208,14 +205,31 @@ export const runFn = (
|
|
|
208
205
|
}
|
|
209
206
|
}
|
|
210
207
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
208
|
+
try {
|
|
209
|
+
// ? Need to call Class.method to access this
|
|
210
|
+
if (typeof method[caller] !== 'function')
|
|
211
|
+
results.push(new Error('Invalid procedure'))
|
|
212
|
+
else if (procedure.p === undefined) results.push(method[caller]())
|
|
213
|
+
else if (procedure.p.length === 1)
|
|
214
|
+
results.push(method[caller](procedure.p[0]))
|
|
215
|
+
else results.push(method[caller](...procedure.p))
|
|
216
|
+
} catch (error) {
|
|
217
|
+
results.push(error)
|
|
218
|
+
}
|
|
218
219
|
}
|
|
219
220
|
|
|
220
|
-
return Promise.
|
|
221
|
+
return Promise.allSettled(results)
|
|
222
|
+
.then((x) => {
|
|
223
|
+
const ops: any[] = []
|
|
224
|
+
|
|
225
|
+
for (let i = 0; i < x.length; i++) {
|
|
226
|
+
const op = x[i]
|
|
227
|
+
|
|
228
|
+
if (op.status === 'fulfilled') ops.push(op.value)
|
|
229
|
+
else ops.push(op.reason)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return ops
|
|
233
|
+
})
|
|
234
|
+
.then(superjsonSerialize)
|
|
221
235
|
}
|
package/src/index.ts
CHANGED
|
@@ -50,9 +50,12 @@ import type {
|
|
|
50
50
|
MergeSchema,
|
|
51
51
|
ListenCallback,
|
|
52
52
|
NoReturnHandler,
|
|
53
|
-
ElysiaRoute,
|
|
54
53
|
MaybePromise,
|
|
55
|
-
IsNever
|
|
54
|
+
IsNever,
|
|
55
|
+
AnyTypedSchema,
|
|
56
|
+
TypedRouteToEden,
|
|
57
|
+
MergeUnionObjects,
|
|
58
|
+
ExtractPath
|
|
56
59
|
} from './types'
|
|
57
60
|
import { type TSchema } from '@sinclair/typebox'
|
|
58
61
|
|
|
@@ -683,7 +686,27 @@ export default class Elysia<Instance extends ElysiaInstance = ElysiaInstance> {
|
|
|
683
686
|
path: Path,
|
|
684
687
|
handler: LocalHandler<Schema, Instance, Path, Response>,
|
|
685
688
|
hook?: LocalHook<Schema, Instance, Path>
|
|
686
|
-
):
|
|
689
|
+
): Elysia<{
|
|
690
|
+
request: Instance['request']
|
|
691
|
+
store: Instance['store']
|
|
692
|
+
schema: Instance['schema']
|
|
693
|
+
meta: Record<typeof DEFS, Instance['meta'][typeof DEFS]> &
|
|
694
|
+
Record<typeof EXPOSED, Instance['meta'][typeof EXPOSED]> &
|
|
695
|
+
Record<
|
|
696
|
+
typeof SCHEMA,
|
|
697
|
+
MergeUnionObjects<
|
|
698
|
+
Instance['meta'][typeof SCHEMA] & {
|
|
699
|
+
[path in Path]: {
|
|
700
|
+
[method in 'GET']: TypedRouteToEden<
|
|
701
|
+
Schema,
|
|
702
|
+
Instance['meta'][typeof DEFS],
|
|
703
|
+
Path
|
|
704
|
+
>
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
>
|
|
708
|
+
>
|
|
709
|
+
}> {
|
|
687
710
|
this._addHandler('GET', path, handler, hook as LocalHook)
|
|
688
711
|
|
|
689
712
|
return this as any
|
|
@@ -717,7 +740,27 @@ export default class Elysia<Instance extends ElysiaInstance = ElysiaInstance> {
|
|
|
717
740
|
path: Path,
|
|
718
741
|
handler: LocalHandler<Schema, Instance, Path, Response>,
|
|
719
742
|
hook?: LocalHook<Schema, Instance, Path>
|
|
720
|
-
):
|
|
743
|
+
): Elysia<{
|
|
744
|
+
request: Instance['request']
|
|
745
|
+
store: Instance['store']
|
|
746
|
+
schema: Instance['schema']
|
|
747
|
+
meta: Record<typeof DEFS, Instance['meta'][typeof DEFS]> &
|
|
748
|
+
Record<typeof EXPOSED, Instance['meta'][typeof EXPOSED]> &
|
|
749
|
+
Record<
|
|
750
|
+
typeof SCHEMA,
|
|
751
|
+
MergeUnionObjects<
|
|
752
|
+
Instance['meta'][typeof SCHEMA] & {
|
|
753
|
+
[path in Path]: {
|
|
754
|
+
[method in 'POST']: TypedRouteToEden<
|
|
755
|
+
Schema,
|
|
756
|
+
Instance['meta'][typeof DEFS],
|
|
757
|
+
Path
|
|
758
|
+
>
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
>
|
|
762
|
+
>
|
|
763
|
+
}> {
|
|
721
764
|
this._addHandler('POST', path, handler, hook as LocalHook)
|
|
722
765
|
|
|
723
766
|
return this as any
|
|
@@ -751,7 +794,27 @@ export default class Elysia<Instance extends ElysiaInstance = ElysiaInstance> {
|
|
|
751
794
|
path: Path,
|
|
752
795
|
handler: LocalHandler<Schema, Instance, Path, Response>,
|
|
753
796
|
hook?: LocalHook<Schema, Instance, Path>
|
|
754
|
-
):
|
|
797
|
+
): Elysia<{
|
|
798
|
+
request: Instance['request']
|
|
799
|
+
store: Instance['store']
|
|
800
|
+
schema: Instance['schema']
|
|
801
|
+
meta: Record<typeof DEFS, Instance['meta'][typeof DEFS]> &
|
|
802
|
+
Record<typeof EXPOSED, Instance['meta'][typeof EXPOSED]> &
|
|
803
|
+
Record<
|
|
804
|
+
typeof SCHEMA,
|
|
805
|
+
MergeUnionObjects<
|
|
806
|
+
Instance['meta'][typeof SCHEMA] & {
|
|
807
|
+
[path in Path]: {
|
|
808
|
+
[method in 'PUT']: TypedRouteToEden<
|
|
809
|
+
Schema,
|
|
810
|
+
Instance['meta'][typeof DEFS],
|
|
811
|
+
Path
|
|
812
|
+
>
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
>
|
|
816
|
+
>
|
|
817
|
+
}> {
|
|
755
818
|
this._addHandler('PUT', path, handler, hook as LocalHook)
|
|
756
819
|
|
|
757
820
|
return this as any
|
|
@@ -785,7 +848,27 @@ export default class Elysia<Instance extends ElysiaInstance = ElysiaInstance> {
|
|
|
785
848
|
path: Path,
|
|
786
849
|
handler: LocalHandler<Schema, Instance, Path, Response>,
|
|
787
850
|
hook?: LocalHook<Schema, Instance, Path>
|
|
788
|
-
):
|
|
851
|
+
): Elysia<{
|
|
852
|
+
request: Instance['request']
|
|
853
|
+
store: Instance['store']
|
|
854
|
+
schema: Instance['schema']
|
|
855
|
+
meta: Record<typeof DEFS, Instance['meta'][typeof DEFS]> &
|
|
856
|
+
Record<typeof EXPOSED, Instance['meta'][typeof EXPOSED]> &
|
|
857
|
+
Record<
|
|
858
|
+
typeof SCHEMA,
|
|
859
|
+
MergeUnionObjects<
|
|
860
|
+
Instance['meta'][typeof SCHEMA] & {
|
|
861
|
+
[path in Path]: {
|
|
862
|
+
[method in 'PATCH']: TypedRouteToEden<
|
|
863
|
+
Schema,
|
|
864
|
+
Instance['meta'][typeof DEFS],
|
|
865
|
+
Path
|
|
866
|
+
>
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
>
|
|
870
|
+
>
|
|
871
|
+
}> {
|
|
789
872
|
this._addHandler('PATCH', path, handler, hook as LocalHook)
|
|
790
873
|
|
|
791
874
|
return this as any
|
|
@@ -819,7 +902,27 @@ export default class Elysia<Instance extends ElysiaInstance = ElysiaInstance> {
|
|
|
819
902
|
path: Path,
|
|
820
903
|
handler: LocalHandler<Schema, Instance, Path, Response>,
|
|
821
904
|
hook?: LocalHook<Schema, Instance, Path>
|
|
822
|
-
):
|
|
905
|
+
): Elysia<{
|
|
906
|
+
request: Instance['request']
|
|
907
|
+
store: Instance['store']
|
|
908
|
+
schema: Instance['schema']
|
|
909
|
+
meta: Record<typeof DEFS, Instance['meta'][typeof DEFS]> &
|
|
910
|
+
Record<typeof EXPOSED, Instance['meta'][typeof EXPOSED]> &
|
|
911
|
+
Record<
|
|
912
|
+
typeof SCHEMA,
|
|
913
|
+
MergeUnionObjects<
|
|
914
|
+
Instance['meta'][typeof SCHEMA] & {
|
|
915
|
+
[path in Path]: {
|
|
916
|
+
[method in 'DELETE']: TypedRouteToEden<
|
|
917
|
+
Schema,
|
|
918
|
+
Instance['meta'][typeof DEFS],
|
|
919
|
+
Path
|
|
920
|
+
>
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
>
|
|
924
|
+
>
|
|
925
|
+
}> {
|
|
823
926
|
this._addHandler('DELETE', path, handler, hook as LocalHook)
|
|
824
927
|
|
|
825
928
|
return this as any
|
|
@@ -853,7 +956,27 @@ export default class Elysia<Instance extends ElysiaInstance = ElysiaInstance> {
|
|
|
853
956
|
path: Path,
|
|
854
957
|
handler: LocalHandler<Schema, Instance, Path, Response>,
|
|
855
958
|
hook?: LocalHook<Schema, Instance, Path>
|
|
856
|
-
):
|
|
959
|
+
): Elysia<{
|
|
960
|
+
request: Instance['request']
|
|
961
|
+
store: Instance['store']
|
|
962
|
+
schema: Instance['schema']
|
|
963
|
+
meta: Record<typeof DEFS, Instance['meta'][typeof DEFS]> &
|
|
964
|
+
Record<typeof EXPOSED, Instance['meta'][typeof EXPOSED]> &
|
|
965
|
+
Record<
|
|
966
|
+
typeof SCHEMA,
|
|
967
|
+
MergeUnionObjects<
|
|
968
|
+
Instance['meta'][typeof SCHEMA] & {
|
|
969
|
+
[path in Path]: {
|
|
970
|
+
[method in 'OPTIONS']: TypedRouteToEden<
|
|
971
|
+
Schema,
|
|
972
|
+
Instance['meta'][typeof DEFS],
|
|
973
|
+
Path
|
|
974
|
+
>
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
>
|
|
978
|
+
>
|
|
979
|
+
}> {
|
|
857
980
|
this._addHandler('OPTIONS', path, handler, hook as LocalHook)
|
|
858
981
|
|
|
859
982
|
return this as any
|
|
@@ -882,7 +1005,27 @@ export default class Elysia<Instance extends ElysiaInstance = ElysiaInstance> {
|
|
|
882
1005
|
path: Path,
|
|
883
1006
|
handler: LocalHandler<Schema, Instance, Path, Response>,
|
|
884
1007
|
hook?: LocalHook<Schema, Instance, Path>
|
|
885
|
-
):
|
|
1008
|
+
): Elysia<{
|
|
1009
|
+
request: Instance['request']
|
|
1010
|
+
store: Instance['store']
|
|
1011
|
+
schema: Instance['schema']
|
|
1012
|
+
meta: Record<typeof DEFS, Instance['meta'][typeof DEFS]> &
|
|
1013
|
+
Record<typeof EXPOSED, Instance['meta'][typeof EXPOSED]> &
|
|
1014
|
+
Record<
|
|
1015
|
+
typeof SCHEMA,
|
|
1016
|
+
MergeUnionObjects<
|
|
1017
|
+
Instance['meta'][typeof SCHEMA] & {
|
|
1018
|
+
[path in Path]: {
|
|
1019
|
+
[method in 'ALL']: TypedRouteToEden<
|
|
1020
|
+
Schema,
|
|
1021
|
+
Instance['meta'][typeof DEFS],
|
|
1022
|
+
Path
|
|
1023
|
+
>
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
>
|
|
1027
|
+
>
|
|
1028
|
+
}> {
|
|
886
1029
|
this._addHandler('ALL', path, handler, hook as LocalHook)
|
|
887
1030
|
|
|
888
1031
|
return this as any
|
|
@@ -916,7 +1059,27 @@ export default class Elysia<Instance extends ElysiaInstance = ElysiaInstance> {
|
|
|
916
1059
|
path: Path,
|
|
917
1060
|
handler: LocalHandler<Schema, Instance, Path, Response>,
|
|
918
1061
|
hook?: LocalHook<Schema, Instance, Path>
|
|
919
|
-
):
|
|
1062
|
+
): Elysia<{
|
|
1063
|
+
request: Instance['request']
|
|
1064
|
+
store: Instance['store']
|
|
1065
|
+
schema: Instance['schema']
|
|
1066
|
+
meta: Record<typeof DEFS, Instance['meta'][typeof DEFS]> &
|
|
1067
|
+
Record<typeof EXPOSED, Instance['meta'][typeof EXPOSED]> &
|
|
1068
|
+
Record<
|
|
1069
|
+
typeof SCHEMA,
|
|
1070
|
+
MergeUnionObjects<
|
|
1071
|
+
Instance['meta'][typeof SCHEMA] & {
|
|
1072
|
+
[path in Path]: {
|
|
1073
|
+
[method in 'HEAD']: TypedRouteToEden<
|
|
1074
|
+
Schema,
|
|
1075
|
+
Instance['meta'][typeof DEFS],
|
|
1076
|
+
Path
|
|
1077
|
+
>
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
>
|
|
1081
|
+
>
|
|
1082
|
+
}> {
|
|
920
1083
|
this._addHandler('HEAD', path, handler, hook as LocalHook)
|
|
921
1084
|
|
|
922
1085
|
return this as any
|
|
@@ -950,7 +1113,27 @@ export default class Elysia<Instance extends ElysiaInstance = ElysiaInstance> {
|
|
|
950
1113
|
path: Path,
|
|
951
1114
|
handler: LocalHandler<Schema, Instance, Path, Response>,
|
|
952
1115
|
hook?: LocalHook<Schema, Instance, Path>
|
|
953
|
-
):
|
|
1116
|
+
): Elysia<{
|
|
1117
|
+
request: Instance['request']
|
|
1118
|
+
store: Instance['store']
|
|
1119
|
+
schema: Instance['schema']
|
|
1120
|
+
meta: Record<typeof DEFS, Instance['meta'][typeof DEFS]> &
|
|
1121
|
+
Record<typeof EXPOSED, Instance['meta'][typeof EXPOSED]> &
|
|
1122
|
+
Record<
|
|
1123
|
+
typeof SCHEMA,
|
|
1124
|
+
MergeUnionObjects<
|
|
1125
|
+
Instance['meta'][typeof SCHEMA] & {
|
|
1126
|
+
[path in Path]: {
|
|
1127
|
+
[method in 'TRACE']: TypedRouteToEden<
|
|
1128
|
+
Schema,
|
|
1129
|
+
Instance['meta'][typeof DEFS],
|
|
1130
|
+
Path
|
|
1131
|
+
>
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
>
|
|
1135
|
+
>
|
|
1136
|
+
}> {
|
|
954
1137
|
this._addHandler('TRACE', path, handler, hook as LocalHook)
|
|
955
1138
|
|
|
956
1139
|
return this as any
|
|
@@ -984,7 +1167,27 @@ export default class Elysia<Instance extends ElysiaInstance = ElysiaInstance> {
|
|
|
984
1167
|
path: Path,
|
|
985
1168
|
handler: LocalHandler<Schema, Instance, Path, Response>,
|
|
986
1169
|
hook?: LocalHook<Schema, Instance, Path>
|
|
987
|
-
):
|
|
1170
|
+
): Elysia<{
|
|
1171
|
+
request: Instance['request']
|
|
1172
|
+
store: Instance['store']
|
|
1173
|
+
schema: Instance['schema']
|
|
1174
|
+
meta: Record<typeof DEFS, Instance['meta'][typeof DEFS]> &
|
|
1175
|
+
Record<typeof EXPOSED, Instance['meta'][typeof EXPOSED]> &
|
|
1176
|
+
Record<
|
|
1177
|
+
typeof SCHEMA,
|
|
1178
|
+
MergeUnionObjects<
|
|
1179
|
+
Instance['meta'][typeof SCHEMA] & {
|
|
1180
|
+
[path in Path]: {
|
|
1181
|
+
[method in 'CONNECT']: TypedRouteToEden<
|
|
1182
|
+
Schema,
|
|
1183
|
+
Instance['meta'][typeof DEFS],
|
|
1184
|
+
Path
|
|
1185
|
+
>
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
>
|
|
1189
|
+
>
|
|
1190
|
+
}> {
|
|
988
1191
|
this._addHandler('CONNECT', path, handler, hook as LocalHook)
|
|
989
1192
|
|
|
990
1193
|
return this as any
|
|
@@ -1020,7 +1223,27 @@ export default class Elysia<Instance extends ElysiaInstance = ElysiaInstance> {
|
|
|
1020
1223
|
path: Path,
|
|
1021
1224
|
handler: LocalHandler<Schema, Instance, Path, Response>,
|
|
1022
1225
|
hook?: LocalHook<Schema, Instance, Path>
|
|
1023
|
-
):
|
|
1226
|
+
): Elysia<{
|
|
1227
|
+
request: Instance['request']
|
|
1228
|
+
store: Instance['store']
|
|
1229
|
+
schema: Instance['schema']
|
|
1230
|
+
meta: Record<typeof DEFS, Instance['meta'][typeof DEFS]> &
|
|
1231
|
+
Record<typeof EXPOSED, Instance['meta'][typeof EXPOSED]> &
|
|
1232
|
+
Record<
|
|
1233
|
+
typeof SCHEMA,
|
|
1234
|
+
MergeUnionObjects<
|
|
1235
|
+
Instance['meta'][typeof SCHEMA] & {
|
|
1236
|
+
[path in Path]: {
|
|
1237
|
+
[method in Method]: TypedRouteToEden<
|
|
1238
|
+
Schema,
|
|
1239
|
+
Instance['meta'][typeof DEFS],
|
|
1240
|
+
Path
|
|
1241
|
+
>
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
>
|
|
1245
|
+
>
|
|
1246
|
+
}> {
|
|
1024
1247
|
this._addHandler(method, path, handler, hook as LocalHook)
|
|
1025
1248
|
|
|
1026
1249
|
return this as any
|
package/src/types.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { Serve, Server } from 'bun'
|
|
|
4
4
|
import type { Context, PreContext } from './context'
|
|
5
5
|
import type { Static, TObject, TSchema } from '@sinclair/typebox'
|
|
6
6
|
import type { TypeCheck } from '@sinclair/typebox/compiler'
|
|
7
|
-
import
|
|
7
|
+
import { SCHEMA, DEFS, EXPOSED } from './utils'
|
|
8
8
|
import type { OpenAPIV3 } from 'openapi-types'
|
|
9
9
|
|
|
10
10
|
export type WithArray<T> = T | T[]
|
|
@@ -40,12 +40,7 @@ export type Handler<
|
|
|
40
40
|
Instance extends ElysiaInstance = ElysiaInstance,
|
|
41
41
|
CatchResponse = Route['response']
|
|
42
42
|
> = (
|
|
43
|
-
context: Context<Route, Instance['store']> &
|
|
44
|
-
Instance['request'] & {
|
|
45
|
-
a: Instance
|
|
46
|
-
r: Route
|
|
47
|
-
merged: MergeSchema<Instance['schema'], Route>
|
|
48
|
-
}
|
|
43
|
+
context: Context<Route, Instance['store']> & Instance['request']
|
|
49
44
|
) => // Catch function
|
|
50
45
|
Route['response'] extends (models: Record<string, TSchema>) => TSchema
|
|
51
46
|
? undefined extends ReturnType<Route['response']>
|
|
@@ -296,52 +291,132 @@ export type RouteToSchema<
|
|
|
296
291
|
params: Record<ExtractPath<Path>, string>
|
|
297
292
|
}
|
|
298
293
|
|
|
294
|
+
export type MergeUnionObjects<T> = {} & { [P in keyof T]: T[P] }
|
|
295
|
+
|
|
296
|
+
// export type ElysiaRouteSchema<
|
|
297
|
+
// Method extends string,
|
|
298
|
+
// Path extends string,
|
|
299
|
+
// CatchResponse,
|
|
300
|
+
// Schema extends TypedSchema<any>,
|
|
301
|
+
// Parent extends ElysiaInstance<any>['meta'][typeof SCHEMA],
|
|
302
|
+
// Definitions extends ElysiaInstance['meta'][typeof DEFS]
|
|
303
|
+
// > = Record<
|
|
304
|
+
// typeof SCHEMA,
|
|
305
|
+
// MergeUnionObjects<
|
|
306
|
+
// Parent & {
|
|
307
|
+
// [path in Path]: {
|
|
308
|
+
// [method in Method]: TypedRouteToEden<
|
|
309
|
+
// Schema,
|
|
310
|
+
// Definitions,
|
|
311
|
+
// Path
|
|
312
|
+
// > extends {
|
|
313
|
+
// body: infer Body extends AnyTypedSchema['body']
|
|
314
|
+
// headers: infer Headers extends AnyTypedSchema['headers']
|
|
315
|
+
// query: infer Query extends AnyTypedSchema['query']
|
|
316
|
+
// params: infer Params extends AnyTypedSchema['params']
|
|
317
|
+
// response: infer Response extends AnyTypedSchema['response']
|
|
318
|
+
// }
|
|
319
|
+
// ? {
|
|
320
|
+
// body: Body
|
|
321
|
+
// headers: Headers
|
|
322
|
+
// query: Query
|
|
323
|
+
// params: Params extends NonNullable<Params>
|
|
324
|
+
// ? Params
|
|
325
|
+
// : Record<ExtractPath<Path>, string>
|
|
326
|
+
// response: undefined extends Response
|
|
327
|
+
// ? {
|
|
328
|
+
// '200': CatchResponse
|
|
329
|
+
// }
|
|
330
|
+
// : Response
|
|
331
|
+
// }
|
|
332
|
+
// : never
|
|
333
|
+
// }
|
|
334
|
+
// }
|
|
335
|
+
// >
|
|
336
|
+
// >
|
|
337
|
+
|
|
299
338
|
export type ElysiaRoute<
|
|
300
339
|
Method extends string = string,
|
|
301
340
|
Schema extends TypedSchema = TypedSchema,
|
|
302
|
-
Instance extends ElysiaInstance = ElysiaInstance,
|
|
341
|
+
Instance extends ElysiaInstance<any> = ElysiaInstance,
|
|
303
342
|
Path extends string = string,
|
|
304
343
|
CatchResponse = unknown
|
|
305
344
|
> = Elysia<{
|
|
306
345
|
request: Instance['request']
|
|
307
346
|
store: Instance['store']
|
|
308
347
|
schema: Instance['schema']
|
|
309
|
-
meta: Instance['meta'] &
|
|
348
|
+
meta: Record<typeof DEFS, Instance['meta'][typeof DEFS]> &
|
|
349
|
+
Record<typeof EXPOSED, Instance['meta'][typeof EXPOSED]> &
|
|
310
350
|
Record<
|
|
311
351
|
typeof SCHEMA,
|
|
312
|
-
|
|
313
|
-
[
|
|
314
|
-
[
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
352
|
+
MergeUnionObjects<
|
|
353
|
+
Instance['meta'][typeof SCHEMA] & {
|
|
354
|
+
[path in Path]: {
|
|
355
|
+
[method in Method]: TypedRouteToEden<
|
|
356
|
+
Schema,
|
|
357
|
+
Instance['meta'][typeof DEFS],
|
|
358
|
+
Path
|
|
359
|
+
> extends {
|
|
360
|
+
body: infer Body extends AnyTypedSchema['body']
|
|
361
|
+
headers: infer Headers extends AnyTypedSchema['headers']
|
|
362
|
+
query: infer Query extends AnyTypedSchema['query']
|
|
363
|
+
params: infer Params extends AnyTypedSchema['params']
|
|
364
|
+
response: infer Response extends AnyTypedSchema['response']
|
|
365
|
+
}
|
|
366
|
+
? {
|
|
367
|
+
body: Body
|
|
368
|
+
headers: Headers
|
|
369
|
+
query: Query
|
|
370
|
+
params: Params extends NonNullable<Params>
|
|
371
|
+
? Params
|
|
372
|
+
: Record<ExtractPath<Path>, string>
|
|
373
|
+
response: undefined extends Response
|
|
374
|
+
? {
|
|
375
|
+
'200': CatchResponse
|
|
376
|
+
}
|
|
377
|
+
: Response
|
|
378
|
+
}
|
|
379
|
+
: never
|
|
380
|
+
}
|
|
327
381
|
}
|
|
328
|
-
|
|
382
|
+
>
|
|
329
383
|
>
|
|
330
384
|
}>
|
|
331
385
|
|
|
332
386
|
export type TypedRouteToEden<
|
|
333
387
|
Schema extends TypedSchema = TypedSchema,
|
|
334
|
-
|
|
388
|
+
Definitions extends TypedSchema<string> = ElysiaInstance['meta'][typeof DEFS],
|
|
335
389
|
Path extends string = string,
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
390
|
+
Typed extends AnyTypedSchema = TypedSchemaToEden<Schema, Definitions>
|
|
391
|
+
> = Schema['params'] extends NonNullable<Schema['params']>
|
|
392
|
+
? Typed extends AnyTypedSchema
|
|
393
|
+
? {
|
|
394
|
+
body: Typed['body']
|
|
395
|
+
headers: Typed['headers']
|
|
396
|
+
query: Typed['query']
|
|
397
|
+
params: Typed['params'] extends NonNullable<Typed['params']>
|
|
398
|
+
? Typed['params']
|
|
399
|
+
: Record<ExtractPath<Path>, string>
|
|
400
|
+
response: undefined extends Response
|
|
401
|
+
? {
|
|
402
|
+
'200': Response
|
|
403
|
+
}
|
|
404
|
+
: Response
|
|
405
|
+
}
|
|
406
|
+
: AnyTypedSchema
|
|
407
|
+
: Typed extends AnyTypedSchema
|
|
408
|
+
? {
|
|
409
|
+
body: Typed['body']
|
|
410
|
+
headers: Typed['headers']
|
|
411
|
+
query: Typed['query']
|
|
412
|
+
params: never
|
|
413
|
+
response: undefined extends Response
|
|
414
|
+
? {
|
|
415
|
+
'200': Response
|
|
416
|
+
}
|
|
417
|
+
: Response
|
|
344
418
|
}
|
|
419
|
+
: AnyTypedSchema
|
|
345
420
|
|
|
346
421
|
export type TypedSchemaToEden<
|
|
347
422
|
Schema extends TypedSchema,
|