How to use @hyral/core - 9 common examples

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 / vue / src / Mixin / Collection.js View on Github external
initCollection() {
      const collection = this.$store.getters[`hyral_${this.resourceType}/collection`](this.collectionName);
      if (collection) {
        return;
      }

      this.$store.commit(`hyral_${this.resourceType}/SET_COLLECTION`, Collection.create(this.collectionName));
    },
    loadCollection() {
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;
}
github SyneticNL / Hyral / packages / json-api / src / Request / Serializers / serializeCreateUpdateTask.js View on Github external
export default function serializeCreateUpdateTask(task) {
  if (!isTask(task)) {
    return task;
  }

  if (task.type !== 'create' && task.type !== 'update') {
    return task;
  }

  const type = { type: task.payload.type };
  const id = task.payload.id !== null ? { id: task.payload.id.toString() } : {};
  const attributes = { attributes: serializeAttributes(task.payload) };
  const relationships = task.related && task.related.length > 0
    ? { relationships: serializeResourceRelationships(task) }
    : {};

  return {
    data: Object.assign(
github SyneticNL / Hyral / packages / json-api / src / Request / Serializers / serializeRelationTask.js View on Github external
export default function serializeRelationTask(task) {
  if (!isTask(task)) {
    return task;
  }

  if (task.type !== 'relation') {
    return task;
  }

  if (!task.payload.resources || task.payload.resources.length === 0) {
    return {
      data: null,
    };
  }

  return {
    data: task.context.relationships[task.payload.relation].many
      ? task.payload.resources.map(serializeRelationship)
github SyneticNL / Hyral / packages / vue / src / Module / createStoreModule.js View on Github external
    resource: state => id => (state.resources[id] ? Resource.fromState(
      id,
      repository.resourceType,
      state.resources[id],
    ) : null),
    collection: state => name => (state.collections[name] ? createVuexCollectionFromState(
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 / vue / src / Collection / createVuexCollectionFromState.js View on Github external
export default function createVuexCollectionFromState(name, state, repository, store) {
  const collection = Collection.fromState(name, state, repository);

  addLoadProxy(collection, state, repository, store);
  addParameterBagProxy(collection, state, repository, store);

  return collection;
}