AshTypescript.NameValidation (ash_typescript v0.19.0)

Copy Markdown View Source

Shared helpers for validating identifiers that need to round-trip through TypeScript codegen. Used by every verifier that flags resource/action/field names producing awkward camelCase output.

A name is invalid if it contains either:

  • an underscore followed by a digit (field_1 → would emit field1, but the underscore is a no-op signal that confuses the formatter), or
  • a trailing ? (Elixir-idiomatic but illegal in JavaScript identifiers).

make_name_better/1 returns the suggestion shown in the error message — drop the spurious underscore, drop the question mark.

Summary

Functions

Returns true when name (atom or string) can be written as-is as a TypeScript property name / identifier ([A-Za-z_$][A-Za-z0-9_$]*).

Returns true when name (atom or string) would produce an awkward TypeScript identifier and should be remapped via field_names / argument_names / metadata_field_names.

Returns the suggested replacement name for use in error messages. Does not apply the configured client formatter — callers should call this only to show the user what to put in their field_names mapping.

Functions

identifier?(name)

Returns true when name (atom or string) can be written as-is as a TypeScript property name / identifier ([A-Za-z_$][A-Za-z0-9_$]*).

Catches what invalid_name?/1 doesn't — names like :"foo-bar", :"1st" or :"with space", which would otherwise be emitted as unquoted keys.

invalid_name?(name)

Returns true when name (atom or string) would produce an awkward TypeScript identifier and should be remapped via field_names / argument_names / metadata_field_names.

make_name_better(name)

Returns the suggested replacement name for use in error messages. Does not apply the configured client formatter — callers should call this only to show the user what to put in their field_names mapping.