Skip to content

Commit e1d3b38

Browse files
authored
docs: Fix broken links and add missing API documentation (#57)
1 parent a10b497 commit e1d3b38

12 files changed

Lines changed: 149 additions & 58 deletions

File tree

docs/api-reference/index.mdx

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This page provides a quick reference for the core Ack classes, methods, and anno
66

77
## Core `Ack` Class
88

9-
Entry point for creating schemas. See [Schema Validation](../core-concepts/typesafe-schemas.mdx).
9+
Entry point for creating schemas. See [Schema Types](../core-concepts/schemas.mdx).
1010

1111
- `Ack.string()`: Creates a `StringSchema` for validating strings.
1212
- `Ack.integer()`: Creates an `IntegerSchema` for validating integers.
@@ -54,7 +54,7 @@ Base class for all schema types.
5454
- `Map<String, Object?> toJsonSchema()`: Converts the schema to a JSON Schema Draft-7 representation.
5555
- `Map<String, Object?> toMap()`: Serializes the schema for debugging.
5656

57-
See also [Schema Validation](../core-concepts/typesafe-schemas.mdx) for detailed usage examples.
57+
See also [Schema Types](../core-concepts/schemas.mdx) for detailed usage examples.
5858

5959
## `StringSchema`
6060

@@ -107,6 +107,8 @@ Schemas for validating numbers. See [Number Validation](../core-concepts/validat
107107

108108
- `min(num limit)`: Minimum value (inclusive)
109109
- `max(num limit)`: Maximum value (inclusive)
110+
- `greaterThan(num limit)`: Must be greater than limit (exclusive)
111+
- `lessThan(num limit)`: Must be less than limit (exclusive)
110112
- `positive()`: Must be greater than 0
111113
- `negative()`: Must be less than 0
112114
- `multipleOf(num factor)`: Must be a multiple of the factor
@@ -121,9 +123,10 @@ Schema for validating booleans. Validates `true` and `false` values, with option
121123

122124
Schema for validating arrays. See [List Validation](../core-concepts/validation.mdx#list-constraints).
123125

124-
- `minLength(int min)`: Minimum number of items
125-
- `maxLength(int max)`: Maximum number of items
126-
- `length(int exact)`: Exact number of items
126+
- `minItems(int min)`: Minimum number of items (alias: `minLength`)
127+
- `maxItems(int max)`: Maximum number of items (alias: `maxLength`)
128+
- `exactLength(int exact)`: Exact number of items (alias: `length`)
129+
- `nonEmpty()`: List must have at least one item (alias: `notEmpty`)
127130
- `unique()`: All items must be unique
128131

129132
## `ObjectSchema`
@@ -137,6 +140,7 @@ Schema for validating objects (maps). See [Object Validation](../core-concepts/s
137140
- Use `.partial()` to make all properties optional.
138141
- Use `.strict()` to disallow additional properties.
139142
- Use `.passthrough()` to allow additional properties not defined in the schema.
143+
- Use `.merge(ObjectSchema other)` to combine with another object schema.
140144

141145
## `SchemaResult<T>`
142146

@@ -177,7 +181,7 @@ combinators.
177181

178182
## Code Generation Annotations
179183

180-
Use the [`ack_generator`](../../packages/ack_generator/README.md) builder to
184+
Use the [`ack_generator`](https://pub.dev/packages/ack_generator) builder to
181185
turn annotations into ready-to-use schemas and extension types. After adding
182186
the annotations below, run:
183187

@@ -189,11 +193,9 @@ dart run build_runner build
189193

190194
**Target**: Dart classes
191195

192-
**Generates**: Both a schema constant AND an extension type
196+
**Generates**: A schema constant only
193197

194-
Annotate a Dart class to automatically generate a validation schema and a strongly typed extension type. The generator analyzes your class fields and creates:
195-
- A schema constant named `<className>Schema` (e.g., `userSchema`)
196-
- An extension type named `<ClassName>Type` (e.g., `UserType`)
198+
Annotate a Dart class to automatically generate a validation schema. The generator analyzes your class fields and creates a schema constant named `<className>Schema` (e.g., `userSchema`).
197199

198200
**Parameters:**
199201
- `schemaName`: Custom name for the generated schema constant
@@ -215,11 +217,13 @@ class User {
215217
216218
// Generated:
217219
// - final userSchema = Ack.object({...});
218-
// - extension type UserType(Map<String, Object?> _data) { ... }
219220
220221
// Usage:
221-
final user = UserType.parse({'name': 'Alice', 'age': 30});
222-
print(user.name); // Type-safe String access
222+
final result = userSchema.safeParse({'name': 'Alice', 'age': 30});
223+
if (result.isOk) {
224+
final data = result.getOrThrow();
225+
print(data['name']); // 'Alice'
226+
}
223227
```
224228

225229
### `@AckType()`
@@ -295,4 +299,4 @@ Every schema can be marked optional through the `optional({bool value = true})`
295299
- Use `schema.optional(value: false)` to clear the optional flag.
296300
- Optional affects object-field presence only; combine with `.nullable()` to also allow explicit `null`.
297301

298-
*Refer to the [Schema Validation](../core-concepts/typesafe-schemas.mdx) guide for detailed usage and examples.*
302+
*Refer to the [Schema Types](../core-concepts/schemas.mdx) guide for detailed usage and examples.*

docs/core-concepts/configuration.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ final signUpSchema = Ack.object({
9595

9696
## Code Generation Configuration
9797

98-
The `ack_generator` package provides automatic schema generation from annotated classes. This feature is production-ready and available at version 1.0.0-beta.1 and later.
98+
The `ack_generator` package provides automatic schema generation from annotated classes. This feature is production-ready.
9999

100-
To use code generation, annotate your classes with `@AckModel`. The generator creates both a validation schema and a type-safe extension type. Use `@AckField` for field-level constraints:
100+
To use code generation, annotate your classes with `@AckModel`. The generator creates a validation schema from your class structure. Use `@AckField` for field-level constraints:
101101

102102
```dart
103103
import 'package:ack_annotations/ack_annotations.dart';

docs/core-concepts/json-serialization.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ if (result.isOk) {
157157
}
158158
```
159159

160-
*See the [ack_generator README](../../packages/ack_generator/) for more details on code generation.*
160+
*See the [ack_generator package](https://pub.dev/packages/ack_generator) for more details on code generation.*
161161

162162
### Generating Extension Types from Standalone Schemas with `@AckType()`
163163

docs/core-concepts/typesafe-schemas.mdx

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ produce these typed views.
99

1010
## Overview
1111

12-
- `@AckModel()` goes on a **Dart class** and produces **both** a schema constant (e.g., `userSchema`) **and** an extension type named `<ClassName>Type`.
13-
- `@AckType()` goes on a **schema variable/getter** and produces **only** an extension type (the schema already exists). The type name is derived from the variable name (e.g., `userSchema``UserType`).
12+
- `@AckModel()` goes on a **Dart class** and produces a **schema constant** (e.g., `userSchema`).
13+
- `@AckType()` goes on a **schema variable/getter** and produces an **extension type** for type-safe access (the schema already exists). The type name is derived from the variable name (e.g., `userSchema``UserType`).
1414
- Both annotations live in `package:ack_annotations` and are processed by the
1515
`ack_generator` builder via `dart run build_runner build`.
1616

17-
## Typed Schemas from Classes with `@AckModel()`
17+
## Schema Generation from Classes with `@AckModel()`
1818

19-
Use `@AckModel()` when you have a Dart class that should drive schema generation. The generator creates both the validation schema and a typed wrapper.
19+
Use `@AckModel()` when you have a Dart class that should drive schema generation. The generator creates a validation schema based on your class structure.
2020

2121
```dart
2222
import 'package:ack_annotations/ack_annotations.dart';
@@ -35,12 +35,10 @@ class User {
3535
Running `dart run build_runner build` writes `user.g.dart` with:
3636

3737
- **Schema constant**: `final userSchema = Ack.object({...});`
38-
- **Extension type**: `extension type UserType(Map<String, Object?> _data)` that exposes typed getters, `parse`, `safeParse`, `toJson`, `copyWith`, and equality.
3938

40-
You can use either the schema directly or the generated extension type:
39+
You can use the generated schema for validation:
4140

4241
```dart
43-
// Option 1: Use the schema directly (returns Map<String, Object?>)
4442
final result = userSchema.safeParse(json);
4543
if (result.isOk) {
4644
final data = result.getOrThrow();
@@ -49,16 +47,10 @@ if (result.isOk) {
4947
age: data['age'] as int,
5048
);
5149
}
52-
53-
// Option 2: Use the extension type (returns UserType)
54-
final result = UserType.safeParse(json);
55-
if (result.isOk) {
56-
final user = result.getOrThrow();
57-
print(user.name); // -> String (type-safe!)
58-
print(user.age); // -> int (type-safe!)
59-
}
6050
```
6151

52+
For type-safe access without manual casting, add `@AckType()` to the generated schema variable (see below).
53+
6254
### Discriminated Hierarchies
6355

6456
Annotate an abstract base with `discriminatedKey` and each subtype with a
@@ -145,16 +137,16 @@ behave like `String`, `int`, etc., while object wrappers implement
145137

146138
| Annotation | Target | Generates Schema? | Generates Extension Type? | Use When |
147139
|------------|--------|-------------------|---------------------------|----------|
148-
| `@AckModel` | Dart class | ✅ Yes | ✅ Yes | You have a class definition and want both validation and typed access |
149-
| `@AckType` | Schema variable | ❌ No (uses existing) | ✅ Yes | You already wrote the schema manually and just want typed access |
140+
| `@AckModel` | Dart class | ✅ Yes | ❌ No | You have a class definition and want schema generation |
141+
| `@AckType` | Schema variable | ❌ No (uses existing) | ✅ Yes | You have a schema and want type-safe access |
150142

151143
**Examples:**
152144

153-
- Use **`@AckModel`** when you have a Dart class (or class hierarchy) that should drive schema generation. The generator creates both the schema and the extension type.
145+
- Use **`@AckModel`** when you have a Dart class (or class hierarchy) that should drive schema generation.
154146

155-
- Use **`@AckType`** for hand-written schemas, shared schema fragments, or when you need typed access to a structure that doesn't have a corresponding Dart class.
147+
- Use **`@AckType`** on schema variables (either hand-written or generated by `@AckModel`) when you want type-safe extension type access.
156148

157-
- **Mix both**: You can reference a `@AckType` schema inside an `@AckModel` class field, or use `@AckModel` classes within `@AckType` schema definitions.
149+
- **Combine both**: Use `@AckModel` to generate the schema from your class, then use `@AckType` on the generated schema variable if you want extension type wrappers.
158150

159151
## Build Runner Checklist
160152

docs/core-concepts/validation.mdx

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,24 +133,95 @@ Ensures the string is one of the `allowedValues`.
133133
Ack.enumString(['active', 'inactive', 'pending'])
134134
```
135135

136+
### `literal(String value)`
137+
Ensures the string exactly matches the specified value.
138+
```dart
139+
Ack.string().literal('admin')
140+
```
141+
142+
### `startsWith(String prefix)`
143+
Ensures the string starts with the given prefix.
144+
```dart
145+
Ack.string().startsWith('https://')
146+
```
147+
148+
### `endsWith(String suffix)`
149+
Ensures the string ends with the given suffix.
150+
```dart
151+
Ack.string().endsWith('.dart')
152+
```
153+
154+
### `url()`
155+
Alias for `uri()`. Ensures the string is a valid URL.
156+
```dart
157+
Ack.string().url()
158+
```
159+
160+
### `ip({int? version})`
161+
Ensures the string is a valid IP address. Optionally specify version 4 or 6.
162+
```dart
163+
Ack.string().ip() // Any IP (v4 or v6)
164+
Ack.string().ip(version: 4) // IPv4 only
165+
Ack.string().ip(version: 6) // IPv6 only
166+
```
167+
168+
## String Transformations
169+
170+
These methods transform the string value during parsing. They don't add validation constraints but modify the output value.
171+
172+
### `trim()`
173+
Removes leading and trailing whitespace from the string.
174+
```dart
175+
Ack.string().trim()
176+
// " hello " → "hello"
177+
```
178+
179+
### `toLowerCase()`
180+
Converts the string to lowercase.
181+
```dart
182+
Ack.string().toLowerCase()
183+
// "HELLO" → "hello"
184+
```
185+
186+
### `toUpperCase()`
187+
Converts the string to uppercase.
188+
```dart
189+
Ack.string().toUpperCase()
190+
// "hello" → "HELLO"
191+
```
192+
136193
## Number Constraints (Int and Double)
137194

138195
Apply these to [`Ack.integer()`](./schemas.mdx#number-schemas) and [`Ack.double()`](./schemas.mdx#number-schemas) schemas.
139196

140197
### `min(num limit)`
141-
Ensures the number is greater than or equal to the `limit`.
198+
Ensures the number is greater than or equal to the `limit` (inclusive).
142199
```dart
143200
Ack.integer().min(0) // >= 0
144201
Ack.double().min(0.0) // >= 0.0
145202
```
146203

147204
### `max(num limit)`
148-
Ensures the number is less than or equal to the `limit`.
205+
Ensures the number is less than or equal to the `limit` (inclusive).
149206
```dart
150207
Ack.integer().max(100) // <= 100
151208
Ack.double().max(100.0) // <= 100.0
152209
```
153210

211+
### `greaterThan(num limit)`
212+
Ensures the number is strictly greater than the `limit` (exclusive).
213+
```dart
214+
Ack.integer().greaterThan(0) // > 0
215+
Ack.double().greaterThan(0.0) // > 0.0
216+
```
217+
218+
### `lessThan(num limit)`
219+
Ensures the number is strictly less than the `limit` (exclusive).
220+
```dart
221+
Ack.integer().lessThan(100) // < 100
222+
Ack.double().lessThan(100.0) // < 100.0
223+
```
224+
154225
### `multipleOf(num factor)`
155226
Ensures the number is a multiple of the `factor`.
156227
```dart
@@ -172,6 +243,18 @@ Ack.integer().negative() // < 0
172243
Ack.double().negative() // < 0.0
173244
```
174245

246+
### `safe()` (Integer only)
247+
Ensures the integer is within the safe integer range for JavaScript interoperability (-2^53+1 to 2^53-1).
248+
```dart
249+
Ack.integer().safe()
250+
```
251+
252+
### `finite()` (Double only)
253+
Ensures the double is a finite number (not `infinity` or `NaN`).
254+
```dart
255+
Ack.double().finite()
256+
```
257+
175258
## List Constraints
176259

177260
Apply these to [`Ack.list()`](./schemas.mdx#list-schema) schemas.

docs/guides/creating-schema-converter-packages.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ dart test # or flutter test if using Flutter
11251125

11261126
## Contributing
11271127

1128-
For contribution guidelines, see [CONTRIBUTING.md](../../CONTRIBUTING.md) in the root repository.
1128+
For contribution guidelines, see the [CONTRIBUTING.md](https://github.com/btwld/ack/blob/main/CONTRIBUTING.md) in the root repository.
11291129

11301130
## License
11311131

docs/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Ack provides a comprehensive set of features for data validation and transformat
6767
- **[Validation Rules](/core-concepts/validation)**: Apply constraints like length, range, pattern matching, and custom validators
6868
- **[Error Handling](/core-concepts/error-handling)**: Get detailed, structured error messages for validation failures
6969
- **[JSON Serialization](/core-concepts/json-serialization)**: Convert between JSON and typed models
70-
- **[Schema Validation](/core-concepts/typesafe-schemas)**: Comprehensive schema validation with fluent API
70+
- **[Configuration](/core-concepts/configuration)**: Schema-level configuration options
7171

7272
## Next Steps
7373

example/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ environment:
99
sdk: '>=3.8.0 <4.0.0'
1010

1111
dependencies:
12-
ack: ^1.0.0-beta.4
12+
ack: any
1313

1414
dev_dependencies:
15-
ack_generator: ^1.0.0-beta.1
15+
ack_generator: any
1616
build_runner: ^2.4.0
1717
dart_code_metrics_presets: ^2.22.0
1818
lints: ^5.0.0

packages/ack_annotations/README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,23 @@ Annotation package for the Ack validation ecosystem. Use these annotations on yo
66

77
## Installation
88

9+
Add to your `pubspec.yaml` (check [pub.dev](https://pub.dev/packages/ack_annotations) for the latest versions):
10+
911
```yaml
1012
dependencies:
11-
ack_annotations: ^1.0.0-beta.1
13+
ack_annotations: ^1.0.0
1214

1315
dev_dependencies:
14-
ack_generator: ^1.0.0-beta.1
16+
ack_generator: ^1.0.0
1517
build_runner: ^2.4.0
1618
```
1719
18-
> Still on the 0.3 alpha line? Use `^0.3.0-alpha.0` for all Ack packages until you migrate to `1.0.0-beta.1`.
20+
Or use the Dart CLI:
21+
22+
```bash
23+
dart pub add ack_annotations
24+
dart pub add --dev ack_generator build_runner
25+
```
1926

2027
---
2128

@@ -128,7 +135,7 @@ Mix and match annotation-based constraints with the string list syntax from `@Ac
128135

129136
## Working With build_runner
130137

131-
1. Make sure all Ack packages are on matching versions (either the 0.3 alpha train or the 1.0.0 release).
138+
1. Make sure all Ack packages are on matching versions.
132139
2. Run `dart run build_runner build --delete-conflicting-outputs` after changing annotated classes.
133140
3. For continuous development, `dart run build_runner watch` keeps schemas in sync.
134141

packages/ack_annotations/lib/src/ack_model.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import 'package:meta/meta_meta.dart';
22

3-
/// Annotation to mark a class for schema and extension type generation.
3+
/// Annotation to mark a class for schema generation.
44
///
5-
/// Generates both a schema for validation and an extension type for type-safe access.
6-
/// For schema variables, use [@AckType] instead.
5+
/// Generates a schema constant for validating data against your class structure.
6+
/// For type-safe access to validated data, use [@AckType] on schema variables.
77
///
88
/// This annotation can be used in two main ways:
99
///
1010
/// ## Regular Models
11-
/// Generate schema validation and extension type for a class:
11+
/// Generate schema validation for a class:
1212
/// ```dart
1313
/// @AckModel()
1414
/// class User {

0 commit comments

Comments
 (0)