From 217dec19073ae22cab68828153859b093b2be966 Mon Sep 17 00:00:00 2001 From: Moritz Date: Thu, 26 Oct 2023 12:05:43 +0200 Subject: [PATCH] Fix hashes --- pkgs/messages/example_json/lib/testarb.g.dart | 35 ++++++--------- pkgs/messages/example_json/lib/testarb.json | 2 +- .../messages/example_json/lib/testarb_de.json | 2 +- .../example_json/lib/testarbctx2.g.dart | 40 ++++++----------- .../example_json/lib/testarbctx2.json | 2 +- .../example_json/lib/testarbctx2_fr.json | 2 +- pkgs/messages/example_json/pubspec.yaml | 2 +- pkgs/messages_builder/lib/arb_parser.dart | 10 ++++- pkgs/messages_builder/lib/builder.dart | 26 +++++------ .../lib/code_generation/class_generation.dart | 20 +-------- .../lib/code_generation/code.dart | 9 ++-- .../lib/code_generation/field_generation.dart | 22 ++-------- .../lib/code_generation/generation.dart | 1 - .../code_generation/import_generation.dart | 3 +- .../code_generation/library_generation.dart | 12 ++---- .../code_generation/method_generation.dart | 43 +++++-------------- .../lib/generation_options.dart | 8 ++-- pkgs/messages_builder/pubspec.yaml | 1 + 18 files changed, 78 insertions(+), 162 deletions(-) diff --git a/pkgs/messages/example_json/lib/testarb.g.dart b/pkgs/messages/example_json/lib/testarb.g.dart index ac179237..03b75163 100644 --- a/pkgs/messages/example_json/lib/testarb.g.dart +++ b/pkgs/messages/example_json/lib/testarb.g.dart @@ -14,11 +14,9 @@ class HomePageMessages { final Map _messages = {}; - static const carbs = {'de': 'lib/testarb_de.json', 'en': 'lib/testarb.json'}; - - final _messageListHashes = { - 'lib/testarb_de.json': 'ju3nni', - 'lib/testarb.json': 'rqcv4f' + static const carbs = { + 'de': ('lib/testarb_de.json', 'hbDN1MhX'), + 'en': ('lib/testarb.json', 'dr9Md951') }; IntlObject intlObject; @@ -31,15 +29,16 @@ class HomePageMessages { Future loadLocale(String locale) async { if (!_messages.containsKey(locale)) { - final carb = carbs[locale]; + final info = carbs[locale]; + final carb = info?.$1; if (carb == null) { throw ArgumentError('Locale $locale is not in $knownLocales'); } final data = await _fileLoader(carb); final messageList = MessageListJson.fromString(data, intlObject); - if (messageList.preamble.hash != _messageListHashes[carb]) { + if (messageList.preamble.hash != info?.$2) { throw ArgumentError(''' - Messages file has different hash "${messageList.preamble.hash}" than generated code "${_messageListHashes[carb]}".'''); + Messages file for locale $locale has different hash "${messageList.preamble.hash}" than generated code "${info?.$2}".'''); } _messages[locale] = messageList; } @@ -56,30 +55,20 @@ class HomePageMessages { String firstName, String lastName, ) => - _currentMessages.generateStringAtIndex( - HomePageMessagesEnum.helloAndWelcome.index, [firstName, lastName]); + _currentMessages.generateStringAtIndex(0, [firstName, lastName]); String helloAndWelcome2( String firstName, String lastName, ) => - _currentMessages.generateStringAtIndex( - HomePageMessagesEnum.helloAndWelcome2.index, [firstName, lastName]); + _currentMessages.generateStringAtIndex(1, [firstName, lastName]); - String newMessages(int newMessages) => _currentMessages.generateStringAtIndex( - HomePageMessagesEnum.newMessages.index, [newMessages]); + String newMessages(int newMessages) => + _currentMessages.generateStringAtIndex(2, [newMessages]); String newMessages2( String gender, int newVar, ) => - _currentMessages.generateStringAtIndex( - HomePageMessagesEnum.newMessages2.index, [gender, newVar]); -} - -enum HomePageMessagesEnum { - helloAndWelcome, - helloAndWelcome2, - newMessages, - newMessages2 + _currentMessages.generateStringAtIndex(3, [gender, newVar]); } diff --git a/pkgs/messages/example_json/lib/testarb.json b/pkgs/messages/example_json/lib/testarb.json index 600bb6fb..eb1082fd 100644 --- a/pkgs/messages/example_json/lib/testarb.json +++ b/pkgs/messages/example_json/lib/testarb.json @@ -1 +1 @@ -[0,"en","rqcv4f",0,null,["Welcome von !",[8,0],[13,1]],["Welcome von !",[8,0],[13,1]],[6,"test ",[3,0,["test new messages",[5,0]],[2,"No new messages",4,"One new message",5,"Two new Messages"]]],[6,"test ",[4,0,"Two new Messages",{"male":"No new messages","female":"One new message"}]]] \ No newline at end of file +[0,"en","dr9Md951",0,null,["Welcome von !",[8,0],[13,1]],["Welcome von !",[8,0],[13,1]],[6,"test ",[3,0,["test new messages",[5,0]],[2,"No new messages",4,"One new message",5,"Two new Messages"]]],[6,"test ",[4,0,"Two new Messages",{"male":"No new messages","female":"One new message"}]]] \ No newline at end of file diff --git a/pkgs/messages/example_json/lib/testarb_de.json b/pkgs/messages/example_json/lib/testarb_de.json index ec3c4cb1..f77a4e5b 100644 --- a/pkgs/messages/example_json/lib/testarb_de.json +++ b/pkgs/messages/example_json/lib/testarb_de.json @@ -1 +1 @@ -[0,"de","iagmc",0,null,["Willkommen von ",[11,0],[16,1]],["Willkommen von 2",[11,0],[16,1]],[6,"testde ",[3,0,["test new messages",[5,0]],[2,"No new messages",4,"One new message",5,"Two new Messages"]]],"testdse is just a simple message"] \ No newline at end of file +[0,"de","hbDN1MhX",0,null,["Willkommen von ",[11,0],[16,1]],["Willkommen von 2",[11,0],[16,1]],[6,"testde ",[3,0,["test new messages",[5,0]],[2,"No new messages",4,"One new message",5,"Two new Messages"]]],"testdse is just a simple message"] \ No newline at end of file diff --git a/pkgs/messages/example_json/lib/testarbctx2.g.dart b/pkgs/messages/example_json/lib/testarbctx2.g.dart index c6c54d93..0a7c6d80 100644 --- a/pkgs/messages/example_json/lib/testarbctx2.g.dart +++ b/pkgs/messages/example_json/lib/testarbctx2.g.dart @@ -15,13 +15,8 @@ class AboutPageMessages { final Map _messages = {}; static const carbs = { - 'fr': 'lib/testarbctx2_fr.json', - 'en': 'lib/testarbctx2.json' - }; - - final _messageListHashes = { - 'lib/testarbctx2_fr.json': 'tjk424', - 'lib/testarbctx2.json': 't7o6rv' + 'fr': ('lib/testarbctx2_fr.json', 'EyPjEJJU'), + 'en': ('lib/testarbctx2.json', 'QrwRSsOy') }; IntlObject intlObject; @@ -34,15 +29,16 @@ class AboutPageMessages { Future loadLocale(String locale) async { if (!_messages.containsKey(locale)) { - final carb = carbs[locale]; + final info = carbs[locale]; + final carb = info?.$1; if (carb == null) { throw ArgumentError('Locale $locale is not in $knownLocales'); } final data = await _fileLoader(carb); final messageList = MessageListJson.fromString(data, intlObject); - if (messageList.preamble.hash != _messageListHashes[carb]) { + if (messageList.preamble.hash != info?.$2) { throw ArgumentError(''' - Messages file has different hash "${messageList.preamble.hash}" than generated code "${_messageListHashes[carb]}".'''); + Messages file for locale $locale has different hash "${messageList.preamble.hash}" than generated code "${info?.$2}".'''); } _messages[locale] = messageList; } @@ -56,34 +52,22 @@ class AboutPageMessages { } String aboutMessage(String websitename) => - _currentMessages.generateStringAtIndex( - AboutPageMessagesEnum.aboutMessage.index, [websitename]); + _currentMessages.generateStringAtIndex(0, [websitename]); String helloAndWelcome( String firstName, int lastName, ) => - _currentMessages.generateStringAtIndex( - AboutPageMessagesEnum.helloAndWelcome.index, [firstName, lastName]); + _currentMessages.generateStringAtIndex(1, [firstName, lastName]); - String newMessages(int newMessages) => _currentMessages.generateStringAtIndex( - AboutPageMessagesEnum.newMessages.index, [newMessages]); + String newMessages(int newMessages) => + _currentMessages.generateStringAtIndex(2, [newMessages]); String newMessages2( String gender, int newVar, ) => - _currentMessages.generateStringAtIndex( - AboutPageMessagesEnum.newMessages2.index, [gender, newVar]); - - String get otherMsg => _currentMessages - .generateStringAtIndex(AboutPageMessagesEnum.otherMsg.index, []); -} + _currentMessages.generateStringAtIndex(3, [gender, newVar]); -enum AboutPageMessagesEnum { - aboutMessage, - helloAndWelcome, - newMessages, - newMessages2, - otherMsg + String get otherMsg => _currentMessages.generateStringAtIndex(4, []); } diff --git a/pkgs/messages/example_json/lib/testarbctx2.json b/pkgs/messages/example_json/lib/testarbctx2.json index e757ed39..f59abb6d 100644 --- a/pkgs/messages/example_json/lib/testarbctx2.json +++ b/pkgs/messages/example_json/lib/testarbctx2.json @@ -1 +1 @@ -[0,"en","t7o6rv",0,null,["About ",[6,0]],["Welcome von <",[8,0],[13,1]],[6,"test ",[3,0,["test new messages",[5,0]],[2,"No new messages",4,"One new message",5,"Two new Messages"]]],[6,"test ",[4,0,"Two new Messages",{"male":"No new messages","female":"One new message"}]],"other"] \ No newline at end of file +[0,"en","QrwRSsOy",0,null,["About ",[6,0]],["Welcome von <",[8,0],[13,1]],[6,"test ",[3,0,["test new messages",[5,0]],[2,"No new messages",4,"One new message",5,"Two new Messages"]]],[6,"test ",[4,0,"Two new Messages",{"male":"No new messages","female":"One new message"}]],"other"] \ No newline at end of file diff --git a/pkgs/messages/example_json/lib/testarbctx2_fr.json b/pkgs/messages/example_json/lib/testarbctx2_fr.json index 70fa14d8..a1c89f3d 100644 --- a/pkgs/messages/example_json/lib/testarbctx2_fr.json +++ b/pkgs/messages/example_json/lib/testarbctx2_fr.json @@ -1 +1 @@ -[0,"fr","vblv7q",0,null,["Sur ",[4,0]],["Welcome von <",[8,0],[13,1]],[6,"test ",[3,0,["test new messages",[5,0]],[2,"No new messages",4,"One new message",5,"Two new Messages"]]],[6,"test ",[4,0,"Two new Messages",{"male":"No new messages","female":"One new message"}]],"other"] \ No newline at end of file +[0,"fr","EyPjEJJU",0,null,["Sur ",[4,0]],["Welcome von <",[8,0],[13,1]],[6,"test ",[3,0,["test new messages",[5,0]],[2,"No new messages",4,"One new message",5,"Two new Messages"]]],[6,"test ",[4,0,"Two new Messages",{"male":"No new messages","female":"One new message"}]],"other"] \ No newline at end of file diff --git a/pkgs/messages/example_json/pubspec.yaml b/pkgs/messages/example_json/pubspec.yaml index 9c171dc9..3726c25c 100644 --- a/pkgs/messages/example_json/pubspec.yaml +++ b/pkgs/messages/example_json/pubspec.yaml @@ -24,4 +24,4 @@ dev_dependencies: messages: generateMethods: true generateFindById: false - generateFindBy: none + generateFindBy: integer diff --git a/pkgs/messages_builder/lib/arb_parser.dart b/pkgs/messages_builder/lib/arb_parser.dart index 8ce5aa42..b879764e 100644 --- a/pkgs/messages_builder/lib/arb_parser.dart +++ b/pkgs/messages_builder/lib/arb_parser.dart @@ -2,7 +2,10 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +import 'dart:convert'; + import 'package:build/build.dart'; +import 'package:crypto/crypto.dart'; import 'message_parser/message_parser.dart'; import 'message_with_metadata.dart'; @@ -30,12 +33,17 @@ class ArbParser { locale ?? inferredLocale, context, referencePath, - arb.hashCode.toRadixString(32), + getHash(arb), arb.keys.any((key) => key.startsWith('@') && !key.startsWith('@@')), assetId, ); } + String getHash(Map arb) { + final digest = sha1.convert(arb.toString().codeUnits); + return base64Encode(digest.bytes).substring(0, 8); + } + MessageWithMetadata parseMessage( Map arb, String messageKey, diff --git a/pkgs/messages_builder/lib/builder.dart b/pkgs/messages_builder/lib/builder.dart index e1044ac0..7b64d26e 100644 --- a/pkgs/messages_builder/lib/builder.dart +++ b/pkgs/messages_builder/lib/builder.dart @@ -51,7 +51,6 @@ class BuildStepGenerator { final allMessageFiles = await getParsedMessageFiles(); final inputMessageFile = allMessageFiles .singleWhere((messageFile) => messageFile.assetId == inputId); - final parentFile = getParentFile(allMessageFiles, inputMessageFile); final reducedMessageFile = reduce(parentFile, inputMessageFile); @@ -88,25 +87,20 @@ class BuildStepGenerator { final resourcesInContext = assetList.where((resource) => resource.context == messageList.context); - final localeToResource = + final localeToResourceInfo = Map.fromEntries(resourcesInContext.map((resource) => MapEntry( resource.locale, - resource.assetId.changeExtension('.json').path, + ( + path: resource.assetId.changeExtension('.json').path, + hasch: resource.hash, + ), ))); - final resourceToHash = Map.fromEntries( - resourcesInContext.map((resource) => MapEntry( - localeToResource[resource.locale]!, - resource.hash, - )), - ); - - printIncludeFilesNotification(messageList.context, localeToResource); + printIncludeFilesNotification(messageList.context, localeToResourceInfo); final libraryCode = CodeGenerator( options, messageList, - localeToResource, - resourceToHash, + localeToResourceInfo, ).generate(); await buildStep.writeAsString( @@ -199,13 +193,15 @@ class BuildStepGenerator { /// Display a notification to the user to include the newly generated files /// in their assets. void printIncludeFilesNotification( - String? context, Map localeToResource) { + String? context, + Map localeToResource, + ) { var contextMessage = 'The'; if (context != null) { contextMessage = 'For the messages in $context, the'; } final fileList = - localeToResource.entries.map((e) => '\t${e.value}').join('\n'); + localeToResource.entries.map((e) => '\t${e.value.path}').join('\n'); print( '''$contextMessage following files need to be declared in your assets:\n$fileList'''); } diff --git a/pkgs/messages_builder/lib/code_generation/class_generation.dart b/pkgs/messages_builder/lib/code_generation/class_generation.dart index 0f07cce2..4b63f5cc 100644 --- a/pkgs/messages_builder/lib/code_generation/class_generation.dart +++ b/pkgs/messages_builder/lib/code_generation/class_generation.dart @@ -39,25 +39,7 @@ class ClassGeneration extends Generation { ..methods.addAll(methods), ), ]; - if (options.findByType == IndexType.integer) { - classes.add(Class((cb) => cb - ..name = indicesName(context) - ..fields.addAll( - List.generate( - messages.length, - (index) => messages[index].nameIsDartConform - ? Field( - (evb) => evb - ..name = messages[index].name - ..type = const Reference('int') - ..assignment = Code('$index') - ..static = true - ..modifier = FieldModifier.constant, - ) - : null).whereType(), - ))); - } - if (options.findByType == IndexType.enumerate || options.messageCalls) { + if (options.indexType == IndexType.enumerate) { classes.add(Enum((cb) => cb ..name = enumName(context) ..values.addAll(List.generate( diff --git a/pkgs/messages_builder/lib/code_generation/code.dart b/pkgs/messages_builder/lib/code_generation/code.dart index ea6e0599..439d3d54 100644 --- a/pkgs/messages_builder/lib/code_generation/code.dart +++ b/pkgs/messages_builder/lib/code_generation/code.dart @@ -13,15 +13,13 @@ class CodeGenerator { final GenerationOptions options; final String? context; final String locale; - final Map localeCarbPaths; final List messages; - final Map resourceToHash; + final Map localeToResourceInfo; CodeGenerator( this.options, MessagesWithMetadata messageListWithMetadata, - this.localeCarbPaths, - this.resourceToHash, + this.localeToResourceInfo, ) : context = messageListWithMetadata.context, locale = messageListWithMetadata.locale, messages = messageListWithMetadata.messages; @@ -32,8 +30,7 @@ class CodeGenerator { context, locale, messages, - localeCarbPaths, - resourceToHash, + localeToResourceInfo, ).generate(); assert(libs.isNotEmpty); diff --git a/pkgs/messages_builder/lib/code_generation/field_generation.dart b/pkgs/messages_builder/lib/code_generation/field_generation.dart index a9823a3f..7c667fb1 100644 --- a/pkgs/messages_builder/lib/code_generation/field_generation.dart +++ b/pkgs/messages_builder/lib/code_generation/field_generation.dart @@ -9,15 +9,13 @@ import 'generation.dart'; class FieldGeneration extends Generation { final GenerationOptions options; - final Map localeCarbPaths; + final Map localeToResourceInfo; final String locale; - final Map resourceToHash; FieldGeneration( this.options, - this.localeCarbPaths, + this.localeToResourceInfo, this.locale, - this.resourceToHash, ); @override @@ -46,8 +44,8 @@ class FieldGeneration extends Generation { ); final carbs = Field( (fb) { - final paths = localeCarbPaths.entries - .map((e) => "'${e.key}' : '${e.value}'") + final paths = localeToResourceInfo.entries + .map((e) => "'${e.key}' : ('${e.value.path}', '${e.value.hasch}')") .join(','); fb ..name = 'carbs' @@ -56,17 +54,6 @@ class FieldGeneration extends Generation { ..assignment = Code('{$paths}'); }, ); - final hashes = Field( - (p0) { - final hashList = resourceToHash.entries - .map((e) => "'${e.key}' : '${e.value}'") - .join(','); - p0 - ..name = '_messageListHashes' - ..modifier = FieldModifier.final$ - ..assignment = Code('{$hashList}'); - }, - ); final intlObject = Field( (fb) => fb ..name = 'intlObject' @@ -77,7 +64,6 @@ class FieldGeneration extends Generation { currentLocale, messages, carbs, - hashes, intlObject, ]; return fields; diff --git a/pkgs/messages_builder/lib/code_generation/generation.dart b/pkgs/messages_builder/lib/code_generation/generation.dart index 8d38f85e..e6bdcef7 100644 --- a/pkgs/messages_builder/lib/code_generation/generation.dart +++ b/pkgs/messages_builder/lib/code_generation/generation.dart @@ -7,6 +7,5 @@ abstract class Generation { } String enumName(String? context) => '${context ?? ''}MessagesEnum'; -String indicesName(String? context) => '${context ?? ''}MessagesIndex'; String getDataFileName(String e) => e.split('.').first; diff --git a/pkgs/messages_builder/lib/code_generation/import_generation.dart b/pkgs/messages_builder/lib/code_generation/import_generation.dart index b499e77b..66a4b7fb 100644 --- a/pkgs/messages_builder/lib/code_generation/import_generation.dart +++ b/pkgs/messages_builder/lib/code_generation/import_generation.dart @@ -9,9 +9,8 @@ import 'generation.dart'; class ImportGeneration extends Generation { final GenerationOptions options; - final Map resourceToHash; - ImportGeneration(this.options, this.resourceToHash); + ImportGeneration(this.options); @override List generate() { diff --git a/pkgs/messages_builder/lib/code_generation/library_generation.dart b/pkgs/messages_builder/lib/code_generation/library_generation.dart index b3424e91..12eacb97 100644 --- a/pkgs/messages_builder/lib/code_generation/library_generation.dart +++ b/pkgs/messages_builder/lib/code_generation/library_generation.dart @@ -18,35 +18,31 @@ class LibraryGeneration extends Generation { final String? context; final String locale; final List messages; - final Map localeCarbPaths; - final Map resourceToHash; + final Map localeToResourceInfo; LibraryGeneration( this.options, this.context, this.locale, this.messages, - this.localeCarbPaths, - this.resourceToHash, + this.localeToResourceInfo, ); @override List generate() { - final imports = ImportGeneration(options, resourceToHash).generate(); + final imports = ImportGeneration(options).generate(); final constructors = ConstructorGeneration(options).generate(); final fields = FieldGeneration( options, - localeCarbPaths, + localeToResourceInfo, locale, - resourceToHash, ).generate(); final methods = MethodGeneration( options, context, messages, - resourceToHash, ).generate(); final classes = ClassGeneration( diff --git a/pkgs/messages_builder/lib/code_generation/method_generation.dart b/pkgs/messages_builder/lib/code_generation/method_generation.dart index c0f20ee5..39f684db 100644 --- a/pkgs/messages_builder/lib/code_generation/method_generation.dart +++ b/pkgs/messages_builder/lib/code_generation/method_generation.dart @@ -12,14 +12,8 @@ class MethodGeneration extends Generation { final GenerationOptions options; final String? context; final List messages; - final Map resourceToHash; - MethodGeneration( - this.options, - this.context, - this.messages, - this.resourceToHash, - ); + MethodGeneration(this.options, this.context, this.messages); Method? generateMessageCall(int index, MessageWithMetadata message) { if (!message.nameIsDartConform) { @@ -28,8 +22,11 @@ class MethodGeneration extends Generation { final arguments = message.placeholders.map((placeholder) => placeholder.name).join(', '); - final index = '${enumName(context)}.${message.name}.index'; - final body = '_currentMessages.generateStringAtIndex($index, [$arguments])'; + final indexStr = options.indexType == IndexType.enumerate + ? '${enumName(context)}.${message.name}.index' + : index.toString(); + final body = + '_currentMessages.generateStringAtIndex($indexStr, [$arguments])'; final methodType = message.placeholders.isEmpty ? MethodType.getter : null; return Method( (mb) => mb @@ -78,14 +75,15 @@ class MethodGeneration extends Generation { ..modifier = MethodModifier.async ..body = Code(''' if (!_messages.containsKey(locale)) { - final carb = carbs[locale]; + final info = carbs[locale]; + final carb = info?.\$1; if (carb == null) { throw ArgumentError('Locale \$locale is not in \$knownLocales'); } $loading - if (messageList.preamble.hash != _messageListHashes[carb]) { + if (messageList.preamble.hash != info?.\$2) { throw ArgumentError(\'\'\' - Messages file has different hash "\${messageList.preamble.hash}" than generated code "\${_messageListHashes[carb]}".\'\'\'); + Messages file for locale \$locale has different hash "\${messageList.preamble.hash}" than generated code "\${info?.\$2}".\'\'\'); } _messages[locale] = messageList; } @@ -149,24 +147,6 @@ class MethodGeneration extends Generation { ..body = const Code('return _currentMessages.generateStringAtId(id, args);') ..returns = const Reference('String')); - final findByIndex = Method((mb) => mb - ..name = 'getByIndex' - ..annotations - .add(const CodeExpression(Code("pragma('dart2js:noInline')"))) - ..requiredParameters.add(Parameter( - (pb) => pb - ..name = 'index' - ..type = const Reference('int'), - )) - ..optionalParameters.add(Parameter( - (pb) => pb - ..name = 'args' - ..type = const Reference('List') - ..defaultTo = const Code('const []'), - )) - ..body = const Code('_currentMessages.generateStringAtIndex(index, args)') - ..lambda = true - ..returns = const Reference('String')); final findByEnum = Method((mb) => mb ..name = 'getByEnum' ..annotations @@ -191,8 +171,7 @@ class MethodGeneration extends Generation { getCurrentLocale, getCurrentMessages, if (options.findById) getMessagebyId, - if (options.findByType == IndexType.enumerate) findByEnum, - if (options.findByType == IndexType.integer) findByIndex, + if (options.indexType == IndexType.enumerate) findByEnum, getKnownLocales, loadLocale, loadAllLocales, diff --git a/pkgs/messages_builder/lib/generation_options.dart b/pkgs/messages_builder/lib/generation_options.dart index 6b5004de..26f4fd12 100644 --- a/pkgs/messages_builder/lib/generation_options.dart +++ b/pkgs/messages_builder/lib/generation_options.dart @@ -9,7 +9,7 @@ import 'package:yaml/yaml.dart'; class GenerationOptions { final bool messageCalls; final bool findById; - final IndexType findByType; + final IndexType indexType; final SerializationType serialization; final DeserializationType deserialization; @@ -18,7 +18,7 @@ class GenerationOptions { required this.deserialization, required this.messageCalls, required this.findById, - required this.findByType, + required this.indexType, }); static Future fromPubspec(BuildStep buildStep) async { @@ -31,11 +31,11 @@ class GenerationOptions { deserialization: DeserializationType.web, messageCalls: (messagesOptions?['generateMethods'] as bool?) ?? true, findById: (messagesOptions?['generateFindById'] as bool?) ?? false, - findByType: IndexType.values + indexType: IndexType.values .where((type) => type.name == messagesOptions?['generateFindBy'] as String?) .firstOrNull ?? - IndexType.none, + IndexType.integer, ); return generationOptions; } diff --git a/pkgs/messages_builder/pubspec.yaml b/pkgs/messages_builder/pubspec.yaml index 4736334f..459dab30 100644 --- a/pkgs/messages_builder/pubspec.yaml +++ b/pkgs/messages_builder/pubspec.yaml @@ -11,6 +11,7 @@ dependencies: build: ^2.3.1 code_builder: ^4.3.0 collection: ^1.18.0 + crypto: ^3.0.3 dart_style: ^2.2.4 glob: ^2.1.1 intl: ^0.18.0