Skip to content

feat(launchpad): build widget-calculated-fields - #1261

Open
rubenvdlinde wants to merge 9 commits into
developmentfrom
quality/build-widget-calculated-fields
Open

rubenvdlinde wants to merge 9 commits into
developmentfrom
quality/build-widget-calculated-fields

Conversation

@rubenvdlinde

@rubenvdlinde rubenvdlinde commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Continues the build of openspec/changes/widget-calculated-fields after #1254.

Tasks done in this PR

  • Task 23: CalculatedFieldService (validateAndCompile, detectCycles, evaluateExpression). Following design D3, the server does not re-parse the source text. It checks the stored compiledExpression with the new CalculatedFieldAstChecker (node shapes as isAstNode(), built-in and allowlisted functions, argument counts) and the new CalculatedFieldTypeChecker, which follows typeChecker.js rule for rule. Each field gets its returnType, typed in dependency order across the dashboard.
  • Task 24: WidgetApiController::updatePlacement validates calculatedFields against the placement's dashboard before saving. addWidget takes no calculated fields.
  • Task 25: refusals answer 400 with {error, message, ...details, field} (invalidExpression, unknownFunction, functionNotAllowed, arityMismatch, functionSignature, typeError, duplicateField, cycleDetected). Nothing is persisted.
  • Task 29: a server/both field that reads a widget of another register or schema, or whose widget has no OpenRegister source, is saved as client. The update response then carries warnings: [{warning: 'downgraded_evaluation_mode', field, reason}].
  • Task 37: PHPUnit coverage for the above.

Tasks left

  • 26-28 and 32 (materialising server-mode fields as x-openregister-calculations on the source schema, cleanup on delete, the server error log) are next on this branch. They need the widget AST translated into OpenRegister's calculation dialect.
  • 19, 20, 35 (widget rendering, export), 39, 40, 41, 48, 49, 52, 53 are still open.
  • Playwright tasks 44-46 and the live checks are left for a live pass.

Tests

  • tests/fixtures/calculated-fields/type-check-cases.json holds 60 ASTs generated from the client parser and type checker. For each one, the PHP checker must give the same type or the same error envelope, and it does for all 60.
  • New: CalculatedFieldAstCheckerTest, CalculatedFieldTypeCheckerTest, CalculatedFieldServiceTest, WidgetApiControllerCalculatedFieldsTest (110 tests).
  • Unit suite: 4563 OK before, 4673 OK after. phpcs, phpstan and the spec-annotation lint are clean on the touched files.

Generated by Claude Code

Server-side save-time validation of calculated fields (tasks 23-25, 37):
CalculatedFieldService checks each stored AST (shape, allowlisted
functions, argument counts), detects cycles across the dashboard and
type-checks in dependency order, setting returnType; the placement update
answers 400 with the editor's error envelope before anything is saved.

Assisted-by: ClaudeCode:claude-opus-5-5
Task 29: a server-mode calculated field that reads a widget of another
register or schema, or whose widget has no OpenRegister source, is saved
in client mode and the placement update answers with a
downgraded_evaluation_mode warning.

Assisted-by: ClaudeCode:claude-opus-5-5
Materialise server-mode calculated fields on the widget's OpenRegister
source schema as read-only calculated properties, keep them in step on
save and source change, and remove them when the widget is removed
(tasks 26-28, 32, 39).

Assisted-by: ClaudeCode:claude-opus-5-5
…es [skip ci]

Assisted-by: ClaudeCode:claude-opus-5-5
Parser case table: 183 Vitest cases over operators, literals, references,
every built-in function and its arity bounds, and malformed input (task 41).

Assisted-by: ClaudeCode:claude-opus-5-5
Document calculated fields in openapi.json, the Postman collection, the
widgets feature page and the change's design notes (tasks 48, 52).

Assisted-by: ClaudeCode:claude-opus-5-5
Move the server-field save flow into CalculatedFieldServerFields to keep
the service under the complexity thresholds, and clear the psalm and
jsdoc findings in the change's files (task 47).

Assisted-by: ClaudeCode:claude-opus-5-5
…ly [skip ci]

The materialiser read and wrote the widget's source schema through
OpenRegister's SchemaMapper with its default access flags. Pass RBAC and
multitenancy explicitly on find() so a change of those defaults cannot
turn them off, document that update() verifies the caller's schema update
permission and organisation access, and lock both in tests: the schema is
read with access checks on, and a schema the caller may not read is never
written while the field stays client-side.

Assisted-by: ClaudeCode:claude-opus-5-5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant