Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: remove some unused jsonapi code (#9389)
Danny Xub6f61c8902a3
diff --git a/frontend/src/store/modules/database.ts b/frontend/src/store/modules/database.tsdeleted file mode 100644index 6ef1ad9864..0000000000--- a/frontend/src/store/modules/database.ts+++ /dev/null@@ -1,172 +0,0 @@-import { defineStore } from "pinia";-import { markRaw } from "vue";-import {- Database,- DatabaseState,- DataSource,- Instance,- InstanceId,- Project,- ResourceIdentifier,- ResourceObject,- unknown,-} from "@/types";-import { useDataSourceStore } from "./dataSource";-import { useLegacyInstanceStore } from "./instance";-import { useLegacyProjectStore } from "./project";--function convert(- database: ResourceObject,- includedList: ResourceObject[]-): Database {- // We first populate the id for instance, project and dataSourceList.- // And if we also provide the detail info for those objects in the includedList,- // then we convert them to the detailed objects.- const instanceId = (- database.relationships!.instance.data as ResourceIdentifier- ).id;- let instance: Instance = unknown("INSTANCE") as Instance;- instance.id = parseInt(instanceId);-- const projectId = (database.relationships!.project.data as ResourceIdentifier)- .id;- let project: Project = unknown("PROJECT") as Project;- project.id = parseInt(projectId);-- const dataSourceIdList = database.relationships!.dataSource- .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 instanceStore = useLegacyInstanceStore();- const projectStore = useLegacyProjectStore();- for (const item of includedList || []) {- if (item.type == "instance" && item.id == instanceId) {- instance = instanceStore.convert(item, includedList);- }- if (item.type == "project" && item.id == projectId) {- project = projectStore.convert(item, includedList);- }- }-- const labels: { key: string; value: string }[] = [];- try {- const array = JSON.parse(database.attributes.labels as any);- if (Array.isArray(array)) {- array.forEach((item) => {- if (- item &&- typeof item["key"] === "string" &&- typeof item["value"] === "string"- ) {- labels.push(item);- }- });- }- } catch {- // nothing to catch- }-- // Only able to assign an empty data source list / anomaly list, otherwise would cause circular dependency.- // This should be fine as e.g. we shouldn't access data source via dataSource.database.dataSourceList- const databaseWPartial = {- ...(database.attributes as Omit<- Database,- "id" | "instance" | "project" | "dataSourceList" | "labels"- >),- id: parseInt(database.id),- instance,- project,- labels,- dataSourceList: [],- };-- for (const item of includedList || []) {- if (- item.type == "data-source" &&- item.attributes.databaseId == database.id- ) {- const i = dataSourceList.findIndex(- (dataSource: DataSource) => parseInt(item.id) == dataSource.id- );- if (i != -1) {- dataSourceList[i] = useDataSourceStore().convert(item);- dataSourceList[i].instanceId = instance.id;- dataSourceList[i].databaseId = databaseWPartial.id;- }- }- }-- return markRaw({- ...(databaseWPartial as Omit<Database, "dataSourceList">),- dataSourceList,- });-}--export const useLegacyDatabaseStore = defineStore("legacy_database", {- state: (): DatabaseState => ({- databaseListByInstanceId: new Map(),- databaseListByProjectId: new Map(),- }),- actions: {- convert(- database: ResourceObject,- includedList: ResourceObject[]- ): Database {- return convert(database, includedList);- },- upsertDatabaseList({- databaseList,- instanceId,- }: {- databaseList: Database[];- instanceId?: InstanceId;- }) {- if (instanceId) {- this.databaseListByInstanceId.set(String(instanceId), databaseList);- } else {- for (const database of databaseList) {- const listByInstance = this.databaseListByInstanceId.get(- String(database.instance.id)- );- if (listByInstance) {- const i = listByInstance.findIndex(- (item: Database) => item.id == database.id- );- if (i != -1) {- listByInstance[i] = database;- } else {- listByInstance.push(database);- }- } else {- this.databaseListByInstanceId.set(String(database.instance.id), [- database,- ]);- }-- const listByProject = this.databaseListByProjectId.get(- String(database.project.id)- );- if (listByProject) {- const i = listByProject.findIndex(- (item: Database) => item.id == database.id- );- if (i != -1) {- listByProject[i] = database;- } else {- listByProject.push(database);- }- } else {- this.databaseListByProjectId.set(String(database.project.id), [- database,- ]);- }- }- }- },- },-});diff --git a/frontend/src/store/modules/index.ts b/frontend/src/store/modules/index.tsindex c282774fe4..4d5a91dc77 100644--- a/frontend/src/store/modules/index.ts+++ b/frontend/src/store/modules/index.ts@@ -1,22 +1,18 @@export * from "./auth";export * from "./command";-export * from "./database";export * from "./dataSource";export * from "./environment";export * from "./help";export * from "./issue";export * from "./instance";export * from "./notification";-export * from "./pipeline";export * from "./slowQueryPolicy";export * from "./principal";export * from "./project";export * from "./router";-export * from "./stage";export * from "./sqlEditor";export * from "./sqlEditorTree";export * from "./tab";-export * from "./task";export * from "./uistate";export * from "./sqlReview";export * from "./onboardingState";diff --git a/frontend/src/store/modules/pipeline.ts b/frontend/src/store/modules/pipeline.tsdeleted file mode 100644index 2c563e8734..0000000000--- a/frontend/src/store/modules/pipeline.ts+++ /dev/null@@ -1,83 +0,0 @@-import { defineStore } from "pinia";-import {- ResourceIdentifier,- ResourceObject,- Pipeline,- PipelineState,- Stage,- TaskId,- Task,- Attributes,- unknown,-} from "@/types";-import { useStageStore } from "./stage";--function convert(- pipeline: ResourceObject,- includedList: ResourceObject[]-): Pipeline {- const stageList: Stage[] = [];- const stageIdList = pipeline.relationships!.stage- .data as ResourceIdentifier[];- const stageStore = useStageStore();- // Needs to iterate through stageIdList to maintain the order- for (const idItem of stageIdList) {- for (const item of includedList || []) {- if (item.type == "stage") {- if (idItem.id == item.id) {- const stage: Stage = stageStore.convertPartial(item, includedList);- stageList.push(stage);- }- }- }- }-- const result: Pipeline = {- ...(pipeline.attributes as Omit<Pipeline, "id" | "stageList">),- id: parseInt(pipeline.id),- stageList,- };-- // Now we have a complete issue, we assign it back to stage and task- for (const stage of result.stageList) {- stage.pipeline = result;- for (const task of stage.taskList) {- task.pipeline = result;- task.stage = stage;- }- }-- // Then we compose tasks' blockedBy since we have converted all tasks in this pipeline- const taskMapById = new Map<TaskId, Task>();- result.stageList.forEach((stage) =>- stage.taskList.forEach((task) => {- taskMapById.set(task.id, task);- })- );- result.stageList.forEach((stage) =>- stage.taskList.forEach((task) => {- // attributes.blockedBy is string[] since jsonapi's limitation- const blockedByTaskIdList = (task as Attributes).blockedBy as string[];- const blockedBy = (blockedByTaskIdList || []).map((blockedById) => {- return (- taskMapById.get(parseInt(blockedById, 10)) ||- (unknown("TASK") as Task)- );- });- task.blockedBy = blockedBy;- })- );-- return result;-}-export const usePipelineStore = defineStore("pipeline", {- state: (): PipelineState => ({}),- actions: {- convert(- pipeline: ResourceObject,- includedList: ResourceObject[]- ): Pipeline {- return convert(pipeline, includedList);- },- },-});diff --git a/frontend/src/store/modules/stage.ts b/frontend/src/store/modules/stage.tsdeleted file mode 100644index d75ccc5249..0000000000--- a/frontend/src/store/modules/stage.ts+++ /dev/null@@ -1,89 +0,0 @@-import { defineStore } from "pinia";-import {- ResourceIdentifier,- ResourceObject,- Stage,- StageState,- Task,- unknown,- PipelineId,- Pipeline,- Environment,-} from "@/types";-import { useLegacyEnvironmentStore } from "./environment";-import { useTaskStore } from "./task";--function convertPartial(- stage: ResourceObject,- includedList: ResourceObject[]-): Omit<Stage, "pipeline"> {- let environment = unknown("ENVIRONMENT") as Environment;- if (stage.relationships?.environment.data) {- const environmentId = (- stage.relationships.environment.data as ResourceIdentifier- ).id;- environment.id = parseInt(environmentId, 10);- }-- const taskList: Task[] = [];- const taskIdList = stage.relationships!.task.data as ResourceIdentifier[];- const taskStore = useTaskStore();- // Needs to iterate through taskIdList to maintain the order- for (const idItem of taskIdList) {- for (const item of includedList || []) {- if (item.type == "task") {- if (idItem.id == item.id) {- const task = taskStore.convertPartial(item, includedList);- taskList.push(task);- }- }- }- }-- const legacyEnvironmentStore = useLegacyEnvironmentStore();- for (const item of includedList || []) {- if (- item.type == "environment" &&- (stage.relationships!.environment.data as ResourceIdentifier).id ==- item.id- ) {- environment = legacyEnvironmentStore.convert(item, includedList);- }- }-- const result: Omit<Stage, "pipeline"> = {- ...(stage.attributes as Omit<Stage, "id" | "database" | "taskList">),- id: parseInt(stage.id),- environment,- taskList,- };-- return result;-}--export const useStageStore = defineStore("stage", {- state: (): StageState => ({}),- actions: {- convertPartial(- stage: ResourceObject,- includedList: ResourceObject[]- ): Stage {- // It's only called when pipeline tries to convert itself, so we don't have a issue yet.- const pipelineId = stage.attributes.pipelineId as PipelineId;- const pipeline: Pipeline = unknown("PIPELINE") as Pipeline;- pipeline.id = pipelineId;-- const result: Stage = {- ...convertPartial(stage, includedList),- pipeline,- };-- for (const task of result.taskList) {- task.stage = result;- task.pipeline = pipeline;- }-- return result;- },- },-});diff --git a/frontend/src/store/modules/task.ts b/frontend/src/store/modules/task.tsdeleted file mode 100644index aafb400eb5..0000000000--- a/frontend/src/store/modules/task.ts+++ /dev/null@@ -1,221 +0,0 @@-import { defineStore } from "pinia";-import {- empty,- Instance,- Pipeline,- PipelineId,- ResourceIdentifier,- ResourceObject,- Stage,- StageId,- Task,- TaskCheckRun,- TaskProgress,- TaskRun,- TaskState,- unknown,-} from "@/types";-import { useLegacyDatabaseStore } from "./database";-import { useLegacyInstanceStore } from "./instance";-import { getPrincipalFromIncludedList } from "./principal";--function convertTaskRun(- taskRun: ResourceObject,- includedList: ResourceObject[]-): TaskRun {- const result = taskRun.attributes.result- ? JSON.parse((taskRun.attributes.result as string) || "{}")- : {};- const payload = taskRun.attributes.payload- ? JSON.parse((taskRun.attributes.payload as string) || "{}")- : {};-- return {- ...(taskRun.attributes as Omit<- TaskRun,- "id" | "result" | "payload" | "creator" | "updater"- >),- id: parseInt(taskRun.id),- creator: getPrincipalFromIncludedList(- taskRun.relationships!.creator.data,- includedList- ),- updater: getPrincipalFromIncludedList(- taskRun.relationships!.updater.data,- includedList- ),- result,- payload,- };-}--function convertTaskCheckRun(- taskCheckRun: ResourceObject,- includedList: ResourceObject[]-): TaskCheckRun {- const result = taskCheckRun.attributes.result- ? JSON.parse((taskCheckRun.attributes.result as string) || "{}")- : {};-- const payload = taskCheckRun.attributes.payload- ? JSON.parse((taskCheckRun.attributes.payload as string) || "{}")- : {};-- return {- ...(taskCheckRun.attributes as Omit<- TaskCheckRun,- "id" | "result" | "payload" | "creator" | "updater"- >),- id: parseInt(taskCheckRun.id),- creator: getPrincipalFromIncludedList(- taskCheckRun.relationships!.creator.data,- includedList- ),- updater: getPrincipalFromIncludedList(- taskCheckRun.relationships!.updater.data,- includedList- ),- result,- payload,- };-}--function convertTaskProgress(attributes: any): TaskProgress {- if (!attributes) return unknown("TASK_PROGRESS");-- const progress: TaskProgress = { ...attributes };- if (typeof attributes.comment === "string") {- try {- progress.payload = JSON.parse(attributes.comment);- } catch {- progress.payload = undefined;- }- } else {- progress.payload = undefined;- }-- return progress;-}--function convertPartial(- task: ResourceObject,- includedList: ResourceObject[]-): Omit<Task, "pipeline" | "stage"> {- const payload = task.attributes.payload- ? JSON.parse((task.attributes.payload as string) || "{}")- : {};-- const taskRunList: TaskRun[] = [];- const taskRunIdList = (task.relationships?.taskRun?.data ??- []) as ResourceIdentifier[];- // Needs to iterate through taskIdList to maintain the order- for (const idItem of taskRunIdList) {- for (const item of includedList || []) {- if (item.type == "taskRun") {- if (idItem.id == item.id) {- const taskRun: TaskRun = convertTaskRun(item, includedList);- taskRunList.push(taskRun);- }- }- }- }-- const taskCheckRunList: TaskCheckRun[] = [];- const taskCheckRunIdList = (task.relationships?.taskCheckRun?.data ??- []) as ResourceIdentifier[];- // Needs to iterate through taskIdList to maintain the order- for (const idItem of taskCheckRunIdList) {- for (const item of includedList || []) {- if (item.type == "taskCheckRun") {- if (idItem.id == item.id) {- const taskCheckRun: TaskCheckRun = convertTaskCheckRun(- item,- includedList- );- taskCheckRunList.push(taskCheckRun);- }- }- }- }-- let instance: Instance = empty("INSTANCE") as Instance;- if (task.relationships?.instance.data) {- const instanceId = (task.relationships.instance.data as ResourceIdentifier)- .id;- instance.id = parseInt(instanceId, 10);- }-- let database = undefined;- const databaseStore = useLegacyDatabaseStore();- const instanceStore = useLegacyInstanceStore();- for (const item of includedList || []) {- if (- item.type == "instance" &&- (task.relationships!.instance.data as ResourceIdentifier).id == item.id- ) {- instance = instanceStore.convert(item, includedList);- }- if (- item.type == "database" &&- // Tasks such as creating database may not have database.- (task.relationships!.database.data as ResourceIdentifier)?.id == item.id- ) {- database = databaseStore.convert(item, includedList);- }- }- const progress = convertTaskProgress(task.attributes.progress);-- return {- ...(task.attributes as Omit<- Task,- | "id"- | "creator"- | "updater"- | "payload"- | "instance"- | "database"- | "taskRunList"- | "taskCheckRunList"- | "pipeline"- | "stage"- | "progress"- >),- id: parseInt(task.id),- creator: getPrincipalFromIncludedList(- task.relationships!.creator.data,- includedList- ),- updater: getPrincipalFromIncludedList(- task.relationships!.updater.data,- includedList- ),- payload,- instance,- database,- progress,- taskRunList,- taskCheckRunList,- };-}--export const useTaskStore = defineStore("task", {- state: (): TaskState => ({}),- actions: {- convertPartial(task: ResourceObject, includedList: ResourceObject[]) {- // It's only called when pipeline/stage tries to convert itself, so we don't have a issue yet.- const pipelineId = task.attributes.pipelineId as PipelineId;- const pipeline: Pipeline = unknown("PIPELINE") as Pipeline;- pipeline.id = pipelineId;-- const stageId = task.attributes.stageId as StageId;- const stage: Stage = unknown("STAGE") as Stage;- stage.id = stageId;-- return {- ...convertPartial(task, includedList),- pipeline,- stage,- } as Task;- },- },-});diff --git a/frontend/src/store/modules/utils.ts b/frontend/src/store/modules/utils.tsindex 309ceedcce..b96aa6e5cb 100644--- a/frontend/src/store/modules/utils.ts+++ b/frontend/src/store/modules/utils.ts@@ -1,50 +1,8 @@import { ClientError } from "nice-grpc-web";import { t } from "@/plugins/i18n";-import {- isPagedResponse,- PagedResponse,- ResourceIdentifier,- ResourceObject,- ResponseWithData,-} from "@/types";import { extractGrpcErrorMessage } from "@/utils/grpcweb";import { pushNotification } from "./notification";-type ConvertEntityFn<T> = (- data: ResourceObject,- includedList: ResourceObject[]-) => T;--type ConvertEntityFromIncludedListFn<T> = (- date:- | ResourceIdentifier<ResourceObject>- | ResourceIdentifier<ResourceObject>[]- | undefined,- includedList: ResourceObject[]-) => T;--// convert entity list from response data-// works for normal array response data and paged response data-export function convertEntityList<T, K extends string>(- responseData: ResponseWithData | PagedResponse<K>,- key: K,- convert: ConvertEntityFn<T>,- convertFromIncludedList: ConvertEntityFromIncludedListFn<T>-) {- if (isPagedResponse(responseData, key)) {- const resourceIdentifierList =- responseData.data.relationships?.[key].data ?? [];- return resourceIdentifierList.map((item) => {- return convertFromIncludedList(item, responseData.included ?? []);- });- }-- const resourceList = responseData.data as ResourceObject[];- return resourceList.map((obj: ResourceObject) => {- return convert(obj, responseData.included ?? []);- });-}-export const useGracefulRequest = async <T>(fn: () => Promise<T>): Promise<T> => {diff --git a/frontend/src/types/jsonapi/index.ts b/frontend/src/types/jsonapi/index.tsindex daa08ea74c..3f98332ede 100644--- a/frontend/src/types/jsonapi/index.ts+++ b/frontend/src/types/jsonapi/index.ts@@ -1,6 +1,2 @@// Based on https://github.com/rmarganti/json-api-export * from "./request";export * from "./resourceObject";-export * from "./response";-export * from "./shared";-export * from "./pagedResponse";diff --git a/frontend/src/types/jsonapi/pagedResponse.ts b/frontend/src/types/jsonapi/pagedResponse.tsdeleted file mode 100644index 5d01c6bd2a..0000000000--- a/frontend/src/types/jsonapi/pagedResponse.ts+++ /dev/null@@ -1,52 +0,0 @@-import { ResourceIdentifier, ResourceObject } from "./resourceObject";-import { ResponseWithData } from "./response";--/**- * example- {- "data": {- "attributes": { "nextToken": "MTAy" },- "relationships": {- "issues": {- "data": [- { "type": "issue", "id": "109" },- { "type": "issue", "id": "108" },- ...- ]- }- }- },- "included": [- ...- ]- }- */-export type PagedResponse<K extends string> = {- data: {- attributes: {- nextToken: string;- };- relationships?: {- [key in K]: {- data: ResourceIdentifier[];- };- };- };- included?: ResourceObject[];-};--export function isPagedResponse<K extends string>(- responseData: ResponseWithData | PagedResponse<K>,- key: K-): responseData is PagedResponse<K> {- const { data } = responseData;- if (Array.isArray(data)) return false;- if (typeof data === "object") {- return (- typeof data.attributes?.nextToken === "string" &&- Array.isArray(data.relationships?.[key]?.data)- );- }-- return false;-}diff --git a/frontend/src/types/jsonapi/request.ts b/frontend/src/types/jsonapi/request.tsdeleted file mode 100644index 19d4b438fc..0000000000--- a/frontend/src/types/jsonapi/request.ts+++ /dev/null@@ -1,17 +0,0 @@-import { NewResourceObject, ResourceObject } from "./resourceObject";-import { Links, Meta } from "./shared";--/**- * A Request to be sent to a JSON API-compliant server.- */-export interface Request<- D extends NewResourceObject | NewResourceObject[] =- | NewResourceObject- | NewResourceObject[]-> {- data: D;- included?: ResourceObject[];- links?: Links;- errors?: [Error];- meta?: Meta;-}diff --git a/frontend/src/types/jsonapi/resourceObject.ts b/frontend/src/types/jsonapi/resourceObject.tsindex ac583709f8..23cee48962 100644--- a/frontend/src/types/jsonapi/resourceObject.ts+++ b/frontend/src/types/jsonapi/resourceObject.ts@@ -1,5 +1,3 @@-import { Links, Meta } from "./shared";-/*** A representation of a single resource.*/@@ -9,8 +7,6 @@ export interface ResourceObject {// [NOTE] This diverges from the spec a bit to make attributes required to avoid "possibly undefined ts warning"attributes: Attributes;relationships?: Relationships;- links?: Links;- meta?: Meta;}/**@@ -27,21 +23,7 @@ export type ResourceObjectOrObjects = ResourceObject | ResourceObjects;* A ResourceIdentifier identifies and individual resource.*/export type ResourceIdentifier<T extends ResourceObject = ResourceObject> =- Pick<T, "type" | "id" | "meta">;--/**- * A representation of a new Resource Object that- * originates at the client and is yet to be created- * on the server. The main difference between a regular- * Resource Object is that this may not have an `id` yet.- */-export interface NewResourceObject {- type: string;- id?: string;- attributes?: Attributes;- relationships?: Relationships;- links?: Links;-}+ Pick<T, "type" | "id">;/*** Attributes describing a Resource Object@@ -71,6 +53,4 @@ export interface Relationship<: D extends ResourceObject[]? ResourceIdentifier<D[0]>[]: ResourceIdentifier | ResourceIdentifier[];- links?: Links;- meta?: Meta;}diff --git a/frontend/src/types/jsonapi/response.ts b/frontend/src/types/jsonapi/response.tsdeleted file mode 100644index 56e4da1bdd..0000000000--- a/frontend/src/types/jsonapi/response.ts+++ /dev/null@@ -1,71 +0,0 @@-import { ResourceObject, ResourceObjectOrObjects } from "./resourceObject";-import { Links, Meta } from "./shared";--/**- * A Response for sure containing data.- */-export interface ResponseWithData<- D extends ResourceObjectOrObjects = ResourceObjectOrObjects-> {- data: D;- included?: ResourceObject[];- links?: Links;- errors?: Error[];- meta?: Meta;-}--/**- * A Response for sure containing Errors.- */-export interface ResponseWithErrors<- D extends ResourceObjectOrObjects = ResourceObjectOrObjects-> {- data?: D;- included?: ResourceObject[];- links?: Links;- errors: Error[];- meta?: Meta;-}--/**- * A Response for sure containing top-level Meta data.- */-export interface ResponseWithMetaData<- D extends ResourceObjectOrObjects = ResourceObjectOrObjects-> {- data?: D;- included?: ResourceObject[];- links?: Links;- errors?: Error[];- meta: Meta;-}--/**- * A Response from a JSON API-compliant server.- */-export interface Response<- D extends ResourceObjectOrObjects = ResourceObjectOrObjects-> {- data?: D;- included?: ResourceObject[];- links?: Links;- errors?: Error[];- meta?: Meta;-}--/**- * An Error.- */-export interface Error {- id?: string;- links?: Links;- status?: string;- code?: string;- title?: string;- detail?: string;- source?: {- pointer?: string;- parameter?: string;- };- meta?: Meta;-}diff --git a/frontend/src/types/jsonapi/shared.ts b/frontend/src/types/jsonapi/shared.tsdeleted file mode 100644index 472a311f3d..0000000000--- a/frontend/src/types/jsonapi/shared.ts+++ /dev/null@@ -1,21 +0,0 @@-/**- * An index of Links.- */-export interface Links {- [index: string]: string | LinkObject;-}--/**- * A Link.- */-export interface LinkObject {- href: string;- meta: Meta;-}--/**- * An index of Meta data.- */-export interface Meta {- [index: string]: any;-}