@nu-art/ts-common 0.400.5 → 0.400.7
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.
- package/consts/consts.js +0 -1
- package/core/application.js +0 -1
- package/core/debug-flags.js +0 -1
- package/core/dispatcher.js +0 -1
- package/core/error-handling.js +0 -1
- package/core/exceptions/exceptions.js +0 -1
- package/core/exceptions/http-codes.js +0 -1
- package/core/exceptions/types.js +0 -1
- package/core/logger/BeLogged.js +0 -1
- package/core/logger/LogClient.js +0 -1
- package/core/logger/LogClient_BaseRotate.js +0 -1
- package/core/logger/LogClient_Browser.js +0 -1
- package/core/logger/LogClient_BrowserGroups.js +0 -1
- package/core/logger/LogClient_ConsoleProxy.js +0 -1
- package/core/logger/LogClient_File.js +0 -1
- package/core/logger/LogClient_Function.js +0 -1
- package/core/logger/LogClient_MemBuffer.js +0 -1
- package/core/logger/LogClient_Terminal.js +0 -1
- package/core/logger/Logger.js +0 -1
- package/core/logger/types.js +0 -1
- package/core/logger/utils.js +0 -1
- package/core/module-manager.js +0 -1
- package/core/module.js +0 -1
- package/csv.js +0 -1
- package/db/consts.js +0 -1
- package/db/dependencies-test.js +0 -1
- package/db/types.js +0 -1
- package/esm.js +0 -1
- package/index.d.ts +1 -0
- package/index.js +1 -1
- package/mem-storage/MemStorage.js +0 -1
- package/mem-storage/index.js +0 -1
- package/modules/CSVModule.js +0 -1
- package/modules/CSVModuleV3.js +0 -1
- package/modules/CliParamsModule.js +0 -1
- package/modules/JSONCSVModule.js +0 -1
- package/modules/csv-serializer.js +0 -1
- package/package.json +2 -4
- package/replacer-v2/ReplacerV2.js +0 -1
- package/test-index.js +0 -1
- package/testing/consts.js +0 -1
- package/testing/test-template.test.js +0 -1
- package/testing/types.js +0 -1
- package/testing/workspace-creator.d.ts +5 -3
- package/testing/workspace-creator.js +29 -12
- package/tools/Replacer.js +0 -1
- package/tools/get-log-style.js +0 -1
- package/utils/FileSystemUtils.js +0 -1
- package/utils/array-tools.d.ts +1 -7
- package/utils/array-tools.js +0 -1
- package/utils/conflict-tools.js +0 -1
- package/utils/crypto-tools.js +0 -1
- package/utils/date-time-tools.js +0 -1
- package/utils/db-object-tools.js +0 -1
- package/utils/debounce.d.ts +32 -0
- package/utils/debounce.js +115 -0
- package/utils/exception-tools.js +0 -1
- package/utils/filter-tools.js +0 -1
- package/utils/hash-tools.js +0 -1
- package/utils/index.js +0 -1
- package/utils/json-tools.js +0 -1
- package/utils/merge-tools.js +0 -1
- package/utils/mimetype-tools.js +0 -1
- package/utils/number-tools.d.ts +1 -0
- package/utils/number-tools.js +3 -1
- package/utils/object-tools.js +0 -1
- package/utils/promise-tools.js +0 -1
- package/utils/query-params.js +0 -1
- package/utils/queue-v2.js +0 -1
- package/utils/queue.js +0 -1
- package/utils/random-tools.js +0 -1
- package/utils/storage-capacity-tools.js +0 -1
- package/utils/string-tools.js +0 -1
- package/utils/time-proxy.js +0 -1
- package/utils/tools.d.ts +1 -0
- package/utils/tools.js +11 -1
- package/utils/types.js +0 -1
- package/utils/ui-tools.js +0 -1
- package/utils/url-tools.js +0 -1
- package/utils/version-tools.js +0 -1
- package/validator/type-validators.js +0 -1
- package/validator/validator-core.js +0 -1
- package/validator/validators.js +0 -1
- package/consts/consts.js.map +0 -1
- package/core/application.js.map +0 -1
- package/core/debug-flags.js.map +0 -1
- package/core/dispatcher.js.map +0 -1
- package/core/error-handling.js.map +0 -1
- package/core/exceptions/exceptions.js.map +0 -1
- package/core/exceptions/http-codes.js.map +0 -1
- package/core/exceptions/types.js.map +0 -1
- package/core/logger/BeLogged.js.map +0 -1
- package/core/logger/LogClient.js.map +0 -1
- package/core/logger/LogClient_BaseRotate.js.map +0 -1
- package/core/logger/LogClient_Browser.js.map +0 -1
- package/core/logger/LogClient_BrowserGroups.js.map +0 -1
- package/core/logger/LogClient_ConsoleProxy.js.map +0 -1
- package/core/logger/LogClient_File.js.map +0 -1
- package/core/logger/LogClient_Function.js.map +0 -1
- package/core/logger/LogClient_MemBuffer.js.map +0 -1
- package/core/logger/LogClient_Terminal.js.map +0 -1
- package/core/logger/Logger.js.map +0 -1
- package/core/logger/types.js.map +0 -1
- package/core/logger/utils.js.map +0 -1
- package/core/module-manager.js.map +0 -1
- package/core/module.js.map +0 -1
- package/csv.js.map +0 -1
- package/db/consts.js.map +0 -1
- package/db/dependencies-test.js.map +0 -1
- package/db/types.js.map +0 -1
- package/esm.js.map +0 -1
- package/index.js.map +0 -1
- package/mem-storage/MemStorage.js.map +0 -1
- package/mem-storage/index.js.map +0 -1
- package/modules/CSVModule.js.map +0 -1
- package/modules/CSVModuleV3.js.map +0 -1
- package/modules/CliParamsModule.js.map +0 -1
- package/modules/JSONCSVModule.js.map +0 -1
- package/modules/csv-serializer.js.map +0 -1
- package/replacer-v2/ReplacerV2.js.map +0 -1
- package/test-index.js.map +0 -1
- package/testing/consts.js.map +0 -1
- package/testing/test-template.test.js.map +0 -1
- package/testing/types.js.map +0 -1
- package/testing/workspace-creator.js.map +0 -1
- package/tools/Replacer.js.map +0 -1
- package/tools/get-log-style.js.map +0 -1
- package/utils/FileSystemUtils.js.map +0 -1
- package/utils/array-tools.js.map +0 -1
- package/utils/conflict-tools.js.map +0 -1
- package/utils/crypto-tools.js.map +0 -1
- package/utils/date-time-tools.js.map +0 -1
- package/utils/db-object-tools.js.map +0 -1
- package/utils/exception-tools.js.map +0 -1
- package/utils/filter-tools.js.map +0 -1
- package/utils/hash-tools.js.map +0 -1
- package/utils/index.js.map +0 -1
- package/utils/json-tools.js.map +0 -1
- package/utils/merge-tools.js.map +0 -1
- package/utils/mimetype-tools.js.map +0 -1
- package/utils/number-tools.js.map +0 -1
- package/utils/object-tools.js.map +0 -1
- package/utils/promise-tools.js.map +0 -1
- package/utils/query-params.js.map +0 -1
- package/utils/queue-v2.js.map +0 -1
- package/utils/queue.js.map +0 -1
- package/utils/random-tools.js.map +0 -1
- package/utils/storage-capacity-tools.js.map +0 -1
- package/utils/string-tools.js.map +0 -1
- package/utils/time-proxy.js.map +0 -1
- package/utils/tools.js.map +0 -1
- package/utils/types.js.map +0 -1
- package/utils/ui-tools.js.map +0 -1
- package/utils/url-tools.js.map +0 -1
- package/utils/version-tools.js.map +0 -1
- package/validator/type-validators.js.map +0 -1
- package/validator/validator-core.js.map +0 -1
- package/validator/validators.js.map +0 -1
package/consts/consts.js
CHANGED
package/core/application.js
CHANGED
package/core/debug-flags.js
CHANGED
package/core/dispatcher.js
CHANGED
package/core/error-handling.js
CHANGED
|
@@ -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
|
package/core/exceptions/types.js
CHANGED
package/core/logger/BeLogged.js
CHANGED
package/core/logger/LogClient.js
CHANGED
package/core/logger/Logger.js
CHANGED
package/core/logger/types.js
CHANGED
package/core/logger/utils.js
CHANGED
package/core/module-manager.js
CHANGED
package/core/module.js
CHANGED
package/csv.js
CHANGED
package/db/consts.js
CHANGED
package/db/dependencies-test.js
CHANGED
package/db/types.js
CHANGED
package/esm.js
CHANGED
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
|
package/mem-storage/index.js
CHANGED
package/modules/CSVModule.js
CHANGED
package/modules/CSVModuleV3.js
CHANGED
package/modules/JSONCSVModule.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nu-art/ts-common",
|
|
3
|
-
"version": "0.400.
|
|
3
|
+
"version": "0.400.7",
|
|
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
|
-
"
|
|
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",
|
package/test-index.js
CHANGED
package/testing/consts.js
CHANGED
package/testing/types.js
CHANGED
|
@@ -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
|
-
|
|
8
|
-
|
|
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,
|
|
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
|
|
15
|
-
|
|
16
|
-
|
|
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),
|
|
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
|
-
|
|
43
|
+
await FileSystemUtils.folder.delete(path);
|
|
25
44
|
}
|
|
26
|
-
extractFixture(pathToFixture, relativePathInWorkspace = '') {
|
|
27
|
-
const content =
|
|
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
|
-
|
|
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
package/tools/get-log-style.js
CHANGED
package/utils/FileSystemUtils.js
CHANGED
package/utils/array-tools.d.ts
CHANGED
|
@@ -49,13 +49,7 @@ export declare function filterFalsy<T>(array?: (T | undefined | null | void)[]):
|
|
|
49
49
|
/**
|
|
50
50
|
* receives array and builds hashmap whom keys are decided via function and values are from array
|
|
51
51
|
* */
|
|
52
|
-
export declare function arrayToMap<T>(array: T[] | Readonly<T[]>, getKey: (item: T, index: number, map:
|
|
53
|
-
[k: string]: T;
|
|
54
|
-
}) => string | number | (string | number)[], map?: {
|
|
55
|
-
[k: string]: T;
|
|
56
|
-
}): {
|
|
57
|
-
[k: string]: T;
|
|
58
|
-
};
|
|
52
|
+
export declare function arrayToMap<T>(array: T[] | Readonly<T[]>, getKey: (item: T, index: number, map: TypedMap<T>) => string | number | (string | number)[], map?: TypedMap<T>): TypedMap<T>;
|
|
59
53
|
type KeyResolver<Input, Output = Input> = (item: Input, index: number, map: {
|
|
60
54
|
[k: string]: Output;
|
|
61
55
|
}) => string | number | (string | number)[];
|
package/utils/array-tools.js
CHANGED
package/utils/conflict-tools.js
CHANGED
package/utils/crypto-tools.js
CHANGED
package/utils/date-time-tools.js
CHANGED
package/utils/db-object-tools.js
CHANGED
|
@@ -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
|
+
}
|
package/utils/exception-tools.js
CHANGED
package/utils/filter-tools.js
CHANGED
package/utils/hash-tools.js
CHANGED
package/utils/index.js
CHANGED
package/utils/json-tools.js
CHANGED
package/utils/merge-tools.js
CHANGED
package/utils/mimetype-tools.js
CHANGED
package/utils/number-tools.d.ts
CHANGED