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

cerebral-forms

Package Overview
Dependencies
Maintainers
2
Versions
186
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cerebral-forms - npm Package Compare versions

Comparing version 1.0.0-b-alpha.b2be293f to 1.0.0-b-alpha.c7c326bf

7

lib/chains/changeField.js

@@ -9,6 +9,9 @@ 'use strict';

_templateObject2 = _taggedTemplateLiteral(['field'], ['field']),
_templateObject3 = _taggedTemplateLiteral(['value'], ['value']);
_templateObject3 = _taggedTemplateLiteral(['value'], ['value']),
_templateObject4 = _taggedTemplateLiteral(['', ''], ['', '']);
var _operators = require('cerebral/operators');
var _tags = require('cerebral/tags');
var _validateField = require('../factories/validateField');

@@ -22,3 +25,3 @@

exports.default = [(0, _operators.set)((0, _operators.state)(_templateObject, (0, _operators.input)(_templateObject2)), (0, _operators.input)(_templateObject3)), (0, _validateField2.default)((0, _operators.input)(_templateObject2))];
exports.default = [(0, _operators.set)((0, _tags.state)(_templateObject, (0, _tags.input)(_templateObject2)), (0, _tags.input)(_templateObject3)), (0, _validateField2.default)((0, _tags.state)(_templateObject4, (0, _tags.input)(_templateObject2)))];
//# sourceMappingURL=changeField.js.map

@@ -13,12 +13,31 @@ 'use strict';

function isValidFormFactory(formPathTemplate) {
function isValidForm(context) {
var formPath = typeof formPathTemplate === 'function' ? formPathTemplate(context).value : formPathTemplate;
var form = context.state.get(formPath);
function isValidFormFactory(formPath) {
function isValidForm(_ref) {
var state = _ref.state,
path = _ref.path,
resolveArg = _ref.resolveArg;
if ((0, _isValidForm2.default)(form)) {
return context.path.true();
if (typeof formPath === 'string') {
console.warn('DEPRECATION: Cerebral Forms now requires STATE TAG to be passed into isValidForm factory');
var form = state.get(formPath);
if ((0, _isValidForm2.default)(form)) {
return path.true();
}
return path.false();
} else {
if (!resolveArg.isTag(formPath, 'state')) {
throw new Error('Cerebral Forms - isValidForm factory requires a STATE TAG');
}
var _form = resolveArg.value(formPath);
if ((0, _isValidForm2.default)(_form)) {
return path.true();
}
return path.false();
}
return context.path.false();
}

@@ -25,0 +44,0 @@

@@ -42,8 +42,22 @@ 'use strict';

function resetFormFactory(formPathTemplate) {
function resetForm(context) {
var formPath = typeof formPathTemplate === 'function' ? formPathTemplate(context).value : formPathTemplate;
var form = context.state.get(formPath);
function resetFormFactory(formPath) {
function resetForm(_ref) {
var state = _ref.state,
resolveArg = _ref.resolveArg;
context.state.merge(formPath, resetObject(form));
if (typeof formPath === 'string') {
console.warn('DEPRECATION: Cerebral Forms now requires STATE TAG to be passed into resetForm factory');
var form = state.get(formPath);
state.merge(formPath, resetObject(form));
} else {
if (!resolveArg.isTag(formPath, 'state')) {
throw new Error('Cerebral Forms - isValidForm factory requires a STATE TAG');
}
var _form = resolveArg.value(formPath);
state.merge(resolveArg.path(formPath), resetObject(_form));
}
}

@@ -50,0 +64,0 @@

@@ -14,9 +14,24 @@ 'use strict';

function validateFieldFactory(pathTemplate) {
function validateField(context) {
var path = typeof pathTemplate === 'function' ? pathTemplate(context).value : pathTemplate;
var fieldPath = path.split('.');
var formPath = fieldPath.slice().splice(0, fieldPath.length - 1);
var field = context.state.get(fieldPath);
var form = context.state.get(formPath);
function validateFieldFactory(fieldPath) {
function validateField(_ref) {
var state = _ref.state,
resolveArg = _ref.resolveArg;
var path = void 0;
if (typeof fieldPath === 'string') {
console.warn('DEPRECATION: Cerebral Forms now requires STATE TAG to be passed into validateField factory');
path = fieldPath;
} else {
if (!resolveArg.isTag(fieldPath, 'state')) {
throw new Error('Cerebral Forms - validateField factory requires a STATE TAG');
}
path = resolveArg.path(fieldPath);
}
var fieldPathAsArray = path.split('.');
var formPath = fieldPathAsArray.slice().splice(0, fieldPathAsArray.length - 1);
var field = state.get(path);
var form = state.get(formPath);
var validationResult = (0, _runValidation2.default)(field, form);

@@ -34,4 +49,4 @@

var dependentFormPath = dependentFieldPath.slice().splice(0, dependentFieldPath.length - 1);
var dependentField = context.state.get(dependentFieldPath);
var dependentForm = context.state.get(dependentFormPath);
var dependentField = state.get(dependentFieldPath);
var dependentForm = state.get(dependentFormPath);
if (!dependentForm || !dependentField) {

@@ -42,3 +57,3 @@ throw new Error('The path ' + stringPath + ' used with "dependsOn" on field ' + fieldPath.join('.') + ' is not correct, please check it');

var dependentValidationResult = (0, _runValidation2.default)(dependentField, dependentForm);
context.state.merge(dependentFieldPath, dependentValidationResult);
state.merge(dependentFieldPath, dependentValidationResult);

@@ -52,3 +67,3 @@ if (currentValidationResult.isValid && !dependentValidationResult.isValid) {

context.state.merge(fieldPath, dependentOfValidationResult);
state.merge(path, dependentOfValidationResult);
}

@@ -55,0 +70,0 @@

@@ -14,9 +14,9 @@ 'use strict';

function validateFormFactory(passedFormPathTemplate) {
function validateForm(context) {
var passedFormPath = typeof passedFormPathTemplate === 'function' ? passedFormPathTemplate(context).value : passedFormPathTemplate;
var formPath = passedFormPath.split('.');
var currentPathValue = context.state.get(formPath);
function validateFormFactory(formPath) {
function validateForm(_ref) {
var state = _ref.state,
input = _ref.input,
resolveArg = _ref.resolveArg;
function validateForm(path, form) {
function validate(path, form) {
Object.keys(form).forEach(function (key) {

@@ -27,5 +27,5 @@ if (form[key] === Object(form[key])) {

} else if ('value' in form[key]) {
context.state.merge(path.concat(key), (0, _runValidation2.default)(form[key], form));
state.merge(path.concat(key), (0, _runValidation2.default)(form[key], form));
} else {
validateForm(path.concat(key), form[key]);
validate(path.concat(key), form[key]);
}

@@ -38,7 +38,15 @@ }

formArray.forEach(function (form, index) {
validateForm(path.concat(index), form);
validate(path.concat(index), form);
});
}
if (typeof formPath === 'string') {
console.warn('DEPRECATION: Cerebral Forms now requires STATE TAG to be passed into validateForm factory');
validate(formPath.split('.'), state.get(formPath));
} else {
if (!resolveArg.isTag(formPath, 'state')) {
throw new Error('Cerebral Forms - validateField factory requires a STATE TAG');
}
validateForm(formPath, currentPathValue);
validate(resolveArg.path(formPath).split('.'), resolveArg.value(formPath));
}
}

@@ -45,0 +53,0 @@

@@ -90,2 +90,4 @@ 'use strict';

var _tags = require('cerebral/tags');
var _isValidForm = require('./helpers/isValidForm');

@@ -102,3 +104,3 @@

function isValidForm(form) {
if (typeof form === 'string' || typeof form === 'function') {
if (typeof form === 'string' || form instanceof _tags.Tag) {
return (0, _isValidForm4.default)(form);

@@ -105,0 +107,0 @@ }

{
"name": "cerebral-forms",
"version": "1.0.0-b-alpha.b2be293f",
"version": "1.0.0-b-alpha.c7c326bf",
"description": "Signals, actions and state factories to create forms",
"main": "lib/index.js",
"scripts": {
"test": "../../node_modules/.bin/mocha --compilers js:../../node_modules/babel-register 'src/**/*.test.js'",
"test": "mocha --compilers js:babel-register 'src/**/*.test.js'",
"test:watch": "npm run test -- --watch",
"prebuild": "npm run test",
"build": "BABEL_ENV=production ../../node_modules/.bin/babel src/ --out-dir=lib/ -s",
"coverage": "../../node_modules/.bin/nyc --reporter=lcov --reporter=json npm run test",
"build": "BABEL_ENV=production babel src/ --out-dir=lib/ -s",
"coverage": "nyc --reporter=lcov --reporter=json npm run test",
"prepublish": "npm run build"

@@ -29,6 +28,7 @@ },

"peerDependencies": {
"cerebral": "^2.0.0-b-alpha.b2be293f"
"cerebral": "^2.0.0-b-alpha.c7c326bf"
},
"devDependencies": {
"cerebral": "^2.0.0-b-alpha.b2be293f"
"@cerebral/monorepo": "^0.0.1-alpha.c7c326bf",
"cerebral": "^2.0.0-b-alpha.c7c326bf"
},

@@ -35,0 +35,0 @@ "nyc": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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