@trpc/server 11.0.0-rc.645 → 11.0.0-rc.648
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 +15 -3
- package/dist/adapters/next-app-dir/redirect.mjs +14 -2
- 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.d.ts.map +1 -1
- package/dist/adapters/ws.js +144 -65
- package/dist/adapters/ws.mjs +144 -65
- package/dist/bundle-analysis.json +190 -183
- 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/node_modules/.pnpm/@rollup_plugin-typescript@12.1.1_rollup@4.27.4_tslib@2.8.1_typescript@5.6.2/node_modules/tslib/tslib.es6.js +73 -0
- 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/error/TRPCError.d.ts +1 -1
- package/dist/unstable-core-do-not-import/error/TRPCError.js +14 -2
- package/dist/unstable-core-do-not-import/error/TRPCError.mjs +13 -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 +3 -9
- package/dist/unstable-core-do-not-import/http/resolveResponse.mjs +3 -9
- package/dist/unstable-core-do-not-import/stream/jsonl.d.ts +7 -33
- package/dist/unstable-core-do-not-import/stream/jsonl.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/jsonl.js +338 -209
- package/dist/unstable-core-do-not-import/stream/jsonl.mjs +337 -208
- package/dist/unstable-core-do-not-import/stream/sse.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/sse.js +143 -74
- package/dist/unstable-core-do-not-import/stream/sse.mjs +144 -75
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.d.ts +1 -0
- 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 +103 -10
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.mjs +104 -12
- package/dist/unstable-core-do-not-import/stream/utils/disposable.d.ts +17 -0
- package/dist/unstable-core-do-not-import/stream/utils/disposable.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/utils/disposable.js +44 -0
- package/dist/unstable-core-do-not-import/stream/utils/disposable.mjs +41 -0
- package/dist/unstable-core-do-not-import/stream/utils/timerResource.d.ts +1 -2
- package/dist/unstable-core-do-not-import/stream/utils/timerResource.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/utils/timerResource.js +8 -10
- package/dist/unstable-core-do-not-import/stream/utils/timerResource.mjs +8 -10
- 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 +113 -24
- package/dist/unstable-core-do-not-import/stream/utils/withPing.mjs +114 -25
- package/dist/unstable-core-do-not-import/transformer.d.ts +1 -1
- package/dist/unstable-core-do-not-import.d.ts +1 -0
- package/dist/unstable-core-do-not-import.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import.js +3 -0
- package/dist/unstable-core-do-not-import.mjs +1 -0
- package/dist/vendor/unpromise/unpromise.js +17 -6
- package/dist/vendor/unpromise/unpromise.mjs +13 -2
- package/package.json +2 -3
- package/src/adapters/ws.ts +7 -8
- package/src/unstable-core-do-not-import/http/resolveResponse.ts +3 -9
- package/src/unstable-core-do-not-import/stream/jsonl.ts +128 -153
- package/src/unstable-core-do-not-import/stream/sse.ts +64 -79
- package/src/unstable-core-do-not-import/stream/utils/asyncIterable.ts +50 -48
- package/src/unstable-core-do-not-import/stream/utils/disposable.ts +52 -0
- package/src/unstable-core-do-not-import/stream/utils/timerResource.ts +17 -15
- package/src/unstable-core-do-not-import/stream/utils/withPing.ts +18 -19
- package/src/unstable-core-do-not-import.ts +1 -0
- package/dist/node_modules/.pnpm/@swc_helpers@0.5.13/node_modules/@swc/helpers/esm/_define_property.js +0 -11
- package/dist/node_modules/.pnpm/@swc_helpers@0.5.13/node_modules/@swc/helpers/esm/_define_property.mjs +0 -9
|
@@ -1,12 +1,91 @@
|
|
|
1
1
|
import { Unpromise } from '../../../vendor/unpromise/unpromise.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { makeAsyncResource } from './disposable.mjs';
|
|
3
|
+
import { timerResource, disposablePromiseTimerResult } from './timerResource.mjs';
|
|
3
4
|
|
|
5
|
+
function _ts_add_disposable_resource(env, value, async) {
|
|
6
|
+
if (value !== null && value !== void 0) {
|
|
7
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
8
|
+
var dispose, inner;
|
|
9
|
+
if (async) {
|
|
10
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.asyncDispose];
|
|
12
|
+
}
|
|
13
|
+
if (dispose === void 0) {
|
|
14
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
15
|
+
dispose = value[Symbol.dispose];
|
|
16
|
+
if (async) inner = dispose;
|
|
17
|
+
}
|
|
18
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
19
|
+
if (inner) dispose = function() {
|
|
20
|
+
try {
|
|
21
|
+
inner.call(this);
|
|
22
|
+
} catch (e) {
|
|
23
|
+
return Promise.reject(e);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
env.stack.push({
|
|
27
|
+
value: value,
|
|
28
|
+
dispose: dispose,
|
|
29
|
+
async: async
|
|
30
|
+
});
|
|
31
|
+
} else if (async) {
|
|
32
|
+
env.stack.push({
|
|
33
|
+
async: true
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
function _ts_dispose_resources(env) {
|
|
39
|
+
var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
40
|
+
var e = new Error(message);
|
|
41
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
42
|
+
};
|
|
43
|
+
return (_ts_dispose_resources = function _ts_dispose_resources(env) {
|
|
44
|
+
function fail(e) {
|
|
45
|
+
env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
46
|
+
env.hasError = true;
|
|
47
|
+
}
|
|
48
|
+
var r, s = 0;
|
|
49
|
+
function next() {
|
|
50
|
+
while(r = env.stack.pop()){
|
|
51
|
+
try {
|
|
52
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
53
|
+
if (r.dispose) {
|
|
54
|
+
var result = r.dispose.call(r.value);
|
|
55
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
|
|
56
|
+
fail(e);
|
|
57
|
+
return next();
|
|
58
|
+
});
|
|
59
|
+
} else s |= 1;
|
|
60
|
+
} catch (e) {
|
|
61
|
+
fail(e);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
65
|
+
if (env.hasError) throw env.error;
|
|
66
|
+
}
|
|
67
|
+
return next();
|
|
68
|
+
})(env);
|
|
69
|
+
}
|
|
70
|
+
function iteratorResource(iterable) {
|
|
71
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
72
|
+
return makeAsyncResource(iterator, async ()=>{
|
|
73
|
+
await iterator.return?.();
|
|
74
|
+
});
|
|
75
|
+
}
|
|
4
76
|
/**
|
|
5
77
|
* Derives a new {@link AsyncGenerator} based on {@link iterable}, that automatically stops after the specified duration.
|
|
6
78
|
*/ async function* withMaxDuration(iterable, opts) {
|
|
7
|
-
const
|
|
8
|
-
|
|
79
|
+
const env = {
|
|
80
|
+
stack: [],
|
|
81
|
+
error: void 0,
|
|
82
|
+
hasError: false
|
|
83
|
+
};
|
|
9
84
|
try {
|
|
85
|
+
const iterator = _ts_add_disposable_resource(env, iteratorResource(iterable), true);
|
|
86
|
+
;
|
|
87
|
+
const timer = _ts_add_disposable_resource(env, timerResource(opts.maxDurationMs), false);
|
|
88
|
+
;
|
|
10
89
|
const timerPromise = timer.start();
|
|
11
90
|
// declaration outside the loop for garbage collection reasons
|
|
12
91
|
let result;
|
|
@@ -27,10 +106,12 @@ import { disposablePromiseTimerResult, timerResource } from './timerResource.mjs
|
|
|
27
106
|
// free up reference for garbage collection
|
|
28
107
|
result = null;
|
|
29
108
|
}
|
|
109
|
+
} catch (e) {
|
|
110
|
+
env.error = e;
|
|
111
|
+
env.hasError = true;
|
|
30
112
|
} finally{
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
timer[Symbol.dispose]();
|
|
113
|
+
const result = _ts_dispose_resources(env);
|
|
114
|
+
if (result) await result;
|
|
34
115
|
}
|
|
35
116
|
}
|
|
36
117
|
/**
|
|
@@ -38,11 +119,18 @@ import { disposablePromiseTimerResult, timerResource } from './timerResource.mjs
|
|
|
38
119
|
* {@link count} values. Then, a grace period of {@link gracePeriodMs} is started in which further
|
|
39
120
|
* values may still come through. After this period, the generator stops.
|
|
40
121
|
*/ async function* takeWithGrace(iterable, opts) {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
122
|
+
const env = {
|
|
123
|
+
stack: [],
|
|
124
|
+
error: void 0,
|
|
125
|
+
hasError: false
|
|
126
|
+
};
|
|
45
127
|
try {
|
|
128
|
+
const iterator = _ts_add_disposable_resource(env, iteratorResource(iterable), true);
|
|
129
|
+
;
|
|
130
|
+
// declaration outside the loop for garbage collection reasons
|
|
131
|
+
let result;
|
|
132
|
+
const timer = _ts_add_disposable_resource(env, timerResource(opts.gracePeriodMs), false);
|
|
133
|
+
;
|
|
46
134
|
let count = opts.count;
|
|
47
135
|
let timerPromise = new Promise(()=>{
|
|
48
136
|
// never resolves
|
|
@@ -67,9 +155,13 @@ import { disposablePromiseTimerResult, timerResource } from './timerResource.mjs
|
|
|
67
155
|
// free up reference for garbage collection
|
|
68
156
|
result = null;
|
|
69
157
|
}
|
|
158
|
+
} catch (e) {
|
|
159
|
+
env.error = e;
|
|
160
|
+
env.hasError = true;
|
|
70
161
|
} finally{
|
|
71
|
-
|
|
162
|
+
const result = _ts_dispose_resources(env);
|
|
163
|
+
if (result) await result;
|
|
72
164
|
}
|
|
73
165
|
}
|
|
74
166
|
|
|
75
|
-
export { takeWithGrace, withMaxDuration };
|
|
167
|
+
export { iteratorResource, takeWithGrace, withMaxDuration };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Takes a value and a dispose function and returns a new object that implements the Disposable interface.
|
|
3
|
+
* The returned object is the original value augmented with a Symbol.dispose method.
|
|
4
|
+
* @param thing The value to make disposable
|
|
5
|
+
* @param dispose Function to call when disposing the resource
|
|
6
|
+
* @returns The original value with Symbol.dispose method added
|
|
7
|
+
*/
|
|
8
|
+
export declare function makeResource<T>(thing: T, dispose: () => void): T & Disposable;
|
|
9
|
+
/**
|
|
10
|
+
* Takes a value and an async dispose function and returns a new object that implements the AsyncDisposable interface.
|
|
11
|
+
* The returned object is the original value augmented with a Symbol.asyncDispose method.
|
|
12
|
+
* @param thing The value to make async disposable
|
|
13
|
+
* @param dispose Async function to call when disposing the resource
|
|
14
|
+
* @returns The original value with Symbol.asyncDispose method added
|
|
15
|
+
*/
|
|
16
|
+
export declare function makeAsyncResource<T>(thing: T, dispose: () => Promise<void>): T & AsyncDisposable;
|
|
17
|
+
//# sourceMappingURL=disposable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"disposable.d.ts","sourceRoot":"","sources":["../../../../src/unstable-core-do-not-import/stream/utils/disposable.ts"],"names":[],"mappings":"AAQA;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,IAAI,GAAG,CAAC,GAAG,UAAU,CAY7E;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAC3B,CAAC,GAAG,eAAe,CAYrB"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// @ts-expect-error - polyfilling symbol
|
|
4
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
5
|
+
var _Symbol, // @ts-expect-error - polyfilling symbol
|
|
6
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
7
|
+
_Symbol1;
|
|
8
|
+
(_Symbol = Symbol).dispose ?? (_Symbol.dispose = Symbol());
|
|
9
|
+
(_Symbol1 = Symbol).asyncDispose ?? (_Symbol1.asyncDispose = Symbol());
|
|
10
|
+
/**
|
|
11
|
+
* Takes a value and a dispose function and returns a new object that implements the Disposable interface.
|
|
12
|
+
* The returned object is the original value augmented with a Symbol.dispose method.
|
|
13
|
+
* @param thing The value to make disposable
|
|
14
|
+
* @param dispose Function to call when disposing the resource
|
|
15
|
+
* @returns The original value with Symbol.dispose method added
|
|
16
|
+
*/ function makeResource(thing, dispose) {
|
|
17
|
+
const it = thing;
|
|
18
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
19
|
+
if (it[Symbol.dispose]) {
|
|
20
|
+
throw new Error('Symbol.dispose already exists');
|
|
21
|
+
}
|
|
22
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
23
|
+
it[Symbol.dispose] = dispose;
|
|
24
|
+
return it;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Takes a value and an async dispose function and returns a new object that implements the AsyncDisposable interface.
|
|
28
|
+
* The returned object is the original value augmented with a Symbol.asyncDispose method.
|
|
29
|
+
* @param thing The value to make async disposable
|
|
30
|
+
* @param dispose Async function to call when disposing the resource
|
|
31
|
+
* @returns The original value with Symbol.asyncDispose method added
|
|
32
|
+
*/ function makeAsyncResource(thing, dispose) {
|
|
33
|
+
const it = thing;
|
|
34
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
35
|
+
if (it[Symbol.asyncDispose]) {
|
|
36
|
+
throw new Error('Symbol.asyncDispose already exists');
|
|
37
|
+
}
|
|
38
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
39
|
+
it[Symbol.asyncDispose] = dispose;
|
|
40
|
+
return it;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
exports.makeAsyncResource = makeAsyncResource;
|
|
44
|
+
exports.makeResource = makeResource;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// @ts-expect-error - polyfilling symbol
|
|
2
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
3
|
+
var _Symbol, // @ts-expect-error - polyfilling symbol
|
|
4
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
5
|
+
_Symbol1;
|
|
6
|
+
(_Symbol = Symbol).dispose ?? (_Symbol.dispose = Symbol());
|
|
7
|
+
(_Symbol1 = Symbol).asyncDispose ?? (_Symbol1.asyncDispose = Symbol());
|
|
8
|
+
/**
|
|
9
|
+
* Takes a value and a dispose function and returns a new object that implements the Disposable interface.
|
|
10
|
+
* The returned object is the original value augmented with a Symbol.dispose method.
|
|
11
|
+
* @param thing The value to make disposable
|
|
12
|
+
* @param dispose Function to call when disposing the resource
|
|
13
|
+
* @returns The original value with Symbol.dispose method added
|
|
14
|
+
*/ function makeResource(thing, dispose) {
|
|
15
|
+
const it = thing;
|
|
16
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
17
|
+
if (it[Symbol.dispose]) {
|
|
18
|
+
throw new Error('Symbol.dispose already exists');
|
|
19
|
+
}
|
|
20
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
21
|
+
it[Symbol.dispose] = dispose;
|
|
22
|
+
return it;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Takes a value and an async dispose function and returns a new object that implements the AsyncDisposable interface.
|
|
26
|
+
* The returned object is the original value augmented with a Symbol.asyncDispose method.
|
|
27
|
+
* @param thing The value to make async disposable
|
|
28
|
+
* @param dispose Async function to call when disposing the resource
|
|
29
|
+
* @returns The original value with Symbol.asyncDispose method added
|
|
30
|
+
*/ function makeAsyncResource(thing, dispose) {
|
|
31
|
+
const it = thing;
|
|
32
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
33
|
+
if (it[Symbol.asyncDispose]) {
|
|
34
|
+
throw new Error('Symbol.asyncDispose already exists');
|
|
35
|
+
}
|
|
36
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
37
|
+
it[Symbol.asyncDispose] = dispose;
|
|
38
|
+
return it;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { makeAsyncResource, makeResource };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export declare const disposablePromiseTimerResult: unique symbol;
|
|
2
2
|
export declare function timerResource(ms: number): {
|
|
3
3
|
start(): Promise<typeof disposablePromiseTimerResult>;
|
|
4
|
-
|
|
5
|
-
};
|
|
4
|
+
} & Disposable;
|
|
6
5
|
//# sourceMappingURL=timerResource.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timerResource.d.ts","sourceRoot":"","sources":["../../../../src/unstable-core-do-not-import/stream/utils/timerResource.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"timerResource.d.ts","sourceRoot":"","sources":["../../../../src/unstable-core-do-not-import/stream/utils/timerResource.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,4BAA4B,eAAW,CAAC;AAErD,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM;;eAwBvC"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
(_Symbol = Symbol).dispose ?? (_Symbol.dispose = Symbol());
|
|
3
|
+
var disposable = require('./disposable.js');
|
|
4
|
+
|
|
6
5
|
const disposablePromiseTimerResult = Symbol();
|
|
7
6
|
function timerResource(ms) {
|
|
8
7
|
let timer = null;
|
|
9
|
-
return {
|
|
8
|
+
return disposable.makeResource({
|
|
10
9
|
start () {
|
|
11
10
|
if (timer) {
|
|
12
11
|
throw new Error('Timer already started');
|
|
@@ -15,13 +14,12 @@ function timerResource(ms) {
|
|
|
15
14
|
timer = setTimeout(()=>resolve(disposablePromiseTimerResult), ms);
|
|
16
15
|
});
|
|
17
16
|
return promise;
|
|
18
|
-
},
|
|
19
|
-
[Symbol.dispose]: ()=>{
|
|
20
|
-
if (timer) {
|
|
21
|
-
clearTimeout(timer);
|
|
22
|
-
}
|
|
23
17
|
}
|
|
24
|
-
}
|
|
18
|
+
}, ()=>{
|
|
19
|
+
if (timer) {
|
|
20
|
+
clearTimeout(timer);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
exports.disposablePromiseTimerResult = disposablePromiseTimerResult;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
(_Symbol = Symbol).dispose ?? (_Symbol.dispose = Symbol());
|
|
1
|
+
import { makeResource } from './disposable.mjs';
|
|
2
|
+
|
|
4
3
|
const disposablePromiseTimerResult = Symbol();
|
|
5
4
|
function timerResource(ms) {
|
|
6
5
|
let timer = null;
|
|
7
|
-
return {
|
|
6
|
+
return makeResource({
|
|
8
7
|
start () {
|
|
9
8
|
if (timer) {
|
|
10
9
|
throw new Error('Timer already started');
|
|
@@ -13,13 +12,12 @@ function timerResource(ms) {
|
|
|
13
12
|
timer = setTimeout(()=>resolve(disposablePromiseTimerResult), ms);
|
|
14
13
|
});
|
|
15
14
|
return promise;
|
|
16
|
-
},
|
|
17
|
-
[Symbol.dispose]: ()=>{
|
|
18
|
-
if (timer) {
|
|
19
|
-
clearTimeout(timer);
|
|
20
|
-
}
|
|
21
15
|
}
|
|
22
|
-
}
|
|
16
|
+
}, ()=>{
|
|
17
|
+
if (timer) {
|
|
18
|
+
clearTimeout(timer);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
23
21
|
}
|
|
24
22
|
|
|
25
23
|
export { disposablePromiseTimerResult, timerResource };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withPing.d.ts","sourceRoot":"","sources":["../../../../src/unstable-core-do-not-import/stream/utils/withPing.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"withPing.d.ts","sourceRoot":"","sources":["../../../../src/unstable-core-do-not-import/stream/utils/withPing.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,QAAQ,eAAiB,CAAC;AAEvC;;;GAGG;AACH,wBAAuB,QAAQ,CAAC,MAAM,EACpC,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,EAC/B,cAAc,EAAE,MAAM,GACrB,cAAc,CAAC,MAAM,GAAG,OAAO,QAAQ,CAAC,CAiC1C"}
|
|
@@ -1,39 +1,128 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var unpromise = require('../../../vendor/unpromise/unpromise.js');
|
|
4
|
+
var asyncIterable = require('./asyncIterable.js');
|
|
4
5
|
var timerResource = require('./timerResource.js');
|
|
5
6
|
|
|
7
|
+
function _ts_add_disposable_resource(env, value, async) {
|
|
8
|
+
if (value !== null && value !== void 0) {
|
|
9
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
10
|
+
var dispose, inner;
|
|
11
|
+
if (async) {
|
|
12
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
13
|
+
dispose = value[Symbol.asyncDispose];
|
|
14
|
+
}
|
|
15
|
+
if (dispose === void 0) {
|
|
16
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
17
|
+
dispose = value[Symbol.dispose];
|
|
18
|
+
if (async) inner = dispose;
|
|
19
|
+
}
|
|
20
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
21
|
+
if (inner) dispose = function() {
|
|
22
|
+
try {
|
|
23
|
+
inner.call(this);
|
|
24
|
+
} catch (e) {
|
|
25
|
+
return Promise.reject(e);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
env.stack.push({
|
|
29
|
+
value: value,
|
|
30
|
+
dispose: dispose,
|
|
31
|
+
async: async
|
|
32
|
+
});
|
|
33
|
+
} else if (async) {
|
|
34
|
+
env.stack.push({
|
|
35
|
+
async: true
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
function _ts_dispose_resources(env) {
|
|
41
|
+
var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
42
|
+
var e = new Error(message);
|
|
43
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
44
|
+
};
|
|
45
|
+
return (_ts_dispose_resources = function _ts_dispose_resources(env) {
|
|
46
|
+
function fail(e) {
|
|
47
|
+
env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
48
|
+
env.hasError = true;
|
|
49
|
+
}
|
|
50
|
+
var r, s = 0;
|
|
51
|
+
function next() {
|
|
52
|
+
while(r = env.stack.pop()){
|
|
53
|
+
try {
|
|
54
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
55
|
+
if (r.dispose) {
|
|
56
|
+
var result = r.dispose.call(r.value);
|
|
57
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
|
|
58
|
+
fail(e);
|
|
59
|
+
return next();
|
|
60
|
+
});
|
|
61
|
+
} else s |= 1;
|
|
62
|
+
} catch (e) {
|
|
63
|
+
fail(e);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
67
|
+
if (env.hasError) throw env.error;
|
|
68
|
+
}
|
|
69
|
+
return next();
|
|
70
|
+
})(env);
|
|
71
|
+
}
|
|
6
72
|
const PING_SYM = Symbol('ping');
|
|
7
73
|
/**
|
|
8
74
|
* Derives a new {@link AsyncGenerator} based of {@link iterable}, that yields {@link PING_SYM}
|
|
9
75
|
* whenever no value has been yielded for {@link pingIntervalMs}.
|
|
10
76
|
*/ async function* withPing(iterable, pingIntervalMs) {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
77
|
+
const env = {
|
|
78
|
+
stack: [],
|
|
79
|
+
error: void 0,
|
|
80
|
+
hasError: false
|
|
81
|
+
};
|
|
82
|
+
try {
|
|
83
|
+
const iterator = _ts_add_disposable_resource(env, asyncIterable.iteratorResource(iterable), true);
|
|
84
|
+
;
|
|
85
|
+
// declaration outside the loop for garbage collection reasons
|
|
86
|
+
let result;
|
|
87
|
+
let nextPromise = iterator.next();
|
|
88
|
+
while(true){
|
|
89
|
+
const env = {
|
|
90
|
+
stack: [],
|
|
91
|
+
error: void 0,
|
|
92
|
+
hasError: false
|
|
93
|
+
};
|
|
94
|
+
try {
|
|
95
|
+
const pingPromise = _ts_add_disposable_resource(env, timerResource.timerResource(pingIntervalMs), false);
|
|
96
|
+
;
|
|
97
|
+
result = await unpromise.Unpromise.race([
|
|
98
|
+
nextPromise,
|
|
99
|
+
pingPromise.start()
|
|
100
|
+
]);
|
|
101
|
+
if (result === timerResource.disposablePromiseTimerResult) {
|
|
102
|
+
// cancelled
|
|
103
|
+
yield PING_SYM;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (result.done) {
|
|
107
|
+
return result.value;
|
|
108
|
+
}
|
|
109
|
+
nextPromise = iterator.next();
|
|
110
|
+
yield result.value;
|
|
111
|
+
// free up reference for garbage collection
|
|
112
|
+
result = null;
|
|
113
|
+
} catch (e) {
|
|
114
|
+
env.error = e;
|
|
115
|
+
env.hasError = true;
|
|
116
|
+
} finally{
|
|
117
|
+
_ts_dispose_resources(env);
|
|
29
118
|
}
|
|
30
|
-
nextPromise = iterator.next();
|
|
31
|
-
yield result.value;
|
|
32
|
-
// free up reference for garbage collection
|
|
33
|
-
result = null;
|
|
34
|
-
} finally{
|
|
35
|
-
pingPromise[Symbol.dispose]();
|
|
36
119
|
}
|
|
120
|
+
} catch (e) {
|
|
121
|
+
env.error = e;
|
|
122
|
+
env.hasError = true;
|
|
123
|
+
} finally{
|
|
124
|
+
const result = _ts_dispose_resources(env);
|
|
125
|
+
if (result) await result;
|
|
37
126
|
}
|
|
38
127
|
}
|
|
39
128
|
|
|
@@ -1,37 +1,126 @@
|
|
|
1
1
|
import { Unpromise } from '../../../vendor/unpromise/unpromise.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { iteratorResource } from './asyncIterable.mjs';
|
|
3
|
+
import { timerResource, disposablePromiseTimerResult } from './timerResource.mjs';
|
|
3
4
|
|
|
5
|
+
function _ts_add_disposable_resource(env, value, async) {
|
|
6
|
+
if (value !== null && value !== void 0) {
|
|
7
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
8
|
+
var dispose, inner;
|
|
9
|
+
if (async) {
|
|
10
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.asyncDispose];
|
|
12
|
+
}
|
|
13
|
+
if (dispose === void 0) {
|
|
14
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
15
|
+
dispose = value[Symbol.dispose];
|
|
16
|
+
if (async) inner = dispose;
|
|
17
|
+
}
|
|
18
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
19
|
+
if (inner) dispose = function() {
|
|
20
|
+
try {
|
|
21
|
+
inner.call(this);
|
|
22
|
+
} catch (e) {
|
|
23
|
+
return Promise.reject(e);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
env.stack.push({
|
|
27
|
+
value: value,
|
|
28
|
+
dispose: dispose,
|
|
29
|
+
async: async
|
|
30
|
+
});
|
|
31
|
+
} else if (async) {
|
|
32
|
+
env.stack.push({
|
|
33
|
+
async: true
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
function _ts_dispose_resources(env) {
|
|
39
|
+
var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
40
|
+
var e = new Error(message);
|
|
41
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
42
|
+
};
|
|
43
|
+
return (_ts_dispose_resources = function _ts_dispose_resources(env) {
|
|
44
|
+
function fail(e) {
|
|
45
|
+
env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
46
|
+
env.hasError = true;
|
|
47
|
+
}
|
|
48
|
+
var r, s = 0;
|
|
49
|
+
function next() {
|
|
50
|
+
while(r = env.stack.pop()){
|
|
51
|
+
try {
|
|
52
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
53
|
+
if (r.dispose) {
|
|
54
|
+
var result = r.dispose.call(r.value);
|
|
55
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
|
|
56
|
+
fail(e);
|
|
57
|
+
return next();
|
|
58
|
+
});
|
|
59
|
+
} else s |= 1;
|
|
60
|
+
} catch (e) {
|
|
61
|
+
fail(e);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
65
|
+
if (env.hasError) throw env.error;
|
|
66
|
+
}
|
|
67
|
+
return next();
|
|
68
|
+
})(env);
|
|
69
|
+
}
|
|
4
70
|
const PING_SYM = Symbol('ping');
|
|
5
71
|
/**
|
|
6
72
|
* Derives a new {@link AsyncGenerator} based of {@link iterable}, that yields {@link PING_SYM}
|
|
7
73
|
* whenever no value has been yielded for {@link pingIntervalMs}.
|
|
8
74
|
*/ async function* withPing(iterable, pingIntervalMs) {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
75
|
+
const env = {
|
|
76
|
+
stack: [],
|
|
77
|
+
error: void 0,
|
|
78
|
+
hasError: false
|
|
79
|
+
};
|
|
80
|
+
try {
|
|
81
|
+
const iterator = _ts_add_disposable_resource(env, iteratorResource(iterable), true);
|
|
82
|
+
;
|
|
83
|
+
// declaration outside the loop for garbage collection reasons
|
|
84
|
+
let result;
|
|
85
|
+
let nextPromise = iterator.next();
|
|
86
|
+
while(true){
|
|
87
|
+
const env = {
|
|
88
|
+
stack: [],
|
|
89
|
+
error: void 0,
|
|
90
|
+
hasError: false
|
|
91
|
+
};
|
|
92
|
+
try {
|
|
93
|
+
const pingPromise = _ts_add_disposable_resource(env, timerResource(pingIntervalMs), false);
|
|
94
|
+
;
|
|
95
|
+
result = await Unpromise.race([
|
|
96
|
+
nextPromise,
|
|
97
|
+
pingPromise.start()
|
|
98
|
+
]);
|
|
99
|
+
if (result === disposablePromiseTimerResult) {
|
|
100
|
+
// cancelled
|
|
101
|
+
yield PING_SYM;
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
if (result.done) {
|
|
105
|
+
return result.value;
|
|
106
|
+
}
|
|
107
|
+
nextPromise = iterator.next();
|
|
108
|
+
yield result.value;
|
|
109
|
+
// free up reference for garbage collection
|
|
110
|
+
result = null;
|
|
111
|
+
} catch (e) {
|
|
112
|
+
env.error = e;
|
|
113
|
+
env.hasError = true;
|
|
114
|
+
} finally{
|
|
115
|
+
_ts_dispose_resources(env);
|
|
27
116
|
}
|
|
28
|
-
nextPromise = iterator.next();
|
|
29
|
-
yield result.value;
|
|
30
|
-
// free up reference for garbage collection
|
|
31
|
-
result = null;
|
|
32
|
-
} finally{
|
|
33
|
-
pingPromise[Symbol.dispose]();
|
|
34
117
|
}
|
|
118
|
+
} catch (e) {
|
|
119
|
+
env.error = e;
|
|
120
|
+
env.hasError = true;
|
|
121
|
+
} finally{
|
|
122
|
+
const result = _ts_dispose_resources(env);
|
|
123
|
+
if (result) await result;
|
|
35
124
|
}
|
|
36
125
|
}
|
|
37
126
|
|
|
@@ -63,7 +63,7 @@ export declare const defaultTransformer: CombinedDataTransformer;
|
|
|
63
63
|
/**
|
|
64
64
|
* Takes a unserialized `TRPCResponse` and serializes it with the router's transformers
|
|
65
65
|
**/
|
|
66
|
-
export declare function transformTRPCResponse<TResponse extends TRPCResponse | TRPCResponse[] | TRPCResponseMessage | TRPCResponseMessage[]>(config: RootConfig<AnyRootTypes>, itemOrItems: TResponse): import("./rpc").
|
|
66
|
+
export declare function transformTRPCResponse<TResponse extends TRPCResponse | TRPCResponse[] | TRPCResponseMessage | TRPCResponseMessage[]>(config: RootConfig<AnyRootTypes>, itemOrItems: TResponse): import("./rpc").TRPCSuccessResponse<unknown> | import("./rpc").TRPCErrorResponse<import("./rpc").TRPCErrorShape<object>> | ({
|
|
67
67
|
id: import("./rpc").JSONRPC2.RequestId;
|
|
68
68
|
} & TRPCResultMessage<unknown>) | (TRPCResponse | TRPCResponseMessage)[];
|
|
69
69
|
/** @internal */
|
|
@@ -36,6 +36,7 @@ export * from './unstable-core-do-not-import/stream/sse.types';
|
|
|
36
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
|
+
export * from './unstable-core-do-not-import/stream/utils/disposable';
|
|
39
40
|
export * from './unstable-core-do-not-import/transformer';
|
|
40
41
|
export * from './unstable-core-do-not-import/types';
|
|
41
42
|
export * from './unstable-core-do-not-import/utils';
|