From 8a85689cbd532de36d1c9f036e41acf1a6871e6e Mon Sep 17 00:00:00 2001 From: Hui Zhao <10602282+HuiSF@users.noreply.github.com> Date: Mon, 4 Apr 2022 17:38:22 -0700 Subject: [PATCH] feat(datastore): model identifier support in dart (#1430) * Convert Model.dart to LF mode * feat(datastore): Adding ModelIdentifier interface * - Update test models t conform interface changes - Update DataStore unit tests to use test_models provided by amplify_test package - Update API unit tests to use updated test models * Update DataStore example App models * Re-apply change after merge main * Regenerated test models with fix adding @override * Fix transitive dependency error * Restore unexpected change * Add unit tests for modelIdentifier getter --- .../example/integration_test/mocks.dart | 22 ++ .../lib/src/types/models/model.dart | 156 +++++---- .../lib/models/BelongsToChildExplicit.dart | 49 ++- .../lib/models/BelongsToChildImplicit.dart | 49 ++- .../example/lib/models/BelongsToParent.dart | 50 ++- .../example/lib/models/Blog.dart | 54 ++- .../example/lib/models/Comment.dart | 60 +++- .../CustomTypeWithAppsyncScalarTypes.dart | 2 +- .../HasManyChildBiDirectionalExplicit.dart | 58 +++- .../HasManyChildBiDirectionalImplicit.dart | 53 ++- .../lib/models/HasManyChildExplicit.dart | 61 +++- .../lib/models/HasManyChildImplicit.dart | 49 ++- .../example/lib/models/HasManyParent.dart | 49 ++- .../HasManyParentBiDirectionalExplicit.dart | 52 ++- .../HasManyParentBiDirectionalImplicit.dart | 52 ++- .../example/lib/models/HasOneChild.dart | 48 ++- .../example/lib/models/HasOneParent.dart | 49 ++- .../example/lib/models/ModelProvider.dart | 2 +- .../models/ModelWithAppsyncScalarTypes.dart | 51 ++- .../lib/models/ModelWithCustomType.dart | 50 ++- .../example/lib/models/ModelWithEnum.dart | 48 ++- .../lib/models/MultiRelatedAttendee.dart | 54 ++- .../lib/models/MultiRelatedMeeting.dart | 59 +++- .../lib/models/MultiRelatedRegistration.dart | 69 +++- .../example/lib/models/Post.dart | 65 +++- .../example/lib/models/PostTags.dart | 60 +++- .../example/lib/models/SimpleCustomType.dart | 8 +- .../example/lib/models/Tag.dart | 56 ++- .../test/amplify_datastore_clear_test.dart | 2 +- ...y_datastore_custom_error_handler_test.dart | 2 +- .../test/amplify_datastore_delete_test.dart | 2 +- .../test/amplify_datastore_observe_test.dart | 2 +- .../test/amplify_datastore_query_test.dart | 2 +- .../test/amplify_datastore_save_test.dart | 2 +- ...lify_datastore_stream_controller_test.dart | 2 +- .../test/amplify_datastore_test.dart | 2 +- .../test/observe_query_executor_test.dart | 2 +- .../test/outbox_mutation_event_test.dart | 2 +- .../test/query_predicate_test.dart | 2 +- .../test/query_sort_test.dart | 2 +- .../test/test_models/Blog.dart | 192 ---------- .../test/test_models/Comment.dart | 189 ---------- .../test/test_models/ModelProvider.dart | 65 ---- .../test/test_models/Post.dart | 311 ----------------- .../test/test_models/StringListTypeModel.dart | 112 ------ .../test/test_models/test_schema.graphql | 24 -- .../test/amplify_custom_type_schema_test.dart | 2 +- .../test/amplify_modelType_test.dart | 2 +- .../test/amplify_modelschema_test.dart | 13 +- .../test/amplify_modelschema_to_map_test.dart | 32 +- .../test/model_identifier_test.dart | 129 +++++++ .../test/query_snapshot_test.dart | 2 +- .../test/testData/Blog.dart | 196 ----------- .../test/testData/Comment.dart | 193 ----------- .../test/testData/ModelProvider.dart | 78 ----- .../test/testData/Post.dart | 315 ----------------- .../lib/test_models}/Address.dart | 28 +- .../amplify_test/lib/test_models/Blog.dart | 68 +++- .../amplify_test/lib/test_models/Comment.dart | 65 +++- .../lib/test_models}/Contact.dart | 16 +- .../lib/test_models/FileMeta.dart | 10 +- .../lib/test_models/Inventory.dart | 327 ++++++++++++++++++ .../lib/test_models/ModelProvider.dart | 52 ++- .../lib/test_models}/Person.dart | 16 +- .../lib/test_models}/Phone.dart | 16 +- .../amplify_test/lib/test_models/Post.dart | 91 ++++- .../lib/test_models/PostWithAuthRules.dart} | 101 ++++-- .../amplify_test/lib/test_models/Product.dart | 267 ++++++++++++++ .../lib/test_models/S3Object.dart | 16 +- .../lib/test_models/StringListTypeModel.dart | 200 +++++++++++ .../lib/test_models/Warehouse.dart | 251 ++++++++++++++ .../lib/test_models/schema.graphql} | 65 +++- packages/amplify_test/pubspec.yaml | 1 + .../amplify_api/example/tool/schema.graphql | 42 +++ .../test/graphql_helpers_test.dart | 6 +- .../types/pagination/paginated_result.dart | 22 ++ 76 files changed, 2899 insertions(+), 2075 deletions(-) delete mode 100644 packages/amplify_datastore/test/test_models/Blog.dart delete mode 100644 packages/amplify_datastore/test/test_models/Comment.dart delete mode 100644 packages/amplify_datastore/test/test_models/ModelProvider.dart delete mode 100644 packages/amplify_datastore/test/test_models/Post.dart delete mode 100644 packages/amplify_datastore/test/test_models/StringListTypeModel.dart delete mode 100644 packages/amplify_datastore/test/test_models/test_schema.graphql create mode 100644 packages/amplify_datastore_plugin_interface/test/model_identifier_test.dart delete mode 100644 packages/amplify_datastore_plugin_interface/test/testData/Blog.dart delete mode 100644 packages/amplify_datastore_plugin_interface/test/testData/Comment.dart delete mode 100644 packages/amplify_datastore_plugin_interface/test/testData/ModelProvider.dart delete mode 100644 packages/amplify_datastore_plugin_interface/test/testData/Post.dart rename packages/{amplify_datastore_plugin_interface/test/testData => amplify_test/lib/test_models}/Address.dart (89%) rename packages/{amplify_datastore_plugin_interface/test/testData => amplify_test/lib/test_models}/Contact.dart (92%) create mode 100644 packages/amplify_test/lib/test_models/Inventory.dart rename packages/{amplify_datastore_plugin_interface/test/testData => amplify_test/lib/test_models}/Person.dart (92%) rename packages/{amplify_datastore_plugin_interface/test/testData => amplify_test/lib/test_models}/Phone.dart (88%) rename packages/{amplify_datastore_plugin_interface/test/testData/PostAuthComplex.dart => amplify_test/lib/test_models/PostWithAuthRules.dart} (63%) create mode 100644 packages/amplify_test/lib/test_models/Product.dart create mode 100644 packages/amplify_test/lib/test_models/StringListTypeModel.dart create mode 100644 packages/amplify_test/lib/test_models/Warehouse.dart rename packages/{amplify_datastore_plugin_interface/test/testData/testData_schema.graphql => amplify_test/lib/test_models/schema.graphql} (54%) diff --git a/packages/amplify/amplify_flutter_ios/example/integration_test/mocks.dart b/packages/amplify/amplify_flutter_ios/example/integration_test/mocks.dart index 1f6163f78b..6bd90f2760 100644 --- a/packages/amplify/amplify_flutter_ios/example/integration_test/mocks.dart +++ b/packages/amplify/amplify_flutter_ios/example/integration_test/mocks.dart @@ -24,6 +24,23 @@ class MockModelType extends ModelType { } } +class _MockModelIdentifier implements ModelIdentifier { + final List> emptyList = const []; + final Map emptyMap = const {}; + final String emptyString = ''; + + const _MockModelIdentifier(); + + @override + List> serializeAsList() => emptyList; + + @override + Map serializeAsMap() => emptyMap; + + @override + String serializeAsString() => emptyString; +} + class MockModel extends Model { final String id; @@ -32,6 +49,11 @@ class MockModel extends Model { @override String getId() => id; + @override + ModelIdentifier get modelIdentifier { + return const _MockModelIdentifier(); + } + @override ModelType getInstanceType() => const MockModelType(); diff --git a/packages/amplify_core/lib/src/types/models/model.dart b/packages/amplify_core/lib/src/types/models/model.dart index e2df60b868..adfbb1ccc1 100644 --- a/packages/amplify_core/lib/src/types/models/model.dart +++ b/packages/amplify_core/lib/src/types/models/model.dart @@ -1,68 +1,88 @@ -/* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -import 'model_schema.dart'; -import 'model_schema_definition.dart'; - -abstract class Model { - ModelType getInstanceType(); - - String getId(); - - Map toJson(); - - const Model(); - - static ModelSchema defineSchema( - {required Function(ModelSchemaDefinition) define}) { - var definition = ModelSchemaDefinition(); - - define(definition); - - return definition.build(); - } -} - -// New ModelType superclass -abstract class ModelType { - const ModelType(); - - T fromSerializedMap(Map serializedMap) { - return fromJson(serializedMap['serializedData']); - } - - T fromJson(Map jsonData); - - String modelName() { - return T.toString(); - } - - /// Perform [action] with [T] as type argument. - R callWithType(R Function() action) => action(); - - // Checks and casts. - bool isInstance(Object o) => o is T; - T cast(Object o) => o as T; - T? safeCast(Object o) => o is T ? o : null; - - // Subtyping checks. - bool operator >=(ModelType other) => other is ModelType; - bool operator <=(ModelType other) => other >= this; - bool operator <(ModelType other) => other >= this && !(this >= other); - bool operator >(ModelType other) => this >= other && !(other >= this); - bool operator ==(Object other) => - other is ModelType && this >= other && other >= this; - int get hashCode => T.hashCode; -} +/* + * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +import 'model_schema.dart'; +import 'model_schema_definition.dart'; + +abstract class Model { + ModelType getInstanceType(); + + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') + String getId(); + + Map toJson(); + + ModelIdentifier get modelIdentifier; + + const Model(); + + static ModelSchema defineSchema( + {required Function(ModelSchemaDefinition) define}) { + var definition = ModelSchemaDefinition(); + + define(definition); + + return definition.build(); + } +} + +// New ModelType superclass +abstract class ModelType { + const ModelType(); + + T fromSerializedMap(Map serializedMap) { + return fromJson(serializedMap['serializedData']); + } + + T fromJson(Map jsonData); + + String modelName() { + return T.toString(); + } + + /// Perform [action] with [T] as type argument. + R callWithType(R Function() action) => action(); + + // Checks and casts. + bool isInstance(Object o) => o is T; + T cast(Object o) => o as T; + T? safeCast(Object o) => o is T ? o : null; + + // Subtyping checks. + bool operator >=(ModelType other) => other is ModelType; + bool operator <=(ModelType other) => other >= this; + bool operator <(ModelType other) => other >= this && !(this >= other); + bool operator >(ModelType other) => this >= other && !(other >= this); + bool operator ==(Object other) => + other is ModelType && this >= other && other >= this; + int get hashCode => T.hashCode; +} + +/// Model identifier presentation +abstract class ModelIdentifier { + const ModelIdentifier(); + + /// Serialize a model identifier as a map. + Map serializeAsMap(); + + /// Serialize a model identifier as a list of key-value pairs. The order of + /// key-value pairs presents primary key and sort keys. + List> serializeAsList(); + + /// Serialize a model identifier into a single string in format: + /// [#] + String serializeAsString(); +} diff --git a/packages/amplify_datastore/example/lib/models/BelongsToChildExplicit.dart b/packages/amplify_datastore/example/lib/models/BelongsToChildExplicit.dart index 8a18880e85..80564e63bc 100644 --- a/packages/amplify_datastore/example/lib/models/BelongsToChildExplicit.dart +++ b/packages/amplify_datastore/example/lib/models/BelongsToChildExplicit.dart @@ -20,7 +20,7 @@ // ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code import 'ModelProvider.dart'; -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:flutter/foundation.dart'; /// This is an auto generated class representing the BelongsToChildExplicit type in your schema. @@ -36,9 +36,13 @@ class BelongsToChildExplicit extends Model { @override getInstanceType() => classType; + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') @override - String getId() { - return id; + String getId() => id; + + BelongsToChildExplicitModelIdentifier get modelIdentifier { + return BelongsToChildExplicitModelIdentifier(id: id); } String? get name { @@ -109,9 +113,9 @@ class BelongsToChildExplicit extends Model { } BelongsToChildExplicit copyWith( - {String? id, String? name, BelongsToParent? belongsToParent}) { + {String? name, BelongsToParent? belongsToParent}) { return BelongsToChildExplicit._internal( - id: id ?? this.id, + id: id, name: name ?? this.name, belongsToParent: belongsToParent ?? this.belongsToParent); } @@ -186,3 +190,38 @@ class _BelongsToChildExplicitModelType return BelongsToChildExplicit.fromJson(jsonData); } } + +/// This is an auto generated class representing the model identifier +/// of [BelongsToChildExplicit] in your schema. +@immutable +class BelongsToChildExplicitModelIdentifier + implements ModelIdentifier { + final String id; + + /// Create an instance of BelongsToChildExplicitModelIdentifier using [id] the primary key. + const BelongsToChildExplicitModelIdentifier({required this.id}); + + Map serializeAsMap() => ({'id': id}); + + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'BelongsToChildExplicitModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is BelongsToChildExplicitModelIdentifier && id == other.id; + } + + @override + int get hashCode => id.hashCode; +} diff --git a/packages/amplify_datastore/example/lib/models/BelongsToChildImplicit.dart b/packages/amplify_datastore/example/lib/models/BelongsToChildImplicit.dart index 5f059c7dc8..bec4fb8742 100644 --- a/packages/amplify_datastore/example/lib/models/BelongsToChildImplicit.dart +++ b/packages/amplify_datastore/example/lib/models/BelongsToChildImplicit.dart @@ -20,7 +20,7 @@ // ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code import 'ModelProvider.dart'; -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:flutter/foundation.dart'; /// This is an auto generated class representing the BelongsToChildImplicit type in your schema. @@ -36,9 +36,13 @@ class BelongsToChildImplicit extends Model { @override getInstanceType() => classType; + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') @override - String getId() { - return id; + String getId() => id; + + BelongsToChildImplicitModelIdentifier get modelIdentifier { + return BelongsToChildImplicitModelIdentifier(id: id); } String? get name { @@ -109,9 +113,9 @@ class BelongsToChildImplicit extends Model { } BelongsToChildImplicit copyWith( - {String? id, String? name, BelongsToParent? belongsToParent}) { + {String? name, BelongsToParent? belongsToParent}) { return BelongsToChildImplicit._internal( - id: id ?? this.id, + id: id, name: name ?? this.name, belongsToParent: belongsToParent ?? this.belongsToParent); } @@ -186,3 +190,38 @@ class _BelongsToChildImplicitModelType return BelongsToChildImplicit.fromJson(jsonData); } } + +/// This is an auto generated class representing the model identifier +/// of [BelongsToChildImplicit] in your schema. +@immutable +class BelongsToChildImplicitModelIdentifier + implements ModelIdentifier { + final String id; + + /// Create an instance of BelongsToChildImplicitModelIdentifier using [id] the primary key. + const BelongsToChildImplicitModelIdentifier({required this.id}); + + Map serializeAsMap() => ({'id': id}); + + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'BelongsToChildImplicitModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is BelongsToChildImplicitModelIdentifier && id == other.id; + } + + @override + int get hashCode => id.hashCode; +} diff --git a/packages/amplify_datastore/example/lib/models/BelongsToParent.dart b/packages/amplify_datastore/example/lib/models/BelongsToParent.dart index 6eef03def2..17eb6f0a79 100644 --- a/packages/amplify_datastore/example/lib/models/BelongsToParent.dart +++ b/packages/amplify_datastore/example/lib/models/BelongsToParent.dart @@ -20,7 +20,7 @@ // ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code import 'ModelProvider.dart'; -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:flutter/foundation.dart'; /// This is an auto generated class representing the BelongsToParent type in your schema. @@ -39,9 +39,13 @@ class BelongsToParent extends Model { @override getInstanceType() => classType; + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') @override - String getId() { - return id; + String getId() => id; + + BelongsToParentModelIdentifier get modelIdentifier { + return BelongsToParentModelIdentifier(id: id); } String? get name { @@ -150,14 +154,13 @@ class BelongsToParent extends Model { } BelongsToParent copyWith( - {String? id, - String? name, + {String? name, BelongsToChildImplicit? implicitChild, BelongsToChildExplicit? explicitChild, String? belongsToParentImplicitChildId, String? belongsToParentExplicitChildId}) { return BelongsToParent._internal( - id: id ?? this.id, + id: id, name: name ?? this.name, implicitChild: implicitChild ?? this.implicitChild, explicitChild: explicitChild ?? this.explicitChild, @@ -270,3 +273,38 @@ class _BelongsToParentModelType extends ModelType { return BelongsToParent.fromJson(jsonData); } } + +/// This is an auto generated class representing the model identifier +/// of [BelongsToParent] in your schema. +@immutable +class BelongsToParentModelIdentifier + implements ModelIdentifier { + final String id; + + /// Create an instance of BelongsToParentModelIdentifier using [id] the primary key. + const BelongsToParentModelIdentifier({required this.id}); + + Map serializeAsMap() => ({'id': id}); + + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'BelongsToParentModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is BelongsToParentModelIdentifier && id == other.id; + } + + @override + int get hashCode => id.hashCode; +} diff --git a/packages/amplify_datastore/example/lib/models/Blog.dart b/packages/amplify_datastore/example/lib/models/Blog.dart index 95dd9b2c6d..71235b1386 100644 --- a/packages/amplify_datastore/example/lib/models/Blog.dart +++ b/packages/amplify_datastore/example/lib/models/Blog.dart @@ -20,7 +20,7 @@ // ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code import 'ModelProvider.dart'; -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; @@ -37,19 +37,23 @@ class Blog extends Model { @override getInstanceType() => classType; + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') @override - String getId() { - return id; + String getId() => id; + + BlogModelIdentifier get modelIdentifier { + return BlogModelIdentifier(id: id); } String get name { try { return _name!; } catch (e) { - throw DataStoreException( - DataStoreExceptionMessages + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages + recoverySuggestion: AmplifyExceptionMessages .codeGenRequiredFieldForceCastRecoverySuggestion, underlyingException: e.toString()); } @@ -114,9 +118,9 @@ class Blog extends Model { return buffer.toString(); } - Blog copyWith({String? id, String? name, List? posts}) { + Blog copyWith({String? name, List? posts}) { return Blog._internal( - id: id ?? this.id, name: name ?? this.name, posts: posts ?? this.posts); + id: id, name: name ?? this.name, posts: posts ?? this.posts); } Blog.fromJson(Map json) @@ -190,3 +194,37 @@ class _BlogModelType extends ModelType { return Blog.fromJson(jsonData); } } + +/// This is an auto generated class representing the model identifier +/// of [Blog] in your schema. +@immutable +class BlogModelIdentifier implements ModelIdentifier { + final String id; + + /// Create an instance of BlogModelIdentifier using [id] the primary key. + const BlogModelIdentifier({required this.id}); + + Map serializeAsMap() => ({'id': id}); + + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'BlogModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is BlogModelIdentifier && id == other.id; + } + + @override + int get hashCode => id.hashCode; +} diff --git a/packages/amplify_datastore/example/lib/models/Comment.dart b/packages/amplify_datastore/example/lib/models/Comment.dart index 067aea5ee5..e573f28773 100644 --- a/packages/amplify_datastore/example/lib/models/Comment.dart +++ b/packages/amplify_datastore/example/lib/models/Comment.dart @@ -20,7 +20,7 @@ // ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code import 'ModelProvider.dart'; -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:flutter/foundation.dart'; /// This is an auto generated class representing the Comment type in your schema. @@ -36,9 +36,13 @@ class Comment extends Model { @override getInstanceType() => classType; + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') @override - String getId() { - return id; + String getId() => id; + + CommentModelIdentifier get modelIdentifier { + return CommentModelIdentifier(id: id); } Post? get post { @@ -49,10 +53,10 @@ class Comment extends Model { try { return _content!; } catch (e) { - throw DataStoreException( - DataStoreExceptionMessages + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages + recoverySuggestion: AmplifyExceptionMessages .codeGenRequiredFieldForceCastRecoverySuggestion, underlyingException: e.toString()); } @@ -112,11 +116,9 @@ class Comment extends Model { return buffer.toString(); } - Comment copyWith({String? id, Post? post, String? content}) { + Comment copyWith({Post? post, String? content}) { return Comment._internal( - id: id ?? this.id, - post: post ?? this.post, - content: content ?? this.content); + id: id, post: post ?? this.post, content: content ?? this.content); } Comment.fromJson(Map json) @@ -152,6 +154,10 @@ class Comment extends Model { modelSchemaDefinition.name = "Comment"; modelSchemaDefinition.pluralName = "Comments"; + modelSchemaDefinition.indexes = [ + ModelIndex(fields: const ["postID", "content"], name: "byPost") + ]; + modelSchemaDefinition.addField(ModelFieldDefinition.id()); modelSchemaDefinition.addField(ModelFieldDefinition.belongsTo( @@ -187,3 +193,37 @@ class _CommentModelType extends ModelType { return Comment.fromJson(jsonData); } } + +/// This is an auto generated class representing the model identifier +/// of [Comment] in your schema. +@immutable +class CommentModelIdentifier implements ModelIdentifier { + final String id; + + /// Create an instance of CommentModelIdentifier using [id] the primary key. + const CommentModelIdentifier({required this.id}); + + Map serializeAsMap() => ({'id': id}); + + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'CommentModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is CommentModelIdentifier && id == other.id; + } + + @override + int get hashCode => id.hashCode; +} diff --git a/packages/amplify_datastore/example/lib/models/CustomTypeWithAppsyncScalarTypes.dart b/packages/amplify_datastore/example/lib/models/CustomTypeWithAppsyncScalarTypes.dart index 38c44eb85e..97843b652f 100644 --- a/packages/amplify_datastore/example/lib/models/CustomTypeWithAppsyncScalarTypes.dart +++ b/packages/amplify_datastore/example/lib/models/CustomTypeWithAppsyncScalarTypes.dart @@ -20,7 +20,7 @@ // ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code import 'ModelProvider.dart'; -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; diff --git a/packages/amplify_datastore/example/lib/models/HasManyChildBiDirectionalExplicit.dart b/packages/amplify_datastore/example/lib/models/HasManyChildBiDirectionalExplicit.dart index 112a480bf8..f886c875c5 100644 --- a/packages/amplify_datastore/example/lib/models/HasManyChildBiDirectionalExplicit.dart +++ b/packages/amplify_datastore/example/lib/models/HasManyChildBiDirectionalExplicit.dart @@ -20,7 +20,7 @@ // ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code import 'ModelProvider.dart'; -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:flutter/foundation.dart'; /// This is an auto generated class representing the HasManyChildBiDirectionalExplicit type in your schema. @@ -36,9 +36,13 @@ class HasManyChildBiDirectionalExplicit extends Model { @override getInstanceType() => classType; + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') @override - String getId() { - return id; + String getId() => id; + + HasManyChildBiDirectionalExplicitModelIdentifier get modelIdentifier { + return HasManyChildBiDirectionalExplicitModelIdentifier(id: id); } String? get name { @@ -111,11 +115,9 @@ class HasManyChildBiDirectionalExplicit extends Model { } HasManyChildBiDirectionalExplicit copyWith( - {String? id, - String? name, - HasManyParentBiDirectionalExplicit? hasManyParent}) { + {String? name, HasManyParentBiDirectionalExplicit? hasManyParent}) { return HasManyChildBiDirectionalExplicit._internal( - id: id ?? this.id, + id: id, name: name ?? this.name, hasManyParent: hasManyParent ?? this.hasManyParent); } @@ -155,6 +157,11 @@ class HasManyChildBiDirectionalExplicit extends Model { modelSchemaDefinition.name = "HasManyChildBiDirectionalExplicit"; modelSchemaDefinition.pluralName = "HasManyChildBiDirectionalExplicits"; + modelSchemaDefinition.indexes = [ + ModelIndex( + fields: const ["hasManyParentId", "name"], name: "byHasManyParent") + ]; + modelSchemaDefinition.addField(ModelFieldDefinition.id()); modelSchemaDefinition.addField(ModelFieldDefinition.field( @@ -191,3 +198,40 @@ class _HasManyChildBiDirectionalExplicitModelType return HasManyChildBiDirectionalExplicit.fromJson(jsonData); } } + +/// This is an auto generated class representing the model identifier +/// of [HasManyChildBiDirectionalExplicit] in your schema. +@immutable +class HasManyChildBiDirectionalExplicitModelIdentifier + implements ModelIdentifier { + final String id; + + /// Create an instance of HasManyChildBiDirectionalExplicitModelIdentifier using [id] the primary key. + const HasManyChildBiDirectionalExplicitModelIdentifier({required this.id}); + + Map serializeAsMap() => ({'id': id}); + + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => + 'HasManyChildBiDirectionalExplicitModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is HasManyChildBiDirectionalExplicitModelIdentifier && + id == other.id; + } + + @override + int get hashCode => id.hashCode; +} diff --git a/packages/amplify_datastore/example/lib/models/HasManyChildBiDirectionalImplicit.dart b/packages/amplify_datastore/example/lib/models/HasManyChildBiDirectionalImplicit.dart index 6a583bf01d..bd4222984b 100644 --- a/packages/amplify_datastore/example/lib/models/HasManyChildBiDirectionalImplicit.dart +++ b/packages/amplify_datastore/example/lib/models/HasManyChildBiDirectionalImplicit.dart @@ -20,7 +20,7 @@ // ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code import 'ModelProvider.dart'; -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:flutter/foundation.dart'; /// This is an auto generated class representing the HasManyChildBiDirectionalImplicit type in your schema. @@ -36,9 +36,13 @@ class HasManyChildBiDirectionalImplicit extends Model { @override getInstanceType() => classType; + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') @override - String getId() { - return id; + String getId() => id; + + HasManyChildBiDirectionalImplicitModelIdentifier get modelIdentifier { + return HasManyChildBiDirectionalImplicitModelIdentifier(id: id); } String? get name { @@ -111,11 +115,9 @@ class HasManyChildBiDirectionalImplicit extends Model { } HasManyChildBiDirectionalImplicit copyWith( - {String? id, - String? name, - HasManyParentBiDirectionalImplicit? hasManyParent}) { + {String? name, HasManyParentBiDirectionalImplicit? hasManyParent}) { return HasManyChildBiDirectionalImplicit._internal( - id: id ?? this.id, + id: id, name: name ?? this.name, hasManyParent: hasManyParent ?? this.hasManyParent); } @@ -192,3 +194,40 @@ class _HasManyChildBiDirectionalImplicitModelType return HasManyChildBiDirectionalImplicit.fromJson(jsonData); } } + +/// This is an auto generated class representing the model identifier +/// of [HasManyChildBiDirectionalImplicit] in your schema. +@immutable +class HasManyChildBiDirectionalImplicitModelIdentifier + implements ModelIdentifier { + final String id; + + /// Create an instance of HasManyChildBiDirectionalImplicitModelIdentifier using [id] the primary key. + const HasManyChildBiDirectionalImplicitModelIdentifier({required this.id}); + + Map serializeAsMap() => ({'id': id}); + + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => + 'HasManyChildBiDirectionalImplicitModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is HasManyChildBiDirectionalImplicitModelIdentifier && + id == other.id; + } + + @override + int get hashCode => id.hashCode; +} diff --git a/packages/amplify_datastore/example/lib/models/HasManyChildExplicit.dart b/packages/amplify_datastore/example/lib/models/HasManyChildExplicit.dart index 8de8bc2261..c188bf6a35 100644 --- a/packages/amplify_datastore/example/lib/models/HasManyChildExplicit.dart +++ b/packages/amplify_datastore/example/lib/models/HasManyChildExplicit.dart @@ -19,7 +19,7 @@ // ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:flutter/foundation.dart'; /// This is an auto generated class representing the HasManyChildExplicit type in your schema. @@ -35,9 +35,13 @@ class HasManyChildExplicit extends Model { @override getInstanceType() => classType; + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') @override - String getId() { - return id; + String getId() => id; + + HasManyChildExplicitModelIdentifier get modelIdentifier { + return HasManyChildExplicitModelIdentifier(id: id); } String? get name { @@ -48,10 +52,10 @@ class HasManyChildExplicit extends Model { try { return _hasManyParentID!; } catch (e) { - throw DataStoreException( - DataStoreExceptionMessages + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages + recoverySuggestion: AmplifyExceptionMessages .codeGenRequiredFieldForceCastRecoverySuggestion, underlyingException: e.toString()); } @@ -114,10 +118,9 @@ class HasManyChildExplicit extends Model { return buffer.toString(); } - HasManyChildExplicit copyWith( - {String? id, String? name, String? hasManyParentID}) { + HasManyChildExplicit copyWith({String? name, String? hasManyParentID}) { return HasManyChildExplicit._internal( - id: id ?? this.id, + id: id, name: name ?? this.name, hasManyParentID: hasManyParentID ?? this.hasManyParentID); } @@ -150,6 +153,11 @@ class HasManyChildExplicit extends Model { modelSchemaDefinition.name = "HasManyChildExplicit"; modelSchemaDefinition.pluralName = "HasManyChildExplicits"; + modelSchemaDefinition.indexes = [ + ModelIndex( + fields: const ["hasManyParentID", "name"], name: "byHasManyParent") + ]; + modelSchemaDefinition.addField(ModelFieldDefinition.id()); modelSchemaDefinition.addField(ModelFieldDefinition.field( @@ -184,3 +192,38 @@ class _HasManyChildExplicitModelType extends ModelType { return HasManyChildExplicit.fromJson(jsonData); } } + +/// This is an auto generated class representing the model identifier +/// of [HasManyChildExplicit] in your schema. +@immutable +class HasManyChildExplicitModelIdentifier + implements ModelIdentifier { + final String id; + + /// Create an instance of HasManyChildExplicitModelIdentifier using [id] the primary key. + const HasManyChildExplicitModelIdentifier({required this.id}); + + Map serializeAsMap() => ({'id': id}); + + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'HasManyChildExplicitModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is HasManyChildExplicitModelIdentifier && id == other.id; + } + + @override + int get hashCode => id.hashCode; +} diff --git a/packages/amplify_datastore/example/lib/models/HasManyChildImplicit.dart b/packages/amplify_datastore/example/lib/models/HasManyChildImplicit.dart index 23604668d2..da152221a0 100644 --- a/packages/amplify_datastore/example/lib/models/HasManyChildImplicit.dart +++ b/packages/amplify_datastore/example/lib/models/HasManyChildImplicit.dart @@ -19,7 +19,7 @@ // ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:flutter/foundation.dart'; /// This is an auto generated class representing the HasManyChildImplicit type in your schema. @@ -35,9 +35,13 @@ class HasManyChildImplicit extends Model { @override getInstanceType() => classType; + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') @override - String getId() { - return id; + String getId() => id; + + HasManyChildImplicitModelIdentifier get modelIdentifier { + return HasManyChildImplicitModelIdentifier(id: id); } String? get name { @@ -113,9 +117,9 @@ class HasManyChildImplicit extends Model { } HasManyChildImplicit copyWith( - {String? id, String? name, String? hasManyParentImplicitChildrenId}) { + {String? name, String? hasManyParentImplicitChildrenId}) { return HasManyChildImplicit._internal( - id: id ?? this.id, + id: id, name: name ?? this.name, hasManyParentImplicitChildrenId: hasManyParentImplicitChildrenId ?? this.hasManyParentImplicitChildrenId); @@ -184,3 +188,38 @@ class _HasManyChildImplicitModelType extends ModelType { return HasManyChildImplicit.fromJson(jsonData); } } + +/// This is an auto generated class representing the model identifier +/// of [HasManyChildImplicit] in your schema. +@immutable +class HasManyChildImplicitModelIdentifier + implements ModelIdentifier { + final String id; + + /// Create an instance of HasManyChildImplicitModelIdentifier using [id] the primary key. + const HasManyChildImplicitModelIdentifier({required this.id}); + + Map serializeAsMap() => ({'id': id}); + + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'HasManyChildImplicitModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is HasManyChildImplicitModelIdentifier && id == other.id; + } + + @override + int get hashCode => id.hashCode; +} diff --git a/packages/amplify_datastore/example/lib/models/HasManyParent.dart b/packages/amplify_datastore/example/lib/models/HasManyParent.dart index abcc3394eb..e26511eed9 100644 --- a/packages/amplify_datastore/example/lib/models/HasManyParent.dart +++ b/packages/amplify_datastore/example/lib/models/HasManyParent.dart @@ -20,7 +20,7 @@ // ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code import 'ModelProvider.dart'; -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; @@ -38,9 +38,13 @@ class HasManyParent extends Model { @override getInstanceType() => classType; + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') @override - String getId() { - return id; + String getId() => id; + + HasManyParentModelIdentifier get modelIdentifier { + return HasManyParentModelIdentifier(id: id); } String? get name { @@ -129,12 +133,11 @@ class HasManyParent extends Model { } HasManyParent copyWith( - {String? id, - String? name, + {String? name, List? implicitChildren, List? explicitChildren}) { return HasManyParent._internal( - id: id ?? this.id, + id: id, name: name ?? this.name, implicitChildren: implicitChildren ?? this.implicitChildren, explicitChildren: explicitChildren ?? this.explicitChildren); @@ -233,3 +236,37 @@ class _HasManyParentModelType extends ModelType { return HasManyParent.fromJson(jsonData); } } + +/// This is an auto generated class representing the model identifier +/// of [HasManyParent] in your schema. +@immutable +class HasManyParentModelIdentifier implements ModelIdentifier { + final String id; + + /// Create an instance of HasManyParentModelIdentifier using [id] the primary key. + const HasManyParentModelIdentifier({required this.id}); + + Map serializeAsMap() => ({'id': id}); + + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'HasManyParentModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is HasManyParentModelIdentifier && id == other.id; + } + + @override + int get hashCode => id.hashCode; +} diff --git a/packages/amplify_datastore/example/lib/models/HasManyParentBiDirectionalExplicit.dart b/packages/amplify_datastore/example/lib/models/HasManyParentBiDirectionalExplicit.dart index 504f1687b0..f610845034 100644 --- a/packages/amplify_datastore/example/lib/models/HasManyParentBiDirectionalExplicit.dart +++ b/packages/amplify_datastore/example/lib/models/HasManyParentBiDirectionalExplicit.dart @@ -20,7 +20,7 @@ // ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code import 'ModelProvider.dart'; -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; @@ -37,9 +37,13 @@ class HasManyParentBiDirectionalExplicit extends Model { @override getInstanceType() => classType; + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') @override - String getId() { - return id; + String getId() => id; + + HasManyParentBiDirectionalExplicitModelIdentifier get modelIdentifier { + return HasManyParentBiDirectionalExplicitModelIdentifier(id: id); } String? get name { @@ -117,11 +121,10 @@ class HasManyParentBiDirectionalExplicit extends Model { } HasManyParentBiDirectionalExplicit copyWith( - {String? id, - String? name, + {String? name, List? biDirectionalExplicitChildren}) { return HasManyParentBiDirectionalExplicit._internal( - id: id ?? this.id, + id: id, name: name ?? this.name, biDirectionalExplicitChildren: biDirectionalExplicitChildren ?? this.biDirectionalExplicitChildren); @@ -203,3 +206,40 @@ class _HasManyParentBiDirectionalExplicitModelType return HasManyParentBiDirectionalExplicit.fromJson(jsonData); } } + +/// This is an auto generated class representing the model identifier +/// of [HasManyParentBiDirectionalExplicit] in your schema. +@immutable +class HasManyParentBiDirectionalExplicitModelIdentifier + implements ModelIdentifier { + final String id; + + /// Create an instance of HasManyParentBiDirectionalExplicitModelIdentifier using [id] the primary key. + const HasManyParentBiDirectionalExplicitModelIdentifier({required this.id}); + + Map serializeAsMap() => ({'id': id}); + + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => + 'HasManyParentBiDirectionalExplicitModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is HasManyParentBiDirectionalExplicitModelIdentifier && + id == other.id; + } + + @override + int get hashCode => id.hashCode; +} diff --git a/packages/amplify_datastore/example/lib/models/HasManyParentBiDirectionalImplicit.dart b/packages/amplify_datastore/example/lib/models/HasManyParentBiDirectionalImplicit.dart index 259d460371..3eae23205f 100644 --- a/packages/amplify_datastore/example/lib/models/HasManyParentBiDirectionalImplicit.dart +++ b/packages/amplify_datastore/example/lib/models/HasManyParentBiDirectionalImplicit.dart @@ -20,7 +20,7 @@ // ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code import 'ModelProvider.dart'; -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; @@ -37,9 +37,13 @@ class HasManyParentBiDirectionalImplicit extends Model { @override getInstanceType() => classType; + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') @override - String getId() { - return id; + String getId() => id; + + HasManyParentBiDirectionalImplicitModelIdentifier get modelIdentifier { + return HasManyParentBiDirectionalImplicitModelIdentifier(id: id); } String? get name { @@ -117,11 +121,10 @@ class HasManyParentBiDirectionalImplicit extends Model { } HasManyParentBiDirectionalImplicit copyWith( - {String? id, - String? name, + {String? name, List? biDirectionalImplicitChildren}) { return HasManyParentBiDirectionalImplicit._internal( - id: id ?? this.id, + id: id, name: name ?? this.name, biDirectionalImplicitChildren: biDirectionalImplicitChildren ?? this.biDirectionalImplicitChildren); @@ -203,3 +206,40 @@ class _HasManyParentBiDirectionalImplicitModelType return HasManyParentBiDirectionalImplicit.fromJson(jsonData); } } + +/// This is an auto generated class representing the model identifier +/// of [HasManyParentBiDirectionalImplicit] in your schema. +@immutable +class HasManyParentBiDirectionalImplicitModelIdentifier + implements ModelIdentifier { + final String id; + + /// Create an instance of HasManyParentBiDirectionalImplicitModelIdentifier using [id] the primary key. + const HasManyParentBiDirectionalImplicitModelIdentifier({required this.id}); + + Map serializeAsMap() => ({'id': id}); + + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => + 'HasManyParentBiDirectionalImplicitModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is HasManyParentBiDirectionalImplicitModelIdentifier && + id == other.id; + } + + @override + int get hashCode => id.hashCode; +} diff --git a/packages/amplify_datastore/example/lib/models/HasOneChild.dart b/packages/amplify_datastore/example/lib/models/HasOneChild.dart index 3fced6064f..ae94c1a5d4 100644 --- a/packages/amplify_datastore/example/lib/models/HasOneChild.dart +++ b/packages/amplify_datastore/example/lib/models/HasOneChild.dart @@ -19,7 +19,7 @@ // ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:flutter/foundation.dart'; /// This is an auto generated class representing the HasOneChild type in your schema. @@ -34,9 +34,13 @@ class HasOneChild extends Model { @override getInstanceType() => classType; + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') @override - String getId() { - return id; + String getId() => id; + + HasOneChildModelIdentifier get modelIdentifier { + return HasOneChildModelIdentifier(id: id); } String? get name { @@ -91,8 +95,8 @@ class HasOneChild extends Model { return buffer.toString(); } - HasOneChild copyWith({String? id, String? name}) { - return HasOneChild._internal(id: id ?? this.id, name: name ?? this.name); + HasOneChild copyWith({String? name}) { + return HasOneChild._internal(id: id, name: name ?? this.name); } HasOneChild.fromJson(Map json) @@ -148,3 +152,37 @@ class _HasOneChildModelType extends ModelType { return HasOneChild.fromJson(jsonData); } } + +/// This is an auto generated class representing the model identifier +/// of [HasOneChild] in your schema. +@immutable +class HasOneChildModelIdentifier implements ModelIdentifier { + final String id; + + /// Create an instance of HasOneChildModelIdentifier using [id] the primary key. + const HasOneChildModelIdentifier({required this.id}); + + Map serializeAsMap() => ({'id': id}); + + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'HasOneChildModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is HasOneChildModelIdentifier && id == other.id; + } + + @override + int get hashCode => id.hashCode; +} diff --git a/packages/amplify_datastore/example/lib/models/HasOneParent.dart b/packages/amplify_datastore/example/lib/models/HasOneParent.dart index ecdf4bca17..c22ccaef23 100644 --- a/packages/amplify_datastore/example/lib/models/HasOneParent.dart +++ b/packages/amplify_datastore/example/lib/models/HasOneParent.dart @@ -20,7 +20,7 @@ // ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code import 'ModelProvider.dart'; -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:flutter/foundation.dart'; /// This is an auto generated class representing the HasOneParent type in your schema. @@ -39,9 +39,13 @@ class HasOneParent extends Model { @override getInstanceType() => classType; + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') @override - String getId() { - return id; + String getId() => id; + + HasOneParentModelIdentifier get modelIdentifier { + return HasOneParentModelIdentifier(id: id); } String? get name { @@ -146,14 +150,13 @@ class HasOneParent extends Model { } HasOneParent copyWith( - {String? id, - String? name, + {String? name, HasOneChild? implicitChild, String? explicitChildID, HasOneChild? explicitChild, String? hasOneParentImplicitChildId}) { return HasOneParent._internal( - id: id ?? this.id, + id: id, name: name ?? this.name, implicitChild: implicitChild ?? this.implicitChild, explicitChildID: explicitChildID ?? this.explicitChildID, @@ -263,3 +266,37 @@ class _HasOneParentModelType extends ModelType { return HasOneParent.fromJson(jsonData); } } + +/// This is an auto generated class representing the model identifier +/// of [HasOneParent] in your schema. +@immutable +class HasOneParentModelIdentifier implements ModelIdentifier { + final String id; + + /// Create an instance of HasOneParentModelIdentifier using [id] the primary key. + const HasOneParentModelIdentifier({required this.id}); + + Map serializeAsMap() => ({'id': id}); + + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'HasOneParentModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is HasOneParentModelIdentifier && id == other.id; + } + + @override + int get hashCode => id.hashCode; +} diff --git a/packages/amplify_datastore/example/lib/models/ModelProvider.dart b/packages/amplify_datastore/example/lib/models/ModelProvider.dart index c677a5e4ab..2fca2b1a2d 100644 --- a/packages/amplify_datastore/example/lib/models/ModelProvider.dart +++ b/packages/amplify_datastore/example/lib/models/ModelProvider.dart @@ -19,7 +19,7 @@ // ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'BelongsToChildExplicit.dart'; import 'BelongsToChildImplicit.dart'; import 'BelongsToParent.dart'; diff --git a/packages/amplify_datastore/example/lib/models/ModelWithAppsyncScalarTypes.dart b/packages/amplify_datastore/example/lib/models/ModelWithAppsyncScalarTypes.dart index 0176d75e54..e8b235fae4 100644 --- a/packages/amplify_datastore/example/lib/models/ModelWithAppsyncScalarTypes.dart +++ b/packages/amplify_datastore/example/lib/models/ModelWithAppsyncScalarTypes.dart @@ -19,7 +19,7 @@ // ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; @@ -62,9 +62,13 @@ class ModelWithAppsyncScalarTypes extends Model { @override getInstanceType() => classType; + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') @override - String getId() { - return id; + String getId() => id; + + ModelWithAppsyncScalarTypesModelIdentifier get modelIdentifier { + return ModelWithAppsyncScalarTypesModelIdentifier(id: id); } String? get stringValue { @@ -498,8 +502,7 @@ class ModelWithAppsyncScalarTypes extends Model { } ModelWithAppsyncScalarTypes copyWith( - {String? id, - String? stringValue, + {String? stringValue, String? altStringValue, List? listOfStringValue, int? intValue, @@ -528,7 +531,7 @@ class ModelWithAppsyncScalarTypes extends Model { String? awsIPAddressValue, List? listOfAWSIPAddressValue}) { return ModelWithAppsyncScalarTypes._internal( - id: id ?? this.id, + id: id, stringValue: stringValue ?? this.stringValue, altStringValue: altStringValue ?? this.altStringValue, listOfStringValue: listOfStringValue ?? this.listOfStringValue, @@ -903,3 +906,39 @@ class _ModelWithAppsyncScalarTypesModelType return ModelWithAppsyncScalarTypes.fromJson(jsonData); } } + +/// This is an auto generated class representing the model identifier +/// of [ModelWithAppsyncScalarTypes] in your schema. +@immutable +class ModelWithAppsyncScalarTypesModelIdentifier + implements ModelIdentifier { + final String id; + + /// Create an instance of ModelWithAppsyncScalarTypesModelIdentifier using [id] the primary key. + const ModelWithAppsyncScalarTypesModelIdentifier({required this.id}); + + Map serializeAsMap() => ({'id': id}); + + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'ModelWithAppsyncScalarTypesModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is ModelWithAppsyncScalarTypesModelIdentifier && + id == other.id; + } + + @override + int get hashCode => id.hashCode; +} diff --git a/packages/amplify_datastore/example/lib/models/ModelWithCustomType.dart b/packages/amplify_datastore/example/lib/models/ModelWithCustomType.dart index a99e690e30..f96ee8fa81 100644 --- a/packages/amplify_datastore/example/lib/models/ModelWithCustomType.dart +++ b/packages/amplify_datastore/example/lib/models/ModelWithCustomType.dart @@ -20,7 +20,7 @@ // ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code import 'ModelProvider.dart'; -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; @@ -37,9 +37,13 @@ class ModelWithCustomType extends Model { @override getInstanceType() => classType; + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') @override - String getId() { - return id; + String getId() => id; + + ModelWithCustomTypeModelIdentifier get modelIdentifier { + return ModelWithCustomTypeModelIdentifier(id: id); } CustomTypeWithAppsyncScalarTypes? get customTypeValue { @@ -124,11 +128,10 @@ class ModelWithCustomType extends Model { } ModelWithCustomType copyWith( - {String? id, - CustomTypeWithAppsyncScalarTypes? customTypeValue, + {CustomTypeWithAppsyncScalarTypes? customTypeValue, List? listOfCustomTypeValue}) { return ModelWithCustomType._internal( - id: id ?? this.id, + id: id, customTypeValue: customTypeValue ?? this.customTypeValue, listOfCustomTypeValue: listOfCustomTypeValue ?? this.listOfCustomTypeValue); @@ -212,3 +215,38 @@ class _ModelWithCustomTypeModelType extends ModelType { return ModelWithCustomType.fromJson(jsonData); } } + +/// This is an auto generated class representing the model identifier +/// of [ModelWithCustomType] in your schema. +@immutable +class ModelWithCustomTypeModelIdentifier + implements ModelIdentifier { + final String id; + + /// Create an instance of ModelWithCustomTypeModelIdentifier using [id] the primary key. + const ModelWithCustomTypeModelIdentifier({required this.id}); + + Map serializeAsMap() => ({'id': id}); + + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'ModelWithCustomTypeModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is ModelWithCustomTypeModelIdentifier && id == other.id; + } + + @override + int get hashCode => id.hashCode; +} diff --git a/packages/amplify_datastore/example/lib/models/ModelWithEnum.dart b/packages/amplify_datastore/example/lib/models/ModelWithEnum.dart index 7e2d5676f6..20cefc1e52 100644 --- a/packages/amplify_datastore/example/lib/models/ModelWithEnum.dart +++ b/packages/amplify_datastore/example/lib/models/ModelWithEnum.dart @@ -20,7 +20,7 @@ // ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code import 'ModelProvider.dart'; -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; @@ -37,9 +37,13 @@ class ModelWithEnum extends Model { @override getInstanceType() => classType; + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') @override - String getId() { - return id; + String getId() => id; + + ModelWithEnumModelIdentifier get modelIdentifier { + return ModelWithEnumModelIdentifier(id: id); } EnumField? get enumField { @@ -117,9 +121,9 @@ class ModelWithEnum extends Model { } ModelWithEnum copyWith( - {String? id, EnumField? enumField, List? listOfEnumField}) { + {EnumField? enumField, List? listOfEnumField}) { return ModelWithEnum._internal( - id: id ?? this.id, + id: id, enumField: enumField ?? this.enumField, listOfEnumField: listOfEnumField ?? this.listOfEnumField); } @@ -194,3 +198,37 @@ class _ModelWithEnumModelType extends ModelType { return ModelWithEnum.fromJson(jsonData); } } + +/// This is an auto generated class representing the model identifier +/// of [ModelWithEnum] in your schema. +@immutable +class ModelWithEnumModelIdentifier implements ModelIdentifier { + final String id; + + /// Create an instance of ModelWithEnumModelIdentifier using [id] the primary key. + const ModelWithEnumModelIdentifier({required this.id}); + + Map serializeAsMap() => ({'id': id}); + + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'ModelWithEnumModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is ModelWithEnumModelIdentifier && id == other.id; + } + + @override + int get hashCode => id.hashCode; +} diff --git a/packages/amplify_datastore/example/lib/models/MultiRelatedAttendee.dart b/packages/amplify_datastore/example/lib/models/MultiRelatedAttendee.dart index edb832aa45..f91be857fd 100644 --- a/packages/amplify_datastore/example/lib/models/MultiRelatedAttendee.dart +++ b/packages/amplify_datastore/example/lib/models/MultiRelatedAttendee.dart @@ -20,7 +20,7 @@ // ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code import 'ModelProvider.dart'; -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; @@ -36,9 +36,13 @@ class MultiRelatedAttendee extends Model { @override getInstanceType() => classType; + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') @override - String getId() { - return id; + String getId() => id; + + MultiRelatedAttendeeModelIdentifier get modelIdentifier { + return MultiRelatedAttendeeModelIdentifier(id: id); } List? get meetings { @@ -99,10 +103,9 @@ class MultiRelatedAttendee extends Model { return buffer.toString(); } - MultiRelatedAttendee copyWith( - {String? id, List? meetings}) { + MultiRelatedAttendee copyWith({List? meetings}) { return MultiRelatedAttendee._internal( - id: id ?? this.id, meetings: meetings ?? this.meetings); + id: id, meetings: meetings ?? this.meetings); } MultiRelatedAttendee.fromJson(Map json) @@ -140,6 +143,10 @@ class MultiRelatedAttendee extends Model { modelSchemaDefinition.name = "MultiRelatedAttendee"; modelSchemaDefinition.pluralName = "MultiRelatedAttendees"; + modelSchemaDefinition.indexes = [ + ModelIndex(fields: const ["id"], name: null) + ]; + modelSchemaDefinition.addField(ModelFieldDefinition.id()); modelSchemaDefinition.addField(ModelFieldDefinition.hasMany( @@ -170,3 +177,38 @@ class _MultiRelatedAttendeeModelType extends ModelType { return MultiRelatedAttendee.fromJson(jsonData); } } + +/// This is an auto generated class representing the model identifier +/// of [MultiRelatedAttendee] in your schema. +@immutable +class MultiRelatedAttendeeModelIdentifier + implements ModelIdentifier { + final String id; + + /// Create an instance of MultiRelatedAttendeeModelIdentifier using [id] the primary key. + const MultiRelatedAttendeeModelIdentifier({required this.id}); + + Map serializeAsMap() => ({'id': id}); + + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'MultiRelatedAttendeeModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is MultiRelatedAttendeeModelIdentifier && id == other.id; + } + + @override + int get hashCode => id.hashCode; +} diff --git a/packages/amplify_datastore/example/lib/models/MultiRelatedMeeting.dart b/packages/amplify_datastore/example/lib/models/MultiRelatedMeeting.dart index 96ad6b1355..651b31af66 100644 --- a/packages/amplify_datastore/example/lib/models/MultiRelatedMeeting.dart +++ b/packages/amplify_datastore/example/lib/models/MultiRelatedMeeting.dart @@ -20,7 +20,7 @@ // ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code import 'ModelProvider.dart'; -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; @@ -37,19 +37,23 @@ class MultiRelatedMeeting extends Model { @override getInstanceType() => classType; + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') @override - String getId() { - return id; + String getId() => id; + + MultiRelatedMeetingModelIdentifier get modelIdentifier { + return MultiRelatedMeetingModelIdentifier(id: id); } String get title { try { return _title!; } catch (e) { - throw DataStoreException( - DataStoreExceptionMessages + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages + recoverySuggestion: AmplifyExceptionMessages .codeGenRequiredFieldForceCastRecoverySuggestion, underlyingException: e.toString()); } @@ -120,9 +124,9 @@ class MultiRelatedMeeting extends Model { } MultiRelatedMeeting copyWith( - {String? id, String? title, List? attendees}) { + {String? title, List? attendees}) { return MultiRelatedMeeting._internal( - id: id ?? this.id, + id: id, title: title ?? this.title, attendees: attendees ?? this.attendees); } @@ -165,6 +169,10 @@ class MultiRelatedMeeting extends Model { modelSchemaDefinition.name = "MultiRelatedMeeting"; modelSchemaDefinition.pluralName = "MultiRelatedMeetings"; + modelSchemaDefinition.indexes = [ + ModelIndex(fields: const ["id"], name: null) + ]; + modelSchemaDefinition.addField(ModelFieldDefinition.id()); modelSchemaDefinition.addField(ModelFieldDefinition.field( @@ -200,3 +208,38 @@ class _MultiRelatedMeetingModelType extends ModelType { return MultiRelatedMeeting.fromJson(jsonData); } } + +/// This is an auto generated class representing the model identifier +/// of [MultiRelatedMeeting] in your schema. +@immutable +class MultiRelatedMeetingModelIdentifier + implements ModelIdentifier { + final String id; + + /// Create an instance of MultiRelatedMeetingModelIdentifier using [id] the primary key. + const MultiRelatedMeetingModelIdentifier({required this.id}); + + Map serializeAsMap() => ({'id': id}); + + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'MultiRelatedMeetingModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is MultiRelatedMeetingModelIdentifier && id == other.id; + } + + @override + int get hashCode => id.hashCode; +} diff --git a/packages/amplify_datastore/example/lib/models/MultiRelatedRegistration.dart b/packages/amplify_datastore/example/lib/models/MultiRelatedRegistration.dart index 96404606ad..7eb0e76b91 100644 --- a/packages/amplify_datastore/example/lib/models/MultiRelatedRegistration.dart +++ b/packages/amplify_datastore/example/lib/models/MultiRelatedRegistration.dart @@ -20,7 +20,7 @@ // ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code import 'ModelProvider.dart'; -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:flutter/foundation.dart'; /// This is an auto generated class representing the MultiRelatedRegistration type in your schema. @@ -36,19 +36,23 @@ class MultiRelatedRegistration extends Model { @override getInstanceType() => classType; + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') @override - String getId() { - return id; + String getId() => id; + + MultiRelatedRegistrationModelIdentifier get modelIdentifier { + return MultiRelatedRegistrationModelIdentifier(id: id); } MultiRelatedMeeting get meeting { try { return _meeting!; } catch (e) { - throw DataStoreException( - DataStoreExceptionMessages + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages + recoverySuggestion: AmplifyExceptionMessages .codeGenRequiredFieldForceCastRecoverySuggestion, underlyingException: e.toString()); } @@ -58,10 +62,10 @@ class MultiRelatedRegistration extends Model { try { return _attendee!; } catch (e) { - throw DataStoreException( - DataStoreExceptionMessages + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages + recoverySuggestion: AmplifyExceptionMessages .codeGenRequiredFieldForceCastRecoverySuggestion, underlyingException: e.toString()); } @@ -134,11 +138,9 @@ class MultiRelatedRegistration extends Model { } MultiRelatedRegistration copyWith( - {String? id, - MultiRelatedMeeting? meeting, - MultiRelatedAttendee? attendee}) { + {MultiRelatedMeeting? meeting, MultiRelatedAttendee? attendee}) { return MultiRelatedRegistration._internal( - id: id ?? this.id, + id: id, meeting: meeting ?? this.meeting, attendee: attendee ?? this.attendee); } @@ -183,6 +185,12 @@ class MultiRelatedRegistration extends Model { modelSchemaDefinition.name = "MultiRelatedRegistration"; modelSchemaDefinition.pluralName = "MultiRelatedRegistrations"; + modelSchemaDefinition.indexes = [ + ModelIndex(fields: const ["id"], name: null), + ModelIndex(fields: const ["meetingId", "attendeeId"], name: "byMeeting"), + ModelIndex(fields: const ["attendeeId", "meetingId"], name: "byAttendee") + ]; + modelSchemaDefinition.addField(ModelFieldDefinition.id()); modelSchemaDefinition.addField(ModelFieldDefinition.belongsTo( @@ -220,3 +228,38 @@ class _MultiRelatedRegistrationModelType return MultiRelatedRegistration.fromJson(jsonData); } } + +/// This is an auto generated class representing the model identifier +/// of [MultiRelatedRegistration] in your schema. +@immutable +class MultiRelatedRegistrationModelIdentifier + implements ModelIdentifier { + final String id; + + /// Create an instance of MultiRelatedRegistrationModelIdentifier using [id] the primary key. + const MultiRelatedRegistrationModelIdentifier({required this.id}); + + Map serializeAsMap() => ({'id': id}); + + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'MultiRelatedRegistrationModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is MultiRelatedRegistrationModelIdentifier && id == other.id; + } + + @override + int get hashCode => id.hashCode; +} diff --git a/packages/amplify_datastore/example/lib/models/Post.dart b/packages/amplify_datastore/example/lib/models/Post.dart index fc3056a193..ea934add95 100644 --- a/packages/amplify_datastore/example/lib/models/Post.dart +++ b/packages/amplify_datastore/example/lib/models/Post.dart @@ -20,7 +20,7 @@ // ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code import 'ModelProvider.dart'; -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; @@ -41,19 +41,23 @@ class Post extends Model { @override getInstanceType() => classType; + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') @override - String getId() { - return id; + String getId() => id; + + PostModelIdentifier get modelIdentifier { + return PostModelIdentifier(id: id); } String get title { try { return _title!; } catch (e) { - throw DataStoreException( - DataStoreExceptionMessages + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages + recoverySuggestion: AmplifyExceptionMessages .codeGenRequiredFieldForceCastRecoverySuggestion, underlyingException: e.toString()); } @@ -63,10 +67,10 @@ class Post extends Model { try { return _rating!; } catch (e) { - throw DataStoreException( - DataStoreExceptionMessages + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages + recoverySuggestion: AmplifyExceptionMessages .codeGenRequiredFieldForceCastRecoverySuggestion, underlyingException: e.toString()); } @@ -177,15 +181,14 @@ class Post extends Model { } Post copyWith( - {String? id, - String? title, + {String? title, int? rating, TemporalDateTime? created, Blog? blog, List? comments, List? tags}) { return Post._internal( - id: id ?? this.id, + id: id, title: title ?? this.title, rating: rating ?? this.rating, created: created ?? this.created, @@ -259,6 +262,10 @@ class Post extends Model { modelSchemaDefinition.name = "Post"; modelSchemaDefinition.pluralName = "Posts"; + modelSchemaDefinition.indexes = [ + ModelIndex(fields: const ["blogID"], name: "byBlog") + ]; + modelSchemaDefinition.addField(ModelFieldDefinition.id()); modelSchemaDefinition.addField(ModelFieldDefinition.field( @@ -316,3 +323,37 @@ class _PostModelType extends ModelType { return Post.fromJson(jsonData); } } + +/// This is an auto generated class representing the model identifier +/// of [Post] in your schema. +@immutable +class PostModelIdentifier implements ModelIdentifier { + final String id; + + /// Create an instance of PostModelIdentifier using [id] the primary key. + const PostModelIdentifier({required this.id}); + + Map serializeAsMap() => ({'id': id}); + + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'PostModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is PostModelIdentifier && id == other.id; + } + + @override + int get hashCode => id.hashCode; +} diff --git a/packages/amplify_datastore/example/lib/models/PostTags.dart b/packages/amplify_datastore/example/lib/models/PostTags.dart index 1a55812c5f..47a2618f32 100644 --- a/packages/amplify_datastore/example/lib/models/PostTags.dart +++ b/packages/amplify_datastore/example/lib/models/PostTags.dart @@ -20,7 +20,7 @@ // ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code import 'ModelProvider.dart'; -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:flutter/foundation.dart'; /// This is an auto generated class representing the PostTags type in your schema. @@ -36,19 +36,23 @@ class PostTags extends Model { @override getInstanceType() => classType; + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') @override - String getId() { - return id; + String getId() => id; + + PostTagsModelIdentifier get modelIdentifier { + return PostTagsModelIdentifier(id: id); } Post get post { try { return _post!; } catch (e) { - throw DataStoreException( - DataStoreExceptionMessages + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages + recoverySuggestion: AmplifyExceptionMessages .codeGenRequiredFieldForceCastRecoverySuggestion, underlyingException: e.toString()); } @@ -58,10 +62,10 @@ class PostTags extends Model { try { return _tag!; } catch (e) { - throw DataStoreException( - DataStoreExceptionMessages + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages + recoverySuggestion: AmplifyExceptionMessages .codeGenRequiredFieldForceCastRecoverySuggestion, underlyingException: e.toString()); } @@ -121,9 +125,9 @@ class PostTags extends Model { return buffer.toString(); } - PostTags copyWith({String? id, Post? post, Tag? tag}) { + PostTags copyWith({Post? post, Tag? tag}) { return PostTags._internal( - id: id ?? this.id, post: post ?? this.post, tag: tag ?? this.tag); + id: id, post: post ?? this.post, tag: tag ?? this.tag); } PostTags.fromJson(Map json) @@ -201,3 +205,37 @@ class _PostTagsModelType extends ModelType { return PostTags.fromJson(jsonData); } } + +/// This is an auto generated class representing the model identifier +/// of [PostTags] in your schema. +@immutable +class PostTagsModelIdentifier implements ModelIdentifier { + final String id; + + /// Create an instance of PostTagsModelIdentifier using [id] the primary key. + const PostTagsModelIdentifier({required this.id}); + + Map serializeAsMap() => ({'id': id}); + + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'PostTagsModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is PostTagsModelIdentifier && id == other.id; + } + + @override + int get hashCode => id.hashCode; +} diff --git a/packages/amplify_datastore/example/lib/models/SimpleCustomType.dart b/packages/amplify_datastore/example/lib/models/SimpleCustomType.dart index e3b0f5d8a6..beb8ca2570 100644 --- a/packages/amplify_datastore/example/lib/models/SimpleCustomType.dart +++ b/packages/amplify_datastore/example/lib/models/SimpleCustomType.dart @@ -19,7 +19,7 @@ // ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:flutter/foundation.dart'; /// This is an auto generated class representing the SimpleCustomType type in your schema. @@ -31,10 +31,10 @@ class SimpleCustomType { try { return _foo!; } catch (e) { - throw DataStoreException( - DataStoreExceptionMessages + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages + recoverySuggestion: AmplifyExceptionMessages .codeGenRequiredFieldForceCastRecoverySuggestion, underlyingException: e.toString()); } diff --git a/packages/amplify_datastore/example/lib/models/Tag.dart b/packages/amplify_datastore/example/lib/models/Tag.dart index 305e1670af..d320f35bb8 100644 --- a/packages/amplify_datastore/example/lib/models/Tag.dart +++ b/packages/amplify_datastore/example/lib/models/Tag.dart @@ -20,7 +20,7 @@ // ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code import 'ModelProvider.dart'; -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; @@ -37,19 +37,23 @@ class Tag extends Model { @override getInstanceType() => classType; + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') @override - String getId() { - return id; + String getId() => id; + + TagModelIdentifier get modelIdentifier { + return TagModelIdentifier(id: id); } String get label { try { return _label!; } catch (e) { - throw DataStoreException( - DataStoreExceptionMessages + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages + recoverySuggestion: AmplifyExceptionMessages .codeGenRequiredFieldForceCastRecoverySuggestion, underlyingException: e.toString()); } @@ -114,11 +118,9 @@ class Tag extends Model { return buffer.toString(); } - Tag copyWith({String? id, String? label, List? posts}) { + Tag copyWith({String? label, List? posts}) { return Tag._internal( - id: id ?? this.id, - label: label ?? this.label, - posts: posts ?? this.posts); + id: id, label: label ?? this.label, posts: posts ?? this.posts); } Tag.fromJson(Map json) @@ -192,3 +194,37 @@ class _TagModelType extends ModelType { return Tag.fromJson(jsonData); } } + +/// This is an auto generated class representing the model identifier +/// of [Tag] in your schema. +@immutable +class TagModelIdentifier implements ModelIdentifier { + final String id; + + /// Create an instance of TagModelIdentifier using [id] the primary key. + const TagModelIdentifier({required this.id}); + + Map serializeAsMap() => ({'id': id}); + + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'TagModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is TagModelIdentifier && id == other.id; + } + + @override + int get hashCode => id.hashCode; +} diff --git a/packages/amplify_datastore/test/amplify_datastore_clear_test.dart b/packages/amplify_datastore/test/amplify_datastore_clear_test.dart index 5832e6cde8..1bf398849e 100644 --- a/packages/amplify_datastore/test/amplify_datastore_clear_test.dart +++ b/packages/amplify_datastore/test/amplify_datastore_clear_test.dart @@ -17,7 +17,7 @@ import 'package:amplify_core/amplify_core.dart'; import 'package:amplify_datastore/amplify_datastore.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'test_models/ModelProvider.dart'; +import 'package:amplify_test/test_models/ModelProvider.dart'; void main() { const MethodChannel dataStoreChannel = diff --git a/packages/amplify_datastore/test/amplify_datastore_custom_error_handler_test.dart b/packages/amplify_datastore/test/amplify_datastore_custom_error_handler_test.dart index 03a6985822..562ef2f030 100644 --- a/packages/amplify_datastore/test/amplify_datastore_custom_error_handler_test.dart +++ b/packages/amplify_datastore/test/amplify_datastore_custom_error_handler_test.dart @@ -17,7 +17,7 @@ import 'package:amplify_core/amplify_core.dart'; import 'package:amplify_datastore/amplify_datastore.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'test_models/ModelProvider.dart'; +import 'package:amplify_test/test_models/ModelProvider.dart'; // Utilized from: https://github.com/flutter/flutter/issues/63465 #CyrilHu // For mocking Native -> Dart diff --git a/packages/amplify_datastore/test/amplify_datastore_delete_test.dart b/packages/amplify_datastore/test/amplify_datastore_delete_test.dart index eb63e80515..a2835e0c6f 100644 --- a/packages/amplify_datastore/test/amplify_datastore_delete_test.dart +++ b/packages/amplify_datastore/test/amplify_datastore_delete_test.dart @@ -17,7 +17,7 @@ import 'package:amplify_datastore/amplify_datastore.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:amplify_test/amplify_test.dart'; -import 'test_models/ModelProvider.dart'; +import 'package:amplify_test/test_models/ModelProvider.dart'; void main() { const MethodChannel dataStoreChannel = diff --git a/packages/amplify_datastore/test/amplify_datastore_observe_test.dart b/packages/amplify_datastore/test/amplify_datastore_observe_test.dart index bdd2e2a832..71e6f93902 100644 --- a/packages/amplify_datastore/test/amplify_datastore_observe_test.dart +++ b/packages/amplify_datastore/test/amplify_datastore_observe_test.dart @@ -17,7 +17,7 @@ import 'package:amplify_datastore/amplify_datastore.dart'; import 'package:amplify_test/amplify_test.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'test_models/ModelProvider.dart'; +import 'package:amplify_test/test_models/ModelProvider.dart'; void main() { const MethodChannel dataStoreChannel = diff --git a/packages/amplify_datastore/test/amplify_datastore_query_test.dart b/packages/amplify_datastore/test/amplify_datastore_query_test.dart index 87519f5a77..44f3f45710 100644 --- a/packages/amplify_datastore/test/amplify_datastore_query_test.dart +++ b/packages/amplify_datastore/test/amplify_datastore_query_test.dart @@ -18,7 +18,7 @@ import 'package:amplify_datastore/amplify_datastore.dart'; import 'package:amplify_test/amplify_test.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'test_models/ModelProvider.dart'; +import 'package:amplify_test/test_models/ModelProvider.dart'; void main() { const MethodChannel dataStoreChannel = diff --git a/packages/amplify_datastore/test/amplify_datastore_save_test.dart b/packages/amplify_datastore/test/amplify_datastore_save_test.dart index 81f9d73ce5..3cc4f26ed9 100644 --- a/packages/amplify_datastore/test/amplify_datastore_save_test.dart +++ b/packages/amplify_datastore/test/amplify_datastore_save_test.dart @@ -17,7 +17,7 @@ import 'package:amplify_datastore/amplify_datastore.dart'; import 'package:amplify_test/amplify_test.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'test_models/ModelProvider.dart'; +import 'package:amplify_test/test_models/ModelProvider.dart'; void main() { const MethodChannel dataStoreChannel = diff --git a/packages/amplify_datastore/test/amplify_datastore_stream_controller_test.dart b/packages/amplify_datastore/test/amplify_datastore_stream_controller_test.dart index 86db4816db..0f45297a31 100644 --- a/packages/amplify_datastore/test/amplify_datastore_stream_controller_test.dart +++ b/packages/amplify_datastore/test/amplify_datastore_stream_controller_test.dart @@ -21,7 +21,7 @@ import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_inte import 'package:amplify_test/amplify_test.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'test_models/ModelProvider.dart'; +import 'package:amplify_test/test_models/ModelProvider.dart'; void main() { const MethodChannel datastoreChannel = diff --git a/packages/amplify_datastore/test/amplify_datastore_test.dart b/packages/amplify_datastore/test/amplify_datastore_test.dart index 913791a133..d9c742fc33 100644 --- a/packages/amplify_datastore/test/amplify_datastore_test.dart +++ b/packages/amplify_datastore/test/amplify_datastore_test.dart @@ -17,7 +17,7 @@ import 'package:amplify_datastore/amplify_datastore.dart'; import 'package:amplify_test/amplify_test.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/services.dart'; -import 'test_models/ModelProvider.dart'; +import 'package:amplify_test/test_models/ModelProvider.dart'; void main() { const mockSyncInterval = 3600; diff --git a/packages/amplify_datastore/test/observe_query_executor_test.dart b/packages/amplify_datastore/test/observe_query_executor_test.dart index e516eeed22..78a7e2b61b 100644 --- a/packages/amplify_datastore/test/observe_query_executor_test.dart +++ b/packages/amplify_datastore/test/observe_query_executor_test.dart @@ -18,7 +18,7 @@ import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_inte import 'package:flutter_test/flutter_test.dart'; import 'package:fake_async/fake_async.dart'; import '../lib/types/observe_query_executor.dart'; -import './test_models/Blog.dart'; +import 'package:amplify_test/test_models/ModelProvider.dart'; var syncQueriesStartedEvent = DataStoreHubEvent( 'syncQueriesStarted', diff --git a/packages/amplify_datastore/test/outbox_mutation_event_test.dart b/packages/amplify_datastore/test/outbox_mutation_event_test.dart index 7852c8aacc..546f914e59 100644 --- a/packages/amplify_datastore/test/outbox_mutation_event_test.dart +++ b/packages/amplify_datastore/test/outbox_mutation_event_test.dart @@ -17,7 +17,7 @@ import 'package:amplify_datastore/amplify_datastore.dart'; import 'package:amplify_test/amplify_test.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'test_models/ModelProvider.dart'; +import 'package:amplify_test/test_models/ModelProvider.dart'; void main() async { var modelProvider = ModelProvider(); diff --git a/packages/amplify_datastore/test/query_predicate_test.dart b/packages/amplify_datastore/test/query_predicate_test.dart index 0f16e3e032..2f9a097c4b 100644 --- a/packages/amplify_datastore/test/query_predicate_test.dart +++ b/packages/amplify_datastore/test/query_predicate_test.dart @@ -19,7 +19,7 @@ import 'dart:io'; import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'test_models/ModelProvider.dart'; +import 'package:amplify_test/test_models/ModelProvider.dart'; void main() { TestWidgetsFlutterBinding.ensureInitialized(); diff --git a/packages/amplify_datastore/test/query_sort_test.dart b/packages/amplify_datastore/test/query_sort_test.dart index 2b3ce9c3b4..e3c43d31fe 100644 --- a/packages/amplify_datastore/test/query_sort_test.dart +++ b/packages/amplify_datastore/test/query_sort_test.dart @@ -19,7 +19,7 @@ import 'dart:io'; import 'package:amplify_datastore/amplify_datastore.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'test_models/ModelProvider.dart'; +import 'package:amplify_test/test_models/ModelProvider.dart'; void main() { TestWidgetsFlutterBinding.ensureInitialized(); diff --git a/packages/amplify_datastore/test/test_models/Blog.dart b/packages/amplify_datastore/test/test_models/Blog.dart deleted file mode 100644 index a94270157e..0000000000 --- a/packages/amplify_datastore/test/test_models/Blog.dart +++ /dev/null @@ -1,192 +0,0 @@ -/* -* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. -* -* Licensed under the Apache License, Version 2.0 (the "License"). -* You may not use this file except in compliance with the License. -* A copy of the License is located at -* -* http://aws.amazon.com/apache2.0 -* -* or in the "license" file accompanying this file. This file is distributed -* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either -* express or implied. See the License for the specific language governing -* permissions and limitations under the License. -*/ - -// NOTE: This file is generated and may not follow lint rules defined in your app -// Generated files can be excluded from analysis in analysis_options.yaml -// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis - -// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code - -import 'ModelProvider.dart'; -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; -import 'package:collection/collection.dart'; -import 'package:flutter/foundation.dart'; - -/** This is an auto generated class representing the Blog type in your schema. */ -@immutable -class Blog extends Model { - static const classType = const _BlogModelType(); - final String id; - final String? _name; - final List? _posts; - final TemporalDateTime? _createdAt; - final TemporalDateTime? _updatedAt; - - @override - getInstanceType() => classType; - - @override - String getId() { - return id; - } - - String get name { - try { - return _name!; - } catch (e) { - throw new DataStoreException( - DataStoreExceptionMessages - .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages - .codeGenRequiredFieldForceCastRecoverySuggestion, - underlyingException: e.toString()); - } - } - - List? get posts { - return _posts; - } - - TemporalDateTime? get createdAt { - return _createdAt; - } - - TemporalDateTime? get updatedAt { - return _updatedAt; - } - - const Blog._internal( - {required this.id, required name, posts, createdAt, updatedAt}) - : _name = name, - _posts = posts, - _createdAt = createdAt, - _updatedAt = updatedAt; - - factory Blog({String? id, required String name, List? posts}) { - return Blog._internal( - id: id == null ? UUID.getUUID() : id, - name: name, - posts: posts != null ? List.unmodifiable(posts) : posts); - } - - bool equals(Object other) { - return this == other; - } - - @override - bool operator ==(Object other) { - if (identical(other, this)) return true; - return other is Blog && - id == other.id && - _name == other._name && - DeepCollectionEquality().equals(_posts, other._posts); - } - - @override - int get hashCode => toString().hashCode; - - @override - String toString() { - var buffer = new StringBuffer(); - - buffer.write("Blog {"); - buffer.write("id=" + "$id" + ", "); - buffer.write("name=" + "$_name" + ", "); - buffer.write("createdAt=" + - (_createdAt != null ? _createdAt!.format() : "null") + - ", "); - buffer.write( - "updatedAt=" + (_updatedAt != null ? _updatedAt!.format() : "null")); - buffer.write("}"); - - return buffer.toString(); - } - - Blog copyWith({String? id, String? name, List? posts}) { - return Blog._internal( - id: id ?? this.id, name: name ?? this.name, posts: posts ?? this.posts); - } - - Blog.fromJson(Map json) - : id = json['id'], - _name = json['name'], - _posts = json['posts'] is List - ? (json['posts'] as List) - .where((e) => e?['serializedData'] != null) - .map((e) => Post.fromJson( - new Map.from(e['serializedData']))) - .toList() - : null, - _createdAt = json['createdAt'] != null - ? TemporalDateTime.fromString(json['createdAt']) - : null, - _updatedAt = json['updatedAt'] != null - ? TemporalDateTime.fromString(json['updatedAt']) - : null; - - Map toJson() => { - 'id': id, - 'name': _name, - 'posts': _posts?.map((Post? e) => e?.toJson()).toList(), - 'createdAt': _createdAt?.format(), - 'updatedAt': _updatedAt?.format() - }; - - static final QueryField ID = QueryField(fieldName: "blog.id"); - static final QueryField NAME = QueryField(fieldName: "name"); - static final QueryField POSTS = QueryField( - fieldName: "posts", - fieldType: ModelFieldType(ModelFieldTypeEnum.model, - ofModelName: (Post).toString())); - static var schema = - Model.defineSchema(define: (ModelSchemaDefinition modelSchemaDefinition) { - modelSchemaDefinition.name = "Blog"; - modelSchemaDefinition.pluralName = "Blogs"; - - modelSchemaDefinition.addField(ModelFieldDefinition.id()); - - modelSchemaDefinition.addField(ModelFieldDefinition.field( - key: Blog.NAME, - isRequired: true, - ofType: ModelFieldType(ModelFieldTypeEnum.string))); - - modelSchemaDefinition.addField(ModelFieldDefinition.hasMany( - key: Blog.POSTS, - isRequired: false, - ofModelName: (Post).toString(), - associatedKey: Post.BLOG)); - - modelSchemaDefinition.addField(ModelFieldDefinition.nonQueryField( - fieldName: 'createdAt', - isRequired: false, - isReadOnly: true, - ofType: ModelFieldType(ModelFieldTypeEnum.dateTime))); - - modelSchemaDefinition.addField(ModelFieldDefinition.nonQueryField( - fieldName: 'updatedAt', - isRequired: false, - isReadOnly: true, - ofType: ModelFieldType(ModelFieldTypeEnum.dateTime))); - }); -} - -class _BlogModelType extends ModelType { - const _BlogModelType(); - - @override - Blog fromJson(Map jsonData) { - return Blog.fromJson(jsonData); - } -} diff --git a/packages/amplify_datastore/test/test_models/Comment.dart b/packages/amplify_datastore/test/test_models/Comment.dart deleted file mode 100644 index cb89852f96..0000000000 --- a/packages/amplify_datastore/test/test_models/Comment.dart +++ /dev/null @@ -1,189 +0,0 @@ -/* -* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. -* -* Licensed under the Apache License, Version 2.0 (the "License"). -* You may not use this file except in compliance with the License. -* A copy of the License is located at -* -* http://aws.amazon.com/apache2.0 -* -* or in the "license" file accompanying this file. This file is distributed -* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either -* express or implied. See the License for the specific language governing -* permissions and limitations under the License. -*/ - -// NOTE: This file is generated and may not follow lint rules defined in your app -// Generated files can be excluded from analysis in analysis_options.yaml -// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis - -// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code - -import 'ModelProvider.dart'; -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; -import 'package:flutter/foundation.dart'; - -/** This is an auto generated class representing the Comment type in your schema. */ -@immutable -class Comment extends Model { - static const classType = const _CommentModelType(); - final String id; - final Post? _post; - final String? _content; - final TemporalDateTime? _createdAt; - final TemporalDateTime? _updatedAt; - - @override - getInstanceType() => classType; - - @override - String getId() { - return id; - } - - Post? get post { - return _post; - } - - String get content { - try { - return _content!; - } catch (e) { - throw new DataStoreException( - DataStoreExceptionMessages - .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages - .codeGenRequiredFieldForceCastRecoverySuggestion, - underlyingException: e.toString()); - } - } - - TemporalDateTime? get createdAt { - return _createdAt; - } - - TemporalDateTime? get updatedAt { - return _updatedAt; - } - - const Comment._internal( - {required this.id, post, required content, createdAt, updatedAt}) - : _post = post, - _content = content, - _createdAt = createdAt, - _updatedAt = updatedAt; - - factory Comment({String? id, Post? post, required String content}) { - return Comment._internal( - id: id == null ? UUID.getUUID() : id, post: post, content: content); - } - - bool equals(Object other) { - return this == other; - } - - @override - bool operator ==(Object other) { - if (identical(other, this)) return true; - return other is Comment && - id == other.id && - _post == other._post && - _content == other._content; - } - - @override - int get hashCode => toString().hashCode; - - @override - String toString() { - var buffer = new StringBuffer(); - - buffer.write("Comment {"); - buffer.write("id=" + "$id" + ", "); - buffer.write("post=" + (_post != null ? _post!.toString() : "null") + ", "); - buffer.write("content=" + "$_content" + ", "); - buffer.write("createdAt=" + - (_createdAt != null ? _createdAt!.format() : "null") + - ", "); - buffer.write( - "updatedAt=" + (_updatedAt != null ? _updatedAt!.format() : "null")); - buffer.write("}"); - - return buffer.toString(); - } - - Comment copyWith({String? id, Post? post, String? content}) { - return Comment._internal( - id: id ?? this.id, - post: post ?? this.post, - content: content ?? this.content); - } - - Comment.fromJson(Map json) - : id = json['id'], - _post = json['post']?['serializedData'] != null - ? Post.fromJson( - new Map.from(json['post']['serializedData'])) - : null, - _content = json['content'], - _createdAt = json['createdAt'] != null - ? TemporalDateTime.fromString(json['createdAt']) - : null, - _updatedAt = json['updatedAt'] != null - ? TemporalDateTime.fromString(json['updatedAt']) - : null; - - Map toJson() => { - 'id': id, - 'post': _post?.toJson(), - 'content': _content, - 'createdAt': _createdAt?.format(), - 'updatedAt': _updatedAt?.format() - }; - - static final QueryField ID = QueryField(fieldName: "comment.id"); - static final QueryField POST = QueryField( - fieldName: "post", - fieldType: ModelFieldType(ModelFieldTypeEnum.model, - ofModelName: (Post).toString())); - static final QueryField CONTENT = QueryField(fieldName: "content"); - static var schema = - Model.defineSchema(define: (ModelSchemaDefinition modelSchemaDefinition) { - modelSchemaDefinition.name = "Comment"; - modelSchemaDefinition.pluralName = "Comments"; - - modelSchemaDefinition.addField(ModelFieldDefinition.id()); - - modelSchemaDefinition.addField(ModelFieldDefinition.belongsTo( - key: Comment.POST, - isRequired: false, - targetName: "postID", - ofModelName: (Post).toString())); - - modelSchemaDefinition.addField(ModelFieldDefinition.field( - key: Comment.CONTENT, - isRequired: true, - ofType: ModelFieldType(ModelFieldTypeEnum.string))); - - modelSchemaDefinition.addField(ModelFieldDefinition.nonQueryField( - fieldName: 'createdAt', - isRequired: false, - isReadOnly: true, - ofType: ModelFieldType(ModelFieldTypeEnum.dateTime))); - - modelSchemaDefinition.addField(ModelFieldDefinition.nonQueryField( - fieldName: 'updatedAt', - isRequired: false, - isReadOnly: true, - ofType: ModelFieldType(ModelFieldTypeEnum.dateTime))); - }); -} - -class _CommentModelType extends ModelType { - const _CommentModelType(); - - @override - Comment fromJson(Map jsonData) { - return Comment.fromJson(jsonData); - } -} diff --git a/packages/amplify_datastore/test/test_models/ModelProvider.dart b/packages/amplify_datastore/test/test_models/ModelProvider.dart deleted file mode 100644 index fdf0333744..0000000000 --- a/packages/amplify_datastore/test/test_models/ModelProvider.dart +++ /dev/null @@ -1,65 +0,0 @@ -/* -* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. -* -* Licensed under the Apache License, Version 2.0 (the "License"). -* You may not use this file except in compliance with the License. -* A copy of the License is located at -* -* http://aws.amazon.com/apache2.0 -* -* or in the "license" file accompanying this file. This file is distributed -* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either -* express or implied. See the License for the specific language governing -* permissions and limitations under the License. -*/ - -// NOTE: This file is generated and may not follow lint rules defined in your app -// Generated files can be excluded from analysis in analysis_options.yaml -// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis - -// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code - -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; -import 'Blog.dart'; -import 'Comment.dart'; -import 'Post.dart'; -import 'StringListTypeModel.dart'; - -export 'Blog.dart'; -export 'Comment.dart'; -export 'Post.dart'; -export 'StringListTypeModel.dart'; - -class ModelProvider implements ModelProviderInterface { - @override - String version = "f43670a12adedf95a96cd58377c6c2bc"; - @override - List modelSchemas = [ - Blog.schema, - Comment.schema, - Post.schema, - StringListTypeModel.schema - ]; - static final ModelProvider _instance = ModelProvider(); - @override - List customTypeSchemas = []; - - static ModelProvider get instance => _instance; - - ModelType getModelTypeByModelName(String modelName) { - switch (modelName) { - case "Blog": - return Blog.classType; - case "Comment": - return Comment.classType; - case "Post": - return Post.classType; - case "StringListTypeModel": - return StringListTypeModel.classType; - default: - throw Exception( - "Failed to find model in model provider for model name: " + - modelName); - } - } -} diff --git a/packages/amplify_datastore/test/test_models/Post.dart b/packages/amplify_datastore/test/test_models/Post.dart deleted file mode 100644 index 5af5dbb852..0000000000 --- a/packages/amplify_datastore/test/test_models/Post.dart +++ /dev/null @@ -1,311 +0,0 @@ -/* -* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. -* -* Licensed under the Apache License, Version 2.0 (the "License"). -* You may not use this file except in compliance with the License. -* A copy of the License is located at -* -* http://aws.amazon.com/apache2.0 -* -* or in the "license" file accompanying this file. This file is distributed -* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either -* express or implied. See the License for the specific language governing -* permissions and limitations under the License. -*/ - -// NOTE: This file is generated and may not follow lint rules defined in your app -// Generated files can be excluded from analysis in analysis_options.yaml -// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis - -// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code - -import 'ModelProvider.dart'; -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; -import 'package:collection/collection.dart'; -import 'package:flutter/foundation.dart'; - -/** This is an auto generated class representing the Post type in your schema. */ -@immutable -class Post extends Model { - static const classType = const _PostModelType(); - final String id; - final String? _title; - final int? _rating; - final TemporalDateTime? _created; - final int? _likeCount; - final Blog? _blog; - final List? _comments; - final TemporalDateTime? _createdAt; - final TemporalDateTime? _updatedAt; - - @override - getInstanceType() => classType; - - @override - String getId() { - return id; - } - - String get title { - try { - return _title!; - } catch (e) { - throw new DataStoreException( - DataStoreExceptionMessages - .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages - .codeGenRequiredFieldForceCastRecoverySuggestion, - underlyingException: e.toString()); - } - } - - int get rating { - try { - return _rating!; - } catch (e) { - throw new DataStoreException( - DataStoreExceptionMessages - .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages - .codeGenRequiredFieldForceCastRecoverySuggestion, - underlyingException: e.toString()); - } - } - - TemporalDateTime? get created { - return _created; - } - - int? get likeCount { - return _likeCount; - } - - Blog? get blog { - return _blog; - } - - List? get comments { - return _comments; - } - - TemporalDateTime? get createdAt { - return _createdAt; - } - - TemporalDateTime? get updatedAt { - return _updatedAt; - } - - const Post._internal( - {required this.id, - required title, - required rating, - created, - likeCount, - blog, - comments, - createdAt, - updatedAt}) - : _title = title, - _rating = rating, - _created = created, - _likeCount = likeCount, - _blog = blog, - _comments = comments, - _createdAt = createdAt, - _updatedAt = updatedAt; - - factory Post( - {String? id, - required String title, - required int rating, - TemporalDateTime? created, - int? likeCount, - Blog? blog, - List? comments}) { - return Post._internal( - id: id == null ? UUID.getUUID() : id, - title: title, - rating: rating, - created: created, - likeCount: likeCount, - blog: blog, - comments: - comments != null ? List.unmodifiable(comments) : comments); - } - - bool equals(Object other) { - return this == other; - } - - @override - bool operator ==(Object other) { - if (identical(other, this)) return true; - return other is Post && - id == other.id && - _title == other._title && - _rating == other._rating && - _created == other._created && - _likeCount == other._likeCount && - _blog == other._blog && - DeepCollectionEquality().equals(_comments, other._comments); - } - - @override - int get hashCode => toString().hashCode; - - @override - String toString() { - var buffer = new StringBuffer(); - - buffer.write("Post {"); - buffer.write("id=" + "$id" + ", "); - buffer.write("title=" + "$_title" + ", "); - buffer.write( - "rating=" + (_rating != null ? _rating!.toString() : "null") + ", "); - buffer.write( - "created=" + (_created != null ? _created!.format() : "null") + ", "); - buffer.write("likeCount=" + - (_likeCount != null ? _likeCount!.toString() : "null") + - ", "); - buffer.write("blog=" + (_blog != null ? _blog!.toString() : "null") + ", "); - buffer.write("createdAt=" + - (_createdAt != null ? _createdAt!.format() : "null") + - ", "); - buffer.write( - "updatedAt=" + (_updatedAt != null ? _updatedAt!.format() : "null")); - buffer.write("}"); - - return buffer.toString(); - } - - Post copyWith( - {String? id, - String? title, - int? rating, - TemporalDateTime? created, - int? likeCount, - Blog? blog, - List? comments}) { - return Post._internal( - id: id ?? this.id, - title: title ?? this.title, - rating: rating ?? this.rating, - created: created ?? this.created, - likeCount: likeCount ?? this.likeCount, - blog: blog ?? this.blog, - comments: comments ?? this.comments); - } - - Post.fromJson(Map json) - : id = json['id'], - _title = json['title'], - _rating = (json['rating'] as num?)?.toInt(), - _created = json['created'] != null - ? TemporalDateTime.fromString(json['created']) - : null, - _likeCount = (json['likeCount'] as num?)?.toInt(), - _blog = json['blog']?['serializedData'] != null - ? Blog.fromJson( - new Map.from(json['blog']['serializedData'])) - : null, - _comments = json['comments'] is List - ? (json['comments'] as List) - .where((e) => e?['serializedData'] != null) - .map((e) => Comment.fromJson( - new Map.from(e['serializedData']))) - .toList() - : null, - _createdAt = json['createdAt'] != null - ? TemporalDateTime.fromString(json['createdAt']) - : null, - _updatedAt = json['updatedAt'] != null - ? TemporalDateTime.fromString(json['updatedAt']) - : null; - - Map toJson() => { - 'id': id, - 'title': _title, - 'rating': _rating, - 'created': _created?.format(), - 'likeCount': _likeCount, - 'blog': _blog?.toJson(), - 'comments': _comments?.map((Comment? e) => e?.toJson()).toList(), - 'createdAt': _createdAt?.format(), - 'updatedAt': _updatedAt?.format() - }; - - static final QueryField ID = QueryField(fieldName: "post.id"); - static final QueryField TITLE = QueryField(fieldName: "title"); - static final QueryField RATING = QueryField(fieldName: "rating"); - static final QueryField CREATED = QueryField(fieldName: "created"); - static final QueryField LIKECOUNT = QueryField(fieldName: "likeCount"); - static final QueryField BLOG = QueryField( - fieldName: "blog", - fieldType: ModelFieldType(ModelFieldTypeEnum.model, - ofModelName: (Blog).toString())); - static final QueryField COMMENTS = QueryField( - fieldName: "comments", - fieldType: ModelFieldType(ModelFieldTypeEnum.model, - ofModelName: (Comment).toString())); - static var schema = - Model.defineSchema(define: (ModelSchemaDefinition modelSchemaDefinition) { - modelSchemaDefinition.name = "Post"; - modelSchemaDefinition.pluralName = "Posts"; - - modelSchemaDefinition.addField(ModelFieldDefinition.id()); - - modelSchemaDefinition.addField(ModelFieldDefinition.field( - key: Post.TITLE, - isRequired: true, - ofType: ModelFieldType(ModelFieldTypeEnum.string))); - - modelSchemaDefinition.addField(ModelFieldDefinition.field( - key: Post.RATING, - isRequired: true, - ofType: ModelFieldType(ModelFieldTypeEnum.int))); - - modelSchemaDefinition.addField(ModelFieldDefinition.field( - key: Post.CREATED, - isRequired: false, - ofType: ModelFieldType(ModelFieldTypeEnum.dateTime))); - - modelSchemaDefinition.addField(ModelFieldDefinition.field( - key: Post.LIKECOUNT, - isRequired: false, - ofType: ModelFieldType(ModelFieldTypeEnum.int))); - - modelSchemaDefinition.addField(ModelFieldDefinition.belongsTo( - key: Post.BLOG, - isRequired: false, - targetName: "blogID", - ofModelName: (Blog).toString())); - - modelSchemaDefinition.addField(ModelFieldDefinition.hasMany( - key: Post.COMMENTS, - isRequired: false, - ofModelName: (Comment).toString(), - associatedKey: Comment.POST)); - - modelSchemaDefinition.addField(ModelFieldDefinition.nonQueryField( - fieldName: 'createdAt', - isRequired: false, - isReadOnly: true, - ofType: ModelFieldType(ModelFieldTypeEnum.dateTime))); - - modelSchemaDefinition.addField(ModelFieldDefinition.nonQueryField( - fieldName: 'updatedAt', - isRequired: false, - isReadOnly: true, - ofType: ModelFieldType(ModelFieldTypeEnum.dateTime))); - }); -} - -class _PostModelType extends ModelType { - const _PostModelType(); - - @override - Post fromJson(Map jsonData) { - return Post.fromJson(jsonData); - } -} diff --git a/packages/amplify_datastore/test/test_models/StringListTypeModel.dart b/packages/amplify_datastore/test/test_models/StringListTypeModel.dart deleted file mode 100644 index 20a489b137..0000000000 --- a/packages/amplify_datastore/test/test_models/StringListTypeModel.dart +++ /dev/null @@ -1,112 +0,0 @@ -/* -* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. -* -* Licensed under the Apache License, Version 2.0 (the "License"). -* You may not use this file except in compliance with the License. -* A copy of the License is located at -* -* http://aws.amazon.com/apache2.0 -* -* or in the "license" file accompanying this file. This file is distributed -* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either -* express or implied. See the License for the specific language governing -* permissions and limitations under the License. -*/ - -// ignore_for_file: public_member_api_docs - -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; -import 'package:collection/collection.dart'; -import 'package:flutter/foundation.dart'; - -/** This is an auto generated class representing the StringListTypeModel type in your schema. */ -@immutable -class StringListTypeModel extends Model { - static const classType = const _StringListTypeModelModelType(); - final String id; - final List? _value; - - @override - getInstanceType() => classType; - - @override - String getId() { - return id; - } - - List? get value { - return _value; - } - - const StringListTypeModel._internal({required this.id, value}) - : _value = value; - - factory StringListTypeModel({String? id, List? value}) { - return StringListTypeModel._internal( - id: id == null ? UUID.getUUID() : id, - value: value != null ? List.unmodifiable(value) : value); - } - - bool equals(Object other) { - return this == other; - } - - @override - bool operator ==(Object other) { - if (identical(other, this)) return true; - return other is StringListTypeModel && - id == other.id && - DeepCollectionEquality().equals(_value, other._value); - } - - @override - int get hashCode => toString().hashCode; - - @override - String toString() { - var buffer = new StringBuffer(); - - buffer.write("StringListTypeModel {"); - buffer.write("id=" + "$id" + ", "); - buffer.write("value=" + (_value != null ? _value!.toString() : "null")); - buffer.write("}"); - - return buffer.toString(); - } - - StringListTypeModel copyWith({String? id, List? value}) { - return StringListTypeModel(id: id ?? this.id, value: value ?? this.value); - } - - StringListTypeModel.fromJson(Map json) - : id = json['id'], - _value = json['value']?.cast(); - - Map toJson() => {'id': id, 'value': _value}; - - static final QueryField ID = QueryField(fieldName: "stringListTypeModel.id"); - static final QueryField VALUE = QueryField(fieldName: "value"); - static var schema = - Model.defineSchema(define: (ModelSchemaDefinition modelSchemaDefinition) { - modelSchemaDefinition.name = "StringListTypeModel"; - modelSchemaDefinition.pluralName = "StringListTypeModels"; - - modelSchemaDefinition.addField(ModelFieldDefinition.id()); - - modelSchemaDefinition.addField(ModelFieldDefinition.field( - key: StringListTypeModel.VALUE, - isRequired: false, - isArray: true, - ofType: ModelFieldType(ModelFieldTypeEnum.collection, - ofModelName: describeEnum(ModelFieldTypeEnum.string)))); - }); -} - -class _StringListTypeModelModelType extends ModelType { - const _StringListTypeModelModelType(); - - @override - StringListTypeModel fromJson(Map jsonData) { - return StringListTypeModel.fromJson(jsonData); - } -} diff --git a/packages/amplify_datastore/test/test_models/test_schema.graphql b/packages/amplify_datastore/test/test_models/test_schema.graphql deleted file mode 100644 index 6189cc977e..0000000000 --- a/packages/amplify_datastore/test/test_models/test_schema.graphql +++ /dev/null @@ -1,24 +0,0 @@ -# This schema can be used to regenerate the test models that are in this folder -type Blog @model { - id: ID! - name: String! - posts: [Post] @connection(keyName: "byBlog", fields: ["id"]) -} - -type Post @model @key(name: "byBlog", fields: ["blogID"]) { - id: ID! - title: String! - rating: Int! - created: AWSDateTime - likeCount: Int - blogID: ID! - blog: Blog @connection(fields: ["blogID"]) - comments: [Comment] @connection(keyName: "byPost", fields: ["id"]) -} - -type Comment @model @key(name: "byPost", fields: ["postID", "content"]) { - id: ID! - postID: ID! - post: Post @connection(fields: ["postID"]) - content: String! -} diff --git a/packages/amplify_datastore_plugin_interface/test/amplify_custom_type_schema_test.dart b/packages/amplify_datastore_plugin_interface/test/amplify_custom_type_schema_test.dart index 05e47cea89..efbb2adbb8 100644 --- a/packages/amplify_datastore_plugin_interface/test/amplify_custom_type_schema_test.dart +++ b/packages/amplify_datastore_plugin_interface/test/amplify_custom_type_schema_test.dart @@ -16,7 +16,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; -import 'testData/ModelProvider.dart'; +import 'package:amplify_test/test_models/ModelProvider.dart'; /* Tests use below schema diff --git a/packages/amplify_datastore_plugin_interface/test/amplify_modelType_test.dart b/packages/amplify_datastore_plugin_interface/test/amplify_modelType_test.dart index bac74c5425..f8f6ca2a79 100644 --- a/packages/amplify_datastore_plugin_interface/test/amplify_modelType_test.dart +++ b/packages/amplify_datastore_plugin_interface/test/amplify_modelType_test.dart @@ -15,7 +15,7 @@ import 'package:flutter_test/flutter_test.dart'; -import 'testData/ModelProvider.dart'; +import 'package:amplify_test/test_models/ModelProvider.dart'; void main() { test('Comment.classType generates proper json from serializedMap modelschema', diff --git a/packages/amplify_datastore_plugin_interface/test/amplify_modelschema_test.dart b/packages/amplify_datastore_plugin_interface/test/amplify_modelschema_test.dart index a863311853..34a721c2b7 100644 --- a/packages/amplify_datastore_plugin_interface/test/amplify_modelschema_test.dart +++ b/packages/amplify_datastore_plugin_interface/test/amplify_modelschema_test.dart @@ -22,7 +22,7 @@ We need to verify that each conversion step (->) is done correctly and each stat import 'package:amplify_core/amplify_core.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'testData/ModelProvider.dart'; +import 'package:amplify_test/test_models/ModelProvider.dart'; void main() { test('Blog codegen model generates modelschema with proper fields', () async { @@ -229,10 +229,11 @@ void main() { ]); }); - test('PostAuthComplex codegen model generates modelschema with proper fields', + test( + 'PostWithAuthRules codegen model generates modelschema with proper fields', () async { /* - type PostAuthComplex + type PostWithAuthRules @model @auth( rules: [ @@ -245,10 +246,10 @@ void main() { } */ - ModelSchema postSchema = PostAuthComplex.schema; + ModelSchema postSchema = PostWithAuthRules.schema; - expect(postSchema.name, "PostAuthComplex"); - expect(postSchema.pluralName, "PostAuthComplexes"); + expect(postSchema.name, "PostWithAuthRules"); + expect(postSchema.pluralName, "PostWithAuthRules"); expect(postSchema.authRules, [ AuthRule( authStrategy: AuthStrategy.OWNER, diff --git a/packages/amplify_datastore_plugin_interface/test/amplify_modelschema_to_map_test.dart b/packages/amplify_datastore_plugin_interface/test/amplify_modelschema_to_map_test.dart index b70c20cee0..1d9faaeacb 100644 --- a/packages/amplify_datastore_plugin_interface/test/amplify_modelschema_to_map_test.dart +++ b/packages/amplify_datastore_plugin_interface/test/amplify_modelschema_to_map_test.dart @@ -16,7 +16,7 @@ import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'testData/ModelProvider.dart'; +import 'package:amplify_test/test_models/ModelProvider.dart'; void main() { test('Blog codegen model generates modelschema with proper fields', () async { @@ -64,7 +64,7 @@ void main() { 'type': {'fieldType': 'dateTime'}, 'isRequired': false, 'isArray': false, - 'isReadOnly': true + 'isReadOnly': false }, 'updatedAt': { 'name': 'updatedAt', @@ -72,7 +72,24 @@ void main() { 'isRequired': false, 'isArray': false, 'isReadOnly': true - } + }, + 'file': { + 'name': 'file', + 'type': {'fieldType': 'embedded', 'ofCustomTypeName': 'S3Object'}, + 'isRequired': false, + 'isArray': false, + 'isReadOnly': false + }, + 'files': { + 'name': 'files', + 'type': { + 'fieldType': 'embeddedCollection', + 'ofCustomTypeName': 'S3Object' + }, + 'isRequired': false, + 'isArray': true, + 'isReadOnly': false + }, } }); }); @@ -227,14 +244,15 @@ void main() { }); }); - test('PostAuthComplex codegen model generates modelschema with proper fields', + test( + 'PostWithAuthRules codegen model generates modelschema with proper fields', () async { - ModelSchema postAuthComplexSchema = PostAuthComplex.schema; + ModelSchema postAuthComplexSchema = PostWithAuthRules.schema; Map map = postAuthComplexSchema.toMap(); expect(map, { - 'name': 'PostAuthComplex', - 'pluralName': 'PostAuthComplexes', + 'name': 'PostWithAuthRules', + 'pluralName': 'PostWithAuthRules', 'authRules': [ { 'authStrategy': 'OWNER', diff --git a/packages/amplify_datastore_plugin_interface/test/model_identifier_test.dart b/packages/amplify_datastore_plugin_interface/test/model_identifier_test.dart new file mode 100644 index 0000000000..60600be6aa --- /dev/null +++ b/packages/amplify_datastore_plugin_interface/test/model_identifier_test.dart @@ -0,0 +1,129 @@ +/* + * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the 'License'). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the 'license' file accompanying this file. This file is distributed + * on an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +import 'package:flutter_test/flutter_test.dart'; +import 'package:amplify_test/test_models/ModelProvider.dart'; + +void main() { + const testId = 'test-id-123'; + test('modelIdentifier getter of a model with non-custom primary', () { + // type Post @model { + // id: ID! + // title: String! + // rating: Int! + // } + var post = Post(id: testId, title: 'test blog', rating: 10); + expect(post.modelIdentifier, PostModelIdentifier(id: testId)); + expect(post.modelIdentifier.serializeAsList(), [ + {'id': testId} + ]); + expect(post.modelIdentifier.serializeAsMap(), {'id': testId}); + expect(post.modelIdentifier.serializeAsList(), [ + {'id': testId} + ]); + expect(post.modelIdentifier.serializeAsString(), testId); + }); + + test( + 'modelIdentifier getter of a model with id field as the custom primary key', + () { + // type Blog @model { + // id: ID! @primaryKey + // name: String! + // } + var blog = Blog(id: testId, name: 'test blog'); + expect(blog.modelIdentifier, BlogModelIdentifier(id: testId)); + expect(blog.modelIdentifier.serializeAsMap(), {'id': testId}); + expect(blog.modelIdentifier.serializeAsList(), [ + {'id': testId} + ]); + expect(blog.modelIdentifier.serializeAsString(), testId); + }); + + test( + 'modelIdentifier getter of a model with id field as a part of composite custom primary key', + () { + // type Warehouse @model { + // id: ID! @primaryKey(sortKeyFields: ["name", "region"]) + // name: String! + // region: String! + // } + final testData = { + 'id': testId, + 'name': 'warehouse A', + 'region': 'west-ca', + }; + var warehouse = Warehouse.fromJson(testData); + expect( + warehouse.modelIdentifier, + WarehouseModelIdentifier( + id: testData['id']!, + name: testData['name']!, + region: testData['region']!, + )); + expect(warehouse.modelIdentifier.serializeAsMap(), testData); + expect(warehouse.modelIdentifier.serializeAsList(), + testData.entries.map((e) => ({e.key: e.value})).toList()); + expect(warehouse.modelIdentifier.serializeAsString(), + testData.values.join('#')); + }); + + test('modelIdentifier getter of a model with custom primary key', () { + // type Product @model { + // productID: ID! @primaryKey + // name: String! + // amount: Int! + // } + var product = Product(productID: testId, name: 'a product', amount: 5); + expect(product.modelIdentifier, ProductModelIdentifier(productID: testId)); + expect(product.modelIdentifier.serializeAsMap(), {'productID': testId}); + expect(product.modelIdentifier.serializeAsList(), [ + {'productID': testId} + ]); + expect(product.modelIdentifier.serializeAsString(), testId); + }); + + test('modelIdentifier getter of a model with composite custom primary key', + () { + // type Inventory @model { + // productID: String! + // @primaryKey(sortKeyFields: ["name", "warehouseID", "region"]) + // name: String! + // warehouseID: ID! + // region: String! + // } + final testData = { + 'productID': testId, + 'name': 'InventoryB', + 'warehouseID': 'warehouse-123', + 'region': 'west-ca' + }; + var inventory = Inventory.fromJson(testData); + expect( + inventory.modelIdentifier, + InventoryModelIdentifier( + productID: testData['productID']!, + name: testData['name']!, + warehouseID: testData['warehouseID']!, + region: testData['region']!, + ), + ); + expect(inventory.modelIdentifier.serializeAsMap(), testData); + expect(inventory.modelIdentifier.serializeAsList(), + testData.entries.map((e) => ({e.key: e.value})).toList()); + expect(inventory.modelIdentifier.serializeAsString(), + testData.values.join('#')); + }); +} diff --git a/packages/amplify_datastore_plugin_interface/test/query_snapshot_test.dart b/packages/amplify_datastore_plugin_interface/test/query_snapshot_test.dart index 3e2cd168a3..89cf319eb3 100644 --- a/packages/amplify_datastore_plugin_interface/test/query_snapshot_test.dart +++ b/packages/amplify_datastore_plugin_interface/test/query_snapshot_test.dart @@ -16,7 +16,7 @@ import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'testData/ModelProvider.dart'; +import 'package:amplify_test/test_models/ModelProvider.dart'; void main() { group('QuerySnapshot', () { diff --git a/packages/amplify_datastore_plugin_interface/test/testData/Blog.dart b/packages/amplify_datastore_plugin_interface/test/testData/Blog.dart deleted file mode 100644 index 1a7d67bef1..0000000000 --- a/packages/amplify_datastore_plugin_interface/test/testData/Blog.dart +++ /dev/null @@ -1,196 +0,0 @@ -/* -* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. -* -* Licensed under the Apache License, Version 2.0 (the "License"). -* You may not use this file except in compliance with the License. -* A copy of the License is located at -* -* http://aws.amazon.com/apache2.0 -* -* or in the "license" file accompanying this file. This file is distributed -* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either -* express or implied. See the License for the specific language governing -* permissions and limitations under the License. -*/ - -// NOTE: This file is generated and may not follow lint rules defined in your app -// Generated files can be excluded from analysis in analysis_options.yaml -// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis - -// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code - -import 'ModelProvider.dart'; -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; -import 'package:collection/collection.dart'; -import 'package:flutter/foundation.dart'; - -/// This is an auto generated class representing the Blog type in your schema. -@immutable -class Blog extends Model { - static const classType = _BlogModelType(); - final String id; - final String? _name; - final List? _posts; - final TemporalDateTime? _createdAt; - final TemporalDateTime? _updatedAt; - - @override - getInstanceType() => classType; - - @override - String getId() { - return id; - } - - String get name { - try { - return _name!; - } catch (e) { - throw DataStoreException( - DataStoreExceptionMessages - .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages - .codeGenRequiredFieldForceCastRecoverySuggestion, - underlyingException: e.toString()); - } - } - - List? get posts { - return _posts; - } - - TemporalDateTime? get createdAt { - return _createdAt; - } - - TemporalDateTime? get updatedAt { - return _updatedAt; - } - - const Blog._internal( - {required this.id, required name, posts, createdAt, updatedAt}) - : _name = name, - _posts = posts, - _createdAt = createdAt, - _updatedAt = updatedAt; - - factory Blog({String? id, required String name, List? posts}) { - return Blog._internal( - id: id == null ? UUID.getUUID() : id, - name: name, - posts: posts != null ? List.unmodifiable(posts) : posts); - } - - bool equals(Object other) { - return this == other; - } - - @override - bool operator ==(Object other) { - if (identical(other, this)) return true; - return other is Blog && - id == other.id && - _name == other._name && - DeepCollectionEquality().equals(_posts, other._posts); - } - - @override - int get hashCode => toString().hashCode; - - @override - String toString() { - var buffer = StringBuffer(); - - buffer.write("Blog {"); - buffer.write("id=" + "$id" + ", "); - buffer.write("name=" + "$_name" + ", "); - buffer.write("createdAt=" + - (_createdAt != null ? _createdAt!.format() : "null") + - ", "); - buffer.write( - "updatedAt=" + (_updatedAt != null ? _updatedAt!.format() : "null")); - buffer.write("}"); - - return buffer.toString(); - } - - Blog copyWith({String? id, String? name, List? posts}) { - return Blog._internal( - id: id ?? this.id, name: name ?? this.name, posts: posts ?? this.posts); - } - - Blog.fromJson(Map json) - : id = json['id'], - _name = json['name'], - _posts = json['posts'] is List - ? (json['posts'] as List) - .where((e) => e?['serializedData'] != null) - .map((e) => Post.fromJson( - Map.from(e['serializedData']))) - .toList() - : null, - _createdAt = json['createdAt'] != null - ? TemporalDateTime.fromString(json['createdAt']) - : null, - _updatedAt = json['updatedAt'] != null - ? TemporalDateTime.fromString(json['updatedAt']) - : null; - - Map toJson() => { - 'id': id, - 'name': _name, - 'posts': _posts?.map((Post? e) => e?.toJson()).toList(), - 'createdAt': _createdAt?.format(), - 'updatedAt': _updatedAt?.format() - }; - - static final QueryField ID = QueryField(fieldName: "blog.id"); - static final QueryField NAME = QueryField(fieldName: "name"); - static final QueryField POSTS = QueryField( - fieldName: "posts", - fieldType: ModelFieldType(ModelFieldTypeEnum.model, - ofModelName: (Post).toString())); - static var schema = - Model.defineSchema(define: (ModelSchemaDefinition modelSchemaDefinition) { - modelSchemaDefinition.name = "Blog"; - modelSchemaDefinition.pluralName = "Blogs"; - - modelSchemaDefinition.indexes = [ - ModelIndex(fields: ["id"], name: null) - ]; - - modelSchemaDefinition.addField(ModelFieldDefinition.id()); - - modelSchemaDefinition.addField(ModelFieldDefinition.field( - key: Blog.NAME, - isRequired: true, - ofType: ModelFieldType(ModelFieldTypeEnum.string))); - - modelSchemaDefinition.addField(ModelFieldDefinition.hasMany( - key: Blog.POSTS, - isRequired: false, - ofModelName: (Post).toString(), - associatedKey: Post.BLOG)); - - modelSchemaDefinition.addField(ModelFieldDefinition.nonQueryField( - fieldName: 'createdAt', - isRequired: false, - isReadOnly: true, - ofType: ModelFieldType(ModelFieldTypeEnum.dateTime))); - - modelSchemaDefinition.addField(ModelFieldDefinition.nonQueryField( - fieldName: 'updatedAt', - isRequired: false, - isReadOnly: true, - ofType: ModelFieldType(ModelFieldTypeEnum.dateTime))); - }); -} - -class _BlogModelType extends ModelType { - const _BlogModelType(); - - @override - Blog fromJson(Map jsonData) { - return Blog.fromJson(jsonData); - } -} diff --git a/packages/amplify_datastore_plugin_interface/test/testData/Comment.dart b/packages/amplify_datastore_plugin_interface/test/testData/Comment.dart deleted file mode 100644 index 639dacdbfd..0000000000 --- a/packages/amplify_datastore_plugin_interface/test/testData/Comment.dart +++ /dev/null @@ -1,193 +0,0 @@ -/* -* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. -* -* Licensed under the Apache License, Version 2.0 (the "License"). -* You may not use this file except in compliance with the License. -* A copy of the License is located at -* -* http://aws.amazon.com/apache2.0 -* -* or in the "license" file accompanying this file. This file is distributed -* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either -* express or implied. See the License for the specific language governing -* permissions and limitations under the License. -*/ - -// NOTE: This file is generated and may not follow lint rules defined in your app -// Generated files can be excluded from analysis in analysis_options.yaml -// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis - -// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code - -import 'ModelProvider.dart'; -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; -import 'package:flutter/foundation.dart'; - -/// This is an auto generated class representing the Comment type in your schema. -@immutable -class Comment extends Model { - static const classType = _CommentModelType(); - final String id; - final Post? _post; - final String? _content; - final TemporalDateTime? _createdAt; - final TemporalDateTime? _updatedAt; - - @override - getInstanceType() => classType; - - @override - String getId() { - return id; - } - - Post? get post { - return _post; - } - - String get content { - try { - return _content!; - } catch (e) { - throw DataStoreException( - DataStoreExceptionMessages - .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages - .codeGenRequiredFieldForceCastRecoverySuggestion, - underlyingException: e.toString()); - } - } - - TemporalDateTime? get createdAt { - return _createdAt; - } - - TemporalDateTime? get updatedAt { - return _updatedAt; - } - - const Comment._internal( - {required this.id, post, required content, createdAt, updatedAt}) - : _post = post, - _content = content, - _createdAt = createdAt, - _updatedAt = updatedAt; - - factory Comment({String? id, Post? post, required String content}) { - return Comment._internal( - id: id == null ? UUID.getUUID() : id, post: post, content: content); - } - - bool equals(Object other) { - return this == other; - } - - @override - bool operator ==(Object other) { - if (identical(other, this)) return true; - return other is Comment && - id == other.id && - _post == other._post && - _content == other._content; - } - - @override - int get hashCode => toString().hashCode; - - @override - String toString() { - var buffer = StringBuffer(); - - buffer.write("Comment {"); - buffer.write("id=" + "$id" + ", "); - buffer.write("post=" + (_post != null ? _post!.toString() : "null") + ", "); - buffer.write("content=" + "$_content" + ", "); - buffer.write("createdAt=" + - (_createdAt != null ? _createdAt!.format() : "null") + - ", "); - buffer.write( - "updatedAt=" + (_updatedAt != null ? _updatedAt!.format() : "null")); - buffer.write("}"); - - return buffer.toString(); - } - - Comment copyWith({String? id, Post? post, String? content}) { - return Comment._internal( - id: id ?? this.id, - post: post ?? this.post, - content: content ?? this.content); - } - - Comment.fromJson(Map json) - : id = json['id'], - _post = json['post']?['serializedData'] != null - ? Post.fromJson( - Map.from(json['post']['serializedData'])) - : null, - _content = json['content'], - _createdAt = json['createdAt'] != null - ? TemporalDateTime.fromString(json['createdAt']) - : null, - _updatedAt = json['updatedAt'] != null - ? TemporalDateTime.fromString(json['updatedAt']) - : null; - - Map toJson() => { - 'id': id, - 'post': _post?.toJson(), - 'content': _content, - 'createdAt': _createdAt?.format(), - 'updatedAt': _updatedAt?.format() - }; - - static final QueryField ID = QueryField(fieldName: "comment.id"); - static final QueryField POST = QueryField( - fieldName: "post", - fieldType: ModelFieldType(ModelFieldTypeEnum.model, - ofModelName: (Post).toString())); - static final QueryField CONTENT = QueryField(fieldName: "content"); - static var schema = - Model.defineSchema(define: (ModelSchemaDefinition modelSchemaDefinition) { - modelSchemaDefinition.name = "Comment"; - modelSchemaDefinition.pluralName = "Comments"; - - modelSchemaDefinition.indexes = [ - ModelIndex(fields: ["postID", "content"], name: "byPost") - ]; - - modelSchemaDefinition.addField(ModelFieldDefinition.id()); - - modelSchemaDefinition.addField(ModelFieldDefinition.belongsTo( - key: Comment.POST, - isRequired: false, - targetName: "postID", - ofModelName: (Post).toString())); - - modelSchemaDefinition.addField(ModelFieldDefinition.field( - key: Comment.CONTENT, - isRequired: true, - ofType: ModelFieldType(ModelFieldTypeEnum.string))); - - modelSchemaDefinition.addField(ModelFieldDefinition.nonQueryField( - fieldName: 'createdAt', - isRequired: false, - isReadOnly: true, - ofType: ModelFieldType(ModelFieldTypeEnum.dateTime))); - - modelSchemaDefinition.addField(ModelFieldDefinition.nonQueryField( - fieldName: 'updatedAt', - isRequired: false, - isReadOnly: true, - ofType: ModelFieldType(ModelFieldTypeEnum.dateTime))); - }); -} - -class _CommentModelType extends ModelType { - const _CommentModelType(); - - @override - Comment fromJson(Map jsonData) { - return Comment.fromJson(jsonData); - } -} diff --git a/packages/amplify_datastore_plugin_interface/test/testData/ModelProvider.dart b/packages/amplify_datastore_plugin_interface/test/testData/ModelProvider.dart deleted file mode 100644 index f87a8dfbac..0000000000 --- a/packages/amplify_datastore_plugin_interface/test/testData/ModelProvider.dart +++ /dev/null @@ -1,78 +0,0 @@ -/* -* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. -* -* Licensed under the Apache License, Version 2.0 (the "License"). -* You may not use this file except in compliance with the License. -* A copy of the License is located at -* -* http://aws.amazon.com/apache2.0 -* -* or in the "license" file accompanying this file. This file is distributed -* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either -* express or implied. See the License for the specific language governing -* permissions and limitations under the License. -*/ - -// NOTE: This file is generated and may not follow lint rules defined in your app -// Generated files can be excluded from analysis in analysis_options.yaml -// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis - -// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code - -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; -import 'Blog.dart'; -import 'Comment.dart'; -import 'Post.dart'; -import 'PostAuthComplex.dart'; -import 'Address.dart'; -import 'Contact.dart'; -import 'Person.dart'; -import 'Phone.dart'; - -export 'Address.dart'; -export 'Blog.dart'; -export 'Comment.dart'; -export 'Contact.dart'; -export 'Person.dart'; -export 'Phone.dart'; -export 'Post.dart'; -export 'PostAuthComplex.dart'; - -class ModelProvider implements ModelProviderInterface { - @override - String version = "17ca7e949658b1d89af21147c8fb3455"; - @override - List modelSchemas = [ - Blog.schema, - Comment.schema, - Post.schema, - PostAuthComplex.schema - ]; - static final ModelProvider _instance = ModelProvider(); - @override - List customTypeSchemas = [ - Address.schema, - Contact.schema, - Person.schema, - Phone.schema - ]; - - static ModelProvider get instance => _instance; - - ModelType getModelTypeByModelName(String modelName) { - switch (modelName) { - case "Blog": - return Blog.classType; - case "Comment": - return Comment.classType; - case "Post": - return Post.classType; - case "PostAuthComplex": - return PostAuthComplex.classType; - default: - throw Exception( - "Failed to find model in model provider for model name: " + - modelName); - } - } -} diff --git a/packages/amplify_datastore_plugin_interface/test/testData/Post.dart b/packages/amplify_datastore_plugin_interface/test/testData/Post.dart deleted file mode 100644 index 453cd206d9..0000000000 --- a/packages/amplify_datastore_plugin_interface/test/testData/Post.dart +++ /dev/null @@ -1,315 +0,0 @@ -/* -* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. -* -* Licensed under the Apache License, Version 2.0 (the "License"). -* You may not use this file except in compliance with the License. -* A copy of the License is located at -* -* http://aws.amazon.com/apache2.0 -* -* or in the "license" file accompanying this file. This file is distributed -* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either -* express or implied. See the License for the specific language governing -* permissions and limitations under the License. -*/ - -// NOTE: This file is generated and may not follow lint rules defined in your app -// Generated files can be excluded from analysis in analysis_options.yaml -// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis - -// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code - -import 'ModelProvider.dart'; -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; -import 'package:collection/collection.dart'; -import 'package:flutter/foundation.dart'; - -/// This is an auto generated class representing the Post type in your schema. -@immutable -class Post extends Model { - static const classType = _PostModelType(); - final String id; - final String? _title; - final int? _rating; - final TemporalDateTime? _created; - final int? _likeCount; - final Blog? _blog; - final List? _comments; - final TemporalDateTime? _createdAt; - final TemporalDateTime? _updatedAt; - - @override - getInstanceType() => classType; - - @override - String getId() { - return id; - } - - String get title { - try { - return _title!; - } catch (e) { - throw DataStoreException( - DataStoreExceptionMessages - .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages - .codeGenRequiredFieldForceCastRecoverySuggestion, - underlyingException: e.toString()); - } - } - - int get rating { - try { - return _rating!; - } catch (e) { - throw DataStoreException( - DataStoreExceptionMessages - .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages - .codeGenRequiredFieldForceCastRecoverySuggestion, - underlyingException: e.toString()); - } - } - - TemporalDateTime? get created { - return _created; - } - - int? get likeCount { - return _likeCount; - } - - Blog? get blog { - return _blog; - } - - List? get comments { - return _comments; - } - - TemporalDateTime? get createdAt { - return _createdAt; - } - - TemporalDateTime? get updatedAt { - return _updatedAt; - } - - const Post._internal( - {required this.id, - required title, - required rating, - created, - likeCount, - blog, - comments, - createdAt, - updatedAt}) - : _title = title, - _rating = rating, - _created = created, - _likeCount = likeCount, - _blog = blog, - _comments = comments, - _createdAt = createdAt, - _updatedAt = updatedAt; - - factory Post( - {String? id, - required String title, - required int rating, - TemporalDateTime? created, - int? likeCount, - Blog? blog, - List? comments}) { - return Post._internal( - id: id == null ? UUID.getUUID() : id, - title: title, - rating: rating, - created: created, - likeCount: likeCount, - blog: blog, - comments: - comments != null ? List.unmodifiable(comments) : comments); - } - - bool equals(Object other) { - return this == other; - } - - @override - bool operator ==(Object other) { - if (identical(other, this)) return true; - return other is Post && - id == other.id && - _title == other._title && - _rating == other._rating && - _created == other._created && - _likeCount == other._likeCount && - _blog == other._blog && - DeepCollectionEquality().equals(_comments, other._comments); - } - - @override - int get hashCode => toString().hashCode; - - @override - String toString() { - var buffer = StringBuffer(); - - buffer.write("Post {"); - buffer.write("id=" + "$id" + ", "); - buffer.write("title=" + "$_title" + ", "); - buffer.write( - "rating=" + (_rating != null ? _rating!.toString() : "null") + ", "); - buffer.write( - "created=" + (_created != null ? _created!.format() : "null") + ", "); - buffer.write("likeCount=" + - (_likeCount != null ? _likeCount!.toString() : "null") + - ", "); - buffer.write("blog=" + (_blog != null ? _blog!.toString() : "null") + ", "); - buffer.write("createdAt=" + - (_createdAt != null ? _createdAt!.format() : "null") + - ", "); - buffer.write( - "updatedAt=" + (_updatedAt != null ? _updatedAt!.format() : "null")); - buffer.write("}"); - - return buffer.toString(); - } - - Post copyWith( - {String? id, - String? title, - int? rating, - TemporalDateTime? created, - int? likeCount, - Blog? blog, - List? comments}) { - return Post._internal( - id: id ?? this.id, - title: title ?? this.title, - rating: rating ?? this.rating, - created: created ?? this.created, - likeCount: likeCount ?? this.likeCount, - blog: blog ?? this.blog, - comments: comments ?? this.comments); - } - - Post.fromJson(Map json) - : id = json['id'], - _title = json['title'], - _rating = (json['rating'] as num?)?.toInt(), - _created = json['created'] != null - ? TemporalDateTime.fromString(json['created']) - : null, - _likeCount = (json['likeCount'] as num?)?.toInt(), - _blog = json['blog']?['serializedData'] != null - ? Blog.fromJson( - Map.from(json['blog']['serializedData'])) - : null, - _comments = json['comments'] is List - ? (json['comments'] as List) - .where((e) => e?['serializedData'] != null) - .map((e) => Comment.fromJson( - Map.from(e['serializedData']))) - .toList() - : null, - _createdAt = json['createdAt'] != null - ? TemporalDateTime.fromString(json['createdAt']) - : null, - _updatedAt = json['updatedAt'] != null - ? TemporalDateTime.fromString(json['updatedAt']) - : null; - - Map toJson() => { - 'id': id, - 'title': _title, - 'rating': _rating, - 'created': _created?.format(), - 'likeCount': _likeCount, - 'blog': _blog?.toJson(), - 'comments': _comments?.map((Comment? e) => e?.toJson()).toList(), - 'createdAt': _createdAt?.format(), - 'updatedAt': _updatedAt?.format() - }; - - static final QueryField ID = QueryField(fieldName: "post.id"); - static final QueryField TITLE = QueryField(fieldName: "title"); - static final QueryField RATING = QueryField(fieldName: "rating"); - static final QueryField CREATED = QueryField(fieldName: "created"); - static final QueryField LIKECOUNT = QueryField(fieldName: "likeCount"); - static final QueryField BLOG = QueryField( - fieldName: "blog", - fieldType: ModelFieldType(ModelFieldTypeEnum.model, - ofModelName: (Blog).toString())); - static final QueryField COMMENTS = QueryField( - fieldName: "comments", - fieldType: ModelFieldType(ModelFieldTypeEnum.model, - ofModelName: (Comment).toString())); - static var schema = - Model.defineSchema(define: (ModelSchemaDefinition modelSchemaDefinition) { - modelSchemaDefinition.name = "Post"; - modelSchemaDefinition.pluralName = "Posts"; - - modelSchemaDefinition.indexes = [ - ModelIndex(fields: ["blogID"], name: "byBlog") - ]; - - modelSchemaDefinition.addField(ModelFieldDefinition.id()); - - modelSchemaDefinition.addField(ModelFieldDefinition.field( - key: Post.TITLE, - isRequired: true, - ofType: ModelFieldType(ModelFieldTypeEnum.string))); - - modelSchemaDefinition.addField(ModelFieldDefinition.field( - key: Post.RATING, - isRequired: true, - ofType: ModelFieldType(ModelFieldTypeEnum.int))); - - modelSchemaDefinition.addField(ModelFieldDefinition.field( - key: Post.CREATED, - isRequired: false, - ofType: ModelFieldType(ModelFieldTypeEnum.dateTime))); - - modelSchemaDefinition.addField(ModelFieldDefinition.field( - key: Post.LIKECOUNT, - isRequired: false, - ofType: ModelFieldType(ModelFieldTypeEnum.int))); - - modelSchemaDefinition.addField(ModelFieldDefinition.belongsTo( - key: Post.BLOG, - isRequired: false, - targetName: "blogID", - ofModelName: (Blog).toString())); - - modelSchemaDefinition.addField(ModelFieldDefinition.hasMany( - key: Post.COMMENTS, - isRequired: false, - ofModelName: (Comment).toString(), - associatedKey: Comment.POST)); - - modelSchemaDefinition.addField(ModelFieldDefinition.nonQueryField( - fieldName: 'createdAt', - isRequired: false, - isReadOnly: true, - ofType: ModelFieldType(ModelFieldTypeEnum.dateTime))); - - modelSchemaDefinition.addField(ModelFieldDefinition.nonQueryField( - fieldName: 'updatedAt', - isRequired: false, - isReadOnly: true, - ofType: ModelFieldType(ModelFieldTypeEnum.dateTime))); - }); -} - -class _PostModelType extends ModelType { - const _PostModelType(); - - @override - Post fromJson(Map jsonData) { - return Post.fromJson(jsonData); - } -} diff --git a/packages/amplify_datastore_plugin_interface/test/testData/Address.dart b/packages/amplify_test/lib/test_models/Address.dart similarity index 89% rename from packages/amplify_datastore_plugin_interface/test/testData/Address.dart rename to packages/amplify_test/lib/test_models/Address.dart index 2af6102c60..fe62ee87b7 100644 --- a/packages/amplify_datastore_plugin_interface/test/testData/Address.dart +++ b/packages/amplify_test/lib/test_models/Address.dart @@ -17,9 +17,9 @@ // Generated files can be excluded from analysis in analysis_options.yaml // For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis -// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code +// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code, implicit_dynamic_parameter, implicit_dynamic_map_literal, implicit_dynamic_type -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:flutter/foundation.dart'; /// This is an auto generated class representing the Address type in your schema. @@ -35,10 +35,10 @@ class Address { try { return _line1!; } catch (e) { - throw DataStoreException( - DataStoreExceptionMessages + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages + recoverySuggestion: AmplifyExceptionMessages .codeGenRequiredFieldForceCastRecoverySuggestion, underlyingException: e.toString()); } @@ -52,10 +52,10 @@ class Address { try { return _city!; } catch (e) { - throw DataStoreException( - DataStoreExceptionMessages + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages + recoverySuggestion: AmplifyExceptionMessages .codeGenRequiredFieldForceCastRecoverySuggestion, underlyingException: e.toString()); } @@ -65,10 +65,10 @@ class Address { try { return _state!; } catch (e) { - throw DataStoreException( - DataStoreExceptionMessages + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages + recoverySuggestion: AmplifyExceptionMessages .codeGenRequiredFieldForceCastRecoverySuggestion, underlyingException: e.toString()); } @@ -78,10 +78,10 @@ class Address { try { return _postalCode!; } catch (e) { - throw DataStoreException( - DataStoreExceptionMessages + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages + recoverySuggestion: AmplifyExceptionMessages .codeGenRequiredFieldForceCastRecoverySuggestion, underlyingException: e.toString()); } diff --git a/packages/amplify_test/lib/test_models/Blog.dart b/packages/amplify_test/lib/test_models/Blog.dart index 03b87d5d20..037d79e850 100644 --- a/packages/amplify_test/lib/test_models/Blog.dart +++ b/packages/amplify_test/lib/test_models/Blog.dart @@ -24,10 +24,10 @@ import 'package:amplify_core/amplify_core.dart'; import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; -/** This is an auto generated class representing the Blog type in your schema. */ +/// This is an auto generated class representing the Blog type in your schema. @immutable class Blog extends Model { - static const classType = const _BlogModelType(); + static const classType = _BlogModelType(); final String id; final String? _name; final TemporalDateTime? _createdAt; @@ -39,16 +39,20 @@ class Blog extends Model { @override getInstanceType() => classType; + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') @override - String getId() { - return id; + String getId() => id; + + BlogModelIdentifier get modelIdentifier { + return BlogModelIdentifier(id: id); } String get name { try { return _name!; } catch (e) { - throw new AmplifyCodeGenModelException( + throw AmplifyCodeGenModelException( AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, recoverySuggestion: AmplifyExceptionMessages @@ -129,7 +133,7 @@ class Blog extends Model { @override String toString() { - var buffer = new StringBuffer(); + var buffer = StringBuffer(); buffer.write("Blog {"); buffer.write("id=" + "$id" + ", "); @@ -148,14 +152,13 @@ class Blog extends Model { } Blog copyWith( - {String? id, - String? name, + {String? name, TemporalDateTime? createdAt, S3Object? file, List? files, List? posts}) { return Blog._internal( - id: id ?? this.id, + id: id, name: name ?? this.name, createdAt: createdAt ?? this.createdAt, file: file ?? this.file, @@ -171,20 +174,20 @@ class Blog extends Model { : null, _file = json['file']?['serializedData'] != null ? S3Object.fromJson( - new Map.from(json['file']['serializedData'])) + Map.from(json['file']['serializedData'])) : null, _files = json['files'] is List ? (json['files'] as List) .where((e) => e != null) .map((e) => S3Object.fromJson( - new Map.from(e['serializedData']))) + Map.from(e['serializedData']))) .toList() : null, _posts = json['posts'] is List ? (json['posts'] as List) .where((e) => e?['serializedData'] != null) .map((e) => Post.fromJson( - new Map.from(e['serializedData']))) + Map.from(e['serializedData']))) .toList() : null, _updatedAt = json['updatedAt'] != null @@ -215,6 +218,10 @@ class Blog extends Model { modelSchemaDefinition.name = "Blog"; modelSchemaDefinition.pluralName = "Blogs"; + modelSchemaDefinition.indexes = [ + ModelIndex(fields: const ["id"], name: null) + ]; + modelSchemaDefinition.addField(ModelFieldDefinition.id()); modelSchemaDefinition.addField(ModelFieldDefinition.field( @@ -262,3 +269,40 @@ class _BlogModelType extends ModelType { return Blog.fromJson(jsonData); } } + +/// This is an auto generated class representing the model identifier +/// of [Blog] in your schema. +@immutable +class BlogModelIdentifier implements ModelIdentifier { + final String id; + + /// Create an instance of BlogModelIdentifier using [id] the primary key. + const BlogModelIdentifier({required this.id}); + + @override + Map serializeAsMap() => ({'id': id}); + + @override + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + @override + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'BlogModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is BlogModelIdentifier && id == other.id; + } + + @override + int get hashCode => id.hashCode; +} diff --git a/packages/amplify_test/lib/test_models/Comment.dart b/packages/amplify_test/lib/test_models/Comment.dart index 1ad3bcd56b..333ebdc1b8 100644 --- a/packages/amplify_test/lib/test_models/Comment.dart +++ b/packages/amplify_test/lib/test_models/Comment.dart @@ -23,10 +23,10 @@ import 'ModelProvider.dart'; import 'package:amplify_core/amplify_core.dart'; import 'package:flutter/foundation.dart'; -/** This is an auto generated class representing the Comment type in your schema. */ +/// This is an auto generated class representing the Comment type in your schema. @immutable class Comment extends Model { - static const classType = const _CommentModelType(); + static const classType = _CommentModelType(); final String id; final Post? _post; final String? _content; @@ -36,9 +36,13 @@ class Comment extends Model { @override getInstanceType() => classType; + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') @override - String getId() { - return id; + String getId() => id; + + CommentModelIdentifier get modelIdentifier { + return CommentModelIdentifier(id: id); } Post? get post { @@ -49,7 +53,7 @@ class Comment extends Model { try { return _content!; } catch (e) { - throw new AmplifyCodeGenModelException( + throw AmplifyCodeGenModelException( AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, recoverySuggestion: AmplifyExceptionMessages @@ -96,7 +100,7 @@ class Comment extends Model { @override String toString() { - var buffer = new StringBuffer(); + var buffer = StringBuffer(); buffer.write("Comment {"); buffer.write("id=" + "$id" + ", "); @@ -112,18 +116,16 @@ class Comment extends Model { return buffer.toString(); } - Comment copyWith({String? id, Post? post, String? content}) { + Comment copyWith({Post? post, String? content}) { return Comment._internal( - id: id ?? this.id, - post: post ?? this.post, - content: content ?? this.content); + id: id, post: post ?? this.post, content: content ?? this.content); } Comment.fromJson(Map json) : id = json['id'], _post = json['post']?['serializedData'] != null ? Post.fromJson( - new Map.from(json['post']['serializedData'])) + Map.from(json['post']['serializedData'])) : null, _content = json['content'], _createdAt = json['createdAt'] != null @@ -152,6 +154,10 @@ class Comment extends Model { modelSchemaDefinition.name = "Comment"; modelSchemaDefinition.pluralName = "Comments"; + modelSchemaDefinition.indexes = [ + ModelIndex(fields: const ["postID", "content"], name: "byPost") + ]; + modelSchemaDefinition.addField(ModelFieldDefinition.id()); modelSchemaDefinition.addField(ModelFieldDefinition.belongsTo( @@ -187,3 +193,40 @@ class _CommentModelType extends ModelType { return Comment.fromJson(jsonData); } } + +/// This is an auto generated class representing the model identifier +/// of [Comment] in your schema. +@immutable +class CommentModelIdentifier implements ModelIdentifier { + final String id; + + /// Create an instance of CommentModelIdentifier using [id] the primary key. + const CommentModelIdentifier({required this.id}); + + @override + Map serializeAsMap() => ({'id': id}); + + @override + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + @override + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'CommentModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is CommentModelIdentifier && id == other.id; + } + + @override + int get hashCode => id.hashCode; +} diff --git a/packages/amplify_datastore_plugin_interface/test/testData/Contact.dart b/packages/amplify_test/lib/test_models/Contact.dart similarity index 92% rename from packages/amplify_datastore_plugin_interface/test/testData/Contact.dart rename to packages/amplify_test/lib/test_models/Contact.dart index dff9c20247..c9e65eadbf 100644 --- a/packages/amplify_datastore_plugin_interface/test/testData/Contact.dart +++ b/packages/amplify_test/lib/test_models/Contact.dart @@ -17,10 +17,10 @@ // Generated files can be excluded from analysis in analysis_options.yaml // For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis -// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code +// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code, implicit_dynamic_parameter, implicit_dynamic_map_literal, implicit_dynamic_type import 'ModelProvider.dart'; -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; @@ -35,10 +35,10 @@ class Contact { try { return _email!; } catch (e) { - throw DataStoreException( - DataStoreExceptionMessages + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages + recoverySuggestion: AmplifyExceptionMessages .codeGenRequiredFieldForceCastRecoverySuggestion, underlyingException: e.toString()); } @@ -48,10 +48,10 @@ class Contact { try { return _phone!; } catch (e) { - throw DataStoreException( - DataStoreExceptionMessages + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages + recoverySuggestion: AmplifyExceptionMessages .codeGenRequiredFieldForceCastRecoverySuggestion, underlyingException: e.toString()); } diff --git a/packages/amplify_test/lib/test_models/FileMeta.dart b/packages/amplify_test/lib/test_models/FileMeta.dart index a55d750760..021fb0462e 100644 --- a/packages/amplify_test/lib/test_models/FileMeta.dart +++ b/packages/amplify_test/lib/test_models/FileMeta.dart @@ -13,12 +13,16 @@ * permissions and limitations under the License. */ +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + // ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code, implicit_dynamic_parameter, implicit_dynamic_map_literal, implicit_dynamic_type import 'package:amplify_core/amplify_core.dart'; import 'package:flutter/foundation.dart'; -/** This is an auto generated class representing the FileMeta type in your schema. */ +/// This is an auto generated class representing the FileMeta type in your schema. @immutable class FileMeta { final String? _name; @@ -27,7 +31,7 @@ class FileMeta { try { return _name!; } catch (e) { - throw new AmplifyCodeGenModelException( + throw AmplifyCodeGenModelException( AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, recoverySuggestion: AmplifyExceptionMessages @@ -57,7 +61,7 @@ class FileMeta { @override String toString() { - var buffer = new StringBuffer(); + var buffer = StringBuffer(); buffer.write("FileMeta {"); buffer.write("name=" + "$_name"); diff --git a/packages/amplify_test/lib/test_models/Inventory.dart b/packages/amplify_test/lib/test_models/Inventory.dart new file mode 100644 index 0000000000..0df0beafbf --- /dev/null +++ b/packages/amplify_test/lib/test_models/Inventory.dart @@ -0,0 +1,327 @@ +/* +* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. +* +* Licensed under the Apache License, Version 2.0 (the "License"). +* You may not use this file except in compliance with the License. +* A copy of the License is located at +* +* http://aws.amazon.com/apache2.0 +* +* or in the "license" file accompanying this file. This file is distributed +* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +* express or implied. See the License for the specific language governing +* permissions and limitations under the License. +*/ + +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code, implicit_dynamic_parameter, implicit_dynamic_map_literal, implicit_dynamic_type + +import 'package:amplify_core/amplify_core.dart'; +import 'package:flutter/foundation.dart'; + +/// This is an auto generated class representing the Inventory type in your schema. +@immutable +class Inventory extends Model { + static const classType = _InventoryModelType(); + final String? _productID; + final String? _name; + final String? _warehouseID; + final String? _region; + final TemporalDateTime? _createdAt; + final TemporalDateTime? _updatedAt; + + @override + getInstanceType() => classType; + + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') + @override + String getId() => modelIdentifier.serializeAsString(); + + InventoryModelIdentifier get modelIdentifier { + try { + return InventoryModelIdentifier( + productID: _productID!, + name: _name!, + warehouseID: _warehouseID!, + region: _region!); + } catch (e) { + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages + .codeGenRequiredFieldForceCastExceptionMessage, + recoverySuggestion: AmplifyExceptionMessages + .codeGenRequiredFieldForceCastRecoverySuggestion, + underlyingException: e.toString()); + } + } + + String get productID { + try { + return _productID!; + } catch (e) { + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages + .codeGenRequiredFieldForceCastExceptionMessage, + recoverySuggestion: AmplifyExceptionMessages + .codeGenRequiredFieldForceCastRecoverySuggestion, + underlyingException: e.toString()); + } + } + + String get name { + try { + return _name!; + } catch (e) { + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages + .codeGenRequiredFieldForceCastExceptionMessage, + recoverySuggestion: AmplifyExceptionMessages + .codeGenRequiredFieldForceCastRecoverySuggestion, + underlyingException: e.toString()); + } + } + + String get warehouseID { + try { + return _warehouseID!; + } catch (e) { + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages + .codeGenRequiredFieldForceCastExceptionMessage, + recoverySuggestion: AmplifyExceptionMessages + .codeGenRequiredFieldForceCastRecoverySuggestion, + underlyingException: e.toString()); + } + } + + String get region { + try { + return _region!; + } catch (e) { + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages + .codeGenRequiredFieldForceCastExceptionMessage, + recoverySuggestion: AmplifyExceptionMessages + .codeGenRequiredFieldForceCastRecoverySuggestion, + underlyingException: e.toString()); + } + } + + TemporalDateTime? get createdAt { + return _createdAt; + } + + TemporalDateTime? get updatedAt { + return _updatedAt; + } + + const Inventory._internal( + {required productID, + required name, + required warehouseID, + required region, + createdAt, + updatedAt}) + : _productID = productID, + _name = name, + _warehouseID = warehouseID, + _region = region, + _createdAt = createdAt, + _updatedAt = updatedAt; + + factory Inventory( + {required String productID, + required String name, + required String warehouseID, + required String region}) { + return Inventory._internal( + productID: productID, + name: name, + warehouseID: warehouseID, + region: region); + } + + bool equals(Object other) { + return this == other; + } + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Inventory && + _productID == other._productID && + _name == other._name && + _warehouseID == other._warehouseID && + _region == other._region; + } + + @override + int get hashCode => toString().hashCode; + + @override + String toString() { + var buffer = StringBuffer(); + + buffer.write("Inventory {"); + buffer.write("productID=" + "$_productID" + ", "); + buffer.write("name=" + "$_name" + ", "); + buffer.write("warehouseID=" + "$_warehouseID" + ", "); + buffer.write("region=" + "$_region" + ", "); + buffer.write("createdAt=" + + (_createdAt != null ? _createdAt!.format() : "null") + + ", "); + buffer.write( + "updatedAt=" + (_updatedAt != null ? _updatedAt!.format() : "null")); + buffer.write("}"); + + return buffer.toString(); + } + + Inventory copyWith() { + return Inventory._internal( + productID: productID, + name: name, + warehouseID: warehouseID, + region: region); + } + + Inventory.fromJson(Map json) + : _productID = json['productID'], + _name = json['name'], + _warehouseID = json['warehouseID'], + _region = json['region'], + _createdAt = json['createdAt'] != null + ? TemporalDateTime.fromString(json['createdAt']) + : null, + _updatedAt = json['updatedAt'] != null + ? TemporalDateTime.fromString(json['updatedAt']) + : null; + + Map toJson() => { + 'productID': _productID, + 'name': _name, + 'warehouseID': _warehouseID, + 'region': _region, + 'createdAt': _createdAt?.format(), + 'updatedAt': _updatedAt?.format() + }; + + static final QueryField PRODUCTID = QueryField(fieldName: "productID"); + static final QueryField NAME = QueryField(fieldName: "name"); + static final QueryField WAREHOUSEID = QueryField(fieldName: "warehouseID"); + static final QueryField REGION = QueryField(fieldName: "region"); + static var schema = + Model.defineSchema(define: (ModelSchemaDefinition modelSchemaDefinition) { + modelSchemaDefinition.name = "Inventory"; + modelSchemaDefinition.pluralName = "Inventories"; + + modelSchemaDefinition.indexes = [ + ModelIndex( + fields: const ["productID", "name", "warehouseID", "region"], + name: null) + ]; + + modelSchemaDefinition.addField(ModelFieldDefinition.field( + key: Inventory.PRODUCTID, + isRequired: true, + ofType: ModelFieldType(ModelFieldTypeEnum.string))); + + modelSchemaDefinition.addField(ModelFieldDefinition.field( + key: Inventory.NAME, + isRequired: true, + ofType: ModelFieldType(ModelFieldTypeEnum.string))); + + modelSchemaDefinition.addField(ModelFieldDefinition.field( + key: Inventory.WAREHOUSEID, + isRequired: true, + ofType: ModelFieldType(ModelFieldTypeEnum.string))); + + modelSchemaDefinition.addField(ModelFieldDefinition.field( + key: Inventory.REGION, + isRequired: true, + ofType: ModelFieldType(ModelFieldTypeEnum.string))); + + modelSchemaDefinition.addField(ModelFieldDefinition.nonQueryField( + fieldName: 'createdAt', + isRequired: false, + isReadOnly: true, + ofType: ModelFieldType(ModelFieldTypeEnum.dateTime))); + + modelSchemaDefinition.addField(ModelFieldDefinition.nonQueryField( + fieldName: 'updatedAt', + isRequired: false, + isReadOnly: true, + ofType: ModelFieldType(ModelFieldTypeEnum.dateTime))); + }); +} + +class _InventoryModelType extends ModelType { + const _InventoryModelType(); + + @override + Inventory fromJson(Map jsonData) { + return Inventory.fromJson(jsonData); + } +} + +/// This is an auto generated class representing the model identifier +/// of [Inventory] in your schema. +@immutable +class InventoryModelIdentifier implements ModelIdentifier { + final String productID; + final String name; + final String warehouseID; + final String region; + + /// Create an instance of InventoryModelIdentifier using [productID] the primary key. + /// And [name], [warehouseID], [region] the sort keys. + const InventoryModelIdentifier( + {required this.productID, + required this.name, + required this.warehouseID, + required this.region}); + + @override + Map serializeAsMap() => ({ + 'productID': productID, + 'name': name, + 'warehouseID': warehouseID, + 'region': region + }); + + @override + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + @override + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => + 'InventoryModelIdentifier(productID: $productID, name: $name, warehouseID: $warehouseID, region: $region)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is InventoryModelIdentifier && + productID == other.productID && + name == other.name && + warehouseID == other.warehouseID && + region == other.region; + } + + @override + int get hashCode => + productID.hashCode ^ + name.hashCode ^ + warehouseID.hashCode ^ + region.hashCode; +} diff --git a/packages/amplify_test/lib/test_models/ModelProvider.dart b/packages/amplify_test/lib/test_models/ModelProvider.dart index 626da997f7..f9c84ea7e2 100644 --- a/packages/amplify_test/lib/test_models/ModelProvider.dart +++ b/packages/amplify_test/lib/test_models/ModelProvider.dart @@ -17,29 +17,63 @@ // Generated files can be excluded from analysis in analysis_options.yaml // For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis -// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code +// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code, implicit_dynamic_parameter, implicit_dynamic_map_literal, implicit_dynamic_type import 'package:amplify_core/amplify_core.dart'; import 'Blog.dart'; import 'Comment.dart'; +import 'Inventory.dart'; import 'Post.dart'; +import 'PostWithAuthRules.dart'; +import 'Product.dart'; +import 'StringListTypeModel.dart'; +import 'Warehouse.dart'; +import 'Address.dart'; +import 'Contact.dart'; import 'FileMeta.dart'; +import 'Person.dart'; +import 'Phone.dart'; import 'S3Object.dart'; +export 'Address.dart'; export 'Blog.dart'; export 'Comment.dart'; +export 'Contact.dart'; export 'FileMeta.dart'; +export 'Inventory.dart'; +export 'Person.dart'; +export 'Phone.dart'; export 'Post.dart'; +export 'PostWithAuthRules.dart'; +export 'Product.dart'; export 'S3Object.dart'; +export 'StringListTypeModel.dart'; +export 'Warehouse.dart'; class ModelProvider implements ModelProviderInterface { @override - String version = "e22227993ad5df5e265b0d065245b740"; + String version = "c51f720bee3a3b8db3aa9ce045d17f5c"; @override - List modelSchemas = [Blog.schema, Comment.schema, Post.schema]; + List modelSchemas = [ + Blog.schema, + Comment.schema, + Inventory.schema, + Post.schema, + PostWithAuthRules.schema, + Product.schema, + Warehouse.schema + ]; static final ModelProvider _instance = ModelProvider(); @override - List customTypeSchemas = [FileMeta.schema, S3Object.schema]; + List customTypeSchemas = [ + Address.schema, + Contact.schema, + FileMeta.schema, + Person.schema, + Phone.schema, + S3Object.schema, + StringListTypeModel.schema + ]; static ModelProvider get instance => _instance; @@ -49,8 +83,18 @@ class ModelProvider implements ModelProviderInterface { return Blog.classType; case "Comment": return Comment.classType; + case "Inventory": + return Inventory.classType; case "Post": return Post.classType; + case "PostWithAuthRules": + return PostWithAuthRules.classType; + case "Product": + return Product.classType; + case "StringListTypeModel": + return StringListTypeModel.classType; + case "Warehouse": + return Warehouse.classType; default: throw Exception( "Failed to find model in model provider for model name: " + diff --git a/packages/amplify_datastore_plugin_interface/test/testData/Person.dart b/packages/amplify_test/lib/test_models/Person.dart similarity index 92% rename from packages/amplify_datastore_plugin_interface/test/testData/Person.dart rename to packages/amplify_test/lib/test_models/Person.dart index fd2d6eb0e5..95bca8b4c4 100644 --- a/packages/amplify_datastore_plugin_interface/test/testData/Person.dart +++ b/packages/amplify_test/lib/test_models/Person.dart @@ -17,10 +17,10 @@ // Generated files can be excluded from analysis in analysis_options.yaml // For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis -// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code +// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code, implicit_dynamic_parameter, implicit_dynamic_map_literal, implicit_dynamic_type import 'ModelProvider.dart'; -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; @@ -35,10 +35,10 @@ class Person { try { return _name!; } catch (e) { - throw DataStoreException( - DataStoreExceptionMessages + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages + recoverySuggestion: AmplifyExceptionMessages .codeGenRequiredFieldForceCastRecoverySuggestion, underlyingException: e.toString()); } @@ -52,10 +52,10 @@ class Person { try { return _contact!; } catch (e) { - throw DataStoreException( - DataStoreExceptionMessages + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages + recoverySuggestion: AmplifyExceptionMessages .codeGenRequiredFieldForceCastRecoverySuggestion, underlyingException: e.toString()); } diff --git a/packages/amplify_datastore_plugin_interface/test/testData/Phone.dart b/packages/amplify_test/lib/test_models/Phone.dart similarity index 88% rename from packages/amplify_datastore_plugin_interface/test/testData/Phone.dart rename to packages/amplify_test/lib/test_models/Phone.dart index e966ca66e0..47559c8ef6 100644 --- a/packages/amplify_datastore_plugin_interface/test/testData/Phone.dart +++ b/packages/amplify_test/lib/test_models/Phone.dart @@ -17,9 +17,9 @@ // Generated files can be excluded from analysis in analysis_options.yaml // For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis -// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code +// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code, implicit_dynamic_parameter, implicit_dynamic_map_literal, implicit_dynamic_type -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:flutter/foundation.dart'; /// This is an auto generated class representing the Phone type in your schema. @@ -32,10 +32,10 @@ class Phone { try { return _country!; } catch (e) { - throw DataStoreException( - DataStoreExceptionMessages + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages + recoverySuggestion: AmplifyExceptionMessages .codeGenRequiredFieldForceCastRecoverySuggestion, underlyingException: e.toString()); } @@ -45,10 +45,10 @@ class Phone { try { return _number!; } catch (e) { - throw DataStoreException( - DataStoreExceptionMessages + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages + recoverySuggestion: AmplifyExceptionMessages .codeGenRequiredFieldForceCastRecoverySuggestion, underlyingException: e.toString()); } diff --git a/packages/amplify_test/lib/test_models/Post.dart b/packages/amplify_test/lib/test_models/Post.dart index 3487b836a3..6c2a21f6ce 100644 --- a/packages/amplify_test/lib/test_models/Post.dart +++ b/packages/amplify_test/lib/test_models/Post.dart @@ -24,14 +24,15 @@ import 'package:amplify_core/amplify_core.dart'; import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; -/** This is an auto generated class representing the Post type in your schema. */ +/// This is an auto generated class representing the Post type in your schema. @immutable class Post extends Model { - static const classType = const _PostModelType(); + static const classType = _PostModelType(); final String id; final String? _title; final int? _rating; final TemporalDateTime? _created; + final int? _likeCount; final Blog? _blog; final List? _comments; final TemporalDateTime? _createdAt; @@ -40,16 +41,20 @@ class Post extends Model { @override getInstanceType() => classType; + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') @override - String getId() { - return id; + String getId() => id; + + PostModelIdentifier get modelIdentifier { + return PostModelIdentifier(id: id); } String get title { try { return _title!; } catch (e) { - throw new AmplifyCodeGenModelException( + throw AmplifyCodeGenModelException( AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, recoverySuggestion: AmplifyExceptionMessages @@ -62,7 +67,7 @@ class Post extends Model { try { return _rating!; } catch (e) { - throw new AmplifyCodeGenModelException( + throw AmplifyCodeGenModelException( AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, recoverySuggestion: AmplifyExceptionMessages @@ -75,6 +80,10 @@ class Post extends Model { return _created; } + int? get likeCount { + return _likeCount; + } + Blog? get blog { return _blog; } @@ -96,6 +105,7 @@ class Post extends Model { required title, required rating, created, + likeCount, blog, comments, createdAt, @@ -103,6 +113,7 @@ class Post extends Model { : _title = title, _rating = rating, _created = created, + _likeCount = likeCount, _blog = blog, _comments = comments, _createdAt = createdAt, @@ -113,6 +124,7 @@ class Post extends Model { required String title, required int rating, TemporalDateTime? created, + int? likeCount, Blog? blog, List? comments}) { return Post._internal( @@ -120,6 +132,7 @@ class Post extends Model { title: title, rating: rating, created: created, + likeCount: likeCount, blog: blog, comments: comments != null ? List.unmodifiable(comments) : comments); @@ -137,6 +150,7 @@ class Post extends Model { _title == other._title && _rating == other._rating && _created == other._created && + _likeCount == other._likeCount && _blog == other._blog && DeepCollectionEquality().equals(_comments, other._comments); } @@ -146,7 +160,7 @@ class Post extends Model { @override String toString() { - var buffer = new StringBuffer(); + var buffer = StringBuffer(); buffer.write("Post {"); buffer.write("id=" + "$id" + ", "); @@ -155,6 +169,9 @@ class Post extends Model { "rating=" + (_rating != null ? _rating!.toString() : "null") + ", "); buffer.write( "created=" + (_created != null ? _created!.format() : "null") + ", "); + buffer.write("likeCount=" + + (_likeCount != null ? _likeCount!.toString() : "null") + + ", "); buffer.write("blog=" + (_blog != null ? _blog!.toString() : "null") + ", "); buffer.write("createdAt=" + (_createdAt != null ? _createdAt!.format() : "null") + @@ -167,17 +184,18 @@ class Post extends Model { } Post copyWith( - {String? id, - String? title, + {String? title, int? rating, TemporalDateTime? created, + int? likeCount, Blog? blog, List? comments}) { return Post._internal( - id: id ?? this.id, + id: id, title: title ?? this.title, rating: rating ?? this.rating, created: created ?? this.created, + likeCount: likeCount ?? this.likeCount, blog: blog ?? this.blog, comments: comments ?? this.comments); } @@ -189,15 +207,16 @@ class Post extends Model { _created = json['created'] != null ? TemporalDateTime.fromString(json['created']) : null, + _likeCount = (json['likeCount'] as num?)?.toInt(), _blog = json['blog']?['serializedData'] != null ? Blog.fromJson( - new Map.from(json['blog']['serializedData'])) + Map.from(json['blog']['serializedData'])) : null, _comments = json['comments'] is List ? (json['comments'] as List) .where((e) => e?['serializedData'] != null) .map((e) => Comment.fromJson( - new Map.from(e['serializedData']))) + Map.from(e['serializedData']))) .toList() : null, _createdAt = json['createdAt'] != null @@ -212,6 +231,7 @@ class Post extends Model { 'title': _title, 'rating': _rating, 'created': _created?.format(), + 'likeCount': _likeCount, 'blog': _blog?.toJson(), 'comments': _comments?.map((Comment? e) => e?.toJson()).toList(), 'createdAt': _createdAt?.format(), @@ -222,6 +242,7 @@ class Post extends Model { static final QueryField TITLE = QueryField(fieldName: "title"); static final QueryField RATING = QueryField(fieldName: "rating"); static final QueryField CREATED = QueryField(fieldName: "created"); + static final QueryField LIKECOUNT = QueryField(fieldName: "likeCount"); static final QueryField BLOG = QueryField( fieldName: "blog", fieldType: ModelFieldType(ModelFieldTypeEnum.model, @@ -235,6 +256,10 @@ class Post extends Model { modelSchemaDefinition.name = "Post"; modelSchemaDefinition.pluralName = "Posts"; + modelSchemaDefinition.indexes = [ + ModelIndex(fields: const ["blogID"], name: "byBlog") + ]; + modelSchemaDefinition.addField(ModelFieldDefinition.id()); modelSchemaDefinition.addField(ModelFieldDefinition.field( @@ -252,6 +277,11 @@ class Post extends Model { isRequired: false, ofType: ModelFieldType(ModelFieldTypeEnum.dateTime))); + modelSchemaDefinition.addField(ModelFieldDefinition.field( + key: Post.LIKECOUNT, + isRequired: false, + ofType: ModelFieldType(ModelFieldTypeEnum.int))); + modelSchemaDefinition.addField(ModelFieldDefinition.belongsTo( key: Post.BLOG, isRequired: false, @@ -286,3 +316,40 @@ class _PostModelType extends ModelType { return Post.fromJson(jsonData); } } + +/// This is an auto generated class representing the model identifier +/// of [Post] in your schema. +@immutable +class PostModelIdentifier implements ModelIdentifier { + final String id; + + /// Create an instance of PostModelIdentifier using [id] the primary key. + const PostModelIdentifier({required this.id}); + + @override + Map serializeAsMap() => ({'id': id}); + + @override + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + @override + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'PostModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is PostModelIdentifier && id == other.id; + } + + @override + int get hashCode => id.hashCode; +} diff --git a/packages/amplify_datastore_plugin_interface/test/testData/PostAuthComplex.dart b/packages/amplify_test/lib/test_models/PostWithAuthRules.dart similarity index 63% rename from packages/amplify_datastore_plugin_interface/test/testData/PostAuthComplex.dart rename to packages/amplify_test/lib/test_models/PostWithAuthRules.dart index 1bf4dd1c2f..18344d674d 100644 --- a/packages/amplify_datastore_plugin_interface/test/testData/PostAuthComplex.dart +++ b/packages/amplify_test/lib/test_models/PostWithAuthRules.dart @@ -17,15 +17,15 @@ // Generated files can be excluded from analysis in analysis_options.yaml // For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis -// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code +// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code, implicit_dynamic_parameter, implicit_dynamic_map_literal, implicit_dynamic_type -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:amplify_core/amplify_core.dart'; import 'package:flutter/foundation.dart'; -/// This is an auto generated class representing the PostAuthComplex type in your schema. +/// This is an auto generated class representing the PostWithAuthRules type in your schema. @immutable -class PostAuthComplex extends Model { - static const classType = _PostAuthComplexModelType(); +class PostWithAuthRules extends Model { + static const classType = _PostWithAuthRulesModelType(); final String id; final String? _title; final String? _owner; @@ -35,19 +35,23 @@ class PostAuthComplex extends Model { @override getInstanceType() => classType; + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') @override - String getId() { - return id; + String getId() => id; + + PostWithAuthRulesModelIdentifier get modelIdentifier { + return PostWithAuthRulesModelIdentifier(id: id); } String get title { try { return _title!; } catch (e) { - throw DataStoreException( - DataStoreExceptionMessages + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: DataStoreExceptionMessages + recoverySuggestion: AmplifyExceptionMessages .codeGenRequiredFieldForceCastRecoverySuggestion, underlyingException: e.toString()); } @@ -65,15 +69,16 @@ class PostAuthComplex extends Model { return _updatedAt; } - const PostAuthComplex._internal( + const PostWithAuthRules._internal( {required this.id, required title, owner, createdAt, updatedAt}) : _title = title, _owner = owner, _createdAt = createdAt, _updatedAt = updatedAt; - factory PostAuthComplex({String? id, required String title, String? owner}) { - return PostAuthComplex._internal( + factory PostWithAuthRules( + {String? id, required String title, String? owner}) { + return PostWithAuthRules._internal( id: id == null ? UUID.getUUID() : id, title: title, owner: owner); } @@ -84,7 +89,7 @@ class PostAuthComplex extends Model { @override bool operator ==(Object other) { if (identical(other, this)) return true; - return other is PostAuthComplex && + return other is PostWithAuthRules && id == other.id && _title == other._title && _owner == other._owner; @@ -97,7 +102,7 @@ class PostAuthComplex extends Model { String toString() { var buffer = StringBuffer(); - buffer.write("PostAuthComplex {"); + buffer.write("PostWithAuthRules {"); buffer.write("id=" + "$id" + ", "); buffer.write("title=" + "$_title" + ", "); buffer.write("owner=" + "$_owner" + ", "); @@ -111,14 +116,12 @@ class PostAuthComplex extends Model { return buffer.toString(); } - PostAuthComplex copyWith({String? id, String? title, String? owner}) { - return PostAuthComplex._internal( - id: id ?? this.id, - title: title ?? this.title, - owner: owner ?? this.owner); + PostWithAuthRules copyWith({String? title, String? owner}) { + return PostWithAuthRules._internal( + id: id, title: title ?? this.title, owner: owner ?? this.owner); } - PostAuthComplex.fromJson(Map json) + PostWithAuthRules.fromJson(Map json) : id = json['id'], _title = json['title'], _owner = json['owner'], @@ -137,13 +140,13 @@ class PostAuthComplex extends Model { 'updatedAt': _updatedAt?.format() }; - static final QueryField ID = QueryField(fieldName: "postAuthComplex.id"); + static final QueryField ID = QueryField(fieldName: "postWithAuthRules.id"); static final QueryField TITLE = QueryField(fieldName: "title"); static final QueryField OWNER = QueryField(fieldName: "owner"); static var schema = Model.defineSchema(define: (ModelSchemaDefinition modelSchemaDefinition) { - modelSchemaDefinition.name = "PostAuthComplex"; - modelSchemaDefinition.pluralName = "PostAuthComplexes"; + modelSchemaDefinition.name = "PostWithAuthRules"; + modelSchemaDefinition.pluralName = "PostWithAuthRules"; modelSchemaDefinition.authRules = [ AuthRule( @@ -162,12 +165,12 @@ class PostAuthComplex extends Model { modelSchemaDefinition.addField(ModelFieldDefinition.id()); modelSchemaDefinition.addField(ModelFieldDefinition.field( - key: PostAuthComplex.TITLE, + key: PostWithAuthRules.TITLE, isRequired: true, ofType: ModelFieldType(ModelFieldTypeEnum.string))); modelSchemaDefinition.addField(ModelFieldDefinition.field( - key: PostAuthComplex.OWNER, + key: PostWithAuthRules.OWNER, isRequired: false, ofType: ModelFieldType(ModelFieldTypeEnum.string))); @@ -185,11 +188,49 @@ class PostAuthComplex extends Model { }); } -class _PostAuthComplexModelType extends ModelType { - const _PostAuthComplexModelType(); +class _PostWithAuthRulesModelType extends ModelType { + const _PostWithAuthRulesModelType(); + + @override + PostWithAuthRules fromJson(Map jsonData) { + return PostWithAuthRules.fromJson(jsonData); + } +} + +/// This is an auto generated class representing the model identifier +/// of [PostWithAuthRules] in your schema. +@immutable +class PostWithAuthRulesModelIdentifier + implements ModelIdentifier { + final String id; + + /// Create an instance of PostWithAuthRulesModelIdentifier using [id] the primary key. + const PostWithAuthRulesModelIdentifier({required this.id}); + + @override + Map serializeAsMap() => ({'id': id}); + + @override + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + @override + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'PostWithAuthRulesModelIdentifier(id: $id)'; @override - PostAuthComplex fromJson(Map jsonData) { - return PostAuthComplex.fromJson(jsonData); + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is PostWithAuthRulesModelIdentifier && id == other.id; } + + @override + int get hashCode => id.hashCode; } diff --git a/packages/amplify_test/lib/test_models/Product.dart b/packages/amplify_test/lib/test_models/Product.dart new file mode 100644 index 0000000000..4d3238dc0c --- /dev/null +++ b/packages/amplify_test/lib/test_models/Product.dart @@ -0,0 +1,267 @@ +/* +* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. +* +* Licensed under the Apache License, Version 2.0 (the "License"). +* You may not use this file except in compliance with the License. +* A copy of the License is located at +* +* http://aws.amazon.com/apache2.0 +* +* or in the "license" file accompanying this file. This file is distributed +* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +* express or implied. See the License for the specific language governing +* permissions and limitations under the License. +*/ + +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code, implicit_dynamic_parameter, implicit_dynamic_map_literal, implicit_dynamic_type + +import 'package:amplify_core/amplify_core.dart'; +import 'package:flutter/foundation.dart'; + +/// This is an auto generated class representing the Product type in your schema. +@immutable +class Product extends Model { + static const classType = _ProductModelType(); + final String? _productID; + final String? _name; + final int? _amount; + final TemporalDateTime? _createdAt; + final TemporalDateTime? _updatedAt; + + @override + getInstanceType() => classType; + + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') + @override + String getId() => modelIdentifier.serializeAsString(); + + ProductModelIdentifier get modelIdentifier { + try { + return ProductModelIdentifier(productID: _productID!); + } catch (e) { + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages + .codeGenRequiredFieldForceCastExceptionMessage, + recoverySuggestion: AmplifyExceptionMessages + .codeGenRequiredFieldForceCastRecoverySuggestion, + underlyingException: e.toString()); + } + } + + String get productID { + try { + return _productID!; + } catch (e) { + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages + .codeGenRequiredFieldForceCastExceptionMessage, + recoverySuggestion: AmplifyExceptionMessages + .codeGenRequiredFieldForceCastRecoverySuggestion, + underlyingException: e.toString()); + } + } + + String get name { + try { + return _name!; + } catch (e) { + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages + .codeGenRequiredFieldForceCastExceptionMessage, + recoverySuggestion: AmplifyExceptionMessages + .codeGenRequiredFieldForceCastRecoverySuggestion, + underlyingException: e.toString()); + } + } + + int get amount { + try { + return _amount!; + } catch (e) { + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages + .codeGenRequiredFieldForceCastExceptionMessage, + recoverySuggestion: AmplifyExceptionMessages + .codeGenRequiredFieldForceCastRecoverySuggestion, + underlyingException: e.toString()); + } + } + + TemporalDateTime? get createdAt { + return _createdAt; + } + + TemporalDateTime? get updatedAt { + return _updatedAt; + } + + const Product._internal( + {required productID, + required name, + required amount, + createdAt, + updatedAt}) + : _productID = productID, + _name = name, + _amount = amount, + _createdAt = createdAt, + _updatedAt = updatedAt; + + factory Product( + {required String productID, required String name, required int amount}) { + return Product._internal(productID: productID, name: name, amount: amount); + } + + bool equals(Object other) { + return this == other; + } + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Product && + _productID == other._productID && + _name == other._name && + _amount == other._amount; + } + + @override + int get hashCode => toString().hashCode; + + @override + String toString() { + var buffer = StringBuffer(); + + buffer.write("Product {"); + buffer.write("productID=" + "$_productID" + ", "); + buffer.write("name=" + "$_name" + ", "); + buffer.write( + "amount=" + (_amount != null ? _amount!.toString() : "null") + ", "); + buffer.write("createdAt=" + + (_createdAt != null ? _createdAt!.format() : "null") + + ", "); + buffer.write( + "updatedAt=" + (_updatedAt != null ? _updatedAt!.format() : "null")); + buffer.write("}"); + + return buffer.toString(); + } + + Product copyWith({String? name, int? amount}) { + return Product._internal( + productID: productID, + name: name ?? this.name, + amount: amount ?? this.amount); + } + + Product.fromJson(Map json) + : _productID = json['productID'], + _name = json['name'], + _amount = (json['amount'] as num?)?.toInt(), + _createdAt = json['createdAt'] != null + ? TemporalDateTime.fromString(json['createdAt']) + : null, + _updatedAt = json['updatedAt'] != null + ? TemporalDateTime.fromString(json['updatedAt']) + : null; + + Map toJson() => { + 'productID': _productID, + 'name': _name, + 'amount': _amount, + 'createdAt': _createdAt?.format(), + 'updatedAt': _updatedAt?.format() + }; + + static final QueryField PRODUCTID = QueryField(fieldName: "productID"); + static final QueryField NAME = QueryField(fieldName: "name"); + static final QueryField AMOUNT = QueryField(fieldName: "amount"); + static var schema = + Model.defineSchema(define: (ModelSchemaDefinition modelSchemaDefinition) { + modelSchemaDefinition.name = "Product"; + modelSchemaDefinition.pluralName = "Products"; + + modelSchemaDefinition.indexes = [ + ModelIndex(fields: const ["productID"], name: null) + ]; + + modelSchemaDefinition.addField(ModelFieldDefinition.field( + key: Product.PRODUCTID, + isRequired: true, + ofType: ModelFieldType(ModelFieldTypeEnum.string))); + + modelSchemaDefinition.addField(ModelFieldDefinition.field( + key: Product.NAME, + isRequired: true, + ofType: ModelFieldType(ModelFieldTypeEnum.string))); + + modelSchemaDefinition.addField(ModelFieldDefinition.field( + key: Product.AMOUNT, + isRequired: true, + ofType: ModelFieldType(ModelFieldTypeEnum.int))); + + modelSchemaDefinition.addField(ModelFieldDefinition.nonQueryField( + fieldName: 'createdAt', + isRequired: false, + isReadOnly: true, + ofType: ModelFieldType(ModelFieldTypeEnum.dateTime))); + + modelSchemaDefinition.addField(ModelFieldDefinition.nonQueryField( + fieldName: 'updatedAt', + isRequired: false, + isReadOnly: true, + ofType: ModelFieldType(ModelFieldTypeEnum.dateTime))); + }); +} + +class _ProductModelType extends ModelType { + const _ProductModelType(); + + @override + Product fromJson(Map jsonData) { + return Product.fromJson(jsonData); + } +} + +/// This is an auto generated class representing the model identifier +/// of [Product] in your schema. +@immutable +class ProductModelIdentifier implements ModelIdentifier { + final String productID; + + /// Create an instance of ProductModelIdentifier using [productID] the primary key. + const ProductModelIdentifier({required this.productID}); + + @override + Map serializeAsMap() => + ({'productID': productID}); + + @override + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + @override + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'ProductModelIdentifier(productID: $productID)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is ProductModelIdentifier && productID == other.productID; + } + + @override + int get hashCode => productID.hashCode; +} diff --git a/packages/amplify_test/lib/test_models/S3Object.dart b/packages/amplify_test/lib/test_models/S3Object.dart index 774a357c11..3c60c68cee 100644 --- a/packages/amplify_test/lib/test_models/S3Object.dart +++ b/packages/amplify_test/lib/test_models/S3Object.dart @@ -13,13 +13,17 @@ * permissions and limitations under the License. */ +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + // ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code, implicit_dynamic_parameter, implicit_dynamic_map_literal, implicit_dynamic_type import 'ModelProvider.dart'; import 'package:amplify_core/amplify_core.dart'; import 'package:flutter/foundation.dart'; -/** This is an auto generated class representing the S3Object type in your schema. */ +/// This is an auto generated class representing the S3Object type in your schema. @immutable class S3Object { final String? _bucket; @@ -31,7 +35,7 @@ class S3Object { try { return _bucket!; } catch (e) { - throw new AmplifyCodeGenModelException( + throw AmplifyCodeGenModelException( AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, recoverySuggestion: AmplifyExceptionMessages @@ -44,7 +48,7 @@ class S3Object { try { return _region!; } catch (e) { - throw new AmplifyCodeGenModelException( + throw AmplifyCodeGenModelException( AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, recoverySuggestion: AmplifyExceptionMessages @@ -57,7 +61,7 @@ class S3Object { try { return _key!; } catch (e) { - throw new AmplifyCodeGenModelException( + throw AmplifyCodeGenModelException( AmplifyExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, recoverySuggestion: AmplifyExceptionMessages @@ -105,7 +109,7 @@ class S3Object { @override String toString() { - var buffer = new StringBuffer(); + var buffer = StringBuffer(); buffer.write("S3Object {"); buffer.write("bucket=" + "$_bucket" + ", "); @@ -132,7 +136,7 @@ class S3Object { _key = json['key'], _meta = json['meta']?['serializedData'] != null ? FileMeta.fromJson( - new Map.from(json['meta']['serializedData'])) + Map.from(json['meta']['serializedData'])) : null; Map toJson() => { diff --git a/packages/amplify_test/lib/test_models/StringListTypeModel.dart b/packages/amplify_test/lib/test_models/StringListTypeModel.dart new file mode 100644 index 0000000000..42be203519 --- /dev/null +++ b/packages/amplify_test/lib/test_models/StringListTypeModel.dart @@ -0,0 +1,200 @@ +/* +* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. +* +* Licensed under the Apache License, Version 2.0 (the "License"). +* You may not use this file except in compliance with the License. +* A copy of the License is located at +* +* http://aws.amazon.com/apache2.0 +* +* or in the "license" file accompanying this file. This file is distributed +* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +* express or implied. See the License for the specific language governing +* permissions and limitations under the License. +*/ + +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, annotate_overrides, dead_code, dead_codepublic_member_api_docs, depend_on_referenced_packages, file_names, library_private_types_in_public_api, no_leading_underscores_for_library_prefixes, no_leading_underscores_for_local_identifiers, non_constant_identifier_names, null_check_on_nullable_type_parameter, prefer_adjacent_string_concatenation, prefer_const_constructors, prefer_if_null_operators, prefer_interpolation_to_compose_strings, slash_for_doc_comments, sort_child_properties_last, unnecessary_const, unnecessary_constructor_name, unnecessary_late, unnecessary_new, unnecessary_null_aware_assignments, unnecessary_nullable_for_final_variable_declarations, unnecessary_string_interpolations, use_build_context_synchronously + +import 'package:amplify_core/amplify_core.dart'; +import 'package:collection/collection.dart'; +import 'package:flutter/foundation.dart'; + +/// This is an auto generated class representing the StringListTypeModel type in your schema. +@immutable +class StringListTypeModel extends Model { + static const classType = _StringListTypeModelModelType(); + final String id; + final List? _value; + final TemporalDateTime? _createdAt; + final TemporalDateTime? _updatedAt; + + @override + getInstanceType() => classType; + + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') + @override + String getId() => id; + + StringListTypeModelModelIdentifier get modelIdentifier { + return StringListTypeModelModelIdentifier(id: id); + } + + List? get value { + return _value; + } + + TemporalDateTime? get createdAt { + return _createdAt; + } + + TemporalDateTime? get updatedAt { + return _updatedAt; + } + + const StringListTypeModel._internal( + {required this.id, value, createdAt, updatedAt}) + : _value = value, + _createdAt = createdAt, + _updatedAt = updatedAt; + + factory StringListTypeModel({String? id, List? value}) { + return StringListTypeModel._internal( + id: id == null ? UUID.getUUID() : id, + value: value != null ? List.unmodifiable(value) : value); + } + + bool equals(Object other) { + return this == other; + } + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is StringListTypeModel && + id == other.id && + DeepCollectionEquality().equals(_value, other._value); + } + + @override + int get hashCode => toString().hashCode; + + @override + String toString() { + var buffer = StringBuffer(); + + buffer.write("StringListTypeModel {"); + buffer.write("id=" + "$id" + ", "); + buffer.write( + "value=" + (_value != null ? _value!.toString() : "null") + ", "); + buffer.write("createdAt=" + + (_createdAt != null ? _createdAt!.format() : "null") + + ", "); + buffer.write( + "updatedAt=" + (_updatedAt != null ? _updatedAt!.format() : "null")); + buffer.write("}"); + + return buffer.toString(); + } + + StringListTypeModel copyWith({List? value}) { + return StringListTypeModel._internal(id: id, value: value ?? this.value); + } + + StringListTypeModel.fromJson(Map json) + : id = json['id'], + _value = json['value']?.cast(), + _createdAt = json['createdAt'] != null + ? TemporalDateTime.fromString(json['createdAt']) + : null, + _updatedAt = json['updatedAt'] != null + ? TemporalDateTime.fromString(json['updatedAt']) + : null; + + Map toJson() => { + 'id': id, + 'value': _value, + 'createdAt': _createdAt?.format(), + 'updatedAt': _updatedAt?.format() + }; + + static final QueryField ID = QueryField(fieldName: "stringListTypeModel.id"); + static final QueryField VALUE = QueryField(fieldName: "value"); + static var schema = + Model.defineSchema(define: (ModelSchemaDefinition modelSchemaDefinition) { + modelSchemaDefinition.name = "StringListTypeModel"; + modelSchemaDefinition.pluralName = "StringListTypeModels"; + + modelSchemaDefinition.addField(ModelFieldDefinition.id()); + + modelSchemaDefinition.addField(ModelFieldDefinition.field( + key: StringListTypeModel.VALUE, + isRequired: false, + isArray: true, + ofType: ModelFieldType(ModelFieldTypeEnum.collection, + ofModelName: describeEnum(ModelFieldTypeEnum.string)))); + + modelSchemaDefinition.addField(ModelFieldDefinition.nonQueryField( + fieldName: 'createdAt', + isRequired: false, + isReadOnly: true, + ofType: ModelFieldType(ModelFieldTypeEnum.dateTime))); + + modelSchemaDefinition.addField(ModelFieldDefinition.nonQueryField( + fieldName: 'updatedAt', + isRequired: false, + isReadOnly: true, + ofType: ModelFieldType(ModelFieldTypeEnum.dateTime))); + }); +} + +class _StringListTypeModelModelType extends ModelType { + const _StringListTypeModelModelType(); + + @override + StringListTypeModel fromJson(Map jsonData) { + return StringListTypeModel.fromJson(jsonData); + } +} + +/// This is an auto generated class representing the model identifier +/// of [StringListTypeModel] in your schema. +@immutable +class StringListTypeModelModelIdentifier + implements ModelIdentifier { + final String id; + + /// Create an instance of StringListTypeModelModelIdentifier using [id] the primary key. + const StringListTypeModelModelIdentifier({required this.id}); + + @override + Map serializeAsMap() => ({'id': id}); + + @override + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + @override + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'StringListTypeModelModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is StringListTypeModelModelIdentifier && id == other.id; + } + + @override + int get hashCode => id.hashCode; +} diff --git a/packages/amplify_test/lib/test_models/Warehouse.dart b/packages/amplify_test/lib/test_models/Warehouse.dart new file mode 100644 index 0000000000..5742e82e0c --- /dev/null +++ b/packages/amplify_test/lib/test_models/Warehouse.dart @@ -0,0 +1,251 @@ +/* +* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. +* +* Licensed under the Apache License, Version 2.0 (the "License"). +* You may not use this file except in compliance with the License. +* A copy of the License is located at +* +* http://aws.amazon.com/apache2.0 +* +* or in the "license" file accompanying this file. This file is distributed +* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +* express or implied. See the License for the specific language governing +* permissions and limitations under the License. +*/ + +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code, implicit_dynamic_parameter, implicit_dynamic_map_literal, implicit_dynamic_type + +import 'package:amplify_core/amplify_core.dart'; +import 'package:flutter/foundation.dart'; + +/// This is an auto generated class representing the Warehouse type in your schema. +@immutable +class Warehouse extends Model { + static const classType = _WarehouseModelType(); + final String id; + final String? _name; + final String? _region; + final TemporalDateTime? _createdAt; + final TemporalDateTime? _updatedAt; + + @override + getInstanceType() => classType; + + @Deprecated( + '[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') + @override + String getId() => id; + + WarehouseModelIdentifier get modelIdentifier { + try { + return WarehouseModelIdentifier(id: id, name: _name!, region: _region!); + } catch (e) { + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages + .codeGenRequiredFieldForceCastExceptionMessage, + recoverySuggestion: AmplifyExceptionMessages + .codeGenRequiredFieldForceCastRecoverySuggestion, + underlyingException: e.toString()); + } + } + + String get name { + try { + return _name!; + } catch (e) { + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages + .codeGenRequiredFieldForceCastExceptionMessage, + recoverySuggestion: AmplifyExceptionMessages + .codeGenRequiredFieldForceCastRecoverySuggestion, + underlyingException: e.toString()); + } + } + + String get region { + try { + return _region!; + } catch (e) { + throw AmplifyCodeGenModelException( + AmplifyExceptionMessages + .codeGenRequiredFieldForceCastExceptionMessage, + recoverySuggestion: AmplifyExceptionMessages + .codeGenRequiredFieldForceCastRecoverySuggestion, + underlyingException: e.toString()); + } + } + + TemporalDateTime? get createdAt { + return _createdAt; + } + + TemporalDateTime? get updatedAt { + return _updatedAt; + } + + const Warehouse._internal( + {required this.id, required name, required region, createdAt, updatedAt}) + : _name = name, + _region = region, + _createdAt = createdAt, + _updatedAt = updatedAt; + + factory Warehouse( + {String? id, required String name, required String region}) { + return Warehouse._internal( + id: id == null ? UUID.getUUID() : id, name: name, region: region); + } + + bool equals(Object other) { + return this == other; + } + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Warehouse && + id == other.id && + _name == other._name && + _region == other._region; + } + + @override + int get hashCode => toString().hashCode; + + @override + String toString() { + var buffer = StringBuffer(); + + buffer.write("Warehouse {"); + buffer.write("id=" + "$id" + ", "); + buffer.write("name=" + "$_name" + ", "); + buffer.write("region=" + "$_region" + ", "); + buffer.write("createdAt=" + + (_createdAt != null ? _createdAt!.format() : "null") + + ", "); + buffer.write( + "updatedAt=" + (_updatedAt != null ? _updatedAt!.format() : "null")); + buffer.write("}"); + + return buffer.toString(); + } + + Warehouse copyWith() { + return Warehouse._internal(id: id, name: name, region: region); + } + + Warehouse.fromJson(Map json) + : id = json['id'], + _name = json['name'], + _region = json['region'], + _createdAt = json['createdAt'] != null + ? TemporalDateTime.fromString(json['createdAt']) + : null, + _updatedAt = json['updatedAt'] != null + ? TemporalDateTime.fromString(json['updatedAt']) + : null; + + Map toJson() => { + 'id': id, + 'name': _name, + 'region': _region, + 'createdAt': _createdAt?.format(), + 'updatedAt': _updatedAt?.format() + }; + + static final QueryField ID = QueryField(fieldName: "warehouse.id"); + static final QueryField NAME = QueryField(fieldName: "name"); + static final QueryField REGION = QueryField(fieldName: "region"); + static var schema = + Model.defineSchema(define: (ModelSchemaDefinition modelSchemaDefinition) { + modelSchemaDefinition.name = "Warehouse"; + modelSchemaDefinition.pluralName = "Warehouses"; + + modelSchemaDefinition.indexes = [ + ModelIndex(fields: const ["id", "name", "region"], name: null) + ]; + + modelSchemaDefinition.addField(ModelFieldDefinition.id()); + + modelSchemaDefinition.addField(ModelFieldDefinition.field( + key: Warehouse.NAME, + isRequired: true, + ofType: ModelFieldType(ModelFieldTypeEnum.string))); + + modelSchemaDefinition.addField(ModelFieldDefinition.field( + key: Warehouse.REGION, + isRequired: true, + ofType: ModelFieldType(ModelFieldTypeEnum.string))); + + modelSchemaDefinition.addField(ModelFieldDefinition.nonQueryField( + fieldName: 'createdAt', + isRequired: false, + isReadOnly: true, + ofType: ModelFieldType(ModelFieldTypeEnum.dateTime))); + + modelSchemaDefinition.addField(ModelFieldDefinition.nonQueryField( + fieldName: 'updatedAt', + isRequired: false, + isReadOnly: true, + ofType: ModelFieldType(ModelFieldTypeEnum.dateTime))); + }); +} + +class _WarehouseModelType extends ModelType { + const _WarehouseModelType(); + + @override + Warehouse fromJson(Map jsonData) { + return Warehouse.fromJson(jsonData); + } +} + +/// This is an auto generated class representing the model identifier +/// of [Warehouse] in your schema. +@immutable +class WarehouseModelIdentifier implements ModelIdentifier { + final String id; + final String name; + final String region; + + /// Create an instance of WarehouseModelIdentifier using [id] the primary key. + /// And [name], [region] the sort keys. + const WarehouseModelIdentifier( + {required this.id, required this.name, required this.region}); + + @override + Map serializeAsMap() => + ({'id': id, 'name': name, 'region': region}); + + @override + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({entry.key: entry.value})) + .toList(); + + @override + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => + 'WarehouseModelIdentifier(id: $id, name: $name, region: $region)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is WarehouseModelIdentifier && + id == other.id && + name == other.name && + region == other.region; + } + + @override + int get hashCode => id.hashCode ^ name.hashCode ^ region.hashCode; +} diff --git a/packages/amplify_datastore_plugin_interface/test/testData/testData_schema.graphql b/packages/amplify_test/lib/test_models/schema.graphql similarity index 54% rename from packages/amplify_datastore_plugin_interface/test/testData/testData_schema.graphql rename to packages/amplify_test/lib/test_models/schema.graphql index 67ed6171a9..cd2e95f5d8 100644 --- a/packages/amplify_datastore_plugin_interface/test/testData/testData_schema.graphql +++ b/packages/amplify_test/lib/test_models/schema.graphql @@ -1,7 +1,24 @@ -# This schema can be used to regenerate the test models that are in this folder +input AMPLIFY { + globalAuthRule: AuthRule = { allow: public } +} + +type FileMeta { + name: String! +} + +type S3Object { + bucket: String! + region: String! + key: String! + meta: FileMeta +} + type Blog @model { id: ID! @primaryKey name: String! + createdAt: AWSDateTime + file: S3Object + files: [S3Object] posts: [Post] @hasMany(indexName: "byBlog", fields: ["id"]) } @@ -16,25 +33,29 @@ type Post @model { comments: [Comment] @hasMany(indexName: "byPost", fields: ["id"]) } -type PostAuthComplex +type Comment @model { + id: ID! + postID: ID! @index(name: "byPost", sortKeyFields: ["content"]) + post: Post @belongsTo(fields: ["postID"]) + content: String! +} + +type PostWithAuthRules @model @auth( rules: [ - { allow: owner, ownerField: "owner", operations: [create, update, delete, read] }, - ]) -{ + { + allow: owner + ownerField: "owner" + operations: [create, update, delete, read] + } + ] + ) { id: ID! title: String! owner: String } -type Comment @model { - id: ID! - postID: ID! @index(name: "byPost", sortKeyFields: ["content"]) - post: Post @belongsTo(fields: ["postID"]) - content: String! -} - type Address { line1: String! line2: String @@ -59,3 +80,23 @@ type Contact { phone: Phone! mailingAddresses: [Address] } + +type Product @model { + productID: ID! @primaryKey + name: String! + amount: Int! +} + +type Inventory @model { + productID: String! + @primaryKey(sortKeyFields: ["name", "warehouseID", "region"]) + name: String! + warehouseID: ID! + region: String! +} + +type Warehouse @model { + id: ID! @primaryKey(sortKeyFields: ["name", "region"]) + name: String! + region: String! +} diff --git a/packages/amplify_test/pubspec.yaml b/packages/amplify_test/pubspec.yaml index 1a06bcede5..32ef379c7b 100644 --- a/packages/amplify_test/pubspec.yaml +++ b/packages/amplify_test/pubspec.yaml @@ -16,6 +16,7 @@ dependencies: amplify_auth_cognito: ^0.4.3 amplify_flutter: ^0.4.3 stream_transform: ^2.0.0 + collection: ^1.15.0 dev_dependencies: amplify_lints: ^1.0.0 diff --git a/packages/api/amplify_api/example/tool/schema.graphql b/packages/api/amplify_api/example/tool/schema.graphql index 52f4e34974..a45310699a 100644 --- a/packages/api/amplify_api/example/tool/schema.graphql +++ b/packages/api/amplify_api/example/tool/schema.graphql @@ -27,6 +27,7 @@ type Post @model { title: String! rating: Int! created: AWSDateTime + likeCount: Int blogID: ID! @index(name: "byBlog") blog: Blog @belongsTo(fields: ["blogID"]) comments: [Comment] @hasMany(indexName: "byPost", fields: ["id"]) @@ -38,3 +39,44 @@ type Comment @model { post: Post @belongsTo(fields: ["postID"]) content: String! } + +type PostWithAuthRules + @model + @auth( + rules: [ + { + allow: owner + ownerField: "owner" + operations: [create, update, delete, read] + } + ] + ) { + id: ID! + title: String! + owner: String +} + +type Address { + line1: String! + line2: String + city: String! + state: String! + postalCode: String! +} + +type Person { + name: String! + propertiesAddresses: [Address] + contact: Contact! +} + +type Phone { + country: String! + number: String! +} + +type Contact { + email: String! + phone: Phone! + mailingAddresses: [Address] +} diff --git a/packages/api/amplify_api/test/graphql_helpers_test.dart b/packages/api/amplify_api/test/graphql_helpers_test.dart index 9d78d58d0b..5e57cb5c08 100644 --- a/packages/api/amplify_api/test/graphql_helpers_test.dart +++ b/packages/api/amplify_api/test/graphql_helpers_test.dart @@ -362,11 +362,12 @@ void main() { 'title': title, 'rating': rating, 'created': null, + 'likeCount': null, 'blogID': blogId } }; const expectedDoc = - 'mutation createPost(\$input: CreatePostInput!, \$condition: ModelPostConditionInput) { createPost(input: \$input, condition: \$condition) { id title rating created createdAt updatedAt blog { $blogSelectionSet } } }'; + 'mutation createPost(\$input: CreatePostInput!, \$condition: ModelPostConditionInput) { createPost(input: \$input, condition: \$condition) { id title rating created likeCount createdAt updatedAt blog { $blogSelectionSet } } }'; GraphQLRequest req = ModelMutations.create(post); expect(req.document, expectedDoc); @@ -481,12 +482,13 @@ void main() { 'title': title, 'rating': rating, 'created': null, + 'likeCount': null, 'blogID': blogId }, 'condition': null }; const expectedDoc = - 'mutation updatePost(\$input: UpdatePostInput!, \$condition: ModelPostConditionInput) { updatePost(input: \$input, condition: \$condition) { id title rating created createdAt updatedAt blog { $blogSelectionSet } } }'; + 'mutation updatePost(\$input: UpdatePostInput!, \$condition: ModelPostConditionInput) { updatePost(input: \$input, condition: \$condition) { id title rating created likeCount createdAt updatedAt blog { $blogSelectionSet } } }'; GraphQLRequest req = ModelMutations.update(post); expect(req.document, expectedDoc); diff --git a/packages/api/amplify_api_plugin_interface/lib/src/types/pagination/paginated_result.dart b/packages/api/amplify_api_plugin_interface/lib/src/types/pagination/paginated_result.dart index 0a58d8b3a3..7fd2f28bfd 100644 --- a/packages/api/amplify_api_plugin_interface/lib/src/types/pagination/paginated_result.dart +++ b/packages/api/amplify_api_plugin_interface/lib/src/types/pagination/paginated_result.dart @@ -17,6 +17,23 @@ import 'package:amplify_core/amplify_core.dart'; import '../../types.dart'; +class _DummyModelIdentifier implements ModelIdentifier { + final List> emptyList = const []; + final Map emptyMap = const {}; + final String emptyString = ''; + + const _DummyModelIdentifier(); + + @override + List> serializeAsList() => emptyList; + + @override + Map serializeAsMap() => emptyMap; + + @override + String serializeAsString() => emptyString; +} + class PaginatedResult extends Model { /// Model instances for this set of results. /// @@ -43,6 +60,11 @@ class PaginatedResult extends Model { return ''; } + @override + ModelIdentifier get modelIdentifier { + return const _DummyModelIdentifier(); + } + /// Returns `true` if there is more data to fetch beyond the data /// contained in this response. If `true`, the request for the next page of /// data can be obtained with `.requestForNextResult`.