@vnejs/plugins.scenario.fastforward 0.1.16 → 0.1.17
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/dist/modules/visits.d.ts +1 -1
- package/dist/modules/visits.js +10 -6
- package/package.json +1 -1
- package/src/modules/visits.ts +12 -6
package/dist/modules/visits.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { ModuleGlobalStateFastforwardVisits } from "@vnejs/contracts.scenar
|
|
|
5
5
|
import type { FastforwardPluginConstants, FastforwardPluginEvents, FastforwardPluginParams, FastforwardPluginSettings } from "../types.js";
|
|
6
6
|
export declare class FastforwardVisits extends ModuleCore<FastforwardPluginEvents, FastforwardPluginConstants, FastforwardPluginSettings, FastforwardPluginParams, ModuleGlobalStateFastforwardVisits> {
|
|
7
7
|
name: string;
|
|
8
|
-
visits:
|
|
8
|
+
visits: Set<string>;
|
|
9
9
|
subscribe: () => void;
|
|
10
10
|
init: () => Promise<void>;
|
|
11
11
|
onExec: ({ module, block, line, args, keywords }?: ScenarioExecPayload) => Promise<void>;
|
package/dist/modules/visits.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import "@vnejs/contracts.core.scenario";
|
|
2
2
|
import { ModuleCore } from "@vnejs/module.core";
|
|
3
|
+
const STORAGE_VALUE = 1;
|
|
3
4
|
export class FastforwardVisits extends ModuleCore {
|
|
4
5
|
name = "fastforward.visits";
|
|
5
|
-
visits =
|
|
6
|
+
visits = new Set();
|
|
6
7
|
subscribe = () => {
|
|
7
8
|
this.on(this.EVENTS.SCENARIO.EXEC, this.onExec);
|
|
8
9
|
this.on(this.EVENTS.FASTFORWARD.CHECK, this.onVisitCheck);
|
|
@@ -12,19 +13,22 @@ export class FastforwardVisits extends ModuleCore {
|
|
|
12
13
|
};
|
|
13
14
|
init = async () => {
|
|
14
15
|
await this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.FASTFORWARD.CHECK_VISITED, value: this.PARAMS.FASTFORWARD.DEFAULT_CHECK_VISITED });
|
|
15
|
-
this.visits = (await this.emitOne(this.EVENTS.STORAGE.GET_ALL, { module: this.name }));
|
|
16
|
+
this.visits = new Set(Object.keys((await this.emitOne(this.EVENTS.STORAGE.GET_ALL, { module: this.name }))));
|
|
16
17
|
};
|
|
17
18
|
onExec = async ({ module, block, line, args = {}, keywords = [] } = {}) => {
|
|
18
19
|
const key = (await this.emitOne(this.EVENTS.VENDORS.HASH, this.state));
|
|
19
|
-
this.visits
|
|
20
|
-
this.emit(this.EVENTS.STORAGE.SET, { module: this.name, key, value:
|
|
20
|
+
this.visits.add(key);
|
|
21
|
+
this.emit(this.EVENTS.STORAGE.SET, { module: this.name, key, value: STORAGE_VALUE });
|
|
21
22
|
this.setState({ module, block, line, args, keywords, label: this.globalState.scenario.label });
|
|
22
23
|
};
|
|
23
24
|
onVisitCheck = async () => {
|
|
24
|
-
const isAllowed = !this.shared.settings[this.SETTINGS.FASTFORWARD.CHECK_VISITED] ||
|
|
25
|
+
const isAllowed = !this.shared.settings[this.SETTINGS.FASTFORWARD.CHECK_VISITED] || this.visits.has((await this.getHash()));
|
|
25
26
|
return { isAllowed, source: this.name };
|
|
26
27
|
};
|
|
27
|
-
onClear = () =>
|
|
28
|
+
onClear = () => {
|
|
29
|
+
this.visits.clear();
|
|
30
|
+
return this.emit(this.EVENTS.STORAGE.RM_ALL, { module: this.name });
|
|
31
|
+
};
|
|
28
32
|
getHash = () => this.emitOne(this.EVENTS.VENDORS.HASH, this.state);
|
|
29
33
|
getDefaultState = () => ({ label: "", args: {}, keywords: [] });
|
|
30
34
|
}
|
package/package.json
CHANGED
package/src/modules/visits.ts
CHANGED
|
@@ -6,6 +6,8 @@ import type { FastforwardCheckResult, ModuleGlobalStateFastforwardVisits } from
|
|
|
6
6
|
|
|
7
7
|
import type { FastforwardPluginConstants, FastforwardPluginEvents, FastforwardPluginParams, FastforwardPluginSettings } from "../types.js";
|
|
8
8
|
|
|
9
|
+
const STORAGE_VALUE = 1;
|
|
10
|
+
|
|
9
11
|
export class FastforwardVisits extends ModuleCore<
|
|
10
12
|
FastforwardPluginEvents,
|
|
11
13
|
FastforwardPluginConstants,
|
|
@@ -15,7 +17,7 @@ export class FastforwardVisits extends ModuleCore<
|
|
|
15
17
|
> {
|
|
16
18
|
name = "fastforward.visits";
|
|
17
19
|
|
|
18
|
-
visits
|
|
20
|
+
visits = new Set<string>();
|
|
19
21
|
|
|
20
22
|
subscribe = () => {
|
|
21
23
|
this.on(this.EVENTS.SCENARIO.EXEC, this.onExec);
|
|
@@ -30,25 +32,29 @@ export class FastforwardVisits extends ModuleCore<
|
|
|
30
32
|
init = async () => {
|
|
31
33
|
await this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.FASTFORWARD.CHECK_VISITED, value: this.PARAMS.FASTFORWARD.DEFAULT_CHECK_VISITED });
|
|
32
34
|
|
|
33
|
-
this.visits = (await this.emitOne(this.EVENTS.STORAGE.GET_ALL, { module: this.name })) as Record<string, number
|
|
35
|
+
this.visits = new Set(Object.keys((await this.emitOne(this.EVENTS.STORAGE.GET_ALL, { module: this.name })) as Record<string, number>));
|
|
34
36
|
};
|
|
35
37
|
|
|
36
38
|
onExec = async ({ module, block, line, args = {}, keywords = [] }: ScenarioExecPayload = {}) => {
|
|
37
39
|
const key = (await this.emitOne(this.EVENTS.VENDORS.HASH, this.state)) as string;
|
|
38
40
|
|
|
39
|
-
this.visits
|
|
40
|
-
this.emit(this.EVENTS.STORAGE.SET, { module: this.name, key, value:
|
|
41
|
+
this.visits.add(key);
|
|
42
|
+
this.emit(this.EVENTS.STORAGE.SET, { module: this.name, key, value: STORAGE_VALUE });
|
|
41
43
|
|
|
42
44
|
this.setState({ module, block, line, args, keywords, label: this.globalState.scenario.label });
|
|
43
45
|
};
|
|
44
46
|
|
|
45
47
|
onVisitCheck = async () => {
|
|
46
|
-
const isAllowed = !this.shared.settings[this.SETTINGS.FASTFORWARD.CHECK_VISITED] ||
|
|
48
|
+
const isAllowed = !this.shared.settings[this.SETTINGS.FASTFORWARD.CHECK_VISITED] || this.visits.has((await this.getHash()) as string);
|
|
47
49
|
|
|
48
50
|
return { isAllowed, source: this.name } satisfies FastforwardCheckResult;
|
|
49
51
|
};
|
|
50
52
|
|
|
51
|
-
onClear = () =>
|
|
53
|
+
onClear = () => {
|
|
54
|
+
this.visits.clear();
|
|
55
|
+
|
|
56
|
+
return this.emit(this.EVENTS.STORAGE.RM_ALL, { module: this.name });
|
|
57
|
+
};
|
|
52
58
|
|
|
53
59
|
getHash = () => this.emitOne(this.EVENTS.VENDORS.HASH, this.state);
|
|
54
60
|
|