@opensaas/stack-core 0.44.0-alpha.4 → 0.44.0-alpha.6

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.
Files changed (160) hide show
  1. package/CHANGELOG.md +402 -0
  2. package/dist/.build-hash +1 -1
  3. package/dist/access/field-access.d.ts +22 -0
  4. package/dist/access/field-access.d.ts.map +1 -1
  5. package/dist/access/field-access.js +112 -69
  6. package/dist/access/field-access.js.map +1 -1
  7. package/dist/access/field-visibility.d.ts +1 -48
  8. package/dist/access/field-visibility.d.ts.map +1 -1
  9. package/dist/access/field-visibility.js +12 -29
  10. package/dist/access/field-visibility.js.map +1 -1
  11. package/dist/access/index.d.ts +3 -1
  12. package/dist/access/index.d.ts.map +1 -1
  13. package/dist/access/index.js +3 -1
  14. package/dist/access/index.js.map +1 -1
  15. package/dist/access/rule-item.d.ts +42 -0
  16. package/dist/access/rule-item.d.ts.map +1 -0
  17. package/dist/access/rule-item.js +215 -0
  18. package/dist/access/rule-item.js.map +1 -0
  19. package/dist/access/types.d.ts +17 -0
  20. package/dist/access/types.d.ts.map +1 -1
  21. package/dist/config/has-access-gate.d.ts +20 -0
  22. package/dist/config/has-access-gate.d.ts.map +1 -0
  23. package/dist/config/has-access-gate.js +26 -0
  24. package/dist/config/has-access-gate.js.map +1 -0
  25. package/dist/config/index.d.ts +1 -1
  26. package/dist/config/index.d.ts.map +1 -1
  27. package/dist/config/index.js +7 -2
  28. package/dist/config/index.js.map +1 -1
  29. package/dist/config/list-view-keys.d.ts +5 -0
  30. package/dist/config/list-view-keys.d.ts.map +1 -0
  31. package/dist/config/list-view-keys.js +18 -0
  32. package/dist/config/list-view-keys.js.map +1 -0
  33. package/dist/config/preset-views.d.ts +22 -0
  34. package/dist/config/preset-views.d.ts.map +1 -0
  35. package/dist/config/preset-views.js +46 -0
  36. package/dist/config/preset-views.js.map +1 -0
  37. package/dist/config/row-action-availability.d.ts +4 -0
  38. package/dist/config/row-action-availability.d.ts.map +1 -0
  39. package/dist/config/row-action-availability.js +20 -0
  40. package/dist/config/row-action-availability.js.map +1 -0
  41. package/dist/config/types.d.ts +268 -6
  42. package/dist/config/types.d.ts.map +1 -1
  43. package/dist/context/hook-pipeline.d.ts +5 -1
  44. package/dist/context/hook-pipeline.d.ts.map +1 -1
  45. package/dist/context/hook-pipeline.js +4 -4
  46. package/dist/context/hook-pipeline.js.map +1 -1
  47. package/dist/context/index.d.ts +5 -0
  48. package/dist/context/index.d.ts.map +1 -1
  49. package/dist/context/index.js +64 -13
  50. package/dist/context/index.js.map +1 -1
  51. package/dist/context/write-pipeline.d.ts.map +1 -1
  52. package/dist/context/write-pipeline.js +35 -15
  53. package/dist/context/write-pipeline.js.map +1 -1
  54. package/dist/contract/fixtures/contract-configs.d.ts +5 -0
  55. package/dist/contract/fixtures/contract-configs.d.ts.map +1 -1
  56. package/dist/contract/fixtures/contract-configs.js +21 -0
  57. package/dist/contract/fixtures/contract-configs.js.map +1 -1
  58. package/dist/contract/prisma.js +2 -2
  59. package/dist/contract/prisma.js.map +1 -1
  60. package/dist/extend.d.ts +1 -1
  61. package/dist/extend.d.ts.map +1 -1
  62. package/dist/fields/index.d.ts +12 -11
  63. package/dist/fields/index.d.ts.map +1 -1
  64. package/dist/fields/index.js +197 -62
  65. package/dist/fields/index.js.map +1 -1
  66. package/dist/filter/collect.d.ts +29 -0
  67. package/dist/filter/collect.d.ts.map +1 -1
  68. package/dist/filter/collect.js +100 -9
  69. package/dist/filter/collect.js.map +1 -1
  70. package/dist/filter/index.d.ts +7 -5
  71. package/dist/filter/index.d.ts.map +1 -1
  72. package/dist/filter/index.js +6 -14
  73. package/dist/filter/index.js.map +1 -1
  74. package/dist/filter/map.d.ts +108 -20
  75. package/dist/filter/map.d.ts.map +1 -1
  76. package/dist/filter/map.js +235 -49
  77. package/dist/filter/map.js.map +1 -1
  78. package/dist/filter/parse.d.ts +70 -26
  79. package/dist/filter/parse.d.ts.map +1 -1
  80. package/dist/filter/parse.js +212 -79
  81. package/dist/filter/parse.js.map +1 -1
  82. package/dist/filter/record-id.d.ts +19 -0
  83. package/dist/filter/record-id.d.ts.map +1 -0
  84. package/dist/filter/record-id.js +37 -0
  85. package/dist/filter/record-id.js.map +1 -0
  86. package/dist/filter/serialize.d.ts +45 -19
  87. package/dist/filter/serialize.d.ts.map +1 -1
  88. package/dist/filter/serialize.js +146 -50
  89. package/dist/filter/serialize.js.map +1 -1
  90. package/dist/filter/types.d.ts +132 -21
  91. package/dist/filter/types.d.ts.map +1 -1
  92. package/dist/filter/types.js +2 -11
  93. package/dist/filter/types.js.map +1 -1
  94. package/dist/hooks/index.d.ts +2 -2
  95. package/dist/hooks/index.d.ts.map +1 -1
  96. package/dist/hooks/index.js +4 -3
  97. package/dist/hooks/index.js.map +1 -1
  98. package/dist/index.d.ts +3 -3
  99. package/dist/index.d.ts.map +1 -1
  100. package/dist/index.js +1 -1
  101. package/dist/index.js.map +1 -1
  102. package/dist/internal.d.ts +7 -1
  103. package/dist/internal.d.ts.map +1 -1
  104. package/dist/internal.js +5 -4
  105. package/dist/internal.js.map +1 -1
  106. package/dist/lib/database-errors.d.ts +2 -1
  107. package/dist/lib/database-errors.d.ts.map +1 -1
  108. package/dist/lib/database-errors.js +5 -4
  109. package/dist/lib/database-errors.js.map +1 -1
  110. package/dist/mcp/field-schema.d.ts.map +1 -1
  111. package/dist/mcp/field-schema.js +13 -2
  112. package/dist/mcp/field-schema.js.map +1 -1
  113. package/dist/mcp/handler.d.ts.map +1 -1
  114. package/dist/mcp/handler.js +68 -19
  115. package/dist/mcp/handler.js.map +1 -1
  116. package/dist/mcp/projection.d.ts +6 -5
  117. package/dist/mcp/projection.d.ts.map +1 -1
  118. package/dist/mcp/projection.js +11 -8
  119. package/dist/mcp/projection.js.map +1 -1
  120. package/dist/mcp/reachability.d.ts +9 -0
  121. package/dist/mcp/reachability.d.ts.map +1 -0
  122. package/dist/mcp/reachability.js +32 -0
  123. package/dist/mcp/reachability.js.map +1 -0
  124. package/dist/mcp/where-reachability.d.ts +8 -0
  125. package/dist/mcp/where-reachability.d.ts.map +1 -0
  126. package/dist/mcp/where-reachability.js +72 -0
  127. package/dist/mcp/where-reachability.js.map +1 -0
  128. package/dist/query/relationship-options.d.ts +6 -0
  129. package/dist/query/relationship-options.d.ts.map +1 -1
  130. package/dist/query/relationship-options.js +16 -3
  131. package/dist/query/relationship-options.js.map +1 -1
  132. package/dist/secured/include.d.ts +14 -1
  133. package/dist/secured/include.d.ts.map +1 -1
  134. package/dist/secured/include.js +11 -7
  135. package/dist/secured/include.js.map +1 -1
  136. package/dist/secured/lock.d.ts +8 -2
  137. package/dist/secured/lock.d.ts.map +1 -1
  138. package/dist/secured/lock.js +44 -15
  139. package/dist/secured/lock.js.map +1 -1
  140. package/dist/secured/lower.d.ts.map +1 -1
  141. package/dist/secured/lower.js +17 -4
  142. package/dist/secured/lower.js.map +1 -1
  143. package/dist/secured/read.d.ts +65 -7
  144. package/dist/secured/read.d.ts.map +1 -1
  145. package/dist/secured/read.js +115 -54
  146. package/dist/secured/read.js.map +1 -1
  147. package/dist/validation/config-refusal.d.ts +1 -1
  148. package/dist/validation/config-refusal.d.ts.map +1 -1
  149. package/dist/validation/database-config.d.ts +0 -15
  150. package/dist/validation/database-config.d.ts.map +1 -1
  151. package/dist/validation/database-config.js +32 -1
  152. package/dist/validation/database-config.js.map +1 -1
  153. package/dist/validation/relations.d.ts.map +1 -1
  154. package/dist/validation/relations.js +11 -0
  155. package/dist/validation/relations.js.map +1 -1
  156. package/dist/validation/schema.d.ts +3 -3
  157. package/dist/validation/schema.d.ts.map +1 -1
  158. package/dist/validation/schema.js +4 -4
  159. package/dist/validation/schema.js.map +1 -1
  160. package/package.json +10 -10
@@ -1,3 +1,6 @@
1
+ import { filterQueryTokens, parseFilterQuery } from './parse.js';
2
+ import { filterValueRecordId } from './record-id.js';
3
+ import { serializeFilterQuery, serializeFilterToken } from './serialize.js';
1
4
  /**
2
5
  * A Where fragment an `AND` chain can carry that never matches a row. `NOT`
3
6
  * on an empty predicate: the empty predicate resolves to the vacuous,
@@ -11,69 +14,252 @@
11
14
  */
12
15
  const NEVER_MATCHES = { NOT: {} };
13
16
  /**
14
- * Map parsed {@link FilterToken}s to a single Prisma `where` fragment, given the
15
- * fields' {@link FilterSpec}s (ADR-0017).
17
+ * Whether a {@link FilterToken} was written with no characters at all (`role:`,
18
+ * `""`, `a:,`, or no values). Such a token is incomplete input and filters
19
+ * nothing (#1509). An `empty` token (`field:!`) carries no values and is not one.
20
+ */
21
+ export function isEmptyFilterToken(token) {
22
+ return token.operator !== 'empty' && token.values.every((value) => value.text === '');
23
+ }
24
+ /**
25
+ * Whether a field whose Filter spec declares `operators` takes an inclusive
26
+ * `range` token: it compares both ways, with `gte` and `lte`.
27
+ */
28
+ export function supportsFilterRange(operators) {
29
+ return operators.includes('gte') && operators.includes('lte');
30
+ }
31
+ /**
32
+ * The token operators a field whose Filter spec declares `operators` accepts
33
+ * on its values: its own, and `range` when it {@link supportsFilterRange}.
34
+ */
35
+ export function filterTokenOperators(operators) {
36
+ return supportsFilterRange(operators) ? [...operators, 'range'] : [...operators];
37
+ }
38
+ /**
39
+ * The token a field whose Filter spec declares `operators` actually maps: a
40
+ * `range` token (`field:a..b`) on a field that does not
41
+ * {@link supportsFilterRange} keeps the meaning it had before ranges existed,
42
+ * `eq` on its literal `a..b`, negated or not. Any other token is returned as
43
+ * it is.
44
+ */
45
+ export function effectiveFilterToken(token, operators) {
46
+ if (token.operator !== 'range' || supportsFilterRange(operators))
47
+ return token;
48
+ const text = token.values.map((value) => value.text).join('..');
49
+ return { ...token, operator: 'eq', values: [{ text, quoted: false }] };
50
+ }
51
+ /**
52
+ * Whether a {@link FilterToken} is a field condition the engine maps through
53
+ * its field's Filter spec: not empty, and naming a field that, as `fieldFor`
54
+ * reports it, supports the token's operator, or can be empty for an `empty`
55
+ * token. A `range` token needs exactly two non-empty bounds, and on a field
56
+ * that takes no range it is that field's `eq` on the literal `a..b` (see
57
+ * {@link effectiveFilterToken}). Negation and several values are composed
58
+ * around the field's own condition, so neither decides this. Any other token
59
+ * is searched as free text.
60
+ */
61
+ export function isFieldConditionToken(token, fieldFor) {
62
+ if (token.field === null || isEmptyFilterToken(token))
63
+ return false;
64
+ const capabilities = fieldFor(token.field);
65
+ if (!capabilities)
66
+ return false;
67
+ if (token.operator === 'empty')
68
+ return capabilities.canBeEmpty === true;
69
+ if (token.operator !== 'range')
70
+ return capabilities.operators.includes(token.operator);
71
+ if (token.values.length !== 2 || token.values.some((value) => value.text === ''))
72
+ return false;
73
+ return supportsFilterRange(capabilities.operators) || capabilities.operators.includes('eq');
74
+ }
75
+ /**
76
+ * The one free-text word a {@link FilterToken} is searched as when it cannot
77
+ * map to a field condition, and the text the Filter builder's chip shows for it.
78
+ *
79
+ * - A positive field token searches its values, written as one comma list
80
+ * with the field name dropped: `nosuchfield:Findable` is `Findable`, and
81
+ * `status:draft,bogus` is `draft,bogus`. A positive `range` token searches
82
+ * its literal `a..b`.
83
+ * - A negated token, or a `field:!`, searches its whole serialised literal
84
+ * (`-secret:x`), so a token that cannot map is never negated.
85
+ * - A bare word searches its own text.
86
+ */
87
+ export function filterTokenFreeTextWord(token) {
88
+ if (token.negated || token.operator === 'empty')
89
+ return serializeFilterToken(token);
90
+ if (token.operator === 'range')
91
+ return token.values.map((value) => value.text).join('..');
92
+ return token.values
93
+ .map((value) => value.text)
94
+ .filter((text) => text !== '')
95
+ .join(',');
96
+ }
97
+ function anyOf(conditions) {
98
+ return conditions.length === 1 ? conditions[0] : { OR: conditions };
99
+ }
100
+ function rangeCondition(token, spec) {
101
+ if (token.values.length !== 2)
102
+ return null;
103
+ const [low, high] = token.values;
104
+ if (low.text === '' || high.text === '')
105
+ return null;
106
+ const lower = spec.toCondition('gte', low.text);
107
+ const upper = lower === null ? null : spec.toCondition('lte', high.text);
108
+ return lower === null || upper === null ? null : { AND: [lower, upper] };
109
+ }
110
+ function valuesCondition(token, operator, spec) {
111
+ const conditions = [];
112
+ for (const value of token.values) {
113
+ if (value.text === '')
114
+ continue;
115
+ const recordId = operator === 'eq' ? filterValueRecordId(value) : null;
116
+ const condition = recordId !== null && spec.toIdCondition
117
+ ? spec.toIdCondition(recordId)
118
+ : spec.toCondition(operator, value.text);
119
+ if (condition === null)
120
+ return null;
121
+ conditions.push(condition);
122
+ }
123
+ return conditions.length === 0 ? null : anyOf(conditions);
124
+ }
125
+ function fieldCondition(written, spec) {
126
+ const token = effectiveFilterToken(written, spec.operators);
127
+ if (token.operator === 'empty') {
128
+ if (spec.empty === undefined)
129
+ return null;
130
+ return token.negated ? { NOT: spec.empty } : spec.empty;
131
+ }
132
+ const matched = token.operator === 'range'
133
+ ? rangeCondition(token, spec)
134
+ : spec.operators.includes(token.operator)
135
+ ? valuesCondition(token, token.operator, spec)
136
+ : null;
137
+ if (matched === null)
138
+ return null;
139
+ if (!token.negated)
140
+ return matched;
141
+ const excluded = { NOT: matched };
142
+ return spec.empty === undefined || spec.negation !== undefined
143
+ ? excluded
144
+ : { OR: [excluded, spec.empty] };
145
+ }
146
+ /**
147
+ * Map a parsed {@link FilterQuery} to a single Where fragment, given the
148
+ * fields' {@link FilterSpec}s (ADR-0017, ADR-0083).
16
149
  *
17
150
  * Pure — no DB/Prisma imports. This is the unit-tested half of the filter seam.
18
- * Tokens combine with implicit AND. An empty-value token (`role:` or a bare
19
- * `""`) is a deliberate no-op — incomplete input expresses no constraint, so it
20
- * contributes nothing and is never handed to a free-text field (#1509). A
21
- * token with a value degrades to free text (never an error) when its field is
22
- * unknown, has no spec, uses an unsupported operator, or maps to `null`. Bare
23
- * words (and degraded tokens) are OR-matched across every free-text field, and
24
- * each such word is ANDed with the rest — so `beta gamma` requires both. A word
25
- * that reaches this stage but cannot be matched against any free-text field —
26
- * because the list has none, or because every free-text field's own mapping
27
- * rejects it — narrows the chain to {@link NEVER_MATCHES} instead of being
28
- * dropped: a condition that cannot be honoured must never widen the result set
29
- * (#1356).
151
+ * Terms combine with implicit AND. An empty token is a deliberate no-op —
152
+ * incomplete input expresses no constraint, so it contributes nothing and is
153
+ * never handed to a free-text field (#1509), and an empty value inside a list
154
+ * (`a:x,`) is skipped the same way.
155
+ *
156
+ * The engine composes around each field's own `toCondition`:
157
+ *
158
+ * - `field:a,b` ORs the field's condition once per value.
159
+ * - `-field:value` is `NOT` of that condition, ORed with the field's `empty`
160
+ * condition when it states one, so "is not" keeps the rows with no value.
161
+ * A spec stating a `negation` says `NOT` alone already does, and gets no `OR`.
162
+ * - `field:!` is the field's `empty` condition and `-field:!` its `NOT`.
163
+ * - `field:a..b` ANDs the field's own `gte` on `a` and `lte` on `b`, on any
164
+ * field comparing both ways, and `-field:a..b` is `NOT` of that, composed
165
+ * like any other negation. On a field that takes no range it is that
166
+ * field's `eq` on the literal `a..b`, as it was before ranges existed
167
+ * ({@link effectiveFilterToken}).
168
+ * - An unquoted `#id` value on a field whose spec has `toIdCondition` maps
169
+ * through it instead, matching exactly that related record, so
170
+ * `field:#a,#b` matches either and `-field:#id` excludes it. An id the
171
+ * related list cannot hold makes the token free text.
172
+ *
173
+ * A token that cannot map in any part (an unknown or unreadable field, an
174
+ * unsupported operator, a value the field rejects, any one value of a list, or
175
+ * `field:!` on a field that cannot be empty, or either bound of a range) is
176
+ * searched as one free-text word,
177
+ * {@link filterTokenFreeTextWord}, which is also what the Filter builder's chip
178
+ * shows. A positive token searches its values with the field name dropped
179
+ * (`status:draft,bogus` searches `draft,bogus`); a negated one searches its
180
+ * whole literal (`-secret:x`) and is never negated, because `NOT` of free text
181
+ * would turn a field the session cannot read into a filter. A free-text token
182
+ * is read as its serialised form reads back, so a structured one with several
183
+ * values is the words its URL holds. A `range` token is read the same way, so
184
+ * one whose bounds cannot be written `a..b` is the literal `"a..b"` its URL
185
+ * holds.
186
+ *
187
+ * An OR group, `(a OR b)`, is the `OR` of its tokens, each mapped exactly as
188
+ * it would be on its own and negated by the same rules. A token in a group
189
+ * that cannot map stays in place as its free-text alternative, never dropped,
190
+ * so it can only add rows the free-text search finds; an empty token in a
191
+ * group is skipped, and a group of nothing but empty tokens filters nothing.
192
+ *
193
+ * Bare words (and degraded tokens) are OR-matched across every free-text
194
+ * field, and each such word is ANDed with the rest — so `beta gamma` requires
195
+ * both. A word that cannot be matched against any free-text field — because
196
+ * the list has none, or because every free-text field's own mapping rejects
197
+ * it — narrows the chain to {@link NEVER_MATCHES} instead of being dropped: a
198
+ * condition that cannot be honoured must never widen the result set (#1356).
30
199
  *
31
- * @param tokens Parsed tokens from {@link parseFilterQuery}.
32
- * @param specs Field-name → Filter spec (from {@link collectFilterSpecs}).
33
- * @returns A Prisma `where` fragment, or `undefined` when nothing filters.
200
+ * @param query The structured query from {@link parseFilterQuery}.
201
+ * @param specs Field-name → Filter spec (from {@link collectFilterSpecs}).
202
+ * @returns A Where fragment, or `undefined` when nothing filters.
34
203
  */
35
- export function buildFilterWhere(tokens, specs) {
36
- const andConditions = [];
37
- const freeTextWords = [];
204
+ export function buildFilterWhere(query, specs) {
205
+ const fieldConditions = [];
206
+ const textConditions = [];
38
207
  const freeTextFields = Object.keys(specs).filter((field) => specs[field].freeText);
39
- for (const token of tokens) {
208
+ const specFor = (field) => Object.hasOwn(specs, field) ? specs[field] : undefined;
209
+ const freeText = (word) => {
210
+ const conditions = freeTextFields
211
+ .map((field) => specs[field].toCondition('eq', word))
212
+ .filter((condition) => condition !== null);
213
+ return conditions.length > 0 ? anyOf(conditions) : NEVER_MATCHES;
214
+ };
215
+ const tokenCondition = (token) => {
216
+ const spec = token.field === null ? undefined : specFor(token.field);
217
+ return spec === undefined ? null : fieldCondition(token, spec);
218
+ };
219
+ const groupCondition = (term) => {
220
+ const alternatives = term.tokens
221
+ .filter((token) => !isEmptyFilterToken(token))
222
+ .map((token) => tokenCondition(token) ?? freeText(filterTokenFreeTextWord(token)));
223
+ return alternatives.length === 0 ? null : anyOf(alternatives);
224
+ };
225
+ const addToken = (token) => {
40
226
  // An empty value is incomplete input, not a constraint the engine failed
41
227
  // to honour: `role:` (or a bare `""`) says nothing to filter on, so it is
42
228
  // inert by design rather than narrowed away (#1509). This must be checked
43
- // before a token ever reaches `freeTextWords` — an empty value degrading
44
- // through the free-text path would call `toCondition('eq', '')`, and a
45
- // `contains`-style mapping over `''` matches every row, not none. That is
46
- // the opposite of #1356's narrow-on-failure rule, which only ever applies
47
- // to a token that DOES carry a value the system cannot compile.
48
- if (token.value === '')
49
- continue;
50
- if (token.field === null) {
51
- freeTextWords.push(token.value);
52
- continue;
53
- }
54
- const spec = Object.hasOwn(specs, token.field) ? specs[token.field] : undefined;
55
- if (!spec || !spec.operators.includes(token.operator)) {
56
- freeTextWords.push(token.value);
57
- continue;
229
+ // before a token ever reaches the free-text path — an empty value there
230
+ // would call `toCondition('eq', '')`, and a `contains`-style mapping over
231
+ // `''` matches every row, not none. That is the opposite of #1356's
232
+ // narrow-on-failure rule, which only ever applies to a token that DOES
233
+ // carry a value the system cannot compile.
234
+ if (isEmptyFilterToken(token))
235
+ return;
236
+ const condition = tokenCondition(token);
237
+ if (condition !== null)
238
+ fieldConditions.push(condition);
239
+ else
240
+ textConditions.push(freeText(filterTokenFreeTextWord(token)));
241
+ };
242
+ const addTerm = (term) => {
243
+ if (term.kind === 'token') {
244
+ addToken(term);
245
+ return;
58
246
  }
59
- const condition = spec.toCondition(token.operator, token.value);
60
- if (condition === null) {
61
- freeTextWords.push(token.value);
62
- continue;
247
+ const condition = groupCondition(term);
248
+ if (condition !== null)
249
+ fieldConditions.push(condition);
250
+ };
251
+ for (const term of query.terms) {
252
+ if (term.kind === 'group' || term.operator === 'range') {
253
+ parseFilterQuery(serializeFilterQuery({ terms: [term] })).terms.forEach(addTerm);
63
254
  }
64
- andConditions.push(condition);
65
- }
66
- for (const word of freeTextWords) {
67
- const orConditions = freeTextFields
68
- .map((field) => specs[field].toCondition('eq', word))
69
- .filter((condition) => condition !== null);
70
- if (orConditions.length > 0) {
71
- andConditions.push(orConditions.length === 1 ? orConditions[0] : { OR: orConditions });
255
+ else if (term.field === null) {
256
+ filterQueryTokens(parseFilterQuery(serializeFilterToken(term))).forEach(addToken);
72
257
  }
73
258
  else {
74
- andConditions.push(NEVER_MATCHES);
259
+ addToken(term);
75
260
  }
76
261
  }
262
+ const andConditions = [...fieldConditions, ...textConditions];
77
263
  if (andConditions.length === 0)
78
264
  return undefined;
79
265
  if (andConditions.length === 1)
@@ -1 +1 @@
1
- {"version":3,"file":"map.js","sourceRoot":"","sources":["../../src/filter/map.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,aAAa,GAAoB,EAAE,GAAG,EAAE,EAAE,EAAE,CAAA;AAElD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,gBAAgB,CAC9B,MAAqB,EACrB,KAAiC;IAEjC,MAAM,aAAa,GAAsB,EAAE,CAAA;IAC3C,MAAM,aAAa,GAAa,EAAE,CAAA;IAElC,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAA;IAElF,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,yEAAyE;QACzE,0EAA0E;QAC1E,0EAA0E;QAC1E,yEAAyE;QACzE,uEAAuE;QACvE,0EAA0E;QAC1E,0EAA0E;QAC1E,gEAAgE;QAChE,IAAI,KAAK,CAAC,KAAK,KAAK,EAAE;YAAE,SAAQ;QAEhC,IAAI,KAAK,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC;YACzB,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YAC/B,SAAQ;QACV,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SA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,CAAC,IAAI,CAAC,CAAA;QAChB,CAAC;IACH,CAAC;IAED,MAAM,aAAa,GAAG,CAAC,GAAG,eAAe,EAAE,GAAG,cAAc,CAAC,CAAA;IAC7D,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAA;IAChD,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,aAAa,CAAC,CAAC,CAAC,CAAA;IACvD,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,CAAA;AAC/B,CAAC"}
@@ -1,33 +1,77 @@
1
- import type { FilterToken } from './types.js';
1
+ import type { FilterGroup, FilterOperator, FilterQuery, FilterTerm, FilterToken } from './types.js';
2
+ /** The keyword joining the tokens of an OR group: `(a OR b)`. */
3
+ export declare const FILTER_GROUP_KEYWORD = "OR";
2
4
  /**
3
- * Parse a filter query string into {@link FilterToken}s (ADR-0017 grammar).
4
- *
5
- * Pure and field-agnostic: it recognises the *syntax* (field prefix, comparison
6
- * operator, quoted value, bare word) but never validates field names or values
7
- * — that is the mapping step's job, where unknown/unmappable tokens degrade to
8
- * free text. This parser therefore never throws; malformed input simply parses
9
- * as bare free-text words.
5
+ * The prefix each {@link FilterOperator} is written with after `field:`: none
6
+ * for `eq`, and `>`, `>=`, `<`, `<=` for the comparisons.
7
+ */
8
+ export declare const FILTER_OPERATOR_PREFIXES: Readonly<Record<FilterOperator, string>>;
9
+ /**
10
+ * Every comparison prefix and its operator, longest prefix first, so a reader
11
+ * matching them in order takes `>=` before `>`.
12
+ */
13
+ export declare const FILTER_COMPARISON_PREFIXES: ReadonlyArray<readonly [string, FilterOperator]>;
14
+ export declare function isFilterWhitespace(ch: string): boolean;
15
+ /**
16
+ * The length of the field prefix (`name:`) at `start` in `text`, or `0` when
17
+ * there is none. A `word:` followed by `//` is a URL scheme, not a field.
18
+ */
19
+ export declare function fieldPrefixLength(text: string, start?: number): number;
20
+ /**
21
+ * The two bounds of an unquoted single value written as an inclusive range
22
+ * (`a..b`), split at its first `..`, or `null` when it is not one: a bound is
23
+ * missing, or the value holds a comma.
24
+ */
25
+ export declare function splitRangeValue(value: string): [string, string] | null;
26
+ export interface FilterRead<T> {
27
+ value: T;
28
+ end: number;
29
+ }
30
+ export declare function readFilterGroup(query: string, start: number): FilterRead<FilterGroup> | null;
31
+ /**
32
+ * Parse a filter query string into a structured {@link FilterQuery}
33
+ * (ADR-0017, ADR-0083). Never throws: input it cannot read as syntax parses as
34
+ * bare free-text words.
10
35
  *
11
- * Grammar:
12
- * - `field:value` → a field token with the `eq` operator.
13
- * - `field:>value`, `field:>=value`, `field:<value`, `field:<=value` →
14
- * comparison operators.
15
- * - `field:"multi word"` / bare `"multi word"` → quoted values keep spaces.
16
- * - anything else (`beta`, `>5`) → a bare free-text token (`field: null`).
36
+ * - `field:value` is a field token with the `eq` operator, and `field:>value`,
37
+ * `field:>=value`, `field:<value`, `field:<=value` are comparisons.
38
+ * - `field:a,b` carries several values, and `field:!` is the `empty` operator.
39
+ * - `field:a..b` is an inclusive `range` token whose two values are its
40
+ * bounds, split at the first `..`. A quoted value is never a range, and
41
+ * neither is a list: `field:a..b,c` is `eq` on `a..b` and `c`.
42
+ * - A leading `-` followed by more of the token negates it: `-field:value`.
43
+ * A `-` on its own is a free-text word.
44
+ * - `(a OR b)` is an OR group of the tokens `a` and `b`: `(` directly before
45
+ * the first token, the uppercase keyword `OR` between tokens, and `)`
46
+ * directly after the last. No member may hold an unquoted parenthesis of its
47
+ * own. Anything else, such as a lowercase `or`, a nested, inner or
48
+ * unmatched parenthesis (`(a OR f(x) y)`), or a group of one token, reads as
49
+ * it would without the group: literal words.
50
+ * - A value in double quotes keeps its spaces and commas and is literal:
51
+ * `"status:draft"` and `"OR"` are free-text words and `field:"!"` the text
52
+ * `!`. Inside quotes, `\"` is a quote and `\\` a backslash; any other
53
+ * backslash is itself.
54
+ * - Anything else (`beta`, `>5`, `http://x`) is a free-text word (`field: null`),
55
+ * whose commas are ordinary characters.
17
56
  *
18
- * A `word:` is *not* treated as a field prefix when the colon is immediately
19
- * followed by `//` (a URL scheme like `http://x` or `https://…`); the whole
20
- * token stays free text so a pasted URL is searched verbatim rather than
21
- * mangled into `{ field: 'http', value: '//x' }`.
57
+ * Validating fields and values is the engine's job, where a token that cannot
58
+ * map degrades to free text. {@link serializeFilterQuery} is the inverse.
22
59
  *
23
60
  * @example
24
- * parseFilterQuery('role:Editor orders:>5 name:"Ada Lovelace" beta')
25
- * // [
26
- * // { field: 'role', operator: 'eq', value: 'Editor', raw: 'role:Editor' },
27
- * // { field: 'orders', operator: 'gt', value: '5', raw: 'orders:>5' },
28
- * // { field: 'name', operator: 'eq', value: 'Ada Lovelace', raw: 'name:"Ada Lovelace"' },
29
- * // { field: null, operator: 'eq', value: 'beta', raw: 'beta' },
30
- * // ]
61
+ * parseFilterQuery('-role:Editor (status:draft OR author:#42) name:"Ada Lovelace" beta')
62
+ * // { terms: [
63
+ * // { kind: 'token', field: 'role', operator: 'eq', negated: true, values: [{ text: 'Editor', quoted: false }] },
64
+ * // { kind: 'group', tokens: [
65
+ * // { kind: 'token', field: 'status', operator: 'eq', negated: false, values: [{ text: 'draft', quoted: false }] },
66
+ * // { kind: 'token', field: 'author', operator: 'eq', negated: false, values: [{ text: '#42', quoted: false }] },
67
+ * // ] },
68
+ * // { kind: 'token', field: 'name', operator: 'eq', negated: false, values: [{ text: 'Ada Lovelace', quoted: true }] },
69
+ * // { kind: 'token', field: null, operator: 'eq', negated: false, values: [{ text: 'beta', quoted: false }] },
70
+ * // ] }
31
71
  */
32
- export declare function parseFilterQuery(query: string): FilterToken[];
72
+ export declare function parseFilterQuery(query: string): FilterQuery;
73
+ /** The tokens of one {@link FilterTerm}: the token itself, or a group's tokens. */
74
+ export declare function filterTermTokens(term: FilterTerm): FilterToken[];
75
+ /** Every token of a {@link FilterQuery}, with its groups flattened, in order. */
76
+ export declare function filterQueryTokens(query: FilterQuery): FilterToken[];
33
77
  //# sourceMappingURL=parse.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/filter/parse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,WAAW,EAAE,MAAM,YAAY,CAAA;AAY7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,EAAE,CAwD7D"}
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/filter/parse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,WAAW,EACX,UAAU,EACV,WAAW,EAEZ,MAAM,YAAY,CAAA;AAYnB,iEAAiE;AACjE,eAAO,MAAM,oBAAoB,OAAO,CAAA;AAIxC;;;GAGG;AACH,eAAO,MAAM,wBAAwB,EAAE,QAAQ,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,CAM7E,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,0BAA0B,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,cAAc,CAAC,CAM1C,CAAA;AAE9C,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,SAAI,GAAG,MAAM,CAKjE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAItE;AAED,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,KAAK,EAAE,CAAC,CAAA;IACR,GAAG,EAAE,MAAM,CAAA;CACZ;AAiGD,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,GAAG,IAAI,CAsB5F;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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