@adviser/cement 0.2.17 → 0.2.19

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.
Files changed (39) hide show
  1. package/{sys_abstraction-CmSCeK7b.d.cts → base-sys-abstraction-C9WW3w57.d.cts} +79 -2
  2. package/{sys_abstraction-CmSCeK7b.d.ts → base-sys-abstraction-C9WW3w57.d.ts} +79 -2
  3. package/{chunk-XJF7FQUN.js → chunk-2L33RPFJ.js} +3 -3
  4. package/{chunk-XJF7FQUN.js.map → chunk-2L33RPFJ.js.map} +1 -1
  5. package/chunk-AO7BGISE.js +353 -0
  6. package/chunk-AO7BGISE.js.map +1 -0
  7. package/{chunk-J2IM7FHM.js → chunk-I4NUGWZ6.js} +6 -1
  8. package/{chunk-O4F5AURC.js → chunk-JYUQZNDZ.js} +187 -179
  9. package/chunk-JYUQZNDZ.js.map +1 -0
  10. package/index-_GuS2IT4.d.cts +93 -0
  11. package/index-_GuS2IT4.d.ts +93 -0
  12. package/index.cjs +515 -183
  13. package/index.cjs.map +1 -1
  14. package/index.d.cts +32 -33
  15. package/index.d.ts +32 -33
  16. package/index.js +178 -174
  17. package/index.js.map +1 -1
  18. package/node/index.cjs +12 -10
  19. package/node/index.cjs.map +1 -1
  20. package/node/index.d.cts +1 -2
  21. package/node/index.d.ts +1 -2
  22. package/node/index.js +5 -5
  23. package/node/index.js.map +1 -1
  24. package/package.json +7 -3
  25. package/utils/index.cjs +98 -2
  26. package/utils/index.cjs.map +1 -1
  27. package/utils/index.d.cts +2 -36
  28. package/utils/index.d.ts +2 -36
  29. package/utils/index.js +21 -221
  30. package/utils/index.js.map +1 -1
  31. package/web/index.cjs +10 -8
  32. package/web/index.cjs.map +1 -1
  33. package/web/index.d.cts +1 -2
  34. package/web/index.d.ts +1 -2
  35. package/web/index.js +3 -3
  36. package/base_sys_abstraction-CJqRmTui.d.ts +0 -21
  37. package/base_sys_abstraction-nsNTl07w.d.cts +0 -21
  38. package/chunk-O4F5AURC.js.map +0 -1
  39. /package/{chunk-J2IM7FHM.js.map → chunk-I4NUGWZ6.js.map} +0 -0
package/index.cjs CHANGED
@@ -74,12 +74,14 @@ var __yieldStar = (value) => {
74
74
  // src/index.ts
75
75
  var src_exports = {};
76
76
  __export(src_exports, {
77
+ BaseSysAbstraction: () => BaseSysAbstraction,
77
78
  BrowserEnvActions: () => BrowserEnvActions,
78
79
  BuildURI: () => BuildURI,
80
+ ConstTime: () => ConstTime,
79
81
  EnvImpl: () => EnvImpl,
80
- FanoutWriter: () => FanoutWriter,
81
82
  Future: () => Future,
82
83
  IDMode: () => IDMode,
84
+ IdService: () => IdService,
83
85
  IsLogger: () => IsLogger,
84
86
  Keyed: () => Keyed,
85
87
  KeyedResolvOnce: () => KeyedResolvOnce,
@@ -88,31 +90,38 @@ __export(src_exports, {
88
90
  LevelHandlerImpl: () => LevelHandlerImpl,
89
91
  LogCollector: () => LogCollector,
90
92
  LogValue: () => LogValue,
91
- LogWriterCollector: () => LogWriterCollector,
93
+ LogWriteStream: () => LogWriteStream,
92
94
  LogWriterStream: () => LogWriterStream,
93
95
  LoggerImpl: () => LoggerImpl,
94
96
  MockLogger: () => MockLogger,
97
+ MutableURL: () => MutableURL,
95
98
  None: () => None,
96
99
  Option: () => Option,
97
100
  RandomMode: () => RandomMode,
101
+ RandomService: () => RandomService,
98
102
  ResolveOnce: () => ResolveOnce,
99
103
  ResolveSeq: () => ResolveSeq,
100
104
  Result: () => Result,
101
105
  ResultError: () => ResultError,
102
106
  ResultOK: () => ResultOK,
103
107
  Some: () => Some,
108
+ StepTime: () => StepTime,
104
109
  String2TimeMode: () => String2TimeMode,
110
+ SysTime: () => SysTime,
105
111
  Time: () => Time,
112
+ TimeFactory: () => TimeFactory,
106
113
  TimeMode: () => TimeMode,
107
114
  TimeUnits: () => TimeUnits,
108
115
  URI: () => URI,
116
+ WrapperSysAbstraction: () => WrapperSysAbstraction,
109
117
  asyncLogValue: () => asyncLogValue,
110
118
  envFactory: () => envFactory,
111
119
  isURL: () => isURL,
112
120
  logValue: () => logValue,
113
121
  removeSelfRef: () => removeSelfRef,
114
122
  runtimeFn: () => runtimeFn,
115
- toCryptoRuntime: () => toCryptoRuntime
123
+ toCryptoRuntime: () => toCryptoRuntime,
124
+ utils: () => utils_exports
116
125
  });
117
126
  module.exports = __toCommonJS(src_exports);
118
127
 
@@ -197,7 +206,7 @@ function IsLogger(obj) {
197
206
  ].map((fn) => typeof obj[fn] === "function").reduce((a, b) => a && b, true);
198
207
  }
199
208
 
200
- // src/sys_abstraction.ts
209
+ // src/sys-abstraction.ts
201
210
  var TimeMode = /* @__PURE__ */ ((TimeMode2) => {
202
211
  TimeMode2["REAL"] = "real";
203
212
  TimeMode2["CONST"] = "const";
@@ -244,7 +253,7 @@ var TimeUnits = /* @__PURE__ */ ((TimeUnits2) => {
244
253
  return TimeUnits2;
245
254
  })(TimeUnits || {});
246
255
 
247
- // src/base_sys_abstraction.ts
256
+ // src/base-sys-abstraction.ts
248
257
  var SysTime = class extends Time {
249
258
  Now() {
250
259
  return /* @__PURE__ */ new Date();
@@ -270,13 +279,15 @@ var StepTime = class extends Time {
270
279
  constructor() {
271
280
  super();
272
281
  this._step = new ConstTime().Now();
282
+ this._start = this._step;
273
283
  }
274
- Now() {
275
- if (this._step.getTime() === 0) {
276
- this._step = new ConstTime().Now();
277
- return this._step;
284
+ Now(steps = 1) {
285
+ for (let i = 0; steps > 0 && i < steps; i++) {
286
+ this._step = new Date(this._step.getTime() + 1e3);
287
+ }
288
+ if (steps < 1) {
289
+ this._step = new Date(this._start.getTime() + steps * -1e3);
278
290
  }
279
- this._step = new Date(this._step.getTime() + 1e3);
280
291
  return this._step;
281
292
  }
282
293
  Sleep(duration) {
@@ -588,7 +599,7 @@ var KeyedResolvSeq = class extends Keyed {
588
599
  }
589
600
  };
590
601
 
591
- // src/sys_env.ts
602
+ // src/sys-env.ts
592
603
  var _node;
593
604
  var NodeEnvActions = class {
594
605
  // eslint-disable-next-line @typescript-eslint/no-useless-constructor, @typescript-eslint/no-unused-vars
@@ -758,7 +769,7 @@ var EnvImpl = class {
758
769
  }
759
770
  };
760
771
 
761
- // src/web/web_sys_abstraction.ts
772
+ // src/web/web-sys-abstraction.ts
762
773
  var WebFileService = class {
763
774
  get baseDir() {
764
775
  throw new Error("basedir-Method not implemented.");
@@ -837,34 +848,100 @@ function falsy2undef(value) {
837
848
  }
838
849
  function ensureURLWithDefaultProto(url, defaultProtocol) {
839
850
  if (!url) {
840
- return new URL(`${defaultProtocol}//`);
851
+ return new MutableURL(`${defaultProtocol}//`);
841
852
  }
842
853
  if (typeof url === "string") {
843
854
  try {
844
- return new URL(url);
855
+ return new MutableURL(url);
845
856
  } catch (e) {
846
- return new URL(`${defaultProtocol}//${url}`);
857
+ return new MutableURL(`${defaultProtocol}//${url}`);
847
858
  }
848
859
  } else {
849
- return url;
860
+ return new MutableURL(url.toString());
850
861
  }
851
862
  }
852
863
  function isURL(value) {
853
864
  return value instanceof URL || !!value && typeof value.searchParams === "object" && typeof value.searchParams.sort === "function" && typeof value.hash === "string";
854
865
  }
866
+ var MutableURL = class _MutableURL extends URL {
867
+ constructor(urlStr) {
868
+ super("defect://does.not.exist");
869
+ this._sysURL = new URL(urlStr);
870
+ this._protocol = this._sysURL.protocol;
871
+ this._hasHostpart = ["http:", "https:"].includes(this._protocol);
872
+ if (this._hasHostpart) {
873
+ this._pathname = this._sysURL.pathname;
874
+ } else {
875
+ this._pathname = urlStr.replace(new RegExp(`^${this._protocol}//`), "").replace(/[#?].*$/, "");
876
+ }
877
+ this.hash = this._sysURL.hash;
878
+ }
879
+ clone() {
880
+ return new _MutableURL(this.toString());
881
+ }
882
+ get hostname() {
883
+ if (!this._hasHostpart) {
884
+ throw new Error("you can use hostname only if protocol is http or https");
885
+ }
886
+ return this._sysURL.hostname;
887
+ }
888
+ set hostname(h) {
889
+ if (!this._hasHostpart) {
890
+ throw new Error("you can use hostname only if protocol is http or https");
891
+ }
892
+ this._sysURL.hostname = h;
893
+ }
894
+ set pathname(p) {
895
+ this._pathname = p;
896
+ }
897
+ get pathname() {
898
+ return this._pathname;
899
+ }
900
+ get protocol() {
901
+ return this._protocol;
902
+ }
903
+ set protocol(p) {
904
+ if (!p.endsWith(":")) {
905
+ p = `${p}:`;
906
+ }
907
+ this._protocol = p;
908
+ }
909
+ get searchParams() {
910
+ return this._sysURL.searchParams;
911
+ }
912
+ toString() {
913
+ let search = "";
914
+ if (this._sysURL.searchParams.size) {
915
+ for (const [key, value] of Array.from(this._sysURL.searchParams.entries()).sort((a, b) => a[0].localeCompare(b[0]))) {
916
+ search += `${!search.length ? "?" : "&"}${key}=${encodeURIComponent(value)}`;
917
+ }
918
+ }
919
+ let hostpart = "";
920
+ if (this._hasHostpart) {
921
+ hostpart = this._sysURL.hostname;
922
+ if (this._sysURL.port) {
923
+ hostpart += `:${this._sysURL.port}`;
924
+ }
925
+ if (!this._pathname.startsWith("/")) {
926
+ hostpart += "/";
927
+ }
928
+ }
929
+ return `${this._protocol}//${hostpart}${this._pathname}${search}`;
930
+ }
931
+ };
855
932
  function from(fac, strURLUri, defaultProtocol) {
856
933
  switch (typeof falsy2undef(strURLUri)) {
857
934
  case "undefined":
858
- return fac(new URL(`${defaultProtocol}//`));
935
+ return fac(new MutableURL(`${defaultProtocol}///`));
859
936
  case "string":
860
937
  return fac(ensureURLWithDefaultProto(strURLUri, defaultProtocol));
861
938
  case "object":
862
939
  if (BuildURI.is(strURLUri)) {
863
- return fac(new URL(strURLUri._url.toString()));
940
+ return fac(new MutableURL(strURLUri._url.toString()));
864
941
  } else if (URI.is(strURLUri)) {
865
- return fac(new URL(strURLUri._url.toString()));
942
+ return fac(new MutableURL(strURLUri._url.toString()));
866
943
  } else if (isURL(strURLUri)) {
867
- return fac(new URL(strURLUri.toString()));
944
+ return fac(new MutableURL(strURLUri.toString()));
868
945
  }
869
946
  throw new Error(`unknown object type: ${strURLUri}`);
870
947
  default:
@@ -886,46 +963,38 @@ var BuildURI = class _BuildURI {
886
963
  this._url.hostname = h;
887
964
  return this;
888
965
  }
889
- password(p) {
890
- this._url.password = p;
891
- return this;
892
- }
893
- port(p) {
894
- this._url.port = p;
895
- return this;
896
- }
897
- username(u) {
898
- this._url.username = u;
899
- return this;
900
- }
901
- search(s) {
902
- this._url.search = s;
903
- return this;
904
- }
966
+ // password(p: string) {
967
+ // this._url.password = p;
968
+ // return this;
969
+ // }
970
+ // port(p: string) {
971
+ // this._url.port = p;
972
+ // return this;
973
+ // }
974
+ // username(u: string) {
975
+ // this._url.username = u;
976
+ // return this;
977
+ // }
978
+ // search(s: string) {
979
+ // this._url.search = s;
980
+ // return this;
981
+ // }
905
982
  protocol(p) {
906
- if (!p.endsWith(":")) {
907
- p = `${p}:`;
908
- }
909
- const mySrc = this._url.toString();
910
- const myDst = mySrc.replace(new RegExp(`^${this._url.protocol}`), `${p}`);
911
- this._url = new URL(myDst);
983
+ this._url.protocol = p;
912
984
  return this;
913
985
  }
914
986
  pathname(p) {
915
- const myp = this.URI().pathname;
916
- const mySrc = this._url.toString();
917
- const myDst = mySrc.replace(new RegExp(`^${this._url.protocol}//${myp}`), `${this._url.protocol}//${p}`);
918
- this._url = new URL(myDst);
919
- return this;
920
- }
921
- hash(h) {
922
- this._url.hash = h;
923
- return this;
924
- }
925
- host(h) {
926
- this._url.host = h;
987
+ this._url.pathname = p;
927
988
  return this;
928
989
  }
990
+ // hash(h: string) {
991
+ // this._url.hash = h;
992
+ // return this;
993
+ // }
994
+ // host(h: string) {
995
+ // this._url.host = h;
996
+ // return this;
997
+ // }
929
998
  delParam(key) {
930
999
  this._url.searchParams.delete(key);
931
1000
  return this;
@@ -944,6 +1013,9 @@ var BuildURI = class _BuildURI {
944
1013
  this._url.searchParams.sort();
945
1014
  return this._url.toString();
946
1015
  }
1016
+ toJSON() {
1017
+ return this.toString();
1018
+ }
947
1019
  URI() {
948
1020
  return URI.from(this._url);
949
1021
  }
@@ -971,38 +1043,38 @@ var URI = class _URI {
971
1043
  return from((url) => new _URI(url), strURLUri, defaultProtocol);
972
1044
  }
973
1045
  constructor(url) {
974
- this._url = url;
1046
+ this._url = url.clone();
975
1047
  }
976
1048
  build() {
977
- return BuildURI.from(this.asURL());
1049
+ return BuildURI.from(this._url);
978
1050
  }
979
1051
  get hostname() {
980
1052
  return this._url.hostname;
981
1053
  }
982
- get password() {
983
- return this._url.password;
984
- }
985
- get port() {
986
- return this._url.port;
987
- }
988
- get username() {
989
- return this._url.username;
990
- }
991
- get search() {
992
- return this._url.search;
993
- }
1054
+ // get password(): string {
1055
+ // return this._url.password;
1056
+ // }
1057
+ // get port(): string {
1058
+ // return this._url.port;
1059
+ // }
1060
+ // get username(): string {
1061
+ // return this._url.username;
1062
+ // }
1063
+ // get search(): string {
1064
+ // return this._url.search;
1065
+ // }
994
1066
  get protocol() {
995
1067
  return this._url.protocol;
996
1068
  }
997
1069
  get pathname() {
998
1070
  return this._url.toString().replace(/^.*:\/\//, "").replace(/\?.*$/, "");
999
1071
  }
1000
- get hash() {
1001
- return this._url.hash;
1002
- }
1003
- get host() {
1004
- return this._url.host;
1005
- }
1072
+ // get hash(): string {
1073
+ // return this._url.hash;
1074
+ // }
1075
+ // get host(): string {
1076
+ // return this._url.host;
1077
+ // }
1006
1078
  get getParams() {
1007
1079
  return this._url.searchParams.entries();
1008
1080
  }
@@ -1013,17 +1085,17 @@ var URI = class _URI {
1013
1085
  return falsy2undef(this._url.searchParams.get(key));
1014
1086
  }
1015
1087
  clone() {
1016
- return new _URI(this.asURL());
1088
+ return new _URI(this._url);
1017
1089
  }
1018
1090
  asURL() {
1019
- const url = new URL(this._url.toString());
1020
- url.searchParams.sort();
1021
- return url;
1091
+ return this._url.clone();
1022
1092
  }
1023
1093
  toString() {
1024
- this._url.searchParams.sort();
1025
1094
  return this._url.toString();
1026
1095
  }
1096
+ toJSON() {
1097
+ return this.toString();
1098
+ }
1027
1099
  };
1028
1100
 
1029
1101
  // src/runtime.ts
@@ -1049,7 +1121,71 @@ function runtimeFn() {
1049
1121
  };
1050
1122
  }
1051
1123
 
1052
- // src/logger_impl.ts
1124
+ // src/utils/console-write-stream.ts
1125
+ var ConsoleWriterStreamDefaultWriter = class {
1126
+ constructor(stream) {
1127
+ this.stream = stream;
1128
+ this.desiredSize = null;
1129
+ this.decoder = new TextDecoder();
1130
+ this._stream = stream;
1131
+ this.ready = Promise.resolve(void 0);
1132
+ this.closed = Promise.resolve(void 0);
1133
+ }
1134
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
1135
+ abort(reason) {
1136
+ throw new Error("Method not implemented.");
1137
+ }
1138
+ async close() {
1139
+ }
1140
+ releaseLock() {
1141
+ this._stream.locked = false;
1142
+ this.ready = Promise.resolve(void 0);
1143
+ this.closed = Promise.resolve(void 0);
1144
+ }
1145
+ async write(chunk) {
1146
+ const str = this.decoder.decode(chunk).trimEnd();
1147
+ let output = "log";
1148
+ try {
1149
+ const decode = JSON.parse(str);
1150
+ output = decode.level;
1151
+ } catch (e) {
1152
+ }
1153
+ switch (output) {
1154
+ case "error":
1155
+ console.error(str);
1156
+ break;
1157
+ case "warn":
1158
+ console.warn(str);
1159
+ break;
1160
+ default:
1161
+ console.log(str);
1162
+ }
1163
+ }
1164
+ };
1165
+ var ConsoleWriterStream = class {
1166
+ constructor() {
1167
+ this.locked = false;
1168
+ }
1169
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
1170
+ abort(reason) {
1171
+ throw new Error("Method not implemented.");
1172
+ }
1173
+ async close() {
1174
+ return;
1175
+ }
1176
+ getWriter() {
1177
+ if (this.locked) {
1178
+ throw new Error("Stream is locked");
1179
+ }
1180
+ this.locked = true;
1181
+ if (!this._writer) {
1182
+ this._writer = new ConsoleWriterStreamDefaultWriter(this);
1183
+ }
1184
+ return this._writer;
1185
+ }
1186
+ };
1187
+
1188
+ // src/logger-impl.ts
1053
1189
  var encoder = new TextEncoder();
1054
1190
  var LevelHandlerImpl = class {
1055
1191
  constructor() {
@@ -1193,68 +1329,6 @@ function toLogValue(lop) {
1193
1329
  }
1194
1330
  return lop;
1195
1331
  }
1196
- var ConsoleWriterStreamDefaultWriter = class {
1197
- constructor(stream) {
1198
- this.stream = stream;
1199
- this.desiredSize = null;
1200
- this.decoder = new TextDecoder();
1201
- this._stream = stream;
1202
- this.ready = Promise.resolve(void 0);
1203
- this.closed = Promise.resolve(void 0);
1204
- }
1205
- // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
1206
- abort(reason) {
1207
- throw new Error("Method not implemented.");
1208
- }
1209
- async close() {
1210
- }
1211
- releaseLock() {
1212
- this._stream.locked = false;
1213
- this.ready = Promise.resolve(void 0);
1214
- this.closed = Promise.resolve(void 0);
1215
- }
1216
- async write(chunk) {
1217
- const str = this.decoder.decode(chunk).trimEnd();
1218
- let output = "log";
1219
- try {
1220
- const decode = JSON.parse(str);
1221
- output = decode.level;
1222
- } catch (e) {
1223
- }
1224
- switch (output) {
1225
- case "error":
1226
- console.error(str);
1227
- break;
1228
- case "warn":
1229
- console.warn(str);
1230
- break;
1231
- default:
1232
- console.log(str);
1233
- }
1234
- }
1235
- };
1236
- var ConsoleWriterStream = class {
1237
- constructor() {
1238
- this.locked = false;
1239
- }
1240
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
1241
- abort(reason) {
1242
- throw new Error("Method not implemented.");
1243
- }
1244
- async close() {
1245
- return;
1246
- }
1247
- getWriter() {
1248
- if (this.locked) {
1249
- throw new Error("Stream is locked");
1250
- }
1251
- this.locked = true;
1252
- if (!this._writer) {
1253
- this._writer = new ConsoleWriterStreamDefaultWriter(this);
1254
- }
1255
- return this._writer;
1256
- }
1257
- };
1258
1332
  var LoggerImpl = class _LoggerImpl {
1259
1333
  // readonly _id: string = "logger-" + Math.random().toString(36)
1260
1334
  constructor(params) {
@@ -1299,6 +1373,17 @@ var LoggerImpl = class _LoggerImpl {
1299
1373
  this._levelHandler = levelSingleton;
1300
1374
  }
1301
1375
  }
1376
+ Attributes() {
1377
+ return Array.from(Object.entries(this._attributes)).reduce(
1378
+ (acc, [key, value]) => {
1379
+ if (value instanceof LogValue) {
1380
+ acc[key] = value.value();
1381
+ }
1382
+ return acc;
1383
+ },
1384
+ {}
1385
+ );
1386
+ }
1302
1387
  SetExposeStack(enable) {
1303
1388
  this._levelHandler.setExposeStack(enable);
1304
1389
  return this;
@@ -1322,7 +1407,7 @@ var LoggerImpl = class _LoggerImpl {
1322
1407
  return this;
1323
1408
  }
1324
1409
  Timestamp() {
1325
- this._attributes["ts"] = logValue(this._sys.Time().Now().toISOString());
1410
+ this._attributes["ts"] = logValue(() => this._sys.Time().Now().toISOString());
1326
1411
  return this;
1327
1412
  }
1328
1413
  Warn() {
@@ -1439,18 +1524,11 @@ var LoggerImpl = class _LoggerImpl {
1439
1524
  return ret;
1440
1525
  }
1441
1526
  _produceError(attr, ...args) {
1442
- var _a;
1443
1527
  attr["msg"] = logValue(args.join(" "));
1444
1528
  const msg = attr["msg"].value();
1445
1529
  if (typeof msg === "string" && !msg.trim().length) {
1446
1530
  delete attr["msg"];
1447
1531
  }
1448
- if (((_a = toLogValue(attr["ts"])) == null ? void 0 : _a.value()) === "ETERNITY") {
1449
- this.Timestamp.call({
1450
- _sys: this._sys,
1451
- _attributes: attr
1452
- });
1453
- }
1454
1532
  return JSON.stringify(attr, removeSelfRef());
1455
1533
  }
1456
1534
  Msg(...args) {
@@ -1482,6 +1560,9 @@ var WithLoggerBuilder = class {
1482
1560
  Object.assign(this._li._withAttributes, this._li._attributes);
1483
1561
  return this._li;
1484
1562
  }
1563
+ Attributes() {
1564
+ return __spreadValues({}, this._li._attributes);
1565
+ }
1485
1566
  SetExposeStack(enable) {
1486
1567
  this._li._levelHandler.setExposeStack(enable);
1487
1568
  return this;
@@ -1563,7 +1644,7 @@ var WithLoggerBuilder = class {
1563
1644
  return this;
1564
1645
  }
1565
1646
  Timestamp() {
1566
- this._li._attributes["ts"] = logValue("ETERNITY");
1647
+ this._li.Timestamp();
1567
1648
  return this;
1568
1649
  }
1569
1650
  Any(key, value) {
@@ -1580,8 +1661,34 @@ var WithLoggerBuilder = class {
1580
1661
  }
1581
1662
  };
1582
1663
 
1583
- // src/test/log_collector.ts
1584
- var LogWriterCollector = class {
1664
+ // src/utils/fanout-write-stream.ts
1665
+ var FanoutWriteStream = class {
1666
+ constructor(writers) {
1667
+ this.desiredSize = null;
1668
+ this._writers = writers;
1669
+ this.ready = Promise.all(this._writers.map((w) => w.ready)).then(() => void 0);
1670
+ this.closed = Promise.all(this._writers.map((w) => w.closed)).then(() => void 0);
1671
+ }
1672
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1673
+ abort(reason) {
1674
+ return Promise.all(this._writers.map((w) => w.abort(reason))).then(() => {
1675
+ });
1676
+ }
1677
+ close() {
1678
+ return Promise.all(this._writers.map((w) => w.close())).then(() => {
1679
+ });
1680
+ }
1681
+ releaseLock() {
1682
+ this._writers.map((w) => w.releaseLock());
1683
+ }
1684
+ write(chunk) {
1685
+ return Promise.all(this._writers.map((w) => w.write(chunk))).then(() => {
1686
+ });
1687
+ }
1688
+ };
1689
+
1690
+ // src/test/log-write-stream.ts
1691
+ var LogWriteStream = class {
1585
1692
  constructor(bufferArr) {
1586
1693
  this._resolveClosed = new Future();
1587
1694
  this.closed = this._resolveClosed.asPromise();
@@ -1606,30 +1713,6 @@ var LogWriterCollector = class {
1606
1713
  return Promise.resolve(void 0);
1607
1714
  }
1608
1715
  };
1609
- var FanoutWriter = class {
1610
- constructor(writers) {
1611
- this.desiredSize = null;
1612
- this._writers = writers;
1613
- this.ready = Promise.all(this._writers.map((w) => w.ready)).then(() => void 0);
1614
- this.closed = Promise.all(this._writers.map((w) => w.closed)).then(() => void 0);
1615
- }
1616
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1617
- abort(reason) {
1618
- return Promise.all(this._writers.map((w) => w.abort(reason))).then(() => {
1619
- });
1620
- }
1621
- close() {
1622
- return Promise.all(this._writers.map((w) => w.close())).then(() => {
1623
- });
1624
- }
1625
- releaseLock() {
1626
- this._writers.map((w) => w.releaseLock());
1627
- }
1628
- write(chunk) {
1629
- return Promise.all(this._writers.map((w) => w.write(chunk))).then(() => {
1630
- });
1631
- }
1632
- };
1633
1716
  var LogCollector = class {
1634
1717
  constructor(pass) {
1635
1718
  this.locked = false;
@@ -1650,11 +1733,11 @@ var LogCollector = class {
1650
1733
  }
1651
1734
  getWriter() {
1652
1735
  if (!this._writer) {
1653
- const dests = [new LogWriterCollector(this._bufferArr)];
1736
+ const dests = [new LogWriteStream(this._bufferArr)];
1654
1737
  if (this._pass) {
1655
1738
  dests.push(this._pass);
1656
1739
  }
1657
- this._writer = new FanoutWriter(dests);
1740
+ this._writer = new FanoutWriteStream(dests);
1658
1741
  }
1659
1742
  return this._writer;
1660
1743
  }
@@ -1679,7 +1762,7 @@ var LogCollector = class {
1679
1762
  }
1680
1763
  };
1681
1764
 
1682
- // src/test/mock_logger.ts
1765
+ // src/test/mock-logger.ts
1683
1766
  function MockLogger(params) {
1684
1767
  const lc = new LogCollector(params == null ? void 0 : params.pass);
1685
1768
  let modNames = ["MockLogger"];
@@ -1845,14 +1928,256 @@ function toCryptoRuntime(cryptoOpts = {}) {
1845
1928
  };
1846
1929
  return runtime;
1847
1930
  }
1931
+
1932
+ // src/utils/index.ts
1933
+ var utils_exports = {};
1934
+ __export(utils_exports, {
1935
+ ConsoleWriterStream: () => ConsoleWriterStream,
1936
+ ConsoleWriterStreamDefaultWriter: () => ConsoleWriterStreamDefaultWriter,
1937
+ FanoutWriteStream: () => FanoutWriteStream,
1938
+ array2stream: () => array2stream,
1939
+ devnull: () => devnull,
1940
+ rebuffer: () => rebuffer,
1941
+ rebufferArray: () => rebufferArray,
1942
+ receiveFromStream: () => receiveFromStream,
1943
+ sendToStream: () => sendToStream,
1944
+ stream2array: () => stream2array,
1945
+ stream2string: () => stream2string,
1946
+ stream2uint8array: () => stream2uint8array,
1947
+ streamMap: () => streamMap,
1948
+ string2stream: () => string2stream,
1949
+ uint8array2stream: () => uint8array2stream
1950
+ });
1951
+
1952
+ // src/utils/stream-map.ts
1953
+ function streamMap(s, sm) {
1954
+ const state = { reader: s.getReader(), streamMap: sm, idx: 0 };
1955
+ return new ReadableStream({
1956
+ async pull(controller) {
1957
+ const { done, value } = await state.reader.read();
1958
+ if (done) {
1959
+ if (state.streamMap.Close) {
1960
+ state.streamMap.Close();
1961
+ }
1962
+ controller.close();
1963
+ return;
1964
+ }
1965
+ const promiseOrU = state.streamMap.Map(value, state.idx++);
1966
+ let mapped;
1967
+ if (promiseOrU instanceof Promise || typeof promiseOrU.then === "function") {
1968
+ mapped = await promiseOrU;
1969
+ } else {
1970
+ mapped = promiseOrU;
1971
+ }
1972
+ controller.enqueue(mapped);
1973
+ }
1974
+ });
1975
+ }
1976
+ async function devnull(a) {
1977
+ const reader = a.getReader();
1978
+ let cnt = 0;
1979
+ while (true) {
1980
+ const { done } = await reader.read();
1981
+ if (done) {
1982
+ break;
1983
+ }
1984
+ cnt++;
1985
+ }
1986
+ return cnt;
1987
+ }
1988
+ function array2stream(a) {
1989
+ let i = 0;
1990
+ return new ReadableStream({
1991
+ pull(controller) {
1992
+ if (i >= a.length) {
1993
+ controller.close();
1994
+ return;
1995
+ }
1996
+ controller.enqueue(a[i]);
1997
+ i++;
1998
+ }
1999
+ });
2000
+ }
2001
+ async function stream2array(a) {
2002
+ const ret = [];
2003
+ const reader = a.getReader();
2004
+ while (true) {
2005
+ const { done, value } = await reader.read();
2006
+ if (done) {
2007
+ break;
2008
+ }
2009
+ ret.push(value);
2010
+ }
2011
+ return ret;
2012
+ }
2013
+
2014
+ // src/utils/rebuffer.ts
2015
+ async function rebufferArray(a, chunkSize) {
2016
+ return stream2array(rebuffer(array2stream(a), chunkSize));
2017
+ }
2018
+ function reChunk(cs, chunkSize) {
2019
+ const len = cs.reduce((acc, v) => acc + v.length, 0);
2020
+ const last = cs[cs.length - 1];
2021
+ const lastOfs = len - last.length;
2022
+ const rest = last.subarray(chunkSize - lastOfs);
2023
+ cs[cs.length - 1] = last.subarray(0, chunkSize - lastOfs);
2024
+ const chunk = new Uint8Array(chunkSize);
2025
+ let ofs = 0;
2026
+ for (const c of cs) {
2027
+ chunk.set(c, ofs);
2028
+ ofs += c.length;
2029
+ }
2030
+ return { rest, chunk };
2031
+ }
2032
+ function pump(ps, controller, next) {
2033
+ ps.reader.read().then(({ done, value }) => {
2034
+ if (done) {
2035
+ if (ps.tmpLen > 0) {
2036
+ controller.enqueue(reChunk(ps.tmp, ps.tmpLen).chunk);
2037
+ }
2038
+ controller.close();
2039
+ next();
2040
+ return;
2041
+ }
2042
+ if (ps.tmpLen + value.length > ps.chunkSize) {
2043
+ ps.tmp.push(value);
2044
+ const res = reChunk(ps.tmp, ps.chunkSize);
2045
+ controller.enqueue(res.chunk);
2046
+ ps.tmp = [res.rest];
2047
+ ps.tmpLen = res.rest.length;
2048
+ next();
2049
+ return;
2050
+ } else if (value.length) {
2051
+ ps.tmp.push(value);
2052
+ ps.tmpLen += value.length;
2053
+ }
2054
+ pump(ps, controller, next);
2055
+ });
2056
+ }
2057
+ function rebuffer(a, chunkSize) {
2058
+ const state = {
2059
+ reader: a.getReader(),
2060
+ tmp: [],
2061
+ tmpLen: 0,
2062
+ chunkSize
2063
+ };
2064
+ return new ReadableStream({
2065
+ async pull(controller) {
2066
+ return new Promise((resolve) => {
2067
+ pump(state, controller, resolve);
2068
+ });
2069
+ }
2070
+ });
2071
+ }
2072
+
2073
+ // src/utils/stream2string.ts
2074
+ async function stream2string(stream, maxSize) {
2075
+ if (!stream) {
2076
+ return Promise.resolve("");
2077
+ }
2078
+ const reader = stream.getReader();
2079
+ let res = "";
2080
+ const decoder2 = new TextDecoder();
2081
+ let rSize = 0;
2082
+ while (typeof maxSize === "undefined" || rSize < maxSize) {
2083
+ try {
2084
+ const read = await reader.read();
2085
+ if (read.done) {
2086
+ break;
2087
+ }
2088
+ if (maxSize && rSize + read.value.length > maxSize) {
2089
+ read.value = read.value.slice(0, maxSize - rSize);
2090
+ }
2091
+ const block = decoder2.decode(read.value, { stream: true });
2092
+ rSize += read.value.length;
2093
+ res += block;
2094
+ } catch (err) {
2095
+ return Promise.reject(err);
2096
+ }
2097
+ }
2098
+ return Promise.resolve(res);
2099
+ }
2100
+ async function stream2uint8array(stream) {
2101
+ if (!stream) {
2102
+ return Promise.resolve(new Uint8Array());
2103
+ }
2104
+ const reader = stream.getReader();
2105
+ let res = new Uint8Array();
2106
+ while (1) {
2107
+ try {
2108
+ const { done, value } = await reader.read();
2109
+ if (done) {
2110
+ break;
2111
+ }
2112
+ res = new Uint8Array([...res, ...value]);
2113
+ } catch (err) {
2114
+ return Promise.reject(err);
2115
+ }
2116
+ }
2117
+ return Promise.resolve(res);
2118
+ }
2119
+
2120
+ // src/utils/stream-test-helper.ts
2121
+ async function receiveFromStream(reb, state) {
2122
+ return new Promise((resolve) => {
2123
+ let reBufferCalls = 0;
2124
+ const reader = reb.getReader();
2125
+ function pump2() {
2126
+ reader.read().then(({ done, value }) => {
2127
+ state.CollectorFn({ done, value, fillCalls: state.fillCalls, reBufferCalls });
2128
+ reBufferCalls++;
2129
+ if (done) {
2130
+ resolve();
2131
+ return;
2132
+ }
2133
+ pump2();
2134
+ });
2135
+ }
2136
+ pump2();
2137
+ });
2138
+ }
2139
+ async function sendToStream(reb, state) {
2140
+ return new Promise((resolve) => {
2141
+ const writer = reb.getWriter();
2142
+ function pump2(i) {
2143
+ if (i >= state.sendChunks) {
2144
+ writer.close();
2145
+ resolve();
2146
+ return;
2147
+ }
2148
+ writer.ready.then(() => {
2149
+ state.fillCalls++;
2150
+ writer.write(new Uint8Array(Array(state.sendChunkSize).fill(i)));
2151
+ pump2(i + 1);
2152
+ });
2153
+ }
2154
+ pump2(0);
2155
+ });
2156
+ }
2157
+
2158
+ // src/utils/string2stream.ts
2159
+ function string2stream(str) {
2160
+ const encoder2 = new TextEncoder();
2161
+ return uint8array2stream(encoder2.encode(str));
2162
+ }
2163
+ function uint8array2stream(str) {
2164
+ return new ReadableStream({
2165
+ start(controller) {
2166
+ controller.enqueue(str);
2167
+ controller.close();
2168
+ }
2169
+ });
2170
+ }
1848
2171
  // Annotate the CommonJS export names for ESM import in node:
1849
2172
  0 && (module.exports = {
2173
+ BaseSysAbstraction,
1850
2174
  BrowserEnvActions,
1851
2175
  BuildURI,
2176
+ ConstTime,
1852
2177
  EnvImpl,
1853
- FanoutWriter,
1854
2178
  Future,
1855
2179
  IDMode,
2180
+ IdService,
1856
2181
  IsLogger,
1857
2182
  Keyed,
1858
2183
  KeyedResolvOnce,
@@ -1861,30 +2186,37 @@ function toCryptoRuntime(cryptoOpts = {}) {
1861
2186
  LevelHandlerImpl,
1862
2187
  LogCollector,
1863
2188
  LogValue,
1864
- LogWriterCollector,
2189
+ LogWriteStream,
1865
2190
  LogWriterStream,
1866
2191
  LoggerImpl,
1867
2192
  MockLogger,
2193
+ MutableURL,
1868
2194
  None,
1869
2195
  Option,
1870
2196
  RandomMode,
2197
+ RandomService,
1871
2198
  ResolveOnce,
1872
2199
  ResolveSeq,
1873
2200
  Result,
1874
2201
  ResultError,
1875
2202
  ResultOK,
1876
2203
  Some,
2204
+ StepTime,
1877
2205
  String2TimeMode,
2206
+ SysTime,
1878
2207
  Time,
2208
+ TimeFactory,
1879
2209
  TimeMode,
1880
2210
  TimeUnits,
1881
2211
  URI,
2212
+ WrapperSysAbstraction,
1882
2213
  asyncLogValue,
1883
2214
  envFactory,
1884
2215
  isURL,
1885
2216
  logValue,
1886
2217
  removeSelfRef,
1887
2218
  runtimeFn,
1888
- toCryptoRuntime
2219
+ toCryptoRuntime,
2220
+ utils
1889
2221
  });
1890
2222
  //# sourceMappingURL=index.cjs.map