Rows API mostly complete, starting into tables.

This commit is contained in:
mike12345567 2022-02-18 15:47:15 +00:00
parent 51b4d42492
commit edcb138366
11 changed files with 652 additions and 70 deletions

View File

@ -22,6 +22,7 @@
"dev:stack:nuke": "node scripts/dev/manage.js nuke", "dev:stack:nuke": "node scripts/dev/manage.js nuke",
"dev:builder": "yarn run dev:stack:up && nodemon", "dev:builder": "yarn run dev:stack:up && nodemon",
"format": "prettier --config ../../.prettierrc.json 'src/**/*.ts' --write", "format": "prettier --config ../../.prettierrc.json 'src/**/*.ts' --write",
"specs": "node specs/generate.js",
"lint": "eslint --fix src/", "lint": "eslint --fix src/",
"lint:fix": "yarn run format && yarn run lint", "lint:fix": "yarn run format && yarn run lint",
"initialise": "node scripts/initialise.js", "initialise": "node scripts/initialise.js",

View File

@ -1,3 +1,17 @@
const row = {
_id: "ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4",
type: "row",
tableId: "ta_5b1649e42a5b41dea4ef7742a36a7a70",
name: "Mike",
age: 30,
relationship: [
{
primaryDisplay: "Joe",
_id: "ro_ta_...",
},
],
}
exports.table = { exports.table = {
value: { value: {
_id: "ta_5b1649e42a5b41dea4ef7742a36a7a70", _id: "ta_5b1649e42a5b41dea4ef7742a36a7a70",
@ -23,17 +37,13 @@ exports.table = {
} }
exports.row = { exports.row = {
value: row,
}
exports.search = {
value: { value: {
_id: "ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4", rows: [row],
type: "row", hasNextPage: true,
tableId: "ta_5b1649e42a5b41dea4ef7742a36a7a70", bookmark: 10,
name: "Mike",
age: 30,
relationship: [
{
primaryDisplay: "Joe",
_id: "ro_ta_...",
},
],
}, },
} }

View File

@ -1,8 +1,9 @@
const swaggerJsdoc = require("swagger-jsdoc") const swaggerJsdoc = require("swagger-jsdoc")
const { join } = require("path") const { join } = require("path")
const { writeFileSync } = require("fs") const { writeFileSync } = require("fs")
const { row, table } = require("./examples") const examples = require("./examples")
const { tableId } = require("./parameters") const parameters = require("./parameters")
const security = require("./security")
const VARIABLES = {} const VARIABLES = {}
@ -26,13 +27,20 @@ const options = {
], ],
components: { components: {
parameters: { parameters: {
tableId: tableId, ...parameters,
}, },
examples: { examples: {
row: row, ...examples,
table: table, },
securitySchemes: {
...security,
}, },
}, },
security: [
{
ApiKeyAuth: [],
},
],
}, },
format: ".json", format: ".json",
apis: [join(__dirname, "..", "src", "api", "routes", "public", "*.js")], apis: [join(__dirname, "..", "src", "api", "routes", "public", "*.js")],

View File

@ -21,28 +21,22 @@
"in": "path", "in": "path",
"name": "tableId", "name": "tableId",
"required": true, "required": true,
"description": "The ID of the table which contains the rows which are being searched for.", "description": "The ID of the table which this request is targeting.",
"schema": {
"type": "string"
}
},
"rowId": {
"in": "path",
"name": "rowId",
"required": true,
"description": "The ID of the row which this request is targeting.",
"schema": { "schema": {
"type": "string" "type": "string"
} }
} }
}, },
"examples": { "examples": {
"row": {
"value": {
"_id": "ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4",
"type": "row",
"tableId": "ta_5b1649e42a5b41dea4ef7742a36a7a70",
"name": "Mike",
"age": 30,
"relationship": [
{
"primaryDisplay": "Joe",
"_id": "ro_ta_..."
}
]
}
},
"table": { "table": {
"value": { "value": {
"_id": "ta_5b1649e42a5b41dea4ef7742a36a7a70", "_id": "ta_5b1649e42a5b41dea4ef7742a36a7a70",
@ -65,13 +59,65 @@
} }
} }
} }
},
"row": {
"value": {
"_id": "ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4",
"type": "row",
"tableId": "ta_5b1649e42a5b41dea4ef7742a36a7a70",
"name": "Mike",
"age": 30,
"relationship": [
{
"primaryDisplay": "Joe",
"_id": "ro_ta_..."
}
]
}
},
"search": {
"value": {
"rows": [
{
"_id": "ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4",
"type": "row",
"tableId": "ta_5b1649e42a5b41dea4ef7742a36a7a70",
"name": "Mike",
"age": 30,
"relationship": [
{
"primaryDisplay": "Joe",
"_id": "ro_ta_..."
}
]
}
],
"hasNextPage": true,
"bookmark": 10
}
}
},
"securitySchemes": {
"ApiKeyAuth": {
"type": "apiKey",
"in": "header",
"name": "x-budibase-api-key",
"description": "Your individual API key, this will provide access based on the configured RBAC settings of your user."
} }
} }
}, },
"security": [
{
"ApiKeyAuth": []
}
],
"paths": { "paths": {
"/tables/{tableId}/rows/search": { "/tables/{tableId}/rows/search": {
"post": { "post": {
"summary": "Allows searching for rows within a table.", "summary": "Used to search for rows within a table.",
"tags": [
"rows"
],
"parameters": [ "parameters": [
{ {
"$ref": "#/components/parameters/tableId" "$ref": "#/components/parameters/tableId"
@ -191,10 +237,7 @@
"description": "An array of rows, these will each contain an _id field which can be used to update or delete them.", "description": "An array of rows, these will each contain an _id field which can be used to update or delete them.",
"type": "array", "type": "array",
"items": { "items": {
"type": "object", "type": "object"
"example": {
"$ref": "#/components/examples/row"
}
} }
}, },
"bookmark": { "bookmark": {
@ -206,12 +249,17 @@
"type": "integer" "type": "integer"
} }
], ],
"description": "If pagination in use, this should be provided" "description": "If pagination in use, this should be provided."
}, },
"hasNextPage": { "hasNextPage": {
"description": "If pagination in use, this will determine if there is another page to fetch.", "description": "If pagination in use, this will determine if there is another page to fetch.",
"type": "boolean" "type": "boolean"
} }
},
"examples": {
"search": [
"#/components/examples/search"
]
} }
} }
} }
@ -222,12 +270,81 @@
}, },
"/tables/{tableId}/rows": { "/tables/{tableId}/rows": {
"post": { "post": {
"summary": "Allows creating a row within a specified table.", "summary": "Creates a new row within a specified table.",
"tags": [
"rows"
],
"parameters": [ "parameters": [
{ {
"$ref": "#/components/parameters/tableId" "$ref": "#/components/parameters/tableId"
} }
], ],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"description": "The contents of the row which is to be created, the keys of",
"type": "object",
"example": {
"$ref": "#/components/examples/row"
},
"additionalProperties": {
"oneOf": [
{
"type": "string"
},
{
"type": "object"
},
{
"type": "integer"
},
{
"type": "array"
},
{
"type": "boolean"
}
]
}
}
}
}
},
"responses": {
"200": {
"description": "Returns the created row, including the ID which has been generated for it. This can be found in the Budibase portal, viewed under the developer information.",
"content": {
"application/json": {
"schema": {
"type": "object"
},
"examples": {
"row": {
"$ref": "#/components/examples/row"
}
}
}
}
}
}
}
},
"/tables/{tableId}/rows/{rowId}": {
"put": {
"summary": "Update a single row within a specified table.",
"tags": [
"rows"
],
"parameters": [
{
"$ref": "#/components/parameters/tableId"
},
{
"$ref": "#/components/parameters/rowId"
}
],
"responses": { "responses": {
"200": { "200": {
"description": "Returns the created row, including the ID which has been generated for it.", "description": "Returns the created row, including the ID which has been generated for it.",
@ -235,6 +352,98 @@
"application/json": { "application/json": {
"schema": { "schema": {
"type": "object" "type": "object"
},
"examples": {
"row": {
"$ref": "#/components/examples/row"
}
}
}
}
}
}
},
"delete": {
"summary": "Delete a single row from the specified table.",
"tags": [
"rows"
],
"parameters": [
{
"$ref": "#/components/parameters/tableId"
},
{
"$ref": "#/components/parameters/rowId"
}
],
"responses": {
"200": {
"description": "Returns the deleted row, including the ID which has been generated for it.",
"content": {
"application/json": {
"schema": {
"type": "object"
},
"examples": {
"row": {
"$ref": "#/components/examples/row"
}
}
}
}
}
}
},
"get": {
"summary": "Get a single row from the specified table.",
"tags": [
"rows"
],
"parameters": [
{
"$ref": "#/components/parameters/tableId"
},
{
"$ref": "#/components/parameters/rowId"
}
],
"responses": {
"200": {
"description": "Returns the retrieved row.",
"content": {
"application/json": {
"schema": {
"type": "object"
},
"examples": {
"row": {
"$ref": "#/components/examples/row"
}
}
}
}
}
}
}
},
"/tables": {
"post": {
"summary": "Create a new table",
"tags": [
"tables"
],
"responses": {
"200": {
"description": "Returns the created table, including the ID which has been generated for it.",
"content": {
"application/json": {
"schema": {
"type": "object"
},
"examples": {
"row": {
"$ref": "#/components/examples/table"
}
} }
} }
} }

View File

@ -14,20 +14,17 @@ components:
in: path in: path
name: tableId name: tableId
required: true required: true
description: The ID of the table which contains the rows which are being searched for. description: The ID of the table which this request is targeting.
schema:
type: string
rowId:
in: path
name: rowId
required: true
description: The ID of the row which this request is targeting.
schema: schema:
type: string type: string
examples: examples:
row:
value:
_id: ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4
type: row
tableId: ta_5b1649e42a5b41dea4ef7742a36a7a70
name: Mike
age: 30
relationship:
- primaryDisplay: Joe
_id: ro_ta_...
table: table:
value: value:
_id: ta_5b1649e42a5b41dea4ef7742a36a7a70 _id: ta_5b1649e42a5b41dea4ef7742a36a7a70
@ -45,10 +42,44 @@ components:
tableId: ta_... tableId: ta_...
fieldName: relatedColumn fieldName: relatedColumn
relationshipType: many-to-many relationshipType: many-to-many
row:
value:
_id: ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4
type: row
tableId: ta_5b1649e42a5b41dea4ef7742a36a7a70
name: Mike
age: 30
relationship:
- primaryDisplay: Joe
_id: ro_ta_...
search:
value:
rows:
- _id: ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4
type: row
tableId: ta_5b1649e42a5b41dea4ef7742a36a7a70
name: Mike
age: 30
relationship:
- primaryDisplay: Joe
_id: ro_ta_...
hasNextPage: true
bookmark: 10
securitySchemes:
ApiKeyAuth:
type: apiKey
in: header
name: x-budibase-api-key
description: Your individual API key, this will provide access based on the
configured RBAC settings of your user.
security:
- ApiKeyAuth: []
paths: paths:
"/tables/{tableId}/rows/search": "/tables/{tableId}/rows/search":
post: post:
summary: Allows searching for rows within a table. summary: Used to search for rows within a table.
tags:
- rows
parameters: parameters:
- $ref: "#/components/parameters/tableId" - $ref: "#/components/parameters/tableId"
requestBody: requestBody:
@ -148,22 +179,61 @@ paths:
type: array type: array
items: items:
type: object type: object
example:
$ref: "#/components/examples/row"
bookmark: bookmark:
oneOf: oneOf:
- type: string - type: string
- type: integer - type: integer
description: If pagination in use, this should be provided description: If pagination in use, this should be provided.
hasNextPage: hasNextPage:
description: If pagination in use, this will determine if there is another page description: If pagination in use, this will determine if there is another page
to fetch. to fetch.
type: boolean type: boolean
examples:
search:
- "#/components/examples/search"
"/tables/{tableId}/rows": "/tables/{tableId}/rows":
post: post:
summary: Allows creating a row within a specified table. summary: Creates a new row within a specified table.
tags:
- rows
parameters: parameters:
- $ref: "#/components/parameters/tableId" - $ref: "#/components/parameters/tableId"
requestBody:
required: true
content:
application/json:
schema:
description: The contents of the row which is to be created, the keys of
type: object
example:
$ref: "#/components/examples/row"
additionalProperties:
oneOf:
- type: string
- type: object
- type: integer
- type: array
- type: boolean
responses:
"200":
description: Returns the created row, including the ID which has been generated
for it. This can be found in the Budibase portal, viewed under the
developer information.
content:
application/json:
schema:
type: object
examples:
row:
$ref: "#/components/examples/row"
"/tables/{tableId}/rows/{rowId}":
put:
summary: Update a single row within a specified table.
tags:
- rows
parameters:
- $ref: "#/components/parameters/tableId"
- $ref: "#/components/parameters/rowId"
responses: responses:
"200": "200":
description: Returns the created row, including the ID which has been generated description: Returns the created row, including the ID which has been generated
@ -172,4 +242,58 @@ paths:
application/json: application/json:
schema: schema:
type: object type: object
examples:
row:
$ref: "#/components/examples/row"
delete:
summary: Delete a single row from the specified table.
tags:
- rows
parameters:
- $ref: "#/components/parameters/tableId"
- $ref: "#/components/parameters/rowId"
responses:
"200":
description: Returns the deleted row, including the ID which has been generated
for it.
content:
application/json:
schema:
type: object
examples:
row:
$ref: "#/components/examples/row"
get:
summary: Get a single row from the specified table.
tags:
- rows
parameters:
- $ref: "#/components/parameters/tableId"
- $ref: "#/components/parameters/rowId"
responses:
"200":
description: Returns the retrieved row.
content:
application/json:
schema:
type: object
examples:
row:
$ref: "#/components/examples/row"
/tables:
post:
summary: Create a new table
tags:
- tables
responses:
"200":
description: Returns the created table, including the ID which has been
generated for it.
content:
application/json:
schema:
type: object
examples:
row:
$ref: "#/components/examples/table"
tags: [] tags: []

View File

@ -2,8 +2,17 @@ exports.tableId = {
in: "path", in: "path",
name: "tableId", name: "tableId",
required: true, required: true,
description: description: "The ID of the table which this request is targeting.",
"The ID of the table which contains the rows which are being searched for.", schema: {
type: "string",
},
}
exports.rowId = {
in: "path",
name: "rowId",
required: true,
description: "The ID of the row which this request is targeting.",
schema: { schema: {
type: "string", type: "string",
}, },

View File

@ -0,0 +1,7 @@
exports.ApiKeyAuth = {
type: "apiKey",
in: "header",
name: "x-budibase-api-key",
description:
"Your individual API key, this will provide access based on the configured RBAC settings of your user.",
}

View File

@ -1,8 +1,3 @@
/*
* Contains pass through functions for all of the public API, make sure
* parameters are in correct format for the main controllers.
*/
exports.search = () => { exports.search = () => {
} }

View File

@ -0,0 +1,19 @@
exports.create = () => {
}
exports.getAllTables = () => {
}
exports.getSingleTable = () => {
}
exports.update = () => {
}
exports.delete = () => {
}

View File

@ -1,5 +1,5 @@
const Router = require("@koa/router") const Router = require("@koa/router")
const controller = require("../../controllers/public") const controller = require("../../controllers/public/rows")
const router = Router() const router = Router()
@ -7,7 +7,9 @@ const router = Router()
* @openapi * @openapi
* /tables/{tableId}/rows/search: * /tables/{tableId}/rows/search:
* post: * post:
* summary: Allows searching for rows within a table. * summary: Used to search for rows within a table.
* tags:
* - rows
* parameters: * parameters:
* - $ref: '#/components/parameters/tableId' * - $ref: '#/components/parameters/tableId'
* requestBody: * requestBody:
@ -100,16 +102,17 @@ const router = Router()
* type: array * type: array
* items: * items:
* type: object * type: object
* example:
* $ref: '#/components/examples/row'
* bookmark: * bookmark:
* oneOf: * oneOf:
* - type: string * - type: string
* - type: integer * - type: integer
* description: If pagination in use, this should be provided * description: If pagination in use, this should be provided.
* hasNextPage: * hasNextPage:
* description: If pagination in use, this will determine if there is another page to fetch. * description: If pagination in use, this will determine if there is another page to fetch.
* type: boolean * type: boolean
* examples:
* search:
* - '#/components/examples/search'
*/ */
router.post("/tables/:tableId/rows/search", controller.search) router.post("/tables/:tableId/rows/search", controller.search)
@ -117,9 +120,51 @@ router.post("/tables/:tableId/rows/search", controller.search)
* @openapi * @openapi
* /tables/{tableId}/rows: * /tables/{tableId}/rows:
* post: * post:
* summary: Allows creating a row within a specified table. * summary: Creates a new row within a specified table.
* tags:
* - rows
* parameters: * parameters:
* - $ref: '#/components/parameters/tableId' * - $ref: '#/components/parameters/tableId'
* requestBody:
* required: true
* content:
* application/json:
* schema:
* description: The contents of the row which is to be created, the keys of
* type: object
* example:
* $ref: '#/components/examples/row'
* additionalProperties:
* oneOf:
* - type: string
* - type: object
* - type: integer
* - type: array
* - type: boolean
* responses:
* 200:
* description: Returns the created row, including the ID which has been generated for it.
* This can be found in the Budibase portal, viewed under the developer information.
* content:
* application/json:
* schema:
* type: object
* examples:
* row:
* $ref: '#/components/examples/row'
*/
router.post("/tables/:tableId/rows", controller.create)
/**
* @openapi
* /tables/{tableId}/rows/{rowId}:
* put:
* summary: Update a single row within a specified table.
* tags:
* - rows
* parameters:
* - $ref: '#/components/parameters/tableId'
* - $ref: '#/components/parameters/rowId'
* responses: * responses:
* 200: * 200:
* description: Returns the created row, including the ID which has been generated for it. * description: Returns the created row, including the ID which has been generated for it.
@ -127,13 +172,56 @@ router.post("/tables/:tableId/rows/search", controller.search)
* application/json: * application/json:
* schema: * schema:
* type: object * type: object
* examples:
* row:
* $ref: '#/components/examples/row'
*/ */
router.post("/tables/:tableId/rows", controller.create)
router.put("/tables/:tableId/rows/:rowId", controller.update) router.put("/tables/:tableId/rows/:rowId", controller.update)
/**
* @openapi
* /tables/{tableId}/rows/{rowId}:
* delete:
* summary: Delete a single row from the specified table.
* tags:
* - rows
* parameters:
* - $ref: '#/components/parameters/tableId'
* - $ref: '#/components/parameters/rowId'
* responses:
* 200:
* description: Returns the deleted row, including the ID which has been generated for it.
* content:
* application/json:
* schema:
* type: object
* examples:
* row:
* $ref: '#/components/examples/row'
*/
router.delete("/tables/:tableId/rows/:rowId", controller.delete) router.delete("/tables/:tableId/rows/:rowId", controller.delete)
/**
* @openapi
* /tables/{tableId}/rows/{rowId}:
* get:
* summary: Get a single row from the specified table.
* tags:
* - rows
* parameters:
* - $ref: '#/components/parameters/tableId'
* - $ref: '#/components/parameters/rowId'
* responses:
* 200:
* description: Returns the retrieved row.
* content:
* application/json:
* schema:
* type: object
* examples:
* row:
* $ref: '#/components/examples/row'
*/
router.get("/tables/:tableId/rows/:rowId", controller.singleRead) router.get("/tables/:tableId/rows/:rowId", controller.singleRead)
module.exports = router module.exports = router

View File

@ -1,5 +1,117 @@
const Router = require("@koa/router") const Router = require("@koa/router")
const controller = require("../../controllers/public/tables")
const router = Router() const router = Router()
/**
* @openapi
* /tables:
* post:
* summary: Create a new table
* tags:
* - tables
* responses:
* 200:
* description: Returns the created table, including the ID which has been generated for it.
* content:
* application/json:
* schema:
* type: object
* examples:
* row:
* $ref: '#/components/examples/table'
*/
router.post("/tables", controller.create)
/**
* @openapi
* /tables/:tableId:
* put:
* summary: Update a single row within a specified table.
* tags:
* - tables
* parameters:
* - $ref: '#/components/parameters/tableId'
* - $ref: '#/components/parameters/rowId'
* responses:
* 200:
* description: Returns the created row, including the ID which has been generated for it.
* content:
* application/json:
* schema:
* type: object
* examples:
* row:
* $ref: '#/components/examples/row'
*/
router.put("/tables/:tableId", controller.update)
/**
* @openapi
* /tables:
* get:
* summary: Update a single row within a specified table.
* tags:
* - tables
* parameters:
* - $ref: '#/components/parameters/tableId'
* - $ref: '#/components/parameters/rowId'
* responses:
* 200:
* description: Returns the created row, including the ID which has been generated for it.
* content:
* application/json:
* schema:
* type: object
* examples:
* row:
* $ref: '#/components/examples/row'
*/
router.get("/tables", controller.getAllTables)
/**
* @openapi
* /tables/{tableId}/rows/{rowId}:
* put:
* summary: Update a single row within a specified table.
* tags:
* - rows
* parameters:
* - $ref: '#/components/parameters/tableId'
* - $ref: '#/components/parameters/rowId'
* responses:
* 200:
* description: Returns the created row, including the ID which has been generated for it.
* content:
* application/json:
* schema:
* type: object
* examples:
* row:
* $ref: '#/components/examples/row'
*/
router.get("/tables/:tableId", controller.getSingleTable)
/**
* @openapi
* /tables/{tableId}/rows/{rowId}:
* put:
* summary: Update a single row within a specified table.
* tags:
* - rows
* parameters:
* - $ref: '#/components/parameters/tableId'
* - $ref: '#/components/parameters/rowId'
* responses:
* 200:
* description: Returns the created row, including the ID which has been generated for it.
* content:
* application/json:
* schema:
* type: object
* examples:
* row:
* $ref: '#/components/examples/row'
*/
router.delete("/tables/:tableId", controller.delete)
module.exports = router module.exports = router