How to use the yaml/map.default function in yaml

To help you get started, we’ve selected a few yaml 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 back4app / antframework / packages / ant / spec / lib / config / Config.spec.js View on Github external
test('should create attributes Map', () => {
    const config = new Config({});
    const map = config._createAttributeMap({
      foo: 'a',
      bar: 'b',
      abc: 1,
      err: undefined // should be ignored
    });
    expect(map).toBeInstanceOf(Map);
    expect(map.items.length).toBe(3);
    expect(map.items[0].key).toBeInstanceOf(Scalar);
    expect(map.items[0].key.value).toBe('foo');
    expect(map.items[0].value).toBeInstanceOf(Scalar);
    expect(map.items[0].value.value).toBe('a');

    expect(map.items[1].key).toBeInstanceOf(Scalar);
    expect(map.items[1].key.value).toBe('bar');
    expect(map.items[1].value).toBeInstanceOf(Scalar);
    expect(map.items[1].value.value).toBe('b');

    expect(map.items[2].key).toBeInstanceOf(Scalar);
    expect(map.items[2].key.value).toBe('abc');
    expect(map.items[2].value).toBeInstanceOf(Scalar);
    expect(map.items[2].value.value).toBe(1);
  });
github back4app / antframework / plugins / ant-graphql / lib / GraphQL.js View on Github external
addDirective(name, definition, handler, runtime, config) {
    config = GraphQL._getConfig(config);

    // Retrieves the plugin configuration node from the Config's YAML document tree.
    // If no configuration node is found, forces its creation and returns it.
    const graphQLNode = config.getPluginConfigurationNode(PLUGIN_DEFAULT_LOCATION, true);
    // Finds the "directives" entry from the configuration node
    let directives = graphQLNode.items.find(
      item => item.key.value === 'directives'
    );
    if (!directives) {
      // If no "directives" entry is found, we must create it in order
      // to add our new directive
      directives = new Map();
      graphQLNode.items.push(new Pair(new Scalar('directives'), directives));
    } else {
      // Since "directives" is a Pair node, we need to access its value
      // to reach the Map of directives
      directives = directives.value;
    }

    // Given the directives map, we need to find the entry whose key is the name
    // of the target directive; either to update it with the new configurations or
    // to know if a brand new entry needs to be created.
    const directive = directives.items.find(
      item => item.key.value === name
    );
    const resolverAttributes = new Map();
    resolverAttributes.items.push(new Pair(new Scalar('handler'), new Scalar(handler)));
    resolverAttributes.items.push(new Pair(new Scalar('runtime'), new Scalar(runtime || this.ant.runtimeController.defaultRuntime.name)));
github back4app / antframework / plugins / ant-graphql / lib / GraphQL.js View on Github external
// Since "directives" is a Pair node, we need to access its value
      // to reach the Map of directives
      directives = directives.value;
    }

    // Given the directives map, we need to find the entry whose key is the name
    // of the target directive; either to update it with the new configurations or
    // to know if a brand new entry needs to be created.
    const directive = directives.items.find(
      item => item.key.value === name
    );
    const resolverAttributes = new Map();
    resolverAttributes.items.push(new Pair(new Scalar('handler'), new Scalar(handler)));
    resolverAttributes.items.push(new Pair(new Scalar('runtime'), new Scalar(runtime || this.ant.runtimeController.defaultRuntime.name)));

    const directiveAttributes = new Map();
    directiveAttributes.items.push(new Pair(new Scalar('resolver'), resolverAttributes));
    directiveAttributes.items.push(new Pair(new Scalar('definition'), new Scalar(definition)));
    if (!directive) {
      directives.items.push(new Pair(new Scalar(name), directiveAttributes));
    } else {
      directive.value = directiveAttributes;
    }
    return config.save();
  }
github back4app / antframework / plugins / ant-graphql / lib / GraphQL.js View on Github external
// to add our new directive
      directives = new Map();
      graphQLNode.items.push(new Pair(new Scalar('directives'), directives));
    } else {
      // Since "directives" is a Pair node, we need to access its value
      // to reach the Map of directives
      directives = directives.value;
    }

    // Given the directives map, we need to find the entry whose key is the name
    // of the target directive; either to update it with the new configurations or
    // to know if a brand new entry needs to be created.
    const directive = directives.items.find(
      item => item.key.value === name
    );
    const resolverAttributes = new Map();
    resolverAttributes.items.push(new Pair(new Scalar('handler'), new Scalar(handler)));
    resolverAttributes.items.push(new Pair(new Scalar('runtime'), new Scalar(runtime || this.ant.runtimeController.defaultRuntime.name)));

    const directiveAttributes = new Map();
    directiveAttributes.items.push(new Pair(new Scalar('resolver'), resolverAttributes));
    directiveAttributes.items.push(new Pair(new Scalar('definition'), new Scalar(definition)));
    if (!directive) {
      directives.items.push(new Pair(new Scalar(name), directiveAttributes));
    } else {
      directive.value = directiveAttributes;
    }
    return config.save();
  }
github back4app / antframework / packages / ant / spec / lib / config / Config.spec.js View on Github external
test('should return a new plugin entry with configuration when no "plugins" entry was found', () => {
        const config = new Config(path.resolve(utilPath, './configs/withTemplatesConfig/ant.yml'));
        const pluginConfigNode = config.getPluginConfigurationNode('foo', true);
        expect(pluginConfigNode).toBeInstanceOf(Map);
        expect(pluginConfigNode.items).toHaveLength(0);
        expect(config.getPluginConfigurationNode('foo')).toBe(pluginConfigNode);
      });
    });
github back4app / antframework / packages / ant / lib / config / Config.js View on Github external
_createAttributeMap(attributes) {
    const map = new Map();
    for(const [key, value] of Object.entries(attributes)) {
      if (value) {
        let valueNode;
        if (value instanceof Array) {
          const seq = new Seq();
          seq.items = seq.items.concat(value);
          valueNode = seq;
        } else {
          valueNode = new Scalar(value);
        }
        map.items.push(new Pair(
          new Scalar(key),
          valueNode
        ));
      }
    }
github back4app / antframework / packages / ant / spec / lib / config / Config.spec.js View on Github external
new Seq()
    );
    const barNode = new Pair(
      new Scalar('bar'),
      new Map()
    );
    const loremNode = new Pair(
      new Scalar('lorem'),
      new Pair()
    );
    config._config.contents.items.push(fooNode);
    config._config.contents.items.push(barNode);
    config._config.contents.items.push(loremNode);
    expect(config._findRootCollectionNode('foo', Seq)).toBe(fooNode.value);
    expect(config._findRootCollectionNode('bar', Map)).toBe(barNode.value);
    expect(config._findRootCollectionNode('lorem', Map)).toBe(null);
  });