@adviser/cement 0.2.40 → 0.2.42

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 (83) hide show
  1. package/{chunk-USQXEZHL.js → chunk-3RHIVQAA.js} +2 -2
  2. package/{chunk-W2GV5KXV.js → chunk-N3NUTN4B.js} +3 -3
  3. package/{chunk-F5W6VELE.js → chunk-N5LQQXOU.js} +2 -2
  4. package/chunk-PPS4L4VW.js +38 -0
  5. package/{chunk-GES3MUGV.js.map → chunk-PPS4L4VW.js.map} +1 -1
  6. package/index.cjs +500 -179
  7. package/index.cjs.map +1 -1
  8. package/index.d.cts +73 -30
  9. package/index.d.ts +73 -30
  10. package/index.js +506 -141
  11. package/index.js.map +1 -1
  12. package/node/index.js +2 -2
  13. package/package.json +2 -2
  14. package/src/http_header.ts +161 -0
  15. package/src/index.ts +1 -0
  16. package/src/jsr.json +1 -1
  17. package/src/log-level-impl.ts +7 -0
  18. package/src/logger-impl.ts +70 -43
  19. package/src/logger.ts +37 -9
  20. package/src/option.ts +7 -0
  21. package/src/result.ts +7 -1
  22. package/src/uri.ts +35 -11
  23. package/src/utils/relative-path.ts +161 -0
  24. package/ts/http_header.d.ts +29 -0
  25. package/ts/http_header.d.ts.map +1 -0
  26. package/ts/http_header.js +155 -0
  27. package/ts/http_header.js.map +1 -0
  28. package/ts/http_header.test.d.ts +2 -0
  29. package/ts/http_header.test.d.ts.map +1 -0
  30. package/ts/http_header.test.js +90 -0
  31. package/ts/http_header.test.js.map +1 -0
  32. package/ts/index.d.ts +1 -0
  33. package/ts/index.d.ts.map +1 -1
  34. package/ts/index.js +1 -0
  35. package/ts/index.js.map +1 -1
  36. package/ts/log-level-impl.d.ts +3 -0
  37. package/ts/log-level-impl.d.ts.map +1 -1
  38. package/ts/log-level-impl.js +5 -0
  39. package/ts/log-level-impl.js.map +1 -1
  40. package/ts/logger-impl.d.ts +2 -1
  41. package/ts/logger-impl.d.ts.map +1 -1
  42. package/ts/logger-impl.js +66 -47
  43. package/ts/logger-impl.js.map +1 -1
  44. package/ts/logger.d.ts +10 -1
  45. package/ts/logger.d.ts.map +1 -1
  46. package/ts/logger.js +22 -8
  47. package/ts/logger.js.map +1 -1
  48. package/ts/logger.test.js +111 -58
  49. package/ts/logger.test.js.map +1 -1
  50. package/ts/option.d.ts +1 -0
  51. package/ts/option.d.ts.map +1 -1
  52. package/ts/option.js +6 -0
  53. package/ts/option.js.map +1 -1
  54. package/ts/result.d.ts +1 -1
  55. package/ts/result.d.ts.map +1 -1
  56. package/ts/result.js +6 -0
  57. package/ts/result.js.map +1 -1
  58. package/ts/result.test.js +6 -0
  59. package/ts/result.test.js.map +1 -1
  60. package/ts/tracer.js +24 -6
  61. package/ts/tracer.js.map +1 -1
  62. package/ts/uri.d.ts +3 -1
  63. package/ts/uri.d.ts.map +1 -1
  64. package/ts/uri.js +27 -10
  65. package/ts/uri.js.map +1 -1
  66. package/ts/uri.test.js +39 -10
  67. package/ts/uri.test.js.map +1 -1
  68. package/ts/utils/relative-path.d.ts +17 -0
  69. package/ts/utils/relative-path.d.ts.map +1 -0
  70. package/ts/utils/relative-path.js +148 -0
  71. package/ts/utils/relative-path.js.map +1 -0
  72. package/ts/utils/relative-path.test.d.ts +2 -0
  73. package/ts/utils/relative-path.test.d.ts.map +1 -0
  74. package/ts/utils/relative-path.test.js +187 -0
  75. package/ts/utils/relative-path.test.js.map +1 -0
  76. package/ts/utils/stripper.js +1 -1
  77. package/ts/utils/stripper.js.map +1 -1
  78. package/utils/index.js +2 -2
  79. package/web/index.js +3 -3
  80. package/chunk-GES3MUGV.js +0 -92
  81. /package/{chunk-USQXEZHL.js.map → chunk-3RHIVQAA.js.map} +0 -0
  82. /package/{chunk-W2GV5KXV.js.map → chunk-N3NUTN4B.js.map} +0 -0
  83. /package/{chunk-F5W6VELE.js.map → chunk-N5LQQXOU.js.map} +0 -0
package/index.js CHANGED
@@ -1,6 +1,11 @@
1
+ import {
2
+ ConsoleWriterStream,
3
+ FanoutWriteStream,
4
+ utils_exports
5
+ } from "./chunk-3RHIVQAA.js";
1
6
  import {
2
7
  WebSysAbstraction
3
- } from "./chunk-W2GV5KXV.js";
8
+ } from "./chunk-N3NUTN4B.js";
4
9
  import {
5
10
  BaseSysAbstraction,
6
11
  BrowserEnvActions,
@@ -25,19 +30,11 @@ import {
25
30
  TimeUnits,
26
31
  WrapperSysAbstraction,
27
32
  envFactory
28
- } from "./chunk-F5W6VELE.js";
29
- import {
30
- ConsoleWriterStream,
31
- FanoutWriteStream,
32
- utils_exports
33
- } from "./chunk-USQXEZHL.js";
33
+ } from "./chunk-N5LQQXOU.js";
34
34
  import {
35
35
  Utf8EnDecoder,
36
- Utf8EnDecoderSingleton,
37
- __spreadProps,
38
- __spreadValues,
39
- __yieldStar
40
- } from "./chunk-GES3MUGV.js";
36
+ Utf8EnDecoderSingleton
37
+ } from "./chunk-PPS4L4VW.js";
41
38
 
42
39
  // src/logger-impl.ts
43
40
  import YAML from "yaml";
@@ -114,7 +111,18 @@ var LogValue = class {
114
111
  function asyncLogValue(val) {
115
112
  throw new Error("Not implemented");
116
113
  }
117
- function logValue(val, state = /* @__PURE__ */ new Set([Math.random()])) {
114
+ function logValue(val, ctx) {
115
+ return logValueInternal(val, {
116
+ ...ctx,
117
+ state: ctx.state || /* @__PURE__ */ new Set([Math.random()])
118
+ });
119
+ }
120
+ function logValueInternal(val, ctx) {
121
+ var _a, _b;
122
+ ctx = {
123
+ ...ctx,
124
+ state: ctx.state || /* @__PURE__ */ new Set([Math.random()])
125
+ };
118
126
  switch (typeof val) {
119
127
  case "function":
120
128
  return new LogValue(val);
@@ -122,7 +130,7 @@ function logValue(val, state = /* @__PURE__ */ new Set([Math.random()])) {
122
130
  try {
123
131
  const ret = JSON.parse(val);
124
132
  if (typeof ret === "object" && ret !== null) {
125
- return logValue(ret, state);
133
+ return logValueInternal(ret, ctx);
126
134
  }
127
135
  } catch (e) {
128
136
  if (val.match(/[\n\r]/)) {
@@ -145,13 +153,15 @@ function logValue(val, state = /* @__PURE__ */ new Set([Math.random()])) {
145
153
  const decoder = new TextDecoder();
146
154
  const asStr = decoder.decode(val);
147
155
  const obj = JSON.parse(asStr);
148
- return logValue(obj, state);
156
+ return logValueInternal(obj, ctx);
149
157
  } catch (e) {
150
- return logValue(bin2string(val, 512));
158
+ return logValueInternal(bin2string(val, 512), ctx);
151
159
  }
152
160
  }
153
161
  if (Array.isArray(val)) {
154
- return new LogValue(() => val.map((v) => logValue(v).value()));
162
+ return new LogValue(
163
+ () => val.map((v) => logValue(v, { ...ctx, state: void 0 }).value())
164
+ );
155
165
  }
156
166
  if (val instanceof Headers) {
157
167
  return new LogValue(() => Object.fromEntries(val.entries()));
@@ -162,22 +172,25 @@ function logValue(val, state = /* @__PURE__ */ new Set([Math.random()])) {
162
172
  if (val instanceof Promise) {
163
173
  return new LogValue(() => ">Promise<");
164
174
  }
165
- if (state.has(val)) {
175
+ if ((_a = ctx.state) == null ? void 0 : _a.has(val)) {
166
176
  return new LogValue(() => "...");
167
177
  }
168
- state.add(val);
178
+ (_b = ctx.state) == null ? void 0 : _b.add(val);
169
179
  if (typeof val.toJSON === "function") {
170
180
  return new LogValue(() => val.toJSON());
171
181
  }
172
182
  const res = {};
173
183
  const typedVal = val;
174
184
  for (const key in typedVal) {
185
+ if (ctx.ignoreAttr.IsSome() && ctx.ignoreAttr.unwrap().test(key)) {
186
+ continue;
187
+ }
175
188
  const element = typedVal[key];
176
189
  if (element instanceof LogValue) {
177
190
  res[key] = element;
178
191
  } else {
179
192
  if (typeof element !== "function") {
180
- res[key] = logValue(element, state);
193
+ res[key] = logValueInternal(element, ctx);
181
194
  }
182
195
  }
183
196
  }
@@ -220,6 +233,12 @@ var Result = class _Result {
220
233
  if (typeof t === "string") {
221
234
  return new ResultError(new Error(t));
222
235
  }
236
+ if (_Result.Is(t)) {
237
+ if (t.is_ok()) {
238
+ return new ResultError(new Error("Result Error is Ok"));
239
+ }
240
+ return t;
241
+ }
223
242
  return new ResultError(t);
224
243
  }
225
244
  static Is(t) {
@@ -296,6 +315,139 @@ function exception2Result(fn) {
296
315
  }
297
316
  }
298
317
 
318
+ // src/utils/relative-path.ts
319
+ var Path = class {
320
+ constructor(parts = []) {
321
+ this.parts = parts;
322
+ }
323
+ toString() {
324
+ return this.parts.map((part) => {
325
+ if (typeof part === "string") {
326
+ return part;
327
+ } else {
328
+ switch (part) {
329
+ case 1 /* Slash */:
330
+ case 3 /* Root */:
331
+ return "/";
332
+ case 4 /* Up */:
333
+ return "..";
334
+ default:
335
+ return part;
336
+ }
337
+ }
338
+ }).join("");
339
+ }
340
+ add(part) {
341
+ if (this.parts.includes(3 /* Root */) && part === 3 /* Root */) {
342
+ throw new Error("Cannot add absolute part to absolute path");
343
+ }
344
+ const last = this.parts[this.parts.length - 1];
345
+ if (last & 1 /* Slash */ && part === 1 /* Slash */) {
346
+ return;
347
+ }
348
+ switch (part) {
349
+ case ".":
350
+ this.parts.push(8 /* Noop */);
351
+ return;
352
+ case "..":
353
+ part = 4 /* Up */;
354
+ }
355
+ if (last === 8 /* Noop */ && part === 1 /* Slash */) {
356
+ if (last === 8 /* Noop */) {
357
+ this.parts.pop();
358
+ }
359
+ return;
360
+ }
361
+ this.parts.push(part);
362
+ }
363
+ };
364
+ function splitPath(path) {
365
+ const p = new Path();
366
+ if (path === "") {
367
+ return p;
368
+ }
369
+ for (let count = 0; path.length; count++) {
370
+ if (path.match(/^\/+/)) {
371
+ if (count === 0) {
372
+ p.add(3 /* Root */);
373
+ } else {
374
+ p.add(1 /* Slash */);
375
+ }
376
+ path = path.replace(/^\/+/, "");
377
+ } else {
378
+ const part = path.replace(/\/.*$/, "");
379
+ p.add(part);
380
+ path = path.replace(/^[^/]+/, "");
381
+ }
382
+ }
383
+ return p;
384
+ }
385
+ function pathJoin(...paths) {
386
+ let prev = "";
387
+ const res = [];
388
+ for (let i = 0; i < paths.length; i++) {
389
+ const path = paths[i];
390
+ if (path === "") {
391
+ continue;
392
+ }
393
+ if (!(prev.endsWith("/") || path.startsWith("/"))) {
394
+ if (prev !== "") {
395
+ res.push("/");
396
+ }
397
+ res.push(path);
398
+ } else {
399
+ res.push(path);
400
+ }
401
+ prev = path;
402
+ }
403
+ return res.join("");
404
+ }
405
+ function relativePath(path, relative) {
406
+ const relativeParts = splitPath(relative);
407
+ let result;
408
+ if (relativeParts.parts[0] === 3 /* Root */) {
409
+ result = relative;
410
+ } else {
411
+ result = pathJoin(path, relative);
412
+ }
413
+ const unoptPath = splitPath(result);
414
+ const out = [];
415
+ let topUp = false;
416
+ for (const part of unoptPath.parts) {
417
+ switch (part) {
418
+ case 3 /* Root */:
419
+ out.push(3 /* Root */);
420
+ break;
421
+ case 4 /* Up */:
422
+ if (out.length && !topUp) {
423
+ const last = out.length - 1;
424
+ if (typeof out[last] === "string" && out[last - 1] == 3 /* Root */) {
425
+ out.pop();
426
+ } else {
427
+ out.pop();
428
+ out.pop();
429
+ }
430
+ if (out.length === 0) {
431
+ topUp = !topUp ? true : topUp;
432
+ out.push(4 /* Up */);
433
+ }
434
+ } else {
435
+ out.push(4 /* Up */);
436
+ }
437
+ break;
438
+ case 1 /* Slash */:
439
+ if (!(out[out.length - 1] & 1 /* Slash */)) {
440
+ out.push(1 /* Slash */);
441
+ }
442
+ break;
443
+ default:
444
+ out.push(part);
445
+ break;
446
+ }
447
+ }
448
+ return new Path(out).toString();
449
+ }
450
+
299
451
  // src/utils/stripper.ts
300
452
  function stripper(strip, obj) {
301
453
  const strips = Array.isArray(strip) ? strip : [strip];
@@ -315,7 +467,7 @@ function localStripper(path, restrips, obj) {
315
467
  if (Array.isArray(obj)) {
316
468
  return obj.map((i) => localStripper(path, restrips, i));
317
469
  }
318
- const ret = __spreadValues({}, obj);
470
+ const ret = { ...obj };
319
471
  const matcher = (key, nextPath) => {
320
472
  for (const re of restrips) {
321
473
  if (re.test(key) || re.test(nextPath)) {
@@ -355,6 +507,7 @@ function localStripper(path, restrips, obj) {
355
507
  }
356
508
 
357
509
  // src/uri.ts
510
+ var REQUIRED = 4711;
358
511
  function coerceKey(key, def) {
359
512
  if (typeof key === "object") {
360
513
  const keys = Object.keys(key);
@@ -575,17 +728,29 @@ var BuildURI = class _BuildURI {
575
728
  this._url.pathname = p;
576
729
  return this;
577
730
  }
578
- appendRelative(p) {
579
- const appendUrl = URI.from(p);
580
- let pathname = appendUrl.pathname;
581
- let basePath = this._url.pathname;
582
- if (pathname.startsWith("/")) {
583
- pathname = pathname.replace(/^\//, "");
731
+ // could pass a relative path or a full URL
732
+ // if relative path, it will be appended to the current path
733
+ resolve(p) {
734
+ if (!p) {
735
+ return this;
584
736
  }
585
- if (basePath.length > 0) {
586
- basePath = basePath.replace(/\/$/, "");
737
+ if (typeof p === "string") {
738
+ if (!p.match(/^[a-zA-Z0-9]+:/)) {
739
+ if (p.startsWith("/")) {
740
+ this.pathname(p);
741
+ return this;
742
+ }
743
+ return this.appendRelative(p);
744
+ }
587
745
  }
588
- this.pathname(basePath + "/" + pathname);
746
+ this._url = new MutableURL(p.toString());
747
+ return this;
748
+ }
749
+ appendRelative(p) {
750
+ const appendUrl = URI.from(p);
751
+ const pathname = "./" + appendUrl.pathname;
752
+ const basePath = this._url.pathname;
753
+ this.pathname(relativePath(basePath, pathname));
589
754
  for (const [key, value] of appendUrl.getParams) {
590
755
  this.setParam(key, value);
591
756
  }
@@ -760,11 +925,12 @@ var URI = class _URI {
760
925
  searchParams: Object.fromEntries(this.getParams)
761
926
  };
762
927
  if (hasHostPartProtocols.has(this.protocol.replace(/:$/, ""))) {
763
- return stripper(strips, __spreadProps(__spreadValues({}, pathURI), {
928
+ return stripper(strips, {
929
+ ...pathURI,
764
930
  style: "host",
765
931
  hostname: this.hostname,
766
932
  port: this.port
767
- }));
933
+ });
768
934
  }
769
935
  return stripper(strips, pathURI);
770
936
  }
@@ -841,11 +1007,66 @@ var LogWriterStream = class {
841
1007
  }
842
1008
  };
843
1009
 
1010
+ // src/option.ts
1011
+ var Option = class _Option {
1012
+ static Some(t) {
1013
+ return new Some(t);
1014
+ }
1015
+ static None() {
1016
+ return new None();
1017
+ }
1018
+ static Is(t) {
1019
+ return t instanceof _Option;
1020
+ }
1021
+ static From(t) {
1022
+ if (!t) {
1023
+ return new None();
1024
+ }
1025
+ return new Some(t);
1026
+ }
1027
+ IsNone() {
1028
+ return this.is_none();
1029
+ }
1030
+ IsSome() {
1031
+ return this.is_some();
1032
+ }
1033
+ Unwrap() {
1034
+ return this.unwrap();
1035
+ }
1036
+ };
1037
+ var Some = class extends Option {
1038
+ constructor(_t) {
1039
+ super();
1040
+ this._t = _t;
1041
+ }
1042
+ is_none() {
1043
+ return false;
1044
+ }
1045
+ is_some() {
1046
+ return true;
1047
+ }
1048
+ unwrap() {
1049
+ return this._t;
1050
+ }
1051
+ };
1052
+ var None = class extends Option {
1053
+ is_none() {
1054
+ return true;
1055
+ }
1056
+ is_some() {
1057
+ return false;
1058
+ }
1059
+ unwrap() {
1060
+ throw new Error("None.unwrap");
1061
+ }
1062
+ };
1063
+
844
1064
  // src/log-level-impl.ts
845
1065
  var LevelHandlerImpl = class {
846
1066
  constructor() {
847
1067
  this._globalLevels = /* @__PURE__ */ new Set(["info" /* INFO */, "error" /* ERROR */, "warn" /* WARN */]);
848
1068
  this._modules = /* @__PURE__ */ new Map();
1069
+ this.ignoreAttr = Option.Some(/^_/);
849
1070
  this.isStackExposed = false;
850
1071
  }
851
1072
  enableLevel(level, ...modules) {
@@ -877,6 +1098,9 @@ var LevelHandlerImpl = class {
877
1098
  setExposeStack(enable) {
878
1099
  this.isStackExposed = !!enable;
879
1100
  }
1101
+ setIgnoreAttr(re) {
1102
+ this.ignoreAttr = Option.From(re);
1103
+ }
880
1104
  forModules(level, fnAction, ...modules) {
881
1105
  for (const m of modules.flat()) {
882
1106
  if (typeof m !== "string") {
@@ -923,20 +1147,20 @@ function LevelHandlerSingleton() {
923
1147
  }
924
1148
 
925
1149
  // src/logger-impl.ts
926
- function getLen(value) {
1150
+ function getLen(value, lvs) {
927
1151
  if (Array.isArray(value)) {
928
- return logValue(() => value.length);
1152
+ return logValue(() => value.length, lvs);
929
1153
  } else if (typeof value === "string") {
930
- return logValue(() => value.length);
1154
+ return logValue(() => value.length, lvs);
931
1155
  } else if (typeof value === "object" && value !== null) {
932
1156
  if (typeof value.size === "number") {
933
- return logValue(() => value.size);
1157
+ return logValue(() => value.size, lvs);
934
1158
  } else if (typeof value.length === "number") {
935
- return logValue(() => value.length);
1159
+ return logValue(() => value.length, lvs);
936
1160
  }
937
- return logValue(() => Object.keys(value).length);
1161
+ return logValue(() => Object.keys(value).length, lvs);
938
1162
  }
939
- return logValue(() => -1);
1163
+ return logValue(() => -1, lvs);
940
1164
  }
941
1165
  function hash(value) {
942
1166
  return "not implemented";
@@ -971,6 +1195,11 @@ var YAMLFormatter = class {
971
1195
  return this._txtEnDe.encode("---\n" + YAML.stringify(attr, null, this._space) + "\n");
972
1196
  }
973
1197
  };
1198
+ function toLogValueCtx(lvh) {
1199
+ return {
1200
+ ignoreAttr: lvh.ignoreAttr
1201
+ };
1202
+ }
974
1203
  var LoggerImpl = class _LoggerImpl {
975
1204
  // readonly _id: string = "logger-" + Math.random().toString(36)
976
1205
  constructor(params) {
@@ -1016,13 +1245,13 @@ var LoggerImpl = class _LoggerImpl {
1016
1245
  if (!params.withAttributes) {
1017
1246
  this._withAttributes = {};
1018
1247
  } else {
1019
- this._withAttributes = __spreadValues({}, params.withAttributes);
1248
+ this._withAttributes = { ...params.withAttributes };
1020
1249
  }
1021
- this._attributes = __spreadValues({}, this._withAttributes);
1250
+ this._attributes = { ...this._withAttributes };
1022
1251
  if (params.levelHandler) {
1023
- this._levelHandler = params.levelHandler;
1252
+ this.levelHandler = params.levelHandler;
1024
1253
  } else {
1025
- this._levelHandler = LevelHandlerSingleton();
1254
+ this.levelHandler = LevelHandlerSingleton();
1026
1255
  }
1027
1256
  }
1028
1257
  TxtEnDe() {
@@ -1032,25 +1261,29 @@ var LoggerImpl = class _LoggerImpl {
1032
1261
  return JSON.parse(JSON.stringify(this._attributes, null));
1033
1262
  }
1034
1263
  SetExposeStack(enable) {
1035
- this._levelHandler.setExposeStack(enable);
1264
+ this.levelHandler.setExposeStack(enable);
1036
1265
  return this;
1037
1266
  }
1038
1267
  EnableLevel(level, ...modules) {
1039
- this._levelHandler.enableLevel(level, ...modules);
1268
+ this.levelHandler.enableLevel(level, ...modules);
1040
1269
  return this;
1041
1270
  }
1042
1271
  DisableLevel(level, ...modules) {
1043
- this._levelHandler.disableLevel(level, ...modules);
1272
+ this.levelHandler.disableLevel(level, ...modules);
1044
1273
  return this;
1045
1274
  }
1046
1275
  Module(key) {
1047
- this._attributes["module"] = logValue(key);
1048
- this._withAttributes["module"] = logValue(key);
1276
+ this._attributes["module"] = logValue(key, toLogValueCtx(this.levelHandler));
1277
+ this._withAttributes["module"] = logValue(key, toLogValueCtx(this.levelHandler));
1049
1278
  return this;
1050
1279
  }
1051
1280
  // if the string is "*" it will enable for all modules
1052
1281
  SetDebug(...modules) {
1053
- this._levelHandler.setDebug(...modules);
1282
+ this.levelHandler.setDebug(...modules);
1283
+ return this;
1284
+ }
1285
+ SetIgnoreAttribute(re) {
1286
+ this.levelHandler.setIgnoreAttr(re);
1054
1287
  return this;
1055
1288
  }
1056
1289
  SetFormatter(formatter) {
@@ -1058,57 +1291,63 @@ var LoggerImpl = class _LoggerImpl {
1058
1291
  return this;
1059
1292
  }
1060
1293
  Timestamp() {
1061
- this._attributes["ts"] = logValue(() => this._sys.Time().Now().toISOString());
1294
+ this._attributes["ts"] = logValue(() => this._sys.Time().Now().toISOString(), toLogValueCtx(this.levelHandler));
1062
1295
  return this;
1063
1296
  }
1064
1297
  Warn() {
1065
- this._attributes["level"] = logValue("warn" /* WARN */);
1298
+ this._attributes["level"] = logValue("warn" /* WARN */, toLogValueCtx(this.levelHandler));
1066
1299
  return this;
1067
1300
  }
1068
1301
  Log() {
1069
1302
  return this;
1070
1303
  }
1071
1304
  Debug() {
1072
- this._attributes["level"] = logValue("debug" /* DEBUG */);
1305
+ this._attributes["level"] = logValue("debug" /* DEBUG */, toLogValueCtx(this.levelHandler));
1073
1306
  return this;
1074
1307
  }
1075
1308
  Error() {
1076
- this._attributes["level"] = logValue("error" /* ERROR */);
1309
+ this._attributes["level"] = logValue("error" /* ERROR */, toLogValueCtx(this.levelHandler));
1077
1310
  return this;
1078
1311
  }
1079
1312
  Info() {
1080
- this._attributes["level"] = logValue("info" /* INFO */);
1313
+ this._attributes["level"] = logValue("info" /* INFO */, toLogValueCtx(this.levelHandler));
1081
1314
  return this;
1082
1315
  }
1083
1316
  Err(err) {
1084
1317
  var _a;
1318
+ let key = "error";
1085
1319
  if (Result.Is(err)) {
1086
1320
  if (err.isOk()) {
1087
- this.Result("noerror", err);
1321
+ key = "noerror";
1322
+ err = err.Ok();
1088
1323
  } else {
1089
- this.Result("error", err);
1324
+ err = err.Err();
1090
1325
  }
1091
- } else if (err instanceof Error) {
1092
- this._attributes["error"] = logValue(err.message);
1093
- if (this._levelHandler.isStackExposed) {
1094
- this._attributes["stack"] = logValue((_a = err.stack) == null ? void 0 : _a.split("\n").map((s) => s.trim()));
1326
+ }
1327
+ if (err instanceof Error) {
1328
+ this._attributes[key] = logValue(err.message, toLogValueCtx(this.levelHandler));
1329
+ if (this.levelHandler.isStackExposed) {
1330
+ this._attributes["stack"] = logValue(
1331
+ (_a = err.stack) == null ? void 0 : _a.split("\n").map((s) => s.trim()),
1332
+ toLogValueCtx(this.levelHandler)
1333
+ );
1095
1334
  }
1096
1335
  } else {
1097
- this._attributes["error"] = logValue("" + err);
1336
+ this.Any(key, err);
1098
1337
  }
1099
1338
  return this;
1100
1339
  }
1101
1340
  WithLevel(l) {
1102
- this._attributes["level"] = logValue(l);
1341
+ this._attributes["level"] = logValue(l, toLogValueCtx(this.levelHandler));
1103
1342
  return this;
1104
1343
  }
1105
1344
  Ref(key, action) {
1106
1345
  if (typeof action === "function") {
1107
- this._attributes[key] = logValue(action);
1346
+ this._attributes[key] = logValue(action, toLogValueCtx(this.levelHandler));
1108
1347
  } else if (typeof action.toString === "function") {
1109
- this._attributes[key] = logValue(() => action.toString());
1348
+ this._attributes[key] = logValue(() => action.toString(), toLogValueCtx(this.levelHandler));
1110
1349
  } else {
1111
- this._attributes[key] = logValue("INVALID REF");
1350
+ this._attributes[key] = logValue("INVALID REF", toLogValueCtx(this.levelHandler));
1112
1351
  }
1113
1352
  return this;
1114
1353
  }
@@ -1158,18 +1397,20 @@ var LoggerImpl = class _LoggerImpl {
1158
1397
  }
1159
1398
  Result(key, res) {
1160
1399
  if (res.isOk()) {
1161
- this._attributes[key] = logValue(res.Ok());
1400
+ this._attributes[key] = logValue(res.Ok(), toLogValueCtx(this.levelHandler));
1162
1401
  } else {
1163
1402
  this.Err(res.Err());
1164
1403
  }
1165
1404
  return this;
1166
1405
  }
1167
1406
  Len(value, key = "len") {
1168
- this._attributes[key] = getLen(value);
1407
+ this._attributes[key] = getLen(value, toLogValueCtx(this.levelHandler));
1169
1408
  return this;
1170
1409
  }
1171
1410
  Hash(value, key = "hash") {
1172
- this._attributes[key] = asyncLogValue(async () => `${getLen(value).value()}:${await hash(value)}`);
1411
+ this._attributes[key] = asyncLogValue(
1412
+ async () => `${getLen(value, toLogValueCtx(this.levelHandler)).value()}:${await hash(value)}`
1413
+ );
1173
1414
  return this;
1174
1415
  }
1175
1416
  Url(url, key = "url") {
@@ -1178,7 +1419,7 @@ var LoggerImpl = class _LoggerImpl {
1178
1419
  }
1179
1420
  coerceKey(key, value) {
1180
1421
  if (typeof key === "string") {
1181
- this._attributes[key] = logValue(value);
1422
+ this._attributes[key] = logValue(value, toLogValueCtx(this.levelHandler));
1182
1423
  } else {
1183
1424
  this.Pair(key);
1184
1425
  }
@@ -1192,7 +1433,7 @@ var LoggerImpl = class _LoggerImpl {
1192
1433
  return this;
1193
1434
  }
1194
1435
  Dur(key, nsec) {
1195
- this._attributes[key] = logValue(`${nsec}ms`);
1436
+ this._attributes[key] = logValue(`${nsec}ms`, toLogValueCtx(this.levelHandler));
1196
1437
  return this;
1197
1438
  }
1198
1439
  Uint64(key, value) {
@@ -1212,11 +1453,12 @@ var LoggerImpl = class _LoggerImpl {
1212
1453
  new _LoggerImpl({
1213
1454
  logWriter: this._logWriter,
1214
1455
  sys: this._sys,
1215
- levelHandler: this._levelHandler,
1456
+ levelHandler: this.levelHandler,
1216
1457
  formatter: this._formatter,
1217
- withAttributes: __spreadValues({
1218
- module: this._attributes["module"]
1219
- }, this._withAttributes)
1458
+ withAttributes: {
1459
+ module: this._attributes["module"],
1460
+ ...this._withAttributes
1461
+ }
1220
1462
  })
1221
1463
  );
1222
1464
  }
@@ -1231,16 +1473,16 @@ var LoggerImpl = class _LoggerImpl {
1231
1473
  Msg(...args) {
1232
1474
  const fnError = this._resetAttributes(() => {
1233
1475
  var _a, _b;
1234
- const doWrite = this._levelHandler.isEnabled(
1476
+ const doWrite = this.levelHandler.isEnabled(
1235
1477
  (_a = toLogValue(this._attributes["level"])) == null ? void 0 : _a.value(),
1236
1478
  (_b = toLogValue(this._attributes["module"])) == null ? void 0 : _b.value()
1237
1479
  );
1238
- this._attributes["msg"] = logValue(args.join(" "));
1480
+ this._attributes["msg"] = logValue(args.join(" "), toLogValueCtx(this.levelHandler));
1239
1481
  const msg = this._attributes["msg"].value();
1240
1482
  if (typeof msg === "string" && !msg.trim().length) {
1241
1483
  delete this._attributes["msg"];
1242
1484
  }
1243
- let fnRet = () => this._formatter.format(__spreadValues({}, this._attributes));
1485
+ let fnRet = () => this._formatter.format({ ...this._attributes });
1244
1486
  if (doWrite) {
1245
1487
  const encoded = fnRet();
1246
1488
  this._logWriter.write(encoded);
@@ -1258,6 +1500,7 @@ var LoggerImpl = class _LoggerImpl {
1258
1500
  var WithLoggerBuilder = class {
1259
1501
  constructor(li) {
1260
1502
  this._li = li;
1503
+ this.levelHandler = li.levelHandler;
1261
1504
  }
1262
1505
  TxtEnDe() {
1263
1506
  return this._li.TxtEnDe();
@@ -1267,10 +1510,14 @@ var WithLoggerBuilder = class {
1267
1510
  return this._li;
1268
1511
  }
1269
1512
  Attributes() {
1270
- return __spreadValues({}, this._li._attributes);
1513
+ return { ...this._li._attributes };
1271
1514
  }
1272
1515
  SetExposeStack(enable) {
1273
- this._li._levelHandler.setExposeStack(enable);
1516
+ this._li.levelHandler.setExposeStack(enable);
1517
+ return this;
1518
+ }
1519
+ SetIgnoreAttribute(re) {
1520
+ this._li.levelHandler.setIgnoreAttr(re);
1274
1521
  return this;
1275
1522
  }
1276
1523
  SetFormatter(fmt) {
@@ -1278,11 +1525,11 @@ var WithLoggerBuilder = class {
1278
1525
  return this;
1279
1526
  }
1280
1527
  EnableLevel(level, ...modules) {
1281
- this._li._levelHandler.enableLevel(level, ...modules);
1528
+ this._li.levelHandler.enableLevel(level, ...modules);
1282
1529
  return this;
1283
1530
  }
1284
1531
  DisableLevel(level, ...modules) {
1285
- this._li._levelHandler.enableLevel(level, ...modules);
1532
+ this._li.levelHandler.enableLevel(level, ...modules);
1286
1533
  return this;
1287
1534
  }
1288
1535
  Module(key) {
@@ -1443,7 +1690,7 @@ var LogCollector = class {
1443
1690
  new Uint8Array(
1444
1691
  function* (res) {
1445
1692
  for (const x of res) {
1446
- yield* __yieldStar(x);
1693
+ yield* x;
1447
1694
  }
1448
1695
  }(this._bufferArr)
1449
1696
  )
@@ -1481,54 +1728,6 @@ function MockLogger(params) {
1481
1728
  };
1482
1729
  }
1483
1730
 
1484
- // src/option.ts
1485
- var Option = class _Option {
1486
- static Some(t) {
1487
- return new Some(t);
1488
- }
1489
- static None() {
1490
- return new None();
1491
- }
1492
- static Is(t) {
1493
- return t instanceof _Option;
1494
- }
1495
- IsNone() {
1496
- return this.is_none();
1497
- }
1498
- IsSome() {
1499
- return this.is_some();
1500
- }
1501
- Unwrap() {
1502
- return this.unwrap();
1503
- }
1504
- };
1505
- var Some = class extends Option {
1506
- constructor(_t) {
1507
- super();
1508
- this._t = _t;
1509
- }
1510
- is_none() {
1511
- return false;
1512
- }
1513
- is_some() {
1514
- return true;
1515
- }
1516
- unwrap() {
1517
- return this._t;
1518
- }
1519
- };
1520
- var None = class extends Option {
1521
- is_none() {
1522
- return true;
1523
- }
1524
- is_some() {
1525
- return false;
1526
- }
1527
- unwrap() {
1528
- throw new Error("None.unwrap");
1529
- }
1530
- };
1531
-
1532
1731
  // src/tracer.ts
1533
1732
  var Metric = class {
1534
1733
  constructor(path) {
@@ -1610,22 +1809,24 @@ var TraceNode = class _TraceNode {
1610
1809
  return this.ctx.parent.getRootPath(rpath.concat(this.ctx.spanId));
1611
1810
  }
1612
1811
  invokes() {
1613
- const cleanCtx = __spreadValues({}, this.ctx);
1812
+ const cleanCtx = { ...this.ctx };
1614
1813
  delete cleanCtx.parent;
1615
1814
  delete cleanCtx.time;
1616
1815
  delete cleanCtx.logger;
1617
1816
  delete cleanCtx.metrics;
1618
1817
  const spanRefs = this.metrics.toJSON.call({ map: this.metrics.spanRefs });
1619
1818
  const metricsRefs = Object.keys(spanRefs).length > 0 ? { metricRefs: spanRefs } : {};
1620
- return __spreadValues({
1819
+ return {
1621
1820
  ctx: cleanCtx,
1622
- invokations: this.invokations
1623
- }, metricsRefs);
1821
+ invokations: this.invokations,
1822
+ ...metricsRefs
1823
+ };
1624
1824
  }
1625
1825
  ctxWith(spanId, logger) {
1626
- const ctx = __spreadProps(__spreadValues({}, this.ctx), {
1826
+ const ctx = {
1827
+ ...this.ctx,
1627
1828
  spanId
1628
- });
1829
+ };
1629
1830
  if (logger) {
1630
1831
  ctx.logger = logger;
1631
1832
  }
@@ -1635,17 +1836,23 @@ var TraceNode = class _TraceNode {
1635
1836
  span(inSpanId, fn) {
1636
1837
  let ctx;
1637
1838
  if (typeof inSpanId === "string") {
1638
- ctx = __spreadProps(__spreadValues({}, this.ctx), {
1839
+ ctx = {
1840
+ ...this.ctx,
1639
1841
  spanId: inSpanId,
1640
1842
  parent: this
1641
- });
1843
+ };
1642
1844
  } else {
1643
- ctx = __spreadProps(__spreadValues(__spreadValues({}, this.ctx), inSpanId), {
1845
+ ctx = {
1846
+ ...this.ctx,
1847
+ ...inSpanId,
1644
1848
  parent: this
1645
- });
1849
+ };
1646
1850
  }
1647
1851
  if (ctx.logger) {
1648
- ctx = __spreadValues(__spreadValues({}, ctx), ctx.logger.Attributes());
1852
+ ctx = {
1853
+ ...ctx,
1854
+ ...ctx.logger.Attributes()
1855
+ };
1649
1856
  }
1650
1857
  const spanId = ctx.spanId;
1651
1858
  let spanTrace = this.childs.get(spanId);
@@ -1708,6 +1915,161 @@ function toCryptoRuntime(cryptoOpts = {}) {
1708
1915
  var VERSION = Object.keys({
1709
1916
  __packageVersion__: "xxxx"
1710
1917
  })[0];
1918
+
1919
+ // src/http_header.ts
1920
+ var HeadersImpl = class extends Headers {
1921
+ constructor(init) {
1922
+ super();
1923
+ this._headers = init;
1924
+ }
1925
+ [Symbol.iterator]() {
1926
+ return this.entries();
1927
+ }
1928
+ entries() {
1929
+ return this._headers.entries();
1930
+ }
1931
+ keys() {
1932
+ return this._headers.keys();
1933
+ }
1934
+ values() {
1935
+ return this._headers.values();
1936
+ }
1937
+ append(key, value) {
1938
+ const values = this._headers.get(key);
1939
+ if (typeof value === "undefined") {
1940
+ value = "";
1941
+ }
1942
+ if (Array.isArray(value)) {
1943
+ this._headers.set(key, [values, ...value].filter((i) => i).join(", "));
1944
+ } else {
1945
+ this._headers.set(key, [values, value].filter((i) => i).join(", "));
1946
+ }
1947
+ return this;
1948
+ }
1949
+ };
1950
+ var HttpHeader = class _HttpHeader {
1951
+ constructor() {
1952
+ this._headers = /* @__PURE__ */ new Map();
1953
+ }
1954
+ static from(headers) {
1955
+ const h = new _HttpHeader();
1956
+ if (headers) {
1957
+ if (Array.isArray(headers)) {
1958
+ for (const [k, v] of headers) {
1959
+ if (v) {
1960
+ h.Add(k, v);
1961
+ }
1962
+ }
1963
+ } else if (headers instanceof Headers) {
1964
+ for (const [k, v] of headers.entries()) {
1965
+ if (v) {
1966
+ h.Add(
1967
+ k,
1968
+ v.split(",").map((v2) => v2.trim())
1969
+ );
1970
+ }
1971
+ }
1972
+ } else {
1973
+ for (const k in headers) {
1974
+ const v = headers[k];
1975
+ if (v) {
1976
+ h.Add(k, v);
1977
+ }
1978
+ }
1979
+ }
1980
+ }
1981
+ return h;
1982
+ }
1983
+ _asStringString() {
1984
+ const ret = /* @__PURE__ */ new Map();
1985
+ for (const [key, values] of this._headers) {
1986
+ ret.set(key, values.join(", "));
1987
+ }
1988
+ return ret;
1989
+ }
1990
+ _key(key) {
1991
+ return key.toLowerCase();
1992
+ }
1993
+ Values(key) {
1994
+ const values = this._headers.get(this._key(key));
1995
+ return values || [];
1996
+ }
1997
+ Get(key) {
1998
+ const values = this._headers.get(this._key(key));
1999
+ if (values === void 0 || values.length === 0) {
2000
+ return void 0;
2001
+ }
2002
+ return values[0];
2003
+ }
2004
+ Set(key, valueOr) {
2005
+ const value = Array.isArray(valueOr) ? valueOr : [valueOr];
2006
+ this._headers.set(this._key(key), value);
2007
+ return this;
2008
+ }
2009
+ Add(key, value) {
2010
+ if (typeof value === "undefined") {
2011
+ return this;
2012
+ }
2013
+ const vs = Array.isArray(value) ? value : [value];
2014
+ const values = this._headers.get(this._key(key));
2015
+ if (values === void 0) {
2016
+ this._headers.set(this._key(key), vs);
2017
+ } else {
2018
+ values.push(...vs);
2019
+ }
2020
+ return this;
2021
+ }
2022
+ Del(ey) {
2023
+ this._headers.delete(this._key(ey));
2024
+ return this;
2025
+ }
2026
+ Items() {
2027
+ return Array.from(this._headers).filter(([_, vs]) => vs.length > 0);
2028
+ }
2029
+ SortItems() {
2030
+ return this.Items().sort(([[a]], [[b]]) => a.localeCompare(b));
2031
+ }
2032
+ Clone() {
2033
+ const clone = new _HttpHeader();
2034
+ for (const [key, values] of this._headers.entries()) {
2035
+ clone._headers.set(key, values.slice());
2036
+ }
2037
+ return clone;
2038
+ }
2039
+ AsRecordStringStringArray() {
2040
+ const obj = {};
2041
+ for (const [key, values] of this._headers.entries()) {
2042
+ obj[key] = [...values];
2043
+ }
2044
+ return obj;
2045
+ }
2046
+ AsRecordStringString() {
2047
+ const obj = {};
2048
+ for (const [key, values] of this._headers.entries()) {
2049
+ obj[key] = values.join(", ");
2050
+ }
2051
+ return obj;
2052
+ }
2053
+ AsHeaderInit() {
2054
+ const obj = {};
2055
+ for (const [key, values] of this._headers.entries()) {
2056
+ obj[key] = values[0];
2057
+ }
2058
+ return obj;
2059
+ }
2060
+ AsHeaders() {
2061
+ return new HeadersImpl(this._asStringString());
2062
+ }
2063
+ Merge(other) {
2064
+ const ret = this.Clone();
2065
+ if (other) {
2066
+ for (const [key, values] of other.Items()) {
2067
+ ret.Add(key, values);
2068
+ }
2069
+ }
2070
+ return ret;
2071
+ }
2072
+ };
1711
2073
  export {
1712
2074
  BaseSysAbstraction,
1713
2075
  BrowserEnvActions,
@@ -1715,6 +2077,8 @@ export {
1715
2077
  ConstTime,
1716
2078
  EnvImpl,
1717
2079
  Future,
2080
+ HeadersImpl,
2081
+ HttpHeader,
1718
2082
  IDMode,
1719
2083
  IdService,
1720
2084
  IsLogger,
@@ -1735,6 +2099,7 @@ export {
1735
2099
  MutableURL,
1736
2100
  None,
1737
2101
  Option,
2102
+ REQUIRED,
1738
2103
  RandomMode,
1739
2104
  RandomService,
1740
2105
  ResolveOnce,