How to use the metaschema.extractDecorator function in metaschema

To help you get started, we’ve selected a few metaschema 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 metarhia / globalstorage / lib / pg.cursor.js View on Github external
--i;
        break;
      }
      if (op.op === 'select') {
        Object.assign(fullQuery, op.query);
      }
    }

    // add inner joins for Include fields
    const schema = this.provider.schema.categories.get(this.category)
      .definition;

    let hasInclude = false;
    for (const key in schema) {
      const field = schema[key];
      if (extractDecorator(field) === 'Include') {
        const cat = field.category;
        pgquery.innerJoin(cat, `${this.category}.Id`, `${cat}.Id`);
        hasInclude = true;
      }
    }

    if (permissionChecker) {
      await permissionChecker(this.category, {
        record: fullQuery,
        isQuery: true,
      });
    }

    // TODO: use array mode here, to avoid possible name collisions when
    //       querying from multiple tables at once
    try {
github metarhia / globalstorage / lib / metaschema-config / config.js View on Github external
Object.entries(schema.definition).forEach(([key, value]) => {
      const decorator = extractDecorator(value);
      if (decorator === 'Action') {
        delete schema.definition[key];
        arr.push({
          type: 'action',
          name: `${schema.name}.${key}`,
          module: schema.module,
          definition: value,
        });
      }
    });
  }
github metarhia / globalstorage / lib / schema.utils.js View on Github external
const extractIncludeCategories = category => {
  const result = [];
  for (const key in category) {
    const field = category[key];
    if (extractDecorator(field) === 'Include') {
      result.push(field.category);
    }
  }
  return result;
};
github metarhia / globalstorage / lib / pg.ddl.js View on Github external
.sort(({ link: l1 }, { link: l2 }) => {
      const d1 = extractDecorator(l1);
      const d2 = extractDecorator(l2);
      if (d1 !== 'Many' && d2 === 'Many') return -1;
      if (d1 === 'Many' && d2 !== 'Many') return 1;
      return 0;
    })
    .map(({ from, to, name, link, destination }) => {
github metarhia / globalstorage / lib / pg.ddl.js View on Github external
const preprocessSchema = (categories, domains) => {
  const processed = new Map();
  for (const [name, category] of categories) {
    processed.set(name, category);
    const type = extractDecorator(category.definition);
    if (type === 'History') {
      const historyName = `${name}History`;
      processed.set(historyName, {
        name: historyName,
        definition: createHistorySchema(
          category.definition,
          domains,
          categories
        ),
      });
    }
  }
  return processed;
};
github metarhia / globalstorage / lib / pg.ddl.js View on Github external
.each(name => {
      validateIdentifier(name, 'entry', `${categoryName}.`);

      const property = category[name];
      const type = extractDecorator(property);
      if (type === 'Include') {
        return;
      }
      const entry = { name, property };
      if (property.index) {
        indexes.push(entry);
      } else if (property.unique) {
        unique.push(entry);
      }
      if (property.domain) {
        properties.push(entry);
      } else if (property.category) {
        entry.foreignKey = requiresForeignKey(categories, categoryName);

        entry.destination = isGlobalCategory(property.definition)
          ? 'Identifier'
github metarhia / globalstorage / lib / metaschema-config / validate.js View on Github external
const props = new Set([...schemaProps, ...objectProps]);
  for (const prop of props) {
    const isSchemaProp = schemaProps.has(prop);
    const isObjectProp = objectProps.has(prop);
    if (isObjectProp && !isSchemaProp) {
      if (prop !== 'Id') {
        errors.push(
          new ValidationError('unresolvedProperty', `${path}${prop}`)
        );
      }
      continue;
    }

    const property = schema[prop];

    if (extractDecorator(property) === 'Validate' && !patch) {
      if (!property.validate(instance)) {
        errors.push(new ValidationError('validation', `${path}${prop}`));
      }
      continue;
    }

    if (property.readOnly && patch) {
      errors.push(new ValidationError('immutable', `${path}${prop}`));
      continue;
    }

    if (!isObjectProp) {
      if (property.required && !patch && property.default === undefined) {
        errors.push(new ValidationError('missingProperty', `${path}${prop}`));
      }
      continue;
github metarhia / globalstorage / lib / metaschema-config / validate.js View on Github external
const validateLink = (ms, property, instance, options) => {
  const { path } = options;
  const type = extractDecorator(property);

  if (type === 'Include') {
    const type = typeof instance;
    if (type !== 'object') {
      return [
        new ValidationError('invalidType', path, {
          expected: 'object',
          actual: type,
        }),
      ];
    }
    options.path += '.';
    const error = ms.validate('category', property, instance, options);
    return error ? error.errors : [];
  } else if (type !== 'Many') {
    return checkLink(instance, path);
github metarhia / globalstorage / lib / metaschema-config / category.js View on Github external
Object.entries(category.definition).forEach(([key, value]) => {
    const decorator = extractDecorator(value);

    if (decorator === 'Hierarchy' && !value.category) {
      value.category = category.name;
    }

    for (const decor of HIERARCHICAL_RELATIONS) {
      if (decorator === decor) {
        const property = decorator.toLowerCase();
        if (category[property]) {
          errors.push(
            new SchemaValidationError('duplicate', `${category.name}.${key}`, {
              type: 'hierarchical relation',
              value: decor,
            })
          );
        } else {
github metarhia / globalstorage / lib / metaschema-config / category.js View on Github external
if (!field.category) {
      continue;
    }

    const destination = ms.categories.get(field.category);
    if (!destination) {
      continue;
    }

    const error = verifyLink(category, destination, fieldName);
    if (error) {
      errors.push(error);
      continue;
    }

    const decorator = extractDecorator(field);
    const type = getReferenceType(decorator);

    if (type === 'Include') {
      errors.push(...checkDetail(destination, category));
    } else if (type === 'Master') {
      errors.push(...checkDetail(category, destination));
    }

    destination.references[type].push({
      category: category.name,
      property: fieldName,
    });
  }
  return errors;
};

metaschema

Metadata Schema and Interface Definition Language (IDL)

MIT
Latest version published 4 months ago

Package Health Score

73 / 100
Full package analysis