@vnejs/plugins.vars 0.1.7 → 0.1.9

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,7 @@
1
+ import { regPlugin } from "@vnejs/shared";
2
+ import { PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/plugins.vars.contract";
3
+ import { VarsGlobal } from "./modules/global.js";
4
+ import { VarsInject } from "./modules/inject.js";
5
+ import { VarsScenario } from "./modules/scenario.js";
6
+ import { Vars } from "./modules/vars.js";
7
+ regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS }, [VarsGlobal, VarsInject, Vars, VarsScenario]);
@@ -0,0 +1,13 @@
1
+ import "@vnejs/plugins.vars.contract";
2
+ import { Module } from "@vnejs/module";
3
+ import type { VarValue } from "@vnejs/plugins.vars.contract";
4
+ import type { VarsPluginConstants, VarsPluginEvents, VarsPluginParams, VarsPluginSettings } from "../types.js";
5
+ import type { VarsGlobalGetPayload, VarsGlobalSetPayload } from "../utils/vars.js";
6
+ export declare class VarsGlobal extends Module<VarsPluginEvents, VarsPluginConstants, VarsPluginSettings, VarsPluginParams> {
7
+ name: string;
8
+ subscribe: () => void;
9
+ init: () => Promise<void>;
10
+ onVarGlobalGet: ({ name }?: VarsGlobalGetPayload) => VarValue;
11
+ onVarGlobalSet: ({ name, value }?: VarsGlobalSetPayload) => Promise<unknown[]> | undefined;
12
+ onVarGlobalClear: () => Promise<unknown[]> | undefined;
13
+ }
@@ -0,0 +1,19 @@
1
+ import "@vnejs/plugins.vars.contract";
2
+ import { Module } from "@vnejs/module";
3
+ export class VarsGlobal extends Module {
4
+ name = "vars.global";
5
+ subscribe = () => {
6
+ this.on(this.EVENTS.VARS.GLOBAL_GET, this.onVarGlobalGet);
7
+ this.on(this.EVENTS.VARS.GLOBAL_SET, this.onVarGlobalSet);
8
+ this.on(this.EVENTS.VARS.GLOBAL_CLEAR, this.onVarGlobalClear);
9
+ };
10
+ init = async () => {
11
+ this.shared.vars = (await this.emitOne(this.EVENTS.STORAGE.GET_ALL, { module: this.name }));
12
+ };
13
+ onVarGlobalGet = ({ name = "" } = {}) => this.shared.vars[name];
14
+ onVarGlobalSet = ({ name = "", value = "" } = {}) => {
15
+ this.shared.vars[name] = value;
16
+ return this.emit(this.EVENTS.STORAGE.SET, { module: this.name, key: name, value });
17
+ };
18
+ onVarGlobalClear = () => this.emit(this.EVENTS.STORAGE.RM_ALL, { module: this.name });
19
+ }
@@ -0,0 +1,9 @@
1
+ import { Module } from "@vnejs/module";
2
+ import type { VarsPluginConstants, VarsPluginEvents, VarsPluginParams, VarsPluginSettings } from "../types.js";
3
+ import type { VarsInjectPayload } from "../utils/vars.js";
4
+ export declare class VarsInject extends Module<VarsPluginEvents, VarsPluginConstants, VarsPluginSettings, VarsPluginParams> {
5
+ name: string;
6
+ subscribe: () => void;
7
+ onVarInject: ({ text }?: VarsInjectPayload) => Promise<string>;
8
+ injectsVars: (text: string) => Promise<string>;
9
+ }
@@ -0,0 +1,18 @@
1
+ import { Module } from "@vnejs/module";
2
+ const INJECT_REG = /%vars:(?<line>.*?)%/;
3
+ export class VarsInject extends Module {
4
+ name = "vars.inject";
5
+ subscribe = () => {
6
+ this.on(this.EVENTS.VARS.INJECT, this.onVarInject);
7
+ };
8
+ onVarInject = ({ text = "" } = {}) => this.injectsVars(text);
9
+ injectsVars = async (text) => {
10
+ if (INJECT_REG.test(text)) {
11
+ const line = INJECT_REG.exec(text)?.groups?.line ?? "";
12
+ const [type = "", name = "", keyword = ""] = line.split(":");
13
+ const varValue = await this.emitOne(this.EVENTS.VARS.GET, { type, name, isGlobal: keyword === this.CONST.SCENARIO.LINE_KEYWORDS.GLOBAL });
14
+ return this.injectsVars(text.replace(`%vars:${line}%`, String(varValue)));
15
+ }
16
+ return text;
17
+ };
18
+ }
@@ -0,0 +1,9 @@
1
+ import { Module } from "@vnejs/module";
2
+ import type { VarsPluginConstants, VarsPluginEvents, VarsPluginParams, VarsPluginSettings } from "../types.js";
3
+ import type { VarsScenarioPayload } from "../utils/vars.js";
4
+ export declare class VarsScenario extends Module<VarsPluginEvents, VarsPluginConstants, VarsPluginSettings, VarsPluginParams> {
5
+ name: string;
6
+ subscribe: () => void;
7
+ onVarScenario: ({ shouldGoInside }?: VarsScenarioPayload) => Promise<void>;
8
+ increaseCurLine: (indexShift: number) => void;
9
+ }
@@ -0,0 +1,20 @@
1
+ import { Module } from "@vnejs/module";
2
+ export class VarsScenario extends Module {
3
+ name = "vars.scenario";
4
+ subscribe = () => {
5
+ this.on(this.EVENTS.VARS.SCENARIO, this.onVarScenario);
6
+ };
7
+ onVarScenario = async ({ shouldGoInside = false } = {}) => {
8
+ if (shouldGoInside)
9
+ return this.increaseCurLine(1);
10
+ const { curLine = 0, label } = this.globalState.scenario;
11
+ const lines = (await this.emitOne(this.EVENTS.SCENARIO.LINES_GET, { label }));
12
+ let indexShift = 1;
13
+ while (lines[curLine + indexShift] && (lines[curLine + indexShift].indent ?? 0) > (lines[curLine].indent ?? 0))
14
+ indexShift++;
15
+ return this.increaseCurLine(indexShift);
16
+ };
17
+ increaseCurLine = (indexShift) => {
18
+ this.globalState.scenario.curLine += indexShift;
19
+ };
20
+ }
@@ -0,0 +1,15 @@
1
+ import { Module } from "@vnejs/module";
2
+ import type { ModuleGlobalStateVars, VarValue } from "@vnejs/plugins.vars.contract";
3
+ import type { VarsPluginConstants, VarsPluginEvents, VarsPluginParams, VarsPluginSettings } from "../types.js";
4
+ import type { VarsDefaultRegPayload, VarsGetPayload, VarsSetPayload, VarsStateSlicePayload } from "../utils/vars.js";
5
+ export declare class Vars extends Module<VarsPluginEvents, VarsPluginConstants, VarsPluginSettings, VarsPluginParams, ModuleGlobalStateVars> {
6
+ name: string;
7
+ defaultVarValues: Record<string, VarValue | undefined>;
8
+ subscribe: () => void;
9
+ onVarSet: ({ name, type, value, isGlobal }?: VarsSetPayload) => void | Promise<unknown[]>;
10
+ onVarGet: ({ name, type, isGlobal, state }?: VarsGetPayload) => Promise<VarValue | undefined>;
11
+ onVarDefaultReg: ({ type, value }?: VarsDefaultRegPayload) => void;
12
+ onStateSet: (payload?: VarsStateSlicePayload) => Promise<void>;
13
+ getInnerVarName: (name?: string, type?: string) => string;
14
+ setLocalVar: (name?: string, value?: VarValue) => void;
15
+ }
@@ -0,0 +1,32 @@
1
+ import { Module } from "@vnejs/module";
2
+ export class Vars extends Module {
3
+ name = "vars";
4
+ defaultVarValues = {};
5
+ subscribe = () => {
6
+ this.on(this.EVENTS.VARS.GET, this.onVarGet);
7
+ this.on(this.EVENTS.VARS.SET, this.onVarSet);
8
+ this.on(this.EVENTS.VARS.DEFAULT_REG, this.onVarDefaultReg);
9
+ this.on(this.EVENTS.STATE.SET, this.onStateSet);
10
+ this.on(this.EVENTS.STATE.CLEAR, this.setDefaultState);
11
+ };
12
+ onVarSet = ({ name = "", type = "", value = "", isGlobal = false } = {}) => {
13
+ const varName = this.getInnerVarName(name, type);
14
+ return isGlobal ? this.emit(this.EVENTS.VARS.GLOBAL_SET, { name: varName, value }) : this.setLocalVar(varName, value);
15
+ };
16
+ onVarGet = async ({ name = "", type = "", isGlobal = false, state = null } = {}) => {
17
+ const varName = this.getInnerVarName(name, type);
18
+ const value = isGlobal ? await this.emitOne(this.EVENTS.VARS.GLOBAL_GET, { name: varName }) : state ? state.vars?.[varName] : this.state[varName];
19
+ return value ?? this.defaultVarValues[type];
20
+ };
21
+ onVarDefaultReg = ({ type = "", value } = {}) => {
22
+ this.defaultVarValues[type] = value;
23
+ };
24
+ onStateSet = async (payload = {}) => {
25
+ const state = payload[this.name];
26
+ return this.setState((await this.emitOne(this.EVENTS.VENDORS.CLONE, state)));
27
+ };
28
+ getInnerVarName = (name = "", type = "") => `${type}:${name}`;
29
+ setLocalVar = (name = "", value = "") => {
30
+ this.state[name] = value;
31
+ };
32
+ }
@@ -0,0 +1,10 @@
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 StatePluginName, SubscribeEvents as StateSubscribeEvents } from "@vnejs/plugins.core.state.contract";
4
+ import type { PluginName as StoragePluginName, SubscribeEvents as StorageSubscribeEvents } from "@vnejs/plugins.core.storage.contract";
5
+ import type { PluginName as VendorsPluginName, SubscribeEvents as VendorsSubscribeEvents } from "@vnejs/plugins.core.vendors.contract";
6
+ import type { PluginName, SubscribeEvents } from "@vnejs/plugins.vars.contract";
7
+ export type VarsPluginEvents = VnePluginEventsMapRegistry & Record<PluginName, SubscribeEvents> & Record<ScenarioPluginName, ScenarioSubscribeEvents> & Record<StatePluginName, StateSubscribeEvents> & Record<StoragePluginName, StorageSubscribeEvents> & Record<VendorsPluginName, VendorsSubscribeEvents>;
8
+ export type VarsPluginConstants = VnePluginConstantsMapRegistry & Record<ScenarioPluginName, ScenarioConstants>;
9
+ export type VarsPluginSettings = VnePluginSettingsMapRegistry;
10
+ export type VarsPluginParams = VnePluginParamsMapRegistry;
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { ModuleGlobalStateVars } from "@vnejs/plugins.vars.contract";
2
+ export type ScenarioLine = {
3
+ line: string;
4
+ indent?: number;
5
+ };
6
+ export type VarsStateSlicePayload = {
7
+ [moduleName: string]: ModuleGlobalStateVars | undefined;
8
+ };
9
+ export type { VarValue, VarsDefaultRegPayload, VarsGetPayload, VarsGlobalGetPayload, VarsGlobalSetPayload, VarsInjectPayload, VarsScenarioPayload, VarsSetPayload } from "@vnejs/plugins.vars.contract";
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,17 +1,46 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.vars",
3
- "version": "0.1.7",
4
- "main": "index.js",
3
+ "version": "0.1.9",
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.contract": "~0.0.1"
34
+ },
35
+ "peerDependencies": {
36
+ "@vnejs/module": "~0.0.1",
37
+ "@vnejs/plugins.core.scenario.contract": "~0.0.1",
38
+ "@vnejs/plugins.core.state.contract": "~0.0.1",
39
+ "@vnejs/plugins.core.storage.contract": "~0.0.1",
40
+ "@vnejs/plugins.core.vendors.contract": "~0.0.1",
41
+ "@vnejs/shared": "~0.0.9"
42
+ },
43
+ "devDependencies": {
44
+ "@vnejs/configs.ts-common": "~0.0.1"
45
+ }
17
46
  }
package/src/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { regPlugin } from "@vnejs/shared";
2
+ import { PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/plugins.vars.contract";
3
+
4
+ import { VarsGlobal } from "./modules/global.js";
5
+ import { VarsInject } from "./modules/inject.js";
6
+ import { VarsScenario } from "./modules/scenario.js";
7
+ import { Vars } from "./modules/vars.js";
8
+
9
+ regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS }, [VarsGlobal, VarsInject, Vars, VarsScenario]);
@@ -0,0 +1,31 @@
1
+ import "@vnejs/plugins.vars.contract";
2
+
3
+ import { Module } from "@vnejs/module";
4
+ import type { VarValue } from "@vnejs/plugins.vars.contract";
5
+
6
+ import type { VarsPluginConstants, VarsPluginEvents, VarsPluginParams, VarsPluginSettings } from "../types.js";
7
+ import type { VarsGlobalGetPayload, VarsGlobalSetPayload } from "../utils/vars.js";
8
+
9
+ export class VarsGlobal extends Module<VarsPluginEvents, VarsPluginConstants, VarsPluginSettings, VarsPluginParams> {
10
+ name = "vars.global";
11
+
12
+ subscribe = () => {
13
+ this.on(this.EVENTS.VARS.GLOBAL_GET, this.onVarGlobalGet);
14
+ this.on(this.EVENTS.VARS.GLOBAL_SET, this.onVarGlobalSet);
15
+ this.on(this.EVENTS.VARS.GLOBAL_CLEAR, this.onVarGlobalClear);
16
+ };
17
+
18
+ init = async () => {
19
+ this.shared.vars = (await this.emitOne(this.EVENTS.STORAGE.GET_ALL, { module: this.name })) as Record<string, VarValue>;
20
+ };
21
+
22
+ onVarGlobalGet = ({ name = "" }: VarsGlobalGetPayload = {}) => this.shared.vars[name];
23
+
24
+ onVarGlobalSet = ({ name = "", value = "" }: VarsGlobalSetPayload = {}) => {
25
+ this.shared.vars[name] = value;
26
+
27
+ return this.emit(this.EVENTS.STORAGE.SET, { module: this.name, key: name, value });
28
+ };
29
+
30
+ onVarGlobalClear = () => this.emit(this.EVENTS.STORAGE.RM_ALL, { module: this.name });
31
+ }
@@ -0,0 +1,29 @@
1
+ import { Module } from "@vnejs/module";
2
+
3
+ import type { VarsPluginConstants, VarsPluginEvents, VarsPluginParams, VarsPluginSettings } from "../types.js";
4
+ import type { VarsInjectPayload } from "../utils/vars.js";
5
+
6
+ const INJECT_REG = /%vars:(?<line>.*?)%/;
7
+
8
+ export class VarsInject extends Module<VarsPluginEvents, VarsPluginConstants, VarsPluginSettings, VarsPluginParams> {
9
+ name = "vars.inject";
10
+
11
+ subscribe = () => {
12
+ this.on(this.EVENTS.VARS.INJECT, this.onVarInject);
13
+ };
14
+
15
+ onVarInject = ({ text = "" }: VarsInjectPayload = {}) => this.injectsVars(text);
16
+
17
+ injectsVars = async (text: string): Promise<string> => {
18
+ if (INJECT_REG.test(text)) {
19
+ const line = INJECT_REG.exec(text)?.groups?.line ?? "";
20
+ const [type = "", name = "", keyword = ""] = line.split(":");
21
+
22
+ const varValue = await this.emitOne(this.EVENTS.VARS.GET, { type, name, isGlobal: keyword === this.CONST.SCENARIO.LINE_KEYWORDS.GLOBAL });
23
+
24
+ return this.injectsVars(text.replace(`%vars:${line}%`, String(varValue)));
25
+ }
26
+
27
+ return text;
28
+ };
29
+ }
@@ -0,0 +1,30 @@
1
+ import { Module } from "@vnejs/module";
2
+
3
+ import type { VarsPluginConstants, VarsPluginEvents, VarsPluginParams, VarsPluginSettings } from "../types.js";
4
+ import type { ScenarioLine, VarsScenarioPayload } from "../utils/vars.js";
5
+
6
+ export class VarsScenario extends Module<VarsPluginEvents, VarsPluginConstants, VarsPluginSettings, VarsPluginParams> {
7
+ name = "vars.scenario";
8
+
9
+ subscribe = () => {
10
+ this.on(this.EVENTS.VARS.SCENARIO, this.onVarScenario);
11
+ };
12
+
13
+ onVarScenario = async ({ shouldGoInside = false }: VarsScenarioPayload = {}) => {
14
+ if (shouldGoInside) return this.increaseCurLine(1);
15
+
16
+ const { curLine = 0, label } = this.globalState.scenario;
17
+
18
+ const lines = (await this.emitOne(this.EVENTS.SCENARIO.LINES_GET, { label })) as ScenarioLine[];
19
+
20
+ let indexShift = 1;
21
+
22
+ while (lines[curLine + indexShift] && (lines[curLine + indexShift].indent ?? 0) > (lines[curLine].indent ?? 0)) indexShift++;
23
+
24
+ return this.increaseCurLine(indexShift);
25
+ };
26
+
27
+ increaseCurLine = (indexShift: number) => {
28
+ this.globalState.scenario.curLine += indexShift;
29
+ };
30
+ }
@@ -0,0 +1,50 @@
1
+ import { Module } from "@vnejs/module";
2
+ import type { ModuleGlobalStateVars, VarValue } from "@vnejs/plugins.vars.contract";
3
+
4
+ import type { VarsPluginConstants, VarsPluginEvents, VarsPluginParams, VarsPluginSettings } from "../types.js";
5
+ import type { VarsDefaultRegPayload, VarsGetPayload, VarsSetPayload, VarsStateSlicePayload } from "../utils/vars.js";
6
+
7
+ export class Vars extends Module<VarsPluginEvents, VarsPluginConstants, VarsPluginSettings, VarsPluginParams, ModuleGlobalStateVars> {
8
+ name = "vars";
9
+
10
+ defaultVarValues: Record<string, VarValue | undefined> = {};
11
+
12
+ subscribe = () => {
13
+ this.on(this.EVENTS.VARS.GET, this.onVarGet);
14
+ this.on(this.EVENTS.VARS.SET, this.onVarSet);
15
+ this.on(this.EVENTS.VARS.DEFAULT_REG, this.onVarDefaultReg);
16
+
17
+ this.on(this.EVENTS.STATE.SET, this.onStateSet);
18
+ this.on(this.EVENTS.STATE.CLEAR, this.setDefaultState);
19
+ };
20
+
21
+ onVarSet = ({ name = "", type = "", value = "", isGlobal = false }: VarsSetPayload = {}) => {
22
+ const varName = this.getInnerVarName(name, type);
23
+
24
+ return isGlobal ? this.emit(this.EVENTS.VARS.GLOBAL_SET, { name: varName, value }) : this.setLocalVar(varName, value);
25
+ };
26
+
27
+ onVarGet = async ({ name = "", type = "", isGlobal = false, state = null }: VarsGetPayload = {}) => {
28
+ const varName = this.getInnerVarName(name, type);
29
+
30
+ const value = isGlobal ? await this.emitOne(this.EVENTS.VARS.GLOBAL_GET, { name: varName }) : state ? state.vars?.[varName] : this.state[varName];
31
+
32
+ return (value as VarValue | undefined) ?? this.defaultVarValues[type];
33
+ };
34
+
35
+ onVarDefaultReg = ({ type = "", value }: VarsDefaultRegPayload = {}) => {
36
+ this.defaultVarValues[type] = value;
37
+ };
38
+
39
+ onStateSet = async (payload: VarsStateSlicePayload = {}) => {
40
+ const state = payload[this.name];
41
+
42
+ return this.setState((await this.emitOne(this.EVENTS.VENDORS.CLONE, state)) as ModuleGlobalStateVars);
43
+ };
44
+
45
+ getInnerVarName = (name = "", type = "") => `${type}:${name}`;
46
+
47
+ setLocalVar = (name = "", value: VarValue = "") => {
48
+ this.state[name] = value;
49
+ };
50
+ }
package/src/types.ts ADDED
@@ -0,0 +1,19 @@
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 StatePluginName, SubscribeEvents as StateSubscribeEvents } from "@vnejs/plugins.core.state.contract";
4
+ import type { PluginName as StoragePluginName, SubscribeEvents as StorageSubscribeEvents } from "@vnejs/plugins.core.storage.contract";
5
+ import type { PluginName as VendorsPluginName, SubscribeEvents as VendorsSubscribeEvents } from "@vnejs/plugins.core.vendors.contract";
6
+ import type { PluginName, SubscribeEvents } from "@vnejs/plugins.vars.contract";
7
+
8
+ export type VarsPluginEvents = VnePluginEventsMapRegistry &
9
+ Record<PluginName, SubscribeEvents> &
10
+ Record<ScenarioPluginName, ScenarioSubscribeEvents> &
11
+ Record<StatePluginName, StateSubscribeEvents> &
12
+ Record<StoragePluginName, StorageSubscribeEvents> &
13
+ Record<VendorsPluginName, VendorsSubscribeEvents>;
14
+
15
+ export type VarsPluginConstants = VnePluginConstantsMapRegistry & Record<ScenarioPluginName, ScenarioConstants>;
16
+
17
+ export type VarsPluginSettings = VnePluginSettingsMapRegistry;
18
+
19
+ export type VarsPluginParams = VnePluginParamsMapRegistry;
@@ -0,0 +1,12 @@
1
+ import type { ModuleGlobalStateVars, VarValue } from "@vnejs/plugins.vars.contract";
2
+
3
+ export type ScenarioLine = {
4
+ line: string;
5
+ indent?: number;
6
+ };
7
+
8
+ export type VarsStateSlicePayload = {
9
+ [moduleName: string]: ModuleGlobalStateVars | undefined;
10
+ };
11
+
12
+ export type { VarValue, VarsDefaultRegPayload, VarsGetPayload, VarsGlobalGetPayload, VarsGlobalSetPayload, VarsInjectPayload, VarsScenarioPayload, VarsSetPayload } from "@vnejs/plugins.vars.contract";
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/events.js DELETED
@@ -1,11 +0,0 @@
1
- export const SUBSCRIBE_EVENTS = {
2
- GET: "vne:vars:get",
3
- SET: "vne:vars:set",
4
- INJECT: "vne:vars:inject",
5
- SCENARIO: "vne:vars:scenario",
6
- DEFAULT_REG: "vne:vars:default_reg",
7
-
8
- GLOBAL_SET: "vne:vars:global_set",
9
- GLOBAL_GET: "vne:vars:global_get",
10
- GLOBAL_CLEAR: "vne:vars:global_clear",
11
- };
package/index.js DELETED
@@ -1,10 +0,0 @@
1
- import { regPlugin } from "@vnejs/shared";
2
-
3
- import { SUBSCRIBE_EVENTS } from "./const/events";
4
-
5
- import { VarsGlobal } from "./modules/global";
6
- import { VarsInject } from "./modules/inject";
7
- import { VarsScenario } from "./modules/scenario";
8
- import { Vars } from "./modules/vars";
9
-
10
- regPlugin("VARS", { events: SUBSCRIBE_EVENTS }, [VarsGlobal, VarsInject, Vars, VarsScenario]);
package/modules/global.js DELETED
@@ -1,23 +0,0 @@
1
- import { Module } from "@vnejs/module";
2
-
3
- export class VarsGlobal extends Module {
4
- name = "vars.global";
5
-
6
- subscribe = () => {
7
- this.on(this.EVENTS.VARS.GLOBAL_GET, this.onVarGlobalGet);
8
- this.on(this.EVENTS.VARS.GLOBAL_SET, this.onVarGlobalSet);
9
- this.on(this.EVENTS.VARS.GLOBAL_CLEAR, this.onVarGlobalClear);
10
- };
11
-
12
- init = async () => {
13
- this.shared.vars = await this.emitOne(this.EVENTS.STORAGE.GET_ALL, { module: this.name });
14
- };
15
-
16
- onVarGlobalGet = ({ name = "" } = {}) => this.shared.vars[name];
17
- onVarGlobalSet = ({ name = "", value = "" } = {}) => {
18
- this.shared.vars[name] = value;
19
-
20
- return this.emit(this.EVENTS.STORAGE.SET, { module: this.name, key: name, value });
21
- };
22
- onVarGlobalClear = () => this.emit(this.EVENTS.STORAGE.RM_ALL, { module: this.name });
23
- }
package/modules/inject.js DELETED
@@ -1,26 +0,0 @@
1
- import { Module } from "@vnejs/module";
2
-
3
- const INJECT_REG = /\%vars:(?<line>.*?)\%/;
4
-
5
- export class VarsInject extends Module {
6
- name = "vars.inject";
7
-
8
- subscribe = () => {
9
- this.on(this.EVENTS.VARS.INJECT, this.onVarInject);
10
- };
11
-
12
- onVarInject = ({ text = "" } = {}) => this.injectsVars(text);
13
-
14
- injectsVars = async (text) => {
15
- if (INJECT_REG.test(text)) {
16
- const line = INJECT_REG.exec(text).groups.line;
17
- const [type = "", name = "", keyword = ""] = line.split(":");
18
-
19
- const varValue = await this.emitOne(this.EVENTS.VARS.GET, { type, name, isGlobal: keyword === "global" });
20
-
21
- return this.injectsVars(text.replace(`%vars:${line}%`, String(varValue)));
22
- }
23
-
24
- return text;
25
- };
26
- }
@@ -1,27 +0,0 @@
1
- import { Module } from "@vnejs/module";
2
-
3
- export class VarsScenario extends Module {
4
- name = "vars.scenario";
5
-
6
- subscribe = () => {
7
- this.on(this.EVENTS.VARS.SCENARIO, this.onVarScenario);
8
- };
9
-
10
- onVarScenario = async ({ shouldGoInside = false } = {}) => {
11
- if (shouldGoInside) return this.increaseCurLine(1);
12
-
13
- const { curLine = 0, label } = this.globalState.scenario;
14
-
15
- const lines = await this.emitOne(this.EVENTS.SCENARIO.LINES_GET, { label });
16
-
17
- let indexShift = 1;
18
-
19
- while (lines[curLine + indexShift] && lines[curLine + indexShift].indent > lines[curLine].indent) indexShift++;
20
-
21
- return this.increaseCurLine(indexShift);
22
- };
23
-
24
- increaseCurLine = (indexShift) => {
25
- this.globalState.scenario.curLine += indexShift;
26
- };
27
- }
package/modules/vars.js DELETED
@@ -1,39 +0,0 @@
1
- import { Module } from "@vnejs/module";
2
-
3
- export class Vars extends Module {
4
- name = "vars";
5
-
6
- defaultVarValues = {};
7
-
8
- subscribe = () => {
9
- this.on(this.EVENTS.VARS.GET, this.onVarGet);
10
- this.on(this.EVENTS.VARS.SET, this.onVarSet);
11
- this.on(this.EVENTS.VARS.DEFAULT_REG, this.onVarDefaultReg);
12
-
13
- this.on(this.EVENTS.STATE.SET, this.onStateSet);
14
- this.on(this.EVENTS.STATE.CLEAR, this.setDefaultState);
15
- };
16
-
17
- onVarSet = ({ name = "", type = "", value = "", isGlobal = false } = {}) => {
18
- const varName = this.getInnerVarName(name, type);
19
-
20
- return isGlobal ? this.emit(this.EVENTS.VARS.GLOBAL_SET, { name: varName, value }) : this.setLocalVar(varName, value);
21
- };
22
- onVarGet = async ({ name = "", type = "", isGlobal = false, state = null } = {}) => {
23
- const varName = this.getInnerVarName(name, type);
24
-
25
- const value = isGlobal ? await this.emitOne(this.EVENTS.VARS.GLOBAL_GET, { name: varName }) : state ? state.vars[varName] : this.state[varName];
26
-
27
- return value ?? this.defaultVarValues[type];
28
- };
29
- onVarDefaultReg = ({ type = "", value } = {}) => {
30
- this.defaultVarValues[type] = value;
31
- };
32
-
33
- onStateSet = async ({ [this.name]: state } = {}) => this.setState(await this.emitOne(this.EVENTS.VENDORS.CLONE, state));
34
-
35
- getInnerVarName = (name = "", type = "") => `${type}:${name}`;
36
- setLocalVar = (name = "", value = "") => {
37
- this.state[name] = value;
38
- };
39
- }