# socar-atomic-converts

> 1.0.2 原子操作 add 时，如提供ID 则使用提供ID # 使用说明

Latest version **1.0.4** (published 2022-01-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install socar-atomic-converts
pnpm add socar-atomic-converts
yarn add socar-atomic-converts
bun add socar-atomic-converts
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2022-01-05 |
| First published | 2021-11-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 135.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | lichonglou |
| Maintainers | lichonglou |

## Links

- npm: https://www.npmjs.com/package/socar-atomic-converts
- Repository: https://github.com/shiwanmenghuxiahuashan/sc-lib-template
- Homepage: https://github.com/shiwanmenghuxiahuashan/sc-lib-template#readme
- Issues: https://github.com/shiwanmenghuxiahuashan/sc-lib-template/issues
- npm.io page: https://npm.io/package/socar-atomic-converts

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ^4.17.21

## Recent versions

- 1.0.4 (latest) — 2022-01-05
- 1.0.3 — 2022-01-05
- 1.0.2 — 2021-12-28
- 1.0.1 — 2021-11-16
- 1.0.0 — 2021-11-16

## README

# Changelog
1.0.2 原子操作 add 时，如提供ID 则使用提供ID 
# 使用说明

```js
    import {
        socarJsonApiConverts,
        parsingSchema
    } from 'socar-atomic-converts'
    socarJsonApiConverts.converts({
        atiomicData, //原子操作数据
        atiomicSchema, //atiomicData见schema.md中的实例,可以传入未解析的schema
    })
```

注意事项:
1.converts的参数atiomicData的操作符对应的数据的数据类型为数组。

```js
 //example
 const temp = {
     add: [{
         xxx
     }]
 }
```

2.atiomicData的操作符对应的数据的relationship字段中的关系字段对应的数据类型为数组。

```js
    //example
    const temp = {
        add: [{
            desc: 'test',
            method: ['get', 'post'],
            name: 'test',
            path: 'test',
            relationship: {
                dependence_rel: [{
                        id: 3,
                        type: 'api'
                    },
                    {
                        id: 9,
                        type: 'api'
                    },
                    {
                        id: 10,
                        type: 'api'
                    }
                ]
            },
            type: 'api'
        }]
    }
```

addRelationConvertor 将传入数据转化为增加的原子操作数据

```js
/**
 *  @param {object} data 需要构建原子操作的数据
 *  @param {string} oper 原子操作的操作符
 *  @param {object} schema 转换原子操作数据所对应的schema
 *  exampleData:
      {
        add:[
          {
            desc: 'test',
            method: ['get', 'post'],
            name: 'test',
            path: 'test',
              relationship: {
                dependence_rel: [
                  { id: 3, type: 'api' },
                  { id: 9, type: 'api' },
                  { id: 10, type: 'api' }
                ]
              },
              type: 'api'
          }
        ],
       }
    @return {object} 
    exampleReturn:
    {
      opp:'add',
      data:{
          attributes:{
              desc: 'test',
              method:['put','get'],
              name:"test",
              path: 'test',
          },
          relationships:{
              dependence_rel:{
                  data:[
                    { id: 3, type: 'api' },
                    { id: 9, type: 'api' },
                    { id: 10, type: 'api' }
                  ]
              }
          },
          type: "api"
      }
    }
 */
function addRelationConvertor(data, oper, schema)
```

UpdateRelationConvertor 将传入数据转化为修改的原子操作数据

```js
/**
 *  @param {object} data 需要构建原子操作的数据
 *  @param {string} oper 原子操作的操作符
 *  @param {object} schema 转换原子操作数据所对应的schema
 *  exampleData:
      {
        update:[
          {
            desc: 'test',
            method: ['get', 'post'],
            name: 'test',
            path: 'test',
              relationship: {
                dependence_rel: [
                  { id: 3, type: 'api' },
                  { id: 9, type: 'api' },
                  { id: 10, type: 'api' }
                ]
              },
              type: 'api'
          }
        ],
       }
    @return {object} 
    exampleReturn:
    [
        {
            op: 'update',
            data:{
                id: 187, 
                type: 'api',
                attributes:{
                    desc: 'test',
                    method:['put','get'],
                    name:"test",
                    path: 'test',
                },
            }
        },
        {
            op: 'update',
            ref:{
                id: 187,
                relationship: "api",
                type: "api",
            },
            data:[
                  { id: 3, type: 'api' },
                  { id: 9, type: 'api' },
                  { id: 10, type: 'api' }
            ]
        }
    ]
*/
```

removeRelationConvertor 将传入数据转化为删除的原子操作数据

```js
/**
 *
 * @param {Object}  data 需要构建原子操作的数据
 * @param {string}  oper 原子操作操作符
 * @param {object}  schema 转换原子操作数据所对应的schema
 * 
 *  exampleData:
      {
        update:[
          {
            desc: 'test',
            method: ['get', 'post'],
            name: 'test',
            path: 'test',
              relationship: {
                dependence_rel: [
                  { id: 3, type: 'api' },
                  { id: 9, type: 'api' },
                  { id: 10, type: 'api' }
                ]
              },
              type: 'api'
          }
        ],
    }
 * exampleSchema:
 *    remove:{
 *       ref:{
 *        id: {title: 'Id', type: 'string'},
 *         type:{title: 'Type', type: 'string'}
 *      }
 *    },
 * exampleReturn:
 *  {
 *      op: "remove",
        ref: {id: 187, type: 'api'}
 *  }
 */
```

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