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.cjs CHANGED
@@ -5004,33 +5004,41 @@ var AsyncHandler = (fn) => (req, res, next) => {
5004
5004
  Promise.resolve(fn(req, res, next)).catch(next);
5005
5005
  };
5006
5006
 
5007
- // src/infrastructure/http/query/QueryConstants.ts
5008
- var QUERY_RESERVED_FIELDS = [
5009
- "page",
5010
- "limit",
5011
- "sort",
5012
- "fields",
5013
- "populate"
5014
- ];
5015
- var DEFAULT_PAGE = 1;
5016
- var DEFAULT_LIMIT = 100;
5017
- var DEFAULT_SORT_DIRECTION = "asc";
5018
- var SUPPORTED_OPERATORS = [
5019
- "eq",
5020
- "ne",
5021
- "gt",
5022
- "gte",
5023
- "lt",
5024
- "lte",
5025
- "in",
5026
- "nin",
5027
- "contains",
5028
- "startsWith",
5029
- "endsWith"
5030
- ];
5007
+ // src/infrastructure/http/query/ApiFeaturesConfig.ts
5008
+ var DefaultApiFeaturesConfig = {
5009
+ defaultPage: 1,
5010
+ defaultLimit: 100,
5011
+ maxLimit: 1e3,
5012
+ reservedFields: ["page", "limit", "sort", "fields", "populate"],
5013
+ supportedOperators: [
5014
+ "eq",
5015
+ "ne",
5016
+ "gt",
5017
+ "gte",
5018
+ "lt",
5019
+ "lte",
5020
+ "in",
5021
+ "nin",
5022
+ "contains",
5023
+ "startsWith",
5024
+ "endsWith"
5025
+ ]
5026
+ };
5031
5027
 
5032
5028
  // src/infrastructure/http/query/ApiFeatures.ts
5033
5029
  var ApiFeatures = class {
5030
+ static config = {
5031
+ ...DefaultApiFeaturesConfig
5032
+ };
5033
+ static configure(config) {
5034
+ this.config = {
5035
+ ...this.config,
5036
+ ...config
5037
+ };
5038
+ }
5039
+ static getConfig() {
5040
+ return this.config;
5041
+ }
5034
5042
  static parse(query) {
5035
5043
  return {
5036
5044
  filters: this.parseFilters(query),
@@ -5043,12 +5051,11 @@ var ApiFeatures = class {
5043
5051
  static parseFilters(query) {
5044
5052
  const filters = [];
5045
5053
  Object.entries(query).forEach(([key, value]) => {
5046
- if (QUERY_RESERVED_FIELDS.includes(key)) {
5054
+ if (this.config.reservedFields.includes(key)) {
5047
5055
  return;
5048
5056
  }
5049
- const match = key.match(
5050
- /^(.+)\[(eq|ne|gt|gte|lt|lte|in|nin|contains|startsWith|endsWith)\]$/
5051
- );
5057
+ const operatorsPattern = this.config.supportedOperators.join("|");
5058
+ const match = key.match(new RegExp(`^(.+)\\[(${operatorsPattern})\\]$`));
5052
5059
  if (match) {
5053
5060
  filters.push({
5054
5061
  field: match[1],
@@ -5098,8 +5105,9 @@ var ApiFeatures = class {
5098
5105
  return populate.split(",").map((field) => field.trim()).filter(Boolean);
5099
5106
  }
5100
5107
  static parsePagination(query) {
5101
- const page = Number(query.page) || DEFAULT_PAGE;
5102
- const limit = Number(query.limit) || DEFAULT_LIMIT;
5108
+ const page = Math.max(1, Number(query.page) || this.config.defaultPage);
5109
+ const requestedLimit = Number(query.limit) || this.config.defaultLimit;
5110
+ const limit = Math.min(Math.max(1, requestedLimit), this.config.maxLimit);
5103
5111
  return {
5104
5112
  page,
5105
5113
  limit
@@ -6404,10 +6412,8 @@ exports.ConsistentHash = ConsistentHash;
6404
6412
  exports.CorrelationId = CorrelationId;
6405
6413
  exports.CountMinSketch = CountMinSketch;
6406
6414
  exports.CrudControllerFactory = CrudControllerFactory;
6407
- exports.DEFAULT_LIMIT = DEFAULT_LIMIT;
6408
- exports.DEFAULT_PAGE = DEFAULT_PAGE;
6409
- exports.DEFAULT_SORT_DIRECTION = DEFAULT_SORT_DIRECTION;
6410
6415
  exports.DatabaseManager = DatabaseManager;
6416
+ exports.DefaultApiFeaturesConfig = DefaultApiFeaturesConfig;
6411
6417
  exports.Deque = Deque;
6412
6418
  exports.DirectedGraph = DirectedGraph;
6413
6419
  exports.DisjointSetUnion = DisjointSetUnion;
@@ -6446,14 +6452,12 @@ exports.OrderedSet = OrderedSet;
6446
6452
  exports.PairingHeap = PairingHeap;
6447
6453
  exports.PairingNode = PairingNode;
6448
6454
  exports.PriorityQueue = PriorityQueue;
6449
- exports.QUERY_RESERVED_FIELDS = QUERY_RESERVED_FIELDS;
6450
6455
  exports.QuadTree = QuadTree;
6451
6456
  exports.Queue = Queue;
6452
6457
  exports.RadixTree = RadixTree;
6453
6458
  exports.RedBlackTree = RedBlackTree;
6454
6459
  exports.RequestContext = RequestContext;
6455
6460
  exports.SMTPProvider = SMTPProvider;
6456
- exports.SUPPORTED_OPERATORS = SUPPORTED_OPERATORS;
6457
6461
  exports.SegmentTree = SegmentTree;
6458
6462
  exports.ServiceClient = ServiceClient;
6459
6463
  exports.Set = Set2;