From fc19155f7cd736d9f1b8021c570cf727bfacb830 Mon Sep 17 00:00:00 2001 From: Gabber235 Date: Sun, 10 Nov 2024 19:07:04 +0100 Subject: [PATCH] Fix complex blueprint serialization --- app/build.yaml | 23 ++++++++++++ app/lib/models/entry.dart | 3 +- app/lib/models/entry_blueprint.dart | 4 +-- app/lib/models/entry_blueprint.g.dart | 35 ++++++++++--------- app/lib/models/extension.g.dart | 4 +-- app/lib/models/page.g.dart | 4 +-- .../widgets/components/app/entry_node.g.dart | 8 ++--- .../widgets/components/app/entry_search.dart | 1 + .../components/app/entry_search.g.dart | 2 +- .../components/app/static_entries_list.g.dart | 2 +- app/lib/widgets/inspector/editors.g.dart | 6 ++-- .../widgets/inspector/editors/generic.dart | 2 ++ .../widgets/inspector/editors/variable.dart | 5 +-- app/lib/widgets/inspector/header.g.dart | 2 +- .../inspector/headers/variable_action.dart | 1 + app/lib/widgets/inspector/heading.g.dart | 10 +++--- 16 files changed, 71 insertions(+), 41 deletions(-) create mode 100644 app/build.yaml diff --git a/app/build.yaml b/app/build.yaml new file mode 100644 index 0000000000..34d8f8d279 --- /dev/null +++ b/app/build.yaml @@ -0,0 +1,23 @@ +targets: + $default: + builders: + json_serializable: + options: + # Options configure how source code is generated for every + # `@JsonSerializable`-annotated class in the package. + # + # The default value for each is listed. + any_map: false + checked: false + constructor: "" + create_factory: true + create_field_map: false + create_json_keys: false + create_per_field_to_json: false + create_to_json: true + disallow_unrecognized_keys: false + explicit_to_json: true + field_rename: none + generic_argument_factories: false + ignore_unannotated: false + include_if_null: true diff --git a/app/lib/models/entry.dart b/app/lib/models/entry.dart index 2efd1cb346..e1a1c04302 100644 --- a/app/lib/models/entry.dart +++ b/app/lib/models/entry.dart @@ -83,7 +83,7 @@ class Entry { : "Blueprint is not generic but a generic blueprint was provided", ), assert( - !blueprint.isGeneric || blueprint.allowsGeneric(genericBlueprint), + blueprint.allowsGeneric(genericBlueprint), "Generic blueprint given is not allowed for this blueprint, blueprint: ${blueprint.id}, allowed: ${blueprint.genericConstraints}, genericBlueprint: $genericBlueprint", ), data = { @@ -120,6 +120,7 @@ class Entry { DataBlueprint? get genericBlueprint { if (_genericBlueprint != null) return _genericBlueprint; final genericBlueprint = data["_genericBlueprint"]; + print("Generic blueprint: $genericBlueprint"); if (genericBlueprint == null) return null; if (genericBlueprint is! Map) { diff --git a/app/lib/models/entry_blueprint.dart b/app/lib/models/entry_blueprint.dart index 6f1c2e338d..69e9078b2a 100644 --- a/app/lib/models/entry_blueprint.dart +++ b/app/lib/models/entry_blueprint.dart @@ -188,9 +188,9 @@ extension EntryBlueprintExt on EntryBlueprint { bool get isGeneric => genericConstraints != null; bool allowsGeneric(DataBlueprint? genericBlueprint) { - if (genericBlueprint == null) return false; final blueprints = genericConstraints; - if (blueprints == null) return false; + if (blueprints == null) return true; + if (genericBlueprint == null) return false; // If the blueprints is empty, all blueprints are allowed. if (blueprints.isEmpty) return true; return blueprints.contains(genericBlueprint); diff --git a/app/lib/models/entry_blueprint.g.dart b/app/lib/models/entry_blueprint.g.dart index 6842401946..df4578f109 100644 --- a/app/lib/models/entry_blueprint.g.dart +++ b/app/lib/models/entry_blueprint.g.dart @@ -38,10 +38,11 @@ Map _$$EntryBlueprintImplToJson( 'name': instance.name, 'description': instance.description, 'extension': instance.extension, - 'dataBlueprint': instance.dataBlueprint, + 'dataBlueprint': instance.dataBlueprint.toJson(), 'tags': instance.tags, - 'genericConstraints': instance.genericConstraints, - 'variableDataBlueprint': instance.variableDataBlueprint, + 'genericConstraints': + instance.genericConstraints?.map((e) => e.toJson()).toList(), + 'variableDataBlueprint': instance.variableDataBlueprint?.toJson(), 'color': const ColorConverter().toJson(instance.color), 'icon': instance.icon, }; @@ -61,7 +62,7 @@ Map _$$DataBlueprintTypeImplToJson( _$DataBlueprintTypeImpl instance) => { 'default': instance.internalDefaultValue, - 'modifiers': instance.modifiers, + 'modifiers': instance.modifiers.map((e) => e.toJson()).toList(), 'kind': instance.$type, }; @@ -82,7 +83,7 @@ Map _$$PrimitiveBlueprintImplToJson( { 'type': _$PrimitiveTypeEnumMap[instance.type]!, 'default': instance.internalDefaultValue, - 'modifiers': instance.modifiers, + 'modifiers': instance.modifiers.map((e) => e.toJson()).toList(), 'kind': instance.$type, }; @@ -109,7 +110,7 @@ Map _$$EnumBlueprintImplToJson(_$EnumBlueprintImpl instance) => { 'values': instance.values, 'default': instance.internalDefaultValue, - 'modifiers': instance.modifiers, + 'modifiers': instance.modifiers.map((e) => e.toJson()).toList(), 'kind': instance.$type, }; @@ -126,9 +127,9 @@ _$ListBlueprintImpl _$$ListBlueprintImplFromJson(Map json) => Map _$$ListBlueprintImplToJson(_$ListBlueprintImpl instance) => { - 'type': instance.type, + 'type': instance.type.toJson(), 'default': instance.internalDefaultValue, - 'modifiers': instance.modifiers, + 'modifiers': instance.modifiers.map((e) => e.toJson()).toList(), 'kind': instance.$type, }; @@ -146,10 +147,10 @@ _$MapBlueprintImpl _$$MapBlueprintImplFromJson(Map json) => Map _$$MapBlueprintImplToJson(_$MapBlueprintImpl instance) => { - 'key': instance.key, - 'value': instance.value, + 'key': instance.key.toJson(), + 'value': instance.value.toJson(), 'default': instance.internalDefaultValue, - 'modifiers': instance.modifiers, + 'modifiers': instance.modifiers.map((e) => e.toJson()).toList(), 'kind': instance.$type, }; @@ -171,9 +172,9 @@ _$ObjectBlueprintImpl _$$ObjectBlueprintImplFromJson( Map _$$ObjectBlueprintImplToJson( _$ObjectBlueprintImpl instance) => { - 'fields': instance.fields, + 'fields': instance.fields.map((k, e) => MapEntry(k, e.toJson())), 'default': instance.internalDefaultValue, - 'modifiers': instance.modifiers, + 'modifiers': instance.modifiers.map((e) => e.toJson()).toList(), 'kind': instance.$type, }; @@ -195,9 +196,9 @@ _$AlgebraicBlueprintImpl _$$AlgebraicBlueprintImplFromJson( Map _$$AlgebraicBlueprintImplToJson( _$AlgebraicBlueprintImpl instance) => { - 'cases': instance.cases, + 'cases': instance.cases.map((k, e) => MapEntry(k, e.toJson())), 'default': instance.internalDefaultValue, - 'modifiers': instance.modifiers, + 'modifiers': instance.modifiers.map((e) => e.toJson()).toList(), 'kind': instance.$type, }; @@ -218,9 +219,9 @@ Map _$$CustomBlueprintImplToJson( _$CustomBlueprintImpl instance) => { 'editor': instance.editor, - 'shape': instance.shape, + 'shape': instance.shape.toJson(), 'default': instance.internalDefaultValue, - 'modifiers': instance.modifiers, + 'modifiers': instance.modifiers.map((e) => e.toJson()).toList(), 'kind': instance.$type, }; diff --git a/app/lib/models/extension.g.dart b/app/lib/models/extension.g.dart index c68e00700d..7eb4a532d2 100644 --- a/app/lib/models/extension.g.dart +++ b/app/lib/models/extension.g.dart @@ -17,8 +17,8 @@ _$ExtensionImpl _$$ExtensionImplFromJson(Map json) => Map _$$ExtensionImplToJson(_$ExtensionImpl instance) => { - 'extension': instance.extension, - 'entries': instance.entries, + 'extension': instance.extension.toJson(), + 'entries': instance.entries.map((e) => e.toJson()).toList(), }; _$ExtensionInfoImpl _$$ExtensionInfoImplFromJson(Map json) => diff --git a/app/lib/models/page.g.dart b/app/lib/models/page.g.dart index 9a2acdfc77..50bedd94bc 100644 --- a/app/lib/models/page.g.dart +++ b/app/lib/models/page.g.dart @@ -23,7 +23,7 @@ Map _$$PageImplToJson(_$PageImpl instance) => 'id': instance.id, 'name': instance.pageName, 'type': _$PageTypeEnumMap[instance.type]!, - 'entries': instance.entries, + 'entries': instance.entries.map((e) => e.toJson()).toList(), 'chapter': instance.chapter, 'priority': instance.priority, }; @@ -39,7 +39,7 @@ const _$PageTypeEnumMap = { // RiverpodGenerator // ************************************************************************** -String _$pagesHash() => r'ea54e231325c749b3affb60c0d7c761cce4f78c6'; +String _$pagesHash() => r'ee119218fa64832cac0391104a4c70960534ec13'; /// See also [pages]. @ProviderFor(pages) diff --git a/app/lib/widgets/components/app/entry_node.g.dart b/app/lib/widgets/components/app/entry_node.g.dart index 5995f2fce3..861bd56bd2 100644 --- a/app/lib/widgets/components/app/entry_node.g.dart +++ b/app/lib/widgets/components/app/entry_node.g.dart @@ -6,7 +6,7 @@ part of 'entry_node.dart'; // RiverpodGenerator // ************************************************************************** -String _$linkablePathsHash() => r'3c9be167013d314d75a71729712e367a5a890149'; +String _$linkablePathsHash() => r'47f32dd1d14d802614689ea1ed447170e1b62579'; /// Copied from Dart SDK class _SystemHash { @@ -158,7 +158,7 @@ class _LinkablePathsProviderElement } String _$linkableDuplicatePathsHash() => - r'8c2866db6d24ba1adfbdf5db004701b73bf1d54f'; + r'd56869583188c0e970986b06819f8199274e5b10'; /// See also [linkableDuplicatePaths]. @ProviderFor(linkableDuplicatePaths) @@ -289,7 +289,7 @@ class _LinkableDuplicatePathsProviderElement String get entryId => (origin as LinkableDuplicatePathsProvider).entryId; } -String _$acceptingPathsHash() => r'dc9a8e21fa7a4a25a51c810ac31f7bdc5e804e3c'; +String _$acceptingPathsHash() => r'a1dcf51daf358669037e01ee2c4175b653aaee69'; /// See also [_acceptingPaths]. @ProviderFor(_acceptingPaths) @@ -436,7 +436,7 @@ class _AcceptingPathsProviderElement String get targetId => (origin as _AcceptingPathsProvider).targetId; } -String _$writersHash() => r'991a539369dd5e8d952a9bd955779c6a4e65c69f'; +String _$writersHash() => r'9c09fe7733316dc8b78bf8aa13fffe6cc1255d5b'; /// See also [_writers]. @ProviderFor(_writers) diff --git a/app/lib/widgets/components/app/entry_search.dart b/app/lib/widgets/components/app/entry_search.dart index 5e0b991ca1..a86cb8cb40 100644 --- a/app/lib/widgets/components/app/entry_search.dart +++ b/app/lib/widgets/components/app/entry_search.dart @@ -102,6 +102,7 @@ class GenericEntryFilter extends SearchFilter { @override bool filter(SearchElement action) { if (action is EntrySearchElement) { + if (action.entry.genericBlueprint == null) return true; return action.entry.genericBlueprint == blueprint; } if (action is AddEntrySearchElement) { diff --git a/app/lib/widgets/components/app/entry_search.g.dart b/app/lib/widgets/components/app/entry_search.g.dart index 115bbdc753..6e7fc02291 100644 --- a/app/lib/widgets/components/app/entry_search.g.dart +++ b/app/lib/widgets/components/app/entry_search.g.dart @@ -6,7 +6,7 @@ part of 'entry_search.dart'; // RiverpodGenerator // ************************************************************************** -String _$fuzzyEntriesHash() => r'28564115561979b60710bda366f43f2ad2cca07d'; +String _$fuzzyEntriesHash() => r'cd87ad75094858c0a69b6c2c27538e413d63d3a4'; /// See also [_fuzzyEntries]. @ProviderFor(_fuzzyEntries) diff --git a/app/lib/widgets/components/app/static_entries_list.g.dart b/app/lib/widgets/components/app/static_entries_list.g.dart index 85be4194ff..4795c97d39 100644 --- a/app/lib/widgets/components/app/static_entries_list.g.dart +++ b/app/lib/widgets/components/app/static_entries_list.g.dart @@ -6,7 +6,7 @@ part of 'static_entries_list.dart'; // RiverpodGenerator // ************************************************************************** -String _$staticEntryIdsHash() => r'dc84b375e482ed7cb8f85addc6daf14e454f8651'; +String _$staticEntryIdsHash() => r'0cdc0873a058daa2450c0c1e1df5a4bb7360ea54'; /// See also [_staticEntryIds]. @ProviderFor(_staticEntryIds) diff --git a/app/lib/widgets/inspector/editors.g.dart b/app/lib/widgets/inspector/editors.g.dart index c372422675..daf688b03c 100644 --- a/app/lib/widgets/inspector/editors.g.dart +++ b/app/lib/widgets/inspector/editors.g.dart @@ -6,7 +6,7 @@ part of 'editors.dart'; // RiverpodGenerator // ************************************************************************** -String _$fieldValueHash() => r'aabeadcbd5808e51610fd3651d159472f99afb18'; +String _$fieldValueHash() => r'a3fbbd771e487619c7f511e3b1ebc1869503c737'; /// Copied from Dart SDK class _SystemHash { @@ -174,7 +174,7 @@ class _FieldValueProviderElement extends AutoDisposeProviderElement dynamic get defaultValue => (origin as FieldValueProvider).defaultValue; } -String _$editorFiltersHash() => r'b229025b172d9a4bbbf2494345af40da5b0fab2b'; +String _$editorFiltersHash() => r'7ed797b514356c77a02d55339c996599c23fae36'; /// See also [editorFilters]. @ProviderFor(editorFilters) @@ -191,7 +191,7 @@ final editorFiltersProvider = AutoDisposeProvider>.internal( @Deprecated('Will be removed in 3.0. Use Ref instead') // ignore: unused_element typedef EditorFiltersRef = AutoDisposeProviderRef>; -String _$pathDisplayNameHash() => r'c772e17ed429169ba903826d0a5605d60b129a31'; +String _$pathDisplayNameHash() => r'4cb4a7c76014fdfb5b467087fff861b000a9b4f2'; /// See also [pathDisplayName]. @ProviderFor(pathDisplayName) diff --git a/app/lib/widgets/inspector/editors/generic.dart b/app/lib/widgets/inspector/editors/generic.dart index b86d95b977..073714d07f 100644 --- a/app/lib/widgets/inspector/editors/generic.dart +++ b/app/lib/widgets/inspector/editors/generic.dart @@ -45,6 +45,8 @@ class GenericEditor extends HookConsumerWidget { blueprint = generic.dataBlueprint; } + print("Generic blueprint: $blueprint"); + return FieldEditor(path: path, dataBlueprint: blueprint); } diff --git a/app/lib/widgets/inspector/editors/variable.dart b/app/lib/widgets/inspector/editors/variable.dart index 031104b090..1a1645546c 100644 --- a/app/lib/widgets/inspector/editors/variable.dart +++ b/app/lib/widgets/inspector/editors/variable.dart @@ -118,8 +118,8 @@ class VariableEditor extends HookConsumerWidget { ], ), ), - const SizedBox(height: 8), - if (variableDataBlueprint != null) + if (variableDataBlueprint != null) ...[ + const SizedBox(height: 8), Header( expanded: ValueNotifier(true), canExpand: false, @@ -130,6 +130,7 @@ class VariableEditor extends HookConsumerWidget { dataBlueprint: variableDataBlueprint, ), ), + ], ], ), ), diff --git a/app/lib/widgets/inspector/header.g.dart b/app/lib/widgets/inspector/header.g.dart index 98674fae2a..d75403d724 100644 --- a/app/lib/widgets/inspector/header.g.dart +++ b/app/lib/widgets/inspector/header.g.dart @@ -7,7 +7,7 @@ part of 'header.dart'; // ************************************************************************** String _$headerActionFiltersHash() => - r'36643ca53a57e7f739cf0e3d55095cd57f39bd72'; + r'ea1c5ba81574b971b18f0a11db1c2a26cfc9430c'; /// See also [headerActionFilters]. @ProviderFor(headerActionFilters) diff --git a/app/lib/widgets/inspector/headers/variable_action.dart b/app/lib/widgets/inspector/headers/variable_action.dart index ff5650388a..a5c84d6201 100644 --- a/app/lib/widgets/inspector/headers/variable_action.dart +++ b/app/lib/widgets/inspector/headers/variable_action.dart @@ -50,6 +50,7 @@ class VariableHeaderAction extends HookConsumerWidget { ) ..fetchEntry(onSelect: (entry) => _update(ref, entry)) ..genericEntry(customBlueprint.shape) + ..tag("variable", canRemove: false) ..open(); } diff --git a/app/lib/widgets/inspector/heading.g.dart b/app/lib/widgets/inspector/heading.g.dart index e267113526..11a9634c23 100644 --- a/app/lib/widgets/inspector/heading.g.dart +++ b/app/lib/widgets/inspector/heading.g.dart @@ -6,7 +6,7 @@ part of 'heading.dart'; // RiverpodGenerator // ************************************************************************** -String _$entryIdHash() => r'aae409d674bee6b65c432d6810f2f3ad299e8a26'; +String _$entryIdHash() => r'cb034bcfd96c294238c7daa47f670e170b120069'; /// See also [_entryId]. @ProviderFor(_entryId) @@ -22,7 +22,7 @@ final _entryIdProvider = AutoDisposeProvider.internal( @Deprecated('Will be removed in 3.0. Use Ref instead') // ignore: unused_element typedef _EntryIdRef = AutoDisposeProviderRef; -String _$entryNameHash() => r'5b97f6d0bfdb17369f3c4fec5aafcba45e1244a0'; +String _$entryNameHash() => r'1c1c30e4aca4781396b565ea6dcb27c5c2f85eed'; /// See also [_entryName]. @ProviderFor(_entryName) @@ -38,7 +38,7 @@ final _entryNameProvider = AutoDisposeProvider.internal( @Deprecated('Will be removed in 3.0. Use Ref instead') // ignore: unused_element typedef _EntryNameRef = AutoDisposeProviderRef; -String _$entryTypeHash() => r'b8db383dacb169526f823865fb2c90e478a4b4ee'; +String _$entryTypeHash() => r'5fe9ddb320ee741eaf36c4495f00129115274178'; /// See also [_entryType]. @ProviderFor(_entryType) @@ -54,7 +54,7 @@ final _entryTypeProvider = AutoDisposeProvider.internal( @Deprecated('Will be removed in 3.0. Use Ref instead') // ignore: unused_element typedef _EntryTypeRef = AutoDisposeProviderRef; -String _$entryUrlHash() => r'694a800667fd4e4be38e5ae6535f605833cda12e'; +String _$entryUrlHash() => r'8ce4ee0f3a1fd70f7d7306f37c71a641f44736de'; /// See also [_entryUrl]. @ProviderFor(_entryUrl) @@ -70,7 +70,7 @@ final _entryUrlProvider = AutoDisposeProvider.internal( @Deprecated('Will be removed in 3.0. Use Ref instead') // ignore: unused_element typedef _EntryUrlRef = AutoDisposeProviderRef; -String _$entryColorHash() => r'7bdd0ca948f969fd17f3b33c020f20585847b543'; +String _$entryColorHash() => r'cd9fce8fca82748da1c8b18df77f400ec9a8c63b'; /// See also [_entryColor]. @ProviderFor(_entryColor)