Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into shelf_router_nullsa…
Browse files Browse the repository at this point in the history
…fety
  • Loading branch information
jonasfj committed Mar 8, 2021
2 parents e1be97f + 6fe9fe1 commit aeb723e
Show file tree
Hide file tree
Showing 16 changed files with 375 additions and 475 deletions.
698 changes: 298 additions & 400 deletions .github/workflows/dart.yml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Dart Neats [![Build Status](https://travis-ci.org/google/dart-neats.svg?branch=master)](https://travis-ci.org/google/dart-neats)
Dart Neats [![Github Actions](https://github.com/google/dart-neats/actions/workflows/dart.yml/badge.svg)](https://github.com/google/dart-neats/actions/workflows/dart.yml)
==========
_A collection of a small neat packages for dart._

Expand Down
3 changes: 3 additions & 0 deletions neat_periodic_task/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v2.0.0
* Migrated to null-safety!

## v1.0.1
* Changed failure to write finished status into a warning. It's only a problem
if it consistently occurs. It could happen if something else went wrong,
Expand Down
23 changes: 10 additions & 13 deletions neat_periodic_task/lib/neat_periodic_task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ abstract class NeatStatusProvider {
///
/// Returns the current status file, or `null` if no status file has ever
/// been written.
Future<List<int>> get();
Future<List<int>?> get();

/// Set the current status file, if status file have not been changed since
/// last time it was read.
Expand Down Expand Up @@ -72,10 +72,11 @@ abstract class NeatStatusProvider {
}

class _InMemoryNeatStatusProvider implements NeatStatusProvider {
List<int> _value;
List<int>? _value;

@override
Future<List<int>> get() async => _value;
Future<List<int>?> get() async => _value;

@override
Future<bool> set(List<int> status) async {
_value = status;
Expand All @@ -88,7 +89,7 @@ class _NeatStatusProviderWithRetry extends NeatStatusProvider {
final RetryOptions _r;
_NeatStatusProviderWithRetry(this._provider, this._r);
@override
Future<List<int>> get() =>
Future<List<int>?> get() =>
_r.retry(() => _provider.get(), retryIf: (e) => e is Exception);
@override
Future<bool> set(List<int> status) =>
Expand Down Expand Up @@ -146,11 +147,11 @@ class NeatPeriodicTaskScheduler {
/// this will continue indefinitely. Thus, it is sensible to pick a high
/// [timeout], if the operation is expensive and this can be tolerated.
NeatPeriodicTaskScheduler({
@required String name,
@required Duration interval,
@required Duration timeout,
@required NeatPeriodicTask task,
NeatStatusProvider status,
required String name,
required Duration interval,
required Duration timeout,
required NeatPeriodicTask task,
NeatStatusProvider? status,
Duration minCycle = const Duration(minutes: 5),
Duration maxCycle = const Duration(hours: 3),
}) : _name = name,
Expand All @@ -160,10 +161,6 @@ class NeatPeriodicTaskScheduler {
_statusProvider = status ?? _InMemoryNeatStatusProvider(),
_minCycle = minCycle,
_maxCycle = maxCycle {
ArgumentError.checkNotNull(name, 'name');
ArgumentError.checkNotNull(interval, 'interval');
ArgumentError.checkNotNull(timeout, 'timeout');
ArgumentError.checkNotNull(task, 'task');
if (maxCycle <= minCycle) {
throw ArgumentError.value(
maxCycle, 'maxCycle', 'maxCycle must larger than minCycle');
Expand Down
38 changes: 21 additions & 17 deletions neat_periodic_task/lib/src/neat_status.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,25 @@ class NeatTaskStatus {
final String owner;

NeatTaskStatus({
this.format,
this.version,
this.state,
this.started,
this.owner,
required this.format,
required this.version,
required this.state,
required this.started,
required this.owner,
});

NeatTaskStatus.create({
this.state,
this.started,
this.owner,
}) : format = formatIdentifier,
required this.state,
required this.started,
required this.owner,
}) : format = formatIdentifier,
version = currentVersion;

/// Create a new [NeatTaskStatus] updating the given values.
NeatTaskStatus update({
String state,
DateTime started,
String owner,
String? state,
DateTime? started,
String? owner,
}) {
return NeatTaskStatus(
format: formatIdentifier,
Expand All @@ -90,17 +90,21 @@ class NeatTaskStatus {
owner: '-',
);

factory NeatTaskStatus.deserialize(List<int> bytes) {
factory NeatTaskStatus.deserialize(List<int>? bytes) {
if (bytes == null) {
return _initial();
}

NeatTaskStatus val;
try {
val = _$NeatTaskStatusFromJson(json.fuse(utf8).decode(bytes));
if (val == null ||
val.format != formatIdentifier ||
val.version < currentVersion) {
final raw = json.fuse(utf8).decode(bytes);
if (raw == null) {
return _initial();
}
val = _$NeatTaskStatusFromJson(
raw as Map<String, dynamic>,
);
if (val.format != formatIdentifier || val.version < currentVersion) {
return _initial();
}
return val;
Expand Down
6 changes: 2 additions & 4 deletions neat_periodic_task/lib/src/neat_status.g.dart

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

3 changes: 2 additions & 1 deletion neat_periodic_task/mono_pkg.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
dart:
- stable
# Enable when 2.12.0 has shipped
#- stable
- dev
stages:
- analyze:
Expand Down
22 changes: 11 additions & 11 deletions neat_periodic_task/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
name: neat_periodic_task
version: 1.0.1
version: 2.0.0
description: |
Auxiliary classes for reliably running a periodic task in a long-running
process such as web-server.
homepage: https://github.com/google/dart-neats/tree/master/neat_periodic_task
repository: https://github.com/google/dart-neats.git
issue_tracker: https://github.com/google/dart-neats/labels/pkg:neat_periodic_task
dependencies:
retry: '>=2.0.0 <4.0.0'
slugid: ^1.0.0
json_annotation: '>=2.0.0 <4.0.0'
meta: ^1.1.7
logging: ^0.11.3+2
collection: ^1.14.11
retry: ^3.1.0
slugid: ^1.1.0
json_annotation: ^4.0.0
meta: ^1.3.0
logging: ^1.0.0
collection: ^1.15.0
dev_dependencies:
test: ^1.5.1
pedantic: ^1.8.0
json_serializable: ^3.2.0
test: ^1.16.5
pedantic: ^1.10.0
build_runner: ^1.3.1
build_verify: ^1.1.1
json_serializable: ^4.0.2
environment:
sdk: '>=2.0.0 <3.0.0'
sdk: '>=2.12.0-0 <3.0.0'

6 changes: 3 additions & 3 deletions neat_periodic_task/test/neat_periodic_task_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ import 'package:logging/logging.dart';
import 'package:collection/collection.dart' show ListEquality;

class _StatusStore {
List<int> _value;
List<int>? _value;

NeatStatusProvider provider() => _StatusStoreNeatStatusProvider(this);
}

class _StatusStoreNeatStatusProvider implements NeatStatusProvider {
final _StatusStore _store;
List<int> _lastRead;
List<int>? _lastRead;
_StatusStoreNeatStatusProvider(this._store);

@override
Future<List<int>> get() async {
Future<List<int>?> get() async {
await Future.delayed(Duration(milliseconds: 1));
_lastRead = _store._value;
return _lastRead;
Expand Down
3 changes: 3 additions & 0 deletions pem/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v2.0.0
* Migrated to null-safety.

## v1.0.1
* Fixed incompability with petitparser version 3.x
* Relaxed dependency constraints on petitparser to `>=2.1.1<4.0.0`.
Expand Down
22 changes: 12 additions & 10 deletions pem/lib/pem.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const _labels = <PemLabel, List<String>>{
PemLabel.certificateRevocationList: ['X509 CRL'],
PemLabel.certificateRequest: [
'CERTIFICATE REQUEST',
'NEW CERTIFICATE REQUEST'
'NEW CERTIFICATE REQUEST',
],
PemLabel.pkcs7: ['PKCS7'],
PemLabel.cms: ['CMS'],
Expand Down Expand Up @@ -192,10 +192,10 @@ List<List<int>> decodePemBlocks(
bool strict = false,
bool unsafeIgnoreLabel = false,
}) {
ArgumentError.checkNotNull(label, 'label');
ArgumentError.checkNotNull(pemString, 'pemString');
ArgumentError.checkNotNull(strict, 'strict');
ArgumentError.checkNotNull(unsafeIgnoreLabel, 'unsafeIgnoreLabel');
final labels = _labels[label];
if (labels == null) {
throw AssertionError('Unkown label');
}

// Pick a parser
final p = strict ? stricttextualmsg : laxtextualmsg;
Expand All @@ -213,11 +213,11 @@ List<List<int>> decodePemBlocks(
continue;
}
// Label much match an allowed alias, if not ignoring
if (!_labels[label].contains(preLabel) && !unsafeIgnoreLabel) {
if (!labels.contains(preLabel) && !unsafeIgnoreLabel) {
continue;
}
// Label much match canonical label name, if we're in strict mode
if (strict && _labels[label].first != preLabel && !unsafeIgnoreLabel) {
if (strict && labels.first != preLabel && !unsafeIgnoreLabel) {
continue;
}

Expand Down Expand Up @@ -246,11 +246,13 @@ List<List<int>> decodePemBlocks(
///
/// [1]: https://tools.ietf.org/html/rfc7468
String encodePemBlock(PemLabel label, List<int> data) {
ArgumentError.checkNotNull(label, 'label');
ArgumentError.checkNotNull(data, 'data');
final labels = _labels[label];
if (labels == null) {
throw AssertionError('Unkown label');
}

final s = StringBuffer();
final L = _labels[label].first;
final L = labels.first;
s.writeln('-----BEGIN $L-----');
final lines = base64.encode(data);
for (var i = 0; i < lines.length; i += 64) {
Expand Down
2 changes: 1 addition & 1 deletion pem/lib/src/helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void _flattenString(dynamic value, StringBuffer target) {
}

/// Create a [Parser] that ignores output from [p] and return `null`.
Parser<String> ignore<T>(Parser<T> p) => p.map((_) => null);
Parser<String?> ignore<T>(Parser<T> p) => p.map((_) => null);

/// Create a [Parser] that flattens all strings in the result from [p].
Parser<String> flatten(Parser<dynamic> p) => p.map((value) {
Expand Down
2 changes: 1 addition & 1 deletion pem/mono_pkg.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dart:
- stable
#- stable # enable when 2.12 has shipped
- dev
stages:
- analyze:
Expand Down
10 changes: 5 additions & 5 deletions pem/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: pem
version: 1.0.1
version: 2.0.0
description: |
PEM encoding/decoding of textual keys following RFC 7468,
supporting both lax/strict-mode, and certificates chains of concatenated
Expand All @@ -8,10 +8,10 @@ homepage: https://github.com/google/dart-neats/tree/master/pem
repository: https://github.com/google/dart-neats.git
issue_tracker: https://github.com/google/dart-neats/labels/pkg:pem
dependencies:
petitparser: '>=2.1.1<4.0.0'
petitparser: ^4.0.2
dev_dependencies:
test: ^1.5.1
pedantic: ^1.4.0
test: ^1.16.5
pedantic: ^1.10.0
environment:
sdk: '>=2.0.0 <3.0.0'
sdk: '>=2.12.0-0 <3.0.0'

2 changes: 1 addition & 1 deletion slugid/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## v1.1.0-null-safety.0
## v1.1.0
* Ported to null-safety without breaking changes.
* Annotated `Slugid` with `@sealed` from `package:meta`.

Expand Down
8 changes: 1 addition & 7 deletions slugid/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: slugid
version: 1.1.0-null-safety.0
version: 1.1.0
description: |
A URL-safe base64 encoding for UUIDv4 stripped of padding. Useful when
embedding short random UUIDs in URLs.
Expand All @@ -14,9 +14,3 @@ dev_dependencies:
pedantic: ^1.10.0-nullsafety.3
environment:
sdk: '>=2.12.0-0 <3.0.0'
dependency_overrides:
# Until shelf (required by test) moves to convert 3.x we need this override
# it has no effect for consumers, and if they don't use package:test they
# should have no issues, they probably do, and can use an override or wait
# for shelf/test to move to convert 3.x
convert: ^3.0.0-nullsafety.0

0 comments on commit aeb723e

Please sign in to comment.