@adviser/cement 0.2.17 → 0.2.19

Sign up to get free protection for your applications and to get access to all the features.
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.js CHANGED
@@ -1,27 +1,40 @@
1
+ import {
2
+ ConsoleWriterStream,
3
+ FanoutWriteStream,
4
+ utils_exports
5
+ } from "./chunk-AO7BGISE.js";
1
6
  import {
2
7
  WebSysAbstraction
3
- } from "./chunk-XJF7FQUN.js";
8
+ } from "./chunk-2L33RPFJ.js";
4
9
  import {
10
+ BaseSysAbstraction,
5
11
  BrowserEnvActions,
12
+ ConstTime,
6
13
  EnvImpl,
7
14
  Future,
8
15
  IDMode,
16
+ IdService,
9
17
  Keyed,
10
18
  KeyedResolvOnce,
11
19
  KeyedResolvSeq,
12
20
  RandomMode,
21
+ RandomService,
13
22
  ResolveOnce,
14
23
  ResolveSeq,
24
+ StepTime,
15
25
  String2TimeMode,
26
+ SysTime,
16
27
  Time,
28
+ TimeFactory,
17
29
  TimeMode,
18
30
  TimeUnits,
31
+ WrapperSysAbstraction,
19
32
  envFactory
20
- } from "./chunk-O4F5AURC.js";
33
+ } from "./chunk-JYUQZNDZ.js";
21
34
  import {
22
35
  __spreadValues,
23
36
  __yieldStar
24
- } from "./chunk-J2IM7FHM.js";
37
+ } from "./chunk-I4NUGWZ6.js";
25
38
 
26
39
  // src/logger.ts
27
40
  var Level = /* @__PURE__ */ ((Level2) => {
@@ -110,34 +123,100 @@ function falsy2undef(value) {
110
123
  }
111
124
  function ensureURLWithDefaultProto(url, defaultProtocol) {
112
125
  if (!url) {
113
- return new URL(`${defaultProtocol}//`);
126
+ return new MutableURL(`${defaultProtocol}//`);
114
127
  }
115
128
  if (typeof url === "string") {
116
129
  try {
117
- return new URL(url);
130
+ return new MutableURL(url);
118
131
  } catch (e) {
119
- return new URL(`${defaultProtocol}//${url}`);
132
+ return new MutableURL(`${defaultProtocol}//${url}`);
120
133
  }
121
134
  } else {
122
- return url;
135
+ return new MutableURL(url.toString());
123
136
  }
124
137
  }
125
138
  function isURL(value) {
126
139
  return value instanceof URL || !!value && typeof value.searchParams === "object" && typeof value.searchParams.sort === "function" && typeof value.hash === "string";
127
140
  }
141
+ var MutableURL = class _MutableURL extends URL {
142
+ constructor(urlStr) {
143
+ super("defect://does.not.exist");
144
+ this._sysURL = new URL(urlStr);
145
+ this._protocol = this._sysURL.protocol;
146
+ this._hasHostpart = ["http:", "https:"].includes(this._protocol);
147
+ if (this._hasHostpart) {
148
+ this._pathname = this._sysURL.pathname;
149
+ } else {
150
+ this._pathname = urlStr.replace(new RegExp(`^${this._protocol}//`), "").replace(/[#?].*$/, "");
151
+ }
152
+ this.hash = this._sysURL.hash;
153
+ }
154
+ clone() {
155
+ return new _MutableURL(this.toString());
156
+ }
157
+ get hostname() {
158
+ if (!this._hasHostpart) {
159
+ throw new Error("you can use hostname only if protocol is http or https");
160
+ }
161
+ return this._sysURL.hostname;
162
+ }
163
+ set hostname(h) {
164
+ if (!this._hasHostpart) {
165
+ throw new Error("you can use hostname only if protocol is http or https");
166
+ }
167
+ this._sysURL.hostname = h;
168
+ }
169
+ set pathname(p) {
170
+ this._pathname = p;
171
+ }
172
+ get pathname() {
173
+ return this._pathname;
174
+ }
175
+ get protocol() {
176
+ return this._protocol;
177
+ }
178
+ set protocol(p) {
179
+ if (!p.endsWith(":")) {
180
+ p = `${p}:`;
181
+ }
182
+ this._protocol = p;
183
+ }
184
+ get searchParams() {
185
+ return this._sysURL.searchParams;
186
+ }
187
+ toString() {
188
+ let search = "";
189
+ if (this._sysURL.searchParams.size) {
190
+ for (const [key, value] of Array.from(this._sysURL.searchParams.entries()).sort((a, b) => a[0].localeCompare(b[0]))) {
191
+ search += `${!search.length ? "?" : "&"}${key}=${encodeURIComponent(value)}`;
192
+ }
193
+ }
194
+ let hostpart = "";
195
+ if (this._hasHostpart) {
196
+ hostpart = this._sysURL.hostname;
197
+ if (this._sysURL.port) {
198
+ hostpart += `:${this._sysURL.port}`;
199
+ }
200
+ if (!this._pathname.startsWith("/")) {
201
+ hostpart += "/";
202
+ }
203
+ }
204
+ return `${this._protocol}//${hostpart}${this._pathname}${search}`;
205
+ }
206
+ };
128
207
  function from(fac, strURLUri, defaultProtocol) {
129
208
  switch (typeof falsy2undef(strURLUri)) {
130
209
  case "undefined":
131
- return fac(new URL(`${defaultProtocol}//`));
210
+ return fac(new MutableURL(`${defaultProtocol}///`));
132
211
  case "string":
133
212
  return fac(ensureURLWithDefaultProto(strURLUri, defaultProtocol));
134
213
  case "object":
135
214
  if (BuildURI.is(strURLUri)) {
136
- return fac(new URL(strURLUri._url.toString()));
215
+ return fac(new MutableURL(strURLUri._url.toString()));
137
216
  } else if (URI.is(strURLUri)) {
138
- return fac(new URL(strURLUri._url.toString()));
217
+ return fac(new MutableURL(strURLUri._url.toString()));
139
218
  } else if (isURL(strURLUri)) {
140
- return fac(new URL(strURLUri.toString()));
219
+ return fac(new MutableURL(strURLUri.toString()));
141
220
  }
142
221
  throw new Error(`unknown object type: ${strURLUri}`);
143
222
  default:
@@ -159,46 +238,38 @@ var BuildURI = class _BuildURI {
159
238
  this._url.hostname = h;
160
239
  return this;
161
240
  }
162
- password(p) {
163
- this._url.password = p;
164
- return this;
165
- }
166
- port(p) {
167
- this._url.port = p;
168
- return this;
169
- }
170
- username(u) {
171
- this._url.username = u;
172
- return this;
173
- }
174
- search(s) {
175
- this._url.search = s;
176
- return this;
177
- }
241
+ // password(p: string) {
242
+ // this._url.password = p;
243
+ // return this;
244
+ // }
245
+ // port(p: string) {
246
+ // this._url.port = p;
247
+ // return this;
248
+ // }
249
+ // username(u: string) {
250
+ // this._url.username = u;
251
+ // return this;
252
+ // }
253
+ // search(s: string) {
254
+ // this._url.search = s;
255
+ // return this;
256
+ // }
178
257
  protocol(p) {
179
- if (!p.endsWith(":")) {
180
- p = `${p}:`;
181
- }
182
- const mySrc = this._url.toString();
183
- const myDst = mySrc.replace(new RegExp(`^${this._url.protocol}`), `${p}`);
184
- this._url = new URL(myDst);
258
+ this._url.protocol = p;
185
259
  return this;
186
260
  }
187
261
  pathname(p) {
188
- const myp = this.URI().pathname;
189
- const mySrc = this._url.toString();
190
- const myDst = mySrc.replace(new RegExp(`^${this._url.protocol}//${myp}`), `${this._url.protocol}//${p}`);
191
- this._url = new URL(myDst);
192
- return this;
193
- }
194
- hash(h) {
195
- this._url.hash = h;
196
- return this;
197
- }
198
- host(h) {
199
- this._url.host = h;
262
+ this._url.pathname = p;
200
263
  return this;
201
264
  }
265
+ // hash(h: string) {
266
+ // this._url.hash = h;
267
+ // return this;
268
+ // }
269
+ // host(h: string) {
270
+ // this._url.host = h;
271
+ // return this;
272
+ // }
202
273
  delParam(key) {
203
274
  this._url.searchParams.delete(key);
204
275
  return this;
@@ -217,6 +288,9 @@ var BuildURI = class _BuildURI {
217
288
  this._url.searchParams.sort();
218
289
  return this._url.toString();
219
290
  }
291
+ toJSON() {
292
+ return this.toString();
293
+ }
220
294
  URI() {
221
295
  return URI.from(this._url);
222
296
  }
@@ -244,38 +318,38 @@ var URI = class _URI {
244
318
  return from((url) => new _URI(url), strURLUri, defaultProtocol);
245
319
  }
246
320
  constructor(url) {
247
- this._url = url;
321
+ this._url = url.clone();
248
322
  }
249
323
  build() {
250
- return BuildURI.from(this.asURL());
324
+ return BuildURI.from(this._url);
251
325
  }
252
326
  get hostname() {
253
327
  return this._url.hostname;
254
328
  }
255
- get password() {
256
- return this._url.password;
257
- }
258
- get port() {
259
- return this._url.port;
260
- }
261
- get username() {
262
- return this._url.username;
263
- }
264
- get search() {
265
- return this._url.search;
266
- }
329
+ // get password(): string {
330
+ // return this._url.password;
331
+ // }
332
+ // get port(): string {
333
+ // return this._url.port;
334
+ // }
335
+ // get username(): string {
336
+ // return this._url.username;
337
+ // }
338
+ // get search(): string {
339
+ // return this._url.search;
340
+ // }
267
341
  get protocol() {
268
342
  return this._url.protocol;
269
343
  }
270
344
  get pathname() {
271
345
  return this._url.toString().replace(/^.*:\/\//, "").replace(/\?.*$/, "");
272
346
  }
273
- get hash() {
274
- return this._url.hash;
275
- }
276
- get host() {
277
- return this._url.host;
278
- }
347
+ // get hash(): string {
348
+ // return this._url.hash;
349
+ // }
350
+ // get host(): string {
351
+ // return this._url.host;
352
+ // }
279
353
  get getParams() {
280
354
  return this._url.searchParams.entries();
281
355
  }
@@ -286,17 +360,17 @@ var URI = class _URI {
286
360
  return falsy2undef(this._url.searchParams.get(key));
287
361
  }
288
362
  clone() {
289
- return new _URI(this.asURL());
363
+ return new _URI(this._url);
290
364
  }
291
365
  asURL() {
292
- const url = new URL(this._url.toString());
293
- url.searchParams.sort();
294
- return url;
366
+ return this._url.clone();
295
367
  }
296
368
  toString() {
297
- this._url.searchParams.sort();
298
369
  return this._url.toString();
299
370
  }
371
+ toJSON() {
372
+ return this.toString();
373
+ }
300
374
  };
301
375
 
302
376
  // src/runtime.ts
@@ -322,7 +396,7 @@ function runtimeFn() {
322
396
  };
323
397
  }
324
398
 
325
- // src/logger_impl.ts
399
+ // src/logger-impl.ts
326
400
  var encoder = new TextEncoder();
327
401
  var LevelHandlerImpl = class {
328
402
  constructor() {
@@ -466,68 +540,6 @@ function toLogValue(lop) {
466
540
  }
467
541
  return lop;
468
542
  }
469
- var ConsoleWriterStreamDefaultWriter = class {
470
- constructor(stream) {
471
- this.stream = stream;
472
- this.desiredSize = null;
473
- this.decoder = new TextDecoder();
474
- this._stream = stream;
475
- this.ready = Promise.resolve(void 0);
476
- this.closed = Promise.resolve(void 0);
477
- }
478
- // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
479
- abort(reason) {
480
- throw new Error("Method not implemented.");
481
- }
482
- async close() {
483
- }
484
- releaseLock() {
485
- this._stream.locked = false;
486
- this.ready = Promise.resolve(void 0);
487
- this.closed = Promise.resolve(void 0);
488
- }
489
- async write(chunk) {
490
- const str = this.decoder.decode(chunk).trimEnd();
491
- let output = "log";
492
- try {
493
- const decode = JSON.parse(str);
494
- output = decode.level;
495
- } catch (e) {
496
- }
497
- switch (output) {
498
- case "error":
499
- console.error(str);
500
- break;
501
- case "warn":
502
- console.warn(str);
503
- break;
504
- default:
505
- console.log(str);
506
- }
507
- }
508
- };
509
- var ConsoleWriterStream = class {
510
- constructor() {
511
- this.locked = false;
512
- }
513
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
514
- abort(reason) {
515
- throw new Error("Method not implemented.");
516
- }
517
- async close() {
518
- return;
519
- }
520
- getWriter() {
521
- if (this.locked) {
522
- throw new Error("Stream is locked");
523
- }
524
- this.locked = true;
525
- if (!this._writer) {
526
- this._writer = new ConsoleWriterStreamDefaultWriter(this);
527
- }
528
- return this._writer;
529
- }
530
- };
531
543
  var LoggerImpl = class _LoggerImpl {
532
544
  // readonly _id: string = "logger-" + Math.random().toString(36)
533
545
  constructor(params) {
@@ -572,6 +584,17 @@ var LoggerImpl = class _LoggerImpl {
572
584
  this._levelHandler = levelSingleton;
573
585
  }
574
586
  }
587
+ Attributes() {
588
+ return Array.from(Object.entries(this._attributes)).reduce(
589
+ (acc, [key, value]) => {
590
+ if (value instanceof LogValue) {
591
+ acc[key] = value.value();
592
+ }
593
+ return acc;
594
+ },
595
+ {}
596
+ );
597
+ }
575
598
  SetExposeStack(enable) {
576
599
  this._levelHandler.setExposeStack(enable);
577
600
  return this;
@@ -595,7 +618,7 @@ var LoggerImpl = class _LoggerImpl {
595
618
  return this;
596
619
  }
597
620
  Timestamp() {
598
- this._attributes["ts"] = logValue(this._sys.Time().Now().toISOString());
621
+ this._attributes["ts"] = logValue(() => this._sys.Time().Now().toISOString());
599
622
  return this;
600
623
  }
601
624
  Warn() {
@@ -712,18 +735,11 @@ var LoggerImpl = class _LoggerImpl {
712
735
  return ret;
713
736
  }
714
737
  _produceError(attr, ...args) {
715
- var _a;
716
738
  attr["msg"] = logValue(args.join(" "));
717
739
  const msg = attr["msg"].value();
718
740
  if (typeof msg === "string" && !msg.trim().length) {
719
741
  delete attr["msg"];
720
742
  }
721
- if (((_a = toLogValue(attr["ts"])) == null ? void 0 : _a.value()) === "ETERNITY") {
722
- this.Timestamp.call({
723
- _sys: this._sys,
724
- _attributes: attr
725
- });
726
- }
727
743
  return JSON.stringify(attr, removeSelfRef());
728
744
  }
729
745
  Msg(...args) {
@@ -755,6 +771,9 @@ var WithLoggerBuilder = class {
755
771
  Object.assign(this._li._withAttributes, this._li._attributes);
756
772
  return this._li;
757
773
  }
774
+ Attributes() {
775
+ return __spreadValues({}, this._li._attributes);
776
+ }
758
777
  SetExposeStack(enable) {
759
778
  this._li._levelHandler.setExposeStack(enable);
760
779
  return this;
@@ -836,7 +855,7 @@ var WithLoggerBuilder = class {
836
855
  return this;
837
856
  }
838
857
  Timestamp() {
839
- this._li._attributes["ts"] = logValue("ETERNITY");
858
+ this._li.Timestamp();
840
859
  return this;
841
860
  }
842
861
  Any(key, value) {
@@ -853,8 +872,8 @@ var WithLoggerBuilder = class {
853
872
  }
854
873
  };
855
874
 
856
- // src/test/log_collector.ts
857
- var LogWriterCollector = class {
875
+ // src/test/log-write-stream.ts
876
+ var LogWriteStream = class {
858
877
  constructor(bufferArr) {
859
878
  this._resolveClosed = new Future();
860
879
  this.closed = this._resolveClosed.asPromise();
@@ -879,30 +898,6 @@ var LogWriterCollector = class {
879
898
  return Promise.resolve(void 0);
880
899
  }
881
900
  };
882
- var FanoutWriter = class {
883
- constructor(writers) {
884
- this.desiredSize = null;
885
- this._writers = writers;
886
- this.ready = Promise.all(this._writers.map((w) => w.ready)).then(() => void 0);
887
- this.closed = Promise.all(this._writers.map((w) => w.closed)).then(() => void 0);
888
- }
889
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
890
- abort(reason) {
891
- return Promise.all(this._writers.map((w) => w.abort(reason))).then(() => {
892
- });
893
- }
894
- close() {
895
- return Promise.all(this._writers.map((w) => w.close())).then(() => {
896
- });
897
- }
898
- releaseLock() {
899
- this._writers.map((w) => w.releaseLock());
900
- }
901
- write(chunk) {
902
- return Promise.all(this._writers.map((w) => w.write(chunk))).then(() => {
903
- });
904
- }
905
- };
906
901
  var LogCollector = class {
907
902
  constructor(pass) {
908
903
  this.locked = false;
@@ -923,11 +918,11 @@ var LogCollector = class {
923
918
  }
924
919
  getWriter() {
925
920
  if (!this._writer) {
926
- const dests = [new LogWriterCollector(this._bufferArr)];
921
+ const dests = [new LogWriteStream(this._bufferArr)];
927
922
  if (this._pass) {
928
923
  dests.push(this._pass);
929
924
  }
930
- this._writer = new FanoutWriter(dests);
925
+ this._writer = new FanoutWriteStream(dests);
931
926
  }
932
927
  return this._writer;
933
928
  }
@@ -952,7 +947,7 @@ var LogCollector = class {
952
947
  }
953
948
  };
954
949
 
955
- // src/test/mock_logger.ts
950
+ // src/test/mock-logger.ts
956
951
  function MockLogger(params) {
957
952
  const lc = new LogCollector(params == null ? void 0 : params.pass);
958
953
  let modNames = ["MockLogger"];
@@ -1119,12 +1114,14 @@ function toCryptoRuntime(cryptoOpts = {}) {
1119
1114
  return runtime;
1120
1115
  }
1121
1116
  export {
1117
+ BaseSysAbstraction,
1122
1118
  BrowserEnvActions,
1123
1119
  BuildURI,
1120
+ ConstTime,
1124
1121
  EnvImpl,
1125
- FanoutWriter,
1126
1122
  Future,
1127
1123
  IDMode,
1124
+ IdService,
1128
1125
  IsLogger,
1129
1126
  Keyed,
1130
1127
  KeyedResolvOnce,
@@ -1133,30 +1130,37 @@ export {
1133
1130
  LevelHandlerImpl,
1134
1131
  LogCollector,
1135
1132
  LogValue,
1136
- LogWriterCollector,
1133
+ LogWriteStream,
1137
1134
  LogWriterStream,
1138
1135
  LoggerImpl,
1139
1136
  MockLogger,
1137
+ MutableURL,
1140
1138
  None,
1141
1139
  Option,
1142
1140
  RandomMode,
1141
+ RandomService,
1143
1142
  ResolveOnce,
1144
1143
  ResolveSeq,
1145
1144
  Result,
1146
1145
  ResultError,
1147
1146
  ResultOK,
1148
1147
  Some,
1148
+ StepTime,
1149
1149
  String2TimeMode,
1150
+ SysTime,
1150
1151
  Time,
1152
+ TimeFactory,
1151
1153
  TimeMode,
1152
1154
  TimeUnits,
1153
1155
  URI,
1156
+ WrapperSysAbstraction,
1154
1157
  asyncLogValue,
1155
1158
  envFactory,
1156
1159
  isURL,
1157
1160
  logValue,
1158
1161
  removeSelfRef,
1159
1162
  runtimeFn,
1160
- toCryptoRuntime
1163
+ toCryptoRuntime,
1164
+ utils_exports as utils
1161
1165
  };
1162
1166
  //# sourceMappingURL=index.js.map