arri 0.0.44 → 0.1.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/LICENSE +9 -0
- package/README.md +11 -0
- package/dist/cli.cjs +166 -19894
- package/dist/cli.mjs +130 -19856
- 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 +26 -679
- package/dist/index.d.cts +73 -68
- package/dist/index.d.mts +73 -68
- package/dist/index.d.ts +73 -68
- package/dist/index.mjs +6 -662
- package/dist/shared/arri.406d936a.cjs +697 -0
- package/dist/shared/arri.8539c7bd.mjs +677 -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,55 +1,46 @@
|
|
|
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, InferType, a, ValidationError } from 'arri-validate';
|
|
4
|
+
import { H3Event, H3EventContext, Router, App, H3Error } from 'h3';
|
|
5
|
+
export * from 'h3';
|
|
6
6
|
import { BuildOptions } from 'esbuild';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
path: TPath;
|
|
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>;
|
|
16
|
-
}
|
|
17
|
-
declare function defineRoute<TPath extends string, TMethod extends HttpMethod, TQuery extends TObject | undefined = any, TBody extends TSchema | undefined = any, TResponse extends TSchema | undefined = undefined, TFallbackResponse = any>(config: ArriRoute<TPath, TMethod, TQuery, TBody, TResponse, TFallbackResponse>): ArriRoute<TPath, TMethod, TQuery, TBody, TResponse, TFallbackResponse>;
|
|
18
|
-
type Middleware = (context: HandlerContext, event: H3Event) => void | Promise<void>;
|
|
8
|
+
type Middleware = (event: H3Event) => void | Promise<void>;
|
|
19
9
|
declare const defineMiddleware: (middleware: Middleware) => Middleware;
|
|
10
|
+
type ExtractParam$1<Path, NextPart> = Path extends `:${infer Param}` ? Record<Param, string> & NextPart : NextPart;
|
|
11
|
+
type ExtractParams$1<Path> = Path extends `${infer Segment}/${infer Rest}` ? ExtractParam$1<Segment, ExtractParams$1<Rest>> : ExtractParam$1<Path, {}>;
|
|
12
|
+
|
|
20
13
|
type ExtractParam<Path, NextPart> = Path extends `:${infer Param}` ? Record<Param, string> & NextPart : NextPart;
|
|
21
14
|
type ExtractParams<Path> = Path extends `${infer Segment}/${infer Rest}` ? ExtractParam<Segment, ExtractParams<Rest>> : ExtractParam<Path, {}>;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
type: "route";
|
|
25
|
-
params: TParams;
|
|
26
|
-
query: TQuery;
|
|
27
|
-
body: TBody;
|
|
15
|
+
interface RouteEventContext<TPath extends string> extends H3EventContext {
|
|
16
|
+
params: ExtractParams<TPath>;
|
|
28
17
|
}
|
|
29
|
-
interface
|
|
30
|
-
|
|
18
|
+
interface RouteEvent<TPath extends string> extends H3Event {
|
|
19
|
+
context: RouteEventContext<TPath>;
|
|
31
20
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
params?: any;
|
|
38
|
-
response?: any;
|
|
39
|
-
handler: (context: any) => any;
|
|
40
|
-
postHandler?: (context: any) => any;
|
|
21
|
+
interface ArriRoute<TPath extends string> {
|
|
22
|
+
path: TPath;
|
|
23
|
+
method: HttpMethod | HttpMethod[];
|
|
24
|
+
handler: (event: RouteEvent<TPath>) => any;
|
|
25
|
+
postHandler?: (event: RouteEvent<TPath>) => any;
|
|
41
26
|
}
|
|
42
|
-
|
|
27
|
+
type RouteOptions = Pick<ArriOptions, "onAfterResponse" | "onBeforeResponse" | "onError" | "onRequest"> & {
|
|
28
|
+
middleware: Middleware[];
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
interface ArriProcedure<TParams extends AObjectSchema | undefined, TResponse extends AObjectSchema | undefined> {
|
|
43
32
|
description?: string;
|
|
44
33
|
method?: HttpMethod;
|
|
45
34
|
params: TParams;
|
|
46
35
|
response: TResponse;
|
|
47
|
-
handler: ArriProcedureHandler<TParams extends
|
|
48
|
-
postHandler?: ArriProcedurePostHandler<TParams extends
|
|
36
|
+
handler: ArriProcedureHandler<TParams extends AObjectSchema ? InferType<TParams> : undefined, TResponse extends AObjectSchema ? InferType<TResponse> : void>;
|
|
37
|
+
postHandler?: ArriProcedurePostHandler<TParams extends AObjectSchema ? InferType<TParams> : undefined, TResponse extends AObjectSchema ? InferType<TResponse> : undefined>;
|
|
38
|
+
}
|
|
39
|
+
interface ArriNamedProcedure<TParams extends AObjectSchema | undefined, TResponse extends AObjectSchema | undefined> extends ArriProcedure<TParams, TResponse> {
|
|
40
|
+
name: string;
|
|
49
41
|
}
|
|
50
42
|
type HandlerContext = Record<string, any>;
|
|
51
|
-
interface RpcHandlerContext<TParams = undefined> extends HandlerContext {
|
|
52
|
-
type: "procedure";
|
|
43
|
+
interface RpcHandlerContext<TParams = undefined> extends HandlerContext, Omit<H3EventContext, "params"> {
|
|
53
44
|
params: TParams;
|
|
54
45
|
}
|
|
55
46
|
interface RpcPostHandlerContext<TParams = undefined, TResponse = undefined> extends RpcHandlerContext<TParams> {
|
|
@@ -58,42 +49,54 @@ interface RpcPostHandlerContext<TParams = undefined, TResponse = undefined> exte
|
|
|
58
49
|
type ArriProcedureHandler<TParams, TResponse> = (context: RpcHandlerContext<TParams>, event: H3Event) => TResponse | Promise<TResponse>;
|
|
59
50
|
type ArriProcedurePostHandler<TParams, TResponse> = (context: RpcPostHandlerContext<TParams, TResponse>, event: H3Event) => any;
|
|
60
51
|
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>):
|
|
52
|
+
declare function defineRpc<TParams extends AObjectSchema | undefined = undefined, TResponse extends AObjectSchema | undefined | never = undefined>(config: ArriProcedure<TParams, TResponse>): ArriProcedure<TParams, TResponse>;
|
|
53
|
+
declare function createRpcDefinition(rpcName: string, httpPath: string, procedure: ArriProcedure<any, any>): RpcDefinition;
|
|
63
54
|
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
|
-
|
|
55
|
+
declare function getRpcParamName(rpcName: string, procedure: ArriProcedure<any, any>): string | undefined;
|
|
56
|
+
declare function getRpcResponseName(rpcName: string, procedure: ArriProcedure<any, any>): string | undefined;
|
|
57
|
+
declare function registerRpc(router: Router, path: string, procedure: ArriProcedure<any, any>, opts: RouteOptions): void;
|
|
58
|
+
|
|
59
|
+
interface ArriRouterBase {
|
|
60
|
+
rpc: <TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: ArriNamedProcedure<TParams, TResponse>) => void;
|
|
61
|
+
route: <TPath extends string>(route: ArriRoute<TPath>) => void;
|
|
62
|
+
}
|
|
63
|
+
declare class ArriRouter implements ArriRouterBase {
|
|
64
|
+
private readonly procedures;
|
|
65
|
+
private readonly routes;
|
|
66
|
+
rpc<TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: ArriNamedProcedure<TParams, TResponse>): void;
|
|
67
|
+
route<TPath extends string>(route: ArriRoute<TPath>): void;
|
|
68
|
+
getProcedures(): ArriNamedProcedure<any, any>[];
|
|
69
|
+
getRoutes(): ArriRoute<any>[];
|
|
70
|
+
}
|
|
68
71
|
|
|
69
72
|
declare const DEV_ENDPOINT_ROOT = "/__arri_dev__";
|
|
70
|
-
declare const DEV_DEFINITION_ENDPOINT = "/__arri_dev__/
|
|
71
|
-
declare class
|
|
73
|
+
declare const DEV_DEFINITION_ENDPOINT = "/__arri_dev__/__definition";
|
|
74
|
+
declare class ArriApp implements ArriRouterBase {
|
|
72
75
|
__isArri__: boolean;
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
readonly h3App: App;
|
|
77
|
+
readonly h3Router: Router;
|
|
75
78
|
private readonly rpcDefinitionPath;
|
|
76
79
|
private readonly rpcRoutePrefix;
|
|
77
|
-
appInfo:
|
|
80
|
+
appInfo: AppDefinition["info"];
|
|
78
81
|
private procedures;
|
|
79
82
|
private models;
|
|
80
83
|
private readonly middlewares;
|
|
84
|
+
private readonly onRequest;
|
|
81
85
|
private readonly onAfterResponse;
|
|
82
86
|
private readonly onBeforeResponse;
|
|
83
87
|
private readonly onError;
|
|
84
88
|
constructor(opts?: ArriOptions);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
getAppDefinition():
|
|
89
|
-
getH3Instance(): App;
|
|
89
|
+
use(input: Middleware | ArriRouter): void;
|
|
90
|
+
rpc<TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: ArriNamedProcedure<TParams, TResponse>): void;
|
|
91
|
+
route<TPath extends string>(route: ArriRoute<TPath>): void;
|
|
92
|
+
getAppDefinition(): AppDefinition;
|
|
90
93
|
}
|
|
91
94
|
interface ArriOptions {
|
|
92
95
|
debug?: boolean;
|
|
93
96
|
/**
|
|
94
97
|
* Metadata to display in the __definition.json file
|
|
95
98
|
*/
|
|
96
|
-
appInfo?:
|
|
99
|
+
appInfo?: AppDefinition["info"];
|
|
97
100
|
rpcRoutePrefix?: string;
|
|
98
101
|
/**
|
|
99
102
|
* Defaults to /__definitions
|
|
@@ -101,24 +104,24 @@ interface ArriOptions {
|
|
|
101
104
|
*/
|
|
102
105
|
rpcDefinitionPath?: string;
|
|
103
106
|
onRequest?: (event: H3Event) => void | Promise<void>;
|
|
104
|
-
onAfterResponse?: (
|
|
105
|
-
onBeforeResponse?: (
|
|
106
|
-
onError?: (error: H3Error,
|
|
107
|
+
onAfterResponse?: (event: H3Event) => void | Promise<void>;
|
|
108
|
+
onBeforeResponse?: (event: H3Event) => void | Promise<void>;
|
|
109
|
+
onError?: (error: H3Error, event: H3Event) => void | Promise<void>;
|
|
107
110
|
}
|
|
108
111
|
|
|
109
|
-
declare const ErrorResponse:
|
|
110
|
-
statusCode:
|
|
111
|
-
statusMessage:
|
|
112
|
-
stack:
|
|
113
|
-
data:
|
|
114
|
-
}>;
|
|
115
|
-
type ErrorResponse =
|
|
112
|
+
declare const ErrorResponse: arri_validate.AObjectSchema<{
|
|
113
|
+
statusCode: number;
|
|
114
|
+
statusMessage: string;
|
|
115
|
+
stack: any[];
|
|
116
|
+
data: any;
|
|
117
|
+
}, false>;
|
|
118
|
+
type ErrorResponse = a.infer<typeof ErrorResponse>;
|
|
116
119
|
declare function defineError(statusCode: StatusCode, input?: Partial<Omit<ErrorResponse, "statusCode" | "stack">> & {
|
|
117
120
|
stack?: string;
|
|
118
121
|
}): H3Error;
|
|
119
|
-
declare function errorResponseFromValidationErrors(errors:
|
|
122
|
+
declare function errorResponseFromValidationErrors(errors: ValidationError["errors"], prefixText?: string): H3Error;
|
|
120
123
|
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,
|
|
124
|
+
declare function handleH3Error(err: unknown, event: H3Event, onError: ArriOptions["onError"]): Promise<void>;
|
|
122
125
|
|
|
123
126
|
interface ArriConfig {
|
|
124
127
|
port: number;
|
|
@@ -134,8 +137,10 @@ interface ArriConfig {
|
|
|
134
137
|
buildDir?: string;
|
|
135
138
|
esbuild?: Omit<BuildOptions, "outfile" | "outdir" | "entryNames" | "entryPoints">;
|
|
136
139
|
}
|
|
140
|
+
declare function isArriConfig(input: unknown): input is ArriConfig;
|
|
141
|
+
declare function isResolvedArriConfig(input: unknown): input is ResolvedArriConfig;
|
|
137
142
|
type ResolvedArriConfig = Required<ArriConfig>;
|
|
138
143
|
declare const defaultConfig: Required<ArriConfig>;
|
|
139
144
|
declare function defineConfig(config: ArriConfig): ResolvedArriConfig;
|
|
140
145
|
|
|
141
|
-
export {
|
|
146
|
+
export { ArriApp, type ArriConfig, type ArriNamedProcedure, type ArriOptions, type ArriProcedure, type ArriProcedureHandler, type ArriProcedurePostHandler, ArriRouter, type ArriRouterBase, DEV_DEFINITION_ENDPOINT, DEV_ENDPOINT_ROOT, ErrorResponse, type ExtractParam$1 as ExtractParam, type ExtractParams$1 as ExtractParams, type HandlerContext, type Middleware, type ResolvedArriConfig, type RpcHandlerContext, type RpcPostHandlerContext, type StatusCode, createRpcDefinition, defaultConfig, defineConfig, defineError, defineMiddleware, defineRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, isArriConfig, isResolvedArriConfig, isRpc, registerRpc };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,55 +1,46 @@
|
|
|
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, InferType, a, ValidationError } from 'arri-validate';
|
|
4
|
+
import { H3Event, H3EventContext, Router, App, H3Error } from 'h3';
|
|
5
|
+
export * from 'h3';
|
|
6
6
|
import { BuildOptions } from 'esbuild';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
path: TPath;
|
|
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>;
|
|
16
|
-
}
|
|
17
|
-
declare function defineRoute<TPath extends string, TMethod extends HttpMethod, TQuery extends TObject | undefined = any, TBody extends TSchema | undefined = any, TResponse extends TSchema | undefined = undefined, TFallbackResponse = any>(config: ArriRoute<TPath, TMethod, TQuery, TBody, TResponse, TFallbackResponse>): ArriRoute<TPath, TMethod, TQuery, TBody, TResponse, TFallbackResponse>;
|
|
18
|
-
type Middleware = (context: HandlerContext, event: H3Event) => void | Promise<void>;
|
|
8
|
+
type Middleware = (event: H3Event) => void | Promise<void>;
|
|
19
9
|
declare const defineMiddleware: (middleware: Middleware) => Middleware;
|
|
10
|
+
type ExtractParam$1<Path, NextPart> = Path extends `:${infer Param}` ? Record<Param, string> & NextPart : NextPart;
|
|
11
|
+
type ExtractParams$1<Path> = Path extends `${infer Segment}/${infer Rest}` ? ExtractParam$1<Segment, ExtractParams$1<Rest>> : ExtractParam$1<Path, {}>;
|
|
12
|
+
|
|
20
13
|
type ExtractParam<Path, NextPart> = Path extends `:${infer Param}` ? Record<Param, string> & NextPart : NextPart;
|
|
21
14
|
type ExtractParams<Path> = Path extends `${infer Segment}/${infer Rest}` ? ExtractParam<Segment, ExtractParams<Rest>> : ExtractParam<Path, {}>;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
type: "route";
|
|
25
|
-
params: TParams;
|
|
26
|
-
query: TQuery;
|
|
27
|
-
body: TBody;
|
|
15
|
+
interface RouteEventContext<TPath extends string> extends H3EventContext {
|
|
16
|
+
params: ExtractParams<TPath>;
|
|
28
17
|
}
|
|
29
|
-
interface
|
|
30
|
-
|
|
18
|
+
interface RouteEvent<TPath extends string> extends H3Event {
|
|
19
|
+
context: RouteEventContext<TPath>;
|
|
31
20
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
params?: any;
|
|
38
|
-
response?: any;
|
|
39
|
-
handler: (context: any) => any;
|
|
40
|
-
postHandler?: (context: any) => any;
|
|
21
|
+
interface ArriRoute<TPath extends string> {
|
|
22
|
+
path: TPath;
|
|
23
|
+
method: HttpMethod | HttpMethod[];
|
|
24
|
+
handler: (event: RouteEvent<TPath>) => any;
|
|
25
|
+
postHandler?: (event: RouteEvent<TPath>) => any;
|
|
41
26
|
}
|
|
42
|
-
|
|
27
|
+
type RouteOptions = Pick<ArriOptions, "onAfterResponse" | "onBeforeResponse" | "onError" | "onRequest"> & {
|
|
28
|
+
middleware: Middleware[];
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
interface ArriProcedure<TParams extends AObjectSchema | undefined, TResponse extends AObjectSchema | undefined> {
|
|
43
32
|
description?: string;
|
|
44
33
|
method?: HttpMethod;
|
|
45
34
|
params: TParams;
|
|
46
35
|
response: TResponse;
|
|
47
|
-
handler: ArriProcedureHandler<TParams extends
|
|
48
|
-
postHandler?: ArriProcedurePostHandler<TParams extends
|
|
36
|
+
handler: ArriProcedureHandler<TParams extends AObjectSchema ? InferType<TParams> : undefined, TResponse extends AObjectSchema ? InferType<TResponse> : void>;
|
|
37
|
+
postHandler?: ArriProcedurePostHandler<TParams extends AObjectSchema ? InferType<TParams> : undefined, TResponse extends AObjectSchema ? InferType<TResponse> : undefined>;
|
|
38
|
+
}
|
|
39
|
+
interface ArriNamedProcedure<TParams extends AObjectSchema | undefined, TResponse extends AObjectSchema | undefined> extends ArriProcedure<TParams, TResponse> {
|
|
40
|
+
name: string;
|
|
49
41
|
}
|
|
50
42
|
type HandlerContext = Record<string, any>;
|
|
51
|
-
interface RpcHandlerContext<TParams = undefined> extends HandlerContext {
|
|
52
|
-
type: "procedure";
|
|
43
|
+
interface RpcHandlerContext<TParams = undefined> extends HandlerContext, Omit<H3EventContext, "params"> {
|
|
53
44
|
params: TParams;
|
|
54
45
|
}
|
|
55
46
|
interface RpcPostHandlerContext<TParams = undefined, TResponse = undefined> extends RpcHandlerContext<TParams> {
|
|
@@ -58,42 +49,54 @@ interface RpcPostHandlerContext<TParams = undefined, TResponse = undefined> exte
|
|
|
58
49
|
type ArriProcedureHandler<TParams, TResponse> = (context: RpcHandlerContext<TParams>, event: H3Event) => TResponse | Promise<TResponse>;
|
|
59
50
|
type ArriProcedurePostHandler<TParams, TResponse> = (context: RpcPostHandlerContext<TParams, TResponse>, event: H3Event) => any;
|
|
60
51
|
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>):
|
|
52
|
+
declare function defineRpc<TParams extends AObjectSchema | undefined = undefined, TResponse extends AObjectSchema | undefined | never = undefined>(config: ArriProcedure<TParams, TResponse>): ArriProcedure<TParams, TResponse>;
|
|
53
|
+
declare function createRpcDefinition(rpcName: string, httpPath: string, procedure: ArriProcedure<any, any>): RpcDefinition;
|
|
63
54
|
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
|
-
|
|
55
|
+
declare function getRpcParamName(rpcName: string, procedure: ArriProcedure<any, any>): string | undefined;
|
|
56
|
+
declare function getRpcResponseName(rpcName: string, procedure: ArriProcedure<any, any>): string | undefined;
|
|
57
|
+
declare function registerRpc(router: Router, path: string, procedure: ArriProcedure<any, any>, opts: RouteOptions): void;
|
|
58
|
+
|
|
59
|
+
interface ArriRouterBase {
|
|
60
|
+
rpc: <TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: ArriNamedProcedure<TParams, TResponse>) => void;
|
|
61
|
+
route: <TPath extends string>(route: ArriRoute<TPath>) => void;
|
|
62
|
+
}
|
|
63
|
+
declare class ArriRouter implements ArriRouterBase {
|
|
64
|
+
private readonly procedures;
|
|
65
|
+
private readonly routes;
|
|
66
|
+
rpc<TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: ArriNamedProcedure<TParams, TResponse>): void;
|
|
67
|
+
route<TPath extends string>(route: ArriRoute<TPath>): void;
|
|
68
|
+
getProcedures(): ArriNamedProcedure<any, any>[];
|
|
69
|
+
getRoutes(): ArriRoute<any>[];
|
|
70
|
+
}
|
|
68
71
|
|
|
69
72
|
declare const DEV_ENDPOINT_ROOT = "/__arri_dev__";
|
|
70
|
-
declare const DEV_DEFINITION_ENDPOINT = "/__arri_dev__/
|
|
71
|
-
declare class
|
|
73
|
+
declare const DEV_DEFINITION_ENDPOINT = "/__arri_dev__/__definition";
|
|
74
|
+
declare class ArriApp implements ArriRouterBase {
|
|
72
75
|
__isArri__: boolean;
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
readonly h3App: App;
|
|
77
|
+
readonly h3Router: Router;
|
|
75
78
|
private readonly rpcDefinitionPath;
|
|
76
79
|
private readonly rpcRoutePrefix;
|
|
77
|
-
appInfo:
|
|
80
|
+
appInfo: AppDefinition["info"];
|
|
78
81
|
private procedures;
|
|
79
82
|
private models;
|
|
80
83
|
private readonly middlewares;
|
|
84
|
+
private readonly onRequest;
|
|
81
85
|
private readonly onAfterResponse;
|
|
82
86
|
private readonly onBeforeResponse;
|
|
83
87
|
private readonly onError;
|
|
84
88
|
constructor(opts?: ArriOptions);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
getAppDefinition():
|
|
89
|
-
getH3Instance(): App;
|
|
89
|
+
use(input: Middleware | ArriRouter): void;
|
|
90
|
+
rpc<TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: ArriNamedProcedure<TParams, TResponse>): void;
|
|
91
|
+
route<TPath extends string>(route: ArriRoute<TPath>): void;
|
|
92
|
+
getAppDefinition(): AppDefinition;
|
|
90
93
|
}
|
|
91
94
|
interface ArriOptions {
|
|
92
95
|
debug?: boolean;
|
|
93
96
|
/**
|
|
94
97
|
* Metadata to display in the __definition.json file
|
|
95
98
|
*/
|
|
96
|
-
appInfo?:
|
|
99
|
+
appInfo?: AppDefinition["info"];
|
|
97
100
|
rpcRoutePrefix?: string;
|
|
98
101
|
/**
|
|
99
102
|
* Defaults to /__definitions
|
|
@@ -101,24 +104,24 @@ interface ArriOptions {
|
|
|
101
104
|
*/
|
|
102
105
|
rpcDefinitionPath?: string;
|
|
103
106
|
onRequest?: (event: H3Event) => void | Promise<void>;
|
|
104
|
-
onAfterResponse?: (
|
|
105
|
-
onBeforeResponse?: (
|
|
106
|
-
onError?: (error: H3Error,
|
|
107
|
+
onAfterResponse?: (event: H3Event) => void | Promise<void>;
|
|
108
|
+
onBeforeResponse?: (event: H3Event) => void | Promise<void>;
|
|
109
|
+
onError?: (error: H3Error, event: H3Event) => void | Promise<void>;
|
|
107
110
|
}
|
|
108
111
|
|
|
109
|
-
declare const ErrorResponse:
|
|
110
|
-
statusCode:
|
|
111
|
-
statusMessage:
|
|
112
|
-
stack:
|
|
113
|
-
data:
|
|
114
|
-
}>;
|
|
115
|
-
type ErrorResponse =
|
|
112
|
+
declare const ErrorResponse: arri_validate.AObjectSchema<{
|
|
113
|
+
statusCode: number;
|
|
114
|
+
statusMessage: string;
|
|
115
|
+
stack: any[];
|
|
116
|
+
data: any;
|
|
117
|
+
}, false>;
|
|
118
|
+
type ErrorResponse = a.infer<typeof ErrorResponse>;
|
|
116
119
|
declare function defineError(statusCode: StatusCode, input?: Partial<Omit<ErrorResponse, "statusCode" | "stack">> & {
|
|
117
120
|
stack?: string;
|
|
118
121
|
}): H3Error;
|
|
119
|
-
declare function errorResponseFromValidationErrors(errors:
|
|
122
|
+
declare function errorResponseFromValidationErrors(errors: ValidationError["errors"], prefixText?: string): H3Error;
|
|
120
123
|
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,
|
|
124
|
+
declare function handleH3Error(err: unknown, event: H3Event, onError: ArriOptions["onError"]): Promise<void>;
|
|
122
125
|
|
|
123
126
|
interface ArriConfig {
|
|
124
127
|
port: number;
|
|
@@ -134,8 +137,10 @@ interface ArriConfig {
|
|
|
134
137
|
buildDir?: string;
|
|
135
138
|
esbuild?: Omit<BuildOptions, "outfile" | "outdir" | "entryNames" | "entryPoints">;
|
|
136
139
|
}
|
|
140
|
+
declare function isArriConfig(input: unknown): input is ArriConfig;
|
|
141
|
+
declare function isResolvedArriConfig(input: unknown): input is ResolvedArriConfig;
|
|
137
142
|
type ResolvedArriConfig = Required<ArriConfig>;
|
|
138
143
|
declare const defaultConfig: Required<ArriConfig>;
|
|
139
144
|
declare function defineConfig(config: ArriConfig): ResolvedArriConfig;
|
|
140
145
|
|
|
141
|
-
export {
|
|
146
|
+
export { ArriApp, type ArriConfig, type ArriNamedProcedure, type ArriOptions, type ArriProcedure, type ArriProcedureHandler, type ArriProcedurePostHandler, ArriRouter, type ArriRouterBase, DEV_DEFINITION_ENDPOINT, DEV_ENDPOINT_ROOT, ErrorResponse, type ExtractParam$1 as ExtractParam, type ExtractParams$1 as ExtractParams, type HandlerContext, type Middleware, type ResolvedArriConfig, type RpcHandlerContext, type RpcPostHandlerContext, type StatusCode, createRpcDefinition, defaultConfig, defineConfig, defineError, defineMiddleware, defineRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, isArriConfig, isResolvedArriConfig, isRpc, registerRpc };
|