arri 0.42.0 → 0.42.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 CHANGED
@@ -13,6 +13,7 @@ Typescript implementation of Arri RPC. It's built on top of [H3](https://github.
13
13
  - [File-Based Routing](#file-based-routing)
14
14
  - [Manual Routing](#manual-routing)
15
15
  - [Creating Event Stream Procedures](#creating-event-stream-procedures)
16
+ - [Creating Websocket Procedures](#creating-websocket-procedures)
16
17
  - [Adding Non-RPC Routes](#adding-non-rpc-routes)
17
18
  - [Adding Middleware](#adding-middleware)
18
19
  - [Key Concepts](#key-concepts)
@@ -277,6 +278,68 @@ stream.end()
277
278
  stream.on(e: 'request:close' | 'close', callback: () => any)
278
279
  ```
279
280
 
281
+ ### Creating Websocket Procedures
282
+
283
+ ```ts
284
+ // Websocket procedures work really well with discriminated unions
285
+ const IncomingMsg = a.discriminator('type', {
286
+ FOO: a.object({
287
+ message: a.string(),
288
+ }),
289
+ PING: a.object({
290
+ message: a.string(),
291
+ })
292
+ });
293
+
294
+ const OutgoingMsg = a.discriminator('type', {
295
+ BAR: a.object({
296
+ message: a.string(),
297
+ }),
298
+ PONG: a.object({
299
+ message: a.string()
300
+ })
301
+ });
302
+
303
+ export default defineWebsocketRpc(
304
+ params: IncomingMsg,
305
+ response: OutgoingMsg,
306
+ handler: {
307
+ onOpen: (peer) => {},
308
+ onMessage: (peer, message) => {
309
+ switch(message.type) {
310
+ case "FOO":
311
+ peer.send({
312
+ type: "BAR",
313
+ message: "You sent a FOO message"
314
+ });
315
+ break;
316
+ case "PING":
317
+ peer.send({
318
+ type: "PONG",
319
+ message: "You sent a PING message"
320
+ });
321
+ break;
322
+ }
323
+ },
324
+ onError: (peer, error) => {}
325
+ }
326
+ )
327
+ ```
328
+
329
+ Under the hood Websocket RPCs use [crossws](https://crossws.unjs.io/).
330
+
331
+ The possible payloads sent by the server will look like the following:
332
+
333
+ ```
334
+ event: message
335
+ data: <response serialized to json>
336
+ ```
337
+
338
+ ```
339
+ event: error
340
+ data: {"code": <some-err-code>, "message": <some-error-msg>}
341
+ ```
342
+
280
343
  ### Adding Non-RPC Routes
281
344
 
282
345
  You can also add generic endpoints for instances when a message-based RPC endpoint doesn't fit.
@@ -467,16 +530,19 @@ The supported HTTP methods are as follows:
467
530
  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.
468
531
 
469
532
  ### H3 Support
533
+
470
534
  Arri is built on top of [H3](https://h3.unjs.io/utils/request#getrequestipevent) so many of the concepts that apply to H3 also apply to Arri.
471
535
 
472
536
  #### Accessing Utilities
537
+
473
538
  Arri re-eports all of the H3 utilities.
474
539
 
475
540
  ```ts
476
- import { getRequestIP, setResponseHeader } from 'arri';
541
+ import { getRequestIP, setResponseHeader } from "arri";
477
542
  ```
478
543
 
479
544
  #### Accessing H3 Events
545
+
480
546
  You can access H3 events from inside procedures handlers.
481
547
 
482
548
  ```ts
@@ -508,6 +574,9 @@ arri build [flags]
508
574
 
509
575
  # create a new project
510
576
  arri init [dir]
577
+
578
+ # run codegen
579
+ arri codegen [path-to-definition-file]
511
580
  ```
512
581
 
513
582
  ## Development
package/dist/cli.cjs CHANGED
@@ -273,8 +273,8 @@ async function bundleAppEntry(config, allowCodegen = true) {
273
273
  bundle: true,
274
274
  packages: "external",
275
275
  format: "esm",
276
- sourcemap: true,
277
- minifyWhitespace: true,
276
+ sourcemap: config.esbuild.sourcemap ?? true,
277
+ minify: config.esbuild.minify ?? true,
278
278
  banner: {
279
279
  js: `import { createRequire as topLevelCreateRequire } from 'module';
280
280
  const require = topLevelCreateRequire(import.meta.url);`
@@ -503,10 +503,10 @@ export default app.h3App;`;
503
503
  outfile: path__default.resolve(config.rootDir, ".output", OUT_APP_FILE),
504
504
  format: "esm",
505
505
  bundle: true,
506
- sourcemap: true,
507
- target: "node20",
508
- platform: "node",
509
- packages: "external"
506
+ packages: "external",
507
+ sourcemap: config.esbuild.sourcemap ?? true,
508
+ target: config.esbuild.target ?? "node20",
509
+ platform: config.esbuild.platform ?? "node"
510
510
  });
511
511
  }
512
512
  async function startDevServer(config) {
@@ -609,7 +609,7 @@ async function generateClients(config$1) {
609
609
  }
610
610
  logger.log(`Generating client code...`);
611
611
  const clientCount = config$1.generators.length;
612
- await Promise.all(
612
+ await Promise.allSettled(
613
613
  config$1.generators.map(
614
614
  (generator) => generator.generator(result, true)
615
615
  )
@@ -618,7 +618,7 @@ async function generateClients(config$1) {
618
618
  `Generated ${clientCount} client${clientCount === 1 ? "" : "s"}`
619
619
  );
620
620
  } catch (err) {
621
- console.error(err);
621
+ logger.error(err);
622
622
  }
623
623
  }
624
624
  async function createEntryModule(config) {
package/dist/cli.mjs CHANGED
@@ -250,8 +250,8 @@ async function bundleAppEntry(config, allowCodegen = true) {
250
250
  bundle: true,
251
251
  packages: "external",
252
252
  format: "esm",
253
- sourcemap: true,
254
- minifyWhitespace: true,
253
+ sourcemap: config.esbuild.sourcemap ?? true,
254
+ minify: config.esbuild.minify ?? true,
255
255
  banner: {
256
256
  js: `import { createRequire as topLevelCreateRequire } from 'module';
257
257
  const require = topLevelCreateRequire(import.meta.url);`
@@ -480,10 +480,10 @@ export default app.h3App;`;
480
480
  outfile: path.resolve(config.rootDir, ".output", OUT_APP_FILE),
481
481
  format: "esm",
482
482
  bundle: true,
483
- sourcemap: true,
484
- target: "node20",
485
- platform: "node",
486
- packages: "external"
483
+ packages: "external",
484
+ sourcemap: config.esbuild.sourcemap ?? true,
485
+ target: config.esbuild.target ?? "node20",
486
+ platform: config.esbuild.platform ?? "node"
487
487
  });
488
488
  }
489
489
  async function startDevServer(config) {
@@ -586,7 +586,7 @@ async function generateClients(config) {
586
586
  }
587
587
  logger.log(`Generating client code...`);
588
588
  const clientCount = config.generators.length;
589
- await Promise.all(
589
+ await Promise.allSettled(
590
590
  config.generators.map(
591
591
  (generator) => generator.generator(result, true)
592
592
  )
@@ -595,7 +595,7 @@ async function generateClients(config) {
595
595
  `Generated ${clientCount} client${clientCount === 1 ? "" : "s"}`
596
596
  );
597
597
  } catch (err) {
598
- console.error(err);
598
+ logger.error(err);
599
599
  }
600
600
  }
601
601
  async function createEntryModule(config) {
package/dist/codegen.cjs CHANGED
@@ -2,8 +2,10 @@
2
2
 
3
3
  const arriCodegenDart = require('arri-codegen-dart');
4
4
  const arriCodegenTs = require('arri-codegen-ts');
5
+ const arriCodegenUtils = require('arri-codegen-utils');
5
6
 
6
7
 
7
8
 
8
9
  exports.dartClientGenerator = arriCodegenDart.dartClientGenerator;
9
10
  exports.typescriptClientGenerator = arriCodegenTs.typescriptClientGenerator;
11
+ exports.createAppDefinition = arriCodegenUtils.createAppDefinition;
@@ -1,2 +1,3 @@
1
1
  export { dartClientGenerator } from 'arri-codegen-dart';
2
2
  export { typescriptClientGenerator } from 'arri-codegen-ts';
3
+ export { AppDefinition, createAppDefinition } from 'arri-codegen-utils';
@@ -1,2 +1,3 @@
1
1
  export { dartClientGenerator } from 'arri-codegen-dart';
2
2
  export { typescriptClientGenerator } from 'arri-codegen-ts';
3
+ export { AppDefinition, createAppDefinition } from 'arri-codegen-utils';
package/dist/codegen.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export { dartClientGenerator } from 'arri-codegen-dart';
2
2
  export { typescriptClientGenerator } from 'arri-codegen-ts';
3
+ export { AppDefinition, createAppDefinition } from 'arri-codegen-utils';
package/dist/codegen.mjs CHANGED
@@ -1,2 +1,3 @@
1
1
  export { dartClientGenerator } from 'arri-codegen-dart';
2
2
  export { typescriptClientGenerator } from 'arri-codegen-ts';
3
+ export { createAppDefinition } from 'arri-codegen-utils';
package/dist/index.d.cts CHANGED
@@ -290,7 +290,7 @@ interface ArriConfig {
290
290
  procedureGlobPatterns?: string[];
291
291
  generators?: Array<ClientGenerator<any>>;
292
292
  buildDir?: string;
293
- esbuild?: Omit<BuildOptions, "outfile" | "outdir" | "entryNames" | "entryPoints">;
293
+ esbuild?: Omit<BuildOptions, "bundle" | "format" | "outfile" | "outdir" | "entryNames" | "entryPoints" | "packages">;
294
294
  https?: {
295
295
  cert: string;
296
296
  key: string;
package/dist/index.d.mts CHANGED
@@ -290,7 +290,7 @@ interface ArriConfig {
290
290
  procedureGlobPatterns?: string[];
291
291
  generators?: Array<ClientGenerator<any>>;
292
292
  buildDir?: string;
293
- esbuild?: Omit<BuildOptions, "outfile" | "outdir" | "entryNames" | "entryPoints">;
293
+ esbuild?: Omit<BuildOptions, "bundle" | "format" | "outfile" | "outdir" | "entryNames" | "entryPoints" | "packages">;
294
294
  https?: {
295
295
  cert: string;
296
296
  key: string;
package/dist/index.d.ts CHANGED
@@ -290,7 +290,7 @@ interface ArriConfig {
290
290
  procedureGlobPatterns?: string[];
291
291
  generators?: Array<ClientGenerator<any>>;
292
292
  buildDir?: string;
293
- esbuild?: Omit<BuildOptions, "outfile" | "outdir" | "entryNames" | "entryPoints">;
293
+ esbuild?: Omit<BuildOptions, "bundle" | "format" | "outfile" | "outdir" | "entryNames" | "entryPoints" | "packages">;
294
294
  https?: {
295
295
  cert: string;
296
296
  key: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arri",
3
- "version": "0.42.0",
3
+ "version": "0.42.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -35,7 +35,7 @@
35
35
  "crossws": "^0.2.4",
36
36
  "degit": "^2.8.4",
37
37
  "enquirer": "^2.4.1",
38
- "esbuild": "^0.20.2",
38
+ "esbuild": "^0.21.1",
39
39
  "esbuild-plugin-replace": "^1.4.0",
40
40
  "globby": "^14.0.1",
41
41
  "h3": "^1.11.1",
@@ -47,13 +47,13 @@
47
47
  "scule": "^1.3.0",
48
48
  "source-map-support": "^0.5.21",
49
49
  "uncrypto": "^0.1.3",
50
- "arri-codegen-ts": "0.42.0",
51
- "arri-codegen-utils": "0.42.0",
52
- "arri-codegen-dart": "0.42.0",
53
- "arri-validate": "0.42.0"
50
+ "arri-codegen-dart": "0.42.2",
51
+ "arri-codegen-ts": "0.42.2",
52
+ "arri-validate": "0.42.2",
53
+ "arri-codegen-utils": "0.42.2"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@types/degit": "^2.8.6",
57
- "bun-types": "^1.1.4"
57
+ "bun-types": "^1.1.8"
58
58
  }
59
59
  }