@moeru/eventa 1.0.0-alpha.9 → 1.0.0-beta.2
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 +246 -1
- package/dist/adapters/broadcast-channel/index.d.mts +2 -2
- package/dist/adapters/broadcast-channel/index.mjs +2 -2
- package/dist/adapters/electron/main.d.mts +10 -3
- package/dist/adapters/electron/main.mjs +3 -3
- package/dist/adapters/electron/main.mjs.map +1 -1
- package/dist/adapters/electron/renderer.d.mts +2 -2
- package/dist/adapters/electron/renderer.mjs +3 -3
- package/dist/adapters/event-emitter/index.d.mts +2 -2
- package/dist/adapters/event-emitter/index.mjs +2 -2
- package/dist/adapters/event-target/index.d.mts +2 -2
- package/dist/adapters/event-target/index.mjs +2 -2
- package/dist/adapters/websocket/h3/index.d.mts +2 -2
- package/dist/adapters/websocket/h3/index.mjs +2 -2
- package/dist/adapters/websocket/h3/index.mjs.map +1 -1
- package/dist/adapters/websocket/index.d.mts +1 -1
- package/dist/adapters/websocket/native/index.d.mts +2 -2
- package/dist/adapters/websocket/native/index.mjs +2 -2
- package/dist/adapters/webworkers/index.d.mts +4 -43
- package/dist/adapters/webworkers/index.mjs +5 -4
- package/dist/adapters/webworkers/index.mjs.map +1 -1
- package/dist/adapters/webworkers/worker/index.d.mts +2 -1
- package/dist/adapters/webworkers/worker/index.mjs +4 -3
- package/dist/adapters/webworkers/worker/index.mjs.map +1 -1
- package/dist/adapters/worker-threads/index.d.mts +25 -0
- package/dist/adapters/worker-threads/index.mjs +43 -0
- package/dist/adapters/worker-threads/index.mjs.map +1 -0
- package/dist/adapters/worker-threads/worker/index.d.mts +26 -0
- package/dist/adapters/worker-threads/worker/index.mjs +46 -0
- package/dist/adapters/worker-threads/worker/index.mjs.map +1 -0
- package/dist/{context-BygZzwvo.mjs → context-BMDJMapI.mjs} +2 -2
- package/dist/context-BMDJMapI.mjs.map +1 -0
- package/dist/{context-C0RYgQg8.d.mts → context-ZVv99bcM.d.mts} +7 -4
- package/dist/{eventa-DWOtUOEf.d.mts → eventa-AJyw28P8.d.mts} +3 -2
- package/dist/index-CI_gUGXg.d.mts +522 -0
- package/dist/index.d.mts +4 -5
- package/dist/index.mjs +3 -3
- package/dist/{internal-C-bIJqJC.mjs → internal-ChLglF1N.mjs} +2 -2
- package/dist/{internal-C-bIJqJC.mjs.map → internal-ChLglF1N.mjs.map} +1 -1
- package/dist/{shared-BExRc0zC.mjs → shared-CA_i_yfR.mjs} +2 -2
- package/dist/{shared-BExRc0zC.mjs.map → shared-CA_i_yfR.mjs.map} +1 -1
- package/dist/{shared-DRAsaLuo.mjs → shared-CRxfs1TC.mjs} +4 -10
- package/dist/shared-CRxfs1TC.mjs.map +1 -0
- package/dist/{shared-Q10kRJA8.d.mts → shared-Cd4CLAdD.d.mts} +2 -2
- package/dist/shared-DgX1R_nY.d.mts +34 -0
- package/dist/src-eMqISeHo.mjs +1169 -0
- package/dist/src-eMqISeHo.mjs.map +1 -0
- package/package.json +19 -6
- package/dist/context-BygZzwvo.mjs.map +0 -1
- package/dist/index-DXQGU0bi.d.mts +0 -24
- package/dist/invoke-BB3tmZlr.d.mts +0 -137
- package/dist/shared-DRAsaLuo.mjs.map +0 -1
- package/dist/src-Bnf7MdlN.mjs +0 -284
- package/dist/src-Bnf7MdlN.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -23,6 +23,14 @@ ni @moeru/eventa
|
|
|
23
23
|
yarn add @moeru/eventa
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
+
### Agent Skills
|
|
27
|
+
|
|
28
|
+
Install the [eventa skill](https://skills.sh) to your AI coding agent:
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
npx skills add moeru-ai/eventa
|
|
32
|
+
```
|
|
33
|
+
|
|
26
34
|
## Getting Started
|
|
27
35
|
|
|
28
36
|
### Event
|
|
@@ -151,6 +159,90 @@ Eventa comes with various adapters for common use scenarios across browsers and
|
|
|
151
159
|
|
|
152
160
|
</details>
|
|
153
161
|
|
|
162
|
+
<details>
|
|
163
|
+
<summary>BroadcastChannel</summary>
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
import { defineEventa } from '@moeru/eventa'
|
|
167
|
+
import { createContext } from '@moeru/eventa/adapters/broadcast-channel'
|
|
168
|
+
|
|
169
|
+
const channel = new BroadcastChannel('eventa-demo')
|
|
170
|
+
const { context: ctx } = createContext(channel)
|
|
171
|
+
|
|
172
|
+
const ping = defineEventa<{ message: string }>('bc:ping')
|
|
173
|
+
ctx.on(ping, ({ body }) => {
|
|
174
|
+
console.log('received', body.message)
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
ctx.emit(ping, { message: 'Hello from BroadcastChannel' })
|
|
178
|
+
```
|
|
179
|
+
</details>
|
|
180
|
+
|
|
181
|
+
<details>
|
|
182
|
+
<summary>EventTarget</summary>
|
|
183
|
+
|
|
184
|
+
```ts
|
|
185
|
+
import { defineInvoke, defineInvokeEventa, defineInvokeHandler } from '@moeru/eventa'
|
|
186
|
+
import { createContext } from '@moeru/eventa/adapters/event-target'
|
|
187
|
+
|
|
188
|
+
const eventTarget = new EventTarget()
|
|
189
|
+
const { context: ctx } = createContext(eventTarget)
|
|
190
|
+
|
|
191
|
+
const echoEvents = defineInvokeEventa<{ output: string }, { input: string }>('et:echo')
|
|
192
|
+
defineInvokeHandler(ctx, echoEvents, ({ input }) => ({ output: input.toUpperCase() }))
|
|
193
|
+
|
|
194
|
+
const echo = defineInvoke(ctx, echoEvents)
|
|
195
|
+
console.log(await echo({ input: 'eventa' })) // => { output: 'EVENTA' }
|
|
196
|
+
```
|
|
197
|
+
</details>
|
|
198
|
+
|
|
199
|
+
<details>
|
|
200
|
+
<summary>EventEmitter (Node.js)</summary>
|
|
201
|
+
|
|
202
|
+
```ts
|
|
203
|
+
import { EventEmitter } from 'node:events'
|
|
204
|
+
|
|
205
|
+
import { defineEventa } from '@moeru/eventa'
|
|
206
|
+
import { createContext } from '@moeru/eventa/adapters/event-emitter'
|
|
207
|
+
|
|
208
|
+
const emitter = new EventEmitter()
|
|
209
|
+
const { context: ctx } = createContext(emitter)
|
|
210
|
+
|
|
211
|
+
const logEvent = defineEventa<{ message: string }>('emitter:log')
|
|
212
|
+
ctx.on(logEvent, ({ body }) => console.log(body.message))
|
|
213
|
+
ctx.emit(logEvent, { message: 'Hello from EventEmitter' })
|
|
214
|
+
```
|
|
215
|
+
</details>
|
|
216
|
+
|
|
217
|
+
<details>
|
|
218
|
+
<summary>Worker Threads (Node.js)</summary>
|
|
219
|
+
|
|
220
|
+
1. Main thread:
|
|
221
|
+
```ts
|
|
222
|
+
import { Worker } from 'node:worker_threads'
|
|
223
|
+
|
|
224
|
+
import { defineInvoke, defineInvokeEventa } from '@moeru/eventa'
|
|
225
|
+
import { createContext } from '@moeru/eventa/adapters/worker-threads'
|
|
226
|
+
|
|
227
|
+
const worker = new Worker(new URL('./worker.ts', import.meta.url), { type: 'module' })
|
|
228
|
+
const { context: mainCtx } = createContext(worker)
|
|
229
|
+
|
|
230
|
+
const helloEvents = defineInvokeEventa<{ output: string }, { input: string }>('node-worker-hello')
|
|
231
|
+
const hello = defineInvoke(mainCtx, helloEvents)
|
|
232
|
+
console.log(await hello({ input: 'Eventa' })) // => { output: 'Hello, Eventa' }
|
|
233
|
+
```
|
|
234
|
+
2. Worker entry:
|
|
235
|
+
```ts
|
|
236
|
+
import { defineInvokeEventa, defineInvokeHandler } from '@moeru/eventa'
|
|
237
|
+
import { createContext } from '@moeru/eventa/adapters/worker-threads/worker'
|
|
238
|
+
|
|
239
|
+
const helloEvents = defineInvokeEventa<{ output: string }, { input: string }>('node-worker-hello')
|
|
240
|
+
|
|
241
|
+
const { context: workerCtx } = createContext()
|
|
242
|
+
defineInvokeHandler(workerCtx, helloEvents, ({ input }) => ({ output: `Hello, ${input}` }))
|
|
243
|
+
```
|
|
244
|
+
</details>
|
|
245
|
+
|
|
154
246
|
<details>
|
|
155
247
|
<summary>WebSocket (Client)</summary>
|
|
156
248
|
|
|
@@ -231,6 +323,159 @@ for await (const update of sync({ jobId: 'import' })) {
|
|
|
231
323
|
|
|
232
324
|
Both generator-style and imperative handlers are exercised in `src/stream.spec.ts:7`.
|
|
233
325
|
|
|
326
|
+
#### Abort/Cancel
|
|
327
|
+
|
|
328
|
+
Eventa supports cancellation via `AbortSignal` on the client side and exposes an `AbortController` inside handlers so you can stop work early.
|
|
329
|
+
|
|
330
|
+
Client-side (unary invoke):
|
|
331
|
+
|
|
332
|
+
```ts
|
|
333
|
+
import { createContext, defineInvoke, defineInvokeEventa } from '@moeru/eventa'
|
|
334
|
+
|
|
335
|
+
const ctx = createContext()
|
|
336
|
+
const slowEvents = defineInvokeEventa<{ output: string }, { input: string }>('rpc:slow')
|
|
337
|
+
const slow = defineInvoke(ctx, slowEvents)
|
|
338
|
+
|
|
339
|
+
const controller = new AbortController()
|
|
340
|
+
const promise = slow({ input: 'work' }, { signal: controller.signal })
|
|
341
|
+
|
|
342
|
+
controller.abort('user cancelled')
|
|
343
|
+
await promise // rejects with AbortError
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
Server-side handler (unary):
|
|
347
|
+
|
|
348
|
+
```ts
|
|
349
|
+
import { defineInvokeHandler } from '@moeru/eventa'
|
|
350
|
+
|
|
351
|
+
defineInvokeHandler(ctx, slowEvents, async ({ input }, options) => {
|
|
352
|
+
const signal = options?.abortController?.signal
|
|
353
|
+
if (signal?.aborted) {
|
|
354
|
+
return { output: 'aborted' }
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
signal?.addEventListener('abort', () => {
|
|
358
|
+
// clean up resources, cancel timers, close connections, etc.
|
|
359
|
+
}, { once: true })
|
|
360
|
+
|
|
361
|
+
// ... do work
|
|
362
|
+
return { output: `done: ${input}` }
|
|
363
|
+
})
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
Client-side (stream invoke):
|
|
367
|
+
|
|
368
|
+
```ts
|
|
369
|
+
import { defineInvokeEventa, defineStreamInvoke } from '@moeru/eventa'
|
|
370
|
+
|
|
371
|
+
const streamEvents = defineInvokeEventa<{ type: 'progress' | 'done', value: number }, { jobId: string }>('rpc:stream')
|
|
372
|
+
const stream = defineStreamInvoke(ctx, streamEvents)
|
|
373
|
+
|
|
374
|
+
const controller = new AbortController()
|
|
375
|
+
const results = stream({ jobId: 'import' }, { signal: controller.signal })
|
|
376
|
+
|
|
377
|
+
setTimeout(() => controller.abort('timeout'), 1000)
|
|
378
|
+
for await (const msg of results) {
|
|
379
|
+
console.log(msg)
|
|
380
|
+
}
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
Server-side handler (streaming):
|
|
384
|
+
|
|
385
|
+
```ts
|
|
386
|
+
import { defineStreamInvokeHandler } from '@moeru/eventa'
|
|
387
|
+
|
|
388
|
+
defineStreamInvokeHandler(ctx, streamEvents, async function* ({ jobId }, options) {
|
|
389
|
+
const signal = options?.abortController?.signal
|
|
390
|
+
|
|
391
|
+
for (let i = 0; i <= 5; i++) {
|
|
392
|
+
if (signal?.aborted) {
|
|
393
|
+
return
|
|
394
|
+
}
|
|
395
|
+
yield { type: 'progress', value: i * 20 }
|
|
396
|
+
await new Promise(r => setTimeout(r, 200))
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
yield { type: 'done', value: 100 }
|
|
400
|
+
})
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
#### Streaming Input
|
|
404
|
+
|
|
405
|
+
Eventa supports stream inputs on unary invokes (client-streaming) and full bidirectional streaming. This mirrors the gRPC shapes:
|
|
406
|
+
|
|
407
|
+
```proto
|
|
408
|
+
// Client-streaming request -> unary response
|
|
409
|
+
rpc RecordRoute(stream Point) returns (RouteSummary) {}
|
|
410
|
+
|
|
411
|
+
// Bidirectional streaming request/response
|
|
412
|
+
rpc RouteChat(stream RouteNote) returns (stream RouteNote) {}
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
Client-streaming input with `defineInvoke` (stream in, single response out):
|
|
416
|
+
|
|
417
|
+
```ts
|
|
418
|
+
import { createContext, defineInvoke, defineInvokeEventa, defineInvokeHandler } from '@moeru/eventa'
|
|
419
|
+
|
|
420
|
+
const ctx = createContext()
|
|
421
|
+
|
|
422
|
+
const recordRoute = defineInvokeEventa<
|
|
423
|
+
{ distance: number, points: number },
|
|
424
|
+
ReadableStream<{ lat: number, lng: number }>
|
|
425
|
+
>('rpc:record-route')
|
|
426
|
+
|
|
427
|
+
defineInvokeHandler(ctx, recordRoute, async (stream) => {
|
|
428
|
+
let points = 0
|
|
429
|
+
for await (const _ of stream) {
|
|
430
|
+
points += 1
|
|
431
|
+
}
|
|
432
|
+
return { distance: points * 10, points }
|
|
433
|
+
})
|
|
434
|
+
|
|
435
|
+
const input = new ReadableStream({
|
|
436
|
+
start(controller) {
|
|
437
|
+
controller.enqueue({ lat: 0, lng: 0 })
|
|
438
|
+
controller.enqueue({ lat: 1, lng: 1 })
|
|
439
|
+
controller.close()
|
|
440
|
+
},
|
|
441
|
+
})
|
|
442
|
+
|
|
443
|
+
const invoke = defineInvoke(ctx, recordRoute)
|
|
444
|
+
console.log(await invoke(input))
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
Bidirectional streaming with `defineStreamInvoke` (stream in, stream out):
|
|
448
|
+
|
|
449
|
+
```ts
|
|
450
|
+
import { createContext, defineInvokeEventa, defineStreamInvoke, defineStreamInvokeHandler } from '@moeru/eventa'
|
|
451
|
+
|
|
452
|
+
const ctx = createContext()
|
|
453
|
+
|
|
454
|
+
const routeChat = defineInvokeEventa<
|
|
455
|
+
{ message: string },
|
|
456
|
+
ReadableStream<{ message: string }>
|
|
457
|
+
>('rpc:route-chat')
|
|
458
|
+
|
|
459
|
+
defineStreamInvokeHandler(ctx, routeChat, async function* (incoming) {
|
|
460
|
+
for await (const note of incoming) {
|
|
461
|
+
yield { message: `echo: ${note.message}` }
|
|
462
|
+
}
|
|
463
|
+
})
|
|
464
|
+
|
|
465
|
+
const outgoing = new ReadableStream({
|
|
466
|
+
start(controller) {
|
|
467
|
+
controller.enqueue({ message: 'hello' })
|
|
468
|
+
controller.enqueue({ message: 'from stream' })
|
|
469
|
+
controller.close()
|
|
470
|
+
},
|
|
471
|
+
})
|
|
472
|
+
|
|
473
|
+
const stream = defineStreamInvoke(ctx, routeChat)
|
|
474
|
+
for await (const note of stream(outgoing)) {
|
|
475
|
+
console.log(note.message)
|
|
476
|
+
}
|
|
477
|
+
```
|
|
478
|
+
|
|
234
479
|
#### Shorthands for `defineInvokeHandler` and `defineInvoke`
|
|
235
480
|
|
|
236
481
|
When you have multiple invoke events to register handlers for, or to create invoke functions for, you can use `defineInvokeHandlers` and `defineInvokes` to do so in bulk.
|
|
@@ -267,7 +512,7 @@ pnpm test
|
|
|
267
512
|
|
|
268
513
|
## Similar projects
|
|
269
514
|
|
|
270
|
-
- [`birpc`](https://github.com/antfu-collective/birpc): We dislike the way the API designs, we want fully free sharable invok-able functions
|
|
515
|
+
- [`birpc`](https://github.com/antfu-collective/birpc): We dislike the way the API designs, we want fully free sharable invok-able functions, streaming input, streaming output, etc.
|
|
271
516
|
- [`async-call-rpc`](https://github.com/Jack-Works/async-call-rpc): it only works with JSON-RPC, but the DX is similar
|
|
272
517
|
|
|
273
518
|
## License
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as EventTag, s as EventaType } from "../../eventa-
|
|
2
|
-
import { t as EventContext } from "../../context-
|
|
1
|
+
import { n as EventTag, s as EventaType } from "../../eventa-AJyw28P8.mjs";
|
|
2
|
+
import { t as EventContext } from "../../context-ZVv99bcM.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/adapters/broadcast-channel/shared.d.ts
|
|
5
5
|
interface Payload<T> {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as defineEventa, c as matchBy, i as and, l as nanoid, n as EventaFlowDirection, o as defineInboundEventa, s as defineOutboundEventa, t as createContext$1 } from "../../context-
|
|
2
|
-
import "../../src-
|
|
1
|
+
import { a as defineEventa, c as matchBy, i as and, l as nanoid, n as EventaFlowDirection, o as defineInboundEventa, s as defineOutboundEventa, t as createContext$1 } from "../../context-BMDJMapI.mjs";
|
|
2
|
+
import "../../src-eMqISeHo.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/adapters/broadcast-channel/internal.ts
|
|
5
5
|
function generatePayload(type, payload) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as EventContext } from "../../context-
|
|
2
|
-
import { n as errorEvent, t as Payload } from "../../shared-
|
|
1
|
+
import { t as EventContext } from "../../context-ZVv99bcM.mjs";
|
|
2
|
+
import { n as errorEvent, t as Payload } from "../../shared-Cd4CLAdD.mjs";
|
|
3
3
|
import { BrowserWindow, IpcMain, IpcMainEvent } from "electron";
|
|
4
4
|
|
|
5
5
|
//#region src/adapters/electron/main.d.ts
|
|
@@ -10,7 +10,14 @@ declare function createContext(ipcMain: IpcMain, window?: BrowserWindow, options
|
|
|
10
10
|
extraListeners?: Record<string, (_: any, event: Event) => void | Promise<void>>;
|
|
11
11
|
throwIfFailedToSend?: boolean;
|
|
12
12
|
}): {
|
|
13
|
-
context: EventContext<
|
|
13
|
+
context: EventContext<{
|
|
14
|
+
invokeRequest?: {
|
|
15
|
+
raw?: {
|
|
16
|
+
ipcMainEvent: IpcMainEvent;
|
|
17
|
+
event: Event | unknown;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
}, {
|
|
14
21
|
raw: {
|
|
15
22
|
ipcMainEvent: IpcMainEvent;
|
|
16
23
|
event: Event | unknown;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { c as matchBy, i as and, n as EventaFlowDirection, o as defineInboundEventa, s as defineOutboundEventa, t as createContext$1 } from "../../context-
|
|
2
|
-
import "../../src-
|
|
3
|
-
import { n as generatePayload, r as parsePayload, t as errorEvent } from "../../shared-
|
|
1
|
+
import { c as matchBy, i as and, n as EventaFlowDirection, o as defineInboundEventa, s as defineOutboundEventa, t as createContext$1 } from "../../context-BMDJMapI.mjs";
|
|
2
|
+
import "../../src-eMqISeHo.mjs";
|
|
3
|
+
import { n as generatePayload, r as parsePayload, t as errorEvent } from "../../shared-CA_i_yfR.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/adapters/electron/main.ts
|
|
6
6
|
function withRemoval(ipcMain, type, listener) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.mjs","names":["createBaseContext","cleanupRemoval: Array<{ remove: () => void }>","options"],"sources":["../../../src/adapters/electron/main.ts"],"sourcesContent":["import type { BrowserWindow, IpcMain, IpcMainEvent } from 'electron'\n\nimport type { EventContext } from '../../context'\nimport type { DirectionalEventa, Eventa } from '../../eventa'\n\nimport { createContext as createBaseContext } from '../../context'\nimport { and, defineInboundEventa, defineOutboundEventa, EventaFlowDirection, matchBy } from '../../eventa'\nimport { generatePayload, parsePayload } from './internal'\nimport { errorEvent } from './shared'\n\nfunction withRemoval(ipcMain: IpcMain, type: string, listener: Parameters<IpcMain['on']>[1]) {\n ipcMain.on(type, listener)\n\n return {\n remove: () => {\n ipcMain.off(type, listener)\n },\n }\n}\n\nexport function createContext(ipcMain: IpcMain, window?: BrowserWindow, options?: {\n onlySameWindow?: boolean\n messageEventName?: string | false\n errorEventName?: string | false\n extraListeners?: Record<string, (_, event: Event) => void | Promise<void>>\n throwIfFailedToSend?: boolean\n}) {\n const ctx = createBaseContext() as EventContext
|
|
1
|
+
{"version":3,"file":"main.mjs","names":["createBaseContext","cleanupRemoval: Array<{ remove: () => void }>","options"],"sources":["../../../src/adapters/electron/main.ts"],"sourcesContent":["import type { BrowserWindow, IpcMain, IpcMainEvent } from 'electron'\n\nimport type { EventContext } from '../../context'\nimport type { DirectionalEventa, Eventa } from '../../eventa'\n\nimport { createContext as createBaseContext } from '../../context'\nimport { and, defineInboundEventa, defineOutboundEventa, EventaFlowDirection, matchBy } from '../../eventa'\nimport { generatePayload, parsePayload } from './internal'\nimport { errorEvent } from './shared'\n\nfunction withRemoval(ipcMain: IpcMain, type: string, listener: Parameters<IpcMain['on']>[1]) {\n ipcMain.on(type, listener)\n\n return {\n remove: () => {\n ipcMain.off(type, listener)\n },\n }\n}\n\nexport function createContext(ipcMain: IpcMain, window?: BrowserWindow, options?: {\n onlySameWindow?: boolean\n messageEventName?: string | false\n errorEventName?: string | false\n extraListeners?: Record<string, (_, event: Event) => void | Promise<void>>\n throwIfFailedToSend?: boolean\n}) {\n const ctx = createBaseContext() as EventContext<\n { invokeRequest?: { raw?: { ipcMainEvent: IpcMainEvent, event: Event | unknown } } },\n { raw: { ipcMainEvent: IpcMainEvent, event: Event | unknown } }\n >\n\n const {\n messageEventName = 'eventa-message',\n errorEventName = 'eventa-error',\n extraListeners = {},\n onlySameWindow = false,\n } = options || {}\n\n const cleanupRemoval: Array<{ remove: () => void }> = []\n\n ctx.on(and(\n matchBy('*'),\n matchBy((e: DirectionalEventa<any>) => e._flowDirection === EventaFlowDirection.Outbound || !e._flowDirection),\n ), (event, options) => {\n const eventBody = generatePayload(event.id, { ...defineOutboundEventa(event.type), ...event })\n if (messageEventName !== false) {\n try {\n if (window != null) {\n if (window.isDestroyed()) {\n return\n }\n\n if (onlySameWindow) {\n if (window.webContents.id === options?.raw.ipcMainEvent.sender.id) {\n window?.webContents?.send(messageEventName, eventBody)\n }\n }\n else {\n window?.webContents?.send(messageEventName, eventBody)\n }\n }\n else {\n if (options?.raw.ipcMainEvent.sender.isDestroyed()) {\n return\n }\n\n options?.raw.ipcMainEvent.sender.send(messageEventName, eventBody)\n }\n }\n catch (error) {\n // NOTICE: Electron may throw if the window is closed before sending\n // ignore the error if it's about destroyed object\n if (!(error instanceof Error) || error?.message !== 'Object has been destroyed') {\n throw error\n }\n }\n }\n })\n\n if (messageEventName) {\n cleanupRemoval.push(withRemoval(ipcMain, messageEventName, (ipcMainEvent, event: Event | unknown) => {\n try {\n const { type, payload } = parsePayload<Eventa<any>>(event)\n ctx.emit(defineInboundEventa(type), payload.body, { raw: { ipcMainEvent, event } })\n }\n catch (error) {\n console.error('Failed to parse IpcMain message:', error)\n ctx.emit(errorEvent, { error }, { raw: { ipcMainEvent, event } })\n }\n }))\n }\n\n if (errorEventName) {\n cleanupRemoval.push(withRemoval(ipcMain, errorEventName, (ipcMainEvent, error: Event | unknown) => {\n ctx.emit(errorEvent, { error }, { raw: { ipcMainEvent, event: error } })\n }))\n }\n\n for (const [eventName, listener] of Object.entries(extraListeners)) {\n cleanupRemoval.push(withRemoval(ipcMain, eventName, listener))\n }\n\n return {\n context: ctx,\n dispose: () => {\n cleanupRemoval.forEach(removal => removal.remove())\n },\n }\n}\n\nexport type * from './shared'\n"],"mappings":";;;;;AAUA,SAAS,YAAY,SAAkB,MAAc,UAAwC;AAC3F,SAAQ,GAAG,MAAM,SAAS;AAE1B,QAAO,EACL,cAAc;AACZ,UAAQ,IAAI,MAAM,SAAS;IAE9B;;AAGH,SAAgB,cAAc,SAAkB,QAAwB,SAMrE;CACD,MAAM,MAAMA,iBAAmB;CAK/B,MAAM,EACJ,mBAAmB,kBACnB,iBAAiB,gBACjB,iBAAiB,EAAE,EACnB,iBAAiB,UACf,WAAW,EAAE;CAEjB,MAAMC,iBAAgD,EAAE;AAExD,KAAI,GAAG,IACL,QAAQ,IAAI,EACZ,SAAS,MAA8B,EAAE,mBAAmB,oBAAoB,YAAY,CAAC,EAAE,eAAe,CAC/G,GAAG,OAAO,cAAY;EACrB,MAAM,YAAY,gBAAgB,MAAM,IAAI;GAAE,GAAG,qBAAqB,MAAM,KAAK;GAAE,GAAG;GAAO,CAAC;AAC9F,MAAI,qBAAqB,MACvB,KAAI;AACF,OAAI,UAAU,MAAM;AAClB,QAAI,OAAO,aAAa,CACtB;AAGF,QAAI,gBACF;SAAI,OAAO,YAAY,OAAOC,WAAS,IAAI,aAAa,OAAO,GAC7D,SAAQ,aAAa,KAAK,kBAAkB,UAAU;UAIxD,SAAQ,aAAa,KAAK,kBAAkB,UAAU;UAGrD;AACH,QAAIA,WAAS,IAAI,aAAa,OAAO,aAAa,CAChD;AAGF,eAAS,IAAI,aAAa,OAAO,KAAK,kBAAkB,UAAU;;WAG/D,OAAO;AAGZ,OAAI,EAAE,iBAAiB,UAAU,OAAO,YAAY,4BAClD,OAAM;;GAIZ;AAEF,KAAI,iBACF,gBAAe,KAAK,YAAY,SAAS,mBAAmB,cAAc,UAA2B;AACnG,MAAI;GACF,MAAM,EAAE,MAAM,YAAY,aAA0B,MAAM;AAC1D,OAAI,KAAK,oBAAoB,KAAK,EAAE,QAAQ,MAAM,EAAE,KAAK;IAAE;IAAc;IAAO,EAAE,CAAC;WAE9E,OAAO;AACZ,WAAQ,MAAM,oCAAoC,MAAM;AACxD,OAAI,KAAK,YAAY,EAAE,OAAO,EAAE,EAAE,KAAK;IAAE;IAAc;IAAO,EAAE,CAAC;;GAEnE,CAAC;AAGL,KAAI,eACF,gBAAe,KAAK,YAAY,SAAS,iBAAiB,cAAc,UAA2B;AACjG,MAAI,KAAK,YAAY,EAAE,OAAO,EAAE,EAAE,KAAK;GAAE;GAAc,OAAO;GAAO,EAAE,CAAC;GACxE,CAAC;AAGL,MAAK,MAAM,CAAC,WAAW,aAAa,OAAO,QAAQ,eAAe,CAChE,gBAAe,KAAK,YAAY,SAAS,WAAW,SAAS,CAAC;AAGhE,QAAO;EACL,SAAS;EACT,eAAe;AACb,kBAAe,SAAQ,YAAW,QAAQ,QAAQ,CAAC;;EAEtD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as EventContext } from "../../context-
|
|
2
|
-
import { n as errorEvent, t as Payload } from "../../shared-
|
|
1
|
+
import { t as EventContext } from "../../context-ZVv99bcM.mjs";
|
|
2
|
+
import { n as errorEvent, t as Payload } from "../../shared-Cd4CLAdD.mjs";
|
|
3
3
|
import { IpcRenderer, IpcRendererListener } from "@electron-toolkit/preload";
|
|
4
4
|
|
|
5
5
|
//#region src/adapters/electron/renderer.d.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { c as matchBy, i as and, n as EventaFlowDirection, o as defineInboundEventa, s as defineOutboundEventa, t as createContext$1 } from "../../context-
|
|
2
|
-
import "../../src-
|
|
3
|
-
import { n as generatePayload, r as parsePayload, t as errorEvent } from "../../shared-
|
|
1
|
+
import { c as matchBy, i as and, n as EventaFlowDirection, o as defineInboundEventa, s as defineOutboundEventa, t as createContext$1 } from "../../context-BMDJMapI.mjs";
|
|
2
|
+
import "../../src-eMqISeHo.mjs";
|
|
3
|
+
import { n as generatePayload, r as parsePayload, t as errorEvent } from "../../shared-CA_i_yfR.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/adapters/electron/renderer.ts
|
|
6
6
|
function createContext(ipcRenderer, options) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as EventTag, s as EventaType } from "../../eventa-
|
|
2
|
-
import { t as EventContext } from "../../context-
|
|
1
|
+
import { n as EventTag, s as EventaType } from "../../eventa-AJyw28P8.mjs";
|
|
2
|
+
import { t as EventContext } from "../../context-ZVv99bcM.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/adapters/event-emitter/shared.d.ts
|
|
5
5
|
interface Payload<T> {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as defineEventa, c as matchBy, i as and, l as nanoid, n as EventaFlowDirection, o as defineInboundEventa, s as defineOutboundEventa, t as createContext$1 } from "../../context-
|
|
2
|
-
import "../../src-
|
|
1
|
+
import { a as defineEventa, c as matchBy, i as and, l as nanoid, n as EventaFlowDirection, o as defineInboundEventa, s as defineOutboundEventa, t as createContext$1 } from "../../context-BMDJMapI.mjs";
|
|
2
|
+
import "../../src-eMqISeHo.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/adapters/event-emitter/internal.ts
|
|
5
5
|
function generatePayload(type, payload) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as EventTag, s as EventaType } from "../../eventa-
|
|
2
|
-
import { t as EventContext } from "../../context-
|
|
1
|
+
import { n as EventTag, s as EventaType } from "../../eventa-AJyw28P8.mjs";
|
|
2
|
+
import { t as EventContext } from "../../context-ZVv99bcM.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/adapters/event-target/shared.d.ts
|
|
5
5
|
interface CustomEventDetail<T> {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as defineEventa, c as matchBy, i as and, l as nanoid, n as EventaFlowDirection, o as defineInboundEventa, r as EventaType, s as defineOutboundEventa, t as createContext$1 } from "../../context-
|
|
2
|
-
import "../../src-
|
|
1
|
+
import { a as defineEventa, c as matchBy, i as and, l as nanoid, n as EventaFlowDirection, o as defineInboundEventa, r as EventaType, s as defineOutboundEventa, t as createContext$1 } from "../../context-BMDJMapI.mjs";
|
|
2
|
+
import "../../src-eMqISeHo.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/adapters/event-target/internal.ts
|
|
5
5
|
function generateCustomEventDetail(type, payload) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as Eventa } from "../../../eventa-
|
|
2
|
-
import { t as EventContext } from "../../../context-
|
|
1
|
+
import { r as Eventa } from "../../../eventa-AJyw28P8.mjs";
|
|
2
|
+
import { t as EventContext } from "../../../context-ZVv99bcM.mjs";
|
|
3
3
|
import { Hooks, Message, Peer, WSError } from "crossws";
|
|
4
4
|
|
|
5
5
|
//#region src/adapters/websocket/h3/global.d.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as defineEventa, c as matchBy, i as and, n as EventaFlowDirection, o as defineInboundEventa, s as defineOutboundEventa, t as createContext } from "../../../context-
|
|
2
|
-
import { n as parseWebsocketPayload, t as generateWebsocketPayload } from "../../../internal-
|
|
1
|
+
import { a as defineEventa, c as matchBy, i as and, n as EventaFlowDirection, o as defineInboundEventa, s as defineOutboundEventa, t as createContext } from "../../../context-BMDJMapI.mjs";
|
|
2
|
+
import { n as parseWebsocketPayload, t as generateWebsocketPayload } from "../../../internal-ChLglF1N.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/adapters/websocket/h3/global.ts
|
|
5
5
|
const wsConnectedEvent = defineEventa("eventa:adapters:websocket-global:connected");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["createBaseContext","wsConnectedEvent","wsDisconnectedEvent","wsErrorEvent","createBaseContext","peer","resolve: (value: PeerContext) => void","message: Hooks['message'] | undefined"],"sources":["../../../../src/adapters/websocket/h3/global.ts","../../../../src/adapters/websocket/h3/peer.ts"],"sourcesContent":["import type { Hooks, Message, Peer, WSError } from 'crossws'\n\nimport type { EventContext } from '../../../context'\nimport type { DirectionalEventa, Eventa } from '../../../eventa'\n\nimport { createContext as createBaseContext } from '../../../context'\nimport { and, defineEventa, defineInboundEventa, defineOutboundEventa, EventaFlowDirection, matchBy } from '../../../eventa'\nimport { generateWebsocketPayload, parseWebsocketPayload } from '../internal'\n\nexport const wsConnectedEvent = defineEventa<{ id: string }>('eventa:adapters:websocket-global:connected')\nexport const wsDisconnectedEvent = defineEventa<{ id: string }>('eventa:adapters:websocket-global:disconnected')\nexport const wsErrorEvent = defineEventa<{ error: unknown }>('eventa:adapters:websocket-global:error')\n\nexport function createGlobalContext(): {\n websocketHandlers: Omit<Hooks, 'upgrade'>\n context: EventContext<any, { raw: { error?: WSError, message?: Message } }>\n} {\n const ctx = createBaseContext()\n const peers = new Set<Peer>()\n\n ctx.on(and(\n matchBy((e: DirectionalEventa<any>) => e._flowDirection === EventaFlowDirection.Outbound || !e._flowDirection),\n matchBy('*'),\n ), (event) => {\n const data = JSON.stringify(generateWebsocketPayload(event.id, { ...defineOutboundEventa(event.type), ...event }))\n for (const peer of peers) {\n peer.send(data)\n }\n })\n\n return {\n websocketHandlers: {\n open(peer) {\n peers.add(peer)\n ctx.emit(wsConnectedEvent, { id: peer.id }, { raw: { } })\n },\n\n close(peer) {\n peers.delete(peer)\n ctx.emit(wsDisconnectedEvent, { id: peer.id }, { raw: { } })\n },\n\n error(_, error) {\n console.error('WebSocket error:', error)\n ctx.emit(wsErrorEvent, { error }, { raw: { error } })\n },\n\n async message(_, message) {\n try {\n const { type, payload } = parseWebsocketPayload<Eventa<any>>(message.text())\n ctx.emit(defineInboundEventa(type), payload.body, { raw: { message } })\n }\n catch (error) {\n console.error('Failed to parse WebSocket message:', error)\n ctx.emit(wsErrorEvent, { error }, { raw: { message } })\n }\n },\n },\n context: ctx,\n }\n}\n","import type { Hooks, Message, Peer } from 'crossws'\n\nimport type { EventContext } from '../../../context'\nimport type { DirectionalEventa, Eventa } from '../../../eventa'\n\nimport { createContext as createBaseContext } from '../../../context'\nimport { and, defineEventa, defineInboundEventa, defineOutboundEventa, EventaFlowDirection, matchBy } from '../../../eventa'\nimport { generateWebsocketPayload, parseWebsocketPayload } from '../internal'\n\nexport const wsConnectedEvent = defineEventa<{ id: string }>('eventa:adapters:websocket-peer:connected')\nexport const wsDisconnectedEvent = defineEventa<{ id: string }>('eventa:adapters:websocket-peer:disconnected')\nexport const wsErrorEvent = defineEventa<{ error: unknown }>('eventa:adapters:websocket-peer:error')\n\nexport function createPeerContext(peer: Peer): {\n hooks: Pick<Hooks, 'message'>\n context: EventContext<any, { raw: { message: Message } }>\n} {\n const peerId = peer.id\n const ctx = createBaseContext()\n\n ctx.on(and(\n matchBy((e: DirectionalEventa<any>) => e._flowDirection === EventaFlowDirection.Outbound || !e._flowDirection),\n matchBy('*'),\n ), (event) => {\n const data = JSON.stringify(generateWebsocketPayload(event.id, { ...defineOutboundEventa(event.type), ...event }))\n peer.send(data)\n })\n\n return {\n hooks: {\n message(peer, message) {\n if (peer.id === peerId) {\n try {\n const { type, payload } = parseWebsocketPayload<Eventa<any>>(message.text())\n ctx.emit(defineInboundEventa(type), payload.body, { raw: { message } })\n }\n catch (error) {\n console.error('Failed to parse WebSocket message:', error)\n ctx.emit(wsErrorEvent, { error }, { raw: { message } })\n }\n }\n },\n },\n context: ctx,\n }\n}\n\nexport interface PeerContext { peer: Peer, context: EventContext<any, { raw: { message: Message } }> }\n\nexport function createPeerHooks(): { hooks: Partial<Hooks>, untilLeastOneConnected: Promise<PeerContext> } {\n let resolve: (value: PeerContext) => void\n const untilLeastOneConnected = new Promise<PeerContext>((r) => {\n resolve = r\n })\n\n let message: Hooks['message'] | undefined\n\n const hooks: Pick<Hooks, 'open' | 'message'> = {\n open: (peer) => {\n const { context, hooks } = createPeerContext(peer)\n message = hooks.message\n resolve({ peer, context })\n },\n message: (peer, msg) => {\n if (message != null) {\n message(peer, msg)\n }\n },\n }\n\n return { hooks, untilLeastOneConnected }\n}\n"],"mappings":";;;;AASA,MAAa,mBAAmB,aAA6B,6CAA6C;AAC1G,MAAa,sBAAsB,aAA6B,gDAAgD;AAChH,MAAa,eAAe,aAAiC,yCAAyC;AAEtG,SAAgB,sBAGd;CACA,MAAM,MAAMA,
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["createBaseContext","wsConnectedEvent","wsDisconnectedEvent","wsErrorEvent","createBaseContext","peer","resolve: (value: PeerContext) => void","message: Hooks['message'] | undefined"],"sources":["../../../../src/adapters/websocket/h3/global.ts","../../../../src/adapters/websocket/h3/peer.ts"],"sourcesContent":["import type { Hooks, Message, Peer, WSError } from 'crossws'\n\nimport type { EventContext } from '../../../context'\nimport type { DirectionalEventa, Eventa } from '../../../eventa'\n\nimport { createContext as createBaseContext } from '../../../context'\nimport { and, defineEventa, defineInboundEventa, defineOutboundEventa, EventaFlowDirection, matchBy } from '../../../eventa'\nimport { generateWebsocketPayload, parseWebsocketPayload } from '../internal'\n\nexport const wsConnectedEvent = defineEventa<{ id: string }>('eventa:adapters:websocket-global:connected')\nexport const wsDisconnectedEvent = defineEventa<{ id: string }>('eventa:adapters:websocket-global:disconnected')\nexport const wsErrorEvent = defineEventa<{ error: unknown }>('eventa:adapters:websocket-global:error')\n\nexport function createGlobalContext(): {\n websocketHandlers: Omit<Hooks, 'upgrade'>\n context: EventContext<any, { raw: { error?: WSError, message?: Message } }>\n} {\n const ctx = createBaseContext<any, { raw: { error?: WSError, message?: Message } }>()\n const peers = new Set<Peer>()\n\n ctx.on(and(\n matchBy((e: DirectionalEventa<any>) => e._flowDirection === EventaFlowDirection.Outbound || !e._flowDirection),\n matchBy('*'),\n ), (event) => {\n const data = JSON.stringify(generateWebsocketPayload(event.id, { ...defineOutboundEventa(event.type), ...event }))\n for (const peer of peers) {\n peer.send(data)\n }\n })\n\n return {\n websocketHandlers: {\n open(peer) {\n peers.add(peer)\n ctx.emit(wsConnectedEvent, { id: peer.id }, { raw: { } })\n },\n\n close(peer) {\n peers.delete(peer)\n ctx.emit(wsDisconnectedEvent, { id: peer.id }, { raw: { } })\n },\n\n error(_, error) {\n console.error('WebSocket error:', error)\n ctx.emit(wsErrorEvent, { error }, { raw: { error } })\n },\n\n async message(_, message) {\n try {\n const { type, payload } = parseWebsocketPayload<Eventa<any>>(message.text())\n ctx.emit(defineInboundEventa(type), payload.body, { raw: { message } })\n }\n catch (error) {\n console.error('Failed to parse WebSocket message:', error)\n ctx.emit(wsErrorEvent, { error }, { raw: { message } })\n }\n },\n },\n context: ctx,\n }\n}\n","import type { Hooks, Message, Peer } from 'crossws'\n\nimport type { EventContext } from '../../../context'\nimport type { DirectionalEventa, Eventa } from '../../../eventa'\n\nimport { createContext as createBaseContext } from '../../../context'\nimport { and, defineEventa, defineInboundEventa, defineOutboundEventa, EventaFlowDirection, matchBy } from '../../../eventa'\nimport { generateWebsocketPayload, parseWebsocketPayload } from '../internal'\n\nexport const wsConnectedEvent = defineEventa<{ id: string }>('eventa:adapters:websocket-peer:connected')\nexport const wsDisconnectedEvent = defineEventa<{ id: string }>('eventa:adapters:websocket-peer:disconnected')\nexport const wsErrorEvent = defineEventa<{ error: unknown }>('eventa:adapters:websocket-peer:error')\n\nexport function createPeerContext(peer: Peer): {\n hooks: Pick<Hooks, 'message'>\n context: EventContext<any, { raw: { message: Message } }>\n} {\n const peerId = peer.id\n const ctx = createBaseContext<any, { raw: { message: Message } }>()\n\n ctx.on(and(\n matchBy((e: DirectionalEventa<any>) => e._flowDirection === EventaFlowDirection.Outbound || !e._flowDirection),\n matchBy('*'),\n ), (event) => {\n const data = JSON.stringify(generateWebsocketPayload(event.id, { ...defineOutboundEventa(event.type), ...event }))\n peer.send(data)\n })\n\n return {\n hooks: {\n message(peer, message) {\n if (peer.id === peerId) {\n try {\n const { type, payload } = parseWebsocketPayload<Eventa<any>>(message.text())\n ctx.emit(defineInboundEventa(type), payload.body, { raw: { message } })\n }\n catch (error) {\n console.error('Failed to parse WebSocket message:', error)\n ctx.emit(wsErrorEvent, { error }, { raw: { message } })\n }\n }\n },\n },\n context: ctx,\n }\n}\n\nexport interface PeerContext { peer: Peer, context: EventContext<any, { raw: { message: Message } }> }\n\nexport function createPeerHooks(): { hooks: Partial<Hooks>, untilLeastOneConnected: Promise<PeerContext> } {\n let resolve: (value: PeerContext) => void\n const untilLeastOneConnected = new Promise<PeerContext>((r) => {\n resolve = r\n })\n\n let message: Hooks['message'] | undefined\n\n const hooks: Pick<Hooks, 'open' | 'message'> = {\n open: (peer) => {\n const { context, hooks } = createPeerContext(peer)\n message = hooks.message\n resolve({ peer, context })\n },\n message: (peer, msg) => {\n if (message != null) {\n message(peer, msg)\n }\n },\n }\n\n return { hooks, untilLeastOneConnected }\n}\n"],"mappings":";;;;AASA,MAAa,mBAAmB,aAA6B,6CAA6C;AAC1G,MAAa,sBAAsB,aAA6B,gDAAgD;AAChH,MAAa,eAAe,aAAiC,yCAAyC;AAEtG,SAAgB,sBAGd;CACA,MAAM,MAAMA,eAAyE;CACrF,MAAM,wBAAQ,IAAI,KAAW;AAE7B,KAAI,GAAG,IACL,SAAS,MAA8B,EAAE,mBAAmB,oBAAoB,YAAY,CAAC,EAAE,eAAe,EAC9G,QAAQ,IAAI,CACb,GAAG,UAAU;EACZ,MAAM,OAAO,KAAK,UAAU,yBAAyB,MAAM,IAAI;GAAE,GAAG,qBAAqB,MAAM,KAAK;GAAE,GAAG;GAAO,CAAC,CAAC;AAClH,OAAK,MAAM,QAAQ,MACjB,MAAK,KAAK,KAAK;GAEjB;AAEF,QAAO;EACL,mBAAmB;GACjB,KAAK,MAAM;AACT,UAAM,IAAI,KAAK;AACf,QAAI,KAAK,kBAAkB,EAAE,IAAI,KAAK,IAAI,EAAE,EAAE,KAAK,EAAG,EAAE,CAAC;;GAG3D,MAAM,MAAM;AACV,UAAM,OAAO,KAAK;AAClB,QAAI,KAAK,qBAAqB,EAAE,IAAI,KAAK,IAAI,EAAE,EAAE,KAAK,EAAG,EAAE,CAAC;;GAG9D,MAAM,GAAG,OAAO;AACd,YAAQ,MAAM,oBAAoB,MAAM;AACxC,QAAI,KAAK,cAAc,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;;GAGvD,MAAM,QAAQ,GAAG,SAAS;AACxB,QAAI;KACF,MAAM,EAAE,MAAM,YAAY,sBAAmC,QAAQ,MAAM,CAAC;AAC5E,SAAI,KAAK,oBAAoB,KAAK,EAAE,QAAQ,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;aAElE,OAAO;AACZ,aAAQ,MAAM,sCAAsC,MAAM;AAC1D,SAAI,KAAK,cAAc,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;;;GAG5D;EACD,SAAS;EACV;;;;;AClDH,MAAaC,qBAAmB,aAA6B,2CAA2C;AACxG,MAAaC,wBAAsB,aAA6B,8CAA8C;AAC9G,MAAaC,iBAAe,aAAiC,uCAAuC;AAEpG,SAAgB,kBAAkB,MAGhC;CACA,MAAM,SAAS,KAAK;CACpB,MAAM,MAAMC,eAAuD;AAEnE,KAAI,GAAG,IACL,SAAS,MAA8B,EAAE,mBAAmB,oBAAoB,YAAY,CAAC,EAAE,eAAe,EAC9G,QAAQ,IAAI,CACb,GAAG,UAAU;EACZ,MAAM,OAAO,KAAK,UAAU,yBAAyB,MAAM,IAAI;GAAE,GAAG,qBAAqB,MAAM,KAAK;GAAE,GAAG;GAAO,CAAC,CAAC;AAClH,OAAK,KAAK,KAAK;GACf;AAEF,QAAO;EACL,OAAO,EACL,QAAQ,QAAM,SAAS;AACrB,OAAIC,OAAK,OAAO,OACd,KAAI;IACF,MAAM,EAAE,MAAM,YAAY,sBAAmC,QAAQ,MAAM,CAAC;AAC5E,QAAI,KAAK,oBAAoB,KAAK,EAAE,QAAQ,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;YAElE,OAAO;AACZ,YAAQ,MAAM,sCAAsC,MAAM;AAC1D,QAAI,KAAKF,gBAAc,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;;KAI9D;EACD,SAAS;EACV;;AAKH,SAAgB,kBAA2F;CACzG,IAAIG;CACJ,MAAM,yBAAyB,IAAI,SAAsB,MAAM;AAC7D,YAAU;GACV;CAEF,IAAIC;AAeJ,QAAO;EAAE,OAbsC;GAC7C,OAAO,SAAS;IACd,MAAM,EAAE,SAAS,UAAU,kBAAkB,KAAK;AAClD,cAAU,MAAM;AAChB,YAAQ;KAAE;KAAM;KAAS,CAAC;;GAE5B,UAAU,MAAM,QAAQ;AACtB,QAAI,WAAW,KACb,SAAQ,MAAM,IAAI;;GAGvB;EAEe;EAAwB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as Eventa } from "../../../eventa-
|
|
2
|
-
import { t as EventContext } from "../../../context-
|
|
1
|
+
import { r as Eventa } from "../../../eventa-AJyw28P8.mjs";
|
|
2
|
+
import { t as EventContext } from "../../../context-ZVv99bcM.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/adapters/websocket/native/index.d.ts
|
|
5
5
|
declare const wsConnectedEvent: Eventa<{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as defineEventa, c as matchBy, i as and, n as EventaFlowDirection, o as defineInboundEventa, s as defineOutboundEventa, t as createContext$1 } from "../../../context-
|
|
2
|
-
import { n as parseWebsocketPayload, t as generateWebsocketPayload } from "../../../internal-
|
|
1
|
+
import { a as defineEventa, c as matchBy, i as and, n as EventaFlowDirection, o as defineInboundEventa, s as defineOutboundEventa, t as createContext$1 } from "../../../context-BMDJMapI.mjs";
|
|
2
|
+
import { n as parseWebsocketPayload, t as generateWebsocketPayload } from "../../../internal-ChLglF1N.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/adapters/websocket/native/index.ts
|
|
5
5
|
const wsConnectedEvent = defineEventa();
|
|
@@ -1,46 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as
|
|
3
|
-
import { t as ExtendableInvokeResponse } from "../../invoke-BB3tmZlr.mjs";
|
|
1
|
+
import { t as EventContext } from "../../context-ZVv99bcM.mjs";
|
|
2
|
+
import { a as isWorkerEventa, c as workerMessageErrorEvent, i as defineWorkerEventa, n as WorkerPayload, o as normalizeOnListenerParameters, r as defineOutboundWorkerEventa, s as workerErrorEvent, t as WorkerEventa } from "../../shared-DgX1R_nY.mjs";
|
|
4
3
|
|
|
5
|
-
//#region src/adapters/webworkers/shared.d.ts
|
|
6
|
-
interface WorkerPayload<T> {
|
|
7
|
-
id: string;
|
|
8
|
-
type: EventTag<any, any>;
|
|
9
|
-
payload: T;
|
|
10
|
-
transfer?: Transferable[];
|
|
11
|
-
}
|
|
12
|
-
interface WorkerEventa<T> extends Eventa<{
|
|
13
|
-
message: T;
|
|
14
|
-
transfer?: Transferable[];
|
|
15
|
-
}> {
|
|
16
|
-
_workerTransfer: true;
|
|
17
|
-
}
|
|
18
|
-
declare function defineWorkerEventa<T>(id?: string): WorkerEventa<T>;
|
|
19
|
-
declare function defineOutboundWorkerEventa<T>(id?: string): WorkerEventa<T>;
|
|
20
|
-
declare function isWorkerEventa(event: Eventa<any>): event is WorkerEventa<any>;
|
|
21
|
-
declare const workerErrorEvent: Eventa<{
|
|
22
|
-
error: unknown;
|
|
23
|
-
}>;
|
|
24
|
-
declare const workerMessageErrorEvent: Eventa<{
|
|
25
|
-
error: unknown;
|
|
26
|
-
message: any;
|
|
27
|
-
}>;
|
|
28
|
-
declare function normalizeOnListenerParameters(event: Eventa<any>, options?: {
|
|
29
|
-
transfer?: Transferable[];
|
|
30
|
-
} | unknown): {
|
|
31
|
-
body: any;
|
|
32
|
-
transfer: Transferable[] | undefined;
|
|
33
|
-
};
|
|
34
|
-
interface WithTransfer<T> {
|
|
35
|
-
message: T;
|
|
36
|
-
_transfer?: Transferable[];
|
|
37
|
-
}
|
|
38
|
-
declare function withTransfer<T>(body: T, transfer?: Transferable[]): ExtendableInvokeResponse<T, EventContext<{
|
|
39
|
-
invokeResponse?: {
|
|
40
|
-
transfer?: Transferable[];
|
|
41
|
-
};
|
|
42
|
-
}, any>>;
|
|
43
|
-
//#endregion
|
|
44
4
|
//#region src/adapters/webworkers/index.d.ts
|
|
45
5
|
declare function createContext(worker: Worker): {
|
|
46
6
|
context: EventContext<{
|
|
@@ -56,8 +16,9 @@ declare function createContext(worker: Worker): {
|
|
|
56
16
|
error?: ErrorEvent;
|
|
57
17
|
messageError?: MessageEvent;
|
|
58
18
|
};
|
|
19
|
+
transfer?: Transferable[];
|
|
59
20
|
}>;
|
|
60
21
|
};
|
|
61
22
|
//#endregion
|
|
62
|
-
export {
|
|
23
|
+
export { WorkerEventa, WorkerPayload, createContext, defineOutboundWorkerEventa, defineWorkerEventa, isWorkerEventa, normalizeOnListenerParameters, workerErrorEvent, workerMessageErrorEvent };
|
|
63
24
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { c as matchBy, i as and, n as EventaFlowDirection, o as defineInboundEventa, s as defineOutboundEventa, t as createContext$1 } from "../../context-
|
|
2
|
-
import "../../src-
|
|
3
|
-
import { a as
|
|
1
|
+
import { c as matchBy, i as and, n as EventaFlowDirection, o as defineInboundEventa, s as defineOutboundEventa, t as createContext$1 } from "../../context-BMDJMapI.mjs";
|
|
2
|
+
import { E as registerInvokeAbortEventListeners } from "../../src-eMqISeHo.mjs";
|
|
3
|
+
import { a as workerErrorEvent, i as normalizeOnListenerParameters, n as defineWorkerEventa, o as generateWorkerPayload, r as isWorkerEventa, s as parseWorkerPayload, t as defineOutboundWorkerEventa } from "../../shared-CRxfs1TC.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/adapters/webworkers/index.ts
|
|
6
6
|
function createContext(worker) {
|
|
7
7
|
const ctx = createContext$1();
|
|
8
|
+
registerInvokeAbortEventListeners(ctx, workerErrorEvent);
|
|
8
9
|
ctx.on(and(matchBy((e) => e._flowDirection === EventaFlowDirection.Outbound || !e._flowDirection), matchBy("*")), (event, options) => {
|
|
9
10
|
const { body, transfer } = normalizeOnListenerParameters(event, options);
|
|
10
11
|
const data = generateWorkerPayload(event.id, {
|
|
@@ -38,5 +39,5 @@ function createContext(worker) {
|
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
//#endregion
|
|
41
|
-
export { createContext, defineOutboundWorkerEventa, defineWorkerEventa, isWorkerEventa
|
|
42
|
+
export { createContext, defineOutboundWorkerEventa, defineWorkerEventa, isWorkerEventa };
|
|
42
43
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["createBaseContext"],"sources":["../../../src/adapters/webworkers/index.ts"],"sourcesContent":["import type { EventContext } from '../../context'\nimport type { DirectionalEventa, Eventa } from '../../eventa'\n\nimport { createContext as createBaseContext } from '../../context'\nimport { and, defineInboundEventa, defineOutboundEventa, EventaFlowDirection, matchBy } from '../../eventa'\nimport { generateWorkerPayload, parseWorkerPayload } from './internal'\nimport { isWorkerEventa, normalizeOnListenerParameters, workerErrorEvent } from './shared'\n\nexport function createContext(worker: Worker) {\n const ctx = createBaseContext() as EventContext<\n {\n invokeRequest?: { transfer?: Transferable[] }\n invokeResponse?: { transfer?: Transferable[] }\n },\n { raw: { message?: MessageEvent, error?: ErrorEvent, messageError?: MessageEvent } }\n >\n\n ctx.on(and(\n matchBy((e: DirectionalEventa<any>) => e._flowDirection === EventaFlowDirection.Outbound || !e._flowDirection),\n matchBy('*'),\n ), (event, options) => {\n const { body, transfer } = normalizeOnListenerParameters(event, options)\n const data = generateWorkerPayload(event.id, { ...defineOutboundEventa(event.type), ...event, body })\n if (transfer != null) {\n worker.postMessage(data, { transfer })\n return\n }\n\n worker.postMessage(data)\n })\n\n worker.onmessage = (event) => {\n try {\n const { type, payload } = parseWorkerPayload<Eventa<any>>(event.data)\n if (!isWorkerEventa(payload)) {\n ctx.emit(defineInboundEventa(type), payload.body, { raw: { message: event } })\n }\n else {\n ctx.emit(defineInboundEventa(type), { message: payload.body }, { raw: { message: event } })\n }\n }\n catch (error) {\n console.error('Failed to parse WebWorker message:', error)\n ctx.emit(workerErrorEvent, { error }, { raw: { message: event } })\n }\n }\n\n worker.onerror = (error) => {\n ctx.emit(workerErrorEvent, { error }, { raw: { error } })\n }\n\n worker.onmessageerror = (error) => {\n ctx.emit(workerErrorEvent, { error }, { raw: { messageError: error } })\n }\n\n return {\n context: ctx,\n }\n}\n\nexport { defineOutboundWorkerEventa, defineWorkerEventa, isWorkerEventa
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["createBaseContext"],"sources":["../../../src/adapters/webworkers/index.ts"],"sourcesContent":["import type { EventContext } from '../../context'\nimport type { DirectionalEventa, Eventa } from '../../eventa'\n\nimport { createContext as createBaseContext } from '../../context'\nimport { registerInvokeAbortEventListeners } from '../../context-extension-invoke-internal'\nimport { and, defineInboundEventa, defineOutboundEventa, EventaFlowDirection, matchBy } from '../../eventa'\nimport { generateWorkerPayload, parseWorkerPayload } from './internal'\nimport { isWorkerEventa, normalizeOnListenerParameters, workerErrorEvent } from './shared'\n\nexport function createContext(worker: Worker) {\n const ctx = createBaseContext() as EventContext<\n {\n invokeRequest?: { transfer?: Transferable[] }\n invokeResponse?: { transfer?: Transferable[] }\n },\n { raw: { message?: MessageEvent, error?: ErrorEvent, messageError?: MessageEvent }, transfer?: Transferable[] }\n >\n // Configure invoke to fail fast on fatal worker errors (load/syntax/runtime).\n registerInvokeAbortEventListeners(ctx, workerErrorEvent)\n\n ctx.on(and(\n matchBy((e: DirectionalEventa<any>) => e._flowDirection === EventaFlowDirection.Outbound || !e._flowDirection),\n matchBy('*'),\n ), (event, options) => {\n const { body, transfer } = normalizeOnListenerParameters(event, options)\n const data = generateWorkerPayload(event.id, { ...defineOutboundEventa(event.type), ...event, body })\n if (transfer != null) {\n worker.postMessage(data, { transfer })\n return\n }\n\n worker.postMessage(data)\n })\n\n worker.onmessage = (event) => {\n try {\n const { type, payload } = parseWorkerPayload<Eventa<any>>(event.data)\n if (!isWorkerEventa(payload)) {\n ctx.emit(defineInboundEventa(type), payload.body, { raw: { message: event } })\n }\n else {\n ctx.emit(defineInboundEventa(type), { message: payload.body }, { raw: { message: event } })\n }\n }\n catch (error) {\n console.error('Failed to parse WebWorker message:', error)\n ctx.emit(workerErrorEvent, { error }, { raw: { message: event } })\n }\n }\n\n worker.onerror = (error) => {\n ctx.emit(workerErrorEvent, { error }, { raw: { error } })\n }\n\n worker.onmessageerror = (error) => {\n ctx.emit(workerErrorEvent, { error }, { raw: { messageError: error } })\n }\n\n return {\n context: ctx,\n }\n}\n\nexport { defineOutboundWorkerEventa, defineWorkerEventa, isWorkerEventa } from './shared'\nexport type * from './shared'\n"],"mappings":";;;;;AASA,SAAgB,cAAc,QAAgB;CAC5C,MAAM,MAAMA,iBAAmB;AAQ/B,mCAAkC,KAAK,iBAAiB;AAExD,KAAI,GAAG,IACL,SAAS,MAA8B,EAAE,mBAAmB,oBAAoB,YAAY,CAAC,EAAE,eAAe,EAC9G,QAAQ,IAAI,CACb,GAAG,OAAO,YAAY;EACrB,MAAM,EAAE,MAAM,aAAa,8BAA8B,OAAO,QAAQ;EACxE,MAAM,OAAO,sBAAsB,MAAM,IAAI;GAAE,GAAG,qBAAqB,MAAM,KAAK;GAAE,GAAG;GAAO;GAAM,CAAC;AACrG,MAAI,YAAY,MAAM;AACpB,UAAO,YAAY,MAAM,EAAE,UAAU,CAAC;AACtC;;AAGF,SAAO,YAAY,KAAK;GACxB;AAEF,QAAO,aAAa,UAAU;AAC5B,MAAI;GACF,MAAM,EAAE,MAAM,YAAY,mBAAgC,MAAM,KAAK;AACrE,OAAI,CAAC,eAAe,QAAQ,CAC1B,KAAI,KAAK,oBAAoB,KAAK,EAAE,QAAQ,MAAM,EAAE,KAAK,EAAE,SAAS,OAAO,EAAE,CAAC;OAG9E,KAAI,KAAK,oBAAoB,KAAK,EAAE,EAAE,SAAS,QAAQ,MAAM,EAAE,EAAE,KAAK,EAAE,SAAS,OAAO,EAAE,CAAC;WAGxF,OAAO;AACZ,WAAQ,MAAM,sCAAsC,MAAM;AAC1D,OAAI,KAAK,kBAAkB,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,SAAS,OAAO,EAAE,CAAC;;;AAItE,QAAO,WAAW,UAAU;AAC1B,MAAI,KAAK,kBAAkB,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;;AAG3D,QAAO,kBAAkB,UAAU;AACjC,MAAI,KAAK,kBAAkB,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,cAAc,OAAO,EAAE,CAAC;;AAGzE,QAAO,EACL,SAAS,KACV"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as EventContext } from "../../../context-
|
|
1
|
+
import { t as EventContext } from "../../../context-ZVv99bcM.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/adapters/webworkers/worker/index.d.ts
|
|
4
4
|
declare function createContext(options?: {
|
|
@@ -16,6 +16,7 @@ declare function createContext(options?: {
|
|
|
16
16
|
event?: any;
|
|
17
17
|
error?: string | Event;
|
|
18
18
|
};
|
|
19
|
+
transfer?: Transferable[];
|
|
19
20
|
}>;
|
|
20
21
|
};
|
|
21
22
|
//#endregion
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { c as matchBy, i as and, n as EventaFlowDirection, o as defineInboundEventa, s as defineOutboundEventa, t as createContext$1 } from "../../../context-
|
|
2
|
-
import "../../../src-
|
|
3
|
-
import {
|
|
1
|
+
import { c as matchBy, i as and, n as EventaFlowDirection, o as defineInboundEventa, s as defineOutboundEventa, t as createContext$1 } from "../../../context-BMDJMapI.mjs";
|
|
2
|
+
import { E as registerInvokeAbortEventListeners } from "../../../src-eMqISeHo.mjs";
|
|
3
|
+
import { a as workerErrorEvent, i as normalizeOnListenerParameters, o as generateWorkerPayload, r as isWorkerEventa, s as parseWorkerPayload } from "../../../shared-CRxfs1TC.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/adapters/webworkers/worker/index.ts
|
|
6
6
|
function createContext(options) {
|
|
7
7
|
const { messagePort = self } = options || {};
|
|
8
8
|
const ctx = createContext$1();
|
|
9
|
+
registerInvokeAbortEventListeners(ctx, workerErrorEvent);
|
|
9
10
|
ctx.on(and(matchBy((e) => e._flowDirection === EventaFlowDirection.Outbound || !e._flowDirection), matchBy("*")), (event, options$1) => {
|
|
10
11
|
const { body, transfer } = normalizeOnListenerParameters(event, options$1);
|
|
11
12
|
const data = generateWorkerPayload(event.id, {
|