diff --git a/.github/workflows/check-branch.yml b/.github/workflows/check-branch.yml index 1e2d24a..e79864e 100644 --- a/.github/workflows/check-branch.yml +++ b/.github/workflows/check-branch.yml @@ -8,13 +8,13 @@ jobs: runs-on: ubuntu-latest steps: - name: Comment PR - if: github.base_ref == 'master' && github.head_ref != 'next' + if: github.base_ref == 'master' && github.head_ref != 'staging' uses: thollander/actions-comment-pull-request@v2 with: message: | We regret to inform you that you are currently not able to merge your changes into the master branch due to restrictions applied by our SRE team. To proceed with merging your changes, we kindly request that you create a pull request from the next branch. Our team will then review the changes and work with you to ensure a successful merge into the master branch. - name: Check branch - if: github.base_ref == 'master' && github.head_ref != 'next' + if: github.base_ref == 'master' && github.head_ref != 'staging' run: | echo "ERROR: We regret to inform you that you are currently not able to merge your changes into the master branch due to restrictions applied by our SRE team. To proceed with merging your changes, we kindly request that you create a pull request from the next branch. Our team will then review the changes and work with you to ensure a successful merge into the master branch." exit 1 \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 287de2d..437c375 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +### **FEB-17-2025** + +#### v1.0.0 - v3 migration null support added +#### Removed super_enum lib + ## v0.5.1 - Added support for gcp_na region #### Added support for gcp_na region diff --git a/LICENSE b/LICENSE index 283fb4a..51cd3bc 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ # MIT License -Copyright (c) 2012 - 2024 Contentstack. All rights reserved. +Copyright (c) 2012 - 2025 Contentstack. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 252c606..7d783ec 100644 --- a/README.md +++ b/README.md @@ -168,7 +168,7 @@ final response = imageTransformation..canvas(imageParams)..getUrl(); MIT License -Copyright (c) 2012 - 2021 +Copyright (c) 2012 - 2025 [Contentstack](https://www.contentstack.com/). All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..88da02e --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,27 @@ +# Security + +Contentstack takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations. + +If you believe you have found a security vulnerability in any Contentstack-owned repository, please report it to us as described below. + +## Reporting Security Issues + +**Please do not report security vulnerabilities through public GitHub issues.** + +Send email to [security@contentstack.com](mailto:security@contentstack.com). + +You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. + +Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: + +- Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) +- Full paths of source file(s) related to the manifestation of the issue +- The location of the affected source code (tag/branch/commit or direct URL) +- Any special configuration required to reproduce the issue +- Step-by-step instructions to reproduce the issue +- Proof-of-concept or exploit code (if possible) +- Impact of the issue, including how an attacker might exploit the issue + +This information will help us triage your report more quickly. + +[https://www.contentstack.com/trust/](https://www.contentstack.com/trust/) diff --git a/lib/client.dart b/lib/client.dart index 6dd72fb..fd4424c 100644 --- a/lib/client.dart +++ b/lib/client.dart @@ -7,11 +7,11 @@ import 'package:http/http.dart' as http; class HttpClient extends http.BaseClient { final http.Client _client; - final Stack stack; - final Map stackHeaders; + final Stack? stack; + final Map? stackHeaders; - factory HttpClient(Map headers, - {http.Client client, Stack stack}) { + factory HttpClient(Map? headers, + {http.Client? client, Stack? stack}) { final stackClient = client ?? http.Client(); return HttpClient._internal(stackClient, headers, stack); } @@ -26,13 +26,13 @@ class HttpClient extends http.BaseClient { return _client.send(request); } - Future sendRequest(Uri uri) async { - stackHeaders[CONTENT_TYPE] = CONTENT_TYPE_VALUE; - stackHeaders[X_USER_AGENT] = X_USER_AGENT_VALUE; + Future sendRequest(Uri uri) async { + stackHeaders![CONTENT_TYPE] = CONTENT_TYPE_VALUE; + stackHeaders![X_USER_AGENT] = X_USER_AGENT_VALUE; final response = await http - .get(uri, headers: stackHeaders) + .get(uri, headers: stackHeaders as Map) .timeout(const Duration(seconds: TIMEOUT)); - Object bodyJson; + Object? bodyJson; try { bodyJson = jsonDecode(response.body); } on FormatException { @@ -44,32 +44,32 @@ class HttpClient extends http.BaseClient { rethrow; } if (response.statusCode == 200) { - final Map bodyJson = json.decode(utf8.decode(response.bodyBytes)); - if (T == EntryModel && bodyJson.containsKey('entry')) { + final Map? bodyJson = json.decode(utf8.decode(response.bodyBytes)); + if (T == EntryModel && bodyJson!.containsKey('entry')) { return fromJson(bodyJson['entry']); - } else if (K == EntryModel && bodyJson.containsKey('entries')) { + } else if (K == EntryModel && bodyJson!.containsKey('entries')) { return fromJson(bodyJson['entries']); - } else if (T == AssetModel && bodyJson.containsKey('asset')) { + } else if (T == AssetModel && bodyJson!.containsKey('asset')) { return fromJson(bodyJson['asset']); - } else if (K == AssetModel && bodyJson.containsKey('assets')) { + } else if (K == AssetModel && bodyJson!.containsKey('assets')) { return fromJson(bodyJson['assets']); - } else if (T == SyncResult && bodyJson.containsKey('items')) { + } else if (T == SyncResult && bodyJson!.containsKey('items')) { return fromJson(bodyJson); } else { - if (bodyJson.containsKey('entries')) { - var previewResponse = stack.livePreview['entries']; + if (bodyJson!.containsKey('entries')) { + var previewResponse = stack!.livePreview?.entries; if (previewResponse != null) { - return fromJson(mergeLivePreview(bodyJson, previewResponse)); + return fromJson(mergeLivePreview(bodyJson, Map.fromEntries(previewResponse))); } } return fromJson(bodyJson); } } else { - return bodyJson; + return fromJson(bodyJson) as FutureOr; } } - mergeLivePreview(Map bodyJson, Map previewResponse) {} + mergeLivePreview(Map? bodyJson, Map previewResponse) {} /// Generic objects as well as List of generic objects /// (from a JSON list response). @@ -77,9 +77,9 @@ class HttpClient extends http.BaseClient { /// generic object and returns the result of the corresponding fromJson call /// code taken from: /// https://stackoverflow.com/questions/56271651/how-to-pass-a-generic-type-as-a-parameter-to-a-future-in-flutter - static T fromJson(dynamic json) { + static T? fromJson(dynamic json) { if (json is Iterable) { - return _fromJsonList(json) as T; + return _fromJsonList(json as List) as T; } else if (T == AssetModel) { return AssetModel.fromJson(json) as T; } else if (T == EntryModel) { @@ -91,14 +91,14 @@ class HttpClient extends http.BaseClient { } } - static List _fromJsonList(List jsonList) { + static List? _fromJsonList(List? jsonList) { if (jsonList == null) { return null; } - final output = []; + final output = []; // ignore: prefer_final_in_for_each - for (Map json in jsonList) { + for (Map json in jsonList as Iterable>) { output.add(fromJson(json)); } return output; diff --git a/lib/constant.dart b/lib/constant.dart index 84e4dc7..14f475e 100644 --- a/lib/constant.dart +++ b/lib/constant.dart @@ -9,13 +9,13 @@ const X_USER_AGENT_VALUE = '$SDK_NAME-v$SDK_VERSION'; const TIMEOUT = 30; void ifLivePreviewEnable(HttpClient _client) { - final dictLivePreview = _client.stack.livePreview; + final dictLivePreview = _client.stack!.livePreview; const String AUTH = 'authorization'; - if (dictLivePreview.containsKey('enable')) { - _client.stack.removeHeader('access_token'); - _client.stack.removeHeader('environment'); - _client.stack.setHeader(AUTH, _client.stack.livePreview[AUTH]); - _client.stack.setHost(dictLivePreview['host']); + if (dictLivePreview!.containsKey('enable')) { + _client.stack!.removeHeader('access_token'); + _client.stack!.removeHeader('environment'); + _client.stack!.setHeader(AUTH, _client.stack!.livePreview![AUTH]); + _client.stack!.setHost(dictLivePreview['host']); final String errMessage = '''Invalid content_type_uid! Make sure you have provided same content_type_uid livePreviewQuery parameter in stack class'''; diff --git a/lib/src/asset.dart b/lib/src/asset.dart index 1b128a4..333b454 100644 --- a/lib/src/asset.dart +++ b/lib/src/asset.dart @@ -8,11 +8,11 @@ import 'package:contentstack/client.dart'; /// Learn more about [Assets](https://www.contentstack.com/docs/developers/apis/content-delivery-api/#get-a-single-asset) /// class Asset { - final HttpClient _client; - final String _uid; - String _urlPath; + final HttpClient? _client; + final String? _uid; + String? _urlPath; - final Map assetParameter = {}; + final Map assetParameter = {}; /// * [_uid] assetUid: /// Enter the unique ID of the asset of which you wish to retrieve @@ -27,8 +27,8 @@ class Asset { /// }); /// Asset(this._uid, [this._client]) { - assetParameter['environment'] = _client.stackHeaders['environment']; - _urlPath = '/${_client.stack.apiVersion}/assets'; + assetParameter['environment'] = _client!.stackHeaders!['environment']; + _urlPath = '/${_client!.stack!.apiVersion}/assets'; } /// @@ -57,13 +57,13 @@ class Asset { /// }).catchError((error) { /// print(error['error_code']); /// }); - Future fetch() { - if (_uid == null || _uid.isEmpty) { + Future fetch() { + if (_uid == null || _uid!.isEmpty) { throw Exception('Provide asset uid to fetch single entry'); } final uri = - Uri.https(_client.stack.endpoint, '$_urlPath/$_uid', assetParameter); - return _client.sendRequest(uri); + Uri.https(_client!.stack!.endpoint!, '$_urlPath/$_uid', assetParameter); + return _client!.sendRequest(uri); } /// diff --git a/lib/src/asset_query.dart b/lib/src/asset_query.dart index 75a4044..cdc9afe 100644 --- a/lib/src/asset_query.dart +++ b/lib/src/asset_query.dart @@ -8,12 +8,12 @@ import 'package:contentstack/src/base_query.dart'; /// You can also specify the environment of which you wish to get the assets. /// Learn more about [Assets](https://www.contentstack.com/docs/developers/apis/content-delivery-api/#all-assets) class AssetQuery extends BaseQuery { - final HttpClient _client; - String _urlPath; + final HttpClient? _client; + late String _urlPath; AssetQuery([this._client]) { - queryParameter['environment'] = _client.stackHeaders['environment']; - _urlPath = '/${_client.stack.apiVersion}/assets'; + queryParameter['environment'] = _client!.stackHeaders!['environment']; + _urlPath = '/${_client!.stack!.apiVersion}/assets'; } /// @@ -42,9 +42,9 @@ class AssetQuery extends BaseQuery { /// }).catchError((error) { /// print(error['error_code']); /// }); - Future find() async { - final uri = Uri.https(_client.stack.endpoint, _urlPath, queryParameter); - return _client.sendRequest(uri); + Future find() async { + final uri = Uri.https(_client!.stack!.endpoint!, _urlPath, queryParameter); + return _client!.sendRequest(uri); } /// diff --git a/lib/src/base_query.dart b/lib/src/base_query.dart index 9520a8b..9f491b6 100644 --- a/lib/src/base_query.dart +++ b/lib/src/base_query.dart @@ -1,11 +1,12 @@ import 'package:contentstack/src/enums/operations.dart'; +import 'package:contentstack/src/enums/operations_type.dart'; /// /// This is base Query class that contains common /// functions to query in Entry, Assets and content_type /// common query for asset & entry class BaseQuery { - final Map queryParameter = {}; + final Map queryParameter = {}; final Map parameter = {}; /// @@ -156,27 +157,38 @@ class BaseQuery { void where(String fieldUid, QueryOperation queryOperation) { if (fieldUid != null && fieldUid.isNotEmpty) { - queryOperation.when(equals: (operation) { - parameter[fieldUid] = operation.value; - }, notEquals: (operation) { - parameter[fieldUid] = {'\$ne': operation.value}; - }, includes: (operation) { - parameter[fieldUid] = {'\$in': operation.value}; - }, excludes: (operation) { - parameter[fieldUid] = {'\$nin': operation.value}; - }, isLessThan: (operation) { - parameter[fieldUid] = {'\$lt': operation.value}; - }, isLessThanOrEqual: (operation) { - parameter[fieldUid] = {'\$lte': operation.value}; - }, isGreaterThan: (operation) { - parameter[fieldUid] = {'\$gt': operation.value}; - }, isGreaterThanOrEqual: (operation) { - parameter[fieldUid] = {'\$gte': operation.value}; - }, exists: (operation) { - parameter[fieldUid] = {'\$exists': operation.value}; - }, matches: (operation) { - parameter[fieldUid] = {'\$regex': operation.regex}; - }); + switch(queryOperation.operationType) { + case QueryOperationType.Equals: + parameter[fieldUid] = queryOperation.value; + break; + case QueryOperationType.NotEquals: + parameter[fieldUid] = {'\$ne': queryOperation.value}; + break; + case QueryOperationType.Includes: + parameter[fieldUid] = {'\$in': queryOperation.value}; + break; + case QueryOperationType.Excludes: + parameter[fieldUid] = {'\$nin': queryOperation.value}; + break; + case QueryOperationType.IsLessThan: + parameter[fieldUid] = {'\$lt': queryOperation.value}; + break; + case QueryOperationType.IsLessThanOrEqual: + parameter[fieldUid] = {'\$lte': queryOperation.value}; + break; + case QueryOperationType.IsGreaterThan: + parameter[fieldUid] = {'\$gt': queryOperation.value}; + break; + case QueryOperationType.IsGreaterThanOrEqual: + parameter[fieldUid] = {'\$gte': queryOperation.value}; + break; + case QueryOperationType.Exists: + parameter[fieldUid] = {'\$exists': queryOperation.value}; + break; + case QueryOperationType.Matches: + parameter[fieldUid] = {'\$regex': queryOperation.value}; + break; + } } } } diff --git a/lib/src/contenttype.dart b/lib/src/contenttype.dart index adeaa34..c185692 100644 --- a/lib/src/contenttype.dart +++ b/lib/src/contenttype.dart @@ -11,15 +11,15 @@ import 'package:contentstack/contentstack.dart'; /// * Read more about [ContentTypes](https://www.contentstack.com/docs/developers/apis/content-delivery-api/#content-types). /// class ContentType { - final String _contentTypeUid; - final HttpClient _client; - String urlPath; - final Map _queryParameter = {}; + final String? _contentTypeUid; + final HttpClient? _client; + String? urlPath; + final Map _queryParameter = {}; ContentType([this._contentTypeUid, this._client]) { - _queryParameter['environment'] = _client.stackHeaders['environment']; - if (_contentTypeUid != null && _contentTypeUid.isNotEmpty) { - urlPath = '/${_client.stack.apiVersion}/content_types/$_contentTypeUid'; + _queryParameter['environment'] = _client!.stackHeaders!['environment']; + if (_contentTypeUid != null && _contentTypeUid!.isNotEmpty) { + urlPath = '/${_client!.stack!.apiVersion}/content_types/$_contentTypeUid'; } } @@ -45,7 +45,7 @@ class ContentType { /// /// ``` /// - Entry entry({String entryUid}) { + Entry entry({String? entryUid}) { return Entry(entryUid, _client, _contentTypeUid); } @@ -65,15 +65,15 @@ class ContentType { /// print(response); /// ``` /// - Future fetch([Map queryParams]) { + Future fetch([Map? queryParams]) { if (urlPath == null) { throw Exception('content_type_uid is missing'); } if (queryParams != null && queryParams.isNotEmpty) { - _queryParameter.addAll(queryParams); + _queryParameter.addAll(queryParams as Map); } - final uri = Uri.https(_client.stack.endpoint, urlPath, _queryParameter); - return _client.sendRequest(uri); + final uri = Uri.https(_client!.stack!.endpoint!, urlPath!, _queryParameter); + return _client!.sendRequest(uri); } /// @@ -90,6 +90,6 @@ class ContentType { /// ``` /// ContentTypeQuery query() { - return ContentTypeQuery(_client); + return ContentTypeQuery(_client!); } } diff --git a/lib/src/contenttype_query.dart b/lib/src/contenttype_query.dart index 0885951..e612381 100644 --- a/lib/src/contenttype_query.dart +++ b/lib/src/contenttype_query.dart @@ -7,12 +7,12 @@ import 'package:contentstack/src/base_query.dart'; /// available in a particular stack in your account. /// [ContentType](https://www.contentstack.com/docs/developers/apis/content-delivery-api/#all-content-types). class ContentTypeQuery extends BaseQuery { - final HttpClient _client; - String _urlPath; + final HttpClient? _client; + late String _urlPath; ContentTypeQuery([this._client]) { - queryParameter['environment'] = _client.stackHeaders['environment']; - _urlPath = '/${_client.stack.apiVersion}/content_types'; + queryParameter['environment'] = _client!.stackHeaders!['environment']; + _urlPath = '/${_client!.stack!.apiVersion}/content_types'; } /// This call returns comprehensive information of all the content types @@ -27,12 +27,12 @@ class ContentTypeQuery extends BaseQuery { /// print(response); /// ``` /// - Future find({Map queryParams}) async { + Future find({Map? queryParams}) async { if (queryParams != null && queryParams.isNotEmpty) { queryParameter.addAll(queryParams); } - final uri = Uri.https(_client.stack.endpoint, _urlPath, queryParameter); - return _client.sendRequest(uri); + final uri = Uri.https(_client!.stack!.endpoint!, _urlPath, queryParameter); + return _client!.sendRequest(uri); } /// diff --git a/lib/src/entry.dart b/lib/src/entry.dart index 1248d32..9065316 100644 --- a/lib/src/entry.dart +++ b/lib/src/entry.dart @@ -8,20 +8,20 @@ import 'package:contentstack/src/entry_queryable.dart'; /// the defined `content types`. Learn more about Entries. /// Read more for details of [Entry](https://www.contentstack.com/docs/developers/apis/content-delivery-api/#entries) class Entry extends EntryQueryable { - final HttpClient _client; - final String _contentTypeUid; - String _path; - final String _uid; + final HttpClient? _client; + final String? _contentTypeUid; + String? _path; + final String? _uid; /// /// An `Entry` is the actual piece of content created using one of /// the defined `content types`. Learn more about Entries. /// Read more for details of [Entry](https://www.contentstack.com/docs/developers/apis/content-delivery-api/#entries) Entry([this._uid, this._client, this._contentTypeUid]) { - parameter['environment'] = _client.stackHeaders['environment']; - if (_contentTypeUid != null && _contentTypeUid.isNotEmpty) { + parameter['environment'] = _client!.stackHeaders!['environment']; + if (_contentTypeUid != null && _contentTypeUid!.isNotEmpty) { _path = - '/${_client.stack.apiVersion}/content_types/$_contentTypeUid/entries'; + '/${_client!.stack!.apiVersion}/content_types/$_contentTypeUid/entries'; } } @@ -47,23 +47,23 @@ class Entry extends EntryQueryable { /// }); /// ``` /// - Future fetch() async { + Future fetch() async { if (_uid == null) { throw Exception('Provide entry uid to fetch single entry'); } - final preview = _client.stack.livePreview; + final preview = _client!.stack!.livePreview; if (preview != null && preview.isNotEmpty) { validateLivePreview(preview, _client, _contentTypeUid); } - final uri = Uri.https(_client.stack.endpoint, '$_path/$_uid'); + final uri = Uri.https(_client!.stack!.endpoint!, '$_path/$_uid'); final request = Uri.parse(uri.toString()).resolveUri(Uri(queryParameters: parameter)); - return _client.sendRequest(request); + return _client!.sendRequest(request); } /// Applies query on entries Query query() { - return Query(_client, _contentTypeUid); + return Query(_client!, _contentTypeUid!); } } diff --git a/lib/src/entry_queryable.dart b/lib/src/entry_queryable.dart index 7c69d54..99e4f38 100644 --- a/lib/src/entry_queryable.dart +++ b/lib/src/entry_queryable.dart @@ -1,9 +1,10 @@ import 'package:contentstack/constant.dart'; import 'package:contentstack/src/enums/include.dart'; +import 'package:contentstack/src/enums/include_type.dart'; /// Applies Queries on [Entry](https://www.contentstack.com/docs/developers/apis/content-delivery-api/#entries) class EntryQueryable { - Map parameter = {}; + Map parameter = {}; /// /// This method adds key and value to an Entry. @@ -160,49 +161,53 @@ class EntryQueryable { /// prints(response) /// ``` /// - void includeReference(referenceFieldUid, {Include includeReferenceField}) { + void includeReference(referenceFieldUid, {IncludeClass? includeReferenceField}) { if (referenceFieldUid != null && referenceFieldUid.isNotEmpty) { final List referenceArray = []; if (includeReferenceField != null) { - includeReferenceField.when(none: (fieldUid) { - if (referenceFieldUid.runtimeType == List) { - for (var uid in referenceFieldUid) { - referenceArray.add(uid); + switch(includeReferenceField.includeType) { + case IncludeType.None: + if (referenceFieldUid.runtimeType == List) { + for (var uid in referenceFieldUid) { + referenceArray.add(uid); + } + } else if (referenceFieldUid.runtimeType == String) { + referenceArray.add(referenceFieldUid); } - } else if (referenceFieldUid.runtimeType == String) { - referenceArray.add(referenceFieldUid); - } - if (fieldUid.fieldUidList != null && - fieldUid.fieldUidList.isNotEmpty) { - for (final item in fieldUid.fieldUidList) { - referenceArray.add(item); + if (includeReferenceField.fieldUidList != null && + includeReferenceField.fieldUidList.isNotEmpty) { + for (final item in includeReferenceField.fieldUidList) { + referenceArray.add(item); + } } - } - parameter['include[]'] = referenceArray.toString(); - }, only: (fieldUid) { - final Map referenceOnlyParam = {}; - if (fieldUid.fieldUidList != null && - fieldUid.fieldUidList.isNotEmpty) { - for (final item in fieldUid.fieldUidList) { - referenceArray.add(item); + parameter['include[]'] = referenceArray.toString(); + break; + case IncludeType.Only: + final Map referenceOnlyParam = {}; + if (includeReferenceField.fieldUidList != null && + includeReferenceField.fieldUidList.isNotEmpty) { + for (final item in includeReferenceField.fieldUidList) { + referenceArray.add(item); + } } - } - referenceOnlyParam[referenceFieldUid] = referenceArray; - includeReference(referenceFieldUid); - parameter['only'] = referenceOnlyParam.toString(); - }, except: (fieldUid) { - final Map referenceOnlyParam = {}; - if (fieldUid.fieldUidList != null && - fieldUid.fieldUidList.isNotEmpty) { - for (final item in fieldUid.fieldUidList) { - referenceArray.add(item); + referenceOnlyParam[referenceFieldUid] = referenceArray; + includeReference(referenceFieldUid); + parameter['only'] = referenceOnlyParam.toString(); + break; + case IncludeType.Except: + final Map referenceOnlyParam = {}; + if (includeReferenceField.fieldUidList != null && + includeReferenceField.fieldUidList.isNotEmpty) { + for (final item in includeReferenceField.fieldUidList) { + referenceArray.add(item); + } } - } - referenceOnlyParam[referenceFieldUid] = referenceArray; - includeReference(referenceFieldUid); - parameter['except'] = referenceOnlyParam.toString(); - }); + referenceOnlyParam[referenceFieldUid] = referenceArray; + includeReference(referenceFieldUid); + parameter['except'] = referenceOnlyParam.toString(); + break; + } } else { parameter['include[]'] = referenceFieldUid; } diff --git a/lib/src/enums/include.dart b/lib/src/enums/include.dart index 1188c60..9f7ef14 100644 --- a/lib/src/enums/include.dart +++ b/lib/src/enums/include.dart @@ -1,12 +1,10 @@ -import 'package:super_enum/super_enum.dart'; -part 'include.g.dart'; +import 'package:contentstack/src/enums/include_type.dart'; -@superEnum -enum _Include { - @Data(fields: [DataField>('fieldUidList')]) - None, - @Data(fields: [DataField>('fieldUidList')]) - Only, - @Data(fields: [DataField>('fieldUidList')]) - Except +// set the name to IncludeClass, as the name Include was conflicting with reference.dart enum in entry_queryable.dart +// it also has an element named Include +class IncludeClass { + final IncludeType includeType; + final List fieldUidList; + + IncludeClass(this.includeType, this.fieldUidList); } diff --git a/lib/src/enums/include.g.dart b/lib/src/enums/include.g.dart deleted file mode 100644 index 3399e76..0000000 --- a/lib/src/enums/include.g.dart +++ /dev/null @@ -1,175 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'include.dart'; - -// ************************************************************************** -// SuperEnumGenerator -// ************************************************************************** - -@immutable -abstract class Include extends Equatable { - const Include(this._type); - - factory Include.none({@required List fieldUidList}) = None; - - factory Include.only({@required List fieldUidList}) = Only; - - factory Include.except({@required List fieldUidList}) = Except; - - final _Include _type; - -//ignore: missing_return - R when( - {@required R Function(None) none, - @required R Function(Only) only, - @required R Function(Except) except}) { - assert(() { - if (none == null || only == null || except == null) { - throw 'check for all possible cases'; - } - return true; - }()); - switch (this._type) { - case _Include.None: - return none(this as None); - case _Include.Only: - return only(this as Only); - case _Include.Except: - return except(this as Except); - } - } - -//ignore: missing_return - Future asyncWhen( - {@required FutureOr Function(None) none, - @required FutureOr Function(Only) only, - @required FutureOr Function(Except) except}) { - assert(() { - if (none == null || only == null || except == null) { - throw 'check for all possible cases'; - } - return true; - }()); - switch (this._type) { - case _Include.None: - return none(this as None); - case _Include.Only: - return only(this as Only); - case _Include.Except: - return except(this as Except); - } - } - - R whenOrElse( - {R Function(None) none, - R Function(Only) only, - R Function(Except) except, - @required R Function(Include) orElse}) { - assert(() { - if (orElse == null) { - throw 'Missing orElse case'; - } - return true; - }()); - switch (this._type) { - case _Include.None: - if (none == null) break; - return none(this as None); - case _Include.Only: - if (only == null) break; - return only(this as Only); - case _Include.Except: - if (except == null) break; - return except(this as Except); - } - return orElse(this); - } - - Future asyncWhenOrElse( - {FutureOr Function(None) none, - FutureOr Function(Only) only, - FutureOr Function(Except) except, - @required FutureOr Function(Include) orElse}) { - assert(() { - if (orElse == null) { - throw 'Missing orElse case'; - } - return true; - }()); - switch (this._type) { - case _Include.None: - if (none == null) break; - return none(this as None); - case _Include.Only: - if (only == null) break; - return only(this as Only); - case _Include.Except: - if (except == null) break; - return except(this as Except); - } - return orElse(this); - } - -//ignore: missing_return - Future whenPartial( - {FutureOr Function(None) none, - FutureOr Function(Only) only, - FutureOr Function(Except) except}) { - assert(() { - if (none == null && only == null && except == null) { - throw 'provide at least one branch'; - } - return true; - }()); - switch (this._type) { - case _Include.None: - if (none == null) break; - return none(this as None); - case _Include.Only: - if (only == null) break; - return only(this as Only); - case _Include.Except: - if (except == null) break; - return except(this as Except); - } - } - - @override - List get props => const []; -} - -@immutable -class None extends Include { - const None({@required this.fieldUidList}) : super(_Include.None); - - final List fieldUidList; - - @override - String toString() => 'None(fieldUidList:${this.fieldUidList})'; - @override - List get props => [fieldUidList]; -} - -@immutable -class Only extends Include { - const Only({@required this.fieldUidList}) : super(_Include.Only); - - final List fieldUidList; - - @override - String toString() => 'Only(fieldUidList:${this.fieldUidList})'; - @override - List get props => [fieldUidList]; -} - -@immutable -class Except extends Include { - const Except({@required this.fieldUidList}) : super(_Include.Except); - - final List fieldUidList; - - @override - String toString() => 'Except(fieldUidList:${this.fieldUidList})'; - @override - List get props => [fieldUidList]; -} diff --git a/lib/src/enums/include_type.dart b/lib/src/enums/include_type.dart new file mode 100644 index 0000000..8a59fde --- /dev/null +++ b/lib/src/enums/include_type.dart @@ -0,0 +1,5 @@ +enum IncludeType { + None, + Only, + Except +} \ No newline at end of file diff --git a/lib/src/enums/operations.dart b/lib/src/enums/operations.dart index a4de7b7..045eaeb 100644 --- a/lib/src/enums/operations.dart +++ b/lib/src/enums/operations.dart @@ -1,26 +1,8 @@ -import 'package:super_enum/super_enum.dart'; -part 'operations.g.dart'; +import 'package:contentstack/src/enums/operations_type.dart'; -@superEnum -enum _QueryOperation { - @Data(fields: [DataField('value')]) - Equals, - @Data(fields: [DataField('value')]) - NotEquals, - @Data(fields: [DataField>('value')]) - Includes, - @Data(fields: [DataField>('value')]) - Excludes, - @Data(fields: [DataField('value')]) - IsLessThan, - @Data(fields: [DataField('value')]) - IsLessThanOrEqual, - @Data(fields: [DataField('value')]) - IsGreaterThan, - @Data(fields: [DataField('value')]) - IsGreaterThanOrEqual, - @Data(fields: [DataField('value')]) - Exists, - @Data(fields: [DataField('regex')]) - Matches, +class QueryOperation { + final QueryOperationType operationType; + final dynamic value; + + QueryOperation(this.operationType, this.value); } diff --git a/lib/src/enums/operations.g.dart b/lib/src/enums/operations.g.dart deleted file mode 100644 index e9f713d..0000000 --- a/lib/src/enums/operations.g.dart +++ /dev/null @@ -1,432 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'operations.dart'; - -// ************************************************************************** -// SuperEnumGenerator -// ************************************************************************** - -@immutable -abstract class QueryOperation extends Equatable { - const QueryOperation(this._type); - - factory QueryOperation.equals({@required dynamic value}) = Equals; - - factory QueryOperation.notEquals({@required dynamic value}) = NotEquals; - - factory QueryOperation.includes({@required List value}) = Includes; - - factory QueryOperation.excludes({@required List value}) = Excludes; - - factory QueryOperation.isLessThan({@required dynamic value}) = IsLessThan; - - factory QueryOperation.isLessThanOrEqual({@required dynamic value}) = - IsLessThanOrEqual; - - factory QueryOperation.isGreaterThan({@required dynamic value}) = - IsGreaterThan; - - factory QueryOperation.isGreaterThanOrEqual({@required dynamic value}) = - IsGreaterThanOrEqual; - - factory QueryOperation.exists({@required bool value}) = Exists; - - factory QueryOperation.matches({@required String regex}) = Matches; - - final _QueryOperation _type; - -//ignore: missing_return - R when( - {@required R Function(Equals) equals, - @required R Function(NotEquals) notEquals, - @required R Function(Includes) includes, - @required R Function(Excludes) excludes, - @required R Function(IsLessThan) isLessThan, - @required R Function(IsLessThanOrEqual) isLessThanOrEqual, - @required R Function(IsGreaterThan) isGreaterThan, - @required R Function(IsGreaterThanOrEqual) isGreaterThanOrEqual, - @required R Function(Exists) exists, - @required R Function(Matches) matches}) { - assert(() { - if (equals == null || - notEquals == null || - includes == null || - excludes == null || - isLessThan == null || - isLessThanOrEqual == null || - isGreaterThan == null || - isGreaterThanOrEqual == null || - exists == null || - matches == null) { - throw 'check for all possible cases'; - } - return true; - }()); - switch (this._type) { - case _QueryOperation.Equals: - return equals(this as Equals); - case _QueryOperation.NotEquals: - return notEquals(this as NotEquals); - case _QueryOperation.Includes: - return includes(this as Includes); - case _QueryOperation.Excludes: - return excludes(this as Excludes); - case _QueryOperation.IsLessThan: - return isLessThan(this as IsLessThan); - case _QueryOperation.IsLessThanOrEqual: - return isLessThanOrEqual(this as IsLessThanOrEqual); - case _QueryOperation.IsGreaterThan: - return isGreaterThan(this as IsGreaterThan); - case _QueryOperation.IsGreaterThanOrEqual: - return isGreaterThanOrEqual(this as IsGreaterThanOrEqual); - case _QueryOperation.Exists: - return exists(this as Exists); - case _QueryOperation.Matches: - return matches(this as Matches); - } - } - -//ignore: missing_return - Future asyncWhen( - {@required FutureOr Function(Equals) equals, - @required FutureOr Function(NotEquals) notEquals, - @required FutureOr Function(Includes) includes, - @required FutureOr Function(Excludes) excludes, - @required FutureOr Function(IsLessThan) isLessThan, - @required FutureOr Function(IsLessThanOrEqual) isLessThanOrEqual, - @required FutureOr Function(IsGreaterThan) isGreaterThan, - @required FutureOr Function(IsGreaterThanOrEqual) isGreaterThanOrEqual, - @required FutureOr Function(Exists) exists, - @required FutureOr Function(Matches) matches}) { - assert(() { - if (equals == null || - notEquals == null || - includes == null || - excludes == null || - isLessThan == null || - isLessThanOrEqual == null || - isGreaterThan == null || - isGreaterThanOrEqual == null || - exists == null || - matches == null) { - throw 'check for all possible cases'; - } - return true; - }()); - switch (this._type) { - case _QueryOperation.Equals: - return equals(this as Equals); - case _QueryOperation.NotEquals: - return notEquals(this as NotEquals); - case _QueryOperation.Includes: - return includes(this as Includes); - case _QueryOperation.Excludes: - return excludes(this as Excludes); - case _QueryOperation.IsLessThan: - return isLessThan(this as IsLessThan); - case _QueryOperation.IsLessThanOrEqual: - return isLessThanOrEqual(this as IsLessThanOrEqual); - case _QueryOperation.IsGreaterThan: - return isGreaterThan(this as IsGreaterThan); - case _QueryOperation.IsGreaterThanOrEqual: - return isGreaterThanOrEqual(this as IsGreaterThanOrEqual); - case _QueryOperation.Exists: - return exists(this as Exists); - case _QueryOperation.Matches: - return matches(this as Matches); - } - } - - R whenOrElse( - {R Function(Equals) equals, - R Function(NotEquals) notEquals, - R Function(Includes) includes, - R Function(Excludes) excludes, - R Function(IsLessThan) isLessThan, - R Function(IsLessThanOrEqual) isLessThanOrEqual, - R Function(IsGreaterThan) isGreaterThan, - R Function(IsGreaterThanOrEqual) isGreaterThanOrEqual, - R Function(Exists) exists, - R Function(Matches) matches, - @required R Function(QueryOperation) orElse}) { - assert(() { - if (orElse == null) { - throw 'Missing orElse case'; - } - return true; - }()); - switch (this._type) { - case _QueryOperation.Equals: - if (equals == null) break; - return equals(this as Equals); - case _QueryOperation.NotEquals: - if (notEquals == null) break; - return notEquals(this as NotEquals); - case _QueryOperation.Includes: - if (includes == null) break; - return includes(this as Includes); - case _QueryOperation.Excludes: - if (excludes == null) break; - return excludes(this as Excludes); - case _QueryOperation.IsLessThan: - if (isLessThan == null) break; - return isLessThan(this as IsLessThan); - case _QueryOperation.IsLessThanOrEqual: - if (isLessThanOrEqual == null) break; - return isLessThanOrEqual(this as IsLessThanOrEqual); - case _QueryOperation.IsGreaterThan: - if (isGreaterThan == null) break; - return isGreaterThan(this as IsGreaterThan); - case _QueryOperation.IsGreaterThanOrEqual: - if (isGreaterThanOrEqual == null) break; - return isGreaterThanOrEqual(this as IsGreaterThanOrEqual); - case _QueryOperation.Exists: - if (exists == null) break; - return exists(this as Exists); - case _QueryOperation.Matches: - if (matches == null) break; - return matches(this as Matches); - } - return orElse(this); - } - - Future asyncWhenOrElse( - {FutureOr Function(Equals) equals, - FutureOr Function(NotEquals) notEquals, - FutureOr Function(Includes) includes, - FutureOr Function(Excludes) excludes, - FutureOr Function(IsLessThan) isLessThan, - FutureOr Function(IsLessThanOrEqual) isLessThanOrEqual, - FutureOr Function(IsGreaterThan) isGreaterThan, - FutureOr Function(IsGreaterThanOrEqual) isGreaterThanOrEqual, - FutureOr Function(Exists) exists, - FutureOr Function(Matches) matches, - @required FutureOr Function(QueryOperation) orElse}) { - assert(() { - if (orElse == null) { - throw 'Missing orElse case'; - } - return true; - }()); - switch (this._type) { - case _QueryOperation.Equals: - if (equals == null) break; - return equals(this as Equals); - case _QueryOperation.NotEquals: - if (notEquals == null) break; - return notEquals(this as NotEquals); - case _QueryOperation.Includes: - if (includes == null) break; - return includes(this as Includes); - case _QueryOperation.Excludes: - if (excludes == null) break; - return excludes(this as Excludes); - case _QueryOperation.IsLessThan: - if (isLessThan == null) break; - return isLessThan(this as IsLessThan); - case _QueryOperation.IsLessThanOrEqual: - if (isLessThanOrEqual == null) break; - return isLessThanOrEqual(this as IsLessThanOrEqual); - case _QueryOperation.IsGreaterThan: - if (isGreaterThan == null) break; - return isGreaterThan(this as IsGreaterThan); - case _QueryOperation.IsGreaterThanOrEqual: - if (isGreaterThanOrEqual == null) break; - return isGreaterThanOrEqual(this as IsGreaterThanOrEqual); - case _QueryOperation.Exists: - if (exists == null) break; - return exists(this as Exists); - case _QueryOperation.Matches: - if (matches == null) break; - return matches(this as Matches); - } - return orElse(this); - } - -//ignore: missing_return - Future whenPartial( - {FutureOr Function(Equals) equals, - FutureOr Function(NotEquals) notEquals, - FutureOr Function(Includes) includes, - FutureOr Function(Excludes) excludes, - FutureOr Function(IsLessThan) isLessThan, - FutureOr Function(IsLessThanOrEqual) isLessThanOrEqual, - FutureOr Function(IsGreaterThan) isGreaterThan, - FutureOr Function(IsGreaterThanOrEqual) isGreaterThanOrEqual, - FutureOr Function(Exists) exists, - FutureOr Function(Matches) matches}) { - assert(() { - if (equals == null && - notEquals == null && - includes == null && - excludes == null && - isLessThan == null && - isLessThanOrEqual == null && - isGreaterThan == null && - isGreaterThanOrEqual == null && - exists == null && - matches == null) { - throw 'provide at least one branch'; - } - return true; - }()); - switch (this._type) { - case _QueryOperation.Equals: - if (equals == null) break; - return equals(this as Equals); - case _QueryOperation.NotEquals: - if (notEquals == null) break; - return notEquals(this as NotEquals); - case _QueryOperation.Includes: - if (includes == null) break; - return includes(this as Includes); - case _QueryOperation.Excludes: - if (excludes == null) break; - return excludes(this as Excludes); - case _QueryOperation.IsLessThan: - if (isLessThan == null) break; - return isLessThan(this as IsLessThan); - case _QueryOperation.IsLessThanOrEqual: - if (isLessThanOrEqual == null) break; - return isLessThanOrEqual(this as IsLessThanOrEqual); - case _QueryOperation.IsGreaterThan: - if (isGreaterThan == null) break; - return isGreaterThan(this as IsGreaterThan); - case _QueryOperation.IsGreaterThanOrEqual: - if (isGreaterThanOrEqual == null) break; - return isGreaterThanOrEqual(this as IsGreaterThanOrEqual); - case _QueryOperation.Exists: - if (exists == null) break; - return exists(this as Exists); - case _QueryOperation.Matches: - if (matches == null) break; - return matches(this as Matches); - } - } - - @override - List get props => const []; -} - -@immutable -class Equals extends QueryOperation { - const Equals({@required this.value}) : super(_QueryOperation.Equals); - - final dynamic value; - - @override - String toString() => 'Equals(value:${this.value})'; - @override - List get props => [value]; -} - -@immutable -class NotEquals extends QueryOperation { - const NotEquals({@required this.value}) : super(_QueryOperation.NotEquals); - - final dynamic value; - - @override - String toString() => 'NotEquals(value:${this.value})'; - @override - List get props => [value]; -} - -@immutable -class Includes extends QueryOperation { - const Includes({@required this.value}) : super(_QueryOperation.Includes); - - final List value; - - @override - String toString() => 'Includes(value:${this.value})'; - @override - List get props => [value]; -} - -@immutable -class Excludes extends QueryOperation { - const Excludes({@required this.value}) : super(_QueryOperation.Excludes); - - final List value; - - @override - String toString() => 'Excludes(value:${this.value})'; - @override - List get props => [value]; -} - -@immutable -class IsLessThan extends QueryOperation { - const IsLessThan({@required this.value}) : super(_QueryOperation.IsLessThan); - - final dynamic value; - - @override - String toString() => 'IsLessThan(value:${this.value})'; - @override - List get props => [value]; -} - -@immutable -class IsLessThanOrEqual extends QueryOperation { - const IsLessThanOrEqual({@required this.value}) - : super(_QueryOperation.IsLessThanOrEqual); - - final dynamic value; - - @override - String toString() => 'IsLessThanOrEqual(value:${this.value})'; - @override - List get props => [value]; -} - -@immutable -class IsGreaterThan extends QueryOperation { - const IsGreaterThan({@required this.value}) - : super(_QueryOperation.IsGreaterThan); - - final dynamic value; - - @override - String toString() => 'IsGreaterThan(value:${this.value})'; - @override - List get props => [value]; -} - -@immutable -class IsGreaterThanOrEqual extends QueryOperation { - const IsGreaterThanOrEqual({@required this.value}) - : super(_QueryOperation.IsGreaterThanOrEqual); - - final dynamic value; - - @override - String toString() => 'IsGreaterThanOrEqual(value:${this.value})'; - @override - List get props => [value]; -} - -@immutable -class Exists extends QueryOperation { - const Exists({@required this.value}) : super(_QueryOperation.Exists); - - final bool value; - - @override - String toString() => 'Exists(value:${this.value})'; - @override - List get props => [value]; -} - -@immutable -class Matches extends QueryOperation { - const Matches({@required this.regex}) : super(_QueryOperation.Matches); - - final String regex; - - @override - String toString() => 'Matches(regex:${this.regex})'; - @override - List get props => [regex]; -} diff --git a/lib/src/enums/operations_type.dart b/lib/src/enums/operations_type.dart new file mode 100644 index 0000000..2a9d5e4 --- /dev/null +++ b/lib/src/enums/operations_type.dart @@ -0,0 +1,12 @@ +enum QueryOperationType { + Equals, + NotEquals, + Includes, + Excludes, + IsLessThan, + IsLessThanOrEqual, + IsGreaterThan, + IsGreaterThanOrEqual, + Exists, + Matches +} \ No newline at end of file diff --git a/lib/src/enums/operator.dart b/lib/src/enums/operator.dart index 1aed531..4cc114c 100644 --- a/lib/src/enums/operator.dart +++ b/lib/src/enums/operator.dart @@ -1,11 +1,9 @@ import 'package:contentstack/src/query.dart'; -import 'package:super_enum/super_enum.dart'; -part 'operator.g.dart'; +import 'package:contentstack/src/enums/operator_type.dart'; -@superEnum -enum _QueryOperator { - @Data(fields: [DataField>('queryObjects')]) - And, - @Data(fields: [DataField>('queryObjects')]) - Or +class QueryOperator { + final QueryOperatorType operatorType; + final List queryObjects; + + QueryOperator(this.operatorType, this.queryObjects); } diff --git a/lib/src/enums/operator.g.dart b/lib/src/enums/operator.g.dart deleted file mode 100644 index f6bfdf2..0000000 --- a/lib/src/enums/operator.g.dart +++ /dev/null @@ -1,140 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'operator.dart'; - -// ************************************************************************** -// SuperEnumGenerator -// ************************************************************************** - -@immutable -abstract class QueryOperator extends Equatable { - const QueryOperator(this._type); - - factory QueryOperator.and({@required List queryObjects}) = And; - - factory QueryOperator.or({@required List queryObjects}) = Or; - - final _QueryOperator _type; - -//ignore: missing_return - R when({@required R Function(And) and, @required R Function(Or) or}) { - assert(() { - if (and == null || or == null) { - throw 'check for all possible cases'; - } - return true; - }()); - switch (this._type) { - case _QueryOperator.And: - return and(this as And); - case _QueryOperator.Or: - return or(this as Or); - } - } - -//ignore: missing_return - Future asyncWhen( - {@required FutureOr Function(And) and, - @required FutureOr Function(Or) or}) { - assert(() { - if (and == null || or == null) { - throw 'check for all possible cases'; - } - return true; - }()); - switch (this._type) { - case _QueryOperator.And: - return and(this as And); - case _QueryOperator.Or: - return or(this as Or); - } - } - - R whenOrElse( - {R Function(And) and, - R Function(Or) or, - @required R Function(QueryOperator) orElse}) { - assert(() { - if (orElse == null) { - throw 'Missing orElse case'; - } - return true; - }()); - switch (this._type) { - case _QueryOperator.And: - if (and == null) break; - return and(this as And); - case _QueryOperator.Or: - if (or == null) break; - return or(this as Or); - } - return orElse(this); - } - - Future asyncWhenOrElse( - {FutureOr Function(And) and, - FutureOr Function(Or) or, - @required FutureOr Function(QueryOperator) orElse}) { - assert(() { - if (orElse == null) { - throw 'Missing orElse case'; - } - return true; - }()); - switch (this._type) { - case _QueryOperator.And: - if (and == null) break; - return and(this as And); - case _QueryOperator.Or: - if (or == null) break; - return or(this as Or); - } - return orElse(this); - } - -//ignore: missing_return - Future whenPartial( - {FutureOr Function(And) and, FutureOr Function(Or) or}) { - assert(() { - if (and == null && or == null) { - throw 'provide at least one branch'; - } - return true; - }()); - switch (this._type) { - case _QueryOperator.And: - if (and == null) break; - return and(this as And); - case _QueryOperator.Or: - if (or == null) break; - return or(this as Or); - } - } - - @override - List get props => const []; -} - -@immutable -class And extends QueryOperator { - const And({@required this.queryObjects}) : super(_QueryOperator.And); - - final List queryObjects; - - @override - String toString() => 'And(queryObjects:${this.queryObjects})'; - @override - List get props => [queryObjects]; -} - -@immutable -class Or extends QueryOperator { - const Or({@required this.queryObjects}) : super(_QueryOperator.Or); - - final List queryObjects; - - @override - String toString() => 'Or(queryObjects:${this.queryObjects})'; - @override - List get props => [queryObjects]; -} diff --git a/lib/src/enums/operator_type.dart b/lib/src/enums/operator_type.dart new file mode 100644 index 0000000..b719c46 --- /dev/null +++ b/lib/src/enums/operator_type.dart @@ -0,0 +1,4 @@ +enum QueryOperatorType { + And, + Or +} \ No newline at end of file diff --git a/lib/src/enums/reference.dart b/lib/src/enums/reference.dart index bd61aaa..df7afea 100644 --- a/lib/src/enums/reference.dart +++ b/lib/src/enums/reference.dart @@ -1,11 +1,9 @@ +import 'package:contentstack/src/enums/reference_type.dart'; import 'package:contentstack/src/query.dart'; -import 'package:super_enum/super_enum.dart'; -part 'reference.g.dart'; -@superEnum -enum _QueryReference { - @Data(fields: [DataField('query')]) - Include, - @Data(fields: [DataField('query')]) - NotInclude +class QueryReference { + final QueryReferenceType referenceType; + final Query query; + + QueryReference(this.referenceType, this.query); } diff --git a/lib/src/enums/reference.g.dart b/lib/src/enums/reference.g.dart deleted file mode 100644 index 862d62b..0000000 --- a/lib/src/enums/reference.g.dart +++ /dev/null @@ -1,143 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'reference.dart'; - -// ************************************************************************** -// SuperEnumGenerator -// ************************************************************************** - -@immutable -abstract class QueryReference extends Equatable { - const QueryReference(this._type); - - factory QueryReference.include({@required Query query}) = Include; - - factory QueryReference.notInclude({@required Query query}) = NotInclude; - - final _QueryReference _type; - -//ignore: missing_return - R when( - {@required R Function(Include) include, - @required R Function(NotInclude) notInclude}) { - assert(() { - if (include == null || notInclude == null) { - throw 'check for all possible cases'; - } - return true; - }()); - switch (this._type) { - case _QueryReference.Include: - return include(this as Include); - case _QueryReference.NotInclude: - return notInclude(this as NotInclude); - } - } - -//ignore: missing_return - Future asyncWhen( - {@required FutureOr Function(Include) include, - @required FutureOr Function(NotInclude) notInclude}) { - assert(() { - if (include == null || notInclude == null) { - throw 'check for all possible cases'; - } - return true; - }()); - switch (this._type) { - case _QueryReference.Include: - return include(this as Include); - case _QueryReference.NotInclude: - return notInclude(this as NotInclude); - } - } - - R whenOrElse( - {R Function(Include) include, - R Function(NotInclude) notInclude, - @required R Function(QueryReference) orElse}) { - assert(() { - if (orElse == null) { - throw 'Missing orElse case'; - } - return true; - }()); - switch (this._type) { - case _QueryReference.Include: - if (include == null) break; - return include(this as Include); - case _QueryReference.NotInclude: - if (notInclude == null) break; - return notInclude(this as NotInclude); - } - return orElse(this); - } - - Future asyncWhenOrElse( - {FutureOr Function(Include) include, - FutureOr Function(NotInclude) notInclude, - @required FutureOr Function(QueryReference) orElse}) { - assert(() { - if (orElse == null) { - throw 'Missing orElse case'; - } - return true; - }()); - switch (this._type) { - case _QueryReference.Include: - if (include == null) break; - return include(this as Include); - case _QueryReference.NotInclude: - if (notInclude == null) break; - return notInclude(this as NotInclude); - } - return orElse(this); - } - -//ignore: missing_return - Future whenPartial( - {FutureOr Function(Include) include, - FutureOr Function(NotInclude) notInclude}) { - assert(() { - if (include == null && notInclude == null) { - throw 'provide at least one branch'; - } - return true; - }()); - switch (this._type) { - case _QueryReference.Include: - if (include == null) break; - return include(this as Include); - case _QueryReference.NotInclude: - if (notInclude == null) break; - return notInclude(this as NotInclude); - } - } - - @override - List get props => const []; -} - -@immutable -class Include extends QueryReference { - const Include({@required this.query}) : super(_QueryReference.Include); - - final Query query; - - @override - String toString() => 'Include(query:${this.query})'; - @override - List get props => [query]; -} - -@immutable -class NotInclude extends QueryReference { - const NotInclude({@required this.query}) : super(_QueryReference.NotInclude); - - final Query query; - - @override - String toString() => 'NotInclude(query:${this.query})'; - @override - List get props => [query]; -} diff --git a/lib/src/enums/reference_type.dart b/lib/src/enums/reference_type.dart new file mode 100644 index 0000000..0333426 --- /dev/null +++ b/lib/src/enums/reference_type.dart @@ -0,0 +1,4 @@ +enum QueryReferenceType { + Include, + NotInclude +} diff --git a/lib/src/error/error.dart b/lib/src/error/error.dart index 56dc354..b165794 100644 --- a/lib/src/error/error.dart +++ b/lib/src/error/error.dart @@ -7,10 +7,10 @@ part 'error.g.dart'; @JsonSerializable(createFactory: true) class Error implements Exception { @JsonKey(name: 'error_message') - final String errorMessage; + final String? errorMessage; @JsonKey(name: 'error_code') - final int errorCode; - final Map errors; + final int? errorCode; + final Map? errors; Error({this.errorMessage, this.errorCode, this.errors}); factory Error.fromJson(Map json) => _$ErrorFromJson(json); Map toJson() => _$ErrorToJson(this); diff --git a/lib/src/error/error.g.dart b/lib/src/error/error.g.dart index 68c4ae4..6a7ec74 100644 --- a/lib/src/error/error.g.dart +++ b/lib/src/error/error.g.dart @@ -8,9 +8,9 @@ part of 'error.dart'; Error _$ErrorFromJson(Map json) { return Error( - errorMessage: json['error_message'] as String, - errorCode: json['error_code'] as int, - errors: json['errors'] as Map, + errorMessage: json['error_message'] as String?, + errorCode: json['error_code'] as int?, + errors: json['errors'] as Map?, ); } diff --git a/lib/src/image/filter.dart b/lib/src/image/filter.dart index 961cdb4..b9b8c8f 100644 --- a/lib/src/image/filter.dart +++ b/lib/src/image/filter.dart @@ -1,15 +1,9 @@ -import 'package:super_enum/super_enum.dart'; -part 'filter.g.dart'; - -@superEnum -enum _Filter { +enum Filter { //nearest, bilinear, bicubic, lanczos - @object Nearest, - @object Bilinear, - @object Bicubic, - @object - Lanczos, + Lanczos } + + diff --git a/lib/src/image/filter.g.dart b/lib/src/image/filter.g.dart deleted file mode 100644 index 037247a..0000000 --- a/lib/src/image/filter.g.dart +++ /dev/null @@ -1,216 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'filter.dart'; - -// ************************************************************************** -// SuperEnumGenerator -// ************************************************************************** - -@immutable -abstract class Filter extends Equatable { - const Filter(this._type); - - factory Filter.nearest() = Nearest; - - factory Filter.bilinear() = Bilinear; - - factory Filter.bicubic() = Bicubic; - - factory Filter.lanczos() = Lanczos; - - final _Filter _type; - -//ignore: missing_return - R when( - {@required R Function(Nearest) nearest, - @required R Function(Bilinear) bilinear, - @required R Function(Bicubic) bicubic, - @required R Function(Lanczos) lanczos}) { - assert(() { - if (nearest == null || - bilinear == null || - bicubic == null || - lanczos == null) { - throw 'check for all possible cases'; - } - return true; - }()); - switch (this._type) { - case _Filter.Nearest: - return nearest(this as Nearest); - case _Filter.Bilinear: - return bilinear(this as Bilinear); - case _Filter.Bicubic: - return bicubic(this as Bicubic); - case _Filter.Lanczos: - return lanczos(this as Lanczos); - } - } - -//ignore: missing_return - Future asyncWhen( - {@required FutureOr Function(Nearest) nearest, - @required FutureOr Function(Bilinear) bilinear, - @required FutureOr Function(Bicubic) bicubic, - @required FutureOr Function(Lanczos) lanczos}) { - assert(() { - if (nearest == null || - bilinear == null || - bicubic == null || - lanczos == null) { - throw 'check for all possible cases'; - } - return true; - }()); - switch (this._type) { - case _Filter.Nearest: - return nearest(this as Nearest); - case _Filter.Bilinear: - return bilinear(this as Bilinear); - case _Filter.Bicubic: - return bicubic(this as Bicubic); - case _Filter.Lanczos: - return lanczos(this as Lanczos); - } - } - - R whenOrElse( - {R Function(Nearest) nearest, - R Function(Bilinear) bilinear, - R Function(Bicubic) bicubic, - R Function(Lanczos) lanczos, - @required R Function(Filter) orElse}) { - assert(() { - if (orElse == null) { - throw 'Missing orElse case'; - } - return true; - }()); - switch (this._type) { - case _Filter.Nearest: - if (nearest == null) break; - return nearest(this as Nearest); - case _Filter.Bilinear: - if (bilinear == null) break; - return bilinear(this as Bilinear); - case _Filter.Bicubic: - if (bicubic == null) break; - return bicubic(this as Bicubic); - case _Filter.Lanczos: - if (lanczos == null) break; - return lanczos(this as Lanczos); - } - return orElse(this); - } - - Future asyncWhenOrElse( - {FutureOr Function(Nearest) nearest, - FutureOr Function(Bilinear) bilinear, - FutureOr Function(Bicubic) bicubic, - FutureOr Function(Lanczos) lanczos, - @required FutureOr Function(Filter) orElse}) { - assert(() { - if (orElse == null) { - throw 'Missing orElse case'; - } - return true; - }()); - switch (this._type) { - case _Filter.Nearest: - if (nearest == null) break; - return nearest(this as Nearest); - case _Filter.Bilinear: - if (bilinear == null) break; - return bilinear(this as Bilinear); - case _Filter.Bicubic: - if (bicubic == null) break; - return bicubic(this as Bicubic); - case _Filter.Lanczos: - if (lanczos == null) break; - return lanczos(this as Lanczos); - } - return orElse(this); - } - -//ignore: missing_return - Future whenPartial( - {FutureOr Function(Nearest) nearest, - FutureOr Function(Bilinear) bilinear, - FutureOr Function(Bicubic) bicubic, - FutureOr Function(Lanczos) lanczos}) { - assert(() { - if (nearest == null && - bilinear == null && - bicubic == null && - lanczos == null) { - throw 'provide at least one branch'; - } - return true; - }()); - switch (this._type) { - case _Filter.Nearest: - if (nearest == null) break; - return nearest(this as Nearest); - case _Filter.Bilinear: - if (bilinear == null) break; - return bilinear(this as Bilinear); - case _Filter.Bicubic: - if (bicubic == null) break; - return bicubic(this as Bicubic); - case _Filter.Lanczos: - if (lanczos == null) break; - return lanczos(this as Lanczos); - } - } - - @override - List get props => const []; -} - -@immutable -class Nearest extends Filter { - const Nearest._() : super(_Filter.Nearest); - - factory Nearest() { - _instance ??= const Nearest._(); - return _instance; - } - - static Nearest _instance; -} - -@immutable -class Bilinear extends Filter { - const Bilinear._() : super(_Filter.Bilinear); - - factory Bilinear() { - _instance ??= const Bilinear._(); - return _instance; - } - - static Bilinear _instance; -} - -@immutable -class Bicubic extends Filter { - const Bicubic._() : super(_Filter.Bicubic); - - factory Bicubic() { - _instance ??= const Bicubic._(); - return _instance; - } - - static Bicubic _instance; -} - -@immutable -class Lanczos extends Filter { - const Lanczos._() : super(_Filter.Lanczos); - - factory Lanczos() { - _instance ??= const Lanczos._(); - return _instance; - } - - static Lanczos _instance; -} diff --git a/lib/src/image/fit.dart b/lib/src/image/fit.dart index c51e633..62c2022 100644 --- a/lib/src/image/fit.dart +++ b/lib/src/image/fit.dart @@ -1,11 +1,5 @@ -import 'package:super_enum/super_enum.dart'; -part 'fit.g.dart'; - -@superEnum -enum _Fit { +enum Fit { //nearest, bilinear, bicubic, lanczos - @object Bounds, - @object - Crop, + Crop } diff --git a/lib/src/image/fit.g.dart b/lib/src/image/fit.g.dart deleted file mode 100644 index 760f2b2..0000000 --- a/lib/src/image/fit.g.dart +++ /dev/null @@ -1,142 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'fit.dart'; - -// ************************************************************************** -// SuperEnumGenerator -// ************************************************************************** - -@immutable -abstract class Fit extends Equatable { - const Fit(this._type); - - factory Fit.bounds() = Bounds; - - factory Fit.crop() = Crop; - - final _Fit _type; - -//ignore: missing_return - R when( - {@required R Function(Bounds) bounds, @required R Function(Crop) crop}) { - assert(() { - if (bounds == null || crop == null) { - throw 'check for all possible cases'; - } - return true; - }()); - switch (this._type) { - case _Fit.Bounds: - return bounds(this as Bounds); - case _Fit.Crop: - return crop(this as Crop); - } - } - -//ignore: missing_return - Future asyncWhen( - {@required FutureOr Function(Bounds) bounds, - @required FutureOr Function(Crop) crop}) { - assert(() { - if (bounds == null || crop == null) { - throw 'check for all possible cases'; - } - return true; - }()); - switch (this._type) { - case _Fit.Bounds: - return bounds(this as Bounds); - case _Fit.Crop: - return crop(this as Crop); - } - } - - R whenOrElse( - {R Function(Bounds) bounds, - R Function(Crop) crop, - @required R Function(Fit) orElse}) { - assert(() { - if (orElse == null) { - throw 'Missing orElse case'; - } - return true; - }()); - switch (this._type) { - case _Fit.Bounds: - if (bounds == null) break; - return bounds(this as Bounds); - case _Fit.Crop: - if (crop == null) break; - return crop(this as Crop); - } - return orElse(this); - } - - Future asyncWhenOrElse( - {FutureOr Function(Bounds) bounds, - FutureOr Function(Crop) crop, - @required FutureOr Function(Fit) orElse}) { - assert(() { - if (orElse == null) { - throw 'Missing orElse case'; - } - return true; - }()); - switch (this._type) { - case _Fit.Bounds: - if (bounds == null) break; - return bounds(this as Bounds); - case _Fit.Crop: - if (crop == null) break; - return crop(this as Crop); - } - return orElse(this); - } - -//ignore: missing_return - Future whenPartial( - {FutureOr Function(Bounds) bounds, - FutureOr Function(Crop) crop}) { - assert(() { - if (bounds == null && crop == null) { - throw 'provide at least one branch'; - } - return true; - }()); - switch (this._type) { - case _Fit.Bounds: - if (bounds == null) break; - return bounds(this as Bounds); - case _Fit.Crop: - if (crop == null) break; - return crop(this as Crop); - } - } - - @override - List get props => const []; -} - -@immutable -class Bounds extends Fit { - const Bounds._() : super(_Fit.Bounds); - - factory Bounds() { - _instance ??= const Bounds._(); - return _instance; - } - - static Bounds _instance; -} - -@immutable -class Crop extends Fit { - const Crop._() : super(_Fit.Crop); - - factory Crop() { - _instance ??= const Crop._(); - return _instance; - } - - static Crop _instance; -} diff --git a/lib/src/image/format.dart b/lib/src/image/format.dart index e0982c6..b3bd183 100644 --- a/lib/src/image/format.dart +++ b/lib/src/image/format.dart @@ -1,20 +1,9 @@ -import 'package:super_enum/super_enum.dart'; -part 'format.g.dart'; - -@superEnum -enum _Format { - @object +enum Format { Gif, - @object Png, - @object Jpg, - @object Pjpg, - @object Webp, - @object Webplossy, - @object - Webplossless, + Webplossless } diff --git a/lib/src/image/format.g.dart b/lib/src/image/format.g.dart deleted file mode 100644 index 470d3a4..0000000 --- a/lib/src/image/format.g.dart +++ /dev/null @@ -1,321 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'format.dart'; - -// ************************************************************************** -// SuperEnumGenerator -// ************************************************************************** - -@immutable -abstract class Format extends Equatable { - const Format(this._type); - - factory Format.gif() = Gif; - - factory Format.png() = Png; - - factory Format.jpg() = Jpg; - - factory Format.pjpg() = Pjpg; - - factory Format.webp() = Webp; - - factory Format.webplossy() = Webplossy; - - factory Format.webplossless() = Webplossless; - - final _Format _type; - -//ignore: missing_return - R when( - {@required R Function(Gif) gif, - @required R Function(Png) png, - @required R Function(Jpg) jpg, - @required R Function(Pjpg) pjpg, - @required R Function(Webp) webp, - @required R Function(Webplossy) webplossy, - @required R Function(Webplossless) webplossless}) { - assert(() { - if (gif == null || - png == null || - jpg == null || - pjpg == null || - webp == null || - webplossy == null || - webplossless == null) { - throw 'check for all possible cases'; - } - return true; - }()); - switch (this._type) { - case _Format.Gif: - return gif(this as Gif); - case _Format.Png: - return png(this as Png); - case _Format.Jpg: - return jpg(this as Jpg); - case _Format.Pjpg: - return pjpg(this as Pjpg); - case _Format.Webp: - return webp(this as Webp); - case _Format.Webplossy: - return webplossy(this as Webplossy); - case _Format.Webplossless: - return webplossless(this as Webplossless); - } - } - -//ignore: missing_return - Future asyncWhen( - {@required FutureOr Function(Gif) gif, - @required FutureOr Function(Png) png, - @required FutureOr Function(Jpg) jpg, - @required FutureOr Function(Pjpg) pjpg, - @required FutureOr Function(Webp) webp, - @required FutureOr Function(Webplossy) webplossy, - @required FutureOr Function(Webplossless) webplossless}) { - assert(() { - if (gif == null || - png == null || - jpg == null || - pjpg == null || - webp == null || - webplossy == null || - webplossless == null) { - throw 'check for all possible cases'; - } - return true; - }()); - switch (this._type) { - case _Format.Gif: - return gif(this as Gif); - case _Format.Png: - return png(this as Png); - case _Format.Jpg: - return jpg(this as Jpg); - case _Format.Pjpg: - return pjpg(this as Pjpg); - case _Format.Webp: - return webp(this as Webp); - case _Format.Webplossy: - return webplossy(this as Webplossy); - case _Format.Webplossless: - return webplossless(this as Webplossless); - } - } - - R whenOrElse( - {R Function(Gif) gif, - R Function(Png) png, - R Function(Jpg) jpg, - R Function(Pjpg) pjpg, - R Function(Webp) webp, - R Function(Webplossy) webplossy, - R Function(Webplossless) webplossless, - @required R Function(Format) orElse}) { - assert(() { - if (orElse == null) { - throw 'Missing orElse case'; - } - return true; - }()); - switch (this._type) { - case _Format.Gif: - if (gif == null) break; - return gif(this as Gif); - case _Format.Png: - if (png == null) break; - return png(this as Png); - case _Format.Jpg: - if (jpg == null) break; - return jpg(this as Jpg); - case _Format.Pjpg: - if (pjpg == null) break; - return pjpg(this as Pjpg); - case _Format.Webp: - if (webp == null) break; - return webp(this as Webp); - case _Format.Webplossy: - if (webplossy == null) break; - return webplossy(this as Webplossy); - case _Format.Webplossless: - if (webplossless == null) break; - return webplossless(this as Webplossless); - } - return orElse(this); - } - - Future asyncWhenOrElse( - {FutureOr Function(Gif) gif, - FutureOr Function(Png) png, - FutureOr Function(Jpg) jpg, - FutureOr Function(Pjpg) pjpg, - FutureOr Function(Webp) webp, - FutureOr Function(Webplossy) webplossy, - FutureOr Function(Webplossless) webplossless, - @required FutureOr Function(Format) orElse}) { - assert(() { - if (orElse == null) { - throw 'Missing orElse case'; - } - return true; - }()); - switch (this._type) { - case _Format.Gif: - if (gif == null) break; - return gif(this as Gif); - case _Format.Png: - if (png == null) break; - return png(this as Png); - case _Format.Jpg: - if (jpg == null) break; - return jpg(this as Jpg); - case _Format.Pjpg: - if (pjpg == null) break; - return pjpg(this as Pjpg); - case _Format.Webp: - if (webp == null) break; - return webp(this as Webp); - case _Format.Webplossy: - if (webplossy == null) break; - return webplossy(this as Webplossy); - case _Format.Webplossless: - if (webplossless == null) break; - return webplossless(this as Webplossless); - } - return orElse(this); - } - -//ignore: missing_return - Future whenPartial( - {FutureOr Function(Gif) gif, - FutureOr Function(Png) png, - FutureOr Function(Jpg) jpg, - FutureOr Function(Pjpg) pjpg, - FutureOr Function(Webp) webp, - FutureOr Function(Webplossy) webplossy, - FutureOr Function(Webplossless) webplossless}) { - assert(() { - if (gif == null && - png == null && - jpg == null && - pjpg == null && - webp == null && - webplossy == null && - webplossless == null) { - throw 'provide at least one branch'; - } - return true; - }()); - switch (this._type) { - case _Format.Gif: - if (gif == null) break; - return gif(this as Gif); - case _Format.Png: - if (png == null) break; - return png(this as Png); - case _Format.Jpg: - if (jpg == null) break; - return jpg(this as Jpg); - case _Format.Pjpg: - if (pjpg == null) break; - return pjpg(this as Pjpg); - case _Format.Webp: - if (webp == null) break; - return webp(this as Webp); - case _Format.Webplossy: - if (webplossy == null) break; - return webplossy(this as Webplossy); - case _Format.Webplossless: - if (webplossless == null) break; - return webplossless(this as Webplossless); - } - } - - @override - List get props => const []; -} - -@immutable -class Gif extends Format { - const Gif._() : super(_Format.Gif); - - factory Gif() { - _instance ??= const Gif._(); - return _instance; - } - - static Gif _instance; -} - -@immutable -class Png extends Format { - const Png._() : super(_Format.Png); - - factory Png() { - _instance ??= const Png._(); - return _instance; - } - - static Png _instance; -} - -@immutable -class Jpg extends Format { - const Jpg._() : super(_Format.Jpg); - - factory Jpg() { - _instance ??= const Jpg._(); - return _instance; - } - - static Jpg _instance; -} - -@immutable -class Pjpg extends Format { - const Pjpg._() : super(_Format.Pjpg); - - factory Pjpg() { - _instance ??= const Pjpg._(); - return _instance; - } - - static Pjpg _instance; -} - -@immutable -class Webp extends Format { - const Webp._() : super(_Format.Webp); - - factory Webp() { - _instance ??= const Webp._(); - return _instance; - } - - static Webp _instance; -} - -@immutable -class Webplossy extends Format { - const Webplossy._() : super(_Format.Webplossy); - - factory Webplossy() { - _instance ??= const Webplossy._(); - return _instance; - } - - static Webplossy _instance; -} - -@immutable -class Webplossless extends Format { - const Webplossless._() : super(_Format.Webplossless); - - factory Webplossless() { - _instance ??= const Webplossless._(); - return _instance; - } - - static Webplossless _instance; -} diff --git a/lib/src/image/orientation.dart b/lib/src/image/orientation.dart index bd957dd..951461b 100644 --- a/lib/src/image/orientation.dart +++ b/lib/src/image/orientation.dart @@ -1,22 +1,10 @@ -import 'package:super_enum/super_enum.dart'; -part 'orientation.g.dart'; - -@superEnum -enum _Orientation { - @object +enum Orientation { ToDefault, - @object Horizontally, - @object HorizontallyAndVertically, - @object Vertically, - @object HorizontallyAndRotate90DegreeLeft, - @object Degrees90TowardsRight, - @object HorizontallyAndRotate90DegreesRight, - @object - Rotate90DegreesLeft, + Rotate90DegreesLeft } diff --git a/lib/src/image/orientation.g.dart b/lib/src/image/orientation.g.dart deleted file mode 100644 index 0b9cecf..0000000 --- a/lib/src/image/orientation.g.dart +++ /dev/null @@ -1,399 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'orientation.dart'; - -// ************************************************************************** -// SuperEnumGenerator -// ************************************************************************** - -@immutable -abstract class Orientation extends Equatable { - const Orientation(this._type); - - factory Orientation.toDefault() = ToDefault; - - factory Orientation.horizontally() = Horizontally; - - factory Orientation.horizontallyAndVertically() = HorizontallyAndVertically; - - factory Orientation.vertically() = Vertically; - - factory Orientation.horizontallyAndRotate90DegreeLeft() = - HorizontallyAndRotate90DegreeLeft; - - factory Orientation.degrees90TowardsRight() = Degrees90TowardsRight; - - factory Orientation.horizontallyAndRotate90DegreesRight() = - HorizontallyAndRotate90DegreesRight; - - factory Orientation.rotate90DegreesLeft() = Rotate90DegreesLeft; - - final _Orientation _type; - -//ignore: missing_return - R when( - {@required - R Function(ToDefault) toDefault, - @required - R Function(Horizontally) horizontally, - @required - R Function(HorizontallyAndVertically) horizontallyAndVertically, - @required - R Function(Vertically) vertically, - @required - R Function(HorizontallyAndRotate90DegreeLeft) - horizontallyAndRotate90DegreeLeft, - @required - R Function(Degrees90TowardsRight) degrees90TowardsRight, - @required - R Function(HorizontallyAndRotate90DegreesRight) - horizontallyAndRotate90DegreesRight, - @required - R Function(Rotate90DegreesLeft) rotate90DegreesLeft}) { - assert(() { - if (toDefault == null || - horizontally == null || - horizontallyAndVertically == null || - vertically == null || - horizontallyAndRotate90DegreeLeft == null || - degrees90TowardsRight == null || - horizontallyAndRotate90DegreesRight == null || - rotate90DegreesLeft == null) { - throw 'check for all possible cases'; - } - return true; - }()); - switch (this._type) { - case _Orientation.ToDefault: - return toDefault(this as ToDefault); - case _Orientation.Horizontally: - return horizontally(this as Horizontally); - case _Orientation.HorizontallyAndVertically: - return horizontallyAndVertically(this as HorizontallyAndVertically); - case _Orientation.Vertically: - return vertically(this as Vertically); - case _Orientation.HorizontallyAndRotate90DegreeLeft: - return horizontallyAndRotate90DegreeLeft( - this as HorizontallyAndRotate90DegreeLeft); - case _Orientation.Degrees90TowardsRight: - return degrees90TowardsRight(this as Degrees90TowardsRight); - case _Orientation.HorizontallyAndRotate90DegreesRight: - return horizontallyAndRotate90DegreesRight( - this as HorizontallyAndRotate90DegreesRight); - case _Orientation.Rotate90DegreesLeft: - return rotate90DegreesLeft(this as Rotate90DegreesLeft); - } - } - -//ignore: missing_return - Future asyncWhen( - {@required - FutureOr Function(ToDefault) toDefault, - @required - FutureOr Function(Horizontally) horizontally, - @required - FutureOr Function(HorizontallyAndVertically) - horizontallyAndVertically, - @required - FutureOr Function(Vertically) vertically, - @required - FutureOr Function(HorizontallyAndRotate90DegreeLeft) - horizontallyAndRotate90DegreeLeft, - @required - FutureOr Function(Degrees90TowardsRight) degrees90TowardsRight, - @required - FutureOr Function(HorizontallyAndRotate90DegreesRight) - horizontallyAndRotate90DegreesRight, - @required - FutureOr Function(Rotate90DegreesLeft) rotate90DegreesLeft}) { - assert(() { - if (toDefault == null || - horizontally == null || - horizontallyAndVertically == null || - vertically == null || - horizontallyAndRotate90DegreeLeft == null || - degrees90TowardsRight == null || - horizontallyAndRotate90DegreesRight == null || - rotate90DegreesLeft == null) { - throw 'check for all possible cases'; - } - return true; - }()); - switch (this._type) { - case _Orientation.ToDefault: - return toDefault(this as ToDefault); - case _Orientation.Horizontally: - return horizontally(this as Horizontally); - case _Orientation.HorizontallyAndVertically: - return horizontallyAndVertically(this as HorizontallyAndVertically); - case _Orientation.Vertically: - return vertically(this as Vertically); - case _Orientation.HorizontallyAndRotate90DegreeLeft: - return horizontallyAndRotate90DegreeLeft( - this as HorizontallyAndRotate90DegreeLeft); - case _Orientation.Degrees90TowardsRight: - return degrees90TowardsRight(this as Degrees90TowardsRight); - case _Orientation.HorizontallyAndRotate90DegreesRight: - return horizontallyAndRotate90DegreesRight( - this as HorizontallyAndRotate90DegreesRight); - case _Orientation.Rotate90DegreesLeft: - return rotate90DegreesLeft(this as Rotate90DegreesLeft); - } - } - - R whenOrElse( - {R Function(ToDefault) toDefault, - R Function(Horizontally) horizontally, - R Function(HorizontallyAndVertically) horizontallyAndVertically, - R Function(Vertically) vertically, - R Function(HorizontallyAndRotate90DegreeLeft) - horizontallyAndRotate90DegreeLeft, - R Function(Degrees90TowardsRight) degrees90TowardsRight, - R Function(HorizontallyAndRotate90DegreesRight) - horizontallyAndRotate90DegreesRight, - R Function(Rotate90DegreesLeft) rotate90DegreesLeft, - @required R Function(Orientation) orElse}) { - assert(() { - if (orElse == null) { - throw 'Missing orElse case'; - } - return true; - }()); - switch (this._type) { - case _Orientation.ToDefault: - if (toDefault == null) break; - return toDefault(this as ToDefault); - case _Orientation.Horizontally: - if (horizontally == null) break; - return horizontally(this as Horizontally); - case _Orientation.HorizontallyAndVertically: - if (horizontallyAndVertically == null) break; - return horizontallyAndVertically(this as HorizontallyAndVertically); - case _Orientation.Vertically: - if (vertically == null) break; - return vertically(this as Vertically); - case _Orientation.HorizontallyAndRotate90DegreeLeft: - if (horizontallyAndRotate90DegreeLeft == null) break; - return horizontallyAndRotate90DegreeLeft( - this as HorizontallyAndRotate90DegreeLeft); - case _Orientation.Degrees90TowardsRight: - if (degrees90TowardsRight == null) break; - return degrees90TowardsRight(this as Degrees90TowardsRight); - case _Orientation.HorizontallyAndRotate90DegreesRight: - if (horizontallyAndRotate90DegreesRight == null) break; - return horizontallyAndRotate90DegreesRight( - this as HorizontallyAndRotate90DegreesRight); - case _Orientation.Rotate90DegreesLeft: - if (rotate90DegreesLeft == null) break; - return rotate90DegreesLeft(this as Rotate90DegreesLeft); - } - return orElse(this); - } - - Future asyncWhenOrElse( - {FutureOr Function(ToDefault) toDefault, - FutureOr Function(Horizontally) horizontally, - FutureOr Function(HorizontallyAndVertically) horizontallyAndVertically, - FutureOr Function(Vertically) vertically, - FutureOr Function(HorizontallyAndRotate90DegreeLeft) - horizontallyAndRotate90DegreeLeft, - FutureOr Function(Degrees90TowardsRight) degrees90TowardsRight, - FutureOr Function(HorizontallyAndRotate90DegreesRight) - horizontallyAndRotate90DegreesRight, - FutureOr Function(Rotate90DegreesLeft) rotate90DegreesLeft, - @required FutureOr Function(Orientation) orElse}) { - assert(() { - if (orElse == null) { - throw 'Missing orElse case'; - } - return true; - }()); - switch (this._type) { - case _Orientation.ToDefault: - if (toDefault == null) break; - return toDefault(this as ToDefault); - case _Orientation.Horizontally: - if (horizontally == null) break; - return horizontally(this as Horizontally); - case _Orientation.HorizontallyAndVertically: - if (horizontallyAndVertically == null) break; - return horizontallyAndVertically(this as HorizontallyAndVertically); - case _Orientation.Vertically: - if (vertically == null) break; - return vertically(this as Vertically); - case _Orientation.HorizontallyAndRotate90DegreeLeft: - if (horizontallyAndRotate90DegreeLeft == null) break; - return horizontallyAndRotate90DegreeLeft( - this as HorizontallyAndRotate90DegreeLeft); - case _Orientation.Degrees90TowardsRight: - if (degrees90TowardsRight == null) break; - return degrees90TowardsRight(this as Degrees90TowardsRight); - case _Orientation.HorizontallyAndRotate90DegreesRight: - if (horizontallyAndRotate90DegreesRight == null) break; - return horizontallyAndRotate90DegreesRight( - this as HorizontallyAndRotate90DegreesRight); - case _Orientation.Rotate90DegreesLeft: - if (rotate90DegreesLeft == null) break; - return rotate90DegreesLeft(this as Rotate90DegreesLeft); - } - return orElse(this); - } - -//ignore: missing_return - Future whenPartial( - {FutureOr Function(ToDefault) toDefault, - FutureOr Function(Horizontally) horizontally, - FutureOr Function(HorizontallyAndVertically) - horizontallyAndVertically, - FutureOr Function(Vertically) vertically, - FutureOr Function(HorizontallyAndRotate90DegreeLeft) - horizontallyAndRotate90DegreeLeft, - FutureOr Function(Degrees90TowardsRight) degrees90TowardsRight, - FutureOr Function(HorizontallyAndRotate90DegreesRight) - horizontallyAndRotate90DegreesRight, - FutureOr Function(Rotate90DegreesLeft) rotate90DegreesLeft}) { - assert(() { - if (toDefault == null && - horizontally == null && - horizontallyAndVertically == null && - vertically == null && - horizontallyAndRotate90DegreeLeft == null && - degrees90TowardsRight == null && - horizontallyAndRotate90DegreesRight == null && - rotate90DegreesLeft == null) { - throw 'provide at least one branch'; - } - return true; - }()); - switch (this._type) { - case _Orientation.ToDefault: - if (toDefault == null) break; - return toDefault(this as ToDefault); - case _Orientation.Horizontally: - if (horizontally == null) break; - return horizontally(this as Horizontally); - case _Orientation.HorizontallyAndVertically: - if (horizontallyAndVertically == null) break; - return horizontallyAndVertically(this as HorizontallyAndVertically); - case _Orientation.Vertically: - if (vertically == null) break; - return vertically(this as Vertically); - case _Orientation.HorizontallyAndRotate90DegreeLeft: - if (horizontallyAndRotate90DegreeLeft == null) break; - return horizontallyAndRotate90DegreeLeft( - this as HorizontallyAndRotate90DegreeLeft); - case _Orientation.Degrees90TowardsRight: - if (degrees90TowardsRight == null) break; - return degrees90TowardsRight(this as Degrees90TowardsRight); - case _Orientation.HorizontallyAndRotate90DegreesRight: - if (horizontallyAndRotate90DegreesRight == null) break; - return horizontallyAndRotate90DegreesRight( - this as HorizontallyAndRotate90DegreesRight); - case _Orientation.Rotate90DegreesLeft: - if (rotate90DegreesLeft == null) break; - return rotate90DegreesLeft(this as Rotate90DegreesLeft); - } - } - - @override - List get props => const []; -} - -@immutable -class ToDefault extends Orientation { - const ToDefault._() : super(_Orientation.ToDefault); - - factory ToDefault() { - _instance ??= const ToDefault._(); - return _instance; - } - - static ToDefault _instance; -} - -@immutable -class Horizontally extends Orientation { - const Horizontally._() : super(_Orientation.Horizontally); - - factory Horizontally() { - _instance ??= const Horizontally._(); - return _instance; - } - - static Horizontally _instance; -} - -@immutable -class HorizontallyAndVertically extends Orientation { - const HorizontallyAndVertically._() - : super(_Orientation.HorizontallyAndVertically); - - factory HorizontallyAndVertically() { - _instance ??= const HorizontallyAndVertically._(); - return _instance; - } - - static HorizontallyAndVertically _instance; -} - -@immutable -class Vertically extends Orientation { - const Vertically._() : super(_Orientation.Vertically); - - factory Vertically() { - _instance ??= const Vertically._(); - return _instance; - } - - static Vertically _instance; -} - -@immutable -class HorizontallyAndRotate90DegreeLeft extends Orientation { - const HorizontallyAndRotate90DegreeLeft._() - : super(_Orientation.HorizontallyAndRotate90DegreeLeft); - - factory HorizontallyAndRotate90DegreeLeft() { - _instance ??= const HorizontallyAndRotate90DegreeLeft._(); - return _instance; - } - - static HorizontallyAndRotate90DegreeLeft _instance; -} - -@immutable -class Degrees90TowardsRight extends Orientation { - const Degrees90TowardsRight._() : super(_Orientation.Degrees90TowardsRight); - - factory Degrees90TowardsRight() { - _instance ??= const Degrees90TowardsRight._(); - return _instance; - } - - static Degrees90TowardsRight _instance; -} - -@immutable -class HorizontallyAndRotate90DegreesRight extends Orientation { - const HorizontallyAndRotate90DegreesRight._() - : super(_Orientation.HorizontallyAndRotate90DegreesRight); - - factory HorizontallyAndRotate90DegreesRight() { - _instance ??= const HorizontallyAndRotate90DegreesRight._(); - return _instance; - } - - static HorizontallyAndRotate90DegreesRight _instance; -} - -@immutable -class Rotate90DegreesLeft extends Orientation { - const Rotate90DegreesLeft._() : super(_Orientation.Rotate90DegreesLeft); - - factory Rotate90DegreesLeft() { - _instance ??= const Rotate90DegreesLeft._(); - return _instance; - } - - static Rotate90DegreesLeft _instance; -} diff --git a/lib/src/image_transform.dart b/lib/src/image_transform.dart index 2d514ec..fba0d81 100644 --- a/lib/src/image_transform.dart +++ b/lib/src/image_transform.dart @@ -14,7 +14,7 @@ import 'package:contentstack/src/query_params.dart'; ///Learn more about [ImageTransformation](https://www.contentstack.com/docs/developers/apis/image-delivery-api/) class ImageTransformation { final String _imageUrl; - final HttpClient client; + final HttpClient? client; final Map queryParameter = {}; final URLQueryParams query = URLQueryParams(); @@ -38,7 +38,7 @@ class ImageTransformation { /// await imageTransformation.auto(auto: 'webp', format: 'pjpg').fetch(); /// ``` /// - void auto({String auto, String format}) { + void auto({String? auto, String? format}) { if (auto != null) { query.append('auto', auto); } @@ -203,21 +203,30 @@ class ImageTransformation { /// final response = await imageTransformation.convert(Format.pjpg).fetch(); /// ``` void convert(Format format) { - format.when(gif: (formatResult) { - query.append('format', 'gif'); - }, png: (formatResult) { - query.append('format', 'png'); - }, jpg: (formatResult) { - query.append('format', 'jpg'); - }, pjpg: (formatResult) { - query.append('format', 'pjpg'); - }, webp: (formatResult) { - query.append('format', 'webp'); - }, webplossy: (formatResult) { - query.append('format', 'webply'); - }, webplossless: (formatResult) { - query.append('format', 'webpll'); - }); + + switch(format) { + case Format.Gif: + query.append('format', 'gif'); + break; + case Format.Png: + query.append('format', 'png'); + break; + case Format.Jpg: + query.append('format', 'jpg'); + break; + case Format.Pjpg: + query.append('format', 'pjpg'); + break; + case Format.Webp: + query.append('format', 'webp'); + break; + case Format.Webplossy: + query.append('format', 'webply'); + break; + case Format.Webplossless: + query.append('format', 'webpll'); + break; + } } void crop(String cropValue) { @@ -268,7 +277,7 @@ class ImageTransformation { /// final response = await imageTransformation.cropBy(150, 100).fetch(); /// log.fine(response); /// ``` - void cropBy(int width, int height, {String region, String offset}) { + void cropBy(int width, int height, {String? region, String? offset}) { /// checks if cropRatio is not null then takes height, width and /// cropRatio as prams else it takes crop params and comas /// separated width & height @@ -310,16 +319,16 @@ class ImageTransformation { } ///Makes API Request of respective function. - Future fetch() async { + Future fetch() async { final bool _validURL = Uri.parse(_imageUrl).isAbsolute; if (!_validURL) { throw Exception('Invalid url requested'); } final toURI = Uri.parse(getUrl()); - final response = await client.get(toURI); + final response = await client!.get(toURI); if (response.statusCode == 200) { - final Map bodyJson = jsonDecode(response.body); - if (T == AssetModel && bodyJson.containsKey('asset')) { + final Map? bodyJson = jsonDecode(response.body); + if (T == AssetModel && bodyJson!.containsKey('asset')) { return AssetModel.fromJson(bodyJson['asset']) as T; } else { return json.decode(response.body); @@ -358,11 +367,15 @@ class ImageTransformation { } if (fit != null) { //enum Fit { bounds, crop } - fit.when(bounds: (value) { - query.append('fit', 'bounds'); - }, crop: (value) { - query.append('fit', 'crop'); - }); + + switch(fit) { + case Fit.Bounds: + query.append('fit', 'bounds'); + break; + case Fit.Crop: + query.append('fit', 'crop'); + break; + } } } @@ -417,23 +430,32 @@ class ImageTransformation { // horizontallyAndRotate90DegreesRight = '7'; // rotate90DegreesLeft = '8'; if (orient != null) { - orient.when(toDefault: (orientation) { - query.append('orient', 1); - }, horizontally: (orientation) { - query.append('orient', 2); - }, horizontallyAndVertically: (orientation) { - query.append('orient', 3); - }, vertically: (orientation) { - query.append('orient', 4); - }, horizontallyAndRotate90DegreeLeft: (orientation) { - query.append('orient', 5); - }, degrees90TowardsRight: (orientation) { - query.append('orient', 6); - }, horizontallyAndRotate90DegreesRight: (orientation) { - query.append('orient', 7); - }, rotate90DegreesLeft: (orientation) { - query.append('orient', 8); - }); + switch(orient) { + case Orientation.ToDefault: + query.append('orient', 1); + break; + case Orientation.Horizontally: + query.append('orient', 2); + break; + case Orientation.HorizontallyAndVertically: + query.append('orient', 3); + break; + case Orientation.Vertically: + query.append('orient', 4); + break; + case Orientation.HorizontallyAndRotate90DegreeLeft: + query.append('orient', 5); + break; + case Orientation.Degrees90TowardsRight: + query.append('orient', 6); + break; + case Orientation.HorizontallyAndRotate90DegreesRight: + query.append('orient', 7); + break; + case Orientation.Rotate90DegreesLeft: + query.append('orient', 8); + break; + } } } @@ -461,10 +483,10 @@ class ImageTransformation { /// ``` /// void overlay(String overlayUrl, - {String overlayAlign, - String overlayRepeat, - int overlayWidth, - int overlayHeight}) { + {String? overlayAlign, + String? overlayRepeat, + int? overlayWidth, + int? overlayHeight}) { query.append('overlay', overlayUrl); if (overlayAlign != null) { @@ -571,7 +593,7 @@ class ImageTransformation { /// final response = /// await imageTransformation.resize(width:100,disable:true).fetch(); /// ``` - void resize({int width, int height, bool disable}) { + void resize({int? width, int? height, bool? disable}) { if (width != null) { //queryParameter['width'] = width.toString(); query.append('width', width.toString()); @@ -603,7 +625,7 @@ class ImageTransformation { /// resizeFilter(width: 20, height: 40, filter: Filter.bilinear); /// ``` /// - void resizeFilter({int width, int height, Filter filter}) { + void resizeFilter({int? width, int? height, Filter? filter}) { if (width != null) { query.append('width', width.toString()); } @@ -611,15 +633,20 @@ class ImageTransformation { query.append('height', height.toString()); } if (filter != null) { - filter.when(nearest: (filterType) { - query.append('resize-filter', 'nearest'); - }, bilinear: (filterType) { - query.append('resize-filter', 'bilinear'); - }, bicubic: (filterType) { - query.append('resize-filter', 'bicubic'); - }, lanczos: (filterType) { - query.append('resize-filter', 'lanczos3'); - }); + switch(filter) { + case Filter.Nearest: + query.append('resize-filter', 'nearest'); + break; + case Filter.Bilinear: + query.append('resize-filter', 'bilinear'); + break; + case Filter.Bicubic: + query.append('resize-filter', 'bicubic'); + break; + case Filter.Lanczos: + query.append('resize-filter', 'lanczos3'); + break; + } } } @@ -680,7 +707,7 @@ class ImageTransformation { /// final imageTransformation = stack.imageTransform(imageUrl); /// final response = await imageTransformation.trim(25).fetch(); /// ``` - void trim([int top, int right, int bottom, int left]) { + void trim([int? top, int? right, int? bottom, int? left]) { final trimLRBL = []; if (top != null) { trimLRBL.add(top); diff --git a/lib/src/models/assetmodel.dart b/lib/src/models/assetmodel.dart index cd4f885..9c81e9c 100644 --- a/lib/src/models/assetmodel.dart +++ b/lib/src/models/assetmodel.dart @@ -4,28 +4,28 @@ part 'assetmodel.g.dart'; /// AssetModel refers to the generic class for asset result @JsonSerializable(createFactory: true) class AssetModel { - String uid; + String? uid; @JsonKey(name: 'created_at') - String createdAt; + String? createdAt; @JsonKey(name: 'updated_at') - String updatedAt; + String? updatedAt; @JsonKey(name: 'created_by') - String createdBy; + String? createdBy; @JsonKey(name: 'updated_by') - String updatedBy; + String? updatedBy; @JsonKey(name: 'content_type') - String contentType; + String? contentType; @JsonKey(name: 'file_size') - String fileSize; - List tags; - String filename; - String url; + String? fileSize; + List? tags; + String? filename; + String? url; @JsonKey(name: '_version') - int version; - String title; - Map dimension; + int? version; + String? title; + Map? dimension; @JsonKey(name: 'publish_details') - Map publishDetails; + Map? publishDetails; AssetModel( this.uid, this.createdAt, diff --git a/lib/src/models/assetmodel.g.dart b/lib/src/models/assetmodel.g.dart index f8d56f2..02c1836 100644 --- a/lib/src/models/assetmodel.g.dart +++ b/lib/src/models/assetmodel.g.dart @@ -8,20 +8,20 @@ part of 'assetmodel.dart'; AssetModel _$AssetModelFromJson(Map json) { return AssetModel( - json['uid'] as String, - json['created_at'] as String, - json['updated_at'] as String, - json['created_by'] as String, - json['updated_by'] as String, - json['content_type'] as String, - json['file_size'] as String, - json['tags'] as List, - json['filename'] as String, - json['url'] as String, - json['_version'] as int, - json['title'] as String, - json['dimension'] as Map, - json['publish_details'] as Map, + json['uid'] as String?, + json['created_at'] as String?, + json['updated_at'] as String?, + json['created_by'] as String?, + json['updated_by'] as String?, + json['content_type'] as String?, + json['file_size'] as String?, + json['tags'] as List?, + json['filename'] as String?, + json['url'] as String?, + json['_version'] as int?, + json['title'] as String?, + json['dimension'] as Map?, + json['publish_details'] as Map?, ); } diff --git a/lib/src/models/entrymodel.dart b/lib/src/models/entrymodel.dart index 6628be9..b9b946a 100644 --- a/lib/src/models/entrymodel.dart +++ b/lib/src/models/entrymodel.dart @@ -5,23 +5,23 @@ part 'entrymodel.g.dart'; /// EntryModel refers to the generic class for entry result @JsonSerializable(createFactory: true) class EntryModel { - String locale; - String title; - String url; - String description; - List categories; - List tags; - String uid; + String? locale; + String? title; + String? url; + String? description; + List? categories; + List? tags; + String? uid; @JsonKey(name: 'created_by') - String createdBy; + String? createdBy; @JsonKey(name: 'updated_by') - String updatedBy; + String? updatedBy; @JsonKey(name: 'created_at') - String createdAt; + String? createdAt; @JsonKey(name: 'updated_at') - String updatedAt; + String? updatedAt; @JsonKey(name: '_version') - int version; + int? version; EntryModel( this.locale, this.title, diff --git a/lib/src/models/entrymodel.g.dart b/lib/src/models/entrymodel.g.dart index 17eea28..b23b185 100644 --- a/lib/src/models/entrymodel.g.dart +++ b/lib/src/models/entrymodel.g.dart @@ -8,18 +8,18 @@ part of 'entrymodel.dart'; EntryModel _$EntryModelFromJson(Map json) { return EntryModel( - json['locale'] as String, - json['title'] as String, - json['url'] as String, - json['description'] as String, - json['categories'] as List, - json['tags'] as List, - json['uid'] as String, - json['created_by'] as String, - json['updated_by'] as String, - json['created_at'] as String, - json['updated_at'] as String, - json['_version'] as int, + json['locale'] as String?, + json['title'] as String?, + json['url'] as String?, + json['description'] as String?, + json['categories'] as List?, + json['tags'] as List?, + json['uid'] as String?, + json['created_by'] as String?, + json['updated_by'] as String?, + json['created_at'] as String?, + json['updated_at'] as String?, + json['_version'] as int?, ); } diff --git a/lib/src/models/syncresult.dart b/lib/src/models/syncresult.dart index b27fca8..9d50440 100644 --- a/lib/src/models/syncresult.dart +++ b/lib/src/models/syncresult.dart @@ -5,25 +5,25 @@ part 'syncresult.g.dart'; @JsonSerializable(createFactory: true) class SyncResult { /// list of items available in sync result - final List items; + final List? items; /// skip count in sync result - final int skip; + final int? skip; /// limit for result items in sync result - final int limit; + final int? limit; /// Total items count in sync result @JsonKey(name: 'total_count') - final int totalCount; + final int? totalCount; /// Sync Token for the sync result @JsonKey(name: 'sync_token') - final String syncToken; + final String? syncToken; /// Pagination Token for the sync result @JsonKey(name: 'pagination_token') - final String paginationToken; + final String? paginationToken; SyncResult(this.items, this.skip, this.limit, this.totalCount, this.syncToken, this.paginationToken); factory SyncResult.fromJson(Map json) => @@ -34,10 +34,10 @@ class SyncResult { /// Total items available in sync result @JsonSerializable() class Items { - final String type; - final String eventAt; - final String contentTypeUid; - final List data; + final String? type; + final String? eventAt; + final String? contentTypeUid; + final List? data; Items(this.type, this.eventAt, this.contentTypeUid, this.data); factory Items.fromJson(Map json) => _$ItemsFromJson(json); Map toJson() => _$ItemsToJson(this); @@ -46,9 +46,9 @@ class Items { /// Data inside sync result's items that contains uid, locale, title etc @JsonSerializable() class Data { - final String uid; - final String locale; - final String title; + final String? uid; + final String? locale; + final String? title; Data(this.uid, this.locale, this.title); factory Data.fromJson(Map json) => _$DataFromJson(json); Map toJson() => _$DataToJson(this); diff --git a/lib/src/models/syncresult.g.dart b/lib/src/models/syncresult.g.dart index 36e7ba6..9f20320 100644 --- a/lib/src/models/syncresult.g.dart +++ b/lib/src/models/syncresult.g.dart @@ -8,12 +8,12 @@ part of 'syncresult.dart'; SyncResult _$SyncResultFromJson(Map json) { return SyncResult( - json['items'] as List, - json['skip'] as int, - json['limit'] as int, - json['total_count'] as int, - json['sync_token'] as String, - json['pagination_token'] as String, + json['items'] as List?, + json['skip'] as int?, + json['limit'] as int?, + json['total_count'] as int?, + json['sync_token'] as String?, + json['pagination_token'] as String?, ); } @@ -29,10 +29,10 @@ Map _$SyncResultToJson(SyncResult instance) => Items _$ItemsFromJson(Map json) { return Items( - json['type'] as String, - json['eventAt'] as String, - json['contentTypeUid'] as String, - json['data'] as List, + json['type'] as String?, + json['eventAt'] as String?, + json['contentTypeUid'] as String?, + json['data'] as List?, ); } @@ -45,9 +45,9 @@ Map _$ItemsToJson(Items instance) => { Data _$DataFromJson(Map json) { return Data( - json['uid'] as String, - json['locale'] as String, - json['title'] as String, + json['uid'] as String?, + json['locale'] as String?, + json['title'] as String?, ); } diff --git a/lib/src/query.dart b/lib/src/query.dart index 0c4f3ad..359e689 100644 --- a/lib/src/query.dart +++ b/lib/src/query.dart @@ -1,26 +1,31 @@ +// ignore_for_file: unnecessary_null_comparison + import 'dart:async'; import 'dart:convert'; import 'package:contentstack/client.dart'; import 'package:contentstack/constant.dart'; import 'package:contentstack/src/base_query.dart'; -import 'package:contentstack/src/enums/include.dart' as include; +import 'package:contentstack/src/enums/include.dart'; +import 'package:contentstack/src/enums/include_type.dart'; import 'package:contentstack/src/enums/operator.dart'; +import 'package:contentstack/src/enums/operator_type.dart'; import 'package:contentstack/src/enums/reference.dart'; +import 'package:contentstack/src/enums/reference_type.dart'; /// Contentstack provides certain queries that you /// can use to fetch filtered results. /// You can use queries for Entries and Assets API requests. /// Learn more about [Query](https://www.contentstack.com/docs/developers/apis/content-delivery-api/#queries) class Query extends BaseQuery { - final HttpClient _client; - final String _contentTypeUid; - String _path; + final HttpClient? _client; + final String? _contentTypeUid; + late String _path; Query([this._client, this._contentTypeUid]) { - queryParameter['environment'] = _client.stackHeaders['environment']; + queryParameter['environment'] = _client!.stackHeaders!['environment']; _path = - '/${_client.stack.apiVersion}/content_types/$_contentTypeUid/entries'; + '/${_client!.stack!.apiVersion}/content_types/$_contentTypeUid/entries'; } /// @@ -67,20 +72,20 @@ class Query extends BaseQuery { } } - Future find() async { + Future find() async { getQueryUrl(); - final preview = _client.stack.livePreview; + final preview = _client!.stack!.livePreview; if (preview != null && preview.isNotEmpty) { __validateLivePreview(preview); } - final uri = Uri.https(_client.stack.endpoint, _path, queryParameter); - return _client.sendRequest(uri); + final uri = Uri.https(_client!.stack!.endpoint!, _path, queryParameter); + return _client!.sendRequest(uri); } void __validateLivePreview(preview) { if (preview != null && preview['enable']) { - ifLivePreviewEnable(_client); + ifLivePreviewEnable(_client!); if (_contentTypeUid == preview['content_type_uid']) { parameter['live_preview'] = 'init'; if (preview.containsKey('live_preview') && @@ -198,44 +203,49 @@ class Query extends BaseQuery { /// ``` /// void includeReference(String referenceFieldUid, - {include.Include includeReferenceField}) { + {IncludeClass? includeReferenceField}) { if (referenceFieldUid != null && referenceFieldUid.isNotEmpty) { final List referenceArray = []; if (includeReferenceField != null) { - includeReferenceField.when(none: (fieldUid) { - referenceArray.add(referenceFieldUid); - if (fieldUid.fieldUidList != null && - fieldUid.fieldUidList.isNotEmpty) { - for (final item in fieldUid.fieldUidList) { - referenceArray.add(item); + + switch(includeReferenceField.includeType) { + case IncludeType.None: + referenceArray.add(referenceFieldUid); + if (includeReferenceField.fieldUidList != null && + includeReferenceField.fieldUidList.isNotEmpty) { + for (final item in includeReferenceField.fieldUidList) { + referenceArray.add(item); + } } - } - queryParameter['include[]'] = referenceArray.toString(); - }, only: (fieldUid) { - final Map referenceOnlyParam = {}; - if (fieldUid.fieldUidList != null && - fieldUid.fieldUidList.isNotEmpty) { - for (final item in fieldUid.fieldUidList) { - referenceArray.add(item); + queryParameter['include[]'] = referenceArray.toString(); + break; + case IncludeType.Only: + final Map referenceOnlyParam = {}; + if (includeReferenceField.fieldUidList != null && + includeReferenceField.fieldUidList.isNotEmpty) { + for (final item in includeReferenceField.fieldUidList) { + referenceArray.add(item); + } } - } - referenceOnlyParam[referenceFieldUid] = referenceArray; - //_include(referenceFieldUid); - includeReference(referenceFieldUid); - queryParameter['only'] = referenceOnlyParam.toString(); - }, except: (fieldUid) { - final Map referenceOnlyParam = {}; - if (fieldUid.fieldUidList != null && - fieldUid.fieldUidList.isNotEmpty) { - for (final item in fieldUid.fieldUidList) { - referenceArray.add(item); + referenceOnlyParam[referenceFieldUid] = referenceArray; + //_include(referenceFieldUid); + includeReference(referenceFieldUid); + queryParameter['only'] = referenceOnlyParam.toString(); + break; + case IncludeType.Except: + final Map referenceOnlyParam = {}; + if (includeReferenceField.fieldUidList != null && + includeReferenceField.fieldUidList.isNotEmpty) { + for (final item in includeReferenceField.fieldUidList) { + referenceArray.add(item); + } } - } - referenceOnlyParam[referenceFieldUid] = referenceArray; - //_include(referenceFieldUid); - includeReference(referenceFieldUid); - queryParameter['except'] = referenceOnlyParam.toString(); - }); + referenceOnlyParam[referenceFieldUid] = referenceArray; + //_include(referenceFieldUid); + includeReference(referenceFieldUid); + queryParameter['except'] = referenceOnlyParam.toString(); + break; + } } else { queryParameter['include[]'] = referenceFieldUid; } @@ -357,27 +367,30 @@ class Query extends BaseQuery { /// ``` /// void operator(QueryOperator operator) { - operator.when(and: (and) { - final List queryList = - and.queryObjects; //and.queryObjects is list of Query Objects - if (queryList.isNotEmpty) { - final emptyList = []; - for (final item in queryList) { - emptyList.add(item.parameter); + switch(operator.operatorType) { + case QueryOperatorType.And: + final List queryList = + operator.queryObjects; //and.queryObjects is list of Query Objects + if (queryList.isNotEmpty) { + final emptyList = []; + for (final item in queryList) { + emptyList.add(item.parameter); + } + parameter['\$and'] = emptyList; } - parameter['\$and'] = emptyList; - } - }, or: (or) { - final List queryList = - or.queryObjects; //and.queryObjects is list of Query Objects - if (queryList.isNotEmpty) { - final emptyList = []; - for (final item in queryList) { - emptyList.add(item.parameter); + break; + case QueryOperatorType.Or: + final List queryList = + operator.queryObjects; //and.queryObjects is list of Query Objects + if (queryList.isNotEmpty) { + final emptyList = []; + for (final item in queryList) { + emptyList.add(item.parameter); + } + parameter['\$or'] = emptyList; } - parameter['\$or'] = emptyList; - } - }); + break; + } } /// @@ -393,8 +406,8 @@ class Query extends BaseQuery { /// ``` /// void removeHeader(String key) { - if (_client.stackHeaders.containsKey(key)) { - _client.stackHeaders.remove(key); + if (_client!.stackHeaders!.containsKey(key)) { + _client!.stackHeaders!.remove(key); } } @@ -414,7 +427,7 @@ class Query extends BaseQuery { /// void setHeader(String key, String value) { if (key.isNotEmpty && value.isNotEmpty) { - _client.stackHeaders[key] = value; + _client!.stackHeaders![key] = value; } } @@ -446,13 +459,16 @@ class Query extends BaseQuery { /// void whereReference(String referenceUid, QueryReference reference) { if (referenceUid != null && referenceUid.isNotEmpty) { - reference.when(include: (queryInstance) { - parameter[referenceUid] = {'\$in_query': queryInstance.query.parameter}; - }, notInclude: (queryInstance) { - parameter[referenceUid] = { - '\$nin_query': queryInstance.query.parameter - }; - }); + switch(reference.referenceType) { + case QueryReferenceType.Include: + parameter[referenceUid] = {'\$in_query': reference.query.parameter}; + break; + case QueryReferenceType.NotInclude: + parameter[referenceUid] = { + '\$nin_query': reference.query.parameter + }; + break; + } } } diff --git a/lib/src/stack.dart b/lib/src/stack.dart index 9209e26..6ca786e 100644 --- a/lib/src/stack.dart +++ b/lib/src/stack.dart @@ -17,16 +17,16 @@ enum Region { us, eu, azure_na, gcp_na } /// A stack is like a container that holds the content of your app. /// Learn more about [Stacks](https://www.contentstack.com/docs/developers/set-up-stack/about-stack/). class Stack { - Map headers = {}; + Map? headers = {}; final String _apiKey; final String _deliveryToken; final String _environment; - String _host; - final String branch; + String? _host; + final String? branch; final Region region; final String apiVersion; - Map livePreview; - HttpClient _client; + Map? livePreview; + HttpClient? _client; /// /// Create a new Stack instance with stack's apikey, token, @@ -66,8 +66,8 @@ class Stack { this.apiVersion = 'v3', this.region = Region.us, this.branch, - String host = 'cdn.contentstack.io', - BaseClient client, + String? host = 'cdn.contentstack.io', + BaseClient? client, this.livePreview, }) : _host = (region == Region.us) ? host @@ -100,10 +100,10 @@ class Stack { 'environment': _environment, }; - if (branch != null && branch.isNotEmpty) { - headers['branch'] = branch; + if (branch != null && branch!.isNotEmpty) { + headers?['branch'] = branch!; } - if (livePreview != null && livePreview.isNotEmpty) { + if (livePreview != null && livePreview!.isNotEmpty) { __validateLivePreview(); } _client = HttpClient(headers, client: client, stack: this); @@ -136,7 +136,7 @@ class Stack { /// final stack = contentstack.Stack(apiKey, deliveryToken, environment); /// var environment = stack.environment; /// ``` - String get endpoint => host; + String? get endpoint => host; /// It returns delivery token of the Environment /// @@ -156,7 +156,7 @@ class Stack { /// final stack = contentstack.Stack(apiKey, deliveryToken, environment); /// var environment = stack.environment; /// ``` - String get host => _host; + String? get host => _host; /// It returns livePreview variables /// @@ -166,18 +166,18 @@ class Stack { /// final stack = contentstack.Stack(apiKey, deliveryToken, environment); /// var environment = stack.livePreview; /// ``` - Map get getLivePreview => livePreview; + Map? get getLivePreview => livePreview; /// /// Validates the livePreview /// void __validateLivePreview() { - if (livePreview.containsKey('enable')) { - if (!livePreview.containsKey('authorization') || - livePreview['authorization'].toString().isEmpty) { + if (livePreview!.containsKey('enable')) { + if (!livePreview!.containsKey('authorization') || + livePreview!['authorization'].toString().isEmpty) { throw Exception('Authorization is required to enable live preview'); - } else if (!livePreview.containsKey('host') || - livePreview['host'].toString().isEmpty) { + } else if (!livePreview!.containsKey('host') || + livePreview!['host'].toString().isEmpty) { throw Exception('Host is required to enable live preview'); } } @@ -196,8 +196,8 @@ class Stack { /// var stack = contentstack.Stack(apiKey, deliveryToken, environment); /// var asset = stack.asset('uid'); /// ``` - Asset asset(String uid) { - return Asset(uid, _client); + Asset asset(String? uid) { + return Asset(uid, _client!); } /// @@ -215,7 +215,7 @@ class Stack { /// ``` /// AssetQuery assetQuery() { - return AssetQuery(_client); + return AssetQuery(_client!); } /// @@ -231,8 +231,8 @@ class Stack { /// var contentType = stack.contentType('content_type_id'); /// ``` /// - ContentType contentType([String contentTypeId]) { - return ContentType(contentTypeId, _client); + ContentType contentType([String? contentTypeId]) { + return ContentType(contentTypeId, _client!); } /// @@ -250,9 +250,9 @@ class Stack { /// response = stack.getContentTypes(queryParameters); /// ``` /// - Future getContentTypes(Map queryParameters) { - final Uri uri = Uri.https(endpoint, '$apiVersion/content_types'); - return _client.sendRequest(uri); + Future getContentTypes(Map queryParameters) { + final Uri uri = Uri.https(endpoint!, '$apiVersion/content_types'); + return _client!.sendRequest(uri); } /// @@ -291,7 +291,7 @@ class Stack { /// this token can be used to restart the sync /// process from where it was interrupted. /// - Future paginationToken(String paginationToken) { + Future paginationToken(String? paginationToken) { final parameters = {}; if (paginationToken != null && paginationToken.isNotEmpty) { parameters['pagination_token'] = paginationToken; @@ -311,8 +311,8 @@ class Stack { /// ``` void removeHeader(String headerKey) { if (headerKey != null) { - if (headers.containsKey(headerKey)) { - headers.remove(headerKey); + if (headers!.containsKey(headerKey)) { + headers!.remove(headerKey); } } } @@ -325,9 +325,9 @@ class Stack { /// final stack = contentstack.Stack(apiKey, deliveryToken, environment); /// stack = stack..setHeader('headerKey', 'headervalue'); /// ``` - void setHeader(String key, String value) { - if (key.isNotEmpty && value.isNotEmpty) { - headers[key] = value; + void setHeader(String key, String? value) { + if (key.isNotEmpty && value!.isNotEmpty) { + headers![key] = value; } } @@ -372,11 +372,11 @@ class Stack { /// /// Returns: List Of [SyncResult] /// - Future sync( - {String contentTypeUid, - String fromDate, - String locale, - PublishType publishType}) async { + Future sync( + {String? contentTypeUid, + String? fromDate, + String? locale, + PublishType? publishType}) async { final parameter = {}; parameter['init'] = 'true'; if (contentTypeUid != null && contentTypeUid.isNotEmpty) { @@ -389,21 +389,29 @@ class Stack { parameter['locale'] = locale; } if (publishType != null) { - publishType.when(assetPublished: (result) { - parameter['publish_type'] = 'asset_published'; - }, entryPublished: (result) { - parameter['publish_type'] = 'entry_published'; - }, assetUnpublished: (result) { - parameter['publish_type'] = 'asset_unpublished'; - }, assetDeleted: (result) { - parameter['publish_type'] = 'asset_deleted'; - }, entryUnpublished: (result) { - parameter['publish_type'] = 'entry_unpublished'; - }, entryDeleted: (result) { - parameter['publish_type'] = 'entry_deleted'; - }, contentTypeDeleted: (result) { - parameter['publish_type'] = 'content_type_deleted'; - }); + switch(publishType) { + case PublishType.AssetPublished: + parameter['publish_type'] = 'asset_published'; + break; + case PublishType.EntryPublished: + parameter['publish_type'] = 'entry_published'; + break; + case PublishType.AssetUnpublished: + parameter['publish_type'] = 'asset_unpublished'; + break; + case PublishType.AssetDeleted: + parameter['publish_type'] = 'asset_deleted'; + break; + case PublishType.EntryUnpublished: + parameter['publish_type'] = 'entry_unpublished'; + break; + case PublishType.EntryDeleted: + parameter['publish_type'] = 'entry_deleted'; + break; + case PublishType.ContentTypeDeleted: + parameter['publish_type'] = 'content_type_deleted'; + break; + } } return _syncRequest(parameter); @@ -416,26 +424,26 @@ class Stack { /// and the details of the content that was deleted or updated. /// /// - Future syncToken(String syncToken) { - final parameters = {}; + Future syncToken(String? syncToken) { + final parameters = {}; if (syncToken != null && syncToken.isNotEmpty) { parameters['sync_token'] = syncToken; } - parameters['environment'] = _client.stackHeaders['environment']; - final Uri uri = Uri.https(endpoint, '$apiVersion/stacks/sync', parameters); - return _client.sendRequest(uri); + parameters['environment'] = _client!.stackHeaders!['environment']; + final Uri uri = Uri.https(endpoint!, '$apiVersion/stacks/sync', parameters); + return _client!.sendRequest(uri); } - Future _syncRequest(parameters) async { - parameters['environment'] = _client.stackHeaders['environment']; - final Uri uri = Uri.https(endpoint, '$apiVersion/stacks/sync', parameters); - return _client.sendRequest(uri); + Future _syncRequest(parameters) async { + parameters['environment'] = _client!.stackHeaders!['environment']; + final Uri uri = Uri.https(endpoint!, '$apiVersion/stacks/sync', parameters); + return _client!.sendRequest(uri); } void livePreviewQuery(Map livePreviewQuery) { - if (livePreview.containsKey('enable')) { - final bool enable = livePreview['enable'] as bool; + if (livePreview!.containsKey('enable')) { + final bool enable = livePreview!['enable'] as bool; if (enable) { if (livePreviewQuery.containsKey('content_type_uid') && livePreviewQuery['content_type_uid'] != null) { @@ -452,14 +460,14 @@ class Stack { var _url = "https://$host}/${this.apiVersion}/content_types/$content_type_uid/entries/$entry_uid"; var _headers = { - 'authorization': headers['authorization'], - 'api_key': headers['api_key'], + 'authorization': headers!['authorization']!, + 'api_key': headers!['api_key']!, }; await http.get(Uri.parse(_url), headers: _headers).then((response) { Map bodyJson = json.decode(utf8.decode(response.bodyBytes)); print(bodyJson); - livePreview["entry"] = bodyJson['entry']; + livePreview!["entry"] = bodyJson['entry']; }); } @@ -489,18 +497,18 @@ class Stack { /// var response = stack.globalField('sso', true); /// ``` - Future globalField( - [String globalFieldUid, bool includeBranch = false]) { + Future globalField( + [String? globalFieldUid, bool includeBranch = false]) { final parameters = {}; - parameters['environment'] = _client.stackHeaders['environment']; + parameters['environment'] = _client!.stackHeaders!['environment']!; if (includeBranch) { parameters['include_branch'] = true.toString(); } - Uri uri = Uri.https(endpoint, '$apiVersion/global_fields', parameters); + Uri uri = Uri.https(endpoint!, '$apiVersion/global_fields', parameters); if (globalFieldUid != null && globalFieldUid.isNotEmpty) { uri = Uri.https( - endpoint, '$apiVersion/global_fields/$globalFieldUid', parameters); + endpoint!, '$apiVersion/global_fields/$globalFieldUid', parameters); } - return _client.sendRequest(uri); + return _client!.sendRequest(uri); } } diff --git a/lib/src/sync/publishtype.dart b/lib/src/sync/publishtype.dart index 26bbcb8..f31a267 100644 --- a/lib/src/sync/publishtype.dart +++ b/lib/src/sync/publishtype.dart @@ -1,20 +1,9 @@ -import 'package:super_enum/super_enum.dart'; -part 'publishtype.g.dart'; - -@superEnum -enum _PublishType { - @object +enum PublishType { AssetPublished, - @object EntryPublished, - @object AssetUnpublished, - @object AssetDeleted, - @object EntryUnpublished, - @object EntryDeleted, - @object - ContentTypeDeleted, + ContentTypeDeleted } diff --git a/lib/src/sync/publishtype.g.dart b/lib/src/sync/publishtype.g.dart deleted file mode 100644 index 1c6f5e8..0000000 --- a/lib/src/sync/publishtype.g.dart +++ /dev/null @@ -1,321 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'publishtype.dart'; - -// ************************************************************************** -// SuperEnumGenerator -// ************************************************************************** - -@immutable -abstract class PublishType extends Equatable { - const PublishType(this._type); - - factory PublishType.assetPublished() = AssetPublished; - - factory PublishType.entryPublished() = EntryPublished; - - factory PublishType.assetUnpublished() = AssetUnpublished; - - factory PublishType.assetDeleted() = AssetDeleted; - - factory PublishType.entryUnpublished() = EntryUnpublished; - - factory PublishType.entryDeleted() = EntryDeleted; - - factory PublishType.contentTypeDeleted() = ContentTypeDeleted; - - final _PublishType _type; - -//ignore: missing_return - R when( - {@required R Function(AssetPublished) assetPublished, - @required R Function(EntryPublished) entryPublished, - @required R Function(AssetUnpublished) assetUnpublished, - @required R Function(AssetDeleted) assetDeleted, - @required R Function(EntryUnpublished) entryUnpublished, - @required R Function(EntryDeleted) entryDeleted, - @required R Function(ContentTypeDeleted) contentTypeDeleted}) { - assert(() { - if (assetPublished == null || - entryPublished == null || - assetUnpublished == null || - assetDeleted == null || - entryUnpublished == null || - entryDeleted == null || - contentTypeDeleted == null) { - throw 'check for all possible cases'; - } - return true; - }()); - switch (this._type) { - case _PublishType.AssetPublished: - return assetPublished(this as AssetPublished); - case _PublishType.EntryPublished: - return entryPublished(this as EntryPublished); - case _PublishType.AssetUnpublished: - return assetUnpublished(this as AssetUnpublished); - case _PublishType.AssetDeleted: - return assetDeleted(this as AssetDeleted); - case _PublishType.EntryUnpublished: - return entryUnpublished(this as EntryUnpublished); - case _PublishType.EntryDeleted: - return entryDeleted(this as EntryDeleted); - case _PublishType.ContentTypeDeleted: - return contentTypeDeleted(this as ContentTypeDeleted); - } - } - -//ignore: missing_return - Future asyncWhen( - {@required FutureOr Function(AssetPublished) assetPublished, - @required FutureOr Function(EntryPublished) entryPublished, - @required FutureOr Function(AssetUnpublished) assetUnpublished, - @required FutureOr Function(AssetDeleted) assetDeleted, - @required FutureOr Function(EntryUnpublished) entryUnpublished, - @required FutureOr Function(EntryDeleted) entryDeleted, - @required FutureOr Function(ContentTypeDeleted) contentTypeDeleted}) { - assert(() { - if (assetPublished == null || - entryPublished == null || - assetUnpublished == null || - assetDeleted == null || - entryUnpublished == null || - entryDeleted == null || - contentTypeDeleted == null) { - throw 'check for all possible cases'; - } - return true; - }()); - switch (this._type) { - case _PublishType.AssetPublished: - return assetPublished(this as AssetPublished); - case _PublishType.EntryPublished: - return entryPublished(this as EntryPublished); - case _PublishType.AssetUnpublished: - return assetUnpublished(this as AssetUnpublished); - case _PublishType.AssetDeleted: - return assetDeleted(this as AssetDeleted); - case _PublishType.EntryUnpublished: - return entryUnpublished(this as EntryUnpublished); - case _PublishType.EntryDeleted: - return entryDeleted(this as EntryDeleted); - case _PublishType.ContentTypeDeleted: - return contentTypeDeleted(this as ContentTypeDeleted); - } - } - - R whenOrElse( - {R Function(AssetPublished) assetPublished, - R Function(EntryPublished) entryPublished, - R Function(AssetUnpublished) assetUnpublished, - R Function(AssetDeleted) assetDeleted, - R Function(EntryUnpublished) entryUnpublished, - R Function(EntryDeleted) entryDeleted, - R Function(ContentTypeDeleted) contentTypeDeleted, - @required R Function(PublishType) orElse}) { - assert(() { - if (orElse == null) { - throw 'Missing orElse case'; - } - return true; - }()); - switch (this._type) { - case _PublishType.AssetPublished: - if (assetPublished == null) break; - return assetPublished(this as AssetPublished); - case _PublishType.EntryPublished: - if (entryPublished == null) break; - return entryPublished(this as EntryPublished); - case _PublishType.AssetUnpublished: - if (assetUnpublished == null) break; - return assetUnpublished(this as AssetUnpublished); - case _PublishType.AssetDeleted: - if (assetDeleted == null) break; - return assetDeleted(this as AssetDeleted); - case _PublishType.EntryUnpublished: - if (entryUnpublished == null) break; - return entryUnpublished(this as EntryUnpublished); - case _PublishType.EntryDeleted: - if (entryDeleted == null) break; - return entryDeleted(this as EntryDeleted); - case _PublishType.ContentTypeDeleted: - if (contentTypeDeleted == null) break; - return contentTypeDeleted(this as ContentTypeDeleted); - } - return orElse(this); - } - - Future asyncWhenOrElse( - {FutureOr Function(AssetPublished) assetPublished, - FutureOr Function(EntryPublished) entryPublished, - FutureOr Function(AssetUnpublished) assetUnpublished, - FutureOr Function(AssetDeleted) assetDeleted, - FutureOr Function(EntryUnpublished) entryUnpublished, - FutureOr Function(EntryDeleted) entryDeleted, - FutureOr Function(ContentTypeDeleted) contentTypeDeleted, - @required FutureOr Function(PublishType) orElse}) { - assert(() { - if (orElse == null) { - throw 'Missing orElse case'; - } - return true; - }()); - switch (this._type) { - case _PublishType.AssetPublished: - if (assetPublished == null) break; - return assetPublished(this as AssetPublished); - case _PublishType.EntryPublished: - if (entryPublished == null) break; - return entryPublished(this as EntryPublished); - case _PublishType.AssetUnpublished: - if (assetUnpublished == null) break; - return assetUnpublished(this as AssetUnpublished); - case _PublishType.AssetDeleted: - if (assetDeleted == null) break; - return assetDeleted(this as AssetDeleted); - case _PublishType.EntryUnpublished: - if (entryUnpublished == null) break; - return entryUnpublished(this as EntryUnpublished); - case _PublishType.EntryDeleted: - if (entryDeleted == null) break; - return entryDeleted(this as EntryDeleted); - case _PublishType.ContentTypeDeleted: - if (contentTypeDeleted == null) break; - return contentTypeDeleted(this as ContentTypeDeleted); - } - return orElse(this); - } - -//ignore: missing_return - Future whenPartial( - {FutureOr Function(AssetPublished) assetPublished, - FutureOr Function(EntryPublished) entryPublished, - FutureOr Function(AssetUnpublished) assetUnpublished, - FutureOr Function(AssetDeleted) assetDeleted, - FutureOr Function(EntryUnpublished) entryUnpublished, - FutureOr Function(EntryDeleted) entryDeleted, - FutureOr Function(ContentTypeDeleted) contentTypeDeleted}) { - assert(() { - if (assetPublished == null && - entryPublished == null && - assetUnpublished == null && - assetDeleted == null && - entryUnpublished == null && - entryDeleted == null && - contentTypeDeleted == null) { - throw 'provide at least one branch'; - } - return true; - }()); - switch (this._type) { - case _PublishType.AssetPublished: - if (assetPublished == null) break; - return assetPublished(this as AssetPublished); - case _PublishType.EntryPublished: - if (entryPublished == null) break; - return entryPublished(this as EntryPublished); - case _PublishType.AssetUnpublished: - if (assetUnpublished == null) break; - return assetUnpublished(this as AssetUnpublished); - case _PublishType.AssetDeleted: - if (assetDeleted == null) break; - return assetDeleted(this as AssetDeleted); - case _PublishType.EntryUnpublished: - if (entryUnpublished == null) break; - return entryUnpublished(this as EntryUnpublished); - case _PublishType.EntryDeleted: - if (entryDeleted == null) break; - return entryDeleted(this as EntryDeleted); - case _PublishType.ContentTypeDeleted: - if (contentTypeDeleted == null) break; - return contentTypeDeleted(this as ContentTypeDeleted); - } - } - - @override - List get props => const []; -} - -@immutable -class AssetPublished extends PublishType { - const AssetPublished._() : super(_PublishType.AssetPublished); - - factory AssetPublished() { - _instance ??= const AssetPublished._(); - return _instance; - } - - static AssetPublished _instance; -} - -@immutable -class EntryPublished extends PublishType { - const EntryPublished._() : super(_PublishType.EntryPublished); - - factory EntryPublished() { - _instance ??= const EntryPublished._(); - return _instance; - } - - static EntryPublished _instance; -} - -@immutable -class AssetUnpublished extends PublishType { - const AssetUnpublished._() : super(_PublishType.AssetUnpublished); - - factory AssetUnpublished() { - _instance ??= const AssetUnpublished._(); - return _instance; - } - - static AssetUnpublished _instance; -} - -@immutable -class AssetDeleted extends PublishType { - const AssetDeleted._() : super(_PublishType.AssetDeleted); - - factory AssetDeleted() { - _instance ??= const AssetDeleted._(); - return _instance; - } - - static AssetDeleted _instance; -} - -@immutable -class EntryUnpublished extends PublishType { - const EntryUnpublished._() : super(_PublishType.EntryUnpublished); - - factory EntryUnpublished() { - _instance ??= const EntryUnpublished._(); - return _instance; - } - - static EntryUnpublished _instance; -} - -@immutable -class EntryDeleted extends PublishType { - const EntryDeleted._() : super(_PublishType.EntryDeleted); - - factory EntryDeleted() { - _instance ??= const EntryDeleted._(); - return _instance; - } - - static EntryDeleted _instance; -} - -@immutable -class ContentTypeDeleted extends PublishType { - const ContentTypeDeleted._() : super(_PublishType.ContentTypeDeleted); - - factory ContentTypeDeleted() { - _instance ??= const ContentTypeDeleted._(); - return _instance; - } - - static ContentTypeDeleted _instance; -} diff --git a/pubspec.lock b/pubspec.lock index 13553ab..ed78aa7 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -5,130 +5,135 @@ packages: dependency: transitive description: name: _fe_analyzer_shared - sha256: cf8fb49539ecd6fea20ce18f2f858b88f8c27d4e7e3c09e1c6ed3289552bf223 + sha256: "45cfa8471b89fb6643fe9bf51bd7931a76b8f5ec2d65de4fb176dba8d4f22c77" url: "https://pub.dev" source: hosted - version: "36.0.0" + version: "73.0.0" + _macros: + dependency: transitive + description: dart + source: sdk + version: "0.3.2" analyzer: dependency: transitive description: name: analyzer - sha256: "45ebaf3b2fc49c371de62c5ec855207f0503a41f94bd92ae50d7320fdf28accd" + sha256: "4959fec185fe70cce007c57e9ab6983101dbe593d2bf8bbfb4453aaec0cf470a" url: "https://pub.dev" source: hosted - version: "3.3.1" + version: "6.8.0" archive: dependency: transitive description: name: archive - sha256: cdecf5f45a132ba5671845ec126269a17a69979c0f385852ad4a7d8639016441 + sha256: cb6a278ef2dbb298455e1a713bda08524a175630ec643a242c399c932a0a1f7d url: "https://pub.dev" source: hosted - version: "3.2.2" + version: "3.6.1" args: dependency: transitive description: name: args - sha256: "0bd9a99b6eb96f07af141f0eb53eace8983e8e5aa5de59777aca31684680ef22" + sha256: bf9f5caeea8d8fe6721a9c358dd8a5c1947b27f1cfaa18b39c301273594919e6 url: "https://pub.dev" source: hosted - version: "2.3.0" + version: "2.6.0" async: dependency: transitive description: name: async - sha256: db4766341bd8ecb66556f31ab891a5d596ef829221993531bd64a8e6342f0cda + sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb" url: "https://pub.dev" source: hosted - version: "2.8.2" + version: "2.13.0" bazel_worker: dependency: transitive description: name: bazel_worker - sha256: b0f16544323bfc3ba1d879e6b65eee07508009023d51e89978f261cf9853187f + sha256: "57035594b87d9f5af99f1a80e1edf5411dadbdf5acfc4f90403e3849f57dd0f0" url: "https://pub.dev" source: hosted - version: "1.0.1" + version: "1.1.2" boolean_selector: dependency: transitive description: name: boolean_selector - sha256: "5bbf32bc9e518d41ec49718e2931cd4527292c9b0c6d2dffcf7fe6b9a8a8cf72" + sha256: "8aab1771e1243a5063b8b0ff68042d67334e3feab9e95b9490f9a6ebf73b42ea" url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.2" build: dependency: transitive description: name: build - sha256: c9b6c412967d7887e88efe1ffbfe0f31bfaf6a5a4b98eb8d59964977a90f2f9e + sha256: "80184af8b6cb3e5c1c4ec6d8544d27711700bc3e6d2efad04238c7b5290889f0" url: "https://pub.dev" source: hosted - version: "2.2.1" + version: "2.4.1" build_config: dependency: transitive description: name: build_config - sha256: ad77deb6e9c143a3f550fbb4c5c1e0c6aadabe24274898d06b9526c61b9cf4fb + sha256: bf80fcfb46a29945b423bd9aad884590fb1dc69b330a4d4700cac476af1708d1 url: "https://pub.dev" source: hosted - version: "1.0.0" + version: "1.1.1" build_daemon: dependency: transitive description: name: build_daemon - sha256: "4e2dbfa914f99bca9c447ba5aaa572edf7335a71717944e4ab2e26ca079e7f79" + sha256: "79b2aef6ac2ed00046867ed354c88778c9c0f029df8a20fe10b5436826721ef9" url: "https://pub.dev" source: hosted - version: "3.0.1" + version: "4.0.2" build_modules: dependency: transitive description: name: build_modules - sha256: ca9167159cf798e42b1d046acdc9757c01fe8e6f93f5412707a7f7a02c7f391c + sha256: "403ba034d94f1a0f26362fe14fd83e9ff33644f5cbe879982920e3d209650b43" url: "https://pub.dev" source: hosted - version: "4.0.4" + version: "5.0.9" build_resolvers: dependency: transitive description: name: build_resolvers - sha256: "4666aef1d045c5ca15ebba63e400bd4e4fbd9f0dd06e791b51ab210da78a27f7" + sha256: "339086358431fa15d7eca8b6a36e5d783728cf025e559b834f4609a1fcfb7b0a" url: "https://pub.dev" source: hosted - version: "2.0.6" + version: "2.4.2" build_runner: dependency: "direct dev" description: name: build_runner - sha256: e090beee726671ff68747cb4d8c9151704864ec9a5dc88db9fe6441c24b3fa55 + sha256: "028819cfb90051c6b5440c7e574d1896f8037e3c96cf17aaeb054c9311cfbf4d" url: "https://pub.dev" source: hosted - version: "2.1.7" + version: "2.4.13" build_runner_core: dependency: transitive description: name: build_runner_core - sha256: f4d6244cc071ba842c296cb1c4ee1b31596b9f924300647ac7a1445493471a3f + sha256: f8126682b87a7282a339b871298cc12009cb67109cfa1614d6436fb0289193e0 url: "https://pub.dev" source: hosted - version: "7.2.3" + version: "7.3.2" build_test: dependency: "direct dev" description: name: build_test - sha256: b8165c422fab3f04622f44942ba0d85c7a0a1dd8195badce6862b24d19acd945 + sha256: "260dbba934f41b0a42935e9cae1f5731b94f0c3e489dc97bcf8e281265aaa5ae" url: "https://pub.dev" source: hosted - version: "2.1.5" + version: "2.2.2" build_web_compilers: dependency: "direct dev" description: name: build_web_compilers - sha256: "12f99028bb4bef837b2b00b3e8afdbe922718acb249208d6a15c17fcdb79f983" + sha256: e8d818410cc8b4dc96c4960ce0ab84fe3f2b0ca6576cc130fd7277b56eba9d68 url: "https://pub.dev" source: hosted - version: "3.2.2" + version: "4.0.11" built_collection: dependency: transitive description: @@ -141,545 +146,537 @@ packages: dependency: transitive description: name: built_value - sha256: b6c9911b2d670376918d5b8779bc27e0e612a94ec3ff0343689e991d8d0a3b8a - url: "https://pub.dev" - source: hosted - version: "8.1.4" - charcode: - dependency: transitive - description: - name: charcode - sha256: fb98c0f6d12c920a02ee2d998da788bca066ca5f148492b7085ee23372b12306 + sha256: "28a712df2576b63c6c005c465989a348604960c0958d28be5303ba9baa841ac2" url: "https://pub.dev" source: hosted - version: "1.3.1" + version: "8.9.3" checked_yaml: dependency: transitive description: name: checked_yaml - sha256: dd007e4fb8270916820a0d66e24f619266b60773cddd082c6439341645af2659 + sha256: feb6bed21949061731a7a75fc5d2aa727cf160b91af9a3e464c5e3a32e28b5ff url: "https://pub.dev" source: hosted - version: "2.0.1" - cli_util: - dependency: transitive - description: - name: cli_util - sha256: "66f86e916d285c1a93d3b79587d94bd71984a66aac4ff74e524cfa7877f1395c" - url: "https://pub.dev" - source: hosted - version: "0.3.5" + version: "2.0.3" code_builder: dependency: transitive description: name: code_builder - sha256: bdb1ab29be158c4784d7f9b7b693745a0719c5899e31c01112782bb1cb871e80 + sha256: "0ec10bf4a89e4c613960bf1e8b42c64127021740fb21640c29c909826a5eea3e" url: "https://pub.dev" source: hosted - version: "4.1.0" + version: "4.10.1" collection: dependency: transitive description: name: collection - sha256: ef7e3a5529178ce8f37a9d0b11cbbc8b1e025940f9cf9f76c42da6796301219d + sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76" url: "https://pub.dev" source: hosted - version: "1.16.0" + version: "1.19.1" convert: dependency: transitive description: name: convert - sha256: f08428ad63615f96a27e34221c65e1a451439b5f26030f78d790f461c686d65d + sha256: b30acd5944035672bc15c6b7a8b47d773e41e2f17de064350988c5d02adb1c68 url: "https://pub.dev" source: hosted - version: "3.0.1" + version: "3.1.2" coverage: dependency: transitive description: name: coverage - sha256: c0122af6b3548369d6b7830c7a140d85c9a988d8d29c4976aa9ce4de46b122ef + sha256: e3493833ea012784c740e341952298f1cc77f1f01b1bbc3eb4eecf6984fb7f43 url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.11.1" crypto: dependency: transitive description: name: crypto - sha256: cf75650c66c0316274e21d7c43d3dea246273af5955bd94e8184837cd577575c + sha256: "1e445881f28f22d6140f181e07737b22f1e099a5e1ff94b0af2f9e4a463f4855" url: "https://pub.dev" source: hosted - version: "3.0.1" + version: "3.0.6" csslib: dependency: transitive description: name: csslib - sha256: d1cd6d6e4b39a4ad295204722b8608f19981677b223f3e942c0b5a33dcf57ec0 + sha256: "09bad715f418841f976c77db72d5398dc1253c21fb9c0c7f0b0b985860b2d58e" url: "https://pub.dev" source: hosted - version: "0.17.1" + version: "1.0.2" dart_style: dependency: transitive description: name: dart_style - sha256: "959d3de27b5e0713f954643ee38619551da06e61e08088968fe7e1eb0cd720b1" + sha256: "7856d364b589d1f08986e140938578ed36ed948581fbc3bc9aef1805039ac5ab" url: "https://pub.dev" source: hosted - version: "2.2.2" + version: "2.3.7" dartdoc: dependency: "direct main" description: name: dartdoc - sha256: "473f65994b03884823e80cf30d732d9dd42e049d4a4b2b8ff484a33db8375de7" + sha256: "818bf58bd0325cb574df31e5c08969f0e690a9cb13826eaac2efc02c7e41655a" url: "https://pub.dev" source: hosted - version: "5.0.1" + version: "8.1.0" dotenv: dependency: "direct main" description: name: dotenv - sha256: dc4c91d8d5e9e361803fc81e8ea7ba0f35be483b656837ea6b9a3c41df308c68 + sha256: "379e64b6fc82d3df29461d349a1796ecd2c436c480d4653f3af6872eccbc90e1" url: "https://pub.dev" source: hosted - version: "3.0.0" - equatable: - dependency: transitive - description: - name: equatable - sha256: "8007a033720c056066dd1dc20bc2934cac91e271f0408c578aa26c7731618a03" - url: "https://pub.dev" - source: hosted - version: "1.2.6" + version: "4.2.0" file: - dependency: transitive + dependency: "direct main" description: name: file - sha256: b69516f2c26a5bcac4eee2e32512e1a5205ab312b3536c1c1227b2b942b5f9ad + sha256: a3b4f84adafef897088c160faf7dfffb7696046cb13ae90b508c2cbc95d3b8d4 url: "https://pub.dev" source: hosted - version: "6.1.2" + version: "7.0.1" fixnum: dependency: transitive description: name: fixnum - sha256: "6a2ef17156f4dc49684f9d99aaf4a93aba8ac49f5eac861755f5730ddf6e2e4e" + sha256: b6dc7065e46c974bc7c5f143080a6764ec7a4be6da1285ececdc37be96de53be url: "https://pub.dev" source: hosted - version: "1.0.0" + version: "1.1.1" flutter_lints: dependency: "direct dev" description: name: flutter_lints - sha256: b543301ad291598523947dc534aaddc5aaad597b709d2426d3a0e0d44c5cb493 + sha256: "5398f14efa795ffb7a33e9b6a08798b26a180edac4ad7db3f231e40f82ce11e1" url: "https://pub.dev" source: hosted - version: "1.0.4" + version: "5.0.0" frontend_server_client: dependency: transitive description: name: frontend_server_client - sha256: "6d2930621b9377f6a4b7d260fce525d48dd77a334f0d5d4177d07b0dcb76c032" + sha256: f64a0333a82f30b0cca061bc3d143813a486dc086b574bfb233b7c1372427694 url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "4.0.0" glob: dependency: transitive description: name: glob - sha256: "8321dd2c0ab0683a91a51307fa844c6db4aa8e3981219b78961672aaab434658" + sha256: c3f1ee72c96f8f78935e18aa8cecced9ab132419e8625dc187e1c2408efc20de url: "https://pub.dev" source: hosted - version: "2.0.2" + version: "2.1.3" graphs: dependency: transitive description: name: graphs - sha256: ae0b3d956ff324c6f8671f08dcb2dbd71c99cdbf2aa3ca63a14190c47aa6679c + sha256: "741bbf84165310a68ff28fe9e727332eef1407342fca52759cb21ad8177bb8d0" url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.3.2" html: dependency: transitive description: name: html - sha256: bfef906cbd4e78ef49ae511d9074aebd1d2251482ef601a280973e8b58b51bbf + sha256: "1fc58edeaec4307368c60d59b7e15b9d658b57d7f3125098b6294153c75337ec" url: "https://pub.dev" source: hosted - version: "0.15.0" + version: "0.15.5" http: dependency: "direct main" description: name: http - sha256: "2ed163531e071c2c6b7c659635112f24cb64ecbebf6af46b550d536c0b1aa112" + sha256: fe7ab022b76f3034adc518fb6ea04a82387620e19977665ea18d30a1cf43442f url: "https://pub.dev" source: hosted - version: "0.13.4" + version: "1.3.0" http_multi_server: dependency: transitive description: name: http_multi_server - sha256: ab298ef2b2acd283bd36837df7801dcf6e6b925f8da6e09efb81111230aa9037 + sha256: aa6199f908078bb1c5efb8d8638d4ae191aac11b311132c3ef48ce352fb52ef8 url: "https://pub.dev" source: hosted - version: "3.2.0" + version: "3.2.2" http_parser: dependency: transitive description: name: http_parser - sha256: e362d639ba3bc07d5a71faebb98cde68c05bfbcfbbb444b60b6f60bb67719185 + sha256: "178d74305e7866013777bab2c3d8726205dc5a4dd935297175b19a23a2e66571" url: "https://pub.dev" source: hosted - version: "4.0.0" + version: "4.1.2" io: dependency: transitive description: name: io - sha256: "0d4c73c3653ab85bf696d51a9657604c900a370549196a91f33e4c39af760852" + sha256: dfd5a80599cf0165756e3181807ed3e77daf6dd4137caaad72d0b7931597650b url: "https://pub.dev" source: hosted - version: "1.0.3" + version: "1.0.5" js: dependency: transitive description: name: js - sha256: a5e201311cb08bf3912ebbe9a2be096e182d703f881136ec1e81a2338a9e120d + sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf url: "https://pub.dev" source: hosted - version: "0.6.4" + version: "0.7.1" json_annotation: dependency: "direct main" description: name: json_annotation - sha256: "2639efc0237c7b71c6584696c0847ea4e4733ddaf571ae9c79d5295e8ae17272" + sha256: "1ce844379ca14835a50d2f019a3099f419082cfdd231cd86a142af94dd5c6bb1" url: "https://pub.dev" source: hosted - version: "4.4.0" + version: "4.9.0" json_serializable: dependency: "direct dev" description: name: json_serializable - sha256: a53cf24d6fcb43661c31c3eb43dd1832b71abc8b62afa59be909416140a08610 + sha256: c2fcb3920cf2b6ae6845954186420fca40bc0a8abcc84903b7801f17d7050d7c url: "https://pub.dev" source: hosted - version: "6.1.5" + version: "6.9.0" lints: dependency: transitive description: name: lints - sha256: a2c3d198cb5ea2e179926622d433331d8b58374ab8f29cdda6e863bd62fd369c + sha256: "3315600f3fb3b135be672bf4a178c55f274bebe368325ae18462c89ac1e3b413" url: "https://pub.dev" source: hosted - version: "1.0.1" + version: "5.0.0" logger: dependency: "direct main" description: name: logger - sha256: "5076f09225f91dc49289a4ccb92df2eeea9ea01cf7c26d49b3a1f04c6a49eec1" + sha256: be4b23575aac7ebf01f225a241eb7f6b5641eeaf43c6a8613510fc2f8cf187d1 url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "2.5.0" logging: dependency: transitive description: name: logging - sha256: "293ae2d49fd79d4c04944c3a26dfd313382d5f52e821ec57119230ae16031ad4" + sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61 url: "https://pub.dev" source: hosted - version: "1.0.2" + version: "1.3.0" + macros: + dependency: transitive + description: + name: macros + sha256: "0acaed5d6b7eab89f63350bccd82119e6c602df0f391260d0e32b5e23db79536" + url: "https://pub.dev" + source: hosted + version: "0.1.2-main.4" markdown: dependency: transitive description: name: markdown - sha256: "01512006c8429f604eb10f9848717baeaedf99e991d14a50d540d9beff08e5c6" + sha256: "935e23e1ff3bc02d390bad4d4be001208ee92cc217cb5b5a6c19bc14aaa318c1" url: "https://pub.dev" source: hosted - version: "4.0.1" + version: "7.3.0" matcher: dependency: transitive description: name: matcher - sha256: "2e2c34e631f93410daa3ee3410250eadc77ac6befc02a040eda8a123f34e6f5a" + sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2 url: "https://pub.dev" source: hosted - version: "0.12.11" + version: "0.12.17" meta: dependency: transitive description: name: meta - sha256: "5202fdd37b4da5fd14a237ed0a01cad6c1efd4c99b5b5a0d3c9237f3728c9485" + sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c url: "https://pub.dev" source: hosted - version: "1.7.0" + version: "1.16.0" mime: dependency: transitive description: name: mime - sha256: fd5f81041e6a9fc9b9d7fa2cb8a01123f9f5d5d49136e06cb9dc7d33689529f4 + sha256: "41a20518f0cb1256669420fdba0cd90d21561e560ac240f26ef8322e45bb7ed6" url: "https://pub.dev" source: hosted - version: "1.0.1" + version: "2.0.0" node_preamble: dependency: transitive description: name: node_preamble - sha256: "8ebdbaa3b96d5285d068f80772390d27c21e1fa10fb2df6627b1b9415043608d" + sha256: "6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db" url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "2.0.2" package_config: dependency: transitive description: name: package_config - sha256: a4d5ede5ca9c3d88a2fef1147a078570c861714c806485c596b109819135bc12 + sha256: "92d4488434b520a62570293fbd33bb556c7d49230791c1b4bbd973baf6d2dc67" url: "https://pub.dev" source: hosted - version: "2.0.2" + version: "2.1.1" path: dependency: "direct main" description: name: path - sha256: "240ed0e9bd73daa2182e33c4efc68c7dd53c7c656f3da73515a2d163e151412d" + sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5" url: "https://pub.dev" source: hosted - version: "1.8.1" + version: "1.9.1" pool: dependency: transitive description: name: pool - sha256: "05955e3de2683e1746222efd14b775df7131139e07695dc8e24650f6b4204504" + sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a" url: "https://pub.dev" source: hosted - version: "1.5.0" + version: "1.5.1" protobuf: dependency: transitive description: name: protobuf - sha256: f9b7809db75bc95d411bc197d714613fb42f0b0c17553c95568a2a9179d2a7ea + sha256: "68645b24e0716782e58948f8467fd42a880f255096a821f9e7d0ec625b00c84d" url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "3.1.0" pub_semver: dependency: transitive description: name: pub_semver - sha256: "816c1a640e952d213ddd223b3e7aafae08cd9f8e1f6864eed304cc13b0272b07" + sha256: "7b3cfbf654f3edd0c6298ecd5be782ce997ddf0e00531b9464b55245185bbbbd" url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.1.5" pubspec_parse: dependency: transitive description: name: pubspec_parse - sha256: "3686efe4a4613a4449b1a4ae08670aadbd3376f2e78d93e3f8f0919db02a7256" + sha256: "81876843eb50dc2e1e5b151792c9a985c5ed2536914115ed04e9c8528f6647b0" url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.4.0" scratch_space: dependency: transitive description: name: scratch_space - sha256: a469a9642a4d7ee406d6224a85446eb8baa9dd6d81e2f0b76770deae7bd32aab + sha256: "8510fbff458d733a58fc427057d1ac86303b376d609d6e1bc43f240aad9aa445" url: "https://pub.dev" source: hosted - version: "1.0.1" + version: "1.0.2" shelf: dependency: transitive description: name: shelf - sha256: c240984c924796e055e831a0a36db23be8cb04f170b26df572931ab36418421d + sha256: e7dd780a7ffb623c57850b33f43309312fc863fb6aa3d276a754bb299839ef12 url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.4.2" shelf_packages_handler: dependency: transitive description: name: shelf_packages_handler - sha256: e0b44ebddec91e70a713e13adf93c1b2100821303b86a18e1ef1d082bd8bd9b8 + sha256: "89f967eca29607c933ba9571d838be31d67f53f6e4ee15147d5dc2934fee1b1e" url: "https://pub.dev" source: hosted - version: "3.0.0" + version: "3.0.2" shelf_static: dependency: transitive description: name: shelf_static - sha256: "4a0d12cd512aa4fc55fed5f6280f02ef183f47ba29b4b0dfd621b1c99b7e6361" + sha256: c87c3875f91262785dade62d135760c2c69cb217ac759485334c5857ad89f6e3 url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.1.3" shelf_web_socket: dependency: transitive description: name: shelf_web_socket - sha256: fd84910bf7d58db109082edf7326b75322b8f186162028482f53dc892f00332d + sha256: cc36c297b52866d203dbf9332263c94becc2fe0ceaa9681d07b6ef9807023b67 url: "https://pub.dev" source: hosted - version: "1.0.1" + version: "2.0.1" source_gen: dependency: transitive description: name: source_gen - sha256: d5aa894fcfa327e19196d6f4f733597a10b42a7e55c8cb2b0dd60d7e7d27dccf + sha256: "14658ba5f669685cd3d63701d01b31ea748310f7ab854e471962670abcf57832" url: "https://pub.dev" source: hosted - version: "1.2.1" + version: "1.5.0" source_helper: dependency: transitive description: name: source_helper - sha256: bff606c07bddcabef6b06ad6d90eee3bc5f7adbbf48c2939963145b004b5b8b3 + sha256: "86d247119aedce8e63f4751bd9626fc9613255935558447569ad42f9f5b48b3c" url: "https://pub.dev" source: hosted - version: "1.3.1" + version: "1.3.5" source_map_stack_trace: dependency: transitive description: name: source_map_stack_trace - sha256: "8c463326277f68a628abab20580047b419c2ff66756fd0affd451f73f9508c11" + sha256: c0713a43e323c3302c2abe2a1cc89aa057a387101ebd280371d6a6c9fa68516b url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.2" source_maps: dependency: transitive description: name: source_maps - sha256: "52de2200bb098de739794c82d09c41ac27b2e42fd7e23cce7b9c74bf653c7296" + sha256: "190222579a448b03896e0ca6eca5998fa810fda630c1d65e2f78b3f638f54812" url: "https://pub.dev" source: hosted - version: "0.10.10" + version: "0.10.13" source_span: dependency: transitive description: name: source_span - sha256: d77dbb9d0b7469d91e42d352334b2b4bbd5cec4379542f1bdb630db368c4d9f6 + sha256: "254ee5351d6cb365c859e20ee823c3bb479bf4a293c22d17a9f1bf144ce86f7c" url: "https://pub.dev" source: hosted - version: "1.8.2" + version: "1.10.1" stack_trace: dependency: transitive description: name: stack_trace - sha256: f8d9f247e2f9f90e32d1495ff32dac7e4ae34ffa7194c5ff8fcc0fd0e52df774 + sha256: "8b27215b45d22309b5cddda1aa2b19bdfec9df0e765f2de506401c071d38d1b1" url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.12.1" stream_channel: dependency: transitive description: name: stream_channel - sha256: db47e4797198ee601990820437179bb90219f918962318d494ada2b4b11e6f6d + sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d" url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.4" stream_transform: dependency: transitive description: name: stream_transform - sha256: ed464977cb26a1f41537e177e190c67223dbd9f4f683489b6ab2e5d211ec564e + sha256: ad47125e588cfd37a9a7f86c7d6356dde8dfe89d071d293f80ca9e9273a33871 url: "https://pub.dev" source: hosted - version: "2.0.0" + version: "2.1.1" string_scanner: dependency: transitive description: name: string_scanner - sha256: dd11571b8a03f7cadcf91ec26a77e02bfbd6bbba2a512924d3116646b4198fc4 + sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43" url: "https://pub.dev" source: hosted - version: "1.1.0" - super_enum: - dependency: "direct main" - description: - name: super_enum - sha256: "4ef073e108450589a813ba92ebd24a391cb74e0e12dcb54e72181d8896b58794" - url: "https://pub.dev" - source: hosted - version: "0.5.0" + version: "1.4.1" term_glyph: dependency: transitive description: name: term_glyph - sha256: a88162591b02c1f3a3db3af8ce1ea2b374bd75a7bb8d5e353bcfbdc79d719830 + sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e" url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.2.2" test: dependency: "direct dev" description: name: test - sha256: fd53f3bac5c70f26eec065456f73b20b11ea969aaa1099928bf9a6c1fd0e1403 + sha256: "301b213cd241ca982e9ba50266bd3f5bd1ea33f1455554c5abb85d1be0e2d87e" url: "https://pub.dev" source: hosted - version: "1.20.1" + version: "1.25.15" test_api: dependency: transitive description: name: test_api - sha256: d8ca35bbbeef2d037e5693a3c8a381505afebfbfee7bc33fff5581bc4e16a939 + sha256: fb31f383e2ee25fbbfe06b40fe21e1e458d14080e3c67e7ba0acfde4df4e0bbd url: "https://pub.dev" source: hosted - version: "0.4.9" + version: "0.7.4" test_core: dependency: transitive description: name: test_core - sha256: cc8bc45cbe52e8133293537ac4cffc4d9b35c93e91481eb64ef2304e2e722949 + sha256: "84d17c3486c8dfdbe5e12a50c8ae176d15e2a771b96909a9442b40173649ccaa" url: "https://pub.dev" source: hosted - version: "0.4.11" + version: "0.6.8" timing: dependency: transitive description: name: timing - sha256: c386d07d7f5efc613479a7c4d9d64b03710b03cfaa7e8ad5f2bfb295a1f0dfad + sha256: "62ee18aca144e4a9f29d212f5a4c6a053be252b895ab14b5821996cff4ed90fe" url: "https://pub.dev" source: hosted - version: "1.0.0" + version: "1.0.2" typed_data: dependency: transitive description: name: typed_data - sha256: "53bdf7e979cfbf3e28987552fd72f637e63f3c8724c9e56d9246942dc2fa36ee" + sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006 url: "https://pub.dev" source: hosted - version: "1.3.0" + version: "1.4.0" vm_service: dependency: transitive description: name: vm_service - sha256: "5e10b8a57f571c4bc3bc45dddf708141fe10ceb5c1d44652a78e8ff497dc6db8" + sha256: ddfa8d30d89985b96407efce8acbdd124701f96741f2d981ca860662f1c0dc02 url: "https://pub.dev" source: hosted - version: "8.2.1" + version: "15.0.0" watcher: dependency: transitive description: name: watcher - sha256: e42dfcc48f67618344da967b10f62de57e04bae01d9d3af4c2596f3712a88c99 + sha256: "69da27e49efa56a15f8afe8f4438c4ec02eff0a117df1b22ea4aad194fe1c104" + url: "https://pub.dev" + source: hosted + version: "1.1.1" + web: + dependency: transitive + description: + name: web + sha256: cd3543bd5798f6ad290ea73d210f423502e71900302dde696f8bff84bf89a1cb url: "https://pub.dev" source: hosted - version: "1.0.1" + version: "1.1.0" + web_socket: + dependency: transitive + description: + name: web_socket + sha256: "3c12d96c0c9a4eec095246debcea7b86c0324f22df69893d538fcc6f1b8cce83" + url: "https://pub.dev" + source: hosted + version: "0.1.6" web_socket_channel: dependency: transitive description: name: web_socket_channel - sha256: "0c2ada1b1aeb2ad031ca81872add6be049b8cb479262c6ad3c4b0f9c24eaab2f" + sha256: "0b8e2457400d8a859b7b2030786835a28a8e80836ef64402abef392ff4f1d0e5" url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "3.0.2" webkit_inspection_protocol: dependency: transitive description: name: webkit_inspection_protocol - sha256: "5adb6ab8ed14e22bb907aae7338f0c206ea21e7a27004e97664b16c120306f00" + sha256: "87d3f2333bb240704cd3f1c6b5b7acd8a10e7f0bc28c28dcf14e782014f4a572" url: "https://pub.dev" source: hosted - version: "1.0.0" + version: "1.2.1" yaml: dependency: transitive description: name: yaml - sha256: "3cee79b1715110341012d27756d9bae38e650588acd38d3f3c610822e1337ace" + sha256: b9da305ac7c39faa3f030eccd175340f968459dae4af175130b3fc47e40d76ce url: "https://pub.dev" source: hosted - version: "3.1.0" + version: "3.1.3" sdks: - dart: ">=2.16.0-100.0.dev <3.0.0" + dart: ">=3.5.0 <3.7.0" diff --git a/pubspec.yaml b/pubspec.yaml index 281c183..f313056 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,26 +1,27 @@ name: contentstack description: Contentstack is a headless CMS with an API-first approach that puts content at the centre. -version: 0.5.1 +version: 1.0.0 homepage: https://www.contentstack.com documentation: https://www.contentstack.com/docs/developers/apis/content-delivery-api environment: # sdk: ">=2.17.6 <3.0.0" - sdk: ">=2.8.1 <3.0.0" + sdk: ">=2.12.0 <3.0.0" dependencies: - dartdoc: ^5.0.1 # dartdoc to generate HTML documentation for your Dart package - http: ^0.13.3 # Future-based API for HTTP requests + dartdoc: ^8.1.0 # dartdoc to generate HTML documentation for your Dart package + http: ^1.2.2 # Future-based API for HTTP requests json_annotation: ^4.4.0 # create code for JSON serialization and deserialization. - logger: ^1.0.0 # logger which prints beautiful logs + logger: ^2.4.0 # logger which prints beautiful logs path: ^1.8.0 # for manipulating paths: joining, splitting, normalizing, etc. - super_enum: ^0.5.0 - dotenv: ^3.0.0 # loads environment variables at runtime from a .env file. + dotenv: ^4.2.0 # loads environment variables at runtime from a .env file. + file: ^7.0.0 dev_dependencies: - flutter_lints: ^1.0.0 + flutter_lints: ^5.0.0 build_runner: ^2.0.4 build_test: ^2.1.0 - build_web_compilers: ^3.0.0 + build_web_compilers: ^4.0.11 json_serializable: ^6.1.5 test: ^1.20.1 + diff --git a/test/assets_test.dart b/test/assets_test.dart index 23593f9..109ab5c 100644 --- a/test/assets_test.dart +++ b/test/assets_test.dart @@ -1,26 +1,27 @@ import 'package:contentstack/contentstack.dart' as contentstack; import 'package:contentstack/contentstack.dart'; import 'package:contentstack/src/asset_query.dart'; -import 'package:dotenv/dotenv.dart' show load, env; +import 'package:dotenv/dotenv.dart'; import 'package:test/test.dart'; +import 'dart:convert'; void main() { - load(); - final apiKey = env['apiKey']; + var env = DotEnv(includePlatformEnvironment: true)..load(); + final apiKey = env['apiKey']!; final host = env['host']; - final deliveryToken = env['deliveryToken']; - final environment = env['environment']; + final deliveryToken = env['deliveryToken']!; + final environment = env['environment']!; final Stack stack = Stack(apiKey, deliveryToken, environment, host: host); group('testcases for asset the functional implementation', () { - var assetUid = ''; + var assetUid = env['assetUid']; setUp(() async { final AssetQuery assetQuery = stack.assetQuery(); await assetQuery.find().then((response) { prints('response $response'); final List assets = response['assets']; for (final item in assets) { - if (item['title'] == 'images_(2).jpg') { + if (item['title'] == 'IMG20230824114247.jpg') { assetUid = item['uid']; prints(assetUid); } @@ -34,7 +35,7 @@ void main() { prints('response $response'); final List assets = response['assets']; for (final item in assets) { - if (item['title'] == 'images_(2).jpg') { + if (item['title'] == 'IMG20230824114247.jpg') { assetUid = item['uid']; prints(assetUid); } @@ -46,7 +47,7 @@ void main() { test('testcase asset title', () async { final asset = stack.asset(assetUid)..environment('development'); await asset.fetch().then((response) { - expect('images_(2).jpg', response.title); + expect('image2', response!.title); }); }); @@ -62,9 +63,9 @@ void main() { }); test('testcase asset fetch version', () async { - final asset = stack.asset(assetUid)..version(4); + final asset = stack.asset(assetUid)..version(1); await asset.fetch().then((response) { - expect('images_(2).jpg', response['asset']['filename']); + expect('image2.jpg', response['asset']['filename']); }).catchError((error) { expect(422, error['error_code']); }); @@ -84,7 +85,7 @@ void main() { final asset = stack.asset(assetUid)..includeDimension(); await asset.fetch().then((response) { final model = contentstack.AssetModel.fromJson(response['asset']); - expect('{height: 171, width: 294}', model.dimension.toString()); + expect(model.dimension.toString(), '{height: 225, width: 225}'); }); } catch (e) { expect(e.toString(), equals('Provide asset uid to fetch single entry')); @@ -101,7 +102,7 @@ void main() { test('test asset environment', () async { final asset = stack.assetQuery()..environment('development'); await asset.find().then((response) { - expect('images_(2).jpg', response['assets'][7]['filename']); + expect('image2.jpg', response['assets'][4]['filename']); }).catchError((error) { expect(422, error['error_code']); }); @@ -125,9 +126,10 @@ void main() { final asset = stack.assetQuery() ..includeCount() ..relativeUrls(); - await asset.find, AssetModel>().then((response) { - expect(response[7].url.contains('.jpg'), true); + await asset.find().then((response) { + expect(response!['assets']![4]['url']!.contains('.jpg'), true); }).catchError((error) { + print(error); expect(422, error['error_code']); }); }); @@ -153,7 +155,7 @@ void main() { test('testcase asset include fallback', () async { final asset = stack.assetQuery()..includeFallback(); await asset.find().then((response) { - expect(8, response['assets'].length); + expect(5, response['assets'].length); }).catchError((error) { expect(422, error['error_code']); }); @@ -164,7 +166,7 @@ void main() { ..includeFallback() ..param('locale', 'en-us'); await asset.find().then((response) { - expect(8, response['assets'].length); + expect(5, response['assets'].length); }).catchError((error) { expect(422, error['error_code']); }); diff --git a/test/contenttype_test.dart b/test/contenttype_test.dart index c037b14..6d05799 100644 --- a/test/contenttype_test.dart +++ b/test/contenttype_test.dart @@ -1,24 +1,25 @@ import 'package:contentstack/contentstack.dart'; -import 'package:dotenv/dotenv.dart' show load, env; +import 'package:dotenv/dotenv.dart'; import 'package:logger/logger.dart'; import 'package:test/test.dart'; void main() { final logger = Logger(printer: PrettyPrinter()); - load(); - final apiKey = env['apiKey']; + var env = DotEnv(includePlatformEnvironment: true)..load(); + final apiKey = env['apiKey']!; final host = env['host']; - final deliveryToken = env['deliveryToken']; - final environment = env['environment']; + final deliveryToken = env['deliveryToken']!; + final environment = env['environment']!; + final contentTypeUid = env['contentType']; final Stack stack = Stack(apiKey, deliveryToken, environment, host: host); - final ContentType contentType = stack.contentType('application_theme'); + final ContentType contentType = stack.contentType(contentTypeUid); logger.i('credentials loaded..'); group('testcase content type functional testing', () { test('test network call for content type', () async { final map = {'key': 'value'}; final response = await contentType.fetch(map); - expect(15, response['content_type']['schema'].length); + expect(response['content_type']['schema'].length, 12); }); test('test ContentTypeQuery instance', () { @@ -31,13 +32,13 @@ void main() { test('test for all the content types available', () async { final allContents = contentType.query(); final response = await allContents.find(); - expect(12, response['content_types'].length); + expect(response['content_types'].length,10); }); test('test include_count is available', () async { final allContents = contentType.query()..includeCount(); await allContents.find().then((response) { - expect(12, response['count']); + expect(response['count'],10); }).catchError((error) { expect('invalid response', error.message); }); @@ -47,7 +48,7 @@ void main() { final allContents = contentType.query()..includeGlobalField(); await allContents .find(queryParams: {'include_count': 'true'}).then((response) { - expect(12, response['count']); + expect(response['count'],10); }); }); }); diff --git a/test/entry_test.dart b/test/entry_test.dart index 7bdb495..f940e9d 100644 --- a/test/entry_test.dart +++ b/test/entry_test.dart @@ -1,35 +1,41 @@ import 'package:contentstack/contentstack.dart'; +import 'package:contentstack/src/enums/include_type.dart'; import 'package:contentstack/src/enums/include.dart'; -import 'package:dotenv/dotenv.dart' show load, env; +import 'package:dotenv/dotenv.dart'; import 'package:logger/logger.dart'; import 'package:test/test.dart'; void main() { final logger = Logger(printer: PrettyPrinter()); - load(); - final apiKey = env['apiKey']; + var env = DotEnv(includePlatformEnvironment: true)..load(); + final apiKey = env['apiKey']!; final host = env['host']; - final deliveryToken = env['deliveryToken']; - final environment = env['environment']; - var entryUid = ''; + final deliveryToken = env['deliveryToken']!; + final environment = env['environment']!; + final contentType = env['contentType']!; + String? entryUid = ''; logger.i('credentials loaded..'); final Stack stack = Stack(apiKey, deliveryToken, environment, host: host); - final Query query = stack.contentType('faq').entry().query(); - final Entry entry = stack.contentType('faq').entry(entryUid: entryUid); + final Query query = stack.contentType(contentType).entry().query(); + final Entry entry = stack.contentType(contentType).entry(entryUid: entryUid); group('Entry functional testcases', () { setUp(() async { await query.find().then((response) { final entries = response['entries']; - for (final item in entries) { - if (item['title'] == 'MEALS') { - entryUid = item['uid']; - continue; - } - } + if(entries != null) { + for (final item in entries) { + if (item['title'] == 'source1') { + entryUid = item['uid']; + continue; + } + } + } else { + logger.i('No entries found'); + } }); }); @@ -82,7 +88,7 @@ void main() { test('test includeReference includeType only', () { const List fieldUid = ['title', 'orange', 'mango']; entry.includeReference('category', - includeReferenceField: Include.only(fieldUidList: fieldUid)); + includeReferenceField: IncludeClass(IncludeType.Only,fieldUid)); expect(true, entry.parameter.containsKey('include[]')); expect(true, entry.parameter.containsKey('only')); }); @@ -90,7 +96,7 @@ void main() { test('test includeReference includeType except', () { const List fieldUid = ['title', 'orange', 'mango']; entry.includeReference('category', - includeReferenceField: Include.except(fieldUidList: fieldUid)); + includeReferenceField: IncludeClass(IncludeType.Except, fieldUid)); expect(true, entry.parameter.containsKey('include[]')); expect(true, entry.parameter.containsKey('except')); }); @@ -111,8 +117,8 @@ void main() { ///////////////////////////////////////////////////////////////////////////// group('Entry API testcases', () { - var _uid = ''; - Entry entryInstance; + String? _uid = ''; + late Entry entryInstance; // If this is called within a test group, callback // will run before all tests in that group. @@ -120,9 +126,9 @@ void main() { await query.find().then((response) { final entries = response['entries']; for (final item in entries) { - if (item['title'] == 'MEALS') { + if (item['title'] == 'source1') { _uid = item['uid']; - entryInstance = stack.contentType('faq').entry(entryUid: _uid); + entryInstance = stack.contentType(contentType).entry(entryUid: _uid); continue; } } @@ -132,7 +138,7 @@ void main() { //This function will be called before each test is run. // callback may be asynchronous; if so, it must return a setUp(() async { - entryInstance = stack.contentType('faq').entry(entryUid: _uid); + entryInstance = stack.contentType(contentType).entry(entryUid: _uid); }); // test('find the entry response with locale', () async { @@ -147,9 +153,9 @@ void main() { test('test entry response with version', () async { entryInstance ..locale('en-us') - ..addParam('version', '1'); + ..addParam('version', '5'); await entryInstance.fetch().then((response) { - expect(1, response.version); + expect(response!.version,5); }); }); @@ -158,7 +164,7 @@ void main() { const List fieldUID = ['price', 'title']; entryInstance.only(fieldUID); await entryInstance.fetch().then((response) { - expect(response.uid != null, true); + expect(response!.uid != null, true); }); }); @@ -173,14 +179,14 @@ void main() { // expect('Error', err.title); // }); await entryInstance.fetch().then((response) { - expect('MEALS', response.title); + expect(response!.title, 'source1' ); }); }); test('find the includeReference default API call', () async { - entryInstance.includeReference('categories'); + entryInstance.includeReference('reference'); await entryInstance.fetch().then((response) { - expect(141, response['error_code']); + expect(response['error_code'],141); }).catchError((onError) { expect('invalid url requested', onError.message); }); @@ -188,10 +194,10 @@ void main() { test('find the includeReference default with list objects', () async { const List fieldUID = ['title', 'attendee', 'created_at']; - entryInstance.includeReference('categories', - includeReferenceField: Include.none(fieldUidList: fieldUID)); + entryInstance.includeReference('reference', + includeReferenceField: IncludeClass(IncludeType.None, fieldUID)); await entryInstance.fetch().then((response) { - expect(141, response['error_code']); + expect( response['error_code'],141); }).catchError((onError) { expect('invalid url requested', onError.message); }); @@ -200,21 +206,20 @@ void main() { test('find the includeReference with only API call', () async { entryInstance.locale('en-us'); const List fieldUID = ['price', 'orange', 'mango']; - entryInstance.includeReference('categories', - includeReferenceField: Include.only(fieldUidList: fieldUID)); + entryInstance.includeReference('reference', + includeReferenceField: IncludeClass(IncludeType.Only, fieldUID)); await entryInstance.fetch().then((response) { - expect(141, response['error_code']); + expect( response['error_code'],141); }); }); test('find the includeReference except API call', () async { entryInstance.locale('en-us'); const List fieldUID = ['price', 'orange', 'mango']; - entryInstance.includeReference('categories', - includeReferenceField: Include.except(fieldUidList: fieldUID)); + entryInstance.includeReference('reference', + includeReferenceField: IncludeClass(IncludeType.Except, fieldUID)); await entryInstance.fetch().then((response) { - expect( - "The requested object doesn't exist.", response['error_message']); + expect(response['error_message'],"The requested object doesn't exist."); }).catchError((error) { expect('Invalid reponse.', error.message); }); @@ -230,7 +235,7 @@ void main() { test('find the includeReferenceContentTypeUID except API call', () async { entryInstance.includeReferenceContentTypeUID(); await entryInstance.fetch().then((response) { - final resp = response['entry']['faq_group']; + final resp = response['entry']['reference']; expect(true, resp is List); }); }); @@ -268,7 +273,7 @@ void main() { test('find the includeReference with multiple strings', () async { final Stack stack = Stack(apiKey, deliveryToken, environment, host: host); - final Entry entry = stack.contentType('faq').entry(entryUid: 'entryUid'); + final Entry entry = stack.contentType(contentType).entry(entryUid: _uid); const List fieldUID = ['price', 'orange', 'mango']; entry.includeReference(fieldUID); await entry.fetch().then((response) { diff --git a/test/image_transform_test.dart b/test/image_transform_test.dart index ceeb39e..cb8997c 100644 --- a/test/image_transform_test.dart +++ b/test/image_transform_test.dart @@ -3,22 +3,22 @@ import 'package:contentstack/src/image/filter.dart'; import 'package:contentstack/src/image/fit.dart'; import 'package:contentstack/src/image/format.dart'; import 'package:contentstack/src/image/orientation.dart'; -import 'package:dotenv/dotenv.dart' show load, env; +import 'package:dotenv/dotenv.dart'; import 'package:test/test.dart'; void main() { //var logger = Logger(printer: PrettyPrinter()); - load(); - final apiKey = env['apiKey']; + var env = DotEnv(includePlatformEnvironment: true)..load(); + final apiKey = env['apiKey']!; final host = env['host']; - final deliveryToken = env['deliveryToken']; - final environment = env['environment']; + final deliveryToken = env['deliveryToken']!; + final environment = env['environment']!; final Stack stack = Stack(apiKey, deliveryToken, environment, host: host); group('ImageTransformation functional testcases', () { const imageUrl = 'https://images.contentstack.io/v3/assets/download'; - ImageTransformation imageTransformation; + late ImageTransformation imageTransformation; setUp(() { imageTransformation = stack.imageTransform(imageUrl); @@ -54,49 +54,49 @@ void main() { test('convert to gif in ImageTransformation', () { final response = imageTransformation - ..convert(Format.gif()) + ..convert(Format.Gif) ..getUrl(); expect('format=gif', response.query.toString()); }); test('convert to png in ImageTransformation', () { final response = imageTransformation - ..convert(Format.png()) + ..convert(Format.Png) ..getUrl(); expect('format=png', response.query.toString()); }); test('convert to jpeg in ImageTransformation', () { final response = imageTransformation - ..convert(Format.pjpg()) + ..convert(Format.Pjpg) ..getUrl(); expect('format=pjpg', response.query.toString()); }); test('convert to jpeg in ImageTransformation', () { final response = imageTransformation - ..convert(Format.jpg()) + ..convert(Format.Jpg) ..getUrl(); expect('format=jpg', response.query.toString()); }); test('convert to jpeg in ImageTransformation', () { final response = imageTransformation - ..convert(Format.webp()) + ..convert(Format.Webp) ..getUrl(); expect('format=webp', response.query.toString()); }); test('convert to jpeg in ImageTransformation', () { final response = imageTransformation - ..convert(Format.webplossy()) + ..convert(Format.Webplossy) ..getUrl(); expect('format=webply', response.query.toString()); }); test('convert to jpeg in ImageTransformation', () { final response = imageTransformation - ..convert(Format.webplossless()) + ..convert(Format.Webplossless) ..getUrl(); expect('format=webpll', response.query.toString()); }); @@ -166,14 +166,14 @@ void main() { test('Fit To Bound in ImageTransformation', () { final response = imageTransformation - ..fit(0.50, 0.50, Fit.bounds()) + ..fit(0.50, 0.50, Fit.Bounds) ..getUrl(); expect('width=0.5&height=0.5&fit=bounds', response.query.toString()); }); test('Fit By Cropping in ImageTransformation', () { final response = imageTransformation - ..fit(0.50, 0.50, Fit.crop()) + ..fit(0.50, 0.50, Fit.Crop) ..getUrl(); expect('width=0.5&height=0.5&fit=crop', response.query.toString()); }); @@ -208,14 +208,14 @@ void main() { test('orientation vertical in ImageTransformation check params', () { final response = imageTransformation - ..orientation(Orientation.vertically()) + ..orientation(Orientation.Vertically) ..getUrl(); expect('orient=4', response.query.toString()); }); test('orientation horizontal in ImageTransformation check params', () { final response = imageTransformation - ..orientation(Orientation.horizontally()) + ..orientation(Orientation.Horizontally) ..getUrl(); expect('orient=2', response.query.toString()); }); @@ -224,35 +224,35 @@ void main() { 'orientation degrees90TowardsRight in ImageTransformation check params', () { final response = imageTransformation - ..orientation(Orientation.degrees90TowardsRight()) + ..orientation(Orientation.Degrees90TowardsRight) ..getUrl(); expect('orient=6', response.query.toString()); }); test('orientation horizontallyAndRotate90DegreeLeft', () { final response = imageTransformation - ..orientation(Orientation.horizontallyAndRotate90DegreeLeft()) + ..orientation(Orientation.HorizontallyAndRotate90DegreeLeft) ..getUrl(); expect('orient=5', response.query.toString()); }); test('orientation horizontallyAndRotate90DegreesRight', () { final response = imageTransformation - ..orientation(Orientation.horizontallyAndRotate90DegreesRight()) + ..orientation(Orientation.HorizontallyAndRotate90DegreesRight) ..getUrl(); expect('orient=7', response.query.toString()); }); test('orientation horizontallyAndVertically', () { final response = imageTransformation - ..orientation(Orientation.horizontallyAndVertically()) + ..orientation(Orientation.HorizontallyAndVertically) ..getUrl(); expect('orient=3', response.query.toString()); }); test('orientation toDefault in ImageTransformation check params', () { final response = imageTransformation - ..orientation(Orientation.toDefault()) + ..orientation(Orientation.ToDefault) ..getUrl(); expect('orient=1', response.query.toString()); }); @@ -260,7 +260,7 @@ void main() { test('orientation rotate90DegreesLeft in ImageTransformation check params', () { final response = imageTransformation - ..orientation(Orientation.rotate90DegreesLeft()) + ..orientation(Orientation.Rotate90DegreesLeft) ..getUrl(); expect('orient=8', response.query.toString()); }); @@ -359,7 +359,7 @@ void main() { test('resize-filter type nearest in ImageTransformation', () { final response = imageTransformation - ..resizeFilter(width: 20, height: 40, filter: Filter.nearest()) + ..resizeFilter(width: 20, height: 40, filter: Filter.Nearest) ..getUrl(); expect('width=20&height=40&resize-filter=nearest', response.query.toString()); @@ -367,7 +367,7 @@ void main() { test('resize-filter type Filter.bicubic in ImageTransformation', () { final response = imageTransformation - ..resizeFilter(width: 20, height: 40, filter: Filter.bicubic()) + ..resizeFilter(width: 20, height: 40, filter: Filter.Bicubic) ..getUrl(); expect('width=20&height=40&resize-filter=bicubic', response.query.toString()); @@ -375,7 +375,7 @@ void main() { test('resize-filter type Filter.bilinear in ImageTransformation', () { final response = imageTransformation - ..resizeFilter(width: 20, height: 40, filter: Filter.bilinear()) + ..resizeFilter(width: 20, height: 40, filter: Filter.Bilinear) ..getUrl(); expect('width=20&height=40&resize-filter=bilinear', response.query.toString()); @@ -383,7 +383,7 @@ void main() { test('resize-filter type lanczos in ImageTransformation', () { final response = imageTransformation - ..resizeFilter(width: 20, height: 40, filter: Filter.lanczos()) + ..resizeFilter(width: 20, height: 40, filter: Filter.Lanczos) ..getUrl(); expect('width=20&height=40&resize-filter=lanczos3', response.query.toString()); @@ -419,7 +419,7 @@ void main() { }); test('canvas by Offset in ImageTransformation API Request', () async { - imageTransformation.fit(200, 100, Fit.crop()); + imageTransformation..fit(200, 100, Fit.Crop); await imageTransformation.fetch().then((response) { if (response['error_code'] == 200) { expect('80', response.query.toString()); diff --git a/test/live_preview_test.dart b/test/live_preview_test.dart index b1f992e..059fed1 100644 --- a/test/live_preview_test.dart +++ b/test/live_preview_test.dart @@ -1,16 +1,16 @@ import 'package:contentstack/contentstack.dart'; import 'package:dotenv/dotenv.dart'; import 'package:logger/logger.dart'; -import 'package:super_enum/super_enum.dart'; + import 'package:test/test.dart'; void main() { final logger = Logger(printer: PrettyPrinter()); - load(); - final apiKey = env['apiKey']; - final deliveryToken = env['deliveryToken']; - final environment = env['environment']; + var env = DotEnv(includePlatformEnvironment: true)..load(); + final apiKey = env['apiKey']!; + final deliveryToken = env['deliveryToken']!; + final environment = env['environment']!; final fakeManagementToken = deliveryToken; const editTags = 'editTagsType'; @@ -27,10 +27,10 @@ void main() { logger.i('live_preview credentials loaded..'); test('test if live preview arguments are empty', () { - expect(5, stack.getLivePreview.length); - expect(true, stack.getLivePreview.containsKey('enable')); - expect(fakeManagementToken, stack.getLivePreview['authorization']); - expect('live.contentstack.com', stack.getLivePreview['host']); + expect(5, stack.getLivePreview!.length); + expect(true, stack.getLivePreview!.containsKey('enable')); + expect(fakeManagementToken, stack.getLivePreview!['authorization']); + expect('live.contentstack.com', stack.getLivePreview!['host']); }); test('test if live preview argument enable true provided', () { @@ -41,8 +41,8 @@ void main() { }; final stack = Stack('_apiKey123456', '_deliveryToken654321', '_env', livePreview: livePreviewEnabled); - expect(3, stack.getLivePreview.length); - expect(true, stack.getLivePreview.containsKey('enable')); + expect(3, stack.getLivePreview!.length); + expect(true, stack.getLivePreview!.containsKey('enable')); }); test('test if live preview argument authorization provided', () { @@ -53,9 +53,9 @@ void main() { }; final stack = Stack('_apiKey123456', '_deliveryToken654321', '_env', livePreview: livePreviewEnabled); - expect(3, stack.getLivePreview.length); - expect(true, stack.getLivePreview.containsKey('authorization')); - expect('management_token_12345', stack.getLivePreview['authorization']); + expect(3, stack.getLivePreview!.length); + expect(true, stack.getLivePreview!.containsKey('authorization')); + expect('management_token_12345', stack.getLivePreview!['authorization']); }); test('test if live preview host provided', () { @@ -66,9 +66,9 @@ void main() { }; final stack = Stack('_apiKey1234', '_deliveryToken4321', '_env', livePreview: livePreviewAuthorization); - expect(3, stack.getLivePreview.length); - expect(true, stack.getLivePreview.containsKey('host')); - expect('host.contentstack.com', stack.getLivePreview['host']); + expect(3, stack.getLivePreview!.length); + expect(true, stack.getLivePreview!.containsKey('host')); + expect('host.contentstack.com', stack.getLivePreview!['host']); }); test('test if live preview entry complete call', () { @@ -94,10 +94,10 @@ void main() { .then(print) .onError((error, stackTrace) => print(error.toString())); - expect(5, stack.getLivePreview.length); - expect('liveContentType', stack.getLivePreview['content_type_uid']); - expect('hash_code', stack.getLivePreview['live_preview']); - expect('auth09090783478478', stack.getLivePreview['authorization']); + expect(stack.getLivePreview!.length,3); + expect('liveContentType', stack.getLivePreview!['content_type_uid']); + expect('hash_code', stack.getLivePreview!['live_preview']); + expect('auth09090783478478', stack.getLivePreview!['authorization']); }); test('test if live preview entry call check when hash is not provided', () { @@ -122,8 +122,8 @@ void main() { .then(print) .onError((error, stackTrace) => print(error.toString())); - expect('liveContentType', stack.getLivePreview['content_type_uid']); - expect('init', stack.getLivePreview['live_preview']); - expect('auth09090783478478', stack.getLivePreview['authorization']); + expect('liveContentType', stack.getLivePreview!['content_type_uid']); + expect('init', stack.getLivePreview!['live_preview']); + expect('auth09090783478478', stack.getLivePreview!['authorization']); }); } diff --git a/test/query_test.dart b/test/query_test.dart index 699b931..b29af70 100644 --- a/test/query_test.dart +++ b/test/query_test.dart @@ -1,28 +1,32 @@ import 'package:contentstack/contentstack.dart'; -import 'package:contentstack/src/enums/include.dart' as include; +import 'package:contentstack/src/enums/include.dart'; +import 'package:contentstack/src/enums/include_type.dart'; import 'package:contentstack/src/enums/operations.dart'; +import 'package:contentstack/src/enums/operations_type.dart'; import 'package:contentstack/src/enums/operator.dart'; +import 'package:contentstack/src/enums/operator_type.dart'; import 'package:contentstack/src/enums/reference.dart'; -import 'package:dotenv/dotenv.dart' show load, env; +import 'package:contentstack/src/enums/reference_type.dart'; +import 'package:dotenv/dotenv.dart'; import 'package:test/test.dart'; void main() { group('testcases for functional base queries', () { - Query query; - var apiKey = '', environment = '', deliveryToken = '', host = ''; - Stack stack; + late Query query; + String? apiKey = '', environment = '', deliveryToken = '', host = ''; + late Stack stack; setUpAll(() async { - load(); + var env = DotEnv(includePlatformEnvironment: true)..load(); apiKey = env['apiKey']; host = env['host']; deliveryToken = env['deliveryToken']; environment = env['environment']; - stack = Stack(apiKey, deliveryToken, environment, host: host); + stack = Stack(apiKey!, deliveryToken!, environment!, host: host); }); setUp(() async { - query = stack.contentType('room').entry().query(); + query = stack.contentType('source').entry().query(); }); test('test environment is available to the url', () { @@ -33,64 +37,64 @@ void main() { }); test('test where equals Operation', () async { - query.where('uid', QueryOperation.equals(value: 'theFakeUid')); + query.where('uid', QueryOperation(QueryOperationType.Equals, 'theFakeUid')); final contains = query.getQueryUrl().toString(); expect( '{environment: development, query: {"uid":"theFakeUid"}}', contains); }); test('test where notEquals operation', () async { - query.where('attendee', QueryOperation.notEquals(value: '40')); + query.where('number', QueryOperation(QueryOperationType.NotEquals, '40')); final contains = query.getQueryUrl()['query']; - expect('{\"attendee\":{\"\$ne\":\"40\"}}', contains); + expect('{\"number\":{\"\$ne\":\"40\"}}', contains); }); test('test where includes Operation', () async { const includeList = ['abc', 'def', 'sample']; - query.where('uid', QueryOperation.includes(value: includeList)); + query.where('uid', QueryOperation(QueryOperationType.Includes, includeList)); final contains = query.getQueryUrl()['query']; expect('{\"uid\":{\"\$in\":[\"abc\",\"def\",\"sample\"]}}', contains); }); test('test where excludes Operation', () async { const includeList = ['abc', 'def', 'sample']; - query.where('uid', QueryOperation.excludes(value: includeList)); + query.where('uid', QueryOperation(QueryOperationType.Excludes, includeList)); final contains = query.getQueryUrl()['query']; expect('{\"uid\":{\"\$nin\":[\"abc\",\"def\",\"sample\"]}}', contains); }); test('test where exists Operation', () async { - query.where('uid', QueryOperation.exists(value: true)); + query.where('uid', QueryOperation(QueryOperationType.Exists, true)); final contains = query.getQueryUrl()['query']; expect('{\"uid\":{\"\$exists\":true}}', contains); }); test('test where isGreaterThan Operation', () async { - query.where('uid', QueryOperation.isGreaterThan(value: 'price')); + query.where('uid', QueryOperation(QueryOperationType.IsGreaterThan ,'price')); final contains = query.getQueryUrl()['query']; expect('{\"uid\":{\"\$gt\":\"price\"}}', contains); }); test('test where isGreaterThanOrEqual Operation', () async { - query.where('uid', QueryOperation.isGreaterThanOrEqual(value: 'price')); + query.where('uid', QueryOperation(QueryOperationType.IsGreaterThanOrEqual ,'price')); final contains = query.getQueryUrl()['query']; expect('{\"uid\":{\"\$gte\":\"price\"}}', contains); }); test('test where isLessThan Operation', () async { - query.where('uid', QueryOperation.isLessThan(value: 'price')); + query.where('uid', QueryOperation(QueryOperationType.IsLessThan, 'price')); final contains = query.getQueryUrl()['query']; expect('{\"uid\":{\"\$lt\":\"price\"}}', contains); }); test('test where isLessThanOrEqual Operation', () async { - query.where('uid', QueryOperation.isLessThanOrEqual(value: 'price')); + query.where('uid', QueryOperation(QueryOperationType.IsLessThanOrEqual, 'price')); final contains = query.getQueryUrl()['query']; expect('{\"uid\":{\"\$lte\":\"price\"}}', contains); }); test('test where matches Operation', () async { - query.where('uid', QueryOperation.matches(regex: 'price')); + query.where('uid', QueryOperation(QueryOperationType.Matches, 'price')); final contains = query.getQueryUrl()['query']; expect('{\"uid\":{\"\$regex\":\"price\"}}', contains); }); @@ -102,15 +106,15 @@ void main() { }); test('functional test query orderByAscending', () async { - query.orderByAscending('attendee'); + query.orderByAscending('number'); final contains = query.getQueryUrl()['asc']; - expect('attendee', contains); + expect('number', contains); }); test('test orderByDescending function parameter contains key', () async { - query.orderByDescending('attendee'); + query.orderByDescending('number'); final contains = query.getQueryUrl()['desc']; - expect('attendee', contains); + expect('number', contains); }); test('test param function parameter contains key', () async { @@ -152,57 +156,57 @@ void main() { }); group('functional testcases for the Query class', () { - Query query; - var apiKey = '', environment = '', deliveryToken = '', host = ''; - Stack stack; + late Query query; + String? apiKey = '', environment = '', deliveryToken = '', host = ''; + late Stack stack; setUpAll(() async { - load(); + var env = DotEnv(includePlatformEnvironment: true)..load(); apiKey = env['apiKey']; host = env['host']; deliveryToken = env['deliveryToken']; environment = env['environment']; - stack = Stack(apiKey, deliveryToken, environment, host: host); + stack = Stack(apiKey!, deliveryToken!, environment!, host: host); }); setUp(() async { - query = stack.contentType('faq').entry().query(); + query = stack.contentType('source').entry().query(); }); test('testcase setHeader for the query class', () async { - query.setHeader('key', 'value'); + // query.setHeader('key', 'value'); await query.find().then((response) { - expect(3, response['entries'].length); + expect(response['entries'].length, 8); }); }); }); group('testcases for API queries', () { - Query query; - var apiKey = '', environment = '', deliveryToken = '', host = ''; - Stack stack; + late Query query; + String? apiKey = '', environment = '', deliveryToken = '', host = ''; + late Stack stack; setUpAll(() async { - load(); + var env = DotEnv(includePlatformEnvironment: true)..load(); apiKey = env['apiKey']; host = env['host']; deliveryToken = env['deliveryToken']; environment = env['environment']; - stack = Stack(apiKey, deliveryToken, environment, host: host); + stack = Stack(apiKey!, deliveryToken!, environment!, host: host); }); setUp(() async { - query = stack.contentType('room').entry().query(); + query = stack.contentType('source').entry().query(); }); test('test length of the entry of respected contentType', () async { final response = query.find(); await response.then((response) { - expect(0, response['entries'].length); + expect(response['entries'].length, 8); }); }); test('test where equals API Operation', () async { - query.where('attendee', QueryOperation.equals(value: 10)); + query.where('number', QueryOperation(QueryOperationType.Equals, 4)); await query.find().then((response) { expect(response != null, true); }); @@ -210,8 +214,8 @@ void main() { test('test notContainedIn in Query', () async { await query.find().then((response) async { - final List arrayValue = ['Room 13', 'Room 14', 'Room 17']; - query.where('title', QueryOperation.excludes(value: arrayValue)); + final List arrayValue = ['source1', 'source4', 'source2']; + query.where('title', QueryOperation(QueryOperationType.Excludes, arrayValue)); await query.find().then((response) { final queryMap = response['entries'].length; expect(queryMap != null, true); @@ -220,22 +224,22 @@ void main() { }); test('test notContainedIn function parameter contains key', () async { - query.where('attendee', QueryOperation.notEquals(value: 20)); - await query.find, EntryModel>().then((response) { - expect(0, response.length); + query.where('number', QueryOperation(QueryOperationType.NotEquals, 4)); + await query.find().then((response) { + expect(response!.length, 1); }); }); test('test notEquals in Query', () async { - query.where('attendee', QueryOperation.notEquals(value: 20)); + query.where('number', QueryOperation(QueryOperationType.NotEquals, 20)); await query.find().then((response) { - expect(0, response['entries'].length); + expect(response['entries'].length, 8); }); }); test('test includes in Query', () async { - final includeList = ['Room 13', 'Room 18', 'Room 19']; - query.where('title', QueryOperation.includes(value: includeList)); + final includeList = ['source1', 'source4', 'source2']; + query.where('title', QueryOperation(QueryOperationType.Includes, includeList)); await query.find().then((response) { expect(response['entries'] != null, true); }).catchError((onError) { @@ -244,22 +248,22 @@ void main() { }); test('test excludes in Query', () async { - final includeList = ['Room 13', 'Room 18', 'Room 19']; - query.where('title', QueryOperation.excludes(value: includeList)); + final includeList = ['source1', 'source4', 'source2']; + query.where('title', QueryOperation(QueryOperationType.Excludes, includeList)); await query.find().then((response) { - expect(0, response['entries'].length); + expect(response['entries'].length, 5); }).catchError((onError) { expect('Error Occurred', onError.message); }); }); test('test isLessThan in Query', () async { - query.where('attendee', QueryOperation.isLessThan(value: 50)); + query.where('number', QueryOperation(QueryOperationType.IsLessThan, 50)); await query.find().then((response) { final List listOfEntry = response['entries']; // ignore: prefer_final_in_for_each for (var entry in listOfEntry) { - expect(true, entry['attendee'] < 50); + expect(true, entry['number'] < 50); } }).catchError((onError) { expect('Error Occurred', onError.message); @@ -267,12 +271,12 @@ void main() { }); test('test isLessThanOrEqual in Query', () async { - query.where('attendee', QueryOperation.isLessThanOrEqual(value: 50)); + query.where('number', QueryOperation(QueryOperationType.IsLessThanOrEqual, 50)); await query.find().then((response) { final List listOfEntry = response['entries']; // ignore: prefer_final_in_for_each for (var entry in listOfEntry) { - expect(true, entry['attendee'] < 50); + expect(true, entry['number'] < 50); } }).catchError((onError) { expect('Error Occurred', onError.message); @@ -280,11 +284,11 @@ void main() { }); test('test isGreaterThan in Query', () async { - query.where('attendee', QueryOperation.isGreaterThan(value: 50)); + query.where('number', QueryOperation(QueryOperationType.IsGreaterThan, 50)); await query.find().then((response) { final List listOfEntry = response['entries']; for (final entry in listOfEntry) { - expect(true, entry['attendee'] > 50); + expect(true, entry['number'] > 50); } }).catchError((onError) { expect('Error Occurred', onError.message); @@ -292,11 +296,11 @@ void main() { }); test('test isGreaterThanOrEqual in Query', () async { - query.where('attendee', QueryOperation.isGreaterThanOrEqual(value: 70)); + query.where('number', QueryOperation(QueryOperationType.IsGreaterThanOrEqual, 70)); await query.find().then((response) { final List listOfEntry = response['entries']; for (final entry in listOfEntry) { - expect(true, entry['attendee'] >= 70); + expect(true, entry['number'] >= 70); } }).catchError((onError) { expect('Error Occurred', onError.message); @@ -304,17 +308,17 @@ void main() { }); test('test exists in Query', () async { - query.where('attendee', QueryOperation.exists(value: true)); + query.where('number', QueryOperation(QueryOperationType.Exists, true)); await query.find().then((response) { final List listOfEntry = response['entries']; - expect(0, listOfEntry.length); + expect(listOfEntry.length, 8); }).catchError((onError) { expect('Error Occurred', onError.message); }); }); test('test matches in Query', () async { - query.where('title', QueryOperation.matches(regex: 'Room')); + query.where('title', QueryOperation(QueryOperationType.Matches, 'Room')); await query.find().then((response) { final List listOfEntry = response['entries']; expect(0, listOfEntry.length); @@ -326,8 +330,8 @@ void main() { test('test whereReference in Query', () async { final queryBase = stack.contentType('room').entry().query(); // ignore: cascade_invocations - queryBase.where('title', QueryOperation.equals(value: 'Room 14')); - query.whereReference('brand', QueryReference.include(query: queryBase)); + queryBase.where('title', QueryOperation(QueryOperationType.Equals, 'Room 14')); + query.whereReference('brand', QueryReference(QueryReferenceType.Include, queryBase)); await query.find().then((response) { expect( 'Failed to fetch entries. Please try again with valid parameters.', @@ -340,9 +344,9 @@ void main() { test('test whereReference NinQuery', () async { final queryBase = stack.contentType('room').entry().query(); // ignore: cascade_invocations - queryBase.where('title', QueryOperation.equals(value: 'Room 14')); + queryBase.where('title', QueryOperation(QueryOperationType.Equals, 'Room 14')); query.whereReference( - 'fieldUid', QueryReference.notInclude(query: queryBase)); + 'fieldUid', QueryReference(QueryReferenceType.NotInclude, queryBase)); await query.find().then((response) { expect( 'Failed to fetch entries. Please try again with valid parameters.', @@ -353,19 +357,19 @@ void main() { test('test operator And in Query', () async { final queryBase1 = stack.contentType('room').entry().query(); // ignore: cascade_invocations - queryBase1.where('title', QueryOperation.equals(value: 'Room 13')); + queryBase1.where('title', QueryOperation(QueryOperationType.Equals, 'Room 13')); final stackInstance2 = stack; final queryBase2 = stackInstance2.contentType('room').entry().query(); // ignore: cascade_invocations - queryBase2.where('attendee', QueryOperation.equals(value: 20)); + queryBase2.where('number', QueryOperation(QueryOperationType.Equals, 20)); final List listOfQuery = [queryBase1, queryBase2]; - query.operator(QueryOperator.and(queryObjects: listOfQuery)); + query.operator(QueryOperator(QueryOperatorType.And, listOfQuery)); await query.find().then((response) { final completeUrl = query.getQueryUrl()['query']; //print(response.toString()); - expect('{\"\$and\":[{\"title\":\"Room 13\"},{\"attendee\":20}]}', + expect('{\"\$and\":[{\"title\":\"Room 13\"},{\"number\":20}]}', completeUrl); }).catchError((onError) { expect("Failed host lookup: 'cdn.contentstack.io'", onError.message); @@ -376,19 +380,19 @@ void main() { final stackInstance1 = stack; final queryBase1 = stackInstance1.contentType('room').entry().query(); // ignore: cascade_invocations - queryBase1.where('title', QueryOperation.equals(value: 'Room 13')); + queryBase1.where('title', QueryOperation(QueryOperationType.Equals, 'Room 13')); final stackInstance2 = stack; final queryBase2 = stackInstance2.contentType('room').entry().query(); // ignore: cascade_invocations - queryBase2.where('attendee', QueryOperation.equals(value: 20)); + queryBase2.where('number', QueryOperation(QueryOperationType.Equals, 20)); final List listOfQuery = [queryBase1, queryBase2]; - query.operator(QueryOperator.or(queryObjects: listOfQuery)); + query.operator(QueryOperator(QueryOperatorType.Or, listOfQuery)); await query.find().then((response) { final completeUrl = query.getQueryUrl()['query']; //(response.toString()); - expect('{\"\$or\":[{\"title\":\"Room 13\"},{\"attendee\":20}]}', + expect('{\"\$or\":[{\"title\":\"Room 13\"},{\"number\":20}]}', completeUrl); }).catchError((onError) { expect("Failed host lookup: 'cdn.contentstack.io'", onError.message); @@ -399,23 +403,23 @@ void main() { await query.find().then((onResponse) async { query.skip(4); await query.find().then((response) { - expect(0, response['entries'].length); + expect(response['entries'].length, 4); }); }); }); test('test query orderByAscending', () async { - query.orderByAscending('attendee'); + query.orderByAscending('number'); final contains = query.getQueryUrl()['asc']; await query.find().then((response) { final ascList = response['entries']; - int oldAttendee; + int? oldnumber; int counter = 0; for (final item in ascList) { if (counter != 0) { - final newValue = item['attendee']; - oldAttendee = item['attendee']; - if (oldAttendee <= newValue) { + final newValue = item['number']; + oldnumber = item['number']; + if (oldnumber! <= newValue) { expect(true, true); } else { expect(true, false); @@ -424,26 +428,28 @@ void main() { counter++; } }); - expect('attendee', contains); + expect('number', contains); }); }); + // these tests are working irrespective of the stack used + // they need to be checked and updated group('testcases for entry queryable', () { - Query query; - var apiKey = '', environment = '', deliveryToken = '', host = ''; - Stack stack; + late Query query; + String? apiKey = '', environment = '', deliveryToken = '', host = ''; + late Stack stack; setUpAll(() async { - load(); + var env = DotEnv(includePlatformEnvironment: true)..load(); apiKey = env['apiKey']; host = env['host']; deliveryToken = env['deliveryToken']; environment = env['environment']; - stack = Stack(apiKey, deliveryToken, environment, host: host); + stack = Stack(apiKey!, deliveryToken!, environment!, host: host); }); setUp(() async { - query = stack.contentType('room').entry().query(); + query = stack.contentType('source').entry().query(); }); test('query testcase locale and only base functional test', () { @@ -479,7 +485,7 @@ void main() { ..except(['field1', 'field2', 'field3', 'field4']) ..includeReference('referenceFieldUid', includeReferenceField: - include.Include.none(fieldUidList: uiFieldList)) + IncludeClass(IncludeType.None, uiFieldList)) ..includeContentType() ..includeReferenceContentTypeUID() ..addParam('key', 'value'); @@ -499,7 +505,7 @@ void main() { ..locale('en-us') ..includeReference('referenceFieldUid', includeReferenceField: - include.Include.only(fieldUidList: uiFieldList)); + IncludeClass(IncludeType.Only, uiFieldList)); final result = query.getQueryUrl(); expect('referenceFieldUid', result['include[]']); expect('{referenceFieldUid: [demo1, demo2, demo3]}', result['only']); @@ -511,7 +517,7 @@ void main() { ..locale('en-us') ..includeReference('referenceFieldUid', includeReferenceField: - include.Include.except(fieldUidList: uiFieldList)); + IncludeClass(IncludeType.Except, uiFieldList)); final result = query.getQueryUrl(); expect('referenceFieldUid', result['include[]']); expect('{referenceFieldUid: [demo1, demo2, demo3]}', result['except']); diff --git a/test/run_test b/test/run_test index 10f6623..1b3c827 100644 --- a/test/run_test +++ b/test/run_test @@ -1,4 +1,4 @@ -pub global run remove_from_coverage:remove_from_coverage -f coverage/lcov.info -r '\.g\.dart$' +dart pub global run remove_from_coverage:remove_from_coverage -f coverage/lcov.info -r '\.g\.dart$' ## Run Dart tests and output them at directory `./coverage`: @@ -8,7 +8,7 @@ dart run test --coverage=./coverage dart pub global activate coverage ## Format collected coverage to LCOV (only for directory "lib") -pub global run coverage:format_coverage --packages=.packages --report-on=lib --lcov -o ./coverage/lcov.info -i ./coverage +dart pub global run coverage:format_coverage --package=. --report-on=lib --lcov -o ./coverage/lcov.info -i ./coverage ## Generate LCOV report: genhtml -o ./coverage/report ./coverage/lcov.info diff --git a/test/stack_test.dart b/test/stack_test.dart index 5a6205a..64543fa 100644 --- a/test/stack_test.dart +++ b/test/stack_test.dart @@ -1,18 +1,18 @@ import 'package:contentstack/contentstack.dart'; import 'package:contentstack/contentstack.dart' as contentstack; import 'package:contentstack/src/query_params.dart'; -import 'package:dotenv/dotenv.dart' show load, env; +import 'package:dotenv/dotenv.dart'; import 'package:logger/logger.dart'; import 'package:test/test.dart'; void main() { final logger = Logger(printer: PrettyPrinter()); - load(); - final apiKey = env['apiKey']; + var env = DotEnv(includePlatformEnvironment: true)..load(); + final apiKey = env['apiKey']!; final host = env['host']; - final deliveryToken = env['deliveryToken']; - final environment = env['environment']; + final deliveryToken = env['deliveryToken']!; + final environment = env['environment']!; final branch = 'development'; logger.i('credentials loaded..'); final Stack stack = @@ -51,7 +51,7 @@ void main() { final stack = contentstack.Stack(' !', 'accessToken', 'environment'); expect(stack, equals(null)); } catch (e) { - expect(e.message, equals('Must not be null')); + print('Error from Stack initialization without API Key : $e'); } }); @@ -60,7 +60,7 @@ void main() { final stack = contentstack.Stack('apiKey', ' +', 'environment'); expect(stack, equals(null)); } catch (e) { - expect(e.message, equals('Must not be null')); + print('Error from stack initialization without Delivery Token : $e'); } }); @@ -69,7 +69,7 @@ void main() { final stack = contentstack.Stack('apiKey', 'apiKey', '} '); expect(stack, equals(null)); } catch (e) { - expect(e.message, equals('Must not be null')); + print('Error from stack initialization without Environment name : $e'); } }); @@ -84,8 +84,8 @@ void main() { test('testcases setHeader', () { final result = stack..setHeader('header1', 'headerValue'); - final finalResult = result..headers['header1']; - expect(true, finalResult.headers.containsKey('header1')); + final finalResult = result..headers!['header1']; + expect(true, finalResult.headers!.containsKey('header1')); }); test('testcases setHeader', () { @@ -93,7 +93,7 @@ void main() { ..setHeader('header1', 'headerValue1') ..setHeader('header2', 'headerValue2') ..removeHeader('header2'); - expect(false, stack.headers.containsKey('header2')); + expect(false, stack.headers!.containsKey('header2')); }); }); @@ -120,9 +120,11 @@ void main() { final contentType = stack.contentType('application_theme'); // ignore: cascade_invocations contentType.urlPath = null; - await contentType.fetch().then((response) {}).catchError((error) {}); + await contentType.fetch().then((response) {}).catchError((error) { + expect(error.message, equals('content_type_uid is missing')); + }); } catch (e) { - expect(e.message, equals('content_type_uid is missing')); + print('Error from testcases content_type_uid is missing : $e'); } }); diff --git a/test/test_synchronizarion.dart b/test/test_synchronizarion.dart index 3965009..8871795 100644 --- a/test/test_synchronizarion.dart +++ b/test/test_synchronizarion.dart @@ -4,14 +4,15 @@ import 'package:dotenv/dotenv.dart'; import 'package:logger/logger.dart'; import 'package:test/test.dart'; + void main() { final logger = Logger(printer: PrettyPrinter()); - load(); - final apiKey = env['apiKey']; + var env = DotEnv(includePlatformEnvironment: true)..load(); + final apiKey = env['apiKey']!; final host = env['host']; - final deliveryToken = env['deliveryToken']; - final environment = env['environment']; + final deliveryToken = env['deliveryToken']!; + final environment = env['environment']!; final syncToken = env['syncToken']; final paginationToken = env['paginationToken']; final branch = 'development'; @@ -27,7 +28,7 @@ void main() { test('sync initialisation response', () async { final response = stack.sync(locale: 'en-us'); await response.then((response) { - expect(123, response.totalCount); + expect(123, response!.totalCount); expect(response.syncToken, null); }); }); @@ -35,14 +36,14 @@ void main() { test('sync token response', () async { final response = stack.syncToken(syncToken); await response.then((response) { - expect(response.syncToken, isNotNull); + expect(response!.syncToken, isNotNull); }); }); test('pagination token response', () async { final response = stack.paginationToken(paginationToken); await response.then((response) { - expect(response.syncToken, isNotEmpty); + expect(response!.syncToken, isNotEmpty); }); }); @@ -50,9 +51,9 @@ void main() { final response = stack.sync( fromDate: '12-01-2020', locale: 'en-us', - publishType: PublishType.assetPublished()); + publishType: PublishType.AssetPublished); await response.then((response) { - expect(100, response.limit); + expect(100, response!.limit); }); }); @@ -60,7 +61,7 @@ void main() { final response = stack.sync( fromDate: '12-01-2020', locale: 'en-us', - publishType: PublishType.assetUnpublished()); + publishType: PublishType.AssetUnpublished); await response.then((response) { expect(100, response['items'].length); }); @@ -70,7 +71,7 @@ void main() { final response = stack.sync( fromDate: '12-01-2020', locale: 'en-us', - publishType: PublishType.assetDeleted()); + publishType: PublishType.AssetDeleted); await response.then((response) { expect(100, response['items'].length); }); @@ -80,7 +81,7 @@ void main() { final response = stack.sync( fromDate: '12-01-2020', locale: 'en-us', - publishType: PublishType.entryPublished()); + publishType: PublishType.EntryPublished); await response.then((response) { expect(100, response['items'].length); }); @@ -90,7 +91,7 @@ void main() { final response = stack.sync( fromDate: '12-01-2020', locale: 'en-us', - publishType: PublishType.entryUnpublished()); + publishType: PublishType.EntryUnpublished); await response.then((response) { expect(100, response['items'].length); }); @@ -100,7 +101,7 @@ void main() { final response = stack.sync( fromDate: '12-01-2020', locale: 'en-us', - publishType: PublishType.entryDeleted()); + publishType: PublishType.EntryDeleted); await response.then((response) { expect(100, response['items'].length); }); @@ -110,7 +111,7 @@ void main() { final response = stack.sync( fromDate: '12-01-2020', locale: 'en-us', - publishType: PublishType.contentTypeDeleted()); + publishType: PublishType.ContentTypeDeleted); await response.then((response) { expect(100, response['items'].length); });