|
| 1 | +--- |
| 2 | +'@objectstack/formula': minor |
| 3 | +'@objectstack/spec': minor |
| 4 | +--- |
| 5 | + |
| 6 | +fix(formula)!: a flow condition that orders a `date` or `datetime` field against a number is now refused, in every spelling |
| 7 | + |
| 8 | +Clause-②: no (narrowing) |
| 9 | +Metadata-protocol: narrowed |
| 10 | +Skills-docs: none — `skills/objectstack-formula/SKILL.md` already teaches a date field as its ISO text and prescribes `daysBetween(today(), record.due)` for days remaining and `daysFromNow(n)` for a date ahead, and no skill teaches ordering a date against a number |
| 11 | + |
| 12 | +<!-- adr-0087: registered flow-condition-date-number-ordering-refused --> |
| 13 | + |
| 14 | +**BREAKING** accept-set narrowing. In a flow condition (a start, edge or `decision` branch condition) a `date` or `datetime` field reaches the run as its text (`YYYY-MM-DD`, or an ISO-8601 instant), and no overload orders that text against a number. So `due_date > 5` faults on every run, and the flow stops at the condition after the write that fired it has landed. The type check saw the fault and dropped it, so the condition passed `os validate` and the publish door with no finding, in all four spellings: the bare name (`due_date > 5`), `record.FIELD` / `previous.FIELD` (`record.due_date > 5`), an index read (`record['due_date'] > 5`) and a macro variable ranging over the field (`[due_date].exists(d, d > 5)`). |
| 15 | + |
| 16 | +- **The verdict.** Two new codes, graded as date arithmetic is (an error at every flow condition): `date-number-ordering-run-fails` on a record-triggered flow or a sweep of the typed object, `date-number-ordering-run-may-fail` elsewhere. A `record.FIELD` / `previous.FIELD` read keeps the row's arm where bare names are unproven; a bare name a flow variable holds is not judged. Params: `operands`, `operator`, and `reference` (the field as written; an index read is named by its member spelling). The message prescribes `daysBetween(a, b)` or a date-to-date comparison with `daysFromNow(n)` / `addDays(d, n)`. |
| 17 | +- **Masking.** A text or boolean mismatch graded a warning no longer hides the ordering behind it: `title > 5 && due_date > 5` gets the error. A mismatch graded an error keeps its code and words. |
| 18 | +- **Where.** `os validate` / `os build` (`validateStackExpressions`) report an `error`, and the flow publish door refuses the publish with `INVALID_METADATA` (422). `registerFlow` logs it as an advisory and still registers the flow, so a stored flow keeps its run-time behaviour until it is next published. |
| 19 | +- **Not refused.** An ordering against a date or a date text (`due_date > today()`, `due_date > '2026-01-01'`), equality, `daysBetween` / `addDays` / `daysFromNow` over the field. Record-scoped sites (formula fields, validation rules, `visibleWhen` / `requiredWhen`) are not judged by this change. The run-time evaluator is unchanged. |
| 20 | + |
| 21 | +## FROM → TO |
| 22 | + |
| 23 | +| FROM | TO | |
| 24 | +|:---|:---| |
| 25 | +| `due_date > 5` (more than five days past due) | `daysBetween(due_date, today()) > 5` | |
| 26 | +| `record.due_date < 7` (due within the week) | `record.due_date < daysFromNow(7)` | |
| 27 | +| `[due_date].exists(d, d > 5)` | `[due_date].exists(d, daysBetween(d, today()) > 5)` | |
| 28 | + |
| 29 | +One-line fix: in a flow condition, never compare a date field with a number; compare a span from `daysBetween(a, b)` with the number, or compare the date with a date from `daysFromNow(n)` / `addDays(d, n)`. |
0 commit comments