From 73656a1a842dfffd297edb559673633db506d089 Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Sat, 3 Sep 2022 21:45:54 +0900 Subject: [PATCH] =?UTF-8?q?Add:=20engineManifest=E3=81=AEstore=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/engineManifest.ts | 27 ++++++++++++++++++++++ src/store/index.ts | 8 +++++++ src/store/type.ts | 42 ++++++++++++++++++++++++++++++----- tests/unit/store/Vuex.spec.ts | 4 ++++ 4 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 src/store/engineManifest.ts diff --git a/src/store/engineManifest.ts b/src/store/engineManifest.ts new file mode 100644 index 0000000000..1dcf44e3c1 --- /dev/null +++ b/src/store/engineManifest.ts @@ -0,0 +1,27 @@ +import { + EngineManifestActions, + EngineManifestGetters, + EngineManifestMutations, + EngineManifestStoreState, + VoiceVoxStoreOptions, +} from "@/store/type"; + +export const engineManifestStoreState: EngineManifestStoreState = {}; + +export const engineManifestStore: VoiceVoxStoreOptions< + EngineManifestGetters, + EngineManifestActions, + EngineManifestMutations +> = { + getters: {}, + mutations: {}, + actions: { + GET_ENGINE_MANIFEST: async ({ dispatch }, { engineId }) => { + return await dispatch("INSTANTIATE_ENGINE_CONNECTOR", { + engineId, + }).then((instance) => + instance.invoke("engineManifestEngineManifestGet")({}) + ); + }, + }, +}; diff --git a/src/store/index.ts b/src/store/index.ts index 1f2ddf4024..ea9c47fea1 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -28,6 +28,10 @@ import { presetStoreState, presetStore } from "./preset"; import { dictionaryStoreState, dictionaryStore } from "./dictionary"; import { proxyStore, proxyStoreState } from "./proxy"; import { DefaultStyleId } from "@/type/preload"; +import { + engineManifestStore, + engineManifestStoreState, +} from "./engineManifest"; const isDevelopment = process.env.NODE_ENV == "development"; @@ -206,6 +210,7 @@ export const store = createStore({ ...indexStoreState, ...presetStoreState, ...dictionaryStoreState, + ...engineManifestStoreState, ...proxyStoreState, }, @@ -217,6 +222,7 @@ export const store = createStore({ ...settingStore.getters, ...presetStore.getters, ...dictionaryStore.getters, + ...engineManifestStore.getters, ...audioCommandStore.getters, ...indexStore.getters, ...proxyStore.getters, @@ -231,6 +237,7 @@ export const store = createStore({ ...audioCommandStore.mutations, ...presetStore.mutations, ...dictionaryStore.mutations, + ...engineManifestStore.mutations, ...indexStore.mutations, ...proxyStore.mutations, }, @@ -244,6 +251,7 @@ export const store = createStore({ ...audioCommandStore.actions, ...presetStore.actions, ...dictionaryStore.actions, + ...engineManifestStore.actions, ...indexStore.actions, ...proxyStore.actions, }, diff --git a/src/store/type.ts b/src/store/type.ts index 5327488d7a..5d310a26dc 100644 --- a/src/store/type.ts +++ b/src/store/type.ts @@ -6,7 +6,12 @@ import { StoreOptions, } from "./vuex"; import { Patch } from "immer"; -import { AccentPhrase, AudioQuery, UserDictWord } from "@/openapi"; +import { + AccentPhrase, + AudioQuery, + EngineManifest, + UserDictWord, +} from "@/openapi"; import { createCommandMutationTree, PayloadRecipeTree } from "./command"; import { CharacterInfo, @@ -70,12 +75,12 @@ export type WriteErrorTypeForSaveAllResultDialog = { type StoreType = { [P in keyof T as Extract extends never - ? never - : P]: T[P] extends { + ? never + : P]: T[P] extends { [K in U]: infer R; } - ? R - : never; + ? R + : never; }; export type QuasarDialog = QVueGlobals["dialog"]; @@ -1180,6 +1185,31 @@ export type DictionaryGetters = StoreType; export type DictionaryMutations = StoreType; export type DictionaryActions = StoreType; +/* + Engine manifest Store Types +*/ + +export type EngineManifestStoreState = Record; + +type EngineManifestStoreTypes = { + GET_ENGINE_MANIFEST: { + action(payload: { engineId: string }): Promise; + }; +}; + +export type EngineManifestGetters = StoreType< + EngineManifestStoreTypes, + "getter" +>; +export type EngineManifestMutations = StoreType< + EngineManifestStoreTypes, + "mutation" +>; +export type EngineManifestActions = StoreType< + EngineManifestStoreTypes, + "action" +>; + /* * Setting Store Types */ @@ -1223,6 +1253,7 @@ export type State = AudioStoreState & UiStoreState & PresetStoreState & DictionaryStoreState & + EngineManifestStoreState & ProxyStoreState; type AllStoreTypes = AudioStoreTypes & @@ -1234,6 +1265,7 @@ type AllStoreTypes = AudioStoreTypes & UiStoreTypes & PresetStoreTypes & DictionaryStoreTypes & + EngineManifestStoreTypes & ProxyStoreTypes; export type AllGetters = StoreType; diff --git a/tests/unit/store/Vuex.spec.ts b/tests/unit/store/Vuex.spec.ts index d37e5fc47b..5e985c7927 100644 --- a/tests/unit/store/Vuex.spec.ts +++ b/tests/unit/store/Vuex.spec.ts @@ -11,6 +11,7 @@ import { presetStore } from "@/store/preset"; import { assert } from "chai"; import { proxyStore } from "@/store/proxy"; import { dictionaryStore } from "@/store/dictionary"; +import { engineManifestStore } from "@/store/engineManifest"; const isDevelopment = process.env.NODE_ENV == "development"; // TODO: Swap external files to Mock @@ -106,6 +107,7 @@ describe("store/vuex.js test", () => { ...presetStore.getters, ...proxyStore.getters, ...dictionaryStore.getters, + ...engineManifestStore.getters, }, mutations: { ...uiStore.mutations, @@ -118,6 +120,7 @@ describe("store/vuex.js test", () => { ...presetStore.mutations, ...proxyStore.mutations, ...dictionaryStore.mutations, + ...engineManifestStore.mutations, }, actions: { ...uiStore.actions, @@ -130,6 +133,7 @@ describe("store/vuex.js test", () => { ...presetStore.actions, ...proxyStore.actions, ...dictionaryStore.actions, + ...engineManifestStore.actions, }, plugins: isDevelopment ? [createLogger()] : undefined, strict: process.env.NODE_ENV !== "production",