client-ts icon indicating copy to clipboard operation
client-ts copied to clipboard

Improve generated template (configuration of XataClient)

Open fabien0102 opened this issue 3 years ago • 1 comments

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

Inside the generated SDK, we have the following lines:

export const getXataClient = () => {
  if (instance) return instance;

  instance = new XataClient();
  return instance;
};

The problem is that we can’t configure the XataClient() here since this is a generated file (so it will be erased at the next generation).

Describe the solution you'd like

Multiple ideas:

  • Remove this getXataClient() from the generated file and force people to write their adapter
  • Generate once a separate file for the XataClient instance (no override on xata codegen)

Describe alternatives you've considered

I can write a separate file for my XataClient() instance, but I still have this dead code on my codebase, which could lead to a mistake if somebody imports this getXataClient() instead of the custom one.

fabien0102 avatar Nov 30 '22 16:11 fabien0102

Since latest minor version we have the ability to rebuild xata.ts file keeping changes inside. It lacks some tests and an override flag so for now it's disabled by default, but we already have the solution built, it was just a matter of me not having the time to finish it and release it.

SferaDev avatar Nov 30 '22 20:11 SferaDev