@arrirpc/server 0.70.1 → 0.71.1
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/README.md +54 -52
- package/dist/index.cjs +11 -11
- package/dist/index.d.cts +16 -16
- package/dist/index.d.mts +16 -16
- package/dist/index.d.ts +16 -16
- package/dist/index.mjs +11 -11
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -2,28 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
Typescript implementation of [Arri RPC](/README.md). It's built on top of [H3](https://github.com/unjs/h3) and uses [esbuild](https://esbuild.github.io/) for bundling.
|
|
4
4
|
|
|
5
|
-
Parameters and responses are defined using [@arrirpc/schema](/
|
|
5
|
+
Parameters and responses are defined using [@arrirpc/schema](/languages/ts/ts-schema/README.md) for automatic validation and serialization of inputs and outputs and to generate Arri Type Definitions for client generators.
|
|
6
6
|
|
|
7
7
|
## Table of Contents
|
|
8
8
|
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
9
|
+
- [Quickstart](#quickstart)
|
|
10
|
+
- [Manual Setup](#manual-setup)
|
|
11
|
+
- [Install Dependencies](#install-dependencies)
|
|
12
|
+
- [Scaffold Your Project](#scaffold-your-project)
|
|
13
|
+
- [Usage](#usage)
|
|
14
|
+
- [Creating Procedures](#creating-procedures)
|
|
15
|
+
- [File-Based Routing](#file-based-routing)
|
|
16
|
+
- [Manual Routing](#manual-routing)
|
|
17
|
+
- [Creating Event Stream Procedures](#creating-event-stream-procedures)
|
|
18
|
+
- [Creating Websocket Procedures](#creating-websocket-procedures-experimental)
|
|
19
|
+
- [Adding to the RPC Context](#adding-to-the-rpc-context)
|
|
20
|
+
- [Adding Non-RPC Routes](#adding-non-rpc-routes)
|
|
21
|
+
- [Adding Middleware](#adding-middleware)
|
|
22
|
+
- [Key Concepts](#key-concepts)
|
|
23
|
+
- [Arri Definition File](#arri-definition-file)
|
|
24
|
+
- [How Procedures Map To Endpoints](#how-procedures-map-to-endpoints)
|
|
25
|
+
- [H3 Support](#h3-support)
|
|
26
|
+
- [Arri CLI](#arri-cli)
|
|
27
27
|
|
|
28
28
|
## Quickstart
|
|
29
29
|
|
|
@@ -47,10 +47,12 @@ pnpm run dev
|
|
|
47
47
|
|
|
48
48
|
```bash
|
|
49
49
|
# npm
|
|
50
|
-
npm install arri
|
|
50
|
+
npm install -D arri
|
|
51
|
+
npm install @arrirpc/server @arrirpc/schema
|
|
51
52
|
|
|
52
53
|
# pnpm
|
|
53
|
-
pnpm install arri
|
|
54
|
+
pnpm install -D arri
|
|
55
|
+
pnpm install @arrirpc/server @arrirpc/schema
|
|
54
56
|
```
|
|
55
57
|
|
|
56
58
|
### Scaffold Your Project
|
|
@@ -84,7 +86,7 @@ Create an `arri.config.ts` in the project directory
|
|
|
84
86
|
|
|
85
87
|
```ts
|
|
86
88
|
// arri.config.ts
|
|
87
|
-
import { defineConfig, servers, generators } from
|
|
89
|
+
import { defineConfig, servers, generators } from 'arri';
|
|
88
90
|
|
|
89
91
|
export default defineConfig({
|
|
90
92
|
server: servers.tsServer(),
|
|
@@ -105,7 +107,7 @@ Create an app entry file in your src directory. The name of the file must match
|
|
|
105
107
|
|
|
106
108
|
```ts
|
|
107
109
|
// ./src/app.ts
|
|
108
|
-
import { ArriApp } from
|
|
110
|
+
import { ArriApp } from 'arri';
|
|
109
111
|
|
|
110
112
|
const app = new ArriApp();
|
|
111
113
|
|
|
@@ -154,8 +156,8 @@ Example `.rpc.ts` file
|
|
|
154
156
|
|
|
155
157
|
```ts
|
|
156
158
|
// ./src/users/getUser.rpc.ts
|
|
157
|
-
import { defineRpc } from
|
|
158
|
-
import { a } from
|
|
159
|
+
import { defineRpc } from '@arrirpc/server';
|
|
160
|
+
import { a } from '@arrirpc/schema';
|
|
159
161
|
|
|
160
162
|
export default defineRpc({
|
|
161
163
|
params: a.object({
|
|
@@ -177,8 +179,8 @@ export default defineRpc({
|
|
|
177
179
|
```ts
|
|
178
180
|
export default defineConfig({
|
|
179
181
|
servers: servers.tsServer({
|
|
180
|
-
procedureDir:
|
|
181
|
-
procedureGlobPatterns: [
|
|
182
|
+
procedureDir: 'procedures', // change which directory to look for procedures (This is relative to the srcDir)
|
|
183
|
+
procedureGlobPatterns: ['**/*.rpc.ts'], // change the file name glob pattern for finding rpcs
|
|
182
184
|
}),
|
|
183
185
|
// rest of config
|
|
184
186
|
});
|
|
@@ -221,23 +223,23 @@ Event stream procedures make use of [Server Sent Events](https://developer.mozil
|
|
|
221
223
|
|
|
222
224
|
Arri Event streams sent the following event types:
|
|
223
225
|
|
|
224
|
-
-
|
|
225
|
-
-
|
|
226
|
-
-
|
|
226
|
+
- `message` - A standard message with the response data serialized as JSON
|
|
227
|
+
- `done` - A message to tell clients that there will be no more events
|
|
228
|
+
- `ping` - A message periodically sent by the server to keep the connection alive.
|
|
227
229
|
|
|
228
230
|
```ts
|
|
229
231
|
/// message event ///
|
|
230
232
|
id: string | undefined;
|
|
231
|
-
event:
|
|
233
|
+
event: 'message';
|
|
232
234
|
data: Response; // whatever you have specified as the response serialized to json
|
|
233
235
|
|
|
234
236
|
/// done event ///
|
|
235
|
-
event:
|
|
236
|
-
data:
|
|
237
|
+
event: 'done';
|
|
238
|
+
data: 'this stream has ended';
|
|
237
239
|
|
|
238
240
|
/// ping event ///
|
|
239
|
-
event:
|
|
240
|
-
data:
|
|
241
|
+
event: 'ping';
|
|
242
|
+
data: '';
|
|
241
243
|
```
|
|
242
244
|
|
|
243
245
|
##### Example Usage:
|
|
@@ -261,15 +263,15 @@ export default defineEventStreamRpc({
|
|
|
261
263
|
// send a message every second
|
|
262
264
|
const interval = setInterval(async () => {
|
|
263
265
|
await stream.push({
|
|
264
|
-
id:
|
|
265
|
-
name:
|
|
266
|
+
id: '1',
|
|
267
|
+
name: 'John Doe',
|
|
266
268
|
createdAt: new Date(),
|
|
267
269
|
updatedAt: new Date(),
|
|
268
270
|
});
|
|
269
271
|
}, 1000);
|
|
270
272
|
|
|
271
273
|
// cleanup when the client disconnects
|
|
272
|
-
stream.on(
|
|
274
|
+
stream.on('close', () => {
|
|
273
275
|
clearInterval(interval);
|
|
274
276
|
});
|
|
275
277
|
},
|
|
@@ -412,12 +414,12 @@ const authMiddleware = defineMiddleware(async (event) => {
|
|
|
412
414
|
// assume you did something to get the user from the request
|
|
413
415
|
event.context.user = {
|
|
414
416
|
id: 1,
|
|
415
|
-
name:
|
|
416
|
-
email:
|
|
417
|
+
name: 'John Doe',
|
|
418
|
+
email: 'johndoe@gmail.com',
|
|
417
419
|
};
|
|
418
420
|
});
|
|
419
421
|
|
|
420
|
-
app.rpc(
|
|
422
|
+
app.rpc('sayHello', {
|
|
421
423
|
params: undefined,
|
|
422
424
|
response: a.object({
|
|
423
425
|
message: a.string(),
|
|
@@ -434,9 +436,9 @@ app.rpc("sayHello", {
|
|
|
434
436
|
To get type safety for these new properties create a `.d.ts` file and augment the `ArriEventContext` provided by `@arrirpc/server`
|
|
435
437
|
|
|
436
438
|
```ts
|
|
437
|
-
import
|
|
439
|
+
import '@arrirpc/server';
|
|
438
440
|
|
|
439
|
-
declare module
|
|
441
|
+
declare module '@arrirpc/server' {
|
|
440
442
|
interface ArriEventContext {
|
|
441
443
|
user?: {
|
|
442
444
|
id: number;
|
|
@@ -538,18 +540,18 @@ By default all procedures will become post requests, but you can change this whe
|
|
|
538
540
|
```ts
|
|
539
541
|
// procedures/users/getUser.rpc.ts
|
|
540
542
|
export default defineRpc({
|
|
541
|
-
method:
|
|
543
|
+
method: 'get',
|
|
542
544
|
// rest of config
|
|
543
545
|
});
|
|
544
546
|
```
|
|
545
547
|
|
|
546
548
|
The supported HTTP methods are as follows:
|
|
547
549
|
|
|
548
|
-
-
|
|
549
|
-
-
|
|
550
|
-
-
|
|
551
|
-
-
|
|
552
|
-
-
|
|
550
|
+
- post
|
|
551
|
+
- get
|
|
552
|
+
- delete
|
|
553
|
+
- patch
|
|
554
|
+
- put
|
|
553
555
|
|
|
554
556
|
When using a get method the RPC params will be mapped as query parameters which will be coerced into their type using the `a.coerce` method from `arri-validate`. Get methods support all basic scalar types however arrays and nested objects are not supported.
|
|
555
557
|
|
|
@@ -562,7 +564,7 @@ Arri is built on top of [H3](https://h3.unjs.io/utils/request#getrequestipevent)
|
|
|
562
564
|
Arri re-eports all of the H3 utilities.
|
|
563
565
|
|
|
564
566
|
```ts
|
|
565
|
-
import { getRequestIP, setResponseHeader } from
|
|
567
|
+
import { getRequestIP, setResponseHeader } from '@arrirpc/server';
|
|
566
568
|
```
|
|
567
569
|
|
|
568
570
|
#### Accessing H3 Events
|
|
@@ -592,8 +594,8 @@ defineEventStreamRpc({
|
|
|
592
594
|
Arri server is just an H3 app under the hood so you can start it the same way you would start an H3 app. Although you should note that currently the filed based router only works when using the Arri CLI.
|
|
593
595
|
|
|
594
596
|
```ts
|
|
595
|
-
import { createServer } from
|
|
596
|
-
import { ArriApp, toNodeListener } from
|
|
597
|
+
import { createServer } from 'node:http';
|
|
598
|
+
import { ArriApp, toNodeListener } from '@arrirpc/server';
|
|
597
599
|
|
|
598
600
|
const app = new ArriApp();
|
|
599
601
|
|
package/dist/index.cjs
CHANGED
|
@@ -273,7 +273,7 @@ function createHttpRpcDefinition(rpcName, httpPath, procedure) {
|
|
|
273
273
|
params: getRpcParamName(rpcName, procedure),
|
|
274
274
|
response: getRpcResponseDefinition(rpcName, procedure),
|
|
275
275
|
isDeprecated: procedure.isDeprecated,
|
|
276
|
-
isEventStream: procedure.isEventStream === true ? true :
|
|
276
|
+
isEventStream: procedure.isEventStream === true ? true : undefined
|
|
277
277
|
};
|
|
278
278
|
}
|
|
279
279
|
function getRpcPath(rpcName, prefix = "") {
|
|
@@ -288,7 +288,7 @@ function getRpcPath(rpcName, prefix = "") {
|
|
|
288
288
|
}
|
|
289
289
|
function getRpcParamName(rpcName, procedure) {
|
|
290
290
|
if (!isRpcParamSchema(procedure.params)) {
|
|
291
|
-
return
|
|
291
|
+
return undefined;
|
|
292
292
|
}
|
|
293
293
|
const nameParts = rpcName.split(".").map(
|
|
294
294
|
(part) => codegenUtils.removeDisallowedChars(part, `!@#$%^&*()+=[]{}|\\;:'"<>,./?`)
|
|
@@ -298,7 +298,7 @@ function getRpcParamName(rpcName, procedure) {
|
|
|
298
298
|
}
|
|
299
299
|
function getRpcResponseName(rpcName, procedure) {
|
|
300
300
|
if (!isRpcParamSchema(procedure.response)) {
|
|
301
|
-
return
|
|
301
|
+
return undefined;
|
|
302
302
|
}
|
|
303
303
|
const nameParts = rpcName.split(".").map(
|
|
304
304
|
(part) => codegenUtils.removeDisallowedChars(part, `!@#$%^&*()+=[]{}|\\;:'"<>,./?`)
|
|
@@ -308,17 +308,17 @@ function getRpcResponseName(rpcName, procedure) {
|
|
|
308
308
|
}
|
|
309
309
|
function getRpcResponseDefinition(rpcName, procedure) {
|
|
310
310
|
if (!isRpcParamSchema(procedure.response)) {
|
|
311
|
-
return
|
|
311
|
+
return undefined;
|
|
312
312
|
}
|
|
313
313
|
const name = getRpcResponseName(rpcName, procedure);
|
|
314
314
|
if (!name) {
|
|
315
|
-
return
|
|
315
|
+
return undefined;
|
|
316
316
|
}
|
|
317
317
|
return name;
|
|
318
318
|
}
|
|
319
319
|
function registerRpc(router, path, procedure, opts) {
|
|
320
|
-
const paramValidator = procedure.params ? getSchemaValidator(procedure.name, "params", procedure.params) :
|
|
321
|
-
const responseValidator = procedure.response ? getSchemaValidator(procedure.name, "response", procedure.response) :
|
|
320
|
+
const paramValidator = procedure.params ? getSchemaValidator(procedure.name, "params", procedure.params) : undefined;
|
|
321
|
+
const responseValidator = procedure.response ? getSchemaValidator(procedure.name, "response", procedure.response) : undefined;
|
|
322
322
|
const httpMethod = procedure.method ?? "post";
|
|
323
323
|
const handler = h3.eventHandler(async (event) => {
|
|
324
324
|
event.context.rpcName = procedure.name;
|
|
@@ -469,7 +469,7 @@ function getSchemaValidator(rpcName, type, schema$1) {
|
|
|
469
469
|
return schema.a.compile(schema$1);
|
|
470
470
|
} catch (_) {
|
|
471
471
|
console.error(`Error compiling ${type} validator for ${rpcName}`);
|
|
472
|
-
return
|
|
472
|
+
return undefined;
|
|
473
473
|
}
|
|
474
474
|
}
|
|
475
475
|
|
|
@@ -490,7 +490,7 @@ class EventStreamConnection {
|
|
|
490
490
|
validator;
|
|
491
491
|
serializer;
|
|
492
492
|
// for some reason Rollup cannot output DTS when this is set to NodeJS.Timeout
|
|
493
|
-
pingInterval =
|
|
493
|
+
pingInterval = undefined;
|
|
494
494
|
pingIntervalMs;
|
|
495
495
|
eventStream;
|
|
496
496
|
constructor(event, opts) {
|
|
@@ -573,8 +573,8 @@ class EventStreamConnection {
|
|
|
573
573
|
}
|
|
574
574
|
}
|
|
575
575
|
function registerEventStreamRpc(router, path, procedure, opts) {
|
|
576
|
-
const paramValidator = procedure.params ? getSchemaValidator(procedure.name, "params", procedure.params) :
|
|
577
|
-
const responseValidator = procedure.response ? getSchemaValidator(procedure.name, "response", procedure.response) :
|
|
576
|
+
const paramValidator = procedure.params ? getSchemaValidator(procedure.name, "params", procedure.params) : undefined;
|
|
577
|
+
const responseValidator = procedure.response ? getSchemaValidator(procedure.name, "response", procedure.response) : undefined;
|
|
578
578
|
const httpMethod = procedure.method ?? "get";
|
|
579
579
|
const handler = h3.eventHandler(async (event) => {
|
|
580
580
|
event.context.rpcName = procedure.name;
|
package/dist/index.d.cts
CHANGED
|
@@ -55,9 +55,9 @@ declare const arriErrorResponse: AObjectSchema<{
|
|
|
55
55
|
data?: any;
|
|
56
56
|
}>;
|
|
57
57
|
type arriErrorResponse = a.infer<typeof arriErrorResponse>;
|
|
58
|
-
declare function defineError(statusCode: StatusCode, input?: Partial<Omit<arriErrorResponse,
|
|
59
|
-
declare function errorResponseFromValidationErrors(errors: ValidationError[
|
|
60
|
-
declare function handleH3Error(err: unknown, event: H3Event, onError: ArriOptions[
|
|
58
|
+
declare function defineError(statusCode: StatusCode, input?: Partial<Omit<arriErrorResponse, 'code' | 'stack'>>): arriError;
|
|
59
|
+
declare function errorResponseFromValidationErrors(errors: ValidationError['errors'], prefixText?: string): H3Error;
|
|
60
|
+
declare function handleH3Error(err: unknown, event: H3Event, onError: ArriOptions['onError'], debug: boolean): Promise<void>;
|
|
61
61
|
|
|
62
62
|
interface RouteEvent<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> extends H3Event {
|
|
63
63
|
context: RouteEventContext<TPath, TQuery, TBody>;
|
|
@@ -74,7 +74,7 @@ interface ArriRoute<TPath extends string, TQuery extends AObjectSchema<any, any>
|
|
|
74
74
|
postHandler?: (event: PostRouteEvent<TPath, InferType<TQuery>, InferType<TBody>, Awaited<TResponse>>) => any;
|
|
75
75
|
}
|
|
76
76
|
declare function defineRoute<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends AObjectSchema<any, any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): ArriRoute<TPath, TQuery, TBody, TResponse>;
|
|
77
|
-
type RouteOptions = Pick<ArriOptions,
|
|
77
|
+
type RouteOptions = Pick<ArriOptions, 'onAfterResponse' | 'onBeforeResponse' | 'onError' | 'onRequest' | 'debug'> & {
|
|
78
78
|
middleware: Middleware[];
|
|
79
79
|
};
|
|
80
80
|
declare function registerRoute(router: Router, route: ArriRoute<any>, opts: RouteOptions): void;
|
|
@@ -91,9 +91,9 @@ declare class ArriRouter {
|
|
|
91
91
|
getDefinitions(): DefinitionMap;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
declare function defineEventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: Omit<EventStreamRpc<TParams, TResponse>,
|
|
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>;
|
|
95
95
|
declare function isEventStreamRpc(input: unknown): input is EventStreamRpc<any, any>;
|
|
96
|
-
interface EventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends Omit<HttpRpc<true, TParams, TResponse>,
|
|
96
|
+
interface EventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends Omit<HttpRpc<true, TParams, TResponse>, 'handler' | 'postHandler'> {
|
|
97
97
|
isEventStream: true;
|
|
98
98
|
handler: EventStreamRpcHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : undefined>;
|
|
99
99
|
}
|
|
@@ -146,7 +146,7 @@ interface NamedWebsocketRpc<TParams extends RpcParamSchema | undefined = undefin
|
|
|
146
146
|
name: string;
|
|
147
147
|
}
|
|
148
148
|
interface WebsocketRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> {
|
|
149
|
-
transport:
|
|
149
|
+
transport: 'ws';
|
|
150
150
|
description?: string;
|
|
151
151
|
path?: string;
|
|
152
152
|
isDeprecated?: boolean;
|
|
@@ -189,7 +189,7 @@ interface WebSocketRpcHandler<TParams, TResponse> {
|
|
|
189
189
|
/**
|
|
190
190
|
* @experimental
|
|
191
191
|
*/
|
|
192
|
-
declare function defineWebsocketRpc<TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined>(def: Omit<WebsocketRpc<TParams, TResponse>,
|
|
192
|
+
declare function defineWebsocketRpc<TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined>(def: Omit<WebsocketRpc<TParams, TResponse>, 'transport'>): WebsocketRpc<TParams, TResponse>;
|
|
193
193
|
/**
|
|
194
194
|
* @experimental
|
|
195
195
|
*/
|
|
@@ -206,7 +206,7 @@ interface NamedHttpRpc<TIsEventStream extends boolean = false, TParams extends R
|
|
|
206
206
|
}
|
|
207
207
|
type Rpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> = HttpRpc<TIsEventStream, TParams, TResponse> | WebsocketRpc<TParams, TResponse>;
|
|
208
208
|
interface HttpRpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> {
|
|
209
|
-
transport:
|
|
209
|
+
transport: 'http';
|
|
210
210
|
method?: RpcHttpMethod;
|
|
211
211
|
path?: string;
|
|
212
212
|
description?: string;
|
|
@@ -218,23 +218,23 @@ interface HttpRpc<TIsEventStream extends boolean = false, TParams extends RpcPar
|
|
|
218
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
219
|
postHandler?: TIsEventStream extends true ? undefined : RpcPostHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : undefined>;
|
|
220
220
|
}
|
|
221
|
-
interface RpcEvent<TParams = undefined> extends Omit<H3Event,
|
|
221
|
+
interface RpcEvent<TParams = undefined> extends Omit<H3Event, 'context'> {
|
|
222
222
|
context: RpcEventContext<TParams>;
|
|
223
223
|
}
|
|
224
|
-
interface RpcPostEvent<TParams = undefined, TResponse = undefined> extends Omit<H3Event,
|
|
224
|
+
interface RpcPostEvent<TParams = undefined, TResponse = undefined> extends Omit<H3Event, 'context'> {
|
|
225
225
|
context: RpcPostEventContext<TParams, TResponse>;
|
|
226
226
|
}
|
|
227
227
|
type RpcHandler<TParams, TResponse> = (context: RpcEventContext<TParams>, event: RpcEvent<TParams>) => TResponse | Promise<TResponse>;
|
|
228
228
|
type RpcPostHandler<TParams, TResponse> = (context: RpcPostEventContext<TParams, TResponse>, event: RpcPostEvent<TParams, TResponse>) => any;
|
|
229
229
|
declare function isRpc(input: unknown): input is HttpRpc<any, any>;
|
|
230
|
-
declare function defineRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: Omit<HttpRpc<false, TParams, TResponse>,
|
|
230
|
+
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
231
|
declare function createHttpRpcDefinition(rpcName: string, httpPath: string, procedure: HttpRpc<any, any, any>): HttpRpcDefinition;
|
|
232
232
|
declare function getRpcPath(rpcName: string, prefix?: string): string;
|
|
233
233
|
declare function getRpcParamName(rpcName: string, procedure: HttpRpc<any, any, any> | WebsocketRpc<any, any>): string | undefined;
|
|
234
234
|
declare function getRpcResponseName(rpcName: string, procedure: HttpRpc<any, any, any> | WebsocketRpc<any, any>): string | undefined;
|
|
235
235
|
declare function registerRpc(router: Router, path: string, procedure: NamedHttpRpc<any, any, any>, opts: RouteOptions): void;
|
|
236
236
|
declare function validateRpcRequestInput(event: H3Event, httpMethod: RpcHttpMethod, schema: ASchema, validator: ReturnType<typeof a.compile>): Promise<void>;
|
|
237
|
-
declare function getSchemaValidator(rpcName: string, type:
|
|
237
|
+
declare function getSchemaValidator(rpcName: string, type: 'params' | 'response', schema: ASchema<any>): ReturnType<typeof a.compile> | undefined;
|
|
238
238
|
|
|
239
239
|
declare class ArriService {
|
|
240
240
|
name: string;
|
|
@@ -256,7 +256,7 @@ declare class ArriApp {
|
|
|
256
256
|
readonly h3Router: Router;
|
|
257
257
|
private readonly _rpcDefinitionPath;
|
|
258
258
|
private readonly _rpcRoutePrefix;
|
|
259
|
-
appInfo: AppDefinition[
|
|
259
|
+
appInfo: AppDefinition['info'];
|
|
260
260
|
private _procedures;
|
|
261
261
|
private _definitions;
|
|
262
262
|
private readonly _middlewares;
|
|
@@ -280,7 +280,7 @@ interface ArriOptions {
|
|
|
280
280
|
/**
|
|
281
281
|
* Metadata to display in the __definition.json file
|
|
282
282
|
*/
|
|
283
|
-
appInfo?: AppDefinition[
|
|
283
|
+
appInfo?: AppDefinition['info'];
|
|
284
284
|
rpcRoutePrefix?: string;
|
|
285
285
|
/**
|
|
286
286
|
* Defaults to /__definitions
|
|
@@ -294,7 +294,7 @@ interface ArriOptions {
|
|
|
294
294
|
onBeforeResponse?: (event: RequestHookEvent) => void | Promise<void>;
|
|
295
295
|
onError?: (error: arriError, event: RequestHookEvent) => void | Promise<void>;
|
|
296
296
|
}
|
|
297
|
-
interface RequestHookEvent extends Omit<H3Event,
|
|
297
|
+
interface RequestHookEvent extends Omit<H3Event, 'context'> {
|
|
298
298
|
context: RequestHookContext;
|
|
299
299
|
}
|
|
300
300
|
|
package/dist/index.d.mts
CHANGED
|
@@ -55,9 +55,9 @@ declare const arriErrorResponse: AObjectSchema<{
|
|
|
55
55
|
data?: any;
|
|
56
56
|
}>;
|
|
57
57
|
type arriErrorResponse = a.infer<typeof arriErrorResponse>;
|
|
58
|
-
declare function defineError(statusCode: StatusCode, input?: Partial<Omit<arriErrorResponse,
|
|
59
|
-
declare function errorResponseFromValidationErrors(errors: ValidationError[
|
|
60
|
-
declare function handleH3Error(err: unknown, event: H3Event, onError: ArriOptions[
|
|
58
|
+
declare function defineError(statusCode: StatusCode, input?: Partial<Omit<arriErrorResponse, 'code' | 'stack'>>): arriError;
|
|
59
|
+
declare function errorResponseFromValidationErrors(errors: ValidationError['errors'], prefixText?: string): H3Error;
|
|
60
|
+
declare function handleH3Error(err: unknown, event: H3Event, onError: ArriOptions['onError'], debug: boolean): Promise<void>;
|
|
61
61
|
|
|
62
62
|
interface RouteEvent<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> extends H3Event {
|
|
63
63
|
context: RouteEventContext<TPath, TQuery, TBody>;
|
|
@@ -74,7 +74,7 @@ interface ArriRoute<TPath extends string, TQuery extends AObjectSchema<any, any>
|
|
|
74
74
|
postHandler?: (event: PostRouteEvent<TPath, InferType<TQuery>, InferType<TBody>, Awaited<TResponse>>) => any;
|
|
75
75
|
}
|
|
76
76
|
declare function defineRoute<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends AObjectSchema<any, any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): ArriRoute<TPath, TQuery, TBody, TResponse>;
|
|
77
|
-
type RouteOptions = Pick<ArriOptions,
|
|
77
|
+
type RouteOptions = Pick<ArriOptions, 'onAfterResponse' | 'onBeforeResponse' | 'onError' | 'onRequest' | 'debug'> & {
|
|
78
78
|
middleware: Middleware[];
|
|
79
79
|
};
|
|
80
80
|
declare function registerRoute(router: Router, route: ArriRoute<any>, opts: RouteOptions): void;
|
|
@@ -91,9 +91,9 @@ declare class ArriRouter {
|
|
|
91
91
|
getDefinitions(): DefinitionMap;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
declare function defineEventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: Omit<EventStreamRpc<TParams, TResponse>,
|
|
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>;
|
|
95
95
|
declare function isEventStreamRpc(input: unknown): input is EventStreamRpc<any, any>;
|
|
96
|
-
interface EventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends Omit<HttpRpc<true, TParams, TResponse>,
|
|
96
|
+
interface EventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends Omit<HttpRpc<true, TParams, TResponse>, 'handler' | 'postHandler'> {
|
|
97
97
|
isEventStream: true;
|
|
98
98
|
handler: EventStreamRpcHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : undefined>;
|
|
99
99
|
}
|
|
@@ -146,7 +146,7 @@ interface NamedWebsocketRpc<TParams extends RpcParamSchema | undefined = undefin
|
|
|
146
146
|
name: string;
|
|
147
147
|
}
|
|
148
148
|
interface WebsocketRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> {
|
|
149
|
-
transport:
|
|
149
|
+
transport: 'ws';
|
|
150
150
|
description?: string;
|
|
151
151
|
path?: string;
|
|
152
152
|
isDeprecated?: boolean;
|
|
@@ -189,7 +189,7 @@ interface WebSocketRpcHandler<TParams, TResponse> {
|
|
|
189
189
|
/**
|
|
190
190
|
* @experimental
|
|
191
191
|
*/
|
|
192
|
-
declare function defineWebsocketRpc<TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined>(def: Omit<WebsocketRpc<TParams, TResponse>,
|
|
192
|
+
declare function defineWebsocketRpc<TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined>(def: Omit<WebsocketRpc<TParams, TResponse>, 'transport'>): WebsocketRpc<TParams, TResponse>;
|
|
193
193
|
/**
|
|
194
194
|
* @experimental
|
|
195
195
|
*/
|
|
@@ -206,7 +206,7 @@ interface NamedHttpRpc<TIsEventStream extends boolean = false, TParams extends R
|
|
|
206
206
|
}
|
|
207
207
|
type Rpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> = HttpRpc<TIsEventStream, TParams, TResponse> | WebsocketRpc<TParams, TResponse>;
|
|
208
208
|
interface HttpRpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> {
|
|
209
|
-
transport:
|
|
209
|
+
transport: 'http';
|
|
210
210
|
method?: RpcHttpMethod;
|
|
211
211
|
path?: string;
|
|
212
212
|
description?: string;
|
|
@@ -218,23 +218,23 @@ interface HttpRpc<TIsEventStream extends boolean = false, TParams extends RpcPar
|
|
|
218
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
219
|
postHandler?: TIsEventStream extends true ? undefined : RpcPostHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : undefined>;
|
|
220
220
|
}
|
|
221
|
-
interface RpcEvent<TParams = undefined> extends Omit<H3Event,
|
|
221
|
+
interface RpcEvent<TParams = undefined> extends Omit<H3Event, 'context'> {
|
|
222
222
|
context: RpcEventContext<TParams>;
|
|
223
223
|
}
|
|
224
|
-
interface RpcPostEvent<TParams = undefined, TResponse = undefined> extends Omit<H3Event,
|
|
224
|
+
interface RpcPostEvent<TParams = undefined, TResponse = undefined> extends Omit<H3Event, 'context'> {
|
|
225
225
|
context: RpcPostEventContext<TParams, TResponse>;
|
|
226
226
|
}
|
|
227
227
|
type RpcHandler<TParams, TResponse> = (context: RpcEventContext<TParams>, event: RpcEvent<TParams>) => TResponse | Promise<TResponse>;
|
|
228
228
|
type RpcPostHandler<TParams, TResponse> = (context: RpcPostEventContext<TParams, TResponse>, event: RpcPostEvent<TParams, TResponse>) => any;
|
|
229
229
|
declare function isRpc(input: unknown): input is HttpRpc<any, any>;
|
|
230
|
-
declare function defineRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: Omit<HttpRpc<false, TParams, TResponse>,
|
|
230
|
+
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
231
|
declare function createHttpRpcDefinition(rpcName: string, httpPath: string, procedure: HttpRpc<any, any, any>): HttpRpcDefinition;
|
|
232
232
|
declare function getRpcPath(rpcName: string, prefix?: string): string;
|
|
233
233
|
declare function getRpcParamName(rpcName: string, procedure: HttpRpc<any, any, any> | WebsocketRpc<any, any>): string | undefined;
|
|
234
234
|
declare function getRpcResponseName(rpcName: string, procedure: HttpRpc<any, any, any> | WebsocketRpc<any, any>): string | undefined;
|
|
235
235
|
declare function registerRpc(router: Router, path: string, procedure: NamedHttpRpc<any, any, any>, opts: RouteOptions): void;
|
|
236
236
|
declare function validateRpcRequestInput(event: H3Event, httpMethod: RpcHttpMethod, schema: ASchema, validator: ReturnType<typeof a.compile>): Promise<void>;
|
|
237
|
-
declare function getSchemaValidator(rpcName: string, type:
|
|
237
|
+
declare function getSchemaValidator(rpcName: string, type: 'params' | 'response', schema: ASchema<any>): ReturnType<typeof a.compile> | undefined;
|
|
238
238
|
|
|
239
239
|
declare class ArriService {
|
|
240
240
|
name: string;
|
|
@@ -256,7 +256,7 @@ declare class ArriApp {
|
|
|
256
256
|
readonly h3Router: Router;
|
|
257
257
|
private readonly _rpcDefinitionPath;
|
|
258
258
|
private readonly _rpcRoutePrefix;
|
|
259
|
-
appInfo: AppDefinition[
|
|
259
|
+
appInfo: AppDefinition['info'];
|
|
260
260
|
private _procedures;
|
|
261
261
|
private _definitions;
|
|
262
262
|
private readonly _middlewares;
|
|
@@ -280,7 +280,7 @@ interface ArriOptions {
|
|
|
280
280
|
/**
|
|
281
281
|
* Metadata to display in the __definition.json file
|
|
282
282
|
*/
|
|
283
|
-
appInfo?: AppDefinition[
|
|
283
|
+
appInfo?: AppDefinition['info'];
|
|
284
284
|
rpcRoutePrefix?: string;
|
|
285
285
|
/**
|
|
286
286
|
* Defaults to /__definitions
|
|
@@ -294,7 +294,7 @@ interface ArriOptions {
|
|
|
294
294
|
onBeforeResponse?: (event: RequestHookEvent) => void | Promise<void>;
|
|
295
295
|
onError?: (error: arriError, event: RequestHookEvent) => void | Promise<void>;
|
|
296
296
|
}
|
|
297
|
-
interface RequestHookEvent extends Omit<H3Event,
|
|
297
|
+
interface RequestHookEvent extends Omit<H3Event, 'context'> {
|
|
298
298
|
context: RequestHookContext;
|
|
299
299
|
}
|
|
300
300
|
|
package/dist/index.d.ts
CHANGED
|
@@ -55,9 +55,9 @@ declare const arriErrorResponse: AObjectSchema<{
|
|
|
55
55
|
data?: any;
|
|
56
56
|
}>;
|
|
57
57
|
type arriErrorResponse = a.infer<typeof arriErrorResponse>;
|
|
58
|
-
declare function defineError(statusCode: StatusCode, input?: Partial<Omit<arriErrorResponse,
|
|
59
|
-
declare function errorResponseFromValidationErrors(errors: ValidationError[
|
|
60
|
-
declare function handleH3Error(err: unknown, event: H3Event, onError: ArriOptions[
|
|
58
|
+
declare function defineError(statusCode: StatusCode, input?: Partial<Omit<arriErrorResponse, 'code' | 'stack'>>): arriError;
|
|
59
|
+
declare function errorResponseFromValidationErrors(errors: ValidationError['errors'], prefixText?: string): H3Error;
|
|
60
|
+
declare function handleH3Error(err: unknown, event: H3Event, onError: ArriOptions['onError'], debug: boolean): Promise<void>;
|
|
61
61
|
|
|
62
62
|
interface RouteEvent<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> extends H3Event {
|
|
63
63
|
context: RouteEventContext<TPath, TQuery, TBody>;
|
|
@@ -74,7 +74,7 @@ interface ArriRoute<TPath extends string, TQuery extends AObjectSchema<any, any>
|
|
|
74
74
|
postHandler?: (event: PostRouteEvent<TPath, InferType<TQuery>, InferType<TBody>, Awaited<TResponse>>) => any;
|
|
75
75
|
}
|
|
76
76
|
declare function defineRoute<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends AObjectSchema<any, any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): ArriRoute<TPath, TQuery, TBody, TResponse>;
|
|
77
|
-
type RouteOptions = Pick<ArriOptions,
|
|
77
|
+
type RouteOptions = Pick<ArriOptions, 'onAfterResponse' | 'onBeforeResponse' | 'onError' | 'onRequest' | 'debug'> & {
|
|
78
78
|
middleware: Middleware[];
|
|
79
79
|
};
|
|
80
80
|
declare function registerRoute(router: Router, route: ArriRoute<any>, opts: RouteOptions): void;
|
|
@@ -91,9 +91,9 @@ declare class ArriRouter {
|
|
|
91
91
|
getDefinitions(): DefinitionMap;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
declare function defineEventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: Omit<EventStreamRpc<TParams, TResponse>,
|
|
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>;
|
|
95
95
|
declare function isEventStreamRpc(input: unknown): input is EventStreamRpc<any, any>;
|
|
96
|
-
interface EventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends Omit<HttpRpc<true, TParams, TResponse>,
|
|
96
|
+
interface EventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends Omit<HttpRpc<true, TParams, TResponse>, 'handler' | 'postHandler'> {
|
|
97
97
|
isEventStream: true;
|
|
98
98
|
handler: EventStreamRpcHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : undefined>;
|
|
99
99
|
}
|
|
@@ -146,7 +146,7 @@ interface NamedWebsocketRpc<TParams extends RpcParamSchema | undefined = undefin
|
|
|
146
146
|
name: string;
|
|
147
147
|
}
|
|
148
148
|
interface WebsocketRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> {
|
|
149
|
-
transport:
|
|
149
|
+
transport: 'ws';
|
|
150
150
|
description?: string;
|
|
151
151
|
path?: string;
|
|
152
152
|
isDeprecated?: boolean;
|
|
@@ -189,7 +189,7 @@ interface WebSocketRpcHandler<TParams, TResponse> {
|
|
|
189
189
|
/**
|
|
190
190
|
* @experimental
|
|
191
191
|
*/
|
|
192
|
-
declare function defineWebsocketRpc<TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined>(def: Omit<WebsocketRpc<TParams, TResponse>,
|
|
192
|
+
declare function defineWebsocketRpc<TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined>(def: Omit<WebsocketRpc<TParams, TResponse>, 'transport'>): WebsocketRpc<TParams, TResponse>;
|
|
193
193
|
/**
|
|
194
194
|
* @experimental
|
|
195
195
|
*/
|
|
@@ -206,7 +206,7 @@ interface NamedHttpRpc<TIsEventStream extends boolean = false, TParams extends R
|
|
|
206
206
|
}
|
|
207
207
|
type Rpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> = HttpRpc<TIsEventStream, TParams, TResponse> | WebsocketRpc<TParams, TResponse>;
|
|
208
208
|
interface HttpRpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> {
|
|
209
|
-
transport:
|
|
209
|
+
transport: 'http';
|
|
210
210
|
method?: RpcHttpMethod;
|
|
211
211
|
path?: string;
|
|
212
212
|
description?: string;
|
|
@@ -218,23 +218,23 @@ interface HttpRpc<TIsEventStream extends boolean = false, TParams extends RpcPar
|
|
|
218
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
219
|
postHandler?: TIsEventStream extends true ? undefined : RpcPostHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : undefined>;
|
|
220
220
|
}
|
|
221
|
-
interface RpcEvent<TParams = undefined> extends Omit<H3Event,
|
|
221
|
+
interface RpcEvent<TParams = undefined> extends Omit<H3Event, 'context'> {
|
|
222
222
|
context: RpcEventContext<TParams>;
|
|
223
223
|
}
|
|
224
|
-
interface RpcPostEvent<TParams = undefined, TResponse = undefined> extends Omit<H3Event,
|
|
224
|
+
interface RpcPostEvent<TParams = undefined, TResponse = undefined> extends Omit<H3Event, 'context'> {
|
|
225
225
|
context: RpcPostEventContext<TParams, TResponse>;
|
|
226
226
|
}
|
|
227
227
|
type RpcHandler<TParams, TResponse> = (context: RpcEventContext<TParams>, event: RpcEvent<TParams>) => TResponse | Promise<TResponse>;
|
|
228
228
|
type RpcPostHandler<TParams, TResponse> = (context: RpcPostEventContext<TParams, TResponse>, event: RpcPostEvent<TParams, TResponse>) => any;
|
|
229
229
|
declare function isRpc(input: unknown): input is HttpRpc<any, any>;
|
|
230
|
-
declare function defineRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: Omit<HttpRpc<false, TParams, TResponse>,
|
|
230
|
+
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
231
|
declare function createHttpRpcDefinition(rpcName: string, httpPath: string, procedure: HttpRpc<any, any, any>): HttpRpcDefinition;
|
|
232
232
|
declare function getRpcPath(rpcName: string, prefix?: string): string;
|
|
233
233
|
declare function getRpcParamName(rpcName: string, procedure: HttpRpc<any, any, any> | WebsocketRpc<any, any>): string | undefined;
|
|
234
234
|
declare function getRpcResponseName(rpcName: string, procedure: HttpRpc<any, any, any> | WebsocketRpc<any, any>): string | undefined;
|
|
235
235
|
declare function registerRpc(router: Router, path: string, procedure: NamedHttpRpc<any, any, any>, opts: RouteOptions): void;
|
|
236
236
|
declare function validateRpcRequestInput(event: H3Event, httpMethod: RpcHttpMethod, schema: ASchema, validator: ReturnType<typeof a.compile>): Promise<void>;
|
|
237
|
-
declare function getSchemaValidator(rpcName: string, type:
|
|
237
|
+
declare function getSchemaValidator(rpcName: string, type: 'params' | 'response', schema: ASchema<any>): ReturnType<typeof a.compile> | undefined;
|
|
238
238
|
|
|
239
239
|
declare class ArriService {
|
|
240
240
|
name: string;
|
|
@@ -256,7 +256,7 @@ declare class ArriApp {
|
|
|
256
256
|
readonly h3Router: Router;
|
|
257
257
|
private readonly _rpcDefinitionPath;
|
|
258
258
|
private readonly _rpcRoutePrefix;
|
|
259
|
-
appInfo: AppDefinition[
|
|
259
|
+
appInfo: AppDefinition['info'];
|
|
260
260
|
private _procedures;
|
|
261
261
|
private _definitions;
|
|
262
262
|
private readonly _middlewares;
|
|
@@ -280,7 +280,7 @@ interface ArriOptions {
|
|
|
280
280
|
/**
|
|
281
281
|
* Metadata to display in the __definition.json file
|
|
282
282
|
*/
|
|
283
|
-
appInfo?: AppDefinition[
|
|
283
|
+
appInfo?: AppDefinition['info'];
|
|
284
284
|
rpcRoutePrefix?: string;
|
|
285
285
|
/**
|
|
286
286
|
* Defaults to /__definitions
|
|
@@ -294,7 +294,7 @@ interface ArriOptions {
|
|
|
294
294
|
onBeforeResponse?: (event: RequestHookEvent) => void | Promise<void>;
|
|
295
295
|
onError?: (error: arriError, event: RequestHookEvent) => void | Promise<void>;
|
|
296
296
|
}
|
|
297
|
-
interface RequestHookEvent extends Omit<H3Event,
|
|
297
|
+
interface RequestHookEvent extends Omit<H3Event, 'context'> {
|
|
298
298
|
context: RequestHookContext;
|
|
299
299
|
}
|
|
300
300
|
|
package/dist/index.mjs
CHANGED
|
@@ -272,7 +272,7 @@ function createHttpRpcDefinition(rpcName, httpPath, procedure) {
|
|
|
272
272
|
params: getRpcParamName(rpcName, procedure),
|
|
273
273
|
response: getRpcResponseDefinition(rpcName, procedure),
|
|
274
274
|
isDeprecated: procedure.isDeprecated,
|
|
275
|
-
isEventStream: procedure.isEventStream === true ? true :
|
|
275
|
+
isEventStream: procedure.isEventStream === true ? true : undefined
|
|
276
276
|
};
|
|
277
277
|
}
|
|
278
278
|
function getRpcPath(rpcName, prefix = "") {
|
|
@@ -287,7 +287,7 @@ function getRpcPath(rpcName, prefix = "") {
|
|
|
287
287
|
}
|
|
288
288
|
function getRpcParamName(rpcName, procedure) {
|
|
289
289
|
if (!isRpcParamSchema(procedure.params)) {
|
|
290
|
-
return
|
|
290
|
+
return undefined;
|
|
291
291
|
}
|
|
292
292
|
const nameParts = rpcName.split(".").map(
|
|
293
293
|
(part) => removeDisallowedChars(part, `!@#$%^&*()+=[]{}|\\;:'"<>,./?`)
|
|
@@ -297,7 +297,7 @@ function getRpcParamName(rpcName, procedure) {
|
|
|
297
297
|
}
|
|
298
298
|
function getRpcResponseName(rpcName, procedure) {
|
|
299
299
|
if (!isRpcParamSchema(procedure.response)) {
|
|
300
|
-
return
|
|
300
|
+
return undefined;
|
|
301
301
|
}
|
|
302
302
|
const nameParts = rpcName.split(".").map(
|
|
303
303
|
(part) => removeDisallowedChars(part, `!@#$%^&*()+=[]{}|\\;:'"<>,./?`)
|
|
@@ -307,17 +307,17 @@ function getRpcResponseName(rpcName, procedure) {
|
|
|
307
307
|
}
|
|
308
308
|
function getRpcResponseDefinition(rpcName, procedure) {
|
|
309
309
|
if (!isRpcParamSchema(procedure.response)) {
|
|
310
|
-
return
|
|
310
|
+
return undefined;
|
|
311
311
|
}
|
|
312
312
|
const name = getRpcResponseName(rpcName, procedure);
|
|
313
313
|
if (!name) {
|
|
314
|
-
return
|
|
314
|
+
return undefined;
|
|
315
315
|
}
|
|
316
316
|
return name;
|
|
317
317
|
}
|
|
318
318
|
function registerRpc(router, path, procedure, opts) {
|
|
319
|
-
const paramValidator = procedure.params ? getSchemaValidator(procedure.name, "params", procedure.params) :
|
|
320
|
-
const responseValidator = procedure.response ? getSchemaValidator(procedure.name, "response", procedure.response) :
|
|
319
|
+
const paramValidator = procedure.params ? getSchemaValidator(procedure.name, "params", procedure.params) : undefined;
|
|
320
|
+
const responseValidator = procedure.response ? getSchemaValidator(procedure.name, "response", procedure.response) : undefined;
|
|
321
321
|
const httpMethod = procedure.method ?? "post";
|
|
322
322
|
const handler = eventHandler(async (event) => {
|
|
323
323
|
event.context.rpcName = procedure.name;
|
|
@@ -468,7 +468,7 @@ function getSchemaValidator(rpcName, type, schema) {
|
|
|
468
468
|
return a.compile(schema);
|
|
469
469
|
} catch (_) {
|
|
470
470
|
console.error(`Error compiling ${type} validator for ${rpcName}`);
|
|
471
|
-
return
|
|
471
|
+
return undefined;
|
|
472
472
|
}
|
|
473
473
|
}
|
|
474
474
|
|
|
@@ -489,7 +489,7 @@ class EventStreamConnection {
|
|
|
489
489
|
validator;
|
|
490
490
|
serializer;
|
|
491
491
|
// for some reason Rollup cannot output DTS when this is set to NodeJS.Timeout
|
|
492
|
-
pingInterval =
|
|
492
|
+
pingInterval = undefined;
|
|
493
493
|
pingIntervalMs;
|
|
494
494
|
eventStream;
|
|
495
495
|
constructor(event, opts) {
|
|
@@ -572,8 +572,8 @@ class EventStreamConnection {
|
|
|
572
572
|
}
|
|
573
573
|
}
|
|
574
574
|
function registerEventStreamRpc(router, path, procedure, opts) {
|
|
575
|
-
const paramValidator = procedure.params ? getSchemaValidator(procedure.name, "params", procedure.params) :
|
|
576
|
-
const responseValidator = procedure.response ? getSchemaValidator(procedure.name, "response", procedure.response) :
|
|
575
|
+
const paramValidator = procedure.params ? getSchemaValidator(procedure.name, "params", procedure.params) : undefined;
|
|
576
|
+
const responseValidator = procedure.response ? getSchemaValidator(procedure.name, "response", procedure.response) : undefined;
|
|
577
577
|
const httpMethod = procedure.method ?? "get";
|
|
578
578
|
const handler = eventHandler(async (event) => {
|
|
579
579
|
event.context.rpcName = procedure.name;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arrirpc/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.71.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -24,15 +24,15 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@types/source-map-support": "^0.5.10",
|
|
26
26
|
"crossws": "^0.3.1",
|
|
27
|
-
"h3": "^1.13.
|
|
27
|
+
"h3": "^1.13.1",
|
|
28
28
|
"scule": "^1.3.0",
|
|
29
29
|
"source-map-support": "^0.5.21",
|
|
30
30
|
"uncrypto": "^0.1.3",
|
|
31
|
-
"@arrirpc/codegen-utils": "0.
|
|
32
|
-
"arri": "0.
|
|
33
|
-
"@arrirpc/schema": "0.
|
|
31
|
+
"@arrirpc/codegen-utils": "0.71.1",
|
|
32
|
+
"arri": "0.71.1",
|
|
33
|
+
"@arrirpc/schema": "0.71.1"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"bun-types": "^1.1.
|
|
36
|
+
"bun-types": "^1.1.43"
|
|
37
37
|
}
|
|
38
38
|
}
|