Skip to content

Add bunch of models, Improve project file structure, Fix docs for enums #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
29fc2ed
Add Response data type
vasya-polyansky Dec 14, 2020
3b20e1c
Add Response export
vasya-polyansky Dec 14, 2020
53543b0
Add UserInfo data type
vasya-polyansky Dec 14, 2020
bdf4338
Add make fields required in UserInfo
vasya-polyansky Dec 14, 2020
bd97935
Add Message, MessageContent and improve docs in Response and UserInfo
vasya-polyansky Dec 15, 2020
71d8393
Add warning docs on manual implementations.
vasya-polyansky Dec 15, 2020
c55fd7b
Fix message id field name in Message
vasya-polyansky Dec 15, 2020
1655244
Rebuild generated code for Message
vasya-polyansky Dec 15, 2020
74ba7d6
Add generic serialization to Response
vasya-polyansky Dec 18, 2020
e1192a2
Add WebsocketEvent
vasya-polyansky Dec 18, 2020
cffbd0b
Add export of WebsocketEvent
vasya-polyansky Dec 18, 2020
276e4ae
Add DateTimeConverted on time field in MarkupEntity
vasya-polyansky Dec 18, 2020
ba9f5f8
Fix type for time field in MarkupEntity
vasya-polyansky Dec 18, 2020
8e3c757
Re-generate code for mock message
vasya-polyansky Dec 25, 2020
dabbac2
Add Features, IceServer and Terms
vasya-polyansky Dec 25, 2020
ef10285
Fix enum docs
vasya-polyansky Dec 25, 2020
96cc9ec
Remove outdated tests
vasya-polyansky Dec 25, 2020
3a8615d
Add license
vasya-polyansky Dec 25, 2020
7d85e37
Adjust dependencies in pubspec.yaml
vasya-polyansky Dec 25, 2020
a15711c
Add MessageContent, MessageSubtype, MessageType
vasya-polyansky Dec 25, 2020
3bfac9f
Remake Message, Add MessageLink, MessageLinkPreview, MessageReaction,…
vasya-polyansky Dec 25, 2020
42991da
Improve project file structure
vasya-polyansky Dec 25, 2020
56a3f4f
Add none value to MediaSubtype enum, Remove deprecated enum values
vasya-polyansky Dec 25, 2020
e6ca0a7
Add information to pubspec.yaml
vasya-polyansky Dec 25, 2020
3ade363
Remove flutter remainders from project
vasya-polyansky Dec 25, 2020
3439476
Add analysis_options.yaml and remove unused imports
vasya-polyansky Dec 25, 2020
153aa21
Set version 1.0.0-dev.1 in pubspec.yaml and Add description in README.md
vasya-polyansky Dec 25, 2020
ca7b583
Update README.md
vasya-polyansky Dec 25, 2020
244805d
And pub badge and license badge to README.md
vasya-polyansky Dec 25, 2020
0580ce1
Merge remote-tracking branch 'origin/master' into dev
vasya-polyansky Dec 25, 2020
edc7ad4
Fix typo in README.md
vasya-polyansky Dec 25, 2020
97ee0fd
Change license badge color in README.md
vasya-polyansky Dec 25, 2020
f665be7
Exclude deprecated_member_use_from_same_package rule for analyzer
vasya-polyansky Dec 25, 2020
810087e
Add features.dart to export
vasya-polyansky Dec 25, 2020
272ff21
Add example and make the package description longer
vasya-polyansky Dec 27, 2020
d3fb30b
Set version to 1.0.1-dev and Update CHANGELOG.md
vasya-polyansky Dec 27, 2020
f667f15
Fix throwsA matcher for non-nullability test
vasya-polyansky Dec 27, 2020
93c2613
docs(changelog): make the changelog format follow Keep a changelog co…
vasya-polyansky Jan 12, 2021
4ee28e3
feat(models): add User model
vasya-polyansky Jan 12, 2021
23491e8
docs(changelog): update changelog about User model
vasya-polyansky Jan 12, 2021
20edb42
fix(changelog): small fix of header
vasya-polyansky Jan 23, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 5 additions & 49 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,58 +20,14 @@
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
# Files and directories created by pub
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
build/

# Android related
**/android/**/gradle-wrapper.jar
**/android/.gradle
**/android/captures/
**/android/gradlew
**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java

# iOS/XCode related
**/ios/**/*.mode1v3
**/ios/**/*.mode2v3
**/ios/**/*.moved-aside
**/ios/**/*.pbxuser
**/ios/**/*.perspectivev3
**/ios/**/*sync/
**/ios/**/.sconsign.dblite
**/ios/**/.tags*
**/ios/**/.vagrant/
**/ios/**/DerivedData/
**/ios/**/Icon?
**/ios/**/Pods/
**/ios/**/.symlinks/
**/ios/**/profile
**/ios/**/xcuserdata
**/ios/.generated/
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Flutter.podspec
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/app.flx
**/ios/Flutter/app.zip
**/ios/Flutter/flutter_assets/
**/ios/Flutter/flutter_export_environment.sh
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*
# Conventional directory for build outputs
build/

# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
# Directory created by dartdoc
doc/api/

pubspec.lock
.fvm
10 changes: 0 additions & 10 deletions .metadata

This file was deleted.

41 changes: 39 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
## [0.0.1] - TODO: Add release date.
# Changelog

* TODO: Describe initial release.

## [Unreleased]
### Added
- Add `User` model.


## [1.0.1-dev] - 2020-12-27
### Added
- Add `Features` export to `lib/tdproto_dart.dart`.
- Add example folder.

### Fixed
- Make `deprecated_member_use_from_same_package` analysis rule excluded.


## [1.0.0-dev.1] - 2020-12-25
### Added
- Initial Version of the library.


---


All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

<!--
## Types of changes

- `Added` for new features.
- `Changed` for changes in existing functionality.
- `Deprecated` for soon-to-be removed features.
- `Removed` for now removed features.
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.
-->
22 changes: 21 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
TODO: Add your license here.
MIT License

Copyright (c) 2020 tada.team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<a href="https://pub.dev/packages/tdproto_dart"><img src="https://img.shields.io/pub/v/tdproto_dart.svg" alt="Pub"></a>
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License: MIT"></a>

# tdproto_dart

Autogenerated Tada API data types for dart.

- Autogenerated by [tdproto](https://github.com/tada-team/tdproto) from go code.
- Powered by [freezed](https://pub.dev/packages/freezed), includes all its features.
- Powered by [freezed](https://pub.dev/packages/freezed), includes all it's features.
- Synced with server data types structure and documentation.
- Has a big brother for TypeScript - [tdproto-ts](https://github.com/tada-team/tdproto-ts).

Expand Down
7 changes: 7 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include: package:pedantic/analysis_options.1.9.0.yaml

analyzer:
errors:
# Required to use the deprecation annotation on fields in this package and
# in the same time avoid issues with generated code by json_serializable.
deprecated_member_use_from_same_package: ignore
16 changes: 6 additions & 10 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@ targets:
options:
# Options configure how source code is generated for every
# `@JsonSerializable`-annotated class in the package.
any_map: false
checked: false
create_factory: true
create_to_json: true
disallow_unrecognized_keys: false

# If true, generated toJson methods will explicitly call toJson on nested objects.
explicit_to_json: true
field_rename: none
generic_argument_factories: false
ignore_unannotated: false
include_if_null: true
nullable: true

# When true on classes with type parameters (generic types),
# extra "helper" parameters will be generated for fromJson and/or toJson
# to support serializing values of those types.
generic_argument_factories: true
142 changes: 142 additions & 0 deletions example/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import 'package:test/test.dart';
import 'package:tdproto_dart/tdproto_dart.dart';

const _messageJson = {
'content': {
'text': 'Hello',
'type': 'plain',
'subtype': 'none',
},
'push_text': 'Hello',
'from': 'd-42d35f81-daad-4a5b-8429-a4b47c6b43ae',
'to': 't-8b8be02d-ca65-40eb-afb0-c3d230332534',
'message_id': '19353ae1-ee16-404f-bc0a-95be4c18a153',
'created': '2020-12-27T09:21:14.796246Z',
'gentime': 1609060874796244743,
'chat_type': 'task',
'chat': 't-8b8be02d-ca65-40eb-afb0-c3d230332534',
'links': [],
'prev': '8a290ace-d8b7-4180-b052-9d8b31ab685c',
'silently': true,
'editable_until': '3000-01-01T00:00:00.000000Z',
'num': 8
};

const _pdfVersionJson = {
'url': 'SOME_URL',
'text_preview': 'sample',
};

const _jsonResponse = {
'_time': '918ms',
'ok': true,
'result': _pdfVersionJson,
};

void main() {
group('tdproto features:', () {
final message = Message.fromJson(_messageJson);

test('enums', () {
// in IDE you get the documentation about any field
message.created;
// in IDE you get the deprecation warnings about deprecated fields due to @Deprecated annotation
message.content.mediaUrl;

expect(message.content.subtype, MediaSubtype.none);
});

test('generic response serialization', () {
// arrange
final handwrittenResponse = Response(
time: _jsonResponse['_time'],
ok: _jsonResponse['ok'],
result: PdfVersion(
url: (_jsonResponse['result'] as Map)['url'],
textPreview: (_jsonResponse['result'] as Map)['text_preview'],
),
);
// act
final serializedResponse = Response.fromJson(_jsonResponse, (json) => PdfVersion.fromJson(json));
// assert
// Can't compare responses just with equality operator because
// response is implemented through json_serializable and doesn't have overridden equality operator.
expect(serializedResponse.time, equals(serializedResponse.time));
expect(serializedResponse.ok, equals(serializedResponse.ok));
expect(serializedResponse.error, equals(serializedResponse.error));
expect(serializedResponse.details, equals(serializedResponse.details));
expect(serializedResponse.result, equals(handwrittenResponse.result));
});
});

group('freezed features:', () {
test('fromJson, toJson', () {
// arrange
final pdfVersion = PdfVersion(
url: _pdfVersionJson['url'],
textPreview: _pdfVersionJson['text_preview'],
);
// act
final pdfVersionFromJson = PdfVersion.fromJson(_pdfVersionJson);
final pdfVersionToJson = pdfVersion.toJson();
// assert
expect(pdfVersionFromJson, equals(pdfVersion));
expect(pdfVersionToJson, equals(_pdfVersionJson));
});

test('equality operator (==)', () {
expect(
PdfVersion(url: 'url1'),
equals(PdfVersion(url: 'url1')),
);
expect(
PdfVersion(url: 'url2'),
isNot(equals(PdfVersion(url: 'url3'))),
);
});

test('hashCode method', () {
expect(
PdfVersion(url: 'url1').hashCode,
equals(PdfVersion(url: 'url1').hashCode),
);
expect(
PdfVersion(url: 'url2').hashCode,
isNot(equals(PdfVersion(url: 'url3').hashCode)),
);
});

test('nice toString', () {
// arrange
final pdfVersion = PdfVersion(
url: 'sample.pdf',
textPreview: 'Sample preview',
);
// act
final string = pdfVersion.toString();
// assert
expect(string, equals('PdfVersion(url: sample.pdf, textPreview: Sample preview)'));
});

test('copyWith method', () {
// arrange
final pdfVersion = PdfVersion.fromJson(_pdfVersionJson);
// act
final copiedPdfVersion = pdfVersion.copyWith(textPreview: 'example');
// assert
expect(copiedPdfVersion, PdfVersion(url: 'SOME_URL', textPreview: 'example'));
});

test('non-nullability', () {
expect(
() => PdfVersion(url: 'SOME_URL'),
isNot(throwsA(isA<Error>())),
);

expect(
() => PdfVersion(url: null),
throwsA(isA<AssertionError>()),
);
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ class DateTimeConverter implements JsonConverter<DateTime, String> {
DateTime fromJson(String dateTimeString) => dateTimeString == null ? null : DateTime.parse(dateTimeString);

@override
String toJson(DateTime dateTime) => dateTime.toIso8601String();
String toJson(DateTime dateTime) => dateTime?.toIso8601String();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import 'package:freezed_annotation/freezed_annotation.dart';

/// Chat type
enum ChatType {
// Direct chat
/// Direct chat
@JsonValue('direct')
direct,

// Group chat
/// Group chat
@JsonValue('group')
group,

// Task
/// Task
@JsonValue('task')
task,
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import 'package:freezed_annotation/freezed_annotation.dart';

/// Status in team
enum GroupStatus {
// Group administrator
/// Group administrator
@JsonValue('admin')
groupAdmin,

// Group member
/// Group member
@JsonValue('member')
groupMember,
}
Loading