1.2.3 • Published 5 years ago
flfjs v1.2.3
FLFjs
RabbitMQ server and client
Installation
To install execute command:
npm i flfjsDocumentation
FLF.Procedure
- Constructor:
FLF.Procedure(({callable, schema = {}})) - Functions:
is_valid(data: FLF.Parameters) -> boolean,call_function(data: FLF.Parameters) -> Parameters
FLF.Parameters
- Constructor:
FLF.Parameters({params = {}, files = {}}) - Fields:
params,files
RpcServer
Server-node for RabbitMQ
Constructor:
- host: host of queue
- port: port of queue
- username: username of queue
- password: password of queue
- procedures: dictionary with procedures of server in format:
{ string: FLF.Procedure }. Each procedure has argumentsparams(dict of parameters) andfiles(dict of binary objects) and returns data in same format (params, files). Additionally you can passschemaargument toProcedureto validate input data. Eachschemashould usev4of json-schema draft.
Functions:
begin()
Example:
const fs = require("fs")
const {RpcServer, Procedure} = require("flfjs");
const add = (params, files) => {
return {
params: {"success": true, "sum": params["a"] + params["b"]},
files: {}
}
}
const add_schema = {
"$schema": "http://json-schema.org/draft-04/schema",
"id": "http://example.com/example.json",
"type": "object",
"title": "The root schema",
"description": "The root schema comprises the entire JSON document.",
"default": {},
"examples": [
{
"a": 1,
"b": 2
}
],
"required": [
"a",
"b"
],
"properties": {
"a": {
"id": "#/properties/a",
"type": "integer",
"title": "The a schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
1
]
},
"b": {
"id": "#/properties/b",
"type": "integer",
"title": "The b schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
2
]
}
},
"additionalProperties": false
}
const super_secret_procedure = (params, files) => {
const secret_file = fs.readFileSync("secret.json")
return {
params: {"success": true},
files: {"secret": secret_file}
}
}
async function main() {
const procedures = {
add: new Procedure({callable: add, schema: add_schema}),
super_secret_procedure: new Procedure({callable: super_secret_procedure})
}
const server = new RpcServer({
host: "google.com",
port: 12345,
username: "mister.robot",
password: "ecorp.zuck",
procedures
})
await server.begin()
}
(async () => {
await main()
})()RpcConnector
Client-node for RabbitMQ
Constructor:
- host: host of queue
- port: port of queue
- username: username of queue
- password: password of queue
Functions:
begin()call_procedure(name, parameters: FLF.Parameters) -> FLF.Parameters
Example:
const {RpcConnector, Parameters} = require("flfjs");
async function main() {
const connector = new RpcConnector({
host: "google.com",
port: 12345,
username: "mister.robot",
password: "ecorp.zuck"
})
await connector.begin()
console.log(await connector.call_procedure("add", new Parameters({
params: {
a: 1,
b: 2
})));
console.log(await connector.call_procedure("super_secret_procedure",
new Parameters({
files: {}
})
));
}
(async () => {
await main()
})()