Skip to content

Commit 1c8c5ce

Browse files
committed
test: type the new pins' query options instead of casting them
The query-options-erasure ratchet counted five new casts on the test surface; the options are on-contract, so they are typed as FilterCondition / EngineAggregateOptions. Claude-Session: https://claude.ai/code/session_01Bvd69VPa6puiNzzPUroDBx Co-authored-by: Claude <noreply@anthropic.com>
1 parent 16aedca commit 1c8c5ce

3 files changed

Lines changed: 16 additions & 13 deletions

File tree

‎packages/drivers/driver-memory/src/memory-20203-epoch-ms-date-comparand.test.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121

2222
import { beforeAll, describe, expect, it } from 'vitest';
23+
import type { FilterCondition } from '@objectstack/spec/data';
2324
import { InMemoryDriver } from './memory-driver.js';
2425

2526
const OBJECT = 'ledger_order';
@@ -62,8 +63,8 @@ const OPERATORS: ReadonlyArray<readonly [string, (v: As) => unknown, string[], s
6263

6364
describe('[#20203] an epoch-ms number on a date field reads as the UTC calendar day of its instant', () => {
6465
let driver: InMemoryDriver;
65-
const ids = async (object: string, where: Record<string, unknown>) =>
66-
((await driver.find(object, { where } as any)) as any[]).map((r) => r.id).sort();
66+
const ids = async (object: string, where: FilterCondition) =>
67+
(await driver.find(object, { where })).map((r) => r.id).sort();
6768

6869
beforeAll(async () => {
6970
driver = new InMemoryDriver({});
@@ -87,7 +88,7 @@ describe('[#20203] an epoch-ms number on a date field reads as the UTC calendar
8788
it('the write path stores the same UTC calendar day — create and update', async () => {
8889
await driver.create(WRITES, { id: 'w1', placed_on: N });
8990
await driver.create(WRITES, { id: 'w2', placed_on: -1 }); // one ms before the epoch
90-
const read = async (id: string) => ((await driver.findOne(WRITES, { where: { id } } as any)) as any)?.placed_on;
91+
const read = async (id: string) => (await driver.findOne(WRITES, { where: { id } }))?.placed_on;
9192
expect(await read('w1')).toBe('2026-02-01');
9293
expect(await read('w2')).toBe('1969-12-31');
9394
await driver.update(WRITES, 'w1', { placed_on: N_JAN10 });

‎packages/drivers/driver-sql/src/sql-driver-20203-epoch-ms-date-comparand.test.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
*/
2828

2929
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
30+
import type { FilterCondition } from '@objectstack/spec/data';
3031
import { SqlDriver } from './sql-driver.js';
3132
import { DIALECT_CELLS, declareDialectCell, type DialectCell } from './live-dialect-matrix.testkit.js';
3233

@@ -72,13 +73,13 @@ const OPERATORS: ReadonlyArray<readonly [string, (v: As) => unknown, string[], s
7273
['$eq on a UTC midnight', (v) => ({ $eq: v(N_MIDNIGHT) }), ['o4', 'o6'], []],
7374
];
7475

75-
const NO_AUDIT = { bypassTenantAudit: true } as any;
76+
const NO_AUDIT = { bypassTenantAudit: true };
7677

7778
function measure(cell: DialectCell): void {
7879
describe(`[#20203] an epoch-ms number on a date field — ${cell.label}`, () => {
7980
let driver: SqlDriver;
80-
const ids = async (table: string, where: Record<string, unknown>) =>
81-
((await driver.find(table, { where }, NO_AUDIT)) as any[]).map((r) => r.id).sort();
81+
const ids = async (table: string, where: FilterCondition) =>
82+
(await driver.find(table, { where }, NO_AUDIT)).map((r) => r.id).sort();
8283

8384
beforeAll(async () => {
8485
driver = new SqlDriver(cell.config());
@@ -107,7 +108,7 @@ function measure(cell: DialectCell): void {
107108
it('the write path stores the same UTC calendar day — create and update', async () => {
108109
await driver.create(WRITES, { id: 'w1', placed_on: N }, NO_AUDIT);
109110
await driver.create(WRITES, { id: 'w2', placed_on: -1 }, NO_AUDIT); // one ms before the epoch
110-
const read = async (id: string) => ((await driver.findOne(WRITES, { where: { id } }, NO_AUDIT)) as any)?.placed_on;
111+
const read = async (id: string) => (await driver.findOne(WRITES, { where: { id } }, NO_AUDIT))?.placed_on;
111112
expect(await read('w1')).toBe('2026-02-01');
112113
expect(await read('w2')).toBe('1969-12-31');
113114
await driver.update(WRITES, 'w1', { placed_on: N_JAN10 }, NO_AUDIT);

‎packages/rest/src/data-query-epoch-ms-date-comparand.test.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626

2727
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
28+
import type { EngineAggregateOptions, FilterCondition } from '@objectstack/spec/data';
2829
import { ObjectQL } from '@objectstack/objectql';
2930
import { SqlDriver } from '@objectstack/driver-sql';
3031
import { ObjectStackProtocolImplementation } from '@objectstack/metadata-protocol';
@@ -129,7 +130,7 @@ describe('[#20203] where — an epoch-ms number on a date field, engine and REST
129130
it(`${op}: ${onDate.join(', ')} on both doors; nothing on an empty table; the datetime control reads the instant`, async () => {
130131
for (const [state, expectDate, expectDatetime] of [['populated', onDate, onDatetime], ['empty', [], []]] as const) {
131132
const { engine, post } = doors[state];
132-
expect(sortedIds(await engine.find(OBJECT, { where: { placed_on: comparand } } as any)), `engine, ${state}`).toEqual(expectDate);
133+
expect(sortedIds(await engine.find(OBJECT, { where: { placed_on: comparand } })), `engine, ${state}`).toEqual(expectDate);
133134
expect(sortedIds(await post({ where: { placed_on: comparand } })), `REST, ${state}`).toEqual(expectDate);
134135
expect(sortedIds(await post({ where: { opened_at: comparand } })), `datetime control, ${state}`).toEqual(expectDatetime);
135136
}
@@ -138,7 +139,7 @@ describe('[#20203] where — an epoch-ms number on a date field, engine and REST
138139
});
139140

140141
describe('[#20203] a per-aggregation filter counts what its where twin counts', () => {
141-
const perAggregation = (filter: unknown) => ({
142+
const perAggregation = (filter: FilterCondition): EngineAggregateOptions => ({
142143
aggregations: [{ function: 'count', alias: 'n' }, { function: 'count', alias: 'm', filter }],
143144
});
144145
for (const [op, comparand, onDate] of OPERATORS) {
@@ -147,15 +148,15 @@ describe('[#20203] a per-aggregation filter counts what its where twin counts',
147148
const { engine, post } = doors[state];
148149
const expected = state === 'populated' ? onDate.length : 0;
149150
const query = perAggregation({ placed_on: comparand });
150-
expect((await engine.aggregate(OBJECT, query as any))[0]?.m, `engine, ${state}`).toBe(expected);
151+
expect((await engine.aggregate(OBJECT, query))[0]?.m, `engine, ${state}`).toBe(expected);
151152
expect((await post(query))[0]?.m, `REST, ${state}`).toBe(expected);
152153
}
153154
});
154155
}
155156
});
156157

157158
describe('[#20203] having on max(date) reads the number as a calendar day', () => {
158-
const grouped = (having: unknown) => ({
159+
const grouped = (having: FilterCondition): EngineAggregateOptions => ({
159160
groupBy: ['customer_id'],
160161
aggregations: [
161162
{ function: 'max', field: 'placed_on', alias: 'last_placed' },
@@ -164,7 +165,7 @@ describe('[#20203] having on max(date) reads the number as a calendar day', () =
164165
having,
165166
});
166167
// c1: last_placed 2026-01-10 · c2: 2026-03-01 · c3: 2026-02-01
167-
const HAVING: ReadonlyArray<readonly [string, Record<string, unknown>, string[]]> = [
168+
const HAVING: ReadonlyArray<readonly [string, FilterCondition, string[]]> = [
168169
['$gt on max(date)', { last_placed: { $gt: N } }, ['c2']],
169170
['$eq on max(date)', { last_placed: { $eq: N } }, ['c3']],
170171
['$in on max(date)', { last_placed: { $in: [N, N_JAN10] } }, ['c1', 'c3']],
@@ -176,7 +177,7 @@ describe('[#20203] having on max(date) reads the number as a calendar day', () =
176177
const { engine, post } = doors[state];
177178
const expected = state === 'populated' ? kept : [];
178179
const q = grouped(having);
179-
expect((await engine.aggregate(OBJECT, q as any)).map((r: any) => r.customer_id).sort(), `engine, ${state}`).toEqual(expected);
180+
expect((await engine.aggregate(OBJECT, q)).map((r: any) => r.customer_id).sort(), `engine, ${state}`).toEqual(expected);
180181
expect((await post(q)).map((r) => r.customer_id).sort(), `REST, ${state}`).toEqual(expected);
181182
}
182183
});

0 commit comments

Comments
 (0)