@adviser/cement 0.2.27 → 0.2.29

Sign up to get free protection for your applications and to get access to all the features.
Files changed (319) hide show
  1. package/{base-sys-abstraction-C9WW3w57.d.cts → base-sys-abstraction-BkEiLHl0.d.ts} +8 -4
  2. package/{base-sys-abstraction-C9WW3w57.d.ts → base-sys-abstraction-Qj7pkY1N.d.cts} +8 -4
  3. package/{chunk-OXD3YZZ7.js → chunk-7KFVMTOS.js} +3 -47
  4. package/chunk-7KFVMTOS.js.map +1 -0
  5. package/{chunk-P5RXA4C4.js → chunk-GES3MUGV.js} +24 -27
  6. package/{chunk-LCPYQVWT.js.map → chunk-GES3MUGV.js.map} +1 -1
  7. package/{chunk-YDIUMYIE.js → chunk-Q65HLCNL.js} +8 -7
  8. package/chunk-Q65HLCNL.js.map +1 -0
  9. package/{chunk-DPIL5UIL.js → chunk-WMMUXBDX.js} +6 -2
  10. package/chunk-WMMUXBDX.js.map +1 -0
  11. package/{index-Dhb2fQiw.d.cts → index-Q3phXzYr.d.cts} +2 -21
  12. package/{index-CcsGcehs.d.ts → index-tIGZMHTc.d.ts} +2 -21
  13. package/index.cjs +265 -7343
  14. package/index.cjs.map +1 -1
  15. package/index.d.cts +73 -12
  16. package/index.d.ts +73 -12
  17. package/index.js +218 -7265
  18. package/index.js.map +1 -1
  19. package/node/index.cjs +220 -39
  20. package/node/index.cjs.map +1 -1
  21. package/node/index.d.cts +22 -4
  22. package/node/index.d.ts +22 -4
  23. package/node/index.js +201 -25
  24. package/node/index.js.map +1 -1
  25. package/package.json +23 -12
  26. package/src/LICENSE +201 -0
  27. package/src/README.md +39 -0
  28. package/src/base-sys-abstraction.test.ts +95 -0
  29. package/src/base-sys-abstraction.ts +242 -0
  30. package/src/bin2text.test.ts +59 -0
  31. package/src/bin2text.ts +47 -0
  32. package/src/crypto.test.ts +15 -0
  33. package/src/crypto.ts +125 -0
  34. package/src/file-service.ts +24 -0
  35. package/src/future.test.ts +32 -0
  36. package/src/future.ts +27 -0
  37. package/src/index.ts +22 -0
  38. package/src/jsr.json +20 -0
  39. package/src/log-level-impl.ts +87 -0
  40. package/src/log-writer-impl.ts +58 -0
  41. package/src/logger-impl.ts +498 -0
  42. package/src/logger.test.ts +1132 -0
  43. package/src/logger.ts +208 -0
  44. package/src/node/deno-file-service.ts +92 -0
  45. package/src/node/deno-sys-abstraction.ts +133 -0
  46. package/src/node/index.ts +4 -0
  47. package/src/node/mock-file-service.ts +45 -0
  48. package/src/node/node-file-service.ts +91 -0
  49. package/src/node/node-sys-abstraction.ts +121 -0
  50. package/src/option.ts +60 -0
  51. package/src/resolve-once.test.ts +321 -0
  52. package/src/resolve-once.ts +179 -0
  53. package/src/result.test.ts +102 -0
  54. package/src/result.ts +165 -0
  55. package/src/runtime.ts +36 -0
  56. package/src/sys-abstraction.ts +53 -0
  57. package/src/sys-env.test.ts +53 -0
  58. package/src/sys-env.ts +216 -0
  59. package/src/test/log-write-stream.ts +95 -0
  60. package/src/test/mock-logger.ts +40 -0
  61. package/src/time.ts +20 -0
  62. package/src/tracer.test.ts +314 -0
  63. package/src/tracer.ts +222 -0
  64. package/src/txt-en-decoder.ts +21 -0
  65. package/src/uri.test.ts +155 -0
  66. package/src/uri.ts +421 -0
  67. package/src/utils/console-write-stream.ts +72 -0
  68. package/src/utils/fanout-write-stream.ts +32 -0
  69. package/src/utils/index.ts +6 -0
  70. package/src/utils/rebuffer.ts +75 -0
  71. package/src/utils/stream-map.ts +67 -0
  72. package/src/utils/stream2string.ts +47 -0
  73. package/src/utils/string2stream.ts +14 -0
  74. package/src/version.ts +3 -0
  75. package/src/web/index.ts +1 -0
  76. package/src/web/web-sys-abstraction.ts +80 -0
  77. package/ts/base-sys-abstraction.d.ts +84 -0
  78. package/ts/base-sys-abstraction.d.ts.map +1 -0
  79. package/ts/base-sys-abstraction.js +178 -0
  80. package/ts/base-sys-abstraction.js.map +1 -0
  81. package/ts/base-sys-abstraction.test.d.ts +2 -0
  82. package/ts/base-sys-abstraction.test.d.ts.map +1 -0
  83. package/ts/base-sys-abstraction.test.js +82 -0
  84. package/ts/base-sys-abstraction.test.js.map +1 -0
  85. package/ts/bin2text.d.ts +3 -0
  86. package/ts/bin2text.d.ts.map +1 -0
  87. package/ts/bin2text.js +43 -0
  88. package/ts/bin2text.js.map +1 -0
  89. package/ts/bin2text.test.d.ts +2 -0
  90. package/ts/bin2text.test.d.ts.map +1 -0
  91. package/ts/bin2text.test.js +51 -0
  92. package/ts/bin2text.test.js.map +1 -0
  93. package/ts/crypto.d.ts +76 -0
  94. package/ts/crypto.d.ts.map +1 -0
  95. package/ts/crypto.js +22 -0
  96. package/ts/crypto.js.map +1 -0
  97. package/ts/crypto.test.d.ts +2 -0
  98. package/ts/crypto.test.d.ts.map +1 -0
  99. package/ts/crypto.test.js +14 -0
  100. package/ts/crypto.test.js.map +1 -0
  101. package/ts/file-service.d.ts +17 -0
  102. package/ts/file-service.d.ts.map +1 -0
  103. package/ts/file-service.js +2 -0
  104. package/ts/file-service.js.map +1 -0
  105. package/ts/future.d.ts +8 -0
  106. package/ts/future.d.ts.map +1 -0
  107. package/ts/future.js +38 -0
  108. package/ts/future.js.map +1 -0
  109. package/ts/future.test.d.ts +2 -0
  110. package/ts/future.test.d.ts.map +1 -0
  111. package/ts/future.test.js +28 -0
  112. package/ts/future.test.js.map +1 -0
  113. package/ts/index.d.ts +23 -0
  114. package/ts/index.d.ts.map +1 -0
  115. package/ts/index.js +23 -0
  116. package/ts/index.js.map +1 -0
  117. package/ts/log-level-impl.d.ts +14 -0
  118. package/ts/log-level-impl.d.ts.map +1 -0
  119. package/ts/log-level-impl.js +72 -0
  120. package/ts/log-level-impl.js.map +1 -0
  121. package/ts/log-writer-impl.d.ts +10 -0
  122. package/ts/log-writer-impl.d.ts.map +1 -0
  123. package/ts/log-writer-impl.js +45 -0
  124. package/ts/log-writer-impl.js.map +1 -0
  125. package/ts/logger-impl.d.ts +71 -0
  126. package/ts/logger-impl.d.ts.map +1 -0
  127. package/ts/logger-impl.js +412 -0
  128. package/ts/logger-impl.js.map +1 -0
  129. package/ts/logger.d.ts +84 -0
  130. package/ts/logger.d.ts.map +1 -0
  131. package/ts/logger.js +114 -0
  132. package/ts/logger.js.map +1 -0
  133. package/ts/logger.test.d.ts +2 -0
  134. package/ts/logger.test.d.ts.map +1 -0
  135. package/ts/logger.test.js +1023 -0
  136. package/ts/logger.test.js.map +1 -0
  137. package/ts/node/deno-file-service.d.ts +17 -0
  138. package/ts/node/deno-file-service.d.ts.map +1 -0
  139. package/ts/node/deno-file-service.js +65 -0
  140. package/ts/node/deno-file-service.js.map +1 -0
  141. package/ts/node/deno-sys-abstraction.d.ts +22 -0
  142. package/ts/node/deno-sys-abstraction.d.ts.map +1 -0
  143. package/ts/node/deno-sys-abstraction.js +101 -0
  144. package/ts/node/deno-sys-abstraction.js.map +1 -0
  145. package/ts/node/index.d.ts +5 -0
  146. package/ts/node/index.d.ts.map +1 -0
  147. package/ts/node/index.js +5 -0
  148. package/ts/node/index.js.map +1 -0
  149. package/ts/node/mock-file-service.d.ts +11 -0
  150. package/ts/node/mock-file-service.d.ts.map +1 -0
  151. package/ts/node/mock-file-service.js +34 -0
  152. package/ts/node/mock-file-service.js.map +1 -0
  153. package/ts/node/mock-file-service.test.d.ts +2 -0
  154. package/ts/node/mock-file-service.test.d.ts.map +1 -0
  155. package/ts/node/mock-file-service.test.js +31 -0
  156. package/ts/node/mock-file-service.test.js.map +1 -0
  157. package/ts/node/node-file-service.d.ts +16 -0
  158. package/ts/node/node-file-service.d.ts.map +1 -0
  159. package/ts/node/node-file-service.js +71 -0
  160. package/ts/node/node-file-service.js.map +1 -0
  161. package/ts/node/node-sys-abstraction.d.ts +22 -0
  162. package/ts/node/node-sys-abstraction.d.ts.map +1 -0
  163. package/ts/node/node-sys-abstraction.js +99 -0
  164. package/ts/node/node-sys-abstraction.js.map +1 -0
  165. package/ts/node/node-sys-abstraction.test.d.ts +2 -0
  166. package/ts/node/node-sys-abstraction.test.d.ts.map +1 -0
  167. package/ts/node/node-sys-abstraction.test.js +87 -0
  168. package/ts/node/node-sys-abstraction.test.js.map +1 -0
  169. package/ts/option.d.ts +25 -0
  170. package/ts/option.d.ts.map +1 -0
  171. package/ts/option.js +47 -0
  172. package/ts/option.js.map +1 -0
  173. package/ts/resolve-once.d.ts +46 -0
  174. package/ts/resolve-once.d.ts.map +1 -0
  175. package/ts/resolve-once.js +152 -0
  176. package/ts/resolve-once.js.map +1 -0
  177. package/ts/resolve-once.test.d.ts +2 -0
  178. package/ts/resolve-once.test.d.ts.map +1 -0
  179. package/ts/resolve-once.test.js +283 -0
  180. package/ts/resolve-once.test.js.map +1 -0
  181. package/ts/result.d.ts +34 -0
  182. package/ts/result.d.ts.map +1 -0
  183. package/ts/result.js +85 -0
  184. package/ts/result.js.map +1 -0
  185. package/ts/result.test.d.ts +2 -0
  186. package/ts/result.test.d.ts.map +1 -0
  187. package/ts/result.test.js +79 -0
  188. package/ts/result.test.js.map +1 -0
  189. package/ts/runtime.d.ts +8 -0
  190. package/ts/runtime.d.ts.map +1 -0
  191. package/ts/runtime.js +26 -0
  192. package/ts/runtime.js.map +1 -0
  193. package/ts/sys-abstraction.d.ts +36 -0
  194. package/ts/sys-abstraction.d.ts.map +1 -0
  195. package/ts/sys-abstraction.js +31 -0
  196. package/ts/sys-abstraction.js.map +1 -0
  197. package/ts/sys-env.d.ts +48 -0
  198. package/ts/sys-env.d.ts.map +1 -0
  199. package/ts/sys-env.js +176 -0
  200. package/ts/sys-env.js.map +1 -0
  201. package/ts/sys-env.test.d.ts +2 -0
  202. package/ts/sys-env.test.d.ts.map +1 -0
  203. package/ts/sys-env.test.js +51 -0
  204. package/ts/sys-env.test.js.map +1 -0
  205. package/ts/test/log-write-stream.d.ts +27 -0
  206. package/ts/test/log-write-stream.d.ts.map +1 -0
  207. package/ts/test/log-write-stream.js +74 -0
  208. package/ts/test/log-write-stream.js.map +1 -0
  209. package/ts/test/mock-logger.d.ts +14 -0
  210. package/ts/test/mock-logger.d.ts.map +1 -0
  211. package/ts/test/mock-logger.js +29 -0
  212. package/ts/test/mock-logger.js.map +1 -0
  213. package/ts/test/mock-logger.test.d.ts +2 -0
  214. package/ts/test/mock-logger.test.d.ts.map +1 -0
  215. package/ts/test/mock-logger.test.js +63 -0
  216. package/ts/test/mock-logger.test.js.map +1 -0
  217. package/ts/test/test-exit-handler.d.ts +2 -0
  218. package/ts/test/test-exit-handler.d.ts.map +1 -0
  219. package/ts/test/test-exit-handler.js +57 -0
  220. package/ts/test/test-exit-handler.js.map +1 -0
  221. package/ts/time.d.ts +13 -0
  222. package/ts/time.d.ts.map +1 -0
  223. package/ts/time.js +14 -0
  224. package/ts/time.js.map +1 -0
  225. package/ts/tracer.d.ts +59 -0
  226. package/ts/tracer.d.ts.map +1 -0
  227. package/ts/tracer.js +148 -0
  228. package/ts/tracer.js.map +1 -0
  229. package/ts/tracer.test.d.ts +2 -0
  230. package/ts/tracer.test.d.ts.map +1 -0
  231. package/ts/tracer.test.js +311 -0
  232. package/ts/tracer.test.js.map +1 -0
  233. package/ts/txt-en-decoder.d.ts +10 -0
  234. package/ts/txt-en-decoder.d.ts.map +1 -0
  235. package/ts/txt-en-decoder.js +15 -0
  236. package/ts/txt-en-decoder.js.map +1 -0
  237. package/ts/uri.d.ts +67 -0
  238. package/ts/uri.d.ts.map +1 -0
  239. package/ts/uri.js +283 -0
  240. package/ts/uri.js.map +1 -0
  241. package/ts/uri.test.d.ts +2 -0
  242. package/ts/uri.test.d.ts.map +1 -0
  243. package/ts/uri.test.js +119 -0
  244. package/ts/uri.test.js.map +1 -0
  245. package/ts/utils/console-write-stream.d.ts +21 -0
  246. package/ts/utils/console-write-stream.d.ts.map +1 -0
  247. package/ts/utils/console-write-stream.js +62 -0
  248. package/ts/utils/console-write-stream.js.map +1 -0
  249. package/ts/utils/fanout-write-stream.d.ts +12 -0
  250. package/ts/utils/fanout-write-stream.d.ts.map +1 -0
  251. package/ts/utils/fanout-write-stream.js +24 -0
  252. package/ts/utils/fanout-write-stream.js.map +1 -0
  253. package/ts/utils/index.d.ts +7 -0
  254. package/ts/utils/index.d.ts.map +1 -0
  255. package/ts/utils/index.js +7 -0
  256. package/ts/utils/index.js.map +1 -0
  257. package/ts/utils/rebuffer.d.ts +3 -0
  258. package/ts/utils/rebuffer.d.ts.map +1 -0
  259. package/ts/utils/rebuffer.js +60 -0
  260. package/ts/utils/rebuffer.js.map +1 -0
  261. package/ts/utils/rebuffer.test.d.ts +2 -0
  262. package/ts/utils/rebuffer.test.d.ts.map +1 -0
  263. package/ts/utils/rebuffer.test.js +77 -0
  264. package/ts/utils/rebuffer.test.js.map +1 -0
  265. package/ts/utils/stream-map.d.ts +9 -0
  266. package/ts/utils/stream-map.d.ts.map +1 -0
  267. package/ts/utils/stream-map.js +62 -0
  268. package/ts/utils/stream-map.js.map +1 -0
  269. package/ts/utils/stream-map.test.d.ts +2 -0
  270. package/ts/utils/stream-map.test.d.ts.map +1 -0
  271. package/ts/utils/stream-map.test.js +87 -0
  272. package/ts/utils/stream-map.test.js.map +1 -0
  273. package/ts/utils/stream-test-helper.d.ts +17 -0
  274. package/ts/utils/stream-test-helper.d.ts.map +1 -0
  275. package/ts/utils/stream-test-helper.js +37 -0
  276. package/ts/utils/stream-test-helper.js.map +1 -0
  277. package/ts/utils/stream2string.d.ts +3 -0
  278. package/ts/utils/stream2string.d.ts.map +1 -0
  279. package/ts/utils/stream2string.js +48 -0
  280. package/ts/utils/stream2string.js.map +1 -0
  281. package/ts/utils/stream2string.test.d.ts +2 -0
  282. package/ts/utils/stream2string.test.d.ts.map +1 -0
  283. package/ts/utils/stream2string.test.js +29 -0
  284. package/ts/utils/stream2string.test.js.map +1 -0
  285. package/ts/utils/string2stream.d.ts +4 -0
  286. package/ts/utils/string2stream.d.ts.map +1 -0
  287. package/ts/utils/string2stream.js +13 -0
  288. package/ts/utils/string2stream.js.map +1 -0
  289. package/ts/utils/string2stream.test.d.ts +2 -0
  290. package/ts/utils/string2stream.test.d.ts.map +1 -0
  291. package/ts/utils/string2stream.test.js +6 -0
  292. package/ts/utils/string2stream.test.js.map +1 -0
  293. package/ts/version.d.ts +2 -0
  294. package/ts/version.d.ts.map +1 -0
  295. package/ts/version.js +4 -0
  296. package/ts/version.js.map +1 -0
  297. package/ts/web/index.d.ts +2 -0
  298. package/ts/web/index.d.ts.map +1 -0
  299. package/ts/web/index.js +2 -0
  300. package/ts/web/index.js.map +1 -0
  301. package/ts/web/web-sys-abstraction.d.ts +4 -0
  302. package/ts/web/web-sys-abstraction.d.ts.map +1 -0
  303. package/ts/web/web-sys-abstraction.js +64 -0
  304. package/ts/web/web-sys-abstraction.js.map +1 -0
  305. package/utils/index.cjs +0 -42
  306. package/utils/index.cjs.map +1 -1
  307. package/utils/index.d.cts +1 -2
  308. package/utils/index.d.ts +1 -2
  309. package/utils/index.js +2 -7
  310. package/web/index.cjs +25 -7
  311. package/web/index.cjs.map +1 -1
  312. package/web/index.d.cts +2 -1
  313. package/web/index.d.ts +2 -1
  314. package/web/index.js +3 -3
  315. package/chunk-DPIL5UIL.js.map +0 -1
  316. package/chunk-LCPYQVWT.js +0 -21
  317. package/chunk-OXD3YZZ7.js.map +0 -1
  318. package/chunk-P5RXA4C4.js.map +0 -1
  319. package/chunk-YDIUMYIE.js.map +0 -1
@@ -0,0 +1,412 @@
1
+ import YAML from "yaml";
2
+ import { Level, logValue, removeSelfRef, asyncLogValue, } from "./logger.js";
3
+ import { WebSysAbstraction } from "./web/web-sys-abstraction.js";
4
+ import { Result } from "./result.js";
5
+ import { URI } from "./uri.js";
6
+ import { runtimeFn } from "./runtime.js";
7
+ import { ConsoleWriterStream } from "./utils/console-write-stream.js";
8
+ import { LogWriterStream } from "./log-writer-impl.js";
9
+ import { Utf8EnDecoderSingleton } from "./txt-en-decoder.js";
10
+ import { LevelHandlerSingleton } from "./log-level-impl.js";
11
+ function getLen(value) {
12
+ if (Array.isArray(value)) {
13
+ return logValue(() => value.length);
14
+ }
15
+ else if (typeof value === "string") {
16
+ return logValue(() => value.length);
17
+ }
18
+ else if (typeof value === "object" && value !== null) {
19
+ if (typeof value.size === "number") {
20
+ return logValue(() => value.size);
21
+ }
22
+ else if (typeof value.length === "number") {
23
+ return logValue(() => value.length);
24
+ }
25
+ return logValue(() => Object.keys(value).length);
26
+ }
27
+ return logValue(() => -1);
28
+ }
29
+ function hash(value) {
30
+ return "not implemented";
31
+ }
32
+ function toLogValue(lop) {
33
+ if (lop && typeof lop.then === "function") {
34
+ throw new Error("async logValue Not implemented");
35
+ }
36
+ return lop;
37
+ }
38
+ export class JSONFormatter {
39
+ constructor(txtEnde, space) {
40
+ this._txtEnDe = txtEnde;
41
+ this._space = space;
42
+ }
43
+ format(attr) {
44
+ return this._txtEnDe.encode(JSON.stringify(attr, removeSelfRef(), this._space) + "\n");
45
+ }
46
+ }
47
+ export class YAMLFormatter {
48
+ constructor(txtEnde, space) {
49
+ this._txtEnDe = txtEnde;
50
+ this._space = space;
51
+ }
52
+ format(attr) {
53
+ return this._txtEnDe.encode("---\n" + YAML.stringify(attr, removeSelfRef(), this._space) + "\n");
54
+ }
55
+ }
56
+ export class LoggerImpl {
57
+ constructor(params) {
58
+ this._attributes = {};
59
+ if (!params) {
60
+ params = {};
61
+ }
62
+ if (!params.sys) {
63
+ this._sys = WebSysAbstraction();
64
+ }
65
+ else {
66
+ this._sys = params.sys;
67
+ }
68
+ if (!params.txtEnDe) {
69
+ this._txtEnDe = Utf8EnDecoderSingleton();
70
+ }
71
+ else {
72
+ this._txtEnDe = params.txtEnDe;
73
+ }
74
+ if (!params.formatter) {
75
+ this._formatter = new JSONFormatter(this._txtEnDe);
76
+ }
77
+ else {
78
+ this._formatter = params.formatter;
79
+ }
80
+ if (params.logWriter) {
81
+ this._logWriter = params.logWriter;
82
+ }
83
+ else {
84
+ if (!params.out) {
85
+ const rt = runtimeFn();
86
+ let stream;
87
+ if (rt.isBrowser) {
88
+ stream = new ConsoleWriterStream();
89
+ }
90
+ else {
91
+ if (rt.isNodeIsh || rt.isReactNative || rt.isDeno) {
92
+ stream = this._sys.Stdout();
93
+ }
94
+ else {
95
+ throw new Error("No output defined for runtime");
96
+ }
97
+ }
98
+ this._logWriter = new LogWriterStream(stream);
99
+ }
100
+ else {
101
+ this._logWriter = new LogWriterStream(params.out);
102
+ }
103
+ }
104
+ if (!params.withAttributes) {
105
+ this._withAttributes = {};
106
+ }
107
+ else {
108
+ this._withAttributes = Object.assign({}, params.withAttributes);
109
+ }
110
+ this._attributes = Object.assign({}, this._withAttributes);
111
+ if (params.levelHandler) {
112
+ this._levelHandler = params.levelHandler;
113
+ }
114
+ else {
115
+ this._levelHandler = LevelHandlerSingleton();
116
+ }
117
+ }
118
+ TxtEnDe() {
119
+ return this._txtEnDe;
120
+ }
121
+ Attributes() {
122
+ return JSON.parse(JSON.stringify(this._attributes, removeSelfRef()));
123
+ }
124
+ SetExposeStack(enable) {
125
+ this._levelHandler.setExposeStack(enable);
126
+ return this;
127
+ }
128
+ EnableLevel(level, ...modules) {
129
+ this._levelHandler.enableLevel(level, ...modules);
130
+ return this;
131
+ }
132
+ DisableLevel(level, ...modules) {
133
+ this._levelHandler.disableLevel(level, ...modules);
134
+ return this;
135
+ }
136
+ Module(key) {
137
+ this._attributes["module"] = logValue(key);
138
+ this._withAttributes["module"] = logValue(key);
139
+ return this;
140
+ }
141
+ SetDebug(...modules) {
142
+ this._levelHandler.setDebug(...modules);
143
+ return this;
144
+ }
145
+ SetFormatter(formatter) {
146
+ this._formatter = formatter;
147
+ return this;
148
+ }
149
+ Timestamp() {
150
+ this._attributes["ts"] = logValue(() => this._sys.Time().Now().toISOString());
151
+ return this;
152
+ }
153
+ Warn() {
154
+ this._attributes["level"] = logValue(Level.WARN);
155
+ return this;
156
+ }
157
+ Log() {
158
+ return this;
159
+ }
160
+ Debug() {
161
+ this._attributes["level"] = logValue(Level.DEBUG);
162
+ return this;
163
+ }
164
+ Error() {
165
+ this._attributes["level"] = logValue(Level.ERROR);
166
+ return this;
167
+ }
168
+ Info() {
169
+ this._attributes["level"] = logValue(Level.INFO);
170
+ return this;
171
+ }
172
+ Err(err) {
173
+ var _a;
174
+ if (Result.Is(err)) {
175
+ if (err.isOk()) {
176
+ this.Result("noerror", err);
177
+ }
178
+ else {
179
+ this.Result("error", err);
180
+ }
181
+ }
182
+ else if (err instanceof Error) {
183
+ this._attributes["error"] = logValue(err.message);
184
+ if (this._levelHandler.isStackExposed) {
185
+ this._attributes["stack"] = logValue((_a = err.stack) === null || _a === void 0 ? void 0 : _a.split("\n").map((s) => s.trim()));
186
+ }
187
+ }
188
+ else {
189
+ this._attributes["error"] = logValue("" + err);
190
+ }
191
+ return this;
192
+ }
193
+ WithLevel(l) {
194
+ this._attributes["level"] = logValue(l);
195
+ return this;
196
+ }
197
+ Ref(key, action) {
198
+ if (typeof action === "function") {
199
+ this._attributes[key] = logValue(action);
200
+ }
201
+ else if (typeof action.toString === "function") {
202
+ this._attributes[key] = logValue(() => action.toString());
203
+ }
204
+ else {
205
+ this._attributes[key] = logValue("INVALID REF");
206
+ }
207
+ return this;
208
+ }
209
+ Bool(key, value) {
210
+ this._attributes[key] = logValue(!!value);
211
+ return this;
212
+ }
213
+ Result(key, res) {
214
+ if (res.isOk()) {
215
+ this._attributes[key] = logValue(res.Ok());
216
+ }
217
+ else {
218
+ this.Err(res.Err());
219
+ }
220
+ return this;
221
+ }
222
+ Len(value, key = "len") {
223
+ this._attributes[key] = getLen(value);
224
+ return this;
225
+ }
226
+ Hash(value, key = "hash") {
227
+ this._attributes[key] = asyncLogValue(async () => `${getLen(value).value()}:${await hash(value)}`);
228
+ return this;
229
+ }
230
+ Url(url, key = "url") {
231
+ this.Ref(key, () => URI.from(url).toString());
232
+ return this;
233
+ }
234
+ Str(key, value) {
235
+ this._attributes[key] = logValue(value);
236
+ return this;
237
+ }
238
+ Any(key, value) {
239
+ this._attributes[key] = logValue(value);
240
+ return this;
241
+ }
242
+ Dur(key, nsec) {
243
+ this._attributes[key] = logValue(`${nsec}ms`);
244
+ return this;
245
+ }
246
+ Uint64(key, value) {
247
+ this._attributes[key] = logValue(value);
248
+ return this;
249
+ }
250
+ Int(key, value) {
251
+ return this.Uint64(key, value);
252
+ }
253
+ async Flush() {
254
+ return new Promise((resolve) => {
255
+ this._logWriter._flush(undefined, resolve);
256
+ });
257
+ }
258
+ With() {
259
+ return new WithLoggerBuilder(new LoggerImpl({
260
+ logWriter: this._logWriter,
261
+ sys: this._sys,
262
+ levelHandler: this._levelHandler,
263
+ formatter: this._formatter,
264
+ withAttributes: Object.assign({ module: this._attributes["module"] }, this._withAttributes),
265
+ }));
266
+ }
267
+ _resetAttributes(fn) {
268
+ const ret = fn();
269
+ Object.keys(this._attributes).forEach((key) => {
270
+ delete this._attributes[key];
271
+ });
272
+ Object.assign(this._attributes, this._withAttributes);
273
+ return ret;
274
+ }
275
+ Msg(...args) {
276
+ const fnError = this._resetAttributes(() => {
277
+ var _a, _b;
278
+ const doWrite = this._levelHandler.isEnabled((_a = toLogValue(this._attributes["level"])) === null || _a === void 0 ? void 0 : _a.value(), (_b = toLogValue(this._attributes["module"])) === null || _b === void 0 ? void 0 : _b.value());
279
+ this._attributes["msg"] = logValue(args.join(" "));
280
+ const msg = this._attributes["msg"].value();
281
+ if (typeof msg === "string" && !msg.trim().length) {
282
+ delete this._attributes["msg"];
283
+ }
284
+ let fnRet = () => this._formatter.format(Object.assign({}, this._attributes));
285
+ if (doWrite) {
286
+ const encoded = fnRet();
287
+ this._logWriter.write(encoded);
288
+ fnRet = () => encoded;
289
+ }
290
+ return fnRet;
291
+ });
292
+ return {
293
+ AsError: () => new Error(this._txtEnDe.decode(fnError())),
294
+ };
295
+ }
296
+ }
297
+ class WithLoggerBuilder {
298
+ constructor(li) {
299
+ this._li = li;
300
+ }
301
+ TxtEnDe() {
302
+ return this._li.TxtEnDe();
303
+ }
304
+ Logger() {
305
+ Object.assign(this._li._withAttributes, this._li._attributes);
306
+ return this._li;
307
+ }
308
+ Attributes() {
309
+ return Object.assign({}, this._li._attributes);
310
+ }
311
+ SetExposeStack(enable) {
312
+ this._li._levelHandler.setExposeStack(enable);
313
+ return this;
314
+ }
315
+ SetFormatter(fmt) {
316
+ this._li.SetFormatter(fmt);
317
+ return this;
318
+ }
319
+ EnableLevel(level, ...modules) {
320
+ this._li._levelHandler.enableLevel(level, ...modules);
321
+ return this;
322
+ }
323
+ DisableLevel(level, ...modules) {
324
+ this._li._levelHandler.enableLevel(level, ...modules);
325
+ return this;
326
+ }
327
+ Module(key) {
328
+ this._li.Module(key);
329
+ return this;
330
+ }
331
+ SetDebug(...modules) {
332
+ this._li.SetDebug(...modules);
333
+ return this;
334
+ }
335
+ Str(key, value) {
336
+ this._li.Str(key, value);
337
+ return this;
338
+ }
339
+ Len(value, key) {
340
+ this._li.Len(value, key);
341
+ return this;
342
+ }
343
+ Hash(value, key) {
344
+ this._li.Hash(value, key);
345
+ return this;
346
+ }
347
+ Ref(key, action) {
348
+ this._li.Ref(key, action);
349
+ return this;
350
+ }
351
+ Bool(key, value) {
352
+ this._li.Bool(key, value);
353
+ return this;
354
+ }
355
+ Result(key, res) {
356
+ this._li.Result(key, res);
357
+ return this;
358
+ }
359
+ Url(url, key) {
360
+ this._li.Url(url, key);
361
+ return this;
362
+ }
363
+ Int(key, value) {
364
+ this._li.Int(key, value);
365
+ return this;
366
+ }
367
+ Log() {
368
+ this._li.Log();
369
+ return this;
370
+ }
371
+ WithLevel(level) {
372
+ this._li.WithLevel(level);
373
+ return this;
374
+ }
375
+ Error() {
376
+ this._li.Error();
377
+ return this;
378
+ }
379
+ Warn() {
380
+ this._li.Error();
381
+ return this;
382
+ }
383
+ Debug() {
384
+ this._li.Debug();
385
+ return this;
386
+ }
387
+ Err(err) {
388
+ this._li.Err(err);
389
+ return this;
390
+ }
391
+ Info() {
392
+ this._li.Info();
393
+ return this;
394
+ }
395
+ Timestamp() {
396
+ this._li.Timestamp();
397
+ return this;
398
+ }
399
+ Any(key, value) {
400
+ this._li.Any(key, value);
401
+ return this;
402
+ }
403
+ Dur(key, nsec) {
404
+ this._li.Dur(key, nsec);
405
+ return this;
406
+ }
407
+ Uint64(key, value) {
408
+ this._li.Uint64(key, value);
409
+ return this;
410
+ }
411
+ }
412
+ //# sourceMappingURL=logger-impl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger-impl.js","sourceRoot":"","sources":["../../src/logger-impl.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAIL,KAAK,EAEL,QAAQ,EAGR,aAAa,EAIb,aAAa,GAId,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEjE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAa,GAAG,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAgB,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,SAAS,MAAM,CAAC,KAAc;IAC5B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,QAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACrC,OAAO,QAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACvD,IAAI,OAAQ,KAAe,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC9C,OAAO,QAAQ,CAAC,GAAG,EAAE,CA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AE,CAAC;QACjB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,GAAG,CAAC,GAAY;QACd,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAClB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI;QACF,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QAChB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,SAAS;QACP,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,GAAG,CAAC,GAAW,EAAE,KAAsB;QACrC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,GAAG,CAAC,GAAW,EAAE,IAAY;QAC3B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACxB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,CAAC,GAAW,EAAE,KAAa;QAC/B,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
package/ts/logger.d.ts ADDED
@@ -0,0 +1,84 @@
1
+ import { Result } from "./result.js";
2
+ import { TxtEnDecoder } from "./txt-en-decoder.js";
3
+ import { CoerceURI } from "./uri.js";
4
+ export declare enum Level {
5
+ WARN = "warn",
6
+ DEBUG = "debug",
7
+ INFO = "info",
8
+ ERROR = "error"
9
+ }
10
+ export type Serialized = string | number | boolean;
11
+ export type FnSerialized = () => Serialized | Serialized[];
12
+ export declare class LogValue {
13
+ readonly fn: FnSerialized;
14
+ constructor(fn: FnSerialized);
15
+ value(): Serialized | Serialized[];
16
+ toJSON(): Serialized | Serialized[];
17
+ }
18
+ export type LogSerializable = Record<string, LogValue | Promise<LogValue>>;
19
+ export declare function removeSelfRef(lineEnd?: string): (key: unknown, val: unknown) => unknown;
20
+ export declare function asyncLogValue(val: () => Promise<Serialized>): Promise<LogValue>;
21
+ export type LogValueArg = LogValue | Serialized | Serialized[] | FnSerialized | undefined | null;
22
+ export declare function logValue(val: LogValueArg, state?: Set<unknown>): LogValue;
23
+ export interface Sized {
24
+ size: number;
25
+ }
26
+ export interface Lengthed {
27
+ length: number;
28
+ }
29
+ export type SizeOrLength = Sized | Lengthed;
30
+ export interface LogFormatter {
31
+ format(attr: LogSerializable): Uint8Array;
32
+ }
33
+ export interface LevelHandler {
34
+ enableLevel(level: Level, ...modules: string[]): void;
35
+ disableLevel(level: Level, ...modules: string[]): void;
36
+ setExposeStack(enable?: boolean): void;
37
+ isStackExposed: boolean;
38
+ setDebug(...modules: (string | string[])[]): void;
39
+ isEnabled(ilevel: unknown, module: unknown): boolean;
40
+ }
41
+ export interface LoggerInterface<R> {
42
+ TxtEnDe(): TxtEnDecoder;
43
+ Module(key: string): R;
44
+ EnableLevel(level: Level, ...modules: string[]): R;
45
+ DisableLevel(level: Level, ...modules: string[]): R;
46
+ Attributes(): Record<string, unknown>;
47
+ SetDebug(...modules: (string | string[])[]): R;
48
+ SetExposeStack(enable?: boolean): R;
49
+ SetFormatter(fmt: LogFormatter): R;
50
+ Ref(key: string, action: {
51
+ toString: () => string;
52
+ } | FnSerialized): R;
53
+ Result<T>(key: string, res: Result<T>): R;
54
+ Url(url: CoerceURI, key?: string): R;
55
+ Len(value: unknown, key?: string): R;
56
+ Hash(value: unknown, key?: string): R;
57
+ Str(key: string, value?: string): R;
58
+ Error(): R;
59
+ Warn(): R;
60
+ Debug(): R;
61
+ Log(): R;
62
+ WithLevel(level: Level): R;
63
+ Err(err: unknown | Result<unknown> | Error): R;
64
+ Info(): R;
65
+ Timestamp(): R;
66
+ Any(key: string, value: unknown): R;
67
+ Dur(key: string, nsec: number): R;
68
+ Uint64(key: string, value: number): R;
69
+ Int(key: string, value: number): R;
70
+ Bool(key: string, value: unknown): R;
71
+ }
72
+ export declare function IsLogger(obj: unknown): obj is Logger;
73
+ export interface WithLogger extends LoggerInterface<WithLogger> {
74
+ Logger(): Logger;
75
+ }
76
+ export interface AsError {
77
+ AsError(): Error;
78
+ }
79
+ export interface Logger extends LoggerInterface<Logger> {
80
+ With(): WithLogger;
81
+ Msg(...args: string[]): AsError;
82
+ Flush(): Promise<void>;
83
+ }
84
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,oBAAY,KAAK;IACf,IAAI,SAAS;IACb,KAAK,UAAU;IACf,IAAI,SAAS;IACb,KAAK,UAAU;CAChB;AAED,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AACnD,MAAM,MAAM,YAAY,GAAG,MAAM,UAAU,GAAG,UAAU,EAAE,CAAC;AAE3D,qBAAa,QAAQ;IACP,QAAQ,CAAC,EAAE,EAAE,YAAY;gBAAhB,EAAE,EAAE,YAAY;IACrC,KAAK,IAAI,UAAU,GAAG,UAAU,EAAE;IAGlC,MAAM,IAAI,UAAU,GAAG,UAAU,EAAE;CAGpC;AAED,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;AAE3E,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,KAAK,OAAO,CAUvF;AAGD,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAG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AAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,CAAC,CAAC;IACpC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,CAAC;IAClC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC;IACtC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC;IACnC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,CAAC,CAAC;CACtC;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM,CAyBpD;AAED,MAAM,WAAW,UAAW,SAAQ,eAAe,CAAC,UAAU,CAAC;IAC7D,MAAM,IAAI,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,OAAO;IACtB,OAAO,IAAI,KAAK,CAAC;CAClB;AAED,MAAM,WAAW,MAAO,SAAQ,eAAe,CAAC,MAAM,CAAC;IACrD,IAAI,IAAI,UAAU,CAAC;IAEnB,GAAG,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAChC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB"}
package/ts/logger.js ADDED
@@ -0,0 +1,114 @@
1
+ import { bin2string } from "./bin2text.js";
2
+ export var Level;
3
+ (function (Level) {
4
+ Level["WARN"] = "warn";
5
+ Level["DEBUG"] = "debug";
6
+ Level["INFO"] = "info";
7
+ Level["ERROR"] = "error";
8
+ })(Level || (Level = {}));
9
+ export class LogValue {
10
+ constructor(fn) {
11
+ this.fn = fn;
12
+ }
13
+ value() {
14
+ return this.fn();
15
+ }
16
+ toJSON() {
17
+ return this.value();
18
+ }
19
+ }
20
+ export function removeSelfRef(lineEnd) {
21
+ const cache = new Set();
22
+ return function (key, value) {
23
+ if (typeof value === "object" && value !== null) {
24
+ if (cache.has(value))
25
+ return "...";
26
+ cache.add(value);
27
+ }
28
+ return lineEnd ? value + lineEnd : value;
29
+ };
30
+ }
31
+ export function asyncLogValue(val) {
32
+ throw new Error("Not implemented");
33
+ }
34
+ export function logValue(val, state = new Set([Math.random()])) {
35
+ switch (typeof val) {
36
+ case "function":
37
+ return new LogValue(val);
38
+ case "string": {
39
+ try {
40
+ const ret = JSON.parse(val);
41
+ if (typeof ret === "object" && ret !== null) {
42
+ return logValue(ret, state);
43
+ }
44
+ }
45
+ catch (e) {
46
+ if (val.match(/[\n\r]/)) {
47
+ const lines = val.trimEnd().split(/[\n\r]/);
48
+ return new LogValue(() => lines);
49
+ }
50
+ }
51
+ return new LogValue(() => val.toString());
52
+ }
53
+ case "number":
54
+ return new LogValue(() => val);
55
+ case "boolean":
56
+ return new LogValue(() => val);
57
+ case "object": {
58
+ if (ArrayBuffer.isView(val)) {
59
+ return logValue(bin2string(val, 512));
60
+ }
61
+ if (Array.isArray(val)) {
62
+ return new LogValue(() => val.map((v) => logValue(v).value()));
63
+ }
64
+ if (val === null) {
65
+ return new LogValue(() => "null");
66
+ }
67
+ if (state.has(val)) {
68
+ return new LogValue(() => "...");
69
+ }
70
+ state.add(val);
71
+ const res = {};
72
+ const typedVal = val;
73
+ for (const key in typedVal) {
74
+ const element = typedVal[key];
75
+ if (element instanceof LogValue) {
76
+ res[key] = element;
77
+ }
78
+ else {
79
+ res[key] = logValue(element, state);
80
+ }
81
+ }
82
+ return new LogValue(() => res);
83
+ }
84
+ default:
85
+ if (!val) {
86
+ return new LogValue(() => "--Falsy--");
87
+ }
88
+ throw new Error(`Invalid type:${typeof val}`);
89
+ }
90
+ }
91
+ export function IsLogger(obj) {
92
+ return (typeof obj === "object" &&
93
+ [
94
+ "Module",
95
+ "EnableLevel",
96
+ "DisableLevel",
97
+ "SetDebug",
98
+ "Str",
99
+ "Error",
100
+ "Warn",
101
+ "Debug",
102
+ "Log",
103
+ "WithLevel",
104
+ "Err",
105
+ "Info",
106
+ "Timestamp",
107
+ "Any",
108
+ "Dur",
109
+ "Uint64",
110
+ ]
111
+ .map((fn) => typeof obj[fn] === "function")
112
+ .reduce((a, b) => a && b, true));
113
+ }
114
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAK3C,MAAM,CAAN,IAAY,KAKX;AALD,WAAY,KAAK;IACf,sBAAa,CAAA;IACb,wBAAe,CAAA;IACf,sBAAa,CAAA;IACb,wBAAe,CAAA;AACjB,CAAC,EALW,KAAK,KAAL,KAAK,QAKhB;AAKD,MAAM,OAAO,QAAQ;IACnB,YAAqB,EAAgB;QAAhB,OAAE,GAAF,EAAE,CAAc;IAAG,CAAC;IACzC,KAAK;QACH,OAAO,IAAI,CAAC,EAAE,EAAE,CAAC;IACnB,CAAC;IACD,MAAM;QACJ,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACF;AAID,MAAM,UAAU,aAAa,CAAC,OAAgB;IAC5C,MAAM,KAAK,GAAG,IAAI,GAAG,EAAE,CAAC;IACxB,OAAO,UAAU,GAAY,EAAE,KAAc;QAC3C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YAEhD,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC;gBAAE,OAAO,KAAK,CAAC;YACnC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACnB,CAAC;QACD,OAAO,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;IAC3C,CAAC,CAAC;AACJ,CAAC;AAGD,MAAM,UAAU,aAAa,CAAC,GAA8B;IAE1D,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;AACrC,CAAC;AAID,MAAM,UAAU,QAAQ,CAAC,GAAgB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AAY;IACnC,OAAO,CACL,OAAO,GAAG,KAAK,QAAQ;QACvB;YACE,QAAQ;YACR,aAAa;YACb,cAAc;YACd,UAAU;YACV,KAAK;YACL,OAAO;YACP,MAAM;YACN,OAAO;YACP,KAAK;YACL,WAAW;YACX,KAAK;YACL,MAAM;YACN,WAAW;YACX,KAAK;YACL,KAAK;YACL,QAAQ;SACT;aAEE,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,OAAQ,GAAW,CAAC,EAAE,CAAC,KAAK,UAAU,CAAC;aACnD,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAClC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=logger.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.test.d.ts","sourceRoot":"","sources":["../../src/logger.test.ts"],"names":[],"mappings":""}