Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@swan-io/graphql-client

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@swan-io/graphql-client - npm Package Compare versions

Comparing version 0.1.0-alpha5 to 0.1.0-alpha6

2

dist/index.js

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

@@ -23,2 +23,6 @@ "description": "A simple, typesafe GraphQL client for React",

],
"browserslist": [
"defaults and fully supports es6-module",
"maintained node versions"
],
"publishConfig": {

@@ -25,0 +29,0 @@ "access": "public",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc