@apollo/client 3.9.0-alpha.0 → 3.9.0-alpha.2

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 (104) hide show
  1. package/apollo-client.cjs +116 -136
  2. package/apollo-client.cjs.map +1 -1
  3. package/apollo-client.min.cjs +1 -1
  4. package/cache/cache.cjs +6 -29
  5. package/cache/cache.cjs.map +1 -1
  6. package/cache/cache.cjs.native.js +6 -29
  7. package/cache/index.d.ts +1 -2
  8. package/cache/index.d.ts.map +1 -1
  9. package/cache/index.js +1 -2
  10. package/cache/index.js.map +1 -1
  11. package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
  12. package/cache/inmemory/inMemoryCache.js +1 -2
  13. package/cache/inmemory/inMemoryCache.js.map +1 -1
  14. package/cache/inmemory/object-canon.d.ts +0 -5
  15. package/cache/inmemory/object-canon.d.ts.map +1 -1
  16. package/cache/inmemory/object-canon.js +0 -22
  17. package/cache/inmemory/object-canon.js.map +1 -1
  18. package/cache/inmemory/policies.d.ts.map +1 -1
  19. package/cache/inmemory/policies.js +0 -2
  20. package/cache/inmemory/policies.js.map +1 -1
  21. package/cache/inmemory/readFromStore.d.ts.map +1 -1
  22. package/cache/inmemory/readFromStore.js +2 -2
  23. package/cache/inmemory/readFromStore.js.map +1 -1
  24. package/cache/inmemory/writeToStore.d.ts.map +1 -1
  25. package/cache/inmemory/writeToStore.js +1 -2
  26. package/cache/inmemory/writeToStore.js.map +1 -1
  27. package/core/ObservableQuery.d.ts.map +1 -1
  28. package/core/ObservableQuery.js +5 -6
  29. package/core/ObservableQuery.js.map +1 -1
  30. package/core/QueryInfo.d.ts +0 -2
  31. package/core/QueryInfo.d.ts.map +1 -1
  32. package/core/QueryInfo.js +0 -2
  33. package/core/QueryInfo.js.map +1 -1
  34. package/core/QueryManager.js +2 -2
  35. package/core/QueryManager.js.map +1 -1
  36. package/core/core.cjs +8 -11
  37. package/core/core.cjs.map +1 -1
  38. package/core/core.cjs.native.js +8 -11
  39. package/dev/dev.cjs +52 -37
  40. package/dev/dev.cjs.map +1 -1
  41. package/dev/dev.cjs.native.js +52 -37
  42. package/dev/loadErrorMessageHandler.js +1 -1
  43. package/dev/loadErrorMessageHandler.js.map +1 -1
  44. package/invariantErrorCodes.js +24 -18
  45. package/package.json +7 -7
  46. package/react/cache/index.d.ts +0 -4
  47. package/react/cache/index.d.ts.map +1 -1
  48. package/react/cache/index.js +0 -14
  49. package/react/cache/index.js.map +1 -1
  50. package/react/index.d.ts +0 -1
  51. package/react/index.d.ts.map +1 -1
  52. package/react/index.js +0 -1
  53. package/react/index.js.map +1 -1
  54. package/react/react.cjs +1 -218
  55. package/react/react.cjs.map +1 -1
  56. package/react/react.cjs.native.js +1 -218
  57. package/react/types/types.d.ts +0 -3
  58. package/react/types/types.d.ts.map +1 -1
  59. package/react/types/types.js.map +1 -1
  60. package/testing/core/core.cjs +9 -1
  61. package/testing/core/core.cjs.map +1 -1
  62. package/testing/core/core.cjs.native.js +9 -1
  63. package/testing/core/mocking/mockLink.d.ts +1 -0
  64. package/testing/core/mocking/mockLink.d.ts.map +1 -1
  65. package/testing/core/mocking/mockLink.js +9 -1
  66. package/testing/core/mocking/mockLink.js.map +1 -1
  67. package/testing/internal/ObservableStream.d.ts +26 -0
  68. package/testing/internal/ObservableStream.d.ts.map +1 -0
  69. package/testing/internal/ObservableStream.js +101 -0
  70. package/testing/internal/ObservableStream.js.map +1 -0
  71. package/testing/internal/index.d.ts +1 -0
  72. package/testing/internal/index.d.ts.map +1 -1
  73. package/testing/internal/index.js +1 -0
  74. package/testing/internal/index.js.map +1 -1
  75. package/utilities/common/canonicalStringify.d.ts +4 -0
  76. package/utilities/common/canonicalStringify.d.ts.map +1 -0
  77. package/utilities/common/canonicalStringify.js +37 -0
  78. package/utilities/common/canonicalStringify.js.map +1 -0
  79. package/utilities/globals/globals.cjs +29 -19
  80. package/utilities/globals/globals.cjs.map +1 -1
  81. package/utilities/globals/globals.cjs.native.js +29 -19
  82. package/utilities/globals/invariantWrappers.d.ts.map +1 -1
  83. package/utilities/globals/invariantWrappers.js +28 -18
  84. package/utilities/globals/invariantWrappers.js.map +1 -1
  85. package/utilities/graphql/DocumentTransform.js +1 -1
  86. package/utilities/graphql/directives.js +4 -4
  87. package/utilities/graphql/fragments.js +3 -3
  88. package/utilities/graphql/getFromAST.js +8 -8
  89. package/utilities/graphql/storeUtils.d.ts +2 -2
  90. package/utilities/graphql/storeUtils.d.ts.map +1 -1
  91. package/utilities/graphql/storeUtils.js +8 -20
  92. package/utilities/graphql/storeUtils.js.map +1 -1
  93. package/utilities/graphql/transform.js +2 -2
  94. package/utilities/index.d.ts +1 -0
  95. package/utilities/index.d.ts.map +1 -1
  96. package/utilities/index.js +1 -0
  97. package/utilities/index.js.map +1 -1
  98. package/utilities/observables/asyncMap.d.ts.map +1 -1
  99. package/utilities/observables/asyncMap.js +17 -34
  100. package/utilities/observables/asyncMap.js.map +1 -1
  101. package/utilities/utilities.cjs +80 -72
  102. package/utilities/utilities.cjs.map +1 -1
  103. package/utilities/utilities.cjs.native.js +80 -72
  104. package/version.js +1 -1
@@ -20,7 +20,7 @@ function shouldInclude(_a, variables) {
20
20
  if (ifArgument.value.kind === "Variable") {
21
21
  evaledValue =
22
22
  variables && variables[ifArgument.value.name.value];
23
- globals.invariant(evaledValue !== void 0, 64, directive.name.value);
23
+ globals.invariant(evaledValue !== void 0, 65, directive.name.value);
24
24
  }
25
25
  else {
26
26
  evaledValue = ifArgument.value.value;
@@ -70,12 +70,12 @@ function getInclusionDirectives(directives) {
70
70
  return;
71
71
  var directiveArguments = directive.arguments;
72
72
  var directiveName = directive.name.value;
73
- globals.invariant(directiveArguments && directiveArguments.length === 1, 65, directiveName);
73
+ globals.invariant(directiveArguments && directiveArguments.length === 1, 66, directiveName);
74
74
  var ifArgument = directiveArguments[0];
75
- globals.invariant(ifArgument.name && ifArgument.name.value === "if", 66, directiveName);
75
+ globals.invariant(ifArgument.name && ifArgument.name.value === "if", 67, directiveName);
76
76
  var ifValue = ifArgument.value;
77
77
  globals.invariant(ifValue &&
78
- (ifValue.kind === "Variable" || ifValue.kind === "BooleanValue"), 67, directiveName);
78
+ (ifValue.kind === "Variable" || ifValue.kind === "BooleanValue"), 68, directiveName);
79
79
  result.push({ directive: directive, ifArgument: ifArgument });
80
80
  });
81
81
  }
@@ -107,7 +107,7 @@ function getFragmentQueryDocument(document, fragmentName) {
107
107
  document.definitions.forEach(function (definition) {
108
108
  if (definition.kind === "OperationDefinition") {
109
109
  throw globals.newInvariantError(
110
- 68,
110
+ 69,
111
111
  definition.operation,
112
112
  definition.name ? " named '".concat(definition.name.value, "'") : ""
113
113
  );
@@ -117,7 +117,7 @@ function getFragmentQueryDocument(document, fragmentName) {
117
117
  }
118
118
  });
119
119
  if (typeof actualFragmentName === "undefined") {
120
- globals.invariant(fragments.length === 1, 69, fragments.length);
120
+ globals.invariant(fragments.length === 1, 70, fragments.length);
121
121
  actualFragmentName = fragments[0].name.value;
122
122
  }
123
123
  var query = tslib.__assign(tslib.__assign({}, document), { definitions: tslib.__spreadArray([
@@ -158,7 +158,7 @@ function getFragmentFromSelection(selection, fragmentMap) {
158
158
  return fragmentMap(fragmentName);
159
159
  }
160
160
  var fragment = fragmentMap && fragmentMap[fragmentName];
161
- globals.invariant(fragment, 70, fragmentName);
161
+ globals.invariant(fragment, 71, fragmentName);
162
162
  return fragment || null;
163
163
  }
164
164
  default:
@@ -166,6 +166,43 @@ function getFragmentFromSelection(selection, fragmentMap) {
166
166
  }
167
167
  }
168
168
 
169
+ var canonicalStringify = Object.assign(function canonicalStringify(value) {
170
+ return JSON.stringify(value, stableObjectReplacer);
171
+ }, {
172
+ reset: function () {
173
+ sortingMap.clear();
174
+ },
175
+ });
176
+ var sortingMap = new Map();
177
+ function stableObjectReplacer(key, value) {
178
+ if (value && typeof value === "object") {
179
+ var proto = Object.getPrototypeOf(value);
180
+ if (proto === Object.prototype || proto === null) {
181
+ var keys = Object.keys(value);
182
+ if (keys.every(everyKeyInOrder))
183
+ return value;
184
+ var unsortedKey = JSON.stringify(keys);
185
+ var sortedKeys = sortingMap.get(unsortedKey);
186
+ if (!sortedKeys) {
187
+ keys.sort();
188
+ var sortedKey = JSON.stringify(keys);
189
+ sortedKeys = sortingMap.get(sortedKey) || keys;
190
+ sortingMap.set(unsortedKey, sortedKeys);
191
+ sortingMap.set(sortedKey, sortedKeys);
192
+ }
193
+ var sortedObject_1 = Object.create(proto);
194
+ sortedKeys.forEach(function (key) {
195
+ sortedObject_1[key] = value[key];
196
+ });
197
+ return sortedObject_1;
198
+ }
199
+ }
200
+ return value;
201
+ }
202
+ function everyKeyInOrder(key, i, keys) {
203
+ return i === 0 || keys[i - 1] <= key;
204
+ }
205
+
169
206
  function makeReference(id) {
170
207
  return { __ref: String(id) };
171
208
  }
@@ -236,7 +273,7 @@ function valueToObjectRepresentation(argObj, name, value, variables) {
236
273
  argObj[name.value] = null;
237
274
  }
238
275
  else {
239
- throw globals.newInvariantError(79, name.value, value.kind);
276
+ throw globals.newInvariantError(80, name.value, value.kind);
240
277
  }
241
278
  }
242
279
  function storeKeyNameFromField(field, variables) {
@@ -272,6 +309,7 @@ var KNOWN_DIRECTIVES = [
272
309
  "export",
273
310
  "nonreactive",
274
311
  ];
312
+ var storeKeyNameStringify = canonicalStringify;
275
313
  var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
276
314
  if (args &&
277
315
  directives &&
@@ -287,7 +325,7 @@ var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
287
325
  filterKeys.forEach(function (key) {
288
326
  filteredArgs_1[key] = args[key];
289
327
  });
290
- return "".concat(directives["connection"]["key"], "(").concat(stringify(filteredArgs_1), ")");
328
+ return "".concat(directives["connection"]["key"], "(").concat(storeKeyNameStringify(filteredArgs_1), ")");
291
329
  }
292
330
  else {
293
331
  return directives["connection"]["key"];
@@ -295,7 +333,7 @@ var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
295
333
  }
296
334
  var completeFieldName = fieldName;
297
335
  if (args) {
298
- var stringifiedArgs = stringify(args);
336
+ var stringifiedArgs = storeKeyNameStringify(args);
299
337
  completeFieldName += "(".concat(stringifiedArgs, ")");
300
338
  }
301
339
  if (directives) {
@@ -303,7 +341,7 @@ var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
303
341
  if (KNOWN_DIRECTIVES.indexOf(key) !== -1)
304
342
  return;
305
343
  if (directives[key] && Object.keys(directives[key]).length) {
306
- completeFieldName += "@".concat(key, "(").concat(stringify(directives[key]), ")");
344
+ completeFieldName += "@".concat(key, "(").concat(storeKeyNameStringify(directives[key]), ")");
307
345
  }
308
346
  else {
309
347
  completeFieldName += "@".concat(key);
@@ -313,25 +351,11 @@ var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
313
351
  return completeFieldName;
314
352
  }, {
315
353
  setStringify: function (s) {
316
- var previous = stringify;
317
- stringify = s;
354
+ var previous = storeKeyNameStringify;
355
+ storeKeyNameStringify = s;
318
356
  return previous;
319
357
  },
320
358
  });
321
- var stringify = function defaultStringify(value) {
322
- return JSON.stringify(value, stringifyReplacer);
323
- };
324
- function stringifyReplacer(_key, value) {
325
- if (isNonNullObject(value) && !Array.isArray(value)) {
326
- value = Object.keys(value)
327
- .sort()
328
- .reduce(function (copy, key) {
329
- copy[key] = value[key];
330
- return copy;
331
- }, {});
332
- }
333
- return value;
334
- }
335
359
  function argumentsObjectFromField(field, variables) {
336
360
  if (field.arguments && field.arguments.length) {
337
361
  var argObj_1 = {};
@@ -383,16 +407,16 @@ function isInlineFragment(selection) {
383
407
  }
384
408
 
385
409
  function checkDocument(doc) {
386
- globals.invariant(doc && doc.kind === "Document", 71);
410
+ globals.invariant(doc && doc.kind === "Document", 72);
387
411
  var operations = doc.definitions
388
412
  .filter(function (d) { return d.kind !== "FragmentDefinition"; })
389
413
  .map(function (definition) {
390
414
  if (definition.kind !== "OperationDefinition") {
391
- throw globals.newInvariantError(72, definition.kind);
415
+ throw globals.newInvariantError(73, definition.kind);
392
416
  }
393
417
  return definition;
394
418
  });
395
- globals.invariant(operations.length <= 1, 73, operations.length);
419
+ globals.invariant(operations.length <= 1, 74, operations.length);
396
420
  return doc;
397
421
  }
398
422
  function getOperationDefinition(doc) {
@@ -415,14 +439,14 @@ function getFragmentDefinitions(doc) {
415
439
  }
416
440
  function getQueryDefinition(doc) {
417
441
  var queryDef = getOperationDefinition(doc);
418
- globals.invariant(queryDef && queryDef.operation === "query", 74);
442
+ globals.invariant(queryDef && queryDef.operation === "query", 75);
419
443
  return queryDef;
420
444
  }
421
445
  function getFragmentDefinition(doc) {
422
- globals.invariant(doc.kind === "Document", 75);
423
- globals.invariant(doc.definitions.length <= 1, 76);
446
+ globals.invariant(doc.kind === "Document", 76);
447
+ globals.invariant(doc.definitions.length <= 1, 77);
424
448
  var fragmentDef = doc.definitions[0];
425
- globals.invariant(fragmentDef.kind === "FragmentDefinition", 77);
449
+ globals.invariant(fragmentDef.kind === "FragmentDefinition", 78);
426
450
  return fragmentDef;
427
451
  }
428
452
  function getMainDefinition(queryDoc) {
@@ -445,7 +469,7 @@ function getMainDefinition(queryDoc) {
445
469
  if (fragmentDefinition) {
446
470
  return fragmentDefinition;
447
471
  }
448
- throw globals.newInvariantError(78);
472
+ throw globals.newInvariantError(79);
449
473
  }
450
474
  function getDefaultValues(definition) {
451
475
  var defaultValues = Object.create(null);
@@ -517,7 +541,7 @@ var DocumentTransform = (function () {
517
541
  return;
518
542
  var cacheKeys = this.getCacheKey(document);
519
543
  if (cacheKeys) {
520
- globals.invariant(Array.isArray(cacheKeys), 63);
544
+ globals.invariant(Array.isArray(cacheKeys), 64);
521
545
  return this.stableCacheKeys.lookupArray(cacheKeys);
522
546
  }
523
547
  };
@@ -613,7 +637,7 @@ function removeDirectivesFromDocument(directives, doc) {
613
637
  return getInUseByFragmentName(ancestor.name.value);
614
638
  }
615
639
  }
616
- globalThis.__DEV__ !== false && globals.invariant.error(80);
640
+ globalThis.__DEV__ !== false && globals.invariant.error(81);
617
641
  return null;
618
642
  };
619
643
  var operationCount = 0;
@@ -800,7 +824,7 @@ var connectionRemoveConfig = {
800
824
  if (willRemove) {
801
825
  if (!directive.arguments ||
802
826
  !directive.arguments.some(function (arg) { return arg.name.value === "key"; })) {
803
- globalThis.__DEV__ !== false && globals.invariant.warn(81);
827
+ globalThis.__DEV__ !== false && globals.invariant.warn(82);
804
828
  }
805
829
  }
806
830
  return willRemove;
@@ -1249,48 +1273,31 @@ function iterateObserversSafely(observers, method, argument) {
1249
1273
 
1250
1274
  function asyncMap(observable, mapFn, catchFn) {
1251
1275
  return new zenObservableTs.Observable(function (observer) {
1252
- var next = observer.next, error = observer.error, complete = observer.complete;
1253
- var activeCallbackCount = 0;
1254
- var completed = false;
1255
1276
  var promiseQueue = {
1256
1277
  then: function (callback) {
1257
1278
  return new Promise(function (resolve) { return resolve(callback()); });
1258
1279
  },
1259
1280
  };
1260
- function makeCallback(examiner, delegate) {
1261
- if (examiner) {
1262
- return function (arg) {
1263
- ++activeCallbackCount;
1264
- var both = function () { return examiner(arg); };
1265
- promiseQueue = promiseQueue
1266
- .then(both, both)
1267
- .then(function (result) {
1268
- --activeCallbackCount;
1269
- next && next.call(observer, result);
1270
- if (completed) {
1271
- handler.complete();
1272
- }
1273
- }, function (error) {
1274
- --activeCallbackCount;
1275
- throw error;
1276
- })
1277
- .catch(function (caught) {
1278
- error && error.call(observer, caught);
1279
- });
1280
- };
1281
- }
1282
- else {
1283
- return function (arg) { return delegate && delegate.call(observer, arg); };
1284
- }
1281
+ function makeCallback(examiner, key) {
1282
+ return function (arg) {
1283
+ if (examiner) {
1284
+ var both = function () {
1285
+ return observer.closed
1286
+ ? 0
1287
+ : examiner(arg);
1288
+ };
1289
+ promiseQueue = promiseQueue.then(both, both).then(function (result) { return observer.next(result); }, function (error) { return observer.error(error); });
1290
+ }
1291
+ else {
1292
+ observer[key](arg);
1293
+ }
1294
+ };
1285
1295
  }
1286
1296
  var handler = {
1287
- next: makeCallback(mapFn, next),
1288
- error: makeCallback(catchFn, error),
1297
+ next: makeCallback(mapFn, "next"),
1298
+ error: makeCallback(catchFn, "error"),
1289
1299
  complete: function () {
1290
- completed = true;
1291
- if (!activeCallbackCount) {
1292
- complete && complete.call(observer);
1293
- }
1300
+ promiseQueue.then(function () { return observer.complete(); });
1294
1301
  },
1295
1302
  };
1296
1303
  var sub = observable.subscribe(handler);
@@ -1591,6 +1598,7 @@ exports.canUseLayoutEffect = canUseLayoutEffect;
1591
1598
  exports.canUseSymbol = canUseSymbol;
1592
1599
  exports.canUseWeakMap = canUseWeakMap;
1593
1600
  exports.canUseWeakSet = canUseWeakSet;
1601
+ exports.canonicalStringify = canonicalStringify;
1594
1602
  exports.checkDocument = checkDocument;
1595
1603
  exports.cloneDeep = cloneDeep;
1596
1604
  exports.compact = compact;
package/version.js CHANGED
@@ -1,2 +1,2 @@
1
- export var version = "3.9.0-alpha.0";
1
+ export var version = "3.9.0-alpha.2";
2
2
  //# sourceMappingURL=version.js.map