@rapidrest/service-core 1.7.2 → 2.0.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/lib/ApiErrors.js +10 -0
- package/dist/lib/ApiErrors.js.map +1 -1
- package/dist/lib/RateLimiter.js +9 -7
- package/dist/lib/RateLimiter.js.map +1 -1
- package/dist/lib/database/TypeOrmSupport.js +45 -0
- package/dist/lib/database/TypeOrmSupport.js.map +1 -1
- package/dist/lib/decorators/RouteDecorators.js +6 -6
- package/dist/lib/decorators/RouteDecorators.js.map +1 -1
- package/dist/lib/models/ModelUtils.js +728 -219
- package/dist/lib/models/ModelUtils.js.map +1 -1
- package/dist/lib/routes/RouteUtils.js +8 -5
- package/dist/lib/routes/RouteUtils.js.map +1 -1
- package/dist/types/ApiErrors.d.ts +10 -0
- package/dist/types/RateLimiter.d.ts +19 -8
- package/dist/types/decorators/RouteDecorators.d.ts +9 -4
- package/dist/types/models/ModelUtils.d.ts +206 -47
- package/dist/types/routes/RouteUtils.d.ts +3 -3
- package/package.json +1 -1
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
import type { Repository } from "typeorm";
|
|
2
2
|
import { MongoRepository } from "../database/MongoRepository.js";
|
|
3
3
|
import "reflect-metadata";
|
|
4
|
+
/** Default number of records returned by a search query when no `limit` is specified. Shared by both backends. */
|
|
5
|
+
export declare const DEFAULT_PAGE_SIZE = 100;
|
|
6
|
+
/** Maximum number of records a search query may request via `limit`, regardless of provider. Shared by both backends. */
|
|
7
|
+
export declare const MAX_PAGE_SIZE = 1000;
|
|
8
|
+
/**
|
|
9
|
+
* A single field comparison leaf in a search query AST (see `QueryNode`). `value` may be a raw string (in which
|
|
10
|
+
* case it is coerced the same way an `op(value)` query-parameter operand is - including `me` substitution and
|
|
11
|
+
* declared-type validation) or an already-typed JS value (used as-is, after an operator-injection check).
|
|
12
|
+
*/
|
|
13
|
+
export interface PredicateNode {
|
|
14
|
+
kind: "predicate";
|
|
15
|
+
field: string;
|
|
16
|
+
op: "eq" | "ne" | "gt" | "gte" | "lt" | "lte" | "in" | "nin" | "range" | "like" | "regex" | "exists";
|
|
17
|
+
value: unknown;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A boolean grouping node in a search query AST: combines child nodes with `and`/`or`, optionally negated.
|
|
21
|
+
* Negation is supported when compiling to MongoDB (via `$nor`) but not against the SQL `find()`-based `where`
|
|
22
|
+
* (see `buildQueryFromNode`).
|
|
23
|
+
*/
|
|
24
|
+
export interface GroupNode {
|
|
25
|
+
kind: "group";
|
|
26
|
+
op: "and" | "or";
|
|
27
|
+
negated?: boolean;
|
|
28
|
+
children: QueryNode[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A tree-shaped search query, for boolean nesting the flat `op(value)` query-parameter form cannot express (e.g.
|
|
32
|
+
* `(a AND b) OR (c AND d)`). See `ModelUtils.buildQueryFromNode`.
|
|
33
|
+
*/
|
|
34
|
+
export type QueryNode = GroupNode | PredicateNode;
|
|
4
35
|
/**
|
|
5
36
|
* Utility class for working with data model classes.
|
|
6
37
|
*
|
|
@@ -11,6 +42,7 @@ export declare class ModelUtils {
|
|
|
11
42
|
private static typeOrm;
|
|
12
43
|
private static idPropertyCache;
|
|
13
44
|
private static readOnlyPropertyCache;
|
|
45
|
+
private static columnTypeCache;
|
|
14
46
|
/**
|
|
15
47
|
* Provides the `typeorm` module to use when building SQL queries. This is called automatically when a SQL
|
|
16
48
|
* datasource connection is established.
|
|
@@ -36,6 +68,19 @@ export declare class ModelUtils {
|
|
|
36
68
|
* @returns The list of all property names that have the @ReadOnly decorator applied.
|
|
37
69
|
*/
|
|
38
70
|
static getReadOnlyPropertyNames(modelClass: any): string[];
|
|
71
|
+
/**
|
|
72
|
+
* Resolves the declared type of a model property, from an explicit `type` override on `@Column` or (falling
|
|
73
|
+
* back) the TypeScript design-time type reflected at decoration time. Returns `undefined` when `modelClass`
|
|
74
|
+
* is not provided or declares no column metadata for `property` - callers must fall back to a heuristic in
|
|
75
|
+
* that case, the same way `coerceOperand` does.
|
|
76
|
+
*/
|
|
77
|
+
private static resolvePropertyType;
|
|
78
|
+
/**
|
|
79
|
+
* Returns the set of property names a `sort` query parameter may reference for `modelClass`, or `undefined`
|
|
80
|
+
* if `modelClass` declares no column metadata at all - in which case sort keys are accepted unvalidated
|
|
81
|
+
* (the same permissive fallback `coerceOperand` uses when no type metadata is available).
|
|
82
|
+
*/
|
|
83
|
+
private static getSortablePropertyNames;
|
|
39
84
|
/**
|
|
40
85
|
* Builds a query object for use with `find` functions of the given repository for retrieving objects matching the
|
|
41
86
|
* specified unique identifier.
|
|
@@ -74,45 +119,125 @@ export declare class ModelUtils {
|
|
|
74
119
|
*/
|
|
75
120
|
static buildIdSearchQueryMongo(modelClass: any, id: any | any[], version?: number, includeDeleted?: boolean): any;
|
|
76
121
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
122
|
+
* Resolves a raw, single-value operand (already unwrapped from any `op(...)` syntax) to a properly-typed
|
|
123
|
+
* native value: `me` is substituted for the requesting user's uid, and the result is otherwise coerced
|
|
124
|
+
* according to `property`'s declared type on `modelClass` (falling back to a JSON/Date/string heuristic when
|
|
125
|
+
* no column metadata is available for it). Used for every scalar operand on both backends - including each
|
|
126
|
+
* element of `in()`/`nin()`/`range()` - so type coercion, `me` substitution and operator-injection rejection
|
|
127
|
+
* are applied uniformly everywhere a client-supplied value enters a query, on both backends.
|
|
81
128
|
*
|
|
82
|
-
* @
|
|
129
|
+
* @throws {ApiError} If `raw` is `me` with no authenticated user, if a typed column rejects an unparseable
|
|
130
|
+
* operand, or if the coerced value contains a hidden MongoDB operator/dotted key.
|
|
83
131
|
*/
|
|
84
|
-
private static
|
|
132
|
+
private static coerceOperand;
|
|
133
|
+
/**
|
|
134
|
+
* Coerces a raw operand string to `type` (an explicit `@Column({type})` override or a reflected TypeScript
|
|
135
|
+
* design type), rejecting operands that don't parse as that type rather than silently guessing.
|
|
136
|
+
*/
|
|
137
|
+
private static coerceToType;
|
|
138
|
+
private static invalidOperandError;
|
|
139
|
+
/**
|
|
140
|
+
* Coerces an already-typed AST predicate value (see `QueryNode`): a string operand is routed through
|
|
141
|
+
* `coerceOperand` (type coercion, `me` substitution, injection guard) exactly like the flat `op(value)`
|
|
142
|
+
* form; any other value is assumed to already be correctly typed by the caller and is only checked for a
|
|
143
|
+
* hidden operator/dotted key.
|
|
144
|
+
*/
|
|
145
|
+
private static coerceNodeValue;
|
|
85
146
|
/**
|
|
86
147
|
* Recursively verifies that no key in the given value (at any depth, including keys of objects nested inside
|
|
87
148
|
* arrays) is a MongoDB operator (starts with `$`) or uses dot-notation field addressing (contains `.`). Client
|
|
88
149
|
* input is only ever meant to supply plain field values/comparison operands — never raw Mongo query operators —
|
|
89
150
|
* so any such key indicates an attempt to inject arbitrary query behavior (e.g. `$where`, `$expr`, or reaching
|
|
90
|
-
* into a field the API doesn't expose via dot-notation).
|
|
151
|
+
* into a field the API doesn't expose via dot-notation). Applied to every coerced operand on both backends -
|
|
152
|
+
* `Equal(JSON.parse(param))`-style SQL operators are constructed by TypeORM rather than interpreted from the
|
|
153
|
+
* operand directly, but a client-supplied object operand should still be rejected consistently on both
|
|
154
|
+
* backends rather than left to whatever TypeORM happens to do with it.
|
|
91
155
|
*
|
|
92
156
|
* @param value The value to check, typically a parsed query parameter.
|
|
93
157
|
* @throws {ApiError} If an operator-like or dotted key is found anywhere in `value`.
|
|
94
158
|
*/
|
|
95
159
|
private static assertNoOperatorInjection;
|
|
96
|
-
/** Maximum accepted length of a client-supplied `like()` search pattern. */
|
|
97
|
-
private static readonly
|
|
160
|
+
/** Maximum accepted length of a client-supplied `like()`/`regex()` search pattern. */
|
|
161
|
+
private static readonly MAX_PATTERN_LENGTH;
|
|
162
|
+
/**
|
|
163
|
+
* Best-effort check for regex patterns vulnerable to catastrophic backtracking (ReDoS): patterns that are
|
|
164
|
+
* unreasonably long, that contain a quantified group whose contents are themselves quantified (e.g. `(a+)+`,
|
|
165
|
+
* `(a*)*`), or a quantified group containing alternation (e.g. `(a|a)*`, `(a|ab)*`) - both classic shapes
|
|
166
|
+
* that cause exponential backtracking in JS's (and SQLite's, since the `regex()` SQL operator is backed by a
|
|
167
|
+
* JS `RegExp` - see `registerRegexpFunction` in `TypeOrmSupport.ts`) regex engine. This is not an exhaustive
|
|
168
|
+
* defense; it catches the common cases a client would realistically send. `like()` no longer accepts raw
|
|
169
|
+
* regex (it compiles glob syntax instead - see `globToRegExpSource`), so this now guards only the explicit
|
|
170
|
+
* `regex()` operator.
|
|
171
|
+
*
|
|
172
|
+
* Public so the SQLite `REGEXP` custom function (registered per-connection in `TypeOrmSupport.ts`) can apply
|
|
173
|
+
* the same guard at query-execution time, since a pattern reaching that function didn't necessarily pass
|
|
174
|
+
* through this class's own query builders (e.g. a raw `Raw()`/QueryBuilder use elsewhere).
|
|
175
|
+
*/
|
|
176
|
+
static isUnsafeRegexPattern(pattern: string): boolean;
|
|
177
|
+
/**
|
|
178
|
+
* Translates a client-supplied glob pattern (`*` = any sequence, `?` = any single character) to a SQL
|
|
179
|
+
* `LIKE` pattern. Any `%`/`_` already present in the glob source is passed through unescaped (matching this
|
|
180
|
+
* operator's pre-existing behavior before glob support was added) - a client wanting to match a literal `%`
|
|
181
|
+
* or `_` cannot fully escape it, a narrow, documented limitation rather than a regression.
|
|
182
|
+
*/
|
|
183
|
+
private static globToLike;
|
|
98
184
|
/**
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
|
|
102
|
-
|
|
185
|
+
* Translates a client-supplied glob pattern into a fully-escaped, anchored regular expression source string
|
|
186
|
+
* for use with MongoDB's `$regex`, so glob syntax behaves identically on both backends.
|
|
187
|
+
*/
|
|
188
|
+
private static globToRegExpSource;
|
|
189
|
+
/**
|
|
190
|
+
* Compiles a validated `regex()` pattern to a driver-appropriate case-insensitive match expression. Only
|
|
191
|
+
* PostgreSQL (`~*`), MySQL/MariaDB (`REGEXP`) and the `better-sqlite3` driver (via a `REGEXP` function
|
|
192
|
+
* registered per-connection - see `registerRegexpFunction` in `TypeOrmSupport.ts`) are supported; any other
|
|
193
|
+
* driver rejects the operator outright rather than silently falling back to something incorrect.
|
|
194
|
+
*/
|
|
195
|
+
private static compileSqlRegex;
|
|
196
|
+
/**
|
|
197
|
+
* Given a string containing a parameter value and/or a comparison operation return a TypeORM compatible find value.
|
|
198
|
+
* e.g.
|
|
199
|
+
* Given the string "myvalue" will return an Eq("myvalue") object.
|
|
200
|
+
* Given the string "Like(myvalue)" will return an Like("myvalue") object.
|
|
103
201
|
*
|
|
104
|
-
* @param
|
|
202
|
+
* @param param
|
|
105
203
|
*/
|
|
106
|
-
private static
|
|
204
|
+
private static getQueryParamValue;
|
|
107
205
|
/**
|
|
108
206
|
* Given a string containing a parameter value and/or a comparison operation return a MongoDB compatible find value.
|
|
109
207
|
* e.g.
|
|
110
208
|
* Given the string "myvalue" will return an `"myvalue"` object.
|
|
111
|
-
* Given the string "not(myvalue)" will return an `{ $
|
|
209
|
+
* Given the string "not(myvalue)" will return an `{ $ne: "myvalue" }` object.
|
|
112
210
|
*
|
|
113
211
|
* @param param
|
|
114
212
|
*/
|
|
115
213
|
private static getQueryParamValueMongo;
|
|
214
|
+
/**
|
|
215
|
+
* Extracts the `$match` stage from either shape `buildSearchQueryMongo` can return (a pipeline array or a
|
|
216
|
+
* flattened `{$match, $sort}` object).
|
|
217
|
+
*/
|
|
218
|
+
private static extractMatch;
|
|
219
|
+
/**
|
|
220
|
+
* Normalizes the return value of `buildSearchQueryMongo` to a single shape: a full aggregation pipeline.
|
|
221
|
+
* `buildSearchQueryMongo` itself still returns either a pipeline array or a flattened `{$match, $sort}`
|
|
222
|
+
* object depending on how many stages it produced (existing callers, e.g. `RepoUtils`, already branch on
|
|
223
|
+
* `Array.isArray()` to handle both) - use this instead at any new call site that wants one consistent shape.
|
|
224
|
+
*/
|
|
225
|
+
static toFindQuery(pipelineOrObject: any): any[];
|
|
226
|
+
/**
|
|
227
|
+
* Resolves the `limit`/`page` reserved query parameters to a bounded `take`/`skip` pair, applying the same
|
|
228
|
+
* default (`DEFAULT_PAGE_SIZE`) and ceiling (`MAX_PAGE_SIZE`) that `buildSearchQuerySQL` already bakes into
|
|
229
|
+
* its own return value (as `take`/`page`). `buildSearchQueryMongo` does NOT bake pagination into its own
|
|
230
|
+
* pipeline - doing so would execute as `$skip`/`$limit` aggregation stages, which would double up with (and
|
|
231
|
+
* corrupt) any cursor-level `.skip()/.limit()` a caller applies on top, as `RepoUtils` already does for its
|
|
232
|
+
* own route-level pagination. A caller building a Mongo query directly - rather than going through
|
|
233
|
+
* `RepoUtils` - should call this explicitly to get the same bounded pagination the SQL path enforces
|
|
234
|
+
* automatically, rather than an unbounded result set.
|
|
235
|
+
*/
|
|
236
|
+
static resolvePagination(query?: any): {
|
|
237
|
+
take: number;
|
|
238
|
+
page: number;
|
|
239
|
+
skip: number;
|
|
240
|
+
};
|
|
116
241
|
/**
|
|
117
242
|
* Builds a query object for the given criteria and repository. Query params can have a value containing a
|
|
118
243
|
* conditional operator to apply for the search. The operator is encoded with the format `op(value)`. The following
|
|
@@ -121,13 +246,22 @@ export declare class ModelUtils {
|
|
|
121
246
|
* * `gt` - Returns matches whose parameter is greater than the given value. e.g. `param > value`
|
|
122
247
|
* * `gte` - Returns matches whose parameter is greater than or equal to the given value. e.g. `param >= value`
|
|
123
248
|
* * `in` - Returns matches whose parameter includes one of the given values. e.g. `param in ('value1', 'value2', 'value3', ...)`
|
|
124
|
-
* * `like` - Returns matches whose parameter
|
|
249
|
+
* * `like` - Returns matches whose parameter matches the given glob pattern (`*` = any sequence, `?` = any single character), case-insensitively. e.g. `like(*.txt)`
|
|
250
|
+
* * `regex` - Returns matches whose parameter matches the given regular expression, case-insensitively.
|
|
125
251
|
* * `lt` - Returns matches whose parameter is less than the given value. e.g. `param < value`
|
|
126
252
|
* * `lte` - Returns matches whose parameter is less than or equal to than the given value. e.g. `param < value`
|
|
127
|
-
* * `not` - Returns matches whose parameter is not equal to the given value. e.g. `param
|
|
253
|
+
* * `not` / `ne` - Returns matches whose parameter is not equal to the given value. e.g. `param != value`
|
|
128
254
|
* * `range` - Returns matches whose parameter is greater than or equal to first given value and less than or equal to the second. e.g. `param between(1,100)`
|
|
255
|
+
* * `exists` - Returns matches whose parameter is (`exists(true)`) or is not (`exists(false)`) set.
|
|
129
256
|
*
|
|
130
|
-
* When no operator is provided the comparison
|
|
257
|
+
* When no operator is provided the comparison is evaluated as `eq`, unless `exactMatch` is `false`, in which
|
|
258
|
+
* case a string-valued parameter is instead matched as a case-insensitive "contains" search.
|
|
259
|
+
*
|
|
260
|
+
* A repeated query parameter name (e.g. `?a=1&a=2`) OR-combines its values, "zipped" positionally against
|
|
261
|
+
* every other repeated parameter rather than as a cartesian product: `?a=1&a=2&b=3&b=4` compiles to
|
|
262
|
+
* `(a=1 AND b=3) OR (a=2 AND b=4)`, not `a IN (1,2)` and not all four combinations. A shorter array is padded
|
|
263
|
+
* by repeating its own last value against the longer one(s), rather than leaving the key unset for the extra
|
|
264
|
+
* branches (which would match ANY value there, silently dropping that filter).
|
|
131
265
|
*
|
|
132
266
|
* NOTE: The result of this function is only compatible with the `aggregate()` function when MongoDB is used.
|
|
133
267
|
*
|
|
@@ -140,43 +274,35 @@ export declare class ModelUtils {
|
|
|
140
274
|
*/
|
|
141
275
|
static buildSearchQuery<T extends {}>(modelClass: any, repo: Repository<T> | MongoRepository<T> | undefined, query?: any, exactMatch?: boolean, user?: any): any;
|
|
142
276
|
/**
|
|
143
|
-
* Builds a TypeORM compatible query object for the given criteria.
|
|
144
|
-
*
|
|
145
|
-
* operators are supported:
|
|
146
|
-
* * `eq` - Returns matches whose parameter exactly matches of the given value. e.g. `param = value`
|
|
147
|
-
* * `gt` - Returns matches whose parameter is greater than the given value. e.g. `param > value`
|
|
148
|
-
* * `gte` - Returns matches whose parameter is greater than or equal to the given value. e.g. `param >= value`
|
|
149
|
-
* * `in` - Returns matches whose parameter includes one of the given values. e.g. `param in ('value1', 'value2', 'value3', ...)`
|
|
150
|
-
* * `like` - Returns matches whose parameter is lexographically similar to the given value. `param like value`
|
|
151
|
-
* * `lt` - Returns matches whose parameter is less than the given value. e.g. `param < value`
|
|
152
|
-
* * `lte` - Returns matches whose parameter is less than or equal to than the given value. e.g. `param < value`
|
|
153
|
-
* * `not` - Returns matches whose parameter is not equal to the given value. e.g. `param not value`
|
|
154
|
-
* * `range` - Returns matches whose parameter is greater than or equal to first given value and less than or equal to the second. e.g. `param between(1,100)`
|
|
277
|
+
* Builds a TypeORM compatible query object for the given criteria. See `buildSearchQuery` for the supported
|
|
278
|
+
* `op(value)` operators and multi-value "zip" semantics.
|
|
155
279
|
*
|
|
156
|
-
*
|
|
280
|
+
* Unlike `buildSearchQuery` (which always injects a `deleted: false` filter for a `RecoverableBaseEntity`
|
|
281
|
+
* before delegating here), this function applies no soft-delete filtering of its own - a caller invoking it
|
|
282
|
+
* directly, bypassing `buildSearchQuery`, will not get that default exclusion.
|
|
157
283
|
*
|
|
158
284
|
* @param modelClass The class definition of the data model to build a search query for.
|
|
159
285
|
* @param {any} query The search query parameters to include.
|
|
160
286
|
* @param {bool} exactMatch Set to true to create a query where parameters are to be matched exactly, otherwise set to false to use a 'contains' search.
|
|
161
287
|
* @param {any} user The user that is performing the request.
|
|
288
|
+
* @param {string} driverType The TypeORM driver type (`connection.options.type`) of the target datasource, used
|
|
289
|
+
* to select a compatible SQL translation for the `regex()` operator. Only needed when `regex()` may appear in
|
|
290
|
+
* `query`.
|
|
291
|
+
* @param {number} depth Internal recursion-depth counter for nested `$or` groups - do not pass explicitly.
|
|
162
292
|
* @returns {object} The TypeORM compatible query object.
|
|
163
293
|
*/
|
|
164
|
-
static buildSearchQuerySQL(modelClass: any, query?: any, exactMatch?: boolean, user?: any): any;
|
|
294
|
+
static buildSearchQuerySQL(modelClass: any, query?: any, exactMatch?: boolean, user?: any, driverType?: string, depth?: number): any;
|
|
165
295
|
/**
|
|
166
|
-
* Builds a MongoDB compatible query object for the given criteria.
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
* * `in` - Returns matches whose parameter includes one of the given values. e.g. `param in ('value1', 'value2', 'value3', ...)`
|
|
173
|
-
* * `like` - Returns matches whose parameter is lexographically similar to the given value. `param like value`
|
|
174
|
-
* * `lt` - Returns matches whose parameter is less than the given value. e.g. `param < value`
|
|
175
|
-
* * `lte` - Returns matches whose parameter is less than or equal to than the given value. e.g. `param < value`
|
|
176
|
-
* * `not` - Returns matches whose parameter is not equal to the given value. e.g. `param not value`
|
|
177
|
-
* * `range` - Returns matches whose parameter is greater than or equal to first given value and less than or equal to the second. e.g. `param between(1,100)`
|
|
296
|
+
* Builds a MongoDB compatible query object for the given criteria. See `buildSearchQuery` for the supported
|
|
297
|
+
* `op(value)` operators and multi-value "zip" semantics.
|
|
298
|
+
*
|
|
299
|
+
* Unlike `buildSearchQuery` (which always injects a `deleted: false` filter for a `RecoverableBaseEntity`
|
|
300
|
+
* before delegating here), this function applies no soft-delete filtering of its own - a caller invoking it
|
|
301
|
+
* directly, bypassing `buildSearchQuery`, will not get that default exclusion.
|
|
178
302
|
*
|
|
179
|
-
*
|
|
303
|
+
* Does NOT bound `limit`/`page` into the returned pipeline (see `resolvePagination`) and returns either an
|
|
304
|
+
* aggregation pipeline array or a flattened `{$match, $sort}` object depending on how many stages it
|
|
305
|
+
* produced (see `toFindQuery` to normalize to one shape).
|
|
180
306
|
*
|
|
181
307
|
* NOTE: The result of this function is only compatible with the `aggregate()` function.
|
|
182
308
|
*
|
|
@@ -184,9 +310,42 @@ export declare class ModelUtils {
|
|
|
184
310
|
* @param {any} query The search query parameters to include.
|
|
185
311
|
* @param {bool} exactMatch Set to true to create a query where parameters are to be matched exactly, otherwise set to false to use a 'contains' search.
|
|
186
312
|
* @param {any} user The user that is performing the request.
|
|
313
|
+
* @param {number} depth Internal recursion-depth counter for nested `$or` groups - do not pass explicitly.
|
|
187
314
|
* @returns {object} The MongoDB compatible query object.
|
|
188
315
|
*/
|
|
189
|
-
static buildSearchQueryMongo(modelClass: any, query?: any, exactMatch?: boolean, user?: any): any;
|
|
316
|
+
static buildSearchQueryMongo(modelClass: any, query?: any, exactMatch?: boolean, user?: any, depth?: number): any;
|
|
317
|
+
/**
|
|
318
|
+
* Compiles a single `PredicateNode` leaf to a MongoDB filter fragment (`{field: ...}`).
|
|
319
|
+
*/
|
|
320
|
+
private static compilePredicateMongo;
|
|
321
|
+
private static compileGroupMongo;
|
|
322
|
+
private static compileNodeMongo;
|
|
323
|
+
private static compilePredicateSQLOperator;
|
|
324
|
+
private static compileNodeSQL;
|
|
325
|
+
/**
|
|
326
|
+
* Compiles a `QueryNode` boolean tree into a query object for the given repository - the nested-condition
|
|
327
|
+
* counterpart to `buildSearchQuery()`'s flat `op(value)` query-parameter form, for boolean shapes the flat
|
|
328
|
+
* form can't express (e.g. `(a AND b) OR (c AND d)`, with no key forced into every branch). Reuses the same
|
|
329
|
+
* operand coercion, `me` substitution and operator-injection guard as the flat form. Bounded by the same
|
|
330
|
+
* `MAX_QUERY_DEPTH`/`MAX_QUERY_NODES` limits as `$or`. Negated groups are supported on MongoDB (via `$nor`)
|
|
331
|
+
* but rejected against the SQL `find()`-based `where` (see `compileNodeSQL`).
|
|
332
|
+
*
|
|
333
|
+
* @param modelClass The class definition of the data model to build a search query for.
|
|
334
|
+
* @param repo The repository to build a search query for.
|
|
335
|
+
* @param node The root of the query tree.
|
|
336
|
+
* @param user The user that is performing the request, resolved for any `field: "me"` predicate value.
|
|
337
|
+
*/
|
|
338
|
+
static buildQueryFromNode<T extends {}>(modelClass: any, repo: Repository<T> | MongoRepository<T> | undefined, node: QueryNode, user?: any): any;
|
|
339
|
+
/**
|
|
340
|
+
* Converts a `QueryNode` boolean tree into a PostgreSQL `tsquery` expression string (`AND` -> `&`, `OR` -> `|`,
|
|
341
|
+
* negation -> `!`), so client input can drive full-text search without passing untrusted text straight to
|
|
342
|
+
* `to_tsquery` (which throws on malformed input) while still supporting the boolean grouping
|
|
343
|
+
* `websearch_to_tsquery` cannot express. Every predicate leaf's `value` is treated as a search term
|
|
344
|
+
* (lexeme/phrase) regardless of its `field`/`op` - this framework has no notion of a full-text-indexed column,
|
|
345
|
+
* so the caller is expected to route the resulting expression to whichever `tsvector` column it's searching,
|
|
346
|
+
* e.g. `to_tsquery(ModelUtils.toTsQuery(node))`.
|
|
347
|
+
*/
|
|
348
|
+
static toTsQuery(node: QueryNode): string;
|
|
190
349
|
/**
|
|
191
350
|
* Loads all model schema files from the specified path and returns a map containing all the definitions.
|
|
192
351
|
*
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { RequestHandler } from "../http/types.js";
|
|
2
2
|
import { RateLimiter } from "../RateLimiter.js";
|
|
3
|
+
import { RateLimitOptions } from "../decorators/RouteDecorators.js";
|
|
3
4
|
/**
|
|
4
5
|
* Provides a set of utilities for converting Route classes to HTTP middleware.
|
|
5
6
|
*
|
|
@@ -18,10 +19,9 @@ export declare class RouteUtils {
|
|
|
18
19
|
*/
|
|
19
20
|
checkElevation(lastStart?: number): RequestHandler;
|
|
20
21
|
/**
|
|
21
|
-
* Creates a middleware function that performs rate limiting on the request
|
|
22
|
-
* used to identify the resource is the request `<method> <path>`.
|
|
22
|
+
* Creates a middleware function that performs rate limiting on the request.
|
|
23
23
|
*/
|
|
24
|
-
checkRateLimiter(): RequestHandler;
|
|
24
|
+
checkRateLimiter(options: RateLimitOptions): RequestHandler;
|
|
25
25
|
/**
|
|
26
26
|
* Creates a middleware function that verifies the incoming request is from a valid user with at least
|
|
27
27
|
* one of the specified roles.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rapidrest/service-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Provides all core functionality for RapidREST based backend services.",
|
|
5
5
|
"repository": "https://github.com/rapidrest/service-core.git",
|
|
6
6
|
"author": "RapidREST <rapidrests@gmail.com>",
|