@adviser/cement 0.2.28 → 0.2.30
Sign up to get free protection for your applications and to get access to all the features.
- package/{base-sys-abstraction-C9WW3w57.d.cts → base-sys-abstraction-BkEiLHl0.d.ts} +8 -4
- package/{base-sys-abstraction-C9WW3w57.d.ts → base-sys-abstraction-Qj7pkY1N.d.cts} +8 -4
- package/{chunk-OXD3YZZ7.js → chunk-7KFVMTOS.js} +3 -47
- package/chunk-7KFVMTOS.js.map +1 -0
- package/{chunk-P5RXA4C4.js → chunk-GES3MUGV.js} +24 -27
- package/{chunk-LCPYQVWT.js.map → chunk-GES3MUGV.js.map} +1 -1
- package/{chunk-YDIUMYIE.js → chunk-Q65HLCNL.js} +8 -7
- package/chunk-Q65HLCNL.js.map +1 -0
- package/{chunk-DPIL5UIL.js → chunk-WMMUXBDX.js} +6 -2
- package/chunk-WMMUXBDX.js.map +1 -0
- package/{index-Dhb2fQiw.d.cts → index-Q3phXzYr.d.cts} +2 -21
- package/{index-CcsGcehs.d.ts → index-tIGZMHTc.d.ts} +2 -21
- package/index.cjs +288 -7345
- package/index.cjs.map +1 -1
- package/index.d.cts +74 -12
- package/index.d.ts +74 -12
- package/index.js +239 -7266
- package/index.js.map +1 -1
- package/node/index.cjs +220 -39
- package/node/index.cjs.map +1 -1
- package/node/index.d.cts +22 -4
- package/node/index.d.ts +22 -4
- package/node/index.js +201 -25
- package/node/index.js.map +1 -1
- package/package.json +34 -23
- package/src/LICENSE +201 -0
- package/src/README.md +39 -0
- package/src/base-sys-abstraction.ts +242 -0
- package/src/bin2text.ts +47 -0
- package/src/crypto.ts +125 -0
- package/src/file-service.ts +24 -0
- package/src/future.ts +27 -0
- package/src/index.ts +23 -0
- package/src/jsr.json +22 -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.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/refcounted.ts +23 -0
- package/src/resolve-once.ts +179 -0
- package/src/result.ts +165 -0
- package/src/runtime.ts +36 -0
- package/src/sys-abstraction.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.ts +222 -0
- package/src/txt-en-decoder.ts +21 -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/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 +24 -0
- package/ts/index.d.ts.map +1 -0
- package/ts/index.js +24 -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 +83 -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/refcounted.d.ts +2 -0
- package/ts/refcounted.d.ts.map +1 -0
- package/ts/refcounted.js +19 -0
- package/ts/refcounted.js.map +1 -0
- package/ts/refcounted.test.d.ts +2 -0
- package/ts/refcounted.test.d.ts.map +1 -0
- package/ts/refcounted.test.js +39 -0
- package/ts/refcounted.test.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/utils/index.cjs +0 -42
- package/utils/index.cjs.map +1 -1
- package/utils/index.d.cts +1 -2
- package/utils/index.d.ts +1 -2
- package/utils/index.js +2 -7
- package/web/index.cjs +25 -7
- package/web/index.cjs.map +1 -1
- package/web/index.d.cts +2 -1
- package/web/index.d.ts +2 -1
- package/web/index.js +3 -3
- package/chunk-DPIL5UIL.js.map +0 -1
- package/chunk-LCPYQVWT.js +0 -21
- package/chunk-OXD3YZZ7.js.map +0 -1
- package/chunk-P5RXA4C4.js.map +0 -1
- package/chunk-YDIUMYIE.js.map +0 -1
package/src/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
package/src/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# cement
|
2
|
+
|
3
|
+
An Agnostic Platform Wrapper
|
4
|
+
|
5
|
+
which Provides:
|
6
|
+
|
7
|
+
- SysAbstraction
|
8
|
+
```typescript
|
9
|
+
export interface SysAbstraction {
|
10
|
+
Time(): Time;
|
11
|
+
Stdout(): WritableStream<Uint8Array>;
|
12
|
+
Stderr(): WritableStream<Uint8Array>;
|
13
|
+
NextId(): string;
|
14
|
+
Random0ToValue(value: number): number;
|
15
|
+
System(): SystemService;
|
16
|
+
FileSystem(): FileService;
|
17
|
+
}
|
18
|
+
```
|
19
|
+
- Logger inspired from golang zlogger
|
20
|
+
```typescript
|
21
|
+
export interface LoggerInterface<R> {
|
22
|
+
Module(key: string): R;
|
23
|
+
SetDebug(...modules: (string | string[])[]): R;
|
24
|
+
|
25
|
+
Str(key: string, value: string): R;
|
26
|
+
Error(): R;
|
27
|
+
Warn(): R;
|
28
|
+
Debug(): R;
|
29
|
+
Log(): R;
|
30
|
+
WithLevel(level: Level): R;
|
31
|
+
|
32
|
+
Err(err: unknown): R; // could be Error, or something which coerces to string
|
33
|
+
Info(): R;
|
34
|
+
Timestamp(): R;
|
35
|
+
Any(key: string, value: unknown): R;
|
36
|
+
Dur(key: string, nsec: number): R;
|
37
|
+
Uint64(key: string, value: number): R;
|
38
|
+
}
|
39
|
+
```
|
@@ -0,0 +1,242 @@
|
|
1
|
+
import { FileService } from "./file-service.js";
|
2
|
+
import { TimeMode, RandomMode, IDMode, SystemService, VoidFunc, SysAbstraction } from "./sys-abstraction.js";
|
3
|
+
import { Time } from "./time.js";
|
4
|
+
import { TxtEnDecoder } from "./txt-en-decoder.js";
|
5
|
+
|
6
|
+
export class SysTime extends Time {
|
7
|
+
Now(): Date {
|
8
|
+
return new Date();
|
9
|
+
}
|
10
|
+
Sleep(duration: number): Promise<void> {
|
11
|
+
return new Promise((resolve) => {
|
12
|
+
setTimeout(() => {
|
13
|
+
resolve();
|
14
|
+
}, duration);
|
15
|
+
});
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
19
|
+
export class ConstTime extends Time {
|
20
|
+
Now(): Date {
|
21
|
+
return new Date(2021, 1, 1, 0, 0, 0, 0);
|
22
|
+
}
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
24
|
+
Sleep(duration: number): Promise<void> {
|
25
|
+
return Promise.resolve();
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
export class StepTime extends Time {
|
30
|
+
_step: Date;
|
31
|
+
readonly _start: Date;
|
32
|
+
constructor() {
|
33
|
+
super();
|
34
|
+
this._step = new ConstTime().Now();
|
35
|
+
this._start = this._step;
|
36
|
+
}
|
37
|
+
Now(steps = 1): Date {
|
38
|
+
// if (this._step.getTime() === 0) {
|
39
|
+
// this._step = new ConstTime().Now();
|
40
|
+
// return this._step;
|
41
|
+
// }
|
42
|
+
for (let i = 0; steps > 0 && i < steps; i++) {
|
43
|
+
this._step = new Date(this._step.getTime() + 1000);
|
44
|
+
}
|
45
|
+
if (steps < 1) {
|
46
|
+
this._step = new Date(this._start.getTime() + steps * -1000);
|
47
|
+
}
|
48
|
+
// this._step = new Date(this._step.getTime() + 1000);
|
49
|
+
return this._step;
|
50
|
+
}
|
51
|
+
Sleep(duration: number): Promise<void> {
|
52
|
+
this._step = new Date(this._step.getTime() + duration);
|
53
|
+
return Promise.resolve();
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
export function TimeFactory(timeMode: TimeMode): Time {
|
58
|
+
switch (timeMode) {
|
59
|
+
case TimeMode.REAL:
|
60
|
+
return new SysTime();
|
61
|
+
case TimeMode.CONST:
|
62
|
+
return new ConstTime();
|
63
|
+
case TimeMode.STEP:
|
64
|
+
return new StepTime();
|
65
|
+
}
|
66
|
+
return new SysTime();
|
67
|
+
}
|
68
|
+
|
69
|
+
export class RandomService {
|
70
|
+
readonly _mode: RandomMode;
|
71
|
+
_step = 0;
|
72
|
+
constructor(mode: RandomMode) {
|
73
|
+
this._mode = mode;
|
74
|
+
}
|
75
|
+
Random0ToValue(value: number): number {
|
76
|
+
switch (this._mode) {
|
77
|
+
case RandomMode.CONST:
|
78
|
+
return 0.5 * value;
|
79
|
+
case RandomMode.STEP:
|
80
|
+
this._step += 0.0001;
|
81
|
+
return this._step * value;
|
82
|
+
case RandomMode.RANDOM:
|
83
|
+
return Math.random() * value;
|
84
|
+
default:
|
85
|
+
throw new Error("Unknown RandomMode");
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
export class IdService {
|
91
|
+
readonly _mode: IDMode;
|
92
|
+
_step = 0;
|
93
|
+
constructor(mode?: IDMode) {
|
94
|
+
if (!mode) {
|
95
|
+
mode = IDMode.UUID;
|
96
|
+
}
|
97
|
+
this._mode = mode;
|
98
|
+
}
|
99
|
+
NextId(): string {
|
100
|
+
switch (this._mode) {
|
101
|
+
case IDMode.UUID:
|
102
|
+
return crypto.randomUUID();
|
103
|
+
case IDMode.CONST:
|
104
|
+
return "VeryUniqueID";
|
105
|
+
case IDMode.STEP:
|
106
|
+
return `STEPId-${this._step++}`;
|
107
|
+
default:
|
108
|
+
throw new Error("Unknown IDMode");
|
109
|
+
}
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
export interface BaseSysAbstractionParams {
|
114
|
+
readonly TxtEnDecoder: TxtEnDecoder;
|
115
|
+
readonly FileSystem: FileService;
|
116
|
+
readonly SystemService: SystemService;
|
117
|
+
}
|
118
|
+
|
119
|
+
export interface ExitHandler {
|
120
|
+
readonly hdl: VoidFunc;
|
121
|
+
readonly id: string;
|
122
|
+
}
|
123
|
+
|
124
|
+
export interface ExitService {
|
125
|
+
injectExitHandlers(hdls: ExitHandler[]): void;
|
126
|
+
exit(code: number): void;
|
127
|
+
}
|
128
|
+
|
129
|
+
export class BaseSysAbstraction {
|
130
|
+
readonly _time: SysTime = new SysTime();
|
131
|
+
readonly _stdout: WritableStream;
|
132
|
+
readonly _stderr: WritableStream;
|
133
|
+
|
134
|
+
readonly _idService: IdService = new IdService();
|
135
|
+
readonly _randomService: RandomService = new RandomService(RandomMode.RANDOM);
|
136
|
+
readonly _fileSystem: FileService;
|
137
|
+
readonly _systemService: SystemService;
|
138
|
+
readonly _txtEnDe: TxtEnDecoder;
|
139
|
+
|
140
|
+
constructor(params: BaseSysAbstractionParams) {
|
141
|
+
this._fileSystem = params.FileSystem;
|
142
|
+
this._systemService = params.SystemService;
|
143
|
+
this._txtEnDe = params.TxtEnDecoder;
|
144
|
+
const decoder = this._txtEnDe;
|
145
|
+
this._stdout = new WritableStream({
|
146
|
+
write(chunk): Promise<void> {
|
147
|
+
return new Promise((resolve) => {
|
148
|
+
const decoded = decoder.decode(chunk);
|
149
|
+
// eslint-disable-next-line no-console
|
150
|
+
console.log(decoded.trimEnd());
|
151
|
+
resolve();
|
152
|
+
});
|
153
|
+
},
|
154
|
+
});
|
155
|
+
this._stderr = new WritableStream({
|
156
|
+
write(chunk): Promise<void> {
|
157
|
+
return new Promise((resolve) => {
|
158
|
+
const decoded = decoder.decode(chunk);
|
159
|
+
// eslint-disable-next-line no-console
|
160
|
+
console.error(decoded.trimEnd());
|
161
|
+
resolve();
|
162
|
+
});
|
163
|
+
},
|
164
|
+
});
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
export interface WrapperSysAbstractionParams {
|
169
|
+
readonly TimeMode?: TimeMode;
|
170
|
+
readonly IdMode?: IDMode;
|
171
|
+
readonly Stdout?: WritableStream<Uint8Array>;
|
172
|
+
readonly Stderr?: WritableStream<Uint8Array>;
|
173
|
+
readonly RandomMode?: RandomMode;
|
174
|
+
readonly FileSystem?: FileService;
|
175
|
+
readonly SystemService?: SystemService;
|
176
|
+
readonly TxtEnDecoder?: TxtEnDecoder;
|
177
|
+
}
|
178
|
+
|
179
|
+
export class WrapperSysAbstraction implements SysAbstraction {
|
180
|
+
readonly _time: Time;
|
181
|
+
readonly _stdout: WritableStream<Uint8Array>;
|
182
|
+
readonly _stderr: WritableStream<Uint8Array>;
|
183
|
+
readonly _idService: IdService;
|
184
|
+
readonly _randomService: RandomService;
|
185
|
+
readonly _fileSystem: FileService;
|
186
|
+
readonly _systemService: SystemService;
|
187
|
+
constructor(base: BaseSysAbstraction, params?: WrapperSysAbstractionParams) {
|
188
|
+
this._time = base._time;
|
189
|
+
this._stdout = base._stdout;
|
190
|
+
this._stderr = base._stderr;
|
191
|
+
this._idService = base._idService;
|
192
|
+
this._randomService = base._randomService;
|
193
|
+
this._fileSystem = base._fileSystem;
|
194
|
+
this._systemService = base._systemService;
|
195
|
+
if (params) {
|
196
|
+
if (params.TimeMode) {
|
197
|
+
this._time = TimeFactory(params.TimeMode);
|
198
|
+
}
|
199
|
+
if (params.Stdout) {
|
200
|
+
this._stdout = params.Stdout;
|
201
|
+
}
|
202
|
+
if (params.Stderr) {
|
203
|
+
this._stderr = params.Stderr;
|
204
|
+
}
|
205
|
+
if (params.IdMode) {
|
206
|
+
this._idService = new IdService(params.IdMode);
|
207
|
+
}
|
208
|
+
if (params.RandomMode) {
|
209
|
+
this._randomService = new RandomService(params.RandomMode);
|
210
|
+
}
|
211
|
+
if (params.FileSystem) {
|
212
|
+
this._fileSystem = params.FileSystem;
|
213
|
+
}
|
214
|
+
if (params.SystemService) {
|
215
|
+
this._systemService = params.SystemService;
|
216
|
+
}
|
217
|
+
}
|
218
|
+
}
|
219
|
+
Time(): Time {
|
220
|
+
return this._time;
|
221
|
+
}
|
222
|
+
NextId(): string {
|
223
|
+
return this._idService.NextId();
|
224
|
+
}
|
225
|
+
Random0ToValue(value: number): number {
|
226
|
+
return this._randomService.Random0ToValue(value);
|
227
|
+
}
|
228
|
+
Stdout(): WritableStream {
|
229
|
+
return this._stdout;
|
230
|
+
}
|
231
|
+
Stderr(): WritableStream {
|
232
|
+
return this._stderr;
|
233
|
+
}
|
234
|
+
|
235
|
+
System(): SystemService {
|
236
|
+
return this._systemService;
|
237
|
+
}
|
238
|
+
FileSystem(): FileService {
|
239
|
+
return this._fileSystem;
|
240
|
+
}
|
241
|
+
}
|
242
|
+
// export const BaseSysAbstraction = new BaseSysAbstractionImpl()
|
package/src/bin2text.ts
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
export function bin2text(hex: ArrayBufferView, lineFn: (line: string) => void, size = 0): void {
|
2
|
+
const arr = new Uint8Array(hex.buffer, hex.byteOffset, hex.byteLength);
|
3
|
+
let cutted = " ";
|
4
|
+
if (size == 0) {
|
5
|
+
size = arr.length;
|
6
|
+
}
|
7
|
+
size = Math.min(size, arr.length);
|
8
|
+
const cols = 16;
|
9
|
+
for (let line = 0; line < size; line += cols) {
|
10
|
+
if (line + cols <= size || arr.length == size) {
|
11
|
+
// normal line
|
12
|
+
} else {
|
13
|
+
line = arr.length - (arr.length % cols);
|
14
|
+
size = arr.length;
|
15
|
+
cutted = ">>";
|
16
|
+
}
|
17
|
+
const l: string[] = [line.toString(16).padStart(4, "0"), cutted];
|
18
|
+
for (let col = 0; col < cols; col++) {
|
19
|
+
if (line + col < size) {
|
20
|
+
l.push(arr[line + col].toString(16).padStart(2, "0"));
|
21
|
+
} else {
|
22
|
+
l.push(" ");
|
23
|
+
}
|
24
|
+
// l.push((col > 0 && col % 4 === 3) ? " " : " ");
|
25
|
+
l.push(" ");
|
26
|
+
}
|
27
|
+
for (let col = 0; col < cols; col++) {
|
28
|
+
if (line + col < size) {
|
29
|
+
const ch = arr[line + col];
|
30
|
+
l.push(ch >= 32 && ch < 127 ? String.fromCharCode(ch) : ".");
|
31
|
+
}
|
32
|
+
}
|
33
|
+
lineFn(l.join(""));
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
export function bin2string(hex: ArrayBufferView, size = 0): string {
|
38
|
+
const collector: string[] = [];
|
39
|
+
bin2text(
|
40
|
+
hex,
|
41
|
+
(line) => {
|
42
|
+
collector.push(line);
|
43
|
+
},
|
44
|
+
size,
|
45
|
+
);
|
46
|
+
return collector.join("\n");
|
47
|
+
}
|
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
|
+
}
|