UNPKG

@apollo/client

Version:

A fully-featured caching GraphQL client.

1 lines 110 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("ts-invariant"),r=require("@wry/equality"),n=require("zen-observable-ts");require("symbol-observable");var i=require("graphql"),o=require("optimism"),a=require("@wry/context"),s=require("@wry/trie"),u=require("graphql-tag"),c=require("react");function l(e){if(e&&e.__esModule)return e;var t=Object.create(null);if(e)for(var r in e)t[r]=e[r];return t.default=e,Object.freeze(t)}var f=l(c);function h(e){try{return e()}catch(e){}}function p(e,r){var n=e.directives;return!n||!n.length||function(e){var r=[];e&&e.length&&e.forEach((function(e){if(function(e){var t=e.name.value;return"skip"===t||"include"===t}(e)){var n=e.arguments;e.name.value;t.invariant(n&&1===n.length,38);var i=n[0];t.invariant(i.name&&"if"===i.name.value,39);var o=i.value;t.invariant(o&&("Variable"===o.kind||"BooleanValue"===o.kind),40),r.push({directive:e,ifArgument:i})}}));return r}(n).every((function(e){var n=e.directive,i=e.ifArgument,o=!1;return"Variable"===i.value.kind?(o=r&&r[i.value.name.value],t.invariant(void 0!==o,37)):o=i.value.value,"skip"===n.name.value?!o:o}))}function d(e,t){return function(e){var t=[];return i.visit(e,{Directive:function(e){t.push(e.name.value)}}),t}(t).some((function(t){return e.indexOf(t)>-1}))}function v(e){return e&&d(["client"],e)&&d(["export"],e)}function y(r,n){var i=n,o=[];return r.definitions.forEach((function(e){if("OperationDefinition"===e.kind)throw new t.InvariantError(41);"FragmentDefinition"===e.kind&&o.push(e)})),void 0===i&&(t.invariant(1===o.length,42),i=o[0].name.value),e.__assign(e.__assign({},r),{definitions:e.__spreadArray([{kind:"OperationDefinition",operation:"query",selectionSet:{kind:"SelectionSet",selections:[{kind:"FragmentSpread",name:{kind:"Name",value:i}}]}}],r.definitions,!0)})}function m(e){void 0===e&&(e=[]);var t={};return e.forEach((function(e){t[e.name.value]=e})),t}function g(e,r){switch(e.kind){case"InlineFragment":return e;case"FragmentSpread":var n=r&&r[e.name.value];return t.invariant(n,43),n;default:return null}}function b(e){return null!==e&&"object"==typeof e}function _(e){return{__ref:String(e)}}function O(e){return Boolean(e&&"object"==typeof e&&"string"==typeof e.__ref)}function w(e,r,n,i){if(function(e){return"IntValue"===e.kind}(n)||function(e){return"FloatValue"===e.kind}(n))e[r.value]=Number(n.value);else if(function(e){return"BooleanValue"===e.kind}(n)||function(e){return"StringValue"===e.kind}(n))e[r.value]=n.value;else if(function(e){return"ObjectValue"===e.kind}(n)){var o={};n.fields.map((function(e){return w(o,e.name,e.value,i)})),e[r.value]=o}else if(function(e){return"Variable"===e.kind}(n)){var a=(i||{})[n.name.value];e[r.value]=a}else if(function(e){return"ListValue"===e.kind}(n))e[r.value]=n.values.map((function(e){var t={};return w(t,r,e,i),t[r.value]}));else if(function(e){return"EnumValue"===e.kind}(n))e[r.value]=n.value;else{if(!function(e){return"NullValue"===e.kind}(n))throw new t.InvariantError(52);e[r.value]=null}}var k=["connection","include","skip","client","rest","export"],S=Object.assign((function(e,t,r){if(t&&r&&r.connection&&r.connection.key){if(r.connection.filter&&r.connection.filter.length>0){var n=r.connection.filter?r.connection.filter:[];n.sort();var i={};return n.forEach((function(e){i[e]=t[e]})),"".concat(r.connection.key,"(").concat(x(i),")")}return r.connection.key}var o=e;if(t){var a=x(t);o+="(".concat(a,")")}return r&&Object.keys(r).forEach((function(e){-1===k.indexOf(e)&&(r[e]&&Object.keys(r[e]).length?o+="@".concat(e,"(").concat(x(r[e]),")"):o+="@".concat(e))})),o}),{setStringify:function(e){var t=x;return x=e,t}}),x=function(e){return JSON.stringify(e,q)};function q(e,t){return b(t)&&!Array.isArray(t)&&(t=Object.keys(t).sort().reduce((function(e,r){return e[r]=t[r],e}),{})),t}function E(e,t){if(e.arguments&&e.arguments.length){var r={};return e.arguments.forEach((function(e){var n=e.name,i=e.value;return w(r,n,i,t)})),r}return null}function R(e){return e.alias?e.alias.value:e.name.value}function P(e,t,r){if("string"==typeof e.__typename)return e.__typename;for(var n=0,i=t.selections;n<i.length;n++){var o=i[n];if(Q(o)){if("__typename"===o.name.value)return e[R(o)]}else{var a=P(e,g(o,r).selectionSet,r);if("string"==typeof a)return a}}}function Q(e){return"Field"===e.kind}function F(e){return"InlineFragment"===e.kind}function C(e){t.invariant(e&&"Document"===e.kind,44);var r=e.definitions.filter((function(e){return"FragmentDefinition"!==e.kind})).map((function(e){if("OperationDefinition"!==e.kind)throw new t.InvariantError(45);return e}));return t.invariant(r.length<=1,46),e}function M(e){return C(e),e.definitions.filter((function(e){return"OperationDefinition"===e.kind}))[0]}function I(e){return e.definitions.filter((function(e){return"OperationDefinition"===e.kind&&e.name})).map((function(e){return e.name.value}))[0]||null}function D(e){return e.definitions.filter((function(e){return"FragmentDefinition"===e.kind}))}function T(e){var r=M(e);return t.invariant(r&&"query"===r.operation,47),r}function j(e){var r;C(e);for(var n=0,i=e.definitions;n<i.length;n++){var o=i[n];if("OperationDefinition"===o.kind){var a=o.operation;if("query"===a||"mutation"===a||"subscription"===a)return o}"FragmentDefinition"!==o.kind||r||(r=o)}if(r)return r;throw new t.InvariantError(51)}function N(e){var t=Object.create(null),r=e&&e.variableDefinitions;return r&&r.length&&r.forEach((function(e){e.defaultValue&&w(t,e.variable.name,e.defaultValue)})),t}function A(e,t,r){var n=0;return e.forEach((function(r,i){t.call(this,r,i,e)&&(e[n++]=r)}),r),e.length=n,e}var L={kind:"Field",name:{kind:"Name",value:"__typename"}};function V(e,t){return e.selectionSet.selections.every((function(e){return"FragmentSpread"===e.kind&&V(t[e.name.value],t)}))}function W(e){return V(M(e)||function(e){t.invariant("Document"===e.kind,48),t.invariant(e.definitions.length<=1,49);var r=e.definitions[0];return t.invariant("FragmentDefinition"===r.kind,50),r}(e),m(D(e)))?null:e}function z(e){return function(t){return e.some((function(e){return e.name&&e.name===t.name.value||e.test&&e.test(t)}))}}function B(t,r){var n=Object.create(null),o=[],a=Object.create(null),s=[],u=W(i.visit(r,{Variable:{enter:function(e,t,r){"VariableDefinition"!==r.kind&&(n[e.name.value]=!0)}},Field:{enter:function(e){if(t&&e.directives&&(t.some((function(e){return e.remove}))&&e.directives&&e.directives.some(z(t))))return e.arguments&&e.arguments.forEach((function(e){"Variable"===e.value.kind&&o.push({name:e.value.name.value})})),e.selectionSet&&J(e.selectionSet).forEach((function(e){s.push({name:e.name.value})})),null}},FragmentSpread:{enter:function(e){a[e.name.value]=!0}},Directive:{enter:function(e){if(z(t)(e))return null}}}));return u&&A(o,(function(e){return!!e.name&&!n[e.name]})).length&&(u=function(t,r){var n=function(e){return function(t){return e.some((function(e){return t.value&&"Variable"===t.value.kind&&t.value.name&&(e.name===t.value.name.value||e.test&&e.test(t))}))}}(t);return W(i.visit(r,{OperationDefinition:{enter:function(r){return e.__assign(e.__assign({},r),{variableDefinitions:r.variableDefinitions?r.variableDefinitions.filter((function(e){return!t.some((function(t){return t.name===e.variable.name.value}))})):[]})}},Field:{enter:function(e){if(t.some((function(e){return e.remove}))){var r=0;if(e.arguments&&e.arguments.forEach((function(e){n(e)&&(r+=1)})),1===r)return null}}},Argument:{enter:function(e){if(n(e))return null}}}))}(o,u)),u&&A(s,(function(e){return!!e.name&&!a[e.name]})).length&&(u=function(e,t){function r(t){if(e.some((function(e){return e.name===t.name.value})))return null}return W(i.visit(t,{FragmentSpread:{enter:r},FragmentDefinition:{enter:r}}))}(s,u)),u}var U=Object.assign((function(t){return i.visit(t,{SelectionSet:{enter:function(t,r,n){if(!n||"OperationDefinition"!==n.kind){var i=t.selections;if(i)if(!i.some((function(e){return Q(e)&&("__typename"===e.name.value||0===e.name.value.lastIndexOf("__",0))}))){var o=n;if(!(Q(o)&&o.directives&&o.directives.some((function(e){return"export"===e.name.value}))))return e.__assign(e.__assign({},t),{selections:e.__spreadArray(e.__spreadArray([],i,!0),[L],!1)})}}}}})}),{added:function(e){return e===L}}),H={test:function(e){var t="connection"===e.name.value;return t&&(!e.arguments||e.arguments.some((function(e){return"key"===e.name.value}))),t}};function J(e){var t=[];return e.selections.forEach((function(e){(Q(e)||F(e))&&e.selectionSet?J(e.selectionSet).forEach((function(e){return t.push(e)})):"FragmentSpread"===e.kind&&t.push(e)})),t}function K(t){return"query"===j(t).operation?t:i.visit(t,{OperationDefinition:{enter:function(t){return e.__assign(e.__assign({},t),{operation:"query"})}}})}var Y=Object.prototype.hasOwnProperty;function G(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return X(e)}function X(e){var t=e[0]||{},r=e.length;if(r>1)for(var n=new Z,i=1;i<r;++i)t=n.merge(t,e[i]);return t}var $=function(e,t,r){return this.merge(e[r],t[r])},Z=function(){function t(e){void 0===e&&(e=$),this.reconciler=e,this.isObject=b,this.pastCopies=new Set}return t.prototype.merge=function(t,r){for(var n=this,i=[],o=2;o<arguments.length;o++)i[o-2]=arguments[o];return b(r)&&b(t)?(Object.keys(r).forEach((function(o){if(Y.call(t,o)){var a=t[o];if(r[o]!==a){var s=n.reconciler.apply(n,e.__spreadArray([t,r,o],i,!1));s!==a&&((t=n.shallowCopyForMerge(t))[o]=s)}}else(t=n.shallowCopyForMerge(t))[o]=r[o]})),t):r},t.prototype.shallowCopyForMerge=function(t){return b(t)&&(this.pastCopies.has(t)||(t=Array.isArray(t)?t.slice(0):e.__assign({__proto__:Object.getPrototypeOf(t)},t),this.pastCopies.add(t))),t},t}(),ee=Object.prototype.toString;function te(e){return re(e)}function re(e,t){switch(ee.call(e)){case"[object Array]":if((t=t||new Map).has(e))return t.get(e);var r=e.slice(0);return t.set(e,r),r.forEach((function(e,n){r[n]=re(e,t)})),r;case"[object Object]":if((t=t||new Map).has(e))return t.get(e);var n=Object.create(Object.getPrototypeOf(e));return t.set(e,n),Object.keys(e).forEach((function(r){n[r]=re(e[r],t)})),n;default:return e}}function ne(e,t,r){var n=[];e.forEach((function(e){return e[t]&&n.push(e)})),n.forEach((function(e){return e[t](r)}))}function ie(e,t,r){return new n.Observable((function(n){var i=n.next,o=n.error,a=n.complete,s=0,u=!1,c={then:function(e){return new Promise((function(t){return t(e())}))}};function l(e,t){return e?function(t){++s;var r=function(){return e(t)};c=c.then(r,r).then((function(e){--s,i&&i.call(n,e),u&&f.complete()}),(function(e){throw--s,e})).catch((function(e){o&&o.call(n,e)}))}:function(e){return t&&t.call(n,e)}}var f={next:l(t,i),error:l(r,o),complete:function(){u=!0,s||a&&a.call(n)}},h=e.subscribe(f);return function(){return h.unsubscribe()}}))}var oe="function"==typeof WeakMap&&"ReactNative"!==h((function(){return navigator.product})),ae="function"==typeof WeakSet,se="function"==typeof Symbol&&"function"==typeof Symbol.for,ue="function"==typeof h((function(){return window.document.createElement})),ce=h((function(){return navigator.userAgent.indexOf("jsdom")>=0}))||!1,le=ue&&!ce;function fe(e){function t(t){Object.defineProperty(e,t,{value:n.Observable})}return se&&Symbol.species&&t(Symbol.species),t("@@species"),e}function he(e){return e&&"function"==typeof e.then}var pe=function(t){function r(e){var r=t.call(this,(function(e){return r.addObserver(e),function(){return r.removeObserver(e)}}))||this;return r.observers=new Set,r.addCount=0,r.promise=new Promise((function(e,t){r.resolve=e,r.reject=t})),r.handlers={next:function(e){null!==r.sub&&(r.latest=["next",e],ne(r.observers,"next",e))},error:function(e){var t=r.sub;null!==t&&(t&&setTimeout((function(){return t.unsubscribe()})),r.sub=null,r.latest=["error",e],r.reject(e),ne(r.observers,"error",e))},complete:function(){var e=r.sub;if(null!==e){var t=r.sources.shift();t?he(t)?t.then((function(e){return r.sub=e.subscribe(r.handlers)})):r.sub=t.subscribe(r.handlers):(e&&setTimeout((function(){return e.unsubscribe()})),r.sub=null,r.latest&&"next"===r.latest[0]?r.resolve(r.latest[1]):r.resolve(),ne(r.observers,"complete"))}}},r.cancel=function(e){r.reject(e),r.sources=[],r.handlers.complete()},r.promise.catch((function(e){})),"function"==typeof e&&(e=[new n.Observable(e)]),he(e)?e.then((function(e){return r.start(e)}),r.handlers.error):r.start(e),r}return e.__extends(r,t),r.prototype.start=function(e){void 0===this.sub&&(this.sources=Array.from(e),this.handlers.complete())},r.prototype.deliverLastMessage=function(e){if(this.latest){var t=this.latest[0],r=e[t];r&&r.call(e,this.latest[1]),null===this.sub&&"next"===t&&e.complete&&e.complete()}},r.prototype.addObserver=function(e){this.observers.has(e)||(this.deliverLastMessage(e),this.observers.add(e),++this.addCount)},r.prototype.removeObserver=function(e,t){this.observers.delete(e)&&--this.addCount<1&&!t&&this.handlers.complete()},r.prototype.cleanup=function(e){var t=this,r=!1,n=function(){r||(r=!0,t.observers.delete(i),e())},i={next:n,error:n,complete:n},o=this.addCount;this.addObserver(i),this.addCount=o},r}(n.Observable);function de(e){return Array.isArray(e)&&e.length>0}function ve(e){return e.errors&&e.errors.length>0||!1}function ye(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r=Object.create(null);return e.forEach((function(e){e&&Object.keys(e).forEach((function(t){var n=e[t];void 0!==n&&(r[t]=n)}))})),r}fe(pe);var me=new Map;function ge(e){var t=me.get(e)||1;return me.set(e,t+1),"".concat(e,":").concat(t,":").concat(Math.random().toString(36).slice(2))}function be(t,r){return ye(t,r,r.variables&&{variables:e.__assign(e.__assign({},t&&t.variables),r.variables)})}function _e(e){return new n.Observable((function(t){t.error(e)}))}var Oe=function(e,t,r){var n=new Error(r);throw n.name="ServerError",n.response=e,n.statusCode=e.status,n.result=t,n};function we(e,t){return t?t(e):n.Observable.of()}function ke(e){return"function"==typeof e?new xe(e):e}function Se(e){return e.request.length<=1}!function(t){function r(e,r){var n=t.call(this,e)||this;return n.link=r,n}e.__extends(r,t)}(Error);var xe=function(){function r(e){e&&(this.request=e)}return r.empty=function(){return new r((function(){return n.Observable.of()}))},r.from=function(e){return 0===e.length?r.empty():e.map(ke).reduce((function(e,t){return e.concat(t)}))},r.split=function(e,t,i){var o=ke(t),a=ke(i||new r(we));return Se(o)&&Se(a)?new r((function(t){return e(t)?o.request(t)||n.Observable.of():a.request(t)||n.Observable.of()})):new r((function(t,r){return e(t)?o.request(t,r)||n.Observable.of():a.request(t,r)||n.Observable.of()}))},r.execute=function(r,i){return r.request(function(t,r){var n=e.__assign({},t);return Object.defineProperty(r,"setContext",{enumerable:!1,value:function(t){n="function"==typeof t?e.__assign(e.__assign({},n),t(n)):e.__assign(e.__assign({},n),t)}}),Object.defineProperty(r,"getContext",{enumerable:!1,value:function(){return e.__assign({},n)}}),r}(i.context,function(e){var t={variables:e.variables||{},extensions:e.extensions||{},operationName:e.operationName,query:e.query};return t.operationName||(t.operationName="string"!=typeof t.query?I(t.query)||void 0:""),t}(function(e){for(var r=["query","operationName","variables","extensions","context"],n=0,i=Object.keys(e);n<i.length;n++){var o=i[n];if(r.indexOf(o)<0)throw new t.InvariantError(24)}return e}(i))))||n.Observable.of()},r.concat=function(e,t){var i=ke(e);if(Se(i))return i;var o=ke(t);return Se(o)?new r((function(e){return i.request(e,(function(e){return o.request(e)||n.Observable.of()}))||n.Observable.of()})):new r((function(e,t){return i.request(e,(function(e){return o.request(e,t)||n.Observable.of()}))||n.Observable.of()}))},r.prototype.split=function(e,t,n){return this.concat(r.split(e,t,n||new r(we)))},r.prototype.concat=function(e){return r.concat(this,e)},r.prototype.request=function(e,r){throw new t.InvariantError(19)},r.prototype.onError=function(e,t){if(t&&t.error)return t.error(e),!1;throw e},r.prototype.setOnError=function(e){return this.onError=e,this},r}(),qe=xe.empty,Ee=xe.from,Re=xe.split,Pe=xe.concat,Qe=xe.execute,Fe=Object.prototype.hasOwnProperty;function Ce(e){return function(t){return t.text().then((function(e){try{return JSON.parse(e)}catch(n){var r=n;throw r.name="ServerParseError",r.response=t,r.statusCode=t.status,r.bodyText=e,r}})).then((function(r){return t.status>=300&&Oe(t,r,"Response not successful: Received status code ".concat(t.status)),Array.isArray(r)||Fe.call(r,"data")||Fe.call(r,"errors")||Oe(t,r,"Server response was missing for query '".concat(Array.isArray(e)?e.map((function(e){return e.operationName})):e.operationName,"'.")),r}))}}var Me=function(e,r){var n;try{n=JSON.stringify(e)}catch(e){var i=new t.InvariantError(21);throw i.parseError=e,i}return n},Ie={http:{includeQuery:!0,includeExtensions:!1},headers:{accept:"*/*","content-type":"application/json"},options:{method:"POST"}},De=function(e,t){return t(e)};function Te(t,r){for(var n=[],o=2;o<arguments.length;o++)n[o-2]=arguments[o];var a={},s={};n.forEach((function(t){a=e.__assign(e.__assign(e.__assign({},a),t.options),{headers:e.__assign(e.__assign({},a.headers),je(t.headers))}),t.credentials&&(a.credentials=t.credentials),s=e.__assign(e.__assign({},s),t.http)}));var u=t.operationName,c=t.extensions,l=t.variables,f=t.query,h={operationName:u,variables:l};return s.includeExtensions&&(h.extensions=c),s.includeQuery&&(h.query=r(f,i.print)),{options:a,body:h}}function je(e){if(e){var t=Object.create(null);return Object.keys(Object(e)).forEach((function(r){t[r.toLowerCase()]=e[r]})),t}return e}var Ne=function(e){if(!e&&"undefined"==typeof fetch)throw new t.InvariantError(20)},Ae=function(){if("undefined"==typeof AbortController)return{controller:!1,signal:!1};var e=new AbortController;return{controller:e,signal:e.signal}},Le=function(e,t){var r=e.getContext().uri;return r||("function"==typeof t?t(e):t||"/graphql")};function Ve(e,t){var r=[],n=function(e,t){r.push("".concat(e,"=").concat(encodeURIComponent(t)))};if("query"in t&&n("query",t.query),t.operationName&&n("operationName",t.operationName),t.variables){var i=void 0;try{i=Me(t.variables)}catch(e){return{parseError:e}}n("variables",i)}if(t.extensions){var o=void 0;try{o=Me(t.extensions)}catch(e){return{parseError:e}}n("extensions",o)}var a="",s=e,u=e.indexOf("#");-1!==u&&(a=e.substr(u),s=e.substr(0,u));var c=-1===s.indexOf("?")?"?":"&";return{newURI:s+c+r.join("&")+a}}var We=h((function(){return fetch})),ze=function(t){void 0===t&&(t={});var r=t.uri,o=void 0===r?"/graphql":r,a=t.fetch,s=t.print,u=void 0===s?De:s,c=t.includeExtensions,l=t.useGETForQueries,f=t.includeUnusedVariables,p=void 0!==f&&f,d=e.__rest(t,["uri","fetch","print","includeExtensions","useGETForQueries","includeUnusedVariables"]);var v={http:{includeExtensions:c},options:d.fetchOptions,credentials:d.credentials,headers:d.headers};return new xe((function(t){var r=Le(t,o),s=t.getContext(),c={};if(s.clientAwareness){var f=s.clientAwareness,d=f.name,y=f.version;d&&(c["apollographql-client-name"]=d),y&&(c["apollographql-client-version"]=y)}var m,g=e.__assign(e.__assign({},c),s.headers),b={http:s.http,options:s.fetchOptions,credentials:s.credentials,headers:g},_=Te(t,u,Ie,v,b),O=_.options,w=_.body;if(w.variables&&!p){var k=new Set(Object.keys(w.variables));i.visit(t.query,{Variable:function(e,t,r){r&&"VariableDefinition"!==r.kind&&k.delete(e.name.value)}}),k.size&&(w.variables=e.__assign({},w.variables),k.forEach((function(e){delete w.variables[e]})))}if(!O.signal){var S=Ae(),x=S.controller,q=S.signal;(m=x)&&(O.signal=q)}if(l&&!t.query.definitions.some((function(e){return"OperationDefinition"===e.kind&&"mutation"===e.operation}))&&(O.method="GET"),"GET"===O.method){var E=Ve(r,w),R=E.newURI,P=E.parseError;if(P)return _e(P);r=R}else try{O.body=Me(w)}catch(P){return _e(P)}return new n.Observable((function(e){return(a||h((function(){return fetch}))||We)(r,O).then((function(e){return t.setContext({response:e}),e})).then(Ce(t)).then((function(t){return e.next(t),e.complete(),t})).catch((function(t){"AbortError"!==t.name&&(t.result&&t.result.errors&&t.result.data&&e.next(t.result),e.error(t))})),function(){m&&m.abort()}}))}))},Be=function(t){function r(e){void 0===e&&(e={});var r=t.call(this,ze(e).request)||this;return r.options=e,r}return e.__extends(r,t),r}(xe),Ue=function(){function t(){this.getFragmentDoc=o.wrap(y)}return t.prototype.batch=function(e){var t,r=this,n="string"==typeof e.optimistic?e.optimistic:!1===e.optimistic?null:void 0;return this.performTransaction((function(){return t=e.update(r)}),n),t},t.prototype.recordOptimisticTransaction=function(e,t){this.performTransaction(e,t)},t.prototype.transformDocument=function(e){return e},t.prototype.identify=function(e){},t.prototype.gc=function(){return[]},t.prototype.modify=function(e){return!1},t.prototype.transformForLink=function(e){return e},t.prototype.readQuery=function(t,r){return void 0===r&&(r=!!t.optimistic),this.read(e.__assign(e.__assign({},t),{rootId:t.id||"ROOT_QUERY",optimistic:r}))},t.prototype.readFragment=function(t,r){return void 0===r&&(r=!!t.optimistic),this.read(e.__assign(e.__assign({},t),{query:this.getFragmentDoc(t.fragment,t.fragmentName),rootId:t.id,optimistic:r}))},t.prototype.writeQuery=function(t){var r=t.id,n=t.data,i=e.__rest(t,["id","data"]);return this.write(Object.assign(i,{dataId:r||"ROOT_QUERY",result:n}))},t.prototype.writeFragment=function(t){var r=t.id,n=t.data,i=t.fragment,o=t.fragmentName,a=e.__rest(t,["id","data","fragment","fragmentName"]);return this.write(Object.assign(a,{query:this.getFragmentDoc(i,o),dataId:r,result:n}))},t.prototype.updateQuery=function(t,r){return this.batch({update:function(n){var i=n.readQuery(t),o=r(i);return null==o?i:(n.writeQuery(e.__assign(e.__assign({},t),{data:o})),o)}})},t.prototype.updateFragment=function(t,r){return this.batch({update:function(n){var i=n.readFragment(t),o=r(i);return null==o?i:(n.writeFragment(e.__assign(e.__assign({},t),{data:o})),o)}})},t}();exports.Cache=void 0,exports.Cache||(exports.Cache={});var He=function(e,t,r,n){this.message=e,this.path=t,this.query=r,this.variables=n},Je=Object.prototype.hasOwnProperty;function Ke(e,t){var r=e.__typename,n=e.id,i=e._id;if("string"==typeof r&&(t&&(t.keyObject=void 0!==n?{id:n}:void 0!==i?{_id:i}:void 0),void 0===n&&(n=i),void 0!==n))return"".concat(r,":").concat("number"==typeof n||"string"==typeof n?n:JSON.stringify(n))}var Ye={dataIdFromObject:Ke,addTypename:!0,resultCaching:!0,canonizeResults:!1};function Ge(e){var t=e.canonizeResults;return void 0===t?Ye.canonizeResults:t}var Xe=/^[_a-z][_0-9a-z]*/i;function $e(e){var t=e.match(Xe);return t?t[0]:e}function Ze(e,t,r){return!!b(t)&&(tt(t)?t.every((function(t){return Ze(e,t,r)})):e.selections.every((function(e){if(Q(e)&&p(e,r)){var n=R(e);return Je.call(t,n)&&(!e.selectionSet||Ze(e.selectionSet,t[n],r))}return!0})))}function et(e){return b(e)&&!O(e)&&!tt(e)}var tt=function(e){return Array.isArray(e)},rt=Object.create(null),nt=function(){return rt},it=Object.create(null),ot=function(){function r(e,t){var r=this;this.policies=e,this.group=t,this.data=Object.create(null),this.rootIds=Object.create(null),this.refs=Object.create(null),this.getFieldValue=function(e,t){return O(e)?r.get(e.__ref,t):e&&e[t]},this.canRead=function(e){return O(e)?r.has(e.__ref):"object"==typeof e},this.toReference=function(e,t){if("string"==typeof e)return _(e);if(O(e))return e;var n=r.policies.identify(e)[0];if(n){var i=_(n);return t&&r.merge(n,e),i}}}return r.prototype.toObject=function(){return e.__assign({},this.data)},r.prototype.has=function(e){return void 0!==this.lookup(e,!0)},r.prototype.get=function(e,t){if(this.group.depend(e,t),Je.call(this.data,e)){var r=this.data[e];if(r&&Je.call(r,t))return r[t]}return"__typename"===t&&Je.call(this.policies.rootTypenamesById,e)?this.policies.rootTypenamesById[e]:this instanceof ct?this.parent.get(e,t):void 0},r.prototype.lookup=function(e,t){return t&&this.group.depend(e,"__exists"),Je.call(this.data,e)?this.data[e]:this instanceof ct?this.parent.lookup(e,t):this.policies.rootTypenamesById[e]?Object.create(null):void 0},r.prototype.merge=function(e,r){var n,i=this;O(e)&&(e=e.__ref),O(r)&&(r=r.__ref);var o="string"==typeof e?this.lookup(n=e):e,a="string"==typeof r?this.lookup(n=r):r;if(a){t.invariant("string"==typeof n,1);var s=new Z(ft).merge(o,a);if(this.data[n]=s,s!==o&&(delete this.refs[n],this.group.caching)){var u=Object.create(null);o||(u.__exists=1),Object.keys(a).forEach((function(e){if(!o||o[e]!==s[e]){u[e]=1;var t=$e(e);t===e||i.policies.hasKeyArgs(s.__typename,t)||(u[t]=1),void 0!==s[e]||i instanceof ct||delete s[e]}})),!u.__typename||o&&o.__typename||this.policies.rootTypenamesById[n]!==s.__typename||delete u.__typename,Object.keys(u).forEach((function(e){return i.group.dirty(n,e)}))}}},r.prototype.modify=function(t,r){var n=this,i=this.lookup(t);if(i){var o=Object.create(null),a=!1,s=!0,u={DELETE:rt,INVALIDATE:it,isReference:O,toReference:this.toReference,canRead:this.canRead,readField:function(e,r){return n.policies.readField("string"==typeof e?{fieldName:e,from:r||_(t)}:e,{store:n})}};if(Object.keys(i).forEach((function(c){var l=$e(c),f=i[c];if(void 0!==f){var h="function"==typeof r?r:r[c]||r[l];if(h){var p=h===nt?rt:h(f,e.__assign(e.__assign({},u),{fieldName:l,storeFieldName:c,storage:n.getStorage(t,c)}));p===it?n.group.dirty(t,c):(p===rt&&(p=void 0),p!==f&&(o[c]=p,a=!0,f=p))}void 0!==f&&(s=!1)}})),a)return this.merge(t,o),s&&(this instanceof ct?this.data[t]=void 0:delete this.data[t],this.group.dirty(t,"__exists")),!0}return!1},r.prototype.delete=function(e,t,r){var n,i=this.lookup(e);if(i){var o=this.getFieldValue(i,"__typename"),a=t&&r?this.policies.getStoreFieldName({typename:o,fieldName:t,args:r}):t;return this.modify(e,a?((n={})[a]=nt,n):nt)}return!1},r.prototype.evict=function(e,t){var r=!1;return e.id&&(Je.call(this.data,e.id)&&(r=this.delete(e.id,e.fieldName,e.args)),this instanceof ct&&this!==t&&(r=this.parent.evict(e,t)||r),(e.fieldName||r)&&this.group.dirty(e.id,e.fieldName||"__exists")),r},r.prototype.clear=function(){this.replace(null)},r.prototype.extract=function(){var e=this,t=this.toObject(),r=[];return this.getRootIdSet().forEach((function(t){Je.call(e.policies.rootTypenamesById,t)||r.push(t)})),r.length&&(t.__META={extraRootIds:r.sort()}),t},r.prototype.replace=function(t){var r=this;if(Object.keys(this.data).forEach((function(e){t&&Je.call(t,e)||r.delete(e)})),t){var n=t.__META,i=e.__rest(t,["__META"]);Object.keys(i).forEach((function(e){r.merge(e,i[e])})),n&&n.extraRootIds.forEach(this.retain,this)}},r.prototype.retain=function(e){return this.rootIds[e]=(this.rootIds[e]||0)+1},r.prototype.release=function(e){if(this.rootIds[e]>0){var t=--this.rootIds[e];return t||delete this.rootIds[e],t}return 0},r.prototype.getRootIdSet=function(e){return void 0===e&&(e=new Set),Object.keys(this.rootIds).forEach(e.add,e),this instanceof ct?this.parent.getRootIdSet(e):Object.keys(this.policies.rootTypenamesById).forEach(e.add,e),e},r.prototype.gc=function(){var e=this,t=this.getRootIdSet(),r=this.toObject();t.forEach((function(n){Je.call(r,n)&&(Object.keys(e.findChildRefIds(n)).forEach(t.add,t),delete r[n])}));var n=Object.keys(r);if(n.length){for(var i=this;i instanceof ct;)i=i.parent;n.forEach((function(e){return i.delete(e)}))}return n},r.prototype.findChildRefIds=function(e){if(!Je.call(this.refs,e)){var t=this.refs[e]=Object.create(null),r=this.data[e];if(!r)return t;var n=new Set([r]);n.forEach((function(e){O(e)&&(t[e.__ref]=!0),b(e)&&Object.keys(e).forEach((function(t){var r=e[t];b(r)&&n.add(r)}))}))}return this.refs[e]},r.prototype.makeCacheKey=function(){return this.group.keyMaker.lookupArray(arguments)},r}(),at=function(){function e(e,t){void 0===t&&(t=null),this.caching=e,this.parent=t,this.d=null,this.resetCaching()}return e.prototype.resetCaching=function(){this.d=this.caching?o.dep():null,this.keyMaker=new s.Trie(oe)},e.prototype.depend=function(e,t){if(this.d){this.d(st(e,t));var r=$e(t);r!==t&&this.d(st(e,r)),this.parent&&this.parent.depend(e,t)}},e.prototype.dirty=function(e,t){this.d&&this.d.dirty(st(e,t),"__exists"===t?"forget":"setDirty")},e}();function st(e,t){return t+"#"+e}function ut(e,t){ht(e)&&e.group.depend(t,"__exists")}!function(t){var r=function(t){function r(e){var r=e.policies,n=e.resultCaching,i=void 0===n||n,o=e.seed,a=t.call(this,r,new at(i))||this;return a.stump=new lt(a),a.storageTrie=new s.Trie(oe),o&&a.replace(o),a}return e.__extends(r,t),r.prototype.addLayer=function(e,t){return this.stump.addLayer(e,t)},r.prototype.removeLayer=function(){return this},r.prototype.getStorage=function(){return this.storageTrie.lookupArray(arguments)},r}(t);t.Root=r}(ot||(ot={}));var ct=function(t){function n(e,r,n,i){var o=t.call(this,r.policies,i)||this;return o.id=e,o.parent=r,o.replay=n,o.group=i,n(o),o}return e.__extends(n,t),n.prototype.addLayer=function(e,t){return new n(e,this,t,this.group)},n.prototype.removeLayer=function(e){var t=this,n=this.parent.removeLayer(e);return e===this.id?(this.group.caching&&Object.keys(this.data).forEach((function(e){var i=t.data[e],o=n.lookup(e);o?i?i!==o&&Object.keys(i).forEach((function(n){r.equal(i[n],o[n])||t.group.dirty(e,n)})):(t.group.dirty(e,"__exists"),Object.keys(o).forEach((function(r){t.group.dirty(e,r)}))):t.delete(e)})),n):n===this.parent?this:n.addLayer(this.id,this.replay)},n.prototype.toObject=function(){return e.__assign(e.__assign({},this.parent.toObject()),this.data)},n.prototype.findChildRefIds=function(r){var n=this.parent.findChildRefIds(r);return Je.call(this.data,r)?e.__assign(e.__assign({},n),t.prototype.findChildRefIds.call(this,r)):n},n.prototype.getStorage=function(){for(var e=this.parent;e.parent;)e=e.parent;return e.getStorage.apply(e,arguments)},n}(ot),lt=function(t){function r(e){return t.call(this,"EntityStore.Stump",e,(function(){}),new at(e.group.caching,e.group))||this}return e.__extends(r,t),r.prototype.removeLayer=function(){return this},r.prototype.merge=function(){return this.parent.merge.apply(this.parent,arguments)},r}(ct);function ft(e,t,n){var i=e[n],o=t[n];return r.equal(i,o)?i:o}function ht(e){return!!(e instanceof ot&&e.group.caching)}var pt,dt,vt=function(){function t(){this.known=new(ae?WeakSet:Set),this.pool=new s.Trie(oe),this.passes=new WeakMap,this.keysByJSON=new Map,this.empty=this.admit({})}return t.prototype.isKnown=function(e){return b(e)&&this.known.has(e)},t.prototype.pass=function(t){if(b(t)){var r=function(t){return b(t)?tt(t)?t.slice(0):e.__assign({__proto__:Object.getPrototypeOf(t)},t):t}(t);return this.passes.set(r,t),r}return t},t.prototype.admit=function(e){var t=this;if(b(e)){var r=this.passes.get(e);if(r)return r;switch(Object.getPrototypeOf(e)){case Array.prototype:if(this.known.has(e))return e;var n=e.map(this.admit,this);return(s=this.pool.lookupArray(n)).array||this.known.add(s.array=n),s.array;case null:case Object.prototype:if(this.known.has(e))return e;var i=Object.getPrototypeOf(e),o=[i],a=this.sortedKeys(e);o.push(a.json);var s,u=o.length;if(a.sorted.forEach((function(r){o.push(t.admit(e[r]))})),!(s=this.pool.lookupArray(o)).object){var c=s.object=Object.create(i);this.known.add(c),a.sorted.forEach((function(e,t){c[e]=o[u+t]}))}return s.object}}return e},t.prototype.sortedKeys=function(e){var t=Object.keys(e),r=this.pool.lookupArray(t);if(!r.keys){t.sort();var n=JSON.stringify(t);(r.keys=this.keysByJSON.get(n))||this.keysByJSON.set(n,r.keys={sorted:t,json:n})}return r.keys},t}(),yt=Object.assign((function(e){if(b(e)){void 0===pt&&mt();var t=pt.admit(e),r=dt.get(t);return void 0===r&&dt.set(t,r=JSON.stringify(t)),r}return JSON.stringify(e)}),{reset:mt});function mt(){pt=new vt,dt=new(oe?WeakMap:Map)}function gt(e){return[e.selectionSet,e.objectOrReference,e.context,e.context.canonizeResults]}var bt=function(){function t(t){var r=this;this.knownResults=new(oe?WeakMap:Map),this.config=ye(t,{addTypename:!1!==t.addTypename,canonizeResults:Ge(t)}),this.canon=t.canon||new vt,this.executeSelectionSet=o.wrap((function(t){var n,i=t.context.canonizeResults,o=gt(t);o[3]=!i;var a=(n=r.executeSelectionSet).peek.apply(n,o);return a?i?e.__assign(e.__assign({},a),{result:r.canon.admit(a.result)}):a:(ut(t.context.store,t.enclosingRef.__ref),r.execSelectionSetImpl(t))}),{max:this.config.resultCacheMaxSize,keyArgs:gt,makeCacheKey:function(e,t,r,n){if(ht(r.store))return r.store.makeCacheKey(e,O(t)?t.__ref:t,r.varString,n)}}),this.executeSubSelectedArray=o.wrap((function(e){return ut(e.context.store,e.enclosingRef.__ref),r.execSubSelectedArrayImpl(e)}),{max:this.config.resultCacheMaxSize,makeCacheKey:function(e){var t=e.field,r=e.array,n=e.context;if(ht(n.store))return n.store.makeCacheKey(t,r,n.varString)}})}return t.prototype.resetCanon=function(){this.canon=new vt},t.prototype.diffQueryAgainstStore=function(t){var r=t.store,n=t.query,i=t.rootId,o=void 0===i?"ROOT_QUERY":i,a=t.variables,s=t.returnPartialData,u=void 0===s||s,c=t.canonizeResults,l=void 0===c?this.config.canonizeResults:c,f=this.config.cache.policies;a=e.__assign(e.__assign({},N(T(n))),a);var h,p=_(o),d=this.executeSelectionSet({selectionSet:j(n).selectionSet,objectOrReference:p,enclosingRef:p,context:{store:r,query:n,policies:f,variables:a,varString:yt(a),canonizeResults:l,fragmentMap:m(D(n))}});if(d.missing&&(h=[new He(_t(d.missing),d.missing,n,a)],!u))throw h[0];return{result:d.result,complete:!h,missing:h}},t.prototype.isFresh=function(e,t,r,n){if(ht(n.store)&&this.knownResults.get(e)===r){var i=this.executeSelectionSet.peek(r,t,n,this.canon.isKnown(e));if(i&&e===i.result)return!0}return!1},t.prototype.execSelectionSetImpl=function(e){var t=this,r=e.selectionSet,n=e.objectOrReference,i=e.enclosingRef,o=e.context;if(O(n)&&!o.policies.rootTypenamesById[n.__ref]&&!o.store.has(n.__ref))return{result:this.canon.empty,missing:"Dangling reference to missing ".concat(n.__ref," object")};var a,s=o.variables,u=o.policies,c=o.store.getFieldValue(n,"__typename"),l=[],f=new Z;function h(e,t){var r;return e.missing&&(a=f.merge(a,((r={})[t]=e.missing,r))),e.result}this.config.addTypename&&"string"==typeof c&&!u.rootIdsByTypename[c]&&l.push({__typename:c});var d=new Set(r.selections);d.forEach((function(e){var r,v;if(p(e,s))if(Q(e)){var y=u.readField({fieldName:e.name.value,field:e,variables:o.variables,from:n},o),m=R(e);void 0===y?U.added(e)||(a=f.merge(a,((r={})[m]="Can't find field '".concat(e.name.value,"' on ").concat(O(n)?n.__ref+" object":"object "+JSON.stringify(n,null,2)),r))):tt(y)?y=h(t.executeSubSelectedArray({field:e,array:y,enclosingRef:i,context:o}),m):e.selectionSet?null!=y&&(y=h(t.executeSelectionSet({selectionSet:e.selectionSet,objectOrReference:y,enclosingRef:O(y)?y:i,context:o}),m)):o.canonizeResults&&(y=t.canon.pass(y)),void 0!==y&&l.push(((v={})[m]=y,v))}else{var b=g(e,o.fragmentMap);b&&u.fragmentMatches(b,c)&&b.selectionSet.selections.forEach(d.add,d)}}));var v={result:X(l),missing:a},y=o.canonizeResults?this.canon.admit(v):v;return y.result&&this.knownResults.set(y.result,r),y},t.prototype.execSubSelectedArrayImpl=function(e){var t,r=this,n=e.field,i=e.array,o=e.enclosingRef,a=e.context,s=new Z;function u(e,r){var n;return e.missing&&(t=s.merge(t,((n={})[r]=e.missing,n))),e.result}return n.selectionSet&&(i=i.filter(a.store.canRead)),i=i.map((function(e,t){return null===e?null:tt(e)?u(r.executeSubSelectedArray({field:n,array:e,enclosingRef:o,context:a}),t):n.selectionSet?u(r.executeSelectionSet({selectionSet:n.selectionSet,objectOrReference:e,enclosingRef:O(e)?e:o,context:a}),t):e})),{result:a.canonizeResults?this.canon.admit(i):i,missing:t}},t}();function _t(e){try{JSON.stringify(e,(function(e,t){if("string"==typeof t)throw t;return t}))}catch(e){return e}}var Ot=new a.Slot,wt=new WeakMap;function kt(e){var t=wt.get(e);return t||wt.set(e,t={vars:new Set,dep:o.dep()}),t}function St(e){kt(e).vars.forEach((function(t){return t.forgetCache(e)}))}function xt(e){var t=new Set,r=new Set,n=function(o){if(arguments.length>0){if(e!==o){e=o,t.forEach((function(e){kt(e).dep.dirty(n),qt(e)}));var a=Array.from(r);r.clear(),a.forEach((function(t){return t(e)}))}}else{var s=Ot.getValue();s&&(i(s),kt(s).dep(n))}return e};n.onNextChange=function(e){return r.add(e),function(){r.delete(e)}};var i=n.attachCache=function(e){return t.add(e),kt(e).vars.add(n),n};return n.forgetCache=function(e){return t.delete(e)},n}function qt(e){e.broadcastWatches&&e.broadcastWatches()}var Et=Object.create(null);function Rt(e){var t=JSON.stringify(e);return Et[t]||(Et[t]=Object.create(null))}function Pt(e){var r=Rt(e);return r.keyFieldsFn||(r.keyFieldsFn=function(r,n){var i=function(e,t){return n.readField(t,e)},o=n.keyObject=Ft(e,(function(e){var o=It(n.storeObject,e,i);return void 0===o&&r!==n.storeObject&&Je.call(r,e[0])&&(o=It(r,e,Mt)),t.invariant(void 0!==o,2),o}));return"".concat(n.typename,":").concat(JSON.stringify(o))})}function Qt(e){var t=Rt(e);return t.keyArgsFn||(t.keyArgsFn=function(t,r){var n=r.field,i=r.variables,o=r.fieldName,a=Ft(e,(function(e){var r=e[0],o=r.charAt(0);if("@"!==o)if("$"!==o){if(t)return It(t,e)}else{var a=r.slice(1);if(i&&Je.call(i,a)){var s=e.slice(0);return s[0]=a,It(i,s)}}else if(n&&de(n.directives)){var u=r.slice(1),c=n.directives.find((function(e){return e.name.value===u})),l=c&&E(c,i);return l&&It(l,e.slice(1))}})),s=JSON.stringify(a);return(t||"{}"!==s)&&(o+=":"+s),o})}function Ft(e,t){var r=new Z;return Ct(e).reduce((function(e,n){var i,o=t(n);if(void 0!==o){for(var a=n.length-1;a>=0;--a)(i={})[n[a]]=o,o=i;e=r.merge(e,o)}return e}),Object.create(null))}function Ct(e){var t=Rt(e);if(!t.paths){var r=t.paths=[],n=[];e.forEach((function(t,i){tt(t)?(Ct(t).forEach((function(e){return r.push(n.concat(e))})),n.length=0):(n.push(t),tt(e[i+1])||(r.push(n.slice(0)),n.length=0))}))}return t.paths}function Mt(e,t){return e[t]}function It(e,t,r){return r=r||Mt,Dt(t.reduce((function e(t,n){return tt(t)?t.map((function(t){return e(t,n)})):t&&r(t,n)}),e))}function Dt(e){return b(e)?tt(e)?e.map(Dt):Ft(Object.keys(e).sort(),(function(t){return It(e,t)})):e}function Tt(e){return void 0!==e.args?e.args:e.field?E(e.field,e.variables):null}S.setStringify(yt);var jt=function(){},Nt=function(e,t){return t.fieldName},At=function(e,t,r){return(0,r.mergeObjects)(e,t)},Lt=function(e,t){return t},Vt=function(){function r(t){this.config=t,this.typePolicies=Object.create(null),this.toBeAdded=Object.create(null),this.supertypeMap=new Map,this.fuzzySubtypes=new Map,this.rootIdsByTypename=Object.create(null),this.rootTypenamesById=Object.create(null),this.usingPossibleTypes=!1,this.config=e.__assign({dataIdFromObject:Ke},t),this.cache=this.config.cache,this.setRootTypename("Query"),this.setRootTypename("Mutation"),this.setRootTypename("Subscription"),t.possibleTypes&&this.addPossibleTypes(t.possibleTypes),t.typePolicies&&this.addTypePolicies(t.typePolicies)}return r.prototype.identify=function(t,r){var n,i=this,o=r&&(r.typename||(null===(n=r.storeObject)||void 0===n?void 0:n.__typename))||t.__typename;if(o===this.rootTypenamesById.ROOT_QUERY)return["ROOT_QUERY"];for(var a,s=r&&r.storeObject||t,u=e.__assign(e.__assign({},r),{typename:o,storeObject:s,readField:r&&r.readField||function(){var e=zt(arguments,s);return i.readField(e,{store:i.cache.data,variables:e.variables})}}),c=o&&this.getTypePolicy(o),l=c&&c.keyFn||this.config.dataIdFromObject;l;){var f=l(t,u);if(!tt(f)){a=f;break}l=Pt(f)}return a=a?String(a):void 0,u.keyObject?[a,u.keyObject]:[a]},r.prototype.addTypePolicies=function(t){var r=this;Object.keys(t).forEach((function(n){var i=t[n],o=i.queryType,a=i.mutationType,s=i.subscriptionType,u=e.__rest(i,["queryType","mutationType","subscriptionType"]);o&&r.setRootTypename("Query",n),a&&r.setRootTypename("Mutation",n),s&&r.setRootTypename("Subscription",n),Je.call(r.toBeAdded,n)?r.toBeAdded[n].push(u):r.toBeAdded[n]=[u]}))},r.prototype.updateTypePolicy=function(e,t){var r=this,n=this.getTypePolicy(e),i=t.keyFields,o=t.fields;function a(e,t){e.merge="function"==typeof t?t:!0===t?At:!1===t?Lt:e.merge}a(n,t.merge),n.keyFn=!1===i?jt:tt(i)?Pt(i):"function"==typeof i?i:n.keyFn,o&&Object.keys(o).forEach((function(t){var n=r.getFieldPolicy(e,t,!0),i=o[t];if("function"==typeof i)n.read=i;else{var s=i.keyArgs,u=i.read,c=i.merge;n.keyFn=!1===s?Nt:tt(s)?Qt(s):"function"==typeof s?s:n.keyFn,"function"==typeof u&&(n.read=u),a(n,c)}n.read&&n.merge&&(n.keyFn=n.keyFn||Nt)}))},r.prototype.setRootTypename=function(e,r){void 0===r&&(r=e);var n="ROOT_"+e.toUpperCase(),i=this.rootTypenamesById[n];r!==i&&(t.invariant(!i||i===e,3),i&&delete this.rootIdsByTypename[i],this.rootIdsByTypename[r]=n,this.rootTypenamesById[n]=r)},r.prototype.addPossibleTypes=function(e){var t=this;this.usingPossibleTypes=!0,Object.keys(e).forEach((function(r){t.getSupertypeSet(r,!0),e[r].forEach((function(e){t.getSupertypeSet(e,!0).add(r);var n=e.match(Xe);n&&n[0]===e||t.fuzzySubtypes.set(e,new RegExp(e))}))}))},r.prototype.getTypePolicy=function(t){var r=this;if(!Je.call(this.typePolicies,t)){var n=this.typePolicies[t]=Object.create(null);n.fields=Object.create(null);var i=this.supertypeMap.get(t);i&&i.size&&i.forEach((function(t){var i=r.getTypePolicy(t),o=i.fields,a=e.__rest(i,["fields"]);Object.assign(n,a),Object.assign(n.fields,o)}))}var o=this.toBeAdded[t];return o&&o.length&&o.splice(0).forEach((function(e){r.updateTypePolicy(t,e)})),this.typePolicies[t]},r.prototype.getFieldPolicy=function(e,t,r){if(e){var n=this.getTypePolicy(e).fields;return n[t]||r&&(n[t]=Object.create(null))}},r.prototype.getSupertypeSet=function(e,t){var r=this.supertypeMap.get(e);return!r&&t&&this.supertypeMap.set(e,r=new Set),r},r.prototype.fragmentMatches=function(e,t,r,n){var i=this;if(!e.typeCondition)return!0;if(!t)return!1;var o=e.typeCondition.name.value;if(t===o)return!0;if(this.usingPossibleTypes&&this.supertypeMap.has(o))for(var a=this.getSupertypeSet(t,!0),s=[a],u=function(e){var t=i.getSupertypeSet(e,!1);t&&t.size&&s.indexOf(t)<0&&s.push(t)},c=!(!r||!this.fuzzySubtypes.size),l=0;l<s.length;++l){var f=s[l];if(f.has(o))return a.has(o)||a.add(o),!0;f.forEach(u),c&&l===s.length-1&&Ze(e.selectionSet,r,n)&&(c=!1,!0,this.fuzzySubtypes.forEach((function(e,r){var n=t.match(e);n&&n[0]===t&&u(r)})))}return!1},r.prototype.hasKeyArgs=function(e,t){var r=this.getFieldPolicy(e,t,!1);return!(!r||!r.keyFn)},r.prototype.getStoreFieldName=function(e){var t,r=e.typename,n=e.fieldName,i=this.getFieldPolicy(r,n,!1),o=i&&i.keyFn;if(o&&r)for(var a={typename:r,fieldName:n,field:e.field||null,variables:e.variables},s=Tt(e);o;){var u=o(s,a);if(!tt(u)){t=u||n;break}o=Qt(u)}return void 0===t&&(t=e.field?function(e,t){var r=null;e.directives&&(r={},e.directives.forEach((function(e){r[e.name.value]={},e.arguments&&e.arguments.forEach((function(n){var i=n.name,o=n.value;return w(r[e.name.value],i,o,t)}))})));var n=null;return e.arguments&&e.arguments.length&&(n={},e.arguments.forEach((function(e){var r=e.name,i=e.value;return w(n,r,i,t)}))),S(e.name.value,n,r)}(e.field,e.variables):S(n,Tt(e))),!1===t?n:n===$e(t)?t:n+":"+t},r.prototype.readField=function(e,t){var r=e.from;if(r&&(e.field||e.fieldName)){if(void 0===e.typename){var n=t.store.getFieldValue(r,"__typename");n&&(e.typename=n)}var i=this.getStoreFieldName(e),o=$e(i),a=t.store.getFieldValue(r,i),s=this.getFieldPolicy(e.typename,o,!1),u=s&&s.read;if(u){var c=Wt(this,r,e,t,t.store.getStorage(O(r)?r.__ref:r,i));return Ot.withValue(this.cache,u,[a,c])}return a}},r.prototype.getReadFunction=function(e,t){var r=this.getFieldPolicy(e,t,!1);return r&&r.read},r.prototype.getMergeFunction=function(e,t,r){var n=this.getFieldPolicy(e,t,!1),i=n&&n.merge;return!i&&r&&(i=(n=this.getTypePolicy(r))&&n.merge),i},r.prototype.runMergeFunction=function(e,t,r,n,i){var o=r.field,a=r.typename,s=r.merge;return s===At?Bt(n.store)(e,t):s===Lt?t:(n.overwrite&&(e=void 0),s(e,t,Wt(this,void 0,{typename:a,fieldName:o.name.value,field:o,variables:n.variables},n,i||Object.create(null))))},r}();function Wt(e,t,r,n,i){var o=e.getStoreFieldName(r),a=$e(o),s=r.variables||n.variables,u=n.store,c=u.toReference,l=u.canRead;return{args:Tt(r),field:r.field||null,fieldName:a,storeFieldName:o,variables:s,isReference:O,toReference:c,storage:i,cache:e.cache,canRead:l,readField:function(){return e.readField(zt(arguments,t,s),n)},mergeObjects:Bt(n.store)}}function zt(t,r,n){var i,o=t[0],a=t[1],s=t.length;return"string"==typeof o?i={fieldName:o,from:s>1?a:r}:(i=e.__assign({},o),Je.call(i,"from")||(i.from=r)),void 0===i.variables&&(i.variables=n),i}function Bt(r){return function(n,i){if(tt(n)||tt(i))throw new t.InvariantError(4);if(b(n)&&b(i)){var o=r.getFieldValue(n,"__typename"),a=r.getFieldValue(i,"__typename");if(o&&a&&o!==a)return i;if(O(n)&&et(i))return r.merge(n.__ref,i),n;if(et(n)&&O(i))return r.merge(n,i.__ref),i;if(et(n)&&et(i))return e.__assign(e.__assign({},n),i)}return i}}function Ut(t,r,n){var i="".concat(r).concat(n),o=t.flavors.get(i);return o||t.flavors.set(i,o=t.clientOnly===r&&t.deferred===n?t:e.__assign(e.__assign({},t),{clientOnly:r,deferred:n})),o}var Ht=function(){function r(e,t){this.cache=e,this.reader=t}return r.prototype.writeToStore=function(r,n){var i=this,o=n.query,a=n.result,s=n.dataId,u=n.variables,c=n.overwrite,l=M(o),f=new Z;u=e.__assign(e.__assign({},N(l)),u);var h={store:r,written:Object.create(null),merge:function(e,t){return f.merge(e,t)},variables:u,varString:yt(u),fragmentMap:m(D(o)),overwrite:!!c,incomingById:new Map,clientOnly:!1,deferred:!1,flavors:new Map},p=this.processSelectionSet({result:a||Object.create(null),dataId:s,selectionSet:l.selectionSet,mergeTree:{map:new Map},context:h});if(!O(p))throw new t.InvariantError(6);return h.incomingById.forEach((function(e,t){var n=e.storeObject,o=e.mergeTree,a=(e.fieldNodeSet,_(t));if(o&&o.map.size){var s=i.applyMerges(o,a,n,h);if(O(s))return;n=s}r.merge(t,n)})),r.retain(p.__ref),p},r.prototype.processSelectionSet=function(t){var r=this,n=t.dataId,i=t.result,o=t.selectionSet,a=t.context,s=t.mergeTree,u=this.cache.policies,c=Object.create(null),l=n&&u.rootTypenamesById[n]||P(i,o,a.fragmentMap)||n&&a.store.get(n,"__typename");"string"==typeof l&&(c.__typename=l);var f=function(){var t=zt(arguments,c,a.variables);if(O(t.from)){var r=a.incomingById.get(t.from.__ref);if(r){var n=u.readField(e.__assign(e.__assign({},t),{from:r.storeObject}),a);if(void 0!==n)return n}}return u.readField(t,a)},h=new Set;this.flattenFields(o,i,a,l).forEach((function(e,t){var n,o=R(t),a=i[o];if(h.add(t),void 0!==a){var p=u.getStoreFieldName({typename:l,fieldName:t.name.value,field:t,variables:e.variables}),d=Kt(s,p),v=r.processFieldValue(a,t,t.selectionSet?Ut(e,!1,!1):e,d),y=void 0;t.selectionSet&&(O(v)||et(v))&&(y=f("__typename",v));var m=u.getMergeFunction(l,t.name.value,y);m?d.info={field:t,typename:l,merge:m}:Xt(s,p),c=e.merge(c,((n={})[p]=v,n))}else 0}));try{var p=u.identify(i,{typename:l,selectionSet:o,fragmentMap:a.fragmentMap,storeObject:c,readField:f}),d=p[0],v=p[1];n=n||d,v&&(c=a.merge(c,v))}catch(e){if(!n)throw e}if("string"==typeof n){var y=_(n),m=a.written[n]||(a.written[n]=[]);if(m.indexOf(o)>=0)return y;if(m.push(o),this.reader&&this.reader.isFresh(i,y,o,a))return y;var g=a.incomingById.get(n);return g?(g.storeObject=a.merge(g.storeObject,c),g.mergeTree=Yt(g.mergeTree,s),h.forEach((function(e){return g.fieldNodeSet.add(e)}))):a.incomingById.set(n,{storeObject:c,mergeTree:Gt(s)?void 0:s,fieldNodeSet:h}),y}return c},r.prototype.processFieldValue=function(e,t,r,n){var i=this;return t.selectionSet&&null!==e?tt(e)?e.map((function(e,o){var a=i.processFieldValue(e,t,r,Kt(n,o));return Xt(n,o),a})):this.processSelectionSet({result:e,selectionSet:t.selectionSet,context:r,mergeTree:n}):e},r.prototype.flattenFields=function(e,t,r,n){void 0===n&&(n=P(t,e,r.fragmentMap));var i=new Map,o=this.cache.policies,a=new s.Trie(!1);return function e(s,u){var c=a.lookup(s,u.clientOnly,u.deferred);c.visited||(c.visited=!0,s.selections.forEach((function(a){if(p(a,r.variables)){var s=u.clientOnly,c=u.deferred;if(s&&c||!de(a.directives)||a.directives.forEach((function(e){var t=e.name.value;if("client"===t&&(s=!0),"defer"===t){var n=E(e,r.variables);n&&!1===n.if||(c=!0)}})),Q(a)){var l=i.get(a);l&&(s=s&&l.clientOnly,c=c&&l.deferred),i.set(a,Ut(r,s,c))}else{var f=g(a,r.fragmentMap);f&&o.fragmentMatches(f,n,t,r.variables)&&e(f.selectionSet,Ut(r,s,c))}}})))}(e,r),i},r.prototype.applyMerges=function(r,n,i,o,a){var s,u=this;if(r.map.size&&!O(i)){var c,l=tt(i)||!O(n)&&!et(n)?void 0:n,f=i;l&&!a&&(a=[O(l)?l.__ref:l]);var h=function(e,t){return tt(e)?"number"==typeof t?e[t]:void 0:o.store.getFieldValue(e,String(t))};r.map.forEach((function(e,r){var n=h(l,r),i=h(f,r);if(void 0!==i){a&&a.push(r);var s=u.applyMerges(e,n,i,o,a);s!==i&&(c=c||new Map).set(r,s),a&&t.invariant(a.pop()===r)}})),c&&(i=tt(f)?f.slice(0):e.__assign({},f),c.forEach((function(e,t){i[t]=e})))}return r.info?this.cache.policies.runMergeFunction(n,i,r.info,o,a&&(s=o.store).getStorage.apply(s,a)):i},r}(),Jt=[];function Kt(e,t){var r=e.map;return r.has(t)||r.set(t,Jt.pop()||{map:new Map}),r.get(t)}function Yt(t,r){if(t===r||!r||Gt(r))return t;if(!t||Gt(t))return r;var n=t.info&&r.info?e.__assign(e.__assign({},t.info),r.info):t.info||r.info,i=t.map.size&&r.map.size,o={info:n,map:i?new Map:t.map.size?t.map:r.map};if(i){var a=new Set(r.map.keys());t.map.forEach((function(e,t){o.map.set(t,Yt(e,r.map.get(t))),a.delete(t)})),a.forEach((function(e){o.map.set(e,Yt(r.map.get(e),t.map.get(e)))}))}return o}function Gt(e){return!e||!(e.info||e.map.size)}function Xt(e,t){var r=e.map,n=r.get(t);n&&Gt(n)&&(Jt.push(n),r.delete(t))}new Set;var $t=function(t){function n(e){void 0===e&&(e={});var r=t.call(this)||this;return r.watches=new Set,r.typenameDocumentCache=new Map,r.makeVar=xt,r.txCount=0,r.config=function(e){return ye(Ye,e)}(e),r.addTypename=!!r.config.addTypename,r.policies=new Vt({cache:r,dataIdFromObject:r.config.dataIdFromObject,possibleTypes:r.config.possibleTypes,typePolicies:r.config.typePolicies}),r.init(),r}return e.__extends(n,t),n.prototype.init=function(){var e=this.data=new ot.Root({po