elseware-nodejs 1.8.1 → 1.8.3

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
@@ -76,19 +76,10 @@ interface DatabaseConfig {
76
76
  }
77
77
  declare function connectMongoDB(config: DatabaseConfig): Promise<void>;
78
78
 
79
- /**
80
- * Overload 1: No transform → return schema inferred type
81
- */
82
- declare function loadEnv<TSchema extends ZodTypeAny>(options: {
79
+ declare function loadEnv<TSchema extends ZodTypeAny, TTransform = undefined>(options: {
83
80
  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;
81
+ transform?: (env: infer<TSchema>) => TTransform;
82
+ }): TTransform extends undefined ? infer<TSchema> : TTransform;
92
83
 
93
84
  interface LoggerOptions {
94
85
  timestamp?: boolean;
@@ -1826,45 +1817,82 @@ declare const GlobalErrorHandler: (isProd?: boolean) => (err: unknown, _req: Req
1826
1817
 
1827
1818
  declare const validate: (schema: Schema) => (req: Request, _res: Response, next: NextFunction) => void;
1828
1819
 
1820
+ type Filter<T> = Partial<Record<keyof T, unknown>>;
1821
+ type Select<T> = (keyof T)[] | Partial<Record<keyof T, 0 | 1>>;
1822
+ type Sort<T> = Partial<Record<keyof T, 1 | -1>>;
1823
+
1824
+ interface IQueryOptions<T> {
1825
+ select?: Select<T>;
1826
+ sort?: Sort<T>;
1827
+ limit?: number;
1828
+ skip?: number;
1829
+ }
1830
+ interface IUpdateQueryOptions {
1831
+ new?: boolean;
1832
+ runValidators: boolean;
1833
+ upsert?: boolean;
1834
+ }
1829
1835
  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>;
1836
+ /**
1837
+ * Create
1838
+ */
1833
1839
  create(data: Partial<T>): Promise<T>;
1834
- updateById(id: string, data: Partial<T>): Promise<T | null>;
1840
+ createMany(data: Partial<T>[]): Promise<T[]>;
1841
+ /**
1842
+ * Read
1843
+ */
1844
+ findAll(filter?: Filter<T>, options?: IQueryOptions<T>): Promise<T[]>;
1845
+ findById(id: string, options?: IQueryOptions<T>): Promise<T | null>;
1846
+ findOne(filter: Filter<T>, options?: IQueryOptions<T>): Promise<T | null>;
1847
+ findManyByIds(ids: string[], options?: IQueryOptions<T>): Promise<T[]>;
1848
+ count(filter?: Filter<T>): Promise<number>;
1849
+ exists(filter?: Filter<T>): Promise<boolean>;
1850
+ /**
1851
+ * Update
1852
+ */
1853
+ updateById(id: string, data: Partial<T>, options?: IUpdateQueryOptions): Promise<T | null>;
1854
+ updateOne(filter: Filter<T>, data: Partial<T>, options?: IUpdateQueryOptions): Promise<T | null>;
1855
+ updateMany(filter: Filter<T>, data: Partial<T>): Promise<number>;
1856
+ /**
1857
+ * Delete
1858
+ */
1835
1859
  deleteById(id: string): Promise<T | null>;
1860
+ deleteOne(filter: Filter<T>): Promise<T | null>;
1861
+ deleteMany(filter: Filter<T>): Promise<number>;
1836
1862
  }
1837
1863
 
1838
1864
  declare class BaseMongoRepository<T> implements IRepository<T> {
1839
1865
  protected model: Model<T>;
1840
1866
  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>;
1867
+ private buildSelect;
1868
+ private applyQueryOptions;
1869
+ private toPlain;
1870
+ /**
1871
+ * Create
1872
+ */
1865
1873
  create(data: Partial<T>): Promise<T>;
1866
- updateById(id: string, data: Partial<T>): Promise<T | null>;
1874
+ createMany(data: Partial<T>[]): Promise<T[]>;
1875
+ /**
1876
+ * Read
1877
+ */
1878
+ findAll(filter?: Filter<T>, options?: IQueryOptions<T>): Promise<T[]>;
1879
+ findById(id: string, options?: IQueryOptions<T>): Promise<T | null>;
1880
+ findOne(filter?: Filter<T>, options?: IQueryOptions<T>): Promise<T | null>;
1881
+ findManyByIds(ids: string[], options?: IQueryOptions<T>): Promise<T[]>;
1882
+ count(filter?: Filter<T>): Promise<number>;
1883
+ exists(filter?: Filter<T>): Promise<boolean>;
1884
+ /**
1885
+ * Update
1886
+ */
1887
+ updateById(id: string, data: UpdateQuery<T>, options?: IUpdateQueryOptions): Promise<T | null>;
1888
+ updateOne(filter: Filter<T>, data: Partial<T>, options?: IUpdateQueryOptions): Promise<T | null>;
1889
+ updateMany(filter: Filter<T>, data: Partial<T>): Promise<number>;
1890
+ /**
1891
+ * Delete
1892
+ */
1867
1893
  deleteById(id: string): Promise<T | null>;
1894
+ deleteOne(filter: Filter<T>): Promise<T | null>;
1895
+ deleteMany(filter: Filter<T>): Promise<number>;
1868
1896
  }
1869
1897
 
1870
1898
  interface AzureBlobStorageConfig {
@@ -2014,4 +2042,4 @@ declare function toMinutes(ms: number): number;
2014
2042
  declare function toHours(ms: number): number;
2015
2043
  declare function sleep(ms: number): Promise<void>;
2016
2044
 
2017
- 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 };
2045
+ export { APIFactory, APIFeatures, APIResponse, AVLTree, AdjacencyList, AdjacencyMatrix, type AdjacentEdge, type AllowedOriginsOptions, AppError, type AzureBlobStorageConfig, AzureBlobStorageService, BPlusTree, BTree, BaseMongoRepository, 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 IQueryOptions, type IRepository, type IUpdateQueryOptions, 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
@@ -76,19 +76,10 @@ interface DatabaseConfig {
76
76
  }
77
77
  declare function connectMongoDB(config: DatabaseConfig): Promise<void>;
78
78
 
79
- /**
80
- * Overload 1: No transform → return schema inferred type
81
- */
82
- declare function loadEnv<TSchema extends ZodTypeAny>(options: {
79
+ declare function loadEnv<TSchema extends ZodTypeAny, TTransform = undefined>(options: {
83
80
  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;
81
+ transform?: (env: infer<TSchema>) => TTransform;
82
+ }): TTransform extends undefined ? infer<TSchema> : TTransform;
92
83
 
93
84
  interface LoggerOptions {
94
85
  timestamp?: boolean;
@@ -1826,45 +1817,82 @@ declare const GlobalErrorHandler: (isProd?: boolean) => (err: unknown, _req: Req
1826
1817
 
1827
1818
  declare const validate: (schema: Schema) => (req: Request, _res: Response, next: NextFunction) => void;
1828
1819
 
1820
+ type Filter<T> = Partial<Record<keyof T, unknown>>;
1821
+ type Select<T> = (keyof T)[] | Partial<Record<keyof T, 0 | 1>>;
1822
+ type Sort<T> = Partial<Record<keyof T, 1 | -1>>;
1823
+
1824
+ interface IQueryOptions<T> {
1825
+ select?: Select<T>;
1826
+ sort?: Sort<T>;
1827
+ limit?: number;
1828
+ skip?: number;
1829
+ }
1830
+ interface IUpdateQueryOptions {
1831
+ new?: boolean;
1832
+ runValidators: boolean;
1833
+ upsert?: boolean;
1834
+ }
1829
1835
  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>;
1836
+ /**
1837
+ * Create
1838
+ */
1833
1839
  create(data: Partial<T>): Promise<T>;
1834
- updateById(id: string, data: Partial<T>): Promise<T | null>;
1840
+ createMany(data: Partial<T>[]): Promise<T[]>;
1841
+ /**
1842
+ * Read
1843
+ */
1844
+ findAll(filter?: Filter<T>, options?: IQueryOptions<T>): Promise<T[]>;
1845
+ findById(id: string, options?: IQueryOptions<T>): Promise<T | null>;
1846
+ findOne(filter: Filter<T>, options?: IQueryOptions<T>): Promise<T | null>;
1847
+ findManyByIds(ids: string[], options?: IQueryOptions<T>): Promise<T[]>;
1848
+ count(filter?: Filter<T>): Promise<number>;
1849
+ exists(filter?: Filter<T>): Promise<boolean>;
1850
+ /**
1851
+ * Update
1852
+ */
1853
+ updateById(id: string, data: Partial<T>, options?: IUpdateQueryOptions): Promise<T | null>;
1854
+ updateOne(filter: Filter<T>, data: Partial<T>, options?: IUpdateQueryOptions): Promise<T | null>;
1855
+ updateMany(filter: Filter<T>, data: Partial<T>): Promise<number>;
1856
+ /**
1857
+ * Delete
1858
+ */
1835
1859
  deleteById(id: string): Promise<T | null>;
1860
+ deleteOne(filter: Filter<T>): Promise<T | null>;
1861
+ deleteMany(filter: Filter<T>): Promise<number>;
1836
1862
  }
1837
1863
 
1838
1864
  declare class BaseMongoRepository<T> implements IRepository<T> {
1839
1865
  protected model: Model<T>;
1840
1866
  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>;
1867
+ private buildSelect;
1868
+ private applyQueryOptions;
1869
+ private toPlain;
1870
+ /**
1871
+ * Create
1872
+ */
1865
1873
  create(data: Partial<T>): Promise<T>;
1866
- updateById(id: string, data: Partial<T>): Promise<T | null>;
1874
+ createMany(data: Partial<T>[]): Promise<T[]>;
1875
+ /**
1876
+ * Read
1877
+ */
1878
+ findAll(filter?: Filter<T>, options?: IQueryOptions<T>): Promise<T[]>;
1879
+ findById(id: string, options?: IQueryOptions<T>): Promise<T | null>;
1880
+ findOne(filter?: Filter<T>, options?: IQueryOptions<T>): Promise<T | null>;
1881
+ findManyByIds(ids: string[], options?: IQueryOptions<T>): Promise<T[]>;
1882
+ count(filter?: Filter<T>): Promise<number>;
1883
+ exists(filter?: Filter<T>): Promise<boolean>;
1884
+ /**
1885
+ * Update
1886
+ */
1887
+ updateById(id: string, data: UpdateQuery<T>, options?: IUpdateQueryOptions): Promise<T | null>;
1888
+ updateOne(filter: Filter<T>, data: Partial<T>, options?: IUpdateQueryOptions): Promise<T | null>;
1889
+ updateMany(filter: Filter<T>, data: Partial<T>): Promise<number>;
1890
+ /**
1891
+ * Delete
1892
+ */
1867
1893
  deleteById(id: string): Promise<T | null>;
1894
+ deleteOne(filter: Filter<T>): Promise<T | null>;
1895
+ deleteMany(filter: Filter<T>): Promise<number>;
1868
1896
  }
1869
1897
 
1870
1898
  interface AzureBlobStorageConfig {
@@ -2014,4 +2042,4 @@ declare function toMinutes(ms: number): number;
2014
2042
  declare function toHours(ms: number): number;
2015
2043
  declare function sleep(ms: number): Promise<void>;
2016
2044
 
2017
- 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 };
2045
+ export { APIFactory, APIFeatures, APIResponse, AVLTree, AdjacencyList, AdjacencyMatrix, type AdjacentEdge, type AllowedOriginsOptions, AppError, type AzureBlobStorageConfig, AzureBlobStorageService, BPlusTree, BTree, BaseMongoRepository, 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 IQueryOptions, type IRepository, type IUpdateQueryOptions, 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
@@ -329,7 +329,8 @@ function loadEnv(options) {
329
329
  handleError(result.error);
330
330
  }
331
331
  logger.success("Env Configurations validated");
332
- return options.transform ? options.transform(result.data) : result.data;
332
+ const env = result.data;
333
+ return options.transform ? options.transform(env) : env;
333
334
  }
334
335
  function handleError(error) {
335
336
  logger.danger("Env validation failed");
@@ -339,20 +340,17 @@ function handleError(error) {
339
340
  const rawValue = key !== "unknown" ? process.env[key] : void 0;
340
341
  const isSecret = key.toLowerCase().includes("secret");
341
342
  const safeValue = isSecret ? "***" : rawValue;
342
- const messageParts = [
343
+ const message = [
343
344
  `message: ${err.message}`,
344
345
  `code: ${err.code}`,
345
346
  rawValue !== void 0 ? `value: ${JSON.stringify(safeValue)}` : null
346
- ].filter(Boolean);
347
- const fullMessage = messageParts.join(" | ");
347
+ ].filter(Boolean).join(" | ");
348
348
  if (!grouped[key]) grouped[key] = [];
349
- grouped[key].push(fullMessage);
349
+ grouped[key].push(message);
350
350
  });
351
351
  Object.entries(grouped).forEach(([key, messages]) => {
352
- logger.info(`${key}`);
353
- messages.forEach((msg) => {
354
- logger.log(` - ${msg}`);
355
- });
352
+ logger.info(key);
353
+ messages.forEach((msg) => logger.log(` - ${msg}`));
356
354
  });
357
355
  logger.danger("Application startup aborted!");
358
356
  process.exit(1);
@@ -5162,81 +5160,98 @@ var validate = (schema) => (req, _res, next) => {
5162
5160
  next();
5163
5161
  };
5164
5162
 
5165
- // src/repositories/mongo.repository.ts
5163
+ // src/repositories/providers/mongo.repository.ts
5166
5164
  var BaseMongoRepository = class {
5167
5165
  model;
5168
5166
  constructor(model) {
5169
5167
  this.model = model;
5170
5168
  }
5171
- async findAll(filter = {}, options = {}) {
5172
- let query = this.model.find(filter);
5173
- if (options.select) query = query.select(options.select);
5169
+ buildSelect(select) {
5170
+ if (!select) return void 0;
5171
+ if (Array.isArray(select)) {
5172
+ return select.join(" ");
5173
+ }
5174
+ return select;
5175
+ }
5176
+ applyQueryOptions(query, options) {
5177
+ const select = this.buildSelect(options.select);
5178
+ if (select) query = query.select(select);
5174
5179
  if (options.sort) query = query.sort(options.sort);
5175
5180
  if (options.limit) query = query.limit(options.limit);
5176
5181
  if (options.skip) query = query.skip(options.skip);
5177
- return query.exec();
5182
+ return query;
5178
5183
  }
5179
- async findById(id) {
5180
- return this.model.findById(id).exec();
5181
- }
5182
- async findOne(filter) {
5183
- return this.model.findOne(filter).exec();
5184
+ toPlain(doc) {
5185
+ return doc.toObject();
5184
5186
  }
5187
+ /**
5188
+ * Create
5189
+ */
5185
5190
  async create(data) {
5186
- return this.model.create(data);
5191
+ const doc = await this.model.create(data);
5192
+ return this.toPlain(doc);
5187
5193
  }
5188
- async updateById(id, data) {
5189
- return this.model.findByIdAndUpdate(id, data, {
5190
- new: true,
5191
- runValidators: true
5192
- }).exec();
5194
+ async createMany(data) {
5195
+ const docs = await this.model.insertMany(data);
5196
+ return docs.map((doc) => this.toPlain(doc));
5193
5197
  }
5194
- async deleteById(id) {
5195
- return this.model.findByIdAndDelete(id).exec();
5198
+ /**
5199
+ * Read
5200
+ */
5201
+ async findAll(filter = {}, options = {}) {
5202
+ let query = this.model.find(filter);
5203
+ query = this.applyQueryOptions(query, options);
5204
+ return query.exec();
5196
5205
  }
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;
5206
+ async findById(id, options = {}) {
5207
+ let query = this.model.findById(id);
5208
+ query = this.applyQueryOptions(query, options);
5209
+ return query.exec();
5205
5210
  }
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
- });
5211
+ async findOne(filter = {}, options = {}) {
5212
+ let query = this.model.findOne(filter);
5213
+ query = this.applyQueryOptions(query, options);
5214
+ return query.exec();
5214
5215
  }
5215
- async findById(id) {
5216
- return this.model.findUnique({
5217
- where: { id }
5218
- });
5216
+ async findManyByIds(ids, options = {}) {
5217
+ let query = this.model.find({ _id: { $in: ids } });
5218
+ query = this.applyQueryOptions(query, options);
5219
+ return query.exec();
5219
5220
  }
5220
- async findOne(filter) {
5221
- return this.model.findFirst({
5222
- where: filter
5223
- });
5221
+ async count(filter) {
5222
+ return this.model.countDocuments(filter).exec();
5224
5223
  }
5225
- async create(data) {
5226
- return this.model.create({
5227
- data
5228
- });
5224
+ async exists(filter) {
5225
+ const result = await this.model.exists(filter);
5226
+ return result !== null;
5229
5227
  }
5230
- async updateById(id, data) {
5231
- return this.model.update({
5232
- where: { id },
5233
- data
5234
- });
5228
+ /**
5229
+ * Update
5230
+ */
5231
+ async updateById(id, data, options) {
5232
+ const finalOptions = { new: true, runValidators: true, ...options };
5233
+ return this.model.findByIdAndUpdate(id, data, finalOptions).exec();
5234
+ }
5235
+ async updateOne(filter, data, options) {
5236
+ const finalOptions = { new: true, runValidators: true, ...options };
5237
+ return this.model.findOneAndUpdate(filter, data, finalOptions).exec();
5235
5238
  }
5239
+ async updateMany(filter, data) {
5240
+ const result = await this.model.updateMany(filter, data).exec();
5241
+ return result.modifiedCount;
5242
+ }
5243
+ /**
5244
+ * Delete
5245
+ */
5236
5246
  async deleteById(id) {
5237
- return this.model.delete({
5238
- where: { id }
5239
- });
5247
+ return this.model.findByIdAndDelete(id).exec();
5248
+ }
5249
+ async deleteOne(filter) {
5250
+ return this.model.findOneAndDelete(filter).exec();
5251
+ }
5252
+ async deleteMany(filter) {
5253
+ const result = await this.model.deleteMany(filter).exec();
5254
+ return result.deletedCount ?? 0;
5240
5255
  }
5241
5256
  };
5242
5257
  var AzureBlobStorageService = class {
@@ -5691,6 +5706,6 @@ function sleep(ms) {
5691
5706
  return new Promise((resolve) => setTimeout(resolve, ms));
5692
5707
  }
5693
5708
 
5694
- 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 };
5709
+ export { APIFactory, apiFeatures_default as APIFeatures, APIResponse, AVLTree, AdjacencyList, AdjacencyMatrix, AppError, AzureBlobStorageService, BPlusTree, BTree, BaseMongoRepository, 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 };
5695
5710
  //# sourceMappingURL=index.js.map
5696
5711
  //# sourceMappingURL=index.js.map