@adviser/cement 0.1.11 → 0.1.12

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 +987 -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 +611 -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,987 @@
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
+ console.log(`Logger:${JSON.stringify([...this._li._levelHandler._globalLevels])}`);
665
+ return this._li;
666
+ }
667
+ EnableLevel(level, ...modules) {
668
+ this._li._levelHandler.enableLevel(level, ...modules);
669
+ return this;
670
+ }
671
+ DisableLevel(level, ...modules) {
672
+ this._li._levelHandler.enableLevel(level, ...modules);
673
+ return this;
674
+ }
675
+ Module(key) {
676
+ this._li.Module(key);
677
+ return this;
678
+ }
679
+ SetDebug(...modules) {
680
+ this._li.SetDebug(...modules);
681
+ return this;
682
+ }
683
+ Str(key, value) {
684
+ this._li.Str(key, value);
685
+ return this;
686
+ }
687
+ Log() {
688
+ this._li.Log();
689
+ return this;
690
+ }
691
+ WithLevel(level) {
692
+ this._li.WithLevel(level);
693
+ return this;
694
+ }
695
+ Error() {
696
+ this._li.Error();
697
+ return this;
698
+ }
699
+ Warn() {
700
+ this._li.Error();
701
+ return this;
702
+ }
703
+ Debug() {
704
+ this._li.Debug();
705
+ return this;
706
+ }
707
+ Err(err) {
708
+ this._li.Err(err);
709
+ return this;
710
+ }
711
+ Info() {
712
+ this._li.Info();
713
+ return this;
714
+ }
715
+ Timestamp() {
716
+ this._li._attributes["ts"] = "ETERNITY";
717
+ return this;
718
+ }
719
+ Any(key, value) {
720
+ this._li.Any(key, value);
721
+ return this;
722
+ }
723
+ Dur(key, nsec) {
724
+ this._li.Dur(key, nsec);
725
+ return this;
726
+ }
727
+ Uint64(key, value) {
728
+ this._li.Uint64(key, value);
729
+ return this;
730
+ }
731
+ };
732
+
733
+ // src/test/log_collector.ts
734
+ var LogWriter2 = class {
735
+ constructor() {
736
+ this._bufferArr = [];
737
+ this.desiredSize = null;
738
+ this.ready = Promise.resolve(void 0);
739
+ this._resolveClosed = () => {
740
+ };
741
+ this.closed = new Promise((resolve) => {
742
+ this._resolveClosed = resolve;
743
+ });
744
+ }
745
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
746
+ abort(reason) {
747
+ throw new Error("Method not implemented.");
748
+ }
749
+ close() {
750
+ this._resolveClosed();
751
+ return Promise.resolve(void 0);
752
+ }
753
+ releaseLock() {
754
+ }
755
+ write(chunk) {
756
+ chunk && this._bufferArr.push(chunk);
757
+ return Promise.resolve(void 0);
758
+ }
759
+ };
760
+ var LogCollector = class {
761
+ constructor() {
762
+ this.locked = false;
763
+ }
764
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
765
+ abort(reason) {
766
+ throw new Error("Method not implemented.");
767
+ }
768
+ async close() {
769
+ if (this._writer) {
770
+ const ret = await this._writer.close();
771
+ this._writer = void 0;
772
+ return ret;
773
+ }
774
+ return Promise.resolve(void 0);
775
+ }
776
+ getWriter() {
777
+ if (!this._writer) {
778
+ this._writer = new LogWriter2();
779
+ }
780
+ return this._writer;
781
+ }
782
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
783
+ Logs() {
784
+ if (!this._writer) {
785
+ return [];
786
+ }
787
+ const jsonNlStr = new TextDecoder().decode(
788
+ new Uint8Array(
789
+ function* (res) {
790
+ for (const x of res) {
791
+ yield* __yieldStar(x);
792
+ }
793
+ }(this._writer._bufferArr)
794
+ )
795
+ );
796
+ const splitStr = jsonNlStr.split("\n");
797
+ const filterStr = splitStr.filter((a) => a.length);
798
+ const mapStr = filterStr.map((a) => JSON.parse(a));
799
+ return mapStr;
800
+ }
801
+ };
802
+
803
+ // src/test/mock_logger.ts
804
+ function MockLogger(params) {
805
+ const lc = new LogCollector();
806
+ let modNames = ["MockLogger"];
807
+ if (typeof (params == null ? void 0 : params.moduleName) === "string") {
808
+ modNames = [params == null ? void 0 : params.moduleName];
809
+ } else if (Array.isArray(params == null ? void 0 : params.moduleName)) {
810
+ modNames = [...params.moduleName, ...modNames];
811
+ }
812
+ const logger = new LoggerImpl({
813
+ out: lc,
814
+ sys: params == null ? void 0 : params.sys,
815
+ levelHandler: new LevelHandlerImpl()
816
+ }).With().Module(modNames[0]).Logger();
817
+ !(params == null ? void 0 : params.disableDebug) && logger.SetDebug(...modNames);
818
+ return {
819
+ logCollector: lc,
820
+ logger
821
+ };
822
+ }
823
+
824
+ // src/result.ts
825
+ var Result = class _Result {
826
+ static Ok(t) {
827
+ return new ResultOK(t);
828
+ }
829
+ static Err(t) {
830
+ if (typeof t === "string") {
831
+ return new ResultError(new Error(t));
832
+ }
833
+ return new ResultError(t);
834
+ }
835
+ static Is(t) {
836
+ return t instanceof _Result;
837
+ }
838
+ isOk() {
839
+ return this.is_ok();
840
+ }
841
+ isErr() {
842
+ return this.is_err();
843
+ }
844
+ Ok() {
845
+ return this.unwrap();
846
+ }
847
+ Err() {
848
+ return this.unwrap_err();
849
+ }
850
+ };
851
+ var ResultOK = class extends Result {
852
+ constructor(t) {
853
+ super();
854
+ this._t = t;
855
+ }
856
+ is_ok() {
857
+ return true;
858
+ }
859
+ is_err() {
860
+ return false;
861
+ }
862
+ unwrap_err() {
863
+ throw new Error("Result is Ok");
864
+ }
865
+ unwrap() {
866
+ return this._t;
867
+ }
868
+ };
869
+ var ResultError = class extends Result {
870
+ constructor(t) {
871
+ super();
872
+ this._error = t;
873
+ }
874
+ is_ok() {
875
+ return false;
876
+ }
877
+ is_err() {
878
+ return true;
879
+ }
880
+ unwrap() {
881
+ throw new Error(`Result is Err: ${this._error}`);
882
+ }
883
+ unwrap_err() {
884
+ return this._error;
885
+ }
886
+ };
887
+
888
+ // src/option.ts
889
+ var Option = class _Option {
890
+ static Some(t) {
891
+ return new Some(t);
892
+ }
893
+ static None() {
894
+ return new None();
895
+ }
896
+ static Is(t) {
897
+ return t instanceof _Option;
898
+ }
899
+ IsNone() {
900
+ return this.is_none();
901
+ }
902
+ IsSome() {
903
+ return this.is_some();
904
+ }
905
+ Unwrap() {
906
+ return this.unwrap();
907
+ }
908
+ };
909
+ var Some = class extends Option {
910
+ constructor(_t) {
911
+ super();
912
+ this._t = _t;
913
+ }
914
+ is_none() {
915
+ return false;
916
+ }
917
+ is_some() {
918
+ return true;
919
+ }
920
+ unwrap() {
921
+ return this._t;
922
+ }
923
+ };
924
+ var None = class extends Option {
925
+ is_none() {
926
+ return true;
927
+ }
928
+ is_some() {
929
+ return false;
930
+ }
931
+ unwrap() {
932
+ throw new Error("None.unwrap");
933
+ }
934
+ };
935
+
936
+ // src/future.ts
937
+ var _promise, _resolveFn, _rejectFn;
938
+ var Future = class {
939
+ constructor() {
940
+ __privateAdd(this, _promise);
941
+ __privateAdd(this, _resolveFn, () => {
942
+ throw new Error("This Promise is not working as expected.");
943
+ });
944
+ __privateAdd(this, _rejectFn, () => {
945
+ throw new Error("This Promise is not working as expected.");
946
+ });
947
+ __privateSet(this, _promise, new Promise((resolve, reject) => {
948
+ __privateSet(this, _resolveFn, resolve);
949
+ __privateSet(this, _rejectFn, reject);
950
+ }));
951
+ }
952
+ async asPromise() {
953
+ return __privateGet(this, _promise);
954
+ }
955
+ resolve(value) {
956
+ __privateGet(this, _resolveFn).call(this, value);
957
+ }
958
+ reject(reason) {
959
+ __privateGet(this, _rejectFn).call(this, reason);
960
+ }
961
+ };
962
+ _promise = new WeakMap();
963
+ _resolveFn = new WeakMap();
964
+ _rejectFn = new WeakMap();
965
+ // Annotate the CommonJS export names for ESM import in node:
966
+ 0 && (module.exports = {
967
+ Future,
968
+ IDMode,
969
+ Level,
970
+ LevelHandlerImpl,
971
+ LogCollector,
972
+ LogWriter,
973
+ LoggerImpl,
974
+ MockLogger,
975
+ None,
976
+ Option,
977
+ RandomMode,
978
+ Result,
979
+ ResultError,
980
+ ResultOK,
981
+ Some,
982
+ String2TimeMode,
983
+ Time,
984
+ TimeMode,
985
+ TimeUnits
986
+ });
987
+ //# sourceMappingURL=index.cjs.map