arri 0.18.1 → 0.18.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/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.34c274c5.cjs');
15
+ const config = require('./shared/arri.2034f594.cjs');
16
16
  const globby = require('globby');
17
17
  const scule = require('scule');
18
18
  const arriCodegenDart = require('arri-codegen-dart');
@@ -22,6 +22,7 @@ const chokidar = require('chokidar');
22
22
  const Degit = require('degit');
23
23
  require('h3');
24
24
  require('arri-validate');
25
+ require('node:process');
25
26
 
26
27
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
27
28
 
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.0ddf73b7.mjs';
14
+ import { n as defaultConfig, m as isResolvedArriConfig, a as DEV_DEFINITION_ENDPOINT } from './shared/arri.97188bcb.mjs';
15
15
  import { globby } from 'globby';
16
16
  import { camelCase, kebabCase } from 'scule';
17
17
  import { dartClientGenerator } from 'arri-codegen-dart';
@@ -21,6 +21,7 @@ import chokidar from 'chokidar';
21
21
  import Degit from 'degit';
22
22
  import 'h3';
23
23
  import 'arri-validate';
24
+ import 'node:process';
24
25
 
25
26
  const GEN_APP_FILE = "__arri_app.js";
26
27
  const GEN_SERVER_ENTRY_FILE = "__arri_server.js";
package/dist/index.cjs CHANGED
@@ -1,8 +1,9 @@
1
1
  'use strict';
2
2
 
3
- const config = require('./shared/arri.34c274c5.cjs');
3
+ const config = require('./shared/arri.2034f594.cjs');
4
4
  const h3 = require('h3');
5
5
  require('arri-validate');
6
+ require('node:process');
6
7
  require('arri-codegen-utils');
7
8
  require('scule');
8
9
 
package/dist/index.d.cts CHANGED
@@ -91,6 +91,7 @@ declare class EventStreamConnection<TData> {
91
91
  private readonly writable;
92
92
  private readonly readable;
93
93
  private readonly writer;
94
+ private writerIsClosed;
94
95
  private readonly encoder;
95
96
  private readonly serializer;
96
97
  private readonly h3Event;
package/dist/index.d.mts CHANGED
@@ -91,6 +91,7 @@ declare class EventStreamConnection<TData> {
91
91
  private readonly writable;
92
92
  private readonly readable;
93
93
  private readonly writer;
94
+ private writerIsClosed;
94
95
  private readonly encoder;
95
96
  private readonly serializer;
96
97
  private readonly h3Event;
package/dist/index.d.ts CHANGED
@@ -91,6 +91,7 @@ declare class EventStreamConnection<TData> {
91
91
  private readonly writable;
92
92
  private readonly readable;
93
93
  private readonly writer;
94
+ private writerIsClosed;
94
95
  private readonly encoder;
95
96
  private readonly serializer;
96
97
  private readonly h3Event;
package/dist/index.mjs CHANGED
@@ -1,6 +1,7 @@
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.0ddf73b7.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.97188bcb.mjs';
2
2
  export * from 'h3';
3
3
  import 'arri-validate';
4
+ import 'node:process';
4
5
  import 'arri-codegen-utils';
5
6
  import 'scule';
6
7
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  const h3 = require('h3');
4
4
  const arriValidate = require('arri-validate');
5
+ const node_process = require('node:process');
5
6
  const arriCodegenUtils = require('arri-codegen-utils');
6
7
  const scule = require('scule');
7
8
 
@@ -460,6 +461,7 @@ class EventStreamConnection {
460
461
  __publicField$2(this, "writable");
461
462
  __publicField$2(this, "readable");
462
463
  __publicField$2(this, "writer");
464
+ __publicField$2(this, "writerIsClosed", false);
463
465
  __publicField$2(this, "encoder");
464
466
  __publicField$2(this, "serializer");
465
467
  __publicField$2(this, "h3Event");
@@ -477,6 +479,9 @@ class EventStreamConnection {
477
479
  this.encoder = new TextEncoder();
478
480
  this.pingIntervalMs = opts.pingInterval ?? 6e4;
479
481
  this.serializer = opts.serializer;
482
+ void this.writer.closed.then(() => {
483
+ this.writerIsClosed = true;
484
+ });
480
485
  }
481
486
  /**
482
487
  * Start sending the event stream to the client
@@ -539,19 +544,37 @@ class EventStreamConnection {
539
544
  }
540
545
  async publishEvents(events) {
541
546
  const payload = formatSseList(events);
547
+ if (this.writerIsClosed) {
548
+ try {
549
+ this.h3Event.node.res.end();
550
+ } catch (_) {
551
+ await this.cleanup();
552
+ }
553
+ return;
554
+ }
542
555
  await this.writer.write(this.encoder.encode(payload));
543
556
  }
544
557
  async publishEvent(event) {
545
558
  const payload = formatSse(event);
559
+ if (this.writerIsClosed) {
560
+ try {
561
+ this.h3Event.node.res.end();
562
+ } catch (_) {
563
+ await this.cleanup();
564
+ }
565
+ return;
566
+ }
546
567
  await this.writer.write(this.encoder.encode(payload));
547
568
  }
548
569
  async cleanup() {
549
570
  if (this.pingInterval) {
550
571
  clearInterval(this.pingInterval);
551
572
  }
552
- try {
553
- await this.writer.close();
554
- } catch (_) {
573
+ if (!this.writerIsClosed) {
574
+ try {
575
+ await this.writer.close();
576
+ } catch (_) {
577
+ }
555
578
  }
556
579
  }
557
580
  /**
@@ -562,8 +585,16 @@ class EventStreamConnection {
562
585
  event: "done",
563
586
  data: "this stream has ended"
564
587
  }).catch();
565
- this.h3Event.node.res.end();
566
- await this.cleanup();
588
+ await new Promise((resolve, reject) => {
589
+ node_process.nextTick(() => {
590
+ try {
591
+ this.h3Event.node.res.end();
592
+ resolve(true);
593
+ } catch (err) {
594
+ reject(err);
595
+ }
596
+ });
597
+ });
567
598
  }
568
599
  on(event, callback) {
569
600
  switch (event) {
@@ -574,7 +605,10 @@ class EventStreamConnection {
574
605
  });
575
606
  break;
576
607
  case "end":
577
- this.h3Event.node.req.on("end", callback);
608
+ this.h3Event.node.req.on("end", async () => {
609
+ await callback();
610
+ await this.cleanup();
611
+ });
578
612
  break;
579
613
  }
580
614
  }
@@ -1,5 +1,6 @@
1
1
  import { createError, isError, setResponseStatus, send, eventHandler, isPreflightRequest, setResponseHeader, readRawBody, getValidatedQuery, setHeaders, getHeader, sendStream, defineEventHandler, getQuery, setHeader, createRouter, createApp, sendError } from 'h3';
2
2
  import { a, isAObjectSchema, isARecordSchema, isADiscriminatorSchema } from 'arri-validate';
3
+ import { nextTick } from 'node:process';
3
4
  import { isRpcHttpMethod, removeDisallowedChars } from 'arri-codegen-utils';
4
5
  import { kebabCase, pascalCase } from 'scule';
5
6
 
@@ -458,6 +459,7 @@ class EventStreamConnection {
458
459
  __publicField$2(this, "writable");
459
460
  __publicField$2(this, "readable");
460
461
  __publicField$2(this, "writer");
462
+ __publicField$2(this, "writerIsClosed", false);
461
463
  __publicField$2(this, "encoder");
462
464
  __publicField$2(this, "serializer");
463
465
  __publicField$2(this, "h3Event");
@@ -475,6 +477,9 @@ class EventStreamConnection {
475
477
  this.encoder = new TextEncoder();
476
478
  this.pingIntervalMs = opts.pingInterval ?? 6e4;
477
479
  this.serializer = opts.serializer;
480
+ void this.writer.closed.then(() => {
481
+ this.writerIsClosed = true;
482
+ });
478
483
  }
479
484
  /**
480
485
  * Start sending the event stream to the client
@@ -537,19 +542,37 @@ class EventStreamConnection {
537
542
  }
538
543
  async publishEvents(events) {
539
544
  const payload = formatSseList(events);
545
+ if (this.writerIsClosed) {
546
+ try {
547
+ this.h3Event.node.res.end();
548
+ } catch (_) {
549
+ await this.cleanup();
550
+ }
551
+ return;
552
+ }
540
553
  await this.writer.write(this.encoder.encode(payload));
541
554
  }
542
555
  async publishEvent(event) {
543
556
  const payload = formatSse(event);
557
+ if (this.writerIsClosed) {
558
+ try {
559
+ this.h3Event.node.res.end();
560
+ } catch (_) {
561
+ await this.cleanup();
562
+ }
563
+ return;
564
+ }
544
565
  await this.writer.write(this.encoder.encode(payload));
545
566
  }
546
567
  async cleanup() {
547
568
  if (this.pingInterval) {
548
569
  clearInterval(this.pingInterval);
549
570
  }
550
- try {
551
- await this.writer.close();
552
- } catch (_) {
571
+ if (!this.writerIsClosed) {
572
+ try {
573
+ await this.writer.close();
574
+ } catch (_) {
575
+ }
553
576
  }
554
577
  }
555
578
  /**
@@ -560,8 +583,16 @@ class EventStreamConnection {
560
583
  event: "done",
561
584
  data: "this stream has ended"
562
585
  }).catch();
563
- this.h3Event.node.res.end();
564
- await this.cleanup();
586
+ await new Promise((resolve, reject) => {
587
+ nextTick(() => {
588
+ try {
589
+ this.h3Event.node.res.end();
590
+ resolve(true);
591
+ } catch (err) {
592
+ reject(err);
593
+ }
594
+ });
595
+ });
565
596
  }
566
597
  on(event, callback) {
567
598
  switch (event) {
@@ -572,7 +603,10 @@ class EventStreamConnection {
572
603
  });
573
604
  break;
574
605
  case "end":
575
- this.h3Event.node.req.on("end", callback);
606
+ this.h3Event.node.req.on("end", async () => {
607
+ await callback();
608
+ await this.cleanup();
609
+ });
576
610
  break;
577
611
  }
578
612
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arri",
3
- "version": "0.18.1",
3
+ "version": "0.18.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -41,10 +41,10 @@
41
41
  "scule": "^1.1.1",
42
42
  "uncrypto": "^0.1.3",
43
43
  "@joshmossas/listhen": "1.5.13",
44
- "arri-codegen-dart": "0.18.1",
45
- "arri-codegen-ts": "0.18.1",
46
- "arri-codegen-utils": "0.18.1",
47
- "arri-validate": "0.18.1"
44
+ "arri-codegen-dart": "0.18.2",
45
+ "arri-codegen-utils": "0.18.2",
46
+ "arri-validate": "0.18.2",
47
+ "arri-codegen-ts": "0.18.2"
48
48
  },
49
49
  "peerDependencies": {},
50
50
  "devDependencies": {