0.1.23 • Published 5 months ago

limbojs v0.1.23

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

limbo

Limbo js is a proof of concept of the method oriented API approach. It allows as to define and delegate methods which then can be called via special query language. One query can be executed by several resolvers chunk by chunk. The query gets splitted into chunks based on defeined resolvers - one chunk can have only one resolver.

addHandler (options : Object)

Adds a method handler. The "options" parameter consists of next elements: 1. regExp : RegExp. Methods which match to the regexp will be processed by current handler 2. handle : Function(params, method). defines the handler for the method.

  const Limbo = require("limbo");
  const instance = new Limbo();
  instance.addHandler({
    regExp : /method\d*/,
    handle : (params)=>{
      return {success : true}
    }
  })

delegate(options : Object)

Adds a resolver which will be applied to the query or subquery if it calls certan method(s). The "options" parameter consists of next elements: 1. regExp : RegExp. The (sub)query will be resolved by current resolver if it calls method that match the regexp 2. handle : Function(query : String) The resolver function;

  const Limbo = require("limbo");
  const instance = new Limbo();
  instance.delegate({regExp : /.+/, handle : query=>{
    var headers = {
        "Content-Type" : "application/json"
    };
    return fetch("/limbo", {
        method : "POST",
        headers : headers,
        body : JSON.stringify({query : query})
    }).then(resp=>{
        return resp && resp.json();
    }).catch(err=>{
        throw err;
    });
  }});

call(query : String)

executes passed query

  instance.call(`
    $loginStatus = user_login ~ ${JSON.stringify(data)};
    ? $loginStatus.success @{;
      $sid = user_getSID ~;
      $userData = user_getDashboard ~;
      =>{"userData" : $userData, "sid" : $sid, "success" : true};
    } : @{;
      ? $loginStatus.error == "user_not_confirm" @{;
        user_sendConfirm ~ {"email" : "${data.email}"};
      };
      =>$loginStatus;
    };
  `)

Query syntax

The language consists of next operator:

Assign.

Assigns value at the right to the variable at the left. All variable names should start with "$". $obj = "val";

Call

Calls method. Only one parameter can be passed to the called method however this one paramer can be an object or an array. Te result can be assign to a variable or returned; $result = method ~ {"key" : "val"};

Return

Ends query execution and returns the value => $result;

Condition

Executes a subqery based on condtion ? $result.success == true @{; =>result; } : @{; =>{"success" : false, "error" : "error during executing 'method'"} }

0.1.23

5 months ago

0.1.20

6 months ago

0.1.21

6 months ago

0.1.22

6 months ago

0.1.18

6 months ago

0.1.19

6 months ago

0.1.17

8 months ago

0.1.14

9 months ago

0.1.15

9 months ago

0.1.16

9 months ago

0.1.13

1 year ago

0.1.10

1 year ago

0.1.11

1 year ago

0.1.12

1 year ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.9

1 year ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago