Skip to content

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

chore: deprecate jsonapi part 2 (#9391)

Danny Xu984e9fc715ec
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index 6f3a51e681..3767e95000 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -24,7 +24,6 @@ import {
useSheetV1Store,
useAuthStore,
useActuatorV1Store,
- useLegacyInstanceStore,
useRouterStore,
useDBSchemaV1Store,
useOnboardingStateStore,
@@ -979,7 +978,6 @@ router.beforeEach((to, from, next) => {
const authStore = useAuthStore();
const dbSchemaStore = useDBSchemaV1Store();
- const instanceStore = useLegacyInstanceStore();
const routerStore = useRouterStore();
const projectV1Store = useProjectV1Store();
const projectWebhookV1Store = useProjectWebhookV1Store();
@@ -1373,7 +1371,6 @@ router.beforeEach((to, from, next) => {
}
if (instanceSlug) {
- instanceStore;
useInstanceV1Store()
.getOrFetchInstanceByUID(String(idFromSlug(instanceSlug)))
.then(() => {
diff --git a/frontend/src/store/modules/environment.ts b/frontend/src/store/modules/environment.ts
deleted file mode 100644
index 9dfcf15b39..0000000000
--- a/frontend/src/store/modules/environment.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-import { defineStore } from "pinia";
-import { Environment, ResourceObject } from "@/types";
-
-function convert(
- environment: ResourceObject,
- includedList: ResourceObject[]
-): Environment {
- return {
- ...(environment.attributes as Omit<Environment, "id">),
- id: parseInt(environment.id),
- };
-}
-
-export const useLegacyEnvironmentStore = defineStore("environment", {
- state: () => ({}),
- actions: {
- convert(
- environment: ResourceObject,
- includedList: ResourceObject[]
- ): Environment {
- return convert(environment, includedList);
- },
- },
-});
diff --git a/frontend/src/store/modules/index.ts b/frontend/src/store/modules/index.ts
index 4d5a91dc77..23e27414a5 100644
--- a/frontend/src/store/modules/index.ts
+++ b/frontend/src/store/modules/index.ts
@@ -1,14 +1,11 @@
export * from "./auth";
export * from "./command";
export * from "./dataSource";
-export * from "./environment";
export * from "./help";
export * from "./issue";
-export * from "./instance";
export * from "./notification";
export * from "./slowQueryPolicy";
export * from "./principal";
-export * from "./project";
export * from "./router";
export * from "./sqlEditor";
export * from "./sqlEditorTree";
diff --git a/frontend/src/store/modules/instance.ts b/frontend/src/store/modules/instance.ts
deleted file mode 100644
index c51e8b498e..0000000000
--- a/frontend/src/store/modules/instance.ts
+++ /dev/null
@@ -1,89 +0,0 @@
-import { defineStore } from "pinia";
-import {
- DataSource,
- Environment,
- Instance,
- InstanceState,
- ResourceIdentifier,
- ResourceObject,
- unknown,
-} from "@/types";
-import { useDataSourceStore } from "./dataSource";
-import { useLegacyEnvironmentStore } from "./environment";
-
-function convert(
- instance: ResourceObject,
- includedList: ResourceObject[]
-): Instance {
- const environmentId = (
- instance.relationships!.environment.data as ResourceIdentifier
- ).id;
- let environment: Environment = unknown("ENVIRONMENT") as Environment;
- environment.id = parseInt(environmentId);
-
- const dataSourceIdList = instance.relationships!.dataSourceList
- .data as ResourceIdentifier[];
- const dataSourceList: DataSource[] = [];
- for (const item of dataSourceIdList) {
- const dataSource = unknown("DATA_SOURCE") as DataSource;
- dataSource.id = parseInt(item.id);
- dataSourceList.push(dataSource);
- }
-
- const instancePartial = {
- ...(instance.attributes as Omit<
- Instance,
- "id" | "environment" | "dataSourceList"
- >),
- id: parseInt(instance.id),
- environment,
- dataSourceList: [],
- };
-
- const legacyEnvironmentStore = useLegacyEnvironmentStore();
- const dataSourceStore = useDataSourceStore();
- for (const item of includedList || []) {
- if (
- item.type == "environment" &&
- (instance.relationships!.environment.data as ResourceIdentifier).id ==
- item.id
- ) {
- environment = legacyEnvironmentStore.convert(item, includedList);
- }
-
- if (
- item.type == "dataSource" &&
- item.attributes.instanceId == instancePartial.id
- ) {
- const i = dataSourceList.findIndex(
- (dataSource: DataSource) => parseInt(item.id) == dataSource.id
- );
- if (i != -1) {
- dataSourceList[i] = dataSourceStore.convert(item);
- }
- }
- }
-
- return {
- ...(instancePartial as Omit<Instance, "environment" | "dataSourceList">),
- environment,
- dataSourceList,
- };
-}
-
-export const useLegacyInstanceStore = defineStore("legacy_instance", {
- state: (): InstanceState => ({
- instanceById: new Map(),
- instanceUserListById: new Map(),
- migrationHistoryById: new Map(),
- migrationHistoryListByIdAndDatabaseName: new Map(),
- }),
- actions: {
- convert(
- instance: ResourceObject,
- includedList: ResourceObject[]
- ): Instance {
- return convert(instance, includedList);
- },
- },
-});
diff --git a/frontend/src/store/modules/project.ts b/frontend/src/store/modules/project.ts
deleted file mode 100644
index d95d5d7fdf..0000000000
--- a/frontend/src/store/modules/project.ts
+++ /dev/null
@@ -1,88 +0,0 @@
-import { defineStore } from "pinia";
-import {
- Project,
- ProjectMember,
- ProjectState,
- ResourceIdentifier,
- ResourceObject,
- unknown,
-} from "@/types";
-import { getPrincipalFromIncludedList } from "./principal";
-
-function convert(
- project: ResourceObject,
- includedList: ResourceObject[]
-): Project {
- const attrs = project.attributes as Omit<Project, "id" | "memberList">;
- // Only able to assign an empty member list, otherwise would cause circular dependency.
- // This should be fine as we shouldn't access member via member.project.memberList
- const projectWithoutMemberList: Project = {
- id: parseInt(project.id),
- resourceId: attrs.resourceId,
- rowStatus: attrs.rowStatus,
- name: attrs.name,
- key: attrs.key,
- memberList: [],
- workflowType: attrs.workflowType,
- visibility: attrs.visibility,
- tenantMode: attrs.tenantMode,
- schemaChangeType: attrs.schemaChangeType,
- };
-
- const memberList: ProjectMember[] = [];
- for (const item of includedList || []) {
- if (item.type == "projectMember") {
- const projectMemberIdList = project.relationships!.projectMember
- .data as ResourceIdentifier[];
- for (const idItem of projectMemberIdList) {
- if (idItem.id == item.id) {
- const member = convertMember(item, includedList);
- member.project = projectWithoutMemberList;
- memberList.push(member);
- }
- }
- }
- }
-
- return {
- ...(projectWithoutMemberList as Omit<Project, "memberList">),
- memberList,
- };
-}
-
-// For now, this is exclusively used as part of converting the Project.
-// Upon calling, the project itself is not constructed yet, so we return
-// an unknown project first.
-function convertMember(
- projectMember: ResourceObject,
- includedList: ResourceObject[]
-): ProjectMember {
- const attrs = projectMember.attributes as Omit<ProjectMember, "project">;
-
- return {
- id: projectMember.id,
- role: attrs.role,
- // `project` will be overwritten after the value is correctly composed
- project: unknown("PROJECT") as Project,
- principal: getPrincipalFromIncludedList(
- projectMember.relationships!.principal.data,
- includedList
- ),
- };
-}
-
-export const useLegacyProjectStore = defineStore("project_legacy", {
- state: (): ProjectState => ({
- projectById: new Map(),
- }),
- getters: {
- projectList: (state) => {
- return [...state.projectById.values()];
- },
- },
- actions: {
- convert(instance: ResourceObject, includedList: ResourceObject[]): Project {
- return convert(instance, includedList || []);
- },
- },
-});
diff --git a/frontend/src/types/jsonapi/resourceObject.ts b/frontend/src/types/jsonapi/resourceObject.ts
index 23cee48962..ba908656c1 100644
--- a/frontend/src/types/jsonapi/resourceObject.ts
+++ b/frontend/src/types/jsonapi/resourceObject.ts
@@ -6,7 +6,6 @@ export interface ResourceObject {
id: string;
// [NOTE] This diverges from the spec a bit to make attributes required to avoid "possibly undefined ts warning"
attributes: Attributes;
- relationships?: Relationships;
}
/**
@@ -31,26 +30,3 @@ export type ResourceIdentifier<T extends ResourceObject = ResourceObject> =
export interface Attributes {
[index: string]: string | number | boolean | object | undefined;
}
-
-/**
- * A Resource object's Relationships.
- */
-export interface Relationships {
- [index: string]: Relationship;
-}
-
-/**
- * Describes a single Relationship type between a
- * Resource Object and one or more other Resource Objects.
- */
-export interface Relationship<
- D extends ResourceObject | ResourceObject[] =
- | ResourceObject
- | ResourceObject[]
-> {
- data?: D extends ResourceObject
- ? ResourceIdentifier<D>
- : D extends ResourceObject[]
- ? ResourceIdentifier<D[0]>[]
- : ResourceIdentifier | ResourceIdentifier[];
-}