Release notes v0.0.124
A bit of a hectic last weeks for me, since I got an adorable pup. So I can't promise that the release works completely or that these docs are complete.
Lint config
The linter got another update. Based on the 'Node.js best practice' of returning promises, we removed the 'no-return-await' rule and added the 'require-await' rule. It boils down to the following: stacktraces are better when promises are awaited instead of ' implicit' returned. The ESLint rules don't cover everything, so most recommendations are not enforced yet. The article also talks a bit about the performance cost, which is negligible in case of for example database calls.
For more information please read the recommendation .
Code gen
Of course, most of the breaking stuff happens here. We introduced a 'common' directory and split the various outputs of generators over subdirectories named by their groups. This should make it easier to discover related api calls and minimize diffs. Let's go over each generator and check what has changed.
types:
The type generator has the least of all changes, but now resides in the $outputDirectory/common
directory.
structure:
As used by dumpStructure
and dumpApiStructure
. This file is now also in the $outputDirectory/common
directory.
router:
The router middleware, setBodyParsers
and groupMiddleware
are all exported from the $outputDirectory/common
directory. The handlers and tags are now exported from $outputDirectory/$group/controller.js
.
validator:
The validator generator behaves much like the 'router' generator. The usable api is exposed from $outputDirectory/$group/validatorsjs
and the 'common' directory is used to store the 'anonymous-validators' (the plain JS, deduplicated, validation functions).
apiClient:
The api-call functions are now split by group in $outputDirectory/$group/apiClient.js
. The apiClient generator has some more breaking changes. We now expect an 'Axios' instance as the first argument of each function. This allows you to manage the 'Axios' instance however you wish. This also means that both isBrowser
and isNode
settings generate the same functions, so it's more intuitive to use. It is expected that the addRequestIdInterceptors
is called which is exported from $outputDirectory/common/apiClient.js
.
reactQuery:
All types and the useApi
hook are now epxorted from $outputDirectory/common/reactQuery.ts
. The hooks are split per group as well and can be found in $outputDirectory/$group/reactQueries.tsx
.
sql:
The sql generator still prefers the $outputDirectory/databse
directory, but only exports the queries
object from $outputDirectory/database/index.js
.
More notes
- The easiest way to deal with all the import errors is probably to remove all imports (
/import \{[\w\n ,]+} from "./generated[\w\./]+";/gm
), and let your IDE resolve them all again. - When doing lots of api calls from the server, it is advised to add a custom
https.Agent
when creating theAxios
instance. This way you can enable connection 'keep-alive' and timeouts. - All
index.js
files are removed, add a sorted imports rule to your ESLint config, as that list may grow a bit. - The
$outputDirectory
is completely wiped on eachapp.generate
call. This to enforceimport
-ing from thecontroller
files instead of directly editing them. common
is now a reserved name in the code generator and can't be used as a group name.
In closing
Some words of encouragement for all breaking changes. I can't guarantee that everything works as expected, since my brain only functions at half capacity currently and not everything is covered by tests please help. Also more breaking changes are planned, see #754 and #703.