@adviser/cement 0.2.40 → 0.2.41

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/index.js CHANGED
@@ -1,3 +1,8 @@
1
+ import {
2
+ ConsoleWriterStream,
3
+ FanoutWriteStream,
4
+ utils_exports
5
+ } from "./chunk-USQXEZHL.js";
1
6
  import {
2
7
  WebSysAbstraction
3
8
  } from "./chunk-W2GV5KXV.js";
@@ -26,11 +31,6 @@ import {
26
31
  WrapperSysAbstraction,
27
32
  envFactory
28
33
  } from "./chunk-F5W6VELE.js";
29
- import {
30
- ConsoleWriterStream,
31
- FanoutWriteStream,
32
- utils_exports
33
- } from "./chunk-USQXEZHL.js";
34
34
  import {
35
35
  Utf8EnDecoder,
36
36
  Utf8EnDecoderSingleton,
@@ -114,7 +114,16 @@ var LogValue = class {
114
114
  function asyncLogValue(val) {
115
115
  throw new Error("Not implemented");
116
116
  }
117
- function logValue(val, state = /* @__PURE__ */ new Set([Math.random()])) {
117
+ function logValue(val, ctx) {
118
+ return logValueInternal(val, __spreadProps(__spreadValues({}, ctx), {
119
+ state: ctx.state || /* @__PURE__ */ new Set([Math.random()])
120
+ }));
121
+ }
122
+ function logValueInternal(val, ctx) {
123
+ var _a, _b;
124
+ ctx = __spreadProps(__spreadValues({}, ctx), {
125
+ state: ctx.state || /* @__PURE__ */ new Set([Math.random()])
126
+ });
118
127
  switch (typeof val) {
119
128
  case "function":
120
129
  return new LogValue(val);
@@ -122,7 +131,7 @@ function logValue(val, state = /* @__PURE__ */ new Set([Math.random()])) {
122
131
  try {
123
132
  const ret = JSON.parse(val);
124
133
  if (typeof ret === "object" && ret !== null) {
125
- return logValue(ret, state);
134
+ return logValueInternal(ret, ctx);
126
135
  }
127
136
  } catch (e) {
128
137
  if (val.match(/[\n\r]/)) {
@@ -145,13 +154,15 @@ function logValue(val, state = /* @__PURE__ */ new Set([Math.random()])) {
145
154
  const decoder = new TextDecoder();
146
155
  const asStr = decoder.decode(val);
147
156
  const obj = JSON.parse(asStr);
148
- return logValue(obj, state);
157
+ return logValueInternal(obj, ctx);
149
158
  } catch (e) {
150
- return logValue(bin2string(val, 512));
159
+ return logValueInternal(bin2string(val, 512), ctx);
151
160
  }
152
161
  }
153
162
  if (Array.isArray(val)) {
154
- return new LogValue(() => val.map((v) => logValue(v).value()));
163
+ return new LogValue(
164
+ () => val.map((v) => logValue(v, __spreadProps(__spreadValues({}, ctx), { state: void 0 })).value())
165
+ );
155
166
  }
156
167
  if (val instanceof Headers) {
157
168
  return new LogValue(() => Object.fromEntries(val.entries()));
@@ -162,22 +173,25 @@ function logValue(val, state = /* @__PURE__ */ new Set([Math.random()])) {
162
173
  if (val instanceof Promise) {
163
174
  return new LogValue(() => ">Promise<");
164
175
  }
165
- if (state.has(val)) {
176
+ if ((_a = ctx.state) == null ? void 0 : _a.has(val)) {
166
177
  return new LogValue(() => "...");
167
178
  }
168
- state.add(val);
179
+ (_b = ctx.state) == null ? void 0 : _b.add(val);
169
180
  if (typeof val.toJSON === "function") {
170
181
  return new LogValue(() => val.toJSON());
171
182
  }
172
183
  const res = {};
173
184
  const typedVal = val;
174
185
  for (const key in typedVal) {
186
+ if (ctx.ignoreAttr.IsSome() && ctx.ignoreAttr.unwrap().test(key)) {
187
+ continue;
188
+ }
175
189
  const element = typedVal[key];
176
190
  if (element instanceof LogValue) {
177
191
  res[key] = element;
178
192
  } else {
179
193
  if (typeof element !== "function") {
180
- res[key] = logValue(element, state);
194
+ res[key] = logValueInternal(element, ctx);
181
195
  }
182
196
  }
183
197
  }
@@ -220,6 +234,12 @@ var Result = class _Result {
220
234
  if (typeof t === "string") {
221
235
  return new ResultError(new Error(t));
222
236
  }
237
+ if (_Result.Is(t)) {
238
+ if (t.is_ok()) {
239
+ return new ResultError(new Error("Result Error is Ok"));
240
+ }
241
+ return t;
242
+ }
223
243
  return new ResultError(t);
224
244
  }
225
245
  static Is(t) {
@@ -355,6 +375,7 @@ function localStripper(path, restrips, obj) {
355
375
  }
356
376
 
357
377
  // src/uri.ts
378
+ var REQUIRED = 4711;
358
379
  function coerceKey(key, def) {
359
380
  if (typeof key === "object") {
360
381
  const keys = Object.keys(key);
@@ -841,11 +862,66 @@ var LogWriterStream = class {
841
862
  }
842
863
  };
843
864
 
865
+ // src/option.ts
866
+ var Option = class _Option {
867
+ static Some(t) {
868
+ return new Some(t);
869
+ }
870
+ static None() {
871
+ return new None();
872
+ }
873
+ static Is(t) {
874
+ return t instanceof _Option;
875
+ }
876
+ static From(t) {
877
+ if (!t) {
878
+ return new None();
879
+ }
880
+ return new Some(t);
881
+ }
882
+ IsNone() {
883
+ return this.is_none();
884
+ }
885
+ IsSome() {
886
+ return this.is_some();
887
+ }
888
+ Unwrap() {
889
+ return this.unwrap();
890
+ }
891
+ };
892
+ var Some = class extends Option {
893
+ constructor(_t) {
894
+ super();
895
+ this._t = _t;
896
+ }
897
+ is_none() {
898
+ return false;
899
+ }
900
+ is_some() {
901
+ return true;
902
+ }
903
+ unwrap() {
904
+ return this._t;
905
+ }
906
+ };
907
+ var None = class extends Option {
908
+ is_none() {
909
+ return true;
910
+ }
911
+ is_some() {
912
+ return false;
913
+ }
914
+ unwrap() {
915
+ throw new Error("None.unwrap");
916
+ }
917
+ };
918
+
844
919
  // src/log-level-impl.ts
845
920
  var LevelHandlerImpl = class {
846
921
  constructor() {
847
922
  this._globalLevels = /* @__PURE__ */ new Set(["info" /* INFO */, "error" /* ERROR */, "warn" /* WARN */]);
848
923
  this._modules = /* @__PURE__ */ new Map();
924
+ this.ignoreAttr = Option.Some(/^_/);
849
925
  this.isStackExposed = false;
850
926
  }
851
927
  enableLevel(level, ...modules) {
@@ -877,6 +953,9 @@ var LevelHandlerImpl = class {
877
953
  setExposeStack(enable) {
878
954
  this.isStackExposed = !!enable;
879
955
  }
956
+ setIgnoreAttr(re) {
957
+ this.ignoreAttr = Option.From(re);
958
+ }
880
959
  forModules(level, fnAction, ...modules) {
881
960
  for (const m of modules.flat()) {
882
961
  if (typeof m !== "string") {
@@ -923,20 +1002,20 @@ function LevelHandlerSingleton() {
923
1002
  }
924
1003
 
925
1004
  // src/logger-impl.ts
926
- function getLen(value) {
1005
+ function getLen(value, lvs) {
927
1006
  if (Array.isArray(value)) {
928
- return logValue(() => value.length);
1007
+ return logValue(() => value.length, lvs);
929
1008
  } else if (typeof value === "string") {
930
- return logValue(() => value.length);
1009
+ return logValue(() => value.length, lvs);
931
1010
  } else if (typeof value === "object" && value !== null) {
932
1011
  if (typeof value.size === "number") {
933
- return logValue(() => value.size);
1012
+ return logValue(() => value.size, lvs);
934
1013
  } else if (typeof value.length === "number") {
935
- return logValue(() => value.length);
1014
+ return logValue(() => value.length, lvs);
936
1015
  }
937
- return logValue(() => Object.keys(value).length);
1016
+ return logValue(() => Object.keys(value).length, lvs);
938
1017
  }
939
- return logValue(() => -1);
1018
+ return logValue(() => -1, lvs);
940
1019
  }
941
1020
  function hash(value) {
942
1021
  return "not implemented";
@@ -971,6 +1050,11 @@ var YAMLFormatter = class {
971
1050
  return this._txtEnDe.encode("---\n" + YAML.stringify(attr, null, this._space) + "\n");
972
1051
  }
973
1052
  };
1053
+ function toLogValueCtx(lvh) {
1054
+ return {
1055
+ ignoreAttr: lvh.ignoreAttr
1056
+ };
1057
+ }
974
1058
  var LoggerImpl = class _LoggerImpl {
975
1059
  // readonly _id: string = "logger-" + Math.random().toString(36)
976
1060
  constructor(params) {
@@ -1020,9 +1104,9 @@ var LoggerImpl = class _LoggerImpl {
1020
1104
  }
1021
1105
  this._attributes = __spreadValues({}, this._withAttributes);
1022
1106
  if (params.levelHandler) {
1023
- this._levelHandler = params.levelHandler;
1107
+ this.levelHandler = params.levelHandler;
1024
1108
  } else {
1025
- this._levelHandler = LevelHandlerSingleton();
1109
+ this.levelHandler = LevelHandlerSingleton();
1026
1110
  }
1027
1111
  }
1028
1112
  TxtEnDe() {
@@ -1032,25 +1116,29 @@ var LoggerImpl = class _LoggerImpl {
1032
1116
  return JSON.parse(JSON.stringify(this._attributes, null));
1033
1117
  }
1034
1118
  SetExposeStack(enable) {
1035
- this._levelHandler.setExposeStack(enable);
1119
+ this.levelHandler.setExposeStack(enable);
1036
1120
  return this;
1037
1121
  }
1038
1122
  EnableLevel(level, ...modules) {
1039
- this._levelHandler.enableLevel(level, ...modules);
1123
+ this.levelHandler.enableLevel(level, ...modules);
1040
1124
  return this;
1041
1125
  }
1042
1126
  DisableLevel(level, ...modules) {
1043
- this._levelHandler.disableLevel(level, ...modules);
1127
+ this.levelHandler.disableLevel(level, ...modules);
1044
1128
  return this;
1045
1129
  }
1046
1130
  Module(key) {
1047
- this._attributes["module"] = logValue(key);
1048
- this._withAttributes["module"] = logValue(key);
1131
+ this._attributes["module"] = logValue(key, toLogValueCtx(this.levelHandler));
1132
+ this._withAttributes["module"] = logValue(key, toLogValueCtx(this.levelHandler));
1049
1133
  return this;
1050
1134
  }
1051
1135
  // if the string is "*" it will enable for all modules
1052
1136
  SetDebug(...modules) {
1053
- this._levelHandler.setDebug(...modules);
1137
+ this.levelHandler.setDebug(...modules);
1138
+ return this;
1139
+ }
1140
+ SetIgnoreAttribute(re) {
1141
+ this.levelHandler.setIgnoreAttr(re);
1054
1142
  return this;
1055
1143
  }
1056
1144
  SetFormatter(formatter) {
@@ -1058,57 +1146,63 @@ var LoggerImpl = class _LoggerImpl {
1058
1146
  return this;
1059
1147
  }
1060
1148
  Timestamp() {
1061
- this._attributes["ts"] = logValue(() => this._sys.Time().Now().toISOString());
1149
+ this._attributes["ts"] = logValue(() => this._sys.Time().Now().toISOString(), toLogValueCtx(this.levelHandler));
1062
1150
  return this;
1063
1151
  }
1064
1152
  Warn() {
1065
- this._attributes["level"] = logValue("warn" /* WARN */);
1153
+ this._attributes["level"] = logValue("warn" /* WARN */, toLogValueCtx(this.levelHandler));
1066
1154
  return this;
1067
1155
  }
1068
1156
  Log() {
1069
1157
  return this;
1070
1158
  }
1071
1159
  Debug() {
1072
- this._attributes["level"] = logValue("debug" /* DEBUG */);
1160
+ this._attributes["level"] = logValue("debug" /* DEBUG */, toLogValueCtx(this.levelHandler));
1073
1161
  return this;
1074
1162
  }
1075
1163
  Error() {
1076
- this._attributes["level"] = logValue("error" /* ERROR */);
1164
+ this._attributes["level"] = logValue("error" /* ERROR */, toLogValueCtx(this.levelHandler));
1077
1165
  return this;
1078
1166
  }
1079
1167
  Info() {
1080
- this._attributes["level"] = logValue("info" /* INFO */);
1168
+ this._attributes["level"] = logValue("info" /* INFO */, toLogValueCtx(this.levelHandler));
1081
1169
  return this;
1082
1170
  }
1083
1171
  Err(err) {
1084
1172
  var _a;
1173
+ let key = "error";
1085
1174
  if (Result.Is(err)) {
1086
1175
  if (err.isOk()) {
1087
- this.Result("noerror", err);
1176
+ key = "noerror";
1177
+ err = err.Ok();
1088
1178
  } else {
1089
- this.Result("error", err);
1179
+ err = err.Err();
1090
1180
  }
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()));
1181
+ }
1182
+ if (err instanceof Error) {
1183
+ this._attributes[key] = logValue(err.message, toLogValueCtx(this.levelHandler));
1184
+ if (this.levelHandler.isStackExposed) {
1185
+ this._attributes["stack"] = logValue(
1186
+ (_a = err.stack) == null ? void 0 : _a.split("\n").map((s) => s.trim()),
1187
+ toLogValueCtx(this.levelHandler)
1188
+ );
1095
1189
  }
1096
1190
  } else {
1097
- this._attributes["error"] = logValue("" + err);
1191
+ this.Any(key, err);
1098
1192
  }
1099
1193
  return this;
1100
1194
  }
1101
1195
  WithLevel(l) {
1102
- this._attributes["level"] = logValue(l);
1196
+ this._attributes["level"] = logValue(l, toLogValueCtx(this.levelHandler));
1103
1197
  return this;
1104
1198
  }
1105
1199
  Ref(key, action) {
1106
1200
  if (typeof action === "function") {
1107
- this._attributes[key] = logValue(action);
1201
+ this._attributes[key] = logValue(action, toLogValueCtx(this.levelHandler));
1108
1202
  } else if (typeof action.toString === "function") {
1109
- this._attributes[key] = logValue(() => action.toString());
1203
+ this._attributes[key] = logValue(() => action.toString(), toLogValueCtx(this.levelHandler));
1110
1204
  } else {
1111
- this._attributes[key] = logValue("INVALID REF");
1205
+ this._attributes[key] = logValue("INVALID REF", toLogValueCtx(this.levelHandler));
1112
1206
  }
1113
1207
  return this;
1114
1208
  }
@@ -1158,18 +1252,20 @@ var LoggerImpl = class _LoggerImpl {
1158
1252
  }
1159
1253
  Result(key, res) {
1160
1254
  if (res.isOk()) {
1161
- this._attributes[key] = logValue(res.Ok());
1255
+ this._attributes[key] = logValue(res.Ok(), toLogValueCtx(this.levelHandler));
1162
1256
  } else {
1163
1257
  this.Err(res.Err());
1164
1258
  }
1165
1259
  return this;
1166
1260
  }
1167
1261
  Len(value, key = "len") {
1168
- this._attributes[key] = getLen(value);
1262
+ this._attributes[key] = getLen(value, toLogValueCtx(this.levelHandler));
1169
1263
  return this;
1170
1264
  }
1171
1265
  Hash(value, key = "hash") {
1172
- this._attributes[key] = asyncLogValue(async () => `${getLen(value).value()}:${await hash(value)}`);
1266
+ this._attributes[key] = asyncLogValue(
1267
+ async () => `${getLen(value, toLogValueCtx(this.levelHandler)).value()}:${await hash(value)}`
1268
+ );
1173
1269
  return this;
1174
1270
  }
1175
1271
  Url(url, key = "url") {
@@ -1178,7 +1274,7 @@ var LoggerImpl = class _LoggerImpl {
1178
1274
  }
1179
1275
  coerceKey(key, value) {
1180
1276
  if (typeof key === "string") {
1181
- this._attributes[key] = logValue(value);
1277
+ this._attributes[key] = logValue(value, toLogValueCtx(this.levelHandler));
1182
1278
  } else {
1183
1279
  this.Pair(key);
1184
1280
  }
@@ -1192,7 +1288,7 @@ var LoggerImpl = class _LoggerImpl {
1192
1288
  return this;
1193
1289
  }
1194
1290
  Dur(key, nsec) {
1195
- this._attributes[key] = logValue(`${nsec}ms`);
1291
+ this._attributes[key] = logValue(`${nsec}ms`, toLogValueCtx(this.levelHandler));
1196
1292
  return this;
1197
1293
  }
1198
1294
  Uint64(key, value) {
@@ -1212,7 +1308,7 @@ var LoggerImpl = class _LoggerImpl {
1212
1308
  new _LoggerImpl({
1213
1309
  logWriter: this._logWriter,
1214
1310
  sys: this._sys,
1215
- levelHandler: this._levelHandler,
1311
+ levelHandler: this.levelHandler,
1216
1312
  formatter: this._formatter,
1217
1313
  withAttributes: __spreadValues({
1218
1314
  module: this._attributes["module"]
@@ -1231,11 +1327,11 @@ var LoggerImpl = class _LoggerImpl {
1231
1327
  Msg(...args) {
1232
1328
  const fnError = this._resetAttributes(() => {
1233
1329
  var _a, _b;
1234
- const doWrite = this._levelHandler.isEnabled(
1330
+ const doWrite = this.levelHandler.isEnabled(
1235
1331
  (_a = toLogValue(this._attributes["level"])) == null ? void 0 : _a.value(),
1236
1332
  (_b = toLogValue(this._attributes["module"])) == null ? void 0 : _b.value()
1237
1333
  );
1238
- this._attributes["msg"] = logValue(args.join(" "));
1334
+ this._attributes["msg"] = logValue(args.join(" "), toLogValueCtx(this.levelHandler));
1239
1335
  const msg = this._attributes["msg"].value();
1240
1336
  if (typeof msg === "string" && !msg.trim().length) {
1241
1337
  delete this._attributes["msg"];
@@ -1258,6 +1354,7 @@ var LoggerImpl = class _LoggerImpl {
1258
1354
  var WithLoggerBuilder = class {
1259
1355
  constructor(li) {
1260
1356
  this._li = li;
1357
+ this.levelHandler = li.levelHandler;
1261
1358
  }
1262
1359
  TxtEnDe() {
1263
1360
  return this._li.TxtEnDe();
@@ -1270,7 +1367,11 @@ var WithLoggerBuilder = class {
1270
1367
  return __spreadValues({}, this._li._attributes);
1271
1368
  }
1272
1369
  SetExposeStack(enable) {
1273
- this._li._levelHandler.setExposeStack(enable);
1370
+ this._li.levelHandler.setExposeStack(enable);
1371
+ return this;
1372
+ }
1373
+ SetIgnoreAttribute(re) {
1374
+ this._li.levelHandler.setIgnoreAttr(re);
1274
1375
  return this;
1275
1376
  }
1276
1377
  SetFormatter(fmt) {
@@ -1278,11 +1379,11 @@ var WithLoggerBuilder = class {
1278
1379
  return this;
1279
1380
  }
1280
1381
  EnableLevel(level, ...modules) {
1281
- this._li._levelHandler.enableLevel(level, ...modules);
1382
+ this._li.levelHandler.enableLevel(level, ...modules);
1282
1383
  return this;
1283
1384
  }
1284
1385
  DisableLevel(level, ...modules) {
1285
- this._li._levelHandler.enableLevel(level, ...modules);
1386
+ this._li.levelHandler.enableLevel(level, ...modules);
1286
1387
  return this;
1287
1388
  }
1288
1389
  Module(key) {
@@ -1481,54 +1582,6 @@ function MockLogger(params) {
1481
1582
  };
1482
1583
  }
1483
1584
 
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
1585
  // src/tracer.ts
1533
1586
  var Metric = class {
1534
1587
  constructor(path) {
@@ -1735,6 +1788,7 @@ export {
1735
1788
  MutableURL,
1736
1789
  None,
1737
1790
  Option,
1791
+ REQUIRED,
1738
1792
  RandomMode,
1739
1793
  RandomService,
1740
1794
  ResolveOnce,