How to use the simpl-schema.default.isSimpleSchema function in simpl-schema

To help you get started, we’ve selected a few simpl-schema examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Meteor-Community-Packages / meteor-collection2 / package / collection2 / collection2.js View on Github external
var schemaIndex = -1;

      // we need an array to hold multiple schemas
      obj._c2._simpleSchemas = obj._c2._simpleSchemas || [];

      // Loop through existing schemas with selectors
      obj._c2._simpleSchemas.forEach((schema, index) => {
        // if we find a schema with an identical selector, save it's index
        if(isEqual(schema.selector, selector)) {
          schemaIndex = index;
        }
      });
      if (schemaIndex === -1) {
        // We didn't find the schema in our array - push it into the array
        obj._c2._simpleSchemas.push({
          schema: SimpleSchema.isSimpleSchema(ss) ? ss : new SimpleSchema(ss),
          selector: selector,
        });
      } else {
        // We found a schema with an identical selector in our array,
        if (options.replace !== true) {
          // Merge with existing schema unless options.replace is `true`
          if (obj._c2._simpleSchemas[schemaIndex].schema.version >= 2) {
            obj._c2._simpleSchemas[schemaIndex].schema.extend(ss);
          } else {
            obj._c2._simpleSchemas[schemaIndex].schema = new SimpleSchema([obj._c2._simpleSchemas[schemaIndex].schema, ss]);
          }
        } else {
          // If options.replace is `true` replace existing schema with new schema
          obj._c2._simpleSchemas[schemaIndex].schema = ss;
        }
github Meteor-Community-Packages / meteor-collection2 / package / collection2 / collection2.js View on Github external
Mongo.Collection.prototype.attachSchema = function c2AttachSchema(ss, options) {
  options = options || {};

  // Allow passing just the schema object
  if (!SimpleSchema.isSimpleSchema(ss)) {
    ss = new SimpleSchema(ss);
  }

  this._c2 = this._c2 || {};

  // If we've already attached one schema, we combine both into a new schema unless options.replace is `true`
  if (this._c2._simpleSchema && options.replace !== true) {
    if (ss.version >= 2) {
      var newSS = new SimpleSchema(this._c2._simpleSchema);
      newSS.extend(ss);
      ss = newSS;
    } else {
      ss = new SimpleSchema([this._c2._simpleSchema, ss]);
    }
  }