From 60329ede0bcf96456e3a7834c9ffb319febe303f Mon Sep 17 00:00:00 2001 From: Anindya Chatterjee Date: Tue, 19 Dec 2023 11:38:57 +0530 Subject: [PATCH] some enhancement --- melos.yaml | 2 +- .../lib/src/common/meta/attributes.dart | 23 +++----- .../src/migration/database_instruction.dart | 2 +- .../lib/src/migration/instructions.dart | 4 +- .../lib/src/migration/migration_manager.dart | 2 +- packages/nitrite/lib/src/nitrite_builder.dart | 17 ++++-- packages/nitrite/lib/src/nitrite_config.dart | 37 ++++++++++--- .../nitrite/lib/src/repository/entity.dart | 9 ++-- .../lib/src/repository/entity_decorator.dart | 2 +- .../src/repository/nitrite_entity_reader.dart | 2 +- .../lib/src/store/user_auth_service.dart | 3 ++ packages/nitrite/lib/src/transaction/tx.dart | 26 +++++----- .../base_object_repository_test_loader.dart | 52 +++++++++---------- .../lib/src/entity_writer.dart | 4 +- .../test/entity_parser_test.dart | 18 +++---- .../test/id_field_parser_test.dart | 12 ++--- .../base_object_repository_test_loader.dart | 52 +++++++++---------- 17 files changed, 144 insertions(+), 123 deletions(-) diff --git a/melos.yaml b/melos.yaml index 6bc4891..5a4a38b 100644 --- a/melos.yaml +++ b/melos.yaml @@ -63,7 +63,7 @@ scripts: melos run generate && melos exec -c 6 --fail-fast --ignore="*generator*" --ignore="*demo*" -- flutter test --coverage --no-pub && melos exec -c 6 --fail-fast --scope="*generator*" -- dart pub global run coverage:test_with_coverage && - melos exec -c 1 --file-exists=coverage/lcov.info --scope="nitrite" -- lcov --remove coverage/lcov.info "lib/src/migration/*" "lib/src/transaction/*" "lib/src/index/fulltext/stop_words.dart" && + melos exec -c 1 --file-exists=coverage/lcov.info --scope="nitrite" -- lcov --ignore-errors unused --remove coverage/lcov.info "lib/src/migration/*" "lib/src/transaction/*" "lib/src/index/fulltext/stop_words.dart" && melos exec --ignore="*demo*" -- genhtml coverage/lcov.info --output-directory=coverage/ && melos exec -c 1 --file-exists=coverage/lcov.info -- coverde filter --input ./coverage/lcov.info --output MELOS_ROOT_PATH/coverage/filtered.lcov.info --filters \.g\.dart && coverde value -i coverage/filtered.lcov.info > MELOS_ROOT_PATH/coverage/result.txt diff --git a/packages/nitrite/lib/src/common/meta/attributes.dart b/packages/nitrite/lib/src/common/meta/attributes.dart index 9c1340e..2354ac8 100644 --- a/packages/nitrite/lib/src/common/meta/attributes.dart +++ b/packages/nitrite/lib/src/common/meta/attributes.dart @@ -17,15 +17,6 @@ class Attributes { static final String lastModifiedTime = "last_modified_at"; static final String owner = "owner"; static final String uniqueId = "uuid"; - static final String syncLock = "sync_lock"; - static final String expiryWait = "expiry_wait"; - static final String tombstone = "tombstone"; - static final String feedLedger = "feed_ledger"; - static final String localCollectionMarker = "local_collection_marker"; - static final String remoteCollectionMarker = "remote_collection_marker"; - static final String localTombstoneMarker = "local_tombstone_marker"; - static final String remoteTombstoneMarker = "remote_tombstone_marker"; - static final String replica = "replica"; Map _attributes = {}; @@ -41,10 +32,10 @@ class Attributes { } /// Creates an instance of the Attributes class from a [Document] object. - /// + /// /// Args: /// document (Document): The parameter "document" is of type "Document". - /// + /// /// Returns: /// The method is returning an instance of the [Attributes] class. factory Attributes.fromDocument(Document document) { @@ -57,15 +48,15 @@ class Attributes { return attr; } - /// Adds a key-value pair to the attributes and returns + /// Adds a key-value pair to the attributes and returns /// the updated [Attributes] object. - /// + /// /// Args: - /// key (String): The key parameter is a string that represents the + /// key (String): The key parameter is a string that represents the /// name of the attribute. - /// value (String): The value parameter is a string that represents + /// value (String): The value parameter is a string that represents /// the value to be associated with the given key. - /// + /// /// Returns: /// The method is returning an object of type [Attributes]. Attributes set(String key, String value) { diff --git a/packages/nitrite/lib/src/migration/database_instruction.dart b/packages/nitrite/lib/src/migration/database_instruction.dart index 8c80cae..1971139 100644 --- a/packages/nitrite/lib/src/migration/database_instruction.dart +++ b/packages/nitrite/lib/src/migration/database_instruction.dart @@ -8,7 +8,7 @@ abstract class DatabaseInstruction implements Instruction { /// Adds an instruction to set an user authentication to the database. DatabaseInstruction addUser(String username, String password) { MigrationStep migrationStep = - MigrationStep(InstructionType.addPassword, (username, password)); + MigrationStep(InstructionType.addUser, (username, password)); addStep(migrationStep); return this; } diff --git a/packages/nitrite/lib/src/migration/instructions.dart b/packages/nitrite/lib/src/migration/instructions.dart index 23cc25e..524e1e0 100644 --- a/packages/nitrite/lib/src/migration/instructions.dart +++ b/packages/nitrite/lib/src/migration/instructions.dart @@ -12,8 +12,8 @@ typedef CustomInstruction = Future Function(Nitrite nitrite); /// Represents an instruction type. enum InstructionType { - /// The add password instruction. - addPassword, + /// The add user authentication instruction. + addUser, /// The change password instruction. changePassword, diff --git a/packages/nitrite/lib/src/migration/migration_manager.dart b/packages/nitrite/lib/src/migration/migration_manager.dart index 42f25db..a8af938 100644 --- a/packages/nitrite/lib/src/migration/migration_manager.dart +++ b/packages/nitrite/lib/src/migration/migration_manager.dart @@ -136,7 +136,7 @@ class MigrationManager { try { Command command; switch (step.instructionType) { - case InstructionType.addPassword: + case InstructionType.addUser: command = AddPasswordCommand(step.arguments as (String, String)); break; case InstructionType.changePassword: diff --git a/packages/nitrite/lib/src/nitrite_builder.dart b/packages/nitrite/lib/src/nitrite_builder.dart index 8934af2..c9710a7 100644 --- a/packages/nitrite/lib/src/nitrite_builder.dart +++ b/packages/nitrite/lib/src/nitrite_builder.dart @@ -23,6 +23,15 @@ class NitriteBuilder { return this; } + /// Registers an [EntityConverter] with Nitrite. The converter is used to + /// convert between an entity and a [Document]. This method allows you to + /// register a custom converter for a specific entity. + NitriteBuilder registerEntityConverter( + EntityConverter entityConverter) { + nitriteConfig.registerEntityConverter(entityConverter); + return this; + } + /// Loads a Nitrite module into the Nitrite database. The module can be /// used to extend the functionality of Nitrite. NitriteBuilder loadModule(NitriteModule module) { @@ -50,18 +59,18 @@ class NitriteBuilder { /// everytime. If it is configured as a file based database, and if the file /// does not exist, then it will create a new file store and open the database; /// otherwise it will open the existing database file. - /// + /// /// If the username and password is not provided, then it will open the database /// without any authentication. - /// + /// /// If the username and password both are provided, then it will open the database /// with authentication. If the database is not already created, then it will /// create a new database with the given username and password. - /// + /// /// If the database is already created, then it will open the database with the /// given username and password. If the username and password is not valid, then /// it will throw an exception. - /// + /// /// NOTE: Both username and password must be provided or both must be null. Future openOrCreate({String? username, String? password}) async { await nitriteConfig.autoConfigure(); diff --git a/packages/nitrite/lib/src/nitrite_config.dart b/packages/nitrite/lib/src/nitrite_config.dart index 3054f53..32e58d7 100644 --- a/packages/nitrite/lib/src/nitrite_config.dart +++ b/packages/nitrite/lib/src/nitrite_config.dart @@ -14,6 +14,7 @@ class NitriteConfig { bool _configured = false; final List _modules = []; late PluginManager _pluginManager; + final List _entityConverters = []; /// A map of migrations to be applied to the database. Map> get migrations => _migrations; @@ -30,7 +31,7 @@ class NitriteConfig { } /// Sets the field separator for Nitrite database. - /// + /// /// Throws [InvalidOperationException] if the database is already initialized. void setFieldSeparator(String fieldSeparator) { if (_configured) { @@ -42,7 +43,7 @@ class NitriteConfig { /// Loads [NitritePlugin] instances defined in the [NitriteModule] /// into the configuration. - /// + /// /// Throws [InvalidOperationException] if the database is already initialized. NitriteConfig loadModule(NitriteModule module) { if (_configured) { @@ -53,10 +54,22 @@ class NitriteConfig { return this; } - /// Adds a migration step to the configuration. A migration step is a process - /// of updating the database from one version to another. If the database is + /// Registers an [EntityConverter] with Nitrite. The converter is used to + /// convert between an entity and a [Document]. + /// + /// Throws [InvalidOperationException] if the database is already initialized. + void registerEntityConverter(EntityConverter entityConverter) { + if (_configured) { + throw InvalidOperationException("Cannot register entity converter after " + "database initialization"); + } + _entityConverters.add(entityConverter); + } + + /// Adds a migration step to the configuration. A migration step is a process + /// of updating the database from one version to another. If the database is /// already initialized, then migration steps cannot be added. - /// + /// /// Throws [InvalidOperationException] if the database is already initialized. NitriteConfig addMigration(Migration migration) { if (_configured) { @@ -77,7 +90,7 @@ class NitriteConfig { } /// Sets the current schema version of the Nitrite database. - /// + /// /// Throws [InvalidOperationException] if the database is already initialized. NitriteConfig currentSchemaVersion(int version) { if (_configured) { @@ -99,7 +112,7 @@ class NitriteConfig { } /// Finds the [NitriteIndexer] for the given index type. - /// + /// /// Throws [IndexingException] if no indexer is found for the given index type. Future findIndexer(String indexType) async { var nitriteIndexer = pluginManager.indexerMap[indexType]; @@ -119,7 +132,7 @@ class NitriteConfig { return pluginManager.getNitriteStore(); } - /// Closes the [NitriteConfig] instance and releases any resources + /// Closes the [NitriteConfig] instance and releases any resources /// associated with it. Future close() { return pluginManager.close(); @@ -132,6 +145,14 @@ class NitriteConfig { } Future _loadModules() async { + if (_entityConverters.isNotEmpty) { + var mapper = SimpleNitriteMapper(); + for (EntityConverter entityConverter in _entityConverters) { + mapper.registerEntityConverter(entityConverter); + } + await _pluginManager.loadModule(module([mapper])); + } + for (NitriteModule module in _modules) { await _pluginManager.loadModule(module); } diff --git a/packages/nitrite/lib/src/repository/entity.dart b/packages/nitrite/lib/src/repository/entity.dart index 68474e6..8644cf9 100644 --- a/packages/nitrite/lib/src/repository/entity.dart +++ b/packages/nitrite/lib/src/repository/entity.dart @@ -20,11 +20,11 @@ class EntityId { /// Returns true if the entity ID is a [NitriteId]. bool get isNitriteId => _isNitriteId; - /// Returns a list of sub-fields of the id field. - List get subFields => _fields; + /// Returns a list of embedded fields of the id field. + List get embeddedFields => _fields; - /// Returns a list of embedded field names. - List get embeddedFieldNames { + /// Returns a list of encoded field names. + List get encodedFieldNames { return _fields .map((field) => "$_fieldName${NitriteConfig.fieldSeparator}$field") .toList(); @@ -130,6 +130,7 @@ class EntityIndex { } @internal + /// @nodoc abstract class NitriteEntity { String? get entityName; diff --git a/packages/nitrite/lib/src/repository/entity_decorator.dart b/packages/nitrite/lib/src/repository/entity_decorator.dart index 8279126..edd2313 100644 --- a/packages/nitrite/lib/src/repository/entity_decorator.dart +++ b/packages/nitrite/lib/src/repository/entity_decorator.dart @@ -33,7 +33,7 @@ class EntityDecoratorReader { _objectIdField = _entityDecorator.idField; var idFieldNames = _entityDecorator.idField!.isEmbedded - ? _entityDecorator.idField!.embeddedFieldNames + ? _entityDecorator.idField!.encodedFieldNames : [_entityDecorator.idField!.fieldName]; var hasIndex = await _collection.hasIndex(idFieldNames); diff --git a/packages/nitrite/lib/src/repository/nitrite_entity_reader.dart b/packages/nitrite/lib/src/repository/nitrite_entity_reader.dart index 43e8cea..1603069 100644 --- a/packages/nitrite/lib/src/repository/nitrite_entity_reader.dart +++ b/packages/nitrite/lib/src/repository/nitrite_entity_reader.dart @@ -19,7 +19,7 @@ class NitriteEntityReader { _objectIdField = entity.entityId; var idFieldNames = _objectIdField!.isEmbedded - ? _objectIdField!.embeddedFieldNames + ? _objectIdField!.encodedFieldNames : [_objectIdField!.fieldName]; var hasIndex = await _nitriteCollection.hasIndex(idFieldNames); diff --git a/packages/nitrite/lib/src/store/user_auth_service.dart b/packages/nitrite/lib/src/store/user_auth_service.dart index b096665..c362781 100644 --- a/packages/nitrite/lib/src/store/user_auth_service.dart +++ b/packages/nitrite/lib/src/store/user_auth_service.dart @@ -53,6 +53,9 @@ class UserAuthenticationService { if (!crypt.match(oldPassword)) { throw NitriteSecurityException('Username or password is invalid'); } + } else { + // if credential is null, it means the user is not present, so we cannot update + throw NitriteSecurityException('Username or password is invalid'); } } else { if (await _nitriteStore.hasMap(userMap)) { diff --git a/packages/nitrite/lib/src/transaction/tx.dart b/packages/nitrite/lib/src/transaction/tx.dart index e9beb27..c055410 100644 --- a/packages/nitrite/lib/src/transaction/tx.dart +++ b/packages/nitrite/lib/src/transaction/tx.dart @@ -3,19 +3,19 @@ import 'dart:collection'; import 'package:nitrite/nitrite.dart'; import 'package:nitrite/src/transaction/tx_store.dart'; -/// Represents a transaction in Nitrite database. -/// It provides methods to perform ACID operations on Nitrite database -/// collections and repositories. -/// -/// A transaction can be committed or rolled back. Once a transaction is -/// committed, all changes made during the transaction are persisted to -/// the underlying store. If a transaction is rolled back, all changes +/// Represents a transaction in Nitrite database. +/// It provides methods to perform transactional operations on Nitrite database +/// collections and repositories. +/// +/// A transaction can be committed or rolled back. Once a transaction is +/// committed, all changes made during the transaction are persisted to +/// the underlying store. If a transaction is rolled back, all changes /// made during the transaction are discarded. -/// +/// /// NOTE: Certain operations are auto-committed in Nitrite database. Those -/// operations are not part of transaction and cannot be rolled back. +/// operations are not part of transaction and cannot be rolled back. /// The following operations are auto-committed: -/// +/// /// * [NitriteCollection.createIndex] /// * [NitriteCollection.rebuildIndex] /// * [NitriteCollection.dropIndex] @@ -37,17 +37,17 @@ abstract class Transaction { /// Returns the current state of the transaction. TransactionState get state; - /// Gets a [NitriteCollection] to perform ACID operations on it. + /// Gets a [NitriteCollection] to perform transactional operations on it. Future getCollection(String name); - /// Gets an [ObjectRepository] to perform ACID operations on it. + /// Gets an [ObjectRepository] to perform transactional operations on it. Future> getRepository( {EntityDecorator? entityDecorator, String? key}); /// Completes the transaction and commits the data to the underlying store. Future commit(); - /// Rolls back the transaction, discarding any changes made during + /// Rolls back the transaction, discarding any changes made during /// the transaction. Future rollback(); diff --git a/packages/nitrite/test/integration/repository/base_object_repository_test_loader.dart b/packages/nitrite/test/integration/repository/base_object_repository_test_loader.dart index 658b51e..96f4275 100644 --- a/packages/nitrite/test/integration/repository/base_object_repository_test_loader.dart +++ b/packages/nitrite/test/integration/repository/base_object_repository_test_loader.dart @@ -114,31 +114,29 @@ Future cleanUp() async { } Future _openDb() async { - var nitriteBuilder = Nitrite.builder().fieldSeparator('.'); - db = await nitriteBuilder.openOrCreate( - username: 'test-user', password: 'test-password'); - - var mapper = db.config.nitriteMapper as SimpleNitriteMapper; - mapper.registerEntityConverter(CompanyConverter()); - mapper.registerEntityConverter(EmployeeConverter()); - mapper.registerEntityConverter(NoteConverter()); - mapper.registerEntityConverter(MyBookConverter()); - mapper.registerEntityConverter(BookIdConverter()); - mapper.registerEntityConverter(ClassAConverter()); - mapper.registerEntityConverter(ClassBConverter()); - mapper.registerEntityConverter(ClassCConverter()); - mapper.registerEntityConverter(ElemMatchConverter()); - mapper.registerEntityConverter(TextDataConverter()); - mapper.registerEntityConverter(SubEmployeeConverter()); - mapper.registerEntityConverter(ProductScoreConverter()); - mapper.registerEntityConverter(PersonEntityConverter()); - mapper.registerEntityConverter(RepeatableIndexTestConverter()); - mapper.registerEntityConverter(EncryptedPersonConverter()); - mapper.registerEntityConverter(TxDataConverter()); - mapper.registerEntityConverter(WithNitriteIdConverter()); - mapper.registerEntityConverter(ProductConverter()); - mapper.registerEntityConverter(ProductIdConverter()); - mapper.registerEntityConverter(ManufacturerConverter()); - mapper.registerEntityConverter(MiniProductConverter()); - mapper.registerEntityConverter(WithNullIdConverter()); + db = await Nitrite.builder() + .registerEntityConverter(CompanyConverter()) + .registerEntityConverter(EmployeeConverter()) + .registerEntityConverter(NoteConverter()) + .registerEntityConverter(MyBookConverter()) + .registerEntityConverter(BookIdConverter()) + .registerEntityConverter(ClassAConverter()) + .registerEntityConverter(ClassBConverter()) + .registerEntityConverter(ClassCConverter()) + .registerEntityConverter(ElemMatchConverter()) + .registerEntityConverter(TextDataConverter()) + .registerEntityConverter(SubEmployeeConverter()) + .registerEntityConverter(ProductScoreConverter()) + .registerEntityConverter(PersonEntityConverter()) + .registerEntityConverter(RepeatableIndexTestConverter()) + .registerEntityConverter(EncryptedPersonConverter()) + .registerEntityConverter(TxDataConverter()) + .registerEntityConverter(WithNitriteIdConverter()) + .registerEntityConverter(ProductConverter()) + .registerEntityConverter(ProductIdConverter()) + .registerEntityConverter(ManufacturerConverter()) + .registerEntityConverter(MiniProductConverter()) + .registerEntityConverter(WithNullIdConverter()) + .fieldSeparator('.') + .openOrCreate(username: 'test-user', password: 'test-password'); } diff --git a/packages/nitrite_entity_generator/lib/src/entity_writer.dart b/packages/nitrite_entity_generator/lib/src/entity_writer.dart index c91b341..6b35194 100644 --- a/packages/nitrite_entity_generator/lib/src/entity_writer.dart +++ b/packages/nitrite_entity_generator/lib/src/entity_writer.dart @@ -89,7 +89,7 @@ class EntityWriter { builder.returns = refer('EntityId'); var isNitriteId = _entityInfo.entityId!.isNitriteId; - if (_entityInfo.entityId!.subFields.isEmpty) { + if (_entityInfo.entityId!.embeddedFields.isEmpty) { builder.body = Code( 'EntityId("${_entityInfo.entityId!.fieldName}", $isNitriteId)'); } else { @@ -97,7 +97,7 @@ class EntityWriter { EntityId( "${_entityInfo.entityId!.fieldName}", $isNitriteId, - [${_entityInfo.entityId!.subFields.map((field) => '"$field"').join(', ')}], + [${_entityInfo.entityId!.embeddedFields.map((field) => '"$field"').join(', ')}], ) '''); } diff --git a/packages/nitrite_entity_generator/test/entity_parser_test.dart b/packages/nitrite_entity_generator/test/entity_parser_test.dart index fa51619..4c2c0a5 100644 --- a/packages/nitrite_entity_generator/test/entity_parser_test.dart +++ b/packages/nitrite_entity_generator/test/entity_parser_test.dart @@ -31,7 +31,7 @@ void main() { ]); expect(entity.entityId, isNotNull); expect(entity.entityId!.fieldName, 'person_id'); - expect(entity.entityId!.embeddedFieldNames, isEmpty); + expect(entity.entityId!.encodedFieldNames, isEmpty); }); test('Parse entity without default constructor', () async { @@ -58,7 +58,7 @@ void main() { ]); expect(entity.entityId, isNotNull); expect(entity.entityId!.fieldName, 'person_id'); - expect(entity.entityId!.embeddedFieldNames, isEmpty); + expect(entity.entityId!.encodedFieldNames, isEmpty); }); test('Parse entity without entity name', () async { @@ -86,7 +86,7 @@ void main() { ]); expect(entity.entityId, isNotNull); expect(entity.entityId!.fieldName, 'person_id'); - expect(entity.entityId!.embeddedFieldNames, isEmpty); + expect(entity.entityId!.encodedFieldNames, isEmpty); }); test('Parse entity without any indexes', () async { @@ -109,7 +109,7 @@ void main() { expect(entity.entityIndices.length, 0); expect(entity.entityId, isNotNull); expect(entity.entityId!.fieldName, 'person_id'); - expect(entity.entityId!.embeddedFieldNames, isEmpty); + expect(entity.entityId!.encodedFieldNames, isEmpty); }); test('Parse entity without Id', () async { @@ -157,7 +157,7 @@ void main() { ]); expect(entity.entityId, isNotNull); expect(entity.entityId!.fieldName, 'personId'); - expect(entity.entityId!.embeddedFieldNames, isEmpty); + expect(entity.entityId!.encodedFieldNames, isEmpty); }); test('Parse entity without Id field name', () async { @@ -185,7 +185,7 @@ void main() { ]); expect(entity.entityId, isNotNull); expect(entity.entityId!.fieldName, 'personId'); - expect(entity.entityId!.embeddedFieldNames, isEmpty); + expect(entity.entityId!.encodedFieldNames, isEmpty); }); test('Parse entity Id with wrong embedded fields', () async { @@ -239,10 +239,10 @@ void main() { ]); expect(entity.entityId, isNotNull); expect(entity.entityId!.fieldName, 'personId'); - expect(entity.entityId!.subFields, ['age', 'dob']); - expect(entity.entityId!.embeddedFieldNames, isNotEmpty); + expect(entity.entityId!.embeddedFields, ['age', 'dob']); + expect(entity.entityId!.encodedFieldNames, isNotEmpty); expect( - entity.entityId!.embeddedFieldNames, ['personId.age', 'personId.dob']); + entity.entityId!.encodedFieldNames, ['personId.age', 'personId.dob']); }); test("Parse entity with multiple id", () async { diff --git a/packages/nitrite_entity_generator/test/id_field_parser_test.dart b/packages/nitrite_entity_generator/test/id_field_parser_test.dart index 0a549a7..7d4cd87 100644 --- a/packages/nitrite_entity_generator/test/id_field_parser_test.dart +++ b/packages/nitrite_entity_generator/test/id_field_parser_test.dart @@ -14,7 +14,7 @@ void main() { final idField = IdFieldParser(fieldElement).parse(); expect(idField.fieldName, equals('id')); - expect(idField.embeddedFieldNames, isEmpty); + expect(idField.encodedFieldNames, isEmpty); expect(idField.isEmbedded, isFalse); }); @@ -27,7 +27,7 @@ void main() { final idField = IdFieldParser(fieldElement).parse(); expect(idField.fieldName, equals('id')); - expect(idField.embeddedFieldNames, isEmpty); + expect(idField.encodedFieldNames, isEmpty); expect(idField.isEmbedded, isFalse); }); @@ -40,7 +40,7 @@ void main() { final idField = IdFieldParser(fieldElement).parse(); expect(idField.fieldName, equals('customName')); - expect(idField.embeddedFieldNames, isEmpty); + expect(idField.encodedFieldNames, isEmpty); expect(idField.isEmbedded, isFalse); }); @@ -73,10 +73,10 @@ void main() { final idField = IdFieldParser(fieldElement).parse(); expect(idField.fieldName, equals('customName')); - expect(idField.embeddedFieldNames, isNotEmpty); + expect(idField.encodedFieldNames, isNotEmpty); expect(idField.isEmbedded, isTrue); - expect(idField.embeddedFieldNames, equals(['customName.name'])); - expect(idField.subFields, equals(['name'])); + expect(idField.encodedFieldNames, equals(['customName.name'])); + expect(idField.embeddedFields, equals(['name'])); }); test("Parse Id field with invalid type and embedded field", () async { diff --git a/packages/nitrite_hive_adapter/test/integration/repository/base_object_repository_test_loader.dart b/packages/nitrite_hive_adapter/test/integration/repository/base_object_repository_test_loader.dart index d66ebd4..188f499 100644 --- a/packages/nitrite_hive_adapter/test/integration/repository/base_object_repository_test_loader.dart +++ b/packages/nitrite_hive_adapter/test/integration/repository/base_object_repository_test_loader.dart @@ -131,33 +131,31 @@ Future _openDb() async { db = await Nitrite.builder() .loadModule(storeModule) + .registerEntityConverter(CompanyConverter()) + .registerEntityConverter(EmployeeConverter()) + .registerEntityConverter(NoteConverter()) + .registerEntityConverter(MyBookConverter()) + .registerEntityConverter(BookIdConverter()) + .registerEntityConverter(ClassAConverter()) + .registerEntityConverter(ClassBConverter()) + .registerEntityConverter(ClassCConverter()) + .registerEntityConverter(ElemMatchConverter()) + .registerEntityConverter(TextDataConverter()) + .registerEntityConverter(SubEmployeeConverter()) + .registerEntityConverter(ProductScoreConverter()) + .registerEntityConverter(PersonEntityConverter()) + .registerEntityConverter(RepeatableIndexTestConverter()) + .registerEntityConverter(EncryptedPersonConverter()) + .registerEntityConverter(TxDataConverter()) + .registerEntityConverter(WithNitriteIdConverter()) + .registerEntityConverter(ProductConverter()) + .registerEntityConverter(ProductIdConverter()) + .registerEntityConverter(ManufacturerConverter()) + .registerEntityConverter(MiniProductConverter()) + .registerEntityConverter(WithNullIdConverter()) + .registerEntityConverter(NewClassConverter()) + .registerEntityConverter(OldClassConverter()) + .registerEntityConverter(LiteratureConverter()) .fieldSeparator('.') .openOrCreate(); - - var mapper = db.config.nitriteMapper as SimpleNitriteMapper; - mapper.registerEntityConverter(CompanyConverter()); - mapper.registerEntityConverter(EmployeeConverter()); - mapper.registerEntityConverter(NoteConverter()); - mapper.registerEntityConverter(MyBookConverter()); - mapper.registerEntityConverter(BookIdConverter()); - mapper.registerEntityConverter(ClassAConverter()); - mapper.registerEntityConverter(ClassBConverter()); - mapper.registerEntityConverter(ClassCConverter()); - mapper.registerEntityConverter(ElemMatchConverter()); - mapper.registerEntityConverter(TextDataConverter()); - mapper.registerEntityConverter(SubEmployeeConverter()); - mapper.registerEntityConverter(ProductScoreConverter()); - mapper.registerEntityConverter(PersonEntityConverter()); - mapper.registerEntityConverter(RepeatableIndexTestConverter()); - mapper.registerEntityConverter(EncryptedPersonConverter()); - mapper.registerEntityConverter(TxDataConverter()); - mapper.registerEntityConverter(WithNitriteIdConverter()); - mapper.registerEntityConverter(ProductConverter()); - mapper.registerEntityConverter(ProductIdConverter()); - mapper.registerEntityConverter(ManufacturerConverter()); - mapper.registerEntityConverter(MiniProductConverter()); - mapper.registerEntityConverter(WithNullIdConverter()); - mapper.registerEntityConverter(NewClassConverter()); - mapper.registerEntityConverter(OldClassConverter()); - mapper.registerEntityConverter(LiteratureConverter()); }