You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ack is a schema validation library for Dart and Flutter that helps you validate data with a simple, fluent API. Ack is short for "acknowledge".
8
+
Ack is a schema validation library for Dart and Flutter. It validates data with a fluent API. Ack is short for "acknowledge".
9
9
10
10
For AI agents: start at [`/llms.txt`](https://docs.page/btwld/ack/llms.txt).
11
11
12
-
## Why Use Ack?
12
+
## Why use Ack?
13
13
14
-
-**Simplify Validation**: Easily handle complex data validation logic
15
-
-**Validate external payloads**: Guard API and user inputs by validating
16
-
required fields, types, and constraints at boundaries
17
-
-**Single Source of Truth**: Define data structures and rules in one place
18
-
-**Reduce Boilerplate**: Minimize repetitive code for validation and JSON conversion
19
-
-**Type Safety**: Generate typed wrappers for hand-written Ack schemas with `@AckType()`
14
+
-**Validate external payloads**: Guard API and user inputs by validating required fields, types, and constraints at boundaries
15
+
-**Single source of truth**: Define data structures and rules in one place
16
+
-**Less boilerplate**: Minimize repetitive validation and JSON conversion code
17
+
-**Type safety**: Generate typed wrappers for hand-written Ack schemas with `@AckType()`
20
18
21
19
## Packages
22
20
23
21
This repository is a monorepo containing:
24
22
25
-
-**[ack](./packages/ack)**: Core validation library with fluent schema building API
26
-
-**[ack_generator](./packages/ack_generator)**: Code generator for `@AckType()` extension-type wrappers
27
-
-**[ack_firebase_ai](./packages/ack_firebase_ai)**: Firebase AI (Gemini) schema converter for structured output generation
23
+
-**[ack](./packages/ack)**: Core validation library with a fluent schema-building API, codecs, and JSON Schema export
24
+
-**[ack_annotations](./packages/ack_annotations)**: The `@AckType()` annotation that marks schemas for code generation
25
+
-**[ack_generator](./packages/ack_generator)**: Code generator that turns `@AckType()` schemas into type-safe extension types
26
+
-**[ack_firebase_ai](./packages/ack_firebase_ai)**: Firebase AI (Gemini) schema converter for structured-output generation
27
+
-**[ack_json_schema_builder](./packages/ack_json_schema_builder)**: Converter to `json_schema_builder` schemas
28
28
-**[example](./example)**: Example projects demonstrating usage of all packages
29
29
30
-
## Quick Start
30
+
## Quick start
31
31
32
-
### Core Library (ack)
32
+
### Core library (ack)
33
33
34
34
Add Ack to your project:
35
35
@@ -42,21 +42,18 @@ Define and use a schema:
42
42
```dart
43
43
import 'package:ack/ack.dart';
44
44
45
-
// Define a schema for a user object
46
45
final userSchema = Ack.object({
47
46
'name': Ack.string().minLength(2).maxLength(50),
48
47
'email': Ack.string().email(),
49
48
'age': Ack.integer().min(0).max(120).optional(),
50
49
});
51
50
52
-
// Validate data against the schema
53
51
final result = userSchema.safeParse({
54
52
'name': 'John Doe',
55
53
'email': 'john@example.com',
56
54
'age': 30
57
55
});
58
56
59
-
// Check if validation passed
60
57
if (result.isOk) {
61
58
final validData = result.getOrThrow();
62
59
print('Valid user: $validData');
@@ -68,9 +65,9 @@ if (result.isOk) {
68
65
69
66
Use `.optional()` when a field may be omitted entirely. Chain `.nullable()` if a present field may hold `null`, or combine both for an optional-and-nullable value.
70
67
71
-
### Advanced Usage
68
+
### Advanced usage
72
69
73
-
For more complex validation scenarios:
70
+
For complex validation:
74
71
75
72
```dart
76
73
import 'package:ack/ack.dart';
@@ -114,11 +111,71 @@ if (result.isOk) {
114
111
}
115
112
```
116
113
114
+
## Code generation
115
+
116
+
Generate type-safe wrappers for hand-written schemas with `@AckType()`. Add
117
+
`ack_annotations` to `dependencies` and `ack_generator` + `build_runner` to
118
+
`dev_dependencies`, then annotate a top-level schema:
dart run build_runner build --delete-conflicting-outputs
137
+
```
138
+
139
+
This emits a `UserType` extension type with `parse`/`safeParse` and typed
140
+
getters — no manual casting:
141
+
142
+
```dart
143
+
final user = UserType.parse({'name': 'Alice', 'email': 'alice@example.com'});
144
+
print(user.name); // typed String getter
145
+
```
146
+
147
+
`@AckType()` supports objects, primitives, lists, enums, explicit transforms, and discriminated unions. See the [TypeSafe Schemas guide](https://docs.page/btwld/ack/core-concepts/typesafe-schemas).
148
+
149
+
## Codecs
150
+
151
+
Codecs decode boundary values (the JSON you receive) into rich Dart runtime types and encode them back. Ack ships built-in codecs and lets you define your own:
152
+
153
+
```dart
154
+
// Built-in codec: ISO 8601 String boundary <-> UTC DateTime runtime
155
+
final when = Ack.datetime();
156
+
final dt = when.parse('2026-01-01T00:00:00Z'); // DateTime
157
+
final iso = when.encode(dt); // back to an ISO 8601 String
158
+
159
+
// Other built-ins: Ack.date(), Ack.uri(), Ack.duration(), Ack.enumCodec(...)
160
+
161
+
// Custom bidirectional codec
162
+
final csv = Ack.codec<String, String, List<String>>(
163
+
input: Ack.string(),
164
+
decode: (s) => s.split(','),
165
+
encode: (list) => list.join(','),
166
+
);
167
+
168
+
csv.parse('a,b,c'); // ['a', 'b', 'c']
169
+
csv.encode(['a', 'b', 'c']); // 'a,b,c'
170
+
```
171
+
172
+
Use `.transform<R>(...)` for one-way (parse-only) conversions. See the
# API compatibility checking using Dart script (for semantic versioning)
232
+
# API compatibility check (for semantic versioning)
178
233
melos api-check v0.2.0
179
234
180
235
# See all available scripts
181
236
melos list-scripts
182
237
```
183
238
184
-
> **Note**: Additional development documentation is available in the `tools/` directory for project maintainers.
239
+
Additional development documentation is available in the `tools/` directory.
185
240
186
-
## Versioning and Publishing
241
+
## Versioning and publishing
187
242
188
-
This project uses GitHub Releases to manage versioning and publishing. For detailed instructions on how to create releases and publish packages, see [PUBLISHING.md](./PUBLISHING.md).
243
+
This project uses GitHub Releases to manage versioning and publishing. See [PUBLISHING.md](./PUBLISHING.md) for instructions.
189
244
190
245
## Contributing
191
246
192
-
Contributions are welcome! A detailed CONTRIBUTING.md file will be added soon with specific guidelines.
247
+
Contributions are welcome. Follow these steps:
193
248
194
-
In the meantime, please follow these basic steps:
195
249
1. Fork the repository
196
250
2. Create a feature branch
197
251
3. Add your changes
198
252
4. Run tests with `melos test`
199
-
5.Make sure to follow[Conventional Commits](https://www.conventionalcommits.org/) in your commit messages
253
+
5.Follow[Conventional Commits](https://www.conventionalcommits.org/) in your commit messages
0 commit comments