Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(prisma): add @tsed/prisma package #1797

Merged
merged 1 commit into from
Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ docs-references
*-lock.json
*.lock
benchmarks.*
**/generated
13 changes: 7 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ jobs:
- name: Run benchmarks
run: yarn benchmarks
- uses: actions/github-script@v4
if: ${{ github.event_name == 'pull_request' && !github.event.pull_request.head.repo.fork }}
if: github.event_name == 'pull_request' && !github.event.pull_request.head.repo.fork
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
Expand All @@ -143,7 +143,12 @@ jobs:
deploy-packages:
runs-on: ubuntu-latest
needs: [lint, test, test-packages, build]
if: ${{ github.event_name != 'pull_request' && (contains(github.ref, 'production') || contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc')) }}
if: github.event_name != 'pull_request' && contains('
refs/heads/production
refs/heads/alpha
refs/heads/beta
refs/heads/rc
', github.ref)

strategy:
matrix:
Expand All @@ -167,8 +172,6 @@ jobs:
publish-docs:
runs-on: ubuntu-latest
needs: deploy-packages
if: ${{ github.event_name != 'pull_request' && (contains(github.ref, 'production') || contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc')) }}

strategy:
matrix:
node-version: [16.x]
Expand Down Expand Up @@ -196,8 +199,6 @@ jobs:
publish-refs:
runs-on: ubuntu-latest
needs: deploy-packages
if: ${{ github.event_name != 'pull_request' && (contains(github.ref, 'production') || contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc')) }}

strategy:
matrix:
node-version: [16.x]
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ node_modules
*-lock.json
*.lock
benchmarks.*
**/generated
61 changes: 5 additions & 56 deletions docs/tutorials/prisma-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,70 +12,19 @@ projects:

# Ts.ED Prisma client

<Badge text="Premium sponsors" />

Ts.ED Prisma client is only available for [premium sponsors](https://tsed.io/support.html).

- You can read the modalities [here](https://github.com/sponsors/Romakita),
- Or get your prisma client access ticket [here](https://github.com/sponsors/Romakita/sponsorships?sponsor=Romakita&tier_id=69644&preview=false).

Then contact the [Ts.ED team](https://api.tsed.io/rest/slack/tsedio/tsed) on Slack so that we add it to the private repository.

## Why should I paid for the package
## Features

Prisma Client generate only TypeScript interfaces based on the Prisma schema. Because, interfaces have no consistency in JavaScript, isn't possible to infer a Json Schema and therefore generate the Swagger documentation or perform validation on the models (without manually writing code).

The Ts.ED Prisma will generates classes and enums compatible with Ts.ED decorators like @@Returns@@ but also, but it will also generate the `PrismaService` (connection to the database) but also the **repositories** for each **model** of your Prisma schema.

## Install the package from Github

Ask Ts.ED team on [Slack](https://api.tsed.io/slack/tsedio/tsed) to get a unique personal GH_TOKEN.

Then add on your project (or on profile level) a `.npmrc` file with the following content:

```
@tsedio:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=GH_TOKEN
```

Replace the `GH_TOKEN` by your token or by `${GH_TOKEN}` if you want to use env variable.
The `@tsed/prisma` will generates classes and enums compatible with Ts.ED decorators like @@Returns@@ but also, but it will also generate the `PrismaService` (connection to the database) but also the **repositories** for each **model** of your Prisma schema.

If you use yarn (v1), you can also add a `.yarnrc` with the following content:

```
"@tsedio:registry" "https://npm.pkg.github.com/tsedio"
```

Then add the package to you package.json:

```json
{
"name": "@project/server",
"version": "1.0.0",
"description": "A Server based on Ts.ED",
"main": "index.js",
"author": "",
"license": "MIT",
"dependencies": {
"@tsedio/prisma": "1.0.3"
}
}
```

Furthermore, `@tsedio/prisma` requires Prisma 2 to work properly, so please install Prisma dependencies if you don't have it already installed:
## Installation

```sh
npm i -D prisma
npm i @prisma/client
npm i @tsed/prisma @prisma/client
```

::: warning
Be aware that `@tsedio/prisma` is designed to work with a selected version of `prisma`.

Please make sure you use `prisma` and `@prisma/client` with version matching `~2.22.0`.
Otherwise, the runtime check will report an error when you run the generator.
:::

## Configuration

After installation, you need to update your `schema.prisma` file and then add a new generator section below the `client` one:
Expand All @@ -102,7 +51,7 @@ generator tsed {
```

By default, when the output path contains `node_modules`, the generated code is transpiled - containing `*.js` and `*.d.ts` files that are ready to use (import) in your code.
However, if you explicitly choose an other folder in `output` config, the generated code will be emitted as raw TS files which you can use and import as your other source code files.
However, if you explicitly choose another folder in `output` config, the generated code will be emitted as raw TS files which you can use and import as your other source code files.

You can overwrite that by explicitly setting `emitTranspiledCode` config option:

Expand Down
Loading