How to use metaschema - 10 common examples

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 / start-server.js View on Github external
cb => {
      metaschema.fs
        .load(
          [
            getPathFromCurrentDir('.', 'schemas'),
            // TODO add other schemas here
          ],
          {
            ...options,
            context: {
              api: {
                argon2,
                common,
                console,
                jstp,
                provider,
              },
            },
github metarhia / globalstorage / test / ms.validate.js View on Github external
metatests.test('Fully supports schemas/system', async test => {
  let schema;

  try {
    schema = await metaschema.fs.load(
      'test/fixtures/validate',
      options,
      config
    );
  } catch (error) {
    console.error(error);
    test.fail(error);
    test.end();
    return;
  }

  test.strictSame(
    schema.validate('category', 'Person', {
      Id: '12',
      FullName: {
        FirstName: 'Name',
github metarhia / globalstorage / test / pg.schema.js View on Github external
metatests.test('Unsupported domain class', async test => {
  const expectedErrorMessage =
    "Unsupported domain class '__UNSUPPORTED_CLASS__' in domain 'Test'";

  let schema;

  try {
    schema = await metaschema.fs.load(
      'test/fixtures/unsupported-domain-class',
      options,
      config
    );
  } catch (error) {
    console.error(error);
    test.fail(error);
    test.end();
    return;
  }

  test.throws(() => generateDDL(schema), new Error(expectedErrorMessage));
  test.end();
});
github metarhia / globalstorage / test / ms.resources.js View on Github external
metatests.test('Fully supports schemas/system', async test => {
  let schema;

  try {
    schema = await metaschema.fs.load(
      'test/fixtures/resources',
      options,
      config
    );
  } catch (error) {
    console.error(error);
    test.fail(error);
    test.end();
    return;
  }

  test.strictSame(schema.resources.common.get('en'), '{"Id":"Identifier"}');
  test.strictSame(schema.resources.domains.get('en'), '{"Id":"Identifier"}');
  test.strictSame(
    schema.actions.get('PublicAction').resources.get('en'),
    '{"Login":"Login"}'
github metarhia / globalstorage / test / ms.validate.js View on Github external
'use strict';

const metaschema = require('metaschema');
const metatests = require('metatests');
const { Uint64 } = require('@metarhia/common');

const { options, config } = require('../lib/metaschema-config/config');

const { ValidationError, MetaschemaError } = metaschema.errors;

metatests.test('Fully supports schemas/system', async test => {
  let schema;

  try {
    schema = await metaschema.fs.load(
      'test/fixtures/validate',
      options,
      config
    );
  } catch (error) {
    console.error(error);
    test.fail(error);
    test.end();
    return;
  }
github metarhia / globalstorage / test / memory.js View on Github external
metatests.test('cursor schema', async test => {
  const languages = [
    { Id: 1, Name: 'English', Locale: 'en' },
    { Id: 2, Name: 'Ukrainian', Locale: 'uk' },
    { Id: 3, Name: 'Russian', Locale: 'ru' },
  ];

  let schema;

  try {
    schema = await metaschema.fs.load('schemas/system', options, config);
  } catch (err) {
    test.fail(err);
    test.end();
    return;
  }

  const schemaName = 'Language';
  const category = schema.categories.get(schemaName).definition;
  const mcLanguages = new MemoryCursor(languages).definition(
    category,
    schemaName
  );

  const data = await mcLanguages
    .select({ Locale: '> en' })
    .order('Name')
github metarhia / globalstorage / test / ms.resources.js View on Github external
async test => {
    let schema;

    try {
      schema = await metaschema.fs.load(
        'test/fixtures/resources',
        options,
        config
      );
    } catch (error) {
      console.error(error);
      test.fail(error);
      test.end();
      return;
    }

    const provider = new StorageProvider({});
    await provider.open({ schema });

    test.endAfterSubtests();
github metarhia / globalstorage / test / unit / pg.ddl / generateLinks.js View on Github external
metatests.test('pg.ddl.generateLinks unit test', async test => {
  let schema;

  try {
    schema = await metaschema.fs.load(schemasDir, options, config);
  } catch (err) {
    test.fail(err);
    test.end();
    return;
  }

  test.strictSame(
    ddl.generateLinks(
      [
        {
          from: 'LocalCategory2',
          to: 'LocalCategory1',
          name: 'field',
          link: schema.categories.get('LocalCategory2').definition.field,
          destination: 'LocalCategory1',
        },
github metarhia / globalstorage / test / unit / pg.ddl / generateTable.js View on Github external
metatests.test('pg.ddl.generateTable unit test', async test => {
  let schema;

  try {
    schema = await metaschema.fs.load(schemasDir, options, config);
  } catch (err) {
    test.fail(err);
    test.end();
    return;
  }

  test.strictSame(
    ddl.generateTable(
      'LocalCategory2',
      schema.categories.get('LocalCategory2').definition,
      'Local',
      new Map([['Nomen', 'text']]),
      new Map(),
      [],
      schema.categories
    ),

metaschema

Metadata Schema and Interface Definition Language (IDL)

MIT
Latest version published 4 months ago

Package Health Score

71 / 100
Full package analysis