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(core): type safe references #691
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This pull request introduces 1 alert when merging da33d0d into de5e66d - view on LGTM.com new alerts:
|
This pull request introduces 1 alert when merging 95ccebe into de5e66d - view on LGTM.com new alerts:
|
EM now returns `Loaded<T, P>` instead of the entity (`T`). This type automatically adds synchronous method `get()` that returns the entity (for references) or array of entities (for collections). There is also `$` property that contains the same as return value of this `get()` method. ```typescript const book1 = await orm.em.findOneOrFail(Book, bible, { populate: ['publisher', 'tags'] }); expect(book1.publisher!.$.name).toBe('Publisher 123'); expect(book1.tags!.$[0].name).toBe('t1'); expect(book1.tags!.$[1].name).toBe('t2'); expect(book1.tags!.$[2].name).toBe('t3'); orm.em.clear(); const books = await orm.em.find(Book, { id: bible.id }, { populate: { publisher: { books: { publisher: true } } }, }); expect(books[0].publisher!.$.books.$[0].publisher!.$.name).toBe('Publisher 123'); const book5 = await orm.em.findOneOrFail(Book, bible, { populate: { publisher: true, tags: true, perex: true }, }); expect(book5.publisher!.$.name).toBe('Publisher 123'); expect(book5.tags.$[0].name).toBe('t1'); ``` Closes #214 BREAKING CHANGE: `Reference.get()` is now available only with correct `Loaded` type hint and is used as a sync getter for the entity, just like `unwrap()`. You can use `Reference.load(prop)` for the original `get()` method functionality. `em.find()` and similar methods now have two type arguments, due to TypeScript not supporting partial type inference, it is no longer possible to specify the `T` explicitly (without also explicitly specifying the load hint).
This pull request introduces 1 alert when merging 4b57cf4 into de5e66d - view on LGTM.com new alerts:
|
B4nan
added a commit
that referenced
this pull request
Jul 30, 2020
B4nan
added a commit
that referenced
this pull request
Jul 30, 2020
B4nan
added a commit
that referenced
this pull request
Aug 2, 2020
EM now returns `Loaded<T, P>` instead of the entity (`T`). This type automatically adds synchronous method `get()` that returns the entity (for references) or array of entities (for collections). There is also `$` property that contains the same as return value of this `get()` method. ```typescript const book1 = await orm.em.findOneOrFail(Book, bible, { populate: ['publisher', 'tags'] }); expect(book1.publisher!.$.name).toBe('Publisher 123'); expect(book1.tags!.$[0].name).toBe('t1'); expect(book1.tags!.$[1].name).toBe('t2'); expect(book1.tags!.$[2].name).toBe('t3'); orm.em.clear(); const books = await orm.em.find(Book, { id: bible.id }, { populate: { publisher: { books: { publisher: true } } }, }); expect(books[0].publisher!.$.books.$[0].publisher!.$.name).toBe('Publisher 123'); const book5 = await orm.em.findOneOrFail(Book, bible, { populate: { publisher: true, tags: true, perex: true }, }); expect(book5.publisher!.$.name).toBe('Publisher 123'); expect(book5.tags.$[0].name).toBe('t1'); ``` Closes #214 BREAKING CHANGE: `Reference.get()` is now available only with correct `Loaded` type hint and is used as a sync getter for the entity, just like `unwrap()`. You can use `Reference.load(prop)` for the original `get()` method functionality. `em.find()` and similar methods now have two type arguments, due to TypeScript not supporting partial type inference, it is no longer possible to specify the `T` explicitly (without also explicitly specifying the load hint).
B4nan
added a commit
that referenced
this pull request
Aug 2, 2020
B4nan
added a commit
that referenced
this pull request
Aug 9, 2020
EM now returns `Loaded<T, P>` instead of the entity (`T`). This type automatically adds synchronous method `get()` that returns the entity (for references) or array of entities (for collections). There is also `$` property that contains the same as return value of this `get()` method. ```typescript const book1 = await orm.em.findOneOrFail(Book, bible, { populate: ['publisher', 'tags'] }); expect(book1.publisher!.$.name).toBe('Publisher 123'); expect(book1.tags!.$[0].name).toBe('t1'); expect(book1.tags!.$[1].name).toBe('t2'); expect(book1.tags!.$[2].name).toBe('t3'); orm.em.clear(); const books = await orm.em.find(Book, { id: bible.id }, { populate: { publisher: { books: { publisher: true } } }, }); expect(books[0].publisher!.$.books.$[0].publisher!.$.name).toBe('Publisher 123'); const book5 = await orm.em.findOneOrFail(Book, bible, { populate: { publisher: true, tags: true, perex: true }, }); expect(book5.publisher!.$.name).toBe('Publisher 123'); expect(book5.tags.$[0].name).toBe('t1'); ``` Closes #214 BREAKING CHANGE: `Reference.get()` is now available only with correct `Loaded` type hint and is used as a sync getter for the entity, just like `unwrap()`. You can use `Reference.load(prop)` for the original `get()` method functionality. `em.find()` and similar methods now have two type arguments, due to TypeScript not supporting partial type inference, it is no longer possible to specify the `T` explicitly (without also explicitly specifying the load hint).
B4nan
added a commit
that referenced
this pull request
Aug 9, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
EM now returns
Loaded<T, P>
instead of the entity (T
). This type automaticallyadds synchronous method
get()
that returns the entity (for references) or arrayof entities (for collections).
There is also
$
property that contains the same as return value of thisget()
method.
Closes #214
BREAKING CHANGE:
Reference.get()
is now available only with correctLoaded
type hint and is usedas a sync getter for the entity, just like
unwrap()
. You can useReference.load(prop)
for the original
get()
method functionality.em.find()
and similar methods now have two type arguments, due to TypeScript not supportingpartial type inference, it is no longer possible to specify the
T
explicitly (without alsoexplicitly specifying the load hint).