Skip to content

Commit

Permalink
Add: engineManifestのstoreを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenc-nanashi committed Sep 3, 2022
1 parent d832aca commit 73656a1
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 5 deletions.
27 changes: 27 additions & 0 deletions src/store/engineManifest.ts
Original file line number Diff line number Diff line change
@@ -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")({})
);
},
},
};
8 changes: 8 additions & 0 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -206,6 +210,7 @@ export const store = createStore<State, AllGetters, AllActions, AllMutations>({
...indexStoreState,
...presetStoreState,
...dictionaryStoreState,
...engineManifestStoreState,
...proxyStoreState,
},

Expand All @@ -217,6 +222,7 @@ export const store = createStore<State, AllGetters, AllActions, AllMutations>({
...settingStore.getters,
...presetStore.getters,
...dictionaryStore.getters,
...engineManifestStore.getters,
...audioCommandStore.getters,
...indexStore.getters,
...proxyStore.getters,
Expand All @@ -231,6 +237,7 @@ export const store = createStore<State, AllGetters, AllActions, AllMutations>({
...audioCommandStore.mutations,
...presetStore.mutations,
...dictionaryStore.mutations,
...engineManifestStore.mutations,
...indexStore.mutations,
...proxyStore.mutations,
},
Expand All @@ -244,6 +251,7 @@ export const store = createStore<State, AllGetters, AllActions, AllMutations>({
...audioCommandStore.actions,
...presetStore.actions,
...dictionaryStore.actions,
...engineManifestStore.actions,
...indexStore.actions,
...proxyStore.actions,
},
Expand Down
42 changes: 37 additions & 5 deletions src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -70,12 +75,12 @@ export type WriteErrorTypeForSaveAllResultDialog = {

type StoreType<T, U extends "getter" | "mutation" | "action"> = {
[P in keyof T as Extract<keyof T[P], U> 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"];
Expand Down Expand Up @@ -1180,6 +1185,31 @@ export type DictionaryGetters = StoreType<DictionaryStoreTypes, "getter">;
export type DictionaryMutations = StoreType<DictionaryStoreTypes, "mutation">;
export type DictionaryActions = StoreType<DictionaryStoreTypes, "action">;

/*
Engine manifest Store Types
*/

export type EngineManifestStoreState = Record<string, unknown>;

type EngineManifestStoreTypes = {
GET_ENGINE_MANIFEST: {
action(payload: { engineId: string }): Promise<EngineManifest>;
};
};

export type EngineManifestGetters = StoreType<
EngineManifestStoreTypes,
"getter"
>;
export type EngineManifestMutations = StoreType<
EngineManifestStoreTypes,
"mutation"
>;
export type EngineManifestActions = StoreType<
EngineManifestStoreTypes,
"action"
>;

/*
* Setting Store Types
*/
Expand Down Expand Up @@ -1223,6 +1253,7 @@ export type State = AudioStoreState &
UiStoreState &
PresetStoreState &
DictionaryStoreState &
EngineManifestStoreState &
ProxyStoreState;

type AllStoreTypes = AudioStoreTypes &
Expand All @@ -1234,6 +1265,7 @@ type AllStoreTypes = AudioStoreTypes &
UiStoreTypes &
PresetStoreTypes &
DictionaryStoreTypes &
EngineManifestStoreTypes &
ProxyStoreTypes;

export type AllGetters = StoreType<AllStoreTypes, "getter">;
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/store/Vuex.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -106,6 +107,7 @@ describe("store/vuex.js test", () => {
...presetStore.getters,
...proxyStore.getters,
...dictionaryStore.getters,
...engineManifestStore.getters,
},
mutations: {
...uiStore.mutations,
Expand All @@ -118,6 +120,7 @@ describe("store/vuex.js test", () => {
...presetStore.mutations,
...proxyStore.mutations,
...dictionaryStore.mutations,
...engineManifestStore.mutations,
},
actions: {
...uiStore.actions,
Expand All @@ -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",
Expand Down

0 comments on commit 73656a1

Please sign in to comment.