How to use the @hyral/core/lib/Resource/Resource.create function in @hyral/core

To help you get started, we’ve selected a few @hyral/core 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 SyneticNL / Hyral / packages / json-api / src / Response / Resource / normalizeResource.js View on Github external
export default function normalizeResource(data) {
  if (!data.relationships) {
    return Resource.create(data.id, data.type, data.attributes, null, data.meta);
  }

  const resource = Resource.create(
    data.id,
    data.type,
    Object.assign(data.attributes, getResourcesFromData(data)),
    null,
    data.meta || null,
  );

  if (isEmpty(resource.relationships)) {
    resource.relationships = getRelationDefinitionFromData(data);
  }

  return resource;
}
github SyneticNL / Hyral / packages / json-api / src / Response / Resource / Relationship / relationshipGetResource.js View on Github external
export default function relationshipGetResource(item, includedRelations) {
  const resource = includedRelations[`${item.type}-${item.id}`] || Resource.create(
    item.id,
    item.type,
  );

  if (!item.meta) {
    return resource;
  }

  return Resource.fromState(resource.id, resource.type, Object.assign(
    {},
    resource.state,
    {
      meta: Object.assign({}, resource.state.meta, item.meta),
    },
  ));
}
github SyneticNL / Hyral / packages / json-api / src / Response / Resource / normalizeResource.js View on Github external
export default function normalizeResource(data) {
  if (!data.relationships) {
    return Resource.create(data.id, data.type, data.attributes, null, data.meta);
  }

  const resource = Resource.create(
    data.id,
    data.type,
    Object.assign(data.attributes, getResourcesFromData(data)),
    null,
    data.meta || null,
  );

  if (isEmpty(resource.relationships)) {
    resource.relationships = getRelationDefinitionFromData(data);
  }

  return resource;
}