arri 0.19.5 → 0.20.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/dist/cli.cjs CHANGED
@@ -12,7 +12,7 @@ const esbuild = require('esbuild');
12
12
  const esbuildPluginReplace = require('esbuild-plugin-replace');
13
13
  const path = require('pathe');
14
14
  const prettier = require('prettier');
15
- const config = require('./shared/arri.014f0e87.cjs');
15
+ const config = require('./shared/arri.b90bc113.cjs');
16
16
  const globby = require('globby');
17
17
  const scule = require('scule');
18
18
  const arriCodegenDart = require('arri-codegen-dart');
package/dist/cli.mjs CHANGED
@@ -11,7 +11,7 @@ import { build as build$1 } from 'esbuild';
11
11
  import { replace } from 'esbuild-plugin-replace';
12
12
  import path from 'pathe';
13
13
  import prettier from 'prettier';
14
- import { n as defaultConfig, m as isResolvedArriConfig, a as DEV_DEFINITION_ENDPOINT } from './shared/arri.1ab2026e.mjs';
14
+ import { n as defaultConfig, m as isResolvedArriConfig, a as DEV_DEFINITION_ENDPOINT } from './shared/arri.f69ab093.mjs';
15
15
  import { globby } from 'globby';
16
16
  import { camelCase, kebabCase } from 'scule';
17
17
  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.014f0e87.cjs');
3
+ const config = require('./shared/arri.b90bc113.cjs');
4
4
  const h3 = require('h3');
5
5
  require('arri-validate');
6
6
  require('node:process');
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { HttpMethod, RpcHttpMethod, RpcDefinition, SchemaFormProperties, SchemaFormDiscriminator, SchemaFormValues, AppDefinition, ClientGenerator } from 'arri-codegen-utils';
2
- import { AObjectSchema, ASchema, InferType, a, ValidationError, ARecordSchema, ADiscriminatorSchema } from 'arri-validate';
2
+ import { AObjectSchema, ASchema, InferType, a, ValidationError, ValueError, ARecordSchema, ADiscriminatorSchema } from 'arri-validate';
3
3
  import { H3EventContext, H3Event, Router, H3Error, App } from 'h3';
4
4
  export * from 'h3';
5
5
  import { BuildOptions } from 'esbuild';
@@ -73,6 +73,8 @@ interface EventStreamRpcHandlerContext<TParams = any, TResponse = any> extends R
73
73
  connection: EventStreamConnection<TResponse>;
74
74
  }
75
75
  interface EventStreamConnectionOptions<TData> {
76
+ validator: (input: unknown) => input is TData;
77
+ validationErrors: (input: unknown) => ValueError[];
76
78
  serializer: (input: TData) => string;
77
79
  pingInterval?: number;
78
80
  }
@@ -93,6 +95,8 @@ declare class EventStreamConnection<TData> {
93
95
  private readonly writer;
94
96
  private writerIsClosed;
95
97
  private readonly encoder;
98
+ private readonly validationErrors;
99
+ private readonly validator;
96
100
  private readonly serializer;
97
101
  private readonly h3Event;
98
102
  private pingInterval;
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { HttpMethod, RpcHttpMethod, RpcDefinition, SchemaFormProperties, SchemaFormDiscriminator, SchemaFormValues, AppDefinition, ClientGenerator } from 'arri-codegen-utils';
2
- import { AObjectSchema, ASchema, InferType, a, ValidationError, ARecordSchema, ADiscriminatorSchema } from 'arri-validate';
2
+ import { AObjectSchema, ASchema, InferType, a, ValidationError, ValueError, ARecordSchema, ADiscriminatorSchema } from 'arri-validate';
3
3
  import { H3EventContext, H3Event, Router, H3Error, App } from 'h3';
4
4
  export * from 'h3';
5
5
  import { BuildOptions } from 'esbuild';
@@ -73,6 +73,8 @@ interface EventStreamRpcHandlerContext<TParams = any, TResponse = any> extends R
73
73
  connection: EventStreamConnection<TResponse>;
74
74
  }
75
75
  interface EventStreamConnectionOptions<TData> {
76
+ validator: (input: unknown) => input is TData;
77
+ validationErrors: (input: unknown) => ValueError[];
76
78
  serializer: (input: TData) => string;
77
79
  pingInterval?: number;
78
80
  }
@@ -93,6 +95,8 @@ declare class EventStreamConnection<TData> {
93
95
  private readonly writer;
94
96
  private writerIsClosed;
95
97
  private readonly encoder;
98
+ private readonly validationErrors;
99
+ private readonly validator;
96
100
  private readonly serializer;
97
101
  private readonly h3Event;
98
102
  private pingInterval;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { HttpMethod, RpcHttpMethod, RpcDefinition, SchemaFormProperties, SchemaFormDiscriminator, SchemaFormValues, AppDefinition, ClientGenerator } from 'arri-codegen-utils';
2
- import { AObjectSchema, ASchema, InferType, a, ValidationError, ARecordSchema, ADiscriminatorSchema } from 'arri-validate';
2
+ import { AObjectSchema, ASchema, InferType, a, ValidationError, ValueError, ARecordSchema, ADiscriminatorSchema } from 'arri-validate';
3
3
  import { H3EventContext, H3Event, Router, H3Error, App } from 'h3';
4
4
  export * from 'h3';
5
5
  import { BuildOptions } from 'esbuild';
@@ -73,6 +73,8 @@ interface EventStreamRpcHandlerContext<TParams = any, TResponse = any> extends R
73
73
  connection: EventStreamConnection<TResponse>;
74
74
  }
75
75
  interface EventStreamConnectionOptions<TData> {
76
+ validator: (input: unknown) => input is TData;
77
+ validationErrors: (input: unknown) => ValueError[];
76
78
  serializer: (input: TData) => string;
77
79
  pingInterval?: number;
78
80
  }
@@ -93,6 +95,8 @@ declare class EventStreamConnection<TData> {
93
95
  private readonly writer;
94
96
  private writerIsClosed;
95
97
  private readonly encoder;
98
+ private readonly validationErrors;
99
+ private readonly validator;
96
100
  private readonly serializer;
97
101
  private readonly h3Event;
98
102
  private pingInterval;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { A as ArriApp, p as ArriRouter, a as DEV_DEFINITION_ENDPOINT, D as DEV_ENDPOINT_ROOT, E as ErrorResponse, B as EventStreamConnection, c as createRpcDefinition, n as defaultConfig, o as defineConfig, h as defineError, w as defineEventStreamRpc, q as defineRoute, d as defineRpc, j as errorResponseFromValidationErrors, y as formatSse, z as formatSseList, e as getRpcParamName, g as getRpcPath, f as getRpcResponseName, k as handleH3Error, t as handleRoute, l as isArriConfig, x as isEventStreamRpc, m as isResolvedArriConfig, b as isRpc, i as isRpcParamSchema, C as registerEventStreamRpc, s as registerRoute, r as registerRpc, u as setSseHeaders, v as validateRpcRequestInput } from './shared/arri.1ab2026e.mjs';
1
+ export { A as ArriApp, p as ArriRouter, a as DEV_DEFINITION_ENDPOINT, D as DEV_ENDPOINT_ROOT, E as ErrorResponse, B as EventStreamConnection, c as createRpcDefinition, n as defaultConfig, o as defineConfig, h as defineError, w as defineEventStreamRpc, q as defineRoute, d as defineRpc, j as errorResponseFromValidationErrors, y as formatSse, z as formatSseList, e as getRpcParamName, g as getRpcPath, f as getRpcResponseName, k as handleH3Error, t as handleRoute, l as isArriConfig, x as isEventStreamRpc, m as isResolvedArriConfig, b as isRpc, i as isRpcParamSchema, C as registerEventStreamRpc, s as registerRoute, r as registerRpc, u as setSseHeaders, v as validateRpcRequestInput } from './shared/arri.f69ab093.mjs';
2
2
  export * from 'h3';
3
3
  import 'arri-validate';
4
4
  import 'node:process';
@@ -312,6 +312,13 @@ function registerRpc(router, path, procedure, opts) {
312
312
  await opts.onBeforeResponse(event);
313
313
  }
314
314
  if (typeof response === "object") {
315
+ if (!responseValidator?.validate(response)) {
316
+ const errors = arriValidate.a.errors(procedure.response, response);
317
+ throw defineError(500, {
318
+ statusMessage: "Failed to serialize response. Response does not match specified schema",
319
+ data: errors
320
+ });
321
+ }
315
322
  h3.setResponseHeader(event, "Content-Type", "application/json");
316
323
  await h3.send(
317
324
  event,
@@ -474,6 +481,8 @@ class EventStreamConnection {
474
481
  __publicField$2(this, "writer");
475
482
  __publicField$2(this, "writerIsClosed", false);
476
483
  __publicField$2(this, "encoder");
484
+ __publicField$2(this, "validationErrors");
485
+ __publicField$2(this, "validator");
477
486
  __publicField$2(this, "serializer");
478
487
  __publicField$2(this, "h3Event");
479
488
  __publicField$2(this, "pingInterval");
@@ -488,6 +497,8 @@ class EventStreamConnection {
488
497
  this.encoder = new TextEncoder();
489
498
  this.pingIntervalMs = opts.pingInterval ?? 6e4;
490
499
  this.serializer = opts.serializer;
500
+ this.validator = opts.validator;
501
+ this.validationErrors = opts.validationErrors;
491
502
  void this.writer.closed.then(() => {
492
503
  this.writerIsClosed = true;
493
504
  });
@@ -512,19 +523,47 @@ class EventStreamConnection {
512
523
  if (Array.isArray(data)) {
513
524
  const events = [];
514
525
  for (const item of data) {
526
+ if (this.validator(item)) {
527
+ events.push({
528
+ id: eventId,
529
+ event: "message",
530
+ data: this.serializer(item)
531
+ });
532
+ continue;
533
+ }
534
+ const errors2 = this.validationErrors(item);
535
+ const errorResponse2 = {
536
+ statusCode: 500,
537
+ statusMessage: "Failed to serialize response. Response does not match specified schema.",
538
+ data: errors2
539
+ };
515
540
  events.push({
516
541
  id: eventId,
517
- event: "message",
518
- data: this.serializer(item)
542
+ event: "error",
543
+ data: JSON.stringify(errorResponse2)
519
544
  });
520
545
  }
521
546
  await this.publishEvents(events);
522
547
  return;
523
548
  }
549
+ if (this.validator(data)) {
550
+ await this.publishEvent({
551
+ id: eventId,
552
+ event: "message",
553
+ data: this.serializer(data)
554
+ });
555
+ return;
556
+ }
557
+ const errors = this.validationErrors(data);
558
+ const errorResponse = {
559
+ statusCode: 500,
560
+ statusMessage: "Failed to serialize response. Response does not match specified schema.",
561
+ data: errors
562
+ };
524
563
  await this.publishEvent({
525
564
  id: eventId,
526
- event: "message",
527
- data: this.serializer(data)
565
+ event: "error",
566
+ data: JSON.stringify(errorResponse)
528
567
  });
529
568
  }
530
569
  // /**
@@ -655,8 +694,17 @@ function registerEventStreamRpc(router, path, procedure, opts) {
655
694
  }
656
695
  const connection = new EventStreamConnection(event, {
657
696
  pingInterval: procedure.pingInterval,
697
+ validator: responseValidator?.validate ?? function() {
698
+ return true;
699
+ },
658
700
  serializer: responseValidator?.serialize ?? function(_) {
659
701
  return "";
702
+ },
703
+ validationErrors(input) {
704
+ if (procedure.response) {
705
+ return arriValidate.a.errors(procedure.response, input);
706
+ }
707
+ return [];
660
708
  }
661
709
  });
662
710
  event.context.connection = connection;
@@ -310,6 +310,13 @@ function registerRpc(router, path, procedure, opts) {
310
310
  await opts.onBeforeResponse(event);
311
311
  }
312
312
  if (typeof response === "object") {
313
+ if (!responseValidator?.validate(response)) {
314
+ const errors = a.errors(procedure.response, response);
315
+ throw defineError(500, {
316
+ statusMessage: "Failed to serialize response. Response does not match specified schema",
317
+ data: errors
318
+ });
319
+ }
313
320
  setResponseHeader(event, "Content-Type", "application/json");
314
321
  await send(
315
322
  event,
@@ -472,6 +479,8 @@ class EventStreamConnection {
472
479
  __publicField$2(this, "writer");
473
480
  __publicField$2(this, "writerIsClosed", false);
474
481
  __publicField$2(this, "encoder");
482
+ __publicField$2(this, "validationErrors");
483
+ __publicField$2(this, "validator");
475
484
  __publicField$2(this, "serializer");
476
485
  __publicField$2(this, "h3Event");
477
486
  __publicField$2(this, "pingInterval");
@@ -486,6 +495,8 @@ class EventStreamConnection {
486
495
  this.encoder = new TextEncoder();
487
496
  this.pingIntervalMs = opts.pingInterval ?? 6e4;
488
497
  this.serializer = opts.serializer;
498
+ this.validator = opts.validator;
499
+ this.validationErrors = opts.validationErrors;
489
500
  void this.writer.closed.then(() => {
490
501
  this.writerIsClosed = true;
491
502
  });
@@ -510,19 +521,47 @@ class EventStreamConnection {
510
521
  if (Array.isArray(data)) {
511
522
  const events = [];
512
523
  for (const item of data) {
524
+ if (this.validator(item)) {
525
+ events.push({
526
+ id: eventId,
527
+ event: "message",
528
+ data: this.serializer(item)
529
+ });
530
+ continue;
531
+ }
532
+ const errors2 = this.validationErrors(item);
533
+ const errorResponse2 = {
534
+ statusCode: 500,
535
+ statusMessage: "Failed to serialize response. Response does not match specified schema.",
536
+ data: errors2
537
+ };
513
538
  events.push({
514
539
  id: eventId,
515
- event: "message",
516
- data: this.serializer(item)
540
+ event: "error",
541
+ data: JSON.stringify(errorResponse2)
517
542
  });
518
543
  }
519
544
  await this.publishEvents(events);
520
545
  return;
521
546
  }
547
+ if (this.validator(data)) {
548
+ await this.publishEvent({
549
+ id: eventId,
550
+ event: "message",
551
+ data: this.serializer(data)
552
+ });
553
+ return;
554
+ }
555
+ const errors = this.validationErrors(data);
556
+ const errorResponse = {
557
+ statusCode: 500,
558
+ statusMessage: "Failed to serialize response. Response does not match specified schema.",
559
+ data: errors
560
+ };
522
561
  await this.publishEvent({
523
562
  id: eventId,
524
- event: "message",
525
- data: this.serializer(data)
563
+ event: "error",
564
+ data: JSON.stringify(errorResponse)
526
565
  });
527
566
  }
528
567
  // /**
@@ -653,8 +692,17 @@ function registerEventStreamRpc(router, path, procedure, opts) {
653
692
  }
654
693
  const connection = new EventStreamConnection(event, {
655
694
  pingInterval: procedure.pingInterval,
695
+ validator: responseValidator?.validate ?? function() {
696
+ return true;
697
+ },
656
698
  serializer: responseValidator?.serialize ?? function(_) {
657
699
  return "";
700
+ },
701
+ validationErrors(input) {
702
+ if (procedure.response) {
703
+ return a.errors(procedure.response, input);
704
+ }
705
+ return [];
658
706
  }
659
707
  });
660
708
  event.context.connection = connection;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arri",
3
- "version": "0.19.5",
3
+ "version": "0.20.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -37,17 +37,17 @@
37
37
  "h3": "^1.10.0",
38
38
  "jiti": "^1.21.0",
39
39
  "ofetch": "^1.3.3",
40
- "pathe": "^1.1.1",
41
- "prettier": "^3.1.1",
42
- "scule": "^1.1.1",
40
+ "pathe": "^1.1.2",
41
+ "prettier": "^3.2.2",
42
+ "scule": "^1.2.0",
43
43
  "uncrypto": "^0.1.3",
44
- "arri-codegen-dart": "0.19.5",
45
- "arri-codegen-ts": "0.19.5",
46
- "arri-codegen-utils": "0.19.5",
47
- "arri-validate": "0.19.5"
44
+ "arri-codegen-dart": "0.20.0",
45
+ "arri-validate": "0.20.0",
46
+ "arri-codegen-utils": "0.20.0",
47
+ "arri-codegen-ts": "0.20.0"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@types/degit": "^2.8.6",
51
- "bun-types": "^1.0.21"
51
+ "bun-types": "^1.0.22"
52
52
  }
53
53
  }