@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/src/crypto.ts
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
export interface CTJsonWebKey {
|
2
|
+
alg?: string;
|
3
|
+
crv?: string;
|
4
|
+
d?: string;
|
5
|
+
dp?: string;
|
6
|
+
dq?: string;
|
7
|
+
e?: string;
|
8
|
+
ext?: boolean;
|
9
|
+
k?: string;
|
10
|
+
key_ops?: string[];
|
11
|
+
kty?: string;
|
12
|
+
n?: string;
|
13
|
+
oth?: RsaOtherPrimesInfo[];
|
14
|
+
p?: string;
|
15
|
+
q?: string;
|
16
|
+
qi?: string;
|
17
|
+
use?: string;
|
18
|
+
x?: string;
|
19
|
+
y?: string;
|
20
|
+
}
|
21
|
+
|
22
|
+
export type CTKeyFormat = "jwk" | "pkcs8" | "raw" | "spki";
|
23
|
+
export type CTKeyUsage = "decrypt" | "deriveBits" | "deriveKey" | "encrypt" | "sign" | "unwrapKey" | "verify" | "wrapKey";
|
24
|
+
|
25
|
+
export interface CTAlgorithm {
|
26
|
+
name: string;
|
27
|
+
}
|
28
|
+
export type CTAlgorithmIdentifier = CTAlgorithm | string;
|
29
|
+
|
30
|
+
export interface CTRsaHashedImportParams extends CTAlgorithm {
|
31
|
+
hash: CTAlgorithmIdentifier;
|
32
|
+
}
|
33
|
+
|
34
|
+
export type CTNamedCurve = string;
|
35
|
+
export interface CTEcKeyImportParams extends CTAlgorithm {
|
36
|
+
namedCurve: CTNamedCurve;
|
37
|
+
}
|
38
|
+
|
39
|
+
export interface CTHmacImportParams extends CTAlgorithm {
|
40
|
+
hash: CTAlgorithmIdentifier;
|
41
|
+
length?: number;
|
42
|
+
}
|
43
|
+
|
44
|
+
export interface CTAesKeyAlgorithm extends CTAlgorithm {
|
45
|
+
length: number;
|
46
|
+
}
|
47
|
+
|
48
|
+
export type CTKeyType = "private" | "public" | "secret";
|
49
|
+
|
50
|
+
export interface CTCryptoKey {
|
51
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CryptoKey/algorithm) */
|
52
|
+
readonly algorithm: CTAlgorithm;
|
53
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CryptoKey/extractable) */
|
54
|
+
readonly extractable: boolean;
|
55
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CryptoKey/type) */
|
56
|
+
readonly type: CTKeyType;
|
57
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CryptoKey/usages) */
|
58
|
+
readonly usages: CTKeyUsage[];
|
59
|
+
}
|
60
|
+
|
61
|
+
interface CTArrayBufferTypes {
|
62
|
+
ArrayBuffer: ArrayBuffer;
|
63
|
+
}
|
64
|
+
type CTArrayBufferLike = CTArrayBufferTypes[keyof CTArrayBufferTypes];
|
65
|
+
|
66
|
+
export interface CTArrayBufferView {
|
67
|
+
/**
|
68
|
+
* The ArrayBuffer instance referenced by the array.
|
69
|
+
*/
|
70
|
+
buffer: CTArrayBufferLike;
|
71
|
+
|
72
|
+
/**
|
73
|
+
* The length in bytes of the array.
|
74
|
+
*/
|
75
|
+
byteLength: number;
|
76
|
+
|
77
|
+
/**
|
78
|
+
* The offset in bytes of the array.
|
79
|
+
*/
|
80
|
+
byteOffset: number;
|
81
|
+
}
|
82
|
+
|
83
|
+
export type CTBufferSource = CTArrayBufferView | ArrayBuffer;
|
84
|
+
|
85
|
+
export interface CryptoRuntime {
|
86
|
+
importKey(
|
87
|
+
format: CTKeyFormat,
|
88
|
+
keyData: CTJsonWebKey | CTBufferSource,
|
89
|
+
algorithm: CTAlgorithmIdentifier | CTRsaHashedImportParams | CTEcKeyImportParams | CTHmacImportParams | CTAesKeyAlgorithm,
|
90
|
+
extractable: boolean,
|
91
|
+
keyUsages: CTKeyUsage[],
|
92
|
+
): Promise<CTCryptoKey>;
|
93
|
+
exportKey(format: CTKeyFormat, key: CTCryptoKey): Promise<CTJsonWebKey | ArrayBuffer>;
|
94
|
+
|
95
|
+
//(format: "raw", key: ArrayBuffer, algo: string, extractable: boolean, usages: string[]) => Promise<CryptoKey>;
|
96
|
+
decrypt(algo: { name: string; iv: Uint8Array; tagLength: number }, key: CTCryptoKey, data: Uint8Array): Promise<ArrayBuffer>;
|
97
|
+
encrypt(algo: { name: string; iv: Uint8Array; tagLength: number }, key: CTCryptoKey, data: Uint8Array): Promise<ArrayBuffer>;
|
98
|
+
digestSHA256(data: Uint8Array): Promise<ArrayBuffer>;
|
99
|
+
randomBytes(size: number): Uint8Array;
|
100
|
+
}
|
101
|
+
|
102
|
+
function randomBytes(size: number): Uint8Array {
|
103
|
+
const bytes = new Uint8Array(size);
|
104
|
+
if (size > 0) {
|
105
|
+
crypto.getRandomValues(bytes);
|
106
|
+
}
|
107
|
+
return bytes;
|
108
|
+
}
|
109
|
+
|
110
|
+
function digestSHA256(data: Uint8Array): Promise<ArrayBuffer> {
|
111
|
+
return Promise.resolve(crypto.subtle.digest("SHA-256", data));
|
112
|
+
}
|
113
|
+
|
114
|
+
export function toCryptoRuntime(cryptoOpts: Partial<CryptoRuntime> = {}): CryptoRuntime {
|
115
|
+
const runtime = {
|
116
|
+
importKey: cryptoOpts.importKey || crypto.subtle.importKey.bind(crypto.subtle),
|
117
|
+
exportKey: cryptoOpts.exportKey || crypto.subtle.exportKey.bind(crypto.subtle),
|
118
|
+
encrypt: cryptoOpts.encrypt || crypto.subtle.encrypt.bind(crypto.subtle),
|
119
|
+
decrypt: cryptoOpts.decrypt || crypto.subtle.decrypt.bind(crypto.subtle),
|
120
|
+
randomBytes: cryptoOpts.randomBytes || randomBytes,
|
121
|
+
digestSHA256: cryptoOpts.digestSHA256 || digestSHA256,
|
122
|
+
};
|
123
|
+
// console.log("cryptoOpts", cryptoOpts, opts)
|
124
|
+
return runtime;
|
125
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
export interface NamedWritableStream {
|
2
|
+
readonly name: string;
|
3
|
+
readonly stream: WritableStream<Uint8Array>;
|
4
|
+
}
|
5
|
+
|
6
|
+
export interface FileService {
|
7
|
+
readonly baseDir: string;
|
8
|
+
create(fname: string): Promise<NamedWritableStream>;
|
9
|
+
readFileString(fname: string): Promise<string>;
|
10
|
+
writeFileString(fname: string, content: string): Promise<void>;
|
11
|
+
|
12
|
+
abs(fname: string): string;
|
13
|
+
|
14
|
+
join(...paths: string[]): string;
|
15
|
+
|
16
|
+
relative(from: string, to?: string): string;
|
17
|
+
|
18
|
+
dirname(fname: string): string;
|
19
|
+
basename(fname: string): string;
|
20
|
+
|
21
|
+
// nodeImport(fname: string): string;
|
22
|
+
|
23
|
+
isAbsolute(fname: string): boolean;
|
24
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { Future } from "@adviser/cement";
|
2
|
+
|
3
|
+
it("Create Future Happy", async () => {
|
4
|
+
const future = new Future();
|
5
|
+
const promise = future.asPromise();
|
6
|
+
expect(promise).toBeInstanceOf(Promise);
|
7
|
+
|
8
|
+
const asynced = new Promise((resolve, reject) => {
|
9
|
+
promise.then(resolve).catch(reject);
|
10
|
+
});
|
11
|
+
future.resolve("Hello World");
|
12
|
+
|
13
|
+
expect(await asynced).toBe("Hello World");
|
14
|
+
});
|
15
|
+
|
16
|
+
it("Create Future Sad", async () => {
|
17
|
+
const future = new Future();
|
18
|
+
const promise = future.asPromise();
|
19
|
+
expect(promise).toBeInstanceOf(Promise);
|
20
|
+
|
21
|
+
const asynced = new Promise((resolve, reject) => {
|
22
|
+
promise.then(resolve).catch(reject);
|
23
|
+
});
|
24
|
+
future.reject("Sad World");
|
25
|
+
|
26
|
+
try {
|
27
|
+
await asynced;
|
28
|
+
expect("Why").toBe("Sad World");
|
29
|
+
} catch (error) {
|
30
|
+
expect(error).toBe("Sad World");
|
31
|
+
}
|
32
|
+
});
|
package/src/future.ts
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
export class Future<T> {
|
2
|
+
readonly #promise: Promise<T>;
|
3
|
+
#resolveFn: (value: T) => void = () => {
|
4
|
+
throw new Error("This Promise is not working as expected.");
|
5
|
+
};
|
6
|
+
#rejectFn: (reason: unknown) => void = () => {
|
7
|
+
throw new Error("This Promise is not working as expected.");
|
8
|
+
};
|
9
|
+
|
10
|
+
constructor() {
|
11
|
+
this.#promise = new Promise<T>((resolve, reject) => {
|
12
|
+
this.#resolveFn = resolve;
|
13
|
+
this.#rejectFn = reject;
|
14
|
+
});
|
15
|
+
}
|
16
|
+
|
17
|
+
async asPromise(): Promise<T> {
|
18
|
+
return this.#promise;
|
19
|
+
}
|
20
|
+
|
21
|
+
resolve(value: T): void {
|
22
|
+
this.#resolveFn(value);
|
23
|
+
}
|
24
|
+
reject(reason: unknown): void {
|
25
|
+
this.#rejectFn(reason);
|
26
|
+
}
|
27
|
+
}
|
package/src/index.ts
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
export * from "./file-service.js";
|
2
|
+
export * from "./logger-impl.js";
|
3
|
+
export * from "./logger.js";
|
4
|
+
export * from "./sys-abstraction.js";
|
5
|
+
export * from "./sys-env.js";
|
6
|
+
export * from "./time.js";
|
7
|
+
export * from "./test/log-write-stream.js";
|
8
|
+
export * from "./test/mock-logger.js";
|
9
|
+
export * from "./txt-en-decoder.js";
|
10
|
+
export * from "./log-level-impl.js";
|
11
|
+
export * from "./result.js";
|
12
|
+
export * from "./option.js";
|
13
|
+
export * from "./future.js";
|
14
|
+
export * from "./tracer.js";
|
15
|
+
export * from "./resolve-once.js";
|
16
|
+
export * from "./runtime.js";
|
17
|
+
export * from "./uri.js";
|
18
|
+
export * from "./crypto.js";
|
19
|
+
export * from "./base-sys-abstraction.js";
|
20
|
+
export * from "./bin2text.js";
|
21
|
+
export * from "./version.js";
|
22
|
+
export * as utils from "./utils/index.js";
|
package/src/jsr.json
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
{
|
2
|
+
"name": "@adviser/cement",
|
3
|
+
"version": "0.0.0-jsr-t1",
|
4
|
+
"exports": {
|
5
|
+
".": "./index.ts",
|
6
|
+
"./web": "./web/index.ts",
|
7
|
+
"./node": "./node/index.ts",
|
8
|
+
"./deno": "./node/index.ts"
|
9
|
+
},
|
10
|
+
"imports": {
|
11
|
+
"yaml": "npm:yaml@^2.5.1",
|
12
|
+
"ts-essentials": "npm:ts-essentials@^10.0.2"
|
13
|
+
},
|
14
|
+
"license": "AFL-2.0",
|
15
|
+
"publish": {
|
16
|
+
"include": [
|
17
|
+
"**/*.ts"
|
18
|
+
]
|
19
|
+
}
|
20
|
+
}
|
@@ -0,0 +1,87 @@
|
|
1
|
+
import { LevelHandler, Level } from "./logger.js";
|
2
|
+
|
3
|
+
export class LevelHandlerImpl implements LevelHandler {
|
4
|
+
readonly _globalLevels: Set<Level> = new Set<Level>([Level.INFO, Level.ERROR, Level.WARN]);
|
5
|
+
readonly _modules: Map<string, Set<Level>> = new Map<string, Set<Level>>();
|
6
|
+
isStackExposed = false;
|
7
|
+
enableLevel(level: Level, ...modules: string[]): void {
|
8
|
+
if (modules.length == 0) {
|
9
|
+
this._globalLevels.add(level);
|
10
|
+
return;
|
11
|
+
}
|
12
|
+
this.forModules(
|
13
|
+
level,
|
14
|
+
(p) => {
|
15
|
+
this._modules.set(p, new Set([...this._globalLevels, level]));
|
16
|
+
},
|
17
|
+
...modules,
|
18
|
+
);
|
19
|
+
}
|
20
|
+
disableLevel(level: Level, ...modules: string[]): void {
|
21
|
+
if (modules.length == 0) {
|
22
|
+
this._globalLevels.delete(level);
|
23
|
+
return;
|
24
|
+
}
|
25
|
+
this.forModules(
|
26
|
+
level,
|
27
|
+
(p) => {
|
28
|
+
this._modules.delete(p);
|
29
|
+
},
|
30
|
+
...modules,
|
31
|
+
);
|
32
|
+
}
|
33
|
+
|
34
|
+
setExposeStack(enable?: boolean): void {
|
35
|
+
this.isStackExposed = !!enable;
|
36
|
+
}
|
37
|
+
|
38
|
+
forModules(level: Level, fnAction: (p: string) => void, ...modules: (string | string[])[]): void {
|
39
|
+
for (const m of modules.flat()) {
|
40
|
+
if (typeof m !== "string") {
|
41
|
+
continue;
|
42
|
+
}
|
43
|
+
const parts = m
|
44
|
+
.split(",")
|
45
|
+
.map((s) => s.trim())
|
46
|
+
.filter((s) => s.length);
|
47
|
+
for (const p of parts) {
|
48
|
+
fnAction(p);
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
setDebug(...modules: (string | string[])[]): void {
|
53
|
+
this.forModules(
|
54
|
+
Level.DEBUG,
|
55
|
+
(p) => {
|
56
|
+
this._modules.set(p, new Set([...this._globalLevels, Level.DEBUG]));
|
57
|
+
},
|
58
|
+
...modules,
|
59
|
+
);
|
60
|
+
}
|
61
|
+
isEnabled(ilevel: unknown, module: unknown): boolean {
|
62
|
+
const level = ilevel as Level; // what if it's not a level?
|
63
|
+
if (typeof module === "string") {
|
64
|
+
const levels = this._modules.get(module);
|
65
|
+
if (levels && levels.has(level)) {
|
66
|
+
return true;
|
67
|
+
}
|
68
|
+
}
|
69
|
+
const wlevel = this._modules.get("*");
|
70
|
+
if (wlevel && typeof level === "string") {
|
71
|
+
if (wlevel.has(level)) {
|
72
|
+
return true;
|
73
|
+
}
|
74
|
+
}
|
75
|
+
if (typeof level !== "string") {
|
76
|
+
// this is a plain log
|
77
|
+
return true;
|
78
|
+
}
|
79
|
+
return this._globalLevels.has(level);
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
const levelSingleton = new LevelHandlerImpl();
|
84
|
+
|
85
|
+
export function LevelHandlerSingleton(): LevelHandler {
|
86
|
+
return levelSingleton;
|
87
|
+
}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
export class LogWriterStream {
|
2
|
+
readonly _out: WritableStream<Uint8Array>;
|
3
|
+
readonly _toFlush: (() => Promise<void>)[] = [];
|
4
|
+
|
5
|
+
constructor(out: WritableStream<Uint8Array>) {
|
6
|
+
this._out = out;
|
7
|
+
}
|
8
|
+
|
9
|
+
write(encoded: Uint8Array): void {
|
10
|
+
const my = async (): Promise<void> => {
|
11
|
+
// const val = Math.random();
|
12
|
+
// console.log(">>>My:", val)
|
13
|
+
try {
|
14
|
+
const writer = this._out.getWriter();
|
15
|
+
await writer.ready;
|
16
|
+
await writer.write(encoded);
|
17
|
+
await writer.releaseLock();
|
18
|
+
} catch (err) {
|
19
|
+
// eslint-disable-next-line no-console
|
20
|
+
console.error("Chunk error:", err);
|
21
|
+
}
|
22
|
+
// console.log("<<<My:", val)
|
23
|
+
};
|
24
|
+
this._toFlush.push(my);
|
25
|
+
this._flush();
|
26
|
+
}
|
27
|
+
|
28
|
+
_flushIsRunning = false;
|
29
|
+
_flushDoneFns: (() => void)[] = [];
|
30
|
+
_flush(toFlush: (() => Promise<void>)[] | undefined = undefined, done?: () => void): void {
|
31
|
+
if (done) {
|
32
|
+
this._flushDoneFns.push(done);
|
33
|
+
}
|
34
|
+
|
35
|
+
if (this._toFlush.length == 0) {
|
36
|
+
// console.log("Flush is stopped", this._toFlush.length)
|
37
|
+
this._flushIsRunning = false;
|
38
|
+
this._flushDoneFns.forEach((fn) => fn());
|
39
|
+
this._flushDoneFns = [];
|
40
|
+
return;
|
41
|
+
}
|
42
|
+
|
43
|
+
if (!toFlush && this._toFlush.length == 1 && !this._flushIsRunning) {
|
44
|
+
this._flushIsRunning = true;
|
45
|
+
// console.log("Flush is started", this._toFlush.length)
|
46
|
+
} else if (!toFlush) {
|
47
|
+
// console.log("flush queue check but is running", this._toFlush.length)
|
48
|
+
return;
|
49
|
+
}
|
50
|
+
|
51
|
+
// console.log(">>>Msg:", this._toFlush.length)
|
52
|
+
const my = this._toFlush.shift();
|
53
|
+
my?.().finally(() => {
|
54
|
+
// console.log("<<<Msg:", this._toFlush.length)
|
55
|
+
this._flush(this._toFlush);
|
56
|
+
});
|
57
|
+
}
|
58
|
+
}
|