2024-10-25 18:32:42 +02:00
|
|
|
import { object } from "./utils"
|
|
|
|
import Resource from "./utils/Resource"
|
|
|
|
|
|
|
|
const view = {
|
2024-10-25 18:51:52 +02:00
|
|
|
name: "peopleView",
|
|
|
|
tableId: "ta_896a325f7e8147d2a2cda93c5d236511",
|
2024-10-25 18:32:42 +02:00
|
|
|
schema: {
|
|
|
|
name: {
|
2024-10-25 18:51:52 +02:00
|
|
|
visible: true,
|
|
|
|
readonly: false,
|
|
|
|
order: 1,
|
|
|
|
width: 300,
|
2024-10-25 18:32:42 +02:00
|
|
|
},
|
|
|
|
age: {
|
2024-10-25 18:51:52 +02:00
|
|
|
visible: true,
|
|
|
|
readonly: true,
|
|
|
|
order: 2,
|
|
|
|
width: 200,
|
2024-10-25 18:32:42 +02:00
|
|
|
},
|
2024-10-25 18:51:52 +02:00
|
|
|
salary: {
|
|
|
|
visible: false,
|
|
|
|
readonly: false,
|
2024-10-25 18:32:42 +02:00
|
|
|
},
|
|
|
|
},
|
2024-10-25 18:51:52 +02:00
|
|
|
primaryDisplay: "name",
|
2024-10-25 18:32:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const baseColumnDef = {
|
2024-10-25 18:51:52 +02:00
|
|
|
visible: {
|
|
|
|
type: "boolean",
|
2024-10-25 18:32:42 +02:00
|
|
|
description:
|
2024-10-25 18:51:52 +02:00
|
|
|
"Defines whether the column is visible or not - rows retrieved/updated through this view will not be able to access it.",
|
2024-10-25 18:32:42 +02:00
|
|
|
},
|
2024-10-25 18:51:52 +02:00
|
|
|
readonly: {
|
|
|
|
type: "boolean",
|
2024-10-25 18:32:42 +02:00
|
|
|
description:
|
2024-10-25 18:51:52 +02:00
|
|
|
"When used in combination with 'visible: true' the column will be visible in row responses but cannot be updated.",
|
2024-10-25 18:32:42 +02:00
|
|
|
},
|
2024-10-25 18:51:52 +02:00
|
|
|
order: {
|
|
|
|
type: "integer",
|
|
|
|
description:
|
|
|
|
"A number defining where the column shows up in tables, lowest being first.",
|
2024-10-25 18:32:42 +02:00
|
|
|
},
|
2024-10-25 18:51:52 +02:00
|
|
|
width: {
|
|
|
|
type: "integer",
|
|
|
|
description:
|
|
|
|
"A width for the column, defined in pixels - this affects rendering in tables.",
|
2024-10-25 18:32:42 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const viewSchema = {
|
2024-10-25 18:51:52 +02:00
|
|
|
description: "The view to be created/updated.",
|
2024-10-25 18:32:42 +02:00
|
|
|
type: "object",
|
|
|
|
required: ["name", "schema"],
|
|
|
|
properties: {
|
|
|
|
name: {
|
2024-10-25 18:51:52 +02:00
|
|
|
description: "The name of the view.",
|
2024-10-25 18:32:42 +02:00
|
|
|
type: "string",
|
|
|
|
},
|
|
|
|
primaryDisplay: {
|
|
|
|
type: "string",
|
|
|
|
description:
|
2024-10-25 18:51:52 +02:00
|
|
|
"A column used to display rows from this view - usually used when rendered in tables.",
|
2024-10-25 18:32:42 +02:00
|
|
|
},
|
|
|
|
schema: {
|
|
|
|
type: "object",
|
|
|
|
additionalProperties: {
|
2024-10-25 18:51:52 +02:00
|
|
|
type: "object",
|
|
|
|
properties: baseColumnDef,
|
2024-10-25 18:32:42 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const viewOutputSchema = {
|
|
|
|
...viewSchema,
|
|
|
|
properties: {
|
|
|
|
...viewSchema.properties,
|
2024-10-25 18:51:52 +02:00
|
|
|
id: {
|
2024-10-25 18:32:42 +02:00
|
|
|
description: "The ID of the view.",
|
|
|
|
type: "string",
|
|
|
|
},
|
|
|
|
},
|
2024-10-25 18:51:52 +02:00
|
|
|
required: [...viewSchema.required, "id"],
|
2024-10-25 18:32:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default new Resource()
|
|
|
|
.setExamples({
|
|
|
|
view: {
|
|
|
|
value: {
|
|
|
|
data: view,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
views: {
|
|
|
|
value: {
|
|
|
|
data: [view],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.setSchemas({
|
|
|
|
view: viewSchema,
|
|
|
|
viewOutput: object({
|
|
|
|
data: viewOutputSchema,
|
|
|
|
}),
|
|
|
|
viewSearch: object({
|
|
|
|
data: {
|
|
|
|
type: "array",
|
|
|
|
items: viewOutputSchema,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
})
|