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

chore(repo): Dart 3 cleanup #2968

Merged
merged 14 commits into from
May 8, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/dart_ddc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ jobs:

- name: Run Tests
if: "always() && steps.bootstrap.conclusion == 'success'"
run: dart run build_runner test --delete-conflicting-outputs -- -p ${{ matrix.browser }} --exclude-tags=no-ddc
run: dart run build_runner test --delete-conflicting-outputs -- -p ${{ matrix.browser }}
working-directory: ${{ inputs.working-directory }}
7 changes: 2 additions & 5 deletions .github/workflows/smoke_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,9 @@ jobs:
# https://github.com/localstack/localstack/pull/6831
pip install pyOpenSSL --upgrade
pip install cryptography --upgrade
pip install localstack

# Pin to <2.0.0 until bucket creation is fixed:
# https://github.com/localstack/localstack/issues/8018
pip install "localstack<2.0.0"

docker pull localstack/localstack
docker pull localstack/localstack:latest
localstack start --detached
echo "Waiting for localstack startup..."
localstack wait -t 30
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// TODO(dnys1): Remove when Dart 2.18 is no longer supported
// ignore_for_file: comment_references

import 'package:amplify_core/src/types/auth/attribute/auth_next_update_attribute_step.dart';

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

// TODO(dnys1): Remove when Dart 2.18 is no longer supported
// ignore_for_file: comment_references

import 'package:amplify_core/src/types/auth/password/reset_password_step.dart';

/// {@template amplify_core.auth.auth_reset_password_step}
Expand Down
4 changes: 0 additions & 4 deletions packages/auth/amplify_auth_cognito_test/dart_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,3 @@ on_platform:
# Tests with workers seems to be really slow on browsers
browser:
timeout: 2x
tags:
# Tests to skip on DDC
no-ddc:
test_on: browser
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// TODO(dnys1): Investigate DDC failures
@Tags(['no-ddc'])

import 'dart:async';

import 'package:amplify_auth_cognito_dart/src/flows/constants.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import 'dart:convert';
import 'dart:typed_data';

import 'package:amplify_auth_cognito_dart/src/crypto/crypto.dart';
import 'package:amplify_auth_cognito_dart/src/exception/srp_error.dart';
import 'package:amplify_auth_cognito_dart/src/flows/helpers.dart';
import 'package:amplify_auth_cognito_dart/src/flows/srp/srp_helper.dart';
Expand All @@ -15,13 +13,79 @@ import 'package:test/test.dart';
// From aws-sdk-net-extensions-cognito:
// https://github.com/aws/aws-sdk-net-extensions-cognito/blob/9743362173a09af846d626dbecdd9a5f80e76ce7/test/Amazon.Extensions.CognitoAuthentication.UnitTests/AuthenticationCryptoTests.cs

SrpInitResult get initResult => SrpInitResult((b) {
final bytes = List.filled(1024, 2)..[1023] = 0;
final a = decodeBigInt(Uint8List.fromList(bytes));
b
..privateA = a
..publicA = SrpHelper.g.modPow(a, SrpHelper.N);
});
/// The computed result of running:
///
/// ```dart
/// final bytes = List.filled(1024, 2)..[1023] = 0;
/// final a = decodeBigInt(Uint8List.fromList(bytes));
/// final privateA = a;
/// final publicA = SrpHelper.g.modPow(a, SrpHelper.N);
/// ```
///
/// Cached so that JS tests, in particular, do not need to make
/// this computation on the main thread during tests which can
/// cause them to block the test runner.
final SrpInitResult initResult = SrpInitResult(
(b) => b
..privateA = BigInt.parse(
'8554887338191497485984190154774767548613836564676334842602610087'
'7625202497970140801275626237270744095996650336953492178283127123'
'1511516912636062560845141018885416704974269011402831235472978984'
'4389779228341895201543308914059680976942127769050210872949160001'
'9806729405270589025850982473398964776886102422035478470716093762'
'7963851768872442792168507785125720432349681512877453151918650465'
'9514161706005445881924758257452084822749930242511815203957474614'
'3254397320474293522147642573509422079824119150188174616921076269'
'1982249470609904221996240393562950353682901308625300297791256264'
'3529387458518592279647451886755070521509924251809795816702329668'
'9123255351437523938954115319560481461588362855648326902386480269'
'4899065820934467593088161878675031690106462301829707786797966663'
'0360733426421618509571687192328028366662420556626329460891075158'
'4840424169181692167629884472338111965875315824247883990455265287'
'1411266328435232131233711732693932099908855115645833740021159031'
'3263315416561415174045705563450917344425433265965483273929886717'
'5197157358002165597071264971244597737881853962421846092199634258'
'0326034693673690718678486342912576839416212009415004490584968241'
'8489722775128910408478263141795395826724335529842632325969339575'
'2562584636546896272931570803024314368950475210196453156762961714'
'0245890583404377930665609577730164947730514464173482128657151942'
'1329266656687087479343520440586842455164591676747639409815054252'
'4157825966918410141453911592515637027076761068453048152571832925'
'9810527337371378487089897558784023424947599035029659433845552465'
'2385044263908554994028092702454925446453260823176951284849477882'
'9776368096641502648307296907075777028659058205511855341793969249'
'9982326934532049402124470156981985279892230747518191246231103577'
'5264601601835504479238893764323114408443499502923892506168248005'
'9334066746580864609711493296688330092312046253487555318344572914'
'9152498968688902463975166231003961911757891214772052757049878748'
'9445282007284109408040997526411014649841212631171584468768828051'
'8108316711942800605328801723693363563810654438862126752929610894'
'4293847610936449479287004389775184915709776422285959361338010787'
'8913704751590695088888540441639249317782913135754227158206537474'
'5822177125558671342283821473052713840015577705677400399756556014'
'8376816736908646919896110677029520622490641294384598407868180410'
'5081007571125860692111623749138742664003284886086280905393024723'
'5629032438874578465400089970448174687576894398571095614965221683'
'83926177741154403966003731104256',
)
..publicA = BigInt.parse(
'4680905440366202979403051712823465156279080027839613035807423065'
'2473340610462246137484129918699659364511462345752207070083507060'
'6915267034077254043065097424106829765680354342236566394037516248'
'1903340258648895590221596612651146227211103722824649786043102047'
'1030745071527239946076957407886984638410751995945753207518688954'
'1780842350763466409139953841563784840433536563856556356298873518'
'5165717796036216980353458178685652630570456714695828456263725807'
'5413469597307934294952499360498909387748391495383509077962709085'
'3510286548059102604833560918454128984378535917707367830976825379'
'0705868829460477425658878928853605580284750895550995454818812335'
'2877018972589496745204920839805558932301519514073819908073683655'
'2219883729226630249463608232417411730498032654088098866936724404'
'8250958976851018795628633429081317552772543188130717141715262148'
'7405802749012638297781132717025502768296370019053119507064706813'
'32790787567298071163660158298',
),
);

const srpUsername = 'User5';
const srpPassword = 'Password1!';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// TODO(dnys1): Investigate DDC failures
@Tags(['no-ddc'])

import 'package:amplify_auth_cognito_dart/src/flows/srp/srp_init_result.dart';
import 'package:amplify_auth_cognito_dart/src/flows/srp/srp_init_worker.dart';
import 'package:amplify_core/amplify_core.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// TODO(dnys1): Investigate DDC failures
@Tags(['no-ddc'])

import 'dart:async';

import 'package:amplify_auth_cognito_dart/src/flows/constants.dart';
Expand Down
21 changes: 10 additions & 11 deletions packages/aws_common/lib/src/config/aws_config_value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ enum AWSConfigValue<T extends Object> {
/// Defaults to `3`.
maxAttempts<int>._(
'AWS_MAX_ATTEMPTS',
// TODO(dnys1): Add back when Dart >=2.19 becomes the min SDK.
// String.fromEnvironment('AWS_MAX_ATTEMPTS'),
String.fromEnvironment('AWS_MAX_ATTEMPTS'),
3,
parse: int.parse,
),
Expand All @@ -30,6 +29,7 @@ enum AWSConfigValue<T extends Object> {
/// Defaults to `us-east-1`.
region._(
'AWS_REGION',
String.fromEnvironment('AWS_REGION'),
'us-east-1',
),

Expand All @@ -38,6 +38,7 @@ enum AWSConfigValue<T extends Object> {
/// Defaults to `~/.aws/config`.
configFile._(
'AWS_CONFIG_FILE',
String.fromEnvironment('AWS_CONFIG_FILE'),
'~/.aws/config',
),

Expand All @@ -46,13 +47,13 @@ enum AWSConfigValue<T extends Object> {
/// Defaults to `~/.aws/credentials`.
sharedCredentialsFile._(
'AWS_SHARED_CREDENTIALS_FILE',
String.fromEnvironment('AWS_SHARED_CREDENTIALS_FILE'),
'~/.aws/credentials',
);

const AWSConfigValue._(
this.key,
// TODO(dnys1): Add back when Dart >=2.19 becomes the min SDK.
// this._fromEnv,
this._fromEnv,
this.defaultValue, {
T Function(String)? parse,
}) : _parse = parse ?? _identity;
Expand All @@ -63,8 +64,7 @@ enum AWSConfigValue<T extends Object> {
/// The default value of the configuration parameter.
final T defaultValue;

// TODO(dnys1): Add back when Dart >=2.19 becomes the min SDK.
// final String? _fromEnv;
final String? _fromEnv;
final T Function(String) _parse;
String? get _fromPlatformEnv => lookupPlatformEnv(key);

Expand All @@ -80,11 +80,10 @@ enum AWSConfigValue<T extends Object> {
} else if (fromOverride is String) {
return _parse(fromOverride);
}
// TODO(dnys1): Add back when Dart >=2.19 becomes the min SDK.
// final fromEnv = _fromEnv;
// if (fromEnv != null && fromEnv.isNotEmpty) {
// return _parse(fromEnv);
// }
final fromEnv = _fromEnv;
if (fromEnv != null && fromEnv.isNotEmpty) {
return _parse(fromEnv);
}
final fromPlatformEnv = _fromPlatformEnv;
if (fromPlatformEnv != null && fromPlatformEnv.isNotEmpty) {
return _parse(fromPlatformEnv);
Expand Down
18 changes: 3 additions & 15 deletions packages/aws_common/lib/src/http/aws_http_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,8 @@ abstract class AWSBaseHttpClient extends AWSCustomHttpClient {
unawaited(
operation.responseProgress.forward(responseProgressController),
);
// TODO(dnys1): Use `completeOperation` when available
operation.operation.then(
(resp) async {
try {
resp = await transformResponse(resp);
completer.complete(resp);
} on Object catch (e, st) {
completer.completeError(e, st);
}
},
onError: completer.completeError,
completer.completeOperation(
operation.operation.then(transformResponse),
);
return operation;
}
Expand All @@ -160,11 +151,8 @@ abstract class AWSBaseHttpClient extends AWSCustomHttpClient {
final responseProgressController =
StreamController<int>.broadcast(sync: true);

// TODO(dnys1): Use `completeOperation` when available
AWSHttpOperation? underlyingOperation;
final completer = CancelableCompleter<AWSBaseHttpResponse>(
onCancel: () {
underlyingOperation?.cancel();
requestProgressController.close();
responseProgressController.close();
return onCancel?.call();
Expand All @@ -175,7 +163,7 @@ abstract class AWSBaseHttpClient extends AWSCustomHttpClient {
completer,
requestProgressController: requestProgressController,
responseProgressController: responseProgressController,
).then((op) => underlyingOperation = op);
);
return AWSHttpOperation(
completer.operation,
requestProgress: requestProgressController.stream,
Expand Down
2 changes: 1 addition & 1 deletion packages/aws_common/lib/src/http/aws_http_client_js.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class AWSHttpClientImpl extends AWSHttpClient {
if (completer.isCanceled) return;
final resp = await fetch(
request.uri.toString(),
createRequestInit(
RequestInit(
method: request.method,
headers: request.headers,
body: body,
Expand Down
15 changes: 6 additions & 9 deletions packages/aws_common/lib/src/js/abort.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

// ignore_for_file: avoid_classes_with_only_static_members

@JS()
library aws_common.js.abort;

import 'package:js/js.dart';
import 'package:js/js_util.dart' as js_util;

Expand All @@ -14,6 +11,7 @@ import 'package:js/js_util.dart' as js_util;
/// a fetch request) and abort it if required via an [AbortController] object.
/// {@endtemplate}
@JS()
@staticInterop
abstract class AbortSignal {
/// An [AbortSignal] instance that is already set as aborted.
external static AbortSignal abort([String? reason]);
Expand All @@ -39,19 +37,18 @@ extension PropsAbortSignal on AbortSignal {
/// and when desired.
/// {@endtemplate}
@JS()
class AbortController {
@staticInterop
abstract class AbortController {
/// {@macro aws_http.js.abort_controller}
external factory AbortController();
}

/// {@macro aws_http.js.abort_controller}
extension PropsAbortController on AbortController {
/// The [AbortSignal], which can be used to communicate with, or to abort,
/// a DOM request.
external AbortSignal get signal;

/// Aborts a DOM request before it has completed.
external void abort([String? reason]);
}

/// {@macro aws_http.js.abort_controller}
extension PropsAbortController on AbortController {
// TODO(dnys1): Move methods here when staticInterop is enabled.
}
Loading