@adviser/cement 0.1.11 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. package/base_sys_abstraction-BCdXJHNa.d.ts +21 -0
  2. package/base_sys_abstraction-BYZvxqsW.d.cts +21 -0
  3. package/chunk-J2IM7FHM.js +65 -0
  4. package/chunk-J2IM7FHM.js.map +1 -0
  5. package/chunk-MWAFFTM4.js +82 -0
  6. package/chunk-MWAFFTM4.js.map +1 -0
  7. package/chunk-PZTL4UNG.js +233 -0
  8. package/chunk-PZTL4UNG.js.map +1 -0
  9. package/index.cjs +986 -0
  10. package/index.cjs.map +1 -0
  11. package/index.d.cts +196 -0
  12. package/index.d.ts +196 -11
  13. package/index.js +610 -26
  14. package/index.js.map +1 -1
  15. package/node/index.cjs +436 -0
  16. package/node/index.cjs.map +1 -0
  17. package/node/index.d.cts +47 -0
  18. package/node/index.d.ts +47 -4
  19. package/node/index.js +215 -17
  20. package/node/index.js.map +1 -1
  21. package/package.json +34 -8
  22. package/sys_abstraction-CjljYIkv.d.cts +65 -0
  23. package/sys_abstraction-CjljYIkv.d.ts +65 -0
  24. package/utils/index.cjs +270 -0
  25. package/utils/index.cjs.map +1 -0
  26. package/utils/index.d.cts +33 -0
  27. package/utils/index.d.ts +33 -6
  28. package/utils/index.js +232 -20
  29. package/utils/index.js.map +1 -1
  30. package/web/index.cjs +286 -0
  31. package/web/index.cjs.map +1 -0
  32. package/web/index.d.cts +6 -0
  33. package/web/index.d.ts +6 -2
  34. package/web/index.js +7 -16
  35. package/web/index.js.map +1 -1
  36. package/base_sys_abstraction.d.ts +0 -79
  37. package/base_sys_abstraction.d.ts.map +0 -1
  38. package/base_sys_abstraction.js +0 -186
  39. package/base_sys_abstraction.js.map +0 -1
  40. package/base_sys_abstraction.test.d.ts +0 -2
  41. package/base_sys_abstraction.test.d.ts.map +0 -1
  42. package/base_sys_abstraction.test.js +0 -77
  43. package/base_sys_abstraction.test.js.map +0 -1
  44. package/file_service.d.ts +0 -18
  45. package/file_service.d.ts.map +0 -1
  46. package/file_service.js +0 -3
  47. package/file_service.js.map +0 -1
  48. package/future.d.ts +0 -8
  49. package/future.d.ts.map +0 -1
  50. package/future.js +0 -42
  51. package/future.js.map +0 -1
  52. package/future.test.d.ts +0 -2
  53. package/future.test.d.ts.map +0 -1
  54. package/future.test.js +0 -30
  55. package/future.test.js.map +0 -1
  56. package/index.d.ts.map +0 -1
  57. package/logger.d.ts +0 -36
  58. package/logger.d.ts.map +0 -1
  59. package/logger.js +0 -11
  60. package/logger.js.map +0 -1
  61. package/logger.test.d.ts +0 -2
  62. package/logger.test.d.ts.map +0 -1
  63. package/logger.test.js +0 -372
  64. package/logger.test.js.map +0 -1
  65. package/logger_impl.d.ts +0 -64
  66. package/logger_impl.d.ts.map +0 -1
  67. package/logger_impl.js +0 -331
  68. package/logger_impl.js.map +0 -1
  69. package/node/index.d.ts.map +0 -1
  70. package/node/mock_file_service.d.ts +0 -11
  71. package/node/mock_file_service.d.ts.map +0 -1
  72. package/node/mock_file_service.js +0 -38
  73. package/node/mock_file_service.js.map +0 -1
  74. package/node/mock_file_service.test.d.ts +0 -2
  75. package/node/mock_file_service.test.d.ts.map +0 -1
  76. package/node/mock_file_service.test.js +0 -19
  77. package/node/mock_file_service.test.js.map +0 -1
  78. package/node/node_file_service.d.ts +0 -16
  79. package/node/node_file_service.d.ts.map +0 -1
  80. package/node/node_file_service.js +0 -84
  81. package/node/node_file_service.js.map +0 -1
  82. package/node/node_sys_abstraction.d.ts +0 -21
  83. package/node/node_sys_abstraction.d.ts.map +0 -1
  84. package/node/node_sys_abstraction.js +0 -101
  85. package/node/node_sys_abstraction.js.map +0 -1
  86. package/node/node_sys_abstraction.test.d.ts +0 -2
  87. package/node/node_sys_abstraction.test.d.ts.map +0 -1
  88. package/node/node_sys_abstraction.test.js +0 -57
  89. package/node/node_sys_abstraction.test.js.map +0 -1
  90. package/option.d.ts +0 -25
  91. package/option.d.ts.map +0 -1
  92. package/option.js +0 -53
  93. package/option.js.map +0 -1
  94. package/result.d.ts +0 -31
  95. package/result.d.ts.map +0 -1
  96. package/result.js +0 -69
  97. package/result.js.map +0 -1
  98. package/result.test.d.ts +0 -2
  99. package/result.test.d.ts.map +0 -1
  100. package/result.test.js +0 -39
  101. package/result.test.js.map +0 -1
  102. package/sys_abstraction.d.ts +0 -35
  103. package/sys_abstraction.d.ts.map +0 -1
  104. package/sys_abstraction.js +0 -35
  105. package/sys_abstraction.js.map +0 -1
  106. package/test/log_collector.d.ts +0 -22
  107. package/test/log_collector.d.ts.map +0 -1
  108. package/test/log_collector.js +0 -66
  109. package/test/log_collector.js.map +0 -1
  110. package/test/mock_logger.d.ts +0 -13
  111. package/test/mock_logger.d.ts.map +0 -1
  112. package/test/mock_logger.js +0 -30
  113. package/test/mock_logger.js.map +0 -1
  114. package/test/mock_logger.test.d.ts +0 -2
  115. package/test/mock_logger.test.d.ts.map +0 -1
  116. package/test/mock_logger.test.js +0 -49
  117. package/test/mock_logger.test.js.map +0 -1
  118. package/test/test-exit-handler.d.ts +0 -1
  119. package/test/test-exit-handler.d.ts.map +0 -1
  120. package/test/test-exit-handler.js +0 -76
  121. package/test/test-exit-handler.js.map +0 -1
  122. package/time.d.ts +0 -13
  123. package/time.d.ts.map +0 -1
  124. package/time.js +0 -18
  125. package/time.js.map +0 -1
  126. package/utils/index.d.ts.map +0 -1
  127. package/utils/rebuffer.d.ts +0 -3
  128. package/utils/rebuffer.d.ts.map +0 -1
  129. package/utils/rebuffer.js +0 -65
  130. package/utils/rebuffer.js.map +0 -1
  131. package/utils/rebuffer.test.d.ts +0 -2
  132. package/utils/rebuffer.test.d.ts.map +0 -1
  133. package/utils/rebuffer.test.js +0 -79
  134. package/utils/rebuffer.test.js.map +0 -1
  135. package/utils/stream2string.d.ts +0 -3
  136. package/utils/stream2string.d.ts.map +0 -1
  137. package/utils/stream2string.js +0 -53
  138. package/utils/stream2string.js.map +0 -1
  139. package/utils/stream2string.test.d.ts +0 -2
  140. package/utils/stream2string.test.d.ts.map +0 -1
  141. package/utils/stream2string.test.js +0 -31
  142. package/utils/stream2string.test.js.map +0 -1
  143. package/utils/stream_map.d.ts +0 -9
  144. package/utils/stream_map.d.ts.map +0 -1
  145. package/utils/stream_map.js +0 -67
  146. package/utils/stream_map.js.map +0 -1
  147. package/utils/stream_map.test.d.ts +0 -2
  148. package/utils/stream_map.test.d.ts.map +0 -1
  149. package/utils/stream_map.test.js +0 -89
  150. package/utils/stream_map.test.js.map +0 -1
  151. package/utils/stream_test_helper.d.ts +0 -15
  152. package/utils/stream_test_helper.d.ts.map +0 -1
  153. package/utils/stream_test_helper.js +0 -42
  154. package/utils/stream_test_helper.js.map +0 -1
  155. package/utils/string2stream.d.ts +0 -3
  156. package/utils/string2stream.d.ts.map +0 -1
  157. package/utils/string2stream.js +0 -18
  158. package/utils/string2stream.js.map +0 -1
  159. package/utils/string2stream.test.d.ts +0 -2
  160. package/utils/string2stream.test.d.ts.map +0 -1
  161. package/utils/string2stream.test.js +0 -9
  162. package/utils/string2stream.test.js.map +0 -1
  163. package/web/index.d.ts.map +0 -1
  164. package/web/web_sys_abstraction.d.ts +0 -4
  165. package/web/web_sys_abstraction.d.ts.map +0 -1
  166. package/web/web_sys_abstraction.js +0 -65
  167. package/web/web_sys_abstraction.js.map +0 -1
package/index.cjs ADDED
@@ -0,0 +1,986 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
9
+ var __typeError = (msg) => {
10
+ throw TypeError(msg);
11
+ };
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __export = (target, all) => {
25
+ for (var name in all)
26
+ __defProp(target, name, { get: all[name], enumerable: true });
27
+ };
28
+ var __copyProps = (to, from, except, desc) => {
29
+ if (from && typeof from === "object" || typeof from === "function") {
30
+ for (let key of __getOwnPropNames(from))
31
+ if (!__hasOwnProp.call(to, key) && key !== except)
32
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
33
+ }
34
+ return to;
35
+ };
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
38
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
39
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
40
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
41
+ var __await = function(promise, isYieldStar) {
42
+ this[0] = promise;
43
+ this[1] = isYieldStar;
44
+ };
45
+ var __yieldStar = (value) => {
46
+ var obj = value[__knownSymbol("asyncIterator")], isAwait = false, method, it = {};
47
+ if (obj == null) {
48
+ obj = value[__knownSymbol("iterator")]();
49
+ method = (k) => it[k] = (x) => obj[k](x);
50
+ } else {
51
+ obj = obj.call(value);
52
+ method = (k) => it[k] = (v) => {
53
+ if (isAwait) {
54
+ isAwait = false;
55
+ if (k === "throw") throw v;
56
+ return v;
57
+ }
58
+ isAwait = true;
59
+ return {
60
+ done: false,
61
+ value: new __await(new Promise((resolve) => {
62
+ var x = obj[k](v);
63
+ if (!(x instanceof Object)) __typeError("Object expected");
64
+ resolve(x);
65
+ }), 1)
66
+ };
67
+ };
68
+ }
69
+ return it[__knownSymbol("iterator")] = () => it, method("next"), "throw" in obj ? method("throw") : it.throw = (x) => {
70
+ throw x;
71
+ }, "return" in obj && method("return"), it;
72
+ };
73
+
74
+ // src/index.ts
75
+ var src_exports = {};
76
+ __export(src_exports, {
77
+ Future: () => Future,
78
+ IDMode: () => IDMode,
79
+ Level: () => Level,
80
+ LevelHandlerImpl: () => LevelHandlerImpl,
81
+ LogCollector: () => LogCollector,
82
+ LogWriter: () => LogWriter,
83
+ LoggerImpl: () => LoggerImpl,
84
+ MockLogger: () => MockLogger,
85
+ None: () => None,
86
+ Option: () => Option,
87
+ RandomMode: () => RandomMode,
88
+ Result: () => Result,
89
+ ResultError: () => ResultError,
90
+ ResultOK: () => ResultOK,
91
+ Some: () => Some,
92
+ String2TimeMode: () => String2TimeMode,
93
+ Time: () => Time,
94
+ TimeMode: () => TimeMode,
95
+ TimeUnits: () => TimeUnits
96
+ });
97
+ module.exports = __toCommonJS(src_exports);
98
+
99
+ // src/logger.ts
100
+ var Level = /* @__PURE__ */ ((Level2) => {
101
+ Level2["WARN"] = "warn";
102
+ Level2["DEBUG"] = "debug";
103
+ Level2["INFO"] = "info";
104
+ Level2["ERROR"] = "error";
105
+ return Level2;
106
+ })(Level || {});
107
+
108
+ // src/sys_abstraction.ts
109
+ var TimeMode = /* @__PURE__ */ ((TimeMode2) => {
110
+ TimeMode2["REAL"] = "real";
111
+ TimeMode2["CONST"] = "const";
112
+ TimeMode2["STEP"] = "step";
113
+ return TimeMode2;
114
+ })(TimeMode || {});
115
+ var RandomMode = /* @__PURE__ */ ((RandomMode2) => {
116
+ RandomMode2["CONST"] = "const";
117
+ RandomMode2["STEP"] = "step";
118
+ RandomMode2["RANDOM"] = "random";
119
+ return RandomMode2;
120
+ })(RandomMode || {});
121
+ var IDMode = /* @__PURE__ */ ((IDMode2) => {
122
+ IDMode2["UUID"] = "uuid";
123
+ IDMode2["CONST"] = "const";
124
+ IDMode2["STEP"] = "step";
125
+ return IDMode2;
126
+ })(IDMode || {});
127
+ function String2TimeMode(s) {
128
+ switch (s == null ? void 0 : s.toLowerCase()) {
129
+ case "real":
130
+ return "real" /* REAL */;
131
+ case "const":
132
+ return "const" /* CONST */;
133
+ case "step":
134
+ return "step" /* STEP */;
135
+ default:
136
+ return "real" /* REAL */;
137
+ }
138
+ }
139
+
140
+ // src/time.ts
141
+ var Time = class {
142
+ TimeSince(start) {
143
+ const now = this.Now();
144
+ return now.getTime() - start.getTime();
145
+ }
146
+ };
147
+ var TimeUnits = /* @__PURE__ */ ((TimeUnits2) => {
148
+ TimeUnits2[TimeUnits2["Microsecond"] = 1] = "Microsecond";
149
+ TimeUnits2[TimeUnits2["Second"] = 1e3] = "Second";
150
+ TimeUnits2[TimeUnits2["Minute"] = 6e4] = "Minute";
151
+ TimeUnits2[TimeUnits2["Hour"] = 36e5] = "Hour";
152
+ return TimeUnits2;
153
+ })(TimeUnits || {});
154
+
155
+ // src/base_sys_abstraction.ts
156
+ var SysTime = class extends Time {
157
+ Now() {
158
+ return /* @__PURE__ */ new Date();
159
+ }
160
+ Sleep(duration) {
161
+ return new Promise((resolve) => {
162
+ setTimeout(() => {
163
+ resolve();
164
+ }, duration);
165
+ });
166
+ }
167
+ };
168
+ var ConstTime = class extends Time {
169
+ Now() {
170
+ return new Date(2021, 1, 1, 0, 0, 0, 0);
171
+ }
172
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
173
+ Sleep(duration) {
174
+ return Promise.resolve();
175
+ }
176
+ };
177
+ var StepTime = class extends Time {
178
+ constructor() {
179
+ super();
180
+ this._step = new ConstTime().Now();
181
+ }
182
+ Now() {
183
+ if (this._step.getTime() === 0) {
184
+ this._step = new ConstTime().Now();
185
+ return this._step;
186
+ }
187
+ this._step = new Date(this._step.getTime() + 1e3);
188
+ return this._step;
189
+ }
190
+ Sleep(duration) {
191
+ this._step = new Date(this._step.getTime() + duration);
192
+ return Promise.resolve();
193
+ }
194
+ };
195
+ function TimeFactory(timeMode) {
196
+ switch (timeMode) {
197
+ case "real" /* REAL */:
198
+ return new SysTime();
199
+ case "const" /* CONST */:
200
+ return new ConstTime();
201
+ case "step" /* STEP */:
202
+ return new StepTime();
203
+ }
204
+ return new SysTime();
205
+ }
206
+ var RandomService = class {
207
+ constructor(mode) {
208
+ this._step = 0;
209
+ this._mode = mode;
210
+ }
211
+ Random0ToValue(value) {
212
+ switch (this._mode) {
213
+ case "const" /* CONST */:
214
+ return 0.5 * value;
215
+ case "step" /* STEP */:
216
+ this._step += 1e-4;
217
+ return this._step * value;
218
+ case "random" /* RANDOM */:
219
+ return Math.random() * value;
220
+ default:
221
+ throw new Error("Unknown RandomMode");
222
+ }
223
+ }
224
+ };
225
+ var IdService = class {
226
+ constructor(mode) {
227
+ this._step = 0;
228
+ if (!mode) {
229
+ mode = "uuid" /* UUID */;
230
+ }
231
+ this._mode = mode;
232
+ }
233
+ NextId() {
234
+ switch (this._mode) {
235
+ case "uuid" /* UUID */:
236
+ return crypto.randomUUID();
237
+ case "const" /* CONST */:
238
+ return "VeryUniqueID";
239
+ case "step" /* STEP */:
240
+ return `STEPId-${this._step++}`;
241
+ default:
242
+ throw new Error("Unknown IDMode");
243
+ }
244
+ }
245
+ };
246
+ var decoder = new TextDecoder();
247
+ var BaseSysAbstraction = class {
248
+ constructor(params) {
249
+ this._time = new SysTime();
250
+ this._stdout = new WritableStream({
251
+ write(chunk) {
252
+ return new Promise((resolve) => {
253
+ const decoded = decoder.decode(chunk);
254
+ console.log(decoded.trimEnd());
255
+ resolve();
256
+ });
257
+ }
258
+ });
259
+ this._stderr = new WritableStream({
260
+ write(chunk) {
261
+ return new Promise((resolve) => {
262
+ const decoded = decoder.decode(chunk);
263
+ console.error(decoded.trimEnd());
264
+ resolve();
265
+ });
266
+ }
267
+ });
268
+ this._idService = new IdService();
269
+ this._randomService = new RandomService("random" /* RANDOM */);
270
+ this._fileSystem = params.FileSystem;
271
+ this._systemService = params.SystemService;
272
+ }
273
+ };
274
+ var WrapperSysAbstraction = class {
275
+ constructor(base, params) {
276
+ this._time = base._time;
277
+ this._stdout = base._stdout;
278
+ this._stderr = base._stderr;
279
+ this._idService = base._idService;
280
+ this._randomService = base._randomService;
281
+ this._fileSystem = base._fileSystem;
282
+ this._systemService = base._systemService;
283
+ if (params) {
284
+ if (params.TimeMode) {
285
+ this._time = TimeFactory(params.TimeMode);
286
+ }
287
+ if (params.Stdout) {
288
+ this._stdout = params.Stdout;
289
+ }
290
+ if (params.Stderr) {
291
+ this._stderr = params.Stderr;
292
+ }
293
+ if (params.IdMode) {
294
+ this._idService = new IdService(params.IdMode);
295
+ }
296
+ if (params.RandomMode) {
297
+ this._randomService = new RandomService(params.RandomMode);
298
+ }
299
+ if (params.FileSystem) {
300
+ this._fileSystem = params.FileSystem;
301
+ }
302
+ if (params.SystemService) {
303
+ this._systemService = params.SystemService;
304
+ }
305
+ }
306
+ }
307
+ Time() {
308
+ return this._time;
309
+ }
310
+ NextId() {
311
+ return this._idService.NextId();
312
+ }
313
+ Random0ToValue(value) {
314
+ return this._randomService.Random0ToValue(value);
315
+ }
316
+ Stdout() {
317
+ return this._stdout;
318
+ }
319
+ Stderr() {
320
+ return this._stderr;
321
+ }
322
+ System() {
323
+ return this._systemService;
324
+ }
325
+ FileSystem() {
326
+ return this._fileSystem;
327
+ }
328
+ };
329
+
330
+ // src/web/web_sys_abstraction.ts
331
+ var WebFileService = class {
332
+ get baseDir() {
333
+ throw new Error("basedir-Method not implemented.");
334
+ }
335
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
336
+ create(fname) {
337
+ throw new Error("create-Method not implemented.");
338
+ }
339
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
340
+ readFileString(fname) {
341
+ throw new Error("readFileString-Method not implemented.");
342
+ }
343
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
344
+ writeFileString(fname, content) {
345
+ throw new Error("writeFileString-Method not implemented.");
346
+ }
347
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
348
+ abs(fname) {
349
+ throw new Error("abs-Method not implemented.");
350
+ }
351
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
352
+ join(...paths) {
353
+ throw new Error("join-Method not implemented.");
354
+ }
355
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
356
+ relative(from, to) {
357
+ throw new Error("relative-Method not implemented.");
358
+ }
359
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
360
+ dirname(fname) {
361
+ throw new Error("dirname-Method not implemented.");
362
+ }
363
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
364
+ basename(fname) {
365
+ throw new Error("basename-Method not implemented.");
366
+ }
367
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
368
+ nodeImport(fname) {
369
+ throw new Error("nodeImport-Method not implemented.");
370
+ }
371
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
372
+ isAbsolute(fname) {
373
+ throw new Error("isAbsolute-Method not implemented.");
374
+ }
375
+ };
376
+ var WebSystemService = class {
377
+ Env() {
378
+ throw new Error("Env-Method not implemented.");
379
+ }
380
+ Args() {
381
+ throw new Error("Args-Method not implemented.");
382
+ }
383
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
384
+ OnExit(hdl) {
385
+ throw new Error("OnExit-Method not implemented.");
386
+ }
387
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
388
+ Exit(code) {
389
+ throw new Error("Exit-Method not implemented.");
390
+ }
391
+ };
392
+ var my = void 0;
393
+ function WebSysAbstraction(param) {
394
+ if (!my) {
395
+ my = new BaseSysAbstraction({
396
+ FileSystem: new WebFileService(),
397
+ SystemService: new WebSystemService()
398
+ });
399
+ }
400
+ return new WrapperSysAbstraction(my, param);
401
+ }
402
+
403
+ // src/logger_impl.ts
404
+ var encoder = new TextEncoder();
405
+ var LevelHandlerImpl = class {
406
+ constructor() {
407
+ this._globalLevels = /* @__PURE__ */ new Set(["info" /* INFO */, "error" /* ERROR */, "warn" /* WARN */]);
408
+ this._modules = /* @__PURE__ */ new Map();
409
+ }
410
+ enableLevel(level, ...modules) {
411
+ if (modules.length == 0) {
412
+ this._globalLevels.add(level);
413
+ return;
414
+ }
415
+ this.forModules(
416
+ level,
417
+ (p) => {
418
+ this._modules.set(p, /* @__PURE__ */ new Set([...this._globalLevels, level]));
419
+ },
420
+ ...modules
421
+ );
422
+ }
423
+ disableLevel(level, ...modules) {
424
+ if (modules.length == 0) {
425
+ this._globalLevels.delete(level);
426
+ return;
427
+ }
428
+ this.forModules(
429
+ level,
430
+ (p) => {
431
+ this._modules.delete(p);
432
+ },
433
+ ...modules
434
+ );
435
+ }
436
+ forModules(level, fnAction, ...modules) {
437
+ for (const m of modules.flat()) {
438
+ const parts = m.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
439
+ for (const p of parts) {
440
+ fnAction(p);
441
+ }
442
+ }
443
+ }
444
+ setDebug(...modules) {
445
+ this.forModules(
446
+ "debug" /* DEBUG */,
447
+ (p) => {
448
+ this._modules.set(p, /* @__PURE__ */ new Set([...this._globalLevels, "debug" /* DEBUG */]));
449
+ },
450
+ ...modules
451
+ );
452
+ }
453
+ isEnabled(ilevel, module2) {
454
+ const level = ilevel;
455
+ if (module2 !== void 0) {
456
+ const levels = this._modules.get(module2);
457
+ if (levels && levels.has(level)) {
458
+ return true;
459
+ }
460
+ }
461
+ if (level === void 0) {
462
+ return true;
463
+ }
464
+ return this._globalLevels.has(level);
465
+ }
466
+ };
467
+ var levelSingleton = new LevelHandlerImpl();
468
+ var LogWriter = class {
469
+ constructor(out) {
470
+ this._toFlush = [];
471
+ this._flushIsRunning = false;
472
+ this._flushDoneFns = Array();
473
+ this._out = out;
474
+ }
475
+ write(encoded) {
476
+ const my2 = async () => {
477
+ try {
478
+ const writer = this._out.getWriter();
479
+ await writer.ready;
480
+ await writer.write(encoded);
481
+ await writer.releaseLock();
482
+ } catch (err) {
483
+ console.error("Chunk error:", err);
484
+ }
485
+ };
486
+ this._toFlush.push(my2);
487
+ this._flush();
488
+ }
489
+ _flush(toFlush = void 0, done) {
490
+ if (done) {
491
+ this._flushDoneFns.push(done);
492
+ }
493
+ if (this._toFlush.length == 0) {
494
+ this._flushIsRunning = false;
495
+ this._flushDoneFns.forEach((fn) => fn());
496
+ this._flushDoneFns = [];
497
+ return;
498
+ }
499
+ if (!toFlush && this._toFlush.length == 1 && !this._flushIsRunning) {
500
+ this._flushIsRunning = true;
501
+ } else if (!toFlush) {
502
+ return;
503
+ }
504
+ const my2 = this._toFlush.shift();
505
+ my2 == null ? void 0 : my2().finally(() => {
506
+ this._flush(this._toFlush);
507
+ });
508
+ }
509
+ };
510
+ var LoggerImpl = class _LoggerImpl {
511
+ // readonly _id: string = "logger-" + Math.random().toString(36)
512
+ constructor(params) {
513
+ this._attributes = {};
514
+ if (!params) {
515
+ params = {};
516
+ }
517
+ if (!params.sys) {
518
+ this._sys = WebSysAbstraction();
519
+ } else {
520
+ this._sys = params.sys;
521
+ }
522
+ if (params.logWriter) {
523
+ this._logWriter = params.logWriter;
524
+ } else {
525
+ if (!params.out) {
526
+ this._logWriter = new LogWriter(this._sys.Stdout());
527
+ } else {
528
+ this._logWriter = new LogWriter(params.out);
529
+ }
530
+ }
531
+ if (!params.withAttributes) {
532
+ this._withAttributes = {};
533
+ } else {
534
+ this._withAttributes = __spreadValues({}, params.withAttributes);
535
+ }
536
+ this._attributes = __spreadValues({}, this._withAttributes);
537
+ if (params.levelHandler) {
538
+ this._levelHandler = params.levelHandler;
539
+ } else {
540
+ this._levelHandler = levelSingleton;
541
+ }
542
+ }
543
+ EnableLevel(level, ...modules) {
544
+ this._levelHandler.enableLevel(level, ...modules);
545
+ return this;
546
+ }
547
+ DisableLevel(level, ...modules) {
548
+ this._levelHandler.disableLevel(level, ...modules);
549
+ return this;
550
+ }
551
+ Module(key) {
552
+ this._attributes["module"] = key;
553
+ this._withAttributes["module"] = key;
554
+ return this;
555
+ }
556
+ SetDebug(...modules) {
557
+ this._levelHandler.setDebug(...modules);
558
+ return this;
559
+ }
560
+ Timestamp() {
561
+ this._attributes["ts"] = this._sys.Time().Now().toISOString();
562
+ return this;
563
+ }
564
+ Warn() {
565
+ this._attributes["level"] = "warn" /* WARN */;
566
+ return this;
567
+ }
568
+ Log() {
569
+ return this;
570
+ }
571
+ Debug() {
572
+ this._attributes["level"] = "debug" /* DEBUG */;
573
+ return this;
574
+ }
575
+ Error() {
576
+ this._attributes["level"] = "error" /* ERROR */;
577
+ return this;
578
+ }
579
+ Info() {
580
+ this._attributes["level"] = "info" /* INFO */;
581
+ return this;
582
+ }
583
+ Err(err) {
584
+ if (err instanceof Error) {
585
+ this._attributes["error"] = err.message;
586
+ } else {
587
+ this._attributes["error"] = "" + err;
588
+ }
589
+ return this;
590
+ }
591
+ WithLevel(l) {
592
+ this._attributes["level"] = l;
593
+ return this;
594
+ }
595
+ Str(key, value) {
596
+ this._attributes[key] = value;
597
+ return this;
598
+ }
599
+ Any(key, value) {
600
+ this._attributes[key] = value;
601
+ return this;
602
+ }
603
+ Dur(key, nsec) {
604
+ this._attributes[key] = `${nsec}ms`;
605
+ return this;
606
+ }
607
+ Uint64(key, value) {
608
+ this._attributes[key] = value;
609
+ return this;
610
+ }
611
+ async Flush() {
612
+ return new Promise((resolve) => {
613
+ this._logWriter._flush(void 0, resolve);
614
+ });
615
+ }
616
+ With() {
617
+ return new WithLoggerBuilder(
618
+ new _LoggerImpl({
619
+ logWriter: this._logWriter,
620
+ sys: this._sys,
621
+ levelHandler: this._levelHandler,
622
+ withAttributes: __spreadValues({
623
+ module: this._attributes["module"]
624
+ }, this._withAttributes)
625
+ })
626
+ );
627
+ }
628
+ _resetAttributes(fn) {
629
+ const ret = fn();
630
+ Object.keys(this._attributes).forEach((key) => {
631
+ delete this._attributes[key];
632
+ });
633
+ Object.assign(this._attributes, this._withAttributes);
634
+ return ret;
635
+ }
636
+ Msg(...args) {
637
+ const error = this._resetAttributes(() => {
638
+ const doWrite = this._levelHandler.isEnabled(this._attributes["level"], this._attributes["module"]);
639
+ this._attributes["msg"] = args.join(" ");
640
+ if (typeof this._attributes["msg"] === "string" && !this._attributes["msg"].trim().length) {
641
+ delete this._attributes["msg"];
642
+ }
643
+ if (this._attributes["ts"] === "ETERNITY") {
644
+ this.Timestamp();
645
+ }
646
+ const str = JSON.stringify(this._attributes);
647
+ if (doWrite) {
648
+ const encoded = encoder.encode(str + "\n");
649
+ this._logWriter.write(encoded);
650
+ }
651
+ return new Error(str);
652
+ });
653
+ return {
654
+ AsError: () => error
655
+ };
656
+ }
657
+ };
658
+ var WithLoggerBuilder = class {
659
+ constructor(li) {
660
+ this._li = li;
661
+ }
662
+ Logger() {
663
+ Object.assign(this._li._withAttributes, this._li._attributes);
664
+ return this._li;
665
+ }
666
+ EnableLevel(level, ...modules) {
667
+ this._li._levelHandler.enableLevel(level, ...modules);
668
+ return this;
669
+ }
670
+ DisableLevel(level, ...modules) {
671
+ this._li._levelHandler.enableLevel(level, ...modules);
672
+ return this;
673
+ }
674
+ Module(key) {
675
+ this._li.Module(key);
676
+ return this;
677
+ }
678
+ SetDebug(...modules) {
679
+ this._li.SetDebug(...modules);
680
+ return this;
681
+ }
682
+ Str(key, value) {
683
+ this._li.Str(key, value);
684
+ return this;
685
+ }
686
+ Log() {
687
+ this._li.Log();
688
+ return this;
689
+ }
690
+ WithLevel(level) {
691
+ this._li.WithLevel(level);
692
+ return this;
693
+ }
694
+ Error() {
695
+ this._li.Error();
696
+ return this;
697
+ }
698
+ Warn() {
699
+ this._li.Error();
700
+ return this;
701
+ }
702
+ Debug() {
703
+ this._li.Debug();
704
+ return this;
705
+ }
706
+ Err(err) {
707
+ this._li.Err(err);
708
+ return this;
709
+ }
710
+ Info() {
711
+ this._li.Info();
712
+ return this;
713
+ }
714
+ Timestamp() {
715
+ this._li._attributes["ts"] = "ETERNITY";
716
+ return this;
717
+ }
718
+ Any(key, value) {
719
+ this._li.Any(key, value);
720
+ return this;
721
+ }
722
+ Dur(key, nsec) {
723
+ this._li.Dur(key, nsec);
724
+ return this;
725
+ }
726
+ Uint64(key, value) {
727
+ this._li.Uint64(key, value);
728
+ return this;
729
+ }
730
+ };
731
+
732
+ // src/test/log_collector.ts
733
+ var LogWriter2 = class {
734
+ constructor() {
735
+ this._bufferArr = [];
736
+ this.desiredSize = null;
737
+ this.ready = Promise.resolve(void 0);
738
+ this._resolveClosed = () => {
739
+ };
740
+ this.closed = new Promise((resolve) => {
741
+ this._resolveClosed = resolve;
742
+ });
743
+ }
744
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
745
+ abort(reason) {
746
+ throw new Error("Method not implemented.");
747
+ }
748
+ close() {
749
+ this._resolveClosed();
750
+ return Promise.resolve(void 0);
751
+ }
752
+ releaseLock() {
753
+ }
754
+ write(chunk) {
755
+ chunk && this._bufferArr.push(chunk);
756
+ return Promise.resolve(void 0);
757
+ }
758
+ };
759
+ var LogCollector = class {
760
+ constructor() {
761
+ this.locked = false;
762
+ }
763
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
764
+ abort(reason) {
765
+ throw new Error("Method not implemented.");
766
+ }
767
+ async close() {
768
+ if (this._writer) {
769
+ const ret = await this._writer.close();
770
+ this._writer = void 0;
771
+ return ret;
772
+ }
773
+ return Promise.resolve(void 0);
774
+ }
775
+ getWriter() {
776
+ if (!this._writer) {
777
+ this._writer = new LogWriter2();
778
+ }
779
+ return this._writer;
780
+ }
781
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
782
+ Logs() {
783
+ if (!this._writer) {
784
+ return [];
785
+ }
786
+ const jsonNlStr = new TextDecoder().decode(
787
+ new Uint8Array(
788
+ function* (res) {
789
+ for (const x of res) {
790
+ yield* __yieldStar(x);
791
+ }
792
+ }(this._writer._bufferArr)
793
+ )
794
+ );
795
+ const splitStr = jsonNlStr.split("\n");
796
+ const filterStr = splitStr.filter((a) => a.length);
797
+ const mapStr = filterStr.map((a) => JSON.parse(a));
798
+ return mapStr;
799
+ }
800
+ };
801
+
802
+ // src/test/mock_logger.ts
803
+ function MockLogger(params) {
804
+ const lc = new LogCollector();
805
+ let modNames = ["MockLogger"];
806
+ if (typeof (params == null ? void 0 : params.moduleName) === "string") {
807
+ modNames = [params == null ? void 0 : params.moduleName];
808
+ } else if (Array.isArray(params == null ? void 0 : params.moduleName)) {
809
+ modNames = [...params.moduleName, ...modNames];
810
+ }
811
+ const logger = new LoggerImpl({
812
+ out: lc,
813
+ sys: params == null ? void 0 : params.sys,
814
+ levelHandler: new LevelHandlerImpl()
815
+ }).With().Module(modNames[0]).Logger();
816
+ !(params == null ? void 0 : params.disableDebug) && logger.SetDebug(...modNames);
817
+ return {
818
+ logCollector: lc,
819
+ logger
820
+ };
821
+ }
822
+
823
+ // src/result.ts
824
+ var Result = class _Result {
825
+ static Ok(t) {
826
+ return new ResultOK(t);
827
+ }
828
+ static Err(t) {
829
+ if (typeof t === "string") {
830
+ return new ResultError(new Error(t));
831
+ }
832
+ return new ResultError(t);
833
+ }
834
+ static Is(t) {
835
+ return t instanceof _Result;
836
+ }
837
+ isOk() {
838
+ return this.is_ok();
839
+ }
840
+ isErr() {
841
+ return this.is_err();
842
+ }
843
+ Ok() {
844
+ return this.unwrap();
845
+ }
846
+ Err() {
847
+ return this.unwrap_err();
848
+ }
849
+ };
850
+ var ResultOK = class extends Result {
851
+ constructor(t) {
852
+ super();
853
+ this._t = t;
854
+ }
855
+ is_ok() {
856
+ return true;
857
+ }
858
+ is_err() {
859
+ return false;
860
+ }
861
+ unwrap_err() {
862
+ throw new Error("Result is Ok");
863
+ }
864
+ unwrap() {
865
+ return this._t;
866
+ }
867
+ };
868
+ var ResultError = class extends Result {
869
+ constructor(t) {
870
+ super();
871
+ this._error = t;
872
+ }
873
+ is_ok() {
874
+ return false;
875
+ }
876
+ is_err() {
877
+ return true;
878
+ }
879
+ unwrap() {
880
+ throw new Error(`Result is Err: ${this._error}`);
881
+ }
882
+ unwrap_err() {
883
+ return this._error;
884
+ }
885
+ };
886
+
887
+ // src/option.ts
888
+ var Option = class _Option {
889
+ static Some(t) {
890
+ return new Some(t);
891
+ }
892
+ static None() {
893
+ return new None();
894
+ }
895
+ static Is(t) {
896
+ return t instanceof _Option;
897
+ }
898
+ IsNone() {
899
+ return this.is_none();
900
+ }
901
+ IsSome() {
902
+ return this.is_some();
903
+ }
904
+ Unwrap() {
905
+ return this.unwrap();
906
+ }
907
+ };
908
+ var Some = class extends Option {
909
+ constructor(_t) {
910
+ super();
911
+ this._t = _t;
912
+ }
913
+ is_none() {
914
+ return false;
915
+ }
916
+ is_some() {
917
+ return true;
918
+ }
919
+ unwrap() {
920
+ return this._t;
921
+ }
922
+ };
923
+ var None = class extends Option {
924
+ is_none() {
925
+ return true;
926
+ }
927
+ is_some() {
928
+ return false;
929
+ }
930
+ unwrap() {
931
+ throw new Error("None.unwrap");
932
+ }
933
+ };
934
+
935
+ // src/future.ts
936
+ var _promise, _resolveFn, _rejectFn;
937
+ var Future = class {
938
+ constructor() {
939
+ __privateAdd(this, _promise);
940
+ __privateAdd(this, _resolveFn, () => {
941
+ throw new Error("This Promise is not working as expected.");
942
+ });
943
+ __privateAdd(this, _rejectFn, () => {
944
+ throw new Error("This Promise is not working as expected.");
945
+ });
946
+ __privateSet(this, _promise, new Promise((resolve, reject) => {
947
+ __privateSet(this, _resolveFn, resolve);
948
+ __privateSet(this, _rejectFn, reject);
949
+ }));
950
+ }
951
+ async asPromise() {
952
+ return __privateGet(this, _promise);
953
+ }
954
+ resolve(value) {
955
+ __privateGet(this, _resolveFn).call(this, value);
956
+ }
957
+ reject(reason) {
958
+ __privateGet(this, _rejectFn).call(this, reason);
959
+ }
960
+ };
961
+ _promise = new WeakMap();
962
+ _resolveFn = new WeakMap();
963
+ _rejectFn = new WeakMap();
964
+ // Annotate the CommonJS export names for ESM import in node:
965
+ 0 && (module.exports = {
966
+ Future,
967
+ IDMode,
968
+ Level,
969
+ LevelHandlerImpl,
970
+ LogCollector,
971
+ LogWriter,
972
+ LoggerImpl,
973
+ MockLogger,
974
+ None,
975
+ Option,
976
+ RandomMode,
977
+ Result,
978
+ ResultError,
979
+ ResultOK,
980
+ Some,
981
+ String2TimeMode,
982
+ Time,
983
+ TimeMode,
984
+ TimeUnits
985
+ });
986
+ //# sourceMappingURL=index.cjs.map