Skip to content

Commit

Permalink
RDART-991: Rename Key enum (#1613)
Browse files Browse the repository at this point in the history
* Rename Key to BsonKey to avoid conflict with flutter Key class

* Update EJson CHANGELOG

* Update EJson version

* Update dependency constraints
  • Loading branch information
nielsenko authored Apr 2, 2024
1 parent 0d8e6d5 commit 92fd50e
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 30 deletions.
4 changes: 4 additions & 0 deletions packages/CHANGELOG.ejson.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.0

- Rename `Key` class to `BsonKey` to avoid common conflict with flutter

## 0.2.0-pre.1

- First published version.
Expand Down
10 changes: 5 additions & 5 deletions packages/ejson/lib/src/decoding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const _commonDecoders = {
bool: _decodeBool,
DateTime: _decodeDate,
Defined: _decodeDefined,
Key: _decodeKey,
BsonKey: _decodeKey,
Map: _decodeDocument,
double: _decodeDouble,
num: _decodeNum,
Expand All @@ -45,7 +45,7 @@ final _decoders = () {
TypePlus.addFactory(undefinedOr);
TypePlus.addFactory(<T>(dynamic f) => f<Defined<T>>(), superTypes: [undefinedOr]);
TypePlus.addFactory(<T>(dynamic f) => f<Undefined<T>>(), superTypes: [undefinedOr]);
TypePlus.add<Key>();
TypePlus.add<BsonKey>();
TypePlus.add<ObjectId>();
TypePlus.add<Uint8List>();
TypePlus.add<Uuid>();
Expand Down Expand Up @@ -173,10 +173,10 @@ int _decodeInt(EJsonValue ejson) {
};
}

Key _decodeKey(EJsonValue ejson) {
BsonKey _decodeKey(EJsonValue ejson) {
return switch (ejson) {
{'\$minKey': 1} => Key.min,
{'\$maxKey': 1} => Key.max,
{'\$minKey': 1} => BsonKey.min,
{'\$maxKey': 1} => BsonKey.max,
_ => raiseInvalidEJson(ejson),
};
}
Expand Down
8 changes: 4 additions & 4 deletions packages/ejson/lib/src/encoding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ EJsonValue _encodeAny(Object? value) {
Defined<dynamic> d => _encodeDefined(d),
double d => _encodeDouble(d),
int i => _encodeInt(i),
Key k => _encodeKey(k),
BsonKey k => _encodeKey(k),
Uint8List b => _encodeBinary(b, subtype: '00'),
Iterable<dynamic> l => _encodeArray(l),
Map<dynamic, dynamic> m => _encodeDocument(m),
Expand Down Expand Up @@ -108,7 +108,7 @@ EJsonValue _encodeInt(int value, {IntFormat? forcedFormat}) {
}
}

EJsonValue _encodeKey(Key key) => {'\$${key.name}Key': 1};
EJsonValue _encodeKey(BsonKey key) => {'\$${key.name}Key': 1};

@pragma('vm:prefer-inline')
EJsonValue _encodeString(String value) => value;
Expand Down Expand Up @@ -168,8 +168,8 @@ extension IntEJsonEncoderExtension on int {
EJsonValue toEJson({IntFormat? forcedFormat}) => _encodeInt(this, forcedFormat: forcedFormat);
}

extension KeyEJsonEncoderExtension on Key {
/// Converts this [Key] to EJson
extension KeyEJsonEncoderExtension on BsonKey {
/// Converts this [BsonKey] to EJson
@pragma('vm:prefer-inline')
EJsonValue toEJson() => _encodeKey(this);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ejson/lib/src/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ enum EJsonType {

/// See [MaxKey](https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-MaxKey)
/// and [MinKey](https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-MinKey)
enum Key { min, max }
enum BsonKey { min, max }

sealed class UndefinedOr<T> {
const UndefinedOr();
Expand Down
6 changes: 3 additions & 3 deletions packages/ejson/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ topics:
- build-runner
- codegen

version: 0.2.0-pre.1
version: 0.3.0
repository: https://github.com/realm/realm-dart/ejson/packages/ejson

environment:
sdk: ^3.0.0

dependencies:
collection: ^1.17.0
ejson_annotation: ^0.2.0-pre.1
ejson_annotation: ^0.3.0
objectid: ^3.0.0
sane_uuid: ^1.0.0-alpha.5
type_plus: ^2.0.0

dev_dependencies:
build_runner: ^2.0.0
ejson_generator: ^0.2.0-pre.1
ejson_generator: ^0.3.0
lints: ^3.0.0
test: ^1.21.0
10 changes: 5 additions & 5 deletions packages/ejson/test/ejson_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ void main() {
expect({'a': 1, 'b': 2}.toEJson(), toEJson({'a': 1, 'b': 2}));
expect(DateTime(1974, 4, 10, 2, 42, 12, 202).toEJson(), toEJson(DateTime(1974, 4, 10, 2, 42, 12, 202)));
expect((#sym).toEJson(), toEJson(#sym));
expect(Key.max.toEJson(), toEJson(Key.max));
expect(Key.min.toEJson(), toEJson(Key.min));
expect(BsonKey.max.toEJson(), toEJson(BsonKey.max));
expect(BsonKey.min.toEJson(), toEJson(BsonKey.min));
expect(undefined.toEJson(), toEJson(undefined));
expect(const Undefined<int?>().toEJson(), toEJson(const Undefined<int?>()));
expect(Undefined<int?>().toEJson(), toEJson(Undefined<int?>()));
Expand All @@ -108,7 +108,7 @@ void main() {
_invalidTestCase<double>({'\$numberDouble': 'foobar'});
_invalidTestCase<double>();
_invalidTestCase<int>();
_invalidTestCase<Key>();
_invalidTestCase<BsonKey>();
_invalidTestCase<List<int>>();
_invalidTestCase<Map<int, int>>([]);
_invalidTestCase<Null>();
Expand Down Expand Up @@ -188,8 +188,8 @@ void main() {
: {'\$date': time.toIso8601String()},
);
_testCase(#sym, {'\$symbol': 'sym'});
_testCase(Key.max, {'\$maxKey': 1});
_testCase(Key.min, {'\$minKey': 1});
_testCase(BsonKey.max, {'\$maxKey': 1});
_testCase(BsonKey.min, {'\$minKey': 1});
_testCase(undefined, {'\$undefined': 1});
_testCase(const Undefined<int?>(), {'\$undefined': 1});
_testCase(Undefined<int?>(), {'\$undefined': 1});
Expand Down
4 changes: 2 additions & 2 deletions packages/ejson_analyzer/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name: ejson_analyzer
description: A starting point for Dart libraries or applications.

version: 0.2.0-pre.1
version: 0.3.0
repository: https://github.com/realm/realm-dart/ejson/packages/ejson_analyzer

environment:
sdk: ^3.0.0

dependencies:
analyzer: ^6.0.0
ejson_annotation: ^0.2.0-pre.1
ejson_annotation: ^0.3.0
source_gen: ^1.3.2

dev_dependencies:
Expand Down
2 changes: 1 addition & 1 deletion packages/ejson_annotation/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: >-
BSON is a binary format used to store JSON-like documents efficiently.
EJSON extends JSON defining how all BSON types should be represented in JSON.
version: 0.2.0-pre.1
version: 0.3.0
repository: https://github.com/realm/realm-dart/ejson/packages/ejson_annotation

environment:
Expand Down
8 changes: 4 additions & 4 deletions packages/ejson_generator/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ topics:
- build-runner
- codegen

version: 0.2.0-pre.1
version: 0.3.0
repository: https://github.com/realm/realm-dart/ejson/packages/ejson_generator

environment:
Expand All @@ -21,15 +21,15 @@ environment:
dependencies:
analyzer: ^6.0.0
build: ^2.4.0
ejson_analyzer: ^0.2.0-pre.1
ejson_analyzer: ^0.3.0
source_gen: ^1.3.2

dev_dependencies:
build_runner: ^2.4.4
build_test: ^2.1.7
dart_style: ^2.3.1
ejson: ^0.2.0-pre.1
ejson_annotation: ^0.2.0-pre.1
ejson: ^0.3.0
ejson_annotation: ^0.3.0
lints: ^3.0.0
meta: ^1.9.1
test: ^1.21.0
4 changes: 2 additions & 2 deletions packages/ejson_lint/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ environment:
sdk: ^3.0.0

dependencies:
ejson_annotation: ^0.2.0-pre.1
ejson_annotation: ^0.3.0

dev_dependencies:
custom_lint: ^0.6.2
ejson_lint: ^0.2.0-pre.1
ejson_lint: ^0.3.0
lints: ^3.0.0


4 changes: 2 additions & 2 deletions packages/ejson_lint/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: ejson_lint
description: A starting point for Dart libraries or applications.

version: 0.2.0-pre.1
version: 0.3.0
repository: https://github.com/realm/realm-dart/ejson/packages/ejson_lint

environment:
Expand All @@ -10,7 +10,7 @@ environment:
dependencies:
analyzer: ^6.0.0
custom_lint_builder: ^0.6.2
ejson_analyzer: ^0.2.0-pre.1
ejson_analyzer: ^0.3.0

dev_dependencies:
lints: ^3.0.0
Expand Down
2 changes: 1 addition & 1 deletion packages/realm_dart/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies:
build_cli_annotations: ^2.0.0
collection: ^1.16.0
crypto: ^3.0.0
ejson: ^0.2.0-pre.1
ejson: ^0.3.0
ffi: ^2.0.1
json_annotation: ^4.7.0
logging: ^1.2.0
Expand Down

0 comments on commit 92fd50e

Please sign in to comment.