1.0.5 • Published 2 years ago

@solyjs/sdk v1.0.5

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

SolyJS

Nodejs Solidity CRUD generator

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

  • Grab your access token here
  • Define your JS object
  • Compile and deploy with SolyJS cli
  • ✨ Magic ✨

Installation

$ 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

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

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

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

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

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

  @Column()
  lastName: string;
}

OR

const User = {
  columns: {
    firstName: 'string',
    lastName: 'string',
  },
};
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

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

RestrictionDescription
publicEveryone can create/update/delete default
ownerOnly contract owner (the address that deployed the contract) can create/update/delete
editorsList of provided editors on deploy can create/update/delete (manipulation with editors coming soon)
How to use?

Restriction type owner

@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

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

  @Column()
  lastName: string;
}

Disable Methods

@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
1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago