Skip to content

Commit 2439394

Browse files
committed
Upgraded SDK constraints + lints.
1 parent 3da76d1 commit 2439394

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+3688
-3124
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 3.5.8
4+
5+
- Upgraded SDK constraints and lints.
6+
37
## 3.5.7.
48

59
- Supporting URL-based connection-string specification in `Connection.openFromUrl` and `Pool.withUrl`. (Note: feature and supported settings is considered experimental.)

example/example.dart

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ void main() async {
3232
print('has connection!');
3333

3434
// Simple query without results
35-
await conn.execute('CREATE TABLE IF NOT EXISTS a_table ('
36-
' id TEXT NOT NULL, '
37-
' totals INTEGER NOT NULL DEFAULT 0'
38-
')');
35+
await conn.execute(
36+
'CREATE TABLE IF NOT EXISTS a_table ('
37+
' id TEXT NOT NULL, '
38+
' totals INTEGER NOT NULL DEFAULT 0'
39+
')',
40+
);
3941

4042
// simple query
4143
final result0 = await conn.execute("SELECT 'foo'");
@@ -71,8 +73,9 @@ void main() async {
7173
await statement.dispose();
7274

7375
// preared statement with types
74-
final anotherStatement =
75-
await conn.prepare(Sql(r'SELECT $1;', types: [Type.bigInteger]));
76+
final anotherStatement = await conn.prepare(
77+
Sql(r'SELECT $1;', types: [Type.bigInteger]),
78+
);
7679
final bound = anotherStatement.bind([1]);
7780
final subscription = bound.listen((row) {
7881
print('row: $row');

lib/postgres.dart

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ abstract class Session {
177177
Future<Result> execute(
178178
Object /* String | Sql */ query, {
179179
Object? /* List<Object?|TypedValue> | Map<String, Object?|TypedValue> */
180-
parameters,
180+
parameters,
181181
bool ignoreRows = false,
182182
QueryMode? queryMode,
183183
Duration? timeout,
@@ -227,8 +227,10 @@ abstract class Connection implements Session, SessionExecutor {
227227
Endpoint endpoint, {
228228
ConnectionSettings? settings,
229229
}) {
230-
return PgConnectionImplementation.connect(endpoint,
231-
connectionSettings: settings);
230+
return PgConnectionImplementation.connect(
231+
endpoint,
232+
connectionSettings: settings,
233+
);
232234
}
233235

234236
/// Open a new connection where the endpoint and the settings are encoded as an URL as
@@ -275,12 +277,13 @@ abstract class ResultStreamSubscription
275277

276278
abstract class Statement {
277279
ResultStream bind(
278-
Object? /* List<Object?|TypedValue> | Map<String, Object?|TypedValue> */
279-
parameters);
280+
Object? /* List<Object?|TypedValue> | Map<String, Object?|TypedValue> */
281+
parameters,
282+
);
280283

281284
Future<Result> run(
282285
Object? /* List<Object?|TypedValue> | Map<String, Object?|TypedValue> */
283-
parameters, {
286+
parameters, {
284287
Duration? timeout,
285288
});
286289

@@ -306,8 +309,8 @@ class ResultRow extends UnmodifiableListView<Object?> {
306309
required List<Object?> values,
307310
required this.schema,
308311
List<bool>? sqlNulls,
309-
}) : _sqlNulls = sqlNulls,
310-
super(values);
312+
}) : _sqlNulls = sqlNulls,
313+
super(values);
311314

312315
/// Returns true if the result at [columnIndex] returned SQL `NULL` value.
313316
///
@@ -432,14 +435,8 @@ final class Endpoint {
432435
});
433436

434437
@override
435-
int get hashCode => Object.hash(
436-
host,
437-
port,
438-
database,
439-
username,
440-
password,
441-
isUnixSocket,
442-
);
438+
int get hashCode =>
439+
Object.hash(host, port, database, username, password, isUnixSocket);
443440

444441
@override
445442
bool operator ==(Object other) {
@@ -468,8 +465,7 @@ enum SslMode {
468465
require,
469466

470467
/// Always use SSL and verify certificates.
471-
verifyFull,
472-
;
468+
verifyFull;
473469

474470
bool get ignoreCertificateIssues => this == SslMode.require;
475471

@@ -599,8 +595,7 @@ enum IsolationLevel {
599595

600596
/// One transaction may see uncommitted changes made by some other transaction.
601597
/// In PostgreSQL READ UNCOMMITTED is treated as READ COMMITTED.
602-
readUncommitted._('READ UNCOMMITTED'),
603-
;
598+
readUncommitted._('READ UNCOMMITTED');
604599

605600
/// The SQL identifier of the isolation level including "ISOLATION LEVEL" prefix
606601
/// and leading space.
@@ -622,8 +617,7 @@ enum AccessMode {
622617
/// GRANT, REVOKE, TRUNCATE; and EXPLAIN ANALYZE and EXECUTE if the command
623618
/// they would execute is among those listed. This is a high-level notion of
624619
/// read-only that does not prevent all writes to disk.
625-
readOnly._('READ ONLY'),
626-
;
620+
readOnly._('READ ONLY');
627621

628622
/// The SQL identifier of the access mode including leading space.
629623
@internal
@@ -644,8 +638,7 @@ enum DeferrableMode {
644638
deferrable._('DEFERRABLE'),
645639

646640
/// The default mode.
647-
notDeferrable._('NOT DEFERRABLE'),
648-
;
641+
notDeferrable._('NOT DEFERRABLE');
649642

650643
/// The SQL identifier of the deferrable mode including leading space.
651644
@internal
@@ -662,11 +655,7 @@ class Retry<R> {
662655
final FutureOr<R> Function()? orElse;
663656
final FutureOr<bool> Function(Exception)? retryIf;
664657

665-
Retry({
666-
required this.maxAttempts,
667-
this.orElse,
668-
this.retryIf,
669-
});
658+
Retry({required this.maxAttempts, this.orElse, this.retryIf});
670659
}
671660

672661
/// The characteristics of the current transaction.

lib/src/auth/auth.dart

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ import 'clear_text_authenticator.dart';
66
import 'md5_authenticator.dart';
77
import 'sasl_authenticator.dart';
88

9-
enum AuthenticationScheme {
10-
md5,
11-
scramSha256,
12-
clear,
13-
}
9+
enum AuthenticationScheme { md5, scramSha256, clear }
1410

1511
/// A small interface to obtain the username and password used for a postgres
1612
/// connection, as well as sending messages.
@@ -37,16 +33,22 @@ abstract class PostgresAuthenticator {
3733
void onMessage(AuthenticationMessage message);
3834
}
3935

40-
PostgresAuthenticator createAuthenticator(PostgresAuthConnection connection,
41-
AuthenticationScheme authenticationScheme) {
36+
PostgresAuthenticator createAuthenticator(
37+
PostgresAuthConnection connection,
38+
AuthenticationScheme authenticationScheme,
39+
) {
4240
switch (authenticationScheme) {
4341
case AuthenticationScheme.md5:
4442
return MD5Authenticator(connection);
4543
case AuthenticationScheme.scramSha256:
4644
final credentials = UsernamePasswordCredential(
47-
username: connection.username, password: connection.password);
45+
username: connection.username,
46+
password: connection.password,
47+
);
4848
return PostgresSaslAuthenticator(
49-
connection, ScramAuthenticator('SCRAM-SHA-256', sha256, credentials));
49+
connection,
50+
ScramAuthenticator('SCRAM-SHA-256', sha256, credentials),
51+
);
5052
case AuthenticationScheme.clear:
5153
return ClearAuthenticator(connection);
5254
}

lib/src/auth/md5_authenticator.dart

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ class MD5Authenticator extends PostgresAuthenticator {
1616
final reader = ByteDataReader()..add(message.bytes);
1717
final salt = reader.read(4, copy: true);
1818

19-
final authMessage =
20-
AuthMD5Message(connection.username!, connection.password!, salt);
19+
final authMessage = AuthMD5Message(
20+
connection.username!,
21+
connection.password!,
22+
salt,
23+
);
2124

2225
connection.sendMessage(authMessage);
2326
}
@@ -28,11 +31,15 @@ class AuthMD5Message extends ClientMessage {
2831

2932
AuthMD5Message._(this._hashedAuthString);
3033
factory AuthMD5Message(
31-
String username, String password, List<int> saltBytes) {
34+
String username,
35+
String password,
36+
List<int> saltBytes,
37+
) {
3238
final passwordHash = md5.convert('$password$username'.codeUnits).toString();
3339
final saltString = String.fromCharCodes(saltBytes);
34-
final md5Hash =
35-
md5.convert('$passwordHash$saltString'.codeUnits).toString();
40+
final md5Hash = md5
41+
.convert('$passwordHash$saltString'.codeUnits)
42+
.toString();
3643
return AuthMD5Message._('md5$md5Hash');
3744
}
3845

lib/src/auth/sasl_authenticator.dart

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,34 @@ class PostgresSaslAuthenticator extends PostgresAuthenticator {
2020
switch (message.type) {
2121
case AuthenticationMessageType.sasl:
2222
final bytesToSend = authenticator.handleMessage(
23-
SaslMessageType.AuthenticationSASL, message.bytes);
23+
SaslMessageType.AuthenticationSASL,
24+
message.bytes,
25+
);
2426
if (bytesToSend == null) {
2527
throw PgException('KindSASL: No bytes to send');
2628
}
2729
msg = SaslClientFirstMessage(bytesToSend, authenticator.mechanism.name);
2830
break;
2931
case AuthenticationMessageType.saslContinue:
3032
final bytesToSend = authenticator.handleMessage(
31-
SaslMessageType.AuthenticationSASLContinue, message.bytes);
33+
SaslMessageType.AuthenticationSASLContinue,
34+
message.bytes,
35+
);
3236
if (bytesToSend == null) {
3337
throw PgException('KindSASLContinue: No bytes to send');
3438
}
3539
msg = SaslClientLastMessage(bytesToSend);
3640
break;
3741
case AuthenticationMessageType.saslFinal:
3842
authenticator.handleMessage(
39-
SaslMessageType.AuthenticationSASLFinal, message.bytes);
43+
SaslMessageType.AuthenticationSASLFinal,
44+
message.bytes,
45+
);
4046
return;
4147
default:
4248
throw PgException(
43-
'Unsupported authentication type ${message.type}, closing connection.');
49+
'Unsupported authentication type ${message.type}, closing connection.',
50+
);
4451
}
4552
connection.sendMessage(msg);
4653
}

lib/src/buffer.dart

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ class EncodedString {
1616
class PgByteDataWriter extends ByteDataWriter {
1717
final Encoding encoding;
1818

19-
PgByteDataWriter({
20-
super.bufferLength,
21-
required this.encoding,
22-
});
19+
PgByteDataWriter({super.bufferLength, required this.encoding});
2320

2421
late final encodingName = encodeString(encoding.name);
2522

@@ -45,9 +42,7 @@ const _emptyString = '';
4542
class PgByteDataReader extends ByteDataReader {
4643
final CodecContext codecContext;
4744

48-
PgByteDataReader({
49-
required this.codecContext,
50-
});
45+
PgByteDataReader({required this.codecContext});
5146

5247
Encoding get encoding => codecContext.encoding;
5348

lib/src/connection_string.dart

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ import '../postgres.dart';
1111
ReplicationMode? replicationMode,
1212
SecurityContext? securityContext,
1313
SslMode? sslMode,
14-
}) parseConnectionString(String connectionString) {
14+
})
15+
parseConnectionString(String connectionString) {
1516
final uri = Uri.parse(connectionString);
1617

1718
if (uri.scheme != 'postgresql' && uri.scheme != 'postgres') {
1819
throw ArgumentError(
19-
'Invalid connection string scheme: ${uri.scheme}. Expected "postgresql" or "postgres".');
20+
'Invalid connection string scheme: ${uri.scheme}. Expected "postgresql" or "postgres".',
21+
);
2022
}
2123

2224
final host = uri.host.isEmpty ? 'localhost' : uri.host;
@@ -33,7 +35,7 @@ import '../postgres.dart';
3335
'connect_timeout',
3436
'application_name',
3537
'client_encoding',
36-
'replication'
38+
'replication',
3739
};
3840

3941
final params = uri.queryParameters;
@@ -58,7 +60,8 @@ import '../postgres.dart';
5860
break;
5961
default:
6062
throw ArgumentError(
61-
'Invalid sslmode value: ${params['sslmode']}. Expected: disable, require, verify-ca, verify-full');
63+
'Invalid sslmode value: ${params['sslmode']}. Expected: disable, require, verify-ca, verify-full',
64+
);
6265
}
6366
}
6467

@@ -83,7 +86,8 @@ import '../postgres.dart';
8386
final timeoutSeconds = int.tryParse(params['connect_timeout']!);
8487
if (timeoutSeconds == null || timeoutSeconds <= 0) {
8588
throw ArgumentError(
86-
'Invalid connect_timeout value: ${params['connect_timeout']}. Expected positive integer.');
89+
'Invalid connect_timeout value: ${params['connect_timeout']}. Expected positive integer.',
90+
);
8791
}
8892
connectTimeout = Duration(seconds: timeoutSeconds);
8993
}
@@ -103,7 +107,8 @@ import '../postgres.dart';
103107
break;
104108
default:
105109
throw ArgumentError(
106-
'Unsupported client_encoding: ${params['client_encoding']}. Supported: UTF8, LATIN1');
110+
'Unsupported client_encoding: ${params['client_encoding']}. Supported: UTF8, LATIN1',
111+
);
107112
}
108113
}
109114

@@ -123,7 +128,8 @@ import '../postgres.dart';
123128
break;
124129
default:
125130
throw ArgumentError(
126-
'Invalid replication value: ${params['replication']}. Expected: database, true, physical, false, no_select');
131+
'Invalid replication value: ${params['replication']}. Expected: database, true, physical, false, no_select',
132+
);
127133
}
128134
}
129135

@@ -190,7 +196,8 @@ SecurityContext _createSecurityContext({
190196
context.setTrustedCertificates(caPath);
191197
} catch (e) {
192198
throw ArgumentError(
193-
'Failed to load SSL CA certificates from $caPath: $e');
199+
'Failed to load SSL CA certificates from $caPath: $e',
200+
);
194201
}
195202
}
196203

0 commit comments

Comments
 (0)