uniforms-bridge-simple-schema-2
Advanced tools
Comparing version 3.0.0-alpha.2 to 3.0.0-alpha.3
@@ -6,5 +6,2 @@ "use strict"; | ||
var uniforms_1 = require("uniforms"); | ||
var SimpleSchema2Bridge_1 = tslib_1.__importDefault(require("./SimpleSchema2Bridge")); | ||
// Register bridge. | ||
uniforms_1.createSchemaBridge.register(SimpleSchema2Bridge_1.default); | ||
// Register custom property. | ||
@@ -11,0 +8,0 @@ simpl_schema_1.default.extendOptions(['uniforms']); |
@@ -5,3 +5,2 @@ import { Bridge } from 'uniforms'; | ||
constructor(schema: any); | ||
static check(schema: any): boolean; | ||
getError(name: any, error: any): any; | ||
@@ -18,3 +17,3 @@ getErrorMessage(name: any, error: any): any; | ||
mutate: boolean; | ||
}): any; | ||
}): (model: any) => any; | ||
} |
@@ -7,2 +7,3 @@ "use strict"; | ||
var invariant_1 = tslib_1.__importDefault(require("invariant")); | ||
var memoize_1 = tslib_1.__importDefault(require("lodash/memoize")); | ||
var uniforms_1 = require("uniforms"); | ||
@@ -14,12 +15,8 @@ var SimpleSchema2Bridge = /** @class */ (function (_super) { | ||
_this.schema = schema; | ||
// Memoize for performance and referential equality. | ||
_this.getField = memoize_1.default(_this.getField); | ||
_this.getSubfields = memoize_1.default(_this.getSubfields); | ||
_this.getType = memoize_1.default(_this.getType); | ||
return _this; | ||
} | ||
SimpleSchema2Bridge.check = function (schema) { | ||
return (schema && | ||
schema.getDefinition && | ||
schema.messageBox && | ||
schema.objectKeys && | ||
schema.validator && | ||
schema.version === 2); | ||
}; | ||
SimpleSchema2Bridge.prototype.getError = function (name, error) { | ||
@@ -77,3 +74,3 @@ return ((error && | ||
} | ||
if (field.type === Object || SimpleSchema2Bridge.check(field.type)) { | ||
if (field.type === Object || field.type instanceof simpl_schema_1.default) { | ||
return {}; | ||
@@ -139,3 +136,3 @@ } | ||
} | ||
if (SimpleSchema2Bridge.check(type)) { | ||
if (type instanceof simpl_schema_1.default) { | ||
return Object; | ||
@@ -148,7 +145,12 @@ } | ||
var validator = this.schema.validator(options); | ||
// Clean mutate its argument, even if mutate is false. | ||
if (options.clean) { | ||
return function (model) { return validator(cloneDeep_1.default(tslib_1.__assign({}, model))); }; | ||
} | ||
return validator; | ||
return function (model) { | ||
try { | ||
// Clean mutate its argument, even if mutate is false. | ||
validator(options.clean ? cloneDeep_1.default(tslib_1.__assign({}, model)) : model); | ||
return null; | ||
} | ||
catch (error) { | ||
return error; | ||
} | ||
}; | ||
}; | ||
@@ -155,0 +157,0 @@ return SimpleSchema2Bridge; |
import SimpleSchema from 'simpl-schema'; | ||
import { createSchemaBridge, filterDOMProps } from 'uniforms'; | ||
import SimpleSchema2Bridge from './SimpleSchema2Bridge'; | ||
// Register bridge. | ||
createSchemaBridge.register(SimpleSchema2Bridge); | ||
import { filterDOMProps } from 'uniforms'; | ||
// Register custom property. | ||
@@ -7,0 +4,0 @@ SimpleSchema.extendOptions(['uniforms']); |
@@ -5,3 +5,2 @@ import { Bridge } from 'uniforms'; | ||
constructor(schema: any); | ||
static check(schema: any): boolean; | ||
getError(name: any, error: any): any; | ||
@@ -18,3 +17,3 @@ getErrorMessage(name: any, error: any): any; | ||
mutate: boolean; | ||
}): any; | ||
}): (model: any) => any; | ||
} |
@@ -5,2 +5,3 @@ import { __rest } from "tslib"; | ||
import invariant from 'invariant'; | ||
import memoize from 'lodash/memoize'; | ||
import { Bridge, joinName } from 'uniforms'; | ||
@@ -11,11 +12,7 @@ export default class SimpleSchema2Bridge extends Bridge { | ||
this.schema = schema; | ||
// Memoize for performance and referential equality. | ||
this.getField = memoize(this.getField); | ||
this.getSubfields = memoize(this.getSubfields); | ||
this.getType = memoize(this.getType); | ||
} | ||
static check(schema) { | ||
return (schema && | ||
schema.getDefinition && | ||
schema.messageBox && | ||
schema.objectKeys && | ||
schema.validator && | ||
schema.version === 2); | ||
} | ||
getError(name, error) { | ||
@@ -71,3 +68,3 @@ return ((error && | ||
} | ||
if (field.type === Object || SimpleSchema2Bridge.check(field.type)) { | ||
if (field.type === Object || field.type instanceof SimpleSchema) { | ||
return {}; | ||
@@ -130,3 +127,3 @@ } | ||
} | ||
if (SimpleSchema2Bridge.check(type)) { | ||
if (type instanceof SimpleSchema) { | ||
return Object; | ||
@@ -138,8 +135,13 @@ } | ||
const validator = this.schema.validator(options); | ||
// Clean mutate its argument, even if mutate is false. | ||
if (options.clean) { | ||
return model => validator(cloneDeep(Object.assign({}, model))); | ||
} | ||
return validator; | ||
return model => { | ||
try { | ||
// Clean mutate its argument, even if mutate is false. | ||
validator(options.clean ? cloneDeep(Object.assign({}, model)) : model); | ||
return null; | ||
} | ||
catch (error) { | ||
return error; | ||
} | ||
}; | ||
} | ||
} |
{ | ||
"name": "uniforms-bridge-simple-schema-2", | ||
"version": "3.0.0-alpha.2", | ||
"version": "3.0.0-alpha.3", | ||
"license": "MIT", | ||
@@ -31,5 +31,5 @@ "main": "es5/index.js", | ||
"tslib": "^1.10.0", | ||
"uniforms": "^3.0.0-alpha.2" | ||
"uniforms": "^3.0.0-alpha.3" | ||
}, | ||
"gitHead": "a828a69acbfb54f1676e2340c4cea08aa0c41d19" | ||
"gitHead": "032f300a30be7dbf54d8e53231fd85db03dd0cf8" | ||
} |
import SimpleSchema from 'simpl-schema'; | ||
import { createSchemaBridge, filterDOMProps } from 'uniforms'; | ||
import { filterDOMProps } from 'uniforms'; | ||
import SimpleSchema2Bridge from './SimpleSchema2Bridge'; | ||
// Register bridge. | ||
createSchemaBridge.register(SimpleSchema2Bridge); | ||
// Register custom property. | ||
@@ -10,0 +5,0 @@ SimpleSchema.extendOptions(['uniforms']); |
import SimpleSchema from 'simpl-schema'; | ||
import cloneDeep from 'lodash/cloneDeep'; | ||
import invariant from 'invariant'; | ||
import memoize from 'lodash/memoize'; | ||
import { Bridge, joinName } from 'uniforms'; | ||
@@ -13,13 +14,7 @@ | ||
this.schema = schema; | ||
} | ||
static check(schema) { | ||
return ( | ||
schema && | ||
schema.getDefinition && | ||
schema.messageBox && | ||
schema.objectKeys && | ||
schema.validator && | ||
schema.version === 2 | ||
); | ||
// Memoize for performance and referential equality. | ||
this.getField = memoize(this.getField); | ||
this.getSubfields = memoize(this.getSubfields); | ||
this.getType = memoize(this.getType); | ||
} | ||
@@ -96,3 +91,3 @@ | ||
if (field.type === Object || SimpleSchema2Bridge.check(field.type)) { | ||
if (field.type === Object || field.type instanceof SimpleSchema) { | ||
return {}; | ||
@@ -173,3 +168,3 @@ } | ||
if (SimpleSchema2Bridge.check(type)) { | ||
if (type instanceof SimpleSchema) { | ||
return Object; | ||
@@ -183,10 +178,12 @@ } | ||
const validator = this.schema.validator(options); | ||
// Clean mutate its argument, even if mutate is false. | ||
if (options.clean) { | ||
return model => validator(cloneDeep({ ...model })); | ||
} | ||
return validator; | ||
return model => { | ||
try { | ||
// Clean mutate its argument, even if mutate is false. | ||
validator(options.clean ? cloneDeep({ ...model }) : model); | ||
return null; | ||
} catch (error) { | ||
return error; | ||
} | ||
}; | ||
} | ||
} |
22024
536
Updateduniforms@^3.0.0-alpha.3