Backup, component and datasource API typing.

This commit is contained in:
mike12345567 2024-11-29 17:25:08 +00:00
parent d83bd47bd7
commit 1094b88042
7 changed files with 52 additions and 13 deletions

View File

@ -1,14 +1,16 @@
import sdk from "../../sdk"
import { events, context, db } from "@budibase/backend-core"
import { DocumentType } from "../../db/utils"
import { App, Ctx } from "@budibase/types"
import {
App,
Ctx,
ExportAppDumpRequest,
ExportAppDumpResponse,
} from "@budibase/types"
interface ExportAppDumpRequest {
excludeRows: boolean
encryptPassword?: string
}
export async function exportAppDump(ctx: Ctx<ExportAppDumpRequest>) {
export async function exportAppDump(
ctx: Ctx<ExportAppDumpRequest, ExportAppDumpResponse>
) {
const { appId } = ctx.query as any
const { excludeRows, encryptPassword } = ctx.request.body

View File

@ -1,9 +1,16 @@
import { DocumentType } from "../../db/utils"
import { App, Plugin, UserCtx } from "@budibase/types"
import {
App,
FetchComponentDefinitionResponse,
Plugin,
UserCtx,
} from "@budibase/types"
import { db as dbCore, context, tenancy } from "@budibase/backend-core"
import { getComponentLibraryManifest } from "../../utilities/fileSystem"
export async function fetchAppComponentDefinitions(ctx: UserCtx) {
export async function fetchAppComponentDefinitions(
ctx: UserCtx<void, FetchComponentDefinitionResponse>
) {
try {
const db = context.getAppDB()
const app = await db.get<App>(DocumentType.APP_METADATA)

View File

@ -23,13 +23,17 @@ import {
Table,
RowValue,
DynamicVariable,
FetchDatasourcesResponse,
FindDatasourcesResponse,
DestroyDatasourceResponse,
FetchExternalSchemaResponse,
} from "@budibase/types"
import sdk from "../../sdk"
import { builderSocket } from "../../websockets"
import { isEqual } from "lodash"
import { processTable } from "../../sdk/app/tables/getters"
export async function fetch(ctx: UserCtx) {
export async function fetch(ctx: UserCtx<void, FetchDatasourcesResponse>) {
ctx.body = await sdk.datasources.fetch()
}
@ -260,7 +264,7 @@ async function destroyInternalTablesBySourceId(datasourceId: string) {
}
}
export async function destroy(ctx: UserCtx) {
export async function destroy(ctx: UserCtx<void, DestroyDatasourceResponse>) {
const db = context.getAppDB()
const datasourceId = ctx.params.datasourceId
@ -291,12 +295,14 @@ export async function destroy(ctx: UserCtx) {
builderSocket?.emitDatasourceDeletion(ctx, datasourceId)
}
export async function find(ctx: UserCtx) {
export async function find(ctx: UserCtx<void, FindDatasourcesResponse>) {
const datasource = await sdk.datasources.get(ctx.params.datasourceId)
ctx.body = await sdk.datasources.removeSecretSingle(datasource)
}
export async function getExternalSchema(ctx: UserCtx) {
export async function getExternalSchema(
ctx: UserCtx<void, FetchExternalSchemaResponse>
) {
const datasource = await sdk.datasources.get(ctx.params.datasourceId)
const enrichedDatasource = await sdk.datasources.getAndMergeDatasource(
datasource

View File

@ -0,0 +1,4 @@
export type FetchComponentDefinitionResponse = Record<
string,
Record<string, any>
>

View File

@ -42,3 +42,14 @@ export interface BuildSchemaFromSourceResponse {
datasource: Datasource
errors: Record<string, string>
}
export type FetchDatasourcesResponse = Datasource[]
export type FindDatasourcesResponse = Datasource
export interface DestroyDatasourceResponse {
message: string
}
export interface FetchExternalSchemaResponse {
schema: string
}

View File

@ -9,3 +9,4 @@ export * from "./attachment"
export * from "./user"
export * from "./rowAction"
export * from "./automation"
export * from "./component"

View File

@ -1,5 +1,6 @@
import type { PlanType } from "../../sdk"
import type { Layout, App, Screen } from "../../documents"
import { ReadStream } from "fs"
export interface SyncAppResponse {
message: string
@ -70,3 +71,10 @@ export interface ImportToUpdateAppResponse {
export interface SetRevertableAppVersionRequest {
revertableVersion: string
}
export interface ExportAppDumpRequest {
excludeRows: boolean
encryptPassword?: string
}
export type ExportAppDumpResponse = ReadStream