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

Deprecation warning in default UuidValue constructor #99

Merged
merged 2 commits into from
Nov 6, 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

v4.2.0

* **[BREAKING CHANGE]** Deprecate default/empty `UuidValue` constructor because it has a different behavior from the 3.x package version.
Use `UuidValue.fromString()` instead, which has the same behavior. If you need to define a const `UuidValue` you can use `UuidValue.raw()`, but making sure the value is lowercase.

v4.1.0

* **[BREAKING CHANGE]** In order to enforce lowercase strings in `UuidValue`, I have made the default const constructor private, and added a `fromString` factory constructor. Please migrate any direct `UuidValue()` usage to `UuidValue.fromString()` or `UuidValue.withValidation()`.
Expand Down
32 changes: 19 additions & 13 deletions lib/uuid_value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ class UuidValue {

/// fromString() creates a UuidValue from a [String] with no validation.
factory UuidValue.fromString(String uuid) {
return UuidValue(uuid.toLowerCase());
return UuidValue.raw(uuid.toLowerCase());
}

/// fromByteList() creates a UuidValue from a [Uint8List] of bytes.
factory UuidValue.fromByteList(Uint8List byteList, {int? offset}) {
return UuidValue(UuidParsing.unparse(byteList, offset: offset ?? 0));
return UuidValue.raw(UuidParsing.unparse(byteList, offset: offset ?? 0));
}

/// fromList() creates a UuidValue from a [List<int>] of bytes.
factory UuidValue.fromList(List<int> byteList, {int? offset}) {
return UuidValue(UuidParsing.unparse(byteList, offset: offset ?? 0));
return UuidValue.raw(UuidParsing.unparse(byteList, offset: offset ?? 0));
}

/// withValidation() creates a UuidValue from a [uuid] string.
Expand All @@ -28,23 +28,29 @@ class UuidValue {
/// Throws [FormatException] if the UUID is invalid.
factory UuidValue.withValidation(String uuid,
[ValidationMode validationMode = ValidationMode.strictRFC4122]) {
final uuidValue = UuidValue(uuid.toLowerCase());
final uuidValue = UuidValue.fromString(uuid);
uuidValue.validate(validationMode);
return uuidValue;
}

static const dns = UuidValue(Uuid.NAMESPACE_DNS);
static const url = UuidValue(Uuid.NAMESPACE_URL);
static const oid = UuidValue(Uuid.NAMESPACE_OID);
static const x500 = UuidValue(Uuid.NAMESPACE_X500);
static const nil = UuidValue(Uuid.NAMESPACE_NIL);
static const dns = UuidValue.raw(Uuid.NAMESPACE_DNS);
static const url = UuidValue.raw(Uuid.NAMESPACE_URL);
static const oid = UuidValue.raw(Uuid.NAMESPACE_OID);
static const x500 = UuidValue.raw(Uuid.NAMESPACE_X500);
static const nil = UuidValue.raw(Uuid.NAMESPACE_NIL);

/// UuidValue() Constructor for creating a uuid value.
///
/// WARNING: Please do not use this directly, use [UuidValue.fromString]
/// or [UuidValue.withValidation]
/// Creates a UuidValue by taking directly the internal string representation of the [uuid],
/// which is expected to be lowercase.
///
/// You can use [UuidValue.fromString] instead, which will lowercase the uuid string for you or
/// [UuidValue.withValidation] if you need validation of the created UUIDs.
const UuidValue.raw(this.uuid);

/// Takes in a string representation of a [uuid] to wrap.
@Deprecated(
'Use UuidValue.fromString() instead. If you need to define a const UuidValue '
'you can use UuidValue.raw(), but making sure the value is lowercase.',
)
const UuidValue(this.uuid);

/// validate() validates the internal string representation of the uuid.
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: uuid
version: 4.1.0
version: 4.2.0
description: >
RFC4122 (v1, v4, v5, v6, v7, v8) UUID Generator and Parser for Dart
documentation: https://daegalus.github.io/dart-uuid/index.html
Expand Down
Loading