royal-core
v3.1.2
Published
Core for role system
Downloads
6
Readme
royal-core
Guideline system controller for pretty roles Includes mongoDB and sync controllers
Install
$ npm i royal-core
or
$ yarn add royal-core
Table of contents
- Getting Started
No DB (Sync)
import Royal, {SyncConnector} from 'royal-core'
const royal = new Royal(new SyncConnector())
MongoDB (aSync)
import Royal from 'royal-core'
import MongoConnector from 'royal-core/MongoConnector.js'
const royal = new Royal(new MongoConnector(uri, dbName, collectionName?))
other (aSync)
Create self controller on base structure
class _Connector {
constructor() {}
getAll() {}
get() {}
add(id, guidelines, payload, rules, upGuideline) {}
remove(id) {}
update(id, controller) {
const {
addRules = [],
removeRules = [],
addGuidelines = [],
removeGuidelines = [],
addUpGuidelines = [],
removeUpGuidelines = [],
payload = {},
} = controller
}
}
Usage
Add guideline
royal.addGuideline(id, {
guidlines: ['idGuideline'],
payload: any,
rules: ['example.test.1'],
upGuideline: ['idGuideline']
})
Remove guideline
royal.removeGuideline(id)
Get guideline from id
royal.getGuideline(id)
Get all guidelines
royal.getGuidelines()
Update guideline
royal.updateGuidelines(id, {
addRules = ['example.test.1'],
removeRules = ['example.test.2'],
addGuidelines = ['idGuideline'],
removeGuidelines = ['idGuideline'],
addUpGuidelines = ['idGuideline'],
removeUpGuidelines = ['idGuideline'],
payload = any,
})
Can guideline do rule
royal.canGuideline(id, 'example.test.10')
Use without connector (front)
front-end:
import {Utils} from 'royal-core'
...recive data from back...
Utils.canRules(data, 'example.test.1')
back-end:
const data royal.getGuidelineRules('idGuideline')
...transfer data to front...
API
Rules
Utils.string2Rule('example.test.*')
How make rule
This rule any.string.split.with.dot
get access to
any
any.string
any.string.split
any.string.split.with
any.string.split.with.dot
any.string.split.with.dot.*
This rule you.can.use.*.to.access.all.middles
get access to
you
you.can
you.can.use
you.can.use.access
you.can.use.to.to
you.can.use.all.to.access
you.can.use.any.to.access.all
you.can.use.namespace.to.access.all.middles
you.can.use.*.to.access.all.middles.*
This rule -just.*.access
and just.*
get access to
just.*.start
just.*.any
just.*.without
(access)
Example:
royal.addGuideline('test', {
rules: ['line.*', '-line.root.add']
})
royal.canGuideline('test', 'line') // true
royal.canGuideline('test', 'line.*') // true
royal.canGuideline('test', 'line.test.add') // true
royal.canGuideline('test', 'line.test.delete.user') // true
royal.canGuideline('test', 'line.test.any') // true
royal.canGuideline('test', 'line.any.move.place') // true
royal.canGuideline('test', 'line.root.move') // true
royal.canGuideline('test', 'line.root.delete') // true
royal.canGuideline('test', 'line.root.add') // false
royal.canGuideline('test', 'line.root.add.test') // false
Guideline childrens
royal.addGuideline('test', {
guidelines: ['test1'], // include all rule from guideline "test1" "test2" "test3" without circular
rules: ['test.*']
})
royal.addGuideline('test1', {
guidelines: ['test2'],
rules: ['test1.*', '-test.1.add']
})
royal.addGuideline('test2', {
guidelines: ['test1', 'test3'],
rules: ['test2.*', '-test.2.add']
})
royal.addGuideline('test3', {
guidelines: ['test1', 'test2'],
rules: ['test3.*', '-test.3.add']
})
License
MIT License © FLomka