@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.
- package/.output/nitro.json +15 -0
- package/.output/public/_nuxt/B-YqONwZ.js +1 -0
- package/.output/public/_nuxt/COXQCz2I.js +1 -0
- package/.output/public/_nuxt/DNF_Kfc9.js +1 -0
- package/.output/public/_nuxt/DYyPqv2f.js +164 -0
- package/.output/public/_nuxt/builds/latest.json +1 -0
- package/.output/public/_nuxt/builds/meta/83577d4c-8c1d-41fa-bec1-21181eaa9f33.json +1 -0
- package/.output/public/_nuxt/entry.BSAdMt6G.css +5 -0
- package/.output/public/_nuxt/error-404.BJkSn6RI.css +1 -0
- package/.output/public/_nuxt/error-500.TOCKLquH.css +1 -0
- package/.output/public/favicon.ico +0 -0
- package/.output/public/robots.txt +1 -0
- package/.output/server/index.mjs +12266 -0
- package/.output/server/index.mjs.map +1 -0
- package/.output/server/node_modules/@babel/parser/lib/index.js +14183 -0
- package/.output/server/node_modules/@babel/parser/package.json +50 -0
- package/.output/server/node_modules/@trpc/server/dist/http.mjs +7 -0
- package/.output/server/node_modules/@trpc/server/dist/index.mjs +11 -0
- package/.output/server/node_modules/@trpc/server/dist/observable/observable.mjs +175 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/createProxy.mjs +73 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/error/TRPCError.mjs +78 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/error/formatter.mjs +5 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/error/getErrorShape.mjs +29 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/http/contentType.mjs +224 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/http/contentTypeParsers.mjs +12 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +76 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/http/isAbortError.mjs +7 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/http/parseConnectionParams.mjs +39 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/http/resolveResponse.mjs +569 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/initTRPC.mjs +80 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/middleware.mjs +90 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/parser.mjs +40 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/procedureBuilder.mjs +194 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/rootConfig.mjs +6 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/router.mjs +176 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/rpc/codes.mjs +54 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/jsonl.mjs +597 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/sse.mjs +359 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/tracked.mjs +25 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/utils/asyncIterable.mjs +167 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/utils/createDeferred.mjs +15 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/utils/disposable.mjs +41 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/utils/mergeAsyncIterables.mjs +239 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/utils/readableStreamFrom.mjs +23 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/utils/timerResource.mjs +23 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/utils/withPing.mjs +127 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/transformer.mjs +101 -0
- package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/utils.mjs +83 -0
- package/.output/server/node_modules/@trpc/server/dist/vendor/unpromise/unpromise.mjs +289 -0
- package/.output/server/node_modules/@trpc/server/package.json +156 -0
- package/.output/server/node_modules/@unhead/dom/dist/index.mjs +197 -0
- package/.output/server/node_modules/@unhead/dom/package.json +40 -0
- package/.output/server/node_modules/@unhead/shared/dist/index.mjs +641 -0
- package/.output/server/node_modules/@unhead/shared/package.json +45 -0
- package/.output/server/node_modules/@unhead/ssr/dist/index.mjs +95 -0
- package/.output/server/node_modules/@unhead/ssr/package.json +40 -0
- package/.output/server/node_modules/@vue/compiler-core/dist/compiler-core.cjs.prod.js +6690 -0
- package/.output/server/node_modules/@vue/compiler-core/package.json +58 -0
- package/.output/server/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +686 -0
- package/.output/server/node_modules/@vue/compiler-dom/package.json +57 -0
- package/.output/server/node_modules/@vue/compiler-ssr/dist/compiler-ssr.cjs.js +1404 -0
- package/.output/server/node_modules/@vue/compiler-ssr/package.json +34 -0
- package/.output/server/node_modules/@vue/reactivity/dist/reactivity.cjs.prod.js +1789 -0
- package/.output/server/node_modules/@vue/reactivity/package.json +55 -0
- package/.output/server/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js +6654 -0
- package/.output/server/node_modules/@vue/runtime-core/package.json +52 -0
- package/.output/server/node_modules/@vue/runtime-dom/dist/runtime-dom.cjs.prod.js +1669 -0
- package/.output/server/node_modules/@vue/runtime-dom/package.json +60 -0
- package/.output/server/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js +857 -0
- package/.output/server/node_modules/@vue/server-renderer/package.json +55 -0
- package/.output/server/node_modules/@vue/shared/dist/shared.cjs.prod.js +594 -0
- package/.output/server/node_modules/@vue/shared/package.json +47 -0
- package/.output/server/node_modules/devalue/index.js +3 -0
- package/.output/server/node_modules/devalue/package.json +34 -0
- package/.output/server/node_modules/devalue/src/base64.js +110 -0
- package/.output/server/node_modules/devalue/src/constants.js +6 -0
- package/.output/server/node_modules/devalue/src/parse.js +160 -0
- package/.output/server/node_modules/devalue/src/stringify.js +232 -0
- package/.output/server/node_modules/devalue/src/uneval.js +351 -0
- package/.output/server/node_modules/devalue/src/utils.js +113 -0
- package/.output/server/node_modules/entities/lib/decode.js +536 -0
- package/.output/server/node_modules/entities/lib/decode_codepoint.js +76 -0
- package/.output/server/node_modules/entities/lib/generated/decode-data-html.js +9 -0
- package/.output/server/node_modules/entities/lib/generated/decode-data-xml.js +9 -0
- package/.output/server/node_modules/entities/package.json +90 -0
- package/.output/server/node_modules/estree-walker/dist/umd/estree-walker.js +344 -0
- package/.output/server/node_modules/estree-walker/package.json +37 -0
- package/.output/server/node_modules/hookable/dist/index.mjs +290 -0
- package/.output/server/node_modules/hookable/package.json +49 -0
- package/.output/server/node_modules/packrup/dist/index.mjs +108 -0
- package/.output/server/node_modules/packrup/package.json +58 -0
- package/.output/server/node_modules/source-map-js/lib/array-set.js +121 -0
- package/.output/server/node_modules/source-map-js/lib/base64-vlq.js +140 -0
- package/.output/server/node_modules/source-map-js/lib/base64.js +67 -0
- package/.output/server/node_modules/source-map-js/lib/binary-search.js +111 -0
- package/.output/server/node_modules/source-map-js/lib/mapping-list.js +79 -0
- package/.output/server/node_modules/source-map-js/lib/quick-sort.js +132 -0
- package/.output/server/node_modules/source-map-js/lib/source-map-consumer.js +1188 -0
- package/.output/server/node_modules/source-map-js/lib/source-map-generator.js +444 -0
- package/.output/server/node_modules/source-map-js/lib/source-node.js +413 -0
- package/.output/server/node_modules/source-map-js/lib/util.js +594 -0
- package/.output/server/node_modules/source-map-js/package.json +71 -0
- package/.output/server/node_modules/source-map-js/source-map.js +8 -0
- package/.output/server/node_modules/ufo/dist/index.mjs +630 -0
- package/.output/server/node_modules/ufo/package.json +47 -0
- package/.output/server/node_modules/unhead/dist/index.mjs +748 -0
- package/.output/server/node_modules/unhead/package.json +46 -0
- package/.output/server/node_modules/vue/dist/vue.cjs.js +80 -0
- package/.output/server/node_modules/vue/dist/vue.cjs.prod.js +66 -0
- package/.output/server/node_modules/vue/index.js +7 -0
- package/.output/server/node_modules/vue/index.mjs +1 -0
- package/.output/server/node_modules/vue/package.json +112 -0
- package/.output/server/node_modules/vue/server-renderer/index.mjs +1 -0
- package/.output/server/node_modules/vue-bundle-renderer/dist/runtime.mjs +196 -0
- package/.output/server/node_modules/vue-bundle-renderer/package.json +50 -0
- package/.output/server/node_modules/zod/lib/index.mjs +4382 -0
- package/.output/server/node_modules/zod/package.json +122 -0
- package/.output/server/package.json +1 -0
- package/package.json +4 -4
package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/sse.mjs
ADDED
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import { Unpromise } from '../../vendor/unpromise/unpromise.mjs';
|
|
2
|
+
import { getTRPCErrorFromUnknown } from '../error/TRPCError.mjs';
|
|
3
|
+
import { isAbortError } from '../http/isAbortError.mjs';
|
|
4
|
+
import { run, identity } from '../utils.mjs';
|
|
5
|
+
import { isTrackedEnvelope } from './tracked.mjs';
|
|
6
|
+
import { takeWithGrace, withMaxDuration } from './utils/asyncIterable.mjs';
|
|
7
|
+
import { makeAsyncResource } from './utils/disposable.mjs';
|
|
8
|
+
import { readableStreamFrom } from './utils/readableStreamFrom.mjs';
|
|
9
|
+
import { timerResource, disposablePromiseTimerResult } from './utils/timerResource.mjs';
|
|
10
|
+
import { withPing, PING_SYM } from './utils/withPing.mjs';
|
|
11
|
+
|
|
12
|
+
function _ts_add_disposable_resource(env, value, async) {
|
|
13
|
+
if (value !== null && value !== void 0) {
|
|
14
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
15
|
+
var dispose, inner;
|
|
16
|
+
if (async) {
|
|
17
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
18
|
+
dispose = value[Symbol.asyncDispose];
|
|
19
|
+
}
|
|
20
|
+
if (dispose === void 0) {
|
|
21
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
22
|
+
dispose = value[Symbol.dispose];
|
|
23
|
+
if (async) inner = dispose;
|
|
24
|
+
}
|
|
25
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
26
|
+
if (inner) dispose = function() {
|
|
27
|
+
try {
|
|
28
|
+
inner.call(this);
|
|
29
|
+
} catch (e) {
|
|
30
|
+
return Promise.reject(e);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
env.stack.push({
|
|
34
|
+
value: value,
|
|
35
|
+
dispose: dispose,
|
|
36
|
+
async: async
|
|
37
|
+
});
|
|
38
|
+
} else if (async) {
|
|
39
|
+
env.stack.push({
|
|
40
|
+
async: true
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
function _ts_dispose_resources(env) {
|
|
46
|
+
var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
47
|
+
var e = new Error(message);
|
|
48
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
49
|
+
};
|
|
50
|
+
return (_ts_dispose_resources = function _ts_dispose_resources(env) {
|
|
51
|
+
function fail(e) {
|
|
52
|
+
env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
53
|
+
env.hasError = true;
|
|
54
|
+
}
|
|
55
|
+
var r, s = 0;
|
|
56
|
+
function next() {
|
|
57
|
+
while(r = env.stack.pop()){
|
|
58
|
+
try {
|
|
59
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
60
|
+
if (r.dispose) {
|
|
61
|
+
var result = r.dispose.call(r.value);
|
|
62
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
|
|
63
|
+
fail(e);
|
|
64
|
+
return next();
|
|
65
|
+
});
|
|
66
|
+
} else s |= 1;
|
|
67
|
+
} catch (e) {
|
|
68
|
+
fail(e);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
72
|
+
if (env.hasError) throw env.error;
|
|
73
|
+
}
|
|
74
|
+
return next();
|
|
75
|
+
})(env);
|
|
76
|
+
}
|
|
77
|
+
const PING_EVENT = 'ping';
|
|
78
|
+
const SERIALIZED_ERROR_EVENT = 'serialized-error';
|
|
79
|
+
const CONNECTED_EVENT = 'connected';
|
|
80
|
+
/**
|
|
81
|
+
*
|
|
82
|
+
* @see https://html.spec.whatwg.org/multipage/server-sent-events.html
|
|
83
|
+
*/ function sseStreamProducer(opts) {
|
|
84
|
+
const { serialize = identity } = opts;
|
|
85
|
+
const ping = {
|
|
86
|
+
enabled: opts.ping?.enabled ?? false,
|
|
87
|
+
intervalMs: opts.ping?.intervalMs ?? 1000
|
|
88
|
+
};
|
|
89
|
+
const client = opts.client ?? {};
|
|
90
|
+
if (ping.enabled && client.reconnectAfterInactivityMs && ping.intervalMs > client.reconnectAfterInactivityMs) {
|
|
91
|
+
throw new Error(`Ping interval must be less than client reconnect interval to prevent unnecessary reconnection - ping.intervalMs: ${ping.intervalMs} client.reconnectAfterInactivityMs: ${client.reconnectAfterInactivityMs}`);
|
|
92
|
+
}
|
|
93
|
+
async function* generator() {
|
|
94
|
+
yield {
|
|
95
|
+
event: CONNECTED_EVENT,
|
|
96
|
+
data: JSON.stringify(client)
|
|
97
|
+
};
|
|
98
|
+
let iterable = opts.data;
|
|
99
|
+
if (opts.emitAndEndImmediately) {
|
|
100
|
+
iterable = takeWithGrace(iterable, {
|
|
101
|
+
count: 1,
|
|
102
|
+
gracePeriodMs: 1
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
if (opts.maxDurationMs && opts.maxDurationMs > 0 && opts.maxDurationMs !== Infinity) {
|
|
106
|
+
iterable = withMaxDuration(iterable, {
|
|
107
|
+
maxDurationMs: opts.maxDurationMs
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
if (ping.enabled && ping.intervalMs !== Infinity && ping.intervalMs > 0) {
|
|
111
|
+
iterable = withPing(iterable, ping.intervalMs);
|
|
112
|
+
}
|
|
113
|
+
// We need those declarations outside the loop for garbage collection reasons. If they were
|
|
114
|
+
// declared inside, they would not be freed until the next value is present.
|
|
115
|
+
let value;
|
|
116
|
+
let chunk;
|
|
117
|
+
for await (value of iterable){
|
|
118
|
+
if (value === PING_SYM) {
|
|
119
|
+
yield {
|
|
120
|
+
event: PING_EVENT,
|
|
121
|
+
data: ''
|
|
122
|
+
};
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
chunk = isTrackedEnvelope(value) ? {
|
|
126
|
+
id: value[0],
|
|
127
|
+
data: value[1]
|
|
128
|
+
} : {
|
|
129
|
+
data: value
|
|
130
|
+
};
|
|
131
|
+
chunk.data = JSON.stringify(serialize(chunk.data));
|
|
132
|
+
yield chunk;
|
|
133
|
+
// free up references for garbage collection
|
|
134
|
+
value = null;
|
|
135
|
+
chunk = null;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async function* generatorWithErrorHandling() {
|
|
139
|
+
try {
|
|
140
|
+
yield* generator();
|
|
141
|
+
} catch (cause) {
|
|
142
|
+
if (isAbortError(cause)) {
|
|
143
|
+
// ignore abort errors, send any other errors
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
// `err` must be caused by `opts.data`, `JSON.stringify` or `serialize`.
|
|
147
|
+
// So, a user error in any case.
|
|
148
|
+
const error = getTRPCErrorFromUnknown(cause);
|
|
149
|
+
const data = opts.formatError?.({
|
|
150
|
+
error
|
|
151
|
+
}) ?? null;
|
|
152
|
+
yield {
|
|
153
|
+
event: SERIALIZED_ERROR_EVENT,
|
|
154
|
+
data: JSON.stringify(serialize(data))
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const stream = readableStreamFrom(generatorWithErrorHandling());
|
|
159
|
+
return stream.pipeThrough(new TransformStream({
|
|
160
|
+
transform (chunk, controller) {
|
|
161
|
+
if ('event' in chunk) {
|
|
162
|
+
controller.enqueue(`event: ${chunk.event}\n`);
|
|
163
|
+
}
|
|
164
|
+
if ('data' in chunk) {
|
|
165
|
+
controller.enqueue(`data: ${chunk.data}\n`);
|
|
166
|
+
}
|
|
167
|
+
if ('id' in chunk) {
|
|
168
|
+
controller.enqueue(`id: ${chunk.id}\n`);
|
|
169
|
+
}
|
|
170
|
+
if ('comment' in chunk) {
|
|
171
|
+
controller.enqueue(`: ${chunk.comment}\n`);
|
|
172
|
+
}
|
|
173
|
+
controller.enqueue('\n\n');
|
|
174
|
+
}
|
|
175
|
+
})).pipeThrough(new TextEncoderStream());
|
|
176
|
+
}
|
|
177
|
+
async function withTimeout(opts) {
|
|
178
|
+
const env = {
|
|
179
|
+
stack: [],
|
|
180
|
+
error: void 0,
|
|
181
|
+
hasError: false
|
|
182
|
+
};
|
|
183
|
+
try {
|
|
184
|
+
const timeoutPromise = _ts_add_disposable_resource(env, timerResource(opts.timeoutMs), false);
|
|
185
|
+
;
|
|
186
|
+
const res = await Unpromise.race([
|
|
187
|
+
opts.promise,
|
|
188
|
+
timeoutPromise.start()
|
|
189
|
+
]);
|
|
190
|
+
if (res === disposablePromiseTimerResult) {
|
|
191
|
+
return await opts.onTimeout();
|
|
192
|
+
}
|
|
193
|
+
return res;
|
|
194
|
+
} catch (e) {
|
|
195
|
+
env.error = e;
|
|
196
|
+
env.hasError = true;
|
|
197
|
+
} finally{
|
|
198
|
+
_ts_dispose_resources(env);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* @see https://html.spec.whatwg.org/multipage/server-sent-events.html
|
|
203
|
+
*/ function sseStreamConsumer(opts) {
|
|
204
|
+
const { deserialize = (v)=>v } = opts;
|
|
205
|
+
let clientOptions = {};
|
|
206
|
+
const signal = opts.signal;
|
|
207
|
+
let _es = null;
|
|
208
|
+
const createStream = ()=>new ReadableStream({
|
|
209
|
+
async start (controller) {
|
|
210
|
+
const [url, init] = await Promise.all([
|
|
211
|
+
opts.url(),
|
|
212
|
+
opts.init()
|
|
213
|
+
]);
|
|
214
|
+
const eventSource = _es = new opts.EventSource(url, init);
|
|
215
|
+
controller.enqueue({
|
|
216
|
+
type: 'connecting',
|
|
217
|
+
eventSource: _es,
|
|
218
|
+
event: null
|
|
219
|
+
});
|
|
220
|
+
eventSource.addEventListener(CONNECTED_EVENT, (_msg)=>{
|
|
221
|
+
const msg = _msg;
|
|
222
|
+
const options = JSON.parse(msg.data);
|
|
223
|
+
clientOptions = options;
|
|
224
|
+
controller.enqueue({
|
|
225
|
+
type: 'connected',
|
|
226
|
+
options,
|
|
227
|
+
eventSource
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
eventSource.addEventListener(SERIALIZED_ERROR_EVENT, (_msg)=>{
|
|
231
|
+
const msg = _msg;
|
|
232
|
+
controller.enqueue({
|
|
233
|
+
type: 'serialized-error',
|
|
234
|
+
error: deserialize(JSON.parse(msg.data)),
|
|
235
|
+
eventSource
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
eventSource.addEventListener(PING_EVENT, ()=>{
|
|
239
|
+
controller.enqueue({
|
|
240
|
+
type: 'ping',
|
|
241
|
+
eventSource
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
eventSource.addEventListener('error', (event)=>{
|
|
245
|
+
if (eventSource.readyState === EventSource.CLOSED) {
|
|
246
|
+
controller.error(event);
|
|
247
|
+
} else {
|
|
248
|
+
controller.enqueue({
|
|
249
|
+
type: 'connecting',
|
|
250
|
+
eventSource,
|
|
251
|
+
event
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
eventSource.addEventListener('message', (_msg)=>{
|
|
256
|
+
const msg = _msg;
|
|
257
|
+
const chunk = deserialize(JSON.parse(msg.data));
|
|
258
|
+
const def = {
|
|
259
|
+
data: chunk
|
|
260
|
+
};
|
|
261
|
+
if (msg.lastEventId) {
|
|
262
|
+
def.id = msg.lastEventId;
|
|
263
|
+
}
|
|
264
|
+
controller.enqueue({
|
|
265
|
+
type: 'data',
|
|
266
|
+
data: def,
|
|
267
|
+
eventSource
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
const onAbort = ()=>{
|
|
271
|
+
try {
|
|
272
|
+
eventSource.close();
|
|
273
|
+
controller.close();
|
|
274
|
+
} catch {
|
|
275
|
+
// ignore errors in case the controller is already closed
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
if (signal.aborted) {
|
|
279
|
+
onAbort();
|
|
280
|
+
} else {
|
|
281
|
+
signal.addEventListener('abort', onAbort);
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
cancel () {
|
|
285
|
+
_es?.close();
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
const getStreamResource = ()=>{
|
|
289
|
+
let stream = createStream();
|
|
290
|
+
let reader = stream.getReader();
|
|
291
|
+
async function dispose() {
|
|
292
|
+
await reader.cancel();
|
|
293
|
+
_es = null;
|
|
294
|
+
}
|
|
295
|
+
return makeAsyncResource({
|
|
296
|
+
read () {
|
|
297
|
+
return reader.read();
|
|
298
|
+
},
|
|
299
|
+
async recreate () {
|
|
300
|
+
await dispose();
|
|
301
|
+
stream = createStream();
|
|
302
|
+
reader = stream.getReader();
|
|
303
|
+
}
|
|
304
|
+
}, dispose);
|
|
305
|
+
};
|
|
306
|
+
return run(async function*() {
|
|
307
|
+
const env = {
|
|
308
|
+
stack: [],
|
|
309
|
+
error: void 0,
|
|
310
|
+
hasError: false
|
|
311
|
+
};
|
|
312
|
+
try {
|
|
313
|
+
const stream = _ts_add_disposable_resource(env, getStreamResource(), true);
|
|
314
|
+
;
|
|
315
|
+
while(true){
|
|
316
|
+
let promise = stream.read();
|
|
317
|
+
const timeoutMs = clientOptions.reconnectAfterInactivityMs;
|
|
318
|
+
if (timeoutMs) {
|
|
319
|
+
promise = withTimeout({
|
|
320
|
+
promise,
|
|
321
|
+
timeoutMs,
|
|
322
|
+
onTimeout: async ()=>{
|
|
323
|
+
const res = {
|
|
324
|
+
value: {
|
|
325
|
+
type: 'timeout',
|
|
326
|
+
ms: timeoutMs,
|
|
327
|
+
eventSource: _es
|
|
328
|
+
},
|
|
329
|
+
done: false
|
|
330
|
+
};
|
|
331
|
+
// Close and release old reader
|
|
332
|
+
await stream.recreate();
|
|
333
|
+
return res;
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
const result = await promise;
|
|
338
|
+
if (result.done) {
|
|
339
|
+
return result.value;
|
|
340
|
+
}
|
|
341
|
+
yield result.value;
|
|
342
|
+
}
|
|
343
|
+
} catch (e) {
|
|
344
|
+
env.error = e;
|
|
345
|
+
env.hasError = true;
|
|
346
|
+
} finally{
|
|
347
|
+
const result = _ts_dispose_resources(env);
|
|
348
|
+
if (result) await result;
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
const sseHeaders = {
|
|
353
|
+
'Content-Type': 'text/event-stream',
|
|
354
|
+
'Cache-Control': 'no-cache, no-transform',
|
|
355
|
+
'X-Accel-Buffering': 'no',
|
|
356
|
+
Connection: 'keep-alive'
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
export { sseHeaders, sseStreamConsumer, sseStreamProducer };
|
package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/tracked.mjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const trackedSymbol = Symbol();
|
|
2
|
+
/**
|
|
3
|
+
* Produce a typed server-sent event message
|
|
4
|
+
* @deprecated use `tracked(id, data)` instead
|
|
5
|
+
*/ function sse(event) {
|
|
6
|
+
return tracked(event.id, event.data);
|
|
7
|
+
}
|
|
8
|
+
function isTrackedEnvelope(value) {
|
|
9
|
+
return Array.isArray(value) && value[2] === trackedSymbol;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Automatically track an event so that it can be resumed from a given id if the connection is lost
|
|
13
|
+
*/ function tracked(id, data) {
|
|
14
|
+
if (id === '') {
|
|
15
|
+
// This limitation could be removed by using different SSE event names / channels for tracked event and non-tracked event
|
|
16
|
+
throw new Error('`id` must not be an empty string as empty string is the same as not setting the id at all');
|
|
17
|
+
}
|
|
18
|
+
return [
|
|
19
|
+
id,
|
|
20
|
+
data,
|
|
21
|
+
trackedSymbol
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { isTrackedEnvelope, sse, tracked };
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { Unpromise } from '../../../vendor/unpromise/unpromise.mjs';
|
|
2
|
+
import { makeAsyncResource } from './disposable.mjs';
|
|
3
|
+
import { timerResource, disposablePromiseTimerResult } from './timerResource.mjs';
|
|
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
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Derives a new {@link AsyncGenerator} based on {@link iterable}, that automatically stops after the specified duration.
|
|
78
|
+
*/ async function* withMaxDuration(iterable, opts) {
|
|
79
|
+
const env = {
|
|
80
|
+
stack: [],
|
|
81
|
+
error: void 0,
|
|
82
|
+
hasError: false
|
|
83
|
+
};
|
|
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
|
+
;
|
|
89
|
+
const timerPromise = timer.start();
|
|
90
|
+
// declaration outside the loop for garbage collection reasons
|
|
91
|
+
let result;
|
|
92
|
+
while(true){
|
|
93
|
+
result = await Unpromise.race([
|
|
94
|
+
iterator.next(),
|
|
95
|
+
timerPromise
|
|
96
|
+
]);
|
|
97
|
+
if (result === disposablePromiseTimerResult) {
|
|
98
|
+
// cancelled due to timeout
|
|
99
|
+
const res = await iterator.return?.();
|
|
100
|
+
return res?.value;
|
|
101
|
+
}
|
|
102
|
+
if (result.done) {
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
yield result.value;
|
|
106
|
+
// free up reference for garbage collection
|
|
107
|
+
result = null;
|
|
108
|
+
}
|
|
109
|
+
} catch (e) {
|
|
110
|
+
env.error = e;
|
|
111
|
+
env.hasError = true;
|
|
112
|
+
} finally{
|
|
113
|
+
const result = _ts_dispose_resources(env);
|
|
114
|
+
if (result) await result;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Derives a new {@link AsyncGenerator} based of {@link iterable}, that yields its first
|
|
119
|
+
* {@link count} values. Then, a grace period of {@link gracePeriodMs} is started in which further
|
|
120
|
+
* values may still come through. After this period, the generator stops.
|
|
121
|
+
*/ async function* takeWithGrace(iterable, opts) {
|
|
122
|
+
const env = {
|
|
123
|
+
stack: [],
|
|
124
|
+
error: void 0,
|
|
125
|
+
hasError: false
|
|
126
|
+
};
|
|
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
|
+
;
|
|
134
|
+
let count = opts.count;
|
|
135
|
+
let timerPromise = new Promise(()=>{
|
|
136
|
+
// never resolves
|
|
137
|
+
});
|
|
138
|
+
while(true){
|
|
139
|
+
result = await Unpromise.race([
|
|
140
|
+
iterator.next(),
|
|
141
|
+
timerPromise
|
|
142
|
+
]);
|
|
143
|
+
if (result === disposablePromiseTimerResult) {
|
|
144
|
+
// cancelled
|
|
145
|
+
const res = await iterator.return?.();
|
|
146
|
+
return res?.value;
|
|
147
|
+
}
|
|
148
|
+
if (result.done) {
|
|
149
|
+
return result.value;
|
|
150
|
+
}
|
|
151
|
+
yield result.value;
|
|
152
|
+
if (--count === 0) {
|
|
153
|
+
timerPromise = timer.start();
|
|
154
|
+
}
|
|
155
|
+
// free up reference for garbage collection
|
|
156
|
+
result = null;
|
|
157
|
+
}
|
|
158
|
+
} catch (e) {
|
|
159
|
+
env.error = e;
|
|
160
|
+
env.hasError = true;
|
|
161
|
+
} finally{
|
|
162
|
+
const result = _ts_dispose_resources(env);
|
|
163
|
+
if (result) await result;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export { iteratorResource, takeWithGrace, withMaxDuration };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */ function createDeferred() {
|
|
2
|
+
let resolve;
|
|
3
|
+
let reject;
|
|
4
|
+
const promise = new Promise((res, rej)=>{
|
|
5
|
+
resolve = res;
|
|
6
|
+
reject = rej;
|
|
7
|
+
});
|
|
8
|
+
return {
|
|
9
|
+
promise,
|
|
10
|
+
resolve: resolve,
|
|
11
|
+
reject: reject
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { createDeferred };
|
|
@@ -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 };
|