arri 0.1.0-beta.9 → 0.1.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 CHANGED
@@ -1,11 +1,167 @@
1
- # arri-rpc
1
+ # Arri RPC
2
2
 
3
- This library was generated with [Nx](https://nx.dev).
3
+ ## Installation
4
4
 
5
- ## Building
5
+ ```bash
6
+ # npm
7
+ npm install arri arri-validate
8
+
9
+ # pnpm
10
+ pnpm install arri arri-validate
11
+ ```
12
+
13
+ ## Basic Setup Example
14
+
15
+ Create an `arri.config.ts` in the project directory
16
+
17
+ ```ts
18
+ // arri.config.ts
19
+ import { defineConfig } from "arri";
20
+ import {
21
+ typescriptClientGenerator,
22
+ dartClientGenerator,
23
+ } from "arri/dist/codegen";
24
+
25
+ export default defineConfig({
26
+ entry: "app.ts",
27
+ port: 3000,
28
+ srcDir: "src",
29
+ clientGenerators: [
30
+ typescriptClientGenerator({
31
+ // options
32
+ }),
33
+ dartClientGenerator({
34
+ // options
35
+ }),
36
+ ],
37
+ });
38
+ ```
39
+
40
+ Create an `app.ts` file in the source directory
41
+
42
+ ```ts
43
+ // ./src/app.ts
44
+ import { ArriApp } from "arri";
45
+ import { a } from "arri-validate";
46
+
47
+ const app = new ArriApp();
48
+
49
+ app.rpc("sayHello", {
50
+ params: a.object({
51
+ name: a.string(),
52
+ }),
53
+ response: a.object({
54
+ message: a.string(),
55
+ }),
56
+ handler({ params }) {
57
+ return {
58
+ message: `Hello ${params.name}`,
59
+ };
60
+ },
61
+ });
62
+
63
+ export default app;
64
+ ```
65
+
66
+ Setup your npm scripts:
67
+
68
+ ```json
69
+ {
70
+ "scripts": {
71
+ "dev": "arri dev",
72
+ "build": "arri build"
73
+ }
74
+ }
75
+ ```
76
+
77
+ Start the dev server:
78
+
79
+ ```bash
80
+ npm run dev
81
+ ```
82
+
83
+ ## File Based Routing
84
+
85
+ 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.
86
+
87
+ ```fs
88
+ |-- src
89
+ |-- procedures
90
+ |-- sayHello.rpc.ts // becomes sayHello()
91
+ |-- users
92
+ |-- getUser.rpc.ts // becomes users.getUser()
93
+ |-- updateUser.rpc.ts // becomes users.updateUser()
94
+ ```
95
+
96
+ Example `.rpc.ts` file
97
+
98
+ ```ts
99
+ // ./src/users/getUser.rpc.ts
100
+ import { defineRpc } from "arri";
101
+ import { a } from "arri-validate";
102
+
103
+ export default defineRpc({
104
+ params: a.object({
105
+ userId: a.string(),
106
+ }),
107
+ response: a.object({
108
+ id: a.string(),
109
+ name: a.string(),
110
+ createdAt: a.timestamp(),
111
+ }),
112
+ handler({ params }) {
113
+ // function body
114
+ },
115
+ });
116
+ ```
117
+
118
+ ### Customizing the File Based Router
119
+
120
+ ```ts
121
+ export default defineConfig({
122
+ // rest of config
123
+ procedureDir: "procedures", // change which directory to look for procedures (This is relative to the srcDir)
124
+ procedureGlobPatterns: ["**/*.rpc.ts"], // change the file name glob pattern for finding rpcs
125
+ });
126
+ ```
127
+
128
+ ## Adding Non-RPC Endpoints
129
+
130
+ ```ts
131
+ app.route({
132
+ method: "get",
133
+ path: "/hello-world",
134
+ handler(event) {
135
+ return "hello world";
136
+ },
137
+ });
138
+ ```
139
+
140
+ ## Creating sub routers
141
+
142
+ ```ts
143
+ import { ArriApp, ArriRouter } from "arri";
144
+
145
+ const app = new ArriApp();
146
+ const router = new ArriRouter();
147
+
148
+ router.rpc({
149
+ // rpc config
150
+ });
151
+
152
+ router.route({
153
+ // route config
154
+ });
155
+
156
+ app.use(router);
157
+ ```
158
+
159
+ ## Developing
160
+
161
+ ### Building
6
162
 
7
163
  Run `nx build arri-rpc` to build the library.
8
164
 
9
- ## Running unit tests
165
+ ### Running unit tests
10
166
 
11
- Run `nx test arri-rpc` to execute the unit tests via [Jest](https://jestjs.io).
167
+ Run `nx test arri-rpc` to execute the unit tests via Vitest.
package/dist/cli.cjs CHANGED
@@ -11,7 +11,7 @@ const consola = require('consola');
11
11
  const esbuild = require('esbuild');
12
12
  const path = require('pathe');
13
13
  const prettier = require('prettier');
14
- const config = require('./shared/arri.eea9df0a.cjs');
14
+ const config = require('./shared/arri.ed4bd5e1.cjs');
15
15
  const globby = require('globby');
16
16
  const scule = require('scule');
17
17
  const arriCodegenDart = require('arri-codegen-dart');
package/dist/cli.mjs CHANGED
@@ -10,7 +10,7 @@ import * as esbuild from 'esbuild';
10
10
  import { build as build$1 } from 'esbuild';
11
11
  import path from 'pathe';
12
12
  import prettier from 'prettier';
13
- import { m as defaultConfig, l as isResolvedArriConfig, a as DEV_DEFINITION_ENDPOINT } from './shared/arri.16b8531c.mjs';
13
+ import { m as defaultConfig, l as isResolvedArriConfig, a as DEV_DEFINITION_ENDPOINT } from './shared/arri.121d68e9.mjs';
14
14
  import { globby } from 'globby';
15
15
  import { camelCase, kebabCase } from 'scule';
16
16
  import { dartClientGenerator } from 'arri-codegen-dart';
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const config = require('./shared/arri.eea9df0a.cjs');
3
+ const config = require('./shared/arri.ed4bd5e1.cjs');
4
4
  const h3 = require('h3');
5
5
  require('arri-validate');
6
6
  require('arri-codegen-utils');
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { A as ArriApp, o as ArriRouter, a as DEV_DEFINITION_ENDPOINT, D as DEV_ENDPOINT_ROOT, E as ErrorResponse, c as createRpcDefinition, m as defaultConfig, n as defineConfig, f as defineError, p as defineRoute, d as defineRpc, h as errorResponseFromValidationErrors, b as getRpcParamName, g as getRpcPath, e as getRpcResponseName, j as handleH3Error, s as handleRoute, k as isArriConfig, l as isResolvedArriConfig, i as isRpc, q as registerRoute, r as registerRpc } from './shared/arri.16b8531c.mjs';
1
+ export { A as ArriApp, o as ArriRouter, a as DEV_DEFINITION_ENDPOINT, D as DEV_ENDPOINT_ROOT, E as ErrorResponse, c as createRpcDefinition, m as defaultConfig, n as defineConfig, f as defineError, p as defineRoute, d as defineRpc, h as errorResponseFromValidationErrors, b as getRpcParamName, g as getRpcPath, e as getRpcResponseName, j as handleH3Error, s as handleRoute, k as isArriConfig, l as isResolvedArriConfig, i as isRpc, q as registerRoute, r as registerRpc } from './shared/arri.121d68e9.mjs';
2
2
  export * from 'h3';
3
3
  import 'arri-validate';
4
4
  import 'arri-codegen-utils';
@@ -270,7 +270,12 @@ function getRpcResponseDefinition(rpcName, procedure) {
270
270
  return name;
271
271
  }
272
272
  function registerRpc(router, path, procedure, opts) {
273
- const responseValidator = procedure.response ? a.compile(procedure.response) : void 0;
273
+ let responseValidator;
274
+ try {
275
+ responseValidator = procedure.response ? a.compile(procedure.response) : void 0;
276
+ } catch (err) {
277
+ console.error("ERROR COMPILING VALIDATOR", err);
278
+ }
274
279
  const httpMethod = procedure.method ?? "post";
275
280
  const handler = eventHandler(async (event) => {
276
281
  event.context.rpcName = procedure.name;
@@ -272,7 +272,12 @@ function getRpcResponseDefinition(rpcName, procedure) {
272
272
  return name;
273
273
  }
274
274
  function registerRpc(router, path, procedure, opts) {
275
- const responseValidator = procedure.response ? arriValidate.a.compile(procedure.response) : void 0;
275
+ let responseValidator;
276
+ try {
277
+ responseValidator = procedure.response ? arriValidate.a.compile(procedure.response) : void 0;
278
+ } catch (err) {
279
+ console.error("ERROR COMPILING VALIDATOR", err);
280
+ }
276
281
  const httpMethod = procedure.method ?? "post";
277
282
  const handler = h3.eventHandler(async (event) => {
278
283
  event.context.rpcName = procedure.name;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arri",
3
- "version": "0.1.0-beta.9",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -31,10 +31,10 @@
31
31
  "pathe": "^1.1.1",
32
32
  "prettier": "^3.0.3",
33
33
  "scule": "^1.0.0",
34
- "arri-codegen-utils": "0.1.0-beta.9",
35
- "arri-codegen-ts": "0.1.0-beta.9",
36
- "arri-codegen-dart": "0.1.0-beta.9",
37
- "arri-validate": "0.1.0-beta.9"
34
+ "arri-codegen-ts": "0.1.1",
35
+ "arri-codegen-dart": "0.1.1",
36
+ "arri-codegen-utils": "0.1.1",
37
+ "arri-validate": "0.1.1"
38
38
  },
39
39
  "devDependencies": {
40
40
  "bun-types": "^1.0.5"