@vnejs/plugins.vars.counters 0.2.3 → 0.2.4

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.
@@ -1,10 +1,10 @@
1
1
  import { ModuleCore } from "@vnejs/module.core";
2
+ import type { CountersGetPayload, CountersSetPayload } from "@vnejs/contracts.vars.counters";
2
3
  import type { CountersPluginConstants, CountersPluginEvents, CountersPluginParams, CountersPluginSettings } from "../types.js";
3
- import type { CountersGetPayload, CountersSetPayload } from "../utils/counters.js";
4
4
  export declare class VarsCounters extends ModuleCore<CountersPluginEvents, CountersPluginConstants, CountersPluginSettings, CountersPluginParams> {
5
5
  name: string;
6
6
  subscribe: () => void;
7
- init: () => Promise<unknown[]> | undefined;
8
- onCounterSet: ({ name, isGlobal, value }?: CountersSetPayload) => Promise<unknown[]> | undefined;
9
- onCounterGet: ({ name, isGlobal, state }?: CountersGetPayload) => Promise<unknown> | undefined;
7
+ init: () => Promise<import("@vnejs/shared").EmitResults<"vne:vars:default_reg">> | undefined;
8
+ onCounterSet: ({ name, isGlobal, value }?: CountersSetPayload) => Promise<import("@vnejs/shared").EmitResults<"vne:vars:set">> | undefined;
9
+ onCounterGet: ({ name, isGlobal, state }?: CountersGetPayload) => Promise<number | undefined>;
10
10
  }
@@ -7,5 +7,8 @@ export class VarsCounters extends ModuleCore {
7
7
  };
8
8
  init = () => this.emit(this.EVENTS.VARS.DEFAULT_REG, { type: this.CONST.VARS_COUNTERS.TYPE, value: 0 });
9
9
  onCounterSet = ({ name = "", isGlobal = false, value = 0 } = {}) => this.emit(this.EVENTS.VARS.SET, { name, type: this.CONST.VARS_COUNTERS.TYPE, value, isGlobal });
10
- onCounterGet = ({ name = "", isGlobal = false, state = null } = {}) => this.emitOne(this.EVENTS.VARS.GET, { name, type: this.CONST.VARS_COUNTERS.TYPE, isGlobal, state });
10
+ onCounterGet = async ({ name = "", isGlobal = false, state = null } = {}) => {
11
+ const value = await this.emitOne(this.EVENTS.VARS.GET, { name, type: this.CONST.VARS_COUNTERS.TYPE, isGlobal, state });
12
+ return typeof value === "number" ? value : value == null ? undefined : Number(value);
13
+ };
11
14
  }
@@ -1,10 +1,10 @@
1
1
  import { ModuleCore } from "@vnejs/module.core";
2
+ import type { CountersExecCheckPayload, CountersExecInfoPayload, CountersExecInfoResult } from "@vnejs/contracts.vars.counters";
2
3
  import type { CountersPluginConstants, CountersPluginEvents, CountersPluginParams, CountersPluginSettings } from "../types.js";
3
- import type { CountersExecCheckPayload, CountersExecInfoPayload, CountersExecInfoResult } from "../utils/counters.js";
4
4
  export declare class VarsCountersExec extends ModuleCore<CountersPluginEvents, CountersPluginConstants, CountersPluginSettings, CountersPluginParams> {
5
5
  name: string;
6
6
  subscribe: () => void;
7
7
  onCounterExecInfo: ({ line, keywords, state, withValue }?: CountersExecInfoPayload) => Promise<CountersExecInfoResult>;
8
- onCounterExecCheck: ({ line, keywords, state }?: CountersExecCheckPayload) => Promise<unknown>;
8
+ onCounterExecCheck: ({ line, keywords, state }?: CountersExecCheckPayload) => Promise<boolean | undefined>;
9
9
  onCounterExecGet: ({ line, keywords, state }?: CountersExecCheckPayload) => Promise<number>;
10
10
  }
@@ -14,14 +14,14 @@ export class VarsCountersExec extends ModuleCore {
14
14
  const execValue = Number(tokens[2] ?? 0);
15
15
  const isGlobal = keywords.includes(this.CONST.VARS.LINE_KEYWORDS.GLOBAL);
16
16
  const result = { name, action, isGlobal, execValue };
17
- return withValue ? { ...result, value: Number(await this.emitOne(this.EVENTS.VARS_COUNTERS.GET, { name, isGlobal, state })) } : result;
17
+ return withValue ? { ...result, value: await this.emitOne(this.EVENTS.VARS_COUNTERS.GET, { name, isGlobal, state }) } : result;
18
18
  };
19
19
  onCounterExecCheck = async ({ line = "", keywords = [], state = null } = {}) => {
20
- const { action = "", execValue = 0, value = 0, } = (await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords, state }));
20
+ const { action = "", execValue = 0, value = 0 } = (await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords, state })) ?? {};
21
21
  return this.emitOne(this.EVENTS.VARS_COUNTERS.COMPARE, { value, execValue, action });
22
22
  };
23
23
  onCounterExecGet = async ({ line = "", keywords = [], state = null } = {}) => {
24
- const { value = 0 } = (await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords, state }));
24
+ const { value = 0 } = (await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords, state })) ?? {};
25
25
  return value;
26
26
  };
27
27
  }
@@ -1,6 +1,6 @@
1
1
  import { ModuleCore } from "@vnejs/module.core";
2
+ import type { CountersChangePayload, CountersComparePayload } from "@vnejs/contracts.vars.counters";
2
3
  import type { CountersPluginConstants, CountersPluginEvents, CountersPluginParams, CountersPluginSettings } from "../types.js";
3
- import type { CountersChangePayload, CountersComparePayload } from "../utils/counters.js";
4
4
  type ChangeHandler = (oldValue?: number, value?: number) => number;
5
5
  type CompareHandler = (oldValue?: number, value?: number) => boolean;
6
6
  export declare class VarsCountersHandlers extends ModuleCore<CountersPluginEvents, CountersPluginConstants, CountersPluginSettings, CountersPluginParams> {
@@ -3,7 +3,7 @@ import type { LineExecHandlerArg } from "@vnejs/module.core";
3
3
  import type { CountersPluginConstants, CountersPluginEvents, CountersPluginParams, CountersPluginSettings } from "../types.js";
4
4
  export declare class VarsCountersScenario extends ModuleCore<CountersPluginEvents, CountersPluginConstants, CountersPluginSettings, CountersPluginParams> {
5
5
  name: string;
6
- init: () => Promise<[unknown[] | undefined, unknown[] | undefined]>;
6
+ init: () => Promise<[import("@vnejs/shared").EmitResults<"vne:scenario:line_exec_reg"> | undefined, import("@vnejs/shared").EmitResults<"vne:scenario:line_exec_reg"> | undefined]>;
7
7
  onLineExecModule: ({ line, keywords }?: LineExecHandlerArg) => Promise<void>;
8
8
  onLineExecBlock: ({ line, keywords }?: LineExecHandlerArg) => Promise<void>;
9
9
  }
@@ -6,15 +6,14 @@ export class VarsCountersScenario extends ModuleCore {
6
6
  this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.CONST.VARS_COUNTERS.EXEC_NAME, handler: this.onLineExecModule }),
7
7
  ]);
8
8
  onLineExecModule = async ({ line = "", keywords = [] } = {}) => {
9
- const execInfo = (await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords }));
10
- const { name = "", action = "", execValue = 0, value = 0, isGlobal = false } = execInfo;
11
- const newValue = Number(await this.emitOne(this.EVENTS.VARS_COUNTERS.CHANGE, { value, execValue, action }));
9
+ const { name = "", action = "", execValue = 0, value = 0, isGlobal = false, } = (await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords })) ?? {};
10
+ const newValue = (await this.emitOne(this.EVENTS.VARS_COUNTERS.CHANGE, { value, execValue, action })) ?? 0;
12
11
  await this.emit(this.EVENTS.VARS_COUNTERS.SET, { name, isGlobal, value: newValue });
13
12
  this.emitNext();
14
13
  };
15
14
  onLineExecBlock = async ({ line = "", keywords = [] } = {}) => {
16
- const { action = "", execValue = 0, value = 0 } = (await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords }));
17
- const shouldGoInside = Boolean(await this.emitOne(this.EVENTS.VARS_COUNTERS.COMPARE, { value, execValue, action }));
15
+ const { action = "", execValue = 0, value = 0 } = (await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords })) ?? {};
16
+ const shouldGoInside = (await this.emitOne(this.EVENTS.VARS_COUNTERS.COMPARE, { value, execValue, action })) ?? false;
18
17
  await this.emit(this.EVENTS.VARS.SCENARIO, { shouldGoInside });
19
18
  this.emitNext();
20
19
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.vars.counters",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,7 +1,8 @@
1
1
  import { ModuleCore } from "@vnejs/module.core";
2
+ import type { CountersGetPayload, CountersSetPayload } from "@vnejs/contracts.vars.counters";
3
+ import type { VarsSetPayload } from "@vnejs/contracts.vars";
2
4
 
3
5
  import type { CountersPluginConstants, CountersPluginEvents, CountersPluginParams, CountersPluginSettings } from "../types.js";
4
- import type { CountersGetPayload, CountersSetPayload, VarsSetPayload } from "../utils/counters.js";
5
6
 
6
7
  export class VarsCounters extends ModuleCore<CountersPluginEvents, CountersPluginConstants, CountersPluginSettings, CountersPluginParams> {
7
8
  name = "vars.counters";
@@ -16,6 +17,9 @@ export class VarsCounters extends ModuleCore<CountersPluginEvents, CountersPlugi
16
17
  onCounterSet = ({ name = "", isGlobal = false, value = 0 }: CountersSetPayload = {}) =>
17
18
  this.emit(this.EVENTS.VARS.SET, { name, type: this.CONST.VARS_COUNTERS.TYPE, value, isGlobal } satisfies VarsSetPayload);
18
19
 
19
- onCounterGet = ({ name = "", isGlobal = false, state = null }: CountersGetPayload = {}) =>
20
- this.emitOne(this.EVENTS.VARS.GET, { name, type: this.CONST.VARS_COUNTERS.TYPE, isGlobal, state });
20
+ onCounterGet = async ({ name = "", isGlobal = false, state = null }: CountersGetPayload = {}) => {
21
+ const value = await this.emitOne(this.EVENTS.VARS.GET, { name, type: this.CONST.VARS_COUNTERS.TYPE, isGlobal, state });
22
+
23
+ return typeof value === "number" ? value : value == null ? undefined : Number(value);
24
+ };
21
25
  }
@@ -1,8 +1,8 @@
1
1
  import { ModuleCore } from "@vnejs/module.core";
2
2
  import { tokenizeExecLine } from "@vnejs/helpers";
3
+ import type { CountersExecCheckPayload, CountersExecInfoPayload, CountersExecInfoResult } from "@vnejs/contracts.vars.counters";
3
4
 
4
5
  import type { CountersPluginConstants, CountersPluginEvents, CountersPluginParams, CountersPluginSettings } from "../types.js";
5
- import type { CountersExecCheckPayload, CountersExecInfoPayload, CountersExecInfoResult } from "../utils/counters.js";
6
6
 
7
7
  export class VarsCountersExec extends ModuleCore<CountersPluginEvents, CountersPluginConstants, CountersPluginSettings, CountersPluginParams> {
8
8
  name = "vars.counters.exec";
@@ -21,21 +21,17 @@ export class VarsCountersExec extends ModuleCore<CountersPluginEvents, CountersP
21
21
  const isGlobal = keywords.includes(this.CONST.VARS.LINE_KEYWORDS.GLOBAL);
22
22
  const result: CountersExecInfoResult = { name, action, isGlobal, execValue };
23
23
 
24
- return withValue ? { ...result, value: Number(await this.emitOne(this.EVENTS.VARS_COUNTERS.GET, { name, isGlobal, state })) } : result;
24
+ return withValue ? { ...result, value: await this.emitOne(this.EVENTS.VARS_COUNTERS.GET, { name, isGlobal, state }) } : result;
25
25
  };
26
26
 
27
27
  onCounterExecCheck = async ({ line = "", keywords = [], state = null }: CountersExecCheckPayload = {}) => {
28
- const {
29
- action = "",
30
- execValue = 0,
31
- value = 0,
32
- } = (await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords, state })) as CountersExecInfoResult;
28
+ const { action = "", execValue = 0, value = 0 } = (await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords, state })) ?? {};
33
29
 
34
30
  return this.emitOne(this.EVENTS.VARS_COUNTERS.COMPARE, { value, execValue, action });
35
31
  };
36
32
 
37
33
  onCounterExecGet = async ({ line = "", keywords = [], state = null }: CountersExecCheckPayload = {}) => {
38
- const { value = 0 } = (await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords, state })) as CountersExecInfoResult;
34
+ const { value = 0 } = (await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords, state })) ?? {};
39
35
 
40
36
  return value;
41
37
  };
@@ -1,7 +1,7 @@
1
1
  import { ModuleCore } from "@vnejs/module.core";
2
+ import type { CountersChangePayload, CountersComparePayload } from "@vnejs/contracts.vars.counters";
2
3
 
3
4
  import type { CountersPluginConstants, CountersPluginEvents, CountersPluginParams, CountersPluginSettings } from "../types.js";
4
- import type { CountersChangePayload, CountersComparePayload } from "../utils/counters.js";
5
5
 
6
6
  type ChangeHandler = (oldValue?: number, value?: number) => number;
7
7
  type CompareHandler = (oldValue?: number, value?: number) => boolean;
@@ -1,9 +1,9 @@
1
1
  import { ModuleCore } from "@vnejs/module.core";
2
2
 
3
3
  import type { LineExecHandlerArg } from "@vnejs/module.core";
4
+ import type { CountersSetPayload } from "@vnejs/contracts.vars.counters";
4
5
 
5
6
  import type { CountersPluginConstants, CountersPluginEvents, CountersPluginParams, CountersPluginSettings } from "../types.js";
6
- import type { CountersExecInfoResult, CountersSetPayload } from "../utils/counters.js";
7
7
 
8
8
  export class VarsCountersScenario extends ModuleCore<CountersPluginEvents, CountersPluginConstants, CountersPluginSettings, CountersPluginParams> {
9
9
  name = "vars.counters.scenario";
@@ -15,10 +15,15 @@ export class VarsCountersScenario extends ModuleCore<CountersPluginEvents, Count
15
15
  ]);
16
16
 
17
17
  onLineExecModule = async ({ line = "", keywords = [] }: LineExecHandlerArg = {}) => {
18
- const execInfo = (await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords })) as CountersExecInfoResult;
19
- const { name = "", action = "", execValue = 0, value = 0, isGlobal = false } = execInfo;
18
+ const {
19
+ name = "",
20
+ action = "",
21
+ execValue = 0,
22
+ value = 0,
23
+ isGlobal = false,
24
+ } = (await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords })) ?? {};
20
25
 
21
- const newValue = Number(await this.emitOne(this.EVENTS.VARS_COUNTERS.CHANGE, { value, execValue, action }));
26
+ const newValue = (await this.emitOne(this.EVENTS.VARS_COUNTERS.CHANGE, { value, execValue, action })) ?? 0;
22
27
 
23
28
  await this.emit(this.EVENTS.VARS_COUNTERS.SET, { name, isGlobal, value: newValue } satisfies CountersSetPayload);
24
29
 
@@ -26,9 +31,9 @@ export class VarsCountersScenario extends ModuleCore<CountersPluginEvents, Count
26
31
  };
27
32
 
28
33
  onLineExecBlock = async ({ line = "", keywords = [] }: LineExecHandlerArg = {}) => {
29
- const { action = "", execValue = 0, value = 0 } = (await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords })) as CountersExecInfoResult;
34
+ const { action = "", execValue = 0, value = 0 } = (await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords })) ?? {};
30
35
 
31
- const shouldGoInside = Boolean(await this.emitOne(this.EVENTS.VARS_COUNTERS.COMPARE, { value, execValue, action }));
36
+ const shouldGoInside = (await this.emitOne(this.EVENTS.VARS_COUNTERS.COMPARE, { value, execValue, action })) ?? false;
32
37
 
33
38
  await this.emit(this.EVENTS.VARS.SCENARIO, { shouldGoInside });
34
39
 
@@ -1,46 +0,0 @@
1
- import type { ModuleGlobalStateRegistry } from "@vnejs/module.core";
2
- import type { VarValue, VarsGetPayload } from "@vnejs/contracts.vars";
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 VarsSetPayload = {
42
- name?: string;
43
- type?: string;
44
- value?: VarValue;
45
- isGlobal?: boolean;
46
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,54 +0,0 @@
1
- import type { ModuleGlobalStateRegistry } from "@vnejs/module.core";
2
- import type { VarValue, VarsGetPayload } from "@vnejs/contracts.vars";
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 VarsSetPayload = {
50
- name?: string;
51
- type?: string;
52
- value?: VarValue;
53
- isGlobal?: boolean;
54
- };