Skip to content

v0.84.0

Choose a tag to compare

@joshmossas joshmossas released this 04 Aug 03:20
· 4 commits to master since this release

Typescript

  • [ts-codegen] the typescriptClient generator now accepts an optional features object to enable and disable some of the generated helper functions

    export default defineConfig({
         generators: [
             generators.typescriptClient({
                features: {
                    validateFn: true, // output a "validate" helper fn for every type (default: false)
                    cloneFn: true, // output a "clone" helper fn for every type that does a deep clone (default: false)
                    validatorObj: true,  // output a validator object for every type that is prefixed with $$ (default: true)
                }
                // rest of config
            })
        ]
    })
  • [ts-codegen] BREAKING: the typescriptClient generator no longer outputs the validate helper fn by default. You must enable it in the arri config

  • [ts-codegen] The outputted typescript code is now much more treeshakable.

    • All helper functions such as "validate" and "clone" will not be included in the final bundle unless actually imported into your application
    • generated code now outputs separate functions such as "fromJson" and "toJson" for each type, that can be imported individually to improve treeshaking. The previous validator objects are still outputted for compatibility reasons and for convenience reasons.
      import { MyTypeFromJsonString, MyTypeToJsonString, MyTypeValidate } from './my-client.g';
      const result = MyTypeFromJsonString('{}');
      MyTypeToJsonString(result);
      MyTypeValidate(result);
      
      // the old way is still available but it is less tree-shakable
      // this will cause FromJson, ToJson, New, and any other helper fns for this type to be imported
      import { $$MyType } from './my-client.g';
      const result = $$MyType.fromJsonString('{}'); 

PRs

  • feature: make TS client more tree-shakeable by @joshmossas in #198
  • feature: add option to generate a clone helper function for generated types by @joshmossas in #199

Full Changelog: v0.83.1...v0.84.0