{"version":3,"sources":["../src/generated/fragment-masking.ts"],"names":["useFragment","_documentNode","fragmentType","makeFragmentData","data","_fragment","isFragmentReady","queryNode","fragmentNode","deferredFields","fragName","fields","field"],"mappings":";AAoCO,SAASA,EACdC,EACAC,EACiD,CACjD,OAAOA,CACT,CAGO,SAASC,EAGdC,EAAUC,EAA+B,CACzC,OAAOD,CACT,CACO,SAASE,EACdC,EACAC,EACAJ,EAC2C,CAC3C,IAAMK,EAAkBF,EAAiF,UACrG,eAEJ,GAAI,CAACE,EAAgB,MAAO,GAG5B,IAAMC,EADUF,EAAa,YAAY,CAAC,GAChB,MAAM,MAE1BG,EAAUD,GAAYD,EAAeC,CAAQ,GAAM,CAAC,EAC1D,OAAOC,EAAO,OAAS,GAAKA,EAAO,MAAMC,GAASR,GAAQQ,KAASR,CAAI,CACzE","sourcesContent":["import type { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core';\nimport type { FragmentDefinitionNode } from 'graphql';\nimport type { Incremental } from './graphql';\n\n\nexport type FragmentType<TDocumentType extends DocumentTypeDecoration<any, any>> = TDocumentType extends DocumentTypeDecoration<\n  infer TType,\n  any\n>\n  ? [TType] extends [{ ' $fragmentName'?: infer TKey }]\n    ? TKey extends string\n      ? { ' $fragmentRefs'?: { [key in TKey]: TType } }\n      : never\n    : never\n  : never;\n\n// return non-nullable if `fragmentType` is non-nullable\nexport function useFragment<TType>(\n  _documentNode: DocumentTypeDecoration<TType, any>,\n  fragmentType: FragmentType<DocumentTypeDecoration<TType, any>>\n): TType;\n// return nullable if `fragmentType` is nullable\nexport function useFragment<TType>(\n  _documentNode: DocumentTypeDecoration<TType, any>,\n  fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined\n): TType | null | undefined;\n// return array of non-nullable if `fragmentType` is array of non-nullable\nexport function useFragment<TType>(\n  _documentNode: DocumentTypeDecoration<TType, any>,\n  fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>\n): ReadonlyArray<TType>;\n// return array of nullable if `fragmentType` is array of nullable\nexport function useFragment<TType>(\n  _documentNode: DocumentTypeDecoration<TType, any>,\n  fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined\n): ReadonlyArray<TType> | null | undefined;\nexport function useFragment<TType>(\n  _documentNode: DocumentTypeDecoration<TType, any>,\n  fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined\n): TType | ReadonlyArray<TType> | null | undefined {\n  return fragmentType as any;\n}\n\n\nexport function makeFragmentData<\n  F extends DocumentTypeDecoration<any, any>,\n  FT extends ResultOf<F>\n>(data: FT, _fragment: F): FragmentType<F> {\n  return data as FragmentType<F>;\n}\nexport function isFragmentReady<TQuery, TFrag>(\n  queryNode: DocumentTypeDecoration<TQuery, any>,\n  fragmentNode: TypedDocumentNode<TFrag>,\n  data: FragmentType<TypedDocumentNode<Incremental<TFrag>, any>> | null | undefined\n): data is FragmentType<typeof fragmentNode> {\n  const deferredFields = (queryNode as { __meta__?: { deferredFields: Record<string, (keyof TFrag)[]> } }).__meta__\n    ?.deferredFields;\n\n  if (!deferredFields) return true;\n\n  const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;\n  const fragName = fragDef?.name?.value;\n\n  const fields = (fragName && deferredFields[fragName]) || [];\n  return fields.length > 0 && fields.every(field => data && field in data);\n}\n"]}