attadux
Version:
Implementation of the redux-modular-ducks, forked from the extensible-duck implementation and extended to include spected validators, state machines, helpers, web workers, effect handling, action multipliers, action enhancers, action throttling/debouncing
129 lines (122 loc) • 8 kB
JavaScript
import _default22 from 'ramda/src/none';
import _default21 from 'ramda/src/complement';
import _default20 from 'ramda/src/difference';
import _default19 from 'ramda/src/keys';
import _default18 from 'ramda/src/isEmpty';
import _default17 from 'ramda/src/allPass';
import _default16 from 'ramda/src/values';
import _default15 from 'ramda/src/filter';
import _default14 from 'ramda/src/split';
import _default13 from 'ramda/src/last';
import _default12 from 'ramda/src/map';
import _default11 from 'ramda/src/equals';
import _default10 from 'ramda/src/uniq';
import _default9 from 'ramda/src/length';
import _default8 from 'ramda/src/toPairs';
import _default7 from 'ramda/src/compose';
import _default6 from 'ramda/src/anyPass';
import _default5 from 'ramda/src/all';
import _default4 from 'ramda/src/is';
import _default3 from 'ramda/src/both';
import _default2 from 'ramda/src/either';
import _default from 'ramda/src/identity';
import { areStateNamesStrings, areInputsAndTransitionsStrings, getStateMachinesPropPath, isEachTransitionAmongMachineStates } from '../machines';
import { createConstants } from '../types';
import { isNotEmpty, isPrimitiveish, isPlainObj, isStringieThingie } from '../util/is';
import { isValidationLevel, makeValidationLevel } from '../validators';
/**
* This object of functions is meant to be applied to an object which has
* some or all of its keys sharing the same name as these evolver functions.
*
* Using [evolve()](http://ramdajs.docs/#evolve) on an object with this set of evolver functions
* will create a clone of the original object with the result of each evolver in place of the original value.
*/
export var metadataEvolvers = {
namespace: _default,
store: _default,
validationLevel: makeValidationLevel,
stateMachinesPropName: getStateMachinesPropPath,
consts: createConstants
/**
* These are values which will always be set for a new duck,
* even though the user may not explicitly supply a value for any of them.
*/
};export var duxDefaults = {
consts: {},
creators: {},
machines: {},
queries: {},
workers: {},
selectors: {},
stateMachinesPropName: 'states',
types: [],
validationLevel: 'CANCEL',
validators: {}
/**
* This set of rules is expected to be supplied to the (curried) [spected](https://github.com/25th-floor/spected)
* function, and is then invoked against the set of values supplied when creating a new duck.
*
* The spected validator function will then apply this collection of validator functions against
* any matching keys on the input values passed in, and set either a value of 'true' if validation succeeded
* or an array of error messages for any value(s) that failed validation.
*/
};export var duxRules = {
validationLevel: [[isValidationLevel, 'must be: STRICT, CANCEL, PRUNE, or LOG. CANCEL is the default.']],
store: [[isStringieThingie, 'must be a (non-blank) string']],
namespace: [[isStringieThingie, 'must be a (non-blank) string']],
stateMachinesPropName: [[_default2(isStringieThingie, _default3(_default4(Array), _default5(isStringieThingie))), 'must be a string (or array of strings)']],
consts: [[_default2(isPlainObj, _default4(Function)), 'must be an object (or a function returning an object)']],
creators: [[_default2(isPlainObj, _default4(Function)), 'must be an object (or a function returning an object)']],
machines: [[_default2(isPlainObj, _default4(Function)), 'must be an object (or a function returning an object)']],
selectors: [[_default2(isPlainObj, _default4(Function)), 'must be an object (or a function returning an object)']],
types: [[_default3(_default4(Array), _default5(_default4(String))), 'must be an object (or a function returning an object)']],
validators: [[_default2(isPlainObj, _default4(Function)), 'must be an object (or a function returning an object)']],
enhancers: [[_default2(isPlainObj, _default4(Function)), 'must be an object (or a function returning an object)']],
multipliers: [[_default2(isPlainObj, _default4(Function)), 'must be an object (or a function returning an object)']],
queries: [[_default2(isPlainObj, _default4(Function)), 'must be an object (or a function returning an object)']],
workers: [[_default2(isPlainObj, _default4(Function)), 'must be an object (or a function returning an object)']],
reducer: [[_default4(Function), 'must be a function']],
effects: [[_default2(_default3(_default4(Array), _default5(_default4(Array))), _default4(Function)), 'must be an array of key/value pairs (or a function returning an one)']],
throttling: [[_default2(_default3(_default4(Array), _default5(_default4(Array))), _default4(Function)), 'must be an array of key/value pairs (or a function returning an one)']],
debouncing: [[_default2(_default3(_default4(Array), _default5(_default4(Array))), _default4(Function)), 'must be an array of key/value pairs (or a function returning an one)']],
initialState: [[_default6([isPrimitiveish, isPlainObj, _default4(Function)]), 'must be an object, a function returning an object, or a primitive value']]
/**
* This set of rules is expected to be supplied to the (curried) [spected](https://github.com/25th-floor/spected)
* function, and is then invoked against one or more ducks supplied to the validator middleware.
*
* The spected validator function will then apply this collection of validator functions against
* any matching keys on the input values passed in, and set either a value of 'true' if validation succeeded
* or an array of error messages for any value(s) that failed validation.
*
* The validator middleware makes use of a small portion of a given duck, so the schema rules
* for validating a usable duck in the middleware function is less strict than those used to create a duck.
*/
};export var duckMiddlewareRules = {
store: [[isStringieThingie, 'must be a (non-blank) string']],
namespace: [[isStringieThingie, 'must be a (non-blank) string']],
types: [[isPlainObj, 'must be an object'], [_default7(_default5(_default7(_default11(1), _default9, _default10)), _default12(function (_ref) {
var key = _ref[0];
var val = _ref[1];
return [key, _default7(_default13, _default14('/'))(val)];
}), _default15(_default5(_default4(String))), _default8), 'each key and value are identical']],
machines: [[_default7(_default5(isPlainObj), _default16), 'must be an object'], [_default7(_default5(isNotEmpty), _default16), 'must not be empty'], [_default7(_default5(_default17([areStateNamesStrings, areInputsAndTransitionsStrings])), _default16), 'each machine contains nested objects (states) whose inputs and transitions are strings'], [_default7(_default5(isEachTransitionAmongMachineStates), _default16), 'each transition value must also be a state']],
stateMachinesPropName: [[_default3(_default4(Array), _default5(isStringieThingie)), 'must be an array of strings (representing the path to the "current state" prop)']]
/**
* Checks to see if a given value is a Duck for middleware,
* which means it is a namespaced unit that contains types and validators for one or more of those types.
*
* @func
* @sig * -> Boolean
* @param {*} val A value which may or may not be a Duck instance
* @returns {Boolean} whether or not the object is an instance of a Duck
*/
};export var isDux = _default7(_default18, _default20(['store', 'namespace', 'validators', 'types']), _default19);
/**
* Checks whether or not a given Object contains ducks
*
* @func
* @sig {k: v} -> Boolean
* @param {Object} row An Object which may contain ducks among its props
* @returns {Boolean} whether or not there are any ducks inside of a given Object
*/
export var noDucks = _default6([_default21(isPlainObj), _default7(_default18, _default19), _default7(_default22(isDux), _default16)]);