diff --git a/.github/workflows/run_ci.yml b/.github/workflows/run_ci.yml index b0d2c5f..5f3649a 100644 --- a/.github/workflows/run_ci.yml +++ b/.github/workflows/run_ci.yml @@ -16,7 +16,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] - dart: [2.19.6, stable, beta, dev] + dart: [3.0.5, stable, beta, dev] steps: - uses: actions/checkout@v3 - uses: dart-lang/setup-dart@v1.4 diff --git a/app/README.md b/app/README.md index cb92978..78fa68c 100644 --- a/app/README.md +++ b/app/README.md @@ -10,7 +10,7 @@ In `pubspec.yaml` tekartik_app_common_utils: git: url: https://github.com/tekartik/app_common_utils.dart - ref: dart2_3 + ref: dart3a path: app version: '>=0.1.0' ``` \ No newline at end of file diff --git a/app/pubspec.yaml b/app/pubspec.yaml index 747efda..80ae3c6 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -6,19 +6,19 @@ homepage: https://www.example.com publish_to: none environment: - sdk: '>=2.18.0 <4.0.0' + sdk: '>=3.0.0 <4.0.0' dependencies: pub_semver: tekartik_common_utils: git: url: https://github.com/tekartik/common_utils.dart - ref: dart2_3 + ref: dart3a version: '>=0.10.7' # tekartik_app_pager: # git: # url: https://github.com/tekartik/app_common_utils.dart -# ref: dart2_3 +# ref: dart3a # path: app_pager # version: '>=0.1.3' @@ -35,4 +35,4 @@ dependency_overrides: # path: ../app_pager # tmp # tekartik_common_utils: -# path: ../../common_utils.dart \ No newline at end of file +# path: ../../common_utils.dart diff --git a/app_bloc/README.md b/app_bloc/README.md index 71f3a37..5c3ba39 100644 --- a/app_bloc/README.md +++ b/app_bloc/README.md @@ -11,7 +11,7 @@ dependencies: tekartik_app_bloc: git: url: https://github.com/tekartik/app_common_utils.dart - ref: dart2_3 + ref: dart3a path: app_bloc version: '>=0.1.0' ``` diff --git a/app_bloc/pubspec.yaml b/app_bloc/pubspec.yaml index fa3d419..be70b47 100644 --- a/app_bloc/pubspec.yaml +++ b/app_bloc/pubspec.yaml @@ -4,13 +4,13 @@ version: 0.2.0 publish_to: none environment: - sdk: '>=2.18.0 <4.0.0' + sdk: '>=3.0.0 <4.0.0' dependencies: tekartik_common_utils: git: url: https://github.com/tekartik/common_utils.dart - ref: dart2_3 + ref: dart3a version: '>=0.10.7' meta: @@ -20,4 +20,4 @@ dev_dependencies: build_runner: '>=1.2.7' build_test: any build_web_compilers: any - process_run: \ No newline at end of file + process_run: diff --git a/app_crypto/README.md b/app_crypto/README.md index 940e732..f43f4b3 100644 --- a/app_crypto/README.md +++ b/app_crypto/README.md @@ -11,7 +11,7 @@ dependencies: tekartik_app_crypto: git: url: https://github.com/tekartik/app_common_utils.dart - ref: dart2_3 + ref: dart3a path: app_crypto version: '>=0.2.2' ``` diff --git a/app_crypto/lib/encrypt.dart b/app_crypto/lib/encrypt.dart index fcffcd9..2a9bc2e 100644 --- a/app_crypto/lib/encrypt.dart +++ b/app_crypto/lib/encrypt.dart @@ -1,4 +1,4 @@ export 'package:tekartik_app_crypto/src/encrypt.dart' - show encrypt, decrypt, StringEncrypter; + show encrypt, decrypt, StringEncrypter, defaultEncryptedFromRawPassword; export 'src/salsa20.dart' show salsa20EncrypterFromPassword; diff --git a/app_crypto/lib/encrypt_codec.dart b/app_crypto/lib/encrypt_codec.dart new file mode 100644 index 0000000..1aeedd7 --- /dev/null +++ b/app_crypto/lib/encrypt_codec.dart @@ -0,0 +1,2 @@ +export 'package:tekartik_app_crypto/src/encrypt_codec.dart' + show defaultEncryptCodec, EncryptCodec, salsa20EncryptCodec; diff --git a/app_crypto/lib/src/encrypt.dart b/app_crypto/lib/src/encrypt.dart index f676636..85f49a0 100644 --- a/app_crypto/lib/src/encrypt.dart +++ b/app_crypto/lib/src/encrypt.dart @@ -7,7 +7,7 @@ import 'package:encrypt/encrypt.dart'; /// returns a bast 64 encrypted string. /// /// Encryption used is AES. -String encrypt(String decoded, String password) { +String _encrypt(String decoded, String password) { final key = Key.fromUtf8(password); final iv = IV.fromLength(16); final encrypter = Encrypter(AES(key)); @@ -20,15 +20,52 @@ String encrypt(String decoded, String password) { /// [password] /// /// Encryption used is AES. -String decrypt(String encoded, String password) { +String _decrypt(String encoded, String password) { final key = Key.fromUtf8(password); final iv = IV.fromLength(16); final encrypter = Encrypter(AES(key)); return encrypter.decrypt(Encrypted.fromBase64(encoded), iv: iv); } +/// encrypt the [decoded] text using [password]. +/// +/// [password] must be ascii character of length 16, 24 or 32. +/// +/// returns a bast 64 encrypted string. +/// +/// Encryption used is AES. +String encrypt(String decoded, String password) => _encrypt(decoded, password); + +/// decrypt the [encoded] text using [password]. +/// +/// [encoded] is base 64 string got from the encrypt method using the same +/// [password] +/// +/// Encryption used is AES. +String decrypt(String encoded, String password) => _decrypt(encoded, password); + /// Encrypt, decrypt helper abstract class StringEncrypter { String encrypt(String input); + String decrypt(String encrypted); } + +/// Using AES, +/// [password] must be ascii character of length 16, 24 or 32. +class _DefaultEncrypter implements StringEncrypter { + final String password; + + _DefaultEncrypter(this.password); + + @override + String decrypt(String encrypted) => _decrypt(encrypted, password); + + @override + String encrypt(String input) => _encrypt(input, password); +} + +/// Using AES, +/// [password] must be ascii character of length 16, 24 or 32. +StringEncrypter defaultEncryptedFromRawPassword(String password) => + _DefaultEncrypter(password); diff --git a/app_crypto/lib/src/encrypt_codec.dart b/app_crypto/lib/src/encrypt_codec.dart new file mode 100644 index 0000000..636fa97 --- /dev/null +++ b/app_crypto/lib/src/encrypt_codec.dart @@ -0,0 +1,42 @@ +import 'dart:convert'; + +import 'package:tekartik_app_crypto/encrypt.dart'; + +class EncryptConverter with Converter { + final StringEncrypter encrypter; + + EncryptConverter({required this.encrypter}); + @override + String convert(String input) => encrypter.encrypt(input); +} + +class DecryptConverter with Converter { + final StringEncrypter encrypter; + + DecryptConverter({required this.encrypter}); + @override + String convert(String input) => encrypter.decrypt(input); +} + +/// Encrypt codec. +class EncryptCodec with Codec { + final StringEncrypter encrypter; + + EncryptCodec({required this.encrypter}); + + @override + Converter get decoder => + DecryptConverter(encrypter: encrypter); + + @override + Converter get encoder => + EncryptConverter(encrypter: encrypter); +} + +/// String password +EncryptCodec defaultEncryptCodec({required String rawPassword}) => + EncryptCodec(encrypter: defaultEncryptedFromRawPassword(rawPassword)); + +/// Any password can be used +EncryptCodec salsa20EncryptCodec({required String password}) => + EncryptCodec(encrypter: salsa20EncrypterFromPassword(password)); diff --git a/app_crypto/lib/src/salsa20.dart b/app_crypto/lib/src/salsa20.dart index ba5ef65..4ab2212 100644 --- a/app_crypto/lib/src/salsa20.dart +++ b/app_crypto/lib/src/salsa20.dart @@ -16,7 +16,7 @@ Uint8List _generateEncryptPassword(String password) { return blob; } -/// Salsa 20 encrypted using any password (use MD5) +/// Salsa 20 encrypted using any password (use MD5), random data prepended StringEncrypter salsa20EncrypterFromPassword(String password) { final key = Key(_generateEncryptPassword(password)); return _Salsa20StringEncrypter(Encrypter(Salsa20(key))); diff --git a/app_crypto/pubspec.yaml b/app_crypto/pubspec.yaml index 601d630..d61f79c 100644 --- a/app_crypto/pubspec.yaml +++ b/app_crypto/pubspec.yaml @@ -6,13 +6,13 @@ homepage: https://www.example.com publish_to: none environment: - sdk: '>=2.18.0 <4.0.0' + sdk: '>=3.0.0 <4.0.0' dependencies: tekartik_common_utils: git: url: https://github.com/tekartik/common_utils.dart - ref: dart2_3 + ref: dart3a version: '>=0.10.7' meta: '>=1.1.6' encrypt: '>=3.0.0' @@ -26,4 +26,4 @@ dev_dependencies: build_runner: '>=1.2.7' build_test: any build_web_compilers: any - process_run: '>=0.12.0+1' \ No newline at end of file + process_run: '>=0.12.0+1' diff --git a/app_crypto/test/codec_test.dart b/app_crypto/test/codec_test.dart new file mode 100644 index 0000000..a2dc04f --- /dev/null +++ b/app_crypto/test/codec_test.dart @@ -0,0 +1,12 @@ +import 'package:tekartik_app_crypto/encrypt_codec.dart'; + +import 'package:test/test.dart'; + +void main() { + test('test', () { + var password = r'E4x*$TwbkJC-xK4KGC4zJF9j*Rh&WLgR'; + var encryptCodec = defaultEncryptCodec(rawPassword: password); + expect(encryptCodec.encode('test'), 'amGhyRRLUIoE59IiEys5Vw=='); + expect(encryptCodec.decode('amGhyRRLUIoE59IiEys5Vw=='), 'test'); + }); +} diff --git a/app_csv/README.md b/app_csv/README.md index 804c537..cb88ca5 100644 --- a/app_csv/README.md +++ b/app_csv/README.md @@ -11,7 +11,7 @@ In `pubspec.yaml` tekartik_app_csv: git: url: https://github.com/tekartik/app_common_utils.dart - ref: dart2_3 + ref: dart3a path: app_csv version: '>=0.1.0' ``` \ No newline at end of file diff --git a/app_csv/pubspec.yaml b/app_csv/pubspec.yaml index e0aa556..80cf053 100644 --- a/app_csv/pubspec.yaml +++ b/app_csv/pubspec.yaml @@ -6,14 +6,14 @@ homepage: https://github.com/tekartik/app_common_utils.dart publish_to: none environment: - sdk: '>=2.18.0 <4.0.0' + sdk: '>=3.0.0 <4.0.0' dependencies: csv: '>=5.0.0-0' tekartik_common_utils: git: url: https://github.com/tekartik/common_utils.dart - ref: dart2_3 + ref: dart3a version: '>=0.10.7' dev_dependencies: path: @@ -21,4 +21,4 @@ dev_dependencies: test: ^1.6.0 process_run: build_runner: - build_test: \ No newline at end of file + build_test: diff --git a/app_cv/.gitignore b/app_cv/.gitignore deleted file mode 100644 index 0c44ab0..0000000 --- a/app_cv/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -# Files and directories created by pub -.dart_tool/ -.packages - -# Omit commiting pubspec.lock for library packages: -# https://dart.dev/guides/libraries/private-files#pubspeclock -pubspec.lock - -# Conventional directory for build outputs -build/ - -# Directory created by dartdoc -doc/api/ diff --git a/app_cv/CHANGELOG.md b/app_cv/CHANGELOG.md deleted file mode 100644 index 553fe21..0000000 --- a/app_cv/CHANGELOG.md +++ /dev/null @@ -1,7 +0,0 @@ -## 0.5.0 - -- Add `CvField.withName` - -## 0.1.0 - -- Initial version diff --git a/app_cv/README.md b/app_cv/README.md deleted file mode 100644 index d36c494..0000000 --- a/app_cv/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# App Content Values - -Helper for content values - -***Obsolete, use cv*** - -# Setup - -In `pubspec.yaml` - -```yaml -tekartik_app_cv: - git: - url: https://github.com/tekartik/app_common_utils.dart - ref: dart2_3 - path: app_cv - version: '>=0.1.0' -``` \ No newline at end of file diff --git a/app_cv/analysis_options.yaml b/app_cv/analysis_options.yaml deleted file mode 100644 index 8b22987..0000000 --- a/app_cv/analysis_options.yaml +++ /dev/null @@ -1,7 +0,0 @@ -# tekartik analysis_options extension to pedantic -include: package:tekartik_lints/strict.yaml - -analyzer: - language: - strict-casts: true - # strict-inference: true \ No newline at end of file diff --git a/app_cv/lib/app_cv.dart b/app_cv/lib/app_cv.dart deleted file mode 100644 index 2ee9902..0000000 --- a/app_cv/lib/app_cv.dart +++ /dev/null @@ -1,26 +0,0 @@ -export 'package:tekartik_common_utils/model/model.dart'; - -export 'src/builder.dart' - show - cvAddBuilder, - cvBuildModel, - cvTypeBuildModel, - cvModelField, - cvModelListField, - CvMapExt, - CvMapListExt; -export 'src/cv_field.dart' - show - CvField, - cvValuesAreEqual, - CvModelListField, - CvListField, - CvFieldListExt, - CvModelField, - CvModelFieldUtilsExt, - CvFieldUtilsExt, - CvListFieldUtilsExt, - CvFillOptions; -export 'src/cv_model.dart' - show CvModel, CvMapModel, CvModelBase, CvModelUtilsExt; -export 'src/cv_model_list.dart' show CvModelListExt; diff --git a/app_cv/lib/app_cv_v1.dart b/app_cv/lib/app_cv_v1.dart deleted file mode 100644 index 8d32d92..0000000 --- a/app_cv/lib/app_cv_v1.dart +++ /dev/null @@ -1,29 +0,0 @@ -@Deprecated('Use v2') -library tekartik_app_cv_v1; - -export 'package:tekartik_common_utils/model/model.dart'; - -export 'src/builder.dart' - show - cvAddBuilder, - cvBuildModel, - cvTypeBuildModel, - cvModelField, - cvModelListField, - CvMapExt, - CvMapListExt; -export 'src/cv_field.dart' - show - CvField, - cvValuesAreEqual, - CvModelListField, - CvListField, - CvFieldListExt, - CvModelField, - CvModelFieldUtilsExt, - CvFieldUtilsExt, - CvListFieldUtilsExt, - CvFillOptions; -export 'src/cv_model.dart' - show CvModel, CvMapModel, CvModelBase, CvModelUtilsExt; -export 'src/cv_model_list.dart' show CvModelListExt; diff --git a/app_cv/lib/app_cv_v2.dart b/app_cv/lib/app_cv_v2.dart deleted file mode 100644 index c823f62..0000000 --- a/app_cv/lib/app_cv_v2.dart +++ /dev/null @@ -1,20 +0,0 @@ -import 'package:cv/cv.dart'; - -export 'package:cv/cv.dart'; - -extension CvModelCompat on CvModel { - /// Convert to map - Model toModel({List? columns, bool includeMissingValue = false}) => - toMap(columns: columns, includeMissingValue: includeMissingValue); - - /// Map alias - void fromModel(Map map, {List? columns}) => - fromMap(map, columns: columns); -} - -extension CvModelListCompat on List { - /// Convert to list - List> toModelList( - {List? columns, bool includeMissingValue = false}) => - toMapList(columns: columns, includeMissingValue: includeMissingValue); -} diff --git a/app_cv/lib/src/builder.dart b/app_cv/lib/src/builder.dart deleted file mode 100644 index 3786bfa..0000000 --- a/app_cv/lib/src/builder.dart +++ /dev/null @@ -1,67 +0,0 @@ -import 'package:meta/meta.dart'; -import 'package:tekartik_app_cv/app_cv.dart'; - -/// Global builder map -var _builders = {}; - -/// Add builder -void cvAddBuilder(T Function(Map contextData) builder) { - _builders[T] = builder; -} - -/// Remove builder -@visibleForTesting -void cvRemoveBuilder(Type type) { - _builders.remove(type); -} - -/// Build a model but does not import the data. -T cvBuildModel(Map contextData, - {T Function(Map contextData)? builder}) { - if (builder == null) { - var foundBuilder = _builders[T]; - if (foundBuilder == null) { - throw UnsupportedError('Missing builder for $T, call addBuilder'); - } - return foundBuilder(contextData) as T; - } else { - return builder(contextData); - } -} - -/// Build a model but does not import the data. -T cvTypeBuildModel(Type type, Map contextData, - {T Function(Map contextData)? builder}) { - if (builder == null) { - var foundBuilder = _builders[type]; - if (foundBuilder == null) { - throw UnsupportedError('Missing builder for $type, call addBuilder'); - } - return foundBuilder(contextData) as T; - } else { - return builder(contextData); - } -} - -/// Auto field -CvModelField cvModelField(String name) => - CvModelField(name, (data) => cvBuildModel(data as Map)); - -/// Auto field -CvModelListField cvModelListField(String name) => - CvModelListField(name, (data) => cvBuildModel(data as Map)); - -/// Easy extension -extension CvMapExt on Map { - /// Create an antry from a map - T cv({T Function(Map contextData)? builder}) { - return cvBuildModel(this, builder: builder)..fromModel(this); - } -} - -/// Easy extension -extension CvMapListExt on List { - /// Create a list of DbRecords from a snapshot - List cv({T Function(Map contextData)? builder}) => - map((map) => map.cv(builder: builder)).toList(); -} diff --git a/app_cv/lib/src/column.dart b/app_cv/lib/src/column.dart deleted file mode 100644 index f31f176..0000000 --- a/app_cv/lib/src/column.dart +++ /dev/null @@ -1,51 +0,0 @@ -abstract class RawColumn { - String get name; -} - -abstract class CvColumn implements RawColumn { - factory CvColumn(String name) => ColumnImpl(name); - - Type get type; - - bool get isTypeInt; - - bool get isTypeString; -} - -class ColumnImpl - with CvColumnMixin, ColumnNameMixin - implements CvColumn { - ColumnImpl(String name) { - this.name = name; - } -} - -mixin ColumnNameMixin implements RawColumn { - @override - late String name; - - @override - bool operator ==(other) { - if (other is RawColumn) { - return other.name == name; - } - return false; - } -} - -mixin CvColumnMixin implements CvColumn { - @override - Type get type => T; - - @override - int get hashCode => name.hashCode; - - @override - bool get isTypeInt => T == int; - - @override - bool get isTypeString => T == String; - - @override - String toString() => 'Column($name)'; -} diff --git a/app_cv/lib/src/content_values.dart b/app_cv/lib/src/content_values.dart deleted file mode 100644 index 42f5b63..0000000 --- a/app_cv/lib/src/content_values.dart +++ /dev/null @@ -1,222 +0,0 @@ -// ignore_for_file: inference_failure_on_function_invocation - -import 'dart:collection'; - -import 'package:tekartik_app_cv/app_cv.dart'; -import 'package:tekartik_app_cv/src/column.dart'; - -import 'cv_model_mixin.dart'; -import 'field.dart'; - -abstract class CvBase - with - // Order is important, first one wins - ContentValuesMapMixin, - ConventValuesKeysFromCvFieldsMixin, - CvModelMixin, - MapMixin {} - -abstract class ContentValues implements Map, CvMapModel { - /// Map based content values - factory ContentValues() => ContentValuesMap(); - - factory ContentValues.withCvFields(List fields) { - return _ContentValuesWithCvFields(fields); - } -} - -/// CvField in the map base implementation -class _CvMapField - with CvColumnMixin, ColumnNameMixin, CvFieldMixin - implements CvField { - final ContentValues cv; - - /// Only set value if not null - _CvMapField(this.cv, String name, [T? value]) { - this.name = name; - setValue(value); - } - - /// Force a null value - _CvMapField.withNull(this.cv, String name) { - this.name = name; - setNull(); - } - - @override - T? get v => cv[name] as T?; - - @override - CvField cast() => - T == RT ? this as CvField : _CvMapField(cv, name); - - @override - void clear() => cv.remove(name); - - @override - void fromCvField(CvField cvField) { - // copy the value whatever the name is - if (cvField.hasValue) { - cv[name] = cvField.v; - } else { - cv.remove(name); - } - } - - @override - bool get hasValue => cv.containsKey(name); - - @override - bool get isNull => cv[name] == null; - - @override - String get k => name; - - @override - void removeValue() { - cv.remove(name); - } - - @override - void setNull() { - cv[name] = null; - } - - @override - void setValue(value, {bool presentIfNull = false}) { - if (value != null) { - cv[name] = value; - } else if (presentIfNull) { - cv[name] = null; - } else { - cv.remove(name); - } - } - - @override - set v(T? value) { - cv[name] = value; - } -} - -mixin _MapBaseMixin implements Map { - late Map _map; - - @override - dynamic operator [](Object? key) => _map[key as String]; - - @override - void operator []=(String key, value) => _map[key] = value; - - @override - void clear() => _map.clear(); - - @override - Iterable get keys => _map.keys; - - @override - dynamic remove(Object? key) => _map.remove(key); -} - -// ignore: unused_element -class _TestClass with _MapBaseMixin, MapMixin {} - -/// A Map based implementation. Default implementation for content values -class ContentValuesMap - with -// Order is important, first one wins - CvModelMixin, - _MapBaseMixin, - MapMixin //ContentValuesMapMixin - implements - ContentValues { - ContentValuesMap([Map? map]) { - _map = map ?? {}; - } - - @override - List get fields => keys - .map((name) => field(name)!) - //.where((field) => field != null) - .toList(); - - @override - CvField? field(String name) { - var value = this[name]; - if (value != null) { - return _CvMapField(this, name, value as T); - } else { - if (containsKey(name)) { - return _CvMapField.withNull(this, name); - } - } - return null; - } - - @override - void fromModel(Map? map, {List? columns}) { - if (columns == null) { - map!.forEach((key, value) { - _map[key.toString()] = value; - }); - } else { - for (var column in columns) { - if (map!.containsKey(column)) { - _map[column] = map[column]; - } - } - } - } - - @override - void copyFrom(CvModel model) { - for (var field in model.fields) { - if (field.hasValue) { - _map[field.k] = field.v; - } - } - } -} - -/// Keys from CvFields -mixin ConventValuesKeysFromCvFieldsMixin implements ContentValues { - @override - Iterable get keys => fields.map((field) => field.name); -} - -mixin ContentValuesMapMixin implements ContentValues { - @override - dynamic operator [](Object? key) { - if (key != null) { - return field(key.toString())?.v; - } else { - return null; - } - } - - @override - void operator []=(key, value) { - field(key.toString())?.v = value; - } - - @override - void clear() { - for (var field in fields) { - field.clear(); - } - } - - @override - dynamic remove(Object? key) { - if (key != null) { - field(key.toString())?.clear(); - } - } -} - -class _ContentValuesWithCvFields extends CvBase { - @override - final List fields; - - _ContentValuesWithCvFields(this.fields); -} diff --git a/app_cv/lib/src/cv_content.dart b/app_cv/lib/src/cv_content.dart deleted file mode 100644 index 584d57f..0000000 --- a/app_cv/lib/src/cv_content.dart +++ /dev/null @@ -1 +0,0 @@ -abstract class CvContent {} diff --git a/app_cv/lib/src/cv_field.dart b/app_cv/lib/src/cv_field.dart deleted file mode 100644 index 395b6e8..0000000 --- a/app_cv/lib/src/cv_field.dart +++ /dev/null @@ -1,197 +0,0 @@ -import 'package:collection/collection.dart'; -import 'package:tekartik_app_cv/app_cv.dart'; -import 'package:tekartik_app_cv/src/cv_field_with_parent.dart'; - -import 'cv_model.dart'; -import 'field.dart'; - -/// If 2 values are equals, entering nested list/map if any. -bool cvValuesAreEqual(dynamic v1, dynamic v2) { - try { - return DeepCollectionEquality().equals(v1, v2); - } catch (_) { - return v1 == v2; - } -} - -/// Basic CvField -abstract class CvField implements CvFieldCore { - /// Only set value if not null - factory CvField(String name, [T? value]) => CvFieldImpl(name, value); - - /// Force a null value - factory CvField.withNull(String name) => CvFieldImpl.withNull(name); - - /// Force a value event if null - factory CvField.withValue(String name, T value) => - CvFieldImpl.withValue(name, value); -} - -/// Nested list of raw values -abstract class CvListField implements CvField> { - /// List create helper - List createList(); - - /// List item type - Type get itemType; - - /// Only set value if not null - factory CvListField(String name) => ListCvFieldImpl(name); -} - -/// Field utils. -extension CvFieldUtilsExt on CvField { - /// For test - void fillField([CvFillOptions? options]) { - options ??= CvFillOptions(); - if (this is CvListField) { - (this as CvListField).fillList(options); - } else if (this is CvModelField) { - var modelValue = (this as CvModelField).create({})..fillModel(options); - v = modelValue as T; - } else if (this is CvFieldWithParent) { - (this as CvFieldWithParent).field.fillField(options); - } else if (options.valueStart != null) { - v = options.generateValue(type) as T; - } else { - // Default to null - v = null; - } - } - - /// Create a new field with a new name - CvField withName(String name) => CvField(name, value); -} - -/// Generate for bool, int, num, text -Object? cvFillOptionsGenerateBasicType(Type type, CvFillOptions options) { - Object? v; - if (options.valueStart != null) { - var valueStart = options.valueStart! + 1; - if (type == int) { - v = valueStart; - } else if (type == num) { - v = valueStart.isEven ? valueStart : (valueStart + .5); - } else if (type == double) { - v = (valueStart + .5); - } else if (type == String) { - v = 'text_$valueStart'; - } else if (type == bool) { - v = valueStart.isEven; - } - if (v != null) { - options.valueStart = valueStart; - } - } - - return v; -} - -typedef CvFillOptionsGenerateFunction = Object? Function( - Type type, CvFillOptions options); - -/// Fill options for unit tests -class CvFillOptions { - final int? collectionSize; - int? valueStart; - final CvFillOptionsGenerateFunction? generate; - - Object? generateValue(Type type) => (generate == null) - ? cvFillOptionsGenerateBasicType(type, this) - : (generate!(type, this) ?? cvFillOptionsGenerateBasicType(type, this)); - - CvFillOptions({this.collectionSize, this.valueStart, this.generate}); -} - -/// Fill helpers -extension CvListFieldUtilsExt on CvListField { - void fillList([CvFillOptions? options]) { - options ??= CvFillOptions(); - var collectionSize = options.collectionSize; - if (collectionSize == null) { - value = null; - } else { - var list = createList(); - for (var i = 0; i < collectionSize; i++) { - if (this is CvModelListField) { - var item = (this as CvModelListField).create({}) as T; - (item as CvModel).fillModel(options); - list.add(item); - } else if (this is CvListField) { - if (options.valueStart != null) { - print('map $this'); - var map = {}; - for (var i = 0; i < collectionSize; i++) { - map['field_$i'] = options.generateValue(int); - } - list.add(map as T); - } - } else if (this is CvListField) { - if (options.valueStart != null) { - print('list $this'); - var subList = []; - for (var i = 0; i < collectionSize; i++) { - subList.add(options.generateValue(int)); - } - list.add(subList as T); - } - } else { - if (options.valueStart != null) { - print('item $this'); - list.add(options.generateValue(itemType) as T); - } - } - } - value = list; - } - } -} - -extension CvModelFieldUtilsExt on CvModelField { - /// Fill all null in model including leaves - /// - /// Fill list if listSize is set - /// - void fillModel([CvFillOptions? options]) { - options ??= CvFillOptions(); - value = create({}); - value!.fillModel(options); - } -} - -/// Nested model -abstract class CvModelField implements CvField { - /// contentValue should be ignored - T create(Map contentValue); - - /// Only set value if not null - factory CvModelField(String name, - [T Function(dynamic contentValue)? create]) => - CvFieldContentImpl(name, create); -} - -/// Utilities -extension CvFieldListExt on List { - /// Copy all fields - void fromCvFields(List fields) { - assert(length == fields.length); - for (var i = 0; i < length; i++) { - this[i].fromCvField(fields[i]); - } - } -} - -/// Nested list -abstract class CvModelListField implements CvListField { - /// contentValue should be ignored or could be used to create the proper object - /// but its content should not be populated. - T create(Map contentValue); - - @override - List createList(); - - /// Only set value if not null - factory CvModelListField(String name, - [T Function(dynamic contentValue)? create]) => - CvFieldContentListImpl(name, create); -} diff --git a/app_cv/lib/src/cv_field_with_parent.dart b/app_cv/lib/src/cv_field_with_parent.dart deleted file mode 100644 index 307c009..0000000 --- a/app_cv/lib/src/cv_field_with_parent.dart +++ /dev/null @@ -1,120 +0,0 @@ -import 'package:tekartik_app_cv/app_cv.dart'; - -/// Class that has parent map -abstract class CvFieldWithParent implements CvField { - CvField get field; - - String get parent; -} - -class CvFieldWithParentImpl< - T> //with CvColumnMixin, ColumnNameMixin, CvFieldMixin - implements - CvFieldWithParent { - @override - final CvField field; - @override - final String parent; - - CvFieldWithParentImpl(this.field, this.parent); - - @override - T? get v => value; - - @override - T? get value => field.value; - - @override - CvField cast() => field.cast().withParent(parent); - - @override - void clear() { - field.clear(); - } - - @override - void fromCvField(CvField cvField) { - field.fromCvField(cvField); - } - - @override - bool get hasValue => field.hasValue; - - @override - bool get isNull => field.isNull; - - @override - bool get isTypeInt => field.isTypeInt; - - @override - bool get isTypeString => field.isTypeString; - - @override - String get k => key; - - @override - String get key => '$parent.${field.name}'; - - @override - String get name => key; - - @override - void removeValue() { - // ignore: deprecated_member_use_from_same_package - field.removeValue(); - } - - @override - void setNull() { - field.setNull(); - } - - @override - void setValue(T? value, {bool presentIfNull = false}) { - field.setValue(value, presentIfNull: presentIfNull); - } - - @override - Type get type => field.type; - - @override - CvField withParent(String parent) { - // TODO: implement withParent - throw UnimplementedError(); - } - - @override - set v(T? value) { - this.value = value; - } - - @override - set value(T? value) { - field.value = value; - } - - @override - String toString() { - return '$parent.$field'; - } - - @override - int get hashCode => key.hashCode + (v?.hashCode ?? 0); - - @override - bool operator ==(other) { - if (other is CvField) { - if (other.key != key) { - return false; - } - if (other.hasValue != hasValue) { - return false; - } - if (!cvValuesAreEqual(other.v, v)) { - return false; - } - return true; - } - return false; - } -} diff --git a/app_cv/lib/src/cv_model.dart b/app_cv/lib/src/cv_model.dart deleted file mode 100644 index cb9e3b0..0000000 --- a/app_cv/lib/src/cv_model.dart +++ /dev/null @@ -1,75 +0,0 @@ -import 'package:tekartik_app_cv/app_cv.dart'; - -import 'content_values.dart'; -import 'cv_model_mixin.dart'; - -/// Read helper -abstract class CvModelRead implements CvModelCore { - /// Convert to model - Model toModel({List? columns, bool includeMissingValue = false}); - - /// Map alias - Map toMap( - {List? columns, bool includeMissingValue = false}); -} - -/// Write helper -abstract class CvModelWrite implements CvModelCore { - /// Convert from model. - void fromModel(Map map, {List? columns}); - - /// Map alias - void fromMap(Map map, {List? columns}); - - /// Clear content - void clear(); - - /// Copy from another model - void copyFrom(CvModel model); -} - -/// Core model -abstract class CvModelCore { - /// to override something like [name, description] - List get fields; - - /// CvField access - CvField? field(String name); -} - -/// Modifiable map. -abstract class CvMapModel implements CvModel, Map { - /// Basic content values factory - factory CvMapModel() => ContentValuesMap(); - - /// Predefined fields, values can be changed but none can added. - /// Usage discouraged unless you known the limitations. - factory CvMapModel.withFields(List list) { - return ContentValues.withCvFields(list); - } -} - -/// Model to access the data -abstract class CvModel implements CvModelRead, CvModelWrite, CvModelCore {} - -/// Base content class -abstract class CvModelBase with CvModelMixin {} - -// ignore: unused_element -class _CvModelMock extends CvModelBase { - @override - List get fields => throw UnimplementedError(); -} - -extension CvModelUtilsExt on CvModel { - /// Fill all null in model including leaves - /// - /// Fill list if listSize is set - /// - void fillModel([CvFillOptions? options]) { - var fields = this.fields; - for (var field in fields) { - field.fillField(options); - } - } -} diff --git a/app_cv/lib/src/cv_model_list.dart b/app_cv/lib/src/cv_model_list.dart deleted file mode 100644 index c19b3cd..0000000 --- a/app_cv/lib/src/cv_model_list.dart +++ /dev/null @@ -1,19 +0,0 @@ -import 'package:tekartik_app_cv/app_cv.dart'; - -/// List convenient extensions. -extension CvModelListExt on List { - /// Convert to model list - ModelList toModelList( - {List? columns, bool includeMissingValue = false}) { - return ModelList(map((e) => - e.toModel(columns: columns, includeMissingValue: includeMissingValue))); - } - - /// Convert to model list - List> toMapList( - {List? columns, bool includeMissingValue = false}) { - return ModelList(map((e) => e.toModel( - columns: columns, includeMissingValue: includeMissingValue))) - .cast>(); - } -} diff --git a/app_cv/lib/src/cv_model_mixin.dart b/app_cv/lib/src/cv_model_mixin.dart deleted file mode 100644 index 19c02aa..0000000 --- a/app_cv/lib/src/cv_model_mixin.dart +++ /dev/null @@ -1,234 +0,0 @@ -// ignore_for_file: inference_failure_on_function_invocation - -import 'package:tekartik_app_cv/app_cv.dart'; -import 'package:tekartik_app_cv/src/cv_field_with_parent.dart'; -import 'package:tekartik_app_cv/src/cv_model.dart'; -import 'package:tekartik_common_utils/env_utils.dart'; - -import 'field.dart'; -import 'utils.dart'; - -var debugContent = false; // devWarning(true); - -/// Content mixin -mixin CvModelMixin implements CvModel { - @override - void fromModel(Map map, {List? columns}) { - fromMap(map, columns: columns); - } - - /// Copy content - @override - void copyFrom(CvModel model) { - _debugCheckCvFields(); - for (var field in fields) { - var recordCvField = model.field(field.name); - if (recordCvField?.hasValue == true) { - // ignore: invalid_use_of_visible_for_testing_member - field.fromCvField(recordCvField!); - } - } - } - - void _debugCheckCvFields() { - if (isDebug) { - var success = _debugCvFieldsCheckDone[runtimeType]; - - if (success == null) { - var fieldNames = {}; - for (var field in fields) { - if (fieldNames.contains(field.name)) { - _debugCvFieldsCheckDone[runtimeType] = false; - throw UnsupportedError( - 'Duplicated CvField ${field.name} in $runtimeType${fields.map((f) => f.name)} - $this'); - } - fieldNames.add(field.name); - } - _debugCvFieldsCheckDone[runtimeType] = success = true; - } else if (!success) { - throw UnsupportedError( - 'Duplicated CvFields in $runtimeType${fields.map((f) => f.name)} - $this'); - } - } - } - - @override - Model toModel({List? columns, bool includeMissingValue = false}) { - return asModel( - toMap(columns: columns, includeMissingValue: includeMissingValue))!; - } - - @override - String toString() { - try { - return logTruncate('${toModel()}'); - } catch (e) { - return logTruncate('$fields $e'); - } - } - - // Only created if necessary - Map? _cvFieldMap; - - @override - CvField? field(String name) { - // Invalidate if needed - if (_cvFieldMap != null) { - if (_cvFieldMap!.length != fields.length) { - _cvFieldMap = null; - } - } - _cvFieldMap ??= - Map.fromEntries(fields.map((field) => MapEntry(field.name, field))); - return _cvFieldMap![name]?.cast(); - } - - @override - int get hashCode => fields.first.hashCode; - - @override - bool operator ==(other) { - if (other is CvModelRead) { - return cvModelAreEquals(this, other); - } - return false; - } - - @override - void fromMap(Map map, {List? columns}) { - _debugCheckCvFields(); - // assert(map != null, 'map cannot be null'); - columns ??= fields.map((e) => e.name).toList(); - var model = Model(map); - for (var column in columns) { - try { - var field = this.field(column)!; - ModelEntry? entry; - - if (field is CvFieldWithParent) { - var parentModel = model; - var parentField = field; - while (true) { - var child = parentModel.getValue(parentField.parent); - if (child is Map) { - parentModel = Model(child); - var subField = parentField.field; - if (subField is CvFieldWithParent) { - parentField = subField; - } else if (subField is CvFieldContent) { - var modelEntry = parentModel.getModelEntry(subField.name); - var modelEntryValue = modelEntry?.value; - if (modelEntryValue is Map) { - entry = ModelEntry( - modelEntry!.key.toString(), - subField.create(modelEntryValue) - ..fromModel(modelEntryValue)); - } - - break; - //subField.create(modelEntry)..fromModel(modelEntry) - } else { - entry = parentModel.getModelEntry(subField.name); - break; - } - } - } - } else { - entry = model.getModelEntry(field.name); - } - if (entry != null) { - if (field is CvFieldContentList) { - var list = field.v = field.createList(); - for (var rawItem in entry.value as List) { - var item = field.create(rawItem as Map)..fromModel(rawItem); - list.add(item); - } - field.v = list; - } else if (field is CvFieldContent) { - var entryValue = entry.value; - var cvModel = field.create(entryValue as Map); - field.v = cvModel; - - cvModel.fromModel(entryValue); - } else if (field is CvListField) { - var list = field.v = field.createList(); - for (var rawItem in entry.value as List) { - list.add(rawItem); - } - field.v = list; - } else { - try { - field.v = entry.value; - } catch (_) { - // Special string handling - if (field.isTypeString) { - field.v = entry.value?.toString(); - } else { - rethrow; - } - } - } - } - } catch (e) { - if (debugContent) { - print('ERROR fromModel($map, $columns) at $column'); - } - } - } - } - - @override - Map toMap( - {List? columns, bool includeMissingValue = false}) { - _debugCheckCvFields(); - - void modelFromField(Model model, CvField field) { - dynamic value = field.v; - if (value is List) { - value = value.map((e) => (e as CvModelRead).toModel()).toList(); - } else if (value is CvModelRead) { - value = value.toModel(includeMissingValue: includeMissingValue); - } - if (field is CvFieldWithParent) { - // Check sub model - if (field.hasValue || includeMissingValue) { - var subModel = model[field.parent] as Model?; - if (subModel is! Model) { - subModel = Model(); - model.setValue(field.parent, subModel); - } - // Try existing if any - modelFromField(subModel, field.field); - } - } else { - model.setValue(field.name, value, - presentIfNull: field.hasValue || includeMissingValue); - } - } - - var model = Model(); - - if (columns == null) { - for (var field in fields) { - modelFromField(model, field); - } - } else { - for (var column in columns) { - var field = this.field(column); - if (field != null) { - modelFromField(model, field); - } - } - } - return model; - } - - @override - void clear() { - for (var field in fields) { - field.clear(); - } - } -} - -final _debugCvFieldsCheckDone = {}; diff --git a/app_cv/lib/src/field.dart b/app_cv/lib/src/field.dart deleted file mode 100644 index bc28f15..0000000 --- a/app_cv/lib/src/field.dart +++ /dev/null @@ -1,313 +0,0 @@ -import 'dart:collection'; - -import 'package:tekartik_app_cv/app_cv.dart'; -import 'package:tekartik_app_cv/src/cv_field_with_parent.dart'; - -import 'column.dart'; - -/// CvField access -/// -/// Use [v] for value access. -abstract class CvFieldCore implements CvColumn { - /// The value (abbr.) - T? get v; - - /// The value - T? get value; - - /// The key (abbr.) - String get k; - - /// The key (abbr.) - String get key; - - /// Return true is null or unset - bool get isNull; - - /// Set the value, even if null - set v(T? value); - - /// Set the value, even if null. - set value(T? value); - - /// Clear value and flag - void clear(); - - // to be deprecated use clear instead - @Deprecated('use clear instead') - void removeValue(); - - /// [presentIfNull] true if null is marked as a value - void setValue(T? value, {bool presentIfNull = false}); - - bool get hasValue; - - /// Allow dynamic CvFields, copy if the value if set, otherwise delete it - void fromCvField(CvField cvField); - - /// Cast if needed - CvField cast(); - - /// Force the null value. - void setNull(); - - /// Make the field an inner field, the parent being a map - CvField withParent(String parent); -} - -/// Base for sub model or list of models -abstract class CvModelFieldCreator { - /// contentValue should be ignored or could be used to create the proper object - /// but its content should not be populated. - T create(Map contentValue); -} - -/// Nested CvField content -abstract class CvFieldContent - implements CvField, CvModelFieldCreator { - /// Only set value if not null - factory CvFieldContent( - String name, T Function(dynamic contentValue) create) => - CvFieldContentImpl(name, create); -} - -/// Nested list -abstract class CvFieldContentList - implements CvField>, CvModelFieldCreator { - List createList(); - - /// Only set value if not null - factory CvFieldContentList( - String name, T Function(dynamic contentValue) create) => - CvFieldContentListImpl(name, create); -} - -class _List extends ListBase { - final _list = []; - - @override - void add(T element) { - _list.add(element); - } - - @override - int get length => _list.length; - - @override - T operator [](int index) { - return _list[index]!; - } - - @override - void operator []=(int index, T value) { - _list[index] = value; - } - - @override - set length(int newLength) => _list.length = newLength; -} - -/// Nested list implementation. -class ListCvFieldImpl extends CvFieldImpl> - implements CvField>, CvListField { - @override - List createList() => _List(); - - ListCvFieldImpl(String name) : super(name); - - @override - Type get itemType => T; -} - -/// Content creator mixin -mixin CvFieldContentCreatorMixin - implements CvModelFieldCreator { - T Function(Map contentValue)? _create; - - @override - T create(Map contentValue) => - _create != null ? _create!(contentValue) : cvBuildModel(contentValue); -} - -/// Nested list of object implementation. -class CvFieldContentListImpl extends CvFieldImpl> - with CvFieldContentCreatorMixin - implements CvFieldContentList, CvModelListField { - @override - List createList() => _List(); - - CvFieldContentListImpl( - String name, T Function(Map contentValue)? createObjectFn) - : super(name) { - _create = createObjectFn; - } - - @override - Type get itemType => T; -} - -class CvFieldContentImpl extends CvFieldImpl - with CvFieldContentCreatorMixin - implements CvFieldContent, CvModelField { - CvFieldContentImpl(String name, T Function(Map contentValue)? createObjectFn) - : super(name) { - _create = createObjectFn; - } -} - -class CvFieldImpl - with // order is important, 2020/11/08 last one wins! - CvColumnMixin, - ColumnNameMixin, - CvFieldMixin { - /// Only set value if not null - CvFieldImpl(String name, [T? value]) { - this.name = name; - if (value != null) { - v = value; - } - } - - /// Force a null value - CvFieldImpl.withNull(String name) { - this.name = name; - _hasValue = true; - } - - /// Set value even if null - CvFieldImpl.withValue(String name, T value) { - this.name = name; - v = value; - } -} - -// ensure mixin compiles -// ignore: unused_element -class _TestCvField - with ColumnNameMixin, CvColumnMixin, CvFieldMixin - implements CvField {} - -mixin CvFieldMixin implements CvField { - T? _value; - - /// The value - @override - T? get v => _value; - - @override - String get key => name; - - @override - T? get value => _value; - - /// The key - @override - String get k => name; - - @override - bool get isNull => _value == null; - - @override - set v(T? value) { - _hasValue = true; - _value = value; - } - - @override - set value(T? value) => v = value; - - /// Clear value and flag - @override - void clear() { - _value = null; - _hasValue = false; - } - - // to be deprecated use clear instead - @override - @Deprecated('Use clear instead') - void removeValue() { - _value = null; - _hasValue = false; - } - - /// [presentIfNull] true if null is marked as a value - @override - void setValue(T? value, {bool presentIfNull = false}) { - if (value == null) { - if (presentIfNull) { - v = value; - } else { - clear(); - } - } else { - v = value; - } - } - - bool _hasValue = false; - - @override - bool get hasValue => _hasValue; - - /// Allow dynamic CvFields - @override - void fromCvField(CvField cvField) { - if (cvField.v is T?) { - setValue(cvField.v as T?, presentIfNull: cvField.hasValue); - } else if (isTypeString && cvField.hasValue) { - /// To string conversion - setValue(cvField.v?.toString() as T?, presentIfNull: true); - } - } - - @override - String toString() => '$name: $v${(v == null && hasValue) ? ' (set)' : ''}'; - - /// Cast if needed - @override - CvField cast() { - if (this is CvField) { - return this as CvField; - } - return CvField(name)..v = v as RT?; - } - - @override - int get hashCode => key.hashCode + (v?.hashCode ?? 0); - - @override - bool operator ==(other) { - if (other is CvField) { - if (other.name != name) { - return false; - } - if (other.hasValue != hasValue) { - return false; - } - if (!cvValuesAreEqual(other.v, v)) { - return false; - } - return true; - } - return false; - } - - /// Force the null value. - @override - void setNull() { - setValue(null, presentIfNull: true); - } - - @override - CvField withParent(String parent) => CvFieldWithParentImpl(this, parent); -} - -CvField intCvField(String name) => CvField(name); - -CvField stringCvField(String name) => CvField(name); - -/// List helpers -extension CvColumnExtension on List { - List get names => map((c) => c.name).toList(); -} diff --git a/app_cv/lib/src/utils.dart b/app_cv/lib/src/utils.dart deleted file mode 100644 index ecbcfc9..0000000 --- a/app_cv/lib/src/utils.dart +++ /dev/null @@ -1,34 +0,0 @@ -// ignore_for_file: inference_failure_on_function_invocation - -import 'package:tekartik_app_cv/src/cv_model.dart'; - -String logTruncate(String text) { - var len = 128; - if (text.length > len) { - text = text.substring(0, len); - } - return text; -} - -/// True for null, num, String, bool -bool isBasicTypeOrNull(dynamic value) { - if (value == null) { - return true; - } else if (value is num || value is String || value is bool) { - return true; - } - return false; -} - -/// If 2 content are equals -bool cvModelAreEquals(CvModelRead model1, CvModelRead model2) { - if (model1.fields.length != model2.fields.length) { - return false; - } - for (var cvField in model2.fields) { - if (model1.field(cvField.name) != cvField) { - return false; - } - } - return true; -} diff --git a/app_cv/pubspec.yaml b/app_cv/pubspec.yaml deleted file mode 100644 index d8503f3..0000000 --- a/app_cv/pubspec.yaml +++ /dev/null @@ -1,26 +0,0 @@ -name: tekartik_app_cv -description: App content values -publish_to: none -version: 0.5.3 - -environment: - sdk: '>=2.18.0 <4.0.0' - -dependencies: - tekartik_app_common_utils: - git: - url: https://github.com/tekartik/app_common_utils.dart - ref: dart2_3 - path: app - version: '>=0.1.0' - tekartik_common_utils: - git: - url: https://github.com/tekartik/common_utils.dart - ref: dart2_3 - version: '>=0.1.0' - cv: '>=0.2.10-1' - meta: - collection: -dev_dependencies: - test: ^1.14.4 - dev_test: \ No newline at end of file diff --git a/app_cv/test/app_cv_api_test.dart b/app_cv/test/app_cv_api_test.dart deleted file mode 100644 index ee74bd1..0000000 --- a/app_cv/test/app_cv_api_test.dart +++ /dev/null @@ -1,20 +0,0 @@ -import 'package:tekartik_app_cv/app_cv.dart'; -import 'package:test/test.dart'; -// ignore_for_file: unnecessary_statements - -void main() { - group('content_api_test', () { - test('exports', () { - [ - CvField, - CvModelBase, - CvModel, - CvMapModel, - CvModelListField, - CvModelField, - CvListField, - cvValuesAreEqual, - ]; - }); - }); -} diff --git a/app_cv/test/builder_test.dart b/app_cv/test/builder_test.dart deleted file mode 100644 index a3a2bc7..0000000 --- a/app_cv/test/builder_test.dart +++ /dev/null @@ -1,67 +0,0 @@ -import 'package:tekartik_app_cv/app_cv.dart'; -import 'package:test/test.dart'; - -class Simple extends CvModelBase { - final value = CvField('value'); - - @override - List get fields => [value]; -} - -class Parent extends CvModelBase { - final child = cvModelField('child'); - - @override - List get fields => [child]; -} - -class Child extends CvModelBase { - final value = CvField('value'); - - @override - List get fields => [value]; -} - -class ParentWithList extends CvModelBase { - final children = cvModelListField('children'); - - @override - List get fields => [children]; -} - -void initModelBuilders() { - cvAddBuilder((_) => Parent()); - cvAddBuilder((_) => Child()); - cvAddBuilder((_) => Simple()); - cvAddBuilder((_) => ParentWithList()); -} - -void main() { - initModelBuilders(); - group('builder', () { - test('simple', () { - var simple = {'value': 'test'}.cv(); - expect(simple.value.v, 'test'); - }); - test('cvModelField', () async { - var parent = Parent()..child.v = (Child()..value.v = 'test'); - expect(parent.toModel(), { - 'child': {'value': 'test'} - }); - expect(parent.toModel().cv(), parent); - }); - test('cvModelListField', () async { - var parent = ParentWithList()..children.v = [Child()..value.v = 'test']; - expect(parent.toModel(), { - 'children': [ - {'value': 'test'} - ] - }); - expect(parent.toModel().cv(), parent); - }); - test('cvBuildModel', () { - expect(cvBuildModel({}), Simple()); - expect(cvTypeBuildModel(Simple, {}), Simple()); - }); - }); -} diff --git a/app_cv/test/cv_column_test.dart b/app_cv/test/cv_column_test.dart deleted file mode 100644 index 6469282..0000000 --- a/app_cv/test/cv_column_test.dart +++ /dev/null @@ -1,13 +0,0 @@ -// ignore_for_file: inference_failure_on_instance_creation - -import 'package:tekartik_app_cv/src/column.dart'; -import 'package:test/test.dart'; - -void main() { - group('Column', () { - test('equals', () async { - expect(CvColumn('name'), CvColumn('name')); - expect(CvColumn('name'), isNot(CvColumn('name2'))); - }); - }); -} diff --git a/app_cv/test/cv_field_test.dart b/app_cv/test/cv_field_test.dart deleted file mode 100644 index 971d7e8..0000000 --- a/app_cv/test/cv_field_test.dart +++ /dev/null @@ -1,115 +0,0 @@ -// ignore_for_file: inference_failure_on_instance_creation - -import 'package:tekartik_app_cv/app_cv.dart'; -import 'package:test/test.dart'; - -import 'cv_model_test.dart'; - -void main() { - group('CvField', () { - test('cvValuesAreEquals', () { - expect(cvValuesAreEqual(null, false), isFalse); - expect(cvValuesAreEqual(null, null), isTrue); - expect(cvValuesAreEqual(1, 1), isTrue); - expect(cvValuesAreEqual(1, 2), isFalse); - expect(cvValuesAreEqual(1, 'text'), isFalse); - expect(cvValuesAreEqual([1], [1]), isTrue); - expect(cvValuesAreEqual([1], [2]), isFalse); - expect(cvValuesAreEqual({'a': 'b'}, {'a': 'b'}), isTrue); - }); - test('hashCode', () { - expect(CvField('name').hashCode, CvField('name').hashCode); - expect((CvField('name').v = 'test').hashCode, - (CvField('name').v = 'test').hashCode); - }); - test('equals', () { - expect(CvField('name'), CvField('name')); - expect(CvField('name'), CvField('name', null)); - expect(CvField('name'), isNot(CvField.withValue('name', null))); - expect(CvField('name'), isNot(CvField.withNull('name'))); - expect(CvField('name', 1), CvField('name', 1)); - expect(CvField('name', [1]), CvField('name', [1])); - expect(CvField('name', {'a': 'b'}), CvField('name', {'a': 'b'})); - expect(CvField('name', 1), isNot(CvField('name', 2))); - expect(CvField('name'), isNot(CvField('name2'))); - expect(CvField('name'), isNot(CvField('name', 1))); - }); - - test('fromCvField', () { - expect(CvField('name')..fromCvField(CvField('name', 'value')), - CvField('name', 'value')); - // bad type - expect(CvField('name')..fromCvField(CvField('name', 'value')), - CvField('name')); - }); - - test('fromCvFieldToString', () { - expect(CvField('name')..fromCvField(CvField('name', 12)), - CvField('name', '12')); - }); - - test('fillField', () { - expect((CvField('int')..fillField()).v, null); - expect((CvField('int')..fillField()).hasValue, true); - expect( - (CvField('int')..fillField(CvFillOptions(valueStart: 0))).v, 1); - expect( - (CvField('text')..fillField(CvFillOptions(valueStart: 0))).v, - 'text_1'); - expect((CvField('num')..fillField(CvFillOptions(valueStart: 0))).v, - 1.5); - expect( - (CvField('double')..fillField(CvFillOptions(valueStart: 0))).v, - 1.5); - }); - - test('withName', () { - var field = CvField('test', 1); - var newField = field.withName('newTest'); - expect(newField.name, 'newTest'); - expect(newField.value, 1); - }); - - test('fillList', () { - expect( - (CvListField('int') - ..fillList(CvFillOptions(collectionSize: 1, valueStart: 0))) - .v, - [1]); - }); - test('hasValue', () { - var field = CvField('name'); - expect(field.hasValue, isFalse); - expect(field.v, isNull); - field.setNull(); - expect(field.hasValue, isTrue); - expect(field.v, isNull); - field.clear(); - expect(field.hasValue, isFalse); - expect(field.v, isNull); - field.v = 1; - expect(field.v, 1); - field.value = 2; - expect(field.v, 2); - }); - test('CvModelField', () { - var modelField = CvModelField('test'); - cvAddBuilder((_) => IntContent()); - expect(modelField.create({}), const TypeMatcher()); - }); - test('withParent', () { - var field = CvField('name').withParent('parent'); - expect(field.name, 'parent.name'); - var field2 = CvField('name').withParent('parent'); - expect(field, field2); - }); - test('List', () { - var field1 = CvField('name'); - var field2 = CvField('count'); - [field1, field2] - .fromCvFields([CvField('other', 'test'), CvField('yet', 1)]); - expect(field1.v, 'test'); - expect(field2.v, 1); - }); - }); -} diff --git a/app_cv/test/cv_map_model_test.dart b/app_cv/test/cv_map_model_test.dart deleted file mode 100644 index 23f9265..0000000 --- a/app_cv/test/cv_map_model_test.dart +++ /dev/null @@ -1,87 +0,0 @@ -// ignore_for_file: inference_failure_on_collection_literal, inference_failure_on_instance_creation, inference_failure_on_function_invocation - -import 'package:tekartik_app_cv/app_cv.dart'; -import 'package:test/test.dart'; - -import 'cv_model_test.dart'; - -void main() { - group('CvMapModel', () { - test('fromMap', () { - var cv = CvMapModel(); - cv['test'] = 1; - expect(cv.toModel(), {'test': 1}); - cv = CvMapModel()..fromModel({'test': 1}); - expect(cv.toModel(), {'test': 1}); - cv.fromModel({'test': 2}); - expect(cv.toModel(), {'test': 2}); - }); - test('copyFrom', () { - var src = CvMapModel(); - src['test'] = 1; - expect(src.toModel(), {'test': 1}); - var cv = CvMapModel()..copyFrom(src); - expect(cv.toModel(), {'test': 1}); - cv = CvMapModel()..copyFrom(IntContent()); - expect(cv.toModel(), {}); - cv = CvMapModel()..copyFrom(IntContent()..value.v = null); - expect(cv.toModel(), {'value': null}); - cv = CvMapModel()..copyFrom(IntContent()..value.v = 1); - expect(cv.toModel(), {'value': 1}); - }); - test('toModel', () { - var cv = CvMapModel(); - cv['test'] = 1; - expect(cv.toModel(columns: ['test']), {'test': 1}); - expect(cv.toModel(columns: []), {}); - }); - test('child content toModel', () { - var cv = CvMapModel(); - cv['test'] = ChildContent()..sub.v = 'sub_v'; - expect(cv.toModel(columns: ['test']), { - 'test': {'sub': 'sub_v'} - }); - expect(cv.toModel(columns: []), {}); - }); - test('child content list toModel', () { - var cv = CvMapModel(); - cv['test'] = [ChildContent()..sub.v = 'sub_v']; - expect(cv.toModel(columns: ['test']), { - 'test': [ - {'sub': 'sub_v'} - ] - }); - expect(cv.toModel(columns: []), {}); - }); - test('withFields', () { - var cv = CvMapModel.withFields([CvField('test', 1)]); - expect(cv.toModel(), {'test': 1}); - cv['test2'] = 1; - cv['test'] = 2; - - //expect(cv.toModel(), {'test': 1, 'test2': 1}); - expect(cv.toModel(), {'test': 2}); - }); - test('map', () { - var cv = CvMapModel(); - expect(cv.fields, []); - cv['test'] = 1; - expect(cv.fields, [CvField('test', 1)]); - cv['test'] = null; - expect(cv.fields, [CvField.withNull('test')]); - expect(cv.toModel(), {'test': null}); - cv.field('test')!.v = 2; - expect(cv.fields, [CvField('test', 2)]); - expect(cv.toModel(), {'test': 2}); - cv.field('test')!.clear(); - expect(cv.fields, []); - expect(cv.toModel(), {}); - - cv = CvMapModel(); - cv['test'] = 1; - expect(cv.fields, [CvField('test', 1)]); - cv.clear(); - expect(cv.fields, []); - }); - }); -} diff --git a/app_cv/test/cv_model_list_test.dart b/app_cv/test/cv_model_list_test.dart deleted file mode 100644 index d1a2b02..0000000 --- a/app_cv/test/cv_model_list_test.dart +++ /dev/null @@ -1,70 +0,0 @@ -// ignore_for_file: inference_failure_on_collection_literal - -import 'package:tekartik_app_cv/app_cv.dart'; -import 'package:test/test.dart'; - -import 'cv_model_test.dart'; - -void main() { - group('cv', () { - test('CvModel', () { - var model = CvMapModel(); - model['test'] = 1; - }); - - test('toMapList', () async { - expect([IntContent()].toMapList(), [{}]); - - expect([(IntContent()..value.v = 1)].toMapList(), [ - {'value': 1} - ]); - expect([(IntContent()..value.v = 1)].toMapList(columns: ['value']), [ - {'value': 1} - ]); - expect([(IntContent()..value.v = 1)].toMapList(columns: ['other']), [{}]); - }); - test('toModelList', () async { - expect([IntContent()].toModelList(), [{}]); - - expect([(IntContent()..value.v = 1)].toModelList(), [ - {'value': 1} - ]); - - expect([{}].cv(builder: intContentBuilder), [IntContent()]); - - expect([{}].cv(builder: intContentBuilder), [IntContent()]); - }); - test('CvModelList.cv', () async { - expect([{}].cv(builder: intContentBuilder), [IntContent()]); - - expect( - [ - {'value': 1} - ].cv(builder: intContentBuilder), - [IntContent()..value.v = 1]); - }); - test('CvModelList no builder', () { - expect( - [ - {'value': 1} - ].cv(builder: noBuilderIntContentBuilder), - [IntContent()..value.v = 1]); - try { - [ - {'value': 1} - ].cv(); - } on UnsupportedError catch (_) {} - - try { - addNoBuilderIntContentBuilder(); - expect( - [ - {'value': 1} - ].cv(), - [IntContent()..value.v = 1]); - } finally { - removeNoBuilderIntContentBuilder(); - } - }); - }); -} diff --git a/app_cv/test/cv_model_test.dart b/app_cv/test/cv_model_test.dart deleted file mode 100644 index c4c6025..0000000 --- a/app_cv/test/cv_model_test.dart +++ /dev/null @@ -1,516 +0,0 @@ -// ignore_for_file: inference_failure_on_collection_literal - -import 'package:tekartik_app_cv/app_cv.dart'; -import 'package:tekartik_app_cv/src/builder.dart'; -import 'package:tekartik_common_utils/common_utils_import.dart'; -import 'package:test/test.dart'; - -CvFillOptions get testFillOptions => - CvFillOptions(valueStart: 0, collectionSize: 1); - -class Note extends CvModelBase { - final title = CvField('title'); - final content = CvField('content'); - final date = CvField('date'); - - @override - List get fields => [title, content, date]; -} - -class IntContent extends CvModelBase { - final value = CvField('value'); - - @override - List get fields => [value]; -} - -/// Builder -IntContent intContentBuilder(Map map) => IntContent(); - -/// This builder is never added, except locally -class NoBuilderIntContent extends CvModelBase { - final value = CvField('value'); - - @override - List get fields => [value]; -} - -void addNoBuilderIntContentBuilder() { - cvAddBuilder(noBuilderIntContentBuilder); -} - -void removeNoBuilderIntContentBuilder() { - cvRemoveBuilder(NoBuilderIntContent); -} - -/// Builder to add and remove -NoBuilderIntContent noBuilderIntContentBuilder(Map map) => - NoBuilderIntContent(); - -class Custom { - final String value; - - Custom(this.value); - - @override - String toString() => value; - - @override - int get hashCode => value.hashCode; - - @override - bool operator ==(Object other) { - return other is Custom && (other.value == value); - } -} - -class CustomContent extends CvModelBase { - final custom1 = CvField('custom1'); - final custom2 = CvField('custom2'); - final text = CvField('text'); - - @override - List get fields => [ - custom1, - custom2, - text, - ]; -} - -class StringContent extends CvModelBase { - final value = CvField('value'); - - @override - List get fields => [value]; -} - -void main() { - group('cv', () { - test('CvModel', () { - var model = CvMapModel(); - model['test'] = 1; - }); - test('equals', () { - expect(IntContent(), IntContent()); - expect(IntContent()..value.v = 1, IntContent()..value.v = 1); - expect(IntContent(), isNot(IntContent()..value.v = 1)); - expect(IntContent()..value.v = 2, isNot(IntContent()..value.v = 1)); - }); - test('toMap', () async { - expect(IntContent().toMap(), {}); - expect(IntContent().toMap(includeMissingValue: true), {'value': null}); - expect((IntContent()..value.v = 1).toMap(), {'value': 1}); - expect((IntContent()..value.v = 1).toMap(columns: []), {}); - expect((IntContent()..value.v = 1).toMap(columns: ['other']), {}); - expect((IntContent()..value.v = 1).toMap(columns: [IntContent().value.k]), - {'value': 1}); - }); - test('toModel', () async { - expect(IntContent().toModel(), {}); - expect((IntContent()..value.v = 1).toModel(), {'value': 1}); - expect((IntContent()..value.v = null).toModel(), {'value': null}); - expect((IntContent()..value.setNull()).toModel(), {'value': null}); - expect((IntContent()..value.setValue(null)).toModel(), {}); - expect( - (IntContent()..value.setValue(null, presentIfNull: true)).toModel(), - {'value': null}); - }); - test('fromModel1', () async { - var content = IntContent()..fromModel({}); - expect(content.value.hasValue, false); - expect(content.value.v, null); - content = IntContent()..fromModel({'value': null}); - expect(content.value.hasValue, true); - expect(content.value.v, null); - content = IntContent()..fromMap({'value': null}); - expect(content.value.hasValue, true); - expect(content.value.v, null); - - // Bad type - content = IntContent()..fromMap({'value': 'not an int'}); - expect(content.value.hasValue, false); - expect(content.value.v, null); - // Bad type, ok for string - var stringContent = StringContent()..fromMap({'value': 12}); - expect(stringContent.value.hasValue, true); - expect(stringContent.value.v, '12'); - }); - test('fromMap', () async { - expect(IntContent()..fromMap({}), IntContent()); - expect(IntContent()..fromMap({'value': 1}), IntContent()..value.v = 1); - expect( - IntContent() - ..fromMap({'value': 1}, columns: [IntContent().value.name]), - IntContent()..value.v = 1); - expect(IntContent()..fromMap({'value': 1}, columns: []), IntContent()); - expect(IntContent()..fromMap({'value': 1}, columns: ['other']), - IntContent()); - }); - test('copyFrom', () { - var cv = IntContent()..copyFrom(IntContent()); - expect(cv.toModel(), {}); - cv = IntContent()..copyFrom(IntContent()..value.v = null); - expect(cv.toModel(), {'value': null}); - cv = IntContent()..copyFrom(IntContent()..value.v = 1); - expect(cv.toModel(), {'value': 1}); - - var src = CvMapModel(); - src['value'] = 1; - expect(src.toModel(), {'value': 1}); - cv = IntContent()..copyFrom(src); - expect(cv.toModel(), {'value': 1}); - - src = CvMapModel(); - src['test'] = 1; - expect(src.toModel(), {'test': 1}); - cv = IntContent()..copyFrom(src); - expect(cv.toModel(), {}); - }); - test('alltoModel', () async { - var note = Note() - ..title.v = 'my_title' - ..content.v = 'my_content' - ..date.v = 1; - expect(note.toModel(), - {'title': 'my_title', 'content': 'my_content', 'date': 1}); - expect(note.toModel(columns: [note.title.name]), {'title': 'my_title'}); - }); - test('duplicated CvField', () { - try { - WithDuplicatedCvFields().toModel(); - fail('should fail'); - } on UnsupportedError catch (e) { - print(e); - } - try { - WithDuplicatedCvFields().fromModel({}); - fail('should fail'); - } on UnsupportedError catch (e) { - print(e); - } - try { - WithDuplicatedCvFields().copyFrom(CvMapModel()); - fail('should fail'); - } on UnsupportedError catch (e) { - print(e); - } - }); - test('content child', () { - expect(WithChildCvField().toModel(), {}); - expect(WithChildCvField().toModel(includeMissingValue: true), - {'child': null}); - expect( - (WithChildCvField()..child.v = ChildContent()) - .toModel(includeMissingValue: true), - { - 'child': {'sub': null} - }); - var parent = WithChildCvField() - ..child.v = (ChildContent()..sub.v = 'sub_value'); - var map = { - 'child': {'sub': 'sub_value'} - }; - expect(parent.toModel(), map); - parent = WithChildCvField()..fromModel(map); - expect(parent.toModel(), map); - }); - test('content child list', () { - expect(WithChildListCvField().toModel(), {}); - expect(WithChildListCvField().toModel(includeMissingValue: true), - {'children': null}); - - var parent = WithChildListCvField() - ..children.v = [ChildContent()..sub.v = 'sub_value']; - var map = { - 'children': [ - {'sub': 'sub_value'} - ] - }; - expect(parent.children.v!.first.sub.v, 'sub_value'); - expect(parent.toModel(), map); - parent = WithChildListCvField()..fromModel(map); - expect(parent.toModel(), map); - }); - test('all types', () { - AllTypes? allTypes; - void check() { - var export = allTypes!.toModel(); - var import = AllTypes()..fromModel(export); - expect(import, allTypes); - expect(import.toModel(), allTypes.toModel()); - import = AllTypes()..fromModel(jsonDecode(jsonEncode(export)) as Map); - - expect(import.toModel(), allTypes.toModel()); - } - - allTypes = AllTypes(); - check(); - allTypes - ..intCvField.v = 1 - ..numCvField.v = 2.5 - ..stringCvField.v = 'some_test' - ..intListCvField.v = [2, 3, 4] - ..mapCvField.v = {'sub': 'map'} - ..mapListCvField.v = [ - {'sub': 'map'} - ] - ..children.v = [ - WithChildCvField()..child.v = (ChildContent()..sub.v = 'sub_value') - ]; - check(); - }); - - test('fillModel', () { - expect( - (CvModelField('int', (_) => IntContent()) - ..fillModel(CvFillOptions(valueStart: 0))) - .v, - IntContent()..value.v = 1); - }); - - test('fillModelList', () { - expect( - (CvModelListField('int', (_) => IntContent()) - ..fillList(CvFillOptions(collectionSize: 1, valueStart: 0))) - .v, - [IntContent()..value.v = 1]); - }); - - test('fillModel', () { - expect((IntContent()..fillModel()).toModel(), {'value': null}); - expect((WithChildCvField()..fillModel()).toModel(), { - 'child': {'sub': null} - }); - expect( - (WithChildListCvField()..fillModel()).toModel(), {'children': null}); - expect((AllTypes()..fillModel()).toModel(), { - 'bool': null, - 'int': null, - 'num': null, - 'string': null, - 'children': null, - 'intList': null, - 'map': null, - 'mapList': null - }); - }); - test('fillModel', () { - expect((IntContent()..fillModel(CvFillOptions(valueStart: 0))).toModel(), - {'value': 1}); - expect( - (WithChildCvField()..fillModel(CvFillOptions(valueStart: 0))) - .toModel(), - { - 'child': {'sub': 'text_1'} - }); - expect( - (WithChildListCvField() - ..fillModel(CvFillOptions(valueStart: 0, collectionSize: 1))) - .toModel(), - { - 'children': [ - {'sub': 'text_1'} - ] - }); - expect( - (AllTypes() - ..fillModel(CvFillOptions(valueStart: 0, collectionSize: 1))) - .toModel(), - { - 'bool': false, - 'int': 2, - 'num': 3.5, - 'string': 'text_4', - 'children': [ - { - 'child': {'sub': 'text_5'} - } - ], - 'intList': [6], - 'map': null, - 'mapList': [ - {'field_0': 7} - ] - }); - expect( - (CustomContent() - ..fillModel(CvFillOptions( - valueStart: 0, - collectionSize: 1, - generate: (type, options) { - if (type == Custom) { - if (options.valueStart != null) { - var value = - options.valueStart = options.valueStart! + 1; - return Custom('custom_$value'); - } - } - return null; - }))) - .toModel(), - { - 'custom1': Custom('custom_1'), - 'custom2': Custom('custom_2'), - 'text': 'text_3' - }); - }); - test('custom', () { - expect((CustomContent()..custom1.v = Custom('test')).toModel(), - {'custom1': Custom('test')}); - }); - test('CvFieldWithParent', () { - var object = WithCvFieldWithParent(); - expect(object.fields.map((e) => e.name), ['sub.value', 'sub.value2']); - expect((WithCvFieldWithParent()..value.v = 1).toModel(), { - 'sub': {'value': 1} - }); - expect( - (WithCvFieldWithParent() - ..value.v = 1 - ..value2.v = 2) - .toModel(), - { - 'sub': {'value': 1, 'value2': 2} - }); - expect((WithCvFieldWithParent()..value.v = null).toModel(), { - 'sub': {'value': null} - }); - expect(WithCvFieldWithParent().toModel(), {}); - - var field = WithCvFieldWithParent() - ..fromModel({ - 'sub': {'value': 1} - }); - expect(field.value.v, 1); - expect(field.toModel(), { - 'sub': {'value': 1} - }); - - expect( - (WithCvFieldWithParent() - ..fillModel(CvFillOptions(valueStart: 0, collectionSize: 1))) - .toModel(), - { - 'sub': {'value': 1, 'value2': 2} - }); - - expect(WithCvFieldWithParent()..value.v = 1, - WithCvFieldWithParent()..value.v = 1); - expect((WithCvFieldWithParent()..value.v = 1).hashCode, - (WithCvFieldWithParent()..value.v = 1).hashCode); - }); - test('CvModelFieldWithParent', () { - var map = { - 'sub': { - 'value': {'value': 1} - } - }; - var model = WithCvModelFieldWithParent() - ..value.v = (IntContent()..value.v = 1); - expect(model.toModel(), map); - model = WithCvModelFieldWithParent()..fromModel(map); - expect(model.toModel(), map); - }); - test('auto children', () { - cvAddBuilder((_) => ChildContent()); - - expect((WithAutoChildren()..fillModel(testFillOptions)).toModel(), { - 'child': {'sub': 'text_1'}, - 'children': [ - {'sub': 'text_2'} - ] - }); - }); - test('updated fields', () { - var model = WithUpdateFields()..test1.v = 1; - expect(model.toModel(), {'test1': 1}); - model.test2 = CvField('test2', 2); - expect(model.toModel(), {'test1': 1, 'test2': 2}); - }); - }); -} - -class WithDuplicatedCvFields extends CvModelBase { - final cvField1 = CvField('CvField1'); - final cvField2 = CvField('CvField1'); - - @override - List get fields => [cvField1, cvField2]; -} - -class WithChildCvField extends CvModelBase { - final child = CvModelField('child', (_) => ChildContent()); - - @override - List get fields => [child]; -} - -class WithChildListCvField extends CvModelBase { - final children = - CvModelListField('children', (_) => ChildContent()); - - @override - List get fields => [children]; -} - -class WithCvFieldWithParent extends CvModelBase { - final value = CvField('value').withParent('sub'); - final value2 = CvField('value2').withParent('sub'); - - @override - List get fields => [value, value2]; -} - -class WithCvModelFieldWithParent extends CvModelBase { - final value = - CvModelField('value', (_) => IntContent()).withParent('sub'); - - @override - List get fields => [value]; -} - -class ChildContent extends CvModelBase { - final sub = CvField('sub'); - - @override - List get fields => [sub]; -} - -class AllTypes extends CvModelBase { - final boolCvField = CvField('bool'); - final intCvField = CvField('int'); - final numCvField = CvField('num'); - final stringCvField = CvField('string'); - final intListCvField = CvListField('intList'); - final mapCvField = CvField('map'); - final mapListCvField = CvListField('mapList'); - final children = - CvModelListField('children', (_) => WithChildCvField()); - - @override - List get fields => [ - boolCvField, - intCvField, - numCvField, - stringCvField, - children, - intListCvField, - mapCvField, - mapListCvField - ]; -} - -class WithAutoChildren extends CvModelBase { - final child = CvModelField('child'); - final children = CvModelListField('children'); - - @override - List get fields => [child, children]; -} - -class WithUpdateFields extends CvModelBase { - final test1 = CvField('test1'); - CvField? test2; - @override - List get fields => [test1, if (test2 != null) test2!]; -} diff --git a/app_cv/test/v2/app_cv_api_test.dart b/app_cv/test/v2/app_cv_api_test.dart deleted file mode 100644 index ee74bd1..0000000 --- a/app_cv/test/v2/app_cv_api_test.dart +++ /dev/null @@ -1,20 +0,0 @@ -import 'package:tekartik_app_cv/app_cv.dart'; -import 'package:test/test.dart'; -// ignore_for_file: unnecessary_statements - -void main() { - group('content_api_test', () { - test('exports', () { - [ - CvField, - CvModelBase, - CvModel, - CvMapModel, - CvModelListField, - CvModelField, - CvListField, - cvValuesAreEqual, - ]; - }); - }); -} diff --git a/app_cv/test/v2/builder_test.dart b/app_cv/test/v2/builder_test.dart deleted file mode 100644 index bf092fa..0000000 --- a/app_cv/test/v2/builder_test.dart +++ /dev/null @@ -1,67 +0,0 @@ -import 'package:tekartik_app_cv/app_cv_v2.dart'; -import 'package:test/test.dart'; - -class Simple extends CvModelBase { - final value = CvField('value'); - - @override - List get fields => [value]; -} - -class Parent extends CvModelBase { - final child = cvModelField('child'); - - @override - List get fields => [child]; -} - -class Child extends CvModelBase { - final value = CvField('value'); - - @override - List get fields => [value]; -} - -class ParentWithList extends CvModelBase { - final children = cvModelListField('children'); - - @override - List get fields => [children]; -} - -void initModelBuilders() { - cvAddBuilder((_) => Parent()); - cvAddBuilder((_) => Child()); - cvAddBuilder((_) => Simple()); - cvAddBuilder((_) => ParentWithList()); -} - -void main() { - initModelBuilders(); - group('builder', () { - test('simple', () { - var simple = {'value': 'test'}.cv(); - expect(simple.value.v, 'test'); - }); - test('cvModelField', () async { - var parent = Parent()..child.v = (Child()..value.v = 'test'); - expect(parent.toModel(), { - 'child': {'value': 'test'} - }); - expect(parent.toModel().cv(), parent); - }); - test('cvModelListField', () async { - var parent = ParentWithList()..children.v = [Child()..value.v = 'test']; - expect(parent.toModel(), { - 'children': [ - {'value': 'test'} - ] - }); - expect(parent.toModel().cv(), parent); - }); - test('cvBuildModel', () { - expect(cvBuildModel({}), Simple()); - expect(cvTypeBuildModel(Simple, {}), Simple()); - }); - }); -} diff --git a/app_cv/test/v2/cv_field_test.dart b/app_cv/test/v2/cv_field_test.dart deleted file mode 100644 index 3d224d8..0000000 --- a/app_cv/test/v2/cv_field_test.dart +++ /dev/null @@ -1,113 +0,0 @@ -import 'package:tekartik_app_cv/app_cv_v2.dart'; -import 'package:test/test.dart'; - -import 'cv_model_test.dart'; - -void main() { - group('CvField', () { - test('cvValuesAreEquals', () { - expect(cvValuesAreEqual(null, false), isFalse); - expect(cvValuesAreEqual(null, null), isTrue); - expect(cvValuesAreEqual(1, 1), isTrue); - expect(cvValuesAreEqual(1, 2), isFalse); - expect(cvValuesAreEqual(1, 'text'), isFalse); - expect(cvValuesAreEqual([1], [1]), isTrue); - expect(cvValuesAreEqual([1], [2]), isFalse); - expect(cvValuesAreEqual({'a': 'b'}, {'a': 'b'}), isTrue); - }); - test('hashCode', () { - expect(CvField('name').hashCode, CvField('name').hashCode); - expect((CvField('name').v = 'test').hashCode, - (CvField('name').v = 'test').hashCode); - }); - test('equals', () { - expect(CvField('name'), CvField('name')); - expect(CvField('name'), CvField('name', null)); - expect(CvField('name'), isNot(CvField.withValue('name', null))); - expect(CvField('name'), isNot(CvField.withNull('name'))); - expect(CvField('name', 1), CvField('name', 1)); - expect(CvField('name', [1]), CvField('name', [1])); - expect(CvField('name', {'a': 'b'}), CvField('name', {'a': 'b'})); - expect(CvField('name', 1), isNot(CvField('name', 2))); - expect(CvField('name'), isNot(CvField('name2'))); - expect(CvField('name'), isNot(CvField('name', 1))); - }); - - test('fromCvField', () { - expect(CvField('name')..fromCvField(CvField('name', 'value')), - CvField('name', 'value')); - // bad type - expect(CvField('name')..fromCvField(CvField('name', 'value')), - CvField('name')); - }); - - test('fromCvFieldToString', () { - expect(CvField('name')..fromCvField(CvField('name', 12)), - CvField('name', '12')); - }); - - test('fillField', () { - expect((CvField('int')..fillField()).v, null); - expect((CvField('int')..fillField()).hasValue, true); - expect( - (CvField('int')..fillField(CvFillOptions(valueStart: 0))).v, 1); - expect( - (CvField('text')..fillField(CvFillOptions(valueStart: 0))).v, - 'text_1'); - expect((CvField('num')..fillField(CvFillOptions(valueStart: 0))).v, - 1.5); - expect( - (CvField('double')..fillField(CvFillOptions(valueStart: 0))).v, - 1.5); - }); - - test('withName', () { - var field = CvField('test', 1); - var newField = field.withName('newTest'); - expect(newField.name, 'newTest'); - expect(newField.value, 1); - }); - - test('fillList', () { - expect( - (CvListField('int') - ..fillList(CvFillOptions(collectionSize: 1, valueStart: 0))) - .v, - [1]); - }); - test('hasValue', () { - var field = CvField('name'); - expect(field.hasValue, isFalse); - expect(field.v, isNull); - field.setNull(); - expect(field.hasValue, isTrue); - expect(field.v, isNull); - field.clear(); - expect(field.hasValue, isFalse); - expect(field.v, isNull); - field.v = 1; - expect(field.v, 1); - field.value = 2; - expect(field.v, 2); - }); - test('CvModelField', () { - var modelField = CvModelField('test'); - cvAddBuilder((_) => IntContent()); - expect(modelField.create({}), const TypeMatcher()); - }); - test('withParent', () { - var field = CvField('name').withParent('parent'); - expect(field.name, 'parent.name'); - var field2 = CvField('name').withParent('parent'); - expect(field, field2); - }); - test('List', () { - var field1 = CvField('name'); - var field2 = CvField('count'); - [field1, field2] - .fromCvFields([CvField('other', 'test'), CvField('yet', 1)]); - expect(field1.v, 'test'); - expect(field2.v, 1); - }); - }); -} diff --git a/app_cv/test/v2/cv_map_model_test.dart b/app_cv/test/v2/cv_map_model_test.dart deleted file mode 100644 index dc89fad..0000000 --- a/app_cv/test/v2/cv_map_model_test.dart +++ /dev/null @@ -1,86 +0,0 @@ -//import 'package:tekartik_app_cv/app_cv.dart'; -import 'package:tekartik_app_cv/app_cv_v2.dart'; -import 'package:test/test.dart'; - -import 'cv_model_test.dart'; - -void main() { - group('CvMapModel', () { - test('fromMap', () { - var cv = CvMapModel(); - cv['test'] = 1; - expect(cv.toModel(), {'test': 1}); - cv = CvMapModel()..fromModel({'test': 1}); - expect(cv.toModel(), {'test': 1}); - cv.fromModel({'test': 2}); - expect(cv.toModel(), {'test': 2}); - }); - test('copyFrom', () { - var src = CvMapModel(); - src['test'] = 1; - expect(src.toModel(), {'test': 1}); - var cv = CvMapModel()..copyFrom(src); - expect(cv.toModel(), {'test': 1}); - cv = CvMapModel()..copyFrom(IntContent()); - expect(cv.toModel(), isEmpty); - cv = CvMapModel()..copyFrom(IntContent()..value.v = null); - expect(cv.toModel(), {'value': null}); - cv = CvMapModel()..copyFrom(IntContent()..value.v = 1); - expect(cv.toModel(), {'value': 1}); - }); - test('toModel', () { - var cv = CvMapModel(); - cv['test'] = 1; - expect(cv.toModel(columns: ['test']), {'test': 1}); - expect(cv.toModel(columns: []), isEmpty); - }); - test('child content toModel', () { - var cv = CvMapModel(); - cv['test'] = ChildContent()..sub.v = 'sub_v'; - expect(cv.toModel(columns: ['test']), { - 'test': {'sub': 'sub_v'} - }); - expect(cv.toModel(columns: []), isEmpty); - }); - test('child content list toModel', () { - var cv = CvMapModel(); - cv['test'] = [ChildContent()..sub.v = 'sub_v']; - expect(cv.toModel(columns: ['test']), { - 'test': [ - {'sub': 'sub_v'} - ] - }); - expect(cv.toModel(columns: []), isEmpty); - }); - test('withFields', () { - var cv = CvMapModel.withFields([CvField('test', 1)]); - expect(cv.toModel(), {'test': 1}); - cv['test2'] = 1; - cv['test'] = 2; - - //expect(cv.toModel(), {'test': 1, 'test2': 1}); - expect(cv.toModel(), {'test': 2}); - }); - test('map', () { - var cv = CvMapModel(); - expect(cv.fields, isEmpty); - cv['test'] = 1; - expect(cv.fields, [CvField('test', 1)]); - cv['test'] = null; - expect(cv.fields, [CvField.withNull('test')]); - expect(cv.toModel(), {'test': null}); - cv.field('test')!.v = 2; - expect(cv.fields, [CvField('test', 2)]); - expect(cv.toModel(), {'test': 2}); - cv.field('test')!.clear(); - expect(cv.fields, isEmpty); - expect(cv.toModel(), isEmpty); - - cv = CvMapModel(); - cv['test'] = 1; - expect(cv.fields, [CvField('test', 1)]); - cv.clear(); - expect(cv.fields, isEmpty); - }); - }); -} diff --git a/app_cv/test/v2/cv_model_list_test.dart b/app_cv/test/v2/cv_model_list_test.dart deleted file mode 100644 index 0afdfdb..0000000 --- a/app_cv/test/v2/cv_model_list_test.dart +++ /dev/null @@ -1,71 +0,0 @@ -//import 'package:tekartik_app_cv/app_cv.dart'; -// ignore_for_file: inference_failure_on_collection_literal - -import 'package:tekartik_app_cv/app_cv_v2.dart'; -import 'package:test/test.dart'; - -import 'cv_model_test.dart'; - -void main() { - group('cv', () { - test('CvModel', () { - var model = CvMapModel(); - model['test'] = 1; - }); - - test('toMapList', () async { - expect([IntContent()].toMapList(), [{}]); - - expect([(IntContent()..value.v = 1)].toMapList(), [ - {'value': 1} - ]); - expect([(IntContent()..value.v = 1)].toMapList(columns: ['value']), [ - {'value': 1} - ]); - expect([(IntContent()..value.v = 1)].toMapList(columns: ['other']), [{}]); - }); - test('toModelList', () async { - expect([IntContent()].toModelList(), [{}]); - - expect([(IntContent()..value.v = 1)].toModelList(), [ - {'value': 1} - ]); - - expect([{}].cv(builder: intContentBuilder), [IntContent()]); - - expect([{}].cv(builder: intContentBuilder), [IntContent()]); - }); - test('CvModelList.cv', () async { - expect([{}].cv(builder: intContentBuilder), [IntContent()]); - - expect( - [ - {'value': 1} - ].cv(builder: intContentBuilder), - [IntContent()..value.v = 1]); - }); - test('CvModelList no builder', () { - expect( - [ - {'value': 1} - ].cv(builder: noBuilderIntContentBuilder), - [IntContent()..value.v = 1]); - try { - [ - {'value': 1} - ].cv(); - } on CvBuilderException catch (_) {} - - try { - addNoBuilderIntContentBuilder(); - expect( - [ - {'value': 1} - ].cv(), - [IntContent()..value.v = 1]); - } finally { - removeNoBuilderIntContentBuilder(); - } - }); - }); -} diff --git a/app_cv/test/v2/cv_model_test.dart b/app_cv/test/v2/cv_model_test.dart deleted file mode 100644 index 18391aa..0000000 --- a/app_cv/test/v2/cv_model_test.dart +++ /dev/null @@ -1,522 +0,0 @@ -// ignore_for_file: inference_failure_on_collection_literal - -/* -import 'package:tekartik_app_cv/app_cv.dart'; -import 'package:tekartik_app_cv/src/builder.dart'; - - */ -import 'package:cv/src/builder.dart'; -import 'package:tekartik_app_cv/app_cv_v2.dart'; -import 'package:tekartik_common_utils/common_utils_import.dart'; -import 'package:test/test.dart'; - -CvFillOptions get testFillOptions => - CvFillOptions(valueStart: 0, collectionSize: 1); - -class Note extends CvModelBase { - final title = CvField('title'); - final content = CvField('content'); - final date = CvField('date'); - - @override - List get fields => [title, content, date]; -} - -class IntContent extends CvModelBase { - final value = CvField('value'); - - @override - List get fields => [value]; -} - -/// Builder -IntContent intContentBuilder(Map map) => IntContent(); - -/// This builder is never added, except locally -class NoBuilderIntContent extends CvModelBase { - final value = CvField('value'); - - @override - List get fields => [value]; -} - -void addNoBuilderIntContentBuilder() { - cvAddBuilder(noBuilderIntContentBuilder); -} - -void removeNoBuilderIntContentBuilder() { - cvRemoveBuilder(NoBuilderIntContent); -} - -/// Builder to add and remove -NoBuilderIntContent noBuilderIntContentBuilder(Map map) => - NoBuilderIntContent(); - -class Custom { - final String value; - - Custom(this.value); - - @override - String toString() => value; - - @override - int get hashCode => value.hashCode; - - @override - bool operator ==(Object other) { - return other is Custom && (other.value == value); - } -} - -class CustomContent extends CvModelBase { - final custom1 = CvField('custom1'); - final custom2 = CvField('custom2'); - final text = CvField('text'); - - @override - List get fields => [ - custom1, - custom2, - text, - ]; -} - -class StringContent extends CvModelBase { - final value = CvField('value'); - - @override - List get fields => [value]; -} - -void main() { - group('cv', () { - test('CvModel', () { - var model = CvMapModel(); - model['test'] = 1; - }); - test('equals', () { - expect(IntContent(), IntContent()); - expect(IntContent()..value.v = 1, IntContent()..value.v = 1); - expect(IntContent(), isNot(IntContent()..value.v = 1)); - expect(IntContent()..value.v = 2, isNot(IntContent()..value.v = 1)); - }); - test('toMap', () async { - expect(IntContent().toMap(), {}); - expect(IntContent().toMap(includeMissingValue: true), {'value': null}); - expect((IntContent()..value.v = 1).toMap(), {'value': 1}); - expect((IntContent()..value.v = 1).toMap(columns: []), {}); - expect((IntContent()..value.v = 1).toMap(columns: ['other']), {}); - expect((IntContent()..value.v = 1).toMap(columns: [IntContent().value.k]), - {'value': 1}); - }); - test('toModel', () async { - expect(IntContent().toModel(), {}); - expect((IntContent()..value.v = 1).toModel(), {'value': 1}); - expect((IntContent()..value.v = null).toModel(), {'value': null}); - expect((IntContent()..value.setNull()).toModel(), {'value': null}); - expect((IntContent()..value.setValue(null)).toModel(), {}); - expect( - (IntContent()..value.setValue(null, presentIfNull: true)).toModel(), - {'value': null}); - }); - test('fromModel1', () async { - var content = IntContent()..fromModel({}); - expect(content.value.hasValue, false); - expect(content.value.v, null); - content = IntContent()..fromModel({'value': null}); - expect(content.value.hasValue, true); - expect(content.value.v, null); - content = IntContent()..fromMap({'value': null}); - expect(content.value.hasValue, true); - expect(content.value.v, null); - - // Bad type - content = IntContent()..fromMap({'value': 'not an int'}); - expect(content.value.hasValue, false); - expect(content.value.v, null); - // Bad type, ok for string - var stringContent = StringContent()..fromMap({'value': 12}); - expect(stringContent.value.hasValue, true); - expect(stringContent.value.v, '12'); - }); - test('fromMap', () async { - expect(IntContent()..fromMap({}), IntContent()); - expect(IntContent()..fromMap({'value': 1}), IntContent()..value.v = 1); - expect( - IntContent() - ..fromMap({'value': 1}, columns: [IntContent().value.name]), - IntContent()..value.v = 1); - expect(IntContent()..fromMap({'value': 1}, columns: []), IntContent()); - expect(IntContent()..fromMap({'value': 1}, columns: ['other']), - IntContent()); - }); - test('copyFrom', () { - var cv = IntContent()..copyFrom(IntContent()); - expect(cv.toModel(), {}); - cv = IntContent()..copyFrom(IntContent()..value.v = null); - expect(cv.toModel(), {'value': null}); - cv = IntContent()..copyFrom(IntContent()..value.v = 1); - expect(cv.toModel(), {'value': 1}); - - var src = CvMapModel(); - src['value'] = 1; - expect(src.toModel(), {'value': 1}); - cv = IntContent()..copyFrom(src); - expect(cv.toModel(), {'value': 1}); - - src = CvMapModel(); - src['test'] = 1; - expect(src.toModel(), {'test': 1}); - cv = IntContent()..copyFrom(src); - expect(cv.toModel(), {}); - }); - test('alltoModel', () async { - var note = Note() - ..title.v = 'my_title' - ..content.v = 'my_content' - ..date.v = 1; - expect(note.toModel(), - {'title': 'my_title', 'content': 'my_content', 'date': 1}); - expect(note.toModel(columns: [note.title.name]), {'title': 'my_title'}); - }); - test('duplicated CvField', () { - try { - WithDuplicatedCvFields().toModel(); - fail('should fail'); - } on CvBuilderException catch (e) { - print(e); - } - /* - try { - WithDuplicatedCvFields().fromModel({}); - fail('should fail'); - } on UnsupportedError catch (e) { - print(e); - } - try { - WithDuplicatedCvFields().copyFrom(CvMapModel()); - fail('should fail'); - } on UnsupportedError catch (e) { - print(e); - }*/ - }); - test('content child', () { - expect(WithChildCvField().toModel(), {}); - expect(WithChildCvField().toModel(includeMissingValue: true), - {'child': null}); - expect( - (WithChildCvField()..child.v = ChildContent()) - .toModel(includeMissingValue: true), - { - 'child': {'sub': null} - }); - var parent = WithChildCvField() - ..child.v = (ChildContent()..sub.v = 'sub_value'); - var map = { - 'child': {'sub': 'sub_value'} - }; - expect(parent.toModel(), map); - parent = WithChildCvField()..fromModel(map); - expect(parent.toModel(), map); - }); - test('content child list', () { - expect(WithChildListCvField().toModel(), {}); - expect(WithChildListCvField().toModel(includeMissingValue: true), - {'children': null}); - - var parent = WithChildListCvField() - ..children.v = [ChildContent()..sub.v = 'sub_value']; - var map = { - 'children': [ - {'sub': 'sub_value'} - ] - }; - expect(parent.children.v!.first.sub.v, 'sub_value'); - expect(parent.toModel(), map); - parent = WithChildListCvField()..fromModel(map); - expect(parent.toModel(), map); - }); - test('all types', () { - AllTypes? allTypes; - void doCheck() { - var export = allTypes!.toModel(); - var import = AllTypes()..fromModel(export); - expect(import, allTypes); - expect(import.toModel(), allTypes.toModel()); - import = AllTypes()..fromModel(jsonDecode(jsonEncode(export)) as Map); - - expect(import.toModel(), allTypes.toModel()); - } - - allTypes = AllTypes(); - doCheck(); - allTypes - ..intCvField.v = 1 - ..numCvField.v = 2.5 - ..stringCvField.v = 'some_test' - ..intListCvField.v = [2, 3, 4] - ..mapCvField.v = {'sub': 'map'} - ..mapListCvField.v = [ - {'sub': 'map'} - ] - ..children.v = [ - WithChildCvField()..child.v = (ChildContent()..sub.v = 'sub_value') - ]; - doCheck(); - }); - - test('fillModel', () { - expect( - (CvModelField('int', (_) => IntContent()) - ..fillModel(CvFillOptions(valueStart: 0))) - .v, - IntContent()..value.v = 1); - }); - - test('fillModelList', () { - expect( - (CvModelListField('int', (_) => IntContent()) - ..fillList(CvFillOptions(collectionSize: 1, valueStart: 0))) - .v, - [IntContent()..value.v = 1]); - }); - - test('fillModel', () { - expect((IntContent()..fillModel()).toModel(), {'value': null}); - expect((WithChildCvField()..fillModel()).toModel(), { - 'child': {'sub': null} - }); - expect( - (WithChildListCvField()..fillModel()).toModel(), {'children': null}); - expect((AllTypes()..fillModel()).toModel(), { - 'bool': null, - 'int': null, - 'num': null, - 'string': null, - 'children': null, - 'intList': null, - 'map': null, - 'mapList': null - }); - }); - test('fillModel', () { - expect((IntContent()..fillModel(CvFillOptions(valueStart: 0))).toModel(), - {'value': 1}); - expect( - (WithChildCvField()..fillModel(CvFillOptions(valueStart: 0))) - .toModel(), - { - 'child': {'sub': 'text_1'} - }); - expect( - (WithChildListCvField() - ..fillModel(CvFillOptions(valueStart: 0, collectionSize: 1))) - .toModel(), - { - 'children': [ - {'sub': 'text_1'} - ] - }); - expect( - (AllTypes() - ..fillModel(CvFillOptions(valueStart: 0, collectionSize: 1))) - .toModel(), - { - 'bool': false, - 'int': 2, - 'num': 3.5, - 'string': 'text_4', - 'children': [ - { - 'child': {'sub': 'text_5'} - } - ], - 'intList': [6], - 'map': {'field_1': 7}, - 'mapList': [ - {'field_1': 8} - ] - }); - expect( - (CustomContent() - ..fillModel(CvFillOptions( - valueStart: 0, - collectionSize: 1, - generate: (type, options) { - if (type == Custom) { - if (options.valueStart != null) { - var value = - options.valueStart = options.valueStart! + 1; - return Custom('custom_$value'); - } - } - return null; - }))) - .toModel(), - { - 'custom1': Custom('custom_1'), - 'custom2': Custom('custom_2'), - 'text': 'text_3' - }); - }); - test('custom', () { - expect((CustomContent()..custom1.v = Custom('test')).toModel(), - {'custom1': Custom('test')}); - }); - test('CvFieldWithParent', () { - var object = WithCvFieldWithParent(); - expect(object.fields.map((e) => e.name), ['sub.value', 'sub.value2']); - expect((WithCvFieldWithParent()..value.v = 1).toModel(), { - 'sub': {'value': 1} - }); - expect( - (WithCvFieldWithParent() - ..value.v = 1 - ..value2.v = 2) - .toModel(), - { - 'sub': {'value': 1, 'value2': 2} - }); - expect((WithCvFieldWithParent()..value.v = null).toModel(), { - 'sub': {'value': null} - }); - expect(WithCvFieldWithParent().toModel(), {}); - - var field = WithCvFieldWithParent() - ..fromModel({ - 'sub': {'value': 1} - }); - expect(field.value.v, 1); - expect(field.toModel(), { - 'sub': {'value': 1} - }); - - expect( - (WithCvFieldWithParent() - ..fillModel(CvFillOptions(valueStart: 0, collectionSize: 1))) - .toModel(), - { - 'sub': {'value': 1, 'value2': 2} - }); - - expect(WithCvFieldWithParent()..value.v = 1, - WithCvFieldWithParent()..value.v = 1); - expect((WithCvFieldWithParent()..value.v = 1).hashCode, - (WithCvFieldWithParent()..value.v = 1).hashCode); - }); - test('CvModelFieldWithParent', () { - var map = { - 'sub': { - 'value': {'value': 1} - } - }; - var model = WithCvModelFieldWithParent() - ..value.v = (IntContent()..value.v = 1); - expect(model.toModel(), map); - model = WithCvModelFieldWithParent()..fromModel(map); - expect(model.toModel(), map); - }); - test('auto children', () { - cvAddBuilder((_) => ChildContent()); - - expect((WithAutoChildren()..fillModel(testFillOptions)).toModel(), { - 'child': {'sub': 'text_1'}, - 'children': [ - {'sub': 'text_2'} - ] - }); - }); - test('updated fields', () { - var model = WithUpdateFields()..test1.v = 1; - expect(model.toModel(), {'test1': 1}); - model.test2 = CvField('test2', 2); - expect(model.toModel(), {'test1': 1, 'test2': 2}); - }); - }); -} - -class WithDuplicatedCvFields extends CvModelBase { - final cvField1 = CvField('CvField1'); - final cvField2 = CvField('CvField1'); - - @override - List get fields => [cvField1, cvField2]; -} - -class WithChildCvField extends CvModelBase { - final child = CvModelField('child', (_) => ChildContent()); - - @override - List get fields => [child]; -} - -class WithChildListCvField extends CvModelBase { - final children = - CvModelListField('children', (_) => ChildContent()); - - @override - List get fields => [children]; -} - -class WithCvFieldWithParent extends CvModelBase { - final value = CvField('value').withParent('sub'); - final value2 = CvField('value2').withParent('sub'); - - @override - List get fields => [value, value2]; -} - -class WithCvModelFieldWithParent extends CvModelBase { - final value = - CvModelField('value', (_) => IntContent()).withParent('sub'); - - @override - List get fields => [value]; -} - -class ChildContent extends CvModelBase { - final sub = CvField('sub'); - - @override - List get fields => [sub]; -} - -class AllTypes extends CvModelBase { - final boolCvField = CvField('bool'); - final intCvField = CvField('int'); - final numCvField = CvField('num'); - final stringCvField = CvField('string'); - final intListCvField = CvListField('intList'); - final mapCvField = CvField('map'); - final mapListCvField = CvListField('mapList'); - final children = - CvModelListField('children', (_) => WithChildCvField()); - - @override - List get fields => [ - boolCvField, - intCvField, - numCvField, - stringCvField, - children, - intListCvField, - mapCvField, - mapListCvField - ]; -} - -class WithAutoChildren extends CvModelBase { - final child = CvModelField('child'); - final children = CvModelListField('children'); - - @override - List get fields => [child, children]; -} - -class WithUpdateFields extends CvModelBase { - final test1 = CvField('test1'); - CvField? test2; - @override - List get fields => [test1, if (test2 != null) test2!]; -} diff --git a/app_cv/tool/run_ci.dart b/app_cv/tool/run_ci.dart deleted file mode 100644 index d9053ac..0000000 --- a/app_cv/tool/run_ci.dart +++ /dev/null @@ -1,5 +0,0 @@ -import 'package:dev_test/package.dart'; - -Future main() async { - await packageRunCi('.'); -} diff --git a/app_cv_firestore/README.md b/app_cv_firestore/README.md index c9ad701..d35318b 100644 --- a/app_cv_firestore/README.md +++ b/app_cv_firestore/README.md @@ -6,7 +6,7 @@ pubspect.yaml: tekartik_app_cv_firestore: git: url: https://github.com/tekartik/app_common_utils.dart - ref: dart2_3 + ref: dart3a path: app_cv_firestore version: '>=0.1.0' ``` \ No newline at end of file diff --git a/app_cv_firestore/lib/app_cv_firestore.dart b/app_cv_firestore/lib/app_cv_firestore.dart index 12de2df..52b54de 100644 --- a/app_cv_firestore/lib/app_cv_firestore.dart +++ b/app_cv_firestore/lib/app_cv_firestore.dart @@ -1,24 +1,4 @@ /// Firestore content values helper library tekartik_app_cv_firestore; -export 'src/builder.dart' - show - CvFirestoreDocument, - CvFirestoreDocumentBase, - cvFirestoreAddBuilder, - CvFirestoreMapDocument, - CvFirestoreDocumentExt; -export 'src/cv_collection_reference.dart' show CvCollectionReference; -export 'src/cv_document_reference.dart' show CvDocumentReference; -export 'src/cv_query_reference.dart' show CvQueryReference; -export 'src/firestore_extension.dart' - show - CvFirestoreDocumentSnapshotExt, - CvFirestoreDocumentSnapshotsExt, - CvFirestoreQuerySnapshotExt, - CvFirestoreExt, - CvFirestoreCollectionReferenceExt, - CvFirestoreDocumentReferenceExt, - CvFirestoreQueryExt, - CvFirestoreWriteBatch, - CvFirestoreTransaction; +export 'app_cv_firestore_v2.dart'; diff --git a/app_cv_firestore/lib/app_cv_firestore_v1.dart b/app_cv_firestore/lib/app_cv_firestore_v1.dart deleted file mode 100644 index b0fe20d..0000000 --- a/app_cv_firestore/lib/app_cv_firestore_v1.dart +++ /dev/null @@ -1,25 +0,0 @@ -/// Firestore content values helper -@Deprecated('use app_cv_firestore_v2') -library tekartik_app_cv_firestore_v1; - -export 'src/builder.dart' - show - CvFirestoreDocument, - CvFirestoreDocumentBase, - cvFirestoreAddBuilder, - CvFirestoreMapDocument, - CvFirestoreDocumentExt; -export 'src/cv_collection_reference.dart' show CvCollectionReference; -export 'src/cv_document_reference.dart' show CvDocumentReference; -export 'src/cv_query_reference.dart' show CvQueryReference; -export 'src/firestore_extension.dart' - show - CvFirestoreDocumentSnapshotExt, - CvFirestoreDocumentSnapshotsExt, - CvFirestoreQuerySnapshotExt, - CvFirestoreExt, - CvFirestoreCollectionReferenceExt, - CvFirestoreDocumentReferenceExt, - CvFirestoreQueryExt, - CvFirestoreWriteBatch, - CvFirestoreTransaction; diff --git a/app_cv_firestore/lib/src/builder.dart b/app_cv_firestore/lib/src/builder.dart deleted file mode 100644 index 4ae223b..0000000 --- a/app_cv_firestore/lib/src/builder.dart +++ /dev/null @@ -1,101 +0,0 @@ -import 'package:meta/meta.dart'; -import 'package:path/path.dart'; -import 'package:tekartik_app_cv/app_cv.dart'; -import 'package:tekartik_app_cv/src/content_values.dart'; // ignore: implementation_imports - -/// Add builder -void cvFirestoreAddBuilder( - T Function(Map contextData) builder) { - cvAddBuilder(builder); -} - -mixin _WithPath implements CvFirestoreDocument { - String? _path; - - /// Id - @override - String get id => url.basename(path); - - /// Set the path - @override - String get path => _path!; - - /// Get the path - @override - set path(String path) => _path = path; - - /// A document without id/path can only be added to a collection - @override - bool get hasId => _path != null; - - /// Can only be called on read documents - @override - late bool exists; - - @override - String toString() => '${hasId ? path : '(new)'} ${super.toString()}'; -} - -/// Only the content is compared on equals -abstract class CvFirestoreDocument implements CvModel { - /// Id - String get id; - - /// Path - String get path; - - set path(String path); - - bool get hasId; - - bool get exists; - - @visibleForTesting - set exists(bool exists); -} - -/// common helper -extension CvFirestoreDocumentExt on CvFirestoreDocument { - /// Id or null - String? get idOrNull => hasId ? id : null; - - /// Path or null - String? get pathOrNull => hasId ? path : null; -} - -/// Only the content is compared on equals -abstract class CvFirestoreDocumentBase extends CvModelBase with _WithPath {} - -/// Modifiable map. -abstract class CvFirestoreMapDocument implements CvFirestoreDocument { - /// Basic content values factory - factory CvFirestoreMapDocument() => _FsDocumentMap(); - - /// Predefined fields, values can be changed but none can added. - /// Usage discouraged unless you known the limitations. - factory CvFirestoreMapDocument.withFields(List list) { - return _FsDocumentWithCvFields(list); - } -} - -/// Only the content is compared on equals -class _FsDocumentMap extends ContentValuesMap - with _WithPath - implements CvFirestoreMapDocument {} - -/* -/// Easy extension -extension CvFsDocumentExt on CvFsDocument { - Future add(Firestore) -} - - - */ -class _FsDocumentWithCvFields extends CvBase - with _WithPath - implements CvFirestoreMapDocument { - @override - final List fields; - - _FsDocumentWithCvFields(this.fields); -} diff --git a/app_cv_firestore/lib/src/cv_collection_reference.dart b/app_cv_firestore/lib/src/cv_collection_reference.dart deleted file mode 100644 index 5edd128..0000000 --- a/app_cv_firestore/lib/src/cv_collection_reference.dart +++ /dev/null @@ -1,32 +0,0 @@ -import 'package:path/path.dart'; -import 'package:tekartik_app_cv_firestore/app_cv_firestore.dart'; -import 'package:tekartik_firebase_firestore/firestore.dart'; - -/// Collection helper -class CvCollectionReference { - final String path; - - CvCollectionReference(this.path); - - /// Get a list of document - Future> get(Firestore firestore) => - firestore.collection(path).cvGet(); - - /// Get a list of document - Stream> onSnapshots(Firestore firestore) => - firestore.collection(path).cvOnSnapshots(); - - /// Document reference - CvDocumentReference doc(String path) => - CvDocumentReference(url.join(this.path, path)); - - /// Create a query - CvQueryReference query() => CvQueryReference(this); - - /// Add a document, path in document is ignored - Future add(Firestore firestore, T document) => - firestore.collection(path).cvAdd(document); - - /// Raw document reference - CollectionReference raw(Firestore firestore) => firestore.collection(path); -} diff --git a/app_cv_firestore/lib/src/cv_document_reference.dart b/app_cv_firestore/lib/src/cv_document_reference.dart deleted file mode 100644 index 96e0965..0000000 --- a/app_cv_firestore/lib/src/cv_document_reference.dart +++ /dev/null @@ -1,35 +0,0 @@ -import 'package:path/path.dart'; -import 'package:tekartik_app_cv/app_cv.dart'; -import 'package:tekartik_app_cv_firestore/app_cv_firestore.dart'; -import 'package:tekartik_firebase_firestore/firestore.dart'; - -/// Document helper -class CvDocumentReference { - /// Document path - final String path; - - CvDocumentReference(this.path); - - /// Get a document - Future get(Firestore firestore) => firestore.doc(path).cvGet(); - - /// Document changed - Stream onSnapshot(Firestore firestore) => - firestore.doc(path).cvOnSnapshot(); - - T cv() => cvBuildModel({}) - ..path = path - // ignore: invalid_use_of_visible_for_testing_member - ..exists = false; - - /// Delete - Future delete(Firestore firestore) => firestore.doc(path).delete(); - - /// Sub collection reference (different type!) - CvCollectionReference collection( - String path) => - CvCollectionReference(url.join(this.path, path)); - - /// Raw document reference - DocumentReference raw(Firestore firestore) => firestore.doc(path); -} diff --git a/app_cv_firestore/lib/src/cv_query_reference.dart b/app_cv_firestore/lib/src/cv_query_reference.dart deleted file mode 100644 index 7c10ab9..0000000 --- a/app_cv_firestore/lib/src/cv_query_reference.dart +++ /dev/null @@ -1,133 +0,0 @@ -import 'package:tekartik_app_cv_firestore/app_cv_firestore.dart'; -import 'package:tekartik_common_utils/common_utils_import.dart'; -import 'package:tekartik_firebase_firestore/firestore.dart'; -import 'package:tekartik_firebase_firestore/src/common/query_mixin.dart'; // ignore: implementation_imports -import 'package:tekartik_firebase_firestore/src/firestore_common.dart'; // ignore: implementation_imports - -class QueryImpl with QueryMixin, FirestoreQueryExecutorMixin { - @override - QueryMixin clone() => QueryImpl()..queryInfo = queryInfo.clone(); - - @override - Future get() { - throw UnimplementedError(); - } - - @override - Stream onSnapshot({bool includeMetadataChanges = false}) { - throw UnimplementedError(); - } -} - -/// Query reference strong type helper -class CvQueryReference { - /// - final Query _impl; - final CvCollectionReference _collectionReference; - - QueryInfo get _queryInfo => (_impl as QueryImpl).queryInfo; - - /// New query reference - @internal - CvQueryReference(this._collectionReference) - : _impl = QueryImpl()..queryInfo = QueryInfo(); - - CvQueryReference._(this._collectionReference, Query impl) : _impl = impl; - - Future> get(Firestore firestore) async { - var query = - await applyQueryInfo(firestore, _collectionReference.path, _queryInfo); - return query.cvGet(); - } - - @Deprecated('User onSnapshots instead') - Stream> onSnapshot(Firestore firestore) => onSnapshot(firestore); - - /// query snapshots - Stream> onSnapshots(Firestore firestore) { - final lock = Lock(); - StreamSubscription? streamSubscription; - var done = false; - late StreamController> ctlr; - ctlr = StreamController>(onListen: () { - lock.synchronized(() async { - var query = await applyQueryInfo( - firestore, _collectionReference.path, _queryInfo); - streamSubscription = query.cvOnSnapshots().listen((event) { - if (!done) { - ctlr.add(event); - } - }); - }); - }, onCancel: () { - done = true; - lock.synchronized(() { - streamSubscription?.cancel(); - }); - }); - return ctlr.stream; - } - - CvQueryReference limit(int limit) => - CvQueryReference._(_collectionReference, _impl.limit(limit)); - - CvQueryReference orderBy(String key, {bool? descending}) => - CvQueryReference._( - _collectionReference, _impl.orderBy(key, descending: descending)); - - CvQueryReference select(List keyPaths) => - CvQueryReference._(_collectionReference, _impl.select(keyPaths)); - - // CvQueryReference offset(int offset); - - CvQueryReference startAt( - {DocumentSnapshot? snapshot, List? values}) => - CvQueryReference._(_collectionReference, - _impl.startAt(snapshot: snapshot, values: values)); - - CvQueryReference startAfter( - {DocumentSnapshot? snapshot, List? values}) => - CvQueryReference._(_collectionReference, - _impl.startAfter(snapshot: snapshot, values: values)); - - CvQueryReference endAt( - {DocumentSnapshot? snapshot, List? values}) => - CvQueryReference._(_collectionReference, - _impl.endAt(snapshot: snapshot, values: values)); - - CvQueryReference endBefore( - {DocumentSnapshot? snapshot, List? values}) => - CvQueryReference._(_collectionReference, - _impl.endBefore(snapshot: snapshot, values: values)); - - CvQueryReference where( - String fieldPath, { - dynamic isEqualTo, - dynamic isLessThan, - dynamic isLessThanOrEqualTo, - dynamic isGreaterThan, - dynamic isGreaterThanOrEqualTo, - dynamic arrayContains, - List? arrayContainsAny, - List? whereIn, - bool? isNull, - }) => - CvQueryReference._( - _collectionReference, - _impl.where( - fieldPath, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isNull: isNull, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, - isLessThan: isLessThan, - arrayContains: arrayContains, - arrayContainsAny: arrayContainsAny, - whereIn: whereIn, - isGreaterThan: isGreaterThan, - isEqualTo: isEqualTo, - )); - - /// Raw query reference, async since it might require a read first - Future rawASync(Firestore firestore) async => - await applyQueryInfo(firestore, _collectionReference.path, _queryInfo); -} diff --git a/app_cv_firestore/lib/src/firestore_extension.dart b/app_cv_firestore/lib/src/firestore_extension.dart deleted file mode 100644 index a365e29..0000000 --- a/app_cv_firestore/lib/src/firestore_extension.dart +++ /dev/null @@ -1,220 +0,0 @@ -import 'dart:async'; - -import 'package:tekartik_app_cv/app_cv.dart'; -import 'package:tekartik_app_cv_firestore/app_cv_firestore.dart'; -import 'package:tekartik_common_utils/list_utils.dart'; -import 'package:tekartik_firebase_firestore/firestore.dart'; - -void _ensurePathSet(CvFirestoreDocument document) { - if (!document.hasId) { - throw ArgumentError('path must be set on document $document'); - } -} - -/// Easy extension -extension CvFirestoreExt on Firestore { - /// Add a document - Future cvSet(T document, - [SetOptions? options]) async { - _ensurePathSet(document); - await doc(document.path).set(document.toModel(), options); - } - - /// Update a document - Future cvUpdate(T document) async { - _ensurePathSet(document); - await doc(document.path).update(document.toModel()); - } - - /// Add a document to collection, [document.path] is ignored. - Future cvAdd( - String path, T document) async { - return await collection(path).cvAdd(document); - } - - /// Add a document - Future cvGet(String path) async { - return (await doc(path).get()).cv(); - } - - /// Transaction - Future cvRunTransaction( - FutureOr Function(CvFirestoreTransaction transaction) action) { - return runTransaction((transaction) async { - return action(CvFirestoreTransaction(this, transaction)); - }); - } - - /// Batch - CvFirestoreWriteBatch cvBatch() { - return CvFirestoreWriteBatch(this, batch()); - } -} - -/// Transaction -class CvFirestoreTransaction extends Transaction { - final Firestore _firestore; - final Transaction _transaction; - - CvFirestoreTransaction(this._firestore, this._transaction); - - /// Delete - void cvDelete(String path) { - delete(_firestore.doc(path)); - } - - /// Returns non-null [Future] of the read data in a [DocumentSnapshot]. - Future cvGet(String path) async { - return (await get(_firestore.doc(path))).cv(); - } - - /// Returns non-null [Future] of the read data in a [DocumentSnapshot]. - Future refGet( - CvDocumentReference ref) async { - return await cvGet(ref.path); - } - - /// Returns non-null [Future] of the read data in a [DocumentSnapshot]. - void refDelete(CvDocumentReference ref) => - cvDelete(ref.path); - - /// Set - void cvSet(T document, [SetOptions? options]) { - _ensurePathSet(document); - set(_firestore.doc(document.path), document.toModel(), options); - } - - /// update - void cvUpdate(T document) { - _ensurePathSet(document); - update(_firestore.doc(document.path), document.toModel()); - } - - @override - void delete(DocumentReference documentRef) { - _transaction.delete(documentRef); - } - - @override - Future get(DocumentReference documentRef) { - return _transaction.get(documentRef); - } - - @override - void set(DocumentReference documentRef, Map data, - [SetOptions? options]) { - _transaction.set(documentRef, data, options); - } - - @override - void update(DocumentReference documentRef, Map data) { - _transaction.update(documentRef, data); - } -} - -/// Easy extension -extension CvFirestoreCollectionReferenceExt on CollectionReference { - /// [document.path] is ignored and update in the response - Future cvAdd(T document) async { - document.path = (await add(document.toModel())).path; - return document; - } -} - -/// Easy extension -extension CvFirestoreQueryExt on Query { - /// path is updated upon add - Future> cvGet() async { - var querySnapshot = await get(); - return querySnapshot.cv(); - } - - Stream> cvOnSnapshots() => onSnapshot() - .transform(StreamTransformer.fromHandlers(handleData: (data, sink) { - sink.add(data.docs.cv()); - })); -} - -/// Easy extension -extension CvFirestoreDocumentSnapshotExt on DocumentSnapshot { - /// Create a DbRecord from a snapshot - T cv() { - var path = ref.path; - - if (!exists) { - return cvBuildModel({}) - ..path = path - // ignore: invalid_use_of_visible_for_testing_member - ..exists = false; - } else { - var data = this.data; - return (cvBuildModel(data)..path = path) - ..fromModel(data) - // ignore: invalid_use_of_visible_for_testing_member - ..exists = exists; - } - } -} - -/// Easy extension -extension CvFirestoreDocumentReferenceExt on DocumentReference { - /// Get a document - Future cvGet() async { - return (await get()).cv(); - } - - /// on snapshots - Stream cvOnSnapshot() => onSnapshot() - .transform(StreamTransformer.fromHandlers(handleData: (data, sink) { - sink.add(data.cv()); - })); -} - -/// Easy extension -extension CvFirestoreDocumentSnapshotsExt on Iterable { - /// Create a list of DbRecords from a snapshot - List cv() => - lazy((snapshot) => snapshot.cv()); -} - -/// Easy extension -extension CvFirestoreQuerySnapshotExt on QuerySnapshot { - /// Create a list of DbRecords from a snapshot - List cv() => docs.cv(); -} - -/// Easy extension -class CvFirestoreWriteBatch extends WriteBatch { - final Firestore _firestore; - final WriteBatch _writeBatch; - - CvFirestoreWriteBatch(this._firestore, this._writeBatch); - - @override - Future commit() => _writeBatch.commit(); - - @override - void set(DocumentReference ref, Map data, - [SetOptions? options]) => - _writeBatch.set(ref, data, options); - - @override - void update(DocumentReference ref, Map data) => - _writeBatch.update(ref, data); - - @override - void delete(DocumentReference ref) => _writeBatch.delete(ref); - - /// set document - void cvSet(CvFirestoreDocument document, [SetOptions? options]) { - _ensurePathSet(document); - set(_firestore.doc(document.path), document.toModel(), options); - } - - void cvUpdate(CvFirestoreDocument document) { - _ensurePathSet(document); - update(_firestore.doc(document.path), document.toModel()); - } - - void cvDelete(String path) => delete(_firestore.doc(path)); -} diff --git a/app_cv_firestore/lib/src/v2/builder.dart b/app_cv_firestore/lib/src/v2/builder.dart index 930341f..555ad5f 100644 --- a/app_cv_firestore/lib/src/v2/builder.dart +++ b/app_cv_firestore/lib/src/v2/builder.dart @@ -1,7 +1,7 @@ +import 'package:cv/cv.dart'; import 'package:cv/src/content_values.dart'; // ignore: implementation_imports import 'package:meta/meta.dart'; import 'package:path/path.dart'; -import 'package:tekartik_app_cv/app_cv_v2.dart'; /// Add builder void cvFirestoreAddBuilder( diff --git a/app_cv_firestore/lib/src/v2/cv_collection_reference.dart b/app_cv_firestore/lib/src/v2/cv_collection_reference.dart index 3c267c6..b2888f5 100644 --- a/app_cv_firestore/lib/src/v2/cv_collection_reference.dart +++ b/app_cv_firestore/lib/src/v2/cv_collection_reference.dart @@ -32,4 +32,8 @@ class CvCollectionReference { /// Raw document reference CollectionReference raw(Firestore firestore) => firestore.collection(path); + + /// Cast to a different type + CvCollectionReference cast() => + CvCollectionReference(path); } diff --git a/app_cv_firestore/lib/src/v2/cv_document_reference.dart b/app_cv_firestore/lib/src/v2/cv_document_reference.dart index 87df215..2b116a1 100644 --- a/app_cv_firestore/lib/src/v2/cv_document_reference.dart +++ b/app_cv_firestore/lib/src/v2/cv_document_reference.dart @@ -1,5 +1,5 @@ +import 'package:cv/cv.dart'; import 'package:path/path.dart'; -import 'package:tekartik_app_cv/app_cv_v2.dart'; import 'package:tekartik_app_cv_firestore/app_cv_firestore_v2.dart'; import 'package:tekartik_firebase_firestore/firestore.dart'; @@ -13,7 +13,7 @@ class CvDocumentReference { /// Get a document Future get(Firestore firestore) => firestore.doc(path).cvGet(); - /// Set a document. document path is ignored here. + /// Set a document. Future setMap(Firestore firestore, Model map, [SetOptions? options]) => firestore.doc(path).set(map, options); @@ -21,6 +21,14 @@ class CvDocumentReference { Future set(Firestore firestore, T document, [SetOptions? options]) => setMap(firestore, document.toMap(), options); + /// Update a document. + Future updateMap(Firestore firestore, Model map) => + firestore.doc(path).update(map); + + /// Update a document. document path is ignored here. + Future update(Firestore firestore, T document) => + updateMap(firestore, document.toMap()); + /// Document changed Stream onSnapshot(Firestore firestore) => firestore.doc(path).cvOnSnapshot(); diff --git a/app_cv_firestore/lib/src/v2/firestore_extension.dart b/app_cv_firestore/lib/src/v2/firestore_extension.dart index 596d706..6e2ea12 100644 --- a/app_cv_firestore/lib/src/v2/firestore_extension.dart +++ b/app_cv_firestore/lib/src/v2/firestore_extension.dart @@ -1,6 +1,6 @@ import 'dart:async'; -import 'package:tekartik_app_cv/app_cv_v2.dart'; +import 'package:cv/cv.dart'; import 'package:tekartik_app_cv_firestore/app_cv_firestore_v2.dart'; import 'package:tekartik_common_utils/list_utils.dart'; import 'package:tekartik_firebase_firestore/firestore.dart'; @@ -17,7 +17,7 @@ extension CvFirestoreExt on Firestore { Future cvSet(T document, [SetOptions? options]) async { _ensurePathSet(document); - await doc(document.path).set(document.toModel(), options); + await doc(document.path).set(document.toMap(), options); } /// Update a document @@ -27,7 +27,7 @@ extension CvFirestoreExt on Firestore { /// Update a document Future docUpdate(T document) async { _ensurePathSet(document); - await doc(document.path).update(document.toModel()); + await doc(document.path).update(document.toMap()); } /// Update a document @@ -104,13 +104,13 @@ class CvFirestoreTransaction extends Transaction { /// Set void cvSet(T document, [SetOptions? options]) { _ensurePathSet(document); - set(_firestore.doc(document.path), document.toModel(), options); + set(_firestore.doc(document.path), document.toMap(), options); } /// update void cvUpdate(T document) { _ensurePathSet(document); - update(_firestore.doc(document.path), document.toModel()); + update(_firestore.doc(document.path), document.toMap()); } @override @@ -148,7 +148,7 @@ class CvFirestoreTransaction extends Transaction { extension CvFirestoreCollectionReferenceExt on CollectionReference { /// [document.path] is ignored and update in the response Future cvAdd(T document) async { - document.path = (await add(document.toModel())).path; + document.path = (await add(document.toMap())).path; return document; } } @@ -181,7 +181,7 @@ extension CvFirestoreDocumentSnapshotExt on DocumentSnapshot { } else { var data = this.data; return (cvBuildModel(data)..path = path) - ..fromModel(data) + ..fromMap(data) // ignore: invalid_use_of_visible_for_testing_member ..exists = exists; } @@ -240,12 +240,12 @@ class CvFirestoreWriteBatch extends WriteBatch { /// set document void cvSet(CvFirestoreDocument document, [SetOptions? options]) { _ensurePathSet(document); - set(_firestore.doc(document.path), document.toModel(), options); + set(_firestore.doc(document.path), document.toMap(), options); } void cvUpdate(CvFirestoreDocument document) { _ensurePathSet(document); - update(_firestore.doc(document.path), document.toModel()); + update(_firestore.doc(document.path), document.toMap()); } void cvDelete(String path) => delete(_firestore.doc(path)); diff --git a/app_cv_firestore/pubspec.yaml b/app_cv_firestore/pubspec.yaml index 71ecb2b..e213569 100644 --- a/app_cv_firestore/pubspec.yaml +++ b/app_cv_firestore/pubspec.yaml @@ -1,9 +1,9 @@ name: tekartik_app_cv_firestore description: Firestore content values helper -version: 0.10.1 +version: 0.10.3 publish_to: none environment: - sdk: '>=2.18.0 <4.0.0' + sdk: '>=3.0.0 <4.0.0' dependencies: meta: @@ -11,19 +11,13 @@ dependencies: tekartik_common_utils: git: url: https://github.com/tekartik/common_utils.dart - ref: dart2_3 + ref: dart3a version: '>=0.11.1' - tekartik_app_cv: - git: - url: https://github.com/tekartik/app_common_utils.dart - ref: dart2_3 - path: app_cv - version: '>=0.1.0' tekartik_firebase_firestore: git: url: https://github.com/tekartik/firebase_firestore.dart path: firestore - ref: dart2_3 + ref: dart3a version: '>=0.9.0' path: # Always add for easy test setup @@ -31,12 +25,9 @@ dependencies: git: url: https://github.com/tekartik/firebase_firestore.dart path: firestore_sembast - ref: dart2_3 + ref: dart3a version: '>=0.9.0' dev_dependencies: test: ^1.14.4 dev_test: -dependency_overrides: - tekartik_app_cv: - path: ../app_cv \ No newline at end of file diff --git a/app_cv_firestore/test/app_cv_firestore_v1_test.dart b/app_cv_firestore/test/app_cv_firestore_v1_test.dart deleted file mode 100644 index ddf5cdb..0000000 --- a/app_cv_firestore/test/app_cv_firestore_v1_test.dart +++ /dev/null @@ -1,306 +0,0 @@ -import 'package:path/path.dart'; -import 'package:tekartik_app_cv/app_cv.dart'; -// ignore: deprecated_member_use_from_same_package -import 'package:tekartik_app_cv_firestore/app_cv_firestore_v1.dart'; -import 'package:tekartik_firebase_firestore/firestore.dart'; -import 'package:tekartik_firebase_firestore_sembast/firestore_sembast.dart'; -import 'package:test/test.dart'; - -class CvFsEmpty extends CvFirestoreDocumentBase { - @override - List get fields => []; -} - -class CvFsSingleString extends CvFirestoreDocumentBase { - final text = CvField('text'); - - @override - List get fields => [text]; -} - -class CvFsAllFields extends CvFirestoreDocumentBase { - final intValue = CvField('intValue'); - - @override - List get fields => [intValue]; -} - -void initBuilders() { - cvFirestoreAddBuilder((_) => CvFsEmpty()); - cvFirestoreAddBuilder((_) => CvFsSingleString()); - cvFirestoreAddBuilder( - (_) => CvFirestoreMapDocument()); -} - -void main() { - group('builder', () { - late Firestore firestore; - setUpAll(() { - initBuilders(); - }); - setUp(() { - firestore = newFirestoreMemory(); - }); - test('get/set empty', () async { - try { - // ignore: unnecessary_statements - CvFsEmpty().exists; - fail('shoud fail'); - } catch (e) { - expect(e, isNot(const TypeMatcher())); - } - var snapshot = await firestore.doc('test/1').get(); - expect(snapshot.cv(), CvFsEmpty()..path = 'test/1'); - expect(snapshot.ref.path, 'test/1'); - expect(snapshot.cv().exists, false); - - var cvFsEmpty = await firestore.cvGet('test/1'); - expect(cvFsEmpty, CvFsEmpty()..path = 'test/1'); - expect(cvFsEmpty.path, 'test/1'); - expect(cvFsEmpty.exists, false); - expect(cvFsEmpty.toModel(), isEmpty); - - await firestore.cvSet(cvFsEmpty); - cvFsEmpty = await firestore.cvGet('test/1'); - expect(cvFsEmpty, CvFsEmpty()..path = 'test/1'); - expect(cvFsEmpty.path, 'test/1'); - expect(cvFsEmpty.exists, true); - expect(cvFsEmpty.toModel(), isEmpty); - - await firestore.cvSet(cvFsEmpty); - }); - - test('missing path', () async { - // No path set - var cvFsEmpty = CvFsEmpty(); - try { - await firestore.cvSet(cvFsEmpty); - fail('should fail'); - } on ArgumentError catch (_) {} - try { - await firestore.cvUpdate(cvFsEmpty); - fail('should fail'); - } on ArgumentError catch (_) {} - - await firestore.cvRunTransaction((transaction) { - try { - transaction.cvSet(cvFsEmpty); - fail('should fail'); - } on ArgumentError catch (_) {} - try { - transaction.cvUpdate(cvFsEmpty); - fail('should fail'); - } on ArgumentError catch (_) {} - }); - - var batch = firestore.cvBatch(); - try { - batch.cvSet(cvFsEmpty); - fail('should fail'); - } on ArgumentError catch (_) {} - try { - batch.cvUpdate(cvFsEmpty); - fail('should fail'); - } on ArgumentError catch (_) {} - }); - - test('model', () async { - var doc = CvFsSingleString(); - expect(doc.idOrNull, null); - expect(doc.pathOrNull, null); - try { - doc.id; - fail('should fail'); - } catch (e) { - expect(e, isNot(const TypeMatcher())); - } - try { - doc.path; - fail('should fail'); - } catch (e) { - expect(e, isNot(const TypeMatcher())); - } - - doc.path = 'test/id'; - expect(doc.pathOrNull, 'test/id'); - expect(doc.idOrNull, 'id'); - expect(doc.path, 'test/id'); - expect(doc.id, 'id'); - }); - - test('single string', () async { - void check(CvFsSingleString doc) { - expect(doc.exists, isTrue); - expect(doc.path, 'test/single_string'); - expect(doc.toModel(), {'text': 'value'}); - } - - var doc = CvFsSingleString() - ..path = 'test/single_string' - ..text.v = 'value'; - try { - // ignore: unnecessary_statements - doc.exists; - fail('shoud fail'); - } catch (e) { - expect(e, isNot(const TypeMatcher())); - } - expect(doc.path, 'test/single_string'); - expect(doc.toModel(), {'text': 'value'}); - await firestore.cvSet(doc); - var readDoc = await firestore.cvGet(doc.path); - check(readDoc); - - readDoc = await firestore.doc(doc.path).cvGet(); - check(readDoc); - - var snapshots = - await firestore.collection('test').cvGet(); - expect(snapshots, [doc]); - check(snapshots.first); - - snapshots = - await firestore.collection('test').limit(1).cvGet(); - expect(snapshots, [doc]); - check(snapshots.first); - - await firestore.cvRunTransaction((transaction) async { - readDoc = await transaction.cvGet(doc.path); - check(readDoc); - - transaction.cvDelete(doc.path); - }); - doc = CvFsSingleString() - ..path = 'test/single_string' - ..text.v = 'value2'; - - await firestore.cvRunTransaction((transaction) async { - readDoc = await transaction.cvGet(doc.path); - expect(readDoc.exists, isFalse); - - transaction.cvSet(doc); - }); - doc = CvFsSingleString() - ..path = 'test/single_string' - ..text.v = 'value3'; - await firestore.cvRunTransaction((transaction) async { - var doc = CvFsSingleString() - ..path = 'test/single_string' - ..text.v = 'value3'; - readDoc = await transaction.cvGet(doc.path); - expect(readDoc.exists, isTrue); - transaction.cvUpdate(doc); - }); - - readDoc = await firestore.cvGet(doc.path); - expect(readDoc, CvFsSingleString()..text.v = 'value3'); - }); - test('add update string', () async { - var doc = CvFsSingleString()..text.v = 'value'; - doc = await firestore.cvAdd('test', doc); - var readDoc = await firestore.cvGet(doc.path); - expect(readDoc, doc); - expect(readDoc.path, doc.path); - doc.text.v = 'value2'; - await firestore.cvUpdate(doc); - readDoc = await firestore.cvGet(doc.path); - expect(readDoc, doc); - expect(readDoc.path, doc.path); - }); - - test('batch', () async { - var doc = CvFsSingleString() - ..path = 'batch/single_string' - ..text.v = 'value'; - var batch = firestore.cvBatch(); - batch.cvSet(doc); - await batch.commit(); - - var readDoc = await firestore.cvGet(doc.path); - expect(readDoc, doc); - - batch = firestore.cvBatch(); - batch.cvUpdate(doc..text.v = 'new value'); - await batch.commit(); - - readDoc = await firestore.cvGet(doc.path); - expect(readDoc, doc); - - batch = firestore.cvBatch(); - batch.cvDelete(doc.path); - await batch.commit(); - - readDoc = await firestore.cvGet(doc.path); - expect(readDoc.exists, isFalse); - }); - - test('api', () { - // ignore: unnecessary_statements - CvFirestoreWriteBatch; - // ignore: unnecessary_statements - CvFirestoreTransaction; - }); - - test('onSnapshot', () async { - var doc = CvFsSingleString() - ..path = 'test/single_string' - ..text.v = 'value'; - - await firestore.cvSet(doc); - expect( - await firestore.doc(doc.path).cvOnSnapshot().first, - doc); - expect( - await firestore - .collection(url.dirname(doc.path)) - .cvOnSnapshots() - .first, - [doc]); - }); - - test('collection', () async { - var collection = CvCollectionReference('test'); - var docRef = collection.doc('1'); - expect(docRef.path, 'test/1'); - expect(await collection.get(firestore), isEmpty); - var doc = docRef.cv()..text.v = 'value'; - await firestore.cvSet(doc); - expect(await collection.get(firestore), [doc]); - //var doc = docRef.cv(); - expect(doc.id, '1'); - // Create a new record - doc = await collection.add(firestore, doc); - expect(doc.id, isNot('1')); - }); - - test('document', () async { - var docRef = CvDocumentReference('test/1'); - expect(docRef.path, 'test/1'); - var doc = docRef.cv(); - doc.text.v = 'value'; - await firestore.cvSet(doc); - expect(await docRef.get(firestore), doc); - - await firestore.cvRunTransaction((transaction) async { - expect(await transaction.refGet(docRef), doc); - }); - - expect(docRef.collection('sub').path, 'test/1/sub'); - }); - - test('query', () async { - var collection = CvCollectionReference('test'); - var query = collection.query().where('text', isEqualTo: 'value'); - var docRef = collection.doc('1'); - expect(docRef.path, 'test/1'); - expect((await query.onSnapshots(firestore).first), isEmpty); - expect(await collection.get(firestore), isEmpty); - var doc = docRef.cv()..text.v = 'value'; - await firestore.cvSet(doc); - expect((await query.onSnapshots(firestore).first), [doc]); - doc = docRef.cv()..text.v = 'value2'; - await firestore.cvSet(doc); - expect((await query.onSnapshots(firestore).first), isEmpty); - }); - }); -} diff --git a/app_cv_firestore/test/app_cv_firestore_v2_test.dart b/app_cv_firestore/test/app_cv_firestore_v2_test.dart index c741151..848315b 100644 --- a/app_cv_firestore/test/app_cv_firestore_v2_test.dart +++ b/app_cv_firestore/test/app_cv_firestore_v2_test.dart @@ -1,5 +1,5 @@ +import 'package:cv/cv.dart'; import 'package:path/path.dart'; -import 'package:tekartik_app_cv/app_cv_v2.dart'; import 'package:tekartik_app_cv_firestore/app_cv_firestore_v2.dart'; import 'package:tekartik_firebase_firestore/firestore.dart'; import 'package:tekartik_firebase_firestore_sembast/firestore_sembast.dart'; @@ -50,14 +50,14 @@ void main() { expect(cvFsEmpty, CvFsEmpty()..path = 'test/1'); expect(cvFsEmpty.path, 'test/1'); expect(cvFsEmpty.exists, false); - expect(cvFsEmpty.toModel(), isEmpty); + expect(cvFsEmpty.toMap(), isEmpty); await firestore.cvSet(cvFsEmpty); cvFsEmpty = await firestore.cvGet('test/1'); expect(cvFsEmpty, CvFsEmpty()..path = 'test/1'); expect(cvFsEmpty.path, 'test/1'); expect(cvFsEmpty.exists, true); - expect(cvFsEmpty.toModel(), isEmpty); + expect(cvFsEmpty.toMap(), isEmpty); await firestore.cvSet(cvFsEmpty); }); @@ -67,7 +67,7 @@ void main() { await firestore.cvSet(cvFsEmpty); cvFsEmpty = await firestore.cvGet('test/1'); expect(cvFsEmpty.exists, true); - expect(cvFsEmpty.toModel(), isEmpty); + expect(cvFsEmpty.toMap(), isEmpty); await firestore.docDelete(cvFsEmpty); cvFsEmpty = await firestore.cvGet('test/1'); @@ -136,7 +136,7 @@ void main() { void check(CvFsSingleString doc) { expect(doc.exists, isTrue); expect(doc.path, 'test/single_string'); - expect(doc.toModel(), {'text': 'value'}); + expect(doc.toMap(), {'text': 'value'}); } var doc = CvFsSingleString() @@ -150,7 +150,7 @@ void main() { expect(e, isNot(const TypeMatcher())); } expect(doc.path, 'test/single_string'); - expect(doc.toModel(), {'text': 'value'}); + expect(doc.toMap(), {'text': 'value'}); await firestore.cvSet(doc); var readDoc = await firestore.cvGet(doc.path); check(readDoc); @@ -277,6 +277,21 @@ void main() { doc = await collection.add(firestore, doc); expect(doc.id, isNot('1')); }); + test('collection.cast', () async { + var collectionOther = CvCollectionReference('test'); + var collection = collectionOther.cast(); + var docRef = collection.doc('1'); + expect(docRef.path, 'test/1'); + expect(await collection.get(firestore), isEmpty); + var doc = docRef.cv()..text.v = 'value'; + await firestore.cvSet(doc); + expect(await collection.get(firestore), [doc]); + //var doc = docRef.cv(); + expect(doc.id, '1'); + // Create a new record + doc = await collection.add(firestore, doc); + expect(doc.id, isNot('1')); + }); test('document', () async { var docRef = CvDocumentReference('test/1'); @@ -302,6 +317,23 @@ void main() { expect(await docRef.get(firestore), doc); }); + test('document.update', () async { + var docRef = CvDocumentReference('test/update'); + + var doc = docRef.cv(); + doc.text.v = 'value'; + try { + await docRef.update(firestore, doc); + fail('should fail'); + } catch (e) { + expect(e, isNot(isA())); + } + + doc.text.v = 'value2'; + await docRef.set(firestore, doc); + expect(await docRef.get(firestore), doc); + }); + test('query', () async { var collection = CvCollectionReference('test'); var query = collection.query().where('text', isEqualTo: 'value'); diff --git a/app_cv_sembast/README.md b/app_cv_sembast/README.md index 754eb04..044e060 100644 --- a/app_cv_sembast/README.md +++ b/app_cv_sembast/README.md @@ -6,7 +6,7 @@ pubspect.yaml: tekartik_app_cv_sembast: git: url: https://github.com/tekartik/app_common_utils.dart - ref: dart2_3 + ref: dart3a path: app_cv_sembast version: '>=0.5.0' ``` \ No newline at end of file diff --git a/app_cv_sembast/pubspec.yaml b/app_cv_sembast/pubspec.yaml index 3e84538..a93b801 100644 --- a/app_cv_sembast/pubspec.yaml +++ b/app_cv_sembast/pubspec.yaml @@ -3,7 +3,7 @@ description: Sembast content values helper version: 0.5.7 publish_to: none environment: - sdk: '>=2.18.0 <4.0.0' + sdk: '>=3.0.0 <4.0.0' dependencies: meta: @@ -11,10 +11,10 @@ dependencies: tekartik_common_utils: git: url: https://github.com/tekartik/common_utils.dart - ref: dart2_3 + ref: dart3a version: '>=0.11.1' sembast: '>=3.4.8-2' # sembast: dev_dependencies: test: ^1.14.4 - dev_test: \ No newline at end of file + dev_test: diff --git a/app_emit/README.md b/app_emit/README.md index 1529a5c..d1c3403 100644 --- a/app_emit/README.md +++ b/app_emit/README.md @@ -11,7 +11,7 @@ dependencies: tekartik_app_emit: git: url: https://github.com/tekartik/app_common_utils.dart - ref: dart2_3 + ref: dart3a path: app_emit version: '>=0.1.2' ``` diff --git a/app_emit/lib/src/future_or.dart b/app_emit/lib/src/future_or.dart index ef0b1b5..489c0df 100644 --- a/app_emit/lib/src/future_or.dart +++ b/app_emit/lib/src/future_or.dart @@ -1,7 +1,7 @@ import 'dart:async'; +import 'package:cv/cv.dart'; import 'package:tekartik_app_emit/src/exception.dart'; -import 'package:tekartik_common_utils/model/model.dart'; class EmitFutureOrSubscription { final EmitFutureOr _emitFutureOr; @@ -134,7 +134,7 @@ class EmitFutureOrController { } Model toDebugModel() { - var model = Model(); + var model = newModel(); model['completer'] = identityHashCode(_completer); model.setValue('error', _error); model.setValue('completed', isCompleted); diff --git a/app_emit/pubspec.yaml b/app_emit/pubspec.yaml index 1f294c7..072a291 100644 --- a/app_emit/pubspec.yaml +++ b/app_emit/pubspec.yaml @@ -6,13 +6,14 @@ homepage: https://www.example.com publish_to: none environment: - sdk: '>=2.18.0 <4.0.0' + sdk: '>=3.0.0 <4.0.0' dependencies: + cv: tekartik_common_utils: git: url: https://github.com/tekartik/common_utils.dart - ref: dart2_3 + ref: dart3a version: '>=0.10.7' meta: @@ -25,4 +26,4 @@ dev_dependencies: #dependency_overrides: # tekartik_common_utils: -# path: ../../common_utils.dart \ No newline at end of file +# path: ../../common_utils.dart diff --git a/app_emit/tool/travis.dart b/app_emit/tool/travis.dart deleted file mode 100644 index 820626d..0000000 --- a/app_emit/tool/travis.dart +++ /dev/null @@ -1,12 +0,0 @@ -import 'package:process_run/shell.dart'; - -Future main() async { - var shell = Shell(); - - await shell.run(''' -dartanalyzer --fatal-warnings --fatal-infos . -dartfmt -n --set-exit-if-changed . -dart pub run build_runner test -- -p vm,chrome -dart pub run test -p vm,chrome -'''); -} diff --git a/app_http/README.md b/app_http/README.md index c993106..43a9c9e 100644 --- a/app_http/README.md +++ b/app_http/README.md @@ -11,7 +11,7 @@ dependencies: tekartik_app_http: git: url: https://github.com/tekartik/app_common_utils.dart - ref: dart2_3 + ref: dart3a path: app_http version: '>=0.1.0' ``` diff --git a/app_http/pubspec.yaml b/app_http/pubspec.yaml index 8b9ed6b..be50417 100644 --- a/app_http/pubspec.yaml +++ b/app_http/pubspec.yaml @@ -4,35 +4,35 @@ version: 0.2.0 publish_to: none environment: - sdk: '>=2.18.0 <4.0.0' + sdk: '>=3.0.0 <4.0.0' dependencies: tekartik_http_browser: git: url: https://github.com/tekartik/http.dart path: http_browser - ref: dart2_3 + ref: dart3a version: '>=0.0.1' tekartik_common_utils: git: url: https://github.com/tekartik/common_utils.dart - ref: dart2_3 + ref: dart3a version: '>=0.0.1' tekartik_http: git: url: https://github.com/tekartik/http.dart path: http - ref: dart2_3 + ref: dart3a version: '>=0.0.1' tekartik_http_io: git: url: https://github.com/tekartik/http.dart path: http_io - ref: dart2_3 + ref: dart3a version: '>=0.0.1' dev_dependencies: http: dev_test: process_run: test: - build_web_compilers: '>=2.4.0' \ No newline at end of file + build_web_compilers: '>=2.4.0' diff --git a/app_intl/README.md b/app_intl/README.md index a1d0351..b51c859 100644 --- a/app_intl/README.md +++ b/app_intl/README.md @@ -10,7 +10,7 @@ In `pubspec.yaml` tekartik_app_intl: git: url: https://github.com/tekartik/app_common_utils.dart - ref: dart2_3 + ref: dart3a path: app_intl version: '>=0.1.0' ``` \ No newline at end of file diff --git a/app_intl/lib/intl_codes.dart b/app_intl/lib/intl_codes.dart new file mode 100644 index 0000000..cdf5fdb --- /dev/null +++ b/app_intl/lib/intl_codes.dart @@ -0,0 +1,11 @@ +export 'src/text_locale.dart' + show + TextLocale, + frFrLocaleName, + enUsLocaleName, + enUsTextLocale, + frFrTextLocale, + frenchLanguageCode, + englishLanguageCode, + franceCountryCode, + usaCountryCode; diff --git a/app_intl/lib/src/text_locale.dart b/app_intl/lib/src/text_locale.dart index 1833b96..52efc0d 100644 --- a/app_intl/lib/src/text_locale.dart +++ b/app_intl/lib/src/text_locale.dart @@ -1,11 +1,20 @@ -const enLanguageName = 'en'; -const frLanguageName = 'fr'; - -const usCountryCode = 'US'; -const frCountryCode = 'FR'; - -const enUsLocaleName = '${enLanguageName}_$usCountryCode'; -const frFrLocaleName = '${frLanguageName}_$frCountryCode'; +// To deprecate +const enLanguageName = englishLanguageCode; +// To deprecate +const frLanguageName = frenchLanguageCode; + +const englishLanguageCode = 'en'; +const frenchLanguageCode = 'fr'; + +// To deprecate +const usCountryCode = usaCountryCode; +// To deprecate +const frCountryCode = franceCountryCode; + +const usaCountryCode = 'US'; +const franceCountryCode = 'FR'; +const enUsLocaleName = '${englishLanguageCode}_$usaCountryCode'; +const frFrLocaleName = '${frenchLanguageCode}_$franceCountryCode'; class TextLocale { final String name; diff --git a/app_intl/pubspec.yaml b/app_intl/pubspec.yaml index 3271f71..0869cb8 100644 --- a/app_intl/pubspec.yaml +++ b/app_intl/pubspec.yaml @@ -1,21 +1,21 @@ name: tekartik_app_intl description: locatization common package -version: 0.2.2 +version: 0.2.3 publish_to: none environment: - sdk: '>=2.18.0 <4.0.0' + sdk: '>=3.0.0 <4.0.0' dependencies: args: tekartik_common_utils: git: url: https://github.com/tekartik/common_utils.dart - ref: dart2_3 + ref: dart3a version: '>=0.10.7' path: fs_shim: process_run: dev_dependencies: lints: - test: ^1.16.0 \ No newline at end of file + test: ^1.16.0 diff --git a/app_lints/README.md b/app_lints/README.md index 2cb5db1..0eae83a 100644 --- a/app_lints/README.md +++ b/app_lints/README.md @@ -11,7 +11,7 @@ dependencies: tekartik_app_lints: git: url: https://github.com/tekartik/app_common_utils.dart - ref: dart2_3 + ref: dart3a path: app_lints version: '>=0.1.0' ``` diff --git a/app_lints/pubspec.yaml b/app_lints/pubspec.yaml index 95b455b..a0801b8 100644 --- a/app_lints/pubspec.yaml +++ b/app_lints/pubspec.yaml @@ -4,7 +4,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=2.18.0 <4.0.0' + sdk: '>=3.0.0 <4.0.0' dependencies: cv: @@ -12,15 +12,15 @@ dependencies: tekartik_io_utils: git: url: https://github.com/tekartik/io_utils.dart - ref: dart2_3 + ref: dart3a version: '>=0.7.0' lints: tekartik_lints: git: url: https://github.com/tekartik/common.dart - ref: dart2_3 + ref: dart3a path: packages/lints version: '>=0.1.0' dev_dependencies: # yaml: - path: \ No newline at end of file + path: diff --git a/app_mirrors/README.md b/app_mirrors/README.md index 1faecc8..724713d 100644 --- a/app_mirrors/README.md +++ b/app_mirrors/README.md @@ -11,7 +11,7 @@ dependencies: tekartik_app_mirrors: git: url: https://github.com/tekartik/app_common_utils.dart - ref: dart2_3 + ref: dart3a path: app_mirrors version: '>=0.1.0' ``` diff --git a/app_mirrors/pubspec.yaml b/app_mirrors/pubspec.yaml index ec8a4dd..c0800ae 100644 --- a/app_mirrors/pubspec.yaml +++ b/app_mirrors/pubspec.yaml @@ -5,17 +5,17 @@ homepage: https://github.com/tekartik/app_common_utils.dart/app_mirrors publish_to: none environment: - sdk: '>=2.18.0 <4.0.0' + sdk: '>=3.0.0 <4.0.0' dependencies: tekartik_common_utils: git: url: https://github.com/tekartik/common_utils.dart - ref: dart2_3 + ref: dart3a version: '>=0.10.7' dev_dependencies: dev_test: test: ^1.0.0 json_annotation: - process_run: \ No newline at end of file + process_run: diff --git a/app_pager/README.md b/app_pager/README.md index fa8f2de..b4c76e5 100644 --- a/app_pager/README.md +++ b/app_pager/README.md @@ -11,7 +11,7 @@ dependencies: tekartik_app_pager: git: url: https://github.com/tekartik/app_common_utils.dart - ref: dart2_3 + ref: dart3a path: app_pager version: '>=0.1.0' ``` diff --git a/app_pager/lib/pager.dart b/app_pager/lib/pager.dart index 928e008..20d38c3 100644 --- a/app_pager/lib/pager.dart +++ b/app_pager/lib/pager.dart @@ -1,10 +1,10 @@ import 'dart:async'; +import 'package:cv/cv.dart'; import 'package:pool/pool.dart'; import 'package:quiver/collection.dart'; import 'package:tekartik_app_emit/emit.dart'; import 'package:tekartik_app_pager/src/data.dart'; -import 'package:tekartik_common_utils/model/model.dart'; /// Provider to implement. abstract class PagerDataProvider { @@ -101,7 +101,7 @@ class Pager { @override String toString() { - var model = Model(); + var model = newModel(); model['pageSize'] = _pageSize; return model.toString(); } diff --git a/app_pager/pubspec.yaml b/app_pager/pubspec.yaml index 032c6b9..e46695f 100644 --- a/app_pager/pubspec.yaml +++ b/app_pager/pubspec.yaml @@ -6,18 +6,19 @@ homepage: https://www.example.com publish_to: none environment: - sdk: '>=2.18.0 <4.0.0' + sdk: '>=3.0.0 <4.0.0' dependencies: + cv: tekartik_common_utils: git: url: https://github.com/tekartik/common_utils.dart - ref: dart2_3 + ref: dart3a version: '>=0.10.7' tekartik_app_emit: git: url: https://github.com/tekartik/app_common_utils.dart - ref: dart2_3 + ref: dart3a path: app_emit version: '>=0.1.3' pool: @@ -36,4 +37,4 @@ dependency_overrides: tekartik_app_emit: path: ../app_emit # tekartik_common_utils: -# path: ../../common_utils.dart \ No newline at end of file +# path: ../../common_utils.dart diff --git a/app_prefs/README.md b/app_prefs/README.md index df1919c..12c24c8 100644 --- a/app_prefs/README.md +++ b/app_prefs/README.md @@ -12,7 +12,7 @@ dependencies: tekartik_app_common_prefs: git: url: https://github.com/tekartik/app_common_utils.dart - ref: dart2_3 + ref: dart3a path: app_prefs version: '>=0.1.0' ``` diff --git a/app_prefs/pubspec.yaml b/app_prefs/pubspec.yaml index 8444021..c3f5164 100644 --- a/app_prefs/pubspec.yaml +++ b/app_prefs/pubspec.yaml @@ -4,33 +4,33 @@ version: 0.4.2 publish_to: none environment: - sdk: '>=2.18.0 <4.0.0' + sdk: '>=3.0.0 <4.0.0' dependencies: tekartik_prefs_sembast: git: url: https://github.com/tekartik/prefs.dart path: prefs_sembast - ref: dart2_3 + ref: dart3a version: '>=0.1.0' tekartik_prefs: git: url: https://github.com/tekartik/prefs.dart path: prefs - ref: dart2_3 + ref: dart3a version: '>=0.1.0' tekartik_prefs_browser: git: url: https://github.com/tekartik/prefs.dart path: prefs_browser - ref: dart2_3 + ref: dart3a version: '>=0.1.0' path: process_run: tekartik_app_sembast: git: url: https://github.com/tekartik/app_common_utils.dart - ref: dart2_3 + ref: dart3a path: app_sembast version: '>=0.1.0' dev_dependencies: @@ -39,7 +39,7 @@ dev_dependencies: tekartik_lints: git: url: https://github.com/tekartik/common.dart - ref: dart2_3 + ref: dart3a path: packages/lints version: '>=0.1.0' @@ -47,4 +47,4 @@ dependency_overrides: tekartik_app_sqflite: path: ../app_sqflite tekartik_app_sembast: - path: ../app_sembast \ No newline at end of file + path: ../app_sembast diff --git a/app_rx_bloc/README.md b/app_rx_bloc/README.md index d479769..7bc9cef 100644 --- a/app_rx_bloc/README.md +++ b/app_rx_bloc/README.md @@ -11,7 +11,7 @@ dependencies: tekartik_app_rx_bloc: git: url: https://github.com/tekartik/app_common_utils.dart - ref: dart2_3 + ref: dart3a path: app_rx_bloc version: '>=0.1.0' ``` diff --git a/app_rx_bloc/pubspec.yaml b/app_rx_bloc/pubspec.yaml index 398c0ee..64c562d 100644 --- a/app_rx_bloc/pubspec.yaml +++ b/app_rx_bloc/pubspec.yaml @@ -4,13 +4,13 @@ version: 0.2.0 publish_to: none environment: - sdk: '>=2.18.0 <4.0.0' + sdk: '>=3.0.0 <4.0.0' dependencies: tekartik_app_bloc: git: url: https://github.com/tekartik/app_common_utils.dart - ref: dart2_3 + ref: dart3a path: app_bloc version: '>=0.2.0' rxdart: @@ -25,4 +25,4 @@ dev_dependencies: dependency_overrides: tekartik_app_bloc: - path: ../app_bloc \ No newline at end of file + path: ../app_bloc diff --git a/app_sembast/README.md b/app_sembast/README.md index 7a31811..f976b47 100644 --- a/app_sembast/README.md +++ b/app_sembast/README.md @@ -20,7 +20,7 @@ dependencies: tekartik_app_sembast: git: url: https://github.com/tekartik/app_common_utils.dart - ref: dart2_3 + ref: dart3a path: app_sembast version: '>=0.1.0' ``` diff --git a/app_sembast/pubspec.yaml b/app_sembast/pubspec.yaml index eef1448..e377213 100644 --- a/app_sembast/pubspec.yaml +++ b/app_sembast/pubspec.yaml @@ -4,13 +4,13 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=2.18.0 <4.0.0' + sdk: '>=3.0.0 <4.0.0' dependencies: tekartik_app_sqflite: git: url: https://github.com/tekartik/app_common_utils.dart - ref: dart2_3 + ref: dart3a path: app_sqflite version: '>=0.2.0' synchronized: @@ -23,7 +23,7 @@ dependencies: tekartik_lints: git: url: https://github.com/tekartik/common.dart - ref: dart2_3 + ref: dart3a path: packages/lints version: '>=0.1.0' dev_dependencies: @@ -33,4 +33,4 @@ dev_dependencies: dependency_overrides: tekartik_app_sqflite: - path: ../app_sqflite \ No newline at end of file + path: ../app_sqflite diff --git a/app_sembast_secure/README.md b/app_sembast_secure/README.md index 15eeedb..1fea335 100644 --- a/app_sembast_secure/README.md +++ b/app_sembast_secure/README.md @@ -11,7 +11,7 @@ dependencies: tekartik_app_sembast_secure: git: url: https://github.com/tekartik/app_common_utils.dart - ref: dart2_3 + ref: dart3a path: app_sembast_secure version: '>=0.1.0' ``` \ No newline at end of file diff --git a/app_sembast_secure/pubspec.yaml b/app_sembast_secure/pubspec.yaml index 65c493f..3d51cd1 100644 --- a/app_sembast_secure/pubspec.yaml +++ b/app_sembast_secure/pubspec.yaml @@ -4,13 +4,13 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=2.18.0 <4.0.0' + sdk: '>=3.0.0 <4.0.0' dependencies: tekartik_app_sembast: git: url: https://github.com/tekartik/app_common_utils.dart - ref: dart2_3 + ref: dart3a path: app_sembast version: '>=0.1.0' sembast: @@ -21,4 +21,10 @@ dependencies: dev_dependencies: lints: - test: ^1.16.0 \ No newline at end of file + test: ^1.16.0 + +dependency_overrides: + tekartik_app_sembast: + path: ../app_sembast + tekartik_app_sqflite: + path: ../app_sqflite \ No newline at end of file diff --git a/app_serialize/README.md b/app_serialize/README.md index 2c787e5..90be740 100644 --- a/app_serialize/README.md +++ b/app_serialize/README.md @@ -11,7 +11,7 @@ dependencies: tekartik_app_serialize: git: url: https://github.com/tekartik/app_common_utils.dart - ref: dart2_3 + ref: dart3a path: app_serialize version: '>=0.1.0' ``` diff --git a/app_serialize/pubspec.yaml b/app_serialize/pubspec.yaml index bd7f99f..2a3b71c 100644 --- a/app_serialize/pubspec.yaml +++ b/app_serialize/pubspec.yaml @@ -5,13 +5,13 @@ homepage: https://github.com/tekartik/app_common_utils.dart/app_serialize publish_to: none environment: - sdk: '>=2.18.0 <4.0.0' + sdk: '>=3.0.0 <4.0.0' dependencies: tekartik_app_mirrors: git: url: https://github.com/tekartik/app_common_utils.dart - ref: dart2_3 + ref: dart3a path: app_mirrors version: '>=0.1.1' meta: @@ -27,4 +27,4 @@ dev_dependencies: dependency_overrides: tekartik_app_mirrors: - path: ../app_mirrors \ No newline at end of file + path: ../app_mirrors diff --git a/app_sqflite/README.md b/app_sqflite/README.md index 9152aae..71e7bc6 100644 --- a/app_sqflite/README.md +++ b/app_sqflite/README.md @@ -13,7 +13,7 @@ dependencies: tekartik_app_sqflite: git: url: https://github.com/tekartik/app_common_utils.dart - ref: dart2_3 + ref: dart3a path: app_sqflite version: '>=0.2.0' ``` diff --git a/app_sqflite/pubspec.yaml b/app_sqflite/pubspec.yaml index cb97a1a..7f94d62 100644 --- a/app_sqflite/pubspec.yaml +++ b/app_sqflite/pubspec.yaml @@ -4,7 +4,7 @@ version: 0.6.1 publish_to: none environment: - sdk: '>=2.18.0 <4.0.0' + sdk: '>=3.0.0 <4.0.0' dependencies: sqflite_common_ffi_web: '>=0.1.0' @@ -18,8 +18,8 @@ dev_dependencies: tekartik_lints: git: url: https://github.com/tekartik/common.dart - ref: dart2_3 + ref: dart3a path: packages/lints version: '>=0.1.0' -dependency_overrides: \ No newline at end of file +dependency_overrides: diff --git a/app_web_socket/README.md b/app_web_socket/README.md index 2357242..465db24 100644 --- a/app_web_socket/README.md +++ b/app_web_socket/README.md @@ -11,7 +11,7 @@ dependencies: tekartik_app_web_socket: git: url: https://github.com/tekartik/app_common_utils.dart - ref: dart2_3 + ref: dart3a path: app_web_socket version: '>=0.1.0' ``` diff --git a/app_web_socket/pubspec.yaml b/app_web_socket/pubspec.yaml index bfffb11..40f3764 100644 --- a/app_web_socket/pubspec.yaml +++ b/app_web_socket/pubspec.yaml @@ -4,29 +4,29 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=2.18.0 <4.0.0' + sdk: '>=3.0.0 <4.0.0' dependencies: tekartik_web_socket_io: git: url: https://github.com/tekartik/web_socket.dart path: web_socket_io - ref: dart2_3 + ref: dart3a version: '>=0.1.0' tekartik_web_socket: git: url: https://github.com/tekartik/web_socket.dart path: web_socket - ref: dart2_3 + ref: dart3a version: '>=0.1.0' tekartik_web_socket_browser: git: url: https://github.com/tekartik/web_socket.dart path: web_socket_browser - ref: dart2_3 + ref: dart3a version: '>=0.1.0' dev_dependencies: dev_test: process_run: - test: \ No newline at end of file + test: diff --git a/repo_support/pubspec.yaml b/repo_support/pubspec.yaml index 71ae1e6..6fa30b7 100644 --- a/repo_support/pubspec.yaml +++ b/repo_support/pubspec.yaml @@ -4,19 +4,10 @@ publish_to: none deploy_to: none environment: - sdk: '>=2.18.0 <4.0.0' + sdk: '>=3.0.0 <4.0.0' dependencies: path: - tekartik_build_utils: - git: - url: https://github.com/tekartik/build_utils.dart - ref: dart2_3 - version: '>=0.7.8' - chrome_travis: - git: - url: https://github.com/tekartik/chrome_travis.dart - ref: dart2_3 process_run: '>=0.10.0' dev_dependencies: @@ -24,5 +15,10 @@ dev_dependencies: dev_test: '>=0.13.4-dev.1' dependency_overrides: -# tekartik_build_utils: -# path: ../../../tekartik/build_utils.dart \ No newline at end of file + tekartik_lints: + git: + url: https://github.com/tekartik/common.dart + ref: dart3a + path: packages/lints + version: '>=0.1.0' + diff --git a/repo_support/tool/travis.dart b/repo_support/tool/travis.dart deleted file mode 100644 index 86b28c3..0000000 --- a/repo_support/tool/travis.dart +++ /dev/null @@ -1,37 +0,0 @@ -import 'package:dev_test/package.dart'; -import 'package:path/path.dart'; -import 'package:process_run/shell.dart'; - -Future main() async { - var shell = Shell(); - - for (var dir in [ - 'app_emit', - ]) { - shell = shell.pushd(join('..', dir)); - await shell.run(''' - - pub get - dart tool/travis.dart - -'''); - shell = shell.popd(); - } - - for (var dir in [ - 'app', - 'app_bloc', - 'app_cv', - 'app_cv_firestore', - 'app_rx_bloc', - 'app_crypto', - 'app_csv', - 'app_http', - 'app_web_socket', - 'app_serialize', - 'app_pager', - 'app_mirrors', - ]) { - await packageRunCi(join('..', dir)); - } -}