Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "chore(amplify_core): move model-related types from datastore interface to amplify_core" #1102

Merged
merged 1 commit into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 1 addition & 22 deletions packages/amplify_core/lib/amplify_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,13 @@ library amplify_core;
export 'src/types/exception/amplify_already_configured_exception.dart';
export 'src/types/exception/amplify_exception.dart';
export 'src/types/exception/amplify_exception_messages.dart';
export 'src/types/exception/codegen_exception.dart';

/// Hub
export 'src/types/hub/hub_channel.dart';
export 'src/types/hub/hub_event.dart';
export 'src/types/hub/hub_event_payload.dart';

/// Model-based types used in datastore and API
export 'src/types/models/auth_rule.dart';
export 'src/types/models/model.dart';
export 'src/types/models/model_association.dart';
export 'src/types/models/model_field.dart';
export 'src/types/models/model_field_definition.dart';
export 'src/types/models/model_field_type.dart';
export 'src/types/models/model_provider.dart';
export 'src/types/models/model_schema.dart';
export 'src/types/models/model_schema_definition.dart';
export 'src/types/query/query_field.dart';
export 'src/types/temporal/datetime_parse.dart';
export 'src/types/temporal/temporal_date.dart';
export 'src/types/temporal/temporal_datetime.dart';
export 'src/types/temporal/temporal_time.dart';
export 'src/types/temporal/temporal_timestamp.dart';
export 'src/types/plugin/amplify_plugin_interface.dart';

// Util
export 'src/util/parsers.dart';
export 'src/util/print.dart';
export 'src/util/uuid.dart';

// ignore: directives_ordering
export 'src/types/plugin/amplify_plugin_interface.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,4 @@ class AmplifyExceptionMessages {

static const nullReturnedFromMethodChannel =
'The value returned from the MethodChannel is null';

static const codeGenRequiredFieldForceCastExceptionMessage =
// ignore: missing_whitespace_between_adjacent_strings
'The field you are accessing is not nullable but has a null value.'
'It was marked as required (!) in your schema.graphql but the containing model class was initialized without setting its value.';

static const codeGenRequiredFieldForceCastRecoverySuggestion =
// ignore: missing_whitespace_between_adjacent_strings
'Please validate that the containing model class was initialized properly with all requried fields being initialized.'
'This can happen when a nested model is returned but only its id field has been set';
}

This file was deleted.

28 changes: 28 additions & 0 deletions packages/amplify_core/lib/src/util/json.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 'dart:convert';
import 'dart:io';

dynamic getJsonFromFile(String path) async {
path = 'resources/' + path;
String jsonString = '';
try {
jsonString = await File(path).readAsString();
} catch (e) {
jsonString = await File('test/' + path).readAsString();
}
return jsonDecode(jsonString);
}
3 changes: 1 addition & 2 deletions packages/amplify_core/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ environment:

dependencies:
plugin_platform_interface: ^2.0.0
meta: ^1.3.0
flutter:
sdk: flutter
date_time_format: ^2.0.1
meta: ^1.3.0
uuid: ^3.0.1

dev_dependencies:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,29 @@ library amplify_datastore_plugin_interface;

import 'dart:async';

import 'package:amplify_datastore_plugin_interface/src/types/models/model_provider.dart';
import 'package:amplify_core/amplify_core.dart';
import 'package:meta/meta.dart';

import 'src/types/models/model.dart';
import 'src/types/models/observe_query_throttle_options.dart';
import 'src/types/models/query_snapshot.dart';
import 'src/types/models/subscription_event.dart';
import 'src/types/sync/DataStoreSyncExpression.dart';
import 'src/types/query/query_field.dart';

export 'src/types/models/auth_rule.dart';
export 'src/types/models/model.dart';
export 'src/types/models/model_field.dart';
export 'src/types/models/model_field_definition.dart';
export 'src/types/models/model_field_type.dart';
export 'src/types/models/model_provider.dart';
export 'src/types/models/model_schema.dart';
export 'src/types/models/model_schema_definition.dart';
export 'src/types/models/uuid.dart';
export 'src/types/query/query_field.dart';
export 'src/types/temporal/datetime_parse.dart';
export 'src/types/utils/parsers.dart';

export 'src/publicTypes.dart';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
export 'package:amplify_core/src/types/models/auth_rule.dart';
export 'package:amplify_core/src/types/models/model.dart';
export 'package:amplify_core/src/types/models/model_field.dart';
export 'package:amplify_core/src/types/models/model_field_definition.dart';
export 'package:amplify_core/src/types/models/model_field_type.dart';
export 'package:amplify_core/src/types/models/model_provider.dart';
export 'package:amplify_core/src/types/models/model_schema.dart';
export 'package:amplify_core/src/types/models/model_schema_definition.dart';
export 'package:amplify_core/src/types/query/query_field.dart';
export 'package:amplify_core/src/types/query/query_field.dart';
export 'package:amplify_core/src/types/temporal/datetime_parse.dart';
export 'package:amplify_core/src/types/temporal/temporal_date.dart';
export 'package:amplify_core/src/types/temporal/temporal_datetime.dart';
export 'package:amplify_core/src/types/temporal/temporal_time.dart';
export 'package:amplify_core/src/types/temporal/temporal_timestamp.dart';
export 'package:amplify_core/src/util/parsers.dart';
export 'package:amplify_core/src/util/uuid.dart';

export 'types/exception/DataStoreException.dart';
export 'types/exception/DataStoreExceptionMessages.dart';
export 'types/models/observe_query_throttle_options.dart';
export 'types/models/query_snapshot.dart';
export 'types/models/subscription_event.dart';
export 'types/models/query_snapshot.dart';
export 'types/models/observe_query_throttle_options.dart';
export 'types/sync/DataStoreSyncExpression.dart';
export 'types/temporal/temporal_date.dart';
export 'types/temporal/temporal_time.dart';
export 'types/temporal/temporal_datetime.dart';
export 'types/temporal/temporal_timestamp.dart';
export 'types/query/query_field.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class AuthRule {
}

Map<String, dynamic> toMap() {
final map = {
Map<String, dynamic> map = {
'authStrategy': describeEnum(authStrategy),
'ownerField': ownerField,
'identityClaim': identityClaim,
Expand All @@ -77,8 +77,7 @@ class AuthRule {
'provider': provider != null ? describeEnum(provider!) : null,
'operations': operations?.map((x) => describeEnum(x)).toList(),
};
return Map<String, dynamic>.from(map)
..removeWhere((k, dynamic v) => v == null);
return Map.from(map)..removeWhere((k, v) => v == null);
}

factory AuthRule.fromMap(Map<String, dynamic> map) {
Expand All @@ -91,7 +90,7 @@ class AuthRule {
groupsField: map['groupsField'],
provider: map['provider'],
operations: List<ModelOperation>.from(
map['operations']?.map((dynamic x) => ModelOperation.values[x])));
map['operations']?.map((x) => ModelOperation.values[x])));
}

String toJson() => json.encode(toMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@ class ModelAssociation {
}

Map<String, dynamic> toMap() {
final map = {
Map<String, dynamic> map = {
'associationType': describeEnum(associationType),
'targetName': targetName,
'associatedName': associatedName,
'associatedType': associatedType,
};
return Map<String, dynamic>.from(map)
..removeWhere((k, dynamic v) => v == null);
return Map.from(map)..removeWhere((k, v) => v == null);
}

factory ModelAssociation.fromMap(Map<String, dynamic> map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class ModelField {
}

Map<String, dynamic> toMap() {
final map = {
Map<String, dynamic> map = {
'name': name,
'type': type.toMap(),
'isRequired': isRequired,
Expand All @@ -81,8 +81,7 @@ class ModelField {
'association': association?.toMap(),
'authRules': authRules?.map((x) => x.toMap()).toList(),
};
return Map<String, dynamic>.from(map)
..removeWhere((k, dynamic v) => v == null);
return Map.from(map)..removeWhere((k, v) => v == null);
}

factory ModelField.fromMap(Map<String, dynamic> map) {
Expand All @@ -96,7 +95,7 @@ class ModelField {
map['association'] ?? ModelAssociation.fromMap(map['association']),
authRules: map['authRules'] ??
List<AuthRule>.from(
map['authRules']?.map((dynamic x) => AuthRule.fromMap(x))),
map['authRules']?.map((x) => AuthRule.fromMap(x))),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* permissions and limitations under the License.
*/

import 'package:amplify_core/amplify_core.dart';
import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart';

import 'auth_rule.dart';
import 'model_association.dart';
Expand Down Expand Up @@ -174,7 +174,7 @@ class ModelFieldDefinition {
associatedType: associatedType));
}

ModelField build() {
build() {
return ModelField(
name: name,
type: type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ModelFieldType {
{this.ofModelName, this.ofCustomTypeName});

Map<String, dynamic> toMap() {
return <String, dynamic>{
return {
'fieldType': describeEnum(fieldType),
if (ofModelName != null) 'ofModelName': ofModelName,
if (ofCustomTypeName != null) 'ofCustomTypeName': ofCustomTypeName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
import 'model.dart';
import 'package:amplify_datastore_plugin_interface/src/types/models/model.dart';

import 'model_schema.dart';

abstract class ModelProviderInterface {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,21 @@ class ModelSchema {
}

Map<String, dynamic> toMap() {
final map = {
Map<String, dynamic> map = {
'name': name,
'pluralName': pluralName,
'authRules': authRules?.map((x) => x.toMap()).toList(),
'fields': fields?.map((key, value) => MapEntry('$key', value.toMap())),
};
return Map<String, dynamic>.from(map)
..removeWhere((k, dynamic v) => v == null);
return Map.from(map)..removeWhere((k, v) => v == null);
}

factory ModelSchema.fromMap(Map<String, dynamic> map) {
return ModelSchema(
name: map['name'],
pluralName: map['pluralName'],
authRules: List<AuthRule>.from(
map['authRules']?.map((dynamic x) => AuthRule.fromMap(x))),
map['authRules']?.map((x) => AuthRule.fromMap(x))),
fields: Map<String, ModelField>.from(map['fields']),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@

library model;

import 'package:amplify_core/amplify_core.dart';
import 'package:amplify_datastore_plugin_interface/src/types/models/sorted_list.dart';
import 'package:amplify_datastore_plugin_interface/src/types/query/query_field.dart';

import 'model.dart';

import 'sorted_list.dart';
import 'subscription_event.dart';

/// {@template query_snapshot}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@

library model;

import 'package:amplify_core/amplify_core.dart';
import 'package:flutter/foundation.dart';

import 'model.dart';

/// {@template subscription_event}
/// An event containing the details of mutations that have occurred on the backend
/// {@endtemplate}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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 'package:uuid/uuid.dart';

class UUID {
static final _internal = Uuid();

static String getUUID() {
return _internal.v4();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@

library query_field;

import 'package:amplify_core/amplify_core.dart';

import '../../util/parsers.dart';
import '../models/model_field_type.dart';
import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart';
import 'package:amplify_datastore_plugin_interface/src/types/models/model_field_type.dart';
import '../temporal/datetime_parse.dart';
import '../utils/parsers.dart';

part 'query_field_operators.dart';
part 'query_pagination.dart';
Expand Down
Loading