Skip to content

Commit aa923a1

Browse files
committed
test(objectql): make the counting double honour limit and refuse what it does not implement
`check:objectql-double-limit` and `check:where-matcher` both named the new double: its `find` ignored the caller's bound, and its matcher read a combinator as a field name. It now applies the bound after the filter, by presence, and throws on a combinator or an operator other than `$gt`. Claude-Session: https://claude.ai/code/session_01Bvd69VPa6puiNzzPUroDBx Co-authored-by: Claude <noreply@anthropic.com>
1 parent c51cd3d commit aa923a1

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

‎packages/objectql/src/engine-where-shape-refusal.test.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,15 @@ function makeCountingDriver() {
6464
throw new Error(`counting driver: received a non-object 'where' (${String(where)})`);
6565
}
6666
for (const [k, v] of Object.entries(where)) {
67+
// A combinator or an operator this double does not implement is REFUSED,
68+
// never read as a field name or skipped (`check:where-matcher`).
69+
if (k.startsWith('$')) throw new Error(`counting driver: unsupported combinator ${k}`);
6770
if (v && typeof v === 'object' && !Array.isArray(v)) {
6871
const ops = v as Record<string, unknown>;
69-
if ('$gt' in ops && !((row[k] as number) > (ops.$gt as number))) return false;
72+
for (const op of Object.keys(ops)) {
73+
if (op !== '$gt') throw new Error(`counting driver: unsupported operator ${op}`);
74+
}
75+
if (!((row[k] as number) > (ops.$gt as number))) return false;
7076
continue;
7177
}
7278
if (row[k] !== v) return false;
@@ -77,7 +83,13 @@ function makeCountingDriver() {
7783
const driver: IDataDriver = {
7884
name: 'counting', version: '0.0.0', supports: {},
7985
async connect() {}, async disconnect() {}, async checkHealth() { return true; }, async execute() { return null; },
80-
async find(_o: string, ast: DriverQuery) { calls.push('find'); return run(ast); },
86+
async find(_o: string, ast: DriverQuery) {
87+
calls.push('find');
88+
const hit = run(ast);
89+
// The caller's bound, applied AFTER the filter and by presence
90+
// (`check:objectql-double-limit`).
91+
return typeof ast?.limit === 'number' ? hit.slice(0, ast.limit) : hit;
92+
},
8193
async findOne(_o: string, ast: DriverQuery) { calls.push('findOne'); return run(ast)[0] ?? null; },
8294
async count(_o: string, ast: DriverQuery) { calls.push('count'); return run(ast).length; },
8395
async aggregate(_o: string, ast: DriverQuery) { calls.push('aggregate'); return [{ n: run(ast).length }]; },

0 commit comments

Comments
 (0)