@@ -7,15 +7,17 @@ import 'dart:convert';
77import 'package:build/build.dart' hide Builder;
88import 'package:built_collection/built_collection.dart' ;
99import 'package:built_value/built_value.dart' ;
10+ import 'package:built_value/serializer.dart' ;
1011import 'package:crypto/crypto.dart' ;
11- import 'package:glob/glob.dart' ;
1212
1313import '../generate/phase.dart' ;
1414
1515part 'node.g.dart' ;
1616
1717/// Types of [AssetNode] .
1818class NodeType extends EnumClass {
19+ static Serializer <NodeType > get serializer => _$nodeTypeSerializer;
20+
1921 static const NodeType builderOptions = _$builderOptions;
2022 static const NodeType generated = _$generated;
2123 static const NodeType glob = _$glob;
@@ -33,6 +35,8 @@ class NodeType extends EnumClass {
3335
3436/// A node in the asset graph which may be an input to other assets.
3537abstract class AssetNode implements Built <AssetNode , AssetNodeBuilder > {
38+ static Serializer <AssetNode > get serializer => _$assetNodeSerializer;
39+
3640 AssetId get id;
3741 NodeType get type;
3842
@@ -219,7 +223,7 @@ abstract class AssetNode implements Built<AssetNode, AssetNodeBuilder> {
219223 factory AssetNode .glob (
220224 AssetId id, {
221225 Digest ? lastKnownDigest,
222- required Glob glob,
226+ required String glob,
223227 required int phaseNumber,
224228 Iterable <AssetId >? inputs,
225229 required PendingBuildAction pendingBuildAction,
@@ -236,11 +240,8 @@ abstract class AssetNode implements Built<AssetNode, AssetNodeBuilder> {
236240 ..lastKnownDigest = lastKnownDigest,
237241 );
238242
239- static AssetId createGlobNodeId (String package, Glob glob, int phaseNum) =>
240- AssetId (
241- package,
242- 'glob.$phaseNum .${base64 .encode (utf8 .encode (glob .pattern ))}' ,
243- );
243+ static AssetId createGlobNodeId (String package, String glob, int phaseNum) =>
244+ AssetId (package, 'glob.$phaseNum .${base64 .encode (utf8 .encode (glob ))}' );
244245
245246 /// A [primaryInput] to a [PostBuildAction] .
246247 ///
@@ -313,6 +314,9 @@ abstract class AssetNode implements Built<AssetNode, AssetNodeBuilder> {
313314abstract class GeneratedNodeConfiguration
314315 implements
315316 Built <GeneratedNodeConfiguration , GeneratedNodeConfigurationBuilder > {
317+ static Serializer <GeneratedNodeConfiguration > get serializer =>
318+ _$generatedNodeConfigurationSerializer;
319+
316320 /// The primary input which generated this node.
317321 AssetId get primaryInput;
318322
@@ -342,6 +346,9 @@ abstract class GeneratedNodeConfiguration
342346/// State for an [AssetNode.generated] that changes during the build.
343347abstract class GeneratedNodeState
344348 implements Built <GeneratedNodeState , GeneratedNodeStateBuilder > {
349+ static Serializer <GeneratedNodeState > get serializer =>
350+ _$generatedNodeStateSerializer;
351+
345352 /// All the inputs that were read when generating this asset, or deciding not
346353 /// to generate it.
347354 BuiltSet <AssetId > get inputs;
@@ -373,7 +380,10 @@ abstract class GeneratedNodeState
373380/// Additional configuration for an [AssetNode.glob] .
374381abstract class GlobNodeConfiguration
375382 implements Built <GlobNodeConfiguration , GlobNodeConfigurationBuilder > {
376- Glob get glob;
383+ static Serializer <GlobNodeConfiguration > get serializer =>
384+ _$globNodeConfigurationSerializer;
385+
386+ String get glob;
377387 int get phaseNumber;
378388
379389 factory GlobNodeConfiguration (
@@ -386,6 +396,10 @@ abstract class GlobNodeConfiguration
386396/// State for an [AssetNode.glob] that changes during the build.
387397abstract class GlobNodeState
388398 implements Built <GlobNodeState , GlobNodeStateBuilder > {
399+ static Serializer <GlobNodeState > get serializer => _$globNodeStateSerializer;
400+
401+ /// The next work that needs doing on this node.
402+
389403 /// All the potential inputs matching this glob.
390404 ///
391405 /// This field differs from [results] in that [AssetNode.generated] which may
@@ -412,6 +426,9 @@ abstract class PostProcessAnchorNodeConfiguration
412426 PostProcessAnchorNodeConfiguration ,
413427 PostProcessAnchorNodeConfigurationBuilder
414428 > {
429+ static Serializer <PostProcessAnchorNodeConfiguration > get serializer =>
430+ _$postProcessAnchorNodeConfigurationSerializer;
431+
415432 int get actionNumber;
416433 AssetId get builderOptionsId;
417434 AssetId get primaryInput;
@@ -427,6 +444,9 @@ abstract class PostProcessAnchorNodeConfiguration
427444abstract class PostProcessAnchorNodeState
428445 implements
429446 Built <PostProcessAnchorNodeState , PostProcessAnchorNodeStateBuilder > {
447+ static Serializer <PostProcessAnchorNodeState > get serializer =>
448+ _$postProcessAnchorNodeStateSerializer;
449+
430450 Digest ? get previousInputsDigest;
431451
432452 factory PostProcessAnchorNodeState (
@@ -438,6 +458,9 @@ abstract class PostProcessAnchorNodeState
438458
439459/// Work that needs doing for a node that tracks its inputs.
440460class PendingBuildAction extends EnumClass {
461+ static Serializer <PendingBuildAction > get serializer =>
462+ _$pendingBuildActionSerializer;
463+
441464 static const PendingBuildAction none = _$none;
442465 static const PendingBuildAction buildIfInputsChanged = _$buildIfInputsChanged;
443466 static const PendingBuildAction build = _$build;
@@ -448,3 +471,59 @@ class PendingBuildAction extends EnumClass {
448471 static PendingBuildAction valueOf (String name) =>
449472 _$pendingBuildActionValueOf (name);
450473}
474+
475+ @SerializersFor ([AssetNode ])
476+ final Serializers serializers =
477+ (_$serializers.toBuilder ()
478+ ..add (AssetIdSerializer ())
479+ ..add (DigestSerializer ()))
480+ .build ();
481+
482+ /// Serializer for [AssetId] .
483+ ///
484+ /// It would also work to make `AssetId` a `built_value` class, but there's
485+ /// little benefit and it's nicer to keep codegen local to this package.
486+ class AssetIdSerializer implements PrimitiveSerializer <AssetId > {
487+ @override
488+ Iterable <Type > get types => [AssetId ];
489+
490+ @override
491+ String get wireName => 'AssetId' ;
492+
493+ @override
494+ AssetId deserialize (
495+ Serializers serializers,
496+ Object serialized, {
497+ FullType specifiedType = FullType .unspecified,
498+ }) => AssetId .parse (serialized as String );
499+
500+ @override
501+ Object serialize (
502+ Serializers serializers,
503+ AssetId object, {
504+ FullType specifiedType = FullType .unspecified,
505+ }) => object.toString ();
506+ }
507+
508+ /// Serializer for [Digest] .
509+ class DigestSerializer implements PrimitiveSerializer <Digest > {
510+ @override
511+ Iterable <Type > get types => [Digest ];
512+
513+ @override
514+ String get wireName => 'Digest' ;
515+
516+ @override
517+ Digest deserialize (
518+ Serializers serializers,
519+ Object serialized, {
520+ FullType specifiedType = FullType .unspecified,
521+ }) => Digest (base64.decode (serialized as String ));
522+
523+ @override
524+ Object serialize (
525+ Serializers serializers,
526+ Digest object, {
527+ FullType specifiedType = FullType .unspecified,
528+ }) => base64.encode (object.bytes);
529+ }
0 commit comments