@highstate/designer 0.4.2 → 0.4.3

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 (119) hide show
  1. package/.output/nitro.json +15 -0
  2. package/.output/public/_nuxt/B-YqONwZ.js +1 -0
  3. package/.output/public/_nuxt/COXQCz2I.js +1 -0
  4. package/.output/public/_nuxt/DNF_Kfc9.js +1 -0
  5. package/.output/public/_nuxt/DYyPqv2f.js +164 -0
  6. package/.output/public/_nuxt/builds/latest.json +1 -0
  7. package/.output/public/_nuxt/builds/meta/83577d4c-8c1d-41fa-bec1-21181eaa9f33.json +1 -0
  8. package/.output/public/_nuxt/entry.BSAdMt6G.css +5 -0
  9. package/.output/public/_nuxt/error-404.BJkSn6RI.css +1 -0
  10. package/.output/public/_nuxt/error-500.TOCKLquH.css +1 -0
  11. package/.output/public/favicon.ico +0 -0
  12. package/.output/public/robots.txt +1 -0
  13. package/.output/server/index.mjs +12266 -0
  14. package/.output/server/index.mjs.map +1 -0
  15. package/.output/server/node_modules/@babel/parser/lib/index.js +14183 -0
  16. package/.output/server/node_modules/@babel/parser/package.json +50 -0
  17. package/.output/server/node_modules/@trpc/server/dist/http.mjs +7 -0
  18. package/.output/server/node_modules/@trpc/server/dist/index.mjs +11 -0
  19. package/.output/server/node_modules/@trpc/server/dist/observable/observable.mjs +175 -0
  20. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/createProxy.mjs +73 -0
  21. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/error/TRPCError.mjs +78 -0
  22. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/error/formatter.mjs +5 -0
  23. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/error/getErrorShape.mjs +29 -0
  24. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/http/contentType.mjs +224 -0
  25. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/http/contentTypeParsers.mjs +12 -0
  26. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +76 -0
  27. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/http/isAbortError.mjs +7 -0
  28. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/http/parseConnectionParams.mjs +39 -0
  29. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/http/resolveResponse.mjs +569 -0
  30. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/initTRPC.mjs +80 -0
  31. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/middleware.mjs +90 -0
  32. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/parser.mjs +40 -0
  33. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/procedureBuilder.mjs +194 -0
  34. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/rootConfig.mjs +6 -0
  35. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/router.mjs +176 -0
  36. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/rpc/codes.mjs +54 -0
  37. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/jsonl.mjs +597 -0
  38. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/sse.mjs +359 -0
  39. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/tracked.mjs +25 -0
  40. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/utils/asyncIterable.mjs +167 -0
  41. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/utils/createDeferred.mjs +15 -0
  42. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/utils/disposable.mjs +41 -0
  43. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/utils/mergeAsyncIterables.mjs +239 -0
  44. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/utils/readableStreamFrom.mjs +23 -0
  45. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/utils/timerResource.mjs +23 -0
  46. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/utils/withPing.mjs +127 -0
  47. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/transformer.mjs +101 -0
  48. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/utils.mjs +83 -0
  49. package/.output/server/node_modules/@trpc/server/dist/vendor/unpromise/unpromise.mjs +289 -0
  50. package/.output/server/node_modules/@trpc/server/package.json +156 -0
  51. package/.output/server/node_modules/@unhead/dom/dist/index.mjs +197 -0
  52. package/.output/server/node_modules/@unhead/dom/package.json +40 -0
  53. package/.output/server/node_modules/@unhead/shared/dist/index.mjs +641 -0
  54. package/.output/server/node_modules/@unhead/shared/package.json +45 -0
  55. package/.output/server/node_modules/@unhead/ssr/dist/index.mjs +95 -0
  56. package/.output/server/node_modules/@unhead/ssr/package.json +40 -0
  57. package/.output/server/node_modules/@vue/compiler-core/dist/compiler-core.cjs.prod.js +6690 -0
  58. package/.output/server/node_modules/@vue/compiler-core/package.json +58 -0
  59. package/.output/server/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +686 -0
  60. package/.output/server/node_modules/@vue/compiler-dom/package.json +57 -0
  61. package/.output/server/node_modules/@vue/compiler-ssr/dist/compiler-ssr.cjs.js +1404 -0
  62. package/.output/server/node_modules/@vue/compiler-ssr/package.json +34 -0
  63. package/.output/server/node_modules/@vue/reactivity/dist/reactivity.cjs.prod.js +1789 -0
  64. package/.output/server/node_modules/@vue/reactivity/package.json +55 -0
  65. package/.output/server/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js +6654 -0
  66. package/.output/server/node_modules/@vue/runtime-core/package.json +52 -0
  67. package/.output/server/node_modules/@vue/runtime-dom/dist/runtime-dom.cjs.prod.js +1669 -0
  68. package/.output/server/node_modules/@vue/runtime-dom/package.json +60 -0
  69. package/.output/server/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js +857 -0
  70. package/.output/server/node_modules/@vue/server-renderer/package.json +55 -0
  71. package/.output/server/node_modules/@vue/shared/dist/shared.cjs.prod.js +594 -0
  72. package/.output/server/node_modules/@vue/shared/package.json +47 -0
  73. package/.output/server/node_modules/devalue/index.js +3 -0
  74. package/.output/server/node_modules/devalue/package.json +34 -0
  75. package/.output/server/node_modules/devalue/src/base64.js +110 -0
  76. package/.output/server/node_modules/devalue/src/constants.js +6 -0
  77. package/.output/server/node_modules/devalue/src/parse.js +160 -0
  78. package/.output/server/node_modules/devalue/src/stringify.js +232 -0
  79. package/.output/server/node_modules/devalue/src/uneval.js +351 -0
  80. package/.output/server/node_modules/devalue/src/utils.js +113 -0
  81. package/.output/server/node_modules/entities/lib/decode.js +536 -0
  82. package/.output/server/node_modules/entities/lib/decode_codepoint.js +76 -0
  83. package/.output/server/node_modules/entities/lib/generated/decode-data-html.js +9 -0
  84. package/.output/server/node_modules/entities/lib/generated/decode-data-xml.js +9 -0
  85. package/.output/server/node_modules/entities/package.json +90 -0
  86. package/.output/server/node_modules/estree-walker/dist/umd/estree-walker.js +344 -0
  87. package/.output/server/node_modules/estree-walker/package.json +37 -0
  88. package/.output/server/node_modules/hookable/dist/index.mjs +290 -0
  89. package/.output/server/node_modules/hookable/package.json +49 -0
  90. package/.output/server/node_modules/packrup/dist/index.mjs +108 -0
  91. package/.output/server/node_modules/packrup/package.json +58 -0
  92. package/.output/server/node_modules/source-map-js/lib/array-set.js +121 -0
  93. package/.output/server/node_modules/source-map-js/lib/base64-vlq.js +140 -0
  94. package/.output/server/node_modules/source-map-js/lib/base64.js +67 -0
  95. package/.output/server/node_modules/source-map-js/lib/binary-search.js +111 -0
  96. package/.output/server/node_modules/source-map-js/lib/mapping-list.js +79 -0
  97. package/.output/server/node_modules/source-map-js/lib/quick-sort.js +132 -0
  98. package/.output/server/node_modules/source-map-js/lib/source-map-consumer.js +1188 -0
  99. package/.output/server/node_modules/source-map-js/lib/source-map-generator.js +444 -0
  100. package/.output/server/node_modules/source-map-js/lib/source-node.js +413 -0
  101. package/.output/server/node_modules/source-map-js/lib/util.js +594 -0
  102. package/.output/server/node_modules/source-map-js/package.json +71 -0
  103. package/.output/server/node_modules/source-map-js/source-map.js +8 -0
  104. package/.output/server/node_modules/ufo/dist/index.mjs +630 -0
  105. package/.output/server/node_modules/ufo/package.json +47 -0
  106. package/.output/server/node_modules/unhead/dist/index.mjs +748 -0
  107. package/.output/server/node_modules/unhead/package.json +46 -0
  108. package/.output/server/node_modules/vue/dist/vue.cjs.js +80 -0
  109. package/.output/server/node_modules/vue/dist/vue.cjs.prod.js +66 -0
  110. package/.output/server/node_modules/vue/index.js +7 -0
  111. package/.output/server/node_modules/vue/index.mjs +1 -0
  112. package/.output/server/node_modules/vue/package.json +112 -0
  113. package/.output/server/node_modules/vue/server-renderer/index.mjs +1 -0
  114. package/.output/server/node_modules/vue-bundle-renderer/dist/runtime.mjs +196 -0
  115. package/.output/server/node_modules/vue-bundle-renderer/package.json +50 -0
  116. package/.output/server/node_modules/zod/lib/index.mjs +4382 -0
  117. package/.output/server/node_modules/zod/package.json +122 -0
  118. package/.output/server/package.json +1 -0
  119. package/package.json +4 -4
@@ -0,0 +1,597 @@
1
+ import { isObject, isFunction, run, isAsyncIterable } from '../utils.mjs';
2
+ import { iteratorResource } from './utils/asyncIterable.mjs';
3
+ import { createDeferred } from './utils/createDeferred.mjs';
4
+ import { makeResource } from './utils/disposable.mjs';
5
+ import { mergeAsyncIterables } from './utils/mergeAsyncIterables.mjs';
6
+ import { readableStreamFrom } from './utils/readableStreamFrom.mjs';
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
+ }
86
+ // ---------- types
87
+ // ---------- types
88
+ const CHUNK_VALUE_TYPE_PROMISE = 0;
89
+ const CHUNK_VALUE_TYPE_ASYNC_ITERABLE = 1;
90
+ const PROMISE_STATUS_FULFILLED = 0;
91
+ const PROMISE_STATUS_REJECTED = 1;
92
+ const ASYNC_ITERABLE_STATUS_RETURN = 0;
93
+ const ASYNC_ITERABLE_STATUS_YIELD = 1;
94
+ const ASYNC_ITERABLE_STATUS_ERROR = 2;
95
+ function isPromise(value) {
96
+ return (isObject(value) || isFunction(value)) && typeof value?.['then'] === 'function' && typeof value?.['catch'] === 'function';
97
+ }
98
+ class MaxDepthError extends Error {
99
+ constructor(path){
100
+ super('Max depth reached at path: ' + path.join('.')), _define_property(this, "path", void 0), this.path = path;
101
+ }
102
+ }
103
+ async function* createBatchStreamProducer(opts) {
104
+ const { data } = opts;
105
+ let counter = 0;
106
+ const placeholder = 0;
107
+ const mergedIterables = mergeAsyncIterables();
108
+ function registerAsync(callback) {
109
+ const idx = counter++;
110
+ const iterable = callback(idx);
111
+ mergedIterables.add(iterable);
112
+ return idx;
113
+ }
114
+ function encodePromise(promise, path) {
115
+ return registerAsync(async function*(idx) {
116
+ const error = checkMaxDepth(path);
117
+ if (error) {
118
+ // Catch any errors from the original promise to ensure they're reported
119
+ promise.catch((cause)=>{
120
+ opts.onError?.({
121
+ error: cause,
122
+ path
123
+ });
124
+ });
125
+ // Replace the promise with a rejected one containing the max depth error
126
+ promise = Promise.reject(error);
127
+ }
128
+ try {
129
+ const next = await promise;
130
+ yield [
131
+ idx,
132
+ PROMISE_STATUS_FULFILLED,
133
+ encode(next, path)
134
+ ];
135
+ } catch (cause) {
136
+ opts.onError?.({
137
+ error: cause,
138
+ path
139
+ });
140
+ yield [
141
+ idx,
142
+ PROMISE_STATUS_REJECTED,
143
+ opts.formatError?.({
144
+ error: cause,
145
+ path
146
+ })
147
+ ];
148
+ }
149
+ });
150
+ }
151
+ function encodeAsyncIterable(iterable, path) {
152
+ return registerAsync(async function*(idx) {
153
+ const env = {
154
+ stack: [],
155
+ error: void 0,
156
+ hasError: false
157
+ };
158
+ try {
159
+ const error = checkMaxDepth(path);
160
+ if (error) {
161
+ throw error;
162
+ }
163
+ const iterator = _ts_add_disposable_resource(env, iteratorResource(iterable), true);
164
+ ;
165
+ try {
166
+ while(true){
167
+ const next = await iterator.next();
168
+ if (next.done) {
169
+ yield [
170
+ idx,
171
+ ASYNC_ITERABLE_STATUS_RETURN,
172
+ encode(next.value, path)
173
+ ];
174
+ break;
175
+ }
176
+ yield [
177
+ idx,
178
+ ASYNC_ITERABLE_STATUS_YIELD,
179
+ encode(next.value, path)
180
+ ];
181
+ }
182
+ } catch (cause) {
183
+ opts.onError?.({
184
+ error: cause,
185
+ path
186
+ });
187
+ yield [
188
+ idx,
189
+ ASYNC_ITERABLE_STATUS_ERROR,
190
+ opts.formatError?.({
191
+ error: cause,
192
+ path
193
+ })
194
+ ];
195
+ }
196
+ } catch (e) {
197
+ env.error = e;
198
+ env.hasError = true;
199
+ } finally{
200
+ const result = _ts_dispose_resources(env);
201
+ if (result) await result;
202
+ }
203
+ });
204
+ }
205
+ function checkMaxDepth(path) {
206
+ if (opts.maxDepth && path.length > opts.maxDepth) {
207
+ return new MaxDepthError(path);
208
+ }
209
+ return null;
210
+ }
211
+ function encodeAsync(value, path) {
212
+ if (isPromise(value)) {
213
+ return [
214
+ CHUNK_VALUE_TYPE_PROMISE,
215
+ encodePromise(value, path)
216
+ ];
217
+ }
218
+ if (isAsyncIterable(value)) {
219
+ if (opts.maxDepth && path.length >= opts.maxDepth) {
220
+ throw new Error('Max depth reached');
221
+ }
222
+ return [
223
+ CHUNK_VALUE_TYPE_ASYNC_ITERABLE,
224
+ encodeAsyncIterable(value, path)
225
+ ];
226
+ }
227
+ return null;
228
+ }
229
+ function encode(value, path) {
230
+ if (value === undefined) {
231
+ return [
232
+ []
233
+ ];
234
+ }
235
+ if (!isObject(value)) {
236
+ return [
237
+ [
238
+ value
239
+ ]
240
+ ];
241
+ }
242
+ const reg = encodeAsync(value, path);
243
+ if (reg) {
244
+ return [
245
+ [
246
+ placeholder
247
+ ],
248
+ [
249
+ null,
250
+ ...reg
251
+ ]
252
+ ];
253
+ }
254
+ const newObj = {};
255
+ const asyncValues = [];
256
+ for (const [key, item] of Object.entries(value)){
257
+ const transformed = encodeAsync(item, [
258
+ ...path,
259
+ key
260
+ ]);
261
+ if (!transformed) {
262
+ newObj[key] = item;
263
+ continue;
264
+ }
265
+ newObj[key] = placeholder;
266
+ asyncValues.push([
267
+ key,
268
+ ...transformed
269
+ ]);
270
+ }
271
+ return [
272
+ [
273
+ newObj
274
+ ],
275
+ ...asyncValues
276
+ ];
277
+ }
278
+ const newHead = {};
279
+ for (const [key, item] of Object.entries(data)){
280
+ newHead[key] = encode(item, [
281
+ key
282
+ ]);
283
+ }
284
+ yield newHead;
285
+ for await (const value of mergedIterables){
286
+ yield value;
287
+ }
288
+ }
289
+ /**
290
+ * JSON Lines stream producer
291
+ * @see https://jsonlines.org/
292
+ */ function jsonlStreamProducer(opts) {
293
+ let stream = readableStreamFrom(createBatchStreamProducer(opts));
294
+ const { serialize } = opts;
295
+ if (serialize) {
296
+ stream = stream.pipeThrough(new TransformStream({
297
+ transform (chunk, controller) {
298
+ controller.enqueue(serialize(chunk));
299
+ }
300
+ }));
301
+ }
302
+ return stream.pipeThrough(new TransformStream({
303
+ transform (chunk, controller) {
304
+ controller.enqueue(JSON.stringify(chunk) + '\n');
305
+ }
306
+ })).pipeThrough(new TextEncoderStream());
307
+ }
308
+ class StreamInterruptedError extends Error {
309
+ constructor(cause){
310
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
311
+ // @ts-ignore https://github.com/tc39/proposal-error-cause
312
+ super('Invalid response or stream interrupted', {
313
+ cause
314
+ });
315
+ }
316
+ }
317
+ class AsyncError extends Error {
318
+ constructor(data){
319
+ super('Received error from server'), _define_property(this, "data", void 0), this.data = data;
320
+ }
321
+ }
322
+ const nodeJsStreamToReaderEsque = (source)=>{
323
+ return {
324
+ getReader () {
325
+ const stream = new ReadableStream({
326
+ start (controller) {
327
+ source.on('data', (chunk)=>{
328
+ controller.enqueue(chunk);
329
+ });
330
+ source.on('end', ()=>{
331
+ controller.close();
332
+ });
333
+ source.on('error', (error)=>{
334
+ controller.error(error);
335
+ });
336
+ }
337
+ });
338
+ return stream.getReader();
339
+ }
340
+ };
341
+ };
342
+ function createLineAccumulator(from) {
343
+ const reader = 'getReader' in from ? from.getReader() : nodeJsStreamToReaderEsque(from).getReader();
344
+ let lineAggregate = '';
345
+ return new ReadableStream({
346
+ async pull (controller) {
347
+ const { done, value } = await reader.read();
348
+ if (done) {
349
+ controller.close();
350
+ } else {
351
+ controller.enqueue(value);
352
+ }
353
+ },
354
+ cancel () {
355
+ return reader.cancel();
356
+ }
357
+ }).pipeThrough(new TextDecoderStream()).pipeThrough(new TransformStream({
358
+ transform (chunk, controller) {
359
+ lineAggregate += chunk;
360
+ const parts = lineAggregate.split('\n');
361
+ lineAggregate = parts.pop() ?? '';
362
+ for (const part of parts){
363
+ controller.enqueue(part);
364
+ }
365
+ }
366
+ }));
367
+ }
368
+ function createConsumerStream(from) {
369
+ const stream = createLineAccumulator(from);
370
+ let sentHead = false;
371
+ return stream.pipeThrough(new TransformStream({
372
+ transform (line, controller) {
373
+ if (!sentHead) {
374
+ const head = JSON.parse(line);
375
+ controller.enqueue(head);
376
+ sentHead = true;
377
+ } else {
378
+ const chunk = JSON.parse(line);
379
+ controller.enqueue(chunk);
380
+ }
381
+ }
382
+ }));
383
+ }
384
+ /**
385
+ * Creates a handler for managing stream controllers and their lifecycle
386
+ */ function createStreamsManager(abortController) {
387
+ const controllerMap = new Map();
388
+ /**
389
+ * Checks if there are no pending controllers or deferred promises
390
+ */ function isEmpty() {
391
+ return Array.from(controllerMap.values()).every((c)=>c.closed);
392
+ }
393
+ /**
394
+ * Creates a stream controller
395
+ */ function createStreamController() {
396
+ let originalController;
397
+ const stream = new ReadableStream({
398
+ start (controller) {
399
+ originalController = controller;
400
+ }
401
+ });
402
+ const streamController = {
403
+ enqueue: (v)=>originalController.enqueue(v),
404
+ close: ()=>{
405
+ originalController.close();
406
+ // mark as closed and remove methods
407
+ Object.assign(streamController, {
408
+ closed: true,
409
+ close: ()=>{
410
+ // noop
411
+ },
412
+ enqueue: ()=>{
413
+ // noop
414
+ },
415
+ getReaderResource: null
416
+ });
417
+ if (isEmpty()) {
418
+ abortController.abort();
419
+ }
420
+ },
421
+ closed: false,
422
+ getReaderResource: ()=>{
423
+ const reader = stream.getReader();
424
+ return makeResource(reader, ()=>{
425
+ reader.releaseLock();
426
+ streamController.close();
427
+ });
428
+ }
429
+ };
430
+ return streamController;
431
+ }
432
+ /**
433
+ * Gets or creates a stream controller
434
+ */ function getOrCreate(chunkId) {
435
+ let c = controllerMap.get(chunkId);
436
+ if (!c) {
437
+ c = createStreamController();
438
+ controllerMap.set(chunkId, c);
439
+ }
440
+ return c;
441
+ }
442
+ /**
443
+ * Cancels all pending controllers and rejects deferred promises
444
+ */ function cancelAll(reason) {
445
+ const error = new StreamInterruptedError(reason);
446
+ for (const controller of controllerMap.values()){
447
+ controller.enqueue(error);
448
+ controller.close();
449
+ }
450
+ }
451
+ return {
452
+ getOrCreate,
453
+ isEmpty,
454
+ cancelAll
455
+ };
456
+ }
457
+ /**
458
+ * JSON Lines stream consumer
459
+ * @see https://jsonlines.org/
460
+ */ async function jsonlStreamConsumer(opts) {
461
+ const { deserialize = (v)=>v } = opts;
462
+ let source = createConsumerStream(opts.from);
463
+ if (deserialize) {
464
+ source = source.pipeThrough(new TransformStream({
465
+ transform (chunk, controller) {
466
+ controller.enqueue(deserialize(chunk));
467
+ }
468
+ }));
469
+ }
470
+ let headDeferred = createDeferred();
471
+ const streamManager = createStreamsManager(opts.abortController);
472
+ function decodeChunkDefinition(value) {
473
+ const [_path, type, chunkId] = value;
474
+ const controller = streamManager.getOrCreate(chunkId);
475
+ switch(type){
476
+ case CHUNK_VALUE_TYPE_PROMISE:
477
+ {
478
+ return run(async ()=>{
479
+ const env = {
480
+ stack: [],
481
+ error: void 0,
482
+ hasError: false
483
+ };
484
+ try {
485
+ const reader = _ts_add_disposable_resource(env, controller.getReaderResource(), false);
486
+ ;
487
+ const { value } = await reader.read();
488
+ if (value instanceof StreamInterruptedError) {
489
+ throw value;
490
+ }
491
+ const [_chunkId, status, data] = value;
492
+ switch(status){
493
+ case PROMISE_STATUS_FULFILLED:
494
+ return decode(data);
495
+ case PROMISE_STATUS_REJECTED:
496
+ throw opts.formatError?.({
497
+ error: data
498
+ }) ?? new AsyncError(data);
499
+ }
500
+ } catch (e) {
501
+ env.error = e;
502
+ env.hasError = true;
503
+ } finally{
504
+ _ts_dispose_resources(env);
505
+ }
506
+ });
507
+ }
508
+ case CHUNK_VALUE_TYPE_ASYNC_ITERABLE:
509
+ {
510
+ return run(async function*() {
511
+ const env = {
512
+ stack: [],
513
+ error: void 0,
514
+ hasError: false
515
+ };
516
+ try {
517
+ const reader = _ts_add_disposable_resource(env, controller.getReaderResource(), false);
518
+ ;
519
+ while(true){
520
+ const { value } = await reader.read();
521
+ if (value instanceof StreamInterruptedError) {
522
+ throw value;
523
+ }
524
+ const [_chunkId, status, data] = value;
525
+ switch(status){
526
+ case ASYNC_ITERABLE_STATUS_YIELD:
527
+ yield decode(data);
528
+ break;
529
+ case ASYNC_ITERABLE_STATUS_RETURN:
530
+ return decode(data);
531
+ case ASYNC_ITERABLE_STATUS_ERROR:
532
+ throw opts.formatError?.({
533
+ error: data
534
+ }) ?? new AsyncError(data);
535
+ }
536
+ }
537
+ } catch (e) {
538
+ env.error = e;
539
+ env.hasError = true;
540
+ } finally{
541
+ _ts_dispose_resources(env);
542
+ }
543
+ });
544
+ }
545
+ }
546
+ }
547
+ function decode(value) {
548
+ const [[data], ...asyncProps] = value;
549
+ for (const value of asyncProps){
550
+ const [key] = value;
551
+ const decoded = decodeChunkDefinition(value);
552
+ if (key === null) {
553
+ return decoded;
554
+ }
555
+ data[key] = decoded;
556
+ }
557
+ return data;
558
+ }
559
+ const closeOrAbort = (reason)=>{
560
+ const error = new StreamInterruptedError(reason);
561
+ headDeferred?.reject(error);
562
+ streamManager.cancelAll(error);
563
+ };
564
+ source.pipeTo(new WritableStream({
565
+ write (chunkOrHead) {
566
+ if (headDeferred) {
567
+ const head = chunkOrHead;
568
+ for (const [key, value] of Object.entries(chunkOrHead)){
569
+ const parsed = decode(value);
570
+ head[key] = parsed;
571
+ }
572
+ headDeferred.resolve(head);
573
+ headDeferred = null;
574
+ return;
575
+ }
576
+ const chunk = chunkOrHead;
577
+ const [idx] = chunk;
578
+ const controller = streamManager.getOrCreate(idx);
579
+ controller.enqueue(chunk);
580
+ },
581
+ close: closeOrAbort,
582
+ abort: closeOrAbort
583
+ }), {
584
+ signal: opts.abortController.signal
585
+ }).catch((error)=>{
586
+ opts.onError?.({
587
+ error
588
+ });
589
+ closeOrAbort(error);
590
+ });
591
+ return [
592
+ await headDeferred.promise,
593
+ streamManager
594
+ ];
595
+ }
596
+
597
+ export { isPromise, jsonlStreamConsumer, jsonlStreamProducer };