feat: formula field typing — inferExpressionType + FieldSchema.returnType - #2255
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📓 Docs Drift CheckThis PR changes 2 package(s): 91 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
|
Surfaces the result type cel-js's type-checker already computes (and that `celEngine.compile` discarded): new `inferExpressionType()` maps a CEL value/formula expression onto `number | text | boolean | date | unknown`, plus the lower-level `inferCelType()` on the engine. Conservative by construction — a member access or two `dyn` operands stay `dyn` → `unknown` (e.g. `a + b`, which could be string concat, is NOT called numeric), while a typed literal or stdlib return pins it (`daysBetween(start,end)+1` → number). The motivating consumer is dataset-derive's measure-eligibility: a `formula` field gets a SUM measure ONLY when its expression is provably numeric, so an AI-built "total of a computed number" dashboard card becomes buildable without ever minting an incoherent sum-of-text measure. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
os-zhuang
force-pushed
the
feat/formula-infer-value-type
branch
from
June 24, 2026 02:17
60c920b to
9537b32
Compare
… type Lets a formula field carry the value type it computes (number/text/boolean/ date), stamped at authoring from the inferred CEL type. Consumers (dataset measures, display formatting, validation) read the declared type rather than re-parsing the expression. Pairs with @objectstack/formula inferExpressionType. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
os-zhuang
force-pushed
the
feat/formula-infer-value-type
branch
from
June 24, 2026 03:01
223426e to
1edb778
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Formula-field typing primitives, consumed by cloud dataset-derive (and useful for formatting/validation):
@objectstack/formula—inferExpressionType(input, {fields})/inferCelType(): surface the cel-js type-checker result for a CEL value/formula expression asnumber | text | boolean | date | unknown. The type was already computed incelEngine.compileand discarded.@objectstack/spec—FieldSchema.returnType(number|text|boolean|date, optional): a formula field can now carry its declared value type (the way Salesforce/Airtable do), so consumers read a declared type instead of re-parsing the expression. Without it the type would be stripped at validation.Why
A numeric formula field carries no static type. Cloud dataset-derive needs to know a formula computes a number to give it a SUM measure (so an AI-built "total of a computed number" dashboard card is buildable). This is the typing half of that fix; the authoring/derive half is a companion cloud PR that canonicalizes a formula's source onto
expressionand stampsreturnTypefrom this inference.Conservative by construction
dynoperands →dyn→unknown(e.g.a + b, possibly string concat, is not numeric)daysBetween(start,end)+1→number,x*0.1→numberTests
validate.test.tscovers number/text/boolean/date/unknown, envelope input, bare vsrecord.-qualified refs, and the conservativedyncases (formula suite green locally, 77).🤖 Generated with Claude Code