Repository navigation
Add --enum-style const to CLI types and generate #2071
Copy link
Copy link
Closed
Description
Tracks PR #2070.
Plan
Goal
Let appwrite types (TypeScript) and appwrite generate emit enum columns as an as const object plus a same-named union type, behind an opt-in --enum-style enum|const flag. enum is not erasable syntax: generated .ts files currently fail tsc --erasableSyntaxOnly (TS1294) and Node's type stripping refuses them (ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX). Default stays enum, so existing output does not change. Fixes appwrite/sdk-for-cli#277.
What changes (from the PR diff)
templates/cli/internal/typegen/enum_style.go(new):EnumStyletype (enum,const),EnumStyleChoices(),ParseEnumStyle()which rejects unknown values.templates/cli/internal/typegen/typescript.go: sharedTypeScript.DeclareEnumrenderer withEnumStyleandDeclarationoptions. For.d.ts,.d.mtsand.d.ctsdestinations the const style emitsexport declare const X: { readonly ... }, because an ambient const can't take an object initializer (TS1254).templates/cli/internal/cmd/types.go:--enum-styleflag.runTypesparses it, rejectsconstfor non-TypeScript languages, and setsDeclarationfrom the destination's extension.templates/cli/internal/cmd/generate.go,templates/cli/internal/generator/generator.go,templates/cli/internal/generator/typescript.go:--enum-styleflag andOptions.EnumStyle.generateEnumsnow usestypegen.TypeScript.DeclareEnumin place of its own enum printer.src/SDK/Language/CLI.php: copies the newenum_style.goand the three new golden files into the generated CLI.- Tests:
internal/typegen/language_test.gowith goldensts.const.appwrite.tsandts.const.appwrite.d.ts;internal/generator/generator_test.gowith goldenserver.const.types.ts;internal/cmd/typegen_commands_test.gocovering the flag surface, theenumdefault, and rejection of unknown and non-TS values.
Remaining steps
- Get review on feat(cli): add --enum-style const to types and generate #2070 and address any feedback. The PR is the whole code change.
- Merge, then ship it in the next CLI release (regenerate
appwrite/sdk-for-cli) and close TypeScript enums sdk-for-cli#277. - Mention
--enum-style constin the CLI docs and changelog fortypesandgenerate.
Risks
- Default
enumoutput has to stay byte-for-byte identical. The existing golden files guard this. - A consumer switching to
constmay rely on enum-only behaviour such as reverse mapping orenum-typed declarations merging. The flag is opt-in, so only people who choose it are affected.
Done when
- feat(cli): add --enum-style const to types and generate #2070 merged with all checks green
- Default
typesandgenerateoutput unchanged against the existing goldens -
--enum-style constoutput passestsc --strict --erasableSyntaxOnlyfor.tsand.d.tsdestinations and forgenerate - Released in a CLI version and TypeScript enums sdk-for-cli#277 closed
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity