Typex
This commit is contained in:
parent
5fa7972564
commit
30138570d5
|
@ -6,9 +6,8 @@ import {
|
||||||
isRows,
|
isRows,
|
||||||
} from "../../../utilities/schema"
|
} from "../../../utilities/schema"
|
||||||
import { isExternalTable, isSQL } from "../../../integrations/utils"
|
import { isExternalTable, isSQL } from "../../../integrations/utils"
|
||||||
import { getDatasourceParams } from "../../../db/utils"
|
import { events } from "@budibase/backend-core"
|
||||||
import { context, events } from "@budibase/backend-core"
|
import { FetchTablesResponse, Table, UserCtx } from "@budibase/types"
|
||||||
import { Table, UserCtx } from "@budibase/types"
|
|
||||||
import sdk from "../../../sdk"
|
import sdk from "../../../sdk"
|
||||||
import { jsonFromCsvString } from "../../../utilities/csv"
|
import { jsonFromCsvString } from "../../../utilities/csv"
|
||||||
import { builderSocket } from "../../../websockets"
|
import { builderSocket } from "../../../websockets"
|
||||||
|
@ -26,25 +25,19 @@ function pickApi({ tableId, table }: { tableId?: string; table?: Table }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// covers both internal and external
|
// covers both internal and external
|
||||||
export async function fetch(ctx: UserCtx) {
|
export async function fetch(ctx: UserCtx<void, FetchTablesResponse>) {
|
||||||
const db = context.getAppDB()
|
|
||||||
|
|
||||||
const internal = await sdk.tables.getAllInternalTables()
|
const internal = await sdk.tables.getAllInternalTables()
|
||||||
|
|
||||||
const externalTables = await db.allDocs(
|
const externalTables = await sdk.datasources.getExternalDatasources()
|
||||||
getDatasourceParams("plus", {
|
|
||||||
include_docs: true,
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
const external = externalTables.rows.flatMap(tableDoc => {
|
const external = externalTables.flatMap(table => {
|
||||||
let entities = tableDoc.doc.entities
|
let entities = table.entities
|
||||||
if (entities) {
|
if (entities) {
|
||||||
return Object.values(entities).map((entity: any) => ({
|
return Object.values(entities).map<Table>((entity: Table) => ({
|
||||||
...entity,
|
...entity,
|
||||||
type: "external",
|
type: "external",
|
||||||
sourceId: tableDoc.doc._id,
|
sourceId: table._id,
|
||||||
sql: isSQL(tableDoc.doc),
|
sql: isSQL(table),
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
return []
|
return []
|
||||||
|
|
|
@ -243,3 +243,15 @@ export function mergeConfigs(update: Datasource, old: Datasource) {
|
||||||
|
|
||||||
return update
|
return update
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getExternalDatasources(): Promise<Datasource[]> {
|
||||||
|
const db = context.getAppDB()
|
||||||
|
|
||||||
|
const externalDatasources = await db.allDocs<Datasource>(
|
||||||
|
getDatasourceParams("plus", {
|
||||||
|
include_docs: true,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
return externalDatasources.rows.map(r => r.doc)
|
||||||
|
}
|
||||||
|
|
|
@ -2,3 +2,4 @@ export * from "./backup"
|
||||||
export * from "./datasource"
|
export * from "./datasource"
|
||||||
export * from "./view"
|
export * from "./view"
|
||||||
export * from "./rows"
|
export * from "./rows"
|
||||||
|
export * from "./table"
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
import { Table } from "../../../documents"
|
||||||
|
|
||||||
|
export type FetchTablesResponse = Table[]
|
Loading…
Reference in New Issue