arri 0.0.44 → 0.1.0-beta.10
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/LICENSE +9 -0
- package/README.md +11 -0
- package/dist/cli.cjs +165 -19892
- package/dist/cli.mjs +129 -19854
- package/dist/codegen.cjs +4 -523
- package/dist/codegen.d.cts +2 -71
- package/dist/codegen.d.mts +2 -71
- package/dist/codegen.d.ts +2 -71
- package/dist/codegen.mjs +2 -498
- package/dist/index.cjs +29 -679
- package/dist/index.d.cts +97 -67
- package/dist/index.d.mts +97 -67
- package/dist/index.d.ts +97 -67
- package/dist/index.mjs +6 -662
- package/dist/shared/arri.121d68e9.mjs +733 -0
- package/dist/shared/arri.ed4bd5e1.cjs +756 -0
- package/package.json +23 -13
- package/dist/chunks/index.cjs +0 -8911
- package/dist/chunks/index.mjs +0 -8889
- package/dist/shared/arri.0752aa2b.cjs +0 -192
- package/dist/shared/arri.4536bc49.d.cts +0 -77
- package/dist/shared/arri.4536bc49.d.mts +0 -77
- package/dist/shared/arri.4536bc49.d.ts +0 -77
- package/dist/shared/arri.bda2f011.cjs +0 -786
- package/dist/shared/arri.dfab1c78.mjs +0 -766
- package/dist/shared/arri.ebf86912.mjs +0 -179
package/dist/index.d.cts
CHANGED
|
@@ -1,124 +1,152 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { HttpMethod, RpcDefinition, AppDefinition, ClientGenerator } from 'arri-codegen-utils';
|
|
2
|
+
import * as arri_validate from 'arri-validate';
|
|
3
|
+
import { AObjectSchema, ASchema, InferType, a, ValidationError } from 'arri-validate';
|
|
4
|
+
import { H3EventContext, H3Event, Router, App, H3Error } from 'h3';
|
|
5
|
+
export * from 'h3';
|
|
6
6
|
import { BuildOptions } from 'esbuild';
|
|
7
7
|
|
|
8
|
-
interface
|
|
9
|
-
|
|
10
|
-
method: TMethod;
|
|
11
|
-
query?: TQuery;
|
|
12
|
-
body?: TBody;
|
|
13
|
-
response?: TResponse;
|
|
14
|
-
handler: ArriRouteHandler<TPath, TQuery extends TObject ? Static<TQuery> : undefined, TBody extends TSchema ? Static<TBody> : undefined, TResponse extends TSchema ? Static<TResponse> : TFallbackResponse>;
|
|
15
|
-
postHandler?: ArriRoutePostHandler<TPath, TQuery extends TObject ? Static<TQuery> : undefined, TBody extends TObject ? Static<TObject> : undefined, TResponse extends TSchema ? Static<TResponse> : TFallbackResponse>;
|
|
8
|
+
interface MiddlewareEventContext extends H3EventContext {
|
|
9
|
+
rpcName?: string;
|
|
16
10
|
}
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
interface MiddlewareEvent extends H3Event {
|
|
12
|
+
context: MiddlewareEventContext;
|
|
13
|
+
}
|
|
14
|
+
type Middleware = (event: MiddlewareEvent) => void | Promise<void>;
|
|
19
15
|
declare const defineMiddleware: (middleware: Middleware) => Middleware;
|
|
20
16
|
type ExtractParam<Path, NextPart> = Path extends `:${infer Param}` ? Record<Param, string> & NextPart : NextPart;
|
|
21
17
|
type ExtractParams<Path> = Path extends `${infer Segment}/${infer Rest}` ? ExtractParam<Segment, ExtractParams<Rest>> : ExtractParam<Path, {}>;
|
|
22
|
-
|
|
23
|
-
interface
|
|
24
|
-
|
|
25
|
-
params: TParams;
|
|
18
|
+
|
|
19
|
+
interface RouteEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> extends H3EventContext {
|
|
20
|
+
params: ExtractParams<TPath>;
|
|
26
21
|
query: TQuery;
|
|
27
22
|
body: TBody;
|
|
28
23
|
}
|
|
29
|
-
interface
|
|
24
|
+
interface RouteEvent<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> extends H3Event {
|
|
25
|
+
context: RouteEventContext<TPath, TQuery, TBody>;
|
|
26
|
+
}
|
|
27
|
+
interface PostRouteEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any, TResponse = any> extends RouteEventContext<TPath, TQuery, TBody> {
|
|
30
28
|
response: TResponse;
|
|
31
29
|
}
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
interface PostRouteEvent<TPath extends string, TQuery extends Record<any, any> = any, TBody = any, TResponse = any> extends H3Event {
|
|
31
|
+
context: PostRouteEventContext<TPath, TQuery, TBody, TResponse>;
|
|
32
|
+
}
|
|
33
|
+
interface ArriRoute<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any> {
|
|
34
|
+
path: TPath;
|
|
35
|
+
method: HttpMethod | HttpMethod[];
|
|
36
|
+
query?: TQuery;
|
|
37
|
+
body?: TBody;
|
|
38
|
+
handler: (event: RouteEvent<TPath, InferType<TQuery>, InferType<TBody>>) => TResponse;
|
|
39
|
+
postHandler?: (event: PostRouteEvent<TPath, InferType<TQuery>, InferType<TBody>, Awaited<TResponse>>) => any;
|
|
40
|
+
}
|
|
41
|
+
declare function defineRoute<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends AObjectSchema<any, any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): ArriRoute<TPath, TQuery, TBody, TResponse>;
|
|
42
|
+
type RouteOptions = Pick<ArriOptions, "onAfterResponse" | "onBeforeResponse" | "onError" | "onRequest"> & {
|
|
43
|
+
middleware: Middleware[];
|
|
44
|
+
};
|
|
45
|
+
declare function registerRoute(router: Router, route: ArriRoute<any>, opts: RouteOptions): void;
|
|
46
|
+
declare function handleRoute(router: Router, method: HttpMethod, route: ArriRoute<any>, opts: RouteOptions): void;
|
|
34
47
|
|
|
35
|
-
interface
|
|
36
|
-
method: HttpMethod;
|
|
37
|
-
params?: any;
|
|
38
|
-
response?: any;
|
|
39
|
-
handler: (context: any) => any;
|
|
40
|
-
postHandler?: (context: any) => any;
|
|
41
|
-
}
|
|
42
|
-
interface ArriProcedure<TParams extends TObject | undefined, TResponse extends TObject | undefined> {
|
|
48
|
+
interface ArriProcedure<TParams extends AObjectSchema | undefined, TResponse extends AObjectSchema | undefined> {
|
|
43
49
|
description?: string;
|
|
44
50
|
method?: HttpMethod;
|
|
51
|
+
path?: string;
|
|
45
52
|
params: TParams;
|
|
46
53
|
response: TResponse;
|
|
47
|
-
handler: ArriProcedureHandler<TParams extends
|
|
48
|
-
postHandler?: ArriProcedurePostHandler<TParams extends
|
|
54
|
+
handler: ArriProcedureHandler<TParams extends AObjectSchema ? InferType<TParams> : undefined, TResponse extends AObjectSchema ? InferType<TResponse> : void>;
|
|
55
|
+
postHandler?: ArriProcedurePostHandler<TParams extends AObjectSchema ? InferType<TParams> : undefined, TResponse extends AObjectSchema ? InferType<TResponse> : undefined>;
|
|
56
|
+
}
|
|
57
|
+
interface ArriNamedProcedure<TParams extends AObjectSchema | undefined, TResponse extends AObjectSchema | undefined> extends ArriProcedure<TParams, TResponse> {
|
|
58
|
+
name: string;
|
|
49
59
|
}
|
|
50
60
|
type HandlerContext = Record<string, any>;
|
|
51
|
-
interface RpcHandlerContext<TParams = undefined> extends HandlerContext {
|
|
52
|
-
|
|
61
|
+
interface RpcHandlerContext<TParams = undefined> extends HandlerContext, Omit<H3EventContext, "params"> {
|
|
62
|
+
rpcName: string;
|
|
53
63
|
params: TParams;
|
|
54
64
|
}
|
|
55
65
|
interface RpcPostHandlerContext<TParams = undefined, TResponse = undefined> extends RpcHandlerContext<TParams> {
|
|
56
66
|
response: TResponse;
|
|
57
67
|
}
|
|
58
|
-
|
|
59
|
-
|
|
68
|
+
interface RpcEvent<TParams = undefined> extends Omit<H3Event, "context"> {
|
|
69
|
+
context: RpcHandlerContext<TParams>;
|
|
70
|
+
}
|
|
71
|
+
interface RpcPostEvent<TParams = undefined, TResponse = undefined> extends Omit<H3Event, "context"> {
|
|
72
|
+
context: RpcPostHandlerContext<TParams, TResponse>;
|
|
73
|
+
}
|
|
74
|
+
type ArriProcedureHandler<TParams, TResponse> = (context: RpcHandlerContext<TParams>, event: RpcEvent<TParams>) => TResponse | Promise<TResponse>;
|
|
75
|
+
type ArriProcedurePostHandler<TParams, TResponse> = (context: RpcPostHandlerContext<TParams, TResponse>, event: RpcPostEvent<TParams, TResponse>) => any;
|
|
60
76
|
declare function isRpc(input: any): input is ArriProcedure<any, any>;
|
|
61
|
-
declare function defineRpc<TParams extends
|
|
62
|
-
declare function createRpcDefinition(rpcName: string, httpPath: string, procedure: ArriProcedure<any, any>):
|
|
77
|
+
declare function defineRpc<TParams extends AObjectSchema | undefined = undefined, TResponse extends AObjectSchema | undefined | never = undefined>(config: ArriProcedure<TParams, TResponse>): ArriProcedure<TParams, TResponse>;
|
|
78
|
+
declare function createRpcDefinition(rpcName: string, httpPath: string, procedure: ArriProcedure<any, any>): RpcDefinition;
|
|
63
79
|
declare function getRpcPath(rpcName: string, prefix?: string): string;
|
|
64
|
-
declare function getRpcParamName(rpcName: string, procedure: ArriProcedure<any, any>): string |
|
|
65
|
-
declare function
|
|
66
|
-
declare function
|
|
67
|
-
|
|
80
|
+
declare function getRpcParamName(rpcName: string, procedure: ArriProcedure<any, any>): string | undefined;
|
|
81
|
+
declare function getRpcResponseName(rpcName: string, procedure: ArriProcedure<any, any>): string | undefined;
|
|
82
|
+
declare function registerRpc(router: Router, path: string, procedure: ArriNamedProcedure<any, any>, opts: RouteOptions): void;
|
|
83
|
+
|
|
84
|
+
interface ArriRouterBase {
|
|
85
|
+
rpc: <TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: ArriNamedProcedure<TParams, TResponse>) => void;
|
|
86
|
+
route: <TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>) => void;
|
|
87
|
+
}
|
|
88
|
+
declare class ArriRouter implements ArriRouterBase {
|
|
89
|
+
private readonly procedures;
|
|
90
|
+
private readonly routes;
|
|
91
|
+
rpc<TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: ArriNamedProcedure<TParams, TResponse>): void;
|
|
92
|
+
route<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): void;
|
|
93
|
+
getProcedures(): ArriNamedProcedure<any, any>[];
|
|
94
|
+
getRoutes(): ArriRoute<any, any, any, any>[];
|
|
95
|
+
}
|
|
68
96
|
|
|
69
97
|
declare const DEV_ENDPOINT_ROOT = "/__arri_dev__";
|
|
70
|
-
declare const DEV_DEFINITION_ENDPOINT = "/__arri_dev__/
|
|
71
|
-
declare class
|
|
98
|
+
declare const DEV_DEFINITION_ENDPOINT = "/__arri_dev__/__definition";
|
|
99
|
+
declare class ArriApp implements ArriRouterBase {
|
|
72
100
|
__isArri__: boolean;
|
|
73
|
-
|
|
74
|
-
|
|
101
|
+
readonly h3App: App;
|
|
102
|
+
readonly h3Router: Router;
|
|
75
103
|
private readonly rpcDefinitionPath;
|
|
76
104
|
private readonly rpcRoutePrefix;
|
|
77
|
-
appInfo:
|
|
105
|
+
appInfo: AppDefinition["info"];
|
|
78
106
|
private procedures;
|
|
79
107
|
private models;
|
|
80
108
|
private readonly middlewares;
|
|
109
|
+
private readonly onRequest;
|
|
81
110
|
private readonly onAfterResponse;
|
|
82
111
|
private readonly onBeforeResponse;
|
|
83
112
|
private readonly onError;
|
|
84
113
|
constructor(opts?: ArriOptions);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
getAppDefinition():
|
|
89
|
-
getH3Instance(): App;
|
|
114
|
+
use(input: Middleware | ArriRouter): void;
|
|
115
|
+
rpc<TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: ArriNamedProcedure<TParams, TResponse>): void;
|
|
116
|
+
route<TPath extends string, TQuery extends AObjectSchema<any, any>, TBody extends ASchema<any>, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): void;
|
|
117
|
+
getAppDefinition(): AppDefinition;
|
|
90
118
|
}
|
|
91
119
|
interface ArriOptions {
|
|
92
120
|
debug?: boolean;
|
|
93
121
|
/**
|
|
94
122
|
* Metadata to display in the __definition.json file
|
|
95
123
|
*/
|
|
96
|
-
appInfo?:
|
|
124
|
+
appInfo?: AppDefinition["info"];
|
|
97
125
|
rpcRoutePrefix?: string;
|
|
98
126
|
/**
|
|
99
127
|
* Defaults to /__definitions
|
|
100
128
|
* This parameters also takes the rpcRoutePrefix option into account
|
|
101
129
|
*/
|
|
102
130
|
rpcDefinitionPath?: string;
|
|
103
|
-
onRequest?: (event:
|
|
104
|
-
onAfterResponse?: (
|
|
105
|
-
onBeforeResponse?: (
|
|
106
|
-
onError?: (error: H3Error,
|
|
131
|
+
onRequest?: (event: MiddlewareEvent) => void | Promise<void>;
|
|
132
|
+
onAfterResponse?: (event: MiddlewareEvent) => void | Promise<void>;
|
|
133
|
+
onBeforeResponse?: (event: MiddlewareEvent) => void | Promise<void>;
|
|
134
|
+
onError?: (error: H3Error, event: MiddlewareEvent) => void | Promise<void>;
|
|
107
135
|
}
|
|
108
136
|
|
|
109
|
-
declare const ErrorResponse:
|
|
110
|
-
statusCode:
|
|
111
|
-
statusMessage:
|
|
112
|
-
stack:
|
|
113
|
-
data:
|
|
114
|
-
}>;
|
|
115
|
-
type ErrorResponse =
|
|
137
|
+
declare const ErrorResponse: arri_validate.AObjectSchema<{
|
|
138
|
+
statusCode: number;
|
|
139
|
+
statusMessage: string;
|
|
140
|
+
stack: any[];
|
|
141
|
+
data: any;
|
|
142
|
+
}, false>;
|
|
143
|
+
type ErrorResponse = a.infer<typeof ErrorResponse>;
|
|
116
144
|
declare function defineError(statusCode: StatusCode, input?: Partial<Omit<ErrorResponse, "statusCode" | "stack">> & {
|
|
117
145
|
stack?: string;
|
|
118
146
|
}): H3Error;
|
|
119
|
-
declare function errorResponseFromValidationErrors(errors:
|
|
147
|
+
declare function errorResponseFromValidationErrors(errors: ValidationError["errors"], prefixText?: string): H3Error;
|
|
120
148
|
type StatusCode = number | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 507 | 511;
|
|
121
|
-
declare function handleH3Error(err: unknown,
|
|
149
|
+
declare function handleH3Error(err: unknown, event: H3Event, onError: ArriOptions["onError"]): Promise<void>;
|
|
122
150
|
|
|
123
151
|
interface ArriConfig {
|
|
124
152
|
port: number;
|
|
@@ -134,8 +162,10 @@ interface ArriConfig {
|
|
|
134
162
|
buildDir?: string;
|
|
135
163
|
esbuild?: Omit<BuildOptions, "outfile" | "outdir" | "entryNames" | "entryPoints">;
|
|
136
164
|
}
|
|
165
|
+
declare function isArriConfig(input: unknown): input is ArriConfig;
|
|
166
|
+
declare function isResolvedArriConfig(input: unknown): input is ResolvedArriConfig;
|
|
137
167
|
type ResolvedArriConfig = Required<ArriConfig>;
|
|
138
168
|
declare const defaultConfig: Required<ArriConfig>;
|
|
139
169
|
declare function defineConfig(config: ArriConfig): ResolvedArriConfig;
|
|
140
170
|
|
|
141
|
-
export {
|
|
171
|
+
export { ArriApp, type ArriConfig, type ArriNamedProcedure, type ArriOptions, type ArriProcedure, type ArriProcedureHandler, type ArriProcedurePostHandler, type ArriRoute, ArriRouter, type ArriRouterBase, DEV_DEFINITION_ENDPOINT, DEV_ENDPOINT_ROOT, ErrorResponse, type ExtractParam, type ExtractParams, type HandlerContext, type Middleware, type MiddlewareEvent, type MiddlewareEventContext, type PostRouteEvent, type PostRouteEventContext, type ResolvedArriConfig, type RouteEvent, type RouteEventContext, type RouteOptions, type RpcEvent, type RpcHandlerContext, type RpcPostEvent, type RpcPostHandlerContext, type StatusCode, createRpcDefinition, defaultConfig, defineConfig, defineError, defineMiddleware, defineRoute, defineRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, handleRoute, isArriConfig, isResolvedArriConfig, isRpc, registerRoute, registerRpc };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,124 +1,152 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { HttpMethod, RpcDefinition, AppDefinition, ClientGenerator } from 'arri-codegen-utils';
|
|
2
|
+
import * as arri_validate from 'arri-validate';
|
|
3
|
+
import { AObjectSchema, ASchema, InferType, a, ValidationError } from 'arri-validate';
|
|
4
|
+
import { H3EventContext, H3Event, Router, App, H3Error } from 'h3';
|
|
5
|
+
export * from 'h3';
|
|
6
6
|
import { BuildOptions } from 'esbuild';
|
|
7
7
|
|
|
8
|
-
interface
|
|
9
|
-
|
|
10
|
-
method: TMethod;
|
|
11
|
-
query?: TQuery;
|
|
12
|
-
body?: TBody;
|
|
13
|
-
response?: TResponse;
|
|
14
|
-
handler: ArriRouteHandler<TPath, TQuery extends TObject ? Static<TQuery> : undefined, TBody extends TSchema ? Static<TBody> : undefined, TResponse extends TSchema ? Static<TResponse> : TFallbackResponse>;
|
|
15
|
-
postHandler?: ArriRoutePostHandler<TPath, TQuery extends TObject ? Static<TQuery> : undefined, TBody extends TObject ? Static<TObject> : undefined, TResponse extends TSchema ? Static<TResponse> : TFallbackResponse>;
|
|
8
|
+
interface MiddlewareEventContext extends H3EventContext {
|
|
9
|
+
rpcName?: string;
|
|
16
10
|
}
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
interface MiddlewareEvent extends H3Event {
|
|
12
|
+
context: MiddlewareEventContext;
|
|
13
|
+
}
|
|
14
|
+
type Middleware = (event: MiddlewareEvent) => void | Promise<void>;
|
|
19
15
|
declare const defineMiddleware: (middleware: Middleware) => Middleware;
|
|
20
16
|
type ExtractParam<Path, NextPart> = Path extends `:${infer Param}` ? Record<Param, string> & NextPart : NextPart;
|
|
21
17
|
type ExtractParams<Path> = Path extends `${infer Segment}/${infer Rest}` ? ExtractParam<Segment, ExtractParams<Rest>> : ExtractParam<Path, {}>;
|
|
22
|
-
|
|
23
|
-
interface
|
|
24
|
-
|
|
25
|
-
params: TParams;
|
|
18
|
+
|
|
19
|
+
interface RouteEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> extends H3EventContext {
|
|
20
|
+
params: ExtractParams<TPath>;
|
|
26
21
|
query: TQuery;
|
|
27
22
|
body: TBody;
|
|
28
23
|
}
|
|
29
|
-
interface
|
|
24
|
+
interface RouteEvent<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> extends H3Event {
|
|
25
|
+
context: RouteEventContext<TPath, TQuery, TBody>;
|
|
26
|
+
}
|
|
27
|
+
interface PostRouteEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any, TResponse = any> extends RouteEventContext<TPath, TQuery, TBody> {
|
|
30
28
|
response: TResponse;
|
|
31
29
|
}
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
interface PostRouteEvent<TPath extends string, TQuery extends Record<any, any> = any, TBody = any, TResponse = any> extends H3Event {
|
|
31
|
+
context: PostRouteEventContext<TPath, TQuery, TBody, TResponse>;
|
|
32
|
+
}
|
|
33
|
+
interface ArriRoute<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any> {
|
|
34
|
+
path: TPath;
|
|
35
|
+
method: HttpMethod | HttpMethod[];
|
|
36
|
+
query?: TQuery;
|
|
37
|
+
body?: TBody;
|
|
38
|
+
handler: (event: RouteEvent<TPath, InferType<TQuery>, InferType<TBody>>) => TResponse;
|
|
39
|
+
postHandler?: (event: PostRouteEvent<TPath, InferType<TQuery>, InferType<TBody>, Awaited<TResponse>>) => any;
|
|
40
|
+
}
|
|
41
|
+
declare function defineRoute<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends AObjectSchema<any, any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): ArriRoute<TPath, TQuery, TBody, TResponse>;
|
|
42
|
+
type RouteOptions = Pick<ArriOptions, "onAfterResponse" | "onBeforeResponse" | "onError" | "onRequest"> & {
|
|
43
|
+
middleware: Middleware[];
|
|
44
|
+
};
|
|
45
|
+
declare function registerRoute(router: Router, route: ArriRoute<any>, opts: RouteOptions): void;
|
|
46
|
+
declare function handleRoute(router: Router, method: HttpMethod, route: ArriRoute<any>, opts: RouteOptions): void;
|
|
34
47
|
|
|
35
|
-
interface
|
|
36
|
-
method: HttpMethod;
|
|
37
|
-
params?: any;
|
|
38
|
-
response?: any;
|
|
39
|
-
handler: (context: any) => any;
|
|
40
|
-
postHandler?: (context: any) => any;
|
|
41
|
-
}
|
|
42
|
-
interface ArriProcedure<TParams extends TObject | undefined, TResponse extends TObject | undefined> {
|
|
48
|
+
interface ArriProcedure<TParams extends AObjectSchema | undefined, TResponse extends AObjectSchema | undefined> {
|
|
43
49
|
description?: string;
|
|
44
50
|
method?: HttpMethod;
|
|
51
|
+
path?: string;
|
|
45
52
|
params: TParams;
|
|
46
53
|
response: TResponse;
|
|
47
|
-
handler: ArriProcedureHandler<TParams extends
|
|
48
|
-
postHandler?: ArriProcedurePostHandler<TParams extends
|
|
54
|
+
handler: ArriProcedureHandler<TParams extends AObjectSchema ? InferType<TParams> : undefined, TResponse extends AObjectSchema ? InferType<TResponse> : void>;
|
|
55
|
+
postHandler?: ArriProcedurePostHandler<TParams extends AObjectSchema ? InferType<TParams> : undefined, TResponse extends AObjectSchema ? InferType<TResponse> : undefined>;
|
|
56
|
+
}
|
|
57
|
+
interface ArriNamedProcedure<TParams extends AObjectSchema | undefined, TResponse extends AObjectSchema | undefined> extends ArriProcedure<TParams, TResponse> {
|
|
58
|
+
name: string;
|
|
49
59
|
}
|
|
50
60
|
type HandlerContext = Record<string, any>;
|
|
51
|
-
interface RpcHandlerContext<TParams = undefined> extends HandlerContext {
|
|
52
|
-
|
|
61
|
+
interface RpcHandlerContext<TParams = undefined> extends HandlerContext, Omit<H3EventContext, "params"> {
|
|
62
|
+
rpcName: string;
|
|
53
63
|
params: TParams;
|
|
54
64
|
}
|
|
55
65
|
interface RpcPostHandlerContext<TParams = undefined, TResponse = undefined> extends RpcHandlerContext<TParams> {
|
|
56
66
|
response: TResponse;
|
|
57
67
|
}
|
|
58
|
-
|
|
59
|
-
|
|
68
|
+
interface RpcEvent<TParams = undefined> extends Omit<H3Event, "context"> {
|
|
69
|
+
context: RpcHandlerContext<TParams>;
|
|
70
|
+
}
|
|
71
|
+
interface RpcPostEvent<TParams = undefined, TResponse = undefined> extends Omit<H3Event, "context"> {
|
|
72
|
+
context: RpcPostHandlerContext<TParams, TResponse>;
|
|
73
|
+
}
|
|
74
|
+
type ArriProcedureHandler<TParams, TResponse> = (context: RpcHandlerContext<TParams>, event: RpcEvent<TParams>) => TResponse | Promise<TResponse>;
|
|
75
|
+
type ArriProcedurePostHandler<TParams, TResponse> = (context: RpcPostHandlerContext<TParams, TResponse>, event: RpcPostEvent<TParams, TResponse>) => any;
|
|
60
76
|
declare function isRpc(input: any): input is ArriProcedure<any, any>;
|
|
61
|
-
declare function defineRpc<TParams extends
|
|
62
|
-
declare function createRpcDefinition(rpcName: string, httpPath: string, procedure: ArriProcedure<any, any>):
|
|
77
|
+
declare function defineRpc<TParams extends AObjectSchema | undefined = undefined, TResponse extends AObjectSchema | undefined | never = undefined>(config: ArriProcedure<TParams, TResponse>): ArriProcedure<TParams, TResponse>;
|
|
78
|
+
declare function createRpcDefinition(rpcName: string, httpPath: string, procedure: ArriProcedure<any, any>): RpcDefinition;
|
|
63
79
|
declare function getRpcPath(rpcName: string, prefix?: string): string;
|
|
64
|
-
declare function getRpcParamName(rpcName: string, procedure: ArriProcedure<any, any>): string |
|
|
65
|
-
declare function
|
|
66
|
-
declare function
|
|
67
|
-
|
|
80
|
+
declare function getRpcParamName(rpcName: string, procedure: ArriProcedure<any, any>): string | undefined;
|
|
81
|
+
declare function getRpcResponseName(rpcName: string, procedure: ArriProcedure<any, any>): string | undefined;
|
|
82
|
+
declare function registerRpc(router: Router, path: string, procedure: ArriNamedProcedure<any, any>, opts: RouteOptions): void;
|
|
83
|
+
|
|
84
|
+
interface ArriRouterBase {
|
|
85
|
+
rpc: <TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: ArriNamedProcedure<TParams, TResponse>) => void;
|
|
86
|
+
route: <TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>) => void;
|
|
87
|
+
}
|
|
88
|
+
declare class ArriRouter implements ArriRouterBase {
|
|
89
|
+
private readonly procedures;
|
|
90
|
+
private readonly routes;
|
|
91
|
+
rpc<TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: ArriNamedProcedure<TParams, TResponse>): void;
|
|
92
|
+
route<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): void;
|
|
93
|
+
getProcedures(): ArriNamedProcedure<any, any>[];
|
|
94
|
+
getRoutes(): ArriRoute<any, any, any, any>[];
|
|
95
|
+
}
|
|
68
96
|
|
|
69
97
|
declare const DEV_ENDPOINT_ROOT = "/__arri_dev__";
|
|
70
|
-
declare const DEV_DEFINITION_ENDPOINT = "/__arri_dev__/
|
|
71
|
-
declare class
|
|
98
|
+
declare const DEV_DEFINITION_ENDPOINT = "/__arri_dev__/__definition";
|
|
99
|
+
declare class ArriApp implements ArriRouterBase {
|
|
72
100
|
__isArri__: boolean;
|
|
73
|
-
|
|
74
|
-
|
|
101
|
+
readonly h3App: App;
|
|
102
|
+
readonly h3Router: Router;
|
|
75
103
|
private readonly rpcDefinitionPath;
|
|
76
104
|
private readonly rpcRoutePrefix;
|
|
77
|
-
appInfo:
|
|
105
|
+
appInfo: AppDefinition["info"];
|
|
78
106
|
private procedures;
|
|
79
107
|
private models;
|
|
80
108
|
private readonly middlewares;
|
|
109
|
+
private readonly onRequest;
|
|
81
110
|
private readonly onAfterResponse;
|
|
82
111
|
private readonly onBeforeResponse;
|
|
83
112
|
private readonly onError;
|
|
84
113
|
constructor(opts?: ArriOptions);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
getAppDefinition():
|
|
89
|
-
getH3Instance(): App;
|
|
114
|
+
use(input: Middleware | ArriRouter): void;
|
|
115
|
+
rpc<TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: ArriNamedProcedure<TParams, TResponse>): void;
|
|
116
|
+
route<TPath extends string, TQuery extends AObjectSchema<any, any>, TBody extends ASchema<any>, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): void;
|
|
117
|
+
getAppDefinition(): AppDefinition;
|
|
90
118
|
}
|
|
91
119
|
interface ArriOptions {
|
|
92
120
|
debug?: boolean;
|
|
93
121
|
/**
|
|
94
122
|
* Metadata to display in the __definition.json file
|
|
95
123
|
*/
|
|
96
|
-
appInfo?:
|
|
124
|
+
appInfo?: AppDefinition["info"];
|
|
97
125
|
rpcRoutePrefix?: string;
|
|
98
126
|
/**
|
|
99
127
|
* Defaults to /__definitions
|
|
100
128
|
* This parameters also takes the rpcRoutePrefix option into account
|
|
101
129
|
*/
|
|
102
130
|
rpcDefinitionPath?: string;
|
|
103
|
-
onRequest?: (event:
|
|
104
|
-
onAfterResponse?: (
|
|
105
|
-
onBeforeResponse?: (
|
|
106
|
-
onError?: (error: H3Error,
|
|
131
|
+
onRequest?: (event: MiddlewareEvent) => void | Promise<void>;
|
|
132
|
+
onAfterResponse?: (event: MiddlewareEvent) => void | Promise<void>;
|
|
133
|
+
onBeforeResponse?: (event: MiddlewareEvent) => void | Promise<void>;
|
|
134
|
+
onError?: (error: H3Error, event: MiddlewareEvent) => void | Promise<void>;
|
|
107
135
|
}
|
|
108
136
|
|
|
109
|
-
declare const ErrorResponse:
|
|
110
|
-
statusCode:
|
|
111
|
-
statusMessage:
|
|
112
|
-
stack:
|
|
113
|
-
data:
|
|
114
|
-
}>;
|
|
115
|
-
type ErrorResponse =
|
|
137
|
+
declare const ErrorResponse: arri_validate.AObjectSchema<{
|
|
138
|
+
statusCode: number;
|
|
139
|
+
statusMessage: string;
|
|
140
|
+
stack: any[];
|
|
141
|
+
data: any;
|
|
142
|
+
}, false>;
|
|
143
|
+
type ErrorResponse = a.infer<typeof ErrorResponse>;
|
|
116
144
|
declare function defineError(statusCode: StatusCode, input?: Partial<Omit<ErrorResponse, "statusCode" | "stack">> & {
|
|
117
145
|
stack?: string;
|
|
118
146
|
}): H3Error;
|
|
119
|
-
declare function errorResponseFromValidationErrors(errors:
|
|
147
|
+
declare function errorResponseFromValidationErrors(errors: ValidationError["errors"], prefixText?: string): H3Error;
|
|
120
148
|
type StatusCode = number | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 507 | 511;
|
|
121
|
-
declare function handleH3Error(err: unknown,
|
|
149
|
+
declare function handleH3Error(err: unknown, event: H3Event, onError: ArriOptions["onError"]): Promise<void>;
|
|
122
150
|
|
|
123
151
|
interface ArriConfig {
|
|
124
152
|
port: number;
|
|
@@ -134,8 +162,10 @@ interface ArriConfig {
|
|
|
134
162
|
buildDir?: string;
|
|
135
163
|
esbuild?: Omit<BuildOptions, "outfile" | "outdir" | "entryNames" | "entryPoints">;
|
|
136
164
|
}
|
|
165
|
+
declare function isArriConfig(input: unknown): input is ArriConfig;
|
|
166
|
+
declare function isResolvedArriConfig(input: unknown): input is ResolvedArriConfig;
|
|
137
167
|
type ResolvedArriConfig = Required<ArriConfig>;
|
|
138
168
|
declare const defaultConfig: Required<ArriConfig>;
|
|
139
169
|
declare function defineConfig(config: ArriConfig): ResolvedArriConfig;
|
|
140
170
|
|
|
141
|
-
export {
|
|
171
|
+
export { ArriApp, type ArriConfig, type ArriNamedProcedure, type ArriOptions, type ArriProcedure, type ArriProcedureHandler, type ArriProcedurePostHandler, type ArriRoute, ArriRouter, type ArriRouterBase, DEV_DEFINITION_ENDPOINT, DEV_ENDPOINT_ROOT, ErrorResponse, type ExtractParam, type ExtractParams, type HandlerContext, type Middleware, type MiddlewareEvent, type MiddlewareEventContext, type PostRouteEvent, type PostRouteEventContext, type ResolvedArriConfig, type RouteEvent, type RouteEventContext, type RouteOptions, type RpcEvent, type RpcHandlerContext, type RpcPostEvent, type RpcPostHandlerContext, type StatusCode, createRpcDefinition, defaultConfig, defineConfig, defineError, defineMiddleware, defineRoute, defineRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, handleRoute, isArriConfig, isResolvedArriConfig, isRpc, registerRoute, registerRpc };
|