@kitman-sh/cli 0.0.0-stage → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-3j7sewn0.js +4618 -0
- package/dist/chunk-6h8ghah0.js +14 -0
- package/dist/chunk-brp7cekg.js +13 -0
- package/dist/chunk-dsefng1v.js +1085 -0
- package/dist/chunk-fc0v325q.js +75 -0
- package/dist/chunk-h8ctzn91.js +241 -0
- package/dist/chunk-hrvcz0m4.js +211 -0
- package/dist/chunk-hw7qkap1.js +1517 -0
- package/dist/chunk-n32jhswz.js +964 -0
- package/dist/chunk-tfr74ays.js +7060 -0
- package/dist/chunk-txyq8r41.js +25537 -0
- package/dist/chunk-xdk488qp.js +364 -0
- package/dist/egress-proxy.ts +107 -0
- package/dist/index.js +5738 -0
- package/package.json +16 -4
- package/README.md +0 -3
|
@@ -0,0 +1,1517 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
pipeArguments,
|
|
4
|
+
dual,
|
|
5
|
+
identity,
|
|
6
|
+
constVoid,
|
|
7
|
+
flow,
|
|
8
|
+
hasProperty,
|
|
9
|
+
getStackTraceLimit,
|
|
10
|
+
setStackTraceLimit,
|
|
11
|
+
assignProperty,
|
|
12
|
+
none,
|
|
13
|
+
some,
|
|
14
|
+
isNone,
|
|
15
|
+
isSome,
|
|
16
|
+
map,
|
|
17
|
+
Service2,
|
|
18
|
+
makeUnsafe,
|
|
19
|
+
empty,
|
|
20
|
+
make8,
|
|
21
|
+
add,
|
|
22
|
+
getOrUndefinedUnsafe,
|
|
23
|
+
getUnsafe,
|
|
24
|
+
get,
|
|
25
|
+
merge,
|
|
26
|
+
Reference,
|
|
27
|
+
isSuccess,
|
|
28
|
+
toMillis,
|
|
29
|
+
squash,
|
|
30
|
+
findError,
|
|
31
|
+
hasInterrupts,
|
|
32
|
+
interruptors,
|
|
33
|
+
failCause,
|
|
34
|
+
fail2,
|
|
35
|
+
die2,
|
|
36
|
+
interrupt,
|
|
37
|
+
isFailure2,
|
|
38
|
+
Scope,
|
|
39
|
+
provide,
|
|
40
|
+
addFinalizerExit,
|
|
41
|
+
addFinalizer,
|
|
42
|
+
succeed4,
|
|
43
|
+
effect,
|
|
44
|
+
effectContext,
|
|
45
|
+
Clock,
|
|
46
|
+
min,
|
|
47
|
+
exponential,
|
|
48
|
+
spaced,
|
|
49
|
+
isEffect,
|
|
50
|
+
forEach,
|
|
51
|
+
whileLoop,
|
|
52
|
+
succeed5,
|
|
53
|
+
suspend,
|
|
54
|
+
sync,
|
|
55
|
+
void_2,
|
|
56
|
+
callback,
|
|
57
|
+
never,
|
|
58
|
+
gen,
|
|
59
|
+
fail4,
|
|
60
|
+
withFiber,
|
|
61
|
+
flatMap,
|
|
62
|
+
andThen,
|
|
63
|
+
map3,
|
|
64
|
+
catchCause,
|
|
65
|
+
catchCauseIf,
|
|
66
|
+
orDie,
|
|
67
|
+
tapCause,
|
|
68
|
+
retryOrElse,
|
|
69
|
+
ignore,
|
|
70
|
+
ignoreCause,
|
|
71
|
+
timeout,
|
|
72
|
+
timeoutOrElse,
|
|
73
|
+
delay,
|
|
74
|
+
raceFirst,
|
|
75
|
+
matchCauseEffect,
|
|
76
|
+
context,
|
|
77
|
+
contextWith,
|
|
78
|
+
provide3,
|
|
79
|
+
provideContext,
|
|
80
|
+
serviceOption,
|
|
81
|
+
updateContext,
|
|
82
|
+
updateService,
|
|
83
|
+
scope,
|
|
84
|
+
scoped,
|
|
85
|
+
acquireRelease,
|
|
86
|
+
ensuring,
|
|
87
|
+
onError,
|
|
88
|
+
onExit,
|
|
89
|
+
interrupt2,
|
|
90
|
+
interruptible,
|
|
91
|
+
onInterrupt,
|
|
92
|
+
uninterruptibleMask,
|
|
93
|
+
forever,
|
|
94
|
+
makeSpanScoped,
|
|
95
|
+
useSpan,
|
|
96
|
+
withParentSpan,
|
|
97
|
+
forkIn,
|
|
98
|
+
forkScoped,
|
|
99
|
+
runForkWith,
|
|
100
|
+
fnUntraced,
|
|
101
|
+
logError,
|
|
102
|
+
annotateLogs,
|
|
103
|
+
interrupt3,
|
|
104
|
+
getCurrent,
|
|
105
|
+
makeUnsafe4,
|
|
106
|
+
bounded,
|
|
107
|
+
offerAll,
|
|
108
|
+
failCause3,
|
|
109
|
+
end,
|
|
110
|
+
shutdownUnsafe,
|
|
111
|
+
isStream,
|
|
112
|
+
fromQueue,
|
|
113
|
+
unwrap,
|
|
114
|
+
provideContext2,
|
|
115
|
+
empty3,
|
|
116
|
+
fromInput,
|
|
117
|
+
merge3,
|
|
118
|
+
declare,
|
|
119
|
+
decodeUnknownEffect,
|
|
120
|
+
decodeSync,
|
|
121
|
+
encodeEffect,
|
|
122
|
+
make16,
|
|
123
|
+
isSchema,
|
|
124
|
+
optional,
|
|
125
|
+
Never,
|
|
126
|
+
String2,
|
|
127
|
+
Void,
|
|
128
|
+
Struct,
|
|
129
|
+
NonEmptyArray,
|
|
130
|
+
Union,
|
|
131
|
+
Literals,
|
|
132
|
+
tag,
|
|
133
|
+
Int,
|
|
134
|
+
Defect,
|
|
135
|
+
Exit,
|
|
136
|
+
Class,
|
|
137
|
+
Error2,
|
|
138
|
+
TaggedError2,
|
|
139
|
+
toCodecJson,
|
|
140
|
+
HttpClientErrorSchema
|
|
141
|
+
} from "./chunk-txyq8r41.js";
|
|
142
|
+
// node_modules/.bun/effect@4.0.4/node_modules/effect/dist/socket/Socket.js
|
|
143
|
+
var TypeId = "~effect/socket/Socket";
|
|
144
|
+
var Socket = /* @__PURE__ */ Service2("effect/socket/Socket");
|
|
145
|
+
var make4 = (options) => Socket.of({
|
|
146
|
+
[TypeId]: TypeId,
|
|
147
|
+
reader: options.reader,
|
|
148
|
+
writer: options.writer
|
|
149
|
+
});
|
|
150
|
+
var encoder = /* @__PURE__ */ new TextEncoder;
|
|
151
|
+
var readerString = (self, encoding) => map3(self.reader, ({
|
|
152
|
+
pull
|
|
153
|
+
}) => {
|
|
154
|
+
const decoder = new TextDecoder(encoding);
|
|
155
|
+
return map3(pull, (chunk) => {
|
|
156
|
+
const out = new Array(chunk.length);
|
|
157
|
+
for (let i = 0;i < chunk.length; i++) {
|
|
158
|
+
const item = chunk[i];
|
|
159
|
+
out[i] = typeof item === "string" ? item : decoder.decode(item);
|
|
160
|
+
}
|
|
161
|
+
return out;
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
var CloseEventTypeId = "~effect/socket/Socket/CloseEvent";
|
|
165
|
+
var isCloseEvent = (u) => hasProperty(u, CloseEventTypeId);
|
|
166
|
+
var SocketErrorTypeId = "~effect/socket/Socket/SocketError";
|
|
167
|
+
var isSocketError = (u) => hasProperty(u, SocketErrorTypeId);
|
|
168
|
+
|
|
169
|
+
class SocketReadError extends (/* @__PURE__ */ Error2("effect/socket/Socket/SocketReadError")({
|
|
170
|
+
_tag: /* @__PURE__ */ tag("SocketReadError"),
|
|
171
|
+
cause: /* @__PURE__ */ Defect()
|
|
172
|
+
})) {
|
|
173
|
+
message = `An error occurred during Read`;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
class SocketWriteError extends (/* @__PURE__ */ Error2("effect/socket/Socket/SocketWriteError")({
|
|
177
|
+
_tag: /* @__PURE__ */ tag("SocketWriteError"),
|
|
178
|
+
cause: /* @__PURE__ */ Defect()
|
|
179
|
+
})) {
|
|
180
|
+
message = `An error occurred during Write`;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
class SocketOpenError extends (/* @__PURE__ */ Error2("effect/socket/Socket/SocketOpenError")({
|
|
184
|
+
_tag: /* @__PURE__ */ tag("SocketOpenError"),
|
|
185
|
+
kind: /* @__PURE__ */ Literals(["Unknown", "Timeout"]),
|
|
186
|
+
cause: /* @__PURE__ */ Defect()
|
|
187
|
+
})) {
|
|
188
|
+
get message() {
|
|
189
|
+
return this.kind === "Timeout" ? `timeout waiting for "open"` : `An error occurred during Open`;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
class SocketUpgradeError extends (/* @__PURE__ */ Error2("effect/socket/Socket/SocketUpgradeError")({
|
|
194
|
+
_tag: /* @__PURE__ */ tag("SocketUpgradeError"),
|
|
195
|
+
cause: /* @__PURE__ */ optional(/* @__PURE__ */ Defect())
|
|
196
|
+
})) {
|
|
197
|
+
static unsupported = () => fail4(new SocketError({
|
|
198
|
+
reason: new SocketUpgradeError({})
|
|
199
|
+
}));
|
|
200
|
+
get message() {
|
|
201
|
+
return this.cause === undefined ? `Socket does not support TLS upgrade` : `An error occurred during TLS upgrade`;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
class SocketCloseError extends (/* @__PURE__ */ Error2("effect/socket/Socket/SocketCloseError")({
|
|
206
|
+
_tag: /* @__PURE__ */ tag("SocketCloseError"),
|
|
207
|
+
code: Int,
|
|
208
|
+
closeReason: /* @__PURE__ */ optional(String2)
|
|
209
|
+
})) {
|
|
210
|
+
get message() {
|
|
211
|
+
if (this.closeReason) {
|
|
212
|
+
return `${this.code}: ${this.closeReason}`;
|
|
213
|
+
}
|
|
214
|
+
return `${this.code}`;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
var SocketErrorReason = /* @__PURE__ */ Union([SocketReadError, SocketWriteError, SocketOpenError, SocketUpgradeError, SocketCloseError]);
|
|
218
|
+
|
|
219
|
+
class SocketError extends (/* @__PURE__ */ TaggedError2(SocketErrorTypeId)("SocketError", {
|
|
220
|
+
_tag: /* @__PURE__ */ tag("SocketError"),
|
|
221
|
+
reason: SocketErrorReason
|
|
222
|
+
})) {
|
|
223
|
+
constructor(props) {
|
|
224
|
+
if ("cause" in props.reason) {
|
|
225
|
+
super({
|
|
226
|
+
...props,
|
|
227
|
+
cause: props.reason.cause
|
|
228
|
+
});
|
|
229
|
+
} else {
|
|
230
|
+
super(props);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
[SocketErrorTypeId] = SocketErrorTypeId;
|
|
234
|
+
static is(u) {
|
|
235
|
+
return isSocketError(u);
|
|
236
|
+
}
|
|
237
|
+
message = this.reason.message;
|
|
238
|
+
}
|
|
239
|
+
var closeError = (code, closeReason) => new SocketError({
|
|
240
|
+
reason: new SocketCloseError({
|
|
241
|
+
code,
|
|
242
|
+
closeReason
|
|
243
|
+
})
|
|
244
|
+
});
|
|
245
|
+
class WebSocketConstructor extends (/* @__PURE__ */ Service2()("@effect/platform/Socket/WebSocketConstructor")) {
|
|
246
|
+
}
|
|
247
|
+
var layerWebSocketConstructorGlobal = /* @__PURE__ */ succeed4(WebSocketConstructor)((url, options) => {
|
|
248
|
+
if (options !== undefined && typeof options !== "string" && !Array.isArray(options)) {
|
|
249
|
+
throw new TypeError("WebSocket client options are not supported by the global WebSocket constructor");
|
|
250
|
+
}
|
|
251
|
+
return new globalThis.WebSocket(url, options);
|
|
252
|
+
});
|
|
253
|
+
var makeWebSocket = (url, options) => WebSocketConstructor.use((makeWs) => fromWebSocket(acquireRelease((typeof url === "string" ? succeed5(url) : url).pipe(map3((url) => makeWs(url, options?.headers === undefined ? options?.protocols : {
|
|
254
|
+
protocols: options.protocols,
|
|
255
|
+
headers: options.headers
|
|
256
|
+
}))), (ws) => sync(() => ws.close(1000))), options));
|
|
257
|
+
var isPausable = (ws) => ("pause" in ws) && typeof ws.pause === "function";
|
|
258
|
+
var fromWebSocket = (acquire, options) => withFiber((fiber) => {
|
|
259
|
+
let currentWS;
|
|
260
|
+
const latch = makeUnsafe4(false);
|
|
261
|
+
const acquireContext = fiber.context;
|
|
262
|
+
const reader = gen(function* () {
|
|
263
|
+
const scope2 = yield* scope;
|
|
264
|
+
const ws = yield* provide(acquire, scope2);
|
|
265
|
+
if ("binaryType" in ws) {
|
|
266
|
+
ws.binaryType = "arraybuffer";
|
|
267
|
+
}
|
|
268
|
+
const pausable = isPausable(ws);
|
|
269
|
+
const highWaterMark = options?.highWaterMark ?? (pausable ? defaultHighWaterMark : undefined);
|
|
270
|
+
let open = ws.readyState === 1;
|
|
271
|
+
let paused = pausable && "isPaused" in ws && ws.isPaused === true;
|
|
272
|
+
let buffer = [];
|
|
273
|
+
let bufferSize = 0;
|
|
274
|
+
let error;
|
|
275
|
+
let waiter;
|
|
276
|
+
let openWaiter;
|
|
277
|
+
function pauseWebSocket() {
|
|
278
|
+
if (!pausable || paused)
|
|
279
|
+
return;
|
|
280
|
+
ws.pause();
|
|
281
|
+
paused = true;
|
|
282
|
+
}
|
|
283
|
+
function resumeWebSocket() {
|
|
284
|
+
if (!pausable || !paused)
|
|
285
|
+
return;
|
|
286
|
+
ws.resume();
|
|
287
|
+
paused = false;
|
|
288
|
+
}
|
|
289
|
+
function takeBuffer() {
|
|
290
|
+
const chunk = buffer;
|
|
291
|
+
buffer = [];
|
|
292
|
+
bufferSize = 0;
|
|
293
|
+
if (error === undefined)
|
|
294
|
+
resumeWebSocket();
|
|
295
|
+
return chunk;
|
|
296
|
+
}
|
|
297
|
+
function deliver() {
|
|
298
|
+
if (waiter === undefined || buffer.length === 0)
|
|
299
|
+
return;
|
|
300
|
+
const resume = waiter;
|
|
301
|
+
waiter = undefined;
|
|
302
|
+
resume(succeed5(takeBuffer()));
|
|
303
|
+
}
|
|
304
|
+
function push(data) {
|
|
305
|
+
buffer.push(data);
|
|
306
|
+
if (highWaterMark !== undefined) {
|
|
307
|
+
bufferSize += typeof data === "string" ? encoder.encode(data).byteLength : data.byteLength;
|
|
308
|
+
}
|
|
309
|
+
if (waiter !== undefined)
|
|
310
|
+
deliver();
|
|
311
|
+
if (pausable && bufferSize >= highWaterMark) {
|
|
312
|
+
pauseWebSocket();
|
|
313
|
+
} else if (!pausable && !waiter && highWaterMark !== undefined && bufferSize > highWaterMark) {
|
|
314
|
+
fail(new SocketError({
|
|
315
|
+
reason: new SocketReadError({
|
|
316
|
+
cause: new Error(`Socket highWaterMark of ${highWaterMark} bytes exceeded`)
|
|
317
|
+
})
|
|
318
|
+
}));
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
function fail(err) {
|
|
322
|
+
if (error === undefined)
|
|
323
|
+
error = err;
|
|
324
|
+
if (openWaiter !== undefined) {
|
|
325
|
+
const {
|
|
326
|
+
cleanup,
|
|
327
|
+
resume
|
|
328
|
+
} = openWaiter;
|
|
329
|
+
openWaiter = undefined;
|
|
330
|
+
cleanup();
|
|
331
|
+
resume(fail4(error));
|
|
332
|
+
}
|
|
333
|
+
if (waiter !== undefined) {
|
|
334
|
+
const resume = waiter;
|
|
335
|
+
waiter = undefined;
|
|
336
|
+
resume(buffer.length > 0 ? succeed5(takeBuffer()) : fail4(error));
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
function onMessage(event) {
|
|
340
|
+
const data = event.data;
|
|
341
|
+
if (typeof Blob !== "undefined" && data instanceof Blob) {
|
|
342
|
+
data.arrayBuffer().then((buf) => push(new Uint8Array(buf)), (cause) => {
|
|
343
|
+
fail(new SocketError({
|
|
344
|
+
reason: new SocketReadError({
|
|
345
|
+
cause
|
|
346
|
+
})
|
|
347
|
+
}));
|
|
348
|
+
});
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
push(data instanceof ArrayBuffer ? new Uint8Array(data) : data);
|
|
352
|
+
}
|
|
353
|
+
function onError(event) {
|
|
354
|
+
fail(new SocketError({
|
|
355
|
+
reason: open ? new SocketReadError({
|
|
356
|
+
cause: event
|
|
357
|
+
}) : new SocketOpenError({
|
|
358
|
+
kind: "Unknown",
|
|
359
|
+
cause: event
|
|
360
|
+
})
|
|
361
|
+
}));
|
|
362
|
+
}
|
|
363
|
+
function onClose(event) {
|
|
364
|
+
fail(closeError(typeof event.code === "number" ? event.code : 1006, event.reason));
|
|
365
|
+
}
|
|
366
|
+
ws.addEventListener("message", onMessage);
|
|
367
|
+
ws.addEventListener("error", onError, {
|
|
368
|
+
once: true
|
|
369
|
+
});
|
|
370
|
+
ws.addEventListener("close", onClose, {
|
|
371
|
+
once: true
|
|
372
|
+
});
|
|
373
|
+
yield* addFinalizer(scope2, sync(() => {
|
|
374
|
+
fail(closeError(1006));
|
|
375
|
+
ws.removeEventListener("message", onMessage);
|
|
376
|
+
ws.removeEventListener("error", onError);
|
|
377
|
+
ws.removeEventListener("close", onClose);
|
|
378
|
+
if (pausable) {
|
|
379
|
+
try {
|
|
380
|
+
resumeWebSocket();
|
|
381
|
+
} catch {}
|
|
382
|
+
}
|
|
383
|
+
latch.closeUnsafe();
|
|
384
|
+
currentWS = undefined;
|
|
385
|
+
}));
|
|
386
|
+
if (ws.readyState >= 2) {
|
|
387
|
+
return yield* fail4(error ?? closeError(1006));
|
|
388
|
+
}
|
|
389
|
+
if (!open) {
|
|
390
|
+
yield* callback((resume) => {
|
|
391
|
+
const onOpen = () => {
|
|
392
|
+
if (openWaiter?.resume !== resume)
|
|
393
|
+
return;
|
|
394
|
+
openWaiter = undefined;
|
|
395
|
+
ws.removeEventListener("open", onOpen);
|
|
396
|
+
resume(void_2);
|
|
397
|
+
};
|
|
398
|
+
const cleanup = () => ws.removeEventListener("open", onOpen);
|
|
399
|
+
openWaiter = {
|
|
400
|
+
resume,
|
|
401
|
+
cleanup
|
|
402
|
+
};
|
|
403
|
+
ws.addEventListener("open", onOpen, {
|
|
404
|
+
once: true
|
|
405
|
+
});
|
|
406
|
+
return sync(() => {
|
|
407
|
+
if (openWaiter?.resume === resume)
|
|
408
|
+
openWaiter = undefined;
|
|
409
|
+
cleanup();
|
|
410
|
+
});
|
|
411
|
+
}).pipe(timeoutOrElse({
|
|
412
|
+
duration: options?.openTimeout ?? 1e4,
|
|
413
|
+
orElse: () => fail4(new SocketError({
|
|
414
|
+
reason: new SocketOpenError({
|
|
415
|
+
kind: "Timeout",
|
|
416
|
+
cause: new Error('timeout waiting for "open"')
|
|
417
|
+
})
|
|
418
|
+
}))
|
|
419
|
+
}));
|
|
420
|
+
open = true;
|
|
421
|
+
}
|
|
422
|
+
if (error === undefined && bufferSize < highWaterMark)
|
|
423
|
+
resumeWebSocket();
|
|
424
|
+
currentWS = ws;
|
|
425
|
+
latch.openUnsafe();
|
|
426
|
+
return {
|
|
427
|
+
pull: callback((resume) => {
|
|
428
|
+
if (buffer.length > 0)
|
|
429
|
+
return resume(succeed5(takeBuffer()));
|
|
430
|
+
if (error !== undefined)
|
|
431
|
+
return resume(fail4(error));
|
|
432
|
+
waiter = resume;
|
|
433
|
+
return sync(() => {
|
|
434
|
+
if (waiter === resume)
|
|
435
|
+
waiter = undefined;
|
|
436
|
+
});
|
|
437
|
+
}),
|
|
438
|
+
upgrade: SocketUpgradeError.unsupported
|
|
439
|
+
};
|
|
440
|
+
}).pipe(updateContext((input) => merge(acquireContext, input)));
|
|
441
|
+
const write = (chunk) => suspend(() => {
|
|
442
|
+
const ws = currentWS;
|
|
443
|
+
if (ws === undefined)
|
|
444
|
+
return latch.whenOpen(write(chunk));
|
|
445
|
+
try {
|
|
446
|
+
if (isCloseEvent(chunk)) {
|
|
447
|
+
ws.close(chunk.code, chunk.reason);
|
|
448
|
+
} else {
|
|
449
|
+
ws.send(chunk);
|
|
450
|
+
}
|
|
451
|
+
return void_2;
|
|
452
|
+
} catch (cause) {
|
|
453
|
+
return fail4(new SocketError({
|
|
454
|
+
reason: new SocketWriteError({
|
|
455
|
+
cause
|
|
456
|
+
})
|
|
457
|
+
}));
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
const writeAll = (chunks) => suspend(() => {
|
|
461
|
+
const ws = currentWS;
|
|
462
|
+
if (ws === undefined)
|
|
463
|
+
return latch.whenOpen(writeAll(chunks));
|
|
464
|
+
try {
|
|
465
|
+
for (let i = 0;i < chunks.length; i++) {
|
|
466
|
+
ws.send(chunks[i]);
|
|
467
|
+
}
|
|
468
|
+
return void_2;
|
|
469
|
+
} catch (cause) {
|
|
470
|
+
return fail4(new SocketError({
|
|
471
|
+
reason: new SocketWriteError({
|
|
472
|
+
cause
|
|
473
|
+
})
|
|
474
|
+
}));
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
const writer = succeed5({
|
|
478
|
+
write,
|
|
479
|
+
writeAll
|
|
480
|
+
});
|
|
481
|
+
return succeed5(make4({
|
|
482
|
+
reader,
|
|
483
|
+
writer
|
|
484
|
+
}));
|
|
485
|
+
});
|
|
486
|
+
var defaultHighWaterMark = 64 * 1024;
|
|
487
|
+
var layerWebSocket = /* @__PURE__ */ flow(makeWebSocket, /* @__PURE__ */ effect(Socket));
|
|
488
|
+
// node_modules/.bun/effect@4.0.4/node_modules/effect/dist/PrimaryKey.js
|
|
489
|
+
var symbol = "~effect/PrimaryKey";
|
|
490
|
+
|
|
491
|
+
// node_modules/.bun/effect@4.0.4/node_modules/effect/dist/rpc/RpcSchema.js
|
|
492
|
+
var StreamSchemaTypeId = "~effect/rpc/RpcSchema/StreamSchema";
|
|
493
|
+
function isStreamSchema(schema) {
|
|
494
|
+
return hasProperty(schema, StreamSchemaTypeId);
|
|
495
|
+
}
|
|
496
|
+
function getStreamSchemas(schema) {
|
|
497
|
+
return isStreamSchema(schema) ? some({
|
|
498
|
+
success: schema.success,
|
|
499
|
+
error: schema.error
|
|
500
|
+
}) : none();
|
|
501
|
+
}
|
|
502
|
+
var schema = /* @__PURE__ */ declare(isStream);
|
|
503
|
+
function Stream(success, error) {
|
|
504
|
+
return make16(schema.ast, {
|
|
505
|
+
[StreamSchemaTypeId]: StreamSchemaTypeId,
|
|
506
|
+
success,
|
|
507
|
+
error
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
// node_modules/.bun/effect@4.0.4/node_modules/effect/dist/rpc/Rpc.js
|
|
512
|
+
var TypeId2 = "~effect/rpc/Rpc";
|
|
513
|
+
var Proto = {
|
|
514
|
+
[TypeId2]: TypeId2,
|
|
515
|
+
pipe() {
|
|
516
|
+
return pipeArguments(this, arguments);
|
|
517
|
+
},
|
|
518
|
+
setSuccess(successSchema) {
|
|
519
|
+
return makeProto({
|
|
520
|
+
_tag: this._tag,
|
|
521
|
+
payloadSchema: this.payloadSchema,
|
|
522
|
+
successSchema,
|
|
523
|
+
errorSchema: this.errorSchema,
|
|
524
|
+
defectSchema: this.defectSchema,
|
|
525
|
+
annotations: this.annotations,
|
|
526
|
+
middlewares: this.middlewares
|
|
527
|
+
});
|
|
528
|
+
},
|
|
529
|
+
setError(errorSchema) {
|
|
530
|
+
return makeProto({
|
|
531
|
+
_tag: this._tag,
|
|
532
|
+
payloadSchema: this.payloadSchema,
|
|
533
|
+
successSchema: this.successSchema,
|
|
534
|
+
errorSchema,
|
|
535
|
+
defectSchema: this.defectSchema,
|
|
536
|
+
annotations: this.annotations,
|
|
537
|
+
middlewares: this.middlewares
|
|
538
|
+
});
|
|
539
|
+
},
|
|
540
|
+
setPayload(payloadSchema) {
|
|
541
|
+
return makeProto({
|
|
542
|
+
_tag: this._tag,
|
|
543
|
+
payloadSchema: isSchema(payloadSchema) ? payloadSchema : Struct(payloadSchema),
|
|
544
|
+
successSchema: this.successSchema,
|
|
545
|
+
errorSchema: this.errorSchema,
|
|
546
|
+
defectSchema: this.defectSchema,
|
|
547
|
+
annotations: this.annotations,
|
|
548
|
+
middlewares: this.middlewares
|
|
549
|
+
});
|
|
550
|
+
},
|
|
551
|
+
middleware(middleware) {
|
|
552
|
+
return makeProto({
|
|
553
|
+
_tag: this._tag,
|
|
554
|
+
payloadSchema: this.payloadSchema,
|
|
555
|
+
successSchema: this.successSchema,
|
|
556
|
+
errorSchema: this.errorSchema,
|
|
557
|
+
defectSchema: this.defectSchema,
|
|
558
|
+
annotations: this.annotations,
|
|
559
|
+
middlewares: new Set([...this.middlewares, middleware])
|
|
560
|
+
});
|
|
561
|
+
},
|
|
562
|
+
prefix(prefix) {
|
|
563
|
+
return makeProto({
|
|
564
|
+
_tag: `${prefix}${this._tag}`,
|
|
565
|
+
payloadSchema: this.payloadSchema,
|
|
566
|
+
successSchema: this.successSchema,
|
|
567
|
+
errorSchema: this.errorSchema,
|
|
568
|
+
defectSchema: this.defectSchema,
|
|
569
|
+
annotations: this.annotations,
|
|
570
|
+
middlewares: this.middlewares
|
|
571
|
+
});
|
|
572
|
+
},
|
|
573
|
+
annotate(tag, value) {
|
|
574
|
+
return makeProto({
|
|
575
|
+
_tag: this._tag,
|
|
576
|
+
payloadSchema: this.payloadSchema,
|
|
577
|
+
successSchema: this.successSchema,
|
|
578
|
+
errorSchema: this.errorSchema,
|
|
579
|
+
defectSchema: this.defectSchema,
|
|
580
|
+
middlewares: this.middlewares,
|
|
581
|
+
annotations: add(this.annotations, tag, value)
|
|
582
|
+
});
|
|
583
|
+
},
|
|
584
|
+
annotateMerge(context) {
|
|
585
|
+
return makeProto({
|
|
586
|
+
_tag: this._tag,
|
|
587
|
+
payloadSchema: this.payloadSchema,
|
|
588
|
+
successSchema: this.successSchema,
|
|
589
|
+
errorSchema: this.errorSchema,
|
|
590
|
+
defectSchema: this.defectSchema,
|
|
591
|
+
middlewares: this.middlewares,
|
|
592
|
+
annotations: merge(this.annotations, context)
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
var makeProto = (options) => {
|
|
597
|
+
function Rpc() {}
|
|
598
|
+
Object.setPrototypeOf(Rpc, Proto);
|
|
599
|
+
Object.assign(Rpc, options);
|
|
600
|
+
Rpc.key = `effect/rpc/Rpc/${options._tag}`;
|
|
601
|
+
return Rpc;
|
|
602
|
+
};
|
|
603
|
+
var make5 = (tag, options) => {
|
|
604
|
+
const successSchema = options?.success ?? Void;
|
|
605
|
+
const errorSchema = options?.error ?? Never;
|
|
606
|
+
const defectSchema = options?.defect ?? Defect();
|
|
607
|
+
let payloadSchema;
|
|
608
|
+
if (options?.primaryKey) {
|
|
609
|
+
payloadSchema = class Payload extends Class(`effect/rpc/Rpc/${tag}`)(options.payload) {
|
|
610
|
+
[symbol]() {
|
|
611
|
+
return options.primaryKey(this);
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
} else {
|
|
615
|
+
payloadSchema = isSchema(options?.payload) ? options?.payload : options?.payload ? Struct(options?.payload) : Void;
|
|
616
|
+
}
|
|
617
|
+
return makeProto({
|
|
618
|
+
_tag: tag,
|
|
619
|
+
payloadSchema,
|
|
620
|
+
successSchema: options?.stream ? Stream(successSchema, errorSchema) : successSchema,
|
|
621
|
+
errorSchema: options?.stream ? Never : errorSchema,
|
|
622
|
+
defectSchema,
|
|
623
|
+
annotations: empty(),
|
|
624
|
+
middlewares: new Set
|
|
625
|
+
});
|
|
626
|
+
};
|
|
627
|
+
var exitSchemaCache = /* @__PURE__ */ new WeakMap;
|
|
628
|
+
var exitSchema = (self) => {
|
|
629
|
+
if (exitSchemaCache.has(self)) {
|
|
630
|
+
return exitSchemaCache.get(self);
|
|
631
|
+
}
|
|
632
|
+
const rpc = self;
|
|
633
|
+
const failures = new Set([rpc.errorSchema]);
|
|
634
|
+
const streamSchemas = getStreamSchemas(rpc.successSchema);
|
|
635
|
+
if (isSome(streamSchemas)) {
|
|
636
|
+
failures.add(streamSchemas.value.error);
|
|
637
|
+
}
|
|
638
|
+
for (const middleware of rpc.middlewares) {
|
|
639
|
+
failures.add(middleware.error);
|
|
640
|
+
}
|
|
641
|
+
const schema = Exit(isSome(streamSchemas) ? Void : rpc.successSchema, Union([...failures]), rpc.defectSchema);
|
|
642
|
+
exitSchemaCache.set(self, schema);
|
|
643
|
+
return schema;
|
|
644
|
+
};
|
|
645
|
+
var WrapperTypeId = "~effect/rpc/Rpc/Wrapper";
|
|
646
|
+
var isWrapper = (u) => (WrapperTypeId in u);
|
|
647
|
+
// node_modules/.bun/effect@4.0.4/node_modules/effect/dist/workers/Transferable.js
|
|
648
|
+
class Collector extends (/* @__PURE__ */ Service2()("effect/workers/Transferable/Collector")) {
|
|
649
|
+
}
|
|
650
|
+
var makeCollectorUnsafe = () => {
|
|
651
|
+
let tranferables = [];
|
|
652
|
+
const unsafeAddAll = (transfers) => {
|
|
653
|
+
tranferables.push(...transfers);
|
|
654
|
+
};
|
|
655
|
+
const unsafeRead = () => tranferables;
|
|
656
|
+
const unsafeClear = () => {
|
|
657
|
+
const prev = tranferables;
|
|
658
|
+
tranferables = [];
|
|
659
|
+
return prev;
|
|
660
|
+
};
|
|
661
|
+
return Collector.of({
|
|
662
|
+
addAllUnsafe: unsafeAddAll,
|
|
663
|
+
addAll: (transferables) => sync(() => unsafeAddAll(transferables)),
|
|
664
|
+
readUnsafe: unsafeRead,
|
|
665
|
+
read: sync(unsafeRead),
|
|
666
|
+
clearUnsafe: unsafeClear,
|
|
667
|
+
clear: sync(unsafeClear)
|
|
668
|
+
});
|
|
669
|
+
};
|
|
670
|
+
|
|
671
|
+
// node_modules/.bun/effect@4.0.4/node_modules/effect/dist/workers/WorkerError.js
|
|
672
|
+
class WorkerSpawnError extends (/* @__PURE__ */ Error2("effect/workers/WorkerError/WorkerSpawnError")({
|
|
673
|
+
_tag: /* @__PURE__ */ tag("WorkerSpawnError"),
|
|
674
|
+
message: String2,
|
|
675
|
+
cause: /* @__PURE__ */ optional(/* @__PURE__ */ Defect())
|
|
676
|
+
})) {
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
class WorkerSendError extends (/* @__PURE__ */ Error2("effect/workers/WorkerError/WorkerSendError")({
|
|
680
|
+
_tag: /* @__PURE__ */ tag("WorkerSendError"),
|
|
681
|
+
message: String2,
|
|
682
|
+
cause: /* @__PURE__ */ optional(/* @__PURE__ */ Defect())
|
|
683
|
+
})) {
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
class WorkerReceiveError extends (/* @__PURE__ */ Error2("effect/workers/WorkerError/WorkerReceiveError")({
|
|
687
|
+
_tag: /* @__PURE__ */ tag("WorkerReceiveError"),
|
|
688
|
+
message: String2,
|
|
689
|
+
cause: /* @__PURE__ */ optional(/* @__PURE__ */ Defect())
|
|
690
|
+
})) {
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
class WorkerUnknownError extends (/* @__PURE__ */ Error2("effect/workers/WorkerError/WorkerUnknownError")({
|
|
694
|
+
_tag: /* @__PURE__ */ tag("WorkerUnknownError"),
|
|
695
|
+
message: String2,
|
|
696
|
+
cause: /* @__PURE__ */ optional(/* @__PURE__ */ Defect())
|
|
697
|
+
})) {
|
|
698
|
+
}
|
|
699
|
+
var WorkerErrorReason = /* @__PURE__ */ Union([WorkerSpawnError, WorkerSendError, WorkerReceiveError, WorkerUnknownError]);
|
|
700
|
+
|
|
701
|
+
// node_modules/.bun/effect@4.0.4/node_modules/effect/dist/rpc/internal/tracing.js
|
|
702
|
+
var spanName = (spanPrefix, tag) => spanPrefix === undefined ? tag : `${spanPrefix}.${tag}`;
|
|
703
|
+
var spanAttributes = (tag, attributes) => ({
|
|
704
|
+
"rpc.system.name": "effect_rpc",
|
|
705
|
+
"rpc.method": tag,
|
|
706
|
+
...attributes
|
|
707
|
+
});
|
|
708
|
+
|
|
709
|
+
// node_modules/.bun/effect@4.0.4/node_modules/effect/dist/rpc/RpcClientError.js
|
|
710
|
+
var TypeId3 = "~effect/rpc/RpcClientError";
|
|
711
|
+
|
|
712
|
+
class RpcClientDefect extends (/* @__PURE__ */ Error2("effect/rpc/RpcClientError/RpcClientDefect")({
|
|
713
|
+
_tag: /* @__PURE__ */ tag("RpcClientDefect"),
|
|
714
|
+
message: String2,
|
|
715
|
+
cause: /* @__PURE__ */ Defect()
|
|
716
|
+
})) {
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
class RpcClientError extends (/* @__PURE__ */ Error2(TypeId3)({
|
|
720
|
+
_tag: /* @__PURE__ */ tag("RpcClientError"),
|
|
721
|
+
reason: /* @__PURE__ */ Union([WorkerErrorReason, SocketErrorReason, HttpClientErrorSchema, RpcClientDefect])
|
|
722
|
+
})) {
|
|
723
|
+
[TypeId3] = TypeId3;
|
|
724
|
+
get message() {
|
|
725
|
+
return `${this.reason._tag}: ${this.reason.message}`;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
// node_modules/.bun/effect@4.0.4/node_modules/effect/dist/rpc/RpcMessage.js
|
|
730
|
+
var RequestId = (id) => id;
|
|
731
|
+
var constPing = {
|
|
732
|
+
_tag: "Ping"
|
|
733
|
+
};
|
|
734
|
+
|
|
735
|
+
// node_modules/.bun/effect@4.0.4/node_modules/effect/dist/rpc/RpcSerialization.js
|
|
736
|
+
var codecForJson = toCodecJson;
|
|
737
|
+
var sharedTextDecoder;
|
|
738
|
+
var decodeText = (bytes) => (sharedTextDecoder ??= new TextDecoder).decode(bytes);
|
|
739
|
+
|
|
740
|
+
class RpcSerialization extends (/* @__PURE__ */ Service2()("effect/rpc/RpcSerialization")) {
|
|
741
|
+
}
|
|
742
|
+
var defaultMaxBufferSize = 16 * 1024 * 1024;
|
|
743
|
+
var json = /* @__PURE__ */ RpcSerialization.of({
|
|
744
|
+
contentType: "application/json",
|
|
745
|
+
includesFraming: false,
|
|
746
|
+
codecFor: codecForJson,
|
|
747
|
+
makeUnsafe: () => ({
|
|
748
|
+
decode: (bytes) => {
|
|
749
|
+
const decoded = JSON.parse(typeof bytes === "string" ? bytes : decodeText(bytes));
|
|
750
|
+
return Array.isArray(decoded) ? decoded : [decoded];
|
|
751
|
+
},
|
|
752
|
+
encode: (response) => JSON.stringify(response)
|
|
753
|
+
})
|
|
754
|
+
});
|
|
755
|
+
var defaultSchemaBinaryMaxFrameSize = 16 * 1024 * 1024;
|
|
756
|
+
var layerJson = /* @__PURE__ */ succeed4(RpcSerialization)(json);
|
|
757
|
+
|
|
758
|
+
// node_modules/.bun/effect@4.0.4/node_modules/effect/dist/rpc/Utils.js
|
|
759
|
+
var withRunClient = (f) => suspend(() => {
|
|
760
|
+
const clientIds = new Set;
|
|
761
|
+
const clientBuffers = new Map;
|
|
762
|
+
const clientWrites = new Map;
|
|
763
|
+
let write = (clientId, data) => contextWith((context) => {
|
|
764
|
+
let buffer = clientBuffers.get(clientId);
|
|
765
|
+
if (!buffer) {
|
|
766
|
+
buffer = [];
|
|
767
|
+
clientBuffers.set(clientId, buffer);
|
|
768
|
+
}
|
|
769
|
+
buffer.push([data, context]);
|
|
770
|
+
return void_2;
|
|
771
|
+
});
|
|
772
|
+
return map3(f((clientId, data) => {
|
|
773
|
+
const clientWrite = clientWrites.get(clientId);
|
|
774
|
+
if (clientWrite) {
|
|
775
|
+
return clientWrite(data);
|
|
776
|
+
}
|
|
777
|
+
return write(clientId, data);
|
|
778
|
+
}, clientIds), (a) => ({
|
|
779
|
+
...a,
|
|
780
|
+
run(clientId, f) {
|
|
781
|
+
return gen(function* () {
|
|
782
|
+
clientIds.add(clientId);
|
|
783
|
+
clientWrites.set(clientId, f);
|
|
784
|
+
const buffer = clientBuffers.get(clientId);
|
|
785
|
+
if (buffer) {
|
|
786
|
+
clientBuffers.delete(clientId);
|
|
787
|
+
for (const [args, context] of buffer) {
|
|
788
|
+
yield* provideContext(suspend(() => f(args)), context);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
return yield* onExit(never, () => {
|
|
792
|
+
clientIds.delete(clientId);
|
|
793
|
+
clientWrites.delete(clientId);
|
|
794
|
+
return void_2;
|
|
795
|
+
});
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
}));
|
|
799
|
+
});
|
|
800
|
+
|
|
801
|
+
// node_modules/.bun/effect@4.0.4/node_modules/effect/dist/rpc/RpcClient.js
|
|
802
|
+
var requestIdCounter = 0;
|
|
803
|
+
var makeNoSerialization = /* @__PURE__ */ fnUntraced(function* (group, options) {
|
|
804
|
+
const spanPrefix = options.spanPrefix;
|
|
805
|
+
const supportsAck = options?.supportsAck ?? true;
|
|
806
|
+
const disableTracing = options?.disableTracing ?? false;
|
|
807
|
+
const generateRequestId = options?.generateRequestId ?? (() => requestIdCounter++);
|
|
808
|
+
const services = yield* context();
|
|
809
|
+
const scope = get(services, Scope);
|
|
810
|
+
const entries = new Map;
|
|
811
|
+
let isShutdown = false;
|
|
812
|
+
yield* addFinalizer(scope, withFiber((parent) => {
|
|
813
|
+
isShutdown = true;
|
|
814
|
+
return clearEntries(interrupt(parent.id));
|
|
815
|
+
}));
|
|
816
|
+
const clearEntries = fnUntraced(function* (exit) {
|
|
817
|
+
for (const [id, entry] of entries) {
|
|
818
|
+
entries.delete(id);
|
|
819
|
+
if (entry._tag === "Queue") {
|
|
820
|
+
yield* exit._tag === "Success" ? end(entry.queue) : failCause3(entry.queue, exit.cause);
|
|
821
|
+
} else {
|
|
822
|
+
entry.resume(exit);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
});
|
|
826
|
+
const onRequest = (rpc) => {
|
|
827
|
+
const isStream = isStreamSchema(rpc.successSchema);
|
|
828
|
+
const middleware = getRpcClientMiddleware(rpc);
|
|
829
|
+
return (payload, opts) => {
|
|
830
|
+
const headers = opts?.headers ? fromInput(opts.headers) : empty3;
|
|
831
|
+
const context = opts?.context ?? empty();
|
|
832
|
+
if (!isStream) {
|
|
833
|
+
const onRequest = (span) => onEffectRequest(rpc, middleware, span, rpc.payloadSchema.make(payload), headers, context, opts?.discard ?? false);
|
|
834
|
+
return disableTracing ? onRequest(undefined) : useSpan(spanName(spanPrefix, rpc._tag), {
|
|
835
|
+
kind: "client",
|
|
836
|
+
attributes: spanAttributes(rpc._tag, options.spanAttributes)
|
|
837
|
+
}, onRequest);
|
|
838
|
+
}
|
|
839
|
+
const queue = onStreamRequest(rpc, middleware, rpc.payloadSchema.make(payload), headers, opts?.streamBufferSize ?? 16, context);
|
|
840
|
+
if (opts?.asQueue)
|
|
841
|
+
return queue;
|
|
842
|
+
return unwrap(map3(queue, fromQueue));
|
|
843
|
+
};
|
|
844
|
+
};
|
|
845
|
+
const onEffectRequest = (rpc, middleware, span, payload, headers, context, discard) => withFiber((parentFiber) => {
|
|
846
|
+
if (isShutdown) {
|
|
847
|
+
return interrupt2;
|
|
848
|
+
}
|
|
849
|
+
const id = generateRequestId();
|
|
850
|
+
const send = middleware((message) => options.onFromClient({
|
|
851
|
+
message,
|
|
852
|
+
context,
|
|
853
|
+
discard
|
|
854
|
+
}), {
|
|
855
|
+
_tag: "Request",
|
|
856
|
+
id,
|
|
857
|
+
tag: rpc._tag,
|
|
858
|
+
payload,
|
|
859
|
+
...span ? {
|
|
860
|
+
traceId: span.traceId,
|
|
861
|
+
spanId: span.spanId,
|
|
862
|
+
sampled: span.sampled
|
|
863
|
+
} : {},
|
|
864
|
+
headers: merge3(parentFiber.getRef(CurrentHeaders), headers)
|
|
865
|
+
});
|
|
866
|
+
if (discard) {
|
|
867
|
+
return send;
|
|
868
|
+
}
|
|
869
|
+
let fiber;
|
|
870
|
+
return onInterrupt(callback((resume) => {
|
|
871
|
+
const entry = {
|
|
872
|
+
_tag: "Effect",
|
|
873
|
+
rpc,
|
|
874
|
+
context,
|
|
875
|
+
resume(exit) {
|
|
876
|
+
resume(exit);
|
|
877
|
+
if (fiber && !fiber.pollUnsafe()) {
|
|
878
|
+
parentFiber.currentDispatcher.scheduleTask(() => {
|
|
879
|
+
fiber.interruptUnsafe(parentFiber.id);
|
|
880
|
+
}, 0);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
};
|
|
884
|
+
entries.set(id, entry);
|
|
885
|
+
fiber = send.pipe(span ? withParentSpan(span, {
|
|
886
|
+
captureStackTrace: false
|
|
887
|
+
}) : identity, runForkWith(parentFiber.context));
|
|
888
|
+
fiber.addObserver((exit) => {
|
|
889
|
+
if (exit._tag === "Failure") {
|
|
890
|
+
return resume(exit);
|
|
891
|
+
}
|
|
892
|
+
});
|
|
893
|
+
}), (interruptors) => {
|
|
894
|
+
entries.delete(id);
|
|
895
|
+
return andThen(interrupt3(fiber), sendInterrupt(id, Array.from(interruptors), context));
|
|
896
|
+
});
|
|
897
|
+
});
|
|
898
|
+
const onStreamRequest = fnUntraced(function* (rpc, middleware, payload, headers, streamBufferSize, context) {
|
|
899
|
+
if (isShutdown) {
|
|
900
|
+
return yield* interrupt2;
|
|
901
|
+
}
|
|
902
|
+
const span = disableTracing ? undefined : yield* makeSpanScoped(spanName(spanPrefix, rpc._tag), {
|
|
903
|
+
kind: "client",
|
|
904
|
+
attributes: spanAttributes(rpc._tag, options.spanAttributes)
|
|
905
|
+
});
|
|
906
|
+
const fiber = getCurrent();
|
|
907
|
+
const id = generateRequestId();
|
|
908
|
+
const scope = getUnsafe(fiber.context, Scope);
|
|
909
|
+
const queue = yield* bounded(streamBufferSize);
|
|
910
|
+
yield* addFinalizerExit(scope, (exit) => {
|
|
911
|
+
shutdownUnsafe(queue);
|
|
912
|
+
if (!entries.has(id))
|
|
913
|
+
return void_2;
|
|
914
|
+
entries.delete(id);
|
|
915
|
+
return sendInterrupt(id, isFailure2(exit) ? Array.from(interruptors(exit.cause)) : [], context);
|
|
916
|
+
});
|
|
917
|
+
entries.set(id, {
|
|
918
|
+
_tag: "Queue",
|
|
919
|
+
rpc,
|
|
920
|
+
queue,
|
|
921
|
+
scope,
|
|
922
|
+
context
|
|
923
|
+
});
|
|
924
|
+
yield* middleware((message) => options.onFromClient({
|
|
925
|
+
message,
|
|
926
|
+
context,
|
|
927
|
+
discard: false
|
|
928
|
+
}), {
|
|
929
|
+
_tag: "Request",
|
|
930
|
+
id,
|
|
931
|
+
tag: rpc._tag,
|
|
932
|
+
payload,
|
|
933
|
+
...span ? {
|
|
934
|
+
traceId: span.traceId,
|
|
935
|
+
spanId: span.spanId,
|
|
936
|
+
sampled: span.sampled
|
|
937
|
+
} : {},
|
|
938
|
+
headers: merge3(fiber.getRef(CurrentHeaders), headers)
|
|
939
|
+
}).pipe(span ? withParentSpan(span, {
|
|
940
|
+
captureStackTrace: false
|
|
941
|
+
}) : identity, onError((cause) => failCause3(queue, cause)), interruptible, forkIn(scope, {
|
|
942
|
+
startImmediately: true
|
|
943
|
+
}));
|
|
944
|
+
return queue;
|
|
945
|
+
});
|
|
946
|
+
const getRpcClientMiddleware = (rpc) => {
|
|
947
|
+
const middlewares = [];
|
|
948
|
+
for (const tag of rpc.middlewares.values()) {
|
|
949
|
+
const middleware = getOrUndefinedUnsafe(services, `${tag.key}/Client`);
|
|
950
|
+
if (!middleware)
|
|
951
|
+
continue;
|
|
952
|
+
middlewares.push(middleware);
|
|
953
|
+
}
|
|
954
|
+
if (middlewares.length === 0) {
|
|
955
|
+
return (send, request) => send(request);
|
|
956
|
+
}
|
|
957
|
+
return function loop(send, request, index = middlewares.length - 1) {
|
|
958
|
+
if (index === -1) {
|
|
959
|
+
return send(request);
|
|
960
|
+
}
|
|
961
|
+
return middlewares[index]({
|
|
962
|
+
rpc,
|
|
963
|
+
request,
|
|
964
|
+
next(request) {
|
|
965
|
+
return loop(send, request, index - 1);
|
|
966
|
+
}
|
|
967
|
+
});
|
|
968
|
+
};
|
|
969
|
+
};
|
|
970
|
+
const sendInterrupt = (requestId, interruptors, context) => callback((resume) => {
|
|
971
|
+
const parentFiber = getCurrent();
|
|
972
|
+
const fiber = options.onFromClient({
|
|
973
|
+
message: {
|
|
974
|
+
_tag: "Interrupt",
|
|
975
|
+
requestId,
|
|
976
|
+
interruptors
|
|
977
|
+
},
|
|
978
|
+
context,
|
|
979
|
+
discard: false
|
|
980
|
+
}).pipe(timeout(1000), runForkWith(parentFiber.context));
|
|
981
|
+
fiber.addObserver(() => {
|
|
982
|
+
resume(void_2);
|
|
983
|
+
});
|
|
984
|
+
});
|
|
985
|
+
const write = (message) => {
|
|
986
|
+
switch (message._tag) {
|
|
987
|
+
case "Chunk": {
|
|
988
|
+
const requestId = message.requestId;
|
|
989
|
+
const entry = entries.get(requestId);
|
|
990
|
+
if (!entry || entry._tag !== "Queue")
|
|
991
|
+
return void_2;
|
|
992
|
+
return offerAll(entry.queue, message.values).pipe(supportsAck ? flatMap(() => options.onFromClient({
|
|
993
|
+
message: {
|
|
994
|
+
_tag: "Ack",
|
|
995
|
+
requestId: message.requestId
|
|
996
|
+
},
|
|
997
|
+
context: entry.context,
|
|
998
|
+
discard: false
|
|
999
|
+
})) : identity, catchCause((cause) => failCause3(entry.queue, cause)));
|
|
1000
|
+
}
|
|
1001
|
+
case "Exit": {
|
|
1002
|
+
const requestId = message.requestId;
|
|
1003
|
+
const entry = entries.get(requestId);
|
|
1004
|
+
if (!entry)
|
|
1005
|
+
return void_2;
|
|
1006
|
+
entries.delete(requestId);
|
|
1007
|
+
if (entry._tag === "Effect") {
|
|
1008
|
+
entry.resume(message.exit);
|
|
1009
|
+
return void_2;
|
|
1010
|
+
}
|
|
1011
|
+
return message.exit._tag === "Success" ? end(entry.queue) : failCause3(entry.queue, message.exit.cause);
|
|
1012
|
+
}
|
|
1013
|
+
case "Defect": {
|
|
1014
|
+
return clearEntries(die2(message.defect));
|
|
1015
|
+
}
|
|
1016
|
+
case "ClientEnd": {
|
|
1017
|
+
return void_2;
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
};
|
|
1021
|
+
let client;
|
|
1022
|
+
if (options.flatten) {
|
|
1023
|
+
const fns = new Map;
|
|
1024
|
+
client = function client(tag, payload, options) {
|
|
1025
|
+
let fn = fns.get(tag);
|
|
1026
|
+
if (!fn) {
|
|
1027
|
+
fn = onRequest(group.requests.get(tag));
|
|
1028
|
+
fns.set(tag, fn);
|
|
1029
|
+
}
|
|
1030
|
+
return fn(payload, options);
|
|
1031
|
+
};
|
|
1032
|
+
} else {
|
|
1033
|
+
client = {};
|
|
1034
|
+
group.requests.forEach((rpc) => {
|
|
1035
|
+
assignProperty(client, rpc._tag, onRequest(rpc));
|
|
1036
|
+
});
|
|
1037
|
+
}
|
|
1038
|
+
return {
|
|
1039
|
+
client,
|
|
1040
|
+
write
|
|
1041
|
+
};
|
|
1042
|
+
});
|
|
1043
|
+
var clientIdCounter = 0;
|
|
1044
|
+
var make7 = /* @__PURE__ */ fnUntraced(function* (group, options) {
|
|
1045
|
+
const clientId = clientIdCounter++;
|
|
1046
|
+
const {
|
|
1047
|
+
codecFor,
|
|
1048
|
+
run,
|
|
1049
|
+
send,
|
|
1050
|
+
supportsAck,
|
|
1051
|
+
supportsTransferables
|
|
1052
|
+
} = yield* Protocol;
|
|
1053
|
+
const rpcSchemas = makeRpcSchemas(codecFor);
|
|
1054
|
+
const decodeDefect = decodeSync(codecFor(Defect()));
|
|
1055
|
+
const entries = new Map;
|
|
1056
|
+
const interruptRequest = (requestId) => {
|
|
1057
|
+
if (!entries.has(requestId))
|
|
1058
|
+
return void_2;
|
|
1059
|
+
entries.delete(requestId);
|
|
1060
|
+
return send(clientId, {
|
|
1061
|
+
_tag: "Interrupt",
|
|
1062
|
+
requestId
|
|
1063
|
+
});
|
|
1064
|
+
};
|
|
1065
|
+
const {
|
|
1066
|
+
client,
|
|
1067
|
+
write
|
|
1068
|
+
} = yield* makeNoSerialization(group, {
|
|
1069
|
+
...options,
|
|
1070
|
+
supportsAck,
|
|
1071
|
+
onFromClient({
|
|
1072
|
+
message
|
|
1073
|
+
}) {
|
|
1074
|
+
switch (message._tag) {
|
|
1075
|
+
case "Request": {
|
|
1076
|
+
const rpc = group.requests.get(message.tag);
|
|
1077
|
+
const collector = supportsTransferables ? makeCollectorUnsafe() : undefined;
|
|
1078
|
+
const fiber = getCurrent();
|
|
1079
|
+
const entry = {
|
|
1080
|
+
rpc,
|
|
1081
|
+
context: collector ? add(fiber.context, Collector, collector) : fiber.context,
|
|
1082
|
+
schemas: rpcSchemas(rpc)
|
|
1083
|
+
};
|
|
1084
|
+
entries.set(message.id, entry);
|
|
1085
|
+
return entry.schemas.encodePayload(message.payload).pipe(provideContext(entry.context), orDie, flatMap((payload) => send(clientId, {
|
|
1086
|
+
...message,
|
|
1087
|
+
id: message.id,
|
|
1088
|
+
payload,
|
|
1089
|
+
headers: Object.entries(message.headers)
|
|
1090
|
+
}, collector && collector.readUnsafe())));
|
|
1091
|
+
}
|
|
1092
|
+
case "Ack": {
|
|
1093
|
+
const entry = entries.get(message.requestId);
|
|
1094
|
+
if (!entry)
|
|
1095
|
+
return void_2;
|
|
1096
|
+
return send(clientId, {
|
|
1097
|
+
_tag: "Ack",
|
|
1098
|
+
requestId: message.requestId
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
case "Interrupt": {
|
|
1102
|
+
return interruptRequest(message.requestId);
|
|
1103
|
+
}
|
|
1104
|
+
case "Eof": {
|
|
1105
|
+
return void_2;
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
});
|
|
1110
|
+
yield* run(clientId, (message) => {
|
|
1111
|
+
switch (message._tag) {
|
|
1112
|
+
case "Chunk": {
|
|
1113
|
+
const requestId = RequestId(message.requestId);
|
|
1114
|
+
const entry = entries.get(requestId);
|
|
1115
|
+
if (!entry || isNone(entry.schemas.decodeChunk))
|
|
1116
|
+
return void_2;
|
|
1117
|
+
const decodeChunk = entry.schemas.decodeChunk.value;
|
|
1118
|
+
return uninterruptibleMask((restore) => restore(decodeChunk(message.values).pipe(provideContext(entry.context), orDie, flatMap((chunk) => write({
|
|
1119
|
+
_tag: "Chunk",
|
|
1120
|
+
clientId: 0,
|
|
1121
|
+
requestId,
|
|
1122
|
+
values: chunk
|
|
1123
|
+
})))).pipe(onError((cause) => write({
|
|
1124
|
+
_tag: "Exit",
|
|
1125
|
+
clientId: 0,
|
|
1126
|
+
requestId,
|
|
1127
|
+
exit: failCause(cause)
|
|
1128
|
+
}).pipe(andThen(hasInterrupts(cause) ? void_2 : ignore(interruptRequest(requestId))))), catchCauseIf((cause) => !hasInterrupts(cause), () => void_2)));
|
|
1129
|
+
}
|
|
1130
|
+
case "Exit": {
|
|
1131
|
+
const requestId = RequestId(message.requestId);
|
|
1132
|
+
const entry = entries.get(requestId);
|
|
1133
|
+
if (!entry)
|
|
1134
|
+
return void_2;
|
|
1135
|
+
entries.delete(requestId);
|
|
1136
|
+
return entry.schemas.decodeExit(message.exit).pipe(provideContext(entry.context), orDie, matchCauseEffect({
|
|
1137
|
+
onSuccess: (exit) => write({
|
|
1138
|
+
_tag: "Exit",
|
|
1139
|
+
clientId: 0,
|
|
1140
|
+
requestId,
|
|
1141
|
+
exit
|
|
1142
|
+
}),
|
|
1143
|
+
onFailure: (cause) => write({
|
|
1144
|
+
_tag: "Exit",
|
|
1145
|
+
clientId: 0,
|
|
1146
|
+
requestId,
|
|
1147
|
+
exit: failCause(cause)
|
|
1148
|
+
})
|
|
1149
|
+
}));
|
|
1150
|
+
}
|
|
1151
|
+
case "Defect": {
|
|
1152
|
+
return write({
|
|
1153
|
+
_tag: "Defect",
|
|
1154
|
+
clientId: 0,
|
|
1155
|
+
defect: decodeDefect(message.defect)
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1158
|
+
case "ClientProtocolError": {
|
|
1159
|
+
const exit = fail2(message.error);
|
|
1160
|
+
return forEach(Array.from(entries.keys()), (requestId) => write({
|
|
1161
|
+
_tag: "Exit",
|
|
1162
|
+
clientId: 0,
|
|
1163
|
+
requestId,
|
|
1164
|
+
exit
|
|
1165
|
+
}));
|
|
1166
|
+
}
|
|
1167
|
+
default: {
|
|
1168
|
+
return void_2;
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
}).pipe(catchCause(logError), interruptible, forkScoped);
|
|
1172
|
+
return client;
|
|
1173
|
+
});
|
|
1174
|
+
var makeRpcSchemas = (codecFor) => {
|
|
1175
|
+
const cache = new WeakMap;
|
|
1176
|
+
return (rpc) => {
|
|
1177
|
+
let entry = cache.get(rpc);
|
|
1178
|
+
if (entry !== undefined) {
|
|
1179
|
+
return entry;
|
|
1180
|
+
}
|
|
1181
|
+
const streamSchemas = getStreamSchemas(rpc.successSchema);
|
|
1182
|
+
entry = {
|
|
1183
|
+
decodeChunk: map(streamSchemas, (streamSchemas) => decodeUnknownEffect(codecFor(NonEmptyArray(streamSchemas.success)))),
|
|
1184
|
+
encodePayload: encodeEffect(codecFor(rpc.payloadSchema)),
|
|
1185
|
+
decodeExit: decodeUnknownEffect(codecFor(exitSchema(rpc)))
|
|
1186
|
+
};
|
|
1187
|
+
cache.set(rpc, entry);
|
|
1188
|
+
return entry;
|
|
1189
|
+
};
|
|
1190
|
+
};
|
|
1191
|
+
var CurrentHeaders = /* @__PURE__ */ Reference("effect/rpc/RpcClient/CurrentHeaders", {
|
|
1192
|
+
defaultValue: () => empty3
|
|
1193
|
+
});
|
|
1194
|
+
var withHeaders = /* @__PURE__ */ dual(2, (effect, headers) => updateService(effect, CurrentHeaders, merge3(fromInput(headers))));
|
|
1195
|
+
|
|
1196
|
+
class Protocol extends (/* @__PURE__ */ Service2()("effect/rpc/RpcClient/Protocol")) {
|
|
1197
|
+
static make = withRunClient;
|
|
1198
|
+
}
|
|
1199
|
+
var makeProtocolSocket = (options) => Protocol.make(fnUntraced(function* (writeResponse, clientIds) {
|
|
1200
|
+
const socket = yield* Socket;
|
|
1201
|
+
const serialization = yield* RpcSerialization;
|
|
1202
|
+
const hooks = yield* serviceOption(ConnectionHooks);
|
|
1203
|
+
const requestClientMap = new Map;
|
|
1204
|
+
const writer = yield* socket.writer;
|
|
1205
|
+
let parser = serialization.makeUnsafe();
|
|
1206
|
+
const pinger = yield* makePinger(suspend(() => writer.write(parser.encode(constPing))), options);
|
|
1207
|
+
const onPingTimeout = ignoreCause(options?.onPingTimeout ?? void_2, {
|
|
1208
|
+
log: true,
|
|
1209
|
+
message: "RpcClient onPingTimeout hook failed"
|
|
1210
|
+
});
|
|
1211
|
+
let currentError;
|
|
1212
|
+
const broadcast = (response) => forEach(clientIds, (clientId) => writeResponse(clientId, response));
|
|
1213
|
+
const broadcastError = (error) => {
|
|
1214
|
+
currentError = error;
|
|
1215
|
+
return broadcast({
|
|
1216
|
+
_tag: "ClientProtocolError",
|
|
1217
|
+
error
|
|
1218
|
+
});
|
|
1219
|
+
};
|
|
1220
|
+
const processData = (data) => {
|
|
1221
|
+
try {
|
|
1222
|
+
const responses = parser.decode(data);
|
|
1223
|
+
if (responses.length === 0)
|
|
1224
|
+
return void_2;
|
|
1225
|
+
pinger.onFrame();
|
|
1226
|
+
let i = 0;
|
|
1227
|
+
return whileLoop({
|
|
1228
|
+
while: () => i < responses.length,
|
|
1229
|
+
body: () => {
|
|
1230
|
+
const response = responses[i++];
|
|
1231
|
+
if (response._tag === "Pong")
|
|
1232
|
+
return void_2;
|
|
1233
|
+
if (Object.hasOwn(response, "requestId")) {
|
|
1234
|
+
const requestId = response.requestId;
|
|
1235
|
+
const clientId = requestClientMap.get(requestId);
|
|
1236
|
+
if (clientId !== undefined) {
|
|
1237
|
+
if (response._tag === "Exit") {
|
|
1238
|
+
requestClientMap.delete(requestId);
|
|
1239
|
+
}
|
|
1240
|
+
return writeResponse(clientId, response);
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
return broadcast(response);
|
|
1244
|
+
},
|
|
1245
|
+
step: constVoid
|
|
1246
|
+
});
|
|
1247
|
+
} catch (defect) {
|
|
1248
|
+
return broadcast({
|
|
1249
|
+
_tag: "ClientProtocolError",
|
|
1250
|
+
error: new RpcClientError({
|
|
1251
|
+
reason: new RpcClientDefect({
|
|
1252
|
+
message: "Error decoding message",
|
|
1253
|
+
cause: defect
|
|
1254
|
+
})
|
|
1255
|
+
})
|
|
1256
|
+
});
|
|
1257
|
+
}
|
|
1258
|
+
};
|
|
1259
|
+
yield* suspend(() => {
|
|
1260
|
+
parser = serialization.makeUnsafe();
|
|
1261
|
+
pinger.reset();
|
|
1262
|
+
let connected = false;
|
|
1263
|
+
return gen(function* () {
|
|
1264
|
+
const {
|
|
1265
|
+
pull
|
|
1266
|
+
} = yield* socket.reader;
|
|
1267
|
+
currentError = undefined;
|
|
1268
|
+
connected = true;
|
|
1269
|
+
if (isSome(hooks)) {
|
|
1270
|
+
yield* hooks.value.onConnect;
|
|
1271
|
+
}
|
|
1272
|
+
while (true) {
|
|
1273
|
+
const frames = yield* pull;
|
|
1274
|
+
for (let i = 0;i < frames.length; i++) {
|
|
1275
|
+
yield* processData(frames[i]);
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
}).pipe(scoped, raceFirst(pinger.timeout), andThen(() => connected ? onPingTimeout : void_2), andThen(() => fail4(new SocketError({
|
|
1279
|
+
reason: new SocketReadError({
|
|
1280
|
+
cause: new Error("ping timeout")
|
|
1281
|
+
})
|
|
1282
|
+
}))));
|
|
1283
|
+
}).pipe(isSome(hooks) ? ensuring(hooks.value.onDisconnect) : identity, tapCause((cause) => {
|
|
1284
|
+
const error = findError(cause);
|
|
1285
|
+
const hasError = isSuccess(error);
|
|
1286
|
+
const rpcError = new RpcClientError({
|
|
1287
|
+
reason: hasError ? error.success.reason : new RpcClientDefect({
|
|
1288
|
+
message: "Unknown socket error",
|
|
1289
|
+
cause: squash(cause)
|
|
1290
|
+
})
|
|
1291
|
+
});
|
|
1292
|
+
if (options?.retryTransientErrors && hasError && error.success.reason._tag === "SocketOpenError") {
|
|
1293
|
+
return (options.onTransientError?.(rpcError) ?? void_2).pipe(ignoreCause({
|
|
1294
|
+
log: true,
|
|
1295
|
+
message: "RpcClient onTransientError hook failed"
|
|
1296
|
+
}));
|
|
1297
|
+
}
|
|
1298
|
+
return broadcastError(rpcError);
|
|
1299
|
+
}), retryOrElse(options?.retryPolicy ?? defaultRetryPolicy, (error) => broadcastError(new RpcClientError({
|
|
1300
|
+
reason: error.reason
|
|
1301
|
+
}))), annotateLogs({
|
|
1302
|
+
module: "RpcClient",
|
|
1303
|
+
method: "makeProtocolSocket"
|
|
1304
|
+
}), forkScoped);
|
|
1305
|
+
return {
|
|
1306
|
+
send(clientId, request) {
|
|
1307
|
+
if (currentError) {
|
|
1308
|
+
return fail4(currentError);
|
|
1309
|
+
}
|
|
1310
|
+
if (request._tag === "Request") {
|
|
1311
|
+
requestClientMap.set(request.id, clientId);
|
|
1312
|
+
}
|
|
1313
|
+
const encoded = parser.encode(request);
|
|
1314
|
+
if (encoded === undefined)
|
|
1315
|
+
return void_2;
|
|
1316
|
+
return orDie(writer.write(encoded));
|
|
1317
|
+
},
|
|
1318
|
+
supportsAck: true,
|
|
1319
|
+
supportsTransferables: false,
|
|
1320
|
+
codecFor: serialization.codecFor
|
|
1321
|
+
};
|
|
1322
|
+
}));
|
|
1323
|
+
var defaultRetryPolicy = /* @__PURE__ */ min([/* @__PURE__ */ exponential(500, 1.5), /* @__PURE__ */ spaced(5000)]);
|
|
1324
|
+
var makePinger = /* @__PURE__ */ fnUntraced(function* (writePing, options) {
|
|
1325
|
+
const clock = yield* Clock;
|
|
1326
|
+
const interval = options?.pingInterval ?? "5 seconds";
|
|
1327
|
+
const timeoutMillis = toMillis(options?.pingTimeout ?? interval);
|
|
1328
|
+
let lastSeen = clock.currentTimeMillisUnsafe();
|
|
1329
|
+
const latch = makeUnsafe4();
|
|
1330
|
+
const onFrame = () => {
|
|
1331
|
+
lastSeen = clock.currentTimeMillisUnsafe();
|
|
1332
|
+
};
|
|
1333
|
+
const reset = () => {
|
|
1334
|
+
onFrame();
|
|
1335
|
+
latch.closeUnsafe();
|
|
1336
|
+
};
|
|
1337
|
+
yield* suspend(() => {
|
|
1338
|
+
if (clock.currentTimeMillisUnsafe() - lastSeen > timeoutMillis)
|
|
1339
|
+
return latch.open;
|
|
1340
|
+
return writePing;
|
|
1341
|
+
}).pipe(delay(interval), ignore, forever, interruptible, forkScoped);
|
|
1342
|
+
return {
|
|
1343
|
+
timeout: latch.await,
|
|
1344
|
+
reset,
|
|
1345
|
+
onFrame
|
|
1346
|
+
};
|
|
1347
|
+
});
|
|
1348
|
+
var layerProtocolSocket = (options) => effect(Protocol)(makeProtocolSocket(options));
|
|
1349
|
+
class ConnectionHooks extends (/* @__PURE__ */ Service2()("effect/rpc/RpcClient/ConnectionHooks")) {
|
|
1350
|
+
}
|
|
1351
|
+
// node_modules/.bun/effect@4.0.4/node_modules/effect/dist/rpc/RpcGroup.js
|
|
1352
|
+
var RpcGroupProto = {
|
|
1353
|
+
add(...rpcs) {
|
|
1354
|
+
const requests = new Map(this.requests);
|
|
1355
|
+
for (const rpc of rpcs) {
|
|
1356
|
+
requests.set(rpc._tag, rpc);
|
|
1357
|
+
}
|
|
1358
|
+
return makeProto2({
|
|
1359
|
+
requests,
|
|
1360
|
+
annotations: this.annotations
|
|
1361
|
+
});
|
|
1362
|
+
},
|
|
1363
|
+
merge(...groups) {
|
|
1364
|
+
const requests = new Map(this.requests);
|
|
1365
|
+
const annotations = new Map(this.annotations.mapUnsafe);
|
|
1366
|
+
for (const group of groups) {
|
|
1367
|
+
for (const [tag, rpc] of group.requests) {
|
|
1368
|
+
requests.set(tag, rpc);
|
|
1369
|
+
}
|
|
1370
|
+
for (const [key, value] of group.annotations.mapUnsafe) {
|
|
1371
|
+
annotations.set(key, value);
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
return makeProto2({
|
|
1375
|
+
requests,
|
|
1376
|
+
annotations: makeUnsafe(annotations)
|
|
1377
|
+
});
|
|
1378
|
+
},
|
|
1379
|
+
omit(...tags) {
|
|
1380
|
+
const requests = new Map(this.requests);
|
|
1381
|
+
for (const tag of tags) {
|
|
1382
|
+
requests.delete(tag);
|
|
1383
|
+
}
|
|
1384
|
+
return makeProto2({
|
|
1385
|
+
requests,
|
|
1386
|
+
annotations: this.annotations
|
|
1387
|
+
});
|
|
1388
|
+
},
|
|
1389
|
+
middleware(middleware) {
|
|
1390
|
+
const requests = new Map;
|
|
1391
|
+
for (const [tag, rpc] of this.requests) {
|
|
1392
|
+
requests.set(tag, rpc.middleware(middleware));
|
|
1393
|
+
}
|
|
1394
|
+
return makeProto2({
|
|
1395
|
+
requests,
|
|
1396
|
+
annotations: this.annotations
|
|
1397
|
+
});
|
|
1398
|
+
},
|
|
1399
|
+
toHandlers(build) {
|
|
1400
|
+
const self = this;
|
|
1401
|
+
return gen(function* () {
|
|
1402
|
+
const services = yield* context();
|
|
1403
|
+
const handlers = isEffect(build) ? yield* build : build;
|
|
1404
|
+
const contextMap = new Map;
|
|
1405
|
+
self.requests.forEach((rpc, tag) => {
|
|
1406
|
+
contextMap.set(rpc.key, {
|
|
1407
|
+
tag: rpc._tag,
|
|
1408
|
+
handler: handlers[tag],
|
|
1409
|
+
context: services
|
|
1410
|
+
});
|
|
1411
|
+
});
|
|
1412
|
+
return makeUnsafe(contextMap);
|
|
1413
|
+
});
|
|
1414
|
+
},
|
|
1415
|
+
prefix(prefix) {
|
|
1416
|
+
const requests = new Map;
|
|
1417
|
+
for (const rpc of this.requests.values()) {
|
|
1418
|
+
const newRpc = rpc.prefix(prefix);
|
|
1419
|
+
requests.set(newRpc._tag, newRpc);
|
|
1420
|
+
}
|
|
1421
|
+
return makeProto2({
|
|
1422
|
+
requests,
|
|
1423
|
+
annotations: this.annotations
|
|
1424
|
+
});
|
|
1425
|
+
},
|
|
1426
|
+
toLayer(build) {
|
|
1427
|
+
return effectContext(this.toHandlers(build));
|
|
1428
|
+
},
|
|
1429
|
+
of: identity,
|
|
1430
|
+
toLayerHandler(service, build) {
|
|
1431
|
+
const self = this;
|
|
1432
|
+
return effectContext(gen(function* () {
|
|
1433
|
+
const services = yield* context();
|
|
1434
|
+
const handler = isEffect(build) ? yield* build : build;
|
|
1435
|
+
const contextMap = new Map;
|
|
1436
|
+
const rpc = self.requests.get(service);
|
|
1437
|
+
contextMap.set(rpc.key, {
|
|
1438
|
+
handler,
|
|
1439
|
+
context: services
|
|
1440
|
+
});
|
|
1441
|
+
return makeUnsafe(contextMap);
|
|
1442
|
+
}));
|
|
1443
|
+
},
|
|
1444
|
+
accessHandler(service) {
|
|
1445
|
+
return contextWith((parentContext) => {
|
|
1446
|
+
const rpc = this.requests.get(service);
|
|
1447
|
+
const {
|
|
1448
|
+
handler,
|
|
1449
|
+
context
|
|
1450
|
+
} = getOrUndefinedUnsafe(parentContext, rpc.key);
|
|
1451
|
+
return succeed5((payload, options) => {
|
|
1452
|
+
options.rpc = rpc;
|
|
1453
|
+
const result = handler(payload, options);
|
|
1454
|
+
const effectOrStream = isWrapper(result) ? result.value : result;
|
|
1455
|
+
return isEffect(effectOrStream) ? provide3(effectOrStream, context) : provideContext2(effectOrStream, context);
|
|
1456
|
+
});
|
|
1457
|
+
});
|
|
1458
|
+
},
|
|
1459
|
+
annotate(service, value) {
|
|
1460
|
+
return makeProto2({
|
|
1461
|
+
requests: this.requests,
|
|
1462
|
+
annotations: add(this.annotations, service, value)
|
|
1463
|
+
});
|
|
1464
|
+
},
|
|
1465
|
+
annotateRpcs(service, value) {
|
|
1466
|
+
return this.annotateRpcsMerge(make8(service, value));
|
|
1467
|
+
},
|
|
1468
|
+
annotateMerge(context) {
|
|
1469
|
+
return makeProto2({
|
|
1470
|
+
requests: this.requests,
|
|
1471
|
+
annotations: merge(this.annotations, context)
|
|
1472
|
+
});
|
|
1473
|
+
},
|
|
1474
|
+
annotateRpcsMerge(context) {
|
|
1475
|
+
const requests = new Map;
|
|
1476
|
+
for (const [tag, rpc] of this.requests) {
|
|
1477
|
+
requests.set(tag, rpc.annotateMerge(merge(context, rpc.annotations)));
|
|
1478
|
+
}
|
|
1479
|
+
return makeProto2({
|
|
1480
|
+
requests,
|
|
1481
|
+
annotations: this.annotations
|
|
1482
|
+
});
|
|
1483
|
+
}
|
|
1484
|
+
};
|
|
1485
|
+
var makeProto2 = (options) => Object.assign(function() {}, RpcGroupProto, {
|
|
1486
|
+
requests: options.requests,
|
|
1487
|
+
annotations: options.annotations
|
|
1488
|
+
});
|
|
1489
|
+
var make6 = (...rpcs) => makeProto2({
|
|
1490
|
+
requests: new Map(rpcs.map((rpc) => [rpc._tag, rpc])),
|
|
1491
|
+
annotations: empty()
|
|
1492
|
+
});
|
|
1493
|
+
// node_modules/.bun/effect@4.0.4/node_modules/effect/dist/rpc/RpcMiddleware.js
|
|
1494
|
+
var TypeId4 = "~effect/rpc/RpcMiddleware";
|
|
1495
|
+
var Service = () => (id, options) => {
|
|
1496
|
+
const limit = getStackTraceLimit();
|
|
1497
|
+
let creationError;
|
|
1498
|
+
if (limit !== 0) {
|
|
1499
|
+
setStackTraceLimit(2);
|
|
1500
|
+
creationError = new globalThis.Error;
|
|
1501
|
+
setStackTraceLimit(limit);
|
|
1502
|
+
}
|
|
1503
|
+
function ServiceClass() {}
|
|
1504
|
+
const ServiceClass_ = ServiceClass;
|
|
1505
|
+
Object.setPrototypeOf(ServiceClass, Object.getPrototypeOf(Service2(id)));
|
|
1506
|
+
ServiceClass.key = id;
|
|
1507
|
+
Object.defineProperty(ServiceClass, "stack", {
|
|
1508
|
+
get() {
|
|
1509
|
+
return creationError?.stack;
|
|
1510
|
+
}
|
|
1511
|
+
});
|
|
1512
|
+
ServiceClass_[TypeId4] = TypeId4;
|
|
1513
|
+
ServiceClass_.error = options?.error ?? Never;
|
|
1514
|
+
ServiceClass_.requiredForClient = options?.requiredForClient ?? false;
|
|
1515
|
+
return ServiceClass;
|
|
1516
|
+
};
|
|
1517
|
+
export { make4, readerString, isCloseEvent, SocketReadError, SocketWriteError, SocketOpenError, SocketUpgradeError, SocketCloseError, SocketError, layerWebSocketConstructorGlobal, layerWebSocket, make5, make6, layerJson, make7, withHeaders, layerProtocolSocket, ConnectionHooks, Service };
|