Skip to content

Commit

Permalink
Compensate for breaking change in sane_uuid (#1730)
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsenko authored Jun 24, 2024
1 parent 16f34e5 commit b109d8c
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 10 deletions.
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

0 comments on commit b109d8c

Please sign in to comment.