Skip to content

Commit df8d020

Browse files
feat(spec): export isListComparandOperator from @objectstack/spec/data; flow record nodes read it instead of a local copy (#29570)
<!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ83ALm8EpEcYUomnqmETUEW1)_ Fixes #29419 Clause-②: yes Metadata-protocol: none ## 维护者速读 - 改了什么:`@objectstack/spec/data` 新增导出谓词 `isListComparandOperator(op)`,对声明列表比较值的字段运算符(`$in` / `$nin` / `$between`)答 true,其余答 false;流程记录节点(`crud-nodes.ts`)改为导入它,删掉本地那份 `LIST_COMPARAND_OPERATORS` 副本及其对账测试。 - 为什么改:#29404 的合约评审 should-fix 2:执行器持有一份运算符拆分的副本,靠一条行为对账测试保持一致;现在只有 spec 一处来源,对账断言随谓词搬进 `packages/spec`。 - 风险与回滚:纯新增导出(加宽),执行器的接受与拒绝行为不变;两份集合本身仍不导出。回滚即撤销本 PR。 - 先看:`packages/spec/src/data/filter-comparand-operators.ts`(谓词与改写的模块说明),`packages/spec/src/data/filter-comparand-operators.test.ts`(对账断言的新家),`packages/services/service-automation/src/builtin/crud-nodes.ts`(导入替换)。 - 两分钟验证:`pnpm --filter @objectstack/spec exec vitest run src/data/filter-comparand-operators.test.ts`,预期 1 个测试文件、2 个用例全部通过。 - 需要你做的:无,席位落地。 ## What changes - **`isListComparandOperator(op: string): boolean`** (`packages/spec/src/data/filter-comparand-operators.ts`), exported from `@objectstack/spec/data` (`packages/spec/src/data/index.ts`, a named re-export). It answers whether a `$`-spelled field operator declares a LIST comparand, reading the same `LIST_COMPARAND_OPERATORS` set the comparand-type face reads. TSDoc is one sentence. - **Why a predicate and not the set.** The card allows either. A published `ReadonlySet` is still a live `Set` at run time: a caller that cast and mutated it would change what every comparand face in `packages/spec` judges. The predicate publishes the answer and keeps both sets module-private. The module docblock's section "Why it is NOT in the `data` barrel" is rewritten to say what the barrel now publishes from the file and why the sets stay out. - **`packages/services/service-automation/src/builtin/crud-nodes.ts`**: `operandValueRefusal` asks `isListComparandOperator(last)`; the local `LIST_COMPARAND_OPERATORS` and its docblock are removed, and the function docblock names the spec predicate. An import swap, nothing else. - **Retired test**: `crud-filter-guard.test.ts` "every declared operator whose comparand is a list takes an evaluated list, and no other does", plus its now-unused `FieldOperatorsSchema` import. Its assertion, every operator `FieldOperatorsSchema` declares is a list operator exactly when its enforced slot takes a list, now lives in `packages/spec/src/data/filter-comparand-operators.test.ts`, against the predicate the executor calls. That is the same assertion at a layer closer to the code. The executor's own use of the predicate stays pinned by the file's remaining list-operator cases (see the ablation below). - **Generated**: `packages/spec/api-surface/data.json` and `packages/spec/export-origins/data.json` gain the one row each. - **Changeset**: `.changeset/29419-list-comparand-operator-predicate.md`, `patch` for `@objectstack/spec` and `@objectstack/service-automation`, carrying both declaration lines. ## Tests - New `packages/spec/src/data/filter-comparand-operators.test.ts` (2 cases), importing through the `data` barrel: the predicate answers `true` exactly for each declared operator whose `FieldOperatorsSchema` slot accepts a two-item list (with a control that the grammar declares more than ten operators, and the derived list pinned to `$between`, `$in`, `$nin`), and `false` for undeclared spellings (`in`, `between`, `$and`, `$or`, `$not`, `$IN`, the empty string, `has`). - `crud-filter-guard.test.ts` loses the one retired case: 66 to 65. - **Forced test edits:** none beyond the retirement above. ## Acceptance notes - **Changeset level.** The claim assumed a spec minor. AGENTS.md Post-Task Checklist step 3 ties the level to `Metadata-protocol` alone, and `none` takes `patch`, so both packages ship `patch`. - **File surface addition.** The new spec test file is outside the claim's listed surface. It is where the retired reconciliation lands, so I added it here. - **Other local copies, not touched.** `packages/drivers/driver-sql/src/sql-driver.ts` and `packages/plugins/plugin-security/src/rls-check-stored-form.ts` each hold their own `LIST_COMPARAND_OPERATORS` (`$in`, `$nin`, `$between`). Both equal the spec set today, and neither is in this card's scope. Not filed: there is no defect, only a possible follow-up to read the new predicate. - `packages/spec/src/data/filter-comparand-shape.ts` keeps its own module-private `LIST_COMPARAND_OPERATORS` map (operator to authoring spellings). It is a different shape, unchanged. - No `protocol.ts` file is touched. ## Verification Readings on head `e5b9d970c` (`6e184de6c` merges `origin/main` `390bd2aed`, then the artifact regeneration), except where a line names `4cc2f8814`, the pre-merge head. <details><summary>Tests and typecheck</summary> - Under the verify lock on `4cc2f8814`: `turbo run build --filter='@objectstack/service-automation^...'` 31/31 tasks; `vitest run` in `packages/services/service-automation`: 262 files / 3394 tests passed; `pnpm --filter @objectstack/service-automation typecheck` exit 0 (`VERDICT command-exit 0`). - Under the verify lock on `e5b9d970c`: spec `filter-comparand-operators`, `filter-comparand-type`, `filter-comparand-shape` tests: 3 files, 166 passed, 1 todo; `crud-filter-guard.test.ts`: 65 passed; `pnpm --filter @objectstack/spec typecheck` and `pnpm --filter @objectstack/service-automation typecheck` exit 0 (`VERDICT command-exit 0`). - `pnpm --filter @objectstack/spec check:generated` after a spec build on `e5b9d970c`: all 14 artifacts up to date. - `test:repo` is not run locally (no file of that project changed); it is CI's `Test Core`. </details> <details><summary>Ablations</summary> Each through `scripts/ablation-replace.mjs` (anchor hit once, blob changed, restored to the HEAD blob, `git status` clean after), on `4cc2f8814`. Both tests import the code under test from source, so no `dist` leg applies. - `isListComparandOperator` made to answer `false` for `$between`: `filter-comparand-operators.test.ts` 1 failed / 1 passed of 2. - `crud-nodes.ts` made to treat `$nin` as a scalar operator: `crud-filter-guard.test.ts` 4 failed / 61 passed of 65 (the three "an evaluated list at a list operator's comparand passes" cases and the empty-entry refusal). </details> <details><summary>Derived gates</summary> - `node scripts/pm/dispatch-gates.mjs --commands` derived 84 families on `e5b9d970c`; all 84 ran there, each exit 0, with exit codes captured before any pipe. `--ran` reconciliation: "84 derived, 84 run, 0 NOT-MEASURED, 0 UNRUN", exit 0. - On `4cc2f8814` the same 84 ran. `check:dual-build-cjs-loads` exited 3 there (PREREQUISITE NOT MET: no `dist/` for packages outside this diff's closure), and `check-plugin-teardown-shape --self-test` exited 3 until its pinned fixture commit was fetched into the shallow clone, then exited 0. - The repo-wide families (`pnpm lint` first among them) are CI's. </details> Dogfood battery: not run (no `!` in the title and no `(narrowing)` arm). ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (The predicate is a constant lookup beside the constant it reads.) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` is CI's. - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. --- _Generated by [Claude Code](https://claude.ai/code/session_01JQwxbZwoKyGHFx3aiQohjE)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1a95c74 commit df8d020

8 files changed

Lines changed: 75 additions & 39 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/spec': patch
3+
'@objectstack/service-automation': patch
4+
---
5+
6+
feat(spec): `@objectstack/spec/data` exports `isListComparandOperator`, and a flow's record nodes read it instead of a local copy of the list operators
7+
8+
Clause-②: yes
9+
Metadata-protocol: none
10+
11+
- **`@objectstack/spec/data`** now exports `isListComparandOperator(op)`: `true` exactly for the field operators whose declared comparand is a list (`$in`, `$nin`, `$between`), `false` for every other spelling. It reads the same split the comparand-type and comparand-shape faces judge with, so a consumer that judges a comparand by its operator no longer keeps its own copy. The two operator sets behind it stay unexported.
12+
- **`@objectstack/service-automation`**: the `get_record`, `update_record` and `delete_record` nodes decide where an evaluated list is accepted in a filter with that predicate. Which operands are accepted or refused is unchanged.

‎packages/services/service-automation/src/builtin/crud-filter-guard.test.ts‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
44
import { VALUE_SLOT_TEMPLATE_REFUSAL } from '@objectstack/spec/automation';
5-
import { FieldOperatorsSchema } from '@objectstack/spec/data';
65
import { AutomationEngine } from '../engine.js';
76
import { registerCrudNodes } from './crud-nodes.js';
87
import { assertEngineFindOnePredicate } from '@objectstack/metadata-core';
@@ -395,22 +394,6 @@ describe('a computed filter operand is a value, never filter structure', () => {
395394
expect(data.seen[verb]).toEqual({ id: { $in: ['r1', 'r2'] }, stage: { $nin: ['lost', 'won'] }, amount: { $between: [10, 90] } });
396395
});
397396

398-
it('every declared operator whose comparand is a list takes an evaluated list, and no other does', async () => {
399-
const operators = Object.keys((FieldOperatorsSchema as unknown as { shape: Record<string, unknown> }).shape);
400-
expect(operators.length, 'control: the grammar declares its operators').toBeGreaterThan(10);
401-
const pair = ['2026-01-01', '2026-12-31'];
402-
for (const op of operators) {
403-
const takesList = FieldOperatorsSchema.safeParse({ [op]: pair }).success;
404-
data = fakeData();
405-
engine = new AutomationEngine(createTestLogger());
406-
registerCrudNodes(engine, ctxWith(data.service));
407-
engine.registerFlow('crud_flow', crudFlow('get_record', { objectName: 'deal', filter: { due: { [op]: CEL('record.pair') } } }));
408-
const result = await engine.execute('crud_flow', { record: { pair } } as any);
409-
expect(result.success, `${op}: the grammar ${takesList ? 'takes' : 'refuses'} a list there`).toBe(takesList);
410-
expect(data.seen.find, `${op}: the data engine was asked`).toEqual(takesList ? { due: { [op]: pair } } : undefined);
411-
}
412-
});
413-
414397
it.each(NODES)('%s: an evaluated scalar passes — a string, a number, a boolean and a date', async (nodeType, verb, extra) => {
415398
const { result } = await run(nodeType, {
416399
objectName: 'deal',

‎packages/services/service-automation/src/builtin/crud-nodes.ts‎

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type {
1717
DeleteRecordConfigParsed,
1818
} from '@objectstack/spec/automation';
1919
import type { AutomationContext, IDataEngine } from '@objectstack/spec/contracts';
20-
import { isAcceptedFilterComparand, type DroppedFieldsEvent } from '@objectstack/spec/data';
20+
import { isAcceptedFilterComparand, isListComparandOperator, type DroppedFieldsEvent } from '@objectstack/spec/data';
2121
import { StandardErrorCode } from '@objectstack/spec/api';
2222
import { isStoredMetadataBodyObject, STORED_METADATA_BODY_PRESCRIPTION } from '@objectstack/spec/kernel';
2323
import {
@@ -149,16 +149,6 @@ function resolveNodeFilter(
149149
return { filter };
150150
}
151151

152-
/**
153-
* The operators whose comparand is a LIST — the split
154-
* `@objectstack/spec`'s comparand faces read (`LIST_COMPARAND_OPERATORS` in
155-
* `data/filter-comparand-operators.ts`, kept out of the published barrel on
156-
* purpose). `crud-filter-guard.test.ts` reconciles this set against
157-
* `FieldOperatorsSchema`: every declared operator whose enforced slot takes a
158-
* list is here, and no other.
159-
*/
160-
const LIST_COMPARAND_OPERATORS: ReadonlySet<string> = new Set(['$in', '$nin', '$between']);
161-
162152
/**
163153
* What an evaluated filter operand is when it is NOT a value its position
164154
* takes, worded for the refusal (`an object`, `a list`, `a list whose entry
@@ -168,9 +158,9 @@ const LIST_COMPARAND_OPERATORS: ReadonlySet<string> = new Set(['$in', '$nin', '$
168158
* (`isAcceptedFilterComparand`, `@objectstack/spec/data`: a string, number,
169159
* bigint, boolean, `null` or `Date`); an operand that IS `null` never gets
170160
* here, the nothing guard owns it. At the comparand of a list operator
171-
* ({@link LIST_COMPARAND_OPERATORS}: the operand's path ends in that
172-
* operator) a list of such values is one too, provided no entry is `null`:
173-
* an entry that is nothing is refused as the nothing guard refuses an operand
161+
* (`isListComparandOperator`, `@objectstack/spec/data`: the operand's path
162+
* ends in that operator) a list of such values is one too, provided no entry
163+
* is `null`: an entry that is nothing is refused as the nothing guard refuses an operand
174164
* that is nothing, since it adds "the field is empty" to the condition, a
175165
* match the author never wrote. Every other position takes one
176166
* value: a field's implicit equality, a scalar operator's comparand, a list
@@ -184,7 +174,7 @@ function operandValueRefusal(value: unknown, path: readonly (string | number)[])
184174
if (isAcceptedFilterComparand(value)) return undefined;
185175
if (!Array.isArray(value)) return kindOfOperand(value);
186176
const last = path[path.length - 1];
187-
if (typeof last !== 'string' || !LIST_COMPARAND_OPERATORS.has(last)) return 'a list';
177+
if (typeof last !== 'string' || !isListComparandOperator(last)) return 'a list';
188178
const index = value.findIndex((member) => member === null || !isAcceptedFilterComparand(member));
189179
return index < 0 ? undefined : `a list whose entry [${index}] is ${kindOfOperand(value[index])}`;
190180
}

‎packages/spec/api-surface/data.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,7 @@
934934
"isInlineRowFormOffered (function)",
935935
"isKnownFilterToken (function)",
936936
"isLegacyApiMethod (function)",
937+
"isListComparandOperator (function)",
937938
"isMaskedOnReadFieldType (function)",
938939
"isMultiValueField (function)",
939940
"isNowDefaultToken (function)",

‎packages/spec/export-origins/data.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,7 @@
920920
"isInlineRowFormOffered": "src/data/inline-grid-columns.ts#isInlineRowFormOffered (function)",
921921
"isKnownFilterToken": "src/data/context-tokens.zod.ts#isKnownFilterToken (function)",
922922
"isLegacyApiMethod": "src/data/api-derivation.ts#isLegacyApiMethod (function)",
923+
"isListComparandOperator": "src/data/filter-comparand-operators.ts#isListComparandOperator (function)",
923924
"isMaskedOnReadFieldType": "src/data/masked-field-types.ts#isMaskedOnReadFieldType (function)",
924925
"isMultiValueField": "src/data/field-value.zod.ts#isMultiValueField (function)",
925926
"isNowDefaultToken": "src/data/default-value-tokens.ts#isNowDefaultToken (function)",
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* `isListComparandOperator`, the one piece of the operator split the `data`
5+
* barrel publishes. A consumer reads it instead of keeping its own copy of
6+
* the list half, so this file holds it to the enforced grammar: it answers
7+
* `true` exactly for the operators whose `FieldOperatorsSchema` slot accepts
8+
* a list, and a list operator added to the grammar reds here.
9+
*/
10+
11+
import { describe, it, expect } from 'vitest';
12+
import { FieldOperatorsSchema, isListComparandOperator } from './index';
13+
14+
describe('isListComparandOperator — the published list half of the operator split', () => {
15+
const declared = Object.keys(FieldOperatorsSchema.shape);
16+
17+
it('answers true exactly for every declared operator whose enforced slot takes a list', () => {
18+
expect(declared.length, 'control: the grammar declares its operators').toBeGreaterThan(10);
19+
const pair = ['2026-01-01', '2026-12-31'];
20+
for (const op of declared) {
21+
const takesList = FieldOperatorsSchema.safeParse({ [op]: pair }).success;
22+
expect(isListComparandOperator(op), `${op}: the grammar ${takesList ? 'takes' : 'refuses'} a list`).toBe(takesList);
23+
}
24+
expect(declared.filter(isListComparandOperator).sort()).toEqual(['$between', '$in', '$nin']);
25+
});
26+
27+
it('answers false for a spelling the grammar does not declare', () => {
28+
for (const op of ['in', 'between', '$and', '$or', '$not', '$IN', '', 'has']) {
29+
expect(isListComparandOperator(op), op).toBe(false);
30+
}
31+
});
32+
});

‎packages/spec/src/data/filter-comparand-operators.ts‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@
2121
* set to the schema's other half: every declared operator whose enforced slot
2222
* refuses an array.
2323
*
24-
* ## Why it is NOT in the `data` barrel
24+
* ## What the `data` barrel publishes from here: one predicate
2525
*
26-
* Nothing here is a contract a consumer calls; the faces are, and they are
27-
* already published (`normalizeFilterComparandTypes`,
28-
* `assertListComparandShapes`). Exporting the split would widen
29-
* `@objectstack/spec/data` for no reader, so this file stays out of
30-
* `./index.ts`, as `./filter-comparand-refusal-text.ts` does. It imports
31-
* nothing, so no face can reach a cycle through it.
26+
* The faces are the contract most consumers call, and they are published on
27+
* their own (`normalizeFilterComparandTypes`, `assertListComparandShapes`).
28+
* A consumer that judges a comparand by its operator without running a face
29+
* (a flow's record nodes take an evaluated list only at a list operator's
30+
* comparand) reads {@link isListComparandOperator}, so it holds no copy of
31+
* the split to drift. The barrel names that predicate alone: the two sets
32+
* stay module-private, because a published `ReadonlySet` is still a live
33+
* `Set` at run time, and a caller that cast and mutated it would change what
34+
* every face here judges. This file imports nothing, so no face can reach a
35+
* cycle through it.
3236
*/
3337

3438
/** The operators whose declared comparand is ONE literal. */
@@ -43,3 +47,11 @@ export const SCALAR_COMPARAND_OPERATORS: ReadonlySet<string> = new Set([
4347
export const LIST_COMPARAND_OPERATORS: ReadonlySet<string> = new Set([
4448
'$in', '$nin', '$between',
4549
]);
50+
51+
/**
52+
* Whether `op` (a `$`-spelled field operator) declares a LIST comparand
53+
* (`$in`, `$nin`, `$between`); `false` for every other spelling.
54+
*/
55+
export function isListComparandOperator(op: string): boolean {
56+
return LIST_COMPARAND_OPERATORS.has(op);
57+
}

‎packages/spec/src/data/index.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ export * from './filter-comparand-type';
2121
// `assertListComparandShapes` now delegates here and `parseFilterAST` enforces
2222
// it for every direct driver caller too.
2323
export * from './filter-comparand-shape';
24+
// Which field operators declare a LIST comparand (`$in`, `$nin`, `$between`),
25+
// as a predicate over the split both faces above read, for a consumer that
26+
// judges a comparand by its operator without running a face. The two sets
27+
// themselves stay module-private (the module says why).
28+
export { isListComparandOperator } from './filter-comparand-operators';
2429
// Canonical conformance cases for the filter logical combinators — the shared
2530
// standard the five independent FilterCondition backends are each checked
2631
// against, so they cannot drift apart again (#3774; the fifth — MongoDB's

0 commit comments

Comments
 (0)