@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.cjs CHANGED
@@ -113,6 +113,7 @@ __export(src_exports, {
113
113
  MutableURL: () => MutableURL,
114
114
  None: () => None,
115
115
  Option: () => Option,
116
+ REQUIRED: () => REQUIRED,
116
117
  RandomMode: () => RandomMode,
117
118
  RandomService: () => RandomService,
118
119
  ResolveOnce: () => ResolveOnce,
@@ -224,7 +225,16 @@ var LogValue = class {
224
225
  function asyncLogValue(val) {
225
226
  throw new Error("Not implemented");
226
227
  }
227
- function logValue(val, state = /* @__PURE__ */ new Set([Math.random()])) {
228
+ function logValue(val, ctx) {
229
+ return logValueInternal(val, __spreadProps(__spreadValues({}, ctx), {
230
+ state: ctx.state || /* @__PURE__ */ new Set([Math.random()])
231
+ }));
232
+ }
233
+ function logValueInternal(val, ctx) {
234
+ var _a, _b;
235
+ ctx = __spreadProps(__spreadValues({}, ctx), {
236
+ state: ctx.state || /* @__PURE__ */ new Set([Math.random()])
237
+ });
228
238
  switch (typeof val) {
229
239
  case "function":
230
240
  return new LogValue(val);
@@ -232,7 +242,7 @@ function logValue(val, state = /* @__PURE__ */ new Set([Math.random()])) {
232
242
  try {
233
243
  const ret = JSON.parse(val);
234
244
  if (typeof ret === "object" && ret !== null) {
235
- return logValue(ret, state);
245
+ return logValueInternal(ret, ctx);
236
246
  }
237
247
  } catch (e) {
238
248
  if (val.match(/[\n\r]/)) {
@@ -255,13 +265,15 @@ function logValue(val, state = /* @__PURE__ */ new Set([Math.random()])) {
255
265
  const decoder2 = new TextDecoder();
256
266
  const asStr = decoder2.decode(val);
257
267
  const obj = JSON.parse(asStr);
258
- return logValue(obj, state);
268
+ return logValueInternal(obj, ctx);
259
269
  } catch (e) {
260
- return logValue(bin2string(val, 512));
270
+ return logValueInternal(bin2string(val, 512), ctx);
261
271
  }
262
272
  }
263
273
  if (Array.isArray(val)) {
264
- return new LogValue(() => val.map((v) => logValue(v).value()));
274
+ return new LogValue(
275
+ () => val.map((v) => logValue(v, __spreadProps(__spreadValues({}, ctx), { state: void 0 })).value())
276
+ );
265
277
  }
266
278
  if (val instanceof Headers) {
267
279
  return new LogValue(() => Object.fromEntries(val.entries()));
@@ -272,22 +284,25 @@ function logValue(val, state = /* @__PURE__ */ new Set([Math.random()])) {
272
284
  if (val instanceof Promise) {
273
285
  return new LogValue(() => ">Promise<");
274
286
  }
275
- if (state.has(val)) {
287
+ if ((_a = ctx.state) == null ? void 0 : _a.has(val)) {
276
288
  return new LogValue(() => "...");
277
289
  }
278
- state.add(val);
290
+ (_b = ctx.state) == null ? void 0 : _b.add(val);
279
291
  if (typeof val.toJSON === "function") {
280
292
  return new LogValue(() => val.toJSON());
281
293
  }
282
294
  const res = {};
283
295
  const typedVal = val;
284
296
  for (const key in typedVal) {
297
+ if (ctx.ignoreAttr.IsSome() && ctx.ignoreAttr.unwrap().test(key)) {
298
+ continue;
299
+ }
285
300
  const element = typedVal[key];
286
301
  if (element instanceof LogValue) {
287
302
  res[key] = element;
288
303
  } else {
289
304
  if (typeof element !== "function") {
290
- res[key] = logValue(element, state);
305
+ res[key] = logValueInternal(element, ctx);
291
306
  }
292
307
  }
293
308
  }
@@ -998,6 +1013,12 @@ var Result = class _Result {
998
1013
  if (typeof t === "string") {
999
1014
  return new ResultError(new Error(t));
1000
1015
  }
1016
+ if (_Result.Is(t)) {
1017
+ if (t.is_ok()) {
1018
+ return new ResultError(new Error("Result Error is Ok"));
1019
+ }
1020
+ return t;
1021
+ }
1001
1022
  return new ResultError(t);
1002
1023
  }
1003
1024
  static Is(t) {
@@ -1133,6 +1154,7 @@ function localStripper(path, restrips, obj) {
1133
1154
  }
1134
1155
 
1135
1156
  // src/uri.ts
1157
+ var REQUIRED = 4711;
1136
1158
  function coerceKey(key, def) {
1137
1159
  if (typeof key === "object") {
1138
1160
  const keys = Object.keys(key);
@@ -1683,11 +1705,66 @@ var LogWriterStream = class {
1683
1705
  }
1684
1706
  };
1685
1707
 
1708
+ // src/option.ts
1709
+ var Option = class _Option {
1710
+ static Some(t) {
1711
+ return new Some(t);
1712
+ }
1713
+ static None() {
1714
+ return new None();
1715
+ }
1716
+ static Is(t) {
1717
+ return t instanceof _Option;
1718
+ }
1719
+ static From(t) {
1720
+ if (!t) {
1721
+ return new None();
1722
+ }
1723
+ return new Some(t);
1724
+ }
1725
+ IsNone() {
1726
+ return this.is_none();
1727
+ }
1728
+ IsSome() {
1729
+ return this.is_some();
1730
+ }
1731
+ Unwrap() {
1732
+ return this.unwrap();
1733
+ }
1734
+ };
1735
+ var Some = class extends Option {
1736
+ constructor(_t) {
1737
+ super();
1738
+ this._t = _t;
1739
+ }
1740
+ is_none() {
1741
+ return false;
1742
+ }
1743
+ is_some() {
1744
+ return true;
1745
+ }
1746
+ unwrap() {
1747
+ return this._t;
1748
+ }
1749
+ };
1750
+ var None = class extends Option {
1751
+ is_none() {
1752
+ return true;
1753
+ }
1754
+ is_some() {
1755
+ return false;
1756
+ }
1757
+ unwrap() {
1758
+ throw new Error("None.unwrap");
1759
+ }
1760
+ };
1761
+
1686
1762
  // src/log-level-impl.ts
1687
1763
  var LevelHandlerImpl = class {
1688
1764
  constructor() {
1689
1765
  this._globalLevels = /* @__PURE__ */ new Set(["info" /* INFO */, "error" /* ERROR */, "warn" /* WARN */]);
1690
1766
  this._modules = /* @__PURE__ */ new Map();
1767
+ this.ignoreAttr = Option.Some(/^_/);
1691
1768
  this.isStackExposed = false;
1692
1769
  }
1693
1770
  enableLevel(level, ...modules) {
@@ -1719,6 +1796,9 @@ var LevelHandlerImpl = class {
1719
1796
  setExposeStack(enable) {
1720
1797
  this.isStackExposed = !!enable;
1721
1798
  }
1799
+ setIgnoreAttr(re) {
1800
+ this.ignoreAttr = Option.From(re);
1801
+ }
1722
1802
  forModules(level, fnAction, ...modules) {
1723
1803
  for (const m of modules.flat()) {
1724
1804
  if (typeof m !== "string") {
@@ -1765,20 +1845,20 @@ function LevelHandlerSingleton() {
1765
1845
  }
1766
1846
 
1767
1847
  // src/logger-impl.ts
1768
- function getLen(value) {
1848
+ function getLen(value, lvs) {
1769
1849
  if (Array.isArray(value)) {
1770
- return logValue(() => value.length);
1850
+ return logValue(() => value.length, lvs);
1771
1851
  } else if (typeof value === "string") {
1772
- return logValue(() => value.length);
1852
+ return logValue(() => value.length, lvs);
1773
1853
  } else if (typeof value === "object" && value !== null) {
1774
1854
  if (typeof value.size === "number") {
1775
- return logValue(() => value.size);
1855
+ return logValue(() => value.size, lvs);
1776
1856
  } else if (typeof value.length === "number") {
1777
- return logValue(() => value.length);
1857
+ return logValue(() => value.length, lvs);
1778
1858
  }
1779
- return logValue(() => Object.keys(value).length);
1859
+ return logValue(() => Object.keys(value).length, lvs);
1780
1860
  }
1781
- return logValue(() => -1);
1861
+ return logValue(() => -1, lvs);
1782
1862
  }
1783
1863
  function hash(value) {
1784
1864
  return "not implemented";
@@ -1813,6 +1893,11 @@ var YAMLFormatter = class {
1813
1893
  return this._txtEnDe.encode("---\n" + import_yaml.default.stringify(attr, null, this._space) + "\n");
1814
1894
  }
1815
1895
  };
1896
+ function toLogValueCtx(lvh) {
1897
+ return {
1898
+ ignoreAttr: lvh.ignoreAttr
1899
+ };
1900
+ }
1816
1901
  var LoggerImpl = class _LoggerImpl {
1817
1902
  // readonly _id: string = "logger-" + Math.random().toString(36)
1818
1903
  constructor(params) {
@@ -1862,9 +1947,9 @@ var LoggerImpl = class _LoggerImpl {
1862
1947
  }
1863
1948
  this._attributes = __spreadValues({}, this._withAttributes);
1864
1949
  if (params.levelHandler) {
1865
- this._levelHandler = params.levelHandler;
1950
+ this.levelHandler = params.levelHandler;
1866
1951
  } else {
1867
- this._levelHandler = LevelHandlerSingleton();
1952
+ this.levelHandler = LevelHandlerSingleton();
1868
1953
  }
1869
1954
  }
1870
1955
  TxtEnDe() {
@@ -1874,25 +1959,29 @@ var LoggerImpl = class _LoggerImpl {
1874
1959
  return JSON.parse(JSON.stringify(this._attributes, null));
1875
1960
  }
1876
1961
  SetExposeStack(enable) {
1877
- this._levelHandler.setExposeStack(enable);
1962
+ this.levelHandler.setExposeStack(enable);
1878
1963
  return this;
1879
1964
  }
1880
1965
  EnableLevel(level, ...modules) {
1881
- this._levelHandler.enableLevel(level, ...modules);
1966
+ this.levelHandler.enableLevel(level, ...modules);
1882
1967
  return this;
1883
1968
  }
1884
1969
  DisableLevel(level, ...modules) {
1885
- this._levelHandler.disableLevel(level, ...modules);
1970
+ this.levelHandler.disableLevel(level, ...modules);
1886
1971
  return this;
1887
1972
  }
1888
1973
  Module(key) {
1889
- this._attributes["module"] = logValue(key);
1890
- this._withAttributes["module"] = logValue(key);
1974
+ this._attributes["module"] = logValue(key, toLogValueCtx(this.levelHandler));
1975
+ this._withAttributes["module"] = logValue(key, toLogValueCtx(this.levelHandler));
1891
1976
  return this;
1892
1977
  }
1893
1978
  // if the string is "*" it will enable for all modules
1894
1979
  SetDebug(...modules) {
1895
- this._levelHandler.setDebug(...modules);
1980
+ this.levelHandler.setDebug(...modules);
1981
+ return this;
1982
+ }
1983
+ SetIgnoreAttribute(re) {
1984
+ this.levelHandler.setIgnoreAttr(re);
1896
1985
  return this;
1897
1986
  }
1898
1987
  SetFormatter(formatter) {
@@ -1900,57 +1989,63 @@ var LoggerImpl = class _LoggerImpl {
1900
1989
  return this;
1901
1990
  }
1902
1991
  Timestamp() {
1903
- this._attributes["ts"] = logValue(() => this._sys.Time().Now().toISOString());
1992
+ this._attributes["ts"] = logValue(() => this._sys.Time().Now().toISOString(), toLogValueCtx(this.levelHandler));
1904
1993
  return this;
1905
1994
  }
1906
1995
  Warn() {
1907
- this._attributes["level"] = logValue("warn" /* WARN */);
1996
+ this._attributes["level"] = logValue("warn" /* WARN */, toLogValueCtx(this.levelHandler));
1908
1997
  return this;
1909
1998
  }
1910
1999
  Log() {
1911
2000
  return this;
1912
2001
  }
1913
2002
  Debug() {
1914
- this._attributes["level"] = logValue("debug" /* DEBUG */);
2003
+ this._attributes["level"] = logValue("debug" /* DEBUG */, toLogValueCtx(this.levelHandler));
1915
2004
  return this;
1916
2005
  }
1917
2006
  Error() {
1918
- this._attributes["level"] = logValue("error" /* ERROR */);
2007
+ this._attributes["level"] = logValue("error" /* ERROR */, toLogValueCtx(this.levelHandler));
1919
2008
  return this;
1920
2009
  }
1921
2010
  Info() {
1922
- this._attributes["level"] = logValue("info" /* INFO */);
2011
+ this._attributes["level"] = logValue("info" /* INFO */, toLogValueCtx(this.levelHandler));
1923
2012
  return this;
1924
2013
  }
1925
2014
  Err(err) {
1926
2015
  var _a;
2016
+ let key = "error";
1927
2017
  if (Result.Is(err)) {
1928
2018
  if (err.isOk()) {
1929
- this.Result("noerror", err);
2019
+ key = "noerror";
2020
+ err = err.Ok();
1930
2021
  } else {
1931
- this.Result("error", err);
2022
+ err = err.Err();
1932
2023
  }
1933
- } else if (err instanceof Error) {
1934
- this._attributes["error"] = logValue(err.message);
1935
- if (this._levelHandler.isStackExposed) {
1936
- this._attributes["stack"] = logValue((_a = err.stack) == null ? void 0 : _a.split("\n").map((s) => s.trim()));
2024
+ }
2025
+ if (err instanceof Error) {
2026
+ this._attributes[key] = logValue(err.message, toLogValueCtx(this.levelHandler));
2027
+ if (this.levelHandler.isStackExposed) {
2028
+ this._attributes["stack"] = logValue(
2029
+ (_a = err.stack) == null ? void 0 : _a.split("\n").map((s) => s.trim()),
2030
+ toLogValueCtx(this.levelHandler)
2031
+ );
1937
2032
  }
1938
2033
  } else {
1939
- this._attributes["error"] = logValue("" + err);
2034
+ this.Any(key, err);
1940
2035
  }
1941
2036
  return this;
1942
2037
  }
1943
2038
  WithLevel(l) {
1944
- this._attributes["level"] = logValue(l);
2039
+ this._attributes["level"] = logValue(l, toLogValueCtx(this.levelHandler));
1945
2040
  return this;
1946
2041
  }
1947
2042
  Ref(key, action) {
1948
2043
  if (typeof action === "function") {
1949
- this._attributes[key] = logValue(action);
2044
+ this._attributes[key] = logValue(action, toLogValueCtx(this.levelHandler));
1950
2045
  } else if (typeof action.toString === "function") {
1951
- this._attributes[key] = logValue(() => action.toString());
2046
+ this._attributes[key] = logValue(() => action.toString(), toLogValueCtx(this.levelHandler));
1952
2047
  } else {
1953
- this._attributes[key] = logValue("INVALID REF");
2048
+ this._attributes[key] = logValue("INVALID REF", toLogValueCtx(this.levelHandler));
1954
2049
  }
1955
2050
  return this;
1956
2051
  }
@@ -2000,18 +2095,20 @@ var LoggerImpl = class _LoggerImpl {
2000
2095
  }
2001
2096
  Result(key, res) {
2002
2097
  if (res.isOk()) {
2003
- this._attributes[key] = logValue(res.Ok());
2098
+ this._attributes[key] = logValue(res.Ok(), toLogValueCtx(this.levelHandler));
2004
2099
  } else {
2005
2100
  this.Err(res.Err());
2006
2101
  }
2007
2102
  return this;
2008
2103
  }
2009
2104
  Len(value, key = "len") {
2010
- this._attributes[key] = getLen(value);
2105
+ this._attributes[key] = getLen(value, toLogValueCtx(this.levelHandler));
2011
2106
  return this;
2012
2107
  }
2013
2108
  Hash(value, key = "hash") {
2014
- this._attributes[key] = asyncLogValue(async () => `${getLen(value).value()}:${await hash(value)}`);
2109
+ this._attributes[key] = asyncLogValue(
2110
+ async () => `${getLen(value, toLogValueCtx(this.levelHandler)).value()}:${await hash(value)}`
2111
+ );
2015
2112
  return this;
2016
2113
  }
2017
2114
  Url(url, key = "url") {
@@ -2020,7 +2117,7 @@ var LoggerImpl = class _LoggerImpl {
2020
2117
  }
2021
2118
  coerceKey(key, value) {
2022
2119
  if (typeof key === "string") {
2023
- this._attributes[key] = logValue(value);
2120
+ this._attributes[key] = logValue(value, toLogValueCtx(this.levelHandler));
2024
2121
  } else {
2025
2122
  this.Pair(key);
2026
2123
  }
@@ -2034,7 +2131,7 @@ var LoggerImpl = class _LoggerImpl {
2034
2131
  return this;
2035
2132
  }
2036
2133
  Dur(key, nsec) {
2037
- this._attributes[key] = logValue(`${nsec}ms`);
2134
+ this._attributes[key] = logValue(`${nsec}ms`, toLogValueCtx(this.levelHandler));
2038
2135
  return this;
2039
2136
  }
2040
2137
  Uint64(key, value) {
@@ -2054,7 +2151,7 @@ var LoggerImpl = class _LoggerImpl {
2054
2151
  new _LoggerImpl({
2055
2152
  logWriter: this._logWriter,
2056
2153
  sys: this._sys,
2057
- levelHandler: this._levelHandler,
2154
+ levelHandler: this.levelHandler,
2058
2155
  formatter: this._formatter,
2059
2156
  withAttributes: __spreadValues({
2060
2157
  module: this._attributes["module"]
@@ -2073,11 +2170,11 @@ var LoggerImpl = class _LoggerImpl {
2073
2170
  Msg(...args) {
2074
2171
  const fnError = this._resetAttributes(() => {
2075
2172
  var _a, _b;
2076
- const doWrite = this._levelHandler.isEnabled(
2173
+ const doWrite = this.levelHandler.isEnabled(
2077
2174
  (_a = toLogValue(this._attributes["level"])) == null ? void 0 : _a.value(),
2078
2175
  (_b = toLogValue(this._attributes["module"])) == null ? void 0 : _b.value()
2079
2176
  );
2080
- this._attributes["msg"] = logValue(args.join(" "));
2177
+ this._attributes["msg"] = logValue(args.join(" "), toLogValueCtx(this.levelHandler));
2081
2178
  const msg = this._attributes["msg"].value();
2082
2179
  if (typeof msg === "string" && !msg.trim().length) {
2083
2180
  delete this._attributes["msg"];
@@ -2100,6 +2197,7 @@ var LoggerImpl = class _LoggerImpl {
2100
2197
  var WithLoggerBuilder = class {
2101
2198
  constructor(li) {
2102
2199
  this._li = li;
2200
+ this.levelHandler = li.levelHandler;
2103
2201
  }
2104
2202
  TxtEnDe() {
2105
2203
  return this._li.TxtEnDe();
@@ -2112,7 +2210,11 @@ var WithLoggerBuilder = class {
2112
2210
  return __spreadValues({}, this._li._attributes);
2113
2211
  }
2114
2212
  SetExposeStack(enable) {
2115
- this._li._levelHandler.setExposeStack(enable);
2213
+ this._li.levelHandler.setExposeStack(enable);
2214
+ return this;
2215
+ }
2216
+ SetIgnoreAttribute(re) {
2217
+ this._li.levelHandler.setIgnoreAttr(re);
2116
2218
  return this;
2117
2219
  }
2118
2220
  SetFormatter(fmt) {
@@ -2120,11 +2222,11 @@ var WithLoggerBuilder = class {
2120
2222
  return this;
2121
2223
  }
2122
2224
  EnableLevel(level, ...modules) {
2123
- this._li._levelHandler.enableLevel(level, ...modules);
2225
+ this._li.levelHandler.enableLevel(level, ...modules);
2124
2226
  return this;
2125
2227
  }
2126
2228
  DisableLevel(level, ...modules) {
2127
- this._li._levelHandler.enableLevel(level, ...modules);
2229
+ this._li.levelHandler.enableLevel(level, ...modules);
2128
2230
  return this;
2129
2231
  }
2130
2232
  Module(key) {
@@ -2349,54 +2451,6 @@ function MockLogger(params) {
2349
2451
  };
2350
2452
  }
2351
2453
 
2352
- // src/option.ts
2353
- var Option = class _Option {
2354
- static Some(t) {
2355
- return new Some(t);
2356
- }
2357
- static None() {
2358
- return new None();
2359
- }
2360
- static Is(t) {
2361
- return t instanceof _Option;
2362
- }
2363
- IsNone() {
2364
- return this.is_none();
2365
- }
2366
- IsSome() {
2367
- return this.is_some();
2368
- }
2369
- Unwrap() {
2370
- return this.unwrap();
2371
- }
2372
- };
2373
- var Some = class extends Option {
2374
- constructor(_t) {
2375
- super();
2376
- this._t = _t;
2377
- }
2378
- is_none() {
2379
- return false;
2380
- }
2381
- is_some() {
2382
- return true;
2383
- }
2384
- unwrap() {
2385
- return this._t;
2386
- }
2387
- };
2388
- var None = class extends Option {
2389
- is_none() {
2390
- return true;
2391
- }
2392
- is_some() {
2393
- return false;
2394
- }
2395
- unwrap() {
2396
- throw new Error("None.unwrap");
2397
- }
2398
- };
2399
-
2400
2454
  // src/tracer.ts
2401
2455
  var Metric = class {
2402
2456
  constructor(path) {
@@ -2803,6 +2857,7 @@ function uint8array2stream(str) {
2803
2857
  MutableURL,
2804
2858
  None,
2805
2859
  Option,
2860
+ REQUIRED,
2806
2861
  RandomMode,
2807
2862
  RandomService,
2808
2863
  ResolveOnce,