2022-02-21 17:37:02 +01:00
|
|
|
const {
|
|
|
|
FieldTypes,
|
|
|
|
RelationshipTypes,
|
|
|
|
FormulaTypes,
|
|
|
|
} = require("../src/constants")
|
2022-02-18 19:06:58 +01:00
|
|
|
|
2022-02-18 18:44:08 +01:00
|
|
|
exports.row = {
|
|
|
|
description: "The row to be created/updated, based on the table schema.",
|
|
|
|
type: "object",
|
|
|
|
additionalProperties: {
|
|
|
|
oneOf: [
|
|
|
|
{ type: "string" },
|
|
|
|
{ type: "object" },
|
|
|
|
{ type: "integer" },
|
|
|
|
{ type: "array" },
|
|
|
|
{ type: "boolean" },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
}
|
2022-02-18 19:06:58 +01:00
|
|
|
|
2022-02-21 17:37:02 +01:00
|
|
|
const baseColumnDef = {
|
|
|
|
type: {
|
|
|
|
type: "string",
|
|
|
|
enum: Object.values(FieldTypes),
|
|
|
|
description:
|
|
|
|
"Defines the type of the column, most explain themselves, a link column is a relationship.",
|
|
|
|
},
|
|
|
|
constraints: {
|
|
|
|
type: "object",
|
|
|
|
description:
|
|
|
|
"A constraint can be applied to the column which will be validated against when a row is saved.",
|
|
|
|
properties: {
|
|
|
|
type: {
|
|
|
|
type: "string",
|
|
|
|
enum: ["string", "number", "object", "boolean"],
|
|
|
|
},
|
|
|
|
presence: {
|
|
|
|
type: "boolean",
|
|
|
|
description: "Defines whether the column is required or not.",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
type: "string",
|
|
|
|
description: "The name of the column.",
|
|
|
|
},
|
|
|
|
autocolumn: {
|
|
|
|
type: "boolean",
|
|
|
|
description: "Defines whether the column is automatically generated.",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-02-18 19:06:58 +01:00
|
|
|
exports.table = {
|
|
|
|
description: "The table to be created/updated.",
|
|
|
|
type: "object",
|
|
|
|
properties: {
|
|
|
|
name: {
|
|
|
|
description: "The name of the table",
|
|
|
|
type: "string",
|
|
|
|
},
|
2022-02-21 17:37:02 +01:00
|
|
|
primaryDisplay: {
|
|
|
|
type: "string",
|
|
|
|
description:
|
|
|
|
"The name of the column which should be used in relationship tags when relating to this table.",
|
|
|
|
},
|
2022-02-18 19:06:58 +01:00
|
|
|
schema: {
|
2022-02-21 17:37:02 +01:00
|
|
|
oneOf: [
|
|
|
|
// relationship
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
properties: {
|
|
|
|
...baseColumnDef,
|
|
|
|
type: {
|
|
|
|
type: "string",
|
|
|
|
enum: [FieldTypes.LINK],
|
|
|
|
description: "A relationship column.",
|
|
|
|
},
|
|
|
|
fieldName: {
|
|
|
|
type: "string",
|
|
|
|
description:
|
|
|
|
"The name of the column which a relationship column is related to in another table.",
|
|
|
|
},
|
|
|
|
tableId: {
|
|
|
|
type: "string",
|
|
|
|
description:
|
|
|
|
"The ID of the table which a relationship column is related to.",
|
|
|
|
},
|
|
|
|
relationshipType: {
|
|
|
|
type: "string",
|
|
|
|
enum: Object.values(RelationshipTypes),
|
|
|
|
description:
|
|
|
|
"Defines the type of relationship that this column will be used for.",
|
|
|
|
},
|
|
|
|
through: {
|
|
|
|
type: "string",
|
|
|
|
description:
|
|
|
|
"When using a SQL table that contains many to many relationships this defines the table the relationships are linked through.",
|
|
|
|
},
|
|
|
|
foreignKey: {
|
|
|
|
type: "string",
|
|
|
|
description:
|
|
|
|
"When using a SQL table that contains a one to many relationship this defines the foreign key.",
|
|
|
|
},
|
|
|
|
throughFrom: {
|
|
|
|
type: "string",
|
|
|
|
description:
|
|
|
|
"When using a SQL table that utilises a through table, this defines the primary key in the through table for this table.",
|
|
|
|
},
|
|
|
|
throughTo: {
|
|
|
|
type: "string",
|
|
|
|
description:
|
|
|
|
"When using a SQL table that utilises a through table, this defines the primary key in the through table for the related table.",
|
|
|
|
},
|
2022-02-18 19:06:58 +01:00
|
|
|
},
|
|
|
|
},
|
2022-02-21 17:37:02 +01:00
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
properties: {
|
|
|
|
...baseColumnDef,
|
|
|
|
type: {
|
|
|
|
type: "string",
|
|
|
|
enum: [FieldTypes.FORMULA],
|
|
|
|
description: "A formula column.",
|
|
|
|
},
|
|
|
|
formula: {
|
|
|
|
type: "string",
|
|
|
|
description:
|
|
|
|
"Defines a Handlebars or JavaScript formula to use, note that Javascript formulas are expected to be provided in the base64 format.",
|
|
|
|
},
|
|
|
|
formulaType: {
|
|
|
|
type: "string",
|
|
|
|
enum: Object.values(FormulaTypes),
|
|
|
|
description:
|
|
|
|
"Defines whether this is a static or dynamic formula.",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
properties: baseColumnDef,
|
|
|
|
},
|
|
|
|
],
|
2022-02-18 19:06:58 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2022-02-21 20:04:13 +01:00
|
|
|
|
2022-02-22 15:28:57 +01:00
|
|
|
function object(props) {
|
|
|
|
return {
|
|
|
|
type: "object",
|
|
|
|
properties: props,
|
|
|
|
}
|
2022-02-21 20:04:13 +01:00
|
|
|
}
|
|
|
|
|
2022-02-22 15:28:57 +01:00
|
|
|
exports.query = object({})
|
2022-02-21 20:04:13 +01:00
|
|
|
|
2022-02-22 15:28:57 +01:00
|
|
|
exports.user = object({})
|
2022-02-22 15:10:01 +01:00
|
|
|
|
2022-02-22 15:28:57 +01:00
|
|
|
exports.application = object({})
|
2022-02-22 15:10:01 +01:00
|
|
|
|
2022-02-22 15:28:57 +01:00
|
|
|
exports.applicationOutput = object({
|
|
|
|
application: exports.application,
|
|
|
|
})
|
2022-02-22 15:10:01 +01:00
|
|
|
|
2022-02-22 15:28:57 +01:00
|
|
|
exports.tableOutput = object({
|
|
|
|
table: exports.table,
|
|
|
|
})
|
2022-02-22 15:10:01 +01:00
|
|
|
|
2022-02-22 15:28:57 +01:00
|
|
|
exports.userOutput = object({
|
|
|
|
user: exports.user,
|
|
|
|
})
|
|
|
|
|
|
|
|
exports.rowOutput = object({
|
|
|
|
row: exports.row,
|
|
|
|
})
|
|
|
|
|
|
|
|
exports.nameSearch = object({
|
|
|
|
name: {
|
|
|
|
type: "string",
|
|
|
|
description:
|
|
|
|
"The name to be used when searching - this will be used in a case insensitive starts with match.",
|
2022-02-22 15:10:01 +01:00
|
|
|
},
|
2022-02-22 15:28:57 +01:00
|
|
|
})
|