@rapiq/parser-expression 2.0.0-beta.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021-2026 Peter Placzek
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # @rapiq/parser-expression
2
+
3
+ Part of [rapiq](https://github.com/tada5hi/rapiq) — typed REST queries: build, transport, validate, execute.
4
+
5
+ Parses a function-call expression language for filters — useful when a single string must carry a complex condition tree (search boxes, saved filters, CLI flags):
6
+
7
+ ```txt
8
+ and(eq(name, 'John'), gte(age, '18'))
9
+ or(in(status, 'active', 'pending'), gt(age, '65'))
10
+ not(contains(user.name, 'Bob'))
11
+ ```
12
+
13
+ ## Installation
14
+
15
+ ```sh
16
+ npm install @rapiq/core @rapiq/parser-simple @rapiq/parser-expression
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```typescript
22
+ import { ExpressionParser } from '@rapiq/parser-expression';
23
+
24
+ const parser = new ExpressionParser(registry);
25
+
26
+ const query = parser.parse({
27
+ filters: "and(eq(name, 'John'), gte(age, '18'))",
28
+ sort: '-age',
29
+ pagination: { limit: 25 },
30
+ }, { schema: 'user' });
31
+ ```
32
+
33
+ Only the `filters` parameter uses the expression language — fields, relations, pagination and sort accept the same input as [@rapiq/parser-simple](https://www.npmjs.com/package/@rapiq/parser-simple), and the whole thing returns the same [`Query`](https://rapiq.tada5hi.net/guide/query-ast) AST. A standalone `parseFilters(input, options)` returns just the `Filters` node.
34
+
35
+ The grammar: `eq`, `ne`, `lt`, `lte`, `gt`, `gte`, `in`, `nin`, `contains`, `startsWith`, `endsWith` (and negations) as leaf conditions, composed with `and(…)` / `or(…)` / `not(…)`. Values are always single-quoted (`gte(age, '18')`); quoted numerals coerce to numbers, `'true'`/`'false'` to booleans, `'null'` to `null`.
36
+
37
+ Syntax errors and schema violations throw `FiltersParseError` immediately — the expression parser has no silent-drop mode for malformed expressions.
38
+
39
+ ## Documentation
40
+
41
+ Full guide (grammar & operator table): [rapiq.tada5hi.net/packages/parser-expression](https://rapiq.tada5hi.net/packages/parser-expression)
42
+
43
+ ## License
44
+
45
+ Published under the [MIT License](https://github.com/tada5hi/rapiq/blob/master/LICENSE).
@@ -0,0 +1,153 @@
1
+ import { BaseParser, BaseQueryParser, FiltersParseOptions, IFilter, IFilters, ObjectLiteral, PaginationParseOptions, Scalar, SchemaRegistry } from "@rapiq/core";
2
+ import { SimpleFieldsParser, SimplePaginationParser, SimpleRelationsParser, SimpleSortParser } from "@rapiq/parser-simple";
3
+ //#region src/parameter/fields/module.d.ts
4
+ declare class ExpressionFieldsParser extends SimpleFieldsParser {}
5
+ //#endregion
6
+ //#region src/parameter/filters/constants.d.ts
7
+ declare enum FilterTokenType {
8
+ NOT = "NOT",
9
+ AND = "AND",
10
+ OR = "OR",
11
+ EQUAL = "eq",
12
+ GREATER_THAN = "gt",
13
+ GREATER_OR_EQUAL = "gte",
14
+ LESS_THAN = "lt",
15
+ LESS_OR_EQUAL = "lte",
16
+ CONTAINS = "like",
17
+ STARTS_WITH = "startsWith",
18
+ ENDS_WITH = "endsWith",
19
+ IN = "in",
20
+ NIN = "nin",
21
+ ELEM_MATCH = "elemMatch",
22
+ SIZE = "size",
23
+ FIELD = "FIELD",
24
+ ITSELF = "ITSELF",
25
+ ESCAPED_TEXT = "ESCAPED_TEXT",
26
+ NULL = "NULL",
27
+ LPAREN = "LPAREN",
28
+ RPAREN = "RPAREN",
29
+ COMMA = "COMMA",
30
+ DOT = "DOT",
31
+ EOF = "EOF"
32
+ }
33
+ /**
34
+ * Grammar keywords of the expression dialect mapped to the token
35
+ * they classify as. The tokenizer classifies whole identifiers
36
+ * against this map; encoders consume its keys to reject field
37
+ * segments that would tokenize as an operator on decode.
38
+ */
39
+ declare const FILTER_EXPRESSION_KEYWORDS: {
40
+ readonly not: FilterTokenType.NOT;
41
+ readonly and: FilterTokenType.AND;
42
+ readonly or: FilterTokenType.OR;
43
+ readonly eq: FilterTokenType.EQUAL;
44
+ readonly gt: FilterTokenType.GREATER_THAN;
45
+ readonly gte: FilterTokenType.GREATER_OR_EQUAL;
46
+ readonly lt: FilterTokenType.LESS_THAN;
47
+ readonly lte: FilterTokenType.LESS_OR_EQUAL;
48
+ readonly contains: FilterTokenType.CONTAINS;
49
+ readonly startsWith: FilterTokenType.STARTS_WITH;
50
+ readonly endsWith: FilterTokenType.ENDS_WITH;
51
+ readonly in: FilterTokenType.IN;
52
+ readonly nin: FilterTokenType.NIN;
53
+ readonly elemMatch: FilterTokenType.ELEM_MATCH;
54
+ readonly size: FilterTokenType.SIZE;
55
+ readonly null: FilterTokenType.NULL;
56
+ };
57
+ /**
58
+ * Identifier grammar of a single field segment as accepted by the
59
+ * expression tokenizer (unanchored regex source; consumers anchor
60
+ * it as needed).
61
+ */
62
+ declare const FILTER_FIELD_SEGMENT_PATTERN = "[A-Za-z0-9_](?:[A-Za-z0-9_-]*[A-Za-z0-9_])?";
63
+ //#endregion
64
+ //#region src/parameter/filters/module.d.ts
65
+ /**
66
+ * @see https://www.jsonapi.net/usage/reading/filtering.html
67
+ */
68
+ declare class ExpressionFiltersParser extends BaseParser<FiltersParseOptions, IFilters> {
69
+ private tokens;
70
+ private pos;
71
+ /**
72
+ * How many elemMatch interiors the parser is currently inside —
73
+ * the ITSELF marker is only legal at depth > 0.
74
+ */
75
+ private elemMatchDepth;
76
+ parse<RECORD extends ObjectLiteral = ObjectLiteral>(input: unknown, options?: FiltersParseOptions<RECORD>): IFilters;
77
+ parseAsync<RECORD extends ObjectLiteral = ObjectLiteral>(input: unknown, options?: FiltersParseOptions<RECORD>): Promise<IFilters>;
78
+ parseExact<RECORD extends ObjectLiteral = ObjectLiteral>(input: unknown, options?: FiltersParseOptions<RECORD>): IFilters | IFilter;
79
+ parseExactAsync<RECORD extends ObjectLiteral = ObjectLiteral>(input: unknown, options?: FiltersParseOptions<RECORD>): Promise<IFilters | IFilter>;
80
+ /**
81
+ * The shared front-end of {@link parseExact} and
82
+ * {@link parseExactAsync}: tokenize, bind the resolution scope and
83
+ * run the grammar — everything up to (but excluding) validation.
84
+ */
85
+ private parseSource;
86
+ private buildAbsentOutput;
87
+ private wrapRoot;
88
+ private peek;
89
+ private consume;
90
+ private tokenize;
91
+ private parseFilterExpression;
92
+ private parseNotExpression;
93
+ private parseLogicalExpression;
94
+ private parseComparisonExpression;
95
+ private parseMatchExpression;
96
+ private parseInExpression;
97
+ /**
98
+ * size(field, n): the field holds an array of exactly n elements
99
+ * (a non-negative integer — the wire is untyped, so the quoted
100
+ * value coerces back to a number). There is no complement — a
101
+ * negated size would silently widen and always throws.
102
+ */
103
+ private parseSizeExpression;
104
+ /**
105
+ * elemMatch(field, expr): field paths inside the interior are
106
+ * relative to the array element; the ITSELF marker addresses the
107
+ * element itself. There is no complement — a negated elemMatch
108
+ * would silently widen and always throws.
109
+ */
110
+ private parseElemMatchExpression;
111
+ /**
112
+ * The field an elemMatch binds plus the interior resolution scope:
113
+ * the related schema when resolvable, otherwise an unbound scope
114
+ * inheriting the current policy (e.g. a JSON array column).
115
+ */
116
+ private parseElemMatchTarget;
117
+ private buildUnboundScope;
118
+ private parseExpressionValue;
119
+ private parseExpressionFieldChain;
120
+ protected normalizeValue(input: unknown): Scalar;
121
+ }
122
+ //#endregion
123
+ //#region src/parameter/filters/types.d.ts
124
+ type FilterToken = {
125
+ type: `${FilterTokenType}`;
126
+ value?: string;
127
+ };
128
+ type FilterExpressionParseOptions<RECORD extends ObjectLiteral = ObjectLiteral> = FiltersParseOptions<RECORD>;
129
+ //#endregion
130
+ //#region src/parameter/pagination/types.d.ts
131
+ type ExpressionPaginationParseOptions = PaginationParseOptions;
132
+ //#endregion
133
+ //#region src/parameter/pagination/module.d.ts
134
+ declare class ExpressionPaginationParser extends SimplePaginationParser<ExpressionPaginationParseOptions> {}
135
+ //#endregion
136
+ //#region src/parameter/relations/module.d.ts
137
+ declare class ExpressionRelationsParser extends SimpleRelationsParser {}
138
+ //#endregion
139
+ //#region src/parameter/sorts/module.d.ts
140
+ declare class ExpressionSortParser extends SimpleSortParser {}
141
+ //#endregion
142
+ //#region src/module.d.ts
143
+ declare class ExpressionParser extends BaseQueryParser {
144
+ protected fieldsParser: ExpressionFieldsParser;
145
+ protected filtersParser: ExpressionFiltersParser;
146
+ protected paginationParser: ExpressionPaginationParser;
147
+ protected relationsParser: ExpressionRelationsParser;
148
+ protected sortParser: ExpressionSortParser;
149
+ constructor(input?: SchemaRegistry);
150
+ }
151
+ //#endregion
152
+ export { ExpressionFieldsParser, ExpressionFiltersParser, ExpressionPaginationParser, ExpressionParser, ExpressionRelationsParser, ExpressionSortParser, FILTER_EXPRESSION_KEYWORDS, FILTER_FIELD_SEGMENT_PATTERN, FilterExpressionParseOptions, FilterToken, FilterTokenType };
153
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/parameter/fields/module.ts","../src/parameter/filters/constants.ts","../src/parameter/filters/module.ts","../src/parameter/filters/types.ts","../src/parameter/pagination/types.ts","../src/parameter/pagination/module.ts","../src/parameter/relations/module.ts","../src/parameter/sorts/module.ts","../src/module.ts"],"mappings":";;;cASa,+BAA+B;;;aCFhC;EACR;EAEA;EACA;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;;;;;;cASS;;;;;;;;;;;;;;;;;;;;;;;cAwBA;;;;;;cCfA,gCAAgC,WACzC,qBACA;UAEQ;UAEA;;;;;UAMA;EAIR,MAAM,eAAe,gBAAgB,eACjC,gBACA,UAAS,oBAAoB,UAC7B;EAWW,WAAW,eAAe,gBAAgB,eACrD,gBACA,UAAS,oBAAoB,UAC7B,QAAQ;EAQZ,WAAW,eAAe,gBAAgB,eACtC,gBACA,UAAS,oBAAoB,UAC7B,WAAW;EAcT,gBAAgB,eAAe,gBAAgB,eACjD,gBACA,UAAS,oBAAoB,UAC7B,QAAQ,WAAW;;;;;;UAqBf;UAgCA;UAWA;UAaA;UAIA;UASA;UA0DA;UAsCA;UAaA;UAoCA;UAwFA;UA+CA;;;;;;;UA+CA;;;;;;;UAgCA;;;;;;UAmCA;UAqEA;UAOA;UAaA;YAqDE,eAAe,iBAAkB;;;;KCztBnC;EACR,SAAS;EACT;;KAGQ,6BACR,eAAe,gBAAgB,iBAC/B,oBAAoB;;;KCRZ,mCAAmC;;;cCClC,mCAAmC,uBAAuB;;;cCD1D,kCAAkC;;;cCAlC,6BAA6B;;;cCQ7B,yBAAyB;YACxB,cAAe;YAEf,eAAgB;YAEhB,kBAAmB;YAEnB,iBAAkB;YAElB,YAAa;cAIX,QAAQ"}
package/dist/index.mjs ADDED
@@ -0,0 +1,430 @@
1
+ import { BaseParser, BaseQueryParser, DEFAULT_ID, ErrorCode, Filter, FilterCompoundOperator, FilterFieldOperator, Filters, FiltersParseError, ITSELF, MAX_TRAVERSAL_DEPTH, Parameter, ParseError, ResolutionScope, applyFiltersSchemaValidation, applyFiltersSchemaValidationAsync, buildFiltersDefaults, isFilters } from "@rapiq/core";
2
+ import { SimpleFieldsParser, SimplePaginationParser, SimpleRelationsParser, SimpleSortParser, parseFilterScalar } from "@rapiq/parser-simple";
3
+ //#region src/parameter/fields/module.ts
4
+ var ExpressionFieldsParser = class extends SimpleFieldsParser {};
5
+ //#endregion
6
+ //#region src/parameter/filters/constants.ts
7
+ let FilterTokenType = /* @__PURE__ */ function(FilterTokenType) {
8
+ FilterTokenType["NOT"] = "NOT";
9
+ FilterTokenType["AND"] = "AND";
10
+ FilterTokenType["OR"] = "OR";
11
+ FilterTokenType["EQUAL"] = "eq";
12
+ FilterTokenType["GREATER_THAN"] = "gt";
13
+ FilterTokenType["GREATER_OR_EQUAL"] = "gte";
14
+ FilterTokenType["LESS_THAN"] = "lt";
15
+ FilterTokenType["LESS_OR_EQUAL"] = "lte";
16
+ FilterTokenType["CONTAINS"] = "like";
17
+ FilterTokenType["STARTS_WITH"] = "startsWith";
18
+ FilterTokenType["ENDS_WITH"] = "endsWith";
19
+ FilterTokenType["IN"] = "in";
20
+ FilterTokenType["NIN"] = "nin";
21
+ FilterTokenType["ELEM_MATCH"] = "elemMatch";
22
+ FilterTokenType["SIZE"] = "size";
23
+ FilterTokenType["FIELD"] = "FIELD";
24
+ FilterTokenType["ITSELF"] = "ITSELF";
25
+ FilterTokenType["ESCAPED_TEXT"] = "ESCAPED_TEXT";
26
+ FilterTokenType["NULL"] = "NULL";
27
+ FilterTokenType["LPAREN"] = "LPAREN";
28
+ FilterTokenType["RPAREN"] = "RPAREN";
29
+ FilterTokenType["COMMA"] = "COMMA";
30
+ FilterTokenType["DOT"] = "DOT";
31
+ FilterTokenType["EOF"] = "EOF";
32
+ return FilterTokenType;
33
+ }({});
34
+ /**
35
+ * Grammar keywords of the expression dialect mapped to the token
36
+ * they classify as. The tokenizer classifies whole identifiers
37
+ * against this map; encoders consume its keys to reject field
38
+ * segments that would tokenize as an operator on decode.
39
+ */
40
+ const FILTER_EXPRESSION_KEYWORDS = {
41
+ not: "NOT",
42
+ and: "AND",
43
+ or: "OR",
44
+ eq: "eq",
45
+ gt: "gt",
46
+ gte: "gte",
47
+ lt: "lt",
48
+ lte: "lte",
49
+ contains: "like",
50
+ startsWith: "startsWith",
51
+ endsWith: "endsWith",
52
+ in: "in",
53
+ nin: "nin",
54
+ elemMatch: "elemMatch",
55
+ size: "size",
56
+ null: "NULL"
57
+ };
58
+ /**
59
+ * Identifier grammar of a single field segment as accepted by the
60
+ * expression tokenizer (unanchored regex source; consumers anchor
61
+ * it as needed).
62
+ */
63
+ const FILTER_FIELD_SEGMENT_PATTERN = "[A-Za-z0-9_](?:[A-Za-z0-9_-]*[A-Za-z0-9_])?";
64
+ //#endregion
65
+ //#region src/parameter/filters/module.ts
66
+ /**
67
+ * Keep recursive expression parsing below the JavaScript call-stack limit and
68
+ * aligned with the schema resolver and Mongo parser traversal caps.
69
+ */
70
+ const MAX_DEPTH = MAX_TRAVERSAL_DEPTH;
71
+ /**
72
+ * @see https://www.jsonapi.net/usage/reading/filtering.html
73
+ */
74
+ var ExpressionFiltersParser = class extends BaseParser {
75
+ tokens = [];
76
+ pos = 0;
77
+ /**
78
+ * How many elemMatch interiors the parser is currently inside —
79
+ * the ITSELF marker is only legal at depth > 0.
80
+ */
81
+ elemMatchDepth = 0;
82
+ parse(input, options = {}) {
83
+ if (input === void 0 || input === null) return this.buildAbsentOutput(options);
84
+ return this.wrapRoot(this.parseExact(input, options));
85
+ }
86
+ async parseAsync(input, options = {}) {
87
+ if (input === void 0 || input === null) return this.buildAbsentOutput(options);
88
+ return this.wrapRoot(await this.parseExactAsync(input, options));
89
+ }
90
+ parseExact(input, options = {}) {
91
+ const { expr, scope } = this.parseSource(input, options);
92
+ if (!scope) return expr;
93
+ return applyFiltersSchemaValidation(expr, scope.schema) ?? new Filters(FilterCompoundOperator.AND, buildFiltersDefaults(scope.schema));
94
+ }
95
+ async parseExactAsync(input, options = {}) {
96
+ const { expr, scope } = this.parseSource(input, options);
97
+ if (!scope) return expr;
98
+ return await applyFiltersSchemaValidationAsync(expr, scope.schema) ?? new Filters(FilterCompoundOperator.AND, buildFiltersDefaults(scope.schema));
99
+ }
100
+ /**
101
+ * The shared front-end of {@link parseExact} and
102
+ * {@link parseExactAsync}: tokenize, bind the resolution scope and
103
+ * run the grammar — everything up to (but excluding) validation.
104
+ */
105
+ parseSource(input, options) {
106
+ if (typeof input !== "string") throw FiltersParseError.inputInvalid();
107
+ this.pos = 0;
108
+ this.elemMatchDepth = 0;
109
+ this.tokens = this.tokenize(input);
110
+ let scope;
111
+ if (options.schema || options.strict) scope = ResolutionScope.for(this.registry, Parameter.FILTERS, options.schema, {
112
+ relations: options.relations,
113
+ throwOnFailure: true,
114
+ strict: options.strict
115
+ });
116
+ const expr = this.parseFilterExpression(scope);
117
+ if (this.peek().type !== "EOF") throw FiltersParseError.syntaxInvalid(`Unexpected token: ${this.peek().type}`);
118
+ return {
119
+ expr,
120
+ scope
121
+ };
122
+ }
123
+ buildAbsentOutput(options) {
124
+ const scope = ResolutionScope.for(this.registry, Parameter.FILTERS, options.schema, { relations: options.relations });
125
+ return new Filters(FilterCompoundOperator.AND, buildFiltersDefaults(scope.schema));
126
+ }
127
+ wrapRoot(expr) {
128
+ if (isFilters(expr, FilterCompoundOperator.AND) || isFilters(expr, FilterCompoundOperator.OR)) return expr;
129
+ return new Filters(FilterCompoundOperator.AND, [expr]);
130
+ }
131
+ peek() {
132
+ return this.tokens[this.pos] || { type: "EOF" };
133
+ }
134
+ consume(expected) {
135
+ const token = this.peek();
136
+ if (expected && token.type !== expected) throw FiltersParseError.syntaxInvalid(`Expected ${expected}, got ${token.type}`);
137
+ this.pos++;
138
+ return token;
139
+ }
140
+ tokenize(input) {
141
+ const tokens = [];
142
+ const regex = new RegExp(`\\s+|\\(|\\)|,|\\.|'(?:''|[^'])*'|\\$[A-Za-z0-9_]*|${FILTER_FIELD_SEGMENT_PATTERN}`, "g");
143
+ let match;
144
+ let cursor = 0;
145
+ while (match = regex.exec(input)) {
146
+ if (match.index !== cursor) throw FiltersParseError.syntaxInvalid(`Unexpected character at position ${cursor}.`);
147
+ const value = match[0];
148
+ cursor = regex.lastIndex;
149
+ if (/^\s+$/.test(value)) continue;
150
+ switch (value) {
151
+ case "(":
152
+ tokens.push({ type: "LPAREN" });
153
+ break;
154
+ case ")":
155
+ tokens.push({ type: "RPAREN" });
156
+ break;
157
+ case ",":
158
+ tokens.push({ type: "COMMA" });
159
+ break;
160
+ case ".":
161
+ tokens.push({ type: "DOT" });
162
+ break;
163
+ default:
164
+ if (value.startsWith("$")) {
165
+ if (value !== ITSELF) throw FiltersParseError.syntaxInvalid(`The marker ${value} is unknown.`);
166
+ tokens.push({ type: "ITSELF" });
167
+ break;
168
+ }
169
+ if (Object.prototype.hasOwnProperty.call(FILTER_EXPRESSION_KEYWORDS, value)) tokens.push({ type: FILTER_EXPRESSION_KEYWORDS[value] });
170
+ else if (value.startsWith("'") && value.endsWith("'")) tokens.push({
171
+ type: "ESCAPED_TEXT",
172
+ value
173
+ });
174
+ else tokens.push({
175
+ type: "FIELD",
176
+ value
177
+ });
178
+ }
179
+ }
180
+ if (cursor !== input.length) throw FiltersParseError.syntaxInvalid(`Unexpected character at position ${cursor}.`);
181
+ tokens.push({ type: "EOF" });
182
+ return tokens;
183
+ }
184
+ parseFilterExpression(scope, negation = false, depth = 0) {
185
+ if (depth > MAX_DEPTH) throw FiltersParseError.syntaxInvalid("The maximum nesting depth was exceeded.");
186
+ const token = this.peek();
187
+ switch (token.type) {
188
+ case "NOT": return this.parseNotExpression(scope, negation, depth);
189
+ case "AND":
190
+ case "OR": return this.parseLogicalExpression(scope, negation, depth);
191
+ case "eq":
192
+ case "gt":
193
+ case "gte":
194
+ case "lt":
195
+ case "lte": return this.parseComparisonExpression(scope, negation);
196
+ case "like":
197
+ case "startsWith":
198
+ case "endsWith": return this.parseMatchExpression(scope, negation);
199
+ case "in":
200
+ case "nin": return this.parseInExpression(scope, negation);
201
+ case "elemMatch": return this.parseElemMatchExpression(scope, negation, depth);
202
+ case "size": return this.parseSizeExpression(scope, negation);
203
+ default: throw FiltersParseError.syntaxInvalid(`Unexpected token in filter expression: ${token.type}`);
204
+ }
205
+ }
206
+ parseNotExpression(scope, negation = false, depth = 0) {
207
+ this.consume("NOT");
208
+ this.consume("LPAREN");
209
+ const expr = this.parseFilterExpression(scope, !negation, depth + 1);
210
+ this.consume("RPAREN");
211
+ return expr;
212
+ }
213
+ parseLogicalExpression(scope, negation = false, depth = 0) {
214
+ let op = this.consume().type;
215
+ if (op !== "AND" && op !== "OR") throw FiltersParseError.syntaxInvalid("Expected AND or OR token type.");
216
+ this.consume("LPAREN");
217
+ const expressions = [this.parseFilterExpression(scope, negation, depth + 1)];
218
+ while (this.peek().type === "COMMA") {
219
+ this.consume("COMMA");
220
+ expressions.push(this.parseFilterExpression(scope, negation, depth + 1));
221
+ }
222
+ this.consume("RPAREN");
223
+ if (negation) if (op === "AND") op = "OR";
224
+ else op = "AND";
225
+ if (op === "AND") return new Filters(FilterCompoundOperator.AND, expressions);
226
+ return new Filters(FilterCompoundOperator.OR, expressions);
227
+ }
228
+ parseComparisonExpression(scope, negation = false) {
229
+ const op = this.consume().type;
230
+ this.consume("LPAREN");
231
+ const left = this.parseExpressionFieldChain(scope);
232
+ this.consume("COMMA");
233
+ const right = this.parseExpressionValue();
234
+ this.consume("RPAREN");
235
+ switch (op) {
236
+ case "eq":
237
+ if (negation) return new Filter(FilterFieldOperator.NOT_EQUAL, left, right);
238
+ return new Filter(FilterFieldOperator.EQUAL, left, right);
239
+ case "gt":
240
+ if (negation) return new Filter(FilterFieldOperator.LESS_THAN_EQUAL, left, right);
241
+ return new Filter(FilterFieldOperator.GREATER_THAN, left, right);
242
+ case "gte":
243
+ if (negation) return new Filter(FilterFieldOperator.LESS_THAN, left, right);
244
+ return new Filter(FilterFieldOperator.GREATER_THAN_EQUAL, left, right);
245
+ case "lt":
246
+ if (negation) return new Filter(FilterFieldOperator.GREATER_THAN_EQUAL, left, right);
247
+ return new Filter(FilterFieldOperator.LESS_THAN, left, right);
248
+ case "lte":
249
+ if (negation) return new Filter(FilterFieldOperator.GREATER_THAN, left, right);
250
+ return new Filter(FilterFieldOperator.LESS_THAN_EQUAL, left, right);
251
+ }
252
+ throw FiltersParseError.syntaxInvalid(`Token type ${op} not supported as comparison operator.`);
253
+ }
254
+ parseMatchExpression(scope, negation = false) {
255
+ const op = this.consume().type;
256
+ this.consume("LPAREN");
257
+ const field = this.parseExpressionFieldChain(scope);
258
+ this.consume("COMMA");
259
+ const text = this.consume("ESCAPED_TEXT").value;
260
+ this.consume("RPAREN");
261
+ const normalized = this.normalizeValue(text);
262
+ if (typeof normalized !== "string") throw FiltersParseError.keyValueInvalid(field);
263
+ switch (op) {
264
+ case "like": return new Filter(negation ? FilterFieldOperator.NOT_CONTAINS : FilterFieldOperator.CONTAINS, field, normalized);
265
+ case "endsWith": return new Filter(negation ? FilterFieldOperator.NOT_ENDS_WITH : FilterFieldOperator.ENDS_WITH, field, normalized);
266
+ default: return new Filter(negation ? FilterFieldOperator.NOT_STARTS_WITH : FilterFieldOperator.STARTS_WITH, field, normalized);
267
+ }
268
+ }
269
+ parseInExpression(scope, negation = false) {
270
+ const token = this.peek();
271
+ if (token.type === "nin") this.consume("nin");
272
+ else this.consume("in");
273
+ this.consume("LPAREN");
274
+ const field = this.parseExpressionFieldChain(scope);
275
+ const values = [];
276
+ while (this.peek().type === "COMMA") {
277
+ this.consume("COMMA");
278
+ values.push(this.parseExpressionValue());
279
+ }
280
+ this.consume("RPAREN");
281
+ if (token.type === "nin" && !negation || token.type === "in" && negation) return new Filter(FilterFieldOperator.NOT_IN, field, values);
282
+ return new Filter(FilterFieldOperator.IN, field, values);
283
+ }
284
+ /**
285
+ * size(field, n): the field holds an array of exactly n elements
286
+ * (a non-negative integer — the wire is untyped, so the quoted
287
+ * value coerces back to a number). There is no complement — a
288
+ * negated size would silently widen and always throws.
289
+ */
290
+ parseSizeExpression(scope, negation = false) {
291
+ if (negation) throw FiltersParseError.operatorUnsupported("size");
292
+ this.consume("size");
293
+ this.consume("LPAREN");
294
+ const field = this.parseExpressionFieldChain(scope);
295
+ this.consume("COMMA");
296
+ const value = this.parseExpressionValue();
297
+ this.consume("RPAREN");
298
+ if (typeof value !== "number" || !Number.isInteger(value) || value < 0) throw FiltersParseError.keyValueInvalid(field);
299
+ return new Filter(FilterFieldOperator.SIZE, field, value);
300
+ }
301
+ /**
302
+ * elemMatch(field, expr): field paths inside the interior are
303
+ * relative to the array element; the ITSELF marker addresses the
304
+ * element itself. There is no complement — a negated elemMatch
305
+ * would silently widen and always throws.
306
+ */
307
+ parseElemMatchExpression(scope, negation = false, depth = 0) {
308
+ if (negation) throw FiltersParseError.operatorUnsupported("elemMatch");
309
+ this.consume("elemMatch");
310
+ this.consume("LPAREN");
311
+ const target = this.parseElemMatchTarget(scope);
312
+ this.consume("COMMA");
313
+ this.elemMatchDepth += 1;
314
+ let condition;
315
+ try {
316
+ condition = this.parseFilterExpression(target.scope, false, depth + 1);
317
+ } finally {
318
+ this.elemMatchDepth -= 1;
319
+ }
320
+ this.consume("RPAREN");
321
+ return new Filter(FilterFieldOperator.ELEM_MATCH, target.field, condition);
322
+ }
323
+ /**
324
+ * The field an elemMatch binds plus the interior resolution scope:
325
+ * the related schema when resolvable, otherwise an unbound scope
326
+ * inheriting the current policy (e.g. a JSON array column).
327
+ */
328
+ parseElemMatchTarget(scope) {
329
+ if (this.peek().type === "ITSELF") return {
330
+ field: this.parseExpressionFieldChain(scope),
331
+ scope: scope ? this.buildUnboundScope(scope) : void 0
332
+ };
333
+ const parts = [this.consume("FIELD").value];
334
+ while (this.peek().type === "DOT") {
335
+ this.consume("DOT");
336
+ parts.push(this.consume("FIELD").value);
337
+ }
338
+ if (!scope) return { field: parts.join(".") };
339
+ if (parts.length > 1 && (parts[0] === DEFAULT_ID || parts[0] === scope.schema.name)) parts.shift();
340
+ const resolved = scope.resolveKey(parts.join("."));
341
+ /* istanbul ignore next -- the scope always throws */
342
+ if (!resolved.success) throw FiltersParseError.keyInvalid(resolved.input);
343
+ const field = [...resolved.path, resolved.name].join(".");
344
+ let interior;
345
+ try {
346
+ const verdict = resolved.scope.descend(resolved.name);
347
+ if (verdict instanceof ResolutionScope) interior = verdict;
348
+ } catch (e) {
349
+ if (!(e instanceof ParseError) || e.code !== ErrorCode.KEY_PATH_INVALID) throw e;
350
+ }
351
+ return {
352
+ field,
353
+ scope: interior ?? this.buildUnboundScope(scope)
354
+ };
355
+ }
356
+ buildUnboundScope(current) {
357
+ return ResolutionScope.for(this.registry, Parameter.FILTERS, void 0, {
358
+ throwOnFailure: true,
359
+ strict: current.strict
360
+ });
361
+ }
362
+ parseExpressionValue() {
363
+ const token = this.consume();
364
+ if (token.type !== "ESCAPED_TEXT" && token.type !== "NULL") throw FiltersParseError.syntaxInvalid(`Unexpected token in value: ${token.type}`);
365
+ return this.normalizeValue(token.value ?? "null");
366
+ }
367
+ parseExpressionFieldChain(scope) {
368
+ if (this.peek().type === "ITSELF") {
369
+ this.consume("ITSELF");
370
+ if (this.elemMatchDepth === 0) throw FiltersParseError.keyInvalid(ITSELF);
371
+ return ITSELF;
372
+ }
373
+ const token = this.consume("FIELD");
374
+ if (token.type !== "FIELD") throw FiltersParseError.syntaxInvalid(`Unexpected token in field chain: ${token.type}`);
375
+ const parts = [token.value];
376
+ while (this.peek().type === "DOT") {
377
+ this.consume("DOT");
378
+ parts.push(this.consume("FIELD").value);
379
+ }
380
+ if (scope) {
381
+ if (parts.length > 1 && (parts[0] === DEFAULT_ID || parts[0] === scope.schema.name)) parts.shift();
382
+ const resolved = scope.resolveKey(parts.join("."));
383
+ /* istanbul ignore next -- the scope always throws */
384
+ if (!resolved.success) throw FiltersParseError.keyInvalid(resolved.input);
385
+ return [...resolved.path, resolved.name].join(".");
386
+ }
387
+ return parts.join(".");
388
+ }
389
+ normalizeValue(input) {
390
+ if (typeof input === "string") {
391
+ const trimmed = input.trim();
392
+ if (trimmed.length === 0) return trimmed;
393
+ if (trimmed.startsWith("'") && trimmed.endsWith("'") && trimmed.length >= 2) return parseFilterScalar(trimmed.slice(1, -1).replace(/''/g, "'"));
394
+ return parseFilterScalar(trimmed);
395
+ }
396
+ if (typeof input === "number") return input;
397
+ if (typeof input === "undefined" || input === null) return null;
398
+ throw new SyntaxError("Value can not be normalized.");
399
+ }
400
+ };
401
+ //#endregion
402
+ //#region src/parameter/pagination/module.ts
403
+ var ExpressionPaginationParser = class extends SimplePaginationParser {};
404
+ //#endregion
405
+ //#region src/parameter/relations/module.ts
406
+ var ExpressionRelationsParser = class extends SimpleRelationsParser {};
407
+ //#endregion
408
+ //#region src/parameter/sorts/module.ts
409
+ var ExpressionSortParser = class extends SimpleSortParser {};
410
+ //#endregion
411
+ //#region src/module.ts
412
+ var ExpressionParser = class extends BaseQueryParser {
413
+ fieldsParser;
414
+ filtersParser;
415
+ paginationParser;
416
+ relationsParser;
417
+ sortParser;
418
+ constructor(input) {
419
+ super(input);
420
+ this.fieldsParser = new ExpressionFieldsParser(this.registry);
421
+ this.filtersParser = new ExpressionFiltersParser(this.registry);
422
+ this.paginationParser = new ExpressionPaginationParser(this.registry);
423
+ this.relationsParser = new ExpressionRelationsParser(this.registry);
424
+ this.sortParser = new ExpressionSortParser(this.registry);
425
+ }
426
+ };
427
+ //#endregion
428
+ export { ExpressionFieldsParser, ExpressionFiltersParser, ExpressionPaginationParser, ExpressionParser, ExpressionRelationsParser, ExpressionSortParser, FILTER_EXPRESSION_KEYWORDS, FILTER_FIELD_SEGMENT_PATTERN, FilterTokenType };
429
+
430
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/parameter/fields/module.ts","../src/parameter/filters/constants.ts","../src/parameter/filters/module.ts","../src/parameter/pagination/module.ts","../src/parameter/relations/module.ts","../src/parameter/sorts/module.ts","../src/module.ts"],"sourcesContent":["/*\n * Copyright (c) 2025-2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { SimpleFieldsParser } from '@rapiq/parser-simple';\n\nexport class ExpressionFieldsParser extends SimpleFieldsParser {\n\n}\n","/*\n * Copyright (c) 2025-2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum FilterTokenType {\n NOT = 'NOT',\n\n AND = 'AND',\n OR = 'OR',\n\n EQUAL = 'eq',\n GREATER_THAN = 'gt',\n GREATER_OR_EQUAL = 'gte',\n LESS_THAN = 'lt',\n LESS_OR_EQUAL = 'lte',\n CONTAINS = 'like',\n STARTS_WITH = 'startsWith',\n ENDS_WITH = 'endsWith',\n IN = 'in',\n NIN = 'nin',\n ELEM_MATCH = 'elemMatch',\n SIZE = 'size',\n\n FIELD = 'FIELD',\n ITSELF = 'ITSELF',\n ESCAPED_TEXT = 'ESCAPED_TEXT',\n NULL = 'NULL',\n LPAREN = 'LPAREN',\n RPAREN = 'RPAREN',\n COMMA = 'COMMA',\n DOT = 'DOT',\n EOF = 'EOF',\n}\n\n/**\n * Grammar keywords of the expression dialect mapped to the token\n * they classify as. The tokenizer classifies whole identifiers\n * against this map; encoders consume its keys to reject field\n * segments that would tokenize as an operator on decode.\n */\nexport const FILTER_EXPRESSION_KEYWORDS = {\n not: FilterTokenType.NOT,\n and: FilterTokenType.AND,\n or: FilterTokenType.OR,\n eq: FilterTokenType.EQUAL,\n gt: FilterTokenType.GREATER_THAN,\n gte: FilterTokenType.GREATER_OR_EQUAL,\n lt: FilterTokenType.LESS_THAN,\n lte: FilterTokenType.LESS_OR_EQUAL,\n contains: FilterTokenType.CONTAINS,\n startsWith: FilterTokenType.STARTS_WITH,\n endsWith: FilterTokenType.ENDS_WITH,\n in: FilterTokenType.IN,\n nin: FilterTokenType.NIN,\n elemMatch: FilterTokenType.ELEM_MATCH,\n size: FilterTokenType.SIZE,\n null: FilterTokenType.NULL,\n} as const satisfies Record<string, FilterTokenType>;\n\n/**\n * Identifier grammar of a single field segment as accepted by the\n * expression tokenizer (unanchored regex source; consumers anchor\n * it as needed).\n */\nexport const FILTER_FIELD_SEGMENT_PATTERN = '[A-Za-z0-9_](?:[A-Za-z0-9_-]*[A-Za-z0-9_])?';\n","/*\n * Copyright (c) 2021-2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type {\n FiltersParseOptions,\n IFilter,\n IFilters,\n ObjectLiteral,\n Scalar,\n} from '@rapiq/core';\nimport {\n BaseParser,\n DEFAULT_ID,\n ErrorCode,\n Filter,\n FilterCompoundOperator,\n FilterFieldOperator,\n Filters,\n FiltersParseError,\n ITSELF,\n MAX_TRAVERSAL_DEPTH,\n Parameter,\n ParseError,\n ResolutionScope,\n applyFiltersSchemaValidation,\n applyFiltersSchemaValidationAsync,\n buildFiltersDefaults,\n isFilters,\n} from '@rapiq/core';\nimport { parseFilterScalar } from '@rapiq/parser-simple';\nimport {\n FILTER_EXPRESSION_KEYWORDS,\n FILTER_FIELD_SEGMENT_PATTERN,\n FilterTokenType,\n} from './constants';\nimport type { FilterToken } from './types';\n\ntype FiltersScope = ResolutionScope<`${Parameter.FILTERS}`>;\n\n/**\n * Keep recursive expression parsing below the JavaScript call-stack limit and\n * aligned with the schema resolver and Mongo parser traversal caps.\n */\nconst MAX_DEPTH = MAX_TRAVERSAL_DEPTH;\n\n/**\n * @see https://www.jsonapi.net/usage/reading/filtering.html\n */\nexport class ExpressionFiltersParser extends BaseParser<\n FiltersParseOptions,\n IFilters\n> {\n private tokens: FilterToken[] = [];\n\n private pos = 0;\n\n /**\n * How many elemMatch interiors the parser is currently inside —\n * the ITSELF marker is only legal at depth > 0.\n */\n private elemMatchDepth = 0;\n\n // ---------------------------------------------------------\n\n parse<RECORD extends ObjectLiteral = ObjectLiteral>(\n input: unknown,\n options: FiltersParseOptions<RECORD> = {},\n ) : IFilters {\n // absent input is not a failure — schema defaults still apply.\n // an empty string is NOT absent: the dialect is precise, so\n // input like `?filter=` must surface a syntax error.\n if (input === undefined || input === null) {\n return this.buildAbsentOutput(options);\n }\n\n return this.wrapRoot(this.parseExact(input, options));\n }\n\n override async parseAsync<RECORD extends ObjectLiteral = ObjectLiteral>(\n input: unknown,\n options: FiltersParseOptions<RECORD> = {},\n ) : Promise<IFilters> {\n if (input === undefined || input === null) {\n return this.buildAbsentOutput(options);\n }\n\n return this.wrapRoot(await this.parseExactAsync(input, options));\n }\n\n parseExact<RECORD extends ObjectLiteral = ObjectLiteral>(\n input: unknown,\n options: FiltersParseOptions<RECORD> = {},\n ) : IFilters | IFilter {\n const { expr, scope } = this.parseSource(input, options);\n if (!scope) {\n return expr;\n }\n\n const validated = applyFiltersSchemaValidation(expr, scope.schema);\n\n return validated ?? new Filters(\n FilterCompoundOperator.AND,\n buildFiltersDefaults(scope.schema),\n );\n }\n\n async parseExactAsync<RECORD extends ObjectLiteral = ObjectLiteral>(\n input: unknown,\n options: FiltersParseOptions<RECORD> = {},\n ) : Promise<IFilters | IFilter> {\n const { expr, scope } = this.parseSource(input, options);\n if (!scope) {\n return expr;\n }\n\n const validated = await applyFiltersSchemaValidationAsync(expr, scope.schema);\n\n return validated ?? new Filters(\n FilterCompoundOperator.AND,\n buildFiltersDefaults(scope.schema),\n );\n }\n\n // ---------------------------------------------------------\n\n /**\n * The shared front-end of {@link parseExact} and\n * {@link parseExactAsync}: tokenize, bind the resolution scope and\n * run the grammar — everything up to (but excluding) validation.\n */\n private parseSource<RECORD extends ObjectLiteral = ObjectLiteral>(\n input: unknown,\n options: FiltersParseOptions<RECORD>,\n ) : { expr: Filters | Filter, scope?: FiltersScope } {\n if (typeof input !== 'string') {\n throw FiltersParseError.inputInvalid();\n }\n\n this.pos = 0;\n this.elemMatchDepth = 0;\n this.tokens = this.tokenize(input);\n\n // expressions are precise — invalid keys always throw,\n // but only when a schema (or the strict override,\n // which rejects undeclared keys) constrains the parse.\n let scope : FiltersScope | undefined;\n if (options.schema || options.strict) {\n scope = ResolutionScope.for(this.registry, Parameter.FILTERS, options.schema, {\n relations: options.relations,\n throwOnFailure: true,\n strict: options.strict,\n }) as FiltersScope;\n }\n\n const expr = this.parseFilterExpression(scope);\n if (this.peek().type !== FilterTokenType.EOF) {\n throw FiltersParseError.syntaxInvalid(`Unexpected token: ${this.peek().type}`);\n }\n\n return { expr, scope };\n }\n\n private buildAbsentOutput<RECORD extends ObjectLiteral = ObjectLiteral>(\n options: FiltersParseOptions<RECORD>,\n ) : IFilters {\n const scope = ResolutionScope.for(this.registry, Parameter.FILTERS, options.schema, { relations: options.relations }) as FiltersScope;\n\n return new Filters(\n FilterCompoundOperator.AND,\n buildFiltersDefaults(scope.schema),\n );\n }\n\n private wrapRoot(expr: IFilters | IFilter) : IFilters {\n if (\n isFilters(expr, FilterCompoundOperator.AND) ||\n isFilters(expr, FilterCompoundOperator.OR)\n ) {\n return expr;\n }\n\n return new Filters(FilterCompoundOperator.AND, [expr]);\n }\n\n // ---------------------------------------------------------\n\n private peek(): FilterToken {\n return this.tokens[this.pos] || { type: FilterTokenType.EOF };\n }\n\n private consume(expected?: `${FilterTokenType}`): FilterToken {\n const token = this.peek();\n if (expected && token.type !== expected) {\n throw FiltersParseError.syntaxInvalid(`Expected ${expected}, got ${token.type}`);\n }\n this.pos++;\n return token;\n }\n\n private tokenize(input: string): FilterToken[] {\n const tokens: FilterToken[] = [];\n // keywords are classified from whole identifiers (lookup below) —\n // matching them in the regex would split identifiers that merely\n // start with a keyword (e.g. \"order\" -> \"or\" + \"der\").\n // $-words are reserved markers, never field segments.\n const regex = new RegExp(`\\\\s+|\\\\(|\\\\)|,|\\\\.|'(?:''|[^'])*'|\\\\$[A-Za-z0-9_]*|${FILTER_FIELD_SEGMENT_PATTERN}`, 'g');\n\n let match: RegExpExecArray | null;\n let cursor = 0;\n\n while ((match = regex.exec(input))) {\n if (match.index !== cursor) {\n throw FiltersParseError.syntaxInvalid(`Unexpected character at position ${cursor}.`);\n }\n\n const value = match[0];\n cursor = regex.lastIndex;\n if (/^\\s+$/.test(value)) continue;\n\n switch (value) {\n case '(': tokens.push({ type: FilterTokenType.LPAREN }); break;\n case ')': tokens.push({ type: FilterTokenType.RPAREN }); break;\n case ',': tokens.push({ type: FilterTokenType.COMMA }); break;\n case '.': tokens.push({ type: FilterTokenType.DOT }); break;\n default:\n if (value.startsWith('$')) {\n if (value !== ITSELF) {\n throw FiltersParseError.syntaxInvalid(`The marker ${value} is unknown.`);\n }\n\n tokens.push({ type: FilterTokenType.ITSELF });\n break;\n }\n\n // own-property check: exotic field names inherited from\n // Object.prototype (toString, constructor, ...) stay fields.\n if (Object.prototype.hasOwnProperty.call(FILTER_EXPRESSION_KEYWORDS, value)) {\n tokens.push({ type: FILTER_EXPRESSION_KEYWORDS[value as keyof typeof FILTER_EXPRESSION_KEYWORDS] });\n } else if (\n value.startsWith('\\'') &&\n value.endsWith('\\'')\n ) {\n tokens.push({ type: FilterTokenType.ESCAPED_TEXT, value });\n } else {\n tokens.push({ type: FilterTokenType.FIELD, value });\n }\n }\n }\n\n if (cursor !== input.length) {\n throw FiltersParseError.syntaxInvalid(`Unexpected character at position ${cursor}.`);\n }\n\n tokens.push({ type: FilterTokenType.EOF });\n return tokens;\n }\n\n private parseFilterExpression(\n scope?: FiltersScope,\n negation: boolean = false,\n depth: number = 0,\n ) : Filters | Filter {\n if (depth > MAX_DEPTH) {\n throw FiltersParseError.syntaxInvalid('The maximum nesting depth was exceeded.');\n }\n\n const token = this.peek();\n switch (token.type) {\n case FilterTokenType.NOT:\n return this.parseNotExpression(scope, negation, depth);\n case FilterTokenType.AND:\n case FilterTokenType.OR:\n return this.parseLogicalExpression(scope, negation, depth);\n case FilterTokenType.EQUAL:\n case FilterTokenType.GREATER_THAN:\n case FilterTokenType.GREATER_OR_EQUAL:\n case FilterTokenType.LESS_THAN:\n case FilterTokenType.LESS_OR_EQUAL:\n return this.parseComparisonExpression(scope, negation);\n case FilterTokenType.CONTAINS:\n case FilterTokenType.STARTS_WITH:\n case FilterTokenType.ENDS_WITH:\n return this.parseMatchExpression(scope, negation);\n case FilterTokenType.IN:\n case FilterTokenType.NIN:\n return this.parseInExpression(scope, negation);\n case FilterTokenType.ELEM_MATCH:\n return this.parseElemMatchExpression(scope, negation, depth);\n case FilterTokenType.SIZE:\n return this.parseSizeExpression(scope, negation);\n default:\n throw FiltersParseError.syntaxInvalid(`Unexpected token in filter expression: ${token.type}`);\n }\n }\n\n private parseNotExpression(\n scope?: FiltersScope,\n negation: boolean = false,\n depth: number = 0,\n ): Filters | Filter {\n this.consume(FilterTokenType.NOT);\n this.consume(FilterTokenType.LPAREN);\n const expr = this.parseFilterExpression(scope, !negation, depth + 1);\n this.consume(FilterTokenType.RPAREN);\n\n return expr;\n }\n\n private parseLogicalExpression(\n scope?: FiltersScope,\n negation: boolean = false,\n depth: number = 0,\n ): Filters | Filter {\n let op = this.consume().type; // AND / OR\n if (op !== FilterTokenType.AND && op !== FilterTokenType.OR) {\n throw FiltersParseError.syntaxInvalid('Expected AND or OR token type.');\n }\n\n this.consume(FilterTokenType.LPAREN);\n const expressions: (Filter | Filters)[] = [this.parseFilterExpression(scope, negation, depth + 1)];\n while (this.peek().type === FilterTokenType.COMMA) {\n this.consume(FilterTokenType.COMMA);\n expressions.push(this.parseFilterExpression(scope, negation, depth + 1));\n }\n this.consume(FilterTokenType.RPAREN);\n\n if (negation) {\n if (op === FilterTokenType.AND) {\n op = FilterTokenType.OR;\n } else {\n op = FilterTokenType.AND;\n }\n }\n\n if (op === FilterTokenType.AND) {\n return new Filters(\n FilterCompoundOperator.AND,\n expressions,\n );\n }\n\n return new Filters(FilterCompoundOperator.OR, expressions);\n }\n\n private parseComparisonExpression(\n scope?: FiltersScope,\n negation: boolean = false,\n ): Filters | Filter {\n const op = this.consume().type;\n this.consume(FilterTokenType.LPAREN);\n const left = this.parseExpressionFieldChain(scope);\n this.consume(FilterTokenType.COMMA);\n const right = this.parseExpressionValue();\n this.consume(FilterTokenType.RPAREN);\n\n switch (op) {\n case FilterTokenType.EQUAL: {\n if (negation) {\n return new Filter(\n FilterFieldOperator.NOT_EQUAL,\n left as string,\n right as string,\n );\n }\n\n return new Filter(\n FilterFieldOperator.EQUAL,\n left as string,\n right as string,\n );\n }\n case FilterTokenType.GREATER_THAN: {\n if (negation) {\n return new Filter(\n FilterFieldOperator.LESS_THAN_EQUAL,\n left as string,\n right as string,\n );\n }\n return new Filter(\n FilterFieldOperator.GREATER_THAN,\n left as string,\n right as string,\n );\n }\n case FilterTokenType.GREATER_OR_EQUAL: {\n if (negation) {\n return new Filter(\n FilterFieldOperator.LESS_THAN,\n left as string,\n right as string,\n );\n }\n return new Filter(\n FilterFieldOperator.GREATER_THAN_EQUAL,\n left as string,\n right as string,\n );\n }\n case FilterTokenType.LESS_THAN: {\n if (negation) {\n return new Filter(\n FilterFieldOperator.GREATER_THAN_EQUAL,\n left as string,\n right as string,\n );\n }\n return new Filter(\n FilterFieldOperator.LESS_THAN,\n left as string,\n right as string,\n );\n }\n case FilterTokenType.LESS_OR_EQUAL: {\n if (negation) {\n return new Filter(\n FilterFieldOperator.GREATER_THAN,\n left as string,\n right as string,\n );\n }\n return new Filter(\n FilterFieldOperator.LESS_THAN_EQUAL,\n left as string,\n right as string,\n );\n }\n }\n\n throw FiltersParseError.syntaxInvalid(`Token type ${op} not supported as comparison operator.`);\n }\n\n private parseMatchExpression(\n scope?: FiltersScope,\n negation: boolean = false,\n ): Filters | Filter {\n const op = this.consume().type;\n this.consume(FilterTokenType.LPAREN);\n const field = this.parseExpressionFieldChain(scope);\n this.consume(FilterTokenType.COMMA);\n const text = this.consume(FilterTokenType.ESCAPED_TEXT).value!;\n this.consume(FilterTokenType.RPAREN);\n\n const normalized = this.normalizeValue(text);\n if (typeof normalized !== 'string') {\n throw FiltersParseError.keyValueInvalid(field);\n }\n\n switch (op) {\n case FilterTokenType.CONTAINS: {\n return new Filter(\n negation ?\n FilterFieldOperator.NOT_CONTAINS :\n FilterFieldOperator.CONTAINS,\n field,\n normalized,\n );\n }\n case FilterTokenType.ENDS_WITH: {\n return new Filter(\n negation ?\n FilterFieldOperator.NOT_ENDS_WITH :\n FilterFieldOperator.ENDS_WITH,\n field,\n normalized,\n );\n }\n default: {\n return new Filter(\n negation ?\n FilterFieldOperator.NOT_STARTS_WITH :\n FilterFieldOperator.STARTS_WITH,\n field,\n normalized,\n );\n }\n }\n }\n\n private parseInExpression(\n scope?: FiltersScope,\n negation: boolean = false,\n ): Filters | Filter {\n const token = this.peek();\n if (token.type === FilterTokenType.NIN) {\n this.consume(FilterTokenType.NIN);\n } else {\n this.consume(FilterTokenType.IN);\n }\n\n this.consume(FilterTokenType.LPAREN);\n\n const field = this.parseExpressionFieldChain(scope);\n\n const values: unknown[] = [];\n while (this.peek().type === FilterTokenType.COMMA) {\n this.consume(FilterTokenType.COMMA);\n\n values.push(this.parseExpressionValue());\n }\n this.consume(FilterTokenType.RPAREN);\n\n const notIn = (token.type === FilterTokenType.NIN && !negation) ||\n (token.type === FilterTokenType.IN && negation);\n\n if (notIn) {\n return new Filter(\n FilterFieldOperator.NOT_IN,\n field,\n values,\n );\n }\n\n return new Filter(\n FilterFieldOperator.IN,\n field,\n values,\n );\n }\n\n /**\n * size(field, n): the field holds an array of exactly n elements\n * (a non-negative integer — the wire is untyped, so the quoted\n * value coerces back to a number). There is no complement — a\n * negated size would silently widen and always throws.\n */\n private parseSizeExpression(\n scope?: FiltersScope,\n negation: boolean = false,\n ): Filter {\n if (negation) {\n throw FiltersParseError.operatorUnsupported('size');\n }\n\n this.consume(FilterTokenType.SIZE);\n this.consume(FilterTokenType.LPAREN);\n const field = this.parseExpressionFieldChain(scope);\n this.consume(FilterTokenType.COMMA);\n const value = this.parseExpressionValue();\n this.consume(FilterTokenType.RPAREN);\n\n if (\n typeof value !== 'number' ||\n !Number.isInteger(value) ||\n value < 0\n ) {\n throw FiltersParseError.keyValueInvalid(field);\n }\n\n return new Filter(FilterFieldOperator.SIZE, field, value);\n }\n\n /**\n * elemMatch(field, expr): field paths inside the interior are\n * relative to the array element; the ITSELF marker addresses the\n * element itself. There is no complement — a negated elemMatch\n * would silently widen and always throws.\n */\n private parseElemMatchExpression(\n scope?: FiltersScope,\n negation: boolean = false,\n depth: number = 0,\n ): Filter {\n if (negation) {\n throw FiltersParseError.operatorUnsupported('elemMatch');\n }\n\n this.consume(FilterTokenType.ELEM_MATCH);\n this.consume(FilterTokenType.LPAREN);\n\n const target = this.parseElemMatchTarget(scope);\n\n this.consume(FilterTokenType.COMMA);\n\n this.elemMatchDepth += 1;\n\n let condition : Filters | Filter;\n try {\n condition = this.parseFilterExpression(target.scope, false, depth + 1);\n } finally {\n this.elemMatchDepth -= 1;\n }\n\n this.consume(FilterTokenType.RPAREN);\n\n return new Filter(FilterFieldOperator.ELEM_MATCH, target.field, condition);\n }\n\n /**\n * The field an elemMatch binds plus the interior resolution scope:\n * the related schema when resolvable, otherwise an unbound scope\n * inheriting the current policy (e.g. a JSON array column).\n */\n private parseElemMatchTarget(\n scope?: FiltersScope,\n ): { field: string, scope?: FiltersScope } {\n if (this.peek().type === FilterTokenType.ITSELF) {\n // an elemMatch on the element itself (arrays of arrays);\n // the chain parser enforces the interior-only contract.\n const field = this.parseExpressionFieldChain(scope);\n\n return {\n field,\n scope: scope ? this.buildUnboundScope(scope) : undefined,\n };\n }\n\n const token = this.consume(FilterTokenType.FIELD);\n\n const parts = [token.value!];\n while (this.peek().type === FilterTokenType.DOT) {\n this.consume(FilterTokenType.DOT);\n parts.push(this.consume(FilterTokenType.FIELD).value!);\n }\n\n if (!scope) {\n return { field: parts.join('.') };\n }\n\n // a leading segment matching the schema name addresses the\n // schema itself (mirrors parseExpressionFieldChain).\n if (\n parts.length > 1 &&\n (parts[0] === DEFAULT_ID || parts[0] === scope.schema.name)\n ) {\n parts.shift();\n }\n\n const resolved = scope.resolveKey(parts.join('.'));\n\n /* istanbul ignore next -- the scope always throws */\n if (!resolved.success) {\n throw FiltersParseError.keyInvalid(resolved.input);\n }\n\n const field = [...resolved.path, resolved.name].join('.');\n\n let interior : FiltersScope | undefined;\n try {\n const verdict = resolved.scope.descend(resolved.name);\n if (verdict instanceof ResolutionScope) {\n interior = verdict as FiltersScope;\n }\n } catch (e) {\n // elemMatch on a non-relation field is legal — a missing\n // related schema (thrown as keyPathInvalid, the scope is\n // always throwing) falls back to the unbound scope; every\n // other failure (e.g. relations gating) propagates.\n if (\n !(e instanceof ParseError) ||\n e.code !== ErrorCode.KEY_PATH_INVALID\n ) {\n throw e;\n }\n }\n\n return {\n field,\n scope: interior ?? this.buildUnboundScope(scope),\n };\n }\n\n private buildUnboundScope(current: FiltersScope) : FiltersScope {\n return ResolutionScope.for(this.registry, Parameter.FILTERS, undefined, {\n throwOnFailure: true,\n strict: current.strict,\n }) as FiltersScope;\n }\n\n private parseExpressionValue(): Scalar {\n const token = this.consume();\n\n if (\n token.type !== FilterTokenType.ESCAPED_TEXT &&\n token.type !== FilterTokenType.NULL\n ) {\n throw FiltersParseError.syntaxInvalid(`Unexpected token in value: ${token.type}`);\n }\n\n return this.normalizeValue(token.value ?? 'null');\n }\n\n private parseExpressionFieldChain(\n scope?: FiltersScope,\n ): string {\n if (this.peek().type === FilterTokenType.ITSELF) {\n this.consume(FilterTokenType.ITSELF);\n\n // the marker addresses the element bound by the enclosing\n // elemMatch interior and never resolves against the schema.\n if (this.elemMatchDepth === 0) {\n throw FiltersParseError.keyInvalid(ITSELF);\n }\n\n return ITSELF;\n }\n\n const token = this.consume(FilterTokenType.FIELD);\n if (token.type !== FilterTokenType.FIELD) {\n throw FiltersParseError.syntaxInvalid(`Unexpected token in field chain: ${token.type}`);\n }\n\n const parts = [token.value!];\n\n while (this.peek().type === FilterTokenType.DOT) {\n this.consume(FilterTokenType.DOT);\n parts.push(this.consume(FilterTokenType.FIELD).value!);\n }\n\n if (scope) {\n // a leading segment matching the schema name addresses the\n // schema itself (mirrors the named-group hoisting of the\n // simple filters parser) and is stripped.\n if (\n parts.length > 1 &&\n (parts[0] === DEFAULT_ID || parts[0] === scope.schema.name)\n ) {\n parts.shift();\n }\n\n const resolved = scope.resolveKey(parts.join('.'));\n\n /* istanbul ignore next -- the scope always throws */\n if (!resolved.success) {\n throw FiltersParseError.keyInvalid(resolved.input);\n }\n\n return [...resolved.path, resolved.name].join('.');\n }\n\n return parts.join('.');\n }\n\n // ---------------------------------------------------------\n\n protected normalizeValue(input: unknown) : Scalar {\n if (typeof input === 'string') {\n const trimmed = input.trim();\n if (trimmed.length === 0) {\n return trimmed;\n }\n\n // quoted content is coerced but never comma-split —\n // the expression dialect passes lists as separate args.\n if (\n trimmed.startsWith('\\'') &&\n trimmed.endsWith('\\'') &&\n trimmed.length >= 2\n ) {\n return parseFilterScalar(trimmed.slice(1, -1).replace(/''/g, '\\''));\n }\n\n return parseFilterScalar(trimmed);\n }\n\n if (typeof input === 'number') {\n return input;\n }\n\n if (typeof input === 'undefined' || input === null) {\n return null;\n }\n\n throw new SyntaxError('Value can not be normalized.');\n }\n}\n","/*\n * Copyright (c) 2022-2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { SimplePaginationParser } from '@rapiq/parser-simple';\nimport type { ExpressionPaginationParseOptions } from './types';\n\nexport class ExpressionPaginationParser extends SimplePaginationParser<ExpressionPaginationParseOptions> {\n\n}\n","/*\n * Copyright (c) 2021-2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { SimpleRelationsParser } from '@rapiq/parser-simple';\n\nexport class ExpressionRelationsParser extends SimpleRelationsParser {\n\n}\n","/*\n * Copyright (c) 2021-2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { SimpleSortParser } from '@rapiq/parser-simple';\n\nexport class ExpressionSortParser extends SimpleSortParser {\n\n}\n","/*\n * Copyright (c) 2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { SchemaRegistry } from '@rapiq/core';\nimport { BaseQueryParser } from '@rapiq/core';\nimport {\n ExpressionFieldsParser,\n ExpressionFiltersParser,\n ExpressionPaginationParser,\n ExpressionRelationsParser,\n ExpressionSortParser,\n} from './parameter';\n\nexport class ExpressionParser extends BaseQueryParser {\n protected fieldsParser : ExpressionFieldsParser;\n\n protected filtersParser : ExpressionFiltersParser;\n\n protected paginationParser : ExpressionPaginationParser;\n\n protected relationsParser : ExpressionRelationsParser;\n\n protected sortParser : ExpressionSortParser;\n\n // -----------------------------------------------------\n\n constructor(input?: SchemaRegistry) {\n super(input);\n\n this.fieldsParser = new ExpressionFieldsParser(this.registry);\n this.filtersParser = new ExpressionFiltersParser(this.registry);\n this.paginationParser = new ExpressionPaginationParser(this.registry);\n this.relationsParser = new ExpressionRelationsParser(this.registry);\n this.sortParser = new ExpressionSortParser(this.registry);\n }\n}\n"],"mappings":";;;AASA,IAAa,yBAAb,cAA4C,mBAAmB,CAE/D;;;ACJA,IAAY,kBAAL,yBAAA,iBAAA;CACH,gBAAA,SAAA;CAEA,gBAAA,SAAA;CACA,gBAAA,QAAA;CAEA,gBAAA,WAAA;CACA,gBAAA,kBAAA;CACA,gBAAA,sBAAA;CACA,gBAAA,eAAA;CACA,gBAAA,mBAAA;CACA,gBAAA,cAAA;CACA,gBAAA,iBAAA;CACA,gBAAA,eAAA;CACA,gBAAA,QAAA;CACA,gBAAA,SAAA;CACA,gBAAA,gBAAA;CACA,gBAAA,UAAA;CAEA,gBAAA,WAAA;CACA,gBAAA,YAAA;CACA,gBAAA,kBAAA;CACA,gBAAA,UAAA;CACA,gBAAA,YAAA;CACA,gBAAA,YAAA;CACA,gBAAA,WAAA;CACA,gBA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AAC,GAAG,SAAS,MAAM,SAAS,IAAI,CAAC,CAAC,KAAK,GAAG;EACrD;EAEA,OAAO,MAAM,KAAK,GAAG;CACzB;CAIA,eAAyB,OAAyB;EAC9C,IAAI,OAAO,UAAU,UAAU;GAC3B,MAAM,UAAU,MAAM,KAAK;GAC3B,IAAI,QAAQ,WAAW,GACnB,OAAO;GAKX,IACI,QAAQ,WAAW,GAAI,KACvB,QAAQ,SAAS,GAAI,KACrB,QAAQ,UAAU,GAElB,OAAO,kBAAkB,QAAQ,MAAM,GAAG,EAAE,CAAC,CAAC,QAAQ,OAAO,GAAI,CAAC;GAGtE,OAAO,kBAAkB,OAAO;EACpC;EAEA,IAAI,OAAO,UAAU,UACjB,OAAO;EAGX,IAAI,OAAO,UAAU,eAAe,UAAU,MAC1C,OAAO;EAGX,MAAM,IAAI,YAAY,8BAA8B;CACxD;AACJ;;;ACvvBA,IAAa,6BAAb,cAAgD,uBAAyD,CAEzG;;;ACHA,IAAa,4BAAb,cAA+C,sBAAsB,CAErE;;;ACFA,IAAa,uBAAb,cAA0C,iBAAiB,CAE3D;;;ACMA,IAAa,mBAAb,cAAsC,gBAAgB;CAClD;CAEA;CAEA;CAEA;CAEA;CAIA,YAAY,OAAwB;EAChC,MAAM,KAAK;EAEX,KAAK,eAAe,IAAI,uBAAuB,KAAK,QAAQ;EAC5D,KAAK,gBAAgB,IAAI,wBAAwB,KAAK,QAAQ;EAC9D,KAAK,mBAAmB,IAAI,2BAA2B,KAAK,QAAQ;EACpE,KAAK,kBAAkB,IAAI,0BAA0B,KAAK,QAAQ;EAClE,KAAK,aAAa,IAAI,qBAAqB,KAAK,QAAQ;CAC5D;AACJ"}
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@rapiq/parser-expression",
3
+ "version": "2.0.0-beta.0",
4
+ "description": "A package containing an expression parser",
5
+ "type": "module",
6
+ "main": "dist/index.mjs",
7
+ "types": "dist/index.d.mts",
8
+ "exports": {
9
+ "./package.json": "./package.json",
10
+ ".": {
11
+ "types": "./dist/index.d.mts",
12
+ "import": "./dist/index.mjs"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist/"
17
+ ],
18
+ "devDependencies": {
19
+ "@rapiq/core": "^2.0.0-beta.0",
20
+ "@rapiq/parser-simple": "^2.0.0-beta.0"
21
+ },
22
+ "peerDependencies": {
23
+ "@rapiq/core": "^2.0.0-beta.0",
24
+ "@rapiq/parser-simple": "^2.0.0-beta.0"
25
+ },
26
+ "scripts": {
27
+ "build:types": "tsc --noEmit -p tsconfig.build.json",
28
+ "build:js": "tsdown",
29
+ "build": "npm run build:types && npm run build:js",
30
+ "test": "vitest --config test/vitest.config.ts --run",
31
+ "test:coverage": "vitest --config test/vitest.config.ts --run --coverage",
32
+ "prepublishOnly": "npm run build"
33
+ },
34
+ "author": {
35
+ "name": "Peter Placzek",
36
+ "email": "contact@tada5hi.net",
37
+ "url": "https://github.com/tada5hi"
38
+ },
39
+ "license": "MIT",
40
+ "publishConfig": {
41
+ "access": "public",
42
+ "tag": "beta"
43
+ },
44
+ "keywords": [
45
+ "query",
46
+ "json",
47
+ "json-api",
48
+ "api",
49
+ "rest",
50
+ "api-utils",
51
+ "include",
52
+ "pagination",
53
+ "sort",
54
+ "fields",
55
+ "filter",
56
+ "relations",
57
+ "typescript"
58
+ ],
59
+ "repository": {
60
+ "type": "git",
61
+ "url": "git+https://github.com/Tada5hi/rapiq.git",
62
+ "directory": "packages/parser-expression"
63
+ },
64
+ "bugs": {
65
+ "url": "https://github.com/Tada5hi/rapiq/issues"
66
+ },
67
+ "homepage": "https://github.com/Tada5hi/rapiq#readme"
68
+ }