@trpc/server 11.0.0-alpha-tmp-app-router-example.388 → 11.0.0-alpha-tmp-issues-5851-take-two.448

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 (139) hide show
  1. package/dist/@trpc/server/http.d.ts +1 -2
  2. package/dist/@trpc/server/http.d.ts.map +1 -1
  3. package/dist/@trpc/server/index.d.ts +1 -1
  4. package/dist/@trpc/server/index.d.ts.map +1 -1
  5. package/dist/@trpc/server/rpc.d.ts +1 -1
  6. package/dist/@trpc/server/rpc.d.ts.map +1 -1
  7. package/dist/adapters/aws-lambda/getPlanner.d.ts.map +1 -1
  8. package/dist/adapters/aws-lambda/getPlanner.js +19 -2
  9. package/dist/adapters/aws-lambda/getPlanner.mjs +19 -2
  10. package/dist/adapters/next-app-dir/nextAppDirCaller.d.ts.map +1 -1
  11. package/dist/adapters/next-app-dir/nextAppDirCaller.js +1 -1
  12. package/dist/adapters/next-app-dir/nextAppDirCaller.mjs +1 -1
  13. package/dist/adapters/next-app-dir/redirect.d.ts.map +1 -1
  14. package/dist/adapters/next.js +1 -1
  15. package/dist/adapters/next.mjs +1 -1
  16. package/dist/adapters/node-http/incomingMessageToRequest.d.ts +0 -1
  17. package/dist/adapters/node-http/incomingMessageToRequest.d.ts.map +1 -1
  18. package/dist/adapters/node-http/incomingMessageToRequest.js +3 -1
  19. package/dist/adapters/node-http/incomingMessageToRequest.mjs +3 -1
  20. package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
  21. package/dist/adapters/node-http/nodeHTTPRequestHandler.js +30 -7
  22. package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +30 -7
  23. package/dist/adapters/node-http/types.d.ts +0 -1
  24. package/dist/adapters/node-http/types.d.ts.map +1 -1
  25. package/dist/adapters/standalone.d.ts +0 -1
  26. package/dist/adapters/standalone.d.ts.map +1 -1
  27. package/dist/adapters/ws.d.ts +3 -4
  28. package/dist/adapters/ws.d.ts.map +1 -1
  29. package/dist/adapters/ws.js +172 -114
  30. package/dist/adapters/ws.mjs +172 -114
  31. package/dist/bundle-analysis.json +236 -155
  32. package/dist/http.js +3 -0
  33. package/dist/http.mjs +1 -0
  34. package/dist/index.js +7 -5
  35. package/dist/index.mjs +3 -2
  36. package/dist/observable/observable.d.ts +1 -0
  37. package/dist/observable/observable.d.ts.map +1 -1
  38. package/dist/observable/observable.js +55 -0
  39. package/dist/observable/observable.mjs +55 -1
  40. package/dist/unstable-core-do-not-import/createProxy.d.ts +3 -3
  41. package/dist/unstable-core-do-not-import/createProxy.d.ts.map +1 -1
  42. package/dist/unstable-core-do-not-import/createProxy.js +15 -6
  43. package/dist/unstable-core-do-not-import/createProxy.mjs +15 -6
  44. package/dist/unstable-core-do-not-import/http/contentType.d.ts +7 -4
  45. package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -1
  46. package/dist/unstable-core-do-not-import/http/contentType.js +60 -17
  47. package/dist/unstable-core-do-not-import/http/contentType.mjs +61 -18
  48. package/dist/unstable-core-do-not-import/http/formDataToObject.d.ts.map +1 -0
  49. package/dist/unstable-core-do-not-import/http/formDataToObject.js +40 -0
  50. package/dist/unstable-core-do-not-import/http/formDataToObject.mjs +38 -0
  51. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +1 -1
  52. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.js +4 -4
  53. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +4 -4
  54. package/dist/unstable-core-do-not-import/http/parseConnectionParams.d.ts +4 -0
  55. package/dist/unstable-core-do-not-import/http/parseConnectionParams.d.ts.map +1 -0
  56. package/dist/unstable-core-do-not-import/http/parseConnectionParams.js +42 -0
  57. package/dist/unstable-core-do-not-import/http/parseConnectionParams.mjs +39 -0
  58. package/dist/unstable-core-do-not-import/http/resolveResponse.d.ts.map +1 -1
  59. package/dist/unstable-core-do-not-import/http/resolveResponse.js +302 -149
  60. package/dist/unstable-core-do-not-import/http/resolveResponse.mjs +301 -148
  61. package/dist/unstable-core-do-not-import/http/types.d.ts +26 -2
  62. package/dist/unstable-core-do-not-import/http/types.d.ts.map +1 -1
  63. package/dist/unstable-core-do-not-import/initTRPC.d.ts +12 -12
  64. package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +1 -1
  65. package/dist/unstable-core-do-not-import/middleware.d.ts +3 -3
  66. package/dist/unstable-core-do-not-import/middleware.d.ts.map +1 -1
  67. package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +3 -1
  68. package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +1 -1
  69. package/dist/unstable-core-do-not-import/rootConfig.d.ts +12 -0
  70. package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -1
  71. package/dist/unstable-core-do-not-import/router.d.ts +2 -2
  72. package/dist/unstable-core-do-not-import/router.d.ts.map +1 -1
  73. package/dist/unstable-core-do-not-import/router.js +7 -2
  74. package/dist/unstable-core-do-not-import/router.mjs +7 -2
  75. package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts +7 -0
  76. package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts.map +1 -1
  77. package/dist/unstable-core-do-not-import/rpc/index.d.ts +1 -1
  78. package/dist/unstable-core-do-not-import/rpc/index.d.ts.map +1 -1
  79. package/dist/unstable-core-do-not-import/stream/{stream.d.ts → jsonl.d.ts} +5 -5
  80. package/dist/unstable-core-do-not-import/stream/jsonl.d.ts.map +1 -0
  81. package/dist/unstable-core-do-not-import/stream/{stream.js → jsonl.js} +148 -111
  82. package/dist/unstable-core-do-not-import/stream/{stream.mjs → jsonl.mjs} +147 -110
  83. package/dist/unstable-core-do-not-import/stream/sse.d.ts +86 -0
  84. package/dist/unstable-core-do-not-import/stream/sse.d.ts.map +1 -0
  85. package/dist/unstable-core-do-not-import/stream/sse.js +178 -0
  86. package/dist/unstable-core-do-not-import/stream/sse.mjs +172 -0
  87. package/dist/unstable-core-do-not-import/stream/utils/createDeferred.d.ts +18 -0
  88. package/dist/unstable-core-do-not-import/stream/utils/createDeferred.d.ts.map +1 -0
  89. package/dist/unstable-core-do-not-import/stream/utils/createDeferred.js +46 -0
  90. package/dist/unstable-core-do-not-import/stream/utils/createDeferred.mjs +43 -0
  91. package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.d.ts +10 -0
  92. package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.d.ts.map +1 -0
  93. package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.js +31 -0
  94. package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.mjs +29 -0
  95. package/dist/unstable-core-do-not-import/stream/utils/createServer.d.ts +7 -0
  96. package/dist/unstable-core-do-not-import/stream/utils/createServer.d.ts.map +1 -0
  97. package/dist/unstable-core-do-not-import/transformer.d.ts +5 -5
  98. package/dist/unstable-core-do-not-import/utils.d.ts +4 -0
  99. package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -1
  100. package/dist/unstable-core-do-not-import/utils.js +4 -0
  101. package/dist/unstable-core-do-not-import/utils.mjs +4 -1
  102. package/dist/unstable-core-do-not-import.d.ts +5 -2
  103. package/dist/unstable-core-do-not-import.d.ts.map +1 -1
  104. package/dist/unstable-core-do-not-import.js +19 -7
  105. package/dist/unstable-core-do-not-import.mjs +6 -3
  106. package/package.json +6 -6
  107. package/src/@trpc/server/http.ts +7 -2
  108. package/src/@trpc/server/index.ts +1 -0
  109. package/src/@trpc/server/rpc.ts +1 -0
  110. package/src/adapters/aws-lambda/getPlanner.ts +21 -2
  111. package/src/adapters/next-app-dir/nextAppDirCaller.ts +2 -1
  112. package/src/adapters/node-http/incomingMessageToRequest.ts +3 -2
  113. package/src/adapters/node-http/nodeHTTPRequestHandler.ts +32 -7
  114. package/src/adapters/ws.ts +193 -107
  115. package/src/observable/observable.ts +63 -0
  116. package/src/unstable-core-do-not-import/createProxy.ts +23 -8
  117. package/src/unstable-core-do-not-import/http/contentType.ts +83 -21
  118. package/src/{adapters/next-app-dir → unstable-core-do-not-import/http}/formDataToObject.ts +18 -10
  119. package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +4 -7
  120. package/src/unstable-core-do-not-import/http/parseConnectionParams.ts +49 -0
  121. package/src/unstable-core-do-not-import/http/resolveResponse.ts +333 -164
  122. package/src/unstable-core-do-not-import/http/types.ts +31 -2
  123. package/src/unstable-core-do-not-import/procedureBuilder.ts +8 -1
  124. package/src/unstable-core-do-not-import/rootConfig.ts +12 -0
  125. package/src/unstable-core-do-not-import/router.ts +47 -35
  126. package/src/unstable-core-do-not-import/rpc/envelopes.ts +9 -0
  127. package/src/unstable-core-do-not-import/rpc/index.ts +1 -0
  128. package/src/unstable-core-do-not-import/stream/{stream.ts → jsonl.ts} +163 -110
  129. package/src/unstable-core-do-not-import/stream/sse.ts +288 -0
  130. package/src/unstable-core-do-not-import/stream/utils/createDeferred.ts +48 -0
  131. package/src/unstable-core-do-not-import/stream/utils/createReadableStream.ts +31 -0
  132. package/src/unstable-core-do-not-import/stream/utils/createServer.ts +44 -0
  133. package/src/unstable-core-do-not-import/utils.ts +5 -0
  134. package/src/unstable-core-do-not-import.ts +5 -2
  135. package/dist/adapters/next-app-dir/formDataToObject.d.ts.map +0 -1
  136. package/dist/adapters/next-app-dir/formDataToObject.js +0 -34
  137. package/dist/adapters/next-app-dir/formDataToObject.mjs +0 -32
  138. package/dist/unstable-core-do-not-import/stream/stream.d.ts.map +0 -1
  139. /package/dist/{adapters/next-app-dir → unstable-core-do-not-import/http}/formDataToObject.d.ts +0 -0
@@ -0,0 +1,288 @@
1
+ import { getTRPCErrorFromUnknown } from '../error/TRPCError';
2
+ import type { ValidateShape } from '../types';
3
+ import { run } from '../utils';
4
+ import type { ConsumerOnError } from './jsonl';
5
+ import { createTimeoutPromise } from './utils/createDeferred';
6
+ import { createReadableStream } from './utils/createReadableStream';
7
+
8
+ type Serialize = (value: any) => any;
9
+ type Deserialize = (value: any) => any;
10
+
11
+ /**
12
+ * Server-sent Event Message
13
+ * @see https://html.spec.whatwg.org/multipage/server-sent-events.html
14
+ * @public
15
+ */
16
+ export interface SSEMessage {
17
+ /**
18
+ * The data field of the message - this can be anything
19
+ */
20
+ data: unknown;
21
+ /**
22
+ * The id for this message
23
+ * Passing this id will allow the client to resume the connection from this point if the connection is lost
24
+ * @see https://html.spec.whatwg.org/multipage/server-sent-events.html#the-last-event-id-header
25
+ */
26
+ id: string;
27
+ }
28
+
29
+ const sseSymbol = Symbol('SSEMessageEnvelope');
30
+ export type SSEMessageEnvelope<TData> = [typeof sseSymbol, TData];
31
+
32
+ /**
33
+ * Produce a typed server-sent event message
34
+ */
35
+ export function sse<TData extends SSEMessage>(
36
+ event: ValidateShape<TData, SSEMessage>,
37
+ ): SSEMessageEnvelope<TData> {
38
+ if (event.id === '') {
39
+ // This could be removed by using different event names for `yield sse(x)`-emitted events and `yield y`-emitted events
40
+ throw new Error(
41
+ '`id` must not be an empty string as empty string is the same as not setting the id at all',
42
+ );
43
+ }
44
+ return [sseSymbol, event as TData];
45
+ }
46
+
47
+ export function isSSEMessageEnvelope<TData extends SSEMessage>(
48
+ value: unknown,
49
+ ): value is SSEMessageEnvelope<TData> {
50
+ return Array.isArray(value) && value[0] === sseSymbol;
51
+ }
52
+
53
+ export type SerializedSSEvent = Omit<SSEMessage, 'data'> & {
54
+ data?: string;
55
+ };
56
+
57
+ /**
58
+ * @internal
59
+ */
60
+ export interface PingOptions {
61
+ /**
62
+ * Enable ping comments sent from the server
63
+ * @default false
64
+ */
65
+ enabled: boolean;
66
+ /**
67
+ * Interval in milliseconds
68
+ * @default 1000
69
+ */
70
+ intervalMs?: number;
71
+ }
72
+
73
+ export interface SSEStreamProducerOptions {
74
+ serialize?: Serialize;
75
+ data: AsyncIterable<unknown>;
76
+ maxDepth?: number;
77
+ ping?: PingOptions;
78
+ /**
79
+ * Maximum duration in milliseconds for the request before ending the stream
80
+ * Only useful for serverless runtimes
81
+ * @default undefined
82
+ */
83
+ maxDurationMs?: number;
84
+ /**
85
+ * End the request immediately after data is sent
86
+ * Only useful for serverless runtimes that do not support streaming responses
87
+ * @default false
88
+ */
89
+ emitAndEndImmediately?: boolean;
90
+ }
91
+
92
+ type SSEvent = Partial<
93
+ SSEMessage & {
94
+ comment: string;
95
+ event: string;
96
+ }
97
+ >;
98
+ /**
99
+ *
100
+ * @see https://html.spec.whatwg.org/multipage/server-sent-events.html
101
+ */
102
+ export function sseStreamProducer(opts: SSEStreamProducerOptions) {
103
+ const stream = createReadableStream<SSEvent>();
104
+ stream.controller.enqueue({
105
+ comment: 'connected',
106
+ });
107
+
108
+ const { serialize = (v) => v } = opts;
109
+
110
+ const ping: Required<PingOptions> = {
111
+ enabled: opts.ping?.enabled ?? false,
112
+ intervalMs: opts.ping?.intervalMs ?? 1000,
113
+ };
114
+
115
+ run(async () => {
116
+ const iterator = opts.data[Symbol.asyncIterator]();
117
+
118
+ const closedPromise = stream.cancelledPromise.then(() => 'closed' as const);
119
+ const maxDurationPromise = createTimeoutPromise(
120
+ opts.maxDurationMs ?? Infinity,
121
+ 'maxDuration' as const,
122
+ );
123
+
124
+ let nextPromise = iterator.next();
125
+
126
+ while (true) {
127
+ const pingPromise = createTimeoutPromise(
128
+ ping.enabled ? ping.intervalMs : Infinity,
129
+ 'ping' as const,
130
+ );
131
+ const next = await Promise.race([
132
+ nextPromise.catch(getTRPCErrorFromUnknown),
133
+ pingPromise.promise,
134
+ closedPromise,
135
+ maxDurationPromise.promise,
136
+ ]);
137
+
138
+ pingPromise.clear();
139
+ if (next === 'closed') {
140
+ break;
141
+ }
142
+ if (next === 'maxDuration') {
143
+ break;
144
+ }
145
+
146
+ if (next === 'ping') {
147
+ stream.controller.enqueue({
148
+ comment: 'ping',
149
+ });
150
+ continue;
151
+ }
152
+
153
+ if (next instanceof Error) {
154
+ stream.controller.error(next);
155
+ break;
156
+ }
157
+ if (next.done) {
158
+ break;
159
+ }
160
+
161
+ const value = next.value;
162
+
163
+ const chunk: SSEvent = isSSEMessageEnvelope(value)
164
+ ? { ...value[1] }
165
+ : {
166
+ data: value,
167
+ };
168
+ if ('data' in chunk) {
169
+ chunk.data = JSON.stringify(serialize(chunk.data));
170
+ }
171
+
172
+ stream.controller.enqueue(chunk);
173
+
174
+ if (opts.emitAndEndImmediately) {
175
+ // end the stream in the next tick so that we can send a few more events from the queue
176
+ setTimeout(maxDurationPromise.resolve, 1);
177
+ }
178
+
179
+ nextPromise = iterator.next();
180
+ }
181
+ maxDurationPromise.clear();
182
+ await iterator.return?.();
183
+ try {
184
+ stream.controller.close();
185
+ } catch {}
186
+ }).catch((error) => {
187
+ return stream.controller.error(error);
188
+ });
189
+
190
+ return stream.readable.pipeThrough(
191
+ new TransformStream<SSEvent, string>({
192
+ transform(chunk, controller) {
193
+ if ('event' in chunk) {
194
+ controller.enqueue(`event: ${chunk.event}\n`);
195
+ }
196
+ if ('data' in chunk) {
197
+ controller.enqueue(`data: ${chunk.data}\n`);
198
+ }
199
+ if ('id' in chunk) {
200
+ controller.enqueue(`id: ${chunk.id}\n`);
201
+ }
202
+ if ('comment' in chunk) {
203
+ controller.enqueue(`: ${chunk.comment}\n`);
204
+ }
205
+ controller.enqueue('\n\n');
206
+ },
207
+ }),
208
+ );
209
+ }
210
+ export type inferSSEOutput<TData> = TData extends SSEMessageEnvelope<
211
+ infer $Data
212
+ >
213
+ ? $Data
214
+ : TData;
215
+ /**
216
+ * @see https://html.spec.whatwg.org/multipage/server-sent-events.html
217
+ */
218
+
219
+ export function sseStreamConsumer<TData>(opts: {
220
+ from: EventSource;
221
+ onError?: ConsumerOnError;
222
+ deserialize?: Deserialize;
223
+ }): AsyncIterable<inferSSEOutput<TData>> {
224
+ const { deserialize = (v) => v } = opts;
225
+ const eventSource = opts.from;
226
+
227
+ const stream = createReadableStream<MessageEvent>();
228
+
229
+ const transform = new TransformStream<MessageEvent, inferSSEOutput<TData>>({
230
+ async transform(chunk, controller) {
231
+ const def: Partial<SSEMessage> = {
232
+ data: deserialize(JSON.parse(chunk.data)),
233
+ };
234
+
235
+ if (chunk.lastEventId) {
236
+ def.id = chunk.lastEventId;
237
+ }
238
+ controller.enqueue(def as inferSSEOutput<TData>);
239
+ },
240
+ });
241
+
242
+ eventSource.addEventListener('message', (msg) => {
243
+ stream.controller.enqueue(msg);
244
+ });
245
+ eventSource.addEventListener('error', (cause) => {
246
+ if (eventSource.readyState === EventSource.CLOSED) {
247
+ stream.controller.error(cause);
248
+ }
249
+ });
250
+
251
+ const readable = stream.readable.pipeThrough(transform);
252
+ return {
253
+ [Symbol.asyncIterator]() {
254
+ const reader = readable.getReader();
255
+
256
+ const iterator: AsyncIterator<inferSSEOutput<TData>> = {
257
+ async next() {
258
+ const value = await reader.read();
259
+ if (value.done) {
260
+ return {
261
+ value: undefined,
262
+ done: true,
263
+ };
264
+ }
265
+ return {
266
+ value: value.value,
267
+ done: false,
268
+ };
269
+ },
270
+ async return() {
271
+ reader.releaseLock();
272
+ return {
273
+ value: undefined,
274
+ done: true,
275
+ };
276
+ },
277
+ };
278
+ return iterator;
279
+ },
280
+ };
281
+ }
282
+
283
+ export const sseHeaders = {
284
+ 'Content-Type': 'text/event-stream',
285
+ 'Cache-Control': 'no-cache, no-transform',
286
+ 'X-Accel-Buffering': 'no',
287
+ Connection: 'keep-alive',
288
+ } as const;
@@ -0,0 +1,48 @@
1
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
+ export function createDeferred<TValue>() {
3
+ let resolve: (value: TValue) => void;
4
+ let reject: (error: unknown) => void;
5
+ const promise = new Promise<TValue>((res, rej) => {
6
+ resolve = res;
7
+ reject = rej;
8
+ });
9
+
10
+ return { promise, resolve: resolve!, reject: reject! };
11
+ }
12
+ export type Deferred<TValue> = ReturnType<typeof createDeferred<TValue>>;
13
+
14
+ export const createTimeoutPromise = <TValue>(
15
+ timeoutMs: number,
16
+ value: TValue,
17
+ ) => {
18
+ let deferred = createDeferred<TValue>();
19
+ deferred = deferred as typeof deferred & { clear: () => void };
20
+
21
+ let timeout: ReturnType<typeof setTimeout> | null = null;
22
+ const clear = () => {
23
+ if (timeout) {
24
+ clearTimeout(timeout);
25
+ timeout = null;
26
+ }
27
+ };
28
+ const resolve = () => {
29
+ deferred.resolve(value);
30
+ clear();
31
+ };
32
+ if (timeoutMs !== Infinity) {
33
+ timeout = setTimeout(resolve, timeoutMs);
34
+ timeout.unref?.();
35
+ }
36
+
37
+ return {
38
+ promise: deferred.promise,
39
+ /**
40
+ * Clear the timeout without resolving the promise
41
+ */
42
+ clear,
43
+ /**
44
+ * Resolve the promise with the value
45
+ */
46
+ resolve,
47
+ };
48
+ };
@@ -0,0 +1,31 @@
1
+ import { createDeferred } from './createDeferred';
2
+
3
+ // ---------- utils
4
+ /**
5
+ * One-off readable stream
6
+ */
7
+ export function createReadableStream<TValue = unknown>() {
8
+ let controller: ReadableStreamDefaultController<TValue> =
9
+ null as unknown as ReadableStreamDefaultController<TValue>;
10
+
11
+ const deferred = createDeferred<'cancelled'>();
12
+ let cancelled = false;
13
+ const readable = new ReadableStream<TValue>({
14
+ start(c) {
15
+ controller = c;
16
+ },
17
+ cancel() {
18
+ deferred.resolve('cancelled');
19
+ cancelled = true;
20
+ },
21
+ });
22
+
23
+ return {
24
+ readable,
25
+ controller,
26
+ cancelledPromise: deferred.promise,
27
+ cancelled() {
28
+ return cancelled;
29
+ },
30
+ } as const;
31
+ }
@@ -0,0 +1,44 @@
1
+ import http from 'http';
2
+ import type { Socket } from 'net';
3
+
4
+ export function createServer(
5
+ handler: (req: http.IncomingMessage, res: http.ServerResponse) => void,
6
+ ) {
7
+ const server = http.createServer(async (req, res) => {
8
+ handler(req, res);
9
+ });
10
+ server.listen(0);
11
+
12
+ const connections = new Set<Socket>();
13
+ server.on('connection', (conn) => {
14
+ connections.add(conn);
15
+ conn.once('close', () => {
16
+ connections.delete(conn);
17
+ });
18
+ });
19
+
20
+ const port = (server.address() as any).port;
21
+
22
+ const url = `http://localhost:${port}`;
23
+
24
+ async function forceClose() {
25
+ for (const conn of connections) {
26
+ conn.destroy();
27
+ }
28
+ await new Promise((resolve) => {
29
+ server.close(resolve);
30
+ });
31
+ }
32
+
33
+ return {
34
+ url,
35
+ close: async () => {
36
+ await forceClose();
37
+ },
38
+ restart: async () => {
39
+ await forceClose();
40
+
41
+ server.listen(port);
42
+ },
43
+ };
44
+ }
@@ -56,3 +56,8 @@ export function isAsyncIterable<TValue>(
56
56
  asyncIteratorsSupported && isObject(value) && Symbol.asyncIterator in value
57
57
  );
58
58
  }
59
+
60
+ /**
61
+ * Run an IIFE
62
+ */
63
+ export const run = <TValue>(fn: () => TValue): TValue => fn();
@@ -12,13 +12,15 @@ export * from './unstable-core-do-not-import/clientish/inference';
12
12
  export * from './unstable-core-do-not-import/clientish/inferrable';
13
13
  export * from './unstable-core-do-not-import/clientish/serialize';
14
14
  export * from './unstable-core-do-not-import/createProxy';
15
- export * from './unstable-core-do-not-import/error/TRPCError';
16
15
  export * from './unstable-core-do-not-import/error/formatter';
17
16
  export * from './unstable-core-do-not-import/error/getErrorShape';
17
+ export * from './unstable-core-do-not-import/error/TRPCError';
18
18
  export * from './unstable-core-do-not-import/http/batchStreamFormatter';
19
19
  export * from './unstable-core-do-not-import/http/contentType';
20
20
  export * from './unstable-core-do-not-import/http/contentTypeParsers';
21
+ export * from './unstable-core-do-not-import/http/formDataToObject';
21
22
  export * from './unstable-core-do-not-import/http/getHTTPStatusCode';
23
+ export * from './unstable-core-do-not-import/http/parseConnectionParams';
22
24
  export * from './unstable-core-do-not-import/http/resolveResponse';
23
25
  export * from './unstable-core-do-not-import/http/toURL';
24
26
  export * from './unstable-core-do-not-import/http/types';
@@ -30,7 +32,8 @@ export * from './unstable-core-do-not-import/procedureBuilder';
30
32
  export * from './unstable-core-do-not-import/rootConfig';
31
33
  export * from './unstable-core-do-not-import/router';
32
34
  export * from './unstable-core-do-not-import/rpc';
35
+ export * from './unstable-core-do-not-import/stream/jsonl';
36
+ export * from './unstable-core-do-not-import/stream/sse';
33
37
  export * from './unstable-core-do-not-import/transformer';
34
38
  export * from './unstable-core-do-not-import/types';
35
39
  export * from './unstable-core-do-not-import/utils';
36
- export * from './unstable-core-do-not-import/stream/stream';
@@ -1 +0,0 @@
1
- {"version":3,"file":"formDataToObject.d.ts","sourceRoot":"","sources":["../../../src/adapters/next-app-dir/formDataToObject.ts"],"names":[],"mappings":"AA2BA,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,2BAQlD"}
@@ -1,34 +0,0 @@
1
- 'use strict';
2
-
3
- /* eslint-disable @typescript-eslint/no-non-null-assertion */ function set(obj, path, value) {
4
- if (typeof path === 'string') {
5
- path = path.split(/[\.\[\]]/).filter(Boolean);
6
- }
7
- if (path.length > 1) {
8
- const p = path.shift();
9
- const isArrayIndex = /^\d+$/.test(path[0]);
10
- obj[p] = obj[p] || (isArrayIndex ? [] : {});
11
- set(obj[p], path, value);
12
- return;
13
- }
14
- const p1 = path[0];
15
- if (obj[p1] === undefined) {
16
- obj[p1] = value;
17
- } else if (Array.isArray(obj[p1])) {
18
- obj[p1].push(value);
19
- } else {
20
- obj[p1] = [
21
- obj[p1],
22
- value
23
- ];
24
- }
25
- }
26
- function formDataToObject(formData) {
27
- const obj = {};
28
- for (const [key, value] of formData.entries()){
29
- set(obj, key, value);
30
- }
31
- return obj;
32
- }
33
-
34
- exports.formDataToObject = formDataToObject;
@@ -1,32 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-non-null-assertion */ function set(obj, path, value) {
2
- if (typeof path === 'string') {
3
- path = path.split(/[\.\[\]]/).filter(Boolean);
4
- }
5
- if (path.length > 1) {
6
- const p = path.shift();
7
- const isArrayIndex = /^\d+$/.test(path[0]);
8
- obj[p] = obj[p] || (isArrayIndex ? [] : {});
9
- set(obj[p], path, value);
10
- return;
11
- }
12
- const p1 = path[0];
13
- if (obj[p1] === undefined) {
14
- obj[p1] = value;
15
- } else if (Array.isArray(obj[p1])) {
16
- obj[p1].push(value);
17
- } else {
18
- obj[p1] = [
19
- obj[p1],
20
- value
21
- ];
22
- }
23
- }
24
- function formDataToObject(formData) {
25
- const obj = {};
26
- for (const [key, value] of formData.entries()){
27
- set(obj, key, value);
28
- }
29
- return obj;
30
- }
31
-
32
- export { formDataToObject };
@@ -1 +0,0 @@
1
- {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/stream/stream.ts"],"names":[],"mappings":"AAiBA;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,SAAS,EAAE,MAAM,2BAA2B,CAAC,UAAU,CAAC,CAAC;CAC1D,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,EAAE,CACA,SAAS,EAAE,MAAM,GAAG,MAAM,EAC1B,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GACjC,yBAAyB,CAAC;CAC9B,CAAC;AAGF,QAAA,MAAM,wBAAwB,IAAI,CAAC;AACnC,KAAK,wBAAwB,GAAG,OAAO,wBAAwB,CAAC;AAChE,QAAA,MAAM,+BAA+B,IAAI,CAAC;AAC1C,KAAK,+BAA+B,GAAG,OAAO,+BAA+B,CAAC;AAE9E,QAAA,MAAM,wBAAwB,IAAI,CAAC;AACnC,KAAK,wBAAwB,GAAG,OAAO,wBAAwB,CAAC;AAChE,QAAA,MAAM,uBAAuB,IAAI,CAAC;AAClC,KAAK,uBAAuB,GAAG,OAAO,uBAAuB,CAAC;AAE9D,QAAA,MAAM,0BAA0B,IAAI,CAAC;AACrC,KAAK,0BAA0B,GAAG,OAAO,0BAA0B,CAAC;AACpE,QAAA,MAAM,2BAA2B,IAAI,CAAC;AACtC,KAAK,2BAA2B,GAAG,OAAO,2BAA2B,CAAC;AACtE,QAAA,MAAM,2BAA2B,IAAI,CAAC;AACtC,KAAK,2BAA2B,GAAG,OAAO,2BAA2B,CAAC;AAEtE,KAAK,kBAAkB,GAEnB,IAAI,GAEJ,MAAM,GAEN,MAAM,CAAC;AAEX,KAAK,UAAU,GAAG,MAAM,GAAG;IAAE,YAAY,EAAE,IA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