1
0
Fork 0
mirror of synced 2024-08-05 13:21:26 +12:00

Quick type improvement.

This commit is contained in:
mike12345567 2024-06-24 13:28:13 +01:00
parent 1402716f5c
commit 75cee3c4fd

View file

@ -170,8 +170,7 @@ export class ExternalRequest<T extends Operation> {
id: string | undefined | string[], id: string | undefined | string[],
filters: SearchFilters, filters: SearchFilters,
table: Table table: Table
) { ): SearchFilters {
const tables = this.tableList
// replace any relationship columns initially, table names and relationship column names are acceptable // replace any relationship columns initially, table names and relationship column names are acceptable
const relationshipColumns = sdk.rows.filters.getRelationshipColumns(table) const relationshipColumns = sdk.rows.filters.getRelationshipColumns(table)
filters = sdk.rows.filters.updateFilterKeys( filters = sdk.rows.filters.updateFilterKeys(
@ -214,7 +213,7 @@ export class ExternalRequest<T extends Operation> {
if (!Array.isArray(idCopy)) { if (!Array.isArray(idCopy)) {
idCopy = breakRowIdField(idCopy) idCopy = breakRowIdField(idCopy)
} }
const equal: any = {} const equal: SearchFilters["equal"] = {}
if (primary && idCopy) { if (primary && idCopy) {
for (let field of primary) { for (let field of primary) {
// work through the ID and get the parts // work through the ID and get the parts
@ -274,7 +273,9 @@ export class ExternalRequest<T extends Operation> {
} }
// seeds the object with table and datasource information // seeds the object with table and datasource information
async retrieveMetadata(datasourceId: string) { async retrieveMetadata(
datasourceId: string
): Promise<{ tables: Record<string, Table>; datasource: Datasource }> {
if (!this.datasource) { if (!this.datasource) {
this.datasource = await sdk.datasources.get(datasourceId) this.datasource = await sdk.datasources.get(datasourceId)
if (!this.datasource || !this.datasource.entities) { if (!this.datasource || !this.datasource.entities) {
@ -283,6 +284,7 @@ export class ExternalRequest<T extends Operation> {
this.tables = this.datasource.entities this.tables = this.datasource.entities
this.tableList = Object.values(this.tables) this.tableList = Object.values(this.tables)
} }
return { tables: this.tables, datasource: this.datasource }
} }
async getRow(table: Table, rowId: string): Promise<Row> { async getRow(table: Table, rowId: string): Promise<Row> {
@ -599,11 +601,13 @@ export class ExternalRequest<T extends Operation> {
throw new Error("Unable to run without a table ID") throw new Error("Unable to run without a table ID")
} }
let { datasourceId, tableName } = breakExternalTableId(tableId) let { datasourceId, tableName } = breakExternalTableId(tableId)
if (!this.datasource) { let datasource = this.datasource
await this.retrieveMetadata(datasourceId) if (!datasource) {
const { datasource: ds } = await this.retrieveMetadata(datasourceId)
datasource = ds
} }
const table = this.tables[tableName] const table = this.tables[tableName]
let isSql = isSQL(this.datasource!) let isSql = isSQL(datasource)
if (!table) { if (!table) {
throw new Error( throw new Error(
`Unable to process query, table "${tableName}" not defined.` `Unable to process query, table "${tableName}" not defined.`