From 42b59ad2d6e10b6110948aee0a88418eb5dcd94c Mon Sep 17 00:00:00 2001 From: Rory& Date: Sun, 1 Jun 2025 15:42:18 +0200 Subject: Rewrite routing --- src/api/RouteDescription.js | 74 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/api/RouteDescription.js (limited to 'src/api/RouteDescription.js') diff --git a/src/api/RouteDescription.js b/src/api/RouteDescription.js new file mode 100644 index 0000000..6ca426b --- /dev/null +++ b/src/api/RouteDescription.js @@ -0,0 +1,74 @@ +export class RouteDescription { + path; + /** + * @type {RouteMethodList} + */ + methods; + + /** + * @param data {RouteDescription} + */ + constructor(data) { + for (const key of Object.keys(data)) { + this[key] = data[key]; + } + } +} + +export class RouteMethodList { + /** + * @type {RouteMethod} + */ + get; + /** + * @type {RouteMethod} + */ + post; + /** + * @type {RouteMethod} + */ + put; + /** + * @type {RouteMethod} + */ + delete; + /** + * @type {RouteMethod} + */ + patch; + + /** + * @param data {RouteMethodList} + */ + constructor(data) { + for (const key of Object.keys(data)) { + this[key] = data[key]; + } + } +} + +export class RouteMethod { + /** + * @type {Array} + */ + middlewares = []; + /** + * @type {Promise} + */ + method; + + description; + + exampleBody; + + /** + * @param data {RouteMethod} + */ + constructor(data) { + for (const key of Object.keys(data)) { + this[key] = data[key]; + } + + if (!Array.isArray(this.middlewares)) this.middlewares = []; + } +} -- cgit 1.5.1