@moeru/eventa 0.3.0
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/LICENSE +21 -0
- package/README.md +286 -0
- package/dist/adapters/electron/main.d.mts +26 -0
- package/dist/adapters/electron/main.mjs +67 -0
- package/dist/adapters/electron/main.mjs.map +1 -0
- package/dist/adapters/electron/renderer.d.mts +24 -0
- package/dist/adapters/electron/renderer.mjs +53 -0
- package/dist/adapters/electron/renderer.mjs.map +1 -0
- package/dist/adapters/event-emitter/index.d.mts +35 -0
- package/dist/adapters/event-emitter/index.mjs +62 -0
- package/dist/adapters/event-emitter/index.mjs.map +1 -0
- package/dist/adapters/event-target/index.d.mts +35 -0
- package/dist/adapters/event-target/index.mjs +67 -0
- package/dist/adapters/event-target/index.mjs.map +1 -0
- package/dist/adapters/websocket/h3/index.d.mts +57 -0
- package/dist/adapters/websocket/h3/index.mjs +100 -0
- package/dist/adapters/websocket/h3/index.mjs.map +1 -0
- package/dist/adapters/websocket/index.d.mts +12 -0
- package/dist/adapters/websocket/index.mjs +1 -0
- package/dist/adapters/websocket/native/index.d.mts +26 -0
- package/dist/adapters/websocket/native/index.mjs +40 -0
- package/dist/adapters/websocket/native/index.mjs.map +1 -0
- package/dist/adapters/webworkers/index.d.mts +63 -0
- package/dist/adapters/webworkers/index.mjs +42 -0
- package/dist/adapters/webworkers/index.mjs.map +1 -0
- package/dist/adapters/webworkers/worker/index.d.mts +24 -0
- package/dist/adapters/webworkers/worker/index.mjs +40 -0
- package/dist/adapters/webworkers/worker/index.mjs.map +1 -0
- package/dist/context-C35Qku9U.mjs +191 -0
- package/dist/context-C35Qku9U.mjs.map +1 -0
- package/dist/context-C_-MRU46.d.mts +41 -0
- package/dist/eventa-B2HPBK4S.d.mts +51 -0
- package/dist/index-BgaYNgPh.d.mts +24 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.mjs +4 -0
- package/dist/internal-DjiAQtsa.mjs +18 -0
- package/dist/internal-DjiAQtsa.mjs.map +1 -0
- package/dist/invoke-LTUFMmHi.d.mts +137 -0
- package/dist/shared-Da41l-vp.mjs +21 -0
- package/dist/shared-Da41l-vp.mjs.map +1 -0
- package/dist/shared-DbO1rU2W.mjs +71 -0
- package/dist/shared-DbO1rU2W.mjs.map +1 -0
- package/dist/shared-DllZ3RPS.d.mts +18 -0
- package/dist/src-Bb-vxm5k.mjs +289 -0
- package/dist/src-Bb-vxm5k.mjs.map +1 -0
- package/package.json +121 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { EventTag, EventaType } from "./eventa-B2HPBK4S.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/adapters/electron/shared.d.ts
|
|
4
|
+
interface Payload<T> {
|
|
5
|
+
id: string;
|
|
6
|
+
type: EventTag<any, any>;
|
|
7
|
+
payload: T;
|
|
8
|
+
}
|
|
9
|
+
declare const errorEvent: {
|
|
10
|
+
body?: {
|
|
11
|
+
error: unknown;
|
|
12
|
+
} | undefined;
|
|
13
|
+
id: string;
|
|
14
|
+
type?: EventaType.Event | undefined;
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
export { Payload, errorEvent };
|
|
18
|
+
//# sourceMappingURL=shared-DllZ3RPS.d.mts.map
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { defineEventa, nanoid } from "./context-C35Qku9U.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/invoke-shared.ts
|
|
4
|
+
let InvokeEventType = /* @__PURE__ */ function(InvokeEventType$1) {
|
|
5
|
+
InvokeEventType$1[InvokeEventType$1["SendEvent"] = 0] = "SendEvent";
|
|
6
|
+
InvokeEventType$1[InvokeEventType$1["SendEventError"] = 1] = "SendEventError";
|
|
7
|
+
InvokeEventType$1[InvokeEventType$1["ReceiveEvent"] = 2] = "ReceiveEvent";
|
|
8
|
+
InvokeEventType$1[InvokeEventType$1["ReceiveEventError"] = 3] = "ReceiveEventError";
|
|
9
|
+
InvokeEventType$1[InvokeEventType$1["ReceiveEventStreamEnd"] = 4] = "ReceiveEventStreamEnd";
|
|
10
|
+
return InvokeEventType$1;
|
|
11
|
+
}({});
|
|
12
|
+
function defineInvokeEventa(tag) {
|
|
13
|
+
if (!tag) tag = nanoid();
|
|
14
|
+
const sendEvent = {
|
|
15
|
+
...defineEventa(`${tag}-send`),
|
|
16
|
+
invokeType: InvokeEventType.SendEvent
|
|
17
|
+
};
|
|
18
|
+
const sendEventError = {
|
|
19
|
+
...defineEventa(`${tag}-send-error`),
|
|
20
|
+
invokeType: InvokeEventType.SendEventError
|
|
21
|
+
};
|
|
22
|
+
const receiveEvent = {
|
|
23
|
+
...defineEventa(`${tag}-receive`),
|
|
24
|
+
invokeType: InvokeEventType.ReceiveEvent
|
|
25
|
+
};
|
|
26
|
+
const receiveEventError = {
|
|
27
|
+
...defineEventa(`${tag}-receive-error`),
|
|
28
|
+
invokeType: InvokeEventType.ReceiveEventError
|
|
29
|
+
};
|
|
30
|
+
const receiveEventStreamEnd = {
|
|
31
|
+
...defineEventa(`${tag}-receive-stream-end`),
|
|
32
|
+
invokeType: InvokeEventType.ReceiveEventStreamEnd
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
sendEvent,
|
|
36
|
+
sendEventError,
|
|
37
|
+
receiveEvent,
|
|
38
|
+
receiveEventError,
|
|
39
|
+
receiveEventStreamEnd
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function isInvokeEventa(event) {
|
|
43
|
+
if (typeof event !== "object") return false;
|
|
44
|
+
if ("invokeType" in event) return true;
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
function isSendEvent(event) {
|
|
48
|
+
if (!isInvokeEventa(event)) return false;
|
|
49
|
+
return event.invokeType === InvokeEventType.SendEvent || event.invokeType === InvokeEventType.SendEventError;
|
|
50
|
+
}
|
|
51
|
+
function isReceiveEvent(event) {
|
|
52
|
+
if (!isInvokeEventa(event)) return false;
|
|
53
|
+
return event.invokeType === InvokeEventType.ReceiveEvent || event.invokeType === InvokeEventType.ReceiveEventError || event.invokeType === InvokeEventType.ReceiveEventStreamEnd;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/invoke.ts
|
|
58
|
+
function isExtendableInvokeResponseLike(value) {
|
|
59
|
+
if (!isReceiveEvent(value)) return false;
|
|
60
|
+
return typeof value.body?.content === "object" && value.body?.content != null && "response" in value.body.content && (!("invokeResponse" in value.body.content) || "invokeResponse" in value.body.content && (typeof value.body.content.invokeResponse === "object" || typeof value.body.content.invokeResponse === "undefined"));
|
|
61
|
+
}
|
|
62
|
+
function defineInvoke(ctx, event) {
|
|
63
|
+
const mInvokeIdPromiseResolvers = /* @__PURE__ */ new Map();
|
|
64
|
+
const mInvokeIdPromiseRejectors = /* @__PURE__ */ new Map();
|
|
65
|
+
function _invoke(req, options) {
|
|
66
|
+
return new Promise((resolve, reject) => {
|
|
67
|
+
const invokeId = nanoid();
|
|
68
|
+
mInvokeIdPromiseResolvers.set(invokeId, resolve);
|
|
69
|
+
mInvokeIdPromiseRejectors.set(invokeId, reject);
|
|
70
|
+
const invokeReceiveEvent = defineEventa(`${event.receiveEvent.id}-${invokeId}`);
|
|
71
|
+
const invokeReceiveEventError = defineEventa(`${event.receiveEventError.id}-${invokeId}`);
|
|
72
|
+
ctx.on(invokeReceiveEvent, (payload) => {
|
|
73
|
+
if (!payload.body) return;
|
|
74
|
+
if (payload.body.invokeId !== invokeId) return;
|
|
75
|
+
const { content } = payload.body;
|
|
76
|
+
mInvokeIdPromiseResolvers.get(invokeId)?.(content);
|
|
77
|
+
mInvokeIdPromiseResolvers.delete(invokeId);
|
|
78
|
+
mInvokeIdPromiseRejectors.delete(invokeId);
|
|
79
|
+
ctx.off(invokeReceiveEvent);
|
|
80
|
+
ctx.off(invokeReceiveEventError);
|
|
81
|
+
});
|
|
82
|
+
ctx.on(invokeReceiveEventError, (payload) => {
|
|
83
|
+
if (!payload.body) return;
|
|
84
|
+
if (payload.body.invokeId !== invokeId) return;
|
|
85
|
+
const { error } = payload.body.content;
|
|
86
|
+
mInvokeIdPromiseRejectors.get(invokeId)?.(error);
|
|
87
|
+
mInvokeIdPromiseRejectors.delete(invokeId);
|
|
88
|
+
mInvokeIdPromiseResolvers.delete(invokeId);
|
|
89
|
+
ctx.off(invokeReceiveEvent);
|
|
90
|
+
ctx.off(invokeReceiveEventError);
|
|
91
|
+
});
|
|
92
|
+
ctx.emit(event.sendEvent, {
|
|
93
|
+
invokeId,
|
|
94
|
+
content: req
|
|
95
|
+
}, options);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return _invoke;
|
|
99
|
+
}
|
|
100
|
+
function defineInvokes(ctx, events) {
|
|
101
|
+
return Object.keys(events).reduce((invokes, key) => {
|
|
102
|
+
invokes[key] = defineInvoke(ctx, events[key]);
|
|
103
|
+
return invokes;
|
|
104
|
+
}, {});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Define an invoke handler for a specific invoke event.
|
|
108
|
+
*
|
|
109
|
+
* @param ctx The event context in which to define the invoke handler.
|
|
110
|
+
* @param event The invoke event for which the handler is to be defined.
|
|
111
|
+
* @param handler The handler function to be invoked when the event is triggered.
|
|
112
|
+
* @returns A function that can be called to remove the invoke handler.
|
|
113
|
+
*/
|
|
114
|
+
function defineInvokeHandler(ctx, event, handler) {
|
|
115
|
+
if (!ctx.invokeHandlers) ctx.invokeHandlers = /* @__PURE__ */ new Map();
|
|
116
|
+
let handlers = ctx.invokeHandlers?.get(event.sendEvent.id);
|
|
117
|
+
if (!handlers) {
|
|
118
|
+
handlers = /* @__PURE__ */ new Map();
|
|
119
|
+
ctx.invokeHandlers?.set(event.sendEvent.id, handlers);
|
|
120
|
+
}
|
|
121
|
+
let internalHandler = handlers.get(handler);
|
|
122
|
+
if (!internalHandler) {
|
|
123
|
+
internalHandler = async (payload, options) => {
|
|
124
|
+
if (!payload.body) return;
|
|
125
|
+
if (!payload.body.invokeId) return;
|
|
126
|
+
try {
|
|
127
|
+
const response = await handler(payload.body?.content, options);
|
|
128
|
+
ctx.emit({
|
|
129
|
+
...defineEventa(`${event.receiveEvent.id}-${payload.body.invokeId}`),
|
|
130
|
+
invokeType: event.receiveEvent.invokeType
|
|
131
|
+
}, {
|
|
132
|
+
...payload.body,
|
|
133
|
+
content: response
|
|
134
|
+
}, options);
|
|
135
|
+
} catch (error) {
|
|
136
|
+
ctx.emit({
|
|
137
|
+
...defineEventa(`${event.receiveEventError.id}-${payload.body.invokeId}`),
|
|
138
|
+
invokeType: event.receiveEventError.invokeType
|
|
139
|
+
}, {
|
|
140
|
+
...payload.body,
|
|
141
|
+
content: error
|
|
142
|
+
}, options);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
handlers.set(handler, internalHandler);
|
|
146
|
+
ctx.on(event.sendEvent, internalHandler);
|
|
147
|
+
}
|
|
148
|
+
return () => ctx.off(event.sendEvent, internalHandler);
|
|
149
|
+
}
|
|
150
|
+
function defineInvokeHandlers(ctx, events, handlers) {
|
|
151
|
+
const eventKeys = Object.keys(events);
|
|
152
|
+
const handlerKeys = new Set(Object.keys(handlers));
|
|
153
|
+
if (eventKeys.length !== handlerKeys.size || !eventKeys.every((key) => handlerKeys.has(key))) throw new Error("The keys of events and handlers must match.");
|
|
154
|
+
return eventKeys.reduce((returnValues, key) => {
|
|
155
|
+
returnValues[key] = defineInvokeHandler(ctx, events[key], handlers[key]);
|
|
156
|
+
return returnValues;
|
|
157
|
+
}, {});
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Remove one or all invoke handlers for a specific invoke event.
|
|
161
|
+
*
|
|
162
|
+
* @param ctx The event context from which to remove the invoke handler(s).
|
|
163
|
+
* @param event The invoke event whose handlers are to be removed.
|
|
164
|
+
* @param handler The specific handler to remove. If not omitted, all handlers for the event will be removed.
|
|
165
|
+
* @returns `true` if at least one handler was removed, `false` otherwise
|
|
166
|
+
*/
|
|
167
|
+
function undefineInvokeHandler(ctx, event, handler) {
|
|
168
|
+
if (!ctx.invokeHandlers) return false;
|
|
169
|
+
const handlers = ctx.invokeHandlers?.get(event.sendEvent.id);
|
|
170
|
+
if (!handlers) return false;
|
|
171
|
+
if (handler) {
|
|
172
|
+
const internalHandler = handlers.get(handler);
|
|
173
|
+
if (!internalHandler) return false;
|
|
174
|
+
ctx.off(event.sendEvent, internalHandler);
|
|
175
|
+
ctx.invokeHandlers.delete(event.sendEvent.id);
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
let returnValue = false;
|
|
179
|
+
for (const internalHandlers of handlers.values()) {
|
|
180
|
+
ctx.off(event.sendEvent, internalHandlers);
|
|
181
|
+
returnValue = true;
|
|
182
|
+
}
|
|
183
|
+
ctx.invokeHandlers.delete(event.sendEvent.id);
|
|
184
|
+
return returnValue;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region src/stream.ts
|
|
189
|
+
function defineStreamInvoke(clientCtx, event) {
|
|
190
|
+
return (req) => {
|
|
191
|
+
const invokeId = nanoid();
|
|
192
|
+
const invokeReceiveEvent = defineEventa(`${event.receiveEvent.id}-${invokeId}`);
|
|
193
|
+
const invokeReceiveEventError = defineEventa(`${event.receiveEventError.id}-${invokeId}`);
|
|
194
|
+
const invokeReceiveEventStreamEnd = defineEventa(`${event.receiveEventStreamEnd.id}-${invokeId}`);
|
|
195
|
+
const stream = new ReadableStream({
|
|
196
|
+
start(controller) {
|
|
197
|
+
clientCtx.on(invokeReceiveEvent, (payload) => {
|
|
198
|
+
if (!payload.body) return;
|
|
199
|
+
if (payload.body.invokeId !== invokeId) return;
|
|
200
|
+
controller.enqueue(payload.body.content);
|
|
201
|
+
});
|
|
202
|
+
clientCtx.on(invokeReceiveEventError, (payload) => {
|
|
203
|
+
if (!payload.body) return;
|
|
204
|
+
if (payload.body.invokeId !== invokeId) return;
|
|
205
|
+
controller.error(payload.body.content);
|
|
206
|
+
});
|
|
207
|
+
clientCtx.on(invokeReceiveEventStreamEnd, (payload) => {
|
|
208
|
+
if (!payload.body) return;
|
|
209
|
+
if (payload.body.invokeId !== invokeId) return;
|
|
210
|
+
controller.close();
|
|
211
|
+
});
|
|
212
|
+
},
|
|
213
|
+
cancel() {
|
|
214
|
+
clientCtx.off(invokeReceiveEvent);
|
|
215
|
+
clientCtx.off(invokeReceiveEventError);
|
|
216
|
+
clientCtx.off(invokeReceiveEventStreamEnd);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
clientCtx.emit(event.sendEvent, {
|
|
220
|
+
invokeId,
|
|
221
|
+
content: req
|
|
222
|
+
});
|
|
223
|
+
return stream;
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
function defineStreamInvokeHandler(serverCtx, event, fn) {
|
|
227
|
+
serverCtx.on(event.sendEvent, async (payload, options) => {
|
|
228
|
+
if (!payload.body) return;
|
|
229
|
+
if (!payload.body.invokeId) return;
|
|
230
|
+
const invokeReceiveEvent = defineEventa(`${event.receiveEvent.id}-${payload.body.invokeId}`);
|
|
231
|
+
const invokeReceiveEventError = defineEventa(`${event.receiveEventError.id}-${payload.body.invokeId}`);
|
|
232
|
+
const invokeReceiveEventStreamEnd = defineEventa(`${event.receiveEventStreamEnd.id}-${payload.body.invokeId}`);
|
|
233
|
+
try {
|
|
234
|
+
const generator = fn(payload.body.content, options);
|
|
235
|
+
for await (const res of generator) serverCtx.emit(invokeReceiveEvent, {
|
|
236
|
+
...payload.body,
|
|
237
|
+
content: res
|
|
238
|
+
}, options);
|
|
239
|
+
serverCtx.emit(invokeReceiveEventStreamEnd, {
|
|
240
|
+
...payload.body,
|
|
241
|
+
content: void 0
|
|
242
|
+
}, options);
|
|
243
|
+
} catch (error) {
|
|
244
|
+
serverCtx.emit(invokeReceiveEventError, {
|
|
245
|
+
...payload.body,
|
|
246
|
+
content: error
|
|
247
|
+
}, options);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
function toStreamHandler(handler) {
|
|
252
|
+
return (payload, options) => {
|
|
253
|
+
const values = [];
|
|
254
|
+
let resolve;
|
|
255
|
+
let handlerError = null;
|
|
256
|
+
values.push(new Promise((r) => {
|
|
257
|
+
resolve = r;
|
|
258
|
+
}));
|
|
259
|
+
const emit = (data) => {
|
|
260
|
+
resolve([data, false]);
|
|
261
|
+
values.push(new Promise((r) => {
|
|
262
|
+
resolve = r;
|
|
263
|
+
}));
|
|
264
|
+
};
|
|
265
|
+
handler({
|
|
266
|
+
payload,
|
|
267
|
+
options,
|
|
268
|
+
emit
|
|
269
|
+
}).then(() => {
|
|
270
|
+
resolve([void 0, true]);
|
|
271
|
+
}).catch((err) => {
|
|
272
|
+
handlerError = err;
|
|
273
|
+
resolve([void 0, true]);
|
|
274
|
+
});
|
|
275
|
+
return async function* () {
|
|
276
|
+
let val;
|
|
277
|
+
for (let i = 0, done = false; !done; i++) {
|
|
278
|
+
[val, done] = await values[i];
|
|
279
|
+
delete values[i];
|
|
280
|
+
if (handlerError) throw handlerError;
|
|
281
|
+
if (!done) yield val;
|
|
282
|
+
}
|
|
283
|
+
}();
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
//#endregion
|
|
288
|
+
export { InvokeEventType, defineInvoke, defineInvokeEventa, defineInvokeHandler, defineInvokeHandlers, defineInvokes, defineStreamInvoke, defineStreamInvokeHandler, isExtendableInvokeResponseLike, isInvokeEventa, isReceiveEvent, isSendEvent, toStreamHandler, undefineInvokeHandler };
|
|
289
|
+
//# sourceMappingURL=src-Bb-vxm5k.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"src-Bb-vxm5k.mjs","names":["values: Promise<[Res, boolean]>[]","resolve: (x: [Res, boolean]) => void","handlerError: Error | null","val: Res"],"sources":["../src/invoke-shared.ts","../src/invoke.ts","../src/stream.ts"],"sourcesContent":["import type { Eventa, EventTag } from './eventa'\n\nimport { defineEventa, nanoid } from './eventa'\n\nexport enum InvokeEventType {\n SendEvent,\n SendEventError,\n ReceiveEvent,\n ReceiveEventError,\n ReceiveEventStreamEnd,\n}\n\nexport interface SendEvent<Res, Req = undefined, _ = undefined, __ = undefined> extends Eventa<{ invokeId: string, content: Req }> {\n id: EventTag<Res, Req>\n invokeType: InvokeEventType.SendEvent\n}\nexport interface SendEventError<Res, Req = undefined, _ = undefined, ReqErr = Error> extends Eventa<{ invokeId: string, content: ReqErr }> {\n id: EventTag<Res, Req>\n invokeType: InvokeEventType.SendEventError\n}\nexport interface ReceiveEvent<Res, Req = undefined, _ = undefined, __ = undefined> extends Eventa<{ invokeId: string, content: Res }> {\n id: EventTag<Res, Req>\n invokeType: InvokeEventType.ReceiveEvent\n}\nexport interface ReceiveEventError<Res, Req = undefined, ResErr = undefined, _ = undefined> extends Eventa<{ invokeId: string, content: { error: ResErr } }> {\n id: EventTag<Res, Req>\n invokeType: InvokeEventType.ReceiveEventError\n}\nexport interface ReceiveEventStreamEnd<Res, Req = undefined, _ = undefined, __ = undefined> extends Eventa<{ invokeId: string, content: undefined }> {\n id: EventTag<Res, Req>\n invokeType: InvokeEventType.ReceiveEventStreamEnd\n}\n\nexport interface InvokeEventa<Res, Req = undefined, ResErr = Error, ReqErr = Error> {\n sendEvent: SendEvent<Res, Req, ResErr, ReqErr>\n sendEventError: SendEventError<Res, Req, ResErr, ReqErr>\n receiveEvent: ReceiveEvent<Res, Req, ResErr, ReqErr>\n receiveEventError: ReceiveEventError<Res, Req, ResErr, ReqErr>\n receiveEventStreamEnd: ReceiveEventStreamEnd<Res, Req, ResErr, ReqErr>\n}\n\nexport function defineInvokeEventa<Res, Req = undefined, ResErr = Error, ReqErr = Error>(tag?: string) {\n if (!tag) {\n tag = nanoid()\n }\n\n const sendEvent = {\n ...defineEventa<InvokeEventType.SendEvent>(`${tag}-send`),\n invokeType: InvokeEventType.SendEvent,\n } as SendEvent<Res, Req, ResErr, ReqErr>\n const sendEventError = {\n ...defineEventa<InvokeEventType.SendEventError>(`${tag}-send-error`),\n invokeType: InvokeEventType.SendEventError,\n } as SendEventError<Res, Req, ResErr, ReqErr>\n const receiveEvent = {\n ...defineEventa<InvokeEventType.ReceiveEvent>(`${tag}-receive`),\n invokeType: InvokeEventType.ReceiveEvent,\n } as ReceiveEvent<Res, Req, ResErr, ReqErr>\n const receiveEventError = {\n ...defineEventa<InvokeEventType.ReceiveEventError>(`${tag}-receive-error`),\n invokeType: InvokeEventType.ReceiveEventError,\n } as ReceiveEventError<Res, Req, ResErr, ReqErr>\n const receiveEventStreamEnd = {\n ...defineEventa<InvokeEventType.ReceiveEventStreamEnd>(`${tag}-receive-stream-end`),\n invokeType: InvokeEventType.ReceiveEventStreamEnd,\n } as ReceiveEventStreamEnd<Res, Req, ResErr, ReqErr>\n\n return {\n sendEvent,\n sendEventError,\n receiveEvent,\n receiveEventError,\n receiveEventStreamEnd,\n } satisfies InvokeEventa<Res, Req, ResErr, ReqErr>\n}\n\nexport function isInvokeEventa(event: Eventa<any>): event is SendEvent<any, any, any, any> | SendEventError<any, any, any, any> | ReceiveEvent<any, any, any, any> | ReceiveEventError<any, any, any, any> | ReceiveEventStreamEnd<any, any, any, any> {\n if (typeof event !== 'object') {\n return false\n }\n if ('invokeType' in event) {\n return true\n }\n\n return false\n}\n\nexport function isSendEvent(event: Eventa<any>): event is SendEvent<any, any, any, any> | SendEventError<any, any, any, any> {\n if (!isInvokeEventa(event)) {\n return false\n }\n\n return event.invokeType === InvokeEventType.SendEvent || event.invokeType === InvokeEventType.SendEventError\n}\n\nexport function isReceiveEvent(event: Eventa<any>): event is ReceiveEvent<any, any, any, any> | ReceiveEventError<any, any, any, any> | ReceiveEventStreamEnd<any, any, any, any> {\n if (!isInvokeEventa(event)) {\n return false\n }\n\n return event.invokeType === InvokeEventType.ReceiveEvent || event.invokeType === InvokeEventType.ReceiveEventError || event.invokeType === InvokeEventType.ReceiveEventStreamEnd\n}\n","import type { EventContext } from './context'\nimport type { Eventa } from './eventa'\nimport type { InvokeEventa, ReceiveEvent, ReceiveEventError } from './invoke-shared'\n\nimport { defineEventa, nanoid } from './eventa'\nimport { isReceiveEvent } from './invoke-shared'\n\ntype IsInvokeRequestOptional<EC extends EventContext<any, any>>\n = EC extends EventContext<infer E, any>\n ? E extends { invokeRequest: any }\n ? undefined extends E['invokeRequest']\n ? true\n : false\n : E extends { invokeRequest?: any }\n ? undefined extends E['invokeRequest']\n ? true\n : false\n : true\n : true\n\ntype ExtractInvokeRequest<EC extends EventContext<any, any>>\n = EC extends EventContext<infer E, any>\n ? E extends { invokeRequest: infer IR }\n ? IR\n : E extends { invokeRequest?: infer IR }\n ? IR\n : undefined\n : undefined\n\ntype ExtractInvokeResponse<EC extends EventContext<any, any>>\n = EC extends EventContext<infer E, any>\n ? E extends { invokeResponse: infer IR }\n ? IR\n : E extends { invokeResponse?: infer IR }\n ? IR\n : undefined\n : undefined\n\nexport type InvokeFunction<Res, Req, EC extends EventContext<any, any>>\n = Req extends undefined\n ? IsInvokeRequestOptional<EC> extends true\n ? (req?: Req, invokeRequest?: ExtractInvokeRequest<EC>) => Promise<Res>\n : (req: Req, invokeRequest: ExtractInvokeRequest<EC>) => Promise<Res>\n : IsInvokeRequestOptional<EC> extends true\n ? (req: Req, invokeRequest?: ExtractInvokeRequest<EC>) => Promise<Res>\n : (req: Req, invokeRequest: ExtractInvokeRequest<EC>) => Promise<Res>\n\nexport type InvokeFunctionMap<EventMap extends Record<string, InvokeEventa<any, any, any, any>>, EC extends EventContext<any, any>> = {\n [K in keyof EventMap]: EventMap[K] extends InvokeEventa<infer Res, infer Req, any, any> ? InvokeFunction<Res, Req, EC> : never\n}\n\nexport type ExtendableInvokeResponse<Res, EC extends EventContext<any, any>>\n = | Promise<Res>\n | Res\n | Promise<{ response: Res, invokeResponse?: ExtractInvokeResponse<EC> }>\n | { response: Res, invokeResponse?: ExtractInvokeResponse<EC> }\n\nexport function isExtendableInvokeResponseLike<Res, EC extends EventContext<any, any>>(value: Eventa<unknown> | ReceiveEvent<{ response: Res, invokeResponse?: unknown }>): value is ReceiveEvent<{ response: Res, invokeResponse?: ExtractInvokeResponse<EC> }> {\n if (!isReceiveEvent(value)) {\n return false\n }\n\n return typeof value.body?.content === 'object'\n && value.body?.content != null\n && 'response' in value.body.content\n && (\n !('invokeResponse' in value.body.content)\n || (\n 'invokeResponse' in value.body.content\n && (\n typeof value.body.content.invokeResponse === 'object'\n || typeof value.body.content.invokeResponse === 'undefined'\n )\n )\n )\n}\n\nexport type Handler<Res, Req = any, EC extends EventContext<any, any> = EventContext<any, any>, RawEventOptions = unknown> = (\n payload: Req,\n options?: {\n /**\n * TODO: Support aborting invoke handlers\n */\n abortController?: AbortController\n } & RawEventOptions\n) => ExtendableInvokeResponse<Res, EC>\n\ntype InternalInvokeHandler<\n Res,\n Req = any,\n ResErr = Error,\n ReqErr = Error,\n EO = any,\n> = (params: InvokeEventa<Res, Req, ResErr, ReqErr>['sendEvent'], eventOptions?: EO) => void\n\nexport type HandlerMap<\n EventMap extends Record<string, InvokeEventa<any, any, any, any>>,\n EO = any,\n EC extends EventContext<any, any> = EventContext<any, any>,\n> = {\n [K in keyof EventMap]: EventMap[K] extends InvokeEventa<infer Res, infer Req, any, any>\n ? Handler<Res, Req, EC, EO>\n : never\n}\n\nexport interface InvocableEventContext<E, EO> extends EventContext<E, EO> {\n invokeHandlers?: Map<string, Map<Handler<any>, InternalInvokeHandler<any>>>\n}\n\nexport function defineInvoke<\n Res,\n Req = undefined,\n ResErr = Error,\n ReqErr = Error,\n CtxExt = any,\n EOpts = any,\n ECtx extends EventContext<CtxExt, EOpts> = EventContext<CtxExt, EOpts>,\n>(ctx: ECtx, event: InvokeEventa<Res, Req, ResErr, ReqErr>): InvokeFunction<Res, Req, ECtx> {\n const mInvokeIdPromiseResolvers = new Map<string, (value: Res | PromiseLike<Res>) => void>()\n const mInvokeIdPromiseRejectors = new Map<string, (err?: any) => void>()\n\n function _invoke(req: Req, options?: { invokeRequest?: ExtractInvokeRequest<ECtx> }): Promise<Res> {\n return new Promise<Res>((resolve, reject) => {\n const invokeId = nanoid()\n mInvokeIdPromiseResolvers.set(invokeId, resolve)\n mInvokeIdPromiseRejectors.set(invokeId, reject)\n\n const invokeReceiveEvent = defineEventa(`${event.receiveEvent.id}-${invokeId}`) as ReceiveEvent<Res>\n const invokeReceiveEventError = defineEventa(`${event.receiveEventError.id}-${invokeId}`) as ReceiveEventError<ResErr>\n\n ctx.on(invokeReceiveEvent, (payload) => {\n if (!payload.body) {\n return\n }\n if (payload.body.invokeId !== invokeId) {\n return\n }\n\n const { content } = payload.body\n mInvokeIdPromiseResolvers.get(invokeId)?.(content as Res)\n mInvokeIdPromiseResolvers.delete(invokeId)\n mInvokeIdPromiseRejectors.delete(invokeId)\n ctx.off(invokeReceiveEvent)\n ctx.off(invokeReceiveEventError)\n })\n\n ctx.on(invokeReceiveEventError, (payload) => {\n if (!payload.body) {\n return\n }\n if (payload.body.invokeId !== invokeId) {\n return\n }\n\n const { error } = payload.body.content\n mInvokeIdPromiseRejectors.get(invokeId)?.(error)\n mInvokeIdPromiseRejectors.delete(invokeId)\n mInvokeIdPromiseResolvers.delete(invokeId)\n ctx.off(invokeReceiveEvent)\n ctx.off(invokeReceiveEventError)\n })\n\n ctx.emit(event.sendEvent, { invokeId, content: req }, options as any) // emit: event_trigger\n })\n }\n\n return _invoke as InvokeFunction<Res, Req, ECtx>\n}\n\nexport function defineInvokes<\n EK extends string,\n EventMap extends Record<EK, InvokeEventa<any, any, any, any>>,\n CtxExt = any,\n EOpts = any,\n ECtx extends EventContext<CtxExt, EOpts> = EventContext<CtxExt, EOpts>,\n>(ctx: ECtx, events: EventMap): InvokeFunctionMap<EventMap, ECtx> {\n return (Object.keys(events) as EK[]).reduce((invokes, key) => {\n invokes[key] = defineInvoke(ctx, events[key])\n return invokes\n }, {} as Record<EK, InvokeFunction<any, any, ECtx>>) as InvokeFunctionMap<EventMap, ECtx>\n}\n\n/**\n * Define an invoke handler for a specific invoke event.\n *\n * @param ctx The event context in which to define the invoke handler.\n * @param event The invoke event for which the handler is to be defined.\n * @param handler The handler function to be invoked when the event is triggered.\n * @returns A function that can be called to remove the invoke handler.\n */\nexport function defineInvokeHandler<\n Res,\n Req = undefined,\n ResErr = Error,\n ReqErr = Error,\n CtxExt = any,\n EOpts extends { raw?: any } = any,\n>(\n ctx: InvocableEventContext<CtxExt, EOpts>,\n event: InvokeEventa<Res, Req, ResErr, ReqErr>,\n handler: Handler<Res, Req, InvocableEventContext<CtxExt, EOpts>, EOpts>,\n): () => void {\n if (!ctx.invokeHandlers) {\n ctx.invokeHandlers = new Map()\n }\n\n let handlers = ctx.invokeHandlers?.get(event.sendEvent.id)\n if (!handlers) {\n handlers = new Map()\n ctx.invokeHandlers?.set(event.sendEvent.id, handlers)\n }\n\n let internalHandler = handlers.get(handler) as InternalInvokeHandler<Res, Req, ResErr, ReqErr, EOpts> | undefined\n if (!internalHandler) {\n internalHandler = async (payload, options) => { // on: event_trigger\n if (!payload.body) {\n return\n }\n if (!payload.body.invokeId) {\n return\n }\n\n try {\n const response = await handler(payload.body?.content as Req, options) // Call the handler function with the request payload\n ctx.emit(\n { ...defineEventa(`${event.receiveEvent.id}-${payload.body.invokeId}`), invokeType: event.receiveEvent.invokeType } as ReceiveEvent<ExtendableInvokeResponse<Res, InvocableEventContext<CtxExt, EOpts>>>,\n { ...payload.body, content: response },\n options,\n ) // emit: event_response\n }\n catch (error) {\n // TODO: to error object\n ctx.emit(\n { ...defineEventa(`${event.receiveEventError.id}-${payload.body.invokeId}`), invokeType: event.receiveEventError.invokeType } as ReceiveEventError<ResErr>,\n { ...payload.body, content: error as any },\n options,\n )\n }\n }\n\n handlers.set(handler, internalHandler)\n ctx.on(event.sendEvent, internalHandler)\n }\n\n return () => ctx.off(event.sendEvent, internalHandler)\n}\n\nexport function defineInvokeHandlers<\n EK extends string,\n EventMap extends Record<EK, InvokeEventa<any, any, any, any>>,\n CtxExt = any,\n EOpts extends { raw?: any } = any,\n>(\n ctx: InvocableEventContext<CtxExt, EOpts>,\n events: EventMap,\n handlers: HandlerMap<EventMap, EOpts>,\n): Record<EK, () => void> {\n const eventKeys = Object.keys(events) as EK[]\n const handlerKeys = new Set(Object.keys(handlers) as EK[])\n\n if (eventKeys.length !== handlerKeys.size || !eventKeys.every(key => handlerKeys.has(key))) {\n throw new Error('The keys of events and handlers must match.')\n }\n\n return eventKeys.reduce((returnValues, key) => {\n returnValues[key] = defineInvokeHandler(ctx, events[key], handlers[key])\n return returnValues\n }, {} as Record<EK, () => void>)\n}\n\n/**\n * Remove one or all invoke handlers for a specific invoke event.\n *\n * @param ctx The event context from which to remove the invoke handler(s).\n * @param event The invoke event whose handlers are to be removed.\n * @param handler The specific handler to remove. If not omitted, all handlers for the event will be removed.\n * @returns `true` if at least one handler was removed, `false` otherwise\n */\nexport function undefineInvokeHandler<\n Res,\n Req = undefined,\n ResErr = Error,\n ReqErr = Error,\n CtxExt = any,\n EOpts = any,\n>(\n ctx: InvocableEventContext<CtxExt, EOpts>,\n event: InvokeEventa<Res, Req, ResErr, ReqErr>,\n handler?: Handler<Res, Req, InvocableEventContext<CtxExt, EOpts>, EOpts>,\n): boolean {\n if (!ctx.invokeHandlers)\n return false\n\n const handlers = ctx.invokeHandlers?.get(event.sendEvent.id)\n if (!handlers)\n return false\n\n if (handler) {\n const internalHandler = handlers.get(handler)\n if (!internalHandler)\n return false\n\n ctx.off(event.sendEvent, internalHandler)\n ctx.invokeHandlers.delete(event.sendEvent.id)\n return true\n }\n\n let returnValue = false\n for (const internalHandlers of handlers.values()) {\n ctx.off(event.sendEvent, internalHandlers)\n returnValue = true\n }\n ctx.invokeHandlers.delete(event.sendEvent.id)\n return returnValue\n}\n","import type { EventContext } from './context'\nimport type {\n InvokeEventa,\n ReceiveEvent,\n ReceiveEventError,\n ReceiveEventStreamEnd,\n} from './invoke-shared'\n\nimport { defineEventa, nanoid } from './eventa'\n\nexport function defineStreamInvoke<\n Res,\n Req = undefined,\n ResErr = Error,\n ReqErr = Error,\n E = any,\n EO = any,\n>(clientCtx: EventContext<E, EO>, event: InvokeEventa<Res, Req, ResErr, ReqErr>) {\n return (req: Req) => {\n const invokeId = nanoid()\n\n const invokeReceiveEvent = defineEventa(`${event.receiveEvent.id}-${invokeId}`) as ReceiveEvent<Res>\n const invokeReceiveEventError = defineEventa(`${event.receiveEventError.id}-${invokeId}`) as ReceiveEventError<ResErr>\n const invokeReceiveEventStreamEnd = defineEventa(`${event.receiveEventStreamEnd.id}-${invokeId}`) as ReceiveEventStreamEnd<Res>\n\n const stream = new ReadableStream<Res>({\n start(controller) {\n clientCtx.on(invokeReceiveEvent, (payload) => {\n if (!payload.body) {\n return\n }\n if (payload.body.invokeId !== invokeId) {\n return\n }\n\n controller.enqueue(payload.body.content as Res)\n })\n clientCtx.on(invokeReceiveEventError, (payload) => {\n if (!payload.body) {\n return\n }\n if (payload.body.invokeId !== invokeId) {\n return\n }\n\n controller.error(payload.body.content as ResErr)\n })\n clientCtx.on(invokeReceiveEventStreamEnd, (payload) => {\n if (!payload.body) {\n return\n }\n if (payload.body.invokeId !== invokeId) {\n return\n }\n\n controller.close()\n })\n },\n cancel() {\n clientCtx.off(invokeReceiveEvent)\n clientCtx.off(invokeReceiveEventError)\n clientCtx.off(invokeReceiveEventStreamEnd)\n },\n })\n\n clientCtx.emit(event.sendEvent, { invokeId, content: req }) // emit: event_trigger\n return stream\n }\n}\n\ntype StreamHandler<Res, Req = any, RawEventOptions = unknown> = (\n payload: Req,\n options?: {\n /**\n * TODO: Support aborting invoke handlers\n */\n abortController?: AbortController\n } & RawEventOptions\n) => AsyncGenerator<Res, void, unknown>\n\nexport function defineStreamInvokeHandler<\n Res,\n Req = undefined,\n ResErr = Error,\n ReqErr = Error,\n E = any,\n EO extends { raw?: any } = any,\n>(serverCtx: EventContext<E, EO>, event: InvokeEventa<Res, Req, ResErr, ReqErr>, fn: StreamHandler<Res, Req, EO>) {\n serverCtx.on(event.sendEvent, async (payload, options) => { // on: event_trigger\n if (!payload.body) {\n return\n }\n if (!payload.body.invokeId) {\n return\n }\n\n const invokeReceiveEvent = defineEventa(`${event.receiveEvent.id}-${payload.body.invokeId}`) as ReceiveEvent<Res>\n const invokeReceiveEventError = defineEventa(`${event.receiveEventError.id}-${payload.body.invokeId}`) as ReceiveEventError<ResErr>\n const invokeReceiveEventStreamEnd = defineEventa(`${event.receiveEventStreamEnd.id}-${payload.body.invokeId}`) as ReceiveEventStreamEnd<Res>\n\n try {\n const generator = fn(payload.body.content as Req, options) // Call the handler function with the request payload\n for await (const res of generator) {\n serverCtx.emit(invokeReceiveEvent, { ...payload.body, content: res }, options) // emit: event_response\n }\n\n serverCtx.emit(invokeReceiveEventStreamEnd, { ...payload.body, content: undefined }, options) // emit: event_stream_end\n }\n catch (error) {\n serverCtx.emit(invokeReceiveEventError, { ...payload.body, content: error as any }, options) // emit: event_response with error\n }\n })\n}\n\nexport function toStreamHandler<Req, Res, EO extends { raw?: any } = any>(handler: (context: { payload: Req, options?: EO, emit: (data: Res) => void }) => Promise<void>): StreamHandler<Res, Req, EO> {\n return (payload, options) => {\n const values: Promise<[Res, boolean]>[] = []\n let resolve: (x: [Res, boolean]) => void\n let handlerError: Error | null = null\n\n values.push(new Promise((r) => {\n resolve = r\n }))\n\n const emit = (data: Res) => {\n resolve([data, false])\n values.push(new Promise((r) => {\n resolve = r\n }))\n }\n\n // Start the handler and mark completion when done\n handler({ payload, options, emit })\n .then(() => {\n resolve([undefined as any, true])\n })\n .catch((err) => {\n handlerError = err\n resolve([undefined as any, true])\n })\n\n return (async function* () {\n let val: Res\n for (let i = 0, done = false; !done; i++) {\n [val, done] = await values[i]\n delete values[i] // Clean up memory\n\n if (handlerError) {\n throw handlerError\n }\n\n if (!done) {\n yield val\n }\n }\n }())\n }\n}\n"],"mappings":";;;AAIA,IAAY,8DAAL;AACL;AACA;AACA;AACA;AACA;;;AAgCF,SAAgB,mBAAyE,KAAc;AACrG,KAAI,CAAC,IACH,OAAM,QAAQ;CAGhB,MAAM,YAAY;EAChB,GAAG,aAAw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tB,UAAO,KAAK,IAAI,SAAS,MAAM;AAC7B,cAAU;KACV,CAAC;;AAIL,UAAQ;GAAE;GAAS;GAAS;GAAM,CAAC,CAChC,WAAW;AACV,WAAQ,CAAC,QAAkB,KAAK,CAAC;IACjC,CACD,OAAO,QAAQ;AACd,kBAAe;AACf,WAAQ,CAAC,QAAkB,KAAK,CAAC;IACjC;AAEJ,SAAQ,mBAAmB;GACzB,IAAIC;AACJ,QAAK,IAAI,IAAI,GAAG,OAAO,OAAO,CAAC,MAAM,KAAK;AACxC,KAAC,KAAK,QAAQ,MAAM,OAAO;AAC3B,WAAO,OAAO;AAEd,QAAI,aACF,OAAM;AAGR,QAAI,CAAC,KACH,OAAM;;KAGT"}
|
package/package.json
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@moeru/eventa",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.3.0",
|
|
5
|
+
"description": "Events are all you need",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "RainbowBird",
|
|
8
|
+
"email": "rbxin2003@outlook.com",
|
|
9
|
+
"url": "https://github.com/luoling8192"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"homepage": "https://github.com/moeru-ai/eventa",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/moeru-ai/eventa.git"
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"type": "./dist/index.mts",
|
|
20
|
+
"import": "./dist/index.mjs",
|
|
21
|
+
"default": "./dist/index.mjs"
|
|
22
|
+
},
|
|
23
|
+
"./adapters/electron/main": {
|
|
24
|
+
"type": "./dist/adapters/electron/main.mts",
|
|
25
|
+
"import": "./dist/adapters/electron/main.mjs",
|
|
26
|
+
"default": "./dist/adapters/electron/main.mjs"
|
|
27
|
+
},
|
|
28
|
+
"./adapters/electron/renderer": {
|
|
29
|
+
"type": "./dist/adapters/electron/renderer.mts",
|
|
30
|
+
"import": "./dist/adapters/electron/renderer.mjs",
|
|
31
|
+
"default": "./dist/adapters/electron/renderer.mjs"
|
|
32
|
+
},
|
|
33
|
+
"./adapters/event-emitter": {
|
|
34
|
+
"type": "./dist/adapters/event-emitter/index.mts",
|
|
35
|
+
"import": "./dist/adapters/event-emitter/index.mjs",
|
|
36
|
+
"default": "./dist/adapters/event-emitter/index.mjs"
|
|
37
|
+
},
|
|
38
|
+
"./adapters/event-target": {
|
|
39
|
+
"type": "./dist/adapters/event-target/index.mts",
|
|
40
|
+
"import": "./dist/adapters/event-target/index.mjs",
|
|
41
|
+
"default": "./dist/adapters/event-target/index.mjs"
|
|
42
|
+
},
|
|
43
|
+
"./adapters/webworkers/worker": {
|
|
44
|
+
"type": "./dist/adapters/webworkers/worker/index.mts",
|
|
45
|
+
"import": "./dist/adapters/webworkers/worker/index.mjs",
|
|
46
|
+
"default": "./dist/adapters/webworkers/worker/index.mjs"
|
|
47
|
+
},
|
|
48
|
+
"./adapters/webworkers": {
|
|
49
|
+
"type": "./dist/adapters/webworkers/index.mts",
|
|
50
|
+
"import": "./dist/adapters/webworkers/index.mjs",
|
|
51
|
+
"default": "./dist/adapters/webworkers/index.mjs"
|
|
52
|
+
},
|
|
53
|
+
"./adapters/websocket/native": {
|
|
54
|
+
"type": "./dist/adapters/websocket/native/index.mts",
|
|
55
|
+
"import": "./dist/adapters/websocket/native/index.mjs",
|
|
56
|
+
"default": "./dist/adapters/websocket/native/index.mjs"
|
|
57
|
+
},
|
|
58
|
+
"./adapters/websocket/h3": {
|
|
59
|
+
"type": "./dist/adapters/websocket/h3/index.mts",
|
|
60
|
+
"import": "./dist/adapters/websocket/h3/index.mjs",
|
|
61
|
+
"default": "./dist/adapters/websocket/h3/index.mjs"
|
|
62
|
+
},
|
|
63
|
+
"./adapters/websocket": {
|
|
64
|
+
"type": "./dist/adapters/websocket/index.mts",
|
|
65
|
+
"import": "./dist/adapters/websocket/index.mjs",
|
|
66
|
+
"default": "./dist/adapters/websocket/index.mjs"
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"main": "./dist/index.mjs",
|
|
70
|
+
"module": "./dist/index.mjs",
|
|
71
|
+
"types": "./dist/index.mts",
|
|
72
|
+
"files": [
|
|
73
|
+
"README.md",
|
|
74
|
+
"dist",
|
|
75
|
+
"package.json"
|
|
76
|
+
],
|
|
77
|
+
"peerDependencies": {
|
|
78
|
+
"electron": ">=30",
|
|
79
|
+
"h3": "2.0.0-beta.1",
|
|
80
|
+
"web-worker": "^1.5.0"
|
|
81
|
+
},
|
|
82
|
+
"peerDependenciesMeta": {
|
|
83
|
+
"electron": {
|
|
84
|
+
"optional": true
|
|
85
|
+
},
|
|
86
|
+
"h3": {
|
|
87
|
+
"optional": true
|
|
88
|
+
},
|
|
89
|
+
"web-worker": {
|
|
90
|
+
"optional": true
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
"dependencies": {
|
|
94
|
+
"nanoid": "^5.1.6",
|
|
95
|
+
"picomatch": "^4.0.3"
|
|
96
|
+
},
|
|
97
|
+
"devDependencies": {
|
|
98
|
+
"@antfu/eslint-config": "^5.4.1",
|
|
99
|
+
"@electron-toolkit/preload": "^3.0.2",
|
|
100
|
+
"@types/node": "^24.6.2",
|
|
101
|
+
"@vitest/web-worker": "^3.2.4",
|
|
102
|
+
"bumpp": "^10.2.3",
|
|
103
|
+
"crossws": "^0.4.1",
|
|
104
|
+
"eslint": "^9.37.0",
|
|
105
|
+
"taze": "^19.7.0",
|
|
106
|
+
"tsdown": "^0.13.5",
|
|
107
|
+
"typescript": "^5.9.3",
|
|
108
|
+
"unplugin-unused": "^0.5.3",
|
|
109
|
+
"vite": "^7.1.9",
|
|
110
|
+
"vitest": "^3.2.4"
|
|
111
|
+
},
|
|
112
|
+
"scripts": {
|
|
113
|
+
"build": "tsdown",
|
|
114
|
+
"test": "vitest --coverage",
|
|
115
|
+
"test:run": "vitest run",
|
|
116
|
+
"lint": "eslint --cache .",
|
|
117
|
+
"lint:fix": "eslint --cache --fix .",
|
|
118
|
+
"typecheck": "tsc --noEmit",
|
|
119
|
+
"up": "taze -w -r -I -f && pnpm prune && pnpm dedupe"
|
|
120
|
+
}
|
|
121
|
+
}
|