PR comments and type improvements.
This commit is contained in:
parent
680c68a35b
commit
956df101e8
|
@ -77,6 +77,7 @@ describe.each([
|
||||||
table = await createTable(
|
table = await createTable(
|
||||||
{
|
{
|
||||||
name: { name: "name", type: FieldType.STRING },
|
name: { name: "name", type: FieldType.STRING },
|
||||||
|
//@ts-ignore - API accepts this structure, will build out rest of definition
|
||||||
productCat: {
|
productCat: {
|
||||||
type: FieldType.LINK,
|
type: FieldType.LINK,
|
||||||
relationshipType: type,
|
relationshipType: type,
|
||||||
|
@ -2297,12 +2298,17 @@ describe.each([
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it("can only pull 500 related rows", async () => {
|
it("can only pull 10 related rows", async () => {
|
||||||
await withCoreEnv({ SQL_MAX_RELATED_ROWS: "10" }, async () => {
|
await withCoreEnv({ SQL_MAX_RELATED_ROWS: "10" }, async () => {
|
||||||
const response = await expectQuery({}).toContain([{ name: "foo" }])
|
const response = await expectQuery({}).toContain([{ name: "foo" }])
|
||||||
expect(response.rows[0].productCat).toBeArrayOfSize(10)
|
expect(response.rows[0].productCat).toBeArrayOfSize(10)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("can pull max rows when env not set (defaults to 500)", async () => {
|
||||||
|
const response = await expectQuery({}).toContain([{ name: "foo" }])
|
||||||
|
expect(response.rows[0].productCat).toBeArrayOfSize(11)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
;(isSqs || isLucene) &&
|
;(isSqs || isLucene) &&
|
||||||
describe("relations to same table", () => {
|
describe("relations to same table", () => {
|
||||||
|
|
|
@ -204,7 +204,9 @@ export async function save(
|
||||||
|
|
||||||
// add in the new table for relationship purposes
|
// add in the new table for relationship purposes
|
||||||
tables[tableToSave.name] = tableToSave
|
tables[tableToSave.name] = tableToSave
|
||||||
cleanupRelationships(tableToSave, tables, oldTable)
|
if (oldTable) {
|
||||||
|
cleanupRelationships(tableToSave, tables, { oldTable })
|
||||||
|
}
|
||||||
|
|
||||||
const operation = tableId ? Operation.UPDATE_TABLE : Operation.CREATE_TABLE
|
const operation = tableId ? Operation.UPDATE_TABLE : Operation.CREATE_TABLE
|
||||||
await makeTableRequest(
|
await makeTableRequest(
|
||||||
|
@ -259,7 +261,7 @@ export async function destroy(datasourceId: string, table: Table) {
|
||||||
const operation = Operation.DELETE_TABLE
|
const operation = Operation.DELETE_TABLE
|
||||||
if (tables) {
|
if (tables) {
|
||||||
await makeTableRequest(datasource, operation, table, tables)
|
await makeTableRequest(datasource, operation, table, tables)
|
||||||
cleanupRelationships(table, tables)
|
cleanupRelationships(table, tables, { deleting: true })
|
||||||
delete tables[table.name]
|
delete tables[table.name]
|
||||||
datasource.entities = tables
|
datasource.entities = tables
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,17 +20,25 @@ import { cloneDeep } from "lodash/fp"
|
||||||
export function cleanupRelationships(
|
export function cleanupRelationships(
|
||||||
table: Table,
|
table: Table,
|
||||||
tables: Record<string, Table>,
|
tables: Record<string, Table>,
|
||||||
oldTable?: Table
|
opts: { oldTable: Table }
|
||||||
) {
|
): void
|
||||||
if (!oldTable) {
|
export function cleanupRelationships(
|
||||||
return
|
table: Table,
|
||||||
}
|
tables: Record<string, Table>,
|
||||||
|
opts: { deleting: boolean }
|
||||||
|
): void
|
||||||
|
export function cleanupRelationships(
|
||||||
|
table: Table,
|
||||||
|
tables: Record<string, Table>,
|
||||||
|
opts?: { oldTable?: Table; deleting?: boolean }
|
||||||
|
): void {
|
||||||
|
const oldTable = opts?.oldTable
|
||||||
const tableToIterate = oldTable ? oldTable : table
|
const tableToIterate = oldTable ? oldTable : table
|
||||||
// clean up relationships in couch table schemas
|
// clean up relationships in couch table schemas
|
||||||
for (let [key, schema] of Object.entries(tableToIterate.schema)) {
|
for (let [key, schema] of Object.entries(tableToIterate.schema)) {
|
||||||
if (
|
if (
|
||||||
schema.type === FieldType.LINK &&
|
schema.type === FieldType.LINK &&
|
||||||
oldTable.schema[key] != null &&
|
(opts?.deleting || oldTable?.schema[key] != null) &&
|
||||||
table.schema[key] == null
|
table.schema[key] == null
|
||||||
) {
|
) {
|
||||||
const schemaTableId = schema.tableId
|
const schemaTableId = schema.tableId
|
||||||
|
|
|
@ -600,10 +600,10 @@ export function fullSchemaWithoutLinks({
|
||||||
allRequired,
|
allRequired,
|
||||||
}: {
|
}: {
|
||||||
allRequired?: boolean
|
allRequired?: boolean
|
||||||
}) {
|
}): {
|
||||||
const schema: {
|
|
||||||
[type in Exclude<FieldType, FieldType.LINK>]: FieldSchema & { type: type }
|
[type in Exclude<FieldType, FieldType.LINK>]: FieldSchema & { type: type }
|
||||||
} = {
|
} {
|
||||||
|
return {
|
||||||
[FieldType.STRING]: {
|
[FieldType.STRING]: {
|
||||||
name: "string",
|
name: "string",
|
||||||
type: FieldType.STRING,
|
type: FieldType.STRING,
|
||||||
|
@ -741,8 +741,6 @@ export function fullSchemaWithoutLinks({
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return schema
|
|
||||||
}
|
}
|
||||||
export function basicAttachment() {
|
export function basicAttachment() {
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in New Issue