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.11.1 to 1.12.0

6

dist/SimpleSchema.js

@@ -83,6 +83,6 @@ "use strict";

// Exported for tests
var schemaDefinitionOptions = ['type', 'label', 'optional', 'required', 'autoValue', 'defaultValue'];
var schemaDefinitionOptions = ['autoValue', 'defaultValue', 'label', 'optional', 'required', 'type'];
exports.schemaDefinitionOptions = schemaDefinitionOptions;
var oneOfProps = ['type', 'min', 'max', 'minCount', 'maxCount', 'allowedValues', 'exclusiveMin', 'exclusiveMax', 'regEx', 'custom', 'blackbox', 'trim'];
var propsThatCanBeFunction = ['label', 'optional', 'min', 'max', 'minCount', 'maxCount', 'allowedValues', 'exclusiveMin', 'exclusiveMax', 'regEx'];
var oneOfProps = ['allowedValues', 'blackbox', 'custom', 'exclusiveMax', 'exclusiveMin', 'max', 'maxCount', 'min', 'minCount', 'regEx', 'skipRegExCheckForEmptyStrings', 'trim', 'type'];
var propsThatCanBeFunction = ['allowedValues', 'exclusiveMax', 'exclusiveMin', 'label', 'max', 'maxCount', 'min', 'minCount', 'optional', 'regEx', 'skipRegExCheckForEmptyStrings'];

@@ -89,0 +89,0 @@ var SimpleSchema = /*#__PURE__*/function () {

@@ -36,3 +36,3 @@ "use strict";

if (def.regEx instanceof RegExp && !def.regEx.test(keyValue)) {
if ((def.skipRegExCheckForEmptyStrings !== true || keyValue !== '') && def.regEx instanceof RegExp && !def.regEx.test(keyValue)) {
return {

@@ -39,0 +39,0 @@ type: _SimpleSchema.SimpleSchema.ErrorTypes.FAILED_REGULAR_EXPRESSION,

{
"name": "simpl-schema",
"version": "1.11.1",
"version": "1.12.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>",

# SimpleSchema (simpl-schema NPM package)
[![Lint, Test, and (Maybe) Publish](https://github.com/aldeed/simpl-schema/workflows/Lint,%20Test,%20and%20(Maybe)%20Publish/badge.svg?event=push)](https://github.com/aldeed/simpl-schema/actions?query=workflow%3A%22Lint%2C+Test%2C+and+%28Maybe%29+Publish%22)
[![Lint, Test, and (Maybe) Publish](<https://github.com/aldeed/simpl-schema/workflows/Lint,%20Test,%20and%20(Maybe)%20Publish/badge.svg?event=push>)](https://github.com/aldeed/simpl-schema/actions?query=workflow%3A%22Lint%2C+Test%2C+and+%28Maybe%29+Publish%22)

@@ -21,4 +21,5 @@ SimpleSchema validates JavaScript objects to ensure they match a schema. It can also clean the objects to automatically convert types, remove unsupported properties, and add automatic values such that the object is then more likely to pass validation.

<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
**Table of Contents** _generated with [DocToc](https://github.com/thlorenz/doctoc)_
- [The History of SimpleSchema](#the-history-of-simpleschema)

@@ -131,3 +132,3 @@ - [Installation](#installation)

```js
import SimpleSchema from 'simpl-schema';
import SimpleSchema from "simpl-schema";

@@ -146,10 +147,7 @@ new SimpleSchema({

```js
import SimpleSchema from 'simpl-schema';
import SimpleSchema from "simpl-schema";
new SimpleSchema({
name: String,
}).validate([
{ name: 'Bill' },
{ name: 2 },
]);
}).validate([{ name: "Bill" }, { name: 2 }]);
```

@@ -162,9 +160,9 @@

```js
import SimpleSchema from 'simpl-schema';
import { check } from 'meteor/check';
import { Meteor } from 'meteor/meteor';
import SimpleSchema from "simpl-schema";
import { check } from "meteor/check";
import { Meteor } from "meteor/meteor";
SimpleSchema.defineValidationErrorTransform(error => {
SimpleSchema.defineValidationErrorTransform((error) => {
const ddpError = new Meteor.Error(error.message);
ddpError.error = 'validation-error';
ddpError.error = "validation-error";
ddpError.details = error.details;

@@ -188,3 +186,3 @@ return ddpError;

```js
import SimpleSchema from 'simpl-schema';
import SimpleSchema from "simpl-schema";

@@ -206,3 +204,3 @@ const validationContext = new SimpleSchema({

```js
import SimpleSchema from 'simpl-schema';
import SimpleSchema from "simpl-schema";

@@ -213,7 +211,10 @@ const validationContext = new SimpleSchema({

validationContext.validate({
$set: {
name: 2,
validationContext.validate(
{
$set: {
name: 2,
},
},
}, { modifier: true });
{ modifier: true }
);

@@ -227,8 +228,11 @@ console.log(validationContext.isValid());

```js
import SimpleSchema from 'simpl-schema';
import { Tracker } from 'meteor/tracker';
import SimpleSchema from "simpl-schema";
import { Tracker } from "meteor/tracker";
const validationContext = new SimpleSchema({
name: String,
}, { tracker: Tracker }).newContext();
const validationContext = new SimpleSchema(
{
name: String,
},
{ tracker: Tracker }
).newContext();

@@ -245,3 +249,3 @@ Tracker.autorun(function () {

validationContext.validate({
name: 'Joe',
name: "Joe",
});

@@ -265,19 +269,22 @@ ```

```js
import SimpleSchema from 'simpl-schema';
import SimpleSchema from "simpl-schema";
const mySchema = new SimpleSchema({
name: String,
}, {
clean: {
autoConvert: true,
extendAutoValueContext: {},
filter: false,
getAutoValues: true,
removeEmptyStrings: true,
removeNullsFromArrays: false,
trimStrings: true,
const mySchema = new SimpleSchema(
{
name: String,
},
humanizeAutoLabels: false,
requiredByDefault: true,
});
{
clean: {
autoConvert: true,
extendAutoValueContext: {},
filter: false,
getAutoValues: true,
removeEmptyStrings: true,
removeNullsFromArrays: false,
trimStrings: true,
},
humanizeAutoLabels: false,
requiredByDefault: true,
}
);
```

@@ -290,3 +297,3 @@

```js
import SimpleSchema from 'simpl-schema';
import SimpleSchema from "simpl-schema";

@@ -314,3 +321,3 @@ SimpleSchema.constructorOptionDefaults({

```js
import SimpleSchema from 'simpl-schema';
import SimpleSchema from "simpl-schema";

@@ -327,3 +334,3 @@ const mySchema = new SimpleSchema({ name: String });

```js
import SimpleSchema from 'simpl-schema';
import SimpleSchema from "simpl-schema";

@@ -344,3 +351,3 @@ const mySchema = new SimpleSchema({ name: String });

```js
import SimpleSchema from 'simpl-schema';
import SimpleSchema from "simpl-schema";

@@ -361,3 +368,3 @@ const schema = new SimpleSchema({

```js
import SimpleSchema from 'simpl-schema';
import SimpleSchema from "simpl-schema";

@@ -385,3 +392,3 @@ const schema = new SimpleSchema({

```js
import SimpleSchema from 'simpl-schema';
import SimpleSchema from "simpl-schema";

@@ -406,3 +413,3 @@ const schema = new SimpleSchema({

{
exp: /foo/
exp: /foo/;
}

@@ -443,3 +450,3 @@ ```

```js
import SimpleSchema from 'simpl-schema';
import SimpleSchema from "simpl-schema";

@@ -455,13 +462,16 @@ const schema = new SimpleSchema({

```js
import SimpleSchema from 'simpl-schema';
import SimpleSchema from "simpl-schema";
const schema = new SimpleSchema({
id: SimpleSchema.oneOf({
type: String,
min: 16,
max: 16,
}, {
type: SimpleSchema.Integer,
min: 0,
}),
id: SimpleSchema.oneOf(
{
type: String,
min: 16,
max: 16,
},
{
type: SimpleSchema.Integer,
min: 0,
}
),
name: String,

@@ -476,10 +486,10 @@ });

```js
import SimpleSchema from 'simpl-schema';
import SimpleSchema from "simpl-schema";
const objSchema = new SimpleSchema({
_id: String
_id: String,
});
const schema = new SimpleSchema({
foo: SimpleSchema.oneOf(String, objSchema)
foo: SimpleSchema.oneOf(String, objSchema),
});

@@ -491,10 +501,10 @@ ```

```js
import SimpleSchema from 'simpl-schema';
import SimpleSchema from "simpl-schema";
const schema = new SimpleSchema({
foo: SimpleSchema.oneOf(String, Object),
'foo._id': {
"foo._id": {
type: String,
optional: true
}
optional: true,
},
});

@@ -510,4 +520,4 @@ ```

```js
import SimpleSchema from 'simpl-schema';
import { idSchema, addressSchema } from './sharedSchemas';
import SimpleSchema from "simpl-schema";
import { idSchema, addressSchema } from "./sharedSchemas";

@@ -526,4 +536,4 @@ const schema = new SimpleSchema({

```js
import SimpleSchema from 'simpl-schema';
import { idSchema, addressSchema } from './sharedSchemas';
import SimpleSchema from "simpl-schema";
import { idSchema, addressSchema } from "./sharedSchemas";

@@ -563,4 +573,4 @@ const schema = new SimpleSchema({

```js
import SimpleSchema from 'simpl-schema';
import { addressSchema } from './sharedSchemas';
import SimpleSchema from "simpl-schema";
import { addressSchema } from "./sharedSchemas";

@@ -584,3 +594,3 @@ const schema = new SimpleSchema({

```js
import SimpleSchema from 'simpl-schema';
import SimpleSchema from "simpl-schema";

@@ -593,3 +603,3 @@ const schema = new SimpleSchema({

const nameSchema = schema.pick('firstName', 'lastName');
const nameSchema = schema.pick("firstName", "lastName");
```

@@ -600,3 +610,3 @@

```js
import SimpleSchema from 'simpl-schema';
import SimpleSchema from "simpl-schema";

@@ -609,3 +619,3 @@ const schema = new SimpleSchema({

const nameSchema = schema.omit('username');
const nameSchema = schema.omit("username");
```

@@ -616,3 +626,3 @@

```js
import SimpleSchema from 'simpl-schema';
import SimpleSchema from "simpl-schema";

@@ -623,10 +633,10 @@ const schema = new SimpleSchema({

address: Object,
'address.street1': String,
'address.street2': { type: String, optional: true },
'address.city': String,
'address.state': String,
'address.postalCode': String,
"address.street1": String,
"address.street2": { type: String, optional: true },
"address.city": String,
"address.state": String,
"address.postalCode": String,
});
const addressSchema = schema.getObjectSchema('address');
const addressSchema = schema.getObjectSchema("address");

@@ -646,8 +656,12 @@ // addressSchema is now the same as this:

Sometimes if you want to get the `rawDefinition` of some schema just pass in the options `{ keepRawDefinition: true}`(if not arg is passed the value will be null). Example:
```javascript
const userSchema = new SimpleSchema({
name: String,
number: 'SimpleSchema.Integer',
email: String
}, { keepRawDefintion: true });
const userSchema = new SimpleSchema(
{
name: String,
number: "SimpleSchema.Integer",
email: String,
},
{ keepRawDefintion: true }
);
userSchema.rawDefinition;

@@ -659,3 +673,3 @@ //{

//}
```
```

@@ -669,8 +683,8 @@ ## Schema Keys

```js
import SimpleSchema from 'simpl-schema';
import SimpleSchema from "simpl-schema";
const schema = new SimpleSchema({
mailingAddress: Object,
'mailingAddress.street': String,
'mailingAddress.city': String,
"mailingAddress.street": String,
"mailingAddress.city": String,
});

@@ -682,3 +696,3 @@ ```

```js
import SimpleSchema from 'simpl-schema';
import SimpleSchema from "simpl-schema";

@@ -689,7 +703,7 @@ const schema = new SimpleSchema({

minCount: 1,
maxCount: 4
maxCount: 4,
},
'addresses.$': Object,
'addresses.$.street': String,
'addresses.$.city': String,
"addresses.$": Object,
"addresses.$.street": String,
"addresses.$.city": String,
});

@@ -718,3 +732,3 @@ ```

*Can also be a function that returns the label*
_Can also be a function that returns the label_

@@ -727,3 +741,3 @@ A string that will be used to refer to this field in validation error messages. The default is an inflected (humanized) derivation of the key name itself. For example, the key "firstName" will have a default label of "First name" if you do not include the `label` property in your definition.

schema.labels({
password: "Enter your password"
password: "Enter your password",
});

@@ -738,3 +752,3 @@ ```

*Can also be a function that returns true or false*
_Can also be a function that returns true or false_

@@ -745,5 +759,5 @@ By default, all keys are required. Set `optional: true` to change that.

- If `type` is `Array`, then "required" means that key must have a value, but an empty array is fine. (If an empty array is *not* fine, add the `minCount: 1` option.)
- If `type` is `Array`, then "required" means that key must have a value, but an empty array is fine. (If an empty array is _not_ fine, add the `minCount: 1` option.)
- For array items (when the key name ends with ".$"), if `optional` is true, then `null` values are valid. If array items are required, then any `null` items will fail the type check.
- If a key is required at a deeper level, the key must have a value *only if* the object it belongs to is present.
- If a key is required at a deeper level, the key must have a value _only if_ the object it belongs to is present.
- When the object being validated is a Mongo modifier object, changes that would unset or `null` a required key result in validation errors.

@@ -753,8 +767,8 @@

- Say you have a required key "friends.address.city" but "friends.address" is optional. If "friends.address" is set in the object you're validating, but "friends.address.city" is not, there is a validation error. However, if "friends.address" is *not* set, then there is no validation error for "friends.address.city" because the object it belongs to is not present.
- If you have a required key "friends.$.name", but the `friends` array has no objects in the object you are validating, there is no validation error for "friends.$.name". When the `friends` array *does* have objects, every present object is validated, and each object could potentially have a validation error if it is missing the `name` property. For example, when there are two objects in the friends array and both are missing the `name` property, there will be a validation error for both "friends.0.name" and "friends.1.name".
- Say you have a required key "friends.address.city" but "friends.address" is optional. If "friends.address" is set in the object you're validating, but "friends.address.city" is not, there is a validation error. However, if "friends.address" is _not_ set, then there is no validation error for "friends.address.city" because the object it belongs to is not present.
- If you have a required key "friends.$.name", but the `friends` array has no objects in the object you are validating, there is no validation error for "friends.$.name". When the `friends` array _does_ have objects, every present object is validated, and each object could potentially have a validation error if it is missing the `name` property. For example, when there are two objects in the friends array and both are missing the `name` property, there will be a validation error for both "friends.0.name" and "friends.1.name".
### required
*Can also be a function that returns true or false*
_Can also be a function that returns true or false_

@@ -764,6 +778,9 @@ If you would rather have all your schema keys be optional by default, pass the `requiredByDefault: false` option and then use `required: true` to make individual keys required.

```js
const schema = new SimpleSchema({
optionalProp: String,
requiredProp: { type: String, required: true },
}, { requiredByDefault: false });
const schema = new SimpleSchema(
{
optionalProp: String,
requiredProp: { type: String, required: true },
},
{ requiredByDefault: false }
);
```

@@ -773,3 +790,3 @@

*Can also be a function that returns the min/max value*
_Can also be a function that returns the min/max value_

@@ -784,3 +801,3 @@ - If `type` is `Number` or `SimpleSchema.Integer`, these rules define the minimum or maximum numeric value.

*Can also be a function that returns true or false*
_Can also be a function that returns true or false_

@@ -791,3 +808,3 @@ Set to `true` to indicate that the range of numeric values, as set by min/max, are to be treated as an exclusive range. Set to `false` (default) to treat ranges as inclusive.

*Can also be a function that returns the minCount/maxCount value*
_Can also be a function that returns the minCount/maxCount value_

@@ -798,3 +815,3 @@ Define the minimum or maximum array length. Used only when type is `Array`.

*Can also be a function that returns the array or the `Set` of allowed values*
_Can also be a function that returns the array or the `Set` of allowed values_

@@ -806,11 +823,12 @@ An array or a `Set` of values that are allowed. A key will be invalid if its value is not one of these.

**Note**: If you wish to restrict the items allowed in an `Array`, the `allowedValues` property must be on the array item definition.
```javascript
const schema = new SimpleSchema({
myArray: {
type: Array
type: Array,
},
'myArray.$': {
"myArray.$": {
type: String,
allowedValues: ['foo', 'bar']
}
allowedValues: ["foo", "bar"],
},
});

@@ -821,3 +839,3 @@ ```

*Can also be a function that returns a regular expression or an array of them*
_Can also be a function that returns a regular expression or an array of them_

@@ -838,7 +856,13 @@ Any regular expression that must be matched for the key to be valid, or an array of regular expressions that will be tested in order.

- `SimpleSchema.RegEx.idOfLength(min, max)` for IDs generated by `Random.id(length)` where min/max define lower and upper bounds.
Call without params for allowing an arbitrary length. Call with `min` only for fixed length.
Call with `max = null` for fixed lower and arbitrary upper bounds.
Call without params for allowing an arbitrary length. Call with `min` only for fixed length.
Call with `max = null` for fixed lower and arbitrary upper bounds.
- `SimpleSchema.RegEx.ZipCode` for 5- and 9-digit ZIP codes
- `SimpleSchema.RegEx.Phone` for phone numbers (taken from Google's libphonenumber library)
### skipRegExCheckForEmptyStrings
_Can also be a function that returns true or false_
Set to `true` when `regEx` is set if you want an empty string to always pass validation, even though the regular expression may disallow it.
### blackbox

@@ -852,3 +876,3 @@

*Used by the cleaning process but not by validation*
_Used by the cleaning process but not by validation_

@@ -863,3 +887,3 @@ When you call `simpleSchemaInstance.clean()` with `trimStrings` set to `true`, all string values are trimmed of leading and trailing whitespace. If you set `trim` to `false` for certain keys in their schema definition, those keys will be skipped.

*Used by the cleaning process but not by validation*
_Used by the cleaning process but not by validation_

@@ -879,3 +903,3 @@ Set this to any value that you want to be used as the default when an object does not include this field or has this field set to `undefined`. This value will be injected into the object by a call to `mySimpleSchema.clean()` with `getAutovalues: true`.

*Used by the cleaning process but not by validation*
_Used by the cleaning process but not by validation_

@@ -938,6 +962,6 @@ The `autoValue` option allows you to specify a function that is called by `simpleSchemaInstance.clean()` to potentially change the value of a property in the object being cleaned. This is a powerful feature that allows you to set up either forced values or default values, potentially based on the values of other fields in the object.

maxCount: 3,
}
},
});
schema.get('friends', 'maxCount'); // 3
schema.get("friends", "maxCount"); // 3
```

@@ -972,3 +996,3 @@

```js
import SimpleSchema from 'simpl-schema';
import SimpleSchema from "simpl-schema";

@@ -979,3 +1003,3 @@ const schema = new SimpleSchema({

const userFormValidationContext = schema.namedContext('userForm');
const userFormValidationContext = schema.namedContext("userForm");
```

@@ -990,3 +1014,3 @@

```js
import SimpleSchema from 'simpl-schema';
import SimpleSchema from "simpl-schema";

@@ -1038,5 +1062,5 @@ const schema = new SimpleSchema({

```js
import SimpleSchema from 'simpl-schema';
import SimpleSchema from "simpl-schema";
SimpleSchema.defineValidationErrorTransform(error => {
SimpleSchema.defineValidationErrorTransform((error) => {
const customError = new MyCustomErrorType(error.message);

@@ -1051,7 +1075,7 @@ customError.errorList = error.details;

```js
import SimpleSchema from 'simpl-schema';
import SimpleSchema from "simpl-schema";
SimpleSchema.defineValidationErrorTransform(error => {
SimpleSchema.defineValidationErrorTransform((error) => {
const ddpError = new Meteor.Error(error.message);
ddpError.error = 'validation-error';
ddpError.error = "validation-error";
ddpError.details = error.details;

@@ -1084,3 +1108,3 @@ return ddpError;

```js
import SimpleSchema from 'simpl-schema';
import SimpleSchema from "simpl-schema";

@@ -1091,3 +1115,3 @@ const schema = new SimpleSchema({

custom: myFunction,
}
},
});

@@ -1122,9 +1146,7 @@ ```

```js
import SimpleSchema from 'simpl-schema';
import SimpleSchema from "simpl-schema";
SimpleSchema.addDocValidator(obj => {
SimpleSchema.addDocValidator((obj) => {
// Must return an array, potentially empty, of objects with `name` and `type` string properties and optional `value` property.
return [
{ name: 'firstName', type: 'TOO_SILLY', value: 'Reepicheep' }
];
return [{ name: "firstName", type: "TOO_SILLY", value: "Reepicheep" }];
});

@@ -1178,3 +1200,3 @@ ```

en: {
wrongPassword: 'Wrong password',
wrongPassword: "Wrong password",
},

@@ -1184,3 +1206,5 @@ },

myValidationContext.addValidationErrors([{ name: 'password', type: 'wrongPassword' }]);
myValidationContext.addValidationErrors([
{ name: "password", type: "wrongPassword" },
]);
```

@@ -1243,3 +1267,3 @@

en: {
"too_long": "Too long!",
too_long: "Too long!",
},

@@ -1257,3 +1281,3 @@ },

en: {
"too_long": "Too long!",
too_long: "Too long!",
},

@@ -1305,9 +1329,12 @@ });

```js
const schema = new SimpleSchema({
name: String
}, {
clean: {
trimStrings: false,
const schema = new SimpleSchema(
{
name: String,
},
});
{
clean: {
trimStrings: false,
},
}
);
```

@@ -1319,3 +1346,3 @@

For consistency, if you care only about the date (year, month, date) portion and not the time, then use a `Date` object set to the desired date at midnight UTC *(note, the clean function won't strip out time)*. This goes for `min` and `max` dates, too. If you care only about the date
For consistency, if you care only about the date (year, month, date) portion and not the time, then use a `Date` object set to the desired date at midnight UTC _(note, the clean function won't strip out time)_. This goes for `min` and `max` dates, too. If you care only about the date
portion and you want to specify a minimum date, `min` should be set to midnight UTC on the minimum date (inclusive).

@@ -1368,3 +1395,3 @@

en: {
passwordMismatch: 'Passwords do not match',
passwordMismatch: "Passwords do not match",
},

@@ -1384,3 +1411,3 @@ });

custom() {
if (this.value !== this.field('password').value) {
if (this.value !== this.field("password").value) {
return "passwordMismatch";

@@ -1443,3 +1470,3 @@ }

```js
SimpleSchema.extendOptions(['index', 'unique', 'denyInsert', 'denyUpdate']);
SimpleSchema.extendOptions(["index", "unique", "denyInsert", "denyUpdate"]);
```

@@ -1446,0 +1473,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