{"version":3,"file":"extend.cjs","names":[],"sources":["../../src/utils/extend.ts"],"sourcesContent":["import type {\n  StrictExtendedTypes,\n  NarrowExtendedTypes,\n  StrictArgsDefinition,\n  GeneDirectiveConfig,\n  GeneConfig,\n} from '../defineConfig'\nimport type { GraphqlReturnTypes, TypeOrFunction, ValidGraphqlType } from '../types'\nimport { isObject } from '.'\n\ndeclare global {\n  var __graphqlGeneExtendedTypes:\n    | { config: StrictExtendedTypes; geneConfig: { [type: string]: GeneConfig | undefined } }\n    | undefined\n}\n\nexport function getGloballyExtendedTypes(): NonNullable<\n  typeof globalThis.__graphqlGeneExtendedTypes\n> {\n  globalThis.__graphqlGeneExtendedTypes = globalThis.__graphqlGeneExtendedTypes ?? {\n    config: {},\n    geneConfig: {},\n  }\n\n  return globalThis.__graphqlGeneExtendedTypes\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function setGeneConfigByType<TGeneConfig extends GeneConfig<any>>(\n  type: string,\n  geneConfig: TGeneConfig | undefined\n) {\n  if (!geneConfig) return\n\n  const globalTypes = getGloballyExtendedTypes()\n  globalTypes.geneConfig[type] = geneConfig\n}\n\nexport function extendTypes<\n  T extends {\n    [TypeName in keyof T]: {\n      [Field in keyof T[TypeName]]: {\n        [K in keyof T[TypeName][Field]]: K extends 'returnType'\n          ? GraphqlReturnTypes<ValidGraphqlType>\n          : K extends 'args'\n            ? StrictArgsDefinition\n            : K extends 'directives'\n              ? TypeOrFunction<GeneDirectiveConfig[]>\n              : T[TypeName][Field][K]\n      }\n    }\n  },\n>(types: NarrowExtendedTypes<T>) {\n  const globalTypes = getGloballyExtendedTypes()\n\n  Object.entries(types).forEach(([graphqlType, fieldConfigs]) => {\n    if (!isObject(fieldConfigs)) {\n      throw new Error(`Provided field config for type \"${graphqlType}\" must be an object.`)\n    }\n    const type = graphqlType as 'Query'\n    globalTypes.config[type] = globalTypes.config[type] || {}\n    globalTypes.config[type] = { ...globalTypes.config[type], ...fieldConfigs }\n  })\n}\n"],"mappings":"kGAgBA,SAAgB,GAEd,CAMA,MALA,YAAW,2BAA6B,WAAW,4BAA8B,CAC/E,OAAQ,EAAE,CACV,WAAY,EAAE,CACf,CAEM,WAAW,2BAIpB,SAAgB,EACd,EACA,EACA,CACA,GAAI,CAAC,EAAY,OAEjB,IAAM,EAAc,GAA0B,CAC9C,EAAY,WAAW,GAAQ,EAGjC,SAAgB,EAcd,EAA+B,CAC/B,IAAM,EAAc,GAA0B,CAE9C,OAAO,QAAQ,EAAM,CAAC,SAAS,CAAC,EAAa,KAAkB,CAC7D,GAAI,CAAC,EAAA,SAAS,EAAa,CACzB,MAAU,MAAM,mCAAmC,EAAY,sBAAsB,CAEvF,IAAM,EAAO,EACb,EAAY,OAAO,GAAQ,EAAY,OAAO,IAAS,EAAE,CACzD,EAAY,OAAO,GAAQ,CAAE,GAAG,EAAY,OAAO,GAAO,GAAG,EAAc,EAC3E"}