Skip to content

Commit d933def

Browse files
authored
Handle additional cases in unmasked types (#12154)
1 parent f4d82c8 commit d933def

33 files changed

+2587
-561
lines changed

.api-reports/api-report-cache.api.md

+76-19
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,25 @@ export const canonicalStringify: ((value: any) => string) & {
216216
// @public (undocumented)
217217
type CanReadFunction = (value: StoreValue) => boolean;
218218

219-
// Warning: (ae-forgotten-export) The symbol "UnionToIntersection" needs to be exported by the entry point index.d.ts
220-
// Warning: (ae-forgotten-export) The symbol "UnwrapFragmentRefs" needs to be exported by the entry point index.d.ts
221-
// Warning: (ae-forgotten-export) The symbol "RemoveFragmentName" needs to be exported by the entry point index.d.ts
219+
// Warning: (ae-forgotten-export) The symbol "Prettify" needs to be exported by the entry point index.d.ts
220+
// Warning: (ae-forgotten-export) The symbol "MergeUnions" needs to be exported by the entry point index.d.ts
221+
// Warning: (ae-forgotten-export) The symbol "ExtractByMatchingTypeNames" needs to be exported by the entry point index.d.ts
222222
//
223-
// @public (undocumented)
224-
type CombineFragmentRefs<FragmentRefs extends Record<string, any>> = UnionToIntersection<{
225-
[K in keyof FragmentRefs]-?: UnwrapFragmentRefs<RemoveFragmentName<FragmentRefs[K]>>;
226-
}[keyof FragmentRefs]>;
223+
// @public
224+
type CombineByTypeName<T extends {
225+
__typename?: string;
226+
}> = {
227+
[TypeName in NonNullable<T["__typename"]>]: Prettify<MergeUnions<ExtractByMatchingTypeNames<T, TypeName>>>;
228+
}[NonNullable<T["__typename"]>];
229+
230+
// Warning: (ae-forgotten-export) The symbol "CombineByTypeName" needs to be exported by the entry point index.d.ts
231+
//
232+
// @public
233+
type CombineIntersection<T> = Exclude<T, {
234+
__typename?: string;
235+
}> | CombineByTypeName<Extract<T, {
236+
__typename?: string;
237+
}>>;
227238

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

366+
// @public (undocumented)
367+
type DistributedRequiredExclude<T, U> = T extends any ? Required<T> extends Required<U> ? Required<U> extends Required<T> ? never : T : T : T;
368+
355369
// @public (undocumented)
356370
export abstract class EntityStore implements NormalizedCache {
357371
constructor(policies: Policies, group: CacheGroup);
@@ -448,6 +462,13 @@ export namespace EntityStore {
448462
}
449463
}
450464

465+
// @public
466+
type ExtractByMatchingTypeNames<Union extends {
467+
__typename?: string;
468+
}, TypeName extends string> = Union extends any ? TypeName extends NonNullable<Union["__typename"]> ? Omit<Union, "__typename"> & {
469+
[K in keyof Union as K extends "__typename" ? K : never]: TypeName;
470+
} : never : never;
471+
451472
// @public (undocumented)
452473
export interface FieldFunctionOptions<TArgs = Record<string, any>, TVars = Record<string, any>> {
453474
// (undocumented)
@@ -677,6 +698,9 @@ interface InvalidateModifier {
677698
// @public (undocumented)
678699
const _invalidateModifier: unique symbol;
679700

701+
// @public (undocumented)
702+
type IsAny<T> = 0 extends 1 & T ? true : false;
703+
680704
// @public (undocumented)
681705
export function isReference(obj: any): obj is Reference;
682706

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

736-
// Warning: (ae-forgotten-export) The symbol "Prettify" needs to be exported by the entry point index.d.ts
760+
// Warning: (ae-forgotten-export) The symbol "IsAny" needs to be exported by the entry point index.d.ts
737761
// Warning: (ae-forgotten-export) The symbol "RemoveMaskedMarker" needs to be exported by the entry point index.d.ts
738762
// Warning: (ae-forgotten-export) The symbol "DataMasking" needs to be exported by the entry point index.d.ts
739763
// Warning: (ae-forgotten-export) The symbol "ContainsFragmentsRefs" needs to be exported by the entry point index.d.ts
740764
//
741765
// @public
742-
type MaybeMasked<TData> = TData extends {
766+
type MaybeMasked<TData> = TData extends any ? true extends IsAny<TData> ? TData : TData extends {
743767
__masked?: true;
744768
} ? Prettify<RemoveMaskedMarker<TData>> : DataMasking extends {
745769
enabled: true;
746-
} ? TData : true extends ContainsFragmentsRefs<TData> ? Unmasked<TData> : TData;
770+
} ? TData : true extends ContainsFragmentsRefs<TData> ? Unmasked<TData> : TData : never;
747771

748772
// @public (undocumented)
749773
export interface MergeInfo {
@@ -755,6 +779,19 @@ export interface MergeInfo {
755779
typename: string | undefined;
756780
}
757781

782+
// Warning: (ae-forgotten-export) The symbol "CombineIntersection" needs to be exported by the entry point index.d.ts
783+
//
784+
// @public (undocumented)
785+
type MergeObjects<T, U> = Prettify<{
786+
[k in keyof T]: k extends keyof U ? [
787+
NonNullable<T[k]>,
788+
NonNullable<U[k]>
789+
] extends ([
790+
infer TK extends object,
791+
infer UK extends object
792+
]) ? 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];
793+
} & Pick<U, Exclude<keyof U, keyof T>>>;
794+
758795
// @public (undocumented)
759796
type MergeObjectsFunction = <T extends StoreObject | Reference>(existing: T, incoming: T) => T;
760797

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

806+
// Warning: (ae-forgotten-export) The symbol "MergeUnionsAcc" needs to be exported by the entry point index.d.ts
807+
// Warning: (ae-forgotten-export) The symbol "takeOneFromUnion" needs to be exported by the entry point index.d.ts
808+
//
809+
// @public (undocumented)
810+
type MergeUnions<TUnion> = MergeUnionsAcc<TUnion, takeOneFromUnion<TUnion>, never>;
811+
812+
// Warning: (ae-forgotten-export) The symbol "DistributedRequiredExclude" needs to be exported by the entry point index.d.ts
813+
// Warning: (ae-forgotten-export) The symbol "MergeObjects" needs to be exported by the entry point index.d.ts
814+
//
815+
// @public (undocumented)
816+
type MergeUnionsAcc<TUnion, Curr, Merged> = [
817+
Curr
818+
] extends [never] ? Merged : MergeUnionsAcc<DistributedRequiredExclude<TUnion, Curr>, takeOneFromUnion<DistributedRequiredExclude<TUnion, Curr>>, [
819+
Merged
820+
] extends [never] ? Curr : MergeObjects<Curr, Merged>>;
821+
769822
// @public (undocumented)
770823
export class MissingFieldError extends Error {
771824
constructor(message: string, path: MissingTree | Array<string | number>, query: DocumentNode, variables?: Record<string, any> | undefined);
@@ -1016,6 +1069,11 @@ class Stump extends Layer {
10161069
removeLayer(): this;
10171070
}
10181071

1072+
// Warning: (ae-forgotten-export) The symbol "unionToIntersection" needs to be exported by the entry point index.d.ts
1073+
//
1074+
// @public (undocumented)
1075+
type takeOneFromUnion<T> = unionToIntersection<T extends T ? (x: T) => 0 : never> extends ((x: infer U) => 0) ? U : never;
1076+
10191077
// @public (undocumented)
10201078
type ToReferenceFunction = (objOrIdOrRef: StoreObject | string | Reference, mergeIntoStore?: boolean) => Reference | undefined;
10211079

@@ -1040,19 +1098,18 @@ export type TypePolicy = {
10401098
};
10411099

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

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

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

.api-reports/api-report-core.api.md

+79-22
Original file line numberDiff line numberDiff line change
@@ -432,14 +432,25 @@ export type ClientParseError = InvariantError & {
432432
parseError: Error;
433433
};
434434

435-
// Warning: (ae-forgotten-export) The symbol "UnionToIntersection" needs to be exported by the entry point index.d.ts
436-
// Warning: (ae-forgotten-export) The symbol "UnwrapFragmentRefs" needs to be exported by the entry point index.d.ts
437-
// Warning: (ae-forgotten-export) The symbol "RemoveFragmentName" needs to be exported by the entry point index.d.ts
435+
// Warning: (ae-forgotten-export) The symbol "Prettify" needs to be exported by the entry point index.d.ts
436+
// Warning: (ae-forgotten-export) The symbol "MergeUnions" needs to be exported by the entry point index.d.ts
437+
// Warning: (ae-forgotten-export) The symbol "ExtractByMatchingTypeNames" needs to be exported by the entry point index.d.ts
438438
//
439-
// @public (undocumented)
440-
type CombineFragmentRefs<FragmentRefs extends Record<string, any>> = UnionToIntersection<{
441-
[K in keyof FragmentRefs]-?: UnwrapFragmentRefs<RemoveFragmentName<FragmentRefs[K]>>;
442-
}[keyof FragmentRefs]>;
439+
// @public
440+
type CombineByTypeName<T extends {
441+
__typename?: string;
442+
}> = {
443+
[TypeName in NonNullable<T["__typename"]>]: Prettify<MergeUnions<ExtractByMatchingTypeNames<T, TypeName>>>;
444+
}[NonNullable<T["__typename"]>];
445+
446+
// Warning: (ae-forgotten-export) The symbol "CombineByTypeName" needs to be exported by the entry point index.d.ts
447+
//
448+
// @public
449+
type CombineIntersection<T> = Exclude<T, {
450+
__typename?: string;
451+
}> | CombineByTypeName<Extract<T, {
452+
__typename?: string;
453+
}>>;
443454

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

634645
export { disableFragmentWarnings }
635646

647+
// @public (undocumented)
648+
type DistributedRequiredExclude<T, U> = T extends any ? Required<T> extends Required<U> ? Required<U> extends Required<T> ? never : T : T : T;
649+
636650
export { DocumentNode }
637651

638652
// @public (undocumented)
@@ -811,6 +825,13 @@ interface ExecutionPatchResultBase {
811825
hasNext?: boolean;
812826
}
813827

828+
// @public
829+
type ExtractByMatchingTypeNames<Union extends {
830+
__typename?: string;
831+
}, TypeName extends string> = Union extends any ? TypeName extends NonNullable<Union["__typename"]> ? Omit<Union, "__typename"> & {
832+
[K in keyof Union as K extends "__typename" ? K : never]: TypeName;
833+
} : never : never;
834+
814835
// @public (undocumented)
815836
export const fallbackHttpConfig: {
816837
http: HttpQueryOptions;
@@ -1227,6 +1248,9 @@ interface InvalidateModifier {
12271248
// @public (undocumented)
12281249
const _invalidateModifier: unique symbol;
12291250

1251+
// @public (undocumented)
1252+
type IsAny<T> = 0 extends 1 & T ? true : false;
1253+
12301254
// @public (undocumented)
12311255
export function isApolloError(err: Error): err is ApolloError;
12321256

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

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

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

1380-
// Warning: (ae-forgotten-export) The symbol "Prettify" needs to be exported by the entry point index.d.ts
1404+
// Warning: (ae-forgotten-export) The symbol "IsAny" needs to be exported by the entry point index.d.ts
13811405
// Warning: (ae-forgotten-export) The symbol "RemoveMaskedMarker" needs to be exported by the entry point index.d.ts
13821406
// Warning: (ae-forgotten-export) The symbol "ContainsFragmentsRefs" needs to be exported by the entry point index.d.ts
13831407
//
13841408
// @public
1385-
export type MaybeMasked<TData> = TData extends {
1409+
export type MaybeMasked<TData> = TData extends any ? true extends IsAny<TData> ? TData : TData extends {
13861410
__masked?: true;
13871411
} ? Prettify<RemoveMaskedMarker<TData>> : DataMasking extends {
13881412
enabled: true;
1389-
} ? TData : true extends ContainsFragmentsRefs<TData> ? Unmasked<TData> : TData;
1413+
} ? TData : true extends ContainsFragmentsRefs<TData> ? Unmasked<TData> : TData : never;
13901414

13911415
// @public (undocumented)
13921416
export interface MergeInfo {
@@ -1398,6 +1422,19 @@ export interface MergeInfo {
13981422
typename: string | undefined;
13991423
}
14001424

1425+
// Warning: (ae-forgotten-export) The symbol "CombineIntersection" needs to be exported by the entry point index.d.ts
1426+
//
1427+
// @public (undocumented)
1428+
type MergeObjects<T, U> = Prettify<{
1429+
[k in keyof T]: k extends keyof U ? [
1430+
NonNullable<T[k]>,
1431+
NonNullable<U[k]>
1432+
] extends ([
1433+
infer TK extends object,
1434+
infer UK extends object
1435+
]) ? 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];
1436+
} & Pick<U, Exclude<keyof U, keyof T>>>;
1437+
14011438
// @public (undocumented)
14021439
type MergeObjectsFunction = <T extends StoreObject | Reference>(existing: T, incoming: T) => T;
14031440

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

1454+
// Warning: (ae-forgotten-export) The symbol "MergeUnionsAcc" needs to be exported by the entry point index.d.ts
1455+
// Warning: (ae-forgotten-export) The symbol "takeOneFromUnion" needs to be exported by the entry point index.d.ts
1456+
//
1457+
// @public (undocumented)
1458+
type MergeUnions<TUnion> = MergeUnionsAcc<TUnion, takeOneFromUnion<TUnion>, never>;
1459+
1460+
// Warning: (ae-forgotten-export) The symbol "DistributedRequiredExclude" needs to be exported by the entry point index.d.ts
1461+
// Warning: (ae-forgotten-export) The symbol "MergeObjects" needs to be exported by the entry point index.d.ts
1462+
//
1463+
// @public (undocumented)
1464+
type MergeUnionsAcc<TUnion, Curr, Merged> = [
1465+
Curr
1466+
] extends [never] ? Merged : MergeUnionsAcc<DistributedRequiredExclude<TUnion, Curr>, takeOneFromUnion<DistributedRequiredExclude<TUnion, Curr>>, [
1467+
Merged
1468+
] extends [never] ? Curr : MergeObjects<Curr, Merged>>;
1469+
14171470
// @public (undocumented)
14181471
export type MethodKeys<T> = {
14191472
[P in keyof T]: T[P] extends Function ? P : never;
@@ -2276,6 +2329,11 @@ export interface SubscriptionOptions<TVariables = OperationVariables, TData = an
22762329
variables?: TVariables;
22772330
}
22782331

2332+
// Warning: (ae-forgotten-export) The symbol "unionToIntersection" needs to be exported by the entry point index.d.ts
2333+
//
2334+
// @public (undocumented)
2335+
type takeOneFromUnion<T> = unionToIntersection<T extends T ? (x: T) => 0 : never> extends ((x: infer U) => 0) ? U : never;
2336+
22792337
// @public (undocumented)
22802338
export const throwServerError: (response: Response, result: any, message: string) => never;
22812339

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

23362394
// @public (undocumented)
2337-
type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
2395+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
23382396

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

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

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

0 commit comments

Comments
 (0)