Socket
Socket
Sign inDemoInstall

effects-as-data

Package Overview
Dependencies
Maintainers
1
Versions
155
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

effects-as-data - npm Package Compare versions

Comparing version 2.7.0 to 2.8.0

50

es5/index.js

@@ -1,4 +0,4 @@

'use strict';
"use strict";
var _require = require('./util'),
var _require = require("./util"),
isGenerator = _require.isGenerator,

@@ -14,3 +14,3 @@ toArray = _require.toArray,

if (!fn) return Promise.reject(new Error('A function is required.'));
if (!fn) return Promise.reject(new Error("A function is required."));
var gen = fn.apply(null, args);

@@ -22,4 +22,24 @@ var el = newExecutionLog();

var end = Date.now();
onComplete({ result: result, config: config, start: start, end: end, latency: end - start });
onComplete({
success: true,
fn: fn,
result: result,
config: config,
start: start,
end: end,
latency: end - start
});
return result;
}).catch(function (e) {
var end = Date.now();
onComplete({
success: false,
fn: fn,
result: e,
config: config,
start: start,
end: end,
latency: end - start
});
throw e;
});

@@ -29,3 +49,3 @@ }

function run(config, handlers, fn, input, el) {
var genOperation = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'next';
var genOperation = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : "next";

@@ -43,6 +63,6 @@ try {

el.step++;
return run(config, handlers, fn, unwrappedResults, el, 'next');
return run(config, handlers, fn, unwrappedResults, el, "next");
}).catch(function (e) {
el.step++;
return run(config, handlers, fn, e, el, 'throw');
return run(config, handlers, fn, e, el, "throw");
});

@@ -65,3 +85,3 @@ } catch (e) {

function getNextOutput(fn, input) {
var op = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'next';
var op = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "next";

@@ -92,3 +112,3 @@ var _fn$op = fn[op](input),

var handler = handlers[command.type];
if (!handler) throw new Error('Handler of type "' + command.type + '" is not registered.');
if (!handler) throw new Error("Handler of type \"" + command.type + "\" is not registered.");
result = handler(command, { call: call, config: config, handlers: handlers });

@@ -137,3 +157,3 @@ } catch (e) {

if (!config.onCommandComplete || typeof config.onCommandComplete !== 'function') return;
if (!config.onCommandComplete || typeof config.onCommandComplete !== "function") return;
var r = {

@@ -160,3 +180,3 @@ success: success,

if (!config.onCall || typeof config.onCall !== 'function') return;
if (!config.onCall || typeof config.onCall !== "function") return;
var r = {

@@ -173,3 +193,5 @@ args: args,

function onComplete(_ref3) {
var result = _ref3.result,
var success = _ref3.success,
result = _ref3.result,
fn = _ref3.fn,
config = _ref3.config,

@@ -180,4 +202,6 @@ start = _ref3.start,

if (!config.onComplete || typeof config.onComplete !== 'function') return;
if (!config.onComplete || typeof config.onComplete !== "function") return;
var r = {
success: success,
fn: fn,
config: config,

@@ -184,0 +208,0 @@ end: end,

@@ -79,2 +79,4 @@ "use strict";

var onComplete = function onComplete(complete) {
expect(complete.success).toEqual(true);
expect(complete.fn).toEqual(basic);
expect(complete.result).toEqual("foo");

@@ -89,2 +91,19 @@ expect(_typeof(complete.latency)).toEqual("number");

});
test("onComplete for errors", function (done) {
var now = Date.now();
var onComplete = function onComplete(complete) {
expect(complete.success).toEqual(false);
expect(complete.fn).toEqual(badHandler);
expect(complete.result.message).toEqual("oops");
expect(_typeof(complete.latency)).toEqual("number");
expect(complete.start).toBeGreaterThanOrEqual(now);
expect(complete.end).toBeGreaterThanOrEqual(complete.start);
done();
};
var config = { onComplete: onComplete, name: "telemetry" };
call(config, handlers, badHandler, "foo").catch(function (e) {
return e;
});
});
//# sourceMappingURL=telemetry.spec.js.map
{
"name": "effects-as-data",
"version": "2.7.0",
"version": "2.8.0",
"description": "A micro abstraction layer for Javascript that makes writing, testing, and monitoring side-effects easy.",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -1,5 +0,5 @@

const { isGenerator, toArray, toPromise, delay } = require('./util')
const { isGenerator, toArray, toPromise, delay } = require("./util")
function call(config, handlers, fn, ...args) {
if (!fn) return Promise.reject(new Error('A function is required.'))
if (!fn) return Promise.reject(new Error("A function is required."))
const gen = fn.apply(null, args)

@@ -9,10 +9,32 @@ const el = newExecutionLog()

onCall({ args, fn, config })
return run(config, handlers, gen, null, el).then(result => {
const end = Date.now()
onComplete({ result, config, start, end, latency: end - start })
return result
})
return run(config, handlers, gen, null, el)
.then(result => {
const end = Date.now()
onComplete({
success: true,
fn,
result,
config,
start,
end,
latency: end - start
})
return result
})
.catch(e => {
const end = Date.now()
onComplete({
success: false,
fn,
result: e,
config,
start,
end,
latency: end - start
})
throw e
})
}
function run(config, handlers, fn, input, el, genOperation = 'next') {
function run(config, handlers, fn, input, el, genOperation = "next") {
try {

@@ -27,7 +49,7 @@ const { output, done } = getNextOutput(fn, input, genOperation)

el.step++
return run(config, handlers, fn, unwrappedResults, el, 'next')
return run(config, handlers, fn, unwrappedResults, el, "next")
})
.catch(e => {
el.step++
return run(config, handlers, fn, e, el, 'throw')
return run(config, handlers, fn, e, el, "throw")
})

@@ -49,3 +71,3 @@ } catch (e) {

function getNextOutput(fn, input, op = 'next') {
function getNextOutput(fn, input, op = "next") {
const { value: output, done } = fn[op](input)

@@ -107,4 +129,17 @@ return { output, done }

function onCommandComplete({ success, command, index, step, result, config, start, end }) {
if (!config.onCommandComplete || typeof config.onCommandComplete !== 'function') return
function onCommandComplete({
success,
command,
index,
step,
result,
config,
start,
end
}) {
if (
!config.onCommandComplete ||
typeof config.onCommandComplete !== "function"
)
return
const r = {

@@ -125,3 +160,3 @@ success,

function onCall({ args, fn, config }) {
if (!config.onCall || typeof config.onCall !== 'function') return
if (!config.onCall || typeof config.onCall !== "function") return
const r = {

@@ -135,5 +170,7 @@ args,

function onComplete({ result, config, start, end, latency }) {
if (!config.onComplete || typeof config.onComplete !== 'function') return
function onComplete({ success, result, fn, config, start, end, latency }) {
if (!config.onComplete || typeof config.onComplete !== "function") return
const r = {
success,
fn,
config,

@@ -140,0 +177,0 @@ end,

@@ -65,2 +65,4 @@ const { call } = require("../index")

const onComplete = complete => {
expect(complete.success).toEqual(true)
expect(complete.fn).toEqual(basic)
expect(complete.result).toEqual("foo")

@@ -75,1 +77,16 @@ expect(typeof complete.latency).toEqual("number")

})
test("onComplete for errors", done => {
const now = Date.now()
const onComplete = complete => {
expect(complete.success).toEqual(false)
expect(complete.fn).toEqual(badHandler)
expect(complete.result.message).toEqual("oops")
expect(typeof complete.latency).toEqual("number")
expect(complete.start).toBeGreaterThanOrEqual(now)
expect(complete.end).toBeGreaterThanOrEqual(complete.start)
done()
}
const config = { onComplete, name: "telemetry" }
call(config, handlers, badHandler, "foo").catch(e => e)
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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