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

fix(data): make non-optimistic add command entity partial #3859

Merged
merged 1 commit into from
Apr 29, 2023
Merged

fix(data): make non-optimistic add command entity partial #3859

merged 1 commit into from
Apr 29, 2023

Conversation

Nosfistis
Copy link
Contributor

Mirror the type definition of EntityCollectionServiceBase.add on EntityServerCommands.add.

Closes EntityServerCommands.add does not allow optional id #3847

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

EntityServerCommands.add() allows only full entities.

Closes #3847

What is the new behavior?

EntityServerCommands.add() allows partial entities if non-optimistic, just like EntityCollectionServiceBase.add().

Does this PR introduce a breaking change?

[ ] Yes
[x] No

@netlify
Copy link

netlify bot commented Apr 26, 2023

Deploy Preview for ngrx-io canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit 3386be0
🔍 Latest deploy log https://app.netlify.com/sites/ngrx-io/deploys/6449aac61985100008b6bcf2

@@ -11,6 +11,10 @@ export interface EntityServerCommands<T> {
* @returns A terminating Observable of the entity
* after server reports successful save or the save error.
*/
add(
entity: Partial<T>,
options: EntityActionOptions & { isOptimistic: false }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a test that verifies this functionality please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this is just a type change, I found it not necessary. I will add a test that would cause Typescript to fail build if it does not work.

@Nosfistis
Copy link
Contributor Author

Nosfistis commented Apr 26, 2023

Digging a little deeper in the dispatcher I found out that the default behavior is indeed pessimistic. However, the initial PR types have been reverted, and omitting the options argument causes a non-partial entity argument (optimistic-like).

I suggest using

add(
    entity: Partial<T>,
    options?: EntityActionOptions & { isOptimistic?: false }
  ): Observable<T>;
  add(
    entity: T,
    options: EntityActionOptions & { isOptimistic: true }
  ): Observable<T>;
  add(entity: T, options?: EntityActionOptions): Observable<T>;

which seems to cover all cases without fail.

Mirror the type definition of EntityCollectionServiceBase.add on EntityServerCommands.add.

Closes EntityServerCommands.add does not allow optional id #3847
Copy link
Member

@timdeschryver timdeschryver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thanks

@brandonroberts brandonroberts merged commit 93ee1db into ngrx:master Apr 29, 2023
@Nosfistis Nosfistis deleted the bugfix/data/entity-commands-add-type branch April 29, 2023 19:24
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.

EntityServerCommands.add does not allow optional id
3 participants