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/dist/index.d.cts CHANGED
@@ -1,55 +1,46 @@
1
- import * as _sinclair_typebox from '@sinclair/typebox';
2
- import { TObject, TSchema, Static } from '@sinclair/typebox';
3
- import { H3Event, Router, App, H3Error } from 'h3';
4
- import { H as HttpMethod, P as ProcedureDef, A as ApplicationDef, a as ClientGenerator } from './shared/arri.4536bc49.cjs';
5
- import { ValueError } from '@sinclair/typebox/errors';
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
- 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> {
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
- type ArriRouteHandler<TPath extends string, TQuery = undefined, TBody = undefined, TResponse = any> = (context: RouteHandlerContext<ExtractParams<TPath>, TQuery, TBody>, event: H3Event) => TResponse extends undefined ? void | Promise<void> : TResponse | Promise<TResponse>;
23
- interface RouteHandlerContext<TParams extends Record<string, string>, TQuery = undefined, TBody = undefined> extends HandlerContext {
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 RoutePostHandlerContext<TParams extends Record<string, string>, TQuery = undefined, TBody = undefined, TResponse = undefined> extends RouteHandlerContext<TParams, TQuery, TBody> {
30
- response: TResponse;
18
+ interface RouteEvent<TPath extends string> extends H3Event {
19
+ context: RouteEventContext<TPath>;
31
20
  }
32
- type ArriRoutePostHandler<TPath extends string, TQuery = undefined, TBody = undefined, TResponse = undefined> = (context: RoutePostHandlerContext<ExtractParams<TPath>, TQuery, TBody, TResponse>, event: H3Event) => any;
33
- declare function registerRoute<TPath extends string>(router: Router, route: ArriRoute<TPath, HttpMethod, any, any, any>, middleware: Middleware[], prefix?: string, opts?: ArriOptions): void;
34
-
35
- interface ArriProcedureBase {
36
- method: HttpMethod;
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
- interface ArriProcedure<TParams extends TObject | undefined, TResponse extends TObject | undefined> {
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 TObject ? Static<TParams> : undefined, TResponse extends TObject ? Static<TResponse> : void>;
48
- postHandler?: ArriProcedurePostHandler<TParams extends TObject ? Static<TParams> : undefined, TResponse extends TObject ? Static<TResponse> : undefined>;
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 TObject | undefined = undefined, TResponse extends TObject | undefined | never = undefined>(config: ArriProcedure<TParams, TResponse>): ArriProcedure<TParams, TResponse>;
62
- declare function createRpcDefinition(rpcName: string, httpPath: string, procedure: ArriProcedure<any, any>): ProcedureDef;
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 | null;
65
- declare function getRpcParamDefinition(rpcName: string, procedure: ArriProcedure<any, any>): ProcedureDef["params"];
66
- declare function getRpcResponseName(rpcName: string, procedure: ArriProcedure<any, any>): string | null;
67
- declare function registerRpc(router: Router, path: string, procedure: ArriProcedure<any, any>, middleware: Middleware[], opts: ArriOptions): void;
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__/definition";
71
- declare class Arri {
73
+ declare const DEV_DEFINITION_ENDPOINT = "/__arri_dev__/__definition";
74
+ declare class ArriApp implements ArriRouterBase {
72
75
  __isArri__: boolean;
73
- private readonly h3App;
74
- private readonly h3Router;
76
+ readonly h3App: App;
77
+ readonly h3Router: Router;
75
78
  private readonly rpcDefinitionPath;
76
79
  private readonly rpcRoutePrefix;
77
- appInfo: ApplicationDef["info"];
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
- registerMiddleware(middleware: Middleware): void;
86
- registerRpc<TParams extends TObject | undefined, TResponse extends TObject | undefined>(name: string, procedure: ArriProcedure<TParams, TResponse>): void;
87
- 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;
88
- getAppDefinition(): ApplicationDef;
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?: ApplicationDef["info"];
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?: (context: RpcPostHandlerContext | RoutePostHandlerContext<any>, event: H3Event) => void | Promise<void>;
105
- onBeforeResponse?: (context: RpcPostHandlerContext | RoutePostHandlerContext<any>, event: H3Event) => void | Promise<void>;
106
- onError?: (error: H3Error, context: RpcHandlerContext | RouteHandlerContext<any>, event: H3Event) => void | Promise<void>;
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: _sinclair_typebox.TObject<{
110
- statusCode: _sinclair_typebox.TInteger;
111
- statusMessage: _sinclair_typebox.TString;
112
- stack: _sinclair_typebox.TArray<_sinclair_typebox.TAny>;
113
- data: _sinclair_typebox.TOptional<_sinclair_typebox.TObject<{}>>;
114
- }>;
115
- type ErrorResponse = Static<typeof 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: ValueError[], prefixText?: string): H3Error;
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, context: RpcHandlerContext | RouteHandlerContext<any>, event: H3Event, onError: ArriOptions["onError"]): Promise<void>;
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 { Arri, type ArriConfig, type ArriOptions, type ArriProcedure, type ArriProcedureBase, type ArriProcedureHandler, type ArriProcedurePostHandler, type ArriRoute, type ArriRouteHandler, type ArriRoutePostHandler, DEV_DEFINITION_ENDPOINT, DEV_ENDPOINT_ROOT, ErrorResponse, type ExtractParam, type ExtractParams, type HandlerContext, type Middleware, type ResolvedArriConfig, type RouteHandlerContext, type RoutePostHandlerContext, type RpcHandlerContext, type RpcPostHandlerContext, type StatusCode, createRpcDefinition, defaultConfig, defineConfig, defineError, defineMiddleware, defineRoute, defineRpc, errorResponseFromValidationErrors, getRpcParamDefinition, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, isRpc, registerRoute, registerRpc };
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 * as _sinclair_typebox from '@sinclair/typebox';
2
- import { TObject, TSchema, Static } from '@sinclair/typebox';
3
- import { H3Event, Router, App, H3Error } from 'h3';
4
- import { H as HttpMethod, P as ProcedureDef, A as ApplicationDef, a as ClientGenerator } from './shared/arri.4536bc49.mjs';
5
- import { ValueError } from '@sinclair/typebox/errors';
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
- 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> {
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
- type ArriRouteHandler<TPath extends string, TQuery = undefined, TBody = undefined, TResponse = any> = (context: RouteHandlerContext<ExtractParams<TPath>, TQuery, TBody>, event: H3Event) => TResponse extends undefined ? void | Promise<void> : TResponse | Promise<TResponse>;
23
- interface RouteHandlerContext<TParams extends Record<string, string>, TQuery = undefined, TBody = undefined> extends HandlerContext {
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 RoutePostHandlerContext<TParams extends Record<string, string>, TQuery = undefined, TBody = undefined, TResponse = undefined> extends RouteHandlerContext<TParams, TQuery, TBody> {
30
- response: TResponse;
18
+ interface RouteEvent<TPath extends string> extends H3Event {
19
+ context: RouteEventContext<TPath>;
31
20
  }
32
- type ArriRoutePostHandler<TPath extends string, TQuery = undefined, TBody = undefined, TResponse = undefined> = (context: RoutePostHandlerContext<ExtractParams<TPath>, TQuery, TBody, TResponse>, event: H3Event) => any;
33
- declare function registerRoute<TPath extends string>(router: Router, route: ArriRoute<TPath, HttpMethod, any, any, any>, middleware: Middleware[], prefix?: string, opts?: ArriOptions): void;
34
-
35
- interface ArriProcedureBase {
36
- method: HttpMethod;
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
- interface ArriProcedure<TParams extends TObject | undefined, TResponse extends TObject | undefined> {
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 TObject ? Static<TParams> : undefined, TResponse extends TObject ? Static<TResponse> : void>;
48
- postHandler?: ArriProcedurePostHandler<TParams extends TObject ? Static<TParams> : undefined, TResponse extends TObject ? Static<TResponse> : undefined>;
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 TObject | undefined = undefined, TResponse extends TObject | undefined | never = undefined>(config: ArriProcedure<TParams, TResponse>): ArriProcedure<TParams, TResponse>;
62
- declare function createRpcDefinition(rpcName: string, httpPath: string, procedure: ArriProcedure<any, any>): ProcedureDef;
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 | null;
65
- declare function getRpcParamDefinition(rpcName: string, procedure: ArriProcedure<any, any>): ProcedureDef["params"];
66
- declare function getRpcResponseName(rpcName: string, procedure: ArriProcedure<any, any>): string | null;
67
- declare function registerRpc(router: Router, path: string, procedure: ArriProcedure<any, any>, middleware: Middleware[], opts: ArriOptions): void;
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__/definition";
71
- declare class Arri {
73
+ declare const DEV_DEFINITION_ENDPOINT = "/__arri_dev__/__definition";
74
+ declare class ArriApp implements ArriRouterBase {
72
75
  __isArri__: boolean;
73
- private readonly h3App;
74
- private readonly h3Router;
76
+ readonly h3App: App;
77
+ readonly h3Router: Router;
75
78
  private readonly rpcDefinitionPath;
76
79
  private readonly rpcRoutePrefix;
77
- appInfo: ApplicationDef["info"];
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
- registerMiddleware(middleware: Middleware): void;
86
- registerRpc<TParams extends TObject | undefined, TResponse extends TObject | undefined>(name: string, procedure: ArriProcedure<TParams, TResponse>): void;
87
- 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;
88
- getAppDefinition(): ApplicationDef;
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?: ApplicationDef["info"];
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?: (context: RpcPostHandlerContext | RoutePostHandlerContext<any>, event: H3Event) => void | Promise<void>;
105
- onBeforeResponse?: (context: RpcPostHandlerContext | RoutePostHandlerContext<any>, event: H3Event) => void | Promise<void>;
106
- onError?: (error: H3Error, context: RpcHandlerContext | RouteHandlerContext<any>, event: H3Event) => void | Promise<void>;
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: _sinclair_typebox.TObject<{
110
- statusCode: _sinclair_typebox.TInteger;
111
- statusMessage: _sinclair_typebox.TString;
112
- stack: _sinclair_typebox.TArray<_sinclair_typebox.TAny>;
113
- data: _sinclair_typebox.TOptional<_sinclair_typebox.TObject<{}>>;
114
- }>;
115
- type ErrorResponse = Static<typeof 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: ValueError[], prefixText?: string): H3Error;
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, context: RpcHandlerContext | RouteHandlerContext<any>, event: H3Event, onError: ArriOptions["onError"]): Promise<void>;
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 { Arri, type ArriConfig, type ArriOptions, type ArriProcedure, type ArriProcedureBase, type ArriProcedureHandler, type ArriProcedurePostHandler, type ArriRoute, type ArriRouteHandler, type ArriRoutePostHandler, DEV_DEFINITION_ENDPOINT, DEV_ENDPOINT_ROOT, ErrorResponse, type ExtractParam, type ExtractParams, type HandlerContext, type Middleware, type ResolvedArriConfig, type RouteHandlerContext, type RoutePostHandlerContext, type RpcHandlerContext, type RpcPostHandlerContext, type StatusCode, createRpcDefinition, defaultConfig, defineConfig, defineError, defineMiddleware, defineRoute, defineRpc, errorResponseFromValidationErrors, getRpcParamDefinition, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, isRpc, registerRoute, registerRpc };
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 };