Skip to content

Commit 2d1e3ea

Browse files
authored
enforce usage of declare namespace over namespace (#12784)
* enforce usage of `declare namespace` over `namespace` * refactor `EntityStore` runtime namespace * chores * formatting * adjustments * chore
1 parent 84d3e78 commit 2d1e3ea

24 files changed

+155
-160
lines changed

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

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,10 @@ export abstract class EntityStore implements NormalizedCache {
386386
replace(newData: NormalizedCacheObject | null): void;
387387
// (undocumented)
388388
retain(rootId: string): number;
389+
// Warning: (ae-forgotten-export) The symbol "Root" needs to be exported by the entry point index.d.ts
390+
//
391+
// (undocumented)
392+
static Root: typeof Root;
389393
// (undocumented)
390394
get supportsResultCaching(): boolean;
391395
// (undocumented)
@@ -396,30 +400,6 @@ export abstract class EntityStore implements NormalizedCache {
396400
toReference: ToReferenceFunction;
397401
}
398402

399-
// @public (undocumented)
400-
export namespace EntityStore {
401-
// (undocumented)
402-
export class Root extends EntityStore {
403-
constructor({ policies, resultCaching, seed, }: {
404-
policies: Policies;
405-
resultCaching?: boolean;
406-
seed?: NormalizedCacheObject;
407-
});
408-
// (undocumented)
409-
addLayer(layerId: string, replay: (layer: EntityStore) => any): Layer;
410-
// (undocumented)
411-
getStorage(): StorageType;
412-
// (undocumented)
413-
removeLayer(): Root;
414-
// (undocumented)
415-
readonly storageTrie: Trie<StorageType>;
416-
// Warning: (ae-forgotten-export) The symbol "Stump" needs to be exported by the entry point index.d.ts
417-
//
418-
// (undocumented)
419-
readonly stump: Stump;
420-
}
421-
}
422-
423403
// @public (undocumented)
424404
export interface FieldFunctionOptions<TArgs = Record<string, any>, TVariables = Record<string, any>> {
425405
// (undocumented)
@@ -873,6 +853,27 @@ export type ReadQueryOptions = {
873853

874854
export { Reference }
875855

856+
// @public (undocumented)
857+
class Root extends EntityStore {
858+
constructor({ policies, resultCaching, seed, }: {
859+
policies: Policies;
860+
resultCaching?: boolean;
861+
seed?: NormalizedCacheObject;
862+
});
863+
// (undocumented)
864+
addLayer(layerId: string, replay: (layer: EntityStore) => any): Layer;
865+
// (undocumented)
866+
getStorage(): StorageType;
867+
// (undocumented)
868+
removeLayer(): Root;
869+
// (undocumented)
870+
readonly storageTrie: Trie<StorageType>;
871+
// Warning: (ae-forgotten-export) The symbol "Stump" needs to be exported by the entry point index.d.ts
872+
//
873+
// (undocumented)
874+
readonly stump: Stump;
875+
}
876+
876877
// @public (undocumented)
877878
type SafeReadonly<T> = T extends object ? Readonly<T> : T;
878879

@@ -890,7 +891,7 @@ export { StoreValue }
890891

891892
// @public (undocumented)
892893
class Stump extends Layer {
893-
constructor(root: EntityStore.Root);
894+
constructor(root: Root);
894895
// (undocumented)
895896
merge(older: string | StoreObject, newer: string | StoreObject): void;
896897
// (undocumented)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,6 @@ namespace OverridableTypes {
749749
// (undocumented)
750750
return: this["arg1"];
751751
}
752-
{};
753752
}
754753

755754
export { parseAndCheckHttpResponse }
@@ -1067,7 +1066,7 @@ export type WatchQueryOptions<TVariables extends OperationVariables = OperationV
10671066

10681067
// Warnings were encountered during analysis:
10691068
//
1070-
// src/core/ApolloClient.ts:360:5 - (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts
1069+
// src/core/ApolloClient.ts:358:5 - (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts
10711070
// src/core/ObservableQuery.ts:359:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
10721071
// src/core/QueryManager.ts:175:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
10731072

.api-reports/api-report-link_persisted-queries.api.md

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import type { DocumentNode } from 'graphql';
99
import type { ErrorLike } from '@apollo/client';
1010
import type { FormattedExecutionResult } from 'graphql';
1111
import type { Operation } from '@apollo/client/link';
12-
import type { Prettify } from '@apollo/client/utilities/internal';
1312

1413
// @public (undocumented)
1514
interface BaseOptions {
@@ -21,14 +20,6 @@ interface BaseOptions {
2120
useGETForHashedQueries?: boolean;
2221
}
2322

24-
// @public (undocumented)
25-
type CallbackOptions = {
26-
error: ErrorLike;
27-
operation: Operation;
28-
meta: ErrorMeta;
29-
result?: FormattedExecutionResult;
30-
};
31-
3223
// @public @deprecated (undocumented)
3324
export const createPersistedQueryLink: (options: PersistedQueryLink.Options) => PersistedQueryLink;
3425

@@ -44,7 +35,21 @@ type GenerateHashFunction = (document: DocumentNode) => string | PromiseLike<str
4435
// @public (undocumented)
4536
export namespace PersistedQueryLink {
4637
// (undocumented)
47-
export type DisableFunctionOptions = Prettify<CallbackOptions>;
38+
export interface CallbackOptions {
39+
// (undocumented)
40+
error: ErrorLike;
41+
// Warning: (ae-forgotten-export) The symbol "ErrorMeta" needs to be exported by the entry point index.d.ts
42+
//
43+
// (undocumented)
44+
meta: ErrorMeta;
45+
// (undocumented)
46+
operation: Operation;
47+
// (undocumented)
48+
result?: FormattedExecutionResult;
49+
}
50+
// (undocumented)
51+
export interface DisableFunctionOptions extends CallbackOptions {
52+
}
4853
// (undocumented)
4954
export interface GenerateHashOptions extends BaseOptions {
5055
// Warning: (ae-forgotten-export) The symbol "GenerateHashFunction" needs to be exported by the entry point index.d.ts
@@ -56,10 +61,9 @@ export namespace PersistedQueryLink {
5661
}
5762
// (undocumented)
5863
export type Options = SHA256Options | GenerateHashOptions;
59-
// Warning: (ae-forgotten-export) The symbol "CallbackOptions" needs to be exported by the entry point index.d.ts
60-
//
6164
// (undocumented)
62-
export type RetryFunctionOptions = Prettify<CallbackOptions>;
65+
export interface RetryFunctionOptions extends CallbackOptions {
66+
}
6367
// Warning: (ae-forgotten-export) The symbol "BaseOptions" needs to be exported by the entry point index.d.ts
6468
//
6569
// (undocumented)
@@ -71,7 +75,6 @@ export namespace PersistedQueryLink {
7175
// (undocumented)
7276
sha256: SHA256Function;
7377
}
74-
{};
7578
}
7679

7780
// @public (undocumented)
@@ -87,10 +90,6 @@ type SHA256Function = (...args: any[]) => string | PromiseLike<string>;
8790
// @public (undocumented)
8891
export const VERSION = 1;
8992

90-
// Warnings were encountered during analysis:
91-
//
92-
// src/link/persisted-queries/index.ts:38:3 - (ae-forgotten-export) The symbol "ErrorMeta" needs to be exported by the entry point index.d.ts
93-
9493
// (No @packageDocumentation comment for this package)
9594

9695
```

.api-reports/api-report-masking.api.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ export namespace GraphQLCodegenDataMasking {
159159
// Warning: (ae-forgotten-export) The symbol "UnwrapFragmentRefs" needs to be exported by the entry point index.d.ts
160160
// Warning: (ae-forgotten-export) The symbol "RemoveFragmentName" needs to be exported by the entry point index.d.ts
161161
export type Unmasked<TData> = true extends IsAny<TData> ? TData : TData extends object ? true extends ContainsFragmentsRefs<TData> ? UnwrapFragmentRefs<RemoveMaskedMarker<RemoveFragmentName<TData>>> : TData : TData;
162-
{};
163162
}
164163

165164
// @public

.api-reports/api-report-react.api.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,6 @@ namespace OverridableTypes {
704704
// (undocumented)
705705
return: this["arg1"];
706706
}
707-
{};
708707
}
709708

710709
export { PreloadedQueryRef }
@@ -1866,17 +1865,17 @@ type WatchQueryFetchPolicy_2 = FetchPolicy | "cache-and-network" | "standby";
18661865

18671866
// Warnings were encountered during analysis:
18681867
//
1869-
// src/core/ApolloClient.ts:174:5 - (ae-forgotten-export) The symbol "MutationQueryReducersMap" needs to be exported by the entry point index.d.ts
1870-
// src/core/ApolloClient.ts:177:5 - (ae-forgotten-export) The symbol "NormalizedExecutionResult" needs to be exported by the entry point index.d.ts
1871-
// src/core/ApolloClient.ts:177:5 - (ae-forgotten-export) The symbol "InternalRefetchQueriesInclude" needs to be exported by the entry point index.d.ts
1872-
// src/core/ApolloClient.ts:187:5 - (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts
1873-
// src/core/ApolloClient.ts:190:5 - (ae-forgotten-export) The symbol "OnQueryUpdated" needs to be exported by the entry point index.d.ts
1874-
// src/core/ApolloClient.ts:193:5 - (ae-forgotten-export) The symbol "ErrorPolicy" needs to be exported by the entry point index.d.ts
1875-
// src/core/ApolloClient.ts:199:5 - (ae-forgotten-export) The symbol "MutationFetchPolicy" needs to be exported by the entry point index.d.ts
1876-
// src/core/ApolloClient.ts:236:5 - (ae-forgotten-export) The symbol "FetchPolicy" needs to be exported by the entry point index.d.ts
1877-
// src/core/ApolloClient.ts:357:5 - (ae-forgotten-export) The symbol "WatchQueryFetchPolicy_2" needs to be exported by the entry point index.d.ts
1878-
// src/core/ApolloClient.ts:360:5 - (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts
1879-
// src/core/ApolloClient.ts:372:5 - (ae-forgotten-export) The symbol "RefetchWritePolicy" needs to be exported by the entry point index.d.ts
1868+
// src/core/ApolloClient.ts:172:5 - (ae-forgotten-export) The symbol "MutationQueryReducersMap" needs to be exported by the entry point index.d.ts
1869+
// src/core/ApolloClient.ts:175:5 - (ae-forgotten-export) The symbol "NormalizedExecutionResult" needs to be exported by the entry point index.d.ts
1870+
// src/core/ApolloClient.ts:175:5 - (ae-forgotten-export) The symbol "InternalRefetchQueriesInclude" needs to be exported by the entry point index.d.ts
1871+
// src/core/ApolloClient.ts:185:5 - (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts
1872+
// src/core/ApolloClient.ts:188:5 - (ae-forgotten-export) The symbol "OnQueryUpdated" needs to be exported by the entry point index.d.ts
1873+
// src/core/ApolloClient.ts:191:5 - (ae-forgotten-export) The symbol "ErrorPolicy" needs to be exported by the entry point index.d.ts
1874+
// src/core/ApolloClient.ts:197:5 - (ae-forgotten-export) The symbol "MutationFetchPolicy" needs to be exported by the entry point index.d.ts
1875+
// src/core/ApolloClient.ts:234:5 - (ae-forgotten-export) The symbol "FetchPolicy" needs to be exported by the entry point index.d.ts
1876+
// src/core/ApolloClient.ts:355:5 - (ae-forgotten-export) The symbol "WatchQueryFetchPolicy_2" needs to be exported by the entry point index.d.ts
1877+
// src/core/ApolloClient.ts:358:5 - (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts
1878+
// src/core/ApolloClient.ts:370:5 - (ae-forgotten-export) The symbol "RefetchWritePolicy" needs to be exported by the entry point index.d.ts
18801879
// src/core/ObservableQuery.ts:236:5 - (ae-forgotten-export) The symbol "NetworkStatus" needs to be exported by the entry point index.d.ts
18811880
// src/core/ObservableQuery.ts:359:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
18821881
// src/core/QueryManager.ts:175:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts

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

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,10 @@ abstract class EntityStore implements NormalizedCache {
880880
replace(newData: NormalizedCacheObject | null): void;
881881
// (undocumented)
882882
retain(rootId: string): number;
883+
// Warning: (ae-forgotten-export) The symbol "Root" needs to be exported by the entry point index.d.ts
884+
//
885+
// (undocumented)
886+
static Root: typeof Root;
883887
// (undocumented)
884888
get supportsResultCaching(): boolean;
885889
// (undocumented)
@@ -890,30 +894,6 @@ abstract class EntityStore implements NormalizedCache {
890894
toReference: ToReferenceFunction;
891895
}
892896

893-
// @public (undocumented)
894-
namespace EntityStore {
895-
// (undocumented)
896-
class Root extends EntityStore {
897-
constructor({ policies, resultCaching, seed, }: {
898-
policies: Policies;
899-
resultCaching?: boolean;
900-
seed?: NormalizedCacheObject;
901-
});
902-
// (undocumented)
903-
addLayer(layerId: string, replay: (layer: EntityStore) => any): Layer;
904-
// (undocumented)
905-
getStorage(): StorageType;
906-
// (undocumented)
907-
removeLayer(): Root;
908-
// (undocumented)
909-
readonly storageTrie: Trie<StorageType>;
910-
// Warning: (ae-forgotten-export) The symbol "Stump" needs to be exported by the entry point index.d.ts
911-
//
912-
// (undocumented)
913-
readonly stump: Stump;
914-
}
915-
}
916-
917897
// @public
918898
export interface ErrorLike {
919899
// (undocumented)
@@ -1219,7 +1199,6 @@ namespace GraphQLCodegenDataMasking {
12191199
// Warning: (ae-forgotten-export) The symbol "UnwrapFragmentRefs" needs to be exported by the entry point index.d.ts
12201200
// Warning: (ae-forgotten-export) The symbol "RemoveFragmentName" needs to be exported by the entry point index.d.ts
12211201
type Unmasked<TData> = true extends IsAny<TData> ? TData : TData extends object ? true extends ContainsFragmentsRefs<TData> ? UnwrapFragmentRefs<RemoveMaskedMarker<RemoveFragmentName<TData>>> : TData : TData;
1222-
{};
12231202
}
12241203

12251204
// @public (undocumented)
@@ -2123,7 +2102,6 @@ namespace OverridableTypes {
21232102
// (undocumented)
21242103
return: this["arg1"];
21252104
}
2126-
{};
21272105
}
21282106

21292107
// @public (undocumented)
@@ -2446,6 +2424,27 @@ export function rewriteURIForGET(chosenURI: string, body: HttpLink.Body): {
24462424
parseError?: undefined;
24472425
};
24482426

2427+
// @public (undocumented)
2428+
class Root extends EntityStore {
2429+
constructor({ policies, resultCaching, seed, }: {
2430+
policies: Policies;
2431+
resultCaching?: boolean;
2432+
seed?: NormalizedCacheObject;
2433+
});
2434+
// (undocumented)
2435+
addLayer(layerId: string, replay: (layer: EntityStore) => any): Layer;
2436+
// (undocumented)
2437+
getStorage(): StorageType;
2438+
// (undocumented)
2439+
removeLayer(): Root;
2440+
// (undocumented)
2441+
readonly storageTrie: Trie<StorageType>;
2442+
// Warning: (ae-forgotten-export) The symbol "Stump" needs to be exported by the entry point index.d.ts
2443+
//
2444+
// (undocumented)
2445+
readonly stump: Stump;
2446+
}
2447+
24492448
// @public (undocumented)
24502449
type SafeReadonly<T> = T extends object ? Readonly<T> : T;
24512450

@@ -2538,7 +2537,7 @@ export type StoreValue = number | string | string[] | Reference | Reference[] |
25382537

25392538
// @public (undocumented)
25402539
class Stump extends Layer {
2541-
constructor(root: EntityStore.Root);
2540+
constructor(root: Root);
25422541
// (undocumented)
25432542
merge(older: string | StoreObject, newer: string | StoreObject): void;
25442543
// (undocumented)
@@ -2741,8 +2740,8 @@ interface WriteContext extends ReadMergeModifyContext {
27412740
// src/cache/inmemory/policies.ts:166:3 - (ae-forgotten-export) The symbol "KeySpecifier" needs to be exported by the entry point index.d.ts
27422741
// src/cache/inmemory/policies.ts:166:3 - (ae-forgotten-export) The symbol "KeyArgsFunction" needs to be exported by the entry point index.d.ts
27432742
// src/cache/inmemory/types.ts:134:3 - (ae-forgotten-export) The symbol "KeyFieldsFunction" needs to be exported by the entry point index.d.ts
2744-
// src/core/ApolloClient.ts:166:5 - (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
2745-
// src/core/ApolloClient.ts:360:5 - (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts
2743+
// src/core/ApolloClient.ts:164:5 - (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
2744+
// src/core/ApolloClient.ts:358:5 - (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts
27462745
// src/core/ObservableQuery.ts:359:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
27472746
// src/core/QueryManager.ts:175:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
27482747
// src/local-state/LocalState.ts:140:5 - (ae-forgotten-export) The symbol "LocalState" needs to be exported by the entry point index.d.ts

.size-limits.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 43823,
3-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 38816,
4-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 33459,
5-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 27742
2+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 43844,
3+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 38842,
4+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 33439,
5+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 27709
66
}

eslint.config.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ export default [
118118
fixStyle: "separate-type-imports",
119119
},
120120
],
121+
"@typescript-eslint/no-namespace": [
122+
"error",
123+
{
124+
allowDeclarations: true,
125+
},
126+
],
121127
},
122128
},
123129
...fixupConfigRules(compat.extends("plugin:react-hooks/recommended")).map(

src/cache/core/types/Cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { ApolloCache } from "../cache.js";
66
import type { AllFieldsModifier, Modifiers } from "./common.js";
77
import { DataProxy } from "./DataProxy.js";
88

9-
export namespace Cache {
9+
export declare namespace Cache {
1010
export type WatchCallback<TData = unknown> = (
1111
diff: Cache.DiffResult<TData>,
1212
lastDiff?: Cache.DiffResult<TData>

src/cache/core/types/DataProxy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import type { TypedDocumentNode } from "@graphql-typed-document-node/core";
22
import type { DocumentNode } from "graphql"; // ignore-comment eslint-disable-line import/no-extraneous-dependencies, import/no-unresolved
33

4-
import type { OperationVariables, DataValue } from "@apollo/client";
4+
import type { DataValue, OperationVariables } from "@apollo/client";
55
import type { Unmasked } from "@apollo/client/masking";
66
import type { Reference } from "@apollo/client/utilities";
77

88
import type { MissingFieldError } from "./common.js";
99

10-
export namespace DataProxy {
10+
export declare namespace DataProxy {
1111
export interface Query<TVariables, TData> {
1212
/**
1313
* The GraphQL query shape to be used constructed using the `gql` template

0 commit comments

Comments
 (0)