@adviser/cement 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- package/{chunk-RSXHMWBX.js → chunk-CI63N5CK.js} +14 -6
- package/chunk-CI63N5CK.js.map +1 -0
- package/{chunk-GX6QZCII.js → chunk-XBYS4FSO.js} +2 -2
- package/index.cjs +16 -5
- package/index.cjs.map +1 -1
- package/index.js +5 -2
- package/index.js.map +1 -1
- package/node/index.cjs +13 -5
- package/node/index.cjs.map +1 -1
- package/node/index.js +1 -1
- package/package.json +1 -1
- package/web/index.cjs +13 -5
- package/web/index.cjs.map +1 -1
- package/web/index.js +2 -2
- package/chunk-RSXHMWBX.js.map +0 -1
- /package/{chunk-GX6QZCII.js.map → chunk-XBYS4FSO.js.map} +0 -0
@@ -112,16 +112,24 @@ var DenoEnvActions = class {
|
|
112
112
|
_deno = new WeakMap();
|
113
113
|
_env2 = new WeakMap();
|
114
114
|
var BrowserEnvActions = class _BrowserEnvActions extends DenoEnvActions {
|
115
|
-
static
|
115
|
+
static globalBEA(sym) {
|
116
116
|
const browser = globalThis;
|
117
117
|
if (typeof browser === "object" && typeof browser[sym] === "object") {
|
118
|
-
return browser[sym];
|
118
|
+
return { map: browser[sym]._map, finalize: () => browser[sym]._map };
|
119
119
|
}
|
120
|
-
|
121
|
-
return
|
120
|
+
const map = /* @__PURE__ */ new Map();
|
121
|
+
return {
|
122
|
+
map,
|
123
|
+
finalize: (bea) => {
|
124
|
+
browser[sym] = bea;
|
125
|
+
return map;
|
126
|
+
}
|
127
|
+
};
|
122
128
|
}
|
123
129
|
constructor(opts) {
|
124
|
-
|
130
|
+
const { map, finalize } = _BrowserEnvActions.globalBEA(Symbol.for(opts.symbol || "CP_ENV"));
|
131
|
+
super(opts, map);
|
132
|
+
this._map = finalize(this);
|
125
133
|
}
|
126
134
|
use() {
|
127
135
|
return true;
|
@@ -396,4 +404,4 @@ export {
|
|
396
404
|
EnvImpl,
|
397
405
|
envImpl
|
398
406
|
};
|
399
|
-
//# sourceMappingURL=chunk-
|
407
|
+
//# sourceMappingURL=chunk-CI63N5CK.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/sys_abstraction.ts","../../src/time.ts","../../src/sys_env.ts","../../src/base_sys_abstraction.ts"],"sourcesContent":["import { FileService } from \"./file_service\";\nimport { Env } from \"./sys_env\";\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(): Env;\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","export interface EnvActions {\n get(key: string): string | undefined;\n set(key: string, value?: string): void;\n del(key: string): void;\n keys(): string[];\n use(): boolean;\n}\n\nclass NodeEnvActions implements EnvActions {\n readonly #node = globalThis as unknown as { process: { env: Record<string, string> } };\n\n // eslint-disable-next-line @typescript-eslint/no-useless-constructor, @typescript-eslint/no-unused-vars\n constructor(opts: Partial<EnvFactoryOpts>) {\n // do nothing\n }\n use(): boolean {\n return typeof this.#node === \"object\" && typeof this.#node.process === \"object\" && typeof this.#node.process.env === \"object\";\n }\n readonly #env = this.use() ? process.env : {};\n keys(): string[] {\n return Object.keys(this.#env);\n }\n get(key: string): string | undefined {\n return this.#env[key];\n }\n set(key: string, value?: string): void {\n if (value) {\n this.#env[key] = value;\n }\n }\n del(key: string): void {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this.#env[key];\n }\n}\n\nclass DenoEnvActions implements EnvActions {\n readonly #deno = globalThis as unknown as { Deno: { env: Map<string, string> } };\n\n readonly #env: Map<string, string>;\n constructor(opts: Partial<EnvFactoryOpts>, env?: Map<string, string>) {\n if (env) {\n this.#env = env;\n } else {\n this.#env = this.use() ? this.#deno.Deno.env : new Map();\n }\n }\n use(): boolean {\n return typeof this.#deno === \"object\" && typeof this.#deno.Deno === \"object\" && typeof this.#deno.Deno.env === \"object\";\n }\n keys(): string[] {\n return Array.from(this.#env.keys());\n }\n get(key: string): string | undefined {\n return this.#env.get(key);\n }\n set(key: string, value?: string): void {\n if (value) {\n this.#env.set(key, value);\n }\n }\n del(key: string): void {\n this.#env.delete(key);\n }\n}\n\nclass BrowserEnvActions extends DenoEnvActions {\n static globalBEA(sym: symbol) {\n const browser = globalThis as unknown as Record<symbol, BrowserEnvActions>;\n if (typeof browser === \"object\" && typeof browser[sym] === \"object\") {\n return { map: browser[sym]._map, finalize: () => browser[sym]._map };\n }\n const map = new Map<string, string>();\n return {\n map,\n finalize: (bea: BrowserEnvActions) => {\n browser[sym] = bea;\n return map;\n },\n };\n }\n\n readonly _map: Map<string, string>;\n constructor(opts: Partial<EnvFactoryOpts>) {\n const { map, finalize } = BrowserEnvActions.globalBEA(Symbol.for(opts.symbol || \"CP_ENV\"));\n // not perfect the globalThis will be polluted\n // also in the case it is not need.\n // better we have a lazy init\n super(opts, map);\n this._map = finalize(this);\n }\n use(): boolean {\n return true;\n }\n}\n\ninterface EnvFactoryOpts {\n readonly symbol: string; // default \"CP_ENV\" used by BrowserEnvActions\n readonly presetEnv: Map<string, string>;\n}\n\nfunction envFactory(opts: Partial<EnvFactoryOpts> = {}): EnvActions {\n const found = [new NodeEnvActions(opts), new DenoEnvActions(opts), new BrowserEnvActions(opts)].find((env) => env.use());\n if (!found) {\n throw new Error(\"SysContainer:envFactory: no env available\");\n }\n return found;\n}\n\ntype OnSetFn = (key: string, value?: string) => void;\nexport interface OnSetItem {\n readonly filter: Set<string>;\n readonly fn: OnSetFn;\n}\n\nexport interface Env extends Omit<EnvActions, \"use\"> {\n onSet(fn: OnSetFn, ...filter: string[]): void;\n}\n\nexport class EnvImpl implements Env {\n readonly #envImpl: EnvActions;\n constructor(opts: Partial<EnvFactoryOpts> = {}) {\n this.#envImpl = envFactory(opts);\n // do nothing\n this.#updatePresets(opts.presetEnv);\n }\n #updatePresets(presetEnv?: Map<string, string>): void {\n if (!presetEnv) {\n return;\n }\n for (const [key, value] of presetEnv) {\n this.#envImpl.set(key, value);\n }\n }\n #applyOnSet(onSet: OnSetItem[], key?: string, value?: string): void {\n onSet.forEach((item) => {\n let keys: string[] = [];\n if (key) {\n keys = [key];\n } else {\n keys = this.#envImpl.keys();\n }\n keys\n .filter((k) => {\n if (item.filter.size === 0) {\n return true;\n }\n if (item.filter.has(k)) {\n return true;\n }\n return false;\n })\n .forEach((k) => {\n let v;\n if (!key && !value) {\n // init\n v = this.#envImpl.get(k);\n } else if (key && !value) {\n // del\n v = undefined;\n } else {\n // set\n v = value;\n }\n item.fn(k, v);\n });\n });\n }\n readonly #onSet: OnSetItem[] = [];\n keys(): string[] {\n return this.#envImpl.keys();\n }\n // filter is not set all sets passed\n onSet(fn: OnSetFn, ...filter: string[]): void {\n const item: OnSetItem = { filter: new Set(filter), fn };\n this.#onSet.push(item);\n this.#applyOnSet([item]);\n }\n get(key: string): string | undefined {\n return this.#envImpl.get(key);\n }\n set(key: string, value?: string): void {\n if (!value) {\n return;\n }\n this.#envImpl.set(key, value);\n this.#applyOnSet(this.#onSet, key, value);\n }\n del(key: string): void {\n this.#envImpl.del(key);\n this.#applyOnSet(this.#onSet, key);\n }\n}\n\nexport const envImpl = new EnvImpl();\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"],"mappings":";;;;;;;;AAIO,IAAK,WAAL,kBAAKA,cAAL;AACL,EAAAA,UAAA,UAAO;AACP,EAAAA,UAAA,WAAQ;AACR,EAAAA,UAAA,UAAO;AAHG,SAAAA;AAAA,GAAA;AAML,IAAK,aAAL,kBAAKC,gBAAL;AACL,EAAAA,YAAA,WAAQ;AACR,EAAAA,YAAA,UAAO;AACP,EAAAA,YAAA,YAAS;AAHC,SAAAA;AAAA,GAAA;AAML,IAAK,SAAL,kBAAKC,YAAL;AACL,EAAAA,QAAA,UAAO;AACP,EAAAA,QAAA,WAAQ;AACR,EAAAA,QAAA,UAAO;AAHG,SAAAA;AAAA,GAAA;AAML,SAAS,gBAAgB,GAAsB;AACpD,U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,aAAa,IAAI,UAAU,OAAO,MAAM;AAAA,MAC/C;AACA,UAAI,OAAO,YAAY;AACrB,aAAK,iBAAiB,IAAI,cAAc,OAAO,UAAU;AAAA,MAC3D;AACA,UAAI,OAAO,YAAY;AACrB,aAAK,cAAc,OAAO;AAAA,MAC5B;AACA,UAAI,OAAO,eAAe;AACxB,aAAK,iBAAiB,OAAO;AAAA,MAC/B;AAAA,IACF;AAAA,EACF;AAAA,EACA,OAAa;AACX,WAAO,KAAK;AAAA,EACd;AAAA,EACA,SAAiB;AACf,WAAO,KAAK,WAAW,OAAO;AAAA,EAChC;AAAA,EACA,eAAe,OAAuB;AACpC,WAAO,KAAK,eAAe,eAAe,KAAK;AAAA,EACjD;AAAA,EACA,SAAyB;AACvB,WAAO,KAAK;AAAA,EACd;AAAA,EACA,SAAyB;AACvB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,SAAwB;AACtB,WAAO,KAAK;AAAA,EACd;AAAA,EACA,aAA0B;AACxB,WAAO,KAAK;AAAA,EACd;AACF;","names":["TimeMode","RandomMode","IDMode","TimeUnits","_env"]}
|
@@ -2,7 +2,7 @@ import {
|
|
2
2
|
BaseSysAbstraction,
|
3
3
|
WrapperSysAbstraction,
|
4
4
|
envImpl
|
5
|
-
} from "./chunk-
|
5
|
+
} from "./chunk-CI63N5CK.js";
|
6
6
|
|
7
7
|
// src/web/web_sys_abstraction.ts
|
8
8
|
var WebFileService = class {
|
@@ -80,4 +80,4 @@ function WebSysAbstraction(param) {
|
|
80
80
|
export {
|
81
81
|
WebSysAbstraction
|
82
82
|
};
|
83
|
-
//# sourceMappingURL=chunk-
|
83
|
+
//# sourceMappingURL=chunk-XBYS4FSO.js.map
|
package/index.cjs
CHANGED
@@ -416,16 +416,24 @@ var DenoEnvActions = class {
|
|
416
416
|
_deno = new WeakMap();
|
417
417
|
_env2 = new WeakMap();
|
418
418
|
var BrowserEnvActions = class _BrowserEnvActions extends DenoEnvActions {
|
419
|
-
static
|
419
|
+
static globalBEA(sym) {
|
420
420
|
const browser = globalThis;
|
421
421
|
if (typeof browser === "object" && typeof browser[sym] === "object") {
|
422
|
-
return browser[sym];
|
422
|
+
return { map: browser[sym]._map, finalize: () => browser[sym]._map };
|
423
423
|
}
|
424
|
-
|
425
|
-
return
|
424
|
+
const map = /* @__PURE__ */ new Map();
|
425
|
+
return {
|
426
|
+
map,
|
427
|
+
finalize: (bea) => {
|
428
|
+
browser[sym] = bea;
|
429
|
+
return map;
|
430
|
+
}
|
431
|
+
};
|
426
432
|
}
|
427
433
|
constructor(opts) {
|
428
|
-
|
434
|
+
const { map, finalize } = _BrowserEnvActions.globalBEA(Symbol.for(opts.symbol || "CP_ENV"));
|
435
|
+
super(opts, map);
|
436
|
+
this._map = finalize(this);
|
429
437
|
}
|
430
438
|
use() {
|
431
439
|
return true;
|
@@ -658,6 +666,9 @@ var LevelHandlerImpl = class {
|
|
658
666
|
}
|
659
667
|
forModules(level, fnAction, ...modules) {
|
660
668
|
for (const m of modules.flat()) {
|
669
|
+
if (typeof m !== "string") {
|
670
|
+
continue;
|
671
|
+
}
|
661
672
|
const parts = m.split(",").map((s) => s.trim()).filter((s) => s.length);
|
662
673
|
for (const p of parts) {
|
663
674
|
fnAction(p);
|
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/sys_env.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 \"./sys_env\";\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 { Env } from \"./sys_env\";\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(): Env;\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","export interface EnvActions {\n get(key: string): string | undefined;\n set(key: string, value?: string): void;\n del(key: string): void;\n keys(): string[];\n use(): boolean;\n}\n\nclass NodeEnvActions implements EnvActions {\n readonly #node = globalThis as unknown as { process: { env: Record<string, string> } };\n\n // eslint-disable-next-line @typescript-eslint/no-useless-constructor, @typescript-eslint/no-unused-vars\n constructor(opts: Partial<EnvFactoryOpts>) {\n // do nothing\n }\n use(): boolean {\n return typeof this.#node === \"object\" && typeof this.#node.process === \"object\" && typeof this.#node.process.env === \"object\";\n }\n readonly #env = this.use() ? process.env : {};\n keys(): string[] {\n return Object.keys(this.#env);\n }\n get(key: string): string | undefined {\n return this.#env[key];\n }\n set(key: string, value?: string): void {\n if (value) {\n this.#env[key] = value;\n }\n }\n del(key: string): void {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this.#env[key];\n }\n}\n\nclass DenoEnvActions implements EnvActions {\n readonly #deno = globalThis as unknown as { Deno: { env: Map<string, string> } };\n\n readonly #env: Map<string, string>;\n constructor(opts: Partial<EnvFactoryOpts>, env?: Map<string, string>) {\n if (env) {\n this.#env = env;\n } else {\n this.#env = this.use() ? this.#deno.Deno.env : new Map();\n }\n }\n use(): boolean {\n return typeof this.#deno === \"object\" && typeof this.#deno.Deno === \"object\" && typeof this.#deno.Deno.env === \"object\";\n }\n keys(): string[] {\n return Array.from(this.#env.keys());\n }\n get(key: string): string | undefined {\n return this.#env.get(key);\n }\n set(key: string, value?: string): void {\n if (value) {\n this.#env.set(key, value);\n }\n }\n del(key: string): void {\n this.#env.delete(key);\n }\n}\n\nclass BrowserEnvActions extends DenoEnvActions {\n static getEnv(sym: symbol) {\n const browser = globalThis as unknown as Record<symbol, Map<string, string>>;\n if (typeof browser === \"object\" && typeof browser[sym] === \"object\") {\n return browser[sym];\n }\n browser[sym] = new Map();\n return browser[sym];\n }\n\n constructor(opts: Partial<EnvFactoryOpts>) {\n // not perfect the globalThis will be polluted\n // also in the case it is not need.\n // better we have a lazy init\n super(opts, BrowserEnvActions.getEnv(Symbol.for(opts.symbol || \"CP_ENV\")));\n }\n use(): boolean {\n return true;\n }\n}\n\ninterface EnvFactoryOpts {\n readonly symbol: string; // default \"CP_ENV\" used by BrowserEnvActions\n readonly presetEnv: Map<string, string>;\n}\n\nfunction envFactory(opts: Partial<EnvFactoryOpts> = {}): EnvActions {\n const found = [new NodeEnvActions(opts), new DenoEnvActions(opts), new BrowserEnvActions(opts)].find((env) => env.use());\n if (!found) {\n throw new Error(\"SysContainer:envFactory: no env available\");\n }\n return found;\n}\n\ntype OnSetFn = (key: string, value?: string) => void;\nexport interface OnSetItem {\n readonly filter: Set<string>;\n readonly fn: OnSetFn;\n}\n\nexport interface Env extends Omit<EnvActions, \"use\"> {\n onSet(fn: OnSetFn, ...filter: string[]): void;\n}\n\nexport class EnvImpl implements Env {\n readonly #envImpl: EnvActions;\n constructor(opts: Partial<EnvFactoryOpts> = {}) {\n this.#envImpl = envFactory(opts);\n // do nothing\n this.#updatePresets(opts.presetEnv);\n }\n #updatePresets(presetEnv?: Map<string, string>): void {\n if (!presetEnv) {\n return;\n }\n for (const [key, value] of presetEnv) {\n this.#envImpl.set(key, value);\n }\n }\n #applyOnSet(onSet: OnSetItem[], key?: string, value?: string): void {\n onSet.forEach((item) => {\n let keys: string[] = [];\n if (key) {\n keys = [key];\n } else {\n keys = this.#envImpl.keys();\n }\n keys\n .filter((k) => {\n if (item.filter.size === 0) {\n return true;\n }\n if (item.filter.has(k)) {\n return true;\n }\n return false;\n })\n .forEach((k) => {\n let v;\n if (!key && !value) {\n // init\n v = this.#envImpl.get(k);\n } else if (key && !value) {\n // del\n v = undefined;\n } else {\n // set\n v = value;\n }\n item.fn(k, v);\n });\n });\n }\n readonly #onSet: OnSetItem[] = [];\n keys(): string[] {\n return this.#envImpl.keys();\n }\n // filter is not set all sets passed\n onSet(fn: OnSetFn, ...filter: string[]): void {\n const item: OnSetItem = { filter: new Set(filter), fn };\n this.#onSet.push(item);\n this.#applyOnSet([item]);\n }\n get(key: string): string | undefined {\n return this.#envImpl.get(key);\n }\n set(key: string, value?: string): void {\n if (!value) {\n return;\n }\n this.#envImpl.set(key, value);\n this.#applyOnSet(this.#onSet, key, value);\n }\n del(key: string): void {\n this.#envImpl.del(key);\n this.#applyOnSet(this.#onSet, key);\n }\n}\n\nexport const envImpl = new EnvImpl();\n","import { BaseSysAbstraction, WrapperSysAbstraction, WrapperSysAbstractionParams } from \"../base_sys_abstraction\";\nimport { FileService, NamedWritableStream } from \"../file_service\";\nimport { SysAbstraction, SystemService, VoidFunc } from \"../sys_abstraction\";\nimport { envImpl } from \"../sys_env\";\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() {\n return envImpl;\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);\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 (typeof module === \"string\") {\n const levels = this._modules.get(module);\n if (levels && levels.has(level)) {\n return true;\n }\n }\n const wlevel = this._modules.get(\"*\");\n if (wlevel && typeof level === \"string\") {\n if (wlevel.has(level)) {\n return true;\n }\n }\n if (typeof level !== \"string\") {\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 // if the string is \"*\" it will enable for all modules\n SetDebug(...modules: (string | string[])[]): Logger {\n this._levelHandler.setDebug(...modules);\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;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,SA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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","TimeMode","RandomMode","IDMode","TimeUnits","_env","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/sys_env.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 \"./sys_env\";\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 { Env } from \"./sys_env\";\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(): Env;\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","export interface EnvActions {\n get(key: string): string | undefined;\n set(key: string, value?: string): void;\n del(key: string): void;\n keys(): string[];\n use(): boolean;\n}\n\nclass NodeEnvActions implements EnvActions {\n readonly #node = globalThis as unknown as { process: { env: Record<string, string> } };\n\n // eslint-disable-next-line @typescript-eslint/no-useless-constructor, @typescript-eslint/no-unused-vars\n constructor(opts: Partial<EnvFactoryOpts>) {\n // do nothing\n }\n use(): boolean {\n return typeof this.#node === \"object\" && typeof this.#node.process === \"object\" && typeof this.#node.process.env === \"object\";\n }\n readonly #env = this.use() ? process.env : {};\n keys(): string[] {\n return Object.keys(this.#env);\n }\n get(key: string): string | undefined {\n return this.#env[key];\n }\n set(key: string, value?: string): void {\n if (value) {\n this.#env[key] = value;\n }\n }\n del(key: string): void {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this.#env[key];\n }\n}\n\nclass DenoEnvActions implements EnvActions {\n readonly #deno = globalThis as unknown as { Deno: { env: Map<string, string> } };\n\n readonly #env: Map<string, string>;\n constructor(opts: Partial<EnvFactoryOpts>, env?: Map<string, string>) {\n if (env) {\n this.#env = env;\n } else {\n this.#env = this.use() ? this.#deno.Deno.env : new Map();\n }\n }\n use(): boolean {\n return typeof this.#deno === \"object\" && typeof this.#deno.Deno === \"object\" && typeof this.#deno.Deno.env === \"object\";\n }\n keys(): string[] {\n return Array.from(this.#env.keys());\n }\n get(key: string): string | undefined {\n return this.#env.get(key);\n }\n set(key: string, value?: string): void {\n if (value) {\n this.#env.set(key, value);\n }\n }\n del(key: string): void {\n this.#env.delete(key);\n }\n}\n\nclass BrowserEnvActions extends DenoEnvActions {\n static globalBEA(sym: symbol) {\n const browser = globalThis as unknown as Record<symbol, BrowserEnvActions>;\n if (typeof browser === \"object\" && typeof browser[sym] === \"object\") {\n return { map: browser[sym]._map, finalize: () => browser[sym]._map };\n }\n const map = new Map<string, string>();\n return {\n map,\n finalize: (bea: BrowserEnvActions) => {\n browser[sym] = bea;\n return map;\n },\n };\n }\n\n readonly _map: Map<string, string>;\n constructor(opts: Partial<EnvFactoryOpts>) {\n const { map, finalize } = BrowserEnvActions.globalBEA(Symbol.for(opts.symbol || \"CP_ENV\"));\n // not perfect the globalThis will be polluted\n // also in the case it is not need.\n // better we have a lazy init\n super(opts, map);\n this._map = finalize(this);\n }\n use(): boolean {\n return true;\n }\n}\n\ninterface EnvFactoryOpts {\n readonly symbol: string; // default \"CP_ENV\" used by BrowserEnvActions\n readonly presetEnv: Map<string, string>;\n}\n\nfunction envFactory(opts: Partial<EnvFactoryOpts> = {}): EnvActions {\n const found = [new NodeEnvActions(opts), new DenoEnvActions(opts), new BrowserEnvActions(opts)].find((env) => env.use());\n if (!found) {\n throw new Error(\"SysContainer:envFactory: no env available\");\n }\n return found;\n}\n\ntype OnSetFn = (key: string, value?: string) => void;\nexport interface OnSetItem {\n readonly filter: Set<string>;\n readonly fn: OnSetFn;\n}\n\nexport interface Env extends Omit<EnvActions, \"use\"> {\n onSet(fn: OnSetFn, ...filter: string[]): void;\n}\n\nexport class EnvImpl implements Env {\n readonly #envImpl: EnvActions;\n constructor(opts: Partial<EnvFactoryOpts> = {}) {\n this.#envImpl = envFactory(opts);\n // do nothing\n this.#updatePresets(opts.presetEnv);\n }\n #updatePresets(presetEnv?: Map<string, string>): void {\n if (!presetEnv) {\n return;\n }\n for (const [key, value] of presetEnv) {\n this.#envImpl.set(key, value);\n }\n }\n #applyOnSet(onSet: OnSetItem[], key?: string, value?: string): void {\n onSet.forEach((item) => {\n let keys: string[] = [];\n if (key) {\n keys = [key];\n } else {\n keys = this.#envImpl.keys();\n }\n keys\n .filter((k) => {\n if (item.filter.size === 0) {\n return true;\n }\n if (item.filter.has(k)) {\n return true;\n }\n return false;\n })\n .forEach((k) => {\n let v;\n if (!key && !value) {\n // init\n v = this.#envImpl.get(k);\n } else if (key && !value) {\n // del\n v = undefined;\n } else {\n // set\n v = value;\n }\n item.fn(k, v);\n });\n });\n }\n readonly #onSet: OnSetItem[] = [];\n keys(): string[] {\n return this.#envImpl.keys();\n }\n // filter is not set all sets passed\n onSet(fn: OnSetFn, ...filter: string[]): void {\n const item: OnSetItem = { filter: new Set(filter), fn };\n this.#onSet.push(item);\n this.#applyOnSet([item]);\n }\n get(key: string): string | undefined {\n return this.#envImpl.get(key);\n }\n set(key: string, value?: string): void {\n if (!value) {\n return;\n }\n this.#envImpl.set(key, value);\n this.#applyOnSet(this.#onSet, key, value);\n }\n del(key: string): void {\n this.#envImpl.del(key);\n this.#applyOnSet(this.#onSet, key);\n }\n}\n\nexport const envImpl = new EnvImpl();\n","import { BaseSysAbstraction, WrapperSysAbstraction, WrapperSysAbstractionParams } from \"../base_sys_abstraction\";\nimport { FileService, NamedWritableStream } from \"../file_service\";\nimport { SysAbstraction, SystemService, VoidFunc } from \"../sys_abstraction\";\nimport { envImpl } from \"../sys_env\";\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() {\n return envImpl;\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 if (typeof m !== \"string\") {\n continue;\n }\n const parts = m\n .split(\",\")\n .map((s) => s.trim())\n .filter((s) => s.length);\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 (typeof module === \"string\") {\n const levels = this._modules.get(module);\n if (levels && levels.has(level)) {\n return true;\n }\n }\n const wlevel = this._modules.get(\"*\");\n if (wlevel && typeof level === \"string\") {\n if (wlevel.has(level)) {\n return true;\n }\n }\n if (typeof level !== \"string\") {\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 // if the string is \"*\" it will enable for all modules\n SetDebug(...modules: (string | string[])[]): Logger {\n this._levelHandler.setDebug(...modules);\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;AAAA;AAAA;;;ACEO,IAAK,QAAL,kBAAKA,WAAL;AACL,EAAAA,OAAA,UAAO;AACP,EAAAA,OAAA,WAAQ;AACR,EAAAA,OAAA,UAAO;AACP,EAAAA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,EAAE,OAAO,KAAK,UAAW,CAAC;AAC3D,aAAK,aAAa,SAAS;AAAA,MAC7B,CAAC;AAAA,IACL;AACA,WAAO,OAAO,UAAU;AAAA,EAC1B;AACF;AAEO,IAAM,QAAN,MAAyD;AAAA,EAI9D,YAAY,SAAwB;AAHpC,SAAiB,OAAO,oBAAI,IAAU;AAIpC,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,MAAM,SAAS,KAAmC;AAChD,WAAO,KAAK,IAAI,MAAM,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","TimeMode","RandomMode","IDMode","TimeUnits","_env","module","my","LogWriter"]}
|
package/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import {
|
2
2
|
WebSysAbstraction
|
3
|
-
} from "./chunk-
|
3
|
+
} from "./chunk-XBYS4FSO.js";
|
4
4
|
import {
|
5
5
|
EnvImpl,
|
6
6
|
IDMode,
|
@@ -10,7 +10,7 @@ import {
|
|
10
10
|
TimeMode,
|
11
11
|
TimeUnits,
|
12
12
|
envImpl
|
13
|
-
} from "./chunk-
|
13
|
+
} from "./chunk-CI63N5CK.js";
|
14
14
|
import {
|
15
15
|
__privateAdd,
|
16
16
|
__privateGet,
|
@@ -120,6 +120,9 @@ var LevelHandlerImpl = class {
|
|
120
120
|
}
|
121
121
|
forModules(level, fnAction, ...modules) {
|
122
122
|
for (const m of modules.flat()) {
|
123
|
+
if (typeof m !== "string") {
|
124
|
+
continue;
|
125
|
+
}
|
123
126
|
const parts = m.split(",").map((s) => s.trim()).filter((s) => s.length);
|
124
127
|
for (const p of parts) {
|
125
128
|
fnAction(p);
|
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 // 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);\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 (typeof module === \"string\") {\n const levels = this._modules.get(module);\n if (levels && levels.has(level)) {\n return true;\n }\n }\n const wlevel = this._modules.get(\"*\");\n if (wlevel && typeof level === \"string\") {\n if (wlevel.has(level)) {\n return true;\n }\n }\n if (typeof level !== \"string\") {\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 // if the string is \"*\" it will enable for all modules\n SetDebug(...modules: (string | string[])[]): Logger {\n this._levelHandler.setDebug(...modules);\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,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;;;AC9DA,IAAM,UAAU,IAAI,YAAY;AAEhC,IAAM,WAAN,MAAe;AAAA,EACb,YAAqB,IAAkB;AAAlB;AAAA,EAAmB;AAAA,EACxC,QAAoB;AAClB,WAAO,KAAK,GAAG;AAAA,EACjB;AACF;AAEA,SAAS,gBAAgB,KAA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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"]}
|
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 if (typeof m !== \"string\") {\n continue;\n }\n const parts = m\n .split(\",\")\n .map((s) => s.trim())\n .filter((s) => s.length);\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 (typeof module === \"string\") {\n const levels = this._modules.get(module);\n if (levels && levels.has(level)) {\n return true;\n }\n }\n const wlevel = this._modules.get(\"*\");\n if (wlevel && typeof level === \"string\") {\n if (wlevel.has(level)) {\n return true;\n }\n }\n if (typeof level !== \"string\") {\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 // if the string is \"*\" it will enable for all modules\n SetDebug(...modules: (string | string[])[]): Logger {\n this._levelHandler.setDebug(...modules);\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,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;;;AC9DA,IAAM,UAAU,IAAI,YAAY;AAEhC,IAAM,WAAN,MAAe;AAAA,EACb,YAAqB,IAAkB;AAAlB;AAAA,EAAmB;AAAA,EACxC,QAAoB;AAClB,WAAO,KAAK,GAAG;AAAA,EACjB;AACF;AAEA,SAAS,gBAAgB,KAA6C;AACpE,QAAM,MAAkC,CAAC;AACzC,SAAO,KAAK,GAAG,EAAE,QAAQ,CAAC,QAAQ;AAChC,UAAM,IAAI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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/node/index.cjs
CHANGED
@@ -365,16 +365,24 @@ var DenoEnvActions = class {
|
|
365
365
|
_deno = new WeakMap();
|
366
366
|
_env2 = new WeakMap();
|
367
367
|
var BrowserEnvActions = class _BrowserEnvActions extends DenoEnvActions {
|
368
|
-
static
|
368
|
+
static globalBEA(sym) {
|
369
369
|
const browser = globalThis;
|
370
370
|
if (typeof browser === "object" && typeof browser[sym] === "object") {
|
371
|
-
return browser[sym];
|
371
|
+
return { map: browser[sym]._map, finalize: () => browser[sym]._map };
|
372
372
|
}
|
373
|
-
|
374
|
-
return
|
373
|
+
const map = /* @__PURE__ */ new Map();
|
374
|
+
return {
|
375
|
+
map,
|
376
|
+
finalize: (bea) => {
|
377
|
+
browser[sym] = bea;
|
378
|
+
return map;
|
379
|
+
}
|
380
|
+
};
|
375
381
|
}
|
376
382
|
constructor(opts) {
|
377
|
-
|
383
|
+
const { map, finalize } = _BrowserEnvActions.globalBEA(Symbol.for(opts.symbol || "CP_ENV"));
|
384
|
+
super(opts, map);
|
385
|
+
this._map = finalize(this);
|
378
386
|
}
|
379
387
|
use() {
|
380
388
|
return true;
|
package/node/index.cjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/node/index.ts","../../../src/node/node_file_service.ts","../../../src/time.ts","../../../src/base_sys_abstraction.ts","../../../src/sys_env.ts","../../../src/node/node_sys_abstraction.ts","../../../src/node/mock_file_service.ts"],"sourcesContent":["export * from \"./node_file_service\";\nexport * from \"./node_sys_abstraction\";\nexport * from \"./mock_file_service\";\n","import path from \"node:path\";\nimport fs from \"node:fs\";\nimport { FileService, NamedWritableStream } from \"../file_service\";\n\nexport class NodeFileService implements FileService {\n readonly baseDir: string;\n constructor(baseDir: string = process.cwd()) {\n this.baseDir = this.abs(baseDir);\n }\n\n nodeImport(fname: string): string {\n // console.log('nodeImport:'+ fname);\n if (path.isAbsolute(fname)) {\n return fname;\n } else {\n return \"./\" + path.normalize(fname);\n }\n }\n\n readFileString(fname: string): Promise<string> {\n return fs.promises.readFile(fname, { encoding: \"utf-8\" });\n }\n\n dirname(fname: string): string {\n return path.dirname(fname);\n }\n basename(fname: string): string {\n return path.basename(fname);\n }\n\n join(...paths: string[]): string {\n return path.join(...paths);\n }\n\n relative(from: string, to?: string): string {\n if (to === undefined) {\n to = from;\n from = process.cwd();\n }\n const ret = path.relative(from, to);\n // console.log('relative:'+ from + \" -> \" + to + \"= \" + ret);\n return ret;\n }\n\n abs(fname: string): string {\n if (path.isAbsolute(fname)) {\n return fname;\n } else {\n const cwd = process.cwd();\n return path.resolve(cwd, fname);\n }\n }\n\n isAbsolute(fname: string): boolean {\n return path.isAbsolute(fname);\n }\n\n async writeFileString(fname: string, content: string): Promise<void> {\n const o = await this.create(fname);\n const wr = o.stream.getWriter();\n await wr.write(new TextEncoder().encode(content));\n await wr.close();\n }\n\n async create(fname: string): Promise<NamedWritableStream> {\n let oName = fname;\n if (!path.isAbsolute(fname)) {\n oName = this.abs(fname);\n }\n\n const base = path.dirname(oName);\n await fs.promises.mkdir(base, { recursive: true });\n const out = fs.createWriteStream(oName);\n return {\n name: oName,\n stream: new WritableStream<Uint8Array>({\n write(chunk) {\n out.write(chunk);\n },\n close() {\n out.close();\n },\n abort() {\n throw new Error(\"not implemented\");\n },\n }),\n };\n }\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","export interface EnvActions {\n get(key: string): string | undefined;\n set(key: string, value?: string): void;\n del(key: string): void;\n keys(): string[];\n use(): boolean;\n}\n\nclass NodeEnvActions implements EnvActions {\n readonly #node = globalThis as unknown as { process: { env: Record<string, string> } };\n\n // eslint-disable-next-line @typescript-eslint/no-useless-constructor, @typescript-eslint/no-unused-vars\n constructor(opts: Partial<EnvFactoryOpts>) {\n // do nothing\n }\n use(): boolean {\n return typeof this.#node === \"object\" && typeof this.#node.process === \"object\" && typeof this.#node.process.env === \"object\";\n }\n readonly #env = this.use() ? process.env : {};\n keys(): string[] {\n return Object.keys(this.#env);\n }\n get(key: string): string | undefined {\n return this.#env[key];\n }\n set(key: string, value?: string): void {\n if (value) {\n this.#env[key] = value;\n }\n }\n del(key: string): void {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this.#env[key];\n }\n}\n\nclass DenoEnvActions implements EnvActions {\n readonly #deno = globalThis as unknown as { Deno: { env: Map<string, string> } };\n\n readonly #env: Map<string, string>;\n constructor(opts: Partial<EnvFactoryOpts>, env?: Map<string, string>) {\n if (env) {\n this.#env = env;\n } else {\n this.#env = this.use() ? this.#deno.Deno.env : new Map();\n }\n }\n use(): boolean {\n return typeof this.#deno === \"object\" && typeof this.#deno.Deno === \"object\" && typeof this.#deno.Deno.env === \"object\";\n }\n keys(): string[] {\n return Array.from(this.#env.keys());\n }\n get(key: string): string | undefined {\n return this.#env.get(key);\n }\n set(key: string, value?: string): void {\n if (value) {\n this.#env.set(key, value);\n }\n }\n del(key: string): void {\n this.#env.delete(key);\n }\n}\n\nclass BrowserEnvActions extends DenoEnvActions {\n static getEnv(sym: symbol) {\n const browser = globalThis as unknown as Record<symbol, Map<string, string>>;\n if (typeof browser === \"object\" && typeof browser[sym] === \"object\") {\n return browser[sym];\n }\n browser[sym] = new Map();\n return browser[sym];\n }\n\n constructor(opts: Partial<EnvFactoryOpts>) {\n // not perfect the globalThis will be polluted\n // also in the case it is not need.\n // better we have a lazy init\n super(opts, BrowserEnvActions.getEnv(Symbol.for(opts.symbol || \"CP_ENV\")));\n }\n use(): boolean {\n return true;\n }\n}\n\ninterface EnvFactoryOpts {\n readonly symbol: string; // default \"CP_ENV\" used by BrowserEnvActions\n readonly presetEnv: Map<string, string>;\n}\n\nfunction envFactory(opts: Partial<EnvFactoryOpts> = {}): EnvActions {\n const found = [new NodeEnvActions(opts), new DenoEnvActions(opts), new BrowserEnvActions(opts)].find((env) => env.use());\n if (!found) {\n throw new Error(\"SysContainer:envFactory: no env available\");\n }\n return found;\n}\n\ntype OnSetFn = (key: string, value?: string) => void;\nexport interface OnSetItem {\n readonly filter: Set<string>;\n readonly fn: OnSetFn;\n}\n\nexport interface Env extends Omit<EnvActions, \"use\"> {\n onSet(fn: OnSetFn, ...filter: string[]): void;\n}\n\nexport class EnvImpl implements Env {\n readonly #envImpl: EnvActions;\n constructor(opts: Partial<EnvFactoryOpts> = {}) {\n this.#envImpl = envFactory(opts);\n // do nothing\n this.#updatePresets(opts.presetEnv);\n }\n #updatePresets(presetEnv?: Map<string, string>): void {\n if (!presetEnv) {\n return;\n }\n for (const [key, value] of presetEnv) {\n this.#envImpl.set(key, value);\n }\n }\n #applyOnSet(onSet: OnSetItem[], key?: string, value?: string): void {\n onSet.forEach((item) => {\n let keys: string[] = [];\n if (key) {\n keys = [key];\n } else {\n keys = this.#envImpl.keys();\n }\n keys\n .filter((k) => {\n if (item.filter.size === 0) {\n return true;\n }\n if (item.filter.has(k)) {\n return true;\n }\n return false;\n })\n .forEach((k) => {\n let v;\n if (!key && !value) {\n // init\n v = this.#envImpl.get(k);\n } else if (key && !value) {\n // del\n v = undefined;\n } else {\n // set\n v = value;\n }\n item.fn(k, v);\n });\n });\n }\n readonly #onSet: OnSetItem[] = [];\n keys(): string[] {\n return this.#envImpl.keys();\n }\n // filter is not set all sets passed\n onSet(fn: OnSetFn, ...filter: string[]): void {\n const item: OnSetItem = { filter: new Set(filter), fn };\n this.#onSet.push(item);\n this.#applyOnSet([item]);\n }\n get(key: string): string | undefined {\n return this.#envImpl.get(key);\n }\n set(key: string, value?: string): void {\n if (!value) {\n return;\n }\n this.#envImpl.set(key, value);\n this.#applyOnSet(this.#onSet, key, value);\n }\n del(key: string): void {\n this.#envImpl.del(key);\n this.#applyOnSet(this.#onSet, key);\n }\n}\n\nexport const envImpl = new EnvImpl();\n","import { SysAbstraction, SystemService, VoidFunc } from \"../sys_abstraction\";\nimport {\n BaseSysAbstraction,\n ExitHandler,\n ExitService,\n WrapperSysAbstraction,\n WrapperSysAbstractionParams,\n} from \"../base_sys_abstraction\";\nimport { NodeFileService } from \"./node_file_service\";\nimport { envImpl } from \"../sys_env\";\n\nexport class ExitServiceImpl implements ExitService {\n constructor() {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n process.on(\"unhandledRejection\", (reason: string, p: Promise<unknown>) => {\n this.exit(19);\n });\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n process.on(\"uncaughtException\", (error: Error) => {\n this.exit(18);\n });\n process.on(\"close\", () => {\n this.exit(0);\n });\n process.on(\"exit\", () => {\n this.exit(0);\n });\n process.on(\"SIGQUIT\", () => {\n this.exit(3);\n });\n process.on(\"SIGINT\", () => {\n this.exit(2);\n });\n process.on(\"SIGTERM\", () => {\n this.exit(9);\n });\n }\n _exitHandlers: ExitHandler[] = [];\n injectExitHandlers(hdls: ExitHandler[]): void {\n // console.log(\"ExitService: injecting exit handlers\", hdls)\n this._exitHandlers = hdls;\n }\n invoked = false;\n readonly _handleExit = async (): Promise<void> => {\n if (this.invoked) {\n // console.error(\"ExitService: already invoked\");\n return;\n }\n this.invoked = true;\n for (const h of this._exitHandlers) {\n try {\n // console.log(`ExitService: calling handler ${h.id}`)\n const ret = h.hdl();\n // console.log(`ExitService: called handler ${h.id}`, ret)\n if (typeof (ret as Promise<void>).then === \"function\") {\n await ret;\n }\n } finally {\n // ignore\n }\n }\n };\n\n exit(code: number): void {\n // console.log(\"ExitService: exit called\", code)\n this._handleExit()\n .then(() => {\n process.exit(code);\n })\n .catch((err) => {\n console.error(\"ExitService: failed to handle exit\", err);\n process.exit(code);\n });\n }\n}\n\nexport class NodeSystemService implements SystemService {\n static readonly _exitHandlers: ExitHandler[] = [];\n readonly _exitService: ExitService = new ExitServiceImpl();\n constructor() {\n this._exitService.injectExitHandlers(NodeSystemService._exitHandlers);\n }\n\n Env() {\n return envImpl;\n }\n\n Args() {\n return process.argv;\n }\n\n OnExit(hdl: VoidFunc): VoidFunc {\n const id = crypto.randomUUID();\n NodeSystemService._exitHandlers.push({ hdl, id });\n return () => {\n const idx = NodeSystemService._exitHandlers.findIndex((h) => h.id === id);\n if (idx >= 0) {\n NodeSystemService._exitHandlers.splice(idx, 1);\n }\n };\n }\n\n Exit(code: number): void {\n this._exitService.exit(code);\n }\n}\n\nlet my: BaseSysAbstraction | undefined = undefined;\nexport function NodeSysAbstraction(param?: WrapperSysAbstractionParams): SysAbstraction {\n if (!my) {\n my = new BaseSysAbstraction({\n FileSystem: new NodeFileService(),\n SystemService: new NodeSystemService(),\n });\n }\n return new WrapperSysAbstraction(my, param);\n}\n","import { NamedWritableStream } from \"../file_service\";\nimport { NodeFileService } from \"./node_file_service\";\n\nexport interface FileCollector {\n readonly name: string;\n content: string;\n}\n\nexport class MockFileService extends NodeFileService {\n readonly files = {} as Record<string, FileCollector>;\n\n // override abs(fname: string): string {\n // return this.join(\"/mock/\", fname);\n // }\n\n override async create(fname: string): Promise<NamedWritableStream> {\n let oName = fname;\n if (!this.isAbsolute(fname)) {\n oName = await this.abs(fname);\n }\n\n const fc = {\n name: oName,\n content: \"\",\n };\n this.files[oName] = fc;\n this.files[fname] = fc;\n const decoder = new TextDecoder();\n\n return {\n name: oName,\n stream: new WritableStream<Uint8Array>({\n write(chunk) {\n fc.content = fc.content + decoder.decode(chunk);\n },\n close() {\n // do nothing\n },\n abort() {\n throw new Error(\"not implemented\");\n },\n }),\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,uBAAiB;AACjB,qBAAe;AAGR,IAAM,kBAAN,MAA6C;AAAA,EAElD,YAAY,UAAkB,QAAQ,IAAI,GAAG;AAC3C,SAAK,UAAU,KAAK,IAAI,OAAO;AAAA,EACjC;AAAA,EAEA,WAAW,OAAuB;AAEhC,QAAI,iBAAAA,QAAK,WAAW,KAAK,GAAG;AAC1B,aAAO;AAAA,IACT,OAAO;AACL,aAAO,OAAO,iBAAAA,QAAK,UAAU,KAAK;AAAA,IACpC;AAAA,EACF;AAAA,EAEA,eAAe,OAAgC;AAC7C,WAAO,eAAAC,QAAG,SAAS,SAAS,OAAO,EAAE,UAAU,QAAQ,CAAC;AAAA,EAC1D;AAAA,EAEA,QAAQ,OAAuB;AAC7B,WAAO,iBAAAD,QAAK,QAAQ,KAAK;AAA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Ae,OAAO,OAA6C;AACjE,QAAI,QAAQ;AACZ,QAAI,CAAC,KAAK,WAAW,KAAK,GAAG;AAC3B,cAAQ,MAAM,KAAK,IAAI,KAAK;AAAA,IAC9B;AAEA,UAAM,KAAK;AAAA,MACT,MAAM;AAAA,MACN,SAAS;AAAA,IACX;AACA,SAAK,MAAM,KAAK,IAAI;AACpB,SAAK,MAAM,KAAK,IAAI;AACpB,UAAMC,WAAU,IAAI,YAAY;AAEhC,WAAO;AAAA,MACL,MAAM;AAAA,MACN,QAAQ,IAAI,eAA2B;AAAA,QACrC,MAAM,OAAO;AACX,aAAG,UAAU,GAAG,UAAUA,SAAQ,OAAO,KAAK;AAAA,QAChD;AAAA,QACA,QAAQ;AAAA,QAER;AAAA,QACA,QAAQ;AACN,gBAAM,IAAI,MAAM,iBAAiB;AAAA,QACnC;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":["path","fs","_env","decoder"]}
|
1
|
+
{"version":3,"sources":["../../../src/node/index.ts","../../../src/node/node_file_service.ts","../../../src/time.ts","../../../src/base_sys_abstraction.ts","../../../src/sys_env.ts","../../../src/node/node_sys_abstraction.ts","../../../src/node/mock_file_service.ts"],"sourcesContent":["export * from \"./node_file_service\";\nexport * from \"./node_sys_abstraction\";\nexport * from \"./mock_file_service\";\n","import path from \"node:path\";\nimport fs from \"node:fs\";\nimport { FileService, NamedWritableStream } from \"../file_service\";\n\nexport class NodeFileService implements FileService {\n readonly baseDir: string;\n constructor(baseDir: string = process.cwd()) {\n this.baseDir = this.abs(baseDir);\n }\n\n nodeImport(fname: string): string {\n // console.log('nodeImport:'+ fname);\n if (path.isAbsolute(fname)) {\n return fname;\n } else {\n return \"./\" + path.normalize(fname);\n }\n }\n\n readFileString(fname: string): Promise<string> {\n return fs.promises.readFile(fname, { encoding: \"utf-8\" });\n }\n\n dirname(fname: string): string {\n return path.dirname(fname);\n }\n basename(fname: string): string {\n return path.basename(fname);\n }\n\n join(...paths: string[]): string {\n return path.join(...paths);\n }\n\n relative(from: string, to?: string): string {\n if (to === undefined) {\n to = from;\n from = process.cwd();\n }\n const ret = path.relative(from, to);\n // console.log('relative:'+ from + \" -> \" + to + \"= \" + ret);\n return ret;\n }\n\n abs(fname: string): string {\n if (path.isAbsolute(fname)) {\n return fname;\n } else {\n const cwd = process.cwd();\n return path.resolve(cwd, fname);\n }\n }\n\n isAbsolute(fname: string): boolean {\n return path.isAbsolute(fname);\n }\n\n async writeFileString(fname: string, content: string): Promise<void> {\n const o = await this.create(fname);\n const wr = o.stream.getWriter();\n await wr.write(new TextEncoder().encode(content));\n await wr.close();\n }\n\n async create(fname: string): Promise<NamedWritableStream> {\n let oName = fname;\n if (!path.isAbsolute(fname)) {\n oName = this.abs(fname);\n }\n\n const base = path.dirname(oName);\n await fs.promises.mkdir(base, { recursive: true });\n const out = fs.createWriteStream(oName);\n return {\n name: oName,\n stream: new WritableStream<Uint8Array>({\n write(chunk) {\n out.write(chunk);\n },\n close() {\n out.close();\n },\n abort() {\n throw new Error(\"not implemented\");\n },\n }),\n };\n }\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","export interface EnvActions {\n get(key: string): string | undefined;\n set(key: string, value?: string): void;\n del(key: string): void;\n keys(): string[];\n use(): boolean;\n}\n\nclass NodeEnvActions implements EnvActions {\n readonly #node = globalThis as unknown as { process: { env: Record<string, string> } };\n\n // eslint-disable-next-line @typescript-eslint/no-useless-constructor, @typescript-eslint/no-unused-vars\n constructor(opts: Partial<EnvFactoryOpts>) {\n // do nothing\n }\n use(): boolean {\n return typeof this.#node === \"object\" && typeof this.#node.process === \"object\" && typeof this.#node.process.env === \"object\";\n }\n readonly #env = this.use() ? process.env : {};\n keys(): string[] {\n return Object.keys(this.#env);\n }\n get(key: string): string | undefined {\n return this.#env[key];\n }\n set(key: string, value?: string): void {\n if (value) {\n this.#env[key] = value;\n }\n }\n del(key: string): void {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this.#env[key];\n }\n}\n\nclass DenoEnvActions implements EnvActions {\n readonly #deno = globalThis as unknown as { Deno: { env: Map<string, string> } };\n\n readonly #env: Map<string, string>;\n constructor(opts: Partial<EnvFactoryOpts>, env?: Map<string, string>) {\n if (env) {\n this.#env = env;\n } else {\n this.#env = this.use() ? this.#deno.Deno.env : new Map();\n }\n }\n use(): boolean {\n return typeof this.#deno === \"object\" && typeof this.#deno.Deno === \"object\" && typeof this.#deno.Deno.env === \"object\";\n }\n keys(): string[] {\n return Array.from(this.#env.keys());\n }\n get(key: string): string | undefined {\n return this.#env.get(key);\n }\n set(key: string, value?: string): void {\n if (value) {\n this.#env.set(key, value);\n }\n }\n del(key: string): void {\n this.#env.delete(key);\n }\n}\n\nclass BrowserEnvActions extends DenoEnvActions {\n static globalBEA(sym: symbol) {\n const browser = globalThis as unknown as Record<symbol, BrowserEnvActions>;\n if (typeof browser === \"object\" && typeof browser[sym] === \"object\") {\n return { map: browser[sym]._map, finalize: () => browser[sym]._map };\n }\n const map = new Map<string, string>();\n return {\n map,\n finalize: (bea: BrowserEnvActions) => {\n browser[sym] = bea;\n return map;\n },\n };\n }\n\n readonly _map: Map<string, string>;\n constructor(opts: Partial<EnvFactoryOpts>) {\n const { map, finalize } = BrowserEnvActions.globalBEA(Symbol.for(opts.symbol || \"CP_ENV\"));\n // not perfect the globalThis will be polluted\n // also in the case it is not need.\n // better we have a lazy init\n super(opts, map);\n this._map = finalize(this);\n }\n use(): boolean {\n return true;\n }\n}\n\ninterface EnvFactoryOpts {\n readonly symbol: string; // default \"CP_ENV\" used by BrowserEnvActions\n readonly presetEnv: Map<string, string>;\n}\n\nfunction envFactory(opts: Partial<EnvFactoryOpts> = {}): EnvActions {\n const found = [new NodeEnvActions(opts), new DenoEnvActions(opts), new BrowserEnvActions(opts)].find((env) => env.use());\n if (!found) {\n throw new Error(\"SysContainer:envFactory: no env available\");\n }\n return found;\n}\n\ntype OnSetFn = (key: string, value?: string) => void;\nexport interface OnSetItem {\n readonly filter: Set<string>;\n readonly fn: OnSetFn;\n}\n\nexport interface Env extends Omit<EnvActions, \"use\"> {\n onSet(fn: OnSetFn, ...filter: string[]): void;\n}\n\nexport class EnvImpl implements Env {\n readonly #envImpl: EnvActions;\n constructor(opts: Partial<EnvFactoryOpts> = {}) {\n this.#envImpl = envFactory(opts);\n // do nothing\n this.#updatePresets(opts.presetEnv);\n }\n #updatePresets(presetEnv?: Map<string, string>): void {\n if (!presetEnv) {\n return;\n }\n for (const [key, value] of presetEnv) {\n this.#envImpl.set(key, value);\n }\n }\n #applyOnSet(onSet: OnSetItem[], key?: string, value?: string): void {\n onSet.forEach((item) => {\n let keys: string[] = [];\n if (key) {\n keys = [key];\n } else {\n keys = this.#envImpl.keys();\n }\n keys\n .filter((k) => {\n if (item.filter.size === 0) {\n return true;\n }\n if (item.filter.has(k)) {\n return true;\n }\n return false;\n })\n .forEach((k) => {\n let v;\n if (!key && !value) {\n // init\n v = this.#envImpl.get(k);\n } else if (key && !value) {\n // del\n v = undefined;\n } else {\n // set\n v = value;\n }\n item.fn(k, v);\n });\n });\n }\n readonly #onSet: OnSetItem[] = [];\n keys(): string[] {\n return this.#envImpl.keys();\n }\n // filter is not set all sets passed\n onSet(fn: OnSetFn, ...filter: string[]): void {\n const item: OnSetItem = { filter: new Set(filter), fn };\n this.#onSet.push(item);\n this.#applyOnSet([item]);\n }\n get(key: string): string | undefined {\n return this.#envImpl.get(key);\n }\n set(key: string, value?: string): void {\n if (!value) {\n return;\n }\n this.#envImpl.set(key, value);\n this.#applyOnSet(this.#onSet, key, value);\n }\n del(key: string): void {\n this.#envImpl.del(key);\n this.#applyOnSet(this.#onSet, key);\n }\n}\n\nexport const envImpl = new EnvImpl();\n","import { SysAbstraction, SystemService, VoidFunc } from \"../sys_abstraction\";\nimport {\n BaseSysAbstraction,\n ExitHandler,\n ExitService,\n WrapperSysAbstraction,\n WrapperSysAbstractionParams,\n} from \"../base_sys_abstraction\";\nimport { NodeFileService } from \"./node_file_service\";\nimport { envImpl } from \"../sys_env\";\n\nexport class ExitServiceImpl implements ExitService {\n constructor() {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n process.on(\"unhandledRejection\", (reason: string, p: Promise<unknown>) => {\n this.exit(19);\n });\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n process.on(\"uncaughtException\", (error: Error) => {\n this.exit(18);\n });\n process.on(\"close\", () => {\n this.exit(0);\n });\n process.on(\"exit\", () => {\n this.exit(0);\n });\n process.on(\"SIGQUIT\", () => {\n this.exit(3);\n });\n process.on(\"SIGINT\", () => {\n this.exit(2);\n });\n process.on(\"SIGTERM\", () => {\n this.exit(9);\n });\n }\n _exitHandlers: ExitHandler[] = [];\n injectExitHandlers(hdls: ExitHandler[]): void {\n // console.log(\"ExitService: injecting exit handlers\", hdls)\n this._exitHandlers = hdls;\n }\n invoked = false;\n readonly _handleExit = async (): Promise<void> => {\n if (this.invoked) {\n // console.error(\"ExitService: already invoked\");\n return;\n }\n this.invoked = true;\n for (const h of this._exitHandlers) {\n try {\n // console.log(`ExitService: calling handler ${h.id}`)\n const ret = h.hdl();\n // console.log(`ExitService: called handler ${h.id}`, ret)\n if (typeof (ret as Promise<void>).then === \"function\") {\n await ret;\n }\n } finally {\n // ignore\n }\n }\n };\n\n exit(code: number): void {\n // console.log(\"ExitService: exit called\", code)\n this._handleExit()\n .then(() => {\n process.exit(code);\n })\n .catch((err) => {\n console.error(\"ExitService: failed to handle exit\", err);\n process.exit(code);\n });\n }\n}\n\nexport class NodeSystemService implements SystemService {\n static readonly _exitHandlers: ExitHandler[] = [];\n readonly _exitService: ExitService = new ExitServiceImpl();\n constructor() {\n this._exitService.injectExitHandlers(NodeSystemService._exitHandlers);\n }\n\n Env() {\n return envImpl;\n }\n\n Args() {\n return process.argv;\n }\n\n OnExit(hdl: VoidFunc): VoidFunc {\n const id = crypto.randomUUID();\n NodeSystemService._exitHandlers.push({ hdl, id });\n return () => {\n const idx = NodeSystemService._exitHandlers.findIndex((h) => h.id === id);\n if (idx >= 0) {\n NodeSystemService._exitHandlers.splice(idx, 1);\n }\n };\n }\n\n Exit(code: number): void {\n this._exitService.exit(code);\n }\n}\n\nlet my: BaseSysAbstraction | undefined = undefined;\nexport function NodeSysAbstraction(param?: WrapperSysAbstractionParams): SysAbstraction {\n if (!my) {\n my = new BaseSysAbstraction({\n FileSystem: new NodeFileService(),\n SystemService: new NodeSystemService(),\n });\n }\n return new WrapperSysAbstraction(my, param);\n}\n","import { NamedWritableStream } from \"../file_service\";\nimport { NodeFileService } from \"./node_file_service\";\n\nexport interface FileCollector {\n readonly name: string;\n content: string;\n}\n\nexport class MockFileService extends NodeFileService {\n readonly files = {} as Record<string, FileCollector>;\n\n // override abs(fname: string): string {\n // return this.join(\"/mock/\", fname);\n // }\n\n override async create(fname: string): Promise<NamedWritableStream> {\n let oName = fname;\n if (!this.isAbsolute(fname)) {\n oName = await this.abs(fname);\n }\n\n const fc = {\n name: oName,\n content: \"\",\n };\n this.files[oName] = fc;\n this.files[fname] = fc;\n const decoder = new TextDecoder();\n\n return {\n name: oName,\n stream: new WritableStream<Uint8Array>({\n write(chunk) {\n fc.content = fc.content + decoder.decode(chunk);\n },\n close() {\n // do nothing\n },\n abort() {\n throw new Error(\"not implemented\");\n },\n }),\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,uBAAiB;AACjB,qBAAe;AAGR,IAAM,kBAAN,MAA6C;AAAA,EAElD,YAAY,UAAkB,QAAQ,IAAI,GAAG;AAC3C,SAAK,UAAU,KAAK,IAAI,OAAO;AAAA,EACjC;AAAA,EAEA,WAAW,OAAuB;AAEhC,QAAI,iBAAAA,QAAK,WAAW,KAAK,GAAG;AAC1B,aAAO;AAAA,IACT,OAAO;AACL,aAAO,OAAO,iBAAAA,QAAK,UAAU,KAAK;AAAA,IACpC;AAAA,EACF;AAAA,EAEA,eAAe,OAAgC;AAC7C,WAAO,eAAAC,QAAG,SAAS,SAAS,OAAO,EAAE,UAAU,QAAQ,CAAC;AAAA,EAC1D;AAAA,EAEA,QAAQ,OAAuB;AAC7B,WAAO,iBAAAD,QAAK,QAAQ,KAAK;AAAA,EAC3B;AAAA,EACA,SAAS,OAAuB;AAC9B,WAAO,iBAAAA,QAAK,SAAS,KAAK;AAAA,EAC5B;AAAA,EAEA,QAAQ,OAAyB;AAC/B,WAAO,iBAAAA,QAAK,KAAK,GAAG,KAAK;AAAA,EAC3B;AAAA,EAEA,SAAS,MAAc,IAAqB;AAC1C,QAAI,OAAO,QAAW;AACpB,WAAK;AACL,aAAO,QAAQ,IAAI;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K,WAAW,KAAK,GAAG;AAC3B,cAAQ,MAAM,KAAK,IAAI,KAAK;AAAA,IAC9B;AAEA,UAAM,KAAK;AAAA,MACT,MAAM;AAAA,MACN,SAAS;AAAA,IACX;AACA,SAAK,MAAM,KAAK,IAAI;AACpB,SAAK,MAAM,KAAK,IAAI;AACpB,UAAMC,WAAU,IAAI,YAAY;AAEhC,WAAO;AAAA,MACL,MAAM;AAAA,MACN,QAAQ,IAAI,eAA2B;AAAA,QACrC,MAAM,OAAO;AACX,aAAG,UAAU,GAAG,UAAUA,SAAQ,OAAO,KAAK;AAAA,QAChD;AAAA,QACA,QAAQ;AAAA,QAER;AAAA,QACA,QAAQ;AACN,gBAAM,IAAI,MAAM,iBAAiB;AAAA,QACnC;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":["path","fs","_env","decoder"]}
|
package/node/index.js
CHANGED
package/package.json
CHANGED
package/web/index.cjs
CHANGED
@@ -275,16 +275,24 @@ var DenoEnvActions = class {
|
|
275
275
|
_deno = new WeakMap();
|
276
276
|
_env2 = new WeakMap();
|
277
277
|
var BrowserEnvActions = class _BrowserEnvActions extends DenoEnvActions {
|
278
|
-
static
|
278
|
+
static globalBEA(sym) {
|
279
279
|
const browser = globalThis;
|
280
280
|
if (typeof browser === "object" && typeof browser[sym] === "object") {
|
281
|
-
return browser[sym];
|
281
|
+
return { map: browser[sym]._map, finalize: () => browser[sym]._map };
|
282
282
|
}
|
283
|
-
|
284
|
-
return
|
283
|
+
const map = /* @__PURE__ */ new Map();
|
284
|
+
return {
|
285
|
+
map,
|
286
|
+
finalize: (bea) => {
|
287
|
+
browser[sym] = bea;
|
288
|
+
return map;
|
289
|
+
}
|
290
|
+
};
|
285
291
|
}
|
286
292
|
constructor(opts) {
|
287
|
-
|
293
|
+
const { map, finalize } = _BrowserEnvActions.globalBEA(Symbol.for(opts.symbol || "CP_ENV"));
|
294
|
+
super(opts, map);
|
295
|
+
this._map = finalize(this);
|
288
296
|
}
|
289
297
|
use() {
|
290
298
|
return true;
|
package/web/index.cjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/web/index.ts","../../../src/time.ts","../../../src/base_sys_abstraction.ts","../../../src/sys_env.ts","../../../src/web/web_sys_abstraction.ts"],"sourcesContent":["export * from \"./web_sys_abstraction\";\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","export interface EnvActions {\n get(key: string): string | undefined;\n set(key: string, value?: string): void;\n del(key: string): void;\n keys(): string[];\n use(): boolean;\n}\n\nclass NodeEnvActions implements EnvActions {\n readonly #node = globalThis as unknown as { process: { env: Record<string, string> } };\n\n // eslint-disable-next-line @typescript-eslint/no-useless-constructor, @typescript-eslint/no-unused-vars\n constructor(opts: Partial<EnvFactoryOpts>) {\n // do nothing\n }\n use(): boolean {\n return typeof this.#node === \"object\" && typeof this.#node.process === \"object\" && typeof this.#node.process.env === \"object\";\n }\n readonly #env = this.use() ? process.env : {};\n keys(): string[] {\n return Object.keys(this.#env);\n }\n get(key: string): string | undefined {\n return this.#env[key];\n }\n set(key: string, value?: string): void {\n if (value) {\n this.#env[key] = value;\n }\n }\n del(key: string): void {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this.#env[key];\n }\n}\n\nclass DenoEnvActions implements EnvActions {\n readonly #deno = globalThis as unknown as { Deno: { env: Map<string, string> } };\n\n readonly #env: Map<string, string>;\n constructor(opts: Partial<EnvFactoryOpts>, env?: Map<string, string>) {\n if (env) {\n this.#env = env;\n } else {\n this.#env = this.use() ? this.#deno.Deno.env : new Map();\n }\n }\n use(): boolean {\n return typeof this.#deno === \"object\" && typeof this.#deno.Deno === \"object\" && typeof this.#deno.Deno.env === \"object\";\n }\n keys(): string[] {\n return Array.from(this.#env.keys());\n }\n get(key: string): string | undefined {\n return this.#env.get(key);\n }\n set(key: string, value?: string): void {\n if (value) {\n this.#env.set(key, value);\n }\n }\n del(key: string): void {\n this.#env.delete(key);\n }\n}\n\nclass BrowserEnvActions extends DenoEnvActions {\n static getEnv(sym: symbol) {\n const browser = globalThis as unknown as Record<symbol, Map<string, string>>;\n if (typeof browser === \"object\" && typeof browser[sym] === \"object\") {\n return browser[sym];\n }\n browser[sym] = new Map();\n return browser[sym];\n }\n\n constructor(opts: Partial<EnvFactoryOpts>) {\n // not perfect the globalThis will be polluted\n // also in the case it is not need.\n // better we have a lazy init\n super(opts, BrowserEnvActions.getEnv(Symbol.for(opts.symbol || \"CP_ENV\")));\n }\n use(): boolean {\n return true;\n }\n}\n\ninterface EnvFactoryOpts {\n readonly symbol: string; // default \"CP_ENV\" used by BrowserEnvActions\n readonly presetEnv: Map<string, string>;\n}\n\nfunction envFactory(opts: Partial<EnvFactoryOpts> = {}): EnvActions {\n const found = [new NodeEnvActions(opts), new DenoEnvActions(opts), new BrowserEnvActions(opts)].find((env) => env.use());\n if (!found) {\n throw new Error(\"SysContainer:envFactory: no env available\");\n }\n return found;\n}\n\ntype OnSetFn = (key: string, value?: string) => void;\nexport interface OnSetItem {\n readonly filter: Set<string>;\n readonly fn: OnSetFn;\n}\n\nexport interface Env extends Omit<EnvActions, \"use\"> {\n onSet(fn: OnSetFn, ...filter: string[]): void;\n}\n\nexport class EnvImpl implements Env {\n readonly #envImpl: EnvActions;\n constructor(opts: Partial<EnvFactoryOpts> = {}) {\n this.#envImpl = envFactory(opts);\n // do nothing\n this.#updatePresets(opts.presetEnv);\n }\n #updatePresets(presetEnv?: Map<string, string>): void {\n if (!presetEnv) {\n return;\n }\n for (const [key, value] of presetEnv) {\n this.#envImpl.set(key, value);\n }\n }\n #applyOnSet(onSet: OnSetItem[], key?: string, value?: string): void {\n onSet.forEach((item) => {\n let keys: string[] = [];\n if (key) {\n keys = [key];\n } else {\n keys = this.#envImpl.keys();\n }\n keys\n .filter((k) => {\n if (item.filter.size === 0) {\n return true;\n }\n if (item.filter.has(k)) {\n return true;\n }\n return false;\n })\n .forEach((k) => {\n let v;\n if (!key && !value) {\n // init\n v = this.#envImpl.get(k);\n } else if (key && !value) {\n // del\n v = undefined;\n } else {\n // set\n v = value;\n }\n item.fn(k, v);\n });\n });\n }\n readonly #onSet: OnSetItem[] = [];\n keys(): string[] {\n return this.#envImpl.keys();\n }\n // filter is not set all sets passed\n onSet(fn: OnSetFn, ...filter: string[]): void {\n const item: OnSetItem = { filter: new Set(filter), fn };\n this.#onSet.push(item);\n this.#applyOnSet([item]);\n }\n get(key: string): string | undefined {\n return this.#envImpl.get(key);\n }\n set(key: string, value?: string): void {\n if (!value) {\n return;\n }\n this.#envImpl.set(key, value);\n this.#applyOnSet(this.#onSet, key, value);\n }\n del(key: string): void {\n this.#envImpl.del(key);\n this.#applyOnSet(this.#onSet, key);\n }\n}\n\nexport const envImpl = new EnvImpl();\n","import { BaseSysAbstraction, WrapperSysAbstraction, WrapperSysAbstractionParams } from \"../base_sys_abstraction\";\nimport { FileService, NamedWritableStream } from \"../file_service\";\nimport { SysAbstraction, SystemService, VoidFunc } from \"../sys_abstraction\";\nimport { envImpl } from \"../sys_env\";\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() {\n return envImpl;\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAe,OAAf,MAAoB;AAAA,EAGzB,UAAU,OAAuB;AAC/B,UAAM,MAAM,KAAK,IAAI;AACrB,WAAO,IAAI,QAAQ,IAAI,MAAM,QAAQ;AAAA,EACvC;AACF;;;ACHO,IAAM,UAAN,cAAsB,KAAK;AAAA,EAChC,MAAY;AACV,WAAO,oBAAI,KAAK;AAAA,EAClB;AAAA,EACA,MAAM,UAAiC;AACrC,WAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,iBAAW,MAAM;AACf,gBAAQ;AAAA,MACV,GAAG,QAAQ;AAAA,IACb,CAAC;AAAA,EACH;AACF;AAEO,IAAM,YAAN,cAAwB,KAAK;AAAA,EAClC,MAAY;AACV,WAAO,IAAI,KAAK,MAAM,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAAA,EACxC;AAAA;AAAA,EAEA,MAAM,UAAiC;AACrC,WAAO,QAAQ,QAAQ;AAAA,EACzB;AACF;AAEO,IAAM,WAAN,cAAuB,KAAK;AAAA,EAEjC,cAAc;AACZ,UAAM;AACN,SAAK,QAAQ,IAAI,UAAU,EAAE,IAAI;AAAA,EACnC;AAAA,EACA,MAAM;AACJ,QAAI,KAAK,MAAM,QAAQ,MAAM,GAAG;AAC9B,WAAK,QAAQ,IAAI,UAA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B,UAAM,IAAI,MAAM,kCAAkC;AAAA,EACpD;AAAA;AAAA,EAEA,WAAW,OAAuB;AAChC,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACtD;AAAA;AAAA,EAEA,WAAW,OAAwB;AACjC,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACtD;AACF;AAEA,IAAM,mBAAN,MAAgD;AAAA,EAC9C,MAAM;AACJ,WAAO;AAAA,EACT;AAAA,EACA,OAAiB;AACf,UAAM,IAAI,MAAM,8BAA8B;AAAA,EAChD;AAAA;AAAA,EAEA,OAAO,KAAyB;AAC9B,UAAM,IAAI,MAAM,gCAAgC;AAAA,EAClD;AAAA;AAAA,EAEA,KAAK,MAAoB;AACvB,UAAM,IAAI,MAAM,8BAA8B;AAAA,EAChD;AACF;AAEA,IAAI,KAAqC;AAClC,SAAS,kBAAkB,OAAqD;AACrF,MAAI,CAAC,IAAI;AACP,SAAK,IAAI,mBAAmB;AAAA,MAC1B,YAAY,IAAI,eAAe;AAAA,MAC/B,eAAe,IAAI,iBAAiB;AAAA,IACtC,CAAC;AAAA,EACH;AACA,SAAO,IAAI,sBAAsB,IAAI,KAAK;AAC5C;","names":["_env"]}
|
1
|
+
{"version":3,"sources":["../../../src/web/index.ts","../../../src/time.ts","../../../src/base_sys_abstraction.ts","../../../src/sys_env.ts","../../../src/web/web_sys_abstraction.ts"],"sourcesContent":["export * from \"./web_sys_abstraction\";\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","export interface EnvActions {\n get(key: string): string | undefined;\n set(key: string, value?: string): void;\n del(key: string): void;\n keys(): string[];\n use(): boolean;\n}\n\nclass NodeEnvActions implements EnvActions {\n readonly #node = globalThis as unknown as { process: { env: Record<string, string> } };\n\n // eslint-disable-next-line @typescript-eslint/no-useless-constructor, @typescript-eslint/no-unused-vars\n constructor(opts: Partial<EnvFactoryOpts>) {\n // do nothing\n }\n use(): boolean {\n return typeof this.#node === \"object\" && typeof this.#node.process === \"object\" && typeof this.#node.process.env === \"object\";\n }\n readonly #env = this.use() ? process.env : {};\n keys(): string[] {\n return Object.keys(this.#env);\n }\n get(key: string): string | undefined {\n return this.#env[key];\n }\n set(key: string, value?: string): void {\n if (value) {\n this.#env[key] = value;\n }\n }\n del(key: string): void {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this.#env[key];\n }\n}\n\nclass DenoEnvActions implements EnvActions {\n readonly #deno = globalThis as unknown as { Deno: { env: Map<string, string> } };\n\n readonly #env: Map<string, string>;\n constructor(opts: Partial<EnvFactoryOpts>, env?: Map<string, string>) {\n if (env) {\n this.#env = env;\n } else {\n this.#env = this.use() ? this.#deno.Deno.env : new Map();\n }\n }\n use(): boolean {\n return typeof this.#deno === \"object\" && typeof this.#deno.Deno === \"object\" && typeof this.#deno.Deno.env === \"object\";\n }\n keys(): string[] {\n return Array.from(this.#env.keys());\n }\n get(key: string): string | undefined {\n return this.#env.get(key);\n }\n set(key: string, value?: string): void {\n if (value) {\n this.#env.set(key, value);\n }\n }\n del(key: string): void {\n this.#env.delete(key);\n }\n}\n\nclass BrowserEnvActions extends DenoEnvActions {\n static globalBEA(sym: symbol) {\n const browser = globalThis as unknown as Record<symbol, BrowserEnvActions>;\n if (typeof browser === \"object\" && typeof browser[sym] === \"object\") {\n return { map: browser[sym]._map, finalize: () => browser[sym]._map };\n }\n const map = new Map<string, string>();\n return {\n map,\n finalize: (bea: BrowserEnvActions) => {\n browser[sym] = bea;\n return map;\n },\n };\n }\n\n readonly _map: Map<string, string>;\n constructor(opts: Partial<EnvFactoryOpts>) {\n const { map, finalize } = BrowserEnvActions.globalBEA(Symbol.for(opts.symbol || \"CP_ENV\"));\n // not perfect the globalThis will be polluted\n // also in the case it is not need.\n // better we have a lazy init\n super(opts, map);\n this._map = finalize(this);\n }\n use(): boolean {\n return true;\n }\n}\n\ninterface EnvFactoryOpts {\n readonly symbol: string; // default \"CP_ENV\" used by BrowserEnvActions\n readonly presetEnv: Map<string, string>;\n}\n\nfunction envFactory(opts: Partial<EnvFactoryOpts> = {}): EnvActions {\n const found = [new NodeEnvActions(opts), new DenoEnvActions(opts), new BrowserEnvActions(opts)].find((env) => env.use());\n if (!found) {\n throw new Error(\"SysContainer:envFactory: no env available\");\n }\n return found;\n}\n\ntype OnSetFn = (key: string, value?: string) => void;\nexport interface OnSetItem {\n readonly filter: Set<string>;\n readonly fn: OnSetFn;\n}\n\nexport interface Env extends Omit<EnvActions, \"use\"> {\n onSet(fn: OnSetFn, ...filter: string[]): void;\n}\n\nexport class EnvImpl implements Env {\n readonly #envImpl: EnvActions;\n constructor(opts: Partial<EnvFactoryOpts> = {}) {\n this.#envImpl = envFactory(opts);\n // do nothing\n this.#updatePresets(opts.presetEnv);\n }\n #updatePresets(presetEnv?: Map<string, string>): void {\n if (!presetEnv) {\n return;\n }\n for (const [key, value] of presetEnv) {\n this.#envImpl.set(key, value);\n }\n }\n #applyOnSet(onSet: OnSetItem[], key?: string, value?: string): void {\n onSet.forEach((item) => {\n let keys: string[] = [];\n if (key) {\n keys = [key];\n } else {\n keys = this.#envImpl.keys();\n }\n keys\n .filter((k) => {\n if (item.filter.size === 0) {\n return true;\n }\n if (item.filter.has(k)) {\n return true;\n }\n return false;\n })\n .forEach((k) => {\n let v;\n if (!key && !value) {\n // init\n v = this.#envImpl.get(k);\n } else if (key && !value) {\n // del\n v = undefined;\n } else {\n // set\n v = value;\n }\n item.fn(k, v);\n });\n });\n }\n readonly #onSet: OnSetItem[] = [];\n keys(): string[] {\n return this.#envImpl.keys();\n }\n // filter is not set all sets passed\n onSet(fn: OnSetFn, ...filter: string[]): void {\n const item: OnSetItem = { filter: new Set(filter), fn };\n this.#onSet.push(item);\n this.#applyOnSet([item]);\n }\n get(key: string): string | undefined {\n return this.#envImpl.get(key);\n }\n set(key: string, value?: string): void {\n if (!value) {\n return;\n }\n this.#envImpl.set(key, value);\n this.#applyOnSet(this.#onSet, key, value);\n }\n del(key: string): void {\n this.#envImpl.del(key);\n this.#applyOnSet(this.#onSet, key);\n }\n}\n\nexport const envImpl = new EnvImpl();\n","import { BaseSysAbstraction, WrapperSysAbstraction, WrapperSysAbstractionParams } from \"../base_sys_abstraction\";\nimport { FileService, NamedWritableStream } from \"../file_service\";\nimport { SysAbstraction, SystemService, VoidFunc } from \"../sys_abstraction\";\nimport { envImpl } from \"../sys_env\";\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() {\n return envImpl;\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA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AAAA,EAC9C,MAAM;AACJ,WAAO;AAAA,EACT;AAAA,EACA,OAAiB;AACf,UAAM,IAAI,MAAM,8BAA8B;AAAA,EAChD;AAAA;AAAA,EAEA,OAAO,KAAyB;AAC9B,UAAM,IAAI,MAAM,gCAAgC;AAAA,EAClD;AAAA;AAAA,EAEA,KAAK,MAAoB;AACvB,UAAM,IAAI,MAAM,8BAA8B;AAAA,EAChD;AACF;AAEA,IAAI,KAAqC;AAClC,SAAS,kBAAkB,OAAqD;AACrF,MAAI,CAAC,IAAI;AACP,SAAK,IAAI,mBAAmB;AAAA,MAC1B,YAAY,IAAI,eAAe;AAAA,MAC/B,eAAe,IAAI,iBAAiB;AAAA,IACtC,CAAC;AAAA,EACH;AACA,SAAO,IAAI,sBAAsB,IAAI,KAAK;AAC5C;","names":["_env"]}
|
package/web/index.js
CHANGED
package/chunk-RSXHMWBX.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/sys_abstraction.ts","../../src/time.ts","../../src/sys_env.ts","../../src/base_sys_abstraction.ts"],"sourcesContent":["import { FileService } from \"./file_service\";\nimport { Env } from \"./sys_env\";\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(): Env;\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","export interface EnvActions {\n get(key: string): string | undefined;\n set(key: string, value?: string): void;\n del(key: string): void;\n keys(): string[];\n use(): boolean;\n}\n\nclass NodeEnvActions implements EnvActions {\n readonly #node = globalThis as unknown as { process: { env: Record<string, string> } };\n\n // eslint-disable-next-line @typescript-eslint/no-useless-constructor, @typescript-eslint/no-unused-vars\n constructor(opts: Partial<EnvFactoryOpts>) {\n // do nothing\n }\n use(): boolean {\n return typeof this.#node === \"object\" && typeof this.#node.process === \"object\" && typeof this.#node.process.env === \"object\";\n }\n readonly #env = this.use() ? process.env : {};\n keys(): string[] {\n return Object.keys(this.#env);\n }\n get(key: string): string | undefined {\n return this.#env[key];\n }\n set(key: string, value?: string): void {\n if (value) {\n this.#env[key] = value;\n }\n }\n del(key: string): void {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this.#env[key];\n }\n}\n\nclass DenoEnvActions implements EnvActions {\n readonly #deno = globalThis as unknown as { Deno: { env: Map<string, string> } };\n\n readonly #env: Map<string, string>;\n constructor(opts: Partial<EnvFactoryOpts>, env?: Map<string, string>) {\n if (env) {\n this.#env = env;\n } else {\n this.#env = this.use() ? this.#deno.Deno.env : new Map();\n }\n }\n use(): boolean {\n return typeof this.#deno === \"object\" && typeof this.#deno.Deno === \"object\" && typeof this.#deno.Deno.env === \"object\";\n }\n keys(): string[] {\n return Array.from(this.#env.keys());\n }\n get(key: string): string | undefined {\n return this.#env.get(key);\n }\n set(key: string, value?: string): void {\n if (value) {\n this.#env.set(key, value);\n }\n }\n del(key: string): void {\n this.#env.delete(key);\n }\n}\n\nclass BrowserEnvActions extends DenoEnvActions {\n static getEnv(sym: symbol) {\n const browser = globalThis as unknown as Record<symbol, Map<string, string>>;\n if (typeof browser === \"object\" && typeof browser[sym] === \"object\") {\n return browser[sym];\n }\n browser[sym] = new Map();\n return browser[sym];\n }\n\n constructor(opts: Partial<EnvFactoryOpts>) {\n // not perfect the globalThis will be polluted\n // also in the case it is not need.\n // better we have a lazy init\n super(opts, BrowserEnvActions.getEnv(Symbol.for(opts.symbol || \"CP_ENV\")));\n }\n use(): boolean {\n return true;\n }\n}\n\ninterface EnvFactoryOpts {\n readonly symbol: string; // default \"CP_ENV\" used by BrowserEnvActions\n readonly presetEnv: Map<string, string>;\n}\n\nfunction envFactory(opts: Partial<EnvFactoryOpts> = {}): EnvActions {\n const found = [new NodeEnvActions(opts), new DenoEnvActions(opts), new BrowserEnvActions(opts)].find((env) => env.use());\n if (!found) {\n throw new Error(\"SysContainer:envFactory: no env available\");\n }\n return found;\n}\n\ntype OnSetFn = (key: string, value?: string) => void;\nexport interface OnSetItem {\n readonly filter: Set<string>;\n readonly fn: OnSetFn;\n}\n\nexport interface Env extends Omit<EnvActions, \"use\"> {\n onSet(fn: OnSetFn, ...filter: string[]): void;\n}\n\nexport class EnvImpl implements Env {\n readonly #envImpl: EnvActions;\n constructor(opts: Partial<EnvFactoryOpts> = {}) {\n this.#envImpl = envFactory(opts);\n // do nothing\n this.#updatePresets(opts.presetEnv);\n }\n #updatePresets(presetEnv?: Map<string, string>): void {\n if (!presetEnv) {\n return;\n }\n for (const [key, value] of presetEnv) {\n this.#envImpl.set(key, value);\n }\n }\n #applyOnSet(onSet: OnSetItem[], key?: string, value?: string): void {\n onSet.forEach((item) => {\n let keys: string[] = [];\n if (key) {\n keys = [key];\n } else {\n keys = this.#envImpl.keys();\n }\n keys\n .filter((k) => {\n if (item.filter.size === 0) {\n return true;\n }\n if (item.filter.has(k)) {\n return true;\n }\n return false;\n })\n .forEach((k) => {\n let v;\n if (!key && !value) {\n // init\n v = this.#envImpl.get(k);\n } else if (key && !value) {\n // del\n v = undefined;\n } else {\n // set\n v = value;\n }\n item.fn(k, v);\n });\n });\n }\n readonly #onSet: OnSetItem[] = [];\n keys(): string[] {\n return this.#envImpl.keys();\n }\n // filter is not set all sets passed\n onSet(fn: OnSetFn, ...filter: string[]): void {\n const item: OnSetItem = { filter: new Set(filter), fn };\n this.#onSet.push(item);\n this.#applyOnSet([item]);\n }\n get(key: string): string | undefined {\n return this.#envImpl.get(key);\n }\n set(key: string, value?: string): void {\n if (!value) {\n return;\n }\n this.#envImpl.set(key, value);\n this.#applyOnSet(this.#onSet, key, value);\n }\n del(key: string): void {\n this.#envImpl.del(key);\n this.#applyOnSet(this.#onSet, key);\n }\n}\n\nexport const envImpl = new EnvImpl();\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"],"mappings":";;;;;;;;AAIO,IAAK,WAAL,kBAAKA,cAAL;AACL,EAAAA,UAAA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