Skip to content

Commit

Permalink
Code: schema系の命名規則を統一 (#1697)
Browse files Browse the repository at this point in the history
* Code: schema系の命名規則を統一

* Add: ドキュメントに追記

* Fix: 日本語を修正
  • Loading branch information
sevenc-nanashi authored Jan 9, 2024
1 parent 1e7bed7 commit 3152e37
Show file tree
Hide file tree
Showing 17 changed files with 125 additions and 106 deletions.
19 changes: 16 additions & 3 deletions docs/細かい設計方針.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,28 @@ SpeakerId は話者が持つ ID で、世界で唯一かつ不変。エンジン
StyleId はスタイルごとの ID で、エンジンごとに唯一であれば良いです。

声を一意に決めるには、(EngineId, SpeakerId, StyleId)の3組が揃っている必要がある、という仕様を目指しています。
現状は、音声合成APIに SpeakerId 引数が無いため、(EngineId, StyleId)の2組で一意に声が決まっています。
現状は、音声合成 API に SpeakerId 引数が無いため、(EngineId, StyleId)の2組で一意に声が決まっています。
現状は StyleId はエンジンごとに唯一である必要がありますが、話者ごとに唯一であれば良いという仕様を目指しています。

VOICEVOX は歴史的経緯により、 SpeakerId と StyleId が混同していることがあります。
特に型が整数値になっている SpeakerId は StyleId と混同している場合があります。
(エンジン API の SpeakerId 引数に StyleId を渡したりなど。)

StyleId は現在整数値型になっていますが、将来的にはUuidにしたいと考えています
StyleId は現在整数値型になっていますが、将来的には Uuid にしたいと考えています

## シングルファイルコンポーネント(SFC、`.vue`ファイル)のtemplate、script、styleの順序
## シングルファイルコンポーネント(SFC、`.vue`ファイル)の template、script、style の順序

`<template>``<script>``<style>`の順序で記述してください。

## Zod のスキーマと型定義

Zod のスキーマ(`z.object`)の変数名は、`[camelCaseでの名前]Schema`、型定義(`z.infer`)の名前は、`[PascalCaseでの名前]Type`としてください。

```ts
export const hogeFugaSchema = z.object({
hoge: z.string(),
fuga: z.number(),
});

export type HogeFugaType = z.infer<typeof hogeFugaSchema>;
```
6 changes: 3 additions & 3 deletions src/background/engineManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import {
EngineInfo,
EngineDirValidationResult,
MinimumEngineManifest,
MinimumEngineManifestType,
EngineId,
minimumEngineManifestSchema,
envEngineInfoSchema,
Expand Down Expand Up @@ -97,7 +97,7 @@ export class EngineManager {
if (!fs.existsSync(manifestPath)) {
return "manifestNotFound";
}
let manifest: MinimumEngineManifest;
let manifest: MinimumEngineManifestType;
try {
manifest = minimumEngineManifestSchema.parse(
JSON.parse(fs.readFileSync(manifestPath, { encoding: "utf8" }))
Expand Down Expand Up @@ -529,7 +529,7 @@ export class EngineManager {
path.join(engineDir, "engine_manifest.json"),
"utf-8"
);
let manifestContent: MinimumEngineManifest;
let manifestContent: MinimumEngineManifestType;
try {
manifestContent = minimumEngineManifestSchema.parse(JSON.parse(manifest));
} catch (e) {
Expand Down
23 changes: 12 additions & 11 deletions src/background/vvppManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
EngineId,
EngineInfo,
minimumEngineManifestSchema,
MinimumEngineManifest,
MinimumEngineManifestType,
} from "@/type/preload";

const isNotWin = process.platform !== "win32";
Expand Down Expand Up @@ -93,12 +93,12 @@ export class VvppManager {
this.willDeleteEngineIds.add(engineId);
}

toValidDirName(manifest: MinimumEngineManifest) {
toValidDirName(manifest: MinimumEngineManifestType) {
// フォルダに使用できない文字が含まれている場合は置換する
return `${manifest.name.replace(/[\s<>:"/\\|?*]+/g, "_")}+${manifest.uuid}`;
}

isEngineDirName(dir: string, manifest: MinimumEngineManifest) {
isEngineDirName(dir: string, manifest: MinimumEngineManifestType) {
return dir.endsWith(`+${manifest.uuid}`);
}

Expand All @@ -121,7 +121,7 @@ export class VvppManager {

private async extractVvpp(
vvppLikeFilePath: string
): Promise<{ outputDir: string; manifest: MinimumEngineManifest }> {
): Promise<{ outputDir: string; manifest: MinimumEngineManifestType }> {
const nonce = new Date().getTime().toString();
const outputDir = path.join(this.vvppEngineDir, ".tmp", nonce);

Expand Down Expand Up @@ -240,14 +240,15 @@ export class VvppManager {
await fs.promises.rm(tmpConcatenatedFile);
}
}
const manifest: MinimumEngineManifest = minimumEngineManifestSchema.parse(
JSON.parse(
await fs.promises.readFile(
path.join(outputDir, "engine_manifest.json"),
"utf-8"
const manifest: MinimumEngineManifestType =
minimumEngineManifestSchema.parse(
JSON.parse(
await fs.promises.readFile(
path.join(outputDir, "engine_manifest.json"),
"utf-8"
)
)
)
);
);
return {
outputDir,
manifest,
Expand Down
8 changes: 4 additions & 4 deletions src/browser/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import {
defaultToolbarButtonSetting,
configSchema,
EngineId,
EngineSetting,
EngineSettingType,
EngineSettings,
HotkeySetting,
HotkeySettingType,
Sandbox,
ThemeConf,
} from "@/type/preload";
Expand Down Expand Up @@ -220,7 +220,7 @@ export const api: Sandbox = {
openEngineDirectory(/* engineId: EngineId */) {
throw new Error(`Not supported on Browser version: openEngineDirectory`);
},
async hotkeySettings(newData?: HotkeySetting) {
async hotkeySettings(newData?: HotkeySettingType) {
type HotkeySettingType = ReturnType<
typeof configSchema["parse"]
>["hotkeySettings"];
Expand Down Expand Up @@ -294,7 +294,7 @@ export const api: Sandbox = {
configManager.set(key, newValue);
return newValue;
},
async setEngineSetting(engineId: EngineId, engineSetting: EngineSetting) {
async setEngineSetting(engineId: EngineId, engineSetting: EngineSettingType) {
const engineSettings = (await this.getSetting(
"engineSettings"
)) as EngineSettings;
Expand Down
4 changes: 2 additions & 2 deletions src/components/AudioDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ import AccentPhrase from "./AccentPhrase.vue";
import { useStore } from "@/store";
import {
AudioKey,
HotkeyAction,
HotkeyActionType,
HotkeyReturnType,
isMac,
} from "@/type/preload";
Expand All @@ -111,7 +111,7 @@ const supportedFeatures = computed(
.supportedFeatures) as EngineManifest["supportedFeatures"] | undefined
);
const hotkeyMap = new Map<HotkeyAction, () => HotkeyReturnType>([
const hotkeyMap = new Map<HotkeyActionType, () => HotkeyReturnType>([
[
"再生/停止",
() => {
Expand Down
6 changes: 3 additions & 3 deletions src/components/HeaderBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
import { useStore } from "@/store";
import { setHotkeyFunctions } from "@/store/setting";
import {
HotkeyAction,
HotkeyActionType,
HotkeyReturnType,
ToolbarButtonTagType,
} from "@/type/preload";
Expand All @@ -54,7 +54,7 @@ const nowPlayingContinuously = computed(
() => store.state.nowPlayingContinuously
);
const undoRedoHotkeyMap = new Map<HotkeyAction, () => HotkeyReturnType>([
const undoRedoHotkeyMap = new Map<HotkeyActionType, () => HotkeyReturnType>([
// undo
[
"元に戻す",
Expand All @@ -78,7 +78,7 @@ const undoRedoHotkeyMap = new Map<HotkeyAction, () => HotkeyReturnType>([
]);
setHotkeyFunctions(undoRedoHotkeyMap);
const hotkeyMap = new Map<HotkeyAction, () => HotkeyReturnType>([
const hotkeyMap = new Map<HotkeyActionType, () => HotkeyReturnType>([
// play/stop continuously
[
"連続再生/停止",
Expand Down
4 changes: 2 additions & 2 deletions src/components/HeaderBarCustomDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
import { computed, ref, watch, Ref } from "vue";
import draggable from "vuedraggable";
import { useStore } from "@/store";
import { ToolbarButtonTagType, ToolbarSetting } from "@/type/preload";
import { ToolbarButtonTagType, ToolbarSettingType } from "@/type/preload";
import { getToolbarButtonName } from "@/store/utility";
const props =
Expand Down Expand Up @@ -148,7 +148,7 @@ watch(
}
);
const defaultSetting: ToolbarSetting = [];
const defaultSetting: ToolbarSettingType = [];
window.electron.getDefaultToolbarSetting().then((setting) => {
defaultSetting.push(...setting);
});
Expand Down
6 changes: 3 additions & 3 deletions src/components/HotkeySettingDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
import { computed, ref } from "vue";
import { useStore } from "@/store";
import { parseCombo } from "@/store/setting";
import { HotkeyAction, HotkeySetting } from "@/type/preload";
import { HotkeyActionType, HotkeySettingType } from "@/type/preload";
const props =
defineProps<{
Expand Down Expand Up @@ -280,7 +280,7 @@ const recordCombination = (event: KeyboardEvent) => {
const changeHotkeySettings = (action: string, combo: string) => {
return store.dispatch("SET_HOTKEY_SETTINGS", {
data: {
action: action as HotkeyAction,
action: action as HotkeyActionType,
combination: combo,
},
});
Expand Down Expand Up @@ -359,7 +359,7 @@ const resetHotkey = async (action: string) => {
if (result === "OK") {
window.electron
.getDefaultHotkeySettings()
.then((defaultSettings: HotkeySetting[]) => {
.then((defaultSettings: HotkeySettingType[]) => {
const setting = defaultSettings.find((value) => value.action == action);
if (setting == undefined) {
return;
Expand Down
4 changes: 2 additions & 2 deletions src/components/MenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
import MenuButton from "./MenuButton.vue";
import TitleBarButtons from "./TitleBarButtons.vue";
import { useStore } from "@/store";
import { HotkeyAction, HotkeyReturnType } from "@/type/preload";
import { HotkeyActionType, HotkeyReturnType } from "@/type/preload";
import { setHotkeyFunctions } from "@/store/setting";
import { base64ImageToUri } from "@/helpers/imageHelper";
Expand Down Expand Up @@ -430,7 +430,7 @@ const reassignSubMenuOpen = (idx: number) => {
}
};
const hotkeyMap = new Map<HotkeyAction, () => HotkeyReturnType>([
const hotkeyMap = new Map<HotkeyActionType, () => HotkeyReturnType>([
["新規プロジェクト", createNewProject],
["音声書き出し", generateAndSaveAllAudio],
["選択音声を書き出し", generateAndSaveSelectedAudio],
Expand Down
8 changes: 4 additions & 4 deletions src/components/SettingDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -948,15 +948,15 @@ import FileNamePatternDialog from "./FileNamePatternDialog.vue";
import { useStore } from "@/store";
import {
SavingSetting,
EngineSetting,
ExperimentalSetting,
EngineSettingType,
ExperimentalSettingType,
ActivePointScrollMode,
SplitTextWhenPasteType,
EditorFontType,
EngineId,
} from "@/type/preload";
type SamplingRateOption = EngineSetting["outputSamplingRate"];
type SamplingRateOption = EngineSettingType["outputSamplingRate"];
const props =
defineProps<{
Expand Down Expand Up @@ -1191,7 +1191,7 @@ const changeEnablePreset = (value: boolean) => {
};
const changeExperimentalSetting = async (
key: keyof ExperimentalSetting,
key: keyof ExperimentalSettingType,
data: boolean
) => {
store.dispatch("SET_EXPERIMENTAL_SETTING", {
Expand Down
10 changes: 5 additions & 5 deletions src/shared/ConfigManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
configSchema,
DefaultStyleId,
defaultHotkeySettings,
HotkeySetting,
ExperimentalSetting,
HotkeySettingType,
ExperimentalSettingType,
} from "@/type/preload";

const lockKey = "save";
Expand Down Expand Up @@ -73,7 +73,7 @@ const migrations: [string, (store: Record<string, unknown>) => unknown][] = [
(config) => {
// マルチエンジン機能を実験的機能から通常機能に
const experimentalSetting =
config.experimentalSetting as ExperimentalSetting; // FIXME: parseするかasをやめる
config.experimentalSetting as ExperimentalSettingType; // FIXME: parseするかasをやめる
if (
Object.prototype.hasOwnProperty.call(
experimentalSetting,
Expand Down Expand Up @@ -229,7 +229,7 @@ export abstract class BaseConfigManager {
const loadedHotkey = loadedHotkeys.find(
(loadedHotkey) => loadedHotkey.action === defaultHotkey.action
);
const hotkeyWithoutCombination: HotkeySetting = {
const hotkeyWithoutCombination: HotkeySettingType = {
action: defaultHotkey.action,
combination: COMBINATION_IS_NONE,
};
Expand All @@ -246,7 +246,7 @@ export abstract class BaseConfigManager {
(hotkey) => hotkey.combination === newHotkey.combination
);
if (combinationExists) {
const emptyHotkey: HotkeySetting = {
const emptyHotkey: HotkeySettingType = {
action: newHotkey.action,
combination: "",
};
Expand Down
Loading

0 comments on commit 3152e37

Please sign in to comment.