@trpc/server 11.0.0-rc.589 → 11.0.0-rc.590

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.
Files changed (26) hide show
  1. package/dist/bundle-analysis.json +114 -111
  2. package/dist/unstable-core-do-not-import/http/resolveResponse.d.ts.map +1 -1
  3. package/dist/unstable-core-do-not-import/http/resolveResponse.js +30 -16
  4. package/dist/unstable-core-do-not-import/http/resolveResponse.mjs +31 -17
  5. package/dist/unstable-core-do-not-import/stream/sse.d.ts +1 -0
  6. package/dist/unstable-core-do-not-import/stream/sse.d.ts.map +1 -1
  7. package/dist/unstable-core-do-not-import/stream/sse.js +3 -2
  8. package/dist/unstable-core-do-not-import/stream/sse.mjs +3 -2
  9. package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.d.ts +2 -1
  10. package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.d.ts.map +1 -1
  11. package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.js +2 -2
  12. package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.mjs +2 -2
  13. package/dist/unstable-core-do-not-import/stream/utils/promiseTimer.js +1 -1
  14. package/dist/unstable-core-do-not-import/stream/utils/promiseTimer.mjs +1 -1
  15. package/dist/unstable-core-do-not-import/utils.d.ts +13 -0
  16. package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -1
  17. package/dist/unstable-core-do-not-import/utils.js +41 -0
  18. package/dist/unstable-core-do-not-import/utils.mjs +39 -1
  19. package/dist/unstable-core-do-not-import.js +3 -0
  20. package/dist/unstable-core-do-not-import.mjs +1 -1
  21. package/package.json +2 -2
  22. package/src/unstable-core-do-not-import/http/resolveResponse.ts +39 -21
  23. package/src/unstable-core-do-not-import/stream/sse.ts +14 -4
  24. package/src/unstable-core-do-not-import/stream/utils/asyncIterable.ts +3 -2
  25. package/src/unstable-core-do-not-import/stream/utils/promiseTimer.ts +1 -1
  26. package/src/unstable-core-do-not-import/utils.ts +48 -0
@@ -27,6 +27,7 @@ export async function* withCancel<T>(
27
27
  interface TakeWithGraceOptions {
28
28
  count: number;
29
29
  gracePeriodMs: number;
30
+ onCancel?: () => void;
30
31
  }
31
32
 
32
33
  /**
@@ -36,7 +37,7 @@ interface TakeWithGraceOptions {
36
37
  */
37
38
  export async function* takeWithGrace<T>(
38
39
  iterable: AsyncIterable<T>,
39
- { count, gracePeriodMs }: TakeWithGraceOptions,
40
+ { count, gracePeriodMs, onCancel }: TakeWithGraceOptions,
40
41
  ): AsyncGenerator<T> {
41
42
  const iterator = iterable[Symbol.asyncIterator]();
42
43
  const timer = createPromiseTimer(gracePeriodMs);
@@ -53,7 +54,7 @@ export async function* takeWithGrace<T>(
53
54
  }
54
55
  yield result.value;
55
56
  if (--count === 0) {
56
- timer.start();
57
+ timer.start().promise.then(onCancel, noop);
57
58
  }
58
59
  }
59
60
  } finally {
@@ -17,7 +17,7 @@ export function createPromiseTimer(ms: number) {
17
17
 
18
18
  function start(): PromiseTimer {
19
19
  if (timeout != null) {
20
- throw new Error("PromiseTimer already started.");
20
+ throw new Error('PromiseTimer already started.');
21
21
  }
22
22
  timeout = setTimeout(deferred.resolve, ms);
23
23
  return timer;
@@ -68,3 +68,51 @@ export function noop(): void {}
68
68
  export function identity<T>(it: T): T {
69
69
  return it;
70
70
  }
71
+
72
+ /**
73
+ * Generic runtime assertion function. Throws, if the condition is not `true`.
74
+ *
75
+ * Can be used as a slightly less dangerous variant of type assertions. Code
76
+ * mistakes would be revealed at runtime then (hopefully during testing).
77
+ */
78
+ export function assert(
79
+ condition: boolean,
80
+ msg = 'no additional info',
81
+ ): asserts condition {
82
+ if (!condition) {
83
+ throw new Error(`AssertionError: ${msg}`);
84
+ }
85
+ }
86
+
87
+ export function sleep(ms = 0): Promise<void> {
88
+ return new Promise<void>((res) => setTimeout(res, ms));
89
+ }
90
+
91
+ /**
92
+ * Ponyfill for
93
+ * [`AbortSignal.any`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static).
94
+ */
95
+ export function abortSignalsAnyPonyfill(signals: AbortSignal[]): AbortSignal {
96
+ if (typeof AbortSignal.any === 'function') {
97
+ return AbortSignal.any(signals);
98
+ }
99
+
100
+ const ac = new AbortController();
101
+
102
+ for (const signal of signals) {
103
+ if (signal.aborted) {
104
+ trigger();
105
+ } else if (!ac.signal.aborted) {
106
+ signal.addEventListener('abort', trigger, { once: true });
107
+ }
108
+ }
109
+
110
+ return ac.signal;
111
+
112
+ function trigger() {
113
+ ac.abort();
114
+ for (const signal of signals) {
115
+ signal.removeEventListener('abort', trigger);
116
+ }
117
+ }
118
+ }