@aj-shadow/z-abs-corelayer-cs 0.0.0-aj-beta.221

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/.gitattributes +26 -0
  2. package/LICENSE.txt +96 -0
  3. package/README.md +5 -0
  4. package/npm-shrinkwrap.json +13 -0
  5. package/package.json +10 -0
  6. package/project/clientServer/_build/Bundle-CoreLayer-cs.bld +25 -0
  7. package/project/clientServer/_build/Client-CoreLayer-cs.bld +10 -0
  8. package/project/clientServer/_build/Server-CoreLayer-cs.bld +12 -0
  9. package/project/clientServer/_build/z-abs-corelayer-cs.prj +28 -0
  10. package/project/clientServer/cache/cache-array.js +38 -0
  11. package/project/clientServer/cache/cache-map.js +26 -0
  12. package/project/clientServer/cache/cache-set.js +24 -0
  13. package/project/clientServer/communication/action-request.js +34 -0
  14. package/project/clientServer/communication/action-response-error.js +18 -0
  15. package/project/clientServer/communication/action-response-success.js +18 -0
  16. package/project/clientServer/communication/app-protocol/app-deserializer.js +74 -0
  17. package/project/clientServer/communication/app-protocol/app-serializer.js +55 -0
  18. package/project/clientServer/communication/cache/text-cache.js +77 -0
  19. package/project/clientServer/communication/core-protocol/core-message.js +22 -0
  20. package/project/clientServer/communication/core-protocol/core-protocol-const.js +21 -0
  21. package/project/clientServer/communication/core-protocol/deserializer-message-persistent-init-request.js +12 -0
  22. package/project/clientServer/communication/core-protocol/deserializer-message-persistent-init-response.js +12 -0
  23. package/project/clientServer/communication/core-protocol/deserializer-message-request.js +45 -0
  24. package/project/clientServer/communication/core-protocol/deserializer-message-response.js +63 -0
  25. package/project/clientServer/communication/core-protocol/deserializer-message-service-init-request.js +24 -0
  26. package/project/clientServer/communication/core-protocol/deserializer-message-service-init-response.js +16 -0
  27. package/project/clientServer/communication/core-protocol/deserializer.js +349 -0
  28. package/project/clientServer/communication/core-protocol/encoder-const.js +21 -0
  29. package/project/clientServer/communication/core-protocol/encoder-giud.js +24 -0
  30. package/project/clientServer/communication/core-protocol/envelope.js +39 -0
  31. package/project/clientServer/communication/core-protocol/serializer-message-persistent-init-request.js +33 -0
  32. package/project/clientServer/communication/core-protocol/serializer-message-persistent-init-response.js +12 -0
  33. package/project/clientServer/communication/core-protocol/serializer-message-request.js +84 -0
  34. package/project/clientServer/communication/core-protocol/serializer-message-response.js +90 -0
  35. package/project/clientServer/communication/core-protocol/serializer-message-service-init-request.js +35 -0
  36. package/project/clientServer/communication/core-protocol/serializer-message-service-init-response.js +29 -0
  37. package/project/clientServer/communication/core-protocol/serializer.js +188 -0
  38. package/project/clientServer/communication/response-data.js +16 -0
  39. package/project/clientServer/communication/service-action.js +29 -0
  40. package/project/clientServer/debug-dashboard/garbage-collection.js +27 -0
  41. package/project/clientServer/debug-dashboard/log.js +444 -0
  42. package/project/clientServer/debug-dashboard/memory.js +73 -0
  43. package/project/clientServer/factory/factory-function.js +24 -0
  44. package/project/clientServer/factory/factory-new.js +24 -0
  45. package/project/clientServer/guid-generator.js +36 -0
  46. package/project/clientServer/memory/memory-cache-array.js +64 -0
  47. package/project/clientServer/memory/memory-cache-map.js +43 -0
  48. package/project/clientServer/memory/memory-cache-object.js +44 -0
  49. package/project/clientServer/memory/memory-cache-set.js +26 -0
  50. package/project/clientServer/memory/memory-pool.js +49 -0
  51. package/project/clientServer/project.js +460 -0
  52. package/project/clientServer/synchronization/mutex-local-callback.js +50 -0
  53. package/project/clientServer/time/high-resolution-date.js +24 -0
  54. package/project/clientServer/time/high-resolution-duration.js +41 -0
  55. package/project/z-abs-corelayer-cs.tree +62 -0
@@ -0,0 +1,44 @@
1
+
2
+ 'use strict';
3
+
4
+ const GuidGenerator = require('z-abs-corelayer-cs/clientServer/guid-generator');
5
+
6
+
7
+ class MemoryCacheObject {
8
+ constructor() {
9
+ #BUILD_DEBUG_START
10
+ this._tag = Symbol(GuidGenerator.create());
11
+ #BUILD_DEBUG_STOP
12
+ this.cache = [];
13
+ }
14
+
15
+ create(factory) {
16
+ if(0 !== this.cache.length) {
17
+ return this.cache.pop();
18
+ }
19
+ else {
20
+ const object = new factory();
21
+ #BUILD_DEBUG_START
22
+ object[MemoryCacheObject._tag] = this._tag;
23
+ #BUILD_DEBUG_STOP
24
+ return object;
25
+ }
26
+ }
27
+
28
+ destroy(object) {
29
+ if(!object) {
30
+ console.log('!object');
31
+ return;
32
+ }
33
+ #BUILD_DEBUG_START
34
+ if(object[MemoryCacheObject._tag] !== this._tag) {
35
+ console.log(`MemoryCacheObject.destroy: object is not created by the cache.`);
36
+ return;
37
+ }
38
+ #BUILD_DEBUG_STOP
39
+ this.cache.push(object);
40
+ }
41
+ }
42
+
43
+
44
+ module.exports = MemoryCacheObject;
@@ -0,0 +1,26 @@
1
+
2
+ 'use strict';
3
+
4
+
5
+ class MemoryCacheSet {
6
+ constructor() {
7
+ this.cacheMap = [];
8
+ }
9
+
10
+ create() {
11
+ if(0 !== this.cacheMap.length) {
12
+ return this.cacheMap.pop();
13
+ }
14
+ else {
15
+ return new Set();
16
+ }
17
+ }
18
+
19
+ destructor(set) {
20
+ set.clear();
21
+ this.cacheMap.push(set);
22
+ }
23
+ }
24
+
25
+
26
+ module.exports = MemoryCacheSet;
@@ -0,0 +1,49 @@
1
+
2
+ 'use strict';
3
+
4
+ const MemoryCacheMap = require('./memory-cache-map');
5
+ const MemoryCacheSet = require('./memory-cache-set');
6
+
7
+
8
+ class MemoryPool {
9
+ static poolObjects = new Map();
10
+ static memoryCacheMap = new MemoryCacheMap();
11
+ static memoryCacheSet = new MemoryCacheSet();
12
+
13
+ static create(id) {
14
+ MemoryPool.poolObjects.set(id, MemoryPool.memoryCacheArray.create());
15
+ }
16
+
17
+ static addObject(id, object) {
18
+ MemoryPool.poolObjects.get(id).push(object);
19
+ }
20
+
21
+ static createArray(id) {
22
+ const array = MemoryPool.memoryCacheArray.create();
23
+ MemoryPool.poolObjects.get(id).push(array);
24
+ return array;
25
+ }
26
+
27
+ static createMap(id) {
28
+ const map = MemoryPool.memoryCacheMap.create();
29
+ MemoryPool.poolObjects.get(id).push(map);
30
+ return map;
31
+ }
32
+
33
+ static createSet(id) {
34
+ const set = MemoryPool.memoryCacheSet.create();
35
+ MemoryPool.poolObjects.get(id).push(set);
36
+ return set;
37
+ }
38
+
39
+ static delete(id) {
40
+ const poolObjects = MemoryPool.poolObjects.get(id);
41
+ poolObjects.forEach((poolObject) => {
42
+ poolObject.destructor(poolObject);
43
+ });
44
+ MemoryPool.memoryCacheArray.destructor(poolObjects);
45
+ }
46
+ }
47
+
48
+
49
+ module.exports = MemoryPool;
@@ -0,0 +1,460 @@
1
+
2
+ 'use strict';
3
+
4
+ const GuidGenerator = require('./guid-generator');
5
+ const Os = require('os');
6
+
7
+
8
+ class Project {
9
+ constructor(source = [], type = undefined, plugin = false) {
10
+ this.source = source;
11
+ this.type = type;
12
+ this.plugin = plugin;
13
+ this.workspaceName = null;
14
+ this.selectedNode = null;
15
+ this.projectId = GuidGenerator.create();
16
+ this.saved = true;
17
+ }
18
+
19
+ clone() {
20
+ const project = new Project(this.source, this.type, this.plugin);
21
+ project.selectedNode = this.selectedNode;
22
+ project.projectId = this.projectId;
23
+ project.saved = this.saved;
24
+ return project;
25
+ }
26
+
27
+ set(source, type, workspaceName) {
28
+ this.source = source;
29
+ this.type = type;
30
+ this.workspaceName = workspaceName;
31
+ }
32
+
33
+ _importPureChild(node, childKey, nodeDatas, expandeds) {
34
+ const childNodeData = nodeDatas.get(childKey);
35
+ const columns = childNodeData.columns;
36
+ const key = columns[0];
37
+ const type = columns[3];
38
+ if('folder' === type || 'static_folder' === type || 'project_folder' === type) {
39
+ const typesString = columns[5];
40
+ const types = typesString.substring(1, typesString.length - 1).split(',');
41
+ const expanded = expandeds.has(key);
42
+ const childNode = this.addFolderToNode(columns[2], columns[4], types, node, type, key, expanded);
43
+ childNodeData.children.forEach((nextChildKey) => {
44
+ this._importPureChild(childNode, nextChildKey, nodeDatas, expandeds);
45
+ });
46
+ }
47
+ else if('file' === type) {
48
+ this.addFileToNode(columns[2], columns[4], columns[5], node, key);
49
+ }
50
+ else {
51
+ ddb.error('UNKNOWN TYPE:', type);
52
+ }
53
+ }
54
+
55
+ importPure(pureProject, jsonProject) {
56
+ this.source = [];
57
+ if(!pureProject) {
58
+ return;
59
+ }
60
+ const rows = pureProject.split(Os.EOL);
61
+ rows.forEach((row, index, array) => {
62
+ array[index] = row.trim();
63
+ });
64
+ const nodeDatas = new Map();
65
+ const firstRow = rows[0];
66
+ const firstColumns = firstRow.split(';');;
67
+ const rootNodeData = {
68
+ columns: firstColumns,
69
+ children: []
70
+ };
71
+ nodeDatas.set(firstColumns[0], rootNodeData);
72
+ for(let i = 1; i < rows.length; ++i) {
73
+ const row = rows[i];
74
+ const columns = row.split(';');
75
+ nodeDatas.set(columns[0], {
76
+ columns: columns,
77
+ children: []
78
+ });
79
+ }
80
+
81
+ // Add children
82
+ nodeDatas.forEach((child) => {
83
+ const parentKey = child.columns[1];
84
+ const parent = nodeDatas.get(parentKey);
85
+ if(parent) {
86
+ parent.children.push(child.columns[0]);
87
+ }
88
+ else {
89
+ if(parentKey) {
90
+ ddb.error('Parent not found. Child dropped.');
91
+ }
92
+ }
93
+ });
94
+
95
+ if(1 <= nodeDatas.size) {
96
+ const expandeds = new Set();
97
+ this._getAllExpandedKeys(jsonProject, expandeds);
98
+ const typesString = firstColumns[5];
99
+ const types = typesString.substring(1, typesString.length - 1).split(',');
100
+ const key = firstColumns[0];
101
+ const expanded = expandeds.has(key);
102
+ let node = this.addRootFolder(firstColumns[2], types, key, expanded);
103
+ rootNodeData.children.forEach((childKey) => {
104
+ this._importPureChild(node, childKey, nodeDatas, expandeds);
105
+ });
106
+ this.sortNode(this.source[0]);
107
+ }
108
+ }
109
+
110
+ sortParent(node) {
111
+ const foundFolder = this.findFolder(this.source, node.data.path.replace(new RegExp('[\\\\]', 'g'), '/'));
112
+ if(foundFolder) {
113
+ this.sortNode(foundFolder);
114
+ }
115
+ }
116
+
117
+ sortNode(node) {
118
+ node.children.sort((a, b) => {
119
+ if(a.folder !== b.folder) {
120
+ return a.folder ? -1 : 1;
121
+ }
122
+ else {
123
+ return a.title >= b.title ? 1 : -1;
124
+ }
125
+ });
126
+ for(let i = 0; i < node.children.length; ++i) {
127
+ const child = node.children[i];
128
+ if(child.folder) {
129
+ this.sortNode(child);
130
+ }
131
+ }
132
+ }
133
+
134
+ _getAllExpandedKeys(jsonProject, expandeds) {
135
+ if(jsonProject) {
136
+ jsonProject.forEach((node) => {
137
+ if(node.folder && node.expanded) {
138
+ expandeds.add(node.key);
139
+ }
140
+ this._getAllExpandedKeys(node.children, expandeds);
141
+ });
142
+ }
143
+ }
144
+
145
+ _exportPureChildren(node, parentKey, result) {
146
+ const value = `${node.key};${parentKey};${node.title};${node.folder ? node.data.type : 'file'};${node.data.path};${node.folder ? '[' + node.data.types.join(',') + ']' : node.data.type}`;
147
+ result.push(value);
148
+ if(node.children) {
149
+ node.children.forEach((child) => {
150
+ this._exportPureChildren(child, node.key, result);
151
+ });
152
+ }
153
+ }
154
+
155
+ exportPure() {
156
+ const result = [];
157
+ this._exportPureChildren(this.source[0], '', result);
158
+ return result.join(Os.EOL);
159
+ }
160
+
161
+ isSaved() {
162
+ return this.saved;
163
+ }
164
+
165
+ setSaved() {
166
+ this.saved = true;
167
+ }
168
+
169
+ isEmpty() {
170
+ return 0 === this.source.length;
171
+ }
172
+
173
+ select(key, selected) {
174
+ this.unSelect();
175
+ const foundNode = this.findKey(this.source, key);
176
+ if(foundNode) {
177
+ foundNode.selected = selected;
178
+ this.selectedNode = foundNode;
179
+ }
180
+ }
181
+
182
+ unSelect() {
183
+ if(this.selectedNode) {
184
+ this.selectedNode.selected = false;
185
+ this.selectedNode = null;
186
+ }
187
+ }
188
+
189
+ toggle(key, expanded) {
190
+ const foundNode = this.findKey(this.source, key);
191
+ if(foundNode) {
192
+ foundNode.expanded = expanded;
193
+ }
194
+ }
195
+
196
+ expandPath(path) {
197
+ const pathSplit = path.split('/');
198
+ if(2 >= pathSplit.length) {
199
+ return;
200
+ }
201
+ if('.' !== pathSplit[0]) {
202
+ return;
203
+ }
204
+ let currentFolder = `${pathSplit[0]}/${pathSplit[1]}/${pathSplit[2]}`;
205
+ pathSplit.shift();
206
+ pathSplit.shift();
207
+ pathSplit.shift();
208
+ let foundFolder = this.findFolder(this.source[0].children, currentFolder);
209
+ if(foundFolder) {
210
+ this.source[0].expanded = true;
211
+ foundFolder.expanded = true;
212
+ while(0 !== pathSplit.length) {
213
+ foundFolder.expanded = true;
214
+ currentFolder = `${currentFolder}/${pathSplit[0]}`;
215
+ foundFolder = this.findFolder(foundFolder.children, currentFolder);
216
+ if(!foundFolder) {
217
+ break;
218
+ }
219
+ foundFolder.expanded = true;
220
+ pathSplit.shift();
221
+ }
222
+ }
223
+ }
224
+
225
+ isChildKey(parentKey, childKey) {
226
+ const parent = this.findKey(this.source, parentKey);
227
+ if(parent) {
228
+ for(let i = 0; i < parent.children.length; ++i) {
229
+ const child = parent.children[i];
230
+ if(child.key === childKey) {
231
+ return true;
232
+ }
233
+ }
234
+ }
235
+ return false;
236
+ }
237
+
238
+ findKey(children, key) { // MOST LIKELY THAT THE NODE IS CLOSE TO THE ROOT
239
+ for(let i = 0; i < children.length; ++i) {
240
+ if(children[i].key === key) {
241
+ return children[i];
242
+ }
243
+ }
244
+ for(let i = 0; i < children.length; ++i) {
245
+ if(children[i].children) {
246
+ const foundNode = this.findKey(children[i].children, key);
247
+ if(foundNode) {
248
+ return foundNode;
249
+ }
250
+ }
251
+ }
252
+ return null;
253
+ }
254
+
255
+ addFileToNode(title, dir, type, node, key=null, selected=false) {
256
+ if(node) {
257
+ const file = {
258
+ key: key ? key : GuidGenerator.create(),
259
+ folder: false,
260
+ title: title,
261
+ selected: selected,
262
+ data: {
263
+ path: dir,
264
+ type: type,
265
+ valid: true
266
+ }
267
+ };
268
+ node.children.push(file);
269
+ this.saved = false;
270
+ return file;
271
+ }
272
+ }
273
+
274
+ addFile(title, dir, type, cb) {
275
+ return this.addFileToNode(title, dir, type, this.findFolder(this.source, dir.replace(new RegExp('[\\\\]', 'g'), '/')));
276
+ }
277
+
278
+ addFolderToNode(title, dir, types, node, type='folder', key=null, expanded=false, selected=false) {
279
+ if(node) {
280
+ const folder = {
281
+ key: key ? key : GuidGenerator.create(),
282
+ folder: true,
283
+ title: title,
284
+ expanded: expanded,
285
+ selected: selected,
286
+ data: {
287
+ path: dir,
288
+ types: types,
289
+ type: type,
290
+ valid: true
291
+ },
292
+ children: []
293
+ };
294
+ node.children.push(folder);
295
+ this.saved = false;
296
+ if(selected) {
297
+ this.unSelect();
298
+ this.selectedNode = folder;
299
+ }
300
+ return folder;
301
+ }
302
+ }
303
+
304
+ addFolder(title, data, types=null) {
305
+ return this.addFolderToNode(title, data.path, types ? types : data.types, this.findFolder(this.source, data.path.replace(new RegExp('[\\\\]', 'g'), '/')), data.type);
306
+ }
307
+
308
+ addRootFolder(title, types, key=null, expanded=false, selected=false) {
309
+ const folder = {
310
+ key: key ? key : GuidGenerator.create(),
311
+ folder: true,
312
+ title: title,
313
+ expanded: expanded,
314
+ selected: selected,
315
+ data: {
316
+ path: '.',
317
+ types: types,
318
+ type: 'project_folder',
319
+ valid: true
320
+ },
321
+ children: []
322
+ }
323
+ if(selected) {
324
+ this.unSelect();
325
+ this.selectedNode = folder;
326
+ }
327
+ this.source.push(folder);
328
+ return folder
329
+ }
330
+
331
+ removeNode(path, key) {
332
+ const node = this.findNode(path);
333
+ const foundIndex = node.children.findIndex((found) => {
334
+ return found.key === key;
335
+ });
336
+ if(-1 !== foundIndex) {
337
+ node.children.splice(foundIndex, 1);
338
+ this.saved = false;
339
+ }
340
+ }
341
+
342
+ getRootName() {
343
+ // FIX to be general
344
+ const node = this.source[0];
345
+ return `${node.data.path}/${node.title}`;
346
+ }
347
+
348
+ getFileNames(dir) {
349
+ const node = this.findFolder(this.source, dir);
350
+ if(node) {
351
+ if(!node.children) {
352
+ node.children = [];
353
+ }
354
+ return node.children.map((childNode) => {
355
+ return `${childNode.data.path}/${childNode.title}`;
356
+ });
357
+ }
358
+ else {
359
+ return [];
360
+ }
361
+ }
362
+
363
+ findNode(file) {
364
+ const fileData = this._pathParse(file);
365
+ const node = this.findFolder(this.source, fileData.dir);
366
+ if(node) {
367
+ if(node.children) {
368
+ for(let i = 0; i < node.children.length; ++i) {
369
+ if(node.children[i].title === fileData.base) {
370
+ return node.children[i];
371
+ }
372
+ }
373
+ }
374
+ //return node;
375
+ }
376
+ }
377
+
378
+ findFolder(nodes, dir) {
379
+ const normalizedDir = dir;
380
+ const nodeFound = nodes.find((node) => {
381
+ return node.folder && (normalizedDir.startsWith(`${node.data.path}/${node.title}/`) || normalizedDir === `${node.data.path}/${node.title}`);
382
+ });
383
+ if(nodeFound) {
384
+ if(`${nodeFound.data.path}/${nodeFound.title}` === normalizedDir) {
385
+ return nodeFound;
386
+ }
387
+ else {
388
+ return this.findFolder(nodeFound.children, normalizedDir);
389
+ }
390
+ }
391
+ }
392
+
393
+ getAllFileChildren(node) {
394
+ const children = [];
395
+ this._getAllFileChildren(node, children);
396
+ return children;
397
+ }
398
+
399
+ _getAllFileChildren(node, children) {
400
+ node.children.forEach((child)=> {
401
+ if(child.folder) {
402
+ this._getAllFileChildren(child, children);
403
+ }
404
+ else {
405
+ children.push(child);
406
+ }
407
+ });
408
+ }
409
+
410
+ renameFile(node, newTitle) {
411
+ node.title = newTitle;
412
+ this.saved = false;
413
+ }
414
+
415
+ renamePathRecursive(node, newTitle) {
416
+ node.title = newTitle;
417
+ this.saved = false;
418
+ node.children.forEach((child) => {
419
+ this._renamePathRecursive(child, `${node.data.path}/${newTitle}`);
420
+ });
421
+ }
422
+
423
+ _renamePathRecursive(node, path) {
424
+ node.data.path = path;
425
+ if(node.folder) {
426
+ node.children.forEach((child) => {
427
+ this._renamePathRecursive(child, `${node.data.path}/${node.title}`);
428
+ });
429
+ }
430
+ }
431
+
432
+ _pathParse(file) {
433
+ const parts = file.split('/');
434
+ let lastPart = parts.pop();
435
+ const lastIndex = lastPart.lastIndexOf('.');
436
+ let dir = parts.join('/');
437
+ if('.' === dir) {
438
+ dir = file;
439
+ lastPart = '';
440
+ }
441
+ if(-1 === lastIndex) {
442
+ return {
443
+ dir: dir,
444
+ base: lastPart,
445
+ ext: undefined,
446
+ name: undefined
447
+ };
448
+ }
449
+ else {
450
+ return {
451
+ dir: dir,
452
+ base: lastPart,
453
+ ext: lastPart.substring(lastIndex),
454
+ name: lastPart.substring(0, lastIndex)
455
+ };
456
+ }
457
+ }
458
+ }
459
+
460
+ module.exports = Project;
@@ -0,0 +1,50 @@
1
+
2
+ 'use strict';
3
+
4
+
5
+ class MutexLocalCallback {
6
+ constructor() {
7
+ this.startTime = 0n;
8
+ this.locked = false;
9
+ this.queue = [];
10
+ }
11
+
12
+ add(object, method) {
13
+ const originalMethod = method.bind(object);
14
+ const self = this;
15
+ return function (...args) {
16
+ if(self.locked) {
17
+ self.queue.push({
18
+ originalMethod: originalMethod,
19
+ args: args
20
+ });
21
+ }
22
+ else {
23
+ const done = args[args.length - 1];
24
+ args[args.length - 1] = (...doneArgs) => {
25
+ if(0 !== self.queue.length) {
26
+ const next = self.queue.shift();
27
+ process.nextTick(next.originalMethod, ...next.args);
28
+ }
29
+ else {
30
+ self.locked = false;
31
+ }
32
+ done(...doneArgs);
33
+ };
34
+ self.locked = true;
35
+ originalMethod(...args);
36
+ }
37
+ };
38
+ }
39
+
40
+ setStartTime() {
41
+ this.startTime = process.hrtime.bigint();
42
+ }
43
+
44
+ logTime(...text) {
45
+ console.log('TIME:', (process.hrtime.bigint() - this.startTime) / 1000000n, ...text);
46
+ }
47
+ }
48
+
49
+
50
+ module.exports = MutexLocalCallback;
@@ -0,0 +1,24 @@
1
+
2
+ 'use strict';
3
+
4
+
5
+ class HighResolutionDate {
6
+ constructor(timestamp) {
7
+ const dateRaw = timestamp;
8
+ this.date = new Date(Math.trunc(Number(dateRaw / 1000000n)));
9
+ const dateSeconds = dateRaw / 1000000000n;
10
+ const dateRest = dateRaw - dateSeconds * 1000000000n;
11
+ this.milliSeconds = Number(dateRest) * 0.000001;
12
+ }
13
+
14
+ getDateMilliSeconds() {
15
+ return `${this.date.toUTCString()} : ${this.milliSeconds.toFixed(3).toString().padStart(7, '0')}`;
16
+ }
17
+
18
+ static getMilliSeconds(hrtime) {
19
+ return Number(hrtime / 1000000n);
20
+ }
21
+ }
22
+
23
+
24
+ module.exports = HighResolutionDate;
@@ -0,0 +1,41 @@
1
+
2
+ 'use strict';
3
+
4
+
5
+ class HighResolutionDuration {
6
+ constructor(duration) {
7
+ this.duration = duration;
8
+ const seconds = this.duration / 1000000000n;
9
+ this.seconds = Number(seconds);
10
+ const dateRest = this.duration - seconds * 1000000000n;
11
+ this.milliSeconds = Number(dateRest) / 1000000;
12
+ }
13
+
14
+ add(duration) {
15
+ this.duration += duration;
16
+ const seconds = this.duration / 1000000000n;
17
+ this.seconds = Number(seconds);
18
+ const dateRest = this.duration - seconds * 1000000000n;
19
+ this.milliSeconds = Number(dateRest) / 1000000;
20
+ }
21
+
22
+ sub(duration) {
23
+ this.duration -= duration;
24
+ const seconds = this.duration / 1000000000n;
25
+ this.seconds = Number(seconds);
26
+ const dateRest = this.duration - seconds * 1000000000n;
27
+ this.milliSeconds = Number(dateRest) / 1000000;
28
+ }
29
+
30
+ getDuration() {
31
+ if(0 !== this.seconds) {
32
+ return `${this.seconds}s ${this.milliSeconds.toFixed(3).toString().padStart(7, '0')}ms`;
33
+ }
34
+ else {
35
+ return `${this.milliSeconds.toFixed(3).toString()}ms`;
36
+ }
37
+ }
38
+ }
39
+
40
+
41
+ module.exports = HighResolutionDuration;