Comparing version 3.0.2 to 4.0.0
@@ -6,3 +6,3 @@ // WARNING: Deprecated. Use "@local" identifier instead. | ||
const FUNCTION_PATH = fs.existsSync('f') ? 'f' : 'functions'; | ||
const FUNCTION_PATH = 'functions'; | ||
@@ -9,0 +9,0 @@ module.exports = (cfg, names, params, callback) => { |
@@ -6,4 +6,3 @@ function formatBuffer(b) { | ||
function containsKeywords(params) { | ||
return params.length && | ||
typeof params[0] === 'object' && | ||
return typeof params[0] === 'object' && | ||
!Array.isArray(params[0]) && | ||
@@ -14,14 +13,8 @@ !Buffer.isBuffer(params[0]); | ||
function formatParams(params) { | ||
if (containsKeywords(params)) { | ||
if (params.length > 1) { | ||
throw new Error('Can not send additional arguments with parameters as keywords'); | ||
} else { | ||
return Object.keys(params[0]).reduce((body, name) => { | ||
body[name] = formatBuffer(body[name]); | ||
return body; | ||
}, params[0]); | ||
} | ||
} else { | ||
return params.map(formatBuffer); | ||
} | ||
var src = params[0] || {}; | ||
var dst = {}; | ||
return Object.keys(params[0] || {}).reduce((dst, name) => { | ||
dst[name] = formatBuffer(src[name]); | ||
return dst; | ||
}, dst); | ||
} | ||
@@ -37,2 +30,8 @@ | ||
if (params.length > 1) { | ||
throw new Error('No more than one optional argument containing an object of key-value pairs expected.'); | ||
} else if (params.length && !containsKeywords(params)) { | ||
throw new Error('Argument must be an object of key-value pairs that act as function parameters.'); | ||
} | ||
return { | ||
@@ -39,0 +38,0 @@ params: formatParams(params), |
const https = require('https'); | ||
const http = require('http'); | ||
const HOST = 'functions.lib.id'; | ||
const HOST = 'api.stdlib.com'; | ||
const PORT = 443; | ||
@@ -28,2 +28,4 @@ const PATH = '/'; | ||
let pathname; | ||
if (names[2] === `@${LOCALENV}`) { | ||
@@ -33,5 +35,8 @@ cfg.host = 'localhost'; | ||
names[2] = ''; | ||
pathname = names.slice(0, 2).join('/') + names.slice(2).join('/'); | ||
} else { | ||
cfg.host = names.slice(0, 1).concat(cfg.host).join('.'); | ||
pathname = names.slice(1, 2).join('/') + names.slice(2).join('/'); | ||
} | ||
let pathname = names.slice(0, 2).join('/') + names.slice(2).join('/'); | ||
pathname = pathname + '/'; | ||
@@ -85,3 +90,3 @@ let headers = {}; | ||
let message = typeof response === 'object' ? | ||
(response && response.error && response.error.message) || ('Unspecified error running remote StdLib function "' + names.join('.') + '"') : | ||
(response && response.error && response.error.message) || ('Unspecified error running remote Standard Library function "' + names.join('.') + '"') : | ||
response; | ||
@@ -88,0 +93,0 @@ return callback(new Error(message), response); |
{ | ||
"name": "lib", | ||
"version": "3.0.2", | ||
"version": "4.0.0", | ||
"description": "StdLib: Standard Library for Microservices Node.js Bindings", | ||
"main": "lib.js", | ||
"engines": { | ||
"node" : ">=4.0.0" | ||
"node": ">=4.0.0" | ||
}, | ||
@@ -9,0 +9,0 @@ "keywords": [ |
14586
265
8