@cyberskill/shared 3.9.0 → 3.10.0
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/dist/config/lint-staged/index.js +1 -1
- package/dist/config/lint-staged/index.js.map +1 -1
- package/dist/config/vitest/vitest.e2e.js +1 -1
- package/dist/config/vitest/vitest.unit.js +1 -1
- package/dist/node/express/express.util.js +3 -4
- package/dist/node/express/express.util.js.map +1 -1
- package/dist/node/fs/fs.util.js +14 -14
- package/dist/node/mongo/index.js +5 -5
- package/dist/node/mongo/mongo.controller.mongoose.js +86 -85
- package/dist/node/mongo/mongo.controller.mongoose.js.map +1 -1
- package/dist/node/mongo/mongo.dynamic-populate.d.ts +0 -4
- package/dist/node/mongo/mongo.dynamic-populate.js +14 -17
- package/dist/node/mongo/mongo.dynamic-populate.js.map +1 -1
- package/dist/node/mongo/mongo.util.js +2 -0
- package/dist/node/mongo/mongo.util.js.map +1 -1
- package/dist/node/storage/storage.util.js +41 -35
- package/dist/node/storage/storage.util.js.map +1 -1
- package/dist/node/upload/upload.util.js +34 -28
- package/dist/node/upload/upload.util.js.map +1 -1
- package/dist/node_modules/.pnpm/vitest@4.1.0_@types_node@25.5.0_jsdom@29.0.0_@noble_hashes@1.8.0__vite@8.0.1_@types_nod_36acd00c2670b611b011192023dc5bd9/node_modules/vitest/dist/config.js +8 -0
- package/dist/node_modules/.pnpm/{vitest@4.1.0_@types_node@25.5.0_jsdom@29.0.0_@noble_hashes@1.8.0__vite@8.0.0_@types_nod_53aa4254f295b3c40bb8f17b6ab226b5 → vitest@4.1.0_@types_node@25.5.0_jsdom@29.0.0_@noble_hashes@1.8.0__vite@8.0.1_@types_nod_36acd00c2670b611b011192023dc5bd9}/node_modules/vitest/dist/config.js.map +1 -1
- package/package.json +8 -8
- package/dist/node_modules/.pnpm/vitest@4.1.0_@types_node@25.5.0_jsdom@29.0.0_@noble_hashes@1.8.0__vite@8.0.0_@types_nod_53aa4254f295b3c40bb8f17b6ab226b5/node_modules/vitest/dist/config.js +0 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/config/lint-staged/index.ts"],"sourcesContent":["export default {\n '*.ts': () => 'tsc --noEmit',\n '*': ['eslint --fix --no-cache'],\n};\n"],"mappings":";AAAA,IAAA,IAAe;CACX,cAAc;CACd,KAAK,CAAC,0BAA0B;CACnC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/config/lint-staged/index.ts"],"sourcesContent":["export default {\n '*.ts': () => 'tsc --noEmit --incremental',\n '*': ['eslint --fix --no-cache'],\n};\n"],"mappings":";AAAA,IAAA,IAAe;CACX,cAAc;CACd,KAAK,CAAC,0BAA0B;CACnC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { deepMerge as e } from "../../util/object/object.util.js";
|
|
2
|
-
import { defineConfig as t } from "../../node_modules/.pnpm/vitest@4.1.0_@types_node@25.5.0_jsdom@29.0.0_@noble_hashes@1.8.0__vite@8.0.
|
|
2
|
+
import { defineConfig as t } from "../../node_modules/.pnpm/vitest@4.1.0_@types_node@25.5.0_jsdom@29.0.0_@noble_hashes@1.8.0__vite@8.0.1_@types_nod_36acd00c2670b611b011192023dc5bd9/node_modules/vitest/dist/config.js";
|
|
3
3
|
import n from "@vitejs/plugin-react";
|
|
4
4
|
//#region src/config/vitest/vitest.e2e.ts
|
|
5
5
|
function r(r) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { deepMerge as e } from "../../util/object/object.util.js";
|
|
2
|
-
import { defineConfig as t } from "../../node_modules/.pnpm/vitest@4.1.0_@types_node@25.5.0_jsdom@29.0.0_@noble_hashes@1.8.0__vite@8.0.
|
|
2
|
+
import { defineConfig as t } from "../../node_modules/.pnpm/vitest@4.1.0_@types_node@25.5.0_jsdom@29.0.0_@noble_hashes@1.8.0__vite@8.0.1_@types_nod_36acd00c2670b611b011192023dc5bd9/node_modules/vitest/dist/config.js";
|
|
3
3
|
import n from "@vitejs/plugin-react";
|
|
4
4
|
//#region src/config/vitest/vitest.unit.ts
|
|
5
5
|
function r(r) {
|
|
@@ -49,8 +49,8 @@ function m(t) {
|
|
|
49
49
|
}
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
|
-
function h(e, n = !1, r = "1mb", o =
|
|
53
|
-
o
|
|
52
|
+
function h(e, n = !1, r = "1mb", o = 1, c = {}) {
|
|
53
|
+
o && e.set("trust proxy", o), e.use(d({
|
|
54
54
|
crossOriginEmbedderPolicy: n ? !1 : void 0,
|
|
55
55
|
contentSecurityPolicy: n ? !1 : void 0
|
|
56
56
|
})), c !== !1 && e.use(s({
|
|
@@ -59,8 +59,7 @@ function h(e, n = !1, r = "1mb", o = !1, c = {}) {
|
|
|
59
59
|
standardHeaders: !0,
|
|
60
60
|
legacyHeaders: !1,
|
|
61
61
|
...c.store !== void 0 && { store: c.store },
|
|
62
|
-
...c.skip !== void 0 && { skip: c.skip }
|
|
63
|
-
...!o && { validate: { xForwardedForHeader: !1 } }
|
|
62
|
+
...c.skip !== void 0 && { skip: c.skip }
|
|
64
63
|
})), e.use(a()), e.use(t.json({ limit: r })), e.use(t.urlencoded({
|
|
65
64
|
extended: !0,
|
|
66
65
|
limit: r
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.util.js","names":[],"sources":["../../../src/node/express/express.util.ts"],"sourcesContent":["import type { INestApplication } from '@nestjs/common';\nimport type { Application, RequestHandler } from 'express';\nimport type { SessionOptions } from 'express-session';\n\nimport { NestFactory } from '@nestjs/core';\nimport bodyParser from 'body-parser';\nimport compression from 'compression';\nimport cookieParser from 'cookie-parser';\nimport cors from 'cors';\nimport express from 'express';\nimport rateLimit from 'express-rate-limit';\nimport session from 'express-session';\nimport { express as useragent } from 'express-useragent';\nimport graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.mjs';\nimport helmet from 'helmet';\nimport process from 'node:process';\n\nimport type { I_ExpressOptions, I_NestOptions, T_CorsOptions, T_CorsType } from './express.type.js';\n\n/**\n * Creates CORS options with environment-specific configuration.\n * This function generates CORS options based on the development environment,\n * including whitelist configuration for allowed origins.\n *\n * @param options - CORS configuration options.\n * @param options.isDev - Whether the application is running in development mode.\n * @param options.whiteList - Array of allowed origins for CORS requests.\n * @returns CORS options object configured for the specified environment.\n */\nexport function createCorsOptions<T extends T_CorsType>({ isDev, whiteList, ...rest }: T_CorsOptions<T>) {\n // Safety net: warn loudly if isDev is mistakenly true in production\n if (isDev && process.env['NODE_ENV'] === 'production') {\n console.warn('[CORS] WARNING: isDev is true but NODE_ENV is \"production\". CORS restrictions are relaxed. This is likely a misconfiguration.');\n }\n\n return {\n origin: (origin: string | undefined, callback: (err: Error | null, allow?: boolean) => void) => {\n // Allow requests without Origin header only in development mode.\n // In production, undefined origin (e.g., curl, server-to-server) is rejected.\n if (isDev && !origin) {\n callback(null, true);\n return;\n }\n\n if (origin && whiteList?.includes(origin)) {\n callback(null, true);\n }\n else {\n callback(new Error('Not allowed by CORS'), false);\n }\n },\n credentials: true,\n ...rest,\n };\n}\n\n/**\n * Creates a CORS middleware function with the specified configuration.\n * This function creates a CORS middleware that can be used with both Express and NestJS applications,\n * applying the configured CORS options for origin validation and credential handling.\n *\n * @param options - CORS configuration options to apply to the middleware.\n * @returns A CORS middleware function ready to be used in Express or NestJS applications.\n */\nexport function createCors<T extends T_CorsType>(options: T_CorsOptions<T>) {\n return cors<cors.CorsRequest>(createCorsOptions(options));\n}\n\n/**\n * Creates a session middleware function with the specified configuration.\n * This function creates an Express session middleware that can be used to handle user sessions\n * with the provided session options including secret, cookie settings, and storage configuration.\n *\n * @param options - Session configuration options including secret, cookie settings, and storage.\n * @returns A session middleware function ready to be used in Express applications.\n */\nexport function createSession(options: SessionOptions): RequestHandler {\n if (!options.secret) {\n throw new Error('Session secret is required. Provide a strong secret string.');\n }\n\n if (!options.store && process.env['NODE_ENV'] === 'production') {\n console.warn('[Session] WARNING: No session store configured in production. The default MemoryStore leaks memory and loses sessions on restart. Use connect-redis, connect-mongo, or another production store.');\n }\n\n const secureDefaults: Partial<SessionOptions> = {\n resave: false,\n saveUninitialized: false,\n cookie: {\n httpOnly: true,\n sameSite: 'lax',\n secure: process.env['NODE_ENV'] === 'production',\n maxAge: 24 * 60 * 60 * 1000, // 24 hours\n },\n };\n\n return session({\n ...secureDefaults,\n ...options,\n cookie: { ...secureDefaults.cookie, ...options.cookie },\n });\n}\n\n/**\n * Sets up common middleware for Express applications.\n * This function configures essential middleware including:\n * - Trust proxy settings for proper IP handling\n * - Cookie parsing for request cookies\n * - URL-encoded body parsing for form data\n * - Compression for response optimization\n * - User agent parsing for device/browser detection\n *\n * @param app - The Express application instance to configure with middleware.\n * @param isDev - Whether the application is running in development mode.\n * @param jsonLimit - Maximum request body size for JSON payloads.\n * @param trustProxy - Trust proxy setting; pass a truthy value to enable.\n * @param rateLimitOptions - Rate limit configuration, or `false` to disable.\n */\nfunction setupMiddleware(\n app: Application,\n isDev = false,\n jsonLimit = '1mb',\n trustProxy: boolean | number | string | string[] = false,\n rateLimitOptions: false | import('./express.type.js').I_RateLimitOptions = {},\n) {\n if (trustProxy !== false) {\n app.set('trust proxy', trustProxy);\n }\n\n app.use(\n helmet({\n crossOriginEmbedderPolicy: isDev ? false : undefined,\n contentSecurityPolicy: isDev ? false : undefined,\n }),\n );\n\n if (rateLimitOptions !== false) {\n app.use(\n rateLimit({\n windowMs: rateLimitOptions.windowMs ?? 15 * 60 * 1000,\n limit: rateLimitOptions.limit ?? 1000,\n standardHeaders: true,\n legacyHeaders: false,\n ...(rateLimitOptions.store !== undefined && { store: rateLimitOptions.store }),\n ...(rateLimitOptions.skip !== undefined && { skip: rateLimitOptions.skip }),\n // When trustProxy is not explicitly set, suppress the\n // ERR_ERL_UNEXPECTED_X_FORWARDED_FOR validation that crashes on\n // X-Forwarded-For headers behind a reverse proxy.\n ...(!trustProxy && { validate: { xForwardedForHeader: false } }),\n }),\n );\n }\n app.use(cookieParser());\n app.use(express.json({ limit: jsonLimit }));\n app.use(express.urlencoded({ extended: true, limit: jsonLimit }));\n app.use(compression());\n app.use(useragent());\n}\n\n/**\n * Sets up static file serving for Express applications.\n * This function configures static file serving for the specified folders,\n * making files in those directories accessible via HTTP requests.\n *\n * @param app - The Express application instance to configure with static file serving.\n * @param staticFolders - A string or array of strings representing the paths to serve statically.\n */\nfunction setupStaticFolders(app: Application, staticFolders?: string | string[]) {\n if (staticFolders) {\n const statics = Array.isArray(staticFolders) ? staticFolders : [staticFolders];\n statics.forEach((folder) => {\n app.use(`/${folder}`, express.static(folder));\n });\n }\n}\n\n/**\n * Creates and configures an Express application with common middleware and settings.\n * This function sets up a complete Express application with:\n * - Essential middleware (cookies, body parsing, compression, user agent)\n * - Static file serving for specified folders\n * - GraphQL upload support for file uploads\n *\n * @remarks\n * **Requires Express 5.x** — This module uses Express 5 APIs and is not compatible with Express 4.\n * The peer dependency requires `express >= 5.0.0`.\n *\n * @param options - Optional configuration for the Express application including static folder paths.\n * @returns A configured Express application instance ready for use.\n */\nexport function createExpress(options?: I_ExpressOptions): Application {\n const app = express();\n\n setupMiddleware(app, options?.isDev, options?.jsonLimit, options?.trustProxy, options?.rateLimit);\n setupStaticFolders(app, options?.static);\n const uploadMiddleware = graphqlUploadExpress({\n maxFileSize: options?.maxFileSize ?? 10_000_000,\n maxFiles: options?.maxFiles ?? 10,\n });\n app.use(options?.uploadPath ?? '/graphql', uploadMiddleware);\n\n return app;\n}\n\n/**\n * Creates and configures a NestJS application with Express integration.\n * This function sets up a NestJS application with:\n * - Express HTTP adapter configuration\n * - Common middleware (cookies, body parsing, compression, user agent)\n * - Static file serving for specified folders\n * - Global filters and pipes if provided\n *\n * @param options - Configuration options for the NestJS application including module, static folders, filters, and pipes.\n * @returns A promise that resolves to a configured NestJS application instance.\n */\nexport async function createNest(options: I_NestOptions): Promise<INestApplication> {\n const app = await NestFactory.create(options.module);\n\n setupMiddleware(app.getHttpAdapter().getInstance(), options.isDev, options.jsonLimit, options.trustProxy, options.rateLimit);\n setupStaticFolders(app.getHttpAdapter().getInstance(), options.static);\n\n if (options.filters) {\n app.useGlobalFilters(...options.filters);\n }\n\n if (options.pipes) {\n app.useGlobalPipes(...options.pipes);\n }\n\n return app;\n}\n\nexport { bodyParser, express };\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"express.util.js","names":[],"sources":["../../../src/node/express/express.util.ts"],"sourcesContent":["import type { INestApplication } from '@nestjs/common';\nimport type { Application, RequestHandler } from 'express';\nimport type { SessionOptions } from 'express-session';\n\nimport { NestFactory } from '@nestjs/core';\nimport bodyParser from 'body-parser';\nimport compression from 'compression';\nimport cookieParser from 'cookie-parser';\nimport cors from 'cors';\nimport express from 'express';\nimport rateLimit from 'express-rate-limit';\nimport session from 'express-session';\nimport { express as useragent } from 'express-useragent';\nimport graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.mjs';\nimport helmet from 'helmet';\nimport process from 'node:process';\n\nimport type { I_ExpressOptions, I_NestOptions, T_CorsOptions, T_CorsType } from './express.type.js';\n\n/**\n * Creates CORS options with environment-specific configuration.\n * This function generates CORS options based on the development environment,\n * including whitelist configuration for allowed origins.\n *\n * @param options - CORS configuration options.\n * @param options.isDev - Whether the application is running in development mode.\n * @param options.whiteList - Array of allowed origins for CORS requests.\n * @returns CORS options object configured for the specified environment.\n */\nexport function createCorsOptions<T extends T_CorsType>({ isDev, whiteList, ...rest }: T_CorsOptions<T>) {\n // Safety net: warn loudly if isDev is mistakenly true in production\n if (isDev && process.env['NODE_ENV'] === 'production') {\n console.warn('[CORS] WARNING: isDev is true but NODE_ENV is \"production\". CORS restrictions are relaxed. This is likely a misconfiguration.');\n }\n\n return {\n origin: (origin: string | undefined, callback: (err: Error | null, allow?: boolean) => void) => {\n // Allow requests without Origin header only in development mode.\n // In production, undefined origin (e.g., curl, server-to-server) is rejected.\n if (isDev && !origin) {\n callback(null, true);\n return;\n }\n\n if (origin && whiteList?.includes(origin)) {\n callback(null, true);\n }\n else {\n callback(new Error('Not allowed by CORS'), false);\n }\n },\n credentials: true,\n ...rest,\n };\n}\n\n/**\n * Creates a CORS middleware function with the specified configuration.\n * This function creates a CORS middleware that can be used with both Express and NestJS applications,\n * applying the configured CORS options for origin validation and credential handling.\n *\n * @param options - CORS configuration options to apply to the middleware.\n * @returns A CORS middleware function ready to be used in Express or NestJS applications.\n */\nexport function createCors<T extends T_CorsType>(options: T_CorsOptions<T>) {\n return cors<cors.CorsRequest>(createCorsOptions(options));\n}\n\n/**\n * Creates a session middleware function with the specified configuration.\n * This function creates an Express session middleware that can be used to handle user sessions\n * with the provided session options including secret, cookie settings, and storage configuration.\n *\n * @param options - Session configuration options including secret, cookie settings, and storage.\n * @returns A session middleware function ready to be used in Express applications.\n */\nexport function createSession(options: SessionOptions): RequestHandler {\n if (!options.secret) {\n throw new Error('Session secret is required. Provide a strong secret string.');\n }\n\n if (!options.store && process.env['NODE_ENV'] === 'production') {\n console.warn('[Session] WARNING: No session store configured in production. The default MemoryStore leaks memory and loses sessions on restart. Use connect-redis, connect-mongo, or another production store.');\n }\n\n const secureDefaults: Partial<SessionOptions> = {\n resave: false,\n saveUninitialized: false,\n cookie: {\n httpOnly: true,\n sameSite: 'lax',\n secure: process.env['NODE_ENV'] === 'production',\n maxAge: 24 * 60 * 60 * 1000, // 24 hours\n },\n };\n\n return session({\n ...secureDefaults,\n ...options,\n cookie: { ...secureDefaults.cookie, ...options.cookie },\n });\n}\n\n/**\n * Sets up common middleware for Express applications.\n * This function configures essential middleware including:\n * - Trust proxy settings for proper IP handling\n * - Cookie parsing for request cookies\n * - URL-encoded body parsing for form data\n * - Compression for response optimization\n * - User agent parsing for device/browser detection\n *\n * @param app - The Express application instance to configure with middleware.\n * @param isDev - Whether the application is running in development mode.\n * @param jsonLimit - Maximum request body size for JSON payloads.\n * @param trustProxy - Trust proxy setting; pass a truthy value to enable.\n * @param rateLimitOptions - Rate limit configuration, or `false` to disable.\n */\nfunction setupMiddleware(\n app: Application,\n isDev = false,\n jsonLimit = '1mb',\n trustProxy: boolean | number | string | string[] = 1,\n rateLimitOptions: false | import('./express.type.js').I_RateLimitOptions = {},\n) {\n if (trustProxy) {\n app.set('trust proxy', trustProxy);\n }\n\n app.use(\n helmet({\n crossOriginEmbedderPolicy: isDev ? false : undefined,\n contentSecurityPolicy: isDev ? false : undefined,\n }),\n );\n\n if (rateLimitOptions !== false) {\n app.use(\n rateLimit({\n windowMs: rateLimitOptions.windowMs ?? 15 * 60 * 1000,\n limit: rateLimitOptions.limit ?? 1000,\n standardHeaders: true,\n legacyHeaders: false,\n ...(rateLimitOptions.store !== undefined && { store: rateLimitOptions.store }),\n ...(rateLimitOptions.skip !== undefined && { skip: rateLimitOptions.skip }),\n }),\n );\n }\n app.use(cookieParser());\n app.use(express.json({ limit: jsonLimit }));\n app.use(express.urlencoded({ extended: true, limit: jsonLimit }));\n app.use(compression());\n app.use(useragent());\n}\n\n/**\n * Sets up static file serving for Express applications.\n * This function configures static file serving for the specified folders,\n * making files in those directories accessible via HTTP requests.\n *\n * @param app - The Express application instance to configure with static file serving.\n * @param staticFolders - A string or array of strings representing the paths to serve statically.\n */\nfunction setupStaticFolders(app: Application, staticFolders?: string | string[]) {\n if (staticFolders) {\n const statics = Array.isArray(staticFolders) ? staticFolders : [staticFolders];\n statics.forEach((folder) => {\n app.use(`/${folder}`, express.static(folder));\n });\n }\n}\n\n/**\n * Creates and configures an Express application with common middleware and settings.\n * This function sets up a complete Express application with:\n * - Essential middleware (cookies, body parsing, compression, user agent)\n * - Static file serving for specified folders\n * - GraphQL upload support for file uploads\n *\n * @remarks\n * **Requires Express 5.x** — This module uses Express 5 APIs and is not compatible with Express 4.\n * The peer dependency requires `express >= 5.0.0`.\n *\n * @param options - Optional configuration for the Express application including static folder paths.\n * @returns A configured Express application instance ready for use.\n */\nexport function createExpress(options?: I_ExpressOptions): Application {\n const app = express();\n\n setupMiddleware(app, options?.isDev, options?.jsonLimit, options?.trustProxy, options?.rateLimit);\n setupStaticFolders(app, options?.static);\n const uploadMiddleware = graphqlUploadExpress({\n maxFileSize: options?.maxFileSize ?? 10_000_000,\n maxFiles: options?.maxFiles ?? 10,\n });\n app.use(options?.uploadPath ?? '/graphql', uploadMiddleware);\n\n return app;\n}\n\n/**\n * Creates and configures a NestJS application with Express integration.\n * This function sets up a NestJS application with:\n * - Express HTTP adapter configuration\n * - Common middleware (cookies, body parsing, compression, user agent)\n * - Static file serving for specified folders\n * - Global filters and pipes if provided\n *\n * @param options - Configuration options for the NestJS application including module, static folders, filters, and pipes.\n * @returns A promise that resolves to a configured NestJS application instance.\n */\nexport async function createNest(options: I_NestOptions): Promise<INestApplication> {\n const app = await NestFactory.create(options.module);\n\n setupMiddleware(app.getHttpAdapter().getInstance(), options.isDev, options.jsonLimit, options.trustProxy, options.rateLimit);\n setupStaticFolders(app.getHttpAdapter().getInstance(), options.static);\n\n if (options.filters) {\n app.useGlobalFilters(...options.filters);\n }\n\n if (options.pipes) {\n app.useGlobalPipes(...options.pipes);\n }\n\n return app;\n}\n\nexport { bodyParser, express };\n"],"mappings":"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"}
|
package/dist/node/fs/fs.util.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import e from "
|
|
2
|
-
import t from "
|
|
1
|
+
import e from "node:path";
|
|
2
|
+
import t from "fs-extra";
|
|
3
3
|
//#region src/node/fs/fs.util.ts
|
|
4
|
-
var n =
|
|
5
|
-
function d(
|
|
6
|
-
|
|
4
|
+
var n = t, { lstatSync: r, readdirSync: i, mkdirSync: a, readFileSync: o, unlinkSync: s, statSync: c, createWriteStream: l } = t, u = t.readJsonSync;
|
|
5
|
+
function d(e, n, r) {
|
|
6
|
+
t.writeFileSync(e, n, r ?? "utf-8");
|
|
7
7
|
}
|
|
8
|
-
function f(
|
|
9
|
-
|
|
8
|
+
function f(e, n, r) {
|
|
9
|
+
t.appendFileSync(e, n, r ?? "utf-8");
|
|
10
10
|
}
|
|
11
|
-
function p(...
|
|
12
|
-
return
|
|
11
|
+
function p(...e) {
|
|
12
|
+
return e.every((e) => t.pathExistsSync(e));
|
|
13
13
|
}
|
|
14
|
-
function m(...
|
|
15
|
-
|
|
16
|
-
p(
|
|
14
|
+
function m(...e) {
|
|
15
|
+
e.forEach((e) => {
|
|
16
|
+
p(e) && t.removeSync(e);
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
function h(n, r, i = {}) {
|
|
20
20
|
let { extensions: a, ...o } = i;
|
|
21
|
-
|
|
22
|
-
filter: (
|
|
21
|
+
t.copySync(n, r, {
|
|
22
|
+
filter: (t) => c(t).isDirectory() || !a || a.length === 0 ? !0 : a.includes(e.extname(t)),
|
|
23
23
|
...o
|
|
24
24
|
});
|
|
25
25
|
}
|
package/dist/node/mongo/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { MONGO_MIGRATE_OPTIONS as e, MONGO_SLUG_MAX_ATTEMPTS as t } from "./mongo.constant.js";
|
|
2
2
|
import { convertEnumToModelName as n, mongo as r } from "./mongo.util.js";
|
|
3
3
|
import { applyNestedPopulate as i } from "./mongo.populate.js";
|
|
4
|
-
import { filterDynamicVirtualsFromPopulate as a, isMongooseDoc as o,
|
|
5
|
-
import { MongooseController as
|
|
6
|
-
import { MongoController as
|
|
7
|
-
import { C_Collection as
|
|
8
|
-
export {
|
|
4
|
+
import { filterDynamicVirtualsFromPopulate as a, isMongooseDoc as o, populateDynamicVirtuals as s, remapDynamicPopulate as c } from "./mongo.dynamic-populate.js";
|
|
5
|
+
import { MongooseController as l } from "./mongo.controller.mongoose.js";
|
|
6
|
+
import { MongoController as u } from "./mongo.controller.native.js";
|
|
7
|
+
import { C_Collection as d, C_Db as f, C_Document as p, C_Model as m } from "./mongo.type.js";
|
|
8
|
+
export { d as C_Collection, f as C_Db, p as C_Document, m as C_Model, e as MONGO_MIGRATE_OPTIONS, t as MONGO_SLUG_MAX_ATTEMPTS, u as MongoController, l as MongooseController, i as applyNestedPopulate, n as convertEnumToModelName, a as filterDynamicVirtualsFromPopulate, o as isMongooseDoc, r as mongo, s as populateDynamicVirtuals, c as remapDynamicPopulate };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { isObject as e } from "../../util/common/common.util.js";
|
|
2
|
+
import { RESPONSE_STATUS as t } from "../../constant/response-status.js";
|
|
3
|
+
import { normalizeMongoFilter as n } from "../../util/object/object.util.js";
|
|
4
|
+
import { generateRandomString as r, generateShortId as i, generateSlug as a } from "../../util/string/string.util.js";
|
|
5
|
+
import { catchError as o, log as s } from "../log/log.util.js";
|
|
5
6
|
import "./mongo.constant.js";
|
|
6
|
-
import { filterDynamicVirtualsFromPopulate as
|
|
7
|
+
import { filterDynamicVirtualsFromPopulate as c, populateDynamicVirtuals as l } from "./mongo.dynamic-populate.js";
|
|
7
8
|
//#region src/node/mongo/mongo.controller.mongoose.ts
|
|
8
9
|
function u(e) {
|
|
9
10
|
return e?.toObject?.() ?? e;
|
|
@@ -34,46 +35,46 @@ var d = class {
|
|
|
34
35
|
let n = this.getDynamicVirtuals();
|
|
35
36
|
return n && n.length > 0 && e.length > 0 ? await l(this.model.base, e, n, t, void 0, this.model) : e;
|
|
36
37
|
}
|
|
37
|
-
async findOne(
|
|
38
|
+
async findOne(e = {}, r = {}, i = {}, a) {
|
|
38
39
|
try {
|
|
39
|
-
let
|
|
40
|
-
l &&
|
|
41
|
-
let d = await
|
|
40
|
+
let o = n(e), s = this.model.findOne(o, r, i).maxTimeMS(3e4).lean(), l = c(a, this.getDynamicVirtuals());
|
|
41
|
+
l && s.populate(l);
|
|
42
|
+
let d = await s.exec();
|
|
42
43
|
return d ? {
|
|
43
44
|
success: !0,
|
|
44
|
-
result: u(await this.populateDynamicVirtualsForDocument(d,
|
|
45
|
+
result: u(await this.populateDynamicVirtualsForDocument(d, a))
|
|
45
46
|
} : {
|
|
46
47
|
success: !1,
|
|
47
48
|
message: `No ${this.getModelName()} found.`,
|
|
48
|
-
code:
|
|
49
|
+
code: t.NOT_FOUND.CODE
|
|
49
50
|
};
|
|
50
51
|
} catch (e) {
|
|
51
|
-
return
|
|
52
|
+
return o(e);
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
|
-
async findAll(e = {},
|
|
55
|
+
async findAll(e = {}, t = {}, r = {}, i) {
|
|
55
56
|
try {
|
|
56
|
-
let a =
|
|
57
|
-
r.limit ||
|
|
58
|
-
let l =
|
|
59
|
-
l &&
|
|
60
|
-
let d = await
|
|
61
|
-
return p &&
|
|
57
|
+
let a = n(e), o = this.model.find(a, t, r).maxTimeMS(3e4).lean();
|
|
58
|
+
r.limit || o.limit(this.defaultLimit);
|
|
59
|
+
let l = c(i, this.getDynamicVirtuals());
|
|
60
|
+
l && o.populate(l);
|
|
61
|
+
let d = await o.exec(), f = await this.populateDynamicVirtualsForDocuments(d, i), p = f.length === this.defaultLimit && !r.limit;
|
|
62
|
+
return p && s.warn(`[${this.getModelName()}] findAll returned exactly ${this.defaultLimit} documents (the default limit). Results may be truncated. Consider using pagination or setting an explicit limit.`), {
|
|
62
63
|
success: !0,
|
|
63
64
|
result: f.map((e) => u(e)),
|
|
64
65
|
truncated: p
|
|
65
66
|
};
|
|
66
67
|
} catch (e) {
|
|
67
|
-
return
|
|
68
|
+
return o(e);
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
|
-
async findPaging(e = {},
|
|
71
|
+
async findPaging(e = {}, t = {}) {
|
|
71
72
|
try {
|
|
72
|
-
let r =
|
|
73
|
-
|
|
73
|
+
let r = n(e), i = this.getDynamicVirtuals(), a = { ...t };
|
|
74
|
+
t.populate && (a.populate = c(t.populate, i));
|
|
74
75
|
let o = await this.model.paginate(r, a);
|
|
75
76
|
if (i && i.length > 0) {
|
|
76
|
-
let e = await this.populateDynamicVirtualsForDocuments(o.docs,
|
|
77
|
+
let e = await this.populateDynamicVirtualsForDocuments(o.docs, t.populate);
|
|
77
78
|
return {
|
|
78
79
|
success: !0,
|
|
79
80
|
result: {
|
|
@@ -90,13 +91,13 @@ var d = class {
|
|
|
90
91
|
}
|
|
91
92
|
};
|
|
92
93
|
} catch (e) {
|
|
93
|
-
return
|
|
94
|
+
return o(e);
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
async findPagingAggregate(e, t = {}) {
|
|
97
98
|
try {
|
|
98
99
|
let n = this.getDynamicVirtuals(), r = { ...t };
|
|
99
|
-
t.populate && (r.populate =
|
|
100
|
+
t.populate && (r.populate = c(t.populate, n));
|
|
100
101
|
let i = await this.model.aggregatePaginate(this.model.aggregate(e), r), a = await this.populateDynamicVirtualsForDocuments(i.docs, t.populate);
|
|
101
102
|
return {
|
|
102
103
|
success: !0,
|
|
@@ -106,18 +107,18 @@ var d = class {
|
|
|
106
107
|
}
|
|
107
108
|
};
|
|
108
109
|
} catch (e) {
|
|
109
|
-
return
|
|
110
|
+
return o(e);
|
|
110
111
|
}
|
|
111
112
|
}
|
|
112
113
|
async count(e = {}) {
|
|
113
114
|
try {
|
|
114
|
-
let
|
|
115
|
+
let t = n(e);
|
|
115
116
|
return {
|
|
116
117
|
success: !0,
|
|
117
|
-
result: await this.model.countDocuments(
|
|
118
|
+
result: await this.model.countDocuments(t)
|
|
118
119
|
};
|
|
119
120
|
} catch (e) {
|
|
120
|
-
return
|
|
121
|
+
return o(e);
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
124
|
async createOne(e) {
|
|
@@ -128,7 +129,7 @@ var d = class {
|
|
|
128
129
|
result: t?.toObject?.() ?? t
|
|
129
130
|
};
|
|
130
131
|
} catch (e) {
|
|
131
|
-
return
|
|
132
|
+
return o(e);
|
|
132
133
|
}
|
|
133
134
|
}
|
|
134
135
|
async createMany(e, t = {}) {
|
|
@@ -138,12 +139,12 @@ var d = class {
|
|
|
138
139
|
result: (await this.model.insertMany(e, t)).map((e) => e?.toObject?.() ?? e)
|
|
139
140
|
};
|
|
140
141
|
} catch (e) {
|
|
141
|
-
return
|
|
142
|
+
return o(e);
|
|
142
143
|
}
|
|
143
144
|
}
|
|
144
|
-
async updateOne(
|
|
145
|
+
async updateOne(e = {}, r = {}, i = {}) {
|
|
145
146
|
try {
|
|
146
|
-
let a =
|
|
147
|
+
let a = n(e), o = await this.model.findOneAndUpdate(a, r, {
|
|
147
148
|
new: !0,
|
|
148
149
|
...i
|
|
149
150
|
}).exec();
|
|
@@ -153,66 +154,66 @@ var d = class {
|
|
|
153
154
|
} : {
|
|
154
155
|
success: !1,
|
|
155
156
|
message: `Failed to update ${this.getModelName()}.`,
|
|
156
|
-
code:
|
|
157
|
+
code: t.NOT_FOUND.CODE
|
|
157
158
|
};
|
|
158
159
|
} catch (e) {
|
|
159
|
-
return
|
|
160
|
+
return o(e);
|
|
160
161
|
}
|
|
161
162
|
}
|
|
162
|
-
async updateMany(e = {},
|
|
163
|
+
async updateMany(e = {}, t = {}, r = {}) {
|
|
163
164
|
try {
|
|
164
|
-
let i =
|
|
165
|
+
let i = n(e);
|
|
165
166
|
return {
|
|
166
167
|
success: !0,
|
|
167
|
-
result: await this.model.updateMany(i,
|
|
168
|
+
result: await this.model.updateMany(i, t, r).exec()
|
|
168
169
|
};
|
|
169
170
|
} catch (e) {
|
|
170
|
-
return
|
|
171
|
+
return o(e);
|
|
171
172
|
}
|
|
172
173
|
}
|
|
173
|
-
async deleteOne(
|
|
174
|
+
async deleteOne(e = {}, r = {}) {
|
|
174
175
|
try {
|
|
175
|
-
let i =
|
|
176
|
+
let i = n(e), a = await this.model.findOneAndDelete(i, r).exec();
|
|
176
177
|
return a ? {
|
|
177
178
|
success: !0,
|
|
178
179
|
result: a?.toObject?.() ?? a
|
|
179
180
|
} : {
|
|
180
181
|
success: !1,
|
|
181
182
|
message: `No ${this.getModelName()} found to delete.`,
|
|
182
|
-
code:
|
|
183
|
+
code: t.NOT_FOUND.CODE
|
|
183
184
|
};
|
|
184
185
|
} catch (e) {
|
|
185
|
-
return
|
|
186
|
+
return o(e);
|
|
186
187
|
}
|
|
187
188
|
}
|
|
188
|
-
async deleteMany(
|
|
189
|
+
async deleteMany(e = {}, r = {}) {
|
|
189
190
|
try {
|
|
190
|
-
let i =
|
|
191
|
+
let i = n(e), a = await this.model.deleteMany(i, r).exec();
|
|
191
192
|
return a.deletedCount === 0 ? {
|
|
192
193
|
success: !1,
|
|
193
194
|
message: "No documents found to delete.",
|
|
194
|
-
code:
|
|
195
|
+
code: t.NOT_FOUND.CODE
|
|
195
196
|
} : {
|
|
196
197
|
success: !0,
|
|
197
198
|
result: a
|
|
198
199
|
};
|
|
199
200
|
} catch (e) {
|
|
200
|
-
return
|
|
201
|
+
return o(e);
|
|
201
202
|
}
|
|
202
203
|
}
|
|
203
|
-
async createShortId(
|
|
204
|
+
async createShortId(e, n = 4) {
|
|
204
205
|
try {
|
|
205
|
-
let
|
|
206
|
+
let r = Array.from({ length: 10 }, (t, r) => i(e, r + n)), a = await this.model.find({ shortId: { $in: r } }).select("shortId").lean(), o = new Set(a.map((e) => e.shortId)), s = r.find((e) => !o.has(e));
|
|
206
207
|
return s ? {
|
|
207
208
|
success: !0,
|
|
208
209
|
result: s
|
|
209
210
|
} : {
|
|
210
211
|
success: !1,
|
|
211
212
|
message: "Failed to create a unique shortId",
|
|
212
|
-
code:
|
|
213
|
+
code: t.INTERNAL_SERVER_ERROR.CODE
|
|
213
214
|
};
|
|
214
215
|
} catch (e) {
|
|
215
|
-
return
|
|
216
|
+
return o(e);
|
|
216
217
|
}
|
|
217
218
|
}
|
|
218
219
|
createSlugQuery({ slug: e, field: t, isObject: n, haveHistory: r = !1, filter: i }) {
|
|
@@ -225,62 +226,62 @@ var d = class {
|
|
|
225
226
|
$or: [{ slug: e }, ...r ? [{ slugHistory: e }] : []]
|
|
226
227
|
};
|
|
227
228
|
}
|
|
228
|
-
async createUniqueSlug({ slug: e, field: t, isObject:
|
|
229
|
+
async createUniqueSlug({ slug: e, field: t, isObject: n, haveHistory: i, filter: o }) {
|
|
229
230
|
if (!e || typeof e != "string") throw Error("Invalid slug provided: must be a non-empty string");
|
|
230
|
-
let s =
|
|
231
|
+
let s = a(e);
|
|
231
232
|
if (!await this.model.exists(this.createSlugQuery({
|
|
232
233
|
slug: s,
|
|
233
234
|
field: t,
|
|
234
|
-
isObject:
|
|
235
|
-
haveHistory:
|
|
235
|
+
isObject: n,
|
|
236
|
+
haveHistory: i,
|
|
236
237
|
filter: o
|
|
237
238
|
}))) return s;
|
|
238
239
|
let c = Array.from({ length: 100 }, (e, t) => `${s}-${t + 1}`), l = c.map((e) => this.createSlugQuery({
|
|
239
240
|
slug: e,
|
|
240
241
|
field: t,
|
|
241
|
-
isObject:
|
|
242
|
-
haveHistory:
|
|
242
|
+
isObject: n,
|
|
243
|
+
haveHistory: i,
|
|
243
244
|
filter: o
|
|
244
|
-
})), u =
|
|
245
|
-
return c.find((e) => !f.has(e)) || `${s}-${Date.now()}-${
|
|
245
|
+
})), u = n ? `slug.${t}` : "slug", d = await this.model.find({ $or: l.map((e) => e.$or).flat() }).select(u).lean(), f = new Set(d.map((e) => n ? e.slug?.[t] : e.slug));
|
|
246
|
+
return c.find((e) => !f.has(e)) || `${s}-${Date.now()}-${r(6)}`;
|
|
246
247
|
}
|
|
247
|
-
async createSlug({ field:
|
|
248
|
+
async createSlug({ field: t, from: n, filter: r, haveHistory: i }) {
|
|
248
249
|
try {
|
|
249
|
-
let
|
|
250
|
-
return
|
|
250
|
+
let a = n[t];
|
|
251
|
+
return e(a) ? {
|
|
251
252
|
success: !0,
|
|
252
|
-
result: Object.fromEntries(await Promise.all(Object.entries(
|
|
253
|
+
result: Object.fromEntries(await Promise.all(Object.entries(a).map(async ([e, t]) => [e, await this.createUniqueSlug({
|
|
253
254
|
slug: t,
|
|
254
255
|
field: e,
|
|
255
256
|
isObject: !0,
|
|
256
|
-
haveHistory:
|
|
257
|
-
filter:
|
|
257
|
+
haveHistory: i,
|
|
258
|
+
filter: r
|
|
258
259
|
})])))
|
|
259
260
|
} : {
|
|
260
261
|
success: !0,
|
|
261
262
|
result: await this.createUniqueSlug({
|
|
262
|
-
slug:
|
|
263
|
-
field:
|
|
263
|
+
slug: a,
|
|
264
|
+
field: t,
|
|
264
265
|
isObject: !1,
|
|
265
|
-
haveHistory:
|
|
266
|
-
filter:
|
|
266
|
+
haveHistory: i,
|
|
267
|
+
filter: r
|
|
267
268
|
})
|
|
268
269
|
};
|
|
269
270
|
} catch (e) {
|
|
270
|
-
return
|
|
271
|
+
return o(e);
|
|
271
272
|
}
|
|
272
273
|
}
|
|
273
|
-
async checkSlug({ slug:
|
|
274
|
+
async checkSlug({ slug: t, field: n, from: r, filter: i, haveHistory: s }) {
|
|
274
275
|
try {
|
|
275
|
-
let
|
|
276
|
-
if (
|
|
277
|
-
let e = Object.values(
|
|
276
|
+
let o = r[n];
|
|
277
|
+
if (e(o)) {
|
|
278
|
+
let e = Object.values(o).map((e) => a(e));
|
|
278
279
|
return (await Promise.all(e.map((e) => this.model.exists(this.createSlugQuery({
|
|
279
280
|
slug: e,
|
|
280
|
-
field:
|
|
281
|
+
field: n,
|
|
281
282
|
isObject: !0,
|
|
282
|
-
haveHistory:
|
|
283
|
-
filter:
|
|
283
|
+
haveHistory: s,
|
|
284
|
+
filter: i
|
|
284
285
|
}))))).some((e) => e) ? {
|
|
285
286
|
success: !0,
|
|
286
287
|
result: !0
|
|
@@ -289,18 +290,18 @@ var d = class {
|
|
|
289
290
|
result: !1
|
|
290
291
|
};
|
|
291
292
|
}
|
|
292
|
-
let
|
|
293
|
+
let c = a(t);
|
|
293
294
|
return {
|
|
294
295
|
success: !0,
|
|
295
296
|
result: await this.model.exists(this.createSlugQuery({
|
|
296
|
-
slug:
|
|
297
|
-
field:
|
|
297
|
+
slug: c,
|
|
298
|
+
field: n,
|
|
298
299
|
isObject: !1,
|
|
299
|
-
filter:
|
|
300
|
+
filter: i
|
|
300
301
|
})) !== null
|
|
301
302
|
};
|
|
302
303
|
} catch (e) {
|
|
303
|
-
return
|
|
304
|
+
return o(e);
|
|
304
305
|
}
|
|
305
306
|
}
|
|
306
307
|
async aggregate(e) {
|
|
@@ -310,7 +311,7 @@ var d = class {
|
|
|
310
311
|
result: await this.model.aggregate(e)
|
|
311
312
|
};
|
|
312
313
|
} catch (e) {
|
|
313
|
-
return
|
|
314
|
+
return o(e);
|
|
314
315
|
}
|
|
315
316
|
}
|
|
316
317
|
async distinct(e, t = {}, n = {}) {
|
|
@@ -320,7 +321,7 @@ var d = class {
|
|
|
320
321
|
result: await this.model.distinct(e, t, n)
|
|
321
322
|
};
|
|
322
323
|
} catch (e) {
|
|
323
|
-
return
|
|
324
|
+
return o(e);
|
|
324
325
|
}
|
|
325
326
|
}
|
|
326
327
|
};
|