How to use the @keystonejs/utils.getType 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 / access-control / index.js View on Github external
mergeWhereClause(args, where) {
    if (getType(where) !== 'Object') {
      return args;
    }

    // Access control is a where clause type
    return {
      ...args,
      where: {
        ...args.where,
        ...where,
      },
    };
  },
github keystonejs / keystone / packages / adapter-mongoose / lib / adapter-mongoose.js View on Github external
return mapKeys(_query, field => {
        if (getType(field) !== 'Object' || !field.where) {
          return field;
        }

        // recurse on object (ie; relationship) types
        return graphQlQueryToMongoJoinQuery(field);
      });
    }
github keystonejs / keystone / packages / access-control / index.js View on Github external
testListAccessControl({ access, listKey, operation, authentication }) {
    // Either a boolean or an object describing a where clause
    if (typeof access[operation] !== 'function') {
      return access[operation];
    }

    const result = access[operation]({
      authentication: authentication.item ? authentication : {}
    });

    const type = getType(result);

    if (!['Object', 'Boolean'].includes(type)) {
      throw new Error(`Must return an Object or Boolean from Imperative or Declarative access control function. Got ${type}`);
    }

    // Special case for 'create' permission
    if (operation === 'create' && type === 'Object') {
      throw new Error(`Expected a Boolean for ${listKey}.access.create(), but got Object. (NOTE: 'create' cannot have a Declarative access control config)`);
    }

    return result;
  }
}
github keystonejs / keystone / packages / access-control / index.js View on Github external
const parseAccess = ({ accessTypes, access, defaultAccess, onGranularParseError, validateGranularType }) => {
  switch (getType(access)) {
    case 'Boolean':
    case 'Function':
      return shorthandToObject(accessTypes, access);

    case 'Object':
      return parseGranularAccessConfig({ accessTypes, access, defaultAccess, onGranularParseError, validateGranularType });

    default:
      throw new Error('Shorthand access must be specified as either a boolean or a function.');
  }
};
github keystonejs / keystone / packages / access-control / index.js View on Github external
.map(([accessType, accessConfig]) => {
      const type = getType(accessConfig);

      return validationError(type, accessType);
    })
    .filter(error => !!error);
github keystonejs / keystone / packages / mongo-join-builder / lib / tokenizers / simple.js View on Github external
$search: value => {
    if (!value || (getType(value) === 'String' && !value.trim())) {
      return undefined;
    }
    return {
      $match: {
        name: new RegExp(`${escapeRegExp(value)}`, 'i'),
      },
    };
  },