How to use the normalizr.schema.Values function in normalizr

To help you get started, we’ve selected a few normalizr 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 amazeeio / lagoon / services / api / src / normalize.js View on Github external
{
    idAttribute: (value, parent, sgName) => sgName,
    processStrategy: (value, parent, sgName) => {
      // We need to add a computed `id` attribute to the sshKey,
      // so we know the context of the key itself
      // e.g sitegroup = 'deploytest1' & sshKey = 'pat' => 'deploytest1/pat'
      // To maintain consistency with the yaml file content, we need to omit
      // the id attribute in the ssh key normalization process (see sshKey schema)
      const sshKeys = addSshKeyId('sitegroup', sgName, value.ssh_keys);

      return Object.assign({}, value, { ssh_keys: sshKeys });
    },
  }
);

const siteGroupObjSchema = new schema.Values(siteGroupObj);

// const clientSchema = { ssh_keys: sshKey };

// const normalizeClient = (data: Object): Object => ({});

const normalizeSiteGroupObj = (data: Object): Object =>
  normalize(data, siteGroupObjSchema);

// const denormalizeSiteGroup = (entities: Object, data: Object): Object =>
//   denormalize(data, siteGroupFileSchema, entities);

module.exports = {
  // denormalizeSiteGroup,
  normalizeSiteGroupObj,
};
github gpbl / denormalizr / test / immutable.js View on Github external
describe('parsing an array of entities and collections', () => {
    const articleSchema = new Schema.Entity('articles');
    const userSchema = new Schema.Entity('users');
    const collectionSchema = new Schema.Entity('collections');

    articleSchema.define({
      collections: new Schema.Values(collectionSchema),
    });

    collectionSchema.define({
      curator: userSchema,
    });

    const article1 = {
      id: 1,
      title: 'Some Article',
      collections: {
        1: {
          id: 1,
          name: 'Dan',
        },
        2: {
          id: 2,
github gpbl / denormalizr / test / index.js View on Github external
describe('parsing a map of entities and collections', () => {
    const articleSchema = new schema.Entity('articles');
    const userSchema = new schema.Entity('users');
    const collectionSchema = new schema.Entity('collections');

    articleSchema.define({
      collections: new schema.Values(collectionSchema),
    });

    collectionSchema.define({
      curator: userSchema,
    });

    const article1 = {
      id: 1,
      title: 'Some Article',
      collections: {
        1: {
          id: 1,
          name: 'Dan',
        },
        2: {
          id: 2,