Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: no any (#18564)

ecmadao083ea999cfe7
diff --git a/frontend/src/components/ExprEditor/ConditionGroup.vue b/frontend/src/components/ExprEditor/ConditionGroup.vue
index 42f99661b1..8d3254ad6b 100644
--- a/frontend/src/components/ExprEditor/ConditionGroup.vue
+++ b/frontend/src/components/ExprEditor/ConditionGroup.vue
@@ -192,6 +192,13 @@ const OPERATORS: SelectOption[] = [
{ label: operatorLabel("_||_"), value: "_||_" },
];
+const getDefaultValue = (factor: Factor): string | number | Date => {
+ if (isNumberFactor(factor)) return 0;
+ if (isStringFactor(factor)) return "";
+ if (isTimestampFactor(factor)) return new Date();
+ return "";
+};
+
const addCondition = () => {
const factor = factorList.value[0];
const operators = getOperatorListByFactor(
@@ -199,11 +206,16 @@ const addCondition = () => {
factorOperatorOverrideMap.value
);
+ const operator = operators[0];
+ if (!operator) {
+ return;
+ }
+
args.value.push({
type: ExprType.Condition,
- operator: operators[0] ?? "",
+ operator,
args: [factor, getDefaultValue(factor)],
- } as any);
+ } as ConditionExpr);
emit("update");
};
@@ -247,12 +259,4 @@ const removeRawString = (rawString: RawStringExpr) => {
emit("update");
}
};
-
-const getDefaultValue = (factor: Factor): any => {
- if (isNumberFactor(factor)) return 0;
- if (isStringFactor(factor)) return "";
- if (isTimestampFactor(factor)) return new Date();
- // Fall back to empty string.
- return "";
-};
</script>
diff --git a/frontend/src/components/MonacoEditor/MonacoEditor.vue b/frontend/src/components/MonacoEditor/MonacoEditor.vue
index 0be153b539..aa654a2524 100644
--- a/frontend/src/components/MonacoEditor/MonacoEditor.vue
+++ b/frontend/src/components/MonacoEditor/MonacoEditor.vue
@@ -19,29 +19,18 @@
<script setup lang="ts">
import { v4 as uuidv4 } from "uuid";
import { computed, ref, toRef } from "vue";
-import type { Language } from "@/types";
import MonacoTextModelEditor from "./MonacoTextModelEditor.vue";
import { useMonacoTextModel } from "./text-model";
-import type { Selection } from "./types";
+import type { MonacoEditorEmits, MonacoEditorProps } from "./types";
import { extensionNameOfLanguage } from "./utils";
const textModelEditorRef = ref<InstanceType<typeof MonacoTextModelEditor>>();
-const props = withDefaults(
- defineProps<{
- content: string;
- filename?: string;
- language?: Language;
- }>(),
- {
- filename: undefined,
- language: "sql",
- }
-);
-const emit = defineEmits<{
- (event: "update:content", content: string): void;
- (event: "update:selection", selection: Selection | null): void;
-}>();
+const props = withDefaults(defineProps<MonacoEditorProps>(), {
+ filename: undefined,
+ language: "sql",
+});
+const emit = defineEmits<MonacoEditorEmits>();
const content = computed({
get() {
diff --git a/frontend/src/components/MonacoEditor/WrappedMonacoEditor.vue b/frontend/src/components/MonacoEditor/WrappedMonacoEditor.vue
index 972566d248..7a79a834d6 100644
--- a/frontend/src/components/MonacoEditor/WrappedMonacoEditor.vue
+++ b/frontend/src/components/MonacoEditor/WrappedMonacoEditor.vue
@@ -1,6 +1,6 @@
<template>
<Suspense>
- <MonacoEditor ref="monacoEditorRef" v-bind="$attrs as any" />
+ <MonacoEditor ref="monacoEditorRef" v-bind="typedAttrs" />
<template #fallback>
<div ref="spinnerWrapperElRef" :class="classes">
<BBSpin />
@@ -11,8 +11,13 @@
<script setup lang="ts">
import { useParentElement } from "@vueuse/core";
-import { computed, defineAsyncComponent, ref } from "vue";
+import { computed, defineAsyncComponent, ref, useAttrs } from "vue";
import { BBSpin } from "@/bbkit";
+import type { MonacoEditorEmits, MonacoEditorProps } from "./types";
+
+type MonacoEditorAttrs = MonacoEditorProps &
+ MonacoEditorEmits &
+ Record<string, unknown>;
const MonacoEditor = defineAsyncComponent(() => import("./MonacoEditor.vue"));
@@ -20,6 +25,9 @@ const spinnerWrapperElRef = ref<HTMLElement>();
const parentElRef = useParentElement(spinnerWrapperElRef);
const monacoEditorRef = ref<InstanceType<typeof MonacoEditor>>();
+const attrs = useAttrs();
+const typedAttrs = computed(() => attrs as MonacoEditorAttrs);
+
const classes = computed(() => {
const classes: string[] = [
"flex",
diff --git a/frontend/src/components/MonacoEditor/types.ts b/frontend/src/components/MonacoEditor/types.ts
index fb63012a68..a85c10bf72 100644
--- a/frontend/src/components/MonacoEditor/types.ts
+++ b/frontend/src/components/MonacoEditor/types.ts
@@ -1,4 +1,5 @@
import type * as monaco from "monaco-editor";
+import type { Language } from "@/types";
export type MonacoModule = typeof monaco;
@@ -49,3 +50,14 @@ export const SupportedLanguages: monaco.languages.ILanguageExtensionPoint[] = [
];
export type Selection = monaco.Selection;
+
+export type MonacoEditorProps = {
+ content: string;
+ filename?: string;
+ language?: Language;
+};
+
+export type MonacoEditorEmits = {
+ (event: "update:content", content: string): void;
+ (event: "update:selection", selection: Selection | null): void;
+};
diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/unified/UnifiedActionGroup.vue b/frontend/src/components/Plan/components/HeaderSection/Actions/unified/UnifiedActionGroup.vue
index f4b601bc70..19cd5a38c7 100644
--- a/frontend/src/components/Plan/components/HeaderSection/Actions/unified/UnifiedActionGroup.vue
+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/unified/UnifiedActionGroup.vue
@@ -62,6 +62,12 @@ import RolloutReadyLink from "../RolloutReadyLink.vue";
import type { ActionConfig, UnifiedAction } from "./types";
import UnifiedActionButton from "./UnifiedActionButton.vue";
+type DropdownActionOption = DropdownOption & {
+ key: UnifiedAction;
+ label: string;
+ description?: string;
+};
+
const props = defineProps<{
primaryAction?: ActionConfig;
secondaryActions: ActionConfig[];
@@ -177,11 +183,10 @@ const actionDisplayName = (action: UnifiedAction): string => {
}
};
-const dropdownOptions = computed(() => {
+const dropdownOptions = computed((): DropdownActionOption[] => {
return props.secondaryActions.map((config) => ({
key: config.action,
label: actionDisplayName(config.action),
- action: config.action,
disabled: props.disabled || config.disabled,
description: props.disabled ? props.disabledTooltip : config.description,
}));
@@ -195,7 +200,7 @@ const renderDropdownOption = ({
option: DropdownOption;
}) => {
const actionOption = props.secondaryActions.find(
- (config) => config.action === (option as any).key
+ (config) => config.action === (option as DropdownActionOption).key
);
const disabled = props.disabled || actionOption?.disabled;
const description = props.disabled
@@ -226,7 +231,7 @@ const handleAction = (action: UnifiedAction) => {
const handleDropdownSelect = (key: string) => {
const option = dropdownOptions.value.find((opt) => opt.key === key);
if (option && !option.disabled) {
- handleAction(option.action);
+ handleAction(option.key);
}
};
</script>
diff --git a/frontend/src/components/Plan/logic/poller/poller.ts b/frontend/src/components/Plan/logic/poller/poller.ts
index 75d45f00cf..de637f1751 100644
--- a/frontend/src/components/Plan/logic/poller/poller.ts
+++ b/frontend/src/components/Plan/logic/poller/poller.ts
@@ -91,7 +91,7 @@ export const provideResourcePoller = () => {
},
issue: {
canRefresh: () => !!issue?.value,
- refresh: () => refreshIssue(issue as any),
+ refresh: () => refreshIssue(issue),
canInitialize: () =>
!!(plan.value?.issue && isValidIssueName(plan.value.issue)),
initialize: async () => {
diff --git a/frontend/src/components/Plan/logic/poller/utils.ts b/frontend/src/components/Plan/logic/poller/utils.ts
index ae45198336..c856de2976 100644
--- a/frontend/src/components/Plan/logic/poller/utils.ts
+++ b/frontend/src/components/Plan/logic/poller/utils.ts
@@ -62,7 +62,12 @@ export const refreshRollout = async (
rollout.value = newRollout;
};
-export const refreshIssue = async (issue: Ref<Issue>): Promise<void> => {
+export const refreshIssue = async (
+ issue: Ref<Issue | undefined>
+): Promise<void> => {
+ if (!issue.value) {
+ return;
+ }
const request = create(GetIssueRequestSchema, {
name: issue.value.name,
});
diff --git a/frontend/src/components/SchemaDiagram/Navigator/Tree.vue b/frontend/src/components/SchemaDiagram/Navigator/Tree.vue
index 0ec220f157..d09e6cccb2 100644
--- a/frontend/src/components/SchemaDiagram/Navigator/Tree.vue
+++ b/frontend/src/components/SchemaDiagram/Navigator/Tree.vue
@@ -73,19 +73,19 @@ const treeData = computed(() => {
// dynamic render the highlight keywords
const renderLabel = ({ option }: { option: TreeOption }) => {
- const node = option as any as TreeNode;
+ const node = option as TreeNode;
return h(Label, { node, keyword: props.keyword });
};
// Render icons before nodes.
const renderPrefix = ({ option }: { option: TreeOption }) => {
- const node = option as any as TreeNode;
+ const node = option as TreeNode;
return h(Prefix, { node });
};
// Render icons after nodes.
const renderSuffix = ({ option }: { option: TreeOption }) => {
- const node = option as any as TreeNode;
+ const node = option as TreeNode;
return h(Suffix, { node });
};
diff --git a/frontend/src/components/SchemaEditorLite/Aside/context-menu.ts b/frontend/src/components/SchemaEditorLite/Aside/context-menu.ts
index ba7281d180..e645d4f3f8 100644
--- a/frontend/src/components/SchemaEditorLite/Aside/context-menu.ts
+++ b/frontend/src/components/SchemaEditorLite/Aside/context-menu.ts
@@ -231,7 +231,11 @@ export const useContextMenu = (): ContextMenuContext => {
const handleSelect = async (key: string) => {
const node = menu.node;
if (!node) return;
- events.emit(key as any, node as any);
+ const emit = events.emit.bind(events) as (
+ event: string,
+ data: TreeNode
+ ) => Promise<void>;
+ emit(key, node);
menu.show = false;
};
diff --git a/frontend/src/components/SensitiveData/ClassificationView.vue b/frontend/src/components/SensitiveData/ClassificationView.vue
index 8f0747111f..dda7b310ba 100644
--- a/frontend/src/components/SensitiveData/ClassificationView.vue
+++ b/frontend/src/components/SensitiveData/ClassificationView.vue
@@ -228,11 +228,14 @@ const onUpload = () => {
};
const onFileChange = () => {
- const files: File[] = (uploader.value as any).files;
- if (files.length !== 1) {
+ const files = uploader.value?.files;
+ if (!files || files.length !== 1) {
+ return;
+ }
+ const file = files.item(0);
+ if (!file) {
return;
}
- const file = files[0];
if (file.size > maxFileSizeInMiB * 1024 * 1024) {
pushNotification({
module: "bytebase",
diff --git a/frontend/src/components/SensitiveData/components/ClassificationTree.vue b/frontend/src/components/SensitiveData/components/ClassificationTree.vue
index d55c266bb2..7eef4d92c6 100644
--- a/frontend/src/components/SensitiveData/components/ClassificationTree.vue
+++ b/frontend/src/components/SensitiveData/components/ClassificationTree.vue
@@ -145,7 +145,7 @@ const getTreeNodeList = (classificationMap: ClassificationMap): TreeNode[] => {
};
const renderSuffix = ({ option }: { option: TreeOption }) => {
- const node = option as any as TreeNode;
+ const node = option as TreeNode;
if (!node.levelId) {
return null;
}
@@ -158,7 +158,7 @@ const renderSuffix = ({ option }: { option: TreeOption }) => {
};
const renderLabel = ({ option }: { option: TreeOption }) => {
- const node = option as any as TreeNode;
+ const node = option as TreeNode;
return h("span", {
innerHTML: getHighlightHTMLByKeyWords(node.label, state.searchText),
});
diff --git a/frontend/src/components/SensitiveData/components/SensitiveColumnTable.vue b/frontend/src/components/SensitiveData/components/SensitiveColumnTable.vue
index 79b1f4823c..25c0dc3e1f 100644
--- a/frontend/src/components/SensitiveData/components/SensitiveColumnTable.vue
+++ b/frontend/src/components/SensitiveData/components/SensitiveColumnTable.vue
@@ -19,7 +19,10 @@ import { useI18n } from "vue-i18n";
import { RouterLink, useRouter } from "vue-router";
import ClassificationCell from "@/components/ColumnDataTable/ClassificationCell.vue";
import SemanticTypeCell from "@/components/ColumnDataTable/SemanticTypeCell.vue";
-import type { MaskData } from "@/components/SensitiveData/types";
+import type {
+ MaskData,
+ MaskDataTarget,
+} from "@/components/SensitiveData/types";
import { MiniActionButton } from "@/components/v2";
import {
pushNotification,
@@ -28,6 +31,11 @@ import {
useSettingV1Store,
} from "@/store";
import type { ComposedDatabase } from "@/types";
+import type {
+ ColumnCatalog,
+ ObjectSchema,
+ TableCatalog,
+} from "@/types/proto-es/v1/database_catalog_service_pb";
import { DataClassificationSetting_DataClassificationConfigSchema } from "@/types/proto-es/v1/setting_service_pb";
import { autoDatabaseRoute } from "@/utils";
@@ -221,9 +229,23 @@ const dataTableColumns = computed(() => {
return columns;
});
+const hasSemanticType = (
+ target: MaskDataTarget
+): target is ColumnCatalog | ObjectSchema => {
+ return "semanticType" in target;
+};
+
+const hasClassificationType = (
+ target: MaskDataTarget
+): target is ColumnCatalog | TableCatalog => {
+ return "classification" in target;
+};
+
const onSemanticTypeApply = async (item: MaskData, semanticType: string) => {
- // TODO(ed): dirty but works.
- (item.target as any).semanticType = semanticType;
+ if (!hasSemanticType(item.target)) {
+ return;
+ }
+ item.target.semanticType = semanticType;
await dbCatalogStore.updateDatabaseCatalog(databaseCatalog.value);
pushNotification({
@@ -237,7 +259,10 @@ const onClassificationIdApply = async (
item: MaskData,
classification: string
) => {
- (item.target as any).classification = classification;
+ if (!hasClassificationType(item.target)) {
+ return;
+ }
+ item.target.classification = classification;
await dbCatalogStore.updateDatabaseCatalog(databaseCatalog.value);
pushNotification({
module: "bytebase",
@@ -247,8 +272,12 @@ const onClassificationIdApply = async (
};
const onMaskingClear = async (item: MaskData) => {
- (item.target as any).classification = "";
- (item.target as any).semanticType = "";
+ if (hasSemanticType(item.target)) {
+ item.target.semanticType = "";
+ }
+ if (hasClassificationType(item.target)) {
+ item.target.classification = "";
+ }
await dbCatalogStore.updateDatabaseCatalog(databaseCatalog.value);
pushNotification({
module: "bytebase",
diff --git a/frontend/src/components/SensitiveData/types.ts b/frontend/src/components/SensitiveData/types.ts
index d27677fe53..51210d1538 100644
--- a/frontend/src/components/SensitiveData/types.ts
+++ b/frontend/src/components/SensitiveData/types.ts
@@ -7,6 +7,8 @@ import type {
import type { Group } from "@/types/proto-es/v1/group_service_pb";
import type { User } from "@/types/proto-es/v1/user_service_pb";
+export type MaskDataTarget = TableCatalog | ColumnCatalog | ObjectSchema;
+
export interface MaskData {
schema: string;
table: string;
@@ -15,7 +17,7 @@ export interface MaskData {
semanticTypeId: string;
disableClassification?: boolean;
classificationId: string;
- target: TableCatalog | ColumnCatalog | ObjectSchema;
+ target: MaskDataTarget;
}
export interface SensitiveColumn {
diff --git a/frontend/src/components/SingleFileSelector.vue b/frontend/src/components/SingleFileSelector.vue
index 3495610f98..be7bfccd56 100644
--- a/frontend/src/components/SingleFileSelector.vue
+++ b/frontend/src/components/SingleFileSelector.vue
@@ -76,11 +76,10 @@ const onUploaderClick = () => {
};
const onFileChange = () => {
- const files: File[] = (uploader.value as any).files;
- selectFile(files);
+ selectFile(uploader.value?.files);
};
-const onFileDrop = (e: any) => {
+const onFileDrop = (e: DragEvent) => {
e.preventDefault();
state.dropAreaActive = false;
@@ -88,17 +87,17 @@ const onFileDrop = (e: any) => {
return;
}
- const files: File[] = e.dataTransfer.files;
+ const files = e.dataTransfer?.files;
selectFile(files);
};
-const selectFile = (files: File[]) => {
- if (!files.length) {
+const selectFile = (files: FileList | null | undefined) => {
+ if (!files || !files.length) {
return;
}
- const file = files[0];
- if (!validFile(file)) {
+ const file = files.item(0);
+ if (!file || !validFile(file)) {
return;
}
emit("on-select", file);
diff --git a/frontend/src/explain-visualizer-main.ts b/frontend/src/explain-visualizer-main.ts
index edbcb912d5..c28f94498b 100644
--- a/frontend/src/explain-visualizer-main.ts
+++ b/frontend/src/explain-visualizer-main.ts
@@ -3,7 +3,7 @@ import { createApp } from "vue";
import ExplainVisualizerApp from "./ExplainVisualizerApp.vue";
// Redefine global using globalThis
-(globalThis as any).global = globalThis;
+(globalThis as typeof globalThis & Record<string, unknown>).global = globalThis;
const app = createApp(ExplainVisualizerApp);
diff --git a/frontend/src/init.ts b/frontend/src/init.ts
index db9d045d4e..ee1521c84a 100644
--- a/frontend/src/init.ts
+++ b/frontend/src/init.ts
@@ -2,4 +2,4 @@
// This is necessary for compatibility with certain dependencies that expect a global object
// Redefine global to use globalThis for compatibility
-(globalThis as any).global = globalThis;
+(globalThis as typeof globalThis & Record<string, unknown>).global = globalThis;
diff --git a/frontend/src/plugins/ai/components/ChatView/Markdown/utils.ts b/frontend/src/plugins/ai/components/ChatView/Markdown/utils.ts
index cf7f610396..a31fa8258e 100644
--- a/frontend/src/plugins/ai/components/ChatView/Markdown/utils.ts
+++ b/frontend/src/plugins/ai/components/ChatView/Markdown/utils.ts
@@ -54,23 +54,26 @@ export type State = {
definitionById: Map<string, Definition>;
};
-type NodeKey = keyof CustomRender;
+type GenericNodeHandler = (node: RootContent, state?: State) => VNode | string;
-type NodeToVNodeKey = keyof typeof mdastToVNode;
+function defaultMdNodeToVNode(
+ node: RootContent,
+ state?: State
+): VNode | string {
+ const { type } = node;
-function defaultMdNodeToVNode(node: RootContent, state?: State) {
- const type = node.type as NodeKey;
+ const customSlot = state?.slots[type as keyof CustomRender] as
+ | GenericNodeHandler
+ | undefined;
- if (state?.slots[type]) {
- return state.slots[type](node as any);
+ if (customSlot) {
+ return customSlot(node, state);
}
- const handler: (typeof mdastToVNode)[NodeToVNodeKey] =
- type in mdastToVNode
- ? mdastToVNode[type as NodeToVNodeKey]
- : mdastToVNode.unknown;
+ const handler = (mdastToVNode[type as keyof typeof mdastToVNode] ??
+ mdastToVNode.unknown) as GenericNodeHandler;
- return handler(node as any, state);
+ return handler(node, state);
}
function rootToVNode(node: Root, state?: State): VNode | string {
@@ -542,19 +545,17 @@ function defaultUnknownHandler(
state?: State
): VNode | string {
if ("children" in node) {
- const properties = ("properties" in node ? node.properties : {}) as Record<
- string,
- any
- >;
+ const properties: Record<string, unknown> =
+ "properties" in node ? (node.properties as Record<string, unknown>) : {};
+
if ("className" in properties && Array.isArray(properties.className)) {
- // hast和vnode的结构不同导致的,JSX上的区别
properties.className = properties.className.join(" ");
}
return h(
"div",
properties,
- node.children.map((node) => defaultMdNodeToVNode(node, state))
+ node.children.map((child) => defaultMdNodeToVNode(child, state))
);
}
@@ -562,7 +563,6 @@ function defaultUnknownHandler(
return node.value;
}
- // empty node……???
return "";
}
diff --git a/frontend/src/plugins/i18n-messages.ts b/frontend/src/plugins/i18n-messages.ts
index c52b8b6c42..19da97bc90 100644
--- a/frontend/src/plugins/i18n-messages.ts
+++ b/frontend/src/plugins/i18n-messages.ts
@@ -1,6 +1,7 @@
import { merge } from "lodash-es";
const localPathPrefix = "../locales/";
+type LocaleModule = { default: Record<string, unknown> };
// import i18n resources
// https://vitejs.dev/guide/features.html#glob-import
@@ -11,7 +12,7 @@ export const mergedLocalMessage = Object.entries(
const name = key.slice(localPathPrefix.length, -5);
const sections = name.split("/");
if (sections.length === 1) {
- map[name] = merge((value as any).default, map[name] || {});
+ map[name] = merge((value as LocaleModule).default, map[name] || {});
} else {
const file = sections.slice(-1)[0];
const sectionsName = sections[0];
@@ -19,7 +20,7 @@ export const mergedLocalMessage = Object.entries(
map[file] = {
...existed,
[sectionsName]: merge(
- (value as any).default,
+ (value as LocaleModule).default,
existed[sectionsName] || {}
),
};
diff --git a/frontend/src/polyfill.ts b/frontend/src/polyfill.ts
index 76c58431f1..c35ffe2ae5 100644
--- a/frontend/src/polyfill.ts
+++ b/frontend/src/polyfill.ts
@@ -1,9 +1,11 @@
(() => {
if (typeof WeakRef === "undefined") {
- class WeakRefPolyfill<T> {
+ class WeakRefPolyfill<T extends WeakKey> {
private targetMap = new Map<WeakRefPolyfill<T>, T | undefined>();
private target: T;
+ readonly [Symbol.toStringTag] = "WeakRef";
+
constructor(target: T) {
if (typeof target !== "object" || target === null) {
throw new TypeError("WeakRef target must be an object.");
@@ -18,6 +20,9 @@
}
}
- (globalThis as any).WeakRef = WeakRefPolyfill;
+ // Use a specific type instead of any
+ (
+ globalThis as typeof globalThis & { WeakRef: typeof WeakRefPolyfill }
+ ).WeakRef = WeakRefPolyfill;
}
})();
diff --git a/frontend/src/store/modules/sqlEditor/legacy/extendedTab.ts b/frontend/src/store/modules/sqlEditor/legacy/extendedTab.ts
index b2da3ccab0..b71c420b26 100644
--- a/frontend/src/store/modules/sqlEditor/legacy/extendedTab.ts
+++ b/frontend/src/store/modules/sqlEditor/legacy/extendedTab.ts
@@ -4,6 +4,10 @@ import PouchDB from "pouchdb";
import PouchDBFind from "pouchdb-find";
import type { SQLEditorTab } from "@/types";
+interface PouchDBError extends Error {
+ status?: number;
+}
+
export const EXTENDED_TAB_FIELDS = [
"statement",
"batchQueryContext",
@@ -54,7 +58,7 @@ export const useExtendedTabStore = defineStore("sqlEditorExtendedTab", () => {
fallback();
}
- if ((err as any)?.status === 404) return;
+ if ((err as PouchDBError)?.status === 404) return;
console.debug("[SQLEditorExtendedTabStore] fetchExtendedTab", err);
}
};
diff --git a/frontend/src/store/modules/sqlEditor/legacy/migration.ts b/frontend/src/store/modules/sqlEditor/legacy/migration.ts
index f04ed8a0c8..3ff26b3e6b 100644
--- a/frontend/src/store/modules/sqlEditor/legacy/migration.ts
+++ b/frontend/src/store/modules/sqlEditor/legacy/migration.ts
@@ -24,6 +24,8 @@ type PersistentTab = Pick<
"id" | "title" | "connection" | "mode" | "worksheet" | "status"
>;
+type LegacyStoredTab = PersistentTab & { statement?: string };
+
export const migrateLegacyCache = async () => {
const me = useCurrentUserV1();
const userUID = computed(() => extractUserId(me.value.name));
@@ -72,7 +74,7 @@ export const migrateLegacyCache = async () => {
// This might happen only once to each user, since the second time when a
// tab is saved, extended fields will be migrated, and won't be saved to
// LocalStorage, so the fallback routine won't be hit.
- const { statement } = stored as any;
+ const { statement } = stored as LegacyStoredTab;
if (statement) {
tab.statement = statement;
}
diff --git a/frontend/src/store/modules/v1/database.ts b/frontend/src/store/modules/v1/database.ts
index ece3e3f3eb..1c8cc13aea 100644
--- a/frontend/src/store/modules/v1/database.ts
+++ b/frontend/src/store/modules/v1/database.ts
@@ -33,7 +33,10 @@ import {
SyncDatabaseRequestSchema,
UpdateDatabaseRequestSchema,
} from "@/types/proto-es/v1/database_service_pb";
-import type { Instance } from "@/types/proto-es/v1/instance_service_pb";
+import {
+ type Instance,
+ InstanceResourceSchema,
+} from "@/types/proto-es/v1/instance_service_pb";
import { extractDatabaseResourceName, isNullOrUndefined } from "@/utils";
import {
instanceNamePrefix,
@@ -230,22 +233,14 @@ export const useDatabaseV1Store = defineStore("database_v1", () => {
if (database.instance !== instance.name) {
continue;
}
- // Conversion boundary: Extract InstanceResource fields from Instance
- database.instanceResource = {
+ database.instanceResource = create(InstanceResourceSchema, {
name: instance.name,
- uid: "",
- state: instance.state,
title: instance.title,
engine: instance.engine,
- externalLink: "",
- maximumConnections: 0,
environment: instance.environment,
- activation: true,
+ activation: instance.activation,
dataSources: [],
- lastSyncTime: undefined,
- syncInterval: undefined,
- options: undefined,
- } as any; // Cross-service boundary conversion
+ });
}
};
const batchSyncDatabases = async (databases: string[]) => {
@@ -294,11 +289,12 @@ export const useDatabaseV1Store = defineStore("database_v1", () => {
return request;
};
const batchGetDatabases = async (names: string[], silent = true) => {
- if (names.length === 0) {
+ const validNames = names.filter(isValidDatabaseName);
+ if (validNames.length === 0) {
return [];
}
const request = create(BatchGetDatabasesRequestSchema, {
- names,
+ names: validNames,
});
const response = await databaseServiceClientConnect.batchGetDatabases(
request,
diff --git a/frontend/src/store/modules/v1/project.ts b/frontend/src/store/modules/v1/project.ts
index 9e3ba24006..844fdff402 100644
--- a/frontend/src/store/modules/v1/project.ts
+++ b/frontend/src/store/modules/v1/project.ts
@@ -187,8 +187,12 @@ export const useProjectV1Store = defineStore("project_v1", () => {
};
const batchGetProjects = async (names: string[], silent = true) => {
+ const validNames = names.filter(isValidProjectName);
+ if (validNames.length === 0) {
+ return [];
+ }
const request = create(BatchGetProjectsRequestSchema, {
- names,
+ names: validNames,
});
const response = await projectServiceClientConnect.batchGetProjects(
request,
diff --git a/frontend/src/utils/TinyTimer.ts b/frontend/src/utils/TinyTimer.ts
index 35b45ad466..37997b46f1 100644
--- a/frontend/src/utils/TinyTimer.ts
+++ b/frontend/src/utils/TinyTimer.ts
@@ -21,8 +21,9 @@ const emptyTimerEntry = (tag: string): TimerEntry => {
};
export class TinyTimer<T extends string = string> {
- private entires: Record<T, TimerEntry> = {} as any;
- private begins: Record<T, number> = {} as any;
+ private entires: Partial<Record<T, TimerEntry>> = {};
+ private begins: Partial<Record<T, number>> = {};
+
title: string;
constructor(title: string = "") {
this.title = title;
diff --git a/frontend/src/utils/v1/advanced-search/common.ts b/frontend/src/utils/v1/advanced-search/common.ts
index 762bdf269d..60ebf6e31a 100644
--- a/frontend/src/utils/v1/advanced-search/common.ts
+++ b/frontend/src/utils/v1/advanced-search/common.ts
@@ -53,7 +53,7 @@ export interface SearchParams {
}
export const isValidSearchScopeId = (id: string): id is SearchScopeId => {
- return AllSearchScopeIdList.includes(id as any);
+ return (AllSearchScopeIdList as readonly string[]).includes(id);
};
export const buildSearchTextBySearchParams = (
diff --git a/frontend/src/utils/web-storage.ts b/frontend/src/utils/web-storage.ts
index 4e0b8c1bc0..ca0d86fbe5 100644
--- a/frontend/src/utils/web-storage.ts
+++ b/frontend/src/utils/web-storage.ts
@@ -167,7 +167,8 @@ export const useDynamicLocalStorage = <
dispatchWriteEvent(oldValue, null);
storage.removeItem(key.value);
} else {
- const serialized = serializer.write(v as any);
+ // v is known to be T at this point since it comes from data.value
+ const serialized = serializer.write(v as T);
if (oldValue !== serialized) {
storage.setItem(key.value, serialized);
dispatchWriteEvent(oldValue, serialized);
@@ -187,10 +188,12 @@ export const useDynamicLocalStorage = <
return rawInit;
} else if (!event && mergeDefaults) {
const value = serializer.read(rawValue);
- if (typeof mergeDefaults === "function")
+ if (typeof mergeDefaults === "function") {
return mergeDefaults(value, rawInit);
- else if (type === "object" && !Array.isArray(value))
- return { ...(rawInit as any), ...value };
+ } else if (type === "object" && !Array.isArray(value)) {
+ // We know T extends object here since type === "object"
+ return { ...(rawInit as Record<string, unknown>), ...value } as T;
+ }
return value;
} else if (typeof rawValue !== "string") {
return rawValue;
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/SchemaPane.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/SchemaPane.vue
index b363a51547..967fe2d0f3 100644
--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/SchemaPane.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/SchemaPane.vue
@@ -252,7 +252,7 @@ const defaultExpandedKeys = () => {
return keys;
};
const nodeProps = ({ option }: { option: TreeOption }) => {
- const node = option as any as TreeNode;
+ const node = option as TreeNode;
return {
onclick(e: MouseEvent) {
if (node.disabled) return;
@@ -318,7 +318,7 @@ const nodeProps = ({ option }: { option: TreeOption }) => {
// dynamic render the highlight keywords
const renderLabel = ({ option }: { option: TreeOption }) => {
- const node = option as any as TreeNode;
+ const node = option as TreeNode;
const keyword = searchPattern.value;
return h(Label, { node, keyword });
};
diff --git a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue
index 78e03801b2..d77bacb0b0 100644
--- a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue
+++ b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue
@@ -662,7 +662,7 @@ const renderLabel = ({ option }: { option: TreeOption }) => {
};
const nodeProps = ({ option }: { option: TreeOption }) => {
- const node = option as any as SQLEditorTreeNode;
+ const node = option as SQLEditorTreeNode;
return {
onClick(e: MouseEvent) {
if (node.disabled) return;