Skip to content

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

Merged
brandonroberts merged 1 commit intongrx:masterfrom
Nosfistis:bugfix/data/entity-commands-add-type
Apr 29, 2023
Merged

fix(data): make non-optimistic add command entity partial#3859
brandonroberts merged 1 commit intongrx:masterfrom
Nosfistis:bugfix/data/entity-commands-add-type

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

*/
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