@trpc/server 11.0.0-rc.637 → 11.0.0-rc.642
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/adapters/aws-lambda/index.js +1 -1
- package/dist/adapters/aws-lambda/index.mjs +1 -1
- package/dist/adapters/express.js +1 -1
- package/dist/adapters/express.mjs +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.js +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.js +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.mjs +1 -1
- package/dist/adapters/next-app-dir/nextAppDirCaller.js +1 -1
- package/dist/adapters/next-app-dir/nextAppDirCaller.mjs +1 -1
- package/dist/adapters/next-app-dir/notFound.js +1 -1
- package/dist/adapters/next-app-dir/notFound.mjs +1 -1
- package/dist/adapters/next-app-dir/redirect.js +1 -1
- package/dist/adapters/next-app-dir/redirect.mjs +1 -1
- package/dist/adapters/next.js +1 -1
- package/dist/adapters/next.mjs +1 -1
- package/dist/adapters/node-http/incomingMessageToRequest.js +1 -1
- package/dist/adapters/node-http/incomingMessageToRequest.mjs +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +1 -1
- package/dist/adapters/node-http/writeResponse.js +1 -1
- package/dist/adapters/node-http/writeResponse.mjs +1 -1
- package/dist/adapters/standalone.js +1 -1
- package/dist/adapters/standalone.mjs +1 -1
- package/dist/adapters/ws.js +1 -1
- package/dist/adapters/ws.mjs +1 -1
- package/dist/bundle-analysis.json +107 -107
- package/dist/http.js +1 -1
- package/dist/http.mjs +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/rpc.js +1 -1
- package/dist/rpc.mjs +1 -1
- package/dist/shared.js +1 -1
- package/dist/shared.mjs +1 -1
- package/dist/unstable-core-do-not-import/http/resolveResponse.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/resolveResponse.js +0 -1
- package/dist/unstable-core-do-not-import/http/resolveResponse.mjs +0 -1
- package/dist/unstable-core-do-not-import/rootConfig.d.ts +1 -1
- package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/jsonl.d.ts +1 -1
- package/dist/unstable-core-do-not-import/stream/jsonl.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/jsonl.js +73 -47
- package/dist/unstable-core-do-not-import/stream/jsonl.mjs +73 -47
- package/dist/unstable-core-do-not-import/stream/sse.d.ts +20 -12
- package/dist/unstable-core-do-not-import/stream/sse.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/sse.js +22 -11
- package/dist/unstable-core-do-not-import/stream/sse.mjs +22 -11
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.d.ts +0 -2
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.js +5 -8
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.mjs +3 -6
- package/dist/unstable-core-do-not-import/stream/utils/{disposablePromiseTimer.d.ts → timerResource.d.ts} +2 -2
- package/dist/unstable-core-do-not-import/stream/utils/timerResource.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/utils/{disposablePromiseTimer.js → timerResource.js} +2 -2
- package/dist/unstable-core-do-not-import/stream/utils/{disposablePromiseTimer.mjs → timerResource.mjs} +2 -2
- package/dist/unstable-core-do-not-import/stream/utils/withPing.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/utils/withPing.js +3 -3
- package/dist/unstable-core-do-not-import/stream/utils/withPing.mjs +2 -2
- package/package.json +7 -3
- package/src/unstable-core-do-not-import/http/resolveResponse.ts +0 -1
- package/src/unstable-core-do-not-import/rootConfig.ts +1 -1
- package/src/unstable-core-do-not-import/stream/jsonl.ts +81 -51
- package/src/unstable-core-do-not-import/stream/sse.ts +56 -24
- package/src/unstable-core-do-not-import/stream/utils/asyncIterable.ts +5 -11
- package/src/unstable-core-do-not-import/stream/utils/{disposablePromiseTimer.ts → timerResource.ts} +1 -1
- package/src/unstable-core-do-not-import/stream/utils/withPing.ts +2 -5
- package/dist/unstable-core-do-not-import/stream/utils/createServer.d.ts +0 -7
- package/dist/unstable-core-do-not-import/stream/utils/createServer.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/stream/utils/disposablePromiseTimer.d.ts.map +0 -1
- package/src/unstable-core-do-not-import/stream/utils/createServer.ts +0 -44
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
import { Unpromise } from '../../../vendor/unpromise';
|
|
2
|
-
import {
|
|
3
|
-
disposablePromiseTimer,
|
|
4
|
-
disposablePromiseTimerResult,
|
|
5
|
-
} from './disposablePromiseTimer';
|
|
2
|
+
import { disposablePromiseTimerResult, timerResource } from './timerResource';
|
|
6
3
|
|
|
7
4
|
/**
|
|
8
5
|
* Derives a new {@link AsyncGenerator} based on {@link iterable}, that automatically stops after the specified duration.
|
|
9
6
|
*/
|
|
10
7
|
export async function* withMaxDuration<T>(
|
|
11
8
|
iterable: AsyncIterable<T>,
|
|
12
|
-
opts: { maxDurationMs: number
|
|
9
|
+
opts: { maxDurationMs: number },
|
|
13
10
|
): AsyncGenerator<T> {
|
|
14
11
|
const iterator = iterable[Symbol.asyncIterator]();
|
|
15
12
|
|
|
16
|
-
const timer =
|
|
13
|
+
const timer = timerResource(opts.maxDurationMs);
|
|
17
14
|
try {
|
|
18
15
|
const timerPromise = timer.start();
|
|
19
16
|
|
|
@@ -24,7 +21,7 @@ export async function* withMaxDuration<T>(
|
|
|
24
21
|
result = await Unpromise.race([iterator.next(), timerPromise]);
|
|
25
22
|
if (result === disposablePromiseTimerResult) {
|
|
26
23
|
// cancelled due to timeout
|
|
27
|
-
|
|
24
|
+
|
|
28
25
|
const res = await iterator.return?.();
|
|
29
26
|
return res?.value;
|
|
30
27
|
}
|
|
@@ -52,7 +49,6 @@ export async function* takeWithGrace<T>(
|
|
|
52
49
|
opts: {
|
|
53
50
|
count: number;
|
|
54
51
|
gracePeriodMs: number;
|
|
55
|
-
abortCtrl: AbortController;
|
|
56
52
|
},
|
|
57
53
|
): AsyncGenerator<T> {
|
|
58
54
|
const iterator = iterable[Symbol.asyncIterator]();
|
|
@@ -60,7 +56,7 @@ export async function* takeWithGrace<T>(
|
|
|
60
56
|
// declaration outside the loop for garbage collection reasons
|
|
61
57
|
let result: null | IteratorResult<T> | typeof disposablePromiseTimerResult;
|
|
62
58
|
|
|
63
|
-
const timer =
|
|
59
|
+
const timer = timerResource(opts.gracePeriodMs);
|
|
64
60
|
try {
|
|
65
61
|
let count = opts.count;
|
|
66
62
|
|
|
@@ -81,8 +77,6 @@ export async function* takeWithGrace<T>(
|
|
|
81
77
|
yield result.value;
|
|
82
78
|
if (--count === 0) {
|
|
83
79
|
timerPromise = timer.start();
|
|
84
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
85
|
-
timerPromise.then(() => opts.abortCtrl.abort());
|
|
86
80
|
}
|
|
87
81
|
// free up reference for garbage collection
|
|
88
82
|
result = null;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { Unpromise } from '../../../vendor/unpromise';
|
|
2
|
-
import {
|
|
3
|
-
disposablePromiseTimer,
|
|
4
|
-
disposablePromiseTimerResult,
|
|
5
|
-
} from './disposablePromiseTimer';
|
|
2
|
+
import { disposablePromiseTimerResult, timerResource } from './timerResource';
|
|
6
3
|
|
|
7
4
|
export const PING_SYM = Symbol('ping');
|
|
8
5
|
|
|
@@ -23,7 +20,7 @@ export async function* withPing<TValue>(
|
|
|
23
20
|
|
|
24
21
|
let nextPromise = iterator.next();
|
|
25
22
|
while (true) {
|
|
26
|
-
const pingPromise =
|
|
23
|
+
const pingPromise = timerResource(pingIntervalMs);
|
|
27
24
|
|
|
28
25
|
try {
|
|
29
26
|
result = await Unpromise.race([nextPromise, pingPromise.start()]);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createServer.d.ts","sourceRoot":"","sources":["../../../../src/unstable-core-do-not-import/stream/utils/createServer.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,wBAAgB,YAAY,CAC1B,OAAO,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,eAAe,EAAE,GAAG,EAAE,IAAI,CAAC,cAAc,KAAK,IAAI;;;;EAuCvE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"disposablePromiseTimer.d.ts","sourceRoot":"","sources":["../../../../src/unstable-core-do-not-import/stream/utils/disposablePromiseTimer.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,4BAA4B,eAAW,CAAC;AACrD,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,MAAM;;;EAsBhD"}
|
|
@@ -1,44 +0,0 @@
|
|
|
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
|
-
}
|