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

Feat/custom pk flutter impl #394

Merged

Conversation

HuiSF
Copy link
Member

@HuiSF HuiSF commented Feb 23, 2022

Description of changes

Issue #, if available

aws-amplify/amplify-flutter#1426

Description of how you validated changes

Sample of generate model with a custom PK Schema
type Inventory @model {
  productId: ID! @primaryKey(sortKeyFields: ["productName", "warehouseId", "region"])
  productName: String!
  warehouseId: ID! @index(name: "byWarehouse", sortKeyFields: ["region"])
  region: String!
}

Generated Dart model

/*
* 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 '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 = const _InventoryModelType();
  final String? _productId;
  final String? _productName;
  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!,
          productName: _productName!,
          warehouseId: _warehouseId!,
          region: _region!);
    } catch (e) {
      throw new DataStoreException(
          DataStoreExceptionMessages
              .codeGenRequiredFieldForceCastExceptionMessage,
          recoverySuggestion: DataStoreExceptionMessages
              .codeGenRequiredFieldForceCastRecoverySuggestion,
          underlyingException: e.toString());
    }
  }

  String get productId {
    try {
      return _productId!;
    } catch (e) {
      throw new DataStoreException(
          DataStoreExceptionMessages
              .codeGenRequiredFieldForceCastExceptionMessage,
          recoverySuggestion: DataStoreExceptionMessages
              .codeGenRequiredFieldForceCastRecoverySuggestion,
          underlyingException: e.toString());
    }
  }

  String get productName {
    try {
      return _productName!;
    } catch (e) {
      throw new DataStoreException(
          DataStoreExceptionMessages
              .codeGenRequiredFieldForceCastExceptionMessage,
          recoverySuggestion: DataStoreExceptionMessages
              .codeGenRequiredFieldForceCastRecoverySuggestion,
          underlyingException: e.toString());
    }
  }

  String get warehouseId {
    try {
      return _warehouseId!;
    } catch (e) {
      throw new DataStoreException(
          DataStoreExceptionMessages
              .codeGenRequiredFieldForceCastExceptionMessage,
          recoverySuggestion: DataStoreExceptionMessages
              .codeGenRequiredFieldForceCastRecoverySuggestion,
          underlyingException: e.toString());
    }
  }

  String get region {
    try {
      return _region!;
    } catch (e) {
      throw new DataStoreException(
          DataStoreExceptionMessages
              .codeGenRequiredFieldForceCastExceptionMessage,
          recoverySuggestion: DataStoreExceptionMessages
              .codeGenRequiredFieldForceCastRecoverySuggestion,
          underlyingException: e.toString());
    }
  }

  TemporalDateTime? get createdAt {
    return _createdAt;
  }

  TemporalDateTime? get updatedAt {
    return _updatedAt;
  }

  const Inventory._internal(
      {required productId,
      required productName,
      required warehouseId,
      required region,
      createdAt,
      updatedAt})
      : _productId = productId,
        _productName = productName,
        _warehouseId = warehouseId,
        _region = region,
        _createdAt = createdAt,
        _updatedAt = updatedAt;

  factory Inventory(
      {required String productId,
      required String productName,
      required String warehouseId,
      required String region}) {
    return Inventory._internal(
        productId: productId,
        productName: productName,
        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 &&
        _productName == other._productName &&
        _warehouseId == other._warehouseId &&
        _region == other._region;
  }

  @override
  int get hashCode => toString().hashCode;

  @override
  String toString() {
    var buffer = new StringBuffer();

    buffer.write("Inventory {");
    buffer.write("productId=" + "$_productId" + ", ");
    buffer.write("productName=" + "$_productName" + ", ");
    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,
        productName: productName,
        warehouseId: warehouseId,
        region: region);
  }

  Inventory.fromJson(Map<String, dynamic> json)
      : _productId = json['productId'],
        _productName = json['productName'],
        _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<String, dynamic> toJson() => {
        'productId': _productId,
        'productName': _productName,
        'warehouseId': _warehouseId,
        'region': _region,
        'createdAt': _createdAt?.format(),
        'updatedAt': _updatedAt?.format()
      };

  static final QueryField PRODUCTID = QueryField(fieldName: "productId");
  static final QueryField PRODUCTNAME = QueryField(fieldName: "productName");
  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", "productName", "warehouseId", "region"],
          name: null),
      ModelIndex(fields: const ["warehouseId", "region"], name: "byWarehouse")
    ];

    modelSchemaDefinition.addField(ModelFieldDefinition.field(
        key: Inventory.PRODUCTID,
        isRequired: true,
        ofType: ModelFieldType(ModelFieldTypeEnum.string)));

    modelSchemaDefinition.addField(ModelFieldDefinition.field(
        key: Inventory.PRODUCTNAME,
        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<Inventory> {
  const _InventoryModelType();

  @override
  Inventory fromJson(Map<String, dynamic> jsonData) {
    return Inventory.fromJson(jsonData);
  }
}

/// This is an auto generated class representing the model identifier
/// of [Inventory] in your schema.
class InventoryModelIdentifier implements ModelIdentifier<Inventory> {
  final String productId;
  final String productName;
  final String warehouseId;
  final String region;

  /// Create an instance of InventoryModelIdentifier using [productId] the primary key.
  /// And [productName], [warehouseId], [region] the sort keys.
  const InventoryModelIdentifier(
      {required this.productId,
      required this.productName,
      required this.warehouseId,
      required this.region});

  Map<String, dynamic> serializeAsMap() {
    return {
      'productId': productId,
      'productName': productName,
      'warehouseId': warehouseId,
      'region': region
    };
  }

  List<Map<String, dynamic>> serializeAsList() {
    return [
      {'productId': productId},
      {'productName': productName},
      {'warehouseId': warehouseId},
      {'region': region}
    ];
  }

  String serializeAsString() => '$productId#$productName#$warehouseId#$region';

  @override
  String toString() =>
      'InventoryModelIdentifier(productId: $productId, productName: $productName, warehouseId: $warehouseId, region: $region)';

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) {
      return true;
    }

    return other is InventoryModelIdentifier &&
        productId == other.productId &&
        productName == other.productName &&
        warehouseId == other.warehouseId &&
        region == other.region;
  }

  @override
  int get hashCode =>
      productId.hashCode ^
      productName.hashCode ^
      warehouseId.hashCode ^
      region.hashCode;
}

Checklist

  • PR description included
  • yarn test passes
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)
  • Breaking changes to existing customers are released behind a feature flag or major version update
  • Changes are tested using sample applications for all relevant platforms (iOS/android/flutter/Javascript) that use the feature added/modified

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@lgtm-com
Copy link

lgtm-com bot commented Feb 23, 2022

This pull request introduces 1 alert when merging 2ce373d into 84831b5 - view on LGTM.com

new alerts:

  • 1 for Expression has no effect

@lgtm-com
Copy link

lgtm-com bot commented Feb 24, 2022

This pull request introduces 1 alert when merging 69c7f70 into 84831b5 - view on LGTM.com

new alerts:

  • 1 for Expression has no effect

@lgtm-com
Copy link

lgtm-com bot commented Mar 2, 2022

This pull request introduces 1 alert when merging 9c17617 into 84831b5 - view on LGTM.com

new alerts:

  • 1 for Expression has no effect

@HuiSF HuiSF marked this pull request as ready for review March 3, 2022 20:08
@HuiSF HuiSF requested a review from a team March 3, 2022 20:08
@lgtm-com
Copy link

lgtm-com bot commented Mar 3, 2022

This pull request introduces 1 alert when merging fee40d3 into 84831b5 - view on LGTM.com

new alerts:

  • 1 for Expression has no effect

@codecov-commenter
Copy link

codecov-commenter commented Mar 3, 2022

Codecov Report

❗ No coverage uploaded for pull request base (custom-pk-flutter@84831b5). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@                 Coverage Diff                  @@
##             custom-pk-flutter     #394   +/-   ##
====================================================
  Coverage                     ?   85.49%           
====================================================
  Files                        ?      145           
  Lines                        ?     6866           
  Branches                     ?     1781           
====================================================
  Hits                         ?     5870           
  Misses                       ?      905           
  Partials                     ?       91           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 84831b5...b255a18. Read the comment docs.

@lgtm-com
Copy link

lgtm-com bot commented Mar 3, 2022

This pull request introduces 1 alert when merging 38927cb into 84831b5 - view on LGTM.com

new alerts:

  • 1 for Expression has no effect

Copy link
Contributor

@AaronZyLee AaronZyLee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The custom PK change LGTM. I have some questions as follows:

  1. I notice some general changes such as changing the comment format to ///, removing the new keyword and adding const keyword. It is better to include the description for these if they are intended.
  2. For scenario where id is PK and sort key fields are defined, I can also see the sort keys are defined in the new model identifier class. However, they are not actually treated as a composite key type. I wonder what is the use case of it comparing to custom PK with SK.
  3. For the getting primary key info, see the comments below.

@@ -999,6 +1146,18 @@ export class AppSyncModelDartVisitor<
});
}

protected getModelIdentifierFields(model: CodeGenModel): CodeGenField[] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This method can work until the v1 transformer is deprecated(as @key is v1). In long term, this method can take advantage of the change in base visitor, where the model fields can be traversed to find pk field and corresponding pk type info (including pk type and sort key fields). The pk name can also be found as well.

const primaryKeyField = model.fields.find(field => field.primaryKeyInfo)!;
const { sortKeyFields } = primaryKeyField.primaryKeyInfo!

@HuiSF
Copy link
Member Author

HuiSF commented Mar 5, 2022

Thanks @AaronZyLee for reviewing -

  1. I notice some general changes such as changing the comment format to ///, removing the new keyword and adding const keyword. It is better to include the description for these if they are intended.

Yes is to conform Dart conventions. I will separate the change out as a separate PR.

  1. For scenario where id is PK and sort key fields are defined, I can also see the sort keys are defined in the new model identifier class. However, they are not actually treated as a composite key type. I wonder what is the use case of it comparing to custom PK with SK.

I wasn't aware of this scenario "where id is PK sort keys are not treated as a composite key type".
From what I understood, as long as a primary key (regardless the primary key filed is id or a custom field) and corresponding sort keys are defined in a model, the model always uses composite key as identifier.

  1. For the getting primary key info, see the comments below.

Will update the impl.

@lgtm-com
Copy link

lgtm-com bot commented Mar 7, 2022

This pull request introduces 1 alert when merging b255a18 into 84831b5 - view on LGTM.com

new alerts:

  • 1 for Expression has no effect

@HuiSF HuiSF requested a review from AaronZyLee March 9, 2022 20:53
Copy link
Contributor

@AaronZyLee AaronZyLee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you fix the bot alert? Otherwise LGTM

@HuiSF HuiSF requested a review from AaronZyLee March 9, 2022 22:49
@AaronZyLee AaronZyLee merged commit f673a6a into aws-amplify:custom-pk-flutter Mar 10, 2022
AaronZyLee pushed a commit that referenced this pull request May 23, 2022
* fix(appsync-dart-visitor): update broken test snapshot

* chore(appsync-dart-visitor): improve indexes generate following Dart lint rules

* feat(appsync-dart-visitor): generate custom PK supporting code

* Make custom PK fields immutable in copyWidth function

* Improve ModelIdentifier methods implementation

* Use the feature flag to control custom PK impl generation

* udpate snapshot for updated dart comment blocks

* Improve generated model identifier helper class

* Update existing unit test snapshots and add new tests for custom PK

* Remove unnecesary new initiating instances

* revert comment block changes

* Update the impl getting identifier fields

* Revert "Remove unnecesary new initiating instances"

This reverts commit 38927cb.

* Remove trash code...
AaronZyLee pushed a commit that referenced this pull request May 31, 2022
* fix(appsync-dart-visitor): update broken test snapshot

* chore(appsync-dart-visitor): improve indexes generate following Dart lint rules

* feat(appsync-dart-visitor): generate custom PK supporting code

* Make custom PK fields immutable in copyWidth function

* Improve ModelIdentifier methods implementation

* Use the feature flag to control custom PK impl generation

* udpate snapshot for updated dart comment blocks

* Improve generated model identifier helper class

* Update existing unit test snapshots and add new tests for custom PK

* Remove unnecesary new initiating instances

* revert comment block changes

* Update the impl getting identifier fields

* Revert "Remove unnecesary new initiating instances"

This reverts commit 38927cb.

* Remove trash code...
AaronZyLee pushed a commit that referenced this pull request Jun 2, 2022
* fix(appsync-dart-visitor): update broken test snapshot

* chore(appsync-dart-visitor): improve indexes generate following Dart lint rules

* feat(appsync-dart-visitor): generate custom PK supporting code

* Make custom PK fields immutable in copyWidth function

* Improve ModelIdentifier methods implementation

* Use the feature flag to control custom PK impl generation

* udpate snapshot for updated dart comment blocks

* Improve generated model identifier helper class

* Update existing unit test snapshots and add new tests for custom PK

* Remove unnecesary new initiating instances

* revert comment block changes

* Update the impl getting identifier fields

* Revert "Remove unnecesary new initiating instances"

This reverts commit 38927cb.

* Remove trash code...
AaronZyLee pushed a commit that referenced this pull request Jun 3, 2022
* fix(appsync-dart-visitor): update broken test snapshot

* chore(appsync-dart-visitor): improve indexes generate following Dart lint rules

* feat(appsync-dart-visitor): generate custom PK supporting code

* Make custom PK fields immutable in copyWidth function

* Improve ModelIdentifier methods implementation

* Use the feature flag to control custom PK impl generation

* udpate snapshot for updated dart comment blocks

* Improve generated model identifier helper class

* Update existing unit test snapshots and add new tests for custom PK

* Remove unnecesary new initiating instances

* revert comment block changes

* Update the impl getting identifier fields

* Revert "Remove unnecesary new initiating instances"

This reverts commit 38927cb.

* Remove trash code...
AaronZyLee pushed a commit that referenced this pull request Jun 6, 2022
* fix(appsync-dart-visitor): update broken test snapshot

* chore(appsync-dart-visitor): improve indexes generate following Dart lint rules

* feat(appsync-dart-visitor): generate custom PK supporting code

* Make custom PK fields immutable in copyWidth function

* Improve ModelIdentifier methods implementation

* Use the feature flag to control custom PK impl generation

* udpate snapshot for updated dart comment blocks

* Improve generated model identifier helper class

* Update existing unit test snapshots and add new tests for custom PK

* Remove unnecesary new initiating instances

* revert comment block changes

* Update the impl getting identifier fields

* Revert "Remove unnecesary new initiating instances"

This reverts commit 38927cb.

* Remove trash code...
AaronZyLee pushed a commit that referenced this pull request Jun 13, 2022
* fix(appsync-dart-visitor): update broken test snapshot

* chore(appsync-dart-visitor): improve indexes generate following Dart lint rules

* feat(appsync-dart-visitor): generate custom PK supporting code

* Make custom PK fields immutable in copyWidth function

* Improve ModelIdentifier methods implementation

* Use the feature flag to control custom PK impl generation

* udpate snapshot for updated dart comment blocks

* Improve generated model identifier helper class

* Update existing unit test snapshots and add new tests for custom PK

* Remove unnecesary new initiating instances

* revert comment block changes

* Update the impl getting identifier fields

* Revert "Remove unnecesary new initiating instances"

This reverts commit 38927cb.

* Remove trash code...
AaronZyLee pushed a commit that referenced this pull request Jun 14, 2022
* fix(appsync-dart-visitor): update broken test snapshot

* chore(appsync-dart-visitor): improve indexes generate following Dart lint rules

* feat(appsync-dart-visitor): generate custom PK supporting code

* Make custom PK fields immutable in copyWidth function

* Improve ModelIdentifier methods implementation

* Use the feature flag to control custom PK impl generation

* udpate snapshot for updated dart comment blocks

* Improve generated model identifier helper class

* Update existing unit test snapshots and add new tests for custom PK

* Remove unnecesary new initiating instances

* revert comment block changes

* Update the impl getting identifier fields

* Revert "Remove unnecesary new initiating instances"

This reverts commit 38927cb.

* Remove trash code...
AaronZyLee pushed a commit that referenced this pull request Jun 15, 2022
* fix(appsync-dart-visitor): update broken test snapshot

* chore(appsync-dart-visitor): improve indexes generate following Dart lint rules

* feat(appsync-dart-visitor): generate custom PK supporting code

* Make custom PK fields immutable in copyWidth function

* Improve ModelIdentifier methods implementation

* Use the feature flag to control custom PK impl generation

* udpate snapshot for updated dart comment blocks

* Improve generated model identifier helper class

* Update existing unit test snapshots and add new tests for custom PK

* Remove unnecesary new initiating instances

* revert comment block changes

* Update the impl getting identifier fields

* Revert "Remove unnecesary new initiating instances"

This reverts commit 38927cb.

* Remove trash code...
AaronZyLee pushed a commit that referenced this pull request Jul 13, 2022
* fix(appsync-dart-visitor): update broken test snapshot

* chore(appsync-dart-visitor): improve indexes generate following Dart lint rules

* feat(appsync-dart-visitor): generate custom PK supporting code

* Make custom PK fields immutable in copyWidth function

* Improve ModelIdentifier methods implementation

* Use the feature flag to control custom PK impl generation

* udpate snapshot for updated dart comment blocks

* Improve generated model identifier helper class

* Update existing unit test snapshots and add new tests for custom PK

* Remove unnecesary new initiating instances

* revert comment block changes

* Update the impl getting identifier fields

* Revert "Remove unnecesary new initiating instances"

This reverts commit 38927cb.

* Remove trash code...
AaronZyLee pushed a commit that referenced this pull request Jul 19, 2022
* fix(appsync-dart-visitor): update broken test snapshot

* chore(appsync-dart-visitor): improve indexes generate following Dart lint rules

* feat(appsync-dart-visitor): generate custom PK supporting code

* Make custom PK fields immutable in copyWidth function

* Improve ModelIdentifier methods implementation

* Use the feature flag to control custom PK impl generation

* udpate snapshot for updated dart comment blocks

* Improve generated model identifier helper class

* Update existing unit test snapshots and add new tests for custom PK

* Remove unnecesary new initiating instances

* revert comment block changes

* Update the impl getting identifier fields

* Revert "Remove unnecesary new initiating instances"

This reverts commit 38927cb.

* Remove trash code...
AaronZyLee added a commit that referenced this pull request Jul 19, 2022
* feat(appsync-dart-visitor): attach index info to model schema (#391)

* Chore/custom pk flutter (#393)

* Revert "fix: revert custom pk change (#376)"

This reverts commit fa4fe52.

* feat: change model meta generation in models

* feat: add useCustomPrimaryKey ff

* fix: rm unused import

* rebase master

Co-authored-by: Zeyu Li <[email protected]>

* Feat/custom pk flutter impl (#394)

* fix(appsync-dart-visitor): update broken test snapshot

* chore(appsync-dart-visitor): improve indexes generate following Dart lint rules

* feat(appsync-dart-visitor): generate custom PK supporting code

* Make custom PK fields immutable in copyWidth function

* Improve ModelIdentifier methods implementation

* Use the feature flag to control custom PK impl generation

* udpate snapshot for updated dart comment blocks

* Improve generated model identifier helper class

* Update existing unit test snapshots and add new tests for custom PK

* Remove unnecesary new initiating instances

* revert comment block changes

* Update the impl getting identifier fields

* Revert "Remove unnecesary new initiating instances"

This reverts commit 38927cb.

* Remove trash code...

* Add method override annotation (#402)

* Custom pk flutter merge main (#407)

* feat: update imports generated for flutter datastore plugin dependency (#382) (#388)

* chore(amplify-codegen): change flutter import path from datastore to core (#380)

* feat(appsync-modelgen-plugin): Change flutter datastore models dependency to use amplify_core

* feat(appsync-modelgen-plugin): add amplify_flutter version check to determine datastore dependency import

* fix(appsync-modelgen-plugin): correct indentation for error message

* fix(appsync-modelgen-plugin): run linter

* fix(amplify-codegen): update unit tests

* fix(amplify-codegen): lower minimum version to 0.4.0-rc.1

* fix(appsync-modelgen-plugin): remove duplicate .dart from imports

Co-authored-by: Travis Sheppard <[email protected]>
Co-authored-by: Dane Pilcher <[email protected]>

Co-authored-by: Phani Srikar Edupuganti <[email protected]>
Co-authored-by: Travis Sheppard <[email protected]>

* chore(release): Publish [ci skip]

 - [email protected]
 - @aws-amplify/[email protected]

* feat: add null type union to optional fields

* chore(release): Publish [ci skip]

 - [email protected]
 - @aws-amplify/[email protected]

* fix(appsync-dart-visitor): update ignored linter rules (#404)

* fix(appsync-dart-visitor): update ignored linter rules

* Dedupe

* fix unit tests snapshot

Co-authored-by: Dane Pilcher <[email protected]>
Co-authored-by: Phani Srikar Edupuganti <[email protected]>
Co-authored-by: Travis Sheppard <[email protected]>
Co-authored-by: phani-srikar <[email protected]>
Co-authored-by: yeung-wah <[email protected]>

* rm unrelated changes

* fix: unit tests for non model

* feat: add custom pk connected model support for belongsTo

* fix: lint error

* lgtm error

* fix snapshot after rebase

* feat: add support for hasMany CPK

* fix: snapshots

* fix: hasone associate with key

* fix: add PK field type respect

* feat(appsync-dart-visitor): capability of creating query predicate wi… (#441)

* feat(appsync-dart-visitor): capability of creating query predicate with custom PK

* wrap the code generation with the feature flag

* fix: snapshots

* fix: change unit test

Co-authored-by: Hui Zhao <[email protected]>
Co-authored-by: Dane Pilcher <[email protected]>
Co-authored-by: Phani Srikar Edupuganti <[email protected]>
Co-authored-by: Travis Sheppard <[email protected]>
Co-authored-by: phani-srikar <[email protected]>
Co-authored-by: yeung-wah <[email protected]>
AaronZyLee added a commit that referenced this pull request Jul 19, 2022
* feat(modelgen):custom pk support for all platforms

* feat(modelgen): connected model support for custom pk (#430)

* feat(modelgen): connected model support for custom pk

* remove additional code

* remove additional code

* use neat statements for targetName

* fix: manyToMany pk issue

* fix: distinguish between option id and custom id

* feat: add associateWithFields and model fk fields

* fix: adding fields in belongsTo

* feat: add associatedWithFields to support CPK

* fix lint error

* fix: rm error for fields in belongsTo

* fix: rewrite toCamelCase, manyToMany and belongsTo process

* feat: refactor hasOne process

* feat: add PK/SK original field respect

* fix: move constants and remove id type error

* fix: refactor get connected fields for hasOne and belongsTo

* add unit tests for connected fields refactor

* fix: import

* address CRs

* fix: change pk naming in manyToMany models (#455)

* address CRs

* feat(modelgen-java): custom PK support for android (#422)

* fix: remove id generation when custom pk is defined

* add primary key class generation

* add model config

* add import for model primary key

* add resolveIdentifier and pk class field

* use outer class for pk class

* fix: lgtm alert

* address feedback

* move pk class to nested one

* rename primary key to identifier

* feat: add target names for hasone/belongsTo

* update snapshot

* fix lint issue

* fix: change version from string to int

* always generate targetName field

* fix: add fk fields in models

* feat: add hasmany cpk support

* fix: snapshot

* fix: hasOne associateWith issue

* fix: add PK field type respect

* fix: apply feature flag to CPK java code

* fix lint

* fix: snapshots

* fix: pre-define booleans for backward compatability

* change ff condition

* feat(modelgen-swift): custom primary key support for ios (#425)

* fix: remove id generation when custom pk is defined

* feat: add custom pk support for ios

* fix snapshots

* add empty line

* fix: pk related fields to immutable

* feat: add target names in hasOne/belongsTo model

* rm additional parenthesis

* feat: add hasMany connected model CPK support

* fix: snapshot

* fix: hasOne asscociate with key

* fix: update ff name

* fix: use feature flag for swift CPK

* fix: snapshot

* fix lint

* add ff check

* feat(modelgen-js): custom primary key support (#389)

* Revert "fix: revert custom pk change (#376)"

This reverts commit fa4fe52.

* feat: change model meta generation in models

* feat: add useCustomPrimaryKey ff

* fix: rm unused import

* rebase master

* fix: add composite identifier type

* fix: use codegen field for sortKeyField

* fix: change ff name and set to true for test purpose

* fix: composite key for id with sk

* add targetNames in schema

* add target name fields in model

* add associateWithFields meta for hasOne relation

* feat: add hasMany CPK support

* fix: additional fiels in hasmany belongsTo

* fix: associate with key issue

* fix: use iscustomPK enabled

* fix: update PK field respect

* fix: meta snap

* feat(modelgen-dart): custom pk support for flutter (#428)

* feat(appsync-dart-visitor): attach index info to model schema (#391)

* Chore/custom pk flutter (#393)

* Revert "fix: revert custom pk change (#376)"

This reverts commit fa4fe52.

* feat: change model meta generation in models

* feat: add useCustomPrimaryKey ff

* fix: rm unused import

* rebase master

Co-authored-by: Zeyu Li <[email protected]>

* Feat/custom pk flutter impl (#394)

* fix(appsync-dart-visitor): update broken test snapshot

* chore(appsync-dart-visitor): improve indexes generate following Dart lint rules

* feat(appsync-dart-visitor): generate custom PK supporting code

* Make custom PK fields immutable in copyWidth function

* Improve ModelIdentifier methods implementation

* Use the feature flag to control custom PK impl generation

* udpate snapshot for updated dart comment blocks

* Improve generated model identifier helper class

* Update existing unit test snapshots and add new tests for custom PK

* Remove unnecesary new initiating instances

* revert comment block changes

* Update the impl getting identifier fields

* Revert "Remove unnecesary new initiating instances"

This reverts commit 38927cb.

* Remove trash code...

* Add method override annotation (#402)

* Custom pk flutter merge main (#407)

* feat: update imports generated for flutter datastore plugin dependency (#382) (#388)

* chore(amplify-codegen): change flutter import path from datastore to core (#380)

* feat(appsync-modelgen-plugin): Change flutter datastore models dependency to use amplify_core

* feat(appsync-modelgen-plugin): add amplify_flutter version check to determine datastore dependency import

* fix(appsync-modelgen-plugin): correct indentation for error message

* fix(appsync-modelgen-plugin): run linter

* fix(amplify-codegen): update unit tests

* fix(amplify-codegen): lower minimum version to 0.4.0-rc.1

* fix(appsync-modelgen-plugin): remove duplicate .dart from imports

Co-authored-by: Travis Sheppard <[email protected]>
Co-authored-by: Dane Pilcher <[email protected]>

Co-authored-by: Phani Srikar Edupuganti <[email protected]>
Co-authored-by: Travis Sheppard <[email protected]>

* chore(release): Publish [ci skip]

 - [email protected]
 - @aws-amplify/[email protected]

* feat: add null type union to optional fields

* chore(release): Publish [ci skip]

 - [email protected]
 - @aws-amplify/[email protected]

* fix(appsync-dart-visitor): update ignored linter rules (#404)

* fix(appsync-dart-visitor): update ignored linter rules

* Dedupe

* fix unit tests snapshot

Co-authored-by: Dane Pilcher <[email protected]>
Co-authored-by: Phani Srikar Edupuganti <[email protected]>
Co-authored-by: Travis Sheppard <[email protected]>
Co-authored-by: phani-srikar <[email protected]>
Co-authored-by: yeung-wah <[email protected]>

* rm unrelated changes

* fix: unit tests for non model

* feat: add custom pk connected model support for belongsTo

* fix: lint error

* lgtm error

* fix snapshot after rebase

* feat: add support for hasMany CPK

* fix: snapshots

* fix: hasone associate with key

* fix: add PK field type respect

* feat(appsync-dart-visitor): capability of creating query predicate wi… (#441)

* feat(appsync-dart-visitor): capability of creating query predicate with custom PK

* wrap the code generation with the feature flag

* fix: snapshots

* fix: change unit test

Co-authored-by: Hui Zhao <[email protected]>
Co-authored-by: Dane Pilcher <[email protected]>
Co-authored-by: Phani Srikar Edupuganti <[email protected]>
Co-authored-by: Travis Sheppard <[email protected]>
Co-authored-by: phani-srikar <[email protected]>
Co-authored-by: yeung-wah <[email protected]>

* fix: use read ff to replace hardcode

Co-authored-by: Hui Zhao <[email protected]>
Co-authored-by: Dane Pilcher <[email protected]>
Co-authored-by: Phani Srikar Edupuganti <[email protected]>
Co-authored-by: Travis Sheppard <[email protected]>
Co-authored-by: phani-srikar <[email protected]>
Co-authored-by: yeung-wah <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants