@trpc/server 11.0.0-rc.645 → 11.0.0-rc.657
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.7.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/middleware.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/jsonl.d.ts +8 -34
- 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 +3 -4
- 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,9 +1,88 @@
|
|
|
1
|
-
import { _ as _define_property } from '../../node_modules/.pnpm/@swc_helpers@0.5.13/node_modules/@swc/helpers/esm/_define_property.mjs';
|
|
2
1
|
import { Unpromise } from '../../vendor/unpromise/unpromise.mjs';
|
|
3
|
-
import { isObject, isFunction,
|
|
2
|
+
import { isObject, isFunction, isAsyncIterable, run } from '../utils.mjs';
|
|
3
|
+
import { iteratorResource } from './utils/asyncIterable.mjs';
|
|
4
4
|
import { createDeferred } from './utils/createDeferred.mjs';
|
|
5
|
+
import { makeAsyncResource, makeResource } from './utils/disposable.mjs';
|
|
5
6
|
import { readableStreamFrom } from './utils/readableStreamFrom.mjs';
|
|
6
7
|
|
|
8
|
+
function _define_property(obj, key, value) {
|
|
9
|
+
if (key in obj) {
|
|
10
|
+
Object.defineProperty(obj, key, {
|
|
11
|
+
value: value,
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true
|
|
15
|
+
});
|
|
16
|
+
} else {
|
|
17
|
+
obj[key] = value;
|
|
18
|
+
}
|
|
19
|
+
return obj;
|
|
20
|
+
}
|
|
21
|
+
function _ts_add_disposable_resource(env, value, async) {
|
|
22
|
+
if (value !== null && value !== void 0) {
|
|
23
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
24
|
+
var dispose, inner;
|
|
25
|
+
if (async) {
|
|
26
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
27
|
+
dispose = value[Symbol.asyncDispose];
|
|
28
|
+
}
|
|
29
|
+
if (dispose === void 0) {
|
|
30
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
31
|
+
dispose = value[Symbol.dispose];
|
|
32
|
+
if (async) inner = dispose;
|
|
33
|
+
}
|
|
34
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
35
|
+
if (inner) dispose = function() {
|
|
36
|
+
try {
|
|
37
|
+
inner.call(this);
|
|
38
|
+
} catch (e) {
|
|
39
|
+
return Promise.reject(e);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
env.stack.push({
|
|
43
|
+
value: value,
|
|
44
|
+
dispose: dispose,
|
|
45
|
+
async: async
|
|
46
|
+
});
|
|
47
|
+
} else if (async) {
|
|
48
|
+
env.stack.push({
|
|
49
|
+
async: true
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
function _ts_dispose_resources(env) {
|
|
55
|
+
var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
56
|
+
var e = new Error(message);
|
|
57
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
58
|
+
};
|
|
59
|
+
return (_ts_dispose_resources = function _ts_dispose_resources(env) {
|
|
60
|
+
function fail(e) {
|
|
61
|
+
env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
62
|
+
env.hasError = true;
|
|
63
|
+
}
|
|
64
|
+
var r, s = 0;
|
|
65
|
+
function next() {
|
|
66
|
+
while(r = env.stack.pop()){
|
|
67
|
+
try {
|
|
68
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
69
|
+
if (r.dispose) {
|
|
70
|
+
var result = r.dispose.call(r.value);
|
|
71
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
|
|
72
|
+
fail(e);
|
|
73
|
+
return next();
|
|
74
|
+
});
|
|
75
|
+
} else s |= 1;
|
|
76
|
+
} catch (e) {
|
|
77
|
+
fail(e);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
81
|
+
if (env.hasError) throw env.error;
|
|
82
|
+
}
|
|
83
|
+
return next();
|
|
84
|
+
})(env);
|
|
85
|
+
}
|
|
7
86
|
// ---------- types
|
|
8
87
|
// ---------- types
|
|
9
88
|
const CHUNK_VALUE_TYPE_PROMISE = 0;
|
|
@@ -22,175 +101,195 @@ class MaxDepthError extends Error {
|
|
|
22
101
|
}
|
|
23
102
|
}
|
|
24
103
|
async function* createBatchStreamProducer(opts) {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
104
|
+
const env = {
|
|
105
|
+
stack: [],
|
|
106
|
+
error: void 0,
|
|
107
|
+
hasError: false
|
|
108
|
+
};
|
|
109
|
+
try {
|
|
110
|
+
const { data } = opts;
|
|
111
|
+
let counter = 0;
|
|
112
|
+
const placeholder = 0;
|
|
113
|
+
const queue = _ts_add_disposable_resource(env, makeAsyncResource(new Set(), async ()=>{
|
|
114
|
+
await Promise.all(Array.from(queue).map((it)=>it.iterator.return?.()));
|
|
115
|
+
}), true);
|
|
116
|
+
;
|
|
117
|
+
function registerAsync(callback) {
|
|
118
|
+
const idx = counter++;
|
|
119
|
+
const iterator = callback(idx)[Symbol.asyncIterator]();
|
|
120
|
+
const nextPromise = iterator.next();
|
|
121
|
+
nextPromise.catch(()=>{
|
|
122
|
+
// prevent unhandled promise rejection
|
|
123
|
+
});
|
|
124
|
+
queue.add({
|
|
125
|
+
iterator,
|
|
126
|
+
nextPromise
|
|
127
|
+
});
|
|
128
|
+
return idx;
|
|
129
|
+
}
|
|
130
|
+
function encodePromise(promise, path) {
|
|
131
|
+
return registerAsync(async function*(idx) {
|
|
132
|
+
const error = checkMaxDepth(path);
|
|
133
|
+
if (error) {
|
|
134
|
+
// Catch any errors from the original promise to ensure they're reported
|
|
135
|
+
promise.catch((cause)=>{
|
|
136
|
+
opts.onError?.({
|
|
137
|
+
error: cause,
|
|
138
|
+
path
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
// Replace the promise with a rejected one containing the max depth error
|
|
142
|
+
promise = Promise.reject(error);
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
const next = await promise;
|
|
146
|
+
return [
|
|
147
|
+
idx,
|
|
148
|
+
PROMISE_STATUS_FULFILLED,
|
|
149
|
+
encode(next, path)
|
|
150
|
+
];
|
|
151
|
+
} catch (cause) {
|
|
48
152
|
opts.onError?.({
|
|
49
153
|
error: cause,
|
|
50
154
|
path
|
|
51
155
|
});
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
156
|
+
return [
|
|
157
|
+
idx,
|
|
158
|
+
PROMISE_STATUS_REJECTED,
|
|
159
|
+
opts.formatError?.({
|
|
160
|
+
error: cause,
|
|
161
|
+
path
|
|
162
|
+
})
|
|
163
|
+
];
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
function encodeAsyncIterable(iterable, path) {
|
|
168
|
+
return registerAsync(async function*(idx) {
|
|
169
|
+
const env = {
|
|
170
|
+
stack: [],
|
|
171
|
+
error: void 0,
|
|
172
|
+
hasError: false
|
|
173
|
+
};
|
|
174
|
+
try {
|
|
175
|
+
const error = checkMaxDepth(path);
|
|
176
|
+
if (error) {
|
|
177
|
+
throw error;
|
|
178
|
+
}
|
|
179
|
+
const iterator = _ts_add_disposable_resource(env, iteratorResource(iterable), true);
|
|
180
|
+
;
|
|
181
|
+
try {
|
|
182
|
+
while(true){
|
|
183
|
+
const next = await iterator.next();
|
|
184
|
+
if (next.done) {
|
|
185
|
+
return [
|
|
186
|
+
idx,
|
|
187
|
+
ASYNC_ITERABLE_STATUS_RETURN,
|
|
188
|
+
encode(next.value, path)
|
|
189
|
+
];
|
|
190
|
+
}
|
|
191
|
+
yield [
|
|
192
|
+
idx,
|
|
193
|
+
ASYNC_ITERABLE_STATUS_YIELD,
|
|
194
|
+
encode(next.value, path)
|
|
195
|
+
];
|
|
196
|
+
}
|
|
197
|
+
} catch (cause) {
|
|
198
|
+
opts.onError?.({
|
|
199
|
+
error: cause,
|
|
200
|
+
path
|
|
201
|
+
});
|
|
202
|
+
return [
|
|
203
|
+
idx,
|
|
204
|
+
ASYNC_ITERABLE_STATUS_ERROR,
|
|
205
|
+
opts.formatError?.({
|
|
206
|
+
error: cause,
|
|
207
|
+
path
|
|
208
|
+
})
|
|
209
|
+
];
|
|
210
|
+
}
|
|
211
|
+
} catch (e) {
|
|
212
|
+
env.error = e;
|
|
213
|
+
env.hasError = true;
|
|
214
|
+
} finally{
|
|
215
|
+
const result = _ts_dispose_resources(env);
|
|
216
|
+
if (result) await result;
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
function checkMaxDepth(path) {
|
|
221
|
+
if (opts.maxDepth && path.length > opts.maxDepth) {
|
|
222
|
+
return new MaxDepthError(path);
|
|
55
223
|
}
|
|
56
|
-
|
|
57
|
-
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
function encodeAsync(value, path) {
|
|
227
|
+
if (isPromise(value)) {
|
|
58
228
|
return [
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
encode(next, path)
|
|
229
|
+
CHUNK_VALUE_TYPE_PROMISE,
|
|
230
|
+
encodePromise(value, path)
|
|
62
231
|
];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
232
|
+
}
|
|
233
|
+
if (isAsyncIterable(value)) {
|
|
234
|
+
if (opts.maxDepth && path.length >= opts.maxDepth) {
|
|
235
|
+
throw new Error('Max depth reached');
|
|
236
|
+
}
|
|
68
237
|
return [
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
opts.formatError?.({
|
|
72
|
-
error: cause,
|
|
73
|
-
path
|
|
74
|
-
})
|
|
238
|
+
CHUNK_VALUE_TYPE_ASYNC_ITERABLE,
|
|
239
|
+
encodeAsyncIterable(value, path)
|
|
75
240
|
];
|
|
76
241
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
function encode(value, path) {
|
|
245
|
+
if (value === undefined) {
|
|
246
|
+
return [
|
|
247
|
+
[]
|
|
248
|
+
];
|
|
84
249
|
}
|
|
85
|
-
|
|
86
|
-
try {
|
|
87
|
-
while(true){
|
|
88
|
-
const next = await iterator.next();
|
|
89
|
-
if (next.done) {
|
|
90
|
-
return [
|
|
91
|
-
idx,
|
|
92
|
-
ASYNC_ITERABLE_STATUS_RETURN,
|
|
93
|
-
encode(next.value, path)
|
|
94
|
-
];
|
|
95
|
-
}
|
|
96
|
-
yield [
|
|
97
|
-
idx,
|
|
98
|
-
ASYNC_ITERABLE_STATUS_YIELD,
|
|
99
|
-
encode(next.value, path)
|
|
100
|
-
];
|
|
101
|
-
}
|
|
102
|
-
} catch (cause) {
|
|
103
|
-
opts.onError?.({
|
|
104
|
-
error: cause,
|
|
105
|
-
path
|
|
106
|
-
});
|
|
250
|
+
if (!isObject(value)) {
|
|
107
251
|
return [
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
error: cause,
|
|
112
|
-
path
|
|
113
|
-
})
|
|
252
|
+
[
|
|
253
|
+
value
|
|
254
|
+
]
|
|
114
255
|
];
|
|
115
|
-
} finally{
|
|
116
|
-
await iterator.return?.();
|
|
117
256
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
];
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
257
|
+
const reg = encodeAsync(value, path);
|
|
258
|
+
if (reg) {
|
|
259
|
+
return [
|
|
260
|
+
[
|
|
261
|
+
placeholder
|
|
262
|
+
],
|
|
263
|
+
[
|
|
264
|
+
null,
|
|
265
|
+
...reg
|
|
266
|
+
]
|
|
267
|
+
];
|
|
268
|
+
}
|
|
269
|
+
const newObj = {};
|
|
270
|
+
const asyncValues = [];
|
|
271
|
+
for (const [key, item] of Object.entries(value)){
|
|
272
|
+
const transformed = encodeAsync(item, [
|
|
273
|
+
...path,
|
|
274
|
+
key
|
|
275
|
+
]);
|
|
276
|
+
if (!transformed) {
|
|
277
|
+
newObj[key] = item;
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
newObj[key] = placeholder;
|
|
281
|
+
asyncValues.push([
|
|
282
|
+
key,
|
|
283
|
+
...transformed
|
|
284
|
+
]);
|
|
136
285
|
}
|
|
137
|
-
return [
|
|
138
|
-
CHUNK_VALUE_TYPE_ASYNC_ITERABLE,
|
|
139
|
-
encodeAsyncIterable(value, path)
|
|
140
|
-
];
|
|
141
|
-
}
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
function encode(value, path) {
|
|
145
|
-
if (value === undefined) {
|
|
146
|
-
return [
|
|
147
|
-
[]
|
|
148
|
-
];
|
|
149
|
-
}
|
|
150
|
-
if (!isObject(value)) {
|
|
151
|
-
return [
|
|
152
|
-
[
|
|
153
|
-
value
|
|
154
|
-
]
|
|
155
|
-
];
|
|
156
|
-
}
|
|
157
|
-
const reg = encodeAsync(value, path);
|
|
158
|
-
if (reg) {
|
|
159
286
|
return [
|
|
160
287
|
[
|
|
161
|
-
|
|
288
|
+
newObj
|
|
162
289
|
],
|
|
163
|
-
|
|
164
|
-
null,
|
|
165
|
-
...reg
|
|
166
|
-
]
|
|
290
|
+
...asyncValues
|
|
167
291
|
];
|
|
168
292
|
}
|
|
169
|
-
const newObj = {};
|
|
170
|
-
const asyncValues = [];
|
|
171
|
-
for (const [key, item] of Object.entries(value)){
|
|
172
|
-
const transformed = encodeAsync(item, [
|
|
173
|
-
...path,
|
|
174
|
-
key
|
|
175
|
-
]);
|
|
176
|
-
if (!transformed) {
|
|
177
|
-
newObj[key] = item;
|
|
178
|
-
continue;
|
|
179
|
-
}
|
|
180
|
-
newObj[key] = placeholder;
|
|
181
|
-
asyncValues.push([
|
|
182
|
-
key,
|
|
183
|
-
...transformed
|
|
184
|
-
]);
|
|
185
|
-
}
|
|
186
|
-
return [
|
|
187
|
-
[
|
|
188
|
-
newObj
|
|
189
|
-
],
|
|
190
|
-
...asyncValues
|
|
191
|
-
];
|
|
192
|
-
}
|
|
193
|
-
try {
|
|
194
293
|
const newHead = {};
|
|
195
294
|
for (const [key, item] of Object.entries(data)){
|
|
196
295
|
newHead[key] = encode(item, [
|
|
@@ -213,11 +312,12 @@ async function* createBatchStreamProducer(opts) {
|
|
|
213
312
|
queue.add(entry);
|
|
214
313
|
}
|
|
215
314
|
}
|
|
315
|
+
} catch (e) {
|
|
316
|
+
env.error = e;
|
|
317
|
+
env.hasError = true;
|
|
216
318
|
} finally{
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
await Promise.all(Array.from(queue).map((it)=>it.iterator.return?.()));
|
|
220
|
-
queue.clear();
|
|
319
|
+
const result = _ts_dispose_resources(env);
|
|
320
|
+
if (result) await result;
|
|
221
321
|
}
|
|
222
322
|
}
|
|
223
323
|
/**
|
|
@@ -324,54 +424,68 @@ function createConsumerStream(from) {
|
|
|
324
424
|
*/ function isEmpty() {
|
|
325
425
|
return Array.from(controllerMap.values()).every((c)=>c.closed);
|
|
326
426
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
427
|
+
/**
|
|
428
|
+
* Creates a stream controller
|
|
429
|
+
*/ function createStreamController() {
|
|
430
|
+
let originalController;
|
|
431
|
+
const stream = new ReadableStream({
|
|
432
|
+
start (controller) {
|
|
433
|
+
originalController = controller;
|
|
332
434
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
435
|
+
});
|
|
436
|
+
const streamController = {
|
|
437
|
+
enqueue: (v)=>originalController.enqueue(v),
|
|
438
|
+
close: ()=>{
|
|
439
|
+
originalController.close();
|
|
440
|
+
// mark as closed and remove methods
|
|
441
|
+
Object.assign(streamController, {
|
|
442
|
+
closed: true,
|
|
443
|
+
close: ()=>{
|
|
444
|
+
// noop
|
|
445
|
+
},
|
|
446
|
+
enqueue: ()=>{
|
|
447
|
+
// noop
|
|
448
|
+
},
|
|
449
|
+
getReaderResource: null
|
|
450
|
+
});
|
|
451
|
+
if (isEmpty()) {
|
|
452
|
+
abortController.abort();
|
|
337
453
|
}
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
close: ()=>{
|
|
347
|
-
// noop
|
|
348
|
-
},
|
|
349
|
-
enqueue: ()=>{
|
|
350
|
-
// noop
|
|
351
|
-
}
|
|
352
|
-
});
|
|
353
|
-
if (isEmpty()) {
|
|
354
|
-
abortController.abort();
|
|
355
|
-
}
|
|
356
|
-
},
|
|
357
|
-
closed: false,
|
|
358
|
-
getReader: ()=>stream.getReader()
|
|
359
|
-
};
|
|
360
|
-
controllerMap.set(chunkId, controllerEsque);
|
|
361
|
-
return controllerEsque;
|
|
362
|
-
},
|
|
363
|
-
/**
|
|
364
|
-
* Check if there are no pending controllers
|
|
365
|
-
**/ isEmpty,
|
|
366
|
-
/**
|
|
367
|
-
* Cancels all pending controllers and rejects deferred promises
|
|
368
|
-
*/ cancelAll (reason) {
|
|
369
|
-
const error = new StreamInterruptedError(reason);
|
|
370
|
-
for (const controller of controllerMap.values()){
|
|
371
|
-
controller.enqueue(error);
|
|
372
|
-
controller.close();
|
|
454
|
+
},
|
|
455
|
+
closed: false,
|
|
456
|
+
getReaderResource: ()=>{
|
|
457
|
+
const reader = stream.getReader();
|
|
458
|
+
return makeResource(reader, ()=>{
|
|
459
|
+
reader.releaseLock();
|
|
460
|
+
streamController.close();
|
|
461
|
+
});
|
|
373
462
|
}
|
|
463
|
+
};
|
|
464
|
+
return streamController;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Gets or creates a stream controller
|
|
468
|
+
*/ function getOrCreate(chunkId) {
|
|
469
|
+
let c = controllerMap.get(chunkId);
|
|
470
|
+
if (!c) {
|
|
471
|
+
c = createStreamController();
|
|
472
|
+
controllerMap.set(chunkId, c);
|
|
374
473
|
}
|
|
474
|
+
return c;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Cancels all pending controllers and rejects deferred promises
|
|
478
|
+
*/ function cancelAll(reason) {
|
|
479
|
+
const error = new StreamInterruptedError(reason);
|
|
480
|
+
for (const controller of controllerMap.values()){
|
|
481
|
+
controller.enqueue(error);
|
|
482
|
+
controller.close();
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
return {
|
|
486
|
+
getOrCreate,
|
|
487
|
+
isEmpty,
|
|
488
|
+
cancelAll
|
|
375
489
|
};
|
|
376
490
|
}
|
|
377
491
|
/**
|
|
@@ -396,8 +510,14 @@ function createConsumerStream(from) {
|
|
|
396
510
|
case CHUNK_VALUE_TYPE_PROMISE:
|
|
397
511
|
{
|
|
398
512
|
return run(async ()=>{
|
|
399
|
-
const
|
|
513
|
+
const env = {
|
|
514
|
+
stack: [],
|
|
515
|
+
error: void 0,
|
|
516
|
+
hasError: false
|
|
517
|
+
};
|
|
400
518
|
try {
|
|
519
|
+
const reader = _ts_add_disposable_resource(env, controller.getReaderResource(), false);
|
|
520
|
+
;
|
|
401
521
|
const { value } = await reader.read();
|
|
402
522
|
if (value instanceof StreamInterruptedError) {
|
|
403
523
|
throw value;
|
|
@@ -411,17 +531,25 @@ function createConsumerStream(from) {
|
|
|
411
531
|
error: data
|
|
412
532
|
}) ?? new AsyncError(data);
|
|
413
533
|
}
|
|
534
|
+
} catch (e) {
|
|
535
|
+
env.error = e;
|
|
536
|
+
env.hasError = true;
|
|
414
537
|
} finally{
|
|
415
|
-
|
|
416
|
-
controller.close();
|
|
538
|
+
_ts_dispose_resources(env);
|
|
417
539
|
}
|
|
418
540
|
});
|
|
419
541
|
}
|
|
420
542
|
case CHUNK_VALUE_TYPE_ASYNC_ITERABLE:
|
|
421
543
|
{
|
|
422
|
-
async function*
|
|
423
|
-
const
|
|
544
|
+
return run(async function*() {
|
|
545
|
+
const env = {
|
|
546
|
+
stack: [],
|
|
547
|
+
error: void 0,
|
|
548
|
+
hasError: false
|
|
549
|
+
};
|
|
424
550
|
try {
|
|
551
|
+
const reader = _ts_add_disposable_resource(env, controller.getReaderResource(), false);
|
|
552
|
+
;
|
|
425
553
|
while(true){
|
|
426
554
|
const { value } = await reader.read();
|
|
427
555
|
if (value instanceof StreamInterruptedError) {
|
|
@@ -440,12 +568,13 @@ function createConsumerStream(from) {
|
|
|
440
568
|
}) ?? new AsyncError(data);
|
|
441
569
|
}
|
|
442
570
|
}
|
|
571
|
+
} catch (e) {
|
|
572
|
+
env.error = e;
|
|
573
|
+
env.hasError = true;
|
|
443
574
|
} finally{
|
|
444
|
-
|
|
445
|
-
controller.close();
|
|
575
|
+
_ts_dispose_resources(env);
|
|
446
576
|
}
|
|
447
|
-
}
|
|
448
|
-
return generator();
|
|
577
|
+
});
|
|
449
578
|
}
|
|
450
579
|
}
|
|
451
580
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/stream/sse.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/stream/sse.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAWpD,KAAK,SAAS,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC;AACrC,KAAK,WAAW,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC;AAEvC;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH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