Skip to content
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

feat: 0.2.0 #51

Merged
merged 13 commits into from
Feb 29, 2024
Merged

feat: 0.2.0 #51

merged 13 commits into from
Feb 29, 2024

Conversation

dnys1
Copy link
Member

@dnys1 dnys1 commented Feb 19, 2024

  • Bump minimum Dart SDK to 3.3 (to support extension types)
  • Adds JsonValue hierarchy for representing JSON primitives safely
  • Model/exception types from third-party packages no longer need to be exported from models.dart/exceptions.dart. Only types you've defined.
  • Adds support for lib/models/ and lib/exceptions/ folders for better organization of custom types

This release also adds a new way to control serialization called "custom overrides".

There are times when you want to use a type from a third-party package in an API, but it is not serializable and Celest complains when you do so. Because you do not control the package, you cannot make it serializable and you are stuck. Other times, the opinionated way Celest serializes (e.g. by using fromJson/toJson methods if available) doesn't align with how you've defined these APIs.

In both of these situations, custom overrides allow you to reimagine the types so that they can be serialized with Celest.

Consider a type called MyType which has fromJson/toJson methods you cannot control and which are causing errors with Celest. The simplest override of this type would look like this (defined in lib/models/overrides.dart):

import 'package:some_package/some_package.dart';

@override
extension type MyTypeOverride(MyType _) implements MyType {}

The @override annotation tells Celest to use this type instead of the original MyType when it encounters a MyType value at any point. The override applies globally and affects all instances of MyType when passing from client<->server. And since MyTypeOverride does not define fromJson/toJson methods, Celest will generate its own.

Custom overrides can do a lot more than override fromJson/toJson methods, though. They can redefine constructors, fields, and even field types. And custom overrides work for exception types too (define those in lib/exceptions/overrides.dart)!

Fixes

Deprecations

  • DEPRECATED lib/models.dart/lib/exceptions.dart have been deprecated in favor of lib/models/ and lib/exceptions/ folders

Breaking Changes

  • BREAKING Fixes casing of resource types (e.g. @env.myEnvVar -> @Env.myEnvVar)

Copy link
Member Author

dnys1 commented Feb 19, 2024

Current dependencies on/for this PR:

This stack of pull requests is managed by Graphite.

@dnys1 dnys1 marked this pull request as ready for review February 29, 2024 05:06
@dnys1 dnys1 merged commit 90dbbf5 into main Feb 29, 2024
3 checks passed
@dnys1 dnys1 deleted the feat/0.2.0 branch February 29, 2024 05:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant