@adviser/cement 0.2.28 → 0.2.29

Sign up to get free protection for your applications and to get access to all the features.
Files changed (319) hide show
  1. package/{base-sys-abstraction-C9WW3w57.d.cts → base-sys-abstraction-BkEiLHl0.d.ts} +8 -4
  2. package/{base-sys-abstraction-C9WW3w57.d.ts → base-sys-abstraction-Qj7pkY1N.d.cts} +8 -4
  3. package/{chunk-OXD3YZZ7.js → chunk-7KFVMTOS.js} +3 -47
  4. package/chunk-7KFVMTOS.js.map +1 -0
  5. package/{chunk-P5RXA4C4.js → chunk-GES3MUGV.js} +24 -27
  6. package/{chunk-LCPYQVWT.js.map → chunk-GES3MUGV.js.map} +1 -1
  7. package/{chunk-YDIUMYIE.js → chunk-Q65HLCNL.js} +8 -7
  8. package/chunk-Q65HLCNL.js.map +1 -0
  9. package/{chunk-DPIL5UIL.js → chunk-WMMUXBDX.js} +6 -2
  10. package/chunk-WMMUXBDX.js.map +1 -0
  11. package/{index-Dhb2fQiw.d.cts → index-Q3phXzYr.d.cts} +2 -21
  12. package/{index-CcsGcehs.d.ts → index-tIGZMHTc.d.ts} +2 -21
  13. package/index.cjs +264 -7343
  14. package/index.cjs.map +1 -1
  15. package/index.d.cts +72 -12
  16. package/index.d.ts +72 -12
  17. package/index.js +217 -7265
  18. package/index.js.map +1 -1
  19. package/node/index.cjs +220 -39
  20. package/node/index.cjs.map +1 -1
  21. package/node/index.d.cts +22 -4
  22. package/node/index.d.ts +22 -4
  23. package/node/index.js +201 -25
  24. package/node/index.js.map +1 -1
  25. package/package.json +23 -12
  26. package/src/LICENSE +201 -0
  27. package/src/README.md +39 -0
  28. package/src/base-sys-abstraction.test.ts +95 -0
  29. package/src/base-sys-abstraction.ts +242 -0
  30. package/src/bin2text.test.ts +59 -0
  31. package/src/bin2text.ts +47 -0
  32. package/src/crypto.test.ts +15 -0
  33. package/src/crypto.ts +125 -0
  34. package/src/file-service.ts +24 -0
  35. package/src/future.test.ts +32 -0
  36. package/src/future.ts +27 -0
  37. package/src/index.ts +22 -0
  38. package/src/jsr.json +20 -0
  39. package/src/log-level-impl.ts +87 -0
  40. package/src/log-writer-impl.ts +58 -0
  41. package/src/logger-impl.ts +498 -0
  42. package/src/logger.test.ts +1132 -0
  43. package/src/logger.ts +208 -0
  44. package/src/node/deno-file-service.ts +92 -0
  45. package/src/node/deno-sys-abstraction.ts +133 -0
  46. package/src/node/index.ts +4 -0
  47. package/src/node/mock-file-service.ts +45 -0
  48. package/src/node/node-file-service.ts +91 -0
  49. package/src/node/node-sys-abstraction.ts +121 -0
  50. package/src/option.ts +60 -0
  51. package/src/resolve-once.test.ts +321 -0
  52. package/src/resolve-once.ts +179 -0
  53. package/src/result.test.ts +102 -0
  54. package/src/result.ts +165 -0
  55. package/src/runtime.ts +36 -0
  56. package/src/sys-abstraction.ts +53 -0
  57. package/src/sys-env.test.ts +53 -0
  58. package/src/sys-env.ts +216 -0
  59. package/src/test/log-write-stream.ts +95 -0
  60. package/src/test/mock-logger.ts +40 -0
  61. package/src/time.ts +20 -0
  62. package/src/tracer.test.ts +314 -0
  63. package/src/tracer.ts +222 -0
  64. package/src/txt-en-decoder.ts +21 -0
  65. package/src/uri.test.ts +155 -0
  66. package/src/uri.ts +421 -0
  67. package/src/utils/console-write-stream.ts +72 -0
  68. package/src/utils/fanout-write-stream.ts +32 -0
  69. package/src/utils/index.ts +6 -0
  70. package/src/utils/rebuffer.ts +75 -0
  71. package/src/utils/stream-map.ts +67 -0
  72. package/src/utils/stream2string.ts +47 -0
  73. package/src/utils/string2stream.ts +14 -0
  74. package/src/version.ts +3 -0
  75. package/src/web/index.ts +1 -0
  76. package/src/web/web-sys-abstraction.ts +80 -0
  77. package/ts/base-sys-abstraction.d.ts +84 -0
  78. package/ts/base-sys-abstraction.d.ts.map +1 -0
  79. package/ts/base-sys-abstraction.js +178 -0
  80. package/ts/base-sys-abstraction.js.map +1 -0
  81. package/ts/base-sys-abstraction.test.d.ts +2 -0
  82. package/ts/base-sys-abstraction.test.d.ts.map +1 -0
  83. package/ts/base-sys-abstraction.test.js +82 -0
  84. package/ts/base-sys-abstraction.test.js.map +1 -0
  85. package/ts/bin2text.d.ts +3 -0
  86. package/ts/bin2text.d.ts.map +1 -0
  87. package/ts/bin2text.js +43 -0
  88. package/ts/bin2text.js.map +1 -0
  89. package/ts/bin2text.test.d.ts +2 -0
  90. package/ts/bin2text.test.d.ts.map +1 -0
  91. package/ts/bin2text.test.js +51 -0
  92. package/ts/bin2text.test.js.map +1 -0
  93. package/ts/crypto.d.ts +76 -0
  94. package/ts/crypto.d.ts.map +1 -0
  95. package/ts/crypto.js +22 -0
  96. package/ts/crypto.js.map +1 -0
  97. package/ts/crypto.test.d.ts +2 -0
  98. package/ts/crypto.test.d.ts.map +1 -0
  99. package/ts/crypto.test.js +14 -0
  100. package/ts/crypto.test.js.map +1 -0
  101. package/ts/file-service.d.ts +17 -0
  102. package/ts/file-service.d.ts.map +1 -0
  103. package/ts/file-service.js +2 -0
  104. package/ts/file-service.js.map +1 -0
  105. package/ts/future.d.ts +8 -0
  106. package/ts/future.d.ts.map +1 -0
  107. package/ts/future.js +38 -0
  108. package/ts/future.js.map +1 -0
  109. package/ts/future.test.d.ts +2 -0
  110. package/ts/future.test.d.ts.map +1 -0
  111. package/ts/future.test.js +28 -0
  112. package/ts/future.test.js.map +1 -0
  113. package/ts/index.d.ts +23 -0
  114. package/ts/index.d.ts.map +1 -0
  115. package/ts/index.js +23 -0
  116. package/ts/index.js.map +1 -0
  117. package/ts/log-level-impl.d.ts +14 -0
  118. package/ts/log-level-impl.d.ts.map +1 -0
  119. package/ts/log-level-impl.js +72 -0
  120. package/ts/log-level-impl.js.map +1 -0
  121. package/ts/log-writer-impl.d.ts +10 -0
  122. package/ts/log-writer-impl.d.ts.map +1 -0
  123. package/ts/log-writer-impl.js +45 -0
  124. package/ts/log-writer-impl.js.map +1 -0
  125. package/ts/logger-impl.d.ts +71 -0
  126. package/ts/logger-impl.d.ts.map +1 -0
  127. package/ts/logger-impl.js +412 -0
  128. package/ts/logger-impl.js.map +1 -0
  129. package/ts/logger.d.ts +84 -0
  130. package/ts/logger.d.ts.map +1 -0
  131. package/ts/logger.js +114 -0
  132. package/ts/logger.js.map +1 -0
  133. package/ts/logger.test.d.ts +2 -0
  134. package/ts/logger.test.d.ts.map +1 -0
  135. package/ts/logger.test.js +1023 -0
  136. package/ts/logger.test.js.map +1 -0
  137. package/ts/node/deno-file-service.d.ts +17 -0
  138. package/ts/node/deno-file-service.d.ts.map +1 -0
  139. package/ts/node/deno-file-service.js +65 -0
  140. package/ts/node/deno-file-service.js.map +1 -0
  141. package/ts/node/deno-sys-abstraction.d.ts +22 -0
  142. package/ts/node/deno-sys-abstraction.d.ts.map +1 -0
  143. package/ts/node/deno-sys-abstraction.js +101 -0
  144. package/ts/node/deno-sys-abstraction.js.map +1 -0
  145. package/ts/node/index.d.ts +5 -0
  146. package/ts/node/index.d.ts.map +1 -0
  147. package/ts/node/index.js +5 -0
  148. package/ts/node/index.js.map +1 -0
  149. package/ts/node/mock-file-service.d.ts +11 -0
  150. package/ts/node/mock-file-service.d.ts.map +1 -0
  151. package/ts/node/mock-file-service.js +34 -0
  152. package/ts/node/mock-file-service.js.map +1 -0
  153. package/ts/node/mock-file-service.test.d.ts +2 -0
  154. package/ts/node/mock-file-service.test.d.ts.map +1 -0
  155. package/ts/node/mock-file-service.test.js +31 -0
  156. package/ts/node/mock-file-service.test.js.map +1 -0
  157. package/ts/node/node-file-service.d.ts +16 -0
  158. package/ts/node/node-file-service.d.ts.map +1 -0
  159. package/ts/node/node-file-service.js +71 -0
  160. package/ts/node/node-file-service.js.map +1 -0
  161. package/ts/node/node-sys-abstraction.d.ts +22 -0
  162. package/ts/node/node-sys-abstraction.d.ts.map +1 -0
  163. package/ts/node/node-sys-abstraction.js +99 -0
  164. package/ts/node/node-sys-abstraction.js.map +1 -0
  165. package/ts/node/node-sys-abstraction.test.d.ts +2 -0
  166. package/ts/node/node-sys-abstraction.test.d.ts.map +1 -0
  167. package/ts/node/node-sys-abstraction.test.js +87 -0
  168. package/ts/node/node-sys-abstraction.test.js.map +1 -0
  169. package/ts/option.d.ts +25 -0
  170. package/ts/option.d.ts.map +1 -0
  171. package/ts/option.js +47 -0
  172. package/ts/option.js.map +1 -0
  173. package/ts/resolve-once.d.ts +46 -0
  174. package/ts/resolve-once.d.ts.map +1 -0
  175. package/ts/resolve-once.js +152 -0
  176. package/ts/resolve-once.js.map +1 -0
  177. package/ts/resolve-once.test.d.ts +2 -0
  178. package/ts/resolve-once.test.d.ts.map +1 -0
  179. package/ts/resolve-once.test.js +283 -0
  180. package/ts/resolve-once.test.js.map +1 -0
  181. package/ts/result.d.ts +34 -0
  182. package/ts/result.d.ts.map +1 -0
  183. package/ts/result.js +85 -0
  184. package/ts/result.js.map +1 -0
  185. package/ts/result.test.d.ts +2 -0
  186. package/ts/result.test.d.ts.map +1 -0
  187. package/ts/result.test.js +79 -0
  188. package/ts/result.test.js.map +1 -0
  189. package/ts/runtime.d.ts +8 -0
  190. package/ts/runtime.d.ts.map +1 -0
  191. package/ts/runtime.js +26 -0
  192. package/ts/runtime.js.map +1 -0
  193. package/ts/sys-abstraction.d.ts +36 -0
  194. package/ts/sys-abstraction.d.ts.map +1 -0
  195. package/ts/sys-abstraction.js +31 -0
  196. package/ts/sys-abstraction.js.map +1 -0
  197. package/ts/sys-env.d.ts +48 -0
  198. package/ts/sys-env.d.ts.map +1 -0
  199. package/ts/sys-env.js +176 -0
  200. package/ts/sys-env.js.map +1 -0
  201. package/ts/sys-env.test.d.ts +2 -0
  202. package/ts/sys-env.test.d.ts.map +1 -0
  203. package/ts/sys-env.test.js +51 -0
  204. package/ts/sys-env.test.js.map +1 -0
  205. package/ts/test/log-write-stream.d.ts +27 -0
  206. package/ts/test/log-write-stream.d.ts.map +1 -0
  207. package/ts/test/log-write-stream.js +74 -0
  208. package/ts/test/log-write-stream.js.map +1 -0
  209. package/ts/test/mock-logger.d.ts +14 -0
  210. package/ts/test/mock-logger.d.ts.map +1 -0
  211. package/ts/test/mock-logger.js +29 -0
  212. package/ts/test/mock-logger.js.map +1 -0
  213. package/ts/test/mock-logger.test.d.ts +2 -0
  214. package/ts/test/mock-logger.test.d.ts.map +1 -0
  215. package/ts/test/mock-logger.test.js +63 -0
  216. package/ts/test/mock-logger.test.js.map +1 -0
  217. package/ts/test/test-exit-handler.d.ts +2 -0
  218. package/ts/test/test-exit-handler.d.ts.map +1 -0
  219. package/ts/test/test-exit-handler.js +57 -0
  220. package/ts/test/test-exit-handler.js.map +1 -0
  221. package/ts/time.d.ts +13 -0
  222. package/ts/time.d.ts.map +1 -0
  223. package/ts/time.js +14 -0
  224. package/ts/time.js.map +1 -0
  225. package/ts/tracer.d.ts +59 -0
  226. package/ts/tracer.d.ts.map +1 -0
  227. package/ts/tracer.js +148 -0
  228. package/ts/tracer.js.map +1 -0
  229. package/ts/tracer.test.d.ts +2 -0
  230. package/ts/tracer.test.d.ts.map +1 -0
  231. package/ts/tracer.test.js +311 -0
  232. package/ts/tracer.test.js.map +1 -0
  233. package/ts/txt-en-decoder.d.ts +10 -0
  234. package/ts/txt-en-decoder.d.ts.map +1 -0
  235. package/ts/txt-en-decoder.js +15 -0
  236. package/ts/txt-en-decoder.js.map +1 -0
  237. package/ts/uri.d.ts +67 -0
  238. package/ts/uri.d.ts.map +1 -0
  239. package/ts/uri.js +283 -0
  240. package/ts/uri.js.map +1 -0
  241. package/ts/uri.test.d.ts +2 -0
  242. package/ts/uri.test.d.ts.map +1 -0
  243. package/ts/uri.test.js +119 -0
  244. package/ts/uri.test.js.map +1 -0
  245. package/ts/utils/console-write-stream.d.ts +21 -0
  246. package/ts/utils/console-write-stream.d.ts.map +1 -0
  247. package/ts/utils/console-write-stream.js +62 -0
  248. package/ts/utils/console-write-stream.js.map +1 -0
  249. package/ts/utils/fanout-write-stream.d.ts +12 -0
  250. package/ts/utils/fanout-write-stream.d.ts.map +1 -0
  251. package/ts/utils/fanout-write-stream.js +24 -0
  252. package/ts/utils/fanout-write-stream.js.map +1 -0
  253. package/ts/utils/index.d.ts +7 -0
  254. package/ts/utils/index.d.ts.map +1 -0
  255. package/ts/utils/index.js +7 -0
  256. package/ts/utils/index.js.map +1 -0
  257. package/ts/utils/rebuffer.d.ts +3 -0
  258. package/ts/utils/rebuffer.d.ts.map +1 -0
  259. package/ts/utils/rebuffer.js +60 -0
  260. package/ts/utils/rebuffer.js.map +1 -0
  261. package/ts/utils/rebuffer.test.d.ts +2 -0
  262. package/ts/utils/rebuffer.test.d.ts.map +1 -0
  263. package/ts/utils/rebuffer.test.js +77 -0
  264. package/ts/utils/rebuffer.test.js.map +1 -0
  265. package/ts/utils/stream-map.d.ts +9 -0
  266. package/ts/utils/stream-map.d.ts.map +1 -0
  267. package/ts/utils/stream-map.js +62 -0
  268. package/ts/utils/stream-map.js.map +1 -0
  269. package/ts/utils/stream-map.test.d.ts +2 -0
  270. package/ts/utils/stream-map.test.d.ts.map +1 -0
  271. package/ts/utils/stream-map.test.js +87 -0
  272. package/ts/utils/stream-map.test.js.map +1 -0
  273. package/ts/utils/stream-test-helper.d.ts +17 -0
  274. package/ts/utils/stream-test-helper.d.ts.map +1 -0
  275. package/ts/utils/stream-test-helper.js +37 -0
  276. package/ts/utils/stream-test-helper.js.map +1 -0
  277. package/ts/utils/stream2string.d.ts +3 -0
  278. package/ts/utils/stream2string.d.ts.map +1 -0
  279. package/ts/utils/stream2string.js +48 -0
  280. package/ts/utils/stream2string.js.map +1 -0
  281. package/ts/utils/stream2string.test.d.ts +2 -0
  282. package/ts/utils/stream2string.test.d.ts.map +1 -0
  283. package/ts/utils/stream2string.test.js +29 -0
  284. package/ts/utils/stream2string.test.js.map +1 -0
  285. package/ts/utils/string2stream.d.ts +4 -0
  286. package/ts/utils/string2stream.d.ts.map +1 -0
  287. package/ts/utils/string2stream.js +13 -0
  288. package/ts/utils/string2stream.js.map +1 -0
  289. package/ts/utils/string2stream.test.d.ts +2 -0
  290. package/ts/utils/string2stream.test.d.ts.map +1 -0
  291. package/ts/utils/string2stream.test.js +6 -0
  292. package/ts/utils/string2stream.test.js.map +1 -0
  293. package/ts/version.d.ts +2 -0
  294. package/ts/version.d.ts.map +1 -0
  295. package/ts/version.js +4 -0
  296. package/ts/version.js.map +1 -0
  297. package/ts/web/index.d.ts +2 -0
  298. package/ts/web/index.d.ts.map +1 -0
  299. package/ts/web/index.js +2 -0
  300. package/ts/web/index.js.map +1 -0
  301. package/ts/web/web-sys-abstraction.d.ts +4 -0
  302. package/ts/web/web-sys-abstraction.d.ts.map +1 -0
  303. package/ts/web/web-sys-abstraction.js +64 -0
  304. package/ts/web/web-sys-abstraction.js.map +1 -0
  305. package/utils/index.cjs +0 -42
  306. package/utils/index.cjs.map +1 -1
  307. package/utils/index.d.cts +1 -2
  308. package/utils/index.d.ts +1 -2
  309. package/utils/index.js +2 -7
  310. package/web/index.cjs +25 -7
  311. package/web/index.cjs.map +1 -1
  312. package/web/index.d.cts +2 -1
  313. package/web/index.d.ts +2 -1
  314. package/web/index.js +3 -3
  315. package/chunk-DPIL5UIL.js.map +0 -1
  316. package/chunk-LCPYQVWT.js +0 -21
  317. package/chunk-OXD3YZZ7.js.map +0 -1
  318. package/chunk-P5RXA4C4.js.map +0 -1
  319. package/chunk-YDIUMYIE.js.map +0 -1
@@ -0,0 +1,99 @@
1
+ import { BaseSysAbstraction, WrapperSysAbstraction, } from "../base-sys-abstraction.js";
2
+ import { NodeFileService } from "./node-file-service.js";
3
+ import { envFactory } from "../sys-env.js";
4
+ import { Utf8EnDecoderSingleton } from "../txt-en-decoder.js";
5
+ import process from "node:process";
6
+ export class NodeExitServiceImpl {
7
+ constructor() {
8
+ this._exitHandlers = [];
9
+ this.invoked = false;
10
+ this._handleExit = async () => {
11
+ if (this.invoked) {
12
+ return;
13
+ }
14
+ this.invoked = true;
15
+ for (const h of this._exitHandlers) {
16
+ try {
17
+ const ret = h.hdl();
18
+ if (typeof ret.then === "function") {
19
+ await ret;
20
+ }
21
+ }
22
+ finally {
23
+ }
24
+ }
25
+ };
26
+ process.on("unhandledRejection", (reason, p) => {
27
+ this.exit(19);
28
+ });
29
+ process.on("uncaughtException", (error) => {
30
+ this.exit(18);
31
+ });
32
+ process.on("close", () => {
33
+ this.exit(0);
34
+ });
35
+ process.on("exit", () => {
36
+ this.exit(0);
37
+ });
38
+ process.on("SIGQUIT", () => {
39
+ this.exit(3);
40
+ });
41
+ process.on("SIGINT", () => {
42
+ this.exit(2);
43
+ });
44
+ process.on("SIGTERM", () => {
45
+ this.exit(9);
46
+ });
47
+ }
48
+ injectExitHandlers(hdls) {
49
+ this._exitHandlers = hdls;
50
+ }
51
+ exit(code) {
52
+ this._handleExit()
53
+ .then(() => {
54
+ process.exit(code);
55
+ })
56
+ .catch((err) => {
57
+ console.error("ExitService: failed to handle exit", err);
58
+ process.exit(code);
59
+ });
60
+ }
61
+ }
62
+ export class NodeSystemService {
63
+ constructor() {
64
+ this._exitService = new NodeExitServiceImpl();
65
+ this._exitService.injectExitHandlers(NodeSystemService._exitHandlers);
66
+ }
67
+ Env() {
68
+ return envFactory();
69
+ }
70
+ Args() {
71
+ return process.argv;
72
+ }
73
+ OnExit(hdl) {
74
+ const id = crypto.randomUUID();
75
+ NodeSystemService._exitHandlers.push({ hdl, id });
76
+ return () => {
77
+ const idx = NodeSystemService._exitHandlers.findIndex((h) => h.id === id);
78
+ if (idx >= 0) {
79
+ NodeSystemService._exitHandlers.splice(idx, 1);
80
+ }
81
+ };
82
+ }
83
+ Exit(code) {
84
+ this._exitService.exit(code);
85
+ }
86
+ }
87
+ NodeSystemService._exitHandlers = [];
88
+ let my = undefined;
89
+ export function NodeSysAbstraction(param) {
90
+ if (!my) {
91
+ my = new BaseSysAbstraction({
92
+ TxtEnDecoder: (param === null || param === void 0 ? void 0 : param.TxtEnDecoder) || Utf8EnDecoderSingleton(),
93
+ FileSystem: new NodeFileService(),
94
+ SystemService: new NodeSystemService(),
95
+ });
96
+ }
97
+ return new WrapperSysAbstraction(my, param);
98
+ }
99
+ //# sourceMappingURL=node-sys-abstra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ys-abstraction.test.d.ts","sourceRoot":"","sources":["../../../src/node/node-sys-abstraction.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,87 @@
1
+ import { runtimeFn } from "@adviser/cement";
2
+ function exitHandler(errCode, larg, done) {
3
+ return (err, stdout, stderr) => {
4
+ if (err) {
5
+ expect(err.code).toBe(errCode);
6
+ }
7
+ if (stdout) {
8
+ const res = stdout
9
+ .toString()
10
+ .split("\n")
11
+ .filter((line) => line.trim())
12
+ .map((line) => {
13
+ const out = JSON.parse(line);
14
+ return out;
15
+ })
16
+ .map((obj) => {
17
+ delete obj.pid;
18
+ return obj;
19
+ });
20
+ expect(res).toEqual([
21
+ {
22
+ larg: larg,
23
+ },
24
+ {
25
+ larg: larg,
26
+ msg: "Called OnExit 1",
27
+ },
28
+ {
29
+ larg: larg,
30
+ msg: "Called OnExit 2",
31
+ },
32
+ ]);
33
+ done();
34
+ }
35
+ if (stderr) {
36
+ expect(stderr).toEqual({});
37
+ }
38
+ };
39
+ }
40
+ describe("node_sys", () => {
41
+ if (runtimeFn().isNodeIsh || runtimeFn().isDeno) {
42
+ let fnExec;
43
+ let execHandler = "tsx src/test/test-exit-handler.ts";
44
+ beforeAll(async () => {
45
+ if (runtimeFn().isDeno) {
46
+ const { exec } = await import("child_process");
47
+ fnExec = exec;
48
+ execHandler = "deno run --allow-net --allow-read --allow-run --unstable-sloppy-imports src/test/test-exit-handler.ts";
49
+ }
50
+ else {
51
+ const { exec } = await import("child_process");
52
+ fnExec = exec;
53
+ }
54
+ });
55
+ it("just-exit", () => {
56
+ return new Promise((done) => {
57
+ fnExec(`${execHandler} exit24`, exitHandler(24, "exit24", done));
58
+ });
59
+ });
60
+ it("throw", () => {
61
+ return new Promise((done) => {
62
+ fnExec(`${execHandler} throw`, exitHandler(19, "throw", done));
63
+ });
64
+ });
65
+ it("via sigint", () => {
66
+ return new Promise((done) => {
67
+ fnExec(`${execHandler} sigint`, exitHandler(2, "sigint", done));
68
+ });
69
+ });
70
+ it("via sigterm", () => {
71
+ return new Promise((done) => {
72
+ fnExec(`${execHandler} sigterm`, exitHandler(9, "sigterm", done));
73
+ });
74
+ });
75
+ it("via sigquit", () => {
76
+ return new Promise((done) => {
77
+ fnExec(`${execHandler} sigquit`, exitHandler(3, "sigquit", done));
78
+ });
79
+ });
80
+ }
81
+ else {
82
+ it.skip("nothing in browser", () => {
83
+ expect(true).toBe(true);
84
+ });
85
+ }
86
+ });
87
+ //# sourceMappingURL=node-sys-abstraction.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-sys-abstraction.test.js","sourceRoot":"","sources":["../../../src/node/node-sys-abstraction.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,SAAS,WAAW,CAAC,OAAe,EAAE,IAAY,EAAE,IAAgB;IAClE,OAAO,CAAC,GAAyB,EAAE,MAAuB,EAAE,MAAuB,EAAQ,EAAE;QAC3F,IAAI,GAAG,EAAE,CAAC;YACR,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACjC,CAAC;QACD,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,GAAG,GAAG,MAAM;iBACf,QAAQ,EAAE;iBACV,KAAK,CAAC,IAAI,CAAC;iBACX,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;iBAC7B,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;gBACZ,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBAC7B,OAAO,GAAG,CAAC;YACb,CAAC,CAAC;iBACD,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;gBACX,OAAO,GAAG,CAAC,GAAG,CAAC;gBACf,OAAO,GAAG,CAAC;YACb,CAAC,CAAC,CAAC;YACL,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC;gBAClB;oBACE,IA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T>(t: unknown): t is Option<T>;
5
+ IsNone(): boolean;
6
+ IsSome(): boolean;
7
+ Unwrap(): T;
8
+ abstract is_none(): boolean;
9
+ abstract is_some(): boolean;
10
+ abstract unwrap(): T;
11
+ }
12
+ export declare class Some<T> extends Option<T> {
13
+ private _t;
14
+ constructor(_t: T);
15
+ is_none(): boolean;
16
+ is_some(): boolean;
17
+ unwrap(): T;
18
+ }
19
+ export declare class None<T> extends Option<T> {
20
+ is_none(): boolean;
21
+ is_some(): boolean;
22
+ unwrap(): T;
23
+ }
24
+ export type WithoutOption<T> = T extends Option<infer U> ? U : T;
25
+ //# sourceMappingURL=option.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"option.d.ts","sourceRoot":"","sources":["../../src/option.ts"],"names":[],"mappings":"AAAA,8BAAsB,MAAM,CAAC,CAAC;IAC5B,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;IAI/B,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC;IAI3B,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC;IAIxC,MAAM,IAAI,OAAO;IAIjB,MAAM,IAAI,OAAO;IAGjB,MAAM,IAAI,CAAC;IAIX,QAAQ,CAAC,OAAO,IAAI,OAAO;IAC3B,QAAQ,CAAC,OAAO,IAAI,OAAO;IAC3B,QAAQ,CAAC,MAAM,IAAI,CAAC;CACrB;AAED,qBAAa,IAAI,CAAC,CAAC,CAAE,SAAQ,MAAM,CAAC,CAAC,CAAC;IACpC,OAAO,CAAC,EAAE,CAAI;gBACF,EAAE,EAAE,CAAC;IAKjB,OAAO,IAAI,OAAO;IAGlB,OAAO,IAAI,OAAO;IAGlB,MAAM,IAAI,CAAC;CAGZ;AAED,qBAAa,IAAI,CAAC,CAAC,CAAE,SAAQ,MAAM,CAAC,CAAC,CAAC;IACpC,OAAO,IAAI,OAAO;IAGlB,OAAO,IAAI,OAAO;IAGlB,MAAM,IAAI,CAAC;CAGZ;AAED,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC"}
package/ts/option.js ADDED
@@ -0,0 +1,47 @@
1
+ export class Option {
2
+ static Some(t) {
3
+ return new Some(t);
4
+ }
5
+ static None() {
6
+ return new None();
7
+ }
8
+ static Is(t) {
9
+ return t instanceof Option;
10
+ }
11
+ IsNone() {
12
+ return this.is_none();
13
+ }
14
+ IsSome() {
15
+ return this.is_some();
16
+ }
17
+ Unwrap() {
18
+ return this.unwrap();
19
+ }
20
+ }
21
+ export class Some extends Option {
22
+ constructor(_t) {
23
+ super();
24
+ this._t = _t;
25
+ }
26
+ is_none() {
27
+ return false;
28
+ }
29
+ is_some() {
30
+ return true;
31
+ }
32
+ unwrap() {
33
+ return this._t;
34
+ }
35
+ }
36
+ export class None extends Option {
37
+ is_none() {
38
+ return true;
39
+ }
40
+ is_some() {
41
+ return false;
42
+ }
43
+ unwrap() {
44
+ throw new Error("None.unwrap");
45
+ }
46
+ }
47
+ //# sourceMappingURL=option.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"option.js","sourceRoot":"","sources":["../../src/option.ts"],"names":[],"mappings":"AAAA,MAAM,OAAgB,MAAM;IAC1B,MAAM,CAAC,IAAI,CAAI,CAAI;QACjB,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;IACrB,CAAC;IAED,MAAM,CAAC,IAAI;QACT,OAAO,IAAI,IAAI,EAAE,CAAC;IACpB,CAAC;IAED,MAAM,CAAC,EAAE,CAAI,CAAU;QACrB,OAAO,CAAC,YAAY,MAAM,CAAC;IAC7B,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;IACD,MAAM;QACJ,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;CAKF;AAED,MAAM,OAAO,IAAQ,SAAQ,MAAS;IAEpC,YAAY,EAAK;QACf,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACf,CAAC;IAED,OAAO;QACL,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO;QACL,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM;QACJ,OAAO,IAAI,CAAC,EAAE,CAAC;IACjB,CAAC;CACF;AAED,MAAM,OAAO,IAAQ,SAAQ,MAAS;IACpC,OAAO;QACL,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO;QACL,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM;QACJ,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;IACjC,CAAC;CACF"}
@@ -0,0 +1,46 @@
1
+ import { Future } from "./future.js";
2
+ interface ResolveSeqItem<T, C> {
3
+ readonly future: Future<T>;
4
+ readonly fn: (c: C) => Promise<T>;
5
+ readonly id?: number;
6
+ }
7
+ export declare class ResolveSeq<T, C = void> {
8
+ readonly ctx: C;
9
+ constructor(ctx?: C);
10
+ reset(): void;
11
+ _step(item?: ResolveSeqItem<T, C> | undefined): Promise<void>;
12
+ readonly _seqFutures: ResolveSeqItem<T, C>[];
13
+ add(fn: (c: C) => Promise<T>, id?: number): Promise<T>;
14
+ }
15
+ export declare class ResolveOnce<T, CTX = void> {
16
+ _onceDone: boolean;
17
+ readonly _onceFutures: Future<T>[];
18
+ _onceOk: boolean;
19
+ _onceValue?: T;
20
+ _onceError?: Error;
21
+ _isPromise: boolean;
22
+ readonly ctx: CTX;
23
+ constructor(ctx?: CTX);
24
+ get ready(): boolean;
25
+ reset(): void;
26
+ once<R>(fn: (c: CTX) => R): R;
27
+ }
28
+ export declare class Keyed<T extends {
29
+ reset: () => void;
30
+ }, K = string> {
31
+ private readonly _map;
32
+ readonly factory: (key: K) => T;
33
+ constructor(factory: (key: K) => T);
34
+ asyncGet(key: () => Promise<K>): Promise<T>;
35
+ get(key: K | (() => K)): T;
36
+ unget(key: K): void;
37
+ reset(): void;
38
+ }
39
+ export declare class KeyedResolvOnce<T, K = string> extends Keyed<ResolveOnce<T, K>, K> {
40
+ constructor();
41
+ }
42
+ export declare class KeyedResolvSeq<T, K = string> extends Keyed<ResolveSeq<T, K>, K> {
43
+ constructor();
44
+ }
45
+ export {};
46
+ //# sourceMappingURL=resolve-once.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-once.d.ts","sourceRoot":"","sources":["../../src/resolve-once.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,UAAU,cAAc,CAAC,CAAC,EAAE,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAC3B,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAClC,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,UAAU,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI;IACjC,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;gBACJ,GAAG,CAAC,EAAE,CAAC;IAGnB,KAAK,IAAI,IAAI;IAGP,KAAK,CAAC,IAAI,CAAC,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAcnE,QAAQ,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAM;IAC5C,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,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GAAG,MAAM,CAAE,SAAQ,KAAK,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;;CAI5E"}
@@ -0,0 +1,152 @@
1
+ import { Future } from "./future.js";
2
+ export class ResolveSeq {
3
+ constructor(ctx) {
4
+ this._seqFutures = [];
5
+ this.ctx = ctx;
6
+ }
7
+ reset() {
8
+ }
9
+ async _step(item) {
10
+ if (!item) {
11
+ return;
12
+ }
13
+ item
14
+ .fn(this.ctx)
15
+ .then((value) => item.future.resolve(value))
16
+ .catch((e) => item.future.reject(e))
17
+ .finally(() => {
18
+ this._seqFutures.shift();
19
+ this._step(this._seqFutures[0]);
20
+ });
21
+ }
22
+ async add(fn, id) {
23
+ const future = new Future();
24
+ this._seqFutures.push({ future, fn, id });
25
+ if (this._seqFutures.length === 1) {
26
+ this._step(this._seqFutures[0]);
27
+ }
28
+ return future.asPromise();
29
+ }
30
+ }
31
+ export class ResolveOnce {
32
+ constructor(ctx) {
33
+ this._onceDone = false;
34
+ this._onceFutures = [];
35
+ this._onceOk = false;
36
+ this._isPromise = false;
37
+ this.ctx = ctx;
38
+ }
39
+ get ready() {
40
+ return this._onceDone;
41
+ }
42
+ reset() {
43
+ this._onceDone = false;
44
+ this._onceOk = false;
45
+ this._onceValue = undefined;
46
+ this._onceError = undefined;
47
+ this._onceFutures.length = 0;
48
+ }
49
+ once(fn) {
50
+ if (this._onceDone) {
51
+ if (this._onceError) {
52
+ if (this._isPromise) {
53
+ return Promise.reject(this._onceError);
54
+ }
55
+ else {
56
+ throw this._onceError;
57
+ }
58
+ }
59
+ if (this._onceOk) {
60
+ if (this._isPromise) {
61
+ return Promise.resolve(this._onceValue);
62
+ }
63
+ else {
64
+ return this._onceValue;
65
+ }
66
+ }
67
+ throw new Error("ResolveOnce.once impossible");
68
+ }
69
+ const future = new Future();
70
+ this._onceFutures.push(future);
71
+ if (this._onceFutures.length === 1) {
72
+ const okFn = (value) => {
73
+ this._onceValue = value;
74
+ this._onceOk = true;
75
+ this._onceDone = true;
76
+ if (this._isPromise) {
77
+ this._onceFutures.forEach((f) => f.resolve(this._onceValue));
78
+ }
79
+ this._onceFutures.length = 0;
80
+ };
81
+ const catchFn = (e) => {
82
+ this._onceError = e;
83
+ this._onceOk = false;
84
+ this._onceValue = undefined;
85
+ this._onceDone = true;
86
+ if (this._isPromise) {
87
+ this._onceFutures.forEach((f) => f.reject(this._onceError));
88
+ }
89
+ this._onceFutures.length = 0;
90
+ };
91
+ try {
92
+ const ret = fn(this.ctx);
93
+ if (typeof ret.then === "function") {
94
+ this._isPromise = true;
95
+ ret.then(okFn).catch(catchFn);
96
+ }
97
+ else {
98
+ okFn(ret);
99
+ }
100
+ }
101
+ catch (e) {
102
+ catchFn(e);
103
+ }
104
+ }
105
+ if (this._isPromise) {
106
+ return future.asPromise();
107
+ }
108
+ else {
109
+ return this.once(fn);
110
+ }
111
+ }
112
+ }
113
+ export class Keyed {
114
+ constructor(factory) {
115
+ this._map = new Map();
116
+ this.factory = factory;
117
+ }
118
+ async asyncGet(key) {
119
+ return this.get(await key());
120
+ }
121
+ get(key) {
122
+ if (typeof key === "function") {
123
+ key = key();
124
+ }
125
+ let keyed = this._map.get(key);
126
+ if (!keyed) {
127
+ keyed = this.factory(key);
128
+ this._map.set(key, keyed);
129
+ }
130
+ return keyed;
131
+ }
132
+ unget(key) {
133
+ const keyed = this._map.get(key);
134
+ keyed === null || keyed === void 0 ? void 0 : keyed.reset();
135
+ this._map.delete(key);
136
+ }
137
+ reset() {
138
+ this._map.forEach((keyed) => keyed.reset());
139
+ this._map.clear();
140
+ }
141
+ }
142
+ export class KeyedResolvOnce extends Keyed {
143
+ constructor() {
144
+ super((key) => new ResolveOnce(key));
145
+ }
146
+ }
147
+ export class KeyedResolvSeq extends Keyed {
148
+ constructor() {
149
+ super((key) => new ResolveSeq(key));
150
+ }
151
+ }
152
+ //# sourceMappingURL=resolve-once.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-once.js","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,EAAE,CAAC;QACf,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;QAC5C,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;CACF;AAED,MAAM,OAAO,eAA+B,SAAQ,KAA2B;IAC7E;QACE,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,WAAW,CAAO,GAAG,CAAC,CAAC,CAAC;IAC7C,CAAC;CACF;AAED,MAAM,OAAO,cAA8B,SAAQ,KAA0B;IAC3E;QACE,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,UAAU,CAAO,GAAG,CAAC,CAAC,CAAC;IAC5C,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=resolve-once.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-once.test.d.ts","sourceRoot":"","sources":["../../src/resolve-once.test.ts"],"names":[],"mappings":""}