Skip to content

feat(utils): export DependsOnEvaluator on the public barrel#69

Open
abhijitnairDhwani wants to merge 1 commit into
developfrom
feat/export-depends-on-evaluator
Open

feat(utils): export DependsOnEvaluator on the public barrel#69
abhijitnairDhwani wants to merge 1 commit into
developfrom
feat/export-depends-on-evaluator

Conversation

@abhijitnairDhwani

Copy link
Copy Markdown
Collaborator

What

One-line addition to the SDK barrel:

export 'src/utils/depends_on_evaluator.dart' show DependsOnEvaluator;

No code in src/utils/depends_on_evaluator.dart changes; only its visibility.

Why this is needed

DependsOnEvaluator evaluates Frappe's depends_on / mandatory_depends_on expressions. The class is already mature canonical infrastructure for the SDK itself — referenced 9 times internally:

  • src/ui/widgets/form_builder.dart × 7 (visibility, mandatoriness, read-only, tab/section evaluation)
  • src/services/link_option_service.dart × 2 (extractEvalDocField)

The class docstring already calls out the public-API intent:

Trust boundary: expressions evaluated here come from server-side DocType meta configured by Frappe admins, not from end-user input. This evaluator is NOT sandboxed — do not pass user-supplied strings to evaluate.

The class lives in src/utils/ only because it was never explicitly exported. Consumers reaching into the SDK to use it need // ignore: implementation_imports.

Who needs this

Apps that own their own form layer rather than rendering through FrappeFormBuilder need the same evaluator on the UI side. Concretely: any consumer that:

  1. Uses the SDK's data layer (OfflineRepository, SyncService, UnifiedResolver) for offline-first save / pull / push;
  2. But builds their own widget tree for forms (because of design-system requirements, custom layouts driven by client-locked design specs, etc.);

… needs depends_on / mandatory_depends_on semantics on the UI side to match the SDK's data-layer expectations.

Re-implementing the evaluator locally would mean duplicating ~150 LOC of expression parsing (the eval: prefix strip, AND/OR splits outside brackets, six comparison operators, .includes([...]) patterns, nested-paren handling). Every time the SDK extends the supported expression syntax, the consumer's duplicate would silently drift.

Exporting the symbol from the SDK's public barrel keeps semantics aligned with the upstream evaluator, with no code drift surface.

Why not introduce a new abstract interface

The existing class is the contract. There's nothing implementation-specific about evaluating a string against a Map<String, dynamic> — that's exactly what the SDK does internally too. A new interface would just shadow the existing class without adding value.

Tests

No new tests; the change is visibility-only. The existing evaluator tests in test/utils/depends_on_evaluator_test.dart (if any) and the 7+2 internal call sites continue to work unchanged.

`DependsOnEvaluator` is canonical infrastructure for evaluating Frappe's
`depends_on` / `mandatory_depends_on` expressions — the SDK uses it 9
times internally (form_builder.dart × 7, link_option_service.dart × 2)
and the class docstring already calls out the public-API intent
("expressions evaluated here come from server-side DocType meta
configured by Frappe admins").

Consumers that own their own form layer (rather than rendering through
`FrappeFormBuilder`) need the same evaluator to apply depends_on
semantics on the UI side — re-implementing the parser locally would
duplicate ~150 LOC and create a drift vector the moment the SDK adds
new expression forms.

One-line addition to the `Utils` section of the barrel. No code in
`src/utils/depends_on_evaluator.dart` changes; only its visibility.
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