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SAAS,mCAAmC,OAAE,GAAU,EAAU,CAAC,GACjE,MAAO,CACL,gBAAsB,UACb,CACL,yBAAM,EAAqB,QAAE,EAAO,SAAE,IACpC,MAAM,EAAQ,EAAQ,cAClB,mBAAmB,GAAU,EAAQ,eACrC,EAEE,EAAS,cACb,EACA,EACA,EAAQ,UACR,EAAQ,cACR,GAEF,GAAI,EAAO,OAAS,EAClB,MAAM,EAAO,KAAI,IACf,MAAM,eAAE,GAAmB,QAAQ,wBACnC,OAAO,IAAI,EAAe,EAAI,QAAS,CAAE,MAAO,EAAI,UAAW,QAAS,EAAI,SAAS,GAG3F,IAIR,CAEA,SAAS,mCAAoC,EAAU,CAAC,GACtD,MAAO,CACL,SAAA,EAAW,KAAE,EAAI,0BAAE,IACjB,MAAM,EAAS,cAAc,EAAK,OAAQ,EAAK,SAAU,EAAK,eAAgB,EAAK,cAAe,GAC9F,EAAO,OAAS,GAClB,EAA0B,CAAE,OAAQ,EAAO,KAAI,GAAgB,IAAI,aAAa,EAAI,QAAS,CAAE,WAAY,CAAE,KAAM,EAAI,KAAM,MAAO,EAAI,UAAW,QAAS,EAAI,cAEpK,EAEJ,CAEA,SAAS,0BAA2B,GAClC,OAAQ,GACC,IAAI,uBAAuB,EAAS,EAE/C,CAEA,OAAO,QAAU,CAAE,wCAAqB,kEAAkC,wDAA6B,4BAAe,oEAAmC,sEAAoC","file":"/npm/graphql-constraint-directive@6.0.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/graphql-constraint-directive@6.0.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const {\n  GraphQLNonNull,\n  GraphQLList,\n  separateOperations,\n  GraphQLError,\n  getDirectiveValues\n} = require('graphql')\nconst QueryValidationVisitor = require('./lib/query-validation-visitor.js')\nconst { validateQuery } = require('./lib/validate-query')\n\nconst { getDirective, mapSchema, MapperKind } = require('@graphql-tools/utils')\nconst { getConstraintTypeObject, getScalarType } = require('./lib/type-utils')\nconst { constraintDirectiveTypeDefs, constraintDirectiveTypeDefsObj } = require('./lib/type-defs')\n\nfunction constraintDirective () {\n  const constraintTypes = {}\n\n  function getConstraintType (fieldName, type, notNull, directiveArgumentMap, list, listNotNull) {\n  // Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ as per graphql-js\n    let uniqueTypeName\n    if (directiveArgumentMap.uniqueTypeName) {\n      uniqueTypeName = directiveArgumentMap.uniqueTypeName.replace(/\\W/g, '')\n    } else {\n      uniqueTypeName =\n                `${fieldName}_${list ? 'List_' : ''}${listNotNull ? 'ListNotNull_' : ''}${\n                  type.name\n                }_${notNull ? 'NotNull_' : ''}` +\n                Object.entries(directiveArgumentMap)\n                  .map(([key, value]) => {\n                    if (\n                      key === 'min' ||\n                            key === 'max' ||\n                            key === 'exclusiveMin' ||\n                            key === 'exclusiveMax' ||\n                            key === 'multipleOf'\n                    ) {\n                      return `${key}_${value.toString().replace(/\\W/g, 'dot')}`\n                    }\n                    return `${key}_${value.toString().replace(/\\W/g, '')}`\n                  })\n                  .join('_')\n    }\n    const key = Symbol.for(uniqueTypeName)\n    let constraintType = constraintTypes[key]\n    if (constraintType) return constraintType\n    constraintType = getConstraintTypeObject(fieldName, type, uniqueTypeName, directiveArgumentMap)\n    if (notNull) {\n      constraintType = new GraphQLNonNull(constraintType)\n    }\n    if (list) {\n      constraintType = new GraphQLList(constraintType)\n      if (listNotNull) {\n        constraintType = new GraphQLNonNull(constraintType)\n      }\n    }\n    constraintTypes[key] = constraintType\n\n    return constraintType\n  }\n\n  function wrapType (fieldConfig, directiveArgumentMap) {\n    const result = getScalarType(fieldConfig.type)\n    const fieldName = fieldConfig.astNode.name.value\n    fieldConfig.type = getConstraintType(\n      fieldName,\n      result.scalarType,\n      result.scalarNotNull,\n      directiveArgumentMap,\n      result.list,\n      result.listNotNull\n    )\n  }\n\n  return (schema) =>\n    mapSchema(schema, {\n      [MapperKind.FIELD]: (fieldConfig) => {\n        const directiveArgumentMap = getDirective(schema, fieldConfig, 'constraint')?.[0]\n\n        if (directiveArgumentMap) {\n          wrapType(fieldConfig, directiveArgumentMap)\n\n          return fieldConfig\n        }\n      },\n      [MapperKind.ARGUMENT]: (fieldConfig) => {\n        const directiveArgumentMap = getDirective(schema, fieldConfig, 'constraint')?.[0]\n\n        if (directiveArgumentMap) {\n          wrapType(fieldConfig, directiveArgumentMap)\n\n          return fieldConfig\n        }\n      }\n    })\n}\n\nfunction constraintDirectiveDocumentation (options) {\n  // Default descriptions, can be changed through options\n  let DESCRIPTINS_MAP = {\n    minLength: 'Minimal length',\n    maxLength: 'Maximal length',\n    startsWith: 'Starts with',\n    endsWith: 'Ends with',\n    contains: 'Contains',\n    notContains: 'Doesn\\'t contain',\n    pattern: 'Must match RegEx pattern',\n    format: 'Must match format',\n    min: 'Minimal value',\n    max: 'Maximal value',\n    exclusiveMin: 'Grater than',\n    exclusiveMax: 'Less than',\n    multipleOf: 'Must be a multiple of',\n    minItems: 'Minimal number of items',\n    maxItems: 'Maximal number of items'\n  }\n\n  if (options?.descriptionsMap) {\n    DESCRIPTINS_MAP = options.descriptionsMap\n  }\n\n  let HEADER = '*Constraints:*'\n  if (options?.header) {\n    HEADER = options.header\n  }\n\n  function documentConstraintDirective (fieldConfig, directiveArgumentMap) {\n    if (fieldConfig.description) {\n      // skip documentation if it is already here\n      if (fieldConfig.description.includes(HEADER)) return\n\n      // add two new lines to separate from previous description by paragraph\n      fieldConfig.description += '\\n\\n'\n    } else {\n      fieldConfig.description = ''\n    }\n\n    fieldConfig.description += HEADER + '\\n'\n\n    Object.entries(directiveArgumentMap).forEach(([key, value]) => {\n      if (key === 'uniqueTypeName') return\n      fieldConfig.description += `* ${DESCRIPTINS_MAP[key] ? DESCRIPTINS_MAP[key] : key}: \\`${value}\\`\\n`\n    })\n\n    if (fieldConfig.astNode?.description) { fieldConfig.astNode.description.value = fieldConfig.description }\n  }\n\n  return (schema) =>\n    mapSchema(schema, {\n      [MapperKind.FIELD]: (fieldConfig) => {\n        if (fieldConfig?.astNode) {\n          const directiveArgumentMap = getDirectiveValues(constraintDirectiveTypeDefsObj, fieldConfig.astNode)\n\n          if (directiveArgumentMap) {\n            documentConstraintDirective(fieldConfig, directiveArgumentMap)\n\n            return fieldConfig\n          }\n        }\n      },\n      [MapperKind.ARGUMENT]: (fieldConfig) => {\n        if (fieldConfig?.astNode) {\n          const directiveArgumentMap = getDirectiveValues(constraintDirectiveTypeDefsObj, fieldConfig.astNode)\n\n          if (directiveArgumentMap) {\n            documentConstraintDirective(fieldConfig, directiveArgumentMap)\n\n            return fieldConfig\n          }\n        }\n      }\n    })\n}\n\nfunction createApolloQueryValidationPlugin ({ schema }, options = {}) {\n  return {\n    async requestDidStart () {\n      return ({\n        async didResolveOperation ({ request, document }) {\n          const query = request.operationName\n            ? separateOperations(document)[request.operationName]\n            : document\n\n          const errors = validateQuery(\n            schema,\n            query,\n            request.variables,\n            request.operationName,\n            options\n          )\n          if (errors.length > 0) {\n            throw errors.map(err => {\n              const { UserInputError } = require('apollo-server-errors')\n              return new UserInputError(err.message, { field: err.fieldName, context: err.context })\n            })\n          }\n        }\n      })\n    }\n  }\n}\n\nfunction createEnvelopQueryValidationPlugin (options = {}) {\n  return {\n    onExecute ({ args, setResultAndStopExecution }) {\n      const errors = validateQuery(args.schema, args.document, args.variableValues, args.operationName, options)\n      if (errors.length > 0) {\n        setResultAndStopExecution({ errors: errors.map(err => { return new GraphQLError(err.message, { extensions: { code: err.code, field: err.fieldName, context: err.context } }) }) })\n      }\n    }\n  }\n}\n\nfunction createQueryValidationRule (options) {\n  return (context) => {\n    return new QueryValidationVisitor(context, options)\n  }\n}\n\nmodule.exports = { constraintDirective, constraintDirectiveDocumentation, constraintDirectiveTypeDefs, validateQuery, createApolloQueryValidationPlugin, createEnvelopQueryValidationPlugin, createQueryValidationRule }\n"]}