From 3ba78cb22b88eaa007bb57623491b291f380bb3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Fri, 26 May 2023 16:11:21 +0200 Subject: [PATCH 001/153] Worthy of first commit --- .gitignore | 3 + .vscode/settings.json | 5 + CHANGELOG.md | 3 + README.md | 2 + analysis_options.yaml | 30 ++ bin/ejson.dart | 3 + lib/ejson.dart | 4 + lib/src/annotations.dart | 41 +++ lib/src/decoding.dart | 228 +++++++++++++++ lib/src/encoding.dart | 162 +++++++++++ lib/src/types.dart | 40 +++ pubspec.lock | 405 ++++++++++++++++++++++++++ pubspec.yaml | 19 ++ test/ejson_serialization_setup.g.dart | 15 + test/ejson_test.dart | 262 +++++++++++++++++ test/person.dart | 34 +++ test/person.g.dart | 34 +++ 17 files changed, 1290 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/settings.json create mode 100644 CHANGELOG.md create mode 100644 README.md create mode 100644 analysis_options.yaml create mode 100644 bin/ejson.dart create mode 100644 lib/ejson.dart create mode 100644 lib/src/annotations.dart create mode 100644 lib/src/decoding.dart create mode 100644 lib/src/encoding.dart create mode 100644 lib/src/types.dart create mode 100644 pubspec.lock create mode 100644 pubspec.yaml create mode 100644 test/ejson_serialization_setup.g.dart create mode 100644 test/ejson_test.dart create mode 100644 test/person.dart create mode 100644 test/person.g.dart diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..3a8579040 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# https://dart.dev/guides/libraries/private-files +# Created by `dart pub` +.dart_tool/ diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..4f32ba4b6 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "cSpell.words": [ + "ejson" + ] +} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..effe43c82 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0 + +- Initial version. diff --git a/README.md b/README.md new file mode 100644 index 000000000..3816eca3a --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +A sample command-line application with an entrypoint in `bin/`, library code +in `lib/`, and example unit test in `test/`. diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 000000000..dee8927aa --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,30 @@ +# This file configures the static analysis results for your project (errors, +# warnings, and lints). +# +# This enables the 'recommended' set of lints from `package:lints`. +# This set helps identify many issues that may lead to problems when running +# or consuming Dart code, and enforces writing Dart using a single, idiomatic +# style and format. +# +# If you want a smaller set of lints you can change this to specify +# 'package:lints/core.yaml'. These are just the most critical lints +# (the recommended set includes the core lints). +# The core lints are also what is used by pub.dev for scoring packages. + +include: package:lints/recommended.yaml + +# Uncomment the following section to specify additional rules. + +# linter: +# rules: +# - camel_case_types + +# analyzer: +# exclude: +# - path/to/excluded/files/** + +# For more information about the core and recommended set of lints, see +# https://dart.dev/go/core-lints + +# For additional information about configuring this file, see +# https://dart.dev/guides/language/analysis-options diff --git a/bin/ejson.dart b/bin/ejson.dart new file mode 100644 index 000000000..e5e128a37 --- /dev/null +++ b/bin/ejson.dart @@ -0,0 +1,3 @@ +void main(List args) { + print('Hello world!'); +} diff --git a/lib/ejson.dart b/lib/ejson.dart new file mode 100644 index 000000000..83a31853e --- /dev/null +++ b/lib/ejson.dart @@ -0,0 +1,4 @@ +export 'src/annotations.dart'; +export 'src/decoding.dart'; +export 'src/encoding.dart'; +export 'src/types.dart'; diff --git a/lib/src/annotations.dart b/lib/src/annotations.dart new file mode 100644 index 000000000..5729259f2 --- /dev/null +++ b/lib/src/annotations.dart @@ -0,0 +1,41 @@ +/// Annotation to mark a class for extended json (ejson) serialization +const ejson = EJson(); + +/// Annotation to mark a property to be ignored wrt. ejson serialization +const ignore = Ignore(); + +/// Annotation to mark a class for extended json (ejson) serialization +class EJson { + const EJson(); +} + +/// Annotation to mark a property to be ignored wrt. ejson serialization +class Ignore { + const Ignore(); +} + +enum EJsonType { + array, + binary, + boolean, + date, + decimal128, + document, + double, + int32, + int64, + maxKey, + minKey, + objectId, + string, + symbol, + nil, // aka. null + undefined, + // TODO: The following is not supported yet + // code, + // codeWithScope, + // databasePointer, + // databaseRef, + // regularExpression, + // timestamp, // Why? Isn't this just a date? +} diff --git a/lib/src/decoding.dart b/lib/src/decoding.dart new file mode 100644 index 000000000..16d740e75 --- /dev/null +++ b/lib/src/decoding.dart @@ -0,0 +1,228 @@ +import 'package:collection/collection.dart'; +import 'package:type_plus/type_plus.dart'; + +import 'types.dart'; + +const commonDecoders = { + dynamic: _decodeAny, + Null: _decodeNull, + Object: _decodeAny, + List: _decodeArray, + bool: _decodeBool, + DateTime: _decodeDate, + Defined: _decodeDefined, + Key: _decodeKey, + Map: _decodeDocument, + double: _decodeDouble, + num: _decodeNum, + int: _decodeInt, + String: _decodeString, + Symbol: _decodeSymbol, + Undefined: _decodeUndefined, + UndefinedOr: _decodeUndefinedOr, +}; + +var customDecoders = const {}; + +// if registerSerializableTypes not called +final decoders = () { + // register extra common types on first access + undefinedOr(f) => f>(); + TypePlus.addFactory(undefinedOr); + TypePlus.addFactory((f) => f>(), superTypes: [undefinedOr]); + TypePlus.addFactory((f) => f>(), superTypes: [undefinedOr]); + TypePlus.add(); + + return CombinedMapView([customDecoders, commonDecoders]); +}(); + +T fromEJson(EJsonValue ejson) { + final type = T; + final nullable = type.isNullable; + final decoder = nullable ? _decodeNullable : decoders[type.base]; + if (decoder == null) { + throw MissingDecoder(ejson, type); + } + final args = nullable ? [type.nonNull] : type.args; + if (args.isEmpty) { + return decoder(ejson); // minor optimization + } + return decoder.callWith(typeArguments: args, parameters: [ejson]); +} + +// Important to return `T` as opposed to [Never] for type inference to work +T raiseInvalidEJson(Object? value) => throw InvalidEJson(value); + +dynamic _decodeAny(EJsonValue ejson) { + return switch (ejson) { + null => null, + bool b => b, + double d => d, // relaxed mode + int i => i, // relaxed mode + String s => s, + {'\$date': _} => _decodeDate(ejson), + {'\$maxKey': _} => _decodeKey(ejson), + {'\$minKey': _} => _decodeKey(ejson), + {'\$numberDouble': _} => _decodeDouble(ejson), + {'\$numberInt': _} => _decodeInt(ejson), + {'\$numberLong': _} => _decodeInt(ejson), + {'\$regex': _} => _decodeString(ejson), + {'\$symbol': _} => _decodeSymbol(ejson), + {'\$undefined': _} => _decodeUndefined(ejson), + List _ => _decodeArray(ejson), + Map _ => _tryDecodeCustom(ejson) ?? + _decodeDocument(ejson), // other maps goes last!! + _ => raiseInvalidEJson(ejson), + }; +} + +dynamic _tryDecodeCustom(json) { + for (final decoder in customDecoders.values) { + try { + return decoder(json); + } catch (_) { + // ignore + } + } + return null; +} + +List _decodeArray(EJsonValue ejson) { + return switch (ejson) { + Iterable i => i.map((ejson) => fromEJson(ejson)).toList(), + _ => raiseInvalidEJson(ejson), + }; +} + +bool _decodeBool(EJsonValue ejson) { + return switch (ejson) { + bool b => b, + _ => raiseInvalidEJson(ejson), + }; +} + +DateTime _decodeDate(EJsonValue ejson) { + return switch (ejson) { + {'\$date': String s} => DateTime.parse(s), // relaxed mode + {'\$date': {'\$numberLong': int i}} => + DateTime.fromMillisecondsSinceEpoch(i), + _ => raiseInvalidEJson(ejson), + }; +} + +Defined _decodeDefined(EJsonValue ejson) { + if (ejson case {'\$undefined': 1}) raiseInvalidEJson(ejson); + return Defined(fromEJson(ejson)); +} + +Map _decodeDocument(EJsonValue ejson) { + return switch (ejson) { + Map m => m.map((key, value) => MapEntry(key as K, fromEJson(value))), + _ => raiseInvalidEJson(ejson), + }; +} + +double _decodeDouble(EJsonValue ejson) { + return switch (ejson) { + double d => d, // relaxed mode + {'\$numberDouble': double d} => d, + {'\$numberDouble': String s} => switch (s) { + 'NaN' => double.nan, + 'Infinity' => double.infinity, + '-Infinity' => double.negativeInfinity, + _ => raiseInvalidEJson(ejson), + }, + _ => raiseInvalidEJson(ejson), + }; +} + +int _decodeInt(EJsonValue ejson) { + return switch (ejson) { + int i => i, // relaxed mode + {'\$numberInt': int i} => i, + {'\$numberLong': int i} => i, + _ => raiseInvalidEJson(ejson) + }; +} + +Key _decodeKey(EJsonValue ejson) { + return switch (ejson) { + {'\$minKey': 1} => Key.min, + {'\$maxKey': 1} => Key.max, + _ => raiseInvalidEJson(ejson), + }; +} + +// ignore: prefer_void_to_null +Null _decodeNull(EJsonValue ejson) { + return switch (ejson) { + null => null, + _ => raiseInvalidEJson(ejson), + }; +} + +T? _decodeNullable(EJsonValue ejson) { + if (ejson == null) { + return null; + } + return fromEJson(ejson); +} + +num _decodeNum(EJsonValue ejson) { + return switch (ejson) { + num n => n, // relaxed mode + {'\$numberLong': _} => _decodeInt(ejson), + {'\$numberInt': _} => _decodeInt(ejson), + {'\$numberDouble': _} => _decodeDouble(ejson), + _ => raiseInvalidEJson(ejson), + }; +} + +String _decodeString(EJsonValue ejson) => switch (ejson) { + String s => s, + _ => raiseInvalidEJson(ejson), + }; + +Symbol _decodeSymbol(EJsonValue ejson) { + return switch (ejson) { + {'\$symbol': String s} => Symbol(s), + _ => raiseInvalidEJson(ejson), + }; +} + +Undefined _decodeUndefined(EJsonValue ejson) { + return switch (ejson) { + {'\$undefined': 1} => Undefined(), + _ => raiseInvalidEJson(ejson), + }; +} + +UndefinedOr _decodeUndefinedOr(EJsonValue ejson) { + return switch (ejson) { + {'\$undefined': 1} => Undefined(), + _ => _decodeDefined(ejson), + }; +} + +class InvalidEJson implements Exception { + final Object? value; + + InvalidEJson(this.value); + + @override + String toString() => 'Invalid EJson for $T: $value'; +} + +class MissingDecoder implements Exception { + final EJsonValue ejson; + final Type type; + + MissingDecoder(this.ejson, this.type); + + @override + String toString() => 'Missing decoder for $type'; +} + +extension EJsonValueDecoderExtension on EJsonValue { + T to() => fromEJson(this); +} diff --git a/lib/src/encoding.dart b/lib/src/encoding.dart new file mode 100644 index 000000000..5ed9e3892 --- /dev/null +++ b/lib/src/encoding.dart @@ -0,0 +1,162 @@ +import 'package:type_plus/type_plus.dart'; + +import 'types.dart'; + +// No custom encoders, if registerSerializableTypes not called +var customEncoders = const {}; + +var relaxed = false; + +Type typeOfExpression(T value) => T; + +@pragma('vm:prefer-inline') +EJsonValue toEJson(Object? value) => _encodeAny(value); + +EJsonValue _encodeAny(Object? value) { + return switch (value) { + null => null, + bool b => _encodeBool(b), + DateTime d => _encodeDate(d), + Defined d => _encodeDefined(d), + double d => _encodeDouble(d), + int i => _encodeInt(i), + Key k => _encodeKey(k), + List l => _encodeArray(l), + Map m => _encodeDocument(m), + String s => _encodeString(s), + Symbol s => _encodeSymbol(s), + Undefined u => _encodeUndefined(u), + _ => _encodeCustom(value), + }; +} + +EJsonValue _encodeArray(Iterable items) => + items.map((e) => toEJson(e)).toList(); + +EJsonValue _encodeBool(bool value) => value; + +EJsonValue _encodeCustom(Object value) { + final encoder = customEncoders[value.runtimeType.base]; + if (encoder == null) { + throw MissingEncoder(value); + } + return encoder(value); +} + +EJsonValue _encodeDate(DateTime value) { + return switch (relaxed) { + true => {'\$date': value.toIso8601String()}, + false => { + '\$date': {'\$numberLong': value.millisecondsSinceEpoch} + }, + }; +} + +EJsonValue _encodeDefined(Defined defined) => toEJson(defined.value); + +EJsonValue _encodeDocument(Map map) => + map.map((k, v) => MapEntry(k, toEJson(v))); + +EJsonValue _encodeDouble(double value) { + if (value.isNaN) { + return {'\$numberDouble': 'NaN'}; + } + return switch (value) { + double.infinity => {'\$numberDouble': 'Infinity'}, + double.negativeInfinity => {'\$numberDouble': '-Infinity'}, + _ => switch (relaxed) { + true => value, + false => {'\$numberDouble': value}, + } + }; +} + +EJsonValue _encodeInt(int value, {bool long = true}) { + return switch (relaxed) { + true => value, + false => {'\$number${long ? 'Long' : 'Int'}': value}, + }; +} + +EJsonValue _encodeKey(Key key) => {'\$${key.name}Key': 1}; + +@pragma('vm:prefer-inline') +EJsonValue _encodeString(String value) => value; + +EJsonValue _encodeSymbol(Symbol value) => {'\$symbol': value.name}; + +EJsonValue _encodeUndefined(Undefined undefined) => {'\$undefined': 1}; + +class MissingEncoder implements Exception { + final Object value; + + MissingEncoder(this.value); + + @override + String toString() => 'Missing encoder for type ${value.runtimeType} ($value)'; +} + +extension BoolEJsonEncoderExtension on bool { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => _encodeBool(this); +} + +extension DateTimeEJsonEncoderExtension on DateTime { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => _encodeDate(this); +} + +extension DefinedEJsonEncoderExtension on Defined { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => _encodeDefined(this); +} + +extension DoubleEJsonEncoderExtension on double { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => _encodeDouble(this); +} + +extension IntEJsonEncoderExtension on int { + @pragma('vm:prefer-inline') + EJsonValue toEJson({bool long = true}) => _encodeInt(this, long: long); +} + +extension KeyEJsonEncoderExtension on Key { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => _encodeKey(this); +} + +extension ListEJsonEncoderExtension on List { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => _encodeArray(this); +} + +extension MapEJsonEncoderExtension on Map { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => _encodeDocument(this); +} + +extension NullableObjectEJsonEncoderExtension on Object? { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => _encodeAny(this); +} + +extension StringEJsonEncoderExtension on String { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => _encodeString(this); +} + +extension SymbolEJsonEncoderExtension on Symbol { + String get name { + final full = toString(); + return full.substring(8, full.length - 2); + } + + @pragma('vm:prefer-inline') + EJsonValue toEJson() => _encodeSymbol(this); +} + +extension UndefinedEJsonEncoderExtension on Undefined { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => _encodeUndefined(this); +} diff --git a/lib/src/types.dart b/lib/src/types.dart new file mode 100644 index 000000000..ac2430f22 --- /dev/null +++ b/lib/src/types.dart @@ -0,0 +1,40 @@ +// while we wait for +// typedef EJsonValue = Null | String | bool | int | double | List | Map; +typedef EJsonValue = Object?; + +enum Key { min, max } + +sealed class UndefinedOr { + const UndefinedOr(); +} + +final class Defined extends UndefinedOr { + final T value; + + const Defined(this.value); + + @override + bool operator ==(Object other) => + identical(this, other) || other is Defined && value == other.value; + + @override + int get hashCode => value.hashCode; + + @override + String toString() => 'Defined<$T>($value)'; +} + +final class Undefined extends UndefinedOr { + const Undefined(); + + @override + operator ==(Object other) => other is Undefined; + + @override + String toString() => 'Undefined<$T>()'; + + @override + int get hashCode => (Undefined).hashCode; +} + +const undefined = Undefined(); diff --git a/pubspec.lock b/pubspec.lock new file mode 100644 index 000000000..3027d1179 --- /dev/null +++ b/pubspec.lock @@ -0,0 +1,405 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + sha256: ae92f5d747aee634b87f89d9946000c2de774be1d6ac3e58268224348cd0101a + url: "https://pub.dev" + source: hosted + version: "61.0.0" + analyzer: + dependency: "direct main" + description: + name: analyzer + sha256: ea3d8652bda62982addfd92fdc2d0214e5f82e43325104990d4f4c4a2a313562 + url: "https://pub.dev" + source: hosted + version: "5.13.0" + args: + dependency: transitive + description: + name: args + sha256: c372bb384f273f0c2a8aaaa226dad84dc27c8519a691b888725dec59518ad53a + url: "https://pub.dev" + source: hosted + version: "2.4.1" + async: + dependency: transitive + description: + name: async + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" + source: hosted + version: "2.11.0" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + build: + dependency: "direct main" + description: + name: build + sha256: "43865b79fbb78532e4bff7c33087aa43b1d488c4fdef014eaef568af6d8016dc" + url: "https://pub.dev" + source: hosted + version: "2.4.0" + collection: + dependency: "direct main" + description: + name: collection + sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 + url: "https://pub.dev" + source: hosted + version: "1.17.2" + convert: + dependency: transitive + description: + name: convert + sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" + url: "https://pub.dev" + source: hosted + version: "3.1.1" + coverage: + dependency: transitive + description: + name: coverage + sha256: "2fb815080e44a09b85e0f2ca8a820b15053982b2e714b59267719e8a9ff17097" + url: "https://pub.dev" + source: hosted + version: "1.6.3" + crypto: + dependency: transitive + description: + name: crypto + sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab + url: "https://pub.dev" + source: hosted + version: "3.0.3" + dart_style: + dependency: transitive + description: + name: dart_style + sha256: f4f1f73ab3fd2afcbcca165ee601fe980d966af6a21b5970c6c9376955c528ad + url: "https://pub.dev" + source: hosted + version: "2.3.1" + file: + dependency: transitive + description: + name: file + sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" + url: "https://pub.dev" + source: hosted + version: "7.0.0" + frontend_server_client: + dependency: transitive + description: + name: frontend_server_client + sha256: "408e3ca148b31c20282ad6f37ebfa6f4bdc8fede5b74bc2f08d9d92b55db3612" + url: "https://pub.dev" + source: hosted + version: "3.2.0" + glob: + dependency: transitive + description: + name: glob + sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + http_multi_server: + dependency: transitive + description: + name: http_multi_server + sha256: "97486f20f9c2f7be8f514851703d0119c3596d14ea63227af6f7a481ef2b2f8b" + url: "https://pub.dev" + source: hosted + version: "3.2.1" + http_parser: + dependency: transitive + description: + name: http_parser + sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" + url: "https://pub.dev" + source: hosted + version: "4.0.2" + io: + dependency: transitive + description: + name: io + sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e" + url: "https://pub.dev" + source: hosted + version: "1.0.4" + js: + dependency: transitive + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" + lints: + dependency: "direct dev" + description: + name: lints + sha256: "6b0206b0bf4f04961fc5438198ccb3a885685cd67d4d4a32cc20ad7f8adbe015" + url: "https://pub.dev" + source: hosted + version: "2.1.0" + logging: + dependency: transitive + description: + name: logging + sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + matcher: + dependency: transitive + description: + name: matcher + sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + url: "https://pub.dev" + source: hosted + version: "0.12.16" + meta: + dependency: transitive + description: + name: meta + sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + url: "https://pub.dev" + source: hosted + version: "1.9.1" + mime: + dependency: transitive + description: + name: mime + sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e + url: "https://pub.dev" + source: hosted + version: "1.0.4" + node_preamble: + dependency: transitive + description: + name: node_preamble + sha256: "6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db" + url: "https://pub.dev" + source: hosted + version: "2.0.2" + package_config: + dependency: transitive + description: + name: package_config + sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd" + url: "https://pub.dev" + source: hosted + version: "2.1.0" + path: + dependency: transitive + description: + name: path + sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + url: "https://pub.dev" + source: hosted + version: "1.8.3" + pool: + dependency: transitive + description: + name: pool + sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a" + url: "https://pub.dev" + source: hosted + version: "1.5.1" + pub_semver: + dependency: transitive + description: + name: pub_semver + sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + shelf: + dependency: transitive + description: + name: shelf + sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4 + url: "https://pub.dev" + source: hosted + version: "1.4.1" + shelf_packages_handler: + dependency: transitive + description: + name: shelf_packages_handler + sha256: "89f967eca29607c933ba9571d838be31d67f53f6e4ee15147d5dc2934fee1b1e" + url: "https://pub.dev" + source: hosted + version: "3.0.2" + shelf_static: + dependency: transitive + description: + name: shelf_static + sha256: a41d3f53c4adf0f57480578c1d61d90342cd617de7fc8077b1304643c2d85c1e + url: "https://pub.dev" + source: hosted + version: "1.1.2" + shelf_web_socket: + dependency: transitive + description: + name: shelf_web_socket + sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1" + url: "https://pub.dev" + source: hosted + version: "1.0.4" + source_gen: + dependency: "direct main" + description: + name: source_gen + sha256: "373f96cf5a8744bc9816c1ff41cf5391bbdbe3d7a96fe98c622b6738a8a7bd33" + url: "https://pub.dev" + source: hosted + version: "1.3.2" + source_map_stack_trace: + dependency: transitive + description: + name: source_map_stack_trace + sha256: "84cf769ad83aa6bb61e0aa5a18e53aea683395f196a6f39c4c881fb90ed4f7ae" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + source_maps: + dependency: transitive + description: + name: source_maps + sha256: "708b3f6b97248e5781f493b765c3337db11c5d2c81c3094f10904bfa8004c703" + url: "https://pub.dev" + source: hosted + version: "0.10.12" + source_span: + dependency: transitive + description: + name: source_span + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" + source: hosted + version: "1.10.0" + stack_trace: + dependency: transitive + description: + name: stack_trace + sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + url: "https://pub.dev" + source: hosted + version: "1.11.0" + stream_channel: + dependency: transitive + description: + name: stream_channel + sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + string_scanner: + dependency: transitive + description: + name: string_scanner + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + term_glyph: + dependency: transitive + description: + name: term_glyph + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" + source: hosted + version: "1.2.1" + test: + dependency: "direct dev" + description: + name: test + sha256: "13b41f318e2a5751c3169137103b60c584297353d4b1761b66029bae6411fe46" + url: "https://pub.dev" + source: hosted + version: "1.24.3" + test_api: + dependency: transitive + description: + name: test_api + sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8" + url: "https://pub.dev" + source: hosted + version: "0.6.0" + test_core: + dependency: transitive + description: + name: test_core + sha256: "99806e9e6d95c7b059b7a0fc08f07fc53fabe54a829497f0d9676299f1e8637e" + url: "https://pub.dev" + source: hosted + version: "0.5.3" + type_plus: + dependency: "direct main" + description: + name: type_plus + sha256: "28cbdcb9d2118f65881d11158ecb4d9db8b78589969e3168061d06963ef3ca59" + url: "https://pub.dev" + source: hosted + version: "2.0.0" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c + url: "https://pub.dev" + source: hosted + version: "1.3.2" + vm_service: + dependency: transitive + description: + name: vm_service + sha256: f3743ca475e0c9ef71df4ba15eb2d7684eecd5c8ba20a462462e4e8b561b2e11 + url: "https://pub.dev" + source: hosted + version: "11.6.0" + watcher: + dependency: transitive + description: + name: watcher + sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8" + url: "https://pub.dev" + source: hosted + version: "1.1.0" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b + url: "https://pub.dev" + source: hosted + version: "2.4.0" + webkit_inspection_protocol: + dependency: transitive + description: + name: webkit_inspection_protocol + sha256: "67d3a8b6c79e1987d19d848b0892e582dbb0c66c57cc1fef58a177dd2aa2823d" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + yaml: + dependency: transitive + description: + name: yaml + sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" + url: "https://pub.dev" + source: hosted + version: "3.1.2" +sdks: + dart: ">=3.0.1 <4.0.0" diff --git a/pubspec.yaml b/pubspec.yaml new file mode 100644 index 000000000..de5c5d762 --- /dev/null +++ b/pubspec.yaml @@ -0,0 +1,19 @@ +name: ejson +description: An EJson serialization library for Dart. +version: 1.0.0 +# repository: https://github.com/my_org/my_repo + +environment: + sdk: ^3.0.1 + +# Add regular dependencies here. +dependencies: + analyzer: ^5.2.0 + build: ^2.3.1 + collection: ^1.17.2 + source_gen: ^1.3.2 + type_plus: ^2.0.0 + +dev_dependencies: + lints: ^2.0.0 + test: ^1.21.0 diff --git a/test/ejson_serialization_setup.g.dart b/test/ejson_serialization_setup.g.dart new file mode 100644 index 000000000..5917a522c --- /dev/null +++ b/test/ejson_serialization_setup.g.dart @@ -0,0 +1,15 @@ +// TODO: should be generated by builder +import 'package:ejson/ejson.dart'; +import 'package:type_plus/type_plus.dart'; + +import 'person.dart'; + +void registerSerializableTypes() { + TypePlus.add(); + customDecoders = const { + Person: decodePerson, + }; + customEncoders = const { + Person: encodePerson, + }; +} diff --git a/test/ejson_test.dart b/test/ejson_test.dart new file mode 100644 index 000000000..9d15abddd --- /dev/null +++ b/test/ejson_test.dart @@ -0,0 +1,262 @@ +import 'dart:convert'; + +import 'package:ejson/ejson.dart'; +import 'package:test/test.dart'; + +import 'ejson_serialization_setup.g.dart'; +import 'person.dart'; + +void _testCase( + T value, + EJsonValue canonicalExpected, [ + EJsonValue? relaxedExpected, +]) { + // relaxed same as canonical, unless otherwise specified + relaxedExpected ??= canonicalExpected; + + test('encode from $value of type $T', () { + final expected = relaxed ? relaxedExpected : canonicalExpected; + expect(toEJson(value), expected); + }); + + test('decode to $value of type $T', () { + final expected = relaxed ? relaxedExpected : canonicalExpected; + expect(fromEJson(expected), value); + }); + + test('roundtrip $value of type $T', () { + expect(fromEJson(toEJson(value)), value); + }); + + test('reverse roundtrip $value of type $T', () { + final expected = relaxed ? relaxedExpected : canonicalExpected; + expect(toEJson(fromEJson(expected)), expected); + }); + + test('roundtrip $value of type $T as String', () { + expect( + fromEJson( + jsonDecode(jsonEncode(toEJson(value))), // roundtrip as String + ), + value, + ); + }); + + test('decode to dynamic', () { + final expected = relaxed ? relaxedExpected : canonicalExpected; + // no here, so dynamic + expect(() => fromEJson(expected), returnsNormally); + }); + + if (value is! Defined) { + test('roundtrip $value of type $T as dynamic', () { + // no here, so dynamic + expect(fromEJson(toEJson(value)), value); + }); + + test('reverse roundtrip $value of type $T as dynamic', () { + final expected = relaxed ? relaxedExpected : canonicalExpected; + // no here, so dynamic + expect(toEJson(fromEJson(expected)), expected); + }); + } +} + +void main() { + for (final useRelaxed in [false, true]) { + group(useRelaxed ? 'relaxed' : 'canonical', () { + relaxed = useRelaxed; + + group('common types', () { + final time = DateTime(1974, 4, 10, 2, 42, 12, 202); // no microseconds! + + _testCase(null, null); + _testCase(1, {'\$numberLong': 1}, 1); + _testCase(1.0, {'\$numberDouble': 1.0}, 1.0); + _testCase(double.infinity, {'\$numberDouble': 'Infinity'}); + _testCase(double.negativeInfinity, {'\$numberDouble': '-Infinity'}); + _testCase('a', 'a'); + _testCase(true, true); + _testCase(false, false); + _testCase( + [1, 2, 3], + [ + {'\$numberLong': 1}, + {'\$numberLong': 2}, + {'\$numberLong': 3}, + ], + [1, 2, 3], + ); + _testCase( + [1, 1.1], + [ + {'\$numberLong': 1}, + {'\$numberDouble': 1.1}, + ], + [1, 1.1], + ); + _testCase( + [1, null, 3], + [ + {'\$numberLong': 1}, + null, + {'\$numberLong': 3}, + ], + [1, null, 3], + ); + _testCase( + {'a': 'abe', 'b': 1}, + { + 'a': 'abe', + 'b': {'\$numberLong': 1}, + }, + {'a': 'abe', 'b': 1}, + ); + _testCase( + time, + { + '\$date': {'\$numberLong': time.millisecondsSinceEpoch} + }, + {'\$date': time.toIso8601String()}, + ); + _testCase(#sym, {'\$symbol': 'sym'}); + _testCase(Key.max, {'\$maxKey': 1}); + _testCase(Key.min, {'\$minKey': 1}); + _testCase(undefined, {'\$undefined': 1}); + _testCase(const Undefined(), {'\$undefined': 1}); + _testCase(Undefined(), {'\$undefined': 1}); + _testCase(const Defined(42), {'\$numberLong': 42}, 42); + _testCase(const Defined(null), null); + _testCase(Defined(42), {'\$numberLong': 42}, 42); + _testCase(Defined(null), null); + // a complex nested generic type + _testCase?>>>( + { + 'a': { + 'b': null, + 'c': [1, 1.1, null] + } + }, + { + 'a': { + 'b': null, + 'c': [ + {'\$numberLong': 1}, + {'\$numberDouble': 1.1}, + null + ] + } + }, + { + 'a': { + 'b': null, + 'c': [1, 1.1, null] + } + }, + ); + + test('UndefinedOr', () { + UndefinedOr x = Undefined(); + expect(x.toEJson(), {'\$undefined': 1}); + + x = Defined(42); + expect(x.toEJson(), relaxed ? 42 : {'\$numberLong': 42}); + + x = Defined(null); + expect(x.toEJson(), isNull); + + expect( + fromEJson>({'\$undefined': 1}), + const Undefined(), + ); + + expect( + fromEJson>({'\$numberLong': 42}), + Defined(42), + ); + + expect(fromEJson>(null), Defined(null)); + }); + + test('NaN', () { + expect(toEJson(double.nan), {'\$numberDouble': 'NaN'}); + expect(fromEJson({'\$numberDouble': 'NaN'}), isNaN); + }); + }); + + group('custom types', () { + registerSerializableTypes(); + + final person = Person( + 'John', + DateTime(1974), + 80000, + spouse: Person('Jane', DateTime(1973), 90000), + ); + + _testCase( + person, + { + 'name': 'John', + 'birthDate': { + '\$date': {'\$numberLong': 126226800000} + }, + 'income': {'\$numberDouble': 80000.0}, + 'spouse': { + 'name': 'Jane', + 'birthDate': { + '\$date': {'\$numberLong': 94690800000} + }, + 'income': {'\$numberDouble': 90000.0}, + 'spouse': null + } + }, + { + 'name': 'John', + 'birthDate': {'\$date': '1974-01-01T00:00:00.000'}, + 'income': 80000.0, + 'spouse': { + 'name': 'Jane', + 'birthDate': {'\$date': '1973-01-01T00:00:00.000'}, + 'income': 90000.0, + 'spouse': null + } + }, + ); + _testCase>( + {'a': person}, + { + 'a': { + 'name': 'John', + 'birthDate': { + '\$date': {'\$numberLong': 126226800000} + }, + 'income': {'\$numberDouble': 80000.0}, + 'spouse': { + 'name': 'Jane', + 'birthDate': { + '\$date': {'\$numberLong': 94690800000} + }, + 'income': {'\$numberDouble': 90000.0}, + 'spouse': null + } + } + }, + { + 'a': { + 'name': 'John', + 'birthDate': {'\$date': '1974-01-01T00:00:00.000'}, + 'income': 80000.0, + 'spouse': { + 'name': 'Jane', + 'birthDate': {'\$date': '1973-01-01T00:00:00.000'}, + 'income': 90000.0, + 'spouse': null + } + } + }, + ); + }); + }); + } +} diff --git a/test/person.dart b/test/person.dart new file mode 100644 index 000000000..5d3a65f57 --- /dev/null +++ b/test/person.dart @@ -0,0 +1,34 @@ +import 'package:ejson/ejson.dart'; + +part 'person.g.dart'; + +class Person { + final String name; + final DateTime birthDate; + Duration get age => DateTime.now().difference(birthDate); + + final int? cprNumber; + final double income; + final Person? spouse; + + final children = []; + + @ejson // annotate constructor to generate decoder and encoder + Person(this.name, this.birthDate, this.income, {this.spouse, this.cprNumber}); + + @override + operator ==(other) => + identical(this, other) || + (other is Person && + other.name == name && + other.birthDate == birthDate && + other.income == income && + other.spouse == spouse); + + @override + String toString() => + 'Person{name: $name, birthDate: $birthDate, income: $income, spouse: $spouse}'; + + @override + int get hashCode => Object.hashAll([name, birthDate, income, spouse]); +} diff --git a/test/person.g.dart b/test/person.g.dart new file mode 100644 index 000000000..d9b219562 --- /dev/null +++ b/test/person.g.dart @@ -0,0 +1,34 @@ +// TODO: should be generated by builder +part of 'person.dart'; + +Person decodePerson(EJsonValue ejson) { + return switch (ejson) { + { + 'name': EJsonValue name, + 'birthDate': EJsonValue birthDate, + 'income': EJsonValue income, + 'spouse': EJsonValue spouse, + } => + Person( + name.to(), + birthDate.to(), + income.to(), + spouse: spouse.to(), + ), + _ => raiseInvalidEJson(ejson), + }; +} + +EJsonValue encodePerson(Person person) { + return { + 'name': person.name.toEJson(), + 'birthDate': person.birthDate.toEJson(), + 'income': person.income.toEJson(), + 'spouse': person.spouse.toEJson(), + }; +} + +extension PersonEJsonEncoderExtension on Person { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodePerson(this); +} From 0273fa0d0b7dc96071c6ea29d014c27ec38b47ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Sat, 27 May 2023 19:06:14 +0200 Subject: [PATCH 002/153] Add actual generator --- lib/generator.dart | 7 +++++++ lib/src/generator/generator.dart | 17 +++++++++++++++++ lib/src/generator/util.dart | 6 ++++++ 3 files changed, 30 insertions(+) create mode 100644 lib/generator.dart create mode 100644 lib/src/generator/generator.dart create mode 100644 lib/src/generator/util.dart diff --git a/lib/generator.dart b/lib/generator.dart new file mode 100644 index 000000000..843d62255 --- /dev/null +++ b/lib/generator.dart @@ -0,0 +1,7 @@ +import 'package:build/build.dart'; +import 'package:ejson/src/generator/generator.dart'; +import 'package:source_gen/source_gen.dart'; + +Builder getEJsonGenerator(BuilderOptions options) { + return SharedPartBuilder([EJsonGenerator()], 'ejson'); +} diff --git a/lib/src/generator/generator.dart b/lib/src/generator/generator.dart new file mode 100644 index 000000000..beb60f5ab --- /dev/null +++ b/lib/src/generator/generator.dart @@ -0,0 +1,17 @@ +import 'package:analyzer/dart/element/element.dart'; +import 'package:build/build.dart'; +import 'package:ejson/ejson.dart'; +import 'package:source_gen/source_gen.dart'; + +/// @nodoc +class EJsonGenerator extends GeneratorForAnnotation { + @override + String generateForAnnotatedElement( + Element element, + ConstantReader annotation, + BuildStep buildStep, + ) { + if (element is ConstructorElement) {} + return ''; + } +} diff --git a/lib/src/generator/util.dart b/lib/src/generator/util.dart new file mode 100644 index 000000000..99ad0bba0 --- /dev/null +++ b/lib/src/generator/util.dart @@ -0,0 +1,6 @@ +// ignore_for_file: public_member_api_docs + +import 'package:ejson/ejson.dart'; +import 'package:source_gen/source_gen.dart'; + +const TypeChecker ejsonChecker = TypeChecker.fromRuntime(EJson); From 16f5675f8910560736d62b291364028013638809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Sun, 28 May 2023 12:41:47 +0200 Subject: [PATCH 003/153] Tweak pubspec.yaml for bette PANA score --- .vscode/settings.json | 2 + LICENSE | 177 ++++++++++++++++++++++++++++++++++++++++++ pubspec.yaml | 19 ++++- 3 files changed, 195 insertions(+), 3 deletions(-) create mode 100644 LICENSE diff --git a/.vscode/settings.json b/.vscode/settings.json index 4f32ba4b6..f1a6e16f2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,7 @@ { "cSpell.words": [ + "bson", + "codegen", "ejson" ] } \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..66a27ec5f --- /dev/null +++ b/LICENSE @@ -0,0 +1,177 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + diff --git a/pubspec.yaml b/pubspec.yaml index de5c5d762..06bed1ec3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,12 +1,25 @@ name: ejson -description: An EJson serialization library for Dart. +description: >- + EJSON serialization. + + 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. + +topics: + - ejson + - bson + - json + - build-runner + - codegen + version: 1.0.0 -# repository: https://github.com/my_org/my_repo +repository: https://github.com/realm/realm-dart + +publish_to: 'none' # Remove this line if you wish to publish to pub.dev environment: sdk: ^3.0.1 -# Add regular dependencies here. dependencies: analyzer: ^5.2.0 build: ^2.3.1 From a3bc311a117bfef703ab9508b8ae129e871cb215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 30 May 2023 10:49:37 +0200 Subject: [PATCH 004/153] move ejson project into ejson folder --- CHANGELOG.md => ejson/CHANGELOG.md | 0 LICENSE => ejson/LICENSE | 0 README.md => ejson/README.md | 0 analysis_options.yaml => ejson/analysis_options.yaml | 0 {bin => ejson/bin}/ejson.dart | 0 {lib => ejson/lib}/ejson.dart | 0 {lib => ejson/lib}/generator.dart | 0 {lib => ejson/lib}/src/annotations.dart | 0 {lib => ejson/lib}/src/decoding.dart | 0 {lib => ejson/lib}/src/encoding.dart | 0 {lib => ejson/lib}/src/generator/generator.dart | 0 {lib => ejson/lib}/src/generator/util.dart | 0 {lib => ejson/lib}/src/types.dart | 0 pubspec.lock => ejson/pubspec.lock | 0 pubspec.yaml => ejson/pubspec.yaml | 0 {test => ejson/test}/ejson_serialization_setup.g.dart | 0 {test => ejson/test}/ejson_test.dart | 0 {test => ejson/test}/person.dart | 0 {test => ejson/test}/person.g.dart | 0 19 files changed, 0 insertions(+), 0 deletions(-) rename CHANGELOG.md => ejson/CHANGELOG.md (100%) rename LICENSE => ejson/LICENSE (100%) rename README.md => ejson/README.md (100%) rename analysis_options.yaml => ejson/analysis_options.yaml (100%) rename {bin => ejson/bin}/ejson.dart (100%) rename {lib => ejson/lib}/ejson.dart (100%) rename {lib => ejson/lib}/generator.dart (100%) rename {lib => ejson/lib}/src/annotations.dart (100%) rename {lib => ejson/lib}/src/decoding.dart (100%) rename {lib => ejson/lib}/src/encoding.dart (100%) rename {lib => ejson/lib}/src/generator/generator.dart (100%) rename {lib => ejson/lib}/src/generator/util.dart (100%) rename {lib => ejson/lib}/src/types.dart (100%) rename pubspec.lock => ejson/pubspec.lock (100%) rename pubspec.yaml => ejson/pubspec.yaml (100%) rename {test => ejson/test}/ejson_serialization_setup.g.dart (100%) rename {test => ejson/test}/ejson_test.dart (100%) rename {test => ejson/test}/person.dart (100%) rename {test => ejson/test}/person.g.dart (100%) diff --git a/CHANGELOG.md b/ejson/CHANGELOG.md similarity index 100% rename from CHANGELOG.md rename to ejson/CHANGELOG.md diff --git a/LICENSE b/ejson/LICENSE similarity index 100% rename from LICENSE rename to ejson/LICENSE diff --git a/README.md b/ejson/README.md similarity index 100% rename from README.md rename to ejson/README.md diff --git a/analysis_options.yaml b/ejson/analysis_options.yaml similarity index 100% rename from analysis_options.yaml rename to ejson/analysis_options.yaml diff --git a/bin/ejson.dart b/ejson/bin/ejson.dart similarity index 100% rename from bin/ejson.dart rename to ejson/bin/ejson.dart diff --git a/lib/ejson.dart b/ejson/lib/ejson.dart similarity index 100% rename from lib/ejson.dart rename to ejson/lib/ejson.dart diff --git a/lib/generator.dart b/ejson/lib/generator.dart similarity index 100% rename from lib/generator.dart rename to ejson/lib/generator.dart diff --git a/lib/src/annotations.dart b/ejson/lib/src/annotations.dart similarity index 100% rename from lib/src/annotations.dart rename to ejson/lib/src/annotations.dart diff --git a/lib/src/decoding.dart b/ejson/lib/src/decoding.dart similarity index 100% rename from lib/src/decoding.dart rename to ejson/lib/src/decoding.dart diff --git a/lib/src/encoding.dart b/ejson/lib/src/encoding.dart similarity index 100% rename from lib/src/encoding.dart rename to ejson/lib/src/encoding.dart diff --git a/lib/src/generator/generator.dart b/ejson/lib/src/generator/generator.dart similarity index 100% rename from lib/src/generator/generator.dart rename to ejson/lib/src/generator/generator.dart diff --git a/lib/src/generator/util.dart b/ejson/lib/src/generator/util.dart similarity index 100% rename from lib/src/generator/util.dart rename to ejson/lib/src/generator/util.dart diff --git a/lib/src/types.dart b/ejson/lib/src/types.dart similarity index 100% rename from lib/src/types.dart rename to ejson/lib/src/types.dart diff --git a/pubspec.lock b/ejson/pubspec.lock similarity index 100% rename from pubspec.lock rename to ejson/pubspec.lock diff --git a/pubspec.yaml b/ejson/pubspec.yaml similarity index 100% rename from pubspec.yaml rename to ejson/pubspec.yaml diff --git a/test/ejson_serialization_setup.g.dart b/ejson/test/ejson_serialization_setup.g.dart similarity index 100% rename from test/ejson_serialization_setup.g.dart rename to ejson/test/ejson_serialization_setup.g.dart diff --git a/test/ejson_test.dart b/ejson/test/ejson_test.dart similarity index 100% rename from test/ejson_test.dart rename to ejson/test/ejson_test.dart diff --git a/test/person.dart b/ejson/test/person.dart similarity index 100% rename from test/person.dart rename to ejson/test/person.dart diff --git a/test/person.g.dart b/ejson/test/person.g.dart similarity index 100% rename from test/person.g.dart rename to ejson/test/person.g.dart From 3dbc76208de69cfebc7d0cc5f57938e3721d8bdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 31 May 2023 13:25:18 +0200 Subject: [PATCH 005/153] Rudimentary generator inplace --- ejson/.vscode/settings.json | 8 + ejson/build.yaml | 8 + ejson/ejson_generator_test/.gitignore | 3 + .../analysis_options.yaml | 1 + ejson/ejson_generator_test/pubspec.yaml | 18 + .../ejson_generator_test/test/ctor_test.dart | 84 ++++ .../test/ctor_test.g.dart | 121 ++++++ ejson/lib/src/decoding.dart | 2 +- ejson/lib/src/encoding.dart | 2 +- ejson/lib/src/generator/generator.dart | 58 ++- ejson/pubspec.lock | 405 ------------------ 11 files changed, 295 insertions(+), 415 deletions(-) create mode 100644 ejson/.vscode/settings.json create mode 100644 ejson/build.yaml create mode 100644 ejson/ejson_generator_test/.gitignore create mode 100644 ejson/ejson_generator_test/analysis_options.yaml create mode 100644 ejson/ejson_generator_test/pubspec.yaml create mode 100644 ejson/ejson_generator_test/test/ctor_test.dart create mode 100644 ejson/ejson_generator_test/test/ctor_test.g.dart delete mode 100644 ejson/pubspec.lock diff --git a/ejson/.vscode/settings.json b/ejson/.vscode/settings.json new file mode 100644 index 000000000..30a20a8b6 --- /dev/null +++ b/ejson/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "cSpell.words": [ + "bson", + "codegen", + "ejson", + "nodoc" + ] +} \ No newline at end of file diff --git a/ejson/build.yaml b/ejson/build.yaml new file mode 100644 index 000000000..bf567e89e --- /dev/null +++ b/ejson/build.yaml @@ -0,0 +1,8 @@ +builders: + ejson: + import: "package:ejson/generator.dart" + builder_factories: ["getEJsonGenerator"] + build_extensions: { ".dart": ["ejson.g.part"] } + auto_apply: dependents + build_to: cache + applies_builders: ["source_gen|combining_builder"] diff --git a/ejson/ejson_generator_test/.gitignore b/ejson/ejson_generator_test/.gitignore new file mode 100644 index 000000000..3a8579040 --- /dev/null +++ b/ejson/ejson_generator_test/.gitignore @@ -0,0 +1,3 @@ +# https://dart.dev/guides/libraries/private-files +# Created by `dart pub` +.dart_tool/ diff --git a/ejson/ejson_generator_test/analysis_options.yaml b/ejson/ejson_generator_test/analysis_options.yaml new file mode 100644 index 000000000..ea2c9e947 --- /dev/null +++ b/ejson/ejson_generator_test/analysis_options.yaml @@ -0,0 +1 @@ +include: package:lints/recommended.yaml \ No newline at end of file diff --git a/ejson/ejson_generator_test/pubspec.yaml b/ejson/ejson_generator_test/pubspec.yaml new file mode 100644 index 000000000..def69820c --- /dev/null +++ b/ejson/ejson_generator_test/pubspec.yaml @@ -0,0 +1,18 @@ +name: ejson_generator_test +description: A sample command-line application. +version: 1.0.0 +# repository: https://github.com/my_org/my_repo + +environment: + sdk: ^3.0.2 + +# Add regular dependencies here. +dependencies: + ejson: + path: .. + # path: ^1.8.0 + +dev_dependencies: + build_runner: ^2.4.4 + lints: ^2.0.0 + test: ^1.21.0 diff --git a/ejson/ejson_generator_test/test/ctor_test.dart b/ejson/ejson_generator_test/test/ctor_test.dart new file mode 100644 index 000000000..d9e0b3969 --- /dev/null +++ b/ejson/ejson_generator_test/test/ctor_test.dart @@ -0,0 +1,84 @@ +import 'package:ejson/ejson.dart'; +import 'package:test/test.dart'; + +part 'ctor_test.g.dart'; + +class Empty { + @ejson + const Empty(); +} + +class Simple { + final int i; + @ejson + const Simple(this.i); +} + +class Named { + String s; + @ejson + Named.nameIt(this.s); +} + +class RequiredNamedParameters { + final String s; + @ejson + RequiredNamedParameters({required this.s}); +} + +class OptionalNamedParameters { + String s; + @ejson + OptionalNamedParameters({this.s = 'rabbit'}); +} + +class OptionalParameters { + String s; + @ejson + OptionalParameters([this.s = 'racoon']); +} + +class PrivateMembers { + final int _id; + + int get id => _id; + + @ejson + PrivateMembers(int id) : _id = id; +} + +void main() { + customEncoders.addAll({ + Empty: encodeEmpty, + Simple: encodeSimple, + Named: encodeNamed, + RequiredNamedParameters: encodeRequiredNamedParameters, + OptionalNamedParameters: encodeOptionalNamedParameters, + OptionalParameters: encodeOptionalParameters, + PrivateMembers: encodePrivateMembers, + }); + + customDecoders.addAll({ + Empty: decodeEmpty, + Simple: decodeSimple, + Named: decodeNamed, + RequiredNamedParameters: decodeRequiredNamedParameters, + OptionalNamedParameters: decodeOptionalNamedParameters, + OptionalParameters: decodeOptionalParameters, + PrivateMembers: decodePrivateMembers, + }); + + test('@ejson encode', () { + expect(Empty().toEJson(), {}); + expect(Simple(42).toEJson(), { + 'i': {'\$numberLong': 42} + }); + expect(Named.nameIt('foobar').toEJson(), {'s': 'foobar'}); + expect(RequiredNamedParameters(s: 'foobar').toEJson(), {'s': 'foobar'}); + expect(OptionalNamedParameters().toEJson(), {'s': 'rabbit'}); + expect(OptionalParameters().toEJson(), {'s': 'racoon'}); + expect(PrivateMembers(42).toEJson(), { + 'id': {'\$numberLong': 42} + }); + }); +} diff --git a/ejson/ejson_generator_test/test/ctor_test.g.dart b/ejson/ejson_generator_test/test/ctor_test.g.dart new file mode 100644 index 000000000..5d8805089 --- /dev/null +++ b/ejson/ejson_generator_test/test/ctor_test.g.dart @@ -0,0 +1,121 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'ctor_test.dart'; + +// ************************************************************************** +// EJsonGenerator +// ************************************************************************** + +EJsonValue encodeEmpty(Empty value) { + return {}; +} + +Empty decodeEmpty(EJsonValue ejson) { + return switch (ejson) { + Map m when m.isEmpty => Empty(), + _ => raiseInvalidEJson(ejson), + }; +} + +extension EmptyEJsonEncoderExtension on Empty { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeEmpty(this); +} + +EJsonValue encodeSimple(Simple value) { + return {'i': value.i.toEJson()}; +} + +Simple decodeSimple(EJsonValue ejson) { + return switch (ejson) { + {'i': EJsonValue i} => Simple(i.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension SimpleEJsonEncoderExtension on Simple { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeSimple(this); +} + +EJsonValue encodeNamed(Named value) { + return {'s': value.s.toEJson()}; +} + +Named decodeNamed(EJsonValue ejson) { + return switch (ejson) { + {'s': EJsonValue s} => Named.nameIt(s.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension NamedEJsonEncoderExtension on Named { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeNamed(this); +} + +EJsonValue encodeRequiredNamedParameters(RequiredNamedParameters value) { + return {'s': value.s.toEJson()}; +} + +RequiredNamedParameters decodeRequiredNamedParameters(EJsonValue ejson) { + return switch (ejson) { + {'s': EJsonValue s} => RequiredNamedParameters(s: s.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension RequiredNamedParametersEJsonEncoderExtension + on RequiredNamedParameters { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeRequiredNamedParameters(this); +} + +EJsonValue encodeOptionalNamedParameters(OptionalNamedParameters value) { + return {'s': value.s.toEJson()}; +} + +OptionalNamedParameters decodeOptionalNamedParameters(EJsonValue ejson) { + return switch (ejson) { + {'s': EJsonValue s} => OptionalNamedParameters(s: s.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension OptionalNamedParametersEJsonEncoderExtension + on OptionalNamedParameters { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeOptionalNamedParameters(this); +} + +EJsonValue encodeOptionalParameters(OptionalParameters value) { + return {'s': value.s.toEJson()}; +} + +OptionalParameters decodeOptionalParameters(EJsonValue ejson) { + return switch (ejson) { + {'s': EJsonValue s} => OptionalParameters(s.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension OptionalParametersEJsonEncoderExtension on OptionalParameters { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeOptionalParameters(this); +} + +EJsonValue encodePrivateMembers(PrivateMembers value) { + return {'id': value.id.toEJson()}; +} + +PrivateMembers decodePrivateMembers(EJsonValue ejson) { + return switch (ejson) { + {'id': EJsonValue id} => PrivateMembers(id.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension PrivateMembersEJsonEncoderExtension on PrivateMembers { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodePrivateMembers(this); +} diff --git a/ejson/lib/src/decoding.dart b/ejson/lib/src/decoding.dart index 16d740e75..e8ec688d0 100644 --- a/ejson/lib/src/decoding.dart +++ b/ejson/lib/src/decoding.dart @@ -22,7 +22,7 @@ const commonDecoders = { UndefinedOr: _decodeUndefinedOr, }; -var customDecoders = const {}; +var customDecoders = {}; // if registerSerializableTypes not called final decoders = () { diff --git a/ejson/lib/src/encoding.dart b/ejson/lib/src/encoding.dart index 5ed9e3892..c2b861735 100644 --- a/ejson/lib/src/encoding.dart +++ b/ejson/lib/src/encoding.dart @@ -3,7 +3,7 @@ import 'package:type_plus/type_plus.dart'; import 'types.dart'; // No custom encoders, if registerSerializableTypes not called -var customEncoders = const {}; +var customEncoders = {}; var relaxed = false; diff --git a/ejson/lib/src/generator/generator.dart b/ejson/lib/src/generator/generator.dart index beb60f5ab..bc6af9331 100644 --- a/ejson/lib/src/generator/generator.dart +++ b/ejson/lib/src/generator/generator.dart @@ -1,17 +1,59 @@ +import 'dart:async'; + import 'package:analyzer/dart/element/element.dart'; import 'package:build/build.dart'; import 'package:ejson/ejson.dart'; import 'package:source_gen/source_gen.dart'; /// @nodoc -class EJsonGenerator extends GeneratorForAnnotation { +class EJsonGenerator extends Generator { + const EJsonGenerator(); + + TypeChecker get typeChecker => TypeChecker.fromRuntime(EJson); + @override - String generateForAnnotatedElement( - Element element, - ConstantReader annotation, - BuildStep buildStep, - ) { - if (element is ConstructorElement) {} - return ''; + FutureOr generate(LibraryReader library, BuildStep buildStep) async { + final ctors = library.classes.map( + (c) => c.constructors.singleWhere( + (c) => + typeChecker.firstAnnotationOf(c, throwOnUnresolved: false) != null, + ), + ); + return ctors.map((ctor) { + final cls = ctor.enclosingElement; + final className = ctor.enclosingElement.name; + + log.info('Generating EJson for $className'); + return ''' + EJsonValue encode$className($className value) { + return { + ${ctor.parameters.map((p) => "'${p.name}': value.${p.name}.toEJson()").join('\n')} + }; + } + + $className decode$className(EJsonValue ejson) { + return switch (ejson) { + ${decodePattern(ctor.parameters)} => $className${ctor.name.isEmpty ? '' : '.${ctor.name}'}( + ${ctor.parameters.map((p) => "${p.isNamed ? '${p.name} : ' : ''}${p.name}.to<${p.type}>()").join(',\n')} + ), + _ => raiseInvalidEJson(ejson), + }; + } + + extension ${className}EJsonEncoderExtension on $className { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encode$className(this); + } + '''; + }).join('\n\n'); + } +} + +String decodePattern(Iterable parameters) { + if (parameters.isEmpty) { + return 'Map m when m.isEmpty'; } + return parameters + .map((p) => "{'${p.name}': EJsonValue ${p.name}}") + .join(',\n'); } diff --git a/ejson/pubspec.lock b/ejson/pubspec.lock deleted file mode 100644 index 3027d1179..000000000 --- a/ejson/pubspec.lock +++ /dev/null @@ -1,405 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: - _fe_analyzer_shared: - dependency: transitive - description: - name: _fe_analyzer_shared - sha256: ae92f5d747aee634b87f89d9946000c2de774be1d6ac3e58268224348cd0101a - url: "https://pub.dev" - source: hosted - version: "61.0.0" - analyzer: - dependency: "direct main" - description: - name: analyzer - sha256: ea3d8652bda62982addfd92fdc2d0214e5f82e43325104990d4f4c4a2a313562 - url: "https://pub.dev" - source: hosted - version: "5.13.0" - args: - dependency: transitive - description: - name: args - sha256: c372bb384f273f0c2a8aaaa226dad84dc27c8519a691b888725dec59518ad53a - url: "https://pub.dev" - source: hosted - version: "2.4.1" - async: - dependency: transitive - description: - name: async - sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" - url: "https://pub.dev" - source: hosted - version: "2.11.0" - boolean_selector: - dependency: transitive - description: - name: boolean_selector - sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" - url: "https://pub.dev" - source: hosted - version: "2.1.1" - build: - dependency: "direct main" - description: - name: build - sha256: "43865b79fbb78532e4bff7c33087aa43b1d488c4fdef014eaef568af6d8016dc" - url: "https://pub.dev" - source: hosted - version: "2.4.0" - collection: - dependency: "direct main" - description: - name: collection - sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 - url: "https://pub.dev" - source: hosted - version: "1.17.2" - convert: - dependency: transitive - description: - name: convert - sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" - url: "https://pub.dev" - source: hosted - version: "3.1.1" - coverage: - dependency: transitive - description: - name: coverage - sha256: "2fb815080e44a09b85e0f2ca8a820b15053982b2e714b59267719e8a9ff17097" - url: "https://pub.dev" - source: hosted - version: "1.6.3" - crypto: - dependency: transitive - description: - name: crypto - sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab - url: "https://pub.dev" - source: hosted - version: "3.0.3" - dart_style: - dependency: transitive - description: - name: dart_style - sha256: f4f1f73ab3fd2afcbcca165ee601fe980d966af6a21b5970c6c9376955c528ad - url: "https://pub.dev" - source: hosted - version: "2.3.1" - file: - dependency: transitive - description: - name: file - sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" - url: "https://pub.dev" - source: hosted - version: "7.0.0" - frontend_server_client: - dependency: transitive - description: - name: frontend_server_client - sha256: "408e3ca148b31c20282ad6f37ebfa6f4bdc8fede5b74bc2f08d9d92b55db3612" - url: "https://pub.dev" - source: hosted - version: "3.2.0" - glob: - dependency: transitive - description: - name: glob - sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" - url: "https://pub.dev" - source: hosted - version: "2.1.2" - http_multi_server: - dependency: transitive - description: - name: http_multi_server - sha256: "97486f20f9c2f7be8f514851703d0119c3596d14ea63227af6f7a481ef2b2f8b" - url: "https://pub.dev" - source: hosted - version: "3.2.1" - http_parser: - dependency: transitive - description: - name: http_parser - sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" - url: "https://pub.dev" - source: hosted - version: "4.0.2" - io: - dependency: transitive - description: - name: io - sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e" - url: "https://pub.dev" - source: hosted - version: "1.0.4" - js: - dependency: transitive - description: - name: js - sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 - url: "https://pub.dev" - source: hosted - version: "0.6.7" - lints: - dependency: "direct dev" - description: - name: lints - sha256: "6b0206b0bf4f04961fc5438198ccb3a885685cd67d4d4a32cc20ad7f8adbe015" - url: "https://pub.dev" - source: hosted - version: "2.1.0" - logging: - dependency: transitive - description: - name: logging - sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" - url: "https://pub.dev" - source: hosted - version: "1.2.0" - matcher: - dependency: transitive - description: - name: matcher - sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" - url: "https://pub.dev" - source: hosted - version: "0.12.16" - meta: - dependency: transitive - description: - name: meta - sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" - url: "https://pub.dev" - source: hosted - version: "1.9.1" - mime: - dependency: transitive - description: - name: mime - sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e - url: "https://pub.dev" - source: hosted - version: "1.0.4" - node_preamble: - dependency: transitive - description: - name: node_preamble - sha256: "6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db" - url: "https://pub.dev" - source: hosted - version: "2.0.2" - package_config: - dependency: transitive - description: - name: package_config - sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd" - url: "https://pub.dev" - source: hosted - version: "2.1.0" - path: - dependency: transitive - description: - name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" - url: "https://pub.dev" - source: hosted - version: "1.8.3" - pool: - dependency: transitive - description: - name: pool - sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a" - url: "https://pub.dev" - source: hosted - version: "1.5.1" - pub_semver: - dependency: transitive - description: - name: pub_semver - sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c" - url: "https://pub.dev" - source: hosted - version: "2.1.4" - shelf: - dependency: transitive - description: - name: shelf - sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4 - url: "https://pub.dev" - source: hosted - version: "1.4.1" - shelf_packages_handler: - dependency: transitive - description: - name: shelf_packages_handler - sha256: "89f967eca29607c933ba9571d838be31d67f53f6e4ee15147d5dc2934fee1b1e" - url: "https://pub.dev" - source: hosted - version: "3.0.2" - shelf_static: - dependency: transitive - description: - name: shelf_static - sha256: a41d3f53c4adf0f57480578c1d61d90342cd617de7fc8077b1304643c2d85c1e - url: "https://pub.dev" - source: hosted - version: "1.1.2" - shelf_web_socket: - dependency: transitive - description: - name: shelf_web_socket - sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1" - url: "https://pub.dev" - source: hosted - version: "1.0.4" - source_gen: - dependency: "direct main" - description: - name: source_gen - sha256: "373f96cf5a8744bc9816c1ff41cf5391bbdbe3d7a96fe98c622b6738a8a7bd33" - url: "https://pub.dev" - source: hosted - version: "1.3.2" - source_map_stack_trace: - dependency: transitive - description: - name: source_map_stack_trace - sha256: "84cf769ad83aa6bb61e0aa5a18e53aea683395f196a6f39c4c881fb90ed4f7ae" - url: "https://pub.dev" - source: hosted - version: "2.1.1" - source_maps: - dependency: transitive - description: - name: source_maps - sha256: "708b3f6b97248e5781f493b765c3337db11c5d2c81c3094f10904bfa8004c703" - url: "https://pub.dev" - source: hosted - version: "0.10.12" - source_span: - dependency: transitive - description: - name: source_span - sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" - url: "https://pub.dev" - source: hosted - version: "1.10.0" - stack_trace: - dependency: transitive - description: - name: stack_trace - sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 - url: "https://pub.dev" - source: hosted - version: "1.11.0" - stream_channel: - dependency: transitive - description: - name: stream_channel - sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" - url: "https://pub.dev" - source: hosted - version: "2.1.1" - string_scanner: - dependency: transitive - description: - name: string_scanner - sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" - url: "https://pub.dev" - source: hosted - version: "1.2.0" - term_glyph: - dependency: transitive - description: - name: term_glyph - sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 - url: "https://pub.dev" - source: hosted - version: "1.2.1" - test: - dependency: "direct dev" - description: - name: test - sha256: "13b41f318e2a5751c3169137103b60c584297353d4b1761b66029bae6411fe46" - url: "https://pub.dev" - source: hosted - version: "1.24.3" - test_api: - dependency: transitive - description: - name: test_api - sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8" - url: "https://pub.dev" - source: hosted - version: "0.6.0" - test_core: - dependency: transitive - description: - name: test_core - sha256: "99806e9e6d95c7b059b7a0fc08f07fc53fabe54a829497f0d9676299f1e8637e" - url: "https://pub.dev" - source: hosted - version: "0.5.3" - type_plus: - dependency: "direct main" - description: - name: type_plus - sha256: "28cbdcb9d2118f65881d11158ecb4d9db8b78589969e3168061d06963ef3ca59" - url: "https://pub.dev" - source: hosted - version: "2.0.0" - typed_data: - dependency: transitive - description: - name: typed_data - sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c - url: "https://pub.dev" - source: hosted - version: "1.3.2" - vm_service: - dependency: transitive - description: - name: vm_service - sha256: f3743ca475e0c9ef71df4ba15eb2d7684eecd5c8ba20a462462e4e8b561b2e11 - url: "https://pub.dev" - source: hosted - version: "11.6.0" - watcher: - dependency: transitive - description: - name: watcher - sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8" - url: "https://pub.dev" - source: hosted - version: "1.1.0" - web_socket_channel: - dependency: transitive - description: - name: web_socket_channel - sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b - url: "https://pub.dev" - source: hosted - version: "2.4.0" - webkit_inspection_protocol: - dependency: transitive - description: - name: webkit_inspection_protocol - sha256: "67d3a8b6c79e1987d19d848b0892e582dbb0c66c57cc1fef58a177dd2aa2823d" - url: "https://pub.dev" - source: hosted - version: "1.2.0" - yaml: - dependency: transitive - description: - name: yaml - sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" - url: "https://pub.dev" - source: hosted - version: "3.1.2" -sdks: - dart: ">=3.0.1 <4.0.0" From 804f669f4e52e7bc57398d94e61759051b887b07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 31 May 2023 14:57:02 +0200 Subject: [PATCH 006/153] Custom decoding tests --- ejson/ejson_generator_test/test/ctor_test.dart | 18 ++++++++++++++---- ejson/lib/src/decoding.dart | 10 ++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/ejson/ejson_generator_test/test/ctor_test.dart b/ejson/ejson_generator_test/test/ctor_test.dart index d9e0b3969..82ea9296d 100644 --- a/ejson/ejson_generator_test/test/ctor_test.dart +++ b/ejson/ejson_generator_test/test/ctor_test.dart @@ -41,14 +41,14 @@ class OptionalParameters { class PrivateMembers { final int _id; - int get id => _id; + int get id => _id; // must match constructor parameter name @ejson - PrivateMembers(int id) : _id = id; + PrivateMembers(int id) : _id = id; // instead of @MapTo } void main() { - customEncoders.addAll({ + customEncoders.addAll(const { Empty: encodeEmpty, Simple: encodeSimple, Named: encodeNamed, @@ -58,7 +58,7 @@ void main() { PrivateMembers: encodePrivateMembers, }); - customDecoders.addAll({ + customDecoders.addAll(const { Empty: decodeEmpty, Simple: decodeSimple, Named: decodeNamed, @@ -81,4 +81,14 @@ void main() { 'id': {'\$numberLong': 42} }); }); + + test('@ejson decode', () { + expect(fromEJson({}), const Empty()); + expect( + fromEJson({ + 'i': {'\$numberLong': 42} + }), + Simple(42), + ); + }); } diff --git a/ejson/lib/src/decoding.dart b/ejson/lib/src/decoding.dart index e8ec688d0..90a693065 100644 --- a/ejson/lib/src/decoding.dart +++ b/ejson/lib/src/decoding.dart @@ -178,10 +178,12 @@ num _decodeNum(EJsonValue ejson) { }; } -String _decodeString(EJsonValue ejson) => switch (ejson) { - String s => s, - _ => raiseInvalidEJson(ejson), - }; +String _decodeString(EJsonValue ejson) { + return switch (ejson) { + String s => s, + _ => raiseInvalidEJson(ejson), + }; +} Symbol _decodeSymbol(EJsonValue ejson) { return switch (ejson) { From 8143bf5e49ad79918f96fed5985e4fcfa7b9245c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 31 May 2023 15:44:32 +0200 Subject: [PATCH 007/153] Fix realm generator tests --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 80c6ad5f6..9b3394093 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -494,7 +494,10 @@ jobs: channel: 'stable' - name: Delete generated files in realm_dart - run: find . -name "*.realm.dart" -delete + run: | + find . -name "*.g.dart" -delete + find . -name "*.realm.dart" -delete + working-directory: packages/realm_dart - name: Run generator in realm_dart From 92a0570c525e64aa8b43adabc3d013619c0c3aa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 31 May 2023 16:32:58 +0200 Subject: [PATCH 008/153] Update pubspec repo ref --- ejson/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ejson/pubspec.yaml b/ejson/pubspec.yaml index 06bed1ec3..3789bfb5c 100644 --- a/ejson/pubspec.yaml +++ b/ejson/pubspec.yaml @@ -13,7 +13,7 @@ topics: - codegen version: 1.0.0 -repository: https://github.com/realm/realm-dart +repository: https://github.com/realm/realm-dart/ejson publish_to: 'none' # Remove this line if you wish to publish to pub.dev From 7baa523d5edf80cdb84c5404295e782ecadef600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 31 May 2023 16:33:48 +0200 Subject: [PATCH 009/153] wip --- ejson/example/main.dart | 1 + ejson/lib/src/generator/generator.dart | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 ejson/example/main.dart diff --git a/ejson/example/main.dart b/ejson/example/main.dart new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/ejson/example/main.dart @@ -0,0 +1 @@ + diff --git a/ejson/lib/src/generator/generator.dart b/ejson/lib/src/generator/generator.dart index bc6af9331..1f65857ac 100644 --- a/ejson/lib/src/generator/generator.dart +++ b/ejson/lib/src/generator/generator.dart @@ -20,7 +20,6 @@ class EJsonGenerator extends Generator { ), ); return ctors.map((ctor) { - final cls = ctor.enclosingElement; final className = ctor.enclosingElement.name; log.info('Generating EJson for $className'); From 161273b60d86bfdc91439a8c50dcd1612e06e9d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 31 May 2023 16:43:54 +0200 Subject: [PATCH 010/153] Add copyright headers --- ejson/ejson_generator_test/test/ctor_test.dart | 18 ++++++++++++++++++ ejson/lib/ejson.dart | 18 ++++++++++++++++++ ejson/lib/generator.dart | 18 ++++++++++++++++++ ejson/lib/src/annotations.dart | 18 ++++++++++++++++++ ejson/lib/src/decoding.dart | 18 ++++++++++++++++++ ejson/lib/src/encoding.dart | 18 ++++++++++++++++++ ejson/lib/src/generator/generator.dart | 18 ++++++++++++++++++ ejson/lib/src/generator/util.dart | 18 ++++++++++++++++++ ejson/lib/src/types.dart | 18 ++++++++++++++++++ ejson/test/ejson_test.dart | 18 ++++++++++++++++++ 10 files changed, 180 insertions(+) diff --git a/ejson/ejson_generator_test/test/ctor_test.dart b/ejson/ejson_generator_test/test/ctor_test.dart index 82ea9296d..a30d8a3bb 100644 --- a/ejson/ejson_generator_test/test/ctor_test.dart +++ b/ejson/ejson_generator_test/test/ctor_test.dart @@ -1,3 +1,21 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2023 Realm Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + import 'package:ejson/ejson.dart'; import 'package:test/test.dart'; diff --git a/ejson/lib/ejson.dart b/ejson/lib/ejson.dart index 83a31853e..15e499d90 100644 --- a/ejson/lib/ejson.dart +++ b/ejson/lib/ejson.dart @@ -1,3 +1,21 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2023 Realm Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + export 'src/annotations.dart'; export 'src/decoding.dart'; export 'src/encoding.dart'; diff --git a/ejson/lib/generator.dart b/ejson/lib/generator.dart index 843d62255..07c230cc1 100644 --- a/ejson/lib/generator.dart +++ b/ejson/lib/generator.dart @@ -1,3 +1,21 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2023 Realm Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + import 'package:build/build.dart'; import 'package:ejson/src/generator/generator.dart'; import 'package:source_gen/source_gen.dart'; diff --git a/ejson/lib/src/annotations.dart b/ejson/lib/src/annotations.dart index 5729259f2..7bf264cf3 100644 --- a/ejson/lib/src/annotations.dart +++ b/ejson/lib/src/annotations.dart @@ -1,3 +1,21 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2023 Realm Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + /// Annotation to mark a class for extended json (ejson) serialization const ejson = EJson(); diff --git a/ejson/lib/src/decoding.dart b/ejson/lib/src/decoding.dart index 90a693065..328c221e3 100644 --- a/ejson/lib/src/decoding.dart +++ b/ejson/lib/src/decoding.dart @@ -1,3 +1,21 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2023 Realm Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + import 'package:collection/collection.dart'; import 'package:type_plus/type_plus.dart'; diff --git a/ejson/lib/src/encoding.dart b/ejson/lib/src/encoding.dart index c2b861735..a65e5107f 100644 --- a/ejson/lib/src/encoding.dart +++ b/ejson/lib/src/encoding.dart @@ -1,3 +1,21 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2023 Realm Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + import 'package:type_plus/type_plus.dart'; import 'types.dart'; diff --git a/ejson/lib/src/generator/generator.dart b/ejson/lib/src/generator/generator.dart index 1f65857ac..24f3550b2 100644 --- a/ejson/lib/src/generator/generator.dart +++ b/ejson/lib/src/generator/generator.dart @@ -1,3 +1,21 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2023 Realm Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + import 'dart:async'; import 'package:analyzer/dart/element/element.dart'; diff --git a/ejson/lib/src/generator/util.dart b/ejson/lib/src/generator/util.dart index 99ad0bba0..c265af390 100644 --- a/ejson/lib/src/generator/util.dart +++ b/ejson/lib/src/generator/util.dart @@ -1,3 +1,21 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2023 Realm Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + // ignore_for_file: public_member_api_docs import 'package:ejson/ejson.dart'; diff --git a/ejson/lib/src/types.dart b/ejson/lib/src/types.dart index ac2430f22..c6fc3f379 100644 --- a/ejson/lib/src/types.dart +++ b/ejson/lib/src/types.dart @@ -1,3 +1,21 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2023 Realm Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + // while we wait for // typedef EJsonValue = Null | String | bool | int | double | List | Map; typedef EJsonValue = Object?; diff --git a/ejson/test/ejson_test.dart b/ejson/test/ejson_test.dart index 9d15abddd..181b88779 100644 --- a/ejson/test/ejson_test.dart +++ b/ejson/test/ejson_test.dart @@ -1,3 +1,21 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2023 Realm Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + import 'dart:convert'; import 'package:ejson/ejson.dart'; From 0a1a7be2ed8c293ec6ce80c0390b43d09fbbdc6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 31 May 2023 18:38:01 +0200 Subject: [PATCH 011/153] Fix multi parameter ctor bug. More tests --- ejson/ejson_generator_test/pubspec.yaml | 1 + .../ejson_generator_test/test/ctor_test.dart | 96 ++++++++++++------- .../test/ctor_test.g.dart | 30 ++++++ ejson/lib/ejson.dart | 1 + ejson/lib/src/configuration.dart | 29 ++++++ ejson/lib/src/generator/generator.dart | 10 +- ejson/lib/src/types.dart | 3 + ejson/test/ejson_serialization_setup.g.dart | 9 +- 8 files changed, 129 insertions(+), 50 deletions(-) create mode 100644 ejson/lib/src/configuration.dart diff --git a/ejson/ejson_generator_test/pubspec.yaml b/ejson/ejson_generator_test/pubspec.yaml index def69820c..bcc993c08 100644 --- a/ejson/ejson_generator_test/pubspec.yaml +++ b/ejson/ejson_generator_test/pubspec.yaml @@ -14,5 +14,6 @@ dependencies: dev_dependencies: build_runner: ^2.4.4 + build_test: ^2.1.7 lints: ^2.0.0 test: ^1.21.0 diff --git a/ejson/ejson_generator_test/test/ctor_test.dart b/ejson/ejson_generator_test/test/ctor_test.dart index a30d8a3bb..64268ee99 100644 --- a/ejson/ejson_generator_test/test/ctor_test.dart +++ b/ejson/ejson_generator_test/test/ctor_test.dart @@ -41,7 +41,7 @@ class Named { class RequiredNamedParameters { final String s; @ejson - RequiredNamedParameters({required this.s}); + const RequiredNamedParameters({required this.s}); } class OptionalNamedParameters { @@ -62,51 +62,73 @@ class PrivateMembers { int get id => _id; // must match constructor parameter name @ejson - PrivateMembers(int id) : _id = id; // instead of @MapTo + const PrivateMembers(int id) : _id = id; // instead of @MapTo } -void main() { - customEncoders.addAll(const { - Empty: encodeEmpty, - Simple: encodeSimple, - Named: encodeNamed, - RequiredNamedParameters: encodeRequiredNamedParameters, - OptionalNamedParameters: encodeOptionalNamedParameters, - OptionalParameters: encodeOptionalParameters, - PrivateMembers: encodePrivateMembers, +class Person { + final String name; + final DateTime birthDate; + Duration get age => DateTime.now().difference(birthDate); + + final int? cprNumber; + final double income; + final Person? spouse; + + final children = []; + + @ejson // annotate constructor to generate decoder and encoder + Person(this.name, this.birthDate, this.income, {this.spouse, this.cprNumber}); +} + +void _testCase(T value, EJsonValue expected) { + test('encode $T to $expected', () { + expect(toEJson(value), expected); + }); + + test('decode $expected to $T', () { + expect(() => fromEJson(expected), returnsNormally); }); - customDecoders.addAll(const { - Empty: decodeEmpty, - Simple: decodeSimple, - Named: decodeNamed, - RequiredNamedParameters: decodeRequiredNamedParameters, - OptionalNamedParameters: decodeOptionalNamedParameters, - OptionalParameters: decodeOptionalParameters, - PrivateMembers: decodePrivateMembers, + test('roundtrip $expected as $T', () { + expect(toEJson(fromEJson(expected)), expected); }); - test('@ejson encode', () { - expect(Empty().toEJson(), {}); - expect(Simple(42).toEJson(), { + test('roundtrip $expected of type $T as dynamic', () { + // no here, so dynamic + expect(toEJson(fromEJson(expected)), expected); + }); +} + +void main() { + group('ctors', () { + register(encodeEmpty, decodeEmpty); + register(encodeSimple, decodeSimple); + register(encodeNamed, decodeNamed); + register(encodeRequiredNamedParameters, decodeRequiredNamedParameters); + register(encodeOptionalNamedParameters, decodeOptionalNamedParameters); + register(encodeOptionalParameters, decodeOptionalParameters); + register(encodePrivateMembers, decodePrivateMembers); + register(encodePerson, decodePerson); + + _testCase(const Empty(), {}); + _testCase(const Simple(42), { 'i': {'\$numberLong': 42} }); - expect(Named.nameIt('foobar').toEJson(), {'s': 'foobar'}); - expect(RequiredNamedParameters(s: 'foobar').toEJson(), {'s': 'foobar'}); - expect(OptionalNamedParameters().toEJson(), {'s': 'rabbit'}); - expect(OptionalParameters().toEJson(), {'s': 'racoon'}); - expect(PrivateMembers(42).toEJson(), { + _testCase(Named.nameIt('foobar'), {'s': 'foobar'}); + _testCase(const RequiredNamedParameters(s: 'foobar'), {'s': 'foobar'}); + _testCase(OptionalNamedParameters(), {'s': 'rabbit'}); + _testCase(OptionalParameters(), {'s': 'racoon'}); + _testCase(const PrivateMembers(42), { 'id': {'\$numberLong': 42} }); - }); - - test('@ejson decode', () { - expect(fromEJson({}), const Empty()); - expect( - fromEJson({ - 'i': {'\$numberLong': 42} - }), - Simple(42), - ); + _testCase(Person('Eva', DateTime(1973), 90000.0), { + 'name': 'Eva', + 'birthDate': { + '\$date': {'\$numberLong': 94690800000} + }, + 'income': {'\$numberDouble': 90000.0}, + 'spouse': null, + 'cprNumber': null, + }); }); } diff --git a/ejson/ejson_generator_test/test/ctor_test.g.dart b/ejson/ejson_generator_test/test/ctor_test.g.dart index 5d8805089..8a32326ee 100644 --- a/ejson/ejson_generator_test/test/ctor_test.g.dart +++ b/ejson/ejson_generator_test/test/ctor_test.g.dart @@ -119,3 +119,33 @@ extension PrivateMembersEJsonEncoderExtension on PrivateMembers { @pragma('vm:prefer-inline') EJsonValue toEJson() => encodePrivateMembers(this); } + +EJsonValue encodePerson(Person value) { + return { + 'name': value.name.toEJson(), + 'birthDate': value.birthDate.toEJson(), + 'income': value.income.toEJson(), + 'spouse': value.spouse.toEJson(), + 'cprNumber': value.cprNumber.toEJson() + }; +} + +Person decodePerson(EJsonValue ejson) { + return switch (ejson) { + { + 'name': EJsonValue name, + 'birthDate': EJsonValue birthDate, + 'income': EJsonValue income, + 'spouse': EJsonValue spouse, + 'cprNumber': EJsonValue cprNumber + } => + Person(name.to(), birthDate.to(), income.to(), + spouse: spouse.to(), cprNumber: cprNumber.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension PersonEJsonEncoderExtension on Person { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodePerson(this); +} diff --git a/ejson/lib/ejson.dart b/ejson/lib/ejson.dart index 15e499d90..d1d57db57 100644 --- a/ejson/lib/ejson.dart +++ b/ejson/lib/ejson.dart @@ -17,6 +17,7 @@ //////////////////////////////////////////////////////////////////////////////// export 'src/annotations.dart'; +export 'src/configuration.dart'; export 'src/decoding.dart'; export 'src/encoding.dart'; export 'src/types.dart'; diff --git a/ejson/lib/src/configuration.dart b/ejson/lib/src/configuration.dart new file mode 100644 index 000000000..edfffb893 --- /dev/null +++ b/ejson/lib/src/configuration.dart @@ -0,0 +1,29 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2023 Realm Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + +import 'package:type_plus/type_plus.dart'; + +import 'decoding.dart'; +import 'encoding.dart'; +import 'types.dart'; + +void register(EJsonEncoder encoder, EJsonDecoder decoder) { + TypePlus.add(); + customEncoders[T] = encoder; + customDecoders[T] = decoder; +} diff --git a/ejson/lib/src/generator/generator.dart b/ejson/lib/src/generator/generator.dart index 24f3550b2..a43483c66 100644 --- a/ejson/lib/src/generator/generator.dart +++ b/ejson/lib/src/generator/generator.dart @@ -44,13 +44,13 @@ class EJsonGenerator extends Generator { return ''' EJsonValue encode$className($className value) { return { - ${ctor.parameters.map((p) => "'${p.name}': value.${p.name}.toEJson()").join('\n')} + ${ctor.parameters.map((p) => "'${p.name}': value.${p.name}.toEJson()").join(',\n')} }; } $className decode$className(EJsonValue ejson) { return switch (ejson) { - ${decodePattern(ctor.parameters)} => $className${ctor.name.isEmpty ? '' : '.${ctor.name}'}( + ${decodePattern(ctor.parameters)} => $className${ctor.name.isEmpty ? '' : '.${ctor.name}'}( ${ctor.parameters.map((p) => "${p.isNamed ? '${p.name} : ' : ''}${p.name}.to<${p.type}>()").join(',\n')} ), _ => raiseInvalidEJson(ejson), @@ -70,7 +70,7 @@ String decodePattern(Iterable parameters) { if (parameters.isEmpty) { return 'Map m when m.isEmpty'; } - return parameters - .map((p) => "{'${p.name}': EJsonValue ${p.name}}") - .join(',\n'); + return '''{ + ${parameters.map((p) => "'${p.name}': EJsonValue ${p.name}").join(',\n')} + }'''; } diff --git a/ejson/lib/src/types.dart b/ejson/lib/src/types.dart index c6fc3f379..00e142758 100644 --- a/ejson/lib/src/types.dart +++ b/ejson/lib/src/types.dart @@ -56,3 +56,6 @@ final class Undefined extends UndefinedOr { } const undefined = Undefined(); + +typedef EJsonDecoder = T Function(EJsonValue ejson); +typedef EJsonEncoder = EJsonValue Function(T object); diff --git a/ejson/test/ejson_serialization_setup.g.dart b/ejson/test/ejson_serialization_setup.g.dart index 5917a522c..47090ddf5 100644 --- a/ejson/test/ejson_serialization_setup.g.dart +++ b/ejson/test/ejson_serialization_setup.g.dart @@ -1,15 +1,8 @@ // TODO: should be generated by builder import 'package:ejson/ejson.dart'; -import 'package:type_plus/type_plus.dart'; import 'person.dart'; void registerSerializableTypes() { - TypePlus.add(); - customDecoders = const { - Person: decodePerson, - }; - customEncoders = const { - Person: encodePerson, - }; + register(encodePerson, decodePerson); } From 73fa459a623b081651b06ff8b27eacfa296cfea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Thu, 1 Jun 2023 10:09:57 +0200 Subject: [PATCH 012/153] Add bad input test, and cheat a bit for dynamic tests --- .../ejson_generator_test/test/ctor_test.dart | 35 ++++++++++++------- .../test/ctor_test.g.dart | 19 +++++----- .../realm_dart/lib/src/native/realm_core.dart | 2 +- .../realm_dart/test/realm_logger_test.dart | 1 + 4 files changed, 35 insertions(+), 22 deletions(-) diff --git a/ejson/ejson_generator_test/test/ctor_test.dart b/ejson/ejson_generator_test/test/ctor_test.dart index 64268ee99..68dae1ca1 100644 --- a/ejson/ejson_generator_test/test/ctor_test.dart +++ b/ejson/ejson_generator_test/test/ctor_test.dart @@ -33,27 +33,27 @@ class Simple { } class Named { - String s; + String namedCtor; @ejson - Named.nameIt(this.s); + Named.nameIt(this.namedCtor); } class RequiredNamedParameters { - final String s; + final String requiredNamed; @ejson - const RequiredNamedParameters({required this.s}); + const RequiredNamedParameters({required this.requiredNamed}); } class OptionalNamedParameters { - String s; + String optionalNamed; @ejson - OptionalNamedParameters({this.s = 'rabbit'}); + OptionalNamedParameters({this.optionalNamed = 'rabbit'}); } class OptionalParameters { - String s; + String optional; @ejson - OptionalParameters([this.s = 'racoon']); + OptionalParameters([this.optional = 'racoon']); } class PrivateMembers { @@ -89,13 +89,21 @@ void _testCase(T value, EJsonValue expected) { expect(() => fromEJson(expected), returnsNormally); }); + EJsonValue badInput = {'bad': 'input'}; + badInput = value is Map ? [badInput] : badInput; // wrap in list for maps + test('decode $badInput to $T fails', () { + expect(() => fromEJson(badInput), throwsA(isA>())); + }); + test('roundtrip $expected as $T', () { expect(toEJson(fromEJson(expected)), expected); }); test('roundtrip $expected of type $T as dynamic', () { // no here, so dynamic - expect(toEJson(fromEJson(expected)), expected); + final decoded = fromEJson(expected); + expect(decoded, isA()); + expect(toEJson(decoded), expected); }); } @@ -114,10 +122,11 @@ void main() { _testCase(const Simple(42), { 'i': {'\$numberLong': 42} }); - _testCase(Named.nameIt('foobar'), {'s': 'foobar'}); - _testCase(const RequiredNamedParameters(s: 'foobar'), {'s': 'foobar'}); - _testCase(OptionalNamedParameters(), {'s': 'rabbit'}); - _testCase(OptionalParameters(), {'s': 'racoon'}); + _testCase(Named.nameIt('foobar'), {'namedCtor': 'foobar'}); + _testCase(const RequiredNamedParameters(requiredNamed: 'foobar'), + {'requiredNamed': 'foobar'}); + _testCase(OptionalNamedParameters(), {'optionalNamed': 'rabbit'}); + _testCase(OptionalParameters(), {'optional': 'racoon'}); _testCase(const PrivateMembers(42), { 'id': {'\$numberLong': 42} }); diff --git a/ejson/ejson_generator_test/test/ctor_test.g.dart b/ejson/ejson_generator_test/test/ctor_test.g.dart index 8a32326ee..848c10adc 100644 --- a/ejson/ejson_generator_test/test/ctor_test.g.dart +++ b/ejson/ejson_generator_test/test/ctor_test.g.dart @@ -39,12 +39,12 @@ extension SimpleEJsonEncoderExtension on Simple { } EJsonValue encodeNamed(Named value) { - return {'s': value.s.toEJson()}; + return {'namedCtor': value.namedCtor.toEJson()}; } Named decodeNamed(EJsonValue ejson) { return switch (ejson) { - {'s': EJsonValue s} => Named.nameIt(s.to()), + {'namedCtor': EJsonValue namedCtor} => Named.nameIt(namedCtor.to()), _ => raiseInvalidEJson(ejson), }; } @@ -55,12 +55,13 @@ extension NamedEJsonEncoderExtension on Named { } EJsonValue encodeRequiredNamedParameters(RequiredNamedParameters value) { - return {'s': value.s.toEJson()}; + return {'requiredNamed': value.requiredNamed.toEJson()}; } RequiredNamedParameters decodeRequiredNamedParameters(EJsonValue ejson) { return switch (ejson) { - {'s': EJsonValue s} => RequiredNamedParameters(s: s.to()), + {'requiredNamed': EJsonValue requiredNamed} => + RequiredNamedParameters(requiredNamed: requiredNamed.to()), _ => raiseInvalidEJson(ejson), }; } @@ -72,12 +73,13 @@ extension RequiredNamedParametersEJsonEncoderExtension } EJsonValue encodeOptionalNamedParameters(OptionalNamedParameters value) { - return {'s': value.s.toEJson()}; + return {'optionalNamed': value.optionalNamed.toEJson()}; } OptionalNamedParameters decodeOptionalNamedParameters(EJsonValue ejson) { return switch (ejson) { - {'s': EJsonValue s} => OptionalNamedParameters(s: s.to()), + {'optionalNamed': EJsonValue optionalNamed} => + OptionalNamedParameters(optionalNamed: optionalNamed.to()), _ => raiseInvalidEJson(ejson), }; } @@ -89,12 +91,13 @@ extension OptionalNamedParametersEJsonEncoderExtension } EJsonValue encodeOptionalParameters(OptionalParameters value) { - return {'s': value.s.toEJson()}; + return {'optional': value.optional.toEJson()}; } OptionalParameters decodeOptionalParameters(EJsonValue ejson) { return switch (ejson) { - {'s': EJsonValue s} => OptionalParameters(s.to()), + {'optional': EJsonValue optional} => + OptionalParameters(optional.to()), _ => raiseInvalidEJson(ejson), }; } diff --git a/packages/realm_dart/lib/src/native/realm_core.dart b/packages/realm_dart/lib/src/native/realm_core.dart index fa300777e..60e019dfc 100644 --- a/packages/realm_dart/lib/src/native/realm_core.dart +++ b/packages/realm_dart/lib/src/native/realm_core.dart @@ -114,7 +114,7 @@ class _RealmCore { // This disables creation of a second _RealmCore instance effectivelly making `realmCore` global variable readonly _instance = this; - // This prevents reentrancy if `realmCore` global variable is accessed during _RealmCore construction + // This prevents reentrance if `realmCore` global variable is accessed during _RealmCore construction realmCore = this; defaultRealmLogger = _initDefaultLogger(scheduler); } diff --git a/packages/realm_dart/test/realm_logger_test.dart b/packages/realm_dart/test/realm_logger_test.dart index cd83da239..b3d66fe4d 100644 --- a/packages/realm_dart/test/realm_logger_test.dart +++ b/packages/realm_dart/test/realm_logger_test.dart @@ -73,6 +73,7 @@ void main() { final completer = Completer(); Realm.logger.level = level; + await Future.delayed(const Duration(milliseconds: 10)); Realm.logger.onRecord.listen((event) { completer.complete(LoggedMessage(event.level, event.message)); }); From ccf303a4bb944e3a3984be8f3b3cbfa640055a95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Fri, 2 Jun 2023 09:02:54 +0200 Subject: [PATCH 013/153] A few compile tests in place --- ejson/ejson_generator_test/pubspec.yaml | 9 +- .../test/compile_test.dart | 153 ++++++++++++++++++ .../ejson_generator_test/test/ctor_test.dart | 5 +- ejson/lib/generator.dart | 25 ++- ejson/lib/src/annotations.dart | 34 +--- ejson/lib/src/generator/generator.dart | 4 +- ejson/lib/src/types.dart | 63 +++++--- ejson/pubspec.yaml | 5 +- 8 files changed, 241 insertions(+), 57 deletions(-) create mode 100644 ejson/ejson_generator_test/test/compile_test.dart diff --git a/ejson/ejson_generator_test/pubspec.yaml b/ejson/ejson_generator_test/pubspec.yaml index bcc993c08..3a827f138 100644 --- a/ejson/ejson_generator_test/pubspec.yaml +++ b/ejson/ejson_generator_test/pubspec.yaml @@ -1,19 +1,20 @@ name: ejson_generator_test -description: A sample command-line application. +description: A separate package for testing the ejson_generator package. version: 1.0.0 -# repository: https://github.com/my_org/my_repo + +publish_to: none environment: sdk: ^3.0.2 -# Add regular dependencies here. dependencies: ejson: path: .. - # path: ^1.8.0 dev_dependencies: build_runner: ^2.4.4 build_test: ^2.1.7 + dart_style: ^2.3.1 lints: ^2.0.0 + meta: ^1.9.1 test: ^1.21.0 diff --git a/ejson/ejson_generator_test/test/compile_test.dart b/ejson/ejson_generator_test/test/compile_test.dart new file mode 100644 index 000000000..3ec9f6fc1 --- /dev/null +++ b/ejson/ejson_generator_test/test/compile_test.dart @@ -0,0 +1,153 @@ +import 'dart:io'; + +import 'package:build_test/build_test.dart'; +import 'package:dart_style/dart_style.dart'; +import 'package:ejson/generator.dart'; +import 'package:test/test.dart'; +import 'package:meta/meta.dart'; + +final _formatter = DartFormatter(); +final _tag = RegExp(r'// \*.*\n// EJsonGenerator\n// \*.*'); + +@isTest +void testCompile(String description, dynamic source, [dynamic matcher]) { + source = source is File ? source.readAsStringSync() : source; + if (source is! String) throw ArgumentError.value(source, 'source'); + + matcher = matcher is File ? matcher.readAsStringSync() : matcher; + matcher = matcher is String + ? completion( + equals( + matcher.substring( + _tag.firstMatch(_formatter.format(matcher))!.start, // strip out any thing before the tag + ), + ), + ) + : matcher; + matcher ??= completes; // fallback + + if (matcher is! Matcher) throw ArgumentError.value(matcher, 'matcher'); + + test(description, () { + generate() async { + final writer = InMemoryAssetWriter(); + await testBuilder( + getEJsonGenerator(), + { + 'pkg|source.dart': "import 'package:ejson/ejson.dart';\n\n$source\n\nvoid main() {}", + }, + writer: writer, + reader: await PackageAssetReader.currentIsolate(), + ); + return _formatter.format(String.fromCharCodes(writer.assets.entries.single.value)); + } + + expect(generate(), matcher); + }); +} + +Future main() async { + group('user errors', () { + testCompile( + 'two annotated ctors', + r''' +class TwoAnnotatedCtors { + final int i; + @ejson + TwoAnnotatedCtors(this.i); + @ejson + TwoAnnotatedCtors.named(this.i); +} +''', + throwsA(isA().having((e) => e.message, 'message', 'Too many elements')), + ); + + testCompile( + 'private field', + r''' +class PrivateField { + final int _i; // private field okay, generating a part + @ejson + PrivateField(this._i); +} +''', + ); + + testCompile( + 'missing getter', + r''' +class MissingGetter { + final int _i; // missing a getter for _i called i + @ejson + MissingGetter(int i) : _i = i; +} +''', + throwsA(isA().having((e) => e.message, 'message', '')), + ); + + testCompile( + 'mismatching getter', + r''' +class MismatchingGetter { + final int _i; + String get i => _i.toString(); // getter is not of type int + @ejson + MismatchingGetter(int i) : _i = i; +} +''', + throwsA(isA()), + ); + + testCompile( + 'mismatching getter but custom encoder', + r''' +EJsonValue _encode(MismatchingGetterButCustomEncoder value) => {'i': value._i}; + +class MismatchingGetterButCustomEncoder { + final int _i; + String get i => _i.toString(); // getter is not of type int + @EJson(encoder: _encode) + MismatchingGetterButCustomEncoder(int i) : _i = i; +} +''', + ); + }); + + group('good', () { + testCompile( + 'empty class', + r''' +class Empty { + @ejson + const Empty(); +} +''', + ''' +// ************************************************************************** +// EJsonGenerator +// ************************************************************************** + +EJsonValue encodeEmpty(Empty value) { + return {}; +} + +Empty decodeEmpty(EJsonValue ejson) { + return switch (ejson) { + Map m when m.isEmpty => Empty(), + _ => raiseInvalidEJson(ejson), + }; +} + +extension EmptyEJsonEncoderExtension on Empty { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeEmpty(this); +} +''', + ); + }); + + await for (final generatedFile in Directory.current.list(recursive: true).where((f) => f is File && f.path.endsWith('.g.dart'))) { + final sourceFile = File(generatedFile.path.replaceFirst('.g.dart', '.dart')); + testCompile('$sourceFile', sourceFile, generatedFile); + } +} diff --git a/ejson/ejson_generator_test/test/ctor_test.dart b/ejson/ejson_generator_test/test/ctor_test.dart index 68dae1ca1..c010de1ac 100644 --- a/ejson/ejson_generator_test/test/ctor_test.dart +++ b/ejson/ejson_generator_test/test/ctor_test.dart @@ -17,6 +17,7 @@ //////////////////////////////////////////////////////////////////////////////// import 'package:ejson/ejson.dart'; +import 'package:meta/meta.dart'; import 'package:test/test.dart'; part 'ctor_test.g.dart'; @@ -80,6 +81,7 @@ class Person { Person(this.name, this.birthDate, this.income, {this.spouse, this.cprNumber}); } +@isTest void _testCase(T value, EJsonValue expected) { test('encode $T to $expected', () { expect(toEJson(value), expected); @@ -123,8 +125,7 @@ void main() { 'i': {'\$numberLong': 42} }); _testCase(Named.nameIt('foobar'), {'namedCtor': 'foobar'}); - _testCase(const RequiredNamedParameters(requiredNamed: 'foobar'), - {'requiredNamed': 'foobar'}); + _testCase(const RequiredNamedParameters(requiredNamed: 'foobar'), {'requiredNamed': 'foobar'}); _testCase(OptionalNamedParameters(), {'optionalNamed': 'rabbit'}); _testCase(OptionalParameters(), {'optional': 'racoon'}); _testCase(const PrivateMembers(42), { diff --git a/ejson/lib/generator.dart b/ejson/lib/generator.dart index 07c230cc1..a5384b4b6 100644 --- a/ejson/lib/generator.dart +++ b/ejson/lib/generator.dart @@ -20,6 +20,29 @@ import 'package:build/build.dart'; import 'package:ejson/src/generator/generator.dart'; import 'package:source_gen/source_gen.dart'; -Builder getEJsonGenerator(BuilderOptions options) { +enum EJsonError { + tooManyAnnotatedConstructors, + missingGetter, + mismatchedGetterType, +} + +extension on EJsonError { + String get message => switch (this) { + EJsonError.tooManyAnnotatedConstructors => 'Too many annotated constructors', + EJsonError.missingGetter => 'Missing getter', + EJsonError.mismatchedGetterType => 'Mismatched getter type', + }; + + Never raise() { + throw EJsonSourceError(this); + } +} + +class EJsonSourceError extends InvalidGenerationSourceError { + final EJsonError error; + EJsonSourceError(this.error) : super(error.message); +} + +Builder getEJsonGenerator([BuilderOptions? options]) { return SharedPartBuilder([EJsonGenerator()], 'ejson'); } diff --git a/ejson/lib/src/annotations.dart b/ejson/lib/src/annotations.dart index 7bf264cf3..07ff02771 100644 --- a/ejson/lib/src/annotations.dart +++ b/ejson/lib/src/annotations.dart @@ -1,3 +1,5 @@ +import 'package:ejson/ejson.dart'; + //////////////////////////////////////////////////////////////////////////////// // // Copyright 2023 Realm Inc. @@ -23,37 +25,13 @@ const ejson = EJson(); const ignore = Ignore(); /// Annotation to mark a class for extended json (ejson) serialization -class EJson { - const EJson(); +class EJson { + final EJsonEncoder? encoder; + final EJsonDecoder? decoder; + const EJson({this.encoder, this.decoder}); } /// Annotation to mark a property to be ignored wrt. ejson serialization class Ignore { const Ignore(); } - -enum EJsonType { - array, - binary, - boolean, - date, - decimal128, - document, - double, - int32, - int64, - maxKey, - minKey, - objectId, - string, - symbol, - nil, // aka. null - undefined, - // TODO: The following is not supported yet - // code, - // codeWithScope, - // databasePointer, - // databaseRef, - // regularExpression, - // timestamp, // Why? Isn't this just a date? -} diff --git a/ejson/lib/src/generator/generator.dart b/ejson/lib/src/generator/generator.dart index a43483c66..bfea93652 100644 --- a/ejson/lib/src/generator/generator.dart +++ b/ejson/lib/src/generator/generator.dart @@ -33,10 +33,10 @@ class EJsonGenerator extends Generator { FutureOr generate(LibraryReader library, BuildStep buildStep) async { final ctors = library.classes.map( (c) => c.constructors.singleWhere( - (c) => - typeChecker.firstAnnotationOf(c, throwOnUnresolved: false) != null, + (c) => typeChecker.firstAnnotationOf(c, throwOnUnresolved: false) != null, ), ); + return ctors.map((ctor) { final className = ctor.enclosingElement.name; diff --git a/ejson/lib/src/types.dart b/ejson/lib/src/types.dart index 00e142758..925011745 100644 --- a/ejson/lib/src/types.dart +++ b/ejson/lib/src/types.dart @@ -1,3 +1,9 @@ +const undefined = Undefined(); + +typedef EJsonDecoder = T Function(EJsonValue ejson); + +typedef EJsonEncoder = EJsonValue Function(T object); + //////////////////////////////////////////////////////////////////////////////// // // Copyright 2023 Realm Inc. @@ -20,42 +26,63 @@ // typedef EJsonValue = Null | String | bool | int | double | List | Map; typedef EJsonValue = Object?; +enum EJsonType { + array, + binary, + boolean, + date, + decimal128, + document, + double, + int32, + int64, + maxKey, + minKey, + objectId, + string, + symbol, + nil, // aka. null + undefined, + // TODO: The following is not supported yet + // code, + // codeWithScope, + // databasePointer, + // databaseRef, + // regularExpression, + // timestamp, // Why? Isn't this just a date? +} + enum Key { min, max } sealed class UndefinedOr { const UndefinedOr(); } -final class Defined extends UndefinedOr { - final T value; - - const Defined(this.value); +final class Undefined extends UndefinedOr { + const Undefined(); @override - bool operator ==(Object other) => - identical(this, other) || other is Defined && value == other.value; + int get hashCode => (Undefined).hashCode; @override - int get hashCode => value.hashCode; + operator ==(Object other) => other is Undefined; @override - String toString() => 'Defined<$T>($value)'; + String toString() => 'Undefined<$T>()'; } -final class Undefined extends UndefinedOr { - const Undefined(); +final class Defined extends UndefinedOr { + final T value; + + const Defined(this.value); @override - operator ==(Object other) => other is Undefined; + int get hashCode => value.hashCode; @override - String toString() => 'Undefined<$T>()'; + bool operator ==(Object other) => + identical(this, other) || other is Defined && value == other.value; @override - int get hashCode => (Undefined).hashCode; + String toString() => 'Defined<$T>($value)'; } - -const undefined = Undefined(); - -typedef EJsonDecoder = T Function(EJsonValue ejson); -typedef EJsonEncoder = EJsonValue Function(T object); diff --git a/ejson/pubspec.yaml b/ejson/pubspec.yaml index 3789bfb5c..30ded6707 100644 --- a/ejson/pubspec.yaml +++ b/ejson/pubspec.yaml @@ -21,10 +21,11 @@ environment: sdk: ^3.0.1 dependencies: - analyzer: ^5.2.0 - build: ^2.3.1 + analyzer: ^5.13.0 + build: ^2.4.0 collection: ^1.17.2 source_gen: ^1.3.2 + source_span: ^1.10.0 type_plus: ^2.0.0 dev_dependencies: From 15d5d0285c1a19605a97969d9270dca3e5b8004e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Fri, 2 Jun 2023 16:02:18 +0200 Subject: [PATCH 014/153] Split in multiple project and move to melos --- ejson/.gitignore | 1 + ejson/.vscode/settings.json | 5 +-- ejson/analysis_options.yaml | 30 -------------- ejson/bin/ejson.dart | 3 -- ejson/build.yaml | 8 ---- ejson/ejson_generator_test/.gitignore | 3 -- ejson/ejson_generator_test/pubspec.yaml | 20 ---------- ejson/lib/src/generator/util.dart | 24 ------------ ejson/melos.yaml | 29 ++++++++++++++ ejson/{ => packages/ejson}/CHANGELOG.md | 0 ejson/{ => packages/ejson}/LICENSE | 0 ejson/{ => packages/ejson}/README.md | 0 .../ejson}/analysis_options.yaml | 0 ejson/{ => packages/ejson}/example/main.dart | 0 ejson/{ => packages/ejson}/lib/ejson.dart | 1 - .../ejson}/lib/src/configuration.dart | 2 +- .../ejson}/lib/src/decoding.dart | 1 + .../ejson}/lib/src/encoding.dart | 1 + ejson/{ => packages/ejson}/lib/src/types.dart | 12 +----- ejson/packages/ejson/pubspec.yaml | 30 ++++++++++++++ .../test/ejson_serialization_setup.g.dart | 0 .../{ => packages/ejson}/test/ejson_test.dart | 1 + ejson/{ => packages/ejson}/test/person.dart | 1 + ejson/{ => packages/ejson}/test/person.g.dart | 0 ejson/packages/ejson_analyzer/.gitignore | 7 ++++ ejson/packages/ejson_analyzer/CHANGELOG.md | 3 ++ ejson/packages/ejson_analyzer/README.md | 39 +++++++++++++++++++ .../ejson_analyzer/analysis_options.yaml | 1 + .../ejson_analyzer/lib/ejson_analyzer.dart | 8 ++++ .../lib/src/ejson_analyzer_base.dart | 6 +++ ejson/packages/ejson_analyzer/pubspec.yaml | 15 +++++++ .../test/ejson_analyzer_test.dart | 16 ++++++++ ejson/packages/ejson_annotation/.gitignore | 7 ++++ ejson/packages/ejson_annotation/CHANGELOG.md | 3 ++ ejson/packages/ejson_annotation/README.md | 39 +++++++++++++++++++ .../ejson_annotation/analysis_options.yaml | 1 + .../lib/ejson_annotation.dart} | 18 ++++----- ejson/packages/ejson_annotation/pubspec.yaml | 15 +++++++ ejson/packages/ejson_generator/.gitignore | 7 ++++ ejson/packages/ejson_generator/CHANGELOG.md | 3 ++ ejson/packages/ejson_generator/README.md | 39 +++++++++++++++++++ .../ejson_generator/analysis_options.yaml | 1 + ejson/packages/ejson_generator/build.yaml | 17 ++++++++ .../ejson_generator/lib/ejson_generator.dart | 3 ++ .../ejson_generator/lib/src/builder.dart} | 6 ++- .../ejson_generator/lib/src}/generator.dart | 9 +++-- ejson/packages/ejson_generator/pubspec.yaml | 38 ++++++++++++++++++ .../ejson_generator}/test/compile_test.dart | 28 +++++++++---- .../ejson_generator}/test/ctor_test.dart | 4 +- .../ejson_generator}/test/ctor_test.g.dart | 0 ejson/packages/ejson_lint/.gitignore | 7 ++++ ejson/packages/ejson_lint/CHANGELOG.md | 3 ++ ejson/packages/ejson_lint/README.md | 39 +++++++++++++++++++ .../packages/ejson_lint/analysis_options.yaml | 1 + .../example/ejson_lint_example.dart | 6 +++ ejson/packages/ejson_lint/lib/ejson_lint.dart | 8 ++++ .../ejson_lint/lib/src/ejson_lint_base.dart | 6 +++ ejson/packages/ejson_lint/pubspec.yaml | 15 +++++++ .../ejson_lint/test/ejson_lint_test.dart | 16 ++++++++ ejson/pubspec.yaml | 32 ++------------- 60 files changed, 482 insertions(+), 156 deletions(-) create mode 100644 ejson/.gitignore delete mode 100644 ejson/analysis_options.yaml delete mode 100644 ejson/bin/ejson.dart delete mode 100644 ejson/build.yaml delete mode 100644 ejson/ejson_generator_test/.gitignore delete mode 100644 ejson/ejson_generator_test/pubspec.yaml delete mode 100644 ejson/lib/src/generator/util.dart create mode 100644 ejson/melos.yaml rename ejson/{ => packages/ejson}/CHANGELOG.md (100%) rename ejson/{ => packages/ejson}/LICENSE (100%) rename ejson/{ => packages/ejson}/README.md (100%) rename ejson/{ejson_generator_test => packages/ejson}/analysis_options.yaml (100%) rename ejson/{ => packages/ejson}/example/main.dart (100%) rename ejson/{ => packages/ejson}/lib/ejson.dart (96%) rename ejson/{ => packages/ejson}/lib/src/configuration.dart (94%) rename ejson/{ => packages/ejson}/lib/src/decoding.dart (99%) rename ejson/{ => packages/ejson}/lib/src/encoding.dart (98%) rename ejson/{ => packages/ejson}/lib/src/types.dart (86%) create mode 100644 ejson/packages/ejson/pubspec.yaml rename ejson/{ => packages/ejson}/test/ejson_serialization_setup.g.dart (100%) rename ejson/{ => packages/ejson}/test/ejson_test.dart (99%) rename ejson/{ => packages/ejson}/test/person.dart (93%) rename ejson/{ => packages/ejson}/test/person.g.dart (100%) create mode 100644 ejson/packages/ejson_analyzer/.gitignore create mode 100644 ejson/packages/ejson_analyzer/CHANGELOG.md create mode 100644 ejson/packages/ejson_analyzer/README.md create mode 100644 ejson/packages/ejson_analyzer/analysis_options.yaml create mode 100644 ejson/packages/ejson_analyzer/lib/ejson_analyzer.dart create mode 100644 ejson/packages/ejson_analyzer/lib/src/ejson_analyzer_base.dart create mode 100644 ejson/packages/ejson_analyzer/pubspec.yaml create mode 100644 ejson/packages/ejson_analyzer/test/ejson_analyzer_test.dart create mode 100644 ejson/packages/ejson_annotation/.gitignore create mode 100644 ejson/packages/ejson_annotation/CHANGELOG.md create mode 100644 ejson/packages/ejson_annotation/README.md create mode 100644 ejson/packages/ejson_annotation/analysis_options.yaml rename ejson/{lib/src/annotations.dart => packages/ejson_annotation/lib/ejson_annotation.dart} (78%) create mode 100644 ejson/packages/ejson_annotation/pubspec.yaml create mode 100644 ejson/packages/ejson_generator/.gitignore create mode 100644 ejson/packages/ejson_generator/CHANGELOG.md create mode 100644 ejson/packages/ejson_generator/README.md create mode 100644 ejson/packages/ejson_generator/analysis_options.yaml create mode 100644 ejson/packages/ejson_generator/build.yaml create mode 100644 ejson/packages/ejson_generator/lib/ejson_generator.dart rename ejson/{lib/generator.dart => packages/ejson_generator/lib/src/builder.dart} (91%) rename ejson/{lib/src/generator => packages/ejson_generator/lib/src}/generator.dart (91%) create mode 100644 ejson/packages/ejson_generator/pubspec.yaml rename ejson/{ejson_generator_test => packages/ejson_generator}/test/compile_test.dart (79%) rename ejson/{ejson_generator_test => packages/ejson_generator}/test/ctor_test.dart (97%) rename ejson/{ejson_generator_test => packages/ejson_generator}/test/ctor_test.g.dart (100%) create mode 100644 ejson/packages/ejson_lint/.gitignore create mode 100644 ejson/packages/ejson_lint/CHANGELOG.md create mode 100644 ejson/packages/ejson_lint/README.md create mode 100644 ejson/packages/ejson_lint/analysis_options.yaml create mode 100644 ejson/packages/ejson_lint/example/ejson_lint_example.dart create mode 100644 ejson/packages/ejson_lint/lib/ejson_lint.dart create mode 100644 ejson/packages/ejson_lint/lib/src/ejson_lint_base.dart create mode 100644 ejson/packages/ejson_lint/pubspec.yaml create mode 100644 ejson/packages/ejson_lint/test/ejson_lint_test.dart diff --git a/ejson/.gitignore b/ejson/.gitignore new file mode 100644 index 000000000..671e1c914 --- /dev/null +++ b/ejson/.gitignore @@ -0,0 +1 @@ +pubspec_overrides.yaml diff --git a/ejson/.vscode/settings.json b/ejson/.vscode/settings.json index 30a20a8b6..4f32ba4b6 100644 --- a/ejson/.vscode/settings.json +++ b/ejson/.vscode/settings.json @@ -1,8 +1,5 @@ { "cSpell.words": [ - "bson", - "codegen", - "ejson", - "nodoc" + "ejson" ] } \ No newline at end of file diff --git a/ejson/analysis_options.yaml b/ejson/analysis_options.yaml deleted file mode 100644 index dee8927aa..000000000 --- a/ejson/analysis_options.yaml +++ /dev/null @@ -1,30 +0,0 @@ -# This file configures the static analysis results for your project (errors, -# warnings, and lints). -# -# This enables the 'recommended' set of lints from `package:lints`. -# This set helps identify many issues that may lead to problems when running -# or consuming Dart code, and enforces writing Dart using a single, idiomatic -# style and format. -# -# If you want a smaller set of lints you can change this to specify -# 'package:lints/core.yaml'. These are just the most critical lints -# (the recommended set includes the core lints). -# The core lints are also what is used by pub.dev for scoring packages. - -include: package:lints/recommended.yaml - -# Uncomment the following section to specify additional rules. - -# linter: -# rules: -# - camel_case_types - -# analyzer: -# exclude: -# - path/to/excluded/files/** - -# For more information about the core and recommended set of lints, see -# https://dart.dev/go/core-lints - -# For additional information about configuring this file, see -# https://dart.dev/guides/language/analysis-options diff --git a/ejson/bin/ejson.dart b/ejson/bin/ejson.dart deleted file mode 100644 index e5e128a37..000000000 --- a/ejson/bin/ejson.dart +++ /dev/null @@ -1,3 +0,0 @@ -void main(List args) { - print('Hello world!'); -} diff --git a/ejson/build.yaml b/ejson/build.yaml deleted file mode 100644 index bf567e89e..000000000 --- a/ejson/build.yaml +++ /dev/null @@ -1,8 +0,0 @@ -builders: - ejson: - import: "package:ejson/generator.dart" - builder_factories: ["getEJsonGenerator"] - build_extensions: { ".dart": ["ejson.g.part"] } - auto_apply: dependents - build_to: cache - applies_builders: ["source_gen|combining_builder"] diff --git a/ejson/ejson_generator_test/.gitignore b/ejson/ejson_generator_test/.gitignore deleted file mode 100644 index 3a8579040..000000000 --- a/ejson/ejson_generator_test/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# https://dart.dev/guides/libraries/private-files -# Created by `dart pub` -.dart_tool/ diff --git a/ejson/ejson_generator_test/pubspec.yaml b/ejson/ejson_generator_test/pubspec.yaml deleted file mode 100644 index 3a827f138..000000000 --- a/ejson/ejson_generator_test/pubspec.yaml +++ /dev/null @@ -1,20 +0,0 @@ -name: ejson_generator_test -description: A separate package for testing the ejson_generator package. -version: 1.0.0 - -publish_to: none - -environment: - sdk: ^3.0.2 - -dependencies: - ejson: - path: .. - -dev_dependencies: - build_runner: ^2.4.4 - build_test: ^2.1.7 - dart_style: ^2.3.1 - lints: ^2.0.0 - meta: ^1.9.1 - test: ^1.21.0 diff --git a/ejson/lib/src/generator/util.dart b/ejson/lib/src/generator/util.dart deleted file mode 100644 index c265af390..000000000 --- a/ejson/lib/src/generator/util.dart +++ /dev/null @@ -1,24 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2023 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// - -// ignore_for_file: public_member_api_docs - -import 'package:ejson/ejson.dart'; -import 'package:source_gen/source_gen.dart'; - -const TypeChecker ejsonChecker = TypeChecker.fromRuntime(EJson); diff --git a/ejson/melos.yaml b/ejson/melos.yaml new file mode 100644 index 000000000..7b12fb5c9 --- /dev/null +++ b/ejson/melos.yaml @@ -0,0 +1,29 @@ +name: ejson + +packages: + - packages/* + +ide: + intellij: false + +scripts: + format: + description: Format Dart code. + run: dart format . + + format:check: + description: Check formatting of Dart code. + run: dart format --output none --set-exit-if-changed . + + analyze: + description: Analyze Dart code. + run: dart analyze . --fatal-infos + + test: + description: Run tests in a specific package. + run: dart test --chain-stack-traces + exec: + concurrency: 1 + packageFilters: + dirExists: + - test \ No newline at end of file diff --git a/ejson/CHANGELOG.md b/ejson/packages/ejson/CHANGELOG.md similarity index 100% rename from ejson/CHANGELOG.md rename to ejson/packages/ejson/CHANGELOG.md diff --git a/ejson/LICENSE b/ejson/packages/ejson/LICENSE similarity index 100% rename from ejson/LICENSE rename to ejson/packages/ejson/LICENSE diff --git a/ejson/README.md b/ejson/packages/ejson/README.md similarity index 100% rename from ejson/README.md rename to ejson/packages/ejson/README.md diff --git a/ejson/ejson_generator_test/analysis_options.yaml b/ejson/packages/ejson/analysis_options.yaml similarity index 100% rename from ejson/ejson_generator_test/analysis_options.yaml rename to ejson/packages/ejson/analysis_options.yaml diff --git a/ejson/example/main.dart b/ejson/packages/ejson/example/main.dart similarity index 100% rename from ejson/example/main.dart rename to ejson/packages/ejson/example/main.dart diff --git a/ejson/lib/ejson.dart b/ejson/packages/ejson/lib/ejson.dart similarity index 96% rename from ejson/lib/ejson.dart rename to ejson/packages/ejson/lib/ejson.dart index d1d57db57..729f83c08 100644 --- a/ejson/lib/ejson.dart +++ b/ejson/packages/ejson/lib/ejson.dart @@ -16,7 +16,6 @@ // //////////////////////////////////////////////////////////////////////////////// -export 'src/annotations.dart'; export 'src/configuration.dart'; export 'src/decoding.dart'; export 'src/encoding.dart'; diff --git a/ejson/lib/src/configuration.dart b/ejson/packages/ejson/lib/src/configuration.dart similarity index 94% rename from ejson/lib/src/configuration.dart rename to ejson/packages/ejson/lib/src/configuration.dart index edfffb893..308bfbde1 100644 --- a/ejson/lib/src/configuration.dart +++ b/ejson/packages/ejson/lib/src/configuration.dart @@ -16,11 +16,11 @@ // //////////////////////////////////////////////////////////////////////////////// +import 'package:ejson_annotation/ejson_annotation.dart'; import 'package:type_plus/type_plus.dart'; import 'decoding.dart'; import 'encoding.dart'; -import 'types.dart'; void register(EJsonEncoder encoder, EJsonDecoder decoder) { TypePlus.add(); diff --git a/ejson/lib/src/decoding.dart b/ejson/packages/ejson/lib/src/decoding.dart similarity index 99% rename from ejson/lib/src/decoding.dart rename to ejson/packages/ejson/lib/src/decoding.dart index 328c221e3..d08d475af 100644 --- a/ejson/lib/src/decoding.dart +++ b/ejson/packages/ejson/lib/src/decoding.dart @@ -17,6 +17,7 @@ //////////////////////////////////////////////////////////////////////////////// import 'package:collection/collection.dart'; +import 'package:ejson_annotation/ejson_annotation.dart'; import 'package:type_plus/type_plus.dart'; import 'types.dart'; diff --git a/ejson/lib/src/encoding.dart b/ejson/packages/ejson/lib/src/encoding.dart similarity index 98% rename from ejson/lib/src/encoding.dart rename to ejson/packages/ejson/lib/src/encoding.dart index a65e5107f..eff415d1b 100644 --- a/ejson/lib/src/encoding.dart +++ b/ejson/packages/ejson/lib/src/encoding.dart @@ -16,6 +16,7 @@ // //////////////////////////////////////////////////////////////////////////////// +import 'package:ejson_annotation/ejson_annotation.dart'; import 'package:type_plus/type_plus.dart'; import 'types.dart'; diff --git a/ejson/lib/src/types.dart b/ejson/packages/ejson/lib/src/types.dart similarity index 86% rename from ejson/lib/src/types.dart rename to ejson/packages/ejson/lib/src/types.dart index 925011745..cda0c0204 100644 --- a/ejson/lib/src/types.dart +++ b/ejson/packages/ejson/lib/src/types.dart @@ -1,9 +1,3 @@ -const undefined = Undefined(); - -typedef EJsonDecoder = T Function(EJsonValue ejson); - -typedef EJsonEncoder = EJsonValue Function(T object); - //////////////////////////////////////////////////////////////////////////////// // // Copyright 2023 Realm Inc. @@ -22,10 +16,6 @@ typedef EJsonEncoder = EJsonValue Function(T object); // //////////////////////////////////////////////////////////////////////////////// -// while we wait for -// typedef EJsonValue = Null | String | bool | int | double | List | Map; -typedef EJsonValue = Object?; - enum EJsonType { array, binary, @@ -71,6 +61,8 @@ final class Undefined extends UndefinedOr { String toString() => 'Undefined<$T>()'; } +const undefined = Undefined(); + final class Defined extends UndefinedOr { final T value; diff --git a/ejson/packages/ejson/pubspec.yaml b/ejson/packages/ejson/pubspec.yaml new file mode 100644 index 000000000..0c1ed1a61 --- /dev/null +++ b/ejson/packages/ejson/pubspec.yaml @@ -0,0 +1,30 @@ +name: ejson +description: >- + EJSON serialization. + + 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. + +topics: + - ejson + - bson + - json + - build-runner + - codegen + +version: 1.0.0 +repository: https://github.com/realm/realm-dart/ejson + +publish_to: none # Remove this line if you wish to publish to pub.dev + +environment: + sdk: ^3.0.1 + +dependencies: + collection: ^1.17.2 + ejson_annotation: ^0.1.0 + type_plus: ^2.0.0 + +dev_dependencies: + lints: ^2.0.0 + test: ^1.21.0 diff --git a/ejson/test/ejson_serialization_setup.g.dart b/ejson/packages/ejson/test/ejson_serialization_setup.g.dart similarity index 100% rename from ejson/test/ejson_serialization_setup.g.dart rename to ejson/packages/ejson/test/ejson_serialization_setup.g.dart diff --git a/ejson/test/ejson_test.dart b/ejson/packages/ejson/test/ejson_test.dart similarity index 99% rename from ejson/test/ejson_test.dart rename to ejson/packages/ejson/test/ejson_test.dart index 181b88779..c2cb73b33 100644 --- a/ejson/test/ejson_test.dart +++ b/ejson/packages/ejson/test/ejson_test.dart @@ -19,6 +19,7 @@ import 'dart:convert'; import 'package:ejson/ejson.dart'; +import 'package:ejson_annotation/ejson_annotation.dart'; import 'package:test/test.dart'; import 'ejson_serialization_setup.g.dart'; diff --git a/ejson/test/person.dart b/ejson/packages/ejson/test/person.dart similarity index 93% rename from ejson/test/person.dart rename to ejson/packages/ejson/test/person.dart index 5d3a65f57..c8a2be4a0 100644 --- a/ejson/test/person.dart +++ b/ejson/packages/ejson/test/person.dart @@ -1,4 +1,5 @@ import 'package:ejson/ejson.dart'; +import 'package:ejson_annotation/ejson_annotation.dart'; part 'person.g.dart'; diff --git a/ejson/test/person.g.dart b/ejson/packages/ejson/test/person.g.dart similarity index 100% rename from ejson/test/person.g.dart rename to ejson/packages/ejson/test/person.g.dart diff --git a/ejson/packages/ejson_analyzer/.gitignore b/ejson/packages/ejson_analyzer/.gitignore new file mode 100644 index 000000000..3cceda557 --- /dev/null +++ b/ejson/packages/ejson_analyzer/.gitignore @@ -0,0 +1,7 @@ +# https://dart.dev/guides/libraries/private-files +# Created by `dart pub` +.dart_tool/ + +# Avoid committing pubspec.lock for library packages; see +# https://dart.dev/guides/libraries/private-files#pubspeclock. +pubspec.lock diff --git a/ejson/packages/ejson_analyzer/CHANGELOG.md b/ejson/packages/ejson_analyzer/CHANGELOG.md new file mode 100644 index 000000000..effe43c82 --- /dev/null +++ b/ejson/packages/ejson_analyzer/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0 + +- Initial version. diff --git a/ejson/packages/ejson_analyzer/README.md b/ejson/packages/ejson_analyzer/README.md new file mode 100644 index 000000000..8b55e735b --- /dev/null +++ b/ejson/packages/ejson_analyzer/README.md @@ -0,0 +1,39 @@ + + +TODO: Put a short description of the package here that helps potential users +know whether this package might be useful for them. + +## Features + +TODO: List what your package can do. Maybe include images, gifs, or videos. + +## Getting started + +TODO: List prerequisites and provide or point to information on how to +start using the package. + +## Usage + +TODO: Include short and useful examples for package users. Add longer examples +to `/example` folder. + +```dart +const like = 'sample'; +``` + +## Additional information + +TODO: Tell users more about the package: where to find more information, how to +contribute to the package, how to file issues, what response they can expect +from the package authors, and more. diff --git a/ejson/packages/ejson_analyzer/analysis_options.yaml b/ejson/packages/ejson_analyzer/analysis_options.yaml new file mode 100644 index 000000000..ea2c9e947 --- /dev/null +++ b/ejson/packages/ejson_analyzer/analysis_options.yaml @@ -0,0 +1 @@ +include: package:lints/recommended.yaml \ No newline at end of file diff --git a/ejson/packages/ejson_analyzer/lib/ejson_analyzer.dart b/ejson/packages/ejson_analyzer/lib/ejson_analyzer.dart new file mode 100644 index 000000000..deae32011 --- /dev/null +++ b/ejson/packages/ejson_analyzer/lib/ejson_analyzer.dart @@ -0,0 +1,8 @@ +/// Support for doing something awesome. +/// +/// More dartdocs go here. +library; + +export 'src/ejson_analyzer_base.dart'; + +// TODO: Export any libraries intended for clients of this package. diff --git a/ejson/packages/ejson_analyzer/lib/src/ejson_analyzer_base.dart b/ejson/packages/ejson_analyzer/lib/src/ejson_analyzer_base.dart new file mode 100644 index 000000000..e8a6f1590 --- /dev/null +++ b/ejson/packages/ejson_analyzer/lib/src/ejson_analyzer_base.dart @@ -0,0 +1,6 @@ +// TODO: Put public facing types in this file. + +/// Checks if you are awesome. Spoiler: you are. +class Awesome { + bool get isAwesome => true; +} diff --git a/ejson/packages/ejson_analyzer/pubspec.yaml b/ejson/packages/ejson_analyzer/pubspec.yaml new file mode 100644 index 000000000..bf6dbe6cb --- /dev/null +++ b/ejson/packages/ejson_analyzer/pubspec.yaml @@ -0,0 +1,15 @@ +name: ejson_analyzer +description: A starting point for Dart libraries or applications. +version: 1.0.0 +# repository: https://github.com/my_org/my_repo + +environment: + sdk: ^3.0.2 + +# Add regular dependencies here. +dependencies: + # path: ^1.8.0 + +dev_dependencies: + lints: ^2.0.0 + test: ^1.21.0 diff --git a/ejson/packages/ejson_analyzer/test/ejson_analyzer_test.dart b/ejson/packages/ejson_analyzer/test/ejson_analyzer_test.dart new file mode 100644 index 000000000..8701d345c --- /dev/null +++ b/ejson/packages/ejson_analyzer/test/ejson_analyzer_test.dart @@ -0,0 +1,16 @@ +import 'package:ejson_analyzer/ejson_analyzer.dart'; +import 'package:test/test.dart'; + +void main() { + group('A group of tests', () { + final awesome = Awesome(); + + setUp(() { + // Additional setup goes here. + }); + + test('First Test', () { + expect(awesome.isAwesome, isTrue); + }); + }); +} diff --git a/ejson/packages/ejson_annotation/.gitignore b/ejson/packages/ejson_annotation/.gitignore new file mode 100644 index 000000000..3cceda557 --- /dev/null +++ b/ejson/packages/ejson_annotation/.gitignore @@ -0,0 +1,7 @@ +# https://dart.dev/guides/libraries/private-files +# Created by `dart pub` +.dart_tool/ + +# Avoid committing pubspec.lock for library packages; see +# https://dart.dev/guides/libraries/private-files#pubspeclock. +pubspec.lock diff --git a/ejson/packages/ejson_annotation/CHANGELOG.md b/ejson/packages/ejson_annotation/CHANGELOG.md new file mode 100644 index 000000000..effe43c82 --- /dev/null +++ b/ejson/packages/ejson_annotation/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0 + +- Initial version. diff --git a/ejson/packages/ejson_annotation/README.md b/ejson/packages/ejson_annotation/README.md new file mode 100644 index 000000000..8b55e735b --- /dev/null +++ b/ejson/packages/ejson_annotation/README.md @@ -0,0 +1,39 @@ + + +TODO: Put a short description of the package here that helps potential users +know whether this package might be useful for them. + +## Features + +TODO: List what your package can do. Maybe include images, gifs, or videos. + +## Getting started + +TODO: List prerequisites and provide or point to information on how to +start using the package. + +## Usage + +TODO: Include short and useful examples for package users. Add longer examples +to `/example` folder. + +```dart +const like = 'sample'; +``` + +## Additional information + +TODO: Tell users more about the package: where to find more information, how to +contribute to the package, how to file issues, what response they can expect +from the package authors, and more. diff --git a/ejson/packages/ejson_annotation/analysis_options.yaml b/ejson/packages/ejson_annotation/analysis_options.yaml new file mode 100644 index 000000000..ea2c9e947 --- /dev/null +++ b/ejson/packages/ejson_annotation/analysis_options.yaml @@ -0,0 +1 @@ +include: package:lints/recommended.yaml \ No newline at end of file diff --git a/ejson/lib/src/annotations.dart b/ejson/packages/ejson_annotation/lib/ejson_annotation.dart similarity index 78% rename from ejson/lib/src/annotations.dart rename to ejson/packages/ejson_annotation/lib/ejson_annotation.dart index 07ff02771..2d3e5f95e 100644 --- a/ejson/lib/src/annotations.dart +++ b/ejson/packages/ejson_annotation/lib/ejson_annotation.dart @@ -1,5 +1,3 @@ -import 'package:ejson/ejson.dart'; - //////////////////////////////////////////////////////////////////////////////// // // Copyright 2023 Realm Inc. @@ -18,12 +16,11 @@ import 'package:ejson/ejson.dart'; // //////////////////////////////////////////////////////////////////////////////// +library; + /// Annotation to mark a class for extended json (ejson) serialization const ejson = EJson(); -/// Annotation to mark a property to be ignored wrt. ejson serialization -const ignore = Ignore(); - /// Annotation to mark a class for extended json (ejson) serialization class EJson { final EJsonEncoder? encoder; @@ -31,7 +28,10 @@ class EJson { const EJson({this.encoder, this.decoder}); } -/// Annotation to mark a property to be ignored wrt. ejson serialization -class Ignore { - const Ignore(); -} +typedef EJsonDecoder = T Function(EJsonValue ejson); + +typedef EJsonEncoder = EJsonValue Function(T object); + +// while we wait for +// typedef EJsonValue = Null | String | bool | int | double | List | Map; +typedef EJsonValue = Object?; diff --git a/ejson/packages/ejson_annotation/pubspec.yaml b/ejson/packages/ejson_annotation/pubspec.yaml new file mode 100644 index 000000000..45e8b1c76 --- /dev/null +++ b/ejson/packages/ejson_annotation/pubspec.yaml @@ -0,0 +1,15 @@ +name: ejson_annotation +description: A starting point for Dart libraries or applications. +version: 1.0.0 +# repository: https://github.com/my_org/my_repo + +environment: + sdk: ^3.0.2 + +# Add regular dependencies here. +dependencies: + # path: ^1.8.0 + +dev_dependencies: + lints: ^2.0.0 + test: ^1.21.0 diff --git a/ejson/packages/ejson_generator/.gitignore b/ejson/packages/ejson_generator/.gitignore new file mode 100644 index 000000000..3cceda557 --- /dev/null +++ b/ejson/packages/ejson_generator/.gitignore @@ -0,0 +1,7 @@ +# https://dart.dev/guides/libraries/private-files +# Created by `dart pub` +.dart_tool/ + +# Avoid committing pubspec.lock for library packages; see +# https://dart.dev/guides/libraries/private-files#pubspeclock. +pubspec.lock diff --git a/ejson/packages/ejson_generator/CHANGELOG.md b/ejson/packages/ejson_generator/CHANGELOG.md new file mode 100644 index 000000000..effe43c82 --- /dev/null +++ b/ejson/packages/ejson_generator/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0 + +- Initial version. diff --git a/ejson/packages/ejson_generator/README.md b/ejson/packages/ejson_generator/README.md new file mode 100644 index 000000000..8b55e735b --- /dev/null +++ b/ejson/packages/ejson_generator/README.md @@ -0,0 +1,39 @@ + + +TODO: Put a short description of the package here that helps potential users +know whether this package might be useful for them. + +## Features + +TODO: List what your package can do. Maybe include images, gifs, or videos. + +## Getting started + +TODO: List prerequisites and provide or point to information on how to +start using the package. + +## Usage + +TODO: Include short and useful examples for package users. Add longer examples +to `/example` folder. + +```dart +const like = 'sample'; +``` + +## Additional information + +TODO: Tell users more about the package: where to find more information, how to +contribute to the package, how to file issues, what response they can expect +from the package authors, and more. diff --git a/ejson/packages/ejson_generator/analysis_options.yaml b/ejson/packages/ejson_generator/analysis_options.yaml new file mode 100644 index 000000000..ea2c9e947 --- /dev/null +++ b/ejson/packages/ejson_generator/analysis_options.yaml @@ -0,0 +1 @@ +include: package:lints/recommended.yaml \ No newline at end of file diff --git a/ejson/packages/ejson_generator/build.yaml b/ejson/packages/ejson_generator/build.yaml new file mode 100644 index 000000000..450d5362f --- /dev/null +++ b/ejson/packages/ejson_generator/build.yaml @@ -0,0 +1,17 @@ +targets: + $default: + builders: + ejson_generator: + enabled: true + generate_for: + include: + - test/** + +builders: + ejson_generator: + import: "package:ejson_generator/ejson_generator.dart" + builder_factories: ["getEJsonGenerator"] + build_extensions: { ".dart": ["ejson.g.part"] } + auto_apply: dependents + build_to: cache + applies_builders: ["source_gen|combining_builder"] diff --git a/ejson/packages/ejson_generator/lib/ejson_generator.dart b/ejson/packages/ejson_generator/lib/ejson_generator.dart new file mode 100644 index 000000000..afe6e17a9 --- /dev/null +++ b/ejson/packages/ejson_generator/lib/ejson_generator.dart @@ -0,0 +1,3 @@ +library; + +export 'src/builder.dart'; diff --git a/ejson/lib/generator.dart b/ejson/packages/ejson_generator/lib/src/builder.dart similarity index 91% rename from ejson/lib/generator.dart rename to ejson/packages/ejson_generator/lib/src/builder.dart index a5384b4b6..e61765858 100644 --- a/ejson/lib/generator.dart +++ b/ejson/packages/ejson_generator/lib/src/builder.dart @@ -17,9 +17,10 @@ //////////////////////////////////////////////////////////////////////////////// import 'package:build/build.dart'; -import 'package:ejson/src/generator/generator.dart'; import 'package:source_gen/source_gen.dart'; +import 'generator.dart'; + enum EJsonError { tooManyAnnotatedConstructors, missingGetter, @@ -28,7 +29,8 @@ enum EJsonError { extension on EJsonError { String get message => switch (this) { - EJsonError.tooManyAnnotatedConstructors => 'Too many annotated constructors', + EJsonError.tooManyAnnotatedConstructors => + 'Too many annotated constructors', EJsonError.missingGetter => 'Missing getter', EJsonError.mismatchedGetterType => 'Mismatched getter type', }; diff --git a/ejson/lib/src/generator/generator.dart b/ejson/packages/ejson_generator/lib/src/generator.dart similarity index 91% rename from ejson/lib/src/generator/generator.dart rename to ejson/packages/ejson_generator/lib/src/generator.dart index bfea93652..aedf6d2bb 100644 --- a/ejson/lib/src/generator/generator.dart +++ b/ejson/packages/ejson_generator/lib/src/generator.dart @@ -20,7 +20,7 @@ import 'dart:async'; import 'package:analyzer/dart/element/element.dart'; import 'package:build/build.dart'; -import 'package:ejson/ejson.dart'; +import 'package:ejson_annotation/ejson_annotation.dart'; import 'package:source_gen/source_gen.dart'; /// @nodoc @@ -31,9 +31,10 @@ class EJsonGenerator extends Generator { @override FutureOr generate(LibraryReader library, BuildStep buildStep) async { - final ctors = library.classes.map( - (c) => c.constructors.singleWhere( - (c) => typeChecker.firstAnnotationOf(c, throwOnUnresolved: false) != null, + final ctors = library.classes.expand( + (c) => c.constructors.where( + (c) => + typeChecker.firstAnnotationOf(c, throwOnUnresolved: false) != null, ), ); diff --git a/ejson/packages/ejson_generator/pubspec.yaml b/ejson/packages/ejson_generator/pubspec.yaml new file mode 100644 index 000000000..ac135938a --- /dev/null +++ b/ejson/packages/ejson_generator/pubspec.yaml @@ -0,0 +1,38 @@ +name: ejson_generator +description: >- + EJSON serialization. + + 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. + +topics: + - ejson + - bson + - json + - build-runner + - codegen + +version: 0.1.0 +repository: https://github.com/realm/realm-dart/ejson + +environment: + sdk: ^3.0.1 + +dependencies: + analyzer: ^5.13.0 + build: ^2.4.0 + collection: ^1.17.2 + ejson_annotation: ^0.1.0 + ejson_analyzer: ^0.1.0 + source_gen: ^1.3.2 + source_span: ^1.10.0 + +dev_dependencies: + build_runner: ^2.4.4 + build_test: ^2.1.7 + dart_style: ^2.3.1 + ejson: ^0.1.0 + lints: ^2.0.0 + meta: ^1.9.1 + test: ^1.21.0 + type_plus: ^2.0.0 diff --git a/ejson/ejson_generator_test/test/compile_test.dart b/ejson/packages/ejson_generator/test/compile_test.dart similarity index 79% rename from ejson/ejson_generator_test/test/compile_test.dart rename to ejson/packages/ejson_generator/test/compile_test.dart index 3ec9f6fc1..84ba08999 100644 --- a/ejson/ejson_generator_test/test/compile_test.dart +++ b/ejson/packages/ejson_generator/test/compile_test.dart @@ -2,7 +2,7 @@ import 'dart:io'; import 'package:build_test/build_test.dart'; import 'package:dart_style/dart_style.dart'; -import 'package:ejson/generator.dart'; +import 'package:ejson_generator/ejson_generator.dart'; import 'package:test/test.dart'; import 'package:meta/meta.dart'; @@ -19,7 +19,9 @@ void testCompile(String description, dynamic source, [dynamic matcher]) { ? completion( equals( matcher.substring( - _tag.firstMatch(_formatter.format(matcher))!.start, // strip out any thing before the tag + _tag + .firstMatch(_formatter.format(matcher))! + .start, // strip out any thing before the tag ), ), ) @@ -34,12 +36,20 @@ void testCompile(String description, dynamic source, [dynamic matcher]) { await testBuilder( getEJsonGenerator(), { - 'pkg|source.dart': "import 'package:ejson/ejson.dart';\n\n$source\n\nvoid main() {}", + 'pkg|source.dart': ''' +import 'package:ejson/ejson.dart'; +import 'package:ejson_annotation/ejson_annotation.dart'; + +$source + +void main() {} +''', }, writer: writer, reader: await PackageAssetReader.currentIsolate(), ); - return _formatter.format(String.fromCharCodes(writer.assets.entries.single.value)); + return _formatter + .format(String.fromCharCodes(writer.assets.entries.single.value)); } expect(generate(), matcher); @@ -59,7 +69,8 @@ class TwoAnnotatedCtors { TwoAnnotatedCtors.named(this.i); } ''', - throwsA(isA().having((e) => e.message, 'message', 'Too many elements')), + throwsA(isA() + .having((e) => e.message, 'message', 'Too many elements')), ); testCompile( @@ -146,8 +157,11 @@ extension EmptyEJsonEncoderExtension on Empty { ); }); - await for (final generatedFile in Directory.current.list(recursive: true).where((f) => f is File && f.path.endsWith('.g.dart'))) { - final sourceFile = File(generatedFile.path.replaceFirst('.g.dart', '.dart')); + await for (final generatedFile in Directory.current + .list(recursive: true) + .where((f) => f is File && f.path.endsWith('.g.dart'))) { + final sourceFile = + File(generatedFile.path.replaceFirst('.g.dart', '.dart')); testCompile('$sourceFile', sourceFile, generatedFile); } } diff --git a/ejson/ejson_generator_test/test/ctor_test.dart b/ejson/packages/ejson_generator/test/ctor_test.dart similarity index 97% rename from ejson/ejson_generator_test/test/ctor_test.dart rename to ejson/packages/ejson_generator/test/ctor_test.dart index c010de1ac..f61245cd8 100644 --- a/ejson/ejson_generator_test/test/ctor_test.dart +++ b/ejson/packages/ejson_generator/test/ctor_test.dart @@ -17,6 +17,7 @@ //////////////////////////////////////////////////////////////////////////////// import 'package:ejson/ejson.dart'; +import 'package:ejson_annotation/ejson_annotation.dart'; import 'package:meta/meta.dart'; import 'package:test/test.dart'; @@ -125,7 +126,8 @@ void main() { 'i': {'\$numberLong': 42} }); _testCase(Named.nameIt('foobar'), {'namedCtor': 'foobar'}); - _testCase(const RequiredNamedParameters(requiredNamed: 'foobar'), {'requiredNamed': 'foobar'}); + _testCase(const RequiredNamedParameters(requiredNamed: 'foobar'), + {'requiredNamed': 'foobar'}); _testCase(OptionalNamedParameters(), {'optionalNamed': 'rabbit'}); _testCase(OptionalParameters(), {'optional': 'racoon'}); _testCase(const PrivateMembers(42), { diff --git a/ejson/ejson_generator_test/test/ctor_test.g.dart b/ejson/packages/ejson_generator/test/ctor_test.g.dart similarity index 100% rename from ejson/ejson_generator_test/test/ctor_test.g.dart rename to ejson/packages/ejson_generator/test/ctor_test.g.dart diff --git a/ejson/packages/ejson_lint/.gitignore b/ejson/packages/ejson_lint/.gitignore new file mode 100644 index 000000000..3cceda557 --- /dev/null +++ b/ejson/packages/ejson_lint/.gitignore @@ -0,0 +1,7 @@ +# https://dart.dev/guides/libraries/private-files +# Created by `dart pub` +.dart_tool/ + +# Avoid committing pubspec.lock for library packages; see +# https://dart.dev/guides/libraries/private-files#pubspeclock. +pubspec.lock diff --git a/ejson/packages/ejson_lint/CHANGELOG.md b/ejson/packages/ejson_lint/CHANGELOG.md new file mode 100644 index 000000000..effe43c82 --- /dev/null +++ b/ejson/packages/ejson_lint/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0 + +- Initial version. diff --git a/ejson/packages/ejson_lint/README.md b/ejson/packages/ejson_lint/README.md new file mode 100644 index 000000000..8b55e735b --- /dev/null +++ b/ejson/packages/ejson_lint/README.md @@ -0,0 +1,39 @@ + + +TODO: Put a short description of the package here that helps potential users +know whether this package might be useful for them. + +## Features + +TODO: List what your package can do. Maybe include images, gifs, or videos. + +## Getting started + +TODO: List prerequisites and provide or point to information on how to +start using the package. + +## Usage + +TODO: Include short and useful examples for package users. Add longer examples +to `/example` folder. + +```dart +const like = 'sample'; +``` + +## Additional information + +TODO: Tell users more about the package: where to find more information, how to +contribute to the package, how to file issues, what response they can expect +from the package authors, and more. diff --git a/ejson/packages/ejson_lint/analysis_options.yaml b/ejson/packages/ejson_lint/analysis_options.yaml new file mode 100644 index 000000000..ea2c9e947 --- /dev/null +++ b/ejson/packages/ejson_lint/analysis_options.yaml @@ -0,0 +1 @@ +include: package:lints/recommended.yaml \ No newline at end of file diff --git a/ejson/packages/ejson_lint/example/ejson_lint_example.dart b/ejson/packages/ejson_lint/example/ejson_lint_example.dart new file mode 100644 index 000000000..eef7252f0 --- /dev/null +++ b/ejson/packages/ejson_lint/example/ejson_lint_example.dart @@ -0,0 +1,6 @@ +import 'package:ejson_lint/ejson_lint.dart'; + +void main() { + var awesome = Awesome(); + print('awesome: ${awesome.isAwesome}'); +} diff --git a/ejson/packages/ejson_lint/lib/ejson_lint.dart b/ejson/packages/ejson_lint/lib/ejson_lint.dart new file mode 100644 index 000000000..6b9894cf3 --- /dev/null +++ b/ejson/packages/ejson_lint/lib/ejson_lint.dart @@ -0,0 +1,8 @@ +/// Support for doing something awesome. +/// +/// More dartdocs go here. +library; + +export 'src/ejson_lint_base.dart'; + +// TODO: Export any libraries intended for clients of this package. diff --git a/ejson/packages/ejson_lint/lib/src/ejson_lint_base.dart b/ejson/packages/ejson_lint/lib/src/ejson_lint_base.dart new file mode 100644 index 000000000..e8a6f1590 --- /dev/null +++ b/ejson/packages/ejson_lint/lib/src/ejson_lint_base.dart @@ -0,0 +1,6 @@ +// TODO: Put public facing types in this file. + +/// Checks if you are awesome. Spoiler: you are. +class Awesome { + bool get isAwesome => true; +} diff --git a/ejson/packages/ejson_lint/pubspec.yaml b/ejson/packages/ejson_lint/pubspec.yaml new file mode 100644 index 000000000..1d3b4d1eb --- /dev/null +++ b/ejson/packages/ejson_lint/pubspec.yaml @@ -0,0 +1,15 @@ +name: ejson_lint +description: A starting point for Dart libraries or applications. +version: 1.0.0 +# repository: https://github.com/my_org/my_repo + +environment: + sdk: ^3.0.2 + +# Add regular dependencies here. +dependencies: + # path: ^1.8.0 + +dev_dependencies: + lints: ^2.0.0 + test: ^1.21.0 diff --git a/ejson/packages/ejson_lint/test/ejson_lint_test.dart b/ejson/packages/ejson_lint/test/ejson_lint_test.dart new file mode 100644 index 000000000..0993bd74a --- /dev/null +++ b/ejson/packages/ejson_lint/test/ejson_lint_test.dart @@ -0,0 +1,16 @@ +import 'package:ejson_lint/ejson_lint.dart'; +import 'package:test/test.dart'; + +void main() { + group('A group of tests', () { + final awesome = Awesome(); + + setUp(() { + // Additional setup goes here. + }); + + test('First Test', () { + expect(awesome.isAwesome, isTrue); + }); + }); +} diff --git a/ejson/pubspec.yaml b/ejson/pubspec.yaml index 30ded6707..5afa1c141 100644 --- a/ejson/pubspec.yaml +++ b/ejson/pubspec.yaml @@ -1,33 +1,7 @@ -name: ejson -description: >- - EJSON serialization. - - 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. - -topics: - - ejson - - bson - - json - - build-runner - - codegen - -version: 1.0.0 -repository: https://github.com/realm/realm-dart/ejson - -publish_to: 'none' # Remove this line if you wish to publish to pub.dev +name: ejson_workspace environment: - sdk: ^3.0.1 - -dependencies: - analyzer: ^5.13.0 - build: ^2.4.0 - collection: ^1.17.2 - source_gen: ^1.3.2 - source_span: ^1.10.0 - type_plus: ^2.0.0 + sdk: ^3.0.2 dev_dependencies: - lints: ^2.0.0 - test: ^1.21.0 + melos: ^3.1.0 From c7cfc495d367c603324fa271ff7c042f4e20609f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Fri, 2 Jun 2023 19:45:35 +0200 Subject: [PATCH 015/153] Basic source error reporting --- ejson/melos.yaml | 2 +- .../ejson_generator/lib/src/builder.dart | 18 ----- .../ejson_generator/lib/src/generator.dart | 65 ++++++++++++++++--- .../ejson_generator/test/compile_test.dart | 44 +++++++------ 4 files changed, 80 insertions(+), 49 deletions(-) diff --git a/ejson/melos.yaml b/ejson/melos.yaml index 7b12fb5c9..870785374 100644 --- a/ejson/melos.yaml +++ b/ejson/melos.yaml @@ -21,7 +21,7 @@ scripts: test: description: Run tests in a specific package. - run: dart test --chain-stack-traces + run: dart test -j1 --chain-stack-traces exec: concurrency: 1 packageFilters: diff --git a/ejson/packages/ejson_generator/lib/src/builder.dart b/ejson/packages/ejson_generator/lib/src/builder.dart index e61765858..ef32150a2 100644 --- a/ejson/packages/ejson_generator/lib/src/builder.dart +++ b/ejson/packages/ejson_generator/lib/src/builder.dart @@ -27,24 +27,6 @@ enum EJsonError { mismatchedGetterType, } -extension on EJsonError { - String get message => switch (this) { - EJsonError.tooManyAnnotatedConstructors => - 'Too many annotated constructors', - EJsonError.missingGetter => 'Missing getter', - EJsonError.mismatchedGetterType => 'Mismatched getter type', - }; - - Never raise() { - throw EJsonSourceError(this); - } -} - -class EJsonSourceError extends InvalidGenerationSourceError { - final EJsonError error; - EJsonSourceError(this.error) : super(error.message); -} - Builder getEJsonGenerator([BuilderOptions? options]) { return SharedPartBuilder([EJsonGenerator()], 'ejson'); } diff --git a/ejson/packages/ejson_generator/lib/src/generator.dart b/ejson/packages/ejson_generator/lib/src/generator.dart index aedf6d2bb..3a79d1eb0 100644 --- a/ejson/packages/ejson_generator/lib/src/generator.dart +++ b/ejson/packages/ejson_generator/lib/src/generator.dart @@ -21,25 +21,72 @@ import 'dart:async'; import 'package:analyzer/dart/element/element.dart'; import 'package:build/build.dart'; import 'package:ejson_annotation/ejson_annotation.dart'; +import 'package:ejson_generator/ejson_generator.dart'; import 'package:source_gen/source_gen.dart'; +extension on EJsonError { + String get message => switch (this) { + EJsonError.tooManyAnnotatedConstructors => + 'Too many annotated constructors', + EJsonError.missingGetter => 'Missing getter', + EJsonError.mismatchedGetterType => 'Mismatched getter type', + }; + + Never raise() { + throw EJsonSourceError(this); + } +} + +class EJsonSourceError extends InvalidGenerationSourceError { + final EJsonError error; + EJsonSourceError(this.error) : super(error.message); +} + /// @nodoc class EJsonGenerator extends Generator { const EJsonGenerator(); TypeChecker get typeChecker => TypeChecker.fromRuntime(EJson); + bool _isAnnotated(Element element) => + typeChecker.hasAnnotationOfExact(element); + @override FutureOr generate(LibraryReader library, BuildStep buildStep) async { - final ctors = library.classes.expand( - (c) => c.constructors.where( - (c) => - typeChecker.firstAnnotationOf(c, throwOnUnresolved: false) != null, - ), - ); - - return ctors.map((ctor) { - final className = ctor.enclosingElement.name; + // find all classes with annotated constructors or classes directly annotated + final annotated = library.classes + .map((cls) => + (cls, cls.constructors.where((ctor) => _isAnnotated(ctor)))) + .where((element) { + final (cls, ctors) = element; + return ctors.isNotEmpty || _isAnnotated(cls); + }); + + //buildStep. + + return annotated.map((x) { + final (cls, ctors) = x; + final className = cls.name; + + if (ctors.length > 1) { + EJsonError.tooManyAnnotatedConstructors.raise(); + } + + if (ctors.isEmpty) { + // TODO! + } + + final ctor = ctors.single; + + for (final p in ctor.parameters) { + final getter = cls.getGetter(p.name); + if (getter == null) { + EJsonError.missingGetter.raise(); + } + if (getter.returnType != p.type) { + EJsonError.mismatchedGetterType.raise(); + } + } log.info('Generating EJson for $className'); return ''' diff --git a/ejson/packages/ejson_generator/test/compile_test.dart b/ejson/packages/ejson_generator/test/compile_test.dart index 84ba08999..acaad134b 100644 --- a/ejson/packages/ejson_generator/test/compile_test.dart +++ b/ejson/packages/ejson_generator/test/compile_test.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:build_test/build_test.dart'; import 'package:dart_style/dart_style.dart'; import 'package:ejson_generator/ejson_generator.dart'; +import 'package:source_gen/source_gen.dart'; import 'package:test/test.dart'; import 'package:meta/meta.dart'; @@ -18,10 +19,9 @@ void testCompile(String description, dynamic source, [dynamic matcher]) { matcher = matcher is String ? completion( equals( + // strip out any thing before the tag matcher.substring( - _tag - .firstMatch(_formatter.format(matcher))! - .start, // strip out any thing before the tag + _tag.firstMatch(_formatter.format(matcher))?.start ?? 0, ), ), ) @@ -69,21 +69,12 @@ class TwoAnnotatedCtors { TwoAnnotatedCtors.named(this.i); } ''', - throwsA(isA() - .having((e) => e.message, 'message', 'Too many elements')), + throwsA(isA().having( + (e) => e.message, + 'message', + 'Too many annotated constructors', + )), ); - - testCompile( - 'private field', - r''' -class PrivateField { - final int _i; // private field okay, generating a part - @ejson - PrivateField(this._i); -} -''', - ); - testCompile( 'missing getter', r''' @@ -93,7 +84,7 @@ class MissingGetter { MissingGetter(int i) : _i = i; } ''', - throwsA(isA().having((e) => e.message, 'message', '')), + throwsA(isA()), ); testCompile( @@ -106,7 +97,20 @@ class MismatchingGetter { MismatchingGetter(int i) : _i = i; } ''', - throwsA(isA()), + throwsA(isA()), + ); + }); + + group('good', () { + testCompile( + 'private field', + r''' +class PrivateFieldIsOkay { + final int _i; // private fields are okay + @ejson + PrivateFieldIsOkay(this._i); +} +''', ); testCompile( @@ -122,9 +126,7 @@ class MismatchingGetterButCustomEncoder { } ''', ); - }); - group('good', () { testCompile( 'empty class', r''' From d60e9d504493572a341cdc350caa3ede8feb1d32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Fri, 2 Jun 2023 20:05:40 +0200 Subject: [PATCH 016/153] add qa script to melos.yaml (combines format:check, analyze, and test) --- ejson/melos.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ejson/melos.yaml b/ejson/melos.yaml index 870785374..bf6c54afa 100644 --- a/ejson/melos.yaml +++ b/ejson/melos.yaml @@ -7,6 +7,13 @@ ide: intellij: false scripts: + qa: + description: Run all QA scripts. + run: | + melos run format:check && + melos analyze && + melos test + format: description: Format Dart code. run: dart format . From ca3693255408eb9e24cae59e29d513d4baae5ef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Fri, 2 Jun 2023 20:52:03 +0200 Subject: [PATCH 017/153] testCompile supports skip --- ejson/packages/ejson_generator/test/compile_test.dart | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ejson/packages/ejson_generator/test/compile_test.dart b/ejson/packages/ejson_generator/test/compile_test.dart index acaad134b..e840941d6 100644 --- a/ejson/packages/ejson_generator/test/compile_test.dart +++ b/ejson/packages/ejson_generator/test/compile_test.dart @@ -11,7 +11,8 @@ final _formatter = DartFormatter(); final _tag = RegExp(r'// \*.*\n// EJsonGenerator\n// \*.*'); @isTest -void testCompile(String description, dynamic source, [dynamic matcher]) { +void testCompile(String description, dynamic source, dynamic matcher, + {dynamic skip}) { source = source is File ? source.readAsStringSync() : source; if (source is! String) throw ArgumentError.value(source, 'source'); @@ -53,7 +54,7 @@ void main() {} } expect(generate(), matcher); - }); + }, skip: skip); } Future main() async { @@ -111,6 +112,7 @@ class PrivateFieldIsOkay { PrivateFieldIsOkay(this._i); } ''', + completes, ); testCompile( @@ -125,6 +127,8 @@ class MismatchingGetterButCustomEncoder { MismatchingGetterButCustomEncoder(int i) : _i = i; } ''', + completes, + skip: "don't work yet", ); testCompile( From 453ab4e4f126ba174c16b9b6ff5cb4f1638114c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Fri, 2 Jun 2023 21:21:06 +0200 Subject: [PATCH 018/153] Enable melos qa on github actions --- .github/workflows/dart-desktop-tests.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/dart-desktop-tests.yml b/.github/workflows/dart-desktop-tests.yml index f71066670..942b74006 100644 --- a/.github/workflows/dart-desktop-tests.yml +++ b/.github/workflows/dart-desktop-tests.yml @@ -75,6 +75,13 @@ jobs: only-summary: true working-directory: packages/realm_dart + - name: Run ejson QA + run: | + dart pub global activate melos + melos bootstrap + melos qa + working-directory: ejson + # we're pruning generated files, the cli folder, as well as realm_bindings.dart from our coverage reports - name: Generate realm_dart coverage report if: inputs.runner == 'ubuntu-latest' From c686b9d4da90b2c04c3a30501cb5c01287f6a097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Fri, 2 Jun 2023 21:38:40 +0200 Subject: [PATCH 019/153] Use utc in test --- ejson/packages/ejson_generator/test/ctor_test.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ejson/packages/ejson_generator/test/ctor_test.dart b/ejson/packages/ejson_generator/test/ctor_test.dart index f61245cd8..ace38307b 100644 --- a/ejson/packages/ejson_generator/test/ctor_test.dart +++ b/ejson/packages/ejson_generator/test/ctor_test.dart @@ -133,10 +133,12 @@ void main() { _testCase(const PrivateMembers(42), { 'id': {'\$numberLong': 42} }); - _testCase(Person('Eva', DateTime(1973), 90000.0), { + + final birthDate = DateTime.utc(1973); + _testCase(Person('Eva', DateTime.utc(1973), 90000.0), { 'name': 'Eva', 'birthDate': { - '\$date': {'\$numberLong': 94690800000} + '\$date': {'\$numberLong': birthDate.millisecondsSinceEpoch} }, 'income': {'\$numberDouble': 90000.0}, 'spouse': null, From b9848389c39ab6e443808e1e7c73991a1fcc69a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Fri, 2 Jun 2023 22:04:11 +0200 Subject: [PATCH 020/153] Add LICENSE file + repo link in pubspecs --- ejson/melos.yaml | 8 +- ejson/packages/ejson/pubspec.yaml | 4 +- ejson/packages/ejson_analyzer/LICENSE | 177 +++++++++++++++++++ ejson/packages/ejson_analyzer/pubspec.yaml | 5 +- ejson/packages/ejson_annotation/LICENSE | 177 +++++++++++++++++++ ejson/packages/ejson_annotation/pubspec.yaml | 15 +- ejson/packages/ejson_generator/pubspec.yaml | 2 +- ejson/packages/ejson_lint/LICENSE | 177 +++++++++++++++++++ ejson/packages/ejson_lint/pubspec.yaml | 5 +- 9 files changed, 555 insertions(+), 15 deletions(-) create mode 100644 ejson/packages/ejson_analyzer/LICENSE create mode 100644 ejson/packages/ejson_annotation/LICENSE create mode 100644 ejson/packages/ejson_lint/LICENSE diff --git a/ejson/melos.yaml b/ejson/melos.yaml index bf6c54afa..fc8236c03 100644 --- a/ejson/melos.yaml +++ b/ejson/melos.yaml @@ -33,4 +33,10 @@ scripts: concurrency: 1 packageFilters: dirExists: - - test \ No newline at end of file + - test + + pana: + description: Run pana on all packages. + run: | + dart pub global activate pana && + dart pub global run pana --no-warning --exit-code-threshold 40 --source path . \ No newline at end of file diff --git a/ejson/packages/ejson/pubspec.yaml b/ejson/packages/ejson/pubspec.yaml index 0c1ed1a61..a7fd4e7bd 100644 --- a/ejson/packages/ejson/pubspec.yaml +++ b/ejson/packages/ejson/pubspec.yaml @@ -12,8 +12,8 @@ topics: - build-runner - codegen -version: 1.0.0 -repository: https://github.com/realm/realm-dart/ejson +version: 0.1.0 +repository: https://github.com/realm/realm-dart/ejson/packages/ejson publish_to: none # Remove this line if you wish to publish to pub.dev diff --git a/ejson/packages/ejson_analyzer/LICENSE b/ejson/packages/ejson_analyzer/LICENSE new file mode 100644 index 000000000..66a27ec5f --- /dev/null +++ b/ejson/packages/ejson_analyzer/LICENSE @@ -0,0 +1,177 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + diff --git a/ejson/packages/ejson_analyzer/pubspec.yaml b/ejson/packages/ejson_analyzer/pubspec.yaml index bf6dbe6cb..2f203d0ea 100644 --- a/ejson/packages/ejson_analyzer/pubspec.yaml +++ b/ejson/packages/ejson_analyzer/pubspec.yaml @@ -1,7 +1,8 @@ name: ejson_analyzer description: A starting point for Dart libraries or applications. -version: 1.0.0 -# repository: https://github.com/my_org/my_repo + +version: 0.1.0 +repository: https://github.com/realm/realm-dart/ejson/packages/ejson_analyzer environment: sdk: ^3.0.2 diff --git a/ejson/packages/ejson_annotation/LICENSE b/ejson/packages/ejson_annotation/LICENSE new file mode 100644 index 000000000..66a27ec5f --- /dev/null +++ b/ejson/packages/ejson_annotation/LICENSE @@ -0,0 +1,177 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + diff --git a/ejson/packages/ejson_annotation/pubspec.yaml b/ejson/packages/ejson_annotation/pubspec.yaml index 45e8b1c76..f7507edee 100644 --- a/ejson/packages/ejson_annotation/pubspec.yaml +++ b/ejson/packages/ejson_annotation/pubspec.yaml @@ -1,15 +1,16 @@ name: ejson_annotation -description: A starting point for Dart libraries or applications. -version: 1.0.0 -# repository: https://github.com/my_org/my_repo +description: >- + Annotation for EJSON serialization. + + 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.1.0 +repository: https://github.com/realm/realm-dart/ejson/packages/ejson_annotation environment: sdk: ^3.0.2 -# Add regular dependencies here. -dependencies: - # path: ^1.8.0 - dev_dependencies: lints: ^2.0.0 test: ^1.21.0 diff --git a/ejson/packages/ejson_generator/pubspec.yaml b/ejson/packages/ejson_generator/pubspec.yaml index ac135938a..8f5bd4780 100644 --- a/ejson/packages/ejson_generator/pubspec.yaml +++ b/ejson/packages/ejson_generator/pubspec.yaml @@ -13,7 +13,7 @@ topics: - codegen version: 0.1.0 -repository: https://github.com/realm/realm-dart/ejson +repository: https://github.com/realm/realm-dart/ejson/packages/ejson_generator environment: sdk: ^3.0.1 diff --git a/ejson/packages/ejson_lint/LICENSE b/ejson/packages/ejson_lint/LICENSE new file mode 100644 index 000000000..66a27ec5f --- /dev/null +++ b/ejson/packages/ejson_lint/LICENSE @@ -0,0 +1,177 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + diff --git a/ejson/packages/ejson_lint/pubspec.yaml b/ejson/packages/ejson_lint/pubspec.yaml index 1d3b4d1eb..e9d6f54d5 100644 --- a/ejson/packages/ejson_lint/pubspec.yaml +++ b/ejson/packages/ejson_lint/pubspec.yaml @@ -1,7 +1,8 @@ name: ejson_lint description: A starting point for Dart libraries or applications. -version: 1.0.0 -# repository: https://github.com/my_org/my_repo + +version: 0.1.0 +repository: https://github.com/realm/realm-dart/ejson/packages/ejson_lint environment: sdk: ^3.0.2 From e927940dee87b0f7f99c734bd4a8117bb0d65c70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Fri, 2 Jun 2023 23:13:52 +0200 Subject: [PATCH 021/153] More melos magic --- ejson/.gitignore | 1 + ejson/melos.yaml | 46 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/ejson/.gitignore b/ejson/.gitignore index 671e1c914..738c59b2f 100644 --- a/ejson/.gitignore +++ b/ejson/.gitignore @@ -1 +1,2 @@ pubspec_overrides.yaml +**/coverage/ \ No newline at end of file diff --git a/ejson/melos.yaml b/ejson/melos.yaml index fc8236c03..fd42f7e68 100644 --- a/ejson/melos.yaml +++ b/ejson/melos.yaml @@ -6,13 +6,36 @@ packages: ide: intellij: false +command: + bootstrap: + hooks: + post: melos run setup + scripts: + setup: + run: | + dart pub global activate pana && + dart pub global activate coverage + qa: - description: Run all QA scripts. + description: Run QA scripts. + run: | + melos run qa:static && + melos run test + + qa:full: + description: Run all QA scripts + run: | + melos run qa:static && + melos run coverage && + melos run pana && + melos publish --dry-run + + qa:static: + description: Run static analysis. run: | melos run format:check && - melos analyze && - melos test + melos run analyze format: description: Format Dart code. @@ -27,16 +50,25 @@ scripts: run: dart analyze . --fatal-infos test: - description: Run tests in a specific package. + description: Run tests. run: dart test -j1 --chain-stack-traces exec: concurrency: 1 packageFilters: dirExists: - test + + coverage: + description: Run tests with coverage. + run: dart test --coverage=coverage -j1 --chain-stack-traces + exec: + concurrency: 1 + packageFilters: + dirExists: + - test pana: description: Run pana on all packages. - run: | - dart pub global activate pana && - dart pub global run pana --no-warning --exit-code-threshold 40 --source path . \ No newline at end of file + run: dart pub global run pana --no-warning --exit-code-threshold 40 --source path . + exec: + concurrency: 1 \ No newline at end of file From b07b7ea30e7fc4742f8152b8ffb508d6e96833b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Sat, 3 Jun 2023 00:23:01 +0200 Subject: [PATCH 022/153] Make ejson package public --- ejson/packages/ejson/pubspec.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/ejson/packages/ejson/pubspec.yaml b/ejson/packages/ejson/pubspec.yaml index a7fd4e7bd..95bdb1750 100644 --- a/ejson/packages/ejson/pubspec.yaml +++ b/ejson/packages/ejson/pubspec.yaml @@ -15,8 +15,6 @@ topics: version: 0.1.0 repository: https://github.com/realm/realm-dart/ejson/packages/ejson -publish_to: none # Remove this line if you wish to publish to pub.dev - environment: sdk: ^3.0.1 From 3b7c93fb11ecf4cf4ed3ab5ded8a2d5eaa3046dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Sat, 3 Jun 2023 00:47:23 +0200 Subject: [PATCH 023/153] Add internal dep --- ejson/packages/ejson_lint/pubspec.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ejson/packages/ejson_lint/pubspec.yaml b/ejson/packages/ejson_lint/pubspec.yaml index e9d6f54d5..dade202b5 100644 --- a/ejson/packages/ejson_lint/pubspec.yaml +++ b/ejson/packages/ejson_lint/pubspec.yaml @@ -7,9 +7,8 @@ repository: https://github.com/realm/realm-dart/ejson/packages/ejson_lint environment: sdk: ^3.0.2 -# Add regular dependencies here. dependencies: - # path: ^1.8.0 + ejson_analyzer: ^0.1.0 dev_dependencies: lints: ^2.0.0 From 4b947fc170c3d2c50c5e891d8556944797af7328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Sat, 3 Jun 2023 10:10:47 +0200 Subject: [PATCH 024/153] Use >- over | to work around windows line ending issue --- ejson/melos.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ejson/melos.yaml b/ejson/melos.yaml index fd42f7e68..3076edc56 100644 --- a/ejson/melos.yaml +++ b/ejson/melos.yaml @@ -13,19 +13,19 @@ command: scripts: setup: - run: | + run: >- dart pub global activate pana && dart pub global activate coverage qa: description: Run QA scripts. - run: | + run: >- melos run qa:static && melos run test qa:full: description: Run all QA scripts - run: | + run: >- melos run qa:static && melos run coverage && melos run pana && @@ -33,7 +33,7 @@ scripts: qa:static: description: Run static analysis. - run: | + run: >- melos run format:check && melos run analyze From a1eacad33ff0f18c152d6e070af677d3409c459a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Sat, 3 Jun 2023 10:29:18 +0200 Subject: [PATCH 025/153] Force \n in DartFormatter due to windows line ending issue --- ejson/packages/ejson_generator/test/compile_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ejson/packages/ejson_generator/test/compile_test.dart b/ejson/packages/ejson_generator/test/compile_test.dart index e840941d6..1b6051bf7 100644 --- a/ejson/packages/ejson_generator/test/compile_test.dart +++ b/ejson/packages/ejson_generator/test/compile_test.dart @@ -7,7 +7,7 @@ import 'package:source_gen/source_gen.dart'; import 'package:test/test.dart'; import 'package:meta/meta.dart'; -final _formatter = DartFormatter(); +final _formatter = DartFormatter(lineEnding: '\n'); final _tag = RegExp(r'// \*.*\n// EJsonGenerator\n// \*.*'); @isTest From 4ccd674f498369011681aa3058975aac7cd95562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Sat, 3 Jun 2023 10:42:19 +0200 Subject: [PATCH 026/153] Drop qa:static scripts (qa:full calls qa) --- ejson/melos.yaml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/ejson/melos.yaml b/ejson/melos.yaml index 3076edc56..e94450b15 100644 --- a/ejson/melos.yaml +++ b/ejson/melos.yaml @@ -20,23 +20,18 @@ scripts: qa: description: Run QA scripts. run: >- - melos run qa:static && + melos run format:check && + melos run analyze && melos run test qa:full: description: Run all QA scripts run: >- - melos run qa:static && + melos run qa && melos run coverage && melos run pana && melos publish --dry-run - qa:static: - description: Run static analysis. - run: >- - melos run format:check && - melos run analyze - format: description: Format Dart code. run: dart format . From 94b7a633930898f653de8248a9f22992f3da67b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Sat, 3 Jun 2023 11:19:00 +0200 Subject: [PATCH 027/153] Fix bug in testCompile --- .../ejson_generator/test/compile_test.dart | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/ejson/packages/ejson_generator/test/compile_test.dart b/ejson/packages/ejson_generator/test/compile_test.dart index 1b6051bf7..82e42a938 100644 --- a/ejson/packages/ejson_generator/test/compile_test.dart +++ b/ejson/packages/ejson_generator/test/compile_test.dart @@ -17,16 +17,11 @@ void testCompile(String description, dynamic source, dynamic matcher, if (source is! String) throw ArgumentError.value(source, 'source'); matcher = matcher is File ? matcher.readAsStringSync() : matcher; - matcher = matcher is String - ? completion( - equals( - // strip out any thing before the tag - matcher.substring( - _tag.firstMatch(_formatter.format(matcher))?.start ?? 0, - ), - ), - ) - : matcher; + if (matcher is String) { + final source = _formatter.format(matcher); + matcher = completion( + equals(source.substring(_tag.firstMatch(source)?.start ?? 0))); + } matcher ??= completes; // fallback if (matcher is! Matcher) throw ArgumentError.value(matcher, 'matcher'); From 02d59b7abc9ccad8b047789cea9001be2a03dc0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Sat, 3 Jun 2023 15:26:31 +0200 Subject: [PATCH 028/153] format and check coverage --- .github/workflows/dart-desktop-tests.yml | 5 ++-- ejson/melos.yaml | 35 +++++++++++++++++++----- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/.github/workflows/dart-desktop-tests.yml b/.github/workflows/dart-desktop-tests.yml index 942b74006..ce5db6900 100644 --- a/.github/workflows/dart-desktop-tests.yml +++ b/.github/workflows/dart-desktop-tests.yml @@ -94,7 +94,8 @@ jobs: --lcov \ --packages .dart_tool/package_config.json \ --report-on lib,common - lcov --remove ./coverage/lcov.info '*.realm.dart' '*/lib/src/cli/*' '*/lib/src/native/realm_bindings.dart' -o coverage/pruned-lcov.info + lcov --remove ./coverage/lcov.info '*.g.dart' '*.realm.dart' '*/lib/src/cli/*' '*/lib/src/native/realm_bindings.dart' -o coverage/pruned-lcov.info + lcov --add-tracefile ejson/lcov.info --add-tracefile coverage/pruned-lcov.info -o coverage/merged-lcov.info - name: Publish realm_dart coverage if: inputs.runner == 'ubuntu-latest' @@ -103,7 +104,7 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} flag-name: realm_dart - path-to-lcov: packages/realm_dart/coverage/pruned-lcov.info + path-to-lcov: ./coverage/merged-lcov.info parallel: true - name: Output Coveralls response diff --git a/ejson/melos.yaml b/ejson/melos.yaml index e94450b15..0a41700c7 100644 --- a/ejson/melos.yaml +++ b/ejson/melos.yaml @@ -14,21 +14,21 @@ command: scripts: setup: run: >- - dart pub global activate pana && - dart pub global activate coverage + dart pub global activate coverage && + dart pub global activate coverde && + dart pub global activate pana qa: description: Run QA scripts. run: >- melos run format:check && melos run analyze && - melos run test + melos run coverage qa:full: description: Run all QA scripts run: >- melos run qa && - melos run coverage && melos run pana && melos publish --dry-run @@ -54,13 +54,34 @@ scripts: - test coverage: - description: Run tests with coverage. - run: dart test --coverage=coverage -j1 --chain-stack-traces + description: Generate, format, and check coverage. + run: >- + melos run coverage:generate && + melos run coverage:format && + melos run coverage:check + + coverage:generate: + description: Generate coverage. + run: dart test -j1 --chain-stack-traces --coverage=coverage + # The following command is not working with coverage:format + # run: dart pub global run coverage:test_with_coverage --branch-coverage exec: concurrency: 1 packageFilters: dirExists: - - test + - test + + coverage:format: + description: Format coverage. + run: >- + dart pub global run coverage:format_coverage + --in=. + --report-on=$MELOS_ROOT_PATH + --lcov --out=lcov.info + + coverage:check: + description: Check coverage. + run: dart pub global run coverde check 90 --input=lcov.info pana: description: Run pana on all packages. From 8995ebb34e5223bd90a707dede62776e918394a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Mon, 5 Jun 2023 15:18:19 +0200 Subject: [PATCH 029/153] Use ejson in realm --- ejson/packages/ejson/pubspec.yaml | 2 +- .../ejson_generator/lib/src/generator.dart | 3 +- ejson/packages/ejson_generator/pubspec.yaml | 4 +- packages/realm/example/lib/main.dart | 4 + packages/realm/example/lib/main.realm.dart | 2 + packages/realm_dart/build.yaml | 14 + packages/realm_dart/example/bin/myapp.dart | 4 + packages/realm_dart/example/bin/myapp.g.dart | 54 ++ .../realm_dart/example/bin/myapp.realm.dart | 2 + packages/realm_dart/pubspec.yaml | 3 + .../realm_dart/test/backlinks_test.g.dart | 51 ++ .../realm_dart/test/backlinks_test.realm.dart | 2 + packages/realm_dart/test/indexed_test.dart | 4 + packages/realm_dart/test/indexed_test.g.dart | 97 ++ .../realm_dart/test/indexed_test.realm.dart | 3 + packages/realm_dart/test/migration_test.dart | 4 + .../realm_dart/test/migration_test.g.dart | 93 ++ .../realm_dart/test/migration_test.realm.dart | 5 + .../realm_dart/test/realm_object_test.dart | 5 + .../realm_dart/test/realm_object_test.g.dart | 174 ++++ .../test/realm_object_test.realm.dart | 10 + packages/realm_dart/test/realm_set_test.dart | 5 +- .../realm_dart/test/realm_set_test.g.dart | 99 ++ .../realm_dart/test/realm_set_test.realm.dart | 2 + packages/realm_dart/test/realm_test.dart | 2 + .../realm_dart/test/realm_value_test.dart | 6 + .../realm_dart/test/realm_value_test.g.dart | 58 ++ .../test/realm_value_test.realm.dart | 3 + packages/realm_dart/test/test.dart | 4 + packages/realm_dart/test/test.g.dart | 851 ++++++++++++++++++ packages/realm_dart/test/test.realm.dart | 27 + .../lib/src/realm_model_info.dart | 1 + .../test/good_test_data/all_types.expected | 4 + .../another_mapto.expected_multi | 1 + .../test/good_test_data/binary_type.expected | 1 + .../embedded_annotations.expected | 2 + .../good_test_data/embedded_objects.expected | 3 + .../good_test_data/indexable_types.expected | 1 + .../list_initialization.expected | 1 + .../test/good_test_data/mapto.expected | 1 + .../good_test_data/optional_argument.expected | 1 + .../test/good_test_data/pinhole.expected | 1 + .../test/good_test_data/primary_key.expected | 8 + .../test/good_test_data/realm_set.expected | 2 + .../good_test_data/required_argument.expected | 1 + ...uired_argument_with_default_value.expected | 1 + .../user_defined_getter.expected | 1 + pubspec_overrides.yaml | 9 + test/backlinks_test.dart | 175 ++++ 49 files changed, 1805 insertions(+), 6 deletions(-) create mode 100644 packages/realm_dart/example/bin/myapp.g.dart create mode 100644 packages/realm_dart/test/backlinks_test.g.dart create mode 100644 packages/realm_dart/test/indexed_test.g.dart create mode 100644 packages/realm_dart/test/migration_test.g.dart create mode 100644 packages/realm_dart/test/realm_object_test.g.dart create mode 100644 packages/realm_dart/test/realm_set_test.g.dart create mode 100644 packages/realm_dart/test/realm_value_test.g.dart create mode 100644 packages/realm_dart/test/test.g.dart create mode 100644 pubspec_overrides.yaml create mode 100644 test/backlinks_test.dart diff --git a/ejson/packages/ejson/pubspec.yaml b/ejson/packages/ejson/pubspec.yaml index 95bdb1750..982b1f429 100644 --- a/ejson/packages/ejson/pubspec.yaml +++ b/ejson/packages/ejson/pubspec.yaml @@ -19,7 +19,7 @@ environment: sdk: ^3.0.1 dependencies: - collection: ^1.17.2 + collection: ^1.17.0 ejson_annotation: ^0.1.0 type_plus: ^2.0.0 diff --git a/ejson/packages/ejson_generator/lib/src/generator.dart b/ejson/packages/ejson_generator/lib/src/generator.dart index 3a79d1eb0..7fdb6ed07 100644 --- a/ejson/packages/ejson_generator/lib/src/generator.dart +++ b/ejson/packages/ejson_generator/lib/src/generator.dart @@ -83,7 +83,8 @@ class EJsonGenerator extends Generator { if (getter == null) { EJsonError.missingGetter.raise(); } - if (getter.returnType != p.type) { + if (!TypeChecker.fromStatic(p.type) + .isAssignableFromType(getter.returnType)) { EJsonError.mismatchedGetterType.raise(); } } diff --git a/ejson/packages/ejson_generator/pubspec.yaml b/ejson/packages/ejson_generator/pubspec.yaml index 8f5bd4780..6c35294a7 100644 --- a/ejson/packages/ejson_generator/pubspec.yaml +++ b/ejson/packages/ejson_generator/pubspec.yaml @@ -21,11 +21,11 @@ environment: dependencies: analyzer: ^5.13.0 build: ^2.4.0 - collection: ^1.17.2 + collection: ^1.17.0 ejson_annotation: ^0.1.0 ejson_analyzer: ^0.1.0 source_gen: ^1.3.2 - source_span: ^1.10.0 + source_span: ^1.9.0 dev_dependencies: build_runner: ^2.4.4 diff --git a/packages/realm/example/lib/main.dart b/packages/realm/example/lib/main.dart index 1d84d335b..d5bec6f44 100644 --- a/packages/realm/example/lib/main.dart +++ b/packages/realm/example/lib/main.dart @@ -17,11 +17,15 @@ //////////////////////////////////////////////////////////////////////////////// // ignore_for_file: avoid_print +import 'package:ejson_annotation/ejson_annotation.dart'; +import 'package:ejson/ejson.dart'; + import 'dart:io'; import 'package:flutter/material.dart'; import 'package:realm/realm.dart'; part 'main.realm.dart'; +part 'main.g.dart'; @RealmModel() class _Car { diff --git a/packages/realm/example/lib/main.realm.dart b/packages/realm/example/lib/main.realm.dart index c0cc2b3a5..012f020b4 100644 --- a/packages/realm/example/lib/main.realm.dart +++ b/packages/realm/example/lib/main.realm.dart @@ -10,6 +10,7 @@ part of 'main.dart'; class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { static var _defaultsSet = false; + @ejson Car( String make, { String? model, @@ -74,6 +75,7 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { static var _defaultsSet = false; + @ejson Person( String name, { int age = 1, diff --git a/packages/realm_dart/build.yaml b/packages/realm_dart/build.yaml index 48004f652..49dc3c4d2 100644 --- a/packages/realm_dart/build.yaml +++ b/packages/realm_dart/build.yaml @@ -13,6 +13,11 @@ targets: include: - test/**.dart - example/**.dart + ejson_generator: + generate_for: + include: + - test/**.dart + - example/**.dart builders: realm_generator: @@ -21,3 +26,12 @@ builders: build_extensions: { ".dart": [".realm.dart"] } auto_apply: dependents build_to: source + runs_before: ["ejson_generator|ejson_generator"] + ejson_generator: + import: "package:ejson_generator/ejson_generator.dart" + required_inputs: [".realm.dart"] + builder_factories: ["getEJsonGenerator"] + build_extensions: { ".dart": ["ejson.g.part"] } + auto_apply: dependents + build_to: cache + applies_builders: ["source_gen|combining_builder"] diff --git a/packages/realm_dart/example/bin/myapp.dart b/packages/realm_dart/example/bin/myapp.dart index ea1835071..d96b2cd62 100644 --- a/packages/realm_dart/example/bin/myapp.dart +++ b/packages/realm_dart/example/bin/myapp.dart @@ -1,8 +1,12 @@ +import 'package:ejson_annotation/ejson_annotation.dart'; +import 'package:ejson/ejson.dart'; + import 'dart:async'; import 'dart:io'; import 'package:realm_dart/realm.dart'; part 'myapp.realm.dart'; +part 'myapp.g.dart'; @RealmModel() class _Car { diff --git a/packages/realm_dart/example/bin/myapp.g.dart b/packages/realm_dart/example/bin/myapp.g.dart new file mode 100644 index 000000000..b106eafc1 --- /dev/null +++ b/packages/realm_dart/example/bin/myapp.g.dart @@ -0,0 +1,54 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'myapp.dart'; + +// ************************************************************************** +// EJsonGenerator +// ************************************************************************** + +EJsonValue encodeCar(Car value) { + return { + 'make': value.make.toEJson(), + 'model': value.model.toEJson(), + 'kilometers': value.kilometers.toEJson(), + 'owner': value.owner.toEJson() + }; +} + +Car decodeCar(EJsonValue ejson) { + return switch (ejson) { + { + 'make': EJsonValue make, + 'model': EJsonValue model, + 'kilometers': EJsonValue kilometers, + 'owner': EJsonValue owner + } => + Car(make.to(), + model: model.to(), + kilometers: kilometers.to(), + owner: owner.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension CarEJsonEncoderExtension on Car { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeCar(this); +} + +EJsonValue encodePerson(Person value) { + return {'name': value.name.toEJson(), 'age': value.age.toEJson()}; +} + +Person decodePerson(EJsonValue ejson) { + return switch (ejson) { + {'name': EJsonValue name, 'age': EJsonValue age} => + Person(name.to(), age: age.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension PersonEJsonEncoderExtension on Person { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodePerson(this); +} diff --git a/packages/realm_dart/example/bin/myapp.realm.dart b/packages/realm_dart/example/bin/myapp.realm.dart index e2e05c69b..28d357c4d 100644 --- a/packages/realm_dart/example/bin/myapp.realm.dart +++ b/packages/realm_dart/example/bin/myapp.realm.dart @@ -10,6 +10,7 @@ part of 'myapp.dart'; class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { static var _defaultsSet = false; + @ejson Car( String make, { String? model, @@ -74,6 +75,7 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { static var _defaultsSet = false; + @ejson Person( String name, { int age = 1, diff --git a/packages/realm_dart/pubspec.yaml b/packages/realm_dart/pubspec.yaml index 07f44ac95..a1360aa1f 100644 --- a/packages/realm_dart/pubspec.yaml +++ b/packages/realm_dart/pubspec.yaml @@ -16,6 +16,8 @@ dependencies: build_cli_annotations: ^2.0.0 collection: ^1.16.0 crypto: ^3.0.0 + ejson_annotation: ^0.1.0 + ejson: ^0.1.0 ffi: ^2.0.1 json_annotation: ^4.7.0 logging: ^1.2.0 @@ -35,6 +37,7 @@ dependencies: dev_dependencies: build_cli: ^2.2.2 + ejson_generator: ^0.1.0 json_serializable: ^6.3.1 lints: ^3.0.0 test: ^1.14.3 diff --git a/packages/realm_dart/test/backlinks_test.g.dart b/packages/realm_dart/test/backlinks_test.g.dart new file mode 100644 index 000000000..10c2ae09d --- /dev/null +++ b/packages/realm_dart/test/backlinks_test.g.dart @@ -0,0 +1,51 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'backlinks_test.dart'; + +// ************************************************************************** +// EJsonGenerator +// ************************************************************************** + +EJsonValue encodeSource(Source value) { + return { + 'name': value.name.toEJson(), + 'oneTarget': value.oneTarget.toEJson(), + 'manyTargets': value.manyTargets.toEJson() + }; +} + +Source decodeSource(EJsonValue ejson) { + return switch (ejson) { + { + 'name': EJsonValue name, + 'oneTarget': EJsonValue oneTarget, + 'manyTargets': EJsonValue manyTargets + } => + Source( + name: name.to(), + oneTarget: oneTarget.to(), + manyTargets: manyTargets.to>()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension SourceEJsonEncoderExtension on Source { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeSource(this); +} + +EJsonValue encodeTarget(Target value) { + return {'name': value.name.toEJson()}; +} + +Target decodeTarget(EJsonValue ejson) { + return switch (ejson) { + {'name': EJsonValue name} => Target(name: name.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension TargetEJsonEncoderExtension on Target { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeTarget(this); +} diff --git a/packages/realm_dart/test/backlinks_test.realm.dart b/packages/realm_dart/test/backlinks_test.realm.dart index d8f144ad3..9d374a1a9 100644 --- a/packages/realm_dart/test/backlinks_test.realm.dart +++ b/packages/realm_dart/test/backlinks_test.realm.dart @@ -10,6 +10,7 @@ part of 'backlinks_test.dart'; class Source extends _Source with RealmEntity, RealmObjectBase, RealmObject { static var _defaultsSet = false; + @ejson Source({ String name = 'source', Target? oneTarget, @@ -95,6 +96,7 @@ class Source extends _Source with RealmEntity, RealmObjectBase, RealmObject { class Target extends _Target with RealmEntity, RealmObjectBase, RealmObject { static var _defaultsSet = false; + @ejson Target({ String name = 'target', Source? source, diff --git a/packages/realm_dart/test/indexed_test.dart b/packages/realm_dart/test/indexed_test.dart index edf8d6417..1def604ef 100644 --- a/packages/realm_dart/test/indexed_test.dart +++ b/packages/realm_dart/test/indexed_test.dart @@ -16,6 +16,9 @@ // //////////////////////////////////////////////////////////////////////////////// +import 'package:ejson_annotation/ejson_annotation.dart'; +import 'package:ejson/ejson.dart'; + import 'dart:math'; import 'dart:typed_data'; @@ -27,6 +30,7 @@ import 'test.dart'; import 'package:realm_dart/realm.dart'; part 'indexed_test.realm.dart'; +part 'indexed_test.g.dart'; // Don't import our own test.dart here. It will break AOT compilation. // We may use AOT compilation locally to manually run the performance diff --git a/packages/realm_dart/test/indexed_test.g.dart b/packages/realm_dart/test/indexed_test.g.dart new file mode 100644 index 000000000..6f1f1cb86 --- /dev/null +++ b/packages/realm_dart/test/indexed_test.g.dart @@ -0,0 +1,97 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'indexed_test.dart'; + +// ************************************************************************** +// EJsonGenerator +// ************************************************************************** + +EJsonValue encodeWithIndexes(WithIndexes value) { + return { + 'anInt': value.anInt.toEJson(), + 'aBool': value.aBool.toEJson(), + 'string': value.string.toEJson(), + 'timestamp': value.timestamp.toEJson(), + 'objectId': value.objectId.toEJson(), + 'uuid': value.uuid.toEJson() + }; +} + +WithIndexes decodeWithIndexes(EJsonValue ejson) { + return switch (ejson) { + { + 'anInt': EJsonValue anInt, + 'aBool': EJsonValue aBool, + 'string': EJsonValue string, + 'timestamp': EJsonValue timestamp, + 'objectId': EJsonValue objectId, + 'uuid': EJsonValue uuid + } => + WithIndexes(anInt.to(), aBool.to(), string.to(), + timestamp.to(), objectId.to(), uuid.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension WithIndexesEJsonEncoderExtension on WithIndexes { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeWithIndexes(this); +} + +EJsonValue encodeNoIndexes(NoIndexes value) { + return { + 'anInt': value.anInt.toEJson(), + 'aBool': value.aBool.toEJson(), + 'string': value.string.toEJson(), + 'timestamp': value.timestamp.toEJson(), + 'objectId': value.objectId.toEJson(), + 'uuid': value.uuid.toEJson() + }; +} + +NoIndexes decodeNoIndexes(EJsonValue ejson) { + return switch (ejson) { + { + 'anInt': EJsonValue anInt, + 'aBool': EJsonValue aBool, + 'string': EJsonValue string, + 'timestamp': EJsonValue timestamp, + 'objectId': EJsonValue objectId, + 'uuid': EJsonValue uuid + } => + NoIndexes(anInt.to(), aBool.to(), string.to(), + timestamp.to(), objectId.to(), uuid.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension NoIndexesEJsonEncoderExtension on NoIndexes { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeNoIndexes(this); +} + +EJsonValue encodeObjectWithFTSIndex(ObjectWithFTSIndex value) { + return { + 'title': value.title.toEJson(), + 'summary': value.summary.toEJson(), + 'nullableSummary': value.nullableSummary.toEJson() + }; +} + +ObjectWithFTSIndex decodeObjectWithFTSIndex(EJsonValue ejson) { + return switch (ejson) { + { + 'title': EJsonValue title, + 'summary': EJsonValue summary, + 'nullableSummary': EJsonValue nullableSummary + } => + ObjectWithFTSIndex(title.to(), summary.to(), + nullableSummary: nullableSummary.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension ObjectWithFTSIndexEJsonEncoderExtension on ObjectWithFTSIndex { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeObjectWithFTSIndex(this); +} diff --git a/packages/realm_dart/test/indexed_test.realm.dart b/packages/realm_dart/test/indexed_test.realm.dart index 79787b278..9d96e92ab 100644 --- a/packages/realm_dart/test/indexed_test.realm.dart +++ b/packages/realm_dart/test/indexed_test.realm.dart @@ -9,6 +9,7 @@ part of 'indexed_test.dart'; // ignore_for_file: type=lint class WithIndexes extends _WithIndexes with RealmEntity, RealmObjectBase, RealmObject { + @ejson WithIndexes( int anInt, bool aBool, @@ -91,6 +92,7 @@ class WithIndexes extends _WithIndexes class NoIndexes extends _NoIndexes with RealmEntity, RealmObjectBase, RealmObject { + @ejson NoIndexes( int anInt, bool aBool, @@ -166,6 +168,7 @@ class NoIndexes extends _NoIndexes class ObjectWithFTSIndex extends _ObjectWithFTSIndex with RealmEntity, RealmObjectBase, RealmObject { + @ejson ObjectWithFTSIndex( String title, String summary, { diff --git a/packages/realm_dart/test/migration_test.dart b/packages/realm_dart/test/migration_test.dart index 9c26de0ac..28157dd28 100644 --- a/packages/realm_dart/test/migration_test.dart +++ b/packages/realm_dart/test/migration_test.dart @@ -18,6 +18,9 @@ // ignore_for_file: unused_local_variable +import 'package:ejson_annotation/ejson_annotation.dart'; +import 'package:ejson/ejson.dart'; + import 'dart:async'; import 'package:test/test.dart' hide test, throws; import 'package:realm_dart/realm.dart'; @@ -27,6 +30,7 @@ import 'package:realm_dart/src/realm_object.dart'; import 'package:realm_dart/src/list.dart'; part 'migration_test.realm.dart'; +part 'migration_test.g.dart'; @RealmModel() @MapTo("Person") diff --git a/packages/realm_dart/test/migration_test.g.dart b/packages/realm_dart/test/migration_test.g.dart new file mode 100644 index 000000000..aa1724d2e --- /dev/null +++ b/packages/realm_dart/test/migration_test.g.dart @@ -0,0 +1,93 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'migration_test.dart'; + +// ************************************************************************** +// EJsonGenerator +// ************************************************************************** + +EJsonValue encodePersonIntName(PersonIntName value) { + return {'name': value.name.toEJson()}; +} + +PersonIntName decodePersonIntName(EJsonValue ejson) { + return switch (ejson) { + {'name': EJsonValue name} => PersonIntName(name.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension PersonIntNameEJsonEncoderExtension on PersonIntName { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodePersonIntName(this); +} + +EJsonValue encodeStudentV1(StudentV1 value) { + return { + 'name': value.name.toEJson(), + 'yearOfBirth': value.yearOfBirth.toEJson() + }; +} + +StudentV1 decodeStudentV1(EJsonValue ejson) { + return switch (ejson) { + {'name': EJsonValue name, 'yearOfBirth': EJsonValue yearOfBirth} => + StudentV1(name.to(), yearOfBirth: yearOfBirth.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension StudentV1EJsonEncoderExtension on StudentV1 { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeStudentV1(this); +} + +EJsonValue encodeMyObjectWithTypo(MyObjectWithTypo value) { + return {'nmae': value.nmae.toEJson(), 'vlaue': value.vlaue.toEJson()}; +} + +MyObjectWithTypo decodeMyObjectWithTypo(EJsonValue ejson) { + return switch (ejson) { + {'nmae': EJsonValue nmae, 'vlaue': EJsonValue vlaue} => + MyObjectWithTypo(nmae.to(), vlaue.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension MyObjectWithTypoEJsonEncoderExtension on MyObjectWithTypo { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeMyObjectWithTypo(this); +} + +EJsonValue encodeMyObjectWithoutTypo(MyObjectWithoutTypo value) { + return {'name': value.name.toEJson(), 'value': value.value.toEJson()}; +} + +MyObjectWithoutTypo decodeMyObjectWithoutTypo(EJsonValue ejson) { + return switch (ejson) { + {'name': EJsonValue name, 'value': EJsonValue value} => + MyObjectWithoutTypo(name.to(), value.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension MyObjectWithoutTypoEJsonEncoderExtension on MyObjectWithoutTypo { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeMyObjectWithoutTypo(this); +} + +EJsonValue encodeMyObjectWithoutValue(MyObjectWithoutValue value) { + return {'name': value.name.toEJson()}; +} + +MyObjectWithoutValue decodeMyObjectWithoutValue(EJsonValue ejson) { + return switch (ejson) { + {'name': EJsonValue name} => MyObjectWithoutValue(name.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension MyObjectWithoutValueEJsonEncoderExtension on MyObjectWithoutValue { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeMyObjectWithoutValue(this); +} diff --git a/packages/realm_dart/test/migration_test.realm.dart b/packages/realm_dart/test/migration_test.realm.dart index f38fa5703..1eb10017d 100644 --- a/packages/realm_dart/test/migration_test.realm.dart +++ b/packages/realm_dart/test/migration_test.realm.dart @@ -9,6 +9,7 @@ part of 'migration_test.dart'; // ignore_for_file: type=lint class PersonIntName extends _PersonIntName with RealmEntity, RealmObjectBase, RealmObject { + @ejson PersonIntName( int name, ) { @@ -41,6 +42,7 @@ class PersonIntName extends _PersonIntName class StudentV1 extends _StudentV1 with RealmEntity, RealmObjectBase, RealmObject { + @ejson StudentV1( String name, { int? yearOfBirth, @@ -82,6 +84,7 @@ class StudentV1 extends _StudentV1 class MyObjectWithTypo extends _MyObjectWithTypo with RealmEntity, RealmObjectBase, RealmObject { + @ejson MyObjectWithTypo( String nmae, int vlaue, @@ -124,6 +127,7 @@ class MyObjectWithTypo extends _MyObjectWithTypo class MyObjectWithoutTypo extends _MyObjectWithoutTypo with RealmEntity, RealmObjectBase, RealmObject { + @ejson MyObjectWithoutTypo( String name, int value, @@ -166,6 +170,7 @@ class MyObjectWithoutTypo extends _MyObjectWithoutTypo class MyObjectWithoutValue extends _MyObjectWithoutValue with RealmEntity, RealmObjectBase, RealmObject { + @ejson MyObjectWithoutValue( String name, ) { diff --git a/packages/realm_dart/test/realm_object_test.dart b/packages/realm_dart/test/realm_object_test.dart index e384ff361..0b4ee1d06 100644 --- a/packages/realm_dart/test/realm_object_test.dart +++ b/packages/realm_dart/test/realm_object_test.dart @@ -18,6 +18,10 @@ // ignore_for_file: unused_local_variable, avoid_relative_lib_imports +import 'package:ejson_annotation/ejson_annotation.dart'; +import 'package:ejson/ejson.dart'; + +import 'dart:io'; import 'dart:typed_data'; import 'package:test/test.dart' hide test, throws; import 'package:realm_dart/realm.dart'; @@ -25,6 +29,7 @@ import 'package:realm_dart/realm.dart'; import 'test.dart'; part 'realm_object_test.realm.dart'; +part 'realm_object_test.g.dart'; @RealmModel() class _ObjectIdPrimaryKey { diff --git a/packages/realm_dart/test/realm_object_test.g.dart b/packages/realm_dart/test/realm_object_test.g.dart new file mode 100644 index 000000000..dfefdcb38 --- /dev/null +++ b/packages/realm_dart/test/realm_object_test.g.dart @@ -0,0 +1,174 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'realm_object_test.dart'; + +// ************************************************************************** +// EJsonGenerator +// ************************************************************************** + +EJsonValue encodeObjectIdPrimaryKey(ObjectIdPrimaryKey value) { + return {'id': value.id.toEJson()}; +} + +ObjectIdPrimaryKey decodeObjectIdPrimaryKey(EJsonValue ejson) { + return switch (ejson) { + {'id': EJsonValue id} => ObjectIdPrimaryKey(id.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension ObjectIdPrimaryKeyEJsonEncoderExtension on ObjectIdPrimaryKey { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeObjectIdPrimaryKey(this); +} + +EJsonValue encodeNullableObjectIdPrimaryKey(NullableObjectIdPrimaryKey value) { + return {'id': value.id.toEJson()}; +} + +NullableObjectIdPrimaryKey decodeNullableObjectIdPrimaryKey(EJsonValue ejson) { + return switch (ejson) { + {'id': EJsonValue id} => NullableObjectIdPrimaryKey(id.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension NullableObjectIdPrimaryKeyEJsonEncoderExtension + on NullableObjectIdPrimaryKey { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeNullableObjectIdPrimaryKey(this); +} + +EJsonValue encodeIntPrimaryKey(IntPrimaryKey value) { + return {'id': value.id.toEJson()}; +} + +IntPrimaryKey decodeIntPrimaryKey(EJsonValue ejson) { + return switch (ejson) { + {'id': EJsonValue id} => IntPrimaryKey(id.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension IntPrimaryKeyEJsonEncoderExtension on IntPrimaryKey { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeIntPrimaryKey(this); +} + +EJsonValue encodeNullableIntPrimaryKey(NullableIntPrimaryKey value) { + return {'id': value.id.toEJson()}; +} + +NullableIntPrimaryKey decodeNullableIntPrimaryKey(EJsonValue ejson) { + return switch (ejson) { + {'id': EJsonValue id} => NullableIntPrimaryKey(id.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension NullableIntPrimaryKeyEJsonEncoderExtension on NullableIntPrimaryKey { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeNullableIntPrimaryKey(this); +} + +EJsonValue encodeStringPrimaryKey(StringPrimaryKey value) { + return {'id': value.id.toEJson()}; +} + +StringPrimaryKey decodeStringPrimaryKey(EJsonValue ejson) { + return switch (ejson) { + {'id': EJsonValue id} => StringPrimaryKey(id.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension StringPrimaryKeyEJsonEncoderExtension on StringPrimaryKey { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeStringPrimaryKey(this); +} + +EJsonValue encodeNullableStringPrimaryKey(NullableStringPrimaryKey value) { + return {'id': value.id.toEJson()}; +} + +NullableStringPrimaryKey decodeNullableStringPrimaryKey(EJsonValue ejson) { + return switch (ejson) { + {'id': EJsonValue id} => NullableStringPrimaryKey(id.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension NullableStringPrimaryKeyEJsonEncoderExtension + on NullableStringPrimaryKey { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeNullableStringPrimaryKey(this); +} + +EJsonValue encodeUuidPrimaryKey(UuidPrimaryKey value) { + return {'id': value.id.toEJson()}; +} + +UuidPrimaryKey decodeUuidPrimaryKey(EJsonValue ejson) { + return switch (ejson) { + {'id': EJsonValue id} => UuidPrimaryKey(id.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension UuidPrimaryKeyEJsonEncoderExtension on UuidPrimaryKey { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeUuidPrimaryKey(this); +} + +EJsonValue encodeNullableUuidPrimaryKey(NullableUuidPrimaryKey value) { + return {'id': value.id.toEJson()}; +} + +NullableUuidPrimaryKey decodeNullableUuidPrimaryKey(EJsonValue ejson) { + return switch (ejson) { + {'id': EJsonValue id} => NullableUuidPrimaryKey(id.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension NullableUuidPrimaryKeyEJsonEncoderExtension + on NullableUuidPrimaryKey { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeNullableUuidPrimaryKey(this); +} + +EJsonValue encodeRemappedFromAnotherFile(RemappedFromAnotherFile value) { + return {'linkToAnotherClass': value.linkToAnotherClass.toEJson()}; +} + +RemappedFromAnotherFile decodeRemappedFromAnotherFile(EJsonValue ejson) { + return switch (ejson) { + {'linkToAnotherClass': EJsonValue linkToAnotherClass} => + RemappedFromAnotherFile( + linkToAnotherClass: linkToAnotherClass.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension RemappedFromAnotherFileEJsonEncoderExtension + on RemappedFromAnotherFile { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeRemappedFromAnotherFile(this); +} + +EJsonValue encodeBoolValue(BoolValue value) { + return {'key': value.key.toEJson(), 'value': value.value.toEJson()}; +} + +BoolValue decodeBoolValue(EJsonValue ejson) { + return switch (ejson) { + {'key': EJsonValue key, 'value': EJsonValue value} => + BoolValue(key.to(), value.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension BoolValueEJsonEncoderExtension on BoolValue { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeBoolValue(this); +} diff --git a/packages/realm_dart/test/realm_object_test.realm.dart b/packages/realm_dart/test/realm_object_test.realm.dart index a49ff88c5..c55b72bdd 100644 --- a/packages/realm_dart/test/realm_object_test.realm.dart +++ b/packages/realm_dart/test/realm_object_test.realm.dart @@ -9,6 +9,7 @@ part of 'realm_object_test.dart'; // ignore_for_file: type=lint class ObjectIdPrimaryKey extends _ObjectIdPrimaryKey with RealmEntity, RealmObjectBase, RealmObject { + @ejson ObjectIdPrimaryKey( ObjectId id, ) { @@ -43,6 +44,7 @@ class ObjectIdPrimaryKey extends _ObjectIdPrimaryKey class NullableObjectIdPrimaryKey extends _NullableObjectIdPrimaryKey with RealmEntity, RealmObjectBase, RealmObject { + @ejson NullableObjectIdPrimaryKey( ObjectId? id, ) { @@ -78,6 +80,7 @@ class NullableObjectIdPrimaryKey extends _NullableObjectIdPrimaryKey class IntPrimaryKey extends _IntPrimaryKey with RealmEntity, RealmObjectBase, RealmObject { + @ejson IntPrimaryKey( int id, ) { @@ -111,6 +114,7 @@ class IntPrimaryKey extends _IntPrimaryKey class NullableIntPrimaryKey extends _NullableIntPrimaryKey with RealmEntity, RealmObjectBase, RealmObject { + @ejson NullableIntPrimaryKey( int? id, ) { @@ -146,6 +150,7 @@ class NullableIntPrimaryKey extends _NullableIntPrimaryKey class StringPrimaryKey extends _StringPrimaryKey with RealmEntity, RealmObjectBase, RealmObject { + @ejson StringPrimaryKey( String id, ) { @@ -180,6 +185,7 @@ class StringPrimaryKey extends _StringPrimaryKey class NullableStringPrimaryKey extends _NullableStringPrimaryKey with RealmEntity, RealmObjectBase, RealmObject { + @ejson NullableStringPrimaryKey( String? id, ) { @@ -215,6 +221,7 @@ class NullableStringPrimaryKey extends _NullableStringPrimaryKey class UuidPrimaryKey extends _UuidPrimaryKey with RealmEntity, RealmObjectBase, RealmObject { + @ejson UuidPrimaryKey( Uuid id, ) { @@ -248,6 +255,7 @@ class UuidPrimaryKey extends _UuidPrimaryKey class NullableUuidPrimaryKey extends _NullableUuidPrimaryKey with RealmEntity, RealmObjectBase, RealmObject { + @ejson NullableUuidPrimaryKey( Uuid? id, ) { @@ -283,6 +291,7 @@ class NullableUuidPrimaryKey extends _NullableUuidPrimaryKey class RemappedFromAnotherFile extends _RemappedFromAnotherFile with RealmEntity, RealmObjectBase, RealmObject { + @ejson RemappedFromAnotherFile({ RemappedClass? linkToAnotherClass, }) { @@ -323,6 +332,7 @@ class RemappedFromAnotherFile extends _RemappedFromAnotherFile class BoolValue extends _BoolValue with RealmEntity, RealmObjectBase, RealmObject { + @ejson BoolValue( int key, bool value, diff --git a/packages/realm_dart/test/realm_set_test.dart b/packages/realm_dart/test/realm_set_test.dart index 43eb5a9d1..3e7fa0765 100644 --- a/packages/realm_dart/test/realm_set_test.dart +++ b/packages/realm_dart/test/realm_set_test.dart @@ -16,15 +16,16 @@ // //////////////////////////////////////////////////////////////////////////////// -import 'dart:typed_data'; +import 'package:ejson_annotation/ejson_annotation.dart'; +import 'package:ejson/ejson.dart'; -import 'package:collection/collection.dart'; import 'package:test/test.dart' hide test, throws; import 'package:realm_dart/realm.dart'; import 'test.dart'; part 'realm_set_test.realm.dart'; +part 'realm_set_test.g.dart'; class _NullableBool {} diff --git a/packages/realm_dart/test/realm_set_test.g.dart b/packages/realm_dart/test/realm_set_test.g.dart new file mode 100644 index 000000000..62747765d --- /dev/null +++ b/packages/realm_dart/test/realm_set_test.g.dart @@ -0,0 +1,99 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'realm_set_test.dart'; + +// ************************************************************************** +// EJsonGenerator +// ************************************************************************** + +EJsonValue encodeCar(Car value) { + return {'make': value.make.toEJson(), 'color': value.color.toEJson()}; +} + +Car decodeCar(EJsonValue ejson) { + return switch (ejson) { + {'make': EJsonValue make, 'color': EJsonValue color} => + Car(make.to(), color: color.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension CarEJsonEncoderExtension on Car { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeCar(this); +} + +EJsonValue encodeTestRealmSets(TestRealmSets value) { + return { + 'key': value.key.toEJson(), + 'boolSet': value.boolSet.toEJson(), + 'intSet': value.intSet.toEJson(), + 'stringSet': value.stringSet.toEJson(), + 'doubleSet': value.doubleSet.toEJson(), + 'dateTimeSet': value.dateTimeSet.toEJson(), + 'objectIdSet': value.objectIdSet.toEJson(), + 'uuidSet': value.uuidSet.toEJson(), + 'mixedSet': value.mixedSet.toEJson(), + 'objectsSet': value.objectsSet.toEJson(), + 'binarySet': value.binarySet.toEJson(), + 'nullableBoolSet': value.nullableBoolSet.toEJson(), + 'nullableIntSet': value.nullableIntSet.toEJson(), + 'nullableStringSet': value.nullableStringSet.toEJson(), + 'nullableDoubleSet': value.nullableDoubleSet.toEJson(), + 'nullableDateTimeSet': value.nullableDateTimeSet.toEJson(), + 'nullableObjectIdSet': value.nullableObjectIdSet.toEJson(), + 'nullableUuidSet': value.nullableUuidSet.toEJson(), + 'nullableBinarySet': value.nullableBinarySet.toEJson() + }; +} + +TestRealmSets decodeTestRealmSets(EJsonValue ejson) { + return switch (ejson) { + { + 'key': EJsonValue key, + 'boolSet': EJsonValue boolSet, + 'intSet': EJsonValue intSet, + 'stringSet': EJsonValue stringSet, + 'doubleSet': EJsonValue doubleSet, + 'dateTimeSet': EJsonValue dateTimeSet, + 'objectIdSet': EJsonValue objectIdSet, + 'uuidSet': EJsonValue uuidSet, + 'mixedSet': EJsonValue mixedSet, + 'objectsSet': EJsonValue objectsSet, + 'binarySet': EJsonValue binarySet, + 'nullableBoolSet': EJsonValue nullableBoolSet, + 'nullableIntSet': EJsonValue nullableIntSet, + 'nullableStringSet': EJsonValue nullableStringSet, + 'nullableDoubleSet': EJsonValue nullableDoubleSet, + 'nullableDateTimeSet': EJsonValue nullableDateTimeSet, + 'nullableObjectIdSet': EJsonValue nullableObjectIdSet, + 'nullableUuidSet': EJsonValue nullableUuidSet, + 'nullableBinarySet': EJsonValue nullableBinarySet + } => + TestRealmSets(key.to(), + boolSet: boolSet.to>(), + intSet: intSet.to>(), + stringSet: stringSet.to>(), + doubleSet: doubleSet.to>(), + dateTimeSet: dateTimeSet.to>(), + objectIdSet: objectIdSet.to>(), + uuidSet: uuidSet.to>(), + mixedSet: mixedSet.to>(), + objectsSet: objectsSet.to>(), + binarySet: binarySet.to>(), + nullableBoolSet: nullableBoolSet.to>(), + nullableIntSet: nullableIntSet.to>(), + nullableStringSet: nullableStringSet.to>(), + nullableDoubleSet: nullableDoubleSet.to>(), + nullableDateTimeSet: nullableDateTimeSet.to>(), + nullableObjectIdSet: nullableObjectIdSet.to>(), + nullableUuidSet: nullableUuidSet.to>(), + nullableBinarySet: nullableBinarySet.to>()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension TestRealmSetsEJsonEncoderExtension on TestRealmSets { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeTestRealmSets(this); +} diff --git a/packages/realm_dart/test/realm_set_test.realm.dart b/packages/realm_dart/test/realm_set_test.realm.dart index ba17d309c..0b0c50f90 100644 --- a/packages/realm_dart/test/realm_set_test.realm.dart +++ b/packages/realm_dart/test/realm_set_test.realm.dart @@ -8,6 +8,7 @@ part of 'realm_set_test.dart'; // ignore_for_file: type=lint class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { + @ejson Car( String make, { String? color, @@ -48,6 +49,7 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { class TestRealmSets extends _TestRealmSets with RealmEntity, RealmObjectBase, RealmObject { + @ejson TestRealmSets( int key, { Set boolSet = const {}, diff --git a/packages/realm_dart/test/realm_test.dart b/packages/realm_dart/test/realm_test.dart index 136de401a..e460088ea 100644 --- a/packages/realm_dart/test/realm_test.dart +++ b/packages/realm_dart/test/realm_test.dart @@ -18,6 +18,8 @@ // ignore_for_file: unused_local_variable, avoid_relative_lib_imports +import 'package:ejson_annotation/ejson_annotation.dart'; + import 'dart:async'; import 'dart:convert'; import 'dart:io'; diff --git a/packages/realm_dart/test/realm_value_test.dart b/packages/realm_dart/test/realm_value_test.dart index c7a24f9e7..150c9c253 100644 --- a/packages/realm_dart/test/realm_value_test.dart +++ b/packages/realm_dart/test/realm_value_test.dart @@ -16,6 +16,11 @@ // //////////////////////////////////////////////////////////////////////////////// +import 'package:ejson_annotation/ejson_annotation.dart'; +import 'package:ejson/ejson.dart'; + +import 'dart:io'; + import 'dart:typed_data'; import 'package:test/test.dart' hide test, throws; @@ -24,6 +29,7 @@ import 'package:realm_dart/realm.dart'; import 'test.dart'; part 'realm_value_test.realm.dart'; +part 'realm_value_test.g.dart'; @RealmModel(ObjectType.embeddedObject) class _TuckedIn { diff --git a/packages/realm_dart/test/realm_value_test.g.dart b/packages/realm_dart/test/realm_value_test.g.dart new file mode 100644 index 000000000..86644891d --- /dev/null +++ b/packages/realm_dart/test/realm_value_test.g.dart @@ -0,0 +1,58 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'realm_value_test.dart'; + +// ************************************************************************** +// EJsonGenerator +// ************************************************************************** + +EJsonValue encodeTuckedIn(TuckedIn value) { + return {'x': value.x.toEJson()}; +} + +TuckedIn decodeTuckedIn(EJsonValue ejson) { + return switch (ejson) { + {'x': EJsonValue x} => TuckedIn(x: x.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension TuckedInEJsonEncoderExtension on TuckedIn { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeTuckedIn(this); +} + +EJsonValue encodeAnythingGoes(AnythingGoes value) { + return {'oneAny': value.oneAny.toEJson(), 'manyAny': value.manyAny.toEJson()}; +} + +AnythingGoes decodeAnythingGoes(EJsonValue ejson) { + return switch (ejson) { + {'oneAny': EJsonValue oneAny, 'manyAny': EJsonValue manyAny} => + AnythingGoes( + oneAny: oneAny.to(), + manyAny: manyAny.to>()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension AnythingGoesEJsonEncoderExtension on AnythingGoes { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeAnythingGoes(this); +} + +EJsonValue encodeStuff(Stuff value) { + return {'i': value.i.toEJson()}; +} + +Stuff decodeStuff(EJsonValue ejson) { + return switch (ejson) { + {'i': EJsonValue i} => Stuff(i: i.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension StuffEJsonEncoderExtension on Stuff { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeStuff(this); +} diff --git a/packages/realm_dart/test/realm_value_test.realm.dart b/packages/realm_dart/test/realm_value_test.realm.dart index 53c9c96de..070b011b6 100644 --- a/packages/realm_dart/test/realm_value_test.realm.dart +++ b/packages/realm_dart/test/realm_value_test.realm.dart @@ -11,6 +11,7 @@ class TuckedIn extends _TuckedIn with RealmEntity, RealmObjectBase, EmbeddedObject { static var _defaultsSet = false; + @ejson TuckedIn({ int x = 42, }) { @@ -48,6 +49,7 @@ class TuckedIn extends _TuckedIn class AnythingGoes extends _AnythingGoes with RealmEntity, RealmObjectBase, RealmObject { + @ejson AnythingGoes({ RealmValue oneAny = const RealmValue.nullValue(), Iterable manyAny = const [], @@ -121,6 +123,7 @@ class AnythingGoes extends _AnythingGoes class Stuff extends _Stuff with RealmEntity, RealmObjectBase, RealmObject { static var _defaultsSet = false; + @ejson Stuff({ int i = 42, }) { diff --git a/packages/realm_dart/test/test.dart b/packages/realm_dart/test/test.dart index 134ea76fe..35c7db0fb 100644 --- a/packages/realm_dart/test/test.dart +++ b/packages/realm_dart/test/test.dart @@ -16,6 +16,9 @@ // //////////////////////////////////////////////////////////////////////////////// +import 'package:ejson_annotation/ejson_annotation.dart'; +import 'package:ejson/ejson.dart'; + import 'dart:async'; import 'dart:collection'; import 'dart:ffi'; @@ -36,6 +39,7 @@ import 'baas_helper.dart'; export 'baas_helper.dart' show AppNames; part 'test.realm.dart'; +part 'test.g.dart'; @RealmModel() class _Car { diff --git a/packages/realm_dart/test/test.g.dart b/packages/realm_dart/test/test.g.dart new file mode 100644 index 000000000..a56dd7967 --- /dev/null +++ b/packages/realm_dart/test/test.g.dart @@ -0,0 +1,851 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'test.dart'; + +// ************************************************************************** +// EJsonGenerator +// ************************************************************************** + +EJsonValue encodeCar(Car value) { + return {'make': value.make.toEJson()}; +} + +Car decodeCar(EJsonValue ejson) { + return switch (ejson) { + {'make': EJsonValue make} => Car(make.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension CarEJsonEncoderExtension on Car { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeCar(this); +} + +EJsonValue encodePerson(Person value) { + return {'name': value.name.toEJson()}; +} + +Person decodePerson(EJsonValue ejson) { + return switch (ejson) { + {'name': EJsonValue name} => Person(name.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension PersonEJsonEncoderExtension on Person { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodePerson(this); +} + +EJsonValue encodeDog(Dog value) { + return { + 'name': value.name.toEJson(), + 'age': value.age.toEJson(), + 'owner': value.owner.toEJson() + }; +} + +Dog decodeDog(EJsonValue ejson) { + return switch (ejson) { + { + 'name': EJsonValue name, + 'age': EJsonValue age, + 'owner': EJsonValue owner + } => + Dog(name.to(), age: age.to(), owner: owner.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension DogEJsonEncoderExtension on Dog { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeDog(this); +} + +EJsonValue encodeTeam(Team value) { + return { + 'name': value.name.toEJson(), + 'players': value.players.toEJson(), + 'scores': value.scores.toEJson() + }; +} + +Team decodeTeam(EJsonValue ejson) { + return switch (ejson) { + { + 'name': EJsonValue name, + 'players': EJsonValue players, + 'scores': EJsonValue scores + } => + Team(name.to(), + players: players.to>(), + scores: scores.to>()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension TeamEJsonEncoderExtension on Team { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeTeam(this); +} + +EJsonValue encodeStudent(Student value) { + return { + 'number': value.number.toEJson(), + 'name': value.name.toEJson(), + 'yearOfBirth': value.yearOfBirth.toEJson(), + 'school': value.school.toEJson() + }; +} + +Student decodeStudent(EJsonValue ejson) { + return switch (ejson) { + { + 'number': EJsonValue number, + 'name': EJsonValue name, + 'yearOfBirth': EJsonValue yearOfBirth, + 'school': EJsonValue school + } => + Student(number.to(), + name: name.to(), + yearOfBirth: yearOfBirth.to(), + school: school.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension StudentEJsonEncoderExtension on Student { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeStudent(this); +} + +EJsonValue encodeSchool(School value) { + return { + 'name': value.name.toEJson(), + 'city': value.city.toEJson(), + 'branchOfSchool': value.branchOfSchool.toEJson(), + 'students': value.students.toEJson(), + 'branches': value.branches.toEJson() + }; +} + +School decodeSchool(EJsonValue ejson) { + return switch (ejson) { + { + 'name': EJsonValue name, + 'city': EJsonValue city, + 'branchOfSchool': EJsonValue branchOfSchool, + 'students': EJsonValue students, + 'branches': EJsonValue branches + } => + School(name.to(), + city: city.to(), + branchOfSchool: branchOfSchool.to(), + students: students.to>(), + branches: branches.to>()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension SchoolEJsonEncoderExtension on School { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeSchool(this); +} + +EJsonValue encodeRemappedClass(RemappedClass value) { + return { + 'remappedProperty': value.remappedProperty.toEJson(), + 'listProperty': value.listProperty.toEJson() + }; +} + +RemappedClass decodeRemappedClass(EJsonValue ejson) { + return switch (ejson) { + { + 'remappedProperty': EJsonValue remappedProperty, + 'listProperty': EJsonValue listProperty + } => + RemappedClass(remappedProperty.to(), + listProperty: listProperty.to>()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension RemappedClassEJsonEncoderExtension on RemappedClass { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeRemappedClass(this); +} + +EJsonValue encodeTask(Task value) { + return {'id': value.id.toEJson()}; +} + +Task decodeTask(EJsonValue ejson) { + return switch (ejson) { + {'id': EJsonValue id} => Task(id.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension TaskEJsonEncoderExtension on Task { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeTask(this); +} + +EJsonValue encodeProduct(Product value) { + return {'id': value.id.toEJson(), 'name': value.name.toEJson()}; +} + +Product decodeProduct(EJsonValue ejson) { + return switch (ejson) { + {'id': EJsonValue id, 'name': EJsonValue name} => + Product(id.to(), name.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension ProductEJsonEncoderExtension on Product { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeProduct(this); +} + +EJsonValue encodeSchedule(Schedule value) { + return {'id': value.id.toEJson(), 'tasks': value.tasks.toEJson()}; +} + +Schedule decodeSchedule(EJsonValue ejson) { + return switch (ejson) { + {'id': EJsonValue id, 'tasks': EJsonValue tasks} => + Schedule(id.to(), tasks: tasks.to>()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension ScheduleEJsonEncoderExtension on Schedule { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeSchedule(this); +} + +EJsonValue encodeFoo(Foo value) { + return { + 'requiredBinaryProp': value.requiredBinaryProp.toEJson(), + 'defaultValueBinaryProp': value.defaultValueBinaryProp.toEJson(), + 'nullableBinaryProp': value.nullableBinaryProp.toEJson() + }; +} + +Foo decodeFoo(EJsonValue ejson) { + return switch (ejson) { + { + 'requiredBinaryProp': EJsonValue requiredBinaryProp, + 'defaultValueBinaryProp': EJsonValue defaultValueBinaryProp, + 'nullableBinaryProp': EJsonValue nullableBinaryProp + } => + Foo(requiredBinaryProp.to(), + defaultValueBinaryProp: defaultValueBinaryProp.to(), + nullableBinaryProp: nullableBinaryProp.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension FooEJsonEncoderExtension on Foo { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeFoo(this); +} + +EJsonValue encodeAllTypes(AllTypes value) { + return { + 'stringProp': value.stringProp.toEJson(), + 'boolProp': value.boolProp.toEJson(), + 'dateProp': value.dateProp.toEJson(), + 'doubleProp': value.doubleProp.toEJson(), + 'objectIdProp': value.objectIdProp.toEJson(), + 'uuidProp': value.uuidProp.toEJson(), + 'intProp': value.intProp.toEJson(), + 'decimalProp': value.decimalProp.toEJson(), + 'binaryProp': value.binaryProp.toEJson(), + 'nullableStringProp': value.nullableStringProp.toEJson(), + 'nullableBoolProp': value.nullableBoolProp.toEJson(), + 'nullableDateProp': value.nullableDateProp.toEJson(), + 'nullableDoubleProp': value.nullableDoubleProp.toEJson(), + 'nullableObjectIdProp': value.nullableObjectIdProp.toEJson(), + 'nullableUuidProp': value.nullableUuidProp.toEJson(), + 'nullableIntProp': value.nullableIntProp.toEJson(), + 'nullableDecimalProp': value.nullableDecimalProp.toEJson(), + 'nullableBinaryProp': value.nullableBinaryProp.toEJson() + }; +} + +AllTypes decodeAllTypes(EJsonValue ejson) { + return switch (ejson) { + { + 'stringProp': EJsonValue stringProp, + 'boolProp': EJsonValue boolProp, + 'dateProp': EJsonValue dateProp, + 'doubleProp': EJsonValue doubleProp, + 'objectIdProp': EJsonValue objectIdProp, + 'uuidProp': EJsonValue uuidProp, + 'intProp': EJsonValue intProp, + 'decimalProp': EJsonValue decimalProp, + 'binaryProp': EJsonValue binaryProp, + 'nullableStringProp': EJsonValue nullableStringProp, + 'nullableBoolProp': EJsonValue nullableBoolProp, + 'nullableDateProp': EJsonValue nullableDateProp, + 'nullableDoubleProp': EJsonValue nullableDoubleProp, + 'nullableObjectIdProp': EJsonValue nullableObjectIdProp, + 'nullableUuidProp': EJsonValue nullableUuidProp, + 'nullableIntProp': EJsonValue nullableIntProp, + 'nullableDecimalProp': EJsonValue nullableDecimalProp, + 'nullableBinaryProp': EJsonValue nullableBinaryProp + } => + AllTypes( + stringProp.to(), + boolProp.to(), + dateProp.to(), + doubleProp.to(), + objectIdProp.to(), + uuidProp.to(), + intProp.to(), + decimalProp.to(), + binaryProp: binaryProp.to(), + nullableStringProp: nullableStringProp.to(), + nullableBoolProp: nullableBoolProp.to(), + nullableDateProp: nullableDateProp.to(), + nullableDoubleProp: nullableDoubleProp.to(), + nullableObjectIdProp: nullableObjectIdProp.to(), + nullableUuidProp: nullableUuidProp.to(), + nullableIntProp: nullableIntProp.to(), + nullableDecimalProp: nullableDecimalProp.to(), + nullableBinaryProp: nullableBinaryProp.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension AllTypesEJsonEncoderExtension on AllTypes { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeAllTypes(this); +} + +EJsonValue encodeLinksClass(LinksClass value) { + return { + 'id': value.id.toEJson(), + 'link': value.link.toEJson(), + 'list': value.list.toEJson() + }; +} + +LinksClass decodeLinksClass(EJsonValue ejson) { + return switch (ejson) { + {'id': EJsonValue id, 'link': EJsonValue link, 'list': EJsonValue list} => + LinksClass(id.to(), + link: link.to(), list: list.to>()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension LinksClassEJsonEncoderExtension on LinksClass { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeLinksClass(this); +} + +EJsonValue encodeAllCollections(AllCollections value) { + return { + 'strings': value.strings.toEJson(), + 'bools': value.bools.toEJson(), + 'dates': value.dates.toEJson(), + 'doubles': value.doubles.toEJson(), + 'objectIds': value.objectIds.toEJson(), + 'uuids': value.uuids.toEJson(), + 'ints': value.ints.toEJson(), + 'decimals': value.decimals.toEJson(), + 'nullableStrings': value.nullableStrings.toEJson(), + 'nullableBools': value.nullableBools.toEJson(), + 'nullableDates': value.nullableDates.toEJson(), + 'nullableDoubles': value.nullableDoubles.toEJson(), + 'nullableObjectIds': value.nullableObjectIds.toEJson(), + 'nullableUuids': value.nullableUuids.toEJson(), + 'nullableInts': value.nullableInts.toEJson(), + 'nullableDecimals': value.nullableDecimals.toEJson() + }; +} + +AllCollections decodeAllCollections(EJsonValue ejson) { + return switch (ejson) { + { + 'strings': EJsonValue strings, + 'bools': EJsonValue bools, + 'dates': EJsonValue dates, + 'doubles': EJsonValue doubles, + 'objectIds': EJsonValue objectIds, + 'uuids': EJsonValue uuids, + 'ints': EJsonValue ints, + 'decimals': EJsonValue decimals, + 'nullableStrings': EJsonValue nullableStrings, + 'nullableBools': EJsonValue nullableBools, + 'nullableDates': EJsonValue nullableDates, + 'nullableDoubles': EJsonValue nullableDoubles, + 'nullableObjectIds': EJsonValue nullableObjectIds, + 'nullableUuids': EJsonValue nullableUuids, + 'nullableInts': EJsonValue nullableInts, + 'nullableDecimals': EJsonValue nullableDecimals + } => + AllCollections( + strings: strings.to>(), + bools: bools.to>(), + dates: dates.to>(), + doubles: doubles.to>(), + objectIds: objectIds.to>(), + uuids: uuids.to>(), + ints: ints.to>(), + decimals: decimals.to>(), + nullableStrings: nullableStrings.to>(), + nullableBools: nullableBools.to>(), + nullableDates: nullableDates.to>(), + nullableDoubles: nullableDoubles.to>(), + nullableObjectIds: nullableObjectIds.to>(), + nullableUuids: nullableUuids.to>(), + nullableInts: nullableInts.to>(), + nullableDecimals: nullableDecimals.to>()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension AllCollectionsEJsonEncoderExtension on AllCollections { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeAllCollections(this); +} + +EJsonValue encodeNullableTypes(NullableTypes value) { + return { + 'id': value.id.toEJson(), + 'differentiator': value.differentiator.toEJson(), + 'stringProp': value.stringProp.toEJson(), + 'boolProp': value.boolProp.toEJson(), + 'dateProp': value.dateProp.toEJson(), + 'doubleProp': value.doubleProp.toEJson(), + 'objectIdProp': value.objectIdProp.toEJson(), + 'uuidProp': value.uuidProp.toEJson(), + 'intProp': value.intProp.toEJson(), + 'decimalProp': value.decimalProp.toEJson() + }; +} + +NullableTypes decodeNullableTypes(EJsonValue ejson) { + return switch (ejson) { + { + 'id': EJsonValue id, + 'differentiator': EJsonValue differentiator, + 'stringProp': EJsonValue stringProp, + 'boolProp': EJsonValue boolProp, + 'dateProp': EJsonValue dateProp, + 'doubleProp': EJsonValue doubleProp, + 'objectIdProp': EJsonValue objectIdProp, + 'uuidProp': EJsonValue uuidProp, + 'intProp': EJsonValue intProp, + 'decimalProp': EJsonValue decimalProp + } => + NullableTypes(id.to(), differentiator.to(), + stringProp: stringProp.to(), + boolProp: boolProp.to(), + dateProp: dateProp.to(), + doubleProp: doubleProp.to(), + objectIdProp: objectIdProp.to(), + uuidProp: uuidProp.to(), + intProp: intProp.to(), + decimalProp: decimalProp.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension NullableTypesEJsonEncoderExtension on NullableTypes { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeNullableTypes(this); +} + +EJsonValue encodeEvent(Event value) { + return { + 'id': value.id.toEJson(), + 'name': value.name.toEJson(), + 'isCompleted': value.isCompleted.toEJson(), + 'durationInMinutes': value.durationInMinutes.toEJson(), + 'assignedTo': value.assignedTo.toEJson() + }; +} + +Event decodeEvent(EJsonValue ejson) { + return switch (ejson) { + { + 'id': EJsonValue id, + 'name': EJsonValue name, + 'isCompleted': EJsonValue isCompleted, + 'durationInMinutes': EJsonValue durationInMinutes, + 'assignedTo': EJsonValue assignedTo + } => + Event(id.to(), + name: name.to(), + isCompleted: isCompleted.to(), + durationInMinutes: durationInMinutes.to(), + assignedTo: assignedTo.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension EventEJsonEncoderExtension on Event { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeEvent(this); +} + +EJsonValue encodeParty(Party value) { + return { + 'year': value.year.toEJson(), + 'host': value.host.toEJson(), + 'previous': value.previous.toEJson(), + 'guests': value.guests.toEJson() + }; +} + +Party decodeParty(EJsonValue ejson) { + return switch (ejson) { + { + 'year': EJsonValue year, + 'host': EJsonValue host, + 'previous': EJsonValue previous, + 'guests': EJsonValue guests + } => + Party(year.to(), + host: host.to(), + previous: previous.to(), + guests: guests.to>()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension PartyEJsonEncoderExtension on Party { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeParty(this); +} + +EJsonValue encodeFriend(Friend value) { + return { + 'name': value.name.toEJson(), + 'age': value.age.toEJson(), + 'bestFriend': value.bestFriend.toEJson(), + 'friends': value.friends.toEJson() + }; +} + +Friend decodeFriend(EJsonValue ejson) { + return switch (ejson) { + { + 'name': EJsonValue name, + 'age': EJsonValue age, + 'bestFriend': EJsonValue bestFriend, + 'friends': EJsonValue friends + } => + Friend(name.to(), + age: age.to(), + bestFriend: bestFriend.to(), + friends: friends.to>()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension FriendEJsonEncoderExtension on Friend { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeFriend(this); +} + +EJsonValue encodeWhen(When value) { + return { + 'dateTimeUtc': value.dateTimeUtc.toEJson(), + 'locationName': value.locationName.toEJson() + }; +} + +When decodeWhen(EJsonValue ejson) { + return switch (ejson) { + { + 'dateTimeUtc': EJsonValue dateTimeUtc, + 'locationName': EJsonValue locationName + } => + When(dateTimeUtc.to(), locationName.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension WhenEJsonEncoderExtension on When { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeWhen(this); +} + +EJsonValue encodePlayer(Player value) { + return { + 'name': value.name.toEJson(), + 'game': value.game.toEJson(), + 'scoresByRound': value.scoresByRound.toEJson() + }; +} + +Player decodePlayer(EJsonValue ejson) { + return switch (ejson) { + { + 'name': EJsonValue name, + 'game': EJsonValue game, + 'scoresByRound': EJsonValue scoresByRound + } => + Player(name.to(), + game: game.to(), + scoresByRound: scoresByRound.to>()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension PlayerEJsonEncoderExtension on Player { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodePlayer(this); +} + +EJsonValue encodeGame(Game value) { + return {'winnerByRound': value.winnerByRound.toEJson()}; +} + +Game decodeGame(EJsonValue ejson) { + return switch (ejson) { + {'winnerByRound': EJsonValue winnerByRound} => + Game(winnerByRound: winnerByRound.to>()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension GameEJsonEncoderExtension on Game { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeGame(this); +} + +EJsonValue encodeAllTypesEmbedded(AllTypesEmbedded value) { + return { + 'stringProp': value.stringProp.toEJson(), + 'boolProp': value.boolProp.toEJson(), + 'dateProp': value.dateProp.toEJson(), + 'doubleProp': value.doubleProp.toEJson(), + 'objectIdProp': value.objectIdProp.toEJson(), + 'uuidProp': value.uuidProp.toEJson(), + 'intProp': value.intProp.toEJson(), + 'decimalProp': value.decimalProp.toEJson(), + 'nullableStringProp': value.nullableStringProp.toEJson(), + 'nullableBoolProp': value.nullableBoolProp.toEJson(), + 'nullableDateProp': value.nullableDateProp.toEJson(), + 'nullableDoubleProp': value.nullableDoubleProp.toEJson(), + 'nullableObjectIdProp': value.nullableObjectIdProp.toEJson(), + 'nullableUuidProp': value.nullableUuidProp.toEJson(), + 'nullableIntProp': value.nullableIntProp.toEJson(), + 'nullableDecimalProp': value.nullableDecimalProp.toEJson(), + 'strings': value.strings.toEJson(), + 'bools': value.bools.toEJson(), + 'dates': value.dates.toEJson(), + 'doubles': value.doubles.toEJson(), + 'objectIds': value.objectIds.toEJson(), + 'uuids': value.uuids.toEJson(), + 'ints': value.ints.toEJson(), + 'decimals': value.decimals.toEJson() + }; +} + +AllTypesEmbedded decodeAllTypesEmbedded(EJsonValue ejson) { + return switch (ejson) { + { + 'stringProp': EJsonValue stringProp, + 'boolProp': EJsonValue boolProp, + 'dateProp': EJsonValue dateProp, + 'doubleProp': EJsonValue doubleProp, + 'objectIdProp': EJsonValue objectIdProp, + 'uuidProp': EJsonValue uuidProp, + 'intProp': EJsonValue intProp, + 'decimalProp': EJsonValue decimalProp, + 'nullableStringProp': EJsonValue nullableStringProp, + 'nullableBoolProp': EJsonValue nullableBoolProp, + 'nullableDateProp': EJsonValue nullableDateProp, + 'nullableDoubleProp': EJsonValue nullableDoubleProp, + 'nullableObjectIdProp': EJsonValue nullableObjectIdProp, + 'nullableUuidProp': EJsonValue nullableUuidProp, + 'nullableIntProp': EJsonValue nullableIntProp, + 'nullableDecimalProp': EJsonValue nullableDecimalProp, + 'strings': EJsonValue strings, + 'bools': EJsonValue bools, + 'dates': EJsonValue dates, + 'doubles': EJsonValue doubles, + 'objectIds': EJsonValue objectIds, + 'uuids': EJsonValue uuids, + 'ints': EJsonValue ints, + 'decimals': EJsonValue decimals + } => + AllTypesEmbedded( + stringProp.to(), + boolProp.to(), + dateProp.to(), + doubleProp.to(), + objectIdProp.to(), + uuidProp.to(), + intProp.to(), + decimalProp.to(), + nullableStringProp: nullableStringProp.to(), + nullableBoolProp: nullableBoolProp.to(), + nullableDateProp: nullableDateProp.to(), + nullableDoubleProp: nullableDoubleProp.to(), + nullableObjectIdProp: nullableObjectIdProp.to(), + nullableUuidProp: nullableUuidProp.to(), + nullableIntProp: nullableIntProp.to(), + nullableDecimalProp: nullableDecimalProp.to(), + strings: strings.to>(), + bools: bools.to>(), + dates: dates.to>(), + doubles: doubles.to>(), + objectIds: objectIds.to>(), + uuids: uuids.to>(), + ints: ints.to>(), + decimals: decimals.to>()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension AllTypesEmbeddedEJsonEncoderExtension on AllTypesEmbedded { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeAllTypesEmbedded(this); +} + +EJsonValue encodeObjectWithEmbedded(ObjectWithEmbedded value) { + return { + 'id': value.id.toEJson(), + 'differentiator': value.differentiator.toEJson(), + 'singleObject': value.singleObject.toEJson(), + 'recursiveObject': value.recursiveObject.toEJson(), + 'list': value.list.toEJson(), + 'recursiveList': value.recursiveList.toEJson() + }; +} + +ObjectWithEmbedded decodeObjectWithEmbedded(EJsonValue ejson) { + return switch (ejson) { + { + 'id': EJsonValue id, + 'differentiator': EJsonValue differentiator, + 'singleObject': EJsonValue singleObject, + 'recursiveObject': EJsonValue recursiveObject, + 'list': EJsonValue list, + 'recursiveList': EJsonValue recursiveList + } => + ObjectWithEmbedded(id.to(), + differentiator: differentiator.to(), + singleObject: singleObject.to(), + recursiveObject: recursiveObject.to(), + list: list.to>(), + recursiveList: recursiveList.to>()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension ObjectWithEmbeddedEJsonEncoderExtension on ObjectWithEmbedded { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeObjectWithEmbedded(this); +} + +EJsonValue encodeRecursiveEmbedded1(RecursiveEmbedded1 value) { + return { + 'value': value.value.toEJson(), + 'child': value.child.toEJson(), + 'realmObject': value.realmObject.toEJson(), + 'children': value.children.toEJson() + }; +} + +RecursiveEmbedded1 decodeRecursiveEmbedded1(EJsonValue ejson) { + return switch (ejson) { + { + 'value': EJsonValue value, + 'child': EJsonValue child, + 'realmObject': EJsonValue realmObject, + 'children': EJsonValue children + } => + RecursiveEmbedded1(value.to(), + child: child.to(), + realmObject: realmObject.to(), + children: children.to>()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension RecursiveEmbedded1EJsonEncoderExtension on RecursiveEmbedded1 { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeRecursiveEmbedded1(this); +} + +EJsonValue encodeRecursiveEmbedded2(RecursiveEmbedded2 value) { + return { + 'value': value.value.toEJson(), + 'child': value.child.toEJson(), + 'realmObject': value.realmObject.toEJson(), + 'children': value.children.toEJson() + }; +} + +RecursiveEmbedded2 decodeRecursiveEmbedded2(EJsonValue ejson) { + return switch (ejson) { + { + 'value': EJsonValue value, + 'child': EJsonValue child, + 'realmObject': EJsonValue realmObject, + 'children': EJsonValue children + } => + RecursiveEmbedded2(value.to(), + child: child.to(), + realmObject: realmObject.to(), + children: children.to>()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension RecursiveEmbedded2EJsonEncoderExtension on RecursiveEmbedded2 { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeRecursiveEmbedded2(this); +} + +EJsonValue encodeRecursiveEmbedded3(RecursiveEmbedded3 value) { + return {'value': value.value.toEJson()}; +} + +RecursiveEmbedded3 decodeRecursiveEmbedded3(EJsonValue ejson) { + return switch (ejson) { + {'value': EJsonValue value} => RecursiveEmbedded3(value.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension RecursiveEmbedded3EJsonEncoderExtension on RecursiveEmbedded3 { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeRecursiveEmbedded3(this); +} + +EJsonValue encodeObjectWithDecimal(ObjectWithDecimal value) { + return { + 'decimal': value.decimal.toEJson(), + 'nullableDecimal': value.nullableDecimal.toEJson() + }; +} + +ObjectWithDecimal decodeObjectWithDecimal(EJsonValue ejson) { + return switch (ejson) { + { + 'decimal': EJsonValue decimal, + 'nullableDecimal': EJsonValue nullableDecimal + } => + ObjectWithDecimal(decimal.to(), + nullableDecimal: nullableDecimal.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension ObjectWithDecimalEJsonEncoderExtension on ObjectWithDecimal { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeObjectWithDecimal(this); +} diff --git a/packages/realm_dart/test/test.realm.dart b/packages/realm_dart/test/test.realm.dart index cb62a1106..52f659000 100644 --- a/packages/realm_dart/test/test.realm.dart +++ b/packages/realm_dart/test/test.realm.dart @@ -8,6 +8,7 @@ part of 'test.dart'; // ignore_for_file: type=lint class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { + @ejson Car( String make, ) { @@ -39,6 +40,7 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { } class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { + @ejson Person( String name, ) { @@ -70,6 +72,7 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { } class Dog extends _Dog with RealmEntity, RealmObjectBase, RealmObject { + @ejson Dog( String name, { int? age, @@ -119,6 +122,7 @@ class Dog extends _Dog with RealmEntity, RealmObjectBase, RealmObject { } class Team extends _Team with RealmEntity, RealmObjectBase, RealmObject { + @ejson Team( String name, { Iterable players = const [], @@ -173,6 +177,7 @@ class Team extends _Team with RealmEntity, RealmObjectBase, RealmObject { } class Student extends _Student with RealmEntity, RealmObjectBase, RealmObject { + @ejson Student( int number, { String? name, @@ -231,6 +236,7 @@ class Student extends _Student with RealmEntity, RealmObjectBase, RealmObject { } class School extends _School with RealmEntity, RealmObjectBase, RealmObject { + @ejson School( String name, { String? city, @@ -306,6 +312,7 @@ class School extends _School with RealmEntity, RealmObjectBase, RealmObject { class RemappedClass extends $RemappedClass with RealmEntity, RealmObjectBase, RealmObject { + @ejson RemappedClass( String remappedProperty, { Iterable listProperty = const [], @@ -356,6 +363,7 @@ class RemappedClass extends $RemappedClass } class Task extends _Task with RealmEntity, RealmObjectBase, RealmObject { + @ejson Task( ObjectId id, ) { @@ -388,6 +396,7 @@ class Task extends _Task with RealmEntity, RealmObjectBase, RealmObject { } class Product extends _Product with RealmEntity, RealmObjectBase, RealmObject { + @ejson Product( ObjectId id, String name, @@ -432,6 +441,7 @@ class Product extends _Product with RealmEntity, RealmObjectBase, RealmObject { class Schedule extends _Schedule with RealmEntity, RealmObjectBase, RealmObject { + @ejson Schedule( ObjectId id, { Iterable tasks = const [], @@ -475,6 +485,7 @@ class Schedule extends _Schedule } class Foo extends _Foo with RealmEntity, RealmObjectBase, RealmObject { + @ejson Foo( Uint8List requiredBinaryProp, { Uint8List? defaultValueBinaryProp, @@ -532,6 +543,7 @@ class Foo extends _Foo with RealmEntity, RealmObjectBase, RealmObject { class AllTypes extends _AllTypes with RealmEntity, RealmObjectBase, RealmObject { + @ejson AllTypes( String stringProp, bool boolProp, @@ -738,6 +750,7 @@ class AllTypes extends _AllTypes class LinksClass extends _LinksClass with RealmEntity, RealmObjectBase, RealmObject { + @ejson LinksClass( Uuid id, { LinksClass? link, @@ -820,6 +833,7 @@ class LinksClass extends _LinksClass class AllCollections extends _AllCollections with RealmEntity, RealmObjectBase, RealmObject { + @ejson AllCollections({ Iterable stringList = const [], Iterable boolList = const [], @@ -1436,6 +1450,7 @@ class AllCollections extends _AllCollections class NullableTypes extends _NullableTypes with RealmEntity, RealmObjectBase, RealmObject { + @ejson NullableTypes( ObjectId id, ObjectId differentiator, { @@ -1554,6 +1569,7 @@ class NullableTypes extends _NullableTypes } class Event extends _Event with RealmEntity, RealmObjectBase, RealmObject { + @ejson Event( ObjectId id, { String? name, @@ -1629,6 +1645,7 @@ class Event extends _Event with RealmEntity, RealmObjectBase, RealmObject { } class Party extends _Party with RealmEntity, RealmObjectBase, RealmObject { + @ejson Party( int year, { Friend? host, @@ -1693,6 +1710,7 @@ class Party extends _Party with RealmEntity, RealmObjectBase, RealmObject { class Friend extends _Friend with RealmEntity, RealmObjectBase, RealmObject { static var _defaultsSet = false; + @ejson Friend( String name, { int age = 42, @@ -1760,6 +1778,7 @@ class Friend extends _Friend with RealmEntity, RealmObjectBase, RealmObject { } class When extends _When with RealmEntity, RealmObjectBase, RealmObject { + @ejson When( DateTime dateTimeUtc, String locationName, @@ -1803,6 +1822,7 @@ class When extends _When with RealmEntity, RealmObjectBase, RealmObject { } class Player extends _Player with RealmEntity, RealmObjectBase, RealmObject { + @ejson Player( String name, { Game? game, @@ -1855,6 +1875,7 @@ class Player extends _Player with RealmEntity, RealmObjectBase, RealmObject { } class Game extends _Game with RealmEntity, RealmObjectBase, RealmObject { + @ejson Game({ Iterable winnerByRound = const [], }) { @@ -1891,6 +1912,7 @@ class Game extends _Game with RealmEntity, RealmObjectBase, RealmObject { class AllTypesEmbedded extends _AllTypesEmbedded with RealmEntity, RealmObjectBase, EmbeddedObject { + @ejson AllTypesEmbedded( String stringProp, bool boolProp, @@ -2171,6 +2193,7 @@ class AllTypesEmbedded extends _AllTypesEmbedded class ObjectWithEmbedded extends _ObjectWithEmbedded with RealmEntity, RealmObjectBase, RealmObject { + @ejson ObjectWithEmbedded( String id, { Uuid? differentiator, @@ -2268,6 +2291,7 @@ class ObjectWithEmbedded extends _ObjectWithEmbedded class RecursiveEmbedded1 extends _RecursiveEmbedded1 with RealmEntity, RealmObjectBase, EmbeddedObject { + @ejson RecursiveEmbedded1( String value, { RecursiveEmbedded2? child, @@ -2340,6 +2364,7 @@ class RecursiveEmbedded1 extends _RecursiveEmbedded1 class RecursiveEmbedded2 extends _RecursiveEmbedded2 with RealmEntity, RealmObjectBase, EmbeddedObject { + @ejson RecursiveEmbedded2( String value, { RecursiveEmbedded3? child, @@ -2412,6 +2437,7 @@ class RecursiveEmbedded2 extends _RecursiveEmbedded2 class RecursiveEmbedded3 extends _RecursiveEmbedded3 with RealmEntity, RealmObjectBase, EmbeddedObject { + @ejson RecursiveEmbedded3( String value, ) { @@ -2446,6 +2472,7 @@ class RecursiveEmbedded3 extends _RecursiveEmbedded3 class ObjectWithDecimal extends _ObjectWithDecimal with RealmEntity, RealmObjectBase, RealmObject { + @ejson ObjectWithDecimal( Decimal128 decimal, { Decimal128? nullableDecimal, diff --git a/packages/realm_generator/lib/src/realm_model_info.dart b/packages/realm_generator/lib/src/realm_model_info.dart index 21f64e57f..b2d310204 100644 --- a/packages/realm_generator/lib/src/realm_model_info.dart +++ b/packages/realm_generator/lib/src/realm_model_info.dart @@ -44,6 +44,7 @@ class RealmModelInfo { } // Constructor + yield '@ejson'; yield '$name('; { final required = allSettable.where((f) => f.isRequired || f.isPrimaryKey); diff --git a/packages/realm_generator/test/good_test_data/all_types.expected b/packages/realm_generator/test/good_test_data/all_types.expected index 779210119..09c9ff624 100644 --- a/packages/realm_generator/test/good_test_data/all_types.expected +++ b/packages/realm_generator/test/good_test_data/all_types.expected @@ -10,6 +10,7 @@ part of 'all_types.dart'; class Foo extends _Foo with RealmEntity, RealmObjectBase, RealmObject { static var _defaultsSet = false; + @ejson Foo({ int x = 0, Bar? bar, @@ -57,6 +58,7 @@ class Foo extends _Foo with RealmEntity, RealmObjectBase, RealmObject { class Bar extends _Bar with RealmEntity, RealmObjectBase, RealmObject { static var _defaultsSet = false; + @ejson Bar( String name, bool aBool, @@ -254,6 +256,8 @@ class Bar extends _Bar with RealmEntity, RealmObjectBase, RealmObject { class PrimitiveTypes extends _PrimitiveTypes with RealmEntity, RealmObjectBase, RealmObject { + + @ejson PrimitiveTypes( String stringProp, bool boolProp, diff --git a/packages/realm_generator/test/good_test_data/another_mapto.expected_multi b/packages/realm_generator/test/good_test_data/another_mapto.expected_multi index e3ac37b43..81e40545d 100644 --- a/packages/realm_generator/test/good_test_data/another_mapto.expected_multi +++ b/packages/realm_generator/test/good_test_data/another_mapto.expected_multi @@ -9,6 +9,7 @@ part of 'another_mapto.dart'; // ignore_for_file: type=lint class MappedToo extends _MappedToo with RealmEntity, RealmObjectBase, RealmObject { + @ejson MappedToo({ Original? singleLink, Iterable listLink = const [], diff --git a/packages/realm_generator/test/good_test_data/binary_type.expected b/packages/realm_generator/test/good_test_data/binary_type.expected index 0595981ae..52114e386 100644 --- a/packages/realm_generator/test/good_test_data/binary_type.expected +++ b/packages/realm_generator/test/good_test_data/binary_type.expected @@ -8,6 +8,7 @@ part of 'binary_type.dart'; // ignore_for_file: type=lint class Foo extends _Foo with RealmEntity, RealmObjectBase, RealmObject { + @ejson Foo( Uint8List requiredBinaryProp, { Uint8List? defaultValueBinaryProp, diff --git a/packages/realm_generator/test/good_test_data/embedded_annotations.expected b/packages/realm_generator/test/good_test_data/embedded_annotations.expected index a50484e9c..7df0052dd 100644 --- a/packages/realm_generator/test/good_test_data/embedded_annotations.expected +++ b/packages/realm_generator/test/good_test_data/embedded_annotations.expected @@ -8,6 +8,7 @@ part of 'embedded_annotations.dart'; // ignore_for_file: type=lint class Parent extends _Parent with RealmEntity, RealmObjectBase, RealmObject { + @ejson Parent({ Child1? child, Iterable children = const [], @@ -56,6 +57,7 @@ class Parent extends _Parent with RealmEntity, RealmObjectBase, RealmObject { } class Child1 extends _Child1 with RealmEntity, RealmObjectBase, EmbeddedObject { + @ejson Child1( String value, String indexedString, { diff --git a/packages/realm_generator/test/good_test_data/embedded_objects.expected b/packages/realm_generator/test/good_test_data/embedded_objects.expected index 3d5376c48..db0f3d1f1 100644 --- a/packages/realm_generator/test/good_test_data/embedded_objects.expected +++ b/packages/realm_generator/test/good_test_data/embedded_objects.expected @@ -8,6 +8,7 @@ part of 'embedded_objects.dart'; // ignore_for_file: type=lint class Parent extends _Parent with RealmEntity, RealmObjectBase, RealmObject { + @ejson Parent({ Child1? child, Iterable children = const [], @@ -53,6 +54,7 @@ class Parent extends _Parent with RealmEntity, RealmObjectBase, RealmObject { } class Child1 extends _Child1 with RealmEntity, RealmObjectBase, EmbeddedObject { + @ejson Child1( String value, { Child2? child, @@ -117,6 +119,7 @@ class Child1 extends _Child1 with RealmEntity, RealmObjectBase, EmbeddedObject { } class Child2 extends _Child2 with RealmEntity, RealmObjectBase, EmbeddedObject { + @ejson Child2( bool boolProp, int intProp, diff --git a/packages/realm_generator/test/good_test_data/indexable_types.expected b/packages/realm_generator/test/good_test_data/indexable_types.expected index 32ad89839..834a6f27d 100644 --- a/packages/realm_generator/test/good_test_data/indexable_types.expected +++ b/packages/realm_generator/test/good_test_data/indexable_types.expected @@ -9,6 +9,7 @@ part of 'indexable_types.dart'; // ignore_for_file: type=lint class Indexable extends _Indexable with RealmEntity, RealmObjectBase, RealmObject { + @ejson Indexable( bool aBool, int anInt, diff --git a/packages/realm_generator/test/good_test_data/list_initialization.expected b/packages/realm_generator/test/good_test_data/list_initialization.expected index 622ff45c2..9b975ea95 100644 --- a/packages/realm_generator/test/good_test_data/list_initialization.expected +++ b/packages/realm_generator/test/good_test_data/list_initialization.expected @@ -8,6 +8,7 @@ part of 'list_initialization.dart'; // ignore_for_file: type=lint class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { + @ejson Person({ Iterable children = const [], Iterable initList = const [], diff --git a/packages/realm_generator/test/good_test_data/mapto.expected b/packages/realm_generator/test/good_test_data/mapto.expected index 649809162..8dbb26493 100644 --- a/packages/realm_generator/test/good_test_data/mapto.expected +++ b/packages/realm_generator/test/good_test_data/mapto.expected @@ -11,6 +11,7 @@ class Original extends $Original with RealmEntity, RealmObjectBase, RealmObject { static var _defaultsSet = false; + @ejson Original({ int primitiveProperty = 0, Original? objectProperty, diff --git a/packages/realm_generator/test/good_test_data/optional_argument.expected b/packages/realm_generator/test/good_test_data/optional_argument.expected index 53c28c92b..cd0eaf05a 100644 --- a/packages/realm_generator/test/good_test_data/optional_argument.expected +++ b/packages/realm_generator/test/good_test_data/optional_argument.expected @@ -8,6 +8,7 @@ part of 'optional_argument.dart'; // ignore_for_file: type=lint class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { + @ejson Person({ Person? spouse, }) { diff --git a/packages/realm_generator/test/good_test_data/pinhole.expected b/packages/realm_generator/test/good_test_data/pinhole.expected index a69faf50d..f6bf2d0f1 100644 --- a/packages/realm_generator/test/good_test_data/pinhole.expected +++ b/packages/realm_generator/test/good_test_data/pinhole.expected @@ -10,6 +10,7 @@ part of 'pinhole.dart'; class Foo extends _Foo with RealmEntity, RealmObjectBase, RealmObject { static var _defaultsSet = false; + @ejson Foo({ int x = 0, }) { diff --git a/packages/realm_generator/test/good_test_data/primary_key.expected b/packages/realm_generator/test/good_test_data/primary_key.expected index 607a97f41..1a1930753 100644 --- a/packages/realm_generator/test/good_test_data/primary_key.expected +++ b/packages/realm_generator/test/good_test_data/primary_key.expected @@ -8,6 +8,7 @@ part of 'primary_key.dart'; // ignore_for_file: type=lint class IntPK extends _IntPK with RealmEntity, RealmObjectBase, RealmObject { + @ejson IntPK( int id, ) { @@ -40,6 +41,7 @@ class IntPK extends _IntPK with RealmEntity, RealmObjectBase, RealmObject { class NullableIntPK extends _NullableIntPK with RealmEntity, RealmObjectBase, RealmObject { + @ejson NullableIntPK( int? id, ) { @@ -75,6 +77,7 @@ class NullableIntPK extends _NullableIntPK class StringPK extends _StringPK with RealmEntity, RealmObjectBase, RealmObject { + @ejson StringPK( String id, ) { @@ -107,6 +110,7 @@ class StringPK extends _StringPK class NullableStringPK extends _NullableStringPK with RealmEntity, RealmObjectBase, RealmObject { + @ejson NullableStringPK( String? id, ) { @@ -142,6 +146,7 @@ class NullableStringPK extends _NullableStringPK class ObjectIdPK extends _ObjectIdPK with RealmEntity, RealmObjectBase, RealmObject { + @ejson ObjectIdPK( ObjectId id, ) { @@ -174,6 +179,7 @@ class ObjectIdPK extends _ObjectIdPK class NullableObjectIdPK extends _NullableObjectIdPK with RealmEntity, RealmObjectBase, RealmObject { + @ejson NullableObjectIdPK( ObjectId? id, ) { @@ -208,6 +214,7 @@ class NullableObjectIdPK extends _NullableObjectIdPK } class UuidPK extends _UuidPK with RealmEntity, RealmObjectBase, RealmObject { + @ejson UuidPK( Uuid id, ) { @@ -240,6 +247,7 @@ class UuidPK extends _UuidPK with RealmEntity, RealmObjectBase, RealmObject { class NullableUuidPK extends _NullableUuidPK with RealmEntity, RealmObjectBase, RealmObject { + @ejson NullableUuidPK( Uuid? id, ) { diff --git a/packages/realm_generator/test/good_test_data/realm_set.expected b/packages/realm_generator/test/good_test_data/realm_set.expected index 5dcb6c94b..5fbdc5f80 100644 --- a/packages/realm_generator/test/good_test_data/realm_set.expected +++ b/packages/realm_generator/test/good_test_data/realm_set.expected @@ -8,6 +8,7 @@ part of 'realm_set.dart'; // ignore_for_file: type=lint class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { + @ejson Car( String make, ) { @@ -40,6 +41,7 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { class RealmSets extends _RealmSets with RealmEntity, RealmObjectBase, RealmObject { + @ejson RealmSets( int key, { Set boolSet = const {}, diff --git a/packages/realm_generator/test/good_test_data/required_argument.expected b/packages/realm_generator/test/good_test_data/required_argument.expected index d17468e22..942abb125 100644 --- a/packages/realm_generator/test/good_test_data/required_argument.expected +++ b/packages/realm_generator/test/good_test_data/required_argument.expected @@ -8,6 +8,7 @@ part of 'required_argument.dart'; // ignore_for_file: type=lint class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { + @ejson Person( String name, ) { diff --git a/packages/realm_generator/test/good_test_data/required_argument_with_default_value.expected b/packages/realm_generator/test/good_test_data/required_argument_with_default_value.expected index e1d4a5e25..c470373e9 100644 --- a/packages/realm_generator/test/good_test_data/required_argument_with_default_value.expected +++ b/packages/realm_generator/test/good_test_data/required_argument_with_default_value.expected @@ -10,6 +10,7 @@ part of 'required_argument_with_default_value.dart'; class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { static var _defaultsSet = false; + @ejson Person({ int age = 47, }) { diff --git a/packages/realm_generator/test/good_test_data/user_defined_getter.expected b/packages/realm_generator/test/good_test_data/user_defined_getter.expected index d29f0ae58..f68dcf984 100644 --- a/packages/realm_generator/test/good_test_data/user_defined_getter.expected +++ b/packages/realm_generator/test/good_test_data/user_defined_getter.expected @@ -8,6 +8,7 @@ part of 'user_defined_getter.dart'; // ignore_for_file: type=lint class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { + @ejson Person( String name, ) { diff --git a/pubspec_overrides.yaml b/pubspec_overrides.yaml new file mode 100644 index 000000000..3ed2e09ab --- /dev/null +++ b/pubspec_overrides.yaml @@ -0,0 +1,9 @@ +dependency_overrides: + ejson: + path: ./ejson/packages/ejson + ejson_annotation: + path: ./ejson/packages/ejson_annotation + ejson_generator: + path: ./ejson/packages/ejson_generator + ejson_analyzer: + path: ./ejson/packages/ejson_analyzer \ No newline at end of file diff --git a/test/backlinks_test.dart b/test/backlinks_test.dart new file mode 100644 index 000000000..ffbb048f2 --- /dev/null +++ b/test/backlinks_test.dart @@ -0,0 +1,175 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2022 Realm Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + +import 'package:ejson_annotation/ejson_annotation.dart'; +import 'package:ejson/ejson.dart'; + +import 'package:test/expect.dart'; + +import '../lib/realm.dart'; +import 'test.dart'; + +part 'backlinks_test.realm.dart'; +part 'backlinks_test.g.dart'; + +@RealmModel() +class _Source { + String name = 'source'; + @MapTo('et mål') // to throw a curve ball.. + _Target? oneTarget; + late List<_Target> manyTargets; +} + +@RealmModel() +class _Target { + @Backlink(#oneTarget) + late Iterable<_Source> oneToMany; + + String name = 'target'; + + @Backlink(#manyTargets) + late Iterable<_Source> manyToMany; +} + +Future main([List? args]) async { + await setupTests(args); + + test('Backlinks empty', () { + final config = Configuration.local([Target.schema, Source.schema]); + final realm = getRealm(config); + + final target = realm.write(() => realm.add(Target())); + + expect(target.oneToMany, isEmpty); + }); + + test('Backlink property getter throws for unmanaged objects', () { + final target = Target(); + expect(() => target.oneToMany, throws("Using backlinks is only possible for managed objects.")); + expect(() => target.manyToMany, throws("Using backlinks is only possible for managed objects.")); + }); + + test('Backlinks 1-1(ish)', () { + final config = Configuration.local([Target.schema, Source.schema]); + final realm = getRealm(config); + + final target = Target(); + final source = realm.write(() => realm.add(Source(oneTarget: target))); + + expect(source.oneTarget, target); + expect(target.oneToMany, [source]); + }); + + test('Backlinks 1-many', () { + final config = Configuration.local([Target.schema, Source.schema]); + final realm = getRealm(config); + + final target = Target(); + final sources = List.generate(100, (i) => Source(oneTarget: target, name: '$i')); + realm.write(() => realm.addAll(sources)); + + expect(target.oneToMany, sources); + }); + + test('Backlinks many-many', () { + final config = Configuration.local([Target.schema, Source.schema]); + final realm = getRealm(config); + + final targets = List.generate(100, (i) => Target(name: '$i')); + final sources = List.generate(100, (i) => Source(manyTargets: targets)); + + realm.write(() => realm.addAll(sources)); + + for (final t in targets) { + expect(t.manyToMany, sources); + } + + for (final s in sources) { + expect(s.manyTargets, targets); + } + }); + + test('Backlinks query', () { + final config = Configuration.local([Target.schema, Source.schema]); + final realm = getRealm(config); + + final target = Target(); + final sources = List.generate(100, (i) => Source(oneTarget: target, name: '$i')); + realm.write(() => realm.addAll(sources)); + + final fortyTwo = realm.query(r'name == $0', ['42']).single; + expect(target.oneToMany[42], fortyTwo); + expect(target.oneToMany.query(r'name = $0', ['42']), [fortyTwo]); + }); + + test('Backlinks notifications', () { + final config = Configuration.local([Target.schema, Source.schema]); + final realm = getRealm(config); + + final target = realm.write(() => realm.add(Target())); + + expectLater( + target.oneToMany.changes, + emitsInOrder([ + isA>().having((ch) => ch.inserted, 'inserted', []), + isA>().having((ch) => ch.inserted, 'inserted', [0]), + isA>().having((ch) => ch.inserted, 'inserted', [1]), + isA>() // + .having((ch) => ch.inserted, 'inserted', [0, 2]) // is this surprising? + .having((ch) => ch.deleted, 'deleted', [0]) // + .having((ch) => ch.modified, 'modified', [1]), + ])); + + final first = realm.write(() => realm.add(Source(oneTarget: target))); + + final second = realm.write(() => realm.add(Source(oneTarget: target))); + + realm.write(() { + realm.add(Source(oneTarget: target)); + realm.add(Source(oneTarget: target)); + second.name = "changed second"; + realm.delete(first); + }); + }); + + test('Backlinks read properties', () { + final config = Configuration.local([Target.schema, Source.schema]); + final realm = getRealm(config); + + final theOne = Target(name: 'the one'); + final targets = List.generate(100, (i) => Target(name: 'T$i')); + final sources = List.generate(100, (i) => Source(name: 'S$i', manyTargets: targets, oneTarget: theOne)); + + realm.write(() { + realm.addAll(sources); + realm.addAll(targets); + realm.add(theOne); + }); + + expect(theOne.oneToMany[0].name, 'S0'); + expect(theOne.oneToMany.map((s) => s.name), sources.map((s) => s.name)); + + for (final t in targets) { + expect(t.manyToMany.map((s) => s.name), sources.map((s) => s.name)); + } + + for (final s in sources) { + expect(s.manyTargets.map((t) => t.name), targets.map((t) => t.name)); + } + }); +} From eb8f49eb825c2a77a638c4acc5582ac519d60b0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Mon, 12 Jun 2023 20:52:42 +0200 Subject: [PATCH 030/153] Lint rules (WIP) --- ejson/.gitignore | 4 +- ejson/melos.yaml | 16 ++++++- .../lib/src/ejson_analyzer_base.dart | 12 ++--- ejson/packages/ejson_analyzer/pubspec.yaml | 5 ++- .../test/ejson_analyzer_test.dart | 8 +--- ejson/packages/ejson_annotation/pubspec.yaml | 1 - .../ejson_generator/lib/src/generator.dart | 13 ++---- ejson/packages/ejson_generator/pubspec.yaml | 7 +-- .../ejson_lint/dart_dependency_validator.yaml | 2 + ejson/packages/ejson_lint/example/.gitignore | 3 ++ .../packages/ejson_lint/example/CHANGELOG.md | 3 ++ ejson/packages/ejson_lint/example/README.md | 2 + .../ejson_lint/example/analysis_options.yaml | 5 +++ .../ejson_lint/example/bin/example.dart | 23 ++++++++++ .../example/dart_dependency_validator.yaml | 4 ++ .../example/ejson_lint_example.dart | 6 --- .../packages/ejson_lint/example/pubspec.yaml | 18 ++++++++ ejson/packages/ejson_lint/lib/ejson_lint.dart | 5 --- .../ejson_lint/lib/src/ejson_lint_base.dart | 18 ++++++-- .../lib/src/lints/mismatched_getter_type.dart | 38 ++++++++++++++++ .../lib/src/lints/missing_getter.dart | 33 ++++++++++++++ .../too_many_annotated_constructors.dart | 44 +++++++++++++++++++ ejson/packages/ejson_lint/pubspec.yaml | 2 + .../ejson_lint/test/ejson_lint_test.dart | 8 +--- 24 files changed, 228 insertions(+), 52 deletions(-) create mode 100644 ejson/packages/ejson_lint/dart_dependency_validator.yaml create mode 100644 ejson/packages/ejson_lint/example/.gitignore create mode 100644 ejson/packages/ejson_lint/example/CHANGELOG.md create mode 100644 ejson/packages/ejson_lint/example/README.md create mode 100644 ejson/packages/ejson_lint/example/analysis_options.yaml create mode 100644 ejson/packages/ejson_lint/example/bin/example.dart create mode 100644 ejson/packages/ejson_lint/example/dart_dependency_validator.yaml delete mode 100644 ejson/packages/ejson_lint/example/ejson_lint_example.dart create mode 100644 ejson/packages/ejson_lint/example/pubspec.yaml create mode 100644 ejson/packages/ejson_lint/lib/src/lints/mismatched_getter_type.dart create mode 100644 ejson/packages/ejson_lint/lib/src/lints/missing_getter.dart create mode 100644 ejson/packages/ejson_lint/lib/src/lints/too_many_annotated_constructors.dart diff --git a/ejson/.gitignore b/ejson/.gitignore index 738c59b2f..e33e893a5 100644 --- a/ejson/.gitignore +++ b/ejson/.gitignore @@ -1,2 +1,4 @@ +custom_lint.log +lcov.info pubspec_overrides.yaml -**/coverage/ \ No newline at end of file +**/coverage/ diff --git a/ejson/melos.yaml b/ejson/melos.yaml index 0a41700c7..c99c50c64 100644 --- a/ejson/melos.yaml +++ b/ejson/melos.yaml @@ -2,6 +2,8 @@ name: ejson packages: - packages/* + - packages/*/example + ide: intellij: false @@ -16,6 +18,7 @@ scripts: run: >- dart pub global activate coverage && dart pub global activate coverde && + dart pub global activate dependency_validator && dart pub global activate pana qa: @@ -29,6 +32,7 @@ scripts: description: Run all QA scripts run: >- melos run qa && + melos run test:lints && melos run pana && melos publish --dry-run @@ -43,6 +47,10 @@ scripts: analyze: description: Analyze Dart code. run: dart analyze . --fatal-infos + + analyze:deps: + description: Analyze dependencies. + exec: dart pub global run dependency_validator test: description: Run tests. @@ -53,6 +61,10 @@ scripts: dirExists: - test + test:lints: + description: Test that custom lints are working. + run: melos exec --depends-on=custom_lint -c1 -- dart run custom_lint + coverage: description: Generate, format, and check coverage. run: >- @@ -87,4 +99,6 @@ scripts: description: Run pana on all packages. run: dart pub global run pana --no-warning --exit-code-threshold 40 --source path . exec: - concurrency: 1 \ No newline at end of file + concurrency: 1 + packageFilters: + public: true \ No newline at end of file diff --git a/ejson/packages/ejson_analyzer/lib/src/ejson_analyzer_base.dart b/ejson/packages/ejson_analyzer/lib/src/ejson_analyzer_base.dart index e8a6f1590..6fd6f3788 100644 --- a/ejson/packages/ejson_analyzer/lib/src/ejson_analyzer_base.dart +++ b/ejson/packages/ejson_analyzer/lib/src/ejson_analyzer_base.dart @@ -1,6 +1,8 @@ -// TODO: Put public facing types in this file. +import 'package:analyzer/dart/element/element.dart'; +import 'package:ejson_annotation/ejson_annotation.dart'; +import 'package:source_gen/source_gen.dart'; -/// Checks if you are awesome. Spoiler: you are. -class Awesome { - bool get isAwesome => true; -} +TypeChecker get typeChecker => TypeChecker.fromRuntime(EJson); + +bool isEJsonAnnotated(Element element) => + typeChecker.hasAnnotationOfExact(element); diff --git a/ejson/packages/ejson_analyzer/pubspec.yaml b/ejson/packages/ejson_analyzer/pubspec.yaml index 2f203d0ea..a9c6985ad 100644 --- a/ejson/packages/ejson_analyzer/pubspec.yaml +++ b/ejson/packages/ejson_analyzer/pubspec.yaml @@ -7,9 +7,10 @@ repository: https://github.com/realm/realm-dart/ejson/packages/ejson_analyzer environment: sdk: ^3.0.2 -# Add regular dependencies here. dependencies: - # path: ^1.8.0 + analyzer: ^5.12.0 + ejson_annotation: ^0.1.0 + source_gen: ^1.3.2 dev_dependencies: lints: ^2.0.0 diff --git a/ejson/packages/ejson_analyzer/test/ejson_analyzer_test.dart b/ejson/packages/ejson_analyzer/test/ejson_analyzer_test.dart index 8701d345c..d2942e3a1 100644 --- a/ejson/packages/ejson_analyzer/test/ejson_analyzer_test.dart +++ b/ejson/packages/ejson_analyzer/test/ejson_analyzer_test.dart @@ -1,16 +1,12 @@ -import 'package:ejson_analyzer/ejson_analyzer.dart'; +// import 'package:ejson_analyzer/ejson_analyzer.dart'; import 'package:test/test.dart'; void main() { group('A group of tests', () { - final awesome = Awesome(); - setUp(() { // Additional setup goes here. }); - test('First Test', () { - expect(awesome.isAwesome, isTrue); - }); + test('First Test', () {}); }); } diff --git a/ejson/packages/ejson_annotation/pubspec.yaml b/ejson/packages/ejson_annotation/pubspec.yaml index f7507edee..148c79f9a 100644 --- a/ejson/packages/ejson_annotation/pubspec.yaml +++ b/ejson/packages/ejson_annotation/pubspec.yaml @@ -13,4 +13,3 @@ environment: dev_dependencies: lints: ^2.0.0 - test: ^1.21.0 diff --git a/ejson/packages/ejson_generator/lib/src/generator.dart b/ejson/packages/ejson_generator/lib/src/generator.dart index 7fdb6ed07..41cd848f7 100644 --- a/ejson/packages/ejson_generator/lib/src/generator.dart +++ b/ejson/packages/ejson_generator/lib/src/generator.dart @@ -20,7 +20,7 @@ import 'dart:async'; import 'package:analyzer/dart/element/element.dart'; import 'package:build/build.dart'; -import 'package:ejson_annotation/ejson_annotation.dart'; +import 'package:ejson_analyzer/ejson_analyzer.dart'; import 'package:ejson_generator/ejson_generator.dart'; import 'package:source_gen/source_gen.dart'; @@ -46,24 +46,17 @@ class EJsonSourceError extends InvalidGenerationSourceError { class EJsonGenerator extends Generator { const EJsonGenerator(); - TypeChecker get typeChecker => TypeChecker.fromRuntime(EJson); - - bool _isAnnotated(Element element) => - typeChecker.hasAnnotationOfExact(element); - @override FutureOr generate(LibraryReader library, BuildStep buildStep) async { // find all classes with annotated constructors or classes directly annotated final annotated = library.classes .map((cls) => - (cls, cls.constructors.where((ctor) => _isAnnotated(ctor)))) + (cls, cls.constructors.where((ctor) => isEJsonAnnotated(ctor)))) .where((element) { final (cls, ctors) = element; - return ctors.isNotEmpty || _isAnnotated(cls); + return ctors.isNotEmpty || isEJsonAnnotated(cls); }); - //buildStep. - return annotated.map((x) { final (cls, ctors) = x; final className = cls.name; diff --git a/ejson/packages/ejson_generator/pubspec.yaml b/ejson/packages/ejson_generator/pubspec.yaml index 6c35294a7..c3aec782e 100644 --- a/ejson/packages/ejson_generator/pubspec.yaml +++ b/ejson/packages/ejson_generator/pubspec.yaml @@ -19,20 +19,17 @@ environment: sdk: ^3.0.1 dependencies: - analyzer: ^5.13.0 + analyzer: ^5.12.0 build: ^2.4.0 - collection: ^1.17.0 - ejson_annotation: ^0.1.0 ejson_analyzer: ^0.1.0 source_gen: ^1.3.2 - source_span: ^1.9.0 dev_dependencies: build_runner: ^2.4.4 build_test: ^2.1.7 dart_style: ^2.3.1 ejson: ^0.1.0 + ejson_annotation: ^0.1.0 lints: ^2.0.0 meta: ^1.9.1 test: ^1.21.0 - type_plus: ^2.0.0 diff --git a/ejson/packages/ejson_lint/dart_dependency_validator.yaml b/ejson/packages/ejson_lint/dart_dependency_validator.yaml new file mode 100644 index 000000000..84e889b1c --- /dev/null +++ b/ejson/packages/ejson_lint/dart_dependency_validator.yaml @@ -0,0 +1,2 @@ +exclude: + - "example/**" # example is its own project \ No newline at end of file diff --git a/ejson/packages/ejson_lint/example/.gitignore b/ejson/packages/ejson_lint/example/.gitignore new file mode 100644 index 000000000..3a8579040 --- /dev/null +++ b/ejson/packages/ejson_lint/example/.gitignore @@ -0,0 +1,3 @@ +# https://dart.dev/guides/libraries/private-files +# Created by `dart pub` +.dart_tool/ diff --git a/ejson/packages/ejson_lint/example/CHANGELOG.md b/ejson/packages/ejson_lint/example/CHANGELOG.md new file mode 100644 index 000000000..effe43c82 --- /dev/null +++ b/ejson/packages/ejson_lint/example/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0 + +- Initial version. diff --git a/ejson/packages/ejson_lint/example/README.md b/ejson/packages/ejson_lint/example/README.md new file mode 100644 index 000000000..3816eca3a --- /dev/null +++ b/ejson/packages/ejson_lint/example/README.md @@ -0,0 +1,2 @@ +A sample command-line application with an entrypoint in `bin/`, library code +in `lib/`, and example unit test in `test/`. diff --git a/ejson/packages/ejson_lint/example/analysis_options.yaml b/ejson/packages/ejson_lint/example/analysis_options.yaml new file mode 100644 index 000000000..530482459 --- /dev/null +++ b/ejson/packages/ejson_lint/example/analysis_options.yaml @@ -0,0 +1,5 @@ +include: package:lints/recommended.yaml + +analyzer: + plugins: + - custom_lint \ No newline at end of file diff --git a/ejson/packages/ejson_lint/example/bin/example.dart b/ejson/packages/ejson_lint/example/bin/example.dart new file mode 100644 index 000000000..2032104d7 --- /dev/null +++ b/ejson/packages/ejson_lint/example/bin/example.dart @@ -0,0 +1,23 @@ +import 'package:ejson_annotation/ejson_annotation.dart'; + +// This file is used to test lint rules using +// dart run custom_lint +// or +// melos test:lint +class Person { + final String name; + // expect_lint: mismatched_getter_type + final int age; + + @ejson + // expect_lint: too_many_annotated_constructors + Person(this.name, {required this.age}); + + @ejson + // expect_lint: too_many_annotated_constructors, mismatched_getter_type + Person.second(this.name, double age) : age = age.toInt(); + + @ejson + // expect_lint: too_many_annotated_constructors, missing_getter + Person.third(String navn, int alder) : this(navn, age: alder); +} diff --git a/ejson/packages/ejson_lint/example/dart_dependency_validator.yaml b/ejson/packages/ejson_lint/example/dart_dependency_validator.yaml new file mode 100644 index 000000000..55bdce175 --- /dev/null +++ b/ejson/packages/ejson_lint/example/dart_dependency_validator.yaml @@ -0,0 +1,4 @@ + +ignore: + # validator mistakenly flags this + - ejson_lint diff --git a/ejson/packages/ejson_lint/example/ejson_lint_example.dart b/ejson/packages/ejson_lint/example/ejson_lint_example.dart deleted file mode 100644 index eef7252f0..000000000 --- a/ejson/packages/ejson_lint/example/ejson_lint_example.dart +++ /dev/null @@ -1,6 +0,0 @@ -import 'package:ejson_lint/ejson_lint.dart'; - -void main() { - var awesome = Awesome(); - print('awesome: ${awesome.isAwesome}'); -} diff --git a/ejson/packages/ejson_lint/example/pubspec.yaml b/ejson/packages/ejson_lint/example/pubspec.yaml new file mode 100644 index 000000000..4c3be7e7c --- /dev/null +++ b/ejson/packages/ejson_lint/example/pubspec.yaml @@ -0,0 +1,18 @@ +name: example +description: A sample command-line application. +version: 1.0.0 + +publish_to: none + +environment: + sdk: ^3.0.3 + +dependencies: + ejson_annotation: ^0.1.0 + +dev_dependencies: + custom_lint: ^0.4.0 + ejson_lint: ^0.1.0 + lints: ^2.0.0 + + diff --git a/ejson/packages/ejson_lint/lib/ejson_lint.dart b/ejson/packages/ejson_lint/lib/ejson_lint.dart index 6b9894cf3..b6a4c23a2 100644 --- a/ejson/packages/ejson_lint/lib/ejson_lint.dart +++ b/ejson/packages/ejson_lint/lib/ejson_lint.dart @@ -1,8 +1,3 @@ -/// Support for doing something awesome. -/// -/// More dartdocs go here. library; export 'src/ejson_lint_base.dart'; - -// TODO: Export any libraries intended for clients of this package. diff --git a/ejson/packages/ejson_lint/lib/src/ejson_lint_base.dart b/ejson/packages/ejson_lint/lib/src/ejson_lint_base.dart index e8a6f1590..c382ac2ee 100644 --- a/ejson/packages/ejson_lint/lib/src/ejson_lint_base.dart +++ b/ejson/packages/ejson_lint/lib/src/ejson_lint_base.dart @@ -1,6 +1,16 @@ -// TODO: Put public facing types in this file. +import 'package:custom_lint_builder/custom_lint_builder.dart'; -/// Checks if you are awesome. Spoiler: you are. -class Awesome { - bool get isAwesome => true; +import 'lints/mismatched_getter_type.dart'; +import 'lints/missing_getter.dart'; +import 'lints/too_many_annotated_constructors.dart'; + +PluginBase createPlugin() => _EJsonLinter(); + +class _EJsonLinter extends PluginBase { + @override + List getLintRules(CustomLintConfigs configs) => [ + TooManyAnnotatedConstructors(), + MissingGetter(), + MismatchedGetterType(), + ]; } diff --git a/ejson/packages/ejson_lint/lib/src/lints/mismatched_getter_type.dart b/ejson/packages/ejson_lint/lib/src/lints/mismatched_getter_type.dart new file mode 100644 index 000000000..8500e4d5f --- /dev/null +++ b/ejson/packages/ejson_lint/lib/src/lints/mismatched_getter_type.dart @@ -0,0 +1,38 @@ +import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/error/listener.dart'; +import 'package:custom_lint_builder/custom_lint_builder.dart'; +import 'package:ejson_analyzer/ejson_analyzer.dart'; + +class MismatchedGetterType extends DartLintRule { + MismatchedGetterType() + : super( + code: const LintCode( + name: 'mismatched_getter_type', + problemMessage: + 'Type of getter does not match type of constructor parameter', + ), + ); + + @override + void run( + CustomLintResolver resolver, + ErrorReporter reporter, + CustomLintContext context, + ) { + context.registry.addConstructorDeclaration((node) { + final ctor = node.declaredElement; + if (ctor == null) return; // not resolved; + if (isEJsonAnnotated(ctor)) { + final cls = ctor.enclosingElement as ClassElement; + for (final param in ctor.parameters) { + final getter = cls.getGetter(param.name); + if (getter == null) continue; + if (getter.returnType != param.type) { + reporter.reportErrorForElement(code, getter); + reporter.reportErrorForElement(code, param); + } + } + } + }); + } +} diff --git a/ejson/packages/ejson_lint/lib/src/lints/missing_getter.dart b/ejson/packages/ejson_lint/lib/src/lints/missing_getter.dart new file mode 100644 index 000000000..01e5a4542 --- /dev/null +++ b/ejson/packages/ejson_lint/lib/src/lints/missing_getter.dart @@ -0,0 +1,33 @@ +import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/error/listener.dart'; +import 'package:custom_lint_builder/custom_lint_builder.dart'; +import 'package:ejson_analyzer/ejson_analyzer.dart'; + +class MissingGetter extends DartLintRule { + MissingGetter() + : super( + code: const LintCode( + name: 'missing_getter', + problemMessage: 'Missing getter for constructor parameter', + ), + ); + + @override + void run( + CustomLintResolver resolver, + ErrorReporter reporter, + CustomLintContext context, + ) { + context.registry.addConstructorDeclaration((node) { + final ctor = node.declaredElement; + if (ctor == null) return; // not resolved; + if (isEJsonAnnotated(ctor)) { + final cls = ctor.enclosingElement as ClassElement; + for (final param in ctor.parameters) { + final getter = cls.getGetter(param.name); + if (getter == null) reporter.reportErrorForElement(code, param); + } + } + }); + } +} diff --git a/ejson/packages/ejson_lint/lib/src/lints/too_many_annotated_constructors.dart b/ejson/packages/ejson_lint/lib/src/lints/too_many_annotated_constructors.dart new file mode 100644 index 000000000..e2b492af1 --- /dev/null +++ b/ejson/packages/ejson_lint/lib/src/lints/too_many_annotated_constructors.dart @@ -0,0 +1,44 @@ +import 'package:analyzer/error/listener.dart'; +import 'package:custom_lint_builder/custom_lint_builder.dart'; +import 'package:ejson_analyzer/ejson_analyzer.dart'; + +abstract class EJsonLintRule extends DartLintRule { + EJsonLintRule({required super.code}); + + @override + Future startUp( + CustomLintResolver resolver, CustomLintContext context) async { + return await super.startUp(resolver, context); + } +} + +class TooManyAnnotatedConstructors extends DartLintRule { + TooManyAnnotatedConstructors() + : super( + code: const LintCode( + name: 'too_many_annotated_constructors', + problemMessage: + 'Only one constructor can be annotated with @EJson()', + ), + ); + + @override + void run( + CustomLintResolver resolver, + ErrorReporter reporter, + CustomLintContext context, + ) { + context.registry.addClassDeclaration((node) { + final cls = node.declaredElement; + if (cls == null) return; // not resolved; + + final annotatedConstructors = + cls.constructors.where((ctor) => isEJsonAnnotated(ctor)); + if (annotatedConstructors.length > 1) { + for (final ctor in annotatedConstructors) { + reporter.reportErrorForElement(code, ctor); + } + } + }); + } +} diff --git a/ejson/packages/ejson_lint/pubspec.yaml b/ejson/packages/ejson_lint/pubspec.yaml index dade202b5..6b3f098ff 100644 --- a/ejson/packages/ejson_lint/pubspec.yaml +++ b/ejson/packages/ejson_lint/pubspec.yaml @@ -8,6 +8,8 @@ environment: sdk: ^3.0.2 dependencies: + analyzer: ^5.12.0 + custom_lint_builder: ^0.4.0 ejson_analyzer: ^0.1.0 dev_dependencies: diff --git a/ejson/packages/ejson_lint/test/ejson_lint_test.dart b/ejson/packages/ejson_lint/test/ejson_lint_test.dart index 0993bd74a..c51c6a3f8 100644 --- a/ejson/packages/ejson_lint/test/ejson_lint_test.dart +++ b/ejson/packages/ejson_lint/test/ejson_lint_test.dart @@ -1,16 +1,12 @@ -import 'package:ejson_lint/ejson_lint.dart'; +//import 'package:ejson_lint/ejson_lint.dart'; import 'package:test/test.dart'; void main() { group('A group of tests', () { - final awesome = Awesome(); - setUp(() { // Additional setup goes here. }); - test('First Test', () { - expect(awesome.isAwesome, isTrue); - }); + test('First Test', () {}); }); } From 32e506845ab55e6d7bdf8a848bffd058e64be235 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 14 Jun 2023 11:31:46 +0200 Subject: [PATCH 031/153] Report lints as errors instead of infos --- ejson/melos.yaml | 1 + .../ejson_lint/lib/src/lints/mismatched_getter_type.dart | 2 ++ ejson/packages/ejson_lint/lib/src/lints/missing_getter.dart | 2 ++ .../lib/src/lints/too_many_annotated_constructors.dart | 2 ++ 4 files changed, 7 insertions(+) diff --git a/ejson/melos.yaml b/ejson/melos.yaml index c99c50c64..144122c22 100644 --- a/ejson/melos.yaml +++ b/ejson/melos.yaml @@ -33,6 +33,7 @@ scripts: run: >- melos run qa && melos run test:lints && + melos run analyze:deps && melos run pana && melos publish --dry-run diff --git a/ejson/packages/ejson_lint/lib/src/lints/mismatched_getter_type.dart b/ejson/packages/ejson_lint/lib/src/lints/mismatched_getter_type.dart index 8500e4d5f..d7c9ce416 100644 --- a/ejson/packages/ejson_lint/lib/src/lints/mismatched_getter_type.dart +++ b/ejson/packages/ejson_lint/lib/src/lints/mismatched_getter_type.dart @@ -1,4 +1,5 @@ import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/error/error.dart'; import 'package:analyzer/error/listener.dart'; import 'package:custom_lint_builder/custom_lint_builder.dart'; import 'package:ejson_analyzer/ejson_analyzer.dart'; @@ -10,6 +11,7 @@ class MismatchedGetterType extends DartLintRule { name: 'mismatched_getter_type', problemMessage: 'Type of getter does not match type of constructor parameter', + errorSeverity: ErrorSeverity.ERROR, ), ); diff --git a/ejson/packages/ejson_lint/lib/src/lints/missing_getter.dart b/ejson/packages/ejson_lint/lib/src/lints/missing_getter.dart index 01e5a4542..724aba157 100644 --- a/ejson/packages/ejson_lint/lib/src/lints/missing_getter.dart +++ b/ejson/packages/ejson_lint/lib/src/lints/missing_getter.dart @@ -1,4 +1,5 @@ import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/error/error.dart'; import 'package:analyzer/error/listener.dart'; import 'package:custom_lint_builder/custom_lint_builder.dart'; import 'package:ejson_analyzer/ejson_analyzer.dart'; @@ -9,6 +10,7 @@ class MissingGetter extends DartLintRule { code: const LintCode( name: 'missing_getter', problemMessage: 'Missing getter for constructor parameter', + errorSeverity: ErrorSeverity.ERROR, ), ); diff --git a/ejson/packages/ejson_lint/lib/src/lints/too_many_annotated_constructors.dart b/ejson/packages/ejson_lint/lib/src/lints/too_many_annotated_constructors.dart index e2b492af1..998e2be52 100644 --- a/ejson/packages/ejson_lint/lib/src/lints/too_many_annotated_constructors.dart +++ b/ejson/packages/ejson_lint/lib/src/lints/too_many_annotated_constructors.dart @@ -1,3 +1,4 @@ +import 'package:analyzer/error/error.dart'; import 'package:analyzer/error/listener.dart'; import 'package:custom_lint_builder/custom_lint_builder.dart'; import 'package:ejson_analyzer/ejson_analyzer.dart'; @@ -19,6 +20,7 @@ class TooManyAnnotatedConstructors extends DartLintRule { name: 'too_many_annotated_constructors', problemMessage: 'Only one constructor can be annotated with @EJson()', + errorSeverity: ErrorSeverity.ERROR, ), ); From f27e3650a315c8030e65548b39015e6037a71893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 14 Jun 2023 11:53:39 +0200 Subject: [PATCH 032/153] Use links for LICENSE file --- ejson/LICENSE | 177 +++++++++++++++++++++++ ejson/packages/ejson/LICENSE | 178 +----------------------- ejson/packages/ejson_analyzer/LICENSE | 178 +----------------------- ejson/packages/ejson_annotation/LICENSE | 178 +----------------------- ejson/packages/ejson_generator/LICENSE | 1 + ejson/packages/ejson_lint/LICENSE | 178 +----------------------- 6 files changed, 182 insertions(+), 708 deletions(-) create mode 100644 ejson/LICENSE mode change 100644 => 120000 ejson/packages/ejson/LICENSE mode change 100644 => 120000 ejson/packages/ejson_analyzer/LICENSE mode change 100644 => 120000 ejson/packages/ejson_annotation/LICENSE create mode 120000 ejson/packages/ejson_generator/LICENSE mode change 100644 => 120000 ejson/packages/ejson_lint/LICENSE diff --git a/ejson/LICENSE b/ejson/LICENSE new file mode 100644 index 000000000..66a27ec5f --- /dev/null +++ b/ejson/LICENSE @@ -0,0 +1,177 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + diff --git a/ejson/packages/ejson/LICENSE b/ejson/packages/ejson/LICENSE deleted file mode 100644 index 66a27ec5f..000000000 --- a/ejson/packages/ejson/LICENSE +++ /dev/null @@ -1,177 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - diff --git a/ejson/packages/ejson/LICENSE b/ejson/packages/ejson/LICENSE new file mode 120000 index 000000000..30cff7403 --- /dev/null +++ b/ejson/packages/ejson/LICENSE @@ -0,0 +1 @@ +../../LICENSE \ No newline at end of file diff --git a/ejson/packages/ejson_analyzer/LICENSE b/ejson/packages/ejson_analyzer/LICENSE deleted file mode 100644 index 66a27ec5f..000000000 --- a/ejson/packages/ejson_analyzer/LICENSE +++ /dev/null @@ -1,177 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - diff --git a/ejson/packages/ejson_analyzer/LICENSE b/ejson/packages/ejson_analyzer/LICENSE new file mode 120000 index 000000000..30cff7403 --- /dev/null +++ b/ejson/packages/ejson_analyzer/LICENSE @@ -0,0 +1 @@ +../../LICENSE \ No newline at end of file diff --git a/ejson/packages/ejson_annotation/LICENSE b/ejson/packages/ejson_annotation/LICENSE deleted file mode 100644 index 66a27ec5f..000000000 --- a/ejson/packages/ejson_annotation/LICENSE +++ /dev/null @@ -1,177 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - diff --git a/ejson/packages/ejson_annotation/LICENSE b/ejson/packages/ejson_annotation/LICENSE new file mode 120000 index 000000000..30cff7403 --- /dev/null +++ b/ejson/packages/ejson_annotation/LICENSE @@ -0,0 +1 @@ +../../LICENSE \ No newline at end of file diff --git a/ejson/packages/ejson_generator/LICENSE b/ejson/packages/ejson_generator/LICENSE new file mode 120000 index 000000000..30cff7403 --- /dev/null +++ b/ejson/packages/ejson_generator/LICENSE @@ -0,0 +1 @@ +../../LICENSE \ No newline at end of file diff --git a/ejson/packages/ejson_lint/LICENSE b/ejson/packages/ejson_lint/LICENSE deleted file mode 100644 index 66a27ec5f..000000000 --- a/ejson/packages/ejson_lint/LICENSE +++ /dev/null @@ -1,177 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - diff --git a/ejson/packages/ejson_lint/LICENSE b/ejson/packages/ejson_lint/LICENSE new file mode 120000 index 000000000..30cff7403 --- /dev/null +++ b/ejson/packages/ejson_lint/LICENSE @@ -0,0 +1 @@ +../../LICENSE \ No newline at end of file From 287afb8a04f525b893fe6e5cd2e3c6f180eec498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 14 Jun 2023 12:13:33 +0200 Subject: [PATCH 033/153] Link READMEs --- ejson/README.md | 38 +++++++++++++++++++++ ejson/packages/ejson/README.md | 3 +- ejson/packages/ejson_analyzer/README.md | 40 +---------------------- ejson/packages/ejson_annotation/README.md | 40 +---------------------- ejson/packages/ejson_generator/README.md | 40 +---------------------- ejson/packages/ejson_lint/README.md | 40 +---------------------- 6 files changed, 43 insertions(+), 158 deletions(-) create mode 100644 ejson/README.md mode change 100644 => 120000 ejson/packages/ejson/README.md mode change 100644 => 120000 ejson/packages/ejson_analyzer/README.md mode change 100644 => 120000 ejson/packages/ejson_annotation/README.md mode change 100644 => 120000 ejson/packages/ejson_generator/README.md mode change 100644 => 120000 ejson/packages/ejson_lint/README.md diff --git a/ejson/README.md b/ejson/README.md new file mode 100644 index 000000000..2366c6c86 --- /dev/null +++ b/ejson/README.md @@ -0,0 +1,38 @@ + + +Support for serializing and deserializing Extended JSON ([EJson](https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/)) + +## Features + + + +## Getting started + +TODO: List prerequisites and provide or point to information on how to +start using the package. + +## Usage + +TODO: Include short and useful examples for package users. Add longer examples +to `/example` folder. + +```dart +const like = 'sample'; +``` + +## Additional information + +TODO: Tell users more about the package: where to find more information, how to +contribute to the package, how to file issues, what response they can expect +from the package authors, and more. diff --git a/ejson/packages/ejson/README.md b/ejson/packages/ejson/README.md deleted file mode 100644 index 3816eca3a..000000000 --- a/ejson/packages/ejson/README.md +++ /dev/null @@ -1,2 +0,0 @@ -A sample command-line application with an entrypoint in `bin/`, library code -in `lib/`, and example unit test in `test/`. diff --git a/ejson/packages/ejson/README.md b/ejson/packages/ejson/README.md new file mode 120000 index 000000000..fe8400541 --- /dev/null +++ b/ejson/packages/ejson/README.md @@ -0,0 +1 @@ +../../README.md \ No newline at end of file diff --git a/ejson/packages/ejson_analyzer/README.md b/ejson/packages/ejson_analyzer/README.md deleted file mode 100644 index 8b55e735b..000000000 --- a/ejson/packages/ejson_analyzer/README.md +++ /dev/null @@ -1,39 +0,0 @@ - - -TODO: Put a short description of the package here that helps potential users -know whether this package might be useful for them. - -## Features - -TODO: List what your package can do. Maybe include images, gifs, or videos. - -## Getting started - -TODO: List prerequisites and provide or point to information on how to -start using the package. - -## Usage - -TODO: Include short and useful examples for package users. Add longer examples -to `/example` folder. - -```dart -const like = 'sample'; -``` - -## Additional information - -TODO: Tell users more about the package: where to find more information, how to -contribute to the package, how to file issues, what response they can expect -from the package authors, and more. diff --git a/ejson/packages/ejson_analyzer/README.md b/ejson/packages/ejson_analyzer/README.md new file mode 120000 index 000000000..fe8400541 --- /dev/null +++ b/ejson/packages/ejson_analyzer/README.md @@ -0,0 +1 @@ +../../README.md \ No newline at end of file diff --git a/ejson/packages/ejson_annotation/README.md b/ejson/packages/ejson_annotation/README.md deleted file mode 100644 index 8b55e735b..000000000 --- a/ejson/packages/ejson_annotation/README.md +++ /dev/null @@ -1,39 +0,0 @@ - - -TODO: Put a short description of the package here that helps potential users -know whether this package might be useful for them. - -## Features - -TODO: List what your package can do. Maybe include images, gifs, or videos. - -## Getting started - -TODO: List prerequisites and provide or point to information on how to -start using the package. - -## Usage - -TODO: Include short and useful examples for package users. Add longer examples -to `/example` folder. - -```dart -const like = 'sample'; -``` - -## Additional information - -TODO: Tell users more about the package: where to find more information, how to -contribute to the package, how to file issues, what response they can expect -from the package authors, and more. diff --git a/ejson/packages/ejson_annotation/README.md b/ejson/packages/ejson_annotation/README.md new file mode 120000 index 000000000..fe8400541 --- /dev/null +++ b/ejson/packages/ejson_annotation/README.md @@ -0,0 +1 @@ +../../README.md \ No newline at end of file diff --git a/ejson/packages/ejson_generator/README.md b/ejson/packages/ejson_generator/README.md deleted file mode 100644 index 8b55e735b..000000000 --- a/ejson/packages/ejson_generator/README.md +++ /dev/null @@ -1,39 +0,0 @@ - - -TODO: Put a short description of the package here that helps potential users -know whether this package might be useful for them. - -## Features - -TODO: List what your package can do. Maybe include images, gifs, or videos. - -## Getting started - -TODO: List prerequisites and provide or point to information on how to -start using the package. - -## Usage - -TODO: Include short and useful examples for package users. Add longer examples -to `/example` folder. - -```dart -const like = 'sample'; -``` - -## Additional information - -TODO: Tell users more about the package: where to find more information, how to -contribute to the package, how to file issues, what response they can expect -from the package authors, and more. diff --git a/ejson/packages/ejson_generator/README.md b/ejson/packages/ejson_generator/README.md new file mode 120000 index 000000000..fe8400541 --- /dev/null +++ b/ejson/packages/ejson_generator/README.md @@ -0,0 +1 @@ +../../README.md \ No newline at end of file diff --git a/ejson/packages/ejson_lint/README.md b/ejson/packages/ejson_lint/README.md deleted file mode 100644 index 8b55e735b..000000000 --- a/ejson/packages/ejson_lint/README.md +++ /dev/null @@ -1,39 +0,0 @@ - - -TODO: Put a short description of the package here that helps potential users -know whether this package might be useful for them. - -## Features - -TODO: List what your package can do. Maybe include images, gifs, or videos. - -## Getting started - -TODO: List prerequisites and provide or point to information on how to -start using the package. - -## Usage - -TODO: Include short and useful examples for package users. Add longer examples -to `/example` folder. - -```dart -const like = 'sample'; -``` - -## Additional information - -TODO: Tell users more about the package: where to find more information, how to -contribute to the package, how to file issues, what response they can expect -from the package authors, and more. diff --git a/ejson/packages/ejson_lint/README.md b/ejson/packages/ejson_lint/README.md new file mode 120000 index 000000000..fe8400541 --- /dev/null +++ b/ejson/packages/ejson_lint/README.md @@ -0,0 +1 @@ +../../README.md \ No newline at end of file From 633b65b7f504f3828fbb0a750ab20fe6051a97b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 14 Jun 2023 19:13:15 +0200 Subject: [PATCH 034/153] Expand melos:qa to include test:lints and analyze:deps --- ejson/melos.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ejson/melos.yaml b/ejson/melos.yaml index 144122c22..09e945ef5 100644 --- a/ejson/melos.yaml +++ b/ejson/melos.yaml @@ -26,14 +26,14 @@ scripts: run: >- melos run format:check && melos run analyze && + melos run analyze:deps && + melos run test:lints && melos run coverage qa:full: - description: Run all QA scripts + description: Run all QA scripts (including expensive ones). run: >- melos run qa && - melos run test:lints && - melos run analyze:deps && melos run pana && melos publish --dry-run From 5b59f5fe023d2b85dd187caf88c4104aaeb879bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 1 Aug 2023 10:28:22 +0200 Subject: [PATCH 035/153] Fix tests after rebase --- .../test/good_test_data/asymmetric_object.expected | 2 ++ test/backlinks_test.dart | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/realm_generator/test/good_test_data/asymmetric_object.expected b/packages/realm_generator/test/good_test_data/asymmetric_object.expected index d8d8497f3..5b6b826f2 100644 --- a/packages/realm_generator/test/good_test_data/asymmetric_object.expected +++ b/packages/realm_generator/test/good_test_data/asymmetric_object.expected @@ -9,6 +9,7 @@ part of 'asymmetric_object.dart'; // ignore_for_file: type=lint class Asymmetric extends _Asymmetric with RealmEntity, RealmObjectBase, RealmObject { + @ejson Asymmetric( ObjectId id, { Embedded? father, @@ -77,6 +78,7 @@ class Asymmetric extends _Asymmetric class Embedded extends _Embedded with RealmEntity, RealmObjectBase, EmbeddedObject { + @ejson Embedded( String name, int age, diff --git a/test/backlinks_test.dart b/test/backlinks_test.dart index ffbb048f2..68242cc52 100644 --- a/test/backlinks_test.dart +++ b/test/backlinks_test.dart @@ -19,7 +19,7 @@ import 'package:ejson_annotation/ejson_annotation.dart'; import 'package:ejson/ejson.dart'; -import 'package:test/expect.dart'; +import 'package:test/expect.dart' hide throws; import '../lib/realm.dart'; import 'test.dart'; From 979bbc7e05cb27559266b42ae2aae9d6e55315c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Mon, 11 Sep 2023 15:41:36 +0200 Subject: [PATCH 036/153] Support ObjectId and Uuid out-of-the-box --- ejson/packages/ejson/lib/src/decoding.dart | 29 ++++++++++++++++++++++ ejson/packages/ejson/lib/src/encoding.dart | 28 +++++++++++++++++++++ ejson/packages/ejson/pubspec.yaml | 2 ++ ejson/packages/ejson/test/ejson_test.dart | 11 ++++++++ 4 files changed, 70 insertions(+) diff --git a/ejson/packages/ejson/lib/src/decoding.dart b/ejson/packages/ejson/lib/src/decoding.dart index d08d475af..a3c24a12d 100644 --- a/ejson/packages/ejson/lib/src/decoding.dart +++ b/ejson/packages/ejson/lib/src/decoding.dart @@ -16,8 +16,13 @@ // //////////////////////////////////////////////////////////////////////////////// +import 'dart:typed_data'; +import 'dart:convert'; + import 'package:collection/collection.dart'; import 'package:ejson_annotation/ejson_annotation.dart'; +import 'package:objectid/objectid.dart'; +import 'package:sane_uuid/uuid.dart'; import 'package:type_plus/type_plus.dart'; import 'types.dart'; @@ -35,8 +40,10 @@ const commonDecoders = { double: _decodeDouble, num: _decodeNum, int: _decodeInt, + ObjectId: _decodeObjectId, String: _decodeString, Symbol: _decodeSymbol, + Uuid: _decodeUuid, Undefined: _decodeUndefined, UndefinedOr: _decodeUndefinedOr, }; @@ -51,6 +58,8 @@ final decoders = () { TypePlus.addFactory((f) => f>(), superTypes: [undefinedOr]); TypePlus.addFactory((f) => f>(), superTypes: [undefinedOr]); TypePlus.add(); + TypePlus.add(); + TypePlus.add(); return CombinedMapView([customDecoders, commonDecoders]); }(); @@ -88,6 +97,8 @@ dynamic _decodeAny(EJsonValue ejson) { {'\$regex': _} => _decodeString(ejson), {'\$symbol': _} => _decodeSymbol(ejson), {'\$undefined': _} => _decodeUndefined(ejson), + {'\$oid': _} => _decodeObjectId(ejson), + {'\$binary': {'base64': _, 'subType': '04'}} => _decodeUuid(ejson), List _ => _decodeArray(ejson), Map _ => _tryDecodeCustom(ejson) ?? _decodeDocument(ejson), // other maps goes last!! @@ -197,6 +208,13 @@ num _decodeNum(EJsonValue ejson) { }; } +ObjectId _decodeObjectId(EJsonValue ejson) { + return switch (ejson) { + {'\$oid': String s} => ObjectId.fromHexString(s), + _ => raiseInvalidEJson(ejson), + }; +} + String _decodeString(EJsonValue ejson) { return switch (ejson) { String s => s, @@ -225,6 +243,17 @@ UndefinedOr _decodeUndefinedOr(EJsonValue ejson) { }; } +Uuid _decodeUuid(EJsonValue ejson) => + Uuid.fromBytes(_decodeBinary(ejson, "04")); + +ByteBuffer _decodeBinary(EJsonValue ejson, String subType) { + return switch (ejson) { + {'\$binary': {'base64': String s, 'subType': String t}} when t == subType => + base64.decode(s).buffer, + _ => raiseInvalidEJson(ejson), + }; +} + class InvalidEJson implements Exception { final Object? value; diff --git a/ejson/packages/ejson/lib/src/encoding.dart b/ejson/packages/ejson/lib/src/encoding.dart index eff415d1b..3f8e7f0cb 100644 --- a/ejson/packages/ejson/lib/src/encoding.dart +++ b/ejson/packages/ejson/lib/src/encoding.dart @@ -16,7 +16,12 @@ // //////////////////////////////////////////////////////////////////////////////// +import 'dart:convert'; +import 'dart:typed_data'; + import 'package:ejson_annotation/ejson_annotation.dart'; +import 'package:objectid/objectid.dart'; +import 'package:sane_uuid/uuid.dart'; import 'package:type_plus/type_plus.dart'; import 'types.dart'; @@ -42,9 +47,11 @@ EJsonValue _encodeAny(Object? value) { Key k => _encodeKey(k), List l => _encodeArray(l), Map m => _encodeDocument(m), + ObjectId o => _encodeObjectId(o), String s => _encodeString(s), Symbol s => _encodeSymbol(s), Undefined u => _encodeUndefined(u), + Uuid u => _encodeUuid(u), _ => _encodeCustom(value), }; } @@ -106,6 +113,17 @@ EJsonValue _encodeSymbol(Symbol value) => {'\$symbol': value.name}; EJsonValue _encodeUndefined(Undefined undefined) => {'\$undefined': 1}; +EJsonValue _encodeUuid(Uuid uuid) => _encodeBinary(uuid.bytes, "04"); + +EJsonValue _encodeBinary(ByteBuffer buffer, String subtype) => { + '\$binary': { + 'base64': base64.encode(buffer.asUint8List()), + 'subType': subtype + }, + }; + +EJsonValue _encodeObjectId(ObjectId objectId) => {'\$oid': objectId.hexString}; + class MissingEncoder implements Exception { final Object value; @@ -160,6 +178,11 @@ extension NullableObjectEJsonEncoderExtension on Object? { EJsonValue toEJson() => _encodeAny(this); } +extension ObjectIdEJsonEncoderExtension on ObjectId { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => _encodeObjectId(this); +} + extension StringEJsonEncoderExtension on String { @pragma('vm:prefer-inline') EJsonValue toEJson() => _encodeString(this); @@ -179,3 +202,8 @@ extension UndefinedEJsonEncoderExtension on Undefined { @pragma('vm:prefer-inline') EJsonValue toEJson() => _encodeUndefined(this); } + +extension UuidEJsonEncoderExtension on Uuid { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => _encodeUuid(this); +} diff --git a/ejson/packages/ejson/pubspec.yaml b/ejson/packages/ejson/pubspec.yaml index 982b1f429..eada24663 100644 --- a/ejson/packages/ejson/pubspec.yaml +++ b/ejson/packages/ejson/pubspec.yaml @@ -21,6 +21,8 @@ environment: dependencies: collection: ^1.17.0 ejson_annotation: ^0.1.0 + objectid: ^3.0.0 + sane_uuid: ^1.0.0-alpha.5 type_plus: ^2.0.0 dev_dependencies: diff --git a/ejson/packages/ejson/test/ejson_test.dart b/ejson/packages/ejson/test/ejson_test.dart index c2cb73b33..f4e65056c 100644 --- a/ejson/packages/ejson/test/ejson_test.dart +++ b/ejson/packages/ejson/test/ejson_test.dart @@ -20,6 +20,8 @@ import 'dart:convert'; import 'package:ejson/ejson.dart'; import 'package:ejson_annotation/ejson_annotation.dart'; +import 'package:objectid/objectid.dart'; +import 'package:sane_uuid/uuid.dart'; import 'package:test/test.dart'; import 'ejson_serialization_setup.g.dart'; @@ -148,6 +150,15 @@ void main() { _testCase(const Defined(null), null); _testCase(Defined(42), {'\$numberLong': 42}, 42); _testCase(Defined(null), null); + _testCase(ObjectId.fromValues(1, 2, 3), + {'\$oid': '000000000000000002000003'}); + final uuid = Uuid.v4(); + _testCase(uuid, { + '\$binary': { + 'base64': base64.encode(uuid.bytes.asUint8List()), + 'subType': '04' + } + }); // a complex nested generic type _testCase?>>>( { From 4ff8544c6903d864573da9be1ddf6f46c7efb097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 3 Jan 2024 11:59:19 +0100 Subject: [PATCH 037/153] Update analyzer dependency for ejson --- ejson/packages/ejson_analyzer/pubspec.yaml | 2 +- ejson/packages/ejson_generator/pubspec.yaml | 2 +- ejson/packages/ejson_lint/pubspec.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ejson/packages/ejson_analyzer/pubspec.yaml b/ejson/packages/ejson_analyzer/pubspec.yaml index a9c6985ad..4b2797772 100644 --- a/ejson/packages/ejson_analyzer/pubspec.yaml +++ b/ejson/packages/ejson_analyzer/pubspec.yaml @@ -8,7 +8,7 @@ environment: sdk: ^3.0.2 dependencies: - analyzer: ^5.12.0 + analyzer: ^6.0.0 ejson_annotation: ^0.1.0 source_gen: ^1.3.2 diff --git a/ejson/packages/ejson_generator/pubspec.yaml b/ejson/packages/ejson_generator/pubspec.yaml index c3aec782e..13205dcc5 100644 --- a/ejson/packages/ejson_generator/pubspec.yaml +++ b/ejson/packages/ejson_generator/pubspec.yaml @@ -19,7 +19,7 @@ environment: sdk: ^3.0.1 dependencies: - analyzer: ^5.12.0 + analyzer: ^6.0.0 build: ^2.4.0 ejson_analyzer: ^0.1.0 source_gen: ^1.3.2 diff --git a/ejson/packages/ejson_lint/pubspec.yaml b/ejson/packages/ejson_lint/pubspec.yaml index 6b3f098ff..ec0be189b 100644 --- a/ejson/packages/ejson_lint/pubspec.yaml +++ b/ejson/packages/ejson_lint/pubspec.yaml @@ -8,7 +8,7 @@ environment: sdk: ^3.0.2 dependencies: - analyzer: ^5.12.0 + analyzer: ^6.0.0 custom_lint_builder: ^0.4.0 ejson_analyzer: ^0.1.0 From 548cfb65ecd567ae37064c4efaf43af566241597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 3 Jan 2024 13:14:53 +0100 Subject: [PATCH 038/153] Update lint related deps --- ejson/packages/ejson/pubspec.yaml | 2 +- ejson/packages/ejson_analyzer/pubspec.yaml | 2 +- ejson/packages/ejson_annotation/pubspec.yaml | 2 +- ejson/packages/ejson_generator/pubspec.yaml | 2 +- ejson/packages/ejson_lint/example/pubspec.yaml | 2 +- ejson/packages/ejson_lint/pubspec.yaml | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ejson/packages/ejson/pubspec.yaml b/ejson/packages/ejson/pubspec.yaml index eada24663..1387b25a4 100644 --- a/ejson/packages/ejson/pubspec.yaml +++ b/ejson/packages/ejson/pubspec.yaml @@ -26,5 +26,5 @@ dependencies: type_plus: ^2.0.0 dev_dependencies: - lints: ^2.0.0 + lints: ^3.0.0 test: ^1.21.0 diff --git a/ejson/packages/ejson_analyzer/pubspec.yaml b/ejson/packages/ejson_analyzer/pubspec.yaml index 4b2797772..86403129f 100644 --- a/ejson/packages/ejson_analyzer/pubspec.yaml +++ b/ejson/packages/ejson_analyzer/pubspec.yaml @@ -13,5 +13,5 @@ dependencies: source_gen: ^1.3.2 dev_dependencies: - lints: ^2.0.0 + lints: ^3.0.0 test: ^1.21.0 diff --git a/ejson/packages/ejson_annotation/pubspec.yaml b/ejson/packages/ejson_annotation/pubspec.yaml index 148c79f9a..e2fbae9b0 100644 --- a/ejson/packages/ejson_annotation/pubspec.yaml +++ b/ejson/packages/ejson_annotation/pubspec.yaml @@ -12,4 +12,4 @@ environment: sdk: ^3.0.2 dev_dependencies: - lints: ^2.0.0 + lints: ^3.0.0 diff --git a/ejson/packages/ejson_generator/pubspec.yaml b/ejson/packages/ejson_generator/pubspec.yaml index 13205dcc5..1975cb65b 100644 --- a/ejson/packages/ejson_generator/pubspec.yaml +++ b/ejson/packages/ejson_generator/pubspec.yaml @@ -30,6 +30,6 @@ dev_dependencies: dart_style: ^2.3.1 ejson: ^0.1.0 ejson_annotation: ^0.1.0 - lints: ^2.0.0 + lints: ^3.0.0 meta: ^1.9.1 test: ^1.21.0 diff --git a/ejson/packages/ejson_lint/example/pubspec.yaml b/ejson/packages/ejson_lint/example/pubspec.yaml index 4c3be7e7c..b3472daaf 100644 --- a/ejson/packages/ejson_lint/example/pubspec.yaml +++ b/ejson/packages/ejson_lint/example/pubspec.yaml @@ -11,7 +11,7 @@ dependencies: ejson_annotation: ^0.1.0 dev_dependencies: - custom_lint: ^0.4.0 + custom_lint: ^0.5.7 ejson_lint: ^0.1.0 lints: ^2.0.0 diff --git a/ejson/packages/ejson_lint/pubspec.yaml b/ejson/packages/ejson_lint/pubspec.yaml index ec0be189b..58adc0851 100644 --- a/ejson/packages/ejson_lint/pubspec.yaml +++ b/ejson/packages/ejson_lint/pubspec.yaml @@ -9,9 +9,9 @@ environment: dependencies: analyzer: ^6.0.0 - custom_lint_builder: ^0.4.0 + custom_lint_builder: ^0.5.7 ejson_analyzer: ^0.1.0 dev_dependencies: - lints: ^2.0.0 + lints: ^3.0.0 test: ^1.21.0 From 92fdd718bff2e459e8a6d587410a2ee914bb7713 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 3 Jan 2024 13:42:02 +0100 Subject: [PATCH 039/153] Fix lints and tests --- ejson/packages/ejson/lib/ejson.dart | 1 + .../packages/ejson/lib/src/configuration.dart | 1 + ejson/packages/ejson/lib/src/decoding.dart | 1 + ejson/packages/ejson/lib/src/encoding.dart | 1 + ejson/packages/ejson/lib/src/types.dart | 1 + ejson/packages/ejson/test/ejson_test.dart | 1 + .../ejson_generator/lib/src/builder.dart | 1 + .../ejson_generator/lib/src/generator.dart | 1 + .../ejson_generator/test/compile_test.dart | 29 ++++++++++++------- .../ejson_generator/test/ctor_test.dart | 1 + 10 files changed, 28 insertions(+), 10 deletions(-) diff --git a/ejson/packages/ejson/lib/ejson.dart b/ejson/packages/ejson/lib/ejson.dart index 729f83c08..45cb030b0 100644 --- a/ejson/packages/ejson/lib/ejson.dart +++ b/ejson/packages/ejson/lib/ejson.dart @@ -15,6 +15,7 @@ // limitations under the License. // //////////////////////////////////////////////////////////////////////////////// +library; export 'src/configuration.dart'; export 'src/decoding.dart'; diff --git a/ejson/packages/ejson/lib/src/configuration.dart b/ejson/packages/ejson/lib/src/configuration.dart index 308bfbde1..361b13694 100644 --- a/ejson/packages/ejson/lib/src/configuration.dart +++ b/ejson/packages/ejson/lib/src/configuration.dart @@ -15,6 +15,7 @@ // limitations under the License. // //////////////////////////////////////////////////////////////////////////////// +library; import 'package:ejson_annotation/ejson_annotation.dart'; import 'package:type_plus/type_plus.dart'; diff --git a/ejson/packages/ejson/lib/src/decoding.dart b/ejson/packages/ejson/lib/src/decoding.dart index a3c24a12d..13d1f1dfb 100644 --- a/ejson/packages/ejson/lib/src/decoding.dart +++ b/ejson/packages/ejson/lib/src/decoding.dart @@ -15,6 +15,7 @@ // limitations under the License. // //////////////////////////////////////////////////////////////////////////////// +library; import 'dart:typed_data'; import 'dart:convert'; diff --git a/ejson/packages/ejson/lib/src/encoding.dart b/ejson/packages/ejson/lib/src/encoding.dart index 3f8e7f0cb..5101016e0 100644 --- a/ejson/packages/ejson/lib/src/encoding.dart +++ b/ejson/packages/ejson/lib/src/encoding.dart @@ -15,6 +15,7 @@ // limitations under the License. // //////////////////////////////////////////////////////////////////////////////// +library; import 'dart:convert'; import 'dart:typed_data'; diff --git a/ejson/packages/ejson/lib/src/types.dart b/ejson/packages/ejson/lib/src/types.dart index cda0c0204..f636b9fcb 100644 --- a/ejson/packages/ejson/lib/src/types.dart +++ b/ejson/packages/ejson/lib/src/types.dart @@ -15,6 +15,7 @@ // limitations under the License. // //////////////////////////////////////////////////////////////////////////////// +library; enum EJsonType { array, diff --git a/ejson/packages/ejson/test/ejson_test.dart b/ejson/packages/ejson/test/ejson_test.dart index f4e65056c..7cb3598da 100644 --- a/ejson/packages/ejson/test/ejson_test.dart +++ b/ejson/packages/ejson/test/ejson_test.dart @@ -15,6 +15,7 @@ // limitations under the License. // //////////////////////////////////////////////////////////////////////////////// +library; import 'dart:convert'; diff --git a/ejson/packages/ejson_generator/lib/src/builder.dart b/ejson/packages/ejson_generator/lib/src/builder.dart index ef32150a2..4b8514ba7 100644 --- a/ejson/packages/ejson_generator/lib/src/builder.dart +++ b/ejson/packages/ejson_generator/lib/src/builder.dart @@ -15,6 +15,7 @@ // limitations under the License. // //////////////////////////////////////////////////////////////////////////////// +library; import 'package:build/build.dart'; import 'package:source_gen/source_gen.dart'; diff --git a/ejson/packages/ejson_generator/lib/src/generator.dart b/ejson/packages/ejson_generator/lib/src/generator.dart index 41cd848f7..6ee2f342d 100644 --- a/ejson/packages/ejson_generator/lib/src/generator.dart +++ b/ejson/packages/ejson_generator/lib/src/generator.dart @@ -15,6 +15,7 @@ // limitations under the License. // //////////////////////////////////////////////////////////////////////////////// +library; import 'dart:async'; diff --git a/ejson/packages/ejson_generator/test/compile_test.dart b/ejson/packages/ejson_generator/test/compile_test.dart index 82e42a938..96a629512 100644 --- a/ejson/packages/ejson_generator/test/compile_test.dart +++ b/ejson/packages/ejson_generator/test/compile_test.dart @@ -31,16 +31,7 @@ void testCompile(String description, dynamic source, dynamic matcher, final writer = InMemoryAssetWriter(); await testBuilder( getEJsonGenerator(), - { - 'pkg|source.dart': ''' -import 'package:ejson/ejson.dart'; -import 'package:ejson_annotation/ejson_annotation.dart'; - -$source - -void main() {} -''', - }, + {'pkg|source.dart': source}, writer: writer, reader: await PackageAssetReader.currentIsolate(), ); @@ -57,6 +48,9 @@ Future main() async { testCompile( 'two annotated ctors', r''' +import 'package:ejson/ejson.dart'; +import 'package:ejson_annotation/ejson_annotation.dart'; + class TwoAnnotatedCtors { final int i; @ejson @@ -74,6 +68,9 @@ class TwoAnnotatedCtors { testCompile( 'missing getter', r''' +import 'package:ejson/ejson.dart'; +import 'package:ejson_annotation/ejson_annotation.dart'; + class MissingGetter { final int _i; // missing a getter for _i called i @ejson @@ -86,6 +83,9 @@ class MissingGetter { testCompile( 'mismatching getter', r''' +import 'package:ejson/ejson.dart'; +import 'package:ejson_annotation/ejson_annotation.dart'; + class MismatchingGetter { final int _i; String get i => _i.toString(); // getter is not of type int @@ -101,6 +101,9 @@ class MismatchingGetter { testCompile( 'private field', r''' +import 'package:ejson/ejson.dart'; +import 'package:ejson_annotation/ejson_annotation.dart'; + class PrivateFieldIsOkay { final int _i; // private fields are okay @ejson @@ -113,6 +116,9 @@ class PrivateFieldIsOkay { testCompile( 'mismatching getter but custom encoder', r''' +import 'package:ejson/ejson.dart'; +import 'package:ejson_annotation/ejson_annotation.dart'; + EJsonValue _encode(MismatchingGetterButCustomEncoder value) => {'i': value._i}; class MismatchingGetterButCustomEncoder { @@ -129,6 +135,9 @@ class MismatchingGetterButCustomEncoder { testCompile( 'empty class', r''' +import 'package:ejson/ejson.dart'; +import 'package:ejson_annotation/ejson_annotation.dart'; + class Empty { @ejson const Empty(); diff --git a/ejson/packages/ejson_generator/test/ctor_test.dart b/ejson/packages/ejson_generator/test/ctor_test.dart index ace38307b..7f4e2565a 100644 --- a/ejson/packages/ejson_generator/test/ctor_test.dart +++ b/ejson/packages/ejson_generator/test/ctor_test.dart @@ -15,6 +15,7 @@ // limitations under the License. // //////////////////////////////////////////////////////////////////////////////// +library; import 'package:ejson/ejson.dart'; import 'package:ejson_annotation/ejson_annotation.dart'; From 8a8be68b93d8761fe35c3a23039518a0a6c1ada1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 3 Jan 2024 13:47:56 +0100 Subject: [PATCH 040/153] Run builder runner --- packages/realm_dart/test/geospatial_test.dart | 3 + .../test/geospatial_test.realm.dart | 3 + packages/realm_dart/test/realm_map_test.dart | 3 + .../realm_dart/test/realm_map_test.realm.dart | 3 + packages/realm_dart/test/test.g.dart | 69 ++++++++++ packages/realm_dart/test/test.realm.dart | 3 + test/geospatial_test.g.dart | 63 +++++++++ test/realm_map_test.g.dart | 124 ++++++++++++++++++ 8 files changed, 271 insertions(+) create mode 100644 test/geospatial_test.g.dart create mode 100644 test/realm_map_test.g.dart diff --git a/packages/realm_dart/test/geospatial_test.dart b/packages/realm_dart/test/geospatial_test.dart index 9e5286490..af1306bf6 100644 --- a/packages/realm_dart/test/geospatial_test.dart +++ b/packages/realm_dart/test/geospatial_test.dart @@ -19,12 +19,15 @@ import 'dart:async'; import 'dart:math'; +import 'package:ejson/ejson.dart'; +import 'package:ejson_annotation/ejson_annotation.dart'; import 'package:realm_common/realm_common.dart'; import 'package:test/test.dart' hide test, throws; import 'package:realm_dart/realm.dart'; import 'test.dart'; +part 'geospatial_test.g.dart'; part 'geospatial_test.realm.dart'; @RealmModel(ObjectType.embeddedObject) diff --git a/packages/realm_dart/test/geospatial_test.realm.dart b/packages/realm_dart/test/geospatial_test.realm.dart index e2e336e19..6a8a6e2fa 100644 --- a/packages/realm_dart/test/geospatial_test.realm.dart +++ b/packages/realm_dart/test/geospatial_test.realm.dart @@ -11,6 +11,7 @@ class Location extends _Location with RealmEntity, RealmObjectBase, EmbeddedObject { static var _defaultsSet = false; + @ejson Location({ String type = 'Point', Iterable coordinates = const [], @@ -58,6 +59,7 @@ class Location extends _Location class Restaurant extends _Restaurant with RealmEntity, RealmObjectBase, RealmObject { + @ejson Restaurant( String name, { Location? location, @@ -102,6 +104,7 @@ class Restaurant extends _Restaurant class LocationList extends _LocationList with RealmEntity, RealmObjectBase, RealmObject { + @ejson LocationList({ Iterable locations = const [], }) { diff --git a/packages/realm_dart/test/realm_map_test.dart b/packages/realm_dart/test/realm_map_test.dart index 32aeac8e5..06d42513d 100644 --- a/packages/realm_dart/test/realm_map_test.dart +++ b/packages/realm_dart/test/realm_map_test.dart @@ -21,12 +21,15 @@ import 'dart:io'; import 'dart:typed_data'; import 'package:collection/collection.dart'; +import 'package:ejson/ejson.dart'; +import 'package:ejson_annotation/ejson_annotation.dart'; import 'package:meta/meta.dart'; import 'package:test/test.dart' hide test, throws; import 'package:realm_dart/realm.dart'; import 'test.dart'; +part 'realm_map_test.g.dart'; part 'realm_map_test.realm.dart'; @RealmModel() diff --git a/packages/realm_dart/test/realm_map_test.realm.dart b/packages/realm_dart/test/realm_map_test.realm.dart index 3acadf1f7..0175b3099 100644 --- a/packages/realm_dart/test/realm_map_test.realm.dart +++ b/packages/realm_dart/test/realm_map_test.realm.dart @@ -8,6 +8,7 @@ part of 'realm_map_test.dart'; // ignore_for_file: type=lint class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { + @ejson Car( String make, { String? color, @@ -48,6 +49,7 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { class EmbeddedValue extends _EmbeddedValue with RealmEntity, RealmObjectBase, EmbeddedObject { + @ejson EmbeddedValue( int intValue, ) { @@ -81,6 +83,7 @@ class EmbeddedValue extends _EmbeddedValue class TestRealmMaps extends _TestRealmMaps with RealmEntity, RealmObjectBase, RealmObject { + @ejson TestRealmMaps( int key, { Map boolMap = const {}, diff --git a/packages/realm_dart/test/test.g.dart b/packages/realm_dart/test/test.g.dart index a56dd7967..95d781920 100644 --- a/packages/realm_dart/test/test.g.dart +++ b/packages/realm_dart/test/test.g.dart @@ -849,3 +849,72 @@ extension ObjectWithDecimalEJsonEncoderExtension on ObjectWithDecimal { @pragma('vm:prefer-inline') EJsonValue toEJson() => encodeObjectWithDecimal(this); } + +EJsonValue encodeAsymmetric(Asymmetric value) { + return { + 'id': value.id.toEJson(), + 'symmetric': value.symmetric.toEJson(), + 'embeddedObjects': value.embeddedObjects.toEJson() + }; +} + +Asymmetric decodeAsymmetric(EJsonValue ejson) { + return switch (ejson) { + { + 'id': EJsonValue id, + 'symmetric': EJsonValue symmetric, + 'embeddedObjects': EJsonValue embeddedObjects + } => + Asymmetric(id.to(), + symmetric: symmetric.to(), + embeddedObjects: embeddedObjects.to>()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension AsymmetricEJsonEncoderExtension on Asymmetric { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeAsymmetric(this); +} + +EJsonValue encodeEmbedded(Embedded value) { + return { + 'value': value.value.toEJson(), + 'any': value.any.toEJson(), + 'symmetric': value.symmetric.toEJson() + }; +} + +Embedded decodeEmbedded(EJsonValue ejson) { + return switch (ejson) { + { + 'value': EJsonValue value, + 'any': EJsonValue any, + 'symmetric': EJsonValue symmetric + } => + Embedded(value.to(), + any: any.to(), symmetric: symmetric.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension EmbeddedEJsonEncoderExtension on Embedded { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeEmbedded(this); +} + +EJsonValue encodeSymmetric(Symmetric value) { + return {'id': value.id.toEJson()}; +} + +Symmetric decodeSymmetric(EJsonValue ejson) { + return switch (ejson) { + {'id': EJsonValue id} => Symmetric(id.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension SymmetricEJsonEncoderExtension on Symmetric { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeSymmetric(this); +} diff --git a/packages/realm_dart/test/test.realm.dart b/packages/realm_dart/test/test.realm.dart index 52f659000..afddc7f4b 100644 --- a/packages/realm_dart/test/test.realm.dart +++ b/packages/realm_dart/test/test.realm.dart @@ -2519,6 +2519,7 @@ class ObjectWithDecimal extends _ObjectWithDecimal class Asymmetric extends _Asymmetric with RealmEntity, RealmObjectBase, AsymmetricObject { + @ejson Asymmetric( ObjectId id, { Symmetric? symmetric, @@ -2577,6 +2578,7 @@ class Asymmetric extends _Asymmetric class Embedded extends _Embedded with RealmEntity, RealmObjectBase, EmbeddedObject { + @ejson Embedded( int value, { RealmValue any = const RealmValue.nullValue(), @@ -2629,6 +2631,7 @@ class Embedded extends _Embedded class Symmetric extends _Symmetric with RealmEntity, RealmObjectBase, RealmObject { + @ejson Symmetric( ObjectId id, ) { diff --git a/test/geospatial_test.g.dart b/test/geospatial_test.g.dart new file mode 100644 index 000000000..3a7b3e471 --- /dev/null +++ b/test/geospatial_test.g.dart @@ -0,0 +1,63 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'geospatial_test.dart'; + +// ************************************************************************** +// EJsonGenerator +// ************************************************************************** + +EJsonValue encodeLocation(Location value) { + return { + 'type': value.type.toEJson(), + 'coordinates': value.coordinates.toEJson() + }; +} + +Location decodeLocation(EJsonValue ejson) { + return switch (ejson) { + {'type': EJsonValue type, 'coordinates': EJsonValue coordinates} => + Location( + type: type.to(), + coordinates: coordinates.to>()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension LocationEJsonEncoderExtension on Location { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeLocation(this); +} + +EJsonValue encodeRestaurant(Restaurant value) { + return {'name': value.name.toEJson(), 'location': value.location.toEJson()}; +} + +Restaurant decodeRestaurant(EJsonValue ejson) { + return switch (ejson) { + {'name': EJsonValue name, 'location': EJsonValue location} => + Restaurant(name.to(), location: location.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension RestaurantEJsonEncoderExtension on Restaurant { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeRestaurant(this); +} + +EJsonValue encodeLocationList(LocationList value) { + return {'locations': value.locations.toEJson()}; +} + +LocationList decodeLocationList(EJsonValue ejson) { + return switch (ejson) { + {'locations': EJsonValue locations} => + LocationList(locations: locations.to>()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension LocationListEJsonEncoderExtension on LocationList { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeLocationList(this); +} diff --git a/test/realm_map_test.g.dart b/test/realm_map_test.g.dart new file mode 100644 index 000000000..21e7ad423 --- /dev/null +++ b/test/realm_map_test.g.dart @@ -0,0 +1,124 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'realm_map_test.dart'; + +// ************************************************************************** +// EJsonGenerator +// ************************************************************************** + +EJsonValue encodeCar(Car value) { + return {'make': value.make.toEJson(), 'color': value.color.toEJson()}; +} + +Car decodeCar(EJsonValue ejson) { + return switch (ejson) { + {'make': EJsonValue make, 'color': EJsonValue color} => + Car(make.to(), color: color.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension CarEJsonEncoderExtension on Car { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeCar(this); +} + +EJsonValue encodeEmbeddedValue(EmbeddedValue value) { + return {'intValue': value.intValue.toEJson()}; +} + +EmbeddedValue decodeEmbeddedValue(EJsonValue ejson) { + return switch (ejson) { + {'intValue': EJsonValue intValue} => EmbeddedValue(intValue.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension EmbeddedValueEJsonEncoderExtension on EmbeddedValue { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeEmbeddedValue(this); +} + +EJsonValue encodeTestRealmMaps(TestRealmMaps value) { + return { + 'key': value.key.toEJson(), + 'boolMap': value.boolMap.toEJson(), + 'intMap': value.intMap.toEJson(), + 'stringMap': value.stringMap.toEJson(), + 'doubleMap': value.doubleMap.toEJson(), + 'dateTimeMap': value.dateTimeMap.toEJson(), + 'objectIdMap': value.objectIdMap.toEJson(), + 'uuidMap': value.uuidMap.toEJson(), + 'binaryMap': value.binaryMap.toEJson(), + 'decimalMap': value.decimalMap.toEJson(), + 'nullableBoolMap': value.nullableBoolMap.toEJson(), + 'nullableIntMap': value.nullableIntMap.toEJson(), + 'nullableStringMap': value.nullableStringMap.toEJson(), + 'nullableDoubleMap': value.nullableDoubleMap.toEJson(), + 'nullableDateTimeMap': value.nullableDateTimeMap.toEJson(), + 'nullableObjectIdMap': value.nullableObjectIdMap.toEJson(), + 'nullableUuidMap': value.nullableUuidMap.toEJson(), + 'nullableBinaryMap': value.nullableBinaryMap.toEJson(), + 'nullableDecimalMap': value.nullableDecimalMap.toEJson(), + 'objectsMap': value.objectsMap.toEJson(), + 'embeddedMap': value.embeddedMap.toEJson(), + 'mixedMap': value.mixedMap.toEJson() + }; +} + +TestRealmMaps decodeTestRealmMaps(EJsonValue ejson) { + return switch (ejson) { + { + 'key': EJsonValue key, + 'boolMap': EJsonValue boolMap, + 'intMap': EJsonValue intMap, + 'stringMap': EJsonValue stringMap, + 'doubleMap': EJsonValue doubleMap, + 'dateTimeMap': EJsonValue dateTimeMap, + 'objectIdMap': EJsonValue objectIdMap, + 'uuidMap': EJsonValue uuidMap, + 'binaryMap': EJsonValue binaryMap, + 'decimalMap': EJsonValue decimalMap, + 'nullableBoolMap': EJsonValue nullableBoolMap, + 'nullableIntMap': EJsonValue nullableIntMap, + 'nullableStringMap': EJsonValue nullableStringMap, + 'nullableDoubleMap': EJsonValue nullableDoubleMap, + 'nullableDateTimeMap': EJsonValue nullableDateTimeMap, + 'nullableObjectIdMap': EJsonValue nullableObjectIdMap, + 'nullableUuidMap': EJsonValue nullableUuidMap, + 'nullableBinaryMap': EJsonValue nullableBinaryMap, + 'nullableDecimalMap': EJsonValue nullableDecimalMap, + 'objectsMap': EJsonValue objectsMap, + 'embeddedMap': EJsonValue embeddedMap, + 'mixedMap': EJsonValue mixedMap + } => + TestRealmMaps(key.to(), + boolMap: boolMap.to>(), + intMap: intMap.to>(), + stringMap: stringMap.to>(), + doubleMap: doubleMap.to>(), + dateTimeMap: dateTimeMap.to>(), + objectIdMap: objectIdMap.to>(), + uuidMap: uuidMap.to>(), + binaryMap: binaryMap.to>(), + decimalMap: decimalMap.to>(), + nullableBoolMap: nullableBoolMap.to>(), + nullableIntMap: nullableIntMap.to>(), + nullableStringMap: nullableStringMap.to>(), + nullableDoubleMap: nullableDoubleMap.to>(), + nullableDateTimeMap: nullableDateTimeMap.to>(), + nullableObjectIdMap: nullableObjectIdMap.to>(), + nullableUuidMap: nullableUuidMap.to>(), + nullableBinaryMap: nullableBinaryMap.to>(), + nullableDecimalMap: nullableDecimalMap.to>(), + objectsMap: objectsMap.to>(), + embeddedMap: embeddedMap.to>(), + mixedMap: mixedMap.to>()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension TestRealmMapsEJsonEncoderExtension on TestRealmMaps { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeTestRealmMaps(this); +} From 2ecd55e1665f4a5cd2cd8411d560ef28f35c4f74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Thu, 4 Jan 2024 11:34:57 +0100 Subject: [PATCH 041/153] Fix realm generator tests --- packages/realm_generator/test/good_test_data/map.expected | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/realm_generator/test/good_test_data/map.expected b/packages/realm_generator/test/good_test_data/map.expected index 386c33cc1..2916662ce 100644 --- a/packages/realm_generator/test/good_test_data/map.expected +++ b/packages/realm_generator/test/good_test_data/map.expected @@ -9,6 +9,7 @@ part of 'map.dart'; // ignore_for_file: type=lint class LotsOfMaps extends _LotsOfMaps with RealmEntity, RealmObjectBase, RealmObject { + @ejson LotsOfMaps({ Map persons = const {}, Map bools = const {}, @@ -170,6 +171,7 @@ class LotsOfMaps extends _LotsOfMaps } class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { + @ejson Person( String name, ) { From 5283e39ed97454317d5fd65465d91bec6bc54a79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Mon, 19 Feb 2024 15:40:59 +0100 Subject: [PATCH 042/153] Flatten package structure --- ejson/LICENSE | 177 ------------------ ejson/melos.yaml => melos.yaml | 0 .../packages => packages}/ejson/CHANGELOG.md | 0 {ejson/packages => packages}/ejson/LICENSE | 0 {ejson/packages => packages}/ejson/README.md | 0 .../ejson/analysis_options.yaml | 0 .../ejson/example/main.dart | 0 .../ejson/lib/ejson.dart | 0 .../ejson/lib/src/configuration.dart | 0 .../ejson/lib/src/decoding.dart | 0 .../ejson/lib/src/encoding.dart | 0 .../ejson/lib/src/types.dart | 0 .../packages => packages}/ejson/pubspec.yaml | 0 .../test/ejson_serialization_setup.g.dart | 0 .../ejson/test/ejson_test.dart | 0 .../ejson/test/person.dart | 0 .../ejson/test/person.g.dart | 0 .../ejson_analyzer/.gitignore | 0 .../ejson_analyzer/CHANGELOG.md | 0 .../ejson_analyzer/LICENSE | 0 .../ejson_analyzer/README.md | 0 .../ejson_analyzer/analysis_options.yaml | 0 .../ejson_analyzer/lib/ejson_analyzer.dart | 0 .../lib/src/ejson_analyzer_base.dart | 0 .../ejson_analyzer/pubspec.yaml | 0 .../test/ejson_analyzer_test.dart | 0 .../ejson_annotation/.gitignore | 0 .../ejson_annotation/CHANGELOG.md | 0 .../ejson_annotation/LICENSE | 0 .../ejson_annotation/README.md | 0 .../ejson_annotation/analysis_options.yaml | 0 .../lib/ejson_annotation.dart | 0 .../ejson_annotation/pubspec.yaml | 0 .../ejson_generator/.gitignore | 0 .../ejson_generator/CHANGELOG.md | 0 .../ejson_generator/LICENSE | 0 .../ejson_generator/README.md | 0 .../ejson_generator/analysis_options.yaml | 0 .../ejson_generator/build.yaml | 0 .../ejson_generator/lib/ejson_generator.dart | 0 .../ejson_generator/lib/src/builder.dart | 0 .../ejson_generator/lib/src/generator.dart | 0 .../ejson_generator/pubspec.yaml | 0 .../ejson_generator/test/compile_test.dart | 0 .../ejson_generator/test/ctor_test.dart | 0 .../ejson_generator/test/ctor_test.g.dart | 0 .../ejson_lint/.gitignore | 0 .../ejson_lint/CHANGELOG.md | 0 .../packages => packages}/ejson_lint/LICENSE | 0 .../ejson_lint/README.md | 0 .../ejson_lint/analysis_options.yaml | 0 .../ejson_lint/dart_dependency_validator.yaml | 0 .../ejson_lint/example/.gitignore | 0 .../ejson_lint/example/CHANGELOG.md | 0 .../ejson_lint/example/README.md | 0 .../ejson_lint/example/analysis_options.yaml | 0 .../ejson_lint/example/bin/example.dart | 0 .../example/dart_dependency_validator.yaml | 0 .../ejson_lint/example/pubspec.yaml | 0 .../ejson_lint/lib/ejson_lint.dart | 0 .../ejson_lint/lib/src/ejson_lint_base.dart | 0 .../lib/src/lints/mismatched_getter_type.dart | 0 .../lib/src/lints/missing_getter.dart | 0 .../too_many_annotated_constructors.dart | 0 .../ejson_lint/pubspec.yaml | 0 .../ejson_lint/test/ejson_lint_test.dart | 0 ejson/pubspec.yaml => pubspec.yaml | 2 +- pubspec_overrides.yaml | 9 - 68 files changed, 1 insertion(+), 187 deletions(-) delete mode 100644 ejson/LICENSE rename ejson/melos.yaml => melos.yaml (100%) rename {ejson/packages => packages}/ejson/CHANGELOG.md (100%) rename {ejson/packages => packages}/ejson/LICENSE (100%) rename {ejson/packages => packages}/ejson/README.md (100%) rename {ejson/packages => packages}/ejson/analysis_options.yaml (100%) rename {ejson/packages => packages}/ejson/example/main.dart (100%) rename {ejson/packages => packages}/ejson/lib/ejson.dart (100%) rename {ejson/packages => packages}/ejson/lib/src/configuration.dart (100%) rename {ejson/packages => packages}/ejson/lib/src/decoding.dart (100%) rename {ejson/packages => packages}/ejson/lib/src/encoding.dart (100%) rename {ejson/packages => packages}/ejson/lib/src/types.dart (100%) rename {ejson/packages => packages}/ejson/pubspec.yaml (100%) rename {ejson/packages => packages}/ejson/test/ejson_serialization_setup.g.dart (100%) rename {ejson/packages => packages}/ejson/test/ejson_test.dart (100%) rename {ejson/packages => packages}/ejson/test/person.dart (100%) rename {ejson/packages => packages}/ejson/test/person.g.dart (100%) rename {ejson/packages => packages}/ejson_analyzer/.gitignore (100%) rename {ejson/packages => packages}/ejson_analyzer/CHANGELOG.md (100%) rename {ejson/packages => packages}/ejson_analyzer/LICENSE (100%) rename {ejson/packages => packages}/ejson_analyzer/README.md (100%) rename {ejson/packages => packages}/ejson_analyzer/analysis_options.yaml (100%) rename {ejson/packages => packages}/ejson_analyzer/lib/ejson_analyzer.dart (100%) rename {ejson/packages => packages}/ejson_analyzer/lib/src/ejson_analyzer_base.dart (100%) rename {ejson/packages => packages}/ejson_analyzer/pubspec.yaml (100%) rename {ejson/packages => packages}/ejson_analyzer/test/ejson_analyzer_test.dart (100%) rename {ejson/packages => packages}/ejson_annotation/.gitignore (100%) rename {ejson/packages => packages}/ejson_annotation/CHANGELOG.md (100%) rename {ejson/packages => packages}/ejson_annotation/LICENSE (100%) rename {ejson/packages => packages}/ejson_annotation/README.md (100%) rename {ejson/packages => packages}/ejson_annotation/analysis_options.yaml (100%) rename {ejson/packages => packages}/ejson_annotation/lib/ejson_annotation.dart (100%) rename {ejson/packages => packages}/ejson_annotation/pubspec.yaml (100%) rename {ejson/packages => packages}/ejson_generator/.gitignore (100%) rename {ejson/packages => packages}/ejson_generator/CHANGELOG.md (100%) rename {ejson/packages => packages}/ejson_generator/LICENSE (100%) rename {ejson/packages => packages}/ejson_generator/README.md (100%) rename {ejson/packages => packages}/ejson_generator/analysis_options.yaml (100%) rename {ejson/packages => packages}/ejson_generator/build.yaml (100%) rename {ejson/packages => packages}/ejson_generator/lib/ejson_generator.dart (100%) rename {ejson/packages => packages}/ejson_generator/lib/src/builder.dart (100%) rename {ejson/packages => packages}/ejson_generator/lib/src/generator.dart (100%) rename {ejson/packages => packages}/ejson_generator/pubspec.yaml (100%) rename {ejson/packages => packages}/ejson_generator/test/compile_test.dart (100%) rename {ejson/packages => packages}/ejson_generator/test/ctor_test.dart (100%) rename {ejson/packages => packages}/ejson_generator/test/ctor_test.g.dart (100%) rename {ejson/packages => packages}/ejson_lint/.gitignore (100%) rename {ejson/packages => packages}/ejson_lint/CHANGELOG.md (100%) rename {ejson/packages => packages}/ejson_lint/LICENSE (100%) rename {ejson/packages => packages}/ejson_lint/README.md (100%) rename {ejson/packages => packages}/ejson_lint/analysis_options.yaml (100%) rename {ejson/packages => packages}/ejson_lint/dart_dependency_validator.yaml (100%) rename {ejson/packages => packages}/ejson_lint/example/.gitignore (100%) rename {ejson/packages => packages}/ejson_lint/example/CHANGELOG.md (100%) rename {ejson/packages => packages}/ejson_lint/example/README.md (100%) rename {ejson/packages => packages}/ejson_lint/example/analysis_options.yaml (100%) rename {ejson/packages => packages}/ejson_lint/example/bin/example.dart (100%) rename {ejson/packages => packages}/ejson_lint/example/dart_dependency_validator.yaml (100%) rename {ejson/packages => packages}/ejson_lint/example/pubspec.yaml (100%) rename {ejson/packages => packages}/ejson_lint/lib/ejson_lint.dart (100%) rename {ejson/packages => packages}/ejson_lint/lib/src/ejson_lint_base.dart (100%) rename {ejson/packages => packages}/ejson_lint/lib/src/lints/mismatched_getter_type.dart (100%) rename {ejson/packages => packages}/ejson_lint/lib/src/lints/missing_getter.dart (100%) rename {ejson/packages => packages}/ejson_lint/lib/src/lints/too_many_annotated_constructors.dart (100%) rename {ejson/packages => packages}/ejson_lint/pubspec.yaml (100%) rename {ejson/packages => packages}/ejson_lint/test/ejson_lint_test.dart (100%) rename ejson/pubspec.yaml => pubspec.yaml (81%) delete mode 100644 pubspec_overrides.yaml diff --git a/ejson/LICENSE b/ejson/LICENSE deleted file mode 100644 index 66a27ec5f..000000000 --- a/ejson/LICENSE +++ /dev/null @@ -1,177 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - diff --git a/ejson/melos.yaml b/melos.yaml similarity index 100% rename from ejson/melos.yaml rename to melos.yaml diff --git a/ejson/packages/ejson/CHANGELOG.md b/packages/ejson/CHANGELOG.md similarity index 100% rename from ejson/packages/ejson/CHANGELOG.md rename to packages/ejson/CHANGELOG.md diff --git a/ejson/packages/ejson/LICENSE b/packages/ejson/LICENSE similarity index 100% rename from ejson/packages/ejson/LICENSE rename to packages/ejson/LICENSE diff --git a/ejson/packages/ejson/README.md b/packages/ejson/README.md similarity index 100% rename from ejson/packages/ejson/README.md rename to packages/ejson/README.md diff --git a/ejson/packages/ejson/analysis_options.yaml b/packages/ejson/analysis_options.yaml similarity index 100% rename from ejson/packages/ejson/analysis_options.yaml rename to packages/ejson/analysis_options.yaml diff --git a/ejson/packages/ejson/example/main.dart b/packages/ejson/example/main.dart similarity index 100% rename from ejson/packages/ejson/example/main.dart rename to packages/ejson/example/main.dart diff --git a/ejson/packages/ejson/lib/ejson.dart b/packages/ejson/lib/ejson.dart similarity index 100% rename from ejson/packages/ejson/lib/ejson.dart rename to packages/ejson/lib/ejson.dart diff --git a/ejson/packages/ejson/lib/src/configuration.dart b/packages/ejson/lib/src/configuration.dart similarity index 100% rename from ejson/packages/ejson/lib/src/configuration.dart rename to packages/ejson/lib/src/configuration.dart diff --git a/ejson/packages/ejson/lib/src/decoding.dart b/packages/ejson/lib/src/decoding.dart similarity index 100% rename from ejson/packages/ejson/lib/src/decoding.dart rename to packages/ejson/lib/src/decoding.dart diff --git a/ejson/packages/ejson/lib/src/encoding.dart b/packages/ejson/lib/src/encoding.dart similarity index 100% rename from ejson/packages/ejson/lib/src/encoding.dart rename to packages/ejson/lib/src/encoding.dart diff --git a/ejson/packages/ejson/lib/src/types.dart b/packages/ejson/lib/src/types.dart similarity index 100% rename from ejson/packages/ejson/lib/src/types.dart rename to packages/ejson/lib/src/types.dart diff --git a/ejson/packages/ejson/pubspec.yaml b/packages/ejson/pubspec.yaml similarity index 100% rename from ejson/packages/ejson/pubspec.yaml rename to packages/ejson/pubspec.yaml diff --git a/ejson/packages/ejson/test/ejson_serialization_setup.g.dart b/packages/ejson/test/ejson_serialization_setup.g.dart similarity index 100% rename from ejson/packages/ejson/test/ejson_serialization_setup.g.dart rename to packages/ejson/test/ejson_serialization_setup.g.dart diff --git a/ejson/packages/ejson/test/ejson_test.dart b/packages/ejson/test/ejson_test.dart similarity index 100% rename from ejson/packages/ejson/test/ejson_test.dart rename to packages/ejson/test/ejson_test.dart diff --git a/ejson/packages/ejson/test/person.dart b/packages/ejson/test/person.dart similarity index 100% rename from ejson/packages/ejson/test/person.dart rename to packages/ejson/test/person.dart diff --git a/ejson/packages/ejson/test/person.g.dart b/packages/ejson/test/person.g.dart similarity index 100% rename from ejson/packages/ejson/test/person.g.dart rename to packages/ejson/test/person.g.dart diff --git a/ejson/packages/ejson_analyzer/.gitignore b/packages/ejson_analyzer/.gitignore similarity index 100% rename from ejson/packages/ejson_analyzer/.gitignore rename to packages/ejson_analyzer/.gitignore diff --git a/ejson/packages/ejson_analyzer/CHANGELOG.md b/packages/ejson_analyzer/CHANGELOG.md similarity index 100% rename from ejson/packages/ejson_analyzer/CHANGELOG.md rename to packages/ejson_analyzer/CHANGELOG.md diff --git a/ejson/packages/ejson_analyzer/LICENSE b/packages/ejson_analyzer/LICENSE similarity index 100% rename from ejson/packages/ejson_analyzer/LICENSE rename to packages/ejson_analyzer/LICENSE diff --git a/ejson/packages/ejson_analyzer/README.md b/packages/ejson_analyzer/README.md similarity index 100% rename from ejson/packages/ejson_analyzer/README.md rename to packages/ejson_analyzer/README.md diff --git a/ejson/packages/ejson_analyzer/analysis_options.yaml b/packages/ejson_analyzer/analysis_options.yaml similarity index 100% rename from ejson/packages/ejson_analyzer/analysis_options.yaml rename to packages/ejson_analyzer/analysis_options.yaml diff --git a/ejson/packages/ejson_analyzer/lib/ejson_analyzer.dart b/packages/ejson_analyzer/lib/ejson_analyzer.dart similarity index 100% rename from ejson/packages/ejson_analyzer/lib/ejson_analyzer.dart rename to packages/ejson_analyzer/lib/ejson_analyzer.dart diff --git a/ejson/packages/ejson_analyzer/lib/src/ejson_analyzer_base.dart b/packages/ejson_analyzer/lib/src/ejson_analyzer_base.dart similarity index 100% rename from ejson/packages/ejson_analyzer/lib/src/ejson_analyzer_base.dart rename to packages/ejson_analyzer/lib/src/ejson_analyzer_base.dart diff --git a/ejson/packages/ejson_analyzer/pubspec.yaml b/packages/ejson_analyzer/pubspec.yaml similarity index 100% rename from ejson/packages/ejson_analyzer/pubspec.yaml rename to packages/ejson_analyzer/pubspec.yaml diff --git a/ejson/packages/ejson_analyzer/test/ejson_analyzer_test.dart b/packages/ejson_analyzer/test/ejson_analyzer_test.dart similarity index 100% rename from ejson/packages/ejson_analyzer/test/ejson_analyzer_test.dart rename to packages/ejson_analyzer/test/ejson_analyzer_test.dart diff --git a/ejson/packages/ejson_annotation/.gitignore b/packages/ejson_annotation/.gitignore similarity index 100% rename from ejson/packages/ejson_annotation/.gitignore rename to packages/ejson_annotation/.gitignore diff --git a/ejson/packages/ejson_annotation/CHANGELOG.md b/packages/ejson_annotation/CHANGELOG.md similarity index 100% rename from ejson/packages/ejson_annotation/CHANGELOG.md rename to packages/ejson_annotation/CHANGELOG.md diff --git a/ejson/packages/ejson_annotation/LICENSE b/packages/ejson_annotation/LICENSE similarity index 100% rename from ejson/packages/ejson_annotation/LICENSE rename to packages/ejson_annotation/LICENSE diff --git a/ejson/packages/ejson_annotation/README.md b/packages/ejson_annotation/README.md similarity index 100% rename from ejson/packages/ejson_annotation/README.md rename to packages/ejson_annotation/README.md diff --git a/ejson/packages/ejson_annotation/analysis_options.yaml b/packages/ejson_annotation/analysis_options.yaml similarity index 100% rename from ejson/packages/ejson_annotation/analysis_options.yaml rename to packages/ejson_annotation/analysis_options.yaml diff --git a/ejson/packages/ejson_annotation/lib/ejson_annotation.dart b/packages/ejson_annotation/lib/ejson_annotation.dart similarity index 100% rename from ejson/packages/ejson_annotation/lib/ejson_annotation.dart rename to packages/ejson_annotation/lib/ejson_annotation.dart diff --git a/ejson/packages/ejson_annotation/pubspec.yaml b/packages/ejson_annotation/pubspec.yaml similarity index 100% rename from ejson/packages/ejson_annotation/pubspec.yaml rename to packages/ejson_annotation/pubspec.yaml diff --git a/ejson/packages/ejson_generator/.gitignore b/packages/ejson_generator/.gitignore similarity index 100% rename from ejson/packages/ejson_generator/.gitignore rename to packages/ejson_generator/.gitignore diff --git a/ejson/packages/ejson_generator/CHANGELOG.md b/packages/ejson_generator/CHANGELOG.md similarity index 100% rename from ejson/packages/ejson_generator/CHANGELOG.md rename to packages/ejson_generator/CHANGELOG.md diff --git a/ejson/packages/ejson_generator/LICENSE b/packages/ejson_generator/LICENSE similarity index 100% rename from ejson/packages/ejson_generator/LICENSE rename to packages/ejson_generator/LICENSE diff --git a/ejson/packages/ejson_generator/README.md b/packages/ejson_generator/README.md similarity index 100% rename from ejson/packages/ejson_generator/README.md rename to packages/ejson_generator/README.md diff --git a/ejson/packages/ejson_generator/analysis_options.yaml b/packages/ejson_generator/analysis_options.yaml similarity index 100% rename from ejson/packages/ejson_generator/analysis_options.yaml rename to packages/ejson_generator/analysis_options.yaml diff --git a/ejson/packages/ejson_generator/build.yaml b/packages/ejson_generator/build.yaml similarity index 100% rename from ejson/packages/ejson_generator/build.yaml rename to packages/ejson_generator/build.yaml diff --git a/ejson/packages/ejson_generator/lib/ejson_generator.dart b/packages/ejson_generator/lib/ejson_generator.dart similarity index 100% rename from ejson/packages/ejson_generator/lib/ejson_generator.dart rename to packages/ejson_generator/lib/ejson_generator.dart diff --git a/ejson/packages/ejson_generator/lib/src/builder.dart b/packages/ejson_generator/lib/src/builder.dart similarity index 100% rename from ejson/packages/ejson_generator/lib/src/builder.dart rename to packages/ejson_generator/lib/src/builder.dart diff --git a/ejson/packages/ejson_generator/lib/src/generator.dart b/packages/ejson_generator/lib/src/generator.dart similarity index 100% rename from ejson/packages/ejson_generator/lib/src/generator.dart rename to packages/ejson_generator/lib/src/generator.dart diff --git a/ejson/packages/ejson_generator/pubspec.yaml b/packages/ejson_generator/pubspec.yaml similarity index 100% rename from ejson/packages/ejson_generator/pubspec.yaml rename to packages/ejson_generator/pubspec.yaml diff --git a/ejson/packages/ejson_generator/test/compile_test.dart b/packages/ejson_generator/test/compile_test.dart similarity index 100% rename from ejson/packages/ejson_generator/test/compile_test.dart rename to packages/ejson_generator/test/compile_test.dart diff --git a/ejson/packages/ejson_generator/test/ctor_test.dart b/packages/ejson_generator/test/ctor_test.dart similarity index 100% rename from ejson/packages/ejson_generator/test/ctor_test.dart rename to packages/ejson_generator/test/ctor_test.dart diff --git a/ejson/packages/ejson_generator/test/ctor_test.g.dart b/packages/ejson_generator/test/ctor_test.g.dart similarity index 100% rename from ejson/packages/ejson_generator/test/ctor_test.g.dart rename to packages/ejson_generator/test/ctor_test.g.dart diff --git a/ejson/packages/ejson_lint/.gitignore b/packages/ejson_lint/.gitignore similarity index 100% rename from ejson/packages/ejson_lint/.gitignore rename to packages/ejson_lint/.gitignore diff --git a/ejson/packages/ejson_lint/CHANGELOG.md b/packages/ejson_lint/CHANGELOG.md similarity index 100% rename from ejson/packages/ejson_lint/CHANGELOG.md rename to packages/ejson_lint/CHANGELOG.md diff --git a/ejson/packages/ejson_lint/LICENSE b/packages/ejson_lint/LICENSE similarity index 100% rename from ejson/packages/ejson_lint/LICENSE rename to packages/ejson_lint/LICENSE diff --git a/ejson/packages/ejson_lint/README.md b/packages/ejson_lint/README.md similarity index 100% rename from ejson/packages/ejson_lint/README.md rename to packages/ejson_lint/README.md diff --git a/ejson/packages/ejson_lint/analysis_options.yaml b/packages/ejson_lint/analysis_options.yaml similarity index 100% rename from ejson/packages/ejson_lint/analysis_options.yaml rename to packages/ejson_lint/analysis_options.yaml diff --git a/ejson/packages/ejson_lint/dart_dependency_validator.yaml b/packages/ejson_lint/dart_dependency_validator.yaml similarity index 100% rename from ejson/packages/ejson_lint/dart_dependency_validator.yaml rename to packages/ejson_lint/dart_dependency_validator.yaml diff --git a/ejson/packages/ejson_lint/example/.gitignore b/packages/ejson_lint/example/.gitignore similarity index 100% rename from ejson/packages/ejson_lint/example/.gitignore rename to packages/ejson_lint/example/.gitignore diff --git a/ejson/packages/ejson_lint/example/CHANGELOG.md b/packages/ejson_lint/example/CHANGELOG.md similarity index 100% rename from ejson/packages/ejson_lint/example/CHANGELOG.md rename to packages/ejson_lint/example/CHANGELOG.md diff --git a/ejson/packages/ejson_lint/example/README.md b/packages/ejson_lint/example/README.md similarity index 100% rename from ejson/packages/ejson_lint/example/README.md rename to packages/ejson_lint/example/README.md diff --git a/ejson/packages/ejson_lint/example/analysis_options.yaml b/packages/ejson_lint/example/analysis_options.yaml similarity index 100% rename from ejson/packages/ejson_lint/example/analysis_options.yaml rename to packages/ejson_lint/example/analysis_options.yaml diff --git a/ejson/packages/ejson_lint/example/bin/example.dart b/packages/ejson_lint/example/bin/example.dart similarity index 100% rename from ejson/packages/ejson_lint/example/bin/example.dart rename to packages/ejson_lint/example/bin/example.dart diff --git a/ejson/packages/ejson_lint/example/dart_dependency_validator.yaml b/packages/ejson_lint/example/dart_dependency_validator.yaml similarity index 100% rename from ejson/packages/ejson_lint/example/dart_dependency_validator.yaml rename to packages/ejson_lint/example/dart_dependency_validator.yaml diff --git a/ejson/packages/ejson_lint/example/pubspec.yaml b/packages/ejson_lint/example/pubspec.yaml similarity index 100% rename from ejson/packages/ejson_lint/example/pubspec.yaml rename to packages/ejson_lint/example/pubspec.yaml diff --git a/ejson/packages/ejson_lint/lib/ejson_lint.dart b/packages/ejson_lint/lib/ejson_lint.dart similarity index 100% rename from ejson/packages/ejson_lint/lib/ejson_lint.dart rename to packages/ejson_lint/lib/ejson_lint.dart diff --git a/ejson/packages/ejson_lint/lib/src/ejson_lint_base.dart b/packages/ejson_lint/lib/src/ejson_lint_base.dart similarity index 100% rename from ejson/packages/ejson_lint/lib/src/ejson_lint_base.dart rename to packages/ejson_lint/lib/src/ejson_lint_base.dart diff --git a/ejson/packages/ejson_lint/lib/src/lints/mismatched_getter_type.dart b/packages/ejson_lint/lib/src/lints/mismatched_getter_type.dart similarity index 100% rename from ejson/packages/ejson_lint/lib/src/lints/mismatched_getter_type.dart rename to packages/ejson_lint/lib/src/lints/mismatched_getter_type.dart diff --git a/ejson/packages/ejson_lint/lib/src/lints/missing_getter.dart b/packages/ejson_lint/lib/src/lints/missing_getter.dart similarity index 100% rename from ejson/packages/ejson_lint/lib/src/lints/missing_getter.dart rename to packages/ejson_lint/lib/src/lints/missing_getter.dart diff --git a/ejson/packages/ejson_lint/lib/src/lints/too_many_annotated_constructors.dart b/packages/ejson_lint/lib/src/lints/too_many_annotated_constructors.dart similarity index 100% rename from ejson/packages/ejson_lint/lib/src/lints/too_many_annotated_constructors.dart rename to packages/ejson_lint/lib/src/lints/too_many_annotated_constructors.dart diff --git a/ejson/packages/ejson_lint/pubspec.yaml b/packages/ejson_lint/pubspec.yaml similarity index 100% rename from ejson/packages/ejson_lint/pubspec.yaml rename to packages/ejson_lint/pubspec.yaml diff --git a/ejson/packages/ejson_lint/test/ejson_lint_test.dart b/packages/ejson_lint/test/ejson_lint_test.dart similarity index 100% rename from ejson/packages/ejson_lint/test/ejson_lint_test.dart rename to packages/ejson_lint/test/ejson_lint_test.dart diff --git a/ejson/pubspec.yaml b/pubspec.yaml similarity index 81% rename from ejson/pubspec.yaml rename to pubspec.yaml index 5afa1c141..750e9fc55 100644 --- a/ejson/pubspec.yaml +++ b/pubspec.yaml @@ -4,4 +4,4 @@ environment: sdk: ^3.0.2 dev_dependencies: - melos: ^3.1.0 + melos: ^4.1.0 diff --git a/pubspec_overrides.yaml b/pubspec_overrides.yaml deleted file mode 100644 index 3ed2e09ab..000000000 --- a/pubspec_overrides.yaml +++ /dev/null @@ -1,9 +0,0 @@ -dependency_overrides: - ejson: - path: ./ejson/packages/ejson - ejson_annotation: - path: ./ejson/packages/ejson_annotation - ejson_generator: - path: ./ejson/packages/ejson_generator - ejson_analyzer: - path: ./ejson/packages/ejson_analyzer \ No newline at end of file From 9819632383a3aed3dfc4a5325c6a7fd5787c3bee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Thu, 1 Feb 2024 15:26:47 +0100 Subject: [PATCH 043/153] Avoid path deps in public packages and remove publish_to: --- packages/realm/example/pubspec.yaml | 15 +-------------- packages/realm/pubspec.yaml | 5 +---- packages/realm_common/pubspec.yaml | 4 +--- packages/realm_dart/pubspec.yaml | 8 ++------ packages/realm_generator/pubspec.yaml | 5 +---- 5 files changed, 6 insertions(+), 31 deletions(-) diff --git a/packages/realm/example/pubspec.yaml b/packages/realm/example/pubspec.yaml index 768d677ec..91c108ca3 100644 --- a/packages/realm/example/pubspec.yaml +++ b/packages/realm/example/pubspec.yaml @@ -2,8 +2,6 @@ name: realm_example description: Demonstrates how to use the Realm SDK for Flutter. version: 2.0.0-alpha.2 -# The following line prevents the package from being accidentally published to -# pub.dev using `pub publish`. This is preferred for private packages. publish_to: "none" environment: @@ -13,21 +11,10 @@ environment: dependencies: flutter: sdk: flutter - - realm: - # When depending on this package from a real application you should use: - # realm: ^x.y.z - # See https://dart.dev/tools/pub/dependencies#version-constraints - # The example app is bundled with the plugin so we use a path dependency on - # the parent directory to use the current plugin's version. - path: ../ - - cupertino_icons: ^1.0.3 + realm: ^1.8.0 characters: ^1.1.0 dev_dependencies: - flutter_test: - sdk: flutter flutter_lints: ^3.0.1 flutter: diff --git a/packages/realm/pubspec.yaml b/packages/realm/pubspec.yaml index c4d482d81..94a0c200f 100644 --- a/packages/realm/pubspec.yaml +++ b/packages/realm/pubspec.yaml @@ -6,8 +6,6 @@ homepage: https://www.realm.io repository: https://github.com/realm/realm-dart issue_tracker: https://github.com/realm/realm-dart/issues -publish_to: none - environment: sdk: ^3.0.0 flutter: ^3.10.0 @@ -15,8 +13,7 @@ environment: dependencies: flutter: sdk: flutter - realm_dart: - path: ../realm_dart + realm_dart: ^1.8.0 flutter: plugin: diff --git a/packages/realm_common/pubspec.yaml b/packages/realm_common/pubspec.yaml index f0988e752..14fe66c46 100644 --- a/packages/realm_common/pubspec.yaml +++ b/packages/realm_common/pubspec.yaml @@ -9,15 +9,13 @@ homepage: https://www.realm.io repository: https://github.com/realm/realm-dart issue_tracker: https://github.com/realm/realm-dart/issues -publish_to: none - environment: sdk: ^3.0.0 dependencies: collection: ^1.18.0 objectid: ^3.0.0 - sane_uuid: ^1.0.0-alpha.4 + sane_uuid: ^1.0.0-alpha.5 dev_dependencies: lints: ^3.0.0 diff --git a/packages/realm_dart/pubspec.yaml b/packages/realm_dart/pubspec.yaml index a1360aa1f..a5b2c869b 100644 --- a/packages/realm_dart/pubspec.yaml +++ b/packages/realm_dart/pubspec.yaml @@ -6,8 +6,6 @@ homepage: https://www.realm.io repository: https://github.com/realm/realm-dart issue_tracker: https://github.com/realm/realm-dart/issues -publish_to: none - environment: sdk: ^3.0.0 @@ -26,10 +24,8 @@ dependencies: path: ^1.0.0 pubspec_parse: ^1.0.0 pub_semver: ^2.1.0 - realm_common: - path: ../realm_common - realm_generator: - path: ../realm_generator + realm_common: ^1.8.0 + realm_generator: ^1.8.0 tar: ^1.0.1 build_runner: ^2.1.0 http: ^1.0.0 diff --git a/packages/realm_generator/pubspec.yaml b/packages/realm_generator/pubspec.yaml index 57f0f578f..71fc05291 100644 --- a/packages/realm_generator/pubspec.yaml +++ b/packages/realm_generator/pubspec.yaml @@ -9,8 +9,6 @@ homepage: https://www.realm.io repository: https://github.com/realm/realm-dart issue_tracker: https://github.com/realm/realm-dart/issues -publish_to: none - environment: sdk: ^3.0.0 @@ -19,8 +17,7 @@ dependencies: build_resolvers: ^2.0.9 build: ^2.0.0 dart_style: ^2.2.0 - realm_common: - path: ../realm_common + realm_common: ^1.8.0 source_gen: ^1.1.0 source_span: ^1.8.0 From 55d54105b4d797726ce3c37529d3cc42db1e1855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 31 Jan 2024 10:39:27 +0100 Subject: [PATCH 044/153] Add melos support --- melos.yaml | 221 ++++++++++++++++++++++++++++++++++----------------- pubspec.yaml | 6 +- 2 files changed, 150 insertions(+), 77 deletions(-) diff --git a/melos.yaml b/melos.yaml index 09e945ef5..7370ff91b 100644 --- a/melos.yaml +++ b/melos.yaml @@ -1,105 +1,178 @@ -name: ejson +name: realm-dart + +repository: https://github.com/realm/realm-dart + +ide: + intellij: # no one uses android studio right? + enabled: false packages: - packages/* - packages/*/example - - -ide: - intellij: false + - packages/*/tests command: bootstrap: + environment: + sdk: ^3.0.0 + flutter: ^3.10.0 + hooks: + pre: >- + git submodule update --init --recursive && + dart pub global activate combine_coverage && + dart pub global activate coverage && + dart pub global activate coverde && + dart pub global activate dependency_validator && + dart pub global activate ffigen && + dart pub global activate melos && + dart pub global activate pana + clean: hooks: - post: melos run setup + pre: melos exec --flutter -- flutter clean scripts: - setup: + build: run: >- - dart pub global activate coverage && - dart pub global activate coverde && - dart pub global activate dependency_validator && - dart pub global activate pana + melos run build:native && + melos run build:binding && + melos run build:dart + + build:native: # TODO: mac specific and too simple + exec: >- + cmake --preset $PLATFORM && + cmake --build --preset $PLATFORM --config MinSizeRel -- -destination "generic/platform=macOS" + packageFilters: + dirExists: src # by convention + + build:dart: + run: dart run build_runner build --delete-conflicting-outputs + exec: + orderDependents: true + packageFilters: + dependsOn: build_runner - qa: - description: Run QA scripts. + build:binding: + exec: dart pub global run ffigen --config ffigen.yaml + packageFilters: + fileExists: ffigen.yaml # by convention + + test: + description: Run all tests. run: >- - melos run format:check && - melos run analyze && - melos run analyze:deps && + melos run test:unit && + melos run test:widget && melos run test:lints && - melos run coverage + melos run test:integration - qa:full: - description: Run all QA scripts (including expensive ones). + test:unit: run: >- - melos run qa && - melos run pana && - melos publish --dry-run - - format: - description: Format Dart code. - run: dart format . + dart test --concurrency=1 --coverage=coverage/ && + dart pub global run coverage:format_coverage + --in=coverage/test/ + --out=coverage/lcov.info + --lcov + exec: + concurrency: 1 # only one project at a time to keep output sane + packageFilters: + dependsOn: test + dirExists: test/ + flutter: false - format:check: - description: Check formatting of Dart code. - run: dart format --output none --set-exit-if-changed . + test:widget: + run: flutter test --concurrency=1 --coverage + exec: + concurrency: 1 # only one project at a time to keep output sane + packageFilters: + dependsOn: flutter_test + noDependsOn: integration_test # integration tests are run separately + dirExists: test/ + flutter: true - analyze: - description: Analyze Dart code. - run: dart analyze . --fatal-infos - - analyze:deps: - description: Analyze dependencies. - exec: dart pub global run dependency_validator + test:lints: + run: dart run custom_lint + exec: + concurrency: 1 # only one project at a time to keep output sane + packageFilters: + dependsOn: custom_lint - test: - description: Run tests. - run: dart test -j1 --chain-stack-traces + test:integration: + run: >- + flutter test integration_test/all_tests.dart + --coverage + --dart-define=BAAS_URL='$BAAS_URL' + --dart-define=BAAS_DIFFERENTIATOR='$BAAS_DIFFERENTIATOR' + --device-id='$DEVICE_ID' + --file-reporter=json:test-results.json + --suppress-analytics exec: - concurrency: 1 + concurrency: 1 # only one project at a time to keep output sane packageFilters: - dirExists: - - test + dependsOn: integration_test + fileExists: integration_test/all_tests.dart + flutter: true - test:lints: - description: Test that custom lints are working. - run: melos exec --depends-on=custom_lint -c1 -- dart run custom_lint + doc: + description: Generate documentation. + exec: dart doc --validate-links + packageFilters: + published: true - coverage: - description: Generate, format, and check coverage. + format: + description: Format code. + run: dart format --fix --line-length 160 . + + lint: + description: Run all lints. run: >- - melos run coverage:generate && - melos run coverage:format && - melos run coverage:check - - coverage:generate: - description: Generate coverage. - run: dart test -j1 --chain-stack-traces --coverage=coverage - # The following command is not working with coverage:format - # run: dart pub global run coverage:test_with_coverage --branch-coverage + melos run lint:format && + melos run lint:pana && + melos publish --dry-run + + lint:format: + run: dart format --fix --line-length 160 --output none --set-exit-if-changed . + exec: + concurrency: 1 # only one project at a time to keep output sane$ + + lint:pana: + run: dart pub global run pana --no-warning --exit-code-threshold 40 . exec: - concurrency: 1 + concurrency: 1 # only one project at a time to keep output sane$ packageFilters: - dirExists: - - test + published: true - coverage:format: - description: Format coverage. + analyze: + description: Analyze code and dependencies. run: >- - dart pub global run coverage:format_coverage - --in=. - --report-on=$MELOS_ROOT_PATH - --lcov --out=lcov.info + melos run analyze:code && + melos run analyze:deps + + analyze:code: + exec: dart analyze . --fatal-infos + + analyze:deps: + exec: dart pub global run dependency_validator + + coverage: + description: Generate, check and render coverage. + run: >- + melos run test && + melos run coverage:check && + melos run coverage:report coverage:check: - description: Check coverage. - run: dart pub global run coverde check 90 --input=lcov.info - - pana: - description: Run pana on all packages. - run: dart pub global run pana --no-warning --exit-code-threshold 40 --source path . + run: dart pub global run coverde check 90 exec: - concurrency: 1 - packageFilters: - public: true \ No newline at end of file + fileExists: coverage/lcov.info # by convention + + coverage:report: + run: dart pub global run coverde report + + ci: + run: >- + melos clean && + melos bootstrap && + melos run build && + melos run test && + melos run lint && + melos run analyze && + melos run coverage diff --git a/pubspec.yaml b/pubspec.yaml index 750e9fc55..23e781959 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ -name: ejson_workspace +name: my_project_workspace environment: - sdk: ^3.0.2 - + sdk: '>=3.0.0 <4.0.0' dev_dependencies: melos: ^4.1.0 + From 39711b2cefc7b5e3ed846fde3e0e159c4d15604e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Mon, 5 Feb 2024 12:12:46 +0100 Subject: [PATCH 045/153] Add lints package on bootstrap Ensure lints is added to all packages during bootstrap, if missing --- melos.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/melos.yaml b/melos.yaml index 7370ff91b..ec0332e65 100644 --- a/melos.yaml +++ b/melos.yaml @@ -16,6 +16,8 @@ command: environment: sdk: ^3.0.0 flutter: ^3.10.0 + dev_dependencies: + lints: ^3.0.0 hooks: pre: >- git submodule update --init --recursive && From e59883dabc7650593b0dd6afb0d2cb879c4222fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 6 Feb 2024 20:12:43 +0100 Subject: [PATCH 046/153] Simplify CI a bit with melos --- .github/workflows/ci.yml | 10 ++++++++++ .github/workflows/dart-desktop-tests.yml | 5 +++++ .github/workflows/flutter-desktop-tests.yml | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9b3394093..0b5d0b29b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -312,6 +312,11 @@ jobs: with: channel: 'stable' + - name: Setup Melos + run: | + dart pub global activate melos + dart pub global run melos bootstrap + - name: Install dependencies run: dart pub get @@ -403,6 +408,11 @@ jobs: with: channel: 'stable' + - name: Setup Melos + run: | + dart pub global activate melos + dart pub global run melos bootstrap + - name: Install dependencies run: dart pub get diff --git a/.github/workflows/dart-desktop-tests.yml b/.github/workflows/dart-desktop-tests.yml index ce5db6900..f4ea75e03 100644 --- a/.github/workflows/dart-desktop-tests.yml +++ b/.github/workflows/dart-desktop-tests.yml @@ -55,6 +55,11 @@ jobs: sdk: stable architecture: ${{ inputs.architecture == 'arm' && 'arm64' || 'x64'}} + - name: Setup Melos + run: | + dart pub global activate melos + dart pub global run melos bootstrap --no-flutter + - name: Install dependencies run: dart pub get diff --git a/.github/workflows/flutter-desktop-tests.yml b/.github/workflows/flutter-desktop-tests.yml index d8fc0cf36..dd28a4a45 100644 --- a/.github/workflows/flutter-desktop-tests.yml +++ b/.github/workflows/flutter-desktop-tests.yml @@ -67,6 +67,11 @@ jobs: - name: Enable Flutter Desktop support run: flutter config --enable-${{ inputs.os }}-desktop + - name: Setup Melos + run: | + dart pub global activate melos + dart pub global run melos bootstrap + - name: Install dependencies run: dart pub get From 663cfd66c0764b94f46546750cde5c0b6f67ec23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 7 Feb 2024 09:23:52 +0100 Subject: [PATCH 047/153] Update root .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a4ce7437c..d8da95775 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,4 @@ test-results.json **/coverage/ # dos -**/doc/ \ No newline at end of file +**/doc/api/ \ No newline at end of file From 2bb3b7f5a8740181902dfa0da0d97e1671c1c76b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 7 Feb 2024 10:27:09 +0100 Subject: [PATCH 048/153] build_native.dart (wip) --- .vscode/settings.json | 2 + packages/realm_dart/tool/build_native.dart | 87 ++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 packages/realm_dart/tool/build_native.dart diff --git a/.vscode/settings.json b/.vscode/settings.json index 8629f816a..4db4b006d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "cSpell.words": [ "apikey", "apikeys", + "armeabi", "backlinks", "BEGINSWITH", "bson", @@ -29,6 +30,7 @@ "nodoc", "nullptr", "posix", + "riscv", "sublist", "sublists", "TRUEPREDICATE", diff --git a/packages/realm_dart/tool/build_native.dart b/packages/realm_dart/tool/build_native.dart new file mode 100644 index 000000000..704e4b68e --- /dev/null +++ b/packages/realm_dart/tool/build_native.dart @@ -0,0 +1,87 @@ +import 'dart:io' as io; +import 'package:args/args.dart'; +import 'package:collection/collection.dart'; + +extension on Iterable { + T firstEqualIgnoreCase(String value) => firstWhere((e) => compareAsciiLowerCase(e.name, value) == 0); + Iterable get names => map((e) => e.name); +} + +enum Architecture { + arm('armeabi-v7a'), + arm64('arm64-v8a'), + ia32('x86'), + riscv32, + riscv64, + x64('x86_64'), + ; + + final String? _cmakeName; + String get cmakeName => _cmakeName ?? name; + + const Architecture([this._cmakeName]); + + static Architecture from(String name) => Architecture.values.firstEqualIgnoreCase(name); +} + +enum OS { + android, + ios, + macos, + windows, + linux, + ; + + static OS from(String name) => OS.values.firstEqualIgnoreCase(name); +} + +// Currently supported targets +enum Target { + androidArm, + androidArm64, + androidIA32, + androidX64, + // androidRiscv64, // not supported by realm currently + // fuchsiaArm64, // -"- etc. + // fuchsiaX64, + iOSArm, + iOSArm64, + // iOSX64, + // linuxArm, + // linuxArm64, + // linuxIA32, + // linuxRiscv32, + // linuxRiscv64, + linuxX64, + macOSArm64, + macOSX64, + // windowsArm64, + // windowsIA32, + windowsX64, + ; + + static Target from(String name) => Target.values.firstEqualIgnoreCase(name); +} + +enum BuildMode { + debug, + release, + ; + + static BuildMode from(String name) => BuildMode.values.firstWhere((e) => e.name == name); +} + +void main(List arguments) { + final parser = ArgParser() + ..addOption('target', abbr: 't', allowed: Target.values.names) + ..addOption('mode', abbr: 'm', allowed: BuildMode.values.names) + ..addOption('arch', abbr: 'a', allowed: Architecture.values.names); + + final argResults = parser.parse(arguments); + + final hostOS = OS.from(io.Platform.operatingSystem); + final targetOs = OS.from(argResults['target']); + final buildMode = BuildMode.from(argResults['mode']); + + print(io.Platform.operatingSystem); +} From 60e0d273dd14ef785e084eee32161f8e26e010d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 7 Feb 2024 17:05:12 +0100 Subject: [PATCH 049/153] Split bootstrap pre-hook into separate setup script (for speed when setup not needed) --- .github/workflows/publish-release.yml | 5 +++++ melos.yaml | 22 ++++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 1d505fc78..2c71b2203 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -35,6 +35,11 @@ jobs: with: channel: 'stable' + - name: Setup Melos + run: | + dart pub global activate melos + dart pub global run melos bootstrap + - name: Download all artifacts uses: dawidd6/action-download-artifact@d0f291cf39bd21965ea9c4c6e210fc355c3844ed with: diff --git a/melos.yaml b/melos.yaml index ec0332e65..145fbbb1f 100644 --- a/melos.yaml +++ b/melos.yaml @@ -18,21 +18,23 @@ command: flutter: ^3.10.0 dev_dependencies: lints: ^3.0.0 - hooks: - pre: >- - git submodule update --init --recursive && - dart pub global activate combine_coverage && - dart pub global activate coverage && - dart pub global activate coverde && - dart pub global activate dependency_validator && - dart pub global activate ffigen && - dart pub global activate melos && - dart pub global activate pana + clean: hooks: pre: melos exec --flutter -- flutter clean scripts: + setup: + run: >- + git submodule update --init --recursive && + dart pub global activate combine_coverage && + dart pub global activate coverage && + dart pub global activate coverde && + dart pub global activate dependency_validator && + dart pub global activate ffigen && + dart pub global activate melos && + dart pub global activate pana + build: run: >- melos run build:native && From b440f7650bc3858765a11102d2616b0ca740a794 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Mon, 19 Feb 2024 16:03:44 +0100 Subject: [PATCH 050/153] Align SDK requirement (handled by melos bootstrap) --- packages/ejson/pubspec.yaml | 2 +- packages/ejson_analyzer/pubspec.yaml | 2 +- packages/ejson_annotation/pubspec.yaml | 2 +- packages/ejson_generator/pubspec.yaml | 2 +- packages/ejson_lint/example/pubspec.yaml | 4 ++-- packages/ejson_lint/pubspec.yaml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/ejson/pubspec.yaml b/packages/ejson/pubspec.yaml index 1387b25a4..3e787616c 100644 --- a/packages/ejson/pubspec.yaml +++ b/packages/ejson/pubspec.yaml @@ -16,7 +16,7 @@ version: 0.1.0 repository: https://github.com/realm/realm-dart/ejson/packages/ejson environment: - sdk: ^3.0.1 + sdk: ^3.0.0 dependencies: collection: ^1.17.0 diff --git a/packages/ejson_analyzer/pubspec.yaml b/packages/ejson_analyzer/pubspec.yaml index 86403129f..ce68df435 100644 --- a/packages/ejson_analyzer/pubspec.yaml +++ b/packages/ejson_analyzer/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 repository: https://github.com/realm/realm-dart/ejson/packages/ejson_analyzer environment: - sdk: ^3.0.2 + sdk: ^3.0.0 dependencies: analyzer: ^6.0.0 diff --git a/packages/ejson_annotation/pubspec.yaml b/packages/ejson_annotation/pubspec.yaml index e2fbae9b0..d316dd0ce 100644 --- a/packages/ejson_annotation/pubspec.yaml +++ b/packages/ejson_annotation/pubspec.yaml @@ -9,7 +9,7 @@ version: 0.1.0 repository: https://github.com/realm/realm-dart/ejson/packages/ejson_annotation environment: - sdk: ^3.0.2 + sdk: ^3.0.0 dev_dependencies: lints: ^3.0.0 diff --git a/packages/ejson_generator/pubspec.yaml b/packages/ejson_generator/pubspec.yaml index 1975cb65b..1119728eb 100644 --- a/packages/ejson_generator/pubspec.yaml +++ b/packages/ejson_generator/pubspec.yaml @@ -16,7 +16,7 @@ version: 0.1.0 repository: https://github.com/realm/realm-dart/ejson/packages/ejson_generator environment: - sdk: ^3.0.1 + sdk: ^3.0.0 dependencies: analyzer: ^6.0.0 diff --git a/packages/ejson_lint/example/pubspec.yaml b/packages/ejson_lint/example/pubspec.yaml index b3472daaf..d867df5fa 100644 --- a/packages/ejson_lint/example/pubspec.yaml +++ b/packages/ejson_lint/example/pubspec.yaml @@ -5,7 +5,7 @@ version: 1.0.0 publish_to: none environment: - sdk: ^3.0.3 + sdk: ^3.0.0 dependencies: ejson_annotation: ^0.1.0 @@ -13,6 +13,6 @@ dependencies: dev_dependencies: custom_lint: ^0.5.7 ejson_lint: ^0.1.0 - lints: ^2.0.0 + lints: ^3.0.0 diff --git a/packages/ejson_lint/pubspec.yaml b/packages/ejson_lint/pubspec.yaml index 58adc0851..537daee6b 100644 --- a/packages/ejson_lint/pubspec.yaml +++ b/packages/ejson_lint/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 repository: https://github.com/realm/realm-dart/ejson/packages/ejson_lint environment: - sdk: ^3.0.2 + sdk: ^3.0.0 dependencies: analyzer: ^6.0.0 From de5a823ea8198e9d1b28c0d037e0df642435bdfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Mon, 19 Feb 2024 16:39:16 +0100 Subject: [PATCH 051/153] melos bootstrap needed This is because some packages are not published yet --- .github/workflows/ci.yml | 5 +++++ .github/workflows/dart-desktop-tests.yml | 12 +++++++----- .github/workflows/deploy-baas.yml | 7 ++++++- .github/workflows/terminate-baas.yml | 7 ++++++- packages/realm_dart/test/realm_test.dart | 14 ++++++-------- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b5d0b29b..e97e1790b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -503,6 +503,11 @@ jobs: with: channel: 'stable' + - name: Setup Melos + run: | + dart pub global activate melos + dart pub global run melos bootstrap --no-flutter + - name: Delete generated files in realm_dart run: | find . -name "*.g.dart" -delete diff --git a/.github/workflows/dart-desktop-tests.yml b/.github/workflows/dart-desktop-tests.yml index f4ea75e03..1a6c9b1f2 100644 --- a/.github/workflows/dart-desktop-tests.yml +++ b/.github/workflows/dart-desktop-tests.yml @@ -81,11 +81,13 @@ jobs: working-directory: packages/realm_dart - name: Run ejson QA - run: | - dart pub global activate melos - melos bootstrap - melos qa - working-directory: ejson + run: >- + dart pub global activate melos && + melos setup && + melos bootstrap --no-flutter && + melos exec --scope=ejson* --depends-on=test -- + melos exec --scope='ejson*' --depends-on=test -- dart test --concurrency=1 --coverage=coverage/ && + melos exec --scope='ejson*' --depends-on=test -- dart pub global run coverage:format_coverage --in=coverage/test/ --out=coverage/lcov.info --lcov # we're pruning generated files, the cli folder, as well as realm_bindings.dart from our coverage reports - name: Generate realm_dart coverage report diff --git a/.github/workflows/deploy-baas.yml b/.github/workflows/deploy-baas.yml index c668c70e4..b6d53ac48 100644 --- a/.github/workflows/deploy-baas.yml +++ b/.github/workflows/deploy-baas.yml @@ -25,12 +25,17 @@ jobs: with: submodules: false - - name : Setup Dart SDK + - name: Setup Dart SDK uses: dart-lang/setup-dart@main with: sdk: stable architecture: 'x64' + - name: Setup Melos + run: | + dart pub global activate melos + dart pub global run melos bootstrap --no-flutter + - name: Install dependencies run: dart pub get diff --git a/.github/workflows/terminate-baas.yml b/.github/workflows/terminate-baas.yml index 098023cdd..d2add5642 100644 --- a/.github/workflows/terminate-baas.yml +++ b/.github/workflows/terminate-baas.yml @@ -25,12 +25,17 @@ jobs: with: submodules: false - - name : Setup Dart SDK + - name: Setup Dart SDK uses: dart-lang/setup-dart@main with: sdk: stable architecture: 'x64' + - name: Setup Melos + run: | + dart pub global activate melos + dart pub global run melos bootstrap --no-flutter + - name: Install dependencies run: dart pub get diff --git a/packages/realm_dart/test/realm_test.dart b/packages/realm_dart/test/realm_test.dart index e460088ea..1423664c8 100644 --- a/packages/realm_dart/test/realm_test.dart +++ b/packages/realm_dart/test/realm_test.dart @@ -16,21 +16,19 @@ // //////////////////////////////////////////////////////////////////////////////// -// ignore_for_file: unused_local_variable, avoid_relative_lib_imports - -import 'package:ejson_annotation/ejson_annotation.dart'; - import 'dart:async'; import 'dart:convert'; import 'dart:io'; import 'dart:isolate'; -import 'package:test/test.dart' hide test, throws; -import 'package:timezone/timezone.dart' as tz; -import 'package:timezone/data/latest.dart' as tz; + import 'package:path/path.dart' as p; import 'package:realm_dart/realm.dart'; -import 'test.dart'; import 'package:realm_dart/src/native/realm_core.dart'; +import 'package:test/test.dart' hide test, throws; +import 'package:timezone/data/latest.dart' as tz; +import 'package:timezone/timezone.dart' as tz; + +import 'test.dart'; void main() { setupTests(); From fb1fb65bc461e050fda9982b1fc7dac2b9fe7877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Mon, 19 Feb 2024 17:49:32 +0100 Subject: [PATCH 052/153] fixup: bad rebase --- packages/realm_dart/test/backlinks_test.dart | 5 +- .../realm_dart/test/backlinks_test.g.dart | 17 +- .../realm_dart/test}/geospatial_test.g.dart | 0 .../realm_dart/test}/realm_map_test.g.dart | 0 packages/realm_dart/test/realm_set_test.dart | 10 +- test/backlinks_test.dart | 175 ------------------ 6 files changed, 22 insertions(+), 185 deletions(-) rename {test => packages/realm_dart/test}/geospatial_test.g.dart (100%) rename {test => packages/realm_dart/test}/realm_map_test.g.dart (100%) delete mode 100644 test/backlinks_test.dart diff --git a/packages/realm_dart/test/backlinks_test.dart b/packages/realm_dart/test/backlinks_test.dart index e1c949ecb..2cfad0a50 100644 --- a/packages/realm_dart/test/backlinks_test.dart +++ b/packages/realm_dart/test/backlinks_test.dart @@ -16,11 +16,14 @@ // //////////////////////////////////////////////////////////////////////////////// +import 'package:ejson/ejson.dart'; +import 'package:ejson_annotation/ejson_annotation.dart'; +import 'package:realm_dart/realm.dart'; import 'package:test/test.dart' hide test, throws; -import 'package:realm_dart/realm.dart'; import 'test.dart'; +part 'backlinks_test.g.dart'; part 'backlinks_test.realm.dart'; @RealmModel() diff --git a/packages/realm_dart/test/backlinks_test.g.dart b/packages/realm_dart/test/backlinks_test.g.dart index 10c2ae09d..da4a0cfd6 100644 --- a/packages/realm_dart/test/backlinks_test.g.dart +++ b/packages/realm_dart/test/backlinks_test.g.dart @@ -10,7 +10,9 @@ EJsonValue encodeSource(Source value) { return { 'name': value.name.toEJson(), 'oneTarget': value.oneTarget.toEJson(), - 'manyTargets': value.manyTargets.toEJson() + 'dynamicTarget': value.dynamicTarget.toEJson(), + 'manyTargets': value.manyTargets.toEJson(), + 'dynamicManyTargets': value.dynamicManyTargets.toEJson() }; } @@ -19,12 +21,16 @@ Source decodeSource(EJsonValue ejson) { { 'name': EJsonValue name, 'oneTarget': EJsonValue oneTarget, - 'manyTargets': EJsonValue manyTargets + 'dynamicTarget': EJsonValue dynamicTarget, + 'manyTargets': EJsonValue manyTargets, + 'dynamicManyTargets': EJsonValue dynamicManyTargets } => Source( name: name.to(), oneTarget: oneTarget.to(), - manyTargets: manyTargets.to>()), + dynamicTarget: dynamicTarget.to(), + manyTargets: manyTargets.to>(), + dynamicManyTargets: dynamicManyTargets.to>()), _ => raiseInvalidEJson(ejson), }; } @@ -35,12 +41,13 @@ extension SourceEJsonEncoderExtension on Source { } EJsonValue encodeTarget(Target value) { - return {'name': value.name.toEJson()}; + return {'name': value.name.toEJson(), 'source': value.source.toEJson()}; } Target decodeTarget(EJsonValue ejson) { return switch (ejson) { - {'name': EJsonValue name} => Target(name: name.to()), + {'name': EJsonValue name, 'source': EJsonValue source} => + Target(name: name.to(), source: source.to()), _ => raiseInvalidEJson(ejson), }; } diff --git a/test/geospatial_test.g.dart b/packages/realm_dart/test/geospatial_test.g.dart similarity index 100% rename from test/geospatial_test.g.dart rename to packages/realm_dart/test/geospatial_test.g.dart diff --git a/test/realm_map_test.g.dart b/packages/realm_dart/test/realm_map_test.g.dart similarity index 100% rename from test/realm_map_test.g.dart rename to packages/realm_dart/test/realm_map_test.g.dart diff --git a/packages/realm_dart/test/realm_set_test.dart b/packages/realm_dart/test/realm_set_test.dart index 3e7fa0765..c3c7f9039 100644 --- a/packages/realm_dart/test/realm_set_test.dart +++ b/packages/realm_dart/test/realm_set_test.dart @@ -16,16 +16,18 @@ // //////////////////////////////////////////////////////////////////////////////// -import 'package:ejson_annotation/ejson_annotation.dart'; -import 'package:ejson/ejson.dart'; +import 'dart:typed_data'; -import 'package:test/test.dart' hide test, throws; +import 'package:collection/collection.dart'; +import 'package:ejson/ejson.dart'; +import 'package:ejson_annotation/ejson_annotation.dart'; import 'package:realm_dart/realm.dart'; +import 'package:test/test.dart' hide test, throws; import 'test.dart'; -part 'realm_set_test.realm.dart'; part 'realm_set_test.g.dart'; +part 'realm_set_test.realm.dart'; class _NullableBool {} diff --git a/test/backlinks_test.dart b/test/backlinks_test.dart deleted file mode 100644 index 68242cc52..000000000 --- a/test/backlinks_test.dart +++ /dev/null @@ -1,175 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2022 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// - -import 'package:ejson_annotation/ejson_annotation.dart'; -import 'package:ejson/ejson.dart'; - -import 'package:test/expect.dart' hide throws; - -import '../lib/realm.dart'; -import 'test.dart'; - -part 'backlinks_test.realm.dart'; -part 'backlinks_test.g.dart'; - -@RealmModel() -class _Source { - String name = 'source'; - @MapTo('et mål') // to throw a curve ball.. - _Target? oneTarget; - late List<_Target> manyTargets; -} - -@RealmModel() -class _Target { - @Backlink(#oneTarget) - late Iterable<_Source> oneToMany; - - String name = 'target'; - - @Backlink(#manyTargets) - late Iterable<_Source> manyToMany; -} - -Future main([List? args]) async { - await setupTests(args); - - test('Backlinks empty', () { - final config = Configuration.local([Target.schema, Source.schema]); - final realm = getRealm(config); - - final target = realm.write(() => realm.add(Target())); - - expect(target.oneToMany, isEmpty); - }); - - test('Backlink property getter throws for unmanaged objects', () { - final target = Target(); - expect(() => target.oneToMany, throws("Using backlinks is only possible for managed objects.")); - expect(() => target.manyToMany, throws("Using backlinks is only possible for managed objects.")); - }); - - test('Backlinks 1-1(ish)', () { - final config = Configuration.local([Target.schema, Source.schema]); - final realm = getRealm(config); - - final target = Target(); - final source = realm.write(() => realm.add(Source(oneTarget: target))); - - expect(source.oneTarget, target); - expect(target.oneToMany, [source]); - }); - - test('Backlinks 1-many', () { - final config = Configuration.local([Target.schema, Source.schema]); - final realm = getRealm(config); - - final target = Target(); - final sources = List.generate(100, (i) => Source(oneTarget: target, name: '$i')); - realm.write(() => realm.addAll(sources)); - - expect(target.oneToMany, sources); - }); - - test('Backlinks many-many', () { - final config = Configuration.local([Target.schema, Source.schema]); - final realm = getRealm(config); - - final targets = List.generate(100, (i) => Target(name: '$i')); - final sources = List.generate(100, (i) => Source(manyTargets: targets)); - - realm.write(() => realm.addAll(sources)); - - for (final t in targets) { - expect(t.manyToMany, sources); - } - - for (final s in sources) { - expect(s.manyTargets, targets); - } - }); - - test('Backlinks query', () { - final config = Configuration.local([Target.schema, Source.schema]); - final realm = getRealm(config); - - final target = Target(); - final sources = List.generate(100, (i) => Source(oneTarget: target, name: '$i')); - realm.write(() => realm.addAll(sources)); - - final fortyTwo = realm.query(r'name == $0', ['42']).single; - expect(target.oneToMany[42], fortyTwo); - expect(target.oneToMany.query(r'name = $0', ['42']), [fortyTwo]); - }); - - test('Backlinks notifications', () { - final config = Configuration.local([Target.schema, Source.schema]); - final realm = getRealm(config); - - final target = realm.write(() => realm.add(Target())); - - expectLater( - target.oneToMany.changes, - emitsInOrder([ - isA>().having((ch) => ch.inserted, 'inserted', []), - isA>().having((ch) => ch.inserted, 'inserted', [0]), - isA>().having((ch) => ch.inserted, 'inserted', [1]), - isA>() // - .having((ch) => ch.inserted, 'inserted', [0, 2]) // is this surprising? - .having((ch) => ch.deleted, 'deleted', [0]) // - .having((ch) => ch.modified, 'modified', [1]), - ])); - - final first = realm.write(() => realm.add(Source(oneTarget: target))); - - final second = realm.write(() => realm.add(Source(oneTarget: target))); - - realm.write(() { - realm.add(Source(oneTarget: target)); - realm.add(Source(oneTarget: target)); - second.name = "changed second"; - realm.delete(first); - }); - }); - - test('Backlinks read properties', () { - final config = Configuration.local([Target.schema, Source.schema]); - final realm = getRealm(config); - - final theOne = Target(name: 'the one'); - final targets = List.generate(100, (i) => Target(name: 'T$i')); - final sources = List.generate(100, (i) => Source(name: 'S$i', manyTargets: targets, oneTarget: theOne)); - - realm.write(() { - realm.addAll(sources); - realm.addAll(targets); - realm.add(theOne); - }); - - expect(theOne.oneToMany[0].name, 'S0'); - expect(theOne.oneToMany.map((s) => s.name), sources.map((s) => s.name)); - - for (final t in targets) { - expect(t.manyToMany.map((s) => s.name), sources.map((s) => s.name)); - } - - for (final s in sources) { - expect(s.manyTargets.map((t) => t.name), targets.map((t) => t.name)); - } - }); -} From 5c6acf0604471c61ee06b28374528749fd632b50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Mon, 19 Feb 2024 18:21:53 +0100 Subject: [PATCH 053/153] Reorder steps --- .github/workflows/dart-desktop-tests.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/dart-desktop-tests.yml b/.github/workflows/dart-desktop-tests.yml index 1a6c9b1f2..b1b30a5c2 100644 --- a/.github/workflows/dart-desktop-tests.yml +++ b/.github/workflows/dart-desktop-tests.yml @@ -70,6 +70,15 @@ jobs: - name: Run tests run: ${{ inputs.architecture == 'arm' && 'arch -arm64 ' || '' }}dart test -r expanded --coverage ./coverage/ -j 1 --test-randomize-ordering-seed random --file-reporter="json:test-results.json" || true + # TODO: Run all test via melos + - name: Run ejson QA + run: >- + dart pub global activate melos && + melos setup && + melos bootstrap --no-flutter && + melos exec --scope='ejson*' --depends-on=test -- dart test --concurrency=1 --coverage=coverage/ && + melos exec --scope='ejson*' --depends-on=test -- dart pub global run coverage:format_coverage --in=coverage/test/ --out=coverage/lcov.info --lcov + - name: Publish Test Report uses: dorny/test-reporter@v1.7.0 if: success() || failure() @@ -80,15 +89,6 @@ jobs: only-summary: true working-directory: packages/realm_dart - - name: Run ejson QA - run: >- - dart pub global activate melos && - melos setup && - melos bootstrap --no-flutter && - melos exec --scope=ejson* --depends-on=test -- - melos exec --scope='ejson*' --depends-on=test -- dart test --concurrency=1 --coverage=coverage/ && - melos exec --scope='ejson*' --depends-on=test -- dart pub global run coverage:format_coverage --in=coverage/test/ --out=coverage/lcov.info --lcov - # we're pruning generated files, the cli folder, as well as realm_bindings.dart from our coverage reports - name: Generate realm_dart coverage report if: inputs.runner == 'ubuntu-latest' From 7cba56e3c677873a862d5a4d642dde2b8c4c1c47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Mon, 19 Feb 2024 20:16:53 +0100 Subject: [PATCH 054/153] missing deps in example --- melos.yaml | 4 +- packages/realm/example/lib/main.dart | 7 ++-- packages/realm/example/lib/main.g.dart | 54 ++++++++++++++++++++++++++ packages/realm/example/pubspec.yaml | 3 ++ 4 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 packages/realm/example/lib/main.g.dart diff --git a/melos.yaml b/melos.yaml index 145fbbb1f..6eded43cf 100644 --- a/melos.yaml +++ b/melos.yaml @@ -135,12 +135,12 @@ scripts: lint:format: run: dart format --fix --line-length 160 --output none --set-exit-if-changed . exec: - concurrency: 1 # only one project at a time to keep output sane$ + concurrency: 1 # only one project at a time to keep output sane lint:pana: run: dart pub global run pana --no-warning --exit-code-threshold 40 . exec: - concurrency: 1 # only one project at a time to keep output sane$ + concurrency: 1 # only one project at a time to keep output sane packageFilters: published: true diff --git a/packages/realm/example/lib/main.dart b/packages/realm/example/lib/main.dart index d5bec6f44..e07e13719 100644 --- a/packages/realm/example/lib/main.dart +++ b/packages/realm/example/lib/main.dart @@ -17,15 +17,16 @@ //////////////////////////////////////////////////////////////////////////////// // ignore_for_file: avoid_print -import 'package:ejson_annotation/ejson_annotation.dart'; -import 'package:ejson/ejson.dart'; import 'dart:io'; + +import 'package:ejson/ejson.dart'; +import 'package:ejson_annotation/ejson_annotation.dart'; import 'package:flutter/material.dart'; import 'package:realm/realm.dart'; -part 'main.realm.dart'; part 'main.g.dart'; +part 'main.realm.dart'; @RealmModel() class _Car { diff --git a/packages/realm/example/lib/main.g.dart b/packages/realm/example/lib/main.g.dart new file mode 100644 index 000000000..3a513404b --- /dev/null +++ b/packages/realm/example/lib/main.g.dart @@ -0,0 +1,54 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'main.dart'; + +// ************************************************************************** +// EJsonGenerator +// ************************************************************************** + +EJsonValue encodeCar(Car value) { + return { + 'make': value.make.toEJson(), + 'model': value.model.toEJson(), + 'kilometers': value.kilometers.toEJson(), + 'owner': value.owner.toEJson() + }; +} + +Car decodeCar(EJsonValue ejson) { + return switch (ejson) { + { + 'make': EJsonValue make, + 'model': EJsonValue model, + 'kilometers': EJsonValue kilometers, + 'owner': EJsonValue owner + } => + Car(make.to(), + model: model.to(), + kilometers: kilometers.to(), + owner: owner.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension CarEJsonEncoderExtension on Car { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodeCar(this); +} + +EJsonValue encodePerson(Person value) { + return {'name': value.name.toEJson(), 'age': value.age.toEJson()}; +} + +Person decodePerson(EJsonValue ejson) { + return switch (ejson) { + {'name': EJsonValue name, 'age': EJsonValue age} => + Person(name.to(), age: age.to()), + _ => raiseInvalidEJson(ejson), + }; +} + +extension PersonEJsonEncoderExtension on Person { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => encodePerson(this); +} diff --git a/packages/realm/example/pubspec.yaml b/packages/realm/example/pubspec.yaml index 91c108ca3..592eef7d0 100644 --- a/packages/realm/example/pubspec.yaml +++ b/packages/realm/example/pubspec.yaml @@ -11,11 +11,14 @@ environment: dependencies: flutter: sdk: flutter + ejson: ^0.1.0 + ejson_annotation: ^0.1.0 realm: ^1.8.0 characters: ^1.1.0 dev_dependencies: flutter_lints: ^3.0.1 + ejson_generator: ^0.1.0 flutter: uses-material-design: true From b4f4be1e32fd323950af8285ecc8e04e091a7390 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Mon, 19 Feb 2024 20:24:00 +0100 Subject: [PATCH 055/153] Cleanup .gitignore hierarchy --- .gitignore | 5 ++++- packages/ejson_analyzer/.gitignore | 7 ------- packages/ejson_annotation/.gitignore | 7 ------- packages/ejson_generator/.gitignore | 7 ------- packages/ejson_lint/.gitignore | 7 ------- packages/ejson_lint/example/.gitignore | 10 +++++++--- 6 files changed, 11 insertions(+), 32 deletions(-) delete mode 100644 packages/ejson_analyzer/.gitignore delete mode 100644 packages/ejson_annotation/.gitignore delete mode 100644 packages/ejson_generator/.gitignore delete mode 100644 packages/ejson_lint/.gitignore diff --git a/.gitignore b/.gitignore index d8da95775..c442974be 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,7 @@ test-results.json **/coverage/ # dos -**/doc/api/ \ No newline at end of file +**/doc/api/ + +# custom lint +**/custom_lint.log \ No newline at end of file diff --git a/packages/ejson_analyzer/.gitignore b/packages/ejson_analyzer/.gitignore deleted file mode 100644 index 3cceda557..000000000 --- a/packages/ejson_analyzer/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -# https://dart.dev/guides/libraries/private-files -# Created by `dart pub` -.dart_tool/ - -# Avoid committing pubspec.lock for library packages; see -# https://dart.dev/guides/libraries/private-files#pubspeclock. -pubspec.lock diff --git a/packages/ejson_annotation/.gitignore b/packages/ejson_annotation/.gitignore deleted file mode 100644 index 3cceda557..000000000 --- a/packages/ejson_annotation/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -# https://dart.dev/guides/libraries/private-files -# Created by `dart pub` -.dart_tool/ - -# Avoid committing pubspec.lock for library packages; see -# https://dart.dev/guides/libraries/private-files#pubspeclock. -pubspec.lock diff --git a/packages/ejson_generator/.gitignore b/packages/ejson_generator/.gitignore deleted file mode 100644 index 3cceda557..000000000 --- a/packages/ejson_generator/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -# https://dart.dev/guides/libraries/private-files -# Created by `dart pub` -.dart_tool/ - -# Avoid committing pubspec.lock for library packages; see -# https://dart.dev/guides/libraries/private-files#pubspeclock. -pubspec.lock diff --git a/packages/ejson_lint/.gitignore b/packages/ejson_lint/.gitignore deleted file mode 100644 index 3cceda557..000000000 --- a/packages/ejson_lint/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -# https://dart.dev/guides/libraries/private-files -# Created by `dart pub` -.dart_tool/ - -# Avoid committing pubspec.lock for library packages; see -# https://dart.dev/guides/libraries/private-files#pubspeclock. -pubspec.lock diff --git a/packages/ejson_lint/example/.gitignore b/packages/ejson_lint/example/.gitignore index 3a8579040..52b7a51ed 100644 --- a/packages/ejson_lint/example/.gitignore +++ b/packages/ejson_lint/example/.gitignore @@ -1,3 +1,7 @@ -# https://dart.dev/guides/libraries/private-files -# Created by `dart pub` -.dart_tool/ +# Don't commit platform specific files for examples +# Use flutter create . --platforms= to generate them +android/ +ios/ +linux/ +macos/ +windows/ From 8d3425e5efa4054e38d5eec45ef10b88c3baba29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Mon, 19 Feb 2024 20:52:29 +0100 Subject: [PATCH 056/153] Align analysis_options.yaml files with symlinks --- analysis_options.yaml | 14 +-------- packages/ejson/analysis_options.yaml | 2 +- packages/ejson_analyzer/analysis_options.yaml | 2 +- .../ejson_annotation/analysis_options.yaml | 2 +- .../ejson_generator/analysis_options.yaml | 2 +- packages/ejson_lint/analysis_options.yaml | 2 +- .../ejson_lint/example/analysis_options.yaml | 6 +--- packages/realm/analysis_options.yaml | 2 +- packages/realm/example/analysis_options.yaml | 30 +----------------- packages/realm/tests/analysis_options.yaml | 30 +----------------- packages/realm_common/analysis_options.yaml | 2 +- packages/realm_dart/analysis_options.yaml | 2 +- .../realm_dart/example/analysis_options.yaml | 31 +------------------ .../realm_generator/analysis_options.yaml | 2 +- 14 files changed, 14 insertions(+), 115 deletions(-) mode change 100644 => 120000 packages/ejson/analysis_options.yaml mode change 100644 => 120000 packages/ejson_analyzer/analysis_options.yaml mode change 100644 => 120000 packages/ejson_annotation/analysis_options.yaml mode change 100644 => 120000 packages/ejson_generator/analysis_options.yaml mode change 100644 => 120000 packages/ejson_lint/analysis_options.yaml mode change 100644 => 120000 packages/ejson_lint/example/analysis_options.yaml mode change 100644 => 120000 packages/realm/example/analysis_options.yaml mode change 100644 => 120000 packages/realm/tests/analysis_options.yaml mode change 100644 => 120000 packages/realm_dart/example/analysis_options.yaml diff --git a/analysis_options.yaml b/analysis_options.yaml index c532ec449..43748cf3a 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,16 +1,4 @@ -# This file configures the static analysis results for your project (errors, -# warnings, and lints). -# -# This enables the 'recommended' set of lints from `package:lints`. -# This set helps identify many issues that may lead to problems when running -# or consuming Dart code, and enforces writing Dart using a single, idiomatic -# style and format. -# -# If you want a smaller set of lints you can change this to specify -# 'package:lints/core.yaml'. These are just the most critical lints -# (the recommended set includes the core lints). -# The core lints are also what is used by pub.dev for scoring packages. - +# This file is symlinked into each package's root directory. include: package:lints/recommended.yaml analyzer: diff --git a/packages/ejson/analysis_options.yaml b/packages/ejson/analysis_options.yaml deleted file mode 100644 index ea2c9e947..000000000 --- a/packages/ejson/analysis_options.yaml +++ /dev/null @@ -1 +0,0 @@ -include: package:lints/recommended.yaml \ No newline at end of file diff --git a/packages/ejson/analysis_options.yaml b/packages/ejson/analysis_options.yaml new file mode 120000 index 000000000..39c772ad4 --- /dev/null +++ b/packages/ejson/analysis_options.yaml @@ -0,0 +1 @@ +analysis_options.yaml \ No newline at end of file diff --git a/packages/ejson_analyzer/analysis_options.yaml b/packages/ejson_analyzer/analysis_options.yaml deleted file mode 100644 index ea2c9e947..000000000 --- a/packages/ejson_analyzer/analysis_options.yaml +++ /dev/null @@ -1 +0,0 @@ -include: package:lints/recommended.yaml \ No newline at end of file diff --git a/packages/ejson_analyzer/analysis_options.yaml b/packages/ejson_analyzer/analysis_options.yaml new file mode 120000 index 000000000..39c772ad4 --- /dev/null +++ b/packages/ejson_analyzer/analysis_options.yaml @@ -0,0 +1 @@ +analysis_options.yaml \ No newline at end of file diff --git a/packages/ejson_annotation/analysis_options.yaml b/packages/ejson_annotation/analysis_options.yaml deleted file mode 100644 index ea2c9e947..000000000 --- a/packages/ejson_annotation/analysis_options.yaml +++ /dev/null @@ -1 +0,0 @@ -include: package:lints/recommended.yaml \ No newline at end of file diff --git a/packages/ejson_annotation/analysis_options.yaml b/packages/ejson_annotation/analysis_options.yaml new file mode 120000 index 000000000..39c772ad4 --- /dev/null +++ b/packages/ejson_annotation/analysis_options.yaml @@ -0,0 +1 @@ +analysis_options.yaml \ No newline at end of file diff --git a/packages/ejson_generator/analysis_options.yaml b/packages/ejson_generator/analysis_options.yaml deleted file mode 100644 index ea2c9e947..000000000 --- a/packages/ejson_generator/analysis_options.yaml +++ /dev/null @@ -1 +0,0 @@ -include: package:lints/recommended.yaml \ No newline at end of file diff --git a/packages/ejson_generator/analysis_options.yaml b/packages/ejson_generator/analysis_options.yaml new file mode 120000 index 000000000..39c772ad4 --- /dev/null +++ b/packages/ejson_generator/analysis_options.yaml @@ -0,0 +1 @@ +analysis_options.yaml \ No newline at end of file diff --git a/packages/ejson_lint/analysis_options.yaml b/packages/ejson_lint/analysis_options.yaml deleted file mode 100644 index ea2c9e947..000000000 --- a/packages/ejson_lint/analysis_options.yaml +++ /dev/null @@ -1 +0,0 @@ -include: package:lints/recommended.yaml \ No newline at end of file diff --git a/packages/ejson_lint/analysis_options.yaml b/packages/ejson_lint/analysis_options.yaml new file mode 120000 index 000000000..39c772ad4 --- /dev/null +++ b/packages/ejson_lint/analysis_options.yaml @@ -0,0 +1 @@ +analysis_options.yaml \ No newline at end of file diff --git a/packages/ejson_lint/example/analysis_options.yaml b/packages/ejson_lint/example/analysis_options.yaml deleted file mode 100644 index 530482459..000000000 --- a/packages/ejson_lint/example/analysis_options.yaml +++ /dev/null @@ -1,5 +0,0 @@ -include: package:lints/recommended.yaml - -analyzer: - plugins: - - custom_lint \ No newline at end of file diff --git a/packages/ejson_lint/example/analysis_options.yaml b/packages/ejson_lint/example/analysis_options.yaml new file mode 120000 index 000000000..39c772ad4 --- /dev/null +++ b/packages/ejson_lint/example/analysis_options.yaml @@ -0,0 +1 @@ +analysis_options.yaml \ No newline at end of file diff --git a/packages/realm/analysis_options.yaml b/packages/realm/analysis_options.yaml index 3a0737064..39c772ad4 120000 --- a/packages/realm/analysis_options.yaml +++ b/packages/realm/analysis_options.yaml @@ -1 +1 @@ -../../analysis_options.yaml \ No newline at end of file +analysis_options.yaml \ No newline at end of file diff --git a/packages/realm/example/analysis_options.yaml b/packages/realm/example/analysis_options.yaml deleted file mode 100644 index 61b6c4de1..000000000 --- a/packages/realm/example/analysis_options.yaml +++ /dev/null @@ -1,29 +0,0 @@ -# This file configures the analyzer, which statically analyzes Dart code to -# check for errors, warnings, and lints. -# -# The issues identified by the analyzer are surfaced in the UI of Dart-enabled -# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be -# invoked from the command line by running `flutter analyze`. - -# The following line activates a set of recommended lints for Flutter apps, -# packages, and plugins designed to encourage good coding practices. -include: package:flutter_lints/flutter.yaml - -linter: - # The lint rules applied to this project can be customized in the - # section below to disable rules from the `package:flutter_lints/flutter.yaml` - # included above or to enable additional rules. A list of all available lints - # and their documentation is published at - # https://dart-lang.github.io/linter/lints/index.html. - # - # Instead of disabling a lint rule for the entire project in the - # section below, it can also be suppressed for a single line of code - # or a specific dart file by using the `// ignore: name_of_lint` and - # `// ignore_for_file: name_of_lint` syntax on the line or in the file - # producing the lint. - rules: - # avoid_print: false # Uncomment to disable the `avoid_print` rule - # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule - -# Additional information about this file can be found at -# https://dart.dev/guides/language/analysis-options diff --git a/packages/realm/example/analysis_options.yaml b/packages/realm/example/analysis_options.yaml new file mode 120000 index 000000000..39c772ad4 --- /dev/null +++ b/packages/realm/example/analysis_options.yaml @@ -0,0 +1 @@ +analysis_options.yaml \ No newline at end of file diff --git a/packages/realm/tests/analysis_options.yaml b/packages/realm/tests/analysis_options.yaml deleted file mode 100644 index 61b6c4de1..000000000 --- a/packages/realm/tests/analysis_options.yaml +++ /dev/null @@ -1,29 +0,0 @@ -# This file configures the analyzer, which statically analyzes Dart code to -# check for errors, warnings, and lints. -# -# The issues identified by the analyzer are surfaced in the UI of Dart-enabled -# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be -# invoked from the command line by running `flutter analyze`. - -# The following line activates a set of recommended lints for Flutter apps, -# packages, and plugins designed to encourage good coding practices. -include: package:flutter_lints/flutter.yaml - -linter: - # The lint rules applied to this project can be customized in the - # section below to disable rules from the `package:flutter_lints/flutter.yaml` - # included above or to enable additional rules. A list of all available lints - # and their documentation is published at - # https://dart-lang.github.io/linter/lints/index.html. - # - # Instead of disabling a lint rule for the entire project in the - # section below, it can also be suppressed for a single line of code - # or a specific dart file by using the `// ignore: name_of_lint` and - # `// ignore_for_file: name_of_lint` syntax on the line or in the file - # producing the lint. - rules: - # avoid_print: false # Uncomment to disable the `avoid_print` rule - # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule - -# Additional information about this file can be found at -# https://dart.dev/guides/language/analysis-options diff --git a/packages/realm/tests/analysis_options.yaml b/packages/realm/tests/analysis_options.yaml new file mode 120000 index 000000000..39c772ad4 --- /dev/null +++ b/packages/realm/tests/analysis_options.yaml @@ -0,0 +1 @@ +analysis_options.yaml \ No newline at end of file diff --git a/packages/realm_common/analysis_options.yaml b/packages/realm_common/analysis_options.yaml index 3a0737064..39c772ad4 120000 --- a/packages/realm_common/analysis_options.yaml +++ b/packages/realm_common/analysis_options.yaml @@ -1 +1 @@ -../../analysis_options.yaml \ No newline at end of file +analysis_options.yaml \ No newline at end of file diff --git a/packages/realm_dart/analysis_options.yaml b/packages/realm_dart/analysis_options.yaml index 3a0737064..39c772ad4 120000 --- a/packages/realm_dart/analysis_options.yaml +++ b/packages/realm_dart/analysis_options.yaml @@ -1 +1 @@ -../../analysis_options.yaml \ No newline at end of file +analysis_options.yaml \ No newline at end of file diff --git a/packages/realm_dart/example/analysis_options.yaml b/packages/realm_dart/example/analysis_options.yaml deleted file mode 100644 index dee8927aa..000000000 --- a/packages/realm_dart/example/analysis_options.yaml +++ /dev/null @@ -1,30 +0,0 @@ -# This file configures the static analysis results for your project (errors, -# warnings, and lints). -# -# This enables the 'recommended' set of lints from `package:lints`. -# This set helps identify many issues that may lead to problems when running -# or consuming Dart code, and enforces writing Dart using a single, idiomatic -# style and format. -# -# If you want a smaller set of lints you can change this to specify -# 'package:lints/core.yaml'. These are just the most critical lints -# (the recommended set includes the core lints). -# The core lints are also what is used by pub.dev for scoring packages. - -include: package:lints/recommended.yaml - -# Uncomment the following section to specify additional rules. - -# linter: -# rules: -# - camel_case_types - -# analyzer: -# exclude: -# - path/to/excluded/files/** - -# For more information about the core and recommended set of lints, see -# https://dart.dev/go/core-lints - -# For additional information about configuring this file, see -# https://dart.dev/guides/language/analysis-options diff --git a/packages/realm_dart/example/analysis_options.yaml b/packages/realm_dart/example/analysis_options.yaml new file mode 120000 index 000000000..39c772ad4 --- /dev/null +++ b/packages/realm_dart/example/analysis_options.yaml @@ -0,0 +1 @@ +analysis_options.yaml \ No newline at end of file diff --git a/packages/realm_generator/analysis_options.yaml b/packages/realm_generator/analysis_options.yaml index 3a0737064..39c772ad4 120000 --- a/packages/realm_generator/analysis_options.yaml +++ b/packages/realm_generator/analysis_options.yaml @@ -1 +1 @@ -../../analysis_options.yaml \ No newline at end of file +analysis_options.yaml \ No newline at end of file From 3cefd0787c8567933aff911cad29482fb6107ee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Mon, 19 Feb 2024 21:07:37 +0100 Subject: [PATCH 057/153] realm/example is a flutter project --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e97e1790b..a5ddbbde3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -506,13 +506,12 @@ jobs: - name: Setup Melos run: | dart pub global activate melos - dart pub global run melos bootstrap --no-flutter + dart pub global run melos bootstrap - name: Delete generated files in realm_dart run: | find . -name "*.g.dart" -delete find . -name "*.realm.dart" -delete - working-directory: packages/realm_dart - name: Run generator in realm_dart From d51c66f5bab1f60322742b7226e0b2e4211faa66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 20 Feb 2024 07:53:59 +0100 Subject: [PATCH 058/153] Remove last remnants of toplevel ejson folder --- ejson/.gitignore | 4 ---- ejson/.vscode/settings.json | 5 ----- ejson/README.md | 38 ------------------------------------- 3 files changed, 47 deletions(-) delete mode 100644 ejson/.gitignore delete mode 100644 ejson/.vscode/settings.json delete mode 100644 ejson/README.md diff --git a/ejson/.gitignore b/ejson/.gitignore deleted file mode 100644 index e33e893a5..000000000 --- a/ejson/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -custom_lint.log -lcov.info -pubspec_overrides.yaml -**/coverage/ diff --git a/ejson/.vscode/settings.json b/ejson/.vscode/settings.json deleted file mode 100644 index 4f32ba4b6..000000000 --- a/ejson/.vscode/settings.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "cSpell.words": [ - "ejson" - ] -} \ No newline at end of file diff --git a/ejson/README.md b/ejson/README.md deleted file mode 100644 index 2366c6c86..000000000 --- a/ejson/README.md +++ /dev/null @@ -1,38 +0,0 @@ - - -Support for serializing and deserializing Extended JSON ([EJson](https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/)) - -## Features - - - -## Getting started - -TODO: List prerequisites and provide or point to information on how to -start using the package. - -## Usage - -TODO: Include short and useful examples for package users. Add longer examples -to `/example` folder. - -```dart -const like = 'sample'; -``` - -## Additional information - -TODO: Tell users more about the package: where to find more information, how to -contribute to the package, how to file issues, what response they can expect -from the package authors, and more. From 488740c3b08a5155e186080de93355c6949d0b75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 20 Feb 2024 07:57:23 +0100 Subject: [PATCH 059/153] Tweak melos.yaml --- melos.yaml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/melos.yaml b/melos.yaml index 6eded43cf..c681c8ad3 100644 --- a/melos.yaml +++ b/melos.yaml @@ -43,8 +43,8 @@ scripts: build:native: # TODO: mac specific and too simple exec: >- - cmake --preset $PLATFORM && - cmake --build --preset $PLATFORM --config MinSizeRel -- -destination "generic/platform=macOS" + cmake --preset $CMAKE_PLATFORM && + cmake --build --preset $CMAKE_PLATFORM --config $CMAKE_CONFIG -- -destination "generic/platform=macOS" packageFilters: dirExists: src # by convention @@ -70,7 +70,10 @@ scripts: test:unit: run: >- - dart test --concurrency=1 --coverage=coverage/ && + dart test + --concurrency=1 + --coverage=coverage/ + --file-reporter=json:test-results.json && dart pub global run coverage:format_coverage --in=coverage/test/ --out=coverage/lcov.info @@ -179,4 +182,4 @@ scripts: melos run test && melos run lint && melos run analyze && - melos run coverage + melos run coverage:check From 4dd38cb6bc8d0379d61d966f05c110b6f76a3f2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 20 Feb 2024 08:47:48 +0100 Subject: [PATCH 060/153] TMP: workaround --- .github/workflows/dart-desktop-tests.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dart-desktop-tests.yml b/.github/workflows/dart-desktop-tests.yml index b1b30a5c2..bb042ab40 100644 --- a/.github/workflows/dart-desktop-tests.yml +++ b/.github/workflows/dart-desktop-tests.yml @@ -102,7 +102,7 @@ jobs: --packages .dart_tool/package_config.json \ --report-on lib,common lcov --remove ./coverage/lcov.info '*.g.dart' '*.realm.dart' '*/lib/src/cli/*' '*/lib/src/native/realm_bindings.dart' -o coverage/pruned-lcov.info - lcov --add-tracefile ejson/lcov.info --add-tracefile coverage/pruned-lcov.info -o coverage/merged-lcov.info +# lcov --add-tracefile ejson/lcov.info --add-tracefile coverage/pruned-lcov.info -o coverage/merged-lcov.info - name: Publish realm_dart coverage if: inputs.runner == 'ubuntu-latest' @@ -111,7 +111,8 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} flag-name: realm_dart - path-to-lcov: ./coverage/merged-lcov.info +# path-to-lcov: ./coverage/merged-lcov.info + path-to-lcov: ./coverage/pruned-lcov.info parallel: true - name: Output Coveralls response From a916a1ed3bf6c9a0a86711c8125197384e40a123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 20 Feb 2024 17:42:23 +0100 Subject: [PATCH 061/153] Coverage (wip) --- .github/workflows/ci.yml | 1 + .github/workflows/dart-desktop-tests.yml | 46 ++++++------------------ melos.yaml | 1 - 3 files changed, 12 insertions(+), 36 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a5ddbbde3..293890e91 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -491,6 +491,7 @@ jobs: runs-on: ${{ matrix.os }}-latest name: Generator Tests + timeout-minutes: 30 steps: - name: Checkout diff --git a/.github/workflows/dart-desktop-tests.yml b/.github/workflows/dart-desktop-tests.yml index bb042ab40..ba254dfc9 100644 --- a/.github/workflows/dart-desktop-tests.yml +++ b/.github/workflows/dart-desktop-tests.yml @@ -30,9 +30,6 @@ jobs: runs-on: ${{ inputs.runner }} name: Dart tests on ${{inputs.os }} ${{ inputs.architecture }} timeout-minutes: 45 - defaults: - run: - working-directory: packages/realm_dart steps: - name: Checkout @@ -40,9 +37,6 @@ jobs: with: submodules: false - - name: Cleanup Workspace - run: git clean -fdx - - name: Fetch artifacts uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7 with: @@ -58,27 +52,17 @@ jobs: - name: Setup Melos run: | dart pub global activate melos - dart pub global run melos bootstrap --no-flutter - - - name: Install dependencies - run: dart pub get + melos bootstrap --no-flutter + melos setup - - name: Bump ulimit + - name: Bump ulimit on macos run: ulimit -n 10240 if: ${{ contains(inputs.os, 'macos') }} - name: Run tests - run: ${{ inputs.architecture == 'arm' && 'arch -arm64 ' || '' }}dart test -r expanded --coverage ./coverage/ -j 1 --test-randomize-ordering-seed random --file-reporter="json:test-results.json" || true - - # TODO: Run all test via melos - - name: Run ejson QA - run: >- - dart pub global activate melos && - melos setup && - melos bootstrap --no-flutter && - melos exec --scope='ejson*' --depends-on=test -- dart test --concurrency=1 --coverage=coverage/ && - melos exec --scope='ejson*' --depends-on=test -- dart pub global run coverage:format_coverage --in=coverage/test/ --out=coverage/lcov.info --lcov + run: ${{ inputs.architecture == 'arm' && 'arch -arm64 ' || '' }}melos test:unit + # TODO: Publish all reports - name: Publish Test Report uses: dorny/test-reporter@v1.7.0 if: success() || failure() @@ -89,30 +73,22 @@ jobs: only-summary: true working-directory: packages/realm_dart - # we're pruning generated files, the cli folder, as well as realm_bindings.dart from our coverage reports - - name: Generate realm_dart coverage report + - name: Gather coverage report if: inputs.runner == 'ubuntu-latest' run: | sudo apt-get install -y lcov - dart run coverage:format_coverage \ - --in coverage/ \ - --out ./coverage/lcov.info \ - --check-ignore \ - --lcov \ - --packages .dart_tool/package_config.json \ - --report-on lib,common - lcov --remove ./coverage/lcov.info '*.g.dart' '*.realm.dart' '*/lib/src/cli/*' '*/lib/src/native/realm_bindings.dart' -o coverage/pruned-lcov.info -# lcov --add-tracefile ejson/lcov.info --add-tracefile coverage/pruned-lcov.info -o coverage/merged-lcov.info + mkdir coverage + touch coverage/merged_lcov.info + find . -name lcov.info | xargs -I % lcov --ignore-errors empty -a % -a coverage/merged_lcov.info -o coverage/merged_lcov.info - - name: Publish realm_dart coverage + - name: Publish coverage if: inputs.runner == 'ubuntu-latest' id: publish-coverage uses: coverallsapp/github-action@f350da2c033043742f89e8c0b7b5145a1616da6d with: github-token: ${{ secrets.GITHUB_TOKEN }} flag-name: realm_dart -# path-to-lcov: ./coverage/merged-lcov.info - path-to-lcov: ./coverage/pruned-lcov.info + path-to-lcov: ./coverage/merged-lcov.info parallel: true - name: Output Coveralls response diff --git a/melos.yaml b/melos.yaml index c681c8ad3..320c8d68b 100644 --- a/melos.yaml +++ b/melos.yaml @@ -26,7 +26,6 @@ command: scripts: setup: run: >- - git submodule update --init --recursive && dart pub global activate combine_coverage && dart pub global activate coverage && dart pub global activate coverde && From ea144693c97799db464afebb0f945e8cd2febab3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 20 Feb 2024 23:17:41 +0100 Subject: [PATCH 062/153] Use combine_coverage package instead of lcov --- .github/workflows/dart-desktop-tests.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/dart-desktop-tests.yml b/.github/workflows/dart-desktop-tests.yml index ba254dfc9..a779648ba 100644 --- a/.github/workflows/dart-desktop-tests.yml +++ b/.github/workflows/dart-desktop-tests.yml @@ -76,10 +76,7 @@ jobs: - name: Gather coverage report if: inputs.runner == 'ubuntu-latest' run: | - sudo apt-get install -y lcov - mkdir coverage - touch coverage/merged_lcov.info - find . -name lcov.info | xargs -I % lcov --ignore-errors empty -a % -a coverage/merged_lcov.info -o coverage/merged_lcov.info + dart pub global run combine_coverage --repo-path=$(pwd) - name: Publish coverage if: inputs.runner == 'ubuntu-latest' @@ -88,7 +85,7 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} flag-name: realm_dart - path-to-lcov: ./coverage/merged-lcov.info + path-to-lcov: ./coverage/lcov.info parallel: true - name: Output Coveralls response From 103f86c9c5ec2e23c79278e1f0257b3581cd47c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 20 Feb 2024 23:35:23 +0100 Subject: [PATCH 063/153] Only report on lib folder --- melos.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/melos.yaml b/melos.yaml index 320c8d68b..6a71e5da6 100644 --- a/melos.yaml +++ b/melos.yaml @@ -74,9 +74,10 @@ scripts: --coverage=coverage/ --file-reporter=json:test-results.json && dart pub global run coverage:format_coverage + --report-on=lib/ --in=coverage/test/ - --out=coverage/lcov.info --lcov + --out=coverage/lcov.info exec: concurrency: 1 # only one project at a time to keep output sane packageFilters: From c445f0299966c23ced2e36fb1cf65cbf479a0040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 20 Feb 2024 23:52:00 +0100 Subject: [PATCH 064/153] Prune coverage a bit --- .github/workflows/dart-desktop-tests.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dart-desktop-tests.yml b/.github/workflows/dart-desktop-tests.yml index a779648ba..b65a4a824 100644 --- a/.github/workflows/dart-desktop-tests.yml +++ b/.github/workflows/dart-desktop-tests.yml @@ -77,6 +77,8 @@ jobs: if: inputs.runner == 'ubuntu-latest' run: | dart pub global run combine_coverage --repo-path=$(pwd) + sudo apt-get install lcov + lcov --remove ./coverage/lcov.info '*/lib/src/cli/*' '*/lib/src/native/realm_bindings.dart' -o coverage/pruned-lcov.info - name: Publish coverage if: inputs.runner == 'ubuntu-latest' @@ -85,7 +87,7 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} flag-name: realm_dart - path-to-lcov: ./coverage/lcov.info + path-to-lcov: ./coverage/pruned-lcov.info parallel: true - name: Output Coveralls response From ef857a3c4ca93a8eaeee47a6e6a67938e32e3b5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 20 Feb 2024 23:57:48 +0100 Subject: [PATCH 065/153] Don't run tests twice --- .github/workflows/ci.yml | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 293890e91..7ca784e49 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -551,39 +551,8 @@ jobs: exit 1 fi - - name: Run generator tests - run: | - dart pub get - dart test -r expanded --coverage ./coverage/ --test-randomize-ordering-seed random - - - name: Generate generator coverage report - if: matrix.os == 'ubuntu' - run: | - dart run coverage:format_coverage \ - --in coverage/ \ - --out ./coverage/lcov.info \ - --check-ignore \ - --lcov \ - --packages .dart_tool/package_config.json \ - --report-on lib - - - name: Publish Generator Coverage - if: matrix.os == 'ubuntu' - id: publish-coverage - uses: coverallsapp/github-action@f350da2c033043742f89e8c0b7b5145a1616da6d - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - flag-name: generator - path-to-lcov: packages/realm_generator/coverage/lcov.info - parallel: true - - - name: Output Coveralls response - if: matrix.os == 'ubuntu' - run: echo ${{ steps.publish-coverage.outputs.coveralls-api-result }} - coverage-finished: needs: - - generator - dart-tests-linux runs-on: ubuntu-latest steps: From e8da64bf22fd71c3773f2bb577e4161903f5b82b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 21 Feb 2024 00:09:13 +0100 Subject: [PATCH 066/153] Skip redundant step --- .github/workflows/dart-desktop-tests.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/dart-desktop-tests.yml b/.github/workflows/dart-desktop-tests.yml index b65a4a824..a25c670de 100644 --- a/.github/workflows/dart-desktop-tests.yml +++ b/.github/workflows/dart-desktop-tests.yml @@ -88,8 +88,4 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} flag-name: realm_dart path-to-lcov: ./coverage/pruned-lcov.info - parallel: true - - - name: Output Coveralls response - if: inputs.runner == 'ubuntu-latest' - run: echo ${{ steps.publish-coverage.outputs.coveralls-api-result }} \ No newline at end of file + parallel: true \ No newline at end of file From 0a3871be22c15364d14349077fed10d775e7b707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 21 Feb 2024 00:35:46 +0100 Subject: [PATCH 067/153] Update checkout action to v4 --- .github/workflows/build-native.yml | 2 +- .github/workflows/check-changelog.yml | 2 +- .github/workflows/ci.yml | 7 +++---- .github/workflows/dart-desktop-tests.yml | 2 +- .github/workflows/deploy-baas.yml | 2 +- .github/workflows/flutter-desktop-tests.yml | 2 +- .github/workflows/issue-labeler.yml | 2 +- .github/workflows/prepare-release.yml | 2 +- .github/workflows/publish-release.yml | 4 ++-- .github/workflows/terminate-baas.yml | 2 +- 10 files changed, 13 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build-native.yml b/.github/workflows/build-native.yml index c880b3edb..a66d7ad26 100644 --- a/.github/workflows/build-native.yml +++ b/.github/workflows/build-native.yml @@ -30,7 +30,7 @@ jobs: build: ${{ fromJSON(inputs.build) }} steps: - name: Checkout - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + uses: actions/checkout@v4 with: submodules: 'recursive' diff --git a/.github/workflows/check-changelog.yml b/.github/workflows/check-changelog.yml index e23ae1751..9c856000b 100644 --- a/.github/workflows/check-changelog.yml +++ b/.github/workflows/check-changelog.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@8230315d06ad95c617244d2f265d237a1682d445 + uses: actions/checkout@v4 with: submodules: false - name: Enforce Changelog diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7ca784e49..e9aecb3d2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -294,7 +294,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + uses: actions/checkout@v4 with: submodules: 'recursive' @@ -378,7 +378,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + uses: actions/checkout@v4 with: submodules: 'recursive' @@ -495,7 +495,7 @@ jobs: timeout-minutes: 30 steps: - name: Checkout - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + uses: actions/checkout@v4 with: submodules: 'recursive' @@ -556,7 +556,6 @@ jobs: - dart-tests-linux runs-on: ubuntu-latest steps: - - name: Coveralls Finished id: publish-coverage uses: coverallsapp/github-action@f350da2c033043742f89e8c0b7b5145a1616da6d diff --git a/.github/workflows/dart-desktop-tests.yml b/.github/workflows/dart-desktop-tests.yml index a25c670de..468758d79 100644 --- a/.github/workflows/dart-desktop-tests.yml +++ b/.github/workflows/dart-desktop-tests.yml @@ -33,7 +33,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + uses: actions/checkout@v4 with: submodules: false diff --git a/.github/workflows/deploy-baas.yml b/.github/workflows/deploy-baas.yml index b6d53ac48..3e7263aa8 100644 --- a/.github/workflows/deploy-baas.yml +++ b/.github/workflows/deploy-baas.yml @@ -21,7 +21,7 @@ jobs: timeout-minutes: 15 steps: - name: Checkout - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + uses: actions/checkout@v4 with: submodules: false diff --git a/.github/workflows/flutter-desktop-tests.yml b/.github/workflows/flutter-desktop-tests.yml index dd28a4a45..70c2db541 100644 --- a/.github/workflows/flutter-desktop-tests.yml +++ b/.github/workflows/flutter-desktop-tests.yml @@ -38,7 +38,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + uses: actions/checkout@v4 with: submodules: false diff --git a/.github/workflows/issue-labeler.yml b/.github/workflows/issue-labeler.yml index 5c9af500c..a93e0c8c0 100644 --- a/.github/workflows/issue-labeler.yml +++ b/.github/workflows/issue-labeler.yml @@ -19,7 +19,7 @@ jobs: template: [ bug.yml, feature.yml ] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Parse issue form uses: stefanbuck/github-issue-parser@c1a559d78bfb8dd05216dab9ffd2b91082ff5324 # v3.0.1 diff --git a/.github/workflows/prepare-release.yml b/.github/workflows/prepare-release.yml index 88195cb55..d4d3e7bc6 100644 --- a/.github/workflows/prepare-release.yml +++ b/.github/workflows/prepare-release.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout Code - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + uses: actions/checkout@v4 with: submodules: true diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 2c71b2203..f2b00cc2b 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -18,7 +18,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + uses: actions/checkout@v4 with: submodules: false @@ -175,7 +175,7 @@ jobs: - prepare-packages steps: - name: Checkout code - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + uses: actions/checkout@v4 with: submodules: false diff --git a/.github/workflows/terminate-baas.yml b/.github/workflows/terminate-baas.yml index d2add5642..547d5a32a 100644 --- a/.github/workflows/terminate-baas.yml +++ b/.github/workflows/terminate-baas.yml @@ -21,7 +21,7 @@ jobs: working-directory: packages/realm_dart # TODO: Move out of realm_dart steps: - name: Checkout - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + uses: actions/checkout@v4 with: submodules: false From 80853492014b13b4d34416a5d2ab09ac2b05318e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 21 Feb 2024 00:44:07 +0100 Subject: [PATCH 068/153] Update upload-artifact action to v4 --- .github/workflows/binary-combine-android.yml | 2 +- .github/workflows/binary-combine-ios.yml | 2 +- .github/workflows/build-native.yml | 2 +- .github/workflows/publish-release.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/binary-combine-android.yml b/.github/workflows/binary-combine-android.yml index 5e2f20ecb..f57efe5e1 100644 --- a/.github/workflows/binary-combine-android.yml +++ b/.github/workflows/binary-combine-android.yml @@ -31,7 +31,7 @@ jobs: path: packages/realm_dart/binary/android - name: Store combined artifact - uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb + uses: actions/upload-artifact@v4 with: name: librealm-android path: packages/realm_dart/binary/android diff --git a/.github/workflows/binary-combine-ios.yml b/.github/workflows/binary-combine-ios.yml index d2646f41e..174bfc2c2 100644 --- a/.github/workflows/binary-combine-ios.yml +++ b/.github/workflows/binary-combine-ios.yml @@ -36,7 +36,7 @@ jobs: rm -rf ./binary/ios/Release-* - name: Store .xcframework artifact - uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb + uses: actions/upload-artifact@v4 with: name: librealm-ios path: binary/ios diff --git a/.github/workflows/build-native.yml b/.github/workflows/build-native.yml index a66d7ad26..f749e9ccc 100644 --- a/.github/workflows/build-native.yml +++ b/.github/workflows/build-native.yml @@ -61,7 +61,7 @@ jobs: cmake --build --preset ${{ matrix.build }} --config Release ${{ startsWith(matrix.build, 'android-') && '--target strip' || '' }} - name: Store artifacts - uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb + uses: actions/upload-artifact@v4 with: name: librealm-${{ matrix.build }} path: packages/realm_dart/binary/${{ inputs.binary }}/** diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index f2b00cc2b..c2ff2e70c 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -140,7 +140,7 @@ jobs: shell: pwsh - name: Upload release folder - uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb + uses: actions/upload-artifact@v4 with: name: release-bundle path: release/** From 4cc49bf472b7cfe2bde7d8ea2f433b81bb822a0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 21 Feb 2024 00:56:58 +0100 Subject: [PATCH 069/153] Update download-artifact action to v4 --- .github/workflows/binary-combine-android.yml | 8 ++++---- .github/workflows/binary-combine-ios.yml | 6 +++--- .github/workflows/ci.yml | 4 ++-- .github/workflows/dart-desktop-tests.yml | 2 +- .github/workflows/flutter-desktop-tests.yml | 2 +- .github/workflows/publish-release.yml | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/binary-combine-android.yml b/.github/workflows/binary-combine-android.yml index f57efe5e1..3b545bfa0 100644 --- a/.github/workflows/binary-combine-android.yml +++ b/.github/workflows/binary-combine-android.yml @@ -10,22 +10,22 @@ jobs: runs-on: ubuntu-latest steps: - name: Fetch x86 build - uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7 + uses: actions/download-artifact@v4 with: name: librealm-android-x86 path: packages/realm_dart/binary/android - name: Fetch x86_64 build - uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7 + uses: actions/download-artifact@v4 with: name: librealm-android-x86_64 path: packages/realm_dart/binary/android - name: Fetch armeabi-v7a build - uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7 + uses: actions/download-artifact@v4 with: name: librealm-android-armeabi-v7a path: packages/realm_dart/binary/android - name: Fetch arm64-v8a build - uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7 + uses: actions/download-artifact@v4 with: name: librealm-android-arm64-v8a path: packages/realm_dart/binary/android diff --git a/.github/workflows/binary-combine-ios.yml b/.github/workflows/binary-combine-ios.yml index 174bfc2c2..579378d56 100644 --- a/.github/workflows/binary-combine-ios.yml +++ b/.github/workflows/binary-combine-ios.yml @@ -11,17 +11,17 @@ jobs: steps: - name: Fetch device build - uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7 + uses: actions/download-artifact@v4 with: name: librealm-ios-device path: binary/ios - name: Fetch simulator build - uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7 + uses: actions/download-artifact@v4 with: name: librealm-ios-simulator path: binary/ios - name: Fetch catalyst build - uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7 + uses: actions/download-artifact@v4 with: name: librealm-ios-catalyst path: binary/ios diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e9aecb3d2..7c7fca1e3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -302,7 +302,7 @@ jobs: run: echo "PATH=/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" >> $GITHUB_ENV - name: Fetch artifacts - uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7 + uses: actions/download-artifact@v4 with: name: librealm-ios path: packages/realm_dart/binary/ios @@ -398,7 +398,7 @@ jobs: java-version: 11 - name: Fetch artifacts - uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7 + uses: actions/download-artifact@v4 with: name: librealm-android path: packages/realm_dart/binary/android diff --git a/.github/workflows/dart-desktop-tests.yml b/.github/workflows/dart-desktop-tests.yml index 468758d79..b679a1c60 100644 --- a/.github/workflows/dart-desktop-tests.yml +++ b/.github/workflows/dart-desktop-tests.yml @@ -38,7 +38,7 @@ jobs: submodules: false - name: Fetch artifacts - uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7 + uses: actions/download-artifact@v4 with: name: librealm-${{ inputs.os }} path: packages/realm_dart/binary/${{ inputs.os }} diff --git a/.github/workflows/flutter-desktop-tests.yml b/.github/workflows/flutter-desktop-tests.yml index 70c2db541..a14ebfaf7 100644 --- a/.github/workflows/flutter-desktop-tests.yml +++ b/.github/workflows/flutter-desktop-tests.yml @@ -53,7 +53,7 @@ jobs: uses: seanmiddleditch/gha-setup-ninja@1815f2d05c2cd60c2d900f89843139b8dde09f4c - name: Fetch artifacts - uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7 + uses: actions/download-artifact@v4 with: name: librealm-${{ inputs.os }} path: packages/realm_dart/binary/${{ inputs.os }} diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index c2ff2e70c..4db61e4a6 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -180,7 +180,7 @@ jobs: submodules: false - name: Download release folder - uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7 + uses: actions/download-artifact@v4 with: name: release-bundle path: release From d5666940b4254ff9fc16bde6027ee8db020ed175 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 21 Feb 2024 01:10:30 +0100 Subject: [PATCH 070/153] Update dorny/test-reporter action to v1.8.0 --- .github/workflows/ci.yml | 4 ++-- .github/workflows/dart-desktop-tests.yml | 2 +- .github/workflows/flutter-desktop-tests.yml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7c7fca1e3..e68ec756e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -336,7 +336,7 @@ jobs: --suppress-analytics - name: Publish Test Report - uses: dorny/test-reporter@v1.7.0 + uses: dorny/test-reporter@v1.8.0 if: success() || failure() with: name: Test Results Flutter iOS @@ -457,7 +457,7 @@ jobs: script: cd packages/realm/tests && flutter test integration_test/all_tests.dart --dart-define=BAAS_BAASAAS_API_KEY=$BAAS_BAASAAS_API_KEY --dart-define=BAAS_DIFFERENTIATOR=$BAAS_DIFFERENTIATOR --file-reporter=json:test-results.json --suppress-analytics - name: Publish Test Report - uses: dorny/test-reporter@v1.7.0 + uses: dorny/test-reporter@v1.8.0 if: success() || failure() with: name: Test Results Flutter Android diff --git a/.github/workflows/dart-desktop-tests.yml b/.github/workflows/dart-desktop-tests.yml index b679a1c60..cacda5a04 100644 --- a/.github/workflows/dart-desktop-tests.yml +++ b/.github/workflows/dart-desktop-tests.yml @@ -64,7 +64,7 @@ jobs: # TODO: Publish all reports - name: Publish Test Report - uses: dorny/test-reporter@v1.7.0 + uses: dorny/test-reporter@v1.8.0 if: success() || failure() with: name: Test Results Dart ${{ inputs.os }} ${{ inputs.architecture }} diff --git a/.github/workflows/flutter-desktop-tests.yml b/.github/workflows/flutter-desktop-tests.yml index a14ebfaf7..e7302710c 100644 --- a/.github/workflows/flutter-desktop-tests.yml +++ b/.github/workflows/flutter-desktop-tests.yml @@ -92,7 +92,7 @@ jobs: working-directory: packages/realm/tests - name: Publish Test Report - uses: dorny/test-reporter@v1.7.0 + uses: dorny/test-reporter@v1.8.0 if: success() || failure() with: name: Test Results Flutter ${{ inputs.os }} ${{ inputs.architecture }} From 220c426254b4d687fe560ad95239bb2834d418d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 21 Feb 2024 01:22:45 +0100 Subject: [PATCH 071/153] Skip redundant step --- .github/workflows/ci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e68ec756e..97f911a86 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -563,9 +563,6 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} parallel-finished: true - - name: Output Coveralls response - run: echo ${{ steps.publish-coverage.outputs.coveralls-api-result }} - slack-on-failure: name: Report failure in main branch needs: From b02e8726fe1a78a92f08a9b477457dce00a3ab9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 21 Feb 2024 07:40:16 +0100 Subject: [PATCH 072/153] Update actions/setup-java action to v4 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 97f911a86..bd0d9c412 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -392,7 +392,7 @@ jobs: uses: gradle/gradle-build-action@v2 - name: Set up Java - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: 11 From 0e2045305b7d905fb90e999e6c1f2fc7b320befa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 21 Feb 2024 07:41:41 +0100 Subject: [PATCH 073/153] Update gradle/gradle-build-action action to v3 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bd0d9c412..088f86949 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -389,7 +389,7 @@ jobs: sudo udevadm trigger --name-match=kvm - name: Gradle cache - uses: gradle/gradle-build-action@v2 + uses: gradle/gradle-build-action@v3 - name: Set up Java uses: actions/setup-java@v4 From 6b2804797b85a905c620fb7094b8501e8bcc0203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 21 Feb 2024 08:32:13 +0100 Subject: [PATCH 074/153] Don't use random github action to install ninja-build. It is not maintained --- .github/workflows/build-native.yml | 5 +++-- .github/workflows/flutter-desktop-tests.yml | 8 ++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build-native.yml b/.github/workflows/build-native.yml index f749e9ccc..d79d1d28c 100644 --- a/.github/workflows/build-native.yml +++ b/.github/workflows/build-native.yml @@ -41,10 +41,11 @@ jobs: path: ./packages/realm_dart/binary/** key: binaries-${{ matrix.build }}-${{ inputs.runner }}-${{hashFiles('./packages/realm_dart/src/**')}} - - name: Setup Ninja if: steps.check-cache.outputs.cache-hit != 'true' - uses: seanmiddleditch/gha-setup-ninja@1815f2d05c2cd60c2d900f89843139b8dde09f4c + run: | + sudo apt-get update -y + sudo apt-get install -y ninja-build - name: Setup Android NDK if: startsWith(matrix.build, 'android-') diff --git a/.github/workflows/flutter-desktop-tests.yml b/.github/workflows/flutter-desktop-tests.yml index e7302710c..59df0e196 100644 --- a/.github/workflows/flutter-desktop-tests.yml +++ b/.github/workflows/flutter-desktop-tests.yml @@ -42,15 +42,11 @@ jobs: with: submodules: false - - name: Setup GTK + - name: Setup GTK & Ninja on Linux if: ${{ inputs.os == 'linux' }} run: | sudo apt-get update -y - sudo apt-get install -y libgtk-3-dev xvfb - - - name: Setup Ninja - if: ${{ inputs.os == 'linux' }} - uses: seanmiddleditch/gha-setup-ninja@1815f2d05c2cd60c2d900f89843139b8dde09f4c + sudo apt-get install -y libgtk-3-dev xvfb ninja-build - name: Fetch artifacts uses: actions/download-artifact@v4 From a7645d77863453146f41ab7a39073ff2163a24ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 21 Feb 2024 09:07:55 +0100 Subject: [PATCH 075/153] Update futureware-tech/simulator-action action to v3 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 088f86949..88a5dc7f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -321,7 +321,7 @@ jobs: run: dart pub get - name: Launch Simulator - uses: futureware-tech/simulator-action@v2 + uses: futureware-tech/simulator-action@v3 with: model: 'iPhone 8' os: 'iOS' From ac51e940cdc75ac772f1198a28572683a47cf5d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 21 Feb 2024 09:18:47 +0100 Subject: [PATCH 076/153] Update geekyeggo/delete-artifact action to v4 --- .github/workflows/binary-combine-android.yml | 5 +++-- .github/workflows/binary-combine-ios.yml | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/binary-combine-android.yml b/.github/workflows/binary-combine-android.yml index 3b545bfa0..d41d28c78 100644 --- a/.github/workflows/binary-combine-android.yml +++ b/.github/workflows/binary-combine-android.yml @@ -38,10 +38,11 @@ jobs: retention-days: 1 - name: Delete individual build artifacts - uses: geekyeggo/delete-artifact@54ab544f12cdb7b71613a16a2b5a37a9ade990af + uses: geekyeggo/delete-artifact@v4 with: name: | librealm-android-x86 librealm-android-x86_64 librealm-android-armeabi-v7a - librealm-android-arm64-v8a \ No newline at end of file + librealm-android-arm64-v8a + failOnError: false diff --git a/.github/workflows/binary-combine-ios.yml b/.github/workflows/binary-combine-ios.yml index 579378d56..3ebc2c9a7 100644 --- a/.github/workflows/binary-combine-ios.yml +++ b/.github/workflows/binary-combine-ios.yml @@ -43,9 +43,10 @@ jobs: retention-days: 1 - name: Delete individual framework artifacts - uses: geekyeggo/delete-artifact@54ab544f12cdb7b71613a16a2b5a37a9ade990af + uses: geekyeggo/delete-artifact@v4 with: name: | librealm-ios-device librealm-ios-simulator librealm-ios-catalyst + failOnError: false From aab77f2ab7919ec5493745b96fc38b50a053903e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 21 Feb 2024 10:55:20 +0100 Subject: [PATCH 077/153] Fix symlink blunder --- packages/ejson/analysis_options.yaml | 2 +- packages/ejson_analyzer/analysis_options.yaml | 2 +- packages/ejson_annotation/analysis_options.yaml | 2 +- packages/ejson_generator/analysis_options.yaml | 2 +- packages/ejson_lint/analysis_options.yaml | 2 +- packages/ejson_lint/example/analysis_options.yaml | 2 +- packages/realm/analysis_options.yaml | 2 +- packages/realm/example/analysis_options.yaml | 2 +- packages/realm/tests/analysis_options.yaml | 2 +- packages/realm_common/analysis_options.yaml | 2 +- packages/realm_dart/analysis_options.yaml | 2 +- packages/realm_dart/example/analysis_options.yaml | 2 +- packages/realm_generator/analysis_options.yaml | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/ejson/analysis_options.yaml b/packages/ejson/analysis_options.yaml index 39c772ad4..55b28ee2d 120000 --- a/packages/ejson/analysis_options.yaml +++ b/packages/ejson/analysis_options.yaml @@ -1 +1 @@ -analysis_options.yaml \ No newline at end of file +/Users/kasper/Projects/mongodb/realm-dart/analysis_options.yaml \ No newline at end of file diff --git a/packages/ejson_analyzer/analysis_options.yaml b/packages/ejson_analyzer/analysis_options.yaml index 39c772ad4..55b28ee2d 120000 --- a/packages/ejson_analyzer/analysis_options.yaml +++ b/packages/ejson_analyzer/analysis_options.yaml @@ -1 +1 @@ -analysis_options.yaml \ No newline at end of file +/Users/kasper/Projects/mongodb/realm-dart/analysis_options.yaml \ No newline at end of file diff --git a/packages/ejson_annotation/analysis_options.yaml b/packages/ejson_annotation/analysis_options.yaml index 39c772ad4..55b28ee2d 120000 --- a/packages/ejson_annotation/analysis_options.yaml +++ b/packages/ejson_annotation/analysis_options.yaml @@ -1 +1 @@ -analysis_options.yaml \ No newline at end of file +/Users/kasper/Projects/mongodb/realm-dart/analysis_options.yaml \ No newline at end of file diff --git a/packages/ejson_generator/analysis_options.yaml b/packages/ejson_generator/analysis_options.yaml index 39c772ad4..55b28ee2d 120000 --- a/packages/ejson_generator/analysis_options.yaml +++ b/packages/ejson_generator/analysis_options.yaml @@ -1 +1 @@ -analysis_options.yaml \ No newline at end of file +/Users/kasper/Projects/mongodb/realm-dart/analysis_options.yaml \ No newline at end of file diff --git a/packages/ejson_lint/analysis_options.yaml b/packages/ejson_lint/analysis_options.yaml index 39c772ad4..55b28ee2d 120000 --- a/packages/ejson_lint/analysis_options.yaml +++ b/packages/ejson_lint/analysis_options.yaml @@ -1 +1 @@ -analysis_options.yaml \ No newline at end of file +/Users/kasper/Projects/mongodb/realm-dart/analysis_options.yaml \ No newline at end of file diff --git a/packages/ejson_lint/example/analysis_options.yaml b/packages/ejson_lint/example/analysis_options.yaml index 39c772ad4..55b28ee2d 120000 --- a/packages/ejson_lint/example/analysis_options.yaml +++ b/packages/ejson_lint/example/analysis_options.yaml @@ -1 +1 @@ -analysis_options.yaml \ No newline at end of file +/Users/kasper/Projects/mongodb/realm-dart/analysis_options.yaml \ No newline at end of file diff --git a/packages/realm/analysis_options.yaml b/packages/realm/analysis_options.yaml index 39c772ad4..55b28ee2d 120000 --- a/packages/realm/analysis_options.yaml +++ b/packages/realm/analysis_options.yaml @@ -1 +1 @@ -analysis_options.yaml \ No newline at end of file +/Users/kasper/Projects/mongodb/realm-dart/analysis_options.yaml \ No newline at end of file diff --git a/packages/realm/example/analysis_options.yaml b/packages/realm/example/analysis_options.yaml index 39c772ad4..55b28ee2d 120000 --- a/packages/realm/example/analysis_options.yaml +++ b/packages/realm/example/analysis_options.yaml @@ -1 +1 @@ -analysis_options.yaml \ No newline at end of file +/Users/kasper/Projects/mongodb/realm-dart/analysis_options.yaml \ No newline at end of file diff --git a/packages/realm/tests/analysis_options.yaml b/packages/realm/tests/analysis_options.yaml index 39c772ad4..55b28ee2d 120000 --- a/packages/realm/tests/analysis_options.yaml +++ b/packages/realm/tests/analysis_options.yaml @@ -1 +1 @@ -analysis_options.yaml \ No newline at end of file +/Users/kasper/Projects/mongodb/realm-dart/analysis_options.yaml \ No newline at end of file diff --git a/packages/realm_common/analysis_options.yaml b/packages/realm_common/analysis_options.yaml index 39c772ad4..55b28ee2d 120000 --- a/packages/realm_common/analysis_options.yaml +++ b/packages/realm_common/analysis_options.yaml @@ -1 +1 @@ -analysis_options.yaml \ No newline at end of file +/Users/kasper/Projects/mongodb/realm-dart/analysis_options.yaml \ No newline at end of file diff --git a/packages/realm_dart/analysis_options.yaml b/packages/realm_dart/analysis_options.yaml index 39c772ad4..55b28ee2d 120000 --- a/packages/realm_dart/analysis_options.yaml +++ b/packages/realm_dart/analysis_options.yaml @@ -1 +1 @@ -analysis_options.yaml \ No newline at end of file +/Users/kasper/Projects/mongodb/realm-dart/analysis_options.yaml \ No newline at end of file diff --git a/packages/realm_dart/example/analysis_options.yaml b/packages/realm_dart/example/analysis_options.yaml index 39c772ad4..55b28ee2d 120000 --- a/packages/realm_dart/example/analysis_options.yaml +++ b/packages/realm_dart/example/analysis_options.yaml @@ -1 +1 @@ -analysis_options.yaml \ No newline at end of file +/Users/kasper/Projects/mongodb/realm-dart/analysis_options.yaml \ No newline at end of file diff --git a/packages/realm_generator/analysis_options.yaml b/packages/realm_generator/analysis_options.yaml index 39c772ad4..55b28ee2d 120000 --- a/packages/realm_generator/analysis_options.yaml +++ b/packages/realm_generator/analysis_options.yaml @@ -1 +1 @@ -analysis_options.yaml \ No newline at end of file +/Users/kasper/Projects/mongodb/realm-dart/analysis_options.yaml \ No newline at end of file From 475e2208c70c2f26c3cbae58942f51c9fc08491e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 21 Feb 2024 11:23:32 +0100 Subject: [PATCH 078/153] Tighten analysis rules --- analysis_options.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 43748cf3a..2b8e1834a 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -2,8 +2,10 @@ include: package:lints/recommended.yaml analyzer: - language: - strict-raw-types: true + language: + strict-casts: true # see https://github.com/dart-lang/language/blob/main/resources/type-system/strict-casts.md + strict-inference: true # see https://github.com/dart-lang/language/blob/main/resources/type-system/strict-inference.md + strict-raw-types: true # see https://github.com/dart-lang/language/blob/main/resources/type-system/strict-raw-types.md strong-mode: implicit-casts: false From 74952150c78f87bf054827289937229276c68c8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 21 Feb 2024 11:50:42 +0100 Subject: [PATCH 079/153] add upgrade script to melos.yaml --- melos.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/melos.yaml b/melos.yaml index 6a71e5da6..8e961583b 100644 --- a/melos.yaml +++ b/melos.yaml @@ -126,7 +126,11 @@ scripts: format: description: Format code. - run: dart format --fix --line-length 160 . + run: dart format --fix --line-length 160 . + + upgrade: + description: Upgrade all dependencies. + exec: dart pub upgrade --major-versions lint: description: Run all lints. From a577df271933cc0f3b951de7d5f032e951d39e4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 21 Feb 2024 11:51:41 +0100 Subject: [PATCH 080/153] bump custom_lint_builder --- packages/ejson_lint/example/pubspec.yaml | 2 +- packages/ejson_lint/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ejson_lint/example/pubspec.yaml b/packages/ejson_lint/example/pubspec.yaml index d867df5fa..171fd2d3c 100644 --- a/packages/ejson_lint/example/pubspec.yaml +++ b/packages/ejson_lint/example/pubspec.yaml @@ -11,7 +11,7 @@ dependencies: ejson_annotation: ^0.1.0 dev_dependencies: - custom_lint: ^0.5.7 + custom_lint: ^0.6.2 ejson_lint: ^0.1.0 lints: ^3.0.0 diff --git a/packages/ejson_lint/pubspec.yaml b/packages/ejson_lint/pubspec.yaml index 537daee6b..53af72f5d 100644 --- a/packages/ejson_lint/pubspec.yaml +++ b/packages/ejson_lint/pubspec.yaml @@ -9,7 +9,7 @@ environment: dependencies: analyzer: ^6.0.0 - custom_lint_builder: ^0.5.7 + custom_lint_builder: ^0.6.2 ejson_analyzer: ^0.1.0 dev_dependencies: From 89bfa58c634722056616fa586514843a3f3f2bbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 21 Feb 2024 17:11:28 +0100 Subject: [PATCH 081/153] tweak publish-release.yml --- .github/workflows/publish-release.yml | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 4db61e4a6..0a266cc87 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -190,16 +190,16 @@ jobs: with: channel: 'stable' + - name: Setup Melos + run: | + dart pub global activate melos + dart pub global run melos bootstrap + - name: Publish packages to pub.dev run: | mkdir -p $HOME/.config/dart echo '${{ secrets.PUB_CREDENTIALS }}' >> $HOME/.config/dart/pub-credentials.json - - dart pub publish --directory realm_common --force - dart pub publish --directory realm_generator --force - dart pub publish --directory realm_dart --force - dart pub publish --directory realm --force - working-directory: release + melos publish --no-dry-run --yes - name: Find Release PR uses: juliangruber/find-pull-request-action@f9f7484f8237cf8485e5ab826e542ba5dd9e9c6e @@ -217,7 +217,6 @@ jobs: - name: Publish Github Release uses: ncipollo/release-action@10c84d509b28aae3903113151bfd832314964f2e with: - artifacts: release/*.tar.gz bodyFile: release/ExtractedChangelog.md name: ${{ needs.prepare-packages.outputs.version }} commit: main @@ -225,7 +224,7 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} draft: false - - name: 'Post to #realm-releases' + - name: 'Post to #appx-releases' uses: realm/ci-actions/release-to-slack@338bf3e7575015a28faec8b67614385d122aece7 continue-on-error: true with: From cedaa52fceff0b2f334dd4bb5bd9adae10de34a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Thu, 22 Feb 2024 09:53:57 +0100 Subject: [PATCH 082/153] Update format and lint:format to not touch generated files (workaround for https://github.com/dart-lang/dart_style/issues/864) --- melos.yaml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/melos.yaml b/melos.yaml index 8e961583b..24acda796 100644 --- a/melos.yaml +++ b/melos.yaml @@ -126,7 +126,12 @@ scripts: format: description: Format code. - run: dart format --fix --line-length 160 . + # while we wait for https://github.com/dart-lang/dart_style/issues/864 + run: >- + find lib test integration_test -name '*.dart' -not -name '*.g.dart' -not -name '*.realm.dart' -not -name 'realm_bindings.dart' + | xargs dart format --fix --line-length 160 + exec: + concurrency: 1 # only one project at a time to keep output sane upgrade: description: Upgrade all dependencies. @@ -140,8 +145,11 @@ scripts: melos publish --dry-run lint:format: - run: dart format --fix --line-length 160 --output none --set-exit-if-changed . - exec: + # while we wait for https://github.com/dart-lang/dart_style/issues/864 + run: >- + find lib test integration_test -name '*.dart' -not -name '*.g.dart' -not -name '*.realm.dart' -not -name 'realm_bindings.dart' + | xargs dart format --fix --line-length 160 --output none --set-exit-if-changed + exec: concurrency: 1 # only one project at a time to keep output sane lint:pana: From b6bdf0b167af49b5a78a7a5f527c5aa275298014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Thu, 22 Feb 2024 11:20:59 +0100 Subject: [PATCH 083/153] Implicit casts made explicit, as mandated by stricter analysis_options.yaml --- packages/ejson/lib/src/decoding.dart | 4 ++-- packages/ejson_generator/test/compile_test.dart | 2 +- packages/realm_dart/lib/src/cli/atlas_apps/baas_client.dart | 6 +++--- packages/realm_dart/tool/build_native.dart | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/ejson/lib/src/decoding.dart b/packages/ejson/lib/src/decoding.dart index 13d1f1dfb..198e479c9 100644 --- a/packages/ejson/lib/src/decoding.dart +++ b/packages/ejson/lib/src/decoding.dart @@ -74,9 +74,9 @@ T fromEJson(EJsonValue ejson) { } final args = nullable ? [type.nonNull] : type.args; if (args.isEmpty) { - return decoder(ejson); // minor optimization + return decoder(ejson) as T; // minor optimization } - return decoder.callWith(typeArguments: args, parameters: [ejson]); + return decoder.callWith(typeArguments: args, parameters: [ejson]) as T; } // Important to return `T` as opposed to [Never] for type inference to work diff --git a/packages/ejson_generator/test/compile_test.dart b/packages/ejson_generator/test/compile_test.dart index 96a629512..60be3efea 100644 --- a/packages/ejson_generator/test/compile_test.dart +++ b/packages/ejson_generator/test/compile_test.dart @@ -31,7 +31,7 @@ void testCompile(String description, dynamic source, dynamic matcher, final writer = InMemoryAssetWriter(); await testBuilder( getEJsonGenerator(), - {'pkg|source.dart': source}, + {'pkg|source.dart': source as Object}, writer: writer, reader: await PackageAssetReader.currentIsolate(), ); diff --git a/packages/realm_dart/lib/src/cli/atlas_apps/baas_client.dart b/packages/realm_dart/lib/src/cli/atlas_apps/baas_client.dart index dba3f0d6d..398cef20c 100644 --- a/packages/realm_dart/lib/src/cli/atlas_apps/baas_client.dart +++ b/packages/realm_dart/lib/src/cli/atlas_apps/baas_client.dart @@ -200,7 +200,7 @@ class BaasClient { } static Future> _getContainers(BaasAuthHelper helper, {String? differentiator}) async { - var result = (await helper.callEndpoint('listContainers', isPost: false) as List).map((e) => _ContainerInfo.fromJson(e)).whereNotNull(); + var result = (await helper.callEndpoint('listContainers', isPost: false) as List>).map((e) => _ContainerInfo.fromJson(e)).whereNotNull(); if (differentiator != null) { final userId = await helper.getUserId(); result = result.where((c) => c.creatorId == userId && c.tags['DIFFERENTIATOR'] == differentiator); @@ -282,7 +282,7 @@ class BaasClient { try { final response = await _get('groups/$_groupId/apps/$appId/sync/progress'); - Map progressInfo = response['progress']; + final progressInfo = response['progress'] as Map; for (final key in progressInfo.keys) { final namespaceComplete = progressInfo[key]['complete'] as bool; @@ -736,7 +736,7 @@ class _ContainerInfo { } final id = json['id'] as String; - final lastStatus = json['lastStatus']; + final lastStatus = json['lastStatus'] as String; final tags = {for (var v in json['tags'] as List) v['key'] as String: v['value'] as String}; final creatorId = json['creatorId'] as String; diff --git a/packages/realm_dart/tool/build_native.dart b/packages/realm_dart/tool/build_native.dart index 704e4b68e..bf0037df9 100644 --- a/packages/realm_dart/tool/build_native.dart +++ b/packages/realm_dart/tool/build_native.dart @@ -80,8 +80,8 @@ void main(List arguments) { final argResults = parser.parse(arguments); final hostOS = OS.from(io.Platform.operatingSystem); - final targetOs = OS.from(argResults['target']); - final buildMode = BuildMode.from(argResults['mode']); + final targetOs = OS.from(argResults['target'] as String); + final buildMode = BuildMode.from(argResults['mode'] as String); print(io.Platform.operatingSystem); } From cb8b38ed7f379b3b0e3ed15124cc466fba7f99d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Thu, 22 Feb 2024 14:47:30 +0100 Subject: [PATCH 084/153] melos run format --- packages/ejson/lib/src/decoding.dart | 14 +++++--------- packages/ejson/lib/src/encoding.dart | 11 +++-------- packages/ejson/lib/src/types.dart | 3 +-- packages/ejson/test/ejson_test.dart | 8 ++------ packages/ejson/test/person.dart | 10 ++-------- .../lib/src/ejson_analyzer_base.dart | 3 +-- .../ejson_generator/lib/src/generator.dart | 11 +++-------- .../ejson_generator/test/compile_test.dart | 16 +++++----------- packages/ejson_generator/test/ctor_test.dart | 3 +-- .../lib/src/lints/mismatched_getter_type.dart | 3 +-- .../lints/too_many_annotated_constructors.dart | 9 +++------ packages/realm_common/lib/realm_common.dart | 2 +- packages/realm_dart/lib/realm.dart | 3 +-- .../lib/src/cli/archive/options.dart | 4 ++-- .../lib/src/cli/atlas_apps/baas_client.dart | 3 ++- .../lib/src/cli/extract/options.dart | 4 ++-- .../lib/src/cli/generate/options.dart | 5 ++++- .../realm_dart/test/realm_value_test.g.dart | 18 +++++++++++++++--- .../lib/src/expanded_context_span.dart | 9 ++++----- .../realm_object_reference_default_values.dart | 2 +- 20 files changed, 59 insertions(+), 82 deletions(-) diff --git a/packages/ejson/lib/src/decoding.dart b/packages/ejson/lib/src/decoding.dart index 198e479c9..7b1296f2c 100644 --- a/packages/ejson/lib/src/decoding.dart +++ b/packages/ejson/lib/src/decoding.dart @@ -101,8 +101,7 @@ dynamic _decodeAny(EJsonValue ejson) { {'\$oid': _} => _decodeObjectId(ejson), {'\$binary': {'base64': _, 'subType': '04'}} => _decodeUuid(ejson), List _ => _decodeArray(ejson), - Map _ => _tryDecodeCustom(ejson) ?? - _decodeDocument(ejson), // other maps goes last!! + Map _ => _tryDecodeCustom(ejson) ?? _decodeDocument(ejson), // other maps goes last!! _ => raiseInvalidEJson(ejson), }; } @@ -135,8 +134,7 @@ bool _decodeBool(EJsonValue ejson) { DateTime _decodeDate(EJsonValue ejson) { return switch (ejson) { {'\$date': String s} => DateTime.parse(s), // relaxed mode - {'\$date': {'\$numberLong': int i}} => - DateTime.fromMillisecondsSinceEpoch(i), + {'\$date': {'\$numberLong': int i}} => DateTime.fromMillisecondsSinceEpoch(i), _ => raiseInvalidEJson(ejson), }; } @@ -172,7 +170,7 @@ int _decodeInt(EJsonValue ejson) { int i => i, // relaxed mode {'\$numberInt': int i} => i, {'\$numberLong': int i} => i, - _ => raiseInvalidEJson(ejson) + _ => raiseInvalidEJson(ejson), }; } @@ -244,13 +242,11 @@ UndefinedOr _decodeUndefinedOr(EJsonValue ejson) { }; } -Uuid _decodeUuid(EJsonValue ejson) => - Uuid.fromBytes(_decodeBinary(ejson, "04")); +Uuid _decodeUuid(EJsonValue ejson) => Uuid.fromBytes(_decodeBinary(ejson, "04")); ByteBuffer _decodeBinary(EJsonValue ejson, String subType) { return switch (ejson) { - {'\$binary': {'base64': String s, 'subType': String t}} when t == subType => - base64.decode(s).buffer, + {'\$binary': {'base64': String s, 'subType': String t}} when t == subType => base64.decode(s).buffer, _ => raiseInvalidEJson(ejson), }; } diff --git a/packages/ejson/lib/src/encoding.dart b/packages/ejson/lib/src/encoding.dart index 5101016e0..100896ffe 100644 --- a/packages/ejson/lib/src/encoding.dart +++ b/packages/ejson/lib/src/encoding.dart @@ -57,8 +57,7 @@ EJsonValue _encodeAny(Object? value) { }; } -EJsonValue _encodeArray(Iterable items) => - items.map((e) => toEJson(e)).toList(); +EJsonValue _encodeArray(Iterable items) => items.map((e) => toEJson(e)).toList(); EJsonValue _encodeBool(bool value) => value; @@ -81,8 +80,7 @@ EJsonValue _encodeDate(DateTime value) { EJsonValue _encodeDefined(Defined defined) => toEJson(defined.value); -EJsonValue _encodeDocument(Map map) => - map.map((k, v) => MapEntry(k, toEJson(v))); +EJsonValue _encodeDocument(Map map) => map.map((k, v) => MapEntry(k, toEJson(v))); EJsonValue _encodeDouble(double value) { if (value.isNaN) { @@ -117,10 +115,7 @@ EJsonValue _encodeUndefined(Undefined undefined) => {'\$undefined': 1}; EJsonValue _encodeUuid(Uuid uuid) => _encodeBinary(uuid.bytes, "04"); EJsonValue _encodeBinary(ByteBuffer buffer, String subtype) => { - '\$binary': { - 'base64': base64.encode(buffer.asUint8List()), - 'subType': subtype - }, + '\$binary': {'base64': base64.encode(buffer.asUint8List()), 'subType': subtype}, }; EJsonValue _encodeObjectId(ObjectId objectId) => {'\$oid': objectId.hexString}; diff --git a/packages/ejson/lib/src/types.dart b/packages/ejson/lib/src/types.dart index f636b9fcb..61ae06c2a 100644 --- a/packages/ejson/lib/src/types.dart +++ b/packages/ejson/lib/src/types.dart @@ -73,8 +73,7 @@ final class Defined extends UndefinedOr { int get hashCode => value.hashCode; @override - bool operator ==(Object other) => - identical(this, other) || other is Defined && value == other.value; + bool operator ==(Object other) => identical(this, other) || other is Defined && value == other.value; @override String toString() => 'Defined<$T>($value)'; diff --git a/packages/ejson/test/ejson_test.dart b/packages/ejson/test/ejson_test.dart index 7cb3598da..fb259ba2f 100644 --- a/packages/ejson/test/ejson_test.dart +++ b/packages/ejson/test/ejson_test.dart @@ -151,14 +151,10 @@ void main() { _testCase(const Defined(null), null); _testCase(Defined(42), {'\$numberLong': 42}, 42); _testCase(Defined(null), null); - _testCase(ObjectId.fromValues(1, 2, 3), - {'\$oid': '000000000000000002000003'}); + _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.asUint8List()), 'subType': '04'} }); // a complex nested generic type _testCase?>>>( diff --git a/packages/ejson/test/person.dart b/packages/ejson/test/person.dart index c8a2be4a0..4dfe98ab7 100644 --- a/packages/ejson/test/person.dart +++ b/packages/ejson/test/person.dart @@ -19,16 +19,10 @@ class Person { @override operator ==(other) => - identical(this, other) || - (other is Person && - other.name == name && - other.birthDate == birthDate && - other.income == income && - other.spouse == spouse); + identical(this, other) || (other is Person && other.name == name && other.birthDate == birthDate && other.income == income && other.spouse == spouse); @override - String toString() => - 'Person{name: $name, birthDate: $birthDate, income: $income, spouse: $spouse}'; + String toString() => 'Person{name: $name, birthDate: $birthDate, income: $income, spouse: $spouse}'; @override int get hashCode => Object.hashAll([name, birthDate, income, spouse]); diff --git a/packages/ejson_analyzer/lib/src/ejson_analyzer_base.dart b/packages/ejson_analyzer/lib/src/ejson_analyzer_base.dart index 6fd6f3788..3364099d3 100644 --- a/packages/ejson_analyzer/lib/src/ejson_analyzer_base.dart +++ b/packages/ejson_analyzer/lib/src/ejson_analyzer_base.dart @@ -4,5 +4,4 @@ import 'package:source_gen/source_gen.dart'; TypeChecker get typeChecker => TypeChecker.fromRuntime(EJson); -bool isEJsonAnnotated(Element element) => - typeChecker.hasAnnotationOfExact(element); +bool isEJsonAnnotated(Element element) => typeChecker.hasAnnotationOfExact(element); diff --git a/packages/ejson_generator/lib/src/generator.dart b/packages/ejson_generator/lib/src/generator.dart index 6ee2f342d..492a11d20 100644 --- a/packages/ejson_generator/lib/src/generator.dart +++ b/packages/ejson_generator/lib/src/generator.dart @@ -27,8 +27,7 @@ import 'package:source_gen/source_gen.dart'; extension on EJsonError { String get message => switch (this) { - EJsonError.tooManyAnnotatedConstructors => - 'Too many annotated constructors', + EJsonError.tooManyAnnotatedConstructors => 'Too many annotated constructors', EJsonError.missingGetter => 'Missing getter', EJsonError.mismatchedGetterType => 'Mismatched getter type', }; @@ -50,10 +49,7 @@ class EJsonGenerator extends Generator { @override FutureOr generate(LibraryReader library, BuildStep buildStep) async { // find all classes with annotated constructors or classes directly annotated - final annotated = library.classes - .map((cls) => - (cls, cls.constructors.where((ctor) => isEJsonAnnotated(ctor)))) - .where((element) { + final annotated = library.classes.map((cls) => (cls, cls.constructors.where((ctor) => isEJsonAnnotated(ctor)))).where((element) { final (cls, ctors) = element; return ctors.isNotEmpty || isEJsonAnnotated(cls); }); @@ -77,8 +73,7 @@ class EJsonGenerator extends Generator { if (getter == null) { EJsonError.missingGetter.raise(); } - if (!TypeChecker.fromStatic(p.type) - .isAssignableFromType(getter.returnType)) { + if (!TypeChecker.fromStatic(p.type).isAssignableFromType(getter.returnType)) { EJsonError.mismatchedGetterType.raise(); } } diff --git a/packages/ejson_generator/test/compile_test.dart b/packages/ejson_generator/test/compile_test.dart index 60be3efea..2146deff5 100644 --- a/packages/ejson_generator/test/compile_test.dart +++ b/packages/ejson_generator/test/compile_test.dart @@ -11,16 +11,14 @@ final _formatter = DartFormatter(lineEnding: '\n'); final _tag = RegExp(r'// \*.*\n// EJsonGenerator\n// \*.*'); @isTest -void testCompile(String description, dynamic source, dynamic matcher, - {dynamic skip}) { +void testCompile(String description, dynamic source, dynamic matcher, {dynamic skip}) { source = source is File ? source.readAsStringSync() : source; if (source is! String) throw ArgumentError.value(source, 'source'); matcher = matcher is File ? matcher.readAsStringSync() : matcher; if (matcher is String) { final source = _formatter.format(matcher); - matcher = completion( - equals(source.substring(_tag.firstMatch(source)?.start ?? 0))); + matcher = completion(equals(source.substring(_tag.firstMatch(source)?.start ?? 0))); } matcher ??= completes; // fallback @@ -35,8 +33,7 @@ void testCompile(String description, dynamic source, dynamic matcher, writer: writer, reader: await PackageAssetReader.currentIsolate(), ); - return _formatter - .format(String.fromCharCodes(writer.assets.entries.single.value)); + return _formatter.format(String.fromCharCodes(writer.assets.entries.single.value)); } expect(generate(), matcher); @@ -167,11 +164,8 @@ extension EmptyEJsonEncoderExtension on Empty { ); }); - await for (final generatedFile in Directory.current - .list(recursive: true) - .where((f) => f is File && f.path.endsWith('.g.dart'))) { - final sourceFile = - File(generatedFile.path.replaceFirst('.g.dart', '.dart')); + await for (final generatedFile in Directory.current.list(recursive: true).where((f) => f is File && f.path.endsWith('.g.dart'))) { + final sourceFile = File(generatedFile.path.replaceFirst('.g.dart', '.dart')); testCompile('$sourceFile', sourceFile, generatedFile); } } diff --git a/packages/ejson_generator/test/ctor_test.dart b/packages/ejson_generator/test/ctor_test.dart index 7f4e2565a..cea2c749c 100644 --- a/packages/ejson_generator/test/ctor_test.dart +++ b/packages/ejson_generator/test/ctor_test.dart @@ -127,8 +127,7 @@ void main() { 'i': {'\$numberLong': 42} }); _testCase(Named.nameIt('foobar'), {'namedCtor': 'foobar'}); - _testCase(const RequiredNamedParameters(requiredNamed: 'foobar'), - {'requiredNamed': 'foobar'}); + _testCase(const RequiredNamedParameters(requiredNamed: 'foobar'), {'requiredNamed': 'foobar'}); _testCase(OptionalNamedParameters(), {'optionalNamed': 'rabbit'}); _testCase(OptionalParameters(), {'optional': 'racoon'}); _testCase(const PrivateMembers(42), { diff --git a/packages/ejson_lint/lib/src/lints/mismatched_getter_type.dart b/packages/ejson_lint/lib/src/lints/mismatched_getter_type.dart index d7c9ce416..4b911a419 100644 --- a/packages/ejson_lint/lib/src/lints/mismatched_getter_type.dart +++ b/packages/ejson_lint/lib/src/lints/mismatched_getter_type.dart @@ -9,8 +9,7 @@ class MismatchedGetterType extends DartLintRule { : super( code: const LintCode( name: 'mismatched_getter_type', - problemMessage: - 'Type of getter does not match type of constructor parameter', + problemMessage: 'Type of getter does not match type of constructor parameter', errorSeverity: ErrorSeverity.ERROR, ), ); diff --git a/packages/ejson_lint/lib/src/lints/too_many_annotated_constructors.dart b/packages/ejson_lint/lib/src/lints/too_many_annotated_constructors.dart index 998e2be52..a1822e1b3 100644 --- a/packages/ejson_lint/lib/src/lints/too_many_annotated_constructors.dart +++ b/packages/ejson_lint/lib/src/lints/too_many_annotated_constructors.dart @@ -7,8 +7,7 @@ abstract class EJsonLintRule extends DartLintRule { EJsonLintRule({required super.code}); @override - Future startUp( - CustomLintResolver resolver, CustomLintContext context) async { + Future startUp(CustomLintResolver resolver, CustomLintContext context) async { return await super.startUp(resolver, context); } } @@ -18,8 +17,7 @@ class TooManyAnnotatedConstructors extends DartLintRule { : super( code: const LintCode( name: 'too_many_annotated_constructors', - problemMessage: - 'Only one constructor can be annotated with @EJson()', + problemMessage: 'Only one constructor can be annotated with @EJson()', errorSeverity: ErrorSeverity.ERROR, ), ); @@ -34,8 +32,7 @@ class TooManyAnnotatedConstructors extends DartLintRule { final cls = node.declaredElement; if (cls == null) return; // not resolved; - final annotatedConstructors = - cls.constructors.where((ctor) => isEJsonAnnotated(ctor)); + final annotatedConstructors = cls.constructors.where((ctor) => isEJsonAnnotated(ctor)); if (annotatedConstructors.length > 1) { for (final ctor in annotatedConstructors) { reporter.reportErrorForElement(code, ctor); diff --git a/packages/realm_common/lib/realm_common.dart b/packages/realm_common/lib/realm_common.dart index 07818387f..3cca805d8 100644 --- a/packages/realm_common/lib/realm_common.dart +++ b/packages/realm_common/lib/realm_common.dart @@ -20,4 +20,4 @@ export 'src/realm_common_base.dart'; export 'src/realm_types.dart'; export 'package:objectid/objectid.dart' show ObjectId; -export 'package:sane_uuid/uuid.dart' show Uuid; \ No newline at end of file +export 'package:sane_uuid/uuid.dart' show Uuid; diff --git a/packages/realm_dart/lib/realm.dart b/packages/realm_dart/lib/realm.dart index 1ed53d3b6..a09767b0f 100644 --- a/packages/realm_dart/lib/realm.dart +++ b/packages/realm_dart/lib/realm.dart @@ -16,6 +16,5 @@ // // ////////////////////////////////////////////////////////////////////////////// - //dart.library.cli is available only on dart desktop -export 'src/realm_flutter.dart' if (dart.library.cli) 'src/realm_dart.dart'; \ No newline at end of file +export 'src/realm_flutter.dart' if (dart.library.cli) 'src/realm_dart.dart'; diff --git a/packages/realm_dart/lib/src/cli/archive/options.dart b/packages/realm_dart/lib/src/cli/archive/options.dart index 2c388ad16..e45f94159 100644 --- a/packages/realm_dart/lib/src/cli/archive/options.dart +++ b/packages/realm_dart/lib/src/cli/archive/options.dart @@ -22,9 +22,9 @@ part 'options.g.dart'; @CliOptions() class Options { - @CliOption(help: "This option is required") + @CliOption(help: "This option is required") final String? sourceDir; - @CliOption(help: "This option is required") + @CliOption(help: "This option is required") final String? outputFile; Options({this.sourceDir, this.outputFile}); diff --git a/packages/realm_dart/lib/src/cli/atlas_apps/baas_client.dart b/packages/realm_dart/lib/src/cli/atlas_apps/baas_client.dart index 398cef20c..13bf0b0a1 100644 --- a/packages/realm_dart/lib/src/cli/atlas_apps/baas_client.dart +++ b/packages/realm_dart/lib/src/cli/atlas_apps/baas_client.dart @@ -200,7 +200,8 @@ class BaasClient { } static Future> _getContainers(BaasAuthHelper helper, {String? differentiator}) async { - var result = (await helper.callEndpoint('listContainers', isPost: false) as List>).map((e) => _ContainerInfo.fromJson(e)).whereNotNull(); + var result = + (await helper.callEndpoint('listContainers', isPost: false) as List>).map((e) => _ContainerInfo.fromJson(e)).whereNotNull(); if (differentiator != null) { final userId = await helper.getUserId(); result = result.where((c) => c.creatorId == userId && c.tags['DIFFERENTIATOR'] == differentiator); diff --git a/packages/realm_dart/lib/src/cli/extract/options.dart b/packages/realm_dart/lib/src/cli/extract/options.dart index 55dd75f7d..b98bd2827 100644 --- a/packages/realm_dart/lib/src/cli/extract/options.dart +++ b/packages/realm_dart/lib/src/cli/extract/options.dart @@ -22,9 +22,9 @@ part 'options.g.dart'; @CliOptions() class Options { - @CliOption(help: "This option is required") + @CliOption(help: "This option is required") final String? outputDir; - @CliOption(help: "This option is required") + @CliOption(help: "This option is required") final String? sourceFile; Options({this.sourceFile, this.outputDir}); diff --git a/packages/realm_dart/lib/src/cli/generate/options.dart b/packages/realm_dart/lib/src/cli/generate/options.dart index 8a460a3ca..a2d05b626 100644 --- a/packages/realm_dart/lib/src/cli/generate/options.dart +++ b/packages/realm_dart/lib/src/cli/generate/options.dart @@ -7,7 +7,10 @@ class Options { @CliOption(defaultsTo: false, help: "Optional. Cleans generator caches. Same as running 'dart run build_runner clean'") bool clean = false; - @CliOption(defaultsTo: false, help: "Optional. Watches for changes and generates RealmObjects classes on the background. Same as running 'dart run build_runner watch --delete-conflicting-outputs'") + @CliOption( + defaultsTo: false, + help: + "Optional. Watches for changes and generates RealmObjects classes on the background. Same as running 'dart run build_runner watch --delete-conflicting-outputs'") bool watch = false; } diff --git a/packages/realm_dart/test/realm_value_test.g.dart b/packages/realm_dart/test/realm_value_test.g.dart index 86644891d..319efcbf1 100644 --- a/packages/realm_dart/test/realm_value_test.g.dart +++ b/packages/realm_dart/test/realm_value_test.g.dart @@ -23,15 +23,27 @@ extension TuckedInEJsonEncoderExtension on TuckedIn { } EJsonValue encodeAnythingGoes(AnythingGoes value) { - return {'oneAny': value.oneAny.toEJson(), 'manyAny': value.manyAny.toEJson()}; + return { + 'oneAny': value.oneAny.toEJson(), + 'manyAny': value.manyAny.toEJson(), + 'setOfAny': value.setOfAny.toEJson(), + 'dictOfAny': value.dictOfAny.toEJson() + }; } AnythingGoes decodeAnythingGoes(EJsonValue ejson) { return switch (ejson) { - {'oneAny': EJsonValue oneAny, 'manyAny': EJsonValue manyAny} => + { + 'oneAny': EJsonValue oneAny, + 'manyAny': EJsonValue manyAny, + 'setOfAny': EJsonValue setOfAny, + 'dictOfAny': EJsonValue dictOfAny + } => AnythingGoes( oneAny: oneAny.to(), - manyAny: manyAny.to>()), + manyAny: manyAny.to>(), + setOfAny: setOfAny.to>(), + dictOfAny: dictOfAny.to>()), _ => raiseInvalidEJson(ejson), }; } diff --git a/packages/realm_generator/lib/src/expanded_context_span.dart b/packages/realm_generator/lib/src/expanded_context_span.dart index 47b1c538d..095e60ae2 100644 --- a/packages/realm_generator/lib/src/expanded_context_span.dart +++ b/packages/realm_generator/lib/src/expanded_context_span.dart @@ -21,11 +21,10 @@ import 'package:source_span/source_span.dart'; class ExpandedContextSpan with SourceSpanMixin implements FileSpan { final FileSpan _span, _contextSpan; - ExpandedContextSpan(this._span, Iterable contextSpans) : - _contextSpan = contextSpans.fold(_span, (acc, c) => acc.expand(c)); + ExpandedContextSpan(this._span, Iterable contextSpans) : _contextSpan = contextSpans.fold(_span, (acc, c) => acc.expand(c)); @override - String get context => _contextSpan.context; + String get context => _contextSpan.context; @override FileLocation get end => _span.end; @@ -46,5 +45,5 @@ class ExpandedContextSpan with SourceSpanMixin implements FileSpan { FileLocation get start => _span.start; @override - String get text => _span.text; -} \ No newline at end of file + String get text => _span.text; +} diff --git a/packages/realm_generator/test/error_test_data/realm_object_reference_default_values.dart b/packages/realm_generator/test/error_test_data/realm_object_reference_default_values.dart index b77305892..5da4b2c31 100644 --- a/packages/realm_generator/test/error_test_data/realm_object_reference_default_values.dart +++ b/packages/realm_generator/test/error_test_data/realm_object_reference_default_values.dart @@ -8,4 +8,4 @@ class _Person { late _Person? parent = Person(); } -class Person extends _Person {} // mock class for testing \ No newline at end of file +class Person extends _Person {} // mock class for testing From 32969908c17450418b976cc26ae6332b98944db4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Thu, 22 Feb 2024 16:04:44 +0100 Subject: [PATCH 085/153] tweak melos.yaml --- melos.yaml | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/melos.yaml b/melos.yaml index 24acda796..e287e41c2 100644 --- a/melos.yaml +++ b/melos.yaml @@ -72,7 +72,8 @@ scripts: dart test --concurrency=1 --coverage=coverage/ - --file-reporter=json:test-results.json && + --file-reporter=json:test-results.json + --reporter=github && dart pub global run coverage:format_coverage --report-on=lib/ --in=coverage/test/ @@ -86,7 +87,7 @@ scripts: flutter: false test:widget: - run: flutter test --concurrency=1 --coverage + run: flutter test --concurrency=1 --coverage --reporter=github exec: concurrency: 1 # only one project at a time to keep output sane packageFilters: @@ -110,6 +111,7 @@ scripts: --dart-define=BAAS_DIFFERENTIATOR='$BAAS_DIFFERENTIATOR' --device-id='$DEVICE_ID' --file-reporter=json:test-results.json + --reporter=github --suppress-analytics exec: concurrency: 1 # only one project at a time to keep output sane @@ -128,7 +130,7 @@ scripts: description: Format code. # while we wait for https://github.com/dart-lang/dart_style/issues/864 run: >- - find lib test integration_test -name '*.dart' -not -name '*.g.dart' -not -name '*.realm.dart' -not -name 'realm_bindings.dart' + find lib test integration_test -name '*.dart' -not -name '*.g.dart' -not -name '*.realm.dart' -not -name 'realm_bindings.dart' 2> /dev/null | xargs dart format --fix --line-length 160 exec: concurrency: 1 # only one project at a time to keep output sane @@ -147,7 +149,7 @@ scripts: lint:format: # while we wait for https://github.com/dart-lang/dart_style/issues/864 run: >- - find lib test integration_test -name '*.dart' -not -name '*.g.dart' -not -name '*.realm.dart' -not -name 'realm_bindings.dart' + find lib test integration_test -name '*.dart' -not -name '*.g.dart' -not -name '*.realm.dart' -not -name 'realm_bindings.dart' 2> /dev/null | xargs dart format --fix --line-length 160 --output none --set-exit-if-changed exec: concurrency: 1 # only one project at a time to keep output sane @@ -174,24 +176,35 @@ scripts: coverage: description: Generate, check and render coverage. run: >- - melos run test && - melos run coverage:check && - melos run coverage:report + melos run coverage:groom && + melos run coverage:report && + melos run coverage:check coverage:check: run: dart pub global run coverde check 90 exec: + concurrency: 1 # only one project at a time to keep output sane + packageFilters: fileExists: coverage/lcov.info # by convention + coverage:groom: + run: | + rm -rf $MELOS_ROOT_PATH/coverage + dart pub global run combine_coverage --repo-path=$MELOS_ROOT_PATH + lcov --remove coverage/lcov.info '*/lib/src/cli/*' -o coverage/lcov.info + lcov --remove coverage/lcov.info '*/realm_bindings.dart' -o coverage/lcov.info + coverage:report: run: dart pub global run coverde report + # TODO: This is actually stricter than on CI, but we should aim for this ci: run: >- melos clean && melos bootstrap && melos run build && melos run test && - melos run lint && + melos run coverage && melos run analyze && - melos run coverage:check + melos run lint + \ No newline at end of file From 43f9a1d6fbd9ddaf751c2fe2d57cb07129b34205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Thu, 22 Feb 2024 19:02:00 +0100 Subject: [PATCH 086/153] Fix lints and increase coverage --- packages/ejson/lib/src/decoding.dart | 41 +++++++++++-------- packages/ejson/test/ejson_test.dart | 31 ++++++++++++++ packages/ejson_generator/test/ctor_test.dart | 4 +- .../lib/src/cli/atlas_apps/baas_client.dart | 5 ++- 4 files changed, 60 insertions(+), 21 deletions(-) diff --git a/packages/ejson/lib/src/decoding.dart b/packages/ejson/lib/src/decoding.dart index 7b1296f2c..9a153e62f 100644 --- a/packages/ejson/lib/src/decoding.dart +++ b/packages/ejson/lib/src/decoding.dart @@ -54,10 +54,10 @@ var customDecoders = {}; // if registerSerializableTypes not called final decoders = () { // register extra common types on first access - undefinedOr(f) => f>(); + undefinedOr(dynamic f) => f>(); TypePlus.addFactory(undefinedOr); - TypePlus.addFactory((f) => f>(), superTypes: [undefinedOr]); - TypePlus.addFactory((f) => f>(), superTypes: [undefinedOr]); + TypePlus.addFactory((dynamic f) => f>(), superTypes: [undefinedOr]); + TypePlus.addFactory((dynamic f) => f>(), superTypes: [undefinedOr]); TypePlus.add(); TypePlus.add(); TypePlus.add(); @@ -80,7 +80,7 @@ T fromEJson(EJsonValue ejson) { } // Important to return `T` as opposed to [Never] for type inference to work -T raiseInvalidEJson(Object? value) => throw InvalidEJson(value); +T raiseInvalidEJson(Object? value) => throw InvalidEJson(value, T); dynamic _decodeAny(EJsonValue ejson) { return switch (ejson) { @@ -97,19 +97,19 @@ dynamic _decodeAny(EJsonValue ejson) { {'\$numberLong': _} => _decodeInt(ejson), {'\$regex': _} => _decodeString(ejson), {'\$symbol': _} => _decodeSymbol(ejson), - {'\$undefined': _} => _decodeUndefined(ejson), + {'\$undefined': _} => _decodeUndefined(ejson), {'\$oid': _} => _decodeObjectId(ejson), {'\$binary': {'base64': _, 'subType': '04'}} => _decodeUuid(ejson), - List _ => _decodeArray(ejson), - Map _ => _tryDecodeCustom(ejson) ?? _decodeDocument(ejson), // other maps goes last!! - _ => raiseInvalidEJson(ejson), + List _ => _decodeArray(ejson), + Map _ => _tryDecodeCustom(ejson) ?? _decodeDocument(ejson), // other maps goes last!! + _ => raiseInvalidEJson(ejson), }; } -dynamic _tryDecodeCustom(json) { +dynamic _tryDecodeCustom(EJsonValue ejson) { for (final decoder in customDecoders.values) { try { - return decoder(json); + return decoder(ejson); } catch (_) { // ignore } @@ -119,7 +119,7 @@ dynamic _tryDecodeCustom(json) { List _decodeArray(EJsonValue ejson) { return switch (ejson) { - Iterable i => i.map((ejson) => fromEJson(ejson)).toList(), + Iterable i => i.map((ejson) => fromEJson(ejson)).toList(), _ => raiseInvalidEJson(ejson), }; } @@ -140,13 +140,13 @@ DateTime _decodeDate(EJsonValue ejson) { } Defined _decodeDefined(EJsonValue ejson) { - if (ejson case {'\$undefined': 1}) raiseInvalidEJson(ejson); + if (ejson case {'\$undefined': 1}) return raiseInvalidEJson(ejson); return Defined(fromEJson(ejson)); } Map _decodeDocument(EJsonValue ejson) { return switch (ejson) { - Map m => m.map((key, value) => MapEntry(key as K, fromEJson(value))), + Map m => m.map((key, value) => MapEntry(key as K, fromEJson(value))), _ => raiseInvalidEJson(ejson), }; } @@ -242,7 +242,13 @@ UndefinedOr _decodeUndefinedOr(EJsonValue ejson) { }; } -Uuid _decodeUuid(EJsonValue ejson) => Uuid.fromBytes(_decodeBinary(ejson, "04")); +Uuid _decodeUuid(EJsonValue ejson) { + try { + return Uuid.fromBytes(_decodeBinary(ejson, "04")); + } on InvalidEJson { + return raiseInvalidEJson(ejson); // get the type right + } +} ByteBuffer _decodeBinary(EJsonValue ejson, String subType) { return switch (ejson) { @@ -251,13 +257,14 @@ ByteBuffer _decodeBinary(EJsonValue ejson, String subType) { }; } -class InvalidEJson implements Exception { +class InvalidEJson implements Exception { final Object? value; + final Type type; - InvalidEJson(this.value); + InvalidEJson(this.value, this.type); @override - String toString() => 'Invalid EJson for $T: $value'; + String toString() => 'Invalid EJson for $type: $value'; } class MissingDecoder implements Exception { diff --git a/packages/ejson/test/ejson_test.dart b/packages/ejson/test/ejson_test.dart index fb259ba2f..42c783195 100644 --- a/packages/ejson/test/ejson_test.dart +++ b/packages/ejson/test/ejson_test.dart @@ -84,7 +84,38 @@ void _testCase( } } +class Dummy {} + +void _invalidTestCase([EJsonValue ejson = const {}]) { + test('decode $T from invalid ejson: $ejson', () { + expect(() => fromEJson(ejson), throwsA(isA().having((e) => e.toString(), 'toString', 'Invalid EJson for $T: $ejson'))); + }); +} + void main() { + group('invalid', () { + _invalidTestCase(); + _invalidTestCase(); + _invalidTestCase({'\$numberDouble': 'foobar'}); + _invalidTestCase(); + _invalidTestCase(); + _invalidTestCase(); + _invalidTestCase>(); + _invalidTestCase>([]); + _invalidTestCase(); + _invalidTestCase(); + _invalidTestCase(); + _invalidTestCase(); + _invalidTestCase(); + _invalidTestCase(); + _invalidTestCase>(); + _invalidTestCase(); + + test('missing decoder', () { + expect(() => fromEJson({}), throwsA(isA().having((e) => e.toString(), 'toString', 'Missing decoder for Dummy'))); + }); + }); + for (final useRelaxed in [false, true]) { group(useRelaxed ? 'relaxed' : 'canonical', () { relaxed = useRelaxed; diff --git a/packages/ejson_generator/test/ctor_test.dart b/packages/ejson_generator/test/ctor_test.dart index cea2c749c..1718c1574 100644 --- a/packages/ejson_generator/test/ctor_test.dart +++ b/packages/ejson_generator/test/ctor_test.dart @@ -96,7 +96,7 @@ void _testCase(T value, EJsonValue expected) { EJsonValue badInput = {'bad': 'input'}; badInput = value is Map ? [badInput] : badInput; // wrap in list for maps test('decode $badInput to $T fails', () { - expect(() => fromEJson(badInput), throwsA(isA>())); + expect(() => fromEJson(badInput), throwsA(isA())); }); test('roundtrip $expected as $T', () { @@ -105,7 +105,7 @@ void _testCase(T value, EJsonValue expected) { test('roundtrip $expected of type $T as dynamic', () { // no here, so dynamic - final decoded = fromEJson(expected); + final decoded = fromEJson(expected); expect(decoded, isA()); expect(toEJson(decoded), expected); }); diff --git a/packages/realm_dart/lib/src/cli/atlas_apps/baas_client.dart b/packages/realm_dart/lib/src/cli/atlas_apps/baas_client.dart index 13bf0b0a1..1ead433c0 100644 --- a/packages/realm_dart/lib/src/cli/atlas_apps/baas_client.dart +++ b/packages/realm_dart/lib/src/cli/atlas_apps/baas_client.dart @@ -200,8 +200,9 @@ class BaasClient { } static Future> _getContainers(BaasAuthHelper helper, {String? differentiator}) async { - var result = - (await helper.callEndpoint('listContainers', isPost: false) as List>).map((e) => _ContainerInfo.fromJson(e)).whereNotNull(); + var result = (await helper.callEndpoint('listContainers', isPost: false) as List) + .map((e) => _ContainerInfo.fromJson(e as Map)) + .whereNotNull(); if (differentiator != null) { final userId = await helper.getUserId(); result = result.where((c) => c.creatorId == userId && c.tags['DIFFERENTIATOR'] == differentiator); From 2a7a90019853da2fed5b4fa106045770e8a2600d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Thu, 22 Feb 2024 20:35:07 +0100 Subject: [PATCH 087/153] switch to melos coverage:groom --- .github/workflows/dart-desktop-tests.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dart-desktop-tests.yml b/.github/workflows/dart-desktop-tests.yml index cacda5a04..fef884444 100644 --- a/.github/workflows/dart-desktop-tests.yml +++ b/.github/workflows/dart-desktop-tests.yml @@ -76,9 +76,8 @@ jobs: - name: Gather coverage report if: inputs.runner == 'ubuntu-latest' run: | - dart pub global run combine_coverage --repo-path=$(pwd) sudo apt-get install lcov - lcov --remove ./coverage/lcov.info '*/lib/src/cli/*' '*/lib/src/native/realm_bindings.dart' -o coverage/pruned-lcov.info + melos coverage:groom - name: Publish coverage if: inputs.runner == 'ubuntu-latest' @@ -87,5 +86,5 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} flag-name: realm_dart - path-to-lcov: ./coverage/pruned-lcov.info + path-to-lcov: ./coverage/lcov.info parallel: true \ No newline at end of file From c4adf673a8156ca89b2882540ae8bca265801611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Thu, 22 Feb 2024 20:50:31 +0100 Subject: [PATCH 088/153] strong-mode has been superceeded by strict --- analysis_options.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 2b8e1834a..92f1a040a 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -7,10 +7,6 @@ analyzer: strict-inference: true # see https://github.com/dart-lang/language/blob/main/resources/type-system/strict-inference.md strict-raw-types: true # see https://github.com/dart-lang/language/blob/main/resources/type-system/strict-raw-types.md - strong-mode: - implicit-casts: false - implicit-dynamic: false - exclude: - lib/**/*.g.dart - lib/**/realm_bindings.dart From 428bcb08be345134db08a0cb77699b62b68109e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Thu, 22 Feb 2024 20:53:26 +0100 Subject: [PATCH 089/153] enable custom_lint tools --- analysis_options.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/analysis_options.yaml b/analysis_options.yaml index 92f1a040a..602785858 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -7,8 +7,12 @@ analyzer: strict-inference: true # see https://github.com/dart-lang/language/blob/main/resources/type-system/strict-inference.md strict-raw-types: true # see https://github.com/dart-lang/language/blob/main/resources/type-system/strict-raw-types.md + plugins: + - custom_lint + exclude: - lib/**/*.g.dart + - lib/**/*.realm.dart - lib/**/realm_bindings.dart linter: From e8ff3d81e660ca973ff1e722d4d5e0e21359c008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Mon, 26 Feb 2024 09:15:42 +0100 Subject: [PATCH 090/153] Add example to package ejson --- packages/ejson/example/main.dart | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/ejson/example/main.dart b/packages/ejson/example/main.dart index 8b1378917..b1406394a 100644 --- a/packages/ejson/example/main.dart +++ b/packages/ejson/example/main.dart @@ -1 +1,18 @@ +import 'dart:convert'; +import 'package:ejson/ejson.dart'; +import 'package:test/test.dart'; + +void main() { + test('round-trip', () { + final value = { + 'abe': [1, 4], + 'kat': [], + }; + final encoded = toEJson(value); + final json = jsonEncode(encoded); + print(json); + final decoded = fromEJson>>(jsonDecode(json)); + expect(value, decoded); + }); +} From c72001638181fd771dcb0cb62aa4d97a2270d20e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Mon, 26 Feb 2024 09:48:24 +0100 Subject: [PATCH 091/153] Fix missing quotes on int and double values in canonical mode --- packages/ejson/lib/src/decoding.dart | 8 ++++---- packages/ejson/lib/src/encoding.dart | 24 ++++++++++++------------ packages/ejson/test/ejson_test.dart | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/ejson/lib/src/decoding.dart b/packages/ejson/lib/src/decoding.dart index 9a153e62f..7f50575b5 100644 --- a/packages/ejson/lib/src/decoding.dart +++ b/packages/ejson/lib/src/decoding.dart @@ -154,12 +154,12 @@ Map _decodeDocument(EJsonValue ejson) { double _decodeDouble(EJsonValue ejson) { return switch (ejson) { double d => d, // relaxed mode - {'\$numberDouble': double d} => d, + //{'\$numberDouble': double d} => d, {'\$numberDouble': String s} => switch (s) { 'NaN' => double.nan, 'Infinity' => double.infinity, '-Infinity' => double.negativeInfinity, - _ => raiseInvalidEJson(ejson), + _ => double.tryParse(s) ?? raiseInvalidEJson(ejson), }, _ => raiseInvalidEJson(ejson), }; @@ -168,8 +168,8 @@ double _decodeDouble(EJsonValue ejson) { int _decodeInt(EJsonValue ejson) { return switch (ejson) { int i => i, // relaxed mode - {'\$numberInt': int i} => i, - {'\$numberLong': int i} => i, + {'\$numberInt': String i} => int.tryParse(i) ?? raiseInvalidEJson(ejson), + {'\$numberLong': String i} => int.tryParse(i) ?? raiseInvalidEJson(ejson), _ => raiseInvalidEJson(ejson), }; } diff --git a/packages/ejson/lib/src/encoding.dart b/packages/ejson/lib/src/encoding.dart index 100896ffe..9261db733 100644 --- a/packages/ejson/lib/src/encoding.dart +++ b/packages/ejson/lib/src/encoding.dart @@ -42,22 +42,22 @@ EJsonValue _encodeAny(Object? value) { null => null, bool b => _encodeBool(b), DateTime d => _encodeDate(d), - Defined d => _encodeDefined(d), + Defined d => _encodeDefined(d), double d => _encodeDouble(d), int i => _encodeInt(i), Key k => _encodeKey(k), - List l => _encodeArray(l), - Map m => _encodeDocument(m), + List l => _encodeArray(l), + Map m => _encodeDocument(m), ObjectId o => _encodeObjectId(o), String s => _encodeString(s), Symbol s => _encodeSymbol(s), - Undefined u => _encodeUndefined(u), + Undefined u => _encodeUndefined(u), Uuid u => _encodeUuid(u), _ => _encodeCustom(value), }; } -EJsonValue _encodeArray(Iterable items) => items.map((e) => toEJson(e)).toList(); +EJsonValue _encodeArray(Iterable items) => items.map((e) => toEJson(e)).toList(); EJsonValue _encodeBool(bool value) => value; @@ -78,9 +78,9 @@ EJsonValue _encodeDate(DateTime value) { }; } -EJsonValue _encodeDefined(Defined defined) => toEJson(defined.value); +EJsonValue _encodeDefined(Defined defined) => toEJson(defined.value); -EJsonValue _encodeDocument(Map map) => map.map((k, v) => MapEntry(k, toEJson(v))); +EJsonValue _encodeDocument(Map map) => map.map((k, v) => MapEntry(k, toEJson(v))); EJsonValue _encodeDouble(double value) { if (value.isNaN) { @@ -91,7 +91,7 @@ EJsonValue _encodeDouble(double value) { double.negativeInfinity => {'\$numberDouble': '-Infinity'}, _ => switch (relaxed) { true => value, - false => {'\$numberDouble': value}, + false => {'\$numberDouble': '$value'}, } }; } @@ -99,7 +99,7 @@ EJsonValue _encodeDouble(double value) { EJsonValue _encodeInt(int value, {bool long = true}) { return switch (relaxed) { true => value, - false => {'\$number${long ? 'Long' : 'Int'}': value}, + false => {'\$number${long ? 'Long' : 'Int'}': '$value'}, }; } @@ -110,7 +110,7 @@ EJsonValue _encodeString(String value) => value; EJsonValue _encodeSymbol(Symbol value) => {'\$symbol': value.name}; -EJsonValue _encodeUndefined(Undefined undefined) => {'\$undefined': 1}; +EJsonValue _encodeUndefined(Undefined undefined) => {'\$undefined': 1}; EJsonValue _encodeUuid(Uuid uuid) => _encodeBinary(uuid.bytes, "04"); @@ -139,7 +139,7 @@ extension DateTimeEJsonEncoderExtension on DateTime { EJsonValue toEJson() => _encodeDate(this); } -extension DefinedEJsonEncoderExtension on Defined { +extension DefinedEJsonEncoderExtension on Defined { @pragma('vm:prefer-inline') EJsonValue toEJson() => _encodeDefined(this); } @@ -194,7 +194,7 @@ extension SymbolEJsonEncoderExtension on Symbol { EJsonValue toEJson() => _encodeSymbol(this); } -extension UndefinedEJsonEncoderExtension on Undefined { +extension UndefinedEJsonEncoderExtension on Undefined { @pragma('vm:prefer-inline') EJsonValue toEJson() => _encodeUndefined(this); } diff --git a/packages/ejson/test/ejson_test.dart b/packages/ejson/test/ejson_test.dart index 42c783195..2caeaafac 100644 --- a/packages/ejson/test/ejson_test.dart +++ b/packages/ejson/test/ejson_test.dart @@ -229,7 +229,7 @@ void main() { ); expect( - fromEJson>({'\$numberLong': 42}), + fromEJson>({'\$numberLong': '42'}), Defined(42), ); From 705f497f83d24ddc85eeab571b307c92e1061819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Mon, 26 Feb 2024 09:52:55 +0100 Subject: [PATCH 092/153] Relax Array type from LIst to Iterable --- packages/ejson/lib/src/decoding.dart | 1 + packages/ejson/lib/src/encoding.dart | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/ejson/lib/src/decoding.dart b/packages/ejson/lib/src/decoding.dart index 7f50575b5..3e7b776ff 100644 --- a/packages/ejson/lib/src/decoding.dart +++ b/packages/ejson/lib/src/decoding.dart @@ -32,6 +32,7 @@ const commonDecoders = { dynamic: _decodeAny, Null: _decodeNull, Object: _decodeAny, + Iterable: _decodeArray, List: _decodeArray, bool: _decodeBool, DateTime: _decodeDate, diff --git a/packages/ejson/lib/src/encoding.dart b/packages/ejson/lib/src/encoding.dart index 9261db733..29b8810b0 100644 --- a/packages/ejson/lib/src/encoding.dart +++ b/packages/ejson/lib/src/encoding.dart @@ -46,7 +46,7 @@ EJsonValue _encodeAny(Object? value) { double d => _encodeDouble(d), int i => _encodeInt(i), Key k => _encodeKey(k), - List l => _encodeArray(l), + Iterable l => _encodeArray(l), Map m => _encodeDocument(m), ObjectId o => _encodeObjectId(o), String s => _encodeString(s), From 2a8f7673c57f5853037cdfa0c55bc3efde94bf1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Mon, 26 Feb 2024 10:02:53 +0100 Subject: [PATCH 093/153] Update a ejson_lint/example README.md --- packages/ejson_lint/example/README.md | 6 ++++-- packages/ejson_lint/example/bin/example.dart | 4 +--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/ejson_lint/example/README.md b/packages/ejson_lint/example/README.md index 3816eca3a..b7bb61e83 100644 --- a/packages/ejson_lint/example/README.md +++ b/packages/ejson_lint/example/README.md @@ -1,2 +1,4 @@ -A sample command-line application with an entrypoint in `bin/`, library code -in `lib/`, and example unit test in `test/`. +This project is used to test lint rules using +```shell +dart run custom_lint +``` diff --git a/packages/ejson_lint/example/bin/example.dart b/packages/ejson_lint/example/bin/example.dart index 2032104d7..e38d05f8f 100644 --- a/packages/ejson_lint/example/bin/example.dart +++ b/packages/ejson_lint/example/bin/example.dart @@ -1,9 +1,7 @@ import 'package:ejson_annotation/ejson_annotation.dart'; // This file is used to test lint rules using -// dart run custom_lint -// or -// melos test:lint +// dart run custom_lint class Person { final String name; // expect_lint: mismatched_getter_type From 902a3481aaef66afa5fe213af19136047e3ed9cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Mon, 26 Feb 2024 10:24:51 +0100 Subject: [PATCH 094/153] Fix missing quotes on DateTime in canonical mode --- packages/ejson/lib/src/decoding.dart | 2 +- packages/ejson/lib/src/encoding.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ejson/lib/src/decoding.dart b/packages/ejson/lib/src/decoding.dart index 3e7b776ff..286fe3940 100644 --- a/packages/ejson/lib/src/decoding.dart +++ b/packages/ejson/lib/src/decoding.dart @@ -135,7 +135,7 @@ bool _decodeBool(EJsonValue ejson) { DateTime _decodeDate(EJsonValue ejson) { return switch (ejson) { {'\$date': String s} => DateTime.parse(s), // relaxed mode - {'\$date': {'\$numberLong': int i}} => DateTime.fromMillisecondsSinceEpoch(i), + {'\$date': {'\$numberLong': String i}} => DateTime.fromMillisecondsSinceEpoch(int.tryParse(i) ?? raiseInvalidEJson(ejson)), _ => raiseInvalidEJson(ejson), }; } diff --git a/packages/ejson/lib/src/encoding.dart b/packages/ejson/lib/src/encoding.dart index 29b8810b0..344d9c0d3 100644 --- a/packages/ejson/lib/src/encoding.dart +++ b/packages/ejson/lib/src/encoding.dart @@ -73,7 +73,7 @@ EJsonValue _encodeDate(DateTime value) { return switch (relaxed) { true => {'\$date': value.toIso8601String()}, false => { - '\$date': {'\$numberLong': value.millisecondsSinceEpoch} + '\$date': {'\$numberLong': value.millisecondsSinceEpoch.toString()}, }, }; } From 8f7168f396626676dc1ca39fbfccc4c0c4d07724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Mon, 26 Feb 2024 10:17:52 +0100 Subject: [PATCH 095/153] Fix ejson_generator tests --- packages/ejson_generator/test/ctor_test.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/ejson_generator/test/ctor_test.dart b/packages/ejson_generator/test/ctor_test.dart index 1718c1574..26cb2499b 100644 --- a/packages/ejson_generator/test/ctor_test.dart +++ b/packages/ejson_generator/test/ctor_test.dart @@ -124,23 +124,23 @@ void main() { _testCase(const Empty(), {}); _testCase(const Simple(42), { - 'i': {'\$numberLong': 42} + 'i': {'\$numberLong': '42'} }); _testCase(Named.nameIt('foobar'), {'namedCtor': 'foobar'}); _testCase(const RequiredNamedParameters(requiredNamed: 'foobar'), {'requiredNamed': 'foobar'}); _testCase(OptionalNamedParameters(), {'optionalNamed': 'rabbit'}); _testCase(OptionalParameters(), {'optional': 'racoon'}); _testCase(const PrivateMembers(42), { - 'id': {'\$numberLong': 42} + 'id': {'\$numberLong': '42'} }); final birthDate = DateTime.utc(1973); _testCase(Person('Eva', DateTime.utc(1973), 90000.0), { 'name': 'Eva', 'birthDate': { - '\$date': {'\$numberLong': birthDate.millisecondsSinceEpoch} + '\$date': {'\$numberLong': birthDate.millisecondsSinceEpoch.toString()} }, - 'income': {'\$numberDouble': 90000.0}, + 'income': {'\$numberDouble': '90000.0'}, 'spouse': null, 'cprNumber': null, }); From dfaa4e0c32af84edfb33ba13d7590ad0f15dd671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Mon, 26 Feb 2024 13:03:19 +0100 Subject: [PATCH 096/153] Only install ninja on linux builds --- .github/workflows/build-native.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-native.yml b/.github/workflows/build-native.yml index d79d1d28c..640d23e46 100644 --- a/.github/workflows/build-native.yml +++ b/.github/workflows/build-native.yml @@ -42,7 +42,7 @@ jobs: key: binaries-${{ matrix.build }}-${{ inputs.runner }}-${{hashFiles('./packages/realm_dart/src/**')}} - name: Setup Ninja - if: steps.check-cache.outputs.cache-hit != 'true' + if: inputs.runner == 'ubuntu-latest' run: | sudo apt-get update -y sudo apt-get install -y ninja-build From b1b73945fc4ef75f7593c85a1d9728df5f689e18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Mon, 26 Feb 2024 15:52:15 +0100 Subject: [PATCH 097/153] Tweak a test --- packages/realm_dart/test/configuration_test.dart | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/realm_dart/test/configuration_test.dart b/packages/realm_dart/test/configuration_test.dart index 6b4487bf6..4aa29dd13 100644 --- a/packages/realm_dart/test/configuration_test.dart +++ b/packages/realm_dart/test/configuration_test.dart @@ -212,15 +212,13 @@ void main() { test('Configuration - disableFormatUpgrade=true throws error', () async { var config = Configuration.local([Car.schema], disableFormatUpgrade: true); await copyFile('test/data/realm_files/old-format.realm', config.path); - expect(() { - getRealm(config); - }, throws("Database upgrade required but prohibited.")); + expect(() => getRealm(config), throws("Database upgrade required but prohibited.")); }); test('Configuration - disableFormatUpgrade=false', () async { var config = Configuration.local([Car.schema], disableFormatUpgrade: false); await copyFile('test/data/realm_files/old-format.realm', config.path); - final realm = getRealm(config); + expect(() => getRealm(config), isNot(throwsException)); }); test('Configuration.initialDataCallback invoked', () { From 0ee6bbaffd0f503f4bad0b5cfdf4a0736abf87af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Mon, 26 Feb 2024 15:52:53 +0100 Subject: [PATCH 098/153] Force a new native build.. --- .github/workflows/build-native.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-native.yml b/.github/workflows/build-native.yml index 640d23e46..0e9710cf9 100644 --- a/.github/workflows/build-native.yml +++ b/.github/workflows/build-native.yml @@ -39,7 +39,7 @@ jobs: uses: actions/cache@v4 with: path: ./packages/realm_dart/binary/** - key: binaries-${{ matrix.build }}-${{ inputs.runner }}-${{hashFiles('./packages/realm_dart/src/**')}} + key: binaries-${{ matrix.build }}-${{ inputs.runner }}-${{hashFiles('./packages/realm_dart/src/**')}}-kick - name: Setup Ninja if: inputs.runner == 'ubuntu-latest' From 771f993c6571f13e9ebb179160becabcf8645b6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Mon, 26 Feb 2024 15:58:25 +0100 Subject: [PATCH 099/153] Tweak condition for Ninja (android- & linux-) --- .github/workflows/build-native.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-native.yml b/.github/workflows/build-native.yml index 0e9710cf9..b69c8be52 100644 --- a/.github/workflows/build-native.yml +++ b/.github/workflows/build-native.yml @@ -42,7 +42,7 @@ jobs: key: binaries-${{ matrix.build }}-${{ inputs.runner }}-${{hashFiles('./packages/realm_dart/src/**')}}-kick - name: Setup Ninja - if: inputs.runner == 'ubuntu-latest' + if: startsWith(matrix.build, 'android-') || startsWith(matrix.build, 'linux-') run: | sudo apt-get update -y sudo apt-get install -y ninja-build From b5eb5b54ffa991db0813becbec4a9973b1cf51ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Mon, 26 Feb 2024 16:04:30 +0100 Subject: [PATCH 100/153] Fix linux.. and simplify --- .github/workflows/build-native.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-native.yml b/.github/workflows/build-native.yml index b69c8be52..616a36dd4 100644 --- a/.github/workflows/build-native.yml +++ b/.github/workflows/build-native.yml @@ -36,23 +36,24 @@ jobs: - name: Check cache id: check-cache + if: contains(github.head_ref, 'release/') != true uses: actions/cache@v4 with: path: ./packages/realm_dart/binary/** key: binaries-${{ matrix.build }}-${{ inputs.runner }}-${{hashFiles('./packages/realm_dart/src/**')}}-kick - name: Setup Ninja - if: startsWith(matrix.build, 'android-') || startsWith(matrix.build, 'linux-') + if: startsWith(matrix.build, 'android') || startsWith(matrix.build, 'linux') run: | sudo apt-get update -y sudo apt-get install -y ninja-build - name: Setup Android NDK - if: startsWith(matrix.build, 'android-') + if: startsWith(matrix.build, 'android') run: echo "ANDROID_NDK=$ANDROID_NDK_LATEST_HOME" >> $GITHUB_ENV - name: Downgrade XCode for MacOS - if: ${{ matrix.build == 'macos' }} + if: matrix.build == 'macos' run: sudo xcode-select -s /Applications/Xcode_14.0.1.app - name: Build From b67d3e9037b847576b70b9b643c57d80b3785ee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Mon, 26 Feb 2024 17:11:12 +0100 Subject: [PATCH 101/153] Upgrade realm-core to v14.0.1 --- packages/realm_dart/src/realm-core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/realm_dart/src/realm-core b/packages/realm_dart/src/realm-core index 677c9c28e..2bfd5e9ba 160000 --- a/packages/realm_dart/src/realm-core +++ b/packages/realm_dart/src/realm-core @@ -1 +1 @@ -Subproject commit 677c9c28e29b3a0899dc46b0054f2354cd47a0d1 +Subproject commit 2bfd5e9ba74ed2620657bf968d2931f6ceab6785 From 48d27bbfcf74ef000b319d46e4091cbe5ca63c45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 27 Feb 2024 08:28:45 +0100 Subject: [PATCH 102/153] testing hypothesis --- packages/realm_dart/lib/src/cli/install/install_command.dart | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/realm_dart/lib/src/cli/install/install_command.dart b/packages/realm_dart/lib/src/cli/install/install_command.dart index f92407628..c3b1730d3 100644 --- a/packages/realm_dart/lib/src/cli/install/install_command.dart +++ b/packages/realm_dart/lib/src/cli/install/install_command.dart @@ -76,9 +76,11 @@ class InstallCommand extends Command { } Future shouldSkipInstall(Pubspec realmPubspec) async { + return true; // testing hypothesis final pubspecFile = await File("pubspec.yaml").readAsString(); + print(pubspecFile); final projectPubspec = Pubspec.parse(pubspecFile); - + print(projectPubspec.name); if (Flavor.values.map((f) => f.packageName).contains(projectPubspec.name)) { print(// 'Running install command inside ${projectPubspec.name} package which is the development package for Realm.\n' @@ -188,6 +190,7 @@ class InstallCommand extends Command { } final binaryPath = Directory(getBinaryPath(path.dirname(realmPackagePath))); + print(binaryPath); final archiveName = "${options.targetOsType!.name}.tar.gz"; await downloadAndExtractBinaries(binaryPath, realmPubspec, archiveName); From ab1893c8745b239540d971d2edbcde972d6dba89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 27 Feb 2024 13:55:54 +0100 Subject: [PATCH 103/153] Rework install command --- packages/realm/android/build.gradle | 2 +- packages/realm/ios/realm.podspec | 4 +- packages/realm/linux/CMakeLists.txt | 2 +- packages/realm/macos/realm.podspec | 2 +- packages/realm/windows/CMakeLists.txt | 2 +- .../lib/src/cli/install/install_command.dart | 149 +++++++----------- .../lib/src/cli/install/options.dart | 5 +- .../lib/src/cli/install/options.g.dart | 16 -- 8 files changed, 62 insertions(+), 120 deletions(-) diff --git a/packages/realm/android/build.gradle b/packages/realm/android/build.gradle index 21b286f03..4469445ba 100644 --- a/packages/realm/android/build.gradle +++ b/packages/realm/android/build.gradle @@ -101,7 +101,7 @@ tasks.register("downloadRealmBinaries", Exec) { def (flutterRoot, dartExecutable) = getPaths() workingDir "${project.rootProject.projectDir}${File.separator}.." - commandLine dartExecutable, 'run', 'realm', 'install', '--target-os-type', 'android', '--flavor', 'flutter' + commandLine dartExecutable, 'run', 'realm', 'install', '--target-os-type', 'android' } def getBundleId() { diff --git a/packages/realm/ios/realm.podspec b/packages/realm/ios/realm.podspec index c5bee8091..11a6ed87f 100644 --- a/packages/realm/ios/realm.podspec +++ b/packages/realm/ios/realm.podspec @@ -51,11 +51,11 @@ Pod::Spec.new do |s| 'FRAMEWORK_SEARCH_PATHS' => '"$(PODS_TARGET_SRCROOT)/**"' } #Use --debug to debug the install command on both prepare_command and script_phase below - s.prepare_command = "source \"#{project_dir}/Flutter/flutter_export_environment.sh\" && cd \"$FLUTTER_APPLICATION_PATH\" && \"$FLUTTER_ROOT/bin/dart\" run realm install --target-os-type ios --flavor flutter" + s.prepare_command = "source \"#{project_dir}/Flutter/flutter_export_environment.sh\" && cd \"$FLUTTER_APPLICATION_PATH\" && \"$FLUTTER_ROOT/bin/dart\" run realm install --target-os-type ios" s.script_phases = [ { :name => 'Download Realm Flutter iOS Binaries', #Use --debug to debug the install command - :script => 'source "$PROJECT_DIR/../Flutter/flutter_export_environment.sh" && cd "$FLUTTER_APPLICATION_PATH" && "$FLUTTER_ROOT/bin/dart" run realm install --target-os-type ios --flavor flutter', + :script => 'source "$PROJECT_DIR/../Flutter/flutter_export_environment.sh" && cd "$FLUTTER_APPLICATION_PATH" && "$FLUTTER_ROOT/bin/dart" run realm install --target-os-type ios', :execution_position => :before_headers }, { :name => 'Report Metrics', diff --git a/packages/realm/linux/CMakeLists.txt b/packages/realm/linux/CMakeLists.txt index 0c36cebe7..688310714 100644 --- a/packages/realm/linux/CMakeLists.txt +++ b/packages/realm/linux/CMakeLists.txt @@ -55,7 +55,7 @@ add_definitions(-DBUNDLE_ID="${BUNDLE_ID}") # message ("FLUTTER_TOOL_ENVIRONMENT is ${FLUTTER_TOOL_ENVIRONMENT}") # message ("FLUTTER_ROOT is ${FLUTTER_ROOT}") -execute_process(COMMAND "${FLUTTER_ROOT}/bin/dart" "run" "realm" "install" "--target-os-type" "linux" "--flavor" "flutter" # "--debug" +execute_process(COMMAND "${FLUTTER_ROOT}/bin/dart" "run" "realm" "install" "--target-os-type" "linux" # "--debug" WORKING_DIRECTORY ${ABSOLUTE_PATH_APP_DIR} OUTPUT_VARIABLE output RESULT_VARIABLE result diff --git a/packages/realm/macos/realm.podspec b/packages/realm/macos/realm.podspec index b054aec32..06f2c16bf 100644 --- a/packages/realm/macos/realm.podspec +++ b/packages/realm/macos/realm.podspec @@ -57,7 +57,7 @@ Pod::Spec.new do |s| s.script_phases = [ { :name => 'Download Realm Flutter macOS Binaries', #Use --debug to debug the install command - :script => 'source "$PROJECT_DIR/../Flutter/ephemeral/flutter_export_environment.sh" && cd "$FLUTTER_APPLICATION_PATH" && "$FLUTTER_ROOT/bin/dart" run realm install --target-os-type macos --flavor flutter', + :script => 'source "$PROJECT_DIR/../Flutter/ephemeral/flutter_export_environment.sh" && cd "$FLUTTER_APPLICATION_PATH" && "$FLUTTER_ROOT/bin/dart" run realm install --target-os-type macos', :execution_position => :before_headers }, { :name => 'Report Metrics', diff --git a/packages/realm/windows/CMakeLists.txt b/packages/realm/windows/CMakeLists.txt index b672b42de..8b8130ada 100644 --- a/packages/realm/windows/CMakeLists.txt +++ b/packages/realm/windows/CMakeLists.txt @@ -47,7 +47,7 @@ add_definitions(-DBUNDLE_ID="${BUNDLE_ID}") # message ("FLUTTER_TOOL_ENVIRONMENT is ${FLUTTER_TOOL_ENVIRONMENT}") # message ("FLUTTER_ROOT is ${FLUTTER_ROOT}") -execute_process(COMMAND "${FLUTTER_ROOT}\\bin\\dart.bat" "run" "realm" "install" "--target-os-type" "windows" "--flavor" "flutter" #"--debug" +execute_process(COMMAND "${FLUTTER_ROOT}\\bin\\dart.bat" "run" "realm" "install" "--target-os-type" "windows" #"--debug" OUTPUT_VARIABLE output RESULT_VARIABLE result COMMAND_ERROR_IS_FATAL ANY diff --git a/packages/realm_dart/lib/src/cli/install/install_command.dart b/packages/realm_dart/lib/src/cli/install/install_command.dart index c3b1730d3..d77452c1d 100644 --- a/packages/realm_dart/lib/src/cli/install/install_command.dart +++ b/packages/realm_dart/lib/src/cli/install/install_command.dart @@ -19,6 +19,7 @@ import 'dart:async'; import 'dart:io'; +import 'package:pub_semver/pub_semver.dart'; import 'package:pubspec_parse/pubspec_parse.dart'; import 'package:args/command_runner.dart'; import 'package:package_config/package_config.dart'; @@ -26,11 +27,10 @@ import 'package:path/path.dart' as path; import '../common/target_os_type.dart'; import '../common/archive.dart'; -import '../common/utils.dart'; import 'options.dart'; class InstallCommand extends Command { - static const versionFileName = "realm_version.txt"; + static const versionFileName = 'realm_version.txt'; @override final description = 'Download & install Realm native binaries into a Flutter or Dart project'; @@ -40,60 +40,26 @@ class InstallCommand extends Command { late Options options; - String get packageName => options.flavor.packageName; - - bool get isFlutter => options.flavor == Flavor.flutter; - bool get isDart => options.flavor == Flavor.dart; bool get debug => options.debug; InstallCommand() { populateOptionsParser(argParser); } - String getBinaryPath(String realmPackagePath) { + Directory getBinaryPath(Package realmPackage, {required bool isFlutter}) { + final realmPackagePath = realmPackage.root.toFilePath(); if (isFlutter) { - switch (options.targetOsType) { - case TargetOsType.android: - return path.join(realmPackagePath, "android", "src", "main", "cpp", "lib"); - case TargetOsType.ios: - return path.join(realmPackagePath, "ios"); - case TargetOsType.macos: - return path.join(realmPackagePath, "macos"); - case TargetOsType.linux: - return path.join(realmPackagePath, "linux", "binary", "linux"); - case TargetOsType.windows: - return path.join(realmPackagePath, "windows", "binary", "windows"); - default: - throw Exception("Unsupported target OS type for Flutter: ${options.targetOsType}"); - } - } - - if (isDart) { - return path.join(Directory.current.absolute.path, 'binary', options.targetOsType!.name); - } - - throw Exception("Unsupported package name: $packageName"); - } - - Future shouldSkipInstall(Pubspec realmPubspec) async { - return true; // testing hypothesis - final pubspecFile = await File("pubspec.yaml").readAsString(); - print(pubspecFile); - final projectPubspec = Pubspec.parse(pubspecFile); - print(projectPubspec.name); - if (Flavor.values.map((f) => f.packageName).contains(projectPubspec.name)) { - print(// - 'Running install command inside ${projectPubspec.name} package which is the development package for Realm.\n' - 'Skipping download as it is expected that you build the packages manually.'); - return true; - } - - if (realmPubspec.publishTo == 'none' && !debug) { - print("Referencing $packageName@${realmPubspec.version} which hasn't been published (publish_to: none). Skipping download."); - return true; - } - - return false; + return Directory(switch (options.targetOsType) { + TargetOsType.android => path.join(realmPackagePath, 'android', 'src', 'main', 'cpp', 'lib'), + TargetOsType.ios => path.join(realmPackagePath, 'ios'), + TargetOsType.macos => path.join(realmPackagePath, 'macos'), + TargetOsType.linux => path.join(realmPackagePath, 'linux', 'binary', 'linux'), + TargetOsType.windows => path.join(realmPackagePath, 'windows', 'binary', 'windows'), + _ => throw Exception('Unsupported target OS type for Flutter: ${options.targetOsType}') + }); + } + // TODO: Should binaries not go into package also for Dart? + return Directory(path.join(Directory.current.absolute.path, 'binary', options.targetOsType!.name)); } Future shouldSkipDownload(String binariesPath, String expectedVersion) async { @@ -101,15 +67,15 @@ class InstallCommand extends Command { if (await versionsFile.exists()) { final existingVersion = await versionsFile.readAsString(); if (expectedVersion == existingVersion) { - print("Realm binaries for $packageName@$expectedVersion already downloaded"); + print('Realm binaries for $expectedVersion already downloaded'); return true; } } return false; } - Future downloadAndExtractBinaries(Directory destinationDir, Pubspec realmPubspec, String archiveName) async { - if (await shouldSkipDownload(destinationDir.absolute.path, realmPubspec.version.toString())) { + Future downloadAndExtractBinaries(Directory destinationDir, Version version, String archiveName) async { + if (await shouldSkipDownload(destinationDir.absolute.path, version.toString())) { return; } @@ -122,9 +88,9 @@ class InstallCommand extends Command { await destinationFile.parent.create(recursive: true); } - print("Downloading Realm binaries for $packageName@${realmPubspec.version} to ${destinationFile.absolute.path}"); + print('Downloading Realm binaries for $version to ${destinationFile.absolute.path}'); final client = HttpClient(); - var url = 'https://static.realm.io/downloads/dart/${Uri.encodeComponent(realmPubspec.version.toString())}/$archiveName'; + var url = 'https://static.realm.io/downloads/dart/${Uri.encodeComponent(version.toString())}/$archiveName'; if (debug) { url = 'http://localhost:8000/$archiveName'; } @@ -132,7 +98,7 @@ class InstallCommand extends Command { final request = await client.getUrl(Uri.parse(url)); final response = await request.close(); if (response.statusCode >= 400) { - throw Exception("Error downloading Realm binaries from $url. Error code: ${response.statusCode}"); + throw Exception('Error downloading Realm binaries from $url. Error code: ${response.statusCode}'); } await response.pipe(destinationFile.openWrite()); } @@ -141,78 +107,73 @@ class InstallCommand extends Command { client.close(force: true); } - print("Extracting Realm binaries to ${destinationDir.absolute.path}"); + print('Extracting Realm binaries to ${destinationDir.absolute.path}'); final archive = Archive(); await archive.extract(destinationFile, destinationDir); final versionFile = File(path.join(destinationDir.absolute.path, versionFileName)); - await versionFile.writeAsString("${realmPubspec.version}"); + await versionFile.writeAsString(version.toString()); } - Future getRealmPackagePath() async { + Future getPackage(String name) async { final packageConfig = await findPackageConfig(Directory.current); if (packageConfig == null) { - throw Exception("Package configuration not found. " - "Run the 'dart run $packageName install` command from the root directory of your application"); + abort('Run `dart pub get`'); } - - final package = packageConfig.packages.where((p) => p.name == Flavor.flutter.packageName || p.name == Flavor.dart.packageName).firstOrNull; + final package = packageConfig.packages.where((p) => p.name == name).singleOrNull; if (package == null) { - throw Exception("$packageName package not found in dependencies. Add $packageName package to your pubspec.yaml"); - } - - if (package.root.scheme != 'file') { - throw Exception("$packageName package uri ${package.root} is not supported. Uri should start with file://"); + abort('$name package not found in dependencies. Add $name package to your pubspec.yaml'); } - - final packagePath = path.join(package.root.toFilePath(), "pubspec.yaml"); - return packagePath; + return package; } - Future parsePubspec(String path) async { + Future parsePubspec(File file) async { try { - return Pubspec.parse(await File(path).readAsString()); + return Pubspec.parse(await file.readAsString(), sourceUrl: file.uri); } on Exception catch (e) { - throw Exception("Error parsing package pubspec at $path. Error $e"); + throw Exception('Error parsing package pubspec at ${file.parent}. Error $e'); } } @override FutureOr run() async { - options = parseOptionsResult(argResults!); - validateOptions(); + final pubspec = await parsePubspec(File('pubspec.yaml')); + final flavor = pubspec.dependencies['flutter'] == null ? Flavor.dart : Flavor.flutter; - final realmPackagePath = await getRealmPackagePath(); - final realmPubspec = await parsePubspec(realmPackagePath); + options = parseOptionsResult(argResults!); + validateOptions(flavor); - if (!options.force && await shouldSkipInstall(realmPubspec)) { + final flavorName = flavor.packageName; + final realmDependency = pubspec.dependencyOverrides[flavorName] ?? pubspec.dependencies[flavorName]; + if (realmDependency is PathDependency) { + print('Path dependency for $flavorName found. Skipping install of native lib (assuming local development)'); return; } + if (realmDependency == null) { + abort('Package $flavorName not found in dependencies. Add $flavorName package to your pubspec.yaml'); + // TODO: Should we just add it for them? What about the version? + } - final binaryPath = Directory(getBinaryPath(path.dirname(realmPackagePath))); + final realmPackage = await getPackage(flavorName); + final realmPubspec = await parsePubspec(File.fromUri(realmPackage.root)); + final binaryPath = getBinaryPath(realmPackage, isFlutter: flavor == Flavor.flutter); print(binaryPath); - final archiveName = "${options.targetOsType!.name}.tar.gz"; - await downloadAndExtractBinaries(binaryPath, realmPubspec, archiveName); + final archiveName = '${options.targetOsType!.name}.tar.gz'; + await downloadAndExtractBinaries(binaryPath, realmPubspec.version!, archiveName); - print("Realm install command finished."); + print('Realm install command finished.'); } - void validateOptions() { - if (isFlutter) { - if (options.targetOsType == null) { - abort("Invalid target OS: null."); - } - } else { - options.targetOsType ??= getTargetOS(); - if ((options.targetOsType == TargetOsType.ios || options.targetOsType == TargetOsType.android) && isDart) { - throw Exception("Invalid package name $packageName for target OS ${options.targetOsType}"); - } + void validateOptions(Flavor flavor) { + final targetOs = flavor == Flavor.dart? getTargetOS() : options.targetOsType; + if (targetOs == null) { + abort('Target OS not specified'); } } - TargetOsType getTargetOS() => Platform.operatingSystem.asTargetOsType ?? (throw UnsupportedError("Unsupported platform ${Platform.operatingSystem}")); + TargetOsType getTargetOS() => Platform.operatingSystem.asTargetOsType ?? (throw UnsupportedError('Unsupported platform ${Platform.operatingSystem}')); - void abort(String error) { + Never abort(String error) { print(error); print(usage); exit(64); //usage error diff --git a/packages/realm_dart/lib/src/cli/install/options.dart b/packages/realm_dart/lib/src/cli/install/options.dart index b67f4830f..8bf98f3f2 100644 --- a/packages/realm_dart/lib/src/cli/install/options.dart +++ b/packages/realm_dart/lib/src/cli/install/options.dart @@ -26,9 +26,6 @@ class Options { @CliOption(help: 'The target OS to install binaries for.', abbr: 't') TargetOsType? targetOsType; - @CliOption(help: 'The flavor to install binaries for.', abbr: 'f', defaultsTo: Flavor.dart) - Flavor flavor; - // use to debug install command @CliOption(hide: true, help: 'Download binary from http://localhost:8000/.', defaultsTo: false) bool debug; @@ -36,7 +33,7 @@ class Options { @CliOption(hide: true, help: 'Force install, even if we would normally skip it.', defaultsTo: false) bool force; - Options({this.targetOsType, this.flavor = Flavor.dart, this.force = false, this.debug = false}); + Options({this.targetOsType, this.force = false, this.debug = false}); } String get usage => _$parserForOptions.usage; diff --git a/packages/realm_dart/lib/src/cli/install/options.g.dart b/packages/realm_dart/lib/src/cli/install/options.g.dart index 0da5c69cf..f0a4e6e05 100644 --- a/packages/realm_dart/lib/src/cli/install/options.g.dart +++ b/packages/realm_dart/lib/src/cli/install/options.g.dart @@ -28,10 +28,6 @@ Options _$parseOptionsResult(ArgResults result) => Options( _$TargetOsTypeEnumMapBuildCli, result['target-os-type'] as String?, ), - flavor: _$enumValueHelper( - _$FlavorEnumMapBuildCli, - result['flavor'] as String, - ), force: result['force'] as bool, debug: result['debug'] as bool, ); @@ -44,11 +40,6 @@ const _$TargetOsTypeEnumMapBuildCli = { TargetOsType.windows: 'windows' }; -const _$FlavorEnumMapBuildCli = { - Flavor.flutter: 'flutter', - Flavor.dart: 'dart' -}; - ArgParser _$populateOptionsParser(ArgParser parser) => parser ..addOption( 'target-os-type', @@ -56,13 +47,6 @@ ArgParser _$populateOptionsParser(ArgParser parser) => parser help: 'The target OS to install binaries for.', allowed: ['android', 'ios', 'linux', 'macos', 'windows'], ) - ..addOption( - 'flavor', - abbr: 'f', - help: 'The flavor to install binaries for.', - defaultsTo: 'dart', - allowed: ['flutter', 'dart'], - ) ..addFlag( 'debug', help: 'Download binary from http://localhost:8000/.', From bb5a761233276ca3eec7ddc4ddfdeb94a9c1457a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 27 Feb 2024 19:38:53 +0100 Subject: [PATCH 104/153] Drop ejson_serialization_setup.g.dart (for now) --- packages/ejson/lib/src/configuration.dart | 1 + packages/ejson/lib/src/decoding.dart | 3 +-- packages/ejson/test/ejson_serialization_setup.g.dart | 8 -------- packages/ejson/test/ejson_test.dart | 3 +-- 4 files changed, 3 insertions(+), 12 deletions(-) delete mode 100644 packages/ejson/test/ejson_serialization_setup.g.dart diff --git a/packages/ejson/lib/src/configuration.dart b/packages/ejson/lib/src/configuration.dart index 361b13694..411e77606 100644 --- a/packages/ejson/lib/src/configuration.dart +++ b/packages/ejson/lib/src/configuration.dart @@ -23,6 +23,7 @@ import 'package:type_plus/type_plus.dart'; import 'decoding.dart'; import 'encoding.dart'; +/// Register custom EJSON [encoder] and [decoder] for a [T]. void register(EJsonEncoder encoder, EJsonDecoder decoder) { TypePlus.add(); customEncoders[T] = encoder; diff --git a/packages/ejson/lib/src/decoding.dart b/packages/ejson/lib/src/decoding.dart index 286fe3940..042c842be 100644 --- a/packages/ejson/lib/src/decoding.dart +++ b/packages/ejson/lib/src/decoding.dart @@ -50,9 +50,8 @@ const commonDecoders = { UndefinedOr: _decodeUndefinedOr, }; -var customDecoders = {}; +final customDecoders = {}; -// if registerSerializableTypes not called final decoders = () { // register extra common types on first access undefinedOr(dynamic f) => f>(); diff --git a/packages/ejson/test/ejson_serialization_setup.g.dart b/packages/ejson/test/ejson_serialization_setup.g.dart deleted file mode 100644 index 47090ddf5..000000000 --- a/packages/ejson/test/ejson_serialization_setup.g.dart +++ /dev/null @@ -1,8 +0,0 @@ -// TODO: should be generated by builder -import 'package:ejson/ejson.dart'; - -import 'person.dart'; - -void registerSerializableTypes() { - register(encodePerson, decodePerson); -} diff --git a/packages/ejson/test/ejson_test.dart b/packages/ejson/test/ejson_test.dart index 2caeaafac..da4e089f4 100644 --- a/packages/ejson/test/ejson_test.dart +++ b/packages/ejson/test/ejson_test.dart @@ -25,7 +25,6 @@ import 'package:objectid/objectid.dart'; import 'package:sane_uuid/uuid.dart'; import 'package:test/test.dart'; -import 'ejson_serialization_setup.g.dart'; import 'person.dart'; void _testCase( @@ -243,7 +242,7 @@ void main() { }); group('custom types', () { - registerSerializableTypes(); + register(encodePerson, decodePerson); final person = Person( 'John', From b861fcb4318cabd853c3cb928da2abaeca27fbe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 27 Feb 2024 20:17:18 +0100 Subject: [PATCH 105/153] Support Uint8List --- packages/ejson/lib/src/decoding.dart | 15 ++++++++------- packages/ejson/lib/src/encoding.dart | 15 ++++++++++++--- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/packages/ejson/lib/src/decoding.dart b/packages/ejson/lib/src/decoding.dart index 042c842be..c3829db9d 100644 --- a/packages/ejson/lib/src/decoding.dart +++ b/packages/ejson/lib/src/decoding.dart @@ -45,6 +45,7 @@ const commonDecoders = { ObjectId: _decodeObjectId, String: _decodeString, Symbol: _decodeSymbol, + Uint8List: _decodeBinary, Uuid: _decodeUuid, Undefined: _decodeUndefined, UndefinedOr: _decodeUndefinedOr, @@ -100,6 +101,7 @@ dynamic _decodeAny(EJsonValue ejson) { {'\$undefined': _} => _decodeUndefined(ejson), {'\$oid': _} => _decodeObjectId(ejson), {'\$binary': {'base64': _, 'subType': '04'}} => _decodeUuid(ejson), + {'\$binary': _} => _decodeBinary(ejson), List _ => _decodeArray(ejson), Map _ => _tryDecodeCustom(ejson) ?? _decodeDocument(ejson), // other maps goes last!! _ => raiseInvalidEJson(ejson), @@ -243,16 +245,15 @@ UndefinedOr _decodeUndefinedOr(EJsonValue ejson) { } Uuid _decodeUuid(EJsonValue ejson) { - try { - return Uuid.fromBytes(_decodeBinary(ejson, "04")); - } on InvalidEJson { - return raiseInvalidEJson(ejson); // get the type right - } + return switch (ejson) { + {'\$binary': {'base64': String s, 'subType': '04'}} => Uuid.fromBytes(base64.decode(s).buffer), + _ => raiseInvalidEJson(ejson), + }; } -ByteBuffer _decodeBinary(EJsonValue ejson, String subType) { +Uint8List _decodeBinary(EJsonValue ejson) { return switch (ejson) { - {'\$binary': {'base64': String s, 'subType': String t}} when t == subType => base64.decode(s).buffer, + {'\$binary': {'base64': String s, 'subType': _}} => base64.decode(s), _ => raiseInvalidEJson(ejson), }; } diff --git a/packages/ejson/lib/src/encoding.dart b/packages/ejson/lib/src/encoding.dart index 344d9c0d3..811268f12 100644 --- a/packages/ejson/lib/src/encoding.dart +++ b/packages/ejson/lib/src/encoding.dart @@ -46,6 +46,7 @@ EJsonValue _encodeAny(Object? value) { double d => _encodeDouble(d), int i => _encodeInt(i), Key k => _encodeKey(k), + Uint8List b => _encodeBinary(b, '00'), Iterable l => _encodeArray(l), Map m => _encodeDocument(m), ObjectId o => _encodeObjectId(o), @@ -112,10 +113,13 @@ EJsonValue _encodeSymbol(Symbol value) => {'\$symbol': value.name}; EJsonValue _encodeUndefined(Undefined undefined) => {'\$undefined': 1}; -EJsonValue _encodeUuid(Uuid uuid) => _encodeBinary(uuid.bytes, "04"); +EJsonValue _encodeUuid(Uuid uuid) => _encodeBinary(uuid.bytes.asUint8List(), "04"); -EJsonValue _encodeBinary(ByteBuffer buffer, String subtype) => { - '\$binary': {'base64': base64.encode(buffer.asUint8List()), 'subType': subtype}, +EJsonValue _encodeBinary(Uint8List buffer, String subtype) => { + '\$binary': { + 'base64': base64.encode(buffer), + 'subType': subtype, + }, }; EJsonValue _encodeObjectId(ObjectId objectId) => {'\$oid': objectId.hexString}; @@ -194,6 +198,11 @@ extension SymbolEJsonEncoderExtension on Symbol { EJsonValue toEJson() => _encodeSymbol(this); } +extension Uint8ListEJsonEncoderExtension on Uint8List { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => _encodeBinary(this, '00'); +} + extension UndefinedEJsonEncoderExtension on Undefined { @pragma('vm:prefer-inline') EJsonValue toEJson() => _encodeUndefined(this); From 3468c5b0a4ac8d7417e0cccaf89017bdb5f68a00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 27 Feb 2024 20:47:12 +0100 Subject: [PATCH 106/153] Get rid of to extension (use fromJson instead) --- packages/ejson/lib/src/decoding.dart | 4 --- packages/ejson/pubspec.yaml | 2 ++ packages/ejson/test/ejson_test.dart | 16 ++++----- packages/ejson/test/person.dart | 4 +-- packages/ejson/test/person.g.dart | 35 ++++++++++--------- .../ejson_generator/lib/src/generator.dart | 2 +- .../ejson_generator/test/ctor_test.g.dart | 16 ++++----- 7 files changed, 39 insertions(+), 40 deletions(-) diff --git a/packages/ejson/lib/src/decoding.dart b/packages/ejson/lib/src/decoding.dart index c3829db9d..25cda0106 100644 --- a/packages/ejson/lib/src/decoding.dart +++ b/packages/ejson/lib/src/decoding.dart @@ -277,7 +277,3 @@ class MissingDecoder implements Exception { @override String toString() => 'Missing decoder for $type'; } - -extension EJsonValueDecoderExtension on EJsonValue { - T to() => fromEJson(this); -} diff --git a/packages/ejson/pubspec.yaml b/packages/ejson/pubspec.yaml index 3e787616c..e271da5f2 100644 --- a/packages/ejson/pubspec.yaml +++ b/packages/ejson/pubspec.yaml @@ -26,5 +26,7 @@ dependencies: type_plus: ^2.0.0 dev_dependencies: + build_runner: ^2.0.0 + ejson_generator: ^0.1.0 lints: ^3.0.0 test: ^1.21.0 diff --git a/packages/ejson/test/ejson_test.dart b/packages/ejson/test/ejson_test.dart index da4e089f4..cdc70fe22 100644 --- a/packages/ejson/test/ejson_test.dart +++ b/packages/ejson/test/ejson_test.dart @@ -256,15 +256,15 @@ void main() { { 'name': 'John', 'birthDate': { - '\$date': {'\$numberLong': 126226800000} + '\$date': {'\$numberLong': '126226800000'} }, - 'income': {'\$numberDouble': 80000.0}, + 'income': {'\$numberDouble': '80000.0'}, 'spouse': { 'name': 'Jane', 'birthDate': { - '\$date': {'\$numberLong': 94690800000} + '\$date': {'\$numberLong': '94690800000'} }, - 'income': {'\$numberDouble': 90000.0}, + 'income': {'\$numberDouble': '90000.0'}, 'spouse': null } }, @@ -286,15 +286,15 @@ void main() { 'a': { 'name': 'John', 'birthDate': { - '\$date': {'\$numberLong': 126226800000} + '\$date': {'\$numberLong': '126226800000'} }, - 'income': {'\$numberDouble': 80000.0}, + 'income': {'\$numberDouble': '80000.0'}, 'spouse': { 'name': 'Jane', 'birthDate': { - '\$date': {'\$numberLong': 94690800000} + '\$date': {'\$numberLong': '94690800000'} }, - 'income': {'\$numberDouble': 90000.0}, + 'income': {'\$numberDouble': '90000.0'}, 'spouse': null } } diff --git a/packages/ejson/test/person.dart b/packages/ejson/test/person.dart index 4dfe98ab7..d5586d60b 100644 --- a/packages/ejson/test/person.dart +++ b/packages/ejson/test/person.dart @@ -1,4 +1,5 @@ import 'package:ejson/ejson.dart'; +import 'package:ejson/src/decoding.dart'; import 'package:ejson_annotation/ejson_annotation.dart'; part 'person.g.dart'; @@ -8,14 +9,13 @@ class Person { final DateTime birthDate; Duration get age => DateTime.now().difference(birthDate); - final int? cprNumber; final double income; final Person? spouse; final children = []; @ejson // annotate constructor to generate decoder and encoder - Person(this.name, this.birthDate, this.income, {this.spouse, this.cprNumber}); + Person(this.name, this.birthDate, this.income, {this.spouse}); @override operator ==(other) => diff --git a/packages/ejson/test/person.g.dart b/packages/ejson/test/person.g.dart index d9b219562..afcbc866f 100644 --- a/packages/ejson/test/person.g.dart +++ b/packages/ejson/test/person.g.dart @@ -1,33 +1,34 @@ -// TODO: should be generated by builder +// GENERATED CODE - DO NOT MODIFY BY HAND + part of 'person.dart'; +// ************************************************************************** +// EJsonGenerator +// ************************************************************************** + +EJsonValue encodePerson(Person value) { + return { + 'name': value.name.toEJson(), + 'birthDate': value.birthDate.toEJson(), + 'income': value.income.toEJson(), + 'spouse': value.spouse.toEJson() + }; +} + Person decodePerson(EJsonValue ejson) { return switch (ejson) { { 'name': EJsonValue name, 'birthDate': EJsonValue birthDate, 'income': EJsonValue income, - 'spouse': EJsonValue spouse, + 'spouse': EJsonValue spouse } => - Person( - name.to(), - birthDate.to(), - income.to(), - spouse: spouse.to(), - ), + Person(fromEJson(name), fromEJson(birthDate), fromEJson(income), + spouse: fromEJson(spouse)), _ => raiseInvalidEJson(ejson), }; } -EJsonValue encodePerson(Person person) { - return { - 'name': person.name.toEJson(), - 'birthDate': person.birthDate.toEJson(), - 'income': person.income.toEJson(), - 'spouse': person.spouse.toEJson(), - }; -} - extension PersonEJsonEncoderExtension on Person { @pragma('vm:prefer-inline') EJsonValue toEJson() => encodePerson(this); diff --git a/packages/ejson_generator/lib/src/generator.dart b/packages/ejson_generator/lib/src/generator.dart index 492a11d20..abc0ebe82 100644 --- a/packages/ejson_generator/lib/src/generator.dart +++ b/packages/ejson_generator/lib/src/generator.dart @@ -89,7 +89,7 @@ class EJsonGenerator extends Generator { $className decode$className(EJsonValue ejson) { return switch (ejson) { ${decodePattern(ctor.parameters)} => $className${ctor.name.isEmpty ? '' : '.${ctor.name}'}( - ${ctor.parameters.map((p) => "${p.isNamed ? '${p.name} : ' : ''}${p.name}.to<${p.type}>()").join(',\n')} + ${ctor.parameters.map((p) => "${p.isNamed ? '${p.name} : ' : ''}fromEJson(${p.name})").join(',\n')} ), _ => raiseInvalidEJson(ejson), }; diff --git a/packages/ejson_generator/test/ctor_test.g.dart b/packages/ejson_generator/test/ctor_test.g.dart index 848c10adc..b36078ee1 100644 --- a/packages/ejson_generator/test/ctor_test.g.dart +++ b/packages/ejson_generator/test/ctor_test.g.dart @@ -28,7 +28,7 @@ EJsonValue encodeSimple(Simple value) { Simple decodeSimple(EJsonValue ejson) { return switch (ejson) { - {'i': EJsonValue i} => Simple(i.to()), + {'i': EJsonValue i} => Simple(fromEJson(i)), _ => raiseInvalidEJson(ejson), }; } @@ -44,7 +44,7 @@ EJsonValue encodeNamed(Named value) { Named decodeNamed(EJsonValue ejson) { return switch (ejson) { - {'namedCtor': EJsonValue namedCtor} => Named.nameIt(namedCtor.to()), + {'namedCtor': EJsonValue namedCtor} => Named.nameIt(fromEJson(namedCtor)), _ => raiseInvalidEJson(ejson), }; } @@ -61,7 +61,7 @@ EJsonValue encodeRequiredNamedParameters(RequiredNamedParameters value) { RequiredNamedParameters decodeRequiredNamedParameters(EJsonValue ejson) { return switch (ejson) { {'requiredNamed': EJsonValue requiredNamed} => - RequiredNamedParameters(requiredNamed: requiredNamed.to()), + RequiredNamedParameters(requiredNamed: fromEJson(requiredNamed)), _ => raiseInvalidEJson(ejson), }; } @@ -79,7 +79,7 @@ EJsonValue encodeOptionalNamedParameters(OptionalNamedParameters value) { OptionalNamedParameters decodeOptionalNamedParameters(EJsonValue ejson) { return switch (ejson) { {'optionalNamed': EJsonValue optionalNamed} => - OptionalNamedParameters(optionalNamed: optionalNamed.to()), + OptionalNamedParameters(optionalNamed: fromEJson(optionalNamed)), _ => raiseInvalidEJson(ejson), }; } @@ -97,7 +97,7 @@ EJsonValue encodeOptionalParameters(OptionalParameters value) { OptionalParameters decodeOptionalParameters(EJsonValue ejson) { return switch (ejson) { {'optional': EJsonValue optional} => - OptionalParameters(optional.to()), + OptionalParameters(fromEJson(optional)), _ => raiseInvalidEJson(ejson), }; } @@ -113,7 +113,7 @@ EJsonValue encodePrivateMembers(PrivateMembers value) { PrivateMembers decodePrivateMembers(EJsonValue ejson) { return switch (ejson) { - {'id': EJsonValue id} => PrivateMembers(id.to()), + {'id': EJsonValue id} => PrivateMembers(fromEJson(id)), _ => raiseInvalidEJson(ejson), }; } @@ -142,8 +142,8 @@ Person decodePerson(EJsonValue ejson) { 'spouse': EJsonValue spouse, 'cprNumber': EJsonValue cprNumber } => - Person(name.to(), birthDate.to(), income.to(), - spouse: spouse.to(), cprNumber: cprNumber.to()), + Person(fromEJson(name), fromEJson(birthDate), fromEJson(income), + spouse: fromEJson(spouse), cprNumber: fromEJson(cprNumber)), _ => raiseInvalidEJson(ejson), }; } From d054b655bcfc4ddf18fe9d53b2e6e694927632e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 27 Feb 2024 21:05:31 +0100 Subject: [PATCH 107/153] Update ejson codecs --- melos.yaml | 2 +- packages/realm_dart/example/bin/myapp.g.dart | 10 +- .../realm_dart/test/backlinks_test.g.dart | 12 +- .../realm_dart/test/geospatial_test.g.dart | 8 +- packages/realm_dart/test/indexed_test.g.dart | 12 +- .../realm_dart/test/migration_test.g.dart | 10 +- .../realm_dart/test/realm_map_test.g.dart | 48 ++-- .../realm_dart/test/realm_object_test.g.dart | 20 +- .../realm_dart/test/realm_set_test.g.dart | 40 +-- .../realm_dart/test/realm_value_test.g.dart | 12 +- packages/realm_dart/test/test.g.dart | 263 +++++++++--------- 11 files changed, 216 insertions(+), 221 deletions(-) diff --git a/melos.yaml b/melos.yaml index e287e41c2..097d2af9c 100644 --- a/melos.yaml +++ b/melos.yaml @@ -50,7 +50,7 @@ scripts: build:dart: run: dart run build_runner build --delete-conflicting-outputs exec: - orderDependents: true + concurrency: 1 # only one project at a time to keep output sane packageFilters: dependsOn: build_runner diff --git a/packages/realm_dart/example/bin/myapp.g.dart b/packages/realm_dart/example/bin/myapp.g.dart index b106eafc1..93176012c 100644 --- a/packages/realm_dart/example/bin/myapp.g.dart +++ b/packages/realm_dart/example/bin/myapp.g.dart @@ -23,10 +23,10 @@ Car decodeCar(EJsonValue ejson) { 'kilometers': EJsonValue kilometers, 'owner': EJsonValue owner } => - Car(make.to(), - model: model.to(), - kilometers: kilometers.to(), - owner: owner.to()), + Car(fromEJson(make), + model: fromEJson(model), + kilometers: fromEJson(kilometers), + owner: fromEJson(owner)), _ => raiseInvalidEJson(ejson), }; } @@ -43,7 +43,7 @@ EJsonValue encodePerson(Person value) { Person decodePerson(EJsonValue ejson) { return switch (ejson) { {'name': EJsonValue name, 'age': EJsonValue age} => - Person(name.to(), age: age.to()), + Person(fromEJson(name), age: fromEJson(age)), _ => raiseInvalidEJson(ejson), }; } diff --git a/packages/realm_dart/test/backlinks_test.g.dart b/packages/realm_dart/test/backlinks_test.g.dart index da4a0cfd6..b926e7d87 100644 --- a/packages/realm_dart/test/backlinks_test.g.dart +++ b/packages/realm_dart/test/backlinks_test.g.dart @@ -26,11 +26,11 @@ Source decodeSource(EJsonValue ejson) { 'dynamicManyTargets': EJsonValue dynamicManyTargets } => Source( - name: name.to(), - oneTarget: oneTarget.to(), - dynamicTarget: dynamicTarget.to(), - manyTargets: manyTargets.to>(), - dynamicManyTargets: dynamicManyTargets.to>()), + name: fromEJson(name), + oneTarget: fromEJson(oneTarget), + dynamicTarget: fromEJson(dynamicTarget), + manyTargets: fromEJson(manyTargets), + dynamicManyTargets: fromEJson(dynamicManyTargets)), _ => raiseInvalidEJson(ejson), }; } @@ -47,7 +47,7 @@ EJsonValue encodeTarget(Target value) { Target decodeTarget(EJsonValue ejson) { return switch (ejson) { {'name': EJsonValue name, 'source': EJsonValue source} => - Target(name: name.to(), source: source.to()), + Target(name: fromEJson(name), source: fromEJson(source)), _ => raiseInvalidEJson(ejson), }; } diff --git a/packages/realm_dart/test/geospatial_test.g.dart b/packages/realm_dart/test/geospatial_test.g.dart index 3a7b3e471..395fcb210 100644 --- a/packages/realm_dart/test/geospatial_test.g.dart +++ b/packages/realm_dart/test/geospatial_test.g.dart @@ -16,9 +16,7 @@ EJsonValue encodeLocation(Location value) { Location decodeLocation(EJsonValue ejson) { return switch (ejson) { {'type': EJsonValue type, 'coordinates': EJsonValue coordinates} => - Location( - type: type.to(), - coordinates: coordinates.to>()), + Location(type: fromEJson(type), coordinates: fromEJson(coordinates)), _ => raiseInvalidEJson(ejson), }; } @@ -35,7 +33,7 @@ EJsonValue encodeRestaurant(Restaurant value) { Restaurant decodeRestaurant(EJsonValue ejson) { return switch (ejson) { {'name': EJsonValue name, 'location': EJsonValue location} => - Restaurant(name.to(), location: location.to()), + Restaurant(fromEJson(name), location: fromEJson(location)), _ => raiseInvalidEJson(ejson), }; } @@ -52,7 +50,7 @@ EJsonValue encodeLocationList(LocationList value) { LocationList decodeLocationList(EJsonValue ejson) { return switch (ejson) { {'locations': EJsonValue locations} => - LocationList(locations: locations.to>()), + LocationList(locations: fromEJson(locations)), _ => raiseInvalidEJson(ejson), }; } diff --git a/packages/realm_dart/test/indexed_test.g.dart b/packages/realm_dart/test/indexed_test.g.dart index 6f1f1cb86..8635acbd4 100644 --- a/packages/realm_dart/test/indexed_test.g.dart +++ b/packages/realm_dart/test/indexed_test.g.dart @@ -27,8 +27,8 @@ WithIndexes decodeWithIndexes(EJsonValue ejson) { 'objectId': EJsonValue objectId, 'uuid': EJsonValue uuid } => - WithIndexes(anInt.to(), aBool.to(), string.to(), - timestamp.to(), objectId.to(), uuid.to()), + WithIndexes(fromEJson(anInt), fromEJson(aBool), fromEJson(string), + fromEJson(timestamp), fromEJson(objectId), fromEJson(uuid)), _ => raiseInvalidEJson(ejson), }; } @@ -59,8 +59,8 @@ NoIndexes decodeNoIndexes(EJsonValue ejson) { 'objectId': EJsonValue objectId, 'uuid': EJsonValue uuid } => - NoIndexes(anInt.to(), aBool.to(), string.to(), - timestamp.to(), objectId.to(), uuid.to()), + NoIndexes(fromEJson(anInt), fromEJson(aBool), fromEJson(string), + fromEJson(timestamp), fromEJson(objectId), fromEJson(uuid)), _ => raiseInvalidEJson(ejson), }; } @@ -85,8 +85,8 @@ ObjectWithFTSIndex decodeObjectWithFTSIndex(EJsonValue ejson) { 'summary': EJsonValue summary, 'nullableSummary': EJsonValue nullableSummary } => - ObjectWithFTSIndex(title.to(), summary.to(), - nullableSummary: nullableSummary.to()), + ObjectWithFTSIndex(fromEJson(title), fromEJson(summary), + nullableSummary: fromEJson(nullableSummary)), _ => raiseInvalidEJson(ejson), }; } diff --git a/packages/realm_dart/test/migration_test.g.dart b/packages/realm_dart/test/migration_test.g.dart index aa1724d2e..13bc99ba4 100644 --- a/packages/realm_dart/test/migration_test.g.dart +++ b/packages/realm_dart/test/migration_test.g.dart @@ -12,7 +12,7 @@ EJsonValue encodePersonIntName(PersonIntName value) { PersonIntName decodePersonIntName(EJsonValue ejson) { return switch (ejson) { - {'name': EJsonValue name} => PersonIntName(name.to()), + {'name': EJsonValue name} => PersonIntName(fromEJson(name)), _ => raiseInvalidEJson(ejson), }; } @@ -32,7 +32,7 @@ EJsonValue encodeStudentV1(StudentV1 value) { StudentV1 decodeStudentV1(EJsonValue ejson) { return switch (ejson) { {'name': EJsonValue name, 'yearOfBirth': EJsonValue yearOfBirth} => - StudentV1(name.to(), yearOfBirth: yearOfBirth.to()), + StudentV1(fromEJson(name), yearOfBirth: fromEJson(yearOfBirth)), _ => raiseInvalidEJson(ejson), }; } @@ -49,7 +49,7 @@ EJsonValue encodeMyObjectWithTypo(MyObjectWithTypo value) { MyObjectWithTypo decodeMyObjectWithTypo(EJsonValue ejson) { return switch (ejson) { {'nmae': EJsonValue nmae, 'vlaue': EJsonValue vlaue} => - MyObjectWithTypo(nmae.to(), vlaue.to()), + MyObjectWithTypo(fromEJson(nmae), fromEJson(vlaue)), _ => raiseInvalidEJson(ejson), }; } @@ -66,7 +66,7 @@ EJsonValue encodeMyObjectWithoutTypo(MyObjectWithoutTypo value) { MyObjectWithoutTypo decodeMyObjectWithoutTypo(EJsonValue ejson) { return switch (ejson) { {'name': EJsonValue name, 'value': EJsonValue value} => - MyObjectWithoutTypo(name.to(), value.to()), + MyObjectWithoutTypo(fromEJson(name), fromEJson(value)), _ => raiseInvalidEJson(ejson), }; } @@ -82,7 +82,7 @@ EJsonValue encodeMyObjectWithoutValue(MyObjectWithoutValue value) { MyObjectWithoutValue decodeMyObjectWithoutValue(EJsonValue ejson) { return switch (ejson) { - {'name': EJsonValue name} => MyObjectWithoutValue(name.to()), + {'name': EJsonValue name} => MyObjectWithoutValue(fromEJson(name)), _ => raiseInvalidEJson(ejson), }; } diff --git a/packages/realm_dart/test/realm_map_test.g.dart b/packages/realm_dart/test/realm_map_test.g.dart index 21e7ad423..4d6fcdd41 100644 --- a/packages/realm_dart/test/realm_map_test.g.dart +++ b/packages/realm_dart/test/realm_map_test.g.dart @@ -13,7 +13,7 @@ EJsonValue encodeCar(Car value) { Car decodeCar(EJsonValue ejson) { return switch (ejson) { {'make': EJsonValue make, 'color': EJsonValue color} => - Car(make.to(), color: color.to()), + Car(fromEJson(make), color: fromEJson(color)), _ => raiseInvalidEJson(ejson), }; } @@ -29,7 +29,7 @@ EJsonValue encodeEmbeddedValue(EmbeddedValue value) { EmbeddedValue decodeEmbeddedValue(EJsonValue ejson) { return switch (ejson) { - {'intValue': EJsonValue intValue} => EmbeddedValue(intValue.to()), + {'intValue': EJsonValue intValue} => EmbeddedValue(fromEJson(intValue)), _ => raiseInvalidEJson(ejson), }; } @@ -92,28 +92,28 @@ TestRealmMaps decodeTestRealmMaps(EJsonValue ejson) { 'embeddedMap': EJsonValue embeddedMap, 'mixedMap': EJsonValue mixedMap } => - TestRealmMaps(key.to(), - boolMap: boolMap.to>(), - intMap: intMap.to>(), - stringMap: stringMap.to>(), - doubleMap: doubleMap.to>(), - dateTimeMap: dateTimeMap.to>(), - objectIdMap: objectIdMap.to>(), - uuidMap: uuidMap.to>(), - binaryMap: binaryMap.to>(), - decimalMap: decimalMap.to>(), - nullableBoolMap: nullableBoolMap.to>(), - nullableIntMap: nullableIntMap.to>(), - nullableStringMap: nullableStringMap.to>(), - nullableDoubleMap: nullableDoubleMap.to>(), - nullableDateTimeMap: nullableDateTimeMap.to>(), - nullableObjectIdMap: nullableObjectIdMap.to>(), - nullableUuidMap: nullableUuidMap.to>(), - nullableBinaryMap: nullableBinaryMap.to>(), - nullableDecimalMap: nullableDecimalMap.to>(), - objectsMap: objectsMap.to>(), - embeddedMap: embeddedMap.to>(), - mixedMap: mixedMap.to>()), + TestRealmMaps(fromEJson(key), + boolMap: fromEJson(boolMap), + intMap: fromEJson(intMap), + stringMap: fromEJson(stringMap), + doubleMap: fromEJson(doubleMap), + dateTimeMap: fromEJson(dateTimeMap), + objectIdMap: fromEJson(objectIdMap), + uuidMap: fromEJson(uuidMap), + binaryMap: fromEJson(binaryMap), + decimalMap: fromEJson(decimalMap), + nullableBoolMap: fromEJson(nullableBoolMap), + nullableIntMap: fromEJson(nullableIntMap), + nullableStringMap: fromEJson(nullableStringMap), + nullableDoubleMap: fromEJson(nullableDoubleMap), + nullableDateTimeMap: fromEJson(nullableDateTimeMap), + nullableObjectIdMap: fromEJson(nullableObjectIdMap), + nullableUuidMap: fromEJson(nullableUuidMap), + nullableBinaryMap: fromEJson(nullableBinaryMap), + nullableDecimalMap: fromEJson(nullableDecimalMap), + objectsMap: fromEJson(objectsMap), + embeddedMap: fromEJson(embeddedMap), + mixedMap: fromEJson(mixedMap)), _ => raiseInvalidEJson(ejson), }; } diff --git a/packages/realm_dart/test/realm_object_test.g.dart b/packages/realm_dart/test/realm_object_test.g.dart index dfefdcb38..ee419acde 100644 --- a/packages/realm_dart/test/realm_object_test.g.dart +++ b/packages/realm_dart/test/realm_object_test.g.dart @@ -12,7 +12,7 @@ EJsonValue encodeObjectIdPrimaryKey(ObjectIdPrimaryKey value) { ObjectIdPrimaryKey decodeObjectIdPrimaryKey(EJsonValue ejson) { return switch (ejson) { - {'id': EJsonValue id} => ObjectIdPrimaryKey(id.to()), + {'id': EJsonValue id} => ObjectIdPrimaryKey(fromEJson(id)), _ => raiseInvalidEJson(ejson), }; } @@ -28,7 +28,7 @@ EJsonValue encodeNullableObjectIdPrimaryKey(NullableObjectIdPrimaryKey value) { NullableObjectIdPrimaryKey decodeNullableObjectIdPrimaryKey(EJsonValue ejson) { return switch (ejson) { - {'id': EJsonValue id} => NullableObjectIdPrimaryKey(id.to()), + {'id': EJsonValue id} => NullableObjectIdPrimaryKey(fromEJson(id)), _ => raiseInvalidEJson(ejson), }; } @@ -45,7 +45,7 @@ EJsonValue encodeIntPrimaryKey(IntPrimaryKey value) { IntPrimaryKey decodeIntPrimaryKey(EJsonValue ejson) { return switch (ejson) { - {'id': EJsonValue id} => IntPrimaryKey(id.to()), + {'id': EJsonValue id} => IntPrimaryKey(fromEJson(id)), _ => raiseInvalidEJson(ejson), }; } @@ -61,7 +61,7 @@ EJsonValue encodeNullableIntPrimaryKey(NullableIntPrimaryKey value) { NullableIntPrimaryKey decodeNullableIntPrimaryKey(EJsonValue ejson) { return switch (ejson) { - {'id': EJsonValue id} => NullableIntPrimaryKey(id.to()), + {'id': EJsonValue id} => NullableIntPrimaryKey(fromEJson(id)), _ => raiseInvalidEJson(ejson), }; } @@ -77,7 +77,7 @@ EJsonValue encodeStringPrimaryKey(StringPrimaryKey value) { StringPrimaryKey decodeStringPrimaryKey(EJsonValue ejson) { return switch (ejson) { - {'id': EJsonValue id} => StringPrimaryKey(id.to()), + {'id': EJsonValue id} => StringPrimaryKey(fromEJson(id)), _ => raiseInvalidEJson(ejson), }; } @@ -93,7 +93,7 @@ EJsonValue encodeNullableStringPrimaryKey(NullableStringPrimaryKey value) { NullableStringPrimaryKey decodeNullableStringPrimaryKey(EJsonValue ejson) { return switch (ejson) { - {'id': EJsonValue id} => NullableStringPrimaryKey(id.to()), + {'id': EJsonValue id} => NullableStringPrimaryKey(fromEJson(id)), _ => raiseInvalidEJson(ejson), }; } @@ -110,7 +110,7 @@ EJsonValue encodeUuidPrimaryKey(UuidPrimaryKey value) { UuidPrimaryKey decodeUuidPrimaryKey(EJsonValue ejson) { return switch (ejson) { - {'id': EJsonValue id} => UuidPrimaryKey(id.to()), + {'id': EJsonValue id} => UuidPrimaryKey(fromEJson(id)), _ => raiseInvalidEJson(ejson), }; } @@ -126,7 +126,7 @@ EJsonValue encodeNullableUuidPrimaryKey(NullableUuidPrimaryKey value) { NullableUuidPrimaryKey decodeNullableUuidPrimaryKey(EJsonValue ejson) { return switch (ejson) { - {'id': EJsonValue id} => NullableUuidPrimaryKey(id.to()), + {'id': EJsonValue id} => NullableUuidPrimaryKey(fromEJson(id)), _ => raiseInvalidEJson(ejson), }; } @@ -145,7 +145,7 @@ RemappedFromAnotherFile decodeRemappedFromAnotherFile(EJsonValue ejson) { return switch (ejson) { {'linkToAnotherClass': EJsonValue linkToAnotherClass} => RemappedFromAnotherFile( - linkToAnotherClass: linkToAnotherClass.to()), + linkToAnotherClass: fromEJson(linkToAnotherClass)), _ => raiseInvalidEJson(ejson), }; } @@ -163,7 +163,7 @@ EJsonValue encodeBoolValue(BoolValue value) { BoolValue decodeBoolValue(EJsonValue ejson) { return switch (ejson) { {'key': EJsonValue key, 'value': EJsonValue value} => - BoolValue(key.to(), value.to()), + BoolValue(fromEJson(key), fromEJson(value)), _ => raiseInvalidEJson(ejson), }; } diff --git a/packages/realm_dart/test/realm_set_test.g.dart b/packages/realm_dart/test/realm_set_test.g.dart index 62747765d..cbf839ef3 100644 --- a/packages/realm_dart/test/realm_set_test.g.dart +++ b/packages/realm_dart/test/realm_set_test.g.dart @@ -13,7 +13,7 @@ EJsonValue encodeCar(Car value) { Car decodeCar(EJsonValue ejson) { return switch (ejson) { {'make': EJsonValue make, 'color': EJsonValue color} => - Car(make.to(), color: color.to()), + Car(fromEJson(make), color: fromEJson(color)), _ => raiseInvalidEJson(ejson), }; } @@ -70,25 +70,25 @@ TestRealmSets decodeTestRealmSets(EJsonValue ejson) { 'nullableUuidSet': EJsonValue nullableUuidSet, 'nullableBinarySet': EJsonValue nullableBinarySet } => - TestRealmSets(key.to(), - boolSet: boolSet.to>(), - intSet: intSet.to>(), - stringSet: stringSet.to>(), - doubleSet: doubleSet.to>(), - dateTimeSet: dateTimeSet.to>(), - objectIdSet: objectIdSet.to>(), - uuidSet: uuidSet.to>(), - mixedSet: mixedSet.to>(), - objectsSet: objectsSet.to>(), - binarySet: binarySet.to>(), - nullableBoolSet: nullableBoolSet.to>(), - nullableIntSet: nullableIntSet.to>(), - nullableStringSet: nullableStringSet.to>(), - nullableDoubleSet: nullableDoubleSet.to>(), - nullableDateTimeSet: nullableDateTimeSet.to>(), - nullableObjectIdSet: nullableObjectIdSet.to>(), - nullableUuidSet: nullableUuidSet.to>(), - nullableBinarySet: nullableBinarySet.to>()), + TestRealmSets(fromEJson(key), + boolSet: fromEJson(boolSet), + intSet: fromEJson(intSet), + stringSet: fromEJson(stringSet), + doubleSet: fromEJson(doubleSet), + dateTimeSet: fromEJson(dateTimeSet), + objectIdSet: fromEJson(objectIdSet), + uuidSet: fromEJson(uuidSet), + mixedSet: fromEJson(mixedSet), + objectsSet: fromEJson(objectsSet), + binarySet: fromEJson(binarySet), + nullableBoolSet: fromEJson(nullableBoolSet), + nullableIntSet: fromEJson(nullableIntSet), + nullableStringSet: fromEJson(nullableStringSet), + nullableDoubleSet: fromEJson(nullableDoubleSet), + nullableDateTimeSet: fromEJson(nullableDateTimeSet), + nullableObjectIdSet: fromEJson(nullableObjectIdSet), + nullableUuidSet: fromEJson(nullableUuidSet), + nullableBinarySet: fromEJson(nullableBinarySet)), _ => raiseInvalidEJson(ejson), }; } diff --git a/packages/realm_dart/test/realm_value_test.g.dart b/packages/realm_dart/test/realm_value_test.g.dart index 319efcbf1..284ab589b 100644 --- a/packages/realm_dart/test/realm_value_test.g.dart +++ b/packages/realm_dart/test/realm_value_test.g.dart @@ -12,7 +12,7 @@ EJsonValue encodeTuckedIn(TuckedIn value) { TuckedIn decodeTuckedIn(EJsonValue ejson) { return switch (ejson) { - {'x': EJsonValue x} => TuckedIn(x: x.to()), + {'x': EJsonValue x} => TuckedIn(x: fromEJson(x)), _ => raiseInvalidEJson(ejson), }; } @@ -40,10 +40,10 @@ AnythingGoes decodeAnythingGoes(EJsonValue ejson) { 'dictOfAny': EJsonValue dictOfAny } => AnythingGoes( - oneAny: oneAny.to(), - manyAny: manyAny.to>(), - setOfAny: setOfAny.to>(), - dictOfAny: dictOfAny.to>()), + oneAny: fromEJson(oneAny), + manyAny: fromEJson(manyAny), + setOfAny: fromEJson(setOfAny), + dictOfAny: fromEJson(dictOfAny)), _ => raiseInvalidEJson(ejson), }; } @@ -59,7 +59,7 @@ EJsonValue encodeStuff(Stuff value) { Stuff decodeStuff(EJsonValue ejson) { return switch (ejson) { - {'i': EJsonValue i} => Stuff(i: i.to()), + {'i': EJsonValue i} => Stuff(i: fromEJson(i)), _ => raiseInvalidEJson(ejson), }; } diff --git a/packages/realm_dart/test/test.g.dart b/packages/realm_dart/test/test.g.dart index 95d781920..bb3d8052d 100644 --- a/packages/realm_dart/test/test.g.dart +++ b/packages/realm_dart/test/test.g.dart @@ -12,7 +12,7 @@ EJsonValue encodeCar(Car value) { Car decodeCar(EJsonValue ejson) { return switch (ejson) { - {'make': EJsonValue make} => Car(make.to()), + {'make': EJsonValue make} => Car(fromEJson(make)), _ => raiseInvalidEJson(ejson), }; } @@ -28,7 +28,7 @@ EJsonValue encodePerson(Person value) { Person decodePerson(EJsonValue ejson) { return switch (ejson) { - {'name': EJsonValue name} => Person(name.to()), + {'name': EJsonValue name} => Person(fromEJson(name)), _ => raiseInvalidEJson(ejson), }; } @@ -53,7 +53,7 @@ Dog decodeDog(EJsonValue ejson) { 'age': EJsonValue age, 'owner': EJsonValue owner } => - Dog(name.to(), age: age.to(), owner: owner.to()), + Dog(fromEJson(name), age: fromEJson(age), owner: fromEJson(owner)), _ => raiseInvalidEJson(ejson), }; } @@ -78,9 +78,8 @@ Team decodeTeam(EJsonValue ejson) { 'players': EJsonValue players, 'scores': EJsonValue scores } => - Team(name.to(), - players: players.to>(), - scores: scores.to>()), + Team(fromEJson(name), + players: fromEJson(players), scores: fromEJson(scores)), _ => raiseInvalidEJson(ejson), }; } @@ -107,10 +106,10 @@ Student decodeStudent(EJsonValue ejson) { 'yearOfBirth': EJsonValue yearOfBirth, 'school': EJsonValue school } => - Student(number.to(), - name: name.to(), - yearOfBirth: yearOfBirth.to(), - school: school.to()), + Student(fromEJson(number), + name: fromEJson(name), + yearOfBirth: fromEJson(yearOfBirth), + school: fromEJson(school)), _ => raiseInvalidEJson(ejson), }; } @@ -139,11 +138,11 @@ School decodeSchool(EJsonValue ejson) { 'students': EJsonValue students, 'branches': EJsonValue branches } => - School(name.to(), - city: city.to(), - branchOfSchool: branchOfSchool.to(), - students: students.to>(), - branches: branches.to>()), + School(fromEJson(name), + city: fromEJson(city), + branchOfSchool: fromEJson(branchOfSchool), + students: fromEJson(students), + branches: fromEJson(branches)), _ => raiseInvalidEJson(ejson), }; } @@ -166,8 +165,8 @@ RemappedClass decodeRemappedClass(EJsonValue ejson) { 'remappedProperty': EJsonValue remappedProperty, 'listProperty': EJsonValue listProperty } => - RemappedClass(remappedProperty.to(), - listProperty: listProperty.to>()), + RemappedClass(fromEJson(remappedProperty), + listProperty: fromEJson(listProperty)), _ => raiseInvalidEJson(ejson), }; } @@ -183,7 +182,7 @@ EJsonValue encodeTask(Task value) { Task decodeTask(EJsonValue ejson) { return switch (ejson) { - {'id': EJsonValue id} => Task(id.to()), + {'id': EJsonValue id} => Task(fromEJson(id)), _ => raiseInvalidEJson(ejson), }; } @@ -200,7 +199,7 @@ EJsonValue encodeProduct(Product value) { Product decodeProduct(EJsonValue ejson) { return switch (ejson) { {'id': EJsonValue id, 'name': EJsonValue name} => - Product(id.to(), name.to()), + Product(fromEJson(id), fromEJson(name)), _ => raiseInvalidEJson(ejson), }; } @@ -217,7 +216,7 @@ EJsonValue encodeSchedule(Schedule value) { Schedule decodeSchedule(EJsonValue ejson) { return switch (ejson) { {'id': EJsonValue id, 'tasks': EJsonValue tasks} => - Schedule(id.to(), tasks: tasks.to>()), + Schedule(fromEJson(id), tasks: fromEJson(tasks)), _ => raiseInvalidEJson(ejson), }; } @@ -242,9 +241,9 @@ Foo decodeFoo(EJsonValue ejson) { 'defaultValueBinaryProp': EJsonValue defaultValueBinaryProp, 'nullableBinaryProp': EJsonValue nullableBinaryProp } => - Foo(requiredBinaryProp.to(), - defaultValueBinaryProp: defaultValueBinaryProp.to(), - nullableBinaryProp: nullableBinaryProp.to()), + Foo(fromEJson(requiredBinaryProp), + defaultValueBinaryProp: fromEJson(defaultValueBinaryProp), + nullableBinaryProp: fromEJson(nullableBinaryProp)), _ => raiseInvalidEJson(ejson), }; } @@ -300,24 +299,24 @@ AllTypes decodeAllTypes(EJsonValue ejson) { 'nullableBinaryProp': EJsonValue nullableBinaryProp } => AllTypes( - stringProp.to(), - boolProp.to(), - dateProp.to(), - doubleProp.to(), - objectIdProp.to(), - uuidProp.to(), - intProp.to(), - decimalProp.to(), - binaryProp: binaryProp.to(), - nullableStringProp: nullableStringProp.to(), - nullableBoolProp: nullableBoolProp.to(), - nullableDateProp: nullableDateProp.to(), - nullableDoubleProp: nullableDoubleProp.to(), - nullableObjectIdProp: nullableObjectIdProp.to(), - nullableUuidProp: nullableUuidProp.to(), - nullableIntProp: nullableIntProp.to(), - nullableDecimalProp: nullableDecimalProp.to(), - nullableBinaryProp: nullableBinaryProp.to()), + fromEJson(stringProp), + fromEJson(boolProp), + fromEJson(dateProp), + fromEJson(doubleProp), + fromEJson(objectIdProp), + fromEJson(uuidProp), + fromEJson(intProp), + fromEJson(decimalProp), + binaryProp: fromEJson(binaryProp), + nullableStringProp: fromEJson(nullableStringProp), + nullableBoolProp: fromEJson(nullableBoolProp), + nullableDateProp: fromEJson(nullableDateProp), + nullableDoubleProp: fromEJson(nullableDoubleProp), + nullableObjectIdProp: fromEJson(nullableObjectIdProp), + nullableUuidProp: fromEJson(nullableUuidProp), + nullableIntProp: fromEJson(nullableIntProp), + nullableDecimalProp: fromEJson(nullableDecimalProp), + nullableBinaryProp: fromEJson(nullableBinaryProp)), _ => raiseInvalidEJson(ejson), }; } @@ -338,8 +337,7 @@ EJsonValue encodeLinksClass(LinksClass value) { LinksClass decodeLinksClass(EJsonValue ejson) { return switch (ejson) { {'id': EJsonValue id, 'link': EJsonValue link, 'list': EJsonValue list} => - LinksClass(id.to(), - link: link.to(), list: list.to>()), + LinksClass(fromEJson(id), link: fromEJson(link), list: fromEJson(list)), _ => raiseInvalidEJson(ejson), }; } @@ -391,22 +389,22 @@ AllCollections decodeAllCollections(EJsonValue ejson) { 'nullableDecimals': EJsonValue nullableDecimals } => AllCollections( - strings: strings.to>(), - bools: bools.to>(), - dates: dates.to>(), - doubles: doubles.to>(), - objectIds: objectIds.to>(), - uuids: uuids.to>(), - ints: ints.to>(), - decimals: decimals.to>(), - nullableStrings: nullableStrings.to>(), - nullableBools: nullableBools.to>(), - nullableDates: nullableDates.to>(), - nullableDoubles: nullableDoubles.to>(), - nullableObjectIds: nullableObjectIds.to>(), - nullableUuids: nullableUuids.to>(), - nullableInts: nullableInts.to>(), - nullableDecimals: nullableDecimals.to>()), + strings: fromEJson(strings), + bools: fromEJson(bools), + dates: fromEJson(dates), + doubles: fromEJson(doubles), + objectIds: fromEJson(objectIds), + uuids: fromEJson(uuids), + ints: fromEJson(ints), + decimals: fromEJson(decimals), + nullableStrings: fromEJson(nullableStrings), + nullableBools: fromEJson(nullableBools), + nullableDates: fromEJson(nullableDates), + nullableDoubles: fromEJson(nullableDoubles), + nullableObjectIds: fromEJson(nullableObjectIds), + nullableUuids: fromEJson(nullableUuids), + nullableInts: fromEJson(nullableInts), + nullableDecimals: fromEJson(nullableDecimals)), _ => raiseInvalidEJson(ejson), }; } @@ -445,15 +443,15 @@ NullableTypes decodeNullableTypes(EJsonValue ejson) { 'intProp': EJsonValue intProp, 'decimalProp': EJsonValue decimalProp } => - NullableTypes(id.to(), differentiator.to(), - stringProp: stringProp.to(), - boolProp: boolProp.to(), - dateProp: dateProp.to(), - doubleProp: doubleProp.to(), - objectIdProp: objectIdProp.to(), - uuidProp: uuidProp.to(), - intProp: intProp.to(), - decimalProp: decimalProp.to()), + NullableTypes(fromEJson(id), fromEJson(differentiator), + stringProp: fromEJson(stringProp), + boolProp: fromEJson(boolProp), + dateProp: fromEJson(dateProp), + doubleProp: fromEJson(doubleProp), + objectIdProp: fromEJson(objectIdProp), + uuidProp: fromEJson(uuidProp), + intProp: fromEJson(intProp), + decimalProp: fromEJson(decimalProp)), _ => raiseInvalidEJson(ejson), }; } @@ -482,11 +480,11 @@ Event decodeEvent(EJsonValue ejson) { 'durationInMinutes': EJsonValue durationInMinutes, 'assignedTo': EJsonValue assignedTo } => - Event(id.to(), - name: name.to(), - isCompleted: isCompleted.to(), - durationInMinutes: durationInMinutes.to(), - assignedTo: assignedTo.to()), + Event(fromEJson(id), + name: fromEJson(name), + isCompleted: fromEJson(isCompleted), + durationInMinutes: fromEJson(durationInMinutes), + assignedTo: fromEJson(assignedTo)), _ => raiseInvalidEJson(ejson), }; } @@ -513,10 +511,10 @@ Party decodeParty(EJsonValue ejson) { 'previous': EJsonValue previous, 'guests': EJsonValue guests } => - Party(year.to(), - host: host.to(), - previous: previous.to(), - guests: guests.to>()), + Party(fromEJson(year), + host: fromEJson(host), + previous: fromEJson(previous), + guests: fromEJson(guests)), _ => raiseInvalidEJson(ejson), }; } @@ -543,10 +541,10 @@ Friend decodeFriend(EJsonValue ejson) { 'bestFriend': EJsonValue bestFriend, 'friends': EJsonValue friends } => - Friend(name.to(), - age: age.to(), - bestFriend: bestFriend.to(), - friends: friends.to>()), + Friend(fromEJson(name), + age: fromEJson(age), + bestFriend: fromEJson(bestFriend), + friends: fromEJson(friends)), _ => raiseInvalidEJson(ejson), }; } @@ -569,7 +567,7 @@ When decodeWhen(EJsonValue ejson) { 'dateTimeUtc': EJsonValue dateTimeUtc, 'locationName': EJsonValue locationName } => - When(dateTimeUtc.to(), locationName.to()), + When(fromEJson(dateTimeUtc), fromEJson(locationName)), _ => raiseInvalidEJson(ejson), }; } @@ -594,9 +592,8 @@ Player decodePlayer(EJsonValue ejson) { 'game': EJsonValue game, 'scoresByRound': EJsonValue scoresByRound } => - Player(name.to(), - game: game.to(), - scoresByRound: scoresByRound.to>()), + Player(fromEJson(name), + game: fromEJson(game), scoresByRound: fromEJson(scoresByRound)), _ => raiseInvalidEJson(ejson), }; } @@ -613,7 +610,7 @@ EJsonValue encodeGame(Game value) { Game decodeGame(EJsonValue ejson) { return switch (ejson) { {'winnerByRound': EJsonValue winnerByRound} => - Game(winnerByRound: winnerByRound.to>()), + Game(winnerByRound: fromEJson(winnerByRound)), _ => raiseInvalidEJson(ejson), }; } @@ -681,30 +678,30 @@ AllTypesEmbedded decodeAllTypesEmbedded(EJsonValue ejson) { 'decimals': EJsonValue decimals } => AllTypesEmbedded( - stringProp.to(), - boolProp.to(), - dateProp.to(), - doubleProp.to(), - objectIdProp.to(), - uuidProp.to(), - intProp.to(), - decimalProp.to(), - nullableStringProp: nullableStringProp.to(), - nullableBoolProp: nullableBoolProp.to(), - nullableDateProp: nullableDateProp.to(), - nullableDoubleProp: nullableDoubleProp.to(), - nullableObjectIdProp: nullableObjectIdProp.to(), - nullableUuidProp: nullableUuidProp.to(), - nullableIntProp: nullableIntProp.to(), - nullableDecimalProp: nullableDecimalProp.to(), - strings: strings.to>(), - bools: bools.to>(), - dates: dates.to>(), - doubles: doubles.to>(), - objectIds: objectIds.to>(), - uuids: uuids.to>(), - ints: ints.to>(), - decimals: decimals.to>()), + fromEJson(stringProp), + fromEJson(boolProp), + fromEJson(dateProp), + fromEJson(doubleProp), + fromEJson(objectIdProp), + fromEJson(uuidProp), + fromEJson(intProp), + fromEJson(decimalProp), + nullableStringProp: fromEJson(nullableStringProp), + nullableBoolProp: fromEJson(nullableBoolProp), + nullableDateProp: fromEJson(nullableDateProp), + nullableDoubleProp: fromEJson(nullableDoubleProp), + nullableObjectIdProp: fromEJson(nullableObjectIdProp), + nullableUuidProp: fromEJson(nullableUuidProp), + nullableIntProp: fromEJson(nullableIntProp), + nullableDecimalProp: fromEJson(nullableDecimalProp), + strings: fromEJson(strings), + bools: fromEJson(bools), + dates: fromEJson(dates), + doubles: fromEJson(doubles), + objectIds: fromEJson(objectIds), + uuids: fromEJson(uuids), + ints: fromEJson(ints), + decimals: fromEJson(decimals)), _ => raiseInvalidEJson(ejson), }; } @@ -735,12 +732,12 @@ ObjectWithEmbedded decodeObjectWithEmbedded(EJsonValue ejson) { 'list': EJsonValue list, 'recursiveList': EJsonValue recursiveList } => - ObjectWithEmbedded(id.to(), - differentiator: differentiator.to(), - singleObject: singleObject.to(), - recursiveObject: recursiveObject.to(), - list: list.to>(), - recursiveList: recursiveList.to>()), + ObjectWithEmbedded(fromEJson(id), + differentiator: fromEJson(differentiator), + singleObject: fromEJson(singleObject), + recursiveObject: fromEJson(recursiveObject), + list: fromEJson(list), + recursiveList: fromEJson(recursiveList)), _ => raiseInvalidEJson(ejson), }; } @@ -767,10 +764,10 @@ RecursiveEmbedded1 decodeRecursiveEmbedded1(EJsonValue ejson) { 'realmObject': EJsonValue realmObject, 'children': EJsonValue children } => - RecursiveEmbedded1(value.to(), - child: child.to(), - realmObject: realmObject.to(), - children: children.to>()), + RecursiveEmbedded1(fromEJson(value), + child: fromEJson(child), + realmObject: fromEJson(realmObject), + children: fromEJson(children)), _ => raiseInvalidEJson(ejson), }; } @@ -797,10 +794,10 @@ RecursiveEmbedded2 decodeRecursiveEmbedded2(EJsonValue ejson) { 'realmObject': EJsonValue realmObject, 'children': EJsonValue children } => - RecursiveEmbedded2(value.to(), - child: child.to(), - realmObject: realmObject.to(), - children: children.to>()), + RecursiveEmbedded2(fromEJson(value), + child: fromEJson(child), + realmObject: fromEJson(realmObject), + children: fromEJson(children)), _ => raiseInvalidEJson(ejson), }; } @@ -816,7 +813,7 @@ EJsonValue encodeRecursiveEmbedded3(RecursiveEmbedded3 value) { RecursiveEmbedded3 decodeRecursiveEmbedded3(EJsonValue ejson) { return switch (ejson) { - {'value': EJsonValue value} => RecursiveEmbedded3(value.to()), + {'value': EJsonValue value} => RecursiveEmbedded3(fromEJson(value)), _ => raiseInvalidEJson(ejson), }; } @@ -839,8 +836,8 @@ ObjectWithDecimal decodeObjectWithDecimal(EJsonValue ejson) { 'decimal': EJsonValue decimal, 'nullableDecimal': EJsonValue nullableDecimal } => - ObjectWithDecimal(decimal.to(), - nullableDecimal: nullableDecimal.to()), + ObjectWithDecimal(fromEJson(decimal), + nullableDecimal: fromEJson(nullableDecimal)), _ => raiseInvalidEJson(ejson), }; } @@ -865,9 +862,9 @@ Asymmetric decodeAsymmetric(EJsonValue ejson) { 'symmetric': EJsonValue symmetric, 'embeddedObjects': EJsonValue embeddedObjects } => - Asymmetric(id.to(), - symmetric: symmetric.to(), - embeddedObjects: embeddedObjects.to>()), + Asymmetric(fromEJson(id), + symmetric: fromEJson(symmetric), + embeddedObjects: fromEJson(embeddedObjects)), _ => raiseInvalidEJson(ejson), }; } @@ -892,8 +889,8 @@ Embedded decodeEmbedded(EJsonValue ejson) { 'any': EJsonValue any, 'symmetric': EJsonValue symmetric } => - Embedded(value.to(), - any: any.to(), symmetric: symmetric.to()), + Embedded(fromEJson(value), + any: fromEJson(any), symmetric: fromEJson(symmetric)), _ => raiseInvalidEJson(ejson), }; } @@ -909,7 +906,7 @@ EJsonValue encodeSymmetric(Symmetric value) { Symmetric decodeSymmetric(EJsonValue ejson) { return switch (ejson) { - {'id': EJsonValue id} => Symmetric(id.to()), + {'id': EJsonValue id} => Symmetric(fromEJson(id)), _ => raiseInvalidEJson(ejson), }; } From 56d47165661e8b8ccef55ed2685e00ec4bb0fc25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 27 Feb 2024 21:21:45 +0100 Subject: [PATCH 108/153] Fix "generator" tests --- packages/realm/example/lib/main.g.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/realm/example/lib/main.g.dart b/packages/realm/example/lib/main.g.dart index 3a513404b..14243f2fd 100644 --- a/packages/realm/example/lib/main.g.dart +++ b/packages/realm/example/lib/main.g.dart @@ -23,10 +23,10 @@ Car decodeCar(EJsonValue ejson) { 'kilometers': EJsonValue kilometers, 'owner': EJsonValue owner } => - Car(make.to(), - model: model.to(), - kilometers: kilometers.to(), - owner: owner.to()), + Car(fromEJson(make), + model: fromEJson(model), + kilometers: fromEJson(kilometers), + owner: fromEJson(owner)), _ => raiseInvalidEJson(ejson), }; } @@ -43,7 +43,7 @@ EJsonValue encodePerson(Person value) { Person decodePerson(EJsonValue ejson) { return switch (ejson) { {'name': EJsonValue name, 'age': EJsonValue age} => - Person(name.to(), age: age.to()), + Person(fromEJson(name), age: fromEJson(age)), _ => raiseInvalidEJson(ejson), }; } From 20031e364f6be638d826b9c6a4af5690ea1a10e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 27 Feb 2024 21:27:51 +0100 Subject: [PATCH 109/153] Fix realm_value_test.dart --- packages/realm_dart/test/realm_value_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/realm_dart/test/realm_value_test.dart b/packages/realm_dart/test/realm_value_test.dart index 150c9c253..529a5e9b4 100644 --- a/packages/realm_dart/test/realm_value_test.dart +++ b/packages/realm_dart/test/realm_value_test.dart @@ -335,7 +335,7 @@ void main() { case RealmCollectionType.map: expect(expected, isMap); final actualMap = actual.asMap(); - final expectedMap = expected as Map; + final expectedMap = expected as Map; expect(actualMap, hasLength(expectedMap.length)); for (String key in expectedMap.keys) { expect(actualMap.containsKey(key), true, reason: "Didn't find $key in the actual map"); From 83bf60783d20f2bf0a2488aa5cbe4d18f62801b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 27 Feb 2024 21:54:03 +0100 Subject: [PATCH 110/153] Convert coverage, despite test failure --- melos.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/melos.yaml b/melos.yaml index 097d2af9c..8cb6b75ad 100644 --- a/melos.yaml +++ b/melos.yaml @@ -73,7 +73,7 @@ scripts: --concurrency=1 --coverage=coverage/ --file-reporter=json:test-results.json - --reporter=github && + --reporter=github; dart pub global run coverage:format_coverage --report-on=lib/ --in=coverage/test/ From bf54b957535ba7222c8a17c04302f80d68b41ce3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 27 Feb 2024 22:38:59 +0100 Subject: [PATCH 111/153] More encoding tests --- packages/ejson/lib/src/encoding.dart | 7 ++++-- packages/ejson/test/ejson_test.dart | 36 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/packages/ejson/lib/src/encoding.dart b/packages/ejson/lib/src/encoding.dart index 811268f12..bb9e3bbfb 100644 --- a/packages/ejson/lib/src/encoding.dart +++ b/packages/ejson/lib/src/encoding.dart @@ -32,8 +32,6 @@ var customEncoders = {}; var relaxed = false; -Type typeOfExpression(T value) => T; - @pragma('vm:prefer-inline') EJsonValue toEJson(Object? value) => _encodeAny(value); @@ -173,6 +171,11 @@ extension MapEJsonEncoderExtension on Map { EJsonValue toEJson() => _encodeDocument(this); } +extension NullEJsonEncoderExtension on Null { + @pragma('vm:prefer-inline') + EJsonValue toEJson() => null; +} + extension NullableObjectEJsonEncoderExtension on Object? { @pragma('vm:prefer-inline') EJsonValue toEJson() => _encodeAny(this); diff --git a/packages/ejson/test/ejson_test.dart b/packages/ejson/test/ejson_test.dart index cdc70fe22..ce18fb0b2 100644 --- a/packages/ejson/test/ejson_test.dart +++ b/packages/ejson/test/ejson_test.dart @@ -40,6 +40,11 @@ void _testCase( expect(toEJson(value), expected); }); + test('encode fluent from $value of type $T', () { + final expected = relaxed ? relaxedExpected : canonicalExpected; + expect(value.toEJson(), expected); + }); + test('decode to $value of type $T', () { final expected = relaxed ? relaxedExpected : canonicalExpected; expect(fromEJson(expected), value); @@ -92,6 +97,37 @@ void _invalidTestCase([EJsonValue ejson = const {}]) { } void main() { + test('fluent encoding', () { + // NOTE: These cannot be handled generically, as we want to hit the correct + // extension method, ie. not the fallback on Object?. + expect(null.toEJson(), toEJson(null)); + expect(1.toEJson(), toEJson(1)); + expect(1.0.toEJson(), toEJson(1.0)); + expect('a'.toEJson(), toEJson('a')); + expect(true.toEJson(), toEJson(true)); + expect(false.toEJson(), toEJson(false)); + expect([1, 2, 3].toEJson(), toEJson([1, 2, 3])); + 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(undefined.toEJson(), toEJson(undefined)); + expect(const Undefined().toEJson(), toEJson(const Undefined())); + expect(Undefined().toEJson(), toEJson(Undefined())); + expect(const Defined(42).toEJson(), toEJson(const Defined(42))); + expect(const Defined(null).toEJson(), toEJson(const Defined(null))); + 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(); + expect(bytes.toEJson(), toEJson(bytes)); + }); + + test('missing encoder', () { + expect(() => toEJson(Dummy()), throwsA(isA().having((e) => e.toString(), 'toString', "Missing encoder for type Dummy (Instance of 'Dummy')"))); + }); + group('invalid', () { _invalidTestCase(); _invalidTestCase(); From f4cf7c8bae279485e41d435313d2182328150207 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 27 Feb 2024 23:13:20 +0100 Subject: [PATCH 112/153] Fix blunder regarding canonical vs. relaxed --- packages/ejson/test/ejson_test.dart | 236 ++++++++++++++-------------- 1 file changed, 116 insertions(+), 120 deletions(-) diff --git a/packages/ejson/test/ejson_test.dart b/packages/ejson/test/ejson_test.dart index ce18fb0b2..a28a72e21 100644 --- a/packages/ejson/test/ejson_test.dart +++ b/packages/ejson/test/ejson_test.dart @@ -27,26 +27,16 @@ import 'package:test/test.dart'; import 'person.dart'; -void _testCase( - T value, - EJsonValue canonicalExpected, [ - EJsonValue? relaxedExpected, -]) { - // relaxed same as canonical, unless otherwise specified - relaxedExpected ??= canonicalExpected; - +void _testCase(T value, EJsonValue expected) { test('encode from $value of type $T', () { - final expected = relaxed ? relaxedExpected : canonicalExpected; expect(toEJson(value), expected); }); test('encode fluent from $value of type $T', () { - final expected = relaxed ? relaxedExpected : canonicalExpected; expect(value.toEJson(), expected); }); test('decode to $value of type $T', () { - final expected = relaxed ? relaxedExpected : canonicalExpected; expect(fromEJson(expected), value); }); @@ -55,7 +45,6 @@ void _testCase( }); test('reverse roundtrip $value of type $T', () { - final expected = relaxed ? relaxedExpected : canonicalExpected; expect(toEJson(fromEJson(expected)), expected); }); @@ -69,7 +58,6 @@ void _testCase( }); test('decode to dynamic', () { - final expected = relaxed ? relaxedExpected : canonicalExpected; // no here, so dynamic expect(() => fromEJson(expected), returnsNormally); }); @@ -81,7 +69,6 @@ void _testCase( }); test('reverse roundtrip $value of type $T as dynamic', () { - final expected = relaxed ? relaxedExpected : canonicalExpected; // no here, so dynamic expect(toEJson(fromEJson(expected)), expected); }); @@ -125,7 +112,8 @@ void main() { }); test('missing encoder', () { - expect(() => toEJson(Dummy()), throwsA(isA().having((e) => e.toString(), 'toString', "Missing encoder for type Dummy (Instance of 'Dummy')"))); + expect( + () => toEJson(Dummy()), throwsA(isA().having((e) => e.toString(), 'toString', "Missing encoder for type Dummy (Instance of 'Dummy')"))); }); group('invalid', () { @@ -151,16 +139,16 @@ void main() { }); }); - for (final useRelaxed in [false, true]) { - group(useRelaxed ? 'relaxed' : 'canonical', () { - relaxed = useRelaxed; + for (final canonical in [true, false]) { + group(canonical ? 'canonical' : 'relaxed', () { + setUp(() => relaxed = !canonical); group('common types', () { final time = DateTime(1974, 4, 10, 2, 42, 12, 202); // no microseconds! _testCase(null, null); - _testCase(1, {'\$numberLong': 1}, 1); - _testCase(1.0, {'\$numberDouble': 1.0}, 1.0); + _testCase(1, canonical ? {'\$numberLong': '1'} : 1); + _testCase(1.0, canonical ? {'\$numberDouble': '1.0'} : 1.0); _testCase(double.infinity, {'\$numberDouble': 'Infinity'}); _testCase(double.negativeInfinity, {'\$numberDouble': '-Infinity'}); _testCase('a', 'a'); @@ -168,44 +156,49 @@ void main() { _testCase(false, false); _testCase( [1, 2, 3], - [ - {'\$numberLong': 1}, - {'\$numberLong': 2}, - {'\$numberLong': 3}, - ], - [1, 2, 3], + canonical + ? [ + {'\$numberLong': '1'}, + {'\$numberLong': '2'}, + {'\$numberLong': '3'}, + ] + : [1, 2, 3], ); _testCase( [1, 1.1], - [ - {'\$numberLong': 1}, - {'\$numberDouble': 1.1}, - ], - [1, 1.1], + canonical + ? [ + {'\$numberLong': '1'}, + {'\$numberDouble': '1.1'}, + ] + : [1, 1.1], ); _testCase( [1, null, 3], - [ - {'\$numberLong': 1}, - null, - {'\$numberLong': 3}, - ], - [1, null, 3], + canonical + ? [ + {'\$numberLong': '1'}, + null, + {'\$numberLong': '3'}, + ] + : [1, null, 3], ); _testCase( {'a': 'abe', 'b': 1}, - { - 'a': 'abe', - 'b': {'\$numberLong': 1}, - }, - {'a': 'abe', 'b': 1}, + canonical + ? { + 'a': 'abe', + 'b': {'\$numberLong': '1'}, + } + : {'a': 'abe', 'b': 1}, ); _testCase( time, - { - '\$date': {'\$numberLong': time.millisecondsSinceEpoch} - }, - {'\$date': time.toIso8601String()}, + canonical + ? { + '\$date': {'\$numberLong': time.millisecondsSinceEpoch.toString()} + } + : {'\$date': time.toIso8601String()}, ); _testCase(#sym, {'\$symbol': 'sym'}); _testCase(Key.max, {'\$maxKey': 1}); @@ -213,9 +206,9 @@ void main() { _testCase(undefined, {'\$undefined': 1}); _testCase(const Undefined(), {'\$undefined': 1}); _testCase(Undefined(), {'\$undefined': 1}); - _testCase(const Defined(42), {'\$numberLong': 42}, 42); + _testCase(const Defined(42), canonical ? {'\$numberLong': '42'} : 42); _testCase(const Defined(null), null); - _testCase(Defined(42), {'\$numberLong': 42}, 42); + _testCase(Defined(42), canonical ? {'\$numberLong': '42'} : 42); _testCase(Defined(null), null); _testCase(ObjectId.fromValues(1, 2, 3), {'\$oid': '000000000000000002000003'}); final uuid = Uuid.v4(); @@ -230,22 +223,23 @@ void main() { 'c': [1, 1.1, null] } }, - { - 'a': { - 'b': null, - 'c': [ - {'\$numberLong': 1}, - {'\$numberDouble': 1.1}, - null - ] - } - }, - { - 'a': { - 'b': null, - 'c': [1, 1.1, null] - } - }, + canonical + ? { + 'a': { + 'b': null, + 'c': [ + {'\$numberLong': '1'}, + {'\$numberDouble': '1.1'}, + null + ] + } + } + : { + 'a': { + 'b': null, + 'c': [1, 1.1, null] + } + }, ); test('UndefinedOr', () { @@ -253,7 +247,7 @@ void main() { expect(x.toEJson(), {'\$undefined': 1}); x = Defined(42); - expect(x.toEJson(), relaxed ? 42 : {'\$numberLong': 42}); + expect(x.toEJson(), relaxed ? 42 : {'\$numberLong': '42'}); x = Defined(null); expect(x.toEJson(), isNull); @@ -289,65 +283,67 @@ void main() { _testCase( person, - { - 'name': 'John', - 'birthDate': { - '\$date': {'\$numberLong': '126226800000'} - }, - 'income': {'\$numberDouble': '80000.0'}, - 'spouse': { - 'name': 'Jane', - 'birthDate': { - '\$date': {'\$numberLong': '94690800000'} - }, - 'income': {'\$numberDouble': '90000.0'}, - 'spouse': null - } - }, - { - 'name': 'John', - 'birthDate': {'\$date': '1974-01-01T00:00:00.000'}, - 'income': 80000.0, - 'spouse': { - 'name': 'Jane', - 'birthDate': {'\$date': '1973-01-01T00:00:00.000'}, - 'income': 90000.0, - 'spouse': null - } - }, + canonical + ? { + 'name': 'John', + 'birthDate': { + '\$date': {'\$numberLong': '126226800000'} + }, + 'income': {'\$numberDouble': '80000.0'}, + 'spouse': { + 'name': 'Jane', + 'birthDate': { + '\$date': {'\$numberLong': '94690800000'} + }, + 'income': {'\$numberDouble': '90000.0'}, + 'spouse': null + } + } + : { + 'name': 'John', + 'birthDate': {'\$date': '1974-01-01T00:00:00.000'}, + 'income': 80000.0, + 'spouse': { + 'name': 'Jane', + 'birthDate': {'\$date': '1973-01-01T00:00:00.000'}, + 'income': 90000.0, + 'spouse': null + } + }, ); _testCase>( {'a': person}, - { - 'a': { - 'name': 'John', - 'birthDate': { - '\$date': {'\$numberLong': '126226800000'} - }, - 'income': {'\$numberDouble': '80000.0'}, - 'spouse': { - 'name': 'Jane', - 'birthDate': { - '\$date': {'\$numberLong': '94690800000'} + canonical + ? { + 'a': { + 'name': 'John', + 'birthDate': { + '\$date': {'\$numberLong': '126226800000'} + }, + 'income': {'\$numberDouble': '80000.0'}, + 'spouse': { + 'name': 'Jane', + 'birthDate': { + '\$date': {'\$numberLong': '94690800000'} + }, + 'income': {'\$numberDouble': '90000.0'}, + 'spouse': null + } + } + } + : { + 'a': { + 'name': 'John', + 'birthDate': {'\$date': '1974-01-01T00:00:00.000'}, + 'income': 80000.0, + 'spouse': { + 'name': 'Jane', + 'birthDate': {'\$date': '1973-01-01T00:00:00.000'}, + 'income': 90000.0, + 'spouse': null + } + } }, - 'income': {'\$numberDouble': '90000.0'}, - 'spouse': null - } - } - }, - { - 'a': { - 'name': 'John', - 'birthDate': {'\$date': '1974-01-01T00:00:00.000'}, - 'income': 80000.0, - 'spouse': { - 'name': 'Jane', - 'birthDate': {'\$date': '1973-01-01T00:00:00.000'}, - 'income': 90000.0, - 'spouse': null - } - } - }, ); }); }); From 78c34d6c0b59519fa277e033d37a7e2fa6fa6b71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 27 Feb 2024 23:29:57 +0100 Subject: [PATCH 113/153] Don't forget windows *sigh* --- melos.yaml | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/melos.yaml b/melos.yaml index 8cb6b75ad..44ce24893 100644 --- a/melos.yaml +++ b/melos.yaml @@ -68,17 +68,9 @@ scripts: melos run test:integration test:unit: - run: >- - dart test - --concurrency=1 - --coverage=coverage/ - --file-reporter=json:test-results.json - --reporter=github; - dart pub global run coverage:format_coverage - --report-on=lib/ - --in=coverage/test/ - --lcov - --out=coverage/lcov.info + run: | + dart test --concurrency=1 --coverage=coverage/ --file-reporter=json:test-results.json --reporter=github + dart pub global run coverage:format_coverage --report-on=lib/ --in=coverage/test/ --lcov --out=coverage/lcov.info exec: concurrency: 1 # only one project at a time to keep output sane packageFilters: From d67ff973542e340b75664749c08842dc67519ae3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 28 Feb 2024 00:10:18 +0100 Subject: [PATCH 114/153] Split test and coverage handling --- .github/workflows/dart-desktop-tests.yml | 2 ++ melos.yaml | 24 ++++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/.github/workflows/dart-desktop-tests.yml b/.github/workflows/dart-desktop-tests.yml index fef884444..0f4d80087 100644 --- a/.github/workflows/dart-desktop-tests.yml +++ b/.github/workflows/dart-desktop-tests.yml @@ -77,6 +77,8 @@ jobs: if: inputs.runner == 'ubuntu-latest' run: | sudo apt-get install lcov + melos coverage:convert + melos coverage:gather melos coverage:groom - name: Publish coverage diff --git a/melos.yaml b/melos.yaml index 44ce24893..4e2ea43c9 100644 --- a/melos.yaml +++ b/melos.yaml @@ -68,9 +68,7 @@ scripts: melos run test:integration test:unit: - run: | - dart test --concurrency=1 --coverage=coverage/ --file-reporter=json:test-results.json --reporter=github - dart pub global run coverage:format_coverage --report-on=lib/ --in=coverage/test/ --lcov --out=coverage/lcov.info + run: dart test --concurrency=1 --coverage=coverage/ --file-reporter=json:test-results.json --reporter=github exec: concurrency: 1 # only one project at a time to keep output sane packageFilters: @@ -168,21 +166,35 @@ scripts: coverage: description: Generate, check and render coverage. run: >- + melos run coverage:convert && + melos run coverage:gather && melos run coverage:groom && melos run coverage:report && melos run coverage:check - coverage:check: - run: dart pub global run coverde check 90 + coverage:check: # TODO: Increase to 90 eventually + run: dart pub global run coverde check 80 exec: concurrency: 1 # only one project at a time to keep output sane packageFilters: fileExists: coverage/lcov.info # by convention - coverage:groom: + coverage:convert: + run: dart pub global run coverage:format_coverage --report-on=lib/ --in=coverage/test/ --lcov --out=coverage/lcov.info + exec: + concurrency: 1 # only one project at a time to keep output sane + packageFilters: + dependsOn: test + dirExists: coverage/test/ + flutter: false + + coverage:gather: run: | rm -rf $MELOS_ROOT_PATH/coverage dart pub global run combine_coverage --repo-path=$MELOS_ROOT_PATH + + coverage:groom: + run: | lcov --remove coverage/lcov.info '*/lib/src/cli/*' -o coverage/lcov.info lcov --remove coverage/lcov.info '*/realm_bindings.dart' -o coverage/lcov.info From 8fa295afce666fc1baf7fdbb9fd84d5105ce7c2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 28 Feb 2024 00:11:03 +0100 Subject: [PATCH 115/153] Small formatting error --- packages/realm_dart/lib/src/cli/install/install_command.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/realm_dart/lib/src/cli/install/install_command.dart b/packages/realm_dart/lib/src/cli/install/install_command.dart index d77452c1d..be6d247fe 100644 --- a/packages/realm_dart/lib/src/cli/install/install_command.dart +++ b/packages/realm_dart/lib/src/cli/install/install_command.dart @@ -165,7 +165,7 @@ class InstallCommand extends Command { } void validateOptions(Flavor flavor) { - final targetOs = flavor == Flavor.dart? getTargetOS() : options.targetOsType; + final targetOs = flavor == Flavor.dart ? getTargetOS() : options.targetOsType; if (targetOs == null) { abort('Target OS not specified'); } From dbe0fcdb3e66edfe68d43bfb9b1b9bd12917b1e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 28 Feb 2024 00:49:16 +0100 Subject: [PATCH 116/153] Use super. syntax --- packages/realm_common/lib/src/realm_types.dart | 2 +- packages/realm_dart/lib/src/configuration.dart | 2 +- packages/realm_dart/lib/src/list.dart | 5 ++--- packages/realm_dart/lib/src/map.dart | 5 ++--- packages/realm_dart/lib/src/native/realm_core.dart | 6 +++--- packages/realm_dart/lib/src/realm_class.dart | 2 +- packages/realm_dart/lib/src/realm_object.dart | 5 ++--- packages/realm_generator/lib/src/error.dart | 6 +++--- 8 files changed, 15 insertions(+), 18 deletions(-) diff --git a/packages/realm_common/lib/src/realm_types.dart b/packages/realm_common/lib/src/realm_types.dart index c41f8bdb4..68028bdae 100644 --- a/packages/realm_common/lib/src/realm_types.dart +++ b/packages/realm_common/lib/src/realm_types.dart @@ -127,7 +127,7 @@ class RealmError extends Error { /// An error throw when operating on an object that has been closed. /// {@category Realm} class RealmClosedError extends RealmError { - RealmClosedError(String message) : super(message); + RealmClosedError(super.message); } /// Thrown if the operation is not supported. diff --git a/packages/realm_dart/lib/src/configuration.dart b/packages/realm_dart/lib/src/configuration.dart index dc59c3ec2..2abcdd2aa 100644 --- a/packages/realm_dart/lib/src/configuration.dart +++ b/packages/realm_dart/lib/src/configuration.dart @@ -646,7 +646,7 @@ class SyncError extends RealmError { /// The code that describes this error. final SyncErrorCode code; - SyncError._(String message, this.code, this.innerError) : super(message); + SyncError._(super.message, this.code, this.innerError); final Object? innerError; diff --git a/packages/realm_dart/lib/src/list.dart b/packages/realm_dart/lib/src/list.dart index e97892538..aec2d84fa 100644 --- a/packages/realm_dart/lib/src/list.dart +++ b/packages/realm_dart/lib/src/list.dart @@ -221,9 +221,8 @@ class UnmanagedRealmList extends collection.DelegatingList UnmanagedRealmList([Iterable? items]) : this._(List.from(items ?? [])); - UnmanagedRealmList._(List items) - : _base = items, - super(items); + UnmanagedRealmList._(super.items) + : _base = items; @override RealmObjectMetadata? get _metadata => throw RealmException("Unmanaged lists don't have metadata associated with them."); diff --git a/packages/realm_dart/lib/src/map.dart b/packages/realm_dart/lib/src/map.dart index fc3c64bbc..2e74bbc78 100644 --- a/packages/realm_dart/lib/src/map.dart +++ b/packages/realm_dart/lib/src/map.dart @@ -53,9 +53,8 @@ class UnmanagedRealmMap extends collection.DelegatingMap? items]) : this._(Map.from(items ?? {})); - UnmanagedRealmMap._(Map items) - : _base = items, - super(items); + UnmanagedRealmMap._(super.items) + : _base = items; @override bool get isValid => true; diff --git a/packages/realm_dart/lib/src/native/realm_core.dart b/packages/realm_dart/lib/src/native/realm_core.dart index 60e019dfc..21e644584 100644 --- a/packages/realm_dart/lib/src/native/realm_core.dart +++ b/packages/realm_dart/lib/src/native/realm_core.dart @@ -3177,13 +3177,13 @@ abstract class RootedHandleBase extends HandleBase { } abstract class CollectionHandleBase extends RootedHandleBase { - CollectionHandleBase(RealmHandle root, Pointer pointer, int size) : super(root, pointer, size); + CollectionHandleBase(super.root, super.pointer, super.size); } class SchemaHandle extends HandleBase { SchemaHandle._(Pointer pointer) : super(pointer, 24); - SchemaHandle.unowned(Pointer pointer) : super.unowned(pointer); + SchemaHandle.unowned(super.pointer) : super.unowned(); } class ConfigHandle extends HandleBase { @@ -3197,7 +3197,7 @@ class RealmHandle extends HandleBase { RealmHandle._(Pointer pointer) : super(pointer, 24); - RealmHandle._unowned(Pointer pointer) : super.unowned(pointer); + RealmHandle._unowned(super.pointer) : super.unowned(); int addChild(RootedHandleBase child) { final id = _counter++; diff --git a/packages/realm_dart/lib/src/realm_class.dart b/packages/realm_dart/lib/src/realm_class.dart index 6f33d1760..bfea8a413 100644 --- a/packages/realm_dart/lib/src/realm_class.dart +++ b/packages/realm_dart/lib/src/realm_class.dart @@ -1021,7 +1021,7 @@ class MigrationRealm extends DynamicRealm { /// the schema will be read from the file. RealmSchema get schema => _realm.schema; - MigrationRealm._(Realm realm) : super._(realm); + MigrationRealm._(super.realm) : super._(); } /// The signature of a callback that will be executed while the Realm is opened asynchronously with [Realm.open]. diff --git a/packages/realm_dart/lib/src/realm_object.dart b/packages/realm_dart/lib/src/realm_object.dart index 41045f202..828ce75b5 100644 --- a/packages/realm_dart/lib/src/realm_object.dart +++ b/packages/realm_dart/lib/src/realm_object.dart @@ -667,9 +667,8 @@ class RealmException implements Exception { /// An exception thrown when a Realm is opened with a different schema and a migration is required. /// See [LocalConfiguration.migrationCallback] for more details. class MigrationRequiredException extends RealmException { - MigrationRequiredException(String message) - : super(message, - helpLink: "https://www.mongodb.com/docs/realm/sdk/flutter/realm-database/model-data/update-realm-object-schema/#manually-migrate-schema"); + MigrationRequiredException(super.message) + : super(helpLink: "https://www.mongodb.com/docs/realm/sdk/flutter/realm-database/model-data/update-realm-object-schema/#manually-migrate-schema"); @override String toString() { diff --git a/packages/realm_generator/lib/src/error.dart b/packages/realm_generator/lib/src/error.dart index 6e95367fa..37f19e41f 100644 --- a/packages/realm_generator/lib/src/error.dart +++ b/packages/realm_generator/lib/src/error.dart @@ -31,8 +31,8 @@ class RealmInvalidGenerationSourceError extends InvalidGenerationSourceError { bool color; RealmInvalidGenerationSourceError( - String message, { - required String todo, + super.message, { + required super.todo, required Element element, FileSpan? primarySpan, bool? color, @@ -41,7 +41,7 @@ class RealmInvalidGenerationSourceError extends InvalidGenerationSourceError { }) : primarySpan = primarySpan ?? element.span, secondarySpans = {...secondarySpans}, color = color ?? session.color, - super(message, todo: todo, element: element) { + super(element: element) { if (element is FieldElement || element is ConstructorElement) { final classElement = element.enclosingElement!; this.secondarySpans.addAll({ From 562a338fc59db13a563c312695dd58444a1ee7c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 28 Feb 2024 00:52:29 +0100 Subject: [PATCH 117/153] Drop some imports --- packages/ejson/test/person.dart | 1 - packages/realm_dart/lib/src/realm_class.dart | 1 - packages/realm_dart/test/indexed_test.dart | 1 - packages/realm_dart/test/realm_object_test.dart | 1 - packages/realm_dart/test/realm_value_test.dart | 1 - packages/realm_generator/test/info_test.dart | 1 - 6 files changed, 6 deletions(-) diff --git a/packages/ejson/test/person.dart b/packages/ejson/test/person.dart index d5586d60b..055c8cf22 100644 --- a/packages/ejson/test/person.dart +++ b/packages/ejson/test/person.dart @@ -1,5 +1,4 @@ import 'package:ejson/ejson.dart'; -import 'package:ejson/src/decoding.dart'; import 'package:ejson_annotation/ejson_annotation.dart'; part 'person.g.dart'; diff --git a/packages/realm_dart/lib/src/realm_class.dart b/packages/realm_dart/lib/src/realm_class.dart index bfea8a413..45366c3a6 100644 --- a/packages/realm_dart/lib/src/realm_class.dart +++ b/packages/realm_dart/lib/src/realm_class.dart @@ -19,7 +19,6 @@ import 'dart:async'; import 'dart:ffi'; import 'dart:io'; -import 'dart:typed_data'; import 'package:cancellation_token/cancellation_token.dart'; import 'package:collection/collection.dart'; diff --git a/packages/realm_dart/test/indexed_test.dart b/packages/realm_dart/test/indexed_test.dart index 1def604ef..1d77ccf2a 100644 --- a/packages/realm_dart/test/indexed_test.dart +++ b/packages/realm_dart/test/indexed_test.dart @@ -22,7 +22,6 @@ import 'package:ejson/ejson.dart'; import 'dart:math'; import 'dart:typed_data'; -import 'package:collection/collection.dart'; import 'package:test/test.dart' hide test, throws; import 'test.dart'; diff --git a/packages/realm_dart/test/realm_object_test.dart b/packages/realm_dart/test/realm_object_test.dart index 0b4ee1d06..7198c76b4 100644 --- a/packages/realm_dart/test/realm_object_test.dart +++ b/packages/realm_dart/test/realm_object_test.dart @@ -21,7 +21,6 @@ import 'package:ejson_annotation/ejson_annotation.dart'; import 'package:ejson/ejson.dart'; -import 'dart:io'; import 'dart:typed_data'; import 'package:test/test.dart' hide test, throws; import 'package:realm_dart/realm.dart'; diff --git a/packages/realm_dart/test/realm_value_test.dart b/packages/realm_dart/test/realm_value_test.dart index 529a5e9b4..0aa3eb60c 100644 --- a/packages/realm_dart/test/realm_value_test.dart +++ b/packages/realm_dart/test/realm_value_test.dart @@ -19,7 +19,6 @@ import 'package:ejson_annotation/ejson_annotation.dart'; import 'package:ejson/ejson.dart'; -import 'dart:io'; import 'dart:typed_data'; diff --git a/packages/realm_generator/test/info_test.dart b/packages/realm_generator/test/info_test.dart index dab0cb1e7..3c85f3146 100644 --- a/packages/realm_generator/test/info_test.dart +++ b/packages/realm_generator/test/info_test.dart @@ -1,4 +1,3 @@ -import 'dart:async'; import 'dart:io'; import 'package:term_glyph/term_glyph.dart'; From 1369c6cfb3860ab9752f9ea672e659b3b0ad1366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 28 Feb 2024 00:58:29 +0100 Subject: [PATCH 118/153] Don't use _ prefix on already local stuff --- packages/realm_dart/test/configuration_test.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/realm_dart/test/configuration_test.dart b/packages/realm_dart/test/configuration_test.dart index 4aa29dd13..92a26caee 100644 --- a/packages/realm_dart/test/configuration_test.dart +++ b/packages/realm_dart/test/configuration_test.dart @@ -439,7 +439,7 @@ void main() { }); const dummyDataSize = 100; - _addDummyData(Realm realm) { + addDummyData(Realm realm) { for (var i = 0; i < dummyDataSize; i++) { realm.write(() { realm.add(Person(generateRandomString(1000))); @@ -461,7 +461,7 @@ void main() { var config = Configuration.local([Person.schema]); final populateRealm = Realm(config); - _addDummyData(populateRealm); + addDummyData(populateRealm); populateRealm.close(); final oldSize = File(config.path).lengthSync(); From cebfd504d52ed80537c2d7894ffb020fb79155f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 28 Feb 2024 08:41:21 +0100 Subject: [PATCH 119/153] DateTime codec use local time in relaxed mode, but millisecondSinceEpoch (utc) in canonical mode --- packages/ejson/test/ejson_test.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/ejson/test/ejson_test.dart b/packages/ejson/test/ejson_test.dart index a28a72e21..d1ddafdc2 100644 --- a/packages/ejson/test/ejson_test.dart +++ b/packages/ejson/test/ejson_test.dart @@ -287,13 +287,13 @@ void main() { ? { 'name': 'John', 'birthDate': { - '\$date': {'\$numberLong': '126226800000'} + '\$date': {'\$numberLong': person.birthDate.millisecondsSinceEpoch.toString()} }, 'income': {'\$numberDouble': '80000.0'}, 'spouse': { 'name': 'Jane', 'birthDate': { - '\$date': {'\$numberLong': '94690800000'} + '\$date': {'\$numberLong': person.spouse!.birthDate.millisecondsSinceEpoch.toString()} }, 'income': {'\$numberDouble': '90000.0'}, 'spouse': null @@ -318,13 +318,13 @@ void main() { 'a': { 'name': 'John', 'birthDate': { - '\$date': {'\$numberLong': '126226800000'} + '\$date': {'\$numberLong': person.birthDate.millisecondsSinceEpoch.toString()} }, 'income': {'\$numberDouble': '80000.0'}, 'spouse': { 'name': 'Jane', 'birthDate': { - '\$date': {'\$numberLong': '94690800000'} + '\$date': {'\$numberLong': person.spouse!.birthDate.millisecondsSinceEpoch.toString()} }, 'income': {'\$numberDouble': '90000.0'}, 'spouse': null From 929fca31cf2c1e138411e7f440c04531e1a6846f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 28 Feb 2024 14:38:02 +0100 Subject: [PATCH 120/153] export ejson.dart from realm.dart to avoid extra import in user code --- packages/realm_dart/lib/realm.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/realm_dart/lib/realm.dart b/packages/realm_dart/lib/realm.dart index a09767b0f..3e92e27de 100644 --- a/packages/realm_dart/lib/realm.dart +++ b/packages/realm_dart/lib/realm.dart @@ -18,3 +18,5 @@ //dart.library.cli is available only on dart desktop export 'src/realm_flutter.dart' if (dart.library.cli) 'src/realm_dart.dart'; +export 'package:ejson/ejson.dart'; + From df0033e84a7457c223fa7c6c703534a563e1ed43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 28 Feb 2024 14:38:44 +0100 Subject: [PATCH 121/153] export ejson_annotation.dart from ejson.dart to avoid extra import in user code --- packages/ejson/lib/ejson.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/ejson/lib/ejson.dart b/packages/ejson/lib/ejson.dart index 45cb030b0..a60076109 100644 --- a/packages/ejson/lib/ejson.dart +++ b/packages/ejson/lib/ejson.dart @@ -21,3 +21,5 @@ export 'src/configuration.dart'; export 'src/decoding.dart'; export 'src/encoding.dart'; export 'src/types.dart'; + +export 'package:ejson_annotation/ejson_annotation.dart'; From 3bef5c87a4452384b9c25e1f229ea8a7a9578edd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 28 Feb 2024 17:47:47 +0100 Subject: [PATCH 122/153] Update copyright --- packages/ejson/lib/ejson.dart | 20 +++-------------- packages/ejson/lib/src/configuration.dart | 20 +++-------------- packages/ejson/lib/src/decoding.dart | 20 +++-------------- packages/ejson/lib/src/encoding.dart | 20 +++-------------- packages/ejson/lib/src/types.dart | 20 +++-------------- packages/ejson/test/ejson_test.dart | 20 +++-------------- .../lib/ejson_annotation.dart | 19 ++-------------- packages/ejson_generator/lib/src/builder.dart | 20 +++-------------- .../ejson_generator/lib/src/generator.dart | 20 +++-------------- packages/ejson_generator/test/ctor_test.dart | 20 +++-------------- packages/realm/bin/realm.dart | 20 +++-------------- packages/realm/example/lib/main.dart | 19 ++-------------- packages/realm_common/lib/realm_common.dart | 19 ++-------------- .../lib/src/realm_common_base.dart | 19 ++-------------- .../realm_common/lib/src/realm_types.dart | 19 ++-------------- packages/realm_dart/bin/realm_dart.dart | 20 +++-------------- packages/realm_dart/lib/realm.dart | 20 ++--------------- packages/realm_dart/lib/src/app.dart | 20 +++-------------- .../lib/src/cli/archive/archive_command.dart | 19 ++-------------- .../lib/src/cli/archive/options.dart | 19 ++-------------- .../lib/src/cli/atlas_apps/baas_client.dart | 19 ++-------------- .../cli/atlas_apps/deleteapps_command.dart | 19 ++-------------- .../cli/atlas_apps/deployapps_command.dart | 19 ++-------------- .../lib/src/cli/atlas_apps/options.dart | 19 ++-------------- .../lib/src/cli/common/archive.dart | 20 +++-------------- .../lib/src/cli/common/target_os_type.dart | 19 ++-------------- .../realm_dart/lib/src/cli/common/utils.dart | 19 ++-------------- .../lib/src/cli/extract/extract_command.dart | 19 ++-------------- .../lib/src/cli/extract/options.dart | 19 ++-------------- .../src/cli/generate/generate_command.dart | 19 ++-------------- .../lib/src/cli/install/install_command.dart | 19 ++-------------- .../lib/src/cli/install/options.dart | 19 ++-------------- packages/realm_dart/lib/src/cli/main.dart | 19 ++-------------- .../lib/src/cli/metrics/flutter_info.dart | 19 ++-------------- .../lib/src/cli/metrics/metrics.dart | 19 ++-------------- .../lib/src/cli/metrics/metrics_command.dart | 20 +++-------------- .../lib/src/cli/metrics/options.dart | 19 ++-------------- packages/realm_dart/lib/src/collections.dart | 19 ++-------------- .../realm_dart/lib/src/configuration.dart | 19 ++-------------- packages/realm_dart/lib/src/credentials.dart | 19 ++-------------- packages/realm_dart/lib/src/list.dart | 22 +++---------------- packages/realm_dart/lib/src/map.dart | 22 +++---------------- packages/realm_dart/lib/src/migration.dart | 19 ++-------------- .../realm_dart/lib/src/native/decimal128.dart | 19 ++-------------- .../realm_dart/lib/src/native/realm_core.dart | 20 +++-------------- packages/realm_dart/lib/src/realm_class.dart | 19 ++-------------- packages/realm_dart/lib/src/realm_dart.dart | 19 ++-------------- .../realm_dart/lib/src/realm_flutter.dart | 19 ++-------------- packages/realm_dart/lib/src/realm_object.dart | 19 ++-------------- .../realm_dart/lib/src/realm_property.dart | 19 ++-------------- packages/realm_dart/lib/src/results.dart | 20 +++-------------- packages/realm_dart/lib/src/scheduler.dart | 19 +++------------- packages/realm_dart/lib/src/session.dart | 19 ++-------------- packages/realm_dart/lib/src/set.dart | 19 ++-------------- packages/realm_dart/lib/src/subscription.dart | 19 ++-------------- packages/realm_dart/lib/src/user.dart | 19 ++-------------- packages/realm_dart/test/app_test.dart | 19 ++-------------- packages/realm_dart/test/asymmetric_test.dart | 19 ++-------------- packages/realm_dart/test/backlinks_test.dart | 19 ++-------------- .../realm_dart/test/client_reset_test.dart | 19 ++-------------- .../realm_dart/test/configuration_test.dart | 19 ++-------------- .../realm_dart/test/credentials_test.dart | 19 ++-------------- packages/realm_dart/test/decimal128_test.dart | 19 ++-------------- .../realm_dart/test/dynamic_realm_test.dart | 19 ++-------------- packages/realm_dart/test/embedded_test.dart | 19 ++-------------- packages/realm_dart/test/geospatial_test.dart | 19 ++-------------- packages/realm_dart/test/indexed_test.dart | 20 ++--------------- packages/realm_dart/test/list_test.dart | 19 ++-------------- packages/realm_dart/test/manual_test.dart | 19 ++-------------- packages/realm_dart/test/migration_test.dart | 19 ++-------------- .../realm_dart/test/realm_logger_test.dart | 19 ++-------------- packages/realm_dart/test/realm_map_test.dart | 19 ++-------------- .../realm_dart/test/realm_object_test.dart | 19 ++-------------- packages/realm_dart/test/realm_set_test.dart | 19 ++-------------- packages/realm_dart/test/realm_test.dart | 19 ++-------------- .../realm_dart/test/realm_value_test.dart | 20 ++--------------- packages/realm_dart/test/results_test.dart | 19 ++-------------- packages/realm_dart/test/session_test.dart | 19 ++-------------- .../realm_dart/test/subscription_test.dart | 20 +++-------------- packages/realm_dart/test/test.dart | 19 ++-------------- packages/realm_dart/test/user_test.dart | 19 ++-------------- .../realm_generator/lib/realm_generator.dart | 19 ++-------------- .../lib/src/annotation_value.dart | 20 +++-------------- .../lib/src/class_element_ex.dart | 19 ++-------------- .../realm_generator/lib/src/dart_type_ex.dart | 19 ++-------------- packages/realm_generator/lib/src/element.dart | 19 ++-------------- packages/realm_generator/lib/src/error.dart | 20 +++-------------- .../lib/src/expanded_context_span.dart | 19 ++-------------- .../lib/src/field_element_ex.dart | 19 ++-------------- .../realm_generator/lib/src/format_spans.dart | 20 +++-------------- packages/realm_generator/lib/src/measure.dart | 20 +++-------------- .../lib/src/realm_field_info.dart | 20 +++-------------- .../lib/src/realm_model_info.dart | 19 ++-------------- .../lib/src/realm_object_generator.dart | 19 ++-------------- packages/realm_generator/lib/src/session.dart | 19 ++-------------- .../lib/src/type_checkers.dart | 19 ++-------------- packages/realm_generator/lib/src/utils.dart | 19 ++-------------- 97 files changed, 219 insertions(+), 1655 deletions(-) diff --git a/packages/ejson/lib/ejson.dart b/packages/ejson/lib/ejson.dart index a60076109..baf35f543 100644 --- a/packages/ejson/lib/ejson.dart +++ b/packages/ejson/lib/ejson.dart @@ -1,20 +1,6 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2023 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2023 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + library; export 'src/configuration.dart'; diff --git a/packages/ejson/lib/src/configuration.dart b/packages/ejson/lib/src/configuration.dart index 411e77606..55be59891 100644 --- a/packages/ejson/lib/src/configuration.dart +++ b/packages/ejson/lib/src/configuration.dart @@ -1,20 +1,6 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2023 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2023 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + library; import 'package:ejson_annotation/ejson_annotation.dart'; diff --git a/packages/ejson/lib/src/decoding.dart b/packages/ejson/lib/src/decoding.dart index 25cda0106..f58d3a43c 100644 --- a/packages/ejson/lib/src/decoding.dart +++ b/packages/ejson/lib/src/decoding.dart @@ -1,20 +1,6 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2023 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2023 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + library; import 'dart:typed_data'; diff --git a/packages/ejson/lib/src/encoding.dart b/packages/ejson/lib/src/encoding.dart index bb9e3bbfb..d4e54683c 100644 --- a/packages/ejson/lib/src/encoding.dart +++ b/packages/ejson/lib/src/encoding.dart @@ -1,20 +1,6 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2023 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2023 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + library; import 'dart:convert'; diff --git a/packages/ejson/lib/src/types.dart b/packages/ejson/lib/src/types.dart index 61ae06c2a..c33d1722c 100644 --- a/packages/ejson/lib/src/types.dart +++ b/packages/ejson/lib/src/types.dart @@ -1,20 +1,6 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2023 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2023 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + library; enum EJsonType { diff --git a/packages/ejson/test/ejson_test.dart b/packages/ejson/test/ejson_test.dart index d1ddafdc2..2f516949c 100644 --- a/packages/ejson/test/ejson_test.dart +++ b/packages/ejson/test/ejson_test.dart @@ -1,20 +1,6 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2023 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2023 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + library; import 'dart:convert'; diff --git a/packages/ejson_annotation/lib/ejson_annotation.dart b/packages/ejson_annotation/lib/ejson_annotation.dart index 2d3e5f95e..1b4e4feef 100644 --- a/packages/ejson_annotation/lib/ejson_annotation.dart +++ b/packages/ejson_annotation/lib/ejson_annotation.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2023 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2023 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 library; diff --git a/packages/ejson_generator/lib/src/builder.dart b/packages/ejson_generator/lib/src/builder.dart index 4b8514ba7..e664fc7d0 100644 --- a/packages/ejson_generator/lib/src/builder.dart +++ b/packages/ejson_generator/lib/src/builder.dart @@ -1,20 +1,6 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2023 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2023 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + library; import 'package:build/build.dart'; diff --git a/packages/ejson_generator/lib/src/generator.dart b/packages/ejson_generator/lib/src/generator.dart index abc0ebe82..47ee54832 100644 --- a/packages/ejson_generator/lib/src/generator.dart +++ b/packages/ejson_generator/lib/src/generator.dart @@ -1,20 +1,6 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2023 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2023 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + library; import 'dart:async'; diff --git a/packages/ejson_generator/test/ctor_test.dart b/packages/ejson_generator/test/ctor_test.dart index 26cb2499b..d05f96882 100644 --- a/packages/ejson_generator/test/ctor_test.dart +++ b/packages/ejson_generator/test/ctor_test.dart @@ -1,20 +1,6 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2023 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2023 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + library; import 'package:ejson/ejson.dart'; diff --git a/packages/realm/bin/realm.dart b/packages/realm/bin/realm.dart index 689c19fc8..80569db28 100644 --- a/packages/realm/bin/realm.dart +++ b/packages/realm/bin/realm.dart @@ -1,20 +1,6 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + import 'package:realm_dart/src/cli/main.dart' as x; void main(List arguments) => x.main(arguments); diff --git a/packages/realm/example/lib/main.dart b/packages/realm/example/lib/main.dart index e07e13719..2a0666cb3 100644 --- a/packages/realm/example/lib/main.dart +++ b/packages/realm/example/lib/main.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 // ignore_for_file: avoid_print diff --git a/packages/realm_common/lib/realm_common.dart b/packages/realm_common/lib/realm_common.dart index 3cca805d8..06fbd3ff9 100644 --- a/packages/realm_common/lib/realm_common.dart +++ b/packages/realm_common/lib/realm_common.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 export 'src/realm_common_base.dart'; export 'src/realm_types.dart'; diff --git a/packages/realm_common/lib/src/realm_common_base.dart b/packages/realm_common/lib/src/realm_common_base.dart index e9c7b01b7..caea8a336 100644 --- a/packages/realm_common/lib/src/realm_common_base.dart +++ b/packages/realm_common/lib/src/realm_common_base.dart @@ -1,20 +1,5 @@ -// ////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'realm_types.dart'; diff --git a/packages/realm_common/lib/src/realm_types.dart b/packages/realm_common/lib/src/realm_types.dart index 68028bdae..36b254b7a 100644 --- a/packages/realm_common/lib/src/realm_types.dart +++ b/packages/realm_common/lib/src/realm_types.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:math'; import 'dart:typed_data'; diff --git a/packages/realm_dart/bin/realm_dart.dart b/packages/realm_dart/bin/realm_dart.dart index 689c19fc8..80569db28 100644 --- a/packages/realm_dart/bin/realm_dart.dart +++ b/packages/realm_dart/bin/realm_dart.dart @@ -1,20 +1,6 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + import 'package:realm_dart/src/cli/main.dart' as x; void main(List arguments) => x.main(arguments); diff --git a/packages/realm_dart/lib/realm.dart b/packages/realm_dart/lib/realm.dart index 3e92e27de..70bd5dc37 100644 --- a/packages/realm_dart/lib/realm.dart +++ b/packages/realm_dart/lib/realm.dart @@ -1,22 +1,6 @@ -// ////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 //dart.library.cli is available only on dart desktop export 'src/realm_flutter.dart' if (dart.library.cli) 'src/realm_dart.dart'; export 'package:ejson/ejson.dart'; - diff --git a/packages/realm_dart/lib/src/app.dart b/packages/realm_dart/lib/src/app.dart index bf0c5f62c..76757ac59 100644 --- a/packages/realm_dart/lib/src/app.dart +++ b/packages/realm_dart/lib/src/app.dart @@ -1,20 +1,6 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2022 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2022 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + import 'dart:convert'; import 'dart:ffi'; import 'dart:io'; diff --git a/packages/realm_dart/lib/src/cli/archive/archive_command.dart b/packages/realm_dart/lib/src/cli/archive/archive_command.dart index 696205fa7..715b12d02 100644 --- a/packages/realm_dart/lib/src/cli/archive/archive_command.dart +++ b/packages/realm_dart/lib/src/cli/archive/archive_command.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:async'; import 'dart:io'; diff --git a/packages/realm_dart/lib/src/cli/archive/options.dart b/packages/realm_dart/lib/src/cli/archive/options.dart index e45f94159..1fb7e6f75 100644 --- a/packages/realm_dart/lib/src/cli/archive/options.dart +++ b/packages/realm_dart/lib/src/cli/archive/options.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'package:build_cli_annotations/build_cli_annotations.dart'; diff --git a/packages/realm_dart/lib/src/cli/atlas_apps/baas_client.dart b/packages/realm_dart/lib/src/cli/atlas_apps/baas_client.dart index 1ead433c0..1ab83f00f 100644 --- a/packages/realm_dart/lib/src/cli/atlas_apps/baas_client.dart +++ b/packages/realm_dart/lib/src/cli/atlas_apps/baas_client.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2022 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2022 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'package:collection/collection.dart'; import 'package:http/http.dart' as http; diff --git a/packages/realm_dart/lib/src/cli/atlas_apps/deleteapps_command.dart b/packages/realm_dart/lib/src/cli/atlas_apps/deleteapps_command.dart index 64a6802a4..9f7ad8974 100644 --- a/packages/realm_dart/lib/src/cli/atlas_apps/deleteapps_command.dart +++ b/packages/realm_dart/lib/src/cli/atlas_apps/deleteapps_command.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2022 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2022 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:async'; import 'dart:io'; diff --git a/packages/realm_dart/lib/src/cli/atlas_apps/deployapps_command.dart b/packages/realm_dart/lib/src/cli/atlas_apps/deployapps_command.dart index 8e3b72414..8948c3945 100644 --- a/packages/realm_dart/lib/src/cli/atlas_apps/deployapps_command.dart +++ b/packages/realm_dart/lib/src/cli/atlas_apps/deployapps_command.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2022 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2022 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:async'; import 'dart:io'; diff --git a/packages/realm_dart/lib/src/cli/atlas_apps/options.dart b/packages/realm_dart/lib/src/cli/atlas_apps/options.dart index b98658b83..74019898c 100644 --- a/packages/realm_dart/lib/src/cli/atlas_apps/options.dart +++ b/packages/realm_dart/lib/src/cli/atlas_apps/options.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2022 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2022 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'package:build_cli_annotations/build_cli_annotations.dart'; diff --git a/packages/realm_dart/lib/src/cli/common/archive.dart b/packages/realm_dart/lib/src/cli/common/archive.dart index 0fb412bd4..23ab1dcbb 100644 --- a/packages/realm_dart/lib/src/cli/common/archive.dart +++ b/packages/realm_dart/lib/src/cli/common/archive.dart @@ -1,20 +1,6 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + /// import 'dart:io'; import 'package:tar/tar.dart'; diff --git a/packages/realm_dart/lib/src/cli/common/target_os_type.dart b/packages/realm_dart/lib/src/cli/common/target_os_type.dart index 8defefbe3..f87d958b6 100644 --- a/packages/realm_dart/lib/src/cli/common/target_os_type.dart +++ b/packages/realm_dart/lib/src/cli/common/target_os_type.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'utils.dart'; diff --git a/packages/realm_dart/lib/src/cli/common/utils.dart b/packages/realm_dart/lib/src/cli/common/utils.dart index 20e8ecc82..c7d5c0851 100644 --- a/packages/realm_dart/lib/src/cli/common/utils.dart +++ b/packages/realm_dart/lib/src/cli/common/utils.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:async'; import 'dart:io'; diff --git a/packages/realm_dart/lib/src/cli/extract/extract_command.dart b/packages/realm_dart/lib/src/cli/extract/extract_command.dart index 2b8f2816d..a7dee75e5 100644 --- a/packages/realm_dart/lib/src/cli/extract/extract_command.dart +++ b/packages/realm_dart/lib/src/cli/extract/extract_command.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:async'; import 'dart:io'; diff --git a/packages/realm_dart/lib/src/cli/extract/options.dart b/packages/realm_dart/lib/src/cli/extract/options.dart index b98bd2827..bb529f8b2 100644 --- a/packages/realm_dart/lib/src/cli/extract/options.dart +++ b/packages/realm_dart/lib/src/cli/extract/options.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'package:build_cli_annotations/build_cli_annotations.dart'; diff --git a/packages/realm_dart/lib/src/cli/generate/generate_command.dart b/packages/realm_dart/lib/src/cli/generate/generate_command.dart index 0ec86fe6d..9cdb91268 100644 --- a/packages/realm_dart/lib/src/cli/generate/generate_command.dart +++ b/packages/realm_dart/lib/src/cli/generate/generate_command.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:async'; import 'dart:io'; diff --git a/packages/realm_dart/lib/src/cli/install/install_command.dart b/packages/realm_dart/lib/src/cli/install/install_command.dart index be6d247fe..8c92a756b 100644 --- a/packages/realm_dart/lib/src/cli/install/install_command.dart +++ b/packages/realm_dart/lib/src/cli/install/install_command.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:async'; import 'dart:io'; diff --git a/packages/realm_dart/lib/src/cli/install/options.dart b/packages/realm_dart/lib/src/cli/install/options.dart index 8bf98f3f2..f9c1440b6 100644 --- a/packages/realm_dart/lib/src/cli/install/options.dart +++ b/packages/realm_dart/lib/src/cli/install/options.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'package:build_cli_annotations/build_cli_annotations.dart'; import '../common/target_os_type.dart'; diff --git a/packages/realm_dart/lib/src/cli/main.dart b/packages/realm_dart/lib/src/cli/main.dart index 9a5ac019c..002ff3a19 100644 --- a/packages/realm_dart/lib/src/cli/main.dart +++ b/packages/realm_dart/lib/src/cli/main.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:io'; diff --git a/packages/realm_dart/lib/src/cli/metrics/flutter_info.dart b/packages/realm_dart/lib/src/cli/metrics/flutter_info.dart index ef26e18a7..47c6b58b3 100644 --- a/packages/realm_dart/lib/src/cli/metrics/flutter_info.dart +++ b/packages/realm_dart/lib/src/cli/metrics/flutter_info.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'package:json_annotation/json_annotation.dart'; import 'package:pub_semver/pub_semver.dart'; diff --git a/packages/realm_dart/lib/src/cli/metrics/metrics.dart b/packages/realm_dart/lib/src/cli/metrics/metrics.dart index 5b3137a5d..a5a0465d2 100644 --- a/packages/realm_dart/lib/src/cli/metrics/metrics.dart +++ b/packages/realm_dart/lib/src/cli/metrics/metrics.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:convert'; import 'dart:io'; diff --git a/packages/realm_dart/lib/src/cli/metrics/metrics_command.dart b/packages/realm_dart/lib/src/cli/metrics/metrics_command.dart index b0d551df8..5f9b342b7 100644 --- a/packages/realm_dart/lib/src/cli/metrics/metrics_command.dart +++ b/packages/realm_dart/lib/src/cli/metrics/metrics_command.dart @@ -1,20 +1,6 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + import 'dart:async'; import 'dart:convert'; import 'dart:io'; diff --git a/packages/realm_dart/lib/src/cli/metrics/options.dart b/packages/realm_dart/lib/src/cli/metrics/options.dart index 8cb528db6..99a9a0577 100644 --- a/packages/realm_dart/lib/src/cli/metrics/options.dart +++ b/packages/realm_dart/lib/src/cli/metrics/options.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'package:build_cli_annotations/build_cli_annotations.dart'; import 'package:path/path.dart' as path; diff --git a/packages/realm_dart/lib/src/collections.dart b/packages/realm_dart/lib/src/collections.dart index 73a29645a..d41d450a0 100644 --- a/packages/realm_dart/lib/src/collections.dart +++ b/packages/realm_dart/lib/src/collections.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2022 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2022 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:ffi'; import 'native/realm_core.dart'; diff --git a/packages/realm_dart/lib/src/configuration.dart b/packages/realm_dart/lib/src/configuration.dart index 2abcdd2aa..1274c55a7 100644 --- a/packages/realm_dart/lib/src/configuration.dart +++ b/packages/realm_dart/lib/src/configuration.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:async'; import 'dart:ffi'; diff --git a/packages/realm_dart/lib/src/credentials.dart b/packages/realm_dart/lib/src/credentials.dart index ab6291c72..9519fee41 100644 --- a/packages/realm_dart/lib/src/credentials.dart +++ b/packages/realm_dart/lib/src/credentials.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2022 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2022 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:convert'; import 'dart:ffi'; diff --git a/packages/realm_dart/lib/src/list.dart b/packages/realm_dart/lib/src/list.dart index aec2d84fa..de5257ae4 100644 --- a/packages/realm_dart/lib/src/list.dart +++ b/packages/realm_dart/lib/src/list.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:core'; import 'dart:async'; @@ -221,8 +206,7 @@ class UnmanagedRealmList extends collection.DelegatingList UnmanagedRealmList([Iterable? items]) : this._(List.from(items ?? [])); - UnmanagedRealmList._(super.items) - : _base = items; + UnmanagedRealmList._(super.items) : _base = items; @override RealmObjectMetadata? get _metadata => throw RealmException("Unmanaged lists don't have metadata associated with them."); diff --git a/packages/realm_dart/lib/src/map.dart b/packages/realm_dart/lib/src/map.dart index 2e74bbc78..c7b9f7208 100644 --- a/packages/realm_dart/lib/src/map.dart +++ b/packages/realm_dart/lib/src/map.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2023 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2023 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:async'; import 'dart:collection'; @@ -53,8 +38,7 @@ class UnmanagedRealmMap extends collection.DelegatingMap? items]) : this._(Map.from(items ?? {})); - UnmanagedRealmMap._(super.items) - : _base = items; + UnmanagedRealmMap._(super.items) : _base = items; @override bool get isValid => true; diff --git a/packages/realm_dart/lib/src/migration.dart b/packages/realm_dart/lib/src/migration.dart index e5e84aa12..7c02226a1 100644 --- a/packages/realm_dart/lib/src/migration.dart +++ b/packages/realm_dart/lib/src/migration.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2022 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2022 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'realm_class.dart'; import 'native/realm_core.dart'; diff --git a/packages/realm_dart/lib/src/native/decimal128.dart b/packages/realm_dart/lib/src/native/decimal128.dart index 834550100..9d0039bbf 100644 --- a/packages/realm_dart/lib/src/native/decimal128.dart +++ b/packages/realm_dart/lib/src/native/decimal128.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2023 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2023 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 part of 'realm_core.dart'; diff --git a/packages/realm_dart/lib/src/native/realm_core.dart b/packages/realm_dart/lib/src/native/realm_core.dart index 21e644584..513e1316f 100644 --- a/packages/realm_dart/lib/src/native/realm_core.dart +++ b/packages/realm_dart/lib/src/native/realm_core.dart @@ -1,20 +1,6 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + // ignore_for_file: non_constant_identifier_names import 'dart:async'; diff --git a/packages/realm_dart/lib/src/realm_class.dart b/packages/realm_dart/lib/src/realm_class.dart index 45366c3a6..981b5c881 100644 --- a/packages/realm_dart/lib/src/realm_class.dart +++ b/packages/realm_dart/lib/src/realm_class.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:async'; import 'dart:ffi'; diff --git a/packages/realm_dart/lib/src/realm_dart.dart b/packages/realm_dart/lib/src/realm_dart.dart index 03e96830a..9de3c2278 100644 --- a/packages/realm_dart/lib/src/realm_dart.dart +++ b/packages/realm_dart/lib/src/realm_dart.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 export 'realm_class.dart' hide RealmInternal; diff --git a/packages/realm_dart/lib/src/realm_flutter.dart b/packages/realm_dart/lib/src/realm_flutter.dart index 821621def..cb7b7e9d6 100644 --- a/packages/realm_dart/lib/src/realm_flutter.dart +++ b/packages/realm_dart/lib/src/realm_flutter.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 export 'realm_class.dart' hide RealmInternal; diff --git a/packages/realm_dart/lib/src/realm_object.dart b/packages/realm_dart/lib/src/realm_object.dart index 828ce75b5..0ee26c800 100644 --- a/packages/realm_dart/lib/src/realm_object.dart +++ b/packages/realm_dart/lib/src/realm_object.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:async'; import 'dart:ffi'; diff --git a/packages/realm_dart/lib/src/realm_property.dart b/packages/realm_dart/lib/src/realm_property.dart index eaea2e7fb..27279501b 100644 --- a/packages/realm_dart/lib/src/realm_property.dart +++ b/packages/realm_dart/lib/src/realm_property.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'realm_class.dart'; diff --git a/packages/realm_dart/lib/src/results.dart b/packages/realm_dart/lib/src/results.dart index d754de2f3..df92d8ef9 100644 --- a/packages/realm_dart/lib/src/results.dart +++ b/packages/realm_dart/lib/src/results.dart @@ -1,20 +1,6 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + import 'dart:async'; import 'dart:ffi'; diff --git a/packages/realm_dart/lib/src/scheduler.dart b/packages/realm_dart/lib/src/scheduler.dart index 6918598c9..a7d282a45 100644 --- a/packages/realm_dart/lib/src/scheduler.dart +++ b/packages/realm_dart/lib/src/scheduler.dart @@ -1,19 +1,6 @@ -// -// Copyright 2022 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2022 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + import 'dart:ffi'; import 'dart:isolate'; import 'native/realm_core.dart'; diff --git a/packages/realm_dart/lib/src/session.dart b/packages/realm_dart/lib/src/session.dart index 0664c1183..e8da07a88 100644 --- a/packages/realm_dart/lib/src/session.dart +++ b/packages/realm_dart/lib/src/session.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2022 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2022 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:async'; import 'dart:ffi'; diff --git a/packages/realm_dart/lib/src/set.dart b/packages/realm_dart/lib/src/set.dart index b1e9c0826..bcfe9d3f3 100644 --- a/packages/realm_dart/lib/src/set.dart +++ b/packages/realm_dart/lib/src/set.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2023 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2023 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:core'; import 'dart:async'; diff --git a/packages/realm_dart/lib/src/subscription.dart b/packages/realm_dart/lib/src/subscription.dart index 2f095c32e..48dd9f0ec 100644 --- a/packages/realm_dart/lib/src/subscription.dart +++ b/packages/realm_dart/lib/src/subscription.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2022 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2022 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:core'; import 'dart:collection'; diff --git a/packages/realm_dart/lib/src/user.dart b/packages/realm_dart/lib/src/user.dart index c622410b6..05e1c0bca 100644 --- a/packages/realm_dart/lib/src/user.dart +++ b/packages/realm_dart/lib/src/user.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2022 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2022 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:async'; import 'dart:convert'; diff --git a/packages/realm_dart/test/app_test.dart b/packages/realm_dart/test/app_test.dart index 222d7bf3a..1f29a6039 100644 --- a/packages/realm_dart/test/app_test.dart +++ b/packages/realm_dart/test/app_test.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2022 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2022 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:convert'; import 'dart:io'; diff --git a/packages/realm_dart/test/asymmetric_test.dart b/packages/realm_dart/test/asymmetric_test.dart index 21fd85f04..8bd4d5841 100644 --- a/packages/realm_dart/test/asymmetric_test.dart +++ b/packages/realm_dart/test/asymmetric_test.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2023 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2023 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'package:test/expect.dart' hide throws; diff --git a/packages/realm_dart/test/backlinks_test.dart b/packages/realm_dart/test/backlinks_test.dart index 2cfad0a50..b98ef7e6c 100644 --- a/packages/realm_dart/test/backlinks_test.dart +++ b/packages/realm_dart/test/backlinks_test.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2022 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2022 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'package:ejson/ejson.dart'; import 'package:ejson_annotation/ejson_annotation.dart'; diff --git a/packages/realm_dart/test/client_reset_test.dart b/packages/realm_dart/test/client_reset_test.dart index 6dba46375..319cb0b25 100644 --- a/packages/realm_dart/test/client_reset_test.dart +++ b/packages/realm_dart/test/client_reset_test.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2022 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2022 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:async'; import 'dart:io'; diff --git a/packages/realm_dart/test/configuration_test.dart b/packages/realm_dart/test/configuration_test.dart index 92a26caee..141eeaaeb 100644 --- a/packages/realm_dart/test/configuration_test.dart +++ b/packages/realm_dart/test/configuration_test.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:io'; import 'dart:math'; diff --git a/packages/realm_dart/test/credentials_test.dart b/packages/realm_dart/test/credentials_test.dart index a2b31e3ec..4a32554fd 100644 --- a/packages/realm_dart/test/credentials_test.dart +++ b/packages/realm_dart/test/credentials_test.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2022 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2022 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'package:test/test.dart' hide test, throws; import 'package:realm_dart/realm.dart'; diff --git a/packages/realm_dart/test/decimal128_test.dart b/packages/realm_dart/test/decimal128_test.dart index 477fdf9db..ef6d76111 100644 --- a/packages/realm_dart/test/decimal128_test.dart +++ b/packages/realm_dart/test/decimal128_test.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2023 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2023 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:math'; diff --git a/packages/realm_dart/test/dynamic_realm_test.dart b/packages/realm_dart/test/dynamic_realm_test.dart index 119e7a199..9086fcbd6 100644 --- a/packages/realm_dart/test/dynamic_realm_test.dart +++ b/packages/realm_dart/test/dynamic_realm_test.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2022 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2022 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 // ignore_for_file: avoid_relative_lib_imports diff --git a/packages/realm_dart/test/embedded_test.dart b/packages/realm_dart/test/embedded_test.dart index 67ada317d..53074840d 100644 --- a/packages/realm_dart/test/embedded_test.dart +++ b/packages/realm_dart/test/embedded_test.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2022 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2022 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'package:test/test.dart' hide test, throws; diff --git a/packages/realm_dart/test/geospatial_test.dart b/packages/realm_dart/test/geospatial_test.dart index af1306bf6..af1ead974 100644 --- a/packages/realm_dart/test/geospatial_test.dart +++ b/packages/realm_dart/test/geospatial_test.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2023 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2023 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:async'; import 'dart:math'; diff --git a/packages/realm_dart/test/indexed_test.dart b/packages/realm_dart/test/indexed_test.dart index 1d77ccf2a..0feeec061 100644 --- a/packages/realm_dart/test/indexed_test.dart +++ b/packages/realm_dart/test/indexed_test.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2022 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2022 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'package:ejson_annotation/ejson_annotation.dart'; import 'package:ejson/ejson.dart'; @@ -22,7 +7,6 @@ import 'package:ejson/ejson.dart'; import 'dart:math'; import 'dart:typed_data'; - import 'package:test/test.dart' hide test, throws; import 'test.dart'; diff --git a/packages/realm_dart/test/list_test.dart b/packages/realm_dart/test/list_test.dart index f074dc3b3..e6634e2c2 100644 --- a/packages/realm_dart/test/list_test.dart +++ b/packages/realm_dart/test/list_test.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 // ignore_for_file: unused_local_variable diff --git a/packages/realm_dart/test/manual_test.dart b/packages/realm_dart/test/manual_test.dart index d528a59d3..5f588d1ab 100644 --- a/packages/realm_dart/test/manual_test.dart +++ b/packages/realm_dart/test/manual_test.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2022 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2022 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 @TestOn('browser') // This file only contain manual tests diff --git a/packages/realm_dart/test/migration_test.dart b/packages/realm_dart/test/migration_test.dart index 28157dd28..e5562dd27 100644 --- a/packages/realm_dart/test/migration_test.dart +++ b/packages/realm_dart/test/migration_test.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2022 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2022 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 // ignore_for_file: unused_local_variable diff --git a/packages/realm_dart/test/realm_logger_test.dart b/packages/realm_dart/test/realm_logger_test.dart index b3d66fe4d..dfa1afc3d 100644 --- a/packages/realm_dart/test/realm_logger_test.dart +++ b/packages/realm_dart/test/realm_logger_test.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2023 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2023 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 // ignore_for_file: unused_local_variable, avoid_relative_lib_imports diff --git a/packages/realm_dart/test/realm_map_test.dart b/packages/realm_dart/test/realm_map_test.dart index 06d42513d..9debff4c2 100644 --- a/packages/realm_dart/test/realm_map_test.dart +++ b/packages/realm_dart/test/realm_map_test.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2023 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2023 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:async'; import 'dart:io'; diff --git a/packages/realm_dart/test/realm_object_test.dart b/packages/realm_dart/test/realm_object_test.dart index 7198c76b4..3df45aa9d 100644 --- a/packages/realm_dart/test/realm_object_test.dart +++ b/packages/realm_dart/test/realm_object_test.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 // ignore_for_file: unused_local_variable, avoid_relative_lib_imports diff --git a/packages/realm_dart/test/realm_set_test.dart b/packages/realm_dart/test/realm_set_test.dart index c3c7f9039..44bf8b4d5 100644 --- a/packages/realm_dart/test/realm_set_test.dart +++ b/packages/realm_dart/test/realm_set_test.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2023 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2023 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:typed_data'; diff --git a/packages/realm_dart/test/realm_test.dart b/packages/realm_dart/test/realm_test.dart index 1423664c8..188b59696 100644 --- a/packages/realm_dart/test/realm_test.dart +++ b/packages/realm_dart/test/realm_test.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:async'; import 'dart:convert'; diff --git a/packages/realm_dart/test/realm_value_test.dart b/packages/realm_dart/test/realm_value_test.dart index 0aa3eb60c..9179a0334 100644 --- a/packages/realm_dart/test/realm_value_test.dart +++ b/packages/realm_dart/test/realm_value_test.dart @@ -1,25 +1,9 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2022 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2022 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'package:ejson_annotation/ejson_annotation.dart'; import 'package:ejson/ejson.dart'; - import 'dart:typed_data'; import 'package:test/test.dart' hide test, throws; diff --git a/packages/realm_dart/test/results_test.dart b/packages/realm_dart/test/results_test.dart index 8c0cd0873..ab69c67c5 100644 --- a/packages/realm_dart/test/results_test.dart +++ b/packages/realm_dart/test/results_test.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 // ignore_for_file: unused_local_variable diff --git a/packages/realm_dart/test/session_test.dart b/packages/realm_dart/test/session_test.dart index 20b8d7f2c..3a585490d 100644 --- a/packages/realm_dart/test/session_test.dart +++ b/packages/realm_dart/test/session_test.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2022 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2022 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:async'; import 'package:test/test.dart' hide test, throws; diff --git a/packages/realm_dart/test/subscription_test.dart b/packages/realm_dart/test/subscription_test.dart index 7262bdb80..9cd90d311 100644 --- a/packages/realm_dart/test/subscription_test.dart +++ b/packages/realm_dart/test/subscription_test.dart @@ -1,20 +1,6 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2022 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2022 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + import 'dart:async'; import 'dart:io'; import 'dart:math'; diff --git a/packages/realm_dart/test/test.dart b/packages/realm_dart/test/test.dart index 35c7db0fb..25176e9e1 100644 --- a/packages/realm_dart/test/test.dart +++ b/packages/realm_dart/test/test.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'package:ejson_annotation/ejson_annotation.dart'; import 'package:ejson/ejson.dart'; diff --git a/packages/realm_dart/test/user_test.dart b/packages/realm_dart/test/user_test.dart index d12d16c48..c4c9ff1d7 100644 --- a/packages/realm_dart/test/user_test.dart +++ b/packages/realm_dart/test/user_test.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2022 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2022 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:async'; import 'dart:isolate'; diff --git a/packages/realm_generator/lib/realm_generator.dart b/packages/realm_generator/lib/realm_generator.dart index 0f4fd9e63..4dff21063 100644 --- a/packages/realm_generator/lib/realm_generator.dart +++ b/packages/realm_generator/lib/realm_generator.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 /// Usage /// diff --git a/packages/realm_generator/lib/src/annotation_value.dart b/packages/realm_generator/lib/src/annotation_value.dart index 4ddf08415..88fade01d 100644 --- a/packages/realm_generator/lib/src/annotation_value.dart +++ b/packages/realm_generator/lib/src/annotation_value.dart @@ -1,20 +1,6 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + import 'package:analyzer/dart/ast/ast.dart'; import 'package:analyzer/dart/constant/value.dart'; diff --git a/packages/realm_generator/lib/src/class_element_ex.dart b/packages/realm_generator/lib/src/class_element_ex.dart index d1e098ba6..00c8fd0e4 100644 --- a/packages/realm_generator/lib/src/class_element_ex.dart +++ b/packages/realm_generator/lib/src/class_element_ex.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'package:analyzer/dart/ast/ast.dart'; import 'package:analyzer/dart/element/element.dart'; diff --git a/packages/realm_generator/lib/src/dart_type_ex.dart b/packages/realm_generator/lib/src/dart_type_ex.dart index 744149334..2cdf2a179 100644 --- a/packages/realm_generator/lib/src/dart_type_ex.dart +++ b/packages/realm_generator/lib/src/dart_type_ex.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:typed_data'; diff --git a/packages/realm_generator/lib/src/element.dart b/packages/realm_generator/lib/src/element.dart index bc40feb0f..6ffd79f10 100644 --- a/packages/realm_generator/lib/src/element.dart +++ b/packages/realm_generator/lib/src/element.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:math'; diff --git a/packages/realm_generator/lib/src/error.dart b/packages/realm_generator/lib/src/error.dart index 37f19e41f..f5c399d20 100644 --- a/packages/realm_generator/lib/src/error.dart +++ b/packages/realm_generator/lib/src/error.dart @@ -1,20 +1,6 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + import 'package:analyzer/dart/element/element.dart'; import 'package:source_gen/source_gen.dart'; import 'package:source_span/source_span.dart'; diff --git a/packages/realm_generator/lib/src/expanded_context_span.dart b/packages/realm_generator/lib/src/expanded_context_span.dart index 095e60ae2..16e7b9348 100644 --- a/packages/realm_generator/lib/src/expanded_context_span.dart +++ b/packages/realm_generator/lib/src/expanded_context_span.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'package:source_span/source_span.dart'; diff --git a/packages/realm_generator/lib/src/field_element_ex.dart b/packages/realm_generator/lib/src/field_element_ex.dart index 4567c3fe0..f44947e96 100644 --- a/packages/realm_generator/lib/src/field_element_ex.dart +++ b/packages/realm_generator/lib/src/field_element_ex.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'package:analyzer/src/dart/ast/ast.dart'; import 'package:analyzer/dart/element/element.dart'; diff --git a/packages/realm_generator/lib/src/format_spans.dart b/packages/realm_generator/lib/src/format_spans.dart index 4473cfb04..4736b5c91 100644 --- a/packages/realm_generator/lib/src/format_spans.dart +++ b/packages/realm_generator/lib/src/format_spans.dart @@ -1,20 +1,6 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + import 'package:analyzer/dart/element/element.dart'; import 'package:source_span/source_span.dart'; diff --git a/packages/realm_generator/lib/src/measure.dart b/packages/realm_generator/lib/src/measure.dart index 5b3179877..60f3e7337 100644 --- a/packages/realm_generator/lib/src/measure.dart +++ b/packages/realm_generator/lib/src/measure.dart @@ -1,20 +1,6 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + import 'dart:async'; import 'package:build/build.dart'; // for shared logging instance log diff --git a/packages/realm_generator/lib/src/realm_field_info.dart b/packages/realm_generator/lib/src/realm_field_info.dart index 1a5fc0616..68c7202a6 100644 --- a/packages/realm_generator/lib/src/realm_field_info.dart +++ b/packages/realm_generator/lib/src/realm_field_info.dart @@ -1,20 +1,6 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:realm_common/realm_common.dart'; diff --git a/packages/realm_generator/lib/src/realm_model_info.dart b/packages/realm_generator/lib/src/realm_model_info.dart index b2d310204..d5f21eead 100644 --- a/packages/realm_generator/lib/src/realm_model_info.dart +++ b/packages/realm_generator/lib/src/realm_model_info.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'package:realm_common/realm_common.dart'; diff --git a/packages/realm_generator/lib/src/realm_object_generator.dart b/packages/realm_generator/lib/src/realm_object_generator.dart index 8c7a33b17..67b58b77e 100644 --- a/packages/realm_generator/lib/src/realm_object_generator.dart +++ b/packages/realm_generator/lib/src/realm_object_generator.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 library realm_generator; diff --git a/packages/realm_generator/lib/src/session.dart b/packages/realm_generator/lib/src/session.dart index 438b42b0a..0e09cca18 100644 --- a/packages/realm_generator/lib/src/session.dart +++ b/packages/realm_generator/lib/src/session.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'dart:async'; diff --git a/packages/realm_generator/lib/src/type_checkers.dart b/packages/realm_generator/lib/src/type_checkers.dart index 96890c087..600513b22 100644 --- a/packages/realm_generator/lib/src/type_checkers.dart +++ b/packages/realm_generator/lib/src/type_checkers.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 import 'package:realm_common/realm_common.dart'; import 'package:source_gen/source_gen.dart'; diff --git a/packages/realm_generator/lib/src/utils.dart b/packages/realm_generator/lib/src/utils.dart index dd11b776a..14bb0fd5b 100644 --- a/packages/realm_generator/lib/src/utils.dart +++ b/packages/realm_generator/lib/src/utils.dart @@ -1,20 +1,5 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// +// Copyright 2021 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 String anOrA(String text) => 'aeiouy'.contains(text[0]) ? 'an' : 'a'; From f44360e14349aedc9f78a7e0d907c1adee0a3335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 28 Feb 2024 17:50:45 +0100 Subject: [PATCH 123/153] Remove redundant "library;" --- packages/ejson/lib/ejson.dart | 2 -- packages/ejson/lib/src/configuration.dart | 2 -- packages/ejson/lib/src/decoding.dart | 2 -- packages/ejson/lib/src/encoding.dart | 2 -- packages/ejson/lib/src/types.dart | 2 -- packages/ejson/test/ejson_test.dart | 2 -- packages/ejson_analyzer/lib/ejson_analyzer.dart | 1 - packages/ejson_annotation/lib/ejson_annotation.dart | 2 -- packages/ejson_generator/lib/ejson_generator.dart | 2 -- packages/ejson_generator/lib/src/builder.dart | 2 -- packages/ejson_generator/lib/src/generator.dart | 2 -- packages/ejson_generator/test/ctor_test.dart | 2 -- packages/ejson_lint/lib/ejson_lint.dart | 2 -- 13 files changed, 25 deletions(-) diff --git a/packages/ejson/lib/ejson.dart b/packages/ejson/lib/ejson.dart index baf35f543..9854bb6a8 100644 --- a/packages/ejson/lib/ejson.dart +++ b/packages/ejson/lib/ejson.dart @@ -1,8 +1,6 @@ // Copyright 2023 MongoDB, Inc. // SPDX-License-Identifier: Apache-2.0 -library; - export 'src/configuration.dart'; export 'src/decoding.dart'; export 'src/encoding.dart'; diff --git a/packages/ejson/lib/src/configuration.dart b/packages/ejson/lib/src/configuration.dart index 55be59891..0eadfd379 100644 --- a/packages/ejson/lib/src/configuration.dart +++ b/packages/ejson/lib/src/configuration.dart @@ -1,8 +1,6 @@ // Copyright 2023 MongoDB, Inc. // SPDX-License-Identifier: Apache-2.0 -library; - import 'package:ejson_annotation/ejson_annotation.dart'; import 'package:type_plus/type_plus.dart'; diff --git a/packages/ejson/lib/src/decoding.dart b/packages/ejson/lib/src/decoding.dart index f58d3a43c..7f61abc93 100644 --- a/packages/ejson/lib/src/decoding.dart +++ b/packages/ejson/lib/src/decoding.dart @@ -1,8 +1,6 @@ // Copyright 2023 MongoDB, Inc. // SPDX-License-Identifier: Apache-2.0 -library; - import 'dart:typed_data'; import 'dart:convert'; diff --git a/packages/ejson/lib/src/encoding.dart b/packages/ejson/lib/src/encoding.dart index d4e54683c..5888efca2 100644 --- a/packages/ejson/lib/src/encoding.dart +++ b/packages/ejson/lib/src/encoding.dart @@ -1,8 +1,6 @@ // Copyright 2023 MongoDB, Inc. // SPDX-License-Identifier: Apache-2.0 -library; - import 'dart:convert'; import 'dart:typed_data'; diff --git a/packages/ejson/lib/src/types.dart b/packages/ejson/lib/src/types.dart index c33d1722c..981bb8ac1 100644 --- a/packages/ejson/lib/src/types.dart +++ b/packages/ejson/lib/src/types.dart @@ -1,8 +1,6 @@ // Copyright 2023 MongoDB, Inc. // SPDX-License-Identifier: Apache-2.0 -library; - enum EJsonType { array, binary, diff --git a/packages/ejson/test/ejson_test.dart b/packages/ejson/test/ejson_test.dart index 2f516949c..dcfdbc288 100644 --- a/packages/ejson/test/ejson_test.dart +++ b/packages/ejson/test/ejson_test.dart @@ -1,8 +1,6 @@ // Copyright 2023 MongoDB, Inc. // SPDX-License-Identifier: Apache-2.0 -library; - import 'dart:convert'; import 'package:ejson/ejson.dart'; diff --git a/packages/ejson_analyzer/lib/ejson_analyzer.dart b/packages/ejson_analyzer/lib/ejson_analyzer.dart index deae32011..d60acfce4 100644 --- a/packages/ejson_analyzer/lib/ejson_analyzer.dart +++ b/packages/ejson_analyzer/lib/ejson_analyzer.dart @@ -1,7 +1,6 @@ /// Support for doing something awesome. /// /// More dartdocs go here. -library; export 'src/ejson_analyzer_base.dart'; diff --git a/packages/ejson_annotation/lib/ejson_annotation.dart b/packages/ejson_annotation/lib/ejson_annotation.dart index 1b4e4feef..5da9bcd40 100644 --- a/packages/ejson_annotation/lib/ejson_annotation.dart +++ b/packages/ejson_annotation/lib/ejson_annotation.dart @@ -1,8 +1,6 @@ // Copyright 2023 MongoDB, Inc. // SPDX-License-Identifier: Apache-2.0 -library; - /// Annotation to mark a class for extended json (ejson) serialization const ejson = EJson(); diff --git a/packages/ejson_generator/lib/ejson_generator.dart b/packages/ejson_generator/lib/ejson_generator.dart index afe6e17a9..8a9e071e9 100644 --- a/packages/ejson_generator/lib/ejson_generator.dart +++ b/packages/ejson_generator/lib/ejson_generator.dart @@ -1,3 +1 @@ -library; - export 'src/builder.dart'; diff --git a/packages/ejson_generator/lib/src/builder.dart b/packages/ejson_generator/lib/src/builder.dart index e664fc7d0..56a5cda2e 100644 --- a/packages/ejson_generator/lib/src/builder.dart +++ b/packages/ejson_generator/lib/src/builder.dart @@ -1,8 +1,6 @@ // Copyright 2023 MongoDB, Inc. // SPDX-License-Identifier: Apache-2.0 -library; - import 'package:build/build.dart'; import 'package:source_gen/source_gen.dart'; diff --git a/packages/ejson_generator/lib/src/generator.dart b/packages/ejson_generator/lib/src/generator.dart index 47ee54832..b768130f1 100644 --- a/packages/ejson_generator/lib/src/generator.dart +++ b/packages/ejson_generator/lib/src/generator.dart @@ -1,8 +1,6 @@ // Copyright 2023 MongoDB, Inc. // SPDX-License-Identifier: Apache-2.0 -library; - import 'dart:async'; import 'package:analyzer/dart/element/element.dart'; diff --git a/packages/ejson_generator/test/ctor_test.dart b/packages/ejson_generator/test/ctor_test.dart index d05f96882..3319aec02 100644 --- a/packages/ejson_generator/test/ctor_test.dart +++ b/packages/ejson_generator/test/ctor_test.dart @@ -1,8 +1,6 @@ // Copyright 2023 MongoDB, Inc. // SPDX-License-Identifier: Apache-2.0 -library; - import 'package:ejson/ejson.dart'; import 'package:ejson_annotation/ejson_annotation.dart'; import 'package:meta/meta.dart'; diff --git a/packages/ejson_lint/lib/ejson_lint.dart b/packages/ejson_lint/lib/ejson_lint.dart index b6a4c23a2..0014b7c2a 100644 --- a/packages/ejson_lint/lib/ejson_lint.dart +++ b/packages/ejson_lint/lib/ejson_lint.dart @@ -1,3 +1 @@ -library; - export 'src/ejson_lint_base.dart'; From fbdb4de4a8bb3a80c71fccf48f54e92dd97c78c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 28 Feb 2024 17:52:10 +0100 Subject: [PATCH 124/153] Remove the now unnecesary imports --- packages/ejson/test/ejson_test.dart | 1 - packages/ejson/test/person.dart | 1 - packages/ejson_generator/test/ctor_test.dart | 1 - packages/realm_dart/test/backlinks_test.dart | 2 -- packages/realm_dart/test/geospatial_test.dart | 2 -- packages/realm_dart/test/indexed_test.dart | 2 -- packages/realm_dart/test/migration_test.dart | 2 -- packages/realm_dart/test/realm_map_test.dart | 2 -- packages/realm_dart/test/realm_object_test.dart | 2 -- packages/realm_dart/test/realm_set_test.dart | 2 -- packages/realm_dart/test/realm_value_test.dart | 2 -- packages/realm_dart/test/test.dart | 2 -- 12 files changed, 21 deletions(-) diff --git a/packages/ejson/test/ejson_test.dart b/packages/ejson/test/ejson_test.dart index dcfdbc288..9647be5c2 100644 --- a/packages/ejson/test/ejson_test.dart +++ b/packages/ejson/test/ejson_test.dart @@ -4,7 +4,6 @@ import 'dart:convert'; import 'package:ejson/ejson.dart'; -import 'package:ejson_annotation/ejson_annotation.dart'; import 'package:objectid/objectid.dart'; import 'package:sane_uuid/uuid.dart'; import 'package:test/test.dart'; diff --git a/packages/ejson/test/person.dart b/packages/ejson/test/person.dart index 055c8cf22..3a627278e 100644 --- a/packages/ejson/test/person.dart +++ b/packages/ejson/test/person.dart @@ -1,5 +1,4 @@ import 'package:ejson/ejson.dart'; -import 'package:ejson_annotation/ejson_annotation.dart'; part 'person.g.dart'; diff --git a/packages/ejson_generator/test/ctor_test.dart b/packages/ejson_generator/test/ctor_test.dart index 3319aec02..b4e68427b 100644 --- a/packages/ejson_generator/test/ctor_test.dart +++ b/packages/ejson_generator/test/ctor_test.dart @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 import 'package:ejson/ejson.dart'; -import 'package:ejson_annotation/ejson_annotation.dart'; import 'package:meta/meta.dart'; import 'package:test/test.dart'; diff --git a/packages/realm_dart/test/backlinks_test.dart b/packages/realm_dart/test/backlinks_test.dart index b98ef7e6c..29c9ed8ca 100644 --- a/packages/realm_dart/test/backlinks_test.dart +++ b/packages/realm_dart/test/backlinks_test.dart @@ -1,8 +1,6 @@ // Copyright 2022 MongoDB, Inc. // SPDX-License-Identifier: Apache-2.0 -import 'package:ejson/ejson.dart'; -import 'package:ejson_annotation/ejson_annotation.dart'; import 'package:realm_dart/realm.dart'; import 'package:test/test.dart' hide test, throws; diff --git a/packages/realm_dart/test/geospatial_test.dart b/packages/realm_dart/test/geospatial_test.dart index af1ead974..122a60282 100644 --- a/packages/realm_dart/test/geospatial_test.dart +++ b/packages/realm_dart/test/geospatial_test.dart @@ -4,8 +4,6 @@ import 'dart:async'; import 'dart:math'; -import 'package:ejson/ejson.dart'; -import 'package:ejson_annotation/ejson_annotation.dart'; import 'package:realm_common/realm_common.dart'; import 'package:test/test.dart' hide test, throws; diff --git a/packages/realm_dart/test/indexed_test.dart b/packages/realm_dart/test/indexed_test.dart index 0feeec061..0a7868c58 100644 --- a/packages/realm_dart/test/indexed_test.dart +++ b/packages/realm_dart/test/indexed_test.dart @@ -1,8 +1,6 @@ // Copyright 2022 MongoDB, Inc. // SPDX-License-Identifier: Apache-2.0 -import 'package:ejson_annotation/ejson_annotation.dart'; -import 'package:ejson/ejson.dart'; import 'dart:math'; import 'dart:typed_data'; diff --git a/packages/realm_dart/test/migration_test.dart b/packages/realm_dart/test/migration_test.dart index e5562dd27..1807c2969 100644 --- a/packages/realm_dart/test/migration_test.dart +++ b/packages/realm_dart/test/migration_test.dart @@ -3,8 +3,6 @@ // ignore_for_file: unused_local_variable -import 'package:ejson_annotation/ejson_annotation.dart'; -import 'package:ejson/ejson.dart'; import 'dart:async'; import 'package:test/test.dart' hide test, throws; diff --git a/packages/realm_dart/test/realm_map_test.dart b/packages/realm_dart/test/realm_map_test.dart index 9debff4c2..51d6623cf 100644 --- a/packages/realm_dart/test/realm_map_test.dart +++ b/packages/realm_dart/test/realm_map_test.dart @@ -6,8 +6,6 @@ import 'dart:io'; import 'dart:typed_data'; import 'package:collection/collection.dart'; -import 'package:ejson/ejson.dart'; -import 'package:ejson_annotation/ejson_annotation.dart'; import 'package:meta/meta.dart'; import 'package:test/test.dart' hide test, throws; import 'package:realm_dart/realm.dart'; diff --git a/packages/realm_dart/test/realm_object_test.dart b/packages/realm_dart/test/realm_object_test.dart index 3df45aa9d..0f13e7a44 100644 --- a/packages/realm_dart/test/realm_object_test.dart +++ b/packages/realm_dart/test/realm_object_test.dart @@ -3,8 +3,6 @@ // ignore_for_file: unused_local_variable, avoid_relative_lib_imports -import 'package:ejson_annotation/ejson_annotation.dart'; -import 'package:ejson/ejson.dart'; import 'dart:typed_data'; import 'package:test/test.dart' hide test, throws; diff --git a/packages/realm_dart/test/realm_set_test.dart b/packages/realm_dart/test/realm_set_test.dart index 44bf8b4d5..a13bf0088 100644 --- a/packages/realm_dart/test/realm_set_test.dart +++ b/packages/realm_dart/test/realm_set_test.dart @@ -4,8 +4,6 @@ import 'dart:typed_data'; import 'package:collection/collection.dart'; -import 'package:ejson/ejson.dart'; -import 'package:ejson_annotation/ejson_annotation.dart'; import 'package:realm_dart/realm.dart'; import 'package:test/test.dart' hide test, throws; diff --git a/packages/realm_dart/test/realm_value_test.dart b/packages/realm_dart/test/realm_value_test.dart index 9179a0334..d214a686e 100644 --- a/packages/realm_dart/test/realm_value_test.dart +++ b/packages/realm_dart/test/realm_value_test.dart @@ -1,8 +1,6 @@ // Copyright 2022 MongoDB, Inc. // SPDX-License-Identifier: Apache-2.0 -import 'package:ejson_annotation/ejson_annotation.dart'; -import 'package:ejson/ejson.dart'; import 'dart:typed_data'; diff --git a/packages/realm_dart/test/test.dart b/packages/realm_dart/test/test.dart index 25176e9e1..db4cb613c 100644 --- a/packages/realm_dart/test/test.dart +++ b/packages/realm_dart/test/test.dart @@ -1,8 +1,6 @@ // Copyright 2021 MongoDB, Inc. // SPDX-License-Identifier: Apache-2.0 -import 'package:ejson_annotation/ejson_annotation.dart'; -import 'package:ejson/ejson.dart'; import 'dart:async'; import 'dart:collection'; From d075bac601b3f0b85bb474f1fe31f99fb936bf3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 28 Feb 2024 17:59:56 +0100 Subject: [PATCH 125/153] Remove deprecated exports --- packages/realm_dart/lib/src/realm_class.dart | 30 ++------------------ 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/packages/realm_dart/lib/src/realm_class.dart b/packages/realm_dart/lib/src/realm_class.dart index 981b5c881..2d29b088e 100644 --- a/packages/realm_dart/lib/src/realm_class.dart +++ b/packages/realm_dart/lib/src/realm_class.dart @@ -77,21 +77,7 @@ export "configuration.dart" SchemaObject, ShouldCompactCallback, SyncError, - SyncErrorHandler, - // ignore: deprecated_member_use_from_same_package - SyncClientError, - // ignore: deprecated_member_use_from_same_package - SyncConnectionError, - // ignore: deprecated_member_use_from_same_package - GeneralSyncError, - // ignore: deprecated_member_use_from_same_package - GeneralSyncErrorCode, - // ignore: deprecated_member_use_from_same_package - SyncResolveError, - // ignore: deprecated_member_use_from_same_package - SyncWebSocketError, - // ignore: deprecated_member_use_from_same_package - SyncSessionError; + SyncErrorHandler; export 'credentials.dart' show AuthProviderType, Credentials, EmailPasswordAuthProvider; export 'list.dart' show RealmList, RealmListOfObject, RealmListChanges, ListExtension; export 'set.dart' show RealmSet, RealmSetChanges, RealmSetOfObject; @@ -120,19 +106,7 @@ export 'session.dart' ConnectionState, Session, SessionState, - SyncErrorCode, - // ignore: deprecated_member_use_from_same_package - SyncClientErrorCode, - // ignore: deprecated_member_use_from_same_package - SyncConnectionErrorCode, - // ignore: deprecated_member_use_from_same_package - SyncErrorCategory, - // ignore: deprecated_member_use_from_same_package - SyncResolveErrorCode, - // ignore: deprecated_member_use_from_same_package - SyncWebSocketErrorCode, - // ignore: deprecated_member_use_from_same_package - SyncSessionErrorCode; + SyncErrorCode; export 'subscription.dart' show Subscription, SubscriptionSet, SubscriptionSetState, MutableSubscriptionSet; export 'user.dart' show User, UserState, ApiKeyClient, UserIdentity, ApiKey, FunctionsClient, UserChanges; export 'native/realm_core.dart' show Decimal128; From 07aeec40c0be2972d969d50f143285cf2dab9e9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 28 Feb 2024 18:02:24 +0100 Subject: [PATCH 126/153] Add unsynced to CSpell --- .vscode/settings.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index 4db4b006d..5218a0f21 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -35,6 +35,7 @@ "sublists", "TRUEPREDICATE", "unmanaged", + "unsynced", "upsert", "usercode", "userdata", From b9b22171fc3193d8cde18ed8dd04b477122d29c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Thu, 29 Feb 2024 13:37:25 +0100 Subject: [PATCH 127/153] Don't use ejson_generator for realm objects, but have realm_generator create the codec pair --- packages/realm_dart/build.yaml | 13 ----- .../lib/src/realm_model_info.dart | 56 +++++++++++++++---- 2 files changed, 45 insertions(+), 24 deletions(-) diff --git a/packages/realm_dart/build.yaml b/packages/realm_dart/build.yaml index 49dc3c4d2..626a99d8a 100644 --- a/packages/realm_dart/build.yaml +++ b/packages/realm_dart/build.yaml @@ -13,11 +13,6 @@ targets: include: - test/**.dart - example/**.dart - ejson_generator: - generate_for: - include: - - test/**.dart - - example/**.dart builders: realm_generator: @@ -27,11 +22,3 @@ builders: auto_apply: dependents build_to: source runs_before: ["ejson_generator|ejson_generator"] - ejson_generator: - import: "package:ejson_generator/ejson_generator.dart" - required_inputs: [".realm.dart"] - builder_factories: ["getEJsonGenerator"] - build_extensions: { ".dart": ["ejson.g.part"] } - auto_apply: dependents - build_to: cache - applies_builders: ["source_gen|combining_builder"] diff --git a/packages/realm_generator/lib/src/realm_model_info.dart b/packages/realm_generator/lib/src/realm_model_info.dart index d5f21eead..ffb26e0b4 100644 --- a/packages/realm_generator/lib/src/realm_model_info.dart +++ b/packages/realm_generator/lib/src/realm_model_info.dart @@ -28,17 +28,16 @@ class RealmModelInfo { yield ''; } + final required = allSettable.where((f) => f.isRequired || f.isPrimaryKey); + final notRequired = allSettable.where((f) => !f.isRequired && !f.isPrimaryKey); + final lists = fields.where((f) => f.isDartCoreList).toList(); + final sets = fields.where((f) => f.isDartCoreSet).toList(); + final maps = fields.where((f) => f.isDartCoreMap).toList(); + // Constructor - yield '@ejson'; yield '$name('; { - final required = allSettable.where((f) => f.isRequired || f.isPrimaryKey); yield* required.map((f) => '${f.mappedTypeName} ${f.name},'); - - final notRequired = allSettable.where((f) => !f.isRequired && !f.isPrimaryKey); - final lists = fields.where((f) => f.isDartCoreList).toList(); - final sets = fields.where((f) => f.isDartCoreSet).toList(); - final maps = fields.where((f) => f.isDartCoreMap).toList(); if (notRequired.isNotEmpty || lists.isNotEmpty || sets.isNotEmpty || maps.isNotEmpty) { yield '{'; yield* notRequired.map((f) { @@ -104,12 +103,47 @@ class RealmModelInfo { yield '$name freeze() => RealmObjectBase.freezeObject<$name>(this);'; yield ''; + // Encode + yield 'static EJsonValue _encode$name($name value) {'; + { + yield 'return {'; + { + yield* fields.map((f) { + return "'${f.realmName}': toEJson(value.${f.name}),"; + }); + } + yield '};'; + } + yield '}'; + + // Decode + yield 'static $name _decode$name(EJsonValue ejson) {'; + { + yield 'return switch (ejson) {'; + { + yield '{'; + { + yield* fields.map((f) { + return "'${f.realmName}': EJsonValue ${f.name},"; + }); + } + yield '} => $name('; + { + yield* required.map((f) => 'fromEJson(${f.name}),'); + yield* notRequired.map((f) => '${f.name}: fromEJson(${f.name}),'); + } + yield '),'; + yield '_ => raiseInvalidEJson(ejson),'; + } + yield '};'; + } + yield '}'; + // Schema - yield 'static SchemaObject get schema => _schema ??= _initSchema();'; - yield 'static SchemaObject? _schema;'; - yield 'static SchemaObject _initSchema() {'; + yield 'static final schema = () {'; { yield 'RealmObjectBase.registerFactory($name._);'; + yield 'register(_encode$name, _decode$name);'; yield "return const SchemaObject(ObjectType.${baseType.name}, $name, '$realmName', ["; { yield* fields.map((f) { @@ -131,7 +165,7 @@ class RealmModelInfo { } yield ']);'; } - yield '}'; + yield '}();'; } yield '}'; } From 28566abd492b4484237ffb3349cdbd7b548a0afc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Thu, 29 Feb 2024 13:48:10 +0100 Subject: [PATCH 128/153] Update .expected files --- .../test/good_test_data/all_types.expected | 164 +++++++++++--- .../another_mapto.expected_multi | 28 ++- .../good_test_data/asymmetric_object.expected | 64 +++++- .../test/good_test_data/binary_type.expected | 35 ++- .../embedded_annotations.expected | 67 ++++-- .../good_test_data/embedded_objects.expected | 128 +++++++++-- .../good_test_data/indexable_types.expected | 71 +++++- .../list_initialization.expected | 48 +++- .../test/good_test_data/map.expected | 107 ++++++--- .../test/good_test_data/mapto.expected | 32 ++- .../good_test_data/optional_argument.expected | 27 ++- .../test/good_test_data/pinhole.expected | 27 ++- .../test/good_test_data/primary_key.expected | 213 ++++++++++++++---- .../test/good_test_data/realm_set.expected | 86 ++++++- .../good_test_data/required_argument.expected | 27 ++- ...uired_argument_with_default_value.expected | 27 ++- .../user_defined_getter.expected | 27 ++- 17 files changed, 962 insertions(+), 216 deletions(-) diff --git a/packages/realm_generator/test/good_test_data/all_types.expected b/packages/realm_generator/test/good_test_data/all_types.expected index 09c9ff624..7f977d12a 100644 --- a/packages/realm_generator/test/good_test_data/all_types.expected +++ b/packages/realm_generator/test/good_test_data/all_types.expected @@ -10,7 +10,6 @@ part of 'all_types.dart'; class Foo extends _Foo with RealmEntity, RealmObjectBase, RealmObject { static var _defaultsSet = false; - @ejson Foo({ int x = 0, Bar? bar, @@ -43,22 +42,42 @@ class Foo extends _Foo with RealmEntity, RealmObjectBase, RealmObject { @override Foo freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeFoo(Foo value) { + return { + 'x': toEJson(value.x), + 'bar': toEJson(value.bar), + }; + } + + static Foo _decodeFoo(EJsonValue ejson) { + return switch (ejson) { + { + 'x': EJsonValue x, + 'bar': EJsonValue bar, + } => + Foo( + x: fromEJson(x), + bar: fromEJson(bar), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Foo._); + register(_encodeFoo, _decodeFoo); return const SchemaObject(ObjectType.realmObject, Foo, 'MyFoo', [ - SchemaProperty('x', RealmPropertyType.int, indexType: RealmIndexType.regular), + SchemaProperty('x', RealmPropertyType.int, + indexType: RealmIndexType.regular), SchemaProperty('bar', RealmPropertyType.object, optional: true, linkTarget: 'Bar'), ]); - } + }(); } class Bar extends _Bar with RealmEntity, RealmObjectBase, RealmObject { static var _defaultsSet = false; - @ejson Bar( String name, bool aBool, @@ -96,10 +115,10 @@ class Bar extends _Bar with RealmEntity, RealmObjectBase, RealmObject { RealmObjectBase.set(this, 'any', any); RealmObjectBase.set(this, 'decimal', decimal); RealmObjectBase.set>(this, 'list', RealmList(list)); - RealmObjectBase.set>(this, 'manyAny', RealmList(manyAny)); + RealmObjectBase.set>( + this, 'manyAny', RealmList(manyAny)); RealmObjectBase.set>(this, 'set', RealmSet(set)); - RealmObjectBase.set>( - this, 'map', RealmMap(map)); + RealmObjectBase.set>(this, 'map', RealmMap(map)); } Bar._(); @@ -169,8 +188,7 @@ class Bar extends _Bar with RealmEntity, RealmObjectBase, RealmObject { RealmMap get map => RealmObjectBase.get(this, 'map') as RealmMap; @override - set map(covariant RealmMap value) => - throw RealmUnsupportedSetError(); + set map(covariant RealmMap value) => throw RealmUnsupportedSetError(); @override String? get anOptionalString => @@ -201,8 +219,7 @@ class Bar extends _Bar with RealmEntity, RealmObjectBase, RealmObject { @override RealmResults get foos { if (!isManaged) { - throw RealmError( - 'Using backlinks is only possible for managed objects.'); + throw RealmError('Using backlinks is only possible for managed objects.'); } return RealmObjectBase.get(this, 'foos') as RealmResults; } @@ -218,22 +235,86 @@ class Bar extends _Bar with RealmEntity, RealmObjectBase, RealmObject { @override Bar freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeBar(Bar value) { + return { + 'name': toEJson(value.name), + 'aBool': toEJson(value.aBool), + 'another': toEJson(value.another), + 'data': toEJson(value.data), + 'tidspunkt': toEJson(value.timestamp), + 'aDouble': toEJson(value.aDouble), + 'foo': toEJson(value.foo), + 'objectId': toEJson(value.objectId), + 'uuid': toEJson(value.uuid), + 'list': toEJson(value.list), + 'set': toEJson(value.set), + 'map': toEJson(value.map), + 'anOptionalString': toEJson(value.anOptionalString), + 'any': toEJson(value.any), + 'manyAny': toEJson(value.manyAny), + 'decimal': toEJson(value.decimal), + 'foos': toEJson(value.foos), + }; + } + + static Bar _decodeBar(EJsonValue ejson) { + return switch (ejson) { + { + 'name': EJsonValue name, + 'aBool': EJsonValue aBool, + 'another': EJsonValue another, + 'data': EJsonValue data, + 'tidspunkt': EJsonValue timestamp, + 'aDouble': EJsonValue aDouble, + 'foo': EJsonValue foo, + 'objectId': EJsonValue objectId, + 'uuid': EJsonValue uuid, + 'list': EJsonValue list, + 'set': EJsonValue set, + 'map': EJsonValue map, + 'anOptionalString': EJsonValue anOptionalString, + 'any': EJsonValue any, + 'manyAny': EJsonValue manyAny, + 'decimal': EJsonValue decimal, + 'foos': EJsonValue foos, + } => + Bar( + fromEJson(name), + fromEJson(aBool), + fromEJson(another), + fromEJson(objectId), + fromEJson(uuid), + fromEJson(decimal), + data: fromEJson(data), + timestamp: fromEJson(timestamp), + aDouble: fromEJson(aDouble), + foo: fromEJson(foo), + anOptionalString: fromEJson(anOptionalString), + any: fromEJson(any), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Bar._); + register(_encodeBar, _decodeBar); return const SchemaObject(ObjectType.realmObject, Bar, 'Bar', [ SchemaProperty('name', RealmPropertyType.string, primaryKey: true), - SchemaProperty('aBool', RealmPropertyType.bool, indexType: RealmIndexType.regular), - SchemaProperty('another', RealmPropertyType.bool, indexType: RealmIndexType.regular), + SchemaProperty('aBool', RealmPropertyType.bool, + indexType: RealmIndexType.regular), + SchemaProperty('another', RealmPropertyType.bool, + indexType: RealmIndexType.regular), SchemaProperty('data', RealmPropertyType.binary), SchemaProperty('timestamp', RealmPropertyType.timestamp, mapTo: 'tidspunkt', indexType: RealmIndexType.regular), SchemaProperty('aDouble', RealmPropertyType.double), SchemaProperty('foo', RealmPropertyType.object, optional: true, linkTarget: 'MyFoo'), - SchemaProperty('objectId', RealmPropertyType.objectid, indexType: RealmIndexType.regular), - SchemaProperty('uuid', RealmPropertyType.uuid, indexType: RealmIndexType.regular), + SchemaProperty('objectId', RealmPropertyType.objectid, + indexType: RealmIndexType.regular), + SchemaProperty('uuid', RealmPropertyType.uuid, + indexType: RealmIndexType.regular), SchemaProperty('list', RealmPropertyType.int, collectionType: RealmCollectionType.list), SchemaProperty('set', RealmPropertyType.int, @@ -251,13 +332,11 @@ class Bar extends _Bar with RealmEntity, RealmObjectBase, RealmObject { collectionType: RealmCollectionType.list, linkTarget: 'MyFoo'), ]); - } + }(); } class PrimitiveTypes extends _PrimitiveTypes with RealmEntity, RealmObjectBase, RealmObject { - - @ejson PrimitiveTypes( String stringProp, bool boolProp, @@ -313,10 +392,39 @@ class PrimitiveTypes extends _PrimitiveTypes @override PrimitiveTypes freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodePrimitiveTypes(PrimitiveTypes value) { + return { + 'stringProp': toEJson(value.stringProp), + 'boolProp': toEJson(value.boolProp), + 'dateProp': toEJson(value.dateProp), + 'doubleProp': toEJson(value.doubleProp), + 'objectIdProp': toEJson(value.objectIdProp), + }; + } + + static PrimitiveTypes _decodePrimitiveTypes(EJsonValue ejson) { + return switch (ejson) { + { + 'stringProp': EJsonValue stringProp, + 'boolProp': EJsonValue boolProp, + 'dateProp': EJsonValue dateProp, + 'doubleProp': EJsonValue doubleProp, + 'objectIdProp': EJsonValue objectIdProp, + } => + PrimitiveTypes( + fromEJson(stringProp), + fromEJson(boolProp), + fromEJson(dateProp), + fromEJson(doubleProp), + fromEJson(objectIdProp), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(PrimitiveTypes._); + register(_encodePrimitiveTypes, _decodePrimitiveTypes); return const SchemaObject( ObjectType.realmObject, PrimitiveTypes, 'PrimitiveTypes', [ SchemaProperty('stringProp', RealmPropertyType.string), @@ -325,5 +433,5 @@ class PrimitiveTypes extends _PrimitiveTypes SchemaProperty('doubleProp', RealmPropertyType.double), SchemaProperty('objectIdProp', RealmPropertyType.objectid), ]); - } + }(); } diff --git a/packages/realm_generator/test/good_test_data/another_mapto.expected_multi b/packages/realm_generator/test/good_test_data/another_mapto.expected_multi index 81e40545d..78d028c10 100644 --- a/packages/realm_generator/test/good_test_data/another_mapto.expected_multi +++ b/packages/realm_generator/test/good_test_data/another_mapto.expected_multi @@ -9,7 +9,6 @@ part of 'another_mapto.dart'; // ignore_for_file: type=lint class MappedToo extends _MappedToo with RealmEntity, RealmObjectBase, RealmObject { - @ejson MappedToo({ Original? singleLink, Iterable listLink = const [], @@ -42,10 +41,29 @@ class MappedToo extends _MappedToo @override MappedToo freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeMappedToo(MappedToo value) { + return { + 'singleLink': toEJson(value.singleLink), + 'listLink': toEJson(value.listLink), + }; + } + + static MappedToo _decodeMappedToo(EJsonValue ejson) { + return switch (ejson) { + { + 'singleLink': EJsonValue singleLink, + 'listLink': EJsonValue listLink, + } => + MappedToo( + singleLink: fromEJson(singleLink), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(MappedToo._); + register(_encodeMappedToo, _decodeMappedToo); return const SchemaObject( ObjectType.realmObject, MappedToo, 'this is also mapped', [ SchemaProperty('singleLink', RealmPropertyType.object, @@ -53,5 +71,5 @@ class MappedToo extends _MappedToo SchemaProperty('listLink', RealmPropertyType.object, linkTarget: 'another type', collectionType: RealmCollectionType.list), ]); - } + }(); } diff --git a/packages/realm_generator/test/good_test_data/asymmetric_object.expected b/packages/realm_generator/test/good_test_data/asymmetric_object.expected index 5b6b826f2..4fd5fdad6 100644 --- a/packages/realm_generator/test/good_test_data/asymmetric_object.expected +++ b/packages/realm_generator/test/good_test_data/asymmetric_object.expected @@ -9,7 +9,6 @@ part of 'asymmetric_object.dart'; // ignore_for_file: type=lint class Asymmetric extends _Asymmetric with RealmEntity, RealmObjectBase, RealmObject { - @ejson Asymmetric( ObjectId id, { Embedded? father, @@ -58,10 +57,35 @@ class Asymmetric extends _Asymmetric @override Asymmetric freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeAsymmetric(Asymmetric value) { + return { + '_id': toEJson(value.id), + 'children': toEJson(value.children), + 'father': toEJson(value.father), + 'mother': toEJson(value.mother), + }; + } + + static Asymmetric _decodeAsymmetric(EJsonValue ejson) { + return switch (ejson) { + { + '_id': EJsonValue id, + 'children': EJsonValue children, + 'father': EJsonValue father, + 'mother': EJsonValue mother, + } => + Asymmetric( + fromEJson(id), + father: fromEJson(father), + mother: fromEJson(mother), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Asymmetric._); + register(_encodeAsymmetric, _decodeAsymmetric); return const SchemaObject( ObjectType.realmObject, Asymmetric, 'Asymmetric', [ SchemaProperty('id', RealmPropertyType.objectid, @@ -73,12 +97,11 @@ class Asymmetric extends _Asymmetric SchemaProperty('mother', RealmPropertyType.object, optional: true, linkTarget: 'Embedded'), ]); - } + }(); } class Embedded extends _Embedded with RealmEntity, RealmObjectBase, EmbeddedObject { - @ejson Embedded( String name, int age, @@ -106,14 +129,33 @@ class Embedded extends _Embedded @override Embedded freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeEmbedded(Embedded value) { + return { + 'name': toEJson(value.name), + 'age': toEJson(value.age), + }; + } + + static Embedded _decodeEmbedded(EJsonValue ejson) { + return switch (ejson) { + { + 'name': EJsonValue name, + 'age': EJsonValue age, + } => + Embedded( + fromEJson(name), + fromEJson(age), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Embedded._); + register(_encodeEmbedded, _decodeEmbedded); return const SchemaObject(ObjectType.embeddedObject, Embedded, 'Embedded', [ SchemaProperty('name', RealmPropertyType.string), SchemaProperty('age', RealmPropertyType.int), ]); - } + }(); } - diff --git a/packages/realm_generator/test/good_test_data/binary_type.expected b/packages/realm_generator/test/good_test_data/binary_type.expected index 52114e386..2783a7048 100644 --- a/packages/realm_generator/test/good_test_data/binary_type.expected +++ b/packages/realm_generator/test/good_test_data/binary_type.expected @@ -8,14 +8,14 @@ part of 'binary_type.dart'; // ignore_for_file: type=lint class Foo extends _Foo with RealmEntity, RealmObjectBase, RealmObject { - @ejson Foo( Uint8List requiredBinaryProp, { Uint8List? defaultValueBinaryProp, Uint8List? nullableBinaryProp, }) { RealmObjectBase.set(this, 'requiredBinaryProp', requiredBinaryProp); - RealmObjectBase.set(this, 'defaultValueBinaryProp', defaultValueBinaryProp ?? Uint8List(8)); + RealmObjectBase.set( + this, 'defaultValueBinaryProp', defaultValueBinaryProp ?? Uint8List(8)); RealmObjectBase.set(this, 'nullableBinaryProp', nullableBinaryProp); } @@ -50,15 +50,38 @@ class Foo extends _Foo with RealmEntity, RealmObjectBase, RealmObject { @override Foo freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeFoo(Foo value) { + return { + 'requiredBinaryProp': toEJson(value.requiredBinaryProp), + 'defaultValueBinaryProp': toEJson(value.defaultValueBinaryProp), + 'nullableBinaryProp': toEJson(value.nullableBinaryProp), + }; + } + + static Foo _decodeFoo(EJsonValue ejson) { + return switch (ejson) { + { + 'requiredBinaryProp': EJsonValue requiredBinaryProp, + 'defaultValueBinaryProp': EJsonValue defaultValueBinaryProp, + 'nullableBinaryProp': EJsonValue nullableBinaryProp, + } => + Foo( + fromEJson(requiredBinaryProp), + defaultValueBinaryProp: fromEJson(defaultValueBinaryProp), + nullableBinaryProp: fromEJson(nullableBinaryProp), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Foo._); + register(_encodeFoo, _decodeFoo); return const SchemaObject(ObjectType.realmObject, Foo, 'Foo', [ SchemaProperty('requiredBinaryProp', RealmPropertyType.binary), SchemaProperty('defaultValueBinaryProp', RealmPropertyType.binary), SchemaProperty('nullableBinaryProp', RealmPropertyType.binary, optional: true), ]); - } + }(); } diff --git a/packages/realm_generator/test/good_test_data/embedded_annotations.expected b/packages/realm_generator/test/good_test_data/embedded_annotations.expected index 7df0052dd..a94551272 100644 --- a/packages/realm_generator/test/good_test_data/embedded_annotations.expected +++ b/packages/realm_generator/test/good_test_data/embedded_annotations.expected @@ -8,7 +8,6 @@ part of 'embedded_annotations.dart'; // ignore_for_file: type=lint class Parent extends _Parent with RealmEntity, RealmObjectBase, RealmObject { - @ejson Parent({ Child1? child, Iterable children = const [], @@ -41,10 +40,29 @@ class Parent extends _Parent with RealmEntity, RealmObjectBase, RealmObject { @override Parent freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeParent(Parent value) { + return { + 'single child': toEJson(value.child), + 'CHILDREN': toEJson(value.children), + }; + } + + static Parent _decodeParent(EJsonValue ejson) { + return switch (ejson) { + { + 'single child': EJsonValue child, + 'CHILDREN': EJsonValue children, + } => + Parent( + child: fromEJson(child), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Parent._); + register(_encodeParent, _decodeParent); return const SchemaObject(ObjectType.realmObject, Parent, 'Parent', [ SchemaProperty('child', RealmPropertyType.object, mapTo: 'single child', optional: true, linkTarget: 'MySuperChild'), @@ -53,11 +71,10 @@ class Parent extends _Parent with RealmEntity, RealmObjectBase, RealmObject { linkTarget: 'MySuperChild', collectionType: RealmCollectionType.list), ]); - } + }(); } class Child1 extends _Child1 with RealmEntity, RealmObjectBase, EmbeddedObject { - @ejson Child1( String value, String indexedString, { @@ -96,16 +113,40 @@ class Child1 extends _Child1 with RealmEntity, RealmObjectBase, EmbeddedObject { @override Child1 freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeChild1(Child1 value) { + return { + '_value': toEJson(value.value), + '_parent': toEJson(value.linkToParent), + 'indexedString': toEJson(value.indexedString), + }; + } + + static Child1 _decodeChild1(EJsonValue ejson) { + return switch (ejson) { + { + '_value': EJsonValue value, + '_parent': EJsonValue linkToParent, + 'indexedString': EJsonValue indexedString, + } => + Child1( + fromEJson(value), + fromEJson(indexedString), + linkToParent: fromEJson(linkToParent), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Child1._); - return const SchemaObject(ObjectType.embeddedObject, Child1, 'MySuperChild', [ + register(_encodeChild1, _decodeChild1); + return const SchemaObject( + ObjectType.embeddedObject, Child1, 'MySuperChild', [ SchemaProperty('value', RealmPropertyType.string, mapTo: '_value'), SchemaProperty('linkToParent', RealmPropertyType.object, mapTo: '_parent', optional: true, linkTarget: 'Parent'), - SchemaProperty('indexedString', RealmPropertyType.string, indexType: RealmIndexType.regular), + SchemaProperty('indexedString', RealmPropertyType.string, + indexType: RealmIndexType.regular), ]); - } + }(); } - diff --git a/packages/realm_generator/test/good_test_data/embedded_objects.expected b/packages/realm_generator/test/good_test_data/embedded_objects.expected index db0f3d1f1..384c2d902 100644 --- a/packages/realm_generator/test/good_test_data/embedded_objects.expected +++ b/packages/realm_generator/test/good_test_data/embedded_objects.expected @@ -8,7 +8,6 @@ part of 'embedded_objects.dart'; // ignore_for_file: type=lint class Parent extends _Parent with RealmEntity, RealmObjectBase, RealmObject { - @ejson Parent({ Child1? child, Iterable children = const [], @@ -40,21 +39,39 @@ class Parent extends _Parent with RealmEntity, RealmObjectBase, RealmObject { @override Parent freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeParent(Parent value) { + return { + 'child': toEJson(value.child), + 'children': toEJson(value.children), + }; + } + + static Parent _decodeParent(EJsonValue ejson) { + return switch (ejson) { + { + 'child': EJsonValue child, + 'children': EJsonValue children, + } => + Parent( + child: fromEJson(child), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Parent._); + register(_encodeParent, _decodeParent); return const SchemaObject(ObjectType.realmObject, Parent, 'Parent', [ SchemaProperty('child', RealmPropertyType.object, optional: true, linkTarget: 'Child1'), SchemaProperty('children', RealmPropertyType.object, linkTarget: 'Child1', collectionType: RealmCollectionType.list), ]); - } + }(); } class Child1 extends _Child1 with RealmEntity, RealmObjectBase, EmbeddedObject { - @ejson Child1( String value, { Child2? child, @@ -102,10 +119,35 @@ class Child1 extends _Child1 with RealmEntity, RealmObjectBase, EmbeddedObject { @override Child1 freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeChild1(Child1 value) { + return { + 'value': toEJson(value.value), + 'child': toEJson(value.child), + 'children': toEJson(value.children), + 'linkToParent': toEJson(value.linkToParent), + }; + } + + static Child1 _decodeChild1(EJsonValue ejson) { + return switch (ejson) { + { + 'value': EJsonValue value, + 'child': EJsonValue child, + 'children': EJsonValue children, + 'linkToParent': EJsonValue linkToParent, + } => + Child1( + fromEJson(value), + child: fromEJson(child), + linkToParent: fromEJson(linkToParent), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Child1._); + register(_encodeChild1, _decodeChild1); return const SchemaObject(ObjectType.embeddedObject, Child1, 'Child1', [ SchemaProperty('value', RealmPropertyType.string), SchemaProperty('child', RealmPropertyType.object, @@ -115,11 +157,10 @@ class Child1 extends _Child1 with RealmEntity, RealmObjectBase, EmbeddedObject { SchemaProperty('linkToParent', RealmPropertyType.object, optional: true, linkTarget: 'Parent'), ]); - } + }(); } class Child2 extends _Child2 with RealmEntity, RealmObjectBase, EmbeddedObject { - @ejson Child2( bool boolProp, int intProp, @@ -252,10 +293,66 @@ class Child2 extends _Child2 with RealmEntity, RealmObjectBase, EmbeddedObject { @override Child2 freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeChild2(Child2 value) { + return { + 'boolProp': toEJson(value.boolProp), + 'intProp': toEJson(value.intProp), + 'doubleProp': toEJson(value.doubleProp), + 'stringProp': toEJson(value.stringProp), + 'dateProp': toEJson(value.dateProp), + 'objectIdProp': toEJson(value.objectIdProp), + 'uuidProp': toEJson(value.uuidProp), + 'nullableBoolProp': toEJson(value.nullableBoolProp), + 'nullableIntProp': toEJson(value.nullableIntProp), + 'nullableDoubleProp': toEJson(value.nullableDoubleProp), + 'nullableStringProp': toEJson(value.nullableStringProp), + 'nullableDateProp': toEJson(value.nullableDateProp), + 'nullableObjectIdProp': toEJson(value.nullableObjectIdProp), + 'nullableUuidProp': toEJson(value.nullableUuidProp), + }; + } + + static Child2 _decodeChild2(EJsonValue ejson) { + return switch (ejson) { + { + 'boolProp': EJsonValue boolProp, + 'intProp': EJsonValue intProp, + 'doubleProp': EJsonValue doubleProp, + 'stringProp': EJsonValue stringProp, + 'dateProp': EJsonValue dateProp, + 'objectIdProp': EJsonValue objectIdProp, + 'uuidProp': EJsonValue uuidProp, + 'nullableBoolProp': EJsonValue nullableBoolProp, + 'nullableIntProp': EJsonValue nullableIntProp, + 'nullableDoubleProp': EJsonValue nullableDoubleProp, + 'nullableStringProp': EJsonValue nullableStringProp, + 'nullableDateProp': EJsonValue nullableDateProp, + 'nullableObjectIdProp': EJsonValue nullableObjectIdProp, + 'nullableUuidProp': EJsonValue nullableUuidProp, + } => + Child2( + fromEJson(boolProp), + fromEJson(intProp), + fromEJson(doubleProp), + fromEJson(stringProp), + fromEJson(dateProp), + fromEJson(objectIdProp), + fromEJson(uuidProp), + nullableBoolProp: fromEJson(nullableBoolProp), + nullableIntProp: fromEJson(nullableIntProp), + nullableDoubleProp: fromEJson(nullableDoubleProp), + nullableStringProp: fromEJson(nullableStringProp), + nullableDateProp: fromEJson(nullableDateProp), + nullableObjectIdProp: fromEJson(nullableObjectIdProp), + nullableUuidProp: fromEJson(nullableUuidProp), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Child2._); + register(_encodeChild2, _decodeChild2); return const SchemaObject(ObjectType.embeddedObject, Child2, 'Child2', [ SchemaProperty('boolProp', RealmPropertyType.bool), SchemaProperty('intProp', RealmPropertyType.int), @@ -278,6 +375,5 @@ class Child2 extends _Child2 with RealmEntity, RealmObjectBase, EmbeddedObject { SchemaProperty('nullableUuidProp', RealmPropertyType.uuid, optional: true), ]); - } + }(); } - diff --git a/packages/realm_generator/test/good_test_data/indexable_types.expected b/packages/realm_generator/test/good_test_data/indexable_types.expected index 834a6f27d..c2c37e96e 100644 --- a/packages/realm_generator/test/good_test_data/indexable_types.expected +++ b/packages/realm_generator/test/good_test_data/indexable_types.expected @@ -9,7 +9,6 @@ part of 'indexable_types.dart'; // ignore_for_file: type=lint class Indexable extends _Indexable with RealmEntity, RealmObjectBase, RealmObject { - @ejson Indexable( bool aBool, int anInt, @@ -159,10 +158,72 @@ class Indexable extends _Indexable @override Indexable freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeIndexable(Indexable value) { + return { + 'aBool': toEJson(value.aBool), + 'aNullableBool': toEJson(value.aNullableBool), + 'anInt': toEJson(value.anInt), + 'aNullableInt': toEJson(value.aNullableInt), + 'aString': toEJson(value.aString), + 'aNullableString': toEJson(value.aNullableString), + 'anObjectId': toEJson(value.anObjectId), + 'aNullableObjectId': toEJson(value.aNullableObjectId), + 'anUuid': toEJson(value.anUuid), + 'aNullableUuid': toEJson(value.aNullableUuid), + 'aDateTime': toEJson(value.aDateTime), + 'aNullableDateTime': toEJson(value.aNullableDateTime), + 'aRealmValue': toEJson(value.aRealmValue), + 'generalStringIndex': toEJson(value.generalStringIndex), + 'ftsStringValue': toEJson(value.ftsStringValue), + 'nullableFtsStringValue': toEJson(value.nullableFtsStringValue), + }; + } + + static Indexable _decodeIndexable(EJsonValue ejson) { + return switch (ejson) { + { + 'aBool': EJsonValue aBool, + 'aNullableBool': EJsonValue aNullableBool, + 'anInt': EJsonValue anInt, + 'aNullableInt': EJsonValue aNullableInt, + 'aString': EJsonValue aString, + 'aNullableString': EJsonValue aNullableString, + 'anObjectId': EJsonValue anObjectId, + 'aNullableObjectId': EJsonValue aNullableObjectId, + 'anUuid': EJsonValue anUuid, + 'aNullableUuid': EJsonValue aNullableUuid, + 'aDateTime': EJsonValue aDateTime, + 'aNullableDateTime': EJsonValue aNullableDateTime, + 'aRealmValue': EJsonValue aRealmValue, + 'generalStringIndex': EJsonValue generalStringIndex, + 'ftsStringValue': EJsonValue ftsStringValue, + 'nullableFtsStringValue': EJsonValue nullableFtsStringValue, + } => + Indexable( + fromEJson(aBool), + fromEJson(anInt), + fromEJson(aString), + fromEJson(anObjectId), + fromEJson(anUuid), + fromEJson(aDateTime), + fromEJson(generalStringIndex), + fromEJson(ftsStringValue), + aNullableBool: fromEJson(aNullableBool), + aNullableInt: fromEJson(aNullableInt), + aNullableString: fromEJson(aNullableString), + aNullableObjectId: fromEJson(aNullableObjectId), + aNullableUuid: fromEJson(aNullableUuid), + aNullableDateTime: fromEJson(aNullableDateTime), + aRealmValue: fromEJson(aRealmValue), + nullableFtsStringValue: fromEJson(nullableFtsStringValue), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Indexable._); + register(_encodeIndexable, _decodeIndexable); return const SchemaObject(ObjectType.realmObject, Indexable, 'Indexable', [ SchemaProperty('aBool', RealmPropertyType.bool, indexType: RealmIndexType.regular), @@ -197,5 +258,5 @@ class Indexable extends _Indexable SchemaProperty('nullableFtsStringValue', RealmPropertyType.string, optional: true, indexType: RealmIndexType.fullText), ]); - } + }(); } diff --git a/packages/realm_generator/test/good_test_data/list_initialization.expected b/packages/realm_generator/test/good_test_data/list_initialization.expected index 9b975ea95..7ec0cfac8 100644 --- a/packages/realm_generator/test/good_test_data/list_initialization.expected +++ b/packages/realm_generator/test/good_test_data/list_initialization.expected @@ -8,7 +8,6 @@ part of 'list_initialization.dart'; // ignore_for_file: type=lint class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { - @ejson Person({ Iterable children = const [], Iterable initList = const [], @@ -34,8 +33,7 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { this, 'initSetWithType', RealmSet(initSetWithType)); RealmObjectBase.set>( this, 'initSetConst', RealmSet(initSetConst)); - RealmObjectBase.set>( - this, 'initMap', RealmMap(initMap)); + RealmObjectBase.set>(this, 'initMap', RealmMap(initMap)); RealmObjectBase.set>( this, 'initMapWithType', RealmMap(initMapWithType)); RealmObjectBase.set>( @@ -102,8 +100,7 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { @override RealmMap get initMapWithType => - RealmObjectBase.get(this, 'initMapWithType') - as RealmMap; + RealmObjectBase.get(this, 'initMapWithType') as RealmMap; @override set initMapWithType(covariant RealmMap value) => throw RealmUnsupportedSetError(); @@ -122,10 +119,43 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { @override Person freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodePerson(Person value) { + return { + 'children': toEJson(value.children), + 'initList': toEJson(value.initList), + 'initListWithType': toEJson(value.initListWithType), + 'initListConst': toEJson(value.initListConst), + 'initSet': toEJson(value.initSet), + 'initSetWithType': toEJson(value.initSetWithType), + 'initSetConst': toEJson(value.initSetConst), + 'initMap': toEJson(value.initMap), + 'initMapWithType': toEJson(value.initMapWithType), + 'initMapConst': toEJson(value.initMapConst), + }; + } + + static Person _decodePerson(EJsonValue ejson) { + return switch (ejson) { + { + 'children': EJsonValue children, + 'initList': EJsonValue initList, + 'initListWithType': EJsonValue initListWithType, + 'initListConst': EJsonValue initListConst, + 'initSet': EJsonValue initSet, + 'initSetWithType': EJsonValue initSetWithType, + 'initSetConst': EJsonValue initSetConst, + 'initMap': EJsonValue initMap, + 'initMapWithType': EJsonValue initMapWithType, + 'initMapConst': EJsonValue initMapConst, + } => + Person(), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Person._); + register(_encodePerson, _decodePerson); return const SchemaObject(ObjectType.realmObject, Person, 'Person', [ SchemaProperty('children', RealmPropertyType.object, linkTarget: 'Person', collectionType: RealmCollectionType.list), @@ -148,5 +178,5 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { SchemaProperty('initMapConst', RealmPropertyType.int, collectionType: RealmCollectionType.map), ]); - } + }(); } diff --git a/packages/realm_generator/test/good_test_data/map.expected b/packages/realm_generator/test/good_test_data/map.expected index 2916662ce..ea8a31069 100644 --- a/packages/realm_generator/test/good_test_data/map.expected +++ b/packages/realm_generator/test/good_test_data/map.expected @@ -9,7 +9,6 @@ part of 'map.dart'; // ignore_for_file: type=lint class LotsOfMaps extends _LotsOfMaps with RealmEntity, RealmObjectBase, RealmObject { - @ejson LotsOfMaps({ Map persons = const {}, Map bools = const {}, @@ -25,16 +24,14 @@ class LotsOfMaps extends _LotsOfMaps }) { RealmObjectBase.set>( this, 'persons', RealmMap(persons)); - RealmObjectBase.set>( - this, 'bools', RealmMap(bools)); + RealmObjectBase.set>(this, 'bools', RealmMap(bools)); RealmObjectBase.set>( this, 'dateTimes', RealmMap(dateTimes)); RealmObjectBase.set>( this, 'decimals', RealmMap(decimals)); RealmObjectBase.set>( this, 'doubles', RealmMap(doubles)); - RealmObjectBase.set>( - this, 'ints', RealmMap(ints)); + RealmObjectBase.set>(this, 'ints', RealmMap(ints)); RealmObjectBase.set>( this, 'objectIds', RealmMap(objectIds)); RealmObjectBase.set>( @@ -43,8 +40,7 @@ class LotsOfMaps extends _LotsOfMaps this, 'strings', RealmMap(strings)); RealmObjectBase.set>( this, 'binary', RealmMap(binary)); - RealmObjectBase.set>( - this, 'uuids', RealmMap(uuids)); + RealmObjectBase.set>(this, 'uuids', RealmMap(uuids)); } LotsOfMaps._(); @@ -60,21 +56,18 @@ class LotsOfMaps extends _LotsOfMaps RealmMap get bools => RealmObjectBase.get(this, 'bools') as RealmMap; @override - set bools(covariant RealmMap value) => - throw RealmUnsupportedSetError(); + set bools(covariant RealmMap value) => throw RealmUnsupportedSetError(); @override RealmMap get dateTimes => - RealmObjectBase.get(this, 'dateTimes') - as RealmMap; + RealmObjectBase.get(this, 'dateTimes') as RealmMap; @override set dateTimes(covariant RealmMap value) => throw RealmUnsupportedSetError(); @override RealmMap get decimals => - RealmObjectBase.get(this, 'decimals') - as RealmMap; + RealmObjectBase.get(this, 'decimals') as RealmMap; @override set decimals(covariant RealmMap value) => throw RealmUnsupportedSetError(); @@ -90,21 +83,18 @@ class LotsOfMaps extends _LotsOfMaps RealmMap get ints => RealmObjectBase.get(this, 'ints') as RealmMap; @override - set ints(covariant RealmMap value) => - throw RealmUnsupportedSetError(); + set ints(covariant RealmMap value) => throw RealmUnsupportedSetError(); @override RealmMap get objectIds => - RealmObjectBase.get(this, 'objectIds') - as RealmMap; + RealmObjectBase.get(this, 'objectIds') as RealmMap; @override set objectIds(covariant RealmMap value) => throw RealmUnsupportedSetError(); @override RealmMap get any => - RealmObjectBase.get(this, 'any') - as RealmMap; + RealmObjectBase.get(this, 'any') as RealmMap; @override set any(covariant RealmMap value) => throw RealmUnsupportedSetError(); @@ -118,8 +108,7 @@ class LotsOfMaps extends _LotsOfMaps @override RealmMap get binary => - RealmObjectBase.get(this, 'binary') - as RealmMap; + RealmObjectBase.get(this, 'binary') as RealmMap; @override set binary(covariant RealmMap value) => throw RealmUnsupportedSetError(); @@ -128,8 +117,7 @@ class LotsOfMaps extends _LotsOfMaps RealmMap get uuids => RealmObjectBase.get(this, 'uuids') as RealmMap; @override - set uuids(covariant RealmMap value) => - throw RealmUnsupportedSetError(); + set uuids(covariant RealmMap value) => throw RealmUnsupportedSetError(); @override Stream> get changes => @@ -138,14 +126,51 @@ class LotsOfMaps extends _LotsOfMaps @override LotsOfMaps freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeLotsOfMaps(LotsOfMaps value) { + return { + 'persons': toEJson(value.persons), + 'bools': toEJson(value.bools), + 'dateTimes': toEJson(value.dateTimes), + 'decimals': toEJson(value.decimals), + 'doubles': toEJson(value.doubles), + 'ints': toEJson(value.ints), + 'objectIds': toEJson(value.objectIds), + 'any': toEJson(value.any), + 'strings': toEJson(value.strings), + 'binary': toEJson(value.binary), + 'uuids': toEJson(value.uuids), + }; + } + + static LotsOfMaps _decodeLotsOfMaps(EJsonValue ejson) { + return switch (ejson) { + { + 'persons': EJsonValue persons, + 'bools': EJsonValue bools, + 'dateTimes': EJsonValue dateTimes, + 'decimals': EJsonValue decimals, + 'doubles': EJsonValue doubles, + 'ints': EJsonValue ints, + 'objectIds': EJsonValue objectIds, + 'any': EJsonValue any, + 'strings': EJsonValue strings, + 'binary': EJsonValue binary, + 'uuids': EJsonValue uuids, + } => + LotsOfMaps(), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(LotsOfMaps._); + register(_encodeLotsOfMaps, _decodeLotsOfMaps); return const SchemaObject( ObjectType.realmObject, LotsOfMaps, 'LotsOfMaps', [ SchemaProperty('persons', RealmPropertyType.object, - optional: true, linkTarget: 'Person', collectionType: RealmCollectionType.map), + optional: true, + linkTarget: 'Person', + collectionType: RealmCollectionType.map), SchemaProperty('bools', RealmPropertyType.bool, collectionType: RealmCollectionType.map), SchemaProperty('dateTimes', RealmPropertyType.timestamp, @@ -167,11 +192,10 @@ class LotsOfMaps extends _LotsOfMaps SchemaProperty('uuids', RealmPropertyType.uuid, collectionType: RealmCollectionType.map), ]); - } + }(); } class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { - @ejson Person( String name, ) { @@ -192,12 +216,29 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { @override Person freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodePerson(Person value) { + return { + 'name': toEJson(value.name), + }; + } + + static Person _decodePerson(EJsonValue ejson) { + return switch (ejson) { + { + 'name': EJsonValue name, + } => + Person( + fromEJson(name), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Person._); + register(_encodePerson, _decodePerson); return const SchemaObject(ObjectType.realmObject, Person, 'Person', [ SchemaProperty('name', RealmPropertyType.string), ]); - } + }(); } diff --git a/packages/realm_generator/test/good_test_data/mapto.expected b/packages/realm_generator/test/good_test_data/mapto.expected index 8dbb26493..5932d65d2 100644 --- a/packages/realm_generator/test/good_test_data/mapto.expected +++ b/packages/realm_generator/test/good_test_data/mapto.expected @@ -11,7 +11,6 @@ class Original extends $Original with RealmEntity, RealmObjectBase, RealmObject { static var _defaultsSet = false; - @ejson Original({ int primitiveProperty = 0, Original? objectProperty, @@ -59,10 +58,32 @@ class Original extends $Original @override Original freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeOriginal(Original value) { + return { + 'remapped primitive': toEJson(value.primitiveProperty), + 'remapped object': toEJson(value.objectProperty), + 'remapped list': toEJson(value.listProperty), + }; + } + + static Original _decodeOriginal(EJsonValue ejson) { + return switch (ejson) { + { + 'remapped primitive': EJsonValue primitiveProperty, + 'remapped object': EJsonValue objectProperty, + 'remapped list': EJsonValue listProperty, + } => + Original( + primitiveProperty: fromEJson(primitiveProperty), + objectProperty: fromEJson(objectProperty), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Original._); + register(_encodeOriginal, _decodeOriginal); return const SchemaObject( ObjectType.realmObject, Original, 'another type', [ SchemaProperty('primitiveProperty', RealmPropertyType.int, @@ -74,6 +95,5 @@ class Original extends $Original linkTarget: 'another type', collectionType: RealmCollectionType.list), ]); - } + }(); } - diff --git a/packages/realm_generator/test/good_test_data/optional_argument.expected b/packages/realm_generator/test/good_test_data/optional_argument.expected index cd0eaf05a..76595c3c3 100644 --- a/packages/realm_generator/test/good_test_data/optional_argument.expected +++ b/packages/realm_generator/test/good_test_data/optional_argument.expected @@ -8,7 +8,6 @@ part of 'optional_argument.dart'; // ignore_for_file: type=lint class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { - @ejson Person({ Person? spouse, }) { @@ -30,14 +29,30 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { @override Person freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodePerson(Person value) { + return { + 'spouse': toEJson(value.spouse), + }; + } + + static Person _decodePerson(EJsonValue ejson) { + return switch (ejson) { + { + 'spouse': EJsonValue spouse, + } => + Person( + spouse: fromEJson(spouse), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Person._); + register(_encodePerson, _decodePerson); return const SchemaObject(ObjectType.realmObject, Person, 'Person', [ SchemaProperty('spouse', RealmPropertyType.object, optional: true, linkTarget: 'Person'), ]); - } + }(); } - diff --git a/packages/realm_generator/test/good_test_data/pinhole.expected b/packages/realm_generator/test/good_test_data/pinhole.expected index f6bf2d0f1..0e9902746 100644 --- a/packages/realm_generator/test/good_test_data/pinhole.expected +++ b/packages/realm_generator/test/good_test_data/pinhole.expected @@ -10,7 +10,6 @@ part of 'pinhole.dart'; class Foo extends _Foo with RealmEntity, RealmObjectBase, RealmObject { static var _defaultsSet = false; - @ejson Foo({ int x = 0, }) { @@ -36,13 +35,29 @@ class Foo extends _Foo with RealmEntity, RealmObjectBase, RealmObject { @override Foo freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeFoo(Foo value) { + return { + 'x': toEJson(value.x), + }; + } + + static Foo _decodeFoo(EJsonValue ejson) { + return switch (ejson) { + { + 'x': EJsonValue x, + } => + Foo( + x: fromEJson(x), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Foo._); + register(_encodeFoo, _decodeFoo); return const SchemaObject(ObjectType.realmObject, Foo, 'Foo', [ SchemaProperty('x', RealmPropertyType.int), ]); - } + }(); } - diff --git a/packages/realm_generator/test/good_test_data/primary_key.expected b/packages/realm_generator/test/good_test_data/primary_key.expected index 1a1930753..28d71bfa0 100644 --- a/packages/realm_generator/test/good_test_data/primary_key.expected +++ b/packages/realm_generator/test/good_test_data/primary_key.expected @@ -8,7 +8,6 @@ part of 'primary_key.dart'; // ignore_for_file: type=lint class IntPK extends _IntPK with RealmEntity, RealmObjectBase, RealmObject { - @ejson IntPK( int id, ) { @@ -29,19 +28,35 @@ class IntPK extends _IntPK with RealmEntity, RealmObjectBase, RealmObject { @override IntPK freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeIntPK(IntPK value) { + return { + 'id': toEJson(value.id), + }; + } + + static IntPK _decodeIntPK(EJsonValue ejson) { + return switch (ejson) { + { + 'id': EJsonValue id, + } => + IntPK( + fromEJson(id), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(IntPK._); + register(_encodeIntPK, _decodeIntPK); return const SchemaObject(ObjectType.realmObject, IntPK, 'IntPK', [ SchemaProperty('id', RealmPropertyType.int, primaryKey: true), ]); - } + }(); } class NullableIntPK extends _NullableIntPK with RealmEntity, RealmObjectBase, RealmObject { - @ejson NullableIntPK( int? id, ) { @@ -62,22 +77,37 @@ class NullableIntPK extends _NullableIntPK @override NullableIntPK freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeNullableIntPK(NullableIntPK value) { + return { + 'id': toEJson(value.id), + }; + } + + static NullableIntPK _decodeNullableIntPK(EJsonValue ejson) { + return switch (ejson) { + { + 'id': EJsonValue id, + } => + NullableIntPK( + fromEJson(id), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(NullableIntPK._); + register(_encodeNullableIntPK, _decodeNullableIntPK); return const SchemaObject( ObjectType.realmObject, NullableIntPK, 'NullableIntPK', [ SchemaProperty('id', RealmPropertyType.int, optional: true, primaryKey: true), ]); - } + }(); } - class StringPK extends _StringPK with RealmEntity, RealmObjectBase, RealmObject { - @ejson StringPK( String id, ) { @@ -98,19 +128,35 @@ class StringPK extends _StringPK @override StringPK freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeStringPK(StringPK value) { + return { + 'id': toEJson(value.id), + }; + } + + static StringPK _decodeStringPK(EJsonValue ejson) { + return switch (ejson) { + { + 'id': EJsonValue id, + } => + StringPK( + fromEJson(id), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(StringPK._); + register(_encodeStringPK, _decodeStringPK); return const SchemaObject(ObjectType.realmObject, StringPK, 'StringPK', [ SchemaProperty('id', RealmPropertyType.string, primaryKey: true), ]); - } + }(); } class NullableStringPK extends _NullableStringPK with RealmEntity, RealmObjectBase, RealmObject { - @ejson NullableStringPK( String? id, ) { @@ -132,21 +178,37 @@ class NullableStringPK extends _NullableStringPK NullableStringPK freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeNullableStringPK(NullableStringPK value) { + return { + 'id': toEJson(value.id), + }; + } + + static NullableStringPK _decodeNullableStringPK(EJsonValue ejson) { + return switch (ejson) { + { + 'id': EJsonValue id, + } => + NullableStringPK( + fromEJson(id), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(NullableStringPK._); + register(_encodeNullableStringPK, _decodeNullableStringPK); return const SchemaObject( ObjectType.realmObject, NullableStringPK, 'NullableStringPK', [ SchemaProperty('id', RealmPropertyType.string, optional: true, primaryKey: true), ]); - } + }(); } class ObjectIdPK extends _ObjectIdPK with RealmEntity, RealmObjectBase, RealmObject { - @ejson ObjectIdPK( ObjectId id, ) { @@ -167,19 +229,36 @@ class ObjectIdPK extends _ObjectIdPK @override ObjectIdPK freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeObjectIdPK(ObjectIdPK value) { + return { + 'id': toEJson(value.id), + }; + } + + static ObjectIdPK _decodeObjectIdPK(EJsonValue ejson) { + return switch (ejson) { + { + 'id': EJsonValue id, + } => + ObjectIdPK( + fromEJson(id), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(ObjectIdPK._); - return const SchemaObject(ObjectType.realmObject, ObjectIdPK, 'ObjectIdPK', [ + register(_encodeObjectIdPK, _decodeObjectIdPK); + return const SchemaObject( + ObjectType.realmObject, ObjectIdPK, 'ObjectIdPK', [ SchemaProperty('id', RealmPropertyType.objectid, primaryKey: true), ]); - } + }(); } class NullableObjectIdPK extends _NullableObjectIdPK with RealmEntity, RealmObjectBase, RealmObject { - @ejson NullableObjectIdPK( ObjectId? id, ) { @@ -201,20 +280,36 @@ class NullableObjectIdPK extends _NullableObjectIdPK NullableObjectIdPK freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeNullableObjectIdPK(NullableObjectIdPK value) { + return { + 'id': toEJson(value.id), + }; + } + + static NullableObjectIdPK _decodeNullableObjectIdPK(EJsonValue ejson) { + return switch (ejson) { + { + 'id': EJsonValue id, + } => + NullableObjectIdPK( + fromEJson(id), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(NullableObjectIdPK._); + register(_encodeNullableObjectIdPK, _decodeNullableObjectIdPK); return const SchemaObject( ObjectType.realmObject, NullableObjectIdPK, 'NullableObjectIdPK', [ SchemaProperty('id', RealmPropertyType.objectid, optional: true, primaryKey: true), ]); - } + }(); } class UuidPK extends _UuidPK with RealmEntity, RealmObjectBase, RealmObject { - @ejson UuidPK( Uuid id, ) { @@ -235,19 +330,35 @@ class UuidPK extends _UuidPK with RealmEntity, RealmObjectBase, RealmObject { @override UuidPK freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeUuidPK(UuidPK value) { + return { + 'id': toEJson(value.id), + }; + } + + static UuidPK _decodeUuidPK(EJsonValue ejson) { + return switch (ejson) { + { + 'id': EJsonValue id, + } => + UuidPK( + fromEJson(id), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(UuidPK._); + register(_encodeUuidPK, _decodeUuidPK); return const SchemaObject(ObjectType.realmObject, UuidPK, 'UuidPK', [ SchemaProperty('id', RealmPropertyType.uuid, primaryKey: true), ]); - } + }(); } class NullableUuidPK extends _NullableUuidPK with RealmEntity, RealmObjectBase, RealmObject { - @ejson NullableUuidPK( Uuid? id, ) { @@ -268,15 +379,31 @@ class NullableUuidPK extends _NullableUuidPK @override NullableUuidPK freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeNullableUuidPK(NullableUuidPK value) { + return { + 'id': toEJson(value.id), + }; + } + + static NullableUuidPK _decodeNullableUuidPK(EJsonValue ejson) { + return switch (ejson) { + { + 'id': EJsonValue id, + } => + NullableUuidPK( + fromEJson(id), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(NullableUuidPK._); + register(_encodeNullableUuidPK, _decodeNullableUuidPK); return const SchemaObject( ObjectType.realmObject, NullableUuidPK, 'NullableUuidPK', [ SchemaProperty('id', RealmPropertyType.uuid, optional: true, primaryKey: true), ]); - } + }(); } - diff --git a/packages/realm_generator/test/good_test_data/realm_set.expected b/packages/realm_generator/test/good_test_data/realm_set.expected index 5fbdc5f80..4656e5996 100644 --- a/packages/realm_generator/test/good_test_data/realm_set.expected +++ b/packages/realm_generator/test/good_test_data/realm_set.expected @@ -8,7 +8,6 @@ part of 'realm_set.dart'; // ignore_for_file: type=lint class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { - @ejson Car( String make, ) { @@ -29,19 +28,35 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { @override Car freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeCar(Car value) { + return { + 'make': toEJson(value.make), + }; + } + + static Car _decodeCar(EJsonValue ejson) { + return switch (ejson) { + { + 'make': EJsonValue make, + } => + Car( + fromEJson(make), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Car._); + register(_encodeCar, _decodeCar); return const SchemaObject(ObjectType.realmObject, Car, 'Car', [ SchemaProperty('make', RealmPropertyType.string, primaryKey: true), ]); - } + }(); } class RealmSets extends _RealmSets with RealmEntity, RealmObjectBase, RealmObject { - @ejson RealmSets( int key, { Set boolSet = const {}, @@ -225,10 +240,59 @@ class RealmSets extends _RealmSets @override RealmSets freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeRealmSets(RealmSets value) { + return { + 'key': toEJson(value.key), + 'boolSet': toEJson(value.boolSet), + 'nullableBoolSet': toEJson(value.nullableBoolSet), + 'intSet': toEJson(value.intSet), + 'nullableintSet': toEJson(value.nullableintSet), + 'stringSet': toEJson(value.stringSet), + 'nullablestringSet': toEJson(value.nullablestringSet), + 'doubleSet': toEJson(value.doubleSet), + 'nullabledoubleSet': toEJson(value.nullabledoubleSet), + 'dateTimeSet': toEJson(value.dateTimeSet), + 'nullabledateTimeSet': toEJson(value.nullabledateTimeSet), + 'objectIdSet': toEJson(value.objectIdSet), + 'nullableobjectIdSet': toEJson(value.nullableobjectIdSet), + 'uuidSet': toEJson(value.uuidSet), + 'nullableuuidSet': toEJson(value.nullableuuidSet), + 'realmValueSet': toEJson(value.realmValueSet), + 'realmObjectsSet': toEJson(value.realmObjectsSet), + }; + } + + static RealmSets _decodeRealmSets(EJsonValue ejson) { + return switch (ejson) { + { + 'key': EJsonValue key, + 'boolSet': EJsonValue boolSet, + 'nullableBoolSet': EJsonValue nullableBoolSet, + 'intSet': EJsonValue intSet, + 'nullableintSet': EJsonValue nullableintSet, + 'stringSet': EJsonValue stringSet, + 'nullablestringSet': EJsonValue nullablestringSet, + 'doubleSet': EJsonValue doubleSet, + 'nullabledoubleSet': EJsonValue nullabledoubleSet, + 'dateTimeSet': EJsonValue dateTimeSet, + 'nullabledateTimeSet': EJsonValue nullabledateTimeSet, + 'objectIdSet': EJsonValue objectIdSet, + 'nullableobjectIdSet': EJsonValue nullableobjectIdSet, + 'uuidSet': EJsonValue uuidSet, + 'nullableuuidSet': EJsonValue nullableuuidSet, + 'realmValueSet': EJsonValue realmValueSet, + 'realmObjectsSet': EJsonValue realmObjectsSet, + } => + RealmSets( + fromEJson(key), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(RealmSets._); + register(_encodeRealmSets, _decodeRealmSets); return const SchemaObject(ObjectType.realmObject, RealmSets, 'RealmSets', [ SchemaProperty('key', RealmPropertyType.int, primaryKey: true), SchemaProperty('boolSet', RealmPropertyType.bool, @@ -264,5 +328,5 @@ class RealmSets extends _RealmSets SchemaProperty('realmObjectsSet', RealmPropertyType.object, linkTarget: 'Car', collectionType: RealmCollectionType.set), ]); - } -} \ No newline at end of file + }(); +} diff --git a/packages/realm_generator/test/good_test_data/required_argument.expected b/packages/realm_generator/test/good_test_data/required_argument.expected index 942abb125..dbf38a559 100644 --- a/packages/realm_generator/test/good_test_data/required_argument.expected +++ b/packages/realm_generator/test/good_test_data/required_argument.expected @@ -8,7 +8,6 @@ part of 'required_argument.dart'; // ignore_for_file: type=lint class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { - @ejson Person( String name, ) { @@ -29,13 +28,29 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { @override Person freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodePerson(Person value) { + return { + 'name': toEJson(value.name), + }; + } + + static Person _decodePerson(EJsonValue ejson) { + return switch (ejson) { + { + 'name': EJsonValue name, + } => + Person( + fromEJson(name), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Person._); + register(_encodePerson, _decodePerson); return const SchemaObject(ObjectType.realmObject, Person, 'Person', [ SchemaProperty('name', RealmPropertyType.string, primaryKey: true), ]); - } + }(); } - diff --git a/packages/realm_generator/test/good_test_data/required_argument_with_default_value.expected b/packages/realm_generator/test/good_test_data/required_argument_with_default_value.expected index c470373e9..d1b237f64 100644 --- a/packages/realm_generator/test/good_test_data/required_argument_with_default_value.expected +++ b/packages/realm_generator/test/good_test_data/required_argument_with_default_value.expected @@ -10,7 +10,6 @@ part of 'required_argument_with_default_value.dart'; class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { static var _defaultsSet = false; - @ejson Person({ int age = 47, }) { @@ -36,13 +35,29 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { @override Person freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodePerson(Person value) { + return { + 'age': toEJson(value.age), + }; + } + + static Person _decodePerson(EJsonValue ejson) { + return switch (ejson) { + { + 'age': EJsonValue age, + } => + Person( + age: fromEJson(age), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Person._); + register(_encodePerson, _decodePerson); return const SchemaObject(ObjectType.realmObject, Person, 'Person', [ SchemaProperty('age', RealmPropertyType.int), ]); - } + }(); } - diff --git a/packages/realm_generator/test/good_test_data/user_defined_getter.expected b/packages/realm_generator/test/good_test_data/user_defined_getter.expected index f68dcf984..79f6d4603 100644 --- a/packages/realm_generator/test/good_test_data/user_defined_getter.expected +++ b/packages/realm_generator/test/good_test_data/user_defined_getter.expected @@ -8,7 +8,6 @@ part of 'user_defined_getter.dart'; // ignore_for_file: type=lint class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { - @ejson Person( String name, ) { @@ -29,13 +28,29 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { @override Person freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodePerson(Person value) { + return { + 'name': toEJson(value.name), + }; + } + + static Person _decodePerson(EJsonValue ejson) { + return switch (ejson) { + { + 'name': EJsonValue name, + } => + Person( + fromEJson(name), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Person._); + register(_encodePerson, _decodePerson); return const SchemaObject(ObjectType.realmObject, Person, 'Person', [ SchemaProperty('name', RealmPropertyType.string), ]); - } + }(); } - From e5a4d266c0a8d1b4316bf377c7d0630ca4132ed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Thu, 29 Feb 2024 13:58:47 +0100 Subject: [PATCH 129/153] Drop dep on ejson_annotation and ejson_generator --- packages/realm_dart/pubspec.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/realm_dart/pubspec.yaml b/packages/realm_dart/pubspec.yaml index a5b2c869b..73c70efc5 100644 --- a/packages/realm_dart/pubspec.yaml +++ b/packages/realm_dart/pubspec.yaml @@ -14,7 +14,6 @@ dependencies: build_cli_annotations: ^2.0.0 collection: ^1.16.0 crypto: ^3.0.0 - ejson_annotation: ^0.1.0 ejson: ^0.1.0 ffi: ^2.0.1 json_annotation: ^4.7.0 @@ -33,9 +32,7 @@ dependencies: dev_dependencies: build_cli: ^2.2.2 - ejson_generator: ^0.1.0 json_serializable: ^6.3.1 lints: ^3.0.0 test: ^1.14.3 timezone: ^0.9.0 - From a15249645642dfcc07bc4a73762ee0fe3b65ccca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Thu, 29 Feb 2024 14:01:27 +0100 Subject: [PATCH 130/153] Rerun generator (.g.dart files no longer generated) --- packages/realm/example/lib/main.g.dart | 54 - packages/realm/example/lib/main.realm.dart | 64 +- packages/realm_dart/example/bin/myapp.dart | 2 +- packages/realm_dart/example/bin/myapp.g.dart | 54 - .../realm_dart/example/bin/myapp.realm.dart | 64 +- packages/realm_dart/test/backlinks_test.dart | 2 +- .../realm_dart/test/backlinks_test.g.dart | 58 - .../realm_dart/test/backlinks_test.realm.dart | 69 +- packages/realm_dart/test/geospatial_test.dart | 2 +- .../realm_dart/test/geospatial_test.g.dart | 61 - .../test/geospatial_test.realm.dart | 81 +- packages/realm_dart/test/indexed_test.dart | 2 +- packages/realm_dart/test/indexed_test.g.dart | 97 -- .../realm_dart/test/indexed_test.realm.dart | 114 +- packages/realm_dart/test/migration_test.dart | 2 +- .../realm_dart/test/migration_test.g.dart | 93 -- .../realm_dart/test/migration_test.realm.dart | 139 +- packages/realm_dart/test/realm_map_test.dart | 2 +- .../realm_dart/test/realm_map_test.g.dart | 124 -- .../realm_dart/test/realm_map_test.realm.dart | 123 +- .../realm_dart/test/realm_object_test.dart | 2 +- .../realm_dart/test/realm_object_test.g.dart | 174 --- .../test/realm_object_test.realm.dart | 272 +++- packages/realm_dart/test/realm_set_test.dart | 2 +- .../realm_dart/test/realm_set_test.g.dart | 99 -- .../realm_dart/test/realm_set_test.realm.dart | 91 +- .../realm_dart/test/realm_value_test.dart | 2 +- .../realm_dart/test/realm_value_test.g.dart | 70 - .../test/realm_value_test.realm.dart | 84 +- packages/realm_dart/test/test.dart | 2 +- packages/realm_dart/test/test.g.dart | 917 ------------- packages/realm_dart/test/test.realm.dart | 1139 ++++++++++++++--- 32 files changed, 1925 insertions(+), 2136 deletions(-) delete mode 100644 packages/realm/example/lib/main.g.dart delete mode 100644 packages/realm_dart/example/bin/myapp.g.dart delete mode 100644 packages/realm_dart/test/backlinks_test.g.dart delete mode 100644 packages/realm_dart/test/geospatial_test.g.dart delete mode 100644 packages/realm_dart/test/indexed_test.g.dart delete mode 100644 packages/realm_dart/test/migration_test.g.dart delete mode 100644 packages/realm_dart/test/realm_map_test.g.dart delete mode 100644 packages/realm_dart/test/realm_object_test.g.dart delete mode 100644 packages/realm_dart/test/realm_set_test.g.dart delete mode 100644 packages/realm_dart/test/realm_value_test.g.dart delete mode 100644 packages/realm_dart/test/test.g.dart diff --git a/packages/realm/example/lib/main.g.dart b/packages/realm/example/lib/main.g.dart deleted file mode 100644 index 14243f2fd..000000000 --- a/packages/realm/example/lib/main.g.dart +++ /dev/null @@ -1,54 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'main.dart'; - -// ************************************************************************** -// EJsonGenerator -// ************************************************************************** - -EJsonValue encodeCar(Car value) { - return { - 'make': value.make.toEJson(), - 'model': value.model.toEJson(), - 'kilometers': value.kilometers.toEJson(), - 'owner': value.owner.toEJson() - }; -} - -Car decodeCar(EJsonValue ejson) { - return switch (ejson) { - { - 'make': EJsonValue make, - 'model': EJsonValue model, - 'kilometers': EJsonValue kilometers, - 'owner': EJsonValue owner - } => - Car(fromEJson(make), - model: fromEJson(model), - kilometers: fromEJson(kilometers), - owner: fromEJson(owner)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension CarEJsonEncoderExtension on Car { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeCar(this); -} - -EJsonValue encodePerson(Person value) { - return {'name': value.name.toEJson(), 'age': value.age.toEJson()}; -} - -Person decodePerson(EJsonValue ejson) { - return switch (ejson) { - {'name': EJsonValue name, 'age': EJsonValue age} => - Person(fromEJson(name), age: fromEJson(age)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension PersonEJsonEncoderExtension on Person { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodePerson(this); -} diff --git a/packages/realm/example/lib/main.realm.dart b/packages/realm/example/lib/main.realm.dart index 012f020b4..1849f5bda 100644 --- a/packages/realm/example/lib/main.realm.dart +++ b/packages/realm/example/lib/main.realm.dart @@ -10,7 +10,6 @@ part of 'main.dart'; class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { static var _defaultsSet = false; - @ejson Car( String make, { String? model, @@ -58,10 +57,36 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { @override Car freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeCar(Car value) { + return { + 'make': toEJson(value.make), + 'model': toEJson(value.model), + 'kilometers': toEJson(value.kilometers), + 'owner': toEJson(value.owner), + }; + } + + static Car _decodeCar(EJsonValue ejson) { + return switch (ejson) { + { + 'make': EJsonValue make, + 'model': EJsonValue model, + 'kilometers': EJsonValue kilometers, + 'owner': EJsonValue owner, + } => + Car( + fromEJson(make), + model: fromEJson(model), + kilometers: fromEJson(kilometers), + owner: fromEJson(owner), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Car._); + register(_encodeCar, _decodeCar); return const SchemaObject(ObjectType.realmObject, Car, 'Car', [ SchemaProperty('make', RealmPropertyType.string), SchemaProperty('model', RealmPropertyType.string, optional: true), @@ -69,13 +94,12 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { SchemaProperty('owner', RealmPropertyType.object, optional: true, linkTarget: 'Person'), ]); - } + }(); } class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { static var _defaultsSet = false; - @ejson Person( String name, { int age = 1, @@ -108,13 +132,33 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { @override Person freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodePerson(Person value) { + return { + 'name': toEJson(value.name), + 'age': toEJson(value.age), + }; + } + + static Person _decodePerson(EJsonValue ejson) { + return switch (ejson) { + { + 'name': EJsonValue name, + 'age': EJsonValue age, + } => + Person( + fromEJson(name), + age: fromEJson(age), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Person._); + register(_encodePerson, _decodePerson); return const SchemaObject(ObjectType.realmObject, Person, 'Person', [ SchemaProperty('name', RealmPropertyType.string), SchemaProperty('age', RealmPropertyType.int), ]); - } + }(); } diff --git a/packages/realm_dart/example/bin/myapp.dart b/packages/realm_dart/example/bin/myapp.dart index d96b2cd62..d8b6deb8d 100644 --- a/packages/realm_dart/example/bin/myapp.dart +++ b/packages/realm_dart/example/bin/myapp.dart @@ -6,7 +6,7 @@ import 'dart:io'; import 'package:realm_dart/realm.dart'; part 'myapp.realm.dart'; -part 'myapp.g.dart'; + @RealmModel() class _Car { diff --git a/packages/realm_dart/example/bin/myapp.g.dart b/packages/realm_dart/example/bin/myapp.g.dart deleted file mode 100644 index 93176012c..000000000 --- a/packages/realm_dart/example/bin/myapp.g.dart +++ /dev/null @@ -1,54 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'myapp.dart'; - -// ************************************************************************** -// EJsonGenerator -// ************************************************************************** - -EJsonValue encodeCar(Car value) { - return { - 'make': value.make.toEJson(), - 'model': value.model.toEJson(), - 'kilometers': value.kilometers.toEJson(), - 'owner': value.owner.toEJson() - }; -} - -Car decodeCar(EJsonValue ejson) { - return switch (ejson) { - { - 'make': EJsonValue make, - 'model': EJsonValue model, - 'kilometers': EJsonValue kilometers, - 'owner': EJsonValue owner - } => - Car(fromEJson(make), - model: fromEJson(model), - kilometers: fromEJson(kilometers), - owner: fromEJson(owner)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension CarEJsonEncoderExtension on Car { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeCar(this); -} - -EJsonValue encodePerson(Person value) { - return {'name': value.name.toEJson(), 'age': value.age.toEJson()}; -} - -Person decodePerson(EJsonValue ejson) { - return switch (ejson) { - {'name': EJsonValue name, 'age': EJsonValue age} => - Person(fromEJson(name), age: fromEJson(age)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension PersonEJsonEncoderExtension on Person { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodePerson(this); -} diff --git a/packages/realm_dart/example/bin/myapp.realm.dart b/packages/realm_dart/example/bin/myapp.realm.dart index 28d357c4d..df4cf69bd 100644 --- a/packages/realm_dart/example/bin/myapp.realm.dart +++ b/packages/realm_dart/example/bin/myapp.realm.dart @@ -10,7 +10,6 @@ part of 'myapp.dart'; class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { static var _defaultsSet = false; - @ejson Car( String make, { String? model, @@ -58,10 +57,36 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { @override Car freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeCar(Car value) { + return { + 'make': toEJson(value.make), + 'model': toEJson(value.model), + 'kilometers': toEJson(value.kilometers), + 'owner': toEJson(value.owner), + }; + } + + static Car _decodeCar(EJsonValue ejson) { + return switch (ejson) { + { + 'make': EJsonValue make, + 'model': EJsonValue model, + 'kilometers': EJsonValue kilometers, + 'owner': EJsonValue owner, + } => + Car( + fromEJson(make), + model: fromEJson(model), + kilometers: fromEJson(kilometers), + owner: fromEJson(owner), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Car._); + register(_encodeCar, _decodeCar); return const SchemaObject(ObjectType.realmObject, Car, 'Car', [ SchemaProperty('make', RealmPropertyType.string), SchemaProperty('model', RealmPropertyType.string, optional: true), @@ -69,13 +94,12 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { SchemaProperty('owner', RealmPropertyType.object, optional: true, linkTarget: 'Person'), ]); - } + }(); } class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { static var _defaultsSet = false; - @ejson Person( String name, { int age = 1, @@ -108,13 +132,33 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { @override Person freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodePerson(Person value) { + return { + 'name': toEJson(value.name), + 'age': toEJson(value.age), + }; + } + + static Person _decodePerson(EJsonValue ejson) { + return switch (ejson) { + { + 'name': EJsonValue name, + 'age': EJsonValue age, + } => + Person( + fromEJson(name), + age: fromEJson(age), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Person._); + register(_encodePerson, _decodePerson); return const SchemaObject(ObjectType.realmObject, Person, 'Person', [ SchemaProperty('name', RealmPropertyType.string), SchemaProperty('age', RealmPropertyType.int), ]); - } + }(); } diff --git a/packages/realm_dart/test/backlinks_test.dart b/packages/realm_dart/test/backlinks_test.dart index 29c9ed8ca..1ebe18ea1 100644 --- a/packages/realm_dart/test/backlinks_test.dart +++ b/packages/realm_dart/test/backlinks_test.dart @@ -6,7 +6,7 @@ import 'package:test/test.dart' hide test, throws; import 'test.dart'; -part 'backlinks_test.g.dart'; + part 'backlinks_test.realm.dart'; @RealmModel() diff --git a/packages/realm_dart/test/backlinks_test.g.dart b/packages/realm_dart/test/backlinks_test.g.dart deleted file mode 100644 index b926e7d87..000000000 --- a/packages/realm_dart/test/backlinks_test.g.dart +++ /dev/null @@ -1,58 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'backlinks_test.dart'; - -// ************************************************************************** -// EJsonGenerator -// ************************************************************************** - -EJsonValue encodeSource(Source value) { - return { - 'name': value.name.toEJson(), - 'oneTarget': value.oneTarget.toEJson(), - 'dynamicTarget': value.dynamicTarget.toEJson(), - 'manyTargets': value.manyTargets.toEJson(), - 'dynamicManyTargets': value.dynamicManyTargets.toEJson() - }; -} - -Source decodeSource(EJsonValue ejson) { - return switch (ejson) { - { - 'name': EJsonValue name, - 'oneTarget': EJsonValue oneTarget, - 'dynamicTarget': EJsonValue dynamicTarget, - 'manyTargets': EJsonValue manyTargets, - 'dynamicManyTargets': EJsonValue dynamicManyTargets - } => - Source( - name: fromEJson(name), - oneTarget: fromEJson(oneTarget), - dynamicTarget: fromEJson(dynamicTarget), - manyTargets: fromEJson(manyTargets), - dynamicManyTargets: fromEJson(dynamicManyTargets)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension SourceEJsonEncoderExtension on Source { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeSource(this); -} - -EJsonValue encodeTarget(Target value) { - return {'name': value.name.toEJson(), 'source': value.source.toEJson()}; -} - -Target decodeTarget(EJsonValue ejson) { - return switch (ejson) { - {'name': EJsonValue name, 'source': EJsonValue source} => - Target(name: fromEJson(name), source: fromEJson(source)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension TargetEJsonEncoderExtension on Target { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeTarget(this); -} diff --git a/packages/realm_dart/test/backlinks_test.realm.dart b/packages/realm_dart/test/backlinks_test.realm.dart index 9d374a1a9..e7aeb4113 100644 --- a/packages/realm_dart/test/backlinks_test.realm.dart +++ b/packages/realm_dart/test/backlinks_test.realm.dart @@ -10,7 +10,6 @@ part of 'backlinks_test.dart'; class Source extends _Source with RealmEntity, RealmObjectBase, RealmObject { static var _defaultsSet = false; - @ejson Source({ String name = 'source', Target? oneTarget, @@ -75,10 +74,37 @@ class Source extends _Source with RealmEntity, RealmObjectBase, RealmObject { @override Source freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeSource(Source value) { + return { + 'name': toEJson(value.name), + 'et mål': toEJson(value.oneTarget), + 'manyTargets': toEJson(value.manyTargets), + 'dynamisk mål': toEJson(value.dynamicTarget), + 'dynamicManyTargets': toEJson(value.dynamicManyTargets), + }; + } + + static Source _decodeSource(EJsonValue ejson) { + return switch (ejson) { + { + 'name': EJsonValue name, + 'et mål': EJsonValue oneTarget, + 'manyTargets': EJsonValue manyTargets, + 'dynamisk mål': EJsonValue dynamicTarget, + 'dynamicManyTargets': EJsonValue dynamicManyTargets, + } => + Source( + name: fromEJson(name), + oneTarget: fromEJson(oneTarget), + dynamicTarget: fromEJson(dynamicTarget), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Source._); + register(_encodeSource, _decodeSource); return const SchemaObject(ObjectType.realmObject, Source, 'Source', [ SchemaProperty('name', RealmPropertyType.string), SchemaProperty('oneTarget', RealmPropertyType.object, @@ -90,13 +116,12 @@ class Source extends _Source with RealmEntity, RealmObjectBase, RealmObject { SchemaProperty('dynamicManyTargets', RealmPropertyType.object, linkTarget: 'Target', collectionType: RealmCollectionType.list), ]); - } + }(); } class Target extends _Target with RealmEntity, RealmObjectBase, RealmObject { static var _defaultsSet = false; - @ejson Target({ String name = 'target', Source? source, @@ -156,10 +181,34 @@ class Target extends _Target with RealmEntity, RealmObjectBase, RealmObject { @override Target freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeTarget(Target value) { + return { + 'name': toEJson(value.name), + 'source': toEJson(value.source), + 'oneToMany': toEJson(value.oneToMany), + 'manyToMany': toEJson(value.manyToMany), + }; + } + + static Target _decodeTarget(EJsonValue ejson) { + return switch (ejson) { + { + 'name': EJsonValue name, + 'source': EJsonValue source, + 'oneToMany': EJsonValue oneToMany, + 'manyToMany': EJsonValue manyToMany, + } => + Target( + name: fromEJson(name), + source: fromEJson(source), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Target._); + register(_encodeTarget, _decodeTarget); return const SchemaObject(ObjectType.realmObject, Target, 'Target', [ SchemaProperty('name', RealmPropertyType.string), SchemaProperty('source', RealmPropertyType.object, @@ -173,5 +222,5 @@ class Target extends _Target with RealmEntity, RealmObjectBase, RealmObject { collectionType: RealmCollectionType.list, linkTarget: 'Source'), ]); - } + }(); } diff --git a/packages/realm_dart/test/geospatial_test.dart b/packages/realm_dart/test/geospatial_test.dart index 122a60282..7f921730c 100644 --- a/packages/realm_dart/test/geospatial_test.dart +++ b/packages/realm_dart/test/geospatial_test.dart @@ -10,7 +10,7 @@ import 'package:test/test.dart' hide test, throws; import 'package:realm_dart/realm.dart'; import 'test.dart'; -part 'geospatial_test.g.dart'; + part 'geospatial_test.realm.dart'; @RealmModel(ObjectType.embeddedObject) diff --git a/packages/realm_dart/test/geospatial_test.g.dart b/packages/realm_dart/test/geospatial_test.g.dart deleted file mode 100644 index 395fcb210..000000000 --- a/packages/realm_dart/test/geospatial_test.g.dart +++ /dev/null @@ -1,61 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'geospatial_test.dart'; - -// ************************************************************************** -// EJsonGenerator -// ************************************************************************** - -EJsonValue encodeLocation(Location value) { - return { - 'type': value.type.toEJson(), - 'coordinates': value.coordinates.toEJson() - }; -} - -Location decodeLocation(EJsonValue ejson) { - return switch (ejson) { - {'type': EJsonValue type, 'coordinates': EJsonValue coordinates} => - Location(type: fromEJson(type), coordinates: fromEJson(coordinates)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension LocationEJsonEncoderExtension on Location { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeLocation(this); -} - -EJsonValue encodeRestaurant(Restaurant value) { - return {'name': value.name.toEJson(), 'location': value.location.toEJson()}; -} - -Restaurant decodeRestaurant(EJsonValue ejson) { - return switch (ejson) { - {'name': EJsonValue name, 'location': EJsonValue location} => - Restaurant(fromEJson(name), location: fromEJson(location)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension RestaurantEJsonEncoderExtension on Restaurant { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeRestaurant(this); -} - -EJsonValue encodeLocationList(LocationList value) { - return {'locations': value.locations.toEJson()}; -} - -LocationList decodeLocationList(EJsonValue ejson) { - return switch (ejson) { - {'locations': EJsonValue locations} => - LocationList(locations: fromEJson(locations)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension LocationListEJsonEncoderExtension on LocationList { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeLocationList(this); -} diff --git a/packages/realm_dart/test/geospatial_test.realm.dart b/packages/realm_dart/test/geospatial_test.realm.dart index 6a8a6e2fa..13e0c832c 100644 --- a/packages/realm_dart/test/geospatial_test.realm.dart +++ b/packages/realm_dart/test/geospatial_test.realm.dart @@ -11,7 +11,6 @@ class Location extends _Location with RealmEntity, RealmObjectBase, EmbeddedObject { static var _defaultsSet = false; - @ejson Location({ String type = 'Point', Iterable coordinates = const [], @@ -45,21 +44,39 @@ class Location extends _Location @override Location freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeLocation(Location value) { + return { + 'type': toEJson(value.type), + 'coordinates': toEJson(value.coordinates), + }; + } + + static Location _decodeLocation(EJsonValue ejson) { + return switch (ejson) { + { + 'type': EJsonValue type, + 'coordinates': EJsonValue coordinates, + } => + Location( + type: fromEJson(type), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Location._); + register(_encodeLocation, _decodeLocation); return const SchemaObject(ObjectType.embeddedObject, Location, 'Location', [ SchemaProperty('type', RealmPropertyType.string), SchemaProperty('coordinates', RealmPropertyType.double, collectionType: RealmCollectionType.list), ]); - } + }(); } class Restaurant extends _Restaurant with RealmEntity, RealmObjectBase, RealmObject { - @ejson Restaurant( String name, { Location? location, @@ -89,22 +106,41 @@ class Restaurant extends _Restaurant @override Restaurant freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeRestaurant(Restaurant value) { + return { + 'name': toEJson(value.name), + 'location': toEJson(value.location), + }; + } + + static Restaurant _decodeRestaurant(EJsonValue ejson) { + return switch (ejson) { + { + 'name': EJsonValue name, + 'location': EJsonValue location, + } => + Restaurant( + fromEJson(name), + location: fromEJson(location), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Restaurant._); + register(_encodeRestaurant, _decodeRestaurant); return const SchemaObject( ObjectType.realmObject, Restaurant, 'Restaurant', [ SchemaProperty('name', RealmPropertyType.string, primaryKey: true), SchemaProperty('location', RealmPropertyType.object, optional: true, linkTarget: 'Location'), ]); - } + }(); } class LocationList extends _LocationList with RealmEntity, RealmObjectBase, RealmObject { - @ejson LocationList({ Iterable locations = const [], }) { @@ -128,14 +164,29 @@ class LocationList extends _LocationList @override LocationList freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeLocationList(LocationList value) { + return { + 'locations': toEJson(value.locations), + }; + } + + static LocationList _decodeLocationList(EJsonValue ejson) { + return switch (ejson) { + { + 'locations': EJsonValue locations, + } => + LocationList(), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(LocationList._); + register(_encodeLocationList, _decodeLocationList); return const SchemaObject( ObjectType.realmObject, LocationList, 'LocationList', [ SchemaProperty('locations', RealmPropertyType.object, linkTarget: 'Location', collectionType: RealmCollectionType.list), ]); - } + }(); } diff --git a/packages/realm_dart/test/indexed_test.dart b/packages/realm_dart/test/indexed_test.dart index 0a7868c58..65d1ce7cf 100644 --- a/packages/realm_dart/test/indexed_test.dart +++ b/packages/realm_dart/test/indexed_test.dart @@ -11,7 +11,7 @@ import 'test.dart'; import 'package:realm_dart/realm.dart'; part 'indexed_test.realm.dart'; -part 'indexed_test.g.dart'; + // Don't import our own test.dart here. It will break AOT compilation. // We may use AOT compilation locally to manually run the performance diff --git a/packages/realm_dart/test/indexed_test.g.dart b/packages/realm_dart/test/indexed_test.g.dart deleted file mode 100644 index 8635acbd4..000000000 --- a/packages/realm_dart/test/indexed_test.g.dart +++ /dev/null @@ -1,97 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'indexed_test.dart'; - -// ************************************************************************** -// EJsonGenerator -// ************************************************************************** - -EJsonValue encodeWithIndexes(WithIndexes value) { - return { - 'anInt': value.anInt.toEJson(), - 'aBool': value.aBool.toEJson(), - 'string': value.string.toEJson(), - 'timestamp': value.timestamp.toEJson(), - 'objectId': value.objectId.toEJson(), - 'uuid': value.uuid.toEJson() - }; -} - -WithIndexes decodeWithIndexes(EJsonValue ejson) { - return switch (ejson) { - { - 'anInt': EJsonValue anInt, - 'aBool': EJsonValue aBool, - 'string': EJsonValue string, - 'timestamp': EJsonValue timestamp, - 'objectId': EJsonValue objectId, - 'uuid': EJsonValue uuid - } => - WithIndexes(fromEJson(anInt), fromEJson(aBool), fromEJson(string), - fromEJson(timestamp), fromEJson(objectId), fromEJson(uuid)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension WithIndexesEJsonEncoderExtension on WithIndexes { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeWithIndexes(this); -} - -EJsonValue encodeNoIndexes(NoIndexes value) { - return { - 'anInt': value.anInt.toEJson(), - 'aBool': value.aBool.toEJson(), - 'string': value.string.toEJson(), - 'timestamp': value.timestamp.toEJson(), - 'objectId': value.objectId.toEJson(), - 'uuid': value.uuid.toEJson() - }; -} - -NoIndexes decodeNoIndexes(EJsonValue ejson) { - return switch (ejson) { - { - 'anInt': EJsonValue anInt, - 'aBool': EJsonValue aBool, - 'string': EJsonValue string, - 'timestamp': EJsonValue timestamp, - 'objectId': EJsonValue objectId, - 'uuid': EJsonValue uuid - } => - NoIndexes(fromEJson(anInt), fromEJson(aBool), fromEJson(string), - fromEJson(timestamp), fromEJson(objectId), fromEJson(uuid)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension NoIndexesEJsonEncoderExtension on NoIndexes { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeNoIndexes(this); -} - -EJsonValue encodeObjectWithFTSIndex(ObjectWithFTSIndex value) { - return { - 'title': value.title.toEJson(), - 'summary': value.summary.toEJson(), - 'nullableSummary': value.nullableSummary.toEJson() - }; -} - -ObjectWithFTSIndex decodeObjectWithFTSIndex(EJsonValue ejson) { - return switch (ejson) { - { - 'title': EJsonValue title, - 'summary': EJsonValue summary, - 'nullableSummary': EJsonValue nullableSummary - } => - ObjectWithFTSIndex(fromEJson(title), fromEJson(summary), - nullableSummary: fromEJson(nullableSummary)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension ObjectWithFTSIndexEJsonEncoderExtension on ObjectWithFTSIndex { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeObjectWithFTSIndex(this); -} diff --git a/packages/realm_dart/test/indexed_test.realm.dart b/packages/realm_dart/test/indexed_test.realm.dart index 9d96e92ab..57da726e1 100644 --- a/packages/realm_dart/test/indexed_test.realm.dart +++ b/packages/realm_dart/test/indexed_test.realm.dart @@ -9,7 +9,6 @@ part of 'indexed_test.dart'; // ignore_for_file: type=lint class WithIndexes extends _WithIndexes with RealmEntity, RealmObjectBase, RealmObject { - @ejson WithIndexes( int anInt, bool aBool, @@ -68,10 +67,42 @@ class WithIndexes extends _WithIndexes @override WithIndexes freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeWithIndexes(WithIndexes value) { + return { + 'anInt': toEJson(value.anInt), + 'aBool': toEJson(value.aBool), + 'string': toEJson(value.string), + 'timestamp': toEJson(value.timestamp), + 'objectId': toEJson(value.objectId), + 'uuid': toEJson(value.uuid), + }; + } + + static WithIndexes _decodeWithIndexes(EJsonValue ejson) { + return switch (ejson) { + { + 'anInt': EJsonValue anInt, + 'aBool': EJsonValue aBool, + 'string': EJsonValue string, + 'timestamp': EJsonValue timestamp, + 'objectId': EJsonValue objectId, + 'uuid': EJsonValue uuid, + } => + WithIndexes( + fromEJson(anInt), + fromEJson(aBool), + fromEJson(string), + fromEJson(timestamp), + fromEJson(objectId), + fromEJson(uuid), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(WithIndexes._); + register(_encodeWithIndexes, _decodeWithIndexes); return const SchemaObject( ObjectType.realmObject, WithIndexes, 'WithIndexes', [ SchemaProperty('anInt', RealmPropertyType.int, @@ -87,12 +118,11 @@ class WithIndexes extends _WithIndexes SchemaProperty('uuid', RealmPropertyType.uuid, indexType: RealmIndexType.regular), ]); - } + }(); } class NoIndexes extends _NoIndexes with RealmEntity, RealmObjectBase, RealmObject { - @ejson NoIndexes( int anInt, bool aBool, @@ -151,10 +181,42 @@ class NoIndexes extends _NoIndexes @override NoIndexes freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeNoIndexes(NoIndexes value) { + return { + 'anInt': toEJson(value.anInt), + 'aBool': toEJson(value.aBool), + 'string': toEJson(value.string), + 'timestamp': toEJson(value.timestamp), + 'objectId': toEJson(value.objectId), + 'uuid': toEJson(value.uuid), + }; + } + + static NoIndexes _decodeNoIndexes(EJsonValue ejson) { + return switch (ejson) { + { + 'anInt': EJsonValue anInt, + 'aBool': EJsonValue aBool, + 'string': EJsonValue string, + 'timestamp': EJsonValue timestamp, + 'objectId': EJsonValue objectId, + 'uuid': EJsonValue uuid, + } => + NoIndexes( + fromEJson(anInt), + fromEJson(aBool), + fromEJson(string), + fromEJson(timestamp), + fromEJson(objectId), + fromEJson(uuid), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(NoIndexes._); + register(_encodeNoIndexes, _decodeNoIndexes); return const SchemaObject(ObjectType.realmObject, NoIndexes, 'NoIndexes', [ SchemaProperty('anInt', RealmPropertyType.int), SchemaProperty('aBool', RealmPropertyType.bool), @@ -163,12 +225,11 @@ class NoIndexes extends _NoIndexes SchemaProperty('objectId', RealmPropertyType.objectid), SchemaProperty('uuid', RealmPropertyType.uuid), ]); - } + }(); } class ObjectWithFTSIndex extends _ObjectWithFTSIndex with RealmEntity, RealmObjectBase, RealmObject { - @ejson ObjectWithFTSIndex( String title, String summary, { @@ -206,10 +267,33 @@ class ObjectWithFTSIndex extends _ObjectWithFTSIndex ObjectWithFTSIndex freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeObjectWithFTSIndex(ObjectWithFTSIndex value) { + return { + 'title': toEJson(value.title), + 'summary': toEJson(value.summary), + 'nullableSummary': toEJson(value.nullableSummary), + }; + } + + static ObjectWithFTSIndex _decodeObjectWithFTSIndex(EJsonValue ejson) { + return switch (ejson) { + { + 'title': EJsonValue title, + 'summary': EJsonValue summary, + 'nullableSummary': EJsonValue nullableSummary, + } => + ObjectWithFTSIndex( + fromEJson(title), + fromEJson(summary), + nullableSummary: fromEJson(nullableSummary), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(ObjectWithFTSIndex._); + register(_encodeObjectWithFTSIndex, _decodeObjectWithFTSIndex); return const SchemaObject( ObjectType.realmObject, ObjectWithFTSIndex, 'ObjectWithFTSIndex', [ SchemaProperty('title', RealmPropertyType.string), @@ -218,5 +302,5 @@ class ObjectWithFTSIndex extends _ObjectWithFTSIndex SchemaProperty('nullableSummary', RealmPropertyType.string, optional: true, indexType: RealmIndexType.fullText), ]); - } + }(); } diff --git a/packages/realm_dart/test/migration_test.dart b/packages/realm_dart/test/migration_test.dart index 1807c2969..a3a3a9230 100644 --- a/packages/realm_dart/test/migration_test.dart +++ b/packages/realm_dart/test/migration_test.dart @@ -13,7 +13,7 @@ import 'package:realm_dart/src/realm_object.dart'; import 'package:realm_dart/src/list.dart'; part 'migration_test.realm.dart'; -part 'migration_test.g.dart'; + @RealmModel() @MapTo("Person") diff --git a/packages/realm_dart/test/migration_test.g.dart b/packages/realm_dart/test/migration_test.g.dart deleted file mode 100644 index 13bc99ba4..000000000 --- a/packages/realm_dart/test/migration_test.g.dart +++ /dev/null @@ -1,93 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'migration_test.dart'; - -// ************************************************************************** -// EJsonGenerator -// ************************************************************************** - -EJsonValue encodePersonIntName(PersonIntName value) { - return {'name': value.name.toEJson()}; -} - -PersonIntName decodePersonIntName(EJsonValue ejson) { - return switch (ejson) { - {'name': EJsonValue name} => PersonIntName(fromEJson(name)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension PersonIntNameEJsonEncoderExtension on PersonIntName { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodePersonIntName(this); -} - -EJsonValue encodeStudentV1(StudentV1 value) { - return { - 'name': value.name.toEJson(), - 'yearOfBirth': value.yearOfBirth.toEJson() - }; -} - -StudentV1 decodeStudentV1(EJsonValue ejson) { - return switch (ejson) { - {'name': EJsonValue name, 'yearOfBirth': EJsonValue yearOfBirth} => - StudentV1(fromEJson(name), yearOfBirth: fromEJson(yearOfBirth)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension StudentV1EJsonEncoderExtension on StudentV1 { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeStudentV1(this); -} - -EJsonValue encodeMyObjectWithTypo(MyObjectWithTypo value) { - return {'nmae': value.nmae.toEJson(), 'vlaue': value.vlaue.toEJson()}; -} - -MyObjectWithTypo decodeMyObjectWithTypo(EJsonValue ejson) { - return switch (ejson) { - {'nmae': EJsonValue nmae, 'vlaue': EJsonValue vlaue} => - MyObjectWithTypo(fromEJson(nmae), fromEJson(vlaue)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension MyObjectWithTypoEJsonEncoderExtension on MyObjectWithTypo { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeMyObjectWithTypo(this); -} - -EJsonValue encodeMyObjectWithoutTypo(MyObjectWithoutTypo value) { - return {'name': value.name.toEJson(), 'value': value.value.toEJson()}; -} - -MyObjectWithoutTypo decodeMyObjectWithoutTypo(EJsonValue ejson) { - return switch (ejson) { - {'name': EJsonValue name, 'value': EJsonValue value} => - MyObjectWithoutTypo(fromEJson(name), fromEJson(value)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension MyObjectWithoutTypoEJsonEncoderExtension on MyObjectWithoutTypo { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeMyObjectWithoutTypo(this); -} - -EJsonValue encodeMyObjectWithoutValue(MyObjectWithoutValue value) { - return {'name': value.name.toEJson()}; -} - -MyObjectWithoutValue decodeMyObjectWithoutValue(EJsonValue ejson) { - return switch (ejson) { - {'name': EJsonValue name} => MyObjectWithoutValue(fromEJson(name)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension MyObjectWithoutValueEJsonEncoderExtension on MyObjectWithoutValue { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeMyObjectWithoutValue(this); -} diff --git a/packages/realm_dart/test/migration_test.realm.dart b/packages/realm_dart/test/migration_test.realm.dart index 1eb10017d..3c3b98c01 100644 --- a/packages/realm_dart/test/migration_test.realm.dart +++ b/packages/realm_dart/test/migration_test.realm.dart @@ -9,7 +9,6 @@ part of 'migration_test.dart'; // ignore_for_file: type=lint class PersonIntName extends _PersonIntName with RealmEntity, RealmObjectBase, RealmObject { - @ejson PersonIntName( int name, ) { @@ -30,19 +29,35 @@ class PersonIntName extends _PersonIntName @override PersonIntName freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodePersonIntName(PersonIntName value) { + return { + 'name': toEJson(value.name), + }; + } + + static PersonIntName _decodePersonIntName(EJsonValue ejson) { + return switch (ejson) { + { + 'name': EJsonValue name, + } => + PersonIntName( + fromEJson(name), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(PersonIntName._); + register(_encodePersonIntName, _decodePersonIntName); return const SchemaObject(ObjectType.realmObject, PersonIntName, 'Person', [ SchemaProperty('name', RealmPropertyType.int), ]); - } + }(); } class StudentV1 extends _StudentV1 with RealmEntity, RealmObjectBase, RealmObject { - @ejson StudentV1( String name, { int? yearOfBirth, @@ -71,20 +86,39 @@ class StudentV1 extends _StudentV1 @override StudentV1 freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeStudentV1(StudentV1 value) { + return { + 'name': toEJson(value.name), + 'yearOfBirth': toEJson(value.yearOfBirth), + }; + } + + static StudentV1 _decodeStudentV1(EJsonValue ejson) { + return switch (ejson) { + { + 'name': EJsonValue name, + 'yearOfBirth': EJsonValue yearOfBirth, + } => + StudentV1( + fromEJson(name), + yearOfBirth: fromEJson(yearOfBirth), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(StudentV1._); + register(_encodeStudentV1, _decodeStudentV1); return const SchemaObject(ObjectType.realmObject, StudentV1, 'Student', [ SchemaProperty('name', RealmPropertyType.string, primaryKey: true), SchemaProperty('yearOfBirth', RealmPropertyType.int, optional: true), ]); - } + }(); } class MyObjectWithTypo extends _MyObjectWithTypo with RealmEntity, RealmObjectBase, RealmObject { - @ejson MyObjectWithTypo( String nmae, int vlaue, @@ -113,21 +147,40 @@ class MyObjectWithTypo extends _MyObjectWithTypo MyObjectWithTypo freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeMyObjectWithTypo(MyObjectWithTypo value) { + return { + 'nmae': toEJson(value.nmae), + 'vlaue': toEJson(value.vlaue), + }; + } + + static MyObjectWithTypo _decodeMyObjectWithTypo(EJsonValue ejson) { + return switch (ejson) { + { + 'nmae': EJsonValue nmae, + 'vlaue': EJsonValue vlaue, + } => + MyObjectWithTypo( + fromEJson(nmae), + fromEJson(vlaue), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(MyObjectWithTypo._); + register(_encodeMyObjectWithTypo, _decodeMyObjectWithTypo); return const SchemaObject( ObjectType.realmObject, MyObjectWithTypo, 'MyObject', [ SchemaProperty('nmae', RealmPropertyType.string), SchemaProperty('vlaue', RealmPropertyType.int), ]); - } + }(); } class MyObjectWithoutTypo extends _MyObjectWithoutTypo with RealmEntity, RealmObjectBase, RealmObject { - @ejson MyObjectWithoutTypo( String name, int value, @@ -156,21 +209,40 @@ class MyObjectWithoutTypo extends _MyObjectWithoutTypo MyObjectWithoutTypo freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeMyObjectWithoutTypo(MyObjectWithoutTypo value) { + return { + 'name': toEJson(value.name), + 'value': toEJson(value.value), + }; + } + + static MyObjectWithoutTypo _decodeMyObjectWithoutTypo(EJsonValue ejson) { + return switch (ejson) { + { + 'name': EJsonValue name, + 'value': EJsonValue value, + } => + MyObjectWithoutTypo( + fromEJson(name), + fromEJson(value), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(MyObjectWithoutTypo._); + register(_encodeMyObjectWithoutTypo, _decodeMyObjectWithoutTypo); return const SchemaObject( ObjectType.realmObject, MyObjectWithoutTypo, 'MyObject', [ SchemaProperty('name', RealmPropertyType.string), SchemaProperty('value', RealmPropertyType.int), ]); - } + }(); } class MyObjectWithoutValue extends _MyObjectWithoutValue with RealmEntity, RealmObjectBase, RealmObject { - @ejson MyObjectWithoutValue( String name, ) { @@ -192,13 +264,30 @@ class MyObjectWithoutValue extends _MyObjectWithoutValue MyObjectWithoutValue freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeMyObjectWithoutValue(MyObjectWithoutValue value) { + return { + 'name': toEJson(value.name), + }; + } + + static MyObjectWithoutValue _decodeMyObjectWithoutValue(EJsonValue ejson) { + return switch (ejson) { + { + 'name': EJsonValue name, + } => + MyObjectWithoutValue( + fromEJson(name), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(MyObjectWithoutValue._); + register(_encodeMyObjectWithoutValue, _decodeMyObjectWithoutValue); return const SchemaObject( ObjectType.realmObject, MyObjectWithoutValue, 'MyObject', [ SchemaProperty('name', RealmPropertyType.string), ]); - } + }(); } diff --git a/packages/realm_dart/test/realm_map_test.dart b/packages/realm_dart/test/realm_map_test.dart index 51d6623cf..d4960daf5 100644 --- a/packages/realm_dart/test/realm_map_test.dart +++ b/packages/realm_dart/test/realm_map_test.dart @@ -12,7 +12,7 @@ import 'package:realm_dart/realm.dart'; import 'test.dart'; -part 'realm_map_test.g.dart'; + part 'realm_map_test.realm.dart'; @RealmModel() diff --git a/packages/realm_dart/test/realm_map_test.g.dart b/packages/realm_dart/test/realm_map_test.g.dart deleted file mode 100644 index 4d6fcdd41..000000000 --- a/packages/realm_dart/test/realm_map_test.g.dart +++ /dev/null @@ -1,124 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'realm_map_test.dart'; - -// ************************************************************************** -// EJsonGenerator -// ************************************************************************** - -EJsonValue encodeCar(Car value) { - return {'make': value.make.toEJson(), 'color': value.color.toEJson()}; -} - -Car decodeCar(EJsonValue ejson) { - return switch (ejson) { - {'make': EJsonValue make, 'color': EJsonValue color} => - Car(fromEJson(make), color: fromEJson(color)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension CarEJsonEncoderExtension on Car { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeCar(this); -} - -EJsonValue encodeEmbeddedValue(EmbeddedValue value) { - return {'intValue': value.intValue.toEJson()}; -} - -EmbeddedValue decodeEmbeddedValue(EJsonValue ejson) { - return switch (ejson) { - {'intValue': EJsonValue intValue} => EmbeddedValue(fromEJson(intValue)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension EmbeddedValueEJsonEncoderExtension on EmbeddedValue { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeEmbeddedValue(this); -} - -EJsonValue encodeTestRealmMaps(TestRealmMaps value) { - return { - 'key': value.key.toEJson(), - 'boolMap': value.boolMap.toEJson(), - 'intMap': value.intMap.toEJson(), - 'stringMap': value.stringMap.toEJson(), - 'doubleMap': value.doubleMap.toEJson(), - 'dateTimeMap': value.dateTimeMap.toEJson(), - 'objectIdMap': value.objectIdMap.toEJson(), - 'uuidMap': value.uuidMap.toEJson(), - 'binaryMap': value.binaryMap.toEJson(), - 'decimalMap': value.decimalMap.toEJson(), - 'nullableBoolMap': value.nullableBoolMap.toEJson(), - 'nullableIntMap': value.nullableIntMap.toEJson(), - 'nullableStringMap': value.nullableStringMap.toEJson(), - 'nullableDoubleMap': value.nullableDoubleMap.toEJson(), - 'nullableDateTimeMap': value.nullableDateTimeMap.toEJson(), - 'nullableObjectIdMap': value.nullableObjectIdMap.toEJson(), - 'nullableUuidMap': value.nullableUuidMap.toEJson(), - 'nullableBinaryMap': value.nullableBinaryMap.toEJson(), - 'nullableDecimalMap': value.nullableDecimalMap.toEJson(), - 'objectsMap': value.objectsMap.toEJson(), - 'embeddedMap': value.embeddedMap.toEJson(), - 'mixedMap': value.mixedMap.toEJson() - }; -} - -TestRealmMaps decodeTestRealmMaps(EJsonValue ejson) { - return switch (ejson) { - { - 'key': EJsonValue key, - 'boolMap': EJsonValue boolMap, - 'intMap': EJsonValue intMap, - 'stringMap': EJsonValue stringMap, - 'doubleMap': EJsonValue doubleMap, - 'dateTimeMap': EJsonValue dateTimeMap, - 'objectIdMap': EJsonValue objectIdMap, - 'uuidMap': EJsonValue uuidMap, - 'binaryMap': EJsonValue binaryMap, - 'decimalMap': EJsonValue decimalMap, - 'nullableBoolMap': EJsonValue nullableBoolMap, - 'nullableIntMap': EJsonValue nullableIntMap, - 'nullableStringMap': EJsonValue nullableStringMap, - 'nullableDoubleMap': EJsonValue nullableDoubleMap, - 'nullableDateTimeMap': EJsonValue nullableDateTimeMap, - 'nullableObjectIdMap': EJsonValue nullableObjectIdMap, - 'nullableUuidMap': EJsonValue nullableUuidMap, - 'nullableBinaryMap': EJsonValue nullableBinaryMap, - 'nullableDecimalMap': EJsonValue nullableDecimalMap, - 'objectsMap': EJsonValue objectsMap, - 'embeddedMap': EJsonValue embeddedMap, - 'mixedMap': EJsonValue mixedMap - } => - TestRealmMaps(fromEJson(key), - boolMap: fromEJson(boolMap), - intMap: fromEJson(intMap), - stringMap: fromEJson(stringMap), - doubleMap: fromEJson(doubleMap), - dateTimeMap: fromEJson(dateTimeMap), - objectIdMap: fromEJson(objectIdMap), - uuidMap: fromEJson(uuidMap), - binaryMap: fromEJson(binaryMap), - decimalMap: fromEJson(decimalMap), - nullableBoolMap: fromEJson(nullableBoolMap), - nullableIntMap: fromEJson(nullableIntMap), - nullableStringMap: fromEJson(nullableStringMap), - nullableDoubleMap: fromEJson(nullableDoubleMap), - nullableDateTimeMap: fromEJson(nullableDateTimeMap), - nullableObjectIdMap: fromEJson(nullableObjectIdMap), - nullableUuidMap: fromEJson(nullableUuidMap), - nullableBinaryMap: fromEJson(nullableBinaryMap), - nullableDecimalMap: fromEJson(nullableDecimalMap), - objectsMap: fromEJson(objectsMap), - embeddedMap: fromEJson(embeddedMap), - mixedMap: fromEJson(mixedMap)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension TestRealmMapsEJsonEncoderExtension on TestRealmMaps { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeTestRealmMaps(this); -} diff --git a/packages/realm_dart/test/realm_map_test.realm.dart b/packages/realm_dart/test/realm_map_test.realm.dart index 0175b3099..748061bf3 100644 --- a/packages/realm_dart/test/realm_map_test.realm.dart +++ b/packages/realm_dart/test/realm_map_test.realm.dart @@ -8,7 +8,6 @@ part of 'realm_map_test.dart'; // ignore_for_file: type=lint class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { - @ejson Car( String make, { String? color, @@ -36,20 +35,39 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { @override Car freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeCar(Car value) { + return { + 'make': toEJson(value.make), + 'color': toEJson(value.color), + }; + } + + static Car _decodeCar(EJsonValue ejson) { + return switch (ejson) { + { + 'make': EJsonValue make, + 'color': EJsonValue color, + } => + Car( + fromEJson(make), + color: fromEJson(color), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Car._); + register(_encodeCar, _decodeCar); return const SchemaObject(ObjectType.realmObject, Car, 'Car', [ SchemaProperty('make', RealmPropertyType.string, primaryKey: true), SchemaProperty('color', RealmPropertyType.string, optional: true), ]); - } + }(); } class EmbeddedValue extends _EmbeddedValue with RealmEntity, RealmObjectBase, EmbeddedObject { - @ejson EmbeddedValue( int intValue, ) { @@ -70,20 +88,36 @@ class EmbeddedValue extends _EmbeddedValue @override EmbeddedValue freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeEmbeddedValue(EmbeddedValue value) { + return { + 'intValue': toEJson(value.intValue), + }; + } + + static EmbeddedValue _decodeEmbeddedValue(EJsonValue ejson) { + return switch (ejson) { + { + 'intValue': EJsonValue intValue, + } => + EmbeddedValue( + fromEJson(intValue), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(EmbeddedValue._); + register(_encodeEmbeddedValue, _decodeEmbeddedValue); return const SchemaObject( ObjectType.embeddedObject, EmbeddedValue, 'EmbeddedValue', [ SchemaProperty('intValue', RealmPropertyType.int), ]); - } + }(); } class TestRealmMaps extends _TestRealmMaps with RealmEntity, RealmObjectBase, RealmObject { - @ejson TestRealmMaps( int key, { Map boolMap = const {}, @@ -320,10 +354,69 @@ class TestRealmMaps extends _TestRealmMaps @override TestRealmMaps freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeTestRealmMaps(TestRealmMaps value) { + return { + 'key': toEJson(value.key), + 'boolMap': toEJson(value.boolMap), + 'intMap': toEJson(value.intMap), + 'stringMap': toEJson(value.stringMap), + 'doubleMap': toEJson(value.doubleMap), + 'dateTimeMap': toEJson(value.dateTimeMap), + 'objectIdMap': toEJson(value.objectIdMap), + 'uuidMap': toEJson(value.uuidMap), + 'binaryMap': toEJson(value.binaryMap), + 'decimalMap': toEJson(value.decimalMap), + 'nullableBoolMap': toEJson(value.nullableBoolMap), + 'nullableIntMap': toEJson(value.nullableIntMap), + 'nullableStringMap': toEJson(value.nullableStringMap), + 'nullableDoubleMap': toEJson(value.nullableDoubleMap), + 'nullableDateTimeMap': toEJson(value.nullableDateTimeMap), + 'nullableObjectIdMap': toEJson(value.nullableObjectIdMap), + 'nullableUuidMap': toEJson(value.nullableUuidMap), + 'nullableBinaryMap': toEJson(value.nullableBinaryMap), + 'nullableDecimalMap': toEJson(value.nullableDecimalMap), + 'objectsMap': toEJson(value.objectsMap), + 'embeddedMap': toEJson(value.embeddedMap), + 'mixedMap': toEJson(value.mixedMap), + }; + } + + static TestRealmMaps _decodeTestRealmMaps(EJsonValue ejson) { + return switch (ejson) { + { + 'key': EJsonValue key, + 'boolMap': EJsonValue boolMap, + 'intMap': EJsonValue intMap, + 'stringMap': EJsonValue stringMap, + 'doubleMap': EJsonValue doubleMap, + 'dateTimeMap': EJsonValue dateTimeMap, + 'objectIdMap': EJsonValue objectIdMap, + 'uuidMap': EJsonValue uuidMap, + 'binaryMap': EJsonValue binaryMap, + 'decimalMap': EJsonValue decimalMap, + 'nullableBoolMap': EJsonValue nullableBoolMap, + 'nullableIntMap': EJsonValue nullableIntMap, + 'nullableStringMap': EJsonValue nullableStringMap, + 'nullableDoubleMap': EJsonValue nullableDoubleMap, + 'nullableDateTimeMap': EJsonValue nullableDateTimeMap, + 'nullableObjectIdMap': EJsonValue nullableObjectIdMap, + 'nullableUuidMap': EJsonValue nullableUuidMap, + 'nullableBinaryMap': EJsonValue nullableBinaryMap, + 'nullableDecimalMap': EJsonValue nullableDecimalMap, + 'objectsMap': EJsonValue objectsMap, + 'embeddedMap': EJsonValue embeddedMap, + 'mixedMap': EJsonValue mixedMap, + } => + TestRealmMaps( + fromEJson(key), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(TestRealmMaps._); + register(_encodeTestRealmMaps, _decodeTestRealmMaps); return const SchemaObject( ObjectType.realmObject, TestRealmMaps, 'TestRealmMaps', [ SchemaProperty('key', RealmPropertyType.int, primaryKey: true), @@ -374,5 +467,5 @@ class TestRealmMaps extends _TestRealmMaps SchemaProperty('mixedMap', RealmPropertyType.mixed, optional: true, collectionType: RealmCollectionType.map), ]); - } + }(); } diff --git a/packages/realm_dart/test/realm_object_test.dart b/packages/realm_dart/test/realm_object_test.dart index 0f13e7a44..260ed2152 100644 --- a/packages/realm_dart/test/realm_object_test.dart +++ b/packages/realm_dart/test/realm_object_test.dart @@ -11,7 +11,7 @@ import 'package:realm_dart/realm.dart'; import 'test.dart'; part 'realm_object_test.realm.dart'; -part 'realm_object_test.g.dart'; + @RealmModel() class _ObjectIdPrimaryKey { diff --git a/packages/realm_dart/test/realm_object_test.g.dart b/packages/realm_dart/test/realm_object_test.g.dart deleted file mode 100644 index ee419acde..000000000 --- a/packages/realm_dart/test/realm_object_test.g.dart +++ /dev/null @@ -1,174 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'realm_object_test.dart'; - -// ************************************************************************** -// EJsonGenerator -// ************************************************************************** - -EJsonValue encodeObjectIdPrimaryKey(ObjectIdPrimaryKey value) { - return {'id': value.id.toEJson()}; -} - -ObjectIdPrimaryKey decodeObjectIdPrimaryKey(EJsonValue ejson) { - return switch (ejson) { - {'id': EJsonValue id} => ObjectIdPrimaryKey(fromEJson(id)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension ObjectIdPrimaryKeyEJsonEncoderExtension on ObjectIdPrimaryKey { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeObjectIdPrimaryKey(this); -} - -EJsonValue encodeNullableObjectIdPrimaryKey(NullableObjectIdPrimaryKey value) { - return {'id': value.id.toEJson()}; -} - -NullableObjectIdPrimaryKey decodeNullableObjectIdPrimaryKey(EJsonValue ejson) { - return switch (ejson) { - {'id': EJsonValue id} => NullableObjectIdPrimaryKey(fromEJson(id)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension NullableObjectIdPrimaryKeyEJsonEncoderExtension - on NullableObjectIdPrimaryKey { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeNullableObjectIdPrimaryKey(this); -} - -EJsonValue encodeIntPrimaryKey(IntPrimaryKey value) { - return {'id': value.id.toEJson()}; -} - -IntPrimaryKey decodeIntPrimaryKey(EJsonValue ejson) { - return switch (ejson) { - {'id': EJsonValue id} => IntPrimaryKey(fromEJson(id)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension IntPrimaryKeyEJsonEncoderExtension on IntPrimaryKey { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeIntPrimaryKey(this); -} - -EJsonValue encodeNullableIntPrimaryKey(NullableIntPrimaryKey value) { - return {'id': value.id.toEJson()}; -} - -NullableIntPrimaryKey decodeNullableIntPrimaryKey(EJsonValue ejson) { - return switch (ejson) { - {'id': EJsonValue id} => NullableIntPrimaryKey(fromEJson(id)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension NullableIntPrimaryKeyEJsonEncoderExtension on NullableIntPrimaryKey { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeNullableIntPrimaryKey(this); -} - -EJsonValue encodeStringPrimaryKey(StringPrimaryKey value) { - return {'id': value.id.toEJson()}; -} - -StringPrimaryKey decodeStringPrimaryKey(EJsonValue ejson) { - return switch (ejson) { - {'id': EJsonValue id} => StringPrimaryKey(fromEJson(id)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension StringPrimaryKeyEJsonEncoderExtension on StringPrimaryKey { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeStringPrimaryKey(this); -} - -EJsonValue encodeNullableStringPrimaryKey(NullableStringPrimaryKey value) { - return {'id': value.id.toEJson()}; -} - -NullableStringPrimaryKey decodeNullableStringPrimaryKey(EJsonValue ejson) { - return switch (ejson) { - {'id': EJsonValue id} => NullableStringPrimaryKey(fromEJson(id)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension NullableStringPrimaryKeyEJsonEncoderExtension - on NullableStringPrimaryKey { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeNullableStringPrimaryKey(this); -} - -EJsonValue encodeUuidPrimaryKey(UuidPrimaryKey value) { - return {'id': value.id.toEJson()}; -} - -UuidPrimaryKey decodeUuidPrimaryKey(EJsonValue ejson) { - return switch (ejson) { - {'id': EJsonValue id} => UuidPrimaryKey(fromEJson(id)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension UuidPrimaryKeyEJsonEncoderExtension on UuidPrimaryKey { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeUuidPrimaryKey(this); -} - -EJsonValue encodeNullableUuidPrimaryKey(NullableUuidPrimaryKey value) { - return {'id': value.id.toEJson()}; -} - -NullableUuidPrimaryKey decodeNullableUuidPrimaryKey(EJsonValue ejson) { - return switch (ejson) { - {'id': EJsonValue id} => NullableUuidPrimaryKey(fromEJson(id)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension NullableUuidPrimaryKeyEJsonEncoderExtension - on NullableUuidPrimaryKey { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeNullableUuidPrimaryKey(this); -} - -EJsonValue encodeRemappedFromAnotherFile(RemappedFromAnotherFile value) { - return {'linkToAnotherClass': value.linkToAnotherClass.toEJson()}; -} - -RemappedFromAnotherFile decodeRemappedFromAnotherFile(EJsonValue ejson) { - return switch (ejson) { - {'linkToAnotherClass': EJsonValue linkToAnotherClass} => - RemappedFromAnotherFile( - linkToAnotherClass: fromEJson(linkToAnotherClass)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension RemappedFromAnotherFileEJsonEncoderExtension - on RemappedFromAnotherFile { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeRemappedFromAnotherFile(this); -} - -EJsonValue encodeBoolValue(BoolValue value) { - return {'key': value.key.toEJson(), 'value': value.value.toEJson()}; -} - -BoolValue decodeBoolValue(EJsonValue ejson) { - return switch (ejson) { - {'key': EJsonValue key, 'value': EJsonValue value} => - BoolValue(fromEJson(key), fromEJson(value)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension BoolValueEJsonEncoderExtension on BoolValue { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeBoolValue(this); -} diff --git a/packages/realm_dart/test/realm_object_test.realm.dart b/packages/realm_dart/test/realm_object_test.realm.dart index c55b72bdd..14db8fac7 100644 --- a/packages/realm_dart/test/realm_object_test.realm.dart +++ b/packages/realm_dart/test/realm_object_test.realm.dart @@ -9,7 +9,6 @@ part of 'realm_object_test.dart'; // ignore_for_file: type=lint class ObjectIdPrimaryKey extends _ObjectIdPrimaryKey with RealmEntity, RealmObjectBase, RealmObject { - @ejson ObjectIdPrimaryKey( ObjectId id, ) { @@ -31,20 +30,36 @@ class ObjectIdPrimaryKey extends _ObjectIdPrimaryKey ObjectIdPrimaryKey freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeObjectIdPrimaryKey(ObjectIdPrimaryKey value) { + return { + 'id': toEJson(value.id), + }; + } + + static ObjectIdPrimaryKey _decodeObjectIdPrimaryKey(EJsonValue ejson) { + return switch (ejson) { + { + 'id': EJsonValue id, + } => + ObjectIdPrimaryKey( + fromEJson(id), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(ObjectIdPrimaryKey._); + register(_encodeObjectIdPrimaryKey, _decodeObjectIdPrimaryKey); return const SchemaObject( ObjectType.realmObject, ObjectIdPrimaryKey, 'ObjectIdPrimaryKey', [ SchemaProperty('id', RealmPropertyType.objectid, primaryKey: true), ]); - } + }(); } class NullableObjectIdPrimaryKey extends _NullableObjectIdPrimaryKey with RealmEntity, RealmObjectBase, RealmObject { - @ejson NullableObjectIdPrimaryKey( ObjectId? id, ) { @@ -66,21 +81,40 @@ class NullableObjectIdPrimaryKey extends _NullableObjectIdPrimaryKey NullableObjectIdPrimaryKey freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeNullableObjectIdPrimaryKey( + NullableObjectIdPrimaryKey value) { + return { + 'id': toEJson(value.id), + }; + } + + static NullableObjectIdPrimaryKey _decodeNullableObjectIdPrimaryKey( + EJsonValue ejson) { + return switch (ejson) { + { + 'id': EJsonValue id, + } => + NullableObjectIdPrimaryKey( + fromEJson(id), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(NullableObjectIdPrimaryKey._); + register( + _encodeNullableObjectIdPrimaryKey, _decodeNullableObjectIdPrimaryKey); return const SchemaObject(ObjectType.realmObject, NullableObjectIdPrimaryKey, 'NullableObjectIdPrimaryKey', [ SchemaProperty('id', RealmPropertyType.objectid, optional: true, primaryKey: true), ]); - } + }(); } class IntPrimaryKey extends _IntPrimaryKey with RealmEntity, RealmObjectBase, RealmObject { - @ejson IntPrimaryKey( int id, ) { @@ -101,20 +135,36 @@ class IntPrimaryKey extends _IntPrimaryKey @override IntPrimaryKey freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeIntPrimaryKey(IntPrimaryKey value) { + return { + 'id': toEJson(value.id), + }; + } + + static IntPrimaryKey _decodeIntPrimaryKey(EJsonValue ejson) { + return switch (ejson) { + { + 'id': EJsonValue id, + } => + IntPrimaryKey( + fromEJson(id), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(IntPrimaryKey._); + register(_encodeIntPrimaryKey, _decodeIntPrimaryKey); return const SchemaObject( ObjectType.realmObject, IntPrimaryKey, 'IntPrimaryKey', [ SchemaProperty('id', RealmPropertyType.int, primaryKey: true), ]); - } + }(); } class NullableIntPrimaryKey extends _NullableIntPrimaryKey with RealmEntity, RealmObjectBase, RealmObject { - @ejson NullableIntPrimaryKey( int? id, ) { @@ -136,21 +186,37 @@ class NullableIntPrimaryKey extends _NullableIntPrimaryKey NullableIntPrimaryKey freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeNullableIntPrimaryKey(NullableIntPrimaryKey value) { + return { + 'id': toEJson(value.id), + }; + } + + static NullableIntPrimaryKey _decodeNullableIntPrimaryKey(EJsonValue ejson) { + return switch (ejson) { + { + 'id': EJsonValue id, + } => + NullableIntPrimaryKey( + fromEJson(id), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(NullableIntPrimaryKey._); + register(_encodeNullableIntPrimaryKey, _decodeNullableIntPrimaryKey); return const SchemaObject(ObjectType.realmObject, NullableIntPrimaryKey, 'NullableIntPrimaryKey', [ SchemaProperty('id', RealmPropertyType.int, optional: true, primaryKey: true), ]); - } + }(); } class StringPrimaryKey extends _StringPrimaryKey with RealmEntity, RealmObjectBase, RealmObject { - @ejson StringPrimaryKey( String id, ) { @@ -172,20 +238,36 @@ class StringPrimaryKey extends _StringPrimaryKey StringPrimaryKey freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeStringPrimaryKey(StringPrimaryKey value) { + return { + 'id': toEJson(value.id), + }; + } + + static StringPrimaryKey _decodeStringPrimaryKey(EJsonValue ejson) { + return switch (ejson) { + { + 'id': EJsonValue id, + } => + StringPrimaryKey( + fromEJson(id), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(StringPrimaryKey._); + register(_encodeStringPrimaryKey, _decodeStringPrimaryKey); return const SchemaObject( ObjectType.realmObject, StringPrimaryKey, 'StringPrimaryKey', [ SchemaProperty('id', RealmPropertyType.string, primaryKey: true), ]); - } + }(); } class NullableStringPrimaryKey extends _NullableStringPrimaryKey with RealmEntity, RealmObjectBase, RealmObject { - @ejson NullableStringPrimaryKey( String? id, ) { @@ -207,21 +289,39 @@ class NullableStringPrimaryKey extends _NullableStringPrimaryKey NullableStringPrimaryKey freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeNullableStringPrimaryKey( + NullableStringPrimaryKey value) { + return { + 'id': toEJson(value.id), + }; + } + + static NullableStringPrimaryKey _decodeNullableStringPrimaryKey( + EJsonValue ejson) { + return switch (ejson) { + { + 'id': EJsonValue id, + } => + NullableStringPrimaryKey( + fromEJson(id), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(NullableStringPrimaryKey._); + register(_encodeNullableStringPrimaryKey, _decodeNullableStringPrimaryKey); return const SchemaObject(ObjectType.realmObject, NullableStringPrimaryKey, 'NullableStringPrimaryKey', [ SchemaProperty('id', RealmPropertyType.string, optional: true, primaryKey: true), ]); - } + }(); } class UuidPrimaryKey extends _UuidPrimaryKey with RealmEntity, RealmObjectBase, RealmObject { - @ejson UuidPrimaryKey( Uuid id, ) { @@ -242,20 +342,36 @@ class UuidPrimaryKey extends _UuidPrimaryKey @override UuidPrimaryKey freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeUuidPrimaryKey(UuidPrimaryKey value) { + return { + 'id': toEJson(value.id), + }; + } + + static UuidPrimaryKey _decodeUuidPrimaryKey(EJsonValue ejson) { + return switch (ejson) { + { + 'id': EJsonValue id, + } => + UuidPrimaryKey( + fromEJson(id), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(UuidPrimaryKey._); + register(_encodeUuidPrimaryKey, _decodeUuidPrimaryKey); return const SchemaObject( ObjectType.realmObject, UuidPrimaryKey, 'UuidPrimaryKey', [ SchemaProperty('id', RealmPropertyType.uuid, primaryKey: true), ]); - } + }(); } class NullableUuidPrimaryKey extends _NullableUuidPrimaryKey with RealmEntity, RealmObjectBase, RealmObject { - @ejson NullableUuidPrimaryKey( Uuid? id, ) { @@ -277,21 +393,39 @@ class NullableUuidPrimaryKey extends _NullableUuidPrimaryKey NullableUuidPrimaryKey freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeNullableUuidPrimaryKey( + NullableUuidPrimaryKey value) { + return { + 'id': toEJson(value.id), + }; + } + + static NullableUuidPrimaryKey _decodeNullableUuidPrimaryKey( + EJsonValue ejson) { + return switch (ejson) { + { + 'id': EJsonValue id, + } => + NullableUuidPrimaryKey( + fromEJson(id), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(NullableUuidPrimaryKey._); + register(_encodeNullableUuidPrimaryKey, _decodeNullableUuidPrimaryKey); return const SchemaObject(ObjectType.realmObject, NullableUuidPrimaryKey, 'NullableUuidPrimaryKey', [ SchemaProperty('id', RealmPropertyType.uuid, optional: true, primaryKey: true), ]); - } + }(); } class RemappedFromAnotherFile extends _RemappedFromAnotherFile with RealmEntity, RealmObjectBase, RealmObject { - @ejson RemappedFromAnotherFile({ RemappedClass? linkToAnotherClass, }) { @@ -316,10 +450,29 @@ class RemappedFromAnotherFile extends _RemappedFromAnotherFile RemappedFromAnotherFile freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeRemappedFromAnotherFile( + RemappedFromAnotherFile value) { + return { + 'property with spaces': toEJson(value.linkToAnotherClass), + }; + } + + static RemappedFromAnotherFile _decodeRemappedFromAnotherFile( + EJsonValue ejson) { + return switch (ejson) { + { + 'property with spaces': EJsonValue linkToAnotherClass, + } => + RemappedFromAnotherFile( + linkToAnotherClass: fromEJson(linkToAnotherClass), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(RemappedFromAnotherFile._); + register(_encodeRemappedFromAnotherFile, _decodeRemappedFromAnotherFile); return const SchemaObject( ObjectType.realmObject, RemappedFromAnotherFile, 'class with spaces', [ SchemaProperty('linkToAnotherClass', RealmPropertyType.object, @@ -327,12 +480,11 @@ class RemappedFromAnotherFile extends _RemappedFromAnotherFile optional: true, linkTarget: 'myRemappedClass'), ]); - } + }(); } class BoolValue extends _BoolValue with RealmEntity, RealmObjectBase, RealmObject { - @ejson BoolValue( int key, bool value, @@ -360,13 +512,33 @@ class BoolValue extends _BoolValue @override BoolValue freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeBoolValue(BoolValue value) { + return { + 'key': toEJson(value.key), + 'value': toEJson(value.value), + }; + } + + static BoolValue _decodeBoolValue(EJsonValue ejson) { + return switch (ejson) { + { + 'key': EJsonValue key, + 'value': EJsonValue value, + } => + BoolValue( + fromEJson(key), + fromEJson(value), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(BoolValue._); + register(_encodeBoolValue, _decodeBoolValue); return const SchemaObject(ObjectType.realmObject, BoolValue, 'BoolValue', [ SchemaProperty('key', RealmPropertyType.int, primaryKey: true), SchemaProperty('value', RealmPropertyType.bool), ]); - } + }(); } diff --git a/packages/realm_dart/test/realm_set_test.dart b/packages/realm_dart/test/realm_set_test.dart index a13bf0088..9aa4e4500 100644 --- a/packages/realm_dart/test/realm_set_test.dart +++ b/packages/realm_dart/test/realm_set_test.dart @@ -9,7 +9,7 @@ import 'package:test/test.dart' hide test, throws; import 'test.dart'; -part 'realm_set_test.g.dart'; + part 'realm_set_test.realm.dart'; class _NullableBool {} diff --git a/packages/realm_dart/test/realm_set_test.g.dart b/packages/realm_dart/test/realm_set_test.g.dart deleted file mode 100644 index cbf839ef3..000000000 --- a/packages/realm_dart/test/realm_set_test.g.dart +++ /dev/null @@ -1,99 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'realm_set_test.dart'; - -// ************************************************************************** -// EJsonGenerator -// ************************************************************************** - -EJsonValue encodeCar(Car value) { - return {'make': value.make.toEJson(), 'color': value.color.toEJson()}; -} - -Car decodeCar(EJsonValue ejson) { - return switch (ejson) { - {'make': EJsonValue make, 'color': EJsonValue color} => - Car(fromEJson(make), color: fromEJson(color)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension CarEJsonEncoderExtension on Car { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeCar(this); -} - -EJsonValue encodeTestRealmSets(TestRealmSets value) { - return { - 'key': value.key.toEJson(), - 'boolSet': value.boolSet.toEJson(), - 'intSet': value.intSet.toEJson(), - 'stringSet': value.stringSet.toEJson(), - 'doubleSet': value.doubleSet.toEJson(), - 'dateTimeSet': value.dateTimeSet.toEJson(), - 'objectIdSet': value.objectIdSet.toEJson(), - 'uuidSet': value.uuidSet.toEJson(), - 'mixedSet': value.mixedSet.toEJson(), - 'objectsSet': value.objectsSet.toEJson(), - 'binarySet': value.binarySet.toEJson(), - 'nullableBoolSet': value.nullableBoolSet.toEJson(), - 'nullableIntSet': value.nullableIntSet.toEJson(), - 'nullableStringSet': value.nullableStringSet.toEJson(), - 'nullableDoubleSet': value.nullableDoubleSet.toEJson(), - 'nullableDateTimeSet': value.nullableDateTimeSet.toEJson(), - 'nullableObjectIdSet': value.nullableObjectIdSet.toEJson(), - 'nullableUuidSet': value.nullableUuidSet.toEJson(), - 'nullableBinarySet': value.nullableBinarySet.toEJson() - }; -} - -TestRealmSets decodeTestRealmSets(EJsonValue ejson) { - return switch (ejson) { - { - 'key': EJsonValue key, - 'boolSet': EJsonValue boolSet, - 'intSet': EJsonValue intSet, - 'stringSet': EJsonValue stringSet, - 'doubleSet': EJsonValue doubleSet, - 'dateTimeSet': EJsonValue dateTimeSet, - 'objectIdSet': EJsonValue objectIdSet, - 'uuidSet': EJsonValue uuidSet, - 'mixedSet': EJsonValue mixedSet, - 'objectsSet': EJsonValue objectsSet, - 'binarySet': EJsonValue binarySet, - 'nullableBoolSet': EJsonValue nullableBoolSet, - 'nullableIntSet': EJsonValue nullableIntSet, - 'nullableStringSet': EJsonValue nullableStringSet, - 'nullableDoubleSet': EJsonValue nullableDoubleSet, - 'nullableDateTimeSet': EJsonValue nullableDateTimeSet, - 'nullableObjectIdSet': EJsonValue nullableObjectIdSet, - 'nullableUuidSet': EJsonValue nullableUuidSet, - 'nullableBinarySet': EJsonValue nullableBinarySet - } => - TestRealmSets(fromEJson(key), - boolSet: fromEJson(boolSet), - intSet: fromEJson(intSet), - stringSet: fromEJson(stringSet), - doubleSet: fromEJson(doubleSet), - dateTimeSet: fromEJson(dateTimeSet), - objectIdSet: fromEJson(objectIdSet), - uuidSet: fromEJson(uuidSet), - mixedSet: fromEJson(mixedSet), - objectsSet: fromEJson(objectsSet), - binarySet: fromEJson(binarySet), - nullableBoolSet: fromEJson(nullableBoolSet), - nullableIntSet: fromEJson(nullableIntSet), - nullableStringSet: fromEJson(nullableStringSet), - nullableDoubleSet: fromEJson(nullableDoubleSet), - nullableDateTimeSet: fromEJson(nullableDateTimeSet), - nullableObjectIdSet: fromEJson(nullableObjectIdSet), - nullableUuidSet: fromEJson(nullableUuidSet), - nullableBinarySet: fromEJson(nullableBinarySet)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension TestRealmSetsEJsonEncoderExtension on TestRealmSets { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeTestRealmSets(this); -} diff --git a/packages/realm_dart/test/realm_set_test.realm.dart b/packages/realm_dart/test/realm_set_test.realm.dart index 0b0c50f90..32007d7ec 100644 --- a/packages/realm_dart/test/realm_set_test.realm.dart +++ b/packages/realm_dart/test/realm_set_test.realm.dart @@ -8,7 +8,6 @@ part of 'realm_set_test.dart'; // ignore_for_file: type=lint class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { - @ejson Car( String make, { String? color, @@ -36,20 +35,39 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { @override Car freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeCar(Car value) { + return { + 'make': toEJson(value.make), + 'color': toEJson(value.color), + }; + } + + static Car _decodeCar(EJsonValue ejson) { + return switch (ejson) { + { + 'make': EJsonValue make, + 'color': EJsonValue color, + } => + Car( + fromEJson(make), + color: fromEJson(color), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Car._); + register(_encodeCar, _decodeCar); return const SchemaObject(ObjectType.realmObject, Car, 'Car', [ SchemaProperty('make', RealmPropertyType.string, primaryKey: true), SchemaProperty('color', RealmPropertyType.string, optional: true), ]); - } + }(); } class TestRealmSets extends _TestRealmSets with RealmEntity, RealmObjectBase, RealmObject { - @ejson TestRealmSets( int key, { Set boolSet = const {}, @@ -253,10 +271,63 @@ class TestRealmSets extends _TestRealmSets @override TestRealmSets freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeTestRealmSets(TestRealmSets value) { + return { + 'key': toEJson(value.key), + 'boolSet': toEJson(value.boolSet), + 'intSet': toEJson(value.intSet), + 'stringSet': toEJson(value.stringSet), + 'doubleSet': toEJson(value.doubleSet), + 'dateTimeSet': toEJson(value.dateTimeSet), + 'objectIdSet': toEJson(value.objectIdSet), + 'uuidSet': toEJson(value.uuidSet), + 'mixedSet': toEJson(value.mixedSet), + 'objectsSet': toEJson(value.objectsSet), + 'binarySet': toEJson(value.binarySet), + 'nullableBoolSet': toEJson(value.nullableBoolSet), + 'nullableIntSet': toEJson(value.nullableIntSet), + 'nullableStringSet': toEJson(value.nullableStringSet), + 'nullableDoubleSet': toEJson(value.nullableDoubleSet), + 'nullableDateTimeSet': toEJson(value.nullableDateTimeSet), + 'nullableObjectIdSet': toEJson(value.nullableObjectIdSet), + 'nullableUuidSet': toEJson(value.nullableUuidSet), + 'nullableBinarySet': toEJson(value.nullableBinarySet), + }; + } + + static TestRealmSets _decodeTestRealmSets(EJsonValue ejson) { + return switch (ejson) { + { + 'key': EJsonValue key, + 'boolSet': EJsonValue boolSet, + 'intSet': EJsonValue intSet, + 'stringSet': EJsonValue stringSet, + 'doubleSet': EJsonValue doubleSet, + 'dateTimeSet': EJsonValue dateTimeSet, + 'objectIdSet': EJsonValue objectIdSet, + 'uuidSet': EJsonValue uuidSet, + 'mixedSet': EJsonValue mixedSet, + 'objectsSet': EJsonValue objectsSet, + 'binarySet': EJsonValue binarySet, + 'nullableBoolSet': EJsonValue nullableBoolSet, + 'nullableIntSet': EJsonValue nullableIntSet, + 'nullableStringSet': EJsonValue nullableStringSet, + 'nullableDoubleSet': EJsonValue nullableDoubleSet, + 'nullableDateTimeSet': EJsonValue nullableDateTimeSet, + 'nullableObjectIdSet': EJsonValue nullableObjectIdSet, + 'nullableUuidSet': EJsonValue nullableUuidSet, + 'nullableBinarySet': EJsonValue nullableBinarySet, + } => + TestRealmSets( + fromEJson(key), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(TestRealmSets._); + register(_encodeTestRealmSets, _decodeTestRealmSets); return const SchemaObject( ObjectType.realmObject, TestRealmSets, 'TestRealmSets', [ SchemaProperty('key', RealmPropertyType.int, primaryKey: true), @@ -297,5 +368,5 @@ class TestRealmSets extends _TestRealmSets SchemaProperty('nullableBinarySet', RealmPropertyType.binary, optional: true, collectionType: RealmCollectionType.set), ]); - } + }(); } diff --git a/packages/realm_dart/test/realm_value_test.dart b/packages/realm_dart/test/realm_value_test.dart index d214a686e..5c98dad83 100644 --- a/packages/realm_dart/test/realm_value_test.dart +++ b/packages/realm_dart/test/realm_value_test.dart @@ -10,7 +10,7 @@ import 'package:realm_dart/realm.dart'; import 'test.dart'; part 'realm_value_test.realm.dart'; -part 'realm_value_test.g.dart'; + @RealmModel(ObjectType.embeddedObject) class _TuckedIn { diff --git a/packages/realm_dart/test/realm_value_test.g.dart b/packages/realm_dart/test/realm_value_test.g.dart deleted file mode 100644 index 284ab589b..000000000 --- a/packages/realm_dart/test/realm_value_test.g.dart +++ /dev/null @@ -1,70 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'realm_value_test.dart'; - -// ************************************************************************** -// EJsonGenerator -// ************************************************************************** - -EJsonValue encodeTuckedIn(TuckedIn value) { - return {'x': value.x.toEJson()}; -} - -TuckedIn decodeTuckedIn(EJsonValue ejson) { - return switch (ejson) { - {'x': EJsonValue x} => TuckedIn(x: fromEJson(x)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension TuckedInEJsonEncoderExtension on TuckedIn { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeTuckedIn(this); -} - -EJsonValue encodeAnythingGoes(AnythingGoes value) { - return { - 'oneAny': value.oneAny.toEJson(), - 'manyAny': value.manyAny.toEJson(), - 'setOfAny': value.setOfAny.toEJson(), - 'dictOfAny': value.dictOfAny.toEJson() - }; -} - -AnythingGoes decodeAnythingGoes(EJsonValue ejson) { - return switch (ejson) { - { - 'oneAny': EJsonValue oneAny, - 'manyAny': EJsonValue manyAny, - 'setOfAny': EJsonValue setOfAny, - 'dictOfAny': EJsonValue dictOfAny - } => - AnythingGoes( - oneAny: fromEJson(oneAny), - manyAny: fromEJson(manyAny), - setOfAny: fromEJson(setOfAny), - dictOfAny: fromEJson(dictOfAny)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension AnythingGoesEJsonEncoderExtension on AnythingGoes { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeAnythingGoes(this); -} - -EJsonValue encodeStuff(Stuff value) { - return {'i': value.i.toEJson()}; -} - -Stuff decodeStuff(EJsonValue ejson) { - return switch (ejson) { - {'i': EJsonValue i} => Stuff(i: fromEJson(i)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension StuffEJsonEncoderExtension on Stuff { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeStuff(this); -} diff --git a/packages/realm_dart/test/realm_value_test.realm.dart b/packages/realm_dart/test/realm_value_test.realm.dart index 070b011b6..cfe9121bc 100644 --- a/packages/realm_dart/test/realm_value_test.realm.dart +++ b/packages/realm_dart/test/realm_value_test.realm.dart @@ -11,7 +11,6 @@ class TuckedIn extends _TuckedIn with RealmEntity, RealmObjectBase, EmbeddedObject { static var _defaultsSet = false; - @ejson TuckedIn({ int x = 42, }) { @@ -37,19 +36,35 @@ class TuckedIn extends _TuckedIn @override TuckedIn freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeTuckedIn(TuckedIn value) { + return { + 'x': toEJson(value.x), + }; + } + + static TuckedIn _decodeTuckedIn(EJsonValue ejson) { + return switch (ejson) { + { + 'x': EJsonValue x, + } => + TuckedIn( + x: fromEJson(x), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(TuckedIn._); + register(_encodeTuckedIn, _decodeTuckedIn); return const SchemaObject(ObjectType.embeddedObject, TuckedIn, 'TuckedIn', [ SchemaProperty('x', RealmPropertyType.int), ]); - } + }(); } class AnythingGoes extends _AnythingGoes with RealmEntity, RealmObjectBase, RealmObject { - @ejson AnythingGoes({ RealmValue oneAny = const RealmValue.nullValue(), Iterable manyAny = const [], @@ -102,10 +117,33 @@ class AnythingGoes extends _AnythingGoes @override AnythingGoes freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeAnythingGoes(AnythingGoes value) { + return { + 'oneAny': toEJson(value.oneAny), + 'manyAny': toEJson(value.manyAny), + 'dictOfAny': toEJson(value.dictOfAny), + 'setOfAny': toEJson(value.setOfAny), + }; + } + + static AnythingGoes _decodeAnythingGoes(EJsonValue ejson) { + return switch (ejson) { + { + 'oneAny': EJsonValue oneAny, + 'manyAny': EJsonValue manyAny, + 'dictOfAny': EJsonValue dictOfAny, + 'setOfAny': EJsonValue setOfAny, + } => + AnythingGoes( + oneAny: fromEJson(oneAny), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(AnythingGoes._); + register(_encodeAnythingGoes, _decodeAnythingGoes); return const SchemaObject( ObjectType.realmObject, AnythingGoes, 'AnythingGoes', [ SchemaProperty('oneAny', RealmPropertyType.mixed, @@ -117,13 +155,12 @@ class AnythingGoes extends _AnythingGoes SchemaProperty('setOfAny', RealmPropertyType.mixed, optional: true, collectionType: RealmCollectionType.set), ]); - } + }(); } class Stuff extends _Stuff with RealmEntity, RealmObjectBase, RealmObject { static var _defaultsSet = false; - @ejson Stuff({ int i = 42, }) { @@ -149,12 +186,29 @@ class Stuff extends _Stuff with RealmEntity, RealmObjectBase, RealmObject { @override Stuff freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeStuff(Stuff value) { + return { + 'i': toEJson(value.i), + }; + } + + static Stuff _decodeStuff(EJsonValue ejson) { + return switch (ejson) { + { + 'i': EJsonValue i, + } => + Stuff( + i: fromEJson(i), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Stuff._); + register(_encodeStuff, _decodeStuff); return const SchemaObject(ObjectType.realmObject, Stuff, 'Stuff', [ SchemaProperty('i', RealmPropertyType.int), ]); - } + }(); } diff --git a/packages/realm_dart/test/test.dart b/packages/realm_dart/test/test.dart index db4cb613c..070b4cd18 100644 --- a/packages/realm_dart/test/test.dart +++ b/packages/realm_dart/test/test.dart @@ -22,7 +22,7 @@ import 'baas_helper.dart'; export 'baas_helper.dart' show AppNames; part 'test.realm.dart'; -part 'test.g.dart'; + @RealmModel() class _Car { diff --git a/packages/realm_dart/test/test.g.dart b/packages/realm_dart/test/test.g.dart deleted file mode 100644 index bb3d8052d..000000000 --- a/packages/realm_dart/test/test.g.dart +++ /dev/null @@ -1,917 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'test.dart'; - -// ************************************************************************** -// EJsonGenerator -// ************************************************************************** - -EJsonValue encodeCar(Car value) { - return {'make': value.make.toEJson()}; -} - -Car decodeCar(EJsonValue ejson) { - return switch (ejson) { - {'make': EJsonValue make} => Car(fromEJson(make)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension CarEJsonEncoderExtension on Car { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeCar(this); -} - -EJsonValue encodePerson(Person value) { - return {'name': value.name.toEJson()}; -} - -Person decodePerson(EJsonValue ejson) { - return switch (ejson) { - {'name': EJsonValue name} => Person(fromEJson(name)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension PersonEJsonEncoderExtension on Person { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodePerson(this); -} - -EJsonValue encodeDog(Dog value) { - return { - 'name': value.name.toEJson(), - 'age': value.age.toEJson(), - 'owner': value.owner.toEJson() - }; -} - -Dog decodeDog(EJsonValue ejson) { - return switch (ejson) { - { - 'name': EJsonValue name, - 'age': EJsonValue age, - 'owner': EJsonValue owner - } => - Dog(fromEJson(name), age: fromEJson(age), owner: fromEJson(owner)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension DogEJsonEncoderExtension on Dog { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeDog(this); -} - -EJsonValue encodeTeam(Team value) { - return { - 'name': value.name.toEJson(), - 'players': value.players.toEJson(), - 'scores': value.scores.toEJson() - }; -} - -Team decodeTeam(EJsonValue ejson) { - return switch (ejson) { - { - 'name': EJsonValue name, - 'players': EJsonValue players, - 'scores': EJsonValue scores - } => - Team(fromEJson(name), - players: fromEJson(players), scores: fromEJson(scores)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension TeamEJsonEncoderExtension on Team { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeTeam(this); -} - -EJsonValue encodeStudent(Student value) { - return { - 'number': value.number.toEJson(), - 'name': value.name.toEJson(), - 'yearOfBirth': value.yearOfBirth.toEJson(), - 'school': value.school.toEJson() - }; -} - -Student decodeStudent(EJsonValue ejson) { - return switch (ejson) { - { - 'number': EJsonValue number, - 'name': EJsonValue name, - 'yearOfBirth': EJsonValue yearOfBirth, - 'school': EJsonValue school - } => - Student(fromEJson(number), - name: fromEJson(name), - yearOfBirth: fromEJson(yearOfBirth), - school: fromEJson(school)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension StudentEJsonEncoderExtension on Student { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeStudent(this); -} - -EJsonValue encodeSchool(School value) { - return { - 'name': value.name.toEJson(), - 'city': value.city.toEJson(), - 'branchOfSchool': value.branchOfSchool.toEJson(), - 'students': value.students.toEJson(), - 'branches': value.branches.toEJson() - }; -} - -School decodeSchool(EJsonValue ejson) { - return switch (ejson) { - { - 'name': EJsonValue name, - 'city': EJsonValue city, - 'branchOfSchool': EJsonValue branchOfSchool, - 'students': EJsonValue students, - 'branches': EJsonValue branches - } => - School(fromEJson(name), - city: fromEJson(city), - branchOfSchool: fromEJson(branchOfSchool), - students: fromEJson(students), - branches: fromEJson(branches)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension SchoolEJsonEncoderExtension on School { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeSchool(this); -} - -EJsonValue encodeRemappedClass(RemappedClass value) { - return { - 'remappedProperty': value.remappedProperty.toEJson(), - 'listProperty': value.listProperty.toEJson() - }; -} - -RemappedClass decodeRemappedClass(EJsonValue ejson) { - return switch (ejson) { - { - 'remappedProperty': EJsonValue remappedProperty, - 'listProperty': EJsonValue listProperty - } => - RemappedClass(fromEJson(remappedProperty), - listProperty: fromEJson(listProperty)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension RemappedClassEJsonEncoderExtension on RemappedClass { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeRemappedClass(this); -} - -EJsonValue encodeTask(Task value) { - return {'id': value.id.toEJson()}; -} - -Task decodeTask(EJsonValue ejson) { - return switch (ejson) { - {'id': EJsonValue id} => Task(fromEJson(id)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension TaskEJsonEncoderExtension on Task { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeTask(this); -} - -EJsonValue encodeProduct(Product value) { - return {'id': value.id.toEJson(), 'name': value.name.toEJson()}; -} - -Product decodeProduct(EJsonValue ejson) { - return switch (ejson) { - {'id': EJsonValue id, 'name': EJsonValue name} => - Product(fromEJson(id), fromEJson(name)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension ProductEJsonEncoderExtension on Product { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeProduct(this); -} - -EJsonValue encodeSchedule(Schedule value) { - return {'id': value.id.toEJson(), 'tasks': value.tasks.toEJson()}; -} - -Schedule decodeSchedule(EJsonValue ejson) { - return switch (ejson) { - {'id': EJsonValue id, 'tasks': EJsonValue tasks} => - Schedule(fromEJson(id), tasks: fromEJson(tasks)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension ScheduleEJsonEncoderExtension on Schedule { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeSchedule(this); -} - -EJsonValue encodeFoo(Foo value) { - return { - 'requiredBinaryProp': value.requiredBinaryProp.toEJson(), - 'defaultValueBinaryProp': value.defaultValueBinaryProp.toEJson(), - 'nullableBinaryProp': value.nullableBinaryProp.toEJson() - }; -} - -Foo decodeFoo(EJsonValue ejson) { - return switch (ejson) { - { - 'requiredBinaryProp': EJsonValue requiredBinaryProp, - 'defaultValueBinaryProp': EJsonValue defaultValueBinaryProp, - 'nullableBinaryProp': EJsonValue nullableBinaryProp - } => - Foo(fromEJson(requiredBinaryProp), - defaultValueBinaryProp: fromEJson(defaultValueBinaryProp), - nullableBinaryProp: fromEJson(nullableBinaryProp)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension FooEJsonEncoderExtension on Foo { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeFoo(this); -} - -EJsonValue encodeAllTypes(AllTypes value) { - return { - 'stringProp': value.stringProp.toEJson(), - 'boolProp': value.boolProp.toEJson(), - 'dateProp': value.dateProp.toEJson(), - 'doubleProp': value.doubleProp.toEJson(), - 'objectIdProp': value.objectIdProp.toEJson(), - 'uuidProp': value.uuidProp.toEJson(), - 'intProp': value.intProp.toEJson(), - 'decimalProp': value.decimalProp.toEJson(), - 'binaryProp': value.binaryProp.toEJson(), - 'nullableStringProp': value.nullableStringProp.toEJson(), - 'nullableBoolProp': value.nullableBoolProp.toEJson(), - 'nullableDateProp': value.nullableDateProp.toEJson(), - 'nullableDoubleProp': value.nullableDoubleProp.toEJson(), - 'nullableObjectIdProp': value.nullableObjectIdProp.toEJson(), - 'nullableUuidProp': value.nullableUuidProp.toEJson(), - 'nullableIntProp': value.nullableIntProp.toEJson(), - 'nullableDecimalProp': value.nullableDecimalProp.toEJson(), - 'nullableBinaryProp': value.nullableBinaryProp.toEJson() - }; -} - -AllTypes decodeAllTypes(EJsonValue ejson) { - return switch (ejson) { - { - 'stringProp': EJsonValue stringProp, - 'boolProp': EJsonValue boolProp, - 'dateProp': EJsonValue dateProp, - 'doubleProp': EJsonValue doubleProp, - 'objectIdProp': EJsonValue objectIdProp, - 'uuidProp': EJsonValue uuidProp, - 'intProp': EJsonValue intProp, - 'decimalProp': EJsonValue decimalProp, - 'binaryProp': EJsonValue binaryProp, - 'nullableStringProp': EJsonValue nullableStringProp, - 'nullableBoolProp': EJsonValue nullableBoolProp, - 'nullableDateProp': EJsonValue nullableDateProp, - 'nullableDoubleProp': EJsonValue nullableDoubleProp, - 'nullableObjectIdProp': EJsonValue nullableObjectIdProp, - 'nullableUuidProp': EJsonValue nullableUuidProp, - 'nullableIntProp': EJsonValue nullableIntProp, - 'nullableDecimalProp': EJsonValue nullableDecimalProp, - 'nullableBinaryProp': EJsonValue nullableBinaryProp - } => - AllTypes( - fromEJson(stringProp), - fromEJson(boolProp), - fromEJson(dateProp), - fromEJson(doubleProp), - fromEJson(objectIdProp), - fromEJson(uuidProp), - fromEJson(intProp), - fromEJson(decimalProp), - binaryProp: fromEJson(binaryProp), - nullableStringProp: fromEJson(nullableStringProp), - nullableBoolProp: fromEJson(nullableBoolProp), - nullableDateProp: fromEJson(nullableDateProp), - nullableDoubleProp: fromEJson(nullableDoubleProp), - nullableObjectIdProp: fromEJson(nullableObjectIdProp), - nullableUuidProp: fromEJson(nullableUuidProp), - nullableIntProp: fromEJson(nullableIntProp), - nullableDecimalProp: fromEJson(nullableDecimalProp), - nullableBinaryProp: fromEJson(nullableBinaryProp)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension AllTypesEJsonEncoderExtension on AllTypes { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeAllTypes(this); -} - -EJsonValue encodeLinksClass(LinksClass value) { - return { - 'id': value.id.toEJson(), - 'link': value.link.toEJson(), - 'list': value.list.toEJson() - }; -} - -LinksClass decodeLinksClass(EJsonValue ejson) { - return switch (ejson) { - {'id': EJsonValue id, 'link': EJsonValue link, 'list': EJsonValue list} => - LinksClass(fromEJson(id), link: fromEJson(link), list: fromEJson(list)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension LinksClassEJsonEncoderExtension on LinksClass { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeLinksClass(this); -} - -EJsonValue encodeAllCollections(AllCollections value) { - return { - 'strings': value.strings.toEJson(), - 'bools': value.bools.toEJson(), - 'dates': value.dates.toEJson(), - 'doubles': value.doubles.toEJson(), - 'objectIds': value.objectIds.toEJson(), - 'uuids': value.uuids.toEJson(), - 'ints': value.ints.toEJson(), - 'decimals': value.decimals.toEJson(), - 'nullableStrings': value.nullableStrings.toEJson(), - 'nullableBools': value.nullableBools.toEJson(), - 'nullableDates': value.nullableDates.toEJson(), - 'nullableDoubles': value.nullableDoubles.toEJson(), - 'nullableObjectIds': value.nullableObjectIds.toEJson(), - 'nullableUuids': value.nullableUuids.toEJson(), - 'nullableInts': value.nullableInts.toEJson(), - 'nullableDecimals': value.nullableDecimals.toEJson() - }; -} - -AllCollections decodeAllCollections(EJsonValue ejson) { - return switch (ejson) { - { - 'strings': EJsonValue strings, - 'bools': EJsonValue bools, - 'dates': EJsonValue dates, - 'doubles': EJsonValue doubles, - 'objectIds': EJsonValue objectIds, - 'uuids': EJsonValue uuids, - 'ints': EJsonValue ints, - 'decimals': EJsonValue decimals, - 'nullableStrings': EJsonValue nullableStrings, - 'nullableBools': EJsonValue nullableBools, - 'nullableDates': EJsonValue nullableDates, - 'nullableDoubles': EJsonValue nullableDoubles, - 'nullableObjectIds': EJsonValue nullableObjectIds, - 'nullableUuids': EJsonValue nullableUuids, - 'nullableInts': EJsonValue nullableInts, - 'nullableDecimals': EJsonValue nullableDecimals - } => - AllCollections( - strings: fromEJson(strings), - bools: fromEJson(bools), - dates: fromEJson(dates), - doubles: fromEJson(doubles), - objectIds: fromEJson(objectIds), - uuids: fromEJson(uuids), - ints: fromEJson(ints), - decimals: fromEJson(decimals), - nullableStrings: fromEJson(nullableStrings), - nullableBools: fromEJson(nullableBools), - nullableDates: fromEJson(nullableDates), - nullableDoubles: fromEJson(nullableDoubles), - nullableObjectIds: fromEJson(nullableObjectIds), - nullableUuids: fromEJson(nullableUuids), - nullableInts: fromEJson(nullableInts), - nullableDecimals: fromEJson(nullableDecimals)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension AllCollectionsEJsonEncoderExtension on AllCollections { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeAllCollections(this); -} - -EJsonValue encodeNullableTypes(NullableTypes value) { - return { - 'id': value.id.toEJson(), - 'differentiator': value.differentiator.toEJson(), - 'stringProp': value.stringProp.toEJson(), - 'boolProp': value.boolProp.toEJson(), - 'dateProp': value.dateProp.toEJson(), - 'doubleProp': value.doubleProp.toEJson(), - 'objectIdProp': value.objectIdProp.toEJson(), - 'uuidProp': value.uuidProp.toEJson(), - 'intProp': value.intProp.toEJson(), - 'decimalProp': value.decimalProp.toEJson() - }; -} - -NullableTypes decodeNullableTypes(EJsonValue ejson) { - return switch (ejson) { - { - 'id': EJsonValue id, - 'differentiator': EJsonValue differentiator, - 'stringProp': EJsonValue stringProp, - 'boolProp': EJsonValue boolProp, - 'dateProp': EJsonValue dateProp, - 'doubleProp': EJsonValue doubleProp, - 'objectIdProp': EJsonValue objectIdProp, - 'uuidProp': EJsonValue uuidProp, - 'intProp': EJsonValue intProp, - 'decimalProp': EJsonValue decimalProp - } => - NullableTypes(fromEJson(id), fromEJson(differentiator), - stringProp: fromEJson(stringProp), - boolProp: fromEJson(boolProp), - dateProp: fromEJson(dateProp), - doubleProp: fromEJson(doubleProp), - objectIdProp: fromEJson(objectIdProp), - uuidProp: fromEJson(uuidProp), - intProp: fromEJson(intProp), - decimalProp: fromEJson(decimalProp)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension NullableTypesEJsonEncoderExtension on NullableTypes { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeNullableTypes(this); -} - -EJsonValue encodeEvent(Event value) { - return { - 'id': value.id.toEJson(), - 'name': value.name.toEJson(), - 'isCompleted': value.isCompleted.toEJson(), - 'durationInMinutes': value.durationInMinutes.toEJson(), - 'assignedTo': value.assignedTo.toEJson() - }; -} - -Event decodeEvent(EJsonValue ejson) { - return switch (ejson) { - { - 'id': EJsonValue id, - 'name': EJsonValue name, - 'isCompleted': EJsonValue isCompleted, - 'durationInMinutes': EJsonValue durationInMinutes, - 'assignedTo': EJsonValue assignedTo - } => - Event(fromEJson(id), - name: fromEJson(name), - isCompleted: fromEJson(isCompleted), - durationInMinutes: fromEJson(durationInMinutes), - assignedTo: fromEJson(assignedTo)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension EventEJsonEncoderExtension on Event { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeEvent(this); -} - -EJsonValue encodeParty(Party value) { - return { - 'year': value.year.toEJson(), - 'host': value.host.toEJson(), - 'previous': value.previous.toEJson(), - 'guests': value.guests.toEJson() - }; -} - -Party decodeParty(EJsonValue ejson) { - return switch (ejson) { - { - 'year': EJsonValue year, - 'host': EJsonValue host, - 'previous': EJsonValue previous, - 'guests': EJsonValue guests - } => - Party(fromEJson(year), - host: fromEJson(host), - previous: fromEJson(previous), - guests: fromEJson(guests)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension PartyEJsonEncoderExtension on Party { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeParty(this); -} - -EJsonValue encodeFriend(Friend value) { - return { - 'name': value.name.toEJson(), - 'age': value.age.toEJson(), - 'bestFriend': value.bestFriend.toEJson(), - 'friends': value.friends.toEJson() - }; -} - -Friend decodeFriend(EJsonValue ejson) { - return switch (ejson) { - { - 'name': EJsonValue name, - 'age': EJsonValue age, - 'bestFriend': EJsonValue bestFriend, - 'friends': EJsonValue friends - } => - Friend(fromEJson(name), - age: fromEJson(age), - bestFriend: fromEJson(bestFriend), - friends: fromEJson(friends)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension FriendEJsonEncoderExtension on Friend { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeFriend(this); -} - -EJsonValue encodeWhen(When value) { - return { - 'dateTimeUtc': value.dateTimeUtc.toEJson(), - 'locationName': value.locationName.toEJson() - }; -} - -When decodeWhen(EJsonValue ejson) { - return switch (ejson) { - { - 'dateTimeUtc': EJsonValue dateTimeUtc, - 'locationName': EJsonValue locationName - } => - When(fromEJson(dateTimeUtc), fromEJson(locationName)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension WhenEJsonEncoderExtension on When { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeWhen(this); -} - -EJsonValue encodePlayer(Player value) { - return { - 'name': value.name.toEJson(), - 'game': value.game.toEJson(), - 'scoresByRound': value.scoresByRound.toEJson() - }; -} - -Player decodePlayer(EJsonValue ejson) { - return switch (ejson) { - { - 'name': EJsonValue name, - 'game': EJsonValue game, - 'scoresByRound': EJsonValue scoresByRound - } => - Player(fromEJson(name), - game: fromEJson(game), scoresByRound: fromEJson(scoresByRound)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension PlayerEJsonEncoderExtension on Player { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodePlayer(this); -} - -EJsonValue encodeGame(Game value) { - return {'winnerByRound': value.winnerByRound.toEJson()}; -} - -Game decodeGame(EJsonValue ejson) { - return switch (ejson) { - {'winnerByRound': EJsonValue winnerByRound} => - Game(winnerByRound: fromEJson(winnerByRound)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension GameEJsonEncoderExtension on Game { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeGame(this); -} - -EJsonValue encodeAllTypesEmbedded(AllTypesEmbedded value) { - return { - 'stringProp': value.stringProp.toEJson(), - 'boolProp': value.boolProp.toEJson(), - 'dateProp': value.dateProp.toEJson(), - 'doubleProp': value.doubleProp.toEJson(), - 'objectIdProp': value.objectIdProp.toEJson(), - 'uuidProp': value.uuidProp.toEJson(), - 'intProp': value.intProp.toEJson(), - 'decimalProp': value.decimalProp.toEJson(), - 'nullableStringProp': value.nullableStringProp.toEJson(), - 'nullableBoolProp': value.nullableBoolProp.toEJson(), - 'nullableDateProp': value.nullableDateProp.toEJson(), - 'nullableDoubleProp': value.nullableDoubleProp.toEJson(), - 'nullableObjectIdProp': value.nullableObjectIdProp.toEJson(), - 'nullableUuidProp': value.nullableUuidProp.toEJson(), - 'nullableIntProp': value.nullableIntProp.toEJson(), - 'nullableDecimalProp': value.nullableDecimalProp.toEJson(), - 'strings': value.strings.toEJson(), - 'bools': value.bools.toEJson(), - 'dates': value.dates.toEJson(), - 'doubles': value.doubles.toEJson(), - 'objectIds': value.objectIds.toEJson(), - 'uuids': value.uuids.toEJson(), - 'ints': value.ints.toEJson(), - 'decimals': value.decimals.toEJson() - }; -} - -AllTypesEmbedded decodeAllTypesEmbedded(EJsonValue ejson) { - return switch (ejson) { - { - 'stringProp': EJsonValue stringProp, - 'boolProp': EJsonValue boolProp, - 'dateProp': EJsonValue dateProp, - 'doubleProp': EJsonValue doubleProp, - 'objectIdProp': EJsonValue objectIdProp, - 'uuidProp': EJsonValue uuidProp, - 'intProp': EJsonValue intProp, - 'decimalProp': EJsonValue decimalProp, - 'nullableStringProp': EJsonValue nullableStringProp, - 'nullableBoolProp': EJsonValue nullableBoolProp, - 'nullableDateProp': EJsonValue nullableDateProp, - 'nullableDoubleProp': EJsonValue nullableDoubleProp, - 'nullableObjectIdProp': EJsonValue nullableObjectIdProp, - 'nullableUuidProp': EJsonValue nullableUuidProp, - 'nullableIntProp': EJsonValue nullableIntProp, - 'nullableDecimalProp': EJsonValue nullableDecimalProp, - 'strings': EJsonValue strings, - 'bools': EJsonValue bools, - 'dates': EJsonValue dates, - 'doubles': EJsonValue doubles, - 'objectIds': EJsonValue objectIds, - 'uuids': EJsonValue uuids, - 'ints': EJsonValue ints, - 'decimals': EJsonValue decimals - } => - AllTypesEmbedded( - fromEJson(stringProp), - fromEJson(boolProp), - fromEJson(dateProp), - fromEJson(doubleProp), - fromEJson(objectIdProp), - fromEJson(uuidProp), - fromEJson(intProp), - fromEJson(decimalProp), - nullableStringProp: fromEJson(nullableStringProp), - nullableBoolProp: fromEJson(nullableBoolProp), - nullableDateProp: fromEJson(nullableDateProp), - nullableDoubleProp: fromEJson(nullableDoubleProp), - nullableObjectIdProp: fromEJson(nullableObjectIdProp), - nullableUuidProp: fromEJson(nullableUuidProp), - nullableIntProp: fromEJson(nullableIntProp), - nullableDecimalProp: fromEJson(nullableDecimalProp), - strings: fromEJson(strings), - bools: fromEJson(bools), - dates: fromEJson(dates), - doubles: fromEJson(doubles), - objectIds: fromEJson(objectIds), - uuids: fromEJson(uuids), - ints: fromEJson(ints), - decimals: fromEJson(decimals)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension AllTypesEmbeddedEJsonEncoderExtension on AllTypesEmbedded { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeAllTypesEmbedded(this); -} - -EJsonValue encodeObjectWithEmbedded(ObjectWithEmbedded value) { - return { - 'id': value.id.toEJson(), - 'differentiator': value.differentiator.toEJson(), - 'singleObject': value.singleObject.toEJson(), - 'recursiveObject': value.recursiveObject.toEJson(), - 'list': value.list.toEJson(), - 'recursiveList': value.recursiveList.toEJson() - }; -} - -ObjectWithEmbedded decodeObjectWithEmbedded(EJsonValue ejson) { - return switch (ejson) { - { - 'id': EJsonValue id, - 'differentiator': EJsonValue differentiator, - 'singleObject': EJsonValue singleObject, - 'recursiveObject': EJsonValue recursiveObject, - 'list': EJsonValue list, - 'recursiveList': EJsonValue recursiveList - } => - ObjectWithEmbedded(fromEJson(id), - differentiator: fromEJson(differentiator), - singleObject: fromEJson(singleObject), - recursiveObject: fromEJson(recursiveObject), - list: fromEJson(list), - recursiveList: fromEJson(recursiveList)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension ObjectWithEmbeddedEJsonEncoderExtension on ObjectWithEmbedded { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeObjectWithEmbedded(this); -} - -EJsonValue encodeRecursiveEmbedded1(RecursiveEmbedded1 value) { - return { - 'value': value.value.toEJson(), - 'child': value.child.toEJson(), - 'realmObject': value.realmObject.toEJson(), - 'children': value.children.toEJson() - }; -} - -RecursiveEmbedded1 decodeRecursiveEmbedded1(EJsonValue ejson) { - return switch (ejson) { - { - 'value': EJsonValue value, - 'child': EJsonValue child, - 'realmObject': EJsonValue realmObject, - 'children': EJsonValue children - } => - RecursiveEmbedded1(fromEJson(value), - child: fromEJson(child), - realmObject: fromEJson(realmObject), - children: fromEJson(children)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension RecursiveEmbedded1EJsonEncoderExtension on RecursiveEmbedded1 { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeRecursiveEmbedded1(this); -} - -EJsonValue encodeRecursiveEmbedded2(RecursiveEmbedded2 value) { - return { - 'value': value.value.toEJson(), - 'child': value.child.toEJson(), - 'realmObject': value.realmObject.toEJson(), - 'children': value.children.toEJson() - }; -} - -RecursiveEmbedded2 decodeRecursiveEmbedded2(EJsonValue ejson) { - return switch (ejson) { - { - 'value': EJsonValue value, - 'child': EJsonValue child, - 'realmObject': EJsonValue realmObject, - 'children': EJsonValue children - } => - RecursiveEmbedded2(fromEJson(value), - child: fromEJson(child), - realmObject: fromEJson(realmObject), - children: fromEJson(children)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension RecursiveEmbedded2EJsonEncoderExtension on RecursiveEmbedded2 { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeRecursiveEmbedded2(this); -} - -EJsonValue encodeRecursiveEmbedded3(RecursiveEmbedded3 value) { - return {'value': value.value.toEJson()}; -} - -RecursiveEmbedded3 decodeRecursiveEmbedded3(EJsonValue ejson) { - return switch (ejson) { - {'value': EJsonValue value} => RecursiveEmbedded3(fromEJson(value)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension RecursiveEmbedded3EJsonEncoderExtension on RecursiveEmbedded3 { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeRecursiveEmbedded3(this); -} - -EJsonValue encodeObjectWithDecimal(ObjectWithDecimal value) { - return { - 'decimal': value.decimal.toEJson(), - 'nullableDecimal': value.nullableDecimal.toEJson() - }; -} - -ObjectWithDecimal decodeObjectWithDecimal(EJsonValue ejson) { - return switch (ejson) { - { - 'decimal': EJsonValue decimal, - 'nullableDecimal': EJsonValue nullableDecimal - } => - ObjectWithDecimal(fromEJson(decimal), - nullableDecimal: fromEJson(nullableDecimal)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension ObjectWithDecimalEJsonEncoderExtension on ObjectWithDecimal { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeObjectWithDecimal(this); -} - -EJsonValue encodeAsymmetric(Asymmetric value) { - return { - 'id': value.id.toEJson(), - 'symmetric': value.symmetric.toEJson(), - 'embeddedObjects': value.embeddedObjects.toEJson() - }; -} - -Asymmetric decodeAsymmetric(EJsonValue ejson) { - return switch (ejson) { - { - 'id': EJsonValue id, - 'symmetric': EJsonValue symmetric, - 'embeddedObjects': EJsonValue embeddedObjects - } => - Asymmetric(fromEJson(id), - symmetric: fromEJson(symmetric), - embeddedObjects: fromEJson(embeddedObjects)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension AsymmetricEJsonEncoderExtension on Asymmetric { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeAsymmetric(this); -} - -EJsonValue encodeEmbedded(Embedded value) { - return { - 'value': value.value.toEJson(), - 'any': value.any.toEJson(), - 'symmetric': value.symmetric.toEJson() - }; -} - -Embedded decodeEmbedded(EJsonValue ejson) { - return switch (ejson) { - { - 'value': EJsonValue value, - 'any': EJsonValue any, - 'symmetric': EJsonValue symmetric - } => - Embedded(fromEJson(value), - any: fromEJson(any), symmetric: fromEJson(symmetric)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension EmbeddedEJsonEncoderExtension on Embedded { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeEmbedded(this); -} - -EJsonValue encodeSymmetric(Symmetric value) { - return {'id': value.id.toEJson()}; -} - -Symmetric decodeSymmetric(EJsonValue ejson) { - return switch (ejson) { - {'id': EJsonValue id} => Symmetric(fromEJson(id)), - _ => raiseInvalidEJson(ejson), - }; -} - -extension SymmetricEJsonEncoderExtension on Symmetric { - @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeSymmetric(this); -} diff --git a/packages/realm_dart/test/test.realm.dart b/packages/realm_dart/test/test.realm.dart index afddc7f4b..b4d79c09e 100644 --- a/packages/realm_dart/test/test.realm.dart +++ b/packages/realm_dart/test/test.realm.dart @@ -8,7 +8,6 @@ part of 'test.dart'; // ignore_for_file: type=lint class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { - @ejson Car( String make, ) { @@ -29,18 +28,34 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { @override Car freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeCar(Car value) { + return { + 'make': toEJson(value.make), + }; + } + + static Car _decodeCar(EJsonValue ejson) { + return switch (ejson) { + { + 'make': EJsonValue make, + } => + Car( + fromEJson(make), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Car._); + register(_encodeCar, _decodeCar); return const SchemaObject(ObjectType.realmObject, Car, 'Car', [ SchemaProperty('make', RealmPropertyType.string, primaryKey: true), ]); - } + }(); } class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { - @ejson Person( String name, ) { @@ -61,18 +76,34 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { @override Person freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodePerson(Person value) { + return { + 'name': toEJson(value.name), + }; + } + + static Person _decodePerson(EJsonValue ejson) { + return switch (ejson) { + { + 'name': EJsonValue name, + } => + Person( + fromEJson(name), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Person._); + register(_encodePerson, _decodePerson); return const SchemaObject(ObjectType.realmObject, Person, 'Person', [ SchemaProperty('name', RealmPropertyType.string), ]); - } + }(); } class Dog extends _Dog with RealmEntity, RealmObjectBase, RealmObject { - @ejson Dog( String name, { int? age, @@ -108,21 +139,43 @@ class Dog extends _Dog with RealmEntity, RealmObjectBase, RealmObject { @override Dog freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeDog(Dog value) { + return { + 'name': toEJson(value.name), + 'age': toEJson(value.age), + 'owner': toEJson(value.owner), + }; + } + + static Dog _decodeDog(EJsonValue ejson) { + return switch (ejson) { + { + 'name': EJsonValue name, + 'age': EJsonValue age, + 'owner': EJsonValue owner, + } => + Dog( + fromEJson(name), + age: fromEJson(age), + owner: fromEJson(owner), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Dog._); + register(_encodeDog, _decodeDog); return const SchemaObject(ObjectType.realmObject, Dog, 'Dog', [ SchemaProperty('name', RealmPropertyType.string, primaryKey: true), SchemaProperty('age', RealmPropertyType.int, optional: true), SchemaProperty('owner', RealmPropertyType.object, optional: true, linkTarget: 'Person'), ]); - } + }(); } class Team extends _Team with RealmEntity, RealmObjectBase, RealmObject { - @ejson Team( String name, { Iterable players = const [], @@ -162,10 +215,31 @@ class Team extends _Team with RealmEntity, RealmObjectBase, RealmObject { @override Team freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeTeam(Team value) { + return { + 'name': toEJson(value.name), + 'players': toEJson(value.players), + 'scores': toEJson(value.scores), + }; + } + + static Team _decodeTeam(EJsonValue ejson) { + return switch (ejson) { + { + 'name': EJsonValue name, + 'players': EJsonValue players, + 'scores': EJsonValue scores, + } => + Team( + fromEJson(name), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Team._); + register(_encodeTeam, _decodeTeam); return const SchemaObject(ObjectType.realmObject, Team, 'Team', [ SchemaProperty('name', RealmPropertyType.string), SchemaProperty('players', RealmPropertyType.object, @@ -173,11 +247,10 @@ class Team extends _Team with RealmEntity, RealmObjectBase, RealmObject { SchemaProperty('scores', RealmPropertyType.int, collectionType: RealmCollectionType.list), ]); - } + }(); } class Student extends _Student with RealmEntity, RealmObjectBase, RealmObject { - @ejson Student( int number, { String? name, @@ -221,10 +294,36 @@ class Student extends _Student with RealmEntity, RealmObjectBase, RealmObject { @override Student freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeStudent(Student value) { + return { + 'number': toEJson(value.number), + 'name': toEJson(value.name), + 'yearOfBirth': toEJson(value.yearOfBirth), + 'school': toEJson(value.school), + }; + } + + static Student _decodeStudent(EJsonValue ejson) { + return switch (ejson) { + { + 'number': EJsonValue number, + 'name': EJsonValue name, + 'yearOfBirth': EJsonValue yearOfBirth, + 'school': EJsonValue school, + } => + Student( + fromEJson(number), + name: fromEJson(name), + yearOfBirth: fromEJson(yearOfBirth), + school: fromEJson(school), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Student._); + register(_encodeStudent, _decodeStudent); return const SchemaObject(ObjectType.realmObject, Student, 'Student', [ SchemaProperty('number', RealmPropertyType.int, primaryKey: true), SchemaProperty('name', RealmPropertyType.string, optional: true), @@ -232,11 +331,10 @@ class Student extends _Student with RealmEntity, RealmObjectBase, RealmObject { SchemaProperty('school', RealmPropertyType.object, optional: true, linkTarget: 'School'), ]); - } + }(); } class School extends _School with RealmEntity, RealmObjectBase, RealmObject { - @ejson School( String name, { String? city, @@ -293,10 +391,37 @@ class School extends _School with RealmEntity, RealmObjectBase, RealmObject { @override School freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeSchool(School value) { + return { + 'name': toEJson(value.name), + 'city': toEJson(value.city), + 'students': toEJson(value.students), + 'branchOfSchool': toEJson(value.branchOfSchool), + 'branches': toEJson(value.branches), + }; + } + + static School _decodeSchool(EJsonValue ejson) { + return switch (ejson) { + { + 'name': EJsonValue name, + 'city': EJsonValue city, + 'students': EJsonValue students, + 'branchOfSchool': EJsonValue branchOfSchool, + 'branches': EJsonValue branches, + } => + School( + fromEJson(name), + city: fromEJson(city), + branchOfSchool: fromEJson(branchOfSchool), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(School._); + register(_encodeSchool, _decodeSchool); return const SchemaObject(ObjectType.realmObject, School, 'School', [ SchemaProperty('name', RealmPropertyType.string, primaryKey: true), SchemaProperty('city', RealmPropertyType.string, optional: true), @@ -307,12 +432,11 @@ class School extends _School with RealmEntity, RealmObjectBase, RealmObject { SchemaProperty('branches', RealmPropertyType.object, linkTarget: 'School', collectionType: RealmCollectionType.list), ]); - } + }(); } class RemappedClass extends $RemappedClass with RealmEntity, RealmObjectBase, RealmObject { - @ejson RemappedClass( String remappedProperty, { Iterable listProperty = const [], @@ -346,10 +470,29 @@ class RemappedClass extends $RemappedClass @override RemappedClass freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeRemappedClass(RemappedClass value) { + return { + 'primitive_property': toEJson(value.remappedProperty), + 'list-with-dashes': toEJson(value.listProperty), + }; + } + + static RemappedClass _decodeRemappedClass(EJsonValue ejson) { + return switch (ejson) { + { + 'primitive_property': EJsonValue remappedProperty, + 'list-with-dashes': EJsonValue listProperty, + } => + RemappedClass( + fromEJson(remappedProperty), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(RemappedClass._); + register(_encodeRemappedClass, _decodeRemappedClass); return const SchemaObject( ObjectType.realmObject, RemappedClass, 'myRemappedClass', [ SchemaProperty('remappedProperty', RealmPropertyType.string, @@ -359,11 +502,10 @@ class RemappedClass extends $RemappedClass linkTarget: 'myRemappedClass', collectionType: RealmCollectionType.list), ]); - } + }(); } class Task extends _Task with RealmEntity, RealmObjectBase, RealmObject { - @ejson Task( ObjectId id, ) { @@ -384,19 +526,35 @@ class Task extends _Task with RealmEntity, RealmObjectBase, RealmObject { @override Task freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeTask(Task value) { + return { + '_id': toEJson(value.id), + }; + } + + static Task _decodeTask(EJsonValue ejson) { + return switch (ejson) { + { + '_id': EJsonValue id, + } => + Task( + fromEJson(id), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Task._); + register(_encodeTask, _decodeTask); return const SchemaObject(ObjectType.realmObject, Task, 'Task', [ SchemaProperty('id', RealmPropertyType.objectid, mapTo: '_id', primaryKey: true), ]); - } + }(); } class Product extends _Product with RealmEntity, RealmObjectBase, RealmObject { - @ejson Product( ObjectId id, String name, @@ -426,22 +584,41 @@ class Product extends _Product with RealmEntity, RealmObjectBase, RealmObject { @override Product freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeProduct(Product value) { + return { + '_id': toEJson(value.id), + 'stringQueryField': toEJson(value.name), + }; + } + + static Product _decodeProduct(EJsonValue ejson) { + return switch (ejson) { + { + '_id': EJsonValue id, + 'stringQueryField': EJsonValue name, + } => + Product( + fromEJson(id), + fromEJson(name), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Product._); + register(_encodeProduct, _decodeProduct); return const SchemaObject(ObjectType.realmObject, Product, 'Product', [ SchemaProperty('id', RealmPropertyType.objectid, mapTo: '_id', primaryKey: true), SchemaProperty('name', RealmPropertyType.string, mapTo: 'stringQueryField'), ]); - } + }(); } class Schedule extends _Schedule with RealmEntity, RealmObjectBase, RealmObject { - @ejson Schedule( ObjectId id, { Iterable tasks = const [], @@ -471,21 +648,39 @@ class Schedule extends _Schedule @override Schedule freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeSchedule(Schedule value) { + return { + '_id': toEJson(value.id), + 'tasks': toEJson(value.tasks), + }; + } + + static Schedule _decodeSchedule(EJsonValue ejson) { + return switch (ejson) { + { + '_id': EJsonValue id, + 'tasks': EJsonValue tasks, + } => + Schedule( + fromEJson(id), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Schedule._); + register(_encodeSchedule, _decodeSchedule); return const SchemaObject(ObjectType.realmObject, Schedule, 'Schedule', [ SchemaProperty('id', RealmPropertyType.objectid, mapTo: '_id', primaryKey: true), SchemaProperty('tasks', RealmPropertyType.object, linkTarget: 'Task', collectionType: RealmCollectionType.list), ]); - } + }(); } class Foo extends _Foo with RealmEntity, RealmObjectBase, RealmObject { - @ejson Foo( Uint8List requiredBinaryProp, { Uint8List? defaultValueBinaryProp, @@ -528,22 +723,44 @@ class Foo extends _Foo with RealmEntity, RealmObjectBase, RealmObject { @override Foo freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeFoo(Foo value) { + return { + 'requiredBinaryProp': toEJson(value.requiredBinaryProp), + 'defaultValueBinaryProp': toEJson(value.defaultValueBinaryProp), + 'nullableBinaryProp': toEJson(value.nullableBinaryProp), + }; + } + + static Foo _decodeFoo(EJsonValue ejson) { + return switch (ejson) { + { + 'requiredBinaryProp': EJsonValue requiredBinaryProp, + 'defaultValueBinaryProp': EJsonValue defaultValueBinaryProp, + 'nullableBinaryProp': EJsonValue nullableBinaryProp, + } => + Foo( + fromEJson(requiredBinaryProp), + defaultValueBinaryProp: fromEJson(defaultValueBinaryProp), + nullableBinaryProp: fromEJson(nullableBinaryProp), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Foo._); + register(_encodeFoo, _decodeFoo); return const SchemaObject(ObjectType.realmObject, Foo, 'Foo', [ SchemaProperty('requiredBinaryProp', RealmPropertyType.binary), SchemaProperty('defaultValueBinaryProp', RealmPropertyType.binary), SchemaProperty('nullableBinaryProp', RealmPropertyType.binary, optional: true), ]); - } + }(); } class AllTypes extends _AllTypes with RealmEntity, RealmObjectBase, RealmObject { - @ejson AllTypes( String stringProp, bool boolProp, @@ -713,10 +930,78 @@ class AllTypes extends _AllTypes @override AllTypes freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeAllTypes(AllTypes value) { + return { + 'stringProp': toEJson(value.stringProp), + 'boolProp': toEJson(value.boolProp), + 'dateProp': toEJson(value.dateProp), + 'doubleProp': toEJson(value.doubleProp), + 'objectIdProp': toEJson(value.objectIdProp), + 'uuidProp': toEJson(value.uuidProp), + 'intProp': toEJson(value.intProp), + 'decimalProp': toEJson(value.decimalProp), + 'binaryProp': toEJson(value.binaryProp), + 'nullableStringProp': toEJson(value.nullableStringProp), + 'nullableBoolProp': toEJson(value.nullableBoolProp), + 'nullableDateProp': toEJson(value.nullableDateProp), + 'nullableDoubleProp': toEJson(value.nullableDoubleProp), + 'nullableObjectIdProp': toEJson(value.nullableObjectIdProp), + 'nullableUuidProp': toEJson(value.nullableUuidProp), + 'nullableIntProp': toEJson(value.nullableIntProp), + 'nullableDecimalProp': toEJson(value.nullableDecimalProp), + 'nullableBinaryProp': toEJson(value.nullableBinaryProp), + }; + } + + static AllTypes _decodeAllTypes(EJsonValue ejson) { + return switch (ejson) { + { + 'stringProp': EJsonValue stringProp, + 'boolProp': EJsonValue boolProp, + 'dateProp': EJsonValue dateProp, + 'doubleProp': EJsonValue doubleProp, + 'objectIdProp': EJsonValue objectIdProp, + 'uuidProp': EJsonValue uuidProp, + 'intProp': EJsonValue intProp, + 'decimalProp': EJsonValue decimalProp, + 'binaryProp': EJsonValue binaryProp, + 'nullableStringProp': EJsonValue nullableStringProp, + 'nullableBoolProp': EJsonValue nullableBoolProp, + 'nullableDateProp': EJsonValue nullableDateProp, + 'nullableDoubleProp': EJsonValue nullableDoubleProp, + 'nullableObjectIdProp': EJsonValue nullableObjectIdProp, + 'nullableUuidProp': EJsonValue nullableUuidProp, + 'nullableIntProp': EJsonValue nullableIntProp, + 'nullableDecimalProp': EJsonValue nullableDecimalProp, + 'nullableBinaryProp': EJsonValue nullableBinaryProp, + } => + AllTypes( + fromEJson(stringProp), + fromEJson(boolProp), + fromEJson(dateProp), + fromEJson(doubleProp), + fromEJson(objectIdProp), + fromEJson(uuidProp), + fromEJson(intProp), + fromEJson(decimalProp), + binaryProp: fromEJson(binaryProp), + nullableStringProp: fromEJson(nullableStringProp), + nullableBoolProp: fromEJson(nullableBoolProp), + nullableDateProp: fromEJson(nullableDateProp), + nullableDoubleProp: fromEJson(nullableDoubleProp), + nullableObjectIdProp: fromEJson(nullableObjectIdProp), + nullableUuidProp: fromEJson(nullableUuidProp), + nullableIntProp: fromEJson(nullableIntProp), + nullableDecimalProp: fromEJson(nullableDecimalProp), + nullableBinaryProp: fromEJson(nullableBinaryProp), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(AllTypes._); + register(_encodeAllTypes, _decodeAllTypes); return const SchemaObject(ObjectType.realmObject, AllTypes, 'AllTypes', [ SchemaProperty('stringProp', RealmPropertyType.string), SchemaProperty('boolProp', RealmPropertyType.bool), @@ -745,12 +1030,11 @@ class AllTypes extends _AllTypes SchemaProperty('nullableBinaryProp', RealmPropertyType.binary, optional: true), ]); - } + }(); } class LinksClass extends _LinksClass with RealmEntity, RealmObjectBase, RealmObject { - @ejson LinksClass( Uuid id, { LinksClass? link, @@ -810,10 +1094,36 @@ class LinksClass extends _LinksClass @override LinksClass freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeLinksClass(LinksClass value) { + return { + 'id': toEJson(value.id), + 'link': toEJson(value.link), + 'list': toEJson(value.list), + 'linksSet': toEJson(value.linksSet), + 'map': toEJson(value.map), + }; + } + + static LinksClass _decodeLinksClass(EJsonValue ejson) { + return switch (ejson) { + { + 'id': EJsonValue id, + 'link': EJsonValue link, + 'list': EJsonValue list, + 'linksSet': EJsonValue linksSet, + 'map': EJsonValue map, + } => + LinksClass( + fromEJson(id), + link: fromEJson(link), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(LinksClass._); + register(_encodeLinksClass, _decodeLinksClass); return const SchemaObject( ObjectType.realmObject, LinksClass, 'LinksClass', [ SchemaProperty('id', RealmPropertyType.uuid, primaryKey: true), @@ -828,12 +1138,11 @@ class LinksClass extends _LinksClass linkTarget: 'LinksClass', collectionType: RealmCollectionType.map), ]); - } + }(); } class AllCollections extends _AllCollections with RealmEntity, RealmObjectBase, RealmObject { - @ejson AllCollections({ Iterable stringList = const [], Iterable boolList = const [], @@ -1342,10 +1651,119 @@ class AllCollections extends _AllCollections @override AllCollections freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeAllCollections(AllCollections value) { + return { + 'stringList': toEJson(value.stringList), + 'boolList': toEJson(value.boolList), + 'dateList': toEJson(value.dateList), + 'doubleList': toEJson(value.doubleList), + 'objectIdList': toEJson(value.objectIdList), + 'uuidList': toEJson(value.uuidList), + 'intList': toEJson(value.intList), + 'decimalList': toEJson(value.decimalList), + 'nullableStringList': toEJson(value.nullableStringList), + 'nullableBoolList': toEJson(value.nullableBoolList), + 'nullableDateList': toEJson(value.nullableDateList), + 'nullableDoubleList': toEJson(value.nullableDoubleList), + 'nullableObjectIdList': toEJson(value.nullableObjectIdList), + 'nullableUuidList': toEJson(value.nullableUuidList), + 'nullableIntList': toEJson(value.nullableIntList), + 'nullableDecimalList': toEJson(value.nullableDecimalList), + 'stringSet': toEJson(value.stringSet), + 'boolSet': toEJson(value.boolSet), + 'dateSet': toEJson(value.dateSet), + 'doubleSet': toEJson(value.doubleSet), + 'objectIdSet': toEJson(value.objectIdSet), + 'uuidSet': toEJson(value.uuidSet), + 'intSet': toEJson(value.intSet), + 'decimalSet': toEJson(value.decimalSet), + 'nullableStringSet': toEJson(value.nullableStringSet), + 'nullableBoolSet': toEJson(value.nullableBoolSet), + 'nullableDateSet': toEJson(value.nullableDateSet), + 'nullableDoubleSet': toEJson(value.nullableDoubleSet), + 'nullableObjectIdSet': toEJson(value.nullableObjectIdSet), + 'nullableUuidSet': toEJson(value.nullableUuidSet), + 'nullableIntSet': toEJson(value.nullableIntSet), + 'nullableDecimalSet': toEJson(value.nullableDecimalSet), + 'stringMap': toEJson(value.stringMap), + 'boolMap': toEJson(value.boolMap), + 'dateMap': toEJson(value.dateMap), + 'doubleMap': toEJson(value.doubleMap), + 'objectIdMap': toEJson(value.objectIdMap), + 'uuidMap': toEJson(value.uuidMap), + 'intMap': toEJson(value.intMap), + 'decimalMap': toEJson(value.decimalMap), + 'nullableStringMap': toEJson(value.nullableStringMap), + 'nullableBoolMap': toEJson(value.nullableBoolMap), + 'nullableDateMap': toEJson(value.nullableDateMap), + 'nullableDoubleMap': toEJson(value.nullableDoubleMap), + 'nullableObjectIdMap': toEJson(value.nullableObjectIdMap), + 'nullableUuidMap': toEJson(value.nullableUuidMap), + 'nullableIntMap': toEJson(value.nullableIntMap), + 'nullableDecimalMap': toEJson(value.nullableDecimalMap), + }; + } + + static AllCollections _decodeAllCollections(EJsonValue ejson) { + return switch (ejson) { + { + 'stringList': EJsonValue stringList, + 'boolList': EJsonValue boolList, + 'dateList': EJsonValue dateList, + 'doubleList': EJsonValue doubleList, + 'objectIdList': EJsonValue objectIdList, + 'uuidList': EJsonValue uuidList, + 'intList': EJsonValue intList, + 'decimalList': EJsonValue decimalList, + 'nullableStringList': EJsonValue nullableStringList, + 'nullableBoolList': EJsonValue nullableBoolList, + 'nullableDateList': EJsonValue nullableDateList, + 'nullableDoubleList': EJsonValue nullableDoubleList, + 'nullableObjectIdList': EJsonValue nullableObjectIdList, + 'nullableUuidList': EJsonValue nullableUuidList, + 'nullableIntList': EJsonValue nullableIntList, + 'nullableDecimalList': EJsonValue nullableDecimalList, + 'stringSet': EJsonValue stringSet, + 'boolSet': EJsonValue boolSet, + 'dateSet': EJsonValue dateSet, + 'doubleSet': EJsonValue doubleSet, + 'objectIdSet': EJsonValue objectIdSet, + 'uuidSet': EJsonValue uuidSet, + 'intSet': EJsonValue intSet, + 'decimalSet': EJsonValue decimalSet, + 'nullableStringSet': EJsonValue nullableStringSet, + 'nullableBoolSet': EJsonValue nullableBoolSet, + 'nullableDateSet': EJsonValue nullableDateSet, + 'nullableDoubleSet': EJsonValue nullableDoubleSet, + 'nullableObjectIdSet': EJsonValue nullableObjectIdSet, + 'nullableUuidSet': EJsonValue nullableUuidSet, + 'nullableIntSet': EJsonValue nullableIntSet, + 'nullableDecimalSet': EJsonValue nullableDecimalSet, + 'stringMap': EJsonValue stringMap, + 'boolMap': EJsonValue boolMap, + 'dateMap': EJsonValue dateMap, + 'doubleMap': EJsonValue doubleMap, + 'objectIdMap': EJsonValue objectIdMap, + 'uuidMap': EJsonValue uuidMap, + 'intMap': EJsonValue intMap, + 'decimalMap': EJsonValue decimalMap, + 'nullableStringMap': EJsonValue nullableStringMap, + 'nullableBoolMap': EJsonValue nullableBoolMap, + 'nullableDateMap': EJsonValue nullableDateMap, + 'nullableDoubleMap': EJsonValue nullableDoubleMap, + 'nullableObjectIdMap': EJsonValue nullableObjectIdMap, + 'nullableUuidMap': EJsonValue nullableUuidMap, + 'nullableIntMap': EJsonValue nullableIntMap, + 'nullableDecimalMap': EJsonValue nullableDecimalMap, + } => + AllCollections(), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(AllCollections._); + register(_encodeAllCollections, _decodeAllCollections); return const SchemaObject( ObjectType.realmObject, AllCollections, 'AllCollections', [ SchemaProperty('stringList', RealmPropertyType.string, @@ -1445,12 +1863,11 @@ class AllCollections extends _AllCollections SchemaProperty('nullableDecimalMap', RealmPropertyType.decimal128, optional: true, collectionType: RealmCollectionType.map), ]); - } + }(); } class NullableTypes extends _NullableTypes with RealmEntity, RealmObjectBase, RealmObject { - @ejson NullableTypes( ObjectId id, ObjectId differentiator, { @@ -1545,10 +1962,54 @@ class NullableTypes extends _NullableTypes @override NullableTypes freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeNullableTypes(NullableTypes value) { + return { + '_id': toEJson(value.id), + 'differentiator': toEJson(value.differentiator), + 'stringProp': toEJson(value.stringProp), + 'boolProp': toEJson(value.boolProp), + 'dateProp': toEJson(value.dateProp), + 'doubleProp': toEJson(value.doubleProp), + 'objectIdProp': toEJson(value.objectIdProp), + 'uuidProp': toEJson(value.uuidProp), + 'intProp': toEJson(value.intProp), + 'decimalProp': toEJson(value.decimalProp), + }; + } + + static NullableTypes _decodeNullableTypes(EJsonValue ejson) { + return switch (ejson) { + { + '_id': EJsonValue id, + 'differentiator': EJsonValue differentiator, + 'stringProp': EJsonValue stringProp, + 'boolProp': EJsonValue boolProp, + 'dateProp': EJsonValue dateProp, + 'doubleProp': EJsonValue doubleProp, + 'objectIdProp': EJsonValue objectIdProp, + 'uuidProp': EJsonValue uuidProp, + 'intProp': EJsonValue intProp, + 'decimalProp': EJsonValue decimalProp, + } => + NullableTypes( + fromEJson(id), + fromEJson(differentiator), + stringProp: fromEJson(stringProp), + boolProp: fromEJson(boolProp), + dateProp: fromEJson(dateProp), + doubleProp: fromEJson(doubleProp), + objectIdProp: fromEJson(objectIdProp), + uuidProp: fromEJson(uuidProp), + intProp: fromEJson(intProp), + decimalProp: fromEJson(decimalProp), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(NullableTypes._); + register(_encodeNullableTypes, _decodeNullableTypes); return const SchemaObject( ObjectType.realmObject, NullableTypes, 'NullableTypes', [ SchemaProperty('id', RealmPropertyType.objectid, @@ -1565,11 +2026,10 @@ class NullableTypes extends _NullableTypes SchemaProperty('decimalProp', RealmPropertyType.decimal128, optional: true), ]); - } + }(); } class Event extends _Event with RealmEntity, RealmObjectBase, RealmObject { - @ejson Event( ObjectId id, { String? name, @@ -1626,10 +2086,39 @@ class Event extends _Event with RealmEntity, RealmObjectBase, RealmObject { @override Event freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeEvent(Event value) { + return { + '_id': toEJson(value.id), + 'stringQueryField': toEJson(value.name), + 'boolQueryField': toEJson(value.isCompleted), + 'intQueryField': toEJson(value.durationInMinutes), + 'assignedTo': toEJson(value.assignedTo), + }; + } + + static Event _decodeEvent(EJsonValue ejson) { + return switch (ejson) { + { + '_id': EJsonValue id, + 'stringQueryField': EJsonValue name, + 'boolQueryField': EJsonValue isCompleted, + 'intQueryField': EJsonValue durationInMinutes, + 'assignedTo': EJsonValue assignedTo, + } => + Event( + fromEJson(id), + name: fromEJson(name), + isCompleted: fromEJson(isCompleted), + durationInMinutes: fromEJson(durationInMinutes), + assignedTo: fromEJson(assignedTo), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Event._); + register(_encodeEvent, _decodeEvent); return const SchemaObject(ObjectType.realmObject, Event, 'Event', [ SchemaProperty('id', RealmPropertyType.objectid, mapTo: '_id', primaryKey: true), @@ -1641,11 +2130,10 @@ class Event extends _Event with RealmEntity, RealmObjectBase, RealmObject { mapTo: 'intQueryField', optional: true), SchemaProperty('assignedTo', RealmPropertyType.string, optional: true), ]); - } + }(); } class Party extends _Party with RealmEntity, RealmObjectBase, RealmObject { - @ejson Party( int year, { Friend? host, @@ -1691,10 +2179,35 @@ class Party extends _Party with RealmEntity, RealmObjectBase, RealmObject { @override Party freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeParty(Party value) { + return { + 'host': toEJson(value.host), + 'year': toEJson(value.year), + 'guests': toEJson(value.guests), + 'previous': toEJson(value.previous), + }; + } + + static Party _decodeParty(EJsonValue ejson) { + return switch (ejson) { + { + 'host': EJsonValue host, + 'year': EJsonValue year, + 'guests': EJsonValue guests, + 'previous': EJsonValue previous, + } => + Party( + fromEJson(year), + host: fromEJson(host), + previous: fromEJson(previous), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Party._); + register(_encodeParty, _decodeParty); return const SchemaObject(ObjectType.realmObject, Party, 'Party', [ SchemaProperty('host', RealmPropertyType.object, optional: true, linkTarget: 'Friend'), @@ -1704,13 +2217,12 @@ class Party extends _Party with RealmEntity, RealmObjectBase, RealmObject { SchemaProperty('previous', RealmPropertyType.object, optional: true, linkTarget: 'Party'), ]); - } + }(); } class Friend extends _Friend with RealmEntity, RealmObjectBase, RealmObject { static var _defaultsSet = false; - @ejson Friend( String name, { int age = 42, @@ -1762,10 +2274,35 @@ class Friend extends _Friend with RealmEntity, RealmObjectBase, RealmObject { @override Friend freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeFriend(Friend value) { + return { + 'name': toEJson(value.name), + 'age': toEJson(value.age), + 'bestFriend': toEJson(value.bestFriend), + 'friends': toEJson(value.friends), + }; + } + + static Friend _decodeFriend(EJsonValue ejson) { + return switch (ejson) { + { + 'name': EJsonValue name, + 'age': EJsonValue age, + 'bestFriend': EJsonValue bestFriend, + 'friends': EJsonValue friends, + } => + Friend( + fromEJson(name), + age: fromEJson(age), + bestFriend: fromEJson(bestFriend), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Friend._); + register(_encodeFriend, _decodeFriend); return const SchemaObject(ObjectType.realmObject, Friend, 'Friend', [ SchemaProperty('name', RealmPropertyType.string, primaryKey: true), SchemaProperty('age', RealmPropertyType.int), @@ -1774,11 +2311,10 @@ class Friend extends _Friend with RealmEntity, RealmObjectBase, RealmObject { SchemaProperty('friends', RealmPropertyType.object, linkTarget: 'Friend', collectionType: RealmCollectionType.list), ]); - } + }(); } class When extends _When with RealmEntity, RealmObjectBase, RealmObject { - @ejson When( DateTime dateTimeUtc, String locationName, @@ -1810,19 +2346,38 @@ class When extends _When with RealmEntity, RealmObjectBase, RealmObject { @override When freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeWhen(When value) { + return { + 'dateTimeUtc': toEJson(value.dateTimeUtc), + 'locationName': toEJson(value.locationName), + }; + } + + static When _decodeWhen(EJsonValue ejson) { + return switch (ejson) { + { + 'dateTimeUtc': EJsonValue dateTimeUtc, + 'locationName': EJsonValue locationName, + } => + When( + fromEJson(dateTimeUtc), + fromEJson(locationName), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(When._); + register(_encodeWhen, _decodeWhen); return const SchemaObject(ObjectType.realmObject, When, 'When', [ SchemaProperty('dateTimeUtc', RealmPropertyType.timestamp), SchemaProperty('locationName', RealmPropertyType.string), ]); - } + }(); } class Player extends _Player with RealmEntity, RealmObjectBase, RealmObject { - @ejson Player( String name, { Game? game, @@ -1860,10 +2415,32 @@ class Player extends _Player with RealmEntity, RealmObjectBase, RealmObject { @override Player freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodePlayer(Player value) { + return { + 'name': toEJson(value.name), + 'game': toEJson(value.game), + 'scoresByRound': toEJson(value.scoresByRound), + }; + } + + static Player _decodePlayer(EJsonValue ejson) { + return switch (ejson) { + { + 'name': EJsonValue name, + 'game': EJsonValue game, + 'scoresByRound': EJsonValue scoresByRound, + } => + Player( + fromEJson(name), + game: fromEJson(game), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Player._); + register(_encodePlayer, _decodePlayer); return const SchemaObject(ObjectType.realmObject, Player, 'Player', [ SchemaProperty('name', RealmPropertyType.string, primaryKey: true), SchemaProperty('game', RealmPropertyType.object, @@ -1871,11 +2448,10 @@ class Player extends _Player with RealmEntity, RealmObjectBase, RealmObject { SchemaProperty('scoresByRound', RealmPropertyType.int, optional: true, collectionType: RealmCollectionType.list), ]); - } + }(); } class Game extends _Game with RealmEntity, RealmObjectBase, RealmObject { - @ejson Game({ Iterable winnerByRound = const [], }) { @@ -1899,20 +2475,34 @@ class Game extends _Game with RealmEntity, RealmObjectBase, RealmObject { @override Game freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeGame(Game value) { + return { + 'winnerByRound': toEJson(value.winnerByRound), + }; + } + + static Game _decodeGame(EJsonValue ejson) { + return switch (ejson) { + { + 'winnerByRound': EJsonValue winnerByRound, + } => + Game(), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Game._); + register(_encodeGame, _decodeGame); return const SchemaObject(ObjectType.realmObject, Game, 'Game', [ SchemaProperty('winnerByRound', RealmPropertyType.object, linkTarget: 'Player', collectionType: RealmCollectionType.list), ]); - } + }(); } class AllTypesEmbedded extends _AllTypesEmbedded with RealmEntity, RealmObjectBase, EmbeddedObject { - @ejson AllTypesEmbedded( String stringProp, bool boolProp, @@ -2142,10 +2732,88 @@ class AllTypesEmbedded extends _AllTypesEmbedded AllTypesEmbedded freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeAllTypesEmbedded(AllTypesEmbedded value) { + return { + 'stringProp': toEJson(value.stringProp), + 'boolProp': toEJson(value.boolProp), + 'dateProp': toEJson(value.dateProp), + 'doubleProp': toEJson(value.doubleProp), + 'objectIdProp': toEJson(value.objectIdProp), + 'uuidProp': toEJson(value.uuidProp), + 'intProp': toEJson(value.intProp), + 'decimalProp': toEJson(value.decimalProp), + 'nullableStringProp': toEJson(value.nullableStringProp), + 'nullableBoolProp': toEJson(value.nullableBoolProp), + 'nullableDateProp': toEJson(value.nullableDateProp), + 'nullableDoubleProp': toEJson(value.nullableDoubleProp), + 'nullableObjectIdProp': toEJson(value.nullableObjectIdProp), + 'nullableUuidProp': toEJson(value.nullableUuidProp), + 'nullableIntProp': toEJson(value.nullableIntProp), + 'nullableDecimalProp': toEJson(value.nullableDecimalProp), + 'strings': toEJson(value.strings), + 'bools': toEJson(value.bools), + 'dates': toEJson(value.dates), + 'doubles': toEJson(value.doubles), + 'objectIds': toEJson(value.objectIds), + 'uuids': toEJson(value.uuids), + 'ints': toEJson(value.ints), + 'decimals': toEJson(value.decimals), + }; + } + + static AllTypesEmbedded _decodeAllTypesEmbedded(EJsonValue ejson) { + return switch (ejson) { + { + 'stringProp': EJsonValue stringProp, + 'boolProp': EJsonValue boolProp, + 'dateProp': EJsonValue dateProp, + 'doubleProp': EJsonValue doubleProp, + 'objectIdProp': EJsonValue objectIdProp, + 'uuidProp': EJsonValue uuidProp, + 'intProp': EJsonValue intProp, + 'decimalProp': EJsonValue decimalProp, + 'nullableStringProp': EJsonValue nullableStringProp, + 'nullableBoolProp': EJsonValue nullableBoolProp, + 'nullableDateProp': EJsonValue nullableDateProp, + 'nullableDoubleProp': EJsonValue nullableDoubleProp, + 'nullableObjectIdProp': EJsonValue nullableObjectIdProp, + 'nullableUuidProp': EJsonValue nullableUuidProp, + 'nullableIntProp': EJsonValue nullableIntProp, + 'nullableDecimalProp': EJsonValue nullableDecimalProp, + 'strings': EJsonValue strings, + 'bools': EJsonValue bools, + 'dates': EJsonValue dates, + 'doubles': EJsonValue doubles, + 'objectIds': EJsonValue objectIds, + 'uuids': EJsonValue uuids, + 'ints': EJsonValue ints, + 'decimals': EJsonValue decimals, + } => + AllTypesEmbedded( + fromEJson(stringProp), + fromEJson(boolProp), + fromEJson(dateProp), + fromEJson(doubleProp), + fromEJson(objectIdProp), + fromEJson(uuidProp), + fromEJson(intProp), + fromEJson(decimalProp), + nullableStringProp: fromEJson(nullableStringProp), + nullableBoolProp: fromEJson(nullableBoolProp), + nullableDateProp: fromEJson(nullableDateProp), + nullableDoubleProp: fromEJson(nullableDoubleProp), + nullableObjectIdProp: fromEJson(nullableObjectIdProp), + nullableUuidProp: fromEJson(nullableUuidProp), + nullableIntProp: fromEJson(nullableIntProp), + nullableDecimalProp: fromEJson(nullableDecimalProp), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(AllTypesEmbedded._); + register(_encodeAllTypesEmbedded, _decodeAllTypesEmbedded); return const SchemaObject( ObjectType.embeddedObject, AllTypesEmbedded, 'AllTypesEmbedded', [ SchemaProperty('stringProp', RealmPropertyType.string), @@ -2188,12 +2856,11 @@ class AllTypesEmbedded extends _AllTypesEmbedded SchemaProperty('decimals', RealmPropertyType.decimal128, collectionType: RealmCollectionType.list), ]); - } + }(); } class ObjectWithEmbedded extends _ObjectWithEmbedded with RealmEntity, RealmObjectBase, RealmObject { - @ejson ObjectWithEmbedded( String id, { Uuid? differentiator, @@ -2266,10 +2933,40 @@ class ObjectWithEmbedded extends _ObjectWithEmbedded ObjectWithEmbedded freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeObjectWithEmbedded(ObjectWithEmbedded value) { + return { + '_id': toEJson(value.id), + 'differentiator': toEJson(value.differentiator), + 'singleObject': toEJson(value.singleObject), + 'list': toEJson(value.list), + 'recursiveObject': toEJson(value.recursiveObject), + 'recursiveList': toEJson(value.recursiveList), + }; + } + + static ObjectWithEmbedded _decodeObjectWithEmbedded(EJsonValue ejson) { + return switch (ejson) { + { + '_id': EJsonValue id, + 'differentiator': EJsonValue differentiator, + 'singleObject': EJsonValue singleObject, + 'list': EJsonValue list, + 'recursiveObject': EJsonValue recursiveObject, + 'recursiveList': EJsonValue recursiveList, + } => + ObjectWithEmbedded( + fromEJson(id), + differentiator: fromEJson(differentiator), + singleObject: fromEJson(singleObject), + recursiveObject: fromEJson(recursiveObject), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(ObjectWithEmbedded._); + register(_encodeObjectWithEmbedded, _decodeObjectWithEmbedded); return const SchemaObject( ObjectType.realmObject, ObjectWithEmbedded, 'ObjectWithEmbedded', [ SchemaProperty('id', RealmPropertyType.string, @@ -2286,12 +2983,11 @@ class ObjectWithEmbedded extends _ObjectWithEmbedded linkTarget: 'RecursiveEmbedded1', collectionType: RealmCollectionType.list), ]); - } + }(); } class RecursiveEmbedded1 extends _RecursiveEmbedded1 with RealmEntity, RealmObjectBase, EmbeddedObject { - @ejson RecursiveEmbedded1( String value, { RecursiveEmbedded2? child, @@ -2344,10 +3040,35 @@ class RecursiveEmbedded1 extends _RecursiveEmbedded1 RecursiveEmbedded1 freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeRecursiveEmbedded1(RecursiveEmbedded1 value) { + return { + 'value': toEJson(value.value), + 'child': toEJson(value.child), + 'children': toEJson(value.children), + 'realmObject': toEJson(value.realmObject), + }; + } + + static RecursiveEmbedded1 _decodeRecursiveEmbedded1(EJsonValue ejson) { + return switch (ejson) { + { + 'value': EJsonValue value, + 'child': EJsonValue child, + 'children': EJsonValue children, + 'realmObject': EJsonValue realmObject, + } => + RecursiveEmbedded1( + fromEJson(value), + child: fromEJson(child), + realmObject: fromEJson(realmObject), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(RecursiveEmbedded1._); + register(_encodeRecursiveEmbedded1, _decodeRecursiveEmbedded1); return const SchemaObject( ObjectType.embeddedObject, RecursiveEmbedded1, 'RecursiveEmbedded1', [ SchemaProperty('value', RealmPropertyType.string), @@ -2359,12 +3080,11 @@ class RecursiveEmbedded1 extends _RecursiveEmbedded1 SchemaProperty('realmObject', RealmPropertyType.object, optional: true, linkTarget: 'ObjectWithEmbedded'), ]); - } + }(); } class RecursiveEmbedded2 extends _RecursiveEmbedded2 with RealmEntity, RealmObjectBase, EmbeddedObject { - @ejson RecursiveEmbedded2( String value, { RecursiveEmbedded3? child, @@ -2417,10 +3137,35 @@ class RecursiveEmbedded2 extends _RecursiveEmbedded2 RecursiveEmbedded2 freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeRecursiveEmbedded2(RecursiveEmbedded2 value) { + return { + 'value': toEJson(value.value), + 'child': toEJson(value.child), + 'children': toEJson(value.children), + 'realmObject': toEJson(value.realmObject), + }; + } + + static RecursiveEmbedded2 _decodeRecursiveEmbedded2(EJsonValue ejson) { + return switch (ejson) { + { + 'value': EJsonValue value, + 'child': EJsonValue child, + 'children': EJsonValue children, + 'realmObject': EJsonValue realmObject, + } => + RecursiveEmbedded2( + fromEJson(value), + child: fromEJson(child), + realmObject: fromEJson(realmObject), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(RecursiveEmbedded2._); + register(_encodeRecursiveEmbedded2, _decodeRecursiveEmbedded2); return const SchemaObject( ObjectType.embeddedObject, RecursiveEmbedded2, 'RecursiveEmbedded2', [ SchemaProperty('value', RealmPropertyType.string), @@ -2432,12 +3177,11 @@ class RecursiveEmbedded2 extends _RecursiveEmbedded2 SchemaProperty('realmObject', RealmPropertyType.object, optional: true, linkTarget: 'ObjectWithEmbedded'), ]); - } + }(); } class RecursiveEmbedded3 extends _RecursiveEmbedded3 with RealmEntity, RealmObjectBase, EmbeddedObject { - @ejson RecursiveEmbedded3( String value, ) { @@ -2459,20 +3203,36 @@ class RecursiveEmbedded3 extends _RecursiveEmbedded3 RecursiveEmbedded3 freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeRecursiveEmbedded3(RecursiveEmbedded3 value) { + return { + 'value': toEJson(value.value), + }; + } + + static RecursiveEmbedded3 _decodeRecursiveEmbedded3(EJsonValue ejson) { + return switch (ejson) { + { + 'value': EJsonValue value, + } => + RecursiveEmbedded3( + fromEJson(value), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(RecursiveEmbedded3._); + register(_encodeRecursiveEmbedded3, _decodeRecursiveEmbedded3); return const SchemaObject( ObjectType.embeddedObject, RecursiveEmbedded3, 'RecursiveEmbedded3', [ SchemaProperty('value', RealmPropertyType.string), ]); - } + }(); } class ObjectWithDecimal extends _ObjectWithDecimal with RealmEntity, RealmObjectBase, RealmObject { - @ejson ObjectWithDecimal( Decimal128 decimal, { Decimal128? nullableDecimal, @@ -2504,22 +3264,41 @@ class ObjectWithDecimal extends _ObjectWithDecimal ObjectWithDecimal freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeObjectWithDecimal(ObjectWithDecimal value) { + return { + 'decimal': toEJson(value.decimal), + 'nullableDecimal': toEJson(value.nullableDecimal), + }; + } + + static ObjectWithDecimal _decodeObjectWithDecimal(EJsonValue ejson) { + return switch (ejson) { + { + 'decimal': EJsonValue decimal, + 'nullableDecimal': EJsonValue nullableDecimal, + } => + ObjectWithDecimal( + fromEJson(decimal), + nullableDecimal: fromEJson(nullableDecimal), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(ObjectWithDecimal._); + register(_encodeObjectWithDecimal, _decodeObjectWithDecimal); return const SchemaObject( ObjectType.realmObject, ObjectWithDecimal, 'ObjectWithDecimal', [ SchemaProperty('decimal', RealmPropertyType.decimal128), SchemaProperty('nullableDecimal', RealmPropertyType.decimal128, optional: true), ]); - } + }(); } class Asymmetric extends _Asymmetric with RealmEntity, RealmObjectBase, AsymmetricObject { - @ejson Asymmetric( ObjectId id, { Symmetric? symmetric, @@ -2560,10 +3339,32 @@ class Asymmetric extends _Asymmetric @override Asymmetric freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeAsymmetric(Asymmetric value) { + return { + '_id': toEJson(value.id), + 'symmetric': toEJson(value.symmetric), + 'embeddedObjects': toEJson(value.embeddedObjects), + }; + } + + static Asymmetric _decodeAsymmetric(EJsonValue ejson) { + return switch (ejson) { + { + '_id': EJsonValue id, + 'symmetric': EJsonValue symmetric, + 'embeddedObjects': EJsonValue embeddedObjects, + } => + Asymmetric( + fromEJson(id), + symmetric: fromEJson(symmetric), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Asymmetric._); + register(_encodeAsymmetric, _decodeAsymmetric); return const SchemaObject( ObjectType.asymmetricObject, Asymmetric, 'Asymmetric', [ SchemaProperty('id', RealmPropertyType.objectid, @@ -2573,12 +3374,11 @@ class Asymmetric extends _Asymmetric SchemaProperty('embeddedObjects', RealmPropertyType.object, linkTarget: 'Embedded', collectionType: RealmCollectionType.list), ]); - } + }(); } class Embedded extends _Embedded with RealmEntity, RealmObjectBase, EmbeddedObject { - @ejson Embedded( int value, { RealmValue any = const RealmValue.nullValue(), @@ -2616,22 +3416,44 @@ class Embedded extends _Embedded @override Embedded freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeEmbedded(Embedded value) { + return { + 'value': toEJson(value.value), + 'any': toEJson(value.any), + 'symmetric': toEJson(value.symmetric), + }; + } + + static Embedded _decodeEmbedded(EJsonValue ejson) { + return switch (ejson) { + { + 'value': EJsonValue value, + 'any': EJsonValue any, + 'symmetric': EJsonValue symmetric, + } => + Embedded( + fromEJson(value), + any: fromEJson(any), + symmetric: fromEJson(symmetric), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Embedded._); + register(_encodeEmbedded, _decodeEmbedded); return const SchemaObject(ObjectType.embeddedObject, Embedded, 'Embedded', [ SchemaProperty('value', RealmPropertyType.int), SchemaProperty('any', RealmPropertyType.mixed, optional: true), SchemaProperty('symmetric', RealmPropertyType.object, optional: true, linkTarget: 'Symmetric'), ]); - } + }(); } class Symmetric extends _Symmetric with RealmEntity, RealmObjectBase, RealmObject { - @ejson Symmetric( ObjectId id, ) { @@ -2652,13 +3474,30 @@ class Symmetric extends _Symmetric @override Symmetric freeze() => RealmObjectBase.freezeObject(this); - static SchemaObject get schema => _schema ??= _initSchema(); - static SchemaObject? _schema; - static SchemaObject _initSchema() { + static EJsonValue _encodeSymmetric(Symmetric value) { + return { + '_id': toEJson(value.id), + }; + } + + static Symmetric _decodeSymmetric(EJsonValue ejson) { + return switch (ejson) { + { + '_id': EJsonValue id, + } => + Symmetric( + fromEJson(id), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { RealmObjectBase.registerFactory(Symmetric._); + register(_encodeSymmetric, _decodeSymmetric); return const SchemaObject(ObjectType.realmObject, Symmetric, 'Symmetric', [ SchemaProperty('id', RealmPropertyType.objectid, mapTo: '_id', primaryKey: true), ]); - } + }(); } From f9c0945b443048584eaf3407f8d2d0fbee4dc558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Thu, 29 Feb 2024 22:01:37 +0100 Subject: [PATCH 131/153] format --- packages/realm_dart/lib/src/realm_class.dart | 11 +---------- packages/realm_dart/test/backlinks_test.dart | 1 - packages/realm_dart/test/geospatial_test.dart | 1 - packages/realm_dart/test/indexed_test.dart | 2 -- packages/realm_dart/test/migration_test.dart | 2 -- packages/realm_dart/test/realm_map_test.dart | 1 - packages/realm_dart/test/realm_object_test.dart | 2 -- packages/realm_dart/test/realm_set_test.dart | 1 - packages/realm_dart/test/realm_value_test.dart | 2 -- packages/realm_dart/test/test.dart | 2 -- 10 files changed, 1 insertion(+), 24 deletions(-) diff --git a/packages/realm_dart/lib/src/realm_class.dart b/packages/realm_dart/lib/src/realm_class.dart index 2d29b088e..dee780af9 100644 --- a/packages/realm_dart/lib/src/realm_class.dart +++ b/packages/realm_dart/lib/src/realm_class.dart @@ -97,16 +97,7 @@ export 'realm_object.dart' UserCallbackException; export 'realm_property.dart'; export 'results.dart' show RealmResultsOfObject, RealmResultsChanges, RealmResults, WaitForSyncMode, RealmResultsOfRealmObject; -export 'session.dart' - show - ConnectionStateChange, - SyncProgress, - ProgressDirection, - ProgressMode, - ConnectionState, - Session, - SessionState, - SyncErrorCode; +export 'session.dart' show ConnectionStateChange, SyncProgress, ProgressDirection, ProgressMode, ConnectionState, Session, SessionState, SyncErrorCode; export 'subscription.dart' show Subscription, SubscriptionSet, SubscriptionSetState, MutableSubscriptionSet; export 'user.dart' show User, UserState, ApiKeyClient, UserIdentity, ApiKey, FunctionsClient, UserChanges; export 'native/realm_core.dart' show Decimal128; diff --git a/packages/realm_dart/test/backlinks_test.dart b/packages/realm_dart/test/backlinks_test.dart index 1ebe18ea1..ce99e885e 100644 --- a/packages/realm_dart/test/backlinks_test.dart +++ b/packages/realm_dart/test/backlinks_test.dart @@ -6,7 +6,6 @@ import 'package:test/test.dart' hide test, throws; import 'test.dart'; - part 'backlinks_test.realm.dart'; @RealmModel() diff --git a/packages/realm_dart/test/geospatial_test.dart b/packages/realm_dart/test/geospatial_test.dart index 7f921730c..b1a4b01f9 100644 --- a/packages/realm_dart/test/geospatial_test.dart +++ b/packages/realm_dart/test/geospatial_test.dart @@ -10,7 +10,6 @@ import 'package:test/test.dart' hide test, throws; import 'package:realm_dart/realm.dart'; import 'test.dart'; - part 'geospatial_test.realm.dart'; @RealmModel(ObjectType.embeddedObject) diff --git a/packages/realm_dart/test/indexed_test.dart b/packages/realm_dart/test/indexed_test.dart index 65d1ce7cf..cc1083570 100644 --- a/packages/realm_dart/test/indexed_test.dart +++ b/packages/realm_dart/test/indexed_test.dart @@ -1,7 +1,6 @@ // Copyright 2022 MongoDB, Inc. // SPDX-License-Identifier: Apache-2.0 - import 'dart:math'; import 'dart:typed_data'; @@ -12,7 +11,6 @@ import 'package:realm_dart/realm.dart'; part 'indexed_test.realm.dart'; - // Don't import our own test.dart here. It will break AOT compilation. // We may use AOT compilation locally to manually run the performance // tests in this file diff --git a/packages/realm_dart/test/migration_test.dart b/packages/realm_dart/test/migration_test.dart index a3a3a9230..8154ccf2e 100644 --- a/packages/realm_dart/test/migration_test.dart +++ b/packages/realm_dart/test/migration_test.dart @@ -3,7 +3,6 @@ // ignore_for_file: unused_local_variable - import 'dart:async'; import 'package:test/test.dart' hide test, throws; import 'package:realm_dart/realm.dart'; @@ -14,7 +13,6 @@ import 'package:realm_dart/src/list.dart'; part 'migration_test.realm.dart'; - @RealmModel() @MapTo("Person") class _PersonIntName { diff --git a/packages/realm_dart/test/realm_map_test.dart b/packages/realm_dart/test/realm_map_test.dart index d4960daf5..032cc18de 100644 --- a/packages/realm_dart/test/realm_map_test.dart +++ b/packages/realm_dart/test/realm_map_test.dart @@ -12,7 +12,6 @@ import 'package:realm_dart/realm.dart'; import 'test.dart'; - part 'realm_map_test.realm.dart'; @RealmModel() diff --git a/packages/realm_dart/test/realm_object_test.dart b/packages/realm_dart/test/realm_object_test.dart index 260ed2152..14e624327 100644 --- a/packages/realm_dart/test/realm_object_test.dart +++ b/packages/realm_dart/test/realm_object_test.dart @@ -3,7 +3,6 @@ // ignore_for_file: unused_local_variable, avoid_relative_lib_imports - import 'dart:typed_data'; import 'package:test/test.dart' hide test, throws; import 'package:realm_dart/realm.dart'; @@ -12,7 +11,6 @@ import 'test.dart'; part 'realm_object_test.realm.dart'; - @RealmModel() class _ObjectIdPrimaryKey { @PrimaryKey() diff --git a/packages/realm_dart/test/realm_set_test.dart b/packages/realm_dart/test/realm_set_test.dart index 9aa4e4500..ffb420814 100644 --- a/packages/realm_dart/test/realm_set_test.dart +++ b/packages/realm_dart/test/realm_set_test.dart @@ -9,7 +9,6 @@ import 'package:test/test.dart' hide test, throws; import 'test.dart'; - part 'realm_set_test.realm.dart'; class _NullableBool {} diff --git a/packages/realm_dart/test/realm_value_test.dart b/packages/realm_dart/test/realm_value_test.dart index 5c98dad83..bb5a7ec3d 100644 --- a/packages/realm_dart/test/realm_value_test.dart +++ b/packages/realm_dart/test/realm_value_test.dart @@ -1,7 +1,6 @@ // Copyright 2022 MongoDB, Inc. // SPDX-License-Identifier: Apache-2.0 - import 'dart:typed_data'; import 'package:test/test.dart' hide test, throws; @@ -11,7 +10,6 @@ import 'test.dart'; part 'realm_value_test.realm.dart'; - @RealmModel(ObjectType.embeddedObject) class _TuckedIn { int x = 42; diff --git a/packages/realm_dart/test/test.dart b/packages/realm_dart/test/test.dart index 070b4cd18..3c3e71641 100644 --- a/packages/realm_dart/test/test.dart +++ b/packages/realm_dart/test/test.dart @@ -1,7 +1,6 @@ // Copyright 2021 MongoDB, Inc. // SPDX-License-Identifier: Apache-2.0 - import 'dart:async'; import 'dart:collection'; import 'dart:ffi'; @@ -23,7 +22,6 @@ export 'baas_helper.dart' show AppNames; part 'test.realm.dart'; - @RealmModel() class _Car { @PrimaryKey() From a115515b66a49fbb2be2b9dd6dda0a0ad1e9ab0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Fri, 1 Mar 2024 08:51:42 +0100 Subject: [PATCH 132/153] Absolute symlinks should be relative --- packages/ejson/analysis_options.yaml | 2 +- packages/ejson_analyzer/analysis_options.yaml | 2 +- packages/ejson_annotation/analysis_options.yaml | 2 +- packages/ejson_generator/analysis_options.yaml | 2 +- packages/ejson_lint/analysis_options.yaml | 2 +- packages/ejson_lint/example/analysis_options.yaml | 2 +- packages/realm/analysis_options.yaml | 2 +- packages/realm/example/analysis_options.yaml | 2 +- packages/realm/tests/analysis_options.yaml | 2 +- packages/realm_common/analysis_options.yaml | 2 +- packages/realm_dart/analysis_options.yaml | 2 +- packages/realm_dart/example/analysis_options.yaml | 2 +- packages/realm_generator/analysis_options.yaml | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/ejson/analysis_options.yaml b/packages/ejson/analysis_options.yaml index 55b28ee2d..3a0737064 120000 --- a/packages/ejson/analysis_options.yaml +++ b/packages/ejson/analysis_options.yaml @@ -1 +1 @@ -/Users/kasper/Projects/mongodb/realm-dart/analysis_options.yaml \ No newline at end of file +../../analysis_options.yaml \ No newline at end of file diff --git a/packages/ejson_analyzer/analysis_options.yaml b/packages/ejson_analyzer/analysis_options.yaml index 55b28ee2d..3a0737064 120000 --- a/packages/ejson_analyzer/analysis_options.yaml +++ b/packages/ejson_analyzer/analysis_options.yaml @@ -1 +1 @@ -/Users/kasper/Projects/mongodb/realm-dart/analysis_options.yaml \ No newline at end of file +../../analysis_options.yaml \ No newline at end of file diff --git a/packages/ejson_annotation/analysis_options.yaml b/packages/ejson_annotation/analysis_options.yaml index 55b28ee2d..3a0737064 120000 --- a/packages/ejson_annotation/analysis_options.yaml +++ b/packages/ejson_annotation/analysis_options.yaml @@ -1 +1 @@ -/Users/kasper/Projects/mongodb/realm-dart/analysis_options.yaml \ No newline at end of file +../../analysis_options.yaml \ No newline at end of file diff --git a/packages/ejson_generator/analysis_options.yaml b/packages/ejson_generator/analysis_options.yaml index 55b28ee2d..3a0737064 120000 --- a/packages/ejson_generator/analysis_options.yaml +++ b/packages/ejson_generator/analysis_options.yaml @@ -1 +1 @@ -/Users/kasper/Projects/mongodb/realm-dart/analysis_options.yaml \ No newline at end of file +../../analysis_options.yaml \ No newline at end of file diff --git a/packages/ejson_lint/analysis_options.yaml b/packages/ejson_lint/analysis_options.yaml index 55b28ee2d..3a0737064 120000 --- a/packages/ejson_lint/analysis_options.yaml +++ b/packages/ejson_lint/analysis_options.yaml @@ -1 +1 @@ -/Users/kasper/Projects/mongodb/realm-dart/analysis_options.yaml \ No newline at end of file +../../analysis_options.yaml \ No newline at end of file diff --git a/packages/ejson_lint/example/analysis_options.yaml b/packages/ejson_lint/example/analysis_options.yaml index 55b28ee2d..d573f89e6 120000 --- a/packages/ejson_lint/example/analysis_options.yaml +++ b/packages/ejson_lint/example/analysis_options.yaml @@ -1 +1 @@ -/Users/kasper/Projects/mongodb/realm-dart/analysis_options.yaml \ No newline at end of file +../../../analysis_options.yaml \ No newline at end of file diff --git a/packages/realm/analysis_options.yaml b/packages/realm/analysis_options.yaml index 55b28ee2d..3a0737064 120000 --- a/packages/realm/analysis_options.yaml +++ b/packages/realm/analysis_options.yaml @@ -1 +1 @@ -/Users/kasper/Projects/mongodb/realm-dart/analysis_options.yaml \ No newline at end of file +../../analysis_options.yaml \ No newline at end of file diff --git a/packages/realm/example/analysis_options.yaml b/packages/realm/example/analysis_options.yaml index 55b28ee2d..d573f89e6 120000 --- a/packages/realm/example/analysis_options.yaml +++ b/packages/realm/example/analysis_options.yaml @@ -1 +1 @@ -/Users/kasper/Projects/mongodb/realm-dart/analysis_options.yaml \ No newline at end of file +../../../analysis_options.yaml \ No newline at end of file diff --git a/packages/realm/tests/analysis_options.yaml b/packages/realm/tests/analysis_options.yaml index 55b28ee2d..d573f89e6 120000 --- a/packages/realm/tests/analysis_options.yaml +++ b/packages/realm/tests/analysis_options.yaml @@ -1 +1 @@ -/Users/kasper/Projects/mongodb/realm-dart/analysis_options.yaml \ No newline at end of file +../../../analysis_options.yaml \ No newline at end of file diff --git a/packages/realm_common/analysis_options.yaml b/packages/realm_common/analysis_options.yaml index 55b28ee2d..3a0737064 120000 --- a/packages/realm_common/analysis_options.yaml +++ b/packages/realm_common/analysis_options.yaml @@ -1 +1 @@ -/Users/kasper/Projects/mongodb/realm-dart/analysis_options.yaml \ No newline at end of file +../../analysis_options.yaml \ No newline at end of file diff --git a/packages/realm_dart/analysis_options.yaml b/packages/realm_dart/analysis_options.yaml index 55b28ee2d..3a0737064 120000 --- a/packages/realm_dart/analysis_options.yaml +++ b/packages/realm_dart/analysis_options.yaml @@ -1 +1 @@ -/Users/kasper/Projects/mongodb/realm-dart/analysis_options.yaml \ No newline at end of file +../../analysis_options.yaml \ No newline at end of file diff --git a/packages/realm_dart/example/analysis_options.yaml b/packages/realm_dart/example/analysis_options.yaml index 55b28ee2d..d573f89e6 120000 --- a/packages/realm_dart/example/analysis_options.yaml +++ b/packages/realm_dart/example/analysis_options.yaml @@ -1 +1 @@ -/Users/kasper/Projects/mongodb/realm-dart/analysis_options.yaml \ No newline at end of file +../../../analysis_options.yaml \ No newline at end of file diff --git a/packages/realm_generator/analysis_options.yaml b/packages/realm_generator/analysis_options.yaml index 55b28ee2d..3a0737064 120000 --- a/packages/realm_generator/analysis_options.yaml +++ b/packages/realm_generator/analysis_options.yaml @@ -1 +1 @@ -/Users/kasper/Projects/mongodb/realm-dart/analysis_options.yaml \ No newline at end of file +../../analysis_options.yaml \ No newline at end of file From 7286f954f4204616e4eed0cf3eea9e0b37975587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Fri, 1 Mar 2024 10:41:37 +0100 Subject: [PATCH 133/153] Upgrade simulator to iPhone SE (3rd generation) --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 88a5dc7f5..9f16a9122 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -323,7 +323,7 @@ jobs: - name: Launch Simulator uses: futureware-tech/simulator-action@v3 with: - model: 'iPhone 8' + model: 'iPhone SE (3rd generation)' os: 'iOS' os_version: '>= 14.0' From 58d802798d61c4adef0e5740e5f248ee1702375c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Fri, 1 Mar 2024 11:48:50 +0100 Subject: [PATCH 134/153] Update example with to/From-EJson --- packages/realm_dart/example/bin/myapp.dart | 18 ++++++++++++------ .../realm_dart/example/bin/myapp.realm.dart | 4 ++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/realm_dart/example/bin/myapp.dart b/packages/realm_dart/example/bin/myapp.dart index d8b6deb8d..37a435195 100644 --- a/packages/realm_dart/example/bin/myapp.dart +++ b/packages/realm_dart/example/bin/myapp.dart @@ -1,13 +1,10 @@ -import 'package:ejson_annotation/ejson_annotation.dart'; -import 'package:ejson/ejson.dart'; - import 'dart:async'; +import 'dart:convert'; import 'dart:io'; import 'package:realm_dart/realm.dart'; part 'myapp.realm.dart'; - @RealmModel() class _Car { late String make; @@ -19,7 +16,7 @@ class _Car { @RealmModel() class _Person { late String name; - int age = 1; + int age = 42; } void main(List arguments) async { @@ -55,6 +52,15 @@ void main(List arguments) async { var cars = realm.all(); print("There are ${cars.length} cars in the Realm."); + print('Serializing the cars to EJSON.'); + final ejson = toEJson(cars); + final jsonString = JsonEncoder.withIndent(' ').convert(ejson); // ejson is still json + print(jsonString); + print('Deserializing the EJSON back to objects.'); + final decoded = fromEJson>(jsonDecode(jsonString)); // decode objects are always unmanaged + print('Adding the deserialized cars back to the Realm, creating duplicates.'); + realm.write(() => realm.addAll(decoded)); // add duplicates back + var indexedCar = cars[0]; print('The first car is ${indexedCar.make} ${indexedCar.model}'); @@ -66,7 +72,7 @@ void main(List arguments) async { await Future.delayed(Duration(milliseconds: 1)); realm.close(); - + //This is only needed in Dart apps as a workaround for https://github.com/dart-lang/sdk/issues/49083 Realm.shutdown(); print("Done"); diff --git a/packages/realm_dart/example/bin/myapp.realm.dart b/packages/realm_dart/example/bin/myapp.realm.dart index df4cf69bd..4a0c80501 100644 --- a/packages/realm_dart/example/bin/myapp.realm.dart +++ b/packages/realm_dart/example/bin/myapp.realm.dart @@ -102,11 +102,11 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { Person( String name, { - int age = 1, + int age = 42, }) { if (!_defaultsSet) { _defaultsSet = RealmObjectBase.setDefaults({ - 'age': 1, + 'age': 42, }); } RealmObjectBase.set(this, 'name', name); From 393046ee12deb21aea79ebf96babad0a558cb3a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Fri, 1 Mar 2024 12:41:25 +0100 Subject: [PATCH 135/153] Update CHANGELOG --- CHANGELOG.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f964dc76..5766b380c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,18 @@ ``` ### Enhancements +* Realm objects can now be serialized as [EJSON](https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/) + ```dart + import 'package:ejson/ejson.dart'; + // ... + class _Event { + late DateTime timestamp; + late String message; + } + // ... + final ejson = toEJson(aRealmObject); + final anUnmanagedRealmObject = fromEJson(ejson); + ``` * Added `isCollectionDeleted` to `RealmListChanges`, `RealmSetChanges`, and `RealmMapChanges` which will be `true` if the parent object, containing the collection has been deleted. (Core 14.0.0) * Added `isCleared` to `RealmMapChanges` which will be `true` if the map has been cleared. (Core 14.0.0) * Querying a specific entry in a collection (in particular 'first and 'last') is supported. (Core 14.0.0) From 59d2801eef33688a7c825a46925398b0d5e3b78b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Fri, 1 Mar 2024 13:13:19 +0100 Subject: [PATCH 136/153] Dart doc updates --- packages/ejson/lib/src/configuration.dart | 3 ++- packages/ejson/lib/src/decoding.dart | 15 +++++++++++--- packages/ejson/lib/src/encoding.dart | 24 ++++++++++++++++++++++- packages/ejson/lib/src/types.dart | 4 +++- packages/realm_generator/build.yaml | 9 +++++++++ 5 files changed, 49 insertions(+), 6 deletions(-) diff --git a/packages/ejson/lib/src/configuration.dart b/packages/ejson/lib/src/configuration.dart index 0eadfd379..7ef45d9f9 100644 --- a/packages/ejson/lib/src/configuration.dart +++ b/packages/ejson/lib/src/configuration.dart @@ -7,7 +7,8 @@ import 'package:type_plus/type_plus.dart'; import 'decoding.dart'; import 'encoding.dart'; -/// Register custom EJSON [encoder] and [decoder] for a [T]. +/// Register custom EJSON [encoder] and [decoder] for a type [T]. +/// The last registered codec pair for a given type [T] will be used. void register(EJsonEncoder encoder, EJsonDecoder decoder) { TypePlus.add(); customEncoders[T] = encoder; diff --git a/packages/ejson/lib/src/decoding.dart b/packages/ejson/lib/src/decoding.dart index 7f61abc93..98238b431 100644 --- a/packages/ejson/lib/src/decoding.dart +++ b/packages/ejson/lib/src/decoding.dart @@ -12,6 +12,7 @@ import 'package:type_plus/type_plus.dart'; import 'types.dart'; +/// Predefined decoders for common types const commonDecoders = { dynamic: _decodeAny, Null: _decodeNull, @@ -35,6 +36,7 @@ const commonDecoders = { UndefinedOr: _decodeUndefinedOr, }; +/// Custom decoders for specific types. Use `register` to add a custom decoder. final customDecoders = {}; final decoders = () { @@ -50,6 +52,10 @@ final decoders = () { return CombinedMapView([customDecoders, commonDecoders]); }(); +/// Converts [ejson] to type [T]. +/// +/// Throws [InvalidEJson] if [ejson] is not valid for [T]. +/// Throws [MissingDecoder] if no decoder is registered for [T]. T fromEJson(EJsonValue ejson) { final type = T; final nullable = type.isNullable; @@ -65,6 +71,7 @@ T fromEJson(EJsonValue ejson) { } // Important to return `T` as opposed to [Never] for type inference to work +/// @nodoc T raiseInvalidEJson(Object? value) => throw InvalidEJson(value, T); dynamic _decodeAny(EJsonValue ejson) { @@ -242,16 +249,18 @@ Uint8List _decodeBinary(EJsonValue ejson) { }; } +/// Thrown when a value cannot be decoded from [ejson]. class InvalidEJson implements Exception { - final Object? value; + final EJsonValue ejson; final Type type; - InvalidEJson(this.value, this.type); + InvalidEJson(this.ejson, this.type); @override - String toString() => 'Invalid EJson for $type: $value'; + String toString() => 'Invalid EJson for $type: $ejson'; } +/// Thrown when no decoder is registered for a [type]. class MissingDecoder implements Exception { final EJsonValue ejson; final Type type; diff --git a/packages/ejson/lib/src/encoding.dart b/packages/ejson/lib/src/encoding.dart index 5888efca2..7fccfbae3 100644 --- a/packages/ejson/lib/src/encoding.dart +++ b/packages/ejson/lib/src/encoding.dart @@ -11,12 +11,16 @@ import 'package:type_plus/type_plus.dart'; import 'types.dart'; -// No custom encoders, if registerSerializableTypes not called +/// Custom encoders for specific types. Use `register` to add a custom encoder. var customEncoders = {}; +/// Whether to use relaxed encoding or not, default is false var relaxed = false; @pragma('vm:prefer-inline') +/// Converts [value] to EJson +/// +/// Throws [MissingEncoder] if no encoder is registered for [value]'s type. EJsonValue toEJson(Object? value) => _encodeAny(value); EJsonValue _encodeAny(Object? value) { @@ -106,6 +110,7 @@ EJsonValue _encodeBinary(Uint8List buffer, String subtype) => { EJsonValue _encodeObjectId(ObjectId objectId) => {'\$oid': objectId.hexString}; +/// Exception thrown when no encoder is registered for the type of a [value]. class MissingEncoder implements Exception { final Object value; @@ -116,86 +121,103 @@ class MissingEncoder implements Exception { } extension BoolEJsonEncoderExtension on bool { + /// Converts this [bool] to EJson @pragma('vm:prefer-inline') EJsonValue toEJson() => _encodeBool(this); } extension DateTimeEJsonEncoderExtension on DateTime { + /// Converts this [DateTime] to EJson @pragma('vm:prefer-inline') EJsonValue toEJson() => _encodeDate(this); } extension DefinedEJsonEncoderExtension on Defined { + /// Converts this [Defined] to EJson @pragma('vm:prefer-inline') EJsonValue toEJson() => _encodeDefined(this); } extension DoubleEJsonEncoderExtension on double { + /// Converts this [double] to EJson @pragma('vm:prefer-inline') EJsonValue toEJson() => _encodeDouble(this); } extension IntEJsonEncoderExtension on int { + /// Converts this [int] to EJson @pragma('vm:prefer-inline') EJsonValue toEJson({bool long = true}) => _encodeInt(this, long: long); } extension KeyEJsonEncoderExtension on Key { + /// Converts this [Key] to EJson @pragma('vm:prefer-inline') EJsonValue toEJson() => _encodeKey(this); } extension ListEJsonEncoderExtension on List { + /// Converts this [List] to EJson @pragma('vm:prefer-inline') EJsonValue toEJson() => _encodeArray(this); } extension MapEJsonEncoderExtension on Map { + /// Converts this [Map] to EJson @pragma('vm:prefer-inline') EJsonValue toEJson() => _encodeDocument(this); } extension NullEJsonEncoderExtension on Null { + /// Converts this [Null] to EJson @pragma('vm:prefer-inline') EJsonValue toEJson() => null; } extension NullableObjectEJsonEncoderExtension on Object? { + /// Converts this [Object] to EJson @pragma('vm:prefer-inline') EJsonValue toEJson() => _encodeAny(this); } extension ObjectIdEJsonEncoderExtension on ObjectId { + /// Converts this [ObjectId] to EJson @pragma('vm:prefer-inline') EJsonValue toEJson() => _encodeObjectId(this); } extension StringEJsonEncoderExtension on String { + /// Converts this [String] to EJson @pragma('vm:prefer-inline') EJsonValue toEJson() => _encodeString(this); } extension SymbolEJsonEncoderExtension on Symbol { + /// Extract the name of this [Symbol] String get name { final full = toString(); return full.substring(8, full.length - 2); } + /// Converts this [Symbol] to EJson @pragma('vm:prefer-inline') EJsonValue toEJson() => _encodeSymbol(this); } extension Uint8ListEJsonEncoderExtension on Uint8List { + /// Converts this [Uint8List] to EJson @pragma('vm:prefer-inline') EJsonValue toEJson() => _encodeBinary(this, '00'); } extension UndefinedEJsonEncoderExtension on Undefined { + /// Converts this [Undefined] to EJson @pragma('vm:prefer-inline') EJsonValue toEJson() => _encodeUndefined(this); } extension UuidEJsonEncoderExtension on Uuid { + /// Converts this [Uuid] to EJson @pragma('vm:prefer-inline') EJsonValue toEJson() => _encodeUuid(this); } diff --git a/packages/ejson/lib/src/types.dart b/packages/ejson/lib/src/types.dart index 981bb8ac1..8a0027afa 100644 --- a/packages/ejson/lib/src/types.dart +++ b/packages/ejson/lib/src/types.dart @@ -24,9 +24,11 @@ enum EJsonType { // databasePointer, // databaseRef, // regularExpression, - // timestamp, // Why? Isn't this just a date? + // timestamp, // This is not what you think, see https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-Timestamp } +/// 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 } sealed class UndefinedOr { diff --git a/packages/realm_generator/build.yaml b/packages/realm_generator/build.yaml index d44a193d7..c7d6e8002 100644 --- a/packages/realm_generator/build.yaml +++ b/packages/realm_generator/build.yaml @@ -1,3 +1,12 @@ +targets: + $default: + builders: + realm_generator: + enabled: true + generate_for: + include: + - test/good_test_data/**.dart + builders: realm_generator: import: "package:realm_generator/realm_generator.dart" From be09a79d43f65acf7ae8c530fa55ed30b0da0731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Fri, 1 Mar 2024 14:15:10 +0100 Subject: [PATCH 137/153] Missing headers --- packages/ejson/example/main.dart | 3 +++ packages/ejson/test/person.dart | 3 +++ packages/ejson_analyzer/lib/ejson_analyzer.dart | 3 +++ packages/ejson_analyzer/lib/src/ejson_analyzer_base.dart | 3 +++ packages/ejson_generator/lib/ejson_generator.dart | 3 +++ packages/ejson_lint/example/bin/example.dart | 3 +++ packages/ejson_lint/lib/ejson_lint.dart | 3 +++ packages/ejson_lint/lib/src/ejson_lint_base.dart | 3 +++ packages/ejson_lint/lib/src/lints/mismatched_getter_type.dart | 3 +++ packages/ejson_lint/lib/src/lints/missing_getter.dart | 3 +++ .../lib/src/lints/too_many_annotated_constructors.dart | 3 +++ 11 files changed, 33 insertions(+) diff --git a/packages/ejson/example/main.dart b/packages/ejson/example/main.dart index b1406394a..f44d0bb72 100644 --- a/packages/ejson/example/main.dart +++ b/packages/ejson/example/main.dart @@ -1,3 +1,6 @@ +// Copyright 2024 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + import 'dart:convert'; import 'package:ejson/ejson.dart'; diff --git a/packages/ejson/test/person.dart b/packages/ejson/test/person.dart index 3a627278e..2e588e5b2 100644 --- a/packages/ejson/test/person.dart +++ b/packages/ejson/test/person.dart @@ -1,3 +1,6 @@ +// Copyright 2024 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + import 'package:ejson/ejson.dart'; part 'person.g.dart'; diff --git a/packages/ejson_analyzer/lib/ejson_analyzer.dart b/packages/ejson_analyzer/lib/ejson_analyzer.dart index d60acfce4..6f1082d01 100644 --- a/packages/ejson_analyzer/lib/ejson_analyzer.dart +++ b/packages/ejson_analyzer/lib/ejson_analyzer.dart @@ -1,3 +1,6 @@ +// Copyright 2024 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + /// Support for doing something awesome. /// /// More dartdocs go here. diff --git a/packages/ejson_analyzer/lib/src/ejson_analyzer_base.dart b/packages/ejson_analyzer/lib/src/ejson_analyzer_base.dart index 3364099d3..39370ff2d 100644 --- a/packages/ejson_analyzer/lib/src/ejson_analyzer_base.dart +++ b/packages/ejson_analyzer/lib/src/ejson_analyzer_base.dart @@ -1,3 +1,6 @@ +// Copyright 2024 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + import 'package:analyzer/dart/element/element.dart'; import 'package:ejson_annotation/ejson_annotation.dart'; import 'package:source_gen/source_gen.dart'; diff --git a/packages/ejson_generator/lib/ejson_generator.dart b/packages/ejson_generator/lib/ejson_generator.dart index 8a9e071e9..7dd0d98fb 100644 --- a/packages/ejson_generator/lib/ejson_generator.dart +++ b/packages/ejson_generator/lib/ejson_generator.dart @@ -1 +1,4 @@ +// Copyright 2024 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + export 'src/builder.dart'; diff --git a/packages/ejson_lint/example/bin/example.dart b/packages/ejson_lint/example/bin/example.dart index e38d05f8f..6ed76f42b 100644 --- a/packages/ejson_lint/example/bin/example.dart +++ b/packages/ejson_lint/example/bin/example.dart @@ -1,3 +1,6 @@ +// Copyright 2024 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + import 'package:ejson_annotation/ejson_annotation.dart'; // This file is used to test lint rules using diff --git a/packages/ejson_lint/lib/ejson_lint.dart b/packages/ejson_lint/lib/ejson_lint.dart index 0014b7c2a..4014edccf 100644 --- a/packages/ejson_lint/lib/ejson_lint.dart +++ b/packages/ejson_lint/lib/ejson_lint.dart @@ -1 +1,4 @@ +// Copyright 2024 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + export 'src/ejson_lint_base.dart'; diff --git a/packages/ejson_lint/lib/src/ejson_lint_base.dart b/packages/ejson_lint/lib/src/ejson_lint_base.dart index c382ac2ee..e931818ab 100644 --- a/packages/ejson_lint/lib/src/ejson_lint_base.dart +++ b/packages/ejson_lint/lib/src/ejson_lint_base.dart @@ -1,3 +1,6 @@ +// Copyright 2024 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + import 'package:custom_lint_builder/custom_lint_builder.dart'; import 'lints/mismatched_getter_type.dart'; diff --git a/packages/ejson_lint/lib/src/lints/mismatched_getter_type.dart b/packages/ejson_lint/lib/src/lints/mismatched_getter_type.dart index 4b911a419..053806ce0 100644 --- a/packages/ejson_lint/lib/src/lints/mismatched_getter_type.dart +++ b/packages/ejson_lint/lib/src/lints/mismatched_getter_type.dart @@ -1,3 +1,6 @@ +// Copyright 2024 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/error/error.dart'; import 'package:analyzer/error/listener.dart'; diff --git a/packages/ejson_lint/lib/src/lints/missing_getter.dart b/packages/ejson_lint/lib/src/lints/missing_getter.dart index 724aba157..a9ac929f4 100644 --- a/packages/ejson_lint/lib/src/lints/missing_getter.dart +++ b/packages/ejson_lint/lib/src/lints/missing_getter.dart @@ -1,3 +1,6 @@ +// Copyright 2024 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/error/error.dart'; import 'package:analyzer/error/listener.dart'; diff --git a/packages/ejson_lint/lib/src/lints/too_many_annotated_constructors.dart b/packages/ejson_lint/lib/src/lints/too_many_annotated_constructors.dart index a1822e1b3..0015c84b2 100644 --- a/packages/ejson_lint/lib/src/lints/too_many_annotated_constructors.dart +++ b/packages/ejson_lint/lib/src/lints/too_many_annotated_constructors.dart @@ -1,3 +1,6 @@ +// Copyright 2024 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + import 'package:analyzer/error/error.dart'; import 'package:analyzer/error/listener.dart'; import 'package:custom_lint_builder/custom_lint_builder.dart'; From 684d288a7e07c65e2463cdc7d3aa73aebbc3c84d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Fri, 1 Mar 2024 14:17:33 +0100 Subject: [PATCH 138/153] Missing headers .. unrelated to ejson --- packages/realm/lib/realm.dart | 3 +++ packages/realm/tests/integration_test/all_tests.dart | 3 +++ packages/realm_dart/example/bin/myapp.dart | 3 +++ packages/realm_dart/lib/src/cli/generate/options.dart | 3 +++ packages/realm_dart/lib/src/init.dart | 3 +++ packages/realm_dart/test/baas_helper.dart | 3 +++ packages/realm_dart/tool/build_native.dart | 3 +++ packages/realm_generator/lib/src/pseudo_type.dart | 3 +++ 8 files changed, 24 insertions(+) diff --git a/packages/realm/lib/realm.dart b/packages/realm/lib/realm.dart index d8f89a2e2..13dbd21f3 100644 --- a/packages/realm/lib/realm.dart +++ b/packages/realm/lib/realm.dart @@ -1 +1,4 @@ +// Copyright 2024 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + export 'package:realm_dart/realm.dart'; diff --git a/packages/realm/tests/integration_test/all_tests.dart b/packages/realm/tests/integration_test/all_tests.dart index f2c0b8043..8cb86c25a 100644 --- a/packages/realm/tests/integration_test/all_tests.dart +++ b/packages/realm/tests/integration_test/all_tests.dart @@ -1,3 +1,6 @@ +// Copyright 2024 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + import 'dart:io'; import 'package:flutter/services.dart' show rootBundle; diff --git a/packages/realm_dart/example/bin/myapp.dart b/packages/realm_dart/example/bin/myapp.dart index 37a435195..7d733ad21 100644 --- a/packages/realm_dart/example/bin/myapp.dart +++ b/packages/realm_dart/example/bin/myapp.dart @@ -1,3 +1,6 @@ +// Copyright 2024 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + import 'dart:async'; import 'dart:convert'; import 'dart:io'; diff --git a/packages/realm_dart/lib/src/cli/generate/options.dart b/packages/realm_dart/lib/src/cli/generate/options.dart index a2d05b626..a426bdf20 100644 --- a/packages/realm_dart/lib/src/cli/generate/options.dart +++ b/packages/realm_dart/lib/src/cli/generate/options.dart @@ -1,3 +1,6 @@ +// Copyright 2024 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + import 'package:build_cli_annotations/build_cli_annotations.dart'; part 'options.g.dart'; diff --git a/packages/realm_dart/lib/src/init.dart b/packages/realm_dart/lib/src/init.dart index d554e7674..f354200a1 100644 --- a/packages/realm_dart/lib/src/init.dart +++ b/packages/realm_dart/lib/src/init.dart @@ -1,3 +1,6 @@ +// Copyright 2024 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + import 'dart:ffi'; import 'dart:io'; diff --git a/packages/realm_dart/test/baas_helper.dart b/packages/realm_dart/test/baas_helper.dart index 5c812adde..cf7f31336 100644 --- a/packages/realm_dart/test/baas_helper.dart +++ b/packages/realm_dart/test/baas_helper.dart @@ -1,3 +1,6 @@ +// Copyright 2024 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + import 'dart:io'; import 'package:test/test.dart' as testing; diff --git a/packages/realm_dart/tool/build_native.dart b/packages/realm_dart/tool/build_native.dart index bf0037df9..e95030db1 100644 --- a/packages/realm_dart/tool/build_native.dart +++ b/packages/realm_dart/tool/build_native.dart @@ -1,3 +1,6 @@ +// Copyright 2024 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + import 'dart:io' as io; import 'package:args/args.dart'; import 'package:collection/collection.dart'; diff --git a/packages/realm_generator/lib/src/pseudo_type.dart b/packages/realm_generator/lib/src/pseudo_type.dart index 8ad2067b3..61e5a8160 100644 --- a/packages/realm_generator/lib/src/pseudo_type.dart +++ b/packages/realm_generator/lib/src/pseudo_type.dart @@ -1,3 +1,6 @@ +// Copyright 2024 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + // ignore_for_file: implementation_imports import 'dart:mirrors'; From c0341b5f747122f87db9ebf63def2aec9c20af51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 5 Mar 2024 12:28:04 +0100 Subject: [PATCH 139/153] Implement PR feedback (part 1) --- .github/workflows/build-native.yml | 5 ++-- melos.yaml | 2 +- packages/ejson/lib/ejson.dart | 4 +-- packages/ejson/lib/src/decoding.dart | 19 ++++++------ packages/ejson/lib/src/encoding.dart | 14 +++++---- .../ejson_analyzer/lib/ejson_analyzer.dart | 6 ---- .../lib/src/ejson_analyzer_base.dart | 1 + .../test/ejson_analyzer_test.dart | 12 -------- .../lib/ejson_annotation.dart | 5 +++- packages/ejson_generator/lib/src/builder.dart | 2 ++ .../ejson_generator/lib/src/generator.dart | 29 ++++++++++++++----- packages/ejson_lint/example/bin/example.dart | 5 ++++ .../too_many_annotated_constructors.dart | 2 +- packages/ejson_lint/test/ejson_lint_test.dart | 12 -------- 14 files changed, 57 insertions(+), 61 deletions(-) delete mode 100644 packages/ejson_analyzer/test/ejson_analyzer_test.dart delete mode 100644 packages/ejson_lint/test/ejson_lint_test.dart diff --git a/.github/workflows/build-native.yml b/.github/workflows/build-native.yml index 616a36dd4..b013d965e 100644 --- a/.github/workflows/build-native.yml +++ b/.github/workflows/build-native.yml @@ -36,14 +36,13 @@ jobs: - name: Check cache id: check-cache - if: contains(github.head_ref, 'release/') != true uses: actions/cache@v4 with: path: ./packages/realm_dart/binary/** - key: binaries-${{ matrix.build }}-${{ inputs.runner }}-${{hashFiles('./packages/realm_dart/src/**')}}-kick + key: binaries-${{ matrix.build }}-${{ inputs.runner }}-${{hashFiles('./packages/realm_dart/src/**')}} - name: Setup Ninja - if: startsWith(matrix.build, 'android') || startsWith(matrix.build, 'linux') + if: steps.check-cache.outputs.cache-hit != 'true' && (startsWith(matrix.build, 'android') || startsWith(matrix.build, 'linux')) run: | sudo apt-get update -y sudo apt-get install -y ninja-build diff --git a/melos.yaml b/melos.yaml index 4e2ea43c9..1cbeab888 100644 --- a/melos.yaml +++ b/melos.yaml @@ -40,7 +40,7 @@ scripts: melos run build:binding && melos run build:dart - build:native: # TODO: mac specific and too simple + build:native: # make sure to set the CMAKE_PLATFORM and CMAKE_CONFIG environment variables exec: >- cmake --preset $CMAKE_PLATFORM && cmake --build --preset $CMAKE_PLATFORM --config $CMAKE_CONFIG -- -destination "generic/platform=macOS" diff --git a/packages/ejson/lib/ejson.dart b/packages/ejson/lib/ejson.dart index 9854bb6a8..417d781bf 100644 --- a/packages/ejson/lib/ejson.dart +++ b/packages/ejson/lib/ejson.dart @@ -2,8 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 export 'src/configuration.dart'; -export 'src/decoding.dart'; -export 'src/encoding.dart'; +export 'src/decoding.dart' hide customDecoders; +export 'src/encoding.dart' hide customEncoders; export 'src/types.dart'; export 'package:ejson_annotation/ejson_annotation.dart'; diff --git a/packages/ejson/lib/src/decoding.dart b/packages/ejson/lib/src/decoding.dart index 98238b431..10a7f4ed2 100644 --- a/packages/ejson/lib/src/decoding.dart +++ b/packages/ejson/lib/src/decoding.dart @@ -13,7 +13,7 @@ import 'package:type_plus/type_plus.dart'; import 'types.dart'; /// Predefined decoders for common types -const commonDecoders = { +const _commonDecoders = { dynamic: _decodeAny, Null: _decodeNull, Object: _decodeAny, @@ -39,7 +39,7 @@ const commonDecoders = { /// Custom decoders for specific types. Use `register` to add a custom decoder. final customDecoders = {}; -final decoders = () { +final _decoders = () { // register extra common types on first access undefinedOr(dynamic f) => f>(); TypePlus.addFactory(undefinedOr); @@ -49,19 +49,19 @@ final decoders = () { TypePlus.add(); TypePlus.add(); - return CombinedMapView([customDecoders, commonDecoders]); + return CombinedMapView([customDecoders, _commonDecoders]); }(); /// Converts [ejson] to type [T]. -/// +/// /// Throws [InvalidEJson] if [ejson] is not valid for [T]. /// Throws [MissingDecoder] if no decoder is registered for [T]. T fromEJson(EJsonValue ejson) { final type = T; final nullable = type.isNullable; - final decoder = nullable ? _decodeNullable : decoders[type.base]; + final decoder = nullable ? _decodeNullable : _decoders[type.base]; if (decoder == null) { - throw MissingDecoder(ejson, type); + throw MissingDecoder._(ejson, type); } final args = nullable ? [type.nonNull] : type.args; if (args.isEmpty) { @@ -72,7 +72,7 @@ T fromEJson(EJsonValue ejson) { // Important to return `T` as opposed to [Never] for type inference to work /// @nodoc -T raiseInvalidEJson(Object? value) => throw InvalidEJson(value, T); +T raiseInvalidEJson(Object? value) => throw InvalidEJson._(value, T); dynamic _decodeAny(EJsonValue ejson) { return switch (ejson) { @@ -147,7 +147,6 @@ Map _decodeDocument(EJsonValue ejson) { double _decodeDouble(EJsonValue ejson) { return switch (ejson) { double d => d, // relaxed mode - //{'\$numberDouble': double d} => d, {'\$numberDouble': String s} => switch (s) { 'NaN' => double.nan, 'Infinity' => double.infinity, @@ -254,7 +253,7 @@ class InvalidEJson implements Exception { final EJsonValue ejson; final Type type; - InvalidEJson(this.ejson, this.type); + InvalidEJson._(this.ejson, this.type); @override String toString() => 'Invalid EJson for $type: $ejson'; @@ -265,7 +264,7 @@ class MissingDecoder implements Exception { final EJsonValue ejson; final Type type; - MissingDecoder(this.ejson, this.type); + MissingDecoder._(this.ejson, this.type); @override String toString() => 'Missing decoder for $type'; diff --git a/packages/ejson/lib/src/encoding.dart b/packages/ejson/lib/src/encoding.dart index 7fccfbae3..ca589a8a7 100644 --- a/packages/ejson/lib/src/encoding.dart +++ b/packages/ejson/lib/src/encoding.dart @@ -18,8 +18,9 @@ var customEncoders = {}; var relaxed = false; @pragma('vm:prefer-inline') -/// Converts [value] to EJson -/// + +/// Converts [value] to EJson +/// /// Throws [MissingEncoder] if no encoder is registered for [value]'s type. EJsonValue toEJson(Object? value) => _encodeAny(value); @@ -32,7 +33,7 @@ EJsonValue _encodeAny(Object? value) { double d => _encodeDouble(d), int i => _encodeInt(i), Key k => _encodeKey(k), - Uint8List b => _encodeBinary(b, '00'), + Uint8List b => _encodeBinary(b, subtype: '00'), Iterable l => _encodeArray(l), Map m => _encodeDocument(m), ObjectId o => _encodeObjectId(o), @@ -99,9 +100,9 @@ EJsonValue _encodeSymbol(Symbol value) => {'\$symbol': value.name}; EJsonValue _encodeUndefined(Undefined undefined) => {'\$undefined': 1}; -EJsonValue _encodeUuid(Uuid uuid) => _encodeBinary(uuid.bytes.asUint8List(), "04"); +EJsonValue _encodeUuid(Uuid uuid) => _encodeBinary(uuid.bytes.asUint8List(), subtype: '04'); -EJsonValue _encodeBinary(Uint8List buffer, String subtype) => { +EJsonValue _encodeBinary(Uint8List buffer, {required String subtype}) => { '\$binary': { 'base64': base64.encode(buffer), 'subType': subtype, @@ -196,6 +197,7 @@ extension SymbolEJsonEncoderExtension on Symbol { /// Extract the name of this [Symbol] String get name { final full = toString(); + // remove leading 'Symbol("' and trailing '")' return full.substring(8, full.length - 2); } @@ -207,7 +209,7 @@ extension SymbolEJsonEncoderExtension on Symbol { extension Uint8ListEJsonEncoderExtension on Uint8List { /// Converts this [Uint8List] to EJson @pragma('vm:prefer-inline') - EJsonValue toEJson() => _encodeBinary(this, '00'); + EJsonValue toEJson() => _encodeBinary(this, subtype: '00'); } extension UndefinedEJsonEncoderExtension on Undefined { diff --git a/packages/ejson_analyzer/lib/ejson_analyzer.dart b/packages/ejson_analyzer/lib/ejson_analyzer.dart index 6f1082d01..e3e5d9351 100644 --- a/packages/ejson_analyzer/lib/ejson_analyzer.dart +++ b/packages/ejson_analyzer/lib/ejson_analyzer.dart @@ -1,10 +1,4 @@ // Copyright 2024 MongoDB, Inc. // SPDX-License-Identifier: Apache-2.0 -/// Support for doing something awesome. -/// -/// More dartdocs go here. - export 'src/ejson_analyzer_base.dart'; - -// TODO: Export any libraries intended for clients of this package. diff --git a/packages/ejson_analyzer/lib/src/ejson_analyzer_base.dart b/packages/ejson_analyzer/lib/src/ejson_analyzer_base.dart index 39370ff2d..c2b89c32b 100644 --- a/packages/ejson_analyzer/lib/src/ejson_analyzer_base.dart +++ b/packages/ejson_analyzer/lib/src/ejson_analyzer_base.dart @@ -7,4 +7,5 @@ import 'package:source_gen/source_gen.dart'; TypeChecker get typeChecker => TypeChecker.fromRuntime(EJson); +EJson getEJsonAnnotation(Element element) => typeChecker.firstAnnotationOfExact(element) as EJson; bool isEJsonAnnotated(Element element) => typeChecker.hasAnnotationOfExact(element); diff --git a/packages/ejson_analyzer/test/ejson_analyzer_test.dart b/packages/ejson_analyzer/test/ejson_analyzer_test.dart deleted file mode 100644 index d2942e3a1..000000000 --- a/packages/ejson_analyzer/test/ejson_analyzer_test.dart +++ /dev/null @@ -1,12 +0,0 @@ -// import 'package:ejson_analyzer/ejson_analyzer.dart'; -import 'package:test/test.dart'; - -void main() { - group('A group of tests', () { - setUp(() { - // Additional setup goes here. - }); - - test('First Test', () {}); - }); -} diff --git a/packages/ejson_annotation/lib/ejson_annotation.dart b/packages/ejson_annotation/lib/ejson_annotation.dart index 5da9bcd40..13c07621a 100644 --- a/packages/ejson_annotation/lib/ejson_annotation.dart +++ b/packages/ejson_annotation/lib/ejson_annotation.dart @@ -8,7 +8,10 @@ const ejson = EJson(); class EJson { final EJsonEncoder? encoder; final EJsonDecoder? decoder; - const EJson({this.encoder, this.decoder}); + const EJson() + : encoder = null, + decoder = null; + const EJson.custom({required EJsonEncoder this.encoder, required EJsonDecoder this.decoder}); } typedef EJsonDecoder = T Function(EJsonValue ejson); diff --git a/packages/ejson_generator/lib/src/builder.dart b/packages/ejson_generator/lib/src/builder.dart index 56a5cda2e..7078e4778 100644 --- a/packages/ejson_generator/lib/src/builder.dart +++ b/packages/ejson_generator/lib/src/builder.dart @@ -8,6 +8,8 @@ import 'generator.dart'; enum EJsonError { tooManyAnnotatedConstructors, + tooManyConstructorsOnAnnotatedClass, + noExplicitConstructor, missingGetter, mismatchedGetterType, } diff --git a/packages/ejson_generator/lib/src/generator.dart b/packages/ejson_generator/lib/src/generator.dart index b768130f1..709e10340 100644 --- a/packages/ejson_generator/lib/src/generator.dart +++ b/packages/ejson_generator/lib/src/generator.dart @@ -14,16 +14,18 @@ extension on EJsonError { EJsonError.tooManyAnnotatedConstructors => 'Too many annotated constructors', EJsonError.missingGetter => 'Missing getter', EJsonError.mismatchedGetterType => 'Mismatched getter type', + EJsonError.tooManyConstructorsOnAnnotatedClass => 'Too many constructors on annotated class', + EJsonError.noExplicitConstructor => 'No explicit constructor', }; Never raise() { - throw EJsonSourceError(this); + throw EJsonSourceError._(this); } } class EJsonSourceError extends InvalidGenerationSourceError { final EJsonError error; - EJsonSourceError(this.error) : super(error.message); + EJsonSourceError._(this.error) : super(error.message); } /// @nodoc @@ -39,20 +41,32 @@ class EJsonGenerator extends Generator { }); return annotated.map((x) { - final (cls, ctors) = x; + final (cls, annotatedCtors) = x; final className = cls.name; - if (ctors.length > 1) { + if (annotatedCtors.length > 1) { EJsonError.tooManyAnnotatedConstructors.raise(); } - if (ctors.isEmpty) { - // TODO! + if (annotatedCtors.isEmpty) { + // class is directly annotated, and no constructors are annotated. + final annotation = getEJsonAnnotation(cls); + if (annotation.decoder != null && annotation.encoder != null) { + return ''; // class has custom defined encoder and decoder + } + if (cls.constructors.length > 1) { + EJsonError.tooManyConstructorsOnAnnotatedClass.raise(); + } } - final ctor = ctors.single; + final ctor = annotatedCtors.singleOrNull ?? cls.constructors.singleOrNull; + if (ctor == null) { + // class is annotated, but has no explicit constructors + EJsonError.noExplicitConstructor.raise(); + } for (final p in ctor.parameters) { + // check that all ctor parameters have a getter with the same name and type final getter = cls.getGetter(p.name); if (getter == null) { EJsonError.missingGetter.raise(); @@ -62,6 +76,7 @@ class EJsonGenerator extends Generator { } } + // generate the codec pair log.info('Generating EJson for $className'); return ''' EJsonValue encode$className($className value) { diff --git a/packages/ejson_lint/example/bin/example.dart b/packages/ejson_lint/example/bin/example.dart index 6ed76f42b..d08534470 100644 --- a/packages/ejson_lint/example/bin/example.dart +++ b/packages/ejson_lint/example/bin/example.dart @@ -22,3 +22,8 @@ class Person { // expect_lint: too_many_annotated_constructors, missing_getter Person.third(String navn, int alder) : this(navn, age: alder); } + +@ejson +class Dog { + late final Person owner; +} diff --git a/packages/ejson_lint/lib/src/lints/too_many_annotated_constructors.dart b/packages/ejson_lint/lib/src/lints/too_many_annotated_constructors.dart index 0015c84b2..7dfc7575b 100644 --- a/packages/ejson_lint/lib/src/lints/too_many_annotated_constructors.dart +++ b/packages/ejson_lint/lib/src/lints/too_many_annotated_constructors.dart @@ -20,7 +20,7 @@ class TooManyAnnotatedConstructors extends DartLintRule { : super( code: const LintCode( name: 'too_many_annotated_constructors', - problemMessage: 'Only one constructor can be annotated with @EJson()', + problemMessage: 'Only one constructor can be annotated', errorSeverity: ErrorSeverity.ERROR, ), ); diff --git a/packages/ejson_lint/test/ejson_lint_test.dart b/packages/ejson_lint/test/ejson_lint_test.dart deleted file mode 100644 index c51c6a3f8..000000000 --- a/packages/ejson_lint/test/ejson_lint_test.dart +++ /dev/null @@ -1,12 +0,0 @@ -//import 'package:ejson_lint/ejson_lint.dart'; -import 'package:test/test.dart'; - -void main() { - group('A group of tests', () { - setUp(() { - // Additional setup goes here. - }); - - test('First Test', () {}); - }); -} From 1370a12e826415a1995396eb90b5c8bcb86e40b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 5 Mar 2024 14:58:51 +0100 Subject: [PATCH 140/153] Refactor int.toEJson to take an optional forcedFormat argument, and otherwise infer format from size of value --- packages/ejson/lib/src/encoding.dart | 24 ++++++++++++----- packages/ejson/test/ejson_test.dart | 28 +++++++++++--------- packages/ejson_generator/test/ctor_test.dart | 4 +-- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/packages/ejson/lib/src/encoding.dart b/packages/ejson/lib/src/encoding.dart index ca589a8a7..66e0d08a4 100644 --- a/packages/ejson/lib/src/encoding.dart +++ b/packages/ejson/lib/src/encoding.dart @@ -84,11 +84,23 @@ EJsonValue _encodeDouble(double value) { }; } -EJsonValue _encodeInt(int value, {bool long = true}) { - return switch (relaxed) { - true => value, - false => {'\$number${long ? 'Long' : 'Int'}': '$value'}, - }; +enum IntFormat { int32, int64 } + +EJsonValue _encodeInt(int value, {IntFormat? forcedFormat}) { + switch (relaxed) { + case true: + return value; + case false: + bool fitsInInt32 = value >= -0x80000000 && value < 0x80000000; + final format = forcedFormat ?? (fitsInInt32 ? IntFormat.int32 : IntFormat.int64); + if (!fitsInInt32 && format == IntFormat.int32) { + throw ArgumentError.value(value, 'value', 'Value does not fit in int32'); + } + return switch (format) { + IntFormat.int32 => {'\$numberInt': '$value'}, + IntFormat.int64 => {'\$numberLong': '$value'}, + }; + } } EJsonValue _encodeKey(Key key) => {'\$${key.name}Key': 1}; @@ -148,7 +160,7 @@ extension DoubleEJsonEncoderExtension on double { extension IntEJsonEncoderExtension on int { /// Converts this [int] to EJson @pragma('vm:prefer-inline') - EJsonValue toEJson({bool long = true}) => _encodeInt(this, long: long); + EJsonValue toEJson({IntFormat? forcedFormat}) => _encodeInt(this, forcedFormat: forcedFormat); } extension KeyEJsonEncoderExtension on Key { diff --git a/packages/ejson/test/ejson_test.dart b/packages/ejson/test/ejson_test.dart index 9647be5c2..92de7575d 100644 --- a/packages/ejson/test/ejson_test.dart +++ b/packages/ejson/test/ejson_test.dart @@ -72,6 +72,8 @@ void main() { // extension method, ie. not the fallback on Object?. expect(null.toEJson(), toEJson(null)); expect(1.toEJson(), toEJson(1)); + expect(1.toEJson(forcedFormat: IntFormat.int64), {'\$numberLong': '1'}); + expect(() => (1 << 33).toEJson(forcedFormat: IntFormat.int32), throwsArgumentError); expect(1.0.toEJson(), toEJson(1.0)); expect('a'.toEJson(), toEJson('a')); expect(true.toEJson(), toEJson(true)); @@ -130,7 +132,7 @@ void main() { final time = DateTime(1974, 4, 10, 2, 42, 12, 202); // no microseconds! _testCase(null, null); - _testCase(1, canonical ? {'\$numberLong': '1'} : 1); + _testCase(1, canonical ? {'\$numberInt': '1'} : 1); _testCase(1.0, canonical ? {'\$numberDouble': '1.0'} : 1.0); _testCase(double.infinity, {'\$numberDouble': 'Infinity'}); _testCase(double.negativeInfinity, {'\$numberDouble': '-Infinity'}); @@ -141,9 +143,9 @@ void main() { [1, 2, 3], canonical ? [ - {'\$numberLong': '1'}, - {'\$numberLong': '2'}, - {'\$numberLong': '3'}, + {'\$numberInt': '1'}, + {'\$numberInt': '2'}, + {'\$numberInt': '3'}, ] : [1, 2, 3], ); @@ -151,7 +153,7 @@ void main() { [1, 1.1], canonical ? [ - {'\$numberLong': '1'}, + {'\$numberInt': '1'}, {'\$numberDouble': '1.1'}, ] : [1, 1.1], @@ -160,9 +162,9 @@ void main() { [1, null, 3], canonical ? [ - {'\$numberLong': '1'}, + {'\$numberInt': '1'}, null, - {'\$numberLong': '3'}, + {'\$numberInt': '3'}, ] : [1, null, 3], ); @@ -171,7 +173,7 @@ void main() { canonical ? { 'a': 'abe', - 'b': {'\$numberLong': '1'}, + 'b': {'\$numberInt': '1'}, } : {'a': 'abe', 'b': 1}, ); @@ -189,9 +191,9 @@ void main() { _testCase(undefined, {'\$undefined': 1}); _testCase(const Undefined(), {'\$undefined': 1}); _testCase(Undefined(), {'\$undefined': 1}); - _testCase(const Defined(42), canonical ? {'\$numberLong': '42'} : 42); + _testCase(const Defined(42), canonical ? {'\$numberInt': '42'} : 42); _testCase(const Defined(null), null); - _testCase(Defined(42), canonical ? {'\$numberLong': '42'} : 42); + _testCase(Defined(42), canonical ? {'\$numberInt': '42'} : 42); _testCase(Defined(null), null); _testCase(ObjectId.fromValues(1, 2, 3), {'\$oid': '000000000000000002000003'}); final uuid = Uuid.v4(); @@ -211,7 +213,7 @@ void main() { 'a': { 'b': null, 'c': [ - {'\$numberLong': '1'}, + {'\$numberInt': '1'}, {'\$numberDouble': '1.1'}, null ] @@ -230,7 +232,7 @@ void main() { expect(x.toEJson(), {'\$undefined': 1}); x = Defined(42); - expect(x.toEJson(), relaxed ? 42 : {'\$numberLong': '42'}); + expect(x.toEJson(), relaxed ? 42 : {'\$numberInt': '42'}); x = Defined(null); expect(x.toEJson(), isNull); @@ -241,7 +243,7 @@ void main() { ); expect( - fromEJson>({'\$numberLong': '42'}), + fromEJson>({'\$numberInt': '42'}), Defined(42), ); diff --git a/packages/ejson_generator/test/ctor_test.dart b/packages/ejson_generator/test/ctor_test.dart index b4e68427b..956af1d99 100644 --- a/packages/ejson_generator/test/ctor_test.dart +++ b/packages/ejson_generator/test/ctor_test.dart @@ -107,14 +107,14 @@ void main() { _testCase(const Empty(), {}); _testCase(const Simple(42), { - 'i': {'\$numberLong': '42'} + 'i': {'\$numberInt': '42'} }); _testCase(Named.nameIt('foobar'), {'namedCtor': 'foobar'}); _testCase(const RequiredNamedParameters(requiredNamed: 'foobar'), {'requiredNamed': 'foobar'}); _testCase(OptionalNamedParameters(), {'optionalNamed': 'rabbit'}); _testCase(OptionalParameters(), {'optional': 'racoon'}); _testCase(const PrivateMembers(42), { - 'id': {'\$numberLong': '42'} + 'id': {'\$numberInt': '42'} }); final birthDate = DateTime.utc(1973); From 7cbf2118ecd57b22968c70ba5a234428f700a5d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 5 Mar 2024 17:03:17 +0100 Subject: [PATCH 141/153] Add toEJsonString and fromEJsonString convinience functions --- packages/ejson/lib/src/decoding.dart | 6 ++++++ packages/ejson/lib/src/encoding.dart | 5 +++++ packages/ejson/test/ejson_test.dart | 6 +++--- packages/ejson_annotation/lib/ejson_annotation.dart | 8 ++++---- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/packages/ejson/lib/src/decoding.dart b/packages/ejson/lib/src/decoding.dart index 10a7f4ed2..e3c326811 100644 --- a/packages/ejson/lib/src/decoding.dart +++ b/packages/ejson/lib/src/decoding.dart @@ -70,6 +70,12 @@ T fromEJson(EJsonValue ejson) { return decoder.callWith(typeArguments: args, parameters: [ejson]) as T; } +/// Parses [source] to [EJsonValue] and convert to type [T]. +/// +/// Throws [InvalidEJson] if [source] is not valid for [T]. +/// Throws [MissingDecoder] if no decoder is registered for [T]. +T fromEJsonString(String source) => fromEJson(jsonDecode(source)); + // Important to return `T` as opposed to [Never] for type inference to work /// @nodoc T raiseInvalidEJson(Object? value) => throw InvalidEJson._(value, T); diff --git a/packages/ejson/lib/src/encoding.dart b/packages/ejson/lib/src/encoding.dart index 66e0d08a4..48f37fa91 100644 --- a/packages/ejson/lib/src/encoding.dart +++ b/packages/ejson/lib/src/encoding.dart @@ -24,6 +24,11 @@ var relaxed = false; /// Throws [MissingEncoder] if no encoder is registered for [value]'s type. EJsonValue toEJson(Object? value) => _encodeAny(value); +/// Converts [value] to EJson string +/// +/// Throws [MissingEncoder] if no encoder is registered for [value]'s type. +String toEJsonString(Object? value) => jsonEncode(toEJson(value)); + EJsonValue _encodeAny(Object? value) { return switch (value) { null => null, diff --git a/packages/ejson/test/ejson_test.dart b/packages/ejson/test/ejson_test.dart index 92de7575d..49519a7b1 100644 --- a/packages/ejson/test/ejson_test.dart +++ b/packages/ejson/test/ejson_test.dart @@ -1,6 +1,8 @@ // Copyright 2023 MongoDB, Inc. // SPDX-License-Identifier: Apache-2.0 +// ignore_for_file: inference_failure_on_function_invocation + import 'dart:convert'; import 'package:ejson/ejson.dart'; @@ -33,9 +35,7 @@ void _testCase(T value, EJsonValue expected) { test('roundtrip $value of type $T as String', () { expect( - fromEJson( - jsonDecode(jsonEncode(toEJson(value))), // roundtrip as String - ), + fromEJsonString(toEJsonString(value)), // roundtrip as String value, ); }); diff --git a/packages/ejson_annotation/lib/ejson_annotation.dart b/packages/ejson_annotation/lib/ejson_annotation.dart index 13c07621a..96d5d6e24 100644 --- a/packages/ejson_annotation/lib/ejson_annotation.dart +++ b/packages/ejson_annotation/lib/ejson_annotation.dart @@ -2,15 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 /// Annotation to mark a class for extended json (ejson) serialization -const ejson = EJson(); +const ejson = EJson(); /// Annotation to mark a class for extended json (ejson) serialization class EJson { final EJsonEncoder? encoder; final EJsonDecoder? decoder; - const EJson() - : encoder = null, - decoder = null; + + const EJson._(this.encoder, this.decoder); + const EJson() : this._(null, null); const EJson.custom({required EJsonEncoder this.encoder, required EJsonDecoder this.decoder}); } From deccc53a1704c117afe01d98f82f3faba7f57a00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 5 Mar 2024 17:45:39 +0100 Subject: [PATCH 142/153] Missing tests for Uint8List aka binary with subtype '00' --- packages/ejson/test/ejson_test.dart | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/ejson/test/ejson_test.dart b/packages/ejson/test/ejson_test.dart index 49519a7b1..c775365d7 100644 --- a/packages/ejson/test/ejson_test.dart +++ b/packages/ejson/test/ejson_test.dart @@ -4,6 +4,7 @@ // ignore_for_file: inference_failure_on_function_invocation import 'dart:convert'; +import 'dart:typed_data'; import 'package:ejson/ejson.dart'; import 'package:objectid/objectid.dart'; @@ -116,6 +117,7 @@ void main() { _invalidTestCase(); _invalidTestCase(); _invalidTestCase(); + _invalidTestCase(); _invalidTestCase>(); _invalidTestCase(); @@ -200,6 +202,10 @@ void main() { _testCase(uuid, { '\$binary': {'base64': base64.encode(uuid.bytes.asUint8List()), 'subType': '04'} }); + final uint8list = Uint8List.fromList(List.generate(32, (i) => i)); + _testCase(uint8list, { + '\$binary': {'base64': base64.encode(uint8list), 'subType': '00'} + }); // a complex nested generic type _testCase?>>>( { From edf4caaed4933cfbfae7b7704f104059302641ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 5 Mar 2024 19:14:27 +0100 Subject: [PATCH 143/153] Fix Uint8List decoding bug --- packages/ejson/lib/src/decoding.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/ejson/lib/src/decoding.dart b/packages/ejson/lib/src/decoding.dart index e3c326811..3c808f6ec 100644 --- a/packages/ejson/lib/src/decoding.dart +++ b/packages/ejson/lib/src/decoding.dart @@ -47,6 +47,7 @@ final _decoders = () { TypePlus.addFactory((dynamic f) => f>(), superTypes: [undefinedOr]); TypePlus.add(); TypePlus.add(); + TypePlus.add(); TypePlus.add(); return CombinedMapView([customDecoders, _commonDecoders]); From 26c19471529281f92ca689de324af74c89e62ecc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 5 Mar 2024 19:07:07 +0100 Subject: [PATCH 144/153] Generate registerX function --- packages/ejson/test/ejson_test.dart | 2 +- packages/ejson/test/person.g.dart | 8 ++- packages/ejson_generator/lib/src/builder.dart | 8 --- .../ejson_generator/lib/src/generator.dart | 27 ++++---- .../ejson_generator/test/compile_test.dart | 8 ++- packages/ejson_generator/test/ctor_test.dart | 16 ++--- .../ejson_generator/test/ctor_test.g.dart | 68 ++++++++++++------- 7 files changed, 78 insertions(+), 59 deletions(-) diff --git a/packages/ejson/test/ejson_test.dart b/packages/ejson/test/ejson_test.dart index c775365d7..a0f77962d 100644 --- a/packages/ejson/test/ejson_test.dart +++ b/packages/ejson/test/ejson_test.dart @@ -263,7 +263,7 @@ void main() { }); group('custom types', () { - register(encodePerson, decodePerson); + registerPerson(); final person = Person( 'John', diff --git a/packages/ejson/test/person.g.dart b/packages/ejson/test/person.g.dart index afcbc866f..586efed81 100644 --- a/packages/ejson/test/person.g.dart +++ b/packages/ejson/test/person.g.dart @@ -6,7 +6,7 @@ part of 'person.dart'; // EJsonGenerator // ************************************************************************** -EJsonValue encodePerson(Person value) { +EJsonValue _encodePerson(Person value) { return { 'name': value.name.toEJson(), 'birthDate': value.birthDate.toEJson(), @@ -15,7 +15,7 @@ EJsonValue encodePerson(Person value) { }; } -Person decodePerson(EJsonValue ejson) { +Person _decodePerson(EJsonValue ejson) { return switch (ejson) { { 'name': EJsonValue name, @@ -31,5 +31,7 @@ Person decodePerson(EJsonValue ejson) { extension PersonEJsonEncoderExtension on Person { @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodePerson(this); + EJsonValue toEJson() => _encodePerson(this); } + +void registerPerson() => register(_encodePerson, _decodePerson); diff --git a/packages/ejson_generator/lib/src/builder.dart b/packages/ejson_generator/lib/src/builder.dart index 7078e4778..4f46b17db 100644 --- a/packages/ejson_generator/lib/src/builder.dart +++ b/packages/ejson_generator/lib/src/builder.dart @@ -6,14 +6,6 @@ import 'package:source_gen/source_gen.dart'; import 'generator.dart'; -enum EJsonError { - tooManyAnnotatedConstructors, - tooManyConstructorsOnAnnotatedClass, - noExplicitConstructor, - missingGetter, - mismatchedGetterType, -} - Builder getEJsonGenerator([BuilderOptions? options]) { return SharedPartBuilder([EJsonGenerator()], 'ejson'); } diff --git a/packages/ejson_generator/lib/src/generator.dart b/packages/ejson_generator/lib/src/generator.dart index 709e10340..66fe6fea5 100644 --- a/packages/ejson_generator/lib/src/generator.dart +++ b/packages/ejson_generator/lib/src/generator.dart @@ -6,17 +6,18 @@ import 'dart:async'; import 'package:analyzer/dart/element/element.dart'; import 'package:build/build.dart'; import 'package:ejson_analyzer/ejson_analyzer.dart'; -import 'package:ejson_generator/ejson_generator.dart'; import 'package:source_gen/source_gen.dart'; -extension on EJsonError { - String get message => switch (this) { - EJsonError.tooManyAnnotatedConstructors => 'Too many annotated constructors', - EJsonError.missingGetter => 'Missing getter', - EJsonError.mismatchedGetterType => 'Mismatched getter type', - EJsonError.tooManyConstructorsOnAnnotatedClass => 'Too many constructors on annotated class', - EJsonError.noExplicitConstructor => 'No explicit constructor', - }; +enum EJsonError { + tooManyAnnotatedConstructors('Too many annotated constructors'), + tooManyConstructorsOnAnnotatedClass('Too many constructors on annotated class'), + noExplicitConstructor('No explicit constructor'), + missingGetter('Missing getter'), + mismatchedGetterType('Mismatched getter type'); + + final String message; + + const EJsonError(this.message); Never raise() { throw EJsonSourceError._(this); @@ -79,13 +80,13 @@ class EJsonGenerator extends Generator { // generate the codec pair log.info('Generating EJson for $className'); return ''' - EJsonValue encode$className($className value) { + EJsonValue _encode$className($className value) { return { ${ctor.parameters.map((p) => "'${p.name}': value.${p.name}.toEJson()").join(',\n')} }; } - $className decode$className(EJsonValue ejson) { + $className _decode$className(EJsonValue ejson) { return switch (ejson) { ${decodePattern(ctor.parameters)} => $className${ctor.name.isEmpty ? '' : '.${ctor.name}'}( ${ctor.parameters.map((p) => "${p.isNamed ? '${p.name} : ' : ''}fromEJson(${p.name})").join(',\n')} @@ -96,8 +97,10 @@ class EJsonGenerator extends Generator { extension ${className}EJsonEncoderExtension on $className { @pragma('vm:prefer-inline') - EJsonValue toEJson() => encode$className(this); + EJsonValue toEJson() => _encode$className(this); } + + void register$className() => register(_encode$className, _decode$className); '''; }).join('\n\n'); } diff --git a/packages/ejson_generator/test/compile_test.dart b/packages/ejson_generator/test/compile_test.dart index 2146deff5..c4006b073 100644 --- a/packages/ejson_generator/test/compile_test.dart +++ b/packages/ejson_generator/test/compile_test.dart @@ -145,11 +145,11 @@ class Empty { // EJsonGenerator // ************************************************************************** -EJsonValue encodeEmpty(Empty value) { +EJsonValue _encodeEmpty(Empty value) { return {}; } -Empty decodeEmpty(EJsonValue ejson) { +Empty _decodeEmpty(EJsonValue ejson) { return switch (ejson) { Map m when m.isEmpty => Empty(), _ => raiseInvalidEJson(ejson), @@ -158,8 +158,10 @@ Empty decodeEmpty(EJsonValue ejson) { extension EmptyEJsonEncoderExtension on Empty { @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeEmpty(this); + EJsonValue toEJson() => _encodeEmpty(this); } + +void registerEmpty() => register(_encodeEmpty, _decodeEmpty); ''', ); }); diff --git a/packages/ejson_generator/test/ctor_test.dart b/packages/ejson_generator/test/ctor_test.dart index 956af1d99..e97641993 100644 --- a/packages/ejson_generator/test/ctor_test.dart +++ b/packages/ejson_generator/test/ctor_test.dart @@ -96,14 +96,14 @@ void _testCase(T value, EJsonValue expected) { void main() { group('ctors', () { - register(encodeEmpty, decodeEmpty); - register(encodeSimple, decodeSimple); - register(encodeNamed, decodeNamed); - register(encodeRequiredNamedParameters, decodeRequiredNamedParameters); - register(encodeOptionalNamedParameters, decodeOptionalNamedParameters); - register(encodeOptionalParameters, decodeOptionalParameters); - register(encodePrivateMembers, decodePrivateMembers); - register(encodePerson, decodePerson); + registerEmpty(); + registerSimple(); + registerNamed(); + registerRequiredNamedParameters(); + registerOptionalNamedParameters(); + registerOptionalParameters(); + registerPrivateMembers(); + registerPerson(); _testCase(const Empty(), {}); _testCase(const Simple(42), { diff --git a/packages/ejson_generator/test/ctor_test.g.dart b/packages/ejson_generator/test/ctor_test.g.dart index b36078ee1..c0d5dd4c4 100644 --- a/packages/ejson_generator/test/ctor_test.g.dart +++ b/packages/ejson_generator/test/ctor_test.g.dart @@ -6,11 +6,11 @@ part of 'ctor_test.dart'; // EJsonGenerator // ************************************************************************** -EJsonValue encodeEmpty(Empty value) { +EJsonValue _encodeEmpty(Empty value) { return {}; } -Empty decodeEmpty(EJsonValue ejson) { +Empty _decodeEmpty(EJsonValue ejson) { return switch (ejson) { Map m when m.isEmpty => Empty(), _ => raiseInvalidEJson(ejson), @@ -19,14 +19,16 @@ Empty decodeEmpty(EJsonValue ejson) { extension EmptyEJsonEncoderExtension on Empty { @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeEmpty(this); + EJsonValue toEJson() => _encodeEmpty(this); } -EJsonValue encodeSimple(Simple value) { +void registerEmpty() => register(_encodeEmpty, _decodeEmpty); + +EJsonValue _encodeSimple(Simple value) { return {'i': value.i.toEJson()}; } -Simple decodeSimple(EJsonValue ejson) { +Simple _decodeSimple(EJsonValue ejson) { return switch (ejson) { {'i': EJsonValue i} => Simple(fromEJson(i)), _ => raiseInvalidEJson(ejson), @@ -35,14 +37,16 @@ Simple decodeSimple(EJsonValue ejson) { extension SimpleEJsonEncoderExtension on Simple { @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeSimple(this); + EJsonValue toEJson() => _encodeSimple(this); } -EJsonValue encodeNamed(Named value) { +void registerSimple() => register(_encodeSimple, _decodeSimple); + +EJsonValue _encodeNamed(Named value) { return {'namedCtor': value.namedCtor.toEJson()}; } -Named decodeNamed(EJsonValue ejson) { +Named _decodeNamed(EJsonValue ejson) { return switch (ejson) { {'namedCtor': EJsonValue namedCtor} => Named.nameIt(fromEJson(namedCtor)), _ => raiseInvalidEJson(ejson), @@ -51,14 +55,16 @@ Named decodeNamed(EJsonValue ejson) { extension NamedEJsonEncoderExtension on Named { @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeNamed(this); + EJsonValue toEJson() => _encodeNamed(this); } -EJsonValue encodeRequiredNamedParameters(RequiredNamedParameters value) { +void registerNamed() => register(_encodeNamed, _decodeNamed); + +EJsonValue _encodeRequiredNamedParameters(RequiredNamedParameters value) { return {'requiredNamed': value.requiredNamed.toEJson()}; } -RequiredNamedParameters decodeRequiredNamedParameters(EJsonValue ejson) { +RequiredNamedParameters _decodeRequiredNamedParameters(EJsonValue ejson) { return switch (ejson) { {'requiredNamed': EJsonValue requiredNamed} => RequiredNamedParameters(requiredNamed: fromEJson(requiredNamed)), @@ -69,14 +75,17 @@ RequiredNamedParameters decodeRequiredNamedParameters(EJsonValue ejson) { extension RequiredNamedParametersEJsonEncoderExtension on RequiredNamedParameters { @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeRequiredNamedParameters(this); + EJsonValue toEJson() => _encodeRequiredNamedParameters(this); } -EJsonValue encodeOptionalNamedParameters(OptionalNamedParameters value) { +void registerRequiredNamedParameters() => + register(_encodeRequiredNamedParameters, _decodeRequiredNamedParameters); + +EJsonValue _encodeOptionalNamedParameters(OptionalNamedParameters value) { return {'optionalNamed': value.optionalNamed.toEJson()}; } -OptionalNamedParameters decodeOptionalNamedParameters(EJsonValue ejson) { +OptionalNamedParameters _decodeOptionalNamedParameters(EJsonValue ejson) { return switch (ejson) { {'optionalNamed': EJsonValue optionalNamed} => OptionalNamedParameters(optionalNamed: fromEJson(optionalNamed)), @@ -87,14 +96,17 @@ OptionalNamedParameters decodeOptionalNamedParameters(EJsonValue ejson) { extension OptionalNamedParametersEJsonEncoderExtension on OptionalNamedParameters { @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeOptionalNamedParameters(this); + EJsonValue toEJson() => _encodeOptionalNamedParameters(this); } -EJsonValue encodeOptionalParameters(OptionalParameters value) { +void registerOptionalNamedParameters() => + register(_encodeOptionalNamedParameters, _decodeOptionalNamedParameters); + +EJsonValue _encodeOptionalParameters(OptionalParameters value) { return {'optional': value.optional.toEJson()}; } -OptionalParameters decodeOptionalParameters(EJsonValue ejson) { +OptionalParameters _decodeOptionalParameters(EJsonValue ejson) { return switch (ejson) { {'optional': EJsonValue optional} => OptionalParameters(fromEJson(optional)), @@ -104,14 +116,17 @@ OptionalParameters decodeOptionalParameters(EJsonValue ejson) { extension OptionalParametersEJsonEncoderExtension on OptionalParameters { @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodeOptionalParameters(this); + EJsonValue toEJson() => _encodeOptionalParameters(this); } -EJsonValue encodePrivateMembers(PrivateMembers value) { +void registerOptionalParameters() => + register(_encodeOptionalParameters, _decodeOptionalParameters); + +EJsonValue _encodePrivateMembers(PrivateMembers value) { return {'id': value.id.toEJson()}; } -PrivateMembers decodePrivateMembers(EJsonValue ejson) { +PrivateMembers _decodePrivateMembers(EJsonValue ejson) { return switch (ejson) { {'id': EJsonValue id} => PrivateMembers(fromEJson(id)), _ => raiseInvalidEJson(ejson), @@ -120,10 +135,13 @@ PrivateMembers decodePrivateMembers(EJsonValue ejson) { extension PrivateMembersEJsonEncoderExtension on PrivateMembers { @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodePrivateMembers(this); + EJsonValue toEJson() => _encodePrivateMembers(this); } -EJsonValue encodePerson(Person value) { +void registerPrivateMembers() => + register(_encodePrivateMembers, _decodePrivateMembers); + +EJsonValue _encodePerson(Person value) { return { 'name': value.name.toEJson(), 'birthDate': value.birthDate.toEJson(), @@ -133,7 +151,7 @@ EJsonValue encodePerson(Person value) { }; } -Person decodePerson(EJsonValue ejson) { +Person _decodePerson(EJsonValue ejson) { return switch (ejson) { { 'name': EJsonValue name, @@ -150,5 +168,7 @@ Person decodePerson(EJsonValue ejson) { extension PersonEJsonEncoderExtension on Person { @pragma('vm:prefer-inline') - EJsonValue toEJson() => encodePerson(this); + EJsonValue toEJson() => _encodePerson(this); } + +void registerPerson() => register(_encodePerson, _decodePerson); From b7f5982bd6d31164811790b18a9be3b71e59d8cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 5 Mar 2024 20:19:32 +0100 Subject: [PATCH 145/153] Refactor realm_generator EJSON support a bit --- packages/realm/example/lib/main.realm.dart | 26 +- .../realm_dart/example/bin/myapp.realm.dart | 26 +- .../realm_dart/test/backlinks_test.realm.dart | 32 +- .../test/geospatial_test.realm.dart | 31 +- .../realm_dart/test/indexed_test.realm.dart | 51 +- .../realm_dart/test/migration_test.realm.dart | 51 +- .../realm_dart/test/realm_map_test.realm.dart | 71 +-- .../test/realm_object_test.realm.dart | 102 ++-- .../realm_dart/test/realm_set_test.realm.dart | 56 +- .../test/realm_value_test.realm.dart | 33 +- packages/realm_dart/test/test.realm.dart | 560 +++++++++--------- .../lib/src/realm_model_info.dart | 10 +- .../test/good_test_data/all_types.expected | 69 +-- .../another_mapto.expected_multi | 11 +- .../good_test_data/asymmetric_object.expected | 26 +- .../test/good_test_data/binary_type.expected | 13 +- .../embedded_annotations.expected | 24 +- .../good_test_data/embedded_objects.expected | 61 +- .../good_test_data/indexable_types.expected | 39 +- .../list_initialization.expected | 27 +- .../test/good_test_data/map.expected | 38 +- .../test/good_test_data/mapto.expected | 13 +- .../good_test_data/optional_argument.expected | 9 +- .../test/good_test_data/pinhole.expected | 9 +- .../test/good_test_data/primary_key.expected | 72 ++- .../test/good_test_data/realm_set.expected | 50 +- .../good_test_data/required_argument.expected | 9 +- ...uired_argument_with_default_value.expected | 9 +- .../user_defined_getter.expected | 9 +- 29 files changed, 814 insertions(+), 723 deletions(-) diff --git a/packages/realm/example/lib/main.realm.dart b/packages/realm/example/lib/main.realm.dart index 1849f5bda..dfecf73ff 100644 --- a/packages/realm/example/lib/main.realm.dart +++ b/packages/realm/example/lib/main.realm.dart @@ -57,16 +57,17 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { @override Car freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeCar(Car value) { + EJsonValue toEJson() { return { - 'make': toEJson(value.make), - 'model': toEJson(value.model), - 'kilometers': toEJson(value.kilometers), - 'owner': toEJson(value.owner), + 'make': make.toEJson(), + 'model': model.toEJson(), + 'kilometers': kilometers.toEJson(), + 'owner': owner.toEJson(), }; } - static Car _decodeCar(EJsonValue ejson) { + static EJsonValue _toEJson(Car value) => value.toEJson(); + static Car _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'make': EJsonValue make, @@ -86,7 +87,7 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Car._); - register(_encodeCar, _decodeCar); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Car, 'Car', [ SchemaProperty('make', RealmPropertyType.string), SchemaProperty('model', RealmPropertyType.string, optional: true), @@ -132,14 +133,15 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { @override Person freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodePerson(Person value) { + EJsonValue toEJson() { return { - 'name': toEJson(value.name), - 'age': toEJson(value.age), + 'name': name.toEJson(), + 'age': age.toEJson(), }; } - static Person _decodePerson(EJsonValue ejson) { + static EJsonValue _toEJson(Person value) => value.toEJson(); + static Person _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'name': EJsonValue name, @@ -155,7 +157,7 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Person._); - register(_encodePerson, _decodePerson); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Person, 'Person', [ SchemaProperty('name', RealmPropertyType.string), SchemaProperty('age', RealmPropertyType.int), diff --git a/packages/realm_dart/example/bin/myapp.realm.dart b/packages/realm_dart/example/bin/myapp.realm.dart index 4a0c80501..f6681c65e 100644 --- a/packages/realm_dart/example/bin/myapp.realm.dart +++ b/packages/realm_dart/example/bin/myapp.realm.dart @@ -57,16 +57,17 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { @override Car freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeCar(Car value) { + EJsonValue toEJson() { return { - 'make': toEJson(value.make), - 'model': toEJson(value.model), - 'kilometers': toEJson(value.kilometers), - 'owner': toEJson(value.owner), + 'make': make.toEJson(), + 'model': model.toEJson(), + 'kilometers': kilometers.toEJson(), + 'owner': owner.toEJson(), }; } - static Car _decodeCar(EJsonValue ejson) { + static EJsonValue _toEJson(Car value) => value.toEJson(); + static Car _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'make': EJsonValue make, @@ -86,7 +87,7 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Car._); - register(_encodeCar, _decodeCar); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Car, 'Car', [ SchemaProperty('make', RealmPropertyType.string), SchemaProperty('model', RealmPropertyType.string, optional: true), @@ -132,14 +133,15 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { @override Person freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodePerson(Person value) { + EJsonValue toEJson() { return { - 'name': toEJson(value.name), - 'age': toEJson(value.age), + 'name': name.toEJson(), + 'age': age.toEJson(), }; } - static Person _decodePerson(EJsonValue ejson) { + static EJsonValue _toEJson(Person value) => value.toEJson(); + static Person _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'name': EJsonValue name, @@ -155,7 +157,7 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Person._); - register(_encodePerson, _decodePerson); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Person, 'Person', [ SchemaProperty('name', RealmPropertyType.string), SchemaProperty('age', RealmPropertyType.int), diff --git a/packages/realm_dart/test/backlinks_test.realm.dart b/packages/realm_dart/test/backlinks_test.realm.dart index e7aeb4113..523961454 100644 --- a/packages/realm_dart/test/backlinks_test.realm.dart +++ b/packages/realm_dart/test/backlinks_test.realm.dart @@ -74,17 +74,18 @@ class Source extends _Source with RealmEntity, RealmObjectBase, RealmObject { @override Source freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeSource(Source value) { + EJsonValue toEJson() { return { - 'name': toEJson(value.name), - 'et mål': toEJson(value.oneTarget), - 'manyTargets': toEJson(value.manyTargets), - 'dynamisk mål': toEJson(value.dynamicTarget), - 'dynamicManyTargets': toEJson(value.dynamicManyTargets), + 'name': name.toEJson(), + 'et mål': oneTarget.toEJson(), + 'manyTargets': manyTargets.toEJson(), + 'dynamisk mål': dynamicTarget.toEJson(), + 'dynamicManyTargets': dynamicManyTargets.toEJson(), }; } - static Source _decodeSource(EJsonValue ejson) { + static EJsonValue _toEJson(Source value) => value.toEJson(); + static Source _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'name': EJsonValue name, @@ -104,7 +105,7 @@ class Source extends _Source with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Source._); - register(_encodeSource, _decodeSource); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Source, 'Source', [ SchemaProperty('name', RealmPropertyType.string), SchemaProperty('oneTarget', RealmPropertyType.object, @@ -181,16 +182,17 @@ class Target extends _Target with RealmEntity, RealmObjectBase, RealmObject { @override Target freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeTarget(Target value) { + EJsonValue toEJson() { return { - 'name': toEJson(value.name), - 'source': toEJson(value.source), - 'oneToMany': toEJson(value.oneToMany), - 'manyToMany': toEJson(value.manyToMany), + 'name': name.toEJson(), + 'source': source.toEJson(), + 'oneToMany': oneToMany.toEJson(), + 'manyToMany': manyToMany.toEJson(), }; } - static Target _decodeTarget(EJsonValue ejson) { + static EJsonValue _toEJson(Target value) => value.toEJson(); + static Target _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'name': EJsonValue name, @@ -208,7 +210,7 @@ class Target extends _Target with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Target._); - register(_encodeTarget, _decodeTarget); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Target, 'Target', [ SchemaProperty('name', RealmPropertyType.string), SchemaProperty('source', RealmPropertyType.object, diff --git a/packages/realm_dart/test/geospatial_test.realm.dart b/packages/realm_dart/test/geospatial_test.realm.dart index 13e0c832c..d893ca96a 100644 --- a/packages/realm_dart/test/geospatial_test.realm.dart +++ b/packages/realm_dart/test/geospatial_test.realm.dart @@ -44,14 +44,15 @@ class Location extends _Location @override Location freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeLocation(Location value) { + EJsonValue toEJson() { return { - 'type': toEJson(value.type), - 'coordinates': toEJson(value.coordinates), + 'type': type.toEJson(), + 'coordinates': coordinates.toEJson(), }; } - static Location _decodeLocation(EJsonValue ejson) { + static EJsonValue _toEJson(Location value) => value.toEJson(); + static Location _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'type': EJsonValue type, @@ -66,7 +67,7 @@ class Location extends _Location static final schema = () { RealmObjectBase.registerFactory(Location._); - register(_encodeLocation, _decodeLocation); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.embeddedObject, Location, 'Location', [ SchemaProperty('type', RealmPropertyType.string), SchemaProperty('coordinates', RealmPropertyType.double, @@ -106,14 +107,15 @@ class Restaurant extends _Restaurant @override Restaurant freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeRestaurant(Restaurant value) { + EJsonValue toEJson() { return { - 'name': toEJson(value.name), - 'location': toEJson(value.location), + 'name': name.toEJson(), + 'location': location.toEJson(), }; } - static Restaurant _decodeRestaurant(EJsonValue ejson) { + static EJsonValue _toEJson(Restaurant value) => value.toEJson(); + static Restaurant _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'name': EJsonValue name, @@ -129,7 +131,7 @@ class Restaurant extends _Restaurant static final schema = () { RealmObjectBase.registerFactory(Restaurant._); - register(_encodeRestaurant, _decodeRestaurant); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, Restaurant, 'Restaurant', [ SchemaProperty('name', RealmPropertyType.string, primaryKey: true), @@ -164,13 +166,14 @@ class LocationList extends _LocationList @override LocationList freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeLocationList(LocationList value) { + EJsonValue toEJson() { return { - 'locations': toEJson(value.locations), + 'locations': locations.toEJson(), }; } - static LocationList _decodeLocationList(EJsonValue ejson) { + static EJsonValue _toEJson(LocationList value) => value.toEJson(); + static LocationList _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'locations': EJsonValue locations, @@ -182,7 +185,7 @@ class LocationList extends _LocationList static final schema = () { RealmObjectBase.registerFactory(LocationList._); - register(_encodeLocationList, _decodeLocationList); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, LocationList, 'LocationList', [ SchemaProperty('locations', RealmPropertyType.object, diff --git a/packages/realm_dart/test/indexed_test.realm.dart b/packages/realm_dart/test/indexed_test.realm.dart index 57da726e1..3de4917fd 100644 --- a/packages/realm_dart/test/indexed_test.realm.dart +++ b/packages/realm_dart/test/indexed_test.realm.dart @@ -67,18 +67,19 @@ class WithIndexes extends _WithIndexes @override WithIndexes freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeWithIndexes(WithIndexes value) { + EJsonValue toEJson() { return { - 'anInt': toEJson(value.anInt), - 'aBool': toEJson(value.aBool), - 'string': toEJson(value.string), - 'timestamp': toEJson(value.timestamp), - 'objectId': toEJson(value.objectId), - 'uuid': toEJson(value.uuid), + 'anInt': anInt.toEJson(), + 'aBool': aBool.toEJson(), + 'string': string.toEJson(), + 'timestamp': timestamp.toEJson(), + 'objectId': objectId.toEJson(), + 'uuid': uuid.toEJson(), }; } - static WithIndexes _decodeWithIndexes(EJsonValue ejson) { + static EJsonValue _toEJson(WithIndexes value) => value.toEJson(); + static WithIndexes _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'anInt': EJsonValue anInt, @@ -102,7 +103,7 @@ class WithIndexes extends _WithIndexes static final schema = () { RealmObjectBase.registerFactory(WithIndexes._); - register(_encodeWithIndexes, _decodeWithIndexes); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, WithIndexes, 'WithIndexes', [ SchemaProperty('anInt', RealmPropertyType.int, @@ -181,18 +182,19 @@ class NoIndexes extends _NoIndexes @override NoIndexes freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeNoIndexes(NoIndexes value) { + EJsonValue toEJson() { return { - 'anInt': toEJson(value.anInt), - 'aBool': toEJson(value.aBool), - 'string': toEJson(value.string), - 'timestamp': toEJson(value.timestamp), - 'objectId': toEJson(value.objectId), - 'uuid': toEJson(value.uuid), + 'anInt': anInt.toEJson(), + 'aBool': aBool.toEJson(), + 'string': string.toEJson(), + 'timestamp': timestamp.toEJson(), + 'objectId': objectId.toEJson(), + 'uuid': uuid.toEJson(), }; } - static NoIndexes _decodeNoIndexes(EJsonValue ejson) { + static EJsonValue _toEJson(NoIndexes value) => value.toEJson(); + static NoIndexes _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'anInt': EJsonValue anInt, @@ -216,7 +218,7 @@ class NoIndexes extends _NoIndexes static final schema = () { RealmObjectBase.registerFactory(NoIndexes._); - register(_encodeNoIndexes, _decodeNoIndexes); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, NoIndexes, 'NoIndexes', [ SchemaProperty('anInt', RealmPropertyType.int), SchemaProperty('aBool', RealmPropertyType.bool), @@ -267,15 +269,16 @@ class ObjectWithFTSIndex extends _ObjectWithFTSIndex ObjectWithFTSIndex freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeObjectWithFTSIndex(ObjectWithFTSIndex value) { + EJsonValue toEJson() { return { - 'title': toEJson(value.title), - 'summary': toEJson(value.summary), - 'nullableSummary': toEJson(value.nullableSummary), + 'title': title.toEJson(), + 'summary': summary.toEJson(), + 'nullableSummary': nullableSummary.toEJson(), }; } - static ObjectWithFTSIndex _decodeObjectWithFTSIndex(EJsonValue ejson) { + static EJsonValue _toEJson(ObjectWithFTSIndex value) => value.toEJson(); + static ObjectWithFTSIndex _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'title': EJsonValue title, @@ -293,7 +296,7 @@ class ObjectWithFTSIndex extends _ObjectWithFTSIndex static final schema = () { RealmObjectBase.registerFactory(ObjectWithFTSIndex._); - register(_encodeObjectWithFTSIndex, _decodeObjectWithFTSIndex); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, ObjectWithFTSIndex, 'ObjectWithFTSIndex', [ SchemaProperty('title', RealmPropertyType.string), diff --git a/packages/realm_dart/test/migration_test.realm.dart b/packages/realm_dart/test/migration_test.realm.dart index 3c3b98c01..5a073d939 100644 --- a/packages/realm_dart/test/migration_test.realm.dart +++ b/packages/realm_dart/test/migration_test.realm.dart @@ -29,13 +29,14 @@ class PersonIntName extends _PersonIntName @override PersonIntName freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodePersonIntName(PersonIntName value) { + EJsonValue toEJson() { return { - 'name': toEJson(value.name), + 'name': name.toEJson(), }; } - static PersonIntName _decodePersonIntName(EJsonValue ejson) { + static EJsonValue _toEJson(PersonIntName value) => value.toEJson(); + static PersonIntName _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'name': EJsonValue name, @@ -49,7 +50,7 @@ class PersonIntName extends _PersonIntName static final schema = () { RealmObjectBase.registerFactory(PersonIntName._); - register(_encodePersonIntName, _decodePersonIntName); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, PersonIntName, 'Person', [ SchemaProperty('name', RealmPropertyType.int), ]); @@ -86,14 +87,15 @@ class StudentV1 extends _StudentV1 @override StudentV1 freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeStudentV1(StudentV1 value) { + EJsonValue toEJson() { return { - 'name': toEJson(value.name), - 'yearOfBirth': toEJson(value.yearOfBirth), + 'name': name.toEJson(), + 'yearOfBirth': yearOfBirth.toEJson(), }; } - static StudentV1 _decodeStudentV1(EJsonValue ejson) { + static EJsonValue _toEJson(StudentV1 value) => value.toEJson(); + static StudentV1 _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'name': EJsonValue name, @@ -109,7 +111,7 @@ class StudentV1 extends _StudentV1 static final schema = () { RealmObjectBase.registerFactory(StudentV1._); - register(_encodeStudentV1, _decodeStudentV1); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, StudentV1, 'Student', [ SchemaProperty('name', RealmPropertyType.string, primaryKey: true), SchemaProperty('yearOfBirth', RealmPropertyType.int, optional: true), @@ -147,14 +149,15 @@ class MyObjectWithTypo extends _MyObjectWithTypo MyObjectWithTypo freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeMyObjectWithTypo(MyObjectWithTypo value) { + EJsonValue toEJson() { return { - 'nmae': toEJson(value.nmae), - 'vlaue': toEJson(value.vlaue), + 'nmae': nmae.toEJson(), + 'vlaue': vlaue.toEJson(), }; } - static MyObjectWithTypo _decodeMyObjectWithTypo(EJsonValue ejson) { + static EJsonValue _toEJson(MyObjectWithTypo value) => value.toEJson(); + static MyObjectWithTypo _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'nmae': EJsonValue nmae, @@ -170,7 +173,7 @@ class MyObjectWithTypo extends _MyObjectWithTypo static final schema = () { RealmObjectBase.registerFactory(MyObjectWithTypo._); - register(_encodeMyObjectWithTypo, _decodeMyObjectWithTypo); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, MyObjectWithTypo, 'MyObject', [ SchemaProperty('nmae', RealmPropertyType.string), @@ -209,14 +212,15 @@ class MyObjectWithoutTypo extends _MyObjectWithoutTypo MyObjectWithoutTypo freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeMyObjectWithoutTypo(MyObjectWithoutTypo value) { + EJsonValue toEJson() { return { - 'name': toEJson(value.name), - 'value': toEJson(value.value), + 'name': name.toEJson(), + 'value': value.toEJson(), }; } - static MyObjectWithoutTypo _decodeMyObjectWithoutTypo(EJsonValue ejson) { + static EJsonValue _toEJson(MyObjectWithoutTypo value) => value.toEJson(); + static MyObjectWithoutTypo _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'name': EJsonValue name, @@ -232,7 +236,7 @@ class MyObjectWithoutTypo extends _MyObjectWithoutTypo static final schema = () { RealmObjectBase.registerFactory(MyObjectWithoutTypo._); - register(_encodeMyObjectWithoutTypo, _decodeMyObjectWithoutTypo); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, MyObjectWithoutTypo, 'MyObject', [ SchemaProperty('name', RealmPropertyType.string), @@ -264,13 +268,14 @@ class MyObjectWithoutValue extends _MyObjectWithoutValue MyObjectWithoutValue freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeMyObjectWithoutValue(MyObjectWithoutValue value) { + EJsonValue toEJson() { return { - 'name': toEJson(value.name), + 'name': name.toEJson(), }; } - static MyObjectWithoutValue _decodeMyObjectWithoutValue(EJsonValue ejson) { + static EJsonValue _toEJson(MyObjectWithoutValue value) => value.toEJson(); + static MyObjectWithoutValue _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'name': EJsonValue name, @@ -284,7 +289,7 @@ class MyObjectWithoutValue extends _MyObjectWithoutValue static final schema = () { RealmObjectBase.registerFactory(MyObjectWithoutValue._); - register(_encodeMyObjectWithoutValue, _decodeMyObjectWithoutValue); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, MyObjectWithoutValue, 'MyObject', [ SchemaProperty('name', RealmPropertyType.string), diff --git a/packages/realm_dart/test/realm_map_test.realm.dart b/packages/realm_dart/test/realm_map_test.realm.dart index 748061bf3..de72a8226 100644 --- a/packages/realm_dart/test/realm_map_test.realm.dart +++ b/packages/realm_dart/test/realm_map_test.realm.dart @@ -35,14 +35,15 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { @override Car freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeCar(Car value) { + EJsonValue toEJson() { return { - 'make': toEJson(value.make), - 'color': toEJson(value.color), + 'make': make.toEJson(), + 'color': color.toEJson(), }; } - static Car _decodeCar(EJsonValue ejson) { + static EJsonValue _toEJson(Car value) => value.toEJson(); + static Car _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'make': EJsonValue make, @@ -58,7 +59,7 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Car._); - register(_encodeCar, _decodeCar); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Car, 'Car', [ SchemaProperty('make', RealmPropertyType.string, primaryKey: true), SchemaProperty('color', RealmPropertyType.string, optional: true), @@ -88,13 +89,14 @@ class EmbeddedValue extends _EmbeddedValue @override EmbeddedValue freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeEmbeddedValue(EmbeddedValue value) { + EJsonValue toEJson() { return { - 'intValue': toEJson(value.intValue), + 'intValue': intValue.toEJson(), }; } - static EmbeddedValue _decodeEmbeddedValue(EJsonValue ejson) { + static EJsonValue _toEJson(EmbeddedValue value) => value.toEJson(); + static EmbeddedValue _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'intValue': EJsonValue intValue, @@ -108,7 +110,7 @@ class EmbeddedValue extends _EmbeddedValue static final schema = () { RealmObjectBase.registerFactory(EmbeddedValue._); - register(_encodeEmbeddedValue, _decodeEmbeddedValue); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.embeddedObject, EmbeddedValue, 'EmbeddedValue', [ SchemaProperty('intValue', RealmPropertyType.int), @@ -354,34 +356,35 @@ class TestRealmMaps extends _TestRealmMaps @override TestRealmMaps freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeTestRealmMaps(TestRealmMaps value) { + EJsonValue toEJson() { return { - 'key': toEJson(value.key), - 'boolMap': toEJson(value.boolMap), - 'intMap': toEJson(value.intMap), - 'stringMap': toEJson(value.stringMap), - 'doubleMap': toEJson(value.doubleMap), - 'dateTimeMap': toEJson(value.dateTimeMap), - 'objectIdMap': toEJson(value.objectIdMap), - 'uuidMap': toEJson(value.uuidMap), - 'binaryMap': toEJson(value.binaryMap), - 'decimalMap': toEJson(value.decimalMap), - 'nullableBoolMap': toEJson(value.nullableBoolMap), - 'nullableIntMap': toEJson(value.nullableIntMap), - 'nullableStringMap': toEJson(value.nullableStringMap), - 'nullableDoubleMap': toEJson(value.nullableDoubleMap), - 'nullableDateTimeMap': toEJson(value.nullableDateTimeMap), - 'nullableObjectIdMap': toEJson(value.nullableObjectIdMap), - 'nullableUuidMap': toEJson(value.nullableUuidMap), - 'nullableBinaryMap': toEJson(value.nullableBinaryMap), - 'nullableDecimalMap': toEJson(value.nullableDecimalMap), - 'objectsMap': toEJson(value.objectsMap), - 'embeddedMap': toEJson(value.embeddedMap), - 'mixedMap': toEJson(value.mixedMap), + 'key': key.toEJson(), + 'boolMap': boolMap.toEJson(), + 'intMap': intMap.toEJson(), + 'stringMap': stringMap.toEJson(), + 'doubleMap': doubleMap.toEJson(), + 'dateTimeMap': dateTimeMap.toEJson(), + 'objectIdMap': objectIdMap.toEJson(), + 'uuidMap': uuidMap.toEJson(), + 'binaryMap': binaryMap.toEJson(), + 'decimalMap': decimalMap.toEJson(), + 'nullableBoolMap': nullableBoolMap.toEJson(), + 'nullableIntMap': nullableIntMap.toEJson(), + 'nullableStringMap': nullableStringMap.toEJson(), + 'nullableDoubleMap': nullableDoubleMap.toEJson(), + 'nullableDateTimeMap': nullableDateTimeMap.toEJson(), + 'nullableObjectIdMap': nullableObjectIdMap.toEJson(), + 'nullableUuidMap': nullableUuidMap.toEJson(), + 'nullableBinaryMap': nullableBinaryMap.toEJson(), + 'nullableDecimalMap': nullableDecimalMap.toEJson(), + 'objectsMap': objectsMap.toEJson(), + 'embeddedMap': embeddedMap.toEJson(), + 'mixedMap': mixedMap.toEJson(), }; } - static TestRealmMaps _decodeTestRealmMaps(EJsonValue ejson) { + static EJsonValue _toEJson(TestRealmMaps value) => value.toEJson(); + static TestRealmMaps _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'key': EJsonValue key, @@ -416,7 +419,7 @@ class TestRealmMaps extends _TestRealmMaps static final schema = () { RealmObjectBase.registerFactory(TestRealmMaps._); - register(_encodeTestRealmMaps, _decodeTestRealmMaps); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, TestRealmMaps, 'TestRealmMaps', [ SchemaProperty('key', RealmPropertyType.int, primaryKey: true), diff --git a/packages/realm_dart/test/realm_object_test.realm.dart b/packages/realm_dart/test/realm_object_test.realm.dart index 14db8fac7..1a5d90c55 100644 --- a/packages/realm_dart/test/realm_object_test.realm.dart +++ b/packages/realm_dart/test/realm_object_test.realm.dart @@ -30,13 +30,14 @@ class ObjectIdPrimaryKey extends _ObjectIdPrimaryKey ObjectIdPrimaryKey freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeObjectIdPrimaryKey(ObjectIdPrimaryKey value) { + EJsonValue toEJson() { return { - 'id': toEJson(value.id), + 'id': id.toEJson(), }; } - static ObjectIdPrimaryKey _decodeObjectIdPrimaryKey(EJsonValue ejson) { + static EJsonValue _toEJson(ObjectIdPrimaryKey value) => value.toEJson(); + static ObjectIdPrimaryKey _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'id': EJsonValue id, @@ -50,7 +51,7 @@ class ObjectIdPrimaryKey extends _ObjectIdPrimaryKey static final schema = () { RealmObjectBase.registerFactory(ObjectIdPrimaryKey._); - register(_encodeObjectIdPrimaryKey, _decodeObjectIdPrimaryKey); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, ObjectIdPrimaryKey, 'ObjectIdPrimaryKey', [ SchemaProperty('id', RealmPropertyType.objectid, primaryKey: true), @@ -81,15 +82,15 @@ class NullableObjectIdPrimaryKey extends _NullableObjectIdPrimaryKey NullableObjectIdPrimaryKey freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeNullableObjectIdPrimaryKey( - NullableObjectIdPrimaryKey value) { + EJsonValue toEJson() { return { - 'id': toEJson(value.id), + 'id': id.toEJson(), }; } - static NullableObjectIdPrimaryKey _decodeNullableObjectIdPrimaryKey( - EJsonValue ejson) { + static EJsonValue _toEJson(NullableObjectIdPrimaryKey value) => + value.toEJson(); + static NullableObjectIdPrimaryKey _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'id': EJsonValue id, @@ -103,8 +104,7 @@ class NullableObjectIdPrimaryKey extends _NullableObjectIdPrimaryKey static final schema = () { RealmObjectBase.registerFactory(NullableObjectIdPrimaryKey._); - register( - _encodeNullableObjectIdPrimaryKey, _decodeNullableObjectIdPrimaryKey); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, NullableObjectIdPrimaryKey, 'NullableObjectIdPrimaryKey', [ SchemaProperty('id', RealmPropertyType.objectid, @@ -135,13 +135,14 @@ class IntPrimaryKey extends _IntPrimaryKey @override IntPrimaryKey freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeIntPrimaryKey(IntPrimaryKey value) { + EJsonValue toEJson() { return { - 'id': toEJson(value.id), + 'id': id.toEJson(), }; } - static IntPrimaryKey _decodeIntPrimaryKey(EJsonValue ejson) { + static EJsonValue _toEJson(IntPrimaryKey value) => value.toEJson(); + static IntPrimaryKey _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'id': EJsonValue id, @@ -155,7 +156,7 @@ class IntPrimaryKey extends _IntPrimaryKey static final schema = () { RealmObjectBase.registerFactory(IntPrimaryKey._); - register(_encodeIntPrimaryKey, _decodeIntPrimaryKey); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, IntPrimaryKey, 'IntPrimaryKey', [ SchemaProperty('id', RealmPropertyType.int, primaryKey: true), @@ -186,13 +187,14 @@ class NullableIntPrimaryKey extends _NullableIntPrimaryKey NullableIntPrimaryKey freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeNullableIntPrimaryKey(NullableIntPrimaryKey value) { + EJsonValue toEJson() { return { - 'id': toEJson(value.id), + 'id': id.toEJson(), }; } - static NullableIntPrimaryKey _decodeNullableIntPrimaryKey(EJsonValue ejson) { + static EJsonValue _toEJson(NullableIntPrimaryKey value) => value.toEJson(); + static NullableIntPrimaryKey _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'id': EJsonValue id, @@ -206,7 +208,7 @@ class NullableIntPrimaryKey extends _NullableIntPrimaryKey static final schema = () { RealmObjectBase.registerFactory(NullableIntPrimaryKey._); - register(_encodeNullableIntPrimaryKey, _decodeNullableIntPrimaryKey); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, NullableIntPrimaryKey, 'NullableIntPrimaryKey', [ SchemaProperty('id', RealmPropertyType.int, @@ -238,13 +240,14 @@ class StringPrimaryKey extends _StringPrimaryKey StringPrimaryKey freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeStringPrimaryKey(StringPrimaryKey value) { + EJsonValue toEJson() { return { - 'id': toEJson(value.id), + 'id': id.toEJson(), }; } - static StringPrimaryKey _decodeStringPrimaryKey(EJsonValue ejson) { + static EJsonValue _toEJson(StringPrimaryKey value) => value.toEJson(); + static StringPrimaryKey _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'id': EJsonValue id, @@ -258,7 +261,7 @@ class StringPrimaryKey extends _StringPrimaryKey static final schema = () { RealmObjectBase.registerFactory(StringPrimaryKey._); - register(_encodeStringPrimaryKey, _decodeStringPrimaryKey); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, StringPrimaryKey, 'StringPrimaryKey', [ SchemaProperty('id', RealmPropertyType.string, primaryKey: true), @@ -289,15 +292,14 @@ class NullableStringPrimaryKey extends _NullableStringPrimaryKey NullableStringPrimaryKey freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeNullableStringPrimaryKey( - NullableStringPrimaryKey value) { + EJsonValue toEJson() { return { - 'id': toEJson(value.id), + 'id': id.toEJson(), }; } - static NullableStringPrimaryKey _decodeNullableStringPrimaryKey( - EJsonValue ejson) { + static EJsonValue _toEJson(NullableStringPrimaryKey value) => value.toEJson(); + static NullableStringPrimaryKey _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'id': EJsonValue id, @@ -311,7 +313,7 @@ class NullableStringPrimaryKey extends _NullableStringPrimaryKey static final schema = () { RealmObjectBase.registerFactory(NullableStringPrimaryKey._); - register(_encodeNullableStringPrimaryKey, _decodeNullableStringPrimaryKey); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, NullableStringPrimaryKey, 'NullableStringPrimaryKey', [ SchemaProperty('id', RealmPropertyType.string, @@ -342,13 +344,14 @@ class UuidPrimaryKey extends _UuidPrimaryKey @override UuidPrimaryKey freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeUuidPrimaryKey(UuidPrimaryKey value) { + EJsonValue toEJson() { return { - 'id': toEJson(value.id), + 'id': id.toEJson(), }; } - static UuidPrimaryKey _decodeUuidPrimaryKey(EJsonValue ejson) { + static EJsonValue _toEJson(UuidPrimaryKey value) => value.toEJson(); + static UuidPrimaryKey _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'id': EJsonValue id, @@ -362,7 +365,7 @@ class UuidPrimaryKey extends _UuidPrimaryKey static final schema = () { RealmObjectBase.registerFactory(UuidPrimaryKey._); - register(_encodeUuidPrimaryKey, _decodeUuidPrimaryKey); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, UuidPrimaryKey, 'UuidPrimaryKey', [ SchemaProperty('id', RealmPropertyType.uuid, primaryKey: true), @@ -393,15 +396,14 @@ class NullableUuidPrimaryKey extends _NullableUuidPrimaryKey NullableUuidPrimaryKey freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeNullableUuidPrimaryKey( - NullableUuidPrimaryKey value) { + EJsonValue toEJson() { return { - 'id': toEJson(value.id), + 'id': id.toEJson(), }; } - static NullableUuidPrimaryKey _decodeNullableUuidPrimaryKey( - EJsonValue ejson) { + static EJsonValue _toEJson(NullableUuidPrimaryKey value) => value.toEJson(); + static NullableUuidPrimaryKey _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'id': EJsonValue id, @@ -415,7 +417,7 @@ class NullableUuidPrimaryKey extends _NullableUuidPrimaryKey static final schema = () { RealmObjectBase.registerFactory(NullableUuidPrimaryKey._); - register(_encodeNullableUuidPrimaryKey, _decodeNullableUuidPrimaryKey); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, NullableUuidPrimaryKey, 'NullableUuidPrimaryKey', [ SchemaProperty('id', RealmPropertyType.uuid, @@ -450,15 +452,14 @@ class RemappedFromAnotherFile extends _RemappedFromAnotherFile RemappedFromAnotherFile freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeRemappedFromAnotherFile( - RemappedFromAnotherFile value) { + EJsonValue toEJson() { return { - 'property with spaces': toEJson(value.linkToAnotherClass), + 'property with spaces': linkToAnotherClass.toEJson(), }; } - static RemappedFromAnotherFile _decodeRemappedFromAnotherFile( - EJsonValue ejson) { + static EJsonValue _toEJson(RemappedFromAnotherFile value) => value.toEJson(); + static RemappedFromAnotherFile _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'property with spaces': EJsonValue linkToAnotherClass, @@ -472,7 +473,7 @@ class RemappedFromAnotherFile extends _RemappedFromAnotherFile static final schema = () { RealmObjectBase.registerFactory(RemappedFromAnotherFile._); - register(_encodeRemappedFromAnotherFile, _decodeRemappedFromAnotherFile); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, RemappedFromAnotherFile, 'class with spaces', [ SchemaProperty('linkToAnotherClass', RealmPropertyType.object, @@ -512,14 +513,15 @@ class BoolValue extends _BoolValue @override BoolValue freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeBoolValue(BoolValue value) { + EJsonValue toEJson() { return { - 'key': toEJson(value.key), - 'value': toEJson(value.value), + 'key': key.toEJson(), + 'value': value.toEJson(), }; } - static BoolValue _decodeBoolValue(EJsonValue ejson) { + static EJsonValue _toEJson(BoolValue value) => value.toEJson(); + static BoolValue _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'key': EJsonValue key, @@ -535,7 +537,7 @@ class BoolValue extends _BoolValue static final schema = () { RealmObjectBase.registerFactory(BoolValue._); - register(_encodeBoolValue, _decodeBoolValue); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, BoolValue, 'BoolValue', [ SchemaProperty('key', RealmPropertyType.int, primaryKey: true), SchemaProperty('value', RealmPropertyType.bool), diff --git a/packages/realm_dart/test/realm_set_test.realm.dart b/packages/realm_dart/test/realm_set_test.realm.dart index 32007d7ec..09bb778e6 100644 --- a/packages/realm_dart/test/realm_set_test.realm.dart +++ b/packages/realm_dart/test/realm_set_test.realm.dart @@ -35,14 +35,15 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { @override Car freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeCar(Car value) { + EJsonValue toEJson() { return { - 'make': toEJson(value.make), - 'color': toEJson(value.color), + 'make': make.toEJson(), + 'color': color.toEJson(), }; } - static Car _decodeCar(EJsonValue ejson) { + static EJsonValue _toEJson(Car value) => value.toEJson(); + static Car _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'make': EJsonValue make, @@ -58,7 +59,7 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Car._); - register(_encodeCar, _decodeCar); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Car, 'Car', [ SchemaProperty('make', RealmPropertyType.string, primaryKey: true), SchemaProperty('color', RealmPropertyType.string, optional: true), @@ -271,31 +272,32 @@ class TestRealmSets extends _TestRealmSets @override TestRealmSets freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeTestRealmSets(TestRealmSets value) { + EJsonValue toEJson() { return { - 'key': toEJson(value.key), - 'boolSet': toEJson(value.boolSet), - 'intSet': toEJson(value.intSet), - 'stringSet': toEJson(value.stringSet), - 'doubleSet': toEJson(value.doubleSet), - 'dateTimeSet': toEJson(value.dateTimeSet), - 'objectIdSet': toEJson(value.objectIdSet), - 'uuidSet': toEJson(value.uuidSet), - 'mixedSet': toEJson(value.mixedSet), - 'objectsSet': toEJson(value.objectsSet), - 'binarySet': toEJson(value.binarySet), - 'nullableBoolSet': toEJson(value.nullableBoolSet), - 'nullableIntSet': toEJson(value.nullableIntSet), - 'nullableStringSet': toEJson(value.nullableStringSet), - 'nullableDoubleSet': toEJson(value.nullableDoubleSet), - 'nullableDateTimeSet': toEJson(value.nullableDateTimeSet), - 'nullableObjectIdSet': toEJson(value.nullableObjectIdSet), - 'nullableUuidSet': toEJson(value.nullableUuidSet), - 'nullableBinarySet': toEJson(value.nullableBinarySet), + 'key': key.toEJson(), + 'boolSet': boolSet.toEJson(), + 'intSet': intSet.toEJson(), + 'stringSet': stringSet.toEJson(), + 'doubleSet': doubleSet.toEJson(), + 'dateTimeSet': dateTimeSet.toEJson(), + 'objectIdSet': objectIdSet.toEJson(), + 'uuidSet': uuidSet.toEJson(), + 'mixedSet': mixedSet.toEJson(), + 'objectsSet': objectsSet.toEJson(), + 'binarySet': binarySet.toEJson(), + 'nullableBoolSet': nullableBoolSet.toEJson(), + 'nullableIntSet': nullableIntSet.toEJson(), + 'nullableStringSet': nullableStringSet.toEJson(), + 'nullableDoubleSet': nullableDoubleSet.toEJson(), + 'nullableDateTimeSet': nullableDateTimeSet.toEJson(), + 'nullableObjectIdSet': nullableObjectIdSet.toEJson(), + 'nullableUuidSet': nullableUuidSet.toEJson(), + 'nullableBinarySet': nullableBinarySet.toEJson(), }; } - static TestRealmSets _decodeTestRealmSets(EJsonValue ejson) { + static EJsonValue _toEJson(TestRealmSets value) => value.toEJson(); + static TestRealmSets _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'key': EJsonValue key, @@ -327,7 +329,7 @@ class TestRealmSets extends _TestRealmSets static final schema = () { RealmObjectBase.registerFactory(TestRealmSets._); - register(_encodeTestRealmSets, _decodeTestRealmSets); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, TestRealmSets, 'TestRealmSets', [ SchemaProperty('key', RealmPropertyType.int, primaryKey: true), diff --git a/packages/realm_dart/test/realm_value_test.realm.dart b/packages/realm_dart/test/realm_value_test.realm.dart index cfe9121bc..0a011da86 100644 --- a/packages/realm_dart/test/realm_value_test.realm.dart +++ b/packages/realm_dart/test/realm_value_test.realm.dart @@ -36,13 +36,14 @@ class TuckedIn extends _TuckedIn @override TuckedIn freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeTuckedIn(TuckedIn value) { + EJsonValue toEJson() { return { - 'x': toEJson(value.x), + 'x': x.toEJson(), }; } - static TuckedIn _decodeTuckedIn(EJsonValue ejson) { + static EJsonValue _toEJson(TuckedIn value) => value.toEJson(); + static TuckedIn _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'x': EJsonValue x, @@ -56,7 +57,7 @@ class TuckedIn extends _TuckedIn static final schema = () { RealmObjectBase.registerFactory(TuckedIn._); - register(_encodeTuckedIn, _decodeTuckedIn); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.embeddedObject, TuckedIn, 'TuckedIn', [ SchemaProperty('x', RealmPropertyType.int), ]); @@ -117,16 +118,17 @@ class AnythingGoes extends _AnythingGoes @override AnythingGoes freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeAnythingGoes(AnythingGoes value) { + EJsonValue toEJson() { return { - 'oneAny': toEJson(value.oneAny), - 'manyAny': toEJson(value.manyAny), - 'dictOfAny': toEJson(value.dictOfAny), - 'setOfAny': toEJson(value.setOfAny), + 'oneAny': oneAny.toEJson(), + 'manyAny': manyAny.toEJson(), + 'dictOfAny': dictOfAny.toEJson(), + 'setOfAny': setOfAny.toEJson(), }; } - static AnythingGoes _decodeAnythingGoes(EJsonValue ejson) { + static EJsonValue _toEJson(AnythingGoes value) => value.toEJson(); + static AnythingGoes _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'oneAny': EJsonValue oneAny, @@ -143,7 +145,7 @@ class AnythingGoes extends _AnythingGoes static final schema = () { RealmObjectBase.registerFactory(AnythingGoes._); - register(_encodeAnythingGoes, _decodeAnythingGoes); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, AnythingGoes, 'AnythingGoes', [ SchemaProperty('oneAny', RealmPropertyType.mixed, @@ -186,13 +188,14 @@ class Stuff extends _Stuff with RealmEntity, RealmObjectBase, RealmObject { @override Stuff freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeStuff(Stuff value) { + EJsonValue toEJson() { return { - 'i': toEJson(value.i), + 'i': i.toEJson(), }; } - static Stuff _decodeStuff(EJsonValue ejson) { + static EJsonValue _toEJson(Stuff value) => value.toEJson(); + static Stuff _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'i': EJsonValue i, @@ -206,7 +209,7 @@ class Stuff extends _Stuff with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Stuff._); - register(_encodeStuff, _decodeStuff); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Stuff, 'Stuff', [ SchemaProperty('i', RealmPropertyType.int), ]); diff --git a/packages/realm_dart/test/test.realm.dart b/packages/realm_dart/test/test.realm.dart index b4d79c09e..1a9c2cfa6 100644 --- a/packages/realm_dart/test/test.realm.dart +++ b/packages/realm_dart/test/test.realm.dart @@ -28,13 +28,14 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { @override Car freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeCar(Car value) { + EJsonValue toEJson() { return { - 'make': toEJson(value.make), + 'make': make.toEJson(), }; } - static Car _decodeCar(EJsonValue ejson) { + static EJsonValue _toEJson(Car value) => value.toEJson(); + static Car _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'make': EJsonValue make, @@ -48,7 +49,7 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Car._); - register(_encodeCar, _decodeCar); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Car, 'Car', [ SchemaProperty('make', RealmPropertyType.string, primaryKey: true), ]); @@ -76,13 +77,14 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { @override Person freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodePerson(Person value) { + EJsonValue toEJson() { return { - 'name': toEJson(value.name), + 'name': name.toEJson(), }; } - static Person _decodePerson(EJsonValue ejson) { + static EJsonValue _toEJson(Person value) => value.toEJson(); + static Person _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'name': EJsonValue name, @@ -96,7 +98,7 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Person._); - register(_encodePerson, _decodePerson); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Person, 'Person', [ SchemaProperty('name', RealmPropertyType.string), ]); @@ -139,15 +141,16 @@ class Dog extends _Dog with RealmEntity, RealmObjectBase, RealmObject { @override Dog freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeDog(Dog value) { + EJsonValue toEJson() { return { - 'name': toEJson(value.name), - 'age': toEJson(value.age), - 'owner': toEJson(value.owner), + 'name': name.toEJson(), + 'age': age.toEJson(), + 'owner': owner.toEJson(), }; } - static Dog _decodeDog(EJsonValue ejson) { + static EJsonValue _toEJson(Dog value) => value.toEJson(); + static Dog _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'name': EJsonValue name, @@ -165,7 +168,7 @@ class Dog extends _Dog with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Dog._); - register(_encodeDog, _decodeDog); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Dog, 'Dog', [ SchemaProperty('name', RealmPropertyType.string, primaryKey: true), SchemaProperty('age', RealmPropertyType.int, optional: true), @@ -215,15 +218,16 @@ class Team extends _Team with RealmEntity, RealmObjectBase, RealmObject { @override Team freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeTeam(Team value) { + EJsonValue toEJson() { return { - 'name': toEJson(value.name), - 'players': toEJson(value.players), - 'scores': toEJson(value.scores), + 'name': name.toEJson(), + 'players': players.toEJson(), + 'scores': scores.toEJson(), }; } - static Team _decodeTeam(EJsonValue ejson) { + static EJsonValue _toEJson(Team value) => value.toEJson(); + static Team _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'name': EJsonValue name, @@ -239,7 +243,7 @@ class Team extends _Team with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Team._); - register(_encodeTeam, _decodeTeam); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Team, 'Team', [ SchemaProperty('name', RealmPropertyType.string), SchemaProperty('players', RealmPropertyType.object, @@ -294,16 +298,17 @@ class Student extends _Student with RealmEntity, RealmObjectBase, RealmObject { @override Student freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeStudent(Student value) { + EJsonValue toEJson() { return { - 'number': toEJson(value.number), - 'name': toEJson(value.name), - 'yearOfBirth': toEJson(value.yearOfBirth), - 'school': toEJson(value.school), + 'number': number.toEJson(), + 'name': name.toEJson(), + 'yearOfBirth': yearOfBirth.toEJson(), + 'school': school.toEJson(), }; } - static Student _decodeStudent(EJsonValue ejson) { + static EJsonValue _toEJson(Student value) => value.toEJson(); + static Student _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'number': EJsonValue number, @@ -323,7 +328,7 @@ class Student extends _Student with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Student._); - register(_encodeStudent, _decodeStudent); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Student, 'Student', [ SchemaProperty('number', RealmPropertyType.int, primaryKey: true), SchemaProperty('name', RealmPropertyType.string, optional: true), @@ -391,17 +396,18 @@ class School extends _School with RealmEntity, RealmObjectBase, RealmObject { @override School freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeSchool(School value) { + EJsonValue toEJson() { return { - 'name': toEJson(value.name), - 'city': toEJson(value.city), - 'students': toEJson(value.students), - 'branchOfSchool': toEJson(value.branchOfSchool), - 'branches': toEJson(value.branches), + 'name': name.toEJson(), + 'city': city.toEJson(), + 'students': students.toEJson(), + 'branchOfSchool': branchOfSchool.toEJson(), + 'branches': branches.toEJson(), }; } - static School _decodeSchool(EJsonValue ejson) { + static EJsonValue _toEJson(School value) => value.toEJson(); + static School _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'name': EJsonValue name, @@ -421,7 +427,7 @@ class School extends _School with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(School._); - register(_encodeSchool, _decodeSchool); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, School, 'School', [ SchemaProperty('name', RealmPropertyType.string, primaryKey: true), SchemaProperty('city', RealmPropertyType.string, optional: true), @@ -470,14 +476,15 @@ class RemappedClass extends $RemappedClass @override RemappedClass freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeRemappedClass(RemappedClass value) { + EJsonValue toEJson() { return { - 'primitive_property': toEJson(value.remappedProperty), - 'list-with-dashes': toEJson(value.listProperty), + 'primitive_property': remappedProperty.toEJson(), + 'list-with-dashes': listProperty.toEJson(), }; } - static RemappedClass _decodeRemappedClass(EJsonValue ejson) { + static EJsonValue _toEJson(RemappedClass value) => value.toEJson(); + static RemappedClass _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'primitive_property': EJsonValue remappedProperty, @@ -492,7 +499,7 @@ class RemappedClass extends $RemappedClass static final schema = () { RealmObjectBase.registerFactory(RemappedClass._); - register(_encodeRemappedClass, _decodeRemappedClass); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, RemappedClass, 'myRemappedClass', [ SchemaProperty('remappedProperty', RealmPropertyType.string, @@ -526,13 +533,14 @@ class Task extends _Task with RealmEntity, RealmObjectBase, RealmObject { @override Task freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeTask(Task value) { + EJsonValue toEJson() { return { - '_id': toEJson(value.id), + '_id': id.toEJson(), }; } - static Task _decodeTask(EJsonValue ejson) { + static EJsonValue _toEJson(Task value) => value.toEJson(); + static Task _fromEJson(EJsonValue ejson) { return switch (ejson) { { '_id': EJsonValue id, @@ -546,7 +554,7 @@ class Task extends _Task with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Task._); - register(_encodeTask, _decodeTask); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Task, 'Task', [ SchemaProperty('id', RealmPropertyType.objectid, mapTo: '_id', primaryKey: true), @@ -584,14 +592,15 @@ class Product extends _Product with RealmEntity, RealmObjectBase, RealmObject { @override Product freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeProduct(Product value) { + EJsonValue toEJson() { return { - '_id': toEJson(value.id), - 'stringQueryField': toEJson(value.name), + '_id': id.toEJson(), + 'stringQueryField': name.toEJson(), }; } - static Product _decodeProduct(EJsonValue ejson) { + static EJsonValue _toEJson(Product value) => value.toEJson(); + static Product _fromEJson(EJsonValue ejson) { return switch (ejson) { { '_id': EJsonValue id, @@ -607,7 +616,7 @@ class Product extends _Product with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Product._); - register(_encodeProduct, _decodeProduct); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Product, 'Product', [ SchemaProperty('id', RealmPropertyType.objectid, mapTo: '_id', primaryKey: true), @@ -648,14 +657,15 @@ class Schedule extends _Schedule @override Schedule freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeSchedule(Schedule value) { + EJsonValue toEJson() { return { - '_id': toEJson(value.id), - 'tasks': toEJson(value.tasks), + '_id': id.toEJson(), + 'tasks': tasks.toEJson(), }; } - static Schedule _decodeSchedule(EJsonValue ejson) { + static EJsonValue _toEJson(Schedule value) => value.toEJson(); + static Schedule _fromEJson(EJsonValue ejson) { return switch (ejson) { { '_id': EJsonValue id, @@ -670,7 +680,7 @@ class Schedule extends _Schedule static final schema = () { RealmObjectBase.registerFactory(Schedule._); - register(_encodeSchedule, _decodeSchedule); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Schedule, 'Schedule', [ SchemaProperty('id', RealmPropertyType.objectid, mapTo: '_id', primaryKey: true), @@ -723,15 +733,16 @@ class Foo extends _Foo with RealmEntity, RealmObjectBase, RealmObject { @override Foo freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeFoo(Foo value) { + EJsonValue toEJson() { return { - 'requiredBinaryProp': toEJson(value.requiredBinaryProp), - 'defaultValueBinaryProp': toEJson(value.defaultValueBinaryProp), - 'nullableBinaryProp': toEJson(value.nullableBinaryProp), + 'requiredBinaryProp': requiredBinaryProp.toEJson(), + 'defaultValueBinaryProp': defaultValueBinaryProp.toEJson(), + 'nullableBinaryProp': nullableBinaryProp.toEJson(), }; } - static Foo _decodeFoo(EJsonValue ejson) { + static EJsonValue _toEJson(Foo value) => value.toEJson(); + static Foo _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'requiredBinaryProp': EJsonValue requiredBinaryProp, @@ -749,7 +760,7 @@ class Foo extends _Foo with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Foo._); - register(_encodeFoo, _decodeFoo); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Foo, 'Foo', [ SchemaProperty('requiredBinaryProp', RealmPropertyType.binary), SchemaProperty('defaultValueBinaryProp', RealmPropertyType.binary), @@ -930,30 +941,31 @@ class AllTypes extends _AllTypes @override AllTypes freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeAllTypes(AllTypes value) { + EJsonValue toEJson() { return { - 'stringProp': toEJson(value.stringProp), - 'boolProp': toEJson(value.boolProp), - 'dateProp': toEJson(value.dateProp), - 'doubleProp': toEJson(value.doubleProp), - 'objectIdProp': toEJson(value.objectIdProp), - 'uuidProp': toEJson(value.uuidProp), - 'intProp': toEJson(value.intProp), - 'decimalProp': toEJson(value.decimalProp), - 'binaryProp': toEJson(value.binaryProp), - 'nullableStringProp': toEJson(value.nullableStringProp), - 'nullableBoolProp': toEJson(value.nullableBoolProp), - 'nullableDateProp': toEJson(value.nullableDateProp), - 'nullableDoubleProp': toEJson(value.nullableDoubleProp), - 'nullableObjectIdProp': toEJson(value.nullableObjectIdProp), - 'nullableUuidProp': toEJson(value.nullableUuidProp), - 'nullableIntProp': toEJson(value.nullableIntProp), - 'nullableDecimalProp': toEJson(value.nullableDecimalProp), - 'nullableBinaryProp': toEJson(value.nullableBinaryProp), + 'stringProp': stringProp.toEJson(), + 'boolProp': boolProp.toEJson(), + 'dateProp': dateProp.toEJson(), + 'doubleProp': doubleProp.toEJson(), + 'objectIdProp': objectIdProp.toEJson(), + 'uuidProp': uuidProp.toEJson(), + 'intProp': intProp.toEJson(), + 'decimalProp': decimalProp.toEJson(), + 'binaryProp': binaryProp.toEJson(), + 'nullableStringProp': nullableStringProp.toEJson(), + 'nullableBoolProp': nullableBoolProp.toEJson(), + 'nullableDateProp': nullableDateProp.toEJson(), + 'nullableDoubleProp': nullableDoubleProp.toEJson(), + 'nullableObjectIdProp': nullableObjectIdProp.toEJson(), + 'nullableUuidProp': nullableUuidProp.toEJson(), + 'nullableIntProp': nullableIntProp.toEJson(), + 'nullableDecimalProp': nullableDecimalProp.toEJson(), + 'nullableBinaryProp': nullableBinaryProp.toEJson(), }; } - static AllTypes _decodeAllTypes(EJsonValue ejson) { + static EJsonValue _toEJson(AllTypes value) => value.toEJson(); + static AllTypes _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'stringProp': EJsonValue stringProp, @@ -1001,7 +1013,7 @@ class AllTypes extends _AllTypes static final schema = () { RealmObjectBase.registerFactory(AllTypes._); - register(_encodeAllTypes, _decodeAllTypes); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, AllTypes, 'AllTypes', [ SchemaProperty('stringProp', RealmPropertyType.string), SchemaProperty('boolProp', RealmPropertyType.bool), @@ -1094,17 +1106,18 @@ class LinksClass extends _LinksClass @override LinksClass freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeLinksClass(LinksClass value) { + EJsonValue toEJson() { return { - 'id': toEJson(value.id), - 'link': toEJson(value.link), - 'list': toEJson(value.list), - 'linksSet': toEJson(value.linksSet), - 'map': toEJson(value.map), + 'id': id.toEJson(), + 'link': link.toEJson(), + 'list': list.toEJson(), + 'linksSet': linksSet.toEJson(), + 'map': map.toEJson(), }; } - static LinksClass _decodeLinksClass(EJsonValue ejson) { + static EJsonValue _toEJson(LinksClass value) => value.toEJson(); + static LinksClass _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'id': EJsonValue id, @@ -1123,7 +1136,7 @@ class LinksClass extends _LinksClass static final schema = () { RealmObjectBase.registerFactory(LinksClass._); - register(_encodeLinksClass, _decodeLinksClass); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, LinksClass, 'LinksClass', [ SchemaProperty('id', RealmPropertyType.uuid, primaryKey: true), @@ -1651,60 +1664,61 @@ class AllCollections extends _AllCollections @override AllCollections freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeAllCollections(AllCollections value) { + EJsonValue toEJson() { return { - 'stringList': toEJson(value.stringList), - 'boolList': toEJson(value.boolList), - 'dateList': toEJson(value.dateList), - 'doubleList': toEJson(value.doubleList), - 'objectIdList': toEJson(value.objectIdList), - 'uuidList': toEJson(value.uuidList), - 'intList': toEJson(value.intList), - 'decimalList': toEJson(value.decimalList), - 'nullableStringList': toEJson(value.nullableStringList), - 'nullableBoolList': toEJson(value.nullableBoolList), - 'nullableDateList': toEJson(value.nullableDateList), - 'nullableDoubleList': toEJson(value.nullableDoubleList), - 'nullableObjectIdList': toEJson(value.nullableObjectIdList), - 'nullableUuidList': toEJson(value.nullableUuidList), - 'nullableIntList': toEJson(value.nullableIntList), - 'nullableDecimalList': toEJson(value.nullableDecimalList), - 'stringSet': toEJson(value.stringSet), - 'boolSet': toEJson(value.boolSet), - 'dateSet': toEJson(value.dateSet), - 'doubleSet': toEJson(value.doubleSet), - 'objectIdSet': toEJson(value.objectIdSet), - 'uuidSet': toEJson(value.uuidSet), - 'intSet': toEJson(value.intSet), - 'decimalSet': toEJson(value.decimalSet), - 'nullableStringSet': toEJson(value.nullableStringSet), - 'nullableBoolSet': toEJson(value.nullableBoolSet), - 'nullableDateSet': toEJson(value.nullableDateSet), - 'nullableDoubleSet': toEJson(value.nullableDoubleSet), - 'nullableObjectIdSet': toEJson(value.nullableObjectIdSet), - 'nullableUuidSet': toEJson(value.nullableUuidSet), - 'nullableIntSet': toEJson(value.nullableIntSet), - 'nullableDecimalSet': toEJson(value.nullableDecimalSet), - 'stringMap': toEJson(value.stringMap), - 'boolMap': toEJson(value.boolMap), - 'dateMap': toEJson(value.dateMap), - 'doubleMap': toEJson(value.doubleMap), - 'objectIdMap': toEJson(value.objectIdMap), - 'uuidMap': toEJson(value.uuidMap), - 'intMap': toEJson(value.intMap), - 'decimalMap': toEJson(value.decimalMap), - 'nullableStringMap': toEJson(value.nullableStringMap), - 'nullableBoolMap': toEJson(value.nullableBoolMap), - 'nullableDateMap': toEJson(value.nullableDateMap), - 'nullableDoubleMap': toEJson(value.nullableDoubleMap), - 'nullableObjectIdMap': toEJson(value.nullableObjectIdMap), - 'nullableUuidMap': toEJson(value.nullableUuidMap), - 'nullableIntMap': toEJson(value.nullableIntMap), - 'nullableDecimalMap': toEJson(value.nullableDecimalMap), + 'stringList': stringList.toEJson(), + 'boolList': boolList.toEJson(), + 'dateList': dateList.toEJson(), + 'doubleList': doubleList.toEJson(), + 'objectIdList': objectIdList.toEJson(), + 'uuidList': uuidList.toEJson(), + 'intList': intList.toEJson(), + 'decimalList': decimalList.toEJson(), + 'nullableStringList': nullableStringList.toEJson(), + 'nullableBoolList': nullableBoolList.toEJson(), + 'nullableDateList': nullableDateList.toEJson(), + 'nullableDoubleList': nullableDoubleList.toEJson(), + 'nullableObjectIdList': nullableObjectIdList.toEJson(), + 'nullableUuidList': nullableUuidList.toEJson(), + 'nullableIntList': nullableIntList.toEJson(), + 'nullableDecimalList': nullableDecimalList.toEJson(), + 'stringSet': stringSet.toEJson(), + 'boolSet': boolSet.toEJson(), + 'dateSet': dateSet.toEJson(), + 'doubleSet': doubleSet.toEJson(), + 'objectIdSet': objectIdSet.toEJson(), + 'uuidSet': uuidSet.toEJson(), + 'intSet': intSet.toEJson(), + 'decimalSet': decimalSet.toEJson(), + 'nullableStringSet': nullableStringSet.toEJson(), + 'nullableBoolSet': nullableBoolSet.toEJson(), + 'nullableDateSet': nullableDateSet.toEJson(), + 'nullableDoubleSet': nullableDoubleSet.toEJson(), + 'nullableObjectIdSet': nullableObjectIdSet.toEJson(), + 'nullableUuidSet': nullableUuidSet.toEJson(), + 'nullableIntSet': nullableIntSet.toEJson(), + 'nullableDecimalSet': nullableDecimalSet.toEJson(), + 'stringMap': stringMap.toEJson(), + 'boolMap': boolMap.toEJson(), + 'dateMap': dateMap.toEJson(), + 'doubleMap': doubleMap.toEJson(), + 'objectIdMap': objectIdMap.toEJson(), + 'uuidMap': uuidMap.toEJson(), + 'intMap': intMap.toEJson(), + 'decimalMap': decimalMap.toEJson(), + 'nullableStringMap': nullableStringMap.toEJson(), + 'nullableBoolMap': nullableBoolMap.toEJson(), + 'nullableDateMap': nullableDateMap.toEJson(), + 'nullableDoubleMap': nullableDoubleMap.toEJson(), + 'nullableObjectIdMap': nullableObjectIdMap.toEJson(), + 'nullableUuidMap': nullableUuidMap.toEJson(), + 'nullableIntMap': nullableIntMap.toEJson(), + 'nullableDecimalMap': nullableDecimalMap.toEJson(), }; } - static AllCollections _decodeAllCollections(EJsonValue ejson) { + static EJsonValue _toEJson(AllCollections value) => value.toEJson(); + static AllCollections _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'stringList': EJsonValue stringList, @@ -1763,7 +1777,7 @@ class AllCollections extends _AllCollections static final schema = () { RealmObjectBase.registerFactory(AllCollections._); - register(_encodeAllCollections, _decodeAllCollections); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, AllCollections, 'AllCollections', [ SchemaProperty('stringList', RealmPropertyType.string, @@ -1962,22 +1976,23 @@ class NullableTypes extends _NullableTypes @override NullableTypes freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeNullableTypes(NullableTypes value) { + EJsonValue toEJson() { return { - '_id': toEJson(value.id), - 'differentiator': toEJson(value.differentiator), - 'stringProp': toEJson(value.stringProp), - 'boolProp': toEJson(value.boolProp), - 'dateProp': toEJson(value.dateProp), - 'doubleProp': toEJson(value.doubleProp), - 'objectIdProp': toEJson(value.objectIdProp), - 'uuidProp': toEJson(value.uuidProp), - 'intProp': toEJson(value.intProp), - 'decimalProp': toEJson(value.decimalProp), + '_id': id.toEJson(), + 'differentiator': differentiator.toEJson(), + 'stringProp': stringProp.toEJson(), + 'boolProp': boolProp.toEJson(), + 'dateProp': dateProp.toEJson(), + 'doubleProp': doubleProp.toEJson(), + 'objectIdProp': objectIdProp.toEJson(), + 'uuidProp': uuidProp.toEJson(), + 'intProp': intProp.toEJson(), + 'decimalProp': decimalProp.toEJson(), }; } - static NullableTypes _decodeNullableTypes(EJsonValue ejson) { + static EJsonValue _toEJson(NullableTypes value) => value.toEJson(); + static NullableTypes _fromEJson(EJsonValue ejson) { return switch (ejson) { { '_id': EJsonValue id, @@ -2009,7 +2024,7 @@ class NullableTypes extends _NullableTypes static final schema = () { RealmObjectBase.registerFactory(NullableTypes._); - register(_encodeNullableTypes, _decodeNullableTypes); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, NullableTypes, 'NullableTypes', [ SchemaProperty('id', RealmPropertyType.objectid, @@ -2086,17 +2101,18 @@ class Event extends _Event with RealmEntity, RealmObjectBase, RealmObject { @override Event freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeEvent(Event value) { + EJsonValue toEJson() { return { - '_id': toEJson(value.id), - 'stringQueryField': toEJson(value.name), - 'boolQueryField': toEJson(value.isCompleted), - 'intQueryField': toEJson(value.durationInMinutes), - 'assignedTo': toEJson(value.assignedTo), + '_id': id.toEJson(), + 'stringQueryField': name.toEJson(), + 'boolQueryField': isCompleted.toEJson(), + 'intQueryField': durationInMinutes.toEJson(), + 'assignedTo': assignedTo.toEJson(), }; } - static Event _decodeEvent(EJsonValue ejson) { + static EJsonValue _toEJson(Event value) => value.toEJson(); + static Event _fromEJson(EJsonValue ejson) { return switch (ejson) { { '_id': EJsonValue id, @@ -2118,7 +2134,7 @@ class Event extends _Event with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Event._); - register(_encodeEvent, _decodeEvent); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Event, 'Event', [ SchemaProperty('id', RealmPropertyType.objectid, mapTo: '_id', primaryKey: true), @@ -2179,16 +2195,17 @@ class Party extends _Party with RealmEntity, RealmObjectBase, RealmObject { @override Party freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeParty(Party value) { + EJsonValue toEJson() { return { - 'host': toEJson(value.host), - 'year': toEJson(value.year), - 'guests': toEJson(value.guests), - 'previous': toEJson(value.previous), + 'host': host.toEJson(), + 'year': year.toEJson(), + 'guests': guests.toEJson(), + 'previous': previous.toEJson(), }; } - static Party _decodeParty(EJsonValue ejson) { + static EJsonValue _toEJson(Party value) => value.toEJson(); + static Party _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'host': EJsonValue host, @@ -2207,7 +2224,7 @@ class Party extends _Party with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Party._); - register(_encodeParty, _decodeParty); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Party, 'Party', [ SchemaProperty('host', RealmPropertyType.object, optional: true, linkTarget: 'Friend'), @@ -2274,16 +2291,17 @@ class Friend extends _Friend with RealmEntity, RealmObjectBase, RealmObject { @override Friend freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeFriend(Friend value) { + EJsonValue toEJson() { return { - 'name': toEJson(value.name), - 'age': toEJson(value.age), - 'bestFriend': toEJson(value.bestFriend), - 'friends': toEJson(value.friends), + 'name': name.toEJson(), + 'age': age.toEJson(), + 'bestFriend': bestFriend.toEJson(), + 'friends': friends.toEJson(), }; } - static Friend _decodeFriend(EJsonValue ejson) { + static EJsonValue _toEJson(Friend value) => value.toEJson(); + static Friend _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'name': EJsonValue name, @@ -2302,7 +2320,7 @@ class Friend extends _Friend with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Friend._); - register(_encodeFriend, _decodeFriend); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Friend, 'Friend', [ SchemaProperty('name', RealmPropertyType.string, primaryKey: true), SchemaProperty('age', RealmPropertyType.int), @@ -2346,14 +2364,15 @@ class When extends _When with RealmEntity, RealmObjectBase, RealmObject { @override When freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeWhen(When value) { + EJsonValue toEJson() { return { - 'dateTimeUtc': toEJson(value.dateTimeUtc), - 'locationName': toEJson(value.locationName), + 'dateTimeUtc': dateTimeUtc.toEJson(), + 'locationName': locationName.toEJson(), }; } - static When _decodeWhen(EJsonValue ejson) { + static EJsonValue _toEJson(When value) => value.toEJson(); + static When _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'dateTimeUtc': EJsonValue dateTimeUtc, @@ -2369,7 +2388,7 @@ class When extends _When with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(When._); - register(_encodeWhen, _decodeWhen); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, When, 'When', [ SchemaProperty('dateTimeUtc', RealmPropertyType.timestamp), SchemaProperty('locationName', RealmPropertyType.string), @@ -2415,15 +2434,16 @@ class Player extends _Player with RealmEntity, RealmObjectBase, RealmObject { @override Player freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodePlayer(Player value) { + EJsonValue toEJson() { return { - 'name': toEJson(value.name), - 'game': toEJson(value.game), - 'scoresByRound': toEJson(value.scoresByRound), + 'name': name.toEJson(), + 'game': game.toEJson(), + 'scoresByRound': scoresByRound.toEJson(), }; } - static Player _decodePlayer(EJsonValue ejson) { + static EJsonValue _toEJson(Player value) => value.toEJson(); + static Player _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'name': EJsonValue name, @@ -2440,7 +2460,7 @@ class Player extends _Player with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Player._); - register(_encodePlayer, _decodePlayer); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Player, 'Player', [ SchemaProperty('name', RealmPropertyType.string, primaryKey: true), SchemaProperty('game', RealmPropertyType.object, @@ -2475,13 +2495,14 @@ class Game extends _Game with RealmEntity, RealmObjectBase, RealmObject { @override Game freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeGame(Game value) { + EJsonValue toEJson() { return { - 'winnerByRound': toEJson(value.winnerByRound), + 'winnerByRound': winnerByRound.toEJson(), }; } - static Game _decodeGame(EJsonValue ejson) { + static EJsonValue _toEJson(Game value) => value.toEJson(); + static Game _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'winnerByRound': EJsonValue winnerByRound, @@ -2493,7 +2514,7 @@ class Game extends _Game with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Game._); - register(_encodeGame, _decodeGame); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Game, 'Game', [ SchemaProperty('winnerByRound', RealmPropertyType.object, linkTarget: 'Player', collectionType: RealmCollectionType.list), @@ -2732,36 +2753,37 @@ class AllTypesEmbedded extends _AllTypesEmbedded AllTypesEmbedded freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeAllTypesEmbedded(AllTypesEmbedded value) { + EJsonValue toEJson() { return { - 'stringProp': toEJson(value.stringProp), - 'boolProp': toEJson(value.boolProp), - 'dateProp': toEJson(value.dateProp), - 'doubleProp': toEJson(value.doubleProp), - 'objectIdProp': toEJson(value.objectIdProp), - 'uuidProp': toEJson(value.uuidProp), - 'intProp': toEJson(value.intProp), - 'decimalProp': toEJson(value.decimalProp), - 'nullableStringProp': toEJson(value.nullableStringProp), - 'nullableBoolProp': toEJson(value.nullableBoolProp), - 'nullableDateProp': toEJson(value.nullableDateProp), - 'nullableDoubleProp': toEJson(value.nullableDoubleProp), - 'nullableObjectIdProp': toEJson(value.nullableObjectIdProp), - 'nullableUuidProp': toEJson(value.nullableUuidProp), - 'nullableIntProp': toEJson(value.nullableIntProp), - 'nullableDecimalProp': toEJson(value.nullableDecimalProp), - 'strings': toEJson(value.strings), - 'bools': toEJson(value.bools), - 'dates': toEJson(value.dates), - 'doubles': toEJson(value.doubles), - 'objectIds': toEJson(value.objectIds), - 'uuids': toEJson(value.uuids), - 'ints': toEJson(value.ints), - 'decimals': toEJson(value.decimals), + 'stringProp': stringProp.toEJson(), + 'boolProp': boolProp.toEJson(), + 'dateProp': dateProp.toEJson(), + 'doubleProp': doubleProp.toEJson(), + 'objectIdProp': objectIdProp.toEJson(), + 'uuidProp': uuidProp.toEJson(), + 'intProp': intProp.toEJson(), + 'decimalProp': decimalProp.toEJson(), + 'nullableStringProp': nullableStringProp.toEJson(), + 'nullableBoolProp': nullableBoolProp.toEJson(), + 'nullableDateProp': nullableDateProp.toEJson(), + 'nullableDoubleProp': nullableDoubleProp.toEJson(), + 'nullableObjectIdProp': nullableObjectIdProp.toEJson(), + 'nullableUuidProp': nullableUuidProp.toEJson(), + 'nullableIntProp': nullableIntProp.toEJson(), + 'nullableDecimalProp': nullableDecimalProp.toEJson(), + 'strings': strings.toEJson(), + 'bools': bools.toEJson(), + 'dates': dates.toEJson(), + 'doubles': doubles.toEJson(), + 'objectIds': objectIds.toEJson(), + 'uuids': uuids.toEJson(), + 'ints': ints.toEJson(), + 'decimals': decimals.toEJson(), }; } - static AllTypesEmbedded _decodeAllTypesEmbedded(EJsonValue ejson) { + static EJsonValue _toEJson(AllTypesEmbedded value) => value.toEJson(); + static AllTypesEmbedded _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'stringProp': EJsonValue stringProp, @@ -2813,7 +2835,7 @@ class AllTypesEmbedded extends _AllTypesEmbedded static final schema = () { RealmObjectBase.registerFactory(AllTypesEmbedded._); - register(_encodeAllTypesEmbedded, _decodeAllTypesEmbedded); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.embeddedObject, AllTypesEmbedded, 'AllTypesEmbedded', [ SchemaProperty('stringProp', RealmPropertyType.string), @@ -2933,18 +2955,19 @@ class ObjectWithEmbedded extends _ObjectWithEmbedded ObjectWithEmbedded freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeObjectWithEmbedded(ObjectWithEmbedded value) { + EJsonValue toEJson() { return { - '_id': toEJson(value.id), - 'differentiator': toEJson(value.differentiator), - 'singleObject': toEJson(value.singleObject), - 'list': toEJson(value.list), - 'recursiveObject': toEJson(value.recursiveObject), - 'recursiveList': toEJson(value.recursiveList), + '_id': id.toEJson(), + 'differentiator': differentiator.toEJson(), + 'singleObject': singleObject.toEJson(), + 'list': list.toEJson(), + 'recursiveObject': recursiveObject.toEJson(), + 'recursiveList': recursiveList.toEJson(), }; } - static ObjectWithEmbedded _decodeObjectWithEmbedded(EJsonValue ejson) { + static EJsonValue _toEJson(ObjectWithEmbedded value) => value.toEJson(); + static ObjectWithEmbedded _fromEJson(EJsonValue ejson) { return switch (ejson) { { '_id': EJsonValue id, @@ -2966,7 +2989,7 @@ class ObjectWithEmbedded extends _ObjectWithEmbedded static final schema = () { RealmObjectBase.registerFactory(ObjectWithEmbedded._); - register(_encodeObjectWithEmbedded, _decodeObjectWithEmbedded); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, ObjectWithEmbedded, 'ObjectWithEmbedded', [ SchemaProperty('id', RealmPropertyType.string, @@ -3040,16 +3063,17 @@ class RecursiveEmbedded1 extends _RecursiveEmbedded1 RecursiveEmbedded1 freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeRecursiveEmbedded1(RecursiveEmbedded1 value) { + EJsonValue toEJson() { return { - 'value': toEJson(value.value), - 'child': toEJson(value.child), - 'children': toEJson(value.children), - 'realmObject': toEJson(value.realmObject), + 'value': value.toEJson(), + 'child': child.toEJson(), + 'children': children.toEJson(), + 'realmObject': realmObject.toEJson(), }; } - static RecursiveEmbedded1 _decodeRecursiveEmbedded1(EJsonValue ejson) { + static EJsonValue _toEJson(RecursiveEmbedded1 value) => value.toEJson(); + static RecursiveEmbedded1 _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'value': EJsonValue value, @@ -3068,7 +3092,7 @@ class RecursiveEmbedded1 extends _RecursiveEmbedded1 static final schema = () { RealmObjectBase.registerFactory(RecursiveEmbedded1._); - register(_encodeRecursiveEmbedded1, _decodeRecursiveEmbedded1); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.embeddedObject, RecursiveEmbedded1, 'RecursiveEmbedded1', [ SchemaProperty('value', RealmPropertyType.string), @@ -3137,16 +3161,17 @@ class RecursiveEmbedded2 extends _RecursiveEmbedded2 RecursiveEmbedded2 freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeRecursiveEmbedded2(RecursiveEmbedded2 value) { + EJsonValue toEJson() { return { - 'value': toEJson(value.value), - 'child': toEJson(value.child), - 'children': toEJson(value.children), - 'realmObject': toEJson(value.realmObject), + 'value': value.toEJson(), + 'child': child.toEJson(), + 'children': children.toEJson(), + 'realmObject': realmObject.toEJson(), }; } - static RecursiveEmbedded2 _decodeRecursiveEmbedded2(EJsonValue ejson) { + static EJsonValue _toEJson(RecursiveEmbedded2 value) => value.toEJson(); + static RecursiveEmbedded2 _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'value': EJsonValue value, @@ -3165,7 +3190,7 @@ class RecursiveEmbedded2 extends _RecursiveEmbedded2 static final schema = () { RealmObjectBase.registerFactory(RecursiveEmbedded2._); - register(_encodeRecursiveEmbedded2, _decodeRecursiveEmbedded2); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.embeddedObject, RecursiveEmbedded2, 'RecursiveEmbedded2', [ SchemaProperty('value', RealmPropertyType.string), @@ -3203,13 +3228,14 @@ class RecursiveEmbedded3 extends _RecursiveEmbedded3 RecursiveEmbedded3 freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeRecursiveEmbedded3(RecursiveEmbedded3 value) { + EJsonValue toEJson() { return { - 'value': toEJson(value.value), + 'value': value.toEJson(), }; } - static RecursiveEmbedded3 _decodeRecursiveEmbedded3(EJsonValue ejson) { + static EJsonValue _toEJson(RecursiveEmbedded3 value) => value.toEJson(); + static RecursiveEmbedded3 _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'value': EJsonValue value, @@ -3223,7 +3249,7 @@ class RecursiveEmbedded3 extends _RecursiveEmbedded3 static final schema = () { RealmObjectBase.registerFactory(RecursiveEmbedded3._); - register(_encodeRecursiveEmbedded3, _decodeRecursiveEmbedded3); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.embeddedObject, RecursiveEmbedded3, 'RecursiveEmbedded3', [ SchemaProperty('value', RealmPropertyType.string), @@ -3264,14 +3290,15 @@ class ObjectWithDecimal extends _ObjectWithDecimal ObjectWithDecimal freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeObjectWithDecimal(ObjectWithDecimal value) { + EJsonValue toEJson() { return { - 'decimal': toEJson(value.decimal), - 'nullableDecimal': toEJson(value.nullableDecimal), + 'decimal': decimal.toEJson(), + 'nullableDecimal': nullableDecimal.toEJson(), }; } - static ObjectWithDecimal _decodeObjectWithDecimal(EJsonValue ejson) { + static EJsonValue _toEJson(ObjectWithDecimal value) => value.toEJson(); + static ObjectWithDecimal _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'decimal': EJsonValue decimal, @@ -3287,7 +3314,7 @@ class ObjectWithDecimal extends _ObjectWithDecimal static final schema = () { RealmObjectBase.registerFactory(ObjectWithDecimal._); - register(_encodeObjectWithDecimal, _decodeObjectWithDecimal); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, ObjectWithDecimal, 'ObjectWithDecimal', [ SchemaProperty('decimal', RealmPropertyType.decimal128), @@ -3339,15 +3366,16 @@ class Asymmetric extends _Asymmetric @override Asymmetric freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeAsymmetric(Asymmetric value) { + EJsonValue toEJson() { return { - '_id': toEJson(value.id), - 'symmetric': toEJson(value.symmetric), - 'embeddedObjects': toEJson(value.embeddedObjects), + '_id': id.toEJson(), + 'symmetric': symmetric.toEJson(), + 'embeddedObjects': embeddedObjects.toEJson(), }; } - static Asymmetric _decodeAsymmetric(EJsonValue ejson) { + static EJsonValue _toEJson(Asymmetric value) => value.toEJson(); + static Asymmetric _fromEJson(EJsonValue ejson) { return switch (ejson) { { '_id': EJsonValue id, @@ -3364,7 +3392,7 @@ class Asymmetric extends _Asymmetric static final schema = () { RealmObjectBase.registerFactory(Asymmetric._); - register(_encodeAsymmetric, _decodeAsymmetric); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.asymmetricObject, Asymmetric, 'Asymmetric', [ SchemaProperty('id', RealmPropertyType.objectid, @@ -3416,15 +3444,16 @@ class Embedded extends _Embedded @override Embedded freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeEmbedded(Embedded value) { + EJsonValue toEJson() { return { - 'value': toEJson(value.value), - 'any': toEJson(value.any), - 'symmetric': toEJson(value.symmetric), + 'value': value.toEJson(), + 'any': any.toEJson(), + 'symmetric': symmetric.toEJson(), }; } - static Embedded _decodeEmbedded(EJsonValue ejson) { + static EJsonValue _toEJson(Embedded value) => value.toEJson(); + static Embedded _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'value': EJsonValue value, @@ -3442,7 +3471,7 @@ class Embedded extends _Embedded static final schema = () { RealmObjectBase.registerFactory(Embedded._); - register(_encodeEmbedded, _decodeEmbedded); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.embeddedObject, Embedded, 'Embedded', [ SchemaProperty('value', RealmPropertyType.int), SchemaProperty('any', RealmPropertyType.mixed, optional: true), @@ -3474,13 +3503,14 @@ class Symmetric extends _Symmetric @override Symmetric freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeSymmetric(Symmetric value) { + EJsonValue toEJson() { return { - '_id': toEJson(value.id), + '_id': id.toEJson(), }; } - static Symmetric _decodeSymmetric(EJsonValue ejson) { + static EJsonValue _toEJson(Symmetric value) => value.toEJson(); + static Symmetric _fromEJson(EJsonValue ejson) { return switch (ejson) { { '_id': EJsonValue id, @@ -3494,7 +3524,7 @@ class Symmetric extends _Symmetric static final schema = () { RealmObjectBase.registerFactory(Symmetric._); - register(_encodeSymmetric, _decodeSymmetric); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Symmetric, 'Symmetric', [ SchemaProperty('id', RealmPropertyType.objectid, mapTo: '_id', primaryKey: true), diff --git a/packages/realm_generator/lib/src/realm_model_info.dart b/packages/realm_generator/lib/src/realm_model_info.dart index ffb26e0b4..0866c2d5f 100644 --- a/packages/realm_generator/lib/src/realm_model_info.dart +++ b/packages/realm_generator/lib/src/realm_model_info.dart @@ -104,20 +104,22 @@ class RealmModelInfo { yield ''; // Encode - yield 'static EJsonValue _encode$name($name value) {'; + yield 'EJsonValue toEJson() {'; { yield 'return {'; { yield* fields.map((f) { - return "'${f.realmName}': toEJson(value.${f.name}),"; + return "'${f.realmName}': ${f.name}.toEJson(),"; }); } yield '};'; } yield '}'; + yield 'static EJsonValue _toEJson($name value) => value.toEJson();'; + // Decode - yield 'static $name _decode$name(EJsonValue ejson) {'; + yield 'static $name _fromEJson(EJsonValue ejson) {'; { yield 'return switch (ejson) {'; { @@ -143,7 +145,7 @@ class RealmModelInfo { yield 'static final schema = () {'; { yield 'RealmObjectBase.registerFactory($name._);'; - yield 'register(_encode$name, _decode$name);'; + yield 'register(_toEJson, _fromEJson);'; yield "return const SchemaObject(ObjectType.${baseType.name}, $name, '$realmName', ["; { yield* fields.map((f) { diff --git a/packages/realm_generator/test/good_test_data/all_types.expected b/packages/realm_generator/test/good_test_data/all_types.expected index 7f977d12a..bdd5e45c0 100644 --- a/packages/realm_generator/test/good_test_data/all_types.expected +++ b/packages/realm_generator/test/good_test_data/all_types.expected @@ -42,14 +42,15 @@ class Foo extends _Foo with RealmEntity, RealmObjectBase, RealmObject { @override Foo freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeFoo(Foo value) { + EJsonValue toEJson() { return { - 'x': toEJson(value.x), - 'bar': toEJson(value.bar), + 'x': x.toEJson(), + 'bar': bar.toEJson(), }; } - static Foo _decodeFoo(EJsonValue ejson) { + static EJsonValue _toEJson(Foo value) => value.toEJson(); + static Foo _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'x': EJsonValue x, @@ -65,7 +66,7 @@ class Foo extends _Foo with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Foo._); - register(_encodeFoo, _decodeFoo); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Foo, 'MyFoo', [ SchemaProperty('x', RealmPropertyType.int, indexType: RealmIndexType.regular), @@ -235,29 +236,30 @@ class Bar extends _Bar with RealmEntity, RealmObjectBase, RealmObject { @override Bar freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeBar(Bar value) { + EJsonValue toEJson() { return { - 'name': toEJson(value.name), - 'aBool': toEJson(value.aBool), - 'another': toEJson(value.another), - 'data': toEJson(value.data), - 'tidspunkt': toEJson(value.timestamp), - 'aDouble': toEJson(value.aDouble), - 'foo': toEJson(value.foo), - 'objectId': toEJson(value.objectId), - 'uuid': toEJson(value.uuid), - 'list': toEJson(value.list), - 'set': toEJson(value.set), - 'map': toEJson(value.map), - 'anOptionalString': toEJson(value.anOptionalString), - 'any': toEJson(value.any), - 'manyAny': toEJson(value.manyAny), - 'decimal': toEJson(value.decimal), - 'foos': toEJson(value.foos), + 'name': name.toEJson(), + 'aBool': aBool.toEJson(), + 'another': another.toEJson(), + 'data': data.toEJson(), + 'tidspunkt': timestamp.toEJson(), + 'aDouble': aDouble.toEJson(), + 'foo': foo.toEJson(), + 'objectId': objectId.toEJson(), + 'uuid': uuid.toEJson(), + 'list': list.toEJson(), + 'set': set.toEJson(), + 'map': map.toEJson(), + 'anOptionalString': anOptionalString.toEJson(), + 'any': any.toEJson(), + 'manyAny': manyAny.toEJson(), + 'decimal': decimal.toEJson(), + 'foos': foos.toEJson(), }; } - static Bar _decodeBar(EJsonValue ejson) { + static EJsonValue _toEJson(Bar value) => value.toEJson(); + static Bar _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'name': EJsonValue name, @@ -298,7 +300,7 @@ class Bar extends _Bar with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Bar._); - register(_encodeBar, _decodeBar); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Bar, 'Bar', [ SchemaProperty('name', RealmPropertyType.string, primaryKey: true), SchemaProperty('aBool', RealmPropertyType.bool, @@ -392,17 +394,18 @@ class PrimitiveTypes extends _PrimitiveTypes @override PrimitiveTypes freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodePrimitiveTypes(PrimitiveTypes value) { + EJsonValue toEJson() { return { - 'stringProp': toEJson(value.stringProp), - 'boolProp': toEJson(value.boolProp), - 'dateProp': toEJson(value.dateProp), - 'doubleProp': toEJson(value.doubleProp), - 'objectIdProp': toEJson(value.objectIdProp), + 'stringProp': stringProp.toEJson(), + 'boolProp': boolProp.toEJson(), + 'dateProp': dateProp.toEJson(), + 'doubleProp': doubleProp.toEJson(), + 'objectIdProp': objectIdProp.toEJson(), }; } - static PrimitiveTypes _decodePrimitiveTypes(EJsonValue ejson) { + static EJsonValue _toEJson(PrimitiveTypes value) => value.toEJson(); + static PrimitiveTypes _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'stringProp': EJsonValue stringProp, @@ -424,7 +427,7 @@ class PrimitiveTypes extends _PrimitiveTypes static final schema = () { RealmObjectBase.registerFactory(PrimitiveTypes._); - register(_encodePrimitiveTypes, _decodePrimitiveTypes); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, PrimitiveTypes, 'PrimitiveTypes', [ SchemaProperty('stringProp', RealmPropertyType.string), diff --git a/packages/realm_generator/test/good_test_data/another_mapto.expected_multi b/packages/realm_generator/test/good_test_data/another_mapto.expected_multi index 78d028c10..0379a2c6a 100644 --- a/packages/realm_generator/test/good_test_data/another_mapto.expected_multi +++ b/packages/realm_generator/test/good_test_data/another_mapto.expected_multi @@ -41,14 +41,15 @@ class MappedToo extends _MappedToo @override MappedToo freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeMappedToo(MappedToo value) { + EJsonValue toEJson() { return { - 'singleLink': toEJson(value.singleLink), - 'listLink': toEJson(value.listLink), + 'singleLink': singleLink.toEJson(), + 'listLink': listLink.toEJson(), }; } - static MappedToo _decodeMappedToo(EJsonValue ejson) { + static EJsonValue _toEJson(MappedToo value) => value.toEJson(); + static MappedToo _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'singleLink': EJsonValue singleLink, @@ -63,7 +64,7 @@ class MappedToo extends _MappedToo static final schema = () { RealmObjectBase.registerFactory(MappedToo._); - register(_encodeMappedToo, _decodeMappedToo); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, MappedToo, 'this is also mapped', [ SchemaProperty('singleLink', RealmPropertyType.object, diff --git a/packages/realm_generator/test/good_test_data/asymmetric_object.expected b/packages/realm_generator/test/good_test_data/asymmetric_object.expected index 4fd5fdad6..e6830bb76 100644 --- a/packages/realm_generator/test/good_test_data/asymmetric_object.expected +++ b/packages/realm_generator/test/good_test_data/asymmetric_object.expected @@ -57,16 +57,17 @@ class Asymmetric extends _Asymmetric @override Asymmetric freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeAsymmetric(Asymmetric value) { + EJsonValue toEJson() { return { - '_id': toEJson(value.id), - 'children': toEJson(value.children), - 'father': toEJson(value.father), - 'mother': toEJson(value.mother), + '_id': id.toEJson(), + 'children': children.toEJson(), + 'father': father.toEJson(), + 'mother': mother.toEJson(), }; } - static Asymmetric _decodeAsymmetric(EJsonValue ejson) { + static EJsonValue _toEJson(Asymmetric value) => value.toEJson(); + static Asymmetric _fromEJson(EJsonValue ejson) { return switch (ejson) { { '_id': EJsonValue id, @@ -85,7 +86,7 @@ class Asymmetric extends _Asymmetric static final schema = () { RealmObjectBase.registerFactory(Asymmetric._); - register(_encodeAsymmetric, _decodeAsymmetric); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, Asymmetric, 'Asymmetric', [ SchemaProperty('id', RealmPropertyType.objectid, @@ -129,14 +130,15 @@ class Embedded extends _Embedded @override Embedded freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeEmbedded(Embedded value) { + EJsonValue toEJson() { return { - 'name': toEJson(value.name), - 'age': toEJson(value.age), + 'name': name.toEJson(), + 'age': age.toEJson(), }; } - static Embedded _decodeEmbedded(EJsonValue ejson) { + static EJsonValue _toEJson(Embedded value) => value.toEJson(); + static Embedded _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'name': EJsonValue name, @@ -152,7 +154,7 @@ class Embedded extends _Embedded static final schema = () { RealmObjectBase.registerFactory(Embedded._); - register(_encodeEmbedded, _decodeEmbedded); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.embeddedObject, Embedded, 'Embedded', [ SchemaProperty('name', RealmPropertyType.string), SchemaProperty('age', RealmPropertyType.int), diff --git a/packages/realm_generator/test/good_test_data/binary_type.expected b/packages/realm_generator/test/good_test_data/binary_type.expected index 2783a7048..12818f4f7 100644 --- a/packages/realm_generator/test/good_test_data/binary_type.expected +++ b/packages/realm_generator/test/good_test_data/binary_type.expected @@ -50,15 +50,16 @@ class Foo extends _Foo with RealmEntity, RealmObjectBase, RealmObject { @override Foo freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeFoo(Foo value) { + EJsonValue toEJson() { return { - 'requiredBinaryProp': toEJson(value.requiredBinaryProp), - 'defaultValueBinaryProp': toEJson(value.defaultValueBinaryProp), - 'nullableBinaryProp': toEJson(value.nullableBinaryProp), + 'requiredBinaryProp': requiredBinaryProp.toEJson(), + 'defaultValueBinaryProp': defaultValueBinaryProp.toEJson(), + 'nullableBinaryProp': nullableBinaryProp.toEJson(), }; } - static Foo _decodeFoo(EJsonValue ejson) { + static EJsonValue _toEJson(Foo value) => value.toEJson(); + static Foo _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'requiredBinaryProp': EJsonValue requiredBinaryProp, @@ -76,7 +77,7 @@ class Foo extends _Foo with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Foo._); - register(_encodeFoo, _decodeFoo); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Foo, 'Foo', [ SchemaProperty('requiredBinaryProp', RealmPropertyType.binary), SchemaProperty('defaultValueBinaryProp', RealmPropertyType.binary), diff --git a/packages/realm_generator/test/good_test_data/embedded_annotations.expected b/packages/realm_generator/test/good_test_data/embedded_annotations.expected index a94551272..0c2bf60ff 100644 --- a/packages/realm_generator/test/good_test_data/embedded_annotations.expected +++ b/packages/realm_generator/test/good_test_data/embedded_annotations.expected @@ -40,14 +40,15 @@ class Parent extends _Parent with RealmEntity, RealmObjectBase, RealmObject { @override Parent freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeParent(Parent value) { + EJsonValue toEJson() { return { - 'single child': toEJson(value.child), - 'CHILDREN': toEJson(value.children), + 'single child': child.toEJson(), + 'CHILDREN': children.toEJson(), }; } - static Parent _decodeParent(EJsonValue ejson) { + static EJsonValue _toEJson(Parent value) => value.toEJson(); + static Parent _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'single child': EJsonValue child, @@ -62,7 +63,7 @@ class Parent extends _Parent with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Parent._); - register(_encodeParent, _decodeParent); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Parent, 'Parent', [ SchemaProperty('child', RealmPropertyType.object, mapTo: 'single child', optional: true, linkTarget: 'MySuperChild'), @@ -113,15 +114,16 @@ class Child1 extends _Child1 with RealmEntity, RealmObjectBase, EmbeddedObject { @override Child1 freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeChild1(Child1 value) { + EJsonValue toEJson() { return { - '_value': toEJson(value.value), - '_parent': toEJson(value.linkToParent), - 'indexedString': toEJson(value.indexedString), + '_value': value.toEJson(), + '_parent': linkToParent.toEJson(), + 'indexedString': indexedString.toEJson(), }; } - static Child1 _decodeChild1(EJsonValue ejson) { + static EJsonValue _toEJson(Child1 value) => value.toEJson(); + static Child1 _fromEJson(EJsonValue ejson) { return switch (ejson) { { '_value': EJsonValue value, @@ -139,7 +141,7 @@ class Child1 extends _Child1 with RealmEntity, RealmObjectBase, EmbeddedObject { static final schema = () { RealmObjectBase.registerFactory(Child1._); - register(_encodeChild1, _decodeChild1); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.embeddedObject, Child1, 'MySuperChild', [ SchemaProperty('value', RealmPropertyType.string, mapTo: '_value'), diff --git a/packages/realm_generator/test/good_test_data/embedded_objects.expected b/packages/realm_generator/test/good_test_data/embedded_objects.expected index 384c2d902..fee06000e 100644 --- a/packages/realm_generator/test/good_test_data/embedded_objects.expected +++ b/packages/realm_generator/test/good_test_data/embedded_objects.expected @@ -39,14 +39,15 @@ class Parent extends _Parent with RealmEntity, RealmObjectBase, RealmObject { @override Parent freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeParent(Parent value) { + EJsonValue toEJson() { return { - 'child': toEJson(value.child), - 'children': toEJson(value.children), + 'child': child.toEJson(), + 'children': children.toEJson(), }; } - static Parent _decodeParent(EJsonValue ejson) { + static EJsonValue _toEJson(Parent value) => value.toEJson(); + static Parent _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'child': EJsonValue child, @@ -61,7 +62,7 @@ class Parent extends _Parent with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Parent._); - register(_encodeParent, _decodeParent); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Parent, 'Parent', [ SchemaProperty('child', RealmPropertyType.object, optional: true, linkTarget: 'Child1'), @@ -119,16 +120,17 @@ class Child1 extends _Child1 with RealmEntity, RealmObjectBase, EmbeddedObject { @override Child1 freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeChild1(Child1 value) { + EJsonValue toEJson() { return { - 'value': toEJson(value.value), - 'child': toEJson(value.child), - 'children': toEJson(value.children), - 'linkToParent': toEJson(value.linkToParent), + 'value': value.toEJson(), + 'child': child.toEJson(), + 'children': children.toEJson(), + 'linkToParent': linkToParent.toEJson(), }; } - static Child1 _decodeChild1(EJsonValue ejson) { + static EJsonValue _toEJson(Child1 value) => value.toEJson(); + static Child1 _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'value': EJsonValue value, @@ -147,7 +149,7 @@ class Child1 extends _Child1 with RealmEntity, RealmObjectBase, EmbeddedObject { static final schema = () { RealmObjectBase.registerFactory(Child1._); - register(_encodeChild1, _decodeChild1); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.embeddedObject, Child1, 'Child1', [ SchemaProperty('value', RealmPropertyType.string), SchemaProperty('child', RealmPropertyType.object, @@ -293,26 +295,27 @@ class Child2 extends _Child2 with RealmEntity, RealmObjectBase, EmbeddedObject { @override Child2 freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeChild2(Child2 value) { + EJsonValue toEJson() { return { - 'boolProp': toEJson(value.boolProp), - 'intProp': toEJson(value.intProp), - 'doubleProp': toEJson(value.doubleProp), - 'stringProp': toEJson(value.stringProp), - 'dateProp': toEJson(value.dateProp), - 'objectIdProp': toEJson(value.objectIdProp), - 'uuidProp': toEJson(value.uuidProp), - 'nullableBoolProp': toEJson(value.nullableBoolProp), - 'nullableIntProp': toEJson(value.nullableIntProp), - 'nullableDoubleProp': toEJson(value.nullableDoubleProp), - 'nullableStringProp': toEJson(value.nullableStringProp), - 'nullableDateProp': toEJson(value.nullableDateProp), - 'nullableObjectIdProp': toEJson(value.nullableObjectIdProp), - 'nullableUuidProp': toEJson(value.nullableUuidProp), + 'boolProp': boolProp.toEJson(), + 'intProp': intProp.toEJson(), + 'doubleProp': doubleProp.toEJson(), + 'stringProp': stringProp.toEJson(), + 'dateProp': dateProp.toEJson(), + 'objectIdProp': objectIdProp.toEJson(), + 'uuidProp': uuidProp.toEJson(), + 'nullableBoolProp': nullableBoolProp.toEJson(), + 'nullableIntProp': nullableIntProp.toEJson(), + 'nullableDoubleProp': nullableDoubleProp.toEJson(), + 'nullableStringProp': nullableStringProp.toEJson(), + 'nullableDateProp': nullableDateProp.toEJson(), + 'nullableObjectIdProp': nullableObjectIdProp.toEJson(), + 'nullableUuidProp': nullableUuidProp.toEJson(), }; } - static Child2 _decodeChild2(EJsonValue ejson) { + static EJsonValue _toEJson(Child2 value) => value.toEJson(); + static Child2 _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'boolProp': EJsonValue boolProp, @@ -352,7 +355,7 @@ class Child2 extends _Child2 with RealmEntity, RealmObjectBase, EmbeddedObject { static final schema = () { RealmObjectBase.registerFactory(Child2._); - register(_encodeChild2, _decodeChild2); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.embeddedObject, Child2, 'Child2', [ SchemaProperty('boolProp', RealmPropertyType.bool), SchemaProperty('intProp', RealmPropertyType.int), diff --git a/packages/realm_generator/test/good_test_data/indexable_types.expected b/packages/realm_generator/test/good_test_data/indexable_types.expected index c2c37e96e..827e459b4 100644 --- a/packages/realm_generator/test/good_test_data/indexable_types.expected +++ b/packages/realm_generator/test/good_test_data/indexable_types.expected @@ -158,28 +158,29 @@ class Indexable extends _Indexable @override Indexable freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeIndexable(Indexable value) { + EJsonValue toEJson() { return { - 'aBool': toEJson(value.aBool), - 'aNullableBool': toEJson(value.aNullableBool), - 'anInt': toEJson(value.anInt), - 'aNullableInt': toEJson(value.aNullableInt), - 'aString': toEJson(value.aString), - 'aNullableString': toEJson(value.aNullableString), - 'anObjectId': toEJson(value.anObjectId), - 'aNullableObjectId': toEJson(value.aNullableObjectId), - 'anUuid': toEJson(value.anUuid), - 'aNullableUuid': toEJson(value.aNullableUuid), - 'aDateTime': toEJson(value.aDateTime), - 'aNullableDateTime': toEJson(value.aNullableDateTime), - 'aRealmValue': toEJson(value.aRealmValue), - 'generalStringIndex': toEJson(value.generalStringIndex), - 'ftsStringValue': toEJson(value.ftsStringValue), - 'nullableFtsStringValue': toEJson(value.nullableFtsStringValue), + 'aBool': aBool.toEJson(), + 'aNullableBool': aNullableBool.toEJson(), + 'anInt': anInt.toEJson(), + 'aNullableInt': aNullableInt.toEJson(), + 'aString': aString.toEJson(), + 'aNullableString': aNullableString.toEJson(), + 'anObjectId': anObjectId.toEJson(), + 'aNullableObjectId': aNullableObjectId.toEJson(), + 'anUuid': anUuid.toEJson(), + 'aNullableUuid': aNullableUuid.toEJson(), + 'aDateTime': aDateTime.toEJson(), + 'aNullableDateTime': aNullableDateTime.toEJson(), + 'aRealmValue': aRealmValue.toEJson(), + 'generalStringIndex': generalStringIndex.toEJson(), + 'ftsStringValue': ftsStringValue.toEJson(), + 'nullableFtsStringValue': nullableFtsStringValue.toEJson(), }; } - static Indexable _decodeIndexable(EJsonValue ejson) { + static EJsonValue _toEJson(Indexable value) => value.toEJson(); + static Indexable _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'aBool': EJsonValue aBool, @@ -223,7 +224,7 @@ class Indexable extends _Indexable static final schema = () { RealmObjectBase.registerFactory(Indexable._); - register(_encodeIndexable, _decodeIndexable); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Indexable, 'Indexable', [ SchemaProperty('aBool', RealmPropertyType.bool, indexType: RealmIndexType.regular), diff --git a/packages/realm_generator/test/good_test_data/list_initialization.expected b/packages/realm_generator/test/good_test_data/list_initialization.expected index 7ec0cfac8..9edcfccee 100644 --- a/packages/realm_generator/test/good_test_data/list_initialization.expected +++ b/packages/realm_generator/test/good_test_data/list_initialization.expected @@ -119,22 +119,23 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { @override Person freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodePerson(Person value) { + EJsonValue toEJson() { return { - 'children': toEJson(value.children), - 'initList': toEJson(value.initList), - 'initListWithType': toEJson(value.initListWithType), - 'initListConst': toEJson(value.initListConst), - 'initSet': toEJson(value.initSet), - 'initSetWithType': toEJson(value.initSetWithType), - 'initSetConst': toEJson(value.initSetConst), - 'initMap': toEJson(value.initMap), - 'initMapWithType': toEJson(value.initMapWithType), - 'initMapConst': toEJson(value.initMapConst), + 'children': children.toEJson(), + 'initList': initList.toEJson(), + 'initListWithType': initListWithType.toEJson(), + 'initListConst': initListConst.toEJson(), + 'initSet': initSet.toEJson(), + 'initSetWithType': initSetWithType.toEJson(), + 'initSetConst': initSetConst.toEJson(), + 'initMap': initMap.toEJson(), + 'initMapWithType': initMapWithType.toEJson(), + 'initMapConst': initMapConst.toEJson(), }; } - static Person _decodePerson(EJsonValue ejson) { + static EJsonValue _toEJson(Person value) => value.toEJson(); + static Person _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'children': EJsonValue children, @@ -155,7 +156,7 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Person._); - register(_encodePerson, _decodePerson); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Person, 'Person', [ SchemaProperty('children', RealmPropertyType.object, linkTarget: 'Person', collectionType: RealmCollectionType.list), diff --git a/packages/realm_generator/test/good_test_data/map.expected b/packages/realm_generator/test/good_test_data/map.expected index ea8a31069..ee0bebbe1 100644 --- a/packages/realm_generator/test/good_test_data/map.expected +++ b/packages/realm_generator/test/good_test_data/map.expected @@ -126,23 +126,24 @@ class LotsOfMaps extends _LotsOfMaps @override LotsOfMaps freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeLotsOfMaps(LotsOfMaps value) { + EJsonValue toEJson() { return { - 'persons': toEJson(value.persons), - 'bools': toEJson(value.bools), - 'dateTimes': toEJson(value.dateTimes), - 'decimals': toEJson(value.decimals), - 'doubles': toEJson(value.doubles), - 'ints': toEJson(value.ints), - 'objectIds': toEJson(value.objectIds), - 'any': toEJson(value.any), - 'strings': toEJson(value.strings), - 'binary': toEJson(value.binary), - 'uuids': toEJson(value.uuids), + 'persons': persons.toEJson(), + 'bools': bools.toEJson(), + 'dateTimes': dateTimes.toEJson(), + 'decimals': decimals.toEJson(), + 'doubles': doubles.toEJson(), + 'ints': ints.toEJson(), + 'objectIds': objectIds.toEJson(), + 'any': any.toEJson(), + 'strings': strings.toEJson(), + 'binary': binary.toEJson(), + 'uuids': uuids.toEJson(), }; } - static LotsOfMaps _decodeLotsOfMaps(EJsonValue ejson) { + static EJsonValue _toEJson(LotsOfMaps value) => value.toEJson(); + static LotsOfMaps _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'persons': EJsonValue persons, @@ -164,7 +165,7 @@ class LotsOfMaps extends _LotsOfMaps static final schema = () { RealmObjectBase.registerFactory(LotsOfMaps._); - register(_encodeLotsOfMaps, _decodeLotsOfMaps); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, LotsOfMaps, 'LotsOfMaps', [ SchemaProperty('persons', RealmPropertyType.object, @@ -216,13 +217,14 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { @override Person freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodePerson(Person value) { + EJsonValue toEJson() { return { - 'name': toEJson(value.name), + 'name': name.toEJson(), }; } - static Person _decodePerson(EJsonValue ejson) { + static EJsonValue _toEJson(Person value) => value.toEJson(); + static Person _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'name': EJsonValue name, @@ -236,7 +238,7 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Person._); - register(_encodePerson, _decodePerson); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Person, 'Person', [ SchemaProperty('name', RealmPropertyType.string), ]); diff --git a/packages/realm_generator/test/good_test_data/mapto.expected b/packages/realm_generator/test/good_test_data/mapto.expected index 5932d65d2..fa9998f32 100644 --- a/packages/realm_generator/test/good_test_data/mapto.expected +++ b/packages/realm_generator/test/good_test_data/mapto.expected @@ -58,15 +58,16 @@ class Original extends $Original @override Original freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeOriginal(Original value) { + EJsonValue toEJson() { return { - 'remapped primitive': toEJson(value.primitiveProperty), - 'remapped object': toEJson(value.objectProperty), - 'remapped list': toEJson(value.listProperty), + 'remapped primitive': primitiveProperty.toEJson(), + 'remapped object': objectProperty.toEJson(), + 'remapped list': listProperty.toEJson(), }; } - static Original _decodeOriginal(EJsonValue ejson) { + static EJsonValue _toEJson(Original value) => value.toEJson(); + static Original _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'remapped primitive': EJsonValue primitiveProperty, @@ -83,7 +84,7 @@ class Original extends $Original static final schema = () { RealmObjectBase.registerFactory(Original._); - register(_encodeOriginal, _decodeOriginal); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, Original, 'another type', [ SchemaProperty('primitiveProperty', RealmPropertyType.int, diff --git a/packages/realm_generator/test/good_test_data/optional_argument.expected b/packages/realm_generator/test/good_test_data/optional_argument.expected index 76595c3c3..f496b59f0 100644 --- a/packages/realm_generator/test/good_test_data/optional_argument.expected +++ b/packages/realm_generator/test/good_test_data/optional_argument.expected @@ -29,13 +29,14 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { @override Person freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodePerson(Person value) { + EJsonValue toEJson() { return { - 'spouse': toEJson(value.spouse), + 'spouse': spouse.toEJson(), }; } - static Person _decodePerson(EJsonValue ejson) { + static EJsonValue _toEJson(Person value) => value.toEJson(); + static Person _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'spouse': EJsonValue spouse, @@ -49,7 +50,7 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Person._); - register(_encodePerson, _decodePerson); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Person, 'Person', [ SchemaProperty('spouse', RealmPropertyType.object, optional: true, linkTarget: 'Person'), diff --git a/packages/realm_generator/test/good_test_data/pinhole.expected b/packages/realm_generator/test/good_test_data/pinhole.expected index 0e9902746..83bb19c62 100644 --- a/packages/realm_generator/test/good_test_data/pinhole.expected +++ b/packages/realm_generator/test/good_test_data/pinhole.expected @@ -35,13 +35,14 @@ class Foo extends _Foo with RealmEntity, RealmObjectBase, RealmObject { @override Foo freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeFoo(Foo value) { + EJsonValue toEJson() { return { - 'x': toEJson(value.x), + 'x': x.toEJson(), }; } - static Foo _decodeFoo(EJsonValue ejson) { + static EJsonValue _toEJson(Foo value) => value.toEJson(); + static Foo _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'x': EJsonValue x, @@ -55,7 +56,7 @@ class Foo extends _Foo with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Foo._); - register(_encodeFoo, _decodeFoo); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Foo, 'Foo', [ SchemaProperty('x', RealmPropertyType.int), ]); diff --git a/packages/realm_generator/test/good_test_data/primary_key.expected b/packages/realm_generator/test/good_test_data/primary_key.expected index 28d71bfa0..6b29508a5 100644 --- a/packages/realm_generator/test/good_test_data/primary_key.expected +++ b/packages/realm_generator/test/good_test_data/primary_key.expected @@ -28,13 +28,14 @@ class IntPK extends _IntPK with RealmEntity, RealmObjectBase, RealmObject { @override IntPK freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeIntPK(IntPK value) { + EJsonValue toEJson() { return { - 'id': toEJson(value.id), + 'id': id.toEJson(), }; } - static IntPK _decodeIntPK(EJsonValue ejson) { + static EJsonValue _toEJson(IntPK value) => value.toEJson(); + static IntPK _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'id': EJsonValue id, @@ -48,7 +49,7 @@ class IntPK extends _IntPK with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(IntPK._); - register(_encodeIntPK, _decodeIntPK); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, IntPK, 'IntPK', [ SchemaProperty('id', RealmPropertyType.int, primaryKey: true), ]); @@ -77,13 +78,14 @@ class NullableIntPK extends _NullableIntPK @override NullableIntPK freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeNullableIntPK(NullableIntPK value) { + EJsonValue toEJson() { return { - 'id': toEJson(value.id), + 'id': id.toEJson(), }; } - static NullableIntPK _decodeNullableIntPK(EJsonValue ejson) { + static EJsonValue _toEJson(NullableIntPK value) => value.toEJson(); + static NullableIntPK _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'id': EJsonValue id, @@ -97,7 +99,7 @@ class NullableIntPK extends _NullableIntPK static final schema = () { RealmObjectBase.registerFactory(NullableIntPK._); - register(_encodeNullableIntPK, _decodeNullableIntPK); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, NullableIntPK, 'NullableIntPK', [ SchemaProperty('id', RealmPropertyType.int, @@ -128,13 +130,14 @@ class StringPK extends _StringPK @override StringPK freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeStringPK(StringPK value) { + EJsonValue toEJson() { return { - 'id': toEJson(value.id), + 'id': id.toEJson(), }; } - static StringPK _decodeStringPK(EJsonValue ejson) { + static EJsonValue _toEJson(StringPK value) => value.toEJson(); + static StringPK _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'id': EJsonValue id, @@ -148,7 +151,7 @@ class StringPK extends _StringPK static final schema = () { RealmObjectBase.registerFactory(StringPK._); - register(_encodeStringPK, _decodeStringPK); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, StringPK, 'StringPK', [ SchemaProperty('id', RealmPropertyType.string, primaryKey: true), ]); @@ -178,13 +181,14 @@ class NullableStringPK extends _NullableStringPK NullableStringPK freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeNullableStringPK(NullableStringPK value) { + EJsonValue toEJson() { return { - 'id': toEJson(value.id), + 'id': id.toEJson(), }; } - static NullableStringPK _decodeNullableStringPK(EJsonValue ejson) { + static EJsonValue _toEJson(NullableStringPK value) => value.toEJson(); + static NullableStringPK _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'id': EJsonValue id, @@ -198,7 +202,7 @@ class NullableStringPK extends _NullableStringPK static final schema = () { RealmObjectBase.registerFactory(NullableStringPK._); - register(_encodeNullableStringPK, _decodeNullableStringPK); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, NullableStringPK, 'NullableStringPK', [ SchemaProperty('id', RealmPropertyType.string, @@ -229,13 +233,14 @@ class ObjectIdPK extends _ObjectIdPK @override ObjectIdPK freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeObjectIdPK(ObjectIdPK value) { + EJsonValue toEJson() { return { - 'id': toEJson(value.id), + 'id': id.toEJson(), }; } - static ObjectIdPK _decodeObjectIdPK(EJsonValue ejson) { + static EJsonValue _toEJson(ObjectIdPK value) => value.toEJson(); + static ObjectIdPK _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'id': EJsonValue id, @@ -249,7 +254,7 @@ class ObjectIdPK extends _ObjectIdPK static final schema = () { RealmObjectBase.registerFactory(ObjectIdPK._); - register(_encodeObjectIdPK, _decodeObjectIdPK); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, ObjectIdPK, 'ObjectIdPK', [ SchemaProperty('id', RealmPropertyType.objectid, primaryKey: true), @@ -280,13 +285,14 @@ class NullableObjectIdPK extends _NullableObjectIdPK NullableObjectIdPK freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeNullableObjectIdPK(NullableObjectIdPK value) { + EJsonValue toEJson() { return { - 'id': toEJson(value.id), + 'id': id.toEJson(), }; } - static NullableObjectIdPK _decodeNullableObjectIdPK(EJsonValue ejson) { + static EJsonValue _toEJson(NullableObjectIdPK value) => value.toEJson(); + static NullableObjectIdPK _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'id': EJsonValue id, @@ -300,7 +306,7 @@ class NullableObjectIdPK extends _NullableObjectIdPK static final schema = () { RealmObjectBase.registerFactory(NullableObjectIdPK._); - register(_encodeNullableObjectIdPK, _decodeNullableObjectIdPK); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, NullableObjectIdPK, 'NullableObjectIdPK', [ SchemaProperty('id', RealmPropertyType.objectid, @@ -330,13 +336,14 @@ class UuidPK extends _UuidPK with RealmEntity, RealmObjectBase, RealmObject { @override UuidPK freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeUuidPK(UuidPK value) { + EJsonValue toEJson() { return { - 'id': toEJson(value.id), + 'id': id.toEJson(), }; } - static UuidPK _decodeUuidPK(EJsonValue ejson) { + static EJsonValue _toEJson(UuidPK value) => value.toEJson(); + static UuidPK _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'id': EJsonValue id, @@ -350,7 +357,7 @@ class UuidPK extends _UuidPK with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(UuidPK._); - register(_encodeUuidPK, _decodeUuidPK); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, UuidPK, 'UuidPK', [ SchemaProperty('id', RealmPropertyType.uuid, primaryKey: true), ]); @@ -379,13 +386,14 @@ class NullableUuidPK extends _NullableUuidPK @override NullableUuidPK freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeNullableUuidPK(NullableUuidPK value) { + EJsonValue toEJson() { return { - 'id': toEJson(value.id), + 'id': id.toEJson(), }; } - static NullableUuidPK _decodeNullableUuidPK(EJsonValue ejson) { + static EJsonValue _toEJson(NullableUuidPK value) => value.toEJson(); + static NullableUuidPK _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'id': EJsonValue id, @@ -399,7 +407,7 @@ class NullableUuidPK extends _NullableUuidPK static final schema = () { RealmObjectBase.registerFactory(NullableUuidPK._); - register(_encodeNullableUuidPK, _decodeNullableUuidPK); + register(_toEJson, _fromEJson); return const SchemaObject( ObjectType.realmObject, NullableUuidPK, 'NullableUuidPK', [ SchemaProperty('id', RealmPropertyType.uuid, diff --git a/packages/realm_generator/test/good_test_data/realm_set.expected b/packages/realm_generator/test/good_test_data/realm_set.expected index 4656e5996..f387b3bb5 100644 --- a/packages/realm_generator/test/good_test_data/realm_set.expected +++ b/packages/realm_generator/test/good_test_data/realm_set.expected @@ -28,13 +28,14 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { @override Car freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeCar(Car value) { + EJsonValue toEJson() { return { - 'make': toEJson(value.make), + 'make': make.toEJson(), }; } - static Car _decodeCar(EJsonValue ejson) { + static EJsonValue _toEJson(Car value) => value.toEJson(); + static Car _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'make': EJsonValue make, @@ -48,7 +49,7 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Car._); - register(_encodeCar, _decodeCar); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Car, 'Car', [ SchemaProperty('make', RealmPropertyType.string, primaryKey: true), ]); @@ -240,29 +241,30 @@ class RealmSets extends _RealmSets @override RealmSets freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodeRealmSets(RealmSets value) { + EJsonValue toEJson() { return { - 'key': toEJson(value.key), - 'boolSet': toEJson(value.boolSet), - 'nullableBoolSet': toEJson(value.nullableBoolSet), - 'intSet': toEJson(value.intSet), - 'nullableintSet': toEJson(value.nullableintSet), - 'stringSet': toEJson(value.stringSet), - 'nullablestringSet': toEJson(value.nullablestringSet), - 'doubleSet': toEJson(value.doubleSet), - 'nullabledoubleSet': toEJson(value.nullabledoubleSet), - 'dateTimeSet': toEJson(value.dateTimeSet), - 'nullabledateTimeSet': toEJson(value.nullabledateTimeSet), - 'objectIdSet': toEJson(value.objectIdSet), - 'nullableobjectIdSet': toEJson(value.nullableobjectIdSet), - 'uuidSet': toEJson(value.uuidSet), - 'nullableuuidSet': toEJson(value.nullableuuidSet), - 'realmValueSet': toEJson(value.realmValueSet), - 'realmObjectsSet': toEJson(value.realmObjectsSet), + 'key': key.toEJson(), + 'boolSet': boolSet.toEJson(), + 'nullableBoolSet': nullableBoolSet.toEJson(), + 'intSet': intSet.toEJson(), + 'nullableintSet': nullableintSet.toEJson(), + 'stringSet': stringSet.toEJson(), + 'nullablestringSet': nullablestringSet.toEJson(), + 'doubleSet': doubleSet.toEJson(), + 'nullabledoubleSet': nullabledoubleSet.toEJson(), + 'dateTimeSet': dateTimeSet.toEJson(), + 'nullabledateTimeSet': nullabledateTimeSet.toEJson(), + 'objectIdSet': objectIdSet.toEJson(), + 'nullableobjectIdSet': nullableobjectIdSet.toEJson(), + 'uuidSet': uuidSet.toEJson(), + 'nullableuuidSet': nullableuuidSet.toEJson(), + 'realmValueSet': realmValueSet.toEJson(), + 'realmObjectsSet': realmObjectsSet.toEJson(), }; } - static RealmSets _decodeRealmSets(EJsonValue ejson) { + static EJsonValue _toEJson(RealmSets value) => value.toEJson(); + static RealmSets _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'key': EJsonValue key, @@ -292,7 +294,7 @@ class RealmSets extends _RealmSets static final schema = () { RealmObjectBase.registerFactory(RealmSets._); - register(_encodeRealmSets, _decodeRealmSets); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, RealmSets, 'RealmSets', [ SchemaProperty('key', RealmPropertyType.int, primaryKey: true), SchemaProperty('boolSet', RealmPropertyType.bool, diff --git a/packages/realm_generator/test/good_test_data/required_argument.expected b/packages/realm_generator/test/good_test_data/required_argument.expected index dbf38a559..7849d093e 100644 --- a/packages/realm_generator/test/good_test_data/required_argument.expected +++ b/packages/realm_generator/test/good_test_data/required_argument.expected @@ -28,13 +28,14 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { @override Person freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodePerson(Person value) { + EJsonValue toEJson() { return { - 'name': toEJson(value.name), + 'name': name.toEJson(), }; } - static Person _decodePerson(EJsonValue ejson) { + static EJsonValue _toEJson(Person value) => value.toEJson(); + static Person _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'name': EJsonValue name, @@ -48,7 +49,7 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Person._); - register(_encodePerson, _decodePerson); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Person, 'Person', [ SchemaProperty('name', RealmPropertyType.string, primaryKey: true), ]); diff --git a/packages/realm_generator/test/good_test_data/required_argument_with_default_value.expected b/packages/realm_generator/test/good_test_data/required_argument_with_default_value.expected index d1b237f64..dde6c5c1c 100644 --- a/packages/realm_generator/test/good_test_data/required_argument_with_default_value.expected +++ b/packages/realm_generator/test/good_test_data/required_argument_with_default_value.expected @@ -35,13 +35,14 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { @override Person freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodePerson(Person value) { + EJsonValue toEJson() { return { - 'age': toEJson(value.age), + 'age': age.toEJson(), }; } - static Person _decodePerson(EJsonValue ejson) { + static EJsonValue _toEJson(Person value) => value.toEJson(); + static Person _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'age': EJsonValue age, @@ -55,7 +56,7 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Person._); - register(_encodePerson, _decodePerson); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Person, 'Person', [ SchemaProperty('age', RealmPropertyType.int), ]); diff --git a/packages/realm_generator/test/good_test_data/user_defined_getter.expected b/packages/realm_generator/test/good_test_data/user_defined_getter.expected index 79f6d4603..9aab3d61b 100644 --- a/packages/realm_generator/test/good_test_data/user_defined_getter.expected +++ b/packages/realm_generator/test/good_test_data/user_defined_getter.expected @@ -28,13 +28,14 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { @override Person freeze() => RealmObjectBase.freezeObject(this); - static EJsonValue _encodePerson(Person value) { + EJsonValue toEJson() { return { - 'name': toEJson(value.name), + 'name': name.toEJson(), }; } - static Person _decodePerson(EJsonValue ejson) { + static EJsonValue _toEJson(Person value) => value.toEJson(); + static Person _fromEJson(EJsonValue ejson) { return switch (ejson) { { 'name': EJsonValue name, @@ -48,7 +49,7 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { static final schema = () { RealmObjectBase.registerFactory(Person._); - register(_encodePerson, _decodePerson); + register(_toEJson, _fromEJson); return const SchemaObject(ObjectType.realmObject, Person, 'Person', [ SchemaProperty('name', RealmPropertyType.string), ]); From 04155e11986e9807ba84d61fa4969d74844c7219 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 5 Mar 2024 21:11:06 +0100 Subject: [PATCH 146/153] fix realm example --- packages/realm/example/lib/main.dart | 3 --- packages/realm/example/pubspec.yaml | 3 --- 2 files changed, 6 deletions(-) diff --git a/packages/realm/example/lib/main.dart b/packages/realm/example/lib/main.dart index 2a0666cb3..4e70f5986 100644 --- a/packages/realm/example/lib/main.dart +++ b/packages/realm/example/lib/main.dart @@ -5,12 +5,9 @@ import 'dart:io'; -import 'package:ejson/ejson.dart'; -import 'package:ejson_annotation/ejson_annotation.dart'; import 'package:flutter/material.dart'; import 'package:realm/realm.dart'; -part 'main.g.dart'; part 'main.realm.dart'; @RealmModel() diff --git a/packages/realm/example/pubspec.yaml b/packages/realm/example/pubspec.yaml index 592eef7d0..91c108ca3 100644 --- a/packages/realm/example/pubspec.yaml +++ b/packages/realm/example/pubspec.yaml @@ -11,14 +11,11 @@ environment: dependencies: flutter: sdk: flutter - ejson: ^0.1.0 - ejson_annotation: ^0.1.0 realm: ^1.8.0 characters: ^1.1.0 dev_dependencies: flutter_lints: ^3.0.1 - ejson_generator: ^0.1.0 flutter: uses-material-design: true From 46340f2e3a4d8da7ef597a59727cabd6ede381a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Tue, 5 Mar 2024 22:48:05 +0100 Subject: [PATCH 147/153] Update CONTRIBUTING.md --- CONTRIBUTING.md | 73 +++++++++++++------------------------------------ 1 file changed, 19 insertions(+), 54 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a1e778596..9ff034c09 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -27,69 +27,34 @@ Realm welcomes all contributions! The only requirement we have is that, like man [Please submit your CLA electronically using our Google form](https://docs.google.com/forms/d/1ga5zIS9qnwwFPmbq-orSPsiBIXQjltKg7ytHd2NmDYo/viewform) so we can accept your submissions. The GitHub username you file there will need to match that of your Pull Requests. If you have any questions or cannot file the CLA electronically, you can email . -## Building the source - -### Building Realm Flutter +## Building from source * Clone the repo - ``` + ```shell git clone https://github.com/realm/realm-dart + cd realm-dart git submodule update --init --recursive ``` - -#### Build Realm Flutter native binaries - -* Android - ```bash - ./scripts/build-android.sh all - scripts\build-android.bat all - # Or for Android Emulator only - ./scripts/build-android.sh x86 - scripts\build-android.bat x86 +* Activate [melos](https://melos.invertase.dev) + ```shell + dart pub global activate melos ``` - -* iOS - ```bash - ./scripts/build-ios.sh - # Or for iOS Simulator only - ./scripts/build-ios.sh simulator + Make sure that `~/.pub-cache/bin/` is added to your `PATH`. Otherwise you need to prefix the following `melos` commands with `dart pub global run`. + +* Setup project + ```shell + melos bootstrap + melos run setup ``` -* Windows - ``` - scripts\build.bat - ``` -* MacOS - ``` - ./scripts/build-macos.sh +* Build artifacts + ```shell + melos run build ``` -* Linux +* Test + ```shell + melos run test ``` - ./scripts/build-linux.sh - ``` - -### Building Realm Dart - -* Windows - ``` - scripts\build.bat - ``` -* MacOS - ``` - ./scripts/build-macos.sh - ``` -* Linux - ``` - ./scripts/build-linux.sh - ``` - -## Versioning - -Realm Flutter and Dart SDK packages follow [Semantic Versioning](https://semver.org/). -During the initial development the packages will be versioned according the scheme `0.major.minor+release stage` until the first stable version is reached then packages will be versioned with `major.minor.patch` scheme. -The first versions will follow `0.1.0+preview`, `0.1.1+preview` etc. -Then next release stages will pick up the next minor version `0.1.2+beta`, `0.1.3+beta`. This will ensure dependencies are updated on `dart pub get` with the new `alpha`, `beta` versions. -If an `alpha` version is released before `beta` and it needs to not be considered for `pub get` then it should be marked as `prerelease` with `-alpha` so `0.1.2-alpha` etc. -Updating the major version with every release stage is also possible - `0.2.0+alpha`, `0.3.0+beta`, `0.3.1+beta`. +There are many more melos scripts to run, see [melos.yaml](melos.yaml) for details. From 5126b35392cefac3d3691cceee41942771aceb3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 6 Mar 2024 08:19:39 +0100 Subject: [PATCH 148/153] No need to build realm_dart for maccatalyst by default, as flutter doesn't currentlys --- packages/realm_dart/scripts/build-ios.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/realm_dart/scripts/build-ios.sh b/packages/realm_dart/scripts/build-ios.sh index 730ba1b95..22fb3e303 100755 --- a/packages/realm_dart/scripts/build-ios.sh +++ b/packages/realm_dart/scripts/build-ios.sh @@ -21,7 +21,7 @@ function usage { } CONFIGURATION=Release -SUPPORT_PLATFORMS=(catalyst ios simulator) +SUPPORT_PLATFORMS=(ios simulator) # flutter doesn't support maccatalyst function is_supported_platform(){ for platform in "${SUPPORT_PLATFORMS[@]}"; do @@ -42,8 +42,8 @@ shift $((OPTIND-1)) PLATFORMS=($@) if [ -z ${PLATFORMS} ]; then - echo "No platform given. building all platforms..."; - PLATFORMS=(ios catalyst simulator) + echo "No platform given. building for all supported platforms..."; + PLATFORMS=(ios simulator) else echo "Building for..."; for check_platform in "${PLATFORMS[@]}"; do From 85a21ef60817ae0b4d86302bf50552db130ec958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 6 Mar 2024 01:43:16 +0100 Subject: [PATCH 149/153] More work on build.dart --- .vscode/settings.json | 5 +- packages/realm_dart/tool/build.dart | 268 +++++++++++++++++++++ packages/realm_dart/tool/build_native.dart | 90 ------- 3 files changed, 272 insertions(+), 91 deletions(-) create mode 100644 packages/realm_dart/tool/build.dart delete mode 100644 packages/realm_dart/tool/build_native.dart diff --git a/.vscode/settings.json b/.vscode/settings.json index 5218a0f21..2411f1d50 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -26,6 +26,7 @@ "HRESULT", "keepalive", "loggable", + "maccatalyst", "mugaritz", "nodoc", "nullptr", @@ -39,7 +40,9 @@ "upsert", "usercode", "userdata", - "writeln" + "writeln", + "xcframework", + "xcodebuild" ], "cmake.statusbar.advanced": { "ctest": { diff --git a/packages/realm_dart/tool/build.dart b/packages/realm_dart/tool/build.dart new file mode 100644 index 000000000..bb5bbb7c3 --- /dev/null +++ b/packages/realm_dart/tool/build.dart @@ -0,0 +1,268 @@ +// Copyright 2024 MongoDB, Inc. +// SPDX-License-Identifier: Apache-2.0 + +// This is a simple command-line tool to build native assets for realm_dart +// It is a precursor to the upcoming `native_assets` feature. +import 'dart:async'; +import 'dart:io' as io; +import 'package:args/command_runner.dart'; +import 'package:collection/collection.dart'; + +extension on Iterable { + T? firstEqualIgnoreCase(String? value) => value == null ? null : where((e) => equalsIgnoreAsciiCase(e.name, value)).firstOrNull; + Iterable get names => map((e) => e.name); +} + +// This enum is based on `Architecture` class from the upcoming `native_assets_cli` package +enum Architecture { + arm('armeabi-v7a'), + arm64('arm64-v8a'), + ia32('x86'), + riscv32, + riscv64, + x64('x86_64'), + ; + + final String? _cmakeName; + String get cmakeName => _cmakeName ?? name; + + const Architecture([this._cmakeName]); + + static Architecture? from(String name) => Architecture.values.firstEqualIgnoreCase(name); +} + +// This enum is based on `iOSSdk` class from the upcoming `native_assets_cli` package +// ignore: camel_case_types +enum iOSSdk { + iPhoneOS('device'), + iPhoneSimulator('simulator'), + ; // flutter doesn't support maccatalyst (yet?) + + final String? _cmakeName; + String get cmakeName => _cmakeName ?? name; + + const iOSSdk([this._cmakeName]); + + static iOSSdk? from(String? name) => iOSSdk.values.firstEqualIgnoreCase(name); +} + +// This enum is based on `OS` class from the upcoming `native_assets_cli` package +enum OS { + android, + iOS, + macOS, + windows, + linux, + ; + + String get cmakeName => name.toLowerCase(); + + static OS? from(String? name) => OS.values.firstEqualIgnoreCase(name); + static OS get current => from(io.Platform.operatingSystem) ?? (throw UnsupportedError('Unsupported OS: ${io.Platform.operatingSystem}')); +} + +// Currently supported targets +// This enum is based on `Target` class from the upcoming `native_assets_cli` package +enum Target { + androidArm(Architecture.arm, OS.android), + androidArm64(Architecture.arm64, OS.android), + androidIA32(Architecture.ia32, OS.android), + androidX64(Architecture.x64, OS.android), // only for emulator + // androidRiscv64, // not supported by realm currently + // fuchsiaArm64, // -"- etc. + // fuchsiaX64, + // iOSArm(Architecture.arm, OS.iOS), // <-- pre ios11, not even supported by flutter?!? + iOSArm64(Architecture.arm64, OS.iOS), + iOSX64(Architecture.x64, OS.iOS), // only for simulator + // linuxArm, + // linuxArm64, + // linuxIA32, + // linuxRiscv32, + // linuxRiscv64, + linuxX64(Architecture.x64, OS.linux), + macOSArm64(Architecture.arm64, OS.macOS), + macOSX64(Architecture.x64, OS.macOS), + // windowsArm64, + // windowsIA32, + windowsX64(Architecture.x64, OS.windows), + ; + + final Architecture architecture; + final OS os; + + const Target(this.architecture, this.os); + + static Target? from(String? name) => Target.values.firstEqualIgnoreCase(name); +} + +enum BuildMode { + debug('Debug'), + release('Release'), + ; + + final String cmakeName; + + const BuildMode(this.cmakeName); + + static BuildMode? from(String? name) => BuildMode.values.firstEqualIgnoreCase(name); +} + +abstract class _BaseCommand extends Command { + @override + final String name; + @override + final String description; + + _BaseCommand(this.name, this.description); + + late final verbose = globalResults!['verbose'] as bool; // don't access before run + + OS get os; + // currently target must match the host OS, or be an android platform + Iterable get possibleTargets => Target.values.where((t) => t.os == os || t.os == OS.android || (os == OS.macOS && t.os == OS.iOS)); +} + +class _BuildNativeCommand extends _BaseCommand { + _BuildNativeCommand() + : super( + 'native', + 'Build native assets for realm_dart', + ) { + argParser + ..addMultiOption( + 'target', + abbr: 't', + help: 'The target platform to build for. Defaults to all possible targets', + allowed: [...possibleTargets.names, 'all'], + defaultsTo: ['all'], + ) + ..addOption( + 'build-mode', + abbr: 'm', + allowed: BuildMode.values.names, + defaultsTo: BuildMode.release.name, + ) + ..addMultiOption( + 'ios-sdk', + abbr: 's', + help: 'The iOS SDK to build for. Ignored for non-iOS platforms. Defaults to all available SDKs.', + allowed: [...iOSSdk.values.names, 'all'], + defaultsTo: ['all'], + ); + } + + @override + OS get os => OS.current; + + Future runProc(List args) async { + final p = await io.Process.start(args.first, args.skip(1).toList()); + if (verbose) { + await io.stdout.addStream(p.stdout); + } else { + await for (final _ in p.stdout) { + io.stdout.write('.'); + } + } + final exitCode = await p.exitCode; + if (exitCode < 0) { + io.stderr.writeln('Error: "${args.join(' ')}" exited with code $exitCode'); + return exitCode; + } else { + return null; // return null if successful + } + } + + @override + Future run() async { + final argResults = this.argResults!; + final targetOptions = argResults['target'] as List; + + final targets = targetOptions.contains('all') // if 'all' is specified, build for all possible targets + ? possibleTargets + : targetOptions.map((o) => Target.from(o) ?? (throw ArgumentError.value(o, 'target', 'Invalid target'))); + + final buildMode = + BuildMode.from(argResults['build-mode'] as String?) ?? (throw ArgumentError.value(argResults['build-mode'], 'build-mode', 'Invalid build mode')); + + final iosSdkOptions = argResults['ios-sdk'] as List; + final iosSdks = iosSdkOptions.contains('all') // if 'all' is specified, build for all available SDKs + ? iOSSdk.values + : iosSdkOptions.map((o) => iOSSdk.from(o)).whereNotNull(); + + int? exitCode; + for (final target in targets) { + io.stdout.writeln('Building for ${target.name} in ${buildMode.name} mode'); + switch (target.os) { + case OS.iOS: + for (final sdk in iosSdks) { + exitCode ??= await runProc(['cmake', '--preset=ios']); + exitCode ??= await runProc(['cmake', '--build', '--preset=ios-${sdk.name}', '--config=${buildMode.cmakeName}']); + } + exitCode ??= await runProc([ + 'xcodebuild', + '-create-xcframework', + for (final s in iosSdks) '-framework ./binary/ios/${buildMode.cmakeName}-${s.name}/realm_dart.framework', + '-output ./binary/ios/realm_dart.xcframework', + ]); + break; + + case OS.android: + case OS.linux: + case OS.macOS: + case OS.windows: + final preset = '${target.os.cmakeName}${target.os == OS.android ? "-${target.architecture.cmakeName}" : ""}'; + exitCode ??= await runProc(['cmake', '--preset=$preset']); + exitCode ??= await runProc([ + 'cmake', + '--build', + '--preset=$preset', + '--config=${buildMode.cmakeName}', + if (target.os == OS.macOS) '-- -destination "generic/platform=macOS', + if (target.os == OS.android) '--target=strip', + ]); + break; + } + io.stdout.writeln(); + } + return exitCode ?? 0; + } +} + +class _PossibleTargets extends _BaseCommand { + _PossibleTargets() + : super( + 'targets', + 'List possible targets for building native assets', + ) { + argParser.addOption( + 'os', + abbr: 'o', + allowed: OS.values.names, + defaultsTo: OS.current.name, + ); + } + + late final _osOption = argResults?['os'] as String?; + @override + OS get os => OS.from(_osOption) ?? (throw ArgumentError.value(_osOption, 'os', 'Invalid OS')); + + @override + int run() { + print(possibleTargets.names.join('\n')); + return 0; + } +} + +Future main(List arguments) async { + final runner = CommandRunner('build', 'Helper tool for building realm_dart') + ..addCommand(_BuildNativeCommand()) + ..addCommand(_PossibleTargets()) + ..argParser.addFlag('verbose', abbr: 'v', help: 'Print verbose output', defaultsTo: false); + try { + final exitCode = await runner.run(arguments); + io.exit(exitCode!); + } on UsageException catch (error) { + print(error); + io.exit(64); // Exit code 64 indicates a usage error. + } +} diff --git a/packages/realm_dart/tool/build_native.dart b/packages/realm_dart/tool/build_native.dart deleted file mode 100644 index e95030db1..000000000 --- a/packages/realm_dart/tool/build_native.dart +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2024 MongoDB, Inc. -// SPDX-License-Identifier: Apache-2.0 - -import 'dart:io' as io; -import 'package:args/args.dart'; -import 'package:collection/collection.dart'; - -extension on Iterable { - T firstEqualIgnoreCase(String value) => firstWhere((e) => compareAsciiLowerCase(e.name, value) == 0); - Iterable get names => map((e) => e.name); -} - -enum Architecture { - arm('armeabi-v7a'), - arm64('arm64-v8a'), - ia32('x86'), - riscv32, - riscv64, - x64('x86_64'), - ; - - final String? _cmakeName; - String get cmakeName => _cmakeName ?? name; - - const Architecture([this._cmakeName]); - - static Architecture from(String name) => Architecture.values.firstEqualIgnoreCase(name); -} - -enum OS { - android, - ios, - macos, - windows, - linux, - ; - - static OS from(String name) => OS.values.firstEqualIgnoreCase(name); -} - -// Currently supported targets -enum Target { - androidArm, - androidArm64, - androidIA32, - androidX64, - // androidRiscv64, // not supported by realm currently - // fuchsiaArm64, // -"- etc. - // fuchsiaX64, - iOSArm, - iOSArm64, - // iOSX64, - // linuxArm, - // linuxArm64, - // linuxIA32, - // linuxRiscv32, - // linuxRiscv64, - linuxX64, - macOSArm64, - macOSX64, - // windowsArm64, - // windowsIA32, - windowsX64, - ; - - static Target from(String name) => Target.values.firstEqualIgnoreCase(name); -} - -enum BuildMode { - debug, - release, - ; - - static BuildMode from(String name) => BuildMode.values.firstWhere((e) => e.name == name); -} - -void main(List arguments) { - final parser = ArgParser() - ..addOption('target', abbr: 't', allowed: Target.values.names) - ..addOption('mode', abbr: 'm', allowed: BuildMode.values.names) - ..addOption('arch', abbr: 'a', allowed: Architecture.values.names); - - final argResults = parser.parse(arguments); - - final hostOS = OS.from(io.Platform.operatingSystem); - final targetOs = OS.from(argResults['target'] as String); - final buildMode = BuildMode.from(argResults['mode'] as String); - - print(io.Platform.operatingSystem); -} From 87ddff7da4ae523d6583ff05339ca5eab9d7010a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 6 Mar 2024 14:41:20 +0100 Subject: [PATCH 150/153] Update build:native script to use tool/build.dart --- melos.yaml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/melos.yaml b/melos.yaml index 1cbeab888..3bf9eb4a8 100644 --- a/melos.yaml +++ b/melos.yaml @@ -40,10 +40,8 @@ scripts: melos run build:binding && melos run build:dart - build:native: # make sure to set the CMAKE_PLATFORM and CMAKE_CONFIG environment variables - exec: >- - cmake --preset $CMAKE_PLATFORM && - cmake --build --preset $CMAKE_PLATFORM --config $CMAKE_CONFIG -- -destination "generic/platform=macOS" + build:native: + exec: dart run tool/build.dart native packageFilters: dirExists: src # by convention From 7db14a045dab16be5e99480986c9aa8c3345cab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 6 Mar 2024 15:48:33 +0100 Subject: [PATCH 151/153] A bit of gold plating.. --- packages/realm_dart/pubspec.yaml | 1 + packages/realm_dart/tool/build.dart | 63 ++++++++++++++++++----------- 2 files changed, 41 insertions(+), 23 deletions(-) diff --git a/packages/realm_dart/pubspec.yaml b/packages/realm_dart/pubspec.yaml index 73c70efc5..9eca10cc0 100644 --- a/packages/realm_dart/pubspec.yaml +++ b/packages/realm_dart/pubspec.yaml @@ -34,5 +34,6 @@ dev_dependencies: build_cli: ^2.2.2 json_serializable: ^6.3.1 lints: ^3.0.0 + mason_logger: ^0.2.12 test: ^1.14.3 timezone: ^0.9.0 diff --git a/packages/realm_dart/tool/build.dart b/packages/realm_dart/tool/build.dart index bb5bbb7c3..2df606cbb 100644 --- a/packages/realm_dart/tool/build.dart +++ b/packages/realm_dart/tool/build.dart @@ -7,6 +7,8 @@ import 'dart:async'; import 'dart:io' as io; import 'package:args/command_runner.dart'; import 'package:collection/collection.dart'; +import 'package:mason_logger/mason_logger.dart'; +import 'package:meta/meta.dart'; extension on Iterable { T? firstEqualIgnoreCase(String? value) => value == null ? null : where((e) => equalsIgnoreAsciiCase(e.name, value)).firstOrNull; @@ -154,22 +156,29 @@ class _BuildNativeCommand extends _BaseCommand { @override OS get os => OS.current; - Future runProc(List args) async { + Future runProc(List args, {required Logger logger, String? message}) async { final p = await io.Process.start(args.first, args.skip(1).toList()); + Progress? progress; if (verbose) { await io.stdout.addStream(p.stdout); } else { + message ??= args.join(' '); + final width = io.stdout.terminalColumns - 12; + message = message.padRight(width).substring(0, width); + progress = logger.progress(message); await for (final _ in p.stdout) { - io.stdout.write('.'); + progress.update(message); } } final exitCode = await p.exitCode; if (exitCode < 0) { - io.stderr.writeln('Error: "${args.join(' ')}" exited with code $exitCode'); + progress?.fail(message); + logger.err('Error: "$message}" exited with code $exitCode'); return exitCode; } else { + progress?.complete(message); return null; // return null if successful - } + } } @override @@ -191,19 +200,22 @@ class _BuildNativeCommand extends _BaseCommand { int? exitCode; for (final target in targets) { - io.stdout.writeln('Building for ${target.name} in ${buildMode.name} mode'); + logger.info('Building for ${target.name} in ${buildMode.name} mode'); switch (target.os) { case OS.iOS: for (final sdk in iosSdks) { - exitCode ??= await runProc(['cmake', '--preset=ios']); - exitCode ??= await runProc(['cmake', '--build', '--preset=ios-${sdk.name}', '--config=${buildMode.cmakeName}']); + exitCode ??= await runProc(['cmake', '--preset=ios'], logger: logger); + exitCode ??= await runProc(['cmake', '--build', '--preset=ios-${sdk.name.toLowerCase()}', '--config=${buildMode.cmakeName}'], logger: logger); } - exitCode ??= await runProc([ - 'xcodebuild', - '-create-xcframework', - for (final s in iosSdks) '-framework ./binary/ios/${buildMode.cmakeName}-${s.name}/realm_dart.framework', - '-output ./binary/ios/realm_dart.xcframework', - ]); + exitCode ??= await runProc( + [ + 'xcodebuild', + '-create-xcframework', + for (final s in iosSdks) '-framework ./binary/ios/${buildMode.cmakeName}-${s.name}/realm_dart.framework', + '-output ./binary/ios/realm_dart.xcframework', + ], + logger: logger, + ); break; case OS.android: @@ -211,15 +223,18 @@ class _BuildNativeCommand extends _BaseCommand { case OS.macOS: case OS.windows: final preset = '${target.os.cmakeName}${target.os == OS.android ? "-${target.architecture.cmakeName}" : ""}'; - exitCode ??= await runProc(['cmake', '--preset=$preset']); - exitCode ??= await runProc([ - 'cmake', - '--build', - '--preset=$preset', - '--config=${buildMode.cmakeName}', - if (target.os == OS.macOS) '-- -destination "generic/platform=macOS', - if (target.os == OS.android) '--target=strip', - ]); + exitCode ??= await runProc(['cmake', '--preset=$preset'], logger: logger); + exitCode ??= await runProc( + [ + 'cmake', + '--build', + '--preset=$preset', + '--config=${buildMode.cmakeName}', + if (target.os == OS.macOS) '-- -destination "generic/platform=macOS', + if (target.os == OS.android) '--target=strip', + ], + logger: logger, + ); break; } io.stdout.writeln(); @@ -253,6 +268,8 @@ class _PossibleTargets extends _BaseCommand { } } +final logger = Logger(progressOptions: ProgressOptions(trailing: '')); + Future main(List arguments) async { final runner = CommandRunner('build', 'Helper tool for building realm_dart') ..addCommand(_BuildNativeCommand()) @@ -262,7 +279,7 @@ Future main(List arguments) async { final exitCode = await runner.run(arguments); io.exit(exitCode!); } on UsageException catch (error) { - print(error); + logger.err('$error'); io.exit(64); // Exit code 64 indicates a usage error. } } From 3d72e93538a33199a630904a90e959ae4e502288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 6 Mar 2024 16:07:33 +0100 Subject: [PATCH 152/153] .. and some bugfixes --- packages/realm_dart/tool/build.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/realm_dart/tool/build.dart b/packages/realm_dart/tool/build.dart index 2df606cbb..21e185b33 100644 --- a/packages/realm_dart/tool/build.dart +++ b/packages/realm_dart/tool/build.dart @@ -163,7 +163,7 @@ class _BuildNativeCommand extends _BaseCommand { await io.stdout.addStream(p.stdout); } else { message ??= args.join(' '); - final width = io.stdout.terminalColumns - 12; + final width = io.stdout.hasTerminal ? io.stdout.terminalColumns - 12 : 80; message = message.padRight(width).substring(0, width); progress = logger.progress(message); await for (final _ in p.stdout) { @@ -205,13 +205,13 @@ class _BuildNativeCommand extends _BaseCommand { case OS.iOS: for (final sdk in iosSdks) { exitCode ??= await runProc(['cmake', '--preset=ios'], logger: logger); - exitCode ??= await runProc(['cmake', '--build', '--preset=ios-${sdk.name.toLowerCase()}', '--config=${buildMode.cmakeName}'], logger: logger); + exitCode ??= await runProc(['cmake', '--build', '--preset=ios-${sdk.cmakeName}', '--config=${buildMode.cmakeName}'], logger: logger); } exitCode ??= await runProc( [ 'xcodebuild', '-create-xcframework', - for (final s in iosSdks) '-framework ./binary/ios/${buildMode.cmakeName}-${s.name}/realm_dart.framework', + for (final s in iosSdks) '-framework ./binary/ios/${buildMode.cmakeName}-${s.name.toLowerCase()}/realm_dart.framework', '-output ./binary/ios/realm_dart.xcframework', ], logger: logger, From 904ef5b543ba87243f6381ac7703e686acd9c628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 6 Mar 2024 16:38:12 +0100 Subject: [PATCH 153/153] Important to drain both stdout and stderr --- packages/realm_dart/tool/build.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/realm_dart/tool/build.dart b/packages/realm_dart/tool/build.dart index 21e185b33..85b890c1d 100644 --- a/packages/realm_dart/tool/build.dart +++ b/packages/realm_dart/tool/build.dart @@ -8,7 +8,7 @@ import 'dart:io' as io; import 'package:args/command_runner.dart'; import 'package:collection/collection.dart'; import 'package:mason_logger/mason_logger.dart'; -import 'package:meta/meta.dart'; +import 'package:async/async.dart'; extension on Iterable { T? firstEqualIgnoreCase(String? value) => value == null ? null : where((e) => equalsIgnoreAsciiCase(e.name, value)).firstOrNull; @@ -160,13 +160,13 @@ class _BuildNativeCommand extends _BaseCommand { final p = await io.Process.start(args.first, args.skip(1).toList()); Progress? progress; if (verbose) { - await io.stdout.addStream(p.stdout); + await Future.wait([io.stdout.addStream(p.stdout), io.stderr.addStream(p.stderr)]); } else { message ??= args.join(' '); final width = io.stdout.hasTerminal ? io.stdout.terminalColumns - 12 : 80; message = message.padRight(width).substring(0, width); progress = logger.progress(message); - await for (final _ in p.stdout) { + await for (final _ in StreamGroup.merge([p.stdout, p.stderr])) { progress.update(message); } }