@systemfsoftware/stryker-js-cli 7.0.1 → 8.0.1
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/CHANGELOG.md +22 -0
- package/dist/compiler-CyKSVP2x.mjs +27429 -0
- package/dist/dist-Bn6hT7sW.mjs +5056 -0
- package/dist/dist-CgglvcIb.mjs +32119 -0
- package/dist/esm-shims-z34yX56b.mjs +12 -0
- package/dist/main.mjs +8188 -601
- package/dist/node-ZeTkblqG.mjs +27089 -0
- package/dist/parser.wasm32-wasi.wasm +0 -0
- package/dist/reporters/html.mjs +77 -0
- package/dist/rolldown-runtime-Dr7-SnC6.mjs +45 -0
- package/dist/wasm-CmiFEbUB.mjs +12995 -0
- package/dist/worker-runtime-DNtUUMeD.mjs +697 -0
- package/dist/workers/checker-worker.mjs +17 -28
- package/dist/workers/child-process-test-runner-worker.mjs +25 -38
- package/package.json +23 -22
- package/dist/node-B7U4hEuW.mjs +0 -107
- package/dist/worker-runtime-CT5LMMgY.mjs +0 -20
|
@@ -0,0 +1,697 @@
|
|
|
1
|
+
import { $n as make$2, $r as interrupt, Aa as forkUnsafe, Ai as runForkWith, Ao as ParentSpan, As as isSome, Bi as suspend, Cc as identity, Ci as provideService, Da as addFinalizerExit, Dr as catchDefect, Ea as addFinalizer, Er as catchCause, Fa as UnhandledLogLevel, Ga as interrupt$1, Gr as forkChild, Ha as die, Hr as fnUntraced, Ia as _await, Jr as forkScoped, Kt as encodeSync, La as doneUnsafe, Lr as ensuring, Ma as makeUnsafe, Mn as runForEachArray, Mo as TaggedError, Na as provide, Ni as scope, Nr as context, Oa as close, Pi as scoped, Ri as succeed, Sc as flow, Si as provideContext, So as reportCauseUnsafe, Sr as annotateLogs, Ta as Scope, Tr as callback, Ua as fail, Ui as tapCause, Va as makeUnsafe$2, Vi as sync, Vr as flatMap, Vt as decodeUnknownEffect, Xr as gen, Ya as void_$1, _a as effectDiscard, _c as constTrue, _r as acquireRelease, ar as offer, bc as constant, cr as take, do as squash, dr as getCurrent, ds as getOrUndefinedUnsafe, fs as getUnsafe, gi as onExit, gs as omit, ha as effect, hr as runIn, ia as withFiber, ii as logFatal, io as hasInterrupts, ir as make$4, ja as make$3, jo as externalSpan, ka as closeUnsafe, ki as runFork, kr as catchReason, ln as defaultFormatter, lo as map, lr as takeAll, ls as get, mc as isTagged, ms as makeUnsafe$1, ni as logDebug, oa as withSpan, os as Service, ot as Any, pa as catchDone, pi as matchEffect, qt as encodeUnknownEffect, ra as whileLoop, ro as hasDies, si as logWithLevel, ss as add, ta as void_, ti as isEffect, ui as mapError, uo as pretty, us as getOrUndefined, ut as Defect, vi as orDie, vt as NonEmptyArray, wc as pipe, wi as raceFirst, xr as andThen, ya as launch, yc as constVoid, yr as addFinalizer$1, za as isDeferred, zi as succeedNone, zr as fail$1 } from "./dist-CgglvcIb.mjs";
|
|
2
|
+
import { B as ServerClient, F as RpcSerialization, G as isStreamSchema, H as isWrapper, J as CloseEvent, K as Collector, L as RequestId, P as withRun, Q as fromInput, R as ResponseDefectEncoded, U as ClientAbort, V as exitSchema, W as getStreamSchemas, X as SocketError, Y as SocketCloseError, Z as SocketOpenError, a as NetSocket, ft as makeUnsafe$3, o as fromDuplex, q as makeCollectorUnsafe, z as constPong } from "./node-ZeTkblqG.mjs";
|
|
3
|
+
import * as Net from "node:net";
|
|
4
|
+
//#region ../../../node_modules/.pnpm/effect@4.0.0-rc.112/node_modules/effect/dist/unstable/socket/SocketServer.js
|
|
5
|
+
/**
|
|
6
|
+
* Service contract for servers that accept socket connections.
|
|
7
|
+
*
|
|
8
|
+
* `SocketServer` exposes the bound server `address` and a long-running `run`
|
|
9
|
+
* loop that hands each accepted connection to a handler as a `Socket.Socket`.
|
|
10
|
+
* The module also defines TCP and Unix socket address models plus the
|
|
11
|
+
* server-level errors reported while opening or running a server. Platform
|
|
12
|
+
* layers provide concrete implementations of this service.
|
|
13
|
+
*
|
|
14
|
+
* @since 4.0.0
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Context service for a socket server, exposing its bound address and a run
|
|
18
|
+
* loop that handles each accepted `Socket`.
|
|
19
|
+
*
|
|
20
|
+
* @category services
|
|
21
|
+
* @since 4.0.0
|
|
22
|
+
*/
|
|
23
|
+
var SocketServer = class extends Service()("@effect/platform/SocketServer") {};
|
|
24
|
+
/**
|
|
25
|
+
* Runtime type identifier attached to `SocketServerError` values.
|
|
26
|
+
*
|
|
27
|
+
* @category type IDs
|
|
28
|
+
* @since 4.0.0
|
|
29
|
+
*/
|
|
30
|
+
const ErrorTypeId = "@effect/platform/SocketServer/SocketServerError";
|
|
31
|
+
/**
|
|
32
|
+
* Error reason for failures that occur while opening a socket server.
|
|
33
|
+
*
|
|
34
|
+
* @category errors
|
|
35
|
+
* @since 4.0.0
|
|
36
|
+
*/
|
|
37
|
+
var SocketServerOpenError = class extends TaggedError("SocketServerOpenError") {
|
|
38
|
+
get message() {
|
|
39
|
+
return "Open";
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
TaggedError("SocketServerUnknownError");
|
|
43
|
+
/**
|
|
44
|
+
* Tagged socket server error that wraps a server error reason and exposes its
|
|
45
|
+
* cause.
|
|
46
|
+
*
|
|
47
|
+
* @category errors
|
|
48
|
+
* @since 4.0.0
|
|
49
|
+
*/
|
|
50
|
+
var SocketServerError = class extends TaggedError("SocketServerError") {
|
|
51
|
+
constructor(props) {
|
|
52
|
+
super({
|
|
53
|
+
...props,
|
|
54
|
+
cause: props.reason.cause
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Marks this value as a socket server error for runtime guards.
|
|
59
|
+
*
|
|
60
|
+
* @since 4.0.0
|
|
61
|
+
*/
|
|
62
|
+
[ErrorTypeId] = ErrorTypeId;
|
|
63
|
+
/**
|
|
64
|
+
* Delegates the public message to the underlying socket server error reason.
|
|
65
|
+
*
|
|
66
|
+
* @since 4.0.0
|
|
67
|
+
*/
|
|
68
|
+
get message() {
|
|
69
|
+
return this.reason.message;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region ../../../node_modules/.pnpm/effect@4.0.0-rc.112/node_modules/effect/dist/unstable/rpc/RpcServer.js
|
|
74
|
+
/**
|
|
75
|
+
* Creates an RPC server for an already-decoded message channel, running
|
|
76
|
+
* handlers for a group and sending decoded server responses through
|
|
77
|
+
* `onFromServer`.
|
|
78
|
+
*
|
|
79
|
+
* @category constructors
|
|
80
|
+
* @since 4.0.0
|
|
81
|
+
*/
|
|
82
|
+
const makeNoSerialization = /*#__PURE__*/ fnUntraced(function* (group, options) {
|
|
83
|
+
const enableTracing = options.disableTracing !== true;
|
|
84
|
+
const enableSpanPropagation = options.disableSpanPropagation !== true;
|
|
85
|
+
const supportsAck = options.disableClientAcks !== true;
|
|
86
|
+
const spanPrefix = options.spanPrefix ?? "RpcServer";
|
|
87
|
+
const concurrency = options.concurrency ?? "unbounded";
|
|
88
|
+
const disableFatalDefects = options.disableFatalDefects ?? false;
|
|
89
|
+
const services = yield* context();
|
|
90
|
+
const scope = get(services, Scope);
|
|
91
|
+
const trackFiber = runIn(forkUnsafe(scope, "parallel"));
|
|
92
|
+
const concurrencySemaphore = concurrency === "unbounded" ? void 0 : yield* make$2(concurrency);
|
|
93
|
+
const clients = /* @__PURE__ */ new Map();
|
|
94
|
+
let isShutdown = false;
|
|
95
|
+
const shutdownLatch = makeUnsafe$3(false);
|
|
96
|
+
yield* addFinalizer(scope, withFiber((parent) => {
|
|
97
|
+
isShutdown = true;
|
|
98
|
+
for (const client of clients.values()) {
|
|
99
|
+
client.ended = true;
|
|
100
|
+
if (client.fibers.size === 0) {
|
|
101
|
+
trackFiber(runForkWith(services)(endClient(client)));
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
for (const fiber of client.fibers.values()) fiber.interruptUnsafe(parent.id);
|
|
105
|
+
}
|
|
106
|
+
if (clients.size === 0) return void_;
|
|
107
|
+
return shutdownLatch.await;
|
|
108
|
+
}));
|
|
109
|
+
const disconnect = (clientId) => withFiber((parent) => {
|
|
110
|
+
const client = clients.get(clientId);
|
|
111
|
+
if (!client) return void_;
|
|
112
|
+
for (const fiber of client.fibers.values()) fiber.interruptUnsafe(parent.id);
|
|
113
|
+
clients.delete(clientId);
|
|
114
|
+
return void_;
|
|
115
|
+
});
|
|
116
|
+
const write = (clientId, message, opts) => catchDefect(withFiber((requestFiber) => {
|
|
117
|
+
if (isShutdown) return interrupt;
|
|
118
|
+
let client = clients.get(clientId);
|
|
119
|
+
if (!client) {
|
|
120
|
+
client = {
|
|
121
|
+
id: clientId,
|
|
122
|
+
latches: /* @__PURE__ */ new Map(),
|
|
123
|
+
fibers: /* @__PURE__ */ new Map(),
|
|
124
|
+
ended: false,
|
|
125
|
+
serverClient: new ServerClient(clientId)
|
|
126
|
+
};
|
|
127
|
+
clients.set(clientId, client);
|
|
128
|
+
} else if (client.ended) return interrupt;
|
|
129
|
+
switch (message._tag) {
|
|
130
|
+
case "Request": return handleRequest(requestFiber, client, message, opts);
|
|
131
|
+
case "Ack": {
|
|
132
|
+
const latch = client.latches.get(message.requestId);
|
|
133
|
+
return latch ? latch.open : void_;
|
|
134
|
+
}
|
|
135
|
+
case "Interrupt": {
|
|
136
|
+
const fiber = client.fibers.get(message.requestId);
|
|
137
|
+
if (fiber) {
|
|
138
|
+
fiber.interruptUnsafe(requestFiber.id, ClientAbort.annotation);
|
|
139
|
+
return void_;
|
|
140
|
+
}
|
|
141
|
+
return options.onFromServer({
|
|
142
|
+
_tag: "Exit",
|
|
143
|
+
clientId,
|
|
144
|
+
requestId: message.requestId,
|
|
145
|
+
exit: interrupt$1()
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
case "Eof":
|
|
149
|
+
client.ended = true;
|
|
150
|
+
if (client.fibers.size > 0) return void_;
|
|
151
|
+
return endClient(client);
|
|
152
|
+
default: return sendDefect(client, `Unknown request tag: ${message._tag}`);
|
|
153
|
+
}
|
|
154
|
+
}), (defect) => sendDefect(clients.get(clientId), defect));
|
|
155
|
+
const endClient = (client) => {
|
|
156
|
+
clients.delete(client.id);
|
|
157
|
+
const write = options.onFromServer({
|
|
158
|
+
_tag: "ClientEnd",
|
|
159
|
+
clientId: client.id
|
|
160
|
+
});
|
|
161
|
+
if (isShutdown && clients.size === 0) return andThen(write, shutdownLatch.open);
|
|
162
|
+
return write;
|
|
163
|
+
};
|
|
164
|
+
const handleRequest = (requestFiber, client, request, opts) => {
|
|
165
|
+
if (client.fibers.has(request.id)) return interrupt;
|
|
166
|
+
const rpc = group.requests.get(request.tag);
|
|
167
|
+
const entry = getOrUndefinedUnsafe(services, rpc?.key);
|
|
168
|
+
if (!rpc || !entry) {
|
|
169
|
+
const write = catchDefect(options.onFromServer({
|
|
170
|
+
_tag: "Exit",
|
|
171
|
+
clientId: client.id,
|
|
172
|
+
requestId: request.id,
|
|
173
|
+
exit: die(`Unknown request tag: ${request.tag}`)
|
|
174
|
+
}), (defect) => sendDefect(client, defect));
|
|
175
|
+
if (!client.ended || client.fibers.size > 0) return write;
|
|
176
|
+
return ensuring(write, endClient(client));
|
|
177
|
+
}
|
|
178
|
+
const isStream = isStreamSchema(rpc.successSchema);
|
|
179
|
+
const metadata = {
|
|
180
|
+
rpc,
|
|
181
|
+
client: client.serverClient,
|
|
182
|
+
requestId: request.id,
|
|
183
|
+
headers: request.headers,
|
|
184
|
+
payload: request.payload
|
|
185
|
+
};
|
|
186
|
+
const result = entry.handler(request.payload, metadata);
|
|
187
|
+
const isWrapper$1 = isWrapper(result);
|
|
188
|
+
const isFork = isWrapper$1 && result.fork;
|
|
189
|
+
const isUninterruptible = isWrapper$1 && result.uninterruptible;
|
|
190
|
+
const streamOrEffect = isWrapper$1 ? result.value : result;
|
|
191
|
+
const handler = isStream ? streamEffect(client, request, streamOrEffect) : streamOrEffect;
|
|
192
|
+
const withMiddleware = rpc.middlewares.size > 0 ? applyMiddleware(services, handler, metadata) : handler;
|
|
193
|
+
let responded = false;
|
|
194
|
+
const scope = makeUnsafe();
|
|
195
|
+
let deferred = void 0;
|
|
196
|
+
let effect = onExit(withMiddleware, (exit) => {
|
|
197
|
+
responded = true;
|
|
198
|
+
let write;
|
|
199
|
+
if (exit._tag === "Success") {
|
|
200
|
+
if (isDeferred(exit.value)) {
|
|
201
|
+
deferred = exit.value;
|
|
202
|
+
write = void_;
|
|
203
|
+
} else write = options.onFromServer({
|
|
204
|
+
_tag: "Exit",
|
|
205
|
+
clientId: client.id,
|
|
206
|
+
requestId: request.id,
|
|
207
|
+
exit
|
|
208
|
+
});
|
|
209
|
+
} else if (!disableFatalDefects && hasDies(exit.cause) && !hasInterrupts(exit.cause)) write = sendDefect(client, squash(exit.cause));
|
|
210
|
+
else write = options.onFromServer({
|
|
211
|
+
_tag: "Exit",
|
|
212
|
+
clientId: client.id,
|
|
213
|
+
requestId: request.id,
|
|
214
|
+
exit
|
|
215
|
+
});
|
|
216
|
+
const close = closeUnsafe(scope, exit);
|
|
217
|
+
if (exit._tag === "Failure") reportCauseUnsafe(getCurrent(), exit.cause);
|
|
218
|
+
return close ? ensuring(write, close) : write;
|
|
219
|
+
});
|
|
220
|
+
if (opts?.onRequest) effect = opts.onRequest(effect);
|
|
221
|
+
if (enableTracing) {
|
|
222
|
+
const parentSpan = getOrUndefined(requestFiber.context, ParentSpan);
|
|
223
|
+
effect = withSpan(effect, `${spanPrefix}.${request.tag}`, {
|
|
224
|
+
captureStackTrace: false,
|
|
225
|
+
attributes: options.spanAttributes,
|
|
226
|
+
parent: enableSpanPropagation && request.spanId ? externalSpan({
|
|
227
|
+
traceId: request.traceId,
|
|
228
|
+
spanId: request.spanId,
|
|
229
|
+
sampled: request.sampled
|
|
230
|
+
}) : void 0,
|
|
231
|
+
links: enableSpanPropagation && parentSpan ? [{
|
|
232
|
+
span: parentSpan,
|
|
233
|
+
attributes: {}
|
|
234
|
+
}] : void 0
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
if (!isFork && concurrencySemaphore) effect = concurrencySemaphore.withPermit(effect);
|
|
238
|
+
const context = new Map(entry.context.mapUnsafe);
|
|
239
|
+
requestFiber.context.mapUnsafe.forEach((value, key) => context.set(key, value));
|
|
240
|
+
context.set(Scope.key, scope);
|
|
241
|
+
const runFork = runForkWith(makeUnsafe$1(context));
|
|
242
|
+
const fiber = trackFiber(runFork(effect, isUninterruptible ? { uninterruptible: true } : void 0));
|
|
243
|
+
client.fibers.set(request.id, fiber);
|
|
244
|
+
fiber.addObserver(function onExit$1(exit) {
|
|
245
|
+
if (deferred) {
|
|
246
|
+
const fiber = trackFiber(runFork(onExit(_await(deferred), (exit) => options.onFromServer({
|
|
247
|
+
_tag: "Exit",
|
|
248
|
+
clientId: client.id,
|
|
249
|
+
requestId: request.id,
|
|
250
|
+
exit
|
|
251
|
+
}))));
|
|
252
|
+
client.fibers.set(request.id, fiber);
|
|
253
|
+
deferred = void 0;
|
|
254
|
+
fiber.addObserver(onExit$1);
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
if (!responded && exit._tag === "Failure") trackFiber(runFork(options.onFromServer({
|
|
258
|
+
_tag: "Exit",
|
|
259
|
+
clientId: client.id,
|
|
260
|
+
requestId: request.id,
|
|
261
|
+
exit: interrupt$1()
|
|
262
|
+
})));
|
|
263
|
+
client.fibers.delete(request.id);
|
|
264
|
+
client.latches.delete(request.id);
|
|
265
|
+
if (client.ended && client.fibers.size === 0) trackFiber(runFork(endClient(client)));
|
|
266
|
+
});
|
|
267
|
+
return void_;
|
|
268
|
+
};
|
|
269
|
+
const streamEffect = (client, request, stream) => {
|
|
270
|
+
let latch = client.latches.get(request.id);
|
|
271
|
+
if (supportsAck && !latch) {
|
|
272
|
+
latch = makeUnsafe$3(false);
|
|
273
|
+
client.latches.set(request.id, latch);
|
|
274
|
+
}
|
|
275
|
+
if (isEffect(stream)) return stream.pipe(flatMap((queue) => whileLoop({
|
|
276
|
+
while: constTrue,
|
|
277
|
+
body: constant(flatMap(takeAll(queue), (values) => {
|
|
278
|
+
const write = options.onFromServer({
|
|
279
|
+
_tag: "Chunk",
|
|
280
|
+
clientId: client.id,
|
|
281
|
+
requestId: request.id,
|
|
282
|
+
values
|
|
283
|
+
});
|
|
284
|
+
if (!latch) return write;
|
|
285
|
+
latch.closeUnsafe();
|
|
286
|
+
return flatMap(write, () => latch.await);
|
|
287
|
+
})),
|
|
288
|
+
step: constVoid
|
|
289
|
+
})), catchDone(() => void_), scoped);
|
|
290
|
+
return runForEachArray(stream, (values) => {
|
|
291
|
+
const write = options.onFromServer({
|
|
292
|
+
_tag: "Chunk",
|
|
293
|
+
clientId: client.id,
|
|
294
|
+
requestId: request.id,
|
|
295
|
+
values
|
|
296
|
+
});
|
|
297
|
+
if (!latch) return write;
|
|
298
|
+
latch.closeUnsafe();
|
|
299
|
+
return andThen(write, latch.await);
|
|
300
|
+
});
|
|
301
|
+
};
|
|
302
|
+
const sendDefect = (client, defect) => suspend(() => {
|
|
303
|
+
const shouldEnd = client.ended && client.fibers.size === 0;
|
|
304
|
+
const write = options.onFromServer({
|
|
305
|
+
_tag: "Defect",
|
|
306
|
+
clientId: client.id,
|
|
307
|
+
defect
|
|
308
|
+
});
|
|
309
|
+
if (!shouldEnd) return write;
|
|
310
|
+
return andThen(write, endClient(client));
|
|
311
|
+
});
|
|
312
|
+
return identity({
|
|
313
|
+
write,
|
|
314
|
+
disconnect
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
const applyMiddleware = (context, handler, options) => {
|
|
318
|
+
for (const service of options.rpc.middlewares) handler = getUnsafe(context, service)(handler, options);
|
|
319
|
+
return handler;
|
|
320
|
+
};
|
|
321
|
+
/**
|
|
322
|
+
* Runs an RPC server for a group using the current server `Protocol`, decoding
|
|
323
|
+
* requests, invoking handlers, encoding responses, and managing in-flight
|
|
324
|
+
* request lifetime.
|
|
325
|
+
*
|
|
326
|
+
* @category running
|
|
327
|
+
* @since 4.0.0
|
|
328
|
+
*/
|
|
329
|
+
const make$1 = /*#__PURE__*/ fnUntraced(function* (group, options) {
|
|
330
|
+
const { codecFor, disconnects, end, run, send, supportsAck, supportsSpanPropagation, supportsTransferables } = yield* Protocol;
|
|
331
|
+
const encodeDefectUnsafe = encodeSync(codecFor(Defect()));
|
|
332
|
+
const services = yield* context();
|
|
333
|
+
const scope = yield* make$3();
|
|
334
|
+
const server = yield* makeNoSerialization(group, {
|
|
335
|
+
...options,
|
|
336
|
+
disableClientAcks: !supportsAck,
|
|
337
|
+
disableSpanPropagation: !supportsSpanPropagation,
|
|
338
|
+
onFromServer(response) {
|
|
339
|
+
const client = clients.get(response.clientId);
|
|
340
|
+
if (!client) return void_;
|
|
341
|
+
switch (response._tag) {
|
|
342
|
+
case "Chunk": {
|
|
343
|
+
const schemas = client.schemas.get(response.requestId);
|
|
344
|
+
if (!schemas) return void_;
|
|
345
|
+
return handleEncode(client, response.requestId, schemas.encodeDefect, schemas.collector, provideContext(schemas.encodeChunk(response.values), schemas.context), (values) => ({
|
|
346
|
+
_tag: "Chunk",
|
|
347
|
+
requestId: response.requestId,
|
|
348
|
+
values
|
|
349
|
+
}));
|
|
350
|
+
}
|
|
351
|
+
case "Exit": {
|
|
352
|
+
const schemas = client.schemas.get(response.requestId);
|
|
353
|
+
if (!schemas) return void_;
|
|
354
|
+
client.schemas.delete(response.requestId);
|
|
355
|
+
return handleEncode(client, response.requestId, schemas.encodeDefect, schemas.collector, provideContext(schemas.encodeExit(response.exit), schemas.context), (exit) => ({
|
|
356
|
+
_tag: "Exit",
|
|
357
|
+
requestId: response.requestId,
|
|
358
|
+
exit
|
|
359
|
+
}));
|
|
360
|
+
}
|
|
361
|
+
case "Defect": return sendDefect(client, response.defect);
|
|
362
|
+
case "ClientEnd":
|
|
363
|
+
clients.delete(response.clientId);
|
|
364
|
+
return end(response.clientId);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}).pipe(provide(scope));
|
|
368
|
+
yield* forkChild(whileLoop({
|
|
369
|
+
while: constTrue,
|
|
370
|
+
body: constant(flatMap(take(disconnects), (clientId) => {
|
|
371
|
+
clients.delete(clientId);
|
|
372
|
+
return server.disconnect(clientId);
|
|
373
|
+
})),
|
|
374
|
+
step: constVoid
|
|
375
|
+
}));
|
|
376
|
+
const schemasCache = /* @__PURE__ */ new WeakMap();
|
|
377
|
+
const getSchemas = (rpc) => {
|
|
378
|
+
let schemas = schemasCache.get(rpc);
|
|
379
|
+
if (!schemas) {
|
|
380
|
+
const entry = getOrUndefinedUnsafe(services, rpc.key);
|
|
381
|
+
const streamSchemas = getStreamSchemas(rpc.successSchema);
|
|
382
|
+
schemas = {
|
|
383
|
+
decode: decodeUnknownEffect(codecFor(rpc.payloadSchema)),
|
|
384
|
+
encodeChunk: encodeUnknownEffect(codecFor(NonEmptyArray(isSome(streamSchemas) ? streamSchemas.value.success : Any))),
|
|
385
|
+
encodeExit: encodeUnknownEffect(codecFor(exitSchema(rpc))),
|
|
386
|
+
encodeDefect: encodeUnknownEffect(codecFor(rpc.defectSchema)),
|
|
387
|
+
context: entry.context
|
|
388
|
+
};
|
|
389
|
+
schemasCache.set(rpc, schemas);
|
|
390
|
+
}
|
|
391
|
+
return schemas;
|
|
392
|
+
};
|
|
393
|
+
const clients = /* @__PURE__ */ new Map();
|
|
394
|
+
const handleEncode = (client, requestId, encodeDefect, collector, effect, onSuccess) => (collector ? provideService(effect, Collector, collector) : effect).pipe(flatMap((a) => send(client.id, onSuccess(a), collector && collector.clearUnsafe())), catchCause((cause) => {
|
|
395
|
+
client.schemas.delete(requestId);
|
|
396
|
+
const defect = squash(map(cause, (e) => defaultFormatter(e.issue)));
|
|
397
|
+
return andThen(sendRequestDefect(client, requestId, encodeDefect, defect), server.write(client.id, {
|
|
398
|
+
_tag: "Interrupt",
|
|
399
|
+
requestId,
|
|
400
|
+
interruptors: []
|
|
401
|
+
}));
|
|
402
|
+
}));
|
|
403
|
+
const sendRequestDefect = (client, requestId, encodeDefect, defect) => catchCause(flatMap(encodeDefect(defect), (encodedDefect) => send(client.id, {
|
|
404
|
+
_tag: "Exit",
|
|
405
|
+
requestId,
|
|
406
|
+
exit: {
|
|
407
|
+
_tag: "Failure",
|
|
408
|
+
cause: [{
|
|
409
|
+
_tag: "Die",
|
|
410
|
+
defect: encodedDefect
|
|
411
|
+
}]
|
|
412
|
+
}
|
|
413
|
+
})), (cause) => sendDefect(client, squash(cause)));
|
|
414
|
+
const sendDefect = (client, defect) => catchCause(send(client.id, ResponseDefectEncoded(encodeDefectUnsafe(defect))), (cause) => annotateLogs(logDebug(cause), {
|
|
415
|
+
module: "RpcServer",
|
|
416
|
+
method: "sendDefect"
|
|
417
|
+
}));
|
|
418
|
+
return yield* run((clientId, request) => {
|
|
419
|
+
let client = clients.get(clientId);
|
|
420
|
+
if (!client) {
|
|
421
|
+
client = {
|
|
422
|
+
id: clientId,
|
|
423
|
+
schemas: /* @__PURE__ */ new Map()
|
|
424
|
+
};
|
|
425
|
+
clients.set(clientId, client);
|
|
426
|
+
}
|
|
427
|
+
switch (request._tag) {
|
|
428
|
+
case "Request": {
|
|
429
|
+
const tag = Object.hasOwn(request, "tag") ? request.tag : "";
|
|
430
|
+
let requestId;
|
|
431
|
+
switch (typeof request.id) {
|
|
432
|
+
case "number":
|
|
433
|
+
case "string":
|
|
434
|
+
requestId = RequestId(request.id);
|
|
435
|
+
break;
|
|
436
|
+
default: return sendDefect(client, `Invalid request id: ${request.id}`);
|
|
437
|
+
}
|
|
438
|
+
const rpc = group.requests.get(tag);
|
|
439
|
+
if (!rpc) return sendRequestDefect(client, requestId, (defect) => succeed(defect), `Unknown request tag: ${tag}`);
|
|
440
|
+
const schemas = getSchemas(rpc);
|
|
441
|
+
return matchEffect(provideContext(schemas.decode(request.payload), schemas.context), {
|
|
442
|
+
onFailure: (error) => sendRequestDefect(client, requestId, schemas.encodeDefect, defaultFormatter(error.issue)),
|
|
443
|
+
onSuccess: (payload) => {
|
|
444
|
+
client.schemas.set(requestId, supportsTransferables ? {
|
|
445
|
+
...schemas,
|
|
446
|
+
collector: makeCollectorUnsafe()
|
|
447
|
+
} : schemas);
|
|
448
|
+
return server.write(clientId, {
|
|
449
|
+
...request,
|
|
450
|
+
id: requestId,
|
|
451
|
+
payload,
|
|
452
|
+
headers: fromInput(request.headers)
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
case "Ping": return catchCause(send(client.id, constPong), (cause) => sendDefect(client, squash(cause)));
|
|
458
|
+
case "Eof": return server.write(clientId, request);
|
|
459
|
+
case "Ack": return server.write(clientId, {
|
|
460
|
+
...request,
|
|
461
|
+
requestId: RequestId(request.requestId)
|
|
462
|
+
});
|
|
463
|
+
case "Interrupt": return server.write(clientId, {
|
|
464
|
+
...request,
|
|
465
|
+
requestId: RequestId(request.requestId),
|
|
466
|
+
interruptors: []
|
|
467
|
+
});
|
|
468
|
+
default: return sendDefect(client, `Unknown request tag: ${request._tag}`);
|
|
469
|
+
}
|
|
470
|
+
}).pipe(tapCause((cause) => logFatal("BUG: RpcServer protocol crashed", cause)), onExit((exit) => close(scope, exit)));
|
|
471
|
+
});
|
|
472
|
+
/**
|
|
473
|
+
* Provides a scoped layer that starts an RPC server for a group using the
|
|
474
|
+
* current server `Protocol`.
|
|
475
|
+
*
|
|
476
|
+
* @category layers
|
|
477
|
+
* @since 4.0.0
|
|
478
|
+
*/
|
|
479
|
+
const layer$1 = (group, options) => effectDiscard(forkScoped(make$1(group, options)));
|
|
480
|
+
/**
|
|
481
|
+
* Defines the service interface for an RPC server transport, responsible for receiving
|
|
482
|
+
* encoded client messages, sending encoded responses, tracking clients, and
|
|
483
|
+
* declaring transport capabilities.
|
|
484
|
+
*
|
|
485
|
+
* **When to use**
|
|
486
|
+
*
|
|
487
|
+
* Use to provide the transport boundary for RPC servers over HTTP, WebSocket,
|
|
488
|
+
* workers, sockets, or custom protocols.
|
|
489
|
+
*
|
|
490
|
+
* @category services
|
|
491
|
+
* @since 4.0.0
|
|
492
|
+
*/
|
|
493
|
+
var Protocol = class extends Service()("effect/rpc/RpcServer/Protocol") {
|
|
494
|
+
/**
|
|
495
|
+
* Creates a server protocol service from the supplied RPC implementation.
|
|
496
|
+
*
|
|
497
|
+
* @since 4.0.0
|
|
498
|
+
*/
|
|
499
|
+
static make = /*#__PURE__*/ withRun();
|
|
500
|
+
};
|
|
501
|
+
/**
|
|
502
|
+
* Creates a server `Protocol` backed by the current `SocketServer`, accepting
|
|
503
|
+
* socket connections and routing decoded RPC messages.
|
|
504
|
+
*
|
|
505
|
+
* @category protocols
|
|
506
|
+
* @since 4.0.0
|
|
507
|
+
*/
|
|
508
|
+
const makeProtocolSocketServer = /*#__PURE__*/ gen(function* () {
|
|
509
|
+
const server = yield* SocketServer;
|
|
510
|
+
const { onSocket, protocol } = yield* makeSocketProtocol;
|
|
511
|
+
yield* forkScoped(server.run(fnUntraced(onSocket, scoped)));
|
|
512
|
+
return protocol;
|
|
513
|
+
});
|
|
514
|
+
/**
|
|
515
|
+
* RPC protocol that uses `SocketServer` for communication.
|
|
516
|
+
*
|
|
517
|
+
* @category layers
|
|
518
|
+
* @since 4.0.0
|
|
519
|
+
*/
|
|
520
|
+
const layerProtocolSocketServer = /*#__PURE__*/ effect(Protocol)(makeProtocolSocketServer);
|
|
521
|
+
const makeSocketProtocol = /*#__PURE__*/ gen(function* () {
|
|
522
|
+
const serialization = yield* RpcSerialization;
|
|
523
|
+
const encodeDefectUnsafe = encodeSync(serialization.codecFor(Defect()));
|
|
524
|
+
const disconnects = yield* make$4();
|
|
525
|
+
let clientId = 0;
|
|
526
|
+
const clients = /* @__PURE__ */ new Map();
|
|
527
|
+
const clientIds = /* @__PURE__ */ new Set();
|
|
528
|
+
let writeRequest;
|
|
529
|
+
const onSocket = function* (socket, headers) {
|
|
530
|
+
const scope$1 = yield* scope;
|
|
531
|
+
const parser = serialization.makeUnsafe();
|
|
532
|
+
const id = clientId++;
|
|
533
|
+
yield* addFinalizerExit(scope$1, () => {
|
|
534
|
+
clients.delete(id);
|
|
535
|
+
clientIds.delete(id);
|
|
536
|
+
return offer(disconnects, id);
|
|
537
|
+
});
|
|
538
|
+
const writeRaw = yield* socket.writer;
|
|
539
|
+
const write = (response) => {
|
|
540
|
+
try {
|
|
541
|
+
const encoded = parser.encode(response);
|
|
542
|
+
if (encoded === void 0) return void_;
|
|
543
|
+
return orDie(writeRaw(encoded));
|
|
544
|
+
} catch (cause) {
|
|
545
|
+
return orDie(writeRaw(parser.encode(ResponseDefectEncoded(encodeDefectUnsafe(cause)))));
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
clients.set(id, { write });
|
|
549
|
+
clientIds.add(id);
|
|
550
|
+
yield* socket.runRaw((data) => {
|
|
551
|
+
try {
|
|
552
|
+
const decoded = parser.decode(data);
|
|
553
|
+
if (decoded.length === 0) return void_;
|
|
554
|
+
let i = 0;
|
|
555
|
+
return whileLoop({
|
|
556
|
+
while: () => i < decoded.length,
|
|
557
|
+
body() {
|
|
558
|
+
const message = decoded[i++];
|
|
559
|
+
if (message._tag === "Request" && headers) message.headers = headers.concat(message.headers);
|
|
560
|
+
return writeRequest(id, message);
|
|
561
|
+
},
|
|
562
|
+
step: constVoid
|
|
563
|
+
});
|
|
564
|
+
} catch (cause) {
|
|
565
|
+
if (isTagged(cause, "MaxBufferSizeExceeded")) return writeRaw(new CloseEvent(1009, String(cause)));
|
|
566
|
+
return writeRaw(parser.encode(ResponseDefectEncoded(encodeDefectUnsafe(cause))));
|
|
567
|
+
}
|
|
568
|
+
}).pipe(catchReason("SocketError", "SocketCloseError", (_) => void_), orDie);
|
|
569
|
+
};
|
|
570
|
+
return {
|
|
571
|
+
protocol: yield* Protocol.make((writeRequest_) => {
|
|
572
|
+
writeRequest = writeRequest_;
|
|
573
|
+
return succeed({
|
|
574
|
+
disconnects,
|
|
575
|
+
send: (clientId, response) => {
|
|
576
|
+
const client = clients.get(clientId);
|
|
577
|
+
if (!client) return void_;
|
|
578
|
+
return orDie(client.write(response));
|
|
579
|
+
},
|
|
580
|
+
end(_clientId) {
|
|
581
|
+
return void_;
|
|
582
|
+
},
|
|
583
|
+
clientIds: sync(() => clientIds),
|
|
584
|
+
initialMessage: succeedNone,
|
|
585
|
+
supportsAck: true,
|
|
586
|
+
supportsTransferables: false,
|
|
587
|
+
supportsSpanPropagation: true,
|
|
588
|
+
supportsNotifications: true,
|
|
589
|
+
codecFor: serialization.codecFor
|
|
590
|
+
});
|
|
591
|
+
}),
|
|
592
|
+
onSocket
|
|
593
|
+
};
|
|
594
|
+
});
|
|
595
|
+
Service()("@effect/platform-node-shared/NodeSocketServer/IncomingMessage");
|
|
596
|
+
/**
|
|
597
|
+
* Provides a TCP `SocketServer` by creating and managing a scoped Node
|
|
598
|
+
* `net.Server` with the supplied server and listen options.
|
|
599
|
+
*
|
|
600
|
+
* @category layers
|
|
601
|
+
* @since 4.0.0
|
|
602
|
+
*/
|
|
603
|
+
const layer = /*#__PURE__*/ flow(/* @__PURE__ */ fnUntraced(function* (options) {
|
|
604
|
+
const errorDeferred = makeUnsafe$2();
|
|
605
|
+
const pending = /* @__PURE__ */ new Map();
|
|
606
|
+
function defaultOnConnection(conn) {
|
|
607
|
+
const remove = () => {
|
|
608
|
+
pending.delete(conn);
|
|
609
|
+
conn.off("close", remove);
|
|
610
|
+
conn.off("error", remove);
|
|
611
|
+
};
|
|
612
|
+
pending.set(conn, remove);
|
|
613
|
+
conn.on("close", remove);
|
|
614
|
+
conn.on("error", remove);
|
|
615
|
+
}
|
|
616
|
+
let onConnection = defaultOnConnection;
|
|
617
|
+
let server;
|
|
618
|
+
yield* addFinalizer$1(() => callback((resume) => {
|
|
619
|
+
pending.forEach((remove, conn) => {
|
|
620
|
+
remove();
|
|
621
|
+
conn.destroy();
|
|
622
|
+
});
|
|
623
|
+
server?.close(() => resume(void_));
|
|
624
|
+
}));
|
|
625
|
+
server = Net.createServer(options, (conn) => onConnection(conn));
|
|
626
|
+
server.on("error", (err) => doneUnsafe(errorDeferred, fail(err)));
|
|
627
|
+
yield* callback((resume) => {
|
|
628
|
+
server.listen(options, () => resume(void_));
|
|
629
|
+
}).pipe(raceFirst(mapError(_await(errorDeferred), (err) => new SocketServerError({ reason: new SocketServerOpenError({ cause: err }) }))));
|
|
630
|
+
const run = fnUntraced(function* (handler) {
|
|
631
|
+
const scope = yield* make$3();
|
|
632
|
+
const services = omit(Scope)(yield* context());
|
|
633
|
+
const trackFiber = runIn(scope);
|
|
634
|
+
const prevOnConnection = onConnection;
|
|
635
|
+
onConnection = function(conn) {
|
|
636
|
+
let error;
|
|
637
|
+
conn.on("error", (err) => {
|
|
638
|
+
error = err;
|
|
639
|
+
});
|
|
640
|
+
pipe(fromDuplex(acquireRelease(suspend(() => {
|
|
641
|
+
if (error) return fail$1(new SocketError({ reason: new SocketOpenError({
|
|
642
|
+
kind: "Unknown",
|
|
643
|
+
cause: error
|
|
644
|
+
}) }));
|
|
645
|
+
else if (conn.closed) return fail$1(new SocketError({ reason: new SocketCloseError({ code: 1e3 }) }));
|
|
646
|
+
return succeed(conn);
|
|
647
|
+
}), (conn) => sync(() => {
|
|
648
|
+
if (conn.closed === false) conn.destroySoon();
|
|
649
|
+
}))), flatMap(handler), catchCause(reportUnhandledError), runForkWith(add(services, NetSocket, conn)), trackFiber);
|
|
650
|
+
};
|
|
651
|
+
pending.forEach((remove, conn) => {
|
|
652
|
+
remove();
|
|
653
|
+
onConnection(conn);
|
|
654
|
+
});
|
|
655
|
+
return yield* callback((_resume) => {
|
|
656
|
+
return suspend(() => {
|
|
657
|
+
onConnection = prevOnConnection;
|
|
658
|
+
return close(scope, void_$1);
|
|
659
|
+
});
|
|
660
|
+
});
|
|
661
|
+
});
|
|
662
|
+
const address = server.address();
|
|
663
|
+
return SocketServer.of({
|
|
664
|
+
address: typeof address === "string" ? {
|
|
665
|
+
_tag: "UnixAddress",
|
|
666
|
+
path: address
|
|
667
|
+
} : {
|
|
668
|
+
_tag: "TcpAddress",
|
|
669
|
+
hostname: address.address,
|
|
670
|
+
port: address.port
|
|
671
|
+
},
|
|
672
|
+
run
|
|
673
|
+
});
|
|
674
|
+
}), /*#__PURE__*/ effect(SocketServer));
|
|
675
|
+
const reportUnhandledError = (cause) => withFiber((fiber) => {
|
|
676
|
+
const unhandledLogLevel = fiber.getRef(UnhandledLogLevel);
|
|
677
|
+
if (unhandledLogLevel) return logWithLevel(unhandledLogLevel)(cause, "Unhandled error in SocketServer");
|
|
678
|
+
return void_;
|
|
679
|
+
});
|
|
680
|
+
//#endregion
|
|
681
|
+
//#region src/workers/worker-runtime.ts
|
|
682
|
+
const workerSocketPath = (label) => {
|
|
683
|
+
const socketPath = process.env["STRYKER_SOCKET"];
|
|
684
|
+
if (socketPath === void 0) {
|
|
685
|
+
process.stderr.write(`${label}: STRYKER_SOCKET is not set\n`);
|
|
686
|
+
process.exit(1);
|
|
687
|
+
}
|
|
688
|
+
return socketPath;
|
|
689
|
+
};
|
|
690
|
+
const launchWorker = (main, label) => {
|
|
691
|
+
runFork(launch(main).pipe(tapCause((cause) => sync(() => {
|
|
692
|
+
process.stderr.write(`${label}: ${pretty(cause)}\n`);
|
|
693
|
+
process.exitCode = 1;
|
|
694
|
+
}))));
|
|
695
|
+
};
|
|
696
|
+
//#endregion
|
|
697
|
+
export { layerProtocolSocketServer as a, layer$1 as i, workerSocketPath as n, layer as r, launchWorker as t };
|