@adviser/cement 0.0.0-jsr-t1
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +201 -0
- package/README.md +39 -0
- package/base-sys-abstraction-BkEiLHl0.d.ts +193 -0
- package/base-sys-abstraction-Qj7pkY1N.d.cts +193 -0
- package/chunk-7KFVMTOS.js +311 -0
- package/chunk-7KFVMTOS.js.map +1 -0
- package/chunk-GES3MUGV.js +92 -0
- package/chunk-GES3MUGV.js.map +1 -0
- package/chunk-Q65HLCNL.js +601 -0
- package/chunk-Q65HLCNL.js.map +1 -0
- package/chunk-WMMUXBDX.js +87 -0
- package/chunk-WMMUXBDX.js.map +1 -0
- package/index-Q3phXzYr.d.cts +75 -0
- package/index-tIGZMHTc.d.ts +75 -0
- package/index.cjs +2593 -0
- package/index.cjs.map +1 -0
- package/index.d.cts +532 -0
- package/index.d.ts +532 -0
- package/index.js +1533 -0
- package/index.js.map +1 -0
- package/node/index.cjs +924 -0
- package/node/index.cjs.map +1 -0
- package/node/index.d.cts +65 -0
- package/node/index.d.ts +65 -0
- package/node/index.js +398 -0
- package/node/index.js.map +1 -0
- package/package.json +81 -0
- package/src/base-sys-abstraction.test.ts +95 -0
- package/src/base-sys-abstraction.ts +242 -0
- package/src/bin2text.test.ts +59 -0
- package/src/bin2text.ts +47 -0
- package/src/crypto.test.ts +15 -0
- package/src/crypto.ts +125 -0
- package/src/file-service.ts +24 -0
- package/src/future.test.ts +32 -0
- package/src/future.ts +27 -0
- package/src/index.ts +22 -0
- package/src/jsr.json +20 -0
- package/src/log-level-impl.ts +87 -0
- package/src/log-writer-impl.ts +58 -0
- package/src/logger-impl.ts +498 -0
- package/src/logger.test.ts +1132 -0
- package/src/logger.ts +208 -0
- package/src/node/deno-file-service.ts +92 -0
- package/src/node/deno-sys-abstraction.ts +133 -0
- package/src/node/index.ts +4 -0
- package/src/node/mock-file-service.ts +45 -0
- package/src/node/node-file-service.ts +91 -0
- package/src/node/node-sys-abstraction.ts +121 -0
- package/src/option.ts +60 -0
- package/src/resolve-once.test.ts +321 -0
- package/src/resolve-once.ts +179 -0
- package/src/result.test.ts +102 -0
- package/src/result.ts +165 -0
- package/src/runtime.ts +36 -0
- package/src/sys-abstraction.ts +53 -0
- package/src/sys-env.test.ts +53 -0
- package/src/sys-env.ts +216 -0
- package/src/test/log-write-stream.ts +95 -0
- package/src/test/mock-logger.ts +40 -0
- package/src/time.ts +20 -0
- package/src/tracer.test.ts +314 -0
- package/src/tracer.ts +222 -0
- package/src/txt-en-decoder.ts +21 -0
- package/src/uri.test.ts +155 -0
- package/src/uri.ts +421 -0
- package/src/utils/console-write-stream.ts +72 -0
- package/src/utils/fanout-write-stream.ts +32 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/rebuffer.ts +75 -0
- package/src/utils/stream-map.ts +67 -0
- package/src/utils/stream2string.ts +47 -0
- package/src/utils/string2stream.ts +14 -0
- package/src/version.ts +3 -0
- package/src/web/index.ts +1 -0
- package/src/web/web-sys-abstraction.ts +80 -0
- package/ts/LICENSE +201 -0
- package/ts/README.md +39 -0
- package/ts/base-sys-abstraction.d.ts +84 -0
- package/ts/base-sys-abstraction.d.ts.map +1 -0
- package/ts/base-sys-abstraction.js +178 -0
- package/ts/base-sys-abstraction.js.map +1 -0
- package/ts/base-sys-abstraction.test.d.ts +2 -0
- package/ts/base-sys-abstraction.test.d.ts.map +1 -0
- package/ts/base-sys-abstraction.test.js +82 -0
- package/ts/base-sys-abstraction.test.js.map +1 -0
- package/ts/bin2text.d.ts +3 -0
- package/ts/bin2text.d.ts.map +1 -0
- package/ts/bin2text.js +43 -0
- package/ts/bin2text.js.map +1 -0
- package/ts/bin2text.test.d.ts +2 -0
- package/ts/bin2text.test.d.ts.map +1 -0
- package/ts/bin2text.test.js +51 -0
- package/ts/bin2text.test.js.map +1 -0
- package/ts/crypto.d.ts +76 -0
- package/ts/crypto.d.ts.map +1 -0
- package/ts/crypto.js +22 -0
- package/ts/crypto.js.map +1 -0
- package/ts/crypto.test.d.ts +2 -0
- package/ts/crypto.test.d.ts.map +1 -0
- package/ts/crypto.test.js +14 -0
- package/ts/crypto.test.js.map +1 -0
- package/ts/file-service.d.ts +17 -0
- package/ts/file-service.d.ts.map +1 -0
- package/ts/file-service.js +2 -0
- package/ts/file-service.js.map +1 -0
- package/ts/future.d.ts +8 -0
- package/ts/future.d.ts.map +1 -0
- package/ts/future.js +38 -0
- package/ts/future.js.map +1 -0
- package/ts/future.test.d.ts +2 -0
- package/ts/future.test.d.ts.map +1 -0
- package/ts/future.test.js +28 -0
- package/ts/future.test.js.map +1 -0
- package/ts/index.d.ts +23 -0
- package/ts/index.d.ts.map +1 -0
- package/ts/index.js +23 -0
- package/ts/index.js.map +1 -0
- package/ts/log-level-impl.d.ts +14 -0
- package/ts/log-level-impl.d.ts.map +1 -0
- package/ts/log-level-impl.js +72 -0
- package/ts/log-level-impl.js.map +1 -0
- package/ts/log-writer-impl.d.ts +10 -0
- package/ts/log-writer-impl.d.ts.map +1 -0
- package/ts/log-writer-impl.js +45 -0
- package/ts/log-writer-impl.js.map +1 -0
- package/ts/logger-impl.d.ts +71 -0
- package/ts/logger-impl.d.ts.map +1 -0
- package/ts/logger-impl.js +412 -0
- package/ts/logger-impl.js.map +1 -0
- package/ts/logger.d.ts +84 -0
- package/ts/logger.d.ts.map +1 -0
- package/ts/logger.js +114 -0
- package/ts/logger.js.map +1 -0
- package/ts/logger.test.d.ts +2 -0
- package/ts/logger.test.d.ts.map +1 -0
- package/ts/logger.test.js +1023 -0
- package/ts/logger.test.js.map +1 -0
- package/ts/node/deno-file-service.d.ts +17 -0
- package/ts/node/deno-file-service.d.ts.map +1 -0
- package/ts/node/deno-file-service.js +65 -0
- package/ts/node/deno-file-service.js.map +1 -0
- package/ts/node/deno-sys-abstraction.d.ts +22 -0
- package/ts/node/deno-sys-abstraction.d.ts.map +1 -0
- package/ts/node/deno-sys-abstraction.js +101 -0
- package/ts/node/deno-sys-abstraction.js.map +1 -0
- package/ts/node/index.d.ts +5 -0
- package/ts/node/index.d.ts.map +1 -0
- package/ts/node/index.js +5 -0
- package/ts/node/index.js.map +1 -0
- package/ts/node/mock-file-service.d.ts +11 -0
- package/ts/node/mock-file-service.d.ts.map +1 -0
- package/ts/node/mock-file-service.js +34 -0
- package/ts/node/mock-file-service.js.map +1 -0
- package/ts/node/mock-file-service.test.d.ts +2 -0
- package/ts/node/mock-file-service.test.d.ts.map +1 -0
- package/ts/node/mock-file-service.test.js +31 -0
- package/ts/node/mock-file-service.test.js.map +1 -0
- package/ts/node/node-file-service.d.ts +16 -0
- package/ts/node/node-file-service.d.ts.map +1 -0
- package/ts/node/node-file-service.js +71 -0
- package/ts/node/node-file-service.js.map +1 -0
- package/ts/node/node-sys-abstraction.d.ts +22 -0
- package/ts/node/node-sys-abstraction.d.ts.map +1 -0
- package/ts/node/node-sys-abstraction.js +99 -0
- package/ts/node/node-sys-abstraction.js.map +1 -0
- package/ts/node/node-sys-abstraction.test.d.ts +2 -0
- package/ts/node/node-sys-abstraction.test.d.ts.map +1 -0
- package/ts/node/node-sys-abstraction.test.js +87 -0
- package/ts/node/node-sys-abstraction.test.js.map +1 -0
- package/ts/option.d.ts +25 -0
- package/ts/option.d.ts.map +1 -0
- package/ts/option.js +47 -0
- package/ts/option.js.map +1 -0
- package/ts/resolve-once.d.ts +46 -0
- package/ts/resolve-once.d.ts.map +1 -0
- package/ts/resolve-once.js +152 -0
- package/ts/resolve-once.js.map +1 -0
- package/ts/resolve-once.test.d.ts +2 -0
- package/ts/resolve-once.test.d.ts.map +1 -0
- package/ts/resolve-once.test.js +283 -0
- package/ts/resolve-once.test.js.map +1 -0
- package/ts/result.d.ts +34 -0
- package/ts/result.d.ts.map +1 -0
- package/ts/result.js +85 -0
- package/ts/result.js.map +1 -0
- package/ts/result.test.d.ts +2 -0
- package/ts/result.test.d.ts.map +1 -0
- package/ts/result.test.js +79 -0
- package/ts/result.test.js.map +1 -0
- package/ts/runtime.d.ts +8 -0
- package/ts/runtime.d.ts.map +1 -0
- package/ts/runtime.js +26 -0
- package/ts/runtime.js.map +1 -0
- package/ts/sys-abstraction.d.ts +36 -0
- package/ts/sys-abstraction.d.ts.map +1 -0
- package/ts/sys-abstraction.js +31 -0
- package/ts/sys-abstraction.js.map +1 -0
- package/ts/sys-env.d.ts +48 -0
- package/ts/sys-env.d.ts.map +1 -0
- package/ts/sys-env.js +176 -0
- package/ts/sys-env.js.map +1 -0
- package/ts/sys-env.test.d.ts +2 -0
- package/ts/sys-env.test.d.ts.map +1 -0
- package/ts/sys-env.test.js +51 -0
- package/ts/sys-env.test.js.map +1 -0
- package/ts/test/log-write-stream.d.ts +27 -0
- package/ts/test/log-write-stream.d.ts.map +1 -0
- package/ts/test/log-write-stream.js +74 -0
- package/ts/test/log-write-stream.js.map +1 -0
- package/ts/test/mock-logger.d.ts +14 -0
- package/ts/test/mock-logger.d.ts.map +1 -0
- package/ts/test/mock-logger.js +29 -0
- package/ts/test/mock-logger.js.map +1 -0
- package/ts/test/mock-logger.test.d.ts +2 -0
- package/ts/test/mock-logger.test.d.ts.map +1 -0
- package/ts/test/mock-logger.test.js +63 -0
- package/ts/test/mock-logger.test.js.map +1 -0
- package/ts/test/test-exit-handler.d.ts +2 -0
- package/ts/test/test-exit-handler.d.ts.map +1 -0
- package/ts/test/test-exit-handler.js +57 -0
- package/ts/test/test-exit-handler.js.map +1 -0
- package/ts/time.d.ts +13 -0
- package/ts/time.d.ts.map +1 -0
- package/ts/time.js +14 -0
- package/ts/time.js.map +1 -0
- package/ts/tracer.d.ts +59 -0
- package/ts/tracer.d.ts.map +1 -0
- package/ts/tracer.js +148 -0
- package/ts/tracer.js.map +1 -0
- package/ts/tracer.test.d.ts +2 -0
- package/ts/tracer.test.d.ts.map +1 -0
- package/ts/tracer.test.js +311 -0
- package/ts/tracer.test.js.map +1 -0
- package/ts/txt-en-decoder.d.ts +10 -0
- package/ts/txt-en-decoder.d.ts.map +1 -0
- package/ts/txt-en-decoder.js +15 -0
- package/ts/txt-en-decoder.js.map +1 -0
- package/ts/uri.d.ts +67 -0
- package/ts/uri.d.ts.map +1 -0
- package/ts/uri.js +283 -0
- package/ts/uri.js.map +1 -0
- package/ts/uri.test.d.ts +2 -0
- package/ts/uri.test.d.ts.map +1 -0
- package/ts/uri.test.js +119 -0
- package/ts/uri.test.js.map +1 -0
- package/ts/utils/console-write-stream.d.ts +21 -0
- package/ts/utils/console-write-stream.d.ts.map +1 -0
- package/ts/utils/console-write-stream.js +62 -0
- package/ts/utils/console-write-stream.js.map +1 -0
- package/ts/utils/fanout-write-stream.d.ts +12 -0
- package/ts/utils/fanout-write-stream.d.ts.map +1 -0
- package/ts/utils/fanout-write-stream.js +24 -0
- package/ts/utils/fanout-write-stream.js.map +1 -0
- package/ts/utils/index.d.ts +7 -0
- package/ts/utils/index.d.ts.map +1 -0
- package/ts/utils/index.js +7 -0
- package/ts/utils/index.js.map +1 -0
- package/ts/utils/rebuffer.d.ts +3 -0
- package/ts/utils/rebuffer.d.ts.map +1 -0
- package/ts/utils/rebuffer.js +60 -0
- package/ts/utils/rebuffer.js.map +1 -0
- package/ts/utils/rebuffer.test.d.ts +2 -0
- package/ts/utils/rebuffer.test.d.ts.map +1 -0
- package/ts/utils/rebuffer.test.js +77 -0
- package/ts/utils/rebuffer.test.js.map +1 -0
- package/ts/utils/stream-map.d.ts +9 -0
- package/ts/utils/stream-map.d.ts.map +1 -0
- package/ts/utils/stream-map.js +62 -0
- package/ts/utils/stream-map.js.map +1 -0
- package/ts/utils/stream-map.test.d.ts +2 -0
- package/ts/utils/stream-map.test.d.ts.map +1 -0
- package/ts/utils/stream-map.test.js +87 -0
- package/ts/utils/stream-map.test.js.map +1 -0
- package/ts/utils/stream-test-helper.d.ts +17 -0
- package/ts/utils/stream-test-helper.d.ts.map +1 -0
- package/ts/utils/stream-test-helper.js +37 -0
- package/ts/utils/stream-test-helper.js.map +1 -0
- package/ts/utils/stream2string.d.ts +3 -0
- package/ts/utils/stream2string.d.ts.map +1 -0
- package/ts/utils/stream2string.js +48 -0
- package/ts/utils/stream2string.js.map +1 -0
- package/ts/utils/stream2string.test.d.ts +2 -0
- package/ts/utils/stream2string.test.d.ts.map +1 -0
- package/ts/utils/stream2string.test.js +29 -0
- package/ts/utils/stream2string.test.js.map +1 -0
- package/ts/utils/string2stream.d.ts +4 -0
- package/ts/utils/string2stream.d.ts.map +1 -0
- package/ts/utils/string2stream.js +13 -0
- package/ts/utils/string2stream.js.map +1 -0
- package/ts/utils/string2stream.test.d.ts +2 -0
- package/ts/utils/string2stream.test.d.ts.map +1 -0
- package/ts/utils/string2stream.test.js +6 -0
- package/ts/utils/string2stream.test.js.map +1 -0
- package/ts/version.d.ts +2 -0
- package/ts/version.d.ts.map +1 -0
- package/ts/version.js +4 -0
- package/ts/version.js.map +1 -0
- package/ts/web/index.d.ts +2 -0
- package/ts/web/index.d.ts.map +1 -0
- package/ts/web/index.js +2 -0
- package/ts/web/index.js.map +1 -0
- package/ts/web/web-sys-abstraction.d.ts +4 -0
- package/ts/web/web-sys-abstraction.d.ts.map +1 -0
- package/ts/web/web-sys-abstraction.js +64 -0
- package/ts/web/web-sys-abstraction.js.map +1 -0
- package/txt-en-decoder-CZYJUju2.d.cts +11 -0
- package/txt-en-decoder-CZYJUju2.d.ts +11 -0
- package/utils/index.cjs +341 -0
- package/utils/index.cjs.map +1 -0
- package/utils/index.d.cts +2 -0
- package/utils/index.d.ts +2 -0
- package/utils/index.js +32 -0
- package/utils/index.js.map +1 -0
- package/web/index.cjs +593 -0
- package/web/index.cjs.map +1 -0
- package/web/index.d.cts +6 -0
- package/web/index.d.ts +6 -0
- package/web/index.js +9 -0
- package/web/index.js.map +1 -0
package/ts/sys-env.d.ts
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
export interface EnvMap {
|
2
|
+
get(key: string): string | undefined;
|
3
|
+
set(key: string, value?: string): void;
|
4
|
+
delete(key: string): void;
|
5
|
+
keys(): string[];
|
6
|
+
}
|
7
|
+
export interface EnvActions extends EnvMap {
|
8
|
+
active(): boolean;
|
9
|
+
register(env: Env): Env;
|
10
|
+
}
|
11
|
+
export declare class BrowserEnvActions implements EnvActions {
|
12
|
+
readonly env: Map<string, string>;
|
13
|
+
readonly opts: Partial<EnvFactoryOpts>;
|
14
|
+
constructor(opts: Partial<EnvFactoryOpts>);
|
15
|
+
get(key: string): string | undefined;
|
16
|
+
set(key: string, value?: string): void;
|
17
|
+
delete(key: string): void;
|
18
|
+
keys(): string[];
|
19
|
+
active(): boolean;
|
20
|
+
register(env: Env): Env;
|
21
|
+
}
|
22
|
+
export interface EnvFactoryOpts {
|
23
|
+
readonly symbol: string;
|
24
|
+
readonly presetEnv: Map<string, string>;
|
25
|
+
}
|
26
|
+
type OnSetFn = (key: string, value?: string) => void;
|
27
|
+
export interface OnSetItem {
|
28
|
+
readonly filter: Set<string>;
|
29
|
+
readonly fn: OnSetFn;
|
30
|
+
}
|
31
|
+
export interface Env extends EnvMap {
|
32
|
+
onSet(fn: OnSetFn, ...filter: string[]): void;
|
33
|
+
}
|
34
|
+
export declare function envFactory(opts?: Partial<EnvFactoryOpts>): Env;
|
35
|
+
export declare class EnvImpl implements Env {
|
36
|
+
readonly _map: EnvMap;
|
37
|
+
constructor(map: EnvMap, opts?: Partial<EnvFactoryOpts>);
|
38
|
+
_updatePresets(presetEnv?: Map<string, string>): void;
|
39
|
+
_applyOnSet(onSet: OnSetItem[], key?: string, value?: string): void;
|
40
|
+
readonly _onSet: OnSetItem[];
|
41
|
+
keys(): string[];
|
42
|
+
onSet(fn: OnSetFn, ...filter: string[]): void;
|
43
|
+
get(key: string): string | undefined;
|
44
|
+
set(key: string, value?: string): void;
|
45
|
+
delete(key: string): void;
|
46
|
+
}
|
47
|
+
export {};
|
48
|
+
//# sourceMappingURL=sys-env.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"sys-env.d.ts","sourceRoot":"","sources":["../../src/sys-env.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,MAAM;IACrB,GAAG,CAAC,GAAG,EAAE,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AAC;CACtB;AAED,MAAM,WAAW,GAAI,SAAQ,MAAM;IACjC,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;CAC/C;AAGD,wBAAgB,UAAU,CAAC,IAAI,GAAE,OAAO,CAAC,cAAc,CAAM,GAAG,GAAG,CAUlE;AAED,qBAAa,OAAQ,YAAW,GAAG;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBACV,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,OAAO,CAAC,cAAc,CAAM;IAI3D,cAAc,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;IAQrD,WAAW,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI;IAkCnE,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,CAAM;IAClC,IAAI,IAAI,MAAM,EAAE;IAIhB,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI;IAK7C,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAGpC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI;IAOtC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;CAI1B"}
|
package/ts/sys-env.js
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
5
|
+
};
|
6
|
+
var _NodeEnvActions_node, _DenoEnvActions_deno;
|
7
|
+
import { ResolveOnce } from "./resolve-once.js";
|
8
|
+
class NodeEnvActions {
|
9
|
+
constructor(opts) {
|
10
|
+
_NodeEnvActions_node.set(this, globalThis);
|
11
|
+
this._env = this.active() ? __classPrivateFieldGet(this, _NodeEnvActions_node, "f").process.env : {};
|
12
|
+
}
|
13
|
+
register(env) {
|
14
|
+
return env;
|
15
|
+
}
|
16
|
+
active() {
|
17
|
+
return typeof __classPrivateFieldGet(this, _NodeEnvActions_node, "f") === "object" && typeof __classPrivateFieldGet(this, _NodeEnvActions_node, "f").process === "object" && typeof __classPrivateFieldGet(this, _NodeEnvActions_node, "f").process.env === "object";
|
18
|
+
}
|
19
|
+
keys() {
|
20
|
+
return Object.keys(this._env);
|
21
|
+
}
|
22
|
+
get(key) {
|
23
|
+
return this._env[key];
|
24
|
+
}
|
25
|
+
set(key, value) {
|
26
|
+
if (value) {
|
27
|
+
this._env[key] = value;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
delete(key) {
|
31
|
+
delete this._env[key];
|
32
|
+
}
|
33
|
+
}
|
34
|
+
_NodeEnvActions_node = new WeakMap();
|
35
|
+
class DenoEnvActions {
|
36
|
+
get _env() {
|
37
|
+
return __classPrivateFieldGet(this, _DenoEnvActions_deno, "f").Deno.env;
|
38
|
+
}
|
39
|
+
constructor(opts) {
|
40
|
+
_DenoEnvActions_deno.set(this, globalThis);
|
41
|
+
}
|
42
|
+
register(env) {
|
43
|
+
return env;
|
44
|
+
}
|
45
|
+
active() {
|
46
|
+
return typeof __classPrivateFieldGet(this, _DenoEnvActions_deno, "f") === "object" && typeof __classPrivateFieldGet(this, _DenoEnvActions_deno, "f").Deno === "object" && typeof __classPrivateFieldGet(this, _DenoEnvActions_deno, "f").Deno.env === "object";
|
47
|
+
}
|
48
|
+
keys() {
|
49
|
+
return Array.from(this._env.keys());
|
50
|
+
}
|
51
|
+
get(key) {
|
52
|
+
return this._env.get(key);
|
53
|
+
}
|
54
|
+
set(key, value) {
|
55
|
+
if (value) {
|
56
|
+
this._env.set(key, value);
|
57
|
+
}
|
58
|
+
}
|
59
|
+
delete(key) {
|
60
|
+
this._env.delete(key);
|
61
|
+
}
|
62
|
+
}
|
63
|
+
_DenoEnvActions_deno = new WeakMap();
|
64
|
+
export class BrowserEnvActions {
|
65
|
+
constructor(opts) {
|
66
|
+
this.env = new Map();
|
67
|
+
this.opts = opts;
|
68
|
+
}
|
69
|
+
get(key) {
|
70
|
+
return this.env.get(key);
|
71
|
+
}
|
72
|
+
set(key, value) {
|
73
|
+
if (value) {
|
74
|
+
this.env.set(key, value);
|
75
|
+
}
|
76
|
+
}
|
77
|
+
delete(key) {
|
78
|
+
this.env.delete(key);
|
79
|
+
}
|
80
|
+
keys() {
|
81
|
+
return Array.from(this.env.keys());
|
82
|
+
}
|
83
|
+
active() {
|
84
|
+
return true;
|
85
|
+
}
|
86
|
+
register(env) {
|
87
|
+
const sym = Symbol.for(this.opts.symbol || "CP_ENV");
|
88
|
+
const browser = globalThis;
|
89
|
+
browser[sym] = env;
|
90
|
+
return env;
|
91
|
+
}
|
92
|
+
}
|
93
|
+
const _envFactory = new ResolveOnce();
|
94
|
+
export function envFactory(opts = {}) {
|
95
|
+
return _envFactory.once(() => {
|
96
|
+
const found = [new NodeEnvActions(opts), new DenoEnvActions(opts), new BrowserEnvActions(opts)].find((env) => env.active());
|
97
|
+
if (!found) {
|
98
|
+
throw new Error("SysContainer:envFactory: no env available");
|
99
|
+
}
|
100
|
+
const ret = new EnvImpl(found, opts);
|
101
|
+
found.register(ret);
|
102
|
+
return ret;
|
103
|
+
});
|
104
|
+
}
|
105
|
+
export class EnvImpl {
|
106
|
+
constructor(map, opts = {}) {
|
107
|
+
this._onSet = [];
|
108
|
+
this._map = map;
|
109
|
+
this._updatePresets(opts.presetEnv);
|
110
|
+
}
|
111
|
+
_updatePresets(presetEnv) {
|
112
|
+
if (!presetEnv) {
|
113
|
+
return;
|
114
|
+
}
|
115
|
+
for (const [key, value] of presetEnv) {
|
116
|
+
this._map.set(key, value);
|
117
|
+
}
|
118
|
+
}
|
119
|
+
_applyOnSet(onSet, key, value) {
|
120
|
+
onSet.forEach((item) => {
|
121
|
+
let keys = [];
|
122
|
+
if (key) {
|
123
|
+
keys = [key];
|
124
|
+
}
|
125
|
+
else {
|
126
|
+
keys = this._map.keys();
|
127
|
+
}
|
128
|
+
keys
|
129
|
+
.filter((k) => {
|
130
|
+
if (item.filter.size === 0) {
|
131
|
+
return true;
|
132
|
+
}
|
133
|
+
if (item.filter.has(k)) {
|
134
|
+
return true;
|
135
|
+
}
|
136
|
+
return false;
|
137
|
+
})
|
138
|
+
.forEach((k) => {
|
139
|
+
let v;
|
140
|
+
if (!key && !value) {
|
141
|
+
v = this._map.get(k);
|
142
|
+
}
|
143
|
+
else if (key && !value) {
|
144
|
+
v = undefined;
|
145
|
+
}
|
146
|
+
else {
|
147
|
+
v = value;
|
148
|
+
}
|
149
|
+
item.fn(k, v);
|
150
|
+
});
|
151
|
+
});
|
152
|
+
}
|
153
|
+
keys() {
|
154
|
+
return this._map.keys();
|
155
|
+
}
|
156
|
+
onSet(fn, ...filter) {
|
157
|
+
const item = { filter: new Set(filter), fn };
|
158
|
+
this._onSet.push(item);
|
159
|
+
this._applyOnSet([item]);
|
160
|
+
}
|
161
|
+
get(key) {
|
162
|
+
return this._map.get(key);
|
163
|
+
}
|
164
|
+
set(key, value) {
|
165
|
+
if (!value) {
|
166
|
+
return;
|
167
|
+
}
|
168
|
+
this._map.set(key, value);
|
169
|
+
this._applyOnSet(this._onSet, key, value);
|
170
|
+
}
|
171
|
+
delete(key) {
|
172
|
+
this._map.delete(key);
|
173
|
+
this._applyOnSet(this._onSet, key);
|
174
|
+
}
|
175
|
+
}
|
176
|
+
//# sourceMappingURL=sys-env.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"sys-env.js","sourceRoot":"","sources":["../../src/sys-env.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C,CAAC,CAAC;YAChB,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACL,CAAC;IAED,IAAI;QACF,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,EAAW,EAAE,GAAG,MAAgB;QACpC,MAAM,IAAI,GAAc,EAAE,MAAM,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC;QACxD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvB,IAAI,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3B,CAAC;IACD,GAAG,CAAC,GAAW;QACb,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IACD,GAAG,CAAC,GAAW,EAAE,KAAc;QAC7B,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO;QACT,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC1B,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IAC5C,CAAC;IACD,MAAM,CAAC,GAAW;QAChB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACtB,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACrC,CAAC;CACF"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"sys-env.test.d.ts","sourceRoot":"","sources":["../../src/sys-env.test.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import { BrowserEnvActions, EnvImpl, envFactory } from "@adviser/cement";
|
2
|
+
describe("sys_env", () => {
|
3
|
+
let key;
|
4
|
+
const envImpl = envFactory();
|
5
|
+
beforeEach(() => {
|
6
|
+
key = `key-${Math.random()}`;
|
7
|
+
});
|
8
|
+
it("actions", () => {
|
9
|
+
expect(envImpl.get(key)).toBeUndefined();
|
10
|
+
envImpl.set(key, "value");
|
11
|
+
expect(envImpl.get(key)).toBe("value");
|
12
|
+
envImpl.set(key);
|
13
|
+
expect(envImpl.get(key)).toBe("value");
|
14
|
+
envImpl.delete(key);
|
15
|
+
expect(envImpl.get(key)).toBeUndefined();
|
16
|
+
});
|
17
|
+
it("preset", () => {
|
18
|
+
const env = new EnvImpl(new BrowserEnvActions({}), {
|
19
|
+
presetEnv: new Map([[key, "value"]]),
|
20
|
+
});
|
21
|
+
expect(env.get(key)).toBe("value");
|
22
|
+
env.delete(key);
|
23
|
+
expect(env.get(key)).toBeUndefined();
|
24
|
+
});
|
25
|
+
it("onSet wild card", () => {
|
26
|
+
const fn = vi.fn();
|
27
|
+
envImpl.onSet(fn);
|
28
|
+
expect(fn).toBeCalledTimes(envImpl.keys().length);
|
29
|
+
expect(fn.mock.calls.map((i) => i[0]).sort()).toEqual(envImpl.keys().sort());
|
30
|
+
expect(fn.mock.calls.map((i) => i[1]).sort()).toEqual(envImpl
|
31
|
+
.keys()
|
32
|
+
.map((i) => envImpl.get(i))
|
33
|
+
.sort());
|
34
|
+
});
|
35
|
+
it("onSet filter", () => {
|
36
|
+
const env = new EnvImpl(new BrowserEnvActions({}), {
|
37
|
+
presetEnv: new Map([[key, "value"]]),
|
38
|
+
});
|
39
|
+
const fn = vi.fn();
|
40
|
+
env.onSet(fn, key);
|
41
|
+
expect(fn).toBeCalledTimes(1);
|
42
|
+
expect(fn.mock.calls[0]).toEqual([key, "value"]);
|
43
|
+
env.set(key, "value2");
|
44
|
+
expect(fn).toBeCalledTimes(2);
|
45
|
+
expect(fn.mock.calls[1]).toEqual([key, "value2"]);
|
46
|
+
env.delete(key);
|
47
|
+
expect(fn).toBeCalledTimes(3);
|
48
|
+
expect(fn.mock.calls[2]).toEqual([key, undefined]);
|
49
|
+
});
|
50
|
+
});
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C,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;SACrC,CAAC,CAAC;QACH,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QACnB,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;QACnB,MAAM,CAAC,EAAE,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QAC9B,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;QACjD,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QACvB,MAAM,CAAC,EAAE,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QAC9B,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;QAClD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAChB,MAAM,CAAC,EAAE,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QAC9B,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { Future } from "../future.js";
|
2
|
+
import { TxtEnDecoder } from "../txt-en-decoder.js";
|
3
|
+
export declare class LogWriteStream implements WritableStreamDefaultWriter<Uint8Array> {
|
4
|
+
private readonly _bufferArr;
|
5
|
+
constructor(bufferArr: Uint8Array[]);
|
6
|
+
readonly _resolveClosed: Future<undefined>;
|
7
|
+
readonly closed: Promise<undefined>;
|
8
|
+
readonly desiredSize: number | null;
|
9
|
+
readonly ready: Promise<undefined>;
|
10
|
+
abort(reason?: any): Promise<void>;
|
11
|
+
close(): Promise<void>;
|
12
|
+
releaseLock(): void;
|
13
|
+
write(chunk?: Uint8Array): Promise<void>;
|
14
|
+
}
|
15
|
+
export declare class LogCollector implements WritableStream<Uint8Array> {
|
16
|
+
readonly locked: boolean;
|
17
|
+
private _writer?;
|
18
|
+
private readonly _pass?;
|
19
|
+
private readonly _bufferArr;
|
20
|
+
private readonly _txtEnDe;
|
21
|
+
constructor(pass?: WritableStreamDefaultWriter<Uint8Array>, txtEnDe?: TxtEnDecoder);
|
22
|
+
abort(reason?: Uint8Array): Promise<void>;
|
23
|
+
close(): Promise<void>;
|
24
|
+
getWriter(): WritableStreamDefaultWriter<Uint8Array>;
|
25
|
+
Logs(notJsonLine?: boolean): any[];
|
26
|
+
}
|
27
|
+
//# sourceMappingURL=log-write-stream.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"log-write-stream.d.ts","sourceRoot":"","sources":["../../../src/test/log-write-stream.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,YAAY,EAA0B,MAAM,sBAAsB,CAAC;AAE5E,qBAAa,cAAe,YAAW,2BAA2B,CAAC,UAAU,CAAC;IAC5E,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAe;gBAE9B,SAAS,EAAE,UAAU,EAAE;IAInC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC,SAAS,CAAC,CAA2B;IACrE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,SAAS,CAAC,CAAmC;IACtE,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC3C,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAA8B;IAGhE,KAAK,CAAC,MAAM,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAG5B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,WAAW,IAAI,IAAI;IAGb,KAAK,CAAC,KAAK,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CAM/C;AAED,qBAAa,YAAa,YAAW,cAAc,CAAC,UAAU,CAAC;IAC7D,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAS;IACjC,OAAO,CAAC,OAAO,CAAC,CAAoB;IACpC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAA0C;IACjE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;IAC/C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;gBAE5B,IAAI,CAAC,EAAE,2BAA2B,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC,EAAE,YAAY;IAMlF,KAAK,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAInC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAS5B,SAAS,IAAI,2BAA2B,CAAC,UAAU,CAAC;IAYpD,IAAI,CAAC,WAAW,UAAQ,GAAG,GAAG,EAAE;CAqBjC"}
|
@@ -0,0 +1,74 @@
|
|
1
|
+
import { FanoutWriteStream } from "../utils/fanout-write-stream.js";
|
2
|
+
import { Future } from "../future.js";
|
3
|
+
import { Utf8EnDecoderSingleton } from "../txt-en-decoder.js";
|
4
|
+
export class LogWriteStream {
|
5
|
+
constructor(bufferArr) {
|
6
|
+
this._resolveClosed = new Future();
|
7
|
+
this.closed = this._resolveClosed.asPromise();
|
8
|
+
this.desiredSize = null;
|
9
|
+
this.ready = Promise.resolve(undefined);
|
10
|
+
this._bufferArr = bufferArr;
|
11
|
+
}
|
12
|
+
abort(reason) {
|
13
|
+
throw new Error("Method not implemented.");
|
14
|
+
}
|
15
|
+
async close() {
|
16
|
+
await this.closed;
|
17
|
+
return Promise.resolve(undefined);
|
18
|
+
}
|
19
|
+
releaseLock() {
|
20
|
+
}
|
21
|
+
async write(chunk) {
|
22
|
+
if (chunk) {
|
23
|
+
this._bufferArr.push(chunk);
|
24
|
+
}
|
25
|
+
return Promise.resolve(undefined);
|
26
|
+
}
|
27
|
+
}
|
28
|
+
export class LogCollector {
|
29
|
+
constructor(pass, txtEnDe) {
|
30
|
+
this.locked = false;
|
31
|
+
this._bufferArr = [];
|
32
|
+
this._pass = pass;
|
33
|
+
this._txtEnDe = txtEnDe || Utf8EnDecoderSingleton();
|
34
|
+
}
|
35
|
+
abort(reason) {
|
36
|
+
throw new Error("Method not implemented.");
|
37
|
+
}
|
38
|
+
async close() {
|
39
|
+
if (this._writer) {
|
40
|
+
const ret = await this._writer.close();
|
41
|
+
this._writer = undefined;
|
42
|
+
return ret;
|
43
|
+
}
|
44
|
+
return Promise.resolve(undefined);
|
45
|
+
}
|
46
|
+
getWriter() {
|
47
|
+
if (!this._writer) {
|
48
|
+
const dests = [new LogWriteStream(this._bufferArr)];
|
49
|
+
if (this._pass) {
|
50
|
+
dests.push(this._pass);
|
51
|
+
}
|
52
|
+
this._writer = new FanoutWriteStream(dests);
|
53
|
+
}
|
54
|
+
return this._writer;
|
55
|
+
}
|
56
|
+
Logs(notJsonLine = false) {
|
57
|
+
if (!this._writer) {
|
58
|
+
return [];
|
59
|
+
}
|
60
|
+
const jsonNlStr = this._txtEnDe.decode(new Uint8Array((function* (res) {
|
61
|
+
for (const x of res) {
|
62
|
+
yield* x;
|
63
|
+
}
|
64
|
+
})(this._bufferArr)));
|
65
|
+
if (!notJsonLine) {
|
66
|
+
const splitStr = jsonNlStr.split("\n");
|
67
|
+
const filterStr = splitStr.filter((a) => a.length);
|
68
|
+
const mapStr = filterStr.map((a) => JSON.parse(a));
|
69
|
+
return mapStr;
|
70
|
+
}
|
71
|
+
return jsonNlStr.split("\n").filter((a) => a.length);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
//# sourceMappingURL=log-write-stream.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"log-write-stream.js","sourceRoot":"","sources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MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;YACnD,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YACnD,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,OAAO,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IACvD,CAAC;CACF"}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { Logger } from "../logger.js";
|
2
|
+
import { SysAbstraction } from "../sys-abstraction.js";
|
3
|
+
import { LogCollector } from "./log-write-stream.js";
|
4
|
+
export interface MockLoggerReturn {
|
5
|
+
readonly logger: Logger;
|
6
|
+
readonly logCollector: LogCollector;
|
7
|
+
}
|
8
|
+
export declare function MockLogger(params?: {
|
9
|
+
readonly sys?: SysAbstraction;
|
10
|
+
readonly pass?: WritableStreamDefaultWriter<Uint8Array>;
|
11
|
+
moduleName?: string | string[];
|
12
|
+
readonly disableDebug?: boolean;
|
13
|
+
}): MockLoggerReturn;
|
14
|
+
//# sourceMappingURL=mock-logger.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"mock-logger.d.ts","sourceRoot":"","sources":["../../../src/test/mock-logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;CACrC;AAED,wBAAgB,UAAU,CAAC,MAAM,CAAC,EAAE;IAClC,QAAQ,CAAC,GAAG,CAAC,EAAE,cAAc,CAAC;IAC9B,QAAQ,CAAC,IAAI,CAAC,EAAE,2BAA2B,CAAC,UAAU,CAAC,CAAC;IACxD,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC/B,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC;CACjC,GAAG,gBAAgB,CAuBnB"}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { LevelHandlerImpl } from "../log-level-impl.js";
|
2
|
+
import { LoggerImpl } from "../logger-impl.js";
|
3
|
+
import { LogCollector } from "./log-write-stream.js";
|
4
|
+
export function MockLogger(params) {
|
5
|
+
const lc = new LogCollector(params === null || params === void 0 ? void 0 : params.pass);
|
6
|
+
let modNames = ["MockLogger"];
|
7
|
+
if (typeof (params === null || params === void 0 ? void 0 : params.moduleName) === "string") {
|
8
|
+
modNames = [params === null || params === void 0 ? void 0 : params.moduleName];
|
9
|
+
}
|
10
|
+
else if (Array.isArray(params === null || params === void 0 ? void 0 : params.moduleName)) {
|
11
|
+
modNames = [...params.moduleName, ...modNames];
|
12
|
+
}
|
13
|
+
const logger = new LoggerImpl({
|
14
|
+
out: lc,
|
15
|
+
sys: params === null || params === void 0 ? void 0 : params.sys,
|
16
|
+
levelHandler: new LevelHandlerImpl(),
|
17
|
+
})
|
18
|
+
.With()
|
19
|
+
.Module(modNames[0])
|
20
|
+
.Logger();
|
21
|
+
if (!(params === null || params === void 0 ? void 0 : params.disableDebug)) {
|
22
|
+
logger.SetDebug(...modNames);
|
23
|
+
}
|
24
|
+
return {
|
25
|
+
logCollector: lc,
|
26
|
+
logger,
|
27
|
+
};
|
28
|
+
}
|
29
|
+
//# sourceMappingURL=mock-logger.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"mock-logger.js","sourceRoot":"","sources":["../../../src/test/mock-logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,C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ceRoot":"","sources":["../../../src/test/mock-logger.test.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,63 @@
|
|
1
|
+
import { LogWriteStream, MockLogger } from "@adviser/cement";
|
2
|
+
describe("logger", () => {
|
3
|
+
it("with logcollector", async () => {
|
4
|
+
const l = MockLogger();
|
5
|
+
l.logger.Debug().Str("bla1", "blub1").Msg("hello1");
|
6
|
+
l.logger.Info().Str("bla2", "blub2").Msg("hello2");
|
7
|
+
await l.logger.Flush();
|
8
|
+
expect(l.logCollector.Logs()).toEqual([
|
9
|
+
{ level: "debug", bla1: "blub1", msg: "hello1", module: "MockLogger" },
|
10
|
+
{ level: "info", bla2: "blub2", msg: "hello2", module: "MockLogger" },
|
11
|
+
]);
|
12
|
+
});
|
13
|
+
it("with logcollector disableDebug", async () => {
|
14
|
+
const l = MockLogger({
|
15
|
+
disableDebug: true,
|
16
|
+
});
|
17
|
+
l.logger.Debug().Str("bla1", "blub1").Msg("hello1");
|
18
|
+
l.logger.Info().Str("bla2", "blub2").Msg("hello2");
|
19
|
+
await l.logger.Flush();
|
20
|
+
expect(l.logCollector.Logs()).toEqual([{ level: "info", bla2: "blub2", msg: "hello2", module: "MockLogger" }]);
|
21
|
+
});
|
22
|
+
it("with logcollector moduleName", async () => {
|
23
|
+
const l = MockLogger({
|
24
|
+
moduleName: "test",
|
25
|
+
});
|
26
|
+
l.logger.Debug().Str("bla1", "blub1").Msg("hello1");
|
27
|
+
l.logger.Info().Str("bla2", "blub2").Msg("hello2");
|
28
|
+
await l.logger.Flush();
|
29
|
+
expect(l.logCollector.Logs()).toEqual([
|
30
|
+
{ level: "debug", bla1: "blub1", msg: "hello1", module: "test" },
|
31
|
+
{ level: "info", bla2: "blub2", msg: "hello2", module: "test" },
|
32
|
+
]);
|
33
|
+
});
|
34
|
+
it("with logcollector [moduleName]", async () => {
|
35
|
+
const l = MockLogger({
|
36
|
+
moduleName: ["test", "wurst"],
|
37
|
+
});
|
38
|
+
l.logger.Debug().Str("bla1", "blub1").Msg("hello1");
|
39
|
+
l.logger.With().Module("wurst").Logger().Debug().Str("bla2", "blub2").Msg("hello2");
|
40
|
+
await l.logger.Flush();
|
41
|
+
expect(l.logCollector.Logs()).toEqual([
|
42
|
+
{ level: "debug", bla1: "blub1", msg: "hello1", module: "test" },
|
43
|
+
{ level: "debug", bla2: "blub2", msg: "hello2", module: "wurst" },
|
44
|
+
]);
|
45
|
+
});
|
46
|
+
it("tee in logcolletor", async () => {
|
47
|
+
const lc2Buffer = [];
|
48
|
+
const lc2 = new LogWriteStream(lc2Buffer);
|
49
|
+
const l = MockLogger({
|
50
|
+
pass: lc2,
|
51
|
+
});
|
52
|
+
l.logger.Error().Msg("should been shown in console");
|
53
|
+
await l.logger.Flush();
|
54
|
+
expect(l.logCollector.Logs()).toEqual([{ level: "error", msg: "should been shown in console", module: "MockLogger" }]);
|
55
|
+
expect(lc2Buffer.length).toBe(1);
|
56
|
+
expect(JSON.parse(new TextDecoder().decode(lc2Buffer[0]))).toEqual({
|
57
|
+
level: "error",
|
58
|
+
msg: "should been shown in console",
|
59
|
+
module: "MockLogger",
|
60
|
+
});
|
61
|
+
});
|
62
|
+
});
|
63
|
+
//# sourceMappingURL=mock-logger.test.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"mock-logger.test.js","sourceRoot":"","sources":["../../../src/test/mock-logger.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7D,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;IACtB,EAAE,CAAC,mBAAmB,EAAE,KAAK,IAAI,EAAE;QACjC,MAAM,CAAC,GAAG,UAAU,EAAE,CAAC;QACvB,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACpD,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC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ts","sourceRoot":"","sources":["../../../src/test/test-exit-handler.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
import { runtimeFn } from "../runtime.js";
|
2
|
+
const gts = globalThis;
|
3
|
+
(async () => {
|
4
|
+
var _a, _b;
|
5
|
+
const sa = await import(runtimeFn().isDeno ? "../node/deno-sys-abstraction.ts" : "../node/node-sys-abstraction.ts");
|
6
|
+
const my = runtimeFn().isDeno ? sa.DenoSysAbstraction() : sa.NodeSysAbstraction();
|
7
|
+
const process = runtimeFn().isDeno ? gts.Deno : gts.process;
|
8
|
+
const rargs = (runtimeFn().isDeno ? (_a = gts.Deno) === null || _a === void 0 ? void 0 : _a.args : (_b = gts.process) === null || _b === void 0 ? void 0 : _b.argv) || [];
|
9
|
+
const larg = rargs[rargs.length - 1];
|
10
|
+
console.log(JSON.stringify({
|
11
|
+
larg,
|
12
|
+
pid: process.pid,
|
13
|
+
}));
|
14
|
+
my.System().OnExit(async () => {
|
15
|
+
await my.Time().Sleep(100);
|
16
|
+
console.log(JSON.stringify({
|
17
|
+
larg,
|
18
|
+
pid: process.pid,
|
19
|
+
msg: "Called OnExit 1",
|
20
|
+
}));
|
21
|
+
});
|
22
|
+
my.System().OnExit(async () => {
|
23
|
+
await my.Time().Sleep(200);
|
24
|
+
console.log(JSON.stringify({
|
25
|
+
larg,
|
26
|
+
pid: process.pid,
|
27
|
+
msg: "Called OnExit 2",
|
28
|
+
}));
|
29
|
+
});
|
30
|
+
switch (larg) {
|
31
|
+
case "sigint":
|
32
|
+
await my.Time().Sleep(100);
|
33
|
+
process.kill(process.pid, "SIGINT");
|
34
|
+
await my.Time().Sleep(1000000);
|
35
|
+
break;
|
36
|
+
case "sigquit":
|
37
|
+
await my.Time().Sleep(100);
|
38
|
+
process.kill(process.pid, "SIGQUIT");
|
39
|
+
await my.Time().Sleep(1000000);
|
40
|
+
break;
|
41
|
+
case "sigterm":
|
42
|
+
await my.Time().Sleep(100);
|
43
|
+
process.kill(process.pid, "SIGTERM");
|
44
|
+
await my.Time().Sleep(1000000);
|
45
|
+
break;
|
46
|
+
case "throw":
|
47
|
+
await my.Time().Sleep(100);
|
48
|
+
throw new Error("throwing");
|
49
|
+
case "sleep":
|
50
|
+
await my.Time().Sleep(3000);
|
51
|
+
break;
|
52
|
+
case "exit24":
|
53
|
+
default:
|
54
|
+
my.System().Exit(24);
|
55
|
+
}
|
56
|
+
})();
|
57
|
+
//# sourceMappingURL=test-exit-handler.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"test-exit-handler.js","sourceRoot":"","sources":["../../../src/test/test-exit-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,MAAM,GAAG,GAAG,UAWX,CAAC;AAEF,CAAC,KAAK,IAAmB,EAAE;;IACzB,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,iCAAiC,CAAC,CAAC,CAAC,iCAAiC,CAAC,CAAC;IAEpH,MAAM,EAAE,GAAG,SAAS,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,kBAAkB,EAAE,CAAC;IAElF,MAAM,OAAO,GAAG,SAAS,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC;IAE5D,MAAM,KAAK,GAAG,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,MAAA,GAAG,CAAC,IAAI,0CAAE,IAAI,CAAC,CAAC,CAAC,MAAA,GAAG,CAAC,OAAO,0CAAE,IAAI,CAAC,IAAI,EAAE,CAAC;IAE9E,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAErC,OAAO,CAAC,GAAG,CACT,IAAI,CA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B,MAAM;QACR,KAAK,SAAS;YACZ,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC3B,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;YACrC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAC/B,MAAM;QACR,KAAK,OAAO;YACV,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC;QAC9B,KAAK,OAAO;YACV,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC5B,MAAM;QACR,KAAK,QAAQ,CAAC;QACd;YACE,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACzB,CAAC;AACH,CAAC,CAAC,EAAE,CAAC"}
|
package/ts/time.d.ts
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
export declare abstract class Time {
|
2
|
+
abstract Now(add?: number): Date;
|
3
|
+
abstract Sleep(duration: Duration): Promise<void>;
|
4
|
+
TimeSince(start: Date): Duration;
|
5
|
+
}
|
6
|
+
export type Duration = number;
|
7
|
+
export declare enum TimeUnits {
|
8
|
+
Microsecond = 1,
|
9
|
+
Second = 1000,
|
10
|
+
Minute = 60000,
|
11
|
+
Hour = 3600000
|
12
|
+
}
|
13
|
+
//# sourceMappingURL=time.d.ts.map
|
package/ts/time.d.ts.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../src/time.ts"],"names":[],"mappings":"AAAA,8BAAsB,IAAI;IACxB,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IAChC,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IACjD,SAAS,CAAC,KAAK,EAAE,IAAI,GAAG,QAAQ;CAIjC;AAED,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC;AAE9B,oBAAY,SAAS;IACnB,WAAW,IAAI;IAEf,MAAM,OAAqB;IAE3B,MAAM,QAAc;IAEpB,IAAI,UAAc;CACnB"}
|