2018-11-03 07:13:19 +00:00
|
|
|
export 'package:quiver_hashcode/hashcode.dart' show hashObjects;
|
|
|
|
|
2017-06-17 01:26:19 +00:00
|
|
|
/// Excludes a field from being excluded.
|
2019-01-07 00:56:05 +00:00
|
|
|
@deprecated
|
2017-06-17 01:26:19 +00:00
|
|
|
class Exclude {
|
2018-02-28 21:04:58 +00:00
|
|
|
final bool canSerialize;
|
|
|
|
|
|
|
|
final bool canDeserialize;
|
|
|
|
|
|
|
|
const Exclude({this.canDeserialize: false, this.canSerialize: false});
|
2017-06-17 01:26:19 +00:00
|
|
|
}
|
|
|
|
|
2019-01-07 00:56:05 +00:00
|
|
|
@deprecated
|
|
|
|
// ignore: deprecated_member_use
|
2017-06-17 01:26:19 +00:00
|
|
|
const Exclude exclude = const Exclude();
|
|
|
|
|
2019-01-06 23:50:33 +00:00
|
|
|
@deprecated
|
|
|
|
|
|
|
|
/// Prefer [SerializableField] instead.
|
2018-05-15 19:54:32 +00:00
|
|
|
class DefaultValue {
|
|
|
|
final value;
|
|
|
|
|
|
|
|
const DefaultValue(this.value);
|
|
|
|
}
|
|
|
|
|
2019-01-06 23:50:33 +00:00
|
|
|
/// Attaches options to a field.
|
|
|
|
class SerializableField {
|
|
|
|
/// An alternative name for this field.
|
|
|
|
final String alias;
|
|
|
|
|
|
|
|
/// A default for this field.
|
|
|
|
final defaultValue;
|
|
|
|
|
|
|
|
/// A custom serializer for this field.
|
|
|
|
final Symbol serializer;
|
|
|
|
|
|
|
|
/// A custom serializer for this field.
|
|
|
|
final Symbol deserializer;
|
|
|
|
|
2019-01-07 00:56:05 +00:00
|
|
|
/// An error message to be printed when the provided value is invalid.
|
|
|
|
final String errorMessage;
|
|
|
|
|
|
|
|
/// Whether this field can be set to `null`.
|
|
|
|
final bool isNullable;
|
|
|
|
|
|
|
|
/// Whether to exclude this field from serialization. Defaults to `false`.
|
|
|
|
final bool exclude;
|
|
|
|
|
|
|
|
/// Whether this field can be serialized, if [exclude] is `true`. Defaults to `false`.
|
|
|
|
final bool canDeserialize;
|
2019-01-06 23:50:33 +00:00
|
|
|
|
2019-01-07 00:56:05 +00:00
|
|
|
/// Whether this field can be serialized, if [exclude] is `true`. Defaults to `false`.
|
|
|
|
final bool canSerialize;
|
|
|
|
|
|
|
|
const SerializableField(
|
2019-01-06 23:50:33 +00:00
|
|
|
{this.alias,
|
|
|
|
this.defaultValue,
|
|
|
|
this.serializer,
|
|
|
|
this.deserializer,
|
2019-01-07 00:56:05 +00:00
|
|
|
this.errorMessage,
|
|
|
|
this.isNullable: true,
|
|
|
|
this.exclude: false,
|
|
|
|
this.canDeserialize: false,
|
|
|
|
this.canSerialize: false});
|
2019-01-06 23:50:33 +00:00
|
|
|
}
|
|
|
|
|
2017-06-17 01:26:19 +00:00
|
|
|
/// Marks a class as eligible for serialization.
|
|
|
|
class Serializable {
|
2018-02-28 00:46:35 +00:00
|
|
|
const Serializable(
|
2018-02-28 00:47:42 +00:00
|
|
|
{this.serializers: const [Serializers.map, Serializers.json],
|
2018-02-28 00:46:35 +00:00
|
|
|
this.autoSnakeCaseNames: true,
|
2019-01-07 00:56:05 +00:00
|
|
|
this.autoIdAndDateFields: true,
|
|
|
|
this.includeAnnotations: const []});
|
2018-02-28 00:46:35 +00:00
|
|
|
|
|
|
|
/// A list of enabled serialization modes.
|
|
|
|
///
|
|
|
|
/// See [Serializers].
|
|
|
|
final List<int> serializers;
|
|
|
|
|
|
|
|
/// Overrides the setting in `SerializerGenerator`.
|
|
|
|
final bool autoSnakeCaseNames;
|
|
|
|
|
|
|
|
/// Overrides the setting in `JsonModelGenerator`.
|
|
|
|
final bool autoIdAndDateFields;
|
2019-01-07 00:56:05 +00:00
|
|
|
|
|
|
|
/// A list of constant members to affix to the generated class.
|
|
|
|
final List includeAnnotations;
|
2017-06-17 01:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const Serializable serializable = const Serializable();
|
|
|
|
|
2018-07-11 15:45:45 +00:00
|
|
|
/// Used by `package:angel_serialize_generator` to reliably identify generated models.
|
|
|
|
class GeneratedSerializable {
|
|
|
|
const GeneratedSerializable();
|
|
|
|
}
|
|
|
|
|
2018-07-11 15:49:46 +00:00
|
|
|
const GeneratedSerializable generatedSerializable =
|
|
|
|
const GeneratedSerializable();
|
2018-07-11 15:45:45 +00:00
|
|
|
|
2018-02-28 00:46:35 +00:00
|
|
|
/// The supported serialization types.
|
|
|
|
abstract class Serializers {
|
2018-02-28 00:59:43 +00:00
|
|
|
/// All supported serialization types.
|
2018-03-29 19:58:36 +00:00
|
|
|
static const List<int> all = const [map, json, typescript];
|
2018-02-28 00:59:43 +00:00
|
|
|
|
2018-02-28 00:46:35 +00:00
|
|
|
/// Enable `fromMap` and `toMap` methods on the model class.
|
2018-02-28 00:47:42 +00:00
|
|
|
static const int map = 0;
|
2018-02-28 00:46:35 +00:00
|
|
|
|
|
|
|
/// Enable a `toJson` method on the model class.
|
2018-02-28 00:47:42 +00:00
|
|
|
static const int json = 1;
|
2018-03-29 19:58:36 +00:00
|
|
|
|
|
|
|
/// Generate a TypeScript definition file (`.d.ts`) for use on the client-side.
|
|
|
|
static const int typescript = 2;
|
2018-02-28 00:46:35 +00:00
|
|
|
}
|
|
|
|
|
2019-01-06 23:50:33 +00:00
|
|
|
@deprecated
|
|
|
|
|
|
|
|
/// Prefer [SerializableField] instead.
|
2017-06-17 01:26:19 +00:00
|
|
|
class Alias {
|
|
|
|
final String name;
|
2018-02-28 00:46:35 +00:00
|
|
|
|
2017-06-17 01:26:19 +00:00
|
|
|
const Alias(this.name);
|
2018-02-28 00:46:35 +00:00
|
|
|
}
|