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

machine

Package Overview
Dependencies
Maintainers
5
Versions
132
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

machine - npm Package Compare versions

Comparing version 8.0.0 to 8.1.0

lib/build-lamda-machine.js

2

DEPENDENCIES.md

@@ -15,3 +15,3 @@ # Dependency Licenses

object-hash@~0.3.0 : MIT
rttc@^3.0.2 : MIT
rttc@^3.1.3 : MIT
switchback@^1.1.3 : MIT

@@ -18,0 +18,0 @@ ms@0.7.1 : MIT

@@ -8,2 +8,3 @@ /**

var makeECMAScriptCompatible = require('convert-to-ecmascript-compatible-varname');
var rttc = require('rttc');

@@ -58,3 +59,3 @@

// If any inputs were used ensure they have an example or typeclass to determine the type
// If any inputs were used ensure they have an example or typeclass to determine the type.
if (_.keys(machineDefinition.inputs).length) {

@@ -86,2 +87,24 @@ var _errors = [];

}
// If `contract` was provided:
if (!_.isUndefined(input.contract)) {
// Validate the `contract` definition
// and ensure that the input is expecting a lamda function.
var contractIsInvalid;
try {
contractIsInvalid =
!_.isObject(input.contract) ||
(input.contract.provides && !_.isObject(input.contract.provides)) ||
(input.contract.expects && !_.isObject(input.contract.expects)) ||
_.isUndefined(input.example) ||
rttc.infer(input.example) !== 'lamda';
} catch (e) {
contractIsInvalid = true;
}
if (contractIsInvalid){
_errors.push(inputKey);
}
}
});

@@ -88,0 +111,0 @@

@@ -8,3 +8,3 @@ /**

var rttc = require('rttc');
var buildLambdaMachine = require('./build-lambda-machine');
var buildLamdaMachine = require('./build-lamda-machine');

@@ -149,10 +149,10 @@

// Handle typeclass * by setting a '*'
// Handle typeclass * by setting type to 'ref'
if(inputDef.typeclass === '*') {
typeSchema = '*';
typeSchema = 'ref';
}
// Handle typeclass 'machine' (which will be deprecated soon) by setting a '*'
// Handle typeclass 'machine' (which will be deprecated soon) by setting type to 'ref'
if (inputDef.typeclass === 'machine') {
typeSchema = '*';
typeSchema = 'ref';
}

@@ -162,8 +162,6 @@ }

// If this is a lambda input, instantiate it into a usable machine.
if (_.isString(inputDef.example) && inputDef.example.match(/(^-+>$)|(^=+>$)|(^<=+$)|(^<-+$)/) ) {
// Prefer the example over typeclass, if one exists.
if (!_.isUndefined(example)){
try {
coercedInputValues[inputName] =
buildLambdaMachine(machine._configuredInputs[inputName], inputName, machine);
return;
typeSchema = rttc.infer(example);
}

@@ -178,19 +176,43 @@ catch (e) {

// Prefer the example over typeclass, if one exists.
if (!_.isUndefined(example)){
try {
typeSchema = rttc.infer(example);
// Now that we have a type schema, we're about to validate the input value.
// Since this oftentimes sanitizes it a little bit, we need a new variable to
// hold that transformed value in. Also, we'll first instantiate a machine for
// lamda inputs which provide a `contract`, so same deal there.
var coercedInputValue;
// If...
// (1) this input is expecting a `lamda` type value at the top-level
// -AND-
// (2) a `contract` was provided for this input
//
// then instantiate the provided lamda into a callable lamda machine for our `fn` to use.
//
// Note:
// If this is just an input which happens to expect a `lamda`,
// i.e. no contract was provided, no problem, just continue onwards
// and treat it like any other value.
//
if (!_.isUndefined(inputDef.contract)) {
if (typeSchema === 'lamda') {
try {
coercedInputValue = buildLamdaMachine(machine._configuredInputs[inputName], inputName, machine);
// Return early for now (TODO: remove this)
coercedInputValues[inputName] = coercedInputValue;
return;
}
catch (e) {
e.input = inputName;
errors.push(e);
return;
}
}
catch (e) {
e.input = inputName;
errors.push(e);
return;
}
// If a `contract` was provided, but the input is not expecting a lamda function,
// then we never should have made it this far (machine would have failed to build)
}
// Now that we have a type schema, validate the input value
// (which oftentimes also sanitizes it a little bit)
// and push on any errors we detect.
var coercedInputValue;
// Validate the input (potentially mildly coercing it as well) and push on any errors
// we detect.
try {

@@ -197,0 +219,0 @@ if (!machine._inputCoercion) {

{
"name": "machine",
"version": "8.0.0",
"version": "8.1.0",
"description": "Configure and execute machines",

@@ -36,3 +36,3 @@ "main": "index.js",

"object-hash": "~0.3.0",
"rttc": "^3.0.2",
"rttc": "^3.1.3",
"switchback": "^1.1.3"

@@ -39,0 +39,0 @@ },

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