elseware-nodejs 1.7.3 → 1.7.5

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/index.d.cts CHANGED
@@ -1,8 +1,9 @@
1
1
  import * as express from 'express';
2
2
  import { Request, Response, NextFunction } from 'express';
3
3
  import { Model, PopulateOptions, Query } from 'mongoose';
4
- import Joi, { Schema } from 'joi';
4
+ import { ZodSchema } from 'zod';
5
5
  import { CorsOptions } from 'cors';
6
+ import { Schema } from 'joi';
6
7
  import { SignOptions, JwtPayload } from 'jsonwebtoken';
7
8
 
8
9
  /**
@@ -75,11 +76,10 @@ interface DatabaseConfig {
75
76
  }
76
77
  declare function connectMongoDB(config: DatabaseConfig): Promise<void>;
77
78
 
78
- /**
79
- * Generic env loader for Elseware apps
80
- * App provides its own Joi schema
81
- */
82
- declare function loadEnv<T>(schema: Joi.ObjectSchema<T>): T;
79
+ declare function loadEnv(options: {
80
+ schema: ZodSchema;
81
+ transform?: (env: any) => any;
82
+ }): any;
83
83
 
84
84
  interface LoggerOptions {
85
85
  timestamp?: boolean;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import * as express from 'express';
2
2
  import { Request, Response, NextFunction } from 'express';
3
3
  import { Model, PopulateOptions, Query } from 'mongoose';
4
- import Joi, { Schema } from 'joi';
4
+ import { ZodSchema } from 'zod';
5
5
  import { CorsOptions } from 'cors';
6
+ import { Schema } from 'joi';
6
7
  import { SignOptions, JwtPayload } from 'jsonwebtoken';
7
8
 
8
9
  /**
@@ -75,11 +76,10 @@ interface DatabaseConfig {
75
76
  }
76
77
  declare function connectMongoDB(config: DatabaseConfig): Promise<void>;
77
78
 
78
- /**
79
- * Generic env loader for Elseware apps
80
- * App provides its own Joi schema
81
- */
82
- declare function loadEnv<T>(schema: Joi.ObjectSchema<T>): T;
79
+ declare function loadEnv(options: {
80
+ schema: ZodSchema;
81
+ transform?: (env: any) => any;
82
+ }): any;
83
83
 
84
84
  interface LoggerOptions {
85
85
  timestamp?: boolean;
package/dist/index.js CHANGED
@@ -322,17 +322,31 @@ async function connectMongoDB(config) {
322
322
  process.exit(1);
323
323
  }
324
324
  }
325
- dotenv.config({ quiet: true });
326
- function loadEnv(schema) {
327
- const { value, error } = schema.validate(process.env, {
328
- abortEarly: false,
329
- allowUnknown: true
325
+ dotenv.config();
326
+ function loadEnv(options) {
327
+ const result = options.schema.safeParse(process.env);
328
+ if (!result.success) {
329
+ handleError(result.error);
330
+ }
331
+ logger.success("\u2705 Env Configurations validated");
332
+ return options.transform ? options.transform(result.data) : result.data;
333
+ }
334
+ function handleError(error) {
335
+ console.error("\u274C ENV VALIDATION FAILED");
336
+ const grouped = {};
337
+ error.issues.forEach((err) => {
338
+ const key = err.path.join(".") || "unknown";
339
+ if (!grouped[key]) grouped[key] = [];
340
+ grouped[key].push(err.message);
330
341
  });
331
- if (error) {
332
- throw new Error(`\u274C Env validation error: ${error.message}`);
333
- }
334
- logger.success("Configurations passed");
335
- return value;
342
+ Object.entries(grouped).forEach(([key, messages]) => {
343
+ console.error(`\u{1F539} ${key}`);
344
+ messages.forEach((msg) => {
345
+ console.error(` - ${msg}`);
346
+ });
347
+ });
348
+ console.error("\u{1F6AB} Application startup aborted.\n");
349
+ process.exit(1);
336
350
  }
337
351
 
338
352
  // src/configs/cors/allowedOrigins.ts
@@ -5319,16 +5333,20 @@ var TemplateEngine = class {
5319
5333
  static partialsLoaded = {};
5320
5334
  static cssCache = {};
5321
5335
  static registerPartials(templateDir) {
5322
- const partialsDir = path.join(templateDir, "partials");
5323
- if (!fs3.existsSync(partialsDir) || this.partialsLoaded[templateDir]) return;
5324
- const files = fs3.readdirSync(partialsDir);
5325
- for (const file of files) {
5326
- if (file.endsWith(".hbs")) {
5327
- const name = path.basename(file, ".hbs");
5328
- const content = fs3.readFileSync(path.join(partialsDir, file), "utf-8");
5329
- Handlebars.registerPartial(name, content);
5336
+ if (this.partialsLoaded[templateDir]) return;
5337
+ const registerFromDir = (dirPath) => {
5338
+ if (!fs3.existsSync(dirPath)) return;
5339
+ const files = fs3.readdirSync(dirPath);
5340
+ for (const file of files) {
5341
+ if (file.endsWith(".hbs")) {
5342
+ const name = path.basename(file, ".hbs");
5343
+ const content = fs3.readFileSync(path.join(dirPath, file), "utf-8");
5344
+ Handlebars.registerPartial(name, content);
5345
+ }
5330
5346
  }
5331
- }
5347
+ };
5348
+ registerFromDir(path.join(templateDir, "partials"));
5349
+ registerFromDir(path.join(templateDir, "layouts"));
5332
5350
  this.partialsLoaded[templateDir] = true;
5333
5351
  }
5334
5352
  static loadAllCSS(stylesDir) {