Skip to content

chore(datastore): DataStore Cocoa Pod removed modules #4934

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

Merged
merged 6 commits into from
May 29, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ class GenerateAmplifySwiftCommand extends AmplifyCommand with GlobOptions {
),
];

final _importsToRemove = [
'import Amplify',
'import AWSPluginsCore',
'import AWSDataStorePlugin',
];

/// Downloads Amplify Swift from GitHub into a temporary directory.
Future<Directory> _downloadRepository() => _cloneMemo.runOnce(() async {
final cloneDir =
Expand Down Expand Up @@ -132,12 +138,55 @@ class GenerateAmplifySwiftCommand extends AmplifyCommand with GlobOptions {
return worktreeDir;
}

/// Find and replaces the `import` statements in the plugin files.
Future<void> _replaceImports(Directory pluginDir) async {
final files = await pluginDir.list(recursive: true).toList();
for (final file in files) {
if (file is! File) {
continue;
}
// Only process Swift files.
if (!file.path.endsWith('.swift')) {
continue;
}
final contents = await file.readAsString();
// remove the list of import statement for Amplify including line breaks
final newContents = contents.split('\n').where((line) {
return !_importsToRemove.any((import) => line.contains(import));
}).join('\n');
await file.writeAsString(newContents);
}
}

/// Remove `info.plist` from the plugin files.
Future<void> _removePListFiles(Directory pluginDir) async {
final files = await pluginDir.list(recursive: true).toList();
for (final file in files) {
if (file is! File) {
continue;
}
// Only process Info.plist files.
if (!file.path.endsWith('Info.plist')) {
continue;
}
await file.delete();
}
}

/// Transforms the plugin files to Amplify Flutter requirements.
Future<void> _transformPlugin(Directory directory) async {
logger
..info('Transforming plugin files...')
..verbose('In ${directory.path}');
await _replaceImports(directory);
await _removePListFiles(directory);
}

/// Sets up the Amplify Swift repo for use later
Future<void> _setupRepo() async {
if (_repoCache[branchTarget] != null) {
return;
}

final repoDir = await _downloadRepository();
final repoRef = await _checkoutRepositoryRef(repoDir, branchTarget);

Expand All @@ -151,9 +200,13 @@ class GenerateAmplifySwiftCommand extends AmplifyCommand with GlobOptions {
exitError('No cached repo for branch $branchTarget');
}

return Directory.fromUri(
final pluginDir = Directory.fromUri(
repoDir.uri.resolve(path),
);

await _transformPlugin(pluginDir);

return pluginDir;
}

/// Generates the Amplify Swift plugin for [plugin].
Expand Down Expand Up @@ -251,6 +304,7 @@ class GenerateAmplifySwiftCommand extends AmplifyCommand with GlobOptions {

@override
Future<void> run() async {
logger.info('Generating Amplify Swift plugins.');
await super.run();
switch (isDiff) {
case true:
Expand Down
5 changes: 0 additions & 5 deletions packages/amplify_datastore/example/ios/Podfile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

import XCTest
import Amplify
@testable import AWSDataStorePlugin
@testable import amplify_datastore

class AmplifyModelSchemaUnitTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

import XCTest
import Amplify
@testable import AWSDataStorePlugin
@testable import amplify_datastore

class AmplifySerializedModelUnitTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import Flutter
import XCTest
import Amplify
import Combine
@testable import AWSDataStorePlugin
@testable import AWSPluginsCore
@testable import amplify_datastore

let testHubSchema: ModelSchema = SchemaData.PostSchema
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import Flutter
import XCTest
import Amplify
import Combine
@testable import AWSDataStorePlugin
@testable import amplify_datastore

let testSchema: ModelSchema = SchemaData.PostSchema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

import Foundation
import Amplify

func readJsonMap(filePath: String) throws -> [String: Any] {
if let object = try readJson(filePath: filePath) as? [String: Any] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@


import XCTest
@testable import Amplify
@testable import AWSPluginsCore
@testable import amplify_datastore

class GraphQLResponseDecodeTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import Foundation
import Amplify
@testable import amplify_datastore

extension ModelSchema: Equatable {
public static func == (lhs: ModelSchema, rhs: ModelSchema) -> Bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

import XCTest
import Amplify
import AWSDataStorePlugin
@testable import amplify_datastore

extension QueryPaginationInput: Equatable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

import XCTest
import Amplify
@testable import amplify_datastore

class QueryPredicateBuilderUnitTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

import XCTest
import Amplify
@testable import AWSDataStorePlugin
@testable import amplify_datastore

// Extending for simple assertions on the objects equality.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import Amplify
@testable import AWSDataStorePlugin
@testable import amplify_datastore

struct FlutterSerializedModelData {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import Amplify
@testable import AWSDataStorePlugin
@testable import amplify_datastore

struct SchemaData {
Expand Down
2 changes: 0 additions & 2 deletions packages/amplify_datastore/ios/Classes/CognitoPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

import Flutter
import UIKit
import Amplify
import AWSPluginsCore

extension NativeAuthUser: AuthUser { }

Expand Down
2 changes: 0 additions & 2 deletions packages/amplify_datastore/ios/Classes/DataStoreBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

import Foundation
import Amplify
import AWSDataStorePlugin
import Combine

public class DataStoreBridge {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import Flutter
import Foundation
import Amplify
import AWSDataStorePlugin

public class DataStoreHubEventStreamHandler: NSObject, FlutterStreamHandler {
private var eventSink: FlutterEventSink?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import Flutter
import Foundation

public class DataStoreObserveEventStreamHandler: NSObject, FlutterStreamHandler {
Expand Down
2 changes: 0 additions & 2 deletions packages/amplify_datastore/ios/Classes/FlutterApiPlugin.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import Foundation
import Flutter
import Amplify
import AWSPluginsCore
import Combine


Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import Flutter
import Foundation
import Amplify
import AWSDataStorePlugin

class FlutterDataStoreErrorHandler {
static func handleDataStoreError(error: DataStoreError, flutterResult: FlutterResult) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

import Foundation
import Amplify
import AWSDataStorePlugin

public enum FlutterDataStoreRequestUtils {
static func getJSONValue(_ jsonDict: [String: Any]) throws -> [String: JSONValue] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import Amplify
import Foundation

// Contains the set of classes that conforms to the `Model` protocol.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

import Flutter
import UIKit
import Amplify
import AWSDataStorePlugin
import AWSPluginsCore
import Combine

public class SwiftAmplifyDataStorePlugin: NSObject, FlutterPlugin, NativeAmplifyBridge, NativeAuthBridge, NativeApiBridge {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


import Foundation
import Amplify

extension GraphQLRequest {
func toNativeGraphQLRequest() -> NativeGraphQLRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@


import Foundation
import Amplify
import AWSPluginsCore

extension GraphQLResponse {
static var jsonDecoder: JSONDecoder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import Foundation
import Combine
import Amplify

extension Publisher {
func toAmplifyAsyncThrowingSequence() -> (AmplifyAsyncThrowingSequence<Output>, AnyCancellable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

import Foundation
import Amplify
import AWSDataStorePlugin
import AWSPluginsCore
import Flutter

/// A factory of [FlutterAuthProvider] instances. Manages shared state for all providers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

import Foundation
import Amplify
import AWSPluginsCore

struct NativeAWSAuthCognitoSession: AuthSession,
AuthAWSCredentialsProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

import Foundation
import AWSPluginsCore

struct NativeAWSPermanentCredentials: AWSCredentials {
let accessKeyId: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

import Foundation
import Amplify

// TODO: Mirgrate to Async Swift v2
public protocol AuthFetchSessionOperation: AmplifyOperation<AuthFetchSessionRequest, AuthSession, AuthError> {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
// SPDX-License-Identifier: Apache-2.0

import Foundation
import AWSPluginsCore

extension NativeUserPoolTokens: AuthCognitoTokens { }
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import Foundation
import Flutter
import UIKit
import Amplify
import AWSDataStorePlugin
import Combine

public struct FlutterHubElement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

import Foundation
import Amplify
import AWSDataStorePlugin

struct FlutterModelSyncedEvent: FlutterHubEvent {
var eventName: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

import Foundation
import Amplify
import AWSDataStorePlugin

struct FlutterNetworkStatusEvent: FlutterHubEvent {
var eventName: String
Expand Down
Loading
Loading