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

Introduce record normalizers #835

Merged
merged 31 commits into from Apr 19, 2021
Merged

Introduce record normalizers #835

merged 31 commits into from Apr 19, 2021

Conversation

dgeb
Copy link
Member

@dgeb dgeb commented Apr 14, 2021

This PR introduces the RecordNormalizer interface and StandardRecordNormalizer implementation. Normalizers are used to transform records and identities into the normalized form from a more developer-friendly form. They will be used by query and transform builders to check and transform inputs. Because normalizers are provided with a keyMap and schema, they can provide validation and also look up identities from keys.

A query builder can now accept either a RecordIdentity or RecordKeyValue in place of an identity. This makes the following queries possible:

source.query(q => q.findRecord({ type: 'planet', id: '123' }));
source.query(q => q.findRecord({ type: 'planet', key: 'remoteId', value: '1' }));

source.query(q => q.findRecords([{ type: 'planet', id: '123' }, { type: 'planet', id: '124' }]));
source.query(q => q.findRecords([{ type: 'planet', key: 'remoteId', value: '1' }, { type: 'planet', key: 'remoteId', value: '2' }]));

Normalizers can work with any kind of inputs, including model classes, such as in ember-orbit. This will soon unlock the ability to mix models with builders, such as:

source.query(q => q.findRecords([earth, jupiter]));

In order to support record normalizers, this PR also:

  • Introduces [Async/Sync]Queryable and[Async/Sync]Updatable interfaces that standardize the public facing interfaces shared by sources and caches.

  • Updates all record-based caches and sources to expose builders as generics. Individual implementations can then override a builder with a custom normalizer and have typings still work.

  • Fixes a number of test cases that were using improperly normalized data.

  • Deprecates the no longer needed firstResult fn in @orbit/utils.


Fixes #545
Fixes #547

Allows for customization of record type arguments in builder methods such as `findRecords`. Also allows for validation of types.
@dgeb dgeb marked this pull request as ready for review April 19, 2021 14:52
@dgeb dgeb merged commit 2dc4eb6 into main Apr 19, 2021
@dgeb dgeb deleted the builders branch April 19, 2021 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant