UNPKG

62.7 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5var globals = require('./globals');
6var graphql = require('graphql');
7var trie = require('@wry/trie');
8var tslib = require('tslib');
9var caches = require('@wry/caches');
10var optimism = require('optimism');
11var zenObservableTs = require('zen-observable-ts');
12require('symbol-observable');
13
14function shouldInclude(_a, variables) {
15 var directives = _a.directives;
16 if (!directives || !directives.length) {
17 return true;
18 }
19 return getInclusionDirectives(directives).every(function (_a) {
20 var directive = _a.directive, ifArgument = _a.ifArgument;
21 var evaledValue = false;
22 if (ifArgument.value.kind === "Variable") {
23 evaledValue =
24 variables && variables[ifArgument.value.name.value];
25 globals.invariant(evaledValue !== void 0, 67, directive.name.value);
26 }
27 else {
28 evaledValue = ifArgument.value.value;
29 }
30 return directive.name.value === "skip" ? !evaledValue : evaledValue;
31 });
32}
33function getDirectiveNames(root) {
34 var names = [];
35 graphql.visit(root, {
36 Directive: function (node) {
37 names.push(node.name.value);
38 },
39 });
40 return names;
41}
42var hasAnyDirectives = function (names, root) {
43 return hasDirectives(names, root, false);
44};
45var hasAllDirectives = function (names, root) {
46 return hasDirectives(names, root, true);
47};
48function hasDirectives(names, root, all) {
49 var nameSet = new Set(names);
50 var uniqueCount = nameSet.size;
51 graphql.visit(root, {
52 Directive: function (node) {
53 if (nameSet.delete(node.name.value) && (!all || !nameSet.size)) {
54 return graphql.BREAK;
55 }
56 },
57 });
58 return all ? !nameSet.size : nameSet.size < uniqueCount;
59}
60function hasClientExports(document) {
61 return document && hasDirectives(["client", "export"], document, true);
62}
63function isInclusionDirective(_a) {
64 var value = _a.name.value;
65 return value === "skip" || value === "include";
66}
67function getInclusionDirectives(directives) {
68 var result = [];
69 if (directives && directives.length) {
70 directives.forEach(function (directive) {
71 if (!isInclusionDirective(directive))
72 return;
73 var directiveArguments = directive.arguments;
74 var directiveName = directive.name.value;
75 globals.invariant(directiveArguments && directiveArguments.length === 1, 68, directiveName);
76 var ifArgument = directiveArguments[0];
77 globals.invariant(ifArgument.name && ifArgument.name.value === "if", 69, directiveName);
78 var ifValue = ifArgument.value;
79 globals.invariant(ifValue &&
80 (ifValue.kind === "Variable" || ifValue.kind === "BooleanValue"), 70, directiveName);
81 result.push({ directive: directive, ifArgument: ifArgument });
82 });
83 }
84 return result;
85}
86
87var canUseWeakMap = typeof WeakMap === "function" &&
88 !globals.maybe(function () { return navigator.product == "ReactNative" && !global.HermesInternal; });
89var canUseWeakSet = typeof WeakSet === "function";
90var canUseSymbol = typeof Symbol === "function" && typeof Symbol.for === "function";
91var canUseAsyncIteratorSymbol = canUseSymbol && Symbol.asyncIterator;
92var canUseDOM = typeof globals.maybe(function () { return window.document.createElement; }) === "function";
93var usingJSDOM =
94globals.maybe(function () { return navigator.userAgent.indexOf("jsdom") >= 0; }) || false;
95var canUseLayoutEffect = canUseDOM && !usingJSDOM;
96
97function isNonNullObject(obj) {
98 return obj !== null && typeof obj === "object";
99}
100function isPlainObject(obj) {
101 return (obj !== null &&
102 typeof obj === "object" &&
103 (Object.getPrototypeOf(obj) === Object.prototype ||
104 Object.getPrototypeOf(obj) === null));
105}
106
107function getFragmentQueryDocument(document, fragmentName) {
108 var actualFragmentName = fragmentName;
109 var fragments = [];
110 document.definitions.forEach(function (definition) {
111 if (definition.kind === "OperationDefinition") {
112 throw globals.newInvariantError(
113 71,
114 definition.operation,
115 definition.name ? " named '".concat(definition.name.value, "'") : ""
116 );
117 }
118 if (definition.kind === "FragmentDefinition") {
119 fragments.push(definition);
120 }
121 });
122 if (typeof actualFragmentName === "undefined") {
123 globals.invariant(fragments.length === 1, 72, fragments.length);
124 actualFragmentName = fragments[0].name.value;
125 }
126 var query = tslib.__assign(tslib.__assign({}, document), { definitions: tslib.__spreadArray([
127 {
128 kind: "OperationDefinition",
129 operation: "query",
130 selectionSet: {
131 kind: "SelectionSet",
132 selections: [
133 {
134 kind: "FragmentSpread",
135 name: {
136 kind: "Name",
137 value: actualFragmentName,
138 },
139 },
140 ],
141 },
142 }
143 ], document.definitions, true) });
144 return query;
145}
146function createFragmentMap(fragments) {
147 if (fragments === void 0) { fragments = []; }
148 var symTable = {};
149 fragments.forEach(function (fragment) {
150 symTable[fragment.name.value] = fragment;
151 });
152 return symTable;
153}
154function getFragmentFromSelection(selection, fragmentMap) {
155 switch (selection.kind) {
156 case "InlineFragment":
157 return selection;
158 case "FragmentSpread": {
159 var fragmentName = selection.name.value;
160 if (typeof fragmentMap === "function") {
161 return fragmentMap(fragmentName);
162 }
163 var fragment = fragmentMap && fragmentMap[fragmentName];
164 globals.invariant(fragment, 73, fragmentName);
165 return fragment || null;
166 }
167 default:
168 return null;
169 }
170}
171
172var scheduledCleanup = new WeakSet();
173function schedule(cache) {
174 if (!scheduledCleanup.has(cache)) {
175 scheduledCleanup.add(cache);
176 setTimeout(function () {
177 cache.clean();
178 scheduledCleanup.delete(cache);
179 }, 100);
180 }
181}
182var AutoCleanedWeakCache = function (max, dispose) {
183 var cache = new caches.WeakCache(max, dispose);
184 cache.set = function (key, value) {
185 schedule(this);
186 return caches.WeakCache.prototype.set.call(this, key, value);
187 };
188 return cache;
189};
190var AutoCleanedStrongCache = function (max, dispose) {
191 var cache = new caches.StrongCache(max, dispose);
192 cache.set = function (key, value) {
193 schedule(this);
194 return caches.StrongCache.prototype.set.call(this, key, value);
195 };
196 return cache;
197};
198
199var cacheSizeSymbol = Symbol.for("apollo.cacheSize");
200var cacheSizes = tslib.__assign({}, globals.global[cacheSizeSymbol]);
201
202var globalCaches = {};
203function registerGlobalCache(name, getSize) {
204 globalCaches[name] = getSize;
205}
206
207var canonicalStringify = Object.assign(function canonicalStringify(value) {
208 return JSON.stringify(value, stableObjectReplacer);
209}, {
210 reset: function () {
211 sortingMap = new AutoCleanedStrongCache(cacheSizes.canonicalStringify || 1000 );
212 },
213});
214if (globalThis.__DEV__ !== false) {
215 registerGlobalCache("canonicalStringify", function () { return sortingMap.size; });
216}
217var sortingMap;
218canonicalStringify.reset();
219function stableObjectReplacer(key, value) {
220 if (value && typeof value === "object") {
221 var proto = Object.getPrototypeOf(value);
222 if (proto === Object.prototype || proto === null) {
223 var keys = Object.keys(value);
224 if (keys.every(everyKeyInOrder))
225 return value;
226 var unsortedKey = JSON.stringify(keys);
227 var sortedKeys = sortingMap.get(unsortedKey);
228 if (!sortedKeys) {
229 keys.sort();
230 var sortedKey = JSON.stringify(keys);
231 sortedKeys = sortingMap.get(sortedKey) || keys;
232 sortingMap.set(unsortedKey, sortedKeys);
233 sortingMap.set(sortedKey, sortedKeys);
234 }
235 var sortedObject_1 = Object.create(proto);
236 sortedKeys.forEach(function (key) {
237 sortedObject_1[key] = value[key];
238 });
239 return sortedObject_1;
240 }
241 }
242 return value;
243}
244function everyKeyInOrder(key, i, keys) {
245 return i === 0 || keys[i - 1] <= key;
246}
247
248function makeReference(id) {
249 return { __ref: String(id) };
250}
251function isReference(obj) {
252 return Boolean(obj && typeof obj === "object" && typeof obj.__ref === "string");
253}
254function isDocumentNode(value) {
255 return (isNonNullObject(value) &&
256 value.kind === "Document" &&
257 Array.isArray(value.definitions));
258}
259function isStringValue(value) {
260 return value.kind === "StringValue";
261}
262function isBooleanValue(value) {
263 return value.kind === "BooleanValue";
264}
265function isIntValue(value) {
266 return value.kind === "IntValue";
267}
268function isFloatValue(value) {
269 return value.kind === "FloatValue";
270}
271function isVariable(value) {
272 return value.kind === "Variable";
273}
274function isObjectValue(value) {
275 return value.kind === "ObjectValue";
276}
277function isListValue(value) {
278 return value.kind === "ListValue";
279}
280function isEnumValue(value) {
281 return value.kind === "EnumValue";
282}
283function isNullValue(value) {
284 return value.kind === "NullValue";
285}
286function valueToObjectRepresentation(argObj, name, value, variables) {
287 if (isIntValue(value) || isFloatValue(value)) {
288 argObj[name.value] = Number(value.value);
289 }
290 else if (isBooleanValue(value) || isStringValue(value)) {
291 argObj[name.value] = value.value;
292 }
293 else if (isObjectValue(value)) {
294 var nestedArgObj_1 = {};
295 value.fields.map(function (obj) {
296 return valueToObjectRepresentation(nestedArgObj_1, obj.name, obj.value, variables);
297 });
298 argObj[name.value] = nestedArgObj_1;
299 }
300 else if (isVariable(value)) {
301 var variableValue = (variables || {})[value.name.value];
302 argObj[name.value] = variableValue;
303 }
304 else if (isListValue(value)) {
305 argObj[name.value] = value.values.map(function (listValue) {
306 var nestedArgArrayObj = {};
307 valueToObjectRepresentation(nestedArgArrayObj, name, listValue, variables);
308 return nestedArgArrayObj[name.value];
309 });
310 }
311 else if (isEnumValue(value)) {
312 argObj[name.value] = value.value;
313 }
314 else if (isNullValue(value)) {
315 argObj[name.value] = null;
316 }
317 else {
318 throw globals.newInvariantError(82, name.value, value.kind);
319 }
320}
321function storeKeyNameFromField(field, variables) {
322 var directivesObj = null;
323 if (field.directives) {
324 directivesObj = {};
325 field.directives.forEach(function (directive) {
326 directivesObj[directive.name.value] = {};
327 if (directive.arguments) {
328 directive.arguments.forEach(function (_a) {
329 var name = _a.name, value = _a.value;
330 return valueToObjectRepresentation(directivesObj[directive.name.value], name, value, variables);
331 });
332 }
333 });
334 }
335 var argObj = null;
336 if (field.arguments && field.arguments.length) {
337 argObj = {};
338 field.arguments.forEach(function (_a) {
339 var name = _a.name, value = _a.value;
340 return valueToObjectRepresentation(argObj, name, value, variables);
341 });
342 }
343 return getStoreKeyName(field.name.value, argObj, directivesObj);
344}
345var KNOWN_DIRECTIVES = [
346 "connection",
347 "include",
348 "skip",
349 "client",
350 "rest",
351 "export",
352 "nonreactive",
353];
354var storeKeyNameStringify = canonicalStringify;
355var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
356 if (args &&
357 directives &&
358 directives["connection"] &&
359 directives["connection"]["key"]) {
360 if (directives["connection"]["filter"] &&
361 directives["connection"]["filter"].length > 0) {
362 var filterKeys = directives["connection"]["filter"] ?
363 directives["connection"]["filter"]
364 : [];
365 filterKeys.sort();
366 var filteredArgs_1 = {};
367 filterKeys.forEach(function (key) {
368 filteredArgs_1[key] = args[key];
369 });
370 return "".concat(directives["connection"]["key"], "(").concat(storeKeyNameStringify(filteredArgs_1), ")");
371 }
372 else {
373 return directives["connection"]["key"];
374 }
375 }
376 var completeFieldName = fieldName;
377 if (args) {
378 var stringifiedArgs = storeKeyNameStringify(args);
379 completeFieldName += "(".concat(stringifiedArgs, ")");
380 }
381 if (directives) {
382 Object.keys(directives).forEach(function (key) {
383 if (KNOWN_DIRECTIVES.indexOf(key) !== -1)
384 return;
385 if (directives[key] && Object.keys(directives[key]).length) {
386 completeFieldName += "@".concat(key, "(").concat(storeKeyNameStringify(directives[key]), ")");
387 }
388 else {
389 completeFieldName += "@".concat(key);
390 }
391 });
392 }
393 return completeFieldName;
394}, {
395 setStringify: function (s) {
396 var previous = storeKeyNameStringify;
397 storeKeyNameStringify = s;
398 return previous;
399 },
400});
401function argumentsObjectFromField(field, variables) {
402 if (field.arguments && field.arguments.length) {
403 var argObj_1 = {};
404 field.arguments.forEach(function (_a) {
405 var name = _a.name, value = _a.value;
406 return valueToObjectRepresentation(argObj_1, name, value, variables);
407 });
408 return argObj_1;
409 }
410 return null;
411}
412function resultKeyNameFromField(field) {
413 return field.alias ? field.alias.value : field.name.value;
414}
415function getTypenameFromResult(result, selectionSet, fragmentMap) {
416 var fragments;
417 for (var _i = 0, _a = selectionSet.selections; _i < _a.length; _i++) {
418 var selection = _a[_i];
419 if (isField(selection)) {
420 if (selection.name.value === "__typename") {
421 return result[resultKeyNameFromField(selection)];
422 }
423 }
424 else if (fragments) {
425 fragments.push(selection);
426 }
427 else {
428 fragments = [selection];
429 }
430 }
431 if (typeof result.__typename === "string") {
432 return result.__typename;
433 }
434 if (fragments) {
435 for (var _b = 0, fragments_1 = fragments; _b < fragments_1.length; _b++) {
436 var selection = fragments_1[_b];
437 var typename = getTypenameFromResult(result, getFragmentFromSelection(selection, fragmentMap).selectionSet, fragmentMap);
438 if (typeof typename === "string") {
439 return typename;
440 }
441 }
442 }
443}
444function isField(selection) {
445 return selection.kind === "Field";
446}
447function isInlineFragment(selection) {
448 return selection.kind === "InlineFragment";
449}
450
451function checkDocument(doc) {
452 globals.invariant(doc && doc.kind === "Document", 74);
453 var operations = doc.definitions
454 .filter(function (d) { return d.kind !== "FragmentDefinition"; })
455 .map(function (definition) {
456 if (definition.kind !== "OperationDefinition") {
457 throw globals.newInvariantError(75, definition.kind);
458 }
459 return definition;
460 });
461 globals.invariant(operations.length <= 1, 76, operations.length);
462 return doc;
463}
464function getOperationDefinition(doc) {
465 checkDocument(doc);
466 return doc.definitions.filter(function (definition) {
467 return definition.kind === "OperationDefinition";
468 })[0];
469}
470function getOperationName(doc) {
471 return (doc.definitions
472 .filter(function (definition) {
473 return definition.kind === "OperationDefinition" && !!definition.name;
474 })
475 .map(function (x) { return x.name.value; })[0] || null);
476}
477function getFragmentDefinitions(doc) {
478 return doc.definitions.filter(function (definition) {
479 return definition.kind === "FragmentDefinition";
480 });
481}
482function getQueryDefinition(doc) {
483 var queryDef = getOperationDefinition(doc);
484 globals.invariant(queryDef && queryDef.operation === "query", 77);
485 return queryDef;
486}
487function getFragmentDefinition(doc) {
488 globals.invariant(doc.kind === "Document", 78);
489 globals.invariant(doc.definitions.length <= 1, 79);
490 var fragmentDef = doc.definitions[0];
491 globals.invariant(fragmentDef.kind === "FragmentDefinition", 80);
492 return fragmentDef;
493}
494function getMainDefinition(queryDoc) {
495 checkDocument(queryDoc);
496 var fragmentDefinition;
497 for (var _i = 0, _a = queryDoc.definitions; _i < _a.length; _i++) {
498 var definition = _a[_i];
499 if (definition.kind === "OperationDefinition") {
500 var operation = definition.operation;
501 if (operation === "query" ||
502 operation === "mutation" ||
503 operation === "subscription") {
504 return definition;
505 }
506 }
507 if (definition.kind === "FragmentDefinition" && !fragmentDefinition) {
508 fragmentDefinition = definition;
509 }
510 }
511 if (fragmentDefinition) {
512 return fragmentDefinition;
513 }
514 throw globals.newInvariantError(81);
515}
516function getDefaultValues(definition) {
517 var defaultValues = Object.create(null);
518 var defs = definition && definition.variableDefinitions;
519 if (defs && defs.length) {
520 defs.forEach(function (def) {
521 if (def.defaultValue) {
522 valueToObjectRepresentation(defaultValues, def.variable.name, def.defaultValue);
523 }
524 });
525 }
526 return defaultValues;
527}
528
529function identity(document) {
530 return document;
531}
532var DocumentTransform = (function () {
533 function DocumentTransform(transform, options) {
534 if (options === void 0) { options = Object.create(null); }
535 this.resultCache = canUseWeakSet ? new WeakSet() : new Set();
536 this.transform = transform;
537 if (options.getCacheKey) {
538 this.getCacheKey = options.getCacheKey;
539 }
540 this.cached = options.cache !== false;
541 this.resetCache();
542 }
543 DocumentTransform.prototype.getCacheKey = function (document) {
544 return [document];
545 };
546 DocumentTransform.identity = function () {
547 return new DocumentTransform(identity, { cache: false });
548 };
549 DocumentTransform.split = function (predicate, left, right) {
550 if (right === void 0) { right = DocumentTransform.identity(); }
551 return Object.assign(new DocumentTransform(function (document) {
552 var documentTransform = predicate(document) ? left : right;
553 return documentTransform.transformDocument(document);
554 },
555 { cache: false }), { left: left, right: right });
556 };
557 DocumentTransform.prototype.resetCache = function () {
558 var _this = this;
559 if (this.cached) {
560 var stableCacheKeys_1 = new trie.Trie(canUseWeakMap);
561 this.performWork = optimism.wrap(DocumentTransform.prototype.performWork.bind(this), {
562 makeCacheKey: function (document) {
563 var cacheKeys = _this.getCacheKey(document);
564 if (cacheKeys) {
565 globals.invariant(Array.isArray(cacheKeys), 66);
566 return stableCacheKeys_1.lookupArray(cacheKeys);
567 }
568 },
569 max: cacheSizes["documentTransform.cache"],
570 cache: (caches.WeakCache),
571 });
572 }
573 };
574 DocumentTransform.prototype.performWork = function (document) {
575 checkDocument(document);
576 return this.transform(document);
577 };
578 DocumentTransform.prototype.transformDocument = function (document) {
579 if (this.resultCache.has(document)) {
580 return document;
581 }
582 var transformedDocument = this.performWork(document);
583 this.resultCache.add(transformedDocument);
584 return transformedDocument;
585 };
586 DocumentTransform.prototype.concat = function (otherTransform) {
587 var _this = this;
588 return Object.assign(new DocumentTransform(function (document) {
589 return otherTransform.transformDocument(_this.transformDocument(document));
590 },
591 { cache: false }), {
592 left: this,
593 right: otherTransform,
594 });
595 };
596 return DocumentTransform;
597}());
598
599var printCache;
600var print = Object.assign(function (ast) {
601 var result = printCache.get(ast);
602 if (!result) {
603 result = graphql.print(ast);
604 printCache.set(ast, result);
605 }
606 return result;
607}, {
608 reset: function () {
609 printCache = new AutoCleanedWeakCache(cacheSizes.print || 2000 );
610 },
611});
612print.reset();
613if (globalThis.__DEV__ !== false) {
614 registerGlobalCache("print", function () { return (printCache ? printCache.size : 0); });
615}
616
617var isArray = Array.isArray;
618function isNonEmptyArray(value) {
619 return Array.isArray(value) && value.length > 0;
620}
621
622var TYPENAME_FIELD = {
623 kind: graphql.Kind.FIELD,
624 name: {
625 kind: graphql.Kind.NAME,
626 value: "__typename",
627 },
628};
629function isEmpty(op, fragmentMap) {
630 return (!op ||
631 op.selectionSet.selections.every(function (selection) {
632 return selection.kind === graphql.Kind.FRAGMENT_SPREAD &&
633 isEmpty(fragmentMap[selection.name.value], fragmentMap);
634 }));
635}
636function nullIfDocIsEmpty(doc) {
637 return (isEmpty(getOperationDefinition(doc) || getFragmentDefinition(doc), createFragmentMap(getFragmentDefinitions(doc)))) ?
638 null
639 : doc;
640}
641function getDirectiveMatcher(configs) {
642 var names = new Map();
643 var tests = new Map();
644 configs.forEach(function (directive) {
645 if (directive) {
646 if (directive.name) {
647 names.set(directive.name, directive);
648 }
649 else if (directive.test) {
650 tests.set(directive.test, directive);
651 }
652 }
653 });
654 return function (directive) {
655 var config = names.get(directive.name.value);
656 if (!config && tests.size) {
657 tests.forEach(function (testConfig, test) {
658 if (test(directive)) {
659 config = testConfig;
660 }
661 });
662 }
663 return config;
664 };
665}
666function makeInUseGetterFunction(defaultKey) {
667 var map = new Map();
668 return function inUseGetterFunction(key) {
669 if (key === void 0) { key = defaultKey; }
670 var inUse = map.get(key);
671 if (!inUse) {
672 map.set(key, (inUse = {
673 variables: new Set(),
674 fragmentSpreads: new Set(),
675 }));
676 }
677 return inUse;
678 };
679}
680function removeDirectivesFromDocument(directives, doc) {
681 checkDocument(doc);
682 var getInUseByOperationName = makeInUseGetterFunction("");
683 var getInUseByFragmentName = makeInUseGetterFunction("");
684 var getInUse = function (ancestors) {
685 for (var p = 0, ancestor = void 0; p < ancestors.length && (ancestor = ancestors[p]); ++p) {
686 if (isArray(ancestor))
687 continue;
688 if (ancestor.kind === graphql.Kind.OPERATION_DEFINITION) {
689 return getInUseByOperationName(ancestor.name && ancestor.name.value);
690 }
691 if (ancestor.kind === graphql.Kind.FRAGMENT_DEFINITION) {
692 return getInUseByFragmentName(ancestor.name.value);
693 }
694 }
695 globalThis.__DEV__ !== false && globals.invariant.error(83);
696 return null;
697 };
698 var operationCount = 0;
699 for (var i = doc.definitions.length - 1; i >= 0; --i) {
700 if (doc.definitions[i].kind === graphql.Kind.OPERATION_DEFINITION) {
701 ++operationCount;
702 }
703 }
704 var directiveMatcher = getDirectiveMatcher(directives);
705 var shouldRemoveField = function (nodeDirectives) {
706 return isNonEmptyArray(nodeDirectives) &&
707 nodeDirectives
708 .map(directiveMatcher)
709 .some(function (config) { return config && config.remove; });
710 };
711 var originalFragmentDefsByPath = new Map();
712 var firstVisitMadeChanges = false;
713 var fieldOrInlineFragmentVisitor = {
714 enter: function (node) {
715 if (shouldRemoveField(node.directives)) {
716 firstVisitMadeChanges = true;
717 return null;
718 }
719 },
720 };
721 var docWithoutDirectiveSubtrees = graphql.visit(doc, {
722 Field: fieldOrInlineFragmentVisitor,
723 InlineFragment: fieldOrInlineFragmentVisitor,
724 VariableDefinition: {
725 enter: function () {
726 return false;
727 },
728 },
729 Variable: {
730 enter: function (node, _key, _parent, _path, ancestors) {
731 var inUse = getInUse(ancestors);
732 if (inUse) {
733 inUse.variables.add(node.name.value);
734 }
735 },
736 },
737 FragmentSpread: {
738 enter: function (node, _key, _parent, _path, ancestors) {
739 if (shouldRemoveField(node.directives)) {
740 firstVisitMadeChanges = true;
741 return null;
742 }
743 var inUse = getInUse(ancestors);
744 if (inUse) {
745 inUse.fragmentSpreads.add(node.name.value);
746 }
747 },
748 },
749 FragmentDefinition: {
750 enter: function (node, _key, _parent, path) {
751 originalFragmentDefsByPath.set(JSON.stringify(path), node);
752 },
753 leave: function (node, _key, _parent, path) {
754 var originalNode = originalFragmentDefsByPath.get(JSON.stringify(path));
755 if (node === originalNode) {
756 return node;
757 }
758 if (
759 operationCount > 0 &&
760 node.selectionSet.selections.every(function (selection) {
761 return selection.kind === graphql.Kind.FIELD &&
762 selection.name.value === "__typename";
763 })) {
764 getInUseByFragmentName(node.name.value).removed = true;
765 firstVisitMadeChanges = true;
766 return null;
767 }
768 },
769 },
770 Directive: {
771 leave: function (node) {
772 if (directiveMatcher(node)) {
773 firstVisitMadeChanges = true;
774 return null;
775 }
776 },
777 },
778 });
779 if (!firstVisitMadeChanges) {
780 return doc;
781 }
782 var populateTransitiveVars = function (inUse) {
783 if (!inUse.transitiveVars) {
784 inUse.transitiveVars = new Set(inUse.variables);
785 if (!inUse.removed) {
786 inUse.fragmentSpreads.forEach(function (childFragmentName) {
787 populateTransitiveVars(getInUseByFragmentName(childFragmentName)).transitiveVars.forEach(function (varName) {
788 inUse.transitiveVars.add(varName);
789 });
790 });
791 }
792 }
793 return inUse;
794 };
795 var allFragmentNamesUsed = new Set();
796 docWithoutDirectiveSubtrees.definitions.forEach(function (def) {
797 if (def.kind === graphql.Kind.OPERATION_DEFINITION) {
798 populateTransitiveVars(getInUseByOperationName(def.name && def.name.value)).fragmentSpreads.forEach(function (childFragmentName) {
799 allFragmentNamesUsed.add(childFragmentName);
800 });
801 }
802 else if (def.kind === graphql.Kind.FRAGMENT_DEFINITION &&
803 operationCount === 0 &&
804 !getInUseByFragmentName(def.name.value).removed) {
805 allFragmentNamesUsed.add(def.name.value);
806 }
807 });
808 allFragmentNamesUsed.forEach(function (fragmentName) {
809 populateTransitiveVars(getInUseByFragmentName(fragmentName)).fragmentSpreads.forEach(function (childFragmentName) {
810 allFragmentNamesUsed.add(childFragmentName);
811 });
812 });
813 var fragmentWillBeRemoved = function (fragmentName) {
814 return !!(
815 (!allFragmentNamesUsed.has(fragmentName) ||
816 getInUseByFragmentName(fragmentName).removed));
817 };
818 var enterVisitor = {
819 enter: function (node) {
820 if (fragmentWillBeRemoved(node.name.value)) {
821 return null;
822 }
823 },
824 };
825 return nullIfDocIsEmpty(graphql.visit(docWithoutDirectiveSubtrees, {
826 FragmentSpread: enterVisitor,
827 FragmentDefinition: enterVisitor,
828 OperationDefinition: {
829 leave: function (node) {
830 if (node.variableDefinitions) {
831 var usedVariableNames_1 = populateTransitiveVars(
832 getInUseByOperationName(node.name && node.name.value)).transitiveVars;
833 if (usedVariableNames_1.size < node.variableDefinitions.length) {
834 return tslib.__assign(tslib.__assign({}, node), { variableDefinitions: node.variableDefinitions.filter(function (varDef) {
835 return usedVariableNames_1.has(varDef.variable.name.value);
836 }) });
837 }
838 }
839 },
840 },
841 }));
842}
843var addTypenameToDocument = Object.assign(function (doc) {
844 return graphql.visit(doc, {
845 SelectionSet: {
846 enter: function (node, _key, parent) {
847 if (parent &&
848 parent.kind ===
849 graphql.Kind.OPERATION_DEFINITION) {
850 return;
851 }
852 var selections = node.selections;
853 if (!selections) {
854 return;
855 }
856 var skip = selections.some(function (selection) {
857 return (isField(selection) &&
858 (selection.name.value === "__typename" ||
859 selection.name.value.lastIndexOf("__", 0) === 0));
860 });
861 if (skip) {
862 return;
863 }
864 var field = parent;
865 if (isField(field) &&
866 field.directives &&
867 field.directives.some(function (d) { return d.name.value === "export"; })) {
868 return;
869 }
870 return tslib.__assign(tslib.__assign({}, node), { selections: tslib.__spreadArray(tslib.__spreadArray([], selections, true), [TYPENAME_FIELD], false) });
871 },
872 },
873 });
874}, {
875 added: function (field) {
876 return field === TYPENAME_FIELD;
877 },
878});
879var connectionRemoveConfig = {
880 test: function (directive) {
881 var willRemove = directive.name.value === "connection";
882 if (willRemove) {
883 if (!directive.arguments ||
884 !directive.arguments.some(function (arg) { return arg.name.value === "key"; })) {
885 globalThis.__DEV__ !== false && globals.invariant.warn(84);
886 }
887 }
888 return willRemove;
889 },
890};
891function removeConnectionDirectiveFromDocument(doc) {
892 return removeDirectivesFromDocument([connectionRemoveConfig], checkDocument(doc));
893}
894function getArgumentMatcher(config) {
895 return function argumentMatcher(argument) {
896 return config.some(function (aConfig) {
897 return argument.value &&
898 argument.value.kind === graphql.Kind.VARIABLE &&
899 argument.value.name &&
900 (aConfig.name === argument.value.name.value ||
901 (aConfig.test && aConfig.test(argument)));
902 });
903 };
904}
905function removeArgumentsFromDocument(config, doc) {
906 var argMatcher = getArgumentMatcher(config);
907 return nullIfDocIsEmpty(graphql.visit(doc, {
908 OperationDefinition: {
909 enter: function (node) {
910 return tslib.__assign(tslib.__assign({}, node), {
911 variableDefinitions: node.variableDefinitions ?
912 node.variableDefinitions.filter(function (varDef) {
913 return !config.some(function (arg) { return arg.name === varDef.variable.name.value; });
914 })
915 : [] });
916 },
917 },
918 Field: {
919 enter: function (node) {
920 var shouldRemoveField = config.some(function (argConfig) { return argConfig.remove; });
921 if (shouldRemoveField) {
922 var argMatchCount_1 = 0;
923 if (node.arguments) {
924 node.arguments.forEach(function (arg) {
925 if (argMatcher(arg)) {
926 argMatchCount_1 += 1;
927 }
928 });
929 }
930 if (argMatchCount_1 === 1) {
931 return null;
932 }
933 }
934 },
935 },
936 Argument: {
937 enter: function (node) {
938 if (argMatcher(node)) {
939 return null;
940 }
941 },
942 },
943 }));
944}
945function removeFragmentSpreadFromDocument(config, doc) {
946 function enter(node) {
947 if (config.some(function (def) { return def.name === node.name.value; })) {
948 return null;
949 }
950 }
951 return nullIfDocIsEmpty(graphql.visit(doc, {
952 FragmentSpread: { enter: enter },
953 FragmentDefinition: { enter: enter },
954 }));
955}
956function buildQueryFromSelectionSet(document) {
957 var definition = getMainDefinition(document);
958 var definitionOperation = definition.operation;
959 if (definitionOperation === "query") {
960 return document;
961 }
962 var modifiedDoc = graphql.visit(document, {
963 OperationDefinition: {
964 enter: function (node) {
965 return tslib.__assign(tslib.__assign({}, node), { operation: "query" });
966 },
967 },
968 });
969 return modifiedDoc;
970}
971function removeClientSetsFromDocument(document) {
972 checkDocument(document);
973 var modifiedDoc = removeDirectivesFromDocument([
974 {
975 test: function (directive) { return directive.name.value === "client"; },
976 remove: true,
977 },
978 ], document);
979 return modifiedDoc;
980}
981
982function isOperation(document, operation) {
983 var _a;
984 return ((_a = getOperationDefinition(document)) === null || _a === void 0 ? void 0 : _a.operation) === operation;
985}
986function isMutationOperation(document) {
987 return isOperation(document, "mutation");
988}
989function isQueryOperation(document) {
990 return isOperation(document, "query");
991}
992function isSubscriptionOperation(document) {
993 return isOperation(document, "subscription");
994}
995
996var hasOwnProperty = Object.prototype.hasOwnProperty;
997function mergeDeep() {
998 var sources = [];
999 for (var _i = 0; _i < arguments.length; _i++) {
1000 sources[_i] = arguments[_i];
1001 }
1002 return mergeDeepArray(sources);
1003}
1004function mergeDeepArray(sources) {
1005 var target = sources[0] || {};
1006 var count = sources.length;
1007 if (count > 1) {
1008 var merger = new DeepMerger();
1009 for (var i = 1; i < count; ++i) {
1010 target = merger.merge(target, sources[i]);
1011 }
1012 }
1013 return target;
1014}
1015var defaultReconciler = function (target, source, property) {
1016 return this.merge(target[property], source[property]);
1017};
1018var DeepMerger = (function () {
1019 function DeepMerger(reconciler) {
1020 if (reconciler === void 0) { reconciler = defaultReconciler; }
1021 this.reconciler = reconciler;
1022 this.isObject = isNonNullObject;
1023 this.pastCopies = new Set();
1024 }
1025 DeepMerger.prototype.merge = function (target, source) {
1026 var _this = this;
1027 var context = [];
1028 for (var _i = 2; _i < arguments.length; _i++) {
1029 context[_i - 2] = arguments[_i];
1030 }
1031 if (isNonNullObject(source) && isNonNullObject(target)) {
1032 Object.keys(source).forEach(function (sourceKey) {
1033 if (hasOwnProperty.call(target, sourceKey)) {
1034 var targetValue = target[sourceKey];
1035 if (source[sourceKey] !== targetValue) {
1036 var result = _this.reconciler.apply(_this, tslib.__spreadArray([target,
1037 source,
1038 sourceKey], context, false));
1039 if (result !== targetValue) {
1040 target = _this.shallowCopyForMerge(target);
1041 target[sourceKey] = result;
1042 }
1043 }
1044 }
1045 else {
1046 target = _this.shallowCopyForMerge(target);
1047 target[sourceKey] = source[sourceKey];
1048 }
1049 });
1050 return target;
1051 }
1052 return source;
1053 };
1054 DeepMerger.prototype.shallowCopyForMerge = function (value) {
1055 if (isNonNullObject(value)) {
1056 if (!this.pastCopies.has(value)) {
1057 if (Array.isArray(value)) {
1058 value = value.slice(0);
1059 }
1060 else {
1061 value = tslib.__assign({ __proto__: Object.getPrototypeOf(value) }, value);
1062 }
1063 this.pastCopies.add(value);
1064 }
1065 }
1066 return value;
1067 };
1068 return DeepMerger;
1069}());
1070
1071function concatPagination(keyArgs) {
1072 if (keyArgs === void 0) { keyArgs = false; }
1073 return {
1074 keyArgs: keyArgs,
1075 merge: function (existing, incoming) {
1076 return existing ? tslib.__spreadArray(tslib.__spreadArray([], existing, true), incoming, true) : incoming;
1077 },
1078 };
1079}
1080function offsetLimitPagination(keyArgs) {
1081 if (keyArgs === void 0) { keyArgs = false; }
1082 return {
1083 keyArgs: keyArgs,
1084 merge: function (existing, incoming, _a) {
1085 var args = _a.args;
1086 var merged = existing ? existing.slice(0) : [];
1087 if (incoming) {
1088 if (args) {
1089 var _b = args.offset, offset = _b === void 0 ? 0 : _b;
1090 for (var i = 0; i < incoming.length; ++i) {
1091 merged[offset + i] = incoming[i];
1092 }
1093 }
1094 else {
1095 merged.push.apply(merged, incoming);
1096 }
1097 }
1098 return merged;
1099 },
1100 };
1101}
1102function relayStylePagination(keyArgs) {
1103 if (keyArgs === void 0) { keyArgs = false; }
1104 return {
1105 keyArgs: keyArgs,
1106 read: function (existing, _a) {
1107 var canRead = _a.canRead, readField = _a.readField;
1108 if (!existing)
1109 return existing;
1110 var edges = [];
1111 var firstEdgeCursor = "";
1112 var lastEdgeCursor = "";
1113 existing.edges.forEach(function (edge) {
1114 if (canRead(readField("node", edge))) {
1115 edges.push(edge);
1116 if (edge.cursor) {
1117 firstEdgeCursor = firstEdgeCursor || edge.cursor || "";
1118 lastEdgeCursor = edge.cursor || lastEdgeCursor;
1119 }
1120 }
1121 });
1122 if (edges.length > 1 && firstEdgeCursor === lastEdgeCursor) {
1123 firstEdgeCursor = "";
1124 }
1125 var _b = existing.pageInfo || {}, startCursor = _b.startCursor, endCursor = _b.endCursor;
1126 return tslib.__assign(tslib.__assign({}, getExtras(existing)), { edges: edges, pageInfo: tslib.__assign(tslib.__assign({}, existing.pageInfo), {
1127 startCursor: startCursor || firstEdgeCursor, endCursor: endCursor || lastEdgeCursor }) });
1128 },
1129 merge: function (existing, incoming, _a) {
1130 var args = _a.args, isReference = _a.isReference, readField = _a.readField;
1131 if (!existing) {
1132 existing = makeEmptyData();
1133 }
1134 if (!incoming) {
1135 return existing;
1136 }
1137 var incomingEdges = incoming.edges ?
1138 incoming.edges.map(function (edge) {
1139 if (isReference((edge = tslib.__assign({}, edge)))) {
1140 edge.cursor = readField("cursor", edge);
1141 }
1142 return edge;
1143 })
1144 : [];
1145 if (incoming.pageInfo) {
1146 var pageInfo_1 = incoming.pageInfo;
1147 var startCursor = pageInfo_1.startCursor, endCursor = pageInfo_1.endCursor;
1148 var firstEdge = incomingEdges[0];
1149 var lastEdge = incomingEdges[incomingEdges.length - 1];
1150 if (firstEdge && startCursor) {
1151 firstEdge.cursor = startCursor;
1152 }
1153 if (lastEdge && endCursor) {
1154 lastEdge.cursor = endCursor;
1155 }
1156 var firstCursor = firstEdge && firstEdge.cursor;
1157 if (firstCursor && !startCursor) {
1158 incoming = mergeDeep(incoming, {
1159 pageInfo: {
1160 startCursor: firstCursor,
1161 },
1162 });
1163 }
1164 var lastCursor = lastEdge && lastEdge.cursor;
1165 if (lastCursor && !endCursor) {
1166 incoming = mergeDeep(incoming, {
1167 pageInfo: {
1168 endCursor: lastCursor,
1169 },
1170 });
1171 }
1172 }
1173 var prefix = existing.edges;
1174 var suffix = [];
1175 if (args && args.after) {
1176 var index = prefix.findIndex(function (edge) { return edge.cursor === args.after; });
1177 if (index >= 0) {
1178 prefix = prefix.slice(0, index + 1);
1179 }
1180 }
1181 else if (args && args.before) {
1182 var index = prefix.findIndex(function (edge) { return edge.cursor === args.before; });
1183 suffix = index < 0 ? prefix : prefix.slice(index);
1184 prefix = [];
1185 }
1186 else if (incoming.edges) {
1187 prefix = [];
1188 }
1189 var edges = tslib.__spreadArray(tslib.__spreadArray(tslib.__spreadArray([], prefix, true), incomingEdges, true), suffix, true);
1190 var pageInfo = tslib.__assign(tslib.__assign({}, incoming.pageInfo), existing.pageInfo);
1191 if (incoming.pageInfo) {
1192 var _b = incoming.pageInfo, hasPreviousPage = _b.hasPreviousPage, hasNextPage = _b.hasNextPage, startCursor = _b.startCursor, endCursor = _b.endCursor, extras = tslib.__rest(_b, ["hasPreviousPage", "hasNextPage", "startCursor", "endCursor"]);
1193 Object.assign(pageInfo, extras);
1194 if (!prefix.length) {
1195 if (void 0 !== hasPreviousPage)
1196 pageInfo.hasPreviousPage = hasPreviousPage;
1197 if (void 0 !== startCursor)
1198 pageInfo.startCursor = startCursor;
1199 }
1200 if (!suffix.length) {
1201 if (void 0 !== hasNextPage)
1202 pageInfo.hasNextPage = hasNextPage;
1203 if (void 0 !== endCursor)
1204 pageInfo.endCursor = endCursor;
1205 }
1206 }
1207 return tslib.__assign(tslib.__assign(tslib.__assign({}, getExtras(existing)), getExtras(incoming)), { edges: edges, pageInfo: pageInfo });
1208 },
1209 };
1210}
1211var getExtras = function (obj) { return tslib.__rest(obj, notExtras); };
1212var notExtras = ["edges", "pageInfo"];
1213function makeEmptyData() {
1214 return {
1215 edges: [],
1216 pageInfo: {
1217 hasPreviousPage: false,
1218 hasNextPage: true,
1219 startCursor: "",
1220 endCursor: "",
1221 },
1222 };
1223}
1224
1225function createFulfilledPromise(value) {
1226 var promise = Promise.resolve(value);
1227 promise.status = "fulfilled";
1228 promise.value = value;
1229 return promise;
1230}
1231function createRejectedPromise(reason) {
1232 var promise = Promise.reject(reason);
1233 promise.catch(function () { });
1234 promise.status = "rejected";
1235 promise.reason = reason;
1236 return promise;
1237}
1238function isStatefulPromise(promise) {
1239 return "status" in promise;
1240}
1241function wrapPromiseWithState(promise) {
1242 if (isStatefulPromise(promise)) {
1243 return promise;
1244 }
1245 var pendingPromise = promise;
1246 pendingPromise.status = "pending";
1247 pendingPromise.then(function (value) {
1248 if (pendingPromise.status === "pending") {
1249 var fulfilledPromise = pendingPromise;
1250 fulfilledPromise.status = "fulfilled";
1251 fulfilledPromise.value = value;
1252 }
1253 }, function (reason) {
1254 if (pendingPromise.status === "pending") {
1255 var rejectedPromise = pendingPromise;
1256 rejectedPromise.status = "rejected";
1257 rejectedPromise.reason = reason;
1258 }
1259 });
1260 return promise;
1261}
1262
1263var toString = Object.prototype.toString;
1264function cloneDeep(value) {
1265 return cloneDeepHelper(value);
1266}
1267function cloneDeepHelper(val, seen) {
1268 switch (toString.call(val)) {
1269 case "[object Array]": {
1270 seen = seen || new Map();
1271 if (seen.has(val))
1272 return seen.get(val);
1273 var copy_1 = val.slice(0);
1274 seen.set(val, copy_1);
1275 copy_1.forEach(function (child, i) {
1276 copy_1[i] = cloneDeepHelper(child, seen);
1277 });
1278 return copy_1;
1279 }
1280 case "[object Object]": {
1281 seen = seen || new Map();
1282 if (seen.has(val))
1283 return seen.get(val);
1284 var copy_2 = Object.create(Object.getPrototypeOf(val));
1285 seen.set(val, copy_2);
1286 Object.keys(val).forEach(function (key) {
1287 copy_2[key] = cloneDeepHelper(val[key], seen);
1288 });
1289 return copy_2;
1290 }
1291 default:
1292 return val;
1293 }
1294}
1295
1296function deepFreeze(value) {
1297 var workSet = new Set([value]);
1298 workSet.forEach(function (obj) {
1299 if (isNonNullObject(obj) && shallowFreeze(obj) === obj) {
1300 Object.getOwnPropertyNames(obj).forEach(function (name) {
1301 if (isNonNullObject(obj[name]))
1302 workSet.add(obj[name]);
1303 });
1304 }
1305 });
1306 return value;
1307}
1308function shallowFreeze(obj) {
1309 if (globalThis.__DEV__ !== false && !Object.isFrozen(obj)) {
1310 try {
1311 Object.freeze(obj);
1312 }
1313 catch (e) {
1314 if (e instanceof TypeError)
1315 return null;
1316 throw e;
1317 }
1318 }
1319 return obj;
1320}
1321function maybeDeepFreeze(obj) {
1322 if (globalThis.__DEV__ !== false) {
1323 deepFreeze(obj);
1324 }
1325 return obj;
1326}
1327
1328function iterateObserversSafely(observers, method, argument) {
1329 var observersWithMethod = [];
1330 observers.forEach(function (obs) { return obs[method] && observersWithMethod.push(obs); });
1331 observersWithMethod.forEach(function (obs) { return obs[method](argument); });
1332}
1333
1334function asyncMap(observable, mapFn, catchFn) {
1335 return new zenObservableTs.Observable(function (observer) {
1336 var promiseQueue = {
1337 then: function (callback) {
1338 return new Promise(function (resolve) { return resolve(callback()); });
1339 },
1340 };
1341 function makeCallback(examiner, key) {
1342 return function (arg) {
1343 if (examiner) {
1344 var both = function () {
1345 return observer.closed ?
1346 0
1347 : examiner(arg);
1348 };
1349 promiseQueue = promiseQueue.then(both, both).then(function (result) { return observer.next(result); }, function (error) { return observer.error(error); });
1350 }
1351 else {
1352 observer[key](arg);
1353 }
1354 };
1355 }
1356 var handler = {
1357 next: makeCallback(mapFn, "next"),
1358 error: makeCallback(catchFn, "error"),
1359 complete: function () {
1360 promiseQueue.then(function () { return observer.complete(); });
1361 },
1362 };
1363 var sub = observable.subscribe(handler);
1364 return function () { return sub.unsubscribe(); };
1365 });
1366}
1367
1368function fixObservableSubclass(subclass) {
1369 function set(key) {
1370 Object.defineProperty(subclass, key, { value: zenObservableTs.Observable });
1371 }
1372 if (canUseSymbol && Symbol.species) {
1373 set(Symbol.species);
1374 }
1375 set("@@species");
1376 return subclass;
1377}
1378
1379function isPromiseLike(value) {
1380 return value && typeof value.then === "function";
1381}
1382var Concast = (function (_super) {
1383 tslib.__extends(Concast, _super);
1384 function Concast(sources) {
1385 var _this = _super.call(this, function (observer) {
1386 _this.addObserver(observer);
1387 return function () { return _this.removeObserver(observer); };
1388 }) || this;
1389 _this.observers = new Set();
1390 _this.promise = new Promise(function (resolve, reject) {
1391 _this.resolve = resolve;
1392 _this.reject = reject;
1393 });
1394 _this.handlers = {
1395 next: function (result) {
1396 if (_this.sub !== null) {
1397 _this.latest = ["next", result];
1398 _this.notify("next", result);
1399 iterateObserversSafely(_this.observers, "next", result);
1400 }
1401 },
1402 error: function (error) {
1403 var sub = _this.sub;
1404 if (sub !== null) {
1405 if (sub)
1406 setTimeout(function () { return sub.unsubscribe(); });
1407 _this.sub = null;
1408 _this.latest = ["error", error];
1409 _this.reject(error);
1410 _this.notify("error", error);
1411 iterateObserversSafely(_this.observers, "error", error);
1412 }
1413 },
1414 complete: function () {
1415 var _a = _this, sub = _a.sub, _b = _a.sources, sources = _b === void 0 ? [] : _b;
1416 if (sub !== null) {
1417 var value = sources.shift();
1418 if (!value) {
1419 if (sub)
1420 setTimeout(function () { return sub.unsubscribe(); });
1421 _this.sub = null;
1422 if (_this.latest && _this.latest[0] === "next") {
1423 _this.resolve(_this.latest[1]);
1424 }
1425 else {
1426 _this.resolve();
1427 }
1428 _this.notify("complete");
1429 iterateObserversSafely(_this.observers, "complete");
1430 }
1431 else if (isPromiseLike(value)) {
1432 value.then(function (obs) { return (_this.sub = obs.subscribe(_this.handlers)); }, _this.handlers.error);
1433 }
1434 else {
1435 _this.sub = value.subscribe(_this.handlers);
1436 }
1437 }
1438 },
1439 };
1440 _this.nextResultListeners = new Set();
1441 _this.cancel = function (reason) {
1442 _this.reject(reason);
1443 _this.sources = [];
1444 _this.handlers.complete();
1445 };
1446 _this.promise.catch(function (_) { });
1447 if (typeof sources === "function") {
1448 sources = [new zenObservableTs.Observable(sources)];
1449 }
1450 if (isPromiseLike(sources)) {
1451 sources.then(function (iterable) { return _this.start(iterable); }, _this.handlers.error);
1452 }
1453 else {
1454 _this.start(sources);
1455 }
1456 return _this;
1457 }
1458 Concast.prototype.start = function (sources) {
1459 if (this.sub !== void 0)
1460 return;
1461 this.sources = Array.from(sources);
1462 this.handlers.complete();
1463 };
1464 Concast.prototype.deliverLastMessage = function (observer) {
1465 if (this.latest) {
1466 var nextOrError = this.latest[0];
1467 var method = observer[nextOrError];
1468 if (method) {
1469 method.call(observer, this.latest[1]);
1470 }
1471 if (this.sub === null && nextOrError === "next" && observer.complete) {
1472 observer.complete();
1473 }
1474 }
1475 };
1476 Concast.prototype.addObserver = function (observer) {
1477 if (!this.observers.has(observer)) {
1478 this.deliverLastMessage(observer);
1479 this.observers.add(observer);
1480 }
1481 };
1482 Concast.prototype.removeObserver = function (observer) {
1483 if (this.observers.delete(observer) && this.observers.size < 1) {
1484 this.handlers.complete();
1485 }
1486 };
1487 Concast.prototype.notify = function (method, arg) {
1488 var nextResultListeners = this.nextResultListeners;
1489 if (nextResultListeners.size) {
1490 this.nextResultListeners = new Set();
1491 nextResultListeners.forEach(function (listener) { return listener(method, arg); });
1492 }
1493 };
1494 Concast.prototype.beforeNext = function (callback) {
1495 var called = false;
1496 this.nextResultListeners.add(function (method, arg) {
1497 if (!called) {
1498 called = true;
1499 callback(method, arg);
1500 }
1501 });
1502 };
1503 return Concast;
1504}(zenObservableTs.Observable));
1505fixObservableSubclass(Concast);
1506
1507function isExecutionPatchIncrementalResult(value) {
1508 return "incremental" in value;
1509}
1510function isExecutionPatchInitialResult(value) {
1511 return "hasNext" in value && "data" in value;
1512}
1513function isExecutionPatchResult(value) {
1514 return (isExecutionPatchIncrementalResult(value) ||
1515 isExecutionPatchInitialResult(value));
1516}
1517function isApolloPayloadResult(value) {
1518 return isNonNullObject(value) && "payload" in value;
1519}
1520function mergeIncrementalData(prevResult, result) {
1521 var mergedData = prevResult;
1522 var merger = new DeepMerger();
1523 if (isExecutionPatchIncrementalResult(result) &&
1524 isNonEmptyArray(result.incremental)) {
1525 result.incremental.forEach(function (_a) {
1526 var data = _a.data, path = _a.path;
1527 for (var i = path.length - 1; i >= 0; --i) {
1528 var key = path[i];
1529 var isNumericKey = !isNaN(+key);
1530 var parent_1 = isNumericKey ? [] : {};
1531 parent_1[key] = data;
1532 data = parent_1;
1533 }
1534 mergedData = merger.merge(mergedData, data);
1535 });
1536 }
1537 return mergedData;
1538}
1539
1540function graphQLResultHasError(result) {
1541 var errors = getGraphQLErrorsFromResult(result);
1542 return isNonEmptyArray(errors);
1543}
1544function getGraphQLErrorsFromResult(result) {
1545 var graphQLErrors = isNonEmptyArray(result.errors) ? result.errors.slice(0) : [];
1546 if (isExecutionPatchIncrementalResult(result) &&
1547 isNonEmptyArray(result.incremental)) {
1548 result.incremental.forEach(function (incrementalResult) {
1549 if (incrementalResult.errors) {
1550 graphQLErrors.push.apply(graphQLErrors, incrementalResult.errors);
1551 }
1552 });
1553 }
1554 return graphQLErrors;
1555}
1556
1557function compact() {
1558 var objects = [];
1559 for (var _i = 0; _i < arguments.length; _i++) {
1560 objects[_i] = arguments[_i];
1561 }
1562 var result = Object.create(null);
1563 objects.forEach(function (obj) {
1564 if (!obj)
1565 return;
1566 Object.keys(obj).forEach(function (key) {
1567 var value = obj[key];
1568 if (value !== void 0) {
1569 result[key] = value;
1570 }
1571 });
1572 });
1573 return result;
1574}
1575
1576var prefixCounts = new Map();
1577function makeUniqueId(prefix) {
1578 var count = prefixCounts.get(prefix) || 1;
1579 prefixCounts.set(prefix, count + 1);
1580 return "".concat(prefix, ":").concat(count, ":").concat(Math.random().toString(36).slice(2));
1581}
1582
1583function stringifyForDisplay(value, space) {
1584 if (space === void 0) { space = 0; }
1585 var undefId = makeUniqueId("stringifyForDisplay");
1586 return JSON.stringify(value, function (key, value) {
1587 return value === void 0 ? undefId : value;
1588 }, space)
1589 .split(JSON.stringify(undefId))
1590 .join("<undefined>");
1591}
1592
1593function mergeOptions(defaults, options) {
1594 return compact(defaults, options, options.variables && {
1595 variables: compact(tslib.__assign(tslib.__assign({}, (defaults && defaults.variables)), options.variables)),
1596 });
1597}
1598
1599function omitDeep(value, key) {
1600 return __omitDeep(value, key);
1601}
1602function __omitDeep(value, key, known) {
1603 if (known === void 0) { known = new Map(); }
1604 if (known.has(value)) {
1605 return known.get(value);
1606 }
1607 var modified = false;
1608 if (Array.isArray(value)) {
1609 var array_1 = [];
1610 known.set(value, array_1);
1611 value.forEach(function (value, index) {
1612 var result = __omitDeep(value, key, known);
1613 modified || (modified = result !== value);
1614 array_1[index] = result;
1615 });
1616 if (modified) {
1617 return array_1;
1618 }
1619 }
1620 else if (isPlainObject(value)) {
1621 var obj_1 = Object.create(Object.getPrototypeOf(value));
1622 known.set(value, obj_1);
1623 Object.keys(value).forEach(function (k) {
1624 if (k === key) {
1625 modified = true;
1626 return;
1627 }
1628 var result = __omitDeep(value[k], key, known);
1629 modified || (modified = result !== value[k]);
1630 obj_1[k] = result;
1631 });
1632 if (modified) {
1633 return obj_1;
1634 }
1635 }
1636 return value;
1637}
1638
1639function stripTypename(value) {
1640 return omitDeep(value, "__typename");
1641}
1642
1643exports.DEV = globals.DEV;
1644exports.maybe = globals.maybe;
1645exports.Observable = zenObservableTs.Observable;
1646exports.AutoCleanedStrongCache = AutoCleanedStrongCache;
1647exports.AutoCleanedWeakCache = AutoCleanedWeakCache;
1648exports.Concast = Concast;
1649exports.DeepMerger = DeepMerger;
1650exports.DocumentTransform = DocumentTransform;
1651exports.addTypenameToDocument = addTypenameToDocument;
1652exports.argumentsObjectFromField = argumentsObjectFromField;
1653exports.asyncMap = asyncMap;
1654exports.buildQueryFromSelectionSet = buildQueryFromSelectionSet;
1655exports.cacheSizes = cacheSizes;
1656exports.canUseAsyncIteratorSymbol = canUseAsyncIteratorSymbol;
1657exports.canUseDOM = canUseDOM;
1658exports.canUseLayoutEffect = canUseLayoutEffect;
1659exports.canUseSymbol = canUseSymbol;
1660exports.canUseWeakMap = canUseWeakMap;
1661exports.canUseWeakSet = canUseWeakSet;
1662exports.canonicalStringify = canonicalStringify;
1663exports.checkDocument = checkDocument;
1664exports.cloneDeep = cloneDeep;
1665exports.compact = compact;
1666exports.concatPagination = concatPagination;
1667exports.createFragmentMap = createFragmentMap;
1668exports.createFulfilledPromise = createFulfilledPromise;
1669exports.createRejectedPromise = createRejectedPromise;
1670exports.fixObservableSubclass = fixObservableSubclass;
1671exports.getDefaultValues = getDefaultValues;
1672exports.getDirectiveNames = getDirectiveNames;
1673exports.getFragmentDefinition = getFragmentDefinition;
1674exports.getFragmentDefinitions = getFragmentDefinitions;
1675exports.getFragmentFromSelection = getFragmentFromSelection;
1676exports.getFragmentQueryDocument = getFragmentQueryDocument;
1677exports.getGraphQLErrorsFromResult = getGraphQLErrorsFromResult;
1678exports.getInclusionDirectives = getInclusionDirectives;
1679exports.getMainDefinition = getMainDefinition;
1680exports.getOperationDefinition = getOperationDefinition;
1681exports.getOperationName = getOperationName;
1682exports.getQueryDefinition = getQueryDefinition;
1683exports.getStoreKeyName = getStoreKeyName;
1684exports.getTypenameFromResult = getTypenameFromResult;
1685exports.graphQLResultHasError = graphQLResultHasError;
1686exports.hasAllDirectives = hasAllDirectives;
1687exports.hasAnyDirectives = hasAnyDirectives;
1688exports.hasClientExports = hasClientExports;
1689exports.hasDirectives = hasDirectives;
1690exports.isApolloPayloadResult = isApolloPayloadResult;
1691exports.isArray = isArray;
1692exports.isDocumentNode = isDocumentNode;
1693exports.isExecutionPatchIncrementalResult = isExecutionPatchIncrementalResult;
1694exports.isExecutionPatchInitialResult = isExecutionPatchInitialResult;
1695exports.isExecutionPatchResult = isExecutionPatchResult;
1696exports.isField = isField;
1697exports.isInlineFragment = isInlineFragment;
1698exports.isMutationOperation = isMutationOperation;
1699exports.isNonEmptyArray = isNonEmptyArray;
1700exports.isNonNullObject = isNonNullObject;
1701exports.isPlainObject = isPlainObject;
1702exports.isQueryOperation = isQueryOperation;
1703exports.isReference = isReference;
1704exports.isStatefulPromise = isStatefulPromise;
1705exports.isSubscriptionOperation = isSubscriptionOperation;
1706exports.iterateObserversSafely = iterateObserversSafely;
1707exports.makeReference = makeReference;
1708exports.makeUniqueId = makeUniqueId;
1709exports.maybeDeepFreeze = maybeDeepFreeze;
1710exports.mergeDeep = mergeDeep;
1711exports.mergeDeepArray = mergeDeepArray;
1712exports.mergeIncrementalData = mergeIncrementalData;
1713exports.mergeOptions = mergeOptions;
1714exports.offsetLimitPagination = offsetLimitPagination;
1715exports.omitDeep = omitDeep;
1716exports.print = print;
1717exports.relayStylePagination = relayStylePagination;
1718exports.removeArgumentsFromDocument = removeArgumentsFromDocument;
1719exports.removeClientSetsFromDocument = removeClientSetsFromDocument;
1720exports.removeConnectionDirectiveFromDocument = removeConnectionDirectiveFromDocument;
1721exports.removeDirectivesFromDocument = removeDirectivesFromDocument;
1722exports.removeFragmentSpreadFromDocument = removeFragmentSpreadFromDocument;
1723exports.resultKeyNameFromField = resultKeyNameFromField;
1724exports.shouldInclude = shouldInclude;
1725exports.storeKeyNameFromField = storeKeyNameFromField;
1726exports.stringifyForDisplay = stringifyForDisplay;
1727exports.stripTypename = stripTypename;
1728exports.valueToObjectRepresentation = valueToObjectRepresentation;
1729exports.wrapPromiseWithState = wrapPromiseWithState;
1730//# sourceMappingURL=utilities.cjs.map