@arkstack/driver-express 0.4.3 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.js +2 -4
- package/dist/index.js.map +1 -1
- package/dist/middlewares/index.d.ts +5 -1
- package/dist/middlewares/index.js +6 -4
- package/dist/middlewares/index.js.map +1 -1
- package/package.json +10 -8
- package/stubs/controller.api.resource.stub +15 -46
- package/stubs/controller.api.stub +15 -45
- package/stubs/controller.model.stub +26 -57
- package/stubs/controller.stub +2 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/middlewares/index.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @arkstack/driver-express
|
|
2
2
|
|
|
3
|
-
Express driver
|
|
3
|
+
Express driver for Arkstack, providing Express-based runtime integration for the framework.
|
|
4
4
|
|
|
5
5
|
## Auth Middleware
|
|
6
6
|
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,6 @@ import { Router as Router$2 } from "clear-router/express";
|
|
|
5
5
|
import { clearRouterExpressPlugin } from "@resora/plugin-clear-router";
|
|
6
6
|
import { join } from "node:path";
|
|
7
7
|
import { registerPlugin } from "resora";
|
|
8
|
-
|
|
9
8
|
//#region src/error-handler.ts
|
|
10
9
|
const defaultErrorHandler = (err, req, res, next) => {
|
|
11
10
|
const responseBody = ErrorHandler.createErrorPayload(err);
|
|
@@ -31,10 +30,10 @@ const defaultErrorHandler = (err, req, res, next) => {
|
|
|
31
30
|
code
|
|
32
31
|
}));
|
|
33
32
|
};
|
|
34
|
-
|
|
35
33
|
//#endregion
|
|
36
34
|
//#region src/Router.ts
|
|
37
35
|
registerPlugin(clearRouterExpressPlugin);
|
|
36
|
+
Router$2.configure({ inferParamName: true });
|
|
38
37
|
var Router = class extends Router$2 {
|
|
39
38
|
static async bind() {
|
|
40
39
|
const router = express.Router();
|
|
@@ -56,7 +55,6 @@ var Router = class extends Router$2 {
|
|
|
56
55
|
return this.allRoutes();
|
|
57
56
|
}
|
|
58
57
|
};
|
|
59
|
-
|
|
60
58
|
//#endregion
|
|
61
59
|
//#region src/index.ts
|
|
62
60
|
/**
|
|
@@ -149,7 +147,7 @@ var ExpressDriver = class extends ArkstackKitDriver {
|
|
|
149
147
|
});
|
|
150
148
|
}
|
|
151
149
|
};
|
|
152
|
-
|
|
153
150
|
//#endregion
|
|
154
151
|
export { ExpressDriver, Router, defaultErrorHandler };
|
|
152
|
+
|
|
155
153
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["ClearRouter"],"sources":["../src/error-handler.ts","../src/Router.ts","../src/index.ts"],"sourcesContent":["import {\n ErrorHandler,\n renderError,\n} from '@arkstack/common'\n\nimport type { ErrorRequestHandler } from 'express'\n\nexport const defaultErrorHandler: ErrorRequestHandler = (err, req, res, next) => {\n const responseBody = ErrorHandler.createErrorPayload(err)\n\n if (ErrorHandler.shouldLogError(err)) {\n ErrorHandler.logUnhandledError(err, {\n headers: req.headers,\n method: req.method,\n url: req.originalUrl || req.url,\n }, 'Unhandled Express request error')\n }\n\n if (process.env.NODE_ENV === 'development') console.error(responseBody)\n\n if (res.headersSent) {\n next(err)\n\n return\n }\n\n const acceptsHeader = Array.isArray(req.headers.accept) ? req.headers.accept.join(',') : req.headers.accept ?? ''\n const expectsJson = acceptsHeader.includes('application/json') || req.originalUrl.startsWith('/api/')\n const code = ErrorHandler.normalizeStatusCode(responseBody.code)\n\n if (expectsJson) {\n res.status(code).json(responseBody)\n\n return\n }\n\n res.status(code).setHeader('Content-Type', 'text/html').send(renderError({\n message: String(responseBody.message),\n stack: typeof responseBody.stack === 'string' ? responseBody.stack : undefined,\n code,\n }))\n}\n\nexport default defaultErrorHandler\n","import { RequestException, importFile } from '@arkstack/common'\nimport express, { Router as ExpressRouter } from 'express'\n\nimport { ArkstackRouteListOptions } from '@arkstack/contract'\nimport { Router as ClearRouter } from 'clear-router/express'\nimport { type Route } from 'clear-router'\nimport { clearRouterExpressPlugin } from '@resora/plugin-clear-router'\nimport { join } from 'node:path'\nimport { registerPlugin } from 'resora'\nimport type { Handler, HttpContext, Middleware } from 'clear-router/types/express'\n\nregisterPlugin(clearRouterExpressPlugin)\n\nexport class Router extends ClearRouter {\n static async bind (): Promise<ExpressRouter> {\n const router = express.Router()\n\n // Register API routes\n await ClearRouter.group('/api', async () => {\n await importFile(join(process.cwd(), 'src/routes/api.ts'))\n })\n\n // Register web routes\n await ClearRouter.group('/', async () => {\n await importFile(join(process.cwd(), 'src/routes/web.ts'))\n })\n\n // Apply the registered routes to the Express application\n ClearRouter.apply(router)\n\n // Handle unmatched routes\n router.all('/*splat', (req, _res, next) => {\n const url = req.originalUrl || req.url\n next(new RequestException(`Cannot find any route matching [${req.method}] ${url}`, 404))\n })\n\n return router\n }\n\n static async list (\n _options: ArkstackRouteListOptions = {}\n ): Promise<Array<Route<HttpContext, Middleware, Handler>>> {\n await this.bind()\n\n return this.allRoutes()\n }\n}\n","import express, { type ErrorRequestHandler, type Express, type Handler } from 'express'\n\nimport { ArkstackKitDriver, ArkstackMiddlewareConfig, PromiseOrValue } from '@arkstack/contract'\nimport { Logger } from '@arkstack/common'\nimport { defaultErrorHandler } from './error-handler'\n\nexport interface ExpressDriverOptions {\n bindRouter: (app: Express) => PromiseOrValue<void>;\n mountPublicAssets?: (app: Express, publicPath: string) => PromiseOrValue<void>;\n errorHandler?: ErrorRequestHandler | Handler;\n}\n\n/**\n * The ExpressDriver class implements the ArkstackKitDriver \n * contract for the Express framework.\n */\nexport class ExpressDriver extends ArkstackKitDriver<Express, Handler> {\n readonly name = 'express'\n private readonly options: ExpressDriverOptions\n\n /**\n * Creates an instance of ExpressDriver.\n * \n * @param options \n */\n constructor(options: ExpressDriverOptions) {\n super()\n this.options = options\n }\n\n /**\n * Creates an Express application instance.\n * \n * @returns \n */\n createApp (): Express {\n return express()\n }\n\n /**\n * Mounts static assets from the specified public path to the Express application.\n * \n * @param app \n * @param publicPath \n */\n mountPublicAssets (app: Express, publicPath: string): PromiseOrValue<void> {\n if (this.options.mountPublicAssets) {\n return this.options.mountPublicAssets(app, publicPath)\n }\n\n app.use(express.static(publicPath, {\n maxAge: '1y',\n immutable: true,\n setHeaders: (res) => {\n res.setHeader('Access-Control-Allow-Origin', '*')\n res.setHeader('Access-Control-Allow-Methods', 'GET, HEAD, OPTIONS')\n res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization')\n },\n }))\n }\n\n /**\n * Binds the router to the Express application using the provided bindRouter function.\n * \n * @param app \n */\n bindRouter (app: Express): PromiseOrValue<void> {\n return this.options.bindRouter(app)\n }\n\n /**\n * Applies middleware to the Express application.\n * \n * @param app \n * @param middleware \n */\n applyMiddleware (\n app: Express,\n middleware: Handler | ArkstackMiddlewareConfig<Handler>,\n ): void {\n if (typeof middleware === 'function') {\n app.use(middleware)\n\n return\n }\n\n for (const [pos, entries] of Object.entries(middleware) as [string, Handler[]][]) {\n for (const entry of entries) {\n if (pos === 'after') {\n app.use(async (req, res, next) => {\n res.once('finish', async () => {\n await entry(req, res, next)\n })\n next()\n })\n } else {\n app.use(entry)\n }\n }\n }\n }\n\n /**\n * Registers an error handler middleware to the Express \n * application if provided in the options.\n * \n * @param app \n */\n registerErrorHandler (app: Express): void {\n app.use((this.options.errorHandler ?? defaultErrorHandler) as ErrorRequestHandler)\n }\n\n /**\n * Starts the Express server on the specified port.\n * \n * @param app \n * @param port \n */\n start (app: Express, port: number): void {\n app.listen(port, () => {\n Logger.log([\n ['Server is running on', 'white'],\n [`http://localhost:${port}`, 'cyan']\n ], ' ')\n })\n }\n}\n\nexport * from './error-handler'\nexport * from './Router'\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["ClearRouter"],"sources":["../src/error-handler.ts","../src/Router.ts","../src/index.ts"],"sourcesContent":["import {\n ErrorHandler,\n renderError,\n} from '@arkstack/common'\n\nimport type { ErrorRequestHandler } from 'express'\n\nexport const defaultErrorHandler: ErrorRequestHandler = (err, req, res, next) => {\n const responseBody = ErrorHandler.createErrorPayload(err)\n\n if (ErrorHandler.shouldLogError(err)) {\n ErrorHandler.logUnhandledError(err, {\n headers: req.headers,\n method: req.method,\n url: req.originalUrl || req.url,\n }, 'Unhandled Express request error')\n }\n\n if (process.env.NODE_ENV === 'development') console.error(responseBody)\n\n if (res.headersSent) {\n next(err)\n\n return\n }\n\n const acceptsHeader = Array.isArray(req.headers.accept) ? req.headers.accept.join(',') : req.headers.accept ?? ''\n const expectsJson = acceptsHeader.includes('application/json') || req.originalUrl.startsWith('/api/')\n const code = ErrorHandler.normalizeStatusCode(responseBody.code)\n\n if (expectsJson) {\n res.status(code).json(responseBody)\n\n return\n }\n\n res.status(code).setHeader('Content-Type', 'text/html').send(renderError({\n message: String(responseBody.message),\n stack: typeof responseBody.stack === 'string' ? responseBody.stack : undefined,\n code,\n }))\n}\n\nexport default defaultErrorHandler\n","import { RequestException, importFile } from '@arkstack/common'\nimport express, { Router as ExpressRouter } from 'express'\n\nimport { ArkstackRouteListOptions } from '@arkstack/contract'\nimport { Router as ClearRouter } from 'clear-router/express'\nimport { type Route } from 'clear-router'\nimport { clearRouterExpressPlugin } from '@resora/plugin-clear-router'\nimport { join } from 'node:path'\nimport { registerPlugin } from 'resora'\nimport type { Handler, HttpContext, Middleware } from 'clear-router/types/express'\n\nregisterPlugin(clearRouterExpressPlugin)\nClearRouter.configure({\n inferParamName: true\n})\n\nexport class Router extends ClearRouter {\n static async bind (): Promise<ExpressRouter> {\n const router = express.Router()\n\n // Register API routes\n await ClearRouter.group('/api', async () => {\n await importFile(join(process.cwd(), 'src/routes/api.ts'))\n })\n\n // Register web routes\n await ClearRouter.group('/', async () => {\n await importFile(join(process.cwd(), 'src/routes/web.ts'))\n })\n\n // Apply the registered routes to the Express application\n ClearRouter.apply(router)\n\n // Handle unmatched routes\n router.all('/*splat', (req, _res, next) => {\n const url = req.originalUrl || req.url\n next(new RequestException(`Cannot find any route matching [${req.method}] ${url}`, 404))\n })\n\n return router\n }\n\n static async list (\n _options: ArkstackRouteListOptions = {}\n ): Promise<Array<Route<HttpContext, Middleware, Handler>>> {\n await this.bind()\n\n return this.allRoutes() as never\n }\n}\n","import express, { type ErrorRequestHandler, type Express, type Handler } from 'express'\n\nimport { ArkstackKitDriver, ArkstackMiddlewareConfig, PromiseOrValue } from '@arkstack/contract'\nimport { Logger } from '@arkstack/common'\nimport { defaultErrorHandler } from './error-handler'\n\nexport interface ExpressDriverOptions {\n bindRouter: (app: Express) => PromiseOrValue<void>;\n mountPublicAssets?: (app: Express, publicPath: string) => PromiseOrValue<void>;\n errorHandler?: ErrorRequestHandler | Handler;\n}\n\n/**\n * The ExpressDriver class implements the ArkstackKitDriver \n * contract for the Express framework.\n */\nexport class ExpressDriver extends ArkstackKitDriver<Express, Handler> {\n readonly name = 'express'\n private readonly options: ExpressDriverOptions\n\n /**\n * Creates an instance of ExpressDriver.\n * \n * @param options \n */\n constructor(options: ExpressDriverOptions) {\n super()\n this.options = options\n }\n\n /**\n * Creates an Express application instance.\n * \n * @returns \n */\n createApp (): Express {\n return express()\n }\n\n /**\n * Mounts static assets from the specified public path to the Express application.\n * \n * @param app \n * @param publicPath \n */\n mountPublicAssets (app: Express, publicPath: string): PromiseOrValue<void> {\n if (this.options.mountPublicAssets) {\n return this.options.mountPublicAssets(app, publicPath)\n }\n\n app.use(express.static(publicPath, {\n maxAge: '1y',\n immutable: true,\n setHeaders: (res) => {\n res.setHeader('Access-Control-Allow-Origin', '*')\n res.setHeader('Access-Control-Allow-Methods', 'GET, HEAD, OPTIONS')\n res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization')\n },\n }))\n }\n\n /**\n * Binds the router to the Express application using the provided bindRouter function.\n * \n * @param app \n */\n bindRouter (app: Express): PromiseOrValue<void> {\n return this.options.bindRouter(app)\n }\n\n /**\n * Applies middleware to the Express application.\n * \n * @param app \n * @param middleware \n */\n applyMiddleware (\n app: Express,\n middleware: Handler | ArkstackMiddlewareConfig<Handler>,\n ): void {\n if (typeof middleware === 'function') {\n app.use(middleware)\n\n return\n }\n\n for (const [pos, entries] of Object.entries(middleware) as [string, Handler[]][]) {\n for (const entry of entries) {\n if (pos === 'after') {\n app.use(async (req, res, next) => {\n res.once('finish', async () => {\n await entry(req, res, next)\n })\n next()\n })\n } else {\n app.use(entry)\n }\n }\n }\n }\n\n /**\n * Registers an error handler middleware to the Express \n * application if provided in the options.\n * \n * @param app \n */\n registerErrorHandler (app: Express): void {\n app.use((this.options.errorHandler ?? defaultErrorHandler) as ErrorRequestHandler)\n }\n\n /**\n * Starts the Express server on the specified port.\n * \n * @param app \n * @param port \n */\n start (app: Express, port: number): void {\n app.listen(port, () => {\n Logger.log([\n ['Server is running on', 'white'],\n [`http://localhost:${port}`, 'cyan']\n ], ' ')\n })\n }\n}\n\nexport * from './error-handler'\nexport * from './Router'\n"],"mappings":"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"}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { Handler, NextFunction, Request, Response } from "express";
|
|
2
|
+
import multer from "multer";
|
|
2
3
|
|
|
3
4
|
//#region src/middlewares/auth.d.ts
|
|
4
5
|
declare const auth: Handler;
|
|
5
6
|
//#endregion
|
|
7
|
+
//#region src/middlewares/formdata.d.ts
|
|
8
|
+
declare const formdata: multer.Multer;
|
|
9
|
+
//#endregion
|
|
6
10
|
//#region src/middlewares/request-logger.d.ts
|
|
7
11
|
declare const requestLogger: ({
|
|
8
12
|
allowInProduction
|
|
@@ -10,5 +14,5 @@ declare const requestLogger: ({
|
|
|
10
14
|
allowInProduction?: boolean;
|
|
11
15
|
}) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
12
16
|
//#endregion
|
|
13
|
-
export { auth, requestLogger };
|
|
17
|
+
export { auth, formdata, requestLogger };
|
|
14
18
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Hook, Logger, nodeEnv } from "@arkstack/common";
|
|
2
2
|
import { Auth, AuthenticationException } from "@arkstack/auth";
|
|
3
|
-
|
|
3
|
+
import multer from "multer";
|
|
4
4
|
//#region src/middlewares/auth.ts
|
|
5
5
|
const auth = async (req, res, next) => {
|
|
6
6
|
try {
|
|
@@ -37,7 +37,9 @@ const readBearerToken = (authorization) => {
|
|
|
37
37
|
if (!value?.startsWith("Bearer ")) return null;
|
|
38
38
|
return value.substring(7);
|
|
39
39
|
};
|
|
40
|
-
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/middlewares/formdata.ts
|
|
42
|
+
const formdata = multer({ storage: multer.memoryStorage() });
|
|
41
43
|
//#endregion
|
|
42
44
|
//#region src/middlewares/request-logger.ts
|
|
43
45
|
const colors = {
|
|
@@ -67,7 +69,7 @@ const requestLogger = ({ allowInProduction = false } = {}) => async (req, res, n
|
|
|
67
69
|
], " ");
|
|
68
70
|
next();
|
|
69
71
|
};
|
|
70
|
-
|
|
71
72
|
//#endregion
|
|
72
|
-
export { auth, requestLogger };
|
|
73
|
+
export { auth, formdata, requestLogger };
|
|
74
|
+
|
|
73
75
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/middlewares/auth.ts","../../src/middlewares/request-logger.ts"],"sourcesContent":["import { Auth, AuthenticationException } from '@arkstack/auth'\n\nimport type { Handler } from 'express'\nimport { Hook } from '@arkstack/common'\n\nexport const auth: Handler = async (req, res, next) => {\n try {\n if (Hook.has('middleware:auth', 'before'))\n Hook.get('middleware:auth', 'before')?.({ req, res })\n\n const token = readBearerToken(req.headers.authorization)\n\n if (!token) {\n throw new AuthenticationException('Unauthenticated', { req, status: 401 })\n }\n\n const auth = Auth.make().setRequest(req)\n const user = await Auth.make().setRequest(req).authorizeToken(token)\n\n req.user = user\n req.auth = auth\n req.authUser = user\n req.authToken = token\n\n if (Hook.has('middleware:auth', 'after'))\n Hook.get('middleware:auth', 'after')?.({ req, res })\n\n next()\n } catch (error) {\n if (Hook.has('middleware:auth', 'error'))\n Hook.get('middleware:auth', 'error')?.(error, { req, res })\n\n next(error)\n }\n}\n\nconst readBearerToken = (authorization: string | string[] | undefined) => {\n const value = Array.isArray(authorization) ? authorization[0] : authorization\n\n if (!value?.startsWith('Bearer ')) {\n return null\n }\n\n return value.substring(7)\n}\n","import { Logger, nodeEnv } from '@arkstack/common'\nimport { NextFunction, Request, Response } from 'express'\n\nconst colors: Record<string, 'green' | 'blue' | 'yellow' | 'red' | 'cyan'> = {\n GET: 'green',\n POST: 'blue',\n PUT: 'yellow',\n DELETE: 'red',\n PATCH: 'cyan',\n}\n\n/**\n * Middleware to log incoming requests and their response times.\n * \n * @param config Configuration options for the request logger middleware.\n * @param config.allowInProduction If true, the logger will also log requests in production environment. Default is false. \n * @returns \n */\nexport const requestLogger = ({\n allowInProduction = false,\n}: {\n allowInProduction?: boolean\n} = {}) => async (req: Request, res: Response, next: NextFunction) => {\n if (nodeEnv() === 'prod' && !allowInProduction) return next()\n\n const start = Date.now()\n\n const status = res.statusCode || 200\n const duration = Date.now() - start\n Logger.log([\n [`[${req.method}]`, colors[req.method] || 'white'],\n [req.url, 'cyan'],\n [status.toString(), status >= 500 ? 'red' : status >= 400 ? 'yellow' : 'green'],\n [`- ${duration}ms`, 'dim']\n ], ' ')\n\n next()\n}"],"mappings":";;;;AAKA,MAAa,OAAgB,OAAO,KAAK,KAAK,SAAS;
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/middlewares/auth.ts","../../src/middlewares/formdata.ts","../../src/middlewares/request-logger.ts"],"sourcesContent":["import { Auth, AuthenticationException } from '@arkstack/auth'\n\nimport type { Handler } from 'express'\nimport { Hook } from '@arkstack/common'\n\nexport const auth: Handler = async (req, res, next) => {\n try {\n if (Hook.has('middleware:auth', 'before'))\n Hook.get('middleware:auth', 'before')?.({ req, res })\n\n const token = readBearerToken(req.headers.authorization)\n\n if (!token) {\n throw new AuthenticationException('Unauthenticated', { req, status: 401 })\n }\n\n const auth = Auth.make().setRequest(req)\n const user = await Auth.make().setRequest(req).authorizeToken(token)\n\n req.user = user\n req.auth = auth\n req.authUser = user\n req.authToken = token\n\n if (Hook.has('middleware:auth', 'after'))\n Hook.get('middleware:auth', 'after')?.({ req, res })\n\n next()\n } catch (error) {\n if (Hook.has('middleware:auth', 'error'))\n Hook.get('middleware:auth', 'error')?.(error, { req, res })\n\n next(error)\n }\n}\n\nconst readBearerToken = (authorization: string | string[] | undefined) => {\n const value = Array.isArray(authorization) ? authorization[0] : authorization\n\n if (!value?.startsWith('Bearer ')) {\n return null\n }\n\n return value.substring(7)\n}\n","import multer from 'multer'\n\nexport const formdata = multer({ storage: multer.memoryStorage() })","import { Logger, nodeEnv } from '@arkstack/common'\nimport { NextFunction, Request, Response } from 'express'\n\nconst colors: Record<string, 'green' | 'blue' | 'yellow' | 'red' | 'cyan'> = {\n GET: 'green',\n POST: 'blue',\n PUT: 'yellow',\n DELETE: 'red',\n PATCH: 'cyan',\n}\n\n/**\n * Middleware to log incoming requests and their response times.\n * \n * @param config Configuration options for the request logger middleware.\n * @param config.allowInProduction If true, the logger will also log requests in production environment. Default is false. \n * @returns \n */\nexport const requestLogger = ({\n allowInProduction = false,\n}: {\n allowInProduction?: boolean\n} = {}) => async (req: Request, res: Response, next: NextFunction) => {\n if (nodeEnv() === 'prod' && !allowInProduction) return next()\n\n const start = Date.now()\n\n const status = res.statusCode || 200\n const duration = Date.now() - start\n Logger.log([\n [`[${req.method}]`, colors[req.method] || 'white'],\n [req.url, 'cyan'],\n [status.toString(), status >= 500 ? 'red' : status >= 400 ? 'yellow' : 'green'],\n [`- ${duration}ms`, 'dim']\n ], ' ')\n\n next()\n}"],"mappings":";;;;AAKA,MAAa,OAAgB,OAAO,KAAK,KAAK,SAAS;CACnD,IAAI;EACA,IAAI,KAAK,IAAI,mBAAmB,SAAS,EACrC,KAAK,IAAI,mBAAmB,SAAS,GAAG;GAAE;GAAK;GAAK,CAAC;EAEzD,MAAM,QAAQ,gBAAgB,IAAI,QAAQ,cAAc;EAExD,IAAI,CAAC,OACD,MAAM,IAAI,wBAAwB,mBAAmB;GAAE;GAAK,QAAQ;GAAK,CAAC;EAG9E,MAAM,OAAO,KAAK,MAAM,CAAC,WAAW,IAAI;EACxC,MAAM,OAAO,MAAM,KAAK,MAAM,CAAC,WAAW,IAAI,CAAC,eAAe,MAAM;EAEpE,IAAI,OAAO;EACX,IAAI,OAAO;EACX,IAAI,WAAW;EACf,IAAI,YAAY;EAEhB,IAAI,KAAK,IAAI,mBAAmB,QAAQ,EACpC,KAAK,IAAI,mBAAmB,QAAQ,GAAG;GAAE;GAAK;GAAK,CAAC;EAExD,MAAM;UACD,OAAO;EACZ,IAAI,KAAK,IAAI,mBAAmB,QAAQ,EACpC,KAAK,IAAI,mBAAmB,QAAQ,GAAG,OAAO;GAAE;GAAK;GAAK,CAAC;EAE/D,KAAK,MAAM;;;AAInB,MAAM,mBAAmB,kBAAiD;CACtE,MAAM,QAAQ,MAAM,QAAQ,cAAc,GAAG,cAAc,KAAK;CAEhE,IAAI,CAAC,OAAO,WAAW,UAAU,EAC7B,OAAO;CAGX,OAAO,MAAM,UAAU,EAAE;;;;ACzC7B,MAAa,WAAW,OAAO,EAAE,SAAS,OAAO,eAAe,EAAE,CAAA;;;ACClE,MAAM,SAAuE;CACzE,KAAK;CACL,MAAM;CACN,KAAK;CACL,QAAQ;CACR,OAAO;CACV;;;;;;;;AASD,MAAa,iBAAiB,EAC1B,oBAAoB,UAGpB,EAAE,KAAK,OAAO,KAAc,KAAe,SAAuB;CAClE,IAAI,SAAS,KAAK,UAAU,CAAC,mBAAmB,OAAO,MAAM;CAE7D,MAAM,QAAQ,KAAK,KAAK;CAExB,MAAM,SAAS,IAAI,cAAc;CACjC,MAAM,WAAW,KAAK,KAAK,GAAG;CAC9B,OAAO,IAAI;EACP,CAAC,IAAI,IAAI,OAAO,IAAI,OAAO,IAAI,WAAW,QAAQ;EAClD,CAAC,IAAI,KAAK,OAAO;EACjB,CAAC,OAAO,UAAU,EAAE,UAAU,MAAM,QAAQ,UAAU,MAAM,WAAW,QAAQ;EAC/E,CAAC,KAAK,SAAS,KAAK,MAAM;EAC7B,EAAE,IAAI;CAEP,MAAM"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkstack/driver-express",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "Express driver
|
|
5
|
+
"description": "Express driver for Arkstack, providing Express-based runtime integration for the framework.",
|
|
6
6
|
"homepage": "https://arkstack.toneflix.net",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -36,16 +36,17 @@
|
|
|
36
36
|
"./package.json": "./package.json"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"
|
|
39
|
+
"multer": "^2.1.1",
|
|
40
|
+
"clear-router": "^2.6.4",
|
|
40
41
|
"express-rate-limit": "^8.4.1",
|
|
41
|
-
"@resora/plugin-clear-router": "^1.0.
|
|
42
|
-
"resora": "^1.2.
|
|
43
|
-
"@arkstack/contract": "^0.
|
|
42
|
+
"@resora/plugin-clear-router": "^1.0.14",
|
|
43
|
+
"resora": "^1.2.4",
|
|
44
|
+
"@arkstack/contract": "^0.5.1"
|
|
44
45
|
},
|
|
45
46
|
"peerDependencies": {
|
|
46
47
|
"express": "^5.2.1",
|
|
47
|
-
"@arkstack/auth": "^0.
|
|
48
|
-
"@arkstack/common": "^0.
|
|
48
|
+
"@arkstack/auth": "^0.5.1",
|
|
49
|
+
"@arkstack/common": "^0.5.1"
|
|
49
50
|
},
|
|
50
51
|
"peerDependenciesMeta": {
|
|
51
52
|
"@arkstack/auth": {
|
|
@@ -53,6 +54,7 @@
|
|
|
53
54
|
}
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
|
57
|
+
"@types/multer": "^2.1.0",
|
|
56
58
|
"@types/express": "^5.0.6"
|
|
57
59
|
},
|
|
58
60
|
"scripts": {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { BaseController } from '@controllers/BaseController'
|
|
2
|
-
import { HttpContext } from 'clear-router/types/express'
|
|
3
2
|
import {{ResourceName}} from '@app/http/resources/{{ResourceName}}'
|
|
4
3
|
import {{CollectionResourceName}} from '@app/http/resources/{{CollectionResourceName}}'
|
|
5
4
|
|
|
@@ -11,86 +10,56 @@ import { Resource, ResourceCollection } from 'resora'
|
|
|
11
10
|
export default class {{ControllerName}} extends BaseController {
|
|
12
11
|
/**
|
|
13
12
|
* Get all resources
|
|
14
|
-
*
|
|
15
|
-
* @param req
|
|
16
|
-
* @param res
|
|
17
13
|
*/
|
|
18
|
-
index
|
|
19
|
-
return await new
|
|
20
|
-
.additional({
|
|
14
|
+
async index () {
|
|
15
|
+
return await new {{CollectionResourceName}}([]).additional({
|
|
21
16
|
status: 'success',
|
|
22
17
|
message: 'OK',
|
|
23
18
|
code: 200,
|
|
24
|
-
})
|
|
25
|
-
.response()
|
|
26
|
-
.setStatusCode(200)
|
|
19
|
+
}).response().setStatusCode(200)
|
|
27
20
|
}
|
|
28
21
|
|
|
29
22
|
/**
|
|
30
23
|
* Get a specific resource
|
|
31
|
-
*
|
|
32
|
-
* @param req
|
|
33
|
-
* @param res
|
|
34
24
|
*/
|
|
35
|
-
show
|
|
36
|
-
return new
|
|
37
|
-
.additional({
|
|
25
|
+
async show () {
|
|
26
|
+
return new {{ResourceName}}({}).additional({
|
|
38
27
|
status: 'success',
|
|
39
28
|
message: 'OK',
|
|
40
29
|
code: 200,
|
|
41
|
-
})
|
|
42
|
-
.response()
|
|
43
|
-
.setStatusCode(200)
|
|
30
|
+
}).response().setStatusCode(200)
|
|
44
31
|
}
|
|
45
32
|
|
|
46
33
|
/**
|
|
47
34
|
* Create a resource
|
|
48
|
-
*
|
|
49
|
-
* @param req
|
|
50
|
-
* @param res
|
|
51
35
|
*/
|
|
52
|
-
create
|
|
53
|
-
return new
|
|
54
|
-
.additional({
|
|
36
|
+
async create () {
|
|
37
|
+
return new {{ResourceName}}({}).additional({
|
|
55
38
|
status: 'success',
|
|
56
39
|
message: 'New {{Name}} created successfully',
|
|
57
40
|
code: 201,
|
|
58
|
-
})
|
|
59
|
-
.response()
|
|
60
|
-
.setStatusCode(201)
|
|
41
|
+
}).response().setStatusCode(201)
|
|
61
42
|
}
|
|
62
43
|
|
|
63
44
|
/**
|
|
64
45
|
* Update a specific resource
|
|
65
|
-
*
|
|
66
|
-
* @param req
|
|
67
|
-
* @param res
|
|
68
46
|
*/
|
|
69
|
-
update
|
|
70
|
-
return new
|
|
71
|
-
.additional({
|
|
47
|
+
async update () {
|
|
48
|
+
return new {{ResourceName}}({}).additional({
|
|
72
49
|
status: 'success',
|
|
73
50
|
message: '{{Name}} updated successfully',
|
|
74
51
|
code: 202,
|
|
75
|
-
})
|
|
76
|
-
.response()
|
|
77
|
-
.setStatusCode(202)
|
|
52
|
+
}).response().setStatusCode(202)
|
|
78
53
|
}
|
|
79
54
|
|
|
80
55
|
/**
|
|
81
56
|
* Delete a specific resource
|
|
82
|
-
*
|
|
83
|
-
* @param req
|
|
84
|
-
* @param res
|
|
85
57
|
*/
|
|
86
|
-
destroy
|
|
87
|
-
return new
|
|
88
|
-
.additional({
|
|
58
|
+
async destroy () {
|
|
59
|
+
return new {{ResourceName}}({}).additional({
|
|
89
60
|
status: 'success',
|
|
90
61
|
message: '{{Name}} deleted successfully',
|
|
91
62
|
code: 202,
|
|
92
|
-
})
|
|
93
|
-
.response()
|
|
94
|
-
.setStatusCode(202)
|
|
63
|
+
}).response().setStatusCode(202)
|
|
95
64
|
}
|
|
96
65
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { BaseController } from '@controllers/BaseController'
|
|
2
|
-
import { HttpContext } from 'clear-router/types/express'
|
|
3
2
|
import { Resource, ResourceCollection } from 'resora'
|
|
4
3
|
|
|
5
4
|
/**
|
|
@@ -8,85 +7,56 @@ import { Resource, ResourceCollection } from 'resora'
|
|
|
8
7
|
export default class {{ControllerName}} extends BaseController {
|
|
9
8
|
/**
|
|
10
9
|
* Get all resources
|
|
11
|
-
*
|
|
12
|
-
* @param req
|
|
13
|
-
* @param res
|
|
14
10
|
*/
|
|
15
|
-
index
|
|
16
|
-
return new ResourceCollection({ data: [] }
|
|
17
|
-
.additional({
|
|
11
|
+
async index () {
|
|
12
|
+
return new ResourceCollection({ data: [] }).additional({
|
|
18
13
|
status: 'success',
|
|
19
14
|
message: 'OK',
|
|
20
15
|
code: 200,
|
|
21
|
-
})
|
|
22
|
-
.response()
|
|
23
|
-
.setStatusCode(200)
|
|
16
|
+
}).response().setStatusCode(200)
|
|
24
17
|
}
|
|
25
18
|
|
|
26
19
|
/**
|
|
27
20
|
* Get a specific resource
|
|
28
|
-
*
|
|
29
|
-
* @param req
|
|
30
|
-
* @param res
|
|
31
21
|
*/
|
|
32
|
-
show
|
|
33
|
-
return new Resource({ data: {} }
|
|
34
|
-
.additional({
|
|
22
|
+
async show () {
|
|
23
|
+
return new Resource({ data: {} }).additional({
|
|
35
24
|
status: 'success',
|
|
36
25
|
message: 'OK',
|
|
37
26
|
code: 200,
|
|
38
|
-
})
|
|
39
|
-
.response()
|
|
40
|
-
.setStatusCode(200)
|
|
27
|
+
}).response().setStatusCode(200)
|
|
41
28
|
}
|
|
42
29
|
|
|
43
30
|
/**
|
|
44
31
|
* Create a resource
|
|
45
|
-
*
|
|
46
|
-
* @param req
|
|
47
|
-
* @param res
|
|
48
32
|
*/
|
|
49
|
-
create
|
|
50
|
-
return new Resource({ data: {} }
|
|
51
|
-
.additional({
|
|
33
|
+
async create () {
|
|
34
|
+
return new Resource({ data: {} }).additional({
|
|
52
35
|
status: 'success',
|
|
53
36
|
message: 'New {{Name}} created successfully',
|
|
54
37
|
code: 201,
|
|
55
|
-
})
|
|
56
|
-
.response()
|
|
57
|
-
.setStatusCode(201)
|
|
38
|
+
}).response().setStatusCode(201)
|
|
58
39
|
}
|
|
59
40
|
|
|
60
41
|
/**
|
|
61
42
|
* Update a specific resource
|
|
62
|
-
*
|
|
63
|
-
* @param req
|
|
64
|
-
* @param res
|
|
65
43
|
*/
|
|
66
|
-
update
|
|
67
|
-
return new Resource({ data: {} }
|
|
68
|
-
.additional({
|
|
44
|
+
async update () {
|
|
45
|
+
return new Resource({ data: {} }).additional({
|
|
69
46
|
status: 'success',
|
|
70
47
|
message: '{{Name}} updated successfully',
|
|
71
48
|
code: 202,
|
|
72
|
-
})
|
|
73
|
-
.response()
|
|
74
|
-
.setStatusCode(202)
|
|
49
|
+
}).response().setStatusCode(202)
|
|
75
50
|
}
|
|
76
51
|
|
|
77
52
|
/**
|
|
78
53
|
* Delete a specific resource
|
|
79
|
-
*
|
|
80
|
-
* @param res
|
|
81
54
|
*/
|
|
82
|
-
destroy
|
|
83
|
-
return new Resource({ data: {}
|
|
84
|
-
.additional({
|
|
55
|
+
async destroy () {
|
|
56
|
+
return new Resource({ data: {}} ).additional({
|
|
85
57
|
status: 'success',
|
|
86
58
|
message: '{{Name}} deleted successfully',
|
|
87
59
|
code: 202,
|
|
88
|
-
})
|
|
89
|
-
.response()
|
|
90
|
-
.setStatusCode(202)
|
|
60
|
+
}).response().setStatusCode(202)
|
|
91
61
|
}
|
|
92
62
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { BaseController } from '@controllers/BaseController'
|
|
2
|
-
import {
|
|
2
|
+
import { Bind } from 'clear-router/decorators'
|
|
3
3
|
import { Resource, ResourceCollection } from 'resora'
|
|
4
|
-
import { {{Model}} } from '
|
|
4
|
+
import { {{Model}} } from '@app/models/{{Model}}'
|
|
5
|
+
import { Request } from '@arkstack/http'
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* {{ControllerName}}
|
|
@@ -9,110 +10,78 @@ import { {{Model}} } from 'src/models/{{Model}}'
|
|
|
9
10
|
export default class {{ControllerName}} extends BaseController {
|
|
10
11
|
/**
|
|
11
12
|
* Get all resource from the database
|
|
12
|
-
*
|
|
13
|
-
* @param req
|
|
14
|
-
* @param res
|
|
15
13
|
*/
|
|
16
|
-
index
|
|
17
|
-
return new ResourceCollection({
|
|
18
|
-
data: await {{Model}}.query().orderBy({ id: 'asc' }).get(),
|
|
19
|
-
}, res)
|
|
20
|
-
.additional({
|
|
14
|
+
async index () {
|
|
15
|
+
return new ResourceCollection(await {{Model}}.query().orderBy({ id: 'asc' }).get()).additional({
|
|
21
16
|
status: 'success',
|
|
22
17
|
message: 'OK',
|
|
23
18
|
code: 200,
|
|
24
|
-
})
|
|
25
|
-
.response()
|
|
26
|
-
.setStatusCode(200)
|
|
19
|
+
}).response().setStatusCode(200)
|
|
27
20
|
}
|
|
28
21
|
|
|
29
22
|
/**
|
|
30
23
|
* Get a specific resource from the database
|
|
31
24
|
*
|
|
32
|
-
* @param
|
|
33
|
-
* @param res
|
|
25
|
+
* @param {{Param}}
|
|
34
26
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}, res)
|
|
39
|
-
.additional({
|
|
27
|
+
@Bind()
|
|
28
|
+
async show ({{Param}}: {{Model}}) {
|
|
29
|
+
return new Resource({{Param}}).additional({
|
|
40
30
|
status: 'success',
|
|
41
31
|
message: 'OK',
|
|
42
32
|
code: 200,
|
|
43
|
-
})
|
|
44
|
-
.response()
|
|
45
|
-
.setStatusCode(200)
|
|
33
|
+
}).response().setStatusCode(200)
|
|
46
34
|
}
|
|
47
35
|
|
|
48
36
|
/**
|
|
49
37
|
* Create a new resource in the database
|
|
50
38
|
*
|
|
51
|
-
* The calling route must recieve a multer.RequestHandler instance
|
|
52
|
-
*
|
|
53
|
-
* @example router.post('/{{ModelName}}s', upload.none(), new AdminController().create)
|
|
54
|
-
*
|
|
55
39
|
* @param req
|
|
56
|
-
* @param res
|
|
57
40
|
*/
|
|
58
|
-
|
|
41
|
+
@Bind()
|
|
42
|
+
async create (req: Request) {
|
|
59
43
|
const data = await {{Model}}.query().create({
|
|
60
44
|
data: req.body,
|
|
61
45
|
})
|
|
62
46
|
|
|
63
|
-
return new Resource({
|
|
64
|
-
data: data,
|
|
65
|
-
}, res)
|
|
66
|
-
.additional({
|
|
47
|
+
return new Resource({ data }).additional({
|
|
67
48
|
status: 'success',
|
|
68
49
|
message: 'New {{ModelName}} created successfully',
|
|
69
50
|
code: 201,
|
|
70
|
-
})
|
|
71
|
-
.response()
|
|
72
|
-
.setStatusCode(201)
|
|
51
|
+
}).response().setStatusCode(201)
|
|
73
52
|
}
|
|
74
53
|
|
|
75
54
|
/**
|
|
76
55
|
* Update a specific resource in the database
|
|
77
56
|
*
|
|
57
|
+
* @param {{Param}}
|
|
78
58
|
* @param req
|
|
79
|
-
* @param res
|
|
80
59
|
*/
|
|
81
|
-
|
|
82
|
-
|
|
60
|
+
@Bind()
|
|
61
|
+
async update (req: Request, {{Param}}: {{Model}}) {
|
|
62
|
+
await {{Param}}.update({
|
|
83
63
|
data: req.body,
|
|
84
64
|
})
|
|
85
65
|
|
|
86
|
-
return new Resource({
|
|
87
|
-
data,
|
|
88
|
-
}, res)
|
|
89
|
-
.additional({
|
|
66
|
+
return new Resource({{Param}}).additional({
|
|
90
67
|
status: 'success',
|
|
91
68
|
message: '{{ModelName}} updated successfully',
|
|
92
69
|
code: 202,
|
|
93
|
-
})
|
|
94
|
-
.response()
|
|
95
|
-
.setStatusCode(202)
|
|
70
|
+
}).response().setStatusCode(202)
|
|
96
71
|
}
|
|
97
72
|
|
|
98
73
|
/**
|
|
99
74
|
* Delete a specific resource from the database
|
|
100
75
|
*
|
|
101
|
-
* @param
|
|
102
|
-
* @param res
|
|
76
|
+
* @param {{Param}}
|
|
103
77
|
*/
|
|
104
|
-
destroy
|
|
105
|
-
await {{
|
|
78
|
+
async destroy ({{Param}}: {{Model}}) {
|
|
79
|
+
await {{Param}}.delete()
|
|
106
80
|
|
|
107
|
-
return new Resource({
|
|
108
|
-
data: {},
|
|
109
|
-
}, res)
|
|
110
|
-
.additional({
|
|
81
|
+
return new Resource({ data: {} }).additional({
|
|
111
82
|
status: 'success',
|
|
112
83
|
message: '{{ModelName}} deleted successfully',
|
|
113
84
|
code: 202,
|
|
114
|
-
})
|
|
115
|
-
.response()
|
|
116
|
-
.setStatusCode(202)
|
|
85
|
+
}).response().setStatusCode(202)
|
|
117
86
|
}
|
|
118
87
|
}
|
package/stubs/controller.stub
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { BaseController } from '@controllers/BaseController'
|
|
2
|
-
import { HttpContext } from 'clear-router/types/express'
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* {{ControllerName}}
|
|
6
5
|
*/
|
|
7
6
|
export default class {{ControllerName}} extends BaseController {
|
|
8
|
-
index
|
|
9
|
-
|
|
7
|
+
async index () {
|
|
8
|
+
return '<p>Hello!</p>'
|
|
10
9
|
}
|
|
11
10
|
}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/error-handler.ts","../src/Router.ts","../src/index.ts"],"mappings":";;;;;;;cAOa,mBAAA,EAAqB,mBAAA;;;cCMrB,MAAA,SAAe,QAAA;EAAA,OACb,IAAA,CAAA,GAAS,OAAA,CAAQ,QAAA;EAAA,OAyBjB,IAAA,CACX,QAAA,GAAU,wBAAA,GACT,OAAA,CAAQ,KAAA,CAAM,KAAA,CAAM,WAAA,EAAa,UAAA,EAAY,SAAA;AAAA;;;UCnCjC,oBAAA;EACb,UAAA,GAAa,GAAA,EAAK,OAAA,KAAY,cAAA;EAC9B,iBAAA,IAAqB,GAAA,EAAK,OAAA,EAAS,UAAA,aAAuB,cAAA;EAC1D,YAAA,GAAe,mBAAA,GAAsB,OAAA;AAAA;AAAA,cAO5B,aAAA,SAAsB,iBAAA,CAAkB,OAAA,EAAS,OAAA;EAAA,SACjD,IAAA;EAAA,iBACQ,OAAA;cAOL,OAAA,EAAS,oBAAA;EAUrB,SAAA,CAAA,GAAc,OAAA;EAUd,iBAAA,CAAmB,GAAA,EAAK,OAAA,EAAS,UAAA,WAAqB,cAAA;EAqBtD,UAAA,CAAY,GAAA,EAAK,OAAA,GAAU,cAAA;EAU3B,eAAA,CACI,GAAA,EAAK,OAAA,EACL,UAAA,EAAY,OAAA,GAAU,wBAAA,CAAyB,OAAA;EA8BnD,oBAAA,CAAsB,GAAA,EAAK,OAAA;EAU3B,KAAA,CAAO,GAAA,EAAK,OAAA,EAAS,IAAA;AAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/middlewares/auth.ts","../../src/middlewares/request-logger.ts"],"mappings":";;;cAKa,IAAA,EAAM,OAAA;;;cCaN,aAAA;EAAiB;AAAA;EAG1B,iBAAA;AAAA,OACc,GAAA,EAAK,OAAA,EAAS,GAAA,EAAK,QAAA,EAAU,IAAA,EAAM,YAAA,KAAY,OAAA"}
|