@nu-art/ts-common 0.400.5 → 0.400.6

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 (157) hide show
  1. package/consts/consts.js +0 -1
  2. package/core/application.js +0 -1
  3. package/core/debug-flags.js +0 -1
  4. package/core/dispatcher.js +0 -1
  5. package/core/error-handling.js +0 -1
  6. package/core/exceptions/exceptions.js +0 -1
  7. package/core/exceptions/http-codes.js +0 -1
  8. package/core/exceptions/types.js +0 -1
  9. package/core/logger/BeLogged.js +0 -1
  10. package/core/logger/LogClient.js +0 -1
  11. package/core/logger/LogClient_BaseRotate.js +0 -1
  12. package/core/logger/LogClient_Browser.js +0 -1
  13. package/core/logger/LogClient_BrowserGroups.js +0 -1
  14. package/core/logger/LogClient_ConsoleProxy.js +0 -1
  15. package/core/logger/LogClient_File.js +0 -1
  16. package/core/logger/LogClient_Function.js +0 -1
  17. package/core/logger/LogClient_MemBuffer.js +0 -1
  18. package/core/logger/LogClient_Terminal.js +0 -1
  19. package/core/logger/Logger.js +0 -1
  20. package/core/logger/types.js +0 -1
  21. package/core/logger/utils.js +0 -1
  22. package/core/module-manager.js +0 -1
  23. package/core/module.js +0 -1
  24. package/csv.js +0 -1
  25. package/db/consts.js +0 -1
  26. package/db/dependencies-test.js +0 -1
  27. package/db/types.js +0 -1
  28. package/esm.js +0 -1
  29. package/index.d.ts +1 -0
  30. package/index.js +1 -1
  31. package/mem-storage/MemStorage.js +0 -1
  32. package/mem-storage/index.js +0 -1
  33. package/modules/CSVModule.js +0 -1
  34. package/modules/CSVModuleV3.js +0 -1
  35. package/modules/CliParamsModule.js +0 -1
  36. package/modules/JSONCSVModule.js +0 -1
  37. package/modules/csv-serializer.js +0 -1
  38. package/package.json +2 -4
  39. package/replacer-v2/ReplacerV2.js +0 -1
  40. package/test-index.js +0 -1
  41. package/testing/consts.js +0 -1
  42. package/testing/test-template.test.js +0 -1
  43. package/testing/types.js +0 -1
  44. package/testing/workspace-creator.d.ts +5 -3
  45. package/testing/workspace-creator.js +29 -12
  46. package/tools/Replacer.js +0 -1
  47. package/tools/get-log-style.js +0 -1
  48. package/utils/FileSystemUtils.js +0 -1
  49. package/utils/array-tools.js +0 -1
  50. package/utils/conflict-tools.js +0 -1
  51. package/utils/crypto-tools.js +0 -1
  52. package/utils/date-time-tools.js +0 -1
  53. package/utils/db-object-tools.js +0 -1
  54. package/utils/debounce.d.ts +32 -0
  55. package/utils/debounce.js +115 -0
  56. package/utils/exception-tools.js +0 -1
  57. package/utils/filter-tools.js +0 -1
  58. package/utils/hash-tools.js +0 -1
  59. package/utils/index.js +0 -1
  60. package/utils/json-tools.js +0 -1
  61. package/utils/merge-tools.js +0 -1
  62. package/utils/mimetype-tools.js +0 -1
  63. package/utils/number-tools.d.ts +1 -0
  64. package/utils/number-tools.js +3 -1
  65. package/utils/object-tools.js +0 -1
  66. package/utils/promise-tools.js +0 -1
  67. package/utils/query-params.js +0 -1
  68. package/utils/queue-v2.js +0 -1
  69. package/utils/queue.js +0 -1
  70. package/utils/random-tools.js +0 -1
  71. package/utils/storage-capacity-tools.js +0 -1
  72. package/utils/string-tools.js +0 -1
  73. package/utils/time-proxy.js +0 -1
  74. package/utils/tools.d.ts +1 -0
  75. package/utils/tools.js +11 -1
  76. package/utils/types.js +0 -1
  77. package/utils/ui-tools.js +0 -1
  78. package/utils/url-tools.js +0 -1
  79. package/utils/version-tools.js +0 -1
  80. package/validator/type-validators.js +0 -1
  81. package/validator/validator-core.js +0 -1
  82. package/validator/validators.js +0 -1
  83. package/consts/consts.js.map +0 -1
  84. package/core/application.js.map +0 -1
  85. package/core/debug-flags.js.map +0 -1
  86. package/core/dispatcher.js.map +0 -1
  87. package/core/error-handling.js.map +0 -1
  88. package/core/exceptions/exceptions.js.map +0 -1
  89. package/core/exceptions/http-codes.js.map +0 -1
  90. package/core/exceptions/types.js.map +0 -1
  91. package/core/logger/BeLogged.js.map +0 -1
  92. package/core/logger/LogClient.js.map +0 -1
  93. package/core/logger/LogClient_BaseRotate.js.map +0 -1
  94. package/core/logger/LogClient_Browser.js.map +0 -1
  95. package/core/logger/LogClient_BrowserGroups.js.map +0 -1
  96. package/core/logger/LogClient_ConsoleProxy.js.map +0 -1
  97. package/core/logger/LogClient_File.js.map +0 -1
  98. package/core/logger/LogClient_Function.js.map +0 -1
  99. package/core/logger/LogClient_MemBuffer.js.map +0 -1
  100. package/core/logger/LogClient_Terminal.js.map +0 -1
  101. package/core/logger/Logger.js.map +0 -1
  102. package/core/logger/types.js.map +0 -1
  103. package/core/logger/utils.js.map +0 -1
  104. package/core/module-manager.js.map +0 -1
  105. package/core/module.js.map +0 -1
  106. package/csv.js.map +0 -1
  107. package/db/consts.js.map +0 -1
  108. package/db/dependencies-test.js.map +0 -1
  109. package/db/types.js.map +0 -1
  110. package/esm.js.map +0 -1
  111. package/index.js.map +0 -1
  112. package/mem-storage/MemStorage.js.map +0 -1
  113. package/mem-storage/index.js.map +0 -1
  114. package/modules/CSVModule.js.map +0 -1
  115. package/modules/CSVModuleV3.js.map +0 -1
  116. package/modules/CliParamsModule.js.map +0 -1
  117. package/modules/JSONCSVModule.js.map +0 -1
  118. package/modules/csv-serializer.js.map +0 -1
  119. package/replacer-v2/ReplacerV2.js.map +0 -1
  120. package/test-index.js.map +0 -1
  121. package/testing/consts.js.map +0 -1
  122. package/testing/test-template.test.js.map +0 -1
  123. package/testing/types.js.map +0 -1
  124. package/testing/workspace-creator.js.map +0 -1
  125. package/tools/Replacer.js.map +0 -1
  126. package/tools/get-log-style.js.map +0 -1
  127. package/utils/FileSystemUtils.js.map +0 -1
  128. package/utils/array-tools.js.map +0 -1
  129. package/utils/conflict-tools.js.map +0 -1
  130. package/utils/crypto-tools.js.map +0 -1
  131. package/utils/date-time-tools.js.map +0 -1
  132. package/utils/db-object-tools.js.map +0 -1
  133. package/utils/exception-tools.js.map +0 -1
  134. package/utils/filter-tools.js.map +0 -1
  135. package/utils/hash-tools.js.map +0 -1
  136. package/utils/index.js.map +0 -1
  137. package/utils/json-tools.js.map +0 -1
  138. package/utils/merge-tools.js.map +0 -1
  139. package/utils/mimetype-tools.js.map +0 -1
  140. package/utils/number-tools.js.map +0 -1
  141. package/utils/object-tools.js.map +0 -1
  142. package/utils/promise-tools.js.map +0 -1
  143. package/utils/query-params.js.map +0 -1
  144. package/utils/queue-v2.js.map +0 -1
  145. package/utils/queue.js.map +0 -1
  146. package/utils/random-tools.js.map +0 -1
  147. package/utils/storage-capacity-tools.js.map +0 -1
  148. package/utils/string-tools.js.map +0 -1
  149. package/utils/time-proxy.js.map +0 -1
  150. package/utils/tools.js.map +0 -1
  151. package/utils/types.js.map +0 -1
  152. package/utils/ui-tools.js.map +0 -1
  153. package/utils/url-tools.js.map +0 -1
  154. package/utils/version-tools.js.map +0 -1
  155. package/validator/type-validators.js.map +0 -1
  156. package/validator/validator-core.js.map +0 -1
  157. package/validator/validators.js.map +0 -1
package/consts/consts.js CHANGED
@@ -16,4 +16,3 @@
16
16
  * limitations under the License.
17
17
  */
18
18
  export const _U = undefined;
19
- //# sourceMappingURL=consts.js.map
@@ -30,4 +30,3 @@ export class Application extends ModuleManager {
30
30
  .catch((err) => this.logError("Error", err));
31
31
  }
32
32
  }
33
- //# sourceMappingURL=application.js.map
@@ -77,4 +77,3 @@ export class DebugFlags {
77
77
  this.instance.AllDebugFlags[newKey] = flag;
78
78
  }
79
79
  }
80
- //# sourceMappingURL=debug-flags.js.map
@@ -73,4 +73,3 @@ export class Dispatcher extends Processor {
73
73
  });
74
74
  }
75
75
  }
76
- //# sourceMappingURL=dispatcher.js.map
@@ -33,4 +33,3 @@ export const ServerErrorSeverity_Ordinal = [
33
33
  ];
34
34
  export const dispatch_onApplicationNotification = new Dispatcher('__processApplicationNotification');
35
35
  export const dispatch_onApplicationException = new Dispatcher('__processApplicationException');
36
- //# sourceMappingURL=error-handling.js.map
@@ -227,4 +227,3 @@ export class ApiException extends CustomException {
227
227
  return typeof causeOrMessage != 'string' ? causeOrMessage : cause;
228
228
  }
229
229
  }
230
- //# sourceMappingURL=exceptions.js.map
@@ -94,4 +94,3 @@ export const HttpCodes = {
94
94
  MUST_NEVER_HAPPENED: 599,
95
95
  },
96
96
  };
97
- //# sourceMappingURL=http-codes.js.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=types.js.map
@@ -52,4 +52,3 @@ class BeLogged_Class {
52
52
  }
53
53
  }
54
54
  export const BeLogged = new BeLogged_Class();
55
- //# sourceMappingURL=BeLogged.js.map
@@ -60,4 +60,3 @@ export const DefaultLogPrefixComposer = (tag, level) => {
60
60
  const date = _logger_finalDate.toISOString().replace(/T/, '_').replace(/Z/, '').substring(0, 23);
61
61
  return ` ${date} ${_logger_getPrefix(level)} ${tag}: `;
62
62
  };
63
- //# sourceMappingURL=LogClient.js.map
@@ -57,4 +57,3 @@ export class LogClient_BaseRotate extends LogClient {
57
57
  this.prepare();
58
58
  }
59
59
  }
60
- //# sourceMappingURL=LogClient_BaseRotate.js.map
@@ -73,4 +73,3 @@ class LogClient_Browser_class extends LogClient {
73
73
  }
74
74
  }
75
75
  export const LogClient_Browser = new LogClient_Browser_class();
76
- //# sourceMappingURL=LogClient_Browser.js.map
@@ -84,4 +84,3 @@ class LogClient_BrowserGroups_Class extends LogClient {
84
84
  };
85
85
  }
86
86
  export const LogClient_BrowserGroups = new LogClient_BrowserGroups_Class();
87
- //# sourceMappingURL=LogClient_BrowserGroups.js.map
@@ -86,4 +86,3 @@ export class LogClient_ConsoleProxy extends LogClient {
86
86
  }
87
87
  }
88
88
  }
89
- //# sourceMappingURL=LogClient_ConsoleProxy.js.map
@@ -53,4 +53,3 @@ export class LogClient_File extends LogClient_BaseRotate {
53
53
  this.buffer = fs.createWriteStream(this.getFileName(), { flags: 'a' });
54
54
  }
55
55
  }
56
- //# sourceMappingURL=LogClient_File.js.map
@@ -50,4 +50,3 @@ class LogClient_Function_class extends LogClient {
50
50
  }
51
51
  }
52
52
  export const LogClient_Function = new LogClient_Function_class();
53
- //# sourceMappingURL=LogClient_Function.js.map
@@ -79,4 +79,3 @@ export class LogClient_MemBuffer extends LogClient_BaseRotate {
79
79
  this.keepNaturalColors = keepNaturalColors;
80
80
  }
81
81
  }
82
- //# sourceMappingURL=LogClient_MemBuffer.js.map
@@ -53,4 +53,3 @@ class LogClient_Terminal_class extends LogClient {
53
53
  }
54
54
  }
55
55
  export const LogClient_Terminal = new LogClient_Terminal_class();
56
- //# sourceMappingURL=LogClient_Terminal.js.map
@@ -127,4 +127,3 @@ export class StaticLogger {
127
127
  return this._DEBUG_FLAG.canLog(level);
128
128
  }
129
129
  }
130
- //# sourceMappingURL=Logger.js.map
@@ -30,4 +30,3 @@ export const LogLevelOrdinal = [
30
30
  LogLevel.Warning,
31
31
  LogLevel.Error,
32
32
  ];
33
- //# sourceMappingURL=types.js.map
@@ -69,4 +69,3 @@ export function _logger_logException(error, fullStack = '') {
69
69
  export function _logger_indentNewLineBy(linePrefix, input) {
70
70
  return linePrefix + input.replace(/\n/g, `\n${linePrefix}`);
71
71
  }
72
- //# sourceMappingURL=utils.js.map
@@ -127,4 +127,3 @@ export class ModuleManager extends Logger {
127
127
  return '';
128
128
  }
129
129
  }
130
- //# sourceMappingURL=module-manager.js.map
package/core/module.js CHANGED
@@ -103,4 +103,3 @@ export class Module extends Logger {
103
103
  // ignorance is bliss
104
104
  }
105
105
  }
106
- //# sourceMappingURL=module.js.map
package/csv.js CHANGED
@@ -17,4 +17,3 @@
17
17
  */
18
18
  export * from './modules/CSVModule.js';
19
19
  export * from './modules/CSVModuleV3.js';
20
- //# sourceMappingURL=csv.js.map
package/db/consts.js CHANGED
@@ -14,4 +14,3 @@ export const MetaData_DBPointer = {
14
14
  description: 'The unique id of the item',
15
15
  }
16
16
  };
17
- //# sourceMappingURL=consts.js.map
@@ -3,4 +3,3 @@ const pah = {
3
3
  'a.yId': { dbName: 'y' }
4
4
  };
5
5
  export {};
6
- //# sourceMappingURL=dependencies-test.js.map
package/db/types.js CHANGED
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=types.js.map
package/esm.js CHANGED
@@ -1,4 +1,3 @@
1
1
  import { fileURLToPath } from 'node:url';
2
2
  import path from 'node:path';
3
3
  export const ___dirname = (metaUrl) => path.dirname(fileURLToPath(metaUrl));
4
- //# sourceMappingURL=esm.js.map
package/index.d.ts CHANGED
@@ -42,6 +42,7 @@ export * from './utils/ui-tools.js';
42
42
  export * from './utils/json-tools.js';
43
43
  export * from './utils/promise-tools.js';
44
44
  export * from './utils/url-tools.js';
45
+ export * from './utils/debounce.js';
45
46
  export * from './validator/validator-core.js';
46
47
  export * from './validator/validators.js';
47
48
  export * from './validator/type-validators.js';
package/index.js CHANGED
@@ -59,10 +59,10 @@ export * from './utils/ui-tools.js';
59
59
  export * from './utils/json-tools.js';
60
60
  export * from './utils/promise-tools.js';
61
61
  export * from './utils/url-tools.js';
62
+ export * from './utils/debounce.js';
62
63
  export * from './validator/validator-core.js';
63
64
  export * from './validator/validators.js';
64
65
  export * from './validator/type-validators.js';
65
66
  export * from './consts/consts.js';
66
67
  export * from './modules/CliParamsModule.js';
67
68
  export * from './modules/csv-serializer.js';
68
- //# sourceMappingURL=index.js.map
@@ -99,4 +99,3 @@ export class MemKey {
99
99
  return asyncLocalStorage.getStore().set(this, merge(currentValue, value));
100
100
  };
101
101
  }
102
- //# sourceMappingURL=MemStorage.js.map
@@ -1,2 +1 @@
1
1
  export * from './MemStorage.js';
2
- //# sourceMappingURL=index.js.map
@@ -137,4 +137,3 @@ class CSVModule_Class extends Module {
137
137
  }
138
138
  }
139
139
  export const CSVModule = new CSVModule_Class();
140
- //# sourceMappingURL=CSVModule.js.map
@@ -80,4 +80,3 @@ export class CSVModuleV3_Class extends Module {
80
80
  };
81
81
  }
82
82
  export const CSVModuleV3 = new CSVModuleV3_Class();
83
- //# sourceMappingURL=CSVModuleV3.js.map
@@ -64,4 +64,3 @@ class CliParamsModule_Class extends Module {
64
64
  };
65
65
  }
66
66
  export const CliParamsModule = new CliParamsModule_Class();
67
- //# sourceMappingURL=CliParamsModule.js.map
@@ -58,4 +58,3 @@ export class JSONCSVModule_Class extends CSVModuleV3_Class {
58
58
  });
59
59
  };
60
60
  }
61
- //# sourceMappingURL=JSONCSVModule.js.map
@@ -40,4 +40,3 @@ export function csvSerializer(items, _csvProps) {
40
40
  outputRows.push(...rowsData);
41
41
  return outputRows.reduce((content, row) => `${content}${row}${csvProps.lineSeparator}`, '').slice(0, -1);
42
42
  }
43
- //# sourceMappingURL=csv-serializer.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nu-art/ts-common",
3
- "version": "0.400.5",
3
+ "version": "0.400.6",
4
4
  "description": "js and ts infra",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -36,9 +36,7 @@
36
36
  "node-forge": "^1.2.1",
37
37
  "uuid": "^9.0.0",
38
38
  "csv-parser": "^2.3.3",
39
- "xlsx": "^0.18.5",
40
- "jose": "^5.0.0",
41
- "pbkdf2": "3.1.2"
39
+ "jose": "^5.0.0"
42
40
  },
43
41
  "devDependencies": {
44
42
  "@types/mocha": "^10.0.6",
@@ -14,4 +14,3 @@ export class ReplacerV2 {
14
14
  return filterInstances(matches.map((param) => param.match(ReplacerV2.Regexp_param)?.[1]));
15
15
  }
16
16
  }
17
- //# sourceMappingURL=ReplacerV2.js.map
package/test-index.js CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from './testing/types.js';
2
2
  export * from './testing/consts.js';
3
- //# sourceMappingURL=test-index.js.map
package/testing/consts.js CHANGED
@@ -78,4 +78,3 @@ export const expectFailAsync = async (action) => {
78
78
  }
79
79
  };
80
80
  export const dispatcher_resetTests = new Dispatcher('__resetForTests');
81
- //# sourceMappingURL=consts.js.map
@@ -39,4 +39,3 @@ describe('template', () => {
39
39
  });
40
40
  });
41
41
  });
42
- //# sourceMappingURL=test-template.test.js.map
package/testing/types.js CHANGED
@@ -16,4 +16,3 @@
16
16
  * limitations under the License.
17
17
  */
18
18
  export {};
19
- //# sourceMappingURL=types.js.map
@@ -1,10 +1,12 @@
1
1
  import { Logger } from '../core/logger/Logger.js';
2
+ import { StringMap } from '../utils/index.js';
2
3
  export declare class TestWorkspaceCreator extends Logger {
3
4
  private readonly pathToFixtures;
4
5
  private readonly pathToWorkspace;
5
6
  constructor(pathToFixtures: string, pathToWorkspace: string);
6
- setupWorkspace(fixtures: string[], relativePath?: string, clean?: boolean): void;
7
- clearWorkspace(relativePathInWorkspace?: string): void;
8
- extractFixture(pathToFixture: string, relativePathInWorkspace?: string): void;
7
+ setupWorkspace(fixtures: string[], relativePath?: string, clean?: boolean): Promise<void>;
8
+ setupWorkspace(fixtures: string[], params: StringMap, relativePath?: string, clean?: boolean): Promise<void>;
9
+ clearWorkspace(relativePathInWorkspace?: string): Promise<void>;
10
+ extractFixture(pathToFixture: string, relativePathInWorkspace?: string, params?: StringMap): Promise<void>;
9
11
  }
10
12
  export declare function setupWorkspace(pathToWorkspaceFile: string, outputRootDir: string, clean?: boolean): void;
@@ -1,6 +1,7 @@
1
- import { mkdirSync, readFileSync, writeFileSync, rmSync } from 'fs';
1
+ import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'fs';
2
2
  import { dirname, resolve } from 'path';
3
3
  import { Logger } from '../core/logger/Logger.js';
4
+ import { FileSystemUtils } from '../utils/FileSystemUtils.js';
4
5
  const FILE_HEADER_REGEX = /^\/\/ file: (.+)$/gm;
5
6
  const INNER_FILE_HEADER_REGEX = /^(\/\/)*?\/\/\/\/ file:/gm;
6
7
  export class TestWorkspaceCreator extends Logger {
@@ -11,20 +12,38 @@ export class TestWorkspaceCreator extends Logger {
11
12
  this.pathToFixtures = pathToFixtures;
12
13
  this.pathToWorkspace = pathToWorkspace;
13
14
  }
14
- setupWorkspace(fixtures, relativePath = '', clean = true) {
15
- if (clean)
16
- this.clearWorkspace(relativePath);
15
+ async setupWorkspace(fixtures, params, relativePath, clean) {
16
+ let _clean = clean;
17
+ let _relativePath;
18
+ let _params;
19
+ if (typeof relativePath === 'boolean') {
20
+ _clean = relativePath;
21
+ }
22
+ else if (typeof relativePath === 'string') {
23
+ _relativePath = relativePath;
24
+ }
25
+ if (typeof params === 'string') {
26
+ _relativePath = params;
27
+ _params = {};
28
+ }
29
+ else {
30
+ _params = params;
31
+ }
32
+ _relativePath = _relativePath ?? '';
33
+ _clean = _clean ?? true;
34
+ if (_clean)
35
+ await this.clearWorkspace(_relativePath);
17
36
  for (const fixture of fixtures) {
18
- this.extractFixture(resolve(this.pathToFixtures, fixture), relativePath);
37
+ await this.extractFixture(resolve(this.pathToFixtures, fixture), _relativePath, _params);
19
38
  }
20
39
  }
21
- clearWorkspace(relativePathInWorkspace = '') {
40
+ async clearWorkspace(relativePathInWorkspace = '') {
22
41
  const path = resolve(this.pathToWorkspace, relativePathInWorkspace);
23
42
  this.logWarning(`Deleting folder: ${path}`);
24
- rmSync(path, { recursive: true, force: true });
43
+ await FileSystemUtils.folder.delete(path);
25
44
  }
26
- extractFixture(pathToFixture, relativePathInWorkspace = '') {
27
- const content = readFileSync(pathToFixture, 'utf8');
45
+ async extractFixture(pathToFixture, relativePathInWorkspace = '', params = {}) {
46
+ const content = await FileSystemUtils.file.template.read(pathToFixture, params);
28
47
  const matches = [...content.matchAll(FILE_HEADER_REGEX)];
29
48
  if (matches.length === 0) {
30
49
  this.logError('No matching file headers found. Aborting.');
@@ -43,8 +62,7 @@ export class TestWorkspaceCreator extends Logger {
43
62
  .slice(startIndex + currentMatch[0].length, endIndex)
44
63
  .trimStart();
45
64
  fileContent = fileContent.replace(INNER_FILE_HEADER_REGEX, '\$1// file:');
46
- mkdirSync(dirname(targetPath), { recursive: true });
47
- writeFileSync(targetPath, fileContent);
65
+ await FileSystemUtils.file.write(targetPath, fileContent);
48
66
  this.logVerbose(`Wrote: ${targetPath}`);
49
67
  }
50
68
  }
@@ -76,4 +94,3 @@ export function setupWorkspace(pathToWorkspaceFile, outputRootDir, clean = true)
76
94
  console.log(`Wrote: ${targetPath}`);
77
95
  }
78
96
  }
79
- //# sourceMappingURL=workspace-creator.js.map
package/tools/Replacer.js CHANGED
@@ -140,4 +140,3 @@ export class Replacer extends Logger {
140
140
  // this.logDebug(value);
141
141
  }
142
142
  }
143
- //# sourceMappingURL=Replacer.js.map
@@ -32,4 +32,3 @@ export function getLogStyle(...styleObj) {
32
32
  });
33
33
  return style;
34
34
  }
35
- //# sourceMappingURL=get-log-style.js.map
@@ -171,4 +171,3 @@ export const FileSystemUtils = {
171
171
  }
172
172
  }
173
173
  };
174
- //# sourceMappingURL=FileSystemUtils.js.map
@@ -303,4 +303,3 @@ export function getMin(arr, mapper = (item) => item) {
303
303
  const sorted = sortArray(arr, mapper);
304
304
  return sorted[0];
305
305
  }
306
- //# sourceMappingURL=array-tools.js.map
@@ -1,3 +1,2 @@
1
1
  export const findConflicts = (origin, ours, theirs) => {
2
2
  };
3
- //# sourceMappingURL=conflict-tools.js.map
@@ -122,4 +122,3 @@ export const TEST_JwtTools = {
122
122
  beforeAll: TEST_JwtTools_BeforeAll,
123
123
  afterAll: TEST_JwtTools_AfterAll,
124
124
  };
125
- //# sourceMappingURL=crypto-tools.js.map
@@ -250,4 +250,3 @@ export function timeCounter() {
250
250
  }
251
251
  };
252
252
  }
253
- //# sourceMappingURL=date-time-tools.js.map
@@ -32,4 +32,3 @@ export function keepPartialObject(instance, keys) {
32
32
  return objectToRet;
33
33
  }, {});
34
34
  }
35
- //# sourceMappingURL=db-object-tools.js.map
@@ -0,0 +1,32 @@
1
+ import { Logger } from '../core/logger/Logger.js';
2
+ export declare class Debounce<Args extends any[], Response> extends Logger {
3
+ private action;
4
+ private readonly waitMs;
5
+ private readonly maxWaitMs?;
6
+ private triggerIndex;
7
+ private waitTimer?;
8
+ private maxTimer?;
9
+ private latestArgs;
10
+ private actionInProgress;
11
+ private triggerPending;
12
+ constructor(action: (...args: Args) => Response, waitMs: number, maxWaitMs?: number);
13
+ private validate_WaitMs;
14
+ private validate_MaxWaitMs;
15
+ private clearTimers;
16
+ private executeAction;
17
+ /** Schedule the action to be performed (fire-and-forget). */
18
+ trigger(...args: Args): void;
19
+ /**
20
+ * Returns whether an action is currently scheduled
21
+ */
22
+ isScheduled(): boolean;
23
+ /**
24
+ * Run immediately if scheduled and return the action's value.
25
+ * - Returns Response when something was scheduled, else undefined.
26
+ * - If action throws sync here, it throws to the caller.
27
+ * - If action returns a rejected Promise, caller handles it.
28
+ */
29
+ flush(): Response | undefined;
30
+ /** Cancel any scheduled run. (Does not cancel in-flight.) */
31
+ clear(): void;
32
+ }
@@ -0,0 +1,115 @@
1
+ import { BadImplementationException } from '../core/exceptions/exceptions.js';
2
+ import { Logger } from '../core/logger/Logger.js';
3
+ import { isPromise } from './promise-tools.js';
4
+ import { exists } from './tools.js';
5
+ export class Debounce extends Logger {
6
+ action;
7
+ waitMs;
8
+ maxWaitMs;
9
+ triggerIndex = 0;
10
+ waitTimer;
11
+ maxTimer;
12
+ latestArgs = [];
13
+ actionInProgress = false;
14
+ triggerPending = false;
15
+ constructor(action, waitMs, maxWaitMs) {
16
+ super('Debounce');
17
+ this.validate_WaitMs(waitMs);
18
+ this.validate_MaxWaitMs(waitMs, maxWaitMs);
19
+ this.action = action;
20
+ this.waitMs = waitMs;
21
+ this.maxWaitMs = maxWaitMs;
22
+ }
23
+ //######################### Validation #########################
24
+ validate_WaitMs(waitMs) {
25
+ if (waitMs < 0)
26
+ throw new BadImplementationException('waitMs value must be >= 0');
27
+ }
28
+ validate_MaxWaitMs(waitMs, maxWaitMs) {
29
+ if (!exists(maxWaitMs))
30
+ return;
31
+ if (maxWaitMs <= 0)
32
+ throw new BadImplementationException('maxWaitMs value must be > 0');
33
+ if (maxWaitMs < waitMs)
34
+ this.logWarning('maxWaitMs < waitMs; the \'max\' may never matter');
35
+ }
36
+ //######################### Internal Logic #########################
37
+ clearTimers() {
38
+ if (this.waitTimer) {
39
+ clearTimeout(this.waitTimer);
40
+ this.waitTimer = undefined;
41
+ }
42
+ if (this.maxTimer) {
43
+ clearTimeout(this.maxTimer);
44
+ this.maxTimer = undefined;
45
+ }
46
+ }
47
+ executeAction(triggerIndex, immediate) {
48
+ if (triggerIndex !== this.triggerIndex)
49
+ return;
50
+ this.triggerIndex++;
51
+ const args = this.latestArgs ?? [];
52
+ this.clearTimers();
53
+ const result = this.action(...args);
54
+ if (immediate)
55
+ return result;
56
+ //Set up chain triggering if the action is asynchronous.
57
+ if (isPromise(result)) {
58
+ this.actionInProgress = true;
59
+ Promise.resolve(result).finally(() => {
60
+ this.actionInProgress = false;
61
+ //Immediately execute the action again if debounce was triggered during the current run
62
+ if (this.triggerPending) {
63
+ this.triggerPending = false;
64
+ void this.executeAction(this.triggerIndex);
65
+ }
66
+ });
67
+ }
68
+ }
69
+ //######################### Public Logic #########################
70
+ /** Schedule the action to be performed (fire-and-forget). */
71
+ trigger(...args) {
72
+ this.latestArgs = args;
73
+ //If action is in progress, queue up immediate trigger
74
+ if (this.actionInProgress) {
75
+ this.triggerPending = true;
76
+ return;
77
+ }
78
+ // Normal debounce behavior while idle:
79
+ //Reset waitTimer
80
+ if (this.waitTimer)
81
+ clearTimeout(this.waitTimer);
82
+ const triggerIndex = this.triggerIndex;
83
+ this.waitTimer = setTimeout(() => {
84
+ void this.executeAction(triggerIndex);
85
+ }, this.waitMs);
86
+ //Set maxWaitTimer if configured and does not currently exist
87
+ if (exists(this.maxWaitMs) && !exists(this.maxTimer))
88
+ this.maxTimer = setTimeout(() => {
89
+ void this.executeAction(triggerIndex);
90
+ }, this.maxWaitMs);
91
+ }
92
+ /**
93
+ * Returns whether an action is currently scheduled
94
+ */
95
+ isScheduled() {
96
+ return exists(this.waitTimer ?? this.maxTimer);
97
+ }
98
+ /**
99
+ * Run immediately if scheduled and return the action's value.
100
+ * - Returns Response when something was scheduled, else undefined.
101
+ * - If action throws sync here, it throws to the caller.
102
+ * - If action returns a rejected Promise, caller handles it.
103
+ */
104
+ flush() {
105
+ if (!this.isScheduled())
106
+ return void this.logInfo('Not scheduled');
107
+ return this.executeAction(this.triggerIndex, true);
108
+ }
109
+ /** Cancel any scheduled run. (Does not cancel in-flight.) */
110
+ clear() {
111
+ this.clearTimers();
112
+ this.triggerIndex++;
113
+ this.triggerPending = false;
114
+ }
115
+ }
@@ -13,4 +13,3 @@ const allExceptions = [
13
13
  export function isCustomException(e) {
14
14
  return allExceptions.some(exc => !!isErrorOfType(e, exc));
15
15
  }
16
- //# sourceMappingURL=exception-tools.js.map
@@ -208,4 +208,3 @@ export class Filter {
208
208
  return this;
209
209
  }
210
210
  }
211
- //# sourceMappingURL=filter-tools.js.map
@@ -44,4 +44,3 @@ export function encode(data, encoding = "base64") {
44
44
  export function decode(encoded, from = "base64", to = "utf8") {
45
45
  return Buffer.from(encoded, from).toString(to);
46
46
  }
47
- //# sourceMappingURL=hash-tools.js.map
package/utils/index.js CHANGED
@@ -25,4 +25,3 @@ export * from "./types.js";
25
25
  export * from "./ui-tools.js";
26
26
  export * from "./url-tools.js";
27
27
  export * from "./version-tools.js";
28
- //# sourceMappingURL=index.js.map
@@ -11,4 +11,3 @@ export function isValidJson(_string) {
11
11
  export function prettifyJson(obj) {
12
12
  return __stringify(obj, true);
13
13
  }
14
- //# sourceMappingURL=json-tools.js.map
@@ -69,4 +69,3 @@ export function merge(original, override, unsafe = false) {
69
69
  return mergeObject(original || {}, override, unsafe);
70
70
  return override;
71
71
  }
72
- //# sourceMappingURL=merge-tools.js.map
@@ -42,4 +42,3 @@ export const MimeType_GROUP_rar = [
42
42
  MimeType_rar_compressed,
43
43
  MimeType_rar_octetStream,
44
44
  ];
45
- //# sourceMappingURL=mimetype-tools.js.map
@@ -1,2 +1,3 @@
1
1
  export declare const roundNumber: (number: number, digits: number) => number;
2
2
  export declare const clamp: (min: number, num: number, max: number) => number;
3
+ export declare const numberInRange: (number: number, range: [number, number]) => boolean;
@@ -20,4 +20,6 @@ export const roundNumber = (number, digits) => {
20
20
  return Math.round(number * multiple) / multiple;
21
21
  };
22
22
  export const clamp = (min, num, max) => Math.min(Math.max(num, min), max);
23
- //# sourceMappingURL=number-tools.js.map
23
+ export const numberInRange = (number, range) => {
24
+ return range[0] <= number && number <= range[1];
25
+ };
@@ -207,4 +207,3 @@ export function deepFreeze(object) {
207
207
  }
208
208
  return Object.freeze(object);
209
209
  }
210
- //# sourceMappingURL=object-tools.js.map