diff --git a/src/masking/internal/types.ts b/src/masking/internal/types.ts index b92d1b03cca..c2f7c54258e 100644 --- a/src/masking/internal/types.ts +++ b/src/masking/internal/types.ts @@ -1,30 +1,34 @@ -import type { Prettify, UnionToIntersection } from "../../utilities/index.js"; - export type UnwrapFragmentRefs = // Leave TData alone if it is Record and not a specific shape string extends keyof NonNullable ? TData - : " $fragmentRefs" extends keyof NonNullable ? - TData extends { " $fragmentRefs"?: infer FragmentRefs extends object } ? - Prettify< - { - [K in keyof TData as K extends " $fragmentRefs" ? never - : K]: UnwrapFragmentRefs; - } & CombineFragmentRefs - > + : keyof NonNullable extends never ? TData + : //: TData extends Array ? Array> + TData extends { " $fragmentRefs"?: object | null } ? + Combine> extends infer Flattened ? + { [K in keyof Flattened]: UnwrapFragmentRefs } : never : TData extends object ? { [K in keyof TData]: UnwrapFragmentRefs } : TData; -type CombineFragmentRefs> = - UnionToIntersection< - { - [K in keyof FragmentRefs]-?: UnwrapFragmentRefs< - RemoveFragmentName - >; - }[keyof FragmentRefs] - >; - export type RemoveMaskedMarker = Omit; -// force distrubution when T is a union with | undefined -export type RemoveFragmentName = - T extends any ? Omit : T; + +type Values = T extends object ? T[keyof T] : never; + +type KeyTuples = + V extends object ? + keyof V extends infer K ? + K extends keyof V ? + K extends " $fragmentRefs" ? KeyTuples> + : K extends " $fragmentName" ? never + : [K, V[K], {} extends Pick ? true : false] + : never + : never + : never; + +type Combine< + Tuple extends [key: string | number | symbol, value: any, optional: boolean], +> = { + [P in Tuple as P[2] extends true ? P[0] : never]?: P[1]; +} & { + [P in Tuple as P[2] extends false ? P[0] : never]: P[1]; +}; diff --git a/src/masking/types.ts b/src/masking/types.ts index ae2216a5c96..55aa79faf0c 100644 --- a/src/masking/types.ts +++ b/src/masking/types.ts @@ -1,6 +1,5 @@ import type { TypedDocumentNode } from "@graphql-typed-document-node/core"; import type { - RemoveFragmentName, RemoveMaskedMarker, UnwrapFragmentRefs, } from "./internal/types.ts"; @@ -45,6 +44,4 @@ export type MaybeMasked = * Unmasks a type to provide its full result. */ export type Unmasked = - TData extends object ? - UnwrapFragmentRefs>> - : TData; + TData extends object ? UnwrapFragmentRefs> : TData;