How to use the @keystonejs/utils.resolveAllKeys function in @keystonejs/utils

To help you get started, we’ve selected a few @keystonejs/utils 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 keystonejs / keystone / packages / keystone / lib / Keystone / index.js View on Github external
disconnect() {
    return resolveAllKeys(
      mapKeys(this.adapters, adapter => adapter.disconnect())
      // Chain an empty function so that the result of this promise
      // isn't unintentionally leaked to the caller
    ).then(() => {});
  }
github keystonejs / keystone / packages / core / Keystone / relationship-utils.js View on Github external
const createRelationships = (lists, relationships, createdItems) => {
  return resolveAllKeys(
    mapObject(relationships, (relationList, listKey) => {
      const listFieldsConfig = lists[listKey].config.fields;

      return resolveAllKeys(
        // NOTE: Sparse array / indexes match the indexes from the `createdItems`
        mapObject(relationList, (relationItem, relationItemIndex) => {
          const createdItem = createdItems[listKey][relationItemIndex];

          // Results in something like:
          // Promise<{ author: , ... }>
          return resolveAllKeys(
            mapObject(relationItem, (relationConditions, relationshipField) => {
              const relatedListKey = listFieldsConfig[relationshipField].ref;

              return relateTo({
                relatedFrom: {
github keystonejs / keystone / packages / keystone / lib / Keystone / index.js View on Github external
async createItems(itemsToCreate) {
    // 1. Split it apart
    const { relationships, data } = unmergeRelationships(this.lists, itemsToCreate);
    // 2. Create the items
    // NOTE: Only works if all relationships fields are non-"required"
    const createdItems = await resolveAllKeys(
      mapKeys(data, (items, listKey) =>
        Promise.all(items.map(itemData => this.createItem(listKey, itemData)))
      )
    );

    let createdRelationships;
    try {
      // 3. Create the relationships
      createdRelationships = await createRelationships(this.lists, relationships, createdItems);
    } catch (error) {
      // 3.5. If creation of relationships didn't work, unwind the createItems
      Promise.all(
        Object.entries(createdItems).map(([listKey, items]) =>
          Promise.all(items.map(({ id }) => this.lists[listKey].adapter.delete(id)))
        )
      );
github keystonejs / keystone / packages / adapter-knex / lib / adapter-knex.js View on Github external
async _processNonRealFields(data, processFunction) {
    return resolveAllKeys(
      arrayToObject(
        Object.entries(omit(data, this.realKeys)).map(([path, value]) => ({
          path,
          value,
          adapter: this.fieldAdaptersByPath[path],
        })),
        'path',
        processFunction
      )
    );
  }
github keystonejs / keystone / packages / keystone / lib / List / index.js View on Github external
_mapToFields(fields, action) {
    return resolveAllKeys(arrayToObject(fields, 'path', action)).catch(error => {
      if (!error.errors) {
        throw error;
      }
      const errorCopy = new Error(error.message || error.toString());
      errorCopy.errors = Object.values(error.errors);
      throw errorCopy;
    });
  }
github keystonejs / keystone / packages / keystone / lib / Keystone / index.js View on Github external
connect() {
    const { adapters, name } = this;
    return resolveAllKeys(mapKeys(adapters, adapter => adapter.connect({ name }))).then(() => {
      if (this.eventHandlers.onConnect) {
        return this.eventHandlers.onConnect(this);
      }
    });
  }