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