Socket
Socket
Sign inDemoInstall

simpl-schema

Package Overview
Dependencies
Maintainers
2
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simpl-schema - npm Package Compare versions

Comparing version 1.9.1 to 1.10.0

78

dist/SimpleSchema.js

@@ -87,13 +87,4 @@ "use strict";

var schema = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
check = _ref.check,
cleanOptions = _ref.clean,
defaultLabel = _ref.defaultLabel,
_ref$humanizeAutoLabe = _ref.humanizeAutoLabels,
humanizeAutoLabels = _ref$humanizeAutoLabe === void 0 ? true : _ref$humanizeAutoLabe,
_ref$requiredByDefaul = _ref.requiredByDefault,
requiredByDefault = _ref$requiredByDefaul === void 0 ? true : _ref$requiredByDefaul,
tracker = _ref.tracker;
_classCallCheck(this, SimpleSchema);

@@ -106,25 +97,13 @@

// Stash the options object
this._constructorOptions = {
check: check,
defaultLabel: defaultLabel,
humanizeAutoLabels: humanizeAutoLabels,
requiredByDefault: requiredByDefault,
tracker: tracker
}; // Custom validators for this instance
this._constructorOptions = _objectSpread({}, SimpleSchema._constructorOptionDefaults, {}, options);
delete this._constructorOptions.clean; // stored separately below
// Schema-level defaults for cleaning
this._cleanOptions = _objectSpread({}, SimpleSchema._constructorOptionDefaults.clean, {}, options.clean || {}); // Custom validators for this instance
this._validators = [];
this._docValidators = []; // Named validation contexts
this._validationContexts = {}; // Schema-level defaults for cleaning
this._validationContexts = {}; // Clone, expanding shorthand, and store the schema object in this._schema
this._cleanOptions = _objectSpread({
filter: true,
autoConvert: true,
removeEmptyStrings: true,
trimStrings: true,
getAutoValues: true,
removeNullsFromArrays: false,
extendAutoValueContext: {}
}, cleanOptions); // Clone, expanding shorthand, and store the schema object in this._schema
this._schema = {};

@@ -419,6 +398,6 @@ this._depsLabels = {};

if (!SimpleSchema.isSimpleSchema(typeDef.type)) return;
result = result.concat(typeDef.type.autoValueFunctions().map(function (_ref2) {
var func = _ref2.func,
fieldName = _ref2.fieldName,
closestSubschemaFieldName = _ref2.closestSubschemaFieldName;
result = result.concat(typeDef.type.autoValueFunctions().map(function (_ref) {
var func = _ref.func,
fieldName = _ref.fieldName,
closestSubschemaFieldName = _ref.closestSubschemaFieldName;
return {

@@ -687,4 +666,4 @@ func: func,

definition.type.definitions.forEach(function (_ref3) {
var type = _ref3.type;
definition.type.definitions.forEach(function (_ref2) {
var type = _ref2.type;

@@ -1022,2 +1001,15 @@ if (SimpleSchema.isSimpleSchema(type)) {

SimpleSchema._docValidators.push(func);
} // Global constructor options
}, {
key: "constructorOptionDefaults",
/**
* @summary Get/set default values for SimpleSchema constructor options
*/
value: function constructorOptionDefaults(options) {
if (!options) return SimpleSchema._constructorOptionDefaults;
SimpleSchema._constructorOptionDefaults = _objectSpread({}, SimpleSchema._constructorOptionDefaults, {}, options, {
clean: _objectSpread({}, SimpleSchema._constructorOptionDefaults.clean, {}, options.clean || {})
});
}

@@ -1047,2 +1039,16 @@ }]);

_defineProperty(SimpleSchema, "_constructorOptionDefaults", {
clean: {
autoConvert: true,
extendAutoValueContext: {},
filter: true,
getAutoValues: true,
removeEmptyStrings: true,
removeNullsFromArrays: false,
trimStrings: true
},
humanizeAutoLabels: true,
requiredByDefault: true
});
_defineProperty(SimpleSchema, "ErrorTypes", {

@@ -1170,4 +1176,4 @@ REQUIRED: 'required',

var couldBeArray = false;
definition.type.definitions.forEach(function (_ref4) {
var type = _ref4.type;
definition.type.definitions.forEach(function (_ref3) {
var type = _ref3.type;
if (!type) throw new Error("Invalid definition for ".concat(fieldName, " field: \"type\" option is required"));

@@ -1174,0 +1180,0 @@

{
"name": "simpl-schema",
"version": "1.9.1",
"version": "1.10.0",
"description": "A schema validation package that supports direct validation of MongoDB update modifier objects.",

@@ -5,0 +5,0 @@ "author": "Eric Dobbertin <aldeed@gmail.com>",

@@ -34,3 +34,4 @@ # SimpleSchema (simpl-schema NPM package)

- [Automatically Clean the Object Before Validating It](#automatically-clean-the-object-before-validating-it)
- [Set Default Cleaning Options](#set-default-cleaning-options)
- [Set Default Options for One Schema](#set-default-options-for-one-schema)
- [Set Default Options for All Schemas](#set-default-options-for-all-schemas)
- [Explicitly Clean an Object](#explicitly-clean-an-object)

@@ -94,3 +95,2 @@ - [Defining a Schema](#defining-a-schema)

- [Contributors](#contributors)
- [Backers](#backers)
- [Sponsors](#sponsors)

@@ -254,3 +254,3 @@ - [License](#license)

### Set Default Cleaning Options
### Set Default Options for One Schema

@@ -264,12 +264,40 @@ ```js

clean: {
filter: true,
autoConvert: true,
extendAutoValueContext: {},
filter: false,
getAutoValues: true,
removeEmptyStrings: true,
removeNullsFromArrays: false,
trimStrings: true,
getAutoValues: true,
removeNullsFromArrays: true,
},
humanizeAutoLabels: false,
requiredByDefault: true,
});
```
These options will be used every time you clean or validate with this particular SimpleSchema instance.
### Set Default Options for All Schemas
```js
import SimpleSchema from 'simpl-schema';
SimpleSchema.constructorOptionDefaults({
clean: {
filter: false,
},
humanizeAutoLabels: false,
});
// If you don't pass in any options, it will return the current defaults.
console.log(SimpleSchema.constructorOptionDefaults());
```
These options will be used every time you clean or validate with any SimpleSchema instance, but can be overridden by options passed in to the constructor for a single instance.
Important notes:
- You must call `SimpleSchema.constructorOptionDefaults` before any of your schemas are created, so put it in an entry-point file and/or at the top of your code file.
- In a large, complex project where SimpleSchema instances might be created by various JavaScript packages, there may be multiple `SimpleSchema` objects. In other words, the `import SimpleSchema` line in one package might be pulling in the `SimpleSchema` object from one package while that line in another package pulls in a completely different `SimpleSchema` object. It will be difficult to know that this is happening unless you notice that your defaults are not being used by some of your schemas. To solve this, you can call `SimpleSchema.constructorOptionDefaults` multiple times or adjust your package dependencies to ensure that only one version of `simpl-schema` is pulled into your project.
### Explicitly Clean an Object

@@ -276,0 +304,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc