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(core): strict partial loading #4092

Merged
merged 1 commit into from
Mar 3, 2023
Merged

feat(core): strict partial loading #4092

merged 1 commit into from
Mar 3, 2023

Conversation

B4nan
Copy link
Member

@B4nan B4nan commented Mar 3, 2023

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.

// 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
@codecov-commenter
Copy link

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.01 ⚠️

Comparison is base (7604c95) 99.57% compared to head (1155cd7) 99.56%.

📣 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              
Impacted Files Coverage Δ
packages/core/src/drivers/IDatabaseDriver.ts 100.00% <ø> (ø)
packages/core/src/typings.ts 100.00% <ø> (ø)
packages/core/src/EntityManager.ts 97.03% <100.00%> (ø)
packages/core/src/drivers/DatabaseDriver.ts 99.46% <100.00%> (ø)
packages/core/src/entity/EntityFactory.ts 100.00% <100.00%> (ø)
packages/core/src/utils/Cursor.ts 96.55% <100.00%> (ø)
packages/core/src/utils/Utils.ts 99.19% <100.00%> (ø)
packages/knex/src/AbstractSqlDriver.ts 100.00% <100.00%> (ø)
packages/mongodb/src/MongoDriver.ts 98.78% <100.00%> (-0.60%) ⬇️

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.
📢 Do you have feedback about the report comment? Let us know in this issue.

@B4nan B4nan merged commit 128bfd3 into v6 Mar 3, 2023
@B4nan B4nan deleted the strict-partial-loading branch March 3, 2023 20:21
@B4nan B4nan mentioned this pull request Mar 3, 2023
B4nan added a commit that referenced this pull request Mar 19, 2023
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
B4nan added a commit that referenced this pull request Apr 6, 2023
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
B4nan added a commit that referenced this pull request Apr 10, 2023
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
B4nan added a commit that referenced this pull request Apr 12, 2023
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
B4nan added a commit that referenced this pull request Apr 26, 2023
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
B4nan added a commit that referenced this pull request May 14, 2023
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
B4nan added a commit that referenced this pull request May 14, 2023
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
B4nan added a commit that referenced this pull request May 24, 2023
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
B4nan added a commit that referenced this pull request May 26, 2023
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
B4nan added a commit that referenced this pull request Jun 11, 2023
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
B4nan added a commit that referenced this pull request Sep 10, 2023
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
B4nan added a commit that referenced this pull request Sep 20, 2023
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
B4nan added a commit that referenced this pull request Sep 24, 2023
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
B4nan added a commit that referenced this pull request Sep 30, 2023
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
@B4nan B4nan mentioned this pull request Sep 30, 2023
22 tasks
B4nan added a commit that referenced this pull request Oct 2, 2023
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
B4nan added a commit that referenced this pull request Oct 17, 2023
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
B4nan added a commit that referenced this pull request Oct 21, 2023
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
B4nan added a commit that referenced this pull request Oct 25, 2023
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
B4nan added a commit that referenced this pull request Nov 2, 2023
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
B4nan added a commit that referenced this pull request Nov 5, 2023
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
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.

None yet

2 participants