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 1.2.4 to 1.2.5

2

dist/index.d.ts

@@ -37,3 +37,3 @@ import Emitter from './Emitter';

observeUntil(query: Query, condition: (data: GenericObject, checksum: number) => boolean, onData?: (data: any, checksum: number) => void): Promise<GenericObject>;
gql(literals: string | readonly string[], ...args: any[]): any;
gql(literals: string | readonly string[], ...args: any[]): BasedGraphQL;
gqlDb(db?: string): (literals: string | readonly string[], ...args: any[]) => BasedGraphQL;

@@ -40,0 +40,0 @@ observe(query: Query, onData: (data: any, checksum: number) => void, onErr?: (err: Error) => void): Promise<() => void>;

@@ -1,551 +0,15 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Based = exports.Observable = exports.BasedClient = exports.generateSubscriptionId = exports.addRequest = exports.removeSubscriber = exports.addGetSubscriber = exports.addSubscriber = exports.generateTrackingKey = exports.handleGraphqlVariables = exports.parseGraphql = exports.createGraphqlOperations = exports.BasedGraphQL = void 0;
const Emitter_1 = __importDefault(require("./Emitter"));
const websocket_1 = __importDefault(require("./websocket"));
const types_1 = require("@based/types");
const subscriptions_1 = require("./subscriptions");
Object.defineProperty(exports, "addSubscriber", { enumerable: true, get: function () { return subscriptions_1.addSubscriber; } });
Object.defineProperty(exports, "generateSubscriptionId", { enumerable: true, get: function () { return subscriptions_1.generateSubscriptionId; } });
Object.defineProperty(exports, "addGetSubscriber", { enumerable: true, get: function () { return subscriptions_1.addGetSubscriber; } });
Object.defineProperty(exports, "removeSubscriber", { enumerable: true, get: function () { return subscriptions_1.removeSubscriber; } });
const request_1 = require("./request");
Object.defineProperty(exports, "addRequest", { enumerable: true, get: function () { return request_1.addRequest; } });
const Client_1 = require("./Client");
Object.defineProperty(exports, "BasedClient", { enumerable: true, get: function () { return Client_1.BasedClient; } });
const findPrefix_1 = __importDefault(require("./findPrefix"));
const createError_1 = __importDefault(require("./createError"));
const hash_1 = require("@saulx/hash");
const token_1 = __importDefault(require("./token"));
const track_1 = __importStar(require("./track"));
Object.defineProperty(exports, "generateTrackingKey", { enumerable: true, get: function () { return track_1.genKey; } });
const observable_1 = require("./observable");
Object.defineProperty(exports, "Observable", { enumerable: true, get: function () { return observable_1.Observable; } });
const file_1 = __importDefault(require("./file"));
const get_service_1 = __importStar(require("@based/get-service"));
const utils_1 = require("@saulx/utils");
const graphql_1 = require("@based/graphql");
Object.defineProperty(exports, "BasedGraphQL", { enumerable: true, get: function () { return graphql_1.BasedGraphQL; } });
Object.defineProperty(exports, "createGraphqlOperations", { enumerable: true, get: function () { return graphql_1.createOperations; } });
Object.defineProperty(exports, "parseGraphql", { enumerable: true, get: function () { return graphql_1.parseGraphql; } });
Object.defineProperty(exports, "handleGraphqlVariables", { enumerable: true, get: function () { return graphql_1.handleGraphqlVariables; } });
__exportStar(require("@based/types"), exports);
class Based extends Emitter_1.default {
constructor(opts) {
super();
this.client = new Client_1.BasedClient(this);
Object.defineProperty(this, 'client', {
enumerable: false,
writable: true,
});
if (opts && opts.url) {
this.connect(opts.url);
}
this.graphql = {
query: this.gqlQuery.bind(this),
live: this.gqlLive.bind(this),
};
}
connect(url) {
if (!url && this._url) {
if (!this.client.connection) {
this.client.connection = (0, websocket_1.default)(this.client, this._url);
}
}
else {
this._url = url;
this.client.connection = (0, websocket_1.default)(this.client, url);
}
}
disconnect() {
if (this.client.connection) {
this.client.connection.disconnected = true;
this.client.connection.destroy();
if (this.client.connection.ws) {
this.client.connection.ws.close();
}
if (this.client.connected) {
this.client.onClose();
}
delete this.client.connection;
}
this.client.connected = false;
}
observeUntil(query, condition, onData) {
return new Promise((resolve, reject) => {
let close;
let isResolved = false;
this.observe(query, (d, checksum) => {
if (onData) {
onData(d, checksum);
}
if (condition(d, checksum)) {
isResolved = true;
if (close) {
close();
}
resolve(d);
}
})
.then((c) => {
if (isResolved) {
close();
}
else {
close = c;
}
})
.catch((err) => {
reject(err);
});
});
}
gql(literals, ...args) {
if (typeof literals === 'string') {
literals = [literals];
}
let result = literals[0];
args.forEach((arg, i) => {
if (arg && arg.kind === 'Document') {
result += arg.loc.source.body;
}
else {
result += arg;
}
result += literals[i + 1];
});
return (0, graphql_1.createOperations)({ schemas: this.client.configuration.schema }, (0, graphql_1.parseGraphql)(result));
}
gqlDb(db = 'default') {
return (literals, ...args) => {
if (typeof literals === 'string') {
literals = [literals];
}
let result = literals[0];
args.forEach((arg, i) => {
if (arg && arg.kind === 'Document') {
result += arg.loc.source.body;
}
else {
result += arg;
}
result += literals[i + 1];
});
return (0, graphql_1.createOperations)({ schemas: this.client.configuration.schema, db }, (0, graphql_1.parseGraphql)(result));
};
}
observe(a, b, c, d) {
if (typeof a === 'string') {
return new Promise((resolve, reject) => {
const noPayload = typeof b === 'function';
const onData = noPayload ? b : c;
const onErr = noPayload ? c : d;
(0, subscriptions_1.addSubscriber)(this.client, noPayload ? undefined : b, // not only query should be any
onData, (err, subscriptionId, subscriberId, _data, isAuthError) => {
if (err && !isAuthError) {
// maybe log also
reject(err);
}
else {
const unsubscribe = () => {
(0, subscriptions_1.removeSubscriber)(this.client, subscriptionId, subscriberId);
};
resolve(unsubscribe);
}
}, onErr, undefined, a);
});
}
else {
return new Promise((resolve, reject) => {
(0, subscriptions_1.addSubscriber)(this.client, a, b, (err, subscriptionId, subscriberId, _data, isAuthError) => {
if (err && !isAuthError) {
// maybe log also
reject(err);
}
else {
const unsubscribe = () => {
(0, subscriptions_1.removeSubscriber)(this.client, subscriptionId, subscriberId);
};
resolve(unsubscribe);
}
}, c);
});
}
}
createObservable(a, payload) {
if (typeof a === 'string') {
return new observable_1.Observable(this.client, a, payload);
}
else {
return new observable_1.Observable(this.client, a);
}
}
observeSchema(a, b, c) {
return new Promise((resolve, reject) => {
const db = typeof a === 'string' ? a : 'default';
const onData = typeof a === 'string' ? b : a;
const onErr = typeof a === 'string' ? c : b;
(0, subscriptions_1.addSubscriber)(this.client, { $subscribe_schema: db }, (data, checksum) => {
if (!this.client.configuration) {
this.client.configuration = { dbs: [], schema: {}, functions: {} };
}
// console.info('hello', this.client.configuration)
this.client.configuration.schema[db] = data;
onData(data, checksum);
// this.client.configuration.schema
}, (err, subscriptionId, subscriberId, _data, isAuthError) => {
if (err && !isAuthError) {
// maybe log also
reject(err);
}
else {
const unsubscribe = () => {
(0, subscriptions_1.removeSubscriber)(this.client, subscriptionId, subscriberId);
};
resolve(unsubscribe);
}
}, onErr);
});
}
get(a, payload) {
if (typeof a === 'string') {
return new Promise((resolve, reject) => {
(0, subscriptions_1.addGetSubscriber)(this.client, payload, (err, _subscriber, _subId, data) => {
if (err) {
reject(err);
}
else {
resolve(data);
}
}, 0, a);
});
}
else {
return new Promise((resolve, reject) => {
(0, request_1.addRequest)(this.client, types_1.RequestTypes.Get, a, resolve, reject);
});
}
}
file(opts) {
if (global.File && opts instanceof File) {
opts = { contents: opts };
}
// @ts-ignore
return (0, file_1.default)(this, opts);
}
call(name, payload) {
return new Promise((resolve, reject) => {
(0, request_1.addRequest)(this.client, types_1.RequestTypes.Call, payload, resolve, reject, name);
});
}
async id(type, opts) {
let prefix = (0, findPrefix_1.default)(this.client, type);
if (!prefix) {
await this.schema();
prefix = (0, findPrefix_1.default)(this.client, type);
}
if (!prefix) {
throw (0, createError_1.default)({
message: `Type does not exist ${type}`,
type: 'Invalid type',
payload: opts
? { type, opts }
: {
type,
},
});
}
if (opts) {
const optsHash = (0, hash_1.hashCompact)(opts, 8, true);
return prefix + optsHash;
}
else {
return (prefix +
(0, hash_1.hashCompact)(Math.floor(Math.random() * 99999999999) + '' + Date.now()));
}
}
digest(payload) {
return new Promise((resolve, reject) => {
(0, request_1.addRequest)(this.client, types_1.RequestTypes.Digest, payload, resolve, reject);
});
}
set(payload) {
return new Promise((resolve, reject) => {
(0, request_1.addRequest)(this.client, types_1.RequestTypes.Set, payload, resolve, reject);
});
}
copy(payload) {
return new Promise((resolve, reject) => {
(0, request_1.addRequest)(this.client, types_1.RequestTypes.Copy, payload, resolve, reject);
});
}
async gqlQuery(q, variables = {}) {
let op;
if (typeof q === 'string') {
op = this.gql(q);
}
else {
op = q;
}
try {
op = (0, graphql_1.handleGraphqlVariables)(op, op, variables);
if (op.opType === 'GET') {
const queryObj = { $db: op.db };
const fnReplies = [];
for (const key in op.ops) {
if (op.ops[key].fnObserve) {
const resp = await this.get(op.ops[key].fnObserve.name, op.ops[key].fnObserve.payload);
fnReplies.push({ key, reply: resp });
continue;
}
if (op.ops[key].get) {
queryObj[key] = op.ops[key].get;
}
}
const getResult = await this.get(queryObj);
for (const { key, reply } of fnReplies) {
getResult[key] = reply;
}
return { data: getResult };
}
const reply = {};
await Promise.all(Object.entries(op.ops).map(async ([k, o]) => {
if (o.delete) {
reply[k] = await this.delete(o.delete);
return;
}
else if (o.fnCall) {
reply[k] = await this.call(o.fnCall.name, o.fnCall.payload);
return;
}
const { id } = await this.set(o.set);
if (!o.get) {
const res = {};
res.id = id;
const type = this.client?.configuration?.schema?.[op.db]
?.prefixToTypeMapping?.[id.slice(0, 2)];
if (type) {
res.type = type;
}
reply[k] = res;
return;
}
const getOpts = (0, utils_1.deepCopy)(o.get);
getOpts.$id = id;
const getData = await this.get(getOpts);
reply[k] = getData;
}));
return { data: reply };
}
catch (e) {
return { errors: [{ message: e.message, locations: e.locations }] };
}
}
async gqlLive(q, variables = {}) {
let op;
if (typeof q === 'string') {
op = this.gql(q);
}
else {
op = q;
}
op = (0, graphql_1.handleGraphqlVariables)(op, op, variables);
if (op.opType === 'GET') {
const fns = [];
const queryObj = {};
for (const key in op.ops) {
if (op.ops[key].fnObserve) {
const { name, payload } = op.ops[key].fnObserve;
fns.push({ key, fn: { name: name, payload } });
continue;
}
queryObj[key] = op.ops[key].get;
}
if (fns?.length) {
const allObs = fns.map((fn) => {
return {
obs: new observable_1.Observable(this.client, fn.fn.name, fn.fn.payload),
key: fn.key,
};
});
const queryObs = new observable_1.Observable(this.client, {
$db: op.db,
...queryObj,
});
allObs.push({ key: '', obs: queryObs });
return new observable_1.CompoundObservable(this.client, allObs);
}
return new observable_1.Observable(this.client, { $db: op.db, data: queryObj });
}
const queryObj = {};
await Promise.all(Object.entries(op.ops).map(async ([k, op]) => {
if (op.delete) {
queryObj[k] = await this.delete(op.delete);
return;
}
else if (op.fnCall) {
queryObj[k] = await this.call(op.fnCall.name, op.fnCall.payload);
return;
}
const { id } = await this.set(op.set);
const getOpts = (0, utils_1.deepCopy)(op.get);
getOpts.$id = id;
queryObj[k] = getOpts;
}));
return new observable_1.Observable(this.client, { $db: op.db, data: queryObj });
}
analytics(opts, onData) {
return new Promise((resolve, reject) => {
if (onData) {
(0, subscriptions_1.addSubscriber)(this.client, opts, onData, (err, subscriptionId, subscriberId, _data, isAuthError) => {
if (err && !isAuthError) {
reject(err);
}
else {
const unsubscribe = () => {
(0, subscriptions_1.removeSubscriber)(this.client, subscriptionId, subscriberId);
};
resolve(unsubscribe);
}
}, (err) => console.error(err), undefined, 'analytics');
}
else {
(0, subscriptions_1.addGetSubscriber)(this.client, opts, (err, _subscriber, _subId, data) => {
if (err) {
reject(err);
}
else {
if ((0, types_1.isAnalyticsHistoryOpts)(opts)) {
resolve(data);
}
else if ((0, types_1.isAnalyticsTypesOpts)(opts)) {
resolve(data);
}
else {
resolve(data);
}
}
}, 0, 'analytics');
}
});
}
track(type, params) {
(0, track_1.default)(this.client, type, params);
}
clearAnalytics(type, params) {
(0, track_1.default)(this.client, type, params, false, false, undefined, true);
}
untrack(type, params) {
(0, track_1.default)(this.client, type, params, true);
}
event(type, params, opts) {
(0, track_1.default)(this.client, type, params, false, true, opts);
}
delete(payload) {
return new Promise((resolve, reject) => {
(0, request_1.addRequest)(this.client, types_1.RequestTypes.Delete, payload, resolve, reject);
});
}
schema() {
return new Promise((resolve, reject) => {
const resolver = (config) => {
this.client.configuration = config;
resolve(config);
};
(0, request_1.addRequest)(this.client, types_1.RequestTypes.GetConfiguration, 0, resolver, reject);
});
}
updateSchema(configuration) {
return new Promise((resolve, reject) => {
(0, request_1.addRequest)(this.client, types_1.RequestTypes.Configuration, configuration, resolve, reject);
});
}
getToken() {
return this.client.token;
}
// allow localstorage
auth(token, options) {
return new Promise((resolve) => {
this.client.auth.push(resolve);
if ((token && token !== this.client.token) ||
(token === false && this.client.token)) {
if (typeof token === 'string') {
(0, token_1.default)(this.client, token, options);
}
else {
// this is very important
// may need to add a req Id (and a timer how long it takes)
(0, token_1.default)(this.client);
}
this.emit('auth', token);
}
});
}
}
exports.Based = Based;
// auth as admin // auth as based
const addParamsToUrl = (url, params) => {
if (params) {
let firstChecked;
url += /\?/.test(url) ? '&' : '?';
for (const key in params) {
const value = params[key];
url += firstChecked ? `&${key}=${value}` : `${key}=${value}`;
firstChecked = true;
}
}
return url;
};
const based = (opts, BasedClass = Based) => {
let { env, project, org, url, key, name = '@based/hub', cluster, params, } = opts;
/*
observeSchema
*/
if (!url) {
cluster = opts.cluster = (0, get_service_1.getClusterUrl)(cluster);
url = async () => {
const { url } = await (0, get_service_1.default)({
env,
project,
org,
key,
name,
}, 0, cluster);
return addParamsToUrl(url, params);
};
}
if (url) {
const client = new BasedClass();
client.opts = opts;
client.connect(url);
return client;
}
};
exports.default = based;
//# sourceMappingURL=index.js.map
var Me=Object.create;var Q=Object.defineProperty;var Le=Object.getOwnPropertyDescriptor;var He=Object.getOwnPropertyNames,de=Object.getOwnPropertySymbols,_e=Object.getPrototypeOf,fe=Object.prototype.hasOwnProperty,ze=Object.prototype.propertyIsEnumerable;var be=(t,e,s)=>e in t?Q(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,me=(t,e)=>{for(var s in e||(e={}))fe.call(e,s)&&be(t,s,e[s]);if(de)for(var s of de(e))ze.call(e,s)&&be(t,s,e[s]);return t};var Je=(t,e)=>{for(var s in e)Q(t,s,{get:e[s],enumerable:!0})},$=(t,e,s,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of He(e))!fe.call(t,n)&&n!==s&&Q(t,n,{get:()=>e[n],enumerable:!(r=Le(e,n))||r.enumerable});return t},f=(t,e,s)=>($(t,e,"default"),s&&$(s,e,"default")),j=(t,e,s)=>(s=t!=null?Me(_e(t)):{},$(e||!t||!t.__esModule?Q(s,"default",{value:t,enumerable:!0}):s,t)),Ke=t=>$(Q({},"__esModule",{value:!0}),t);var b={};Je(b,{Based:()=>pe,BasedClient:()=>J,BasedGraphQL:()=>y.BasedGraphQL,Observable:()=>w,addGetSubscriber:()=>M,addRequest:()=>O,addSubscriber:()=>P,createGraphqlOperations:()=>y.createOperations,default:()=>at,generateSubscriptionId:()=>T,generateTrackingKey:()=>oe,handleGraphqlVariables:()=>y.handleGraphqlVariables,parseGraphql:()=>y.parseGraphql,removeSubscriber:()=>g});module.exports=Ke(b);var he=class{constructor(){this.listeners={};Object.defineProperty(this,"listeners",{enumerable:!1,writable:!0})}emit(e,s){this.listeners[e]&&this.listeners[e].forEach(r=>r(s))}on(e,s){this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(s)}removeAllListeners(){this.listeners={}}once(e,s){this.on(e,r=>{s(r),this.removeListener(e,s)})}removeListener(e,s){let r=this.listeners[e];if(r){if(!s)delete this.listeners[e];else for(let n=0,i=r.length;n<i;n++)if(r[n]===s){r.splice(n,1);break}}}},ge=he;var ye=(t,e)=>{typeof t=="function"?t().then(s=>{e(s)}):e(t)};var Se=j(require("isomorphic-ws")),R=new Map,ve;typeof window!="undefined"&&document.addEventListener("visibilitychange",function(t){clearTimeout(ve),document.hidden?ve=setTimeout(()=>{R.forEach(e=>{e(!1)})},3e4):R.forEach(e=>{e(!0)})});var Z=(t,e,s={destroy:()=>{R.delete(s)}},r=0,n=!1)=>(ye(e,i=>{setTimeout(()=>{if(s.disconnected)return;let o=!0;R.set(s,a=>{s.disconnected||(!a&&o?(console.warn("Send to background - close connection"),o=!1,t.onClose(),c.close()):!o&&a&&(R.delete(s),Z(t,e,s,0,!0)))});let c=s.ws=new Se.default(i);c.onerror=()=>{},c.onmessage=a=>t.onData(a),c.onopen=()=>{if(o){if(s.disconnected)return;r=100,n&&t.onReconnect(),t.onOpen()}},c.onclose=()=>{if(o){if(s.disconnected)return;t.onClose(),Z(t,e,s,Math.min(1250,Math.min(r+500)),!0)}}},r)}),s),ee=Z;var k=require("@based/types");var E=require("@based/types");var U=require("@based/types");var We=t=>{clearTimeout(t.idlePing),t.idlePing=setTimeout(()=>{t.connection&&t.connected&&!t.connection.disconnected&&t.connection.ws.send("1")},6e4)},N=We;var m=(t,e)=>{e[0]===U.RequestTypes.Unsubscribe||e[0]===U.RequestTypes.Subscription||e[0]===U.RequestTypes.SendSubscriptionData||e[0]===U.RequestTypes.GetSubscription?t.subscriptionQueue.push(e):t.queue.push(e),t.connected&&!t.drainInProgress&&te(t)},te=t=>{t.connected&&!t.drainInProgress&&(t.queue.length||t.subscriptionQueue.length)&&(t.drainInProgress=!0,t.drainTimeout=setTimeout(()=>{if(t.drainInProgress=!1,t.queue.length||t.subscriptionQueue.length){let e=[...t.queue,...t.subscriptionQueue];t.queue=[],t.subscriptionQueue=[],t.connection.ws.send(JSON.stringify(e)),N(t)}},0))},ke=t=>{t.drainInProgress&&(clearTimeout(t.drainTimeout),t.drainInProgress=!1)};var se=require("@saulx/hash"),T=(t,e)=>e?(0,se.hashObjectIgnoreKeyOrder)([e,t]):(0,se.hashObjectIgnoreKeyOrder)(t);var M=(t,e,s,r,n)=>{r||(r=T(e,n));let i=t.subscriptions[r],o=t.cache[r];if(i)if(i.authError)if(!t.beingAuth)s(i.authError.error,r,0);else{let c=++i.cnt;i.subscribers[c]={onInitial:s}}else if(o)s(null,r,0,o.value);else{let c=++i.cnt;i.subscribers[c]={onInitial:s}}else{i=t.subscriptions[r]={query:e,cnt:1,name:n,subscribers:{1:{onInitial:s}}};let c;for(let a=0;a<t.subscriptionQueue.length;a++){let[u,l,,p]=t.subscriptionQueue[a];(u===E.RequestTypes.Unsubscribe||u===E.RequestTypes.SendSubscriptionData)&&l===r?(t.subscriptionQueue.splice(a,1),a--):(u===E.RequestTypes.Subscription||u===E.RequestTypes.GetSubscription)&&l===r&&(c=!0,u===E.RequestTypes.Subscription&&(p!==o.checksum&&(t.subscriptionQueue[a][3]=o.checksum),t.subscriptionQueue[a][4]=2))}if(!c){let a=[E.RequestTypes.GetSubscription,r,e];o&&a.push(o.checksum),n&&(o||a.push(0),a.push(n)),m(t,a)}}};var C=require("@based/types");var P=(t,e,s,r,n,i,o)=>{i||(i=T(e,o));let c=t.subscriptions[i],a=t.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:n,onData:s,onInitial:r},l){for(let d=0;d<t.subscriptionQueue.length;d++){let[h,v]=t.subscriptionQueue[d];h===C.RequestTypes.GetSubscription&&v===i&&(t.subscriptionQueue.splice(d,1),d--)}let p=[C.RequestTypes.Subscription,i,e];a&&(p.push(a.checksum),p.push(2)),o&&(a||p.push(0,2),p.push(o)),m(t,p)}}else{u=1,c=t.subscriptions[i]={query:e,cnt:1,name:o,subscribers:{1:{onError:n,onData:s,onInitial:r}}};let l=!1,p=!1,d;for(let h=0;h<t.subscriptionQueue.length;h++){let[v,q,,G]=t.subscriptionQueue[h];(v===C.RequestTypes.Unsubscribe||v===C.RequestTypes.SendSubscriptionData||v===C.RequestTypes.GetSubscription)&&q===i?(v===C.RequestTypes.GetSubscription&&(p=!0),d&&(d[4]=2),t.subscriptionQueue.splice(h,1),h--):v===C.RequestTypes.Subscription&&q===i&&(l=!0,d=t.subscriptionQueue[h],G!==a.checksum&&(d[3]=a.checksum),!d[4]&&p&&(d[4]=2))}if(!l){let h=[C.RequestTypes.Subscription,i,e];a&&(h.push(a.checksum),p&&h.push(2)),o&&(a?!p&&a&&h.push(2):h.push(0,0),h.push(o)),m(t,h)}}return a&&(r&&(r(null,i,u),delete c.subscribers[u].onInitial),s&&s(a.value,a.checksum)),[i,u]};var x=require("@based/types");var g=(t,e,s)=>{let r=t.subscriptions[e];if(r){let n=!1;if(s?r.subscribers[s]&&(delete r.subscribers[s],r.cnt--,r.cnt===0&&(n=!0)):n=!0,n){delete t.subscriptions[e];let i=!1;for(let o=0;o<t.subscriptionQueue.length;o++){let[c,a]=t.subscriptionQueue[o];c===x.RequestTypes.Unsubscribe&&a===e?i=!0:(c===x.RequestTypes.Subscription||c===x.RequestTypes.SendSubscriptionData)&&a===e&&(t.subscriptionQueue.splice(o,1),o--)}i||m(t,[x.RequestTypes.Unsubscribe,e])}}};var Oe=require("@based/types"),Te=t=>{for(let e=0;e<t.subscriptionQueue.length;e++)t.subscriptionQueue[e][0]===Oe.RequestTypes.Unsubscribe&&(t.subscriptionQueue.splice(e,1),e--)};var Ce=require("@based/types"),we=t=>{for(let e=0;e<t.subscriptionQueue.length;e++)t.subscriptionQueue[e][0]===Ce.RequestTypes.SendSubscriptionData&&(t.subscriptionQueue.splice(e,1),e--)};var L=(t,e=!1)=>{for(let s in t.subscriptions){let r=Number(s),n=t.subscriptions[s];if(e&&!n.authError)continue;let i,o,c;for(let l=0;l<t.subscriptionQueue.length;l++){let[p,d]=t.subscriptionQueue[l];d===r&&(p===10?(c=l,i=t.subscriptionQueue[l]):p===1&&(o=t.subscriptionQueue[l]))}i&&o&&console.error("GET IN Q AND SUB IN Q SHOULD BE IMPOSSIBLE");let a=t.cache[r],u=!1;if(i){let l=!0;for(let p in n.subscribers)if(n.subscribers[p].onData){l=!1;break}l?u=!0:(console.info("not only gets remove get"),t.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}=t.subscriptions[r];l?a?m(t,[1,r,p,a.checksum,i?2:0,l]):m(t,[1,r,p,0,i?2:0,l]):a?m(t,[1,r,p,a.checksum,i?2:0]):m(t,[1,r,p,0,i?2:0])}}};var H=(t,e)=>{if(typeof window!="undefined")return t;let s={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`${s[e]}${t}${s.reset}`},re=(t,e=0,s=!1,r="",n=!1)=>{let i="";for(let a=0;a<e;a++)i+=" ";let o=s?[]:r?[i+`${H(r,n?"brightRed":"white")} {`]:[i+"{"],c=!1;s||(i+=" ",e+=1);for(let a in t){let u=t[a],l=a[0]==="$"?H(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 d=u[p];o.push(...d&&typeof d=="object"?re(d,e+4):[`${i} ${d}`]),p!==u.length-1&&(o[o.length-1]+=",")}o.push(`${i} ]`)}else u&&typeof u=="object"?(o.push(`${i} ${l}: {`),o.push(...re(u,e+2,!0)),o.push(`${i} }`)):o.push(`${i} ${l}: ${u}`);c=!0}return s||o.push(i.slice(0,-1)+"}"),o},_=re;var B=t=>{let e=new Error(t.message);if(e.name=t.name?`${t.type} from ${t.name}`:t.type,e.stack=null,t.query||t.payload){let s=e.message.split(`
`),r=0;s[0]===""&&s.shift();let n=s[0];for(let i=0;i<n.length;i++)if(n[i]!==" "){r=i-2;break}r>0?s=s.map(i=>i.slice(r)):s=s.map(i=>" "+i),t.code&&(e.code=t.code),e.message=`
`+(t.payload&&typeof t.payload!="object"?` ${H("Payload","brightRed")} ${t.payload}`:_(t.payload||t.query,0,!1,t.payload?"Payload":"Query",!0).map(i=>" "+i).join(`
`))+`
`+s.join(`
`)+`
`}return e};var Pe=(t,e)=>{let[,s,r,n,i]=e,o=t.subscriptions[s];if(o){let c=t.cache[s]&&t.cache[s].checksum;if(i){let a=B(i);i.auth&&(o.authError={token:t.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(s),Number(u),void 0,!0),delete l.onInitial):(l.onInitial(a,Number(s),Number(u)),delete l.onInitial,g(t,s,Number(u))):l.onError&&l.onError(a)}}else if(c===n){o.authError&&delete o.authError;for(let a in o.subscribers){let u=o.subscribers[a];u.onInitial&&(u.onInitial(null,Number(s),Number(a),t.cache[s].value),delete u.onInitial,u.onData||g(t,s,Number(a)))}}else{o.authError&&delete o.authError,t.cache[s]={value:r,checksum:n};for(let a in o.subscribers){let u=o.subscribers[a];u.onInitial&&(u.onInitial(null,Number(s),Number(a),r),delete u.onInitial,u.onData||g(t,s,Number(a))),u.onData&&u.onData(r,n)}}}};var Be=require("@saulx/diff"),z=require("@based/types");var qe=(t,e)=>{let[,s,r,[n,i]]=e,o=t.subscriptions[s];if(o){let c=t.cache[s];if(!c||c.checksum!==n)if(c)if(c.checksum===i)for(let a in o.subscribers){let u=o.subscribers[a];u.onInitial&&(u.onInitial(null,Number(s),Number(a),c.value),delete u.onInitial,u.onData||g(t,s,Number(a)))}else m(t,[z.RequestTypes.SendSubscriptionData,s]);else m(t,[z.RequestTypes.SendSubscriptionData,s]);else{let a=!1;try{c.value=(0,Be.applyPatch)(c.value,r),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
`),console.warn(_(o.query,2,!1,"Query").join(`
`)+`
`),delete t.cache[s],m(t,[z.RequestTypes.SendSubscriptionData,s]);else{c.checksum=i;for(let u in o.subscribers){let l=o.subscribers[u];l.onInitial&&(l.onInitial(null,Number(s),Number(u),c.value),delete l.onInitial,l.onData||g(t,s,Number(u))),l.onData&&l.onData(c.value,c.checksum)}}}}};var Ee=(t,e)=>{for(let s of e[1]){delete t.cache[s];let r=t.subscriptions[s];if(r){let n={type:"AuthorizationError",name:r.name?`observe "${r.name}"`:"observe",message:"Unauthorized request",payload:r.query,auth:!0},i=B(n);r.authError={token:t.token,error:i};for(let o in r.subscribers){let c=r.subscribers[o];c.onError&&c.onError(i)}}}};var Fe=require("@based/types");var Ve=0,O=(t,e,s,r,n,i)=>{let o=++Ve;t.requestCallbacks[o]={resolve:r,reject:n},e===Fe.RequestTypes.Call?m(t,[e,i,o,s]):m(t,[e,o,s])};var Qe=(t,e)=>{let[,s,r,n]=e,i=t.requestCallbacks[s];i&&(delete t.requestCallbacks[s],n?i.reject(B(n)):i.resolve(r))};var S=require("@based/types");var ie=require("@based/types");var Xe=t=>typeof t!="undefined"&&t!==null,Ye=(t,e,s)=>{if(t.beingAuth=!0,e)t.token=e,t.sendTokenOptions=s;else{for(let r in t.cache)t.subscriptions[r]||delete t.cache[r];delete t.token,delete t.sendTokenOptions}if(t.connected){let r=e?[ie.RequestTypes.Token,e,s].filter(Xe):[ie.RequestTypes.Token];t.connection.ws.send(JSON.stringify(r)),N(t),L(t,!0)}},D=Ye;var J=class{constructor(e){this.auth=[];this.subscriptions={};this.cache={};this.requestCallbacks={};this.connected=!1;this.subscriptionQueue=[];this.queue=[];this.drainInProgress=!1;this.based=e}onClose(){this.connected=!1,ke(this),Te(this),we(this),this.based.listeners.disconnect&&this.based.listeners.disconnect.forEach(e=>e())}onReconnect(){if(this.based.listeners.reconnect&&this.based.listeners.reconnect.forEach(e=>e()),this.tracking)for(let e of this.tracking)m(this,[S.RequestTypes.Track,{t:e}])}onOpen(){this.connected=!0,this.based.listeners.connect&&this.based.listeners.connect.forEach(e=>e()),this.token&&D(this,this.token,this.sendTokenOptions),L(this),te(this)}onData(e){try{let s=JSON.parse(e.data);if(s[0]===S.RequestTypes.Token){s[1].length&&Ee(this,s);for(let r of this.auth)r(!s[2]);this.beingAuth=!1,this.auth=[]}else s[0]===S.RequestTypes.Set||s[0]===S.RequestTypes.Get||s[0]===S.RequestTypes.Configuration||s[0]===S.RequestTypes.GetConfiguration||s[0]===S.RequestTypes.Call||s[0]===S.RequestTypes.Delete||s[0]===S.RequestTypes.Copy||s[0]===S.RequestTypes.Digest?Qe(this,s):s[0]===S.RequestTypes.Subscription?Pe(this,s):s[0]===S.RequestTypes.SubscriptionDiff&&qe(this,s)}catch(s){console.error("Received incorrect data ",e)}}};var ne=(t,e)=>{let s;if(t.configuration&&t.configuration.schema)for(let r in t.configuration.schema){let n=t.configuration.schema[r];if(n.prefixToTypeMapping){for(let i in n.prefixToTypeMapping)if(n.prefixToTypeMapping[i]===e){s=i;break}}}return s};var ue=require("@saulx/hash");var Ue=require("@based/types"),xe=require("@saulx/hash"),Re=new Set,Ze=t=>{if(typeof window!="undefined"){if(Re.has(t))return!1;Re.add(t);try{let e="_ba:"+(0,xe.hashCompact)(t);return localStorage.getItem(e)?!1:(localStorage.setItem(e,"1"),!0)}catch(e){return!1}}return!1},oe=(t,e)=>{if(e){let s=`${t}`,r=Object.keys(e).sort();for(let n of r)s+="_"+n+"_"+e[n];return s}else return t},I=(t,e,s,r,n,i,o)=>{let c=oe(e,s),a={t:c};o&&(a.r=1),n&&(a.e=1,i&&(a.o=i)),r?(a.s=1,t.tracking.delete(c)):o||(n||(t.tracking||(t.tracking=new Set),t.tracking.add(c)),Ze(c)&&(a.u=1)),m(t,[Ue.RequestTypes.Track,a])};var De=class{constructor(e,s,r){this.closed=!1;this.client=e,this.subId=r,this.subscriberId=s}unsubscribe(){this.closed=!0,g(this.client,this.subId,this.subscriberId)}},Ie=class{constructor(e,s){this.closed=!1;this.client=e,this.subs=s}unsubscribe(){if(!this.closed){this.closed=!0;for(let e of this.subs)e.unsubscribe()}}},ae=class{constructor(e,s){this.client=e,this.components=s}subscribe(e,s,r){let n={data:{}},i=[];for(let{key:o,obs:c}of this.components){let a=c.subscribe(u=>{if(o===""){Object.assign(n.data,u),e(n);return}n.data[o]=u,e(n)},s);i.push(a)}return new Ie(this.client,i)}},w=class{constructor(e,s,r){this.client=e,this.subId=typeof s=="string"?T(r,s):T(s),this.name=typeof s=="string"?s:null,this.payload=typeof s=="string"?r:s}subscribe(e,s,r){let[,n]=P(this.client,this.payload,e,i=>{i&&(console.error(i),s&&s(i))},s,this.subId,this.name);return new De(this.client,n,this.subId)}};var ce={},A={},et=(t,e)=>{ce[t]||(ce[t]=!0,setTimeout(()=>{console.info("Drain file q"),ce[t]=!1;let s=A[t];A[t]=[];let r=new global.FormData;for(let n of s){let{raw:i,name:o,id:c,file:a,functionName:u}=n,l=`${u||""}|${i?1:0}|${c}|${a.size}${o?`|${o}`:""}`;r.append(l,a)}try{let n=new global.XMLHttpRequest;n.upload.onprogress=i=>{let o=100*(i.loaded||i.position)/(i.totalSize||i.total);console.info(o,"upload...")},n.onerror=i=>{console.error("error!",i,"flap",n.responseText)},n.timeout=1e3*60*60*24,n.onabort=i=>{console.error("abort",i)},n.ontimeout=i=>{console.error("on timeout",i)},n.onload=()=>{let i={};try{i=JSON.parse(n.response),console.info("SUCCESS",i)}catch(o){console.error("something wrong with file upload",o)}},n.open("POST",t+"/file"),n.setRequestHeader("Content-Type","multipart/form-data"),n.setRequestHeader("Authorization",e),n.send(r)}catch(n){console.error("Something wrong with xhr upload",n)}},500))},Ae=async(t,e,s,r,n,i,o)=>{A[s]||(A[s]=[]),A[s].push({file:e,id:r,url:s,raw:n,name:i,functionName:o}),et(s,t.getToken())};var Ge=j(require("@based/get-service")),K={},W={},tt=async(t,e)=>{if(e.url)return typeof e.url=="string"?e.url:await e.url();if(!t.opts.env&&t.opts.url)return typeof t.opts.url=="string"?t.opts.url:await t.opts.url();let{env:s,project:r,org:n}=t.opts,i=s+"/"+r+"/"+n+"/"+t.opts.cluster;if(K[i])return K[i];if(W[i])return(await W[i]).url;let o=await(W[i]=(0,Ge.default)({env:s,project:r,org:n,name:"@based/hub",key:"file-upload",optionalKey:!0},0,t.opts.cluster));return delete W[i],setTimeout(()=>{delete K[i]},2e3),K[i]=o.url},$e=tt;var je=j(require("cross-fetch")),V=(t,e,s)=>((0,je.default)(e,{method:"POST",cache:"no-cache",headers:{"Content-Type":s.mimeType||"text/plain","File-Id":s.id,"File-Is-Raw":s.raw?"1":"0","File-Name":s.name||"","Function-Name":s.functionName||"",Authorization:t.getToken()},body:s.contents}).then(r=>{}).catch(r=>{console.error("Error while uploading file",r)}),{id:s.id});var F=require("./file/stream"),X=typeof window!="undefined",st=t=>"src"in t&&typeof t.src=="string",rt=t=>"path"in t&&typeof t.path=="string",it=t=>"contents"in t&&(0,F.isStream)(t.contents),Ne=async(t,e)=>{if(st(e)){let n=e.id?{$id:e.id}:{type:"file"};return e.src?(n.src=e.src,n.origin=e.src,e.size&&(n.size=e.size),e.name&&(n.name=e.name),e.parents&&(n.parents=e.parents),await t.set(n)):void 0}let s=e.id;if(!s){let n={type:"file",progress:0};e.name?n.name=e.name:global.File&&"contents"in e&&e.contents instanceof global.File&&(n.name=e.contents.name),e.parents&&(n.parents=e.parents),s=(await t.set(n)).id}e.id=s;let r=(await $e(t,e)).replace(/^ws/,"http");if(rt(e))return(0,F.uploadFilePath)(t,r,e),{id:s};if(it(e))return(0,F.uploadFileStream)(t,r,e),{id:s};if(e.contents instanceof ArrayBuffer)return e.contents=X?new global.Blob([e.contents],{type:e.mimeType||"text/plain"}):global.Buffer.from(e.contents),V(t,r+"/file",e);if(X&&e.contents instanceof global.Blob)return e.mimeType||(e.mimeType=e.contents.type),V(t,r+"/file",e);if(typeof e.contents=="string"||!X&&e.contents instanceof global.Buffer)return V(t,r+"/file",e);if(X&&e.contents instanceof File)return Ae(t,e.contents,r,e.id,e.raw||!1,e.name,e.functionName),{id:s};throw e.id||await t.delete({$id:s}),new Error(`Invalid contents for file api ${JSON.stringify(e,null,2)}`)};var Y=j(require("@based/get-service")),le=require("@saulx/utils"),y=require("@based/graphql");f(b,require("@based/types"),module.exports);var pe=class extends ge{constructor(e){super();this.client=new J(this),Object.defineProperty(this,"client",{enumerable:!1,writable:!0}),e&&e.url&&this.connect(e.url),this.graphql={query:this.gqlQuery.bind(this),live:this.gqlLive.bind(this)}}connect(e){!e&&this._url?this.client.connection||(this.client.connection=ee(this.client,this._url)):(this._url=e,this.client.connection=ee(this.client,e))}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(e,s,r){return new Promise((n,i)=>{let o,c=!1;this.observe(e,(a,u)=>{r&&r(a,u),s(a,u)&&(c=!0,o&&o(),n(a))}).then(a=>{c?o():o=a}).catch(a=>{i(a)})})}gql(e,...s){typeof e=="string"&&(e=[e]);let r=e[0];return s.forEach((n,i)=>{n&&n.kind==="Document"?r+=n.loc.source.body:r+=n,r+=e[i+1]}),(0,y.createOperations)({schemas:this.client.configuration.schema},(0,y.parseGraphql)(r))}gqlDb(e="default"){return(s,...r)=>{typeof s=="string"&&(s=[s]);let n=s[0];return r.forEach((i,o)=>{i&&i.kind==="Document"?n+=i.loc.source.body:n+=i,n+=s[o+1]}),(0,y.createOperations)({schemas:this.client.configuration.schema,db:e},(0,y.parseGraphql)(n))}}observe(e,s,r,n){return typeof e=="string"?new Promise((i,o)=>{let c=typeof s=="function",a=c?s:r,u=c?r:n;P(this.client,c?void 0:s,a,(l,p,d,h,v)=>{l&&!v?o(l):i(()=>{g(this.client,p,d)})},u,void 0,e)}):new Promise((i,o)=>{P(this.client,e,s,(c,a,u,l,p)=>{c&&!p?o(c):i(()=>{g(this.client,a,u)})},r)})}createObservable(e,s){return typeof e=="string"?new w(this.client,e,s):new w(this.client,e)}observeSchema(e,s,r){return new Promise((n,i)=>{let o=typeof e=="string"?e:"default",c=typeof e=="string"?s:e,a=typeof e=="string"?r:s;P(this.client,{$subscribe_schema:o},(u,l)=>{this.client.configuration||(this.client.configuration={dbs:[],schema:{},functions:{}}),this.client.configuration.schema[o]=u,c(u,l)},(u,l,p,d,h)=>{u&&!h?i(u):n(()=>{g(this.client,l,p)})},a)})}get(e,s){return typeof e=="string"?new Promise((r,n)=>{M(this.client,s,(i,o,c,a)=>{i?n(i):r(a)},0,e)}):new Promise((r,n)=>{O(this.client,k.RequestTypes.Get,e,r,n)})}file(e){return global.File&&e instanceof File&&(e={contents:e}),Ne(this,e)}call(e,s){return new Promise((r,n)=>{O(this.client,k.RequestTypes.Call,s,r,n,e)})}async id(e,s){let r=ne(this.client,e);if(r||(await this.schema(),r=ne(this.client,e)),!r)throw B({message:`Type does not exist ${e}`,type:"Invalid type",payload:s?{type:e,opts:s}:{type:e}});if(s){let n=(0,ue.hashCompact)(s,8,!0);return r+n}else return r+(0,ue.hashCompact)(Math.floor(Math.random()*99999999999)+""+Date.now())}digest(e){return new Promise((s,r)=>{O(this.client,k.RequestTypes.Digest,e,s,r)})}set(e){return new Promise((s,r)=>{O(this.client,k.RequestTypes.Set,e,s,r)})}copy(e){return new Promise((s,r)=>{O(this.client,k.RequestTypes.Copy,e,s,r)})}async gqlQuery(e,s={}){let r;typeof e=="string"?r=this.gql(e):r=e;try{if(r=(0,y.handleGraphqlVariables)(r,r,s),r.opType==="GET"){let i={$db:r.db},o=[];for(let a in r.ops){if(r.ops[a].fnObserve){let u=await this.get(r.ops[a].fnObserve.name,r.ops[a].fnObserve.payload);o.push({key:a,reply:u});continue}r.ops[a].get&&(i[a]=r.ops[a].get)}let c=await this.get(i);for(let{key:a,reply:u}of o)c[a]=u;return{data:c}}let n={};return await Promise.all(Object.entries(r.ops).map(async([i,o])=>{var l,p,d,h,v;if(o.delete){n[i]=await this.delete(o.delete);return}else if(o.fnCall){n[i]=await this.call(o.fnCall.name,o.fnCall.payload);return}let{id:c}=await this.set(o.set);if(!o.get){let q={};q.id=c;let G=(v=(h=(d=(p=(l=this.client)==null?void 0:l.configuration)==null?void 0:p.schema)==null?void 0:d[r.db])==null?void 0:h.prefixToTypeMapping)==null?void 0:v[c.slice(0,2)];G&&(q.type=G),n[i]=q;return}let a=(0,le.deepCopy)(o.get);a.$id=c;let u=await this.get(a);n[i]=u})),{data:n}}catch(n){return{errors:[{message:n.message,locations:n.locations}]}}}async gqlLive(e,s={}){let r;if(typeof e=="string"?r=this.gql(e):r=e,r=(0,y.handleGraphqlVariables)(r,r,s),r.opType==="GET"){let i=[],o={};for(let c in r.ops){if(r.ops[c].fnObserve){let{name:a,payload:u}=r.ops[c].fnObserve;i.push({key:c,fn:{name:a,payload:u}});continue}o[c]=r.ops[c].get}if(i!=null&&i.length){let c=i.map(u=>({obs:new w(this.client,u.fn.name,u.fn.payload),key:u.key})),a=new w(this.client,me({$db:r.db},o));return c.push({key:"",obs:a}),new ae(this.client,c)}return new w(this.client,{$db:r.db,data:o})}let n={};return await Promise.all(Object.entries(r.ops).map(async([i,o])=>{if(o.delete){n[i]=await this.delete(o.delete);return}else if(o.fnCall){n[i]=await this.call(o.fnCall.name,o.fnCall.payload);return}let{id:c}=await this.set(o.set),a=(0,le.deepCopy)(o.get);a.$id=c,n[i]=a})),new w(this.client,{$db:r.db,data:n})}analytics(e,s){return new Promise((r,n)=>{s?P(this.client,e,s,(i,o,c,a,u)=>{i&&!u?n(i):r(()=>{g(this.client,o,c)})},i=>console.error(i),void 0,"analytics"):M(this.client,e,(i,o,c,a)=>{i?n(i):((0,k.isAnalyticsHistoryOpts)(e)||(0,k.isAnalyticsTypesOpts)(e),r(a))},0,"analytics")})}track(e,s){I(this.client,e,s)}clearAnalytics(e,s){I(this.client,e,s,!1,!1,void 0,!0)}untrack(e,s){I(this.client,e,s,!0)}event(e,s,r){I(this.client,e,s,!1,!0,r)}delete(e){return new Promise((s,r)=>{O(this.client,k.RequestTypes.Delete,e,s,r)})}schema(){return new Promise((e,s)=>{let r=n=>{this.client.configuration=n,e(n)};O(this.client,k.RequestTypes.GetConfiguration,0,r,s)})}updateSchema(e){return new Promise((s,r)=>{O(this.client,k.RequestTypes.Configuration,e,s,r)})}getToken(){return this.client.token}auth(e,s){return new Promise(r=>{this.client.auth.push(r),(e&&e!==this.client.token||e===!1&&this.client.token)&&(typeof e=="string"?D(this.client,e,s):D(this.client),this.emit("auth",e))})}},nt=(t,e)=>{if(e){let s;t+=/\?/.test(t)?"&":"?";for(let r in e){let n=e[r];t+=s?`&${r}=${n}`:`${r}=${n}`,s=!0}}return t},ot=(t,e=pe)=>{let{env:s,project:r,org:n,url:i,key:o,name:c="@based/hub",cluster:a,params:u}=t;if(i||(a=t.cluster=(0,Y.getClusterUrl)(a),i=async()=>{let{url:l}=await(0,Y.default)({env:s,project:r,org:n,key:o,name:c},0,a);return nt(l,u)}),i){let l=new e;return l.opts=t,l.connect(i),l}},at=ot;0&&(module.exports={Based,BasedClient,BasedGraphQL,Observable,addGetSubscriber,addRequest,addSubscriber,createGraphqlOperations,generateSubscriptionId,generateTrackingKey,handleGraphqlVariables,parseGraphql,removeSubscriber});
{
"name": "@based/client",
"version": "1.2.4",
"main": "dist/bundle.js",
"version": "1.2.5",
"main": "dist/index.js",
"browser": {

@@ -6,0 +6,0 @@ "./dist/file/stream/index.js": "./dist/file/stream/browser.js"

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