Skip to content

Commit a721485

Browse files
committed
refactor(driver-sql, plugin-security): read the list-comparand split from the spec
Both modules kept a hand copy of the list operators ($in, $nin, $between). They now call isListComparandOperator from @objectstack/spec/data, the one source the comparand faces read. The copies equalled the spec set, so behaviour is unchanged. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JQwxbYnNFzqeb7KM8Lpd7j
1 parent 4d8095b commit a721485

4 files changed

Lines changed: 37 additions & 20 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/driver-sql': patch
3+
---
4+
5+
refactor(driver-sql): the comparand bind test reads the list operators from the spec
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The SQL driver bind-tests each member of a `$in`, `$nin` or `$between` list as a comparand in its own right. It now asks `isListComparandOperator` from `@objectstack/spec/data` which operators take a list, instead of keeping its own copy of `$in` / `$nin` / `$between`. The set is the same, so no filter compiles or is refused differently. A later change to the spec's list operators now reaches this driver without a second edit.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/plugin-security': patch
3+
---
4+
5+
refactor(plugin-security): the RLS stored-form check reads the list operators from the spec
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The RLS check puts a value comparand into its column's storage form, and a `$in`, `$nin` or `$between` list member by member. It now asks `isListComparandOperator` from `@objectstack/spec/data` which operators take a list, instead of keeping its own copy of `$in` / `$nin` / `$between`. The set is the same, so no policy filter is judged differently. A later change to the spec's list operators now reaches this check without a second edit.

‎packages/drivers/driver-sql/src/sql-driver.ts‎

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ import {
7272
isAcceptedFilterComparand,
7373
ACCEPTED_FILTER_COMPARAND_TYPES_SENTENCE,
7474
} from '@objectstack/spec/data';
75+
// [#29611] The operator split's list half (`$in` / `$nin` / `$between`): the
76+
// operators whose comparand is a LIST, so each member is bind-tested on its own
77+
// (see {@link assertCompilableComparand}). Asked of the spec, the one source the
78+
// comparand faces read, so this driver keeps no copy to drift from it.
79+
import { isListComparandOperator } from '@objectstack/spec/data';
7580
// [#7536] `$like`/`$ilike`'s pattern language, defined once in the spec: the
7681
// dangling-escape gate every face refuses on, and the LIKE→GLOB translation the
7782
// SQLite dialects need because GLOB is the only case-exact pattern operator
@@ -2487,7 +2492,7 @@ const CROSS_FIELD_COMPARISON_OPERATORS: ReadonlySet<string> = new Set([
24872492
* their own `whereIn` / `whereBetween` arms. Only their MEMBERS are inspected —
24882493
* for `$field` (#5041) and, since #5234, for bindability — never their arity:
24892494
* the existing descriptive `$between` refusal stays the one that answers a
2490-
* malformed range. See {@link LIST_COMPARAND_OPERATORS}.
2495+
* malformed range. See {@link isListComparandOperator}.
24912496
*/
24922497
const SCALAR_COMPARAND_OPERATORS: ReadonlySet<string> = new Set([
24932498
'$eq', '$ne', '$gt', '$gte', '$lt', '$lte',
@@ -2569,17 +2574,6 @@ const TEXT_OPERATORS: ReadonlySet<string> = new Set([
25692574
...LIKE_PATTERN_OPERATORS,
25702575
]);
25712576

2572-
/**
2573-
* [#5234] Operators for which an ARRAY is the legitimate comparand, so it is
2574-
* each MEMBER that must be individually compilable.
2575-
*
2576-
* Scoping the member scan to these three is what keeps a scalar operator that
2577-
* received an array answering with its own message ("requires a single
2578-
* comparable value") instead of reporting the first bad member of a list it
2579-
* should never have been given.
2580-
*/
2581-
const LIST_COMPARAND_OPERATORS: ReadonlySet<string> = new Set(['$in', '$nin', '$between']);
2582-
25832577
/**
25842578
* [#5234] Does this value have a faithful rendering as the text of a LIKE
25852579
* pattern?
@@ -2687,10 +2681,13 @@ function assertCompilableComparand(
26872681
if (nowAnchorOf(member) !== null) throw nowAnchorPositionError(field, op, member, index);
26882682
// [#5234] Every member of a list operator's array is a comparand in its
26892683
// own right and gets the same bind test the whole comparand gets. Scoped
2690-
// to the operators for which an array is legitimate, so a scalar operator
2691-
// handed an array keeps answering with its own message below.
2684+
// to the operators for which an array is legitimate (the spec's list
2685+
// half, {@link isListComparandOperator}), so a scalar operator handed an
2686+
// array keeps answering with its own message ("requires a single
2687+
// comparable value") instead of reporting the first bad member of a list
2688+
// it should never have been given.
26922689
// [#20039] The member when it is an object, else the list that holds it.
2693-
if (LIST_COMPARAND_OPERATORS.has(op) && !isBindableComparand(member)) {
2690+
if (isListComparandOperator(op) && !isBindableComparand(member)) {
26942691
throw unbindableListMemberError(field, op, member, index, refusalSubtree(member, value));
26952692
}
26962693
}

‎packages/plugins/plugin-security/src/rls-check-stored-form.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ import {
163163
INSTANT_TYPES,
164164
STRUCTURED_JSON_TYPES,
165165
filterSubtreeProvenanceOf,
166+
isListComparandOperator,
166167
isMultiValueField,
167168
markFilterSubtreeProvenance,
168169
} from '@objectstack/spec/data';
@@ -179,15 +180,14 @@ const NO_MULTI_VALUE_COLUMNS: DeclaredMultiValueColumns = new Set();
179180
/**
180181
* The operators whose comparand is a VALUE of the column, compared with the
181182
* stored value. The drivers put these comparands into the column's storage
182-
* form; every other operator's operand is left as written.
183+
* form; every other operator's operand is left as written. Which of them take
184+
* a LIST of values is the spec's answer ({@link isListComparandOperator}), not
185+
* a copy kept here.
183186
*/
184187
const VALUE_COMPARISON_OPERATORS: ReadonlySet<string> = new Set([
185188
'$eq', '$ne', '$gt', '$gte', '$lt', '$lte', '$in', '$nin', '$between',
186189
]);
187190

188-
/** The value-comparison operators whose comparand is a LIST of values. */
189-
const LIST_COMPARAND_OPERATORS: ReadonlySet<string> = new Set(['$in', '$nin', '$between']);
190-
191191
/** The storage rule a declared type takes, or `undefined` for a non-temporal type. */
192192
function temporalKindOfDeclaredType(type: string): TemporalComparandKind | undefined {
193193
if (CALENDAR_DATE_TYPES.has(type)) return 'date';
@@ -412,7 +412,7 @@ function storedComparand(value: unknown, kind: TemporalComparandKind): unknown {
412412

413413
/** A value-comparison operand in its column's storage form, a list member by member. */
414414
function storedOperand(op: string, value: unknown, kind: TemporalComparandKind): unknown {
415-
if (!LIST_COMPARAND_OPERATORS.has(op) || !Array.isArray(value)) return storedComparand(value, kind);
415+
if (!isListComparandOperator(op) || !Array.isArray(value)) return storedComparand(value, kind);
416416
let copy: unknown[] | undefined;
417417
value.forEach((member, index) => {
418418
const stored = storedComparand(member, kind);

0 commit comments

Comments
 (0)