Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Portable Form Contracts via Declarative Expression Trees

Описание и применение

Статья описывает проблему непортативности форм, использующих колбэки для валидации. Предлагается решение через декларативные деревья выражений (JSON), которые можно сериализовать и выполнять в разных средах, обеспечивая единый контракт между клиентом и сервером.

Задача

Standard form libraries rely on executable callbacks for validation and conditional logic, which cannot be serialized as JSON. This prevents forms from being portable across different runtimes, backends, or visual editors, breaking the contract between client and server.

Результат

By decoupling form behavior from executable code and using declarative expression trees, forms become portable contracts. This enables consistent validation across clients and servers, supports visual editors, and eliminates security risks associated with remote code execution.

Рабочий процесс

  • Identify form logic that relies on imperative callbacks.
  • Replace callbacks with a declarative expression tree format (e.g., { op: 'eq', left: { path: [...] }, right: { literal: ... } }).
  • Use a typed builder (TypeScript) for authoring to ensure type safety and reference checking.
  • Serialize the resulting structure to JSON for transport.
  • Implement interpreters in target runtimes to execute the declarative rules.
  • Validate the form contract independently on the server using the same JSON definition.

Доказательства

A form configuration is not a portable form contract if part of its meaning still lives inside executable callbacks.

Источник

The remote document never contains JavaScript, serialized callbacks or instructions to evaluate arbitrary source code. It only contains data from a closed vocabulary.

Источник

  • Дата записи: 2026-09-05T13:44:49.563Z