@moeru/eventa 1.0.0-beta.2 → 1.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -1
- package/dist/adapters/broadcast-channel/index.d.mts +4 -2
- package/dist/adapters/broadcast-channel/index.mjs +6 -9
- package/dist/adapters/broadcast-channel/index.mjs.map +1 -1
- package/dist/adapters/electron/main.d.mts +2 -2
- package/dist/adapters/electron/main.mjs +7 -9
- package/dist/adapters/electron/main.mjs.map +1 -1
- package/dist/adapters/electron/renderer.d.mts +134 -3
- package/dist/adapters/electron/renderer.mjs +4 -6
- package/dist/adapters/electron/renderer.mjs.map +1 -1
- package/dist/adapters/event-emitter/index.d.mts +4 -2
- package/dist/adapters/event-emitter/index.mjs +4 -7
- package/dist/adapters/event-emitter/index.mjs.map +1 -1
- package/dist/adapters/event-target/index.d.mts +4 -2
- package/dist/adapters/event-target/index.mjs +5 -8
- package/dist/adapters/event-target/index.mjs.map +1 -1
- package/dist/adapters/websocket/h3/index.d.mts +448 -9
- package/dist/adapters/websocket/h3/index.mjs +7 -9
- package/dist/adapters/websocket/h3/index.mjs.map +1 -1
- package/dist/adapters/websocket/index.d.mts +1 -1
- package/dist/adapters/websocket/index.mjs +1 -1
- package/dist/adapters/websocket/native/index.d.mts +5 -5
- package/dist/adapters/websocket/native/index.mjs +4 -5
- package/dist/adapters/websocket/native/index.mjs.map +1 -1
- package/dist/adapters/webworkers/index.d.mts +2 -2
- package/dist/adapters/webworkers/index.mjs +5 -6
- package/dist/adapters/webworkers/index.mjs.map +1 -1
- package/dist/adapters/webworkers/worker/index.d.mts +1 -1
- package/dist/adapters/webworkers/worker/index.mjs +6 -7
- package/dist/adapters/webworkers/worker/index.mjs.map +1 -1
- package/dist/adapters/window-message/index.d.mts +50 -0
- package/dist/adapters/window-message/index.mjs +79 -0
- package/dist/adapters/window-message/index.mjs.map +1 -0
- package/dist/adapters/worker-threads/index.d.mts +2 -2
- package/dist/adapters/worker-threads/index.mjs +5 -6
- package/dist/adapters/worker-threads/index.mjs.map +1 -1
- package/dist/adapters/worker-threads/worker/index.d.mts +1 -1
- package/dist/adapters/worker-threads/worker/index.mjs +6 -7
- package/dist/adapters/worker-threads/worker/index.mjs.map +1 -1
- package/dist/{context-ZVv99bcM.d.mts → context-BsqFeoer.d.mts} +2 -2
- package/dist/{context-BMDJMapI.mjs → context-Dht_IZMb.mjs} +30 -27
- package/dist/context-Dht_IZMb.mjs.map +1 -0
- package/dist/eventa-DSnoBa1O.d.mts +106 -0
- package/dist/{index-CI_gUGXg.d.mts → index-g6DulgOI.d.mts} +111 -99
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +3 -4
- package/dist/{internal-ChLglF1N.mjs → internal-CHUsXYiP.mjs} +3 -4
- package/dist/{internal-ChLglF1N.mjs.map → internal-CHUsXYiP.mjs.map} +1 -1
- package/dist/{shared-CRxfs1TC.mjs → shared-CA5MGwv0.mjs} +5 -7
- package/dist/shared-CA5MGwv0.mjs.map +1 -0
- package/dist/{shared-DgX1R_nY.d.mts → shared-CVTLm458.d.mts} +4 -4
- package/dist/{shared-Cd4CLAdD.d.mts → shared-CfXZb-7K.d.mts} +4 -2
- package/dist/{shared-CA_i_yfR.mjs → shared-Dl0_bFq0.mjs} +4 -5
- package/dist/{shared-CA_i_yfR.mjs.map → shared-Dl0_bFq0.mjs.map} +1 -1
- package/dist/{src-eMqISeHo.mjs → src-CTs6h4Ci.mjs} +177 -161
- package/dist/src-CTs6h4Ci.mjs.map +1 -0
- package/package.json +14 -7
- package/dist/context-BMDJMapI.mjs.map +0 -1
- package/dist/eventa-AJyw28P8.d.mts +0 -52
- package/dist/shared-CRxfs1TC.mjs.map +0 -1
- package/dist/src-eMqISeHo.mjs.map +0 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
//#region src/eventa.d.ts
|
|
2
|
+
declare function nanoid(): string;
|
|
3
|
+
interface InvokeEventConstraint<_Req, _Res> {}
|
|
4
|
+
type EventTag<Res, Req> = string & InvokeEventConstraint<Req, Res>;
|
|
5
|
+
declare enum EventaType {
|
|
6
|
+
Event = "event",
|
|
7
|
+
MatchExpression = "matchExpression"
|
|
8
|
+
}
|
|
9
|
+
declare enum EventaFlowDirection {
|
|
10
|
+
Inbound = "inbound",
|
|
11
|
+
Outbound = "outbound"
|
|
12
|
+
}
|
|
13
|
+
interface DirectionalEventa<P, T = undefined> extends Eventa<P> {
|
|
14
|
+
_flowDirection: EventaFlowDirection | T;
|
|
15
|
+
}
|
|
16
|
+
interface InboundEventa<T> extends DirectionalEventa<T> {
|
|
17
|
+
_flowDirection: EventaFlowDirection.Inbound;
|
|
18
|
+
}
|
|
19
|
+
interface OutboundEventa<T> extends DirectionalEventa<T> {
|
|
20
|
+
_flowDirection: EventaFlowDirection.Outbound;
|
|
21
|
+
}
|
|
22
|
+
declare function defineInboundEventa<T>(id?: string): InboundEventa<T>;
|
|
23
|
+
declare function defineOutboundEventa<T>(id?: string): OutboundEventa<T>;
|
|
24
|
+
interface EventaLike<_P = undefined, T extends EventaType = EventaType> {
|
|
25
|
+
id: string;
|
|
26
|
+
type?: T;
|
|
27
|
+
}
|
|
28
|
+
interface Eventa<P = unknown, M = unknown, IM = unknown> extends EventaLike<P, EventaType.Event> {
|
|
29
|
+
body?: P;
|
|
30
|
+
/**
|
|
31
|
+
* Optional runtime metadata that can be attached to the eventa.
|
|
32
|
+
*
|
|
33
|
+
* NOTICE: for defineInvoke, and defineInvokeHandler, the metadata will be omitted
|
|
34
|
+
* for smaller chunk size, this means for metadata, the data contains will not be available in the defineInvokeHandler.
|
|
35
|
+
*
|
|
36
|
+
* This can be used for various purposes such as logging, debugging, or providing additional context about the eventa.
|
|
37
|
+
* Allowing the event handler to be able to access this metadata can enable more flexible and powerful event handling logic.
|
|
38
|
+
*/
|
|
39
|
+
metadata?: M;
|
|
40
|
+
/**
|
|
41
|
+
* Optional runtime metadata that can be attached to the eventa when invoking it.
|
|
42
|
+
*
|
|
43
|
+
* Unlike the `metadata` field, the `invokeMetadata` is specifically designed to be used when invoking the eventa, and it
|
|
44
|
+
* will be available in the defineInvokeHandler.
|
|
45
|
+
*
|
|
46
|
+
* This allows for a clear separation between the metadata that describes the eventa itself and the metadata that is relevant
|
|
47
|
+
* to the invocation of the eventa, providing more flexibility in how metadata is used and accessed within the event
|
|
48
|
+
* handling system.
|
|
49
|
+
*/
|
|
50
|
+
invokeMetadata?: IM;
|
|
51
|
+
}
|
|
52
|
+
type InferEventaPayload<E> = E extends Eventa<infer P> ? P : never;
|
|
53
|
+
declare function defineEventa<P = undefined, M = undefined, IM = undefined>(id?: string, options?: {
|
|
54
|
+
/**
|
|
55
|
+
* Optionally inherit many properties from another parent eventa.
|
|
56
|
+
*/
|
|
57
|
+
inheritFrom?: Eventa<P, M, IM>;
|
|
58
|
+
/**
|
|
59
|
+
* Optional runtime metadata that can be attached to the eventa.
|
|
60
|
+
*
|
|
61
|
+
* NOTICE: for defineInvoke, and defineInvokeHandler, the metadata will be omitted
|
|
62
|
+
* for smaller chunk size, this means for metadata, the data contains will not be available in the defineInvokeHandler.
|
|
63
|
+
*
|
|
64
|
+
* This can be used for various purposes such as logging, debugging, or providing additional context about the eventa.
|
|
65
|
+
* Allowing the event handler to be able to access this metadata can enable more flexible and powerful event handling logic.
|
|
66
|
+
*/
|
|
67
|
+
metadata?: M;
|
|
68
|
+
/**
|
|
69
|
+
* Optional runtime metadata that can be attached to the eventa when invoking it.
|
|
70
|
+
*
|
|
71
|
+
* Unlike the `metadata` field, the `invokeMetadata` is specifically designed to be used when invoking the eventa, and it
|
|
72
|
+
* will be available in the defineInvokeHandler.
|
|
73
|
+
*
|
|
74
|
+
* This allows for a clear separation between the metadata that describes the eventa itself and the metadata that is relevant
|
|
75
|
+
* to the invocation of the eventa, providing more flexibility in how metadata is used and accessed within the event
|
|
76
|
+
* handling system.
|
|
77
|
+
*/
|
|
78
|
+
invokeMetadata?: IM;
|
|
79
|
+
}): Eventa<P, M, IM>;
|
|
80
|
+
interface EventaMatchExpression<P = undefined> extends EventaLike<P, EventaType.MatchExpression> {
|
|
81
|
+
matcher?: (event: Eventa<P>) => boolean | Promise<boolean>;
|
|
82
|
+
}
|
|
83
|
+
declare function and<P>(...matchExpression: Array<EventaMatchExpression<P>>): EventaMatchExpression<P>;
|
|
84
|
+
declare function or<P>(...matchExpression: Array<EventaMatchExpression<P>>): EventaMatchExpression<P>;
|
|
85
|
+
/**
|
|
86
|
+
* Match by is powerful utility function that allows you to create a match expression based on various criteria
|
|
87
|
+
* when working with eventa (event system).
|
|
88
|
+
*
|
|
89
|
+
* Semantics like glob matching, RegExp, or even custom matcher function can be used to create complex match
|
|
90
|
+
* expressions that can be used to filter and handle events in a flexible way.
|
|
91
|
+
*/
|
|
92
|
+
declare function matchBy<P = undefined>(glob: string, inverted?: boolean): EventaMatchExpression<P>;
|
|
93
|
+
declare function matchBy<P = undefined>(options: {
|
|
94
|
+
ids: string[];
|
|
95
|
+
}, inverted?: boolean): EventaMatchExpression<P>;
|
|
96
|
+
declare function matchBy<P = undefined>(options: {
|
|
97
|
+
eventa: Eventa<P>[];
|
|
98
|
+
}, inverted?: boolean): EventaMatchExpression<P>;
|
|
99
|
+
declare function matchBy<P = undefined>(options: {
|
|
100
|
+
types: EventaType[];
|
|
101
|
+
}, inverted?: boolean): EventaMatchExpression<P>;
|
|
102
|
+
declare function matchBy<P = undefined>(regExp: RegExp, inverted?: boolean): EventaMatchExpression<P>;
|
|
103
|
+
declare function matchBy<P = undefined, E extends Eventa<P> = Eventa<P>>(matcher: (event: E) => boolean | Promise<boolean>): EventaMatchExpression<P>;
|
|
104
|
+
//#endregion
|
|
105
|
+
export { nanoid as _, EventaLike as a, InboundEventa as c, OutboundEventa as d, and as f, matchBy as g, defineOutboundEventa as h, EventaFlowDirection as i, InferEventaPayload as l, defineInboundEventa as m, EventTag as n, EventaMatchExpression as o, defineEventa as p, Eventa as r, EventaType as s, DirectionalEventa as t, InvokeEventConstraint as u, or as v };
|
|
106
|
+
//# sourceMappingURL=eventa-DSnoBa1O.d.mts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as EventTag, r as Eventa } from "./eventa-
|
|
2
|
-
import { t as EventContext } from "./context-
|
|
1
|
+
import { n as EventTag, r as Eventa } from "./eventa-DSnoBa1O.mjs";
|
|
2
|
+
import { t as EventContext } from "./context-BsqFeoer.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/invoke-shared.d.ts
|
|
5
5
|
declare enum InvokeEventType {
|
|
@@ -9,102 +9,114 @@ declare enum InvokeEventType {
|
|
|
9
9
|
SendEventAbort = 3,
|
|
10
10
|
ReceiveEvent = 4,
|
|
11
11
|
ReceiveEventError = 5,
|
|
12
|
-
ReceiveEventStreamEnd = 6
|
|
12
|
+
ReceiveEventStreamEnd = 6
|
|
13
13
|
}
|
|
14
|
-
interface SendEvent<Res
|
|
14
|
+
interface SendEvent<Res, Req = undefined, _ = undefined, __ = undefined, M = undefined, IM = undefined> extends Eventa<{
|
|
15
15
|
invokeId: string;
|
|
16
|
-
content: Req
|
|
16
|
+
content: Req;
|
|
17
17
|
isReqStream?: boolean;
|
|
18
|
-
}> {
|
|
19
|
-
id: EventTag<Res
|
|
18
|
+
}, M, IM> {
|
|
19
|
+
id: EventTag<Res, Req>;
|
|
20
20
|
invokeType: InvokeEventType.SendEvent;
|
|
21
21
|
}
|
|
22
|
-
interface SendEventError<Res
|
|
22
|
+
interface SendEventError<Res, Req = undefined, _ = undefined, ReqErr = Error, M = undefined, IM = undefined> extends Eventa<{
|
|
23
23
|
invokeId: string;
|
|
24
|
-
content: ReqErr
|
|
25
|
-
}> {
|
|
26
|
-
id: EventTag<Res
|
|
24
|
+
content: ReqErr;
|
|
25
|
+
}, M, IM> {
|
|
26
|
+
id: EventTag<Res, Req>;
|
|
27
27
|
invokeType: InvokeEventType.SendEventError;
|
|
28
28
|
}
|
|
29
|
-
interface SendEventStreamEnd<Res
|
|
29
|
+
interface SendEventStreamEnd<Res, Req = undefined, _ = undefined, __ = undefined, M = undefined, IM = undefined> extends Eventa<{
|
|
30
30
|
invokeId: string;
|
|
31
31
|
content: undefined;
|
|
32
|
-
}> {
|
|
33
|
-
id: EventTag<Res
|
|
32
|
+
}, M, IM> {
|
|
33
|
+
id: EventTag<Res, Req>;
|
|
34
34
|
invokeType: InvokeEventType.SendEventStreamEnd;
|
|
35
35
|
}
|
|
36
|
-
interface SendEventAbort<Res
|
|
36
|
+
interface SendEventAbort<Res, Req = undefined, _ = undefined, __ = undefined, M = undefined, IM = undefined> extends Eventa<{
|
|
37
37
|
invokeId: string;
|
|
38
38
|
content?: unknown;
|
|
39
|
-
}> {
|
|
40
|
-
id: EventTag<Res
|
|
39
|
+
}, M, IM> {
|
|
40
|
+
id: EventTag<Res, Req>;
|
|
41
41
|
invokeType: InvokeEventType.SendEventAbort;
|
|
42
42
|
}
|
|
43
|
-
interface ReceiveEvent<Res
|
|
43
|
+
interface ReceiveEvent<Res, Req = undefined, _ = undefined, __ = undefined, M = undefined, IM = undefined> extends Eventa<{
|
|
44
44
|
invokeId: string;
|
|
45
|
-
content: Res
|
|
46
|
-
}> {
|
|
47
|
-
id: EventTag<Res
|
|
45
|
+
content: Res;
|
|
46
|
+
}, M, IM> {
|
|
47
|
+
id: EventTag<Res, Req>;
|
|
48
48
|
invokeType: InvokeEventType.ReceiveEvent;
|
|
49
49
|
}
|
|
50
|
-
interface ReceiveEventError<Res
|
|
50
|
+
interface ReceiveEventError<Res, Req = undefined, ResErr = undefined, _ = undefined, M = undefined, IM = undefined> extends Eventa<{
|
|
51
51
|
invokeId: string;
|
|
52
52
|
content: {
|
|
53
|
-
error: ResErr
|
|
53
|
+
error: ResErr;
|
|
54
54
|
};
|
|
55
|
-
}> {
|
|
56
|
-
id: EventTag<Res
|
|
55
|
+
}, M, IM> {
|
|
56
|
+
id: EventTag<Res, Req>;
|
|
57
57
|
invokeType: InvokeEventType.ReceiveEventError;
|
|
58
58
|
}
|
|
59
|
-
interface ReceiveEventStreamEnd<Res
|
|
59
|
+
interface ReceiveEventStreamEnd<Res, Req = undefined, _ = undefined, __ = undefined, M = undefined, IM = undefined> extends Eventa<{
|
|
60
60
|
invokeId: string;
|
|
61
61
|
content: undefined;
|
|
62
|
-
}> {
|
|
63
|
-
id: EventTag<Res
|
|
62
|
+
}, M, IM> {
|
|
63
|
+
id: EventTag<Res, Req>;
|
|
64
64
|
invokeType: InvokeEventType.ReceiveEventStreamEnd;
|
|
65
65
|
}
|
|
66
|
-
interface InvokeEventa<Res
|
|
67
|
-
sendEvent: SendEvent<Res
|
|
68
|
-
sendEventError: SendEventError<Res
|
|
69
|
-
sendEventStreamEnd: SendEventStreamEnd<Res
|
|
70
|
-
sendEventAbort: SendEventAbort<Res
|
|
71
|
-
receiveEvent: ReceiveEvent<Res
|
|
72
|
-
receiveEventError: ReceiveEventError<Res
|
|
73
|
-
receiveEventStreamEnd: ReceiveEventStreamEnd<Res
|
|
66
|
+
interface InvokeEventa<Res, Req = undefined, ResErr = Error, ReqErr = Error, M = undefined, IM = undefined> {
|
|
67
|
+
sendEvent: SendEvent<Res, Req, ResErr, ReqErr, M, IM>;
|
|
68
|
+
sendEventError: SendEventError<Res, Req, ResErr, ReqErr, M, IM>;
|
|
69
|
+
sendEventStreamEnd: SendEventStreamEnd<Res, Req, ResErr, ReqErr, M, IM>;
|
|
70
|
+
sendEventAbort: SendEventAbort<Res, Req, ResErr, ReqErr, M, IM>;
|
|
71
|
+
receiveEvent: ReceiveEvent<Res, Req, ResErr, ReqErr, M, IM>;
|
|
72
|
+
receiveEventError: ReceiveEventError<Res, Req, ResErr, ReqErr, M, IM>;
|
|
73
|
+
receiveEventStreamEnd: ReceiveEventStreamEnd<Res, Req, ResErr, ReqErr, M, IM>;
|
|
74
|
+
}
|
|
75
|
+
interface InvokeHandlerEventa<Res, Req = undefined, ResErr = Error, ReqErr = Error, M = undefined, _IM = undefined> extends InvokeEventa<Res, Req, ResErr, ReqErr, M, undefined> {
|
|
76
|
+
sendEvent: SendEvent<Res, Req, ResErr, ReqErr, M, undefined>;
|
|
77
|
+
sendEventError: SendEventError<Res, Req, ResErr, ReqErr, M, undefined>;
|
|
78
|
+
sendEventStreamEnd: SendEventStreamEnd<Res, Req, ResErr, ReqErr, M, undefined>;
|
|
79
|
+
sendEventAbort: SendEventAbort<Res, Req, ResErr, ReqErr, M, undefined>;
|
|
80
|
+
receiveEvent: ReceiveEvent<Res, Req, ResErr, ReqErr, M, undefined>;
|
|
81
|
+
receiveEventError: ReceiveEventError<Res, Req, ResErr, ReqErr, M, undefined>;
|
|
82
|
+
receiveEventStreamEnd: ReceiveEventStreamEnd<Res, Req, ResErr, ReqErr, M, undefined>;
|
|
74
83
|
}
|
|
75
84
|
type InferSendEvent<T> = T extends {
|
|
76
|
-
sendEvent: SendEvent<infer Res, infer Req, infer ResErr, infer ReqErr>;
|
|
77
|
-
} ? SendEvent<Res, Req, ResErr, ReqErr> : never;
|
|
85
|
+
sendEvent: SendEvent<infer Res, infer Req, infer ResErr, infer ReqErr, infer M, infer IM>;
|
|
86
|
+
} ? SendEvent<Res, Req, ResErr, ReqErr, M, IM> : never;
|
|
78
87
|
type InferSendEventError<T> = T extends {
|
|
79
|
-
sendEventError: SendEventError<infer Res, infer Req, infer ResErr, infer ReqErr>;
|
|
80
|
-
} ? SendEventError<Res, Req, ResErr, ReqErr> : never;
|
|
88
|
+
sendEventError: SendEventError<infer Res, infer Req, infer ResErr, infer ReqErr, infer M, infer IM>;
|
|
89
|
+
} ? SendEventError<Res, Req, ResErr, ReqErr, M, IM> : never;
|
|
81
90
|
type InferSendEventStreamEnd<T> = T extends {
|
|
82
|
-
sendEventStreamEnd: SendEventStreamEnd<infer Res, infer Req, infer ResErr, infer ReqErr>;
|
|
83
|
-
} ? SendEventStreamEnd<Res, Req, ResErr, ReqErr> : never;
|
|
91
|
+
sendEventStreamEnd: SendEventStreamEnd<infer Res, infer Req, infer ResErr, infer ReqErr, infer M, infer IM>;
|
|
92
|
+
} ? SendEventStreamEnd<Res, Req, ResErr, ReqErr, M, IM> : never;
|
|
84
93
|
type InferSendEventAbort<T> = T extends {
|
|
85
|
-
sendEventAbort: SendEventAbort<infer Res, infer Req, infer ResErr, infer ReqErr>;
|
|
86
|
-
} ? SendEventAbort<Res, Req, ResErr, ReqErr> : never;
|
|
94
|
+
sendEventAbort: SendEventAbort<infer Res, infer Req, infer ResErr, infer ReqErr, infer M, infer IM>;
|
|
95
|
+
} ? SendEventAbort<Res, Req, ResErr, ReqErr, M, IM> : never;
|
|
87
96
|
type InferReceiveEvent<T> = T extends {
|
|
88
|
-
receiveEvent: ReceiveEvent<infer Res, infer Req, infer ResErr, infer ReqErr>;
|
|
89
|
-
} ? ReceiveEvent<Res, Req, ResErr, ReqErr> : never;
|
|
97
|
+
receiveEvent: ReceiveEvent<infer Res, infer Req, infer ResErr, infer ReqErr, infer M, infer IM>;
|
|
98
|
+
} ? ReceiveEvent<Res, Req, ResErr, ReqErr, M, IM> : never;
|
|
90
99
|
type InferReceiveEventError<T> = T extends {
|
|
91
|
-
receiveEventError: ReceiveEventError<infer Res, infer Req, infer ResErr, infer ReqErr>;
|
|
92
|
-
} ? ReceiveEventError<Res, Req, ResErr, ReqErr> : never;
|
|
100
|
+
receiveEventError: ReceiveEventError<infer Res, infer Req, infer ResErr, infer ReqErr, infer M, infer IM>;
|
|
101
|
+
} ? ReceiveEventError<Res, Req, ResErr, ReqErr, M, IM> : never;
|
|
93
102
|
type InferReceiveEventStreamEnd<T> = T extends {
|
|
94
|
-
receiveEventStreamEnd: ReceiveEventStreamEnd<infer Res, infer Req, infer ResErr, infer ReqErr>;
|
|
95
|
-
} ? ReceiveEventStreamEnd<Res, Req, ResErr, ReqErr> : never;
|
|
96
|
-
declare function defineInvokeEventa<Res
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
receiveEventStreamEnd: ReceiveEventStreamEnd<infer Res, infer Req, infer ResErr, infer ReqErr, infer M, infer IM>;
|
|
104
|
+
} ? ReceiveEventStreamEnd<Res, Req, ResErr, ReqErr, M, IM> : never;
|
|
105
|
+
declare function defineInvokeEventa<Res, Req = undefined, ResErr = Error, ReqErr = Error, M = undefined, IM = undefined>(tag?: string, options?: {
|
|
106
|
+
metadata?: M;
|
|
107
|
+
invokeMetadata?: IM;
|
|
108
|
+
}): {
|
|
109
|
+
sendEvent: SendEvent<Res, Req, ResErr, ReqErr, M, IM>;
|
|
110
|
+
sendEventError: SendEventError<Res, Req, ResErr, ReqErr, M, IM>;
|
|
111
|
+
sendEventStreamEnd: SendEventStreamEnd<Res, Req, ResErr, ReqErr, M, IM>;
|
|
112
|
+
sendEventAbort: SendEventAbort<Res, Req, ResErr, ReqErr, M, IM>;
|
|
113
|
+
receiveEvent: ReceiveEvent<Res, Req, ResErr, ReqErr, M, IM>;
|
|
114
|
+
receiveEventError: ReceiveEventError<Res, Req, ResErr, ReqErr, M, IM>;
|
|
115
|
+
receiveEventStreamEnd: ReceiveEventStreamEnd<Res, Req, ResErr, ReqErr, M, IM>;
|
|
104
116
|
};
|
|
105
|
-
declare function isInvokeEventa(event: Eventa<any>): event is SendEvent<any, any, any, any> | SendEventError<any, any, any, any> | SendEventStreamEnd<any, any, any, any> | ReceiveEvent<any, any, any, any> | ReceiveEventError<any, any, any, any> | ReceiveEventStreamEnd<any, any, any, any> | SendEventAbort<any, any, any, any>;
|
|
106
|
-
declare function isSendEvent(event: Eventa<any>): event is SendEvent<any, any, any, any> | SendEventError<any, any, any, any> | SendEventStreamEnd<any, any, any, any> | SendEventAbort<any, any, any, any>;
|
|
107
|
-
declare function isReceiveEvent(event: Eventa<any>): event is ReceiveEvent<any, any, any, any> | ReceiveEventError<any, any, any, any> | ReceiveEventStreamEnd<any, any, any, any>;
|
|
117
|
+
declare function isInvokeEventa(event: Eventa<any>): event is SendEvent<any, any, any, any, any, any> | SendEventError<any, any, any, any, any, any> | SendEventStreamEnd<any, any, any, any, any, any> | ReceiveEvent<any, any, any, any, any, any> | ReceiveEventError<any, any, any, any, any, any> | ReceiveEventStreamEnd<any, any, any, any, any, any> | SendEventAbort<any, any, any, any, any, any>;
|
|
118
|
+
declare function isSendEvent(event: Eventa<any>): event is SendEvent<any, any, any, any, any, any> | SendEventError<any, any, any, any, any, any> | SendEventStreamEnd<any, any, any, any, any, any> | SendEventAbort<any, any, any, any, any, any>;
|
|
119
|
+
declare function isReceiveEvent(event: Eventa<any>): event is ReceiveEvent<any, any, any, any, any, any> | ReceiveEventError<any, any, any, any, any, any> | ReceiveEventStreamEnd<any, any, any, any, any, any>;
|
|
108
120
|
//#endregion
|
|
109
121
|
//#region src/invoke.d.ts
|
|
110
122
|
type IsInvokeRequestOptional<EC extends EventContext<any, any>> = EC extends EventContext<infer E, any> ? E extends {
|
|
@@ -130,33 +142,33 @@ type ExtractInvokeResponseOptions<EC extends EventContext<any, any>> = EC extend
|
|
|
130
142
|
} ? IR : E extends {
|
|
131
143
|
invokeResponse?: infer IR;
|
|
132
144
|
} ? IR : undefined : undefined;
|
|
133
|
-
type InvokeFunction<Res
|
|
145
|
+
type InvokeFunction<Res, Req, EC extends EventContext<any, any>> = [Req] extends [undefined] ? IsInvokeRequestOptional<EC> extends true ? (req?: Req, options?: ExtractInvokeRequestOptions<EC>) => Promise<Res> : (req: Req, options: ExtractInvokeRequestOptions<EC>) => Promise<Res> : IsInvokeRequestOptional<EC> extends true ? (req: Req, options?: ExtractInvokeRequestOptions<EC>) => Promise<Res> : (req: Req, options: ExtractInvokeRequestOptions<EC>) => Promise<Res>;
|
|
134
146
|
type InvokeFunctionMap<EventMap extends Record<string, InvokeEventa<any, any, any, any>>, EC extends EventContext<any, any>> = { [K in keyof EventMap]: EventMap[K] extends InvokeEventa<infer Res, infer Req, any, any> ? InvokeFunction<Res, Req, EC> : never };
|
|
135
|
-
type ExtendableInvokeResponse<Res
|
|
136
|
-
response: Res
|
|
147
|
+
type ExtendableInvokeResponse<Res, EC extends EventContext<any, any>> = Promise<Res> | Res | Promise<{
|
|
148
|
+
response: Res;
|
|
137
149
|
invokeResponse?: ExtractInvokeResponseOptions<EC>;
|
|
138
150
|
}> | {
|
|
139
|
-
response: Res
|
|
151
|
+
response: Res;
|
|
140
152
|
invokeResponse?: ExtractInvokeResponseOptions<EC>;
|
|
141
153
|
};
|
|
142
|
-
declare function isExtendableInvokeResponseLike<Res
|
|
143
|
-
response: Res
|
|
154
|
+
declare function isExtendableInvokeResponseLike<Res, EC extends EventContext<any, any>>(value: Eventa<unknown> | ReceiveEvent<{
|
|
155
|
+
response: Res;
|
|
144
156
|
invokeResponse?: unknown;
|
|
145
157
|
}>): value is ReceiveEvent<{
|
|
146
|
-
response: Res
|
|
158
|
+
response: Res;
|
|
147
159
|
invokeResponse?: ExtractInvokeResponseOptions<EC>;
|
|
148
160
|
}>;
|
|
149
|
-
type Handler<Res
|
|
161
|
+
type Handler<Res, Req = any, EC extends EventContext<any, any> = EventContext<any, any>, RawEventOptions = unknown> = (payload: Req, options?: {
|
|
150
162
|
abortController?: AbortController;
|
|
151
|
-
} & RawEventOptions) => ExtendableInvokeResponse<Res
|
|
152
|
-
interface InternalInvokeHandler<Res
|
|
153
|
-
onSend: (params: InvokeEventa<Res
|
|
154
|
-
onSendStreamEnd: (params: InvokeEventa<Res
|
|
155
|
-
onSendAbort: (params: InvokeEventa<Res
|
|
163
|
+
} & RawEventOptions) => ExtendableInvokeResponse<Res, EC>;
|
|
164
|
+
interface InternalInvokeHandler<Res, Req = any, ResErr = Error, ReqErr = Error, EO = any, M = undefined, IM = undefined> {
|
|
165
|
+
onSend: (params: InvokeEventa<Res, Req, ResErr, ReqErr, M, IM>['sendEvent'], eventOptions?: EO) => void;
|
|
166
|
+
onSendStreamEnd: (params: InvokeEventa<Res, Req, ResErr, ReqErr, M, IM>['sendEventStreamEnd'], eventOptions?: EO) => void;
|
|
167
|
+
onSendAbort: (params: InvokeEventa<Res, Req, ResErr, ReqErr, M, IM>['sendEventAbort'], eventOptions?: EO) => void;
|
|
156
168
|
}
|
|
157
|
-
type HandlerMap<EventMap extends Record<string, InvokeEventa<any, any, any, any>>, EO = any, EC extends EventContext<any, any> = EventContext<any, any>> = { [K in keyof EventMap]: EventMap[K] extends InvokeEventa<infer Res, infer Req, any, any> ? Handler<Res, Req, EC, EO> : never };
|
|
158
|
-
interface InvocableEventContext<E
|
|
159
|
-
invokeHandlers?: Map<string, Map<Handler<any>, InternalInvokeHandler<any>>>;
|
|
169
|
+
type HandlerMap<EventMap extends Record<string, InvokeEventa<any, any, any, any, any, any>>, EO = any, EC extends EventContext<any, any> = EventContext<any, any>> = { [K in keyof EventMap]: EventMap[K] extends InvokeEventa<infer Res, infer Req, any, any, any, any> ? Handler<Res, Req, EC, EO> : never };
|
|
170
|
+
interface InvocableEventContext<E, EO> extends EventContext<E, EO> {
|
|
171
|
+
invokeHandlers?: Map<string, Map<Handler<any>, InternalInvokeHandler<any, any, any, any, any, any, any>>>;
|
|
160
172
|
}
|
|
161
173
|
/**
|
|
162
174
|
* Create a unary invoke function (client side).
|
|
@@ -208,7 +220,7 @@ interface InvocableEventContext<E$1, EO> extends EventContext<E$1, EO> {
|
|
|
208
220
|
* @param ctx Event context on the caller/client side.
|
|
209
221
|
* @param event Invoke event definition created by `defineInvokeEventa`.
|
|
210
222
|
*/
|
|
211
|
-
declare function defineInvoke<Res
|
|
223
|
+
declare function defineInvoke<Res, Req = undefined, ResErr = Error, ReqErr = Error, M = undefined, IM = undefined, CtxExt = any, EOpts = any, ECtx extends EventContext<CtxExt, EOpts> = EventContext<CtxExt, EOpts>>(ctx: ECtx | (() => ECtx | Promise<ECtx>), event: InvokeEventa<Res, Req, ResErr, ReqErr, M, IM>): InvokeFunction<Res, Req, ECtx>;
|
|
212
224
|
/**
|
|
213
225
|
* Create a map of invoke functions from a map of invoke events (client side).
|
|
214
226
|
*
|
|
@@ -226,7 +238,7 @@ declare function defineInvoke<Res$1, Req$1 = undefined, ResErr$1 = Error, ReqErr
|
|
|
226
238
|
* @param ctx Event context on the caller/client side.
|
|
227
239
|
* @param events Map of invoke events created by `defineInvokeEventa`.
|
|
228
240
|
*/
|
|
229
|
-
declare function defineInvokes<EK extends string, EventMap extends Record<EK, InvokeEventa<any, any, any, any>>, CtxExt = any, EOpts = any, ECtx extends EventContext<CtxExt, EOpts> = EventContext<CtxExt, EOpts>>(ctx: ECtx | (() => ECtx | Promise<ECtx>), events: EventMap): InvokeFunctionMap<EventMap, ECtx>;
|
|
241
|
+
declare function defineInvokes<EK extends string, EventMap extends Record<EK, InvokeEventa<any, any, any, any, any, any>>, CtxExt = any, EOpts = any, ECtx extends EventContext<CtxExt, EOpts> = EventContext<CtxExt, EOpts>>(ctx: ECtx | (() => ECtx | Promise<ECtx>), events: EventMap): InvokeFunctionMap<EventMap, ECtx>;
|
|
230
242
|
/**
|
|
231
243
|
* Define a unary invoke handler (server side).
|
|
232
244
|
*
|
|
@@ -246,9 +258,9 @@ declare function defineInvokes<EK extends string, EventMap extends Record<EK, In
|
|
|
246
258
|
* @param event Invoke event definition created by `defineInvokeEventa`.
|
|
247
259
|
* @param handler Handler that returns a response (or response + metadata).
|
|
248
260
|
*/
|
|
249
|
-
declare function defineInvokeHandler<Res
|
|
261
|
+
declare function defineInvokeHandler<Res, Req = undefined, ResErr = Error, ReqErr = Error, M = undefined, IM = undefined, CtxExt = any, EOpts extends {
|
|
250
262
|
raw?: any;
|
|
251
|
-
} = any>(ctx: InvocableEventContext<CtxExt, EOpts>, event:
|
|
263
|
+
} = any>(ctx: InvocableEventContext<CtxExt, EOpts>, event: InvokeHandlerEventa<Res, Req, ResErr, ReqErr, M, IM>, handler: Handler<Res, Req, InvocableEventContext<CtxExt, EOpts>, EOpts>): () => void;
|
|
252
264
|
/**
|
|
253
265
|
* Define multiple invoke handlers in batch (server side).
|
|
254
266
|
*
|
|
@@ -289,7 +301,7 @@ declare function defineInvokeHandlers<EK extends string, EventMap extends Record
|
|
|
289
301
|
* @param handler Specific handler to remove (omit to remove all).
|
|
290
302
|
* @returns `true` if at least one handler was removed, `false` otherwise
|
|
291
303
|
*/
|
|
292
|
-
declare function undefineInvokeHandler<Res
|
|
304
|
+
declare function undefineInvokeHandler<Res, Req = undefined, ResErr = Error, ReqErr = Error, CtxExt = any, EOpts = any>(ctx: InvocableEventContext<CtxExt, EOpts>, event: InvokeEventa<Res, Req, ResErr, ReqErr>, handler?: Handler<Res, Req, InvocableEventContext<CtxExt, EOpts>, EOpts>): boolean;
|
|
293
305
|
//#endregion
|
|
294
306
|
//#region src/invoke-extension-transfer.d.ts
|
|
295
307
|
interface WithTransfer<T> {
|
|
@@ -315,10 +327,10 @@ interface InvokeFunctionStubOptions {
|
|
|
315
327
|
type RemoteInvokeOptions<EC extends EventContext<any, any>> = ExtractInvokeRequestOptions<EC> & {
|
|
316
328
|
functionStubs?: boolean | InvokeFunctionStubOptions;
|
|
317
329
|
};
|
|
318
|
-
interface RemoteInvokeResult<Res
|
|
330
|
+
interface RemoteInvokeResult<Res> extends Promise<Res> {
|
|
319
331
|
dispose: () => void;
|
|
320
332
|
}
|
|
321
|
-
type RemoteInvokeFunction<Res
|
|
333
|
+
type RemoteInvokeFunction<Res, Req, EC extends EventContext<any, any>> = [Req] extends [undefined] ? (req?: Req, options?: RemoteInvokeOptions<EC>) => RemoteInvokeResult<Res> : (req: Req, options?: RemoteInvokeOptions<EC>) => RemoteInvokeResult<Res>;
|
|
322
334
|
declare function createRemoteMethodTagPrefix(prefix?: string): string;
|
|
323
335
|
/**
|
|
324
336
|
* Enable "remote method" payloads for invoke: functions in the request body are
|
|
@@ -369,10 +381,10 @@ declare function createRemoteMethodTagPrefix(prefix?: string): string;
|
|
|
369
381
|
* `onDisallowedTag`, `autoDisposeMs`, and `strict` for stricter control.
|
|
370
382
|
*/
|
|
371
383
|
declare function withRemoteMethods(defaultOptions?: boolean | InvokeFunctionStubOptions): {
|
|
372
|
-
defineInvoke<Res
|
|
373
|
-
defineInvokeHandler<Res
|
|
384
|
+
defineInvoke<Res, Req = undefined, ResErr = Error, ReqErr = Error, CtxExt = any, EOpts = any, ECtx extends EventContext<CtxExt, EOpts> = EventContext<CtxExt, EOpts>>(ctx: ECtx, event: InvokeEventa<Res, Req, ResErr, ReqErr>): RemoteInvokeFunction<Res, Req, ECtx>;
|
|
385
|
+
defineInvokeHandler<Res, Req = undefined, ResErr = Error, ReqErr = Error, CtxExt = any, EOpts extends {
|
|
374
386
|
raw?: any;
|
|
375
|
-
} = any>(ctx: InvocableEventContext<CtxExt, EOpts>, event: InvokeEventa<Res
|
|
387
|
+
} = any>(ctx: InvocableEventContext<CtxExt, EOpts>, event: InvokeEventa<Res, Req, ResErr, ReqErr>, handler: Handler<Res, Req, InvocableEventContext<CtxExt, EOpts>, EOpts>): () => void;
|
|
376
388
|
};
|
|
377
389
|
//#endregion
|
|
378
390
|
//#region src/stream.d.ts
|
|
@@ -414,12 +426,12 @@ declare function withRemoteMethods(defaultOptions?: boolean | InvokeFunctionStub
|
|
|
414
426
|
* @param clientCtx Event context on the caller/client side.
|
|
415
427
|
* @param event Invoke event definition created by `defineInvokeEventa`.
|
|
416
428
|
*/
|
|
417
|
-
declare function defineStreamInvoke<Res
|
|
429
|
+
declare function defineStreamInvoke<Res, Req = undefined, ResErr = Error, ReqErr = Error, E = any, EO = any>(clientCtx: EventContext<E, EO>, event: InvokeEventa<Res, Req, ResErr, ReqErr>): (req: Req | ReadableStream<Req> | AsyncIterable<Req>, options?: {
|
|
418
430
|
signal?: AbortSignal;
|
|
419
|
-
} & EO) => ReadableStream<Res
|
|
420
|
-
type StreamHandler<Res
|
|
431
|
+
} & EO) => ReadableStream<Res>;
|
|
432
|
+
type StreamHandler<Res, Req = any, RawEventOptions = unknown> = (payload: Req, options?: {
|
|
421
433
|
abortController?: AbortController;
|
|
422
|
-
} & RawEventOptions) => AsyncGenerator<Res
|
|
434
|
+
} & RawEventOptions) => AsyncGenerator<Res, void, unknown>;
|
|
423
435
|
/**
|
|
424
436
|
* Define a stream invoke handler (server side).
|
|
425
437
|
*
|
|
@@ -448,9 +460,9 @@ type StreamHandler<Res$1, Req$1 = any, RawEventOptions = unknown> = (payload: Re
|
|
|
448
460
|
* @param event Invoke event definition created by `defineInvokeEventa`.
|
|
449
461
|
* @param fn Stream handler that yields response chunks.
|
|
450
462
|
*/
|
|
451
|
-
declare function defineStreamInvokeHandler<Res
|
|
463
|
+
declare function defineStreamInvokeHandler<Res, Req = undefined, ResErr = Error, ReqErr = Error, E = any, EO extends {
|
|
452
464
|
raw?: any;
|
|
453
|
-
} = any>(serverCtx: EventContext<E
|
|
465
|
+
} = any>(serverCtx: EventContext<E, EO>, event: InvokeEventa<Res, Req, ResErr, ReqErr>, fn: StreamHandler<Res, Req, EO>): void;
|
|
454
466
|
/**
|
|
455
467
|
* Convert a callback-style handler into a stream handler.
|
|
456
468
|
*
|
|
@@ -475,13 +487,13 @@ declare function defineStreamInvokeHandler<Res$1, Req$1 = undefined, ResErr$1 =
|
|
|
475
487
|
*
|
|
476
488
|
* @param handler Callback handler with `emit` for streaming responses.
|
|
477
489
|
*/
|
|
478
|
-
declare function toStreamHandler<Req
|
|
490
|
+
declare function toStreamHandler<Req, Res, EO extends {
|
|
479
491
|
raw?: any;
|
|
480
492
|
} = any>(handler: (context: {
|
|
481
|
-
payload: Req
|
|
493
|
+
payload: Req;
|
|
482
494
|
options?: EO;
|
|
483
|
-
emit: (data: Res
|
|
484
|
-
}) => Promise<void>): StreamHandler<Res
|
|
495
|
+
emit: (data: Res) => void;
|
|
496
|
+
}) => Promise<void>): StreamHandler<Res, Req, EO>;
|
|
485
497
|
//#endregion
|
|
486
498
|
//#region src/utils.d.ts
|
|
487
499
|
declare function randomBetween(min: number, max: number): number;
|
|
@@ -518,5 +530,5 @@ declare function createUntil<T>(options?: {
|
|
|
518
530
|
handler: (value: T) => void;
|
|
519
531
|
};
|
|
520
532
|
//#endregion
|
|
521
|
-
export {
|
|
522
|
-
//# sourceMappingURL=index-
|
|
533
|
+
export { isReceiveEvent as $, defineInvokeHandlers as A, InferSendEventStreamEnd as B, Handler as C, InvokeFunctionMap as D, InvokeFunction as E, InferReceiveEventError as F, ReceiveEventError as G, InvokeEventa as H, InferReceiveEventStreamEnd as I, SendEventAbort as J, ReceiveEventStreamEnd as K, InferSendEvent as L, isExtendableInvokeResponseLike as M, undefineInvokeHandler as N, defineInvoke as O, InferReceiveEvent as P, isInvokeEventa as Q, InferSendEventAbort as R, ExtractInvokeResponseOptions as S, InvocableEventContext as T, InvokeHandlerEventa as U, InvokeEventType as V, ReceiveEvent as W, SendEventStreamEnd as X, SendEventError as Y, defineInvokeEventa as Z, withRemoteMethods as _, isAbortError as a, ExtendableInvokeResponse as b, randomBetween as c, toStreamHandler as d, isSendEvent as et, InvokeFunctionStubOptions as f, createRemoteMethodTagPrefix as g, RemoteInvokeResult as h, createUntilTriggeredOnce as i, defineInvokes as j, defineInvokeHandler as k, defineStreamInvoke as l, RemoteInvokeOptions as m, createUntil as n, isAsyncIterable as o, RemoteInvokeFunction as p, SendEvent as q, createUntilTriggered as r, isReadableStream as s, createAbortError as t, defineStreamInvokeHandler as u, WithTransfer as v, HandlerMap as w, ExtractInvokeRequestOptions as x, withTransfer as y, InferSendEventError as z };
|
|
534
|
+
//# sourceMappingURL=index-g6DulgOI.d.mts.map
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as nanoid, a as EventaLike, c as InboundEventa, d as OutboundEventa, f as and, g as matchBy, h as defineOutboundEventa, i as EventaFlowDirection, l as InferEventaPayload, m as defineInboundEventa, n as EventTag, o as EventaMatchExpression, p as defineEventa, r as Eventa, s as EventaType, t as DirectionalEventa, u as InvokeEventConstraint, v as or } from "./eventa-
|
|
2
|
-
import { n as EventContextEmitFn, r as createContext, t as EventContext } from "./context-
|
|
3
|
-
import { $ as
|
|
4
|
-
export { DirectionalEventa, EventContext, EventContextEmitFn, EventTag, Eventa, EventaFlowDirection, EventaLike, EventaMatchExpression, EventaType, ExtendableInvokeResponse, ExtractInvokeRequestOptions, ExtractInvokeResponseOptions, Handler, HandlerMap, InboundEventa, InferEventaPayload, InferReceiveEvent, InferReceiveEventError, InferReceiveEventStreamEnd, InferSendEvent, InferSendEventAbort, InferSendEventError, InferSendEventStreamEnd, InvocableEventContext, InvokeEventConstraint, InvokeEventType, InvokeEventa, InvokeFunction, InvokeFunctionMap, InvokeFunctionStubOptions, OutboundEventa, ReceiveEvent, ReceiveEventError, ReceiveEventStreamEnd, RemoteInvokeFunction, RemoteInvokeOptions, RemoteInvokeResult, SendEvent, SendEventAbort, SendEventError, SendEventStreamEnd, WithTransfer, and, createAbortError, createContext, createRemoteMethodTagPrefix, createUntil, createUntilTriggered, createUntilTriggeredOnce, defineEventa, defineInboundEventa, defineInvoke, defineInvokeEventa, defineInvokeHandler, defineInvokeHandlers, defineInvokes, defineOutboundEventa, defineStreamInvoke, defineStreamInvokeHandler, isAbortError, isAsyncIterable, isExtendableInvokeResponseLike, isInvokeEventa, isReadableStream, isReceiveEvent, isSendEvent, matchBy, nanoid, or, randomBetween, toStreamHandler, undefineInvokeHandler, withRemoteMethods, withTransfer };
|
|
1
|
+
import { _ as nanoid, a as EventaLike, c as InboundEventa, d as OutboundEventa, f as and, g as matchBy, h as defineOutboundEventa, i as EventaFlowDirection, l as InferEventaPayload, m as defineInboundEventa, n as EventTag, o as EventaMatchExpression, p as defineEventa, r as Eventa, s as EventaType, t as DirectionalEventa, u as InvokeEventConstraint, v as or } from "./eventa-DSnoBa1O.mjs";
|
|
2
|
+
import { n as EventContextEmitFn, r as createContext, t as EventContext } from "./context-BsqFeoer.mjs";
|
|
3
|
+
import { $ as isReceiveEvent, A as defineInvokeHandlers, B as InferSendEventStreamEnd, C as Handler, D as InvokeFunctionMap, E as InvokeFunction, F as InferReceiveEventError, G as ReceiveEventError, H as InvokeEventa, I as InferReceiveEventStreamEnd, J as SendEventAbort, K as ReceiveEventStreamEnd, L as InferSendEvent, M as isExtendableInvokeResponseLike, N as undefineInvokeHandler, O as defineInvoke, P as InferReceiveEvent, Q as isInvokeEventa, R as InferSendEventAbort, S as ExtractInvokeResponseOptions, T as InvocableEventContext, U as InvokeHandlerEventa, V as InvokeEventType, W as ReceiveEvent, X as SendEventStreamEnd, Y as SendEventError, Z as defineInvokeEventa, _ as withRemoteMethods, a as isAbortError, b as ExtendableInvokeResponse, c as randomBetween, d as toStreamHandler, et as isSendEvent, f as InvokeFunctionStubOptions, g as createRemoteMethodTagPrefix, h as RemoteInvokeResult, i as createUntilTriggeredOnce, j as defineInvokes, k as defineInvokeHandler, l as defineStreamInvoke, m as RemoteInvokeOptions, n as createUntil, o as isAsyncIterable, p as RemoteInvokeFunction, q as SendEvent, r as createUntilTriggered, s as isReadableStream, t as createAbortError, u as defineStreamInvokeHandler, v as WithTransfer, w as HandlerMap, x as ExtractInvokeRequestOptions, y as withTransfer, z as InferSendEventError } from "./index-g6DulgOI.mjs";
|
|
4
|
+
export { DirectionalEventa, EventContext, EventContextEmitFn, EventTag, Eventa, EventaFlowDirection, EventaLike, EventaMatchExpression, EventaType, ExtendableInvokeResponse, ExtractInvokeRequestOptions, ExtractInvokeResponseOptions, Handler, HandlerMap, InboundEventa, InferEventaPayload, InferReceiveEvent, InferReceiveEventError, InferReceiveEventStreamEnd, InferSendEvent, InferSendEventAbort, InferSendEventError, InferSendEventStreamEnd, InvocableEventContext, InvokeEventConstraint, InvokeEventType, InvokeEventa, InvokeFunction, InvokeFunctionMap, InvokeFunctionStubOptions, InvokeHandlerEventa, OutboundEventa, ReceiveEvent, ReceiveEventError, ReceiveEventStreamEnd, RemoteInvokeFunction, RemoteInvokeOptions, RemoteInvokeResult, SendEvent, SendEventAbort, SendEventError, SendEventStreamEnd, WithTransfer, and, createAbortError, createContext, createRemoteMethodTagPrefix, createUntil, createUntilTriggered, createUntilTriggeredOnce, defineEventa, defineInboundEventa, defineInvoke, defineInvokeEventa, defineInvokeHandler, defineInvokeHandlers, defineInvokes, defineOutboundEventa, defineStreamInvoke, defineStreamInvokeHandler, isAbortError, isAsyncIterable, isExtendableInvokeResponseLike, isInvokeEventa, isReadableStream, isReceiveEvent, isSendEvent, matchBy, nanoid, or, randomBetween, toStreamHandler, undefineInvokeHandler, withRemoteMethods, withTransfer };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
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, u as or } from "./context-
|
|
2
|
-
import { C as isInvokeEventa, S as defineInvokeEventa, T as isSendEvent, _ as isAbortError, a as withRemoteMethods, b as randomBetween, c as defineInvokeHandler, d as isExtendableInvokeResponseLike, f as undefineInvokeHandler, g as createUntilTriggeredOnce, h as createUntilTriggered, i as createRemoteMethodTagPrefix, l as defineInvokeHandlers, m as createUntil, n as defineStreamInvokeHandler, o as withTransfer, p as createAbortError, r as toStreamHandler, s as defineInvoke, t as defineStreamInvoke, u as defineInvokes, v as isAsyncIterable, w as isReceiveEvent, x as InvokeEventType, y as isReadableStream } from "./src-
|
|
3
|
-
|
|
4
|
-
export { EventaFlowDirection, EventaType, InvokeEventType, and, createAbortError, createContext, createRemoteMethodTagPrefix, createUntil, createUntilTriggered, createUntilTriggeredOnce, defineEventa, defineInboundEventa, defineInvoke, defineInvokeEventa, defineInvokeHandler, defineInvokeHandlers, defineInvokes, defineOutboundEventa, defineStreamInvoke, defineStreamInvokeHandler, isAbortError, isAsyncIterable, isExtendableInvokeResponseLike, isInvokeEventa, isReadableStream, isReceiveEvent, isSendEvent, matchBy, nanoid, or, randomBetween, toStreamHandler, undefineInvokeHandler, withRemoteMethods, withTransfer };
|
|
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, u as or } from "./context-Dht_IZMb.mjs";
|
|
2
|
+
import { C as isInvokeEventa, S as defineInvokeEventa, T as isSendEvent, _ as isAbortError, a as withRemoteMethods, b as randomBetween, c as defineInvokeHandler, d as isExtendableInvokeResponseLike, f as undefineInvokeHandler, g as createUntilTriggeredOnce, h as createUntilTriggered, i as createRemoteMethodTagPrefix, l as defineInvokeHandlers, m as createUntil, n as defineStreamInvokeHandler, o as withTransfer, p as createAbortError, r as toStreamHandler, s as defineInvoke, t as defineStreamInvoke, u as defineInvokes, v as isAsyncIterable, w as isReceiveEvent, x as InvokeEventType, y as isReadableStream } from "./src-CTs6h4Ci.mjs";
|
|
3
|
+
export { EventaFlowDirection, EventaType, InvokeEventType, and, createAbortError, createContext, createRemoteMethodTagPrefix, createUntil, createUntilTriggered, createUntilTriggeredOnce, defineEventa, defineInboundEventa, defineInvoke, defineInvokeEventa, defineInvokeHandler, defineInvokeHandlers, defineInvokes, defineOutboundEventa, defineStreamInvoke, defineStreamInvokeHandler, isAbortError, isAsyncIterable, isExtendableInvokeResponseLike, isInvokeEventa, isReadableStream, isReceiveEvent, isSendEvent, matchBy, nanoid, or, randomBetween, toStreamHandler, undefineInvokeHandler, withRemoteMethods, withTransfer };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { l as nanoid } from "./context-
|
|
2
|
-
|
|
1
|
+
import { l as nanoid } from "./context-Dht_IZMb.mjs";
|
|
3
2
|
//#region src/adapters/websocket/internal.ts
|
|
4
3
|
function generateWebsocketPayload(type, payload) {
|
|
5
4
|
return {
|
|
@@ -12,7 +11,7 @@ function generateWebsocketPayload(type, payload) {
|
|
|
12
11
|
function parseWebsocketPayload(data) {
|
|
13
12
|
return JSON.parse(data);
|
|
14
13
|
}
|
|
15
|
-
|
|
16
14
|
//#endregion
|
|
17
15
|
export { parseWebsocketPayload as n, generateWebsocketPayload as t };
|
|
18
|
-
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=internal-CHUsXYiP.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal-
|
|
1
|
+
{"version":3,"file":"internal-CHUsXYiP.mjs","names":[],"sources":["../src/adapters/websocket/internal.ts"],"sourcesContent":["import type { EventTag } from '../../eventa'\nimport type { WebsocketPayload } from './shared'\n\nimport { nanoid } from '../../eventa'\n\nexport function generateWebsocketPayload<T>(type: EventTag<any, any>, payload: T): WebsocketPayload<T> {\n return {\n id: nanoid(),\n type,\n payload,\n timestamp: Date.now(),\n }\n}\n\nexport function parseWebsocketPayload<T>(data: string): WebsocketPayload<T> {\n return JSON.parse(data) as WebsocketPayload<T>\n}\n"],"mappings":";;AAKA,SAAgB,yBAA4B,MAA0B,SAAiC;AACrG,QAAO;EACL,IAAI,QAAQ;EACZ;EACA;EACA,WAAW,KAAK,KAAK;EACtB;;AAGH,SAAgB,sBAAyB,MAAmC;AAC1E,QAAO,KAAK,MAAM,KAAK"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { a as defineEventa, l as nanoid, s as defineOutboundEventa } from "./context-
|
|
2
|
-
import { d as isExtendableInvokeResponseLike } from "./src-
|
|
3
|
-
|
|
1
|
+
import { a as defineEventa, l as nanoid, s as defineOutboundEventa } from "./context-Dht_IZMb.mjs";
|
|
2
|
+
import { d as isExtendableInvokeResponseLike } from "./src-CTs6h4Ci.mjs";
|
|
4
3
|
//#region src/adapters/webworkers/internal.ts
|
|
5
4
|
function generateWorkerPayload(type, payload) {
|
|
6
5
|
return {
|
|
@@ -12,7 +11,6 @@ function generateWorkerPayload(type, payload) {
|
|
|
12
11
|
function parseWorkerPayload(data) {
|
|
13
12
|
return data;
|
|
14
13
|
}
|
|
15
|
-
|
|
16
14
|
//#endregion
|
|
17
15
|
//#region src/adapters/webworkers/shared.ts
|
|
18
16
|
function defineWorkerEventa(id) {
|
|
@@ -31,7 +29,7 @@ function isWorkerEventa(event) {
|
|
|
31
29
|
return typeof event === "object" && "_workerTransfer" in event && typeof event._workerTransfer === "boolean" && event._workerTransfer === true;
|
|
32
30
|
}
|
|
33
31
|
const workerErrorEvent = defineEventa();
|
|
34
|
-
|
|
32
|
+
defineEventa();
|
|
35
33
|
function normalizeOnListenerParameters(event, options) {
|
|
36
34
|
let eventPayload = event.body;
|
|
37
35
|
let transfer;
|
|
@@ -59,7 +57,7 @@ function normalizeOnListenerParameters(event, options) {
|
|
|
59
57
|
transfer
|
|
60
58
|
};
|
|
61
59
|
}
|
|
62
|
-
|
|
63
60
|
//#endregion
|
|
64
61
|
export { workerErrorEvent as a, normalizeOnListenerParameters as i, defineWorkerEventa as n, generateWorkerPayload as o, isWorkerEventa as r, parseWorkerPayload as s, defineOutboundWorkerEventa as t };
|
|
65
|
-
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=shared-CA5MGwv0.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-CA5MGwv0.mjs","names":[],"sources":["../src/adapters/webworkers/internal.ts","../src/adapters/webworkers/shared.ts"],"sourcesContent":["import type { EventTag } from '../..'\nimport type { WorkerPayload } from './shared'\n\nimport { nanoid } from '../..'\n\nexport function generateWorkerPayload<T>(type: EventTag<any, any>, payload: T): WorkerPayload<T> {\n return {\n id: nanoid(),\n type,\n payload,\n }\n}\n\nexport function parseWorkerPayload<T>(data: unknown): WorkerPayload<T> {\n return data as WorkerPayload<T>\n}\n","import type { EventContext } from '../../context'\nimport type { Eventa, EventTag } from '../../eventa'\n\nimport { defineEventa, defineOutboundEventa } from '../../eventa'\nimport { isExtendableInvokeResponseLike } from '../../invoke'\n\nexport interface WorkerPayload<T> {\n id: string\n type: EventTag<any, any>\n payload: T\n transfer?: Transferable[]\n}\n\nexport interface WorkerEventa<T> extends Eventa<{ message: T, transfer?: Transferable[] }> {\n _workerTransfer: true\n}\n\nexport function defineWorkerEventa<T>(id?: string): WorkerEventa<T> {\n return {\n ...defineEventa<{ message: T, transfer?: Transferable[] }>(id),\n _workerTransfer: true,\n }\n}\n\nexport function defineOutboundWorkerEventa<T>(id?: string): WorkerEventa<T> {\n return {\n ...defineOutboundEventa<{ message: T, transfer?: Transferable[] }>(id),\n _workerTransfer: true,\n }\n}\n\nexport function isWorkerEventa(event: Eventa<any>): event is WorkerEventa<any> {\n return typeof event === 'object'\n && '_workerTransfer' in event\n && typeof event._workerTransfer === 'boolean'\n && event._workerTransfer === true\n}\n\nexport const workerErrorEvent = defineEventa<{ error: unknown }>()\nexport const workerMessageErrorEvent = defineEventa<{ error: unknown, message: any }>()\n\nexport function normalizeOnListenerParameters(event: Eventa<any>, options?: { transfer?: Transferable[] } | unknown) {\n let eventPayload: any = event.body\n let transfer: Transferable[] | undefined\n\n if (isExtendableInvokeResponseLike<unknown, EventContext<{ invokeResponse?: { transfer?: Transferable[] } }>>(event)) {\n if (event.body!.content.invokeResponse?.transfer != null) {\n transfer = event.body!.content.invokeResponse!.transfer\n delete event.body!.content.invokeResponse\n }\n\n eventPayload = { ...event.body, content: event.body!.content.response }\n delete eventPayload.content.response\n }\n else if (isWorkerEventa(event)) {\n transfer = event.body?.transfer\n delete event.body?.transfer\n\n eventPayload = event.body?.message\n delete event.body?.message\n }\n\n // Override from options\n if (typeof options !== 'undefined' && options != null && typeof options === 'object' && 'transfer' in options) {\n if (Array.isArray(options.transfer)) {\n transfer = options.transfer\n }\n }\n\n return {\n body: eventPayload,\n transfer,\n }\n}\n"],"mappings":";;;AAKA,SAAgB,sBAAyB,MAA0B,SAA8B;AAC/F,QAAO;EACL,IAAI,QAAQ;EACZ;EACA;EACD;;AAGH,SAAgB,mBAAsB,MAAiC;AACrE,QAAO;;;;ACGT,SAAgB,mBAAsB,IAA8B;AAClE,QAAO;EACL,GAAG,aAAwD,GAAG;EAC9D,iBAAiB;EAClB;;AAGH,SAAgB,2BAA8B,IAA8B;AAC1E,QAAO;EACL,GAAG,qBAAgE,GAAG;EACtE,iBAAiB;EAClB;;AAGH,SAAgB,eAAe,OAAgD;AAC7E,QAAO,OAAO,UAAU,YACnB,qBAAqB,SACrB,OAAO,MAAM,oBAAoB,aACjC,MAAM,oBAAoB;;AAGjC,MAAa,mBAAmB,cAAkC;AAC3B,cAAgD;AAEvF,SAAgB,8BAA8B,OAAoB,SAAmD;CACnH,IAAI,eAAoB,MAAM;CAC9B,IAAI;AAEJ,KAAI,+BAA0G,MAAM,EAAE;AACpH,MAAI,MAAM,KAAM,QAAQ,gBAAgB,YAAY,MAAM;AACxD,cAAW,MAAM,KAAM,QAAQ,eAAgB;AAC/C,UAAO,MAAM,KAAM,QAAQ;;AAG7B,iBAAe;GAAE,GAAG,MAAM;GAAM,SAAS,MAAM,KAAM,QAAQ;GAAU;AACvE,SAAO,aAAa,QAAQ;YAErB,eAAe,MAAM,EAAE;AAC9B,aAAW,MAAM,MAAM;AACvB,SAAO,MAAM,MAAM;AAEnB,iBAAe,MAAM,MAAM;AAC3B,SAAO,MAAM,MAAM;;AAIrB,KAAI,OAAO,YAAY,eAAe,WAAW,QAAQ,OAAO,YAAY,YAAY,cAAc;MAChG,MAAM,QAAQ,QAAQ,SAAS,CACjC,YAAW,QAAQ;;AAIvB,QAAO;EACL,MAAM;EACN;EACD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as EventTag, r as Eventa } from "./eventa-
|
|
1
|
+
import { n as EventTag, r as Eventa } from "./eventa-DSnoBa1O.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/adapters/webworkers/shared.d.ts
|
|
4
4
|
interface WorkerPayload<T> {
|
|
@@ -18,11 +18,11 @@ declare function defineOutboundWorkerEventa<T>(id?: string): WorkerEventa<T>;
|
|
|
18
18
|
declare function isWorkerEventa(event: Eventa<any>): event is WorkerEventa<any>;
|
|
19
19
|
declare const workerErrorEvent: Eventa<{
|
|
20
20
|
error: unknown;
|
|
21
|
-
}>;
|
|
21
|
+
}, undefined, undefined>;
|
|
22
22
|
declare const workerMessageErrorEvent: Eventa<{
|
|
23
23
|
error: unknown;
|
|
24
24
|
message: any;
|
|
25
|
-
}>;
|
|
25
|
+
}, undefined, undefined>;
|
|
26
26
|
declare function normalizeOnListenerParameters(event: Eventa<any>, options?: {
|
|
27
27
|
transfer?: Transferable[];
|
|
28
28
|
} | unknown): {
|
|
@@ -31,4 +31,4 @@ declare function normalizeOnListenerParameters(event: Eventa<any>, options?: {
|
|
|
31
31
|
};
|
|
32
32
|
//#endregion
|
|
33
33
|
export { isWorkerEventa as a, workerMessageErrorEvent as c, defineWorkerEventa as i, WorkerPayload as n, normalizeOnListenerParameters as o, defineOutboundWorkerEventa as r, workerErrorEvent as s, WorkerEventa as t };
|
|
34
|
-
//# sourceMappingURL=shared-
|
|
34
|
+
//# sourceMappingURL=shared-CVTLm458.d.mts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as EventTag, s as EventaType } from "./eventa-
|
|
1
|
+
import { n as EventTag, s as EventaType } from "./eventa-DSnoBa1O.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/adapters/electron/shared.d.ts
|
|
4
4
|
interface Payload<T> {
|
|
@@ -10,9 +10,11 @@ declare const errorEvent: {
|
|
|
10
10
|
body?: {
|
|
11
11
|
error: unknown;
|
|
12
12
|
} | undefined;
|
|
13
|
+
metadata?: undefined;
|
|
14
|
+
invokeMetadata?: undefined;
|
|
13
15
|
id: string;
|
|
14
16
|
type?: EventaType.Event | undefined;
|
|
15
17
|
};
|
|
16
18
|
//#endregion
|
|
17
19
|
export { errorEvent as n, Payload as t };
|
|
18
|
-
//# sourceMappingURL=shared-
|
|
20
|
+
//# sourceMappingURL=shared-CfXZb-7K.d.mts.map
|