2g 0.3.0 → 0.3.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 +7 -0
- package/dist/2g.d.ts +9 -1
- package/dist/2g.js +119 -107
- package/dist/2g.js.map +1 -1
- package/dist/2g.mjs +151 -141
- package/dist/2g.mjs.map +1 -1
- package/package.json +1 -1
package/dist/2g.mjs
CHANGED
|
@@ -2,19 +2,19 @@ import e from "node:path";
|
|
|
2
2
|
|
|
3
3
|
import { performance as t } from "node:perf_hooks";
|
|
4
4
|
|
|
5
|
-
import { E as i, h as s, p as n, m as r, j as o, c, I as l, k as h, D as a, l as u, o as f, q as d, S as
|
|
5
|
+
import { E as i, h as s, p as n, m as r, j as o, c, I as l, k as h, D as a, l as u, o as f, q as d, S as g, b as p, s as m, g as y, t as w, L as k } from "./chunks/sessionSockets-chunk.mjs";
|
|
6
6
|
|
|
7
|
-
import
|
|
7
|
+
import v from "node:fs";
|
|
8
8
|
|
|
9
|
-
import
|
|
9
|
+
import S from "node:net";
|
|
10
10
|
|
|
11
11
|
import { s as b, f as L, a as _ } from "./chunks/pretty-chunk.mjs";
|
|
12
12
|
|
|
13
13
|
import { Buffer as P } from "node:buffer";
|
|
14
14
|
|
|
15
|
-
import { EventEmitter as
|
|
15
|
+
import { EventEmitter as E } from "node:events";
|
|
16
16
|
|
|
17
|
-
import { isMainThread as
|
|
17
|
+
import { isMainThread as I, threadId as $ } from "node:worker_threads";
|
|
18
18
|
|
|
19
19
|
const O = Symbol.for(`2g/state-${i}`);
|
|
20
20
|
|
|
@@ -27,19 +27,19 @@ const D = function getEventLogState() {
|
|
|
27
27
|
};
|
|
28
28
|
}();
|
|
29
29
|
|
|
30
|
-
const
|
|
30
|
+
const C = t.timeOrigin;
|
|
31
31
|
|
|
32
|
-
const
|
|
32
|
+
const x = Array.from({
|
|
33
33
|
length: 1e3
|
|
34
34
|
}, (e, t) => `.${`${t}`.padStart(3, "0")}`);
|
|
35
35
|
|
|
36
|
-
let
|
|
36
|
+
let N = -1;
|
|
37
37
|
|
|
38
|
-
let
|
|
38
|
+
let T = "";
|
|
39
39
|
|
|
40
|
-
let
|
|
40
|
+
let j;
|
|
41
41
|
|
|
42
|
-
let
|
|
42
|
+
let F = "";
|
|
43
43
|
|
|
44
44
|
function writeEvent(e, t, i, s, n, r) {
|
|
45
45
|
try {
|
|
@@ -80,21 +80,21 @@ function writeCompleteEvent(e, t, i, s, n, r, o, c) {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
function stringifyTimestamp() {
|
|
83
|
-
const e =
|
|
83
|
+
const e = C + t.now();
|
|
84
84
|
const i = Math.floor(e);
|
|
85
|
-
if (i !==
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
if (i !== N) {
|
|
86
|
+
N = i;
|
|
87
|
+
T = `${i}`;
|
|
88
88
|
}
|
|
89
|
-
return
|
|
89
|
+
return T + x[1e3 * (e - i) | 0];
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
function stringifyWorkerId(e) {
|
|
93
|
-
if (e !==
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
if (e !== j) {
|
|
94
|
+
j = e;
|
|
95
|
+
F = JSON.stringify(e);
|
|
96
96
|
}
|
|
97
|
-
return
|
|
97
|
+
return F;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
function appendPayload(e, t) {
|
|
@@ -226,7 +226,7 @@ function createDebugSink(e = process.env[o]) {
|
|
|
226
226
|
};
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
-
class LogStream extends
|
|
229
|
+
class LogStream extends E {
|
|
230
230
|
#e=-1;
|
|
231
231
|
#t=null;
|
|
232
232
|
#i=null;
|
|
@@ -241,25 +241,25 @@ class LogStream extends I {
|
|
|
241
241
|
#u="";
|
|
242
242
|
#f=0;
|
|
243
243
|
#d=[];
|
|
244
|
-
#p=0;
|
|
245
244
|
#g=0;
|
|
245
|
+
#p=0;
|
|
246
246
|
#m=0;
|
|
247
247
|
#y=!1;
|
|
248
248
|
#w=!1;
|
|
249
249
|
#k;
|
|
250
|
-
#
|
|
251
|
-
this.#
|
|
250
|
+
#v=(e, t) => {
|
|
251
|
+
this.#S(e, t);
|
|
252
252
|
};
|
|
253
253
|
#b=e => {
|
|
254
254
|
if (null != e) {
|
|
255
255
|
this.#L(e);
|
|
256
256
|
} else {
|
|
257
|
-
this.#
|
|
257
|
+
this.#S(null, P.byteLength(this.#u));
|
|
258
258
|
}
|
|
259
259
|
};
|
|
260
260
|
#_=() => {
|
|
261
261
|
this.#w = !1;
|
|
262
|
-
if (!this.#n && !this.#l && (this.#d.length - this.#
|
|
262
|
+
if (!this.#n && !this.#l && (this.#d.length - this.#g > this.#p || this.#u)) {
|
|
263
263
|
this.#P();
|
|
264
264
|
}
|
|
265
265
|
};
|
|
@@ -268,14 +268,14 @@ class LogStream extends I {
|
|
|
268
268
|
this.#s = !1 !== t.closeFd;
|
|
269
269
|
if ("number" == typeof e) {
|
|
270
270
|
try {
|
|
271
|
-
|
|
271
|
+
v.fsyncSync(e);
|
|
272
272
|
} catch {}
|
|
273
273
|
this.#e = e;
|
|
274
274
|
process.nextTick(() => this.emit("ready"));
|
|
275
275
|
} else if ("string" == typeof e) {
|
|
276
|
-
this.#
|
|
276
|
+
this.#E(e);
|
|
277
277
|
} else {
|
|
278
|
-
this
|
|
278
|
+
this.#I(e, null);
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
281
|
get file() {
|
|
@@ -309,16 +309,16 @@ class LogStream extends I {
|
|
|
309
309
|
}
|
|
310
310
|
this.#a = !0;
|
|
311
311
|
if (!this.#n) {
|
|
312
|
-
this
|
|
312
|
+
this.#$();
|
|
313
313
|
}
|
|
314
314
|
}
|
|
315
|
-
|
|
315
|
+
#$() {
|
|
316
316
|
if (null == this.#t) {
|
|
317
317
|
return;
|
|
318
318
|
}
|
|
319
319
|
this.#a = !1;
|
|
320
320
|
this.#i = this.#e;
|
|
321
|
-
this.#
|
|
321
|
+
this.#E(this.#t);
|
|
322
322
|
}
|
|
323
323
|
#O(e) {
|
|
324
324
|
if ("EAGAIN" === e.code && null != this.#k) {
|
|
@@ -332,7 +332,7 @@ class LogStream extends I {
|
|
|
332
332
|
setTimeout(() => this.#P(), this.#m);
|
|
333
333
|
}
|
|
334
334
|
}
|
|
335
|
-
#
|
|
335
|
+
#S(e, t) {
|
|
336
336
|
if (e) {
|
|
337
337
|
if ("EAGAIN" === e.code || "EBUSY" === e.code) {
|
|
338
338
|
this.#O(e);
|
|
@@ -361,11 +361,11 @@ class LogStream extends I {
|
|
|
361
361
|
} else if (this.#o && !this.#r) {
|
|
362
362
|
this.#n = !1;
|
|
363
363
|
this.#D();
|
|
364
|
-
} else if (this.#d.length - this.#
|
|
364
|
+
} else if (this.#d.length - this.#g > this.#p) {
|
|
365
365
|
this.#P();
|
|
366
366
|
} else if (this.#a) {
|
|
367
367
|
this.#n = !1;
|
|
368
|
-
this
|
|
368
|
+
this.#$();
|
|
369
369
|
} else if (this.#r) {
|
|
370
370
|
this.#n = !1;
|
|
371
371
|
this.#D();
|
|
@@ -377,24 +377,24 @@ class LogStream extends I {
|
|
|
377
377
|
}
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
|
-
#
|
|
381
|
-
this
|
|
382
|
-
|
|
380
|
+
#E(t) {
|
|
381
|
+
this.#I(i => {
|
|
382
|
+
v.mkdir(e.dirname(t), {
|
|
383
383
|
recursive: !0
|
|
384
384
|
}, () => {
|
|
385
|
-
|
|
385
|
+
v.open(t, "a", 384, (e, t) => {
|
|
386
386
|
if (e || null == t) {
|
|
387
387
|
i(e);
|
|
388
388
|
return;
|
|
389
389
|
}
|
|
390
|
-
|
|
390
|
+
v.fchmod(t, 384, () => {
|
|
391
391
|
i(null, t);
|
|
392
392
|
});
|
|
393
393
|
});
|
|
394
394
|
});
|
|
395
395
|
}, t);
|
|
396
396
|
}
|
|
397
|
-
|
|
397
|
+
#I(e, t) {
|
|
398
398
|
this.#h = !0;
|
|
399
399
|
this.#n = !0;
|
|
400
400
|
e((e, i, s) => {
|
|
@@ -411,14 +411,14 @@ class LogStream extends I {
|
|
|
411
411
|
this.#n = !1;
|
|
412
412
|
this.emit("ready");
|
|
413
413
|
if (null != n && n !== this.#e && !isStdFd(n)) {
|
|
414
|
-
fsFsync(n, () =>
|
|
414
|
+
fsFsync(n, () => v.close(n, () => {}));
|
|
415
415
|
}
|
|
416
416
|
if (this.#l) {
|
|
417
417
|
return;
|
|
418
418
|
}
|
|
419
419
|
if (this.#o) {
|
|
420
420
|
this.#D();
|
|
421
|
-
} else if (!this.#n && this.#d.length - this.#
|
|
421
|
+
} else if (!this.#n && this.#d.length - this.#g > this.#p || this.#c) {
|
|
422
422
|
this.#P();
|
|
423
423
|
}
|
|
424
424
|
}
|
|
@@ -430,9 +430,9 @@ class LogStream extends I {
|
|
|
430
430
|
return;
|
|
431
431
|
}
|
|
432
432
|
this.#l = !0;
|
|
433
|
-
this.#g = 0;
|
|
434
|
-
this.#d.length = 0;
|
|
435
433
|
this.#p = 0;
|
|
434
|
+
this.#d.length = 0;
|
|
435
|
+
this.#g = 0;
|
|
436
436
|
const onClose = e => {
|
|
437
437
|
if (e) {
|
|
438
438
|
this.emit("error", e);
|
|
@@ -450,7 +450,7 @@ class LogStream extends I {
|
|
|
450
450
|
}
|
|
451
451
|
fsFsync(this.#e, e => {
|
|
452
452
|
if (!e && this.#s && !isStdFd(this.#e)) {
|
|
453
|
-
|
|
453
|
+
v.close(this.#e, onClose);
|
|
454
454
|
} else {
|
|
455
455
|
onClose();
|
|
456
456
|
}
|
|
@@ -463,7 +463,7 @@ class LogStream extends I {
|
|
|
463
463
|
}
|
|
464
464
|
this.#D();
|
|
465
465
|
}
|
|
466
|
-
#
|
|
466
|
+
#C() {
|
|
467
467
|
if (!this.#w) {
|
|
468
468
|
this.#w = !0;
|
|
469
469
|
setImmediate(this.#_);
|
|
@@ -472,22 +472,22 @@ class LogStream extends I {
|
|
|
472
472
|
#P() {
|
|
473
473
|
this.#n = !0;
|
|
474
474
|
if (!this.#u) {
|
|
475
|
-
const e = this.#d.length - this.#
|
|
476
|
-
if (e > this.#
|
|
477
|
-
this.#u = this.#d[this.#
|
|
478
|
-
while (this.#
|
|
479
|
-
this.#u += this.#d[this.#
|
|
475
|
+
const e = this.#d.length - this.#p;
|
|
476
|
+
if (e > this.#g) {
|
|
477
|
+
this.#u = this.#d[this.#g++] || "";
|
|
478
|
+
while (this.#g < e && this.#u.length < 65536) {
|
|
479
|
+
this.#u += this.#d[this.#g++];
|
|
480
480
|
}
|
|
481
|
-
if (this.#
|
|
481
|
+
if (this.#g === this.#d.length) {
|
|
482
482
|
this.#d.length = 0;
|
|
483
|
-
this.#
|
|
483
|
+
this.#g = 0;
|
|
484
484
|
}
|
|
485
485
|
}
|
|
486
486
|
}
|
|
487
487
|
if (null != this.#k && (this.#y || this.#e < 0)) {
|
|
488
488
|
this.#k(this.#u, this.#b);
|
|
489
489
|
} else {
|
|
490
|
-
|
|
490
|
+
v.write(this.#e, this.#u, this.#v);
|
|
491
491
|
}
|
|
492
492
|
}
|
|
493
493
|
_end() {
|
|
@@ -496,7 +496,7 @@ class LogStream extends I {
|
|
|
496
496
|
if (this.#h) {
|
|
497
497
|
this.once("ready", () => this._end());
|
|
498
498
|
} else if (!this.#n && this.#e >= 0) {
|
|
499
|
-
if (this.#d.length - this.#
|
|
499
|
+
if (this.#d.length - this.#g > this.#p) {
|
|
500
500
|
this.#P();
|
|
501
501
|
} else {
|
|
502
502
|
this.#D();
|
|
@@ -525,7 +525,7 @@ class LogStream extends I {
|
|
|
525
525
|
}
|
|
526
526
|
if (this.#n || this.#h) {
|
|
527
527
|
this.#o = !0;
|
|
528
|
-
} else if (this.#d.length - this.#
|
|
528
|
+
} else if (this.#d.length - this.#g > this.#p) {
|
|
529
529
|
this.#o = !0;
|
|
530
530
|
this.#P();
|
|
531
531
|
} else {
|
|
@@ -561,7 +561,7 @@ class LogStream extends I {
|
|
|
561
561
|
this.once("drain", onDrain);
|
|
562
562
|
this.once("error", onError);
|
|
563
563
|
if (!this.#n) {
|
|
564
|
-
if (this.#d.length - this.#
|
|
564
|
+
if (this.#d.length - this.#g > this.#p || this.#u) {
|
|
565
565
|
this.#P();
|
|
566
566
|
} else {
|
|
567
567
|
process.nextTick(() => this.emit("drain"));
|
|
@@ -576,7 +576,7 @@ class LogStream extends I {
|
|
|
576
576
|
this.#f += e.length;
|
|
577
577
|
this.#d.push(e);
|
|
578
578
|
if (!this.#n) {
|
|
579
|
-
this.#
|
|
579
|
+
this.#C();
|
|
580
580
|
}
|
|
581
581
|
return this.#f < 16384;
|
|
582
582
|
}
|
|
@@ -584,7 +584,7 @@ class LogStream extends I {
|
|
|
584
584
|
if (this.#l) {
|
|
585
585
|
return !1;
|
|
586
586
|
}
|
|
587
|
-
if (0 === this.#
|
|
587
|
+
if (0 === this.#p && 10 === e.charCodeAt(e.length - 1)) {
|
|
588
588
|
return this._writeln(e);
|
|
589
589
|
}
|
|
590
590
|
this.#f += e.length;
|
|
@@ -592,25 +592,25 @@ class LogStream extends I {
|
|
|
592
592
|
let i = -1;
|
|
593
593
|
while ((i = e.indexOf("\n", t)) > -1) {
|
|
594
594
|
const s = e.slice(t, i + 1);
|
|
595
|
-
if (this.#
|
|
595
|
+
if (this.#p > 0) {
|
|
596
596
|
this.#d[this.#d.length - 1] += s;
|
|
597
597
|
} else {
|
|
598
598
|
this.#d.push(s);
|
|
599
599
|
}
|
|
600
|
-
this.#
|
|
600
|
+
this.#p = 0;
|
|
601
601
|
t = ++i;
|
|
602
602
|
}
|
|
603
603
|
if (t < e.length) {
|
|
604
604
|
const i = e.slice(t);
|
|
605
|
-
if (this.#
|
|
605
|
+
if (this.#p > 0) {
|
|
606
606
|
this.#d[this.#d.length - 1] += i;
|
|
607
607
|
} else {
|
|
608
608
|
this.#d.push(e.slice(t));
|
|
609
609
|
}
|
|
610
|
-
this.#
|
|
610
|
+
this.#p = 1;
|
|
611
611
|
}
|
|
612
|
-
if (!this.#n && this.#d.length - this.#
|
|
613
|
-
this.#
|
|
612
|
+
if (!this.#n && this.#d.length - this.#g > this.#p) {
|
|
613
|
+
this.#C();
|
|
614
614
|
}
|
|
615
615
|
return this.#f < 16384;
|
|
616
616
|
}
|
|
@@ -645,43 +645,43 @@ const isStdFd = e => {
|
|
|
645
645
|
|
|
646
646
|
const fsFsync = (e, t) => {
|
|
647
647
|
try {
|
|
648
|
-
|
|
648
|
+
v.fsync(e, t);
|
|
649
649
|
} catch (e) {
|
|
650
650
|
t(e);
|
|
651
651
|
}
|
|
652
652
|
};
|
|
653
653
|
|
|
654
654
|
class SocketSink {
|
|
655
|
-
#
|
|
655
|
+
#x;
|
|
656
656
|
constructor(e) {
|
|
657
|
-
this.#
|
|
657
|
+
this.#x = e;
|
|
658
658
|
e.on("error", () => {});
|
|
659
659
|
}
|
|
660
660
|
get writable() {
|
|
661
|
-
return this.#
|
|
661
|
+
return this.#x.writable;
|
|
662
662
|
}
|
|
663
663
|
get buffered() {
|
|
664
|
-
return this.#
|
|
664
|
+
return this.#x.writableLength;
|
|
665
665
|
}
|
|
666
666
|
_writeln(e) {
|
|
667
|
-
return this.#
|
|
667
|
+
return this.#x.write(e);
|
|
668
668
|
}
|
|
669
669
|
end(e) {
|
|
670
|
-
this.#
|
|
670
|
+
this.#x.end(e);
|
|
671
671
|
return this;
|
|
672
672
|
}
|
|
673
673
|
destroy() {
|
|
674
|
-
this.#
|
|
674
|
+
this.#x.destroy();
|
|
675
675
|
}
|
|
676
676
|
}
|
|
677
677
|
|
|
678
678
|
class BroadcastChannel {
|
|
679
|
-
#
|
|
680
|
-
#
|
|
679
|
+
#N;
|
|
680
|
+
#T=[];
|
|
681
681
|
#l=!1;
|
|
682
682
|
constructor(e) {
|
|
683
|
-
this.#
|
|
684
|
-
this.#
|
|
683
|
+
this.#N = e;
|
|
684
|
+
this.#T.push({
|
|
685
685
|
sink: e,
|
|
686
686
|
dropOnBackpressure: !1,
|
|
687
687
|
destroy: () => e.destroy()
|
|
@@ -691,8 +691,8 @@ class BroadcastChannel {
|
|
|
691
691
|
if (this.#l) {
|
|
692
692
|
return !1;
|
|
693
693
|
}
|
|
694
|
-
for (let e = 0; e < this.#
|
|
695
|
-
if (this.#
|
|
694
|
+
for (let e = 0; e < this.#T.length; e++) {
|
|
695
|
+
if (this.#T[e].sink.writable) {
|
|
696
696
|
return !0;
|
|
697
697
|
}
|
|
698
698
|
}
|
|
@@ -705,7 +705,7 @@ class BroadcastChannel {
|
|
|
705
705
|
if (this.#l) {
|
|
706
706
|
e.destroy();
|
|
707
707
|
} else {
|
|
708
|
-
this.#
|
|
708
|
+
this.#T.push({
|
|
709
709
|
sink: e,
|
|
710
710
|
dropOnBackpressure: !1,
|
|
711
711
|
destroy: () => e.destroy()
|
|
@@ -737,11 +737,11 @@ class BroadcastChannel {
|
|
|
737
737
|
e.destroy();
|
|
738
738
|
}
|
|
739
739
|
};
|
|
740
|
-
this.#
|
|
740
|
+
this.#T.push(i);
|
|
741
741
|
const detach = () => {
|
|
742
|
-
const e = this.#
|
|
742
|
+
const e = this.#T.indexOf(i);
|
|
743
743
|
if (e > -1) {
|
|
744
|
-
this.#
|
|
744
|
+
this.#T.splice(e, 1);
|
|
745
745
|
}
|
|
746
746
|
i.destroy();
|
|
747
747
|
};
|
|
@@ -768,7 +768,7 @@ class BroadcastChannel {
|
|
|
768
768
|
e.on("error", () => {});
|
|
769
769
|
}
|
|
770
770
|
_writeln(e) {
|
|
771
|
-
const t = this.#
|
|
771
|
+
const t = this.#T;
|
|
772
772
|
let i = !1;
|
|
773
773
|
for (let s = t.length - 1; s >= 0; s--) {
|
|
774
774
|
const n = t[s];
|
|
@@ -782,24 +782,24 @@ class BroadcastChannel {
|
|
|
782
782
|
return i;
|
|
783
783
|
}
|
|
784
784
|
flush(e) {
|
|
785
|
-
if (this.#
|
|
786
|
-
this.#
|
|
785
|
+
if (this.#N.flush) {
|
|
786
|
+
this.#N.flush(e);
|
|
787
787
|
} else {
|
|
788
788
|
e();
|
|
789
789
|
}
|
|
790
790
|
}
|
|
791
791
|
end(e) {
|
|
792
|
-
for (const t of this.#
|
|
793
|
-
t.sink.end(t.sink === this.#
|
|
792
|
+
for (const t of this.#T) {
|
|
793
|
+
t.sink.end(t.sink === this.#N ? e : void 0);
|
|
794
794
|
}
|
|
795
795
|
return this;
|
|
796
796
|
}
|
|
797
797
|
destroy() {
|
|
798
798
|
this.#l = !0;
|
|
799
|
-
for (const e of this.#
|
|
799
|
+
for (const e of this.#T) {
|
|
800
800
|
e.destroy();
|
|
801
801
|
}
|
|
802
|
-
this.#
|
|
802
|
+
this.#T.length = 0;
|
|
803
803
|
}
|
|
804
804
|
}
|
|
805
805
|
|
|
@@ -809,7 +809,7 @@ function openIpc(e, t = {}) {
|
|
|
809
809
|
return (t, n) => {
|
|
810
810
|
const r = Date.now();
|
|
811
811
|
const attempt = () => {
|
|
812
|
-
const o =
|
|
812
|
+
const o = S.connect(e);
|
|
813
813
|
let c = !1;
|
|
814
814
|
o.once("connect", () => {
|
|
815
815
|
const e = o._handle?.fd;
|
|
@@ -859,10 +859,10 @@ function setLocalProcessOrigin(e) {
|
|
|
859
859
|
}
|
|
860
860
|
|
|
861
861
|
function getProcessOrigin() {
|
|
862
|
-
if (
|
|
862
|
+
if (!I) {
|
|
863
863
|
return {
|
|
864
864
|
kind: "worker_thread",
|
|
865
|
-
id: String(
|
|
865
|
+
id: String($)
|
|
866
866
|
};
|
|
867
867
|
}
|
|
868
868
|
const e = globalThis[M];
|
|
@@ -906,11 +906,11 @@ function createSession(t) {
|
|
|
906
906
|
const n = `${process.pid}-${s.toString(36)}-${Math.random().toString(36).slice(2, 8).padEnd(6, "0")}`;
|
|
907
907
|
const r = e.join(i, n);
|
|
908
908
|
try {
|
|
909
|
-
|
|
909
|
+
v.mkdirSync(r, {
|
|
910
910
|
recursive: !0,
|
|
911
911
|
mode: 448
|
|
912
912
|
});
|
|
913
|
-
|
|
913
|
+
v.chmodSync(i, 448);
|
|
914
914
|
} catch {}
|
|
915
915
|
const o = t.maxSegments ?? a;
|
|
916
916
|
const c = t.maxSegmentSize ?? u;
|
|
@@ -928,24 +928,24 @@ function createSession(t) {
|
|
|
928
928
|
}
|
|
929
929
|
r = 0;
|
|
930
930
|
!function rotateSegments(t, i) {
|
|
931
|
-
|
|
931
|
+
v.rmSync(e.join(t, i - 1 + ".jsonl"), {
|
|
932
932
|
force: !0
|
|
933
933
|
});
|
|
934
934
|
for (let s = i - 1; s >= 1; s--) {
|
|
935
935
|
const i = e.join(t, s - 1 + ".jsonl");
|
|
936
936
|
const n = e.join(t, `${s}.jsonl`);
|
|
937
937
|
try {
|
|
938
|
-
|
|
938
|
+
v.renameSync(i, n);
|
|
939
939
|
} catch {}
|
|
940
940
|
}
|
|
941
941
|
}(i, s);
|
|
942
942
|
t.reopen();
|
|
943
943
|
});
|
|
944
944
|
}(L, r, o, c);
|
|
945
|
-
const P =
|
|
946
|
-
const
|
|
947
|
-
const
|
|
948
|
-
const
|
|
945
|
+
const P = S.createServer(e => _.attach(e));
|
|
946
|
+
const E = S.createServer(e => _.ingest(e));
|
|
947
|
+
const I = d(P, k.path);
|
|
948
|
+
const $ = d(E, b.path);
|
|
949
949
|
const O = function publishIpcPath(e) {
|
|
950
950
|
process.env[l] = e;
|
|
951
951
|
return () => {
|
|
@@ -965,7 +965,7 @@ function createSession(t) {
|
|
|
965
965
|
setLocalProcessOrigin(void 0);
|
|
966
966
|
};
|
|
967
967
|
}();
|
|
968
|
-
const
|
|
968
|
+
const C = {
|
|
969
969
|
pid: process.pid,
|
|
970
970
|
formatVersion: m,
|
|
971
971
|
startedAt: s,
|
|
@@ -980,21 +980,21 @@ function createSession(t) {
|
|
|
980
980
|
try {
|
|
981
981
|
!function writeJsonAtomic(e, t) {
|
|
982
982
|
const i = `${e}.${process.pid}.tmp`;
|
|
983
|
-
|
|
983
|
+
v.writeFileSync(i, JSON.stringify(t, null, 2), {
|
|
984
984
|
mode: 384
|
|
985
985
|
});
|
|
986
|
-
|
|
987
|
-
}(e.join(r,
|
|
986
|
+
v.renameSync(i, e);
|
|
987
|
+
}(e.join(r, g.meta), C);
|
|
988
988
|
} catch {}
|
|
989
|
-
let
|
|
989
|
+
let x = !1;
|
|
990
990
|
const destroy = () => {
|
|
991
|
-
if (
|
|
991
|
+
if (x) {
|
|
992
992
|
return;
|
|
993
993
|
}
|
|
994
|
-
|
|
994
|
+
x = !0;
|
|
995
995
|
_.destroy();
|
|
996
|
+
I();
|
|
996
997
|
$();
|
|
997
|
-
E();
|
|
998
998
|
O();
|
|
999
999
|
D();
|
|
1000
1000
|
w(k.path);
|
|
@@ -1020,12 +1020,12 @@ function createSession(t) {
|
|
|
1020
1020
|
}(destroy);
|
|
1021
1021
|
setImmediate(() => {
|
|
1022
1022
|
try {
|
|
1023
|
-
|
|
1023
|
+
p();
|
|
1024
1024
|
} catch {}
|
|
1025
1025
|
});
|
|
1026
1026
|
return {
|
|
1027
1027
|
sessionDir: r,
|
|
1028
|
-
meta:
|
|
1028
|
+
meta: C,
|
|
1029
1029
|
sink: _,
|
|
1030
1030
|
destroy
|
|
1031
1031
|
};
|
|
@@ -1048,11 +1048,45 @@ function createSessionOrigin() {
|
|
|
1048
1048
|
|
|
1049
1049
|
const U = events("root");
|
|
1050
1050
|
|
|
1051
|
-
function
|
|
1051
|
+
function installChildEventLogger(e) {
|
|
1052
1052
|
if (D.primarySink) {
|
|
1053
|
-
return;
|
|
1053
|
+
return !0;
|
|
1054
1054
|
}
|
|
1055
|
+
const t = function getProcessWorkerId() {
|
|
1056
|
+
const e = getProcessOrigin();
|
|
1057
|
+
return e ? `${e.kind}:${e.id}` : void 0;
|
|
1058
|
+
}();
|
|
1059
|
+
if (t) {
|
|
1060
|
+
D.eventMeta = {
|
|
1061
|
+
_w: t
|
|
1062
|
+
};
|
|
1063
|
+
}
|
|
1064
|
+
const i = function getParentIpcPath() {
|
|
1065
|
+
return process.env[l];
|
|
1066
|
+
}();
|
|
1067
|
+
if (i) {
|
|
1068
|
+
D.debug = e?.debug ?? !!process.env[o];
|
|
1069
|
+
!function connectToParent(e) {
|
|
1070
|
+
D.primarySink = createPrimarySink(openIpc(e), {
|
|
1071
|
+
closeFd: !1
|
|
1072
|
+
});
|
|
1073
|
+
D.eventLoggerInfo = {
|
|
1074
|
+
destination: "ipc",
|
|
1075
|
+
isUserVisibleOutput: !1
|
|
1076
|
+
};
|
|
1077
|
+
U("init", getInitMetadata());
|
|
1078
|
+
}(i);
|
|
1079
|
+
return !0;
|
|
1080
|
+
} else {
|
|
1081
|
+
return !1;
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
function installEventLogger(e) {
|
|
1055
1086
|
const t = e && "object" == typeof e ? e : void 0;
|
|
1087
|
+
if (installChildEventLogger(t)) {
|
|
1088
|
+
return;
|
|
1089
|
+
}
|
|
1056
1090
|
const i = parseLogTarget(process.env[k]) ?? parseLogTarget("string" == typeof e || "number" == typeof e ? e : void 0);
|
|
1057
1091
|
if (null != i) {
|
|
1058
1092
|
if ("number" == typeof i) {
|
|
@@ -1076,32 +1110,6 @@ function installEventLogger(e) {
|
|
|
1076
1110
|
activateSink(createPrimarySink(i));
|
|
1077
1111
|
return;
|
|
1078
1112
|
}
|
|
1079
|
-
const s = function getParentIpcPath() {
|
|
1080
|
-
return process.env[l];
|
|
1081
|
-
}();
|
|
1082
|
-
if (s) {
|
|
1083
|
-
D.debug = t?.debug ?? !!process.env[o];
|
|
1084
|
-
!function connectToParent(e) {
|
|
1085
|
-
const t = function getProcessWorkerId() {
|
|
1086
|
-
const e = getProcessOrigin();
|
|
1087
|
-
return e ? `${e.kind}:${e.id}` : void 0;
|
|
1088
|
-
}();
|
|
1089
|
-
if (t) {
|
|
1090
|
-
D.eventMeta = {
|
|
1091
|
-
_w: t
|
|
1092
|
-
};
|
|
1093
|
-
}
|
|
1094
|
-
D.primarySink = createPrimarySink(openIpc(e), {
|
|
1095
|
-
closeFd: !1
|
|
1096
|
-
});
|
|
1097
|
-
D.eventLoggerInfo = {
|
|
1098
|
-
destination: "ipc",
|
|
1099
|
-
isUserVisibleOutput: !1
|
|
1100
|
-
};
|
|
1101
|
-
U("init", getInitMetadata());
|
|
1102
|
-
}(s);
|
|
1103
|
-
return;
|
|
1104
|
-
}
|
|
1105
1113
|
if (t && !1 !== t.session) {
|
|
1106
1114
|
D.debug = t.debug ?? !!process.env[o];
|
|
1107
1115
|
const e = createSession(t);
|
|
@@ -1173,5 +1181,7 @@ function activateSink(e, t) {
|
|
|
1173
1181
|
U("init", getInitMetadata(t));
|
|
1174
1182
|
}
|
|
1175
1183
|
|
|
1176
|
-
|
|
1184
|
+
installChildEventLogger();
|
|
1185
|
+
|
|
1186
|
+
export { events, flushEventLogger, getEventLoggerInfo, installChildEventLogger, installEventLogger };
|
|
1177
1187
|
//# sourceMappingURL=2g.mjs.map
|