@adviser/cement 0.1.23 → 0.1.25

Sign up to get free protection for your applications and to get access to all the features.
package/index.cjs CHANGED
@@ -77,7 +77,9 @@ __export(src_exports, {
77
77
  Future: () => Future,
78
78
  IDMode: () => IDMode,
79
79
  IsLogger: () => IsLogger,
80
+ Keyed: () => Keyed,
80
81
  KeyedResolvOnce: () => KeyedResolvOnce,
82
+ KeyedResolvSeq: () => KeyedResolvSeq,
81
83
  Level: () => Level,
82
84
  LevelHandlerImpl: () => LevelHandlerImpl,
83
85
  LogCollector: () => LogCollector,
@@ -88,6 +90,7 @@ __export(src_exports, {
88
90
  Option: () => Option,
89
91
  RandomMode: () => RandomMode,
90
92
  ResolveOnce: () => ResolveOnce,
93
+ ResolveSeq: () => ResolveSeq,
91
94
  Result: () => Result,
92
95
  ResultError: () => ResultError,
93
96
  ResultOK: () => ResultOK,
@@ -444,10 +447,9 @@ function resolveLogValue(val) {
444
447
  return ret;
445
448
  }
446
449
  function logValue(val) {
447
- if (typeof val === "function") {
448
- return new LogValue(val);
449
- }
450
450
  switch (typeof val) {
451
+ case "function":
452
+ return new LogValue(val);
451
453
  case "string":
452
454
  return new LogValue(() => val.toString());
453
455
  case "number":
@@ -457,6 +459,9 @@ function logValue(val) {
457
459
  case "object":
458
460
  return new LogValue(() => JSON.stringify(val));
459
461
  default:
462
+ if (!val) {
463
+ return new LogValue(() => "--Falsy--");
464
+ }
460
465
  throw new Error(`Invalid type:${typeof val}`);
461
466
  }
462
467
  }
@@ -672,6 +677,18 @@ var LoggerImpl = class _LoggerImpl {
672
677
  }
673
678
  return this;
674
679
  }
680
+ Len(value, key = "len") {
681
+ if (Array.isArray(value)) {
682
+ this._attributes[key] = logValue(() => value.length);
683
+ } else if (typeof value === "string") {
684
+ this._attributes[key] = logValue(() => value.length);
685
+ } else if (typeof value === "object" && value !== null) {
686
+ this._attributes[key] = logValue(() => Object.keys(value).length);
687
+ } else {
688
+ this.Int(key, -1);
689
+ }
690
+ return this;
691
+ }
675
692
  Url(url, key = "url") {
676
693
  this.Ref(key, () => url.toString());
677
694
  return this;
@@ -720,27 +737,36 @@ var LoggerImpl = class _LoggerImpl {
720
737
  Object.assign(this._attributes, this._withAttributes);
721
738
  return ret;
722
739
  }
740
+ _produceError(attr, ...args) {
741
+ var _a;
742
+ attr["msg"] = logValue(args.join(" "));
743
+ const msg = attr["msg"].value();
744
+ if (typeof msg === "string" && !msg.trim().length) {
745
+ delete attr["msg"];
746
+ }
747
+ if (((_a = attr["ts"]) == null ? void 0 : _a.value()) === "ETERNITY") {
748
+ this.Timestamp.call({
749
+ _sys: this._sys,
750
+ _attributes: attr
751
+ });
752
+ }
753
+ return JSON.stringify(resolveLogValue(attr));
754
+ }
723
755
  Msg(...args) {
724
- const error = this._resetAttributes(() => {
725
- var _a, _b, _c;
756
+ const fnError = this._resetAttributes(() => {
757
+ var _a, _b;
726
758
  const doWrite = this._levelHandler.isEnabled((_a = this._attributes["level"]) == null ? void 0 : _a.value(), (_b = this._attributes["module"]) == null ? void 0 : _b.value());
727
- this._attributes["msg"] = logValue(args.join(" "));
728
- const msg = this._attributes["msg"].value();
729
- if (typeof msg === "string" && !msg.trim().length) {
730
- delete this._attributes["msg"];
731
- }
732
- if (((_c = this._attributes["ts"]) == null ? void 0 : _c.value()) === "ETERNITY") {
733
- this.Timestamp();
734
- }
735
- const str = JSON.stringify(resolveLogValue(this._attributes));
759
+ let fnRet = () => this._produceError(__spreadValues({}, this._attributes), ...args);
736
760
  if (doWrite) {
761
+ const str = this._produceError(__spreadValues({}, this._attributes), ...args);
737
762
  const encoded = encoder.encode(str + "\n");
738
763
  this._logWriter.write(encoded);
764
+ fnRet = () => str;
739
765
  }
740
- return new Error(str);
766
+ return fnRet;
741
767
  });
742
768
  return {
743
- AsError: () => error
769
+ AsError: () => new Error(fnError())
744
770
  };
745
771
  }
746
772
  };
@@ -772,6 +798,10 @@ var WithLoggerBuilder = class {
772
798
  this._li.Str(key, value);
773
799
  return this;
774
800
  }
801
+ Len(value, key) {
802
+ this._li.Len(value, key);
803
+ return this;
804
+ }
775
805
  Ref(key, action) {
776
806
  this._li.Ref(key, action);
777
807
  return this;
@@ -1072,6 +1102,26 @@ _resolveFn = new WeakMap();
1072
1102
  _rejectFn = new WeakMap();
1073
1103
 
1074
1104
  // src/resolve-once.ts
1105
+ var ResolveSeq = class {
1106
+ constructor(ctx) {
1107
+ this._seqFutures = [];
1108
+ this.ctx = ctx;
1109
+ }
1110
+ reset() {
1111
+ }
1112
+ async _step(item) {
1113
+ if (!item) {
1114
+ return;
1115
+ }
1116
+ item.fn(this.ctx).then((value) => item.future.resolve(value)).catch((e) => item.future.reject(e)).finally(() => this._step(this._seqFutures.shift()));
1117
+ }
1118
+ async add(fn) {
1119
+ const future = new Future();
1120
+ this._seqFutures.push({ future, fn });
1121
+ this._step(this._seqFutures.shift());
1122
+ return future.asPromise();
1123
+ }
1124
+ };
1075
1125
  var ResolveOnce = class {
1076
1126
  constructor(ctx) {
1077
1127
  this._onceDone = false;
@@ -1110,6 +1160,8 @@ var ResolveOnce = class {
1110
1160
  this._onceFutures.length = 0;
1111
1161
  }).catch((e) => {
1112
1162
  this._onceError = e;
1163
+ this._onceOk = false;
1164
+ this._onceValue = void 0;
1113
1165
  this._onceDone = true;
1114
1166
  this._onceFutures.forEach((f) => f.reject(this._onceError));
1115
1167
  this._onceFutures.length = 0;
@@ -1118,32 +1170,48 @@ var ResolveOnce = class {
1118
1170
  return future.asPromise();
1119
1171
  }
1120
1172
  };
1121
- var KeyedResolvOnce = class {
1122
- constructor() {
1173
+ var Keyed = class {
1174
+ constructor(factory) {
1123
1175
  this._map = /* @__PURE__ */ new Map();
1176
+ this.factory = factory;
1177
+ }
1178
+ async asyncGet(key) {
1179
+ return this.get(await key());
1124
1180
  }
1125
1181
  get(key) {
1126
1182
  if (typeof key === "function") {
1127
1183
  key = key();
1128
1184
  }
1129
- let resolveOnce = this._map.get(key);
1130
- if (!resolveOnce) {
1131
- resolveOnce = new ResolveOnce(key);
1132
- this._map.set(key, resolveOnce);
1185
+ let keyed = this._map.get(key);
1186
+ if (!keyed) {
1187
+ keyed = this.factory(key);
1188
+ this._map.set(key, keyed);
1133
1189
  }
1134
- return resolveOnce;
1190
+ return keyed;
1135
1191
  }
1136
1192
  reset() {
1137
- this._map.forEach((resolveOnce) => resolveOnce.reset());
1193
+ this._map.forEach((keyed) => keyed.reset());
1138
1194
  this._map.clear();
1139
1195
  }
1140
1196
  };
1197
+ var KeyedResolvOnce = class extends Keyed {
1198
+ constructor() {
1199
+ super((key) => new ResolveOnce(key));
1200
+ }
1201
+ };
1202
+ var KeyedResolvSeq = class extends Keyed {
1203
+ constructor() {
1204
+ super((key) => new ResolveSeq(key));
1205
+ }
1206
+ };
1141
1207
  // Annotate the CommonJS export names for ESM import in node:
1142
1208
  0 && (module.exports = {
1143
1209
  Future,
1144
1210
  IDMode,
1145
1211
  IsLogger,
1212
+ Keyed,
1146
1213
  KeyedResolvOnce,
1214
+ KeyedResolvSeq,
1147
1215
  Level,
1148
1216
  LevelHandlerImpl,
1149
1217
  LogCollector,
@@ -1154,6 +1222,7 @@ var KeyedResolvOnce = class {
1154
1222
  Option,
1155
1223
  RandomMode,
1156
1224
  ResolveOnce,
1225
+ ResolveSeq,
1157
1226
  Result,
1158
1227
  ResultError,
1159
1228
  ResultOK,
package/index.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/logger.ts","../../src/sys_abstraction.ts","../../src/time.ts","../../src/base_sys_abstraction.ts","../../src/web/web_sys_abstraction.ts","../../src/logger_impl.ts","../../src/test/log_collector.ts","../../src/test/mock_logger.ts","../../src/result.ts","../../src/option.ts","../../src/future.ts","../../src/resolve-once.ts"],"sourcesContent":["export * from \"./file_service\";\nexport * from \"./logger_impl\";\nexport * from \"./logger\";\nexport * from \"./sys_abstraction\";\nexport * from \"./time\";\nexport * from \"./test/log_collector\";\nexport * from \"./test/mock_logger\";\nexport * from \"./result\";\nexport * from \"./option\";\nexport * from \"./future\";\nexport * from \"./resolve-once\";\n","import { Result } from \"./result\";\n\nexport enum Level {\n WARN = \"warn\",\n DEBUG = \"debug\",\n INFO = \"info\",\n ERROR = \"error\",\n}\n\nexport type Serialized = string | number | boolean;\nexport type FnSerialized = () => Serialized;\nexport interface LoggerInterface<R> {\n Module(key: string): R;\n // if modules is empty, set for all Levels\n EnableLevel(level: Level, ...modules: string[]): R;\n DisableLevel(level: Level, ...modules: string[]): R;\n\n SetDebug(...modules: (string | string[])[]): R;\n\n Ref(key: string, action: { toString: () => string } | FnSerialized): R;\n Result<T>(key: string, res: Result<T>): R;\n // default key url\n Url(url: URL, key?: string): R;\n\n Str(key: string, value?: string): R;\n Error(): R;\n Warn(): R;\n Debug(): R;\n Log(): R;\n WithLevel(level: Level): R;\n\n Err(err: unknown): R; // could be Error, or something which coerces to string\n Info(): R;\n Timestamp(): R;\n Any(key: string, value: unknown): R;\n Dur(key: string, nsec: number): R;\n Uint64(key: string, value: number): R;\n Int(key: string, value: number): R;\n Bool(key: string, value: unknown): R;\n}\n\nexport function IsLogger(obj: unknown): obj is Logger {\n return (\n typeof obj === \"object\" &&\n [\n \"Module\",\n \"EnableLevel\",\n \"DisableLevel\",\n \"SetDebug\",\n \"Str\",\n \"Error\",\n \"Warn\",\n \"Debug\",\n \"Log\",\n \"WithLevel\",\n \"Err\",\n \"Info\",\n \"Timestamp\",\n \"Any\",\n \"Dur\",\n \"Uint64\",\n ]\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n .map((fn) => typeof (obj as any)[fn] === \"function\")\n .reduce((a, b) => a && b, true)\n );\n}\n\nexport interface WithLogger extends LoggerInterface<WithLogger> {\n Logger(): Logger;\n}\n\nexport interface AsError {\n AsError(): Error;\n}\n\nexport interface Logger extends LoggerInterface<Logger> {\n With(): WithLogger;\n\n Msg(...args: string[]): AsError;\n Flush(): Promise<void>;\n}\n","import { FileService } from \"./file_service\";\nimport { Time } from \"./time\";\n\nexport enum TimeMode {\n REAL = \"real\",\n CONST = \"const\",\n STEP = \"step\",\n}\n\nexport enum RandomMode {\n CONST = \"const\",\n STEP = \"step\",\n RANDOM = \"random\",\n}\n\nexport enum IDMode {\n UUID = \"uuid\",\n CONST = \"const\",\n STEP = \"step\",\n}\n\nexport function String2TimeMode(s?: string): TimeMode {\n switch (s?.toLowerCase()) {\n case \"real\":\n return TimeMode.REAL;\n case \"const\":\n return TimeMode.CONST;\n case \"step\":\n return TimeMode.STEP;\n default:\n return TimeMode.REAL;\n }\n}\n\nexport type VoidFunc = () => void | Promise<void>;\n\nexport interface SystemService {\n Env(): Record<string, string>;\n Args(): string[];\n OnExit(hdl: VoidFunc): VoidFunc;\n Exit(code: number): void;\n}\n\nexport interface SysAbstraction {\n Time(): Time;\n Stdout(): WritableStream<Uint8Array>;\n Stderr(): WritableStream<Uint8Array>;\n NextId(): string;\n Random0ToValue(value: number): number;\n System(): SystemService;\n FileSystem(): FileService;\n}\n","export abstract class Time {\n abstract Now(): Date;\n abstract Sleep(duration: Duration): Promise<void>;\n TimeSince(start: Date): Duration {\n const now = this.Now();\n return now.getTime() - start.getTime();\n }\n}\n\nexport type Duration = number;\n\nexport enum TimeUnits {\n Microsecond = 1,\n // eslint-disable-next-line @typescript-eslint/prefer-literal-enum-member\n Second = 1000 * Microsecond,\n // eslint-disable-next-line @typescript-eslint/prefer-literal-enum-member\n Minute = 60 * Second,\n // eslint-disable-next-line @typescript-eslint/prefer-literal-enum-member\n Hour = 60 * Minute,\n}\n","import { FileService } from \"./file_service\";\nimport { TimeMode, RandomMode, IDMode, SystemService, VoidFunc, SysAbstraction } from \"./sys_abstraction\";\nimport { Time } from \"./time\";\n\nexport class SysTime extends Time {\n Now(): Date {\n return new Date();\n }\n Sleep(duration: number): Promise<void> {\n return new Promise((resolve) => {\n setTimeout(() => {\n resolve();\n }, duration);\n });\n }\n}\n\nexport class ConstTime extends Time {\n Now(): Date {\n return new Date(2021, 1, 1, 0, 0, 0, 0);\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n Sleep(duration: number): Promise<void> {\n return Promise.resolve();\n }\n}\n\nexport class StepTime extends Time {\n _step: Date;\n constructor() {\n super();\n this._step = new ConstTime().Now();\n }\n Now() {\n if (this._step.getTime() === 0) {\n this._step = new ConstTime().Now();\n return this._step;\n }\n this._step = new Date(this._step.getTime() + 1000);\n return this._step;\n }\n Sleep(duration: number): Promise<void> {\n this._step = new Date(this._step.getTime() + duration);\n return Promise.resolve();\n }\n}\n\nexport function TimeFactory(timeMode: TimeMode): Time {\n switch (timeMode) {\n case TimeMode.REAL:\n return new SysTime();\n case TimeMode.CONST:\n return new ConstTime();\n case TimeMode.STEP:\n return new StepTime();\n }\n return new SysTime();\n}\n\nexport class RandomService {\n readonly _mode: RandomMode;\n _step = 0;\n constructor(mode: RandomMode) {\n this._mode = mode;\n }\n Random0ToValue(value: number): number {\n switch (this._mode) {\n case RandomMode.CONST:\n return 0.5 * value;\n case RandomMode.STEP:\n this._step += 0.0001;\n return this._step * value;\n case RandomMode.RANDOM:\n return Math.random() * value;\n default:\n throw new Error(\"Unknown RandomMode\");\n }\n }\n}\n\nexport class IdService {\n readonly _mode: IDMode;\n _step = 0;\n constructor(mode?: IDMode) {\n if (!mode) {\n mode = IDMode.UUID;\n }\n this._mode = mode;\n }\n NextId(): string {\n switch (this._mode) {\n case IDMode.UUID:\n return crypto.randomUUID();\n case IDMode.CONST:\n return \"VeryUniqueID\";\n case IDMode.STEP:\n return `STEPId-${this._step++}`;\n default:\n throw new Error(\"Unknown IDMode\");\n }\n }\n}\n\nexport interface BaseSysAbstractionParams {\n readonly FileSystem: FileService;\n readonly SystemService: SystemService;\n}\n\nexport interface ExitHandler {\n readonly hdl: VoidFunc;\n readonly id: string;\n}\n\nexport interface ExitService {\n injectExitHandlers(hdls: ExitHandler[]): void;\n exit(code: number): void;\n}\n\nconst decoder = new TextDecoder();\nexport class BaseSysAbstraction {\n readonly _time = new SysTime();\n readonly _stdout = new WritableStream({\n write(chunk) {\n return new Promise((resolve) => {\n const decoded = decoder.decode(chunk);\n console.log(decoded.trimEnd());\n resolve();\n });\n },\n });\n readonly _stderr = new WritableStream({\n write(chunk) {\n return new Promise((resolve) => {\n const decoded = decoder.decode(chunk);\n console.error(decoded.trimEnd());\n resolve();\n });\n },\n });\n\n readonly _idService = new IdService();\n readonly _randomService = new RandomService(RandomMode.RANDOM);\n readonly _fileSystem: FileService;\n readonly _systemService: SystemService;\n\n constructor(params: BaseSysAbstractionParams) {\n this._fileSystem = params.FileSystem;\n this._systemService = params.SystemService;\n }\n}\n\nexport interface WrapperSysAbstractionParams {\n readonly TimeMode?: TimeMode;\n readonly IdMode?: IDMode;\n readonly Stdout?: WritableStream<Uint8Array>;\n readonly Stderr?: WritableStream<Uint8Array>;\n readonly RandomMode?: RandomMode;\n readonly FileSystem?: FileService;\n readonly SystemService?: SystemService;\n}\n\nexport class WrapperSysAbstraction implements SysAbstraction {\n readonly _time: Time;\n readonly _stdout: WritableStream<Uint8Array>;\n readonly _stderr: WritableStream<Uint8Array>;\n readonly _idService: IdService;\n readonly _randomService: RandomService;\n readonly _fileSystem: FileService;\n readonly _systemService: SystemService;\n constructor(base: BaseSysAbstraction, params?: WrapperSysAbstractionParams) {\n this._time = base._time;\n this._stdout = base._stdout;\n this._stderr = base._stderr;\n this._idService = base._idService;\n this._randomService = base._randomService;\n this._fileSystem = base._fileSystem;\n this._systemService = base._systemService;\n if (params) {\n if (params.TimeMode) {\n this._time = TimeFactory(params.TimeMode);\n }\n if (params.Stdout) {\n this._stdout = params.Stdout;\n }\n if (params.Stderr) {\n this._stderr = params.Stderr;\n }\n if (params.IdMode) {\n this._idService = new IdService(params.IdMode);\n }\n if (params.RandomMode) {\n this._randomService = new RandomService(params.RandomMode);\n }\n if (params.FileSystem) {\n this._fileSystem = params.FileSystem;\n }\n if (params.SystemService) {\n this._systemService = params.SystemService;\n }\n }\n }\n Time(): Time {\n return this._time;\n }\n NextId(): string {\n return this._idService.NextId();\n }\n Random0ToValue(value: number): number {\n return this._randomService.Random0ToValue(value);\n }\n Stdout(): WritableStream {\n return this._stdout;\n }\n Stderr(): WritableStream {\n return this._stderr;\n }\n\n System(): SystemService {\n return this._systemService;\n }\n FileSystem(): FileService {\n return this._fileSystem;\n }\n}\n// export const BaseSysAbstraction = new BaseSysAbstractionImpl()\n","import { BaseSysAbstraction, WrapperSysAbstraction, WrapperSysAbstractionParams } from \"../base_sys_abstraction\";\nimport { FileService, NamedWritableStream } from \"../file_service\";\nimport { SysAbstraction, SystemService, VoidFunc } from \"../sys_abstraction\";\n\nclass WebFileService implements FileService {\n get baseDir(): string {\n throw new Error(\"basedir-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n create(fname: string): Promise<NamedWritableStream> {\n throw new Error(\"create-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n readFileString(fname: string): Promise<string> {\n throw new Error(\"readFileString-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n writeFileString(fname: string, content: string): Promise<void> {\n throw new Error(\"writeFileString-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abs(fname: string): string {\n throw new Error(\"abs-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n join(...paths: string[]): string {\n throw new Error(\"join-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n relative(from: string, to?: string | undefined): string {\n throw new Error(\"relative-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n dirname(fname: string): string {\n throw new Error(\"dirname-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n basename(fname: string): string {\n throw new Error(\"basename-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n nodeImport(fname: string): string {\n throw new Error(\"nodeImport-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n isAbsolute(fname: string): boolean {\n throw new Error(\"isAbsolute-Method not implemented.\");\n }\n}\n\nclass WebSystemService implements SystemService {\n Env(): Record<string, string> {\n throw new Error(\"Env-Method not implemented.\");\n }\n Args(): string[] {\n throw new Error(\"Args-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n OnExit(hdl: VoidFunc): VoidFunc {\n throw new Error(\"OnExit-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n Exit(code: number): void {\n throw new Error(\"Exit-Method not implemented.\");\n }\n}\n\nlet my: BaseSysAbstraction | undefined = undefined;\nexport function WebSysAbstraction(param?: WrapperSysAbstractionParams): SysAbstraction {\n if (!my) {\n my = new BaseSysAbstraction({\n FileSystem: new WebFileService(),\n SystemService: new WebSystemService(),\n });\n }\n return new WrapperSysAbstraction(my, param);\n}\n","// import { v4 } from \"uuid\";\nimport { AsError, FnSerialized, Level, Logger, Serialized, WithLogger } from \"./logger\";\nimport { WebSysAbstraction } from \"./web/web_sys_abstraction\";\nimport { SysAbstraction } from \"./sys_abstraction\";\nimport { Result } from \"./result\";\n\nconst encoder = new TextEncoder();\n\nclass LogValue {\n constructor(readonly fn: FnSerialized) {}\n value(): Serialized {\n return this.fn();\n }\n}\n\nfunction resolveLogValue(val: JsonRecord): Record<string, Serialized> {\n const ret: Record<string, Serialized> = {};\n Object.keys(val).forEach((key) => {\n const v = val[key];\n if (v instanceof LogValue) {\n ret[key] = v.value();\n }\n });\n return ret;\n}\n\nfunction logValue(val: Serialized | FnSerialized | JsonRecord): LogValue {\n if (typeof val === \"function\") {\n return new LogValue(val);\n }\n switch (typeof val) {\n case \"string\":\n return new LogValue(() => val.toString());\n case \"number\":\n return new LogValue(() => val);\n case \"boolean\":\n return new LogValue(() => val);\n case \"object\":\n return new LogValue(() => JSON.stringify(val));\n default:\n throw new Error(`Invalid type:${typeof val}`);\n }\n}\n\ntype JsonRecord = Record<string, LogValue>;\n\nexport interface LevelHandler {\n enableLevel(level: Level, ...modules: string[]): void;\n disableLevel(level: Level, ...modules: string[]): void;\n setDebug(...modules: (string | string[])[]): void;\n isEnabled(ilevel: unknown, module: unknown): boolean;\n}\n\nexport class LevelHandlerImpl implements LevelHandler {\n readonly _globalLevels = new Set<Level>([Level.INFO, Level.ERROR, Level.WARN]);\n readonly _modules = new Map<string, Set<Level>>();\n enableLevel(level: Level, ...modules: string[]): void {\n if (modules.length == 0) {\n this._globalLevels.add(level);\n return;\n }\n this.forModules(\n level,\n (p) => {\n this._modules.set(p, new Set([...this._globalLevels, level]));\n },\n ...modules,\n );\n }\n disableLevel(level: Level, ...modules: string[]): void {\n if (modules.length == 0) {\n this._globalLevels.delete(level);\n return;\n }\n this.forModules(\n level,\n (p) => {\n this._modules.delete(p);\n },\n ...modules,\n );\n }\n\n forModules(level: Level, fnAction: (p: string) => void, ...modules: (string | string[])[]): void {\n for (const m of modules.flat()) {\n const parts = m\n .split(\",\")\n .map((s) => s.trim())\n .filter((s) => s.length > 0);\n for (const p of parts) {\n fnAction(p);\n }\n }\n }\n setDebug(...modules: (string | string[])[]): void {\n this.forModules(\n Level.DEBUG,\n (p) => {\n this._modules.set(p, new Set([...this._globalLevels, Level.DEBUG]));\n },\n ...modules,\n );\n }\n isEnabled(ilevel: unknown, module: unknown): boolean {\n const level = ilevel as Level; // what if it's not a level?\n if (module !== undefined) {\n const levels = this._modules.get(module as string);\n if (levels && levels.has(level)) {\n return true;\n }\n }\n if (level === undefined) {\n // this is a plain log\n return true;\n }\n return this._globalLevels.has(level);\n }\n}\n\nconst levelSingleton = new LevelHandlerImpl();\n\n// globalThis[Symbol(\"levelSingleton\")] = new LevelHandlerImpl()\n\nexport class LogWriter {\n readonly _out: WritableStream<Uint8Array>;\n readonly _toFlush: (() => Promise<void>)[] = [];\n\n constructor(out: WritableStream<Uint8Array>) {\n this._out = out;\n }\n\n write(encoded: Uint8Array) {\n const my = async () => {\n // const val = Math.random();\n // console.log(\">>>My:\", val)\n try {\n const writer = this._out.getWriter();\n await writer.ready;\n await writer.write(encoded);\n await writer.releaseLock();\n } catch (err) {\n console.error(\"Chunk error:\", err);\n }\n // console.log(\"<<<My:\", val)\n };\n this._toFlush.push(my);\n this._flush();\n }\n\n _flushIsRunning = false;\n _flushDoneFns = Array<() => void>();\n _flush(toFlush: (() => Promise<void>)[] | undefined = undefined, done?: () => void): void {\n if (done) {\n this._flushDoneFns.push(done);\n }\n\n if (this._toFlush.length == 0) {\n // console.log(\"Flush is stopped\", this._toFlush.length)\n this._flushIsRunning = false;\n this._flushDoneFns.forEach((fn) => fn());\n this._flushDoneFns = [];\n return;\n }\n\n if (!toFlush && this._toFlush.length == 1 && !this._flushIsRunning) {\n this._flushIsRunning = true;\n // console.log(\"Flush is started\", this._toFlush.length)\n } else if (!toFlush) {\n // console.log(\"flush queue check but is running\", this._toFlush.length)\n return;\n }\n\n // console.log(\">>>Msg:\", this._toFlush.length)\n const my = this._toFlush.shift();\n my?.().finally(() => {\n // console.log(\"<<<Msg:\", this._toFlush.length)\n this._flush(this._toFlush);\n });\n }\n}\n\nexport interface LoggerImplParams {\n readonly out?: WritableStream<Uint8Array>;\n readonly logWriter?: LogWriter;\n readonly sys?: SysAbstraction;\n readonly withAttributes?: JsonRecord;\n readonly levelHandler?: LevelHandler;\n}\nexport class LoggerImpl implements Logger {\n readonly _sys: SysAbstraction;\n readonly _attributes: JsonRecord = {};\n readonly _withAttributes: JsonRecord;\n readonly _logWriter: LogWriter;\n readonly _levelHandler: LevelHandler;\n // readonly _id: string = \"logger-\" + Math.random().toString(36)\n\n constructor(params?: LoggerImplParams) {\n if (!params) {\n params = {};\n }\n if (!params.sys) {\n this._sys = WebSysAbstraction();\n } else {\n this._sys = params.sys;\n }\n if (params.logWriter) {\n this._logWriter = params.logWriter;\n } else {\n if (!params.out) {\n this._logWriter = new LogWriter(this._sys.Stdout());\n } else {\n this._logWriter = new LogWriter(params.out);\n }\n }\n if (!params.withAttributes) {\n this._withAttributes = {};\n } else {\n this._withAttributes = { ...params.withAttributes };\n }\n this._attributes = { ...this._withAttributes };\n if (params.levelHandler) {\n this._levelHandler = params.levelHandler;\n } else {\n this._levelHandler = levelSingleton;\n }\n // console.log(\"LoggerImpl\", this._id, this._attributes, this._withAttributes)\n }\n\n EnableLevel(level: Level, ...modules: string[]): Logger {\n this._levelHandler.enableLevel(level, ...modules);\n return this;\n }\n DisableLevel(level: Level, ...modules: string[]): Logger {\n this._levelHandler.disableLevel(level, ...modules);\n return this;\n }\n\n Module(key: string): Logger {\n this._attributes[\"module\"] = logValue(key);\n this._withAttributes[\"module\"] = logValue(key);\n return this;\n }\n SetDebug(...modules: (string | string[])[]): Logger {\n this._levelHandler.setDebug(...modules);\n\n return this;\n }\n\n Timestamp(): Logger {\n this._attributes[\"ts\"] = logValue(this._sys.Time().Now().toISOString());\n return this;\n }\n Warn(): Logger {\n this._attributes[\"level\"] = logValue(Level.WARN);\n return this;\n }\n Log(): Logger {\n return this;\n }\n Debug(): Logger {\n this._attributes[\"level\"] = logValue(Level.DEBUG);\n return this;\n }\n Error(): Logger {\n this._attributes[\"level\"] = logValue(Level.ERROR);\n return this;\n }\n Info(): Logger {\n this._attributes[\"level\"] = logValue(Level.INFO);\n return this;\n }\n Err(err: unknown): Logger {\n if (err instanceof Error) {\n this._attributes[\"error\"] = logValue(err.message);\n } else {\n this._attributes[\"error\"] = logValue(\"\" + err);\n }\n return this;\n }\n WithLevel(l: Level): Logger {\n this._attributes[\"level\"] = logValue(l);\n return this;\n }\n\n Ref(key: string, action: { toString: () => string } | FnSerialized): Logger {\n if (typeof action === \"function\") {\n this._attributes[key] = logValue(action as FnSerialized);\n } else if (typeof action.toString === \"function\") {\n this._attributes[key] = logValue(() => action.toString());\n } else {\n this._attributes[key] = logValue(\"INVALID REF\");\n }\n return this;\n }\n Bool(key: string, value: unknown): Logger {\n this._attributes[key] = logValue(!!value);\n return this;\n }\n Result<T>(key: string, res: Result<T, Error>): Logger {\n if (res.isOk()) {\n this._attributes[key] = logValue(res.Ok() as Serialized);\n } else {\n this.Err(res.Err());\n }\n return this;\n }\n\n Url(url: URL, key = \"url\"): Logger {\n this.Ref(key, () => url.toString());\n return this;\n }\n\n Str(key: string, value: string): Logger {\n this._attributes[key] = logValue(value);\n return this;\n }\n\n Any(key: string, value: string | number | boolean | JsonRecord): Logger {\n this._attributes[key] = logValue(value);\n return this;\n }\n Dur(key: string, nsec: number): Logger {\n this._attributes[key] = logValue(`${nsec}ms`);\n // new Intl.DurationFormat(\"en\", { style: \"narrow\" }).format(nsec);\n return this;\n }\n Uint64(key: string, value: number): Logger {\n this._attributes[key] = logValue(value);\n return this;\n }\n Int(key: string, value: number): Logger {\n return this.Uint64(key, value);\n }\n\n async Flush(): Promise<void> {\n return new Promise((resolve) => {\n this._logWriter._flush(undefined, resolve);\n });\n }\n\n With(): WithLogger {\n // console.log(\"WithLoggerBuilder.With\", this._id, this._attributes, this._withAttributes);\n return new WithLoggerBuilder(\n new LoggerImpl({\n logWriter: this._logWriter,\n sys: this._sys,\n levelHandler: this._levelHandler,\n withAttributes: {\n module: this._attributes[\"module\"],\n ...this._withAttributes,\n },\n }),\n );\n }\n\n _resetAttributes(fn: () => Error): Error {\n const ret = fn();\n Object.keys(this._attributes).forEach((key) => {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this._attributes[key];\n });\n Object.assign(this._attributes, this._withAttributes);\n return ret;\n }\n Msg(...args: string[]): AsError {\n const error = this._resetAttributes(() => {\n const doWrite = this._levelHandler.isEnabled(this._attributes[\"level\"]?.value(), this._attributes[\"module\"]?.value());\n this._attributes[\"msg\"] = logValue(args.join(\" \"));\n const msg = this._attributes[\"msg\"].value();\n if (typeof msg === \"string\" && !msg.trim().length) {\n delete this._attributes[\"msg\"];\n }\n if (this._attributes[\"ts\"]?.value() === \"ETERNITY\") {\n this.Timestamp();\n }\n const str = JSON.stringify(resolveLogValue(this._attributes));\n if (doWrite) {\n const encoded = encoder.encode(str + \"\\n\");\n this._logWriter.write(encoded);\n }\n return new Error(str);\n });\n return {\n AsError: () => error,\n };\n }\n}\n\nclass WithLoggerBuilder implements WithLogger {\n readonly _li: LoggerImpl;\n constructor(li: LoggerImpl) {\n this._li = li;\n }\n\n Logger(): Logger {\n Object.assign(this._li._withAttributes, this._li._attributes);\n return this._li;\n }\n\n EnableLevel(level: Level, ...modules: string[]): WithLogger {\n this._li._levelHandler.enableLevel(level, ...modules);\n return this;\n }\n DisableLevel(level: Level, ...modules: string[]): WithLogger {\n this._li._levelHandler.enableLevel(level, ...modules);\n return this;\n }\n\n Module(key: string): WithLogger {\n this._li.Module(key);\n return this;\n }\n SetDebug(...modules: (string | string[])[]): WithLogger {\n this._li.SetDebug(...modules);\n return this;\n }\n\n Str(key: string, value: string): WithLogger {\n this._li.Str(key, value);\n return this;\n }\n\n Ref(key: string, action: Serialized | FnSerialized): WithLogger {\n this._li.Ref(key, action);\n return this;\n }\n Bool(key: string, value: unknown): WithLogger {\n this._li.Bool(key, value);\n return this;\n }\n Result<T>(key: string, res: Result<T, Error>): WithLogger {\n this._li.Result(key, res);\n return this;\n }\n Url(url: URL, key?: string): WithLogger {\n this._li.Url(url, key);\n return this;\n }\n Int(key: string, value: number): WithLogger {\n this._li.Int(key, value);\n return this;\n }\n\n Log(): WithLogger {\n this._li.Log();\n return this;\n }\n\n WithLevel(level: Level): WithLogger {\n this._li.WithLevel(level);\n return this;\n }\n\n Error(): WithLogger {\n this._li.Error();\n return this;\n }\n Warn(): WithLogger {\n this._li.Error();\n return this;\n }\n Debug(): WithLogger {\n this._li.Debug();\n return this;\n }\n Err(err: unknown): WithLogger {\n this._li.Err(err);\n return this;\n }\n Info(): WithLogger {\n this._li.Info();\n return this;\n }\n Timestamp(): WithLogger {\n this._li._attributes[\"ts\"] = logValue(\"ETERNITY\");\n return this;\n }\n Any(key: string, value: JsonRecord): WithLogger {\n this._li.Any(key, value);\n return this;\n }\n Dur(key: string, nsec: number): WithLogger {\n this._li.Dur(key, nsec);\n return this;\n }\n Uint64(key: string, value: number): WithLogger {\n this._li.Uint64(key, value);\n return this;\n }\n}\n","class LogWriter implements WritableStreamDefaultWriter<Uint8Array> {\n readonly _bufferArr: Uint8Array[] = [];\n\n _resolveClosed: (value?: PromiseLike<undefined>) => void;\n closed: Promise<undefined>;\n desiredSize: number | null = null;\n ready: Promise<undefined> = Promise.resolve(undefined);\n\n constructor() {\n this._resolveClosed = () => {\n // do nothing\n };\n this.closed = new Promise((resolve) => {\n this._resolveClosed = resolve;\n });\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any\n abort(reason?: any): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n close(): Promise<void> {\n this._resolveClosed();\n return Promise.resolve(undefined);\n }\n releaseLock(): void {\n // do nothing\n }\n write(chunk?: Uint8Array): Promise<void> {\n chunk && this._bufferArr.push(chunk);\n return Promise.resolve(undefined);\n }\n}\n\nexport class LogCollector implements WritableStream<Uint8Array> {\n readonly locked: boolean = false;\n _writer?: LogWriter;\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abort(reason?: Uint8Array): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n async close(): Promise<void> {\n if (this._writer) {\n const ret = await this._writer.close();\n this._writer = undefined;\n return ret;\n }\n return Promise.resolve(undefined);\n }\n\n getWriter(): WritableStreamDefaultWriter<Uint8Array> {\n if (!this._writer) {\n this._writer = new LogWriter();\n }\n return this._writer;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Logs(): any[] {\n if (!this._writer) {\n return [];\n }\n const jsonNlStr = new TextDecoder().decode(\n new Uint8Array(\n (function* (res: Uint8Array[]) {\n for (const x of res) {\n yield* x;\n }\n })(this._writer._bufferArr),\n ),\n );\n const splitStr = jsonNlStr.split(\"\\n\");\n const filterStr = splitStr.filter((a) => a.length);\n const mapStr = filterStr.map((a) => JSON.parse(a));\n return mapStr;\n }\n}\n","import { Logger } from \"../logger\";\nimport { LevelHandlerImpl, LoggerImpl } from \"../logger_impl\";\nimport { SysAbstraction } from \"../sys_abstraction\";\nimport { LogCollector } from \"./log_collector\";\n\nexport interface MockLoggerReturn {\n readonly logger: Logger;\n readonly logCollector: LogCollector;\n}\n\nexport function MockLogger(params?: {\n readonly sys?: SysAbstraction;\n moduleName?: string | string[];\n readonly disableDebug?: boolean;\n}): MockLoggerReturn {\n const lc = new LogCollector();\n let modNames = [\"MockLogger\"];\n if (typeof params?.moduleName === \"string\") {\n modNames = [params?.moduleName];\n } else if (Array.isArray(params?.moduleName)) {\n modNames = [...params.moduleName, ...modNames];\n }\n const logger = new LoggerImpl({\n out: lc,\n sys: params?.sys,\n levelHandler: new LevelHandlerImpl(),\n })\n .With()\n .Module(modNames[0])\n .Logger();\n !params?.disableDebug && logger.SetDebug(...modNames);\n return {\n logCollector: lc,\n logger,\n };\n}\n","export abstract class Result<T, E = Error> {\n static Ok<T>(t: T): Result<T, Error> {\n return new ResultOK(t);\n }\n static Err<T extends Error = Error>(t: T | string): Result<never, T> {\n if (typeof t === \"string\") {\n return new ResultError(new Error(t) as T);\n }\n return new ResultError(t);\n }\n static Is<T>(t: unknown): t is Result<T> {\n return t instanceof Result;\n }\n\n isOk(): boolean {\n return this.is_ok();\n }\n isErr(): boolean {\n return this.is_err();\n }\n\n Ok(): T {\n return this.unwrap();\n }\n Err(): E {\n return this.unwrap_err();\n }\n\n abstract is_ok(): boolean;\n abstract is_err(): boolean;\n abstract unwrap(): T;\n abstract unwrap_err(): E;\n}\n\nexport class ResultOK<T> extends Result<T, Error> {\n private _t: T;\n constructor(t: T) {\n super();\n this._t = t;\n }\n is_ok(): boolean {\n return true;\n }\n is_err(): boolean {\n return false;\n }\n unwrap_err(): Error {\n throw new Error(\"Result is Ok\");\n }\n unwrap(): T {\n return this._t;\n }\n}\n\nexport class ResultError<T extends Error> extends Result<never, T> {\n private _error: T;\n constructor(t: T) {\n super();\n this._error = t;\n }\n is_ok(): boolean {\n return false;\n }\n is_err(): boolean {\n return true;\n }\n unwrap(): never {\n throw new Error(`Result is Err: ${this._error}`);\n }\n unwrap_err(): T {\n return this._error;\n }\n}\n\nexport type WithoutResult<T> = T extends Result<infer U> ? U : T;\n\n/*\n\ntype FinalizedResult<T> = {\n result: T;\n scopeResult?: Result<void>;\n finally: () => Promise<void>;\n}\n\ntype exection2ResultParam<T> = {\n init: () => Promise<T>;\n inScope?: (t: T) => Promise<void>;\n cleanup: (t: T) => Promise<void>;\n\n}\n\nasync function expection2Result<T>({fn, inScope, cleanup}: exection2ResultParam<T>): Promise<Result<FinalizedResult<T>>> {\n try {\n const res = await fn();\n if (inScope) {\n try {\n await inScope?.(res)\n } catch (err) {\n return Result.Err(err as Error)\n }\n await cleanup(res)\n return Result.Ok({\n result: res,\n finally: async () => { }\n })\n }\n return Result.Ok({\n result: res ,\n finally: async () => {\n return cleanup(res)\n }\n })\n } catch (err) {\n return Result.Err(err as Error)\n }\n}\n*/\n\n// await expection2Result({\n// init: openDB,\n// inScope: (res) => {\n// res.query()\n// },\n// cleanup: async (y) => {\n// await y.close()\n// }\n// })\n// async function openDB() {\n// try {\n// const opendb = await openDB()\n// return Result.Ok({\n// openDB,\n// finally: async () => {\n// await opendb.close()\n// }})\n// } catch (err) {\n// return Result.Err(err)\n// }\n// }\n// }\n","export abstract class Option<T> {\n static Some<T>(t: T): Option<T> {\n return new Some(t);\n }\n\n static None<T>(): Option<T> {\n return new None();\n }\n\n static Is<T>(t: unknown): t is Option<T> {\n return t instanceof Option;\n }\n\n IsNone(): boolean {\n return this.is_none();\n }\n\n IsSome(): boolean {\n return this.is_some();\n }\n Unwrap(): T {\n return this.unwrap();\n }\n\n abstract is_none(): boolean;\n abstract is_some(): boolean;\n abstract unwrap(): T;\n}\n\nexport class Some<T> extends Option<T> {\n private _t: T;\n constructor(_t: T) {\n super();\n this._t = _t;\n }\n\n is_none(): boolean {\n return false;\n }\n is_some(): boolean {\n return true;\n }\n unwrap(): T {\n return this._t;\n }\n}\n\nexport class None<T> extends Option<T> {\n is_none(): boolean {\n return true;\n }\n is_some(): boolean {\n return false;\n }\n unwrap(): T {\n throw new Error(\"None.unwrap\");\n }\n}\n\nexport type WithoutOption<T> = T extends Option<infer U> ? U : T;\n","export class Future<T> {\n readonly #promise: Promise<T>;\n #resolveFn: (value: T) => void = () => {\n throw new Error(\"This Promise is not working as expected.\");\n };\n #rejectFn: (reason: unknown) => void = () => {\n throw new Error(\"This Promise is not working as expected.\");\n };\n\n constructor() {\n this.#promise = new Promise<T>((resolve, reject) => {\n this.#resolveFn = resolve;\n this.#rejectFn = reject;\n });\n }\n\n async asPromise(): Promise<T> {\n return this.#promise;\n }\n\n resolve(value: T) {\n this.#resolveFn(value);\n }\n reject(reason: unknown) {\n this.#rejectFn(reason);\n }\n}\n","import { Future } from \"./future\";\n\nexport class ResolveOnce<T, C = void> {\n _onceDone = false;\n readonly _onceFutures: Future<T>[] = [];\n _onceOk = false;\n _onceValue?: T;\n _onceError?: Error;\n\n readonly ctx: C;\n\n constructor(ctx?: C) {\n this.ctx = ctx as C;\n }\n\n get ready() {\n return this._onceDone;\n }\n\n reset() {\n this._onceDone = false;\n this._onceOk = false;\n this._onceValue = undefined;\n this._onceError = undefined;\n this._onceFutures.length = 0;\n }\n\n async once(fn: (c: C) => Promise<T>): Promise<T> {\n if (this._onceDone) {\n if (this._onceError) {\n return Promise.reject(this._onceError);\n }\n if (this._onceOk) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return Promise.resolve(this._onceValue!);\n }\n throw new Error(\"ResolveOnce.once impossible\");\n }\n const future = new Future<T>();\n this._onceFutures.push(future);\n if (this._onceFutures.length === 1) {\n fn(this.ctx)\n .then((value) => {\n this._onceValue = value;\n this._onceOk = true;\n this._onceDone = true;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this._onceFutures.forEach((f) => f.resolve(this._onceValue!));\n this._onceFutures.length = 0;\n })\n .catch((e) => {\n this._onceError = e as Error;\n this._onceDone = true;\n this._onceFutures.forEach((f) => f.reject(this._onceError));\n this._onceFutures.length = 0;\n });\n }\n return future.asPromise();\n }\n}\n\nexport class KeyedResolvOnce<T, K = string> {\n private readonly _map = new Map<K, ResolveOnce<T, K>>();\n\n get(key: K | (() => K)): ResolveOnce<T, K> {\n if (typeof key === \"function\") {\n key = (key as () => K)();\n }\n let resolveOnce = this._map.get(key);\n if (!resolveOnce) {\n resolveOnce = new ResolveOnce<T, K>(key);\n this._map.set(key, resolveOnce);\n }\n return resolveOnce;\n }\n\n reset() {\n this._map.forEach((resolveOnce) => resolveOnce.reset());\n this._map.clear();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAK,QAAL,kBAAKA,WAAL;AACL,EAAAA,OAAA,UAAO;AACP,EAAAA,OAAA,WAAQ;AACR,EAAAA,OAAA,UAAO;AACP,EAAAA,OAAA,WAAQ;AAJE,SAAAA;AAAA,GAAA;AAuCL,SAAS,SAAS,KAA6B;AACpD,SACE,OAAO,QAAQ,YACf;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,EAEG,IAAI,CAAC,OAAO,OAAQ,IAAY,EAAE,MAAM,UAAU,EAClD,OAAO,CAAC,GAAG,MAAM,KAAK,GAAG,IAAI;AAEpC;;;AC/DO,IAAK,WAAL,kBAAKC,cAAL;AACL,EAAAA,UAAA,UAAO;AACP,EAAAA,UAAA,WAAQ;AACR,EAAAA,UAAA,UAAO;AAHG,SAAAA;AAAA,GAAA;AA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MAAM,CAAC,MAAM;AACZ,aAAK,aAAa;AAClB,aAAK,YAAY;AACjB,aAAK,aAAa,QAAQ,CAAC,MAAM,EAAE,OAAO,KAAK,UAAU,CAAC;AAC1D,aAAK,aAAa,SAAS;AAAA,MAC7B,CAAC;AAAA,IACL;AACA,WAAO,OAAO,UAAU;AAAA,EAC1B;AACF;AAEO,IAAM,kBAAN,MAAqC;AAAA,EAArC;AACL,SAAiB,OAAO,oBAAI,IAA0B;AAAA;AAAA,EAEtD,IAAI,KAAuC;AACzC,QAAI,OAAO,QAAQ,YAAY;AAC7B,YAAO,IAAgB;AAAA,IACzB;AACA,QAAI,cAAc,KAAK,KAAK,IAAI,GAAG;AACnC,QAAI,CAAC,aAAa;AAChB,oBAAc,IAAI,YAAkB,GAAG;AACvC,WAAK,KAAK,IAAI,KAAK,WAAW;AAAA,IAChC;AACA,WAAO;AAAA,EACT;AAAA,EAEA,QAAQ;AACN,SAAK,KAAK,QAAQ,CAAC,gBAAgB,YAAY,MAAM,CAAC;AACtD,SAAK,KAAK,MAAM;AAAA,EAClB;AACF;","names":["Level","TimeMode","RandomMode","IDMode","TimeUnits","module","my","LogWriter"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/logger.ts","../../src/sys_abstraction.ts","../../src/time.ts","../../src/base_sys_abstraction.ts","../../src/web/web_sys_abstraction.ts","../../src/logger_impl.ts","../../src/test/log_collector.ts","../../src/test/mock_logger.ts","../../src/result.ts","../../src/option.ts","../../src/future.ts","../../src/resolve-once.ts"],"sourcesContent":["export * from \"./file_service\";\nexport * from \"./logger_impl\";\nexport * from \"./logger\";\nexport * from \"./sys_abstraction\";\nexport * from \"./time\";\nexport * from \"./test/log_collector\";\nexport * from \"./test/mock_logger\";\nexport * from \"./result\";\nexport * from \"./option\";\nexport * from \"./future\";\nexport * from \"./resolve-once\";\n","import { Result } from \"./result\";\n\nexport enum Level {\n WARN = \"warn\",\n DEBUG = \"debug\",\n INFO = \"info\",\n ERROR = \"error\",\n}\n\nexport type Serialized = string | number | boolean;\nexport type FnSerialized = () => Serialized;\nexport interface LoggerInterface<R> {\n Module(key: string): R;\n // if modules is empty, set for all Levels\n EnableLevel(level: Level, ...modules: string[]): R;\n DisableLevel(level: Level, ...modules: string[]): R;\n\n SetDebug(...modules: (string | string[])[]): R;\n\n Ref(key: string, action: { toString: () => string } | FnSerialized): R;\n Result<T>(key: string, res: Result<T>): R;\n // default key url\n Url(url: URL, key?: string): R;\n // len\n Len(value: object | { length: number } | string | undefined | null, key?: string): R;\n\n Str(key: string, value?: string): R;\n Error(): R;\n Warn(): R;\n Debug(): R;\n Log(): R;\n WithLevel(level: Level): R;\n\n Err(err: unknown): R; // could be Error, or something which coerces to string\n Info(): R;\n Timestamp(): R;\n Any(key: string, value: unknown): R;\n Dur(key: string, nsec: number): R;\n Uint64(key: string, value: number): R;\n Int(key: string, value: number): R;\n Bool(key: string, value: unknown): R;\n}\n\nexport function IsLogger(obj: unknown): obj is Logger {\n return (\n typeof obj === \"object\" &&\n [\n \"Module\",\n \"EnableLevel\",\n \"DisableLevel\",\n \"SetDebug\",\n \"Str\",\n \"Error\",\n \"Warn\",\n \"Debug\",\n \"Log\",\n \"WithLevel\",\n \"Err\",\n \"Info\",\n \"Timestamp\",\n \"Any\",\n \"Dur\",\n \"Uint64\",\n ]\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n .map((fn) => typeof (obj as any)[fn] === \"function\")\n .reduce((a, b) => a && b, true)\n );\n}\n\nexport interface WithLogger extends LoggerInterface<WithLogger> {\n Logger(): Logger;\n}\n\nexport interface AsError {\n AsError(): Error;\n}\n\nexport interface Logger extends LoggerInterface<Logger> {\n With(): WithLogger;\n\n Msg(...args: string[]): AsError;\n Flush(): Promise<void>;\n}\n","import { FileService } from \"./file_service\";\nimport { Time } from \"./time\";\n\nexport enum TimeMode {\n REAL = \"real\",\n CONST = \"const\",\n STEP = \"step\",\n}\n\nexport enum RandomMode {\n CONST = \"const\",\n STEP = \"step\",\n RANDOM = \"random\",\n}\n\nexport enum IDMode {\n UUID = \"uuid\",\n CONST = \"const\",\n STEP = \"step\",\n}\n\nexport function String2TimeMode(s?: string): TimeMode {\n switch (s?.toLowerCase()) {\n case \"real\":\n return TimeMode.REAL;\n case \"const\":\n return TimeMode.CONST;\n case \"step\":\n return TimeMode.STEP;\n default:\n return TimeMode.REAL;\n }\n}\n\nexport type VoidFunc = () => void | Promise<void>;\n\nexport interface SystemService {\n Env(): Record<string, string>;\n Args(): string[];\n OnExit(hdl: VoidFunc): VoidFunc;\n Exit(code: number): void;\n}\n\nexport interface SysAbstraction {\n Time(): Time;\n Stdout(): WritableStream<Uint8Array>;\n Stderr(): WritableStream<Uint8Array>;\n NextId(): string;\n Random0ToValue(value: number): number;\n System(): SystemService;\n FileSystem(): FileService;\n}\n","export abstract class Time {\n abstract Now(): Date;\n abstract Sleep(duration: Duration): Promise<void>;\n TimeSince(start: Date): Duration {\n const now = this.Now();\n return now.getTime() - start.getTime();\n }\n}\n\nexport type Duration = number;\n\nexport enum TimeUnits {\n Microsecond = 1,\n // eslint-disable-next-line @typescript-eslint/prefer-literal-enum-member\n Second = 1000 * Microsecond,\n // eslint-disable-next-line @typescript-eslint/prefer-literal-enum-member\n Minute = 60 * Second,\n // eslint-disable-next-line @typescript-eslint/prefer-literal-enum-member\n Hour = 60 * Minute,\n}\n","import { FileService } from \"./file_service\";\nimport { TimeMode, RandomMode, IDMode, SystemService, VoidFunc, SysAbstraction } from \"./sys_abstraction\";\nimport { Time } from \"./time\";\n\nexport class SysTime extends Time {\n Now(): Date {\n return new Date();\n }\n Sleep(duration: number): Promise<void> {\n return new Promise((resolve) => {\n setTimeout(() => {\n resolve();\n }, duration);\n });\n }\n}\n\nexport class ConstTime extends Time {\n Now(): Date {\n return new Date(2021, 1, 1, 0, 0, 0, 0);\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n Sleep(duration: number): Promise<void> {\n return Promise.resolve();\n }\n}\n\nexport class StepTime extends Time {\n _step: Date;\n constructor() {\n super();\n this._step = new ConstTime().Now();\n }\n Now() {\n if (this._step.getTime() === 0) {\n this._step = new ConstTime().Now();\n return this._step;\n }\n this._step = new Date(this._step.getTime() + 1000);\n return this._step;\n }\n Sleep(duration: number): Promise<void> {\n this._step = new Date(this._step.getTime() + duration);\n return Promise.resolve();\n }\n}\n\nexport function TimeFactory(timeMode: TimeMode): Time {\n switch (timeMode) {\n case TimeMode.REAL:\n return new SysTime();\n case TimeMode.CONST:\n return new ConstTime();\n case TimeMode.STEP:\n return new StepTime();\n }\n return new SysTime();\n}\n\nexport class RandomService {\n readonly _mode: RandomMode;\n _step = 0;\n constructor(mode: RandomMode) {\n this._mode = mode;\n }\n Random0ToValue(value: number): number {\n switch (this._mode) {\n case RandomMode.CONST:\n return 0.5 * value;\n case RandomMode.STEP:\n this._step += 0.0001;\n return this._step * value;\n case RandomMode.RANDOM:\n return Math.random() * value;\n default:\n throw new Error(\"Unknown RandomMode\");\n }\n }\n}\n\nexport class IdService {\n readonly _mode: IDMode;\n _step = 0;\n constructor(mode?: IDMode) {\n if (!mode) {\n mode = IDMode.UUID;\n }\n this._mode = mode;\n }\n NextId(): string {\n switch (this._mode) {\n case IDMode.UUID:\n return crypto.randomUUID();\n case IDMode.CONST:\n return \"VeryUniqueID\";\n case IDMode.STEP:\n return `STEPId-${this._step++}`;\n default:\n throw new Error(\"Unknown IDMode\");\n }\n }\n}\n\nexport interface BaseSysAbstractionParams {\n readonly FileSystem: FileService;\n readonly SystemService: SystemService;\n}\n\nexport interface ExitHandler {\n readonly hdl: VoidFunc;\n readonly id: string;\n}\n\nexport interface ExitService {\n injectExitHandlers(hdls: ExitHandler[]): void;\n exit(code: number): void;\n}\n\nconst decoder = new TextDecoder();\nexport class BaseSysAbstraction {\n readonly _time = new SysTime();\n readonly _stdout = new WritableStream({\n write(chunk) {\n return new Promise((resolve) => {\n const decoded = decoder.decode(chunk);\n console.log(decoded.trimEnd());\n resolve();\n });\n },\n });\n readonly _stderr = new WritableStream({\n write(chunk) {\n return new Promise((resolve) => {\n const decoded = decoder.decode(chunk);\n console.error(decoded.trimEnd());\n resolve();\n });\n },\n });\n\n readonly _idService = new IdService();\n readonly _randomService = new RandomService(RandomMode.RANDOM);\n readonly _fileSystem: FileService;\n readonly _systemService: SystemService;\n\n constructor(params: BaseSysAbstractionParams) {\n this._fileSystem = params.FileSystem;\n this._systemService = params.SystemService;\n }\n}\n\nexport interface WrapperSysAbstractionParams {\n readonly TimeMode?: TimeMode;\n readonly IdMode?: IDMode;\n readonly Stdout?: WritableStream<Uint8Array>;\n readonly Stderr?: WritableStream<Uint8Array>;\n readonly RandomMode?: RandomMode;\n readonly FileSystem?: FileService;\n readonly SystemService?: SystemService;\n}\n\nexport class WrapperSysAbstraction implements SysAbstraction {\n readonly _time: Time;\n readonly _stdout: WritableStream<Uint8Array>;\n readonly _stderr: WritableStream<Uint8Array>;\n readonly _idService: IdService;\n readonly _randomService: RandomService;\n readonly _fileSystem: FileService;\n readonly _systemService: SystemService;\n constructor(base: BaseSysAbstraction, params?: WrapperSysAbstractionParams) {\n this._time = base._time;\n this._stdout = base._stdout;\n this._stderr = base._stderr;\n this._idService = base._idService;\n this._randomService = base._randomService;\n this._fileSystem = base._fileSystem;\n this._systemService = base._systemService;\n if (params) {\n if (params.TimeMode) {\n this._time = TimeFactory(params.TimeMode);\n }\n if (params.Stdout) {\n this._stdout = params.Stdout;\n }\n if (params.Stderr) {\n this._stderr = params.Stderr;\n }\n if (params.IdMode) {\n this._idService = new IdService(params.IdMode);\n }\n if (params.RandomMode) {\n this._randomService = new RandomService(params.RandomMode);\n }\n if (params.FileSystem) {\n this._fileSystem = params.FileSystem;\n }\n if (params.SystemService) {\n this._systemService = params.SystemService;\n }\n }\n }\n Time(): Time {\n return this._time;\n }\n NextId(): string {\n return this._idService.NextId();\n }\n Random0ToValue(value: number): number {\n return this._randomService.Random0ToValue(value);\n }\n Stdout(): WritableStream {\n return this._stdout;\n }\n Stderr(): WritableStream {\n return this._stderr;\n }\n\n System(): SystemService {\n return this._systemService;\n }\n FileSystem(): FileService {\n return this._fileSystem;\n }\n}\n// export const BaseSysAbstraction = new BaseSysAbstractionImpl()\n","import { BaseSysAbstraction, WrapperSysAbstraction, WrapperSysAbstractionParams } from \"../base_sys_abstraction\";\nimport { FileService, NamedWritableStream } from \"../file_service\";\nimport { SysAbstraction, SystemService, VoidFunc } from \"../sys_abstraction\";\n\nclass WebFileService implements FileService {\n get baseDir(): string {\n throw new Error(\"basedir-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n create(fname: string): Promise<NamedWritableStream> {\n throw new Error(\"create-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n readFileString(fname: string): Promise<string> {\n throw new Error(\"readFileString-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n writeFileString(fname: string, content: string): Promise<void> {\n throw new Error(\"writeFileString-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abs(fname: string): string {\n throw new Error(\"abs-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n join(...paths: string[]): string {\n throw new Error(\"join-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n relative(from: string, to?: string | undefined): string {\n throw new Error(\"relative-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n dirname(fname: string): string {\n throw new Error(\"dirname-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n basename(fname: string): string {\n throw new Error(\"basename-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n nodeImport(fname: string): string {\n throw new Error(\"nodeImport-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n isAbsolute(fname: string): boolean {\n throw new Error(\"isAbsolute-Method not implemented.\");\n }\n}\n\nclass WebSystemService implements SystemService {\n Env(): Record<string, string> {\n throw new Error(\"Env-Method not implemented.\");\n }\n Args(): string[] {\n throw new Error(\"Args-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n OnExit(hdl: VoidFunc): VoidFunc {\n throw new Error(\"OnExit-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n Exit(code: number): void {\n throw new Error(\"Exit-Method not implemented.\");\n }\n}\n\nlet my: BaseSysAbstraction | undefined = undefined;\nexport function WebSysAbstraction(param?: WrapperSysAbstractionParams): SysAbstraction {\n if (!my) {\n my = new BaseSysAbstraction({\n FileSystem: new WebFileService(),\n SystemService: new WebSystemService(),\n });\n }\n return new WrapperSysAbstraction(my, param);\n}\n","// import { v4 } from \"uuid\";\nimport { AsError, FnSerialized, Level, Logger, Serialized, WithLogger } from \"./logger\";\nimport { WebSysAbstraction } from \"./web/web_sys_abstraction\";\nimport { SysAbstraction } from \"./sys_abstraction\";\nimport { Result } from \"./result\";\n\nconst encoder = new TextEncoder();\n\nclass LogValue {\n constructor(readonly fn: FnSerialized) {}\n value(): Serialized {\n return this.fn();\n }\n}\n\nfunction resolveLogValue(val: JsonRecord): Record<string, Serialized> {\n const ret: Record<string, Serialized> = {};\n Object.keys(val).forEach((key) => {\n const v = val[key];\n if (v instanceof LogValue) {\n ret[key] = v.value();\n }\n });\n return ret;\n}\n\nfunction logValue(val: Serialized | FnSerialized | JsonRecord | undefined | null): LogValue {\n switch (typeof val) {\n case \"function\":\n return new LogValue(val);\n case \"string\":\n return new LogValue(() => val.toString());\n case \"number\":\n return new LogValue(() => val);\n case \"boolean\":\n return new LogValue(() => val);\n case \"object\":\n return new LogValue(() => JSON.stringify(val));\n default:\n if (!val) {\n return new LogValue(() => \"--Falsy--\");\n }\n throw new Error(`Invalid type:${typeof val}`);\n }\n}\n\ntype JsonRecord = Record<string, LogValue>;\n\nexport interface LevelHandler {\n enableLevel(level: Level, ...modules: string[]): void;\n disableLevel(level: Level, ...modules: string[]): void;\n setDebug(...modules: (string | string[])[]): void;\n isEnabled(ilevel: unknown, module: unknown): boolean;\n}\n\nexport class LevelHandlerImpl implements LevelHandler {\n readonly _globalLevels = new Set<Level>([Level.INFO, Level.ERROR, Level.WARN]);\n readonly _modules = new Map<string, Set<Level>>();\n enableLevel(level: Level, ...modules: string[]): void {\n if (modules.length == 0) {\n this._globalLevels.add(level);\n return;\n }\n this.forModules(\n level,\n (p) => {\n this._modules.set(p, new Set([...this._globalLevels, level]));\n },\n ...modules,\n );\n }\n disableLevel(level: Level, ...modules: string[]): void {\n if (modules.length == 0) {\n this._globalLevels.delete(level);\n return;\n }\n this.forModules(\n level,\n (p) => {\n this._modules.delete(p);\n },\n ...modules,\n );\n }\n\n forModules(level: Level, fnAction: (p: string) => void, ...modules: (string | string[])[]): void {\n for (const m of modules.flat()) {\n const parts = m\n .split(\",\")\n .map((s) => s.trim())\n .filter((s) => s.length > 0);\n for (const p of parts) {\n fnAction(p);\n }\n }\n }\n setDebug(...modules: (string | string[])[]): void {\n this.forModules(\n Level.DEBUG,\n (p) => {\n this._modules.set(p, new Set([...this._globalLevels, Level.DEBUG]));\n },\n ...modules,\n );\n }\n isEnabled(ilevel: unknown, module: unknown): boolean {\n const level = ilevel as Level; // what if it's not a level?\n if (module !== undefined) {\n const levels = this._modules.get(module as string);\n if (levels && levels.has(level)) {\n return true;\n }\n }\n if (level === undefined) {\n // this is a plain log\n return true;\n }\n return this._globalLevels.has(level);\n }\n}\n\nconst levelSingleton = new LevelHandlerImpl();\n\n// globalThis[Symbol(\"levelSingleton\")] = new LevelHandlerImpl()\n\nexport class LogWriter {\n readonly _out: WritableStream<Uint8Array>;\n readonly _toFlush: (() => Promise<void>)[] = [];\n\n constructor(out: WritableStream<Uint8Array>) {\n this._out = out;\n }\n\n write(encoded: Uint8Array) {\n const my = async () => {\n // const val = Math.random();\n // console.log(\">>>My:\", val)\n try {\n const writer = this._out.getWriter();\n await writer.ready;\n await writer.write(encoded);\n await writer.releaseLock();\n } catch (err) {\n console.error(\"Chunk error:\", err);\n }\n // console.log(\"<<<My:\", val)\n };\n this._toFlush.push(my);\n this._flush();\n }\n\n _flushIsRunning = false;\n _flushDoneFns = Array<() => void>();\n _flush(toFlush: (() => Promise<void>)[] | undefined = undefined, done?: () => void): void {\n if (done) {\n this._flushDoneFns.push(done);\n }\n\n if (this._toFlush.length == 0) {\n // console.log(\"Flush is stopped\", this._toFlush.length)\n this._flushIsRunning = false;\n this._flushDoneFns.forEach((fn) => fn());\n this._flushDoneFns = [];\n return;\n }\n\n if (!toFlush && this._toFlush.length == 1 && !this._flushIsRunning) {\n this._flushIsRunning = true;\n // console.log(\"Flush is started\", this._toFlush.length)\n } else if (!toFlush) {\n // console.log(\"flush queue check but is running\", this._toFlush.length)\n return;\n }\n\n // console.log(\">>>Msg:\", this._toFlush.length)\n const my = this._toFlush.shift();\n my?.().finally(() => {\n // console.log(\"<<<Msg:\", this._toFlush.length)\n this._flush(this._toFlush);\n });\n }\n}\n\nexport interface LoggerImplParams {\n readonly out?: WritableStream<Uint8Array>;\n readonly logWriter?: LogWriter;\n readonly sys?: SysAbstraction;\n readonly withAttributes?: JsonRecord;\n readonly levelHandler?: LevelHandler;\n}\nexport class LoggerImpl implements Logger {\n readonly _sys: SysAbstraction;\n readonly _attributes: JsonRecord = {};\n readonly _withAttributes: JsonRecord;\n readonly _logWriter: LogWriter;\n readonly _levelHandler: LevelHandler;\n // readonly _id: string = \"logger-\" + Math.random().toString(36)\n\n constructor(params?: LoggerImplParams) {\n if (!params) {\n params = {};\n }\n if (!params.sys) {\n this._sys = WebSysAbstraction();\n } else {\n this._sys = params.sys;\n }\n if (params.logWriter) {\n this._logWriter = params.logWriter;\n } else {\n if (!params.out) {\n this._logWriter = new LogWriter(this._sys.Stdout());\n } else {\n this._logWriter = new LogWriter(params.out);\n }\n }\n if (!params.withAttributes) {\n this._withAttributes = {};\n } else {\n this._withAttributes = { ...params.withAttributes };\n }\n this._attributes = { ...this._withAttributes };\n if (params.levelHandler) {\n this._levelHandler = params.levelHandler;\n } else {\n this._levelHandler = levelSingleton;\n }\n // console.log(\"LoggerImpl\", this._id, this._attributes, this._withAttributes)\n }\n\n EnableLevel(level: Level, ...modules: string[]): Logger {\n this._levelHandler.enableLevel(level, ...modules);\n return this;\n }\n DisableLevel(level: Level, ...modules: string[]): Logger {\n this._levelHandler.disableLevel(level, ...modules);\n return this;\n }\n\n Module(key: string): Logger {\n this._attributes[\"module\"] = logValue(key);\n this._withAttributes[\"module\"] = logValue(key);\n return this;\n }\n SetDebug(...modules: (string | string[])[]): Logger {\n this._levelHandler.setDebug(...modules);\n\n return this;\n }\n\n Timestamp(): Logger {\n // this is called with .call from _produceError where this\n // this is crafted to have _sys and _attributes\n // CAUTION so done use other ref from this\n this._attributes[\"ts\"] = logValue(this._sys.Time().Now().toISOString());\n return this;\n }\n Warn(): Logger {\n this._attributes[\"level\"] = logValue(Level.WARN);\n return this;\n }\n Log(): Logger {\n return this;\n }\n Debug(): Logger {\n this._attributes[\"level\"] = logValue(Level.DEBUG);\n return this;\n }\n Error(): Logger {\n this._attributes[\"level\"] = logValue(Level.ERROR);\n return this;\n }\n Info(): Logger {\n this._attributes[\"level\"] = logValue(Level.INFO);\n return this;\n }\n Err(err: unknown): Logger {\n if (err instanceof Error) {\n this._attributes[\"error\"] = logValue(err.message);\n } else {\n this._attributes[\"error\"] = logValue(\"\" + err);\n }\n return this;\n }\n WithLevel(l: Level): Logger {\n this._attributes[\"level\"] = logValue(l);\n return this;\n }\n\n Ref(key: string, action: { toString: () => string } | FnSerialized): Logger {\n if (typeof action === \"function\") {\n this._attributes[key] = logValue(action as FnSerialized);\n } else if (typeof action.toString === \"function\") {\n this._attributes[key] = logValue(() => action.toString());\n } else {\n this._attributes[key] = logValue(\"INVALID REF\");\n }\n return this;\n }\n Bool(key: string, value: unknown): Logger {\n this._attributes[key] = logValue(!!value);\n return this;\n }\n Result<T>(key: string, res: Result<T, Error>): Logger {\n if (res.isOk()) {\n this._attributes[key] = logValue(res.Ok() as Serialized);\n } else {\n this.Err(res.Err());\n }\n return this;\n }\n\n Len(value: unknown, key = \"len\"): Logger {\n if (Array.isArray(value)) {\n this._attributes[key] = logValue(() => value.length);\n } else if (typeof value === \"string\") {\n this._attributes[key] = logValue(() => value.length);\n } else if (typeof value === \"object\" && value !== null) {\n this._attributes[key] = logValue(() => Object.keys(value).length);\n } else {\n this.Int(key, -1);\n }\n return this;\n }\n\n Url(url: URL, key = \"url\"): Logger {\n this.Ref(key, () => url.toString());\n return this;\n }\n\n Str(key: string, value?: string): Logger {\n this._attributes[key] = logValue(value);\n return this;\n }\n\n Any(key: string, value: string | number | boolean | JsonRecord): Logger {\n this._attributes[key] = logValue(value);\n return this;\n }\n Dur(key: string, nsec: number): Logger {\n this._attributes[key] = logValue(`${nsec}ms`);\n // new Intl.DurationFormat(\"en\", { style: \"narrow\" }).format(nsec);\n return this;\n }\n Uint64(key: string, value: number): Logger {\n this._attributes[key] = logValue(value);\n return this;\n }\n Int(key: string, value: number): Logger {\n return this.Uint64(key, value);\n }\n\n async Flush(): Promise<void> {\n return new Promise((resolve) => {\n this._logWriter._flush(undefined, resolve);\n });\n }\n\n With(): WithLogger {\n // console.log(\"WithLoggerBuilder.With\", this._id, this._attributes, this._withAttributes);\n return new WithLoggerBuilder(\n new LoggerImpl({\n logWriter: this._logWriter,\n sys: this._sys,\n levelHandler: this._levelHandler,\n withAttributes: {\n module: this._attributes[\"module\"],\n ...this._withAttributes,\n },\n }),\n );\n }\n\n _resetAttributes(fn: () => () => string): () => string {\n const ret = fn();\n Object.keys(this._attributes).forEach((key) => {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this._attributes[key];\n });\n Object.assign(this._attributes, this._withAttributes);\n return ret;\n }\n _produceError(attr: JsonRecord, ...args: string[]): string {\n attr[\"msg\"] = logValue(args.join(\" \"));\n const msg = attr[\"msg\"].value();\n if (typeof msg === \"string\" && !msg.trim().length) {\n delete attr[\"msg\"];\n }\n if (attr[\"ts\"]?.value() === \"ETERNITY\") {\n // hacky but it works\n this.Timestamp.call({\n _sys: this._sys,\n _attributes: attr,\n });\n }\n return JSON.stringify(resolveLogValue(attr));\n }\n\n Msg(...args: string[]): AsError {\n const fnError = this._resetAttributes(() => {\n const doWrite = this._levelHandler.isEnabled(this._attributes[\"level\"]?.value(), this._attributes[\"module\"]?.value());\n let fnRet = () => this._produceError({ ...this._attributes }, ...args);\n if (doWrite) {\n const str = this._produceError({ ...this._attributes }, ...args);\n const encoded = encoder.encode(str + \"\\n\");\n this._logWriter.write(encoded);\n fnRet = () => str;\n }\n return fnRet;\n });\n return {\n AsError: () => new Error(fnError()),\n };\n }\n}\n\nclass WithLoggerBuilder implements WithLogger {\n readonly _li: LoggerImpl;\n constructor(li: LoggerImpl) {\n this._li = li;\n }\n\n Logger(): Logger {\n Object.assign(this._li._withAttributes, this._li._attributes);\n return this._li;\n }\n\n EnableLevel(level: Level, ...modules: string[]): WithLogger {\n this._li._levelHandler.enableLevel(level, ...modules);\n return this;\n }\n DisableLevel(level: Level, ...modules: string[]): WithLogger {\n this._li._levelHandler.enableLevel(level, ...modules);\n return this;\n }\n\n Module(key: string): WithLogger {\n this._li.Module(key);\n return this;\n }\n SetDebug(...modules: (string | string[])[]): WithLogger {\n this._li.SetDebug(...modules);\n return this;\n }\n\n Str(key: string, value?: string): WithLogger {\n this._li.Str(key, value);\n return this;\n }\n\n Len(value: unknown, key?: string): WithLogger {\n this._li.Len(value, key);\n return this;\n }\n\n Ref(key: string, action: Serialized | FnSerialized): WithLogger {\n this._li.Ref(key, action);\n return this;\n }\n Bool(key: string, value: unknown): WithLogger {\n this._li.Bool(key, value);\n return this;\n }\n Result<T>(key: string, res: Result<T, Error>): WithLogger {\n this._li.Result(key, res);\n return this;\n }\n Url(url: URL, key?: string): WithLogger {\n this._li.Url(url, key);\n return this;\n }\n Int(key: string, value: number): WithLogger {\n this._li.Int(key, value);\n return this;\n }\n\n Log(): WithLogger {\n this._li.Log();\n return this;\n }\n\n WithLevel(level: Level): WithLogger {\n this._li.WithLevel(level);\n return this;\n }\n\n Error(): WithLogger {\n this._li.Error();\n return this;\n }\n Warn(): WithLogger {\n this._li.Error();\n return this;\n }\n Debug(): WithLogger {\n this._li.Debug();\n return this;\n }\n Err(err: unknown): WithLogger {\n this._li.Err(err);\n return this;\n }\n Info(): WithLogger {\n this._li.Info();\n return this;\n }\n Timestamp(): WithLogger {\n this._li._attributes[\"ts\"] = logValue(\"ETERNITY\");\n return this;\n }\n Any(key: string, value: JsonRecord): WithLogger {\n this._li.Any(key, value);\n return this;\n }\n Dur(key: string, nsec: number): WithLogger {\n this._li.Dur(key, nsec);\n return this;\n }\n Uint64(key: string, value: number): WithLogger {\n this._li.Uint64(key, value);\n return this;\n }\n}\n","class LogWriter implements WritableStreamDefaultWriter<Uint8Array> {\n readonly _bufferArr: Uint8Array[] = [];\n\n _resolveClosed: (value?: PromiseLike<undefined>) => void;\n closed: Promise<undefined>;\n desiredSize: number | null = null;\n ready: Promise<undefined> = Promise.resolve(undefined);\n\n constructor() {\n this._resolveClosed = () => {\n // do nothing\n };\n this.closed = new Promise((resolve) => {\n this._resolveClosed = resolve;\n });\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any\n abort(reason?: any): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n close(): Promise<void> {\n this._resolveClosed();\n return Promise.resolve(undefined);\n }\n releaseLock(): void {\n // do nothing\n }\n write(chunk?: Uint8Array): Promise<void> {\n chunk && this._bufferArr.push(chunk);\n return Promise.resolve(undefined);\n }\n}\n\nexport class LogCollector implements WritableStream<Uint8Array> {\n readonly locked: boolean = false;\n _writer?: LogWriter;\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abort(reason?: Uint8Array): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n async close(): Promise<void> {\n if (this._writer) {\n const ret = await this._writer.close();\n this._writer = undefined;\n return ret;\n }\n return Promise.resolve(undefined);\n }\n\n getWriter(): WritableStreamDefaultWriter<Uint8Array> {\n if (!this._writer) {\n this._writer = new LogWriter();\n }\n return this._writer;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Logs(): any[] {\n if (!this._writer) {\n return [];\n }\n const jsonNlStr = new TextDecoder().decode(\n new Uint8Array(\n (function* (res: Uint8Array[]) {\n for (const x of res) {\n yield* x;\n }\n })(this._writer._bufferArr),\n ),\n );\n const splitStr = jsonNlStr.split(\"\\n\");\n const filterStr = splitStr.filter((a) => a.length);\n const mapStr = filterStr.map((a) => JSON.parse(a));\n return mapStr;\n }\n}\n","import { Logger } from \"../logger\";\nimport { LevelHandlerImpl, LoggerImpl } from \"../logger_impl\";\nimport { SysAbstraction } from \"../sys_abstraction\";\nimport { LogCollector } from \"./log_collector\";\n\nexport interface MockLoggerReturn {\n readonly logger: Logger;\n readonly logCollector: LogCollector;\n}\n\nexport function MockLogger(params?: {\n readonly sys?: SysAbstraction;\n moduleName?: string | string[];\n readonly disableDebug?: boolean;\n}): MockLoggerReturn {\n const lc = new LogCollector();\n let modNames = [\"MockLogger\"];\n if (typeof params?.moduleName === \"string\") {\n modNames = [params?.moduleName];\n } else if (Array.isArray(params?.moduleName)) {\n modNames = [...params.moduleName, ...modNames];\n }\n const logger = new LoggerImpl({\n out: lc,\n sys: params?.sys,\n levelHandler: new LevelHandlerImpl(),\n })\n .With()\n .Module(modNames[0])\n .Logger();\n !params?.disableDebug && logger.SetDebug(...modNames);\n return {\n logCollector: lc,\n logger,\n };\n}\n","export abstract class Result<T, E = Error> {\n static Ok<T>(t: T): Result<T, Error> {\n return new ResultOK(t);\n }\n static Err<T extends Error = Error>(t: T | string): Result<never, T> {\n if (typeof t === \"string\") {\n return new ResultError(new Error(t) as T);\n }\n return new ResultError(t);\n }\n static Is<T>(t: unknown): t is Result<T> {\n return t instanceof Result;\n }\n\n isOk(): boolean {\n return this.is_ok();\n }\n isErr(): boolean {\n return this.is_err();\n }\n\n Ok(): T {\n return this.unwrap();\n }\n Err(): E {\n return this.unwrap_err();\n }\n\n abstract is_ok(): boolean;\n abstract is_err(): boolean;\n abstract unwrap(): T;\n abstract unwrap_err(): E;\n}\n\nexport class ResultOK<T> extends Result<T, Error> {\n private _t: T;\n constructor(t: T) {\n super();\n this._t = t;\n }\n is_ok(): boolean {\n return true;\n }\n is_err(): boolean {\n return false;\n }\n unwrap_err(): Error {\n throw new Error(\"Result is Ok\");\n }\n unwrap(): T {\n return this._t;\n }\n}\n\nexport class ResultError<T extends Error> extends Result<never, T> {\n private _error: T;\n constructor(t: T) {\n super();\n this._error = t;\n }\n is_ok(): boolean {\n return false;\n }\n is_err(): boolean {\n return true;\n }\n unwrap(): never {\n throw new Error(`Result is Err: ${this._error}`);\n }\n unwrap_err(): T {\n return this._error;\n }\n}\n\nexport type WithoutResult<T> = T extends Result<infer U> ? U : T;\n\n/*\n\ntype FinalizedResult<T> = {\n result: T;\n scopeResult?: Result<void>;\n finally: () => Promise<void>;\n}\n\ntype exection2ResultParam<T> = {\n init: () => Promise<T>;\n inScope?: (t: T) => Promise<void>;\n cleanup: (t: T) => Promise<void>;\n\n}\n\nasync function expection2Result<T>({fn, inScope, cleanup}: exection2ResultParam<T>): Promise<Result<FinalizedResult<T>>> {\n try {\n const res = await fn();\n if (inScope) {\n try {\n await inScope?.(res)\n } catch (err) {\n return Result.Err(err as Error)\n }\n await cleanup(res)\n return Result.Ok({\n result: res,\n finally: async () => { }\n })\n }\n return Result.Ok({\n result: res ,\n finally: async () => {\n return cleanup(res)\n }\n })\n } catch (err) {\n return Result.Err(err as Error)\n }\n}\n*/\n\n// await expection2Result({\n// init: openDB,\n// inScope: (res) => {\n// res.query()\n// },\n// cleanup: async (y) => {\n// await y.close()\n// }\n// })\n// async function openDB() {\n// try {\n// const opendb = await openDB()\n// return Result.Ok({\n// openDB,\n// finally: async () => {\n// await opendb.close()\n// }})\n// } catch (err) {\n// return Result.Err(err)\n// }\n// }\n// }\n","export abstract class Option<T> {\n static Some<T>(t: T): Option<T> {\n return new Some(t);\n }\n\n static None<T>(): Option<T> {\n return new None();\n }\n\n static Is<T>(t: unknown): t is Option<T> {\n return t instanceof Option;\n }\n\n IsNone(): boolean {\n return this.is_none();\n }\n\n IsSome(): boolean {\n return this.is_some();\n }\n Unwrap(): T {\n return this.unwrap();\n }\n\n abstract is_none(): boolean;\n abstract is_some(): boolean;\n abstract unwrap(): T;\n}\n\nexport class Some<T> extends Option<T> {\n private _t: T;\n constructor(_t: T) {\n super();\n this._t = _t;\n }\n\n is_none(): boolean {\n return false;\n }\n is_some(): boolean {\n return true;\n }\n unwrap(): T {\n return this._t;\n }\n}\n\nexport class None<T> extends Option<T> {\n is_none(): boolean {\n return true;\n }\n is_some(): boolean {\n return false;\n }\n unwrap(): T {\n throw new Error(\"None.unwrap\");\n }\n}\n\nexport type WithoutOption<T> = T extends Option<infer U> ? U : T;\n","export class Future<T> {\n readonly #promise: Promise<T>;\n #resolveFn: (value: T) => void = () => {\n throw new Error(\"This Promise is not working as expected.\");\n };\n #rejectFn: (reason: unknown) => void = () => {\n throw new Error(\"This Promise is not working as expected.\");\n };\n\n constructor() {\n this.#promise = new Promise<T>((resolve, reject) => {\n this.#resolveFn = resolve;\n this.#rejectFn = reject;\n });\n }\n\n async asPromise(): Promise<T> {\n return this.#promise;\n }\n\n resolve(value: T) {\n this.#resolveFn(value);\n }\n reject(reason: unknown) {\n this.#rejectFn(reason);\n }\n}\n","import { Future } from \"./future\";\n\ninterface ResolveSeqItem<T, C> {\n future: Future<T>;\n fn: (c: C) => Promise<T>;\n}\n\nexport class ResolveSeq<T, C = void> {\n readonly ctx: C;\n constructor(ctx?: C) {\n this.ctx = ctx as C;\n }\n reset() {\n /* noop */\n }\n async _step(item?: ResolveSeqItem<T, C> | undefined) {\n if (!item) {\n // done\n return;\n }\n item\n .fn(this.ctx)\n .then((value) => item.future.resolve(value))\n .catch((e) => item.future.reject(e as Error))\n .finally(() => this._step(this._seqFutures.shift()));\n }\n readonly _seqFutures: ResolveSeqItem<T, C>[] = [];\n async add(fn: (c: C) => Promise<T>): Promise<T> {\n const future = new Future<T>();\n this._seqFutures.push({ future, fn });\n this._step(this._seqFutures.shift());\n return future.asPromise();\n }\n}\n\nexport class ResolveOnce<T, C = void> {\n _onceDone = false;\n readonly _onceFutures: Future<T>[] = [];\n _onceOk = false;\n _onceValue?: T;\n _onceError?: Error;\n\n readonly ctx: C;\n\n constructor(ctx?: C) {\n this.ctx = ctx as C;\n }\n\n get ready() {\n return this._onceDone;\n }\n\n reset() {\n this._onceDone = false;\n this._onceOk = false;\n this._onceValue = undefined;\n this._onceError = undefined;\n this._onceFutures.length = 0;\n }\n\n async once(fn: (c: C) => Promise<T>): Promise<T> {\n if (this._onceDone) {\n if (this._onceError) {\n return Promise.reject(this._onceError);\n }\n if (this._onceOk) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return Promise.resolve(this._onceValue!);\n }\n throw new Error(\"ResolveOnce.once impossible\");\n }\n const future = new Future<T>();\n this._onceFutures.push(future);\n if (this._onceFutures.length === 1) {\n fn(this.ctx)\n .then((value) => {\n this._onceValue = value;\n this._onceOk = true;\n this._onceDone = true;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this._onceFutures.forEach((f) => f.resolve(this._onceValue!));\n this._onceFutures.length = 0;\n })\n .catch((e) => {\n this._onceError = e as Error;\n this._onceOk = false;\n this._onceValue = undefined;\n this._onceDone = true;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this._onceFutures.forEach((f) => f.reject(this._onceError!));\n this._onceFutures.length = 0;\n });\n }\n return future.asPromise();\n }\n}\n\nexport class Keyed<T extends { reset: () => void }, K = string> {\n private readonly _map = new Map<K, T>();\n\n readonly factory: (key: K) => T;\n constructor(factory: (key: K) => T) {\n this.factory = factory;\n }\n\n async asyncGet(key: () => Promise<K>): Promise<T> {\n return this.get(await key());\n }\n\n get(key: K | (() => K)): T {\n if (typeof key === \"function\") {\n key = (key as () => K)();\n }\n let keyed = this._map.get(key);\n if (!keyed) {\n keyed = this.factory(key);\n this._map.set(key, keyed);\n }\n return keyed;\n }\n\n reset() {\n this._map.forEach((keyed) => keyed.reset());\n this._map.clear();\n }\n}\n\nexport class KeyedResolvOnce<T, K = string> extends Keyed<ResolveOnce<T, K>, K> {\n constructor() {\n super((key) => new ResolveOnce<T, K>(key));\n }\n}\n\nexport class KeyedResolvSeq<T, K = string> extends Keyed<ResolveSeq<T, K>, K> {\n constructor() {\n super((key) => new ResolveSeq<T, K>(key));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAK,QAAL,kBAAKA,WAAL;AACL,EAAAA,OAAA,UAAO;AACP,EAAAA,OAAA,WAAQ;AACR,EAAAA,OAAA,UAAO;AACP,EAAAA,OAAA,WAAQ;AAJE,SAAAA;AAAA,GAAA;AAyCL,SAAS,SAAS,KAA6B;AACpD,SACE,OAAO,QAAQ,YACf;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,EAEG,IAAI,CAAC,OAAO,OAAQ,IAAY,EAAE,MAAM,UAAU,EAClD,OAAO,CAAC,GAAG,MAAM,KAAK,GAAG,IAAI;AAEpC;;;ACjEO,IAAK,WAAL,kBAAKC,cAAL;AACL,EAAAA,UAAA,UAAO;AACP,EAAAA,UAAA,WAAQ;AACR,EAAAA,UAAA,UAAO;AAHG,SAAAA;AAAA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B,GAAG,CAAC;AAAA,EAC1C;AACF;","names":["Level","TimeMode","RandomMode","IDMode","TimeUnits","module","my","LogWriter"]}
package/index.d.cts CHANGED
@@ -50,6 +50,9 @@ interface LoggerInterface<R> {
50
50
  } | FnSerialized): R;
51
51
  Result<T>(key: string, res: Result<T>): R;
52
52
  Url(url: URL, key?: string): R;
53
+ Len(value: object | {
54
+ length: number;
55
+ } | string | undefined | null, key?: string): R;
53
56
  Str(key: string, value?: string): R;
54
57
  Error(): R;
55
58
  Warn(): R;
@@ -139,15 +142,17 @@ declare class LoggerImpl implements Logger {
139
142
  } | FnSerialized): Logger;
140
143
  Bool(key: string, value: unknown): Logger;
141
144
  Result<T>(key: string, res: Result<T, Error>): Logger;
145
+ Len(value: unknown, key?: string): Logger;
142
146
  Url(url: URL, key?: string): Logger;
143
- Str(key: string, value: string): Logger;
147
+ Str(key: string, value?: string): Logger;
144
148
  Any(key: string, value: string | number | boolean | JsonRecord): Logger;
145
149
  Dur(key: string, nsec: number): Logger;
146
150
  Uint64(key: string, value: number): Logger;
147
151
  Int(key: string, value: number): Logger;
148
152
  Flush(): Promise<void>;
149
153
  With(): WithLogger;
150
- _resetAttributes(fn: () => Error): Error;
154
+ _resetAttributes(fn: () => () => string): () => string;
155
+ _produceError(attr: JsonRecord, ...args: string[]): string;
151
156
  Msg(...args: string[]): AsError;
152
157
  }
153
158
 
@@ -215,6 +220,18 @@ declare class Future<T> {
215
220
  reject(reason: unknown): void;
216
221
  }
217
222
 
223
+ interface ResolveSeqItem<T, C> {
224
+ future: Future<T>;
225
+ fn: (c: C) => Promise<T>;
226
+ }
227
+ declare class ResolveSeq<T, C = void> {
228
+ readonly ctx: C;
229
+ constructor(ctx?: C);
230
+ reset(): void;
231
+ _step(item?: ResolveSeqItem<T, C> | undefined): Promise<void>;
232
+ readonly _seqFutures: ResolveSeqItem<T, C>[];
233
+ add(fn: (c: C) => Promise<T>): Promise<T>;
234
+ }
218
235
  declare class ResolveOnce<T, C = void> {
219
236
  _onceDone: boolean;
220
237
  readonly _onceFutures: Future<T>[];
@@ -227,10 +244,21 @@ declare class ResolveOnce<T, C = void> {
227
244
  reset(): void;
228
245
  once(fn: (c: C) => Promise<T>): Promise<T>;
229
246
  }
230
- declare class KeyedResolvOnce<T, K = string> {
247
+ declare class Keyed<T extends {
248
+ reset: () => void;
249
+ }, K = string> {
231
250
  private readonly _map;
232
- get(key: K | (() => K)): ResolveOnce<T, K>;
251
+ readonly factory: (key: K) => T;
252
+ constructor(factory: (key: K) => T);
253
+ asyncGet(key: () => Promise<K>): Promise<T>;
254
+ get(key: K | (() => K)): T;
233
255
  reset(): void;
234
256
  }
257
+ declare class KeyedResolvOnce<T, K = string> extends Keyed<ResolveOnce<T, K>, K> {
258
+ constructor();
259
+ }
260
+ declare class KeyedResolvSeq<T, K = string> extends Keyed<ResolveSeq<T, K>, K> {
261
+ constructor();
262
+ }
235
263
 
236
- export { type AsError, type FnSerialized, Future, IsLogger, KeyedResolvOnce, Level, type LevelHandler, LevelHandlerImpl, LogCollector, LogWriter$1 as LogWriter, type Logger, LoggerImpl, type LoggerImplParams, type LoggerInterface, MockLogger, type MockLoggerReturn, None, Option, ResolveOnce, Result, ResultError, ResultOK, type Serialized, Some, SysAbstraction, type WithLogger, type WithoutOption, type WithoutResult };
264
+ export { type AsError, type FnSerialized, Future, IsLogger, Keyed, KeyedResolvOnce, KeyedResolvSeq, Level, type LevelHandler, LevelHandlerImpl, LogCollector, LogWriter$1 as LogWriter, type Logger, LoggerImpl, type LoggerImplParams, type LoggerInterface, MockLogger, type MockLoggerReturn, None, Option, ResolveOnce, ResolveSeq, Result, ResultError, ResultOK, type Serialized, Some, SysAbstraction, type WithLogger, type WithoutOption, type WithoutResult };
package/index.d.ts CHANGED
@@ -50,6 +50,9 @@ interface LoggerInterface<R> {
50
50
  } | FnSerialized): R;
51
51
  Result<T>(key: string, res: Result<T>): R;
52
52
  Url(url: URL, key?: string): R;
53
+ Len(value: object | {
54
+ length: number;
55
+ } | string | undefined | null, key?: string): R;
53
56
  Str(key: string, value?: string): R;
54
57
  Error(): R;
55
58
  Warn(): R;
@@ -139,15 +142,17 @@ declare class LoggerImpl implements Logger {
139
142
  } | FnSerialized): Logger;
140
143
  Bool(key: string, value: unknown): Logger;
141
144
  Result<T>(key: string, res: Result<T, Error>): Logger;
145
+ Len(value: unknown, key?: string): Logger;
142
146
  Url(url: URL, key?: string): Logger;
143
- Str(key: string, value: string): Logger;
147
+ Str(key: string, value?: string): Logger;
144
148
  Any(key: string, value: string | number | boolean | JsonRecord): Logger;
145
149
  Dur(key: string, nsec: number): Logger;
146
150
  Uint64(key: string, value: number): Logger;
147
151
  Int(key: string, value: number): Logger;
148
152
  Flush(): Promise<void>;
149
153
  With(): WithLogger;
150
- _resetAttributes(fn: () => Error): Error;
154
+ _resetAttributes(fn: () => () => string): () => string;
155
+ _produceError(attr: JsonRecord, ...args: string[]): string;
151
156
  Msg(...args: string[]): AsError;
152
157
  }
153
158
 
@@ -215,6 +220,18 @@ declare class Future<T> {
215
220
  reject(reason: unknown): void;
216
221
  }
217
222
 
223
+ interface ResolveSeqItem<T, C> {
224
+ future: Future<T>;
225
+ fn: (c: C) => Promise<T>;
226
+ }
227
+ declare class ResolveSeq<T, C = void> {
228
+ readonly ctx: C;
229
+ constructor(ctx?: C);
230
+ reset(): void;
231
+ _step(item?: ResolveSeqItem<T, C> | undefined): Promise<void>;
232
+ readonly _seqFutures: ResolveSeqItem<T, C>[];
233
+ add(fn: (c: C) => Promise<T>): Promise<T>;
234
+ }
218
235
  declare class ResolveOnce<T, C = void> {
219
236
  _onceDone: boolean;
220
237
  readonly _onceFutures: Future<T>[];
@@ -227,10 +244,21 @@ declare class ResolveOnce<T, C = void> {
227
244
  reset(): void;
228
245
  once(fn: (c: C) => Promise<T>): Promise<T>;
229
246
  }
230
- declare class KeyedResolvOnce<T, K = string> {
247
+ declare class Keyed<T extends {
248
+ reset: () => void;
249
+ }, K = string> {
231
250
  private readonly _map;
232
- get(key: K | (() => K)): ResolveOnce<T, K>;
251
+ readonly factory: (key: K) => T;
252
+ constructor(factory: (key: K) => T);
253
+ asyncGet(key: () => Promise<K>): Promise<T>;
254
+ get(key: K | (() => K)): T;
233
255
  reset(): void;
234
256
  }
257
+ declare class KeyedResolvOnce<T, K = string> extends Keyed<ResolveOnce<T, K>, K> {
258
+ constructor();
259
+ }
260
+ declare class KeyedResolvSeq<T, K = string> extends Keyed<ResolveSeq<T, K>, K> {
261
+ constructor();
262
+ }
235
263
 
236
- export { type AsError, type FnSerialized, Future, IsLogger, KeyedResolvOnce, Level, type LevelHandler, LevelHandlerImpl, LogCollector, LogWriter$1 as LogWriter, type Logger, LoggerImpl, type LoggerImplParams, type LoggerInterface, MockLogger, type MockLoggerReturn, None, Option, ResolveOnce, Result, ResultError, ResultOK, type Serialized, Some, SysAbstraction, type WithLogger, type WithoutOption, type WithoutResult };
264
+ export { type AsError, type FnSerialized, Future, IsLogger, Keyed, KeyedResolvOnce, KeyedResolvSeq, Level, type LevelHandler, LevelHandlerImpl, LogCollector, LogWriter$1 as LogWriter, type Logger, LoggerImpl, type LoggerImplParams, type LoggerInterface, MockLogger, type MockLoggerReturn, None, Option, ResolveOnce, ResolveSeq, Result, ResultError, ResultOK, type Serialized, Some, SysAbstraction, type WithLogger, type WithoutOption, type WithoutResult };
package/index.js CHANGED
@@ -67,10 +67,9 @@ function resolveLogValue(val) {
67
67
  return ret;
68
68
  }
69
69
  function logValue(val) {
70
- if (typeof val === "function") {
71
- return new LogValue(val);
72
- }
73
70
  switch (typeof val) {
71
+ case "function":
72
+ return new LogValue(val);
74
73
  case "string":
75
74
  return new LogValue(() => val.toString());
76
75
  case "number":
@@ -80,6 +79,9 @@ function logValue(val) {
80
79
  case "object":
81
80
  return new LogValue(() => JSON.stringify(val));
82
81
  default:
82
+ if (!val) {
83
+ return new LogValue(() => "--Falsy--");
84
+ }
83
85
  throw new Error(`Invalid type:${typeof val}`);
84
86
  }
85
87
  }
@@ -295,6 +297,18 @@ var LoggerImpl = class _LoggerImpl {
295
297
  }
296
298
  return this;
297
299
  }
300
+ Len(value, key = "len") {
301
+ if (Array.isArray(value)) {
302
+ this._attributes[key] = logValue(() => value.length);
303
+ } else if (typeof value === "string") {
304
+ this._attributes[key] = logValue(() => value.length);
305
+ } else if (typeof value === "object" && value !== null) {
306
+ this._attributes[key] = logValue(() => Object.keys(value).length);
307
+ } else {
308
+ this.Int(key, -1);
309
+ }
310
+ return this;
311
+ }
298
312
  Url(url, key = "url") {
299
313
  this.Ref(key, () => url.toString());
300
314
  return this;
@@ -343,27 +357,36 @@ var LoggerImpl = class _LoggerImpl {
343
357
  Object.assign(this._attributes, this._withAttributes);
344
358
  return ret;
345
359
  }
360
+ _produceError(attr, ...args) {
361
+ var _a;
362
+ attr["msg"] = logValue(args.join(" "));
363
+ const msg = attr["msg"].value();
364
+ if (typeof msg === "string" && !msg.trim().length) {
365
+ delete attr["msg"];
366
+ }
367
+ if (((_a = attr["ts"]) == null ? void 0 : _a.value()) === "ETERNITY") {
368
+ this.Timestamp.call({
369
+ _sys: this._sys,
370
+ _attributes: attr
371
+ });
372
+ }
373
+ return JSON.stringify(resolveLogValue(attr));
374
+ }
346
375
  Msg(...args) {
347
- const error = this._resetAttributes(() => {
348
- var _a, _b, _c;
376
+ const fnError = this._resetAttributes(() => {
377
+ var _a, _b;
349
378
  const doWrite = this._levelHandler.isEnabled((_a = this._attributes["level"]) == null ? void 0 : _a.value(), (_b = this._attributes["module"]) == null ? void 0 : _b.value());
350
- this._attributes["msg"] = logValue(args.join(" "));
351
- const msg = this._attributes["msg"].value();
352
- if (typeof msg === "string" && !msg.trim().length) {
353
- delete this._attributes["msg"];
354
- }
355
- if (((_c = this._attributes["ts"]) == null ? void 0 : _c.value()) === "ETERNITY") {
356
- this.Timestamp();
357
- }
358
- const str = JSON.stringify(resolveLogValue(this._attributes));
379
+ let fnRet = () => this._produceError(__spreadValues({}, this._attributes), ...args);
359
380
  if (doWrite) {
381
+ const str = this._produceError(__spreadValues({}, this._attributes), ...args);
360
382
  const encoded = encoder.encode(str + "\n");
361
383
  this._logWriter.write(encoded);
384
+ fnRet = () => str;
362
385
  }
363
- return new Error(str);
386
+ return fnRet;
364
387
  });
365
388
  return {
366
- AsError: () => error
389
+ AsError: () => new Error(fnError())
367
390
  };
368
391
  }
369
392
  };
@@ -395,6 +418,10 @@ var WithLoggerBuilder = class {
395
418
  this._li.Str(key, value);
396
419
  return this;
397
420
  }
421
+ Len(value, key) {
422
+ this._li.Len(value, key);
423
+ return this;
424
+ }
398
425
  Ref(key, action) {
399
426
  this._li.Ref(key, action);
400
427
  return this;
@@ -695,6 +722,26 @@ _resolveFn = new WeakMap();
695
722
  _rejectFn = new WeakMap();
696
723
 
697
724
  // src/resolve-once.ts
725
+ var ResolveSeq = class {
726
+ constructor(ctx) {
727
+ this._seqFutures = [];
728
+ this.ctx = ctx;
729
+ }
730
+ reset() {
731
+ }
732
+ async _step(item) {
733
+ if (!item) {
734
+ return;
735
+ }
736
+ item.fn(this.ctx).then((value) => item.future.resolve(value)).catch((e) => item.future.reject(e)).finally(() => this._step(this._seqFutures.shift()));
737
+ }
738
+ async add(fn) {
739
+ const future = new Future();
740
+ this._seqFutures.push({ future, fn });
741
+ this._step(this._seqFutures.shift());
742
+ return future.asPromise();
743
+ }
744
+ };
698
745
  var ResolveOnce = class {
699
746
  constructor(ctx) {
700
747
  this._onceDone = false;
@@ -733,6 +780,8 @@ var ResolveOnce = class {
733
780
  this._onceFutures.length = 0;
734
781
  }).catch((e) => {
735
782
  this._onceError = e;
783
+ this._onceOk = false;
784
+ this._onceValue = void 0;
736
785
  this._onceDone = true;
737
786
  this._onceFutures.forEach((f) => f.reject(this._onceError));
738
787
  this._onceFutures.length = 0;
@@ -741,31 +790,47 @@ var ResolveOnce = class {
741
790
  return future.asPromise();
742
791
  }
743
792
  };
744
- var KeyedResolvOnce = class {
745
- constructor() {
793
+ var Keyed = class {
794
+ constructor(factory) {
746
795
  this._map = /* @__PURE__ */ new Map();
796
+ this.factory = factory;
797
+ }
798
+ async asyncGet(key) {
799
+ return this.get(await key());
747
800
  }
748
801
  get(key) {
749
802
  if (typeof key === "function") {
750
803
  key = key();
751
804
  }
752
- let resolveOnce = this._map.get(key);
753
- if (!resolveOnce) {
754
- resolveOnce = new ResolveOnce(key);
755
- this._map.set(key, resolveOnce);
805
+ let keyed = this._map.get(key);
806
+ if (!keyed) {
807
+ keyed = this.factory(key);
808
+ this._map.set(key, keyed);
756
809
  }
757
- return resolveOnce;
810
+ return keyed;
758
811
  }
759
812
  reset() {
760
- this._map.forEach((resolveOnce) => resolveOnce.reset());
813
+ this._map.forEach((keyed) => keyed.reset());
761
814
  this._map.clear();
762
815
  }
763
816
  };
817
+ var KeyedResolvOnce = class extends Keyed {
818
+ constructor() {
819
+ super((key) => new ResolveOnce(key));
820
+ }
821
+ };
822
+ var KeyedResolvSeq = class extends Keyed {
823
+ constructor() {
824
+ super((key) => new ResolveSeq(key));
825
+ }
826
+ };
764
827
  export {
765
828
  Future,
766
829
  IDMode,
767
830
  IsLogger,
831
+ Keyed,
768
832
  KeyedResolvOnce,
833
+ KeyedResolvSeq,
769
834
  Level,
770
835
  LevelHandlerImpl,
771
836
  LogCollector,
@@ -776,6 +841,7 @@ export {
776
841
  Option,
777
842
  RandomMode,
778
843
  ResolveOnce,
844
+ ResolveSeq,
779
845
  Result,
780
846
  ResultError,
781
847
  ResultOK,
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/logger.ts","../../src/logger_impl.ts","../../src/test/log_collector.ts","../../src/test/mock_logger.ts","../../src/result.ts","../../src/option.ts","../../src/future.ts","../../src/resolve-once.ts"],"sourcesContent":["import { Result } from \"./result\";\n\nexport enum Level {\n WARN = \"warn\",\n DEBUG = \"debug\",\n INFO = \"info\",\n ERROR = \"error\",\n}\n\nexport type Serialized = string | number | boolean;\nexport type FnSerialized = () => Serialized;\nexport interface LoggerInterface<R> {\n Module(key: string): R;\n // if modules is empty, set for all Levels\n EnableLevel(level: Level, ...modules: string[]): R;\n DisableLevel(level: Level, ...modules: string[]): R;\n\n SetDebug(...modules: (string | string[])[]): R;\n\n Ref(key: string, action: { toString: () => string } | FnSerialized): R;\n Result<T>(key: string, res: Result<T>): R;\n // default key url\n Url(url: URL, key?: string): R;\n\n Str(key: string, value?: string): R;\n Error(): R;\n Warn(): R;\n Debug(): R;\n Log(): R;\n WithLevel(level: Level): R;\n\n Err(err: unknown): R; // could be Error, or something which coerces to string\n Info(): R;\n Timestamp(): R;\n Any(key: string, value: unknown): R;\n Dur(key: string, nsec: number): R;\n Uint64(key: string, value: number): R;\n Int(key: string, value: number): R;\n Bool(key: string, value: unknown): R;\n}\n\nexport function IsLogger(obj: unknown): obj is Logger {\n return (\n typeof obj === \"object\" &&\n [\n \"Module\",\n \"EnableLevel\",\n \"DisableLevel\",\n \"SetDebug\",\n \"Str\",\n \"Error\",\n \"Warn\",\n \"Debug\",\n \"Log\",\n \"WithLevel\",\n \"Err\",\n \"Info\",\n \"Timestamp\",\n \"Any\",\n \"Dur\",\n \"Uint64\",\n ]\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n .map((fn) => typeof (obj as any)[fn] === \"function\")\n .reduce((a, b) => a && b, true)\n );\n}\n\nexport interface WithLogger extends LoggerInterface<WithLogger> {\n Logger(): Logger;\n}\n\nexport interface AsError {\n AsError(): Error;\n}\n\nexport interface Logger extends LoggerInterface<Logger> {\n With(): WithLogger;\n\n Msg(...args: string[]): AsError;\n Flush(): Promise<void>;\n}\n","// import { v4 } from \"uuid\";\nimport { AsError, FnSerialized, Level, Logger, Serialized, WithLogger } from \"./logger\";\nimport { WebSysAbstraction } from \"./web/web_sys_abstraction\";\nimport { SysAbstraction } from \"./sys_abstraction\";\nimport { Result } from \"./result\";\n\nconst encoder = new TextEncoder();\n\nclass LogValue {\n constructor(readonly fn: FnSerialized) {}\n value(): Serialized {\n return this.fn();\n }\n}\n\nfunction resolveLogValue(val: JsonRecord): Record<string, Serialized> {\n const ret: Record<string, Serialized> = {};\n Object.keys(val).forEach((key) => {\n const v = val[key];\n if (v instanceof LogValue) {\n ret[key] = v.value();\n }\n });\n return ret;\n}\n\nfunction logValue(val: Serialized | FnSerialized | JsonRecord): LogValue {\n if (typeof val === \"function\") {\n return new LogValue(val);\n }\n switch (typeof val) {\n case \"string\":\n return new LogValue(() => val.toString());\n case \"number\":\n return new LogValue(() => val);\n case \"boolean\":\n return new LogValue(() => val);\n case \"object\":\n return new LogValue(() => JSON.stringify(val));\n default:\n throw new Error(`Invalid type:${typeof val}`);\n }\n}\n\ntype JsonRecord = Record<string, LogValue>;\n\nexport interface LevelHandler {\n enableLevel(level: Level, ...modules: string[]): void;\n disableLevel(level: Level, ...modules: string[]): void;\n setDebug(...modules: (string | string[])[]): void;\n isEnabled(ilevel: unknown, module: unknown): boolean;\n}\n\nexport class LevelHandlerImpl implements LevelHandler {\n readonly _globalLevels = new Set<Level>([Level.INFO, Level.ERROR, Level.WARN]);\n readonly _modules = new Map<string, Set<Level>>();\n enableLevel(level: Level, ...modules: string[]): void {\n if (modules.length == 0) {\n this._globalLevels.add(level);\n return;\n }\n this.forModules(\n level,\n (p) => {\n this._modules.set(p, new Set([...this._globalLevels, level]));\n },\n ...modules,\n );\n }\n disableLevel(level: Level, ...modules: string[]): void {\n if (modules.length == 0) {\n this._globalLevels.delete(level);\n return;\n }\n this.forModules(\n level,\n (p) => {\n this._modules.delete(p);\n },\n ...modules,\n );\n }\n\n forModules(level: Level, fnAction: (p: string) => void, ...modules: (string | string[])[]): void {\n for (const m of modules.flat()) {\n const parts = m\n .split(\",\")\n .map((s) => s.trim())\n .filter((s) => s.length > 0);\n for (const p of parts) {\n fnAction(p);\n }\n }\n }\n setDebug(...modules: (string | string[])[]): void {\n this.forModules(\n Level.DEBUG,\n (p) => {\n this._modules.set(p, new Set([...this._globalLevels, Level.DEBUG]));\n },\n ...modules,\n );\n }\n isEnabled(ilevel: unknown, module: unknown): boolean {\n const level = ilevel as Level; // what if it's not a level?\n if (module !== undefined) {\n const levels = this._modules.get(module as string);\n if (levels && levels.has(level)) {\n return true;\n }\n }\n if (level === undefined) {\n // this is a plain log\n return true;\n }\n return this._globalLevels.has(level);\n }\n}\n\nconst levelSingleton = new LevelHandlerImpl();\n\n// globalThis[Symbol(\"levelSingleton\")] = new LevelHandlerImpl()\n\nexport class LogWriter {\n readonly _out: WritableStream<Uint8Array>;\n readonly _toFlush: (() => Promise<void>)[] = [];\n\n constructor(out: WritableStream<Uint8Array>) {\n this._out = out;\n }\n\n write(encoded: Uint8Array) {\n const my = async () => {\n // const val = Math.random();\n // console.log(\">>>My:\", val)\n try {\n const writer = this._out.getWriter();\n await writer.ready;\n await writer.write(encoded);\n await writer.releaseLock();\n } catch (err) {\n console.error(\"Chunk error:\", err);\n }\n // console.log(\"<<<My:\", val)\n };\n this._toFlush.push(my);\n this._flush();\n }\n\n _flushIsRunning = false;\n _flushDoneFns = Array<() => void>();\n _flush(toFlush: (() => Promise<void>)[] | undefined = undefined, done?: () => void): void {\n if (done) {\n this._flushDoneFns.push(done);\n }\n\n if (this._toFlush.length == 0) {\n // console.log(\"Flush is stopped\", this._toFlush.length)\n this._flushIsRunning = false;\n this._flushDoneFns.forEach((fn) => fn());\n this._flushDoneFns = [];\n return;\n }\n\n if (!toFlush && this._toFlush.length == 1 && !this._flushIsRunning) {\n this._flushIsRunning = true;\n // console.log(\"Flush is started\", this._toFlush.length)\n } else if (!toFlush) {\n // console.log(\"flush queue check but is running\", this._toFlush.length)\n return;\n }\n\n // console.log(\">>>Msg:\", this._toFlush.length)\n const my = this._toFlush.shift();\n my?.().finally(() => {\n // console.log(\"<<<Msg:\", this._toFlush.length)\n this._flush(this._toFlush);\n });\n }\n}\n\nexport interface LoggerImplParams {\n readonly out?: WritableStream<Uint8Array>;\n readonly logWriter?: LogWriter;\n readonly sys?: SysAbstraction;\n readonly withAttributes?: JsonRecord;\n readonly levelHandler?: LevelHandler;\n}\nexport class LoggerImpl implements Logger {\n readonly _sys: SysAbstraction;\n readonly _attributes: JsonRecord = {};\n readonly _withAttributes: JsonRecord;\n readonly _logWriter: LogWriter;\n readonly _levelHandler: LevelHandler;\n // readonly _id: string = \"logger-\" + Math.random().toString(36)\n\n constructor(params?: LoggerImplParams) {\n if (!params) {\n params = {};\n }\n if (!params.sys) {\n this._sys = WebSysAbstraction();\n } else {\n this._sys = params.sys;\n }\n if (params.logWriter) {\n this._logWriter = params.logWriter;\n } else {\n if (!params.out) {\n this._logWriter = new LogWriter(this._sys.Stdout());\n } else {\n this._logWriter = new LogWriter(params.out);\n }\n }\n if (!params.withAttributes) {\n this._withAttributes = {};\n } else {\n this._withAttributes = { ...params.withAttributes };\n }\n this._attributes = { ...this._withAttributes };\n if (params.levelHandler) {\n this._levelHandler = params.levelHandler;\n } else {\n this._levelHandler = levelSingleton;\n }\n // console.log(\"LoggerImpl\", this._id, this._attributes, this._withAttributes)\n }\n\n EnableLevel(level: Level, ...modules: string[]): Logger {\n this._levelHandler.enableLevel(level, ...modules);\n return this;\n }\n DisableLevel(level: Level, ...modules: string[]): Logger {\n this._levelHandler.disableLevel(level, ...modules);\n return this;\n }\n\n Module(key: string): Logger {\n this._attributes[\"module\"] = logValue(key);\n this._withAttributes[\"module\"] = logValue(key);\n return this;\n }\n SetDebug(...modules: (string | string[])[]): Logger {\n this._levelHandler.setDebug(...modules);\n\n return this;\n }\n\n Timestamp(): Logger {\n this._attributes[\"ts\"] = logValue(this._sys.Time().Now().toISOString());\n return this;\n }\n Warn(): Logger {\n this._attributes[\"level\"] = logValue(Level.WARN);\n return this;\n }\n Log(): Logger {\n return this;\n }\n Debug(): Logger {\n this._attributes[\"level\"] = logValue(Level.DEBUG);\n return this;\n }\n Error(): Logger {\n this._attributes[\"level\"] = logValue(Level.ERROR);\n return this;\n }\n Info(): Logger {\n this._attributes[\"level\"] = logValue(Level.INFO);\n return this;\n }\n Err(err: unknown): Logger {\n if (err instanceof Error) {\n this._attributes[\"error\"] = logValue(err.message);\n } else {\n this._attributes[\"error\"] = logValue(\"\" + err);\n }\n return this;\n }\n WithLevel(l: Level): Logger {\n this._attributes[\"level\"] = logValue(l);\n return this;\n }\n\n Ref(key: string, action: { toString: () => string } | FnSerialized): Logger {\n if (typeof action === \"function\") {\n this._attributes[key] = logValue(action as FnSerialized);\n } else if (typeof action.toString === \"function\") {\n this._attributes[key] = logValue(() => action.toString());\n } else {\n this._attributes[key] = logValue(\"INVALID REF\");\n }\n return this;\n }\n Bool(key: string, value: unknown): Logger {\n this._attributes[key] = logValue(!!value);\n return this;\n }\n Result<T>(key: string, res: Result<T, Error>): Logger {\n if (res.isOk()) {\n this._attributes[key] = logValue(res.Ok() as Serialized);\n } else {\n this.Err(res.Err());\n }\n return this;\n }\n\n Url(url: URL, key = \"url\"): Logger {\n this.Ref(key, () => url.toString());\n return this;\n }\n\n Str(key: string, value: string): Logger {\n this._attributes[key] = logValue(value);\n return this;\n }\n\n Any(key: string, value: string | number | boolean | JsonRecord): Logger {\n this._attributes[key] = logValue(value);\n return this;\n }\n Dur(key: string, nsec: number): Logger {\n this._attributes[key] = logValue(`${nsec}ms`);\n // new Intl.DurationFormat(\"en\", { style: \"narrow\" }).format(nsec);\n return this;\n }\n Uint64(key: string, value: number): Logger {\n this._attributes[key] = logValue(value);\n return this;\n }\n Int(key: string, value: number): Logger {\n return this.Uint64(key, value);\n }\n\n async Flush(): Promise<void> {\n return new Promise((resolve) => {\n this._logWriter._flush(undefined, resolve);\n });\n }\n\n With(): WithLogger {\n // console.log(\"WithLoggerBuilder.With\", this._id, this._attributes, this._withAttributes);\n return new WithLoggerBuilder(\n new LoggerImpl({\n logWriter: this._logWriter,\n sys: this._sys,\n levelHandler: this._levelHandler,\n withAttributes: {\n module: this._attributes[\"module\"],\n ...this._withAttributes,\n },\n }),\n );\n }\n\n _resetAttributes(fn: () => Error): Error {\n const ret = fn();\n Object.keys(this._attributes).forEach((key) => {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this._attributes[key];\n });\n Object.assign(this._attributes, this._withAttributes);\n return ret;\n }\n Msg(...args: string[]): AsError {\n const error = this._resetAttributes(() => {\n const doWrite = this._levelHandler.isEnabled(this._attributes[\"level\"]?.value(), this._attributes[\"module\"]?.value());\n this._attributes[\"msg\"] = logValue(args.join(\" \"));\n const msg = this._attributes[\"msg\"].value();\n if (typeof msg === \"string\" && !msg.trim().length) {\n delete this._attributes[\"msg\"];\n }\n if (this._attributes[\"ts\"]?.value() === \"ETERNITY\") {\n this.Timestamp();\n }\n const str = JSON.stringify(resolveLogValue(this._attributes));\n if (doWrite) {\n const encoded = encoder.encode(str + \"\\n\");\n this._logWriter.write(encoded);\n }\n return new Error(str);\n });\n return {\n AsError: () => error,\n };\n }\n}\n\nclass WithLoggerBuilder implements WithLogger {\n readonly _li: LoggerImpl;\n constructor(li: LoggerImpl) {\n this._li = li;\n }\n\n Logger(): Logger {\n Object.assign(this._li._withAttributes, this._li._attributes);\n return this._li;\n }\n\n EnableLevel(level: Level, ...modules: string[]): WithLogger {\n this._li._levelHandler.enableLevel(level, ...modules);\n return this;\n }\n DisableLevel(level: Level, ...modules: string[]): WithLogger {\n this._li._levelHandler.enableLevel(level, ...modules);\n return this;\n }\n\n Module(key: string): WithLogger {\n this._li.Module(key);\n return this;\n }\n SetDebug(...modules: (string | string[])[]): WithLogger {\n this._li.SetDebug(...modules);\n return this;\n }\n\n Str(key: string, value: string): WithLogger {\n this._li.Str(key, value);\n return this;\n }\n\n Ref(key: string, action: Serialized | FnSerialized): WithLogger {\n this._li.Ref(key, action);\n return this;\n }\n Bool(key: string, value: unknown): WithLogger {\n this._li.Bool(key, value);\n return this;\n }\n Result<T>(key: string, res: Result<T, Error>): WithLogger {\n this._li.Result(key, res);\n return this;\n }\n Url(url: URL, key?: string): WithLogger {\n this._li.Url(url, key);\n return this;\n }\n Int(key: string, value: number): WithLogger {\n this._li.Int(key, value);\n return this;\n }\n\n Log(): WithLogger {\n this._li.Log();\n return this;\n }\n\n WithLevel(level: Level): WithLogger {\n this._li.WithLevel(level);\n return this;\n }\n\n Error(): WithLogger {\n this._li.Error();\n return this;\n }\n Warn(): WithLogger {\n this._li.Error();\n return this;\n }\n Debug(): WithLogger {\n this._li.Debug();\n return this;\n }\n Err(err: unknown): WithLogger {\n this._li.Err(err);\n return this;\n }\n Info(): WithLogger {\n this._li.Info();\n return this;\n }\n Timestamp(): WithLogger {\n this._li._attributes[\"ts\"] = logValue(\"ETERNITY\");\n return this;\n }\n Any(key: string, value: JsonRecord): WithLogger {\n this._li.Any(key, value);\n return this;\n }\n Dur(key: string, nsec: number): WithLogger {\n this._li.Dur(key, nsec);\n return this;\n }\n Uint64(key: string, value: number): WithLogger {\n this._li.Uint64(key, value);\n return this;\n }\n}\n","class LogWriter implements WritableStreamDefaultWriter<Uint8Array> {\n readonly _bufferArr: Uint8Array[] = [];\n\n _resolveClosed: (value?: PromiseLike<undefined>) => void;\n closed: Promise<undefined>;\n desiredSize: number | null = null;\n ready: Promise<undefined> = Promise.resolve(undefined);\n\n constructor() {\n this._resolveClosed = () => {\n // do nothing\n };\n this.closed = new Promise((resolve) => {\n this._resolveClosed = resolve;\n });\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any\n abort(reason?: any): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n close(): Promise<void> {\n this._resolveClosed();\n return Promise.resolve(undefined);\n }\n releaseLock(): void {\n // do nothing\n }\n write(chunk?: Uint8Array): Promise<void> {\n chunk && this._bufferArr.push(chunk);\n return Promise.resolve(undefined);\n }\n}\n\nexport class LogCollector implements WritableStream<Uint8Array> {\n readonly locked: boolean = false;\n _writer?: LogWriter;\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abort(reason?: Uint8Array): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n async close(): Promise<void> {\n if (this._writer) {\n const ret = await this._writer.close();\n this._writer = undefined;\n return ret;\n }\n return Promise.resolve(undefined);\n }\n\n getWriter(): WritableStreamDefaultWriter<Uint8Array> {\n if (!this._writer) {\n this._writer = new LogWriter();\n }\n return this._writer;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Logs(): any[] {\n if (!this._writer) {\n return [];\n }\n const jsonNlStr = new TextDecoder().decode(\n new Uint8Array(\n (function* (res: Uint8Array[]) {\n for (const x of res) {\n yield* x;\n }\n })(this._writer._bufferArr),\n ),\n );\n const splitStr = jsonNlStr.split(\"\\n\");\n const filterStr = splitStr.filter((a) => a.length);\n const mapStr = filterStr.map((a) => JSON.parse(a));\n return mapStr;\n }\n}\n","import { Logger } from \"../logger\";\nimport { LevelHandlerImpl, LoggerImpl } from \"../logger_impl\";\nimport { SysAbstraction } from \"../sys_abstraction\";\nimport { LogCollector } from \"./log_collector\";\n\nexport interface MockLoggerReturn {\n readonly logger: Logger;\n readonly logCollector: LogCollector;\n}\n\nexport function MockLogger(params?: {\n readonly sys?: SysAbstraction;\n moduleName?: string | string[];\n readonly disableDebug?: boolean;\n}): MockLoggerReturn {\n const lc = new LogCollector();\n let modNames = [\"MockLogger\"];\n if (typeof params?.moduleName === \"string\") {\n modNames = [params?.moduleName];\n } else if (Array.isArray(params?.moduleName)) {\n modNames = [...params.moduleName, ...modNames];\n }\n const logger = new LoggerImpl({\n out: lc,\n sys: params?.sys,\n levelHandler: new LevelHandlerImpl(),\n })\n .With()\n .Module(modNames[0])\n .Logger();\n !params?.disableDebug && logger.SetDebug(...modNames);\n return {\n logCollector: lc,\n logger,\n };\n}\n","export abstract class Result<T, E = Error> {\n static Ok<T>(t: T): Result<T, Error> {\n return new ResultOK(t);\n }\n static Err<T extends Error = Error>(t: T | string): Result<never, T> {\n if (typeof t === \"string\") {\n return new ResultError(new Error(t) as T);\n }\n return new ResultError(t);\n }\n static Is<T>(t: unknown): t is Result<T> {\n return t instanceof Result;\n }\n\n isOk(): boolean {\n return this.is_ok();\n }\n isErr(): boolean {\n return this.is_err();\n }\n\n Ok(): T {\n return this.unwrap();\n }\n Err(): E {\n return this.unwrap_err();\n }\n\n abstract is_ok(): boolean;\n abstract is_err(): boolean;\n abstract unwrap(): T;\n abstract unwrap_err(): E;\n}\n\nexport class ResultOK<T> extends Result<T, Error> {\n private _t: T;\n constructor(t: T) {\n super();\n this._t = t;\n }\n is_ok(): boolean {\n return true;\n }\n is_err(): boolean {\n return false;\n }\n unwrap_err(): Error {\n throw new Error(\"Result is Ok\");\n }\n unwrap(): T {\n return this._t;\n }\n}\n\nexport class ResultError<T extends Error> extends Result<never, T> {\n private _error: T;\n constructor(t: T) {\n super();\n this._error = t;\n }\n is_ok(): boolean {\n return false;\n }\n is_err(): boolean {\n return true;\n }\n unwrap(): never {\n throw new Error(`Result is Err: ${this._error}`);\n }\n unwrap_err(): T {\n return this._error;\n }\n}\n\nexport type WithoutResult<T> = T extends Result<infer U> ? U : T;\n\n/*\n\ntype FinalizedResult<T> = {\n result: T;\n scopeResult?: Result<void>;\n finally: () => Promise<void>;\n}\n\ntype exection2ResultParam<T> = {\n init: () => Promise<T>;\n inScope?: (t: T) => Promise<void>;\n cleanup: (t: T) => Promise<void>;\n\n}\n\nasync function expection2Result<T>({fn, inScope, cleanup}: exection2ResultParam<T>): Promise<Result<FinalizedResult<T>>> {\n try {\n const res = await fn();\n if (inScope) {\n try {\n await inScope?.(res)\n } catch (err) {\n return Result.Err(err as Error)\n }\n await cleanup(res)\n return Result.Ok({\n result: res,\n finally: async () => { }\n })\n }\n return Result.Ok({\n result: res ,\n finally: async () => {\n return cleanup(res)\n }\n })\n } catch (err) {\n return Result.Err(err as Error)\n }\n}\n*/\n\n// await expection2Result({\n// init: openDB,\n// inScope: (res) => {\n// res.query()\n// },\n// cleanup: async (y) => {\n// await y.close()\n// }\n// })\n// async function openDB() {\n// try {\n// const opendb = await openDB()\n// return Result.Ok({\n// openDB,\n// finally: async () => {\n// await opendb.close()\n// }})\n// } catch (err) {\n// return Result.Err(err)\n// }\n// }\n// }\n","export abstract class Option<T> {\n static Some<T>(t: T): Option<T> {\n return new Some(t);\n }\n\n static None<T>(): Option<T> {\n return new None();\n }\n\n static Is<T>(t: unknown): t is Option<T> {\n return t instanceof Option;\n }\n\n IsNone(): boolean {\n return this.is_none();\n }\n\n IsSome(): boolean {\n return this.is_some();\n }\n Unwrap(): T {\n return this.unwrap();\n }\n\n abstract is_none(): boolean;\n abstract is_some(): boolean;\n abstract unwrap(): T;\n}\n\nexport class Some<T> extends Option<T> {\n private _t: T;\n constructor(_t: T) {\n super();\n this._t = _t;\n }\n\n is_none(): boolean {\n return false;\n }\n is_some(): boolean {\n return true;\n }\n unwrap(): T {\n return this._t;\n }\n}\n\nexport class None<T> extends Option<T> {\n is_none(): boolean {\n return true;\n }\n is_some(): boolean {\n return false;\n }\n unwrap(): T {\n throw new Error(\"None.unwrap\");\n }\n}\n\nexport type WithoutOption<T> = T extends Option<infer U> ? U : T;\n","export class Future<T> {\n readonly #promise: Promise<T>;\n #resolveFn: (value: T) => void = () => {\n throw new Error(\"This Promise is not working as expected.\");\n };\n #rejectFn: (reason: unknown) => void = () => {\n throw new Error(\"This Promise is not working as expected.\");\n };\n\n constructor() {\n this.#promise = new Promise<T>((resolve, reject) => {\n this.#resolveFn = resolve;\n this.#rejectFn = reject;\n });\n }\n\n async asPromise(): Promise<T> {\n return this.#promise;\n }\n\n resolve(value: T) {\n this.#resolveFn(value);\n }\n reject(reason: unknown) {\n this.#rejectFn(reason);\n }\n}\n","import { Future } from \"./future\";\n\nexport class ResolveOnce<T, C = void> {\n _onceDone = false;\n readonly _onceFutures: Future<T>[] = [];\n _onceOk = false;\n _onceValue?: T;\n _onceError?: Error;\n\n readonly ctx: C;\n\n constructor(ctx?: C) {\n this.ctx = ctx as C;\n }\n\n get ready() {\n return this._onceDone;\n }\n\n reset() {\n this._onceDone = false;\n this._onceOk = false;\n this._onceValue = undefined;\n this._onceError = undefined;\n this._onceFutures.length = 0;\n }\n\n async once(fn: (c: C) => Promise<T>): Promise<T> {\n if (this._onceDone) {\n if (this._onceError) {\n return Promise.reject(this._onceError);\n }\n if (this._onceOk) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return Promise.resolve(this._onceValue!);\n }\n throw new Error(\"ResolveOnce.once impossible\");\n }\n const future = new Future<T>();\n this._onceFutures.push(future);\n if (this._onceFutures.length === 1) {\n fn(this.ctx)\n .then((value) => {\n this._onceValue = value;\n this._onceOk = true;\n this._onceDone = true;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this._onceFutures.forEach((f) => f.resolve(this._onceValue!));\n this._onceFutures.length = 0;\n })\n .catch((e) => {\n this._onceError = e as Error;\n this._onceDone = true;\n this._onceFutures.forEach((f) => f.reject(this._onceError));\n this._onceFutures.length = 0;\n });\n }\n return future.asPromise();\n }\n}\n\nexport class KeyedResolvOnce<T, K = string> {\n private readonly _map = new Map<K, ResolveOnce<T, K>>();\n\n get(key: K | (() => K)): ResolveOnce<T, K> {\n if (typeof key === \"function\") {\n key = (key as () => K)();\n }\n let resolveOnce = this._map.get(key);\n if (!resolveOnce) {\n resolveOnce = new ResolveOnce<T, K>(key);\n this._map.set(key, resolveOnce);\n }\n return resolveOnce;\n }\n\n reset() {\n this._map.forEach((resolveOnce) => resolveOnce.reset());\n this._map.clear();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAEO,IAAK,QAAL,kBAAKA,WAAL;AACL,EAAAA,OAAA,UAAO;AACP,EAAAA,OAAA,WAAQ;AACR,EAAAA,OAAA,UAAO;AACP,EAAAA,OAAA,WAAQ;AAJE,SAAAA;AAAA,GAAA;AAuCL,SAAS,SAAS,KAA6B;AACpD,SACE,OAAO,QAAQ,YACf;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,EAEG,IAAI,CAAC,OAAO,OAAQ,I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A,MACzC;AACA,YAAM,IAAI,MAAM,6BAA6B;AAAA,IAC/C;AACA,UAAM,SAAS,IAAI,OAAU;AAC7B,SAAK,aAAa,KAAK,MAAM;AAC7B,QAAI,KAAK,aAAa,WAAW,GAAG;AAClC,SAAG,KAAK,GAAG,EACR,KAAK,CAAC,UAAU;AACf,aAAK,aAAa;AAClB,aAAK,UAAU;AACf,aAAK,YAAY;AAEjB,aAAK,aAAa,QAAQ,CAAC,MAAM,EAAE,QAAQ,KAAK,UAAW,CAAC;AAC5D,aAAK,aAAa,SAAS;AAAA,MAC7B,CAAC,EACA,MAAM,CAAC,MAAM;AACZ,aAAK,aAAa;AAClB,aAAK,YAAY;AACjB,aAAK,aAAa,QAAQ,CAAC,MAAM,EAAE,OAAO,KAAK,UAAU,CAAC;AAC1D,aAAK,aAAa,SAAS;AAAA,MAC7B,CAAC;AAAA,IACL;AACA,WAAO,OAAO,UAAU;AAAA,EAC1B;AACF;AAEO,IAAM,kBAAN,MAAqC;AAAA,EAArC;AACL,SAAiB,OAAO,oBAAI,IAA0B;AAAA;AAAA,EAEtD,IAAI,KAAuC;AACzC,QAAI,OAAO,QAAQ,YAAY;AAC7B,YAAO,IAAgB;AAAA,IACzB;AACA,QAAI,cAAc,KAAK,KAAK,IAAI,GAAG;AACnC,QAAI,CAAC,aAAa;AAChB,oBAAc,IAAI,YAAkB,GAAG;AACvC,WAAK,KAAK,IAAI,KAAK,WAAW;AAAA,IAChC;AACA,WAAO;AAAA,EACT;AAAA,EAEA,QAAQ;AACN,SAAK,KAAK,QAAQ,CAAC,gBAAgB,YAAY,MAAM,CAAC;AACtD,SAAK,KAAK,MAAM;AAAA,EAClB;AACF;","names":["Level","LogWriter"]}
1
+ {"version":3,"sources":["../../src/logger.ts","../../src/logger_impl.ts","../../src/test/log_collector.ts","../../src/test/mock_logger.ts","../../src/result.ts","../../src/option.ts","../../src/future.ts","../../src/resolve-once.ts"],"sourcesContent":["import { Result } from \"./result\";\n\nexport enum Level {\n WARN = \"warn\",\n DEBUG = \"debug\",\n INFO = \"info\",\n ERROR = \"error\",\n}\n\nexport type Serialized = string | number | boolean;\nexport type FnSerialized = () => Serialized;\nexport interface LoggerInterface<R> {\n Module(key: string): R;\n // if modules is empty, set for all Levels\n EnableLevel(level: Level, ...modules: string[]): R;\n DisableLevel(level: Level, ...modules: string[]): R;\n\n SetDebug(...modules: (string | string[])[]): R;\n\n Ref(key: string, action: { toString: () => string } | FnSerialized): R;\n Result<T>(key: string, res: Result<T>): R;\n // default key url\n Url(url: URL, key?: string): R;\n // len\n Len(value: object | { length: number } | string | undefined | null, key?: string): R;\n\n Str(key: string, value?: string): R;\n Error(): R;\n Warn(): R;\n Debug(): R;\n Log(): R;\n WithLevel(level: Level): R;\n\n Err(err: unknown): R; // could be Error, or something which coerces to string\n Info(): R;\n Timestamp(): R;\n Any(key: string, value: unknown): R;\n Dur(key: string, nsec: number): R;\n Uint64(key: string, value: number): R;\n Int(key: string, value: number): R;\n Bool(key: string, value: unknown): R;\n}\n\nexport function IsLogger(obj: unknown): obj is Logger {\n return (\n typeof obj === \"object\" &&\n [\n \"Module\",\n \"EnableLevel\",\n \"DisableLevel\",\n \"SetDebug\",\n \"Str\",\n \"Error\",\n \"Warn\",\n \"Debug\",\n \"Log\",\n \"WithLevel\",\n \"Err\",\n \"Info\",\n \"Timestamp\",\n \"Any\",\n \"Dur\",\n \"Uint64\",\n ]\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n .map((fn) => typeof (obj as any)[fn] === \"function\")\n .reduce((a, b) => a && b, true)\n );\n}\n\nexport interface WithLogger extends LoggerInterface<WithLogger> {\n Logger(): Logger;\n}\n\nexport interface AsError {\n AsError(): Error;\n}\n\nexport interface Logger extends LoggerInterface<Logger> {\n With(): WithLogger;\n\n Msg(...args: string[]): AsError;\n Flush(): Promise<void>;\n}\n","// import { v4 } from \"uuid\";\nimport { AsError, FnSerialized, Level, Logger, Serialized, WithLogger } from \"./logger\";\nimport { WebSysAbstraction } from \"./web/web_sys_abstraction\";\nimport { SysAbstraction } from \"./sys_abstraction\";\nimport { Result } from \"./result\";\n\nconst encoder = new TextEncoder();\n\nclass LogValue {\n constructor(readonly fn: FnSerialized) {}\n value(): Serialized {\n return this.fn();\n }\n}\n\nfunction resolveLogValue(val: JsonRecord): Record<string, Serialized> {\n const ret: Record<string, Serialized> = {};\n Object.keys(val).forEach((key) => {\n const v = val[key];\n if (v instanceof LogValue) {\n ret[key] = v.value();\n }\n });\n return ret;\n}\n\nfunction logValue(val: Serialized | FnSerialized | JsonRecord | undefined | null): LogValue {\n switch (typeof val) {\n case \"function\":\n return new LogValue(val);\n case \"string\":\n return new LogValue(() => val.toString());\n case \"number\":\n return new LogValue(() => val);\n case \"boolean\":\n return new LogValue(() => val);\n case \"object\":\n return new LogValue(() => JSON.stringify(val));\n default:\n if (!val) {\n return new LogValue(() => \"--Falsy--\");\n }\n throw new Error(`Invalid type:${typeof val}`);\n }\n}\n\ntype JsonRecord = Record<string, LogValue>;\n\nexport interface LevelHandler {\n enableLevel(level: Level, ...modules: string[]): void;\n disableLevel(level: Level, ...modules: string[]): void;\n setDebug(...modules: (string | string[])[]): void;\n isEnabled(ilevel: unknown, module: unknown): boolean;\n}\n\nexport class LevelHandlerImpl implements LevelHandler {\n readonly _globalLevels = new Set<Level>([Level.INFO, Level.ERROR, Level.WARN]);\n readonly _modules = new Map<string, Set<Level>>();\n enableLevel(level: Level, ...modules: string[]): void {\n if (modules.length == 0) {\n this._globalLevels.add(level);\n return;\n }\n this.forModules(\n level,\n (p) => {\n this._modules.set(p, new Set([...this._globalLevels, level]));\n },\n ...modules,\n );\n }\n disableLevel(level: Level, ...modules: string[]): void {\n if (modules.length == 0) {\n this._globalLevels.delete(level);\n return;\n }\n this.forModules(\n level,\n (p) => {\n this._modules.delete(p);\n },\n ...modules,\n );\n }\n\n forModules(level: Level, fnAction: (p: string) => void, ...modules: (string | string[])[]): void {\n for (const m of modules.flat()) {\n const parts = m\n .split(\",\")\n .map((s) => s.trim())\n .filter((s) => s.length > 0);\n for (const p of parts) {\n fnAction(p);\n }\n }\n }\n setDebug(...modules: (string | string[])[]): void {\n this.forModules(\n Level.DEBUG,\n (p) => {\n this._modules.set(p, new Set([...this._globalLevels, Level.DEBUG]));\n },\n ...modules,\n );\n }\n isEnabled(ilevel: unknown, module: unknown): boolean {\n const level = ilevel as Level; // what if it's not a level?\n if (module !== undefined) {\n const levels = this._modules.get(module as string);\n if (levels && levels.has(level)) {\n return true;\n }\n }\n if (level === undefined) {\n // this is a plain log\n return true;\n }\n return this._globalLevels.has(level);\n }\n}\n\nconst levelSingleton = new LevelHandlerImpl();\n\n// globalThis[Symbol(\"levelSingleton\")] = new LevelHandlerImpl()\n\nexport class LogWriter {\n readonly _out: WritableStream<Uint8Array>;\n readonly _toFlush: (() => Promise<void>)[] = [];\n\n constructor(out: WritableStream<Uint8Array>) {\n this._out = out;\n }\n\n write(encoded: Uint8Array) {\n const my = async () => {\n // const val = Math.random();\n // console.log(\">>>My:\", val)\n try {\n const writer = this._out.getWriter();\n await writer.ready;\n await writer.write(encoded);\n await writer.releaseLock();\n } catch (err) {\n console.error(\"Chunk error:\", err);\n }\n // console.log(\"<<<My:\", val)\n };\n this._toFlush.push(my);\n this._flush();\n }\n\n _flushIsRunning = false;\n _flushDoneFns = Array<() => void>();\n _flush(toFlush: (() => Promise<void>)[] | undefined = undefined, done?: () => void): void {\n if (done) {\n this._flushDoneFns.push(done);\n }\n\n if (this._toFlush.length == 0) {\n // console.log(\"Flush is stopped\", this._toFlush.length)\n this._flushIsRunning = false;\n this._flushDoneFns.forEach((fn) => fn());\n this._flushDoneFns = [];\n return;\n }\n\n if (!toFlush && this._toFlush.length == 1 && !this._flushIsRunning) {\n this._flushIsRunning = true;\n // console.log(\"Flush is started\", this._toFlush.length)\n } else if (!toFlush) {\n // console.log(\"flush queue check but is running\", this._toFlush.length)\n return;\n }\n\n // console.log(\">>>Msg:\", this._toFlush.length)\n const my = this._toFlush.shift();\n my?.().finally(() => {\n // console.log(\"<<<Msg:\", this._toFlush.length)\n this._flush(this._toFlush);\n });\n }\n}\n\nexport interface LoggerImplParams {\n readonly out?: WritableStream<Uint8Array>;\n readonly logWriter?: LogWriter;\n readonly sys?: SysAbstraction;\n readonly withAttributes?: JsonRecord;\n readonly levelHandler?: LevelHandler;\n}\nexport class LoggerImpl implements Logger {\n readonly _sys: SysAbstraction;\n readonly _attributes: JsonRecord = {};\n readonly _withAttributes: JsonRecord;\n readonly _logWriter: LogWriter;\n readonly _levelHandler: LevelHandler;\n // readonly _id: string = \"logger-\" + Math.random().toString(36)\n\n constructor(params?: LoggerImplParams) {\n if (!params) {\n params = {};\n }\n if (!params.sys) {\n this._sys = WebSysAbstraction();\n } else {\n this._sys = params.sys;\n }\n if (params.logWriter) {\n this._logWriter = params.logWriter;\n } else {\n if (!params.out) {\n this._logWriter = new LogWriter(this._sys.Stdout());\n } else {\n this._logWriter = new LogWriter(params.out);\n }\n }\n if (!params.withAttributes) {\n this._withAttributes = {};\n } else {\n this._withAttributes = { ...params.withAttributes };\n }\n this._attributes = { ...this._withAttributes };\n if (params.levelHandler) {\n this._levelHandler = params.levelHandler;\n } else {\n this._levelHandler = levelSingleton;\n }\n // console.log(\"LoggerImpl\", this._id, this._attributes, this._withAttributes)\n }\n\n EnableLevel(level: Level, ...modules: string[]): Logger {\n this._levelHandler.enableLevel(level, ...modules);\n return this;\n }\n DisableLevel(level: Level, ...modules: string[]): Logger {\n this._levelHandler.disableLevel(level, ...modules);\n return this;\n }\n\n Module(key: string): Logger {\n this._attributes[\"module\"] = logValue(key);\n this._withAttributes[\"module\"] = logValue(key);\n return this;\n }\n SetDebug(...modules: (string | string[])[]): Logger {\n this._levelHandler.setDebug(...modules);\n\n return this;\n }\n\n Timestamp(): Logger {\n // this is called with .call from _produceError where this\n // this is crafted to have _sys and _attributes\n // CAUTION so done use other ref from this\n this._attributes[\"ts\"] = logValue(this._sys.Time().Now().toISOString());\n return this;\n }\n Warn(): Logger {\n this._attributes[\"level\"] = logValue(Level.WARN);\n return this;\n }\n Log(): Logger {\n return this;\n }\n Debug(): Logger {\n this._attributes[\"level\"] = logValue(Level.DEBUG);\n return this;\n }\n Error(): Logger {\n this._attributes[\"level\"] = logValue(Level.ERROR);\n return this;\n }\n Info(): Logger {\n this._attributes[\"level\"] = logValue(Level.INFO);\n return this;\n }\n Err(err: unknown): Logger {\n if (err instanceof Error) {\n this._attributes[\"error\"] = logValue(err.message);\n } else {\n this._attributes[\"error\"] = logValue(\"\" + err);\n }\n return this;\n }\n WithLevel(l: Level): Logger {\n this._attributes[\"level\"] = logValue(l);\n return this;\n }\n\n Ref(key: string, action: { toString: () => string } | FnSerialized): Logger {\n if (typeof action === \"function\") {\n this._attributes[key] = logValue(action as FnSerialized);\n } else if (typeof action.toString === \"function\") {\n this._attributes[key] = logValue(() => action.toString());\n } else {\n this._attributes[key] = logValue(\"INVALID REF\");\n }\n return this;\n }\n Bool(key: string, value: unknown): Logger {\n this._attributes[key] = logValue(!!value);\n return this;\n }\n Result<T>(key: string, res: Result<T, Error>): Logger {\n if (res.isOk()) {\n this._attributes[key] = logValue(res.Ok() as Serialized);\n } else {\n this.Err(res.Err());\n }\n return this;\n }\n\n Len(value: unknown, key = \"len\"): Logger {\n if (Array.isArray(value)) {\n this._attributes[key] = logValue(() => value.length);\n } else if (typeof value === \"string\") {\n this._attributes[key] = logValue(() => value.length);\n } else if (typeof value === \"object\" && value !== null) {\n this._attributes[key] = logValue(() => Object.keys(value).length);\n } else {\n this.Int(key, -1);\n }\n return this;\n }\n\n Url(url: URL, key = \"url\"): Logger {\n this.Ref(key, () => url.toString());\n return this;\n }\n\n Str(key: string, value?: string): Logger {\n this._attributes[key] = logValue(value);\n return this;\n }\n\n Any(key: string, value: string | number | boolean | JsonRecord): Logger {\n this._attributes[key] = logValue(value);\n return this;\n }\n Dur(key: string, nsec: number): Logger {\n this._attributes[key] = logValue(`${nsec}ms`);\n // new Intl.DurationFormat(\"en\", { style: \"narrow\" }).format(nsec);\n return this;\n }\n Uint64(key: string, value: number): Logger {\n this._attributes[key] = logValue(value);\n return this;\n }\n Int(key: string, value: number): Logger {\n return this.Uint64(key, value);\n }\n\n async Flush(): Promise<void> {\n return new Promise((resolve) => {\n this._logWriter._flush(undefined, resolve);\n });\n }\n\n With(): WithLogger {\n // console.log(\"WithLoggerBuilder.With\", this._id, this._attributes, this._withAttributes);\n return new WithLoggerBuilder(\n new LoggerImpl({\n logWriter: this._logWriter,\n sys: this._sys,\n levelHandler: this._levelHandler,\n withAttributes: {\n module: this._attributes[\"module\"],\n ...this._withAttributes,\n },\n }),\n );\n }\n\n _resetAttributes(fn: () => () => string): () => string {\n const ret = fn();\n Object.keys(this._attributes).forEach((key) => {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this._attributes[key];\n });\n Object.assign(this._attributes, this._withAttributes);\n return ret;\n }\n _produceError(attr: JsonRecord, ...args: string[]): string {\n attr[\"msg\"] = logValue(args.join(\" \"));\n const msg = attr[\"msg\"].value();\n if (typeof msg === \"string\" && !msg.trim().length) {\n delete attr[\"msg\"];\n }\n if (attr[\"ts\"]?.value() === \"ETERNITY\") {\n // hacky but it works\n this.Timestamp.call({\n _sys: this._sys,\n _attributes: attr,\n });\n }\n return JSON.stringify(resolveLogValue(attr));\n }\n\n Msg(...args: string[]): AsError {\n const fnError = this._resetAttributes(() => {\n const doWrite = this._levelHandler.isEnabled(this._attributes[\"level\"]?.value(), this._attributes[\"module\"]?.value());\n let fnRet = () => this._produceError({ ...this._attributes }, ...args);\n if (doWrite) {\n const str = this._produceError({ ...this._attributes }, ...args);\n const encoded = encoder.encode(str + \"\\n\");\n this._logWriter.write(encoded);\n fnRet = () => str;\n }\n return fnRet;\n });\n return {\n AsError: () => new Error(fnError()),\n };\n }\n}\n\nclass WithLoggerBuilder implements WithLogger {\n readonly _li: LoggerImpl;\n constructor(li: LoggerImpl) {\n this._li = li;\n }\n\n Logger(): Logger {\n Object.assign(this._li._withAttributes, this._li._attributes);\n return this._li;\n }\n\n EnableLevel(level: Level, ...modules: string[]): WithLogger {\n this._li._levelHandler.enableLevel(level, ...modules);\n return this;\n }\n DisableLevel(level: Level, ...modules: string[]): WithLogger {\n this._li._levelHandler.enableLevel(level, ...modules);\n return this;\n }\n\n Module(key: string): WithLogger {\n this._li.Module(key);\n return this;\n }\n SetDebug(...modules: (string | string[])[]): WithLogger {\n this._li.SetDebug(...modules);\n return this;\n }\n\n Str(key: string, value?: string): WithLogger {\n this._li.Str(key, value);\n return this;\n }\n\n Len(value: unknown, key?: string): WithLogger {\n this._li.Len(value, key);\n return this;\n }\n\n Ref(key: string, action: Serialized | FnSerialized): WithLogger {\n this._li.Ref(key, action);\n return this;\n }\n Bool(key: string, value: unknown): WithLogger {\n this._li.Bool(key, value);\n return this;\n }\n Result<T>(key: string, res: Result<T, Error>): WithLogger {\n this._li.Result(key, res);\n return this;\n }\n Url(url: URL, key?: string): WithLogger {\n this._li.Url(url, key);\n return this;\n }\n Int(key: string, value: number): WithLogger {\n this._li.Int(key, value);\n return this;\n }\n\n Log(): WithLogger {\n this._li.Log();\n return this;\n }\n\n WithLevel(level: Level): WithLogger {\n this._li.WithLevel(level);\n return this;\n }\n\n Error(): WithLogger {\n this._li.Error();\n return this;\n }\n Warn(): WithLogger {\n this._li.Error();\n return this;\n }\n Debug(): WithLogger {\n this._li.Debug();\n return this;\n }\n Err(err: unknown): WithLogger {\n this._li.Err(err);\n return this;\n }\n Info(): WithLogger {\n this._li.Info();\n return this;\n }\n Timestamp(): WithLogger {\n this._li._attributes[\"ts\"] = logValue(\"ETERNITY\");\n return this;\n }\n Any(key: string, value: JsonRecord): WithLogger {\n this._li.Any(key, value);\n return this;\n }\n Dur(key: string, nsec: number): WithLogger {\n this._li.Dur(key, nsec);\n return this;\n }\n Uint64(key: string, value: number): WithLogger {\n this._li.Uint64(key, value);\n return this;\n }\n}\n","class LogWriter implements WritableStreamDefaultWriter<Uint8Array> {\n readonly _bufferArr: Uint8Array[] = [];\n\n _resolveClosed: (value?: PromiseLike<undefined>) => void;\n closed: Promise<undefined>;\n desiredSize: number | null = null;\n ready: Promise<undefined> = Promise.resolve(undefined);\n\n constructor() {\n this._resolveClosed = () => {\n // do nothing\n };\n this.closed = new Promise((resolve) => {\n this._resolveClosed = resolve;\n });\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any\n abort(reason?: any): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n close(): Promise<void> {\n this._resolveClosed();\n return Promise.resolve(undefined);\n }\n releaseLock(): void {\n // do nothing\n }\n write(chunk?: Uint8Array): Promise<void> {\n chunk && this._bufferArr.push(chunk);\n return Promise.resolve(undefined);\n }\n}\n\nexport class LogCollector implements WritableStream<Uint8Array> {\n readonly locked: boolean = false;\n _writer?: LogWriter;\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abort(reason?: Uint8Array): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n async close(): Promise<void> {\n if (this._writer) {\n const ret = await this._writer.close();\n this._writer = undefined;\n return ret;\n }\n return Promise.resolve(undefined);\n }\n\n getWriter(): WritableStreamDefaultWriter<Uint8Array> {\n if (!this._writer) {\n this._writer = new LogWriter();\n }\n return this._writer;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Logs(): any[] {\n if (!this._writer) {\n return [];\n }\n const jsonNlStr = new TextDecoder().decode(\n new Uint8Array(\n (function* (res: Uint8Array[]) {\n for (const x of res) {\n yield* x;\n }\n })(this._writer._bufferArr),\n ),\n );\n const splitStr = jsonNlStr.split(\"\\n\");\n const filterStr = splitStr.filter((a) => a.length);\n const mapStr = filterStr.map((a) => JSON.parse(a));\n return mapStr;\n }\n}\n","import { Logger } from \"../logger\";\nimport { LevelHandlerImpl, LoggerImpl } from \"../logger_impl\";\nimport { SysAbstraction } from \"../sys_abstraction\";\nimport { LogCollector } from \"./log_collector\";\n\nexport interface MockLoggerReturn {\n readonly logger: Logger;\n readonly logCollector: LogCollector;\n}\n\nexport function MockLogger(params?: {\n readonly sys?: SysAbstraction;\n moduleName?: string | string[];\n readonly disableDebug?: boolean;\n}): MockLoggerReturn {\n const lc = new LogCollector();\n let modNames = [\"MockLogger\"];\n if (typeof params?.moduleName === \"string\") {\n modNames = [params?.moduleName];\n } else if (Array.isArray(params?.moduleName)) {\n modNames = [...params.moduleName, ...modNames];\n }\n const logger = new LoggerImpl({\n out: lc,\n sys: params?.sys,\n levelHandler: new LevelHandlerImpl(),\n })\n .With()\n .Module(modNames[0])\n .Logger();\n !params?.disableDebug && logger.SetDebug(...modNames);\n return {\n logCollector: lc,\n logger,\n };\n}\n","export abstract class Result<T, E = Error> {\n static Ok<T>(t: T): Result<T, Error> {\n return new ResultOK(t);\n }\n static Err<T extends Error = Error>(t: T | string): Result<never, T> {\n if (typeof t === \"string\") {\n return new ResultError(new Error(t) as T);\n }\n return new ResultError(t);\n }\n static Is<T>(t: unknown): t is Result<T> {\n return t instanceof Result;\n }\n\n isOk(): boolean {\n return this.is_ok();\n }\n isErr(): boolean {\n return this.is_err();\n }\n\n Ok(): T {\n return this.unwrap();\n }\n Err(): E {\n return this.unwrap_err();\n }\n\n abstract is_ok(): boolean;\n abstract is_err(): boolean;\n abstract unwrap(): T;\n abstract unwrap_err(): E;\n}\n\nexport class ResultOK<T> extends Result<T, Error> {\n private _t: T;\n constructor(t: T) {\n super();\n this._t = t;\n }\n is_ok(): boolean {\n return true;\n }\n is_err(): boolean {\n return false;\n }\n unwrap_err(): Error {\n throw new Error(\"Result is Ok\");\n }\n unwrap(): T {\n return this._t;\n }\n}\n\nexport class ResultError<T extends Error> extends Result<never, T> {\n private _error: T;\n constructor(t: T) {\n super();\n this._error = t;\n }\n is_ok(): boolean {\n return false;\n }\n is_err(): boolean {\n return true;\n }\n unwrap(): never {\n throw new Error(`Result is Err: ${this._error}`);\n }\n unwrap_err(): T {\n return this._error;\n }\n}\n\nexport type WithoutResult<T> = T extends Result<infer U> ? U : T;\n\n/*\n\ntype FinalizedResult<T> = {\n result: T;\n scopeResult?: Result<void>;\n finally: () => Promise<void>;\n}\n\ntype exection2ResultParam<T> = {\n init: () => Promise<T>;\n inScope?: (t: T) => Promise<void>;\n cleanup: (t: T) => Promise<void>;\n\n}\n\nasync function expection2Result<T>({fn, inScope, cleanup}: exection2ResultParam<T>): Promise<Result<FinalizedResult<T>>> {\n try {\n const res = await fn();\n if (inScope) {\n try {\n await inScope?.(res)\n } catch (err) {\n return Result.Err(err as Error)\n }\n await cleanup(res)\n return Result.Ok({\n result: res,\n finally: async () => { }\n })\n }\n return Result.Ok({\n result: res ,\n finally: async () => {\n return cleanup(res)\n }\n })\n } catch (err) {\n return Result.Err(err as Error)\n }\n}\n*/\n\n// await expection2Result({\n// init: openDB,\n// inScope: (res) => {\n// res.query()\n// },\n// cleanup: async (y) => {\n// await y.close()\n// }\n// })\n// async function openDB() {\n// try {\n// const opendb = await openDB()\n// return Result.Ok({\n// openDB,\n// finally: async () => {\n// await opendb.close()\n// }})\n// } catch (err) {\n// return Result.Err(err)\n// }\n// }\n// }\n","export abstract class Option<T> {\n static Some<T>(t: T): Option<T> {\n return new Some(t);\n }\n\n static None<T>(): Option<T> {\n return new None();\n }\n\n static Is<T>(t: unknown): t is Option<T> {\n return t instanceof Option;\n }\n\n IsNone(): boolean {\n return this.is_none();\n }\n\n IsSome(): boolean {\n return this.is_some();\n }\n Unwrap(): T {\n return this.unwrap();\n }\n\n abstract is_none(): boolean;\n abstract is_some(): boolean;\n abstract unwrap(): T;\n}\n\nexport class Some<T> extends Option<T> {\n private _t: T;\n constructor(_t: T) {\n super();\n this._t = _t;\n }\n\n is_none(): boolean {\n return false;\n }\n is_some(): boolean {\n return true;\n }\n unwrap(): T {\n return this._t;\n }\n}\n\nexport class None<T> extends Option<T> {\n is_none(): boolean {\n return true;\n }\n is_some(): boolean {\n return false;\n }\n unwrap(): T {\n throw new Error(\"None.unwrap\");\n }\n}\n\nexport type WithoutOption<T> = T extends Option<infer U> ? U : T;\n","export class Future<T> {\n readonly #promise: Promise<T>;\n #resolveFn: (value: T) => void = () => {\n throw new Error(\"This Promise is not working as expected.\");\n };\n #rejectFn: (reason: unknown) => void = () => {\n throw new Error(\"This Promise is not working as expected.\");\n };\n\n constructor() {\n this.#promise = new Promise<T>((resolve, reject) => {\n this.#resolveFn = resolve;\n this.#rejectFn = reject;\n });\n }\n\n async asPromise(): Promise<T> {\n return this.#promise;\n }\n\n resolve(value: T) {\n this.#resolveFn(value);\n }\n reject(reason: unknown) {\n this.#rejectFn(reason);\n }\n}\n","import { Future } from \"./future\";\n\ninterface ResolveSeqItem<T, C> {\n future: Future<T>;\n fn: (c: C) => Promise<T>;\n}\n\nexport class ResolveSeq<T, C = void> {\n readonly ctx: C;\n constructor(ctx?: C) {\n this.ctx = ctx as C;\n }\n reset() {\n /* noop */\n }\n async _step(item?: ResolveSeqItem<T, C> | undefined) {\n if (!item) {\n // done\n return;\n }\n item\n .fn(this.ctx)\n .then((value) => item.future.resolve(value))\n .catch((e) => item.future.reject(e as Error))\n .finally(() => this._step(this._seqFutures.shift()));\n }\n readonly _seqFutures: ResolveSeqItem<T, C>[] = [];\n async add(fn: (c: C) => Promise<T>): Promise<T> {\n const future = new Future<T>();\n this._seqFutures.push({ future, fn });\n this._step(this._seqFutures.shift());\n return future.asPromise();\n }\n}\n\nexport class ResolveOnce<T, C = void> {\n _onceDone = false;\n readonly _onceFutures: Future<T>[] = [];\n _onceOk = false;\n _onceValue?: T;\n _onceError?: Error;\n\n readonly ctx: C;\n\n constructor(ctx?: C) {\n this.ctx = ctx as C;\n }\n\n get ready() {\n return this._onceDone;\n }\n\n reset() {\n this._onceDone = false;\n this._onceOk = false;\n this._onceValue = undefined;\n this._onceError = undefined;\n this._onceFutures.length = 0;\n }\n\n async once(fn: (c: C) => Promise<T>): Promise<T> {\n if (this._onceDone) {\n if (this._onceError) {\n return Promise.reject(this._onceError);\n }\n if (this._onceOk) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return Promise.resolve(this._onceValue!);\n }\n throw new Error(\"ResolveOnce.once impossible\");\n }\n const future = new Future<T>();\n this._onceFutures.push(future);\n if (this._onceFutures.length === 1) {\n fn(this.ctx)\n .then((value) => {\n this._onceValue = value;\n this._onceOk = true;\n this._onceDone = true;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this._onceFutures.forEach((f) => f.resolve(this._onceValue!));\n this._onceFutures.length = 0;\n })\n .catch((e) => {\n this._onceError = e as Error;\n this._onceOk = false;\n this._onceValue = undefined;\n this._onceDone = true;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this._onceFutures.forEach((f) => f.reject(this._onceError!));\n this._onceFutures.length = 0;\n });\n }\n return future.asPromise();\n }\n}\n\nexport class Keyed<T extends { reset: () => void }, K = string> {\n private readonly _map = new Map<K, T>();\n\n readonly factory: (key: K) => T;\n constructor(factory: (key: K) => T) {\n this.factory = factory;\n }\n\n async asyncGet(key: () => Promise<K>): Promise<T> {\n return this.get(await key());\n }\n\n get(key: K | (() => K)): T {\n if (typeof key === \"function\") {\n key = (key as () => K)();\n }\n let keyed = this._map.get(key);\n if (!keyed) {\n keyed = this.factory(key);\n this._map.set(key, keyed);\n }\n return keyed;\n }\n\n reset() {\n this._map.forEach((keyed) => keyed.reset());\n this._map.clear();\n }\n}\n\nexport class KeyedResolvOnce<T, K = string> extends Keyed<ResolveOnce<T, K>, K> {\n constructor() {\n super((key) => new ResolveOnce<T, K>(key));\n }\n}\n\nexport class KeyedResolvSeq<T, K = string> extends Keyed<ResolveSeq<T, K>, K> {\n constructor() {\n super((key) => new ResolveSeq<T, K>(key));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAEO,IAAK,QAAL,kBAAKA,WAAL;AACL,EAAAA,OAAA,UAAO;AACP,EAAAA,OAAA,WAAQ;AACR,EAAAA,OAAA,UAAO;AACP,EAAAA,OAAA,WAAQ;AAJE,SAAAA;AAAA,GAAA;AAyCL,SAAS,SAA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AM,IAAI,CAAC;AAAA,EAC7B;AAAA,EAEA,IAAI,KAAuB;AACzB,QAAI,OAAO,QAAQ,YAAY;AAC7B,YAAO,IAAgB;AAAA,IACzB;AACA,QAAI,QAAQ,KAAK,KAAK,IAAI,GAAG;AAC7B,QAAI,CAAC,OAAO;AACV,cAAQ,KAAK,QAAQ,GAAG;AACxB,WAAK,KAAK,IAAI,KAAK,KAAK;AAAA,IAC1B;AACA,WAAO;AAAA,EACT;AAAA,EAEA,QAAQ;AACN,SAAK,KAAK,QAAQ,CAAC,UAAU,MAAM,MAAM,CAAC;AAC1C,SAAK,KAAK,MAAM;AAAA,EAClB;AACF;AAEO,IAAM,kBAAN,cAA6C,MAA4B;AAAA,EAC9E,cAAc;AACZ,UAAM,CAAC,QAAQ,IAAI,YAAkB,GAAG,CAAC;AAAA,EAC3C;AACF;AAEO,IAAM,iBAAN,cAA4C,MAA2B;AAAA,EAC5E,cAAc;AACZ,UAAM,CAAC,QAAQ,IAAI,WAAiB,GAAG,CAAC;AAAA,EAC1C;AACF;","names":["Level","LogWriter"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adviser/cement",
3
- "version": "0.1.23",
3
+ "version": "0.1.25",
4
4
  "description": "better try/catch/finally handling",
5
5
  "main": "index.js",
6
6
  "type": "module",