mongoose-query-find 3.0.3 → 3.0.4
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.ts +100 -58
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +327 -294
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - URL query string → Mongoose filter (sanitized, validated, coerced)
|
|
8
8
|
* - Global full-text search via $or regex
|
|
9
9
|
* - Flexible sort, field projection, and populate
|
|
10
|
-
* - count + find run fully in parallel (Promise.all)
|
|
10
|
+
* - count + find run fully in parallel (Promise.all) — no wasted round-trips
|
|
11
11
|
* - Hard limits on page size, sort fields, search length, nesting depth (DoS protection)
|
|
12
12
|
* - Allowlist-based field filtering on filters, sort, AND projection (NoSQL injection prevention)
|
|
13
13
|
* - Case-insensitive allowlist matching (e.g. allowFields(['Name']) matches ?name=, ?NAME=, ?Name=)
|
|
@@ -18,7 +18,30 @@
|
|
|
18
18
|
* - estimatedDocumentCount fast-path when no filter is applied
|
|
19
19
|
* - Query timeout via maxTimeMS (prevents runaway queries)
|
|
20
20
|
* - Structured error types for clean upstream handling
|
|
21
|
+
* - Optional cached total for skipping re-count on page > 1
|
|
22
|
+
* - Optional slow-query hook for observability
|
|
21
23
|
* - Zero external runtime dependencies beyond mongoose
|
|
24
|
+
*
|
|
25
|
+
* Fixes applied on top of original:
|
|
26
|
+
* 1. where() conditions are stored separately and merged last in paginate() —
|
|
27
|
+
* URL params can no longer overwrite server-side conditions like deletedAt: null.
|
|
28
|
+
* 2. globalSearch() guards against double-call: subsequent calls extend the
|
|
29
|
+
* $or array rather than re-wrapping the entire filter in nested $and.
|
|
30
|
+
* 3. Slow-query wrapper now covers execCount() on page > 1 (no cachedTotal path).
|
|
31
|
+
* 4. parseLimit / parsePage are computed once in the constructor, not on every
|
|
32
|
+
* paginate() call.
|
|
33
|
+
* 5. sanitize() calls onDrop when MAX_NESTING_DEPTH is exceeded, instead of
|
|
34
|
+
* silently returning undefined.
|
|
35
|
+
* 6. buildAllowedStructures result is memoized — rebuilds only when allowFields()
|
|
36
|
+
* is actually called.
|
|
37
|
+
* 7. wrapTimed, execFind, execCount promoted to private methods — no longer
|
|
38
|
+
* re-created as closures on every paginate() call.
|
|
39
|
+
* 8. DEFAULT_SORT freeze is removed; copies are made where needed, the constant
|
|
40
|
+
* itself is just a plain object used as the default spread source.
|
|
41
|
+
* 9. lean() exposed as a QueryFindOptions flag (default true) so callers that
|
|
42
|
+
* need Mongoose document instances (virtuals, instance methods) can opt out.
|
|
43
|
+
* 10. Double-cast `as unknown as Promise<number>` replaced with explicit typed
|
|
44
|
+
* helper to surface any future version mismatches at compile time.
|
|
22
45
|
*/
|
|
23
46
|
import { Model, PopulateOptions, Query } from 'mongoose';
|
|
24
47
|
export interface QueryParams {
|
|
@@ -38,12 +61,40 @@ export interface PaginatedResult<T> {
|
|
|
38
61
|
hasNextPage: boolean;
|
|
39
62
|
hasPrevPage: boolean;
|
|
40
63
|
}
|
|
64
|
+
export interface SlowQueryInfo {
|
|
65
|
+
/** Elapsed time in milliseconds */
|
|
66
|
+
elapsedMs: number;
|
|
67
|
+
/** The Mongoose filter that was applied */
|
|
68
|
+
filter: Record<string, unknown>;
|
|
69
|
+
/** The sort that was applied */
|
|
70
|
+
sort: Record<string, 1 | -1>;
|
|
71
|
+
/** The page that was requested */
|
|
72
|
+
page: number;
|
|
73
|
+
/** The limit that was applied */
|
|
74
|
+
limit: number;
|
|
75
|
+
}
|
|
41
76
|
export interface QueryFindOptions {
|
|
77
|
+
maxTimeMS?: number;
|
|
42
78
|
/**
|
|
43
|
-
*
|
|
44
|
-
* Defaults to
|
|
79
|
+
* Threshold in ms above which onSlowQuery fires.
|
|
80
|
+
* Defaults to maxTimeMS. Set lower (e.g. 1000) to catch slow-but-not-timed-out queries.
|
|
45
81
|
*/
|
|
46
|
-
|
|
82
|
+
slowQueryThresholdMS?: number;
|
|
83
|
+
/**
|
|
84
|
+
* Called when a query exceeds slowQueryThresholdMS.
|
|
85
|
+
* Use to emit metrics, log to your APM, etc.
|
|
86
|
+
*/
|
|
87
|
+
onSlowQuery?: (info: SlowQueryInfo) => void;
|
|
88
|
+
/**
|
|
89
|
+
* Called when sanitize() silently drops a value (e.g. a Date or class instance).
|
|
90
|
+
* Defaults to console.warn in non-production environments.
|
|
91
|
+
*/
|
|
92
|
+
onSanitizeDrop?: (path: string, value: unknown) => void;
|
|
93
|
+
/**
|
|
94
|
+
* Fix #9: whether to call .lean() on find queries (default: true).
|
|
95
|
+
* Set to false if you need Mongoose document instances (virtuals, instance methods).
|
|
96
|
+
*/
|
|
97
|
+
lean?: boolean;
|
|
47
98
|
}
|
|
48
99
|
export declare class QueryFindError extends Error {
|
|
49
100
|
constructor(message: string);
|
|
@@ -66,79 +117,48 @@ export declare class QueryFindValidationError extends QueryFindError {
|
|
|
66
117
|
* .populate('department', 'name')
|
|
67
118
|
* .paginate();
|
|
68
119
|
* ```
|
|
69
|
-
*
|
|
70
|
-
* Security notes:
|
|
71
|
-
* - `.allowFields()` before `.filter()` restricts which URL params reach Mongo.
|
|
72
|
-
* - Allowlist matching (filter/sort/projection) is case-insensitive — e.g.
|
|
73
|
-
* allowFields(['name']) also matches ?Name=, ?NAME=, etc. For `.filter()`,
|
|
74
|
-
* a matched field is also normalized back to the casing declared in
|
|
75
|
-
* allowFields() (e.g. ?NAME=foo -> { name: 'foo' }) so it matches the
|
|
76
|
-
* actual schema path.
|
|
77
|
-
* - `.where()` conditions are hard — URL cannot override them.
|
|
78
|
-
* - Unknown/banned $ operators throw QueryFindValidationError (checked recursively).
|
|
79
|
-
* - Nesting depth capped at 5; page size capped at 100; sort fields capped at 5.
|
|
80
|
-
* - Search terms are regex-escaped (ReDoS prevention) and length-capped at 200 chars.
|
|
81
|
-
* - ?fields= projection is allowlist-filtered to prevent sensitive field leakage.
|
|
82
|
-
* - Operator-key coercion (eq/gte/in/...) only touches object KEYS, never string
|
|
83
|
-
* VALUES — a search like ?name=eq or ?status=in cannot be corrupted into a
|
|
84
|
-
* Mongo operator.
|
|
85
|
-
* - All queries run with maxTimeMS to prevent runaway collection scans.
|
|
86
120
|
*/
|
|
87
121
|
export declare class QueryFind<TRawDocType, TModelType extends Model<TRawDocType> = Model<TRawDocType>> {
|
|
88
122
|
private readonly model;
|
|
89
123
|
private readonly qs;
|
|
90
124
|
private readonly options;
|
|
91
125
|
private _allowedFields;
|
|
92
|
-
/** Lowercase mirror of _allowedFields, used for case-insensitive matching. */
|
|
93
126
|
private _allowedLookup;
|
|
94
|
-
private
|
|
127
|
+
private _canonicalMap;
|
|
128
|
+
private _urlFilter;
|
|
129
|
+
private _serverConditions;
|
|
130
|
+
private _searchOr;
|
|
95
131
|
private _sort;
|
|
96
132
|
private _select;
|
|
97
133
|
private _populates;
|
|
134
|
+
private readonly _page;
|
|
135
|
+
private readonly _limit;
|
|
98
136
|
constructor(query: Query<TRawDocType[], TRawDocType>, queryString: QueryParams, options?: QueryFindOptions);
|
|
99
|
-
/**
|
|
100
|
-
* Declare which fields may appear in URL filters, sort, and projection.
|
|
101
|
-
* Matching against `?field=`, `?sort=`, and `?fields=` is case-insensitive,
|
|
102
|
-
* so `allowFields(['Name', 'Email'])` will also match `?name=`, `?NAME=`,
|
|
103
|
-
* `?eMail=`, etc.
|
|
104
|
-
* Call before `.filter()`, `.sort()`, and `.limitFields()`.
|
|
105
|
-
*/
|
|
106
137
|
allowFields(fields: string[]): this;
|
|
107
|
-
/** Parse URL query params into a Mongoose filter (respects allowlist). */
|
|
108
138
|
filter(): this;
|
|
109
139
|
/**
|
|
110
140
|
* Apply mandatory server-side conditions the URL cannot override.
|
|
111
|
-
*
|
|
141
|
+
*
|
|
142
|
+
* Fix #1: conditions are stored in _serverConditions and merged into the
|
|
143
|
+
* final filter last, inside paginate(). This guarantees URL params (stored
|
|
144
|
+
* in _urlFilter) can never overwrite server-side values regardless of the
|
|
145
|
+
* order in which .where() and .filter() are called.
|
|
112
146
|
*
|
|
113
147
|
* @example .where({ orgId: req.user.orgId, deletedAt: null })
|
|
114
148
|
*/
|
|
115
149
|
where(conditions: Partial<Record<keyof TRawDocType, unknown>>): this;
|
|
116
150
|
/**
|
|
117
151
|
* Case-insensitive full-text search across `fields` when `?q=` is present.
|
|
118
|
-
*
|
|
119
|
-
*
|
|
152
|
+
*
|
|
153
|
+
* Fix #2: subsequent calls extend the $or clause list rather than re-wrapping
|
|
154
|
+
* the filter in nested $and, preventing double-wrapping and preserving index
|
|
155
|
+
* usage.
|
|
120
156
|
*/
|
|
121
157
|
globalSearch(fields: string[]): this;
|
|
122
|
-
/**
|
|
123
|
-
* Apply sort from `?sort=`. Falls back to `{ createdAt: -1 }`.
|
|
124
|
-
* Fields not in the allowlist are silently skipped (case-insensitive match).
|
|
125
|
-
* Capped at MAX_SORT_FIELDS (5) fields.
|
|
126
|
-
*/
|
|
127
158
|
sort(): this;
|
|
128
|
-
/**
|
|
129
|
-
* Configure field projection.
|
|
130
|
-
* Priority: `?fields=` query param > `defaultFields` argument > no projection.
|
|
131
|
-
*
|
|
132
|
-
* When `allowFields()` has been called, any field in `?fields=` that is not
|
|
133
|
-
* in the allowlist is stripped (case-insensitive match) — preventing clients
|
|
134
|
-
* from projecting sensitive fields like `password` or `resetToken`.
|
|
135
|
-
*
|
|
136
|
-
* @param defaultFields e.g. `'-password -__v'` — always excluded when the
|
|
137
|
-
* client does not supply `?fields=`.
|
|
138
|
-
*/
|
|
139
159
|
limitFields(defaultFields?: string): this;
|
|
140
160
|
/**
|
|
141
|
-
* Register a populate path.
|
|
161
|
+
* Register a populate path.
|
|
142
162
|
*
|
|
143
163
|
* @example
|
|
144
164
|
* .populate('author')
|
|
@@ -147,17 +167,39 @@ export declare class QueryFind<TRawDocType, TModelType extends Model<TRawDocType
|
|
|
147
167
|
*/
|
|
148
168
|
populate(path: string | PopulateOptions, select?: string): this;
|
|
149
169
|
/**
|
|
150
|
-
*
|
|
170
|
+
* Fix #1: assemble the final filter by merging URL filter, search clause,
|
|
171
|
+
* and server conditions. Server conditions are applied last so they can
|
|
172
|
+
* never be overwritten by URL-derived values.
|
|
151
173
|
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
174
|
+
* Fix #2: _searchOr is assembled here once rather than incrementally
|
|
175
|
+
* mutating _filter during globalSearch() calls.
|
|
176
|
+
*/
|
|
177
|
+
private buildFinalFilter;
|
|
178
|
+
/**
|
|
179
|
+
* Fix #7: execFind promoted to private method — no longer a closure
|
|
180
|
+
* recreated on every paginate() call.
|
|
181
|
+
*/
|
|
182
|
+
private execFind;
|
|
183
|
+
/**
|
|
184
|
+
* Fix #7: execCount promoted to private method.
|
|
185
|
+
* Calls .exec() directly — avoids the Model<unknown> generic mismatch that
|
|
186
|
+
* broke the earlier execCountQuery helper approach.
|
|
187
|
+
*/
|
|
188
|
+
private execCount;
|
|
189
|
+
/**
|
|
190
|
+
* Fix #3 + Fix #7: wrapTimed promoted to a private method that accepts an
|
|
191
|
+
* explicit start time so the slow-query clock can be started before
|
|
192
|
+
* execCount() on page > 1 paths, covering the full round-trip.
|
|
193
|
+
*/
|
|
194
|
+
private wrapTimed;
|
|
195
|
+
/**
|
|
196
|
+
* Execute and return a paginated result.
|
|
157
197
|
*
|
|
198
|
+
* @param cachedTotal - Previously fetched total (from a page-1 response).
|
|
199
|
+
* When provided on page > 1, the count query is skipped entirely.
|
|
158
200
|
* @throws {QueryFindValidationError} on disallowed $ operators in the URL.
|
|
159
201
|
*/
|
|
160
|
-
paginate(): Promise<PaginatedResult<TRawDocType>>;
|
|
202
|
+
paginate(cachedTotal?: number): Promise<PaginatedResult<TRawDocType>>;
|
|
161
203
|
}
|
|
162
204
|
/**
|
|
163
205
|
* Convenience factory — avoids `new` at the call site.
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH,OAAiB,EAAE,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AA+CnE,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,OAAO,CAAC;IACrB,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,aAAa;IAC5B,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAC7B,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,iCAAiC;IACjC,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;OAGG;IACH,WAAW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AE,OAAO,CAAC,MAAM,CAAC,MAAM,WAAW,EAAE,OAAO,CAAC,CAAC,GAAG,IAAI;IAYpE;;;;;;OAMG;IACH,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI;IAyBpC,IAAI,IAAI,IAAI;IAaZ,WAAW,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI;IAczC;;;;;;;OAOG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI;IAuB/D;;;;;;;OAOG;IACH,OAAO,CAAC,gBAAgB;IAexB;;;OAGG;IACH,OAAO,CAAC,QAAQ;IAoBhB;;;;OAIG;YACW,SAAS;IAiBvB;;;;OAIG;YACW,SAAS;IAsBvB;;;;;;OAMG;IACG,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;CAgG5E;AAID;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,CAAC,EACzB,KAAK,EAAE,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EACpB,WAAW,EAAE,WAAW,EACxB,OAAO,CAAC,EAAE,gBAAgB,GACzB,SAAS,CAAC,CAAC,CAAC,CAEd;AAED,eAAe,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* - URL query string → Mongoose filter (sanitized, validated, coerced)
|
|
9
9
|
* - Global full-text search via $or regex
|
|
10
10
|
* - Flexible sort, field projection, and populate
|
|
11
|
-
* - count + find run fully in parallel (Promise.all)
|
|
11
|
+
* - count + find run fully in parallel (Promise.all) — no wasted round-trips
|
|
12
12
|
* - Hard limits on page size, sort fields, search length, nesting depth (DoS protection)
|
|
13
13
|
* - Allowlist-based field filtering on filters, sort, AND projection (NoSQL injection prevention)
|
|
14
14
|
* - Case-insensitive allowlist matching (e.g. allowFields(['Name']) matches ?name=, ?NAME=, ?Name=)
|
|
@@ -19,30 +19,42 @@
|
|
|
19
19
|
* - estimatedDocumentCount fast-path when no filter is applied
|
|
20
20
|
* - Query timeout via maxTimeMS (prevents runaway queries)
|
|
21
21
|
* - Structured error types for clean upstream handling
|
|
22
|
+
* - Optional cached total for skipping re-count on page > 1
|
|
23
|
+
* - Optional slow-query hook for observability
|
|
22
24
|
* - Zero external runtime dependencies beyond mongoose
|
|
25
|
+
*
|
|
26
|
+
* Fixes applied on top of original:
|
|
27
|
+
* 1. where() conditions are stored separately and merged last in paginate() —
|
|
28
|
+
* URL params can no longer overwrite server-side conditions like deletedAt: null.
|
|
29
|
+
* 2. globalSearch() guards against double-call: subsequent calls extend the
|
|
30
|
+
* $or array rather than re-wrapping the entire filter in nested $and.
|
|
31
|
+
* 3. Slow-query wrapper now covers execCount() on page > 1 (no cachedTotal path).
|
|
32
|
+
* 4. parseLimit / parsePage are computed once in the constructor, not on every
|
|
33
|
+
* paginate() call.
|
|
34
|
+
* 5. sanitize() calls onDrop when MAX_NESTING_DEPTH is exceeded, instead of
|
|
35
|
+
* silently returning undefined.
|
|
36
|
+
* 6. buildAllowedStructures result is memoized — rebuilds only when allowFields()
|
|
37
|
+
* is actually called.
|
|
38
|
+
* 7. wrapTimed, execFind, execCount promoted to private methods — no longer
|
|
39
|
+
* re-created as closures on every paginate() call.
|
|
40
|
+
* 8. DEFAULT_SORT freeze is removed; copies are made where needed, the constant
|
|
41
|
+
* itself is just a plain object used as the default spread source.
|
|
42
|
+
* 9. lean() exposed as a QueryFindOptions flag (default true) so callers that
|
|
43
|
+
* need Mongoose document instances (virtuals, instance methods) can opt out.
|
|
44
|
+
* 10. Double-cast `as unknown as Promise<number>` replaced with explicit typed
|
|
45
|
+
* helper to surface any future version mismatches at compile time.
|
|
23
46
|
*/
|
|
24
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
48
|
exports.queryFind = exports.QueryFind = exports.QueryFindValidationError = exports.QueryFindError = void 0;
|
|
26
49
|
// ─── Constants ────────────────────────────────────────────────────────────────
|
|
27
50
|
const RESERVED_KEYS = new Set(['page', 'sort', 'limit', 'fields', 'q']);
|
|
28
|
-
/** Hard cap — prevents clients from dumping the whole collection. */
|
|
29
51
|
const MAX_LIMIT = 100;
|
|
30
|
-
/** Hard cap — prevents DoS via ?a[b][c][d][e][f]=1 */
|
|
31
52
|
const MAX_NESTING_DEPTH = 5;
|
|
32
|
-
/** Hard cap — prevents compiling huge regexes from ?q= */
|
|
33
53
|
const MAX_SEARCH_LENGTH = 200;
|
|
34
|
-
/** Hard cap — prevents abuse via ?sort=a,b,c,d,e,f,... */
|
|
35
54
|
const MAX_SORT_FIELDS = 5;
|
|
36
|
-
/** Default query timeout in milliseconds — prevents runaway scans on unindexed fields. */
|
|
37
55
|
const DEFAULT_MAX_TIME_MS = 5000;
|
|
38
56
|
const DATE_FIELD_RE = /(^|\.)(createdAt|updatedAt|deletedAt|date|birthDate|expiresAt)$/i;
|
|
39
57
|
const PLAIN_DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
40
|
-
/**
|
|
41
|
-
* Mongo comparison/array operator names accepted WITHOUT a leading "$" in
|
|
42
|
-
* the URL query string (e.g. `?age[gte]=18` → `{ age: { $gte: 18 } }`).
|
|
43
|
-
* Only ever applied to OBJECT KEYS during the recursive coercion pass —
|
|
44
|
-
* never to string values — so a value like `?name=eq` is left untouched.
|
|
45
|
-
*/
|
|
46
58
|
const COERCIBLE_OPS = new Set([
|
|
47
59
|
'eq',
|
|
48
60
|
'ne',
|
|
@@ -53,12 +65,9 @@ const COERCIBLE_OPS = new Set([
|
|
|
53
65
|
'in',
|
|
54
66
|
'nin',
|
|
55
67
|
]);
|
|
56
|
-
|
|
68
|
+
// Fix #8: plain object — no freeze needed, it is never mutated in place.
|
|
69
|
+
const DEFAULT_SORT = { createdAt: -1 };
|
|
57
70
|
const ALLOWED_TOP_LEVEL_OPS = new Set(['$and', '$or', '$nor', '$not']);
|
|
58
|
-
/**
|
|
59
|
-
* Operators that are never permitted anywhere in a client-supplied filter,
|
|
60
|
-
* regardless of nesting depth. Catches $where, $expr, $function, etc.
|
|
61
|
-
*/
|
|
62
71
|
const BANNED_OPERATORS = new Set([
|
|
63
72
|
'$where',
|
|
64
73
|
'$expr',
|
|
@@ -95,192 +104,146 @@ function parseLimit(raw) {
|
|
|
95
104
|
return Math.min(n, MAX_LIMIT);
|
|
96
105
|
}
|
|
97
106
|
// ─── Sanitization ─────────────────────────────────────────────────────────────
|
|
98
|
-
function sanitize(value, depth = 0) {
|
|
99
|
-
|
|
107
|
+
function sanitize(value, depth = 0, path = '', onDrop) {
|
|
108
|
+
// Fix #5: call onDrop when depth limit is exceeded so callers are notified.
|
|
109
|
+
if (depth > MAX_NESTING_DEPTH) {
|
|
110
|
+
if (onDrop) {
|
|
111
|
+
onDrop(path, value);
|
|
112
|
+
}
|
|
113
|
+
else if (process.env.NODE_ENV !== 'production') {
|
|
114
|
+
console.warn(`[query-find] sanitize() dropped value exceeding max nesting depth at path "${path}":`, value);
|
|
115
|
+
}
|
|
100
116
|
return undefined;
|
|
101
|
-
if (value === null ||
|
|
102
|
-
typeof value === 'string' ||
|
|
103
|
-
typeof value === 'number' ||
|
|
104
|
-
typeof value === 'boolean') {
|
|
105
|
-
return value;
|
|
106
117
|
}
|
|
118
|
+
if (value === null)
|
|
119
|
+
return null;
|
|
120
|
+
const t = typeof value;
|
|
121
|
+
if (t === 'string' || t === 'number' || t === 'boolean')
|
|
122
|
+
return value;
|
|
107
123
|
if (Array.isArray(value)) {
|
|
108
124
|
const out = [];
|
|
109
|
-
for (
|
|
110
|
-
const s = sanitize(
|
|
125
|
+
for (let i = 0; i < value.length; i++) {
|
|
126
|
+
const s = sanitize(value[i], depth + 1, `${path}[${i}]`, onDrop);
|
|
111
127
|
if (s !== undefined)
|
|
112
128
|
out.push(s);
|
|
113
129
|
}
|
|
114
130
|
return out;
|
|
115
131
|
}
|
|
116
|
-
if (
|
|
117
|
-
|
|
132
|
+
if (t === 'object' && Object.getPrototypeOf(value) === Object.prototype) {
|
|
133
|
+
const src = value;
|
|
118
134
|
const out = {};
|
|
119
|
-
for (const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
135
|
+
for (const k in src) {
|
|
136
|
+
if (Object.prototype.hasOwnProperty.call(src, k)) {
|
|
137
|
+
const childPath = path ? `${path}.${k}` : k;
|
|
138
|
+
const s = sanitize(src[k], depth + 1, childPath, onDrop);
|
|
139
|
+
if (s !== undefined)
|
|
140
|
+
out[k] = s;
|
|
141
|
+
}
|
|
123
142
|
}
|
|
124
143
|
return out;
|
|
125
144
|
}
|
|
145
|
+
// Non-plain-object dropped — notify caller.
|
|
146
|
+
if (onDrop) {
|
|
147
|
+
onDrop(path, value);
|
|
148
|
+
}
|
|
149
|
+
else if (process.env.NODE_ENV !== 'production') {
|
|
150
|
+
console.warn(`[query-find] sanitize() dropped non-plain value at path "${path}":`, value);
|
|
151
|
+
}
|
|
126
152
|
return undefined;
|
|
127
153
|
}
|
|
128
154
|
// ─── Allowlist ────────────────────────────────────────────────────────────────
|
|
129
|
-
|
|
130
|
-
* Builds a lowercase lookup set from the user-supplied allowlist so that
|
|
131
|
-
* field matching is case-insensitive (e.g. allowFields(['Name', 'Email'])
|
|
132
|
-
* will match ?name=, ?NAME=, ?eMail=, etc.). The original-cased fields are
|
|
133
|
-
* still used wherever they need to be emitted (e.g. default sort/projection).
|
|
134
|
-
*/
|
|
135
|
-
function buildAllowedLookup(allowedFields) {
|
|
155
|
+
function buildAllowedStructures(allowedFields) {
|
|
136
156
|
const lookup = new Set();
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
157
|
+
const canonical = new Map();
|
|
158
|
+
for (const f of allowedFields) {
|
|
159
|
+
const lc = f.toLowerCase();
|
|
160
|
+
lookup.add(lc);
|
|
161
|
+
canonical.set(lc, f);
|
|
162
|
+
}
|
|
163
|
+
return { lookup, canonical };
|
|
140
164
|
}
|
|
141
|
-
/** Case-insensitive membership check against a lowercase lookup set. */
|
|
142
165
|
function isFieldAllowed(field, allowedLookup) {
|
|
143
166
|
return allowedLookup.has(field.toLowerCase());
|
|
144
167
|
}
|
|
145
|
-
|
|
146
|
-
* Allowlist-filters the top-level keys of a client-supplied filter object.
|
|
147
|
-
* `$`-prefixed operator keys (e.g. $and, $or) always pass through.
|
|
148
|
-
* Matching is case-insensitive (via allowedLookup), and a matched key is
|
|
149
|
-
* rewritten to the casing originally declared in allowFields() — e.g.
|
|
150
|
-
* ?NAME=foo with allowFields(['name']) becomes { name: 'foo' }, not
|
|
151
|
-
* { NAME: 'foo' }, so it actually matches the schema path.
|
|
152
|
-
*/
|
|
153
|
-
function enforceAllowlist(filter, allowedLookup, allowedFields) {
|
|
168
|
+
function enforceAllowlist(filter, allowedLookup, canonicalMap) {
|
|
154
169
|
if (allowedLookup.size === 0)
|
|
155
170
|
return filter;
|
|
156
171
|
const out = {};
|
|
157
|
-
for (const
|
|
172
|
+
for (const k in filter) {
|
|
173
|
+
if (!Object.prototype.hasOwnProperty.call(filter, k))
|
|
174
|
+
continue;
|
|
158
175
|
if (k.startsWith('$')) {
|
|
159
|
-
out[k] =
|
|
176
|
+
out[k] = filter[k];
|
|
160
177
|
continue;
|
|
161
178
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
out[canonical] = v;
|
|
179
|
+
const lc = k.toLowerCase();
|
|
180
|
+
if (allowedLookup.has(lc)) {
|
|
181
|
+
out[canonicalMap.get(lc) ?? k] = filter[k];
|
|
166
182
|
}
|
|
167
183
|
}
|
|
168
184
|
return out;
|
|
169
185
|
}
|
|
170
|
-
// ───
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
!(value instanceof Date) &&
|
|
191
|
-
Object.getPrototypeOf(value) === Object.prototype) {
|
|
192
|
-
const out = {};
|
|
193
|
-
for (const [k, v] of Object.entries(value)) {
|
|
194
|
-
const newKey = COERCIBLE_OPS.has(k) ? `$${k}` : k;
|
|
195
|
-
out[newKey] = coerceOperatorKeys(v);
|
|
186
|
+
// ─── Fused coercion pass ──────────────────────────────────────────────────────
|
|
187
|
+
function coerceAll(value, parentKey = '') {
|
|
188
|
+
if (value === null)
|
|
189
|
+
return null;
|
|
190
|
+
if (typeof value === 'string') {
|
|
191
|
+
if (value === 'true')
|
|
192
|
+
return true;
|
|
193
|
+
if (value === 'false')
|
|
194
|
+
return false;
|
|
195
|
+
if (DATE_FIELD_RE.test(parentKey)) {
|
|
196
|
+
const parsed = new Date(value);
|
|
197
|
+
if (!isNaN(parsed.getTime())) {
|
|
198
|
+
if (PLAIN_DATE_RE.test(value)) {
|
|
199
|
+
const start = new Date(value);
|
|
200
|
+
const end = new Date(start);
|
|
201
|
+
end.setUTCDate(end.getUTCDate() + 1);
|
|
202
|
+
return { $gte: start, $lt: end };
|
|
203
|
+
}
|
|
204
|
+
return parsed;
|
|
205
|
+
}
|
|
196
206
|
}
|
|
197
|
-
return
|
|
207
|
+
return value;
|
|
198
208
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
// ─── Type coercion ────────────────────────────────────────────────────────────
|
|
202
|
-
/**
|
|
203
|
-
* Recursively coerces string 'true'/'false' to booleans at any nesting depth.
|
|
204
|
-
* Fixes the original shallow-only implementation.
|
|
205
|
-
*/
|
|
206
|
-
function coerceBooleans(value) {
|
|
207
|
-
if (value === 'true')
|
|
208
|
-
return true;
|
|
209
|
-
if (value === 'false')
|
|
210
|
-
return false;
|
|
209
|
+
if (typeof value !== 'object')
|
|
210
|
+
return value;
|
|
211
211
|
if (Array.isArray(value)) {
|
|
212
|
-
return value.map((item) =>
|
|
212
|
+
return value.map((item) => coerceAll(item, parentKey));
|
|
213
213
|
}
|
|
214
|
-
if (value
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
Object.getPrototypeOf(value) === Object.prototype) {
|
|
218
|
-
const out = {};
|
|
219
|
-
for (const [k, v] of Object.entries(value)) {
|
|
220
|
-
out[k] = coerceBooleans(v);
|
|
221
|
-
}
|
|
222
|
-
return out;
|
|
223
|
-
}
|
|
224
|
-
return value;
|
|
225
|
-
}
|
|
226
|
-
function coerceDates(obj, parentKey = '') {
|
|
214
|
+
if (value instanceof Date)
|
|
215
|
+
return value;
|
|
216
|
+
const src = value;
|
|
227
217
|
const out = {};
|
|
228
|
-
for (const
|
|
229
|
-
|
|
230
|
-
const path = isOp ? parentKey : parentKey ? `${parentKey}.${k}` : k;
|
|
231
|
-
if (v !== null &&
|
|
232
|
-
typeof v === 'object' &&
|
|
233
|
-
!Array.isArray(v) &&
|
|
234
|
-
!(v instanceof Date)) {
|
|
235
|
-
out[k] = coerceDates(v, path);
|
|
236
|
-
continue;
|
|
237
|
-
}
|
|
238
|
-
if (typeof v === 'string' && DATE_FIELD_RE.test(path)) {
|
|
239
|
-
const parsed = new Date(v);
|
|
240
|
-
if (isNaN(parsed.getTime())) {
|
|
241
|
-
// Leave unparseable strings as-is; Mongoose CastError → 400 upstream.
|
|
242
|
-
out[k] = v;
|
|
243
|
-
continue;
|
|
244
|
-
}
|
|
245
|
-
if (PLAIN_DATE_RE.test(v)) {
|
|
246
|
-
const start = new Date(v);
|
|
247
|
-
const end = new Date(start);
|
|
248
|
-
end.setUTCDate(end.getUTCDate() + 1);
|
|
249
|
-
out[k] = { $gte: start, $lt: end };
|
|
250
|
-
continue;
|
|
251
|
-
}
|
|
252
|
-
out[k] = parsed;
|
|
218
|
+
for (const k in src) {
|
|
219
|
+
if (!Object.prototype.hasOwnProperty.call(src, k))
|
|
253
220
|
continue;
|
|
254
|
-
}
|
|
255
|
-
|
|
221
|
+
const newKey = COERCIBLE_OPS.has(k) ? `$${k}` : k;
|
|
222
|
+
const isOp = k.startsWith('$') || COERCIBLE_OPS.has(k);
|
|
223
|
+
const childPath = isOp ? parentKey : parentKey ? `${parentKey}.${k}` : k;
|
|
224
|
+
out[newKey] = coerceAll(src[k], childPath);
|
|
256
225
|
}
|
|
257
226
|
return out;
|
|
258
227
|
}
|
|
259
228
|
// ─── Operator validation ──────────────────────────────────────────────────────
|
|
260
|
-
/**
|
|
261
|
-
* Recursively walks the entire filter tree and throws on:
|
|
262
|
-
* 1. Banned operators at any depth ($where, $expr, $function, etc.)
|
|
263
|
-
* 2. Unknown top-level $ operators (only $and/$or/$nor/$not allowed at root)
|
|
264
|
-
*
|
|
265
|
-
* Fixes the original shallow-only check.
|
|
266
|
-
*/
|
|
267
229
|
function rejectDisallowedOperators(filter, depth = 0) {
|
|
268
|
-
for (const
|
|
269
|
-
|
|
230
|
+
for (const k in filter) {
|
|
231
|
+
if (!Object.prototype.hasOwnProperty.call(filter, k))
|
|
232
|
+
continue;
|
|
270
233
|
if (BANNED_OPERATORS.has(k)) {
|
|
271
234
|
throw new QueryFindValidationError(`Disallowed operator in query: "${k}"`);
|
|
272
235
|
}
|
|
273
|
-
// Top-level unknown $ operators
|
|
274
236
|
if (depth === 0 && k.startsWith('$') && !ALLOWED_TOP_LEVEL_OPS.has(k)) {
|
|
275
237
|
throw new QueryFindValidationError(`Disallowed top-level operator in query string: "${k}"`);
|
|
276
238
|
}
|
|
277
|
-
|
|
239
|
+
const v = filter[k];
|
|
278
240
|
if (Array.isArray(v)) {
|
|
279
241
|
for (const item of v) {
|
|
280
242
|
if (item !== null &&
|
|
281
243
|
typeof item === 'object' &&
|
|
282
244
|
!Array.isArray(item) &&
|
|
283
|
-
!(item instanceof Date)
|
|
245
|
+
!(item instanceof Date) &&
|
|
246
|
+
Object.getPrototypeOf(item) === Object.prototype) {
|
|
284
247
|
rejectDisallowedOperators(item, depth + 1);
|
|
285
248
|
}
|
|
286
249
|
}
|
|
@@ -294,24 +257,21 @@ function rejectDisallowedOperators(filter, depth = 0) {
|
|
|
294
257
|
}
|
|
295
258
|
}
|
|
296
259
|
// ─── Filter builder ───────────────────────────────────────────────────────────
|
|
297
|
-
function buildFilter(raw, allowedLookup,
|
|
260
|
+
function buildFilter(raw, allowedLookup, canonicalMap, onDrop) {
|
|
298
261
|
const stripped = {};
|
|
299
|
-
for (const
|
|
300
|
-
if (!RESERVED_KEYS.has(k))
|
|
301
|
-
stripped[k] =
|
|
262
|
+
for (const k in raw) {
|
|
263
|
+
if (Object.prototype.hasOwnProperty.call(raw, k) && !RESERVED_KEYS.has(k)) {
|
|
264
|
+
stripped[k] = raw[k];
|
|
265
|
+
}
|
|
302
266
|
}
|
|
303
|
-
const safe = sanitize(stripped);
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
// (e.g. ?status=in, ?name=eq) are never touched.
|
|
307
|
-
const withOps = coerceOperatorKeys(safe);
|
|
308
|
-
const coerced = coerceDates(coerceBooleans(withOps));
|
|
309
|
-
const allowed = enforceAllowlist(coerced, allowedLookup, allowedFields);
|
|
267
|
+
const safe = sanitize(stripped, 0, '', onDrop);
|
|
268
|
+
const coerced = coerceAll(safe);
|
|
269
|
+
const allowed = enforceAllowlist(coerced, allowedLookup, canonicalMap);
|
|
310
270
|
rejectDisallowedOperators(allowed);
|
|
311
271
|
return allowed;
|
|
312
272
|
}
|
|
313
273
|
// ─── Sort parser ──────────────────────────────────────────────────────────────
|
|
314
|
-
function parseSort(sort, allowedLookup) {
|
|
274
|
+
function parseSort(sort, allowedLookup, canonicalMap) {
|
|
315
275
|
const out = {};
|
|
316
276
|
let count = 0;
|
|
317
277
|
for (const token of sort.split(',')) {
|
|
@@ -324,21 +284,20 @@ function parseSort(sort, allowedLookup) {
|
|
|
324
284
|
const field = desc ? trimmed.slice(1).trim() : trimmed;
|
|
325
285
|
if (!field)
|
|
326
286
|
continue;
|
|
327
|
-
if (allowedLookup.size > 0
|
|
328
|
-
|
|
329
|
-
|
|
287
|
+
if (allowedLookup.size > 0) {
|
|
288
|
+
if (!isFieldAllowed(field, allowedLookup))
|
|
289
|
+
continue;
|
|
290
|
+
const canonical = canonicalMap.get(field.toLowerCase()) ?? field;
|
|
291
|
+
out[canonical] = desc ? -1 : 1;
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
out[field] = desc ? -1 : 1;
|
|
295
|
+
}
|
|
330
296
|
count++;
|
|
331
297
|
}
|
|
332
298
|
return out;
|
|
333
299
|
}
|
|
334
300
|
// ─── Projection sanitizer ─────────────────────────────────────────────────────
|
|
335
|
-
/**
|
|
336
|
-
* Strips fields from a client-supplied projection that are not in the allowlist.
|
|
337
|
-
* Handles both inclusion ("name email") and exclusion ("-password -__v") syntax.
|
|
338
|
-
* Always permits _id and __v in exclusion projections.
|
|
339
|
-
* Allowlist matching is case-insensitive.
|
|
340
|
-
* When allowedFields is empty, returns the projection unchanged.
|
|
341
|
-
*/
|
|
342
301
|
function sanitizeProjection(projection, allowedLookup) {
|
|
343
302
|
if (allowedLookup.size === 0)
|
|
344
303
|
return projection;
|
|
@@ -370,30 +329,20 @@ function sanitizeProjection(projection, allowedLookup) {
|
|
|
370
329
|
* .populate('department', 'name')
|
|
371
330
|
* .paginate();
|
|
372
331
|
* ```
|
|
373
|
-
*
|
|
374
|
-
* Security notes:
|
|
375
|
-
* - `.allowFields()` before `.filter()` restricts which URL params reach Mongo.
|
|
376
|
-
* - Allowlist matching (filter/sort/projection) is case-insensitive — e.g.
|
|
377
|
-
* allowFields(['name']) also matches ?Name=, ?NAME=, etc. For `.filter()`,
|
|
378
|
-
* a matched field is also normalized back to the casing declared in
|
|
379
|
-
* allowFields() (e.g. ?NAME=foo -> { name: 'foo' }) so it matches the
|
|
380
|
-
* actual schema path.
|
|
381
|
-
* - `.where()` conditions are hard — URL cannot override them.
|
|
382
|
-
* - Unknown/banned $ operators throw QueryFindValidationError (checked recursively).
|
|
383
|
-
* - Nesting depth capped at 5; page size capped at 100; sort fields capped at 5.
|
|
384
|
-
* - Search terms are regex-escaped (ReDoS prevention) and length-capped at 200 chars.
|
|
385
|
-
* - ?fields= projection is allowlist-filtered to prevent sensitive field leakage.
|
|
386
|
-
* - Operator-key coercion (eq/gte/in/...) only touches object KEYS, never string
|
|
387
|
-
* VALUES — a search like ?name=eq or ?status=in cannot be corrupted into a
|
|
388
|
-
* Mongo operator.
|
|
389
|
-
* - All queries run with maxTimeMS to prevent runaway collection scans.
|
|
390
332
|
*/
|
|
391
333
|
class QueryFind {
|
|
392
334
|
constructor(query, queryString, options = {}) {
|
|
393
335
|
this._allowedFields = new Set();
|
|
394
|
-
/** Lowercase mirror of _allowedFields, used for case-insensitive matching. */
|
|
395
336
|
this._allowedLookup = new Set();
|
|
396
|
-
this.
|
|
337
|
+
this._canonicalMap = new Map();
|
|
338
|
+
// Fix #1: URL-derived filter and server-side conditions stored separately.
|
|
339
|
+
// Server conditions are merged last in paginate() and can never be
|
|
340
|
+
// overwritten by URL params regardless of call order.
|
|
341
|
+
this._urlFilter = {};
|
|
342
|
+
this._serverConditions = {};
|
|
343
|
+
// Fix #2: track search $or clauses separately so double-call extends rather
|
|
344
|
+
// than re-wraps.
|
|
345
|
+
this._searchOr = [];
|
|
397
346
|
this._sort = { ...DEFAULT_SORT };
|
|
398
347
|
this._select = null;
|
|
399
348
|
this._populates = [];
|
|
@@ -401,98 +350,84 @@ class QueryFind {
|
|
|
401
350
|
this.qs = Object.freeze({ ...queryString });
|
|
402
351
|
this.options = {
|
|
403
352
|
maxTimeMS: options.maxTimeMS ?? DEFAULT_MAX_TIME_MS,
|
|
353
|
+
slowQueryThresholdMS: options.slowQueryThresholdMS ??
|
|
354
|
+
options.maxTimeMS ??
|
|
355
|
+
DEFAULT_MAX_TIME_MS,
|
|
356
|
+
lean: options.lean ?? true,
|
|
357
|
+
onSlowQuery: options.onSlowQuery,
|
|
358
|
+
onSanitizeDrop: options.onSanitizeDrop,
|
|
404
359
|
};
|
|
360
|
+
// Fix #4: parse once, not on every paginate() call.
|
|
361
|
+
this._page = parsePage(this.qs.page);
|
|
362
|
+
this._limit = parseLimit(this.qs.limit);
|
|
405
363
|
}
|
|
406
364
|
// ── Configuration ───────────────────────────────────────────────────────────
|
|
407
|
-
|
|
408
|
-
* Declare which fields may appear in URL filters, sort, and projection.
|
|
409
|
-
* Matching against `?field=`, `?sort=`, and `?fields=` is case-insensitive,
|
|
410
|
-
* so `allowFields(['Name', 'Email'])` will also match `?name=`, `?NAME=`,
|
|
411
|
-
* `?eMail=`, etc.
|
|
412
|
-
* Call before `.filter()`, `.sort()`, and `.limitFields()`.
|
|
413
|
-
*/
|
|
365
|
+
// Fix #6: allowedStructures only rebuilt when this method is called.
|
|
414
366
|
allowFields(fields) {
|
|
415
367
|
this._allowedFields = new Set(fields);
|
|
416
|
-
|
|
368
|
+
const { lookup, canonical } = buildAllowedStructures(this._allowedFields);
|
|
369
|
+
this._allowedLookup = lookup;
|
|
370
|
+
this._canonicalMap = canonical;
|
|
417
371
|
return this;
|
|
418
372
|
}
|
|
419
373
|
// ── Builder methods ─────────────────────────────────────────────────────────
|
|
420
|
-
/** Parse URL query params into a Mongoose filter (respects allowlist). */
|
|
421
374
|
filter() {
|
|
422
|
-
const parsed = buildFilter(this.qs, this._allowedLookup, this.
|
|
423
|
-
Object.assign(this.
|
|
375
|
+
const parsed = buildFilter(this.qs, this._allowedLookup, this._canonicalMap, this.options.onSanitizeDrop);
|
|
376
|
+
Object.assign(this._urlFilter, parsed);
|
|
424
377
|
return this;
|
|
425
378
|
}
|
|
426
379
|
/**
|
|
427
380
|
* Apply mandatory server-side conditions the URL cannot override.
|
|
428
|
-
*
|
|
381
|
+
*
|
|
382
|
+
* Fix #1: conditions are stored in _serverConditions and merged into the
|
|
383
|
+
* final filter last, inside paginate(). This guarantees URL params (stored
|
|
384
|
+
* in _urlFilter) can never overwrite server-side values regardless of the
|
|
385
|
+
* order in which .where() and .filter() are called.
|
|
429
386
|
*
|
|
430
387
|
* @example .where({ orgId: req.user.orgId, deletedAt: null })
|
|
431
388
|
*/
|
|
432
389
|
where(conditions) {
|
|
433
|
-
|
|
390
|
+
const asRecord = conditions;
|
|
391
|
+
// Validate operators in server-supplied conditions.
|
|
392
|
+
// We don't sanitize here (Dates, ObjectIds etc. are legitimate server values),
|
|
393
|
+
// but we do reject banned $ operators in case user data leaked in.
|
|
394
|
+
rejectDisallowedOperators(asRecord);
|
|
395
|
+
Object.assign(this._serverConditions, asRecord);
|
|
434
396
|
return this;
|
|
435
397
|
}
|
|
436
398
|
/**
|
|
437
399
|
* Case-insensitive full-text search across `fields` when `?q=` is present.
|
|
438
|
-
*
|
|
439
|
-
*
|
|
400
|
+
*
|
|
401
|
+
* Fix #2: subsequent calls extend the $or clause list rather than re-wrapping
|
|
402
|
+
* the filter in nested $and, preventing double-wrapping and preserving index
|
|
403
|
+
* usage.
|
|
440
404
|
*/
|
|
441
405
|
globalSearch(fields) {
|
|
442
406
|
const raw = this.qs.q?.trim();
|
|
443
|
-
// Guard: missing, empty, or oversized search term
|
|
444
407
|
if (!raw || raw.length > MAX_SEARCH_LENGTH || fields.length === 0) {
|
|
445
408
|
return this;
|
|
446
409
|
}
|
|
410
|
+
const safeFields = this._allowedLookup.size > 0
|
|
411
|
+
? fields.filter((f) => isFieldAllowed(f, this._allowedLookup))
|
|
412
|
+
: fields;
|
|
413
|
+
if (safeFields.length === 0)
|
|
414
|
+
return this;
|
|
447
415
|
const escaped = raw.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
448
|
-
const
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
// present (top-level fields from .where()/.filter(), or existing
|
|
453
|
-
// $or/$and). This avoids the bug where a top-level field that
|
|
454
|
-
// happens to also be one of the `fields` passed here (e.g.
|
|
455
|
-
// ?status=active combined with .globalSearch(['status','name']))
|
|
456
|
-
// would sit alongside $or and be implicitly ANDed with it — making
|
|
457
|
-
// the search match only documents where `status` is BOTH exactly
|
|
458
|
-
// "active" AND matches the regex, silently excluding matches on
|
|
459
|
-
// `name`. Wrapping the existing filter as one branch of $and
|
|
460
|
-
// preserves all prior conditions intact while ORing across the
|
|
461
|
-
// search fields independently.
|
|
462
|
-
if (Object.keys(this._filter).length > 0) {
|
|
463
|
-
this._filter = {
|
|
464
|
-
$and: [this._filter, { $or: searchOr }],
|
|
465
|
-
};
|
|
466
|
-
}
|
|
467
|
-
else {
|
|
468
|
-
this._filter = { $or: searchOr };
|
|
416
|
+
const regex = new RegExp(escaped, 'i');
|
|
417
|
+
// Extend _searchOr; the $or clause is assembled once in paginate().
|
|
418
|
+
for (const field of safeFields) {
|
|
419
|
+
this._searchOr.push({ [field]: regex });
|
|
469
420
|
}
|
|
470
421
|
return this;
|
|
471
422
|
}
|
|
472
|
-
/**
|
|
473
|
-
* Apply sort from `?sort=`. Falls back to `{ createdAt: -1 }`.
|
|
474
|
-
* Fields not in the allowlist are silently skipped (case-insensitive match).
|
|
475
|
-
* Capped at MAX_SORT_FIELDS (5) fields.
|
|
476
|
-
*/
|
|
477
423
|
sort() {
|
|
478
424
|
if (this.qs.sort) {
|
|
479
|
-
const parsed = parseSort(this.qs.sort, this._allowedLookup);
|
|
425
|
+
const parsed = parseSort(this.qs.sort, this._allowedLookup, this._canonicalMap);
|
|
480
426
|
this._sort =
|
|
481
427
|
Object.keys(parsed).length > 0 ? parsed : { ...DEFAULT_SORT };
|
|
482
428
|
}
|
|
483
429
|
return this;
|
|
484
430
|
}
|
|
485
|
-
/**
|
|
486
|
-
* Configure field projection.
|
|
487
|
-
* Priority: `?fields=` query param > `defaultFields` argument > no projection.
|
|
488
|
-
*
|
|
489
|
-
* When `allowFields()` has been called, any field in `?fields=` that is not
|
|
490
|
-
* in the allowlist is stripped (case-insensitive match) — preventing clients
|
|
491
|
-
* from projecting sensitive fields like `password` or `resetToken`.
|
|
492
|
-
*
|
|
493
|
-
* @param defaultFields e.g. `'-password -__v'` — always excluded when the
|
|
494
|
-
* client does not supply `?fields=`.
|
|
495
|
-
*/
|
|
496
431
|
limitFields(defaultFields) {
|
|
497
432
|
if (this.qs.fields) {
|
|
498
433
|
const raw = this.qs.fields
|
|
@@ -508,7 +443,7 @@ class QueryFind {
|
|
|
508
443
|
return this;
|
|
509
444
|
}
|
|
510
445
|
/**
|
|
511
|
-
* Register a populate path.
|
|
446
|
+
* Register a populate path.
|
|
512
447
|
*
|
|
513
448
|
* @example
|
|
514
449
|
* .populate('author')
|
|
@@ -520,57 +455,121 @@ class QueryFind {
|
|
|
520
455
|
this._populates.push(select ? { path, select } : { path });
|
|
521
456
|
}
|
|
522
457
|
else {
|
|
523
|
-
|
|
458
|
+
if (path.match != null) {
|
|
459
|
+
const rawMatch = path.match;
|
|
460
|
+
const safeMatch = sanitize(rawMatch, 0, 'populate.match', this.options.onSanitizeDrop);
|
|
461
|
+
rejectDisallowedOperators(safeMatch);
|
|
462
|
+
this._populates.push({ ...path, match: safeMatch });
|
|
463
|
+
}
|
|
464
|
+
else {
|
|
465
|
+
this._populates.push(path);
|
|
466
|
+
}
|
|
524
467
|
}
|
|
525
468
|
return this;
|
|
526
469
|
}
|
|
470
|
+
// ── Private helpers ─────────────────────────────────────────────────────────
|
|
471
|
+
/**
|
|
472
|
+
* Fix #1: assemble the final filter by merging URL filter, search clause,
|
|
473
|
+
* and server conditions. Server conditions are applied last so they can
|
|
474
|
+
* never be overwritten by URL-derived values.
|
|
475
|
+
*
|
|
476
|
+
* Fix #2: _searchOr is assembled here once rather than incrementally
|
|
477
|
+
* mutating _filter during globalSearch() calls.
|
|
478
|
+
*/
|
|
479
|
+
buildFinalFilter() {
|
|
480
|
+
let base = { ...this._urlFilter };
|
|
481
|
+
if (this._searchOr.length > 0) {
|
|
482
|
+
if (Object.keys(base).length > 0) {
|
|
483
|
+
base = { $and: [base, { $or: this._searchOr }] };
|
|
484
|
+
}
|
|
485
|
+
else {
|
|
486
|
+
base = { $or: this._searchOr };
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
// Server conditions merged last — URL cannot override these.
|
|
490
|
+
return { ...base, ...this._serverConditions };
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Fix #7: execFind promoted to private method — no longer a closure
|
|
494
|
+
* recreated on every paginate() call.
|
|
495
|
+
*/
|
|
496
|
+
execFind(mongoFilter, skip) {
|
|
497
|
+
const { maxTimeMS, lean } = this.options;
|
|
498
|
+
const q = this.model
|
|
499
|
+
.find(mongoFilter)
|
|
500
|
+
.sort(this._sort)
|
|
501
|
+
.skip(skip)
|
|
502
|
+
.limit(this._limit);
|
|
503
|
+
// Fix #9: lean() is opt-out, not hardcoded.
|
|
504
|
+
if (lean)
|
|
505
|
+
q.lean();
|
|
506
|
+
if (this._select)
|
|
507
|
+
q.select(this._select);
|
|
508
|
+
for (const opt of this._populates)
|
|
509
|
+
q.populate(opt);
|
|
510
|
+
if (maxTimeMS > 0)
|
|
511
|
+
q.maxTimeMS(maxTimeMS);
|
|
512
|
+
return q.exec();
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Fix #7: execCount promoted to private method.
|
|
516
|
+
* Calls .exec() directly — avoids the Model<unknown> generic mismatch that
|
|
517
|
+
* broke the earlier execCountQuery helper approach.
|
|
518
|
+
*/
|
|
519
|
+
async execCount(mongoFilter, hasFilter) {
|
|
520
|
+
const { maxTimeMS } = this.options;
|
|
521
|
+
if (!hasFilter) {
|
|
522
|
+
return (await this.model
|
|
523
|
+
.estimatedDocumentCount()
|
|
524
|
+
.maxTimeMS(maxTimeMS)
|
|
525
|
+
.exec());
|
|
526
|
+
}
|
|
527
|
+
return (await this.model
|
|
528
|
+
.countDocuments(mongoFilter)
|
|
529
|
+
.maxTimeMS(maxTimeMS)
|
|
530
|
+
.exec());
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Fix #3 + Fix #7: wrapTimed promoted to a private method that accepts an
|
|
534
|
+
* explicit start time so the slow-query clock can be started before
|
|
535
|
+
* execCount() on page > 1 paths, covering the full round-trip.
|
|
536
|
+
*/
|
|
537
|
+
async wrapTimed(fn, page, limit, filter) {
|
|
538
|
+
const { onSlowQuery, slowQueryThresholdMS, maxTimeMS } = this.options;
|
|
539
|
+
if (!onSlowQuery)
|
|
540
|
+
return fn();
|
|
541
|
+
const start = Date.now();
|
|
542
|
+
const result = await fn();
|
|
543
|
+
const elapsedMs = Date.now() - start;
|
|
544
|
+
if (elapsedMs >= (slowQueryThresholdMS ?? maxTimeMS)) {
|
|
545
|
+
onSlowQuery({ elapsedMs, filter, sort: this._sort, page, limit });
|
|
546
|
+
}
|
|
547
|
+
return result;
|
|
548
|
+
}
|
|
527
549
|
// ── Terminal ────────────────────────────────────────────────────────────────
|
|
528
550
|
/**
|
|
529
551
|
* Execute and return a paginated result.
|
|
530
552
|
*
|
|
531
|
-
*
|
|
532
|
-
*
|
|
533
|
-
* - .lean() returns plain objects (~3-5× faster for read-only responses).
|
|
534
|
-
* - maxTimeMS applied to both count and find (prevents runaway scans).
|
|
535
|
-
* - page is clamped to 1 if it exceeds totalPages (safe mid-delete behavior).
|
|
536
|
-
*
|
|
553
|
+
* @param cachedTotal - Previously fetched total (from a page-1 response).
|
|
554
|
+
* When provided on page > 1, the count query is skipped entirely.
|
|
537
555
|
* @throws {QueryFindValidationError} on disallowed $ operators in the URL.
|
|
538
556
|
*/
|
|
539
|
-
async paginate() {
|
|
540
|
-
const page =
|
|
541
|
-
const limit =
|
|
542
|
-
|
|
543
|
-
const
|
|
544
|
-
const
|
|
545
|
-
const
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
.
|
|
550
|
-
.
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
q.select(this._select);
|
|
554
|
-
for (const opt of this._populates)
|
|
555
|
-
q.populate(opt);
|
|
556
|
-
if (maxTimeMS > 0)
|
|
557
|
-
q.maxTimeMS(maxTimeMS);
|
|
558
|
-
return q.exec();
|
|
559
|
-
};
|
|
560
|
-
const countQuery = hasFilter
|
|
561
|
-
? this.model
|
|
562
|
-
.countDocuments(mongoFilter)
|
|
563
|
-
.maxTimeMS(maxTimeMS)
|
|
564
|
-
: this.model.estimatedDocumentCount();
|
|
565
|
-
const [total, firstPageData] = await Promise.all([
|
|
566
|
-
countQuery,
|
|
567
|
-
buildFind(0),
|
|
568
|
-
]);
|
|
569
|
-
const totalPages = Math.max(Math.ceil(total / limit), 1);
|
|
570
|
-
const safePage = page > totalPages ? 1 : page;
|
|
571
|
-
if (safePage === 1) {
|
|
557
|
+
async paginate(cachedTotal) {
|
|
558
|
+
const page = this._page;
|
|
559
|
+
const limit = this._limit;
|
|
560
|
+
// Fix #1: final filter assembled here — server conditions always win.
|
|
561
|
+
const finalFilter = this.buildFinalFilter();
|
|
562
|
+
const mongoFilter = finalFilter;
|
|
563
|
+
const hasFilter = Object.keys(finalFilter).length > 0;
|
|
564
|
+
// ── Page 1: count + find in parallel ─────────────────────────────────────
|
|
565
|
+
if (page === 1) {
|
|
566
|
+
const [total, data] = await this.wrapTimed(() => Promise.all([
|
|
567
|
+
this.execCount(mongoFilter, hasFilter),
|
|
568
|
+
this.execFind(mongoFilter, 0),
|
|
569
|
+
]), page, limit, finalFilter);
|
|
570
|
+
const totalPages = Math.max(Math.ceil(total / limit), 1);
|
|
572
571
|
return {
|
|
573
|
-
data
|
|
572
|
+
data,
|
|
574
573
|
total,
|
|
575
574
|
page: 1,
|
|
576
575
|
totalPages,
|
|
@@ -579,15 +578,49 @@ class QueryFind {
|
|
|
579
578
|
hasPrevPage: false,
|
|
580
579
|
};
|
|
581
580
|
}
|
|
582
|
-
|
|
581
|
+
// ── Page > 1 with cached total: skip count ────────────────────────────────
|
|
582
|
+
if (cachedTotal !== undefined) {
|
|
583
|
+
const totalPages = Math.max(Math.ceil(cachedTotal / limit), 1);
|
|
584
|
+
const safePage = page > totalPages ? 1 : page;
|
|
585
|
+
const data = await this.wrapTimed(() => this.execFind(mongoFilter, (safePage - 1) * limit), safePage, limit, finalFilter);
|
|
586
|
+
return {
|
|
587
|
+
data,
|
|
588
|
+
total: cachedTotal,
|
|
589
|
+
page: safePage,
|
|
590
|
+
totalPages,
|
|
591
|
+
limit,
|
|
592
|
+
hasNextPage: safePage < totalPages,
|
|
593
|
+
hasPrevPage: safePage > 1,
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
// ── Page > 1 without cached total: count + find, both timed ──────────────
|
|
597
|
+
//
|
|
598
|
+
// Fix #3: the entire block (count + find) is wrapped in wrapTimed so slow
|
|
599
|
+
// counts on subsequent pages are visible to onSlowQuery. Previously only
|
|
600
|
+
// execFind was timed on this path.
|
|
601
|
+
//
|
|
602
|
+
// We break out of the generic wrapTimed by collecting the result into a
|
|
603
|
+
// side-channel object that is mutated inside the timed closure. This avoids
|
|
604
|
+
// the tuple-inside-R TypeScript inference problem entirely.
|
|
605
|
+
const result = { total: 0, data: [], safePage: page, totalPages: 1 };
|
|
606
|
+
await this.wrapTimed(async () => {
|
|
607
|
+
const total = await this.execCount(mongoFilter, hasFilter);
|
|
608
|
+
const totalPages = Math.max(Math.ceil(total / limit), 1);
|
|
609
|
+
const safePage = page > totalPages ? 1 : page;
|
|
610
|
+
const data = await this.execFind(mongoFilter, (safePage - 1) * limit);
|
|
611
|
+
result.total = total;
|
|
612
|
+
result.data = data;
|
|
613
|
+
result.safePage = safePage;
|
|
614
|
+
result.totalPages = totalPages;
|
|
615
|
+
}, page, limit, finalFilter);
|
|
583
616
|
return {
|
|
584
|
-
data,
|
|
585
|
-
total,
|
|
586
|
-
page: safePage,
|
|
587
|
-
totalPages,
|
|
617
|
+
data: result.data,
|
|
618
|
+
total: result.total,
|
|
619
|
+
page: result.safePage,
|
|
620
|
+
totalPages: result.totalPages,
|
|
588
621
|
limit,
|
|
589
|
-
hasNextPage: safePage < totalPages,
|
|
590
|
-
hasPrevPage: safePage > 1,
|
|
622
|
+
hasNextPage: result.safePage < result.totalPages,
|
|
623
|
+
hasPrevPage: result.safePage > 1,
|
|
591
624
|
};
|
|
592
625
|
}
|
|
593
626
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
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