@arrirpc/server 0.73.0 → 0.74.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.mts CHANGED
@@ -1,8 +1,7 @@
1
- import { HttpMethod, WsRpcDefinition, RpcHttpMethod, HttpRpcDefinition, SchemaFormProperties, SchemaFormDiscriminator, SchemaFormValues, AppDefinition } from '@arrirpc/codegen-utils';
2
- import { AObjectSchema, a, ValidationError, ASchema, InferType, ValueError, CompiledValidator, ADiscriminatorSchema } from '@arrirpc/schema';
1
+ import { HttpMethod, RpcHttpMethod, HttpRpcDefinition, SchemaFormProperties, SchemaFormDiscriminator, SchemaFormValues, AppDefinition } from '@arrirpc/codegen-utils';
2
+ import { AObjectSchema, a, ValueError, ASchema, InferType, ADiscriminatorSchema, Result } from '@arrirpc/schema';
3
3
  import { H3Event, StatusCode, H3Error, Router, EventStream, App } from 'h3';
4
4
  export * from 'h3';
5
- import { Peer, WSError } from 'crossws';
6
5
 
7
6
  interface MiddlewareEvent extends H3Event {
8
7
  context: MiddlewareEventContext;
@@ -56,7 +55,7 @@ declare const arriErrorResponse: AObjectSchema<{
56
55
  }>;
57
56
  type arriErrorResponse = a.infer<typeof arriErrorResponse>;
58
57
  declare function defineError(statusCode: StatusCode, input?: Partial<Omit<arriErrorResponse, 'code' | 'stack'>>): arriError;
59
- declare function errorResponseFromValidationErrors(errors: ValidationError['errors'], prefixText?: string): H3Error;
58
+ declare function errorResponseFromValidationErrors(errors: ValueError[], prefixText?: string): H3Error;
60
59
  declare function handleH3Error(err: unknown, event: H3Event, onError: ArriOptions['onError'], debug: boolean): Promise<void>;
61
60
 
62
61
  interface RouteEvent<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> extends H3Event {
@@ -91,7 +90,7 @@ declare class ArriRouter {
91
90
  getDefinitions(): DefinitionMap;
92
91
  }
93
92
 
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>;
93
+ declare function defineEventStreamRpc<TResponse extends RpcParamSchema<any>, TParams extends RpcParamSchema<any> | undefined = undefined>(config: Omit<EventStreamRpc<TParams, TResponse>, 'isEventStream' | 'transport'>): EventStreamRpc<TParams, TResponse>;
95
94
  declare function isEventStreamRpc(input: unknown): input is EventStreamRpc<any, any>;
96
95
  interface EventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends Omit<HttpRpc<true, TParams, TResponse>, 'handler' | 'postHandler'> {
97
96
  isEventStream: true;
@@ -102,16 +101,12 @@ interface EventStreamRpcHandlerContext<TParams = any, TResponse = any> extends R
102
101
  stream: EventStreamConnection<TResponse>;
103
102
  }
104
103
  interface EventStreamConnectionOptions<TData> {
105
- validator: (input: unknown) => input is TData;
106
- validationErrors: (input: unknown) => ValueError[];
107
- serializer: (input: TData) => string;
104
+ validator?: RequestValidator<TData>;
108
105
  pingInterval?: number;
109
106
  }
110
107
  declare class EventStreamConnection<TData> {
111
108
  readonly lastEventId?: string;
112
- private readonly validationErrors;
113
- private readonly validator;
114
- private readonly serializer;
109
+ private readonly validator?;
115
110
  private pingInterval;
116
111
  private readonly pingIntervalMs;
117
112
  readonly eventStream: EventStream;
@@ -142,69 +137,12 @@ declare function registerEventStreamRpc(router: Router, path: string, procedure:
142
137
  name: string;
143
138
  }, opts: RouteOptions): void;
144
139
 
145
- interface NamedWebsocketRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends WebsocketRpc<TParams, TResponse> {
146
- name: string;
147
- }
148
- interface WebsocketRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> {
149
- transport: 'ws';
150
- description?: string;
151
- path?: string;
152
- isDeprecated?: boolean;
153
- params: TParams;
154
- response: TResponse;
155
- pingInterval?: boolean;
156
- handler: WebSocketRpcHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : undefined> | (() => WebSocketRpcHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : undefined>);
157
- }
158
- interface WsPeerOpts<TResponse> {
159
- validator?: CompiledValidator<ASchema<TResponse>>;
160
- context: WsPeerContext;
161
- }
162
- interface WsPeerContext extends Record<string, any> {
163
- rpcName: string;
164
- queryParams?: Record<string, string>;
165
- clientAddress?: string;
166
- }
167
- declare class WsPeer<TResponse> {
168
- private readonly _peer;
169
- private readonly _validator?;
170
- context: WsPeerContext;
171
- url: string;
172
- constructor(peer: Peer, opts: WsPeerOpts<TResponse>);
173
- send(data: TResponse): number | void;
174
- sendError(err: arriErrorResponse): number | void | undefined;
175
- close(): void;
176
- subscribe(channel: string): void;
177
- unsubscribe(channel: string): void;
178
- publish(channel: string, message: TResponse): void;
179
- }
180
- interface WebSocketRpcHandler<TParams, TResponse> {
181
- onOpen: (peer: WsPeer<TResponse>) => void;
182
- onMessage: (peer: WsPeer<TResponse>, message: TParams) => void;
183
- onClose: (peer: WsPeer<TResponse>, details: {
184
- code?: number;
185
- reason?: string;
186
- }) => void;
187
- onError: (peer: WsPeer<TResponse>, error: WSError) => void;
188
- }
189
- /**
190
- * @experimental
191
- */
192
- declare function defineWebsocketRpc<TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined>(def: Omit<WebsocketRpc<TParams, TResponse>, 'transport'>): WebsocketRpc<TParams, TResponse>;
193
- /**
194
- * @experimental
195
- */
196
- declare function registerWebsocketRpc(router: Router, path: string, _rpc: NamedWebsocketRpc<any, any>): void;
197
- /**
198
- * @experimental
199
- */
200
- declare function createWsRpcDefinition(rpcName: string, path: string, rpc: NamedWebsocketRpc<any, any>): WsRpcDefinition;
201
-
202
- type RpcParamSchema<TObjectInner = any, TDiscriminatorInner = any> = AObjectSchema<TObjectInner> | ADiscriminatorSchema<TDiscriminatorInner>;
203
- declare function isRpcParamSchema(input: unknown): input is RpcParamSchema;
140
+ type RpcParamSchema<T = any> = AObjectSchema<T> | ADiscriminatorSchema<T>;
141
+ declare function isRpcParamSchema(input: unknown): input is RpcParamSchema<any>;
204
142
  interface NamedHttpRpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends HttpRpc<TIsEventStream, TParams, TResponse> {
205
143
  name: string;
206
144
  }
207
- type Rpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> = HttpRpc<TIsEventStream, TParams, TResponse> | WebsocketRpc<TParams, TResponse>;
145
+ type Rpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> = HttpRpc<TIsEventStream, TParams, TResponse>;
208
146
  interface HttpRpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> {
209
147
  transport: 'http';
210
148
  method?: RpcHttpMethod;
@@ -215,8 +153,8 @@ interface HttpRpc<TIsEventStream extends boolean = false, TParams extends RpcPar
215
153
  isDeprecated?: boolean;
216
154
  isEventStream?: TIsEventStream;
217
155
  pingInterval?: TIsEventStream extends true ? number : undefined;
218
- 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>;
219
- postHandler?: TIsEventStream extends true ? undefined : RpcPostHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : undefined>;
156
+ handler: TIsEventStream extends true ? EventStreamRpcHandler<TParams extends RpcParamSchema<any> ? InferType<TParams> : undefined, TResponse extends RpcParamSchema<any> ? InferType<TResponse> : undefined> : RpcHandler<TParams extends RpcParamSchema<any> ? InferType<TParams> : undefined, TResponse extends RpcParamSchema<any> ? InferType<TResponse> : void>;
157
+ postHandler?: TIsEventStream extends true ? undefined : RpcPostHandler<TParams extends RpcParamSchema<any> ? InferType<TParams> : undefined, TResponse extends RpcParamSchema<any> ? InferType<TResponse> : undefined>;
220
158
  }
221
159
  interface RpcEvent<TParams = undefined> extends Omit<H3Event, 'context'> {
222
160
  context: RpcEventContext<TParams>;
@@ -230,11 +168,19 @@ declare function isRpc(input: unknown): input is HttpRpc<any, any>;
230
168
  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>;
231
169
  declare function createHttpRpcDefinition(rpcName: string, httpPath: string, procedure: HttpRpc<any, any, any>): HttpRpcDefinition;
232
170
  declare function getRpcPath(rpcName: string, prefix?: string): string;
233
- declare function getRpcParamName(rpcName: string, procedure: HttpRpc<any, any, any> | WebsocketRpc<any, any>): string | undefined;
234
- declare function getRpcResponseName(rpcName: string, procedure: HttpRpc<any, any, any> | WebsocketRpc<any, any>): string | undefined;
171
+ declare function getRpcParamName(rpcName: string, procedure: HttpRpc<any, any, any>): string | undefined;
172
+ declare function getRpcResponseName(rpcName: string, procedure: HttpRpc<any, any, any>): string | undefined;
235
173
  declare function registerRpc(router: Router, path: string, procedure: NamedHttpRpc<any, any, any>, opts: RouteOptions): void;
236
- declare function validateRpcRequestInput(event: H3Event, httpMethod: RpcHttpMethod, schema: ASchema, validator: ReturnType<typeof a.compile>): Promise<void>;
237
- declare function getSchemaValidator(rpcName: string, type: 'params' | 'response', schema: ASchema<any>): ReturnType<typeof a.compile> | undefined;
174
+ declare function validateRpcRequestInput(event: H3Event, httpMethod: RpcHttpMethod, validator: RequestValidator): Promise<void>;
175
+ type RequestValidator<T = any> = {
176
+ validate: (input: unknown) => input is T;
177
+ errors: (input: unknown) => ValueError[];
178
+ coerce: (input: unknown) => Result<T>;
179
+ parse: (input: unknown) => Result<T>;
180
+ serialize: (input: any) => Result<string>;
181
+ };
182
+ declare function getSchemaValidator<T extends Record<string, any> = any>(rpcName: string, type: 'params' | 'response', schema: RpcParamSchema<T>): RequestValidator<T> | undefined;
183
+ declare function getSchemaName(rpcName: string, type: 'params' | 'response', schema: RpcParamSchema<any>): string;
238
184
 
239
185
  declare class ArriService {
240
186
  name: string;
@@ -243,10 +189,10 @@ declare class ArriService {
243
189
  private readonly definitions;
244
190
  rpc(name: string, procedure: Rpc<any, any, any>): void;
245
191
  registerDefinitions(models: DefinitionMap): void;
246
- getProcedures(): (NamedWebsocketRpc<any, any> | NamedHttpRpc<any, any, any>)[];
192
+ getProcedures(): NamedHttpRpc<any, any, any>[];
247
193
  getDefinitions(): DefinitionMap;
248
194
  }
249
- declare function defineService(name: string, procedures?: Record<string, HttpRpc<any, any, any> | WebsocketRpc<any, any>>): ArriService;
195
+ declare function defineService(name: string, procedures?: Record<string, HttpRpc<any, any, any>>): ArriService;
250
196
 
251
197
  type DefinitionMap = Record<string, SchemaFormProperties | SchemaFormDiscriminator | SchemaFormValues>;
252
198
  declare const createAppDefinition: (def: AppDefinition) => AppDefinition;
@@ -298,4 +244,4 @@ interface RequestHookEvent extends Omit<H3Event, 'context'> {
298
244
  context: RequestHookContext;
299
245
  }
300
246
 
301
- export { ArriApp, type ArriEventContext, type ArriOptions, type ArriRoute, ArriRouter, 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, arriError, arriErrorResponse, 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 };
247
+ export { ArriApp, type ArriEventContext, type ArriOptions, type ArriRoute, ArriRouter, 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 PostRouteEvent, type RequestHookContext, type RequestHookEvent, type RequestValidator, 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, arriError, arriErrorResponse, createAppDefinition, createHttpRpcDefinition, defineError, defineEventStreamRpc, defineMiddleware, defineRoute, defineRpc, defineService, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, getSchemaName, getSchemaValidator, handleH3Error, handleRoute, isEventStreamRpc, isRpc, isRpcParamSchema, registerEventStreamRpc, registerRoute, registerRpc, validateRpcRequestInput };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,7 @@
1
- import { HttpMethod, WsRpcDefinition, RpcHttpMethod, HttpRpcDefinition, SchemaFormProperties, SchemaFormDiscriminator, SchemaFormValues, AppDefinition } from '@arrirpc/codegen-utils';
2
- import { AObjectSchema, a, ValidationError, ASchema, InferType, ValueError, CompiledValidator, ADiscriminatorSchema } from '@arrirpc/schema';
1
+ import { HttpMethod, RpcHttpMethod, HttpRpcDefinition, SchemaFormProperties, SchemaFormDiscriminator, SchemaFormValues, AppDefinition } from '@arrirpc/codegen-utils';
2
+ import { AObjectSchema, a, ValueError, ASchema, InferType, ADiscriminatorSchema, Result } from '@arrirpc/schema';
3
3
  import { H3Event, StatusCode, H3Error, Router, EventStream, App } from 'h3';
4
4
  export * from 'h3';
5
- import { Peer, WSError } from 'crossws';
6
5
 
7
6
  interface MiddlewareEvent extends H3Event {
8
7
  context: MiddlewareEventContext;
@@ -56,7 +55,7 @@ declare const arriErrorResponse: AObjectSchema<{
56
55
  }>;
57
56
  type arriErrorResponse = a.infer<typeof arriErrorResponse>;
58
57
  declare function defineError(statusCode: StatusCode, input?: Partial<Omit<arriErrorResponse, 'code' | 'stack'>>): arriError;
59
- declare function errorResponseFromValidationErrors(errors: ValidationError['errors'], prefixText?: string): H3Error;
58
+ declare function errorResponseFromValidationErrors(errors: ValueError[], prefixText?: string): H3Error;
60
59
  declare function handleH3Error(err: unknown, event: H3Event, onError: ArriOptions['onError'], debug: boolean): Promise<void>;
61
60
 
62
61
  interface RouteEvent<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> extends H3Event {
@@ -91,7 +90,7 @@ declare class ArriRouter {
91
90
  getDefinitions(): DefinitionMap;
92
91
  }
93
92
 
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>;
93
+ declare function defineEventStreamRpc<TResponse extends RpcParamSchema<any>, TParams extends RpcParamSchema<any> | undefined = undefined>(config: Omit<EventStreamRpc<TParams, TResponse>, 'isEventStream' | 'transport'>): EventStreamRpc<TParams, TResponse>;
95
94
  declare function isEventStreamRpc(input: unknown): input is EventStreamRpc<any, any>;
96
95
  interface EventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends Omit<HttpRpc<true, TParams, TResponse>, 'handler' | 'postHandler'> {
97
96
  isEventStream: true;
@@ -102,16 +101,12 @@ interface EventStreamRpcHandlerContext<TParams = any, TResponse = any> extends R
102
101
  stream: EventStreamConnection<TResponse>;
103
102
  }
104
103
  interface EventStreamConnectionOptions<TData> {
105
- validator: (input: unknown) => input is TData;
106
- validationErrors: (input: unknown) => ValueError[];
107
- serializer: (input: TData) => string;
104
+ validator?: RequestValidator<TData>;
108
105
  pingInterval?: number;
109
106
  }
110
107
  declare class EventStreamConnection<TData> {
111
108
  readonly lastEventId?: string;
112
- private readonly validationErrors;
113
- private readonly validator;
114
- private readonly serializer;
109
+ private readonly validator?;
115
110
  private pingInterval;
116
111
  private readonly pingIntervalMs;
117
112
  readonly eventStream: EventStream;
@@ -142,69 +137,12 @@ declare function registerEventStreamRpc(router: Router, path: string, procedure:
142
137
  name: string;
143
138
  }, opts: RouteOptions): void;
144
139
 
145
- interface NamedWebsocketRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends WebsocketRpc<TParams, TResponse> {
146
- name: string;
147
- }
148
- interface WebsocketRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> {
149
- transport: 'ws';
150
- description?: string;
151
- path?: string;
152
- isDeprecated?: boolean;
153
- params: TParams;
154
- response: TResponse;
155
- pingInterval?: boolean;
156
- handler: WebSocketRpcHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : undefined> | (() => WebSocketRpcHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : undefined>);
157
- }
158
- interface WsPeerOpts<TResponse> {
159
- validator?: CompiledValidator<ASchema<TResponse>>;
160
- context: WsPeerContext;
161
- }
162
- interface WsPeerContext extends Record<string, any> {
163
- rpcName: string;
164
- queryParams?: Record<string, string>;
165
- clientAddress?: string;
166
- }
167
- declare class WsPeer<TResponse> {
168
- private readonly _peer;
169
- private readonly _validator?;
170
- context: WsPeerContext;
171
- url: string;
172
- constructor(peer: Peer, opts: WsPeerOpts<TResponse>);
173
- send(data: TResponse): number | void;
174
- sendError(err: arriErrorResponse): number | void | undefined;
175
- close(): void;
176
- subscribe(channel: string): void;
177
- unsubscribe(channel: string): void;
178
- publish(channel: string, message: TResponse): void;
179
- }
180
- interface WebSocketRpcHandler<TParams, TResponse> {
181
- onOpen: (peer: WsPeer<TResponse>) => void;
182
- onMessage: (peer: WsPeer<TResponse>, message: TParams) => void;
183
- onClose: (peer: WsPeer<TResponse>, details: {
184
- code?: number;
185
- reason?: string;
186
- }) => void;
187
- onError: (peer: WsPeer<TResponse>, error: WSError) => void;
188
- }
189
- /**
190
- * @experimental
191
- */
192
- declare function defineWebsocketRpc<TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined>(def: Omit<WebsocketRpc<TParams, TResponse>, 'transport'>): WebsocketRpc<TParams, TResponse>;
193
- /**
194
- * @experimental
195
- */
196
- declare function registerWebsocketRpc(router: Router, path: string, _rpc: NamedWebsocketRpc<any, any>): void;
197
- /**
198
- * @experimental
199
- */
200
- declare function createWsRpcDefinition(rpcName: string, path: string, rpc: NamedWebsocketRpc<any, any>): WsRpcDefinition;
201
-
202
- type RpcParamSchema<TObjectInner = any, TDiscriminatorInner = any> = AObjectSchema<TObjectInner> | ADiscriminatorSchema<TDiscriminatorInner>;
203
- declare function isRpcParamSchema(input: unknown): input is RpcParamSchema;
140
+ type RpcParamSchema<T = any> = AObjectSchema<T> | ADiscriminatorSchema<T>;
141
+ declare function isRpcParamSchema(input: unknown): input is RpcParamSchema<any>;
204
142
  interface NamedHttpRpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends HttpRpc<TIsEventStream, TParams, TResponse> {
205
143
  name: string;
206
144
  }
207
- type Rpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> = HttpRpc<TIsEventStream, TParams, TResponse> | WebsocketRpc<TParams, TResponse>;
145
+ type Rpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> = HttpRpc<TIsEventStream, TParams, TResponse>;
208
146
  interface HttpRpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> {
209
147
  transport: 'http';
210
148
  method?: RpcHttpMethod;
@@ -215,8 +153,8 @@ interface HttpRpc<TIsEventStream extends boolean = false, TParams extends RpcPar
215
153
  isDeprecated?: boolean;
216
154
  isEventStream?: TIsEventStream;
217
155
  pingInterval?: TIsEventStream extends true ? number : undefined;
218
- 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>;
219
- postHandler?: TIsEventStream extends true ? undefined : RpcPostHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : undefined>;
156
+ handler: TIsEventStream extends true ? EventStreamRpcHandler<TParams extends RpcParamSchema<any> ? InferType<TParams> : undefined, TResponse extends RpcParamSchema<any> ? InferType<TResponse> : undefined> : RpcHandler<TParams extends RpcParamSchema<any> ? InferType<TParams> : undefined, TResponse extends RpcParamSchema<any> ? InferType<TResponse> : void>;
157
+ postHandler?: TIsEventStream extends true ? undefined : RpcPostHandler<TParams extends RpcParamSchema<any> ? InferType<TParams> : undefined, TResponse extends RpcParamSchema<any> ? InferType<TResponse> : undefined>;
220
158
  }
221
159
  interface RpcEvent<TParams = undefined> extends Omit<H3Event, 'context'> {
222
160
  context: RpcEventContext<TParams>;
@@ -230,11 +168,19 @@ declare function isRpc(input: unknown): input is HttpRpc<any, any>;
230
168
  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>;
231
169
  declare function createHttpRpcDefinition(rpcName: string, httpPath: string, procedure: HttpRpc<any, any, any>): HttpRpcDefinition;
232
170
  declare function getRpcPath(rpcName: string, prefix?: string): string;
233
- declare function getRpcParamName(rpcName: string, procedure: HttpRpc<any, any, any> | WebsocketRpc<any, any>): string | undefined;
234
- declare function getRpcResponseName(rpcName: string, procedure: HttpRpc<any, any, any> | WebsocketRpc<any, any>): string | undefined;
171
+ declare function getRpcParamName(rpcName: string, procedure: HttpRpc<any, any, any>): string | undefined;
172
+ declare function getRpcResponseName(rpcName: string, procedure: HttpRpc<any, any, any>): string | undefined;
235
173
  declare function registerRpc(router: Router, path: string, procedure: NamedHttpRpc<any, any, any>, opts: RouteOptions): void;
236
- declare function validateRpcRequestInput(event: H3Event, httpMethod: RpcHttpMethod, schema: ASchema, validator: ReturnType<typeof a.compile>): Promise<void>;
237
- declare function getSchemaValidator(rpcName: string, type: 'params' | 'response', schema: ASchema<any>): ReturnType<typeof a.compile> | undefined;
174
+ declare function validateRpcRequestInput(event: H3Event, httpMethod: RpcHttpMethod, validator: RequestValidator): Promise<void>;
175
+ type RequestValidator<T = any> = {
176
+ validate: (input: unknown) => input is T;
177
+ errors: (input: unknown) => ValueError[];
178
+ coerce: (input: unknown) => Result<T>;
179
+ parse: (input: unknown) => Result<T>;
180
+ serialize: (input: any) => Result<string>;
181
+ };
182
+ declare function getSchemaValidator<T extends Record<string, any> = any>(rpcName: string, type: 'params' | 'response', schema: RpcParamSchema<T>): RequestValidator<T> | undefined;
183
+ declare function getSchemaName(rpcName: string, type: 'params' | 'response', schema: RpcParamSchema<any>): string;
238
184
 
239
185
  declare class ArriService {
240
186
  name: string;
@@ -243,10 +189,10 @@ declare class ArriService {
243
189
  private readonly definitions;
244
190
  rpc(name: string, procedure: Rpc<any, any, any>): void;
245
191
  registerDefinitions(models: DefinitionMap): void;
246
- getProcedures(): (NamedWebsocketRpc<any, any> | NamedHttpRpc<any, any, any>)[];
192
+ getProcedures(): NamedHttpRpc<any, any, any>[];
247
193
  getDefinitions(): DefinitionMap;
248
194
  }
249
- declare function defineService(name: string, procedures?: Record<string, HttpRpc<any, any, any> | WebsocketRpc<any, any>>): ArriService;
195
+ declare function defineService(name: string, procedures?: Record<string, HttpRpc<any, any, any>>): ArriService;
250
196
 
251
197
  type DefinitionMap = Record<string, SchemaFormProperties | SchemaFormDiscriminator | SchemaFormValues>;
252
198
  declare const createAppDefinition: (def: AppDefinition) => AppDefinition;
@@ -298,4 +244,4 @@ interface RequestHookEvent extends Omit<H3Event, 'context'> {
298
244
  context: RequestHookContext;
299
245
  }
300
246
 
301
- export { ArriApp, type ArriEventContext, type ArriOptions, type ArriRoute, ArriRouter, 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, arriError, arriErrorResponse, 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 };
247
+ export { ArriApp, type ArriEventContext, type ArriOptions, type ArriRoute, ArriRouter, 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 PostRouteEvent, type RequestHookContext, type RequestHookEvent, type RequestValidator, 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, arriError, arriErrorResponse, createAppDefinition, createHttpRpcDefinition, defineError, defineEventStreamRpc, defineMiddleware, defineRoute, defineRpc, defineService, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, getSchemaName, getSchemaValidator, handleH3Error, handleRoute, isEventStreamRpc, isRpc, isRpcParamSchema, registerEventStreamRpc, registerRoute, registerRpc, validateRpcRequestInput };