@adviser/cement 0.0.1
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/adviser-cement-0.0.1.tgz +0 -0
- package/file_service.d.ts +17 -0
- package/file_service.d.ts.map +1 -0
- package/file_service.js +3 -0
- package/file_service.js.map +1 -0
- package/index.d.ts +10 -0
- package/index.d.ts.map +1 -0
- package/index.js +26 -0
- package/index.js.map +1 -0
- package/logger.d.ts +31 -0
- package/logger.d.ts.map +1 -0
- package/logger.js +11 -0
- package/logger.js.map +1 -0
- package/logger.test.d.ts +2 -0
- package/logger.test.d.ts.map +1 -0
- package/logger.test.js +228 -0
- package/logger.test.js.map +1 -0
- package/logger_impl.d.ts +46 -0
- package/logger_impl.d.ts.map +1 -0
- package/logger_impl.js +260 -0
- package/logger_impl.js.map +1 -0
- package/mock_file_service.d.ts +20 -0
- package/mock_file_service.d.ts.map +1 -0
- package/mock_file_service.js +80 -0
- package/mock_file_service.js.map +1 -0
- package/node_file_service.d.ts +15 -0
- package/node_file_service.d.ts.map +1 -0
- package/node_file_service.js +78 -0
- package/node_file_service.js.map +1 -0
- package/node_sys_abstraction.d.ts +91 -0
- package/node_sys_abstraction.d.ts.map +1 -0
- package/node_sys_abstraction.js +265 -0
- package/node_sys_abstraction.js.map +1 -0
- package/node_sys_abstraction.test.d.ts +2 -0
- package/node_sys_abstraction.test.d.ts.map +1 -0
- package/node_sys_abstraction.test.js +123 -0
- package/node_sys_abstraction.test.js.map +1 -0
- package/package.json +40 -0
- package/sys_abstraction.d.ts +35 -0
- package/sys_abstraction.d.ts.map +1 -0
- package/sys_abstraction.js +35 -0
- package/sys_abstraction.js.map +1 -0
- package/test/log_collector.d.ts +22 -0
- package/test/log_collector.d.ts.map +1 -0
- package/test/log_collector.js +65 -0
- package/test/log_collector.js.map +1 -0
- package/test/mock_logger.d.ts +13 -0
- package/test/mock_logger.d.ts.map +1 -0
- package/test/mock_logger.js +23 -0
- package/test/mock_logger.js.map +1 -0
- package/test/mock_logger.test.d.ts +2 -0
- package/test/mock_logger.test.d.ts.map +1 -0
- package/test/mock_logger.test.js +49 -0
- package/test/mock_logger.test.js.map +1 -0
- package/test/test-exit-handler.d.ts +1 -0
- package/test/test-exit-handler.d.ts.map +1 -0
- package/test/test-exit-handler.js +76 -0
- package/test/test-exit-handler.js.map +1 -0
- package/time.d.ts +13 -0
- package/time.d.ts.map +1 -0
- package/time.js +18 -0
- package/time.js.map +1 -0
@@ -0,0 +1,265 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.NodeSysAbstraction = exports.NodeSystemService = exports.ExitServiceImpl = exports.IdService = exports.RandomService = exports.TimeFactory = exports.StepTime = exports.ConstTime = void 0;
|
4
|
+
const sys_abstraction_1 = require("./sys_abstraction");
|
5
|
+
const node_file_service_1 = require("./node_file_service");
|
6
|
+
const time_1 = require("./time");
|
7
|
+
class SysTime extends time_1.Time {
|
8
|
+
Now() {
|
9
|
+
return new Date();
|
10
|
+
}
|
11
|
+
Sleep(duration) {
|
12
|
+
return new Promise((resolve) => {
|
13
|
+
setTimeout(() => {
|
14
|
+
resolve();
|
15
|
+
}, duration);
|
16
|
+
});
|
17
|
+
}
|
18
|
+
}
|
19
|
+
class ConstTime extends time_1.Time {
|
20
|
+
Now() {
|
21
|
+
return new Date(2021, 1, 1, 0, 0, 0, 0);
|
22
|
+
}
|
23
|
+
Sleep(duration) {
|
24
|
+
return Promise.resolve();
|
25
|
+
}
|
26
|
+
}
|
27
|
+
exports.ConstTime = ConstTime;
|
28
|
+
class StepTime extends time_1.Time {
|
29
|
+
constructor() {
|
30
|
+
super();
|
31
|
+
this._step = new ConstTime().Now();
|
32
|
+
}
|
33
|
+
Now() {
|
34
|
+
if (this._step.getTime() === 0) {
|
35
|
+
this._step = new ConstTime().Now();
|
36
|
+
return this._step;
|
37
|
+
}
|
38
|
+
this._step = new Date(this._step.getTime() + 1000);
|
39
|
+
return this._step;
|
40
|
+
}
|
41
|
+
Sleep(duration) {
|
42
|
+
this._step = new Date(this._step.getTime() + duration);
|
43
|
+
return Promise.resolve();
|
44
|
+
}
|
45
|
+
}
|
46
|
+
exports.StepTime = StepTime;
|
47
|
+
function TimeFactory(timeMode) {
|
48
|
+
switch (timeMode) {
|
49
|
+
case sys_abstraction_1.TimeMode.REAL:
|
50
|
+
return new SysTime();
|
51
|
+
case sys_abstraction_1.TimeMode.CONST:
|
52
|
+
return new ConstTime();
|
53
|
+
case sys_abstraction_1.TimeMode.STEP:
|
54
|
+
return new StepTime();
|
55
|
+
}
|
56
|
+
return new SysTime();
|
57
|
+
}
|
58
|
+
exports.TimeFactory = TimeFactory;
|
59
|
+
const decoder = new TextDecoder();
|
60
|
+
class RandomService {
|
61
|
+
constructor(mode) {
|
62
|
+
this._step = 0;
|
63
|
+
this._mode = mode;
|
64
|
+
}
|
65
|
+
Random0ToValue(value) {
|
66
|
+
switch (this._mode) {
|
67
|
+
case sys_abstraction_1.RandomMode.CONST:
|
68
|
+
return 0.5 * value;
|
69
|
+
case sys_abstraction_1.RandomMode.STEP:
|
70
|
+
this._step += 0.0001;
|
71
|
+
return this._step * value;
|
72
|
+
case sys_abstraction_1.RandomMode.RANDOM:
|
73
|
+
return Math.random() * value;
|
74
|
+
default:
|
75
|
+
throw new Error("Unknown RandomMode");
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
79
|
+
exports.RandomService = RandomService;
|
80
|
+
class IdService {
|
81
|
+
constructor(mode) {
|
82
|
+
this._step = 0;
|
83
|
+
if (!mode) {
|
84
|
+
mode = sys_abstraction_1.IDMode.UUID;
|
85
|
+
}
|
86
|
+
this._mode = mode;
|
87
|
+
}
|
88
|
+
NextId() {
|
89
|
+
switch (this._mode) {
|
90
|
+
case sys_abstraction_1.IDMode.UUID:
|
91
|
+
return crypto.randomUUID();
|
92
|
+
case sys_abstraction_1.IDMode.CONST:
|
93
|
+
return "VeryUniqueID";
|
94
|
+
case sys_abstraction_1.IDMode.STEP:
|
95
|
+
return `STEPId-${this._step++}`;
|
96
|
+
default:
|
97
|
+
throw new Error("Unknown IDMode");
|
98
|
+
}
|
99
|
+
}
|
100
|
+
}
|
101
|
+
exports.IdService = IdService;
|
102
|
+
class ExitServiceImpl {
|
103
|
+
constructor() {
|
104
|
+
this._exitHandlers = [];
|
105
|
+
this.invoked = false;
|
106
|
+
this._handleExit = async () => {
|
107
|
+
if (this.invoked) {
|
108
|
+
return;
|
109
|
+
}
|
110
|
+
this.invoked = true;
|
111
|
+
for (const h of this._exitHandlers) {
|
112
|
+
try {
|
113
|
+
const ret = h.hdl();
|
114
|
+
if (typeof ret.then === "function") {
|
115
|
+
await ret;
|
116
|
+
}
|
117
|
+
}
|
118
|
+
finally {
|
119
|
+
}
|
120
|
+
}
|
121
|
+
};
|
122
|
+
process.on("unhandledRejection", (reason, p) => {
|
123
|
+
this.exit(19);
|
124
|
+
});
|
125
|
+
process.on("uncaughtException", (error) => {
|
126
|
+
this.exit(18);
|
127
|
+
});
|
128
|
+
process.on("close", () => {
|
129
|
+
this.exit(0);
|
130
|
+
});
|
131
|
+
process.on("exit", () => {
|
132
|
+
this.exit(0);
|
133
|
+
});
|
134
|
+
process.on("SIGQUIT", () => {
|
135
|
+
this.exit(3);
|
136
|
+
});
|
137
|
+
process.on("SIGINT", () => {
|
138
|
+
this.exit(2);
|
139
|
+
});
|
140
|
+
process.on("SIGTERM", () => {
|
141
|
+
this.exit(9);
|
142
|
+
});
|
143
|
+
}
|
144
|
+
injectExitHandlers(hdls) {
|
145
|
+
this._exitHandlers = hdls;
|
146
|
+
}
|
147
|
+
exit(code) {
|
148
|
+
this._handleExit()
|
149
|
+
.then(() => {
|
150
|
+
process.exit(code);
|
151
|
+
})
|
152
|
+
.catch((err) => {
|
153
|
+
console.error("ExitService: failed to handle exit", err);
|
154
|
+
process.exit(code);
|
155
|
+
});
|
156
|
+
}
|
157
|
+
}
|
158
|
+
exports.ExitServiceImpl = ExitServiceImpl;
|
159
|
+
class NodeSystemService {
|
160
|
+
constructor() {
|
161
|
+
this._exitService = new ExitServiceImpl();
|
162
|
+
this._exitService.injectExitHandlers(NodeSystemService._exitHandlers);
|
163
|
+
}
|
164
|
+
Env() {
|
165
|
+
return process.env;
|
166
|
+
}
|
167
|
+
Args() {
|
168
|
+
return process.argv;
|
169
|
+
}
|
170
|
+
OnExit(hdl) {
|
171
|
+
const id = crypto.randomUUID();
|
172
|
+
NodeSystemService._exitHandlers.push({ hdl, id });
|
173
|
+
return () => {
|
174
|
+
const idx = NodeSystemService._exitHandlers.findIndex((h) => h.id === id);
|
175
|
+
if (idx >= 0) {
|
176
|
+
NodeSystemService._exitHandlers.splice(idx, 1);
|
177
|
+
}
|
178
|
+
};
|
179
|
+
}
|
180
|
+
Exit(code) {
|
181
|
+
this._exitService.exit(code);
|
182
|
+
}
|
183
|
+
}
|
184
|
+
exports.NodeSystemService = NodeSystemService;
|
185
|
+
NodeSystemService._exitHandlers = [];
|
186
|
+
class NodeSysAbstraction {
|
187
|
+
constructor(params) {
|
188
|
+
this._time = NodeSysAbstraction._time;
|
189
|
+
this._stdout = NodeSysAbstraction._stdout;
|
190
|
+
this._stderr = NodeSysAbstraction._stderr;
|
191
|
+
this._idService = NodeSysAbstraction._idService;
|
192
|
+
this._randomService = NodeSysAbstraction._randomService;
|
193
|
+
this._fileSystem = NodeSysAbstraction._fileSystem;
|
194
|
+
this._systemService = NodeSysAbstraction._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() {
|
220
|
+
return this._time;
|
221
|
+
}
|
222
|
+
NextId() {
|
223
|
+
return this._idService.NextId();
|
224
|
+
}
|
225
|
+
Random0ToValue(value) {
|
226
|
+
return this._randomService.Random0ToValue(value);
|
227
|
+
}
|
228
|
+
Stdout() {
|
229
|
+
return this._stdout;
|
230
|
+
}
|
231
|
+
Stderr() {
|
232
|
+
return this._stderr;
|
233
|
+
}
|
234
|
+
System() {
|
235
|
+
return this._systemService;
|
236
|
+
}
|
237
|
+
FileSystem() {
|
238
|
+
return this._fileSystem;
|
239
|
+
}
|
240
|
+
}
|
241
|
+
exports.NodeSysAbstraction = NodeSysAbstraction;
|
242
|
+
NodeSysAbstraction._time = new SysTime();
|
243
|
+
NodeSysAbstraction._stdout = new WritableStream({
|
244
|
+
write(chunk) {
|
245
|
+
return new Promise((resolve) => {
|
246
|
+
const decoded = decoder.decode(chunk);
|
247
|
+
console.log(decoded.trimEnd());
|
248
|
+
resolve();
|
249
|
+
});
|
250
|
+
},
|
251
|
+
});
|
252
|
+
NodeSysAbstraction._stderr = new WritableStream({
|
253
|
+
write(chunk) {
|
254
|
+
return new Promise((resolve) => {
|
255
|
+
const decoded = decoder.decode(chunk);
|
256
|
+
console.error(decoded.trimEnd());
|
257
|
+
resolve();
|
258
|
+
});
|
259
|
+
},
|
260
|
+
});
|
261
|
+
NodeSysAbstraction._idService = new IdService();
|
262
|
+
NodeSysAbstraction._randomService = new RandomService(sys_abstraction_1.RandomMode.RANDOM);
|
263
|
+
NodeSysAbstraction._fileSystem = new node_file_service_1.NodeFileService();
|
264
|
+
NodeSysAbstraction._systemService = new NodeSystemService();
|
265
|
+
//# sourceMappingURL=node_sys_abstraction.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{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
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const sys_abstraction_1 = require("./sys_abstraction");
|
4
|
+
const node_sys_abstraction_1 = require("./node_sys_abstraction");
|
5
|
+
const node_child_process_1 = require("node:child_process");
|
6
|
+
it("IdService UUID", () => {
|
7
|
+
const sys = new node_sys_abstraction_1.NodeSysAbstraction();
|
8
|
+
const id1 = sys.NextId();
|
9
|
+
const id2 = sys.NextId();
|
10
|
+
expect(id1).not.toEqual(id2);
|
11
|
+
});
|
12
|
+
it("IdService explict UUID", () => {
|
13
|
+
const sys = new node_sys_abstraction_1.NodeSysAbstraction({ IdMode: sys_abstraction_1.IDMode.UUID });
|
14
|
+
const id1 = sys.NextId();
|
15
|
+
const id2 = sys.NextId();
|
16
|
+
expect(id1).not.toEqual(id2);
|
17
|
+
});
|
18
|
+
it("IdService const", () => {
|
19
|
+
const sys = new node_sys_abstraction_1.NodeSysAbstraction({ IdMode: sys_abstraction_1.IDMode.CONST });
|
20
|
+
const id1 = sys.NextId();
|
21
|
+
const id2 = sys.NextId();
|
22
|
+
expect(id1).toEqual(id2);
|
23
|
+
});
|
24
|
+
it("IdService set", () => {
|
25
|
+
for (let i = 0; i < 10; i++) {
|
26
|
+
const sys = new node_sys_abstraction_1.NodeSysAbstraction({ IdMode: sys_abstraction_1.IDMode.STEP });
|
27
|
+
const id1 = sys.NextId();
|
28
|
+
const id2 = sys.NextId();
|
29
|
+
expect(id1).toEqual("STEPId-0");
|
30
|
+
expect(id2).toEqual("STEPId-1");
|
31
|
+
}
|
32
|
+
});
|
33
|
+
it("time sleep", async () => {
|
34
|
+
const sys = new node_sys_abstraction_1.NodeSysAbstraction();
|
35
|
+
const start = sys.Time().Now();
|
36
|
+
await sys.Time().Sleep(100);
|
37
|
+
expect(sys.Time().TimeSince(start)).toBeGreaterThan(90);
|
38
|
+
});
|
39
|
+
it("time sleep const", async () => {
|
40
|
+
const sys = new node_sys_abstraction_1.NodeSysAbstraction({ TimeMode: sys_abstraction_1.TimeMode.REAL });
|
41
|
+
const start = new Date();
|
42
|
+
await sys.Time().Sleep(100);
|
43
|
+
const end = new Date();
|
44
|
+
expect(end.getTime() - start.getTime()).toBeGreaterThan(90);
|
45
|
+
});
|
46
|
+
it("time sleep step", async () => {
|
47
|
+
const sys = new node_sys_abstraction_1.NodeSysAbstraction({ TimeMode: sys_abstraction_1.TimeMode.STEP });
|
48
|
+
const start = sys.Time().Now();
|
49
|
+
await sys.Time().Sleep(86400500);
|
50
|
+
expect(sys.Time().Now().getTime() - start.getTime()).toEqual(86401500);
|
51
|
+
});
|
52
|
+
it("const random", () => {
|
53
|
+
const sys = new node_sys_abstraction_1.NodeSysAbstraction({ RandomMode: sys_abstraction_1.RandomMode.CONST });
|
54
|
+
expect(sys.Random0ToValue(10)).toEqual(5);
|
55
|
+
expect(sys.Random0ToValue(10)).toEqual(5);
|
56
|
+
});
|
57
|
+
it("step random", () => {
|
58
|
+
const sys = new node_sys_abstraction_1.NodeSysAbstraction({ RandomMode: sys_abstraction_1.RandomMode.STEP });
|
59
|
+
expect(sys.Random0ToValue(10000)).toEqual(1);
|
60
|
+
expect(sys.Random0ToValue(10000)).toEqual(2);
|
61
|
+
});
|
62
|
+
it("random", () => {
|
63
|
+
const sys = new node_sys_abstraction_1.NodeSysAbstraction({});
|
64
|
+
for (let i = 0; i < 100; i++) {
|
65
|
+
const val = sys.Random0ToValue(10);
|
66
|
+
expect(val).toBeGreaterThanOrEqual(0);
|
67
|
+
expect(val).toBeLessThanOrEqual(10);
|
68
|
+
}
|
69
|
+
});
|
70
|
+
function exitHandler(errCode, larg, done) {
|
71
|
+
return (err, stdout, stderr) => {
|
72
|
+
if (err) {
|
73
|
+
expect(err.code).toBe(errCode);
|
74
|
+
}
|
75
|
+
if (stdout) {
|
76
|
+
const res = stdout
|
77
|
+
.toString()
|
78
|
+
.split("\n")
|
79
|
+
.filter((line) => line.trim())
|
80
|
+
.map((line) => {
|
81
|
+
const out = JSON.parse(line);
|
82
|
+
return out;
|
83
|
+
})
|
84
|
+
.map((obj) => {
|
85
|
+
delete obj.pid;
|
86
|
+
return obj;
|
87
|
+
});
|
88
|
+
expect(res).toEqual([
|
89
|
+
{
|
90
|
+
larg: larg,
|
91
|
+
},
|
92
|
+
{
|
93
|
+
larg: larg,
|
94
|
+
msg: "Called OnExit 1",
|
95
|
+
},
|
96
|
+
{
|
97
|
+
larg: larg,
|
98
|
+
msg: "Called OnExit 2",
|
99
|
+
},
|
100
|
+
]);
|
101
|
+
done();
|
102
|
+
}
|
103
|
+
if (stderr) {
|
104
|
+
expect(stderr).toEqual({});
|
105
|
+
}
|
106
|
+
};
|
107
|
+
}
|
108
|
+
it("just-exit", (done) => {
|
109
|
+
(0, node_child_process_1.exec)("ts-node src/test/test-exit-handler.ts exit24", exitHandler(24, "exit24", done));
|
110
|
+
});
|
111
|
+
it("throw", (done) => {
|
112
|
+
(0, node_child_process_1.exec)("ts-node src/test/test-exit-handler.ts throw", exitHandler(19, "throw", done));
|
113
|
+
});
|
114
|
+
it("via sigint", (done) => {
|
115
|
+
(0, node_child_process_1.exec)("ts-node src/test/test-exit-handler.ts sigint", exitHandler(2, "sigint", done));
|
116
|
+
});
|
117
|
+
it("via sigterm", (done) => {
|
118
|
+
(0, node_child_process_1.exec)("ts-node src/test/test-exit-handler.ts sigterm", exitHandler(9, "sigterm", done));
|
119
|
+
});
|
120
|
+
it("via sigquit", (done) => {
|
121
|
+
(0, node_child_process_1.exec)("ts-node src/test/test-exit-handler.ts sigquit", exitHandler(3, "sigquit", done));
|
122
|
+
});
|
123
|
+
//# sourceMappingURL=node_sys_abstraction.test.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"node_sys_abstraction.test.js","sourceRoot":"","sources":["../src/node_sys_abstraction.test.ts"],"names":[],"mappings":";;AAAA,uDAAiE;AACjE,iEAA4D;AAC5D,2DAAyD;AAEzD,EAAE,CAAC,gBAAgB,EAAE,GAAG,EAAE;IACxB,MAAM,GAA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E,CAAC;YACX,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED,EAAE,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,EAAE;IACvB,IAAA,yBAAI,EAAC,8CAA8C,EAAE,WAAW,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC;AACxF,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;IACnB,IAAA,yBAAI,EAAC,6CAA6C,EAAE,WAAW,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;AACtF,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE;IACxB,IAAA,yBAAI,EAAC,8CAA8C,EAAE,WAAW,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC;AACvF,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,aAAa,EAAE,CAAC,IAAI,EAAE,EAAE;IACzB,IAAA,yBAAI,EAAC,+CAA+C,EAAE,WAAW,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;AACzF,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,aAAa,EAAE,CAAC,IAAI,EAAE,EAAE;IACzB,IAAA,yBAAI,EAAC,+CAA+C,EAAE,WAAW,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;AACzF,CAAC,CAAC,CAAC"}
|
package/package.json
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
{
|
2
|
+
"name": "@adviser/cement",
|
3
|
+
"version": "0.0.1",
|
4
|
+
"description": "better try/catch/finally handling",
|
5
|
+
"main": "index.js",
|
6
|
+
"keywords": [],
|
7
|
+
"author": "Meno Abels <meno.abels@adviser.com>",
|
8
|
+
"license": "AFL-2.0",
|
9
|
+
"bugs": {
|
10
|
+
"url": "https://github.com/mabels/cement/issues"
|
11
|
+
},
|
12
|
+
"homepage": "https://github.com/mabels/cement#readme",
|
13
|
+
"devDependencies": {
|
14
|
+
"@types/jest": "^29.5.11",
|
15
|
+
"@types/node": "^20.11.13",
|
16
|
+
"@typescript-eslint/eslint-plugin": "^6.20.0",
|
17
|
+
"@typescript-eslint/parser": "^6.20.0",
|
18
|
+
"eslint": "^8.56.0",
|
19
|
+
"jest": "^29.7.0",
|
20
|
+
"prettier": "^3.2.4",
|
21
|
+
"ts-jest": "^29.1.2",
|
22
|
+
"ts-node": "^10.9.2",
|
23
|
+
"typescript": "^5.3.3"
|
24
|
+
},
|
25
|
+
"engines": {
|
26
|
+
"node": ">=16"
|
27
|
+
},
|
28
|
+
"scripts": {
|
29
|
+
"clean": "rm -rf dist node_modules",
|
30
|
+
"build": "pnpm run build:js",
|
31
|
+
"build:js": "tsc",
|
32
|
+
"test": "pnpm run test:js",
|
33
|
+
"test:js": "jest",
|
34
|
+
"pubdir": "pnpm run build; rm -rf pubdir ; mkdir -p pubdir; cp -pr ../.gitignore package.json ../README.md ../LICENSE pubdir/; cd dist ; cp -pr . ../pubdir/",
|
35
|
+
"presmoke": "pnpm run pubdir ; cd pubdir ; pnpm pack",
|
36
|
+
"smoke": "cd smoke; rm -f package.json; pnpm init ; pnpm install -f ../pubdir/adviser-cement-*.tgz; npx ts-node ./smoke.ts",
|
37
|
+
"lint": "eslint . --ext .ts",
|
38
|
+
"prettier": "prettier ."
|
39
|
+
}
|
40
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import { FileService } from "./file_service";
|
2
|
+
import { Time } from "./time";
|
3
|
+
export declare enum TimeMode {
|
4
|
+
REAL = "real",
|
5
|
+
CONST = "const",
|
6
|
+
STEP = "step"
|
7
|
+
}
|
8
|
+
export declare enum RandomMode {
|
9
|
+
CONST = "const",
|
10
|
+
STEP = "step",
|
11
|
+
RANDOM = "random"
|
12
|
+
}
|
13
|
+
export declare enum IDMode {
|
14
|
+
UUID = "uuid",
|
15
|
+
CONST = "const",
|
16
|
+
STEP = "step"
|
17
|
+
}
|
18
|
+
export declare function String2TimeMode(s?: string): TimeMode;
|
19
|
+
export type VoidFunc = () => void | Promise<void>;
|
20
|
+
export interface SystemService {
|
21
|
+
Env(): Record<string, string>;
|
22
|
+
Args(): string[];
|
23
|
+
OnExit(hdl: VoidFunc): VoidFunc;
|
24
|
+
Exit(code: number): void;
|
25
|
+
}
|
26
|
+
export interface SysAbstraction {
|
27
|
+
Time(): Time;
|
28
|
+
Stdout(): WritableStream<Uint8Array>;
|
29
|
+
Stderr(): WritableStream<Uint8Array>;
|
30
|
+
NextId(): string;
|
31
|
+
Random0ToValue(value: number): number;
|
32
|
+
System(): SystemService;
|
33
|
+
FileSystem(): FileService;
|
34
|
+
}
|
35
|
+
//# sourceMappingURL=sys_abstraction.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"sys_abstraction.d.ts","sourceRoot":"","sources":["../src/sys_abstraction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,oBAAY,QAAQ;IAClB,IAAI,SAAS;IACb,KAAK,UAAU;IACf,IAAI,SAAS;CACd;AAED,oBAAY,UAAU;IACpB,KAAK,UAAU;IACf,IAAI,SAAS;IACb,MAAM,WAAW;CAClB;AAED,oBAAY,MAAM;IAChB,IAAI,SAAS;IACb,KAAK,UAAU;IACf,IAAI,SAAS;CACd;AAED,wBAAgB,eAAe,CAAC,CAAC,CAAC,EAAE,MAAM,GAAG,QAAQ,CAWpD;AAED,MAAM,MAAM,QAAQ,GAAG,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAElD,MAAM,WAAW,aAAa;IAC5B,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,IAAI,IAAI,MAAM,EAAE,CAAC;IACjB,MAAM,CAAC,GAAG,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAChC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,IAAI,IAAI,CAAC;IACb,MAAM,IAAI,cAAc,CAAC,UAAU,CAAC,CAAC;IACrC,MAAM,IAAI,cAAc,CAAC,UAAU,CAAC,CAAC;IACrC,MAAM,IAAI,MAAM,CAAC;IACjB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACtC,MAAM,IAAI,aAAa,CAAC;IACxB,UAAU,IAAI,WAAW,CAAC;CAC3B"}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.String2TimeMode = exports.IDMode = exports.RandomMode = exports.TimeMode = void 0;
|
4
|
+
var TimeMode;
|
5
|
+
(function (TimeMode) {
|
6
|
+
TimeMode["REAL"] = "real";
|
7
|
+
TimeMode["CONST"] = "const";
|
8
|
+
TimeMode["STEP"] = "step";
|
9
|
+
})(TimeMode || (exports.TimeMode = TimeMode = {}));
|
10
|
+
var RandomMode;
|
11
|
+
(function (RandomMode) {
|
12
|
+
RandomMode["CONST"] = "const";
|
13
|
+
RandomMode["STEP"] = "step";
|
14
|
+
RandomMode["RANDOM"] = "random";
|
15
|
+
})(RandomMode || (exports.RandomMode = RandomMode = {}));
|
16
|
+
var IDMode;
|
17
|
+
(function (IDMode) {
|
18
|
+
IDMode["UUID"] = "uuid";
|
19
|
+
IDMode["CONST"] = "const";
|
20
|
+
IDMode["STEP"] = "step";
|
21
|
+
})(IDMode || (exports.IDMode = IDMode = {}));
|
22
|
+
function String2TimeMode(s) {
|
23
|
+
switch (s === null || s === void 0 ? void 0 : s.toLowerCase()) {
|
24
|
+
case "real":
|
25
|
+
return TimeMode.REAL;
|
26
|
+
case "const":
|
27
|
+
return TimeMode.CONST;
|
28
|
+
case "step":
|
29
|
+
return TimeMode.STEP;
|
30
|
+
default:
|
31
|
+
return TimeMode.REAL;
|
32
|
+
}
|
33
|
+
}
|
34
|
+
exports.String2TimeMode = String2TimeMode;
|
35
|
+
//# sourceMappingURL=sys_abstraction.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"sys_abstraction.js","sourceRoot":"","sources":["../src/sys_abstraction.ts"],"names":[],"mappings":";;;AAGA,IAAY,QAIX;AAJD,WAAY,QAAQ;IAClB,yBAAa,CAAA;IACb,2BAAe,CAAA;IACf,yBAAa,CAAA;AACf,CAAC,EAJW,QAAQ,wBAAR,QAAQ,QAInB;AAED,IAAY,UAIX;AAJD,WAAY,UAAU;IACpB,6BAAe,CAAA;IACf,2BAAa,CAAA;IACb,+BAAiB,CAAA;AACnB,CAAC,EAJW,UAAU,0BAAV,UAAU,QAIrB;AAED,IAAY,MAIX;AAJD,WAAY,MAAM;IAChB,uBAAa,CAAA;IACb,yBAAe,CAAA;IACf,uBAAa,CAAA;AACf,CAAC,EAJW,MAAM,sBAAN,MAAM,QAIjB;AAED,SAAgB,eAAe,CAAC,CAAU;IACxC,QAAQ,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,WAAW,EAAE,EAAE,CAAC;QACzB,KAAK,MAAM;YACT,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,KAAK,OAAO;YACV,OAAO,QAAQ,CAAC,KAAK,CAAC;QACxB,KAAK,MAAM;YACT,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB;YACE,OAAO,QAAQ,CAAC,IAAI,CAAC;IACzB,CAAC;AACH,CAAC;AAXD,0CAWC"}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
declare class LogWriter implements WritableStreamDefaultWriter<Uint8Array> {
|
2
|
+
readonly _bufferArr: Uint8Array[];
|
3
|
+
_resolveClosed: (value?: PromiseLike<undefined>) => void;
|
4
|
+
closed: Promise<undefined>;
|
5
|
+
desiredSize: number | null;
|
6
|
+
ready: Promise<undefined>;
|
7
|
+
constructor();
|
8
|
+
abort(reason?: any): Promise<void>;
|
9
|
+
close(): Promise<void>;
|
10
|
+
releaseLock(): void;
|
11
|
+
write(chunk?: Uint8Array): Promise<void>;
|
12
|
+
}
|
13
|
+
export declare class LogCollector implements WritableStream<Uint8Array> {
|
14
|
+
readonly locked: boolean;
|
15
|
+
_writer?: LogWriter;
|
16
|
+
abort(reason?: Uint8Array): Promise<void>;
|
17
|
+
close(): Promise<void>;
|
18
|
+
getWriter(): WritableStreamDefaultWriter<Uint8Array>;
|
19
|
+
Logs(): any[];
|
20
|
+
}
|
21
|
+
export {};
|
22
|
+
//# sourceMappingURL=log_collector.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"log_collector.d.ts","sourceRoot":"","sources":["../../src/test/log_collector.ts"],"names":[],"mappings":"AAAA,cAAM,SAAU,YAAW,2BAA2B,CAAC,UAAU,CAAC;IAChE,QAAQ,CAAC,UAAU,EAAE,UAAU,EAAE,CAAM;IAEvC,cAAc,EAAE,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC;IACzD,MAAM,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAC3B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAQ;IAClC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAA8B;;IAWvD,KAAK,CAAC,MAAM,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAGlC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,WAAW,IAAI,IAAI;IAGnB,KAAK,CAAC,KAAK,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CAIzC;AAED,qBAAa,YAAa,YAAW,cAAc,CAAC,UAAU,CAAC;IAC7D,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAS;IACjC,OAAO,CAAC,EAAE,SAAS,CAAC;IAGpB,KAAK,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAInC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAS5B,SAAS,IAAI,2BAA2B,CAAC,UAAU,CAAC;IAQpD,IAAI,IAAI,GAAG,EAAE;CAkBd"}
|
@@ -0,0 +1,65 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.LogCollector = void 0;
|
4
|
+
class LogWriter {
|
5
|
+
constructor() {
|
6
|
+
this._bufferArr = [];
|
7
|
+
this.desiredSize = null;
|
8
|
+
this.ready = Promise.resolve(undefined);
|
9
|
+
this._resolveClosed = () => { };
|
10
|
+
this.closed = new Promise((resolve) => {
|
11
|
+
this._resolveClosed = resolve;
|
12
|
+
});
|
13
|
+
}
|
14
|
+
abort(reason) {
|
15
|
+
throw new Error("Method not implemented.");
|
16
|
+
}
|
17
|
+
close() {
|
18
|
+
this._resolveClosed();
|
19
|
+
return Promise.resolve(undefined);
|
20
|
+
}
|
21
|
+
releaseLock() {
|
22
|
+
}
|
23
|
+
write(chunk) {
|
24
|
+
chunk && this._bufferArr.push(chunk);
|
25
|
+
return Promise.resolve(undefined);
|
26
|
+
}
|
27
|
+
}
|
28
|
+
class LogCollector {
|
29
|
+
constructor() {
|
30
|
+
this.locked = false;
|
31
|
+
}
|
32
|
+
abort(reason) {
|
33
|
+
throw new Error("Method not implemented.");
|
34
|
+
}
|
35
|
+
async close() {
|
36
|
+
if (this._writer) {
|
37
|
+
const ret = await this._writer.close();
|
38
|
+
this._writer = undefined;
|
39
|
+
return ret;
|
40
|
+
}
|
41
|
+
return Promise.resolve(undefined);
|
42
|
+
}
|
43
|
+
getWriter() {
|
44
|
+
if (!this._writer) {
|
45
|
+
this._writer = new LogWriter();
|
46
|
+
}
|
47
|
+
return this._writer;
|
48
|
+
}
|
49
|
+
Logs() {
|
50
|
+
if (!this._writer) {
|
51
|
+
return [];
|
52
|
+
}
|
53
|
+
const jsonNlStr = new TextDecoder().decode(new Uint8Array((function* (res) {
|
54
|
+
for (const x of res) {
|
55
|
+
yield* x;
|
56
|
+
}
|
57
|
+
})(this._writer._bufferArr)));
|
58
|
+
const splitStr = jsonNlStr.split("\n");
|
59
|
+
const filterStr = splitStr.filter((a) => a.length);
|
60
|
+
const mapStr = filterStr.map((a) => JSON.parse(a));
|
61
|
+
return mapStr;
|
62
|
+
}
|
63
|
+
}
|
64
|
+
exports.LogCollector = LogCollector;
|
65
|
+
//# sourceMappingURL=log_collector.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"log_collector.js","sourceRoot":"","sources":["../../src/test/log_collector.ts"],"names":[],"mappings":";;;AAAA,MAAM,SAAS;IAQb;QAPS,eAAU,GAAiB,EAAE,CAAC;QAIvC,gBAAW,GAAkB,IAAI,CAAC;QAClC,UAAK,GAAuB,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAIrD,IAAI,CAAC,cAAc,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YACpC,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC;QAChC,CAAC,CAAC,CAAC;IACL,CAAC;IAGD,KAAK,CAAC,MAAY;QAChB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IACD,KAAK;QACH,IAAI,CAAC,cAAc,EAAE,CAAC;QACtB,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC;IACD,WAAW;IAEX,CAAC;IACD,KAAK,CAAC,KAAkB;QACtB,KAAK,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrC,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC;CACF;A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CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACnD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA5CD,oCA4CC"}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { Logger } from "../logger";
|
2
|
+
import { SysAbstraction } from "../sys_abstraction";
|
3
|
+
import { LogCollector } from "./log_collector";
|
4
|
+
export interface MockLoggerReturn {
|
5
|
+
readonly logger: Logger;
|
6
|
+
readonly logCollector: LogCollector;
|
7
|
+
}
|
8
|
+
export declare function MockLogger(params?: {
|
9
|
+
readonly sys?: SysAbstraction;
|
10
|
+
moduleName?: string | string[];
|
11
|
+
readonly disableDebug?: boolean;
|
12
|
+
}): MockLoggerReturn;
|
13
|
+
//# sourceMappingURL=mock_logger.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"mock_logger.d.ts","sourceRoot":"","sources":["../../src/test/mock_logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;CACrC;AAED,wBAAgB,UAAU,CAAC,MAAM,CAAC,EAAE;IAClC,QAAQ,CAAC,GAAG,CAAC,EAAE,cAAc,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC/B,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC;CACjC,GAAG,gBAAgB,CAcnB"}
|