npm package: @solyjs/sdk
Description: ### Nodejs Solidity CRUD generator
Latest version: 1.0.5

# SolyJS

### Nodejs Solidity CRUD generator

Sometimes creating CRUDS in solidity and connecting with javascript can be a painful.\

- Grab your access token [here](https://solyjs-app.vercel.app/)
- Define your JS object
- Compile and deploy with SolyJS cli
- ✨ Magic ✨

## Installation

```bash
$ npm install @solyjs/sdk # for library
```

Start using SolyJS
`solyjs init`\
 This command will create directories which solyjs need for works

on your app init

```typescript
import { SolyModule } from '@solyjs/sdk';
import { Photo } from './photo/photo.contract';
import { User } from './user/user.contract';

await SolyJS.initialize({
  accessKey: 'eyJhbxxxxx',
  privateKey: 'e26ec8xxxx',
  provider: 'https://rpc-mumbai.maticvigil.com/',
  contracts: [User, { name: 'Photo', contract: Photo }],
});
```

Compile and deploy

```typescript
await SolyJS.deploy();
await SolyJS.compile();
```

With SolyJs you can define your contract like `user.contract.ts`:

```typescript
import { Contract, Column } from '@solyjs/sdk';

@Contract()
export class User {
  @Column()
  firstName: string;

  @Column()
  lastName: string;
}
```

OR

```typescript
const User = {
  columns: {
    firstName: 'string',
    lastName: 'string',
  },
};
```

```typescript
import {CrudContract, AbstractCrudContract} from 'solyjs'

@CrudContract(User)
export class UserContract extends AbstractCrudContract<User> {

    // SolyJs will automaticaly create _id for your user
    async createUser(){
        return this.contract.create({firstName: 'John', lastName: 'Doe'});
    }

    async getUser(id){
        return this.contract.get(id);
    }

    async getAllUsers(){
        return this.contract.getAll();
    }
    ....
}
```

OR

```typescript
import {SolyJS} from '@solyjs/sdk'

const userContract = SolyModule.getContract('User');
await userContract.create({firstName: 'John', lastName: 'Doe'});
 ....
```

Allowed methods:
`create(data)`, `getAll()`, `get(_id)`, `count()`, `updateById(_id, data)`, `deleteById(_id)`

## Restrictions

| Restriction |                                              Description                                              |
| :---------: | :---------------------------------------------------------------------------------------------------: |
| **public**  |                             Everyone can create/update/delete **default**                             |
|  **owner**  |         Only contract owner (the address that deployed the contract) can create/update/delete         |
| **editors** | List of provided editors on deploy can create/update/delete (_manipulation with editors coming soon_) |

##### How to use?

Restriction type `owner`

```typescript
@Contract({ restriction: 'owner' })
export class User {
  @Column()
  firstName: string;

  @Column()
  lastName: string;
}

const User = {
  options: { restriction: 'owner' },
  columns: { firstName: 'string', lastName: 'string' },
};

export const UserContract = SolyModule.registerContract('User', User);
```

Restriction type `editors`

```typescript
@Contract({
  restriction: 'editors',
  editors: [
    '0x25a39f7E0b8b2D6b2Ebe1f155B09EE6FfB7D11F9',
    '0xbAce2110fA28910B48a5ed08F7ad844d8f1Af6c2',
  ],
})
export class User {
  @Column()
  firstName: string;

  @Column()
  lastName: string;
}
```

### Disable Methods

```typescript
@Contract({ disabledMethods: ['delete', 'update'] })
export class User {
  @Column()
  firstName: string;

  @Column()
  lastName: string;
}

const User = {
  options: { disabledMethods: ['update'] },
  columns: { firstName: 'string', lastName: 'string' },
};

export const UserContract = SolyModule.registerContract('User', User);
```

List of methods: `'delete' | 'create' | 'update' | 'get' | 'count' | 'getAll' `

## IMPORTANT

This package is in development phase, so a lot of new features coming soon

## Roadmap

In next version:

1. CLI for compile and deploy
2. Relations between contracts