@trpc/server 11.0.0-rc.630 → 11.0.0-rc.633

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 (117) hide show
  1. package/dist/@trpc/server/http.d.ts +1 -1
  2. package/dist/@trpc/server/http.d.ts.map +1 -1
  3. package/dist/adapters/aws-lambda/index.js +1 -0
  4. package/dist/adapters/aws-lambda/index.mjs +1 -0
  5. package/dist/adapters/express.js +1 -0
  6. package/dist/adapters/express.mjs +1 -0
  7. package/dist/adapters/fastify/fastifyRequestHandler.js +2 -1
  8. package/dist/adapters/fastify/fastifyRequestHandler.mjs +2 -1
  9. package/dist/adapters/fetch/fetchRequestHandler.js +1 -0
  10. package/dist/adapters/fetch/fetchRequestHandler.mjs +1 -0
  11. package/dist/adapters/next-app-dir/nextAppDirCaller.js +1 -0
  12. package/dist/adapters/next-app-dir/nextAppDirCaller.mjs +1 -0
  13. package/dist/adapters/next-app-dir/notFound.js +1 -0
  14. package/dist/adapters/next-app-dir/notFound.mjs +1 -0
  15. package/dist/adapters/next-app-dir/redirect.js +1 -0
  16. package/dist/adapters/next-app-dir/redirect.mjs +1 -0
  17. package/dist/adapters/next.js +1 -0
  18. package/dist/adapters/next.mjs +1 -0
  19. package/dist/adapters/node-http/incomingMessageToRequest.d.ts +1 -1
  20. package/dist/adapters/node-http/incomingMessageToRequest.d.ts.map +1 -1
  21. package/dist/adapters/node-http/incomingMessageToRequest.js +7 -5
  22. package/dist/adapters/node-http/incomingMessageToRequest.mjs +7 -5
  23. package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
  24. package/dist/adapters/node-http/nodeHTTPRequestHandler.js +9 -42
  25. package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +9 -42
  26. package/dist/adapters/node-http/writeResponse.d.ts +18 -0
  27. package/dist/adapters/node-http/writeResponse.d.ts.map +1 -0
  28. package/dist/adapters/node-http/writeResponse.js +80 -0
  29. package/dist/adapters/node-http/writeResponse.mjs +77 -0
  30. package/dist/adapters/standalone.js +1 -0
  31. package/dist/adapters/standalone.mjs +1 -0
  32. package/dist/adapters/ws.js +1 -0
  33. package/dist/adapters/ws.mjs +1 -0
  34. package/dist/bundle-analysis.json +195 -168
  35. package/dist/http.js +1 -2
  36. package/dist/http.mjs +1 -1
  37. package/dist/index.js +1 -0
  38. package/dist/index.mjs +1 -0
  39. package/dist/rpc.js +1 -0
  40. package/dist/rpc.mjs +1 -0
  41. package/dist/shared.js +1 -0
  42. package/dist/shared.mjs +1 -0
  43. package/dist/unstable-core-do-not-import/http/isAbortError.d.ts +4 -0
  44. package/dist/unstable-core-do-not-import/http/isAbortError.d.ts.map +1 -0
  45. package/dist/unstable-core-do-not-import/http/isAbortError.js +9 -0
  46. package/dist/unstable-core-do-not-import/http/isAbortError.mjs +7 -0
  47. package/dist/unstable-core-do-not-import/http/resolveResponse.d.ts.map +1 -1
  48. package/dist/unstable-core-do-not-import/http/resolveResponse.js +3 -3
  49. package/dist/unstable-core-do-not-import/http/resolveResponse.mjs +3 -3
  50. package/dist/unstable-core-do-not-import/initTRPC.js +2 -2
  51. package/dist/unstable-core-do-not-import/initTRPC.mjs +2 -2
  52. package/dist/unstable-core-do-not-import/rootConfig.d.ts +14 -14
  53. package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -1
  54. package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts +7 -10
  55. package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts.map +1 -1
  56. package/dist/unstable-core-do-not-import/stream/jsonl.d.ts +6 -9
  57. package/dist/unstable-core-do-not-import/stream/jsonl.d.ts.map +1 -1
  58. package/dist/unstable-core-do-not-import/stream/jsonl.js +75 -124
  59. package/dist/unstable-core-do-not-import/stream/jsonl.mjs +76 -125
  60. package/dist/unstable-core-do-not-import/stream/sse.d.ts +11 -1
  61. package/dist/unstable-core-do-not-import/stream/sse.d.ts.map +1 -1
  62. package/dist/unstable-core-do-not-import/stream/sse.js +154 -86
  63. package/dist/unstable-core-do-not-import/stream/sse.mjs +155 -87
  64. package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.d.ts +10 -10
  65. package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.d.ts.map +1 -1
  66. package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.js +47 -34
  67. package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.mjs +47 -34
  68. package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.d.ts +0 -4
  69. package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.d.ts.map +1 -1
  70. package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.js +0 -11
  71. package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.mjs +1 -11
  72. package/dist/unstable-core-do-not-import/stream/utils/disposablePromiseTimer.d.ts +6 -0
  73. package/dist/unstable-core-do-not-import/stream/utils/disposablePromiseTimer.d.ts.map +1 -0
  74. package/dist/unstable-core-do-not-import/stream/utils/disposablePromiseTimer.js +28 -0
  75. package/dist/unstable-core-do-not-import/stream/utils/disposablePromiseTimer.mjs +25 -0
  76. package/dist/unstable-core-do-not-import/stream/utils/withPing.d.ts.map +1 -1
  77. package/dist/unstable-core-do-not-import/stream/utils/withPing.js +17 -17
  78. package/dist/unstable-core-do-not-import/stream/utils/withPing.mjs +17 -17
  79. package/dist/unstable-core-do-not-import/stream/utils/withRefCount.d.ts +17 -0
  80. package/dist/unstable-core-do-not-import/stream/utils/withRefCount.d.ts.map +1 -0
  81. package/dist/unstable-core-do-not-import/stream/utils/withRefCount.js +59 -0
  82. package/dist/unstable-core-do-not-import/stream/utils/withRefCount.mjs +57 -0
  83. package/dist/unstable-core-do-not-import/transformer.d.ts +1 -4
  84. package/dist/unstable-core-do-not-import/transformer.d.ts.map +1 -1
  85. package/dist/unstable-core-do-not-import.d.ts +2 -2
  86. package/dist/unstable-core-do-not-import.d.ts.map +1 -1
  87. package/dist/unstable-core-do-not-import.js +2 -2
  88. package/dist/unstable-core-do-not-import.mjs +1 -1
  89. package/package.json +3 -3
  90. package/src/@trpc/server/http.ts +0 -1
  91. package/src/adapters/fastify/fastifyRequestHandler.ts +1 -1
  92. package/src/adapters/node-http/incomingMessageToRequest.ts +8 -4
  93. package/src/adapters/node-http/nodeHTTPRequestHandler.ts +8 -46
  94. package/src/adapters/node-http/writeResponse.ts +91 -0
  95. package/src/unstable-core-do-not-import/http/isAbortError.ts +7 -0
  96. package/src/unstable-core-do-not-import/http/resolveResponse.ts +3 -4
  97. package/src/unstable-core-do-not-import/initTRPC.ts +1 -1
  98. package/src/unstable-core-do-not-import/rootConfig.ts +17 -17
  99. package/src/unstable-core-do-not-import/rpc/envelopes.ts +7 -12
  100. package/src/unstable-core-do-not-import/stream/jsonl.ts +85 -154
  101. package/src/unstable-core-do-not-import/stream/sse.ts +179 -92
  102. package/src/unstable-core-do-not-import/stream/utils/asyncIterable.ts +58 -37
  103. package/src/unstable-core-do-not-import/stream/utils/createReadableStream.ts +0 -13
  104. package/src/unstable-core-do-not-import/stream/utils/disposablePromiseTimer.ts +27 -0
  105. package/src/unstable-core-do-not-import/stream/utils/withPing.ts +31 -19
  106. package/src/unstable-core-do-not-import/stream/utils/withRefCount.ts +93 -0
  107. package/src/unstable-core-do-not-import.ts +2 -2
  108. package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts +0 -24
  109. package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts.map +0 -1
  110. package/dist/unstable-core-do-not-import/http/batchStreamFormatter.js +0 -32
  111. package/dist/unstable-core-do-not-import/http/batchStreamFormatter.mjs +0 -30
  112. package/dist/unstable-core-do-not-import/stream/utils/promiseTimer.d.ts +0 -8
  113. package/dist/unstable-core-do-not-import/stream/utils/promiseTimer.d.ts.map +0 -1
  114. package/dist/unstable-core-do-not-import/stream/utils/promiseTimer.js +0 -38
  115. package/dist/unstable-core-do-not-import/stream/utils/promiseTimer.mjs +0 -36
  116. package/src/unstable-core-do-not-import/http/batchStreamFormatter.ts +0 -29
  117. package/src/unstable-core-do-not-import/stream/utils/promiseTimer.ts +0 -40
@@ -0,0 +1,93 @@
1
+ // Callback function type that is called when a collection is drained
2
+ type OnDrain = () => void;
3
+
4
+ // Interface for objects that can be activated
5
+ export interface RefCount {
6
+ activate(): void;
7
+ }
8
+
9
+ // Map type that includes ref counting capabilities
10
+ export interface RefCountMap<TKey, TValue>
11
+ extends Map<TKey, TValue>,
12
+ RefCount {}
13
+
14
+ // Set type that includes ref counting capabilities
15
+ export interface RefCountSet<TValue> extends Set<TValue>, RefCount {}
16
+
17
+ /**
18
+ * Adds reference counting capabilities to a Map or Set collection.
19
+ * The collection can be activated, after which it will trigger a drain callback when emptied.
20
+ * Once drained, the collection cannot be modified further.
21
+ */
22
+ export function withRefCount<TKey, TValue>(
23
+ map: Map<TKey, TValue>,
24
+ onDrain: OnDrain,
25
+ ): RefCountMap<TKey, TValue>;
26
+ export function withRefCount<TValue>(
27
+ set: Set<TValue>,
28
+ onDrain: OnDrain,
29
+ ): RefCountSet<TValue>;
30
+ export function withRefCount(
31
+ _obj: Set<any> | Map<any, any>,
32
+ onDrain: OnDrain,
33
+ ): RefCountMap<any, any> & RefCountSet<any> {
34
+ const obj = _obj as any;
35
+
36
+ // Track whether the collection has been drained
37
+ let drained = false;
38
+ // Track whether the collection has been activated
39
+ let active = false;
40
+
41
+ // Check if collection should be drained (empty and active)
42
+ const checkDrain = () => {
43
+ if (!drained && active && obj.size === 0) {
44
+ onDrain();
45
+ drained = true;
46
+ }
47
+ };
48
+
49
+ // Create proxy to intercept collection operations
50
+ return new Proxy(obj, {
51
+ get(_, prop) {
52
+ // Handle activation
53
+ if (prop === 'activate') {
54
+ return () => {
55
+ active = true;
56
+ checkDrain();
57
+ };
58
+ }
59
+
60
+ // Handle adding items - prevent if already drained
61
+ if (prop === 'set' || prop === 'add') {
62
+ return (...args: any[]) => {
63
+ if (drained) {
64
+ throw new Error('Already drained');
65
+ }
66
+
67
+ return obj[prop](...args);
68
+ };
69
+ }
70
+
71
+ // Handle removing items - check if should drain after
72
+ if (prop === 'delete' || prop === 'clear') {
73
+ return (...args: any[]) => {
74
+ try {
75
+ return obj[prop](...args);
76
+ } finally {
77
+ checkDrain();
78
+ }
79
+ };
80
+ }
81
+ // Pass through other method calls
82
+ const target = obj[prop];
83
+ if (typeof target === 'function') {
84
+ return (...args: any[]) => {
85
+ return obj[prop](...args);
86
+ };
87
+ }
88
+
89
+ // Pass through property access
90
+ return target;
91
+ },
92
+ }) as never as RefCountMap<any, any> & RefCountSet<any>;
93
+ }
@@ -15,11 +15,11 @@ export * from './unstable-core-do-not-import/createProxy';
15
15
  export * from './unstable-core-do-not-import/error/formatter';
16
16
  export * from './unstable-core-do-not-import/error/getErrorShape';
17
17
  export * from './unstable-core-do-not-import/error/TRPCError';
18
- export * from './unstable-core-do-not-import/http/batchStreamFormatter';
19
18
  export * from './unstable-core-do-not-import/http/contentType';
20
19
  export * from './unstable-core-do-not-import/http/contentTypeParsers';
21
20
  export * from './unstable-core-do-not-import/http/formDataToObject';
22
21
  export * from './unstable-core-do-not-import/http/getHTTPStatusCode';
22
+ export * from './unstable-core-do-not-import/http/isAbortError';
23
23
  export * from './unstable-core-do-not-import/http/parseConnectionParams';
24
24
  export * from './unstable-core-do-not-import/http/resolveResponse';
25
25
  export * from './unstable-core-do-not-import/http/types';
@@ -32,8 +32,8 @@ export * from './unstable-core-do-not-import/rootConfig';
32
32
  export * from './unstable-core-do-not-import/router';
33
33
  export * from './unstable-core-do-not-import/rpc';
34
34
  export * from './unstable-core-do-not-import/stream/jsonl';
35
- export * from './unstable-core-do-not-import/stream/sse';
36
35
  export * from './unstable-core-do-not-import/stream/sse.types';
36
+ export * from './unstable-core-do-not-import/stream/sse';
37
37
  export * from './unstable-core-do-not-import/stream/tracked';
38
38
  export * from './unstable-core-do-not-import/stream/utils/createDeferred';
39
39
  export * from './unstable-core-do-not-import/transformer';
@@ -1,24 +0,0 @@
1
- /**
2
- * Format a batch response as a line-delimited JSON stream
3
- * that the `unstable_httpBatchStreamLink` can parse:
4
- *
5
- * @example
6
- * ```ts
7
- * const formatter = getBatchStreamFormatter();
8
- * res.send(formatter(1, 'response #2'));
9
- * res.send(formatter(0, 'response #1'));
10
- * res.send(formatter.end());
11
- * ```
12
- *
13
- * Expected format:
14
- * ```json
15
- * {"1":"response #2"
16
- * ,"0":"response #1"
17
- * }
18
- * ```
19
- */
20
- export declare function getBatchStreamFormatter(): {
21
- (index: number, string: string): string;
22
- end(): string;
23
- };
24
- //# sourceMappingURL=batchStreamFormatter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"batchStreamFormatter.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/batchStreamFormatter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,uBAAuB;YAEd,MAAM,UAAU,MAAM;;EAO9C"}
@@ -1,32 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * Format a batch response as a line-delimited JSON stream
5
- * that the `unstable_httpBatchStreamLink` can parse:
6
- *
7
- * @example
8
- * ```ts
9
- * const formatter = getBatchStreamFormatter();
10
- * res.send(formatter(1, 'response #2'));
11
- * res.send(formatter(0, 'response #1'));
12
- * res.send(formatter.end());
13
- * ```
14
- *
15
- * Expected format:
16
- * ```json
17
- * {"1":"response #2"
18
- * ,"0":"response #1"
19
- * }
20
- * ```
21
- */ function getBatchStreamFormatter() {
22
- let first = true;
23
- function format(index, string) {
24
- const prefix = first ? '{' : ',';
25
- first = false;
26
- return `${prefix}"${index}":${string}\n`;
27
- }
28
- format.end = ()=>'}';
29
- return format;
30
- }
31
-
32
- exports.getBatchStreamFormatter = getBatchStreamFormatter;
@@ -1,30 +0,0 @@
1
- /**
2
- * Format a batch response as a line-delimited JSON stream
3
- * that the `unstable_httpBatchStreamLink` can parse:
4
- *
5
- * @example
6
- * ```ts
7
- * const formatter = getBatchStreamFormatter();
8
- * res.send(formatter(1, 'response #2'));
9
- * res.send(formatter(0, 'response #1'));
10
- * res.send(formatter.end());
11
- * ```
12
- *
13
- * Expected format:
14
- * ```json
15
- * {"1":"response #2"
16
- * ,"0":"response #1"
17
- * }
18
- * ```
19
- */ function getBatchStreamFormatter() {
20
- let first = true;
21
- function format(index, string) {
22
- const prefix = first ? '{' : ',';
23
- first = false;
24
- return `${prefix}"${index}":${string}\n`;
25
- }
26
- format.end = ()=>'}';
27
- return format;
28
- }
29
-
30
- export { getBatchStreamFormatter };
@@ -1,8 +0,0 @@
1
- export declare function createPromiseTimer(ms: number): {
2
- readonly promise: Promise<void>;
3
- start: () => PromiseTimer;
4
- reset: () => PromiseTimer;
5
- clear: () => PromiseTimer;
6
- };
7
- export type PromiseTimer = ReturnType<typeof createPromiseTimer>;
8
- //# sourceMappingURL=promiseTimer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"promiseTimer.d.ts","sourceRoot":"","sources":["../../../../src/unstable-core-do-not-import/stream/utils/promiseTimer.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM;;iBAezB,YAAY;iBAQZ,YAAY;iBAMZ,YAAY;EAO/B;AACD,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
@@ -1,38 +0,0 @@
1
- 'use strict';
2
-
3
- var createDeferred = require('./createDeferred.js');
4
-
5
- function createPromiseTimer(ms) {
6
- let deferred = createDeferred.createDeferred();
7
- let timeout = null;
8
- const timer = {
9
- get promise () {
10
- return deferred.promise;
11
- },
12
- start,
13
- reset,
14
- clear
15
- };
16
- return timer;
17
- function start() {
18
- if (timeout != null) {
19
- throw new Error('PromiseTimer already started.');
20
- }
21
- timeout = setTimeout(deferred.resolve, ms);
22
- return timer;
23
- }
24
- function reset() {
25
- clear();
26
- deferred = createDeferred.createDeferred();
27
- return timer;
28
- }
29
- function clear() {
30
- if (timeout != null) {
31
- clearTimeout(timeout);
32
- timeout = null;
33
- }
34
- return timer;
35
- }
36
- }
37
-
38
- exports.createPromiseTimer = createPromiseTimer;
@@ -1,36 +0,0 @@
1
- import { createDeferred } from './createDeferred.mjs';
2
-
3
- function createPromiseTimer(ms) {
4
- let deferred = createDeferred();
5
- let timeout = null;
6
- const timer = {
7
- get promise () {
8
- return deferred.promise;
9
- },
10
- start,
11
- reset,
12
- clear
13
- };
14
- return timer;
15
- function start() {
16
- if (timeout != null) {
17
- throw new Error('PromiseTimer already started.');
18
- }
19
- timeout = setTimeout(deferred.resolve, ms);
20
- return timer;
21
- }
22
- function reset() {
23
- clear();
24
- deferred = createDeferred();
25
- return timer;
26
- }
27
- function clear() {
28
- if (timeout != null) {
29
- clearTimeout(timeout);
30
- timeout = null;
31
- }
32
- return timer;
33
- }
34
- }
35
-
36
- export { createPromiseTimer };
@@ -1,29 +0,0 @@
1
- /**
2
- * Format a batch response as a line-delimited JSON stream
3
- * that the `unstable_httpBatchStreamLink` can parse:
4
- *
5
- * @example
6
- * ```ts
7
- * const formatter = getBatchStreamFormatter();
8
- * res.send(formatter(1, 'response #2'));
9
- * res.send(formatter(0, 'response #1'));
10
- * res.send(formatter.end());
11
- * ```
12
- *
13
- * Expected format:
14
- * ```json
15
- * {"1":"response #2"
16
- * ,"0":"response #1"
17
- * }
18
- * ```
19
- */
20
- export function getBatchStreamFormatter() {
21
- let first = true;
22
- function format(index: number, string: string) {
23
- const prefix = first ? '{' : ',';
24
- first = false;
25
- return `${prefix}"${index}":${string}\n`;
26
- }
27
- format.end = () => '}';
28
- return format;
29
- }
@@ -1,40 +0,0 @@
1
- import { createDeferred } from './createDeferred';
2
-
3
- export function createPromiseTimer(ms: number) {
4
- let deferred = createDeferred<void>();
5
- let timeout: ReturnType<typeof setTimeout> | null = null;
6
-
7
- const timer = {
8
- get promise() {
9
- return deferred.promise;
10
- },
11
-
12
- start,
13
- reset,
14
- clear,
15
- };
16
- return timer;
17
-
18
- function start(): PromiseTimer {
19
- if (timeout != null) {
20
- throw new Error('PromiseTimer already started.');
21
- }
22
- timeout = setTimeout(deferred.resolve, ms);
23
- return timer;
24
- }
25
-
26
- function reset(): PromiseTimer {
27
- clear();
28
- deferred = createDeferred();
29
- return timer;
30
- }
31
-
32
- function clear(): PromiseTimer {
33
- if (timeout != null) {
34
- clearTimeout(timeout);
35
- timeout = null;
36
- }
37
- return timer;
38
- }
39
- }
40
- export type PromiseTimer = ReturnType<typeof createPromiseTimer>;