@deslop/coding-standards 0.1.1257 → 0.1.1258
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 +20 -0
- package/dist/lint.d.ts +1 -0
- package/dist/lint.js +791 -7163
- package/dist/main.cli.js +22496 -3
- package/dist/rules-DTNpsy5k.mjs +25759 -0
- package/dist/upgrade-B6wL9Y5m.mjs +615 -0
- package/package.json +3 -4
|
@@ -0,0 +1,615 @@
|
|
|
1
|
+
import { $a as ensure, Bn as fail, Dt as optional, Fr as suspend, Ir as sync, Ni as provide, Oi as addFinalizer, Pr as succeed, Qs as hasProperty, Vr as timeoutOrElse, Wo as Service, Yr as void_, Zo as merge, Zr as withFiber, bt as Union, er as gen, ft as Literals, gn as acquireRelease, gt as String, hc as identity, kr as scope, kt as tag, on as value, ot as Defect, qr as updateContext, st as Error$1, ut as Int, vo as map, vt as TaggedError, wn as callback, xn as as } from "./rules-DTNpsy5k.mjs";
|
|
2
|
+
import { t as makeUnsafe } from "./main.cli.js";
|
|
3
|
+
import { Readable, finished } from "node:stream";
|
|
4
|
+
import { Buffer as Buffer$1 } from "node:buffer";
|
|
5
|
+
import * as Tls from "node:tls";
|
|
6
|
+
// ../../node_modules/.pnpm/effect@4.1.2/node_modules/effect/dist/socket/Socket.js
|
|
7
|
+
/**
|
|
8
|
+
* Runtime type identifier attached to `Socket` services.
|
|
9
|
+
*
|
|
10
|
+
* @stability unstable
|
|
11
|
+
* @category type IDs
|
|
12
|
+
* @since 4.0.0
|
|
13
|
+
*/
|
|
14
|
+
const TypeId = "~effect/socket/Socket";
|
|
15
|
+
/**
|
|
16
|
+
* Service tag for bidirectional socket transports.
|
|
17
|
+
*
|
|
18
|
+
* **When to use**
|
|
19
|
+
*
|
|
20
|
+
* Use to access or provide the socket implementation used by programs that
|
|
21
|
+
* read and write frames through the Effect environment.
|
|
22
|
+
*
|
|
23
|
+
* @stability unstable
|
|
24
|
+
* @category services
|
|
25
|
+
* @since 4.0.0
|
|
26
|
+
*/
|
|
27
|
+
const Socket = /*#__PURE__*/ Service("effect/socket/Socket");
|
|
28
|
+
/**
|
|
29
|
+
* Constructs a `Socket` from a reader acquisition and a scoped writer.
|
|
30
|
+
*
|
|
31
|
+
* **Details**
|
|
32
|
+
*
|
|
33
|
+
* The reader must fail a suspended pull when its acquisition scope closes; see
|
|
34
|
+
* `Socket` for why. A reader that leaves a pull blocked forever will hang any
|
|
35
|
+
* consumer that shuts the socket down by closing that scope.
|
|
36
|
+
*
|
|
37
|
+
* @stability unstable
|
|
38
|
+
* @category constructors
|
|
39
|
+
* @since 4.0.0
|
|
40
|
+
*/
|
|
41
|
+
const make = (options) => Socket.of({
|
|
42
|
+
[TypeId]: TypeId,
|
|
43
|
+
reader: options.reader,
|
|
44
|
+
writer: options.writer
|
|
45
|
+
});
|
|
46
|
+
const CloseEventTypeId = "~effect/socket/Socket/CloseEvent";
|
|
47
|
+
/**
|
|
48
|
+
* Returns `true` when a value is a `CloseEvent`.
|
|
49
|
+
*
|
|
50
|
+
* @stability unstable
|
|
51
|
+
* @category guards
|
|
52
|
+
* @since 4.0.0
|
|
53
|
+
*/
|
|
54
|
+
const isCloseEvent = (u) => hasProperty(u, CloseEventTypeId);
|
|
55
|
+
/**
|
|
56
|
+
* Runtime type identifier attached to `SocketError` values.
|
|
57
|
+
*
|
|
58
|
+
* @stability unstable
|
|
59
|
+
* @category type IDs
|
|
60
|
+
* @since 4.0.0
|
|
61
|
+
*/
|
|
62
|
+
const SocketErrorTypeId = "~effect/socket/Socket/SocketError";
|
|
63
|
+
/**
|
|
64
|
+
* Returns `true` when a value is a `SocketError`.
|
|
65
|
+
*
|
|
66
|
+
* @stability unstable
|
|
67
|
+
* @category guards
|
|
68
|
+
* @since 4.0.0
|
|
69
|
+
*/
|
|
70
|
+
const isSocketError = (u) => hasProperty(u, SocketErrorTypeId);
|
|
71
|
+
/**
|
|
72
|
+
* Typed error for failures that occur while reading from a socket.
|
|
73
|
+
*
|
|
74
|
+
* @stability unstable
|
|
75
|
+
* @category errors
|
|
76
|
+
* @since 4.0.0
|
|
77
|
+
*/
|
|
78
|
+
var SocketReadError = class extends (/*#__PURE__*/ Error$1("effect/socket/Socket/SocketReadError")({
|
|
79
|
+
_tag: /*#__PURE__*/ tag("SocketReadError"),
|
|
80
|
+
cause: /*#__PURE__*/ Defect()
|
|
81
|
+
})) {
|
|
82
|
+
/**
|
|
83
|
+
* Default message used for socket read failures.
|
|
84
|
+
*
|
|
85
|
+
* @stability unstable
|
|
86
|
+
* @since 4.0.0
|
|
87
|
+
*/
|
|
88
|
+
message = `An error occurred during Read`;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Typed error for failures that occur while writing to a socket.
|
|
92
|
+
*
|
|
93
|
+
* @stability unstable
|
|
94
|
+
* @category errors
|
|
95
|
+
* @since 4.0.0
|
|
96
|
+
*/
|
|
97
|
+
var SocketWriteError = class extends (/*#__PURE__*/ Error$1("effect/socket/Socket/SocketWriteError")({
|
|
98
|
+
_tag: /*#__PURE__*/ tag("SocketWriteError"),
|
|
99
|
+
cause: /*#__PURE__*/ Defect()
|
|
100
|
+
})) {
|
|
101
|
+
/**
|
|
102
|
+
* Default message used for socket write failures.
|
|
103
|
+
*
|
|
104
|
+
* @stability unstable
|
|
105
|
+
* @since 4.0.0
|
|
106
|
+
*/
|
|
107
|
+
message = `An error occurred during Write`;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Typed error for failures that occur while opening a socket, including
|
|
111
|
+
* unknown open failures and open timeouts.
|
|
112
|
+
*
|
|
113
|
+
* @stability unstable
|
|
114
|
+
* @category errors
|
|
115
|
+
* @since 4.0.0
|
|
116
|
+
*/
|
|
117
|
+
var SocketOpenError = class extends (/*#__PURE__*/ Error$1("effect/socket/Socket/SocketOpenError")({
|
|
118
|
+
_tag: /*#__PURE__*/ tag("SocketOpenError"),
|
|
119
|
+
kind: /*#__PURE__*/ Literals(["Unknown", "Timeout"]),
|
|
120
|
+
cause: /*#__PURE__*/ Defect()
|
|
121
|
+
})) {
|
|
122
|
+
/**
|
|
123
|
+
* Formats timeout and unknown open failures for display.
|
|
124
|
+
*
|
|
125
|
+
* @stability unstable
|
|
126
|
+
* @since 4.0.0
|
|
127
|
+
*/
|
|
128
|
+
get message() {
|
|
129
|
+
return this.kind === "Timeout" ? `timeout waiting for "open"` : `An error occurred during Open`;
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Typed error for an unsupported or failed in-place TLS upgrade.
|
|
134
|
+
*
|
|
135
|
+
* @stability unstable
|
|
136
|
+
* @category errors
|
|
137
|
+
* @since 4.0.0
|
|
138
|
+
*/
|
|
139
|
+
var SocketUpgradeError = class SocketUpgradeError extends (/*#__PURE__*/ Error$1("effect/socket/Socket/SocketUpgradeError")({
|
|
140
|
+
_tag: /*#__PURE__*/ tag("SocketUpgradeError"),
|
|
141
|
+
cause: /*#__PURE__*/ optional(/*#__PURE__*/ Defect())
|
|
142
|
+
})) {
|
|
143
|
+
/**
|
|
144
|
+
* An upgrade implementation for transports that cannot wrap the connection
|
|
145
|
+
* with TLS.
|
|
146
|
+
*
|
|
147
|
+
* @stability unstable
|
|
148
|
+
* @since 4.0.0
|
|
149
|
+
*/
|
|
150
|
+
static unsupported = () => fail(new SocketError({ reason: new SocketUpgradeError({}) }));
|
|
151
|
+
get message() {
|
|
152
|
+
return this.cause === void 0 ? `Socket does not support TLS upgrade` : `An error occurred during TLS upgrade`;
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Typed error for a socket close, carrying the close code and optional close
|
|
157
|
+
* reason.
|
|
158
|
+
*
|
|
159
|
+
* **Details**
|
|
160
|
+
*
|
|
161
|
+
* Sockets never classify closes: any close, whatever the code, fails the
|
|
162
|
+
* reader with a `SocketError` wrapping this reason. Consumers that treat a
|
|
163
|
+
* close as normal catch it.
|
|
164
|
+
*
|
|
165
|
+
* @stability unstable
|
|
166
|
+
* @category errors
|
|
167
|
+
* @since 4.0.0
|
|
168
|
+
*/
|
|
169
|
+
var SocketCloseError = class extends (/*#__PURE__*/ Error$1("effect/socket/Socket/SocketCloseError")({
|
|
170
|
+
_tag: /*#__PURE__*/ tag("SocketCloseError"),
|
|
171
|
+
code: Int,
|
|
172
|
+
closeReason: /*#__PURE__*/ optional(String)
|
|
173
|
+
})) {
|
|
174
|
+
get message() {
|
|
175
|
+
if (this.closeReason) return `${this.code}: ${this.closeReason}`;
|
|
176
|
+
return `${this.code}`;
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* Schema for all socket-specific error reasons.
|
|
181
|
+
*
|
|
182
|
+
* @stability unstable
|
|
183
|
+
* @category errors
|
|
184
|
+
* @since 4.0.0
|
|
185
|
+
*/
|
|
186
|
+
const SocketErrorReason = /*#__PURE__*/ Union([
|
|
187
|
+
SocketReadError,
|
|
188
|
+
SocketWriteError,
|
|
189
|
+
SocketOpenError,
|
|
190
|
+
SocketUpgradeError,
|
|
191
|
+
SocketCloseError
|
|
192
|
+
]);
|
|
193
|
+
/**
|
|
194
|
+
* Tagged error that wraps socket read, write, open, upgrade, and close failures
|
|
195
|
+
* while preserving the underlying reason.
|
|
196
|
+
*
|
|
197
|
+
* @stability unstable
|
|
198
|
+
* @category errors
|
|
199
|
+
* @since 4.0.0
|
|
200
|
+
*/
|
|
201
|
+
var SocketError = class extends (/*#__PURE__*/ TaggedError(SocketErrorTypeId)("SocketError", {
|
|
202
|
+
_tag: /*#__PURE__*/ tag("SocketError"),
|
|
203
|
+
reason: SocketErrorReason
|
|
204
|
+
})) {
|
|
205
|
+
constructor(props) {
|
|
206
|
+
if ("cause" in props.reason) super({
|
|
207
|
+
...props,
|
|
208
|
+
cause: props.reason.cause
|
|
209
|
+
});
|
|
210
|
+
else super(props);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Marks this value as a socket error wrapper for runtime guards.
|
|
214
|
+
*
|
|
215
|
+
* @stability unstable
|
|
216
|
+
* @since 4.0.0
|
|
217
|
+
*/
|
|
218
|
+
[SocketErrorTypeId] = SocketErrorTypeId;
|
|
219
|
+
/**
|
|
220
|
+
* Returns `true` when the value is a `SocketError`.
|
|
221
|
+
*
|
|
222
|
+
* @stability unstable
|
|
223
|
+
* @since 4.0.0
|
|
224
|
+
*/
|
|
225
|
+
static is(u) {
|
|
226
|
+
return isSocketError(u);
|
|
227
|
+
}
|
|
228
|
+
message = this.reason.message;
|
|
229
|
+
};
|
|
230
|
+
// ../../node_modules/.pnpm/@effect+platform-node-shared@4.1.2_effect@4.1.2/node_modules/@effect/platform-node-shared/dist/NodeSocket.js
|
|
231
|
+
/**
|
|
232
|
+
* Node socket adapters for Effect sockets.
|
|
233
|
+
*
|
|
234
|
+
* This module opens `node:net` or `node:tls` connections, or wraps existing
|
|
235
|
+
* Node `Duplex` streams, and presents them as `Socket.Socket` values, socket
|
|
236
|
+
* channels, or layers. It also exposes the `NetSocket` service tag for the
|
|
237
|
+
* underlying Node socket.
|
|
238
|
+
*
|
|
239
|
+
* @stability unstable
|
|
240
|
+
* @since 4.0.0
|
|
241
|
+
*/
|
|
242
|
+
const isDeno = "Deno" in globalThis;
|
|
243
|
+
const readAvailable = (conn, chunkSize) => {
|
|
244
|
+
const first = conn.read();
|
|
245
|
+
if (first === null) return void 0;
|
|
246
|
+
const out = [first];
|
|
247
|
+
let chunk;
|
|
248
|
+
while (out.length < chunkSize && (chunk = conn.read()) !== null) out.push(chunk);
|
|
249
|
+
return out;
|
|
250
|
+
};
|
|
251
|
+
const toBuffers = (input) => map(ensure(input), (value) => Buffer$1.from(value));
|
|
252
|
+
/**
|
|
253
|
+
* Adapts a Node `Duplex` into a `Socket.Socket`.
|
|
254
|
+
*
|
|
255
|
+
* **Details**
|
|
256
|
+
*
|
|
257
|
+
* Reader acquisition opens the duplex and keeps it paused: each pull reads at
|
|
258
|
+
* most `chunkSize` chunks (default 4096) with `stream.read()`. On Node 26+ that
|
|
259
|
+
* yields each buffered chunk as a separate batch element with no copy. Earlier Node
|
|
260
|
+
* concatenates the buffer into one chunk. The stream is never resumed, so once
|
|
261
|
+
* Node's buffer reaches its `highWaterMark` the kernel receive window closes
|
|
262
|
+
* and the peer blocks: backpressure is end-to-end with no buffering above
|
|
263
|
+
* Node's own.
|
|
264
|
+
*
|
|
265
|
+
* Writes use `write()` return-value backpressure, awaiting one `drain` when
|
|
266
|
+
* the internal buffer is full. `writeAll` corks the stream around the batch.
|
|
267
|
+
* Releasing the writer scope half-closes the stream (`end()`).
|
|
268
|
+
*
|
|
269
|
+
* @stability unstable
|
|
270
|
+
* @category constructors
|
|
271
|
+
* @since 4.0.0
|
|
272
|
+
*/
|
|
273
|
+
const fromDuplex = (open, options) => withFiber((fiber) => {
|
|
274
|
+
let currentSocket;
|
|
275
|
+
const latch = makeUnsafe(false);
|
|
276
|
+
const openServices = fiber.context;
|
|
277
|
+
const isServer = options?.tlsServer === true;
|
|
278
|
+
const requestedChunkSize = options?.chunkSize ?? 4096;
|
|
279
|
+
const chunkSize = requestedChunkSize === Infinity || Number.isSafeInteger(requestedChunkSize) && requestedChunkSize > 0 ? requestedChunkSize : 4096;
|
|
280
|
+
const secureEvent = isServer ? "secure" : "secureConnect";
|
|
281
|
+
const reader = gen(function* () {
|
|
282
|
+
const scope$1 = yield* scope;
|
|
283
|
+
let conn = yield* provide(open, scope$1).pipe(options?.openTimeout !== void 0 ? timeoutOrElse({
|
|
284
|
+
duration: options.openTimeout,
|
|
285
|
+
orElse: () => fail(new SocketError({ reason: new SocketOpenError({
|
|
286
|
+
kind: "Timeout",
|
|
287
|
+
cause: /* @__PURE__ */ new Error("Connection timed out")
|
|
288
|
+
}) }))
|
|
289
|
+
}) : identity);
|
|
290
|
+
let error;
|
|
291
|
+
let waiter;
|
|
292
|
+
let pending;
|
|
293
|
+
let reading = false;
|
|
294
|
+
let closed = false;
|
|
295
|
+
let upgradeAvailable = true;
|
|
296
|
+
function drain() {
|
|
297
|
+
if (waiter === void 0 || reading) return;
|
|
298
|
+
let chunk = pending;
|
|
299
|
+
pending = void 0;
|
|
300
|
+
if (chunk === void 0 && !closed) {
|
|
301
|
+
reading = true;
|
|
302
|
+
try {
|
|
303
|
+
chunk = readAvailable(conn, chunkSize);
|
|
304
|
+
} finally {
|
|
305
|
+
reading = false;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
if (closed) chunk = void 0;
|
|
309
|
+
if (waiter === void 0) {
|
|
310
|
+
pending = chunk;
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
const result = chunk !== void 0 ? succeed(chunk) : error !== void 0 ? fail(error) : void 0;
|
|
314
|
+
if (result === void 0) return;
|
|
315
|
+
const resume = waiter;
|
|
316
|
+
waiter = void 0;
|
|
317
|
+
resume(result);
|
|
318
|
+
}
|
|
319
|
+
function end(err) {
|
|
320
|
+
error ??= err;
|
|
321
|
+
drain();
|
|
322
|
+
}
|
|
323
|
+
function close(err) {
|
|
324
|
+
error ??= err;
|
|
325
|
+
closed = true;
|
|
326
|
+
pending = void 0;
|
|
327
|
+
drain();
|
|
328
|
+
}
|
|
329
|
+
function onEnd() {
|
|
330
|
+
end(new SocketError({ reason: new SocketCloseError({ code: 1e3 }) }));
|
|
331
|
+
}
|
|
332
|
+
function onError(cause) {
|
|
333
|
+
close(new SocketError({ reason: new SocketReadError({ cause }) }));
|
|
334
|
+
}
|
|
335
|
+
function onClose(hadError) {
|
|
336
|
+
const err = new SocketError({ reason: new SocketCloseError({ code: hadError ? 1006 : 1e3 }) });
|
|
337
|
+
if (hadError) close(err);
|
|
338
|
+
else end(err);
|
|
339
|
+
}
|
|
340
|
+
function attachReadListeners(conn) {
|
|
341
|
+
conn.on("readable", drain);
|
|
342
|
+
conn.on("end", onEnd);
|
|
343
|
+
conn.on("error", onError);
|
|
344
|
+
conn.on("close", onClose);
|
|
345
|
+
}
|
|
346
|
+
function detachReadListeners(conn) {
|
|
347
|
+
conn.off("readable", drain);
|
|
348
|
+
conn.off("end", onEnd);
|
|
349
|
+
conn.off("error", onError);
|
|
350
|
+
conn.off("close", onClose);
|
|
351
|
+
}
|
|
352
|
+
if (!isDeno) conn.pause();
|
|
353
|
+
attachReadListeners(conn);
|
|
354
|
+
yield* addFinalizer(scope$1, sync(() => {
|
|
355
|
+
close(new SocketError({ reason: new SocketCloseError({ code: 1006 }) }));
|
|
356
|
+
detachReadListeners(conn);
|
|
357
|
+
latch.closeUnsafe();
|
|
358
|
+
currentSocket = void 0;
|
|
359
|
+
upgradeAvailable = false;
|
|
360
|
+
}));
|
|
361
|
+
currentSocket = conn;
|
|
362
|
+
latch.openUnsafe();
|
|
363
|
+
const pull = callback((resume) => {
|
|
364
|
+
waiter = resume;
|
|
365
|
+
drain();
|
|
366
|
+
if (waiter !== resume) return;
|
|
367
|
+
return sync(() => {
|
|
368
|
+
if (waiter === resume) waiter = void 0;
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
const upgrade = (upgradeOptions = {}) => suspend(() => {
|
|
372
|
+
if (!upgradeAvailable) return fail(new SocketError({ reason: new SocketUpgradeError({ cause: /* @__PURE__ */ new Error("socket is already upgraded or closed") }) }));
|
|
373
|
+
const hasKey = upgradeOptions.key !== void 0;
|
|
374
|
+
const hasCert = upgradeOptions.cert !== void 0;
|
|
375
|
+
if (isServer && (!hasKey || !hasCert) || hasKey !== hasCert) return fail(new SocketError({ reason: new SocketUpgradeError({ cause: /* @__PURE__ */ new Error(isServer ? "server TLS upgrade requires both key and cert" : "TLS upgrade credentials must include both key and cert") }) }));
|
|
376
|
+
return callback((resume) => {
|
|
377
|
+
const raw = conn;
|
|
378
|
+
detachReadListeners(raw);
|
|
379
|
+
let tls;
|
|
380
|
+
try {
|
|
381
|
+
const tlsOptions = {
|
|
382
|
+
secureContext: Tls.createSecureContext({
|
|
383
|
+
key: upgradeOptions.key === void 0 ? void 0 : map(ensure(upgradeOptions.key), (value$1) => Buffer$1.from(value(value$1))),
|
|
384
|
+
cert: upgradeOptions.cert === void 0 ? void 0 : toBuffers(upgradeOptions.cert),
|
|
385
|
+
ca: upgradeOptions.ca === void 0 ? void 0 : toBuffers(upgradeOptions.ca),
|
|
386
|
+
passphrase: upgradeOptions.passphrase === void 0 ? void 0 : value(upgradeOptions.passphrase)
|
|
387
|
+
}),
|
|
388
|
+
ALPNProtocols: upgradeOptions.alpnProtocols === void 0 ? void 0 : [...upgradeOptions.alpnProtocols],
|
|
389
|
+
requestCert: upgradeOptions.requestCert,
|
|
390
|
+
rejectUnauthorized: upgradeOptions.rejectUnauthorized
|
|
391
|
+
};
|
|
392
|
+
tls = isServer ? new Tls.TLSSocket(raw, {
|
|
393
|
+
...tlsOptions,
|
|
394
|
+
isServer: true
|
|
395
|
+
}) : Tls.connect({
|
|
396
|
+
...tlsOptions,
|
|
397
|
+
servername: upgradeOptions.servername,
|
|
398
|
+
socket: raw
|
|
399
|
+
});
|
|
400
|
+
} catch (cause) {
|
|
401
|
+
attachReadListeners(raw);
|
|
402
|
+
resume(fail(new SocketError({ reason: new SocketUpgradeError({ cause }) })));
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
conn = tls;
|
|
406
|
+
currentSocket = tls;
|
|
407
|
+
tls.pause();
|
|
408
|
+
function cleanup() {
|
|
409
|
+
tls.off(secureEvent, succeed);
|
|
410
|
+
tls.off("error", failUpgrade);
|
|
411
|
+
tls.off("close", onUpgradeClose);
|
|
412
|
+
}
|
|
413
|
+
function succeed() {
|
|
414
|
+
cleanup();
|
|
415
|
+
upgradeAvailable = false;
|
|
416
|
+
attachReadListeners(tls);
|
|
417
|
+
resume(void_);
|
|
418
|
+
}
|
|
419
|
+
function failUpgrade(cause) {
|
|
420
|
+
cleanup();
|
|
421
|
+
const upgradeError = new SocketError({ reason: new SocketUpgradeError({ cause }) });
|
|
422
|
+
close(upgradeError);
|
|
423
|
+
resume(fail(upgradeError));
|
|
424
|
+
}
|
|
425
|
+
function onUpgradeClose() {
|
|
426
|
+
failUpgrade(/* @__PURE__ */ new Error("socket closed during TLS upgrade"));
|
|
427
|
+
}
|
|
428
|
+
tls.once(secureEvent, succeed);
|
|
429
|
+
tls.once("error", failUpgrade);
|
|
430
|
+
tls.once("close", onUpgradeClose);
|
|
431
|
+
return sync(() => {
|
|
432
|
+
cleanup();
|
|
433
|
+
close(new SocketError({ reason: new SocketCloseError({ code: 1006 }) }));
|
|
434
|
+
tls.destroy();
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
});
|
|
438
|
+
return {
|
|
439
|
+
pull,
|
|
440
|
+
upgrade
|
|
441
|
+
};
|
|
442
|
+
}).pipe(updateContext((input) => merge(openServices, input)));
|
|
443
|
+
const awaitDrain = (conn) => callback((resume) => {
|
|
444
|
+
function cleanup() {
|
|
445
|
+
conn.off("drain", onDrain);
|
|
446
|
+
conn.off("error", onError);
|
|
447
|
+
conn.off("close", onClose);
|
|
448
|
+
}
|
|
449
|
+
function onDrain() {
|
|
450
|
+
cleanup();
|
|
451
|
+
resume(void_);
|
|
452
|
+
}
|
|
453
|
+
function onError(cause) {
|
|
454
|
+
cleanup();
|
|
455
|
+
resume(fail(new SocketError({ reason: new SocketWriteError({ cause }) })));
|
|
456
|
+
}
|
|
457
|
+
function onClose() {
|
|
458
|
+
cleanup();
|
|
459
|
+
resume(fail(new SocketError({ reason: new SocketWriteError({ cause: /* @__PURE__ */ new Error("socket closed") }) })));
|
|
460
|
+
}
|
|
461
|
+
conn.on("drain", onDrain);
|
|
462
|
+
conn.on("error", onError);
|
|
463
|
+
conn.on("close", onClose);
|
|
464
|
+
return sync(cleanup);
|
|
465
|
+
});
|
|
466
|
+
const write = (chunk) => suspend(() => {
|
|
467
|
+
const conn = currentSocket;
|
|
468
|
+
if (conn === void 0) return latch.whenOpen(write(chunk));
|
|
469
|
+
if (isCloseEvent(chunk)) {
|
|
470
|
+
conn.destroy(chunk.code > 1e3 ? /* @__PURE__ */ new Error(`closed with code ${chunk.code}`) : void 0);
|
|
471
|
+
return void_;
|
|
472
|
+
}
|
|
473
|
+
try {
|
|
474
|
+
return conn.write(chunk) ? void_ : awaitDrain(conn);
|
|
475
|
+
} catch (cause) {
|
|
476
|
+
return fail(new SocketError({ reason: new SocketWriteError({ cause }) }));
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
const writeAll = (chunks) => suspend(() => {
|
|
480
|
+
const conn = currentSocket;
|
|
481
|
+
if (conn === void 0) return latch.whenOpen(writeAll(chunks));
|
|
482
|
+
let needsDrain = false;
|
|
483
|
+
try {
|
|
484
|
+
if (chunks.length === 1) needsDrain = !conn.write(chunks[0]);
|
|
485
|
+
else {
|
|
486
|
+
conn.cork();
|
|
487
|
+
try {
|
|
488
|
+
for (let i = 0; i < chunks.length; i++) needsDrain = !conn.write(chunks[i]) || needsDrain;
|
|
489
|
+
} finally {
|
|
490
|
+
conn.uncork();
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
} catch (cause) {
|
|
494
|
+
return fail(new SocketError({ reason: new SocketWriteError({ cause }) }));
|
|
495
|
+
}
|
|
496
|
+
return needsDrain ? awaitDrain(conn) : void_;
|
|
497
|
+
});
|
|
498
|
+
const writer = acquireRelease(succeed({
|
|
499
|
+
write,
|
|
500
|
+
writeAll
|
|
501
|
+
}), () => sync(() => {
|
|
502
|
+
if (!currentSocket || currentSocket.writableEnded) return;
|
|
503
|
+
currentSocket.end();
|
|
504
|
+
}));
|
|
505
|
+
return succeed(make({
|
|
506
|
+
reader,
|
|
507
|
+
writer
|
|
508
|
+
}));
|
|
509
|
+
});
|
|
510
|
+
// ../../node_modules/.pnpm/@effect+platform-node@4.1.2_effect@4.1.2_redis@6.3.1/node_modules/@effect/platform-node/dist/internal/upgrade.js
|
|
511
|
+
/**
|
|
512
|
+
* Wraps an upgraded connection. Acquiring the reader runs `open`; releasing
|
|
513
|
+
* its scope closes the connection.
|
|
514
|
+
*
|
|
515
|
+
* No `data` listener is attached before acquisition, so early bytes stay buffered.
|
|
516
|
+
*
|
|
517
|
+
* @internal
|
|
518
|
+
*/
|
|
519
|
+
const toSocket = (conn, open = void_) => fromDuplex(acquireRelease(suspend(() => conn.destroyed ? fail(openError("The upgraded connection closed before it was read")) : as(open, conn)), (conn) => sync(() => {
|
|
520
|
+
if (conn.destroyed) return;
|
|
521
|
+
if ("destroySoon" in conn) conn.destroySoon();
|
|
522
|
+
else conn.destroy();
|
|
523
|
+
})));
|
|
524
|
+
const openError = (cause) => new SocketError({ reason: new SocketOpenError({
|
|
525
|
+
kind: "Unknown",
|
|
526
|
+
cause: typeof cause === "string" ? new Error(cause) : cause
|
|
527
|
+
}) });
|
|
528
|
+
/**
|
|
529
|
+
* Node 25 and older stop parsing at the head of an upgrade request, leaving
|
|
530
|
+
* the body in `head` and on the connection. Reads a `Content-Length` body
|
|
531
|
+
* from them on demand and returns the bytes after it.
|
|
532
|
+
*
|
|
533
|
+
* @internal
|
|
534
|
+
*/
|
|
535
|
+
const frameBody = (conn, head, length) => {
|
|
536
|
+
if (head.length >= length) return {
|
|
537
|
+
body: Readable.from(length === 0 ? [] : [head.subarray(0, length)], { objectMode: false }),
|
|
538
|
+
rest: head.subarray(length)
|
|
539
|
+
};
|
|
540
|
+
let remaining = length - head.length;
|
|
541
|
+
let reading = false;
|
|
542
|
+
const stop = () => {
|
|
543
|
+
conn.off("readable", onReadable);
|
|
544
|
+
conn.off("end", onEnd);
|
|
545
|
+
};
|
|
546
|
+
const onReadable = () => {
|
|
547
|
+
while (remaining > 0) {
|
|
548
|
+
let chunk = conn.read();
|
|
549
|
+
if (chunk === null) return;
|
|
550
|
+
if (chunk.length > remaining) {
|
|
551
|
+
conn.unshift(chunk.subarray(remaining));
|
|
552
|
+
chunk = chunk.subarray(0, remaining);
|
|
553
|
+
}
|
|
554
|
+
remaining -= chunk.length;
|
|
555
|
+
if (!body.push(chunk) && remaining > 0) return;
|
|
556
|
+
}
|
|
557
|
+
stop();
|
|
558
|
+
body.push(null);
|
|
559
|
+
};
|
|
560
|
+
const onEnd = () => {
|
|
561
|
+
stop();
|
|
562
|
+
body.destroy(/* @__PURE__ */ new Error("The connection closed before the request body ended"));
|
|
563
|
+
};
|
|
564
|
+
const body = new Readable({
|
|
565
|
+
read() {
|
|
566
|
+
if (reading) return onReadable();
|
|
567
|
+
reading = true;
|
|
568
|
+
if (head.length > 0) this.push(head);
|
|
569
|
+
if (conn.readableEnded) return onEnd();
|
|
570
|
+
conn.on("readable", onReadable);
|
|
571
|
+
conn.on("end", onEnd);
|
|
572
|
+
},
|
|
573
|
+
destroy(error, callback) {
|
|
574
|
+
stop();
|
|
575
|
+
callback(error);
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
body.on("error", () => {});
|
|
579
|
+
return {
|
|
580
|
+
body,
|
|
581
|
+
rest: Buffer.alloc(0)
|
|
582
|
+
};
|
|
583
|
+
};
|
|
584
|
+
/**
|
|
585
|
+
* Waits for the request body to end before the `101` is written, discarding
|
|
586
|
+
* any of it the handler did not read, up to `maxBytes`.
|
|
587
|
+
*
|
|
588
|
+
* @internal
|
|
589
|
+
*/
|
|
590
|
+
const drainBody = (body, maxBytes) => callback((resume) => {
|
|
591
|
+
if (body.readableEnded) return resume(void_);
|
|
592
|
+
let bytes = 0;
|
|
593
|
+
const cleanup = finished(body, {
|
|
594
|
+
readable: true,
|
|
595
|
+
writable: false
|
|
596
|
+
}, (error) => {
|
|
597
|
+
done();
|
|
598
|
+
resume(error ? fail(openError(error)) : void_);
|
|
599
|
+
});
|
|
600
|
+
function onData(chunk) {
|
|
601
|
+
bytes += chunk.length;
|
|
602
|
+
if (maxBytes !== void 0 && bytes > maxBytes) {
|
|
603
|
+
done();
|
|
604
|
+
resume(fail(openError("The request body exceeds the maximum body size")));
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
function done() {
|
|
608
|
+
body.off("data", onData);
|
|
609
|
+
cleanup();
|
|
610
|
+
}
|
|
611
|
+
body.on("data", onData);
|
|
612
|
+
body.resume();
|
|
613
|
+
return sync(done);
|
|
614
|
+
});
|
|
615
|
+
export { drainBody, frameBody, toSocket };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deslop/coding-standards",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1258",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/MP281X/deslop.git",
|
|
@@ -28,14 +28,13 @@
|
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
+
"@effect/platform-node": "latest",
|
|
31
32
|
"@shadcn/lint": "latest",
|
|
32
33
|
"@typeonce/oxlint-plugin-effect-machine": "latest",
|
|
33
34
|
"effect": "latest",
|
|
35
|
+
"oxc-parser": "latest",
|
|
34
36
|
"oxlint-plugin-react-doctor": "latest"
|
|
35
37
|
},
|
|
36
|
-
"devDependencies": {
|
|
37
|
-
"@effect/platform-node": "latest"
|
|
38
|
-
},
|
|
39
38
|
"peerDependencies": {
|
|
40
39
|
"@effect/tsgo": ">=0.67",
|
|
41
40
|
"vite-plus": "^1.3"
|