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

Refinement of serialization options #837

Merged
merged 4 commits into from Apr 25, 2021
Merged

Refinement of serialization options #837

merged 4 commits into from Apr 25, 2021

Conversation

dgeb
Copy link
Member

@dgeb dgeb commented Apr 25, 2021

This PR makes a cleanup pass on a number of issues related to serialization prior to the launch of the new interfaces in v0.17.

First of all, the model definitions used to define a schema now expect serializationOptions and deserializationOptions to be shortened to simply serialization and deserialization:

const person: ModelDefinition = {
  attributes: {
    name: { type: 'string' },
    birthday: { type: 'date' },
    height: {
      type: 'distance',
-      serializationOptions: { format: 'cm', digits: 2 },
-      deserializationOptions: { format: 'cm' }
+      serialization: { format: 'cm', digits: 2 },
+      deserialization: { format: 'cm' }
    }
  }
};

The old names are deprecated for now, but won't be supported in v0.18.

This change clears the way for a sibling set of options, validation, to be included in a very symmetrical and ergonomic way.

Along the lines of introducing validation concepts, this PR also removes the option disallowNull as a base serialization option in favor of encouraging this kind of check in validators instead. IMO this option added unnecessary complexity to every serializer and makes much more sense in a validation layer. Since this option was only supported for a few beta releases, I'm not going to go through the full deprecation process. I want it gone by v0.17 final.

One last change is related to typings for serializers. The Serializer and SerializerClass interfaces now better use generics and default to unknowns, eliminating the need for the awkward interfaces UnknownSerializer and UnknownSerializerClass.

Apologies for some of the churn as I try to stabilize serialization concepts and typings before v0.17 final.

@dgeb dgeb merged commit 7e0685d into main Apr 25, 2021
@dgeb dgeb deleted the serialization-options branch April 25, 2021 14:41
backspace added a commit to backspace/koa-orbit that referenced this pull request Sep 24, 2021
This is a followup to this PR:
tchak/orbit-sql#8

I needed to use the code from that branch (and with the
not-building test removed).

This seems pretty straightforward; `UnknownSerializer` is
no longer needed because `Serializer` can be used directly:
orbitjs/orbit#837

I chose to rename the two deserialising functions to remove
the QB that was also removed from the imported class names.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant