Skip to content

fix(schema): drop constructor defaults when deriving update schemas#814

Open
MindfulLearner wants to merge 4 commits into
mainfrom
feat-omit-default-removal
Open

fix(schema): drop constructor defaults when deriving update schemas#814
MindfulLearner wants to merge 4 commits into
mainfrom
feat-omit-default-removal

Conversation

@MindfulLearner

@MindfulLearner MindfulLearner commented Jul 2, 2026

Copy link
Copy Markdown
Member

Problem: UpdateProject-style schemas are patch APIs, an omitted field means leave unchanged. When such a schema is derived from a create schema via Struct.omit/pick, a field with withConstructorDefault keeps its default. Clients call .make() implicitly on mutate, so the default silently overwrites the value the caller left untouched.

Fix:

  • dropConstructorDefault: a Struct.Lambda that removes a field's constructor default. Composable via Struct.map(Struct.omit(...), S.dropConstructorDefault), per review feedback. Replaces the earlier combined omitConstructorDefaults helper.
  • makeExactOptional now drops constructor defaults automatically, since exact optionality and an inherited default are contradictory.

Related: https://github.com/macs-holding/configurator/pull/851

discussion: https://discord.com/channels/1083767712431480922/1521940676416241745

@pkg-pr-new

pkg-pr-new Bot commented Jul 2, 2026

Copy link
Copy Markdown

Open in StackBlitz

@effect-app/cli

npm i https://pkg.pr.new/effect-app/libs/@effect-app/cli@814

effect-app

npm i https://pkg.pr.new/effect-app/libs/effect-app@814

@effect-app/eslint-codegen-model

npm i https://pkg.pr.new/effect-app/libs/@effect-app/eslint-codegen-model@814

@effect-app/eslint-shared-config

npm i https://pkg.pr.new/effect-app/libs/@effect-app/eslint-shared-config@814

@effect-app/infra

npm i https://pkg.pr.new/effect-app/libs/@effect-app/infra@814

@effect-app/vue

npm i https://pkg.pr.new/effect-app/libs/@effect-app/vue@814

@effect-app/vue-components

npm i https://pkg.pr.new/effect-app/libs/@effect-app/vue-components@814

commit: 22972a1

@MindfulLearner MindfulLearner self-assigned this Jul 2, 2026
@patroza

patroza commented Jul 2, 2026

Copy link
Copy Markdown
Member

Inheriting the behaviors of fields is desired. In what case are you considering this undesirable or a "bug"?
This pr / issue lacks motivation.

If you need a tool to strip withConstructorDefault then i would suggest to make a helper that just does that so you can simply mapFields(flow(Struct.omit(..), stripConstructorDefaults))

@MindfulLearner MindfulLearner changed the title feat(): added implementation, api test and story test, and added comment for Struct.omit jsdoc fix(schema): drop constructor defaults when deriving update schemas Jul 6, 2026
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.

2 participants