feat: strict language enum types

This commit is contained in:
DIYgod 2024-06-13 15:50:59 +08:00
parent 810111291c
commit 3fc6ec4531
No known key found for this signature in database
6 changed files with 43 additions and 7 deletions

View File

@ -58,6 +58,7 @@
"electron-store": "8.2.0",
"electron-updater": "^6.1.7",
"framer-motion": "11.2.9",
"franc-min": "6.2.0",
"hast-util-to-jsx-runtime": "2.3.0",
"idb-keyval": "6.2.1",
"immer": "10.1.1",

View File

@ -118,6 +118,9 @@ importers:
framer-motion:
specifier: 11.2.9
version: 11.2.9(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
franc-min:
specifier: 6.2.0
version: 6.2.0
hast-util-to-jsx-runtime:
specifier: 2.3.0
version: 2.3.0
@ -2394,6 +2397,9 @@ packages:
react: ^18.0.0
react-dom: ^18.0.0
collapse-white-space@2.1.0:
resolution: {integrity: sha512-loKTxY1zCOuG4j9f6EPnuyyYkf58RnhhWTvRoZEokgB+WbdXehfjFviyOVYkqzEWz1Q5kRiZdBYS5SwxbQYwzw==}
color-convert@1.9.3:
resolution: {integrity: sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==}
@ -3107,6 +3113,9 @@ packages:
react-dom:
optional: true
franc-min@6.2.0:
resolution: {integrity: sha512-1uDIEUSlUZgvJa2AKYR/dmJC66v/PvGQ9mWfI9nOr/kPpMFyvswK0gPXOwpYJYiYD008PpHLkGfG58SPjQJFxw==}
fs-constants@1.0.0:
resolution: {integrity: sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==}
@ -4027,6 +4036,9 @@ packages:
mz@2.7.0:
resolution: {integrity: sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==}
n-gram@2.0.2:
resolution: {integrity: sha512-S24aGsn+HLBxUGVAUFOwGpKs7LBcG4RudKU//eWzt/mQ97/NMKQxDWHyHx63UNWk/OOdihgmzoETn1tf5nQDzQ==}
nanoid@3.3.7:
resolution: {integrity: sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==}
engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
@ -4949,6 +4961,9 @@ packages:
resolution: {integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==}
engines: {node: '>=8.0'}
trigram-utils@2.0.1:
resolution: {integrity: sha512-nfWIXHEaB+HdyslAfMxSqWKDdmqY9I32jS7GnqpdWQnLH89r6A5sdk3fDVYqGAZ0CrT8ovAFSAo6HRiWcWNIGQ==}
trim-lines@3.0.1:
resolution: {integrity: sha512-kRj8B+YHZCc9kQYdWfJB2/oUl9rA99qbowYYBtr4ui4mZyAQ2JpvVBd/6U2YloATfqBhBTSMhTpgBHtU0Mf3Rg==}
@ -7706,6 +7721,8 @@ snapshots:
- '@types/react'
- '@types/react-dom'
collapse-white-space@2.1.0: {}
color-convert@1.9.3:
dependencies:
color-name: 1.1.3
@ -8682,6 +8699,10 @@ snapshots:
react: 18.3.1
react-dom: 18.3.1(react@18.3.1)
franc-min@6.2.0:
dependencies:
trigram-utils: 2.0.1
fs-constants@1.0.0: {}
fs-extra@10.1.0:
@ -9791,6 +9812,8 @@ snapshots:
object-assign: 4.1.1
thenify-all: 1.6.0
n-gram@2.0.2: {}
nanoid@3.3.7: {}
natural-compare@1.4.0: {}
@ -10751,6 +10774,11 @@ snapshots:
dependencies:
is-number: 7.0.0
trigram-utils@2.0.1:
dependencies:
collapse-white-space: 2.1.0
n-gram: 2.0.2
trim-lines@3.0.1: {}
trough@2.2.0: {}

View File

@ -31,6 +31,7 @@ import {
} from "@renderer/components/ui/table"
import { ViewSelectContent } from "@renderer/components/view-select-content"
import { cn } from "@renderer/lib/utils"
import type { SupportedLanguages } from "@renderer/models"
type Operation =
| "contains"
@ -155,7 +156,10 @@ const FeedOptions = [
},
]
const TransitionOptions = [
const TransitionOptions: {
name: string
value: SupportedLanguages
}[] = [
{
name: "English",
value: "en",

View File

@ -39,7 +39,7 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[];
result: {
translation?: string | undefined;
translation?: "en" | "ja" | "zh-CN" | "zh-TW" | undefined;
summary?: boolean | undefined;
rewriteRules?: {
from: string;
@ -68,7 +68,7 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[];
result: {
translation?: string | undefined;
translation?: "en" | "ja" | "zh-CN" | "zh-TW" | undefined;
summary?: boolean | undefined;
rewriteRules?: {
from: string;
@ -440,7 +440,7 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
createdAt: string;
} | undefined;
settings?: {
translation?: string | undefined;
translation?: "en" | "ja" | "zh-CN" | "zh-TW" | undefined;
summary?: boolean | undefined;
rewriteRules?: {
from: string;
@ -502,7 +502,7 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
};
read: boolean | null;
settings?: {
translation?: string | undefined;
translation?: "en" | "ja" | "zh-CN" | "zh-TW" | undefined;
summary?: boolean | undefined;
rewriteRules?: {
from: string;

View File

@ -73,3 +73,5 @@ export type FeedListModel = {
name: string
}[]
}
export type SupportedLanguages = Parameters<typeof apiClient.ai.translation.$get>[0]["query"]["language"]

View File

@ -1,5 +1,6 @@
import { apiClient } from "@renderer/lib/api-fetch"
import { defineQuery } from "@renderer/lib/defineQuery"
import type { SupportedLanguages } from "@renderer/models"
export const ai = {
translation: ({
@ -8,7 +9,7 @@ export const ai = {
fields,
}: {
id: string
language?: string
language?: SupportedLanguages
fields: string
}) =>
defineQuery(["translation", id, language], async () => {
@ -18,7 +19,7 @@ export const ai = {
const res = await apiClient.ai.translation.$get({
query: {
id,
language: language as "en" | "ja" | "zh-CN" | "zh-TW",
language: language as SupportedLanguages,
fields,
},
})