sanity-io / sanity

Sanity Studio – Rapidly configure content workspaces powered by structured content
https://www.sanity.io
MIT License
5.2k stars 420 forks source link

Typegen result names are not customizable #6562

Open largis21 opened 5 months ago

largis21 commented 5 months ago

Is your feature request related to a problem? Please describe.

Most codebases have a strict naming convention, i.e prefixing every type with "i". This is not currently possible with typegen generate.

Describe the solution you'd like

Adding a format property to the sanity-typgen.json config file:

"format": {
  "schemaTypes": {
    "literal": "i{name}Schema",
    "nameCase": "camel" // camel | pascal | snake
  },
  "queries": {
    "literal": "i{name}",
    "nameCase": "camel"
  }
}

Open to suggestions for the api.

Example:

// sanity-typegen.json

{
  "path": "'./**/*.{ts,tsx,js,jsx}'",
  "schema": "schema.json",
  "generates": "sanity.types.ts",
  "format": {
    "schemaTypes": {
      "literal": "i{name}Schema",
      "nameCase": "pascal"
    },
    "queries": {
      "literal": "i{name}",
      "nameCase": "pascal"
    }
  }
}
// Old result

SomeDocumentType = {...}
// New result

iSomeDocumentTypeSchema = {...}

Describe alternatives you've considered

Using as when importing

Additional context I have submitted a pr which I will extend later today: https://github.com/sanity-io/sanity/pull/6559

largis21 commented 5 months ago

The proof of concept is now finished #6559