@arrirpc/server 0.55.0 → 0.57.0

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,9 +1,43 @@
1
1
  import { HttpMethod, WsRpcDefinition, RpcHttpMethod, HttpRpcDefinition, SchemaFormProperties, SchemaFormDiscriminator, SchemaFormValues, AppDefinition } from '@arrirpc/codegen-utils';
2
2
  import { AObjectSchema, a, ValidationError, ASchema, InferType, ValueError, CompiledValidator, ADiscriminatorSchema } from '@arrirpc/schema';
3
- import { StatusCode, H3Error, H3Event, H3EventContext, Router, EventStream, App } from 'h3';
3
+ import { H3Event, StatusCode, H3Error, Router, EventStream, App } from 'h3';
4
4
  export * from 'h3';
5
5
  import { Peer, WSError } from 'crossws';
6
6
 
7
+ interface MiddlewareEvent extends H3Event {
8
+ context: MiddlewareEventContext;
9
+ }
10
+ type Middleware = (event: MiddlewareEvent) => void | Promise<void>;
11
+ declare const defineMiddleware: (middleware: Middleware) => Middleware;
12
+ type ExtractParam<Path, NextPart> = Path extends `:${infer Param}` ? Record<Param, string> & NextPart : NextPart;
13
+ type ExtractParams<Path> = Path extends `${infer Segment}/${infer Rest}` ? ExtractParam<Segment, ExtractParams<Rest>> : ExtractParam<Path, {}>;
14
+
15
+ interface ArriEventContext extends Record<string, unknown> {
16
+ }
17
+ type RpcEventContext<TParams = undefined> = ArriEventContext & {
18
+ rpcName: string;
19
+ params: TParams;
20
+ };
21
+ type RpcPostEventContext<TParams = undefined, TResponse = undefined> = RpcEventContext<TParams> & {
22
+ response: TResponse;
23
+ };
24
+ type RouteEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> = ArriEventContext & {
25
+ params: ExtractParams<TPath>;
26
+ query: TQuery;
27
+ body: TBody;
28
+ };
29
+ type RoutePostEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any, TResponse = any> = RouteEventContext<TPath, TQuery, TBody> & {
30
+ response: TResponse;
31
+ };
32
+ type MiddlewareEventContext = ArriEventContext & {
33
+ rpcName?: string;
34
+ };
35
+ type RequestHookContext = ArriEventContext & {
36
+ rpcName?: string;
37
+ params?: Record<string, unknown>;
38
+ response?: unknown;
39
+ };
40
+
7
41
  declare class ArriServerError extends Error {
8
42
  code: number;
9
43
  data?: any;
@@ -25,34 +59,6 @@ declare function defineError(statusCode: StatusCode, input?: Partial<Omit<ArriSe
25
59
  declare function errorResponseFromValidationErrors(errors: ValidationError["errors"], prefixText?: string): H3Error;
26
60
  declare function handleH3Error(err: unknown, event: H3Event, onError: ArriOptions["onError"], debug: boolean): Promise<void>;
27
61
 
28
- type ArriEventContext = Record<string, any>;
29
- interface RpcEventContext<TParams = undefined> extends ArriEventContext, Omit<H3EventContext, "params"> {
30
- rpcName: string;
31
- params: TParams;
32
- }
33
- interface RpcPostEventContext<TParams = undefined, TResponse = undefined> extends RpcEventContext<TParams> {
34
- response: TResponse;
35
- }
36
- interface RouteEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> extends ArriEventContext, H3EventContext {
37
- params: ExtractParams<TPath>;
38
- query: TQuery;
39
- body: TBody;
40
- }
41
- interface RoutePostEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any, TResponse = any> extends RouteEventContext<TPath, TQuery, TBody> {
42
- response: TResponse;
43
- }
44
- interface MiddlewareEventContext extends ArriEventContext, H3EventContext {
45
- rpcName?: string;
46
- }
47
-
48
- interface MiddlewareEvent extends H3Event {
49
- context: MiddlewareEventContext;
50
- }
51
- type Middleware = (event: MiddlewareEvent) => void | Promise<void>;
52
- declare const defineMiddleware: (middleware: Middleware) => Middleware;
53
- type ExtractParam<Path, NextPart> = Path extends `:${infer Param}` ? Record<Param, string> & NextPart : NextPart;
54
- type ExtractParams<Path> = Path extends `${infer Segment}/${infer Rest}` ? ExtractParam<Segment, ExtractParams<Rest>> : ExtractParam<Path, {}>;
55
-
56
62
  interface RouteEvent<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> extends H3Event {
57
63
  context: RouteEventContext<TPath, TQuery, TBody>;
58
64
  }
@@ -74,9 +80,20 @@ type RouteOptions = Pick<ArriOptions, "onAfterResponse" | "onBeforeResponse" | "
74
80
  declare function registerRoute(router: Router, route: ArriRoute<any>, opts: RouteOptions): void;
75
81
  declare function handleRoute(router: Router, method: HttpMethod, route: ArriRoute<any>, opts: RouteOptions): void;
76
82
 
83
+ declare class ArriRouter {
84
+ private readonly routes;
85
+ private readonly definitions;
86
+ prefix: string;
87
+ constructor(routePrefix?: string);
88
+ route<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): void;
89
+ registerDefinitions(models: DefinitionMap): void;
90
+ getRoutes(): ArriRoute<any, any, any, any>[];
91
+ getDefinitions(): DefinitionMap;
92
+ }
93
+
77
94
  declare function defineEventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: Omit<EventStreamRpc<TParams, TResponse>, "isEventStream" | "transport">): EventStreamRpc<TParams, TResponse>;
78
95
  declare function isEventStreamRpc(input: unknown): input is EventStreamRpc<any, any>;
79
- interface EventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends Omit<Rpc<true, TParams, TResponse>, "handler" | "postHandler"> {
96
+ interface EventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends Omit<HttpRpc<true, TParams, TResponse>, "handler" | "postHandler"> {
80
97
  isEventStream: true;
81
98
  handler: EventStreamRpcHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : undefined>;
82
99
  }
@@ -185,10 +202,11 @@ declare function createWsRpcDefinition(rpcName: string, path: string, rpc: Named
185
202
 
186
203
  type RpcParamSchema<TObjectInner = any, TDiscriminatorInner = any> = AObjectSchema<TObjectInner> | ADiscriminatorSchema<TDiscriminatorInner>;
187
204
  declare function isRpcParamSchema(input: unknown): input is RpcParamSchema;
188
- interface NamedRpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends Rpc<TIsEventStream, TParams, TResponse> {
205
+ interface NamedHttpRpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends HttpRpc<TIsEventStream, TParams, TResponse> {
189
206
  name: string;
190
207
  }
191
- interface Rpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> {
208
+ type Rpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> = HttpRpc<TIsEventStream, TParams, TResponse> | WebsocketRpc<TParams, TResponse>;
209
+ interface HttpRpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> {
192
210
  transport: "http";
193
211
  method?: RpcHttpMethod;
194
212
  path?: string;
@@ -201,7 +219,6 @@ interface Rpc<TIsEventStream extends boolean = false, TParams extends RpcParamSc
201
219
  handler: TIsEventStream extends true ? EventStreamRpcHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : undefined> : RpcHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : void>;
202
220
  postHandler?: TIsEventStream extends true ? undefined : RpcPostHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : undefined>;
203
221
  }
204
- type HttpRpc<TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined> = Omit<Rpc<false, TParams, TResponse>, "isEventStream">;
205
222
  interface RpcEvent<TParams = undefined> extends Omit<H3Event, "context"> {
206
223
  context: RpcEventContext<TParams>;
207
224
  }
@@ -210,37 +227,31 @@ interface RpcPostEvent<TParams = undefined, TResponse = undefined> extends Omit<
210
227
  }
211
228
  type RpcHandler<TParams, TResponse> = (context: RpcEventContext<TParams>, event: RpcEvent<TParams>) => TResponse | Promise<TResponse>;
212
229
  type RpcPostHandler<TParams, TResponse> = (context: RpcPostEventContext<TParams, TResponse>, event: RpcPostEvent<TParams, TResponse>) => any;
213
- declare function isRpc(input: unknown): input is Rpc<any, any>;
214
- declare function defineRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: Omit<HttpRpc<TParams, TResponse>, "transport">): Rpc<false, TParams, TResponse>;
215
- declare function createHttpRpcDefinition(rpcName: string, httpPath: string, procedure: Rpc<any, any, any>): HttpRpcDefinition;
230
+ declare function isRpc(input: unknown): input is HttpRpc<any, any>;
231
+ declare function defineRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: Omit<HttpRpc<false, TParams, TResponse>, "transport" | "isEventStream">): HttpRpc<false, TParams, TResponse>;
232
+ declare function createHttpRpcDefinition(rpcName: string, httpPath: string, procedure: HttpRpc<any, any, any>): HttpRpcDefinition;
216
233
  declare function getRpcPath(rpcName: string, prefix?: string): string;
217
- declare function getRpcParamName(rpcName: string, procedure: Rpc<any, any, any> | WebsocketRpc<any, any>): string | undefined;
218
- declare function getRpcResponseName(rpcName: string, procedure: Rpc<any, any, any> | WebsocketRpc<any, any>): string | undefined;
219
- declare function registerRpc(router: Router, path: string, procedure: NamedRpc<any, any, any>, opts: RouteOptions): void;
220
- declare function validateRpcRequestInput(event: H3Event, httpMethod: RpcHttpMethod, schema: ASchema): Promise<void>;
234
+ declare function getRpcParamName(rpcName: string, procedure: HttpRpc<any, any, any> | WebsocketRpc<any, any>): string | undefined;
235
+ declare function getRpcResponseName(rpcName: string, procedure: HttpRpc<any, any, any> | WebsocketRpc<any, any>): string | undefined;
236
+ declare function registerRpc(router: Router, path: string, procedure: NamedHttpRpc<any, any, any>, opts: RouteOptions): void;
237
+ declare function validateRpcRequestInput(event: H3Event, httpMethod: RpcHttpMethod, schema: ASchema, validator: ReturnType<typeof a.compile>): Promise<void>;
238
+ declare function getSchemaValidator(rpcName: string, type: "params" | "response", schema: ASchema<any>): ReturnType<typeof a.compile> | undefined;
221
239
 
222
- interface ArriRouterBase {
223
- rpc: <TIsEventStream extends boolean, TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: Omit<NamedRpc<TIsEventStream, TParams, TResponse>, "transport">) => void;
224
- wsRpc: <TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined>(procedure: Omit<NamedWebsocketRpc<TParams, TResponse>, "transport">) => void;
225
- route: <TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>) => void;
226
- registerDefinitions: (definitions: DefinitionMap) => void;
227
- }
228
- declare class ArriRouter implements ArriRouterBase {
240
+ declare class ArriService {
241
+ name: string;
242
+ constructor(name: string);
229
243
  private readonly procedures;
230
- private readonly routes;
231
244
  private readonly definitions;
232
- rpc<TIsEventStream extends boolean = false, TParams extends AObjectSchema<any, any> | undefined = undefined, TResponse extends AObjectSchema<any, any> | undefined = undefined>(procedure: Omit<NamedRpc<TIsEventStream, TParams, TResponse>, "transport">): void;
233
- wsRpc<TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined>(procedure: Omit<NamedWebsocketRpc<TParams, TResponse>, "transport">): void;
234
- route<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): void;
245
+ rpc(name: string, procedure: Rpc<any, any, any>): void;
235
246
  registerDefinitions(models: DefinitionMap): void;
236
- getProcedures(): (NamedWebsocketRpc<any, any> | NamedRpc<any, any, any>)[];
237
- getRoutes(): ArriRoute<any, any, any, any>[];
247
+ getProcedures(): (NamedWebsocketRpc<any, any> | NamedHttpRpc<any, any, any>)[];
238
248
  getDefinitions(): DefinitionMap;
239
249
  }
250
+ declare function defineService(name: string, procedures?: Record<string, HttpRpc<any, any, any> | WebsocketRpc<any, any>>): ArriService;
240
251
 
241
252
  type DefinitionMap = Record<string, SchemaFormProperties | SchemaFormDiscriminator | SchemaFormValues>;
242
253
  declare const createAppDefinition: (def: AppDefinition) => AppDefinition;
243
- declare class ArriApp implements ArriRouterBase {
254
+ declare class ArriApp {
244
255
  __isArri__: boolean;
245
256
  readonly h3App: App;
246
257
  readonly h3Router: Router;
@@ -257,9 +268,8 @@ declare class ArriApp implements ArriRouterBase {
257
268
  private readonly _debug;
258
269
  readonly definitionPath: string;
259
270
  constructor(opts?: ArriOptions);
260
- use(input: Middleware | ArriRouter): void;
261
- rpc<TIsEventStream extends boolean = false, TParams extends AObjectSchema<any, any> | undefined = undefined, TResponse extends AObjectSchema<any, any> | undefined = undefined>(procedure: Omit<NamedRpc<TIsEventStream, TParams, TResponse>, "transport">): void;
262
- wsRpc<TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined>(procedure: Omit<NamedWebsocketRpc<TParams, TResponse>, "transport">): void;
271
+ use(input: Middleware | ArriRouter | ArriService): void;
272
+ rpc(name: string, procedure: Rpc<any, any, any>): void;
263
273
  route<TPath extends string, TQuery extends AObjectSchema<any, any>, TBody extends ASchema<any>, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): void;
264
274
  registerDefinitions(definitions: DefinitionMap): void;
265
275
  getAppDefinition(): AppDefinition;
@@ -279,9 +289,12 @@ interface ArriOptions {
279
289
  disableDefaultRoute?: boolean;
280
290
  disableDefinitionRoute?: boolean;
281
291
  onRequest?: (event: MiddlewareEvent) => void | Promise<void>;
282
- onAfterResponse?: (event: MiddlewareEvent) => void | Promise<void>;
283
- onBeforeResponse?: (event: MiddlewareEvent) => void | Promise<void>;
284
- onError?: (error: ArriServerError, event: MiddlewareEvent) => void | Promise<void>;
292
+ onAfterResponse?: (event: RequestHookEvent) => void | Promise<void>;
293
+ onBeforeResponse?: (event: RequestHookEvent) => void | Promise<void>;
294
+ onError?: (error: ArriServerError, event: RequestHookContext) => void | Promise<void>;
295
+ }
296
+ interface RequestHookEvent extends Omit<H3Event, "context"> {
297
+ context: RequestHookContext;
285
298
  }
286
299
 
287
- export { ArriApp, type ArriEventContext, type ArriOptions, type ArriRoute, ArriRouter, type ArriRouterBase, ArriServerError, ArriServerErrorResponse, type DefinitionMap, EventStreamConnection, type EventStreamConnectionOptions, type EventStreamRpc, type EventStreamRpcHandler, type EventStreamRpcHandlerContext, type ExtractParam, type ExtractParams, type HttpRpc, type Middleware, type MiddlewareEvent, type MiddlewareEventContext, type NamedRpc, type NamedWebsocketRpc, type PostRouteEvent, type RouteEvent, type RouteEventContext, type RouteOptions, type RoutePostEventContext, type Rpc, type RpcEvent, type RpcEventContext, type RpcHandler, type RpcParamSchema, type RpcPostEvent, type RpcPostEventContext, type RpcPostHandler, type SsePushResult, type WebSocketRpcHandler, type WebsocketRpc, WsPeer, type WsPeerContext, createAppDefinition, createHttpRpcDefinition, createWsRpcDefinition, defineError, defineEventStreamRpc, defineMiddleware, defineRoute, defineRpc, defineWebsocketRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, handleRoute, isEventStreamRpc, isRpc, isRpcParamSchema, registerEventStreamRpc, registerRoute, registerRpc, registerWebsocketRpc, validateRpcRequestInput };
300
+ export { ArriApp, type ArriEventContext, type ArriOptions, type ArriRoute, ArriRouter, ArriServerError, ArriServerErrorResponse, ArriService, type DefinitionMap, EventStreamConnection, type EventStreamConnectionOptions, type EventStreamRpc, type EventStreamRpcHandler, type EventStreamRpcHandlerContext, type ExtractParam, type ExtractParams, type HttpRpc, type Middleware, type MiddlewareEvent, type MiddlewareEventContext, type NamedHttpRpc, type NamedWebsocketRpc, type PostRouteEvent, type RequestHookContext, type RequestHookEvent, type RouteEvent, type RouteEventContext, type RouteOptions, type RoutePostEventContext, type Rpc, type RpcEvent, type RpcEventContext, type RpcHandler, type RpcParamSchema, type RpcPostEvent, type RpcPostEventContext, type RpcPostHandler, type SsePushResult, type WebSocketRpcHandler, type WebsocketRpc, WsPeer, type WsPeerContext, createAppDefinition, createHttpRpcDefinition, createWsRpcDefinition, defineError, defineEventStreamRpc, defineMiddleware, defineRoute, defineRpc, defineService, defineWebsocketRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, getSchemaValidator, handleH3Error, handleRoute, isEventStreamRpc, isRpc, isRpcParamSchema, registerEventStreamRpc, registerRoute, registerRpc, registerWebsocketRpc, validateRpcRequestInput };
package/dist/index.d.mts CHANGED
@@ -1,9 +1,43 @@
1
1
  import { HttpMethod, WsRpcDefinition, RpcHttpMethod, HttpRpcDefinition, SchemaFormProperties, SchemaFormDiscriminator, SchemaFormValues, AppDefinition } from '@arrirpc/codegen-utils';
2
2
  import { AObjectSchema, a, ValidationError, ASchema, InferType, ValueError, CompiledValidator, ADiscriminatorSchema } from '@arrirpc/schema';
3
- import { StatusCode, H3Error, H3Event, H3EventContext, Router, EventStream, App } from 'h3';
3
+ import { H3Event, StatusCode, H3Error, Router, EventStream, App } from 'h3';
4
4
  export * from 'h3';
5
5
  import { Peer, WSError } from 'crossws';
6
6
 
7
+ interface MiddlewareEvent extends H3Event {
8
+ context: MiddlewareEventContext;
9
+ }
10
+ type Middleware = (event: MiddlewareEvent) => void | Promise<void>;
11
+ declare const defineMiddleware: (middleware: Middleware) => Middleware;
12
+ type ExtractParam<Path, NextPart> = Path extends `:${infer Param}` ? Record<Param, string> & NextPart : NextPart;
13
+ type ExtractParams<Path> = Path extends `${infer Segment}/${infer Rest}` ? ExtractParam<Segment, ExtractParams<Rest>> : ExtractParam<Path, {}>;
14
+
15
+ interface ArriEventContext extends Record<string, unknown> {
16
+ }
17
+ type RpcEventContext<TParams = undefined> = ArriEventContext & {
18
+ rpcName: string;
19
+ params: TParams;
20
+ };
21
+ type RpcPostEventContext<TParams = undefined, TResponse = undefined> = RpcEventContext<TParams> & {
22
+ response: TResponse;
23
+ };
24
+ type RouteEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> = ArriEventContext & {
25
+ params: ExtractParams<TPath>;
26
+ query: TQuery;
27
+ body: TBody;
28
+ };
29
+ type RoutePostEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any, TResponse = any> = RouteEventContext<TPath, TQuery, TBody> & {
30
+ response: TResponse;
31
+ };
32
+ type MiddlewareEventContext = ArriEventContext & {
33
+ rpcName?: string;
34
+ };
35
+ type RequestHookContext = ArriEventContext & {
36
+ rpcName?: string;
37
+ params?: Record<string, unknown>;
38
+ response?: unknown;
39
+ };
40
+
7
41
  declare class ArriServerError extends Error {
8
42
  code: number;
9
43
  data?: any;
@@ -25,34 +59,6 @@ declare function defineError(statusCode: StatusCode, input?: Partial<Omit<ArriSe
25
59
  declare function errorResponseFromValidationErrors(errors: ValidationError["errors"], prefixText?: string): H3Error;
26
60
  declare function handleH3Error(err: unknown, event: H3Event, onError: ArriOptions["onError"], debug: boolean): Promise<void>;
27
61
 
28
- type ArriEventContext = Record<string, any>;
29
- interface RpcEventContext<TParams = undefined> extends ArriEventContext, Omit<H3EventContext, "params"> {
30
- rpcName: string;
31
- params: TParams;
32
- }
33
- interface RpcPostEventContext<TParams = undefined, TResponse = undefined> extends RpcEventContext<TParams> {
34
- response: TResponse;
35
- }
36
- interface RouteEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> extends ArriEventContext, H3EventContext {
37
- params: ExtractParams<TPath>;
38
- query: TQuery;
39
- body: TBody;
40
- }
41
- interface RoutePostEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any, TResponse = any> extends RouteEventContext<TPath, TQuery, TBody> {
42
- response: TResponse;
43
- }
44
- interface MiddlewareEventContext extends ArriEventContext, H3EventContext {
45
- rpcName?: string;
46
- }
47
-
48
- interface MiddlewareEvent extends H3Event {
49
- context: MiddlewareEventContext;
50
- }
51
- type Middleware = (event: MiddlewareEvent) => void | Promise<void>;
52
- declare const defineMiddleware: (middleware: Middleware) => Middleware;
53
- type ExtractParam<Path, NextPart> = Path extends `:${infer Param}` ? Record<Param, string> & NextPart : NextPart;
54
- type ExtractParams<Path> = Path extends `${infer Segment}/${infer Rest}` ? ExtractParam<Segment, ExtractParams<Rest>> : ExtractParam<Path, {}>;
55
-
56
62
  interface RouteEvent<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> extends H3Event {
57
63
  context: RouteEventContext<TPath, TQuery, TBody>;
58
64
  }
@@ -74,9 +80,20 @@ type RouteOptions = Pick<ArriOptions, "onAfterResponse" | "onBeforeResponse" | "
74
80
  declare function registerRoute(router: Router, route: ArriRoute<any>, opts: RouteOptions): void;
75
81
  declare function handleRoute(router: Router, method: HttpMethod, route: ArriRoute<any>, opts: RouteOptions): void;
76
82
 
83
+ declare class ArriRouter {
84
+ private readonly routes;
85
+ private readonly definitions;
86
+ prefix: string;
87
+ constructor(routePrefix?: string);
88
+ route<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): void;
89
+ registerDefinitions(models: DefinitionMap): void;
90
+ getRoutes(): ArriRoute<any, any, any, any>[];
91
+ getDefinitions(): DefinitionMap;
92
+ }
93
+
77
94
  declare function defineEventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: Omit<EventStreamRpc<TParams, TResponse>, "isEventStream" | "transport">): EventStreamRpc<TParams, TResponse>;
78
95
  declare function isEventStreamRpc(input: unknown): input is EventStreamRpc<any, any>;
79
- interface EventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends Omit<Rpc<true, TParams, TResponse>, "handler" | "postHandler"> {
96
+ interface EventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends Omit<HttpRpc<true, TParams, TResponse>, "handler" | "postHandler"> {
80
97
  isEventStream: true;
81
98
  handler: EventStreamRpcHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : undefined>;
82
99
  }
@@ -185,10 +202,11 @@ declare function createWsRpcDefinition(rpcName: string, path: string, rpc: Named
185
202
 
186
203
  type RpcParamSchema<TObjectInner = any, TDiscriminatorInner = any> = AObjectSchema<TObjectInner> | ADiscriminatorSchema<TDiscriminatorInner>;
187
204
  declare function isRpcParamSchema(input: unknown): input is RpcParamSchema;
188
- interface NamedRpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends Rpc<TIsEventStream, TParams, TResponse> {
205
+ interface NamedHttpRpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends HttpRpc<TIsEventStream, TParams, TResponse> {
189
206
  name: string;
190
207
  }
191
- interface Rpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> {
208
+ type Rpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> = HttpRpc<TIsEventStream, TParams, TResponse> | WebsocketRpc<TParams, TResponse>;
209
+ interface HttpRpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> {
192
210
  transport: "http";
193
211
  method?: RpcHttpMethod;
194
212
  path?: string;
@@ -201,7 +219,6 @@ interface Rpc<TIsEventStream extends boolean = false, TParams extends RpcParamSc
201
219
  handler: TIsEventStream extends true ? EventStreamRpcHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : undefined> : RpcHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : void>;
202
220
  postHandler?: TIsEventStream extends true ? undefined : RpcPostHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : undefined>;
203
221
  }
204
- type HttpRpc<TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined> = Omit<Rpc<false, TParams, TResponse>, "isEventStream">;
205
222
  interface RpcEvent<TParams = undefined> extends Omit<H3Event, "context"> {
206
223
  context: RpcEventContext<TParams>;
207
224
  }
@@ -210,37 +227,31 @@ interface RpcPostEvent<TParams = undefined, TResponse = undefined> extends Omit<
210
227
  }
211
228
  type RpcHandler<TParams, TResponse> = (context: RpcEventContext<TParams>, event: RpcEvent<TParams>) => TResponse | Promise<TResponse>;
212
229
  type RpcPostHandler<TParams, TResponse> = (context: RpcPostEventContext<TParams, TResponse>, event: RpcPostEvent<TParams, TResponse>) => any;
213
- declare function isRpc(input: unknown): input is Rpc<any, any>;
214
- declare function defineRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: Omit<HttpRpc<TParams, TResponse>, "transport">): Rpc<false, TParams, TResponse>;
215
- declare function createHttpRpcDefinition(rpcName: string, httpPath: string, procedure: Rpc<any, any, any>): HttpRpcDefinition;
230
+ declare function isRpc(input: unknown): input is HttpRpc<any, any>;
231
+ declare function defineRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: Omit<HttpRpc<false, TParams, TResponse>, "transport" | "isEventStream">): HttpRpc<false, TParams, TResponse>;
232
+ declare function createHttpRpcDefinition(rpcName: string, httpPath: string, procedure: HttpRpc<any, any, any>): HttpRpcDefinition;
216
233
  declare function getRpcPath(rpcName: string, prefix?: string): string;
217
- declare function getRpcParamName(rpcName: string, procedure: Rpc<any, any, any> | WebsocketRpc<any, any>): string | undefined;
218
- declare function getRpcResponseName(rpcName: string, procedure: Rpc<any, any, any> | WebsocketRpc<any, any>): string | undefined;
219
- declare function registerRpc(router: Router, path: string, procedure: NamedRpc<any, any, any>, opts: RouteOptions): void;
220
- declare function validateRpcRequestInput(event: H3Event, httpMethod: RpcHttpMethod, schema: ASchema): Promise<void>;
234
+ declare function getRpcParamName(rpcName: string, procedure: HttpRpc<any, any, any> | WebsocketRpc<any, any>): string | undefined;
235
+ declare function getRpcResponseName(rpcName: string, procedure: HttpRpc<any, any, any> | WebsocketRpc<any, any>): string | undefined;
236
+ declare function registerRpc(router: Router, path: string, procedure: NamedHttpRpc<any, any, any>, opts: RouteOptions): void;
237
+ declare function validateRpcRequestInput(event: H3Event, httpMethod: RpcHttpMethod, schema: ASchema, validator: ReturnType<typeof a.compile>): Promise<void>;
238
+ declare function getSchemaValidator(rpcName: string, type: "params" | "response", schema: ASchema<any>): ReturnType<typeof a.compile> | undefined;
221
239
 
222
- interface ArriRouterBase {
223
- rpc: <TIsEventStream extends boolean, TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: Omit<NamedRpc<TIsEventStream, TParams, TResponse>, "transport">) => void;
224
- wsRpc: <TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined>(procedure: Omit<NamedWebsocketRpc<TParams, TResponse>, "transport">) => void;
225
- route: <TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>) => void;
226
- registerDefinitions: (definitions: DefinitionMap) => void;
227
- }
228
- declare class ArriRouter implements ArriRouterBase {
240
+ declare class ArriService {
241
+ name: string;
242
+ constructor(name: string);
229
243
  private readonly procedures;
230
- private readonly routes;
231
244
  private readonly definitions;
232
- rpc<TIsEventStream extends boolean = false, TParams extends AObjectSchema<any, any> | undefined = undefined, TResponse extends AObjectSchema<any, any> | undefined = undefined>(procedure: Omit<NamedRpc<TIsEventStream, TParams, TResponse>, "transport">): void;
233
- wsRpc<TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined>(procedure: Omit<NamedWebsocketRpc<TParams, TResponse>, "transport">): void;
234
- route<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): void;
245
+ rpc(name: string, procedure: Rpc<any, any, any>): void;
235
246
  registerDefinitions(models: DefinitionMap): void;
236
- getProcedures(): (NamedWebsocketRpc<any, any> | NamedRpc<any, any, any>)[];
237
- getRoutes(): ArriRoute<any, any, any, any>[];
247
+ getProcedures(): (NamedWebsocketRpc<any, any> | NamedHttpRpc<any, any, any>)[];
238
248
  getDefinitions(): DefinitionMap;
239
249
  }
250
+ declare function defineService(name: string, procedures?: Record<string, HttpRpc<any, any, any> | WebsocketRpc<any, any>>): ArriService;
240
251
 
241
252
  type DefinitionMap = Record<string, SchemaFormProperties | SchemaFormDiscriminator | SchemaFormValues>;
242
253
  declare const createAppDefinition: (def: AppDefinition) => AppDefinition;
243
- declare class ArriApp implements ArriRouterBase {
254
+ declare class ArriApp {
244
255
  __isArri__: boolean;
245
256
  readonly h3App: App;
246
257
  readonly h3Router: Router;
@@ -257,9 +268,8 @@ declare class ArriApp implements ArriRouterBase {
257
268
  private readonly _debug;
258
269
  readonly definitionPath: string;
259
270
  constructor(opts?: ArriOptions);
260
- use(input: Middleware | ArriRouter): void;
261
- rpc<TIsEventStream extends boolean = false, TParams extends AObjectSchema<any, any> | undefined = undefined, TResponse extends AObjectSchema<any, any> | undefined = undefined>(procedure: Omit<NamedRpc<TIsEventStream, TParams, TResponse>, "transport">): void;
262
- wsRpc<TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined>(procedure: Omit<NamedWebsocketRpc<TParams, TResponse>, "transport">): void;
271
+ use(input: Middleware | ArriRouter | ArriService): void;
272
+ rpc(name: string, procedure: Rpc<any, any, any>): void;
263
273
  route<TPath extends string, TQuery extends AObjectSchema<any, any>, TBody extends ASchema<any>, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): void;
264
274
  registerDefinitions(definitions: DefinitionMap): void;
265
275
  getAppDefinition(): AppDefinition;
@@ -279,9 +289,12 @@ interface ArriOptions {
279
289
  disableDefaultRoute?: boolean;
280
290
  disableDefinitionRoute?: boolean;
281
291
  onRequest?: (event: MiddlewareEvent) => void | Promise<void>;
282
- onAfterResponse?: (event: MiddlewareEvent) => void | Promise<void>;
283
- onBeforeResponse?: (event: MiddlewareEvent) => void | Promise<void>;
284
- onError?: (error: ArriServerError, event: MiddlewareEvent) => void | Promise<void>;
292
+ onAfterResponse?: (event: RequestHookEvent) => void | Promise<void>;
293
+ onBeforeResponse?: (event: RequestHookEvent) => void | Promise<void>;
294
+ onError?: (error: ArriServerError, event: RequestHookContext) => void | Promise<void>;
295
+ }
296
+ interface RequestHookEvent extends Omit<H3Event, "context"> {
297
+ context: RequestHookContext;
285
298
  }
286
299
 
287
- export { ArriApp, type ArriEventContext, type ArriOptions, type ArriRoute, ArriRouter, type ArriRouterBase, ArriServerError, ArriServerErrorResponse, type DefinitionMap, EventStreamConnection, type EventStreamConnectionOptions, type EventStreamRpc, type EventStreamRpcHandler, type EventStreamRpcHandlerContext, type ExtractParam, type ExtractParams, type HttpRpc, type Middleware, type MiddlewareEvent, type MiddlewareEventContext, type NamedRpc, type NamedWebsocketRpc, type PostRouteEvent, type RouteEvent, type RouteEventContext, type RouteOptions, type RoutePostEventContext, type Rpc, type RpcEvent, type RpcEventContext, type RpcHandler, type RpcParamSchema, type RpcPostEvent, type RpcPostEventContext, type RpcPostHandler, type SsePushResult, type WebSocketRpcHandler, type WebsocketRpc, WsPeer, type WsPeerContext, createAppDefinition, createHttpRpcDefinition, createWsRpcDefinition, defineError, defineEventStreamRpc, defineMiddleware, defineRoute, defineRpc, defineWebsocketRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, handleRoute, isEventStreamRpc, isRpc, isRpcParamSchema, registerEventStreamRpc, registerRoute, registerRpc, registerWebsocketRpc, validateRpcRequestInput };
300
+ export { ArriApp, type ArriEventContext, type ArriOptions, type ArriRoute, ArriRouter, ArriServerError, ArriServerErrorResponse, ArriService, type DefinitionMap, EventStreamConnection, type EventStreamConnectionOptions, type EventStreamRpc, type EventStreamRpcHandler, type EventStreamRpcHandlerContext, type ExtractParam, type ExtractParams, type HttpRpc, type Middleware, type MiddlewareEvent, type MiddlewareEventContext, type NamedHttpRpc, type NamedWebsocketRpc, type PostRouteEvent, type RequestHookContext, type RequestHookEvent, type RouteEvent, type RouteEventContext, type RouteOptions, type RoutePostEventContext, type Rpc, type RpcEvent, type RpcEventContext, type RpcHandler, type RpcParamSchema, type RpcPostEvent, type RpcPostEventContext, type RpcPostHandler, type SsePushResult, type WebSocketRpcHandler, type WebsocketRpc, WsPeer, type WsPeerContext, createAppDefinition, createHttpRpcDefinition, createWsRpcDefinition, defineError, defineEventStreamRpc, defineMiddleware, defineRoute, defineRpc, defineService, defineWebsocketRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, getSchemaValidator, handleH3Error, handleRoute, isEventStreamRpc, isRpc, isRpcParamSchema, registerEventStreamRpc, registerRoute, registerRpc, registerWebsocketRpc, validateRpcRequestInput };