Ack 2.0: one namespace for constraint annotations (@Check.email(), @Check.minLength(2))

Aperta
#191 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
30/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Attiva
Stack tecnologico
dart
Ambito
api

Direzione di ricerca

Start by reviewing the annotation exports in package:ack/annotations.dart and package:ack/ack.dart, the existing constraint annotation classes, and the generator entry point. Resolve the open questions about the namespace name, format annotations, and generator identification, then define tests covering the new API and deprecated aliases.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

2.0 enhancement

Problem

The constraint annotations are top-level classes with common names: Email, Url, Uuid, Date, Min, Max, Pattern. They clash with other libraries and with a user's own types in the same file:

  • package:uuid declares class Uuid; a file importing both and calling Uuid() gets ambiguous_import.
  • A user's own value type named Email, Url or Date, used as a field type next to @Email(), clashes the same way. Type-owned schemas (#185) encourage exactly such types.
  • Pattern shadows dart:core's Pattern silently, which is why it was renamed @Matches in 1.7.

In 1.7 the constraints are exported from package:ack/annotations.dart, not from package:ack/ack.dart, and the documented way out of a clash is an import prefix (import 'package:ack/annotations.dart' as ack; and @ack.Email()). That works but depends on convention, and the list of clashing names will grow with every new constraint.

Proposal

One exported name for every constraint, with a const named constructor per constraint, mirroring the schema API:

@Check.email()
@Check.minLength(2)
@Check.matches(r'^\d+$')
final String value;
  • One name to export, so it can live in package:ack/ack.dart and a model file needs a single import.
  • The names match the fluent methods (.email(), .minLength(), .matches()), so there is one vocabulary.
  • New constraints add a constructor, not a top-level name.

The existing annotation classes stay as deprecated aliases for one release line.

Open questions

  • The name: Check, Rule, or another word that does not collide with Constraint, which is already a runtime type in ack.
  • Whether the format annotations (@formats.Uri(), @formats.DateTime()) fold into the same namespace.
  • How the generator identifies the constraint: by constructor name, or by a kind field on the constant.

Related

  • #185: type-owned schemas.
  • The 1.7 pull request that moved the annotations into ack and split the exports.
Lingua principale
Dart
Stelle
64
Fork
3
Merge medio
17h 32m
PR unite (30g)
33

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di btwld/ack

Tutte le issue di btwld/ack

Issue simili

Altre issue su Dart

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.