Skip to content

Commit 1a9092d

Browse files
committed
docs: add annotation catalog for serialization and validation annotations and some smaller changes
1 parent 974dc7b commit 1a9092d

File tree

6 files changed

+143
-42
lines changed

6 files changed

+143
-42
lines changed

docs/advanced/operation_modes.md

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,52 +17,22 @@ Map<Type, OperationMode<DateTime> Function()> get modes => {
1717
```
1818

1919
## Mode Registry
20-
Operation modes are always resolved through the `OperationModeRegistry`. This registry serves
20+
Operation modes are always resolved through the engine's `OperationModeRegistry`. This registry serves
2121
as a central cache and mapping from converters and types to operation mode entries. Child engines
2222
will always have their independent operation mode registry.
2323

24-
!!! success "Modes do not need to be registered!"
25-
The registration is handled on the fly by the `OperationModeRegistry`. If a mode is not found
26-
in the registry, the registry will try to infer the operation mode using the `OperationModeFactory`
27-
28-
## Operation Mode Factories
29-
If an operation mode is not found in the registry, the registry will try infer the operation mode
30-
using the `OperationModeFactory` list of its engine. Those factories can provide operation modes
31-
for converters that do not define the required operation modes themselves. Using this mechanism,
32-
packages can provide operation modes for converters that are not under their control. This feature
33-
is used by the `dogs_forms` package to provide operation modes for the `AutoFormFieldFactory`.
34-
35-
The `OperationModeFactory` class defines several static functions that can be used to create
36-
and combine factories for specific converter or structure types.
37-
```dart title="Default factory composition for dogs_forms"
38-
final defaultFormFactories = OperationModeFactory.compose<AutoFormFieldFactory>([
39-
OperationModeFactory.converterSingleton<NativeRetentionConverter<String>,
40-
AutoFormFieldFactory>(const TextFieldFormFieldFactory()),
41-
// [...]
42-
ListFieldOperationModeFactory<String>(const TextFieldFormFieldFactory()),
43-
ListFieldOperationModeFactory<int>(const IntTextFieldFormFieldFactory()),
44-
// [...]
45-
EnumOpmodeFactory(),
46-
StructureOpmodeFactory(),
47-
]);
48-
49-
```
24+
Operation modes are always first looked up in the registry. For misses, the registry will first try to resolve
25+
the operation mode through the converter itself. If the converter does not provide the requested
26+
operation mode, the registry will try to infer the operation mode using the `OperationModeFactory`s registered in
27+
the current engine instance.
5028

5129
## Examples
5230
### NativeSerializerMode
5331
The native operation mode is the most basic operation mode. It is used to serialize and deserialize
54-
objects to and from dart maps that can be directly serialized to json. Most of the dogs library
32+
objects to and from dart maps that can be directly serialized to JSON. Most of the dogs library
5533
is built around this operation mode.
5634

57-
!!! tip "Not only for serialization!"
58-
The operation modes are not only used to serialize and deserialize objects,
59-
but can also to provide additional functionality like validation and introspection.
60-
6135
### ValidationMode
6236
The validation operation mode is used to validate objects. It is used by the `@validate` annotation
6337
and can be used to validate objects before they are serialized, or to validate objects that have
64-
been deserialized.
65-
66-
### AutoFormFieldFactory
67-
While the name may be a bit misleading, the auto form field factory is also an operation mode that
68-
is used to derive flutter form fields from structures.
38+
been deserialized.

docs/advanced/schema.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Schemas ![Static Badge](https://img.shields.io/badge/experimental-orange)
1+
# Schemas ![](https://img.shields.io/badge/experimental-orange)
22

33
The library can **generate schema definitions** for all converters that support it and can **also regenerate**
44
'materialize' **structures** from those **schema definitions**. The schema definition format is JSON-based and a

docs/annotation_catalog.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
---
2+
icon: octicons/book-16
3+
---
4+
5+
# Annotation Catalog
6+
## Serialization Annotations
7+
<div class="grid cards" markdown>
8+
9+
- ![](https://img.shields.io/badge/class-seagreen){ .lg .middle }
10+
![](https://img.shields.io/badge/enum-orange){ .lg .middle }
11+
__Structure__
12+
13+
---
14+
Generates a structure for the target. `serialName` can be specified to change the identifier used.
15+
`serializable: false` can be used to only generate structures.
16+
17+
- ![](https://img.shields.io/badge/class-seagreen){ .lg .middle }
18+
![](https://img.shields.io/badge/enum-orange){ .lg .middle }
19+
__Serializable / serializable__
20+
21+
---
22+
Aliases for serializable `Structures`. `serialName` can be specified to change the identifier used.
23+
24+
- ![](https://img.shields.io/badge/enum--constant-orange){ .lg .middle }
25+
__EnumProperty__
26+
27+
---
28+
The name of the enum constant can be overridden using the `name` parameter. Additionally,
29+
a single constant can be marked as `fallback` to handle invalid enum values.
30+
31+
- ![](https://img.shields.io/badge/property-blue){ .lg .middle }
32+
__polymorphic__
33+
34+
---
35+
Marks a field as polymorphic so that the actual runtime type is used for serialization.
36+
37+
- ![](https://img.shields.io/badge/property-blue){ .lg .middle }
38+
__PropertySerializer__
39+
40+
---
41+
Specifies the type of custom converter to be used for this fields' serialization.
42+
43+
- ![](https://img.shields.io/badge/property-blue){ .lg .middle }
44+
__PropertyName__
45+
46+
---
47+
Changes the name of the property used in serialization.
48+
49+
- ![](https://img.shields.io/badge/property-blue){ .lg .middle }
50+
__DefaultValue__
51+
52+
---
53+
Sets a default value for the field. If `keep` is `false`, the field will be omitted in serialization if it has the default value.
54+
55+
- ![](https://img.shields.io/badge/class-seagreen){ .lg .middle }
56+
![](https://img.shields.io/badge/property-blue){ .lg .middle }
57+
__excludeNull__
58+
59+
---
60+
If applied to a member, direct null values will be excluded from serialization.
61+
62+
- ![](https://img.shields.io/badge/class-seagreen){ .lg .middle }
63+
__LightweightMigration__
64+
65+
---
66+
Applies a list of functions on deserialization to migrate data from older versions.
67+
68+
- ![](https://img.shields.io/badge/class-seagreen){ .lg .middle }
69+
__RevisionMigration__
70+
71+
---
72+
Applies migrations based on the revision number added to the map output.
73+
74+
</div>
75+
76+
## Validation Annotations
77+
<div class="grid cards" markdown>
78+
79+
- ![](https://img.shields.io/badge/string-seagreen){ .lg .middle }
80+
![](https://img.shields.io/badge/or-many-slategray){ .lg .middle }
81+
__LengthRange__
82+
- ![](https://img.shields.io/badge/string-seagreen){ .lg .middle }
83+
![](https://img.shields.io/badge/or-many-slategray){ .lg .middle }
84+
__Regex__
85+
- ![](https://img.shields.io/badge/string-seagreen){ .lg .middle }
86+
![](https://img.shields.io/badge/or-many-slategray){ .lg .middle }
87+
__email__
88+
- ![](https://img.shields.io/badge/string-seagreen){ .lg .middle }
89+
![](https://img.shields.io/badge/or-many-slategray){ .lg .middle }
90+
__notBlank__
91+
92+
- ![](https://img.shields.io/badge/num-blue){ .lg .middle }
93+
![](https://img.shields.io/badge/or-many-slategray){ .lg .middle }
94+
__Range__
95+
- ![](https://img.shields.io/badge/num-blue){ .lg .middle }
96+
![](https://img.shields.io/badge/or-many-slategray){ .lg .middle }
97+
__Minimum__
98+
- ![](https://img.shields.io/badge/num-blue){ .lg .middle }
99+
![](https://img.shields.io/badge/or-many-slategray){ .lg .middle }
100+
__Maximum__
101+
- ![](https://img.shields.io/badge/num-blue){ .lg .middle }
102+
![](https://img.shields.io/badge/or-many-slategray){ .lg .middle }
103+
__positive__
104+
- ![](https://img.shields.io/badge/num-blue){ .lg .middle }
105+
![](https://img.shields.io/badge/or-many-slategray){ .lg .middle }
106+
__positiveOrZero__
107+
- ![](https://img.shields.io/badge/num-blue){ .lg .middle }
108+
![](https://img.shields.io/badge/or-many-slategray){ .lg .middle }
109+
__negative__
110+
- ![](https://img.shields.io/badge/num-blue){ .lg .middle }
111+
![](https://img.shields.io/badge/or-many-slategray){ .lg .middle }
112+
__negativeOrZero__
113+
- ![](https://img.shields.io/badge/iterable-slategray){ .lg .middle }
114+
__SizeRange__
115+
- ![](https://img.shields.io/badge/any-red){ .lg .middle }
116+
![](https://img.shields.io/badge/or-many-slategray){ .lg .middle }
117+
__validated__
118+
119+
</div>

docs/quickstart.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
icon: octicons/book-16
2+
icon: octicons/zap-16
33
---
44

55
``` { .dart .focus hl_lines="3 6-9" }
@@ -59,6 +59,4 @@ IconButton(
5959
```
6060

6161
We then add a button to share the entry as JSON. The `dogs.toJson` method is used to convert the entry to a JSON string,
62-
that is then display in a dialog.
63-
64-
62+
that is then display in a dialog.

docs/stylesheets/theme-tweaks.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,17 @@ iframe {
207207
overflow: hidden !important;
208208
padding: 0;
209209
background-color: black;
210+
}
211+
212+
div.cards li {
213+
border-radius: var(--md-border-radius) !important;
214+
}
215+
216+
div.cards hr {
217+
margin-top: 0.5em !important;
218+
margin-bottom: 0.5em !important;
219+
}
220+
221+
div.cards strong:first-of-type {
222+
margin-left: 4px;
210223
}

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ nav:
2828
- index.md
2929
- installation.md
3030
- quickstart.md
31+
- annotation_catalog.md
3132
- "Basics":
3233
- basics/serializables.md
3334
- basics/serialization.md

0 commit comments

Comments
 (0)