Skip to content

Commit 501732c

Browse files
committed
Merge remote-tracking branch 'origin/main' into claude/project-thread-a2sab2
2 parents f3a19b4 + 6aa658a commit 501732c

17 files changed

Lines changed: 788 additions & 65 deletions
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@object-ui/core': patch
3+
'@object-ui/plugin-gantt': patch
4+
---
5+
6+
feat(plugin-gantt): the gantt draws up to 10,000 rows before it truncates, instead of the 2,000 the other non-grid views share
7+
8+
Clause-②: yes (widening)
9+
Metadata-protocol: none
10+
11+
- **`@object-ui/plugin-gantt`:** a gantt now fetches and draws up to `GANTT_ROW_CEILING` (10,000) rows of its filtered result set; past it, it draws the first 10,000 and shows the same "Showing the first N of M records" note as before. A schedule of 2,001 to 10,000 rows that used to draw its first 2,000 with that note now draws whole, with no metadata change. The ceiling is still not authorable: an authored `pagination.pageSize` or `limit` does not reach the gantt's query, and a datasource's `external.rowCap` is not read. Calendar, map and tree keep the shared 2,000.
12+
- **`@object-ui/core`:** exports `GANTT_ROW_CEILING` beside `NON_GRID_ROW_CEILING`, and the `NonGridRowCeiling` type (the closed set of the two). `nonGridRowCeilingQuery(ceiling?)` and `applyNonGridRowCeiling(result, ceiling?)` take an optional ceiling from that set; leaving it out keeps the shared 2,000, so existing callers are unchanged.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/driver-sql': patch
3+
---
4+
5+
fix(driver-sql): a `date` field still on a Postgres `timestamptz` column reads, writes, filters and buckets the same day
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
Publishing a field changed from `datetime` to `date` keeps its `timestamptz` column on Postgres. The driver then wrote a bare day into that column, and Postgres stored it as midnight in the server's time zone; the read folds the stored instant by its UTC day, so with the server ahead of UTC (`Asia/Shanghai`) a date written as `2026-11-12` read back `2026-11-11`. A filter by the day and the date bucket also read the column in the server's zone, so the four doors gave three answers. SQLite and MySQL were not affected.
11+
12+
Every door now uses UTC, the zone the read already used: the write binds the day's UTC midnight, and a filter and a date bucket read the column as its UTC calendar day. The schema sync records which `date` fields sit on a `timestamptz` column from the column catalog it already reads. Nothing a `datetime` field reads changes, the column type is not changed, and no stored value is rewritten. A day written before this fix on such a server keeps the earlier day it was stored as.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@objectstack/runtime': patch
3+
---
4+
5+
fix(runtime): the bare action route serves the environment's own action declaration on an object no holder of the name binds
6+
7+
Clause-②: yes (widening)
8+
Metadata-protocol: none
9+
10+
When two packages hold an action of one name on other objects (for example `account` and `contact`) and the environment has its own action of that name on a third object (`lead`), the bare route `/api/v1/actions/lead/NAME` answered that the action has no declaration. The route found the environment's item only through the first holder's exact address, and that address no longer serves a package-less copy (#32568).
11+
12+
FROM no declaration TO the environment's own action declaration, with no package, in either registration order. The route reads the environment's own item directly (its registry item and the environment's own stored row), never at a holder's exact address. An environment item with no object answers on `lead` too, and an item bound to `lead` comes before one with no object. Each holder's own route (`account`, `contact`) answers as before. A route that an enabled package's action binds answers that package's own action, as before. A route that a disabled package's action binds stays no declaration, which keeps main's answer there. So does a package-less item with no row in the environment's store (host or plugin code). A store read that fails answers 503 rather than no declaration.
13+
14+
This change serves the declaration. Whether a script-bodied action of that name then runs on a booted host is a separate binding question, tracked on its own.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [#32851] A `Field.date` whose Postgres column is still an INSTANT column.
5+
*
6+
* `createColumn` gives a `date` field a `date` column, and the additive sync
7+
* never revisits an existing column's type. So a field retyped `datetime` →
8+
* `date` and published keeps the `timestamptz` column its `datetime`
9+
* declaration built, and the driver's `date` path, written for a `date`
10+
* column, met a column that holds instants:
11+
*
12+
* - the WRITE bound the bare day `'2026-11-12'`, which Postgres reads into
13+
* `timestamptz` as midnight in the SESSION's zone, so on a server at
14+
* `Asia/Shanghai` it stored `2026-11-11T16:00:00Z`;
15+
* - the READ folds the `Date` node-pg hands back by its UTC components
16+
* (ADR-0053; `temporalStorageForm`), so that row read `2026-11-11`;
17+
* - a FILTER bound the same bare day, cast in the session zone again, so
18+
* `due = '2026-11-12'` matched the row that READ `2026-11-11` and missed a
19+
* row written as a `datetime` that read `2026-11-12`;
20+
* - the DATE BUCKET cast the column with `::date`, also in the session
21+
* zone, and put both of those rows on `2026-11-12`.
22+
*
23+
* Four doors, three answers, no error. Measured on live Postgres 16 with the
24+
* server at `Asia/Shanghai` and the process at `America/New_York`.
25+
*
26+
* The fix pins every door to ONE zone, UTC, the zone the read already uses,
27+
* so nothing a `datetime` field reads moves and no stored value is rewritten:
28+
*
29+
* - the write binds the day as the instant of its UTC midnight
30+
* ({@link utcMidnightOfDay});
31+
* - a filter and a date bucket read the column as its UTC calendar day
32+
* ({@link utcCalendarDaySql}), so they compare and group the day the read
33+
* presents, for every stored value, including one written while the field
34+
* was a `datetime`.
35+
*
36+
* The column is NOT narrowed to `date` here: that rewrites every stored value
37+
* (it drops the time of day a `datetime` wrote), which is a data change, not a
38+
* read rule.
39+
*
40+
* MySQL needs none of this: its session is pinned to UTC (`withUtcSession`)
41+
* and `DATETIME` is zone-naive, so a bare day IS UTC midnight on every door.
42+
* SQLite stores text. Only Postgres records the registry this module reads.
43+
*/
44+
45+
/**
46+
* The registry: per table, the `Field.date` fields whose physical Postgres
47+
* column is a `timestamp` type. Recorded by the schema sync from the column
48+
* catalog it already reads, and EMPTY until a sync has looked — a driver that
49+
* never synced the table (deferred DDL, a guest datasource) keeps the plain
50+
* `date` path it had before.
51+
*/
52+
export type DateFieldsOnInstantColumn = Record<string, Set<string>>;
53+
54+
/**
55+
* Whether `field` of `table` is a declared `Field.date` that the sync found on
56+
* an instant column. Both registries are asked: a field retyped away from
57+
* `date` since the last sync leaves the date registry first.
58+
*/
59+
export function isDateOnInstantColumn(
60+
host: { readonly dateFields: Record<string, Set<string>>; readonly dateFieldsOnInstantColumn: DateFieldsOnInstantColumn },
61+
table: string | null | undefined,
62+
field: string,
63+
): boolean {
64+
if (!table) return false;
65+
return host.dateFieldsOnInstantColumn[table]?.has(field) === true && host.dateFields[table]?.has(field) === true;
66+
}
67+
68+
/**
69+
* Whether a Postgres catalog type (as knex `columnInfo()` reports it:
70+
* `timestamp with time zone`, `timestamp without time zone`) holds instants.
71+
* Only `timestamptz` is recorded: it is the column this driver builds for a
72+
* `datetime` field, and the one whose bare-day cast reads the session zone.
73+
*/
74+
export function isPostgresInstantColumnType(type: unknown): boolean {
75+
return String(type ?? '').trim().toLowerCase() === 'timestamp with time zone';
76+
}
77+
78+
/** The fixed-width calendar day `temporalStorageForm(…, 'date')` answers. */
79+
const CALENDAR_DAY = /^\d{4}-\d{2}-\d{2}$/;
80+
81+
/**
82+
* The write binding of a calendar day into an instant column: the instant of
83+
* its UTC midnight, zone explicit, so the server's zone takes no part. Any
84+
* other shape (a value the day fold could not read) is handed back unchanged
85+
* for the server to refuse as it did before.
86+
*/
87+
export function utcMidnightOfDay(day: unknown): unknown {
88+
return typeof day === 'string' && CALENDAR_DAY.test(day) ? `${day}T00:00:00.000Z` : day;
89+
}
90+
91+
/**
92+
* The SQL that reads an instant column as its UTC calendar day — the day the
93+
* read door presents. `columnSql` is an identifier placeholder (`??`) or an
94+
* already-quoted column reference.
95+
*/
96+
export function utcCalendarDaySql(columnSql: string): string {
97+
return `((${columnSql}) AT TIME ZONE 'UTC')::date`;
98+
}
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [#32851] A field published `datetime` → `date` keeps its `timestamptz`
5+
* column on Postgres, and the `date` path read that column in two zones.
6+
*
7+
* Measured on live Postgres 16 before the fix, server at `Asia/Shanghai`,
8+
* process at `America/New_York` (the `Temporal Conformance (live PG + MySQL)`
9+
* job's pair):
10+
*
11+
* - `create({ due: '2026-11-12' })` answered, and read back, `2026-11-11`:
12+
* the bare day was stored as midnight in the SERVER's zone
13+
* (`2026-11-11T16:00:00Z`) and read back by its UTC components;
14+
* - `due = '2026-11-12'` matched that row (the comparand was cast in the
15+
* session zone too) and missed the row written as the instant
16+
* `2026-11-12T20:00:00Z` while the field was a `datetime`, which READ
17+
* `2026-11-12`;
18+
* - the day bucket put the second row on `2026-11-13` (`::date` in the
19+
* session zone).
20+
*
21+
* The fix reads every door in UTC, the zone the read already used: the write
22+
* binds the day's UTC midnight, and the filter and the bucket read the column
23+
* as its UTC calendar day. See `date-on-instant-column.ts`.
24+
*
25+
* Every cell writes and reads the same rows: SQLite and MySQL never had the
26+
* defect (SQLite stores text; MySQL's session is UTC and `DATETIME` is
27+
* zone-naive) and must still answer the same day. The row written while the
28+
* field was a `datetime` is asserted through the filter and the bucket on
29+
* Postgres only: on SQLite and MySQL a bare-day comparand does not match a
30+
* stored instant with a time of day, the same on the pre-fix tree, and that is
31+
* not what this card changes.
32+
*/
33+
34+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
35+
import { SqlDriver } from './sql-driver.js';
36+
import { DIALECT_CELLS, declareDialectCell, type DialectCell } from './live-dialect-matrix.testkit.js';
37+
38+
const MATRIX = 'date on an instant column (#32851)';
39+
const TABLE = 'pub32851_due';
40+
41+
/** The live table as it was created: `due` a `datetime`. */
42+
const V1 = { name: TABLE, fields: { label: { type: 'text' }, due: { type: 'datetime' }, seen: { type: 'datetime' } } };
43+
/** The published change: `due` becomes a `date`; `seen` stays a `datetime`. */
44+
const V2 = { name: TABLE, fields: { label: { type: 'text' }, due: { type: 'date' }, seen: { type: 'datetime' } } };
45+
46+
/** 20:00Z is 04:00 the NEXT day at `Asia/Shanghai`: a session-zone day discriminates. */
47+
const DATETIME_ERA = '2026-11-12T20:00:00.000Z';
48+
const DAY = '2026-11-12';
49+
const SEEN = '2026-11-12T23:30:00.000Z';
50+
51+
const rowsOf = (res: unknown): Record<string, unknown>[] =>
52+
(Array.isArray(res) ? res : ((res as { rows?: unknown[] })?.rows ?? [])) as Record<string, unknown>[];
53+
54+
function measure(cell: DialectCell): void {
55+
describe(`a \`datetime\` field published as \`date\` — ${cell.label} (#32851)`, () => {
56+
const pg = cell.id === 'pg';
57+
let driver: SqlDriver;
58+
let columnType = '';
59+
let serverOffsetSeconds = 0;
60+
const ids: Record<'era' | 'created' | 'updated', string> = { era: '', created: '', updated: '' };
61+
let createdAnswer: Record<string, unknown> = {};
62+
63+
const labelsOf = (rows: readonly Record<string, unknown>[]) => rows.map((r) => String(r.label)).sort();
64+
65+
// Live: a connect, the two syncs and the publish's column half (#14213).
66+
beforeAll(async () => {
67+
driver = new SqlDriver(cell.config());
68+
await driver.connect();
69+
await driver.getKnex().schema.dropTableIfExists(TABLE);
70+
71+
await driver.syncSchema(TABLE, V1);
72+
ids.era = String((await driver.create(TABLE, { label: 'era', due: DATETIME_ERA })).id);
73+
ids.updated = String((await driver.create(TABLE, { label: 'updated', due: DATETIME_ERA })).id);
74+
75+
// The publish: its storage sync, then the column half it asks for.
76+
await driver.syncSchema(TABLE, V2);
77+
await driver.applyPublishedColumnChanges(V2);
78+
79+
columnType = String(((await driver.getKnex()(TABLE).columnInfo()) as any).due.type).toLowerCase();
80+
if (pg) {
81+
const res = await driver.execute(`select extract(timezone from now())::int as off`);
82+
serverOffsetSeconds = Number(rowsOf(res)[0]?.off);
83+
}
84+
85+
createdAnswer = (await driver.create(TABLE, { label: 'created', due: DAY, seen: SEEN })) as Record<string, unknown>;
86+
ids.created = String(createdAnswer.id);
87+
await driver.update(TABLE, ids.updated, { due: DAY });
88+
}, 60_000);
89+
90+
afterAll(async () => {
91+
await driver?.getKnex().schema.dropTableIfExists(TABLE).catch(() => {});
92+
await driver?.disconnect().catch(() => {});
93+
}, 60_000);
94+
95+
it.runIf(pg)('the fixture is real: the column is still `timestamptz` and the server zone is ahead of UTC', () => {
96+
expect(columnType).toBe('timestamp with time zone');
97+
// The defect needs a session zone east of UTC; CI points the server at
98+
// `Asia/Shanghai`. A server at UTC would pass every assertion below on
99+
// the pre-fix tree.
100+
expect(serverOffsetSeconds, 'point the Postgres server at a zone ahead of UTC (e.g. Asia/Shanghai)').toBeGreaterThan(0);
101+
});
102+
103+
it('a day written after the publish is answered and read back as that day', async () => {
104+
expect(createdAnswer.due).toBe(DAY);
105+
const created: any = await driver.findOne(TABLE, { where: { id: ids.created } });
106+
expect(created.due).toBe(DAY);
107+
const updated: any = await driver.findOne(TABLE, { where: { id: ids.updated } });
108+
expect(updated.due).toBe(DAY);
109+
});
110+
111+
it('a filter by that day finds every row written as that day', async () => {
112+
const eq = await driver.find(TABLE, { where: { due: DAY } });
113+
expect(labelsOf(eq as any[])).toEqual(expect.arrayContaining(['created', 'updated']));
114+
const range = await driver.find(TABLE, { where: { due: { $gte: DAY, $lte: DAY } } });
115+
expect(labelsOf(range as any[])).toEqual(expect.arrayContaining(['created', 'updated']));
116+
const before = await driver.find(TABLE, { where: { due: { $lt: DAY } } });
117+
expect(labelsOf(before as any[])).not.toContain('created');
118+
});
119+
120+
it('a `datetime` field beside it still reads and filters as its instant', async () => {
121+
const row: any = await driver.findOne(TABLE, { where: { id: ids.created } });
122+
expect(row.seen).toBe(SEEN);
123+
const hit = await driver.find(TABLE, { where: { seen: SEEN } });
124+
expect(labelsOf(hit as any[])).toEqual(['created']);
125+
});
126+
127+
it.runIf(pg)('the row written as a `datetime` reads, filters and buckets as one day', async () => {
128+
const era: any = await driver.findOne(TABLE, { where: { id: ids.era } });
129+
expect(era.due).toBe(DAY);
130+
131+
const eq = await driver.find(TABLE, { where: { due: DAY } });
132+
expect(labelsOf(eq as any[])).toEqual(['created', 'era', 'updated']);
133+
134+
const grouped = await driver.aggregate(TABLE, {
135+
groupBy: [{ field: 'due', dateGranularity: 'day' }],
136+
aggregations: [{ function: 'count', alias: 'n' }],
137+
});
138+
expect((grouped as any[]).map((g) => [g.due, Number(g.n)])).toEqual([[DAY, 3]]);
139+
});
140+
141+
it.runIf(pg)('the outside-the-builder doors (analytics native SQL) answer the same day', async () => {
142+
const column = driver.temporalFilterColumnSql(TABLE, 'due', '"due"');
143+
const comparand = driver.temporalFilterValue(TABLE, 'due', DAY);
144+
const hit = rowsOf(await driver.execute(`select label from "${TABLE}" where ${column} = ? order by label`, [comparand]));
145+
expect(hit.map((r) => r.label)).toEqual(['created', 'era', 'updated']);
146+
147+
const expr = driver.dateBucketSql(TABLE, 'due', 'day');
148+
const echoed = rowsOf(await driver.execute(`select ${expr} as b, count(*) as n from "${TABLE}" group by ${expr}`));
149+
expect(echoed.map((r) => [r.b, Number(r.n)])).toEqual([[DAY, 3]]);
150+
});
151+
});
152+
}
153+
154+
for (const cell of DIALECT_CELLS) {
155+
declareDialectCell(cell, MATRIX, measure);
156+
}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
*/
4242

4343
import type { SqlDriver } from './sql-driver.js';
44+
import { isDateOnInstantColumn, utcCalendarDaySql } from './date-on-instant-column.js';
4445

4546
/**
4647
* The `SqlDriver` members the function below reads — every one of them, and
@@ -50,6 +51,8 @@ import type { SqlDriver } from './sql-driver.js';
5051
* the module header for which members are getters.
5152
*/
5253
export interface DateBucketHost {
54+
readonly dateFields: SqlDriver['dateFields'];
55+
readonly dateFieldsOnInstantColumn: SqlDriver['dateFieldsOnInstantColumn'];
5356
readonly dateGranularityCapabilities: SqlDriver['dateGranularityCapabilities'];
5457
readonly isMysql: SqlDriver['isMysql'];
5558
readonly isOracle: SqlDriver['isOracle'];
@@ -60,7 +63,7 @@ export interface DateBucketHost {
6063
}
6164

6265
/** The body of `SqlDriver#buildDateBucketExpr`; the method's docblock there is its contract. */
63-
export function buildDateBucketExpr(this: Pick<DateBucketHost, 'dateGranularityCapabilities' | 'isMysql' | 'isOracle' | 'isPostgres' | 'isSqlite' | 'sqliteTemporalArg' | 'temporalFieldKind'>, field: string, granularity: 'day' | 'week' | 'month' | 'quarter' | 'year', table?: string | null, column: string = field): { sql: string; bindings: any[] } | null {
66+
export function buildDateBucketExpr(this: Pick<DateBucketHost, 'dateFields' | 'dateFieldsOnInstantColumn' | 'dateGranularityCapabilities' | 'isMysql' | 'isOracle' | 'isPostgres' | 'isSqlite' | 'sqliteTemporalArg' | 'temporalFieldKind'>, field: string, granularity: 'day' | 'week' | 'month' | 'quarter' | 'year', table?: string | null, column: string = field): { sql: string; bindings: any[] } | null {
6467
if (!this.dateGranularityCapabilities[granularity]) return null;
6568

6669
// `field` is the FIELD — the registries (`temporalFieldKind`, the SQLite
@@ -89,7 +92,11 @@ export function buildDateBucketExpr(this: Pick<DateBucketHost, 'dateGranularityC
8992
}
9093

9194
if (this.isPostgres) {
92-
const arg = calendarDay ? `(??)::date::timestamp` : `(??)::timestamptz AT TIME ZONE 'UTC'`;
95+
// [#32851] A `Field.date` still on a `timestamptz` column (a `datetime` →
96+
// `date` publish) is bucketed as its UTC day, the day the read presents;
97+
// a bare `::date` would read it in the session's zone.
98+
const dayArg = isDateOnInstantColumn(this, table, field) ? `${utcCalendarDaySql('??')}::timestamp` : `(??)::date::timestamp`;
99+
const arg = calendarDay ? dayArg : `(??)::timestamptz AT TIME ZONE 'UTC'`;
93100
switch (granularity) {
94101
case 'year': return { sql: `to_char(${arg}, 'YYYY')`, bindings: [field] };
95102
case 'month': return { sql: `to_char(${arg}, 'YYYY-MM')`, bindings: [field] };

0 commit comments

Comments
 (0)