1.2.3 • Published 3 years ago

flfjs v1.2.3

Weekly downloads
5
License
ISC
Repository
-
Last release
3 years ago

FLFjs

RabbitMQ server and client

Installation

To install execute command:

npm i flfjs

Documentation

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 arguments params (dict of parameters) and files (dict of binary objects) and returns data in same format (params, files). Additionally you can pass schema argument to Procedure to validate input data. Each schema should use v4 of 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()
})()
1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.1.1

3 years ago

1.0.0

3 years ago