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

RDART-1059: Compensate for breaking change in sane_uuid #1730

Merged
merged 1 commit into from
Jun 24, 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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
* None

### Fixed
* None
* [sane_uuid](https://pub.dev/packages/sane_uuid) 1.0.0 was released, which has a few minor breaking change as compared to to 1.0.0-rc.5 that impact realm:
- The `Uuid.fromBytes` factory now accepts a `Uint8List` instead of a `ByteBuffer`
- The type of `Uuid.bytes` has changed to `Uint8List`.

Issue [#1729](https://github.com/realm/realm-dart/issues/1729)

### Compatibility
* Realm Studio: 15.0.0 or later.
Expand Down
2 changes: 1 addition & 1 deletion packages/ejson/lib/src/decoding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ UndefinedOr<T> _decodeUndefinedOr<T>(EJsonValue ejson) {

Uuid _decodeUuid(EJsonValue ejson) {
return switch (ejson) {
{'\$binary': {'base64': String s, 'subType': '04'}} => Uuid.fromBytes(base64.decode(s).buffer),
{'\$binary': {'base64': String s, 'subType': '04'}} => Uuid.fromBytes(base64.decode(s)),
_ => raiseInvalidEJson(ejson),
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ejson/lib/src/encoding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ EJsonValue _encodeSymbol(Symbol value) => {'\$symbol': value.name};

EJsonValue _encodeUndefined(Undefined<dynamic> undefined) => {'\$undefined': 1};

EJsonValue _encodeUuid(Uuid uuid) => _encodeBinary(uuid.bytes.asUint8List(), subtype: '04');
EJsonValue _encodeUuid(Uuid uuid) => _encodeBinary(uuid.bytes, subtype: '04');

EJsonValue _encodeBinary(Uint8List buffer, {required String subtype}) => {
'\$binary': {
Expand Down
2 changes: 1 addition & 1 deletion packages/ejson/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies:
collection: ^1.17.0
ejson_annotation: ^0.3.0
objectid: ^3.0.0
sane_uuid: ^1.0.0-alpha.5
sane_uuid: ^1.0.0
type_plus: ^2.0.0

dev_dependencies:
Expand Down
4 changes: 2 additions & 2 deletions packages/ejson/test/ejson_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void main() {
expect(ObjectId.fromValues(1, 2, 3).toEJson(), toEJson(ObjectId.fromValues(1, 2, 3)));
final uuid = Uuid.v4();
expect(uuid.toEJson(), toEJson(uuid));
final bytes = uuid.bytes.asUint8List();
final bytes = uuid.bytes;
expect(bytes.toEJson(), toEJson(bytes));
});

Expand Down Expand Up @@ -200,7 +200,7 @@ void main() {
_testCase(ObjectId.fromValues(1, 2, 3), {'\$oid': '000000000000000002000003'});
final uuid = Uuid.v4();
_testCase(uuid, {
'\$binary': {'base64': base64.encode(uuid.bytes.asUint8List()), 'subType': '04'}
'\$binary': {'base64': base64.encode(uuid.bytes), 'subType': '04'}
});
final uint8list = Uint8List.fromList(List.generate(32, (i) => i));
_testCase(uint8list, {
Expand Down
2 changes: 1 addition & 1 deletion packages/realm_common/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ environment:
dependencies:
collection: ^1.18.0
objectid: ^3.0.0
sane_uuid: ^1.0.0-alpha.5
sane_uuid: ^1.0.0

dev_dependencies:
lints: ^3.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extension RealmValueEx on realm_value_t {
return ObjectId.fromBytes(values.object_id.bytes.toList(12));
case realm_value_type.RLM_TYPE_UUID:
final listInt = values.uuid.bytes.toList(16);
return Uuid.fromBytes(Uint8List.fromList(listInt).buffer);
return Uuid.fromBytes(Uint8List.fromList(listInt));
case realm_value_type.RLM_TYPE_LIST:
if (getList == null || realm == null) {
throw RealmException('toDartValue called with a list argument but without a list getter');
Expand Down
2 changes: 1 addition & 1 deletion packages/realm_dart/lib/src/handles/native/to_native.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void _intoRealmValue(Object? value, realm_value realmValue, Allocator allocator)
}
realmValue.type = realm_value_type.RLM_TYPE_OBJECT_ID;
} else if (value is Uuid) {
final bytes = value.bytes.asUint8List();
final bytes = value.bytes;
for (var i = 0; i < 16; i++) {
realmValue.values.uuid.bytes[i] = bytes[i];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/realm_dart/test/indexed_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void main() {
stringFactory(int i) => '${i.hashCode} $i';
timestampFactory(int i) => DateTime.fromMillisecondsSinceEpoch(i.hashCode);
objectIdFactory(int i) => ObjectId.fromValues(i.hashCode * 1000000, i.hashCode, i);
uuidFactory(int i) => Uuid.fromBytes(Uint8List(16).buffer..asByteData().setInt64(0, i.hashCode));
uuidFactory(int i) => Uuid.fromBytes(Uint8List(16)..buffer.asByteData().setInt64(0, i.hashCode));

// skip timestamp for now, as timestamps are not indexed properly it seems
final indexedTestData = [
Expand Down
Loading