# venom-generator

> In the way of code generation, complete the storage model->computation model (business API) transformation to achieve the goal of design and implementation

Latest version **1.5.2** (published 2019-05-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install venom-generator
pnpm add venom-generator
yarn add venom-generator
bun add venom-generator
```

Provides the command `venom-generator`.

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.5.2 |
| Published | 2019-05-30 |
| First published | 2019-05-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 89.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | manjusaka |
| Maintainers | manjusakachn, xuybin |
| Keywords | venom-generator, venom, generator |

## Links

- npm: https://www.npmjs.com/package/venom-generator
- Repository: https://github.com/xuybin/venom-generator
- Homepage: https://github.com/xuybin/venom-generator#readme
- Issues: https://github.com/xuybin/venom-generator/issues
- npm.io page: https://npm.io/package/venom-generator

## Dependencies (7)

- [rc](https://npm.io/package/rc.md) ^1.2.8
- [ajv](https://npm.io/package/ajv.md) ^6.10.0
- [npm](https://npm.io/package/npm.md) ^6.9.0
- [js-yaml](https://npm.io/package/js-yaml.md) ^3.13.1
- [prisma-datamodel](https://npm.io/package/prisma-datamodel.md) ^1.30.4
- [prisma-json-schema](https://npm.io/package/prisma-json-schema.md) ^0.1.3
- [source-map-support](https://npm.io/package/source-map-support.md) ^0.5.12

## Recent versions

- 1.5.2 (latest) — 2019-05-30
- 1.5.1 — 2019-05-30
- 1.5.0 — 2019-05-29
- 1.4.4 — 2019-05-29
- 1.4.3 — 2019-05-29
- 1.4.2 — 2019-05-29
- 1.4.1 — 2019-05-29
- 1.4.0 — 2019-05-29
- 1.3.9 — 2019-05-29
- 1.3.8 — 2019-05-29
- 1.3.7 — 2019-05-29
- 1.3.6 — 2019-05-27
- 1.3.5 — 2019-05-27
- 1.3.3 — 2019-05-27
- 1.3.2 — 2019-05-27
- … 60 more at https://npm.io/package/venom-generator/versions

## README

# venom-generator

以代码生成的方式,完成存储模型->计算模型(业务 API)转换，实现设计即实现的目标

## 参数

- server:服务名称[可省略] 默认为 pservice 项目名

- output:文件输出地址[可省略] 默认输出到./src/generated 文件夹下

- yml:prisma.yml 文件路径[可省略] 默认从./prisma 读取文件 如果指定 'yml' 参数，未找到文件时再次从./prisma 读取文件

- dev:开发调试 默认为 false ,true 可查看模型指令相关参数值

## 形式

- 配置文件

  - 存放根目录[src 同级]

  - 文件名[.vgeneratorrc]:开发所需配置文件名必须与文件名一致，否则不读取

- 命令行

## 使用

- 无'.vgeneratorrc'文件使用方法

```bash
npx venom-generator --server account --output ./src/generated  --yml ./prisma
```

- 有'.vgeneratorrc'文件使用方法

```bash
npx venom-generator
```

## 模型文件指令说明

### @Include(value: "poclicy")

- 是否需要依赖公共服务 poclicy 指令

  - value:公共服务名称

### @Mutation/QueryResolve(description: "方法描述", type: "类型", args: "参数",list:true/false)

- 用于公开的自定义方法指令

  - description:方法描述(所有指令参数都是如此)

  - type:方法返回类型

  - args:方法参数(所有指令参数都是如此)

    - 格式:key:value

    - '!':参数类型若有'!'符号，则表示该参数必传(如:"id:String!"表示 id 必传)

    - 可以为 prisma 基本数据类型[Boolean,DateTime,Float,ID,Int,String],也可以为 prisma 复杂对象

  - list:是否返回为数组。默认 false

  - @QueryResolve 指令用法

    - 若参数为 prisma 基本数据类型[Boolean,DateTime,Float,ID,Int,String]，则 key 可定义，value 定义为[Boolean,DateTime,Float,ID,Int,String]

    - 若参数为复杂对象，需查询唯一则 key 定义为 where，value 定义为需查询的复杂对象

    - 若参数为复杂对象，需查询列表则 key 定义为 wheres，value 定义为需查询的复杂对象

    - 若参数为复杂对象，需分组或排序查询则 key 定义为 orderBy，value 定义为需查询的复杂对象

  - @MutationResolve 指令用法

    - 若参数为 prisma 基本数据类型[Boolean,DateTime,Float,ID,Int,String]，则 key 可定义，value 定义为[Boolean,DateTime,Float,ID,Int,String]

    - 若参数为复杂对象且为新增，key 定义为 data，value 定义为需新增的复杂对象拼接 Create

    - 若参数为复杂对象且为更新，修改数据 key 定义为 data，value 定义为需更新的复杂对象拼接 Update,若条件也为复杂对象且根据唯一条件更新则 key 定义为 where，value 定义为需更新条件的复杂对象，若条件也为复杂对象且根据任意条件更新则 key 定义为 wheres，value 定义为需更新条件的复杂对象

    - 若参数为复杂对象且为删除，若条件也为复杂对象且根据唯一条件删除则 key 定义为 where，value 定义为需更新条件的复杂对象，若条件也为复杂对象且根据任意条件删除则 key 定义为 wheres，value 定义为需更新条件的复杂对象

### @QueryUnique(description: "方法描述", args: "参数")

- 查询单条数据方法指令

  - args:默认"id:String!"

### @Query(description: "方法描述", args: "参数")

- 查询多条数据方法指令

### @Mutation(description: "方法描述", create: true, update: true, delete: true, args: "参数")

- 增删改方法指令

  - create: ture/false 是否需要新增数据方法。 默认 false

  - update: ture/false 是否需要修改数据方法。 默认 false

  - delete: ture/false 是否需要删除数据方法。 默认 false

### @CalcAuthorization(aud: "数据拥有者")

- 当前方法是否需要检查相关权限指令

  - aud:当前方法是否检查数据拥有者

### @Filter(Query: true, Mutation: true)

- 暴露 api 字段过滤

  - Query:true/false 数据查询是否需要过滤该字段。 默认 false

  - Mutation:true/false 数据增删改是否需要过滤该字段。 默认 false

## 例子

- 需要依赖公共服务

```graphql
enum Test @Include(value: "poclicy") {
  Version @Version(value: "1.0.0")
  Description @Description(value: "测试")
}
```

- 用于公开的自定义字段[Mutationxxx]

```graphql
enum Test @MutationResolve(description: "测试方法", type: "String", args: "userName:String!,password:String!") {
  Test
}
```

```graphql
enum Test @MutationResolve(description: "新增数据", type: "Test", args: "data:TestCreate!") {
  Test
}
```

```graphql
enum Test @MutationResolve(description: "根据唯一条件更新数据", type: "Test", args: "data:TestUpdate!,where:Test!") {
  Test
}
```

````graphql
enum Test @MutationResolve(description: "根据任意条件更新数据", type: "Test", args: "data:TestUpdate!,wheres:Test!") {
  Test
}

```graphql
enum Test @MutationResolve(description: "根据任意条件删除数据", type: "Test", args: "wheres:Test!") {
  Test
}
````

- 单条数据查询且需要检查权限

```graphql
type Test @QueryUnique(description: "测试方法", args: "id:String!") @CalcAuthorization(aud: "id") {
  id: Id! @id
}
```

- 多条数据查询且无需检查权限

```graphql
type Test @Query(description: "测试方法", args: "where:Test,orderBy:Test") {
  id: Id! @id
}
```

- 增删改且需要检查权限

```graphql
type Test @Mutation(description: "测试方法", create: true, update: true, delete: true, args: "where:Test!") @CalcAuthorization {
  id: Id! @id
}
```

- 字段过滤

```graphql
type Test {
  id: ID @id
  userName: String
  passWord: String @Filter(Query: true, Mutation: true)
}
```

---
_Source: https://npm.io/package/venom-generator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
