-
-
Notifications
You must be signed in to change notification settings - Fork 502
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): strict partial loading #4092
Conversation
The `Loaded` type is now improved to support the partial loading hints (`fields` option). When used, the returned type will only allow accessing selected properties. Primary keys are automatically selected. ```ts // book is typed to `Selected<Book, 'author', 'title' | 'author.email'>` const book = await em.findOneOrFail(Book, 1, { fields: ['title', 'author.email'], populate: ['author'], }); const id = book.id; // ok, PK is selected automatically const title = book.title; // ok, title is selected const publisher = book.publisher; // fail, not selected const author = book.author.id; // ok, PK is selected automatically const email = book.author.email; // ok, selected const name = book.author.name; // fail, not selected ``` BREAKING CHANGE: `FindOptions.fields` now accepts only array of strings, like `populate`. Closes #3443
Codecov ReportPatch coverage:
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## v6 #4092 +/- ##
==========================================
- Coverage 99.57% 99.56% -0.01%
==========================================
Files 217 217
Lines 13940 13944 +4
Branches 3187 3190 +3
==========================================
+ Hits 13881 13884 +3
- Misses 55 56 +1
Partials 4 4
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
The `Loaded` type is now improved to support the partial loading hints (`fields` option). When used, the returned type will only allow accessing selected properties. Primary keys are automatically selected. ```ts // book is typed to `Selected<Book, 'author', 'title' | 'author.email'>` const book = await em.findOneOrFail(Book, 1, { fields: ['title', 'author.email'], populate: ['author'], }); const id = book.id; // ok, PK is selected automatically const title = book.title; // ok, title is selected const publisher = book.publisher; // fail, not selected const author = book.author.id; // ok, PK is selected automatically const email = book.author.email; // ok, selected const name = book.author.name; // fail, not selected ``` BREAKING CHANGE: `FindOptions.fields` now accepts only array of strings, like `populate`. Closes #3443
The `Loaded` type is now improved to support the partial loading hints (`fields` option). When used, the returned type will only allow accessing selected properties. Primary keys are automatically selected. ```ts // book is typed to `Selected<Book, 'author', 'title' | 'author.email'>` const book = await em.findOneOrFail(Book, 1, { fields: ['title', 'author.email'], populate: ['author'], }); const id = book.id; // ok, PK is selected automatically const title = book.title; // ok, title is selected const publisher = book.publisher; // fail, not selected const author = book.author.id; // ok, PK is selected automatically const email = book.author.email; // ok, selected const name = book.author.name; // fail, not selected ``` BREAKING CHANGE: `FindOptions.fields` now accepts only array of strings, like `populate`. Closes #3443
The `Loaded` type is now improved to support the partial loading hints (`fields` option). When used, the returned type will only allow accessing selected properties. Primary keys are automatically selected. ```ts // book is typed to `Selected<Book, 'author', 'title' | 'author.email'>` const book = await em.findOneOrFail(Book, 1, { fields: ['title', 'author.email'], populate: ['author'], }); const id = book.id; // ok, PK is selected automatically const title = book.title; // ok, title is selected const publisher = book.publisher; // fail, not selected const author = book.author.id; // ok, PK is selected automatically const email = book.author.email; // ok, selected const name = book.author.name; // fail, not selected ``` BREAKING CHANGE: `FindOptions.fields` now accepts only array of strings, like `populate`. Closes #3443
The `Loaded` type is now improved to support the partial loading hints (`fields` option). When used, the returned type will only allow accessing selected properties. Primary keys are automatically selected. ```ts // book is typed to `Selected<Book, 'author', 'title' | 'author.email'>` const book = await em.findOneOrFail(Book, 1, { fields: ['title', 'author.email'], populate: ['author'], }); const id = book.id; // ok, PK is selected automatically const title = book.title; // ok, title is selected const publisher = book.publisher; // fail, not selected const author = book.author.id; // ok, PK is selected automatically const email = book.author.email; // ok, selected const name = book.author.name; // fail, not selected ``` BREAKING CHANGE: `FindOptions.fields` now accepts only array of strings, like `populate`. Closes #3443
The `Loaded` type is now improved to support the partial loading hints (`fields` option). When used, the returned type will only allow accessing selected properties. Primary keys are automatically selected. ```ts // book is typed to `Selected<Book, 'author', 'title' | 'author.email'>` const book = await em.findOneOrFail(Book, 1, { fields: ['title', 'author.email'], populate: ['author'], }); const id = book.id; // ok, PK is selected automatically const title = book.title; // ok, title is selected const publisher = book.publisher; // fail, not selected const author = book.author.id; // ok, PK is selected automatically const email = book.author.email; // ok, selected const name = book.author.name; // fail, not selected ``` BREAKING CHANGE: `FindOptions.fields` now accepts only array of strings, like `populate`. Closes #3443
The `Loaded` type is now improved to support the partial loading hints (`fields` option). When used, the returned type will only allow accessing selected properties. Primary keys are automatically selected. ```ts // book is typed to `Selected<Book, 'author', 'title' | 'author.email'>` const book = await em.findOneOrFail(Book, 1, { fields: ['title', 'author.email'], populate: ['author'], }); const id = book.id; // ok, PK is selected automatically const title = book.title; // ok, title is selected const publisher = book.publisher; // fail, not selected const author = book.author.id; // ok, PK is selected automatically const email = book.author.email; // ok, selected const name = book.author.name; // fail, not selected ``` BREAKING CHANGE: `FindOptions.fields` now accepts only array of strings, like `populate`. Closes #3443
The `Loaded` type is now improved to support the partial loading hints (`fields` option). When used, the returned type will only allow accessing selected properties. Primary keys are automatically selected. ```ts // book is typed to `Selected<Book, 'author', 'title' | 'author.email'>` const book = await em.findOneOrFail(Book, 1, { fields: ['title', 'author.email'], populate: ['author'], }); const id = book.id; // ok, PK is selected automatically const title = book.title; // ok, title is selected const publisher = book.publisher; // fail, not selected const author = book.author.id; // ok, PK is selected automatically const email = book.author.email; // ok, selected const name = book.author.name; // fail, not selected ``` BREAKING CHANGE: `FindOptions.fields` now accepts only array of strings, like `populate`. Closes #3443
The `Loaded` type is now improved to support the partial loading hints (`fields` option). When used, the returned type will only allow accessing selected properties. Primary keys are automatically selected. ```ts // book is typed to `Selected<Book, 'author', 'title' | 'author.email'>` const book = await em.findOneOrFail(Book, 1, { fields: ['title', 'author.email'], populate: ['author'], }); const id = book.id; // ok, PK is selected automatically const title = book.title; // ok, title is selected const publisher = book.publisher; // fail, not selected const author = book.author.id; // ok, PK is selected automatically const email = book.author.email; // ok, selected const name = book.author.name; // fail, not selected ``` BREAKING CHANGE: `FindOptions.fields` now accepts only array of strings, like `populate`. Closes #3443
The `Loaded` type is now improved to support the partial loading hints (`fields` option). When used, the returned type will only allow accessing selected properties. Primary keys are automatically selected. ```ts // book is typed to `Selected<Book, 'author', 'title' | 'author.email'>` const book = await em.findOneOrFail(Book, 1, { fields: ['title', 'author.email'], populate: ['author'], }); const id = book.id; // ok, PK is selected automatically const title = book.title; // ok, title is selected const publisher = book.publisher; // fail, not selected const author = book.author.id; // ok, PK is selected automatically const email = book.author.email; // ok, selected const name = book.author.name; // fail, not selected ``` BREAKING CHANGE: `FindOptions.fields` now accepts only array of strings, like `populate`. Closes #3443
The `Loaded` type is now improved to support the partial loading hints (`fields` option). When used, the returned type will only allow accessing selected properties. Primary keys are automatically selected. ```ts // book is typed to `Selected<Book, 'author', 'title' | 'author.email'>` const book = await em.findOneOrFail(Book, 1, { fields: ['title', 'author.email'], populate: ['author'], }); const id = book.id; // ok, PK is selected automatically const title = book.title; // ok, title is selected const publisher = book.publisher; // fail, not selected const author = book.author.id; // ok, PK is selected automatically const email = book.author.email; // ok, selected const name = book.author.name; // fail, not selected ``` BREAKING CHANGE: `FindOptions.fields` now accepts only array of strings, like `populate`. Closes #3443
The `Loaded` type is now improved to support the partial loading hints (`fields` option). When used, the returned type will only allow accessing selected properties. Primary keys are automatically selected. ```ts // book is typed to `Selected<Book, 'author', 'title' | 'author.email'>` const book = await em.findOneOrFail(Book, 1, { fields: ['title', 'author.email'], populate: ['author'], }); const id = book.id; // ok, PK is selected automatically const title = book.title; // ok, title is selected const publisher = book.publisher; // fail, not selected const author = book.author.id; // ok, PK is selected automatically const email = book.author.email; // ok, selected const name = book.author.name; // fail, not selected ``` BREAKING CHANGE: `FindOptions.fields` now accepts only array of strings, like `populate`. Closes #3443
The `Loaded` type is now improved to support the partial loading hints (`fields` option). When used, the returned type will only allow accessing selected properties. Primary keys are automatically selected. ```ts // book is typed to `Selected<Book, 'author', 'title' | 'author.email'>` const book = await em.findOneOrFail(Book, 1, { fields: ['title', 'author.email'], populate: ['author'], }); const id = book.id; // ok, PK is selected automatically const title = book.title; // ok, title is selected const publisher = book.publisher; // fail, not selected const author = book.author.id; // ok, PK is selected automatically const email = book.author.email; // ok, selected const name = book.author.name; // fail, not selected ``` BREAKING CHANGE: `FindOptions.fields` now accepts only array of strings, like `populate`. Closes #3443
The `Loaded` type is now improved to support the partial loading hints (`fields` option). When used, the returned type will only allow accessing selected properties. Primary keys are automatically selected. ```ts // book is typed to `Selected<Book, 'author', 'title' | 'author.email'>` const book = await em.findOneOrFail(Book, 1, { fields: ['title', 'author.email'], populate: ['author'], }); const id = book.id; // ok, PK is selected automatically const title = book.title; // ok, title is selected const publisher = book.publisher; // fail, not selected const author = book.author.id; // ok, PK is selected automatically const email = book.author.email; // ok, selected const name = book.author.name; // fail, not selected ``` BREAKING CHANGE: `FindOptions.fields` now accepts only array of strings, like `populate`. Closes #3443
The `Loaded` type is now improved to support the partial loading hints (`fields` option). When used, the returned type will only allow accessing selected properties. Primary keys are automatically selected. ```ts // book is typed to `Selected<Book, 'author', 'title' | 'author.email'>` const book = await em.findOneOrFail(Book, 1, { fields: ['title', 'author.email'], populate: ['author'], }); const id = book.id; // ok, PK is selected automatically const title = book.title; // ok, title is selected const publisher = book.publisher; // fail, not selected const author = book.author.id; // ok, PK is selected automatically const email = book.author.email; // ok, selected const name = book.author.name; // fail, not selected ``` BREAKING CHANGE: `FindOptions.fields` now accepts only array of strings, like `populate`. Closes #3443
The `Loaded` type is now improved to support the partial loading hints (`fields` option). When used, the returned type will only allow accessing selected properties. Primary keys are automatically selected. ```ts // book is typed to `Selected<Book, 'author', 'title' | 'author.email'>` const book = await em.findOneOrFail(Book, 1, { fields: ['title', 'author.email'], populate: ['author'], }); const id = book.id; // ok, PK is selected automatically const title = book.title; // ok, title is selected const publisher = book.publisher; // fail, not selected const author = book.author.id; // ok, PK is selected automatically const email = book.author.email; // ok, selected const name = book.author.name; // fail, not selected ``` BREAKING CHANGE: `FindOptions.fields` now accepts only array of strings, like `populate`. Closes #3443
The `Loaded` type is now improved to support the partial loading hints (`fields` option). When used, the returned type will only allow accessing selected properties. Primary keys are automatically selected. ```ts // book is typed to `Selected<Book, 'author', 'title' | 'author.email'>` const book = await em.findOneOrFail(Book, 1, { fields: ['title', 'author.email'], populate: ['author'], }); const id = book.id; // ok, PK is selected automatically const title = book.title; // ok, title is selected const publisher = book.publisher; // fail, not selected const author = book.author.id; // ok, PK is selected automatically const email = book.author.email; // ok, selected const name = book.author.name; // fail, not selected ``` BREAKING CHANGE: `FindOptions.fields` now accepts only array of strings, like `populate`. Closes #3443
The `Loaded` type is now improved to support the partial loading hints (`fields` option). When used, the returned type will only allow accessing selected properties. Primary keys are automatically selected. ```ts // book is typed to `Selected<Book, 'author', 'title' | 'author.email'>` const book = await em.findOneOrFail(Book, 1, { fields: ['title', 'author.email'], populate: ['author'], }); const id = book.id; // ok, PK is selected automatically const title = book.title; // ok, title is selected const publisher = book.publisher; // fail, not selected const author = book.author.id; // ok, PK is selected automatically const email = book.author.email; // ok, selected const name = book.author.name; // fail, not selected ``` BREAKING CHANGE: `FindOptions.fields` now accepts only array of strings, like `populate`. Closes #3443
The `Loaded` type is now improved to support the partial loading hints (`fields` option). When used, the returned type will only allow accessing selected properties. Primary keys are automatically selected. ```ts // book is typed to `Selected<Book, 'author', 'title' | 'author.email'>` const book = await em.findOneOrFail(Book, 1, { fields: ['title', 'author.email'], populate: ['author'], }); const id = book.id; // ok, PK is selected automatically const title = book.title; // ok, title is selected const publisher = book.publisher; // fail, not selected const author = book.author.id; // ok, PK is selected automatically const email = book.author.email; // ok, selected const name = book.author.name; // fail, not selected ``` BREAKING CHANGE: `FindOptions.fields` now accepts only array of strings, like `populate`. Closes #3443
The `Loaded` type is now improved to support the partial loading hints (`fields` option). When used, the returned type will only allow accessing selected properties. Primary keys are automatically selected. ```ts // book is typed to `Selected<Book, 'author', 'title' | 'author.email'>` const book = await em.findOneOrFail(Book, 1, { fields: ['title', 'author.email'], populate: ['author'], }); const id = book.id; // ok, PK is selected automatically const title = book.title; // ok, title is selected const publisher = book.publisher; // fail, not selected const author = book.author.id; // ok, PK is selected automatically const email = book.author.email; // ok, selected const name = book.author.name; // fail, not selected ``` BREAKING CHANGE: `FindOptions.fields` now accepts only array of strings, like `populate`. Closes #3443
The `Loaded` type is now improved to support the partial loading hints (`fields` option). When used, the returned type will only allow accessing selected properties. Primary keys are automatically selected. ```ts // book is typed to `Selected<Book, 'author', 'title' | 'author.email'>` const book = await em.findOneOrFail(Book, 1, { fields: ['title', 'author.email'], populate: ['author'], }); const id = book.id; // ok, PK is selected automatically const title = book.title; // ok, title is selected const publisher = book.publisher; // fail, not selected const author = book.author.id; // ok, PK is selected automatically const email = book.author.email; // ok, selected const name = book.author.name; // fail, not selected ``` BREAKING CHANGE: `FindOptions.fields` now accepts only array of strings, like `populate`. Closes #3443
The
Loaded
type is now improved to support the partial loading hints (fields
option). When used, the returned type will only allow accessing selected properties. Primary keys are automatically selected.BREAKING CHANGE:
FindOptions.fields
now accepts only array of strings, likepopulate
.Closes #3443