@arrirpc/server 0.53.0 → 0.53.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -24
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@ Typescript implementation of [Arri RPC](/README.md). It's built on top of [H3](h
|
|
|
14
14
|
- [Manual Routing](#manual-routing)
|
|
15
15
|
- [Creating Event Stream Procedures](#creating-event-stream-procedures)
|
|
16
16
|
- [Creating Websocket Procedures](#creating-websocket-procedures-experimental)
|
|
17
|
+
- [Adding to the RPC Context](#adding-to-the-rpc-context)
|
|
17
18
|
- [Adding Non-RPC Routes](#adding-non-rpc-routes)
|
|
18
19
|
- [Adding Middleware](#adding-middleware)
|
|
19
20
|
- [Key Concepts](#key-concepts)
|
|
@@ -136,7 +137,7 @@ Setup your npm scripts:
|
|
|
136
137
|
|
|
137
138
|
### Creating Procedures
|
|
138
139
|
|
|
139
|
-
#### File Based
|
|
140
|
+
#### File Based Routing
|
|
140
141
|
|
|
141
142
|
Arri RPC comes with an optional file based router that will automatically register functions in the `./procedures` directory that end with the `.rpc.ts` file extension.
|
|
142
143
|
|
|
@@ -192,7 +193,7 @@ app.rpc('sayHello', {...})
|
|
|
192
193
|
|
|
193
194
|
// using a sub-router
|
|
194
195
|
const app = new ArriApp();
|
|
195
|
-
const router = new
|
|
196
|
+
const router = new ArriRouter();
|
|
196
197
|
router.rpc('sayHello', {...})
|
|
197
198
|
app.use(router)
|
|
198
199
|
```
|
|
@@ -404,12 +405,12 @@ app.rpc("sayHello", {
|
|
|
404
405
|
});
|
|
405
406
|
```
|
|
406
407
|
|
|
407
|
-
To get type safety for these new properties create a `.d.ts` file and augment the `ArriEventContext` provided by `@
|
|
408
|
+
To get type safety for these new properties create a `.d.ts` file and augment the `ArriEventContext` provided by `@arrirpc/server`
|
|
408
409
|
|
|
409
410
|
```ts
|
|
410
|
-
import "@
|
|
411
|
+
import "@arrirpc/server";
|
|
411
412
|
|
|
412
|
-
declare module "@
|
|
413
|
+
declare module "@arrirpc/server" {
|
|
413
414
|
interface ArriEventContext {
|
|
414
415
|
user?: {
|
|
415
416
|
id: number;
|
|
@@ -422,26 +423,25 @@ declare module "@arri/server" {
|
|
|
422
423
|
|
|
423
424
|
### Adding Client Generators
|
|
424
425
|
|
|
425
|
-
Right now Arri RPC has client generators for the following languages:
|
|
426
|
-
|
|
427
|
-
- typescript
|
|
428
|
-
- dart
|
|
429
|
-
- kotlin
|
|
430
|
-
|
|
431
426
|
```ts
|
|
432
427
|
// arri.config.ts
|
|
433
428
|
import { defineConfig, generators } from "arri";
|
|
434
429
|
|
|
435
430
|
export default defineConfig({
|
|
436
431
|
// rest of config
|
|
437
|
-
|
|
432
|
+
generators: [
|
|
438
433
|
generators.typescriptClient({...}),
|
|
439
434
|
generators.dartClient({...}),
|
|
440
435
|
generators.kotlinClient({...})
|
|
436
|
+
generators.someGenerator({...})
|
|
441
437
|
]
|
|
442
438
|
});
|
|
443
439
|
```
|
|
444
440
|
|
|
441
|
+
For info on what generators are available see [here](/README.md#client-generators)
|
|
442
|
+
|
|
443
|
+
For info on how to create your own generator see []
|
|
444
|
+
|
|
445
445
|
## Key Concepts
|
|
446
446
|
|
|
447
447
|
### Arri Definition File
|
|
@@ -545,20 +545,33 @@ You can access H3 events from inside procedures handlers.
|
|
|
545
545
|
|
|
546
546
|
```ts
|
|
547
547
|
defineRpc({
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
)
|
|
548
|
+
params: undefined,
|
|
549
|
+
response: undefined,
|
|
550
|
+
handler(_, event) {
|
|
551
|
+
getRequestIP(event);
|
|
552
|
+
},
|
|
553
|
+
});
|
|
554
554
|
|
|
555
555
|
defineEventStreamRpc({
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
)
|
|
556
|
+
params: undefined,
|
|
557
|
+
response: undefined,
|
|
558
|
+
handler(_, event) {
|
|
559
|
+
getRequestIP(event);
|
|
560
|
+
},
|
|
561
|
+
});
|
|
562
|
+
```
|
|
563
|
+
|
|
564
|
+
#### Manually Starting an Arri Server
|
|
565
|
+
|
|
566
|
+
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.
|
|
567
|
+
|
|
568
|
+
```ts
|
|
569
|
+
import { createServer } from "node:http";
|
|
570
|
+
import { ArriApp, toNodeListener } from "@arrirpc/server";
|
|
571
|
+
|
|
572
|
+
const app = new ArriApp();
|
|
573
|
+
|
|
574
|
+
createServer(toNodeListener(app.h3App)).listen(process.env.PORT || 3000);
|
|
562
575
|
```
|
|
563
576
|
|
|
564
577
|
## Arri CLI
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arrirpc/server",
|
|
3
|
-
"version": "0.53.
|
|
3
|
+
"version": "0.53.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
"scule": "^1.3.0",
|
|
30
30
|
"source-map-support": "^0.5.21",
|
|
31
31
|
"uncrypto": "^0.1.3",
|
|
32
|
-
"@arrirpc/codegen-dart": "0.53.
|
|
33
|
-
"@arrirpc/codegen-kotlin": "0.53.
|
|
34
|
-
"@arrirpc/codegen-ts": "0.53.
|
|
35
|
-
"@arrirpc/codegen-utils": "0.53.
|
|
36
|
-
"
|
|
37
|
-
"
|
|
32
|
+
"@arrirpc/codegen-dart": "0.53.2",
|
|
33
|
+
"@arrirpc/codegen-kotlin": "0.53.2",
|
|
34
|
+
"@arrirpc/codegen-ts": "0.53.2",
|
|
35
|
+
"@arrirpc/codegen-utils": "0.53.2",
|
|
36
|
+
"@arrirpc/schema": "0.53.2",
|
|
37
|
+
"arri": "0.53.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"bun-types": "^1.1.
|
|
40
|
+
"bun-types": "^1.1.14"
|
|
41
41
|
}
|
|
42
42
|
}
|