elseware-nodejs 1.3.1 → 1.4.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
@@ -57,6 +57,18 @@ declare class APIResponse {
57
57
 
58
58
  declare const asyncHandler: (fn: (req: Request, res: Response, next: NextFunction) => Promise<void>) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
59
59
 
60
+ type FieldTransform<T> = (value: T) => any;
61
+ type PickOptions<T extends Record<string, any>, K extends keyof T> = {
62
+ removeUndefined?: boolean;
63
+ removeNull?: boolean;
64
+ removeEmptyString?: boolean;
65
+ strict?: boolean;
66
+ defaults?: Partial<Record<K, any>>;
67
+ rename?: Partial<Record<K, string>>;
68
+ transform?: Partial<Record<K, FieldTransform<T[K]>>>;
69
+ };
70
+ declare function pickFields<T extends Record<string, any>, K extends keyof T>(obj: T, fields: readonly K[], options?: PickOptions<T, K>): Partial<Record<K | string, any>>;
71
+
60
72
  interface AzureBlobConfig {
61
73
  connectionString: string;
62
74
  accountName: string;
@@ -1882,4 +1894,4 @@ declare function toMinutes(ms: number): number;
1882
1894
  declare function toHours(ms: number): number;
1883
1895
  declare function sleep(ms: number): Promise<void>;
1884
1896
 
1885
- export { APIFactory, APIFeatures, APIResponse, AVLTree, AdjacencyList, AdjacencyMatrix, type AdjacentEdge, type AllowedOriginsOptions, AppError, type AzureBlobConfig, AzureBlobService, BPlusTree, BTree, BaseService, BinaryHeap, BinarySearchTree, BinaryTree, BloomFilter, CircularArray, CircularLinkedList, CircularQueue, type CloudinaryConfig, CloudinaryService, ConsistentHash, CountMinSketch, type CrudService, type DatabaseConfig, Deque, type DirectedEdge, DirectedGraph, DisjointSetUnion, DoublyLinkedList, DynamicArray, type Edge, FenwickTree, FibNode, FibonacciHeap, GlobalErrorHandler, Graph, HashMap, HashSet, HyperLogLog, type Interval, IntervalTree, KDTree, LFUCache, LRUCache, type LoggerOptions, MaxHeap, MaxStack, MinHeap, MinStack, MultiSet, Node, OrderedSet, PairingHeap, PairingNode, type Point, type Point2D, PriorityQueue, type ProgressCallback, QuadTree, Queue, RadixTree, type Rect, RedBlackTree, SegmentTree, Set, SinglyLinkedList, SparseTable, SplayTree, Stack, StaticArray, SuffixArray, SuffixTree, TernarySearchTree, TreeNode, Trie, type UploadOptions, asyncHandler, authMiddleware, connectMongoDB, createAllowedOrigins, createCorsOptions, days, errorToString, hours, loadEnv, logger, milliseconds, minutes, seconds, sleep, toHours, toMinutes, toSeconds, validate };
1897
+ export { APIFactory, APIFeatures, APIResponse, AVLTree, AdjacencyList, AdjacencyMatrix, type AdjacentEdge, type AllowedOriginsOptions, AppError, type AzureBlobConfig, AzureBlobService, BPlusTree, BTree, BaseService, BinaryHeap, BinarySearchTree, BinaryTree, BloomFilter, CircularArray, CircularLinkedList, CircularQueue, type CloudinaryConfig, CloudinaryService, ConsistentHash, CountMinSketch, type CrudService, type DatabaseConfig, Deque, type DirectedEdge, DirectedGraph, DisjointSetUnion, DoublyLinkedList, DynamicArray, type Edge, FenwickTree, FibNode, FibonacciHeap, GlobalErrorHandler, Graph, HashMap, HashSet, HyperLogLog, type Interval, IntervalTree, KDTree, LFUCache, LRUCache, type LoggerOptions, MaxHeap, MaxStack, MinHeap, MinStack, MultiSet, Node, OrderedSet, PairingHeap, PairingNode, type Point, type Point2D, PriorityQueue, type ProgressCallback, QuadTree, Queue, RadixTree, type Rect, RedBlackTree, SegmentTree, Set, SinglyLinkedList, SparseTable, SplayTree, Stack, StaticArray, SuffixArray, SuffixTree, 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
@@ -57,6 +57,18 @@ declare class APIResponse {
57
57
 
58
58
  declare const asyncHandler: (fn: (req: Request, res: Response, next: NextFunction) => Promise<void>) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
59
59
 
60
+ type FieldTransform<T> = (value: T) => any;
61
+ type PickOptions<T extends Record<string, any>, K extends keyof T> = {
62
+ removeUndefined?: boolean;
63
+ removeNull?: boolean;
64
+ removeEmptyString?: boolean;
65
+ strict?: boolean;
66
+ defaults?: Partial<Record<K, any>>;
67
+ rename?: Partial<Record<K, string>>;
68
+ transform?: Partial<Record<K, FieldTransform<T[K]>>>;
69
+ };
70
+ declare function pickFields<T extends Record<string, any>, K extends keyof T>(obj: T, fields: readonly K[], options?: PickOptions<T, K>): Partial<Record<K | string, any>>;
71
+
60
72
  interface AzureBlobConfig {
61
73
  connectionString: string;
62
74
  accountName: string;
@@ -1882,4 +1894,4 @@ declare function toMinutes(ms: number): number;
1882
1894
  declare function toHours(ms: number): number;
1883
1895
  declare function sleep(ms: number): Promise<void>;
1884
1896
 
1885
- export { APIFactory, APIFeatures, APIResponse, AVLTree, AdjacencyList, AdjacencyMatrix, type AdjacentEdge, type AllowedOriginsOptions, AppError, type AzureBlobConfig, AzureBlobService, BPlusTree, BTree, BaseService, BinaryHeap, BinarySearchTree, BinaryTree, BloomFilter, CircularArray, CircularLinkedList, CircularQueue, type CloudinaryConfig, CloudinaryService, ConsistentHash, CountMinSketch, type CrudService, type DatabaseConfig, Deque, type DirectedEdge, DirectedGraph, DisjointSetUnion, DoublyLinkedList, DynamicArray, type Edge, FenwickTree, FibNode, FibonacciHeap, GlobalErrorHandler, Graph, HashMap, HashSet, HyperLogLog, type Interval, IntervalTree, KDTree, LFUCache, LRUCache, type LoggerOptions, MaxHeap, MaxStack, MinHeap, MinStack, MultiSet, Node, OrderedSet, PairingHeap, PairingNode, type Point, type Point2D, PriorityQueue, type ProgressCallback, QuadTree, Queue, RadixTree, type Rect, RedBlackTree, SegmentTree, Set, SinglyLinkedList, SparseTable, SplayTree, Stack, StaticArray, SuffixArray, SuffixTree, TernarySearchTree, TreeNode, Trie, type UploadOptions, asyncHandler, authMiddleware, connectMongoDB, createAllowedOrigins, createCorsOptions, days, errorToString, hours, loadEnv, logger, milliseconds, minutes, seconds, sleep, toHours, toMinutes, toSeconds, validate };
1897
+ export { APIFactory, APIFeatures, APIResponse, AVLTree, AdjacencyList, AdjacencyMatrix, type AdjacentEdge, type AllowedOriginsOptions, AppError, type AzureBlobConfig, AzureBlobService, BPlusTree, BTree, BaseService, BinaryHeap, BinarySearchTree, BinaryTree, BloomFilter, CircularArray, CircularLinkedList, CircularQueue, type CloudinaryConfig, CloudinaryService, ConsistentHash, CountMinSketch, type CrudService, type DatabaseConfig, Deque, type DirectedEdge, DirectedGraph, DisjointSetUnion, DoublyLinkedList, DynamicArray, type Edge, FenwickTree, FibNode, FibonacciHeap, GlobalErrorHandler, Graph, HashMap, HashSet, HyperLogLog, type Interval, IntervalTree, KDTree, LFUCache, LRUCache, type LoggerOptions, MaxHeap, MaxStack, MinHeap, MinStack, MultiSet, Node, OrderedSet, PairingHeap, PairingNode, type Point, type Point2D, PriorityQueue, type ProgressCallback, QuadTree, Queue, RadixTree, type Rect, RedBlackTree, SegmentTree, Set, SinglyLinkedList, SparseTable, SplayTree, Stack, StaticArray, SuffixArray, SuffixTree, 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
@@ -203,6 +203,42 @@ var APIFactory = class {
203
203
  });
204
204
  }
205
205
  };
206
+
207
+ // src/api/pickFields.ts
208
+ function pickFields(obj, fields, options = {}) {
209
+ const removeUndefined = options.removeUndefined ?? false;
210
+ const removeNull = options.removeNull ?? false;
211
+ const removeEmptyString = options.removeEmptyString ?? false;
212
+ const strict = options.strict ?? false;
213
+ const defaults = options.defaults ?? {};
214
+ const rename = options.rename ?? {};
215
+ const transform = options.transform ?? {};
216
+ const result = {};
217
+ if (strict) {
218
+ for (const key of Object.keys(obj)) {
219
+ if (!fields.includes(key)) {
220
+ throw new Error(`Unknown field: ${key}`);
221
+ }
222
+ }
223
+ }
224
+ for (const field of fields) {
225
+ let value = obj[field];
226
+ if (value === void 0 && field in defaults) {
227
+ value = defaults[field];
228
+ }
229
+ if (removeUndefined && value === void 0) continue;
230
+ if (removeNull && value === null) continue;
231
+ if (removeEmptyString && value === "") continue;
232
+ if (transform[field]) {
233
+ value = transform[field](value);
234
+ }
235
+ const outputKey = rename[field] ?? field;
236
+ if (Object.prototype.hasOwnProperty.call(obj, field) || field in defaults) {
237
+ result[outputKey] = value;
238
+ }
239
+ }
240
+ return result;
241
+ }
206
242
  var AzureBlobService = class {
207
243
  containerName;
208
244
  blobServiceClient;
@@ -5327,6 +5363,6 @@ function sleep(ms) {
5327
5363
  return new Promise((resolve) => setTimeout(resolve, ms));
5328
5364
  }
5329
5365
 
5330
- export { APIFactory, apiFeatures_default as APIFeatures, APIResponse, AVLTree, AdjacencyList, AdjacencyMatrix, AppError, AzureBlobService, BPlusTree, BTree, BaseService, BinaryHeap, BinarySearchTree, BinaryTree, BloomFilter, CircularArray, CircularLinkedList, CircularQueue, CloudinaryService, ConsistentHash, CountMinSketch, Deque, DirectedGraph, DisjointSetUnion, DoublyLinkedList, DynamicArray, FenwickTree, FibNode, FibonacciHeap, GlobalErrorHandler, Graph, HashMap, HashSet, HyperLogLog, IntervalTree, KDTree, LFUCache, LRUCache, MaxHeap, MaxStack, MinHeap, MinStack, MultiSet, Node, OrderedSet, PairingHeap, PairingNode, PriorityQueue, QuadTree, Queue, RadixTree, RedBlackTree, SegmentTree, Set2 as Set, SinglyLinkedList, SparseTable, SplayTree, Stack, StaticArray, SuffixArray, SuffixTree, TernarySearchTree, TreeNode, Trie, asyncHandler, authMiddleware, connectMongoDB, createAllowedOrigins, createCorsOptions, days, errorToString, hours, loadEnv, logger, milliseconds, minutes, seconds, sleep, toHours, toMinutes, toSeconds, validate };
5366
+ export { APIFactory, apiFeatures_default as APIFeatures, APIResponse, AVLTree, AdjacencyList, AdjacencyMatrix, AppError, AzureBlobService, BPlusTree, BTree, BaseService, BinaryHeap, BinarySearchTree, BinaryTree, BloomFilter, CircularArray, CircularLinkedList, CircularQueue, CloudinaryService, ConsistentHash, CountMinSketch, Deque, DirectedGraph, DisjointSetUnion, DoublyLinkedList, DynamicArray, FenwickTree, FibNode, FibonacciHeap, GlobalErrorHandler, Graph, HashMap, HashSet, HyperLogLog, IntervalTree, KDTree, LFUCache, LRUCache, MaxHeap, MaxStack, MinHeap, MinStack, MultiSet, Node, OrderedSet, PairingHeap, PairingNode, PriorityQueue, QuadTree, Queue, RadixTree, RedBlackTree, SegmentTree, Set2 as Set, SinglyLinkedList, SparseTable, SplayTree, Stack, StaticArray, SuffixArray, SuffixTree, TernarySearchTree, TreeNode, Trie, asyncHandler, authMiddleware, connectMongoDB, createAllowedOrigins, createCorsOptions, days, errorToString, hours, loadEnv, logger, milliseconds, minutes, pickFields, seconds, sleep, toHours, toMinutes, toSeconds, validate };
5331
5367
  //# sourceMappingURL=index.js.map
5332
5368
  //# sourceMappingURL=index.js.map