@swan-io/graphql-client
Advanced tools
Comparing version 0.1.0-alpha2 to 0.1.0-alpha3
export * from "./client"; | ||
export { ClientError } from "./errors"; | ||
export { print } from "./graphql/print"; | ||
export * from "./react/ClientContext"; | ||
@@ -4,0 +5,0 @@ export * from "./react/useDeferredQuery"; |
@@ -1,2 +0,2 @@ | ||
var e=require("@swan-io/boxed"),t=require("@swan-io/request"),n=require("ts-pattern"),r=require("@0no-co/graphql.web"),i=require("react");function o(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(o=function(){return!!e})()}function u(){return u=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},u.apply(this,arguments)}function a(e){return a=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},a(e)}function c(e,t){return c=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},c(e,t)}function s(e){var t="function"==typeof Map?new Map:void 0;return s=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return function(e,t,n){if(o())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,t);var i=new(e.bind.apply(e,r));return n&&c(i,n.prototype),i}(e,arguments,a(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),c(n,e)},s(e)}var f=Symbol.for("DEEP_MERGE_DELETE"),l=function e(t,n){var r=Array.isArray(t)?Array(t.length):Array.isArray(n)?Array(n.length):{};return Object.getOwnPropertyNames(t).forEach(function(e){n[e]!==f&&(r[e]=t[e])}),Object.getOwnPropertySymbols(t).forEach(function(e){n[e]!==f&&(r[e]=t[e])}),Object.getOwnPropertyNames(n).forEach(function(t){n[t]!==f&&(r[t]=p(r[t])&&p(n[t])?e(r[t],n[t]):n[t])}),Object.getOwnPropertySymbols(n).forEach(function(t){n[t]!==f&&(r[t]=p(r[t])&&p(n[t])?e(r[t],n[t]):n[t])}),r},p=function(e){return null!=e&&"object"==typeof e},m=Object.prototype.hasOwnProperty,h=function e(t,n){if(Object.is(t,n))return!0;if("object"!=typeof t||null===t||"object"!=typeof n||null===n)return!1;var r=Object.keys(t),i=Object.keys(n);if(r.length!==i.length)return!1;for(var o=0,u=r;o<u.length;o++){var a=u[o];if(!m.call(n,a)||!e(t[a],n[a]))return!1}return!0},d=function(e){return JSON.stringify(e)},v=function(t){return n.match(t).with({__typename:n.P.select(n.P.union("Query","Mutation","Subscription"))},function(t){return e.Option.Some(Symbol.for(t))}).with({__typename:n.P.select("name",n.P.string),id:n.P.select("id",n.P.string)},function(t){return e.Option.Some(Symbol.for(t.name+"<"+t.id+">"))}).otherwise(function(){return e.Option.None()})},y=function(t){return n.match(t.operation).with(r.OperationTypeNode.QUERY,function(){return e.Option.Some(Symbol.for("Query"))}).with(r.OperationTypeNode.SUBSCRIPTION,function(){return e.Option.Some(Symbol.for("Subscription"))}).otherwise(function(){return e.Option.None()})},g=function(e,t){return{requestedKeys:new Set([].concat(e.requestedKeys.values(),t.requestedKeys.values())),value:l(e.value,t.value)}},O=/*#__PURE__*/function(){function t(){this.cache=new Map,this.operationCache=new Map}var r=t.prototype;return r.dump=function(){return this.cache},r.getOperationFromCache=function(t,n){var r=d(n);return e.Option.fromNullable(this.operationCache.get(t)).flatMap(function(t){return e.Option.fromNullable(t.get(r))}).flatMap(function(e){return e})},r.setOperationInCache=function(t,n,r){var i=d(n),o=e.Option.fromNullable(this.operationCache.get(t)).getWithDefault(new Map);o.set(i,e.Option.Some(r)),this.operationCache.set(t,o)},r.getFromCache=function(t,n){return this.get(t).flatMap(function(t){return r=t.requestedKeys,[].concat(n.values()).every(function(e){return r.has(e)})?e.Option.Some(t.value):e.Option.None();var r})},r.getFromCacheWithoutKey=function(t){return this.get(t).flatMap(function(t){return e.Option.Some(t.value)})},r.get=function(t){return this.cache.has(t)?e.Option.Some(this.cache.get(t)):e.Option.None()},r.getOrDefault=function(e){return this.cache.has(e)?this.cache.get(e):{requestedKeys:new Set,value:{}}},r.set=function(e,t){this.cache.set(e,t)},r.cacheIfEligible=function(t,r){var i=this;return n.match(v(t)).with(e.Option.P.Some(n.P.select()),function(e){var n=i.getOrDefault(e);return i.set(e,g(n,{requestedKeys:r,value:t})),e}).otherwise(function(){return t})},r.updateFieldInClosestCachedAncestor=function(e){for(var t,n=e.originalFieldName,r=e.fieldNameWithArguments,i=e.value,o=e.path,a=e.variables,c=e.rootTypename,s=e.ancestors.concat(),l=o.concat(),m=[];t=s.pop();){var h=v(0===s.length?u({},t,{__typename:c}):t);if(h.isSome()){var d,y=h.get(),O=this.getOrDefault(y);p(i)&&"string"==typeof i.__typename&&i.__typename.endsWith("Connection")&&(i.__connectionArguments=a);var S=m.reduce(function(e,t){var n;return(n={})[t]=e,n},((d={})[n]=f,d[r]=i,d));this.set(y,g(O,{requestedKeys:new Set,value:S}));break}m.push(l.pop())}},t}(),S=function(e,t){var n=new Set;return e.selectionSet&&function e(i){i.selections.forEach(function(i){if(i.kind===r.Kind.FIELD){var o=N(i,t);n.add(o)}else i.kind===r.Kind.INLINE_FRAGMENT&&e(i.selectionSet)})}(e.selectionSet),n},N=function(e,t){var n=w(e),r=b(e,t);return 0===Object.keys(r).length?Symbol.for(n):Symbol.for(n+"("+JSON.stringify(r)+")")},b=function(e,t){var n,r=null!=(n=e.arguments)?n:[];return Object.fromEntries(r.map(function(e){return[e.name.value,E(e.value,t)]}))},E=function e(t,i){return n.match(t).with({kind:r.Kind.NULL},function(){return null}).with({kind:n.P.union(r.Kind.INT,r.Kind.FLOAT,r.Kind.STRING,r.Kind.BOOLEAN,r.Kind.ENUM)},function(e){return e.value}).with({kind:r.Kind.LIST},function(t){return t.values.map(function(t){return e(t,i)})}).with({kind:r.Kind.OBJECT},function(e){return Object.fromEntries(e.fields.map(function(e){return[e.name.value,e.value]}))}).with({kind:r.Kind.VARIABLE},function(e){return i[e.name.value]}).exhaustive()},w=function(e){return e.alias?e.alias.value:e.name.value},A={kind:r.Kind.FIELD,name:{kind:r.Kind.NAME,value:"__typename"}},I=function(e){var t;return r.visit(e,((t={})[r.Kind.SELECTION_SET]=function(e){return e.selections.find(function(e){return e.kind===r.Kind.FIELD&&"__typename"===e.name.value})?e:u({},e,{selections:[A].concat(e.selections)})},t))},D=function t(i){return n.match(i).with({kind:r.Kind.FIELD},function(t){return"id"===t.name.value?e.Option.Some(t):e.Option.None()}).with({kind:r.Kind.INLINE_FRAGMENT},function(n){return e.Array.findMap(n.selectionSet.selections,t)}).otherwise(function(){return e.Option.None()})},P=function(t,n){var r=e.Array.findMap(t.selections,D);return e.Array.findMap(n.selections,D).isSome()?n:r.map(function(e){return u({},n,{selections:[e].concat(n.selections)})}).getWithDefault(n)},C=function(t,n,r){return"symbol"==typeof n?t.getFromCache(n,r).flatMap(e.Option.fromNullable):e.Option.Some(n)},F=function(t,n){return"symbol"==typeof n?t.getFromCacheWithoutKey(n).flatMap(e.Option.fromNullable):e.Option.Some(n)},M=new WeakMap,T=function(t,i,o){var a=function i(a,c){return a.selections.reduce(function(a,c){return a.flatMap(function(a){return n.match(c).with({kind:r.Kind.FIELD},function(n){var r=w(n),c=N(n,o);if(null==a)return e.Option.None();if(!m.call(a,c))return e.Option.None();var s,f=a[c];if(null==f)return e.Option.Some(u({},a,((s={})[r]=f,s)));if(e.Array.isArray(f)){var l=S(n,o);return e.Option.all(f.map(function(r){return C(t,r,l).flatMap(function(t){return p(t)&&null!=n.selectionSet?i(n.selectionSet,t):e.Option.Some(t)})})).map(function(e){var t;return u({},a,((t={})[r]=e,t))})}var h=S(n,o);return C(t,f,h).flatMap(function(t){return p(t)&&null!=n.selectionSet?i(n.selectionSet,t).map(function(e){var t;return u({},a,((t={})[r]=e,t))}):e.Option.Some(u({},a,((o={})[r]=t,o)));var o})}).with({kind:r.Kind.INLINE_FRAGMENT},function(e){return i(e.selectionSet,a)}).with({kind:r.Kind.FRAGMENT_SPREAD},function(){return e.Option.None()}).exhaustive()})},e.Option.Some(c))};return e.Array.findMap(i.definitions,function(t){return t.kind===r.Kind.OPERATION_DEFINITION?e.Option.Some(t):e.Option.None()}).flatMap(function(e){return y(e).map(function(t){return{operation:e,cacheKey:t}})}).flatMap(function(e){var n=e.operation;return t.getFromCache(e.cacheKey,S(n,o)).map(function(e){return{cache:e,operation:n}})}).flatMap(function(e){return a(e.operation.selectionSet,e.cache)}).map(function(e){return JSON.parse(JSON.stringify(e))}).flatMap(function(t){var n=d(o),r=e.Option.fromNullable(M.get(i)).flatMap(function(t){return e.Option.fromNullable(t.get(n))}).flatMap(function(e){return e});if(r.flatMap(function(e){return e.toOption()}).map(function(e){return h(t,e)}).getWithDefault(!1))return r;var u,a=e.Option.Some(e.Result.Ok(t)),c=null!=(u=M.get(i))?u:new Map;return c.set(n,a),M.set(i,c),a})},k=function(e,t,i,o){var a=function t(i,u,a,c){void 0===a&&(a=[]),i.selections.forEach(function(i){n.match(i).with({kind:r.Kind.FIELD},function(n){var r=w(n),i=N(n,o),s=b(n,o),f=u.at(-1),l=f[r],m=S(n,o);if(null!=l)if(Array.isArray(l))l.forEach(function(o,f){var h=e.cacheIfEligible(o,m),d=Array(l.length);d[f]=h,e.updateFieldInClosestCachedAncestor({originalFieldName:r,fieldNameWithArguments:i,value:d,path:a,ancestors:u,variables:s,rootTypename:c}),p(o)&&!Array.isArray(o)&&t(n.selectionSet,[].concat(u,[l,o]),[].concat(a,[i,f.toString()]),c)});else{var h=e.cacheIfEligible(l,m);e.updateFieldInClosestCachedAncestor({originalFieldName:r,fieldNameWithArguments:i,value:h,path:a,ancestors:u,variables:s,rootTypename:c}),p(l)&&null!=n.selectionSet&&t(n.selectionSet,[].concat(u,[l]),[].concat(a,[i]),c)}else r in f&&e.updateFieldInClosestCachedAncestor({originalFieldName:r,fieldNameWithArguments:i,value:l,path:a,ancestors:u,variables:s,rootTypename:c})}).with({kind:r.Kind.INLINE_FRAGMENT},function(e){t(e.selectionSet,u,a,c)}).with({kind:r.Kind.FRAGMENT_SPREAD},function(){}).exhaustive()})};return t.definitions.forEach(function(t){if(t.kind===r.Kind.OPERATION_DEFINITION){var c=n.match(t.operation).with(r.OperationTypeNode.QUERY,function(){return"Query"}).with(r.OperationTypeNode.SUBSCRIPTION,function(){return"Subscription"}).with(r.OperationTypeNode.MUTATION,function(){return"Mutation"}).exhaustive();e.cacheIfEligible(p(i)?u({},i,{__typename:c}):i,S(t,o)),a(t.selectionSet,[i],[],c)}}),e},R=/*#__PURE__*/function(e){function t(n){var r;return(r=e.call(this,"Received an invalid GraphQL response")||this).response=void 0,r.name=r.constructor.name,r.response=n,Object.setPrototypeOf(r,t.prototype),r}var n,r;return r=e,(n=t).prototype=Object.create(r.prototype),n.prototype.constructor=n,c(n,r),t}(/*#__PURE__*/s(Error)),_=function(e){return n.match(e).with({message:n.P.string,nodes:n.P.optional(n.P.any),source:n.P.optional(n.P.any),positions:n.P.optional(n.P.any),path:n.P.optional(n.P.any),error:n.P.optional(n.P.any),extensions:n.P.optional(n.P.any)},function(e){var t=e.message,i=e.nodes,o=e.source,u=e.positions,a=e.path,c=e.extensions,s=n.match(e.error).with({message:n.P.string},function(e){return new Error(e.message)}).otherwise(function(){});return new r.GraphQLError(t,i,o,u,a,s,c)}).otherwise(function(e){return new r.GraphQLError(JSON.stringify(e))})},K={toArray:function(e){return Array.isArray(e)?e:[e]},forEach:function(e,t){K.toArray(e).forEach(t)}},j=function(e){return Boolean(e&&e.length)},q={OperationDefinition:function(e){if("query"===e.operation&&!e.name&&!j(e.variableDefinitions)&&!j(e.directives))return q.SelectionSet(e.selectionSet);var t=e.operation;return e.name&&(t+=" "+e.name.value),j(e.variableDefinitions)&&(e.name||(t+=" "),t+="("+e.variableDefinitions.map(q.VariableDefinition).join(", ")+")"),j(e.directives)&&(t+=" "+e.directives.map(q.Directive).join(" ")),t+" "+q.SelectionSet(e.selectionSet)},VariableDefinition:function(e){var t=q.Variable(e.variable)+": "+L(e.type);return e.defaultValue&&(t+=" = "+L(e.defaultValue)),j(e.directives)&&(t+=" "+e.directives.map(q.Directive).join(" ")),t},Field:function(e){var t=(e.alias?e.alias.value+": ":"")+e.name.value;if(j(e.arguments)){var n=e.arguments.map(q.Argument),r=t+"("+n.join(", ")+")";t=r.length>80?t+"("+n.join(" ")+")":r}return j(e.directives)&&(t+=" "+e.directives.map(q.Directive).join(" ")),e.selectionSet?t+" "+q.SelectionSet(e.selectionSet):t},StringValue:function(e){return e.block?'"""'+e.value.replace(/"""/g,'\\"""')+'"""':JSON.stringify(e.value)},BooleanValue:function(e){return String(e.value)},NullValue:function(){return"null"},IntValue:function(e){return e.value},FloatValue:function(e){return e.value},EnumValue:function(e){return e.value},Name:function(e){return e.value},Variable:function(e){return"$"+e.name.value},ListValue:function(e){return"["+e.values.map(L).join(", ")+"]"},ObjectValue:function(e){return"{"+e.fields.map(q.ObjectField).join(", ")+"}"},ObjectField:function(e){return e.name.value+": "+L(e.value)},Document:function(e){return j(e.definitions)?e.definitions.map(L).join(" "):""},SelectionSet:function(e){return"{"+e.selections.map(L).join(" ")+"}"},Argument:function(e){return e.name.value+": "+L(e.value)},FragmentSpread:function(e){var t="..."+e.name.value;return j(e.directives)&&(t+=" "+e.directives.map(q.Directive).join(" ")),t},InlineFragment:function(e){var t="...";return e.typeCondition&&(t+=" on "+e.typeCondition.name.value),j(e.directives)&&(t+=" "+e.directives.map(q.Directive).join(" ")),t+" "+L(e.selectionSet)},FragmentDefinition:function(e){var t="fragment "+e.name.value;return t+=" on "+e.typeCondition.name.value,j(e.directives)&&(t+=" "+e.directives.map(q.Directive).join(" ")),t+" "+L(e.selectionSet)},Directive:function(e){var t="@"+e.name.value;return j(e.arguments)&&(t+="("+e.arguments.map(q.Argument).join(", ")+")"),t},NamedType:function(e){return e.name.value},ListType:function(e){return"["+L(e.type)+"]"},NonNullType:function(e){return L(e.type)+"!"}},L=function(e){return"function"==typeof q[e.kind]?q[e.kind](e):""},x=function(r){return e.Result.Ok(r).flatMap(t.badStatusToError).flatMap(t.emptyToError).flatMap(function(t){return n.match(t).returnType().with({errors:n.P.select(n.P.array())},function(t){return e.Result.Error(t.map(_))}).with({data:n.P.select(n.P.not(n.P.nullish))},function(t){return e.Result.Ok(t)}).otherwise(function(t){return e.Result.Error(new R(t))})})},G=function(e){var n=e.variables;return t.Request.make({url:e.url,method:"POST",responseType:"json",headers:e.headers,body:JSON.stringify({operationName:e.operationName,query:L(e.document),variables:n})})},V=/*#__PURE__*/function(){function t(e){var t,n,r;this.url=void 0,this.headers=void 0,this.cache=void 0,this.makeRequest=void 0,this.parseResponse=void 0,this.subscribers=void 0,this.transformedDocuments=void 0,this.transformedDocumentsForRequest=void 0,this.url=e.url,this.headers=null!=(t=e.headers)?t:{"Content-Type":"application/json"},this.cache=new O,this.makeRequest=null!=(n=e.makeRequest)?n:G,this.parseResponse=null!=(r=e.parseResponse)?r:x,this.subscribers=new Set,this.transformedDocuments=new Map,this.transformedDocumentsForRequest=new Map}var i=t.prototype;return i.getTransformedDocument=function(e){if(this.transformedDocuments.has(e))return this.transformedDocuments.get(e);var t,n,i,o,a=(t=I(e),o={},r.visit(t,((n={})[r.Kind.FRAGMENT_DEFINITION]=function(e){o[e.name.value]=e},n)),r.visit(t,((i={})[r.Kind.FRAGMENT_DEFINITION]=function(){return null},i.enter=function e(t){if(t.kind===r.Kind.FRAGMENT_SPREAD){var n=t.name.value,i=o[n];if(!i)throw new Error('Fragment "'+n+'" is not defined.');return{kind:r.Kind.INLINE_FRAGMENT,typeCondition:i.typeCondition,selectionSet:i.selectionSet}}return t.kind===r.Kind.SELECTION_SET?u({},t,{selections:t.selections.map(function(t){return e(t)})}):"selectionSet"in t&&null!=t.selectionSet?u({},t,{selectionSet:e(t.selectionSet)}):t},i)));return this.transformedDocuments.set(e,a),a},i.getTransformedDocumentsForRequest=function(e){if(this.transformedDocumentsForRequest.has(e))return this.transformedDocumentsForRequest.get(e);var t=I(e);return this.transformedDocumentsForRequest.set(e,t),t},i.subscribe=function(e){var t=this;return this.subscribers.add(e),function(){return t.subscribers.delete(e)}},i.request=function(t,i,o){var a=this,c=(void 0===o?{}:o).optimize,s=void 0!==c&&c,f=this.getTransformedDocument(t),l=this.getTransformedDocumentsForRequest(t),p=function(t){return e.Array.findMap(t.definitions,function(t){return t.kind===r.Kind.OPERATION_DEFINITION?e.Option.fromNullable(t.name).map(function(e){return e.value}):e.Option.None()})}(f).getWithDefault("Untitled"),h=i,d=s?function(t,i,o){var a=function i(a,c,s){var f=e.Array.filterMap(a.selections,function(a){return n.match(a).with({kind:r.Kind.FIELD},function(n){var r=N(n,o);if(null==c)return e.Option.Some(n);if(!m.call(c,r))return e.Option.Some(n);if(s.has(r)){var a=c[r],f=S(n,o);if(e.Array.isArray(a))return a.reduce(function(r,o){var a=F(t,o);if(a.isNone())return e.Option.Some(n);var c=n.selectionSet;return null!=c?i(c,a.get(),f).map(function(e){return u({},n,{selectionSet:P(c,e)})}):r},e.Option.None());var l=F(t,a);if(l.isNone())return e.Option.Some(n);var p=n.selectionSet;return null!=p?i(p,l.get(),f).map(function(e){return u({},n,{selectionSet:P(p,e)})}):e.Option.None()}return e.Option.Some(n)}).with({kind:r.Kind.INLINE_FRAGMENT},function(e){return i(e.selectionSet,c,s).map(function(t){return u({},e,{selectionSet:t})})}).with({kind:r.Kind.FRAGMENT_SPREAD},function(){return e.Option.None()}).exhaustive()});return f.length>0?e.Option.Some(u({},a,{selections:f})):e.Option.None()};return e.Array.findMap(i.definitions,function(t){return t.kind===r.Kind.OPERATION_DEFINITION?e.Option.Some(t):e.Option.None()}).flatMap(function(e){return y(e).map(function(t){return{operation:e,cacheKey:t}})}).flatMap(function(e){var n=e.operation,r=e.cacheKey,i=S(n,o);return t.getFromCache(r,i).map(function(e){return{cache:e,operation:n,selectedKeys:i}})}).flatMap(function(e){var t=e.operation;return a(t.selectionSet,e.cache,e.selectedKeys).map(function(e){return u({},i,{definitions:[u({},t,{selectionSet:e})]})})})}(this.cache,f,h).map(I):e.Option.Some(l);if(d.isNone()){var v=T(this.cache,f,h);if(v.isSome())return e.Future.value(v.get())}return this.makeRequest({url:this.url,headers:this.headers,operationName:p,document:d.getWithDefault(l),variables:h}).mapOkToResult(this.parseResponse).mapOk(function(e){return e}).tapOk(function(e){k(a.cache,f,e,h)}).tap(function(e){a.cache.setOperationInCache(f,h,e),a.subscribers.forEach(function(e){e()})})},i.readFromCache=function(t,r){var i=this,o=r,u=this.getTransformedDocument(t);return n.match(this.cache.getOperationFromCache(u,o)).with(e.Option.P.Some(e.Result.P.Error(n.P._)),function(e){return e}).otherwise(function(){return T(i.cache,u,o)})},i.query=function(e,t,n){return this.request(e,t,n)},i.commitMutation=function(e,t,n){return this.request(e,t,n)},t}(),W=i.createContext(new V({url:"/graphql"})),B=function(e){return function(t){var r,o,a,c=i.useRef(t);return c.current=(r=c.current,a=e,null==(o=t)||null==r||"__connectionArguments"in o&&p(o.__connectionArguments)&&null==o.__connectionArguments[a]?o:"after"===a&&o.pageInfo.endCursor===r.pageInfo.endCursor||"before"===a&&o.pageInfo.startCursor===r.pageInfo.startCursor?r:u({},o,{edges:n.match(a).with("before",function(){var e,t;return[].concat(null!=(e=o.edges)?e:[],null!=(t=r.edges)?t:[])}).with("after",function(){var e,t;return[].concat(null!=(e=r.edges)?e:[],null!=(t=o.edges)?t:[])}).exhaustive(),pageInfo:n.match(a).with("before",function(){return{hasPreviousPage:o.pageInfo.hasPreviousPage,startCursor:o.pageInfo.startCursor,hasNextPage:r.pageInfo.hasNextPage,endCursor:r.pageInfo.endCursor}}).with("after",function(){return{hasPreviousPage:r.pageInfo.hasPreviousPage,startCursor:r.pageInfo.startCursor,hasNextPage:o.pageInfo.hasNextPage,endCursor:o.pageInfo.endCursor}}).exhaustive()})),c.current}},Q=B("after"),J=B("before");exports.Client=V,exports.ClientContext=W,exports.ClientError=K,exports.useBackwardPagination=J,exports.useDeferredQuery=function(t,n){var r=(void 0===n?{}:n).optimize,o=void 0!==r&&r,u=i.useContext(W),a=i.useState(t)[0],c=i.useState(e.Option.None()),s=c[0],f=c[1],l=i.useCallback(function(){return s.flatMap(function(e){return u.readFromCache(a,e)})},[u,a,s]),p=i.useSyncExternalStore(function(e){return u.subscribe(e)},l),m=i.useMemo(function(){return p.map(function(t){return e.AsyncData.Done(t)}).getWithDefault(e.AsyncData.NotAsked())},[p]),d=i.useState(!1),v=d[0],y=d[1],g=i.useCallback(function(t){return f(function(n){return n.match({None:function(){return e.Option.Some(t)},Some:function(r){return h(r,t)?n:e.Option.Some(t)}})}),y(!0),u.request(a,t,{optimize:o}).tap(function(){return y(!1)})},[u,a,o]);return[v?e.AsyncData.Loading():m,g]},exports.useForwardPagination=Q,exports.useMutation=function(t){var n=i.useContext(W),r=i.useState(t)[0],o=i.useState(e.AsyncData.NotAsked()),u=o[0],a=o[1];return[i.useCallback(function(t){return a(e.AsyncData.Loading()),n.commitMutation(r,t).tap(function(t){return a(e.AsyncData.Done(t))})},[n,r]),u]},exports.useQuery=function(t,n,r){var o=void 0===r?{}:r,u=o.suspense,a=void 0!==u&&u,c=o.optimize,s=void 0!==c&&c,f=i.useContext(W),l=i.useState(t)[0],p=i.useState(n),m=p[0],d=p[1];i.useEffect(function(){h(m,n)||d(n)},[m,n]);var v,y,g=i.useCallback(function(){return f.readFromCache(l,m)},[f,l,m]),O=i.useSyncExternalStore(function(e){return f.subscribe(e)},g),S=i.useMemo(function(){return O.map(function(t){return e.AsyncData.Done(t)}).getWithDefault(e.AsyncData.Loading())},[O]),N=(y=i.useRef(v=S),i.useEffect(function(){y.current=v},[v]),y.current),b=i.useRef(!0);i.useEffect(function(){if(!a||!b.current){var e=f.query(l,m,{optimize:s});return function(){return e.cancel()}}b.current=!1},[f,a,s,l,m]);var E=i.useState(!1),w=E[0],A=E[1],I=i.useCallback(function(){return A(!0),f.request(l,m).tap(function(){return A(!1)})},[f,l,m]),D=i.useState(!1),P=D[0],C=D[1],F=i.useCallback(function(){return C(!0),f.request(l,m).tap(function(){return C(!1)})},[f,l,m]),M=w||P||S.isLoading(),T=P?e.AsyncData.Loading():M?N:S;if(a&&T.isLoading())throw f.query(l,m,{optimize:s}).toPromise();return[T,{isLoading:M,refresh:I,reload:F}]}; | ||
var e=require("@swan-io/boxed"),t=require("@swan-io/request"),n=require("ts-pattern"),r=require("@0no-co/graphql.web"),i=require("react");function o(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(o=function(){return!!e})()}function u(){return u=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},u.apply(this,arguments)}function a(e){return a=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},a(e)}function c(e,t){return c=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},c(e,t)}function s(e){var t="function"==typeof Map?new Map:void 0;return s=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return function(e,t,n){if(o())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,t);var i=new(e.bind.apply(e,r));return n&&c(i,n.prototype),i}(e,arguments,a(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),c(n,e)},s(e)}var f=Symbol.for("DEEP_MERGE_DELETE"),l=function e(t,n){var r=Array.isArray(t)?Array(t.length):Array.isArray(n)?Array(n.length):{};return Object.getOwnPropertyNames(t).forEach(function(e){n[e]!==f&&(r[e]=t[e])}),Object.getOwnPropertySymbols(t).forEach(function(e){n[e]!==f&&(r[e]=t[e])}),Object.getOwnPropertyNames(n).forEach(function(t){n[t]!==f&&(r[t]=p(r[t])&&p(n[t])?e(r[t],n[t]):n[t])}),Object.getOwnPropertySymbols(n).forEach(function(t){n[t]!==f&&(r[t]=p(r[t])&&p(n[t])?e(r[t],n[t]):n[t])}),r},p=function(e){return null!=e&&"object"==typeof e},m=Object.prototype.hasOwnProperty,h=function e(t,n){if(Object.is(t,n))return!0;if("object"!=typeof t||null===t||"object"!=typeof n||null===n)return!1;var r=Object.keys(t),i=Object.keys(n);if(r.length!==i.length)return!1;for(var o=0,u=r;o<u.length;o++){var a=u[o];if(!m.call(n,a)||!e(t[a],n[a]))return!1}return!0},d=function(e){return JSON.stringify(e)},v=function(t){return n.match(t).with({__typename:n.P.select(n.P.union("Query","Mutation","Subscription"))},function(t){return e.Option.Some(Symbol.for(t))}).with({__typename:n.P.select("name",n.P.string),id:n.P.select("id",n.P.string)},function(t){return e.Option.Some(Symbol.for(t.name+"<"+t.id+">"))}).otherwise(function(){return e.Option.None()})},y=function(t){return n.match(t.operation).with(r.OperationTypeNode.QUERY,function(){return e.Option.Some(Symbol.for("Query"))}).with(r.OperationTypeNode.SUBSCRIPTION,function(){return e.Option.Some(Symbol.for("Subscription"))}).otherwise(function(){return e.Option.None()})},g=function(e,t){return{requestedKeys:new Set([].concat(e.requestedKeys.values(),t.requestedKeys.values())),value:l(e.value,t.value)}},O=/*#__PURE__*/function(){function t(){this.cache=new Map,this.operationCache=new Map}var r=t.prototype;return r.dump=function(){return this.cache},r.getOperationFromCache=function(t,n){var r=d(n);return e.Option.fromNullable(this.operationCache.get(t)).flatMap(function(t){return e.Option.fromNullable(t.get(r))}).flatMap(function(e){return e})},r.setOperationInCache=function(t,n,r){var i=d(n),o=e.Option.fromNullable(this.operationCache.get(t)).getWithDefault(new Map);o.set(i,e.Option.Some(r)),this.operationCache.set(t,o)},r.getFromCache=function(t,n){return this.get(t).flatMap(function(t){return r=t.requestedKeys,[].concat(n.values()).every(function(e){return r.has(e)})?e.Option.Some(t.value):e.Option.None();var r})},r.getFromCacheWithoutKey=function(t){return this.get(t).flatMap(function(t){return e.Option.Some(t.value)})},r.get=function(t){return this.cache.has(t)?e.Option.Some(this.cache.get(t)):e.Option.None()},r.getOrDefault=function(e){return this.cache.has(e)?this.cache.get(e):{requestedKeys:new Set,value:{}}},r.set=function(e,t){this.cache.set(e,t)},r.cacheIfEligible=function(t,r){var i=this;return n.match(v(t)).with(e.Option.P.Some(n.P.select()),function(e){var n=i.getOrDefault(e);return i.set(e,g(n,{requestedKeys:r,value:t})),e}).otherwise(function(){return t})},r.updateFieldInClosestCachedAncestor=function(e){for(var t,n=e.originalFieldName,r=e.fieldNameWithArguments,i=e.value,o=e.path,a=e.variables,c=e.rootTypename,s=e.ancestors.concat(),l=o.concat(),m=[];t=s.pop();){var h=v(0===s.length?u({},t,{__typename:c}):t);if(h.isSome()){var d,y=h.get(),O=this.getOrDefault(y);p(i)&&"string"==typeof i.__typename&&i.__typename.endsWith("Connection")&&(i.__connectionArguments=a);var S=m.reduce(function(e,t){var n;return(n={})[t]=e,n},((d={})[n]=f,d[r]=i,d));this.set(y,g(O,{requestedKeys:new Set,value:S}));break}m.push(l.pop())}},t}(),S=function(e,t){var n=new Set;return e.selectionSet&&function e(i){i.selections.forEach(function(i){if(i.kind===r.Kind.FIELD){var o=N(i,t);n.add(o)}else i.kind===r.Kind.INLINE_FRAGMENT&&e(i.selectionSet)})}(e.selectionSet),n},N=function(e,t){var n=w(e),r=b(e,t);return 0===Object.keys(r).length?Symbol.for(n):Symbol.for(n+"("+JSON.stringify(r)+")")},b=function(e,t){var n,r=null!=(n=e.arguments)?n:[];return Object.fromEntries(r.map(function(e){return[e.name.value,E(e.value,t)]}))},E=function e(t,i){return n.match(t).with({kind:r.Kind.NULL},function(){return null}).with({kind:n.P.union(r.Kind.INT,r.Kind.FLOAT,r.Kind.STRING,r.Kind.BOOLEAN,r.Kind.ENUM)},function(e){return e.value}).with({kind:r.Kind.LIST},function(t){return t.values.map(function(t){return e(t,i)})}).with({kind:r.Kind.OBJECT},function(e){return Object.fromEntries(e.fields.map(function(e){return[e.name.value,e.value]}))}).with({kind:r.Kind.VARIABLE},function(e){return i[e.name.value]}).exhaustive()},w=function(e){return e.alias?e.alias.value:e.name.value},A={kind:r.Kind.FIELD,name:{kind:r.Kind.NAME,value:"__typename"}},I=function(e){var t;return r.visit(e,((t={})[r.Kind.SELECTION_SET]=function(e){return e.selections.find(function(e){return e.kind===r.Kind.FIELD&&"__typename"===e.name.value})?e:u({},e,{selections:[A].concat(e.selections)})},t))},D=function t(i){return n.match(i).with({kind:r.Kind.FIELD},function(t){return"id"===t.name.value?e.Option.Some(t):e.Option.None()}).with({kind:r.Kind.INLINE_FRAGMENT},function(n){return e.Array.findMap(n.selectionSet.selections,t)}).otherwise(function(){return e.Option.None()})},P=function(t,n){var r=e.Array.findMap(t.selections,D);return e.Array.findMap(n.selections,D).isSome()?n:r.map(function(e){return u({},n,{selections:[e].concat(n.selections)})}).getWithDefault(n)},C=function(t,n,r){return"symbol"==typeof n?t.getFromCache(n,r).flatMap(e.Option.fromNullable):e.Option.Some(n)},F=function(t,n){return"symbol"==typeof n?t.getFromCacheWithoutKey(n).flatMap(e.Option.fromNullable):e.Option.Some(n)},M=new WeakMap,T=function(t,i,o){var a=function i(a,c){return a.selections.reduce(function(a,c){return a.flatMap(function(a){return n.match(c).with({kind:r.Kind.FIELD},function(n){var r=w(n),c=N(n,o);if(null==a)return e.Option.None();if(!m.call(a,c))return e.Option.None();var s,f=a[c];if(null==f)return e.Option.Some(u({},a,((s={})[r]=f,s)));if(e.Array.isArray(f)){var l=S(n,o);return e.Option.all(f.map(function(r){return C(t,r,l).flatMap(function(t){return p(t)&&null!=n.selectionSet?i(n.selectionSet,t):e.Option.Some(t)})})).map(function(e){var t;return u({},a,((t={})[r]=e,t))})}var h=S(n,o);return C(t,f,h).flatMap(function(t){return p(t)&&null!=n.selectionSet?i(n.selectionSet,t).map(function(e){var t;return u({},a,((t={})[r]=e,t))}):e.Option.Some(u({},a,((o={})[r]=t,o)));var o})}).with({kind:r.Kind.INLINE_FRAGMENT},function(e){return i(e.selectionSet,a)}).with({kind:r.Kind.FRAGMENT_SPREAD},function(){return e.Option.None()}).exhaustive()})},e.Option.Some(c))};return e.Array.findMap(i.definitions,function(t){return t.kind===r.Kind.OPERATION_DEFINITION?e.Option.Some(t):e.Option.None()}).flatMap(function(e){return y(e).map(function(t){return{operation:e,cacheKey:t}})}).flatMap(function(e){var n=e.operation;return t.getFromCache(e.cacheKey,S(n,o)).map(function(e){return{cache:e,operation:n}})}).flatMap(function(e){return a(e.operation.selectionSet,e.cache)}).map(function(e){return JSON.parse(JSON.stringify(e))}).flatMap(function(t){var n=d(o),r=e.Option.fromNullable(M.get(i)).flatMap(function(t){return e.Option.fromNullable(t.get(n))}).flatMap(function(e){return e});if(r.flatMap(function(e){return e.toOption()}).map(function(e){return h(t,e)}).getWithDefault(!1))return r;var u,a=e.Option.Some(e.Result.Ok(t)),c=null!=(u=M.get(i))?u:new Map;return c.set(n,a),M.set(i,c),a})},k=function(e,t,i,o){var a=function t(i,u,a,c){void 0===a&&(a=[]),i.selections.forEach(function(i){n.match(i).with({kind:r.Kind.FIELD},function(n){var r=w(n),i=N(n,o),s=b(n,o),f=u.at(-1),l=f[r],m=S(n,o);if(null!=l)if(Array.isArray(l))l.forEach(function(o,f){var h=e.cacheIfEligible(o,m),d=Array(l.length);d[f]=h,e.updateFieldInClosestCachedAncestor({originalFieldName:r,fieldNameWithArguments:i,value:d,path:a,ancestors:u,variables:s,rootTypename:c}),p(o)&&!Array.isArray(o)&&t(n.selectionSet,[].concat(u,[l,o]),[].concat(a,[i,f.toString()]),c)});else{var h=e.cacheIfEligible(l,m);e.updateFieldInClosestCachedAncestor({originalFieldName:r,fieldNameWithArguments:i,value:h,path:a,ancestors:u,variables:s,rootTypename:c}),p(l)&&null!=n.selectionSet&&t(n.selectionSet,[].concat(u,[l]),[].concat(a,[i]),c)}else r in f&&e.updateFieldInClosestCachedAncestor({originalFieldName:r,fieldNameWithArguments:i,value:l,path:a,ancestors:u,variables:s,rootTypename:c})}).with({kind:r.Kind.INLINE_FRAGMENT},function(e){t(e.selectionSet,u,a,c)}).with({kind:r.Kind.FRAGMENT_SPREAD},function(){}).exhaustive()})};return t.definitions.forEach(function(t){if(t.kind===r.Kind.OPERATION_DEFINITION){var c=n.match(t.operation).with(r.OperationTypeNode.QUERY,function(){return"Query"}).with(r.OperationTypeNode.SUBSCRIPTION,function(){return"Subscription"}).with(r.OperationTypeNode.MUTATION,function(){return"Mutation"}).exhaustive();e.cacheIfEligible(p(i)?u({},i,{__typename:c}):i,S(t,o)),a(t.selectionSet,[i],[],c)}}),e},R=/*#__PURE__*/function(e){function t(n){var r;return(r=e.call(this,"Received an invalid GraphQL response")||this).response=void 0,r.name=r.constructor.name,r.response=n,Object.setPrototypeOf(r,t.prototype),r}var n,r;return r=e,(n=t).prototype=Object.create(r.prototype),n.prototype.constructor=n,c(n,r),t}(/*#__PURE__*/s(Error)),_=function(e){return n.match(e).with({message:n.P.string,nodes:n.P.optional(n.P.any),source:n.P.optional(n.P.any),positions:n.P.optional(n.P.any),path:n.P.optional(n.P.any),error:n.P.optional(n.P.any),extensions:n.P.optional(n.P.any)},function(e){var t=e.message,i=e.nodes,o=e.source,u=e.positions,a=e.path,c=e.extensions,s=n.match(e.error).with({message:n.P.string},function(e){return new Error(e.message)}).otherwise(function(){});return new r.GraphQLError(t,i,o,u,a,s,c)}).otherwise(function(e){return new r.GraphQLError(JSON.stringify(e))})},K={toArray:function(e){return Array.isArray(e)?e:[e]},forEach:function(e,t){K.toArray(e).forEach(t)}},j=function(e){return Boolean(e&&e.length)},q={OperationDefinition:function(e){if("query"===e.operation&&!e.name&&!j(e.variableDefinitions)&&!j(e.directives))return q.SelectionSet(e.selectionSet);var t=e.operation;return e.name&&(t+=" "+e.name.value),j(e.variableDefinitions)&&(e.name||(t+=" "),t+="("+e.variableDefinitions.map(q.VariableDefinition).join(", ")+")"),j(e.directives)&&(t+=" "+e.directives.map(q.Directive).join(" ")),t+" "+q.SelectionSet(e.selectionSet)},VariableDefinition:function(e){var t=q.Variable(e.variable)+": "+L(e.type);return e.defaultValue&&(t+=" = "+L(e.defaultValue)),j(e.directives)&&(t+=" "+e.directives.map(q.Directive).join(" ")),t},Field:function(e){var t=(e.alias?e.alias.value+": ":"")+e.name.value;if(j(e.arguments)){var n=e.arguments.map(q.Argument),r=t+"("+n.join(", ")+")";t=r.length>80?t+"("+n.join(" ")+")":r}return j(e.directives)&&(t+=" "+e.directives.map(q.Directive).join(" ")),e.selectionSet?t+" "+q.SelectionSet(e.selectionSet):t},StringValue:function(e){return e.block?'"""'+e.value.replace(/"""/g,'\\"""')+'"""':JSON.stringify(e.value)},BooleanValue:function(e){return String(e.value)},NullValue:function(){return"null"},IntValue:function(e){return e.value},FloatValue:function(e){return e.value},EnumValue:function(e){return e.value},Name:function(e){return e.value},Variable:function(e){return"$"+e.name.value},ListValue:function(e){return"["+e.values.map(L).join(", ")+"]"},ObjectValue:function(e){return"{"+e.fields.map(q.ObjectField).join(", ")+"}"},ObjectField:function(e){return e.name.value+": "+L(e.value)},Document:function(e){return j(e.definitions)?e.definitions.map(L).join(" "):""},SelectionSet:function(e){return"{"+e.selections.map(L).join(" ")+"}"},Argument:function(e){return e.name.value+": "+L(e.value)},FragmentSpread:function(e){var t="..."+e.name.value;return j(e.directives)&&(t+=" "+e.directives.map(q.Directive).join(" ")),t},InlineFragment:function(e){var t="...";return e.typeCondition&&(t+=" on "+e.typeCondition.name.value),j(e.directives)&&(t+=" "+e.directives.map(q.Directive).join(" ")),t+" "+L(e.selectionSet)},FragmentDefinition:function(e){var t="fragment "+e.name.value;return t+=" on "+e.typeCondition.name.value,j(e.directives)&&(t+=" "+e.directives.map(q.Directive).join(" ")),t+" "+L(e.selectionSet)},Directive:function(e){var t="@"+e.name.value;return j(e.arguments)&&(t+="("+e.arguments.map(q.Argument).join(", ")+")"),t},NamedType:function(e){return e.name.value},ListType:function(e){return"["+L(e.type)+"]"},NonNullType:function(e){return L(e.type)+"!"}},L=function(e){return"function"==typeof q[e.kind]?q[e.kind](e):""},x=function(r){return e.Result.Ok(r).flatMap(t.badStatusToError).flatMap(t.emptyToError).flatMap(function(t){return n.match(t).returnType().with({errors:n.P.select(n.P.array())},function(t){return e.Result.Error(t.map(_))}).with({data:n.P.select(n.P.not(n.P.nullish))},function(t){return e.Result.Ok(t)}).otherwise(function(t){return e.Result.Error(new R(t))})})},G=function(e){var n=e.variables;return t.Request.make({url:e.url,method:"POST",responseType:"json",headers:e.headers,body:JSON.stringify({operationName:e.operationName,query:L(e.document),variables:n})})},V=/*#__PURE__*/function(){function t(e){var t,n,r;this.url=void 0,this.headers=void 0,this.cache=void 0,this.makeRequest=void 0,this.parseResponse=void 0,this.subscribers=void 0,this.transformedDocuments=void 0,this.transformedDocumentsForRequest=void 0,this.url=e.url,this.headers=null!=(t=e.headers)?t:{"Content-Type":"application/json"},this.cache=new O,this.makeRequest=null!=(n=e.makeRequest)?n:G,this.parseResponse=null!=(r=e.parseResponse)?r:x,this.subscribers=new Set,this.transformedDocuments=new Map,this.transformedDocumentsForRequest=new Map}var i=t.prototype;return i.getTransformedDocument=function(e){if(this.transformedDocuments.has(e))return this.transformedDocuments.get(e);var t,n,i,o,a=(t=I(e),o={},r.visit(t,((n={})[r.Kind.FRAGMENT_DEFINITION]=function(e){o[e.name.value]=e},n)),r.visit(t,((i={})[r.Kind.FRAGMENT_DEFINITION]=function(){return null},i.enter=function e(t){if(t.kind===r.Kind.FRAGMENT_SPREAD){var n=t.name.value,i=o[n];if(!i)throw new Error('Fragment "'+n+'" is not defined.');return{kind:r.Kind.INLINE_FRAGMENT,typeCondition:i.typeCondition,selectionSet:i.selectionSet}}return t.kind===r.Kind.SELECTION_SET?u({},t,{selections:t.selections.map(function(t){return e(t)})}):"selectionSet"in t&&null!=t.selectionSet?u({},t,{selectionSet:e(t.selectionSet)}):t},i)));return this.transformedDocuments.set(e,a),a},i.getTransformedDocumentsForRequest=function(e){if(this.transformedDocumentsForRequest.has(e))return this.transformedDocumentsForRequest.get(e);var t=I(e);return this.transformedDocumentsForRequest.set(e,t),t},i.subscribe=function(e){var t=this;return this.subscribers.add(e),function(){return t.subscribers.delete(e)}},i.request=function(t,i,o){var a=this,c=(void 0===o?{}:o).optimize,s=void 0!==c&&c,f=this.getTransformedDocument(t),l=this.getTransformedDocumentsForRequest(t),p=function(t){return e.Array.findMap(t.definitions,function(t){return t.kind===r.Kind.OPERATION_DEFINITION?e.Option.fromNullable(t.name).map(function(e){return e.value}):e.Option.None()})}(f).getWithDefault("Untitled"),h=i,d=s?function(t,i,o){var a=function i(a,c,s){var f=e.Array.filterMap(a.selections,function(a){return n.match(a).with({kind:r.Kind.FIELD},function(n){var r=N(n,o);if(null==c)return e.Option.Some(n);if(!m.call(c,r))return e.Option.Some(n);if(s.has(r)){var a=c[r],f=S(n,o);if(e.Array.isArray(a))return a.reduce(function(r,o){var a=F(t,o);if(a.isNone())return e.Option.Some(n);var c=n.selectionSet;return null!=c?i(c,a.get(),f).map(function(e){return u({},n,{selectionSet:P(c,e)})}):r},e.Option.None());var l=F(t,a);if(l.isNone())return e.Option.Some(n);var p=n.selectionSet;return null!=p?i(p,l.get(),f).map(function(e){return u({},n,{selectionSet:P(p,e)})}):e.Option.None()}return e.Option.Some(n)}).with({kind:r.Kind.INLINE_FRAGMENT},function(e){return i(e.selectionSet,c,s).map(function(t){return u({},e,{selectionSet:t})})}).with({kind:r.Kind.FRAGMENT_SPREAD},function(){return e.Option.None()}).exhaustive()});return f.length>0?e.Option.Some(u({},a,{selections:f})):e.Option.None()};return e.Array.findMap(i.definitions,function(t){return t.kind===r.Kind.OPERATION_DEFINITION?e.Option.Some(t):e.Option.None()}).flatMap(function(e){return y(e).map(function(t){return{operation:e,cacheKey:t}})}).flatMap(function(e){var n=e.operation,r=e.cacheKey,i=S(n,o);return t.getFromCache(r,i).map(function(e){return{cache:e,operation:n,selectedKeys:i}})}).flatMap(function(e){var t=e.operation;return a(t.selectionSet,e.cache,e.selectedKeys).map(function(e){return u({},i,{definitions:[u({},t,{selectionSet:e})]})})})}(this.cache,f,h).map(I):e.Option.Some(l);if(d.isNone()){var v=T(this.cache,f,h);if(v.isSome())return e.Future.value(v.get())}return this.makeRequest({url:this.url,headers:this.headers,operationName:p,document:d.getWithDefault(l),variables:h}).mapOkToResult(this.parseResponse).mapOk(function(e){return e}).tapOk(function(e){k(a.cache,f,e,h)}).tap(function(e){a.cache.setOperationInCache(f,h,e),a.subscribers.forEach(function(e){e()})})},i.readFromCache=function(t,r){var i=this,o=r,u=this.getTransformedDocument(t);return n.match(this.cache.getOperationFromCache(u,o)).with(e.Option.P.Some(e.Result.P.Error(n.P._)),function(e){return e}).otherwise(function(){return T(i.cache,u,o)})},i.query=function(e,t,n){return this.request(e,t,n)},i.commitMutation=function(e,t,n){return this.request(e,t,n)},t}(),W=i.createContext(new V({url:"/graphql"})),B=function(e){return function(t){var r,o,a,c=i.useRef(t);return c.current=(r=c.current,a=e,null==(o=t)||null==r||"__connectionArguments"in o&&p(o.__connectionArguments)&&null==o.__connectionArguments[a]?o:"after"===a&&o.pageInfo.endCursor===r.pageInfo.endCursor||"before"===a&&o.pageInfo.startCursor===r.pageInfo.startCursor?r:u({},o,{edges:n.match(a).with("before",function(){var e,t;return[].concat(null!=(e=o.edges)?e:[],null!=(t=r.edges)?t:[])}).with("after",function(){var e,t;return[].concat(null!=(e=r.edges)?e:[],null!=(t=o.edges)?t:[])}).exhaustive(),pageInfo:n.match(a).with("before",function(){return{hasPreviousPage:o.pageInfo.hasPreviousPage,startCursor:o.pageInfo.startCursor,hasNextPage:r.pageInfo.hasNextPage,endCursor:r.pageInfo.endCursor}}).with("after",function(){return{hasPreviousPage:r.pageInfo.hasPreviousPage,startCursor:r.pageInfo.startCursor,hasNextPage:o.pageInfo.hasNextPage,endCursor:o.pageInfo.endCursor}}).exhaustive()})),c.current}},Q=B("after"),J=B("before");exports.Client=V,exports.ClientContext=W,exports.ClientError=K,exports.print=L,exports.useBackwardPagination=J,exports.useDeferredQuery=function(t,n){var r=(void 0===n?{}:n).optimize,o=void 0!==r&&r,u=i.useContext(W),a=i.useState(t)[0],c=i.useState(e.Option.None()),s=c[0],f=c[1],l=i.useCallback(function(){return s.flatMap(function(e){return u.readFromCache(a,e)})},[u,a,s]),p=i.useSyncExternalStore(function(e){return u.subscribe(e)},l),m=i.useMemo(function(){return p.map(function(t){return e.AsyncData.Done(t)}).getWithDefault(e.AsyncData.NotAsked())},[p]),d=i.useState(!1),v=d[0],y=d[1],g=i.useCallback(function(t){return f(function(n){return n.match({None:function(){return e.Option.Some(t)},Some:function(r){return h(r,t)?n:e.Option.Some(t)}})}),y(!0),u.request(a,t,{optimize:o}).tap(function(){return y(!1)})},[u,a,o]);return[v?e.AsyncData.Loading():m,g]},exports.useForwardPagination=Q,exports.useMutation=function(t){var n=i.useContext(W),r=i.useState(t)[0],o=i.useState(e.AsyncData.NotAsked()),u=o[0],a=o[1];return[i.useCallback(function(t){return a(e.AsyncData.Loading()),n.commitMutation(r,t).tap(function(t){return a(e.AsyncData.Done(t))})},[n,r]),u]},exports.useQuery=function(t,n,r){var o=void 0===r?{}:r,u=o.suspense,a=void 0!==u&&u,c=o.optimize,s=void 0!==c&&c,f=i.useContext(W),l=i.useState(t)[0],p=i.useState(n),m=p[0],d=p[1];i.useEffect(function(){h(m,n)||d(n)},[m,n]);var v,y,g=i.useCallback(function(){return f.readFromCache(l,m)},[f,l,m]),O=i.useSyncExternalStore(function(e){return f.subscribe(e)},g),S=i.useMemo(function(){return O.map(function(t){return e.AsyncData.Done(t)}).getWithDefault(e.AsyncData.Loading())},[O]),N=(y=i.useRef(v=S),i.useEffect(function(){y.current=v},[v]),y.current),b=i.useRef(!0);i.useEffect(function(){if(!a||!b.current){var e=f.query(l,m,{optimize:s});return function(){return e.cancel()}}b.current=!1},[f,a,s,l,m]);var E=i.useState(!1),w=E[0],A=E[1],I=i.useCallback(function(){return A(!0),f.request(l,m).tap(function(){return A(!1)})},[f,l,m]),D=i.useState(!1),P=D[0],C=D[1],F=i.useCallback(function(){return C(!0),f.request(l,m).tap(function(){return C(!1)})},[f,l,m]),M=w||P||S.isLoading(),T=P?e.AsyncData.Loading():M?N:S;if(a&&T.isLoading())throw f.query(l,m,{optimize:s}).toPromise();return[T,{isLoading:M,refresh:I,reload:F}]}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@swan-io/graphql-client", | ||
"version": "0.1.0-alpha2", | ||
"version": "0.1.0-alpha3", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "A simple, typesafe GraphQL client for React", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
234006
412