@moeru/eventa 1.0.0-beta.2 → 1.0.0-beta.4
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/README.md +53 -1
- package/dist/adapters/broadcast-channel/index.d.mts +4 -2
- package/dist/adapters/broadcast-channel/index.mjs +6 -9
- package/dist/adapters/broadcast-channel/index.mjs.map +1 -1
- package/dist/adapters/electron/main.d.mts +2 -2
- package/dist/adapters/electron/main.mjs +7 -9
- package/dist/adapters/electron/main.mjs.map +1 -1
- package/dist/adapters/electron/renderer.d.mts +134 -3
- package/dist/adapters/electron/renderer.mjs +4 -6
- package/dist/adapters/electron/renderer.mjs.map +1 -1
- package/dist/adapters/event-emitter/index.d.mts +4 -2
- package/dist/adapters/event-emitter/index.mjs +4 -7
- package/dist/adapters/event-emitter/index.mjs.map +1 -1
- package/dist/adapters/event-target/index.d.mts +4 -2
- package/dist/adapters/event-target/index.mjs +5 -8
- package/dist/adapters/event-target/index.mjs.map +1 -1
- package/dist/adapters/websocket/h3/index.d.mts +448 -9
- package/dist/adapters/websocket/h3/index.mjs +7 -9
- package/dist/adapters/websocket/h3/index.mjs.map +1 -1
- package/dist/adapters/websocket/index.d.mts +1 -1
- package/dist/adapters/websocket/index.mjs +1 -1
- package/dist/adapters/websocket/native/index.d.mts +5 -5
- package/dist/adapters/websocket/native/index.mjs +4 -5
- package/dist/adapters/websocket/native/index.mjs.map +1 -1
- package/dist/adapters/webworkers/index.d.mts +2 -2
- package/dist/adapters/webworkers/index.mjs +5 -6
- package/dist/adapters/webworkers/index.mjs.map +1 -1
- package/dist/adapters/webworkers/worker/index.d.mts +1 -1
- package/dist/adapters/webworkers/worker/index.mjs +6 -7
- package/dist/adapters/webworkers/worker/index.mjs.map +1 -1
- package/dist/adapters/window-message/index.d.mts +50 -0
- package/dist/adapters/window-message/index.mjs +79 -0
- package/dist/adapters/window-message/index.mjs.map +1 -0
- package/dist/adapters/worker-threads/index.d.mts +2 -2
- package/dist/adapters/worker-threads/index.mjs +5 -6
- package/dist/adapters/worker-threads/index.mjs.map +1 -1
- package/dist/adapters/worker-threads/worker/index.d.mts +1 -1
- package/dist/adapters/worker-threads/worker/index.mjs +6 -7
- package/dist/adapters/worker-threads/worker/index.mjs.map +1 -1
- package/dist/{context-ZVv99bcM.d.mts → context-BsqFeoer.d.mts} +2 -2
- package/dist/{context-BMDJMapI.mjs → context-Dht_IZMb.mjs} +30 -27
- package/dist/context-Dht_IZMb.mjs.map +1 -0
- package/dist/eventa-DSnoBa1O.d.mts +106 -0
- package/dist/{index-CI_gUGXg.d.mts → index-g6DulgOI.d.mts} +111 -99
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +3 -4
- package/dist/{internal-ChLglF1N.mjs → internal-CHUsXYiP.mjs} +3 -4
- package/dist/{internal-ChLglF1N.mjs.map → internal-CHUsXYiP.mjs.map} +1 -1
- package/dist/{shared-CRxfs1TC.mjs → shared-CA5MGwv0.mjs} +5 -7
- package/dist/shared-CA5MGwv0.mjs.map +1 -0
- package/dist/{shared-DgX1R_nY.d.mts → shared-CVTLm458.d.mts} +4 -4
- package/dist/{shared-Cd4CLAdD.d.mts → shared-CfXZb-7K.d.mts} +4 -2
- package/dist/{shared-CA_i_yfR.mjs → shared-Dl0_bFq0.mjs} +4 -5
- package/dist/{shared-CA_i_yfR.mjs.map → shared-Dl0_bFq0.mjs.map} +1 -1
- package/dist/{src-eMqISeHo.mjs → src-CTs6h4Ci.mjs} +177 -161
- package/dist/src-CTs6h4Ci.mjs.map +1 -0
- package/package.json +14 -7
- package/dist/context-BMDJMapI.mjs.map +0 -1
- package/dist/eventa-AJyw28P8.d.mts +0 -52
- package/dist/shared-CRxfs1TC.mjs.map +0 -1
- package/dist/src-eMqISeHo.mjs.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as defineEventa, l as nanoid } from "./context-
|
|
2
|
-
|
|
1
|
+
import { a as defineEventa, l as nanoid } from "./context-Dht_IZMb.mjs";
|
|
2
|
+
import "./src-CTs6h4Ci.mjs";
|
|
3
3
|
//#region src/adapters/electron/internal.ts
|
|
4
4
|
function generatePayload(type, payload) {
|
|
5
5
|
return {
|
|
@@ -11,11 +11,10 @@ function generatePayload(type, payload) {
|
|
|
11
11
|
function parsePayload(data) {
|
|
12
12
|
return data;
|
|
13
13
|
}
|
|
14
|
-
|
|
15
14
|
//#endregion
|
|
16
15
|
//#region src/adapters/electron/shared.ts
|
|
17
16
|
const errorEvent = { ...defineEventa() };
|
|
18
|
-
|
|
19
17
|
//#endregion
|
|
20
18
|
export { generatePayload as n, parsePayload as r, errorEvent as t };
|
|
21
|
-
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=shared-Dl0_bFq0.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-
|
|
1
|
+
{"version":3,"file":"shared-Dl0_bFq0.mjs","names":[],"sources":["../src/adapters/electron/internal.ts","../src/adapters/electron/shared.ts"],"sourcesContent":["import type { EventTag } from '../..'\nimport type { Payload as CustomEventDetailDetail } from './shared'\n\nimport { nanoid } from '../..'\n\nexport function generatePayload<T>(type: EventTag<any, any>, payload: T): CustomEventDetailDetail<T> {\n return {\n id: nanoid(),\n type,\n payload,\n }\n}\n\nexport function parsePayload<T>(data: unknown): CustomEventDetailDetail<T> {\n return data as CustomEventDetailDetail<T>\n}\n","import type { EventTag } from '../../eventa'\n\nimport { defineEventa } from '../../eventa'\n\nexport interface Payload<T> {\n id: string\n type: EventTag<any, any>\n payload: T\n}\n\nexport const errorEvent = { ...defineEventa<{ error: unknown }>() }\n"],"mappings":";;;AAKA,SAAgB,gBAAmB,MAA0B,SAAwC;AACnG,QAAO;EACL,IAAI,QAAQ;EACZ;EACA;EACD;;AAGH,SAAgB,aAAgB,MAA2C;AACzE,QAAO;;;;ACJT,MAAa,aAAa,EAAE,GAAG,cAAkC,EAAE"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { a as defineEventa, l as nanoid } from "./context-
|
|
2
|
-
|
|
1
|
+
import { a as defineEventa, l as nanoid } from "./context-Dht_IZMb.mjs";
|
|
3
2
|
//#region src/context-extension-invoke-internal.ts
|
|
4
3
|
/**
|
|
5
4
|
* Read the internal invoke configuration from context extensions, if present.
|
|
@@ -30,49 +29,69 @@ function registerInvokeAbortEventListeners(ctx, eventOrMatch) {
|
|
|
30
29
|
ctx.extensions = extensions;
|
|
31
30
|
return invokeInternal;
|
|
32
31
|
}
|
|
33
|
-
|
|
34
32
|
//#endregion
|
|
35
33
|
//#region src/invoke-shared.ts
|
|
36
|
-
let InvokeEventType = /* @__PURE__ */ function(InvokeEventType
|
|
37
|
-
InvokeEventType
|
|
38
|
-
InvokeEventType
|
|
39
|
-
InvokeEventType
|
|
40
|
-
InvokeEventType
|
|
41
|
-
InvokeEventType
|
|
42
|
-
InvokeEventType
|
|
43
|
-
InvokeEventType
|
|
44
|
-
return InvokeEventType
|
|
34
|
+
let InvokeEventType = /* @__PURE__ */ function(InvokeEventType) {
|
|
35
|
+
InvokeEventType[InvokeEventType["SendEvent"] = 0] = "SendEvent";
|
|
36
|
+
InvokeEventType[InvokeEventType["SendEventError"] = 1] = "SendEventError";
|
|
37
|
+
InvokeEventType[InvokeEventType["SendEventStreamEnd"] = 2] = "SendEventStreamEnd";
|
|
38
|
+
InvokeEventType[InvokeEventType["SendEventAbort"] = 3] = "SendEventAbort";
|
|
39
|
+
InvokeEventType[InvokeEventType["ReceiveEvent"] = 4] = "ReceiveEvent";
|
|
40
|
+
InvokeEventType[InvokeEventType["ReceiveEventError"] = 5] = "ReceiveEventError";
|
|
41
|
+
InvokeEventType[InvokeEventType["ReceiveEventStreamEnd"] = 6] = "ReceiveEventStreamEnd";
|
|
42
|
+
return InvokeEventType;
|
|
45
43
|
}({});
|
|
46
|
-
function defineInvokeEventa(tag) {
|
|
44
|
+
function defineInvokeEventa(tag, options) {
|
|
47
45
|
if (!tag) tag = nanoid();
|
|
48
46
|
return {
|
|
49
47
|
sendEvent: {
|
|
50
|
-
...defineEventa(`${tag}-send
|
|
51
|
-
|
|
48
|
+
...defineEventa(`${tag}-send`, {
|
|
49
|
+
metadata: options?.metadata,
|
|
50
|
+
invokeMetadata: options?.invokeMetadata
|
|
51
|
+
}),
|
|
52
|
+
invokeType: 0
|
|
52
53
|
},
|
|
53
54
|
sendEventError: {
|
|
54
|
-
...defineEventa(`${tag}-send-error
|
|
55
|
-
|
|
55
|
+
...defineEventa(`${tag}-send-error`, {
|
|
56
|
+
metadata: options?.metadata,
|
|
57
|
+
invokeMetadata: options?.invokeMetadata
|
|
58
|
+
}),
|
|
59
|
+
invokeType: 1
|
|
56
60
|
},
|
|
57
61
|
sendEventStreamEnd: {
|
|
58
|
-
...defineEventa(`${tag}-send-stream-end
|
|
59
|
-
|
|
62
|
+
...defineEventa(`${tag}-send-stream-end`, {
|
|
63
|
+
metadata: options?.metadata,
|
|
64
|
+
invokeMetadata: options?.invokeMetadata
|
|
65
|
+
}),
|
|
66
|
+
invokeType: 2
|
|
60
67
|
},
|
|
61
68
|
sendEventAbort: {
|
|
62
|
-
...defineEventa(`${tag}-send-abort
|
|
63
|
-
|
|
69
|
+
...defineEventa(`${tag}-send-abort`, {
|
|
70
|
+
metadata: options?.metadata,
|
|
71
|
+
invokeMetadata: options?.invokeMetadata
|
|
72
|
+
}),
|
|
73
|
+
invokeType: 3
|
|
64
74
|
},
|
|
65
75
|
receiveEvent: {
|
|
66
|
-
...defineEventa(`${tag}-receive
|
|
67
|
-
|
|
76
|
+
...defineEventa(`${tag}-receive`, {
|
|
77
|
+
metadata: options?.metadata,
|
|
78
|
+
invokeMetadata: options?.invokeMetadata
|
|
79
|
+
}),
|
|
80
|
+
invokeType: 4
|
|
68
81
|
},
|
|
69
82
|
receiveEventError: {
|
|
70
|
-
...defineEventa(`${tag}-receive-error
|
|
71
|
-
|
|
83
|
+
...defineEventa(`${tag}-receive-error`, {
|
|
84
|
+
metadata: options?.metadata,
|
|
85
|
+
invokeMetadata: options?.invokeMetadata
|
|
86
|
+
}),
|
|
87
|
+
invokeType: 5
|
|
72
88
|
},
|
|
73
89
|
receiveEventStreamEnd: {
|
|
74
|
-
...defineEventa(`${tag}-receive-stream-end
|
|
75
|
-
|
|
90
|
+
...defineEventa(`${tag}-receive-stream-end`, {
|
|
91
|
+
metadata: options?.metadata,
|
|
92
|
+
invokeMetadata: options?.invokeMetadata
|
|
93
|
+
}),
|
|
94
|
+
invokeType: 6
|
|
76
95
|
}
|
|
77
96
|
};
|
|
78
97
|
}
|
|
@@ -83,13 +102,12 @@ function isInvokeEventa(event) {
|
|
|
83
102
|
}
|
|
84
103
|
function isSendEvent(event) {
|
|
85
104
|
if (!isInvokeEventa(event)) return false;
|
|
86
|
-
return event.invokeType ===
|
|
105
|
+
return event.invokeType === 0 || event.invokeType === 1 || event.invokeType === 2 || event.invokeType === 3;
|
|
87
106
|
}
|
|
88
107
|
function isReceiveEvent(event) {
|
|
89
108
|
if (!isInvokeEventa(event)) return false;
|
|
90
|
-
return event.invokeType ===
|
|
109
|
+
return event.invokeType === 4 || event.invokeType === 5 || event.invokeType === 6;
|
|
91
110
|
}
|
|
92
|
-
|
|
93
111
|
//#endregion
|
|
94
112
|
//#region src/utils.ts
|
|
95
113
|
function randomBetween(min, max) {
|
|
@@ -170,7 +188,6 @@ function createUntil(options) {
|
|
|
170
188
|
handler: resolve
|
|
171
189
|
};
|
|
172
190
|
}
|
|
173
|
-
|
|
174
191
|
//#endregion
|
|
175
192
|
//#region src/invoke.ts
|
|
176
193
|
function isExtendableInvokeResponseLike(value) {
|
|
@@ -228,125 +245,127 @@ function isExtendableInvokeResponseLike(value) {
|
|
|
228
245
|
* @param event Invoke event definition created by `defineInvokeEventa`.
|
|
229
246
|
*/
|
|
230
247
|
function defineInvoke(ctx, event) {
|
|
231
|
-
|
|
232
|
-
if (typeof ctx === "function")
|
|
233
|
-
const resolvedCtx = ctx();
|
|
234
|
-
if (resolvedCtx instanceof Promise) return await resolvedCtx;
|
|
235
|
-
return resolvedCtx;
|
|
236
|
-
}
|
|
248
|
+
function getContext() {
|
|
249
|
+
if (typeof ctx === "function") return ctx();
|
|
237
250
|
return ctx;
|
|
238
251
|
}
|
|
239
|
-
function
|
|
252
|
+
function createInvokePromise(resolvedCtx, req, options) {
|
|
240
253
|
return new Promise((resolve, reject) => {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
254
|
+
const ctx = resolvedCtx;
|
|
255
|
+
const invokeId = nanoid();
|
|
256
|
+
const invokeReceiveEvent = defineEventa(`${event.receiveEvent.id}-${invokeId}`);
|
|
257
|
+
delete invokeReceiveEvent.metadata;
|
|
258
|
+
const invokeReceiveEventError = defineEventa(`${event.receiveEventError.id}-${invokeId}`);
|
|
259
|
+
delete invokeReceiveEventError.metadata;
|
|
260
|
+
const { signal, ...emitOptions } = options ?? {};
|
|
261
|
+
let finished = false;
|
|
262
|
+
const onAbort = () => {
|
|
263
|
+
ctx.emit(event.sendEventAbort, {
|
|
264
|
+
invokeId,
|
|
265
|
+
content: signal?.reason
|
|
266
|
+
}, emitOptions);
|
|
267
|
+
finishReject(createAbortError(signal?.reason));
|
|
268
|
+
};
|
|
269
|
+
const invokeInternalConfig = getContextExtensionInvokeInternalConfig(ctx);
|
|
270
|
+
const abortOffs = [];
|
|
271
|
+
const onAbortEvent = (payload, eventOptions) => {
|
|
272
|
+
const mappedError = invokeInternalConfig?.mapAbortError?.(payload, eventOptions);
|
|
273
|
+
if (typeof mappedError !== "undefined") {
|
|
274
|
+
finishReject(mappedError);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
const body = payload?.body;
|
|
278
|
+
finishReject(body && typeof body === "object" && "error" in body ? body.error : typeof body !== "undefined" ? body : payload);
|
|
279
|
+
};
|
|
280
|
+
const cleanup = () => {
|
|
281
|
+
ctx.off(invokeReceiveEvent);
|
|
282
|
+
ctx.off(invokeReceiveEventError);
|
|
283
|
+
for (const off of abortOffs) off();
|
|
284
|
+
if (signal) signal.removeEventListener("abort", onAbort);
|
|
285
|
+
};
|
|
286
|
+
const finishReject = (error) => {
|
|
287
|
+
if (finished) return;
|
|
288
|
+
finished = true;
|
|
289
|
+
reject(error);
|
|
290
|
+
cleanup();
|
|
291
|
+
};
|
|
292
|
+
const finishResolve = (value) => {
|
|
293
|
+
if (finished) return;
|
|
294
|
+
finished = true;
|
|
295
|
+
resolve(value);
|
|
296
|
+
cleanup();
|
|
297
|
+
};
|
|
298
|
+
ctx.on(invokeReceiveEvent, (payload) => {
|
|
299
|
+
if (!payload.body) return;
|
|
300
|
+
if (payload.body.invokeId !== invokeId) return;
|
|
301
|
+
const { content } = payload.body;
|
|
302
|
+
finishResolve(content);
|
|
303
|
+
});
|
|
304
|
+
ctx.on(invokeReceiveEventError, (payload) => {
|
|
305
|
+
if (!payload.body) return;
|
|
306
|
+
if (payload.body.invokeId !== invokeId) return;
|
|
307
|
+
const { error } = payload.body.content;
|
|
308
|
+
finishReject(error);
|
|
309
|
+
});
|
|
310
|
+
if (invokeInternalConfig?.abortOnEvents?.length) for (const eventOrMatch of invokeInternalConfig.abortOnEvents) abortOffs.push(ctx.on(eventOrMatch, onAbortEvent));
|
|
311
|
+
if (signal) {
|
|
312
|
+
if (signal.aborted) {
|
|
313
|
+
onAbort();
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
317
|
+
}
|
|
318
|
+
if (!isReadableStream(req) && !isAsyncIterable(req)) ctx.emit(event.sendEvent, {
|
|
319
|
+
invokeId,
|
|
320
|
+
content: req
|
|
321
|
+
}, emitOptions);
|
|
322
|
+
else {
|
|
323
|
+
const sendChunk = (chunk) => {
|
|
324
|
+
if (finished) return;
|
|
325
|
+
ctx.emit(event.sendEvent, {
|
|
249
326
|
invokeId,
|
|
250
|
-
content:
|
|
327
|
+
content: chunk,
|
|
328
|
+
isReqStream: true
|
|
251
329
|
}, emitOptions);
|
|
252
|
-
finishReject(createAbortError(signal?.reason));
|
|
253
|
-
};
|
|
254
|
-
const invokeInternalConfig = getContextExtensionInvokeInternalConfig(ctx$1);
|
|
255
|
-
const abortOffs = [];
|
|
256
|
-
const onAbortEvent = (payload, eventOptions) => {
|
|
257
|
-
const mappedError = invokeInternalConfig?.mapAbortError?.(payload, eventOptions);
|
|
258
|
-
if (typeof mappedError !== "undefined") {
|
|
259
|
-
finishReject(mappedError);
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
const body = payload?.body;
|
|
263
|
-
finishReject(body && typeof body === "object" && "error" in body ? body.error : typeof body !== "undefined" ? body : payload);
|
|
264
|
-
};
|
|
265
|
-
const cleanup = () => {
|
|
266
|
-
ctx$1.off(invokeReceiveEvent);
|
|
267
|
-
ctx$1.off(invokeReceiveEventError);
|
|
268
|
-
for (const off of abortOffs) off();
|
|
269
|
-
if (signal) signal.removeEventListener("abort", onAbort);
|
|
270
|
-
};
|
|
271
|
-
const finishReject = (error) => {
|
|
272
|
-
if (finished) return;
|
|
273
|
-
finished = true;
|
|
274
|
-
reject(error);
|
|
275
|
-
cleanup();
|
|
276
330
|
};
|
|
277
|
-
const
|
|
331
|
+
const sendEnd = () => {
|
|
278
332
|
if (finished) return;
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
333
|
+
ctx.emit(event.sendEventStreamEnd, {
|
|
334
|
+
invokeId,
|
|
335
|
+
content: void 0
|
|
336
|
+
}, emitOptions);
|
|
282
337
|
};
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
const { content } = payload.body;
|
|
287
|
-
finishResolve(content);
|
|
288
|
-
});
|
|
289
|
-
ctx$1.on(invokeReceiveEventError, (payload) => {
|
|
290
|
-
if (!payload.body) return;
|
|
291
|
-
if (payload.body.invokeId !== invokeId) return;
|
|
292
|
-
const { error } = payload.body.content;
|
|
293
|
-
finishReject(error);
|
|
294
|
-
});
|
|
295
|
-
if (invokeInternalConfig?.abortOnEvents?.length) for (const eventOrMatch of invokeInternalConfig.abortOnEvents) abortOffs.push(ctx$1.on(eventOrMatch, onAbortEvent));
|
|
296
|
-
if (signal) {
|
|
297
|
-
if (signal.aborted) {
|
|
298
|
-
onAbort();
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
302
|
-
}
|
|
303
|
-
if (!isReadableStream(req) && !isAsyncIterable(req)) ctx$1.emit(event.sendEvent, {
|
|
304
|
-
invokeId,
|
|
305
|
-
content: req
|
|
306
|
-
}, emitOptions);
|
|
307
|
-
else {
|
|
308
|
-
const sendChunk = (chunk) => {
|
|
309
|
-
if (finished) return;
|
|
310
|
-
ctx$1.emit(event.sendEvent, {
|
|
311
|
-
invokeId,
|
|
312
|
-
content: chunk,
|
|
313
|
-
isReqStream: true
|
|
314
|
-
}, emitOptions);
|
|
315
|
-
};
|
|
316
|
-
const sendEnd = () => {
|
|
317
|
-
if (finished) return;
|
|
318
|
-
ctx$1.emit(event.sendEventStreamEnd, {
|
|
319
|
-
invokeId,
|
|
320
|
-
content: void 0
|
|
321
|
-
}, emitOptions);
|
|
322
|
-
};
|
|
323
|
-
const pump = async () => {
|
|
324
|
-
try {
|
|
325
|
-
for await (const chunk of req) {
|
|
326
|
-
if (signal?.aborted) return;
|
|
327
|
-
sendChunk(chunk);
|
|
328
|
-
}
|
|
329
|
-
sendEnd();
|
|
330
|
-
} catch (error) {
|
|
338
|
+
const pump = async () => {
|
|
339
|
+
try {
|
|
340
|
+
for await (const chunk of req) {
|
|
331
341
|
if (signal?.aborted) return;
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
ctx$1.emit(event.sendEventError, {
|
|
342
|
+
sendChunk(chunk);
|
|
343
|
+
}
|
|
344
|
+
sendEnd();
|
|
345
|
+
} catch (error) {
|
|
346
|
+
if (signal?.aborted) return;
|
|
347
|
+
if (isAbortError(error)) {
|
|
348
|
+
ctx.emit(event.sendEventAbort, {
|
|
340
349
|
invokeId,
|
|
341
350
|
content: error
|
|
342
351
|
}, emitOptions);
|
|
352
|
+
return;
|
|
343
353
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
354
|
+
ctx.emit(event.sendEventError, {
|
|
355
|
+
invokeId,
|
|
356
|
+
content: error
|
|
357
|
+
}, emitOptions);
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
pump();
|
|
361
|
+
}
|
|
348
362
|
});
|
|
349
363
|
}
|
|
364
|
+
function _invoke(req, options) {
|
|
365
|
+
const resolvedCtx = getContext();
|
|
366
|
+
if (resolvedCtx instanceof Promise) return resolvedCtx.then((ctx) => createInvokePromise(ctx, req, options));
|
|
367
|
+
return createInvokePromise(resolvedCtx, req, options);
|
|
368
|
+
}
|
|
350
369
|
return _invoke;
|
|
351
370
|
}
|
|
352
371
|
/**
|
|
@@ -485,17 +504,17 @@ function defineInvokeHandler(ctx, event, handler) {
|
|
|
485
504
|
const abortController = abortControllers.get(invokeId);
|
|
486
505
|
if (!abortController) {
|
|
487
506
|
abortReasons.set(invokeId, reason);
|
|
488
|
-
let streamController
|
|
489
|
-
if (!streamController
|
|
507
|
+
let streamController = streamStates.get(invokeId);
|
|
508
|
+
if (!streamController) {
|
|
490
509
|
let localController;
|
|
491
510
|
const reqStream = new ReadableStream({ start(c) {
|
|
492
511
|
localController = c;
|
|
493
512
|
} });
|
|
494
|
-
streamController
|
|
495
|
-
streamStates.set(invokeId, streamController
|
|
513
|
+
streamController = localController;
|
|
514
|
+
streamStates.set(invokeId, streamController);
|
|
496
515
|
handleInvoke(invokeId, reqStream, options);
|
|
497
516
|
}
|
|
498
|
-
streamController
|
|
517
|
+
streamController.error(createAbortError(reason));
|
|
499
518
|
streamStates.delete(invokeId);
|
|
500
519
|
return;
|
|
501
520
|
}
|
|
@@ -591,7 +610,6 @@ function undefineInvokeHandler(ctx, event, handler) {
|
|
|
591
610
|
ctx.invokeHandlers.delete(event.sendEvent.id);
|
|
592
611
|
return returnValue;
|
|
593
612
|
}
|
|
594
|
-
|
|
595
613
|
//#endregion
|
|
596
614
|
//#region src/invoke-extension-transfer.ts
|
|
597
615
|
function withTransfer(body, transfer) {
|
|
@@ -600,7 +618,6 @@ function withTransfer(body, transfer) {
|
|
|
600
618
|
invokeResponse: { transfer: transfer ?? [] }
|
|
601
619
|
};
|
|
602
620
|
}
|
|
603
|
-
|
|
604
621
|
//#endregion
|
|
605
622
|
//#region src/invoke-remote-methods.ts
|
|
606
623
|
const DEFAULT_FUNCTION_STUB_OPTIONS = {
|
|
@@ -682,10 +699,10 @@ function serializeInvokeFunctionPayload(value, ctx, options) {
|
|
|
682
699
|
if (depth > options.maxDepth) throw new Error(`Invoke payload is too deep (max ${options.maxDepth}).`);
|
|
683
700
|
if (seen.has(input)) return seen.get(input);
|
|
684
701
|
if (Array.isArray(input)) {
|
|
685
|
-
const output
|
|
686
|
-
seen.set(input, output
|
|
687
|
-
for (let i = 0; i < input.length; i += 1) output
|
|
688
|
-
return output
|
|
702
|
+
const output = Array.from({ length: input.length });
|
|
703
|
+
seen.set(input, output);
|
|
704
|
+
for (let i = 0; i < input.length; i += 1) output[i] = walk(input[i], depth + 1);
|
|
705
|
+
return output;
|
|
689
706
|
}
|
|
690
707
|
if (!isPlainObject(input)) return input;
|
|
691
708
|
const output = Object.create(null);
|
|
@@ -719,10 +736,10 @@ function deserializeInvokeFunctionPayload(value, ctx, options) {
|
|
|
719
736
|
} else if (options.strict && hasInvokeFunctionStubKey(input)) throw new Error("Invalid invoke function stub payload.");
|
|
720
737
|
if (seen.has(input)) return seen.get(input);
|
|
721
738
|
if (Array.isArray(input)) {
|
|
722
|
-
const output
|
|
723
|
-
seen.set(input, output
|
|
724
|
-
for (let i = 0; i < input.length; i += 1) output
|
|
725
|
-
return output
|
|
739
|
+
const output = Array.from({ length: input.length });
|
|
740
|
+
seen.set(input, output);
|
|
741
|
+
for (let i = 0; i < input.length; i += 1) output[i] = walk(input[i], depth + 1);
|
|
742
|
+
return output;
|
|
726
743
|
}
|
|
727
744
|
if (!isPlainObject(input)) return input;
|
|
728
745
|
const output = Object.create(null);
|
|
@@ -788,9 +805,9 @@ function withRemoteMethods(defaultOptions) {
|
|
|
788
805
|
const { functionStubs, ...invokeOptions } = options ?? {};
|
|
789
806
|
const normalizedOptions = resolveFunctionStubOptions(defaultOptions, functionStubs);
|
|
790
807
|
if (!normalizedOptions.allow) {
|
|
791
|
-
const wrapped
|
|
792
|
-
wrapped
|
|
793
|
-
return wrapped
|
|
808
|
+
const wrapped = baseInvoke(req, invokeOptions);
|
|
809
|
+
wrapped.dispose = () => void 0;
|
|
810
|
+
return wrapped;
|
|
794
811
|
}
|
|
795
812
|
let serialized;
|
|
796
813
|
try {
|
|
@@ -828,7 +845,6 @@ function withRemoteMethods(defaultOptions) {
|
|
|
828
845
|
}
|
|
829
846
|
};
|
|
830
847
|
}
|
|
831
|
-
|
|
832
848
|
//#endregion
|
|
833
849
|
//#region src/stream.ts
|
|
834
850
|
/**
|
|
@@ -1082,17 +1098,17 @@ function defineStreamInvokeHandler(serverCtx, event, fn) {
|
|
|
1082
1098
|
const abortController = abortControllers.get(invokeId);
|
|
1083
1099
|
if (!abortController) {
|
|
1084
1100
|
abortReasons.set(invokeId, reason);
|
|
1085
|
-
let controller
|
|
1086
|
-
if (!controller
|
|
1101
|
+
let controller = streamStates.get(invokeId);
|
|
1102
|
+
if (!controller) {
|
|
1087
1103
|
let localController;
|
|
1088
1104
|
const reqStream = new ReadableStream({ start(c) {
|
|
1089
1105
|
localController = c;
|
|
1090
1106
|
} });
|
|
1091
|
-
controller
|
|
1092
|
-
streamStates.set(invokeId, controller
|
|
1107
|
+
controller = localController;
|
|
1108
|
+
streamStates.set(invokeId, controller);
|
|
1093
1109
|
handleInvoke(invokeId, reqStream);
|
|
1094
1110
|
}
|
|
1095
|
-
controller
|
|
1111
|
+
controller.error(createAbortError(reason));
|
|
1096
1112
|
streamStates.delete(invokeId);
|
|
1097
1113
|
return;
|
|
1098
1114
|
}
|
|
@@ -1163,7 +1179,7 @@ function toStreamHandler(handler) {
|
|
|
1163
1179
|
}();
|
|
1164
1180
|
};
|
|
1165
1181
|
}
|
|
1166
|
-
|
|
1167
1182
|
//#endregion
|
|
1168
1183
|
export { isInvokeEventa as C, registerInvokeAbortEventListeners as E, defineInvokeEventa as S, isSendEvent as T, isAbortError as _, withRemoteMethods as a, randomBetween as b, defineInvokeHandler as c, isExtendableInvokeResponseLike as d, undefineInvokeHandler as f, createUntilTriggeredOnce as g, createUntilTriggered as h, createRemoteMethodTagPrefix as i, defineInvokeHandlers as l, createUntil as m, defineStreamInvokeHandler as n, withTransfer as o, createAbortError as p, toStreamHandler as r, defineInvoke as s, defineStreamInvoke as t, defineInvokes as u, isAsyncIterable as v, isReceiveEvent as w, InvokeEventType as x, isReadableStream as y };
|
|
1169
|
-
|
|
1184
|
+
|
|
1185
|
+
//# sourceMappingURL=src-CTs6h4Ci.mjs.map
|