@apollo/client 4.0.9 → 4.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/__cjs/cache/core/cache.cjs +1 -1
  3. package/__cjs/cache/inmemory/entityStore.cjs +3 -3
  4. package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
  5. package/__cjs/cache/inmemory/policies.cjs +4 -4
  6. package/__cjs/cache/inmemory/policies.cjs.map +1 -1
  7. package/__cjs/cache/inmemory/readFromStore.cjs +2 -2
  8. package/__cjs/cache/inmemory/writeToStore.cjs +4 -4
  9. package/__cjs/core/ApolloClient.cjs.map +1 -1
  10. package/__cjs/core/ApolloClient.d.cts +16 -1
  11. package/__cjs/core/ObservableQuery.cjs +18 -7
  12. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  13. package/__cjs/core/ObservableQuery.d.cts +1 -0
  14. package/__cjs/core/QueryManager.cjs +13 -13
  15. package/__cjs/core/QueryManager.cjs.map +1 -1
  16. package/__cjs/invariantErrorCodes.cjs +39 -33
  17. package/__cjs/link/http/parseAndCheckHttpResponse.cjs +1 -1
  18. package/__cjs/link/http/parseAndCheckHttpResponse.cjs.map +1 -1
  19. package/__cjs/link/schema/index.cjs +1 -1
  20. package/__cjs/link/schema/index.cjs.map +1 -1
  21. package/__cjs/link/schema/index.d.cts +1 -1
  22. package/__cjs/react/hooks/useLazyQuery.cjs +1 -0
  23. package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
  24. package/__cjs/react/hooks/useQuery.cjs +7 -4
  25. package/__cjs/react/hooks/useQuery.cjs.map +1 -1
  26. package/__cjs/react/hooks/useSuspenseQuery.cjs +2 -0
  27. package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
  28. package/__cjs/utilities/internal/checkDocument.cjs +2 -4
  29. package/__cjs/utilities/internal/checkDocument.cjs.map +1 -1
  30. package/__cjs/utilities/internal/constants.cjs +13 -0
  31. package/__cjs/utilities/internal/constants.cjs.map +1 -0
  32. package/__cjs/utilities/internal/constants.d.cts +10 -0
  33. package/__cjs/utilities/internal/index.cjs +4 -2
  34. package/__cjs/utilities/internal/index.cjs.map +1 -1
  35. package/__cjs/utilities/internal/index.d.cts +1 -0
  36. package/__cjs/utilities/internal/memoize.cjs +31 -0
  37. package/__cjs/utilities/internal/memoize.cjs.map +1 -0
  38. package/__cjs/utilities/internal/memoize.d.cts +7 -0
  39. package/__cjs/version.cjs +1 -1
  40. package/__cjs/version.cjs.map +1 -1
  41. package/cache/core/cache.js +1 -1
  42. package/cache/inmemory/entityStore.js +3 -3
  43. package/cache/inmemory/key-extractor.js +1 -1
  44. package/cache/inmemory/policies.js +4 -4
  45. package/cache/inmemory/policies.js.map +1 -1
  46. package/cache/inmemory/readFromStore.js +2 -2
  47. package/cache/inmemory/writeToStore.js +4 -4
  48. package/core/ApolloClient.d.ts +16 -1
  49. package/core/ApolloClient.js.map +1 -1
  50. package/core/ObservableQuery.d.ts +1 -0
  51. package/core/ObservableQuery.js +19 -8
  52. package/core/ObservableQuery.js.map +1 -1
  53. package/core/QueryManager.js +13 -13
  54. package/core/QueryManager.js.map +1 -1
  55. package/invariantErrorCodes.js +39 -33
  56. package/link/http/parseAndCheckHttpResponse.js +1 -1
  57. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  58. package/link/schema/index.d.ts +1 -1
  59. package/link/schema/index.js +1 -1
  60. package/link/schema/index.js.map +1 -1
  61. package/package.json +1 -1
  62. package/react/hooks/useLazyQuery.js +2 -1
  63. package/react/hooks/useLazyQuery.js.map +1 -1
  64. package/react/hooks/useQuery.js +8 -5
  65. package/react/hooks/useQuery.js.map +1 -1
  66. package/react/hooks/useSuspenseQuery.js +2 -0
  67. package/react/hooks/useSuspenseQuery.js.map +1 -1
  68. package/react/hooks-compiled/useLazyQuery.js +2 -1
  69. package/react/hooks-compiled/useLazyQuery.js.map +1 -1
  70. package/react/hooks-compiled/useQuery.js +9 -5
  71. package/react/hooks-compiled/useQuery.js.map +1 -1
  72. package/react/hooks-compiled/useSuspenseQuery.js +3 -1
  73. package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
  74. package/utilities/internal/checkDocument.js +2 -4
  75. package/utilities/internal/checkDocument.js.map +1 -1
  76. package/utilities/internal/constants.d.ts +10 -0
  77. package/utilities/internal/constants.js +10 -0
  78. package/utilities/internal/constants.js.map +1 -0
  79. package/utilities/internal/index.d.ts +1 -0
  80. package/utilities/internal/index.js +1 -0
  81. package/utilities/internal/index.js.map +1 -1
  82. package/utilities/internal/memoize.d.ts +7 -0
  83. package/utilities/internal/memoize.js +28 -0
  84. package/utilities/internal/memoize.js.map +1 -0
  85. package/version.js +1 -1
  86. package/version.js.map +1 -1
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.memoize = memoize;
4
+ const trie_1 = require("@wry/trie");
5
+ const caches_js_1 = require("./caches.cjs");
6
+ /**
7
+ * Naive alternative to `wrap` without any dependency tracking, potentially avoiding resulting memory leaks.
8
+ */
9
+ function memoize(fn, { max }) {
10
+ const keys = new trie_1.Trie(true);
11
+ const cache = new caches_js_1.AutoCleanedWeakCache(max);
12
+ return (...args) => {
13
+ const cacheKey = keys.lookupArray(args);
14
+ const cached = cache.get(cacheKey);
15
+ if (cached) {
16
+ if (cached.error) {
17
+ throw cached.error;
18
+ }
19
+ return cached.result;
20
+ }
21
+ const entry = cache.set(cacheKey, {});
22
+ try {
23
+ return (entry.result = fn(...args));
24
+ }
25
+ catch (error) {
26
+ entry.error = error;
27
+ throw error;
28
+ }
29
+ };
30
+ }
31
+ //# sourceMappingURL=memoize.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memoize.cjs","sources":["../../../../src/utilities/internal/memoize.ts"],"sourcesContent":["import { Trie } from \"@wry/trie\";\n\nimport { AutoCleanedWeakCache } from \"./caches.js\";\n\n/**\n * Naive alternative to `wrap` without any dependency tracking, potentially avoiding resulting memory leaks.\n */\nexport function memoize<TArgs extends any[], TResult>(\n fn: (...args: TArgs) => TResult,\n { max }: { max: number }\n): (...args: TArgs) => TResult {\n const keys = new Trie<{}>(true);\n const cache = new AutoCleanedWeakCache<\n {},\n { result?: TResult; error?: unknown }\n >(max);\n\n return (...args: TArgs): TResult => {\n const cacheKey = keys.lookupArray(args);\n const cached = cache.get(cacheKey);\n if (cached) {\n if (cached.error) {\n throw cached.error;\n }\n return cached.result!;\n }\n\n const entry = cache.set(cacheKey, {});\n try {\n return (entry.result = fn(...args));\n } catch (error) {\n entry.error = error;\n throw error;\n }\n };\n}\n"],"names":[],"mappings":";;AAOA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AAPA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AAEA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,eAAA,CAAA;AAEA,CAAA,CAAA;;CAEA,CAAA;AACA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAgB,CAAhB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAuB,CACrB,CADF,CACiC,EAC/B,EAAE,CAFJ,CAAA,EAAA,CAE0B,EAF1B;IAIE,CAAF,CAAA,CAAA,CAAA,EAAQ,CAAR,CAAA,CAAA,EAAA,EAAe,CAAf,CAAA,EAAmB,CAAnB,CAAA,CAAA,CAAA,CAAA,CA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A,CAAN,CAAA,CAAA,CAAA,CAAA,EAAa,CAAb,CAAA,CAAA,CAAA,CAAA,CAAmB,CAAC,CAApB,CAAA,CAAA,CAAA,CAAA,CAA2B;QACvB;QAEA,CAAJ,CAAA,CAAA,CAAA,EAAU,CAAV,CAAA,CAAA,CAAA,EAAA,EAAkB,CAAlB,CAAA,CAAA,CAAA,CAAuB,CAAC,CAAxB,CAAA,CAA2B,CAAC,CAA5B,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAoC,EAAE,CAAtC,CAAwC,CAAC;QACrC,CAAJ,CAAA,EAAQ;YACF,CAAN,CAAA,CAAA,CAAA,CAAA,EAAa,CAAC,CAAd,CAAA,CAAA,CAAA,CAAmB,CAAC,CAApB,CAAA,CAAA,CAAA,CAAA,EAAA,EAA6B,CAA7B,CAA+B,CAAC,CAAhC,CAAA,CAAmC,CAAnC,CAAA,CAAA,CAAuC,CAAC,CAAC;QACrC;QAAE,CAAN,CAAA,CAAA,CAAA,EAAA,CAAa,CAAb,CAAA,CAAA,CAAA,CAAkB,EAAE;YACd,CAAN,CAAA,CAAA,CAAA,CAAW,CAAC,CAAZ,CAAA,CAAA,CAAA,EAAA,EAAoB,CAApB,CAAA,CAAA,CAAA,CAAyB;YACnB,CAAN,CAAA,CAAA,CAAA,EAAY,CAAZ,CAAA,CAAA,CAAA,CAAiB;QACb;IACF,CAAC;AACH;"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Naive alternative to `wrap` without any dependency tracking, potentially avoiding resulting memory leaks.
3
+ */
4
+ export declare function memoize<TArgs extends any[], TResult>(fn: (...args: TArgs) => TResult, { max }: {
5
+ max: number;
6
+ }): (...args: TArgs) => TResult;
7
+ //# sourceMappingURL=memoize.d.cts.map
package/__cjs/version.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.build = exports.version = void 0;
4
- exports.version = "4.0.9";
4
+ exports.version = "4.0.11";
5
5
  exports.build = "cjs";
6
6
  //# sourceMappingURL=version.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.cjs","sources":["../../src/version.ts"],"sourcesContent":["export const version = \"local\" as string;\nexport const build = \"source\" as \"source\" | \"esm\" | \"cjs\";\n"],"names":[],"mappings":";;;AAAa,CAAb,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAa,CAAb,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,SAAwC;AAC3B,CAAb,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAa,CAAb,CAAA,CAAA,CAAA,EAAA,OAAyD;"}
1
+ {"version":3,"file":"version.cjs","sources":["../../src/version.ts"],"sourcesContent":["export const version = \"local\" as string;\nexport const build = \"source\" as \"source\" | \"esm\" | \"cjs\";\n"],"names":[],"mappings":";;;AAAa,CAAb,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAa,CAAb,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,UAAwC;AAC3B,CAAb,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAa,CAAb,CAAA,CAAA,CAAA,EAAA,OAAyD;"}
@@ -88,7 +88,7 @@ export class ApolloCache {
88
88
  if (__DEV__) {
89
89
  const actualFragmentName = fragmentName || getFragmentDefinition(fragment).name.value;
90
90
  if (!id) {
91
- __DEV__ && invariant.warn(109, actualFragmentName);
91
+ __DEV__ && invariant.warn(110, actualFragmentName);
92
92
  }
93
93
  }
94
94
  const diffOptions = {
@@ -73,7 +73,7 @@ export class EntityStore {
73
73
  // then there are no fields to be merged, so we're done.
74
74
  if (!incoming)
75
75
  return;
76
- invariant(typeof dataId === "string", 95);
76
+ invariant(typeof dataId === "string", 96);
77
77
  const merged = new DeepMerger(storeObjectReconciler).merge(existing, incoming);
78
78
  // Even if merged === existing, existing may have come from a lower
79
79
  // layer, so we always need to set this.data[dataId] on this level.
@@ -173,7 +173,7 @@ export class EntityStore {
173
173
  if (__DEV__) {
174
174
  const checkReference = (ref) => {
175
175
  if (this.lookup(ref.__ref) === undefined) {
176
- __DEV__ && invariant.warn(96, ref);
176
+ __DEV__ && invariant.warn(97, ref);
177
177
  return true;
178
178
  }
179
179
  };
@@ -202,7 +202,7 @@ export class EntityStore {
202
202
  }
203
203
  }
204
204
  if (seenReference && someNonReference !== undefined) {
205
- __DEV__ && invariant.warn(97, someNonReference);
205
+ __DEV__ && invariant.warn(98, someNonReference);
206
206
  break;
207
207
  }
208
208
  }
@@ -34,7 +34,7 @@ export function keyFieldsFnFromSpecifier(specifier) {
34
34
  // context.readField for this extraction.
35
35
  extracted = extractKeyPath(object, schemaKeyPath, extractKey);
36
36
  }
37
- invariant(extracted !== void 0, 98, schemaKeyPath.join("."), object);
37
+ invariant(extracted !== void 0, 99, schemaKeyPath.join("."), object);
38
38
  return extracted;
39
39
  }));
40
40
  return `${context.typename}:${JSON.stringify(keyObject)}`;
@@ -204,7 +204,7 @@ export class Policies {
204
204
  const rootId = "ROOT_" + which.toUpperCase();
205
205
  const old = this.rootTypenamesById[rootId];
206
206
  if (typename !== old) {
207
- invariant(!old || old === which, 99, which);
207
+ invariant(!old || old === which, 100, which);
208
208
  // First, delete any old __typename associated with this rootId from
209
209
  // rootIdsByTypename.
210
210
  if (old)
@@ -347,7 +347,7 @@ export class Policies {
347
347
  if (supertypeSet.has(supertype)) {
348
348
  if (!typenameSupertypeSet.has(supertype)) {
349
349
  if (checkingFuzzySubtypes) {
350
- __DEV__ && invariant.warn(100, typename, supertype);
350
+ __DEV__ && invariant.warn(101, typename, supertype);
351
351
  }
352
352
  // Record positive results for faster future lookup.
353
353
  // Unfortunately, we cannot safely cache negative results,
@@ -557,7 +557,7 @@ export function normalizeReadFieldOptions(readFieldArgs, objectOrReference, vari
557
557
  }
558
558
  }
559
559
  if (__DEV__ && options.from === void 0) {
560
- __DEV__ && invariant.warn(101, stringifyForDisplay(Array.from(readFieldArgs)));
560
+ __DEV__ && invariant.warn(102, stringifyForDisplay(Array.from(readFieldArgs)));
561
561
  }
562
562
  if (void 0 === options.variables) {
563
563
  options.variables = variables;
@@ -567,7 +567,7 @@ export function normalizeReadFieldOptions(readFieldArgs, objectOrReference, vari
567
567
  function makeMergeObjectsFunction(store) {
568
568
  return function mergeObjects(existing, incoming) {
569
569
  if (isArray(existing) || isArray(incoming)) {
570
- throw newInvariantError(102);
570
+ throw newInvariantError(103);
571
571
  }
572
572
  // These dynamic checks are necessary because the parameters of a
573
573
  // custom merge function can easily have the any type, so the type