{"version":3,"file":"FragmentReference.mjs","names":[],"sources":["../../src/core/FragmentReference.ts"],"sourcesContent":["import type { ReaderWithRefetchQueries } from './entrypoint';\nimport {\n  type ComponentOrFieldName,\n  type StoreLink,\n} from './IsographEnvironment';\nimport type { PromiseWrapper } from './PromiseWrapper';\nimport type { StartUpdate } from './reader';\nimport { stableCopy } from './util';\n\n// TODO type this better\nexport type VariableValue =\n  | string\n  | number\n  | boolean\n  | null\n  | {\n      readonly [index: string]: VariableValue;\n    }\n  | VariableValue[];\n\nexport type Variables = { readonly [index: string]: VariableValue };\n\nexport type UnknownTReadFromStore = {\n  parameters: object;\n  data: object;\n  startUpdate?: StartUpdate<object>;\n};\n\nexport type ExtractData<T> = T extends {\n  data: infer D extends object;\n}\n  ? D\n  : never;\n\nexport type ExtractParameters<T> = T extends {\n  parameters: infer P extends Variables;\n}\n  ? P\n  : Variables;\n\nexport type ExtractStartUpdate<T extends UnknownTReadFromStore> =\n  T['startUpdate'];\n\nexport type ExtractUpdatableData<T extends UnknownTReadFromStore> =\n  ExtractUpdatableDataFromStartUpdate<ExtractStartUpdate<T>>;\n\nexport type ExtractUpdatableDataFromStartUpdate<T> =\n  T extends StartUpdate<infer D> ? D : never;\n\nexport type FragmentReference<\n  TReadFromStore extends UnknownTReadFromStore,\n  TClientFieldValue,\n> = {\n  readonly kind: 'FragmentReference';\n  readonly readerWithRefetchQueries: PromiseWrapper<\n    ReaderWithRefetchQueries<TReadFromStore, TClientFieldValue>\n  >;\n  readonly root: StoreLink;\n  readonly fieldName: ComponentOrFieldName;\n  readonly readerArtifactKind:\n    | 'EagerReaderArtifact'\n    | 'ComponentReaderArtifact';\n  // TODO we potentially stably copy and stringify variables a lot!\n  // So, we should employ interior mutability: pretend that fragment reference\n  // is immutable, but actually store something like\n  // `Map<Variable, StablyCopiedStringifiedOutput>`\n  // and read or update that map when we would otherwise stably copy and\n  // stringify.\n  readonly variables: ExtractParameters<TReadFromStore>;\n  readonly networkRequest: PromiseWrapper<void, any>;\n};\n\nexport type StableIdForFragmentReference = string;\n\nexport function stableIdForFragmentReference(\n  fragmentReference: FragmentReference<any, any>,\n): StableIdForFragmentReference {\n  return `${fragmentReference.root.__typename}/${fragmentReference.root.__link}/${fragmentReference.fieldName}/${JSON.stringify(stableCopy(fragmentReference.variables))}`;\n}\n"],"mappings":";;;AA0EA,SAAgB,6BACd,mBAC8B;AAC9B,QAAO,GAAG,kBAAkB,KAAK,WAAW,GAAG,kBAAkB,KAAK,OAAO,GAAG,kBAAkB,UAAU,GAAG,KAAK,UAAU,WAAW,kBAAkB,UAAU,CAAC"}