1.0.36 • Published 2 years ago

solyjs v1.0.36

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

SolyJS

Nodejs Solidity CRUD generator

Sometimes creating CRUDS in solidity and connecting with javascript can be a painful.\ SolyJS convert javascript defined struct to solidity crud.

  • Define your JS object
  • Compile and deploy with SolyJS cli
  • ✨ Magic ✨

Installation

$ npm install -g solyjs # for cli
$ npm install solyjs # for library

or add cli in your scripts

"solyjs": "node ./node_modules/solyjs/build/cli.js"

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

on your app init

import { SolyModule } from "solyjs";

await SolyModule.load();

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

import { Contract, Column } from "solyjs";

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

  @Column()
  lastName: string;
}

OR

import { SolyModule } from "solyjs";

const User = {
  columns: {
    firstName: "string",
    lastName: "string",
  },
};

const UserContract = SolyModule.registerContract("User", User);

Create config inside your root project solyjs.config.js

module.exports = {
  privateKey:
    '98ed3412c00cbe4f11xxxxxxxxxxxxxxxx',
  provider: 'https://data-seed-prebsc-1-s1.binance.org:8545',
  cli: {
    contracts: ['/build/**/*.contract{.ts,.js}'],
  },
};

And run CLI

  1. Compile contracts: solyjs contracts:compile
  2. Deploy contracts: solyjs contracts:deploy

Start using your contracts through app

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 {SolyModule} from 'solyjs'
import {UserContract} from './user.contract'

const userContract = SolyModule.getContract(UserContract);
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

1.0.36

2 years ago

1.0.34

2 years ago

1.0.33

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

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