@seip/bluebird-js 0.0.0-stage → 0.0.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/.env_example +54 -0
- package/AGENTS.md +403 -0
- package/LICENSE +21 -0
- package/README.md +284 -2
- package/app/routes/api.js +50 -0
- package/app/routes/web.js +53 -0
- package/app/views/about.html +161 -0
- package/app/views/dashboard.html +140 -0
- package/app/views/index.html +150 -0
- package/app/views/login.html +144 -0
- package/core/app.d.ts +18 -0
- package/core/app.js +644 -0
- package/core/auth.d.ts +13 -0
- package/core/auth.js +326 -0
- package/core/cache.d.ts +17 -0
- package/core/cache.js +475 -0
- package/core/cli/doctor.js +287 -0
- package/core/cli/ecosystem.js +162 -0
- package/core/cli/init.js +779 -0
- package/core/cli/migrate.js +541 -0
- package/core/cli/model.js +66 -0
- package/core/cli/nginx.js +199 -0
- package/core/cli/route.js +121 -0
- package/core/cli/swagger.js +45 -0
- package/core/cli/view.js +77 -0
- package/core/config.d.ts +3 -0
- package/core/config.js +111 -0
- package/core/csrf.d.ts +3 -0
- package/core/csrf.js +114 -0
- package/core/database.d.ts +15 -0
- package/core/database.js +636 -0
- package/core/debug.d.ts +3 -0
- package/core/debug.js +250 -0
- package/core/hash.d.ts +3 -0
- package/core/hash.js +194 -0
- package/core/index.d.ts +1071 -0
- package/core/logger.d.ts +3 -0
- package/core/logger.js +124 -0
- package/core/middleware.d.ts +3 -0
- package/core/middleware.js +28 -0
- package/core/model.d.ts +19 -0
- package/core/model.js +600 -0
- package/core/queue.d.ts +13 -0
- package/core/queue.js +172 -0
- package/core/ratelimit.d.ts +3 -0
- package/core/ratelimit.js +145 -0
- package/core/redis.d.ts +21 -0
- package/core/redis.js +230 -0
- package/core/render.d.ts +3 -0
- package/core/render.js +676 -0
- package/core/router.d.ts +3 -0
- package/core/router.js +171 -0
- package/core/seo.d.ts +3 -0
- package/core/seo.js +106 -0
- package/core/swagger.d.ts +3 -0
- package/core/swagger.js +60 -0
- package/core/upload.d.ts +13 -0
- package/core/upload.js +102 -0
- package/core/util/colors.js +82 -0
- package/core/validate.d.ts +15 -0
- package/core/validate.js +364 -0
- package/core/vite.d.ts +3 -0
- package/core/vite.js +145 -0
- package/core/ws.d.ts +13 -0
- package/core/ws.js +245 -0
- package/index.js +18 -0
- package/jsconfig.json +15 -0
- package/package.json +84 -3
- package/production.md +273 -0
- package/public/css/bluebird.min.css +2 -0
- package/public/images/favicon.ico +0 -0
- package/public/js/bluebird-client.js +1663 -0
- package/public/js/bluebird.min.js +1073 -0
package/core/router.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
import Config from "./config.js";
|
|
3
|
+
import Seo from "./seo.js";
|
|
4
|
+
|
|
5
|
+
const props = Config.props();
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Wraps route handlers to automatically catch async rejections and forward them to next(err).
|
|
9
|
+
* @param {Function} fn - Handler function.
|
|
10
|
+
* @returns {Function} Wrapped handler.
|
|
11
|
+
*/
|
|
12
|
+
function wrapAsync(fn) {
|
|
13
|
+
if (typeof fn !== "function") return fn;
|
|
14
|
+
return (req, res, next) => {
|
|
15
|
+
try {
|
|
16
|
+
const result = fn(req, res, next);
|
|
17
|
+
if (result && typeof result.catch === "function") {
|
|
18
|
+
result.catch(next);
|
|
19
|
+
}
|
|
20
|
+
} catch (err) {
|
|
21
|
+
next(err);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Router wrapper class for handling Express routing logic.
|
|
28
|
+
* When created with { seo: true }, all GET routes registered on this router
|
|
29
|
+
* are automatically included in the generated sitemap.xml and robots.txt.
|
|
30
|
+
*/
|
|
31
|
+
class Router {
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new Router instance.
|
|
34
|
+
* @param {string} [path="/"] - The base path for this router.
|
|
35
|
+
* @param {Object} [options={}] - Router configuration options.
|
|
36
|
+
* @param {boolean} [options.seo=false] - When true, GET routes on this router are included in sitemap/robots.txt.
|
|
37
|
+
* @param {string[]} [options.languages=[]] - Language prefixes for SEO route generation (e.g., ["en", "es"]).
|
|
38
|
+
* @example
|
|
39
|
+
* const router = new Router("/", { seo: true, languages: ["en", "es"] });
|
|
40
|
+
* router.get("/", (req, res) => {
|
|
41
|
+
* Render.send(res, "index", { title: "Home" });
|
|
42
|
+
* });
|
|
43
|
+
*/
|
|
44
|
+
constructor(path = "/", options = {}) {
|
|
45
|
+
this.router = express.Router();
|
|
46
|
+
this.path = path;
|
|
47
|
+
this._seo = options.seo ?? false;
|
|
48
|
+
this._languages = options.languages || [];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Registers a middleware on this router.
|
|
53
|
+
* @param {...Function} middleware - Middleware functions.
|
|
54
|
+
* @example
|
|
55
|
+
* router.use(Auth.protect());
|
|
56
|
+
* router.use(App.helmet());
|
|
57
|
+
*/
|
|
58
|
+
use(...middleware) {
|
|
59
|
+
const handlers = middleware.map(wrapAsync);
|
|
60
|
+
this.router.use(...handlers);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Registers a GET route handler.
|
|
65
|
+
* If this router was created with { seo: true }, the route path is automatically
|
|
66
|
+
* registered for sitemap.xml and robots.txt generation.
|
|
67
|
+
* @param {string|RegExp} path - The relative path for the GET route.
|
|
68
|
+
* @param {...Function} callback - One or more handler functions (middlewares and controller).
|
|
69
|
+
* @example
|
|
70
|
+
* router.get("/about", (req, res) => {
|
|
71
|
+
* Render.send(res, "about", { title: "About Us" });
|
|
72
|
+
* });
|
|
73
|
+
*/
|
|
74
|
+
get(path, ...callback) {
|
|
75
|
+
if (this._seo && typeof path === "string") {
|
|
76
|
+
Seo.registerRoute(this.path, path, this._languages);
|
|
77
|
+
}
|
|
78
|
+
if (path === "/*" || path === "*") {
|
|
79
|
+
path = /.*/;
|
|
80
|
+
}
|
|
81
|
+
const handlers = callback.map(wrapAsync);
|
|
82
|
+
this.router.get(path, ...handlers);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Registers a POST route handler.
|
|
87
|
+
* @param {string} path - The relative path for the POST route.
|
|
88
|
+
* @param {...Function} callback - One or more handler functions (middlewares and controller).
|
|
89
|
+
* @example
|
|
90
|
+
* router.post("/users", (req, res) => {
|
|
91
|
+
* res.json({ message: "User created successfully" })
|
|
92
|
+
* })
|
|
93
|
+
*/
|
|
94
|
+
post(path, ...callback) {
|
|
95
|
+
if (path === "/*" || path === "*") {
|
|
96
|
+
path = /.*/;
|
|
97
|
+
}
|
|
98
|
+
const handlers = callback.map(wrapAsync);
|
|
99
|
+
this.router.post(path, ...handlers);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Registers a PUT route handler.
|
|
104
|
+
* @param {string} path - The relative path for the PUT route.
|
|
105
|
+
* @param {...Function} callback - One or more handler functions (middlewares and controller).
|
|
106
|
+
* @example
|
|
107
|
+
* router.put("/users/:id", (req, res) => {
|
|
108
|
+
* res.json({ message: "User updated successfully" })
|
|
109
|
+
* })
|
|
110
|
+
*/
|
|
111
|
+
put(path, ...callback) {
|
|
112
|
+
const handlers = callback.map(wrapAsync);
|
|
113
|
+
this.router.put(path, ...handlers);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Registers a DELETE route handler.
|
|
118
|
+
* @param {string} path - The relative path for the DELETE route.
|
|
119
|
+
* @param {...Function} callback - One or more handler functions (middlewares and controller).
|
|
120
|
+
* @example
|
|
121
|
+
* router.delete("/users/:id", (req, res) => {
|
|
122
|
+
* res.json({ message: "User deleted successfully" })
|
|
123
|
+
* })
|
|
124
|
+
*/
|
|
125
|
+
delete(path, ...callback) {
|
|
126
|
+
const handlers = callback.map(wrapAsync);
|
|
127
|
+
this.router.delete(path, ...handlers);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Registers a PATCH route handler.
|
|
132
|
+
* @param {string} path - The relative path for the PATCH route.
|
|
133
|
+
* @param {...Function} callback - One or more handler functions (middlewares and controller).
|
|
134
|
+
* @example
|
|
135
|
+
* router.patch("/users/:id", (req, res) => {
|
|
136
|
+
* res.json({ message: "User patched successfully" })
|
|
137
|
+
* })
|
|
138
|
+
*/
|
|
139
|
+
patch(path, ...callback) {
|
|
140
|
+
const handlers = callback.map(wrapAsync);
|
|
141
|
+
this.router.patch(path, ...handlers);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Registers an OPTIONS route handler.
|
|
146
|
+
* @param {string} path - The relative path for the OPTIONS route.
|
|
147
|
+
* @param {...Function} callback - One or more handler functions (middlewares and controller).
|
|
148
|
+
*/
|
|
149
|
+
options(path, ...callback) {
|
|
150
|
+
const handlers = callback.map(wrapAsync);
|
|
151
|
+
this.router.options(path, ...handlers);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Returns the underlying Express router instance.
|
|
156
|
+
* @returns {import('express').Router}
|
|
157
|
+
*/
|
|
158
|
+
getRouter() {
|
|
159
|
+
return this.router;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Returns the base path associated with this router.
|
|
164
|
+
* @returns {string}
|
|
165
|
+
*/
|
|
166
|
+
getPath() {
|
|
167
|
+
return this.path;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
export { Router };
|
|
171
|
+
export default Router;
|
package/core/seo.d.ts
ADDED
package/core/seo.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import Config from "./config.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Registry of SEO-enabled routes for automatic sitemap.xml and robots.txt generation.
|
|
5
|
+
* @type {Set<string>}
|
|
6
|
+
*/
|
|
7
|
+
const registeredSeoRoutes = new Set();
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Native SEO module for registering indexable routes and serving sitemap.xml and robots.txt.
|
|
11
|
+
*/
|
|
12
|
+
class Seo {
|
|
13
|
+
/**
|
|
14
|
+
* Registers a GET route path for inclusion in sitemap.xml.
|
|
15
|
+
* Ignores parameterized dynamic segments (e.g. :id) and wildcards.
|
|
16
|
+
* @param {string} basePath - Router base path.
|
|
17
|
+
* @param {string|RegExp} routePath - Route relative path.
|
|
18
|
+
* @param {string[]} [languages=[]] - Optional language prefixes.
|
|
19
|
+
*/
|
|
20
|
+
static registerRoute(basePath, routePath, languages = []) {
|
|
21
|
+
if (typeof routePath !== "string") return;
|
|
22
|
+
if (routePath.includes("*") || routePath.includes(":")) return;
|
|
23
|
+
|
|
24
|
+
const normalizedBase = basePath === "/" ? "" : basePath.replace(/\/$/, "");
|
|
25
|
+
const normalizedRoute = routePath.startsWith("/") ? routePath : `/${routePath}`;
|
|
26
|
+
const fullPath = `${normalizedBase}${normalizedRoute}` || "/";
|
|
27
|
+
|
|
28
|
+
if (languages && languages.length > 0) {
|
|
29
|
+
for (const lang of languages) {
|
|
30
|
+
const cleanLang = String(lang).trim().replace(/^\/|\/$/g, "");
|
|
31
|
+
if (cleanLang) {
|
|
32
|
+
const localizedPath = fullPath === "/" ? `/${cleanLang}` : `/${cleanLang}${fullPath}`;
|
|
33
|
+
registeredSeoRoutes.add(localizedPath);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
registeredSeoRoutes.add(fullPath);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Returns all registered SEO route paths.
|
|
43
|
+
* @returns {string[]}
|
|
44
|
+
*/
|
|
45
|
+
static getRoutes() {
|
|
46
|
+
return Array.from(registeredSeoRoutes);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Clears all registered SEO routes.
|
|
51
|
+
*/
|
|
52
|
+
static clear() {
|
|
53
|
+
registeredSeoRoutes.clear();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Generates the XML string for sitemap.xml.
|
|
58
|
+
* @param {string} [baseUrl] - Public base URL of the application.
|
|
59
|
+
* @returns {string}
|
|
60
|
+
*/
|
|
61
|
+
static generateSitemap(baseUrl) {
|
|
62
|
+
const props = Config.props();
|
|
63
|
+
const rootUrl = (baseUrl || props.appUrl || `${props.host}:${props.port}`).replace(/\/$/, "");
|
|
64
|
+
const lastmod = new Date().toISOString().split("T")[0];
|
|
65
|
+
|
|
66
|
+
const urls = Array.from(registeredSeoRoutes).map((routePath) => {
|
|
67
|
+
const priority = routePath === "/" ? "1.0" : "0.8";
|
|
68
|
+
return [
|
|
69
|
+
" <url>",
|
|
70
|
+
` <loc>${rootUrl}${routePath}</loc>`,
|
|
71
|
+
` <lastmod>${lastmod}</lastmod>`,
|
|
72
|
+
" <changefreq>weekly</changefreq>",
|
|
73
|
+
` <priority>${priority}</priority>`,
|
|
74
|
+
" </url>",
|
|
75
|
+
].join("\n");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
return [
|
|
79
|
+
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
80
|
+
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
|
|
81
|
+
...urls,
|
|
82
|
+
"</urlset>",
|
|
83
|
+
].join("\n");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Generates the plain text content for robots.txt.
|
|
88
|
+
* @param {string} [baseUrl] - Public base URL of the application.
|
|
89
|
+
* @returns {string}
|
|
90
|
+
*/
|
|
91
|
+
static generateRobots(baseUrl) {
|
|
92
|
+
const props = Config.props();
|
|
93
|
+
const rootUrl = (baseUrl || props.appUrl || `${props.host}:${props.port}`).replace(/\/$/, "");
|
|
94
|
+
return [
|
|
95
|
+
"User-agent: *",
|
|
96
|
+
"Allow: /",
|
|
97
|
+
"Disallow: /api/",
|
|
98
|
+
"Disallow: /debug/",
|
|
99
|
+
`Sitemap: ${rootUrl}/sitemap.xml`,
|
|
100
|
+
"",
|
|
101
|
+
].join("\n");
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export { Seo };
|
|
106
|
+
export default Seo;
|
package/core/swagger.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Swagger and OpenAPI documentation integration module.
|
|
3
|
+
* Dynamically loads swagger-ui-express and swagger-jsdoc when enabled.
|
|
4
|
+
*/
|
|
5
|
+
class Swagger {
|
|
6
|
+
/**
|
|
7
|
+
* Initializes Swagger UI documentation on the Express application.
|
|
8
|
+
* @param {import('express').Application} app - Express application instance.
|
|
9
|
+
* @param {Object} [options={}] - Configuration options.
|
|
10
|
+
* @param {string} [options.route="/docs"] - HTTP route for documentation.
|
|
11
|
+
* @param {Object} [options.info={}] - OpenAPI info object.
|
|
12
|
+
* @param {string[]} [options.apis=[]] - Glob paths for JSDoc documentation files.
|
|
13
|
+
* @returns {Promise<boolean>} Resolves to true if documentation was mounted.
|
|
14
|
+
*/
|
|
15
|
+
static async init(app, options = {}) {
|
|
16
|
+
const route = options.route || "/docs";
|
|
17
|
+
const apis = options.apis || ["./app/routes/*.js", "./app/routes/*.ts"];
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
const [{ default: swaggerUi }, { default: swaggerJsdoc }] = await Promise.all([
|
|
21
|
+
import("swagger-ui-express"),
|
|
22
|
+
import("swagger-jsdoc"),
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
const swaggerDefinition = {
|
|
26
|
+
openapi: "3.0.0",
|
|
27
|
+
info: {
|
|
28
|
+
title: options.info?.title || "Blue Bird API",
|
|
29
|
+
version: options.info?.version || "1.0.0",
|
|
30
|
+
description: options.info?.description || "Blue Bird Framework API Documentation",
|
|
31
|
+
},
|
|
32
|
+
servers: [
|
|
33
|
+
{
|
|
34
|
+
url: options.url || "http://localhost:3000",
|
|
35
|
+
description: "API Server",
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const swaggerSpec = swaggerJsdoc({
|
|
41
|
+
swaggerDefinition,
|
|
42
|
+
apis,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
app.use(route, swaggerUi.serve, swaggerUi.setup(swaggerSpec));
|
|
46
|
+
app.get(`${route}/json`, (req, res) => {
|
|
47
|
+
res.setHeader("Content-Type", "application/json");
|
|
48
|
+
res.send(swaggerSpec);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return true;
|
|
52
|
+
} catch {
|
|
53
|
+
console.warn("[SWAGGER WARN] 'swagger-ui-express' or 'swagger-jsdoc' is not installed. Run: npx blue-bird add swagger");
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { Swagger };
|
|
60
|
+
export default Swagger;
|
package/core/upload.d.ts
ADDED
package/core/upload.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import Config from "./config.js";
|
|
4
|
+
|
|
5
|
+
const __dirname = Config.dirname();
|
|
6
|
+
const props = Config.props();
|
|
7
|
+
|
|
8
|
+
let multer = null;
|
|
9
|
+
try {
|
|
10
|
+
multer = (await import("multer")).default || (await import("multer"));
|
|
11
|
+
} catch {}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Upload helper to manage file uploads using multer.
|
|
15
|
+
*/
|
|
16
|
+
class Upload {
|
|
17
|
+
/**
|
|
18
|
+
* Asserts that the multer package is available.
|
|
19
|
+
* @private
|
|
20
|
+
*/
|
|
21
|
+
static _ensureMulter() {
|
|
22
|
+
if (!multer) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
"[UPLOAD ERROR] 'multer' package is not installed. Install it with: npm install multer or npx blue-bird add upload",
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Configures storage for uploaded files.
|
|
31
|
+
* @param {string} folder - The destination folder within the static path.
|
|
32
|
+
* @returns {import('multer').StorageEngine}
|
|
33
|
+
* @example
|
|
34
|
+
* const storage = Upload.storage("uploads");
|
|
35
|
+
*/
|
|
36
|
+
static storage(folder = "uploads") {
|
|
37
|
+
this._ensureMulter();
|
|
38
|
+
const dest = path.join(__dirname, props.static.path, folder);
|
|
39
|
+
|
|
40
|
+
if (!fs.existsSync(dest)) {
|
|
41
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return multer.diskStorage({
|
|
45
|
+
destination: (req, file, cb) => {
|
|
46
|
+
cb(null, dest);
|
|
47
|
+
},
|
|
48
|
+
filename: (req, file, cb) => {
|
|
49
|
+
const uniqueSuffix =
|
|
50
|
+
Date.now() + "-" + Math.round(Math.random() * 1e9);
|
|
51
|
+
cb(null, uniqueSuffix + path.extname(file.originalname));
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Returns a multer instance for single or multiple file uploads.
|
|
58
|
+
* @param {Object} options - Multer options.
|
|
59
|
+
* @param {string} [options.folder='uploads'] - Destination folder.
|
|
60
|
+
* @param {number} [options.fileSize=5000000] - Max file size in bytes (default 5MB).
|
|
61
|
+
* @param {Array<string>} [options.allowedTypes=[]] - Allowed mime types (e.g. ['image/png', 'image/jpeg']).
|
|
62
|
+
* @returns {import('multer').Multer}
|
|
63
|
+
* @example
|
|
64
|
+
* const upload = Upload.disk({ folder: "uploads", fileSize: 5000000, allowedTypes: ["image/png", "image/jpeg"] });
|
|
65
|
+
*/
|
|
66
|
+
static disk(options = {}) {
|
|
67
|
+
this._ensureMulter();
|
|
68
|
+
const {
|
|
69
|
+
folder = "uploads",
|
|
70
|
+
fileSize = 5000000,
|
|
71
|
+
allowedTypes = [],
|
|
72
|
+
} = options;
|
|
73
|
+
|
|
74
|
+
return multer({
|
|
75
|
+
storage: this.storage(folder),
|
|
76
|
+
limits: { fileSize },
|
|
77
|
+
fileFilter: (req, file, cb) => {
|
|
78
|
+
if (allowedTypes.length > 0 && !allowedTypes.includes(file.mimetype)) {
|
|
79
|
+
return cb(new Error("File type not allowed"), false);
|
|
80
|
+
}
|
|
81
|
+
cb(null, true);
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Helper to get the public URL of an uploaded file.
|
|
88
|
+
* @param {string} filename - The name of the file.
|
|
89
|
+
* @param {string} [folder='uploads'] - The folder where the file is stored.
|
|
90
|
+
* @returns {string} The full public URL.
|
|
91
|
+
* @example
|
|
92
|
+
* const url = Upload.url("file.jpg", "uploads");
|
|
93
|
+
*/
|
|
94
|
+
static url(filename, folder = "uploads") {
|
|
95
|
+
const appUrl = props.appUrl ?? `${props.host}:${props.port}`;
|
|
96
|
+
return `${appUrl}/${folder}/${filename}`;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export { Upload };
|
|
101
|
+
export default Upload;
|
|
102
|
+
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { styleText } from "node:util";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ANSI color formatting utilities powered by Node.js native styleText.
|
|
5
|
+
* Provides a lightweight, zero-dependency alternative to chalk.
|
|
6
|
+
*/
|
|
7
|
+
const colors = {
|
|
8
|
+
/**
|
|
9
|
+
* Applies bold formatting.
|
|
10
|
+
* @param {string|number} text
|
|
11
|
+
* @returns {string}
|
|
12
|
+
*/
|
|
13
|
+
bold: (text) => styleText("bold", String(text)),
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Applies green color.
|
|
17
|
+
* @param {string|number} text
|
|
18
|
+
* @returns {string}
|
|
19
|
+
*/
|
|
20
|
+
green: (text) => styleText("green", String(text)),
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Applies red color.
|
|
24
|
+
* @param {string|number} text
|
|
25
|
+
* @returns {string}
|
|
26
|
+
*/
|
|
27
|
+
red: (text) => styleText("red", String(text)),
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Applies blue color.
|
|
31
|
+
* @param {string|number} text
|
|
32
|
+
* @returns {string}
|
|
33
|
+
*/
|
|
34
|
+
blue: (text) => styleText("blue", String(text)),
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Applies yellow color.
|
|
38
|
+
* @param {string|number} text
|
|
39
|
+
* @returns {string}
|
|
40
|
+
*/
|
|
41
|
+
yellow: (text) => styleText("yellow", String(text)),
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Applies cyan color.
|
|
45
|
+
* @param {string|number} text
|
|
46
|
+
* @returns {string}
|
|
47
|
+
*/
|
|
48
|
+
cyan: (text) => styleText("cyan", String(text)),
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Applies magenta color.
|
|
52
|
+
* @param {string|number} text
|
|
53
|
+
* @returns {string}
|
|
54
|
+
*/
|
|
55
|
+
magenta: (text) => styleText("magenta", String(text)),
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Applies gray color.
|
|
59
|
+
* @param {string|number} text
|
|
60
|
+
* @returns {string}
|
|
61
|
+
*/
|
|
62
|
+
gray: (text) => styleText("gray", String(text)),
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Applies white color.
|
|
66
|
+
* @param {string|number} text
|
|
67
|
+
* @returns {string}
|
|
68
|
+
*/
|
|
69
|
+
white: (text) => styleText("white", String(text)),
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Bold color modifier functions.
|
|
74
|
+
*/
|
|
75
|
+
colors.bold.green = (text) => styleText(["bold", "green"], String(text));
|
|
76
|
+
colors.bold.red = (text) => styleText(["bold", "red"], String(text));
|
|
77
|
+
colors.bold.blue = (text) => styleText(["bold", "blue"], String(text));
|
|
78
|
+
colors.bold.cyan = (text) => styleText(["bold", "cyan"], String(text));
|
|
79
|
+
colors.bold.yellow = (text) => styleText(["bold", "yellow"], String(text));
|
|
80
|
+
colors.bold.magenta = (text) => styleText(["bold", "magenta"], String(text));
|
|
81
|
+
|
|
82
|
+
export default colors;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Validator,
|
|
3
|
+
ValidationRule,
|
|
4
|
+
ValidationSchema,
|
|
5
|
+
ValidationError,
|
|
6
|
+
ValidationResult,
|
|
7
|
+
} from "./index.js";
|
|
8
|
+
export default Validator;
|
|
9
|
+
export {
|
|
10
|
+
Validator,
|
|
11
|
+
ValidationRule,
|
|
12
|
+
ValidationSchema,
|
|
13
|
+
ValidationError,
|
|
14
|
+
ValidationResult,
|
|
15
|
+
};
|