@arrirpc/server 0.70.1 → 0.71.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/README.md +62 -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,36 @@
|
|
|
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
|
+
|
|
7
|
+
## Related Libraries
|
|
8
|
+
|
|
9
|
+
| Name | Description |
|
|
10
|
+
| --------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
11
|
+
| [arri](/tooling/cli/README.md) | The Arri CLI |
|
|
12
|
+
| [@arrirpc/schema](/languages/ts/ts-schema/README.md) | High performance validation library used to define the inputs and outputs of procedures. Can also be used standalone as a generic TS validation library. |
|
|
13
|
+
| [@arrirpc/eslint-plugin](/languages/ts/eslint-plugin/README.md) | Eslint rules for Arri RPC |
|
|
6
14
|
|
|
7
15
|
## Table of Contents
|
|
8
16
|
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
17
|
+
- [Quickstart](#quickstart)
|
|
18
|
+
- [Manual Setup](#manual-setup)
|
|
19
|
+
- [Install Dependencies](#install-dependencies)
|
|
20
|
+
- [Scaffold Your Project](#scaffold-your-project)
|
|
21
|
+
- [Usage](#usage)
|
|
22
|
+
- [Creating Procedures](#creating-procedures)
|
|
23
|
+
- [File-Based Routing](#file-based-routing)
|
|
24
|
+
- [Manual Routing](#manual-routing)
|
|
25
|
+
- [Creating Event Stream Procedures](#creating-event-stream-procedures)
|
|
26
|
+
- [Creating Websocket Procedures](#creating-websocket-procedures-experimental)
|
|
27
|
+
- [Adding to the RPC Context](#adding-to-the-rpc-context)
|
|
28
|
+
- [Adding Non-RPC Routes](#adding-non-rpc-routes)
|
|
29
|
+
- [Adding Middleware](#adding-middleware)
|
|
30
|
+
- [Key Concepts](#key-concepts)
|
|
31
|
+
- [Arri Definition File](#arri-definition-file)
|
|
32
|
+
- [How Procedures Map To Endpoints](#how-procedures-map-to-endpoints)
|
|
33
|
+
- [H3 Support](#h3-support)
|
|
34
|
+
- [Arri CLI](#arri-cli)
|
|
27
35
|
|
|
28
36
|
## Quickstart
|
|
29
37
|
|
|
@@ -47,10 +55,12 @@ pnpm run dev
|
|
|
47
55
|
|
|
48
56
|
```bash
|
|
49
57
|
# npm
|
|
50
|
-
npm install arri
|
|
58
|
+
npm install -D arri
|
|
59
|
+
npm install @arrirpc/server @arrirpc/schema
|
|
51
60
|
|
|
52
61
|
# pnpm
|
|
53
|
-
pnpm install arri
|
|
62
|
+
pnpm install -D arri
|
|
63
|
+
pnpm install @arrirpc/server @arrirpc/schema
|
|
54
64
|
```
|
|
55
65
|
|
|
56
66
|
### Scaffold Your Project
|
|
@@ -84,7 +94,7 @@ Create an `arri.config.ts` in the project directory
|
|
|
84
94
|
|
|
85
95
|
```ts
|
|
86
96
|
// arri.config.ts
|
|
87
|
-
import { defineConfig, servers, generators } from
|
|
97
|
+
import { defineConfig, servers, generators } from 'arri';
|
|
88
98
|
|
|
89
99
|
export default defineConfig({
|
|
90
100
|
server: servers.tsServer(),
|
|
@@ -105,7 +115,7 @@ Create an app entry file in your src directory. The name of the file must match
|
|
|
105
115
|
|
|
106
116
|
```ts
|
|
107
117
|
// ./src/app.ts
|
|
108
|
-
import { ArriApp } from
|
|
118
|
+
import { ArriApp } from 'arri';
|
|
109
119
|
|
|
110
120
|
const app = new ArriApp();
|
|
111
121
|
|
|
@@ -154,8 +164,8 @@ Example `.rpc.ts` file
|
|
|
154
164
|
|
|
155
165
|
```ts
|
|
156
166
|
// ./src/users/getUser.rpc.ts
|
|
157
|
-
import { defineRpc } from
|
|
158
|
-
import { a } from
|
|
167
|
+
import { defineRpc } from '@arrirpc/server';
|
|
168
|
+
import { a } from '@arrirpc/schema';
|
|
159
169
|
|
|
160
170
|
export default defineRpc({
|
|
161
171
|
params: a.object({
|
|
@@ -177,8 +187,8 @@ export default defineRpc({
|
|
|
177
187
|
```ts
|
|
178
188
|
export default defineConfig({
|
|
179
189
|
servers: servers.tsServer({
|
|
180
|
-
procedureDir:
|
|
181
|
-
procedureGlobPatterns: [
|
|
190
|
+
procedureDir: 'procedures', // change which directory to look for procedures (This is relative to the srcDir)
|
|
191
|
+
procedureGlobPatterns: ['**/*.rpc.ts'], // change the file name glob pattern for finding rpcs
|
|
182
192
|
}),
|
|
183
193
|
// rest of config
|
|
184
194
|
});
|
|
@@ -221,23 +231,23 @@ Event stream procedures make use of [Server Sent Events](https://developer.mozil
|
|
|
221
231
|
|
|
222
232
|
Arri Event streams sent the following event types:
|
|
223
233
|
|
|
224
|
-
-
|
|
225
|
-
-
|
|
226
|
-
-
|
|
234
|
+
- `message` - A standard message with the response data serialized as JSON
|
|
235
|
+
- `done` - A message to tell clients that there will be no more events
|
|
236
|
+
- `ping` - A message periodically sent by the server to keep the connection alive.
|
|
227
237
|
|
|
228
238
|
```ts
|
|
229
239
|
/// message event ///
|
|
230
240
|
id: string | undefined;
|
|
231
|
-
event:
|
|
241
|
+
event: 'message';
|
|
232
242
|
data: Response; // whatever you have specified as the response serialized to json
|
|
233
243
|
|
|
234
244
|
/// done event ///
|
|
235
|
-
event:
|
|
236
|
-
data:
|
|
245
|
+
event: 'done';
|
|
246
|
+
data: 'this stream has ended';
|
|
237
247
|
|
|
238
248
|
/// ping event ///
|
|
239
|
-
event:
|
|
240
|
-
data:
|
|
249
|
+
event: 'ping';
|
|
250
|
+
data: '';
|
|
241
251
|
```
|
|
242
252
|
|
|
243
253
|
##### Example Usage:
|
|
@@ -261,15 +271,15 @@ export default defineEventStreamRpc({
|
|
|
261
271
|
// send a message every second
|
|
262
272
|
const interval = setInterval(async () => {
|
|
263
273
|
await stream.push({
|
|
264
|
-
id:
|
|
265
|
-
name:
|
|
274
|
+
id: '1',
|
|
275
|
+
name: 'John Doe',
|
|
266
276
|
createdAt: new Date(),
|
|
267
277
|
updatedAt: new Date(),
|
|
268
278
|
});
|
|
269
279
|
}, 1000);
|
|
270
280
|
|
|
271
281
|
// cleanup when the client disconnects
|
|
272
|
-
stream.on(
|
|
282
|
+
stream.on('close', () => {
|
|
273
283
|
clearInterval(interval);
|
|
274
284
|
});
|
|
275
285
|
},
|
|
@@ -412,12 +422,12 @@ const authMiddleware = defineMiddleware(async (event) => {
|
|
|
412
422
|
// assume you did something to get the user from the request
|
|
413
423
|
event.context.user = {
|
|
414
424
|
id: 1,
|
|
415
|
-
name:
|
|
416
|
-
email:
|
|
425
|
+
name: 'John Doe',
|
|
426
|
+
email: 'johndoe@gmail.com',
|
|
417
427
|
};
|
|
418
428
|
});
|
|
419
429
|
|
|
420
|
-
app.rpc(
|
|
430
|
+
app.rpc('sayHello', {
|
|
421
431
|
params: undefined,
|
|
422
432
|
response: a.object({
|
|
423
433
|
message: a.string(),
|
|
@@ -434,9 +444,9 @@ app.rpc("sayHello", {
|
|
|
434
444
|
To get type safety for these new properties create a `.d.ts` file and augment the `ArriEventContext` provided by `@arrirpc/server`
|
|
435
445
|
|
|
436
446
|
```ts
|
|
437
|
-
import
|
|
447
|
+
import '@arrirpc/server';
|
|
438
448
|
|
|
439
|
-
declare module
|
|
449
|
+
declare module '@arrirpc/server' {
|
|
440
450
|
interface ArriEventContext {
|
|
441
451
|
user?: {
|
|
442
452
|
id: number;
|
|
@@ -538,18 +548,18 @@ By default all procedures will become post requests, but you can change this whe
|
|
|
538
548
|
```ts
|
|
539
549
|
// procedures/users/getUser.rpc.ts
|
|
540
550
|
export default defineRpc({
|
|
541
|
-
method:
|
|
551
|
+
method: 'get',
|
|
542
552
|
// rest of config
|
|
543
553
|
});
|
|
544
554
|
```
|
|
545
555
|
|
|
546
556
|
The supported HTTP methods are as follows:
|
|
547
557
|
|
|
548
|
-
-
|
|
549
|
-
-
|
|
550
|
-
-
|
|
551
|
-
-
|
|
552
|
-
-
|
|
558
|
+
- post
|
|
559
|
+
- get
|
|
560
|
+
- delete
|
|
561
|
+
- patch
|
|
562
|
+
- put
|
|
553
563
|
|
|
554
564
|
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
565
|
|
|
@@ -562,7 +572,7 @@ Arri is built on top of [H3](https://h3.unjs.io/utils/request#getrequestipevent)
|
|
|
562
572
|
Arri re-eports all of the H3 utilities.
|
|
563
573
|
|
|
564
574
|
```ts
|
|
565
|
-
import { getRequestIP, setResponseHeader } from
|
|
575
|
+
import { getRequestIP, setResponseHeader } from '@arrirpc/server';
|
|
566
576
|
```
|
|
567
577
|
|
|
568
578
|
#### Accessing H3 Events
|
|
@@ -592,8 +602,8 @@ defineEventStreamRpc({
|
|
|
592
602
|
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
603
|
|
|
594
604
|
```ts
|
|
595
|
-
import { createServer } from
|
|
596
|
-
import { ArriApp, toNodeListener } from
|
|
605
|
+
import { createServer } from 'node:http';
|
|
606
|
+
import { ArriApp, toNodeListener } from '@arrirpc/server';
|
|
597
607
|
|
|
598
608
|
const app = new ArriApp();
|
|
599
609
|
|
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.0",
|
|
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
|
-
"
|
|
33
|
-
"
|
|
31
|
+
"@arrirpc/codegen-utils": "0.71.0",
|
|
32
|
+
"@arrirpc/schema": "0.71.0",
|
|
33
|
+
"arri": "0.71.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"bun-types": "^1.1.
|
|
36
|
+
"bun-types": "^1.1.43"
|
|
37
37
|
}
|
|
38
38
|
}
|