@vnejs/compatibility.scenario.choose-with-scenario.history 0.2.1

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,9 @@
1
+ import "@vnejs/contracts.scenario.choose";
2
+ import "@vnejs/contracts.scenario.history";
3
+ import { ModuleCore } from "@vnejs/module.core";
4
+ import type { PluginConstants, PluginEvents, PluginParams, PluginSettings } from "./types.js";
5
+ export declare class CompatibilityScenarioChooseWithScenarioHistory extends ModuleCore<PluginEvents, PluginConstants, PluginSettings, PluginParams> {
6
+ name: string;
7
+ init: () => Promise<unknown[]> | undefined;
8
+ onChooseOptionBefore: () => Promise<unknown[]> | undefined;
9
+ }
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ import "@vnejs/contracts.scenario.choose";
2
+ import "@vnejs/contracts.scenario.history";
3
+ import { ModuleCore } from "@vnejs/module.core";
4
+ import { regModule } from "@vnejs/shared";
5
+ const HISTORY_CHOICE_LOC_KEY = "choice";
6
+ export class CompatibilityScenarioChooseWithScenarioHistory extends ModuleCore {
7
+ name = "compatibility.scenario.choose-with-scenario.history";
8
+ init = () => this.emit(this.EVENTS.CHOOSE.OPTION_BEFORE_REG, { handler: this.onChooseOptionBefore });
9
+ onChooseOptionBefore = () => this.emit(this.EVENTS.HISTORY.ADD, { locKey: HISTORY_CHOICE_LOC_KEY });
10
+ }
11
+ regModule(CompatibilityScenarioChooseWithScenarioHistory);
@@ -0,0 +1,7 @@
1
+ import type { ModuleCoreConstants, ModuleCoreEvents, ModuleCoreParams, ModuleCoreSettings } from "@vnejs/module.core";
2
+ import type { PluginName as ChoosePluginName, SubscribeEvents as ChooseSubscribeEvents } from "@vnejs/contracts.scenario.choose";
3
+ import type { PluginName as HistoryPluginName, SubscribeEvents as HistorySubscribeEvents } from "@vnejs/contracts.scenario.history";
4
+ export type PluginEvents = ModuleCoreEvents & Record<ChoosePluginName, ChooseSubscribeEvents> & Record<HistoryPluginName, HistorySubscribeEvents>;
5
+ export type PluginConstants = ModuleCoreConstants;
6
+ export type PluginSettings = ModuleCoreSettings;
7
+ export type PluginParams = ModuleCoreParams;
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@vnejs/compatibility.scenario.choose-with-scenario.history",
3
+ "version": "0.2.1",
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
+ ],
20
+ "scripts": {
21
+ "test": "npx @vnejs/monorepo test",
22
+ "build": "npx @vnejs/monorepo package",
23
+ "publish:major:plugin": "npm run publish:major",
24
+ "publish:minor:plugin": "npm run publish:minor",
25
+ "publish:patch:plugin": "npm run publish:patch",
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"
29
+ },
30
+ "author": "",
31
+ "license": "ISC",
32
+ "peerDependencies": {
33
+ "@vnejs/module.core": "~0.2.0",
34
+ "@vnejs/contracts.scenario.choose": "~0.2.0",
35
+ "@vnejs/contracts.scenario.history": "~0.2.0",
36
+ "@vnejs/shared": "~0.2.0"
37
+ },
38
+ "devDependencies": {
39
+ "@vnejs/configs.ts-common": "~0.2.0",
40
+ "@vnejs/configs.vitest": "~0.2.0",
41
+ "@vnejs/test-utils": "~0.2.0"
42
+ }
43
+ }
package/src/index.ts ADDED
@@ -0,0 +1,19 @@
1
+ import "@vnejs/contracts.scenario.choose";
2
+ import "@vnejs/contracts.scenario.history";
3
+
4
+ import { ModuleCore } from "@vnejs/module.core";
5
+ import { regModule } from "@vnejs/shared";
6
+
7
+ import type { PluginConstants, PluginEvents, PluginParams, PluginSettings } from "./types.js";
8
+
9
+ const HISTORY_CHOICE_LOC_KEY = "choice";
10
+
11
+ export class CompatibilityScenarioChooseWithScenarioHistory extends ModuleCore<PluginEvents, PluginConstants, PluginSettings, PluginParams> {
12
+ name = "compatibility.scenario.choose-with-scenario.history";
13
+
14
+ init = () => this.emit(this.EVENTS.CHOOSE.OPTION_BEFORE_REG, { handler: this.onChooseOptionBefore });
15
+
16
+ onChooseOptionBefore = () => this.emit(this.EVENTS.HISTORY.ADD, { locKey: HISTORY_CHOICE_LOC_KEY });
17
+ }
18
+
19
+ regModule(CompatibilityScenarioChooseWithScenarioHistory);
@@ -0,0 +1,34 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { spyEvent } from "@vnejs/test-utils";
4
+
5
+ import { CompatibilityScenarioChooseWithScenarioHistory } from "../index.js";
6
+ import { CHOOSE_EVENTS, createCompatibilityTestModule, HISTORY_EVENTS, registerCompatibilityVne } from "./setup.js";
7
+
8
+ describe("CompatibilityScenarioChooseWithScenarioHistory", () => {
9
+ beforeEach(() => registerCompatibilityVne());
10
+
11
+ it("init registers CHOOSE.OPTION_BEFORE handler", async () => {
12
+ const { module, observer } = createCompatibilityTestModule(CompatibilityScenarioChooseWithScenarioHistory, { subscribe: false });
13
+ const reg = spyEvent(observer, CHOOSE_EVENTS.OPTION_BEFORE_REG);
14
+
15
+ await (module as CompatibilityScenarioChooseWithScenarioHistory).init();
16
+
17
+ expect(reg).toHaveBeenCalledOnce();
18
+ expect(reg.mock.calls[0]?.[0]?.handler).toEqual(expect.any(Function));
19
+ });
20
+
21
+ it("registered handler emits HISTORY.ADD with locKey choice", async () => {
22
+ const { module, observer } = createCompatibilityTestModule(CompatibilityScenarioChooseWithScenarioHistory, { subscribe: false });
23
+ const reg = spyEvent(observer, CHOOSE_EVENTS.OPTION_BEFORE_REG);
24
+ const add = spyEvent(observer, HISTORY_EVENTS.ADD);
25
+
26
+ await (module as CompatibilityScenarioChooseWithScenarioHistory).init();
27
+
28
+ const handler = reg.mock.calls[0]?.[0]?.handler as () => unknown;
29
+ await handler();
30
+
31
+ expect(add).toHaveBeenCalledOnce();
32
+ expect(add.mock.calls[0]?.[0]).toMatchObject({ locKey: "choice" });
33
+ });
34
+ });
@@ -0,0 +1,16 @@
1
+ import { PARAMS as CHOOSE_PARAMS, PLUGIN_NAME as CHOOSE, SUBSCRIBE_EVENTS as CHOOSE_EVENTS } from "@vnejs/contracts.scenario.choose";
2
+ import { PLUGIN_NAME as HISTORY, SUBSCRIBE_EVENTS as HISTORY_EVENTS } from "@vnejs/contracts.scenario.history";
3
+ import { createTestModule as baseCreateTestModule, registerCoreVne, registerVnePlugin } from "@vnejs/test-utils";
4
+
5
+ export const registerCompatibilityVne = () => {
6
+ registerCoreVne();
7
+ registerVnePlugin(CHOOSE, { events: CHOOSE_EVENTS, params: CHOOSE_PARAMS });
8
+ registerVnePlugin(HISTORY, { events: HISTORY_EVENTS });
9
+ };
10
+
11
+ export const createCompatibilityTestModule = <T extends Parameters<typeof baseCreateTestModule>[0]>(
12
+ ModuleClass: T,
13
+ options: Parameters<typeof baseCreateTestModule>[1] = {},
14
+ ) => baseCreateTestModule(ModuleClass, options);
15
+
16
+ export { CHOOSE_EVENTS, HISTORY_EVENTS };
package/src/types.ts ADDED
@@ -0,0 +1,11 @@
1
+ import type { ModuleCoreConstants, ModuleCoreEvents, ModuleCoreParams, ModuleCoreSettings } from "@vnejs/module.core";
2
+ import type { PluginName as ChoosePluginName, SubscribeEvents as ChooseSubscribeEvents } from "@vnejs/contracts.scenario.choose";
3
+ import type { PluginName as HistoryPluginName, SubscribeEvents as HistorySubscribeEvents } from "@vnejs/contracts.scenario.history";
4
+
5
+ export type PluginEvents = ModuleCoreEvents & Record<ChoosePluginName, ChooseSubscribeEvents> & Record<HistoryPluginName, HistorySubscribeEvents>;
6
+
7
+ export type PluginConstants = ModuleCoreConstants;
8
+
9
+ export type PluginSettings = ModuleCoreSettings;
10
+
11
+ export type PluginParams = ModuleCoreParams;
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", "src/tests"]
9
+ }