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

@based/client

Package Overview
Dependencies
Maintainers
1
Versions
139
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@based/client - npm Package Compare versions

Comparing version 2.9.0 to 2.10.0

5

dist/auth.d.ts
import { BasedClient } from '.';
import { AuthData, GenericObject, LoginOpts, RenewTokenOpts } from '@based/types';
import { AuthData, GenericObject, LoginOpts, RegisterOpts, RenewTokenOpts } from '@based/types';
export declare const login: (client: BasedClient, opts: LoginOpts) => Promise<{
token: string;
}>;
export declare const register: (client: BasedClient, opts: RegisterOpts) => Promise<{
token: string;
}>;
export declare const renewToken: (client: BasedClient, opts: RenewTokenOpts) => Promise<{

@@ -7,0 +10,0 @@ token: string;

12

dist/auth.js

@@ -6,3 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.logout = exports.incomingAuthRequest = exports.renewToken = exports.login = void 0;
exports.logout = exports.incomingAuthRequest = exports.renewToken = exports.register = exports.login = void 0;
const queue_1 = require("./queue");

@@ -12,2 +12,3 @@ const types_1 = require("@based/types");

const token_1 = __importDefault(require("./token"));
const request_1 = require("./request");
let loginCbId = 0;

@@ -30,2 +31,11 @@ const login = (client, opts) => {

exports.login = login;
const register = (client, opts) => new Promise((resolve, reject) => {
(0, request_1.addRequest)(client, types_1.RequestTypes.Call, opts, (response) => {
(0, token_1.default)(client, response.token, {
refreshToken: response.refreshToken,
});
resolve(response);
}, reject, 'registerUser');
});
exports.register = register;
const renewToken = (client, opts) => {

@@ -32,0 +42,0 @@ const reqId = ++loginCbId;

import Emitter from './Emitter';
import { GenericObject, Configuration, Query, DigestOptions, SetOptions, Copy, SendTokenOptions, TrackOpts, AnalyticsTypes, AnalyticsResult, AnalyticsOpts, AnalyticsTypesOpts, AnalyticsHistoryOpts, FileUploadOptions, FileUploadSrc, FileUploadPath, FileUploadStream, AnalyticsHistoryResult, LoginOpts } from '@based/types';
import { GenericObject, Configuration, Query, DigestOptions, SetOptions, Copy, SendTokenOptions, TrackOpts, AnalyticsTypes, AnalyticsResult, AnalyticsOpts, AnalyticsTypesOpts, AnalyticsHistoryOpts, FileUploadOptions, FileUploadSrc, FileUploadPath, FileUploadStream, AnalyticsHistoryResult, RegisterOpts, LoginOpts } from '@based/types';
import { addSubscriber, generateSubscriptionId, addGetSubscriber, removeSubscriber } from './subscriptions';

@@ -105,2 +105,3 @@ import { addRequest } from './request';

login(opts: LoginOpts): Promise<GenericObject>;
register(opts: RegisterOpts): Promise<GenericObject>;
logout(): Promise<GenericObject>;

@@ -107,0 +108,0 @@ }

@@ -1,2 +0,2 @@

var rt=Object.create;var U=Object.defineProperty,it=Object.defineProperties,nt=Object.getOwnPropertyDescriptor,ot=Object.getOwnPropertyDescriptors,at=Object.getOwnPropertyNames,H=Object.getOwnPropertySymbols,ct=Object.getPrototypeOf,ne=Object.prototype.hasOwnProperty,we=Object.prototype.propertyIsEnumerable;var Oe=(e,s,t)=>s in e?U(e,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[s]=t,oe=(e,s)=>{for(var t in s||(s={}))ne.call(s,t)&&Oe(e,t,s[t]);if(H)for(var t of H(s))we.call(s,t)&&Oe(e,t,s[t]);return e},Ce=(e,s)=>it(e,ot(s));var Pe=(e,s)=>{var t={};for(var n in e)ne.call(e,n)&&s.indexOf(n)<0&&(t[n]=e[n]);if(e!=null&&H)for(var n of H(e))s.indexOf(n)<0&&we.call(e,n)&&(t[n]=e[n]);return t};var qe=(e,s)=>{for(var t in s)U(e,t,{get:s[t],enumerable:!0})},_=(e,s,t,n)=>{if(s&&typeof s=="object"||typeof s=="function")for(let r of at(s))!ne.call(e,r)&&r!==t&&U(e,r,{get:()=>s[r],enumerable:!(n=nt(s,r))||n.enumerable});return e},d=(e,s,t)=>(_(e,s,"default"),t&&_(t,s,"default")),z=(e,s,t)=>(t=e!=null?rt(ct(e)):{},_(s||!e||!e.__esModule?U(t,"default",{value:e,enumerable:!0}):t,e)),ut=e=>_(U({},"__esModule",{value:!0}),e);var m={};qe(m,{Based:()=>re,BasedClient:()=>D,BasedGraphQL:()=>S.BasedGraphQL,Observable:()=>P,addGetSubscriber:()=>K,addRequest:()=>k,addSubscriber:()=>E,createGraphqlOperations:()=>S.createOperations,default:()=>Tt,generateSubscriptionId:()=>q,generateTrackingKey:()=>he,handleGraphqlVariables:()=>S.handleGraphqlVariables,parseGraphql:()=>S.parseGraphql,removeSubscriber:()=>y});module.exports=ut(m);var ae=class{constructor(){this.listeners={};Object.defineProperty(this,"listeners",{enumerable:!1,writable:!0})}emit(s,t){this.listeners[s]&&this.listeners[s].forEach(n=>n(t))}on(s,t){this.listeners[s]||(this.listeners[s]=[]),this.listeners[s].push(t)}removeAllListeners(){this.listeners={}}once(s,t){this.on(s,n=>{t(n),this.removeListener(s,t)})}removeListener(s,t){let n=this.listeners[s];if(n){if(!t)delete this.listeners[s];else for(let r=0,i=n.length;r<i;r++)if(n[r]===t){n.splice(r,1);break}}}},Be=ae;var Re=(e,s)=>{typeof e=="function"?e().then(t=>{s(t)}):s(e)};var Fe=z(require("isomorphic-ws")),G=new Map,Ee;typeof window!="undefined"&&document.addEventListener("visibilitychange",function(){clearTimeout(Ee),document.hidden?Ee=setTimeout(()=>{G.forEach(e=>{e(!1)})},3e4):G.forEach(e=>{e(!0)})});var ce=(e,s,t={destroy:()=>{G.delete(t)}},n=0,r=!1)=>(Re(s,i=>{setTimeout(()=>{if(t.disconnected)return;let o=!0;G.set(t,a=>{t.disconnected||(!a&&o?(console.warn("Send to background - close connection"),o=!1,e.onClose(),c.close()):!o&&a&&(G.delete(t),ce(e,s,t,0,!0)))});let c=t.ws=new Fe.default(i);c.onerror=()=>{},c.onmessage=a=>e.onData(a),c.onopen=()=>{if(o){if(t.disconnected)return;n=100,r&&e.onReconnect(),e.onOpen()}},c.onclose=()=>{if(o){if(t.disconnected)return;e.onClose(),ce(e,s,t,Math.min(1250,Math.min(n+500)),!0)}}},n)}),t),ue=ce;var v=require("@based/types");var I=require("@based/types");var j=require("@based/types");var lt=e=>{clearTimeout(e.idlePing),e.idlePing=setTimeout(()=>{e.connection&&e.connected&&!e.connection.disconnected&&e.connection.ws.send("1")},6e4)},J=lt;var f=(e,s)=>{s[0]===j.RequestTypes.Unsubscribe||s[0]===j.RequestTypes.Subscription||s[0]===j.RequestTypes.SendSubscriptionData||s[0]===j.RequestTypes.GetSubscription?e.subscriptionQueue.push(s):e.queue.push(s),e.connected&&!e.drainInProgress&&le(e)},le=e=>{e.connected&&!e.drainInProgress&&(e.queue.length||e.subscriptionQueue.length)&&!e.isLogginIn&&(e.drainInProgress=!0,e.drainTimeout=setTimeout(()=>{if(e.drainInProgress=!1,e.queue.length||e.subscriptionQueue.length){let s=[...e.queue,...e.subscriptionQueue];e.queue=[],e.subscriptionQueue=[],e.debugInternal&&e.debugInternal(s,"outgoing"),e.connection.ws.send(JSON.stringify(s)),J(e)}},0))},Ie=e=>{e.drainInProgress&&(clearTimeout(e.drainTimeout),e.drainInProgress=!1)};var pe=require("@saulx/hash"),q=(e,s)=>s?(0,pe.hashObjectIgnoreKeyOrder)([s,e]):(0,pe.hashObjectIgnoreKeyOrder)(e);var K=(e,s,t,n,r)=>{n||(n=q(s,r));let i=e.subscriptions[n],o=e.cache[n];if(i)if(i.authError)if(!e.beingAuth)t(i.authError.error,n,0);else{let c=++i.cnt;i.subscribers[c]={onInitial:t}}else if(o)t(null,n,0,o.value);else{let c=++i.cnt;i.subscribers[c]={onInitial:t}}else{i=e.subscriptions[n]={query:s,cnt:1,name:r,subscribers:{1:{onInitial:t}}};let c;for(let a=0;a<e.subscriptionQueue.length;a++){let[u,l,,p]=e.subscriptionQueue[a];(u===I.RequestTypes.Unsubscribe||u===I.RequestTypes.SendSubscriptionData)&&l===n?(e.subscriptionQueue.splice(a,1),a--):(u===I.RequestTypes.Subscription||u===I.RequestTypes.GetSubscription)&&l===n&&(c=!0,u===I.RequestTypes.Subscription&&(p!==o.checksum&&(e.subscriptionQueue[a][3]=o.checksum),e.subscriptionQueue[a][4]=2))}if(!c){let a=[I.RequestTypes.GetSubscription,n,s];o&&a.push(o.checksum),r&&(o||a.push(0),a.push(r)),f(e,a)}}};var B=require("@based/types");var E=(e,s,t,n,r,i,o)=>{i||(i=q(s,o));let c=e.subscriptions[i],a=e.cache[i],u;if(c){u=++c.cnt;let l=!0;for(let p in c.subscribers)if(c.subscribers[p].onData){l=!1;break}if(c.subscribers[u]={onError:r,onData:t,onInitial:n},l){for(let b=0;b<e.subscriptionQueue.length;b++){let[h,T]=e.subscriptionQueue[b];h===B.RequestTypes.GetSubscription&&T===i&&(e.subscriptionQueue.splice(b,1),b--)}let p=[B.RequestTypes.Subscription,i,s];a&&(p.push(a.checksum),p.push(2)),o&&(a||p.push(0,2),p.push(o)),f(e,p)}}else{u=1,c=e.subscriptions[i]={query:s,cnt:1,name:o,subscribers:{1:{onError:r,onData:t,onInitial:n}}};let l=!1,p=!1,b;for(let h=0;h<e.subscriptionQueue.length;h++){let[T,R,,x]=e.subscriptionQueue[h];(T===B.RequestTypes.Unsubscribe||T===B.RequestTypes.SendSubscriptionData||T===B.RequestTypes.GetSubscription)&&R===i?(T===B.RequestTypes.GetSubscription&&(p=!0),b&&(b[4]=2),e.subscriptionQueue.splice(h,1),h--):T===B.RequestTypes.Subscription&&R===i&&(l=!0,b=e.subscriptionQueue[h],x!==a.checksum&&(b[3]=a.checksum),!b[4]&&p&&(b[4]=2))}if(!l){let h=[B.RequestTypes.Subscription,i,s];a&&(h.push(a.checksum),p&&h.push(2)),o&&(a?!p&&a&&h.push(2):h.push(0,0),h.push(o)),f(e,h)}}return a&&(n&&(n(null,i,u),delete c.subscribers[u].onInitial),t&&t(a.value,a.checksum)),[i,u]};var $=require("@based/types");var y=(e,s,t)=>{let n=e.subscriptions[s];if(n){let r=!1;if(t?n.subscribers[t]&&(delete n.subscribers[t],n.cnt--,n.cnt===0&&(r=!0)):r=!0,r){delete e.subscriptions[s];let i=!1;for(let o=0;o<e.subscriptionQueue.length;o++){let[c,a]=e.subscriptionQueue[o];c===$.RequestTypes.Unsubscribe&&a===s?i=!0:(c===$.RequestTypes.Subscription||c===$.RequestTypes.SendSubscriptionData)&&a===s&&(e.subscriptionQueue.splice(o,1),o--)}i||f(e,[$.RequestTypes.Unsubscribe,s])}}};var Qe=require("@based/types"),xe=e=>{for(let s=0;s<e.subscriptionQueue.length;s++)e.subscriptionQueue[s][0]===Qe.RequestTypes.Unsubscribe&&(e.subscriptionQueue.splice(s,1),s--)};var De=require("@based/types"),Ae=e=>{for(let s=0;s<e.subscriptionQueue.length;s++)e.subscriptionQueue[s][0]===De.RequestTypes.SendSubscriptionData&&(e.subscriptionQueue.splice(s,1),s--)};var Q=require("@based/types");var M=(e,s=!1)=>{for(let t in e.subscriptions){let n=Number(t),r=e.subscriptions[t];if(s&&!r.authError)continue;let i,o,c;for(let l=0;l<e.subscriptionQueue.length;l++){let[p,b]=e.subscriptionQueue[l];b===n&&(p===Q.RequestTypes.GetSubscription?(c=l,i=e.subscriptionQueue[l]):p===Q.RequestTypes.Subscription&&(o=e.subscriptionQueue[l]))}i&&o&&console.error("GET IN Q AND SUB IN Q SHOULD BE IMPOSSIBLE");let a=e.cache[n],u=!1;if(i){let l=!0;for(let p in r.subscribers)if(r.subscribers[p].onData){l=!1;break}l?u=!0:(console.info("not only gets remove get"),e.subscriptionQueue.splice(c,1)),a&&i[3]!==a.checksum&&(i[3]=a.checksum)}if(!u)if(o)a&&o[3]!==a.checksum&&(o[3]=a.checksum,i&&(o[4]=2));else{let{name:l,query:p}=e.subscriptions[n];l?a?f(e,[Q.RequestTypes.Subscription,n,p,a.checksum,i?2:0,l]):f(e,[Q.RequestTypes.Subscription,n,p,0,i?2:0,l]):a?f(e,[Q.RequestTypes.Subscription,n,p,a.checksum,i?2:0]):f(e,[Q.RequestTypes.Subscription,n,p,0,i?2:0])}}};var Ue=require("@based/types");var W=(e,s)=>{if(typeof window!="undefined")return e;let t={white:"\x1B[37;1m",reset:"\x1B[0m",blue:"\x1B[34m",red:"\x1B[31m",green:"\x1B[32m",brightBlue:"\x1B[34;1m",brightRed:"\x1B[31;1m"};return`${t[s]}${e}${t.reset}`},de=(e,s=0,t=!1,n="",r=!1)=>{let i="";for(let a=0;a<s;a++)i+=" ";let o=t?[]:n?[i+`${W(n,r?"brightRed":"white")} {`]:[i+"{"],c=!1;t||(i+=" ",s+=1);for(let a in e){let u=e[a],l=a[0]==="$"?W(a,"white"):a;if(c&&(o[o.length-1]+=","),Array.isArray(u)){o.push(`${i} ${l}: [`);for(let p=0;p<u.length;p++){let b=u[p];o.push(...b&&typeof b=="object"?de(b,s+4):[`${i} ${b}`]),p!==u.length-1&&(o[o.length-1]+=",")}o.push(`${i} ]`)}else u&&typeof u=="object"?(o.push(`${i} ${l}: {`),o.push(...de(u,s+2,!0)),o.push(`${i} }`)):o.push(`${i} ${l}: ${u}`);c=!0}return t||o.push(i.slice(0,-1)+"}"),o},V=de;var w=e=>{let s=new Ue.BasedError(e.message);if(s.name=e.name?`${e.type} from ${e.name}`:e.type,s.stack=null,e.query||e.payload){let t=s.message.split(`
var it=Object.create;var U=Object.defineProperty,nt=Object.defineProperties,ot=Object.getOwnPropertyDescriptor,at=Object.getOwnPropertyDescriptors,ct=Object.getOwnPropertyNames,H=Object.getOwnPropertySymbols,ut=Object.getPrototypeOf,ne=Object.prototype.hasOwnProperty,we=Object.prototype.propertyIsEnumerable;var Oe=(e,s,t)=>s in e?U(e,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[s]=t,oe=(e,s)=>{for(var t in s||(s={}))ne.call(s,t)&&Oe(e,t,s[t]);if(H)for(var t of H(s))we.call(s,t)&&Oe(e,t,s[t]);return e},Ce=(e,s)=>nt(e,at(s));var Pe=(e,s)=>{var t={};for(var n in e)ne.call(e,n)&&s.indexOf(n)<0&&(t[n]=e[n]);if(e!=null&&H)for(var n of H(e))s.indexOf(n)<0&&we.call(e,n)&&(t[n]=e[n]);return t};var qe=(e,s)=>{for(var t in s)U(e,t,{get:s[t],enumerable:!0})},_=(e,s,t,n)=>{if(s&&typeof s=="object"||typeof s=="function")for(let r of ct(s))!ne.call(e,r)&&r!==t&&U(e,r,{get:()=>s[r],enumerable:!(n=ot(s,r))||n.enumerable});return e},d=(e,s,t)=>(_(e,s,"default"),t&&_(t,s,"default")),z=(e,s,t)=>(t=e!=null?it(ut(e)):{},_(s||!e||!e.__esModule?U(t,"default",{value:e,enumerable:!0}):t,e)),lt=e=>_(U({},"__esModule",{value:!0}),e);var m={};qe(m,{Based:()=>re,BasedClient:()=>D,BasedGraphQL:()=>S.BasedGraphQL,Observable:()=>P,addGetSubscriber:()=>K,addRequest:()=>y,addSubscriber:()=>F,createGraphqlOperations:()=>S.createOperations,default:()=>Ot,generateSubscriptionId:()=>q,generateTrackingKey:()=>he,handleGraphqlVariables:()=>S.handleGraphqlVariables,parseGraphql:()=>S.parseGraphql,removeSubscriber:()=>v});module.exports=lt(m);var ae=class{constructor(){this.listeners={};Object.defineProperty(this,"listeners",{enumerable:!1,writable:!0})}emit(s,t){this.listeners[s]&&this.listeners[s].forEach(n=>n(t))}on(s,t){this.listeners[s]||(this.listeners[s]=[]),this.listeners[s].push(t)}removeAllListeners(){this.listeners={}}once(s,t){this.on(s,n=>{t(n),this.removeListener(s,t)})}removeListener(s,t){let n=this.listeners[s];if(n){if(!t)delete this.listeners[s];else for(let r=0,i=n.length;r<i;r++)if(n[r]===t){n.splice(r,1);break}}}},Re=ae;var Be=(e,s)=>{typeof e=="function"?e().then(t=>{s(t)}):s(e)};var Fe=z(require("isomorphic-ws")),G=new Map,Ee;typeof window!="undefined"&&document.addEventListener("visibilitychange",function(){clearTimeout(Ee),document.hidden?Ee=setTimeout(()=>{G.forEach(e=>{e(!1)})},3e4):G.forEach(e=>{e(!0)})});var ce=(e,s,t={destroy:()=>{G.delete(t)}},n=0,r=!1)=>(Be(s,i=>{setTimeout(()=>{if(t.disconnected)return;let o=!0;G.set(t,a=>{t.disconnected||(!a&&o?(console.warn("Send to background - close connection"),o=!1,e.onClose(),c.close()):!o&&a&&(G.delete(t),ce(e,s,t,0,!0)))});let c=t.ws=new Fe.default(i);c.onerror=()=>{},c.onmessage=a=>e.onData(a),c.onopen=()=>{if(o){if(t.disconnected)return;n=100,r&&e.onReconnect(),e.onOpen()}},c.onclose=()=>{if(o){if(t.disconnected)return;e.onClose(),ce(e,s,t,Math.min(1250,Math.min(n+500)),!0)}}},n)}),t),ue=ce;var k=require("@based/types");var I=require("@based/types");var j=require("@based/types");var pt=e=>{clearTimeout(e.idlePing),e.idlePing=setTimeout(()=>{e.connection&&e.connected&&!e.connection.disconnected&&e.connection.ws.send("1")},6e4)},J=pt;var f=(e,s)=>{s[0]===j.RequestTypes.Unsubscribe||s[0]===j.RequestTypes.Subscription||s[0]===j.RequestTypes.SendSubscriptionData||s[0]===j.RequestTypes.GetSubscription?e.subscriptionQueue.push(s):e.queue.push(s),e.connected&&!e.drainInProgress&&le(e)},le=e=>{e.connected&&!e.drainInProgress&&(e.queue.length||e.subscriptionQueue.length)&&!e.isLogginIn&&(e.drainInProgress=!0,e.drainTimeout=setTimeout(()=>{if(e.drainInProgress=!1,e.queue.length||e.subscriptionQueue.length){let s=[...e.queue,...e.subscriptionQueue];e.queue=[],e.subscriptionQueue=[],e.debugInternal&&e.debugInternal(s,"outgoing"),e.connection.ws.send(JSON.stringify(s)),J(e)}},0))},Ie=e=>{e.drainInProgress&&(clearTimeout(e.drainTimeout),e.drainInProgress=!1)};var pe=require("@saulx/hash"),q=(e,s)=>s?(0,pe.hashObjectIgnoreKeyOrder)([s,e]):(0,pe.hashObjectIgnoreKeyOrder)(e);var K=(e,s,t,n,r)=>{n||(n=q(s,r));let i=e.subscriptions[n],o=e.cache[n];if(i)if(i.authError)if(!e.beingAuth)t(i.authError.error,n,0);else{let c=++i.cnt;i.subscribers[c]={onInitial:t}}else if(o)t(null,n,0,o.value);else{let c=++i.cnt;i.subscribers[c]={onInitial:t}}else{i=e.subscriptions[n]={query:s,cnt:1,name:r,subscribers:{1:{onInitial:t}}};let c;for(let a=0;a<e.subscriptionQueue.length;a++){let[u,l,,p]=e.subscriptionQueue[a];(u===I.RequestTypes.Unsubscribe||u===I.RequestTypes.SendSubscriptionData)&&l===n?(e.subscriptionQueue.splice(a,1),a--):(u===I.RequestTypes.Subscription||u===I.RequestTypes.GetSubscription)&&l===n&&(c=!0,u===I.RequestTypes.Subscription&&(p!==o.checksum&&(e.subscriptionQueue[a][3]=o.checksum),e.subscriptionQueue[a][4]=2))}if(!c){let a=[I.RequestTypes.GetSubscription,n,s];o&&a.push(o.checksum),r&&(o||a.push(0),a.push(r)),f(e,a)}}};var R=require("@based/types");var F=(e,s,t,n,r,i,o)=>{i||(i=q(s,o));let c=e.subscriptions[i],a=e.cache[i],u;if(c){u=++c.cnt;let l=!0;for(let p in c.subscribers)if(c.subscribers[p].onData){l=!1;break}if(c.subscribers[u]={onError:r,onData:t,onInitial:n},l){for(let b=0;b<e.subscriptionQueue.length;b++){let[h,T]=e.subscriptionQueue[b];h===R.RequestTypes.GetSubscription&&T===i&&(e.subscriptionQueue.splice(b,1),b--)}let p=[R.RequestTypes.Subscription,i,s];a&&(p.push(a.checksum),p.push(2)),o&&(a||p.push(0,2),p.push(o)),f(e,p)}}else{u=1,c=e.subscriptions[i]={query:s,cnt:1,name:o,subscribers:{1:{onError:r,onData:t,onInitial:n}}};let l=!1,p=!1,b;for(let h=0;h<e.subscriptionQueue.length;h++){let[T,E,,x]=e.subscriptionQueue[h];(T===R.RequestTypes.Unsubscribe||T===R.RequestTypes.SendSubscriptionData||T===R.RequestTypes.GetSubscription)&&E===i?(T===R.RequestTypes.GetSubscription&&(p=!0),b&&(b[4]=2),e.subscriptionQueue.splice(h,1),h--):T===R.RequestTypes.Subscription&&E===i&&(l=!0,b=e.subscriptionQueue[h],x!==a.checksum&&(b[3]=a.checksum),!b[4]&&p&&(b[4]=2))}if(!l){let h=[R.RequestTypes.Subscription,i,s];a&&(h.push(a.checksum),p&&h.push(2)),o&&(a?!p&&a&&h.push(2):h.push(0,0),h.push(o)),f(e,h)}}return a&&(n&&(n(null,i,u),delete c.subscribers[u].onInitial),t&&t(a.value,a.checksum)),[i,u]};var $=require("@based/types");var v=(e,s,t)=>{let n=e.subscriptions[s];if(n){let r=!1;if(t?n.subscribers[t]&&(delete n.subscribers[t],n.cnt--,n.cnt===0&&(r=!0)):r=!0,r){delete e.subscriptions[s];let i=!1;for(let o=0;o<e.subscriptionQueue.length;o++){let[c,a]=e.subscriptionQueue[o];c===$.RequestTypes.Unsubscribe&&a===s?i=!0:(c===$.RequestTypes.Subscription||c===$.RequestTypes.SendSubscriptionData)&&a===s&&(e.subscriptionQueue.splice(o,1),o--)}i||f(e,[$.RequestTypes.Unsubscribe,s])}}};var Qe=require("@based/types"),xe=e=>{for(let s=0;s<e.subscriptionQueue.length;s++)e.subscriptionQueue[s][0]===Qe.RequestTypes.Unsubscribe&&(e.subscriptionQueue.splice(s,1),s--)};var De=require("@based/types"),Ae=e=>{for(let s=0;s<e.subscriptionQueue.length;s++)e.subscriptionQueue[s][0]===De.RequestTypes.SendSubscriptionData&&(e.subscriptionQueue.splice(s,1),s--)};var Q=require("@based/types");var M=(e,s=!1)=>{for(let t in e.subscriptions){let n=Number(t),r=e.subscriptions[t];if(s&&!r.authError)continue;let i,o,c;for(let l=0;l<e.subscriptionQueue.length;l++){let[p,b]=e.subscriptionQueue[l];b===n&&(p===Q.RequestTypes.GetSubscription?(c=l,i=e.subscriptionQueue[l]):p===Q.RequestTypes.Subscription&&(o=e.subscriptionQueue[l]))}i&&o&&console.error("GET IN Q AND SUB IN Q SHOULD BE IMPOSSIBLE");let a=e.cache[n],u=!1;if(i){let l=!0;for(let p in r.subscribers)if(r.subscribers[p].onData){l=!1;break}l?u=!0:(console.info("not only gets remove get"),e.subscriptionQueue.splice(c,1)),a&&i[3]!==a.checksum&&(i[3]=a.checksum)}if(!u)if(o)a&&o[3]!==a.checksum&&(o[3]=a.checksum,i&&(o[4]=2));else{let{name:l,query:p}=e.subscriptions[n];l?a?f(e,[Q.RequestTypes.Subscription,n,p,a.checksum,i?2:0,l]):f(e,[Q.RequestTypes.Subscription,n,p,0,i?2:0,l]):a?f(e,[Q.RequestTypes.Subscription,n,p,a.checksum,i?2:0]):f(e,[Q.RequestTypes.Subscription,n,p,0,i?2:0])}}};var Ue=require("@based/types");var W=(e,s)=>{if(typeof window!="undefined")return e;let t={white:"\x1B[37;1m",reset:"\x1B[0m",blue:"\x1B[34m",red:"\x1B[31m",green:"\x1B[32m",brightBlue:"\x1B[34;1m",brightRed:"\x1B[31;1m"};return`${t[s]}${e}${t.reset}`},de=(e,s=0,t=!1,n="",r=!1)=>{let i="";for(let a=0;a<s;a++)i+=" ";let o=t?[]:n?[i+`${W(n,r?"brightRed":"white")} {`]:[i+"{"],c=!1;t||(i+=" ",s+=1);for(let a in e){let u=e[a],l=a[0]==="$"?W(a,"white"):a;if(c&&(o[o.length-1]+=","),Array.isArray(u)){o.push(`${i} ${l}: [`);for(let p=0;p<u.length;p++){let b=u[p];o.push(...b&&typeof b=="object"?de(b,s+4):[`${i} ${b}`]),p!==u.length-1&&(o[o.length-1]+=",")}o.push(`${i} ]`)}else u&&typeof u=="object"?(o.push(`${i} ${l}: {`),o.push(...de(u,s+2,!0)),o.push(`${i} }`)):o.push(`${i} ${l}: ${u}`);c=!0}return t||o.push(i.slice(0,-1)+"}"),o},V=de;var C=e=>{let s=new Ue.BasedError(e.message);if(s.name=e.name?`${e.type} from ${e.name}`:e.type,s.stack=null,e.query||e.payload){let t=s.message.split(`
`),n=0;t[0]===""&&t.shift();let r=t[0];for(let i=0;i<r.length;i++)if(r[i]!==" "){n=i-2;break}n>0?t=t.map(i=>i.slice(n)):t=t.map(i=>" "+i),e.code&&(s.code=e.code),s.message=`

@@ -10,3 +10,3 @@

`}return s};var Ge=(e,s)=>{let[,t,n,r,i]=s,o=e.subscriptions[t];if(o){let c=e.cache[t]&&e.cache[t].checksum;if(i){let a=w(i);i.auth&&(o.authError={token:e.token,error:a});for(let u in o.subscribers){let l=o.subscribers[u];l.onInitial?i.auth?(l.onError&&l.onError(a),l.onInitial(a,Number(t),Number(u),void 0,!0),delete l.onInitial):(l.onInitial(a,Number(t),Number(u)),delete l.onInitial,y(e,t,Number(u))):l.onError&&l.onError(a)}}else if(c===r){o.authError&&delete o.authError;for(let a in o.subscribers){let u=o.subscribers[a];u.onInitial&&(u.onInitial(null,Number(t),Number(a),e.cache[t].value),delete u.onInitial,u.onData||y(e,t,Number(a)))}}else{o.authError&&delete o.authError,e.cache[t]={value:n,checksum:r};for(let a in o.subscribers){let u=o.subscribers[a];u.onInitial&&(u.onInitial(null,Number(t),Number(a),n),delete u.onInitial,u.onData||y(e,t,Number(a))),u.onData&&u.onData(n,r)}}}};var je=require("@saulx/diff"),X=require("@based/types");var $e=(e,s)=>{let[,t,n,[r,i]]=s,o=e.subscriptions[t];if(o){let c=e.cache[t];if(!c||c.checksum!==r)if(c)if(c.checksum===i)for(let a in o.subscribers){let u=o.subscribers[a];u.onInitial&&(u.onInitial(null,Number(t),Number(a),c.value),delete u.onInitial,u.onData||y(e,t,Number(a)))}else f(e,[X.RequestTypes.SendSubscriptionData,t]);else f(e,[X.RequestTypes.SendSubscriptionData,t]);else{let a=!1;try{c.value=(0,je.applyPatch)(c.value,n),c.value===null&&(a=!0)}catch(u){a=!0}if(a)console.warn(`
`}return s};var Ge=(e,s)=>{let[,t,n,r,i]=s,o=e.subscriptions[t];if(o){let c=e.cache[t]&&e.cache[t].checksum;if(i){let a=C(i);i.auth&&(o.authError={token:e.token,error:a});for(let u in o.subscribers){let l=o.subscribers[u];l.onInitial?i.auth?(l.onError&&l.onError(a),l.onInitial(a,Number(t),Number(u),void 0,!0),delete l.onInitial):(l.onInitial(a,Number(t),Number(u)),delete l.onInitial,v(e,t,Number(u))):l.onError&&l.onError(a)}}else if(c===r){o.authError&&delete o.authError;for(let a in o.subscribers){let u=o.subscribers[a];u.onInitial&&(u.onInitial(null,Number(t),Number(a),e.cache[t].value),delete u.onInitial,u.onData||v(e,t,Number(a)))}}else{o.authError&&delete o.authError,e.cache[t]={value:n,checksum:r};for(let a in o.subscribers){let u=o.subscribers[a];u.onInitial&&(u.onInitial(null,Number(t),Number(a),n),delete u.onInitial,u.onData||v(e,t,Number(a))),u.onData&&u.onData(n,r)}}}};var je=require("@saulx/diff"),X=require("@based/types");var $e=(e,s)=>{let[,t,n,[r,i]]=s,o=e.subscriptions[t];if(o){let c=e.cache[t];if(!c||c.checksum!==r)if(c)if(c.checksum===i)for(let a in o.subscribers){let u=o.subscribers[a];u.onInitial&&(u.onInitial(null,Number(t),Number(a),c.value),delete u.onInitial,u.onData||v(e,t,Number(a)))}else f(e,[X.RequestTypes.SendSubscriptionData,t]);else f(e,[X.RequestTypes.SendSubscriptionData,t]);else{let a=!1;try{c.value=(0,je.applyPatch)(c.value,n),c.value===null&&(a=!0)}catch(u){a=!0}if(a)console.warn(`
Found corrupt data while applying diff to subscription need to re-fetch

@@ -16,2 +16,2 @@ `),console.warn(V(o.query,2,!1,"Query").join(`

`),delete e.cache[t],f(e,[X.RequestTypes.SendSubscriptionData,t]);else{c.checksum=i;for(let u in o.subscribers){let l=o.subscribers[u];l.onInitial&&(l.onInitial(null,Number(t),Number(u),c.value),delete l.onInitial,l.onData||y(e,t,Number(u))),l.onData&&l.onData(c.value,c.checksum)}}}}};var Me=(e,s)=>{for(let t of s[1]){delete e.cache[t];let n=e.subscriptions[t];if(n){let r={type:"AuthorizationError",name:n.name?`observe "${n.name}"`:"observe",message:"Unauthorized request",payload:n.query,auth:!0},i=w(r);n.authError={token:e.token,error:i};for(let o in n.subscribers){let c=n.subscribers[o];c.onError&&c.onError(i)}}}};var Ne=require("@based/types");var pt=0,k=(e,s,t,n,r,i,o)=>{let c=++pt;e.requestCallbacks[c]={resolve:n,reject:r,type:s,payload:t,name:i,isRetry:o},s===Ne.RequestTypes.Call?f(e,[s,i,c,t]):f(e,[s,c,t])};var Le=(e,s)=>{let[,t,n,r]=s,i=e.requestCallbacks[t];i&&(delete e.requestCallbacks[t],r?i.reject(w(r)):i.resolve(n))};var O={};qe(O,{BasedClient:()=>D});var g=require("@based/types");var be=require("@based/types");var dt=e=>typeof e!="undefined"&&e!==null,bt=(e,s,t)=>{if(e.beingAuth=!0,s)e.token=s,e.sendTokenOptions=t;else{for(let n in e.cache)e.subscriptions[n]||delete e.cache[n];delete e.token,delete e.sendTokenOptions}if(e.connected){let n=s?[be.RequestTypes.Token,s,t].filter(dt):[be.RequestTypes.Token];e.connection.ws.send(JSON.stringify(n)),J(e),M(e,!0)}},C=bt;var F=require("@based/types");var fe=0,He=(e,s)=>{let t=++fe;return f(e,[F.RequestTypes.Auth,F.AuthRequestTypes.Login,t,s]),new Promise((n,r)=>{e.authCallbacks[t]={resolve:i=>{C(e,i.token,{refreshToken:i.refreshToken}),n(i)},reject:r}})},_e=(e,s)=>{let t=++fe;return f(e,[F.RequestTypes.Auth,F.AuthRequestTypes.RenewToken,t,s]),new Promise((n,r)=>{e.authCallbacks[t]={resolve:i=>{C(e,i.token),n(i)},reject:r}})},ze=(e,s)=>{let[,t,n,r]=s,i=e.authCallbacks[t];i&&(delete e.authCallbacks[t],r?i.reject(w(r)):i.resolve(n))},Je=e=>{let s=++fe;return f(e,[F.RequestTypes.Auth,F.AuthRequestTypes.Logout,s]),new Promise((t,n)=>{e.authCallbacks[s]={resolve:r=>{C(e),t(r)},reject:n}})};var Ke=(e,s)=>{let t=new Date,n=t.getHours()+":"+t.getMinutes()+":"+t.getSeconds()+":"+t.getMilliseconds();if(s==="incoming"){let r=`\u25BC ${n} -- `;console.info(r,e)}else{let r=`\u25B2 ${n} -- `;console.info(r,e)}};d(O,require("@based/types"));var D=class{constructor(s){this.auth=[];this.subscriptions={};this.cache={};this.requestCallbacks={};this.authCallbacks={};this.connected=!1;this.subscriptionQueue=[];this.queue=[];this.drainInProgress=!1;this.based=s}get debug(){return this.debugInternal}set debug(s){s===!0?this.debugInternal=Ke:this.debugInternal=s}onClose(){this.connected=!1,Ie(this),xe(this),Ae(this),this.based.listeners.disconnect&&this.based.listeners.disconnect.forEach(s=>s())}onReconnect(){if(this.based.listeners.reconnect&&this.based.listeners.reconnect.forEach(s=>s()),this.tracking)for(let s of this.tracking)f(this,[g.RequestTypes.Track,{t:s}])}onOpen(){this.connected=!0,this.based.listeners.connect&&this.based.listeners.connect.forEach(s=>s()),this.token&&C(this,this.token,this.sendTokenOptions),M(this),le(this)}onData(s){var t,n;try{let r=JSON.parse(s.data);this.debugInternal&&this.debugInternal(r,"incoming");let[i,o,c,a,u]=r;if(i===g.RequestTypes.Token){this.retryingRenewToken=!1,o.length&&Me(this,r);for(let l of this.auth)l(!c);this.beingAuth=!1,this.auth=[]}else i===g.RequestTypes.Auth?ze(this,r):(((t=u||a)==null?void 0:t.code)===g.BasedErrorCodes.TokenExpired||((n=u||a)==null?void 0:n.message)==="Token expired")&&!this.retryingRenewToken?(this.retryingRenewToken=!0,_e(this,this.renewOptions).then(l=>{C(this,l.token,this.sendTokenOptions),i===g.RequestTypes.Subscription||i===g.RequestTypes.SubscriptionDiff?M(this):k(this,i,a==null?void 0:a.payload,this.requestCallbacks[o].resolve,this.requestCallbacks[o].reject),this.based.emit("renewToken",l)}).catch(l=>{var p;(p=this.requestCallbacks[o])==null||p.reject(l)})):i===g.RequestTypes.Set||i===g.RequestTypes.Get||i===g.RequestTypes.Configuration||i===g.RequestTypes.GetConfiguration||i===g.RequestTypes.Call||i===g.RequestTypes.Delete||i===g.RequestTypes.Copy||i===g.RequestTypes.Digest||i===g.RequestTypes.RemoveType||i===g.RequestTypes.RemoveField?Le(this,r):i===g.RequestTypes.Subscription?Ge(this,r):i===g.RequestTypes.SubscriptionDiff&&$e(this,r)}catch(r){console.error("Received incorrect data ",s.data)}}};var me=(e,s)=>{let t;if(e.configuration&&e.configuration.schema)for(let n in e.configuration.schema){let r=e.configuration.schema[n];if(r.prefixToTypeMapping){for(let i in r.prefixToTypeMapping)if(r.prefixToTypeMapping[i]===s){t=i;break}}}return t};var ke=require("@saulx/hash");var Ve=require("@based/types"),Xe=require("@saulx/hash"),We=new Set,ft=e=>{if(typeof window!="undefined"){if(We.has(e))return!1;We.add(e);try{let s="_ba:"+(0,Xe.hashCompact)(e);return localStorage.getItem(s)?!1:(localStorage.setItem(s,"1"),!0)}catch(s){return!1}}return!1},he=(e,s)=>{if(s){let t=`${e}`,n=Object.keys(s).sort();for(let r of n)t+="_"+r+"_"+s[r];return t}else return e},N=(e,s,t,n,r,i,o)=>{let c=he(s,t),a={t:c};o&&(a.r=1),r&&(a.e=1,i&&(a.o=i)),n?(a.s=1,e.tracking.delete(c)):o||(r||(e.tracking||(e.tracking=new Set),e.tracking.add(c)),ft(c)&&(a.u=1)),f(e,[Ve.RequestTypes.Track,a])};var ge=class{constructor(s,t,n){this.closed=!1;this.client=s,this.subId=n,this.subscriberId=t}unsubscribe(){this.closed=!0,y(this.client,this.subId,this.subscriberId)}},ye=class{constructor(s,t){this.closed=!1;this.client=s,this.subs=t}unsubscribe(){if(!this.closed){this.closed=!0;for(let s of this.subs)s.unsubscribe()}}},Y=class{constructor(s,t){this.client=s,this.components=t}subscribe(s,t,n){let r={data:{}},i=[];for(let{key:o,obs:c}of this.components){let a=c.subscribe(u=>{if(o===""){Object.assign(r.data,u),s(r);return}r.data[o]=u,s(r)},t);i.push(a)}return new ye(this.client,i)}},P=class{constructor(s,t,n){this.client=s,this.subId=typeof t=="string"?q(n,t):q(t),this.name=typeof t=="string"?t:null,this.payload=typeof t=="string"?n:t}subscribe(s,t,n){let[,r]=E(this.client,this.payload,s,i=>{i&&(console.error(i),t&&t(i))},t,this.subId,this.name);return new ge(this.client,r,this.subId)}};var ve={},L={},mt=(e,s)=>{ve[e]||(ve[e]=!0,setTimeout(()=>{console.info("Drain file q"),ve[e]=!1;let t=L[e];L[e]=[];let n=new global.FormData;for(let r of t){let{raw:i,name:o,id:c,file:a,functionName:u}=r,l=`${u||""}|${i?1:0}|${c}|${a.size}${o?`|${o}`:""}`;n.append(l,a)}try{let r=new global.XMLHttpRequest;r.upload.onprogress=i=>{let o=100*(i.loaded||i.position)/(i.totalSize||i.total);console.info(o,"upload...")},r.onerror=i=>{console.error("error!",i,"flap",r.responseText)},r.timeout=1e3*60*60*24,r.onabort=i=>{console.error("abort",i)},r.ontimeout=i=>{console.error("on timeout",i)},r.onload=()=>{let i={};try{i=JSON.parse(r.response),console.info("SUCCESS",i)}catch(o){console.error("something wrong with file upload",o)}},r.open("POST",e+"/file"),r.setRequestHeader("Content-Type","multipart/form-data"),r.setRequestHeader("Authorization",s),r.send(n)}catch(r){console.error("Something wrong with xhr upload",r)}},500))},Ye=async(e,s,t,n,r,i,o)=>{L[t]||(L[t]=[]),L[t].push({file:s,id:n,url:t,raw:r,name:i,functionName:o}),mt(t,e.getToken())};var Ze=z(require("@based/get-service")),Z={},ee={},ht=async(e,s)=>{if(s.url)return typeof s.url=="string"?s.url:await s.url();if(!e.opts.env&&e.opts.url)return typeof e.opts.url=="string"?e.opts.url:await e.opts.url();let{env:t,project:n,org:r}=e.opts,i=t+"/"+n+"/"+r+"/"+e.opts.cluster;if(Z[i])return Z[i];if(ee[i])return(await ee[i]).url;let o=await(ee[i]=(0,Ze.default)({env:t,project:n,org:r,name:"@based/hub",key:"file-upload",optionalKey:!0},0,e.opts.cluster));return delete ee[i],setTimeout(()=>{delete Z[i]},2e3),Z[i]=o.url},et=ht;var tt=z(require("cross-fetch")),te=(e,s,t)=>((0,tt.default)(s,{method:"POST",cache:"no-cache",headers:{"Content-Type":t.mimeType||"text/plain","File-Id":t.id,"File-Is-Raw":t.raw?"1":"0","File-Name":t.name||"","Function-Name":t.functionName||"",Authorization:e.getToken()},body:t.contents}).then(n=>{}).catch(n=>{console.error("Error while uploading file",n)}),{id:t.id});var A=require("./file/stream"),se=typeof window!="undefined",gt=e=>"src"in e&&typeof e.src=="string",yt=e=>"path"in e&&typeof e.path=="string",vt=e=>"contents"in e&&(0,A.isStream)(e.contents),st=async(e,s)=>{if(gt(s)){let r=s.id?{$id:s.id}:{type:"file"};return s.src?(r.src=s.src,r.origin=s.src,s.size&&(r.size=s.size),s.name&&(r.name=s.name),s.parents&&(r.parents=s.parents),await e.set(r)):void 0}let t=s.id;if(!t){let r={type:"file",progress:0};s.name?r.name=s.name:global.File&&"contents"in s&&s.contents instanceof global.File&&(r.name=s.contents.name),s.parents&&(r.parents=s.parents),t=(await e.set(r)).id}s.id=t;let n=(await et(e,s)).replace(/^ws/,"http");if(yt(s))return(0,A.uploadFilePath)(e,n,s),{id:t};if(vt(s))return(0,A.uploadFileStream)(e,n,s),{id:t};if(s.contents instanceof ArrayBuffer)return s.contents=se?new global.Blob([s.contents],{type:s.mimeType||"text/plain"}):global.Buffer.from(s.contents),te(e,n+"/file",s);if(se&&s.contents instanceof global.Blob)return s.mimeType||(s.mimeType=s.contents.type),te(e,n+"/file",s);if(typeof s.contents=="string"||!se&&s.contents instanceof global.Buffer)return te(e,n+"/file",s);if(se&&s.contents instanceof File)return Ye(e,s.contents,n,s.id,s.raw||!1,s.name,s.functionName),{id:t};throw s.id||await e.delete({$id:t}),new Error(`Invalid contents for file api ${JSON.stringify(s,null,2)}`)};var ie=z(require("@based/get-service")),Se=require("@saulx/utils"),S=require("@based/graphql");d(m,require("@based/types"),module.exports);var re=class extends Be{constructor(t){super();this.client=new D(this),Object.defineProperty(this,"client",{enumerable:!1,writable:!0}),t&&t.url&&this.connect(t.url),this.graphql={query:this.gqlQuery.bind(this),live:this.gqlLive.bind(this)}}connect(t){!t&&this._url?this.client.connection||(this.client.connection=ue(this.client,this._url)):(this._url=t,this.client.connection=ue(this.client,t))}disconnect(){this.client.connection&&(this.client.connection.disconnected=!0,this.client.connection.destroy(),this.client.connection.ws&&this.client.connection.ws.close(),this.client.connected&&this.client.onClose(),delete this.client.connection),this.client.connected=!1}observeUntil(t,n,r){return new Promise((i,o)=>{let c,a=!1;this.observe(t,(u,l)=>{r&&r(u,l),n(u,l)&&(a=!0,c&&c(),i(u))}).then(u=>{a?c():c=u}).catch(u=>{o(u)})})}gql(t,...n){typeof t=="string"&&(t=[t]);let r=t[0];return n.forEach((i,o)=>{i&&i.kind==="Document"?r+=i.loc.source.body:r+=i,r+=t[o+1]}),(0,S.createOperations)({schemas:this.client.configuration.schema},(0,S.parseGraphql)(r))}gqlDb(t="default"){return(n,...r)=>{typeof n=="string"&&(n=[n]);let i=n[0];return r.forEach((o,c)=>{o&&o.kind==="Document"?i+=o.loc.source.body:i+=o,i+=n[c+1]}),(0,S.createOperations)({schemas:this.client.configuration.schema,db:t},(0,S.parseGraphql)(i))}}observe(t,n,r,i){return typeof t=="string"?new Promise((o,c)=>{let a=typeof n=="function",u=a?n:r,l=a?r:i;E(this.client,a?void 0:n,u,(p,b,h,T,R)=>{p&&!R?c(p):o(()=>{y(this.client,b,h)})},l,void 0,t)}):new Promise((o,c)=>{E(this.client,t,n,(a,u,l,p,b)=>{a&&!b?c(a):o(()=>{y(this.client,u,l)})},r)})}createObservable(t,n){return typeof t=="string"?new P(this.client,t,n):new P(this.client,t)}observeSchema(t,n,r){return new Promise((i,o)=>{let c=typeof t=="string"?t:"default",a=typeof t=="string"?n:t,u=typeof t=="string"?r:n;E(this.client,{$subscribe_schema:c},(l,p)=>{this.client.configuration||(this.client.configuration={dbs:[],schema:{},functions:{}}),this.client.configuration.schema[c]=l,a(l,p)},(l,p,b,h,T)=>{l&&!T?o(l):i(()=>{y(this.client,p,b)})},u)})}get(t,n){return typeof t=="string"?new Promise((r,i)=>{K(this.client,n,(o,c,a,u)=>{o?i(o):r(u)},0,t)}):new Promise((r,i)=>{k(this.client,v.RequestTypes.Get,t,r,i)})}file(t){return global.File&&t instanceof File&&(t={contents:t}),st(this,t)}call(t,n){return new Promise((r,i)=>{k(this.client,v.RequestTypes.Call,n,r,i,t)})}async id(t,n){let r=me(this.client,t);if(r||(await this.schema(),r=me(this.client,t)),!r)throw w({message:`Type does not exist ${t}`,type:"Invalid type",payload:n?{type:t,opts:n}:{type:t}});if(n){let i=(0,ke.hashCompact)(n,8,!0);return r+i}else return r+(0,ke.hashCompact)(Math.floor(Math.random()*99999999999)+""+Date.now())}digest(t){return new Promise((n,r)=>{k(this.client,v.RequestTypes.Digest,t,n,r)})}set(t){return new Promise((n,r)=>{k(this.client,v.RequestTypes.Set,t,n,r)})}copy(t){return new Promise((n,r)=>{k(this.client,v.RequestTypes.Copy,t,n,r)})}async gqlQuery(t,n={}){let r;typeof t=="string"?r=this.gql(t):r=t;try{if(r=(0,S.handleGraphqlVariables)(r,r,n),r.opType==="GET"){let o={$db:r.db},c=[];for(let u in r.ops){if(r.ops[u].fnObserve){let l=await this.get(r.ops[u].fnObserve.name,r.ops[u].fnObserve.payload);c.push({key:u,reply:l});continue}r.ops[u].get&&(o[u]=r.ops[u].get)}let a=await this.get(o);for(let{key:u,reply:l}of c)a[u]=l;return{data:a}}let i={};return await Promise.all(Object.entries(r.ops).map(async([o,c])=>{var p,b,h,T,R;if(c.delete){i[o]=await this.delete(c.delete);return}else if(c.fnCall){i[o]=await this.call(c.fnCall.name,c.fnCall.payload);return}let{id:a}=await this.set(c.set);if(!c.get){let x={};x.id=a;let Te=(R=(T=(h=(b=(p=this.client)==null?void 0:p.configuration)==null?void 0:b.schema)==null?void 0:h[r.db])==null?void 0:T.prefixToTypeMapping)==null?void 0:R[a.slice(0,2)];Te&&(x.type=Te),i[o]=x;return}let u=(0,Se.deepCopy)(c.get);u.$id=a;let l=await this.get(u);i[o]=l})),{data:i}}catch(i){return{errors:[{message:i.message,locations:i.locations}]}}}async gqlLive(t,n={}){let r;if(typeof t=="string"?r=this.gql(t):r=t,r=(0,S.handleGraphqlVariables)(r,r,n),r.opType==="GET"){let o=[],c={};for(let a in r.ops){if(r.ops[a].fnObserve){let{name:u,payload:l}=r.ops[a].fnObserve;o.push({key:a,fn:{name:u,payload:l}});continue}c[a]=r.ops[a].get}if(o!=null&&o.length){let a=o.map(l=>({obs:new P(this.client,l.fn.name,l.fn.payload),key:l.key})),u=new P(this.client,oe({$db:r.db},c));return a.push({key:"",obs:u}),new Y(this.client,a)}return new P(this.client,{$db:r.db,data:c})}let i={};return await Promise.all(Object.entries(r.ops).map(async([o,c])=>{if(c.delete){i[o]=await this.delete(c.delete);return}else if(c.fnCall){i[o]=await this.call(c.fnCall.name,c.fnCall.payload);return}let{id:a}=await this.set(c.set),u=(0,Se.deepCopy)(c.get);u.$id=a,i[o]=u})),new P(this.client,{$db:r.db,data:i})}analytics(t,n){return new Promise((r,i)=>{n?E(this.client,t,n,(o,c,a,u,l)=>{o&&!l?i(o):r(()=>{y(this.client,c,a)})},o=>console.error(o),void 0,"analytics"):K(this.client,t,(o,c,a,u)=>{o?i(o):((0,v.isAnalyticsHistoryOpts)(t)||(0,v.isAnalyticsTypesOpts)(t),r(u))},0,"analytics")})}track(t,n){N(this.client,t,n)}clearAnalytics(t,n){N(this.client,t,n,!1,!1,void 0,!0)}untrack(t,n){N(this.client,t,n,!0)}event(t,n,r){N(this.client,t,n,!1,!0,r)}delete(t){return new Promise((n,r)=>{k(this.client,v.RequestTypes.Delete,t,n,r)})}schema(){return new Promise((t,n)=>{let r=i=>{this.client.configuration=i,t(i)};k(this.client,v.RequestTypes.GetConfiguration,0,r,n)})}removeType(t,n="default"){return new Promise((r,i)=>{k(this.client,v.RequestTypes.RemoveType,{type:t,db:n},r,i)})}removeField(t,n,r="default"){return new Promise((i,o)=>{!n||n.length===0?o(new Error("Path cannot be empty")):(Array.isArray(n)||(n=[n]),k(this.client,v.RequestTypes.RemoveField,{type:t,db:r,path:n},i,o))})}updateSchema(t){return new Promise((n,r)=>{k(this.client,v.RequestTypes.Configuration,t,n,r)})}getToken(){return this.client.token}auth(t,n){return new Promise(r=>{if(this.client.auth.push(r),t&&t!==this.client.token||t===!1&&this.client.token){if(typeof t=="string"){let i=n||{},{renewOptions:o,refreshToken:c}=i,a=Pe(i,["renewOptions","refreshToken"]);o&&(this.client.renewOptions=o),c&&(this.client.renewOptions=Ce(oe({},this.client.renewOptions),{refreshToken:c})),C(this.client,t,a)}else C(this.client);this.emit("auth",t)}})}async login(t){return He(this.client,t)}logout(){return Je(this.client)}},kt=(e,s)=>{if(s){let t;e+=/\?/.test(e)?"&":"?";for(let n in s){let r=s[n];e+=t?`&${n}=${r}`:`${n}=${r}`,t=!0}}return e},St=(e,s=re)=>{let{env:t,project:n,org:r,url:i,key:o,name:c="@based/hub",cluster:a,params:u}=e;if(i||(a=e.cluster=(0,ie.getClusterUrl)(a),i=async()=>{let{url:l}=await(0,ie.default)({env:t,project:n,org:r,key:o,name:c},0,a);return kt(l,u)}),i){let l=new s;return l.opts=e,l.connect(i),l}},Tt=St;0&&(module.exports={Based,BasedClient,BasedGraphQL,Observable,addGetSubscriber,addRequest,addSubscriber,createGraphqlOperations,generateSubscriptionId,generateTrackingKey,handleGraphqlVariables,parseGraphql,removeSubscriber});
`),delete e.cache[t],f(e,[X.RequestTypes.SendSubscriptionData,t]);else{c.checksum=i;for(let u in o.subscribers){let l=o.subscribers[u];l.onInitial&&(l.onInitial(null,Number(t),Number(u),c.value),delete l.onInitial,l.onData||v(e,t,Number(u))),l.onData&&l.onData(c.value,c.checksum)}}}}};var Me=(e,s)=>{for(let t of s[1]){delete e.cache[t];let n=e.subscriptions[t];if(n){let r={type:"AuthorizationError",name:n.name?`observe "${n.name}"`:"observe",message:"Unauthorized request",payload:n.query,auth:!0},i=C(r);n.authError={token:e.token,error:i};for(let o in n.subscribers){let c=n.subscribers[o];c.onError&&c.onError(i)}}}};var Ne=require("@based/types");var dt=0,y=(e,s,t,n,r,i,o)=>{let c=++dt;e.requestCallbacks[c]={resolve:n,reject:r,type:s,payload:t,name:i,isRetry:o},s===Ne.RequestTypes.Call?f(e,[s,i,c,t]):f(e,[s,c,t])};var Le=(e,s)=>{let[,t,n,r]=s,i=e.requestCallbacks[t];i&&(delete e.requestCallbacks[t],r?i.reject(C(r)):i.resolve(n))};var O={};qe(O,{BasedClient:()=>D});var g=require("@based/types");var be=require("@based/types");var bt=e=>typeof e!="undefined"&&e!==null,ft=(e,s,t)=>{if(e.beingAuth=!0,s)e.token=s,e.sendTokenOptions=t;else{for(let n in e.cache)e.subscriptions[n]||delete e.cache[n];delete e.token,delete e.sendTokenOptions}if(e.connected){let n=s?[be.RequestTypes.Token,s,t].filter(bt):[be.RequestTypes.Token];e.connection.ws.send(JSON.stringify(n)),J(e),M(e,!0)}},w=ft;var B=require("@based/types");var fe=0,He=(e,s)=>{let t=++fe;return f(e,[B.RequestTypes.Auth,B.AuthRequestTypes.Login,t,s]),new Promise((n,r)=>{e.authCallbacks[t]={resolve:i=>{w(e,i.token,{refreshToken:i.refreshToken}),n(i)},reject:r}})},_e=(e,s)=>new Promise((t,n)=>{y(e,B.RequestTypes.Call,s,r=>{w(e,r.token,{refreshToken:r.refreshToken}),t(r)},n,"registerUser")}),ze=(e,s)=>{let t=++fe;return f(e,[B.RequestTypes.Auth,B.AuthRequestTypes.RenewToken,t,s]),new Promise((n,r)=>{e.authCallbacks[t]={resolve:i=>{w(e,i.token),n(i)},reject:r}})},Je=(e,s)=>{let[,t,n,r]=s,i=e.authCallbacks[t];i&&(delete e.authCallbacks[t],r?i.reject(C(r)):i.resolve(n))},Ke=e=>{let s=++fe;return f(e,[B.RequestTypes.Auth,B.AuthRequestTypes.Logout,s]),new Promise((t,n)=>{e.authCallbacks[s]={resolve:r=>{w(e),t(r)},reject:n}})};var We=(e,s)=>{let t=new Date,n=t.getHours()+":"+t.getMinutes()+":"+t.getSeconds()+":"+t.getMilliseconds();if(s==="incoming"){let r=`\u25BC ${n} -- `;console.info(r,e)}else{let r=`\u25B2 ${n} -- `;console.info(r,e)}};d(O,require("@based/types"));var D=class{constructor(s){this.auth=[];this.subscriptions={};this.cache={};this.requestCallbacks={};this.authCallbacks={};this.connected=!1;this.subscriptionQueue=[];this.queue=[];this.drainInProgress=!1;this.based=s}get debug(){return this.debugInternal}set debug(s){s===!0?this.debugInternal=We:this.debugInternal=s}onClose(){this.connected=!1,Ie(this),xe(this),Ae(this),this.based.listeners.disconnect&&this.based.listeners.disconnect.forEach(s=>s())}onReconnect(){if(this.based.listeners.reconnect&&this.based.listeners.reconnect.forEach(s=>s()),this.tracking)for(let s of this.tracking)f(this,[g.RequestTypes.Track,{t:s}])}onOpen(){this.connected=!0,this.based.listeners.connect&&this.based.listeners.connect.forEach(s=>s()),this.token&&w(this,this.token,this.sendTokenOptions),M(this),le(this)}onData(s){var t,n;try{let r=JSON.parse(s.data);this.debugInternal&&this.debugInternal(r,"incoming");let[i,o,c,a,u]=r;if(i===g.RequestTypes.Token){this.retryingRenewToken=!1,o.length&&Me(this,r);for(let l of this.auth)l(!c);this.beingAuth=!1,this.auth=[]}else i===g.RequestTypes.Auth?Je(this,r):(((t=u||a)==null?void 0:t.code)===g.BasedErrorCodes.TokenExpired||((n=u||a)==null?void 0:n.message)==="Token expired")&&!this.retryingRenewToken?(this.retryingRenewToken=!0,ze(this,this.renewOptions).then(l=>{w(this,l.token,this.sendTokenOptions),i===g.RequestTypes.Subscription||i===g.RequestTypes.SubscriptionDiff?M(this):y(this,i,a==null?void 0:a.payload,this.requestCallbacks[o].resolve,this.requestCallbacks[o].reject),this.based.emit("renewToken",l)}).catch(l=>{var p;(p=this.requestCallbacks[o])==null||p.reject(l)})):i===g.RequestTypes.Set||i===g.RequestTypes.Get||i===g.RequestTypes.Configuration||i===g.RequestTypes.GetConfiguration||i===g.RequestTypes.Call||i===g.RequestTypes.Delete||i===g.RequestTypes.Copy||i===g.RequestTypes.Digest||i===g.RequestTypes.RemoveType||i===g.RequestTypes.RemoveField?Le(this,r):i===g.RequestTypes.Subscription?Ge(this,r):i===g.RequestTypes.SubscriptionDiff&&$e(this,r)}catch(r){console.error("Received incorrect data ",s.data)}}};var me=(e,s)=>{let t;if(e.configuration&&e.configuration.schema)for(let n in e.configuration.schema){let r=e.configuration.schema[n];if(r.prefixToTypeMapping){for(let i in r.prefixToTypeMapping)if(r.prefixToTypeMapping[i]===s){t=i;break}}}return t};var ke=require("@saulx/hash");var Xe=require("@based/types"),Ye=require("@saulx/hash"),Ve=new Set,mt=e=>{if(typeof window!="undefined"){if(Ve.has(e))return!1;Ve.add(e);try{let s="_ba:"+(0,Ye.hashCompact)(e);return localStorage.getItem(s)?!1:(localStorage.setItem(s,"1"),!0)}catch(s){return!1}}return!1},he=(e,s)=>{if(s){let t=`${e}`,n=Object.keys(s).sort();for(let r of n)t+="_"+r+"_"+s[r];return t}else return e},N=(e,s,t,n,r,i,o)=>{let c=he(s,t),a={t:c};o&&(a.r=1),r&&(a.e=1,i&&(a.o=i)),n?(a.s=1,e.tracking.delete(c)):o||(r||(e.tracking||(e.tracking=new Set),e.tracking.add(c)),mt(c)&&(a.u=1)),f(e,[Xe.RequestTypes.Track,a])};var ge=class{constructor(s,t,n){this.closed=!1;this.client=s,this.subId=n,this.subscriberId=t}unsubscribe(){this.closed=!0,v(this.client,this.subId,this.subscriberId)}},ye=class{constructor(s,t){this.closed=!1;this.client=s,this.subs=t}unsubscribe(){if(!this.closed){this.closed=!0;for(let s of this.subs)s.unsubscribe()}}},Y=class{constructor(s,t){this.client=s,this.components=t}subscribe(s,t,n){let r={data:{}},i=[];for(let{key:o,obs:c}of this.components){let a=c.subscribe(u=>{if(o===""){Object.assign(r.data,u),s(r);return}r.data[o]=u,s(r)},t);i.push(a)}return new ye(this.client,i)}},P=class{constructor(s,t,n){this.client=s,this.subId=typeof t=="string"?q(n,t):q(t),this.name=typeof t=="string"?t:null,this.payload=typeof t=="string"?n:t}subscribe(s,t,n){let[,r]=F(this.client,this.payload,s,i=>{i&&(console.error(i),t&&t(i))},t,this.subId,this.name);return new ge(this.client,r,this.subId)}};var ve={},L={},ht=(e,s)=>{ve[e]||(ve[e]=!0,setTimeout(()=>{console.info("Drain file q"),ve[e]=!1;let t=L[e];L[e]=[];let n=new global.FormData;for(let r of t){let{raw:i,name:o,id:c,file:a,functionName:u}=r,l=`${u||""}|${i?1:0}|${c}|${a.size}${o?`|${o}`:""}`;n.append(l,a)}try{let r=new global.XMLHttpRequest;r.upload.onprogress=i=>{let o=100*(i.loaded||i.position)/(i.totalSize||i.total);console.info(o,"upload...")},r.onerror=i=>{console.error("error!",i,"flap",r.responseText)},r.timeout=1e3*60*60*24,r.onabort=i=>{console.error("abort",i)},r.ontimeout=i=>{console.error("on timeout",i)},r.onload=()=>{let i={};try{i=JSON.parse(r.response),console.info("SUCCESS",i)}catch(o){console.error("something wrong with file upload",o)}},r.open("POST",e+"/file"),r.setRequestHeader("Content-Type","multipart/form-data"),r.setRequestHeader("Authorization",s),r.send(n)}catch(r){console.error("Something wrong with xhr upload",r)}},500))},Ze=async(e,s,t,n,r,i,o)=>{L[t]||(L[t]=[]),L[t].push({file:s,id:n,url:t,raw:r,name:i,functionName:o}),ht(t,e.getToken())};var et=z(require("@based/get-service")),Z={},ee={},gt=async(e,s)=>{if(s.url)return typeof s.url=="string"?s.url:await s.url();if(!e.opts.env&&e.opts.url)return typeof e.opts.url=="string"?e.opts.url:await e.opts.url();let{env:t,project:n,org:r}=e.opts,i=t+"/"+n+"/"+r+"/"+e.opts.cluster;if(Z[i])return Z[i];if(ee[i])return(await ee[i]).url;let o=await(ee[i]=(0,et.default)({env:t,project:n,org:r,name:"@based/hub",key:"file-upload",optionalKey:!0},0,e.opts.cluster));return delete ee[i],setTimeout(()=>{delete Z[i]},2e3),Z[i]=o.url},tt=gt;var st=z(require("cross-fetch")),te=(e,s,t)=>((0,st.default)(s,{method:"POST",cache:"no-cache",headers:{"Content-Type":t.mimeType||"text/plain","File-Id":t.id,"File-Is-Raw":t.raw?"1":"0","File-Name":t.name||"","Function-Name":t.functionName||"",Authorization:e.getToken()},body:t.contents}).then(n=>{}).catch(n=>{console.error("Error while uploading file",n)}),{id:t.id});var A=require("./file/stream"),se=typeof window!="undefined",yt=e=>"src"in e&&typeof e.src=="string",vt=e=>"path"in e&&typeof e.path=="string",kt=e=>"contents"in e&&(0,A.isStream)(e.contents),rt=async(e,s)=>{if(yt(s)){let r=s.id?{$id:s.id}:{type:"file"};return s.src?(r.src=s.src,r.origin=s.src,s.size&&(r.size=s.size),s.name&&(r.name=s.name),s.parents&&(r.parents=s.parents),await e.set(r)):void 0}let t=s.id;if(!t){let r={type:"file",progress:0};s.name?r.name=s.name:global.File&&"contents"in s&&s.contents instanceof global.File&&(r.name=s.contents.name),s.parents&&(r.parents=s.parents),t=(await e.set(r)).id}s.id=t;let n=(await tt(e,s)).replace(/^ws/,"http");if(vt(s))return(0,A.uploadFilePath)(e,n,s),{id:t};if(kt(s))return(0,A.uploadFileStream)(e,n,s),{id:t};if(s.contents instanceof ArrayBuffer)return s.contents=se?new global.Blob([s.contents],{type:s.mimeType||"text/plain"}):global.Buffer.from(s.contents),te(e,n+"/file",s);if(se&&s.contents instanceof global.Blob)return s.mimeType||(s.mimeType=s.contents.type),te(e,n+"/file",s);if(typeof s.contents=="string"||!se&&s.contents instanceof global.Buffer)return te(e,n+"/file",s);if(se&&s.contents instanceof File)return Ze(e,s.contents,n,s.id,s.raw||!1,s.name,s.functionName),{id:t};throw s.id||await e.delete({$id:t}),new Error(`Invalid contents for file api ${JSON.stringify(s,null,2)}`)};var ie=z(require("@based/get-service")),Se=require("@saulx/utils"),S=require("@based/graphql");d(m,require("@based/types"),module.exports);var re=class extends Re{constructor(t){super();this.client=new D(this),Object.defineProperty(this,"client",{enumerable:!1,writable:!0}),t&&t.url&&this.connect(t.url),this.graphql={query:this.gqlQuery.bind(this),live:this.gqlLive.bind(this)}}connect(t){!t&&this._url?this.client.connection||(this.client.connection=ue(this.client,this._url)):(this._url=t,this.client.connection=ue(this.client,t))}disconnect(){this.client.connection&&(this.client.connection.disconnected=!0,this.client.connection.destroy(),this.client.connection.ws&&this.client.connection.ws.close(),this.client.connected&&this.client.onClose(),delete this.client.connection),this.client.connected=!1}observeUntil(t,n,r){return new Promise((i,o)=>{let c,a=!1;this.observe(t,(u,l)=>{r&&r(u,l),n(u,l)&&(a=!0,c&&c(),i(u))}).then(u=>{a?c():c=u}).catch(u=>{o(u)})})}gql(t,...n){typeof t=="string"&&(t=[t]);let r=t[0];return n.forEach((i,o)=>{i&&i.kind==="Document"?r+=i.loc.source.body:r+=i,r+=t[o+1]}),(0,S.createOperations)({schemas:this.client.configuration.schema},(0,S.parseGraphql)(r))}gqlDb(t="default"){return(n,...r)=>{typeof n=="string"&&(n=[n]);let i=n[0];return r.forEach((o,c)=>{o&&o.kind==="Document"?i+=o.loc.source.body:i+=o,i+=n[c+1]}),(0,S.createOperations)({schemas:this.client.configuration.schema,db:t},(0,S.parseGraphql)(i))}}observe(t,n,r,i){return typeof t=="string"?new Promise((o,c)=>{let a=typeof n=="function",u=a?n:r,l=a?r:i;F(this.client,a?void 0:n,u,(p,b,h,T,E)=>{p&&!E?c(p):o(()=>{v(this.client,b,h)})},l,void 0,t)}):new Promise((o,c)=>{F(this.client,t,n,(a,u,l,p,b)=>{a&&!b?c(a):o(()=>{v(this.client,u,l)})},r)})}createObservable(t,n){return typeof t=="string"?new P(this.client,t,n):new P(this.client,t)}observeSchema(t,n,r){return new Promise((i,o)=>{let c=typeof t=="string"?t:"default",a=typeof t=="string"?n:t,u=typeof t=="string"?r:n;F(this.client,{$subscribe_schema:c},(l,p)=>{this.client.configuration||(this.client.configuration={dbs:[],schema:{},functions:{}}),this.client.configuration.schema[c]=l,a(l,p)},(l,p,b,h,T)=>{l&&!T?o(l):i(()=>{v(this.client,p,b)})},u)})}get(t,n){return typeof t=="string"?new Promise((r,i)=>{K(this.client,n,(o,c,a,u)=>{o?i(o):r(u)},0,t)}):new Promise((r,i)=>{y(this.client,k.RequestTypes.Get,t,r,i)})}file(t){return global.File&&t instanceof File&&(t={contents:t}),rt(this,t)}call(t,n){return new Promise((r,i)=>{y(this.client,k.RequestTypes.Call,n,r,i,t)})}async id(t,n){let r=me(this.client,t);if(r||(await this.schema(),r=me(this.client,t)),!r)throw C({message:`Type does not exist ${t}`,type:"Invalid type",payload:n?{type:t,opts:n}:{type:t}});if(n){let i=(0,ke.hashCompact)(n,8,!0);return r+i}else return r+(0,ke.hashCompact)(Math.floor(Math.random()*99999999999)+""+Date.now())}digest(t){return new Promise((n,r)=>{y(this.client,k.RequestTypes.Digest,t,n,r)})}set(t){return new Promise((n,r)=>{y(this.client,k.RequestTypes.Set,t,n,r)})}copy(t){return new Promise((n,r)=>{y(this.client,k.RequestTypes.Copy,t,n,r)})}async gqlQuery(t,n={}){let r;typeof t=="string"?r=this.gql(t):r=t;try{if(r=(0,S.handleGraphqlVariables)(r,r,n),r.opType==="GET"){let o={$db:r.db},c=[];for(let u in r.ops){if(r.ops[u].fnObserve){let l=await this.get(r.ops[u].fnObserve.name,r.ops[u].fnObserve.payload);c.push({key:u,reply:l});continue}r.ops[u].get&&(o[u]=r.ops[u].get)}let a=await this.get(o);for(let{key:u,reply:l}of c)a[u]=l;return{data:a}}let i={};return await Promise.all(Object.entries(r.ops).map(async([o,c])=>{var p,b,h,T,E;if(c.delete){i[o]=await this.delete(c.delete);return}else if(c.fnCall){i[o]=await this.call(c.fnCall.name,c.fnCall.payload);return}let{id:a}=await this.set(c.set);if(!c.get){let x={};x.id=a;let Te=(E=(T=(h=(b=(p=this.client)==null?void 0:p.configuration)==null?void 0:b.schema)==null?void 0:h[r.db])==null?void 0:T.prefixToTypeMapping)==null?void 0:E[a.slice(0,2)];Te&&(x.type=Te),i[o]=x;return}let u=(0,Se.deepCopy)(c.get);u.$id=a;let l=await this.get(u);i[o]=l})),{data:i}}catch(i){return{errors:[{message:i.message,locations:i.locations}]}}}async gqlLive(t,n={}){let r;if(typeof t=="string"?r=this.gql(t):r=t,r=(0,S.handleGraphqlVariables)(r,r,n),r.opType==="GET"){let o=[],c={};for(let a in r.ops){if(r.ops[a].fnObserve){let{name:u,payload:l}=r.ops[a].fnObserve;o.push({key:a,fn:{name:u,payload:l}});continue}c[a]=r.ops[a].get}if(o!=null&&o.length){let a=o.map(l=>({obs:new P(this.client,l.fn.name,l.fn.payload),key:l.key})),u=new P(this.client,oe({$db:r.db},c));return a.push({key:"",obs:u}),new Y(this.client,a)}return new P(this.client,{$db:r.db,data:c})}let i={};return await Promise.all(Object.entries(r.ops).map(async([o,c])=>{if(c.delete){i[o]=await this.delete(c.delete);return}else if(c.fnCall){i[o]=await this.call(c.fnCall.name,c.fnCall.payload);return}let{id:a}=await this.set(c.set),u=(0,Se.deepCopy)(c.get);u.$id=a,i[o]=u})),new P(this.client,{$db:r.db,data:i})}analytics(t,n){return new Promise((r,i)=>{n?F(this.client,t,n,(o,c,a,u,l)=>{o&&!l?i(o):r(()=>{v(this.client,c,a)})},o=>console.error(o),void 0,"analytics"):K(this.client,t,(o,c,a,u)=>{o?i(o):((0,k.isAnalyticsHistoryOpts)(t)||(0,k.isAnalyticsTypesOpts)(t),r(u))},0,"analytics")})}track(t,n){N(this.client,t,n)}clearAnalytics(t,n){N(this.client,t,n,!1,!1,void 0,!0)}untrack(t,n){N(this.client,t,n,!0)}event(t,n,r){N(this.client,t,n,!1,!0,r)}delete(t){return new Promise((n,r)=>{y(this.client,k.RequestTypes.Delete,t,n,r)})}schema(){return new Promise((t,n)=>{let r=i=>{this.client.configuration=i,t(i)};y(this.client,k.RequestTypes.GetConfiguration,0,r,n)})}removeType(t,n="default"){return new Promise((r,i)=>{y(this.client,k.RequestTypes.RemoveType,{type:t,db:n},r,i)})}removeField(t,n,r="default"){return new Promise((i,o)=>{!n||n.length===0?o(new Error("Path cannot be empty")):(Array.isArray(n)||(n=[n]),y(this.client,k.RequestTypes.RemoveField,{type:t,db:r,path:n},i,o))})}updateSchema(t){return new Promise((n,r)=>{y(this.client,k.RequestTypes.Configuration,t,n,r)})}getToken(){return this.client.token}auth(t,n){return new Promise(r=>{if(this.client.auth.push(r),t&&t!==this.client.token||t===!1&&this.client.token){if(typeof t=="string"){let i=n||{},{renewOptions:o,refreshToken:c}=i,a=Pe(i,["renewOptions","refreshToken"]);o&&(this.client.renewOptions=o),c&&(this.client.renewOptions=Ce(oe({},this.client.renewOptions),{refreshToken:c})),w(this.client,t,a)}else w(this.client);this.emit("auth",t)}})}async login(t){return He(this.client,t)}async register(t){return _e(this.client,t)}logout(){return Ke(this.client)}},St=(e,s)=>{if(s){let t;e+=/\?/.test(e)?"&":"?";for(let n in s){let r=s[n];e+=t?`&${n}=${r}`:`${n}=${r}`,t=!0}}return e},Tt=(e,s=re)=>{let{env:t,project:n,org:r,url:i,key:o,name:c="@based/hub",cluster:a,params:u}=e;if(i||(a=e.cluster=(0,ie.getClusterUrl)(a),i=async()=>{let{url:l}=await(0,ie.default)({env:t,project:n,org:r,key:o,name:c},0,a);return St(l,u)}),i){let l=new s;return l.opts=e,l.connect(i),l}},Ot=Tt;0&&(module.exports={Based,BasedClient,BasedGraphQL,Observable,addGetSubscriber,addRequest,addSubscriber,createGraphqlOperations,generateSubscriptionId,generateTrackingKey,handleGraphqlVariables,parseGraphql,removeSubscriber});
{
"name": "@based/client",
"version": "2.9.0",
"version": "2.10.0",
"license": "MIT",

@@ -34,3 +34,3 @@ "main": "dist/index.js",

"@based/graphql": "2.4.2",
"@based/types": "^2.6.0",
"@based/types": "^2.7.1",
"@saulx/diff": "^1.1.3",

@@ -37,0 +37,0 @@ "@saulx/hash": "^1.1.0",

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