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 12:23:26 +00:00
committed by GitHub
parent 6d928628a9
commit 55febef7f1
10 changed files with 177 additions and 0 deletions
+14
View File
@@ -5722,6 +5722,20 @@ __metadata:
languageName: unknown
linkType: soft
"@medusajs/client-types@workspace:packages/generated/client-types":
version: 0.0.0-use.local
resolution: "@medusajs/client-types@workspace:packages/generated/client-types"
dependencies:
"@medusajs/medusa-oas-cli": "*"
cross-env: ^7.0.3
execa: ^5.1.1
jest: ^27.4.7
prettier: ^2.7.1
ts-node: ^10.9.1
typescript: ^4.9.5
languageName: unknown
linkType: soft
"@medusajs/inventory@workspace:packages/inventory":
version: 0.0.0-use.local
resolution: "@medusajs/inventory@workspace:packages/inventory"