@vnejs/plugins.vars.counters 0.1.6 → 0.1.8

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.
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import { regPlugin } from "@vnejs/shared";
2
+ import { CONSTANTS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/plugins.vars.counters.contract";
3
+ import { Counters } from "./modules/counters.js";
4
+ import { CountersExec } from "./modules/exec.js";
5
+ regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS }, [Counters, CountersExec]);
@@ -0,0 +1,20 @@
1
+ import { Module } from "@vnejs/module";
2
+ import type { CountersPluginConstants, CountersPluginEvents, CountersPluginParams, CountersPluginSettings } from "../types.js";
3
+ import type { CountersChangePayload, CountersComparePayload, CountersExecCheckPayload, CountersExecInfoPayload, CountersExecInfoResult, CountersGetPayload, CountersSetPayload } from "../utils/counters.js";
4
+ type ChangeHandler = (oldValue?: number, value?: number) => number;
5
+ type CompareHandler = (oldValue?: number, value?: number) => boolean;
6
+ export declare class Counters extends Module<CountersPluginEvents, CountersPluginConstants, CountersPluginSettings, CountersPluginParams> {
7
+ name: string;
8
+ varsChangeHandlers: Record<string, ChangeHandler>;
9
+ varsCompareHandlers: Record<string, CompareHandler>;
10
+ subscribe: () => void;
11
+ init: () => Promise<unknown[]> | undefined;
12
+ onCounterSet: ({ name, isGlobal, value }?: CountersSetPayload) => Promise<unknown[]> | undefined;
13
+ onCounterGet: ({ name, isGlobal, state }?: CountersGetPayload) => Promise<unknown> | undefined;
14
+ onCounterChange: ({ value, execValue, action }?: CountersChangePayload) => number;
15
+ onCounterCompare: ({ value, execValue, action }?: CountersComparePayload) => boolean;
16
+ onCounterExecInfo: ({ line, keywords, state, withValue }?: CountersExecInfoPayload) => Promise<CountersExecInfoResult>;
17
+ onCounterExecCheck: ({ line, keywords, state }?: CountersExecCheckPayload) => Promise<unknown>;
18
+ onCounterExecGet: ({ line, keywords, state }?: CountersExecCheckPayload) => Promise<number>;
19
+ }
20
+ export {};
@@ -0,0 +1,51 @@
1
+ import { Module } from "@vnejs/module";
2
+ import { tokenizeExecLine } from "@vnejs/helpers";
3
+ export class Counters extends Module {
4
+ name = "vars.counters";
5
+ varsChangeHandlers = {
6
+ [this.CONST.VARS_COUNTERS.CHANGE_ACTIONS.SET]: (oldValue = 0, value = 0) => value,
7
+ [this.CONST.VARS_COUNTERS.CHANGE_ACTIONS.INC]: (oldValue = 0) => oldValue + 1,
8
+ [this.CONST.VARS_COUNTERS.CHANGE_ACTIONS.DEC]: (oldValue = 0) => oldValue - 1,
9
+ [this.CONST.VARS_COUNTERS.CHANGE_ACTIONS.ADD]: (oldValue = 0, value = 0) => oldValue + value,
10
+ [this.CONST.VARS_COUNTERS.CHANGE_ACTIONS.SUB]: (oldValue = 0, value = 0) => oldValue - value,
11
+ };
12
+ varsCompareHandlers = {
13
+ [this.CONST.VARS_COUNTERS.COMPARE_ACTIONS.MORE]: (oldValue = 0, value = 0) => oldValue > value,
14
+ [this.CONST.VARS_COUNTERS.COMPARE_ACTIONS.MORE_EQ]: (oldValue = 0, value = 0) => oldValue >= value,
15
+ [this.CONST.VARS_COUNTERS.COMPARE_ACTIONS.EQ]: (oldValue = 0, value = 0) => oldValue === value,
16
+ [this.CONST.VARS_COUNTERS.COMPARE_ACTIONS.EQ_NOT]: (oldValue = 0, value = 0) => oldValue !== value,
17
+ [this.CONST.VARS_COUNTERS.COMPARE_ACTIONS.LESS]: (oldValue = 0, value = 0) => oldValue < value,
18
+ [this.CONST.VARS_COUNTERS.COMPARE_ACTIONS.LESS_EQ]: (oldValue = 0, value = 0) => oldValue <= value,
19
+ };
20
+ subscribe = () => {
21
+ this.on(this.EVENTS.VARS_COUNTERS.SET, this.onCounterSet);
22
+ this.on(this.EVENTS.VARS_COUNTERS.GET, this.onCounterGet);
23
+ this.on(this.EVENTS.VARS_COUNTERS.CHANGE, this.onCounterChange);
24
+ this.on(this.EVENTS.VARS_COUNTERS.COMPARE, this.onCounterCompare);
25
+ this.on(this.EVENTS.VARS_COUNTERS.EXEC_INFO, this.onCounterExecInfo);
26
+ this.on(this.EVENTS.VARS_COUNTERS.EXEC_CHECK, this.onCounterExecCheck);
27
+ this.on(this.EVENTS.VARS_COUNTERS.EXEC_GET, this.onCounterExecGet);
28
+ };
29
+ init = () => this.emit(this.EVENTS.VARS.DEFAULT_REG, { type: this.CONST.VARS_COUNTERS.TYPE, value: 0 });
30
+ onCounterSet = ({ name = "", isGlobal = false, value = 0 } = {}) => this.emit(this.EVENTS.VARS.SET, { name, type: this.CONST.VARS_COUNTERS.TYPE, value, isGlobal });
31
+ onCounterGet = ({ name = "", isGlobal = false, state = null } = {}) => this.emitOne(this.EVENTS.VARS.GET, { name, type: this.CONST.VARS_COUNTERS.TYPE, isGlobal, state });
32
+ onCounterChange = ({ value = 0, execValue = 0, action = "" } = {}) => this.varsChangeHandlers[action]?.(value, execValue) ?? value;
33
+ onCounterCompare = ({ value = 0, execValue = 0, action = "" } = {}) => this.varsCompareHandlers[action]?.(value, execValue) ?? false;
34
+ onCounterExecInfo = async ({ line = "", keywords = [], state = null, withValue = true } = {}) => {
35
+ const tokens = tokenizeExecLine(line);
36
+ const name = String(tokens[0] ?? "");
37
+ const action = String(tokens[1] ?? "");
38
+ const execValue = Number(tokens[2] ?? 0);
39
+ const isGlobal = keywords.includes(this.CONST.SCENARIO.LINE_KEYWORDS.GLOBAL);
40
+ const result = { name, action, isGlobal, execValue };
41
+ return withValue ? { ...result, value: Number(await this.emitOne(this.EVENTS.VARS_COUNTERS.GET, { name, isGlobal, state })) } : result;
42
+ };
43
+ onCounterExecCheck = async ({ line = "", keywords = [], state = null } = {}) => {
44
+ const { action = "", execValue = 0, value = 0 } = (await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords, state }));
45
+ return this.emitOne(this.EVENTS.VARS_COUNTERS.COMPARE, { value, execValue, action });
46
+ };
47
+ onCounterExecGet = async ({ line = "", keywords = [], state = null } = {}) => {
48
+ const { value = 0 } = (await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords, state }));
49
+ return value;
50
+ };
51
+ }
@@ -0,0 +1,9 @@
1
+ import { Module } from "@vnejs/module";
2
+ import type { CountersPluginConstants, CountersPluginEvents, CountersPluginParams, CountersPluginSettings } from "../types.js";
3
+ import type { ScenarioLineExecPayload } from "../utils/counters.js";
4
+ export declare class CountersExec extends Module<CountersPluginEvents, CountersPluginConstants, CountersPluginSettings, CountersPluginParams> {
5
+ name: string;
6
+ init: () => Promise<[unknown[] | undefined, unknown[] | undefined]>;
7
+ onLineExecModule: ({ line, keywords }?: ScenarioLineExecPayload) => Promise<void>;
8
+ onLineExecBlock: ({ line, keywords }?: ScenarioLineExecPayload) => Promise<void>;
9
+ }
@@ -0,0 +1,20 @@
1
+ import { Module } from "@vnejs/module";
2
+ export class CountersExec extends Module {
3
+ name = "vars.counters.exec";
4
+ init = () => Promise.all([
5
+ this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { block: this.CONST.VARS_COUNTERS.EXEC_NAME, handler: this.onLineExecBlock }),
6
+ this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.CONST.VARS_COUNTERS.EXEC_NAME, handler: this.onLineExecModule }),
7
+ ]);
8
+ onLineExecModule = async ({ line = "", keywords = [] } = {}) => {
9
+ const { name = "", action = "", execValue = 0, value = 0, isGlobal = false } = (await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords }));
10
+ const newValue = Number(await this.emitOne(this.EVENTS.VARS_COUNTERS.CHANGE, { value, execValue, action }));
11
+ await this.emit(this.EVENTS.VARS_COUNTERS.SET, { name, isGlobal, value: newValue });
12
+ this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
13
+ };
14
+ onLineExecBlock = async ({ line = "", keywords = [] } = {}) => {
15
+ const { action = "", execValue = 0, value = 0 } = (await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords }));
16
+ const shouldGoInside = Boolean(await this.emitOne(this.EVENTS.VARS_COUNTERS.COMPARE, { value, execValue, action }));
17
+ await this.emit(this.EVENTS.VARS.SCENARIO, { shouldGoInside });
18
+ this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
19
+ };
20
+ }
@@ -0,0 +1,8 @@
1
+ import type { VnePluginConstantsMapRegistry, VnePluginEventsMapRegistry, VnePluginParamsMapRegistry, VnePluginSettingsMapRegistry } from "@vnejs/shared";
2
+ import type { Constants as ScenarioConstants, PluginName as ScenarioPluginName, SubscribeEvents as ScenarioSubscribeEvents } from "@vnejs/plugins.core.scenario.contract";
3
+ import type { PluginName as VarsPluginName, SubscribeEvents as VarsSubscribeEvents } from "@vnejs/plugins.vars.contract";
4
+ import type { Constants, PluginName, SubscribeEvents } from "@vnejs/plugins.vars.counters.contract";
5
+ export type CountersPluginEvents = VnePluginEventsMapRegistry & Record<PluginName, SubscribeEvents> & Record<VarsPluginName, VarsSubscribeEvents> & Record<ScenarioPluginName, ScenarioSubscribeEvents>;
6
+ export type CountersPluginConstants = VnePluginConstantsMapRegistry & Record<PluginName, Constants> & Record<ScenarioPluginName, ScenarioConstants> & Record<VarsPluginName, VnePluginConstantsMapRegistry[VarsPluginName]>;
7
+ export type CountersPluginSettings = VnePluginSettingsMapRegistry;
8
+ export type CountersPluginParams = VnePluginParamsMapRegistry;
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,50 @@
1
+ import type { ModuleGlobalStateRegistry } from "@vnejs/module";
2
+ import type { VarValue, VarsGetPayload } from "@vnejs/plugins.vars.contract";
3
+ export type CountersSetPayload = {
4
+ name?: string;
5
+ isGlobal?: boolean;
6
+ value?: number;
7
+ };
8
+ export type CountersGetPayload = {
9
+ name?: string;
10
+ isGlobal?: boolean;
11
+ state?: VarsGetPayload["state"];
12
+ };
13
+ export type CountersChangePayload = {
14
+ value?: number;
15
+ execValue?: number;
16
+ action?: string;
17
+ };
18
+ export type CountersComparePayload = {
19
+ value?: number;
20
+ execValue?: number;
21
+ action?: string;
22
+ };
23
+ export type CountersExecInfoPayload = {
24
+ line?: string;
25
+ keywords?: string[];
26
+ state?: ModuleGlobalStateRegistry | null;
27
+ withValue?: boolean;
28
+ };
29
+ export type CountersExecInfoResult = {
30
+ name: string;
31
+ action: string;
32
+ isGlobal: boolean;
33
+ execValue: number;
34
+ value?: number;
35
+ };
36
+ export type CountersExecCheckPayload = {
37
+ line?: string;
38
+ keywords?: string[];
39
+ state?: ModuleGlobalStateRegistry | null;
40
+ };
41
+ export type ScenarioLineExecPayload = {
42
+ line?: string;
43
+ keywords?: string[];
44
+ };
45
+ export type VarsSetPayload = {
46
+ name?: string;
47
+ type?: string;
48
+ value?: VarValue;
49
+ isGlobal?: boolean;
50
+ };
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,17 +1,45 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.vars.counters",
3
- "version": "0.1.6",
4
- "main": "index.js",
3
+ "version": "0.1.8",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "src",
18
+ "tsconfig.json"
19
+ ],
5
20
  "scripts": {
6
21
  "test": "echo \"Error: no test specified\" && exit 1",
22
+ "build": "npx @vnejs/monorepo package",
7
23
  "publish:major:plugin": "npm run publish:major",
8
24
  "publish:minor:plugin": "npm run publish:minor",
9
25
  "publish:patch:plugin": "npm run publish:patch",
10
- "publish:major": "npm version major && npm publish --access public",
11
- "publish:minor": "npm version minor && npm publish --access public",
12
- "publish:patch": "npm version patch && npm publish --access public"
26
+ "publish:major": "npx @vnejs/monorepo publish major --access public",
27
+ "publish:minor": "npx @vnejs/monorepo publish minor --access public",
28
+ "publish:patch": "npx @vnejs/monorepo publish patch --access public"
13
29
  },
14
30
  "author": "",
15
31
  "license": "ISC",
16
- "description": ""
32
+ "dependencies": {
33
+ "@vnejs/plugins.vars.counters.contract": "~0.0.1"
34
+ },
35
+ "peerDependencies": {
36
+ "@vnejs/helpers": "~0.1.0",
37
+ "@vnejs/module": "~0.0.1",
38
+ "@vnejs/plugins.core.scenario.contract": "~0.0.1",
39
+ "@vnejs/plugins.vars.contract": "~0.0.1",
40
+ "@vnejs/shared": "~0.0.9"
41
+ },
42
+ "devDependencies": {
43
+ "@vnejs/configs.ts-common": "~0.0.1"
44
+ }
17
45
  }
package/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { regPlugin } from "@vnejs/shared";
2
+ import { CONSTANTS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/plugins.vars.counters.contract";
3
+
4
+ import { Counters } from "./modules/counters.js";
5
+ import { CountersExec } from "./modules/exec.js";
6
+
7
+ regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS }, [Counters, CountersExec]);
@@ -0,0 +1,83 @@
1
+ import { Module } from "@vnejs/module";
2
+ import { tokenizeExecLine } from "@vnejs/helpers";
3
+
4
+ import type { CountersPluginConstants, CountersPluginEvents, CountersPluginParams, CountersPluginSettings } from "../types.js";
5
+ import type {
6
+ CountersChangePayload,
7
+ CountersComparePayload,
8
+ CountersExecCheckPayload,
9
+ CountersExecInfoPayload,
10
+ CountersExecInfoResult,
11
+ CountersGetPayload,
12
+ CountersSetPayload,
13
+ VarsSetPayload,
14
+ } from "../utils/counters.js";
15
+
16
+ type ChangeHandler = (oldValue?: number, value?: number) => number;
17
+ type CompareHandler = (oldValue?: number, value?: number) => boolean;
18
+
19
+ export class Counters extends Module<CountersPluginEvents, CountersPluginConstants, CountersPluginSettings, CountersPluginParams> {
20
+ name = "vars.counters";
21
+
22
+ varsChangeHandlers: Record<string, ChangeHandler> = {
23
+ [this.CONST.VARS_COUNTERS.CHANGE_ACTIONS.SET]: (oldValue = 0, value = 0) => value,
24
+ [this.CONST.VARS_COUNTERS.CHANGE_ACTIONS.INC]: (oldValue = 0) => oldValue + 1,
25
+ [this.CONST.VARS_COUNTERS.CHANGE_ACTIONS.DEC]: (oldValue = 0) => oldValue - 1,
26
+ [this.CONST.VARS_COUNTERS.CHANGE_ACTIONS.ADD]: (oldValue = 0, value = 0) => oldValue + value,
27
+ [this.CONST.VARS_COUNTERS.CHANGE_ACTIONS.SUB]: (oldValue = 0, value = 0) => oldValue - value,
28
+ };
29
+
30
+ varsCompareHandlers: Record<string, CompareHandler> = {
31
+ [this.CONST.VARS_COUNTERS.COMPARE_ACTIONS.MORE]: (oldValue = 0, value = 0) => oldValue > value,
32
+ [this.CONST.VARS_COUNTERS.COMPARE_ACTIONS.MORE_EQ]: (oldValue = 0, value = 0) => oldValue >= value,
33
+ [this.CONST.VARS_COUNTERS.COMPARE_ACTIONS.EQ]: (oldValue = 0, value = 0) => oldValue === value,
34
+ [this.CONST.VARS_COUNTERS.COMPARE_ACTIONS.EQ_NOT]: (oldValue = 0, value = 0) => oldValue !== value,
35
+ [this.CONST.VARS_COUNTERS.COMPARE_ACTIONS.LESS]: (oldValue = 0, value = 0) => oldValue < value,
36
+ [this.CONST.VARS_COUNTERS.COMPARE_ACTIONS.LESS_EQ]: (oldValue = 0, value = 0) => oldValue <= value,
37
+ };
38
+
39
+ subscribe = () => {
40
+ this.on(this.EVENTS.VARS_COUNTERS.SET, this.onCounterSet);
41
+ this.on(this.EVENTS.VARS_COUNTERS.GET, this.onCounterGet);
42
+ this.on(this.EVENTS.VARS_COUNTERS.CHANGE, this.onCounterChange);
43
+ this.on(this.EVENTS.VARS_COUNTERS.COMPARE, this.onCounterCompare);
44
+ this.on(this.EVENTS.VARS_COUNTERS.EXEC_INFO, this.onCounterExecInfo);
45
+ this.on(this.EVENTS.VARS_COUNTERS.EXEC_CHECK, this.onCounterExecCheck);
46
+ this.on(this.EVENTS.VARS_COUNTERS.EXEC_GET, this.onCounterExecGet);
47
+ };
48
+
49
+ init = () => this.emit(this.EVENTS.VARS.DEFAULT_REG, { type: this.CONST.VARS_COUNTERS.TYPE, value: 0 });
50
+
51
+ onCounterSet = ({ name = "", isGlobal = false, value = 0 }: CountersSetPayload = {}) =>
52
+ this.emit(this.EVENTS.VARS.SET, { name, type: this.CONST.VARS_COUNTERS.TYPE, value, isGlobal } satisfies VarsSetPayload);
53
+
54
+ onCounterGet = ({ name = "", isGlobal = false, state = null }: CountersGetPayload = {}) =>
55
+ this.emitOne(this.EVENTS.VARS.GET, { name, type: this.CONST.VARS_COUNTERS.TYPE, isGlobal, state });
56
+
57
+ onCounterChange = ({ value = 0, execValue = 0, action = "" }: CountersChangePayload = {}) => this.varsChangeHandlers[action]?.(value, execValue) ?? value;
58
+
59
+ onCounterCompare = ({ value = 0, execValue = 0, action = "" }: CountersComparePayload = {}) => this.varsCompareHandlers[action]?.(value, execValue) ?? false;
60
+
61
+ onCounterExecInfo = async ({ line = "", keywords = [], state = null, withValue = true }: CountersExecInfoPayload = {}) => {
62
+ const tokens = tokenizeExecLine(line);
63
+ const name = String(tokens[0] ?? "");
64
+ const action = String(tokens[1] ?? "");
65
+ const execValue = Number(tokens[2] ?? 0);
66
+ const isGlobal = keywords.includes(this.CONST.SCENARIO.LINE_KEYWORDS.GLOBAL);
67
+ const result: CountersExecInfoResult = { name, action, isGlobal, execValue };
68
+
69
+ return withValue ? { ...result, value: Number(await this.emitOne(this.EVENTS.VARS_COUNTERS.GET, { name, isGlobal, state })) } : result;
70
+ };
71
+
72
+ onCounterExecCheck = async ({ line = "", keywords = [], state = null }: CountersExecCheckPayload = {}) => {
73
+ const { action = "", execValue = 0, value = 0 } = (await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords, state })) as CountersExecInfoResult;
74
+
75
+ return this.emitOne(this.EVENTS.VARS_COUNTERS.COMPARE, { value, execValue, action });
76
+ };
77
+
78
+ onCounterExecGet = async ({ line = "", keywords = [], state = null }: CountersExecCheckPayload = {}) => {
79
+ const { value = 0 } = (await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords, state })) as CountersExecInfoResult;
80
+
81
+ return value;
82
+ };
83
+ }
@@ -0,0 +1,34 @@
1
+ import { Module } from "@vnejs/module";
2
+
3
+ import type { CountersPluginConstants, CountersPluginEvents, CountersPluginParams, CountersPluginSettings } from "../types.js";
4
+ import type { CountersExecInfoResult, CountersSetPayload, ScenarioLineExecPayload } from "../utils/counters.js";
5
+
6
+ export class CountersExec extends Module<CountersPluginEvents, CountersPluginConstants, CountersPluginSettings, CountersPluginParams> {
7
+ name = "vars.counters.exec";
8
+
9
+ init = () =>
10
+ Promise.all([
11
+ this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { block: this.CONST.VARS_COUNTERS.EXEC_NAME, handler: this.onLineExecBlock }),
12
+ this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.CONST.VARS_COUNTERS.EXEC_NAME, handler: this.onLineExecModule }),
13
+ ]);
14
+
15
+ onLineExecModule = async ({ line = "", keywords = [] }: ScenarioLineExecPayload = {}) => {
16
+ const { name = "", action = "", execValue = 0, value = 0, isGlobal = false } = (await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords })) as CountersExecInfoResult;
17
+
18
+ const newValue = Number(await this.emitOne(this.EVENTS.VARS_COUNTERS.CHANGE, { value, execValue, action }));
19
+
20
+ await this.emit(this.EVENTS.VARS_COUNTERS.SET, { name, isGlobal, value: newValue } satisfies CountersSetPayload);
21
+
22
+ this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
23
+ };
24
+
25
+ onLineExecBlock = async ({ line = "", keywords = [] }: ScenarioLineExecPayload = {}) => {
26
+ const { action = "", execValue = 0, value = 0 } = (await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords })) as CountersExecInfoResult;
27
+
28
+ const shouldGoInside = Boolean(await this.emitOne(this.EVENTS.VARS_COUNTERS.COMPARE, { value, execValue, action }));
29
+
30
+ await this.emit(this.EVENTS.VARS.SCENARIO, { shouldGoInside });
31
+
32
+ this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
33
+ };
34
+ }
package/src/types.ts ADDED
@@ -0,0 +1,18 @@
1
+ import type { VnePluginConstantsMapRegistry, VnePluginEventsMapRegistry, VnePluginParamsMapRegistry, VnePluginSettingsMapRegistry } from "@vnejs/shared";
2
+ import type { Constants as ScenarioConstants, PluginName as ScenarioPluginName, SubscribeEvents as ScenarioSubscribeEvents } from "@vnejs/plugins.core.scenario.contract";
3
+ import type { PluginName as VarsPluginName, SubscribeEvents as VarsSubscribeEvents } from "@vnejs/plugins.vars.contract";
4
+ import type { Constants, PluginName, SubscribeEvents } from "@vnejs/plugins.vars.counters.contract";
5
+
6
+ export type CountersPluginEvents = VnePluginEventsMapRegistry &
7
+ Record<PluginName, SubscribeEvents> &
8
+ Record<VarsPluginName, VarsSubscribeEvents> &
9
+ Record<ScenarioPluginName, ScenarioSubscribeEvents>;
10
+
11
+ export type CountersPluginConstants = VnePluginConstantsMapRegistry &
12
+ Record<PluginName, Constants> &
13
+ Record<ScenarioPluginName, ScenarioConstants> &
14
+ Record<VarsPluginName, VnePluginConstantsMapRegistry[VarsPluginName]>;
15
+
16
+ export type CountersPluginSettings = VnePluginSettingsMapRegistry;
17
+
18
+ export type CountersPluginParams = VnePluginParamsMapRegistry;
@@ -0,0 +1,59 @@
1
+ import type { ModuleGlobalStateRegistry } from "@vnejs/module";
2
+ import type { VarValue, VarsGetPayload } from "@vnejs/plugins.vars.contract";
3
+
4
+ export type CountersSetPayload = {
5
+ name?: string;
6
+ isGlobal?: boolean;
7
+ value?: number;
8
+ };
9
+
10
+ export type CountersGetPayload = {
11
+ name?: string;
12
+ isGlobal?: boolean;
13
+ state?: VarsGetPayload["state"];
14
+ };
15
+
16
+ export type CountersChangePayload = {
17
+ value?: number;
18
+ execValue?: number;
19
+ action?: string;
20
+ };
21
+
22
+ export type CountersComparePayload = {
23
+ value?: number;
24
+ execValue?: number;
25
+ action?: string;
26
+ };
27
+
28
+ export type CountersExecInfoPayload = {
29
+ line?: string;
30
+ keywords?: string[];
31
+ state?: ModuleGlobalStateRegistry | null;
32
+ withValue?: boolean;
33
+ };
34
+
35
+ export type CountersExecInfoResult = {
36
+ name: string;
37
+ action: string;
38
+ isGlobal: boolean;
39
+ execValue: number;
40
+ value?: number;
41
+ };
42
+
43
+ export type CountersExecCheckPayload = {
44
+ line?: string;
45
+ keywords?: string[];
46
+ state?: ModuleGlobalStateRegistry | null;
47
+ };
48
+
49
+ export type ScenarioLineExecPayload = {
50
+ line?: string;
51
+ keywords?: string[];
52
+ };
53
+
54
+ export type VarsSetPayload = {
55
+ name?: string;
56
+ type?: string;
57
+ value?: VarValue;
58
+ isGlobal?: boolean;
59
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@vnejs/configs.ts-common/tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist"
6
+ },
7
+ "include": ["src/**/*.ts"],
8
+ "exclude": ["dist", "node_modules"]
9
+ }
package/const/const.js DELETED
@@ -1,5 +0,0 @@
1
- export const TYPE = "counter";
2
- export const EXEC_NAME = "counter";
3
-
4
- export const CHANGE_ACTIONS = { ADD: "+=", SUB: "-=", INC: "++", DEC: "--", SET: "=" };
5
- export const COMPARE_ACTIONS = { MORE: ">", MORE_EQ: ">=", EQ: "===", EQ_NOT: "!==", LESS: "<", LESS_EQ: "<=" };
package/const/events.js DELETED
@@ -1,9 +0,0 @@
1
- export const SUBSCRIBE_EVENTS = {
2
- SET: "vne:vars_counter:set",
3
- GET: "vne:vars_counter:get",
4
- CHANGE: "vne:vars_counter:change",
5
- COMPARE: "vne:vars_counter:compare",
6
- EXEC_INFO: "vne:vars_counter:exec_info",
7
- EXEC_CHECK: "vne:vars_counter:exec_check",
8
- EXEC_GET: "vne:vars_counter:exec_get",
9
- };
package/index.js DELETED
@@ -1,9 +0,0 @@
1
- import { regPlugin } from "@vnejs/shared";
2
-
3
- import * as constants from "./const/const";
4
- import { SUBSCRIBE_EVENTS } from "./const/events";
5
-
6
- import { Counters } from "./modules/counters";
7
- import { CountersExec } from "./modules/exec";
8
-
9
- regPlugin("VARS_COUNTERS", { constants, events: SUBSCRIBE_EVENTS }, [Counters, CountersExec]);
@@ -1,57 +0,0 @@
1
- import { Module } from "@vnejs/module";
2
- import { tokenizeExecLine } from "@vnejs/helpers";
3
-
4
- export class Counters extends Module {
5
- name = "vars.counters";
6
-
7
- varsChangeHandlers = {
8
- [this.CONST.VARS_COUNTERS.CHANGE_ACTIONS.SET]: (oldValue = 0, value = 0) => value,
9
- [this.CONST.VARS_COUNTERS.CHANGE_ACTIONS.INC]: (oldValue = 0) => oldValue + 1,
10
- [this.CONST.VARS_COUNTERS.CHANGE_ACTIONS.DEC]: (oldValue = 0) => oldValue - 1,
11
- [this.CONST.VARS_COUNTERS.CHANGE_ACTIONS.ADD]: (oldValue = 0, value = 0) => oldValue + value,
12
- [this.CONST.VARS_COUNTERS.CHANGE_ACTIONS.SUB]: (oldValue = 0, value = 0) => oldValue - value,
13
- };
14
- varsCompareHandlers = {
15
- [this.CONST.VARS_COUNTERS.COMPARE_ACTIONS.MORE]: (oldValue = 0, value) => oldValue > value,
16
- [this.CONST.VARS_COUNTERS.COMPARE_ACTIONS.MORE_EQ]: (oldValue = 0, value) => oldValue >= value,
17
- [this.CONST.VARS_COUNTERS.COMPARE_ACTIONS.EQ]: (oldValue = 0, value) => oldValue === value,
18
- [this.CONST.VARS_COUNTERS.COMPARE_ACTIONS.EQ_NOT]: (oldValue = 0, value) => oldValue !== value,
19
- [this.CONST.VARS_COUNTERS.COMPARE_ACTIONS.LESS]: (oldValue = 0, value) => oldValue < value,
20
- [this.CONST.VARS_COUNTERS.COMPARE_ACTIONS.LESS_EQ]: (oldValue = 0, value) => oldValue <= value,
21
- };
22
-
23
- subscribe = () => {
24
- this.on(this.EVENTS.VARS_COUNTERS.SET, this.onCounterSet);
25
- this.on(this.EVENTS.VARS_COUNTERS.GET, this.onCounterGet);
26
- this.on(this.EVENTS.VARS_COUNTERS.CHANGE, this.onCounterChange);
27
- this.on(this.EVENTS.VARS_COUNTERS.COMPARE, this.onCounterCompare);
28
- this.on(this.EVENTS.VARS_COUNTERS.EXEC_INFO, this.onCounterExecInfo);
29
- this.on(this.EVENTS.VARS_COUNTERS.EXEC_CHECK, this.onCounterExecCheck);
30
- this.on(this.EVENTS.VARS_COUNTERS.EXEC_GET, this.onCounterExecGet);
31
- };
32
-
33
- init = () => this.emit(this.EVENTS.VARS.DEFAULT_REG, { type: this.CONST.VARS_COUNTERS.TYPE, value: 0 });
34
-
35
- onCounterSet = ({ name, isGlobal = false, value = 0 }) => this.emit(this.EVENTS.VARS.SET, { name, type: this.CONST.VARS_COUNTERS.TYPE, value, isGlobal });
36
- onCounterGet = ({ name = "", isGlobal = false, state = null } = {}) =>
37
- this.emitOne(this.EVENTS.VARS.GET, { name, type: this.CONST.VARS_COUNTERS.TYPE, isGlobal, state });
38
- onCounterChange = ({ value = 0, execValue = 0, action = "" } = {}) => this.varsChangeHandlers[action](value, execValue);
39
- onCounterCompare = ({ value = 0, execValue = 0, action = "" } = {}) => this.varsCompareHandlers[action](value, execValue);
40
- onCounterExecInfo = async ({ line = "", keywords = [], state = null, withValue = true } = {}) => {
41
- const [name = "", action = "", execValue = 0] = tokenizeExecLine(line);
42
- const isGlobal = keywords.includes("global");
43
- const result = { name, action, isGlobal, execValue };
44
-
45
- return withValue ? { ...result, value: await this.emitOne(this.EVENTS.VARS_COUNTERS.GET, { name, isGlobal, state }) } : result;
46
- };
47
- onCounterExecCheck = async ({ line = "", keywords = [], state = null } = {}) => {
48
- const { action = "", execValue = 0, value = 0 } = await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords, state });
49
-
50
- return this.emitOne(this.EVENTS.VARS_COUNTERS.COMPARE, { value, execValue, action });
51
- };
52
- onCounterExecGet = async ({ line = "", keywords = [], state = null } = {}) => {
53
- const { value = 0 } = await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords, state });
54
-
55
- return value;
56
- };
57
- }
package/modules/exec.js DELETED
@@ -1,30 +0,0 @@
1
- import { Module } from "@vnejs/module";
2
-
3
- export class CountersExec extends Module {
4
- name = "vars.counters.exec";
5
-
6
- init = () =>
7
- Promise.all([
8
- this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { block: this.CONST.VARS_COUNTERS.EXEC_NAME, handler: this.onLineExecBlock }),
9
- this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.CONST.VARS_COUNTERS.EXEC_NAME, handler: this.onLineExecModule }),
10
- ]);
11
-
12
- onLineExecModule = async ({ line = "", keywords = [] } = {}) => {
13
- const { name = "", action = "", execValue = 0, value = 0, isGlobal = false } = await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords });
14
-
15
- const newValue = await this.emitOne(this.EVENTS.VARS_COUNTERS.CHANGE, { value, execValue, action });
16
-
17
- await this.emit(this.EVENTS.VARS_COUNTERS.SET, { name, isGlobal, value: newValue });
18
-
19
- this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
20
- };
21
- onLineExecBlock = async ({ line = "", keywords = [] } = {}) => {
22
- const { action = "", execValue = 0, value = 0 } = await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords });
23
-
24
- const shouldGoInside = await this.emitOne(this.EVENTS.VARS_COUNTERS.COMPARE, { value, execValue, action });
25
-
26
- await this.emit(this.EVENTS.VARS.SCENARIO, { shouldGoInside });
27
-
28
- this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
29
- };
30
- }