Making meta required in query JSON.
This commit is contained in:
parent
1ceca21778
commit
7d2861718a
|
@ -119,6 +119,9 @@ async function removeManyToManyRelationships(
|
||||||
endpoint: getEndpoint(tableId, Operation.DELETE),
|
endpoint: getEndpoint(tableId, Operation.DELETE),
|
||||||
body: { [colName]: null },
|
body: { [colName]: null },
|
||||||
filters,
|
filters,
|
||||||
|
meta: {
|
||||||
|
table,
|
||||||
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
return []
|
return []
|
||||||
|
@ -133,6 +136,9 @@ async function removeOneToManyRelationships(rowId: string, table: Table) {
|
||||||
return getDatasourceAndQuery({
|
return getDatasourceAndQuery({
|
||||||
endpoint: getEndpoint(tableId, Operation.UPDATE),
|
endpoint: getEndpoint(tableId, Operation.UPDATE),
|
||||||
filters,
|
filters,
|
||||||
|
meta: {
|
||||||
|
table,
|
||||||
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
return []
|
return []
|
||||||
|
@ -248,6 +254,9 @@ export class ExternalRequest<T extends Operation> {
|
||||||
const response = await getDatasourceAndQuery({
|
const response = await getDatasourceAndQuery({
|
||||||
endpoint: getEndpoint(table._id!, Operation.READ),
|
endpoint: getEndpoint(table._id!, Operation.READ),
|
||||||
filters: buildFilters(rowId, {}, table),
|
filters: buildFilters(rowId, {}, table),
|
||||||
|
meta: {
|
||||||
|
table,
|
||||||
|
}
|
||||||
})
|
})
|
||||||
if (Array.isArray(response) && response.length > 0) {
|
if (Array.isArray(response) && response.length > 0) {
|
||||||
return response[0]
|
return response[0]
|
||||||
|
@ -395,6 +404,9 @@ export class ExternalRequest<T extends Operation> {
|
||||||
[fieldName]: row[lookupField],
|
[fieldName]: row[lookupField],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
meta: {
|
||||||
|
table,
|
||||||
|
}
|
||||||
})
|
})
|
||||||
// this is the response from knex if no rows found
|
// this is the response from knex if no rows found
|
||||||
const rows: Row[] =
|
const rows: Row[] =
|
||||||
|
@ -425,6 +437,7 @@ export class ExternalRequest<T extends Operation> {
|
||||||
// if we're creating (in a through table) need to wipe the existing ones first
|
// if we're creating (in a through table) need to wipe the existing ones first
|
||||||
const promises = []
|
const promises = []
|
||||||
const related = await this.lookupRelations(mainTableId, row)
|
const related = await this.lookupRelations(mainTableId, row)
|
||||||
|
const table = this.getTable(mainTableId)
|
||||||
for (let relationship of relationships) {
|
for (let relationship of relationships) {
|
||||||
const { key, tableId, isUpdate, id, ...rest } = relationship
|
const { key, tableId, isUpdate, id, ...rest } = relationship
|
||||||
const body: { [key: string]: any } = processObjectSync(rest, row, {})
|
const body: { [key: string]: any } = processObjectSync(rest, row, {})
|
||||||
|
@ -470,6 +483,9 @@ export class ExternalRequest<T extends Operation> {
|
||||||
// if we're doing many relationships then we're writing, only one response
|
// if we're doing many relationships then we're writing, only one response
|
||||||
body,
|
body,
|
||||||
filters: buildFilters(id, {}, linkTable),
|
filters: buildFilters(id, {}, linkTable),
|
||||||
|
meta: {
|
||||||
|
table,
|
||||||
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -755,6 +755,9 @@ describe.each(
|
||||||
name: "two",
|
name: "two",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
meta: {
|
||||||
|
table: config.table,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
expect(res).toHaveLength(1)
|
expect(res).toHaveLength(1)
|
||||||
expect(res[0]).toEqual({
|
expect(res[0]).toEqual({
|
||||||
|
|
|
@ -9,6 +9,14 @@ import {
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
|
||||||
const TABLE_NAME = "test"
|
const TABLE_NAME = "test"
|
||||||
|
const TABLE: Table = {
|
||||||
|
type: "table",
|
||||||
|
sourceType: TableSourceType.EXTERNAL,
|
||||||
|
sourceId: "SOURCE_ID",
|
||||||
|
schema: {},
|
||||||
|
name: TABLE_NAME,
|
||||||
|
primary: ["id"],
|
||||||
|
}
|
||||||
|
|
||||||
function endpoint(table: any, operation: any) {
|
function endpoint(table: any, operation: any) {
|
||||||
return {
|
return {
|
||||||
|
@ -25,6 +33,10 @@ function generateReadJson({
|
||||||
sort,
|
sort,
|
||||||
paginate,
|
paginate,
|
||||||
}: any = {}): QueryJson {
|
}: any = {}): QueryJson {
|
||||||
|
const tableObj = { ...TABLE }
|
||||||
|
if (table) {
|
||||||
|
tableObj.name = table
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
endpoint: endpoint(table || TABLE_NAME, "READ"),
|
endpoint: endpoint(table || TABLE_NAME, "READ"),
|
||||||
resource: {
|
resource: {
|
||||||
|
@ -34,14 +46,7 @@ function generateReadJson({
|
||||||
sort: sort || {},
|
sort: sort || {},
|
||||||
paginate: paginate || {},
|
paginate: paginate || {},
|
||||||
meta: {
|
meta: {
|
||||||
table: {
|
table: tableObj,
|
||||||
type: "table",
|
|
||||||
sourceType: TableSourceType.EXTERNAL,
|
|
||||||
sourceId: "SOURCE_ID",
|
|
||||||
schema: {},
|
|
||||||
name: table || TABLE_NAME,
|
|
||||||
primary: ["id"],
|
|
||||||
} as any,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,6 +54,9 @@ function generateReadJson({
|
||||||
function generateCreateJson(table = TABLE_NAME, body = {}): QueryJson {
|
function generateCreateJson(table = TABLE_NAME, body = {}): QueryJson {
|
||||||
return {
|
return {
|
||||||
endpoint: endpoint(table, "CREATE"),
|
endpoint: endpoint(table, "CREATE"),
|
||||||
|
meta: {
|
||||||
|
table: TABLE,
|
||||||
|
},
|
||||||
body,
|
body,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,6 +78,9 @@ function generateUpdateJson({
|
||||||
function generateDeleteJson(table = TABLE_NAME, filters = {}): QueryJson {
|
function generateDeleteJson(table = TABLE_NAME, filters = {}): QueryJson {
|
||||||
return {
|
return {
|
||||||
endpoint: endpoint(table, "DELETE"),
|
endpoint: endpoint(table, "DELETE"),
|
||||||
|
meta: {
|
||||||
|
table: TABLE,
|
||||||
|
},
|
||||||
filters,
|
filters,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,6 +113,9 @@ function generateRelationshipJson(config: { schema?: string } = {}): QueryJson {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
extra: { idFilter: {} },
|
extra: { idFilter: {} },
|
||||||
|
meta: {
|
||||||
|
table: TABLE,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@ import {
|
||||||
QueryJson,
|
QueryJson,
|
||||||
SourceName,
|
SourceName,
|
||||||
SqlQuery,
|
SqlQuery,
|
||||||
|
Table,
|
||||||
|
TableSourceType,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { join } from "path"
|
import { join } from "path"
|
||||||
import Sql from "../base/sql"
|
import Sql from "../base/sql"
|
||||||
|
@ -11,6 +13,16 @@ import { SqlClient } from "../utils"
|
||||||
import { generator } from "@budibase/backend-core/tests"
|
import { generator } from "@budibase/backend-core/tests"
|
||||||
import sdk from "../../sdk"
|
import sdk from "../../sdk"
|
||||||
|
|
||||||
|
// this doesn't exist strictly
|
||||||
|
const TABLE: Table = {
|
||||||
|
type: "table",
|
||||||
|
sourceType: TableSourceType.EXTERNAL,
|
||||||
|
sourceId: "SOURCE_ID",
|
||||||
|
schema: {},
|
||||||
|
name: "tableName",
|
||||||
|
primary: ["id"],
|
||||||
|
}
|
||||||
|
|
||||||
const AliasTables = sdk.rows.AliasTables
|
const AliasTables = sdk.rows.AliasTables
|
||||||
|
|
||||||
function multiline(sql: string) {
|
function multiline(sql: string) {
|
||||||
|
@ -222,6 +234,9 @@ describe("Captures of real examples", () => {
|
||||||
resource: {
|
resource: {
|
||||||
fields,
|
fields,
|
||||||
},
|
},
|
||||||
|
meta: {
|
||||||
|
table: TABLE,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ export interface QueryJson {
|
||||||
paginate?: PaginationJson
|
paginate?: PaginationJson
|
||||||
body?: Row | Row[]
|
body?: Row | Row[]
|
||||||
table?: Table
|
table?: Table
|
||||||
meta?: {
|
meta: {
|
||||||
table?: Table
|
table?: Table
|
||||||
tables?: Record<string, Table>
|
tables?: Record<string, Table>
|
||||||
renamed?: RenameColumn
|
renamed?: RenameColumn
|
||||||
|
|
Loading…
Reference in New Issue