2g 0.2.0 → 0.3.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/2g.mjs CHANGED
@@ -2,7 +2,7 @@ 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 p, b as g, s as y, g as m, t as w, L as k } from "./chunks/sessionSockets-chunk.mjs";
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 p, b as g, s as m, g as y, t as w, L as k } from "./chunks/sessionSockets-chunk.mjs";
6
6
 
7
7
  import S from "node:fs";
8
8
 
@@ -27,15 +27,15 @@ const D = function getEventLogState() {
27
27
  };
28
28
  }();
29
29
 
30
- const j = t.timeOrigin;
30
+ const x = t.timeOrigin;
31
31
 
32
- const x = Array.from({
32
+ const N = Array.from({
33
33
  length: 1e3
34
34
  }, (e, t) => `.${`${t}`.padStart(3, "0")}`);
35
35
 
36
- let N = -1;
36
+ let T = -1;
37
37
 
38
- let T = "";
38
+ let j = "";
39
39
 
40
40
  let F;
41
41
 
@@ -74,22 +74,19 @@ function writeCompleteEvent(e, t, i, s, n, r, o, c) {
74
74
  if (!t) {
75
75
  return appendPayload(e, i);
76
76
  }
77
- if (!i) {
78
- return appendPayload(e, t);
79
- }
80
- return appendPayload(e, Object.assign(t, i));
77
+ return appendPayload(e, t);
81
78
  }(l, s, n)}}\n`);
82
79
  } catch {}
83
80
  }
84
81
 
85
82
  function stringifyTimestamp() {
86
- const e = j + t.now();
83
+ const e = x + t.now();
87
84
  const i = Math.floor(e);
88
- if (i !== N) {
89
- N = i;
90
- T = `${i}`;
85
+ if (i !== T) {
86
+ T = i;
87
+ j = `${i}`;
91
88
  }
92
- return T + x[1e3 * (e - i) | 0];
89
+ return j + N[1e3 * (e - i) | 0];
93
90
  }
94
91
 
95
92
  function stringifyWorkerId(e) {
@@ -141,16 +138,16 @@ function createEventLogger(i, s) {
141
138
  writeEvent(D.primarySink, i, e, t, D.eventMeta, s);
142
139
  }
143
140
  }
144
- log.span = function span(e, n) {
141
+ log.span = function span() {
145
142
  if (!D.primarySink || s && !D.debug) {
146
143
  return NOOP_DONE;
147
144
  }
148
- const r = t.now();
149
- return function done(e, o) {
145
+ const e = t.now();
146
+ return function done(n, r) {
150
147
  if (!D.primarySink) {
151
148
  return;
152
149
  }
153
- writeCompleteEvent(D.primarySink, i, e, n, o, t.now() - r, D.eventMeta, s);
150
+ writeCompleteEvent(D.primarySink, i, n, r, void 0, t.now() - e, D.eventMeta, s);
154
151
  };
155
152
  };
156
153
  log.path = function relativePath(t) {
@@ -246,8 +243,8 @@ class LogStream extends I {
246
243
  #d=[];
247
244
  #p=0;
248
245
  #g=0;
249
- #y=0;
250
- #m=!1;
246
+ #m=0;
247
+ #y=!1;
251
248
  #w=!1;
252
249
  #k;
253
250
  #S=(e, t) => {
@@ -325,14 +322,14 @@ class LogStream extends I {
325
322
  }
326
323
  #O(e) {
327
324
  if ("EAGAIN" === e.code && null != this.#k) {
328
- this.#m = !0;
325
+ this.#y = !0;
329
326
  this.#k(this.#u, this.#b);
330
- } else if (0 === this.#y) {
331
- this.#y = 1;
327
+ } else if (0 === this.#m) {
328
+ this.#m = 1;
332
329
  setImmediate(() => this.#P());
333
330
  } else {
334
- this.#y = Math.min(2 * this.#y, 100);
335
- setTimeout(() => this.#P(), this.#y);
331
+ this.#m = Math.min(2 * this.#m, 100);
332
+ setTimeout(() => this.#P(), this.#m);
336
333
  }
337
334
  }
338
335
  #v(e, t) {
@@ -344,7 +341,7 @@ class LogStream extends I {
344
341
  }
345
342
  return;
346
343
  }
347
- this.#y = 0;
344
+ this.#m = 0;
348
345
  this.emit("write", t);
349
346
  if (t === this.#u.length) {
350
347
  this.#f -= this.#u.length;
@@ -374,7 +371,7 @@ class LogStream extends I {
374
371
  this.#D();
375
372
  } else {
376
373
  this.#n = !1;
377
- this.#m = !1;
374
+ this.#y = !1;
378
375
  if (this.#c) {
379
376
  this.emit("drain");
380
377
  }
@@ -466,7 +463,7 @@ class LogStream extends I {
466
463
  }
467
464
  this.#D();
468
465
  }
469
- #j() {
466
+ #x() {
470
467
  if (!this.#w) {
471
468
  this.#w = !0;
472
469
  setImmediate(this.#_);
@@ -487,7 +484,7 @@ class LogStream extends I {
487
484
  }
488
485
  }
489
486
  }
490
- if (null != this.#k && (this.#m || this.#e < 0)) {
487
+ if (null != this.#k && (this.#y || this.#e < 0)) {
491
488
  this.#k(this.#u, this.#b);
492
489
  } else {
493
490
  S.write(this.#e, this.#u, this.#S);
@@ -579,7 +576,7 @@ class LogStream extends I {
579
576
  this.#f += e.length;
580
577
  this.#d.push(e);
581
578
  if (!this.#n) {
582
- this.#j();
579
+ this.#x();
583
580
  }
584
581
  return this.#f < 16384;
585
582
  }
@@ -613,7 +610,7 @@ class LogStream extends I {
613
610
  this.#g = 1;
614
611
  }
615
612
  if (!this.#n && this.#d.length - this.#p > this.#g) {
616
- this.#j();
613
+ this.#x();
617
614
  }
618
615
  return this.#f < 16384;
619
616
  }
@@ -655,36 +652,36 @@ const fsFsync = (e, t) => {
655
652
  };
656
653
 
657
654
  class SocketSink {
658
- #x;
655
+ #N;
659
656
  constructor(e) {
660
- this.#x = e;
657
+ this.#N = e;
661
658
  e.on("error", () => {});
662
659
  }
663
660
  get writable() {
664
- return this.#x.writable;
661
+ return this.#N.writable;
665
662
  }
666
663
  get buffered() {
667
- return this.#x.writableLength;
664
+ return this.#N.writableLength;
668
665
  }
669
666
  _writeln(e) {
670
- return this.#x.write(e);
667
+ return this.#N.write(e);
671
668
  }
672
669
  end(e) {
673
- this.#x.end(e);
670
+ this.#N.end(e);
674
671
  return this;
675
672
  }
676
673
  destroy() {
677
- this.#x.destroy();
674
+ this.#N.destroy();
678
675
  }
679
676
  }
680
677
 
681
678
  class BroadcastChannel {
682
- #N;
683
- #T=[];
679
+ #T;
680
+ #j=[];
684
681
  #l=!1;
685
682
  constructor(e) {
686
- this.#N = e;
687
- this.#T.push({
683
+ this.#T = e;
684
+ this.#j.push({
688
685
  sink: e,
689
686
  dropOnBackpressure: !1,
690
687
  destroy: () => e.destroy()
@@ -694,8 +691,8 @@ class BroadcastChannel {
694
691
  if (this.#l) {
695
692
  return !1;
696
693
  }
697
- for (let e = 0; e < this.#T.length; e++) {
698
- if (this.#T[e].sink.writable) {
694
+ for (let e = 0; e < this.#j.length; e++) {
695
+ if (this.#j[e].sink.writable) {
699
696
  return !0;
700
697
  }
701
698
  }
@@ -708,7 +705,7 @@ class BroadcastChannel {
708
705
  if (this.#l) {
709
706
  e.destroy();
710
707
  } else {
711
- this.#T.push({
708
+ this.#j.push({
712
709
  sink: e,
713
710
  dropOnBackpressure: !1,
714
711
  destroy: () => e.destroy()
@@ -740,11 +737,11 @@ class BroadcastChannel {
740
737
  e.destroy();
741
738
  }
742
739
  };
743
- this.#T.push(i);
740
+ this.#j.push(i);
744
741
  const detach = () => {
745
- const e = this.#T.indexOf(i);
742
+ const e = this.#j.indexOf(i);
746
743
  if (e > -1) {
747
- this.#T.splice(e, 1);
744
+ this.#j.splice(e, 1);
748
745
  }
749
746
  i.destroy();
750
747
  };
@@ -771,7 +768,7 @@ class BroadcastChannel {
771
768
  e.on("error", () => {});
772
769
  }
773
770
  _writeln(e) {
774
- const t = this.#T;
771
+ const t = this.#j;
775
772
  let i = !1;
776
773
  for (let s = t.length - 1; s >= 0; s--) {
777
774
  const n = t[s];
@@ -785,24 +782,24 @@ class BroadcastChannel {
785
782
  return i;
786
783
  }
787
784
  flush(e) {
788
- if (this.#N.flush) {
789
- this.#N.flush(e);
785
+ if (this.#T.flush) {
786
+ this.#T.flush(e);
790
787
  } else {
791
788
  e();
792
789
  }
793
790
  }
794
791
  end(e) {
795
- for (const t of this.#T) {
796
- t.sink.end(t.sink === this.#N ? e : void 0);
792
+ for (const t of this.#j) {
793
+ t.sink.end(t.sink === this.#T ? e : void 0);
797
794
  }
798
795
  return this;
799
796
  }
800
797
  destroy() {
801
798
  this.#l = !0;
802
- for (const e of this.#T) {
799
+ for (const e of this.#j) {
803
800
  e.destroy();
804
801
  }
805
- this.#T.length = 0;
802
+ this.#j.length = 0;
806
803
  }
807
804
  }
808
805
 
@@ -873,7 +870,7 @@ function getProcessOrigin() {
873
870
  if (t && t !== e) {
874
871
  return {
875
872
  kind: "event_log_child",
876
- id: t
873
+ id: String(process.pid)
877
874
  };
878
875
  }
879
876
  if (process.env.NODE_UNIQUE_ID) {
@@ -904,7 +901,7 @@ function runProcessCleanup() {
904
901
  }
905
902
 
906
903
  function createSession(t) {
907
- const i = m();
904
+ const i = y();
908
905
  const s = Date.now();
909
906
  const n = `${process.pid}-${s.toString(36)}-${Math.random().toString(36).slice(2, 8).padEnd(6, "0")}`;
910
907
  const r = e.join(i, n);
@@ -968,9 +965,9 @@ function createSession(t) {
968
965
  setLocalProcessOrigin(void 0);
969
966
  };
970
967
  }();
971
- const j = {
968
+ const x = {
972
969
  pid: process.pid,
973
- formatVersion: y,
970
+ formatVersion: m,
974
971
  startedAt: s,
975
972
  command: t.command ?? process.argv.slice(1).join(" "),
976
973
  cwd: process.cwd(),
@@ -987,14 +984,14 @@ function createSession(t) {
987
984
  mode: 384
988
985
  });
989
986
  S.renameSync(i, e);
990
- }(e.join(r, p.meta), j);
987
+ }(e.join(r, p.meta), x);
991
988
  } catch {}
992
- let x = !1;
989
+ let N = !1;
993
990
  const destroy = () => {
994
- if (x) {
991
+ if (N) {
995
992
  return;
996
993
  }
997
- x = !0;
994
+ N = !0;
998
995
  _.destroy();
999
996
  $();
1000
997
  E();
@@ -1028,7 +1025,7 @@ function createSession(t) {
1028
1025
  });
1029
1026
  return {
1030
1027
  sessionDir: r,
1031
- meta: j,
1028
+ meta: x,
1032
1029
  sink: _,
1033
1030
  destroy
1034
1031
  };
@@ -1165,7 +1162,7 @@ function createPrimarySink(e, t) {
1165
1162
  function getInitMetadata(e) {
1166
1163
  return {
1167
1164
  format: "v0-jsonl",
1168
- formatVersion: y,
1165
+ formatVersion: m,
1169
1166
  version: e ?? "UNVERSIONED",
1170
1167
  processOrigin: getProcessOrigin() ?? void 0
1171
1168
  };