Skip to content

feat: add uri and duration transformed schemas#89

Merged
leoafarias merged 2 commits intomainfrom
feat/dart-types
Mar 4, 2026
Merged

feat: add uri and duration transformed schemas#89
leoafarias merged 2 commits intomainfrom
feat/dart-types

Conversation

@leoafarias
Copy link
Collaborator

Adds Ack.uri() and Ack.duration() transformed schema entry points in ack.dart.
Introduces DurationConstraint plus DurationSchemaExtensions to support .min() and .max() constraints and JSON Schema emission (minimum/maximum).
Updates barrel exports so the new constraint and extension are publicly available.
Adds comprehensive schema tests for URI and Duration validation, composition behavior, error quality, and JSON Schema output.

@docs-page
Copy link

docs-page bot commented Mar 4, 2026

To view this pull requests documentation preview, visit the following URL:

docs.page/btwld/ack~89

Documentation is deployed and generated using docs.page.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds two new transformed schema entry points—Ack.uri() and Ack.duration()—and introduces Duration range constraints (.min(), .max()) with JSON Schema emission and validation tests.

Changes:

  • Add Ack.uri() (string → Uri) and Ack.duration() (integer milliseconds → Duration) transformed schemas.
  • Introduce DurationConstraint and DurationSchemaExtensions to support inclusive .min() / .max() checks and emit minimum/maximum in JSON Schema.
  • Add test coverage for URI and Duration parsing/validation, composition, error messaging, and JSON Schema output.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/ack/lib/src/ack.dart Adds Ack.uri() and Ack.duration() transformed schema factories.
packages/ack/lib/src/constraints/duration_constraint.dart Implements inclusive min/max validation + JSON Schema emission for Duration.
packages/ack/lib/src/schemas/extensions/duration_schema_extensions.dart Adds .min() / .max() fluent APIs to TransformedSchema<int, Duration>.
packages/ack/lib/ack.dart Exposes the new constraint and extension via barrel exports.
packages/ack/test/schemas/uri_validation_test.dart Adds URI validation and JSON Schema tests for the transformed URI schema.
packages/ack/test/schemas/duration_validation_test.dart Adds Duration validation, constraints, composition, error quality, and JSON Schema tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +104 to +108
/// Creates a schema that parses URI strings into [Uri] objects.
///
/// The schema validates the URI format before transformation, ensuring only
/// valid URIs are parsed.
///
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring for Ack.uri() says it validates “valid URIs”, but the underlying PatternConstraint.uri() requires hasScheme and a non-empty host, which rejects valid RFC 3986 URIs like mailto:foo@bar.com or urn:isbn:.... Either loosen the validator to match “uri” semantics, or update the docs (and/or naming) to clarify it validates absolute URIs with an authority/host (i.e., URLs).

Copilot uses AI. Check for mistakes.
Comment on lines +61 to +66
bool isValid(Duration value) => switch (type) {
DurationComparisonType.min =>
value.inMilliseconds >= reference.inMilliseconds,
DurationComparisonType.max =>
value.inMilliseconds <= reference.inMilliseconds,
};
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DurationConstraint compares and serializes using inMilliseconds, which silently truncates Durations that aren’t whole-millisecond values (e.g., Duration(microseconds: 1500) becomes 1 ms). Since the schema represents integer milliseconds, consider validating that reference.inMicroseconds % 1000 == 0 (and possibly rejecting/rounding) to avoid surprising off-by-one behavior in min/max checks and JSON Schema output.

Copilot uses AI. Check for mistakes.
@leoafarias
Copy link
Collaborator Author

Addressed Copilot's feedback:

URI docs (fixed): Updated the docstring for Ack.uri() and the constraint description to clarify it validates absolute URIs with a scheme and host, not arbitrary RFC 3986 URIs. Fixed in feac4a8.

Duration microsecond truncation (no change): The JSON Schema representation is integer milliseconds, so sub-millisecond precision is intentionally out of scope. Adding a microsecond guard would over-validate a programmer error that the API design already makes unlikely.

@leoafarias leoafarias merged commit 6ba5b1d into main Mar 4, 2026
1 check passed
@leoafarias leoafarias deleted the feat/dart-types branch March 4, 2026 23:46
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.

2 participants