elseware-nodejs 1.7.9 → 1.8.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/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as express from 'express';
2
2
  import { Request, Response, NextFunction } from 'express';
3
- import { Model, PopulateOptions, Query } from 'mongoose';
4
- import { ZodSchema } from 'zod';
3
+ import { Model, PopulateOptions, Query, UpdateQuery } from 'mongoose';
4
+ import { ZodTypeAny, infer } from 'zod';
5
5
  import { CorsOptions } from 'cors';
6
6
  import { Schema } from 'joi';
7
7
  import { SignOptions, JwtPayload } from 'jsonwebtoken';
@@ -76,10 +76,19 @@ interface DatabaseConfig {
76
76
  }
77
77
  declare function connectMongoDB(config: DatabaseConfig): Promise<void>;
78
78
 
79
- declare function loadEnv(options: {
80
- schema: ZodSchema;
81
- transform?: (env: any) => any;
82
- }): any;
79
+ /**
80
+ * Overload 1: No transform → return schema inferred type
81
+ */
82
+ declare function loadEnv<TSchema extends ZodTypeAny>(options: {
83
+ schema: TSchema;
84
+ }): infer<TSchema>;
85
+ /**
86
+ * Overload 2: With transform → return transformed type
87
+ */
88
+ declare function loadEnv<TSchema extends ZodTypeAny, TConfig>(options: {
89
+ schema: TSchema;
90
+ transform: (env: infer<TSchema>) => TConfig;
91
+ }): TConfig;
83
92
 
84
93
  interface LoggerOptions {
85
94
  timestamp?: boolean;
@@ -1817,6 +1826,47 @@ declare const GlobalErrorHandler: (isProd?: boolean) => (err: unknown, _req: Req
1817
1826
 
1818
1827
  declare const validate: (schema: Schema) => (req: Request, _res: Response, next: NextFunction) => void;
1819
1828
 
1829
+ interface IRepository<T> {
1830
+ findAll(filter?: any, options?: any): Promise<T[]>;
1831
+ findById(id: string): Promise<T | null>;
1832
+ findOne(filter: any): Promise<T | null>;
1833
+ create(data: Partial<T>): Promise<T>;
1834
+ updateById(id: string, data: Partial<T>): Promise<T | null>;
1835
+ deleteById(id: string): Promise<T | null>;
1836
+ }
1837
+
1838
+ declare class BaseMongoRepository<T> implements IRepository<T> {
1839
+ protected model: Model<T>;
1840
+ constructor(model: Model<T>);
1841
+ findAll(filter?: Record<string, any>, options?: {
1842
+ select?: string;
1843
+ sort?: any;
1844
+ limit?: number;
1845
+ skip?: number;
1846
+ }): Promise<T[]>;
1847
+ findById(id: string): Promise<T | null>;
1848
+ findOne(filter: Record<string, any>): Promise<T | null>;
1849
+ create(data: Partial<T>): Promise<T>;
1850
+ updateById(id: string, data: UpdateQuery<T>): Promise<T | null>;
1851
+ deleteById(id: string): Promise<T | null>;
1852
+ }
1853
+
1854
+ declare class BasePostgresRepository<T> implements IRepository<T> {
1855
+ protected model: any;
1856
+ constructor(model: any);
1857
+ findAll(filter?: Record<string, any>, options?: {
1858
+ select?: any;
1859
+ sort?: any;
1860
+ limit?: number;
1861
+ skip?: number;
1862
+ }): Promise<T[]>;
1863
+ findById(id: string): Promise<T | null>;
1864
+ findOne(filter: Record<string, any>): Promise<T | null>;
1865
+ create(data: Partial<T>): Promise<T>;
1866
+ updateById(id: string, data: Partial<T>): Promise<T | null>;
1867
+ deleteById(id: string): Promise<T | null>;
1868
+ }
1869
+
1820
1870
  interface AzureBlobStorageConfig {
1821
1871
  connectionString: string;
1822
1872
  accountName: string;
@@ -1963,4 +2013,4 @@ declare function toMinutes(ms: number): number;
1963
2013
  declare function toHours(ms: number): number;
1964
2014
  declare function sleep(ms: number): Promise<void>;
1965
2015
 
1966
- export { APIFactory, APIFeatures, APIResponse, AVLTree, AdjacencyList, AdjacencyMatrix, type AdjacentEdge, type AllowedOriginsOptions, AppError, type AzureBlobStorageConfig, AzureBlobStorageService, BPlusTree, BTree, BinaryHeap, BinarySearchTree, BinaryTree, BloomFilter, CircularArray, CircularLinkedList, CircularQueue, type CloudinaryConfig, CloudinaryService, ConsistentHash, CountMinSketch, type DatabaseConfig, Deque, type DirectedEdge, DirectedGraph, DisjointSetUnion, DoublyLinkedList, DynamicArray, type Edge, type EmailProvider, EmailService, FenwickTree, FibNode, FibonacciHeap, GlobalErrorHandler, Graph, HashMap, HashSet, HyperLogLog, type Interval, IntervalTree, JWTService, type JWTServiceOptions, KDTree, LFUCache, LRUCache, type LoggerOptions, MaxHeap, MaxStack, MinHeap, MinStack, MulterFileHandlerService, MultiSet, Node, OrderedSet, PairingHeap, PairingNode, type Point, type Point2D, PriorityQueue, type ProgressCallback, QuadTree, Queue, RadixTree, type Rect, RedBlackTree, SMTPProvider, SegmentTree, type SendEmailOptions, Set, SinglyLinkedList, SparseTable, SplayTree, Stack, StaticArray, SuffixArray, SuffixTree, TemplateEngine, TernarySearchTree, TreeNode, Trie, type UploadOptions, asyncHandler, authMiddleware, connectMongoDB, createAllowedOrigins, createCorsOptions, days, errorToString, hours, loadEnv, logger, milliseconds, minutes, pickFields, seconds, sleep, toHours, toMinutes, toSeconds, validate };
2016
+ export { APIFactory, APIFeatures, APIResponse, AVLTree, AdjacencyList, AdjacencyMatrix, type AdjacentEdge, type AllowedOriginsOptions, AppError, type AzureBlobStorageConfig, AzureBlobStorageService, BPlusTree, BTree, BaseMongoRepository, BasePostgresRepository, BinaryHeap, BinarySearchTree, BinaryTree, BloomFilter, CircularArray, CircularLinkedList, CircularQueue, type CloudinaryConfig, CloudinaryService, ConsistentHash, CountMinSketch, type DatabaseConfig, Deque, type DirectedEdge, DirectedGraph, DisjointSetUnion, DoublyLinkedList, DynamicArray, type Edge, type EmailProvider, EmailService, FenwickTree, FibNode, FibonacciHeap, GlobalErrorHandler, Graph, HashMap, HashSet, HyperLogLog, type IRepository, type Interval, IntervalTree, JWTService, type JWTServiceOptions, KDTree, LFUCache, LRUCache, type LoggerOptions, MaxHeap, MaxStack, MinHeap, MinStack, MulterFileHandlerService, MultiSet, Node, OrderedSet, PairingHeap, PairingNode, type Point, type Point2D, PriorityQueue, type ProgressCallback, QuadTree, Queue, RadixTree, type Rect, RedBlackTree, SMTPProvider, SegmentTree, type SendEmailOptions, Set, SinglyLinkedList, SparseTable, SplayTree, Stack, StaticArray, SuffixArray, SuffixTree, TemplateEngine, TernarySearchTree, TreeNode, Trie, type UploadOptions, asyncHandler, authMiddleware, connectMongoDB, createAllowedOrigins, createCorsOptions, days, errorToString, hours, loadEnv, logger, milliseconds, minutes, pickFields, seconds, sleep, toHours, toMinutes, toSeconds, validate };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as express from 'express';
2
2
  import { Request, Response, NextFunction } from 'express';
3
- import { Model, PopulateOptions, Query } from 'mongoose';
4
- import { ZodSchema } from 'zod';
3
+ import { Model, PopulateOptions, Query, UpdateQuery } from 'mongoose';
4
+ import { ZodTypeAny, infer } from 'zod';
5
5
  import { CorsOptions } from 'cors';
6
6
  import { Schema } from 'joi';
7
7
  import { SignOptions, JwtPayload } from 'jsonwebtoken';
@@ -76,10 +76,19 @@ interface DatabaseConfig {
76
76
  }
77
77
  declare function connectMongoDB(config: DatabaseConfig): Promise<void>;
78
78
 
79
- declare function loadEnv(options: {
80
- schema: ZodSchema;
81
- transform?: (env: any) => any;
82
- }): any;
79
+ /**
80
+ * Overload 1: No transform → return schema inferred type
81
+ */
82
+ declare function loadEnv<TSchema extends ZodTypeAny>(options: {
83
+ schema: TSchema;
84
+ }): infer<TSchema>;
85
+ /**
86
+ * Overload 2: With transform → return transformed type
87
+ */
88
+ declare function loadEnv<TSchema extends ZodTypeAny, TConfig>(options: {
89
+ schema: TSchema;
90
+ transform: (env: infer<TSchema>) => TConfig;
91
+ }): TConfig;
83
92
 
84
93
  interface LoggerOptions {
85
94
  timestamp?: boolean;
@@ -1817,6 +1826,47 @@ declare const GlobalErrorHandler: (isProd?: boolean) => (err: unknown, _req: Req
1817
1826
 
1818
1827
  declare const validate: (schema: Schema) => (req: Request, _res: Response, next: NextFunction) => void;
1819
1828
 
1829
+ interface IRepository<T> {
1830
+ findAll(filter?: any, options?: any): Promise<T[]>;
1831
+ findById(id: string): Promise<T | null>;
1832
+ findOne(filter: any): Promise<T | null>;
1833
+ create(data: Partial<T>): Promise<T>;
1834
+ updateById(id: string, data: Partial<T>): Promise<T | null>;
1835
+ deleteById(id: string): Promise<T | null>;
1836
+ }
1837
+
1838
+ declare class BaseMongoRepository<T> implements IRepository<T> {
1839
+ protected model: Model<T>;
1840
+ constructor(model: Model<T>);
1841
+ findAll(filter?: Record<string, any>, options?: {
1842
+ select?: string;
1843
+ sort?: any;
1844
+ limit?: number;
1845
+ skip?: number;
1846
+ }): Promise<T[]>;
1847
+ findById(id: string): Promise<T | null>;
1848
+ findOne(filter: Record<string, any>): Promise<T | null>;
1849
+ create(data: Partial<T>): Promise<T>;
1850
+ updateById(id: string, data: UpdateQuery<T>): Promise<T | null>;
1851
+ deleteById(id: string): Promise<T | null>;
1852
+ }
1853
+
1854
+ declare class BasePostgresRepository<T> implements IRepository<T> {
1855
+ protected model: any;
1856
+ constructor(model: any);
1857
+ findAll(filter?: Record<string, any>, options?: {
1858
+ select?: any;
1859
+ sort?: any;
1860
+ limit?: number;
1861
+ skip?: number;
1862
+ }): Promise<T[]>;
1863
+ findById(id: string): Promise<T | null>;
1864
+ findOne(filter: Record<string, any>): Promise<T | null>;
1865
+ create(data: Partial<T>): Promise<T>;
1866
+ updateById(id: string, data: Partial<T>): Promise<T | null>;
1867
+ deleteById(id: string): Promise<T | null>;
1868
+ }
1869
+
1820
1870
  interface AzureBlobStorageConfig {
1821
1871
  connectionString: string;
1822
1872
  accountName: string;
@@ -1963,4 +2013,4 @@ declare function toMinutes(ms: number): number;
1963
2013
  declare function toHours(ms: number): number;
1964
2014
  declare function sleep(ms: number): Promise<void>;
1965
2015
 
1966
- export { APIFactory, APIFeatures, APIResponse, AVLTree, AdjacencyList, AdjacencyMatrix, type AdjacentEdge, type AllowedOriginsOptions, AppError, type AzureBlobStorageConfig, AzureBlobStorageService, BPlusTree, BTree, BinaryHeap, BinarySearchTree, BinaryTree, BloomFilter, CircularArray, CircularLinkedList, CircularQueue, type CloudinaryConfig, CloudinaryService, ConsistentHash, CountMinSketch, type DatabaseConfig, Deque, type DirectedEdge, DirectedGraph, DisjointSetUnion, DoublyLinkedList, DynamicArray, type Edge, type EmailProvider, EmailService, FenwickTree, FibNode, FibonacciHeap, GlobalErrorHandler, Graph, HashMap, HashSet, HyperLogLog, type Interval, IntervalTree, JWTService, type JWTServiceOptions, KDTree, LFUCache, LRUCache, type LoggerOptions, MaxHeap, MaxStack, MinHeap, MinStack, MulterFileHandlerService, MultiSet, Node, OrderedSet, PairingHeap, PairingNode, type Point, type Point2D, PriorityQueue, type ProgressCallback, QuadTree, Queue, RadixTree, type Rect, RedBlackTree, SMTPProvider, SegmentTree, type SendEmailOptions, Set, SinglyLinkedList, SparseTable, SplayTree, Stack, StaticArray, SuffixArray, SuffixTree, TemplateEngine, TernarySearchTree, TreeNode, Trie, type UploadOptions, asyncHandler, authMiddleware, connectMongoDB, createAllowedOrigins, createCorsOptions, days, errorToString, hours, loadEnv, logger, milliseconds, minutes, pickFields, seconds, sleep, toHours, toMinutes, toSeconds, validate };
2016
+ export { APIFactory, APIFeatures, APIResponse, AVLTree, AdjacencyList, AdjacencyMatrix, type AdjacentEdge, type AllowedOriginsOptions, AppError, type AzureBlobStorageConfig, AzureBlobStorageService, BPlusTree, BTree, BaseMongoRepository, BasePostgresRepository, BinaryHeap, BinarySearchTree, BinaryTree, BloomFilter, CircularArray, CircularLinkedList, CircularQueue, type CloudinaryConfig, CloudinaryService, ConsistentHash, CountMinSketch, type DatabaseConfig, Deque, type DirectedEdge, DirectedGraph, DisjointSetUnion, DoublyLinkedList, DynamicArray, type Edge, type EmailProvider, EmailService, FenwickTree, FibNode, FibonacciHeap, GlobalErrorHandler, Graph, HashMap, HashSet, HyperLogLog, type IRepository, type Interval, IntervalTree, JWTService, type JWTServiceOptions, KDTree, LFUCache, LRUCache, type LoggerOptions, MaxHeap, MaxStack, MinHeap, MinStack, MulterFileHandlerService, MultiSet, Node, OrderedSet, PairingHeap, PairingNode, type Point, type Point2D, PriorityQueue, type ProgressCallback, QuadTree, Queue, RadixTree, type Rect, RedBlackTree, SMTPProvider, SegmentTree, type SendEmailOptions, Set, SinglyLinkedList, SparseTable, SplayTree, Stack, StaticArray, SuffixArray, SuffixTree, TemplateEngine, TernarySearchTree, TreeNode, Trie, type UploadOptions, asyncHandler, authMiddleware, connectMongoDB, createAllowedOrigins, createCorsOptions, days, errorToString, hours, loadEnv, logger, milliseconds, minutes, pickFields, seconds, sleep, toHours, toMinutes, toSeconds, validate };
package/dist/index.js CHANGED
@@ -332,20 +332,29 @@ function loadEnv(options) {
332
332
  return options.transform ? options.transform(result.data) : result.data;
333
333
  }
334
334
  function handleError(error) {
335
- logger.danger("ENV VALIDATION FAILED");
335
+ logger.danger("Env validation failed");
336
336
  const grouped = {};
337
337
  error.issues.forEach((err) => {
338
338
  const key = err.path.join(".") || "unknown";
339
+ const rawValue = key !== "unknown" ? process.env[key] : void 0;
340
+ const isSecret = key.toLowerCase().includes("secret");
341
+ const safeValue = isSecret ? "***" : rawValue;
342
+ const messageParts = [
343
+ `message: ${err.message}`,
344
+ `code: ${err.code}`,
345
+ rawValue !== void 0 ? `value: ${JSON.stringify(safeValue)}` : null
346
+ ].filter(Boolean);
347
+ const fullMessage = messageParts.join(" | ");
339
348
  if (!grouped[key]) grouped[key] = [];
340
- grouped[key].push(err.message);
349
+ grouped[key].push(fullMessage);
341
350
  });
342
351
  Object.entries(grouped).forEach(([key, messages]) => {
343
352
  logger.info(`${key}`);
344
353
  messages.forEach((msg) => {
345
- logger.log(`${msg}`);
354
+ logger.log(` - ${msg}`);
346
355
  });
347
356
  });
348
- logger.danger("Application startup aborted.\n");
357
+ logger.danger("Application startup aborted!");
349
358
  process.exit(1);
350
359
  }
351
360
 
@@ -5152,6 +5161,84 @@ var validate = (schema) => (req, _res, next) => {
5152
5161
  }
5153
5162
  next();
5154
5163
  };
5164
+
5165
+ // src/repositories/mongo.repository.ts
5166
+ var BaseMongoRepository = class {
5167
+ model;
5168
+ constructor(model) {
5169
+ this.model = model;
5170
+ }
5171
+ async findAll(filter = {}, options = {}) {
5172
+ let query = this.model.find(filter);
5173
+ if (options.select) query = query.select(options.select);
5174
+ if (options.sort) query = query.sort(options.sort);
5175
+ if (options.limit) query = query.limit(options.limit);
5176
+ if (options.skip) query = query.skip(options.skip);
5177
+ return query.exec();
5178
+ }
5179
+ async findById(id) {
5180
+ return this.model.findById(id).exec();
5181
+ }
5182
+ async findOne(filter) {
5183
+ return this.model.findOne(filter).exec();
5184
+ }
5185
+ async create(data) {
5186
+ return this.model.create(data);
5187
+ }
5188
+ async updateById(id, data) {
5189
+ return this.model.findByIdAndUpdate(id, data, {
5190
+ new: true,
5191
+ runValidators: true
5192
+ }).exec();
5193
+ }
5194
+ async deleteById(id) {
5195
+ return this.model.findByIdAndDelete(id).exec();
5196
+ }
5197
+ };
5198
+
5199
+ // src/repositories/postgres.repository.ts
5200
+ var BasePostgresRepository = class {
5201
+ model;
5202
+ // prisma model (e.g. prisma.testPost)
5203
+ constructor(model) {
5204
+ this.model = model;
5205
+ }
5206
+ async findAll(filter = {}, options = {}) {
5207
+ return this.model.findMany({
5208
+ where: filter,
5209
+ select: options.select,
5210
+ orderBy: options.sort,
5211
+ take: options.limit,
5212
+ skip: options.skip
5213
+ });
5214
+ }
5215
+ async findById(id) {
5216
+ return this.model.findUnique({
5217
+ where: { id }
5218
+ });
5219
+ }
5220
+ async findOne(filter) {
5221
+ return this.model.findFirst({
5222
+ where: filter
5223
+ });
5224
+ }
5225
+ async create(data) {
5226
+ return this.model.create({
5227
+ data
5228
+ });
5229
+ }
5230
+ async updateById(id, data) {
5231
+ return this.model.update({
5232
+ where: { id },
5233
+ data
5234
+ });
5235
+ }
5236
+ async deleteById(id) {
5237
+ return this.model.delete({
5238
+ where: { id }
5239
+ });
5240
+ }
5241
+ };
5155
5242
  var AzureBlobStorageService = class {
5156
5243
  containerName;
5157
5244
  blobServiceClient;
@@ -5603,6 +5690,6 @@ function sleep(ms) {
5603
5690
  return new Promise((resolve) => setTimeout(resolve, ms));
5604
5691
  }
5605
5692
 
5606
- export { APIFactory, apiFeatures_default as APIFeatures, APIResponse, AVLTree, AdjacencyList, AdjacencyMatrix, AppError, AzureBlobStorageService, BPlusTree, BTree, BinaryHeap, BinarySearchTree, BinaryTree, BloomFilter, CircularArray, CircularLinkedList, CircularQueue, CloudinaryService, ConsistentHash, CountMinSketch, Deque, DirectedGraph, DisjointSetUnion, DoublyLinkedList, DynamicArray, EmailService, FenwickTree, FibNode, FibonacciHeap, GlobalErrorHandler, Graph, HashMap, HashSet, HyperLogLog, IntervalTree, JWTService, KDTree, LFUCache, LRUCache, MaxHeap, MaxStack, MinHeap, MinStack, MulterFileHandlerService, MultiSet, Node, OrderedSet, PairingHeap, PairingNode, PriorityQueue, QuadTree, Queue, RadixTree, RedBlackTree, SMTPProvider, SegmentTree, Set2 as Set, SinglyLinkedList, SparseTable, SplayTree, Stack, StaticArray, SuffixArray, SuffixTree, TemplateEngine, TernarySearchTree, TreeNode, Trie, asyncHandler, authMiddleware, connectMongoDB, createAllowedOrigins, createCorsOptions, days, errorToString, hours, loadEnv, logger, milliseconds, minutes, pickFields, seconds, sleep, toHours, toMinutes, toSeconds, validate };
5693
+ export { APIFactory, apiFeatures_default as APIFeatures, APIResponse, AVLTree, AdjacencyList, AdjacencyMatrix, AppError, AzureBlobStorageService, BPlusTree, BTree, BaseMongoRepository, BasePostgresRepository, BinaryHeap, BinarySearchTree, BinaryTree, BloomFilter, CircularArray, CircularLinkedList, CircularQueue, CloudinaryService, ConsistentHash, CountMinSketch, Deque, DirectedGraph, DisjointSetUnion, DoublyLinkedList, DynamicArray, EmailService, FenwickTree, FibNode, FibonacciHeap, GlobalErrorHandler, Graph, HashMap, HashSet, HyperLogLog, IntervalTree, JWTService, KDTree, LFUCache, LRUCache, MaxHeap, MaxStack, MinHeap, MinStack, MulterFileHandlerService, MultiSet, Node, OrderedSet, PairingHeap, PairingNode, PriorityQueue, QuadTree, Queue, RadixTree, RedBlackTree, SMTPProvider, SegmentTree, Set2 as Set, SinglyLinkedList, SparseTable, SplayTree, Stack, StaticArray, SuffixArray, SuffixTree, TemplateEngine, TernarySearchTree, TreeNode, Trie, asyncHandler, authMiddleware, connectMongoDB, createAllowedOrigins, createCorsOptions, days, errorToString, hours, loadEnv, logger, milliseconds, minutes, pickFields, seconds, sleep, toHours, toMinutes, toSeconds, validate };
5607
5694
  //# sourceMappingURL=index.js.map
5608
5695
  //# sourceMappingURL=index.js.map