feat(types): package scaffolding for generated types (#3452)

## What

Generated client types package based on the API's OpenApi Spec.

## Why

This package aims at replacing the need to import types directly from the core `@medusajs/medusa` package which can lead to side effects like importing backend dependencies into the client's realm.

## How

* The package contains a script that is invoked during the build step. 
* The script will use the `medusa-oas oas --type=combined` cli to generate a combined oas file. 
* Then, `medusa-oas client --component=types` uses the oas file to generate the types based on the OAS schema definitions. The result is outputted into `/src/lib`
* `prettier` is run on the `/src/lib` directory to ensure that the generated code follows the monorepo coding style.
* Finally, with `"emitDeclarationOnly": true`,  `tsc` compiles the src directory to only output types.

Until we update our CI pipeline, we will not commit the content `/src/lib`.

## Test

* Run `yarn install`
* Run `yarn build`
* Expect `packages/generated/client-types/dist/` to contain types generated from the OAS defined by `@medusajs/medusa`
This commit is contained in:
Patrick
2023-03-13 08:23:26 -04:00
committed by GitHub
parent 6d928628a9
commit 55febef7f1
10 changed files with 177 additions and 0 deletions

View File

@@ -4,6 +4,7 @@
"workspaces": {
"packages": [
"packages/*",
"packages/generated/*",
"packages/oas/*",
"integration-tests/**/*"
]