Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

f

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

f - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

lib/parse.js

67

lib/f.js

@@ -5,27 +5,5 @@ 'use strict';

var fs = require('fs');
var path = require('path');
var parse = require('./parse.js');
function parseArgList(argList) {
var args;
var kwargs = {};
if (typeof argList[argList.length - 1] === 'object' && argList[argList.length - 1] !== 'null') {
kwargs = argList.pop();
}
args = argList.slice();
return new Buffer(
JSON.stringify({
args: args,
kwargs: kwargs
})
);
}
function parseContent(content) {
return new Buffer(content.toString());
}
function f(name, mode, config) {

@@ -40,2 +18,3 @@

var callback = function() {};
var params;
var payload;

@@ -45,2 +24,7 @@ var headers;

var pkgjson;
var fnjson;
var fn;
var env;
if (typeof argList[argList.length - 1] === 'function') {

@@ -52,6 +36,8 @@ callback = argList.pop();

headers = {'Content-Type': 'application/json'};
payload = parseArgList(argList);
params = parse.fromArgList(argList);
payload = new Buffer(JSON.stringify(params));
} else if (mode === 'command') {
headers = {'Content-Type': 'application/command'};
payload = parseContent(argList[0]);
headers = {'Content-Type': 'application/json'};
params = parse.fromString(argList[0]);
payload = new Buffer(JSON.stringify(params));
} else if (mode === 'file') {

@@ -62,2 +48,3 @@ if (!argList[0] instanceof Buffer) {

headers = {'Content-Type': 'application/octet-stream'};
params = parse.fromArgList([]);
payload = argList[0];

@@ -68,2 +55,25 @@ } else {

// if it's a string and the first character is a period...
if (typeof name === 'string' && name[0] === '.') {
try {
name = require(path.join(process.cwd(), 'f', name, 'index.js'));
} catch (e) {
callback(new Error('Could not find local function "' + name + '"'));
return true;
}
}
// if it's a function, it's being called locally
if (typeof name === 'function') {
params.remoteAddress = '::1';
params.buffer = payload;
return name(params, callback);
}
// Throw error if invalid function
if (!name || typeof name !== 'string') {
callback(new Error('Invalid function name'));
return true;
}
req = [http, https][(config.gateway.port === 443) | 0].request({

@@ -108,4 +118,5 @@ host: config.gateway.host,

req.end();
return;
};
}

@@ -112,0 +123,0 @@ };

{
"name": "f",
"version": "1.0.2",
"version": "1.1.0",
"description": "Functional Microservice Request Library",
"main": "lib/f.js",
"bin": {
"f": "cli/bin.js"
},
"scripts": {

@@ -10,0 +7,0 @@ "test": "echo \"Error: no test specified\" && exit 1"

@@ -7,8 +7,5 @@ # ![f](http://stdlib.com/static/images/f-128.png)

microservices. It's built to work out-of-the-box with services created using
[the stdlib functional microservice platform](https://stdlib.com), but can be
[the stdlib microservice registry](https://stdlib.com), but can be
configured to use any gateway (and associated platform or infrastructure provider).
`f` also comes with a CLI tool to run functional microservices from your command
line (using the `f` command) without having to use the Node.js REPL.
## Installation

@@ -30,10 +27,2 @@

### Command Line
For access to the CLI, install `f` globally using npm:
```
$ npm install f -g
```
### Web

@@ -58,3 +47,3 @@

closely to function invocation you're used to (as if it were running in a
native environment). Let's say we have a functional microservice running on
native environment). Let's say we have a microservice running on
[stdlib](https://stdlib.com) that calculates great-circle distances given

@@ -67,3 +56,3 @@ two sets of coordinates using the [Haversine formula](https://en.wikipedia.org/wiki/Haversine_formula).

// Calculate distance from Toronto to San Francisco
f('polybit/distance/haversine')({
f('polybit/haversine')({
from: [43.65, -79.38],

@@ -73,3 +62,3 @@ to: [37.77, -122.42]

console.log(result); // logs 3645473 (metres!)
console.log(result); // logs 3644329 (metres!)

@@ -124,23 +113,2 @@ });

## Command Line Interface
`f` can also be used from the command line. If you run:
```shell
$ npm install f -g
```
You can start running microservices immediately using:
```shell
$ f path/to/func arg1 arg2 --kwarg1 val1
```
This functionality can be mimicked using the library in Node.js by
providing a second argument when referencing the function:
```javascript
f('path/to/func', 'command')('arg1 arg2 --kwarg1 val1', callback);
```
## Sending Files

@@ -179,5 +147,5 @@

## Why use Functional Microservices? Why not npm?
## Why Use Microservices?
Functional Microservices are tremendously useful for offloading computationally
Microservices are tremendously useful for offloading computationally
expensive tasks from your core infrastructure, or providing standardized

@@ -198,3 +166,3 @@ functionality to many different systems (at the cost of a few ms of network latency).

We plan to have more SDKs out in the coming months, you can also [run your microservices from the web](https://github.com/poly/f-web). :)
We plan to have more SDKs out in the coming months. :)

@@ -204,3 +172,3 @@ ## Where can I find Microservices to use?

You can find a list of available microservices on [stdlib's search page](https://stdlib.com/search),
where the `f` team (Polybit Inc.) is hard at work creating a central repository
where the `f` team (Polybit Inc.) is hard at work creating a central registry
of microservices for the web. Feel free to test drive a basic service or create

@@ -220,7 +188,4 @@ your own.

We're actively working our buns off to build the future of cloud development,
beginning with microservice adoption. We'd love your support!
Sign up for [stdlib: A Standard Library for Microservices](https://stdlib.com).
Sign up for [stdlib: A Standard Library for the Web](https://stdlib.com).
Follow us on Twitter [@polybit](https://twitter.com/polybit).
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc