@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
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
import { n as EventTag, r as Eventa } from "./eventa-AJyw28P8.mjs";
|
|
2
|
+
import { t as EventContext } from "./context-ZVv99bcM.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/invoke-shared.d.ts
|
|
5
|
+
declare enum InvokeEventType {
|
|
6
|
+
SendEvent = 0,
|
|
7
|
+
SendEventError = 1,
|
|
8
|
+
SendEventStreamEnd = 2,
|
|
9
|
+
SendEventAbort = 3,
|
|
10
|
+
ReceiveEvent = 4,
|
|
11
|
+
ReceiveEventError = 5,
|
|
12
|
+
ReceiveEventStreamEnd = 6,
|
|
13
|
+
}
|
|
14
|
+
interface SendEvent<Res$1, Req$1 = undefined, _ = undefined, __ = undefined> extends Eventa<{
|
|
15
|
+
invokeId: string;
|
|
16
|
+
content: Req$1;
|
|
17
|
+
isReqStream?: boolean;
|
|
18
|
+
}> {
|
|
19
|
+
id: EventTag<Res$1, Req$1>;
|
|
20
|
+
invokeType: InvokeEventType.SendEvent;
|
|
21
|
+
}
|
|
22
|
+
interface SendEventError<Res$1, Req$1 = undefined, _ = undefined, ReqErr$1 = Error> extends Eventa<{
|
|
23
|
+
invokeId: string;
|
|
24
|
+
content: ReqErr$1;
|
|
25
|
+
}> {
|
|
26
|
+
id: EventTag<Res$1, Req$1>;
|
|
27
|
+
invokeType: InvokeEventType.SendEventError;
|
|
28
|
+
}
|
|
29
|
+
interface SendEventStreamEnd<Res$1, Req$1 = undefined, _ = undefined, __ = undefined> extends Eventa<{
|
|
30
|
+
invokeId: string;
|
|
31
|
+
content: undefined;
|
|
32
|
+
}> {
|
|
33
|
+
id: EventTag<Res$1, Req$1>;
|
|
34
|
+
invokeType: InvokeEventType.SendEventStreamEnd;
|
|
35
|
+
}
|
|
36
|
+
interface SendEventAbort<Res$1, Req$1 = undefined, _ = undefined, __ = undefined> extends Eventa<{
|
|
37
|
+
invokeId: string;
|
|
38
|
+
content?: unknown;
|
|
39
|
+
}> {
|
|
40
|
+
id: EventTag<Res$1, Req$1>;
|
|
41
|
+
invokeType: InvokeEventType.SendEventAbort;
|
|
42
|
+
}
|
|
43
|
+
interface ReceiveEvent<Res$1, Req$1 = undefined, _ = undefined, __ = undefined> extends Eventa<{
|
|
44
|
+
invokeId: string;
|
|
45
|
+
content: Res$1;
|
|
46
|
+
}> {
|
|
47
|
+
id: EventTag<Res$1, Req$1>;
|
|
48
|
+
invokeType: InvokeEventType.ReceiveEvent;
|
|
49
|
+
}
|
|
50
|
+
interface ReceiveEventError<Res$1, Req$1 = undefined, ResErr$1 = undefined, _ = undefined> extends Eventa<{
|
|
51
|
+
invokeId: string;
|
|
52
|
+
content: {
|
|
53
|
+
error: ResErr$1;
|
|
54
|
+
};
|
|
55
|
+
}> {
|
|
56
|
+
id: EventTag<Res$1, Req$1>;
|
|
57
|
+
invokeType: InvokeEventType.ReceiveEventError;
|
|
58
|
+
}
|
|
59
|
+
interface ReceiveEventStreamEnd<Res$1, Req$1 = undefined, _ = undefined, __ = undefined> extends Eventa<{
|
|
60
|
+
invokeId: string;
|
|
61
|
+
content: undefined;
|
|
62
|
+
}> {
|
|
63
|
+
id: EventTag<Res$1, Req$1>;
|
|
64
|
+
invokeType: InvokeEventType.ReceiveEventStreamEnd;
|
|
65
|
+
}
|
|
66
|
+
interface InvokeEventa<Res$1, Req$1 = undefined, ResErr$1 = Error, ReqErr$1 = Error> {
|
|
67
|
+
sendEvent: SendEvent<Res$1, Req$1, ResErr$1, ReqErr$1>;
|
|
68
|
+
sendEventError: SendEventError<Res$1, Req$1, ResErr$1, ReqErr$1>;
|
|
69
|
+
sendEventStreamEnd: SendEventStreamEnd<Res$1, Req$1, ResErr$1, ReqErr$1>;
|
|
70
|
+
sendEventAbort: SendEventAbort<Res$1, Req$1, ResErr$1, ReqErr$1>;
|
|
71
|
+
receiveEvent: ReceiveEvent<Res$1, Req$1, ResErr$1, ReqErr$1>;
|
|
72
|
+
receiveEventError: ReceiveEventError<Res$1, Req$1, ResErr$1, ReqErr$1>;
|
|
73
|
+
receiveEventStreamEnd: ReceiveEventStreamEnd<Res$1, Req$1, ResErr$1, ReqErr$1>;
|
|
74
|
+
}
|
|
75
|
+
type InferSendEvent<T> = T extends {
|
|
76
|
+
sendEvent: SendEvent<infer Res, infer Req, infer ResErr, infer ReqErr>;
|
|
77
|
+
} ? SendEvent<Res, Req, ResErr, ReqErr> : never;
|
|
78
|
+
type InferSendEventError<T> = T extends {
|
|
79
|
+
sendEventError: SendEventError<infer Res, infer Req, infer ResErr, infer ReqErr>;
|
|
80
|
+
} ? SendEventError<Res, Req, ResErr, ReqErr> : never;
|
|
81
|
+
type InferSendEventStreamEnd<T> = T extends {
|
|
82
|
+
sendEventStreamEnd: SendEventStreamEnd<infer Res, infer Req, infer ResErr, infer ReqErr>;
|
|
83
|
+
} ? SendEventStreamEnd<Res, Req, ResErr, ReqErr> : never;
|
|
84
|
+
type InferSendEventAbort<T> = T extends {
|
|
85
|
+
sendEventAbort: SendEventAbort<infer Res, infer Req, infer ResErr, infer ReqErr>;
|
|
86
|
+
} ? SendEventAbort<Res, Req, ResErr, ReqErr> : never;
|
|
87
|
+
type InferReceiveEvent<T> = T extends {
|
|
88
|
+
receiveEvent: ReceiveEvent<infer Res, infer Req, infer ResErr, infer ReqErr>;
|
|
89
|
+
} ? ReceiveEvent<Res, Req, ResErr, ReqErr> : never;
|
|
90
|
+
type InferReceiveEventError<T> = T extends {
|
|
91
|
+
receiveEventError: ReceiveEventError<infer Res, infer Req, infer ResErr, infer ReqErr>;
|
|
92
|
+
} ? ReceiveEventError<Res, Req, ResErr, ReqErr> : never;
|
|
93
|
+
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$1, Req$1 = undefined, ResErr$1 = Error, ReqErr$1 = Error>(tag?: string): {
|
|
97
|
+
sendEvent: SendEvent<Res$1, Req$1, ResErr$1, ReqErr$1>;
|
|
98
|
+
sendEventError: SendEventError<Res$1, Req$1, ResErr$1, ReqErr$1>;
|
|
99
|
+
sendEventStreamEnd: SendEventStreamEnd<Res$1, Req$1, ResErr$1, ReqErr$1>;
|
|
100
|
+
sendEventAbort: SendEventAbort<Res$1, Req$1, ResErr$1, ReqErr$1>;
|
|
101
|
+
receiveEvent: ReceiveEvent<Res$1, Req$1, ResErr$1, ReqErr$1>;
|
|
102
|
+
receiveEventError: ReceiveEventError<Res$1, Req$1, ResErr$1, ReqErr$1>;
|
|
103
|
+
receiveEventStreamEnd: ReceiveEventStreamEnd<Res$1, Req$1, ResErr$1, ReqErr$1>;
|
|
104
|
+
};
|
|
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>;
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/invoke.d.ts
|
|
110
|
+
type IsInvokeRequestOptional<EC extends EventContext<any, any>> = EC extends EventContext<infer E, any> ? E extends {
|
|
111
|
+
invokeRequest: any;
|
|
112
|
+
} ? undefined extends E['invokeRequest'] ? true : false : E extends {
|
|
113
|
+
invokeRequest?: any;
|
|
114
|
+
} ? undefined extends E['invokeRequest'] ? true : false : true : true;
|
|
115
|
+
type ExtractInvokeRequestOptions<EC extends EventContext<any, any>> = EC extends EventContext<infer E, any> ? E extends {
|
|
116
|
+
invokeRequest: infer IR;
|
|
117
|
+
} ? IR & {
|
|
118
|
+
signal?: AbortSignal;
|
|
119
|
+
} : E extends {
|
|
120
|
+
invokeRequest?: infer IR;
|
|
121
|
+
} ? IR & {
|
|
122
|
+
signal?: AbortSignal;
|
|
123
|
+
} : {
|
|
124
|
+
signal?: AbortSignal;
|
|
125
|
+
} : {
|
|
126
|
+
signal?: AbortSignal;
|
|
127
|
+
};
|
|
128
|
+
type ExtractInvokeResponseOptions<EC extends EventContext<any, any>> = EC extends EventContext<infer E, any> ? E extends {
|
|
129
|
+
invokeResponse: infer IR;
|
|
130
|
+
} ? IR : E extends {
|
|
131
|
+
invokeResponse?: infer IR;
|
|
132
|
+
} ? IR : undefined : undefined;
|
|
133
|
+
type InvokeFunction<Res$1, Req$1, EC extends EventContext<any, any>> = [Req$1] extends [undefined] ? IsInvokeRequestOptional<EC> extends true ? (req?: Req$1, options?: ExtractInvokeRequestOptions<EC>) => Promise<Res$1> : (req: Req$1, options: ExtractInvokeRequestOptions<EC>) => Promise<Res$1> : IsInvokeRequestOptional<EC> extends true ? (req: Req$1, options?: ExtractInvokeRequestOptions<EC>) => Promise<Res$1> : (req: Req$1, options: ExtractInvokeRequestOptions<EC>) => Promise<Res$1>;
|
|
134
|
+
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$1, EC extends EventContext<any, any>> = Promise<Res$1> | Res$1 | Promise<{
|
|
136
|
+
response: Res$1;
|
|
137
|
+
invokeResponse?: ExtractInvokeResponseOptions<EC>;
|
|
138
|
+
}> | {
|
|
139
|
+
response: Res$1;
|
|
140
|
+
invokeResponse?: ExtractInvokeResponseOptions<EC>;
|
|
141
|
+
};
|
|
142
|
+
declare function isExtendableInvokeResponseLike<Res$1, EC extends EventContext<any, any>>(value: Eventa<unknown> | ReceiveEvent<{
|
|
143
|
+
response: Res$1;
|
|
144
|
+
invokeResponse?: unknown;
|
|
145
|
+
}>): value is ReceiveEvent<{
|
|
146
|
+
response: Res$1;
|
|
147
|
+
invokeResponse?: ExtractInvokeResponseOptions<EC>;
|
|
148
|
+
}>;
|
|
149
|
+
type Handler<Res$1, Req$1 = any, EC extends EventContext<any, any> = EventContext<any, any>, RawEventOptions = unknown> = (payload: Req$1, options?: {
|
|
150
|
+
abortController?: AbortController;
|
|
151
|
+
} & RawEventOptions) => ExtendableInvokeResponse<Res$1, EC>;
|
|
152
|
+
interface InternalInvokeHandler<Res$1, Req$1 = any, ResErr$1 = Error, ReqErr$1 = Error, EO = any> {
|
|
153
|
+
onSend: (params: InvokeEventa<Res$1, Req$1, ResErr$1, ReqErr$1>['sendEvent'], eventOptions?: EO) => void;
|
|
154
|
+
onSendStreamEnd: (params: InvokeEventa<Res$1, Req$1, ResErr$1, ReqErr$1>['sendEventStreamEnd'], eventOptions?: EO) => void;
|
|
155
|
+
onSendAbort: (params: InvokeEventa<Res$1, Req$1, ResErr$1, ReqErr$1>['sendEventAbort'], eventOptions?: EO) => void;
|
|
156
|
+
}
|
|
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$1, EO> extends EventContext<E$1, EO> {
|
|
159
|
+
invokeHandlers?: Map<string, Map<Handler<any>, InternalInvokeHandler<any>>>;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Create a unary invoke function (client side).
|
|
163
|
+
*
|
|
164
|
+
* It supports unary or streaming requests, but returns a single response.
|
|
165
|
+
* Use `defineStreamInvoke` when you expect a stream of responses.
|
|
166
|
+
*
|
|
167
|
+
* If you want stream input, set `Req` to `ReadableStream<T>` or `AsyncIterable<T>`
|
|
168
|
+
* (or a union type like `T | ReadableStream<T>` for optional streaming).
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* // 1) Define eventa once (shared by client/server)
|
|
173
|
+
* const events = defineInvokeEventa<{ id: string }, { name: string }>()
|
|
174
|
+
*
|
|
175
|
+
* // 2) Client: define invoke function
|
|
176
|
+
* const invoke = defineInvoke(clientCtx, events)
|
|
177
|
+
*
|
|
178
|
+
* // 3) Call
|
|
179
|
+
* const res = await invoke({ name: 'alice' })
|
|
180
|
+
* ```
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```ts
|
|
184
|
+
* // Stream request -> unary response
|
|
185
|
+
* const events = defineInvokeEventa<number, ReadableStream<number>>()
|
|
186
|
+
*
|
|
187
|
+
* defineInvokeHandler(serverCtx, events, async (payload) => {
|
|
188
|
+
* let sum = 0
|
|
189
|
+
* for await (const value of payload) {
|
|
190
|
+
* sum += value
|
|
191
|
+
* }
|
|
192
|
+
*
|
|
193
|
+
* return sum
|
|
194
|
+
* })
|
|
195
|
+
*
|
|
196
|
+
* const invoke = defineInvoke(clientCtx, events)
|
|
197
|
+
* const input = new ReadableStream<number>({
|
|
198
|
+
* start(controller) {
|
|
199
|
+
* controller.enqueue(1)
|
|
200
|
+
* controller.enqueue(2)
|
|
201
|
+
* controller.close()
|
|
202
|
+
* },
|
|
203
|
+
* })
|
|
204
|
+
*
|
|
205
|
+
* const total = await invoke(input)
|
|
206
|
+
* ```
|
|
207
|
+
*
|
|
208
|
+
* @param ctx Event context on the caller/client side.
|
|
209
|
+
* @param event Invoke event definition created by `defineInvokeEventa`.
|
|
210
|
+
*/
|
|
211
|
+
declare function defineInvoke<Res$1, Req$1 = undefined, ResErr$1 = Error, ReqErr$1 = Error, CtxExt = any, EOpts = any, ECtx extends EventContext<CtxExt, EOpts> = EventContext<CtxExt, EOpts>>(ctx: ECtx | (() => ECtx | Promise<ECtx>), event: InvokeEventa<Res$1, Req$1, ResErr$1, ReqErr$1>): InvokeFunction<Res$1, Req$1, ECtx>;
|
|
212
|
+
/**
|
|
213
|
+
* Create a map of invoke functions from a map of invoke events (client side).
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```ts
|
|
217
|
+
* const events = {
|
|
218
|
+
* double: defineInvokeEventa<number, number>(),
|
|
219
|
+
* greet: defineInvokeEventa<string, { name: string }>(),
|
|
220
|
+
* }
|
|
221
|
+
*
|
|
222
|
+
* const invokes = defineInvokes(ctx, events)
|
|
223
|
+
* const result = await invokes.double(2)
|
|
224
|
+
* ```
|
|
225
|
+
*
|
|
226
|
+
* @param ctx Event context on the caller/client side.
|
|
227
|
+
* @param events Map of invoke events created by `defineInvokeEventa`.
|
|
228
|
+
*/
|
|
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>;
|
|
230
|
+
/**
|
|
231
|
+
* Define a unary invoke handler (server side).
|
|
232
|
+
*
|
|
233
|
+
* The handler can accept a unary or streaming request; it must return
|
|
234
|
+
* a single response (or an extendable response envelope).
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* ```ts
|
|
238
|
+
* const events = defineInvokeEventa<{ id: string }, { name: string }>()
|
|
239
|
+
*
|
|
240
|
+
* defineInvokeHandler(serverCtx, events, ({ name }) => ({
|
|
241
|
+
* id: `user-${name}`,
|
|
242
|
+
* }))
|
|
243
|
+
* ```
|
|
244
|
+
*
|
|
245
|
+
* @param ctx Event context on the handler/server side.
|
|
246
|
+
* @param event Invoke event definition created by `defineInvokeEventa`.
|
|
247
|
+
* @param handler Handler that returns a response (or response + metadata).
|
|
248
|
+
*/
|
|
249
|
+
declare function defineInvokeHandler<Res$1, Req$1 = undefined, ResErr$1 = Error, ReqErr$1 = Error, CtxExt = any, EOpts extends {
|
|
250
|
+
raw?: any;
|
|
251
|
+
} = any>(ctx: InvocableEventContext<CtxExt, EOpts>, event: InvokeEventa<Res$1, Req$1, ResErr$1, ReqErr$1>, handler: Handler<Res$1, Req$1, InvocableEventContext<CtxExt, EOpts>, EOpts>): () => void;
|
|
252
|
+
/**
|
|
253
|
+
* Define multiple invoke handlers in batch (server side).
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* ```ts
|
|
257
|
+
* const events = {
|
|
258
|
+
* double: defineInvokeEventa<number, number>(),
|
|
259
|
+
* greet: defineInvokeEventa<string, { name: string }>(),
|
|
260
|
+
* }
|
|
261
|
+
*
|
|
262
|
+
* defineInvokeHandlers(ctx, events, {
|
|
263
|
+
* double: value => value * 2,
|
|
264
|
+
* greet: ({ name }) => `hi ${name}`,
|
|
265
|
+
* })
|
|
266
|
+
* ```
|
|
267
|
+
*
|
|
268
|
+
* @param ctx Event context on the handler/server side.
|
|
269
|
+
* @param events Map of invoke events created by `defineInvokeEventa`.
|
|
270
|
+
* @param handlers Map of handlers keyed by event name.
|
|
271
|
+
*/
|
|
272
|
+
declare function defineInvokeHandlers<EK extends string, EventMap extends Record<EK, InvokeEventa<any, any, any, any>>, CtxExt = any, EOpts extends {
|
|
273
|
+
raw?: any;
|
|
274
|
+
} = any>(ctx: InvocableEventContext<CtxExt, EOpts>, events: EventMap, handlers: HandlerMap<EventMap, EOpts>): Record<EK, () => void>;
|
|
275
|
+
/**
|
|
276
|
+
* Remove one or all invoke handlers for a specific invoke event (server side).
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* ```ts
|
|
280
|
+
* const off = defineInvokeHandler(ctx, events, handler)
|
|
281
|
+
* off() // remove one handler
|
|
282
|
+
*
|
|
283
|
+
* // or remove all handlers for the event:
|
|
284
|
+
* undefineInvokeHandler(ctx, events)
|
|
285
|
+
* ```
|
|
286
|
+
*
|
|
287
|
+
* @param ctx Event context on the handler/server side.
|
|
288
|
+
* @param event Invoke event definition created by `defineInvokeEventa`.
|
|
289
|
+
* @param handler Specific handler to remove (omit to remove all).
|
|
290
|
+
* @returns `true` if at least one handler was removed, `false` otherwise
|
|
291
|
+
*/
|
|
292
|
+
declare function undefineInvokeHandler<Res$1, Req$1 = undefined, ResErr$1 = Error, ReqErr$1 = Error, CtxExt = any, EOpts = any>(ctx: InvocableEventContext<CtxExt, EOpts>, event: InvokeEventa<Res$1, Req$1, ResErr$1, ReqErr$1>, handler?: Handler<Res$1, Req$1, InvocableEventContext<CtxExt, EOpts>, EOpts>): boolean;
|
|
293
|
+
//#endregion
|
|
294
|
+
//#region src/invoke-extension-transfer.d.ts
|
|
295
|
+
interface WithTransfer<T> {
|
|
296
|
+
message: T;
|
|
297
|
+
_transfer?: Transferable[];
|
|
298
|
+
}
|
|
299
|
+
declare function withTransfer<T>(body: T, transfer?: Transferable[]): ExtendableInvokeResponse<T, EventContext<{
|
|
300
|
+
invokeResponse?: {
|
|
301
|
+
transfer?: Transferable[];
|
|
302
|
+
};
|
|
303
|
+
}, any>>;
|
|
304
|
+
//#endregion
|
|
305
|
+
//#region src/invoke-remote-methods.d.ts
|
|
306
|
+
interface InvokeFunctionStubOptions {
|
|
307
|
+
allow?: boolean;
|
|
308
|
+
maxDepth?: number;
|
|
309
|
+
maxFunctions?: number;
|
|
310
|
+
tagPrefix?: string;
|
|
311
|
+
onDisallowedTag?: 'ignore' | 'throw';
|
|
312
|
+
autoDisposeMs?: number;
|
|
313
|
+
strict?: boolean;
|
|
314
|
+
}
|
|
315
|
+
type RemoteInvokeOptions<EC extends EventContext<any, any>> = ExtractInvokeRequestOptions<EC> & {
|
|
316
|
+
functionStubs?: boolean | InvokeFunctionStubOptions;
|
|
317
|
+
};
|
|
318
|
+
interface RemoteInvokeResult<Res$1> extends Promise<Res$1> {
|
|
319
|
+
dispose: () => void;
|
|
320
|
+
}
|
|
321
|
+
type RemoteInvokeFunction<Res$1, Req$1, EC extends EventContext<any, any>> = [Req$1] extends [undefined] ? (req?: Req$1, options?: RemoteInvokeOptions<EC>) => RemoteInvokeResult<Res$1> : (req: Req$1, options?: RemoteInvokeOptions<EC>) => RemoteInvokeResult<Res$1>;
|
|
322
|
+
declare function createRemoteMethodTagPrefix(prefix?: string): string;
|
|
323
|
+
/**
|
|
324
|
+
* Enable "remote method" payloads for invoke: functions in the request body are
|
|
325
|
+
* serialized into stub descriptors and rehydrated into invoke callers on the
|
|
326
|
+
* receiving side.
|
|
327
|
+
*
|
|
328
|
+
* This is an adapter around the plain-value RPC primitives `defineInvoke` and
|
|
329
|
+
* `defineInvokeHandler`. It keeps the core invoke APIs clean while offering an
|
|
330
|
+
* opt-in bridge for function values.
|
|
331
|
+
*
|
|
332
|
+
* @example
|
|
333
|
+
* ```ts
|
|
334
|
+
* const remote = withRemoteMethods({ allow: true })
|
|
335
|
+
* const events = defineInvokeEventa<{ output: number }, { helper: (n: number) => Promise<number> }>()
|
|
336
|
+
*
|
|
337
|
+
* // server (handler)
|
|
338
|
+
* remote.defineInvokeHandler(serverCtx, events, async ({ helper }) => {
|
|
339
|
+
* const output = await helper(21)
|
|
340
|
+
* return { output }
|
|
341
|
+
* })
|
|
342
|
+
*
|
|
343
|
+
* // client (caller)
|
|
344
|
+
* const invoke = remote.defineInvoke(clientCtx, events)
|
|
345
|
+
* const result = await invoke({ helper: async n => n * 2 }, { functionStubs: true })
|
|
346
|
+
* ```
|
|
347
|
+
*
|
|
348
|
+
* @example
|
|
349
|
+
* ```ts
|
|
350
|
+
* // Manual cleanup when you fire-and-forget or cancel midway:
|
|
351
|
+
* const invoke = remote.defineInvoke(clientCtx, events)
|
|
352
|
+
* const result = invoke({ helper: () => 'ok' }, { functionStubs: true })
|
|
353
|
+
* result.dispose()
|
|
354
|
+
* await result
|
|
355
|
+
* ```
|
|
356
|
+
*
|
|
357
|
+
* Security notes:
|
|
358
|
+
* - This feature is off by default. Enabling it allows the remote side to call
|
|
359
|
+
* back into your process; only use with trusted peers.
|
|
360
|
+
* - Function stubs are tagged; prefer a unique `tagPrefix` to avoid collisions
|
|
361
|
+
* (see `createRemoteMethodTagPrefix`).
|
|
362
|
+
* - `maxDepth`, `maxFunctions`, and `autoDisposeMs` limit attack surface and
|
|
363
|
+
* resource usage. `autoDisposeMs` is useful for fire-and-forget calls.
|
|
364
|
+
* - Objects are rebuilt with a null prototype to mitigate `__proto__` pollution.
|
|
365
|
+
* - Enable `strict` to reject malformed `__eventaInvoke` payloads.
|
|
366
|
+
*
|
|
367
|
+
* @param defaultOptions Defaults for function stub behavior. Use `{ allow: true }`
|
|
368
|
+
* to enable, or provide `maxDepth`, `maxFunctions`, `tagPrefix`,
|
|
369
|
+
* `onDisallowedTag`, `autoDisposeMs`, and `strict` for stricter control.
|
|
370
|
+
*/
|
|
371
|
+
declare function withRemoteMethods(defaultOptions?: boolean | InvokeFunctionStubOptions): {
|
|
372
|
+
defineInvoke<Res$1, Req$1 = undefined, ResErr$1 = Error, ReqErr$1 = Error, CtxExt = any, EOpts = any, ECtx extends EventContext<CtxExt, EOpts> = EventContext<CtxExt, EOpts>>(ctx: ECtx, event: InvokeEventa<Res$1, Req$1, ResErr$1, ReqErr$1>): RemoteInvokeFunction<Res$1, Req$1, ECtx>;
|
|
373
|
+
defineInvokeHandler<Res$1, Req$1 = undefined, ResErr$1 = Error, ReqErr$1 = Error, CtxExt = any, EOpts extends {
|
|
374
|
+
raw?: any;
|
|
375
|
+
} = any>(ctx: InvocableEventContext<CtxExt, EOpts>, event: InvokeEventa<Res$1, Req$1, ResErr$1, ReqErr$1>, handler: Handler<Res$1, Req$1, InvocableEventContext<CtxExt, EOpts>, EOpts>): () => void;
|
|
376
|
+
};
|
|
377
|
+
//#endregion
|
|
378
|
+
//#region src/stream.d.ts
|
|
379
|
+
/**
|
|
380
|
+
* Create a stream invoke function (client side).
|
|
381
|
+
*
|
|
382
|
+
* Use when the response is streamed and the request may be unary or streaming.
|
|
383
|
+
*
|
|
384
|
+
* Common patterns:
|
|
385
|
+
* - Unary request -> stream response (server-streaming)
|
|
386
|
+
* - Stream request -> stream response (bi-directional streaming)
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
* ```ts
|
|
390
|
+
* // 1) Define eventa once (shared by client/server)
|
|
391
|
+
* const events = defineInvokeEventa<Progress | Result, Params>()
|
|
392
|
+
*
|
|
393
|
+
* // 2) Client: define invoke function
|
|
394
|
+
* const invoke = defineStreamInvoke(clientCtx, events)
|
|
395
|
+
*
|
|
396
|
+
* // 3) Call with unary request
|
|
397
|
+
* for await (const msg of invoke({ name: 'alice' })) {
|
|
398
|
+
* console.log(msg)
|
|
399
|
+
* }
|
|
400
|
+
* ```
|
|
401
|
+
*
|
|
402
|
+
* @example
|
|
403
|
+
* ```ts
|
|
404
|
+
* // Client-streaming request
|
|
405
|
+
* const input = new ReadableStream<number>({
|
|
406
|
+
* start(c) { c.enqueue(1); c.enqueue(2); c.close() },
|
|
407
|
+
* })
|
|
408
|
+
*
|
|
409
|
+
* for await (const msg of invoke(input)) {
|
|
410
|
+
* console.log(msg)
|
|
411
|
+
* }
|
|
412
|
+
* ```
|
|
413
|
+
*
|
|
414
|
+
* @param clientCtx Event context on the caller/client side.
|
|
415
|
+
* @param event Invoke event definition created by `defineInvokeEventa`.
|
|
416
|
+
*/
|
|
417
|
+
declare function defineStreamInvoke<Res$1, Req$1 = undefined, ResErr$1 = Error, ReqErr$1 = Error, E$1 = any, EO = any>(clientCtx: EventContext<E$1, EO>, event: InvokeEventa<Res$1, Req$1, ResErr$1, ReqErr$1>): (req: Req$1 | ReadableStream<Req$1> | AsyncIterable<Req$1>, options?: {
|
|
418
|
+
signal?: AbortSignal;
|
|
419
|
+
} & EO) => ReadableStream<Res$1>;
|
|
420
|
+
type StreamHandler<Res$1, Req$1 = any, RawEventOptions = unknown> = (payload: Req$1, options?: {
|
|
421
|
+
abortController?: AbortController;
|
|
422
|
+
} & RawEventOptions) => AsyncGenerator<Res$1, void, unknown>;
|
|
423
|
+
/**
|
|
424
|
+
* Define a stream invoke handler (server side).
|
|
425
|
+
*
|
|
426
|
+
* The handler can receive either:
|
|
427
|
+
* - a unary request `Req`
|
|
428
|
+
* - a streaming request `ReadableStream<Req>` / `AsyncIterable<Req>`
|
|
429
|
+
*
|
|
430
|
+
* It must return an async generator of response messages.
|
|
431
|
+
*
|
|
432
|
+
* @example
|
|
433
|
+
* ```ts
|
|
434
|
+
* const events = defineInvokeEventa<Progress | Result, Params>()
|
|
435
|
+
*
|
|
436
|
+
* defineStreamInvokeHandler(serverCtx, events, async function* (payload) {
|
|
437
|
+
* if (isReadableStream<Params>(payload) || isAsyncIterable<Params>(payload)) {
|
|
438
|
+
* for await (const item of payload) {
|
|
439
|
+
* yield { type: 'progress', value: item }
|
|
440
|
+
* }
|
|
441
|
+
* }
|
|
442
|
+
*
|
|
443
|
+
* yield { type: 'result', ok: true }
|
|
444
|
+
* })
|
|
445
|
+
* ```
|
|
446
|
+
*
|
|
447
|
+
* @param serverCtx Event context on the handler/server side.
|
|
448
|
+
* @param event Invoke event definition created by `defineInvokeEventa`.
|
|
449
|
+
* @param fn Stream handler that yields response chunks.
|
|
450
|
+
*/
|
|
451
|
+
declare function defineStreamInvokeHandler<Res$1, Req$1 = undefined, ResErr$1 = Error, ReqErr$1 = Error, E$1 = any, EO extends {
|
|
452
|
+
raw?: any;
|
|
453
|
+
} = any>(serverCtx: EventContext<E$1, EO>, event: InvokeEventa<Res$1, Req$1, ResErr$1, ReqErr$1>, fn: StreamHandler<Res$1, Req$1, EO>): void;
|
|
454
|
+
/**
|
|
455
|
+
* Convert a callback-style handler into a stream handler.
|
|
456
|
+
*
|
|
457
|
+
* Use `emit` to push response chunks, and return when done.
|
|
458
|
+
* Works for unary or streaming requests.
|
|
459
|
+
*
|
|
460
|
+
* @example
|
|
461
|
+
* ```ts
|
|
462
|
+
* defineStreamInvokeHandler(ctx, events, toStreamHandler(async ({ payload, emit }) => {
|
|
463
|
+
* if (isReadableStream<Params>(payload) || isAsyncIterable<Params>(payload)) {
|
|
464
|
+
* for await (const item of payload) {
|
|
465
|
+
* emit({ type: 'progress', value: item })
|
|
466
|
+
* }
|
|
467
|
+
*
|
|
468
|
+
* emit({ type: 'result', ok: true })
|
|
469
|
+
* return
|
|
470
|
+
* }
|
|
471
|
+
*
|
|
472
|
+
* emit({ type: 'result', ok: true })
|
|
473
|
+
* }))
|
|
474
|
+
* ```
|
|
475
|
+
*
|
|
476
|
+
* @param handler Callback handler with `emit` for streaming responses.
|
|
477
|
+
*/
|
|
478
|
+
declare function toStreamHandler<Req$1, Res$1, EO extends {
|
|
479
|
+
raw?: any;
|
|
480
|
+
} = any>(handler: (context: {
|
|
481
|
+
payload: Req$1;
|
|
482
|
+
options?: EO;
|
|
483
|
+
emit: (data: Res$1) => void;
|
|
484
|
+
}) => Promise<void>): StreamHandler<Res$1, Req$1, EO>;
|
|
485
|
+
//#endregion
|
|
486
|
+
//#region src/utils.d.ts
|
|
487
|
+
declare function randomBetween(min: number, max: number): number;
|
|
488
|
+
/**
|
|
489
|
+
* Checks if a value is an AsyncIterable.
|
|
490
|
+
*
|
|
491
|
+
* @param value
|
|
492
|
+
* @returns True if the value is an AsyncIterable.
|
|
493
|
+
*/
|
|
494
|
+
declare function isAsyncIterable<T>(value: unknown): value is AsyncIterable<T>;
|
|
495
|
+
/**
|
|
496
|
+
* Checks if an object is a ReadableStream.
|
|
497
|
+
*
|
|
498
|
+
* @link https://github.com/cloudflare/workerd/blob/88e8696ce7a5f8969a7e02a2dcfb6504c17c9e8d/src/cloudflare/internal/streaming-forms.ts#L3
|
|
499
|
+
* @param obj
|
|
500
|
+
* @returns True if the object looks like a ReadableStream.
|
|
501
|
+
*/
|
|
502
|
+
declare function isReadableStream<T>(obj?: unknown | null): obj is ReadableStream<T>;
|
|
503
|
+
declare function createAbortError(reason?: unknown): Error;
|
|
504
|
+
declare function isAbortError(error: unknown): error is Error;
|
|
505
|
+
declare function createUntilTriggeredOnce<F extends (...args: any[]) => any, P extends any[] = Parameters<F>, R = ReturnType<F>>(fn: F): {
|
|
506
|
+
onceTriggered: Promise<Awaited<R>>;
|
|
507
|
+
wrapper: (...args: P) => Promise<Awaited<R>>;
|
|
508
|
+
};
|
|
509
|
+
declare function createUntilTriggered<P, R>(fn: (...args: P[]) => R): {
|
|
510
|
+
promise: Promise<void>;
|
|
511
|
+
handler: () => void;
|
|
512
|
+
};
|
|
513
|
+
declare function createUntil<T>(options?: {
|
|
514
|
+
intervalHandler?: () => Promise<boolean>;
|
|
515
|
+
interval?: number;
|
|
516
|
+
}): {
|
|
517
|
+
promise: Promise<T>;
|
|
518
|
+
handler: (value: T) => void;
|
|
519
|
+
};
|
|
520
|
+
//#endregion
|
|
521
|
+
export { isSendEvent as $, defineInvokeHandlers as A, InferSendEventStreamEnd as B, Handler as C, InvokeFunctionMap as D, InvokeFunction as E, InferReceiveEventError as F, ReceiveEventStreamEnd as G, InvokeEventa as H, InferReceiveEventStreamEnd as I, SendEventError as J, SendEvent as K, InferSendEvent as L, isExtendableInvokeResponseLike as M, undefineInvokeHandler as N, defineInvoke as O, InferReceiveEvent as P, isReceiveEvent as Q, InferSendEventAbort as R, ExtractInvokeResponseOptions as S, InvocableEventContext as T, ReceiveEvent as U, InvokeEventType as V, ReceiveEventError as W, defineInvokeEventa as X, SendEventStreamEnd as Y, isInvokeEventa as Z, withRemoteMethods as _, isAbortError as a, ExtendableInvokeResponse as b, randomBetween as c, toStreamHandler as d, 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, SendEventAbort 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 };
|
|
522
|
+
//# sourceMappingURL=index-CI_gUGXg.d.mts.map
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { _ as
|
|
2
|
-
import { n as EventContextEmitFn, r as createContext, t as EventContext } from "./context-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export { DirectionalEventa, EventContext, EventContextEmitFn, EventTag, Eventa, EventaFlowDirection, EventaLike, EventaMatchExpression, EventaType, ExtendableInvokeResponse, Handler, HandlerMap, InboundEventa, InvocableEventContext, InvokeEventConstraint, InvokeEventType, InvokeEventa, InvokeFunction, InvokeFunctionMap, OutboundEventa, ReceiveEvent, ReceiveEventError, ReceiveEventStreamEnd, SendEvent, SendEventError, and, createContext, defineEventa, defineInboundEventa, defineInvoke, defineInvokeEventa, defineInvokeHandler, defineInvokeHandlers, defineInvokes, defineOutboundEventa, defineStreamInvoke, defineStreamInvokeHandler, isExtendableInvokeResponseLike, isInvokeEventa, isReceiveEvent, isSendEvent, matchBy, nanoid, or, toStreamHandler, undefineInvokeHandler };
|
|
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-AJyw28P8.mjs";
|
|
2
|
+
import { n as EventContextEmitFn, r as createContext, t as EventContext } from "./context-ZVv99bcM.mjs";
|
|
3
|
+
import { $ as isSendEvent, A as defineInvokeHandlers, B as InferSendEventStreamEnd, C as Handler, D as InvokeFunctionMap, E as InvokeFunction, F as InferReceiveEventError, G as ReceiveEventStreamEnd, H as InvokeEventa, I as InferReceiveEventStreamEnd, J as SendEventError, K as SendEvent, L as InferSendEvent, M as isExtendableInvokeResponseLike, N as undefineInvokeHandler, O as defineInvoke, P as InferReceiveEvent, Q as isReceiveEvent, R as InferSendEventAbort, S as ExtractInvokeResponseOptions, T as InvocableEventContext, U as ReceiveEvent, V as InvokeEventType, W as ReceiveEventError, X as defineInvokeEventa, Y as SendEventStreamEnd, Z as isInvokeEventa, _ as withRemoteMethods, a as isAbortError, b as ExtendableInvokeResponse, c as randomBetween, d as toStreamHandler, 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 SendEventAbort, 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-CI_gUGXg.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, 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,4 @@
|
|
|
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 { a as
|
|
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-BMDJMapI.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-eMqISeHo.mjs";
|
|
3
3
|
|
|
4
|
-
export { EventaFlowDirection, EventaType, InvokeEventType, and, createContext, defineEventa, defineInboundEventa, defineInvoke, defineInvokeEventa, defineInvokeHandler, defineInvokeHandlers, defineInvokes, defineOutboundEventa, defineStreamInvoke, defineStreamInvokeHandler, isExtendableInvokeResponseLike, isInvokeEventa, isReceiveEvent, isSendEvent, matchBy, nanoid, or, toStreamHandler, undefineInvokeHandler };
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import { l as nanoid } from "./context-
|
|
1
|
+
import { l as nanoid } from "./context-BMDJMapI.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/adapters/websocket/internal.ts
|
|
4
4
|
function generateWebsocketPayload(type, payload) {
|
|
@@ -15,4 +15,4 @@ function parseWebsocketPayload(data) {
|
|
|
15
15
|
|
|
16
16
|
//#endregion
|
|
17
17
|
export { parseWebsocketPayload as n, generateWebsocketPayload as t };
|
|
18
|
-
//# sourceMappingURL=internal-
|
|
18
|
+
//# sourceMappingURL=internal-ChLglF1N.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal-
|
|
1
|
+
{"version":3,"file":"internal-ChLglF1N.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,4 +1,4 @@
|
|
|
1
|
-
import { a as defineEventa, l as nanoid } from "./context-
|
|
1
|
+
import { a as defineEventa, l as nanoid } from "./context-BMDJMapI.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/adapters/electron/internal.ts
|
|
4
4
|
function generatePayload(type, payload) {
|
|
@@ -18,4 +18,4 @@ const errorEvent = { ...defineEventa() };
|
|
|
18
18
|
|
|
19
19
|
//#endregion
|
|
20
20
|
export { generatePayload as n, parsePayload as r, errorEvent as t };
|
|
21
|
-
//# sourceMappingURL=shared-
|
|
21
|
+
//# sourceMappingURL=shared-CA_i_yfR.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-
|
|
1
|
+
{"version":3,"file":"shared-CA_i_yfR.mjs","names":[],"sources":["../src/adapters/electron/internal.ts","../src/adapters/electron/shared.ts"],"sourcesContent":["import type { EventTag } from '../..'\nimport type { Payload as CustomEventDetailDetail } from './shared'\n\nimport { nanoid } from '../..'\n\nexport function generatePayload<T>(type: EventTag<any, any>, payload: T): CustomEventDetailDetail<T> {\n return {\n id: nanoid(),\n type,\n payload,\n }\n}\n\nexport function parsePayload<T>(data: unknown): CustomEventDetailDetail<T> {\n return data as CustomEventDetailDetail<T>\n}\n","import type { EventTag } from '../../eventa'\n\nimport { defineEventa } from '../../eventa'\n\nexport interface Payload<T> {\n id: string\n type: EventTag<any, any>\n payload: T\n}\n\nexport const errorEvent = { ...defineEventa<{ error: unknown }>() }\n"],"mappings":";;;AAKA,SAAgB,gBAAmB,MAA0B,SAAwC;AACnG,QAAO;EACL,IAAI,QAAQ;EACZ;EACA;EACD;;AAGH,SAAgB,aAAgB,MAA2C;AACzE,QAAO;;;;;ACJT,MAAa,aAAa,EAAE,GAAG,cAAkC,EAAE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as defineEventa, l as nanoid, s as defineOutboundEventa } from "./context-
|
|
2
|
-
import {
|
|
1
|
+
import { a as defineEventa, l as nanoid, s as defineOutboundEventa } from "./context-BMDJMapI.mjs";
|
|
2
|
+
import { d as isExtendableInvokeResponseLike } from "./src-eMqISeHo.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/adapters/webworkers/internal.ts
|
|
5
5
|
function generateWorkerPayload(type, payload) {
|
|
@@ -59,13 +59,7 @@ function normalizeOnListenerParameters(event, options) {
|
|
|
59
59
|
transfer
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
-
function withTransfer(body, transfer) {
|
|
63
|
-
return {
|
|
64
|
-
response: body,
|
|
65
|
-
invokeResponse: { transfer: transfer ?? [] }
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
62
|
|
|
69
63
|
//#endregion
|
|
70
|
-
export {
|
|
71
|
-
//# sourceMappingURL=shared-
|
|
64
|
+
export { workerErrorEvent as a, normalizeOnListenerParameters as i, defineWorkerEventa as n, generateWorkerPayload as o, isWorkerEventa as r, parseWorkerPayload as s, defineOutboundWorkerEventa as t };
|
|
65
|
+
//# sourceMappingURL=shared-CRxfs1TC.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-CRxfs1TC.mjs","names":["eventPayload: any","transfer: Transferable[] | undefined"],"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;AAClE,MAAa,0BAA0B,cAAgD;AAEvF,SAAgB,8BAA8B,OAAoB,SAAmD;CACnH,IAAIA,eAAoB,MAAM;CAC9B,IAAIC;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,SACpG;MAAI,MAAM,QAAQ,QAAQ,SAAS,CACjC,YAAW,QAAQ;;AAIvB,QAAO;EACL,MAAM;EACN;EACD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as EventTag, s as EventaType } from "./eventa-
|
|
1
|
+
import { n as EventTag, s as EventaType } from "./eventa-AJyw28P8.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/adapters/electron/shared.d.ts
|
|
4
4
|
interface Payload<T> {
|
|
@@ -15,4 +15,4 @@ declare const errorEvent: {
|
|
|
15
15
|
};
|
|
16
16
|
//#endregion
|
|
17
17
|
export { errorEvent as n, Payload as t };
|
|
18
|
-
//# sourceMappingURL=shared-
|
|
18
|
+
//# sourceMappingURL=shared-Cd4CLAdD.d.mts.map
|