@vnejs/plugins.vars.counters 0.2.0 → 0.2.2

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/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import "@vnejs/contracts.vars.counters";
2
2
  import { regPlugin } from "@vnejs/shared";
3
3
  import { CONSTANTS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.vars.counters";
4
- import { Counters } from "./modules/counters.js";
5
- import { CountersExec } from "./modules/exec.js";
6
- regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS }, [Counters, CountersExec]);
4
+ import { VarsCounters } from "./modules/counters.js";
5
+ import { VarsCountersExec } from "./modules/exec.js";
6
+ regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS }, [VarsCounters, VarsCountersExec]);
@@ -3,7 +3,7 @@ import type { CountersPluginConstants, CountersPluginEvents, CountersPluginParam
3
3
  import type { CountersChangePayload, CountersComparePayload, CountersExecCheckPayload, CountersExecInfoPayload, CountersExecInfoResult, CountersGetPayload, CountersSetPayload } from "../utils/counters.js";
4
4
  type ChangeHandler = (oldValue?: number, value?: number) => number;
5
5
  type CompareHandler = (oldValue?: number, value?: number) => boolean;
6
- export declare class Counters extends ModuleCore<CountersPluginEvents, CountersPluginConstants, CountersPluginSettings, CountersPluginParams> {
6
+ export declare class VarsCounters extends ModuleCore<CountersPluginEvents, CountersPluginConstants, CountersPluginSettings, CountersPluginParams> {
7
7
  name: string;
8
8
  varsChangeHandlers: Record<string, ChangeHandler>;
9
9
  varsCompareHandlers: Record<string, CompareHandler>;
@@ -1,6 +1,6 @@
1
1
  import { ModuleCore } from "@vnejs/module.core";
2
2
  import { tokenizeExecLine } from "@vnejs/helpers";
3
- export class Counters extends ModuleCore {
3
+ export class VarsCounters extends ModuleCore {
4
4
  name = "vars.counters";
5
5
  varsChangeHandlers = {
6
6
  [this.CONST.VARS_COUNTERS.CHANGE_ACTIONS.SET]: (oldValue = 0, value = 0) => value,
@@ -41,7 +41,7 @@ export class Counters extends ModuleCore {
41
41
  return withValue ? { ...result, value: Number(await this.emitOne(this.EVENTS.VARS_COUNTERS.GET, { name, isGlobal, state })) } : result;
42
42
  };
43
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 }));
44
+ const { action = "", execValue = 0, value = 0, } = (await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords, state }));
45
45
  return this.emitOne(this.EVENTS.VARS_COUNTERS.COMPARE, { value, execValue, action });
46
46
  };
47
47
  onCounterExecGet = async ({ line = "", keywords = [], state = null } = {}) => {
@@ -1,7 +1,7 @@
1
1
  import { ModuleCore } from "@vnejs/module.core";
2
2
  import type { LineExecHandlerArg } from "@vnejs/module.core";
3
3
  import type { CountersPluginConstants, CountersPluginEvents, CountersPluginParams, CountersPluginSettings } from "../types.js";
4
- export declare class CountersExec extends ModuleCore<CountersPluginEvents, CountersPluginConstants, CountersPluginSettings, CountersPluginParams> {
4
+ export declare class VarsCountersExec extends ModuleCore<CountersPluginEvents, CountersPluginConstants, CountersPluginSettings, CountersPluginParams> {
5
5
  name: string;
6
6
  init: () => Promise<[unknown[] | undefined, unknown[] | undefined]>;
7
7
  onLineExecModule: ({ line, keywords }?: LineExecHandlerArg) => Promise<void>;
@@ -1,5 +1,5 @@
1
1
  import { ModuleCore } from "@vnejs/module.core";
2
- export class CountersExec extends ModuleCore {
2
+ export class VarsCountersExec extends ModuleCore {
3
3
  name = "vars.counters.exec";
4
4
  init = () => Promise.all([
5
5
  this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { block: this.CONST.VARS_COUNTERS.EXEC_NAME, handler: this.onLineExecBlock }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.vars.counters",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -3,7 +3,7 @@ import "@vnejs/contracts.vars.counters";
3
3
  import { regPlugin } from "@vnejs/shared";
4
4
  import { CONSTANTS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.vars.counters";
5
5
 
6
- import { Counters } from "./modules/counters.js";
7
- import { CountersExec } from "./modules/exec.js";
6
+ import { VarsCounters } from "./modules/counters.js";
7
+ import { VarsCountersExec } from "./modules/exec.js";
8
8
 
9
- regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS }, [Counters, CountersExec]);
9
+ regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS }, [VarsCounters, VarsCountersExec]);
@@ -16,7 +16,7 @@ import type {
16
16
  type ChangeHandler = (oldValue?: number, value?: number) => number;
17
17
  type CompareHandler = (oldValue?: number, value?: number) => boolean;
18
18
 
19
- export class Counters extends ModuleCore<CountersPluginEvents, CountersPluginConstants, CountersPluginSettings, CountersPluginParams> {
19
+ export class VarsCounters extends ModuleCore<CountersPluginEvents, CountersPluginConstants, CountersPluginSettings, CountersPluginParams> {
20
20
  name = "vars.counters";
21
21
 
22
22
  varsChangeHandlers: Record<string, ChangeHandler> = {
@@ -70,7 +70,11 @@ export class Counters extends ModuleCore<CountersPluginEvents, CountersPluginCon
70
70
  };
71
71
 
72
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;
73
+ const {
74
+ action = "",
75
+ execValue = 0,
76
+ value = 0,
77
+ } = (await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords, state })) as CountersExecInfoResult;
74
78
 
75
79
  return this.emitOne(this.EVENTS.VARS_COUNTERS.COMPARE, { value, execValue, action });
76
80
  };
@@ -5,7 +5,7 @@ import type { LineExecHandlerArg } from "@vnejs/module.core";
5
5
  import type { CountersPluginConstants, CountersPluginEvents, CountersPluginParams, CountersPluginSettings } from "../types.js";
6
6
  import type { CountersExecInfoResult, CountersSetPayload } from "../utils/counters.js";
7
7
 
8
- export class CountersExec extends ModuleCore<CountersPluginEvents, CountersPluginConstants, CountersPluginSettings, CountersPluginParams> {
8
+ export class VarsCountersExec extends ModuleCore<CountersPluginEvents, CountersPluginConstants, CountersPluginSettings, CountersPluginParams> {
9
9
  name = "vars.counters.exec";
10
10
 
11
11
  init = () =>
@@ -3,16 +3,16 @@ import { beforeEach, describe, expect, it } from "vitest";
3
3
  import { SUBSCRIBE_EVENTS as VARS_EVENTS } from "@vnejs/contracts.vars";
4
4
  import { spyEvent } from "@vnejs/test-utils";
5
5
 
6
- import { Counters } from "../modules/counters.js";
6
+ import { VarsCounters } from "../modules/counters.js";
7
7
  import { CONSTANTS, createCountersTestModule, registerCountersPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
8
8
 
9
- describe("Counters", () => {
9
+ describe("VarsCounters", () => {
10
10
  beforeEach(() => {
11
11
  registerCountersPluginVne();
12
12
  });
13
13
 
14
14
  it("CHANGE applies increment action", async () => {
15
- const { observer } = createCountersTestModule(Counters);
15
+ const { observer } = createCountersTestModule(VarsCounters);
16
16
 
17
17
  const [result] = await observer.emit(SUBSCRIBE_EVENTS.CHANGE, {
18
18
  value: 5,
@@ -24,7 +24,7 @@ describe("Counters", () => {
24
24
  });
25
25
 
26
26
  it("COMPARE uses configured comparator", async () => {
27
- const { observer } = createCountersTestModule(Counters);
27
+ const { observer } = createCountersTestModule(VarsCounters);
28
28
 
29
29
  const [result] = await observer.emit(SUBSCRIBE_EVENTS.COMPARE, {
30
30
  value: 10,
@@ -36,7 +36,7 @@ describe("Counters", () => {
36
36
  });
37
37
 
38
38
  it("SET delegates to VARS.SET with counter type", async () => {
39
- const { observer } = createCountersTestModule(Counters);
39
+ const { observer } = createCountersTestModule(VarsCounters);
40
40
  const set = spyEvent(observer, VARS_EVENTS.SET);
41
41
 
42
42
  await observer.emit(SUBSCRIBE_EVENTS.SET, { name: "gold", value: 3 });
package/src/types.ts CHANGED
@@ -1,9 +1,5 @@
1
1
  import type { ModuleCoreConstants, ModuleCoreEvents, ModuleCoreParams, ModuleCoreSettings } from "@vnejs/module.core";
2
- import type {
3
- Constants as VarsConstants,
4
- PluginName as VarsPluginName,
5
- SubscribeEvents as VarsSubscribeEvents,
6
- } from "@vnejs/contracts.vars";
2
+ import type { Constants as VarsConstants, PluginName as VarsPluginName, SubscribeEvents as VarsSubscribeEvents } from "@vnejs/contracts.vars";
7
3
  import type { Constants, PluginName, SubscribeEvents } from "@vnejs/contracts.vars.counters";
8
4
 
9
5
  export type CountersPluginEvents = ModuleCoreEvents & Record<PluginName, SubscribeEvents> & Record<VarsPluginName, VarsSubscribeEvents>;