Skip to content

Commit

Permalink
Handle additional cases in unmasked types (#12154)
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas authored Nov 25, 2024
1 parent f4d82c8 commit d933def
Show file tree
Hide file tree
Showing 33 changed files with 2,587 additions and 561 deletions.
95 changes: 76 additions & 19 deletions .api-reports/api-report-cache.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,25 @@ export const canonicalStringify: ((value: any) => string) & {
// @public (undocumented)
type CanReadFunction = (value: StoreValue) => boolean;

// Warning: (ae-forgotten-export) The symbol "UnionToIntersection" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "UnwrapFragmentRefs" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "RemoveFragmentName" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "Prettify" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "MergeUnions" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ExtractByMatchingTypeNames" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
type CombineFragmentRefs<FragmentRefs extends Record<string, any>> = UnionToIntersection<{
[K in keyof FragmentRefs]-?: UnwrapFragmentRefs<RemoveFragmentName<FragmentRefs[K]>>;
}[keyof FragmentRefs]>;
// @public
type CombineByTypeName<T extends {
__typename?: string;
}> = {
[TypeName in NonNullable<T["__typename"]>]: Prettify<MergeUnions<ExtractByMatchingTypeNames<T, TypeName>>>;
}[NonNullable<T["__typename"]>];

// Warning: (ae-forgotten-export) The symbol "CombineByTypeName" needs to be exported by the entry point index.d.ts
//
// @public
type CombineIntersection<T> = Exclude<T, {
__typename?: string;
}> | CombineByTypeName<Extract<T, {
__typename?: string;
}>>;

// @public (undocumented)
type ContainsFragmentsRefs<TData> = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs<TData[keyof TData]> : false;
Expand Down Expand Up @@ -352,6 +363,9 @@ export type DiffQueryAgainstStoreOptions = ReadQueryOptions & {
returnPartialData?: boolean;
};

// @public (undocumented)
type DistributedRequiredExclude<T, U> = T extends any ? Required<T> extends Required<U> ? Required<U> extends Required<T> ? never : T : T : T;

// @public (undocumented)
export abstract class EntityStore implements NormalizedCache {
constructor(policies: Policies, group: CacheGroup);
Expand Down Expand Up @@ -448,6 +462,13 @@ export namespace EntityStore {
}
}

// @public
type ExtractByMatchingTypeNames<Union extends {
__typename?: string;
}, TypeName extends string> = Union extends any ? TypeName extends NonNullable<Union["__typename"]> ? Omit<Union, "__typename"> & {
[K in keyof Union as K extends "__typename" ? K : never]: TypeName;
} : never : never;

// @public (undocumented)
export interface FieldFunctionOptions<TArgs = Record<string, any>, TVars = Record<string, any>> {
// (undocumented)
Expand Down Expand Up @@ -677,6 +698,9 @@ interface InvalidateModifier {
// @public (undocumented)
const _invalidateModifier: unique symbol;

// @public (undocumented)
type IsAny<T> = 0 extends 1 & T ? true : false;

// @public (undocumented)
export function isReference(obj: any): obj is Reference;

Expand Down Expand Up @@ -733,17 +757,17 @@ export function makeReference(id: string): Reference;
// @public (undocumented)
export function makeVar<T>(value: T): ReactiveVar<T>;

// Warning: (ae-forgotten-export) The symbol "Prettify" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "IsAny" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "RemoveMaskedMarker" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "DataMasking" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ContainsFragmentsRefs" needs to be exported by the entry point index.d.ts
//
// @public
type MaybeMasked<TData> = TData extends {
type MaybeMasked<TData> = TData extends any ? true extends IsAny<TData> ? TData : TData extends {
__masked?: true;
} ? Prettify<RemoveMaskedMarker<TData>> : DataMasking extends {
enabled: true;
} ? TData : true extends ContainsFragmentsRefs<TData> ? Unmasked<TData> : TData;
} ? TData : true extends ContainsFragmentsRefs<TData> ? Unmasked<TData> : TData : never;

// @public (undocumented)
export interface MergeInfo {
Expand All @@ -755,6 +779,19 @@ export interface MergeInfo {
typename: string | undefined;
}

// Warning: (ae-forgotten-export) The symbol "CombineIntersection" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
type MergeObjects<T, U> = Prettify<{
[k in keyof T]: k extends keyof U ? [
NonNullable<T[k]>,
NonNullable<U[k]>
] extends ([
infer TK extends object,
infer UK extends object
]) ? TK extends unknown[] ? UK extends unknown[] ? CombineIntersection<TK[number] | UK[number]>[] | Extract<T[k] | U[k], undefined | null> : T[k] : CombineIntersection<TK | UK> | Extract<T[k] | U[k], undefined | null> : T[k] : T[k];
} & Pick<U, Exclude<keyof U, keyof T>>>;

// @public (undocumented)
type MergeObjectsFunction = <T extends StoreObject | Reference>(existing: T, incoming: T) => T;

Expand All @@ -766,6 +803,22 @@ export interface MergeTree {
map: Map<string | number, MergeTree>;
}

// Warning: (ae-forgotten-export) The symbol "MergeUnionsAcc" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "takeOneFromUnion" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
type MergeUnions<TUnion> = MergeUnionsAcc<TUnion, takeOneFromUnion<TUnion>, never>;

// Warning: (ae-forgotten-export) The symbol "DistributedRequiredExclude" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "MergeObjects" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
type MergeUnionsAcc<TUnion, Curr, Merged> = [
Curr
] extends [never] ? Merged : MergeUnionsAcc<DistributedRequiredExclude<TUnion, Curr>, takeOneFromUnion<DistributedRequiredExclude<TUnion, Curr>>, [
Merged
] extends [never] ? Curr : MergeObjects<Curr, Merged>>;

// @public (undocumented)
export class MissingFieldError extends Error {
constructor(message: string, path: MissingTree | Array<string | number>, query: DocumentNode, variables?: Record<string, any> | undefined);
Expand Down Expand Up @@ -1016,6 +1069,11 @@ class Stump extends Layer {
removeLayer(): this;
}

// Warning: (ae-forgotten-export) The symbol "unionToIntersection" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
type takeOneFromUnion<T> = unionToIntersection<T extends T ? (x: T) => 0 : never> extends ((x: infer U) => 0) ? U : never;

// @public (undocumented)
type ToReferenceFunction = (objOrIdOrRef: StoreObject | string | Reference, mergeIntoStore?: boolean) => Reference | undefined;

Expand All @@ -1040,19 +1098,18 @@ export type TypePolicy = {
};

// @public (undocumented)
type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
type unionToIntersection<T> = (T extends unknown ? (x: T) => unknown : never) extends ((x: infer U) => unknown) ? U : never;

// Warning: (ae-forgotten-export) The symbol "UnwrapFragmentRefs" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "RemoveFragmentName" needs to be exported by the entry point index.d.ts
//
// @public
type Unmasked<TData> = TData extends object ? UnwrapFragmentRefs<RemoveMaskedMarker<RemoveFragmentName<TData>>> : TData;
type Unmasked<TData> = true extends IsAny<TData> ? TData : TData extends object ? UnwrapFragmentRefs<RemoveMaskedMarker<RemoveFragmentName<TData>>> : TData;

// Warning: (ae-forgotten-export) The symbol "CombineFragmentRefs" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
type UnwrapFragmentRefs<TData> = TData extends any ? string extends keyof NonNullable<TData> ? TData : " $fragmentRefs" extends keyof NonNullable<TData> ? TData extends {
" $fragmentRefs"?: infer FragmentRefs extends object;
} ? Prettify<{
[K in keyof TData as K extends " $fragmentRefs" ? never : K]: UnwrapFragmentRefs<TData[K]>;
} & CombineFragmentRefs<FragmentRefs>> : never : TData extends Array<infer TItem> ? Array<UnwrapFragmentRefs<TItem>> : TData extends object ? {
type UnwrapFragmentRefs<TData> = true extends IsAny<TData> ? TData : TData extends any ? string extends keyof TData ? TData : keyof TData extends never ? TData : TData extends {
" $fragmentRefs"?: infer FragmentRefs;
} ? UnwrapFragmentRefs<CombineIntersection<Omit<TData, " $fragmentRefs"> | RemoveFragmentName<NonNullable<NonNullable<FragmentRefs>[keyof NonNullable<FragmentRefs>]>>>> : TData extends Array<infer TItem> ? Array<UnwrapFragmentRefs<TItem>> : TData extends object ? {
[K in keyof TData]: UnwrapFragmentRefs<TData[K]>;
} : TData : never;

Expand Down
101 changes: 79 additions & 22 deletions .api-reports/api-report-core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -432,14 +432,25 @@ export type ClientParseError = InvariantError & {
parseError: Error;
};

// Warning: (ae-forgotten-export) The symbol "UnionToIntersection" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "UnwrapFragmentRefs" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "RemoveFragmentName" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "Prettify" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "MergeUnions" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ExtractByMatchingTypeNames" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
type CombineFragmentRefs<FragmentRefs extends Record<string, any>> = UnionToIntersection<{
[K in keyof FragmentRefs]-?: UnwrapFragmentRefs<RemoveFragmentName<FragmentRefs[K]>>;
}[keyof FragmentRefs]>;
// @public
type CombineByTypeName<T extends {
__typename?: string;
}> = {
[TypeName in NonNullable<T["__typename"]>]: Prettify<MergeUnions<ExtractByMatchingTypeNames<T, TypeName>>>;
}[NonNullable<T["__typename"]>];

// Warning: (ae-forgotten-export) The symbol "CombineByTypeName" needs to be exported by the entry point index.d.ts
//
// @public
type CombineIntersection<T> = Exclude<T, {
__typename?: string;
}> | CombineByTypeName<Extract<T, {
__typename?: string;
}>>;

// @public (undocumented)
class Concast<T> extends Observable<T> {
Expand Down Expand Up @@ -633,6 +644,9 @@ export { disableExperimentalFragmentVariables }

export { disableFragmentWarnings }

// @public (undocumented)
type DistributedRequiredExclude<T, U> = T extends any ? Required<T> extends Required<U> ? Required<U> extends Required<T> ? never : T : T : T;

export { DocumentNode }

// @public (undocumented)
Expand Down Expand Up @@ -811,6 +825,13 @@ interface ExecutionPatchResultBase {
hasNext?: boolean;
}

// @public
type ExtractByMatchingTypeNames<Union extends {
__typename?: string;
}, TypeName extends string> = Union extends any ? TypeName extends NonNullable<Union["__typename"]> ? Omit<Union, "__typename"> & {
[K in keyof Union as K extends "__typename" ? K : never]: TypeName;
} : never : never;

// @public (undocumented)
export const fallbackHttpConfig: {
http: HttpQueryOptions;
Expand Down Expand Up @@ -1227,6 +1248,9 @@ interface InvalidateModifier {
// @public (undocumented)
const _invalidateModifier: unique symbol;

// @public (undocumented)
type IsAny<T> = 0 extends 1 & T ? true : false;

// @public (undocumented)
export function isApolloError(err: Error): err is ApolloError;

Expand All @@ -1236,11 +1260,11 @@ export function isNetworkRequestSettled(networkStatus?: NetworkStatus): boolean;
// @public (undocumented)
export function isReference(obj: any): obj is Reference;

// Warning: (ae-forgotten-export) The symbol "UnionToIntersection_2" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "UnionToIntersection" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "UnionForAny" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
type IsStrictlyAny<T> = UnionToIntersection_2<UnionForAny<T>> extends never ? true : false;
type IsStrictlyAny<T> = UnionToIntersection<UnionForAny<T>> extends never ? true : false;

// @public (undocumented)
type KeyArgsFunction = (args: Record<string, any> | null, context: {
Expand Down Expand Up @@ -1377,16 +1401,16 @@ interface MaskOperationOptions<TData> {
// @public (undocumented)
type MaybeAsync<T> = T | PromiseLike<T>;

// Warning: (ae-forgotten-export) The symbol "Prettify" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "IsAny" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "RemoveMaskedMarker" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ContainsFragmentsRefs" needs to be exported by the entry point index.d.ts
//
// @public
export type MaybeMasked<TData> = TData extends {
export type MaybeMasked<TData> = TData extends any ? true extends IsAny<TData> ? TData : TData extends {
__masked?: true;
} ? Prettify<RemoveMaskedMarker<TData>> : DataMasking extends {
enabled: true;
} ? TData : true extends ContainsFragmentsRefs<TData> ? Unmasked<TData> : TData;
} ? TData : true extends ContainsFragmentsRefs<TData> ? Unmasked<TData> : TData : never;

// @public (undocumented)
export interface MergeInfo {
Expand All @@ -1398,6 +1422,19 @@ export interface MergeInfo {
typename: string | undefined;
}

// Warning: (ae-forgotten-export) The symbol "CombineIntersection" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
type MergeObjects<T, U> = Prettify<{
[k in keyof T]: k extends keyof U ? [
NonNullable<T[k]>,
NonNullable<U[k]>
] extends ([
infer TK extends object,
infer UK extends object
]) ? TK extends unknown[] ? UK extends unknown[] ? CombineIntersection<TK[number] | UK[number]>[] | Extract<T[k] | U[k], undefined | null> : T[k] : CombineIntersection<TK | UK> | Extract<T[k] | U[k], undefined | null> : T[k] : T[k];
} & Pick<U, Exclude<keyof U, keyof T>>>;

// @public (undocumented)
type MergeObjectsFunction = <T extends StoreObject | Reference>(existing: T, incoming: T) => T;

Expand All @@ -1414,6 +1451,22 @@ export interface MergeTree {
map: Map<string | number, MergeTree>;
}

// Warning: (ae-forgotten-export) The symbol "MergeUnionsAcc" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "takeOneFromUnion" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
type MergeUnions<TUnion> = MergeUnionsAcc<TUnion, takeOneFromUnion<TUnion>, never>;

// Warning: (ae-forgotten-export) The symbol "DistributedRequiredExclude" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "MergeObjects" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
type MergeUnionsAcc<TUnion, Curr, Merged> = [
Curr
] extends [never] ? Merged : MergeUnionsAcc<DistributedRequiredExclude<TUnion, Curr>, takeOneFromUnion<DistributedRequiredExclude<TUnion, Curr>>, [
Merged
] extends [never] ? Curr : MergeObjects<Curr, Merged>>;

// @public (undocumented)
export type MethodKeys<T> = {
[P in keyof T]: T[P] extends Function ? P : never;
Expand Down Expand Up @@ -2276,6 +2329,11 @@ export interface SubscriptionOptions<TVariables = OperationVariables, TData = an
variables?: TVariables;
}

// Warning: (ae-forgotten-export) The symbol "unionToIntersection" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
type takeOneFromUnion<T> = unionToIntersection<T extends T ? (x: T) => 0 : never> extends ((x: infer U) => 0) ? U : never;

// @public (undocumented)
export const throwServerError: (response: Response, result: any, message: string) => never;

Expand Down Expand Up @@ -2334,22 +2392,21 @@ export type TypePolicy = {
type UnionForAny<T> = T extends never ? "a" : 1;

// @public (undocumented)
type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;

// @public (undocumented)
type UnionToIntersection_2<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
type unionToIntersection<T> = (T extends unknown ? (x: T) => unknown : never) extends ((x: infer U) => unknown) ? U : never;

// Warning: (ae-forgotten-export) The symbol "UnwrapFragmentRefs" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "RemoveFragmentName" needs to be exported by the entry point index.d.ts
//
// @public
export type Unmasked<TData> = TData extends object ? UnwrapFragmentRefs<RemoveMaskedMarker<RemoveFragmentName<TData>>> : TData;
export type Unmasked<TData> = true extends IsAny<TData> ? TData : TData extends object ? UnwrapFragmentRefs<RemoveMaskedMarker<RemoveFragmentName<TData>>> : TData;

// Warning: (ae-forgotten-export) The symbol "CombineFragmentRefs" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
type UnwrapFragmentRefs<TData> = TData extends any ? string extends keyof NonNullable<TData> ? TData : " $fragmentRefs" extends keyof NonNullable<TData> ? TData extends {
" $fragmentRefs"?: infer FragmentRefs extends object;
} ? Prettify<{
[K in keyof TData as K extends " $fragmentRefs" ? never : K]: UnwrapFragmentRefs<TData[K]>;
} & CombineFragmentRefs<FragmentRefs>> : never : TData extends Array<infer TItem> ? Array<UnwrapFragmentRefs<TItem>> : TData extends object ? {
type UnwrapFragmentRefs<TData> = true extends IsAny<TData> ? TData : TData extends any ? string extends keyof TData ? TData : keyof TData extends never ? TData : TData extends {
" $fragmentRefs"?: infer FragmentRefs;
} ? UnwrapFragmentRefs<CombineIntersection<Omit<TData, " $fragmentRefs"> | RemoveFragmentName<NonNullable<NonNullable<FragmentRefs>[keyof NonNullable<FragmentRefs>]>>>> : TData extends Array<infer TItem> ? Array<UnwrapFragmentRefs<TItem>> : TData extends object ? {
[K in keyof TData]: UnwrapFragmentRefs<TData[K]>;
} : TData : never;

Expand Down
Loading

0 comments on commit d933def

Please sign in to comment.