RAHHH
This commit is contained in:
3
backend/frontend/node_modules/tcomb/lib/Any.js
generated
vendored
Normal file
3
backend/frontend/node_modules/tcomb/lib/Any.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
var irreducible = require('./irreducible');
|
||||
|
||||
module.exports = irreducible('Any', function () { return true; });
|
||||
4
backend/frontend/node_modules/tcomb/lib/Array.js
generated
vendored
Normal file
4
backend/frontend/node_modules/tcomb/lib/Array.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var irreducible = require('./irreducible');
|
||||
var isArray = require('./isArray');
|
||||
|
||||
module.exports = irreducible('Array', isArray);
|
||||
4
backend/frontend/node_modules/tcomb/lib/Boolean.js
generated
vendored
Normal file
4
backend/frontend/node_modules/tcomb/lib/Boolean.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var irreducible = require('./irreducible');
|
||||
var isBoolean = require('./isBoolean');
|
||||
|
||||
module.exports = irreducible('Boolean', isBoolean);
|
||||
3
backend/frontend/node_modules/tcomb/lib/Date.js
generated
vendored
Normal file
3
backend/frontend/node_modules/tcomb/lib/Date.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
var irreducible = require('./irreducible');
|
||||
|
||||
module.exports = irreducible('Date', function (x) { return x instanceof Date; });
|
||||
3
backend/frontend/node_modules/tcomb/lib/Error.js
generated
vendored
Normal file
3
backend/frontend/node_modules/tcomb/lib/Error.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
var irreducible = require('./irreducible');
|
||||
|
||||
module.exports = irreducible('Error', function (x) { return x instanceof Error; });
|
||||
4
backend/frontend/node_modules/tcomb/lib/Function.js
generated
vendored
Normal file
4
backend/frontend/node_modules/tcomb/lib/Function.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var irreducible = require('./irreducible');
|
||||
var isFunction = require('./isFunction');
|
||||
|
||||
module.exports = irreducible('Function', isFunction);
|
||||
4
backend/frontend/node_modules/tcomb/lib/Integer.js
generated
vendored
Normal file
4
backend/frontend/node_modules/tcomb/lib/Integer.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var refinement = require('./refinement');
|
||||
var Number = require('./Number');
|
||||
|
||||
module.exports = refinement(Number, function (x) { return x % 1 === 0; }, 'Integer');
|
||||
4
backend/frontend/node_modules/tcomb/lib/Nil.js
generated
vendored
Normal file
4
backend/frontend/node_modules/tcomb/lib/Nil.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var irreducible = require('./irreducible');
|
||||
var isNil = require('./isNil');
|
||||
|
||||
module.exports = irreducible('Nil', isNil);
|
||||
4
backend/frontend/node_modules/tcomb/lib/Number.js
generated
vendored
Normal file
4
backend/frontend/node_modules/tcomb/lib/Number.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var irreducible = require('./irreducible');
|
||||
var isNumber = require('./isNumber');
|
||||
|
||||
module.exports = irreducible('Number', isNumber);
|
||||
4
backend/frontend/node_modules/tcomb/lib/Object.js
generated
vendored
Normal file
4
backend/frontend/node_modules/tcomb/lib/Object.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var irreducible = require('./irreducible');
|
||||
var isObject = require('./isObject');
|
||||
|
||||
module.exports = irreducible('Object', isObject);
|
||||
3
backend/frontend/node_modules/tcomb/lib/RegExp.js
generated
vendored
Normal file
3
backend/frontend/node_modules/tcomb/lib/RegExp.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
var irreducible = require('./irreducible');
|
||||
|
||||
module.exports = irreducible('RegExp', function (x) { return x instanceof RegExp; });
|
||||
4
backend/frontend/node_modules/tcomb/lib/String.js
generated
vendored
Normal file
4
backend/frontend/node_modules/tcomb/lib/String.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var irreducible = require('./irreducible');
|
||||
var isString = require('./isString');
|
||||
|
||||
module.exports = irreducible('String', isString);
|
||||
4
backend/frontend/node_modules/tcomb/lib/Type.js
generated
vendored
Normal file
4
backend/frontend/node_modules/tcomb/lib/Type.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var irreducible = require('./irreducible');
|
||||
var isType = require('./isType');
|
||||
|
||||
module.exports = irreducible('Type', isType);
|
||||
21
backend/frontend/node_modules/tcomb/lib/assert.js
generated
vendored
Normal file
21
backend/frontend/node_modules/tcomb/lib/assert.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
var isFunction = require('./isFunction');
|
||||
var isNil = require('./isNil');
|
||||
var fail = require('./fail');
|
||||
var stringify = require('./stringify');
|
||||
|
||||
function assert(guard, message) {
|
||||
if (guard !== true) {
|
||||
if (isFunction(message)) { // handle lazy messages
|
||||
message = message();
|
||||
}
|
||||
else if (isNil(message)) { // use a default message
|
||||
message = 'Assert failed (turn on "Pause on exceptions" in your Source panel)';
|
||||
}
|
||||
assert.fail(message);
|
||||
}
|
||||
}
|
||||
|
||||
assert.fail = fail;
|
||||
assert.stringify = stringify;
|
||||
|
||||
module.exports = assert;
|
||||
10
backend/frontend/node_modules/tcomb/lib/assign.js
generated
vendored
Normal file
10
backend/frontend/node_modules/tcomb/lib/assign.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
function assign(x, y) {
|
||||
for (var k in y) {
|
||||
if (y.hasOwnProperty(k)) {
|
||||
x[k] = y[k];
|
||||
}
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
module.exports = assign;
|
||||
19
backend/frontend/node_modules/tcomb/lib/create.js
generated
vendored
Normal file
19
backend/frontend/node_modules/tcomb/lib/create.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
var isType = require('./isType');
|
||||
var getFunctionName = require('./getFunctionName');
|
||||
var assert = require('./assert');
|
||||
var stringify = require('./stringify');
|
||||
|
||||
// creates an instance of a type, handling the optional new operator
|
||||
module.exports = function create(type, value, path) {
|
||||
if (isType(type)) {
|
||||
return !type.meta.identity && typeof value === 'object' && value !== null ? new type(value, path): type(value, path);
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
// here type should be a class constructor and value some instance, just check membership and return the value
|
||||
path = path || [getFunctionName(type)];
|
||||
assert(value instanceof type, function () { return 'Invalid value ' + stringify(value) + ' supplied to ' + path.join('/'); });
|
||||
}
|
||||
|
||||
return value;
|
||||
};
|
||||
56
backend/frontend/node_modules/tcomb/lib/declare.js
generated
vendored
Normal file
56
backend/frontend/node_modules/tcomb/lib/declare.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
var assert = require('./assert');
|
||||
var isTypeName = require('./isTypeName');
|
||||
var isType = require('./isType');
|
||||
var isNil = require('./isNil');
|
||||
var mixin = require('./mixin');
|
||||
var getTypeName = require('./getTypeName');
|
||||
var isUnion = require('./isUnion');
|
||||
|
||||
// All the .declare-d types should be clearly different from each other thus they should have
|
||||
// different names when a name was not explicitly provided.
|
||||
var nextDeclareUniqueId = 1;
|
||||
|
||||
module.exports = function declare(name) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isTypeName(name), function () { return 'Invalid argument name ' + name + ' supplied to declare([name]) (expected a string)'; });
|
||||
}
|
||||
|
||||
var type;
|
||||
|
||||
function Declare(value, path) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(!isNil(type), function () { return 'Type declared but not defined, don\'t forget to call .define on every declared type'; });
|
||||
if (isUnion(type)) {
|
||||
assert(type.dispatch === Declare.dispatch, function () { return 'Please define the custom ' + name + '.dispatch function before calling ' + name + '.define()'; });
|
||||
}
|
||||
}
|
||||
return type(value, path);
|
||||
}
|
||||
|
||||
Declare.define = function (spec) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isType(spec), function () { return 'Invalid argument type ' + assert.stringify(spec) + ' supplied to define(type) (expected a type)'; });
|
||||
assert(isNil(type), function () { return 'Declare.define(type) can only be invoked once'; });
|
||||
// assert(isNil(spec.meta.name) && Object.keys(spec.prototype).length === 0, function () { return 'Invalid argument type ' + assert.stringify(spec) + ' supplied to define(type) (expected a fresh, unnamed type)'; });
|
||||
}
|
||||
|
||||
if (isUnion(spec) && Declare.hasOwnProperty('dispatch')) {
|
||||
spec.dispatch = Declare.dispatch;
|
||||
}
|
||||
type = spec;
|
||||
mixin(Declare, type, true); // true because it overwrites Declare.displayName
|
||||
if (name) {
|
||||
type.displayName = Declare.displayName = name;
|
||||
Declare.meta.name = name;
|
||||
}
|
||||
Declare.meta.identity = type.meta.identity;
|
||||
Declare.prototype = type.prototype;
|
||||
return Declare;
|
||||
};
|
||||
|
||||
Declare.displayName = name || ( getTypeName(Declare) + "$" + nextDeclareUniqueId++ );
|
||||
// in general I can't say if this type will be an identity, for safety setting to false
|
||||
Declare.meta = { identity: false };
|
||||
Declare.prototype = null;
|
||||
return Declare;
|
||||
};
|
||||
26
backend/frontend/node_modules/tcomb/lib/decompose.js
generated
vendored
Normal file
26
backend/frontend/node_modules/tcomb/lib/decompose.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
var isType = require('./isType');
|
||||
|
||||
function isRefinement(type) {
|
||||
return isType(type) && type.meta.kind === 'subtype';
|
||||
}
|
||||
|
||||
function getPredicates(type) {
|
||||
return isRefinement(type) ?
|
||||
[type.meta.predicate].concat(getPredicates(type.meta.type)) :
|
||||
[];
|
||||
}
|
||||
|
||||
function getUnrefinedType(type) {
|
||||
return isRefinement(type) ?
|
||||
getUnrefinedType(type.meta.type) :
|
||||
type;
|
||||
}
|
||||
|
||||
function decompose(type) {
|
||||
return {
|
||||
predicates: getPredicates(type),
|
||||
unrefinedType: getUnrefinedType(type)
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = decompose;
|
||||
95
backend/frontend/node_modules/tcomb/lib/dict.js
generated
vendored
Normal file
95
backend/frontend/node_modules/tcomb/lib/dict.js
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
var assert = require('./assert');
|
||||
var isTypeName = require('./isTypeName');
|
||||
var isFunction = require('./isFunction');
|
||||
var getTypeName = require('./getTypeName');
|
||||
var isIdentity = require('./isIdentity');
|
||||
var isObject = require('./isObject');
|
||||
var create = require('./create');
|
||||
var is = require('./is');
|
||||
|
||||
function getDefaultName(domain, codomain) {
|
||||
return '{[key: ' + getTypeName(domain) + ']: ' + getTypeName(codomain) + '}';
|
||||
}
|
||||
|
||||
function dict(domain, codomain, name) {
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isFunction(domain), function () { return 'Invalid argument domain ' + assert.stringify(domain) + ' supplied to dict(domain, codomain, [name]) combinator (expected a type)'; });
|
||||
assert(isFunction(codomain), function () { return 'Invalid argument codomain ' + assert.stringify(codomain) + ' supplied to dict(domain, codomain, [name]) combinator (expected a type)'; });
|
||||
assert(isTypeName(name), function () { return 'Invalid argument name ' + assert.stringify(name) + ' supplied to dict(domain, codomain, [name]) combinator (expected a string)'; });
|
||||
}
|
||||
|
||||
var displayName = name || getDefaultName(domain, codomain);
|
||||
var domainNameCache = getTypeName(domain);
|
||||
var codomainNameCache = getTypeName(codomain);
|
||||
var identity = isIdentity(domain) && isIdentity(codomain);
|
||||
|
||||
function Dict(value, path) {
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
if (identity) {
|
||||
return value; // just trust the input if elements must not be hydrated
|
||||
}
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
path = path || [displayName];
|
||||
assert(isObject(value), function () { return 'Invalid value ' + assert.stringify(value) + ' supplied to ' + path.join('/'); });
|
||||
}
|
||||
|
||||
var idempotent = true; // will remain true if I can reutilise the input
|
||||
var ret = {}; // make a temporary copy, will be discarded if idempotent remains true
|
||||
for (var k in value) {
|
||||
if (value.hasOwnProperty(k)) {
|
||||
k = create(domain, k, ( process.env.NODE_ENV !== 'production' ? path.concat(domainNameCache) : null ));
|
||||
var actual = value[k];
|
||||
var instance = create(codomain, actual, ( process.env.NODE_ENV !== 'production' ? path.concat(k + ': ' + codomainNameCache) : null ));
|
||||
idempotent = idempotent && ( actual === instance );
|
||||
ret[k] = instance;
|
||||
}
|
||||
}
|
||||
|
||||
if (idempotent) { // implements idempotency
|
||||
ret = value;
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
Object.freeze(ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Dict.meta = {
|
||||
kind: 'dict',
|
||||
domain: domain,
|
||||
codomain: codomain,
|
||||
name: name,
|
||||
identity: identity
|
||||
};
|
||||
|
||||
Dict.displayName = displayName;
|
||||
|
||||
Dict.is = function (x) {
|
||||
if (!isObject(x)) {
|
||||
return false;
|
||||
}
|
||||
for (var k in x) {
|
||||
if (x.hasOwnProperty(k)) {
|
||||
if (!is(k, domain) || !is(x[k], codomain)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
Dict.update = function (instance, patch) {
|
||||
return Dict(assert.update(instance, patch));
|
||||
};
|
||||
|
||||
return Dict;
|
||||
}
|
||||
|
||||
dict.getDefaultName = getDefaultName;
|
||||
module.exports = dict;
|
||||
59
backend/frontend/node_modules/tcomb/lib/enums.js
generated
vendored
Normal file
59
backend/frontend/node_modules/tcomb/lib/enums.js
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
var assert = require('./assert');
|
||||
var isTypeName = require('./isTypeName');
|
||||
var forbidNewOperator = require('./forbidNewOperator');
|
||||
var isNumber = require('./isNumber');
|
||||
var isString = require('./isString');
|
||||
var isObject = require('./isObject');
|
||||
|
||||
function getDefaultName(map) {
|
||||
return Object.keys(map).map(function (k) { return assert.stringify(k); }).join(' | ');
|
||||
}
|
||||
|
||||
function enums(map, name) {
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isObject(map), function () { return 'Invalid argument map ' + assert.stringify(map) + ' supplied to enums(map, [name]) combinator (expected a dictionary of String -> String | Number)'; });
|
||||
assert(isTypeName(name), function () { return 'Invalid argument name ' + assert.stringify(name) + ' supplied to enums(map, [name]) combinator (expected a string)'; });
|
||||
}
|
||||
|
||||
var displayName = name || getDefaultName(map);
|
||||
|
||||
function Enums(value, path) {
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
forbidNewOperator(this, Enums);
|
||||
path = path || [displayName];
|
||||
assert(Enums.is(value), function () { return 'Invalid value ' + assert.stringify(value) + ' supplied to ' + path.join('/') + ' (expected one of ' + assert.stringify(Object.keys(map)) + ')'; });
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
Enums.meta = {
|
||||
kind: 'enums',
|
||||
map: map,
|
||||
name: name,
|
||||
identity: true
|
||||
};
|
||||
|
||||
Enums.displayName = displayName;
|
||||
|
||||
Enums.is = function (x) {
|
||||
return (isString(x) || isNumber(x)) && map.hasOwnProperty(x);
|
||||
};
|
||||
|
||||
return Enums;
|
||||
}
|
||||
|
||||
enums.of = function (keys, name) {
|
||||
keys = isString(keys) ? keys.split(' ') : keys;
|
||||
var value = {};
|
||||
keys.forEach(function (k) {
|
||||
value[k] = k;
|
||||
});
|
||||
return enums(value, name);
|
||||
};
|
||||
|
||||
enums.getDefaultName = getDefaultName;
|
||||
module.exports = enums;
|
||||
|
||||
64
backend/frontend/node_modules/tcomb/lib/extend.js
generated
vendored
Normal file
64
backend/frontend/node_modules/tcomb/lib/extend.js
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
var assert = require('./assert');
|
||||
var isFunction = require('./isFunction');
|
||||
var isArray = require('./isArray');
|
||||
var mixin = require('./mixin');
|
||||
var isStruct = require('./isStruct');
|
||||
var isInterface = require('./isInterface');
|
||||
var isObject = require('./isObject');
|
||||
var refinement = require('./refinement');
|
||||
var decompose = require('./decompose');
|
||||
|
||||
function compose(predicates, unrefinedType, name) {
|
||||
var result = predicates.reduce(function (type, predicate) {
|
||||
return refinement(type, predicate);
|
||||
}, unrefinedType);
|
||||
if (name) {
|
||||
result.displayName = name;
|
||||
result.meta.name = name;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function getProps(type) {
|
||||
return isObject(type) ? type : type.meta.props;
|
||||
}
|
||||
|
||||
function getDefaultProps(type) {
|
||||
return isObject(type) ? null : type.meta.defaultProps;
|
||||
}
|
||||
|
||||
function pushAll(arr, elements) {
|
||||
Array.prototype.push.apply(arr, elements);
|
||||
}
|
||||
|
||||
function extend(combinator, mixins, options) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isFunction(combinator), function () { return 'Invalid argument combinator supplied to extend(combinator, mixins, options), expected a function'; });
|
||||
assert(isArray(mixins), function () { return 'Invalid argument mixins supplied to extend(combinator, mixins, options), expected an array'; });
|
||||
}
|
||||
var props = {};
|
||||
var prototype = {};
|
||||
var predicates = [];
|
||||
var defaultProps = {};
|
||||
mixins.forEach(function (x, i) {
|
||||
var decomposition = decompose(x);
|
||||
var unrefinedType = decomposition.unrefinedType;
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isObject(unrefinedType) || isStruct(unrefinedType) || isInterface(unrefinedType), function () { return 'Invalid argument mixins[' + i + '] supplied to extend(combinator, mixins, options), expected an object, struct, interface or a refinement (of struct or interface)'; });
|
||||
}
|
||||
pushAll(predicates, decomposition.predicates);
|
||||
mixin(props, getProps(unrefinedType));
|
||||
mixin(prototype, unrefinedType.prototype);
|
||||
mixin(defaultProps, getDefaultProps(unrefinedType), true);
|
||||
});
|
||||
options = combinator.getOptions(options);
|
||||
options.defaultProps = mixin(defaultProps, options.defaultProps, true);
|
||||
var result = compose(predicates, combinator(props, {
|
||||
strict: options.strict,
|
||||
defaultProps: options.defaultProps
|
||||
}), options.name);
|
||||
mixin(result.prototype, prototype);
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = extend;
|
||||
3
backend/frontend/node_modules/tcomb/lib/fail.js
generated
vendored
Normal file
3
backend/frontend/node_modules/tcomb/lib/fail.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
module.exports = function fail(message) {
|
||||
throw new TypeError('[tcomb] ' + message);
|
||||
};
|
||||
6
backend/frontend/node_modules/tcomb/lib/forbidNewOperator.js
generated
vendored
Normal file
6
backend/frontend/node_modules/tcomb/lib/forbidNewOperator.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
var assert = require('./assert');
|
||||
var getTypeName = require('./getTypeName');
|
||||
|
||||
module.exports = function forbidNewOperator(x, type) {
|
||||
assert(!(x instanceof type), function () { return 'Cannot use the new operator to instantiate the type ' + getTypeName(type); });
|
||||
};
|
||||
5
backend/frontend/node_modules/tcomb/lib/fromJSON.d.ts
generated
vendored
Normal file
5
backend/frontend/node_modules/tcomb/lib/fromJSON.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import * as t from '../.'
|
||||
|
||||
declare function fromJSON<T>(value: any, type: t.Type<T>): T;
|
||||
|
||||
export default fromJSON
|
||||
155
backend/frontend/node_modules/tcomb/lib/fromJSON.js
generated
vendored
Normal file
155
backend/frontend/node_modules/tcomb/lib/fromJSON.js
generated
vendored
Normal file
@@ -0,0 +1,155 @@
|
||||
var assert = require('./assert');
|
||||
var isFunction = require('./isFunction');
|
||||
var isNil = require('./isNil');
|
||||
var getTypeName = require('./getTypeName');
|
||||
var isObject = require('./isObject');
|
||||
var isArray = require('./isArray');
|
||||
var isType = require('./isType');
|
||||
var create = require('./create');
|
||||
var assign = require('./assign');
|
||||
|
||||
function assignMany(values) {
|
||||
return values.reduce(function (acc, v) {
|
||||
return assign(acc, v);
|
||||
}, {});
|
||||
}
|
||||
|
||||
function fromJSON(value, type, path) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isFunction(type), function () {
|
||||
return 'Invalid argument type ' + assert.stringify(type) + ' supplied to fromJSON(value, type) (expected a type)';
|
||||
});
|
||||
path = path || [getTypeName(type)];
|
||||
}
|
||||
|
||||
if (isFunction(type.fromJSON)) {
|
||||
return create(type, type.fromJSON(value), path);
|
||||
}
|
||||
|
||||
if (!isType(type)) {
|
||||
return value instanceof type ? value : new type(value);
|
||||
}
|
||||
|
||||
var kind = type.meta.kind;
|
||||
var k;
|
||||
var ret;
|
||||
|
||||
switch (kind) {
|
||||
|
||||
case 'maybe' :
|
||||
return isNil(value) ? null : fromJSON(value, type.meta.type, path);
|
||||
|
||||
case 'subtype' : // the kind of a refinement is 'subtype' (for legacy reasons)
|
||||
ret = fromJSON(value, type.meta.type, path);
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(type.meta.predicate(ret), function () {
|
||||
return 'Invalid argument value ' + assert.stringify(value) + ' supplied to fromJSON(value, type) (expected a valid ' + getTypeName(type) + ')';
|
||||
});
|
||||
}
|
||||
return ret;
|
||||
|
||||
case 'struct' :
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isObject(value), function () {
|
||||
return 'Invalid argument value ' + assert.stringify(value) + ' supplied to fromJSON(value, type) (expected an object for type ' + getTypeName(type) + ')';
|
||||
});
|
||||
}
|
||||
var props = type.meta.props;
|
||||
var defaultProps = type.meta.defaultProps;
|
||||
ret = {};
|
||||
for (k in props) {
|
||||
var actual = value[k];
|
||||
if (actual === undefined) {
|
||||
actual = defaultProps[k];
|
||||
}
|
||||
if (props.hasOwnProperty(k)) {
|
||||
ret[k] = fromJSON(actual, props[k], ( process.env.NODE_ENV !== 'production' ? path.concat(k + ': ' + getTypeName(props[k])) : null ));
|
||||
}
|
||||
}
|
||||
return new type(ret);
|
||||
|
||||
case 'interface' :
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isObject(value), function () {
|
||||
return 'Invalid argument value ' + assert.stringify(value) + ' supplied to fromJSON(value, type) (expected an object)';
|
||||
});
|
||||
}
|
||||
var interProps = type.meta.props;
|
||||
ret = {};
|
||||
for (k in interProps) {
|
||||
if (interProps.hasOwnProperty(k)) {
|
||||
ret[k] = fromJSON(value[k], interProps[k], ( process.env.NODE_ENV !== 'production' ? path.concat(k + ': ' + getTypeName(interProps[k])) : null ));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
||||
case 'list' :
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isArray(value), function () {
|
||||
return 'Invalid argument value ' + assert.stringify(value) + ' supplied to fromJSON(value, type) (expected an array for type ' + getTypeName(type) + ')';
|
||||
});
|
||||
}
|
||||
var elementType = type.meta.type;
|
||||
var elementTypeName = getTypeName(elementType);
|
||||
return value.map(function (element, i) {
|
||||
return fromJSON(element, elementType, ( process.env.NODE_ENV !== 'production' ? path.concat(i + ': ' + elementTypeName) : null ));
|
||||
});
|
||||
|
||||
case 'union' :
|
||||
var actualType = type.dispatch(value);
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isFunction(actualType), function () {
|
||||
return 'Invalid argument value ' + assert.stringify(value) + ' supplied to fromJSON(value, type) (no constructor returned by dispatch of union ' + getTypeName(type) + ')';
|
||||
});
|
||||
}
|
||||
return fromJSON(value, actualType, path);
|
||||
|
||||
case 'tuple' :
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isArray(value), function () {
|
||||
return 'Invalid argument value ' + assert.stringify(value) + ' supplied to fromJSON(value, type) (expected an array for type ' + getTypeName(type) + ')';
|
||||
});
|
||||
}
|
||||
var types = type.meta.types;
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isArray(value) && value.length === types.length, function () {
|
||||
return 'Invalid value ' + assert.stringify(value) + ' supplied to fromJSON(value, type) (expected an array of length ' + types.length + ' for type ' + getTypeName(type) + ')';
|
||||
});
|
||||
}
|
||||
return value.map(function (element, i) {
|
||||
return fromJSON(element, types[i], ( process.env.NODE_ENV !== 'production' ? path.concat(i + ': ' + getTypeName(types[i])) : null ));
|
||||
});
|
||||
|
||||
case 'dict' :
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isObject(value), function () {
|
||||
return 'Invalid argument value ' + assert.stringify(value) + ' supplied to fromJSON(value, type) (expected an object for type ' + getTypeName(type) + ')';
|
||||
});
|
||||
}
|
||||
var domain = type.meta.domain;
|
||||
var codomain = type.meta.codomain;
|
||||
var domainName = getTypeName(domain);
|
||||
var codomainName = getTypeName(codomain);
|
||||
ret = {};
|
||||
for (k in value) {
|
||||
if (value.hasOwnProperty(k)) {
|
||||
ret[domain(k, ( process.env.NODE_ENV !== 'production' ? path.concat(domainName) : null ))] = fromJSON(value[k], codomain, ( process.env.NODE_ENV !== 'production' ? path.concat(k + ': ' + codomainName) : null ));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
||||
case 'intersection' :
|
||||
var values = type.meta.types.map(function (type, i) {
|
||||
return fromJSON(value, type, ( process.env.NODE_ENV !== 'production' ? path.concat(i + ': ' + getTypeName(type)) : null ));
|
||||
});
|
||||
return type(
|
||||
isObject(values[0]) ? assignMany(values) : value,
|
||||
path
|
||||
);
|
||||
|
||||
default : // enums, irreducible
|
||||
return type(value, path);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = fromJSON;
|
||||
136
backend/frontend/node_modules/tcomb/lib/func.js
generated
vendored
Normal file
136
backend/frontend/node_modules/tcomb/lib/func.js
generated
vendored
Normal file
@@ -0,0 +1,136 @@
|
||||
var assert = require('./assert');
|
||||
var isTypeName = require('./isTypeName');
|
||||
var FunctionType = require('./Function');
|
||||
var isArray = require('./isArray');
|
||||
var list = require('./list');
|
||||
var isObject = require('./isObject');
|
||||
var create = require('./create');
|
||||
var isNil = require('./isNil');
|
||||
var isBoolean = require('./isBoolean');
|
||||
var tuple = require('./tuple');
|
||||
var getFunctionName = require('./getFunctionName');
|
||||
var getTypeName = require('./getTypeName');
|
||||
var isType = require('./isType');
|
||||
|
||||
function getDefaultName(domain, codomain) {
|
||||
return '(' + domain.map(getTypeName).join(', ') + ') => ' + getTypeName(codomain);
|
||||
}
|
||||
|
||||
function isInstrumented(f) {
|
||||
return FunctionType.is(f) && isObject(f.instrumentation);
|
||||
}
|
||||
|
||||
function getOptionalArgumentsIndex(types) {
|
||||
var end = types.length;
|
||||
var areAllMaybes = false;
|
||||
for (var i = end - 1; i >= 0; i--) {
|
||||
var type = types[i];
|
||||
if (!isType(type) || type.meta.kind !== 'maybe') {
|
||||
return (i + 1);
|
||||
} else {
|
||||
areAllMaybes = true;
|
||||
}
|
||||
}
|
||||
return areAllMaybes ? 0 : end;
|
||||
}
|
||||
|
||||
function func(domain, codomain, name) {
|
||||
|
||||
domain = isArray(domain) ? domain : [domain]; // handle handy syntax for unary functions
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(list(FunctionType).is(domain), function () { return 'Invalid argument domain ' + assert.stringify(domain) + ' supplied to func(domain, codomain, [name]) combinator (expected an array of types)'; });
|
||||
assert(FunctionType.is(codomain), function () { return 'Invalid argument codomain ' + assert.stringify(codomain) + ' supplied to func(domain, codomain, [name]) combinator (expected a type)'; });
|
||||
assert(isTypeName(name), function () { return 'Invalid argument name ' + assert.stringify(name) + ' supplied to func(domain, codomain, [name]) combinator (expected a string)'; });
|
||||
}
|
||||
|
||||
var displayName = name || getDefaultName(domain, codomain);
|
||||
var domainLength = domain.length;
|
||||
var optionalArgumentsIndex = getOptionalArgumentsIndex(domain);
|
||||
|
||||
function FuncType(value, path) {
|
||||
|
||||
if (!isInstrumented(value)) { // automatically instrument the function
|
||||
return FuncType.of(value);
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
path = path || [displayName];
|
||||
assert(FuncType.is(value), function () { return 'Invalid value ' + assert.stringify(value) + ' supplied to ' + path.join('/'); });
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
FuncType.meta = {
|
||||
kind: 'func',
|
||||
domain: domain,
|
||||
codomain: codomain,
|
||||
name: name,
|
||||
identity: true
|
||||
};
|
||||
|
||||
FuncType.displayName = displayName;
|
||||
|
||||
FuncType.is = function (x) {
|
||||
return isInstrumented(x) &&
|
||||
x.instrumentation.domain.length === domainLength &&
|
||||
x.instrumentation.domain.every(function (type, i) {
|
||||
return type === domain[i];
|
||||
}) &&
|
||||
x.instrumentation.codomain === codomain;
|
||||
};
|
||||
|
||||
FuncType.of = function (f, curried) {
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(FunctionType.is(f), function () { return 'Invalid argument f supplied to func.of ' + displayName + ' (expected a function)'; });
|
||||
assert(isNil(curried) || isBoolean(curried), function () { return 'Invalid argument curried ' + assert.stringify(curried) + ' supplied to func.of ' + displayName + ' (expected a boolean)'; });
|
||||
}
|
||||
|
||||
if (FuncType.is(f)) { // makes FuncType.of idempotent
|
||||
return f;
|
||||
}
|
||||
|
||||
function fn() {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
var argsLength = args.length;
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
// type-check arguments
|
||||
var tupleLength = curried ? argsLength : Math.max(argsLength, optionalArgumentsIndex);
|
||||
tuple(domain.slice(0, tupleLength), 'arguments of function ' + displayName)(args);
|
||||
}
|
||||
|
||||
if (curried && argsLength < domainLength) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(argsLength > 0, 'Invalid arguments.length = 0 for curried function ' + displayName);
|
||||
}
|
||||
var g = Function.prototype.bind.apply(f, [this].concat(args));
|
||||
var newDomain = func(domain.slice(argsLength), codomain);
|
||||
return newDomain.of(g, true);
|
||||
}
|
||||
else {
|
||||
return create(codomain, f.apply(this, args));
|
||||
}
|
||||
}
|
||||
|
||||
fn.instrumentation = {
|
||||
domain: domain,
|
||||
codomain: codomain,
|
||||
f: f
|
||||
};
|
||||
|
||||
fn.displayName = getFunctionName(f);
|
||||
|
||||
return fn;
|
||||
|
||||
};
|
||||
|
||||
return FuncType;
|
||||
|
||||
}
|
||||
|
||||
func.getDefaultName = getDefaultName;
|
||||
func.getOptionalArgumentsIndex = getOptionalArgumentsIndex;
|
||||
module.exports = func;
|
||||
9
backend/frontend/node_modules/tcomb/lib/getDefaultInterfaceName.js
generated
vendored
Normal file
9
backend/frontend/node_modules/tcomb/lib/getDefaultInterfaceName.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
var getTypeName = require('./getTypeName');
|
||||
|
||||
function getDefaultInterfaceName(props) {
|
||||
return '{' + Object.keys(props).map(function (prop) {
|
||||
return prop + ': ' + getTypeName(props[prop]);
|
||||
}).join(', ') + '}';
|
||||
}
|
||||
|
||||
module.exports = getDefaultInterfaceName;
|
||||
3
backend/frontend/node_modules/tcomb/lib/getFunctionName.js
generated
vendored
Normal file
3
backend/frontend/node_modules/tcomb/lib/getFunctionName.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
module.exports = function getFunctionName(f) {
|
||||
return f.displayName || f.name || '<function' + f.length + '>';
|
||||
};
|
||||
9
backend/frontend/node_modules/tcomb/lib/getTypeName.js
generated
vendored
Normal file
9
backend/frontend/node_modules/tcomb/lib/getTypeName.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
var isType = require('./isType');
|
||||
var getFunctionName = require('./getFunctionName');
|
||||
|
||||
module.exports = function getTypeName(ctor) {
|
||||
if (isType(ctor)) {
|
||||
return ctor.displayName;
|
||||
}
|
||||
return getFunctionName(ctor);
|
||||
};
|
||||
85
backend/frontend/node_modules/tcomb/lib/installTypeFormatter.js
generated
vendored
Normal file
85
backend/frontend/node_modules/tcomb/lib/installTypeFormatter.js
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
var isType = require('./isType');
|
||||
var getTypeName = require('./getTypeName');
|
||||
|
||||
var listStyle = {style: 'list-style-type: none; padding: 5px 10px; margin: 0;'};
|
||||
var listItemStyle = {style: 'padding: 3px 0;'};
|
||||
var typeStyle = {style: 'font-weight: bolder;'};
|
||||
var propStyle = {style: 'color: #881391;'};
|
||||
var metaStyle = {style: 'color: #777;'};
|
||||
|
||||
function getKindName(kind) {
|
||||
return kind === 'subtype' ? 'refinement' : kind;
|
||||
}
|
||||
|
||||
var TypeFormatter = {
|
||||
header: function (x) {
|
||||
if (!isType(x)) {
|
||||
return null;
|
||||
}
|
||||
return ['span',
|
||||
['span', typeStyle, getTypeName(x)],
|
||||
' (' + getKindName(x.meta.kind) + ')'
|
||||
];
|
||||
},
|
||||
hasBody: function (x) {
|
||||
return x.meta.kind !== 'irreducible';
|
||||
},
|
||||
body: function (x) {
|
||||
if (x.meta.kind === 'struct' || x.meta.kind === 'interface') {
|
||||
var props = Object.keys(x.meta.props).map(function (prop) {
|
||||
return ['li', listItemStyle,
|
||||
['span', propStyle, prop + ': '],
|
||||
['object', { object: x.meta.props[prop] }]
|
||||
];
|
||||
});
|
||||
return ['ol', listStyle].concat(props);
|
||||
}
|
||||
if (x.meta.kind === 'dict') {
|
||||
return ['ol', listStyle,
|
||||
['li', listItemStyle,
|
||||
['span', metaStyle, 'domain: '],
|
||||
['object', { object: x.meta.domain }]
|
||||
],
|
||||
['li', listItemStyle,
|
||||
['span', metaStyle, 'codomain: '],
|
||||
['object', { object: x.meta.codomain }]
|
||||
]
|
||||
];
|
||||
}
|
||||
if (x.meta.kind === 'list' || x.meta.kind === 'subtype' || x.meta.kind === 'maybe') {
|
||||
return ['ol', listStyle,
|
||||
['li', listItemStyle,
|
||||
['span', metaStyle, 'type: '],
|
||||
['object', { object: x.meta.type }]
|
||||
]
|
||||
];
|
||||
}
|
||||
if (x.meta.kind === 'enums') {
|
||||
var enums = Object.keys(x.meta.map).map(function (e) {
|
||||
return ['li', listItemStyle,
|
||||
['span', propStyle, e + ': '],
|
||||
['object', { object: x.meta.map[e] }]
|
||||
];
|
||||
});
|
||||
return ['ol', listStyle].concat(enums);
|
||||
}
|
||||
if (x.meta.kind === 'union' || x.meta.kind === 'tuple' || x.meta.kind === 'intersection') {
|
||||
var types = x.meta.types.map(function (type) {
|
||||
return ['li', listItemStyle,
|
||||
['object', { object: type }]
|
||||
];
|
||||
});
|
||||
return ['ol', listStyle].concat(types);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function installTypeFormatter() {
|
||||
if (typeof window !== 'undefined') {
|
||||
window.devtoolsFormatters = window.devtoolsFormatters || [];
|
||||
window.devtoolsFormatters.push(TypeFormatter);
|
||||
}
|
||||
}
|
||||
|
||||
installTypeFormatter.TypeFormatter = TypeFormatter;
|
||||
module.exports = installTypeFormatter;
|
||||
131
backend/frontend/node_modules/tcomb/lib/interface.js
generated
vendored
Normal file
131
backend/frontend/node_modules/tcomb/lib/interface.js
generated
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
var assert = require('./assert');
|
||||
var isTypeName = require('./isTypeName');
|
||||
var String = require('./String');
|
||||
var Function = require('./Function');
|
||||
var isBoolean = require('./isBoolean');
|
||||
var isObject = require('./isObject');
|
||||
var isNil = require('./isNil');
|
||||
var create = require('./create');
|
||||
var getTypeName = require('./getTypeName');
|
||||
var dict = require('./dict');
|
||||
var getDefaultInterfaceName = require('./getDefaultInterfaceName');
|
||||
var isIdentity = require('./isIdentity');
|
||||
var is = require('./is');
|
||||
var extend = require('./extend');
|
||||
var assign = require('./assign');
|
||||
|
||||
function extendInterface(mixins, name) {
|
||||
return extend(inter, mixins, name);
|
||||
}
|
||||
|
||||
function getOptions(options) {
|
||||
if (!isObject(options)) {
|
||||
options = isNil(options) ? {} : { name: options };
|
||||
}
|
||||
if (!options.hasOwnProperty('strict')) {
|
||||
options.strict = inter.strict;
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
function inter(props, options) {
|
||||
|
||||
options = getOptions(options);
|
||||
var name = options.name;
|
||||
var strict = options.strict;
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(dict(String, Function).is(props), function () { return 'Invalid argument props ' + assert.stringify(props) + ' supplied to interface(props, [options]) combinator (expected a dictionary String -> Type)'; });
|
||||
assert(isTypeName(name), function () { return 'Invalid argument name ' + assert.stringify(name) + ' supplied to interface(props, [options]) combinator (expected a string)'; });
|
||||
assert(isBoolean(strict), function () { return 'Invalid argument strict ' + assert.stringify(strict) + ' supplied to struct(props, [options]) combinator (expected a boolean)'; });
|
||||
}
|
||||
|
||||
var displayName = name || getDefaultInterfaceName(props);
|
||||
var identity = Object.keys(props).map(function (prop) { return props[prop]; }).every(isIdentity);
|
||||
|
||||
function Interface(value, path) {
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
if (identity) {
|
||||
return value; // just trust the input if elements must not be hydrated
|
||||
}
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
path = path || [displayName];
|
||||
assert(!isNil(value), function () { return 'Invalid value ' + value + ' supplied to ' + path.join('/'); });
|
||||
// strictness
|
||||
if (strict) {
|
||||
for (var k in value) {
|
||||
assert(props.hasOwnProperty(k), function () { return 'Invalid additional prop "' + k + '" supplied to ' + path.join('/'); });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var idempotent = true;
|
||||
var ret = identity ? {} : assign({}, value);
|
||||
for (var prop in props) {
|
||||
var expected = props[prop];
|
||||
var actual = value[prop];
|
||||
var instance = create(expected, actual, ( process.env.NODE_ENV !== 'production' ? path.concat(prop + ': ' + getTypeName(expected)) : null ));
|
||||
idempotent = idempotent && ( actual === instance );
|
||||
ret[prop] = instance;
|
||||
}
|
||||
|
||||
if (idempotent) { // implements idempotency
|
||||
ret = value;
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
Object.freeze(ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
Interface.meta = {
|
||||
kind: 'interface',
|
||||
props: props,
|
||||
name: name,
|
||||
identity: identity,
|
||||
strict: strict
|
||||
};
|
||||
|
||||
Interface.displayName = displayName;
|
||||
|
||||
Interface.is = function (x) {
|
||||
if (isNil(x)) {
|
||||
return false;
|
||||
}
|
||||
if (strict) {
|
||||
for (var k in x) {
|
||||
if (!props.hasOwnProperty(k)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (var prop in props) {
|
||||
if (!is(x[prop], props[prop])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
Interface.update = function (instance, patch) {
|
||||
return Interface(assert.update(instance, patch));
|
||||
};
|
||||
|
||||
Interface.extend = function (xs, name) {
|
||||
return extendInterface([Interface].concat(xs), name);
|
||||
};
|
||||
|
||||
return Interface;
|
||||
}
|
||||
|
||||
inter.strict = false;
|
||||
inter.getOptions = getOptions;
|
||||
inter.getDefaultName = getDefaultInterfaceName;
|
||||
inter.extend = extendInterface;
|
||||
module.exports = inter;
|
||||
61
backend/frontend/node_modules/tcomb/lib/intersection.js
generated
vendored
Normal file
61
backend/frontend/node_modules/tcomb/lib/intersection.js
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
var assert = require('./assert');
|
||||
var isTypeName = require('./isTypeName');
|
||||
var isFunction = require('./isFunction');
|
||||
var isArray = require('./isArray');
|
||||
var forbidNewOperator = require('./isIdentity');
|
||||
var is = require('./is');
|
||||
var getTypeName = require('./getTypeName');
|
||||
var isIdentity = require('./isIdentity');
|
||||
|
||||
function getDefaultName(types) {
|
||||
return types.map(getTypeName).join(' & ');
|
||||
}
|
||||
|
||||
function intersection(types, name) {
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isArray(types) && types.every(isFunction) && types.length >= 2, function () { return 'Invalid argument types ' + assert.stringify(types) + ' supplied to intersection(types, [name]) combinator (expected an array of at least 2 types)'; });
|
||||
assert(isTypeName(name), function () { return 'Invalid argument name ' + assert.stringify(name) + ' supplied to intersection(types, [name]) combinator (expected a string)'; });
|
||||
}
|
||||
|
||||
var displayName = name || getDefaultName(types);
|
||||
var identity = types.every(isIdentity);
|
||||
|
||||
function Intersection(value, path) {
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (identity) {
|
||||
forbidNewOperator(this, Intersection);
|
||||
}
|
||||
path = path || [displayName];
|
||||
assert(Intersection.is(value), function () { return 'Invalid value ' + assert.stringify(value) + ' supplied to ' + path.join('/'); });
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
Intersection.meta = {
|
||||
kind: 'intersection',
|
||||
types: types,
|
||||
name: name,
|
||||
identity: identity
|
||||
};
|
||||
|
||||
Intersection.displayName = displayName;
|
||||
|
||||
Intersection.is = function (x) {
|
||||
return types.every(function (type) {
|
||||
return is(x, type);
|
||||
});
|
||||
};
|
||||
|
||||
Intersection.update = function (instance, patch) {
|
||||
return Intersection(assert.update(instance, patch));
|
||||
};
|
||||
|
||||
return Intersection;
|
||||
}
|
||||
|
||||
intersection.getDefaultName = getDefaultName;
|
||||
module.exports = intersection;
|
||||
|
||||
36
backend/frontend/node_modules/tcomb/lib/irreducible.js
generated
vendored
Normal file
36
backend/frontend/node_modules/tcomb/lib/irreducible.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
var assert = require('./assert');
|
||||
var isString = require('./isString');
|
||||
var isFunction = require('./isFunction');
|
||||
var forbidNewOperator = require('./forbidNewOperator');
|
||||
|
||||
module.exports = function irreducible(name, predicate) {
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isString(name), function () { return 'Invalid argument name ' + assert.stringify(name) + ' supplied to irreducible(name, predicate) (expected a string)'; });
|
||||
assert(isFunction(predicate), 'Invalid argument predicate ' + assert.stringify(predicate) + ' supplied to irreducible(name, predicate) (expected a function)');
|
||||
}
|
||||
|
||||
function Irreducible(value, path) {
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
forbidNewOperator(this, Irreducible);
|
||||
path = path || [name];
|
||||
assert(predicate(value), function () { return 'Invalid value ' + assert.stringify(value) + ' supplied to ' + path.join('/'); });
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
Irreducible.meta = {
|
||||
kind: 'irreducible',
|
||||
name: name,
|
||||
predicate: predicate,
|
||||
identity: true
|
||||
};
|
||||
|
||||
Irreducible.displayName = name;
|
||||
|
||||
Irreducible.is = predicate;
|
||||
|
||||
return Irreducible;
|
||||
};
|
||||
9
backend/frontend/node_modules/tcomb/lib/is.js
generated
vendored
Normal file
9
backend/frontend/node_modules/tcomb/lib/is.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
var isType = require('./isType');
|
||||
|
||||
// returns true if x is an instance of type
|
||||
module.exports = function is(x, type) {
|
||||
if (isType(type)) {
|
||||
return type.is(x);
|
||||
}
|
||||
return x instanceof type; // type should be a class constructor
|
||||
};
|
||||
3
backend/frontend/node_modules/tcomb/lib/isArray.js
generated
vendored
Normal file
3
backend/frontend/node_modules/tcomb/lib/isArray.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
module.exports = function isArray(x) {
|
||||
return Array.isArray ? Array.isArray(x) : x instanceof Array;
|
||||
};
|
||||
3
backend/frontend/node_modules/tcomb/lib/isBoolean.js
generated
vendored
Normal file
3
backend/frontend/node_modules/tcomb/lib/isBoolean.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
module.exports = function isBoolean(x) {
|
||||
return x === true || x === false;
|
||||
};
|
||||
3
backend/frontend/node_modules/tcomb/lib/isFunction.js
generated
vendored
Normal file
3
backend/frontend/node_modules/tcomb/lib/isFunction.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
module.exports = function isFunction(x) {
|
||||
return typeof x === 'function';
|
||||
};
|
||||
16
backend/frontend/node_modules/tcomb/lib/isIdentity.js
generated
vendored
Normal file
16
backend/frontend/node_modules/tcomb/lib/isIdentity.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
var assert = require('./assert');
|
||||
var Boolean = require('./Boolean');
|
||||
var isType = require('./isType');
|
||||
var getTypeName = require('./getTypeName');
|
||||
|
||||
// return true if the type constructor behaves like the identity function
|
||||
module.exports = function isIdentity(type) {
|
||||
if (isType(type)) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(Boolean.is(type.meta.identity), function () { return 'Invalid meta identity ' + assert.stringify(type.meta.identity) + ' supplied to type ' + getTypeName(type); });
|
||||
}
|
||||
return type.meta.identity;
|
||||
}
|
||||
// for tcomb the other constructors, like ES6 classes, are identity-like
|
||||
return true;
|
||||
};
|
||||
5
backend/frontend/node_modules/tcomb/lib/isInterface.js
generated
vendored
Normal file
5
backend/frontend/node_modules/tcomb/lib/isInterface.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
var isType = require('./isType');
|
||||
|
||||
module.exports = function isInterface(x) {
|
||||
return isType(x) && ( x.meta.kind === 'interface' );
|
||||
};
|
||||
5
backend/frontend/node_modules/tcomb/lib/isMaybe.js
generated
vendored
Normal file
5
backend/frontend/node_modules/tcomb/lib/isMaybe.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
var isType = require('./isType');
|
||||
|
||||
module.exports = function isMaybe(x) {
|
||||
return isType(x) && ( x.meta.kind === 'maybe' );
|
||||
};
|
||||
3
backend/frontend/node_modules/tcomb/lib/isNil.js
generated
vendored
Normal file
3
backend/frontend/node_modules/tcomb/lib/isNil.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
module.exports = function isNil(x) {
|
||||
return x === null || x === void 0;
|
||||
};
|
||||
3
backend/frontend/node_modules/tcomb/lib/isNumber.js
generated
vendored
Normal file
3
backend/frontend/node_modules/tcomb/lib/isNumber.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
module.exports = function isNumber(x) {
|
||||
return typeof x === 'number' && isFinite(x) && !isNaN(x);
|
||||
};
|
||||
6
backend/frontend/node_modules/tcomb/lib/isObject.js
generated
vendored
Normal file
6
backend/frontend/node_modules/tcomb/lib/isObject.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
var isNil = require('./isNil');
|
||||
var isArray = require('./isArray');
|
||||
|
||||
module.exports = function isObject(x) {
|
||||
return !isNil(x) && typeof x === 'object' && !isArray(x);
|
||||
};
|
||||
3
backend/frontend/node_modules/tcomb/lib/isString.js
generated
vendored
Normal file
3
backend/frontend/node_modules/tcomb/lib/isString.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
module.exports = function isString(x) {
|
||||
return typeof x === 'string';
|
||||
};
|
||||
5
backend/frontend/node_modules/tcomb/lib/isStruct.js
generated
vendored
Normal file
5
backend/frontend/node_modules/tcomb/lib/isStruct.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
var isType = require('./isType');
|
||||
|
||||
module.exports = function isStruct(x) {
|
||||
return isType(x) && ( x.meta.kind === 'struct' );
|
||||
};
|
||||
5
backend/frontend/node_modules/tcomb/lib/isSubsetOf.d.ts
generated
vendored
Normal file
5
backend/frontend/node_modules/tcomb/lib/isSubsetOf.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import * as t from '../.'
|
||||
|
||||
declare function isSubsetOf(subset: t.Type<any>, superset: t.Type<any>): boolean;
|
||||
|
||||
export default isSubsetOf
|
||||
194
backend/frontend/node_modules/tcomb/lib/isSubsetOf.js
generated
vendored
Normal file
194
backend/frontend/node_modules/tcomb/lib/isSubsetOf.js
generated
vendored
Normal file
@@ -0,0 +1,194 @@
|
||||
var assert = require('./assert');
|
||||
var decompose = require('./decompose');
|
||||
var isType = require('./isType');
|
||||
var Any = require('./Any');
|
||||
var Array = require('./Array');
|
||||
var Function = require('./Function');
|
||||
var Nil = require('./Nil');
|
||||
var tObject = require('./Object');
|
||||
|
||||
function leqList(As, Bs) {
|
||||
return ( As.length === Bs.length ) && As.every(function (A, i) {
|
||||
return recurse(A, Bs[i]);
|
||||
});
|
||||
}
|
||||
|
||||
function leqPredicates(ps1, ps2) {
|
||||
return ps2.length <= ps1.length && ps2.every(function (p) {
|
||||
return ps1.indexOf(p) !== -1;
|
||||
});
|
||||
}
|
||||
|
||||
var index = [];
|
||||
|
||||
function find(A, B) {
|
||||
for (var i = 0, len = index.length ; i < len ; i++) {
|
||||
var item = index[i];
|
||||
if (item.A === A && item.B === B) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function leq(A, B) {
|
||||
|
||||
// Fast results
|
||||
// (1) if B === t.Any then A <= B for all A
|
||||
// (2) if B === A then A <= B for all A
|
||||
if (A === B || B === Any) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var kindA = A.meta.kind;
|
||||
var kindB = B.meta.kind;
|
||||
|
||||
// Reductions
|
||||
|
||||
// (3) if B = maybe(C) and A is not a maybe then A <= B if and only if A === t.Nil or A <= C
|
||||
if (kindB === 'maybe' && kindA !== 'maybe') {
|
||||
return ( A === Nil ) || recurse(A, B.meta.type);
|
||||
}
|
||||
|
||||
function gte(type) {
|
||||
return recurse(A, type);
|
||||
}
|
||||
|
||||
// (4) if B is a union then A <= B if exists B' in B.meta.types such that A <= B'
|
||||
if (kindB === 'union') {
|
||||
if (B.meta.types.some(gte)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// (5) if B is an intersection then A <= B if A <= B' for all B' in B.meta.types
|
||||
if (kindB === 'intersection') {
|
||||
if (B.meta.types.every(gte)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Let A be a struct then A <= B if B === t.Object
|
||||
if (kindA === 'struct') {
|
||||
return B === tObject;
|
||||
}
|
||||
|
||||
// Let A be a maybe then A <= B if B is a maybe and A.meta.type <= B.meta.type
|
||||
else if (kindA === 'maybe') {
|
||||
return ( kindB === 'maybe' ) && recurse(A.meta.type, B.meta.type);
|
||||
}
|
||||
|
||||
// Let A be an union then A <= B if A' <= B for all A' in A.meta.types
|
||||
else if (kindA === 'union') {
|
||||
return A.meta.types.every(function (T) {
|
||||
return recurse(T, B);
|
||||
});
|
||||
}
|
||||
|
||||
// Let A be an intersection then A <= B if exists A' in A.meta.types such that A' <= B
|
||||
else if (kindA === 'intersection') {
|
||||
return A.meta.types.some(function (T) {
|
||||
return recurse(T, B);
|
||||
});
|
||||
}
|
||||
|
||||
// Let A be irreducible then A <= B if B is irreducible and A.is === B.is
|
||||
else if (kindA === 'irreducible') {
|
||||
return ( kindB === 'irreducible' ) && ( A.meta.predicate === B.meta.predicate );
|
||||
}
|
||||
|
||||
// Let A be an enum then A <= B if and only if B.is(a) === true for all a in keys(A.meta.map)
|
||||
else if (kindA === 'enums') {
|
||||
return Object.keys(A.meta.map).every(B.is);
|
||||
}
|
||||
|
||||
// Let A be a refinement then A <= B if decompose(A) <= decompose(B)
|
||||
else if (kindA === 'subtype') {
|
||||
var dA = decompose(A);
|
||||
var dB = decompose(B);
|
||||
return leqPredicates(dA.predicates, dB.predicates) && recurse(dA.unrefinedType, dB.unrefinedType);
|
||||
}
|
||||
|
||||
// Let A be a list then A <= B if one of the following holds:
|
||||
else if (kindA === 'list') {
|
||||
// B === t.Array
|
||||
if (B === Array) {
|
||||
return true;
|
||||
}
|
||||
// B is a list and A.meta.type <= B.meta.type
|
||||
return ( kindB === 'list' ) && recurse(A.meta.type, B.meta.type);
|
||||
}
|
||||
|
||||
// Let A be a list then A <= B if one of the following holds:
|
||||
else if (kindA === 'dict') {
|
||||
// B === t.Object
|
||||
if (B === tObject) {
|
||||
return true;
|
||||
}
|
||||
// B is a dictionary and [A.meta.domain, A.meta.codomain] <= [B.meta.domain, B.meta.codomain]
|
||||
return ( kindB === 'dict' ) && recurse(A.meta.domain, B.meta.domain) && recurse(A.meta.codomain, B.meta.codomain);
|
||||
}
|
||||
|
||||
// Let A be a tuple then A <= B if one of the following holds:
|
||||
else if (kindA === 'tuple') {
|
||||
// B === t.Array
|
||||
if (B === Array) {
|
||||
return true;
|
||||
}
|
||||
// B is a tuple and A.meta.types <= B.meta.types
|
||||
return ( kindB === 'tuple' ) && leqList(A.meta.types, B.meta.types);
|
||||
}
|
||||
|
||||
// Let A be a function then then A <= B if one of the following holds:
|
||||
else if (kindA === 'func') {
|
||||
// B === t.Function
|
||||
if (B === Function) {
|
||||
return true;
|
||||
}
|
||||
// B is a function and [A.meta.domain, A.meta.codomain] <= [B.meta.domain, B.meta.codomain]
|
||||
return ( kindB === 'func' ) && recurse(A.meta.codomain, B.meta.codomain) && leqList(A.meta.domain, B.meta.domain);
|
||||
}
|
||||
|
||||
// Let A be an interface then A <= B if one of the following holds:
|
||||
else if (kindA === 'interface') {
|
||||
// B === t.Object
|
||||
if (B === tObject) {
|
||||
return true;
|
||||
}
|
||||
if (kindB === 'interface') {
|
||||
var keysB = Object.keys(B.meta.props);
|
||||
var compatible = keysB.every(function (k) {
|
||||
return A.meta.props.hasOwnProperty(k) && recurse(A.meta.props[k], B.meta.props[k]);
|
||||
});
|
||||
// B is an interface, B.meta.strict === false, keys(B.meta.props) <= keys(A.meta.props) and A.meta.props[k] <= B.meta.props[k] for all k in keys(B.meta.props)
|
||||
if (B.meta.strict === false) {
|
||||
return compatible;
|
||||
}
|
||||
// B is an interface, B.meta.strict === true, A.meta.strict === true, keys(B.meta.props) = keys(A.meta.props) and A.meta.props[k] <= B.meta.props[k] for all k in keys(B.meta.props)
|
||||
return compatible && ( A.meta.strict === true ) && ( keysB.length === Object.keys(A.meta.props).length );
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function recurse(A, B) {
|
||||
// handle recursive types
|
||||
var hit = find(A, B);
|
||||
if (hit) {
|
||||
return hit.leq;
|
||||
}
|
||||
hit = { A: A, B: B, leq: true };
|
||||
index.push(hit);
|
||||
return ( hit.leq = leq(A, B) );
|
||||
}
|
||||
|
||||
function isSubsetOf(A, B) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isType(A), function () { return 'Invalid argument subset ' + assert.stringify(A) + ' supplied to isSubsetOf(subset, superset) (expected a type)'; });
|
||||
assert(isType(B), function () { return 'Invalid argument superset ' + assert.stringify(B) + ' supplied to isSubsetOf(subset, superset) (expected a type)'; });
|
||||
}
|
||||
|
||||
return recurse(A, B);
|
||||
}
|
||||
|
||||
module.exports = isSubsetOf;
|
||||
6
backend/frontend/node_modules/tcomb/lib/isType.js
generated
vendored
Normal file
6
backend/frontend/node_modules/tcomb/lib/isType.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
var isFunction = require('./isFunction');
|
||||
var isObject = require('./isObject');
|
||||
|
||||
module.exports = function isType(x) {
|
||||
return isFunction(x) && isObject(x.meta);
|
||||
};
|
||||
6
backend/frontend/node_modules/tcomb/lib/isTypeName.js
generated
vendored
Normal file
6
backend/frontend/node_modules/tcomb/lib/isTypeName.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
var isNil = require('./isNil');
|
||||
var isString = require('./isString');
|
||||
|
||||
module.exports = function isTypeName(name) {
|
||||
return isNil(name) || isString(name);
|
||||
};
|
||||
5
backend/frontend/node_modules/tcomb/lib/isUnion.js
generated
vendored
Normal file
5
backend/frontend/node_modules/tcomb/lib/isUnion.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
var isType = require('./isType');
|
||||
|
||||
module.exports = function isUnion(x) {
|
||||
return isType(x) && ( x.meta.kind === 'union' );
|
||||
};
|
||||
81
backend/frontend/node_modules/tcomb/lib/list.js
generated
vendored
Normal file
81
backend/frontend/node_modules/tcomb/lib/list.js
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
var assert = require('./assert');
|
||||
var isTypeName = require('./isTypeName');
|
||||
var isFunction = require('./isFunction');
|
||||
var getTypeName = require('./getTypeName');
|
||||
var isIdentity = require('./isIdentity');
|
||||
var create = require('./create');
|
||||
var is = require('./is');
|
||||
var isArray = require('./isArray');
|
||||
|
||||
function getDefaultName(type) {
|
||||
return 'Array<' + getTypeName(type) + '>';
|
||||
}
|
||||
|
||||
function list(type, name) {
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isFunction(type), function () { return 'Invalid argument type ' + assert.stringify(type) + ' supplied to list(type, [name]) combinator (expected a type)'; });
|
||||
assert(isTypeName(name), function () { return 'Invalid argument name ' + assert.stringify(name) + ' supplied to list(type, [name]) combinator (expected a string)'; });
|
||||
}
|
||||
|
||||
var displayName = name || getDefaultName(type);
|
||||
var typeNameCache = getTypeName(type);
|
||||
var identity = isIdentity(type); // the list is identity iif type is identity
|
||||
|
||||
function List(value, path) {
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
if (identity) {
|
||||
return value; // just trust the input if elements must not be hydrated
|
||||
}
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
path = path || [displayName];
|
||||
assert(isArray(value), function () { return 'Invalid value ' + assert.stringify(value) + ' supplied to ' + path.join('/') + ' (expected an array of ' + typeNameCache + ')'; });
|
||||
}
|
||||
|
||||
var idempotent = true; // will remain true if I can reutilise the input
|
||||
var ret = []; // make a temporary copy, will be discarded if idempotent remains true
|
||||
for (var i = 0, len = value.length; i < len; i++ ) {
|
||||
var actual = value[i];
|
||||
var instance = create(type, actual, ( process.env.NODE_ENV !== 'production' ? path.concat(i + ': ' + typeNameCache) : null ));
|
||||
idempotent = idempotent && ( actual === instance );
|
||||
ret.push(instance);
|
||||
}
|
||||
|
||||
if (idempotent) { // implements idempotency
|
||||
ret = value;
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
Object.freeze(ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
List.meta = {
|
||||
kind: 'list',
|
||||
type: type,
|
||||
name: name,
|
||||
identity: identity
|
||||
};
|
||||
|
||||
List.displayName = displayName;
|
||||
|
||||
List.is = function (x) {
|
||||
return isArray(x) && x.every(function (e) {
|
||||
return is(e, type);
|
||||
});
|
||||
};
|
||||
|
||||
List.update = function (instance, patch) {
|
||||
return List(assert.update(instance, patch));
|
||||
};
|
||||
|
||||
return List;
|
||||
}
|
||||
|
||||
list.getDefaultName = getDefaultName;
|
||||
module.exports = list;
|
||||
34
backend/frontend/node_modules/tcomb/lib/match.js
generated
vendored
Normal file
34
backend/frontend/node_modules/tcomb/lib/match.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
var assert = require('./assert');
|
||||
var isFunction = require('./isFunction');
|
||||
var isType = require('./isType');
|
||||
var Any = require('./Any');
|
||||
|
||||
module.exports = function match(x) {
|
||||
var type, guard, f, count;
|
||||
for (var i = 1, len = arguments.length; i < len; ) {
|
||||
type = arguments[i];
|
||||
guard = arguments[i + 1];
|
||||
f = arguments[i + 2];
|
||||
|
||||
if (isFunction(f) && !isType(f)) {
|
||||
i = i + 3;
|
||||
}
|
||||
else {
|
||||
f = guard;
|
||||
guard = Any.is;
|
||||
i = i + 2;
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
count = (count || 0) + 1;
|
||||
assert(isType(type), function () { return 'Invalid type in clause #' + count; });
|
||||
assert(isFunction(guard), function () { return 'Invalid guard in clause #' + count; });
|
||||
assert(isFunction(f), function () { return 'Invalid block in clause #' + count; });
|
||||
}
|
||||
|
||||
if (type.is(x) && guard(x)) {
|
||||
return f(x);
|
||||
}
|
||||
}
|
||||
assert.fail('Match error');
|
||||
};
|
||||
57
backend/frontend/node_modules/tcomb/lib/maybe.js
generated
vendored
Normal file
57
backend/frontend/node_modules/tcomb/lib/maybe.js
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
var assert = require('./assert');
|
||||
var isTypeName = require('./isTypeName');
|
||||
var isFunction = require('./isFunction');
|
||||
var isMaybe = require('./isMaybe');
|
||||
var isIdentity = require('./isIdentity');
|
||||
var Any = require('./Any');
|
||||
var create = require('./create');
|
||||
var Nil = require('./Nil');
|
||||
var forbidNewOperator = require('./forbidNewOperator');
|
||||
var is = require('./is');
|
||||
var getTypeName = require('./getTypeName');
|
||||
|
||||
function getDefaultName(type) {
|
||||
return '?' + getTypeName(type);
|
||||
}
|
||||
|
||||
function maybe(type, name) {
|
||||
|
||||
if (isMaybe(type) || type === Any || type === Nil) { // makes the combinator idempotent and handle Any, Nil
|
||||
return type;
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isFunction(type), function () { return 'Invalid argument type ' + assert.stringify(type) + ' supplied to maybe(type, [name]) combinator (expected a type)'; });
|
||||
assert(isTypeName(name), function () { return 'Invalid argument name ' + assert.stringify(name) + ' supplied to maybe(type, [name]) combinator (expected a string)'; });
|
||||
}
|
||||
|
||||
var displayName = name || getDefaultName(type);
|
||||
var identity = isIdentity(type);
|
||||
|
||||
function Maybe(value, path) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (identity) {
|
||||
forbidNewOperator(this, Maybe);
|
||||
}
|
||||
}
|
||||
return Nil.is(value) ? value : create(type, value, path);
|
||||
}
|
||||
|
||||
Maybe.meta = {
|
||||
kind: 'maybe',
|
||||
type: type,
|
||||
name: name,
|
||||
identity: identity
|
||||
};
|
||||
|
||||
Maybe.displayName = displayName;
|
||||
|
||||
Maybe.is = function (x) {
|
||||
return Nil.is(x) || is(x, type);
|
||||
};
|
||||
|
||||
return Maybe;
|
||||
}
|
||||
|
||||
maybe.getDefaultName = getDefaultName;
|
||||
module.exports = maybe;
|
||||
18
backend/frontend/node_modules/tcomb/lib/mixin.js
generated
vendored
Normal file
18
backend/frontend/node_modules/tcomb/lib/mixin.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
var isNil = require('./isNil');
|
||||
var assert = require('./assert');
|
||||
|
||||
// safe mixin, cannot override props unless specified
|
||||
module.exports = function mixin(target, source, overwrite) {
|
||||
if (isNil(source)) { return target; }
|
||||
for (var k in source) {
|
||||
if (source.hasOwnProperty(k)) {
|
||||
if (overwrite !== true) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(!target.hasOwnProperty(k) || target[k] === source[k], function () { return 'Invalid call to mixin(target, source, [overwrite]): cannot overwrite property "' + k + '" of target object'; });
|
||||
}
|
||||
}
|
||||
target[k] = source[k];
|
||||
}
|
||||
}
|
||||
return target;
|
||||
};
|
||||
66
backend/frontend/node_modules/tcomb/lib/refinement.js
generated
vendored
Normal file
66
backend/frontend/node_modules/tcomb/lib/refinement.js
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
var assert = require('./assert');
|
||||
var isTypeName = require('./isTypeName');
|
||||
var isFunction = require('./isFunction');
|
||||
var forbidNewOperator = require('./forbidNewOperator');
|
||||
var isIdentity = require('./isIdentity');
|
||||
var create = require('./create');
|
||||
var is = require('./is');
|
||||
var getTypeName = require('./getTypeName');
|
||||
var getFunctionName = require('./getFunctionName');
|
||||
|
||||
function getDefaultName(type, predicate) {
|
||||
return '{' + getTypeName(type) + ' | ' + getFunctionName(predicate) + '}';
|
||||
}
|
||||
|
||||
function refinement(type, predicate, name) {
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isFunction(type), function () { return 'Invalid argument type ' + assert.stringify(type) + ' supplied to refinement(type, predicate, [name]) combinator (expected a type)'; });
|
||||
assert(isFunction(predicate), function () { return 'Invalid argument predicate supplied to refinement(type, predicate, [name]) combinator (expected a function)'; });
|
||||
assert(isTypeName(name), function () { return 'Invalid argument name ' + assert.stringify(name) + ' supplied to refinement(type, predicate, [name]) combinator (expected a string)'; });
|
||||
}
|
||||
|
||||
var displayName = name || getDefaultName(type, predicate);
|
||||
var identity = isIdentity(type);
|
||||
|
||||
function Refinement(value, path) {
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (identity) {
|
||||
forbidNewOperator(this, Refinement);
|
||||
}
|
||||
path = path || [displayName];
|
||||
}
|
||||
|
||||
var x = create(type, value, path);
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(predicate(x), function () { return 'Invalid value ' + assert.stringify(value) + ' supplied to ' + path.join('/'); });
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
Refinement.meta = {
|
||||
kind: 'subtype',
|
||||
type: type,
|
||||
predicate: predicate,
|
||||
name: name,
|
||||
identity: identity
|
||||
};
|
||||
|
||||
Refinement.displayName = displayName;
|
||||
|
||||
Refinement.is = function (x) {
|
||||
return is(x, type) && predicate(x);
|
||||
};
|
||||
|
||||
Refinement.update = function (instance, patch) {
|
||||
return Refinement(assert.update(instance, patch));
|
||||
};
|
||||
|
||||
return Refinement;
|
||||
}
|
||||
|
||||
refinement.getDefaultName = getDefaultName;
|
||||
module.exports = refinement;
|
||||
17
backend/frontend/node_modules/tcomb/lib/stringify.js
generated
vendored
Normal file
17
backend/frontend/node_modules/tcomb/lib/stringify.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
var getFunctionName = require('./getFunctionName');
|
||||
|
||||
function replacer(key, value) {
|
||||
if (typeof value === 'function') {
|
||||
return getFunctionName(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
module.exports = function stringify(x) {
|
||||
try { // handle "Converting circular structure to JSON" error
|
||||
return JSON.stringify(x, replacer, 2);
|
||||
}
|
||||
catch (e) {
|
||||
return String(x);
|
||||
}
|
||||
};
|
||||
122
backend/frontend/node_modules/tcomb/lib/struct.js
generated
vendored
Normal file
122
backend/frontend/node_modules/tcomb/lib/struct.js
generated
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
var assert = require('./assert');
|
||||
var isTypeName = require('./isTypeName');
|
||||
var String = require('./String');
|
||||
var Function = require('./Function');
|
||||
var isBoolean = require('./isBoolean');
|
||||
var isObject = require('./isObject');
|
||||
var isNil = require('./isNil');
|
||||
var create = require('./create');
|
||||
var getTypeName = require('./getTypeName');
|
||||
var dict = require('./dict');
|
||||
var getDefaultInterfaceName = require('./getDefaultInterfaceName');
|
||||
var extend = require('./extend');
|
||||
|
||||
function getDefaultName(props) {
|
||||
return 'Struct' + getDefaultInterfaceName(props);
|
||||
}
|
||||
|
||||
function extendStruct(mixins, name) {
|
||||
return extend(struct, mixins, name);
|
||||
}
|
||||
|
||||
function getOptions(options) {
|
||||
if (!isObject(options)) {
|
||||
options = isNil(options) ? {} : { name: options };
|
||||
}
|
||||
if (!options.hasOwnProperty('strict')) {
|
||||
options.strict = struct.strict;
|
||||
}
|
||||
if (!options.hasOwnProperty('defaultProps')) {
|
||||
options.defaultProps = {};
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
function struct(props, options) {
|
||||
|
||||
options = getOptions(options);
|
||||
var name = options.name;
|
||||
var strict = options.strict;
|
||||
var defaultProps = options.defaultProps;
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(dict(String, Function).is(props), function () { return 'Invalid argument props ' + assert.stringify(props) + ' supplied to struct(props, [options]) combinator (expected a dictionary String -> Type)'; });
|
||||
assert(isTypeName(name), function () { return 'Invalid argument name ' + assert.stringify(name) + ' supplied to struct(props, [options]) combinator (expected a string)'; });
|
||||
assert(isBoolean(strict), function () { return 'Invalid argument strict ' + assert.stringify(strict) + ' supplied to struct(props, [options]) combinator (expected a boolean)'; });
|
||||
assert(isObject(defaultProps), function () { return 'Invalid argument defaultProps ' + assert.stringify(defaultProps) + ' supplied to struct(props, [options]) combinator (expected an object)'; });
|
||||
}
|
||||
|
||||
var displayName = name || getDefaultName(props);
|
||||
|
||||
function Struct(value, path) {
|
||||
|
||||
if (Struct.is(value)) { // implements idempotency
|
||||
return value;
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
path = path || [displayName];
|
||||
assert(isObject(value), function () { return 'Invalid value ' + assert.stringify(value) + ' supplied to ' + path.join('/') + ' (expected an object)'; });
|
||||
// strictness
|
||||
if (strict) {
|
||||
for (k in value) {
|
||||
if (value.hasOwnProperty(k)) {
|
||||
assert(props.hasOwnProperty(k), function () { return 'Invalid additional prop "' + k + '" supplied to ' + path.join('/'); });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!(this instanceof Struct)) { // `new` is optional
|
||||
return new Struct(value, path);
|
||||
}
|
||||
|
||||
for (var k in props) {
|
||||
if (props.hasOwnProperty(k)) {
|
||||
var expected = props[k];
|
||||
var actual = value[k];
|
||||
// apply defaults
|
||||
if (actual === undefined) {
|
||||
actual = defaultProps[k];
|
||||
}
|
||||
this[k] = create(expected, actual, ( process.env.NODE_ENV !== 'production' ? path.concat(k + ': ' + getTypeName(expected)) : null ));
|
||||
}
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Struct.meta = {
|
||||
kind: 'struct',
|
||||
props: props,
|
||||
name: name,
|
||||
identity: false,
|
||||
strict: strict,
|
||||
defaultProps: defaultProps
|
||||
};
|
||||
|
||||
Struct.displayName = displayName;
|
||||
|
||||
Struct.is = function (x) {
|
||||
return x instanceof Struct;
|
||||
};
|
||||
|
||||
Struct.update = function (instance, patch) {
|
||||
return new Struct(assert.update(instance, patch));
|
||||
};
|
||||
|
||||
Struct.extend = function (xs, name) {
|
||||
return extendStruct([Struct].concat(xs), name);
|
||||
};
|
||||
|
||||
return Struct;
|
||||
}
|
||||
|
||||
struct.strict = false;
|
||||
struct.getOptions = getOptions;
|
||||
struct.getDefaultName = getDefaultName;
|
||||
struct.extend = extendStruct;
|
||||
module.exports = struct;
|
||||
83
backend/frontend/node_modules/tcomb/lib/tuple.js
generated
vendored
Normal file
83
backend/frontend/node_modules/tcomb/lib/tuple.js
generated
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
var assert = require('./assert');
|
||||
var isTypeName = require('./isTypeName');
|
||||
var isFunction = require('./isFunction');
|
||||
var getTypeName = require('./getTypeName');
|
||||
var isIdentity = require('./isIdentity');
|
||||
var isArray = require('./isArray');
|
||||
var create = require('./create');
|
||||
var is = require('./is');
|
||||
|
||||
function getDefaultName(types) {
|
||||
return '[' + types.map(getTypeName).join(', ') + ']';
|
||||
}
|
||||
|
||||
function tuple(types, name) {
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isArray(types) && types.every(isFunction), function () { return 'Invalid argument types ' + assert.stringify(types) + ' supplied to tuple(types, [name]) combinator (expected an array of types)'; });
|
||||
assert(isTypeName(name), function () { return 'Invalid argument name ' + assert.stringify(name) + ' supplied to tuple(types, [name]) combinator (expected a string)'; });
|
||||
}
|
||||
|
||||
var displayName = name || getDefaultName(types);
|
||||
var identity = types.every(isIdentity);
|
||||
|
||||
function Tuple(value, path) {
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
if (identity) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
path = path || [displayName];
|
||||
assert(isArray(value) && value.length === types.length, function () { return 'Invalid value ' + assert.stringify(value) + ' supplied to ' + path.join('/') + ' (expected an array of length ' + types.length + ')'; });
|
||||
}
|
||||
|
||||
var idempotent = true;
|
||||
var ret = [];
|
||||
for (var i = 0, len = types.length; i < len; i++) {
|
||||
var expected = types[i];
|
||||
var actual = value[i];
|
||||
var instance = create(expected, actual, ( process.env.NODE_ENV !== 'production' ? path.concat(i + ': ' + getTypeName(expected)) : null ));
|
||||
idempotent = idempotent && ( actual === instance );
|
||||
ret.push(instance);
|
||||
}
|
||||
|
||||
if (idempotent) { // implements idempotency
|
||||
ret = value;
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
Object.freeze(ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Tuple.meta = {
|
||||
kind: 'tuple',
|
||||
types: types,
|
||||
name: name,
|
||||
identity: identity
|
||||
};
|
||||
|
||||
Tuple.displayName = displayName;
|
||||
|
||||
Tuple.is = function (x) {
|
||||
return isArray(x) &&
|
||||
x.length === types.length &&
|
||||
types.every(function (type, i) {
|
||||
return is(x[i], type);
|
||||
});
|
||||
};
|
||||
|
||||
Tuple.update = function (instance, patch) {
|
||||
return Tuple(assert.update(instance, patch));
|
||||
};
|
||||
|
||||
return Tuple;
|
||||
}
|
||||
|
||||
tuple.getDefaultName = getDefaultName;
|
||||
module.exports = tuple;
|
||||
91
backend/frontend/node_modules/tcomb/lib/union.js
generated
vendored
Normal file
91
backend/frontend/node_modules/tcomb/lib/union.js
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
var assert = require('./assert');
|
||||
var isTypeName = require('./isTypeName');
|
||||
var isFunction = require('./isFunction');
|
||||
var getTypeName = require('./getTypeName');
|
||||
var isIdentity = require('./isIdentity');
|
||||
var isArray = require('./isArray');
|
||||
var create = require('./create');
|
||||
var is = require('./is');
|
||||
var forbidNewOperator = require('./forbidNewOperator');
|
||||
var isUnion = require('./isUnion');
|
||||
var isNil = require('./isNil');
|
||||
|
||||
function getDefaultName(types) {
|
||||
return types.map(getTypeName).join(' | ');
|
||||
}
|
||||
|
||||
function union(types, name) {
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isArray(types) && types.every(isFunction) && types.length >= 2, function () { return 'Invalid argument types ' + assert.stringify(types) + ' supplied to union(types, [name]) combinator (expected an array of at least 2 types)'; });
|
||||
assert(isTypeName(name), function () { return 'Invalid argument name ' + assert.stringify(name) + ' supplied to union(types, [name]) combinator (expected a string)'; });
|
||||
}
|
||||
|
||||
var displayName = name || getDefaultName(types);
|
||||
var identity = types.every(isIdentity);
|
||||
|
||||
function Union(value, path) {
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
if (identity) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
var type = Union.dispatch(value);
|
||||
if (!type && Union.is(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (identity) {
|
||||
forbidNewOperator(this, Union);
|
||||
}
|
||||
path = path || [displayName];
|
||||
assert(isFunction(type), function () { return 'Invalid value ' + assert.stringify(value) + ' supplied to ' + path.join('/') + ' (no constructor returned by dispatch)'; });
|
||||
path[path.length - 1] += '(' + getTypeName(type) + ')';
|
||||
}
|
||||
|
||||
return create(type, value, path);
|
||||
}
|
||||
|
||||
Union.meta = {
|
||||
kind: 'union',
|
||||
types: types,
|
||||
name: name,
|
||||
identity: identity
|
||||
};
|
||||
|
||||
Union.displayName = displayName;
|
||||
|
||||
Union.is = function (x) {
|
||||
return types.some(function (type) {
|
||||
return is(x, type);
|
||||
});
|
||||
};
|
||||
|
||||
Union.dispatch = function (x) { // default dispatch implementation
|
||||
for (var i = 0, len = types.length; i < len; i++ ) {
|
||||
var type = types[i];
|
||||
if (isUnion(type)) { // handle union of unions
|
||||
var t = type.dispatch(x);
|
||||
if (!isNil(t)) {
|
||||
return t;
|
||||
}
|
||||
}
|
||||
else if (is(x, type)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Union.update = function (instance, patch) {
|
||||
return Union(assert.update(instance, patch));
|
||||
};
|
||||
|
||||
return Union;
|
||||
}
|
||||
|
||||
union.getDefaultName = getDefaultName;
|
||||
module.exports = union;
|
||||
|
||||
165
backend/frontend/node_modules/tcomb/lib/update.js
generated
vendored
Normal file
165
backend/frontend/node_modules/tcomb/lib/update.js
generated
vendored
Normal file
@@ -0,0 +1,165 @@
|
||||
var assert = require('./assert');
|
||||
var isObject = require('./isObject');
|
||||
var isFunction = require('./isFunction');
|
||||
var isArray = require('./isArray');
|
||||
var isNumber = require('./isNumber');
|
||||
var assign = require('./assign');
|
||||
|
||||
function getShallowCopy(x) {
|
||||
if (isObject(x)) {
|
||||
if (x instanceof Date || x instanceof RegExp) {
|
||||
return x;
|
||||
}
|
||||
return assign({}, x);
|
||||
}
|
||||
if (isArray(x)) {
|
||||
return x.concat();
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
function isCommand(k) {
|
||||
return update.commands.hasOwnProperty(k);
|
||||
}
|
||||
|
||||
function getCommand(k) {
|
||||
return update.commands[k];
|
||||
}
|
||||
|
||||
function update(instance, patch) {
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isObject(patch), function () { return 'Invalid argument patch ' + assert.stringify(patch) + ' supplied to function update(instance, patch): expected an object containing commands'; });
|
||||
}
|
||||
|
||||
var value = instance;
|
||||
var isChanged = false;
|
||||
var newValue;
|
||||
for (var k in patch) {
|
||||
if (patch.hasOwnProperty(k)) {
|
||||
if (isCommand(k)) {
|
||||
newValue = getCommand(k)(patch[k], value);
|
||||
if (newValue !== instance) {
|
||||
isChanged = true;
|
||||
value = newValue;
|
||||
} else {
|
||||
value = instance;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (value === instance) {
|
||||
value = getShallowCopy(instance);
|
||||
}
|
||||
newValue = update(value[k], patch[k]);
|
||||
isChanged = isChanged || ( newValue !== value[k] );
|
||||
value[k] = newValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return isChanged ? value : instance;
|
||||
}
|
||||
|
||||
// built-in commands
|
||||
|
||||
function $apply(f, value) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isFunction(f), 'Invalid argument f supplied to immutability helper { $apply: f } (expected a function)');
|
||||
}
|
||||
return f(value);
|
||||
}
|
||||
|
||||
function $push(elements, arr) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isArray(elements), 'Invalid argument elements supplied to immutability helper { $push: elements } (expected an array)');
|
||||
assert(isArray(arr), 'Invalid value supplied to immutability helper $push (expected an array)');
|
||||
}
|
||||
if (elements.length > 0) {
|
||||
return arr.concat(elements);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
function $remove(keys, obj) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isArray(keys), 'Invalid argument keys supplied to immutability helper { $remove: keys } (expected an array)');
|
||||
assert(isObject(obj), 'Invalid value supplied to immutability helper $remove (expected an object)');
|
||||
}
|
||||
if (keys.length > 0) {
|
||||
obj = getShallowCopy(obj);
|
||||
for (var i = 0, len = keys.length; i < len; i++ ) {
|
||||
delete obj[keys[i]];
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
function $set(value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
function $splice(splices, arr) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isArray(splices) && splices.every(isArray), 'Invalid argument splices supplied to immutability helper { $splice: splices } (expected an array of arrays)');
|
||||
assert(isArray(arr), 'Invalid value supplied to immutability helper $splice (expected an array)');
|
||||
}
|
||||
if (splices.length > 0) {
|
||||
arr = getShallowCopy(arr);
|
||||
return splices.reduce(function (acc, splice) {
|
||||
acc.splice.apply(acc, splice);
|
||||
return acc;
|
||||
}, arr);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
function $swap(config, arr) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isObject(config), 'Invalid argument config supplied to immutability helper { $swap: config } (expected an object)');
|
||||
assert(isNumber(config.from), 'Invalid argument config.from supplied to immutability helper { $swap: config } (expected a number)');
|
||||
assert(isNumber(config.to), 'Invalid argument config.to supplied to immutability helper { $swap: config } (expected a number)');
|
||||
assert(isArray(arr), 'Invalid value supplied to immutability helper $swap (expected an array)');
|
||||
}
|
||||
if (config.from !== config.to) {
|
||||
arr = getShallowCopy(arr);
|
||||
var element = arr[config.to];
|
||||
arr[config.to] = arr[config.from];
|
||||
arr[config.from] = element;
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
function $unshift(elements, arr) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert(isArray(elements), 'Invalid argument elements supplied to immutability helper {$unshift: elements} (expected an array)');
|
||||
assert(isArray(arr), 'Invalid value supplied to immutability helper $unshift (expected an array)');
|
||||
}
|
||||
if (elements.length > 0) {
|
||||
return elements.concat(arr);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
function $merge(whatToMerge, value) {
|
||||
var isChanged = false;
|
||||
var result = getShallowCopy(value);
|
||||
for (var k in whatToMerge) {
|
||||
if (whatToMerge.hasOwnProperty(k)) {
|
||||
result[k] = whatToMerge[k];
|
||||
isChanged = isChanged || ( result[k] !== value[k] );
|
||||
}
|
||||
}
|
||||
return isChanged ? result : value;
|
||||
}
|
||||
|
||||
update.commands = {
|
||||
$apply: $apply,
|
||||
$push: $push,
|
||||
$remove: $remove,
|
||||
$set: $set,
|
||||
$splice: $splice,
|
||||
$swap: $swap,
|
||||
$unshift: $unshift,
|
||||
$merge: $merge
|
||||
};
|
||||
|
||||
module.exports = update;
|
||||
Reference in New Issue
Block a user