elseware-nodejs 1.11.7 → 1.11.8

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
@@ -1926,7 +1926,19 @@ interface ParsedQuery {
1926
1926
  populate: string[];
1927
1927
  }
1928
1928
 
1929
+ interface ApiFeaturesConfig {
1930
+ defaultPage: number;
1931
+ defaultLimit: number;
1932
+ maxLimit: number;
1933
+ reservedFields: string[];
1934
+ supportedOperators: string[];
1935
+ }
1936
+ declare const DefaultApiFeaturesConfig: ApiFeaturesConfig;
1937
+
1929
1938
  declare class ApiFeatures {
1939
+ private static config;
1940
+ static configure(config: Partial<ApiFeaturesConfig>): void;
1941
+ static getConfig(): ApiFeaturesConfig;
1930
1942
  static parse(query: Record<string, unknown>): ParsedQuery;
1931
1943
  private static parseFilters;
1932
1944
  private static parseSort;
@@ -1935,12 +1947,6 @@ declare class ApiFeatures {
1935
1947
  private static parsePagination;
1936
1948
  }
1937
1949
 
1938
- declare const QUERY_RESERVED_FIELDS: readonly ["page", "limit", "sort", "fields", "populate"];
1939
- declare const DEFAULT_PAGE = 1;
1940
- declare const DEFAULT_LIMIT = 100;
1941
- declare const DEFAULT_SORT_DIRECTION = "asc";
1942
- declare const SUPPORTED_OPERATORS: readonly ["eq", "ne", "gt", "gte", "lt", "lte", "in", "nin", "contains", "startsWith", "endsWith"];
1943
-
1944
1950
  interface ApiResponseOptions<T = unknown> {
1945
1951
  statusCode?: number;
1946
1952
  success?: boolean;
@@ -2340,4 +2346,4 @@ declare function toMinutes(ms: number): number;
2340
2346
  declare function toHours(ms: number): number;
2341
2347
  declare function sleep(ms: number): Promise<void>;
2342
2348
 
2343
- export { AVLTree, AdjacencyList, AdjacencyMatrix, type AdjacentEdge, ApiFeatures, type ApiMeta, ApiResponse, type ApiResponseOptions, AppError, type AppErrorOptions, AsyncHandler, type AsyncRequestHandler, type AuthStrategy, type AuthenticatedUser, type AzureBlobStorageConfig, AzureBlobStorageService, BPlusTree, BTree, BearerTokenStrategy, BinaryHeap, BinarySearchTree, BinaryTree, BloomFilter, CircularArray, CircularLinkedList, CircularQueue, type CloudinaryConfig, CloudinaryService, ConsistentHash, CorrelationId, type CorsOptionsConfig, CountMinSketch, CrudControllerFactory, type CrudControllerOptions, DEFAULT_LIMIT, DEFAULT_PAGE, DEFAULT_SORT_DIRECTION, type DatabaseConnectionOptions, DatabaseManager, type DatabaseProvider, Deque, type DirectedEdge, DirectedGraph, DisjointSetUnion, DoublyLinkedList, DynamicArray, type Edge, type EmailProvider, EmailService, type ErrorMeta, ErrorMiddleware, type ExponentialBackoffOptions, ExponentialBackoffRetryPolicy, FenwickTree, FibNode, FibonacciHeap, type Filter, FixedRetryPolicy, type FixedRetryPolicyOptions, Graph, HashMap, HashSet, HttpClient, type HttpClientOptions, HyperLogLog, type IValidator, type InferSchema, InternalServiceClient, type Interval, IntervalTree, JWTService, type JWTServiceOptions, JoiValidator, KDTree, LFUCache, LRUCache, type LoadEnvOptions, Logger, type LoggerOptions, MaxHeap, MaxStack, MinHeap, MinStack, type MongoDatabaseConfig, MongoDatabaseProvider, MongoRepository, MulterFileHandlerService, MultiSet, Node, OrderedSet, type PaginationMeta, type PaginationQuery, PairingHeap, PairingNode, type ParsedQuery, type PickOptions, type Point, type Point2D, PriorityQueue, type ProgressCallback, QUERY_RESERVED_FIELDS, QuadTree, type QueryFilter, type QueryOperator, type QueryOptions, type QuerySort, Queue, RadixTree, type Rect, RedBlackTree, type Repository, RequestContext, type RequestContextData, type RequestContextOptions, type RetryPolicy, SMTPProvider, SUPPORTED_OPERATORS, SegmentTree, type Select, type SendEmailOptions, ServiceClient, type ServiceResponse, Set, SinglyLinkedList, type Sort, SparseTable, SplayTree, Stack, type StandardApiResponse, StaticArray, StaticTokenProvider, SuffixArray, SuffixTree, TemplateEngine, TernarySearchTree, type TokenProvider, TracingHeaders, TreeNode, Trie, type UpdateQueryOptions, type UploadOptions, type ValidationResult, type ValidationSchema, ZodValidator, authMiddleware, createCorsOptions, createRequestContextMiddleware, days, errorToString, hours, isAllowedOrigin, isJoiSchema, isZodSchema, loadEnv, logger, milliseconds, minutes, pickFields, seconds, sleep, toHours, toMinutes, toSeconds, validate };
2349
+ export { AVLTree, AdjacencyList, AdjacencyMatrix, type AdjacentEdge, ApiFeatures, type ApiFeaturesConfig, type ApiMeta, ApiResponse, type ApiResponseOptions, AppError, type AppErrorOptions, AsyncHandler, type AsyncRequestHandler, type AuthStrategy, type AuthenticatedUser, type AzureBlobStorageConfig, AzureBlobStorageService, BPlusTree, BTree, BearerTokenStrategy, BinaryHeap, BinarySearchTree, BinaryTree, BloomFilter, CircularArray, CircularLinkedList, CircularQueue, type CloudinaryConfig, CloudinaryService, ConsistentHash, CorrelationId, type CorsOptionsConfig, CountMinSketch, CrudControllerFactory, type CrudControllerOptions, type DatabaseConnectionOptions, DatabaseManager, type DatabaseProvider, DefaultApiFeaturesConfig, Deque, type DirectedEdge, DirectedGraph, DisjointSetUnion, DoublyLinkedList, DynamicArray, type Edge, type EmailProvider, EmailService, type ErrorMeta, ErrorMiddleware, type ExponentialBackoffOptions, ExponentialBackoffRetryPolicy, FenwickTree, FibNode, FibonacciHeap, type Filter, FixedRetryPolicy, type FixedRetryPolicyOptions, Graph, HashMap, HashSet, HttpClient, type HttpClientOptions, HyperLogLog, type IValidator, type InferSchema, InternalServiceClient, type Interval, IntervalTree, JWTService, type JWTServiceOptions, JoiValidator, KDTree, LFUCache, LRUCache, type LoadEnvOptions, Logger, type LoggerOptions, MaxHeap, MaxStack, MinHeap, MinStack, type MongoDatabaseConfig, MongoDatabaseProvider, MongoRepository, MulterFileHandlerService, MultiSet, Node, OrderedSet, type PaginationMeta, type PaginationQuery, PairingHeap, PairingNode, type ParsedQuery, type PickOptions, type Point, type Point2D, PriorityQueue, type ProgressCallback, QuadTree, type QueryFilter, type QueryOperator, type QueryOptions, type QuerySort, Queue, RadixTree, type Rect, RedBlackTree, type Repository, RequestContext, type RequestContextData, type RequestContextOptions, type RetryPolicy, SMTPProvider, SegmentTree, type Select, type SendEmailOptions, ServiceClient, type ServiceResponse, Set, SinglyLinkedList, type Sort, SparseTable, SplayTree, Stack, type StandardApiResponse, StaticArray, StaticTokenProvider, SuffixArray, SuffixTree, TemplateEngine, TernarySearchTree, type TokenProvider, TracingHeaders, TreeNode, Trie, type UpdateQueryOptions, type UploadOptions, type ValidationResult, type ValidationSchema, ZodValidator, authMiddleware, createCorsOptions, createRequestContextMiddleware, days, errorToString, hours, isAllowedOrigin, isJoiSchema, isZodSchema, loadEnv, logger, milliseconds, minutes, pickFields, seconds, sleep, toHours, toMinutes, toSeconds, validate };
package/dist/index.d.ts CHANGED
@@ -1926,7 +1926,19 @@ interface ParsedQuery {
1926
1926
  populate: string[];
1927
1927
  }
1928
1928
 
1929
+ interface ApiFeaturesConfig {
1930
+ defaultPage: number;
1931
+ defaultLimit: number;
1932
+ maxLimit: number;
1933
+ reservedFields: string[];
1934
+ supportedOperators: string[];
1935
+ }
1936
+ declare const DefaultApiFeaturesConfig: ApiFeaturesConfig;
1937
+
1929
1938
  declare class ApiFeatures {
1939
+ private static config;
1940
+ static configure(config: Partial<ApiFeaturesConfig>): void;
1941
+ static getConfig(): ApiFeaturesConfig;
1930
1942
  static parse(query: Record<string, unknown>): ParsedQuery;
1931
1943
  private static parseFilters;
1932
1944
  private static parseSort;
@@ -1935,12 +1947,6 @@ declare class ApiFeatures {
1935
1947
  private static parsePagination;
1936
1948
  }
1937
1949
 
1938
- declare const QUERY_RESERVED_FIELDS: readonly ["page", "limit", "sort", "fields", "populate"];
1939
- declare const DEFAULT_PAGE = 1;
1940
- declare const DEFAULT_LIMIT = 100;
1941
- declare const DEFAULT_SORT_DIRECTION = "asc";
1942
- declare const SUPPORTED_OPERATORS: readonly ["eq", "ne", "gt", "gte", "lt", "lte", "in", "nin", "contains", "startsWith", "endsWith"];
1943
-
1944
1950
  interface ApiResponseOptions<T = unknown> {
1945
1951
  statusCode?: number;
1946
1952
  success?: boolean;
@@ -2340,4 +2346,4 @@ declare function toMinutes(ms: number): number;
2340
2346
  declare function toHours(ms: number): number;
2341
2347
  declare function sleep(ms: number): Promise<void>;
2342
2348
 
2343
- export { AVLTree, AdjacencyList, AdjacencyMatrix, type AdjacentEdge, ApiFeatures, type ApiMeta, ApiResponse, type ApiResponseOptions, AppError, type AppErrorOptions, AsyncHandler, type AsyncRequestHandler, type AuthStrategy, type AuthenticatedUser, type AzureBlobStorageConfig, AzureBlobStorageService, BPlusTree, BTree, BearerTokenStrategy, BinaryHeap, BinarySearchTree, BinaryTree, BloomFilter, CircularArray, CircularLinkedList, CircularQueue, type CloudinaryConfig, CloudinaryService, ConsistentHash, CorrelationId, type CorsOptionsConfig, CountMinSketch, CrudControllerFactory, type CrudControllerOptions, DEFAULT_LIMIT, DEFAULT_PAGE, DEFAULT_SORT_DIRECTION, type DatabaseConnectionOptions, DatabaseManager, type DatabaseProvider, Deque, type DirectedEdge, DirectedGraph, DisjointSetUnion, DoublyLinkedList, DynamicArray, type Edge, type EmailProvider, EmailService, type ErrorMeta, ErrorMiddleware, type ExponentialBackoffOptions, ExponentialBackoffRetryPolicy, FenwickTree, FibNode, FibonacciHeap, type Filter, FixedRetryPolicy, type FixedRetryPolicyOptions, Graph, HashMap, HashSet, HttpClient, type HttpClientOptions, HyperLogLog, type IValidator, type InferSchema, InternalServiceClient, type Interval, IntervalTree, JWTService, type JWTServiceOptions, JoiValidator, KDTree, LFUCache, LRUCache, type LoadEnvOptions, Logger, type LoggerOptions, MaxHeap, MaxStack, MinHeap, MinStack, type MongoDatabaseConfig, MongoDatabaseProvider, MongoRepository, MulterFileHandlerService, MultiSet, Node, OrderedSet, type PaginationMeta, type PaginationQuery, PairingHeap, PairingNode, type ParsedQuery, type PickOptions, type Point, type Point2D, PriorityQueue, type ProgressCallback, QUERY_RESERVED_FIELDS, QuadTree, type QueryFilter, type QueryOperator, type QueryOptions, type QuerySort, Queue, RadixTree, type Rect, RedBlackTree, type Repository, RequestContext, type RequestContextData, type RequestContextOptions, type RetryPolicy, SMTPProvider, SUPPORTED_OPERATORS, SegmentTree, type Select, type SendEmailOptions, ServiceClient, type ServiceResponse, Set, SinglyLinkedList, type Sort, SparseTable, SplayTree, Stack, type StandardApiResponse, StaticArray, StaticTokenProvider, SuffixArray, SuffixTree, TemplateEngine, TernarySearchTree, type TokenProvider, TracingHeaders, TreeNode, Trie, type UpdateQueryOptions, type UploadOptions, type ValidationResult, type ValidationSchema, ZodValidator, authMiddleware, createCorsOptions, createRequestContextMiddleware, days, errorToString, hours, isAllowedOrigin, isJoiSchema, isZodSchema, loadEnv, logger, milliseconds, minutes, pickFields, seconds, sleep, toHours, toMinutes, toSeconds, validate };
2349
+ export { AVLTree, AdjacencyList, AdjacencyMatrix, type AdjacentEdge, ApiFeatures, type ApiFeaturesConfig, type ApiMeta, ApiResponse, type ApiResponseOptions, AppError, type AppErrorOptions, AsyncHandler, type AsyncRequestHandler, type AuthStrategy, type AuthenticatedUser, type AzureBlobStorageConfig, AzureBlobStorageService, BPlusTree, BTree, BearerTokenStrategy, BinaryHeap, BinarySearchTree, BinaryTree, BloomFilter, CircularArray, CircularLinkedList, CircularQueue, type CloudinaryConfig, CloudinaryService, ConsistentHash, CorrelationId, type CorsOptionsConfig, CountMinSketch, CrudControllerFactory, type CrudControllerOptions, type DatabaseConnectionOptions, DatabaseManager, type DatabaseProvider, DefaultApiFeaturesConfig, Deque, type DirectedEdge, DirectedGraph, DisjointSetUnion, DoublyLinkedList, DynamicArray, type Edge, type EmailProvider, EmailService, type ErrorMeta, ErrorMiddleware, type ExponentialBackoffOptions, ExponentialBackoffRetryPolicy, FenwickTree, FibNode, FibonacciHeap, type Filter, FixedRetryPolicy, type FixedRetryPolicyOptions, Graph, HashMap, HashSet, HttpClient, type HttpClientOptions, HyperLogLog, type IValidator, type InferSchema, InternalServiceClient, type Interval, IntervalTree, JWTService, type JWTServiceOptions, JoiValidator, KDTree, LFUCache, LRUCache, type LoadEnvOptions, Logger, type LoggerOptions, MaxHeap, MaxStack, MinHeap, MinStack, type MongoDatabaseConfig, MongoDatabaseProvider, MongoRepository, MulterFileHandlerService, MultiSet, Node, OrderedSet, type PaginationMeta, type PaginationQuery, PairingHeap, PairingNode, type ParsedQuery, type PickOptions, type Point, type Point2D, PriorityQueue, type ProgressCallback, QuadTree, type QueryFilter, type QueryOperator, type QueryOptions, type QuerySort, Queue, RadixTree, type Rect, RedBlackTree, type Repository, RequestContext, type RequestContextData, type RequestContextOptions, type RetryPolicy, SMTPProvider, SegmentTree, type Select, type SendEmailOptions, ServiceClient, type ServiceResponse, Set, SinglyLinkedList, type Sort, SparseTable, SplayTree, Stack, type StandardApiResponse, StaticArray, StaticTokenProvider, SuffixArray, SuffixTree, TemplateEngine, TernarySearchTree, type TokenProvider, TracingHeaders, TreeNode, Trie, type UpdateQueryOptions, type UploadOptions, type ValidationResult, type ValidationSchema, ZodValidator, authMiddleware, createCorsOptions, createRequestContextMiddleware, days, errorToString, hours, isAllowedOrigin, isJoiSchema, isZodSchema, loadEnv, logger, milliseconds, minutes, pickFields, seconds, sleep, toHours, toMinutes, toSeconds, validate };
package/dist/index.js CHANGED
@@ -4989,33 +4989,41 @@ var AsyncHandler = (fn) => (req, res, next) => {
4989
4989
  Promise.resolve(fn(req, res, next)).catch(next);
4990
4990
  };
4991
4991
 
4992
- // src/infrastructure/http/query/QueryConstants.ts
4993
- var QUERY_RESERVED_FIELDS = [
4994
- "page",
4995
- "limit",
4996
- "sort",
4997
- "fields",
4998
- "populate"
4999
- ];
5000
- var DEFAULT_PAGE = 1;
5001
- var DEFAULT_LIMIT = 100;
5002
- var DEFAULT_SORT_DIRECTION = "asc";
5003
- var SUPPORTED_OPERATORS = [
5004
- "eq",
5005
- "ne",
5006
- "gt",
5007
- "gte",
5008
- "lt",
5009
- "lte",
5010
- "in",
5011
- "nin",
5012
- "contains",
5013
- "startsWith",
5014
- "endsWith"
5015
- ];
4992
+ // src/infrastructure/http/query/ApiFeaturesConfig.ts
4993
+ var DefaultApiFeaturesConfig = {
4994
+ defaultPage: 1,
4995
+ defaultLimit: 100,
4996
+ maxLimit: 1e3,
4997
+ reservedFields: ["page", "limit", "sort", "fields", "populate"],
4998
+ supportedOperators: [
4999
+ "eq",
5000
+ "ne",
5001
+ "gt",
5002
+ "gte",
5003
+ "lt",
5004
+ "lte",
5005
+ "in",
5006
+ "nin",
5007
+ "contains",
5008
+ "startsWith",
5009
+ "endsWith"
5010
+ ]
5011
+ };
5016
5012
 
5017
5013
  // src/infrastructure/http/query/ApiFeatures.ts
5018
5014
  var ApiFeatures = class {
5015
+ static config = {
5016
+ ...DefaultApiFeaturesConfig
5017
+ };
5018
+ static configure(config) {
5019
+ this.config = {
5020
+ ...this.config,
5021
+ ...config
5022
+ };
5023
+ }
5024
+ static getConfig() {
5025
+ return this.config;
5026
+ }
5019
5027
  static parse(query) {
5020
5028
  return {
5021
5029
  filters: this.parseFilters(query),
@@ -5028,12 +5036,11 @@ var ApiFeatures = class {
5028
5036
  static parseFilters(query) {
5029
5037
  const filters = [];
5030
5038
  Object.entries(query).forEach(([key, value]) => {
5031
- if (QUERY_RESERVED_FIELDS.includes(key)) {
5039
+ if (this.config.reservedFields.includes(key)) {
5032
5040
  return;
5033
5041
  }
5034
- const match = key.match(
5035
- /^(.+)\[(eq|ne|gt|gte|lt|lte|in|nin|contains|startsWith|endsWith)\]$/
5036
- );
5042
+ const operatorsPattern = this.config.supportedOperators.join("|");
5043
+ const match = key.match(new RegExp(`^(.+)\\[(${operatorsPattern})\\]$`));
5037
5044
  if (match) {
5038
5045
  filters.push({
5039
5046
  field: match[1],
@@ -5083,8 +5090,9 @@ var ApiFeatures = class {
5083
5090
  return populate.split(",").map((field) => field.trim()).filter(Boolean);
5084
5091
  }
5085
5092
  static parsePagination(query) {
5086
- const page = Number(query.page) || DEFAULT_PAGE;
5087
- const limit = Number(query.limit) || DEFAULT_LIMIT;
5093
+ const page = Math.max(1, Number(query.page) || this.config.defaultPage);
5094
+ const requestedLimit = Number(query.limit) || this.config.defaultLimit;
5095
+ const limit = Math.min(Math.max(1, requestedLimit), this.config.maxLimit);
5088
5096
  return {
5089
5097
  page,
5090
5098
  limit
@@ -6366,6 +6374,6 @@ function sleep(ms) {
6366
6374
  return new Promise((resolve) => setTimeout(resolve, ms));
6367
6375
  }
6368
6376
 
6369
- export { AVLTree, AdjacencyList, AdjacencyMatrix, ApiFeatures, ApiResponse, AppError, AsyncHandler, AzureBlobStorageService, BPlusTree, BTree, BearerTokenStrategy, BinaryHeap, BinarySearchTree, BinaryTree, BloomFilter, CircularArray, CircularLinkedList, CircularQueue, CloudinaryService, ConsistentHash, CorrelationId, CountMinSketch, CrudControllerFactory, DEFAULT_LIMIT, DEFAULT_PAGE, DEFAULT_SORT_DIRECTION, DatabaseManager, Deque, DirectedGraph, DisjointSetUnion, DoublyLinkedList, DynamicArray, EmailService, ErrorMiddleware, ExponentialBackoffRetryPolicy, FenwickTree, FibNode, FibonacciHeap, FixedRetryPolicy, Graph, HashMap, HashSet, HttpClient, HyperLogLog, InternalServiceClient, IntervalTree, JWTService, JoiValidator, KDTree, LFUCache, LRUCache, Logger, MaxHeap, MaxStack, MinHeap, MinStack, MongoDatabaseProvider, MongoRepository, MulterFileHandlerService, MultiSet, Node, OrderedSet, PairingHeap, PairingNode, PriorityQueue, QUERY_RESERVED_FIELDS, QuadTree, Queue, RadixTree, RedBlackTree, RequestContext, SMTPProvider, SUPPORTED_OPERATORS, SegmentTree, ServiceClient, Set2 as Set, SinglyLinkedList, SparseTable, SplayTree, Stack, StaticArray, StaticTokenProvider, SuffixArray, SuffixTree, TemplateEngine, TernarySearchTree, TracingHeaders, TreeNode, Trie, ZodValidator, authMiddleware, createCorsOptions, createRequestContextMiddleware, days, errorToString, hours, isAllowedOrigin, isJoiSchema, isZodSchema, loadEnv, logger, milliseconds, minutes, pickFields, seconds, sleep, toHours, toMinutes, toSeconds, validate };
6377
+ export { AVLTree, AdjacencyList, AdjacencyMatrix, ApiFeatures, ApiResponse, AppError, AsyncHandler, AzureBlobStorageService, BPlusTree, BTree, BearerTokenStrategy, BinaryHeap, BinarySearchTree, BinaryTree, BloomFilter, CircularArray, CircularLinkedList, CircularQueue, CloudinaryService, ConsistentHash, CorrelationId, CountMinSketch, CrudControllerFactory, DatabaseManager, DefaultApiFeaturesConfig, Deque, DirectedGraph, DisjointSetUnion, DoublyLinkedList, DynamicArray, EmailService, ErrorMiddleware, ExponentialBackoffRetryPolicy, FenwickTree, FibNode, FibonacciHeap, FixedRetryPolicy, Graph, HashMap, HashSet, HttpClient, HyperLogLog, InternalServiceClient, IntervalTree, JWTService, JoiValidator, KDTree, LFUCache, LRUCache, Logger, MaxHeap, MaxStack, MinHeap, MinStack, MongoDatabaseProvider, MongoRepository, MulterFileHandlerService, MultiSet, Node, OrderedSet, PairingHeap, PairingNode, PriorityQueue, QuadTree, Queue, RadixTree, RedBlackTree, RequestContext, SMTPProvider, SegmentTree, ServiceClient, Set2 as Set, SinglyLinkedList, SparseTable, SplayTree, Stack, StaticArray, StaticTokenProvider, SuffixArray, SuffixTree, TemplateEngine, TernarySearchTree, TracingHeaders, TreeNode, Trie, ZodValidator, authMiddleware, createCorsOptions, createRequestContextMiddleware, days, errorToString, hours, isAllowedOrigin, isJoiSchema, isZodSchema, loadEnv, logger, milliseconds, minutes, pickFields, seconds, sleep, toHours, toMinutes, toSeconds, validate };
6370
6378
  //# sourceMappingURL=index.js.map
6371
6379
  //# sourceMappingURL=index.js.map