arri 0.0.1 → 0.0.4

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.
@@ -0,0 +1,160 @@
1
+ import * as _sinclair_typebox from '@sinclair/typebox';
2
+ import { TObject, Static, TVoid, TSchema } from '@sinclair/typebox';
3
+ import { H3Event, Router, App, AppOptions, H3Error } from 'h3';
4
+ import { ValueError } from '@sinclair/typebox/errors';
5
+
6
+ interface ProcedureDefinition {
7
+ path: string;
8
+ description?: string;
9
+ method: HttpMethod;
10
+ params: string | undefined;
11
+ response: string | undefined;
12
+ }
13
+ interface ApplicationDefinition {
14
+ schemaVersion: "0.0.1";
15
+ description: string;
16
+ procedures: Record<string, ProcedureDefinition>;
17
+ models: Record<string, JsonSchemaObject>;
18
+ errors: Omit<TObject, symbol>;
19
+ }
20
+ declare const JsonSchemaScalarTypeValues: readonly ["integer", "number", "bigint", "string", "boolean", "Date"];
21
+ declare const JsonSchemaNullTypeValues: readonly ["null", "undefined"];
22
+ type JsonSchemaType = JsonSchemaScalarType | JsonSchemaNullType | JsonSchemaComplexType;
23
+ interface JsonSchemaScalarType {
24
+ title?: string;
25
+ description?: string;
26
+ type: (typeof JsonSchemaScalarTypeValues)[number];
27
+ }
28
+ interface JsonSchemaNullType {
29
+ type: (typeof JsonSchemaNullTypeValues)[number];
30
+ }
31
+ type JsonSchemaComplexType = JsonSchemaObject | JsonSchemaArray;
32
+ interface JsonSchemaObject {
33
+ $id?: string;
34
+ title?: string;
35
+ description?: string;
36
+ type: "object";
37
+ properties: Record<string, JsonSchemaType>;
38
+ required?: string[];
39
+ }
40
+ interface JsonSchemaArray {
41
+ $id?: string;
42
+ title?: string;
43
+ description?: string;
44
+ type: "array";
45
+ items: JsonSchemaType;
46
+ }
47
+
48
+ interface ArriProcedureBase {
49
+ method: HttpMethod;
50
+ params?: any;
51
+ response?: any;
52
+ handler: (context: any) => any;
53
+ postHandler?: (context: any) => any;
54
+ }
55
+ interface ArriProcedure<TParams extends TObject | undefined, TResponse extends TObject | undefined, TFinalResponse extends TResponse extends TObject ? Static<TResponse> : Static<TVoid>> {
56
+ description?: string;
57
+ method?: HttpMethod;
58
+ params: TParams;
59
+ response: TResponse;
60
+ handler: ArriProcedureHandler<TParams extends TObject ? Static<TParams> : undefined, TFinalResponse>;
61
+ postHandler?: ArriProcedurePostHandler<TParams extends TObject ? Static<TParams> : undefined, TFinalResponse>;
62
+ }
63
+ interface HandlerContext {
64
+ [key: string]: any;
65
+ event: H3Event;
66
+ }
67
+ interface RpcHandlerContext<TParams = undefined> extends HandlerContext {
68
+ params: TParams;
69
+ }
70
+ interface RpcPostHandlerContext<TParams = undefined, TResponse = undefined> extends RpcHandlerContext<TParams> {
71
+ response: TResponse;
72
+ }
73
+ type ArriProcedureHandler<TParams, TResponse> = (context: RpcHandlerContext<TParams>) => TResponse | Promise<TResponse>;
74
+ type ArriProcedurePostHandler<TParams, TResponse> = (event: RpcPostHandlerContext<TParams, TResponse>) => any;
75
+ declare function isRpc(input: any): input is ArriProcedure<any, any, any>;
76
+ declare function defineRpc<TParams extends TObject | undefined = undefined, TResponse extends TObject | undefined | never = undefined, TFinalResponse extends TResponse extends TObject ? Static<TObject> : Static<TVoid> = any>(config: ArriProcedure<TParams, TResponse, TFinalResponse>): ArriProcedure<TParams, TResponse, TFinalResponse>;
77
+ declare function createRpcDefinition(rpcName: string, httpPath: string, procedure: ArriProcedure<any, any, any>): ProcedureDefinition;
78
+ declare function getRpcPath(rpcName: string, prefix?: string): string;
79
+ declare function getRpcParamName(rpcName: string, procedure: ArriProcedure<any, any, any>): string | null;
80
+ declare function getRpcParamDefinition(rpcName: string, procedure: ArriProcedure<any, any, any>): ProcedureDefinition["params"];
81
+ declare function getRpcResponseName(rpcName: string, procedure: ArriProcedure<any, any, any>): string | null;
82
+ declare function registerRpc(router: Router, path: string, procedure: ArriProcedure<any, any, any>, middleware: Middleware[]): void;
83
+
84
+ interface ArriRoute<TPath extends string, TMethod extends HttpMethod, TQuery extends TObject | undefined = undefined, TBody extends TSchema | undefined = undefined, TResponse extends TSchema | undefined = undefined, TFallbackResponse = any> {
85
+ path: TPath;
86
+ method: TMethod;
87
+ query?: TQuery;
88
+ body?: TBody;
89
+ response?: TResponse;
90
+ handler: ArriRouteHandler<TPath, TQuery extends TObject ? Static<TQuery> : undefined, TBody extends TObject ? Static<TObject> : undefined, TResponse extends TSchema ? Static<TResponse> : TFallbackResponse>;
91
+ postHandler?: ArriRoutePostHandler<TPath, TQuery extends TObject ? Static<TQuery> : undefined, TBody extends TObject ? Static<TObject> : undefined, TResponse extends TSchema ? Static<TResponse> : TFallbackResponse>;
92
+ }
93
+ 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>;
94
+ type Middleware = (context: HandlerContext) => void | Promise<void>;
95
+ declare const defineMiddleware: (middleware: Middleware) => Middleware;
96
+ type ExtractParam<Path, NextPart> = Path extends `:${infer Param}` ? Record<Param, string> & NextPart : NextPart;
97
+ type ExtractParams<Path> = Path extends `${infer Segment}/${infer Rest}` ? ExtractParam<Segment, ExtractParams<Rest>> : ExtractParam<Path, {}>;
98
+ type ArriRouteHandler<TPath extends string, TQuery = undefined, TBody = undefined, TResponse = any> = (context: RouteHandlerContext<ExtractParams<TPath>, TQuery, TBody>) => TResponse extends undefined ? void | Promise<void> : TResponse | Promise<TResponse>;
99
+ interface RouteHandlerContext<TParams extends Record<string, string>, TQuery = undefined, TBody = undefined> extends HandlerContext {
100
+ params: TParams;
101
+ query: TQuery;
102
+ body: TBody;
103
+ }
104
+ interface RoutePostHandlerContext<TParams extends Record<string, string>, TQuery = undefined, TBody = undefined, TResponse = undefined> extends RouteHandlerContext<TParams, TQuery, TBody> {
105
+ response: TResponse;
106
+ }
107
+ type ArriRoutePostHandler<TPath extends string, TQuery = undefined, TBody = undefined, TResponse = undefined> = (context: RoutePostHandlerContext<ExtractParams<TPath>, TQuery, TBody, TResponse>) => any;
108
+ declare function registerRoute<TPath extends string>(router: Router, route: ArriRoute<TPath, HttpMethod, any, any, any>, middleware: Middleware[], prefix?: string): void;
109
+
110
+ interface ArriServerOptions extends AppOptions {
111
+ rpcRoutePrefix?: string;
112
+ /**
113
+ * Defaults to /__definitions
114
+ * This parameters also takes the rpcRoutePrefix option into account
115
+ */
116
+ rpcDefinitionPath?: string;
117
+ appDescription?: string;
118
+ }
119
+ declare class ArriServer {
120
+ app: App;
121
+ router: Router;
122
+ rpcRoutePrefix: string;
123
+ rpcDefinitionPath: string;
124
+ procedures: Record<string, ProcedureDefinition>;
125
+ models: Record<string, TObject>;
126
+ middlewares: Middleware[];
127
+ appDescription: string;
128
+ constructor(opts?: ArriServerOptions);
129
+ registerMiddleware(middleware: Middleware): void;
130
+ /**
131
+ * Statically register routes to the server router
132
+ * Routes will not be served until this is done
133
+ */
134
+ initializeRoutes(): void;
135
+ registerRpc<TParams extends TObject | undefined, TResponse extends TObject | undefined, TFinalResponse extends TResponse extends TObject ? Static<TResponse> : Static<TVoid>>(name: string, procedure: ArriProcedure<TParams, TResponse, TFinalResponse>): void;
136
+ registerRoute<TPath extends string, TMethod extends HttpMethod = HttpMethod, TQuery extends TObject | undefined = undefined, TBody extends TSchema | undefined = undefined, TResponse extends TSchema | undefined = undefined, TFallbackResponse = any>(route: ArriRoute<TPath, TMethod, TQuery, TBody, TResponse, TFallbackResponse>): void;
137
+ getAppDefinition(): ApplicationDefinition;
138
+ }
139
+ interface ArriService {
140
+ id: string;
141
+ procedures: Record<string, any>;
142
+ }
143
+ declare const HttpMethodValues: readonly ["get", "post", "put", "patch", "delete", "head"];
144
+ type HttpMethod = (typeof HttpMethodValues)[number];
145
+ declare const isHttpMethod: (input: any) => input is "get" | "post" | "put" | "patch" | "delete" | "head";
146
+
147
+ declare const ErrorResponse: _sinclair_typebox.TObject<{
148
+ statusCode: _sinclair_typebox.TInteger;
149
+ statusMessage: _sinclair_typebox.TString;
150
+ stack: _sinclair_typebox.TArray<_sinclair_typebox.TAny>;
151
+ data: _sinclair_typebox.TOptional<_sinclair_typebox.TObject<{}>>;
152
+ }>;
153
+ type ErrorResponse = Static<typeof ErrorResponse>;
154
+ declare function defineError(statusCode: StatusCode, input?: Partial<Omit<ErrorResponse, "statusCode" | "stack">> & {
155
+ stack?: string;
156
+ }): H3Error;
157
+ declare function errorResponseFromValidationErrors(errors: ValueError[], prefixText?: string): H3Error;
158
+ 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;
159
+
160
+ export { type ArriProcedure, type ArriProcedureBase, type ArriProcedureHandler, type ArriProcedurePostHandler, type ArriRoute, type ArriRouteHandler, type ArriRoutePostHandler, ArriServer, type ArriService, ErrorResponse, type ExtractParam, type ExtractParams, type HandlerContext, type HttpMethod, HttpMethodValues, type Middleware, type RouteHandlerContext, type RoutePostHandlerContext, type RpcHandlerContext, type RpcPostHandlerContext, type StatusCode, createRpcDefinition, defineError, defineMiddleware, defineRoute, defineRpc, errorResponseFromValidationErrors, getRpcParamDefinition, getRpcParamName, getRpcPath, getRpcResponseName, isHttpMethod, isRpc, registerRoute, registerRpc };
@@ -0,0 +1,160 @@
1
+ import * as _sinclair_typebox from '@sinclair/typebox';
2
+ import { TObject, Static, TVoid, TSchema } from '@sinclair/typebox';
3
+ import { H3Event, Router, App, AppOptions, H3Error } from 'h3';
4
+ import { ValueError } from '@sinclair/typebox/errors';
5
+
6
+ interface ProcedureDefinition {
7
+ path: string;
8
+ description?: string;
9
+ method: HttpMethod;
10
+ params: string | undefined;
11
+ response: string | undefined;
12
+ }
13
+ interface ApplicationDefinition {
14
+ schemaVersion: "0.0.1";
15
+ description: string;
16
+ procedures: Record<string, ProcedureDefinition>;
17
+ models: Record<string, JsonSchemaObject>;
18
+ errors: Omit<TObject, symbol>;
19
+ }
20
+ declare const JsonSchemaScalarTypeValues: readonly ["integer", "number", "bigint", "string", "boolean", "Date"];
21
+ declare const JsonSchemaNullTypeValues: readonly ["null", "undefined"];
22
+ type JsonSchemaType = JsonSchemaScalarType | JsonSchemaNullType | JsonSchemaComplexType;
23
+ interface JsonSchemaScalarType {
24
+ title?: string;
25
+ description?: string;
26
+ type: (typeof JsonSchemaScalarTypeValues)[number];
27
+ }
28
+ interface JsonSchemaNullType {
29
+ type: (typeof JsonSchemaNullTypeValues)[number];
30
+ }
31
+ type JsonSchemaComplexType = JsonSchemaObject | JsonSchemaArray;
32
+ interface JsonSchemaObject {
33
+ $id?: string;
34
+ title?: string;
35
+ description?: string;
36
+ type: "object";
37
+ properties: Record<string, JsonSchemaType>;
38
+ required?: string[];
39
+ }
40
+ interface JsonSchemaArray {
41
+ $id?: string;
42
+ title?: string;
43
+ description?: string;
44
+ type: "array";
45
+ items: JsonSchemaType;
46
+ }
47
+
48
+ interface ArriProcedureBase {
49
+ method: HttpMethod;
50
+ params?: any;
51
+ response?: any;
52
+ handler: (context: any) => any;
53
+ postHandler?: (context: any) => any;
54
+ }
55
+ interface ArriProcedure<TParams extends TObject | undefined, TResponse extends TObject | undefined, TFinalResponse extends TResponse extends TObject ? Static<TResponse> : Static<TVoid>> {
56
+ description?: string;
57
+ method?: HttpMethod;
58
+ params: TParams;
59
+ response: TResponse;
60
+ handler: ArriProcedureHandler<TParams extends TObject ? Static<TParams> : undefined, TFinalResponse>;
61
+ postHandler?: ArriProcedurePostHandler<TParams extends TObject ? Static<TParams> : undefined, TFinalResponse>;
62
+ }
63
+ interface HandlerContext {
64
+ [key: string]: any;
65
+ event: H3Event;
66
+ }
67
+ interface RpcHandlerContext<TParams = undefined> extends HandlerContext {
68
+ params: TParams;
69
+ }
70
+ interface RpcPostHandlerContext<TParams = undefined, TResponse = undefined> extends RpcHandlerContext<TParams> {
71
+ response: TResponse;
72
+ }
73
+ type ArriProcedureHandler<TParams, TResponse> = (context: RpcHandlerContext<TParams>) => TResponse | Promise<TResponse>;
74
+ type ArriProcedurePostHandler<TParams, TResponse> = (event: RpcPostHandlerContext<TParams, TResponse>) => any;
75
+ declare function isRpc(input: any): input is ArriProcedure<any, any, any>;
76
+ declare function defineRpc<TParams extends TObject | undefined = undefined, TResponse extends TObject | undefined | never = undefined, TFinalResponse extends TResponse extends TObject ? Static<TObject> : Static<TVoid> = any>(config: ArriProcedure<TParams, TResponse, TFinalResponse>): ArriProcedure<TParams, TResponse, TFinalResponse>;
77
+ declare function createRpcDefinition(rpcName: string, httpPath: string, procedure: ArriProcedure<any, any, any>): ProcedureDefinition;
78
+ declare function getRpcPath(rpcName: string, prefix?: string): string;
79
+ declare function getRpcParamName(rpcName: string, procedure: ArriProcedure<any, any, any>): string | null;
80
+ declare function getRpcParamDefinition(rpcName: string, procedure: ArriProcedure<any, any, any>): ProcedureDefinition["params"];
81
+ declare function getRpcResponseName(rpcName: string, procedure: ArriProcedure<any, any, any>): string | null;
82
+ declare function registerRpc(router: Router, path: string, procedure: ArriProcedure<any, any, any>, middleware: Middleware[]): void;
83
+
84
+ interface ArriRoute<TPath extends string, TMethod extends HttpMethod, TQuery extends TObject | undefined = undefined, TBody extends TSchema | undefined = undefined, TResponse extends TSchema | undefined = undefined, TFallbackResponse = any> {
85
+ path: TPath;
86
+ method: TMethod;
87
+ query?: TQuery;
88
+ body?: TBody;
89
+ response?: TResponse;
90
+ handler: ArriRouteHandler<TPath, TQuery extends TObject ? Static<TQuery> : undefined, TBody extends TObject ? Static<TObject> : undefined, TResponse extends TSchema ? Static<TResponse> : TFallbackResponse>;
91
+ postHandler?: ArriRoutePostHandler<TPath, TQuery extends TObject ? Static<TQuery> : undefined, TBody extends TObject ? Static<TObject> : undefined, TResponse extends TSchema ? Static<TResponse> : TFallbackResponse>;
92
+ }
93
+ 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>;
94
+ type Middleware = (context: HandlerContext) => void | Promise<void>;
95
+ declare const defineMiddleware: (middleware: Middleware) => Middleware;
96
+ type ExtractParam<Path, NextPart> = Path extends `:${infer Param}` ? Record<Param, string> & NextPart : NextPart;
97
+ type ExtractParams<Path> = Path extends `${infer Segment}/${infer Rest}` ? ExtractParam<Segment, ExtractParams<Rest>> : ExtractParam<Path, {}>;
98
+ type ArriRouteHandler<TPath extends string, TQuery = undefined, TBody = undefined, TResponse = any> = (context: RouteHandlerContext<ExtractParams<TPath>, TQuery, TBody>) => TResponse extends undefined ? void | Promise<void> : TResponse | Promise<TResponse>;
99
+ interface RouteHandlerContext<TParams extends Record<string, string>, TQuery = undefined, TBody = undefined> extends HandlerContext {
100
+ params: TParams;
101
+ query: TQuery;
102
+ body: TBody;
103
+ }
104
+ interface RoutePostHandlerContext<TParams extends Record<string, string>, TQuery = undefined, TBody = undefined, TResponse = undefined> extends RouteHandlerContext<TParams, TQuery, TBody> {
105
+ response: TResponse;
106
+ }
107
+ type ArriRoutePostHandler<TPath extends string, TQuery = undefined, TBody = undefined, TResponse = undefined> = (context: RoutePostHandlerContext<ExtractParams<TPath>, TQuery, TBody, TResponse>) => any;
108
+ declare function registerRoute<TPath extends string>(router: Router, route: ArriRoute<TPath, HttpMethod, any, any, any>, middleware: Middleware[], prefix?: string): void;
109
+
110
+ interface ArriServerOptions extends AppOptions {
111
+ rpcRoutePrefix?: string;
112
+ /**
113
+ * Defaults to /__definitions
114
+ * This parameters also takes the rpcRoutePrefix option into account
115
+ */
116
+ rpcDefinitionPath?: string;
117
+ appDescription?: string;
118
+ }
119
+ declare class ArriServer {
120
+ app: App;
121
+ router: Router;
122
+ rpcRoutePrefix: string;
123
+ rpcDefinitionPath: string;
124
+ procedures: Record<string, ProcedureDefinition>;
125
+ models: Record<string, TObject>;
126
+ middlewares: Middleware[];
127
+ appDescription: string;
128
+ constructor(opts?: ArriServerOptions);
129
+ registerMiddleware(middleware: Middleware): void;
130
+ /**
131
+ * Statically register routes to the server router
132
+ * Routes will not be served until this is done
133
+ */
134
+ initializeRoutes(): void;
135
+ registerRpc<TParams extends TObject | undefined, TResponse extends TObject | undefined, TFinalResponse extends TResponse extends TObject ? Static<TResponse> : Static<TVoid>>(name: string, procedure: ArriProcedure<TParams, TResponse, TFinalResponse>): void;
136
+ registerRoute<TPath extends string, TMethod extends HttpMethod = HttpMethod, TQuery extends TObject | undefined = undefined, TBody extends TSchema | undefined = undefined, TResponse extends TSchema | undefined = undefined, TFallbackResponse = any>(route: ArriRoute<TPath, TMethod, TQuery, TBody, TResponse, TFallbackResponse>): void;
137
+ getAppDefinition(): ApplicationDefinition;
138
+ }
139
+ interface ArriService {
140
+ id: string;
141
+ procedures: Record<string, any>;
142
+ }
143
+ declare const HttpMethodValues: readonly ["get", "post", "put", "patch", "delete", "head"];
144
+ type HttpMethod = (typeof HttpMethodValues)[number];
145
+ declare const isHttpMethod: (input: any) => input is "get" | "post" | "put" | "patch" | "delete" | "head";
146
+
147
+ declare const ErrorResponse: _sinclair_typebox.TObject<{
148
+ statusCode: _sinclair_typebox.TInteger;
149
+ statusMessage: _sinclair_typebox.TString;
150
+ stack: _sinclair_typebox.TArray<_sinclair_typebox.TAny>;
151
+ data: _sinclair_typebox.TOptional<_sinclair_typebox.TObject<{}>>;
152
+ }>;
153
+ type ErrorResponse = Static<typeof ErrorResponse>;
154
+ declare function defineError(statusCode: StatusCode, input?: Partial<Omit<ErrorResponse, "statusCode" | "stack">> & {
155
+ stack?: string;
156
+ }): H3Error;
157
+ declare function errorResponseFromValidationErrors(errors: ValueError[], prefixText?: string): H3Error;
158
+ 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;
159
+
160
+ export { type ArriProcedure, type ArriProcedureBase, type ArriProcedureHandler, type ArriProcedurePostHandler, type ArriRoute, type ArriRouteHandler, type ArriRoutePostHandler, ArriServer, type ArriService, ErrorResponse, type ExtractParam, type ExtractParams, type HandlerContext, type HttpMethod, HttpMethodValues, type Middleware, type RouteHandlerContext, type RoutePostHandlerContext, type RpcHandlerContext, type RpcPostHandlerContext, type StatusCode, createRpcDefinition, defineError, defineMiddleware, defineRoute, defineRpc, errorResponseFromValidationErrors, getRpcParamDefinition, getRpcParamName, getRpcPath, getRpcResponseName, isHttpMethod, isRpc, registerRoute, registerRpc };
package/dist/index.d.ts CHANGED
@@ -1,39 +1,160 @@
1
- import { H3Error, H3Event, RouterMethod, App } from 'h3';
2
- import { ZodTypeAny, AnyZodObject } from 'zod';
1
+ import * as _sinclair_typebox from '@sinclair/typebox';
2
+ import { TObject, Static, TVoid, TSchema } from '@sinclair/typebox';
3
+ import { H3Event, Router, App, AppOptions, H3Error } from 'h3';
4
+ import { ValueError } from '@sinclair/typebox/errors';
3
5
 
4
- declare function isH3Error(input: unknown): input is H3Error;
5
- declare function defineError(statusCode: number, opts?: Partial<Omit<H3Error, "statusCode">>): H3Error;
6
+ interface ProcedureDefinition {
7
+ path: string;
8
+ description?: string;
9
+ method: HttpMethod;
10
+ params: string | undefined;
11
+ response: string | undefined;
12
+ }
13
+ interface ApplicationDefinition {
14
+ schemaVersion: "0.0.1";
15
+ description: string;
16
+ procedures: Record<string, ProcedureDefinition>;
17
+ models: Record<string, JsonSchemaObject>;
18
+ errors: Omit<TObject, symbol>;
19
+ }
20
+ declare const JsonSchemaScalarTypeValues: readonly ["integer", "number", "bigint", "string", "boolean", "Date"];
21
+ declare const JsonSchemaNullTypeValues: readonly ["null", "undefined"];
22
+ type JsonSchemaType = JsonSchemaScalarType | JsonSchemaNullType | JsonSchemaComplexType;
23
+ interface JsonSchemaScalarType {
24
+ title?: string;
25
+ description?: string;
26
+ type: (typeof JsonSchemaScalarTypeValues)[number];
27
+ }
28
+ interface JsonSchemaNullType {
29
+ type: (typeof JsonSchemaNullTypeValues)[number];
30
+ }
31
+ type JsonSchemaComplexType = JsonSchemaObject | JsonSchemaArray;
32
+ interface JsonSchemaObject {
33
+ $id?: string;
34
+ title?: string;
35
+ description?: string;
36
+ type: "object";
37
+ properties: Record<string, JsonSchemaType>;
38
+ required?: string[];
39
+ }
40
+ interface JsonSchemaArray {
41
+ $id?: string;
42
+ title?: string;
43
+ description?: string;
44
+ type: "array";
45
+ items: JsonSchemaType;
46
+ }
6
47
 
48
+ interface ArriProcedureBase {
49
+ method: HttpMethod;
50
+ params?: any;
51
+ response?: any;
52
+ handler: (context: any) => any;
53
+ postHandler?: (context: any) => any;
54
+ }
55
+ interface ArriProcedure<TParams extends TObject | undefined, TResponse extends TObject | undefined, TFinalResponse extends TResponse extends TObject ? Static<TResponse> : Static<TVoid>> {
56
+ description?: string;
57
+ method?: HttpMethod;
58
+ params: TParams;
59
+ response: TResponse;
60
+ handler: ArriProcedureHandler<TParams extends TObject ? Static<TParams> : undefined, TFinalResponse>;
61
+ postHandler?: ArriProcedurePostHandler<TParams extends TObject ? Static<TParams> : undefined, TFinalResponse>;
62
+ }
63
+ interface HandlerContext {
64
+ [key: string]: any;
65
+ event: H3Event;
66
+ }
67
+ interface RpcHandlerContext<TParams = undefined> extends HandlerContext {
68
+ params: TParams;
69
+ }
70
+ interface RpcPostHandlerContext<TParams = undefined, TResponse = undefined> extends RpcHandlerContext<TParams> {
71
+ response: TResponse;
72
+ }
73
+ type ArriProcedureHandler<TParams, TResponse> = (context: RpcHandlerContext<TParams>) => TResponse | Promise<TResponse>;
74
+ type ArriProcedurePostHandler<TParams, TResponse> = (event: RpcPostHandlerContext<TParams, TResponse>) => any;
75
+ declare function isRpc(input: any): input is ArriProcedure<any, any, any>;
76
+ declare function defineRpc<TParams extends TObject | undefined = undefined, TResponse extends TObject | undefined | never = undefined, TFinalResponse extends TResponse extends TObject ? Static<TObject> : Static<TVoid> = any>(config: ArriProcedure<TParams, TResponse, TFinalResponse>): ArriProcedure<TParams, TResponse, TFinalResponse>;
77
+ declare function createRpcDefinition(rpcName: string, httpPath: string, procedure: ArriProcedure<any, any, any>): ProcedureDefinition;
78
+ declare function getRpcPath(rpcName: string, prefix?: string): string;
79
+ declare function getRpcParamName(rpcName: string, procedure: ArriProcedure<any, any, any>): string | null;
80
+ declare function getRpcParamDefinition(rpcName: string, procedure: ArriProcedure<any, any, any>): ProcedureDefinition["params"];
81
+ declare function getRpcResponseName(rpcName: string, procedure: ArriProcedure<any, any, any>): string | null;
82
+ declare function registerRpc(router: Router, path: string, procedure: ArriProcedure<any, any, any>, middleware: Middleware[]): void;
83
+
84
+ interface ArriRoute<TPath extends string, TMethod extends HttpMethod, TQuery extends TObject | undefined = undefined, TBody extends TSchema | undefined = undefined, TResponse extends TSchema | undefined = undefined, TFallbackResponse = any> {
85
+ path: TPath;
86
+ method: TMethod;
87
+ query?: TQuery;
88
+ body?: TBody;
89
+ response?: TResponse;
90
+ handler: ArriRouteHandler<TPath, TQuery extends TObject ? Static<TQuery> : undefined, TBody extends TObject ? Static<TObject> : undefined, TResponse extends TSchema ? Static<TResponse> : TFallbackResponse>;
91
+ postHandler?: ArriRoutePostHandler<TPath, TQuery extends TObject ? Static<TQuery> : undefined, TBody extends TObject ? Static<TObject> : undefined, TResponse extends TSchema ? Static<TResponse> : TFallbackResponse>;
92
+ }
93
+ 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>;
94
+ type Middleware = (context: HandlerContext) => void | Promise<void>;
95
+ declare const defineMiddleware: (middleware: Middleware) => Middleware;
7
96
  type ExtractParam<Path, NextPart> = Path extends `:${infer Param}` ? Record<Param, string> & NextPart : NextPart;
8
97
  type ExtractParams<Path> = Path extends `${infer Segment}/${infer Rest}` ? ExtractParam<Segment, ExtractParams<Rest>> : ExtractParam<Path, {}>;
98
+ type ArriRouteHandler<TPath extends string, TQuery = undefined, TBody = undefined, TResponse = any> = (context: RouteHandlerContext<ExtractParams<TPath>, TQuery, TBody>) => TResponse extends undefined ? void | Promise<void> : TResponse | Promise<TResponse>;
99
+ interface RouteHandlerContext<TParams extends Record<string, string>, TQuery = undefined, TBody = undefined> extends HandlerContext {
100
+ params: TParams;
101
+ query: TQuery;
102
+ body: TBody;
103
+ }
104
+ interface RoutePostHandlerContext<TParams extends Record<string, string>, TQuery = undefined, TBody = undefined, TResponse = undefined> extends RouteHandlerContext<TParams, TQuery, TBody> {
105
+ response: TResponse;
106
+ }
107
+ type ArriRoutePostHandler<TPath extends string, TQuery = undefined, TBody = undefined, TResponse = undefined> = (context: RoutePostHandlerContext<ExtractParams<TPath>, TQuery, TBody, TResponse>) => any;
108
+ declare function registerRoute<TPath extends string>(router: Router, route: ArriRoute<TPath, HttpMethod, any, any, any>, middleware: Middleware[], prefix?: string): void;
109
+
110
+ interface ArriServerOptions extends AppOptions {
111
+ rpcRoutePrefix?: string;
112
+ /**
113
+ * Defaults to /__definitions
114
+ * This parameters also takes the rpcRoutePrefix option into account
115
+ */
116
+ rpcDefinitionPath?: string;
117
+ appDescription?: string;
118
+ }
119
+ declare class ArriServer {
120
+ app: App;
121
+ router: Router;
122
+ rpcRoutePrefix: string;
123
+ rpcDefinitionPath: string;
124
+ procedures: Record<string, ProcedureDefinition>;
125
+ models: Record<string, TObject>;
126
+ middlewares: Middleware[];
127
+ appDescription: string;
128
+ constructor(opts?: ArriServerOptions);
129
+ registerMiddleware(middleware: Middleware): void;
130
+ /**
131
+ * Statically register routes to the server router
132
+ * Routes will not be served until this is done
133
+ */
134
+ initializeRoutes(): void;
135
+ registerRpc<TParams extends TObject | undefined, TResponse extends TObject | undefined, TFinalResponse extends TResponse extends TObject ? Static<TResponse> : Static<TVoid>>(name: string, procedure: ArriProcedure<TParams, TResponse, TFinalResponse>): void;
136
+ registerRoute<TPath extends string, TMethod extends HttpMethod = HttpMethod, TQuery extends TObject | undefined = undefined, TBody extends TSchema | undefined = undefined, TResponse extends TSchema | undefined = undefined, TFallbackResponse = any>(route: ArriRoute<TPath, TMethod, TQuery, TBody, TResponse, TFallbackResponse>): void;
137
+ getAppDefinition(): ApplicationDefinition;
138
+ }
139
+ interface ArriService {
140
+ id: string;
141
+ procedures: Record<string, any>;
142
+ }
143
+ declare const HttpMethodValues: readonly ["get", "post", "put", "patch", "delete", "head"];
144
+ type HttpMethod = (typeof HttpMethodValues)[number];
145
+ declare const isHttpMethod: (input: any) => input is "get" | "post" | "put" | "patch" | "delete" | "head";
9
146
 
10
- interface RouteEventContext<Params extends Record<string, string> = any, Body = any, Query = any, Response = any> {
11
- params?: Params;
12
- body?: Body;
13
- query?: Query;
14
- response?: Response;
15
- }
16
- interface RouteEvent<Context extends RouteEventContext> extends H3Event {
17
- context: Context;
18
- }
19
- type ArriRouteHandler<Params extends Record<string, string>, Body, Query, Response> = (event: RouteEvent<RouteEventContext<Params, Body, Query>>) => Response | Promise<Response>;
20
- interface ArriRoute<Path extends string = "", Method extends RouterMethod = "get", Body extends undefined | ZodTypeAny = undefined, Query extends undefined | AnyZodObject = undefined, Response = any> {
21
- id?: string;
22
- path: Path;
23
- method: Method;
24
- schema?: {
25
- body?: Body;
26
- query?: Query;
27
- };
28
- handler: ArriRouteHandler<ExtractParams<Path>, Body extends ZodTypeAny ? Body["_type"] : undefined, Query extends AnyZodObject ? Query["_type"] : undefined, Response>;
29
- postHandler?: (event: RouteEvent<RouteEventContext<ExtractParams<Path>, Body extends ZodTypeAny ? Body["_type"] : undefined, Query extends AnyZodObject ? Query["_type"] : undefined, Response>>) => any;
30
- }
31
- declare const defineRoute: <Path extends string, Method extends "get" | "head" | "patch" | "post" | "put" | "delete" | "connect" | "options" | "trace", Body_1 extends ZodTypeAny | undefined, Query extends AnyZodObject | undefined, Response_1 = any>(route: ArriRoute<Path, Method, Body_1, Query, Response_1>) => ArriRoute<Path, Method, Body_1, Query, Response_1>;
32
- type ApiRouteMiddleware = (event: RouteEvent<RouteEventContext<Record<string, string>, any, any, undefined>>) => void | Promise<void>;
33
- declare const defineMiddleware: (middleware: ApiRouteMiddleware) => ApiRouteMiddleware;
34
- declare function handleRoute(event: H3Event, route: ArriRoute, middlewares: ApiRouteMiddleware[]): Promise<void>;
35
- declare function registerArriRoutes(app: App, routeMap: any): void;
36
- declare function registerArriRoute(app: App, route: ArriRoute): void;
37
- declare const methodAllowsBody: (method: RouterMethod) => boolean;
147
+ declare const ErrorResponse: _sinclair_typebox.TObject<{
148
+ statusCode: _sinclair_typebox.TInteger;
149
+ statusMessage: _sinclair_typebox.TString;
150
+ stack: _sinclair_typebox.TArray<_sinclair_typebox.TAny>;
151
+ data: _sinclair_typebox.TOptional<_sinclair_typebox.TObject<{}>>;
152
+ }>;
153
+ type ErrorResponse = Static<typeof ErrorResponse>;
154
+ declare function defineError(statusCode: StatusCode, input?: Partial<Omit<ErrorResponse, "statusCode" | "stack">> & {
155
+ stack?: string;
156
+ }): H3Error;
157
+ declare function errorResponseFromValidationErrors(errors: ValueError[], prefixText?: string): H3Error;
158
+ 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;
38
159
 
39
- export { ApiRouteMiddleware, ArriRoute, ArriRouteHandler, ExtractParam, ExtractParams, RouteEvent, RouteEventContext, defineError, defineMiddleware, defineRoute, handleRoute, isH3Error, methodAllowsBody, registerArriRoute, registerArriRoutes };
160
+ export { type ArriProcedure, type ArriProcedureBase, type ArriProcedureHandler, type ArriProcedurePostHandler, type ArriRoute, type ArriRouteHandler, type ArriRoutePostHandler, ArriServer, type ArriService, ErrorResponse, type ExtractParam, type ExtractParams, type HandlerContext, type HttpMethod, HttpMethodValues, type Middleware, type RouteHandlerContext, type RoutePostHandlerContext, type RpcHandlerContext, type RpcPostHandlerContext, type StatusCode, createRpcDefinition, defineError, defineMiddleware, defineRoute, defineRpc, errorResponseFromValidationErrors, getRpcParamDefinition, getRpcParamName, getRpcPath, getRpcResponseName, isHttpMethod, isRpc, registerRoute, registerRpc };