@graffy/client 0.15.8-alpha.2 → 0.15.8-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +1 -0
- package/index.d.ts +29 -0
- package/index.mjs +1 -0
- package/package.json +11 -7
- package/cjs/Socket.js +0 -192
- package/cjs/httpClient.js +0 -352
- package/cjs/index.js +0 -22
- package/cjs/wsClient.js +0 -98
- package/types/Socket.d.ts +0 -8
- package/types/httpClient.d.ts +0 -6
- package/types/index.d.ts +0 -1
- package/types/wsClient.d.ts +0 -6
package/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=Object.defineProperty,t=(t,n,o)=>(((t,n,o)=>{n in t?e(t,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[n]=o})(t,"symbol"!=typeof n?n+"":n,o),o),n=require("@graffy/common"),o=require("@graffy/stream");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=r(require("debug"));function a(e){return e?encodeURIComponent(n.serialize(e)):""}const i={};class c{constructor(e){t(this,"combinedQuery",[]),t(this,"readers",[]),t(this,"timer",null),this.url=e}add(e){return n.add(this.combinedQuery,e),this.timer&&clearTimeout(this.timer),this.timer=setTimeout((()=>this.doFetch()),0),new Promise(((t,n)=>{this.readers.push({query:e,resolve:t,reject:n})}))}async doFetch(){delete i[this.url];const e=await fetch(this.url,{method:"POST",headers:{"Content-Type":"application/json"},body:n.serialize(this.combinedQuery)});if(200!==e.status){const t=await e.text(),n=new Error(t);for(const e of this.readers)e.reject(n);return}const t=await e.json();for(const n of this.readers)n.resolve(t)}}const u=(e,{getOptions:t=(async()=>{}),watch:r,connInfoPath:s="connection"}={})=>u=>{u.onWrite(s,(({url:t})=>(e=t,{url:t}))),u.onRead(s,(()=>({url:e}))),u.on("read",(async(n,o)=>{if(!fetch)throw Error("client.fetch.unavailable");const r=a(await t("read",o));return function(e,t){return i[e]||(i[e]=new c(e)),i[e].add(t)}(`${e}?opts=${r}&op=read`,n)})),u.on("watch",(async function*(s,i){if("none"===r)throw Error("client.no_watch");if("hang"===r)return void(yield*o.makeStream((e=>{e(void 0)})));if(!EventSource)throw Error("client.sse.unavailable");const c=a(await t("watch",i)),u=`${e}?q=${n.encodeUrl(s)}&opts=${c}`,l=new EventSource(u);yield*o.makeStream(((e,t)=>(l.onmessage=({data:t})=>{e(n.deserialize(t))},l.onerror=e=>{t(Error("client.sse.transport: "+e.message))},l.addEventListener("graffyerror",(e=>{t(Error("server."+e.data))})),()=>{l.close()})))})),u.on("write",(async(o,r)=>{if(!fetch)throw Error("client.fetch.unavailable");const s=a(await t("write",r));return fetch(`${e}?opts=${s}&op=write`,{method:"POST",headers:{"Content-Type":"application/json"},body:n.serialize(o)}).then((e=>200===e.status?e.json():e.text().then((e=>{throw Error("server."+e)}))))}))},l=s.default("graffy:client:socket");l.log=console.log.bind(console);function h(e,{onUnhandled:t,onStatusChange:o}={}){const r={},s=[];let a,i,c,u,h,d=!1,f=!1,w=0;function m(){l("Trying to connect to",e),d=!1,f=!0,c=Date.now(),w++,a=new WebSocket(e),a.onmessage=p,a.onerror=y,a.onclose=y,a.onopen=v}function p(e){const[o,...s]=n.deserialize(e.data);g(),":ping"===o?k([":pong"]):r[o]?r[o].callback(...s):t&&t(o,...s)}function y(e){l("Closed"),d&&o&&o(!1);const t=d;d=!1,f=!1,c=Date.now(),!t||w?b():m()}function b(){const e=c+Math.min(3e5,1e3*Math.pow(1.5,w))-Date.now();l("Will reconnect in",e,"ms"),e<=0?m():(clearTimeout(u),u=setTimeout(m,e))}function v(){l("Connected",s.length,Object.keys(r).length),d=!0,f=!1,c=Date.now(),g(),o&&o(!0);for(const e in r)k(r[e].request);for(;s.length;)k(s.shift())}function g(){i=Date.now(),l("Set alive",i-c),i-c>1e4&&(w=0)}function E(){return l("Liveness check",d?"open":"closed",Date.now()-i),clearTimeout(h),h=setTimeout(E,2e3),d?Date.now()-i<4e4||(a.close(),!1):(f||b(),!1)}function k(e){E()?a.send(n.serialize(e)):s.push(e)}return m(),h=setTimeout(E,2e3),{start:function(e,t){const o=n.makeId(),s=[o,...e];return r[o]={request:s,callback:t},E()&&k(s),o},stop:function(e,t){delete r[e],t&&k([e,...t])},isAlive:E}}const d=/^wss?:\/\//;module.exports=function(e,t){return d.test(e)?((e,{getOptions:t=(()=>{}),watch:r,connInfoPath:s="connection"}={})=>a=>{if(!WebSocket)throw Error("client.websocket.unavailable");const i=new h(e,{onUnhandled:function(e){i.stop(e,["unwatch"])},onStatusChange:function(e){c=e,u.write({status:c})}});let c=!1;const u=n.makeWatcher();function l(e,n,o){return new Promise(((r,s)=>{const a=i.start([e,n,t(e,o)||{}],((e,t)=>{i.stop(a),e?s(Error("server."+e)):r(t)}))}))}a.onWrite(s,(()=>(c=i.isAlive(),{status:c}))),a.onRead(s,(()=>({status:c}))),a.onWatch(s,(()=>u.watch({status:c}))),a.on("read",((e,t)=>l("read",e,t))),a.on("write",((e,t)=>l("write",e,t))),a.on("watch",((e,n)=>{if("none"===r)throw Error("client.no_watch");const s="watch";return o.makeStream(((o,r)=>{const a=i.start([s,e,t(s,n)||{}],((e,t)=>{if(e)return i.stop(a),void r(Error("server."+e));o(t)}));return()=>{i.stop(a,["unwatch"])}}))}))})(e,t):u(e,t)};
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
declare module "httpClient" {
|
|
2
|
+
export default httpClient;
|
|
3
|
+
function httpClient(baseUrl: any, { getOptions, watch, connInfoPath }?: {
|
|
4
|
+
getOptions?: () => Promise<void>;
|
|
5
|
+
watch: any;
|
|
6
|
+
connInfoPath?: string;
|
|
7
|
+
}): (store: any) => void;
|
|
8
|
+
}
|
|
9
|
+
declare module "Socket" {
|
|
10
|
+
export default function Socket(url: any, { onUnhandled, onStatusChange }?: {
|
|
11
|
+
onUnhandled: any;
|
|
12
|
+
onStatusChange: any;
|
|
13
|
+
}): {
|
|
14
|
+
start: (params: any, callback: any) => any;
|
|
15
|
+
stop: (id: any, params: any) => void;
|
|
16
|
+
isAlive: () => boolean;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
declare module "wsClient" {
|
|
20
|
+
export default wsClient;
|
|
21
|
+
function wsClient(url: any, { getOptions, watch, connInfoPath }?: {
|
|
22
|
+
getOptions?: () => void;
|
|
23
|
+
watch: any;
|
|
24
|
+
connInfoPath?: string;
|
|
25
|
+
}): (store: any) => void;
|
|
26
|
+
}
|
|
27
|
+
declare module "index" {
|
|
28
|
+
export default function GraffyClient(baseUrl: any, options: any): (store: any) => void;
|
|
29
|
+
}
|
package/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t=Object.defineProperty,e=(e,n,o)=>(((e,n,o)=>{n in e?t(e,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[n]=o})(e,"symbol"!=typeof n?n+"":n,o),o);import{encodeUrl as n,deserialize as o,serialize as r,add as s,makeId as c,makeWatcher as a}from"@graffy/common";import{makeStream as i}from"@graffy/stream";import u from"debug";function l(t){return t?encodeURIComponent(r(t)):""}const h={};class f{constructor(t){e(this,"combinedQuery",[]),e(this,"readers",[]),e(this,"timer",null),this.url=t}add(t){return s(this.combinedQuery,t),this.timer&&clearTimeout(this.timer),this.timer=setTimeout((()=>this.doFetch()),0),new Promise(((e,n)=>{this.readers.push({query:t,resolve:e,reject:n})}))}async doFetch(){delete h[this.url];const t=await fetch(this.url,{method:"POST",headers:{"Content-Type":"application/json"},body:r(this.combinedQuery)});if(200!==t.status){const e=await t.text(),n=new Error(e);for(const t of this.readers)t.reject(n);return}const e=await t.json();for(const n of this.readers)n.resolve(e)}}const d=(t,{getOptions:e=(async()=>{}),watch:s,connInfoPath:c="connection"}={})=>a=>{a.onWrite(c,(({url:e})=>(t=e,{url:e}))),a.onRead(c,(()=>({url:t}))),a.on("read",(async(n,o)=>{if(!fetch)throw Error("client.fetch.unavailable");const r=l(await e("read",o));return function(t,e){return h[t]||(h[t]=new f(t)),h[t].add(e)}(`${t}?opts=${r}&op=read`,n)})),a.on("watch",(async function*(r,c){if("none"===s)throw Error("client.no_watch");if("hang"===s)return void(yield*i((t=>{t(void 0)})));if(!EventSource)throw Error("client.sse.unavailable");const a=l(await e("watch",c)),u=`${t}?q=${n(r)}&opts=${a}`,h=new EventSource(u);yield*i(((t,e)=>(h.onmessage=({data:e})=>{t(o(e))},h.onerror=t=>{e(Error("client.sse.transport: "+t.message))},h.addEventListener("graffyerror",(t=>{e(Error("server."+t.data))})),()=>{h.close()})))})),a.on("write",(async(n,o)=>{if(!fetch)throw Error("client.fetch.unavailable");const s=l(await e("write",o));return fetch(`${t}?opts=${s}&op=write`,{method:"POST",headers:{"Content-Type":"application/json"},body:r(n)}).then((t=>200===t.status?t.json():t.text().then((t=>{throw Error("server."+t)}))))}))},w=u("graffy:client:socket");w.log=console.log.bind(console);function m(t,{onUnhandled:e,onStatusChange:n}={}){const s={},a=[];let i,u,l,h,f,d=!1,m=!1,p=0;function y(){w("Trying to connect to",t),d=!1,m=!0,l=Date.now(),p++,i=new WebSocket(t),i.onmessage=b,i.onerror=g,i.onclose=g,i.onopen=E}function b(t){const[n,...r]=o(t.data);T(),":ping"===n?j([":pong"]):s[n]?s[n].callback(...r):e&&e(n,...r)}function g(t){w("Closed"),d&&n&&n(!1);const e=d;d=!1,m=!1,l=Date.now(),!e||p?v():y()}function v(){const t=l+Math.min(3e5,1e3*Math.pow(1.5,p))-Date.now();w("Will reconnect in",t,"ms"),t<=0?y():(clearTimeout(h),h=setTimeout(y,t))}function E(){w("Connected",a.length,Object.keys(s).length),d=!0,m=!1,l=Date.now(),T(),n&&n(!0);for(const t in s)j(s[t].request);for(;a.length;)j(a.shift())}function T(){u=Date.now(),w("Set alive",u-l),u-l>1e4&&(p=0)}function S(){return w("Liveness check",d?"open":"closed",Date.now()-u),clearTimeout(f),f=setTimeout(S,2e3),d?Date.now()-u<4e4||(i.close(),!1):(m||v(),!1)}function j(t){S()?i.send(r(t)):a.push(t)}return y(),f=setTimeout(S,2e3),{start:function(t,e){const n=c(),o=[n,...t];return s[n]={request:o,callback:e},S()&&j(o),n},stop:function(t,e){delete s[t],e&&j([t,...e])},isAlive:S}}const p=/^wss?:\/\//;function y(t,e){return p.test(t)?((t,{getOptions:e=(()=>{}),watch:n,connInfoPath:o="connection"}={})=>r=>{if(!WebSocket)throw Error("client.websocket.unavailable");const s=new m(t,{onUnhandled:function(t){s.stop(t,["unwatch"])},onStatusChange:function(t){c=t,u.write({status:c})}});let c=!1;const u=a();function l(t,n,o){return new Promise(((r,c)=>{const a=s.start([t,n,e(t,o)||{}],((t,e)=>{s.stop(a),t?c(Error("server."+t)):r(e)}))}))}r.onWrite(o,(()=>(c=s.isAlive(),{status:c}))),r.onRead(o,(()=>({status:c}))),r.onWatch(o,(()=>u.watch({status:c}))),r.on("read",((t,e)=>l("read",t,e))),r.on("write",((t,e)=>l("write",t,e))),r.on("watch",((t,o)=>{if("none"===n)throw Error("client.no_watch");const r="watch";return i(((n,c)=>{const a=s.start([r,t,e(r,o)||{}],((t,e)=>{if(t)return s.stop(a),void c(Error("server."+t));n(e)}));return()=>{s.stop(a,["unwatch"])}}))}))})(t,e):d(t,e)}export{y as default};
|
package/package.json
CHANGED
|
@@ -2,18 +2,22 @@
|
|
|
2
2
|
"name": "@graffy/client",
|
|
3
3
|
"description": "Graffy client library for the browser.",
|
|
4
4
|
"author": "aravind (https://github.com/aravindet)",
|
|
5
|
-
"version": "0.15.8-alpha.
|
|
6
|
-
"main": "./
|
|
7
|
-
"
|
|
5
|
+
"version": "0.15.8-alpha.3",
|
|
6
|
+
"main": "./index.cjs",
|
|
7
|
+
"exports": {
|
|
8
|
+
"import": "./index.mjs",
|
|
9
|
+
"require": "./index.cjs"
|
|
10
|
+
},
|
|
11
|
+
"module": "./index.mjs",
|
|
12
|
+
"types": "./index.d.ts",
|
|
8
13
|
"repository": {
|
|
9
14
|
"type": "git",
|
|
10
15
|
"url": "git+https://github.com/usegraffy/graffy.git"
|
|
11
16
|
},
|
|
12
17
|
"license": "Apache-2.0",
|
|
13
18
|
"dependencies": {
|
|
14
|
-
"@
|
|
15
|
-
"@graffy/
|
|
16
|
-
"debug": "^4.3.2"
|
|
17
|
-
"@graffy/stream": "0.15.8-alpha.2"
|
|
19
|
+
"@graffy/common": "0.15.8-alpha.3",
|
|
20
|
+
"@graffy/stream": "0.15.8-alpha.3",
|
|
21
|
+
"debug": "^4.3.2"
|
|
18
22
|
}
|
|
19
23
|
}
|
package/cjs/Socket.js
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
exports.__esModule = true;
|
|
6
|
-
exports.default = Socket;
|
|
7
|
-
|
|
8
|
-
var _bind = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/bind"));
|
|
9
|
-
|
|
10
|
-
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
|
11
|
-
|
|
12
|
-
var _now = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/date/now"));
|
|
13
|
-
|
|
14
|
-
var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice"));
|
|
15
|
-
|
|
16
|
-
var _setTimeout2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/set-timeout"));
|
|
17
|
-
|
|
18
|
-
var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/keys"));
|
|
19
|
-
|
|
20
|
-
var _common = require("@graffy/common");
|
|
21
|
-
|
|
22
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
23
|
-
|
|
24
|
-
var _context;
|
|
25
|
-
|
|
26
|
-
var log = (0, _debug.default)('graffy:client:socket'); // eslint-disable-next-line no-console
|
|
27
|
-
|
|
28
|
-
log.log = (0, _bind.default)(_context = console.log).call(_context, console);
|
|
29
|
-
var MIN_DELAY = 1000;
|
|
30
|
-
var MAX_DELAY = 300000;
|
|
31
|
-
var DELAY_GROWTH = 1.5;
|
|
32
|
-
var INTERVAL = 2000;
|
|
33
|
-
var PING_TIMEOUT = 40000; // Make this greater than server interval.
|
|
34
|
-
|
|
35
|
-
var RESET_TIMEOUT = 10000;
|
|
36
|
-
|
|
37
|
-
function Socket(url, _temp) {
|
|
38
|
-
var _ref = _temp === void 0 ? {} : _temp,
|
|
39
|
-
onUnhandled = _ref.onUnhandled,
|
|
40
|
-
onStatusChange = _ref.onStatusChange;
|
|
41
|
-
|
|
42
|
-
var handlers = {};
|
|
43
|
-
var buffer = [];
|
|
44
|
-
var isOpen = false;
|
|
45
|
-
var isConnecting = false;
|
|
46
|
-
var socket;
|
|
47
|
-
var lastAlive;
|
|
48
|
-
var lastAttempt;
|
|
49
|
-
var attempts = 0;
|
|
50
|
-
var connectTimer;
|
|
51
|
-
var aliveTimer;
|
|
52
|
-
|
|
53
|
-
function start(params, callback) {
|
|
54
|
-
var _context2;
|
|
55
|
-
|
|
56
|
-
var id = (0, _common.makeId)();
|
|
57
|
-
var request = (0, _concat.default)(_context2 = [id]).call(_context2, params);
|
|
58
|
-
handlers[id] = {
|
|
59
|
-
request: request,
|
|
60
|
-
callback: callback
|
|
61
|
-
};
|
|
62
|
-
if (isAlive()) send(request);
|
|
63
|
-
return id;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function stop(id, params) {
|
|
67
|
-
var _context3;
|
|
68
|
-
|
|
69
|
-
delete handlers[id];
|
|
70
|
-
if (params) send((0, _concat.default)(_context3 = [id]).call(_context3, params));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function connect() {
|
|
74
|
-
log('Trying to connect to', url);
|
|
75
|
-
isOpen = false;
|
|
76
|
-
isConnecting = true;
|
|
77
|
-
lastAttempt = (0, _now.default)();
|
|
78
|
-
attempts++;
|
|
79
|
-
socket = new WebSocket(url);
|
|
80
|
-
socket.onmessage = received;
|
|
81
|
-
socket.onerror = closed;
|
|
82
|
-
socket.onclose = closed;
|
|
83
|
-
socket.onopen = opened;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function received(event) {
|
|
87
|
-
var _deserialize = (0, _common.deserialize)(event.data),
|
|
88
|
-
id = _deserialize[0],
|
|
89
|
-
data = (0, _slice.default)(_deserialize).call(_deserialize, 1);
|
|
90
|
-
|
|
91
|
-
setAlive();
|
|
92
|
-
|
|
93
|
-
if (id === ':ping') {
|
|
94
|
-
send([':pong']);
|
|
95
|
-
} else if (handlers[id]) {
|
|
96
|
-
var _handlers$id;
|
|
97
|
-
|
|
98
|
-
(_handlers$id = handlers[id]).callback.apply(_handlers$id, data);
|
|
99
|
-
} else {
|
|
100
|
-
var _context4;
|
|
101
|
-
|
|
102
|
-
// We received an unexpected push.
|
|
103
|
-
onUnhandled && onUnhandled.apply(void 0, (0, _concat.default)(_context4 = [id]).call(_context4, data));
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function closed(_event) {
|
|
108
|
-
log('Closed');
|
|
109
|
-
if (isOpen && onStatusChange) onStatusChange(false);
|
|
110
|
-
var wasOpen = isOpen;
|
|
111
|
-
isOpen = false;
|
|
112
|
-
isConnecting = false;
|
|
113
|
-
lastAttempt = (0, _now.default)();
|
|
114
|
-
|
|
115
|
-
if (wasOpen && !attempts) {
|
|
116
|
-
// Quick reconnect path if we previously had a stable connection.
|
|
117
|
-
connect();
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
maybeConnect();
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function maybeConnect() {
|
|
125
|
-
var connDelay = lastAttempt + Math.min(MAX_DELAY, MIN_DELAY * Math.pow(DELAY_GROWTH, attempts)) - (0, _now.default)();
|
|
126
|
-
log('Will reconnect in', connDelay, 'ms');
|
|
127
|
-
|
|
128
|
-
if (connDelay <= 0) {
|
|
129
|
-
connect();
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
clearTimeout(connectTimer);
|
|
134
|
-
connectTimer = (0, _setTimeout2.default)(connect, connDelay);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function opened() {
|
|
138
|
-
log('Connected', buffer.length, (0, _keys.default)(handlers).length);
|
|
139
|
-
isOpen = true;
|
|
140
|
-
isConnecting = false;
|
|
141
|
-
lastAttempt = (0, _now.default)();
|
|
142
|
-
setAlive();
|
|
143
|
-
if (onStatusChange) onStatusChange(true);
|
|
144
|
-
|
|
145
|
-
for (var id in handlers) {
|
|
146
|
-
send(handlers[id].request);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
while (buffer.length) {
|
|
150
|
-
send(buffer.shift());
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function setAlive() {
|
|
155
|
-
lastAlive = (0, _now.default)();
|
|
156
|
-
log('Set alive', lastAlive - lastAttempt);
|
|
157
|
-
if (lastAlive - lastAttempt > RESET_TIMEOUT) attempts = 0;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function isAlive() {
|
|
161
|
-
log('Liveness check', isOpen ? 'open' : 'closed', (0, _now.default)() - lastAlive);
|
|
162
|
-
clearTimeout(aliveTimer);
|
|
163
|
-
aliveTimer = (0, _setTimeout2.default)(isAlive, INTERVAL);
|
|
164
|
-
|
|
165
|
-
if (!isOpen) {
|
|
166
|
-
if (!isConnecting) maybeConnect();
|
|
167
|
-
return false;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if ((0, _now.default)() - lastAlive < PING_TIMEOUT) return true;
|
|
171
|
-
socket.close();
|
|
172
|
-
return false;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function send(req) {
|
|
176
|
-
if (isAlive()) {
|
|
177
|
-
socket.send((0, _common.serialize)(req));
|
|
178
|
-
} else {
|
|
179
|
-
buffer.push(req);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
connect();
|
|
184
|
-
aliveTimer = (0, _setTimeout2.default)(isAlive, INTERVAL);
|
|
185
|
-
return {
|
|
186
|
-
start: start,
|
|
187
|
-
stop: stop,
|
|
188
|
-
isAlive: isAlive
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
module.exports = exports.default;
|
package/cjs/httpClient.js
DELETED
|
@@ -1,352 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _sliceInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/slice");
|
|
4
|
-
|
|
5
|
-
var _Array$from = require("@babel/runtime-corejs3/core-js-stable/array/from");
|
|
6
|
-
|
|
7
|
-
var _Symbol = require("@babel/runtime-corejs3/core-js-stable/symbol");
|
|
8
|
-
|
|
9
|
-
var _getIteratorMethod = require("@babel/runtime-corejs3/core-js/get-iterator-method");
|
|
10
|
-
|
|
11
|
-
var _bindInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/bind");
|
|
12
|
-
|
|
13
|
-
var _Array$isArray = require("@babel/runtime-corejs3/core-js-stable/array/is-array");
|
|
14
|
-
|
|
15
|
-
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
16
|
-
|
|
17
|
-
exports.__esModule = true;
|
|
18
|
-
exports.default = void 0;
|
|
19
|
-
|
|
20
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs3/regenerator"));
|
|
21
|
-
|
|
22
|
-
var _setTimeout2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/set-timeout"));
|
|
23
|
-
|
|
24
|
-
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
25
|
-
|
|
26
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));
|
|
27
|
-
|
|
28
|
-
var _wrapAsyncGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/wrapAsyncGenerator"));
|
|
29
|
-
|
|
30
|
-
var _awaitAsyncGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/awaitAsyncGenerator"));
|
|
31
|
-
|
|
32
|
-
var _asyncIterator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncIterator"));
|
|
33
|
-
|
|
34
|
-
var _asyncGeneratorDelegate2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncGeneratorDelegate"));
|
|
35
|
-
|
|
36
|
-
var _common = require("@graffy/common");
|
|
37
|
-
|
|
38
|
-
var _stream = require("@graffy/stream");
|
|
39
|
-
|
|
40
|
-
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var _context7; var it = typeof _Symbol !== "undefined" && _getIteratorMethod(o) || o["@@iterator"]; if (it) return _bindInstanceProperty(_context7 = (it = it.call(o)).next).call(_context7, it); if (_Array$isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
41
|
-
|
|
42
|
-
function _unsupportedIterableToArray(o, minLen) { var _context6; if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = _sliceInstanceProperty(_context6 = Object.prototype.toString.call(o)).call(_context6, 8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return _Array$from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
43
|
-
|
|
44
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
45
|
-
|
|
46
|
-
function getOptionsParam(options) {
|
|
47
|
-
if (!options) return '';
|
|
48
|
-
return encodeURIComponent((0, _common.serialize)(options));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
var aggregateQueries = {};
|
|
52
|
-
|
|
53
|
-
var AggregateQuery = /*#__PURE__*/function () {
|
|
54
|
-
function AggregateQuery(url) {
|
|
55
|
-
this.combinedQuery = [];
|
|
56
|
-
this.readers = [];
|
|
57
|
-
this.timer = null;
|
|
58
|
-
this.url = url;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
var _proto = AggregateQuery.prototype;
|
|
62
|
-
|
|
63
|
-
_proto.add = function add(query) {
|
|
64
|
-
var _this = this;
|
|
65
|
-
|
|
66
|
-
(0, _common.add)(this.combinedQuery, query);
|
|
67
|
-
if (this.timer) clearTimeout(this.timer);
|
|
68
|
-
this.timer = (0, _setTimeout2.default)(function () {
|
|
69
|
-
return _this.doFetch();
|
|
70
|
-
}, 0);
|
|
71
|
-
return new _promise.default(function (resolve, reject) {
|
|
72
|
-
_this.readers.push({
|
|
73
|
-
query: query,
|
|
74
|
-
resolve: resolve,
|
|
75
|
-
reject: reject
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
_proto.doFetch = /*#__PURE__*/function () {
|
|
81
|
-
var _doFetch = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
82
|
-
var response, message, err, _iterator, _step, reader, data, _iterator2, _step2, _reader;
|
|
83
|
-
|
|
84
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
85
|
-
while (1) {
|
|
86
|
-
switch (_context.prev = _context.next) {
|
|
87
|
-
case 0:
|
|
88
|
-
delete aggregateQueries[this.url];
|
|
89
|
-
_context.next = 3;
|
|
90
|
-
return fetch(this.url, {
|
|
91
|
-
method: 'POST',
|
|
92
|
-
headers: {
|
|
93
|
-
'Content-Type': 'application/json'
|
|
94
|
-
},
|
|
95
|
-
body: (0, _common.serialize)(this.combinedQuery)
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
case 3:
|
|
99
|
-
response = _context.sent;
|
|
100
|
-
|
|
101
|
-
if (!(response.status !== 200)) {
|
|
102
|
-
_context.next = 11;
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
_context.next = 7;
|
|
107
|
-
return response.text();
|
|
108
|
-
|
|
109
|
-
case 7:
|
|
110
|
-
message = _context.sent;
|
|
111
|
-
err = new Error(message);
|
|
112
|
-
|
|
113
|
-
for (_iterator = _createForOfIteratorHelperLoose(this.readers); !(_step = _iterator()).done;) {
|
|
114
|
-
reader = _step.value;
|
|
115
|
-
reader.reject(err);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return _context.abrupt("return");
|
|
119
|
-
|
|
120
|
-
case 11:
|
|
121
|
-
_context.next = 13;
|
|
122
|
-
return response.json();
|
|
123
|
-
|
|
124
|
-
case 13:
|
|
125
|
-
data = _context.sent;
|
|
126
|
-
|
|
127
|
-
for (_iterator2 = _createForOfIteratorHelperLoose(this.readers); !(_step2 = _iterator2()).done;) {
|
|
128
|
-
_reader = _step2.value;
|
|
129
|
-
|
|
130
|
-
_reader.resolve(data);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
case 15:
|
|
134
|
-
case "end":
|
|
135
|
-
return _context.stop();
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}, _callee, this);
|
|
139
|
-
}));
|
|
140
|
-
|
|
141
|
-
function doFetch() {
|
|
142
|
-
return _doFetch.apply(this, arguments);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return doFetch;
|
|
146
|
-
}();
|
|
147
|
-
|
|
148
|
-
return AggregateQuery;
|
|
149
|
-
}();
|
|
150
|
-
|
|
151
|
-
function makeQuery(url, query) {
|
|
152
|
-
if (!aggregateQueries[url]) aggregateQueries[url] = new AggregateQuery(url);
|
|
153
|
-
return aggregateQueries[url].add(query);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
var httpClient = function httpClient(baseUrl, _temp) {
|
|
157
|
-
var _ref2 = _temp === void 0 ? {} : _temp,
|
|
158
|
-
_ref2$getOptions = _ref2.getOptions,
|
|
159
|
-
getOptions = _ref2$getOptions === void 0 ? /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
|
|
160
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
161
|
-
while (1) {
|
|
162
|
-
switch (_context2.prev = _context2.next) {
|
|
163
|
-
case 0:
|
|
164
|
-
case "end":
|
|
165
|
-
return _context2.stop();
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}, _callee2);
|
|
169
|
-
})) : _ref2$getOptions,
|
|
170
|
-
watch = _ref2.watch,
|
|
171
|
-
_ref2$connInfoPath = _ref2.connInfoPath,
|
|
172
|
-
connInfoPath = _ref2$connInfoPath === void 0 ? 'connection' : _ref2$connInfoPath;
|
|
173
|
-
|
|
174
|
-
return function (store) {
|
|
175
|
-
store.onWrite(connInfoPath, function (_ref4) {
|
|
176
|
-
var url = _ref4.url;
|
|
177
|
-
baseUrl = url;
|
|
178
|
-
return {
|
|
179
|
-
url: url
|
|
180
|
-
};
|
|
181
|
-
});
|
|
182
|
-
store.onRead(connInfoPath, function () {
|
|
183
|
-
return {
|
|
184
|
-
url: baseUrl
|
|
185
|
-
};
|
|
186
|
-
});
|
|
187
|
-
store.on('read', /*#__PURE__*/function () {
|
|
188
|
-
var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(query, options) {
|
|
189
|
-
var optionsParam, url;
|
|
190
|
-
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
191
|
-
while (1) {
|
|
192
|
-
switch (_context3.prev = _context3.next) {
|
|
193
|
-
case 0:
|
|
194
|
-
if (fetch) {
|
|
195
|
-
_context3.next = 2;
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
throw Error('client.fetch.unavailable');
|
|
200
|
-
|
|
201
|
-
case 2:
|
|
202
|
-
_context3.t0 = getOptionsParam;
|
|
203
|
-
_context3.next = 5;
|
|
204
|
-
return getOptions('read', options);
|
|
205
|
-
|
|
206
|
-
case 5:
|
|
207
|
-
_context3.t1 = _context3.sent;
|
|
208
|
-
optionsParam = (0, _context3.t0)(_context3.t1);
|
|
209
|
-
url = baseUrl + "?opts=" + optionsParam + "&op=read";
|
|
210
|
-
return _context3.abrupt("return", makeQuery(url, query));
|
|
211
|
-
|
|
212
|
-
case 9:
|
|
213
|
-
case "end":
|
|
214
|
-
return _context3.stop();
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}, _callee3);
|
|
218
|
-
}));
|
|
219
|
-
|
|
220
|
-
return function (_x3, _x4) {
|
|
221
|
-
return _ref5.apply(this, arguments);
|
|
222
|
-
};
|
|
223
|
-
}());
|
|
224
|
-
store.on('watch', /*#__PURE__*/function () {
|
|
225
|
-
var _ref = (0, _wrapAsyncGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(query, options) {
|
|
226
|
-
var optionsParam, url, source;
|
|
227
|
-
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
228
|
-
while (1) {
|
|
229
|
-
switch (_context4.prev = _context4.next) {
|
|
230
|
-
case 0:
|
|
231
|
-
if (!(watch === 'none')) {
|
|
232
|
-
_context4.next = 2;
|
|
233
|
-
break;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
throw Error('client.no_watch');
|
|
237
|
-
|
|
238
|
-
case 2:
|
|
239
|
-
if (!(watch === 'hang')) {
|
|
240
|
-
_context4.next = 5;
|
|
241
|
-
break;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return _context4.delegateYield((0, _asyncGeneratorDelegate2.default)((0, _asyncIterator2.default)((0, _stream.makeStream)(function (push) {
|
|
245
|
-
push(undefined);
|
|
246
|
-
})), _awaitAsyncGenerator2.default), "t0", 4);
|
|
247
|
-
|
|
248
|
-
case 4:
|
|
249
|
-
return _context4.abrupt("return");
|
|
250
|
-
|
|
251
|
-
case 5:
|
|
252
|
-
if (EventSource) {
|
|
253
|
-
_context4.next = 7;
|
|
254
|
-
break;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
throw Error('client.sse.unavailable');
|
|
258
|
-
|
|
259
|
-
case 7:
|
|
260
|
-
_context4.t1 = getOptionsParam;
|
|
261
|
-
_context4.next = 10;
|
|
262
|
-
return (0, _awaitAsyncGenerator2.default)(getOptions('watch', options));
|
|
263
|
-
|
|
264
|
-
case 10:
|
|
265
|
-
_context4.t2 = _context4.sent;
|
|
266
|
-
optionsParam = (0, _context4.t1)(_context4.t2);
|
|
267
|
-
url = baseUrl + "?q=" + (0, _common.encodeUrl)(query) + "&opts=" + optionsParam;
|
|
268
|
-
source = new EventSource(url);
|
|
269
|
-
return _context4.delegateYield((0, _asyncGeneratorDelegate2.default)((0, _asyncIterator2.default)((0, _stream.makeStream)(function (push, end) {
|
|
270
|
-
source.onmessage = function (_ref6) {
|
|
271
|
-
var data = _ref6.data;
|
|
272
|
-
push((0, _common.deserialize)(data));
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
source.onerror = function (e) {
|
|
276
|
-
end(Error('client.sse.transport: ' + e.message));
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
source.addEventListener('graffyerror', function (e) {
|
|
280
|
-
end(Error('server.' + e.data));
|
|
281
|
-
});
|
|
282
|
-
return function () {
|
|
283
|
-
source.close();
|
|
284
|
-
};
|
|
285
|
-
})), _awaitAsyncGenerator2.default), "t3", 15);
|
|
286
|
-
|
|
287
|
-
case 15:
|
|
288
|
-
case "end":
|
|
289
|
-
return _context4.stop();
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}, _callee4);
|
|
293
|
-
}));
|
|
294
|
-
|
|
295
|
-
return function (_x, _x2) {
|
|
296
|
-
return _ref.apply(this, arguments);
|
|
297
|
-
};
|
|
298
|
-
}());
|
|
299
|
-
store.on('write', /*#__PURE__*/function () {
|
|
300
|
-
var _ref7 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(change, options) {
|
|
301
|
-
var optionsParam, url;
|
|
302
|
-
return _regenerator.default.wrap(function _callee5$(_context5) {
|
|
303
|
-
while (1) {
|
|
304
|
-
switch (_context5.prev = _context5.next) {
|
|
305
|
-
case 0:
|
|
306
|
-
if (fetch) {
|
|
307
|
-
_context5.next = 2;
|
|
308
|
-
break;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
throw Error('client.fetch.unavailable');
|
|
312
|
-
|
|
313
|
-
case 2:
|
|
314
|
-
_context5.t0 = getOptionsParam;
|
|
315
|
-
_context5.next = 5;
|
|
316
|
-
return getOptions('write', options);
|
|
317
|
-
|
|
318
|
-
case 5:
|
|
319
|
-
_context5.t1 = _context5.sent;
|
|
320
|
-
optionsParam = (0, _context5.t0)(_context5.t1);
|
|
321
|
-
url = baseUrl + "?opts=" + optionsParam + "&op=write";
|
|
322
|
-
return _context5.abrupt("return", fetch(url, {
|
|
323
|
-
method: 'POST',
|
|
324
|
-
headers: {
|
|
325
|
-
'Content-Type': 'application/json'
|
|
326
|
-
},
|
|
327
|
-
body: (0, _common.serialize)(change)
|
|
328
|
-
}).then(function (res) {
|
|
329
|
-
if (res.status === 200) return res.json();
|
|
330
|
-
return res.text().then(function (message) {
|
|
331
|
-
throw Error('server.' + message);
|
|
332
|
-
});
|
|
333
|
-
}));
|
|
334
|
-
|
|
335
|
-
case 9:
|
|
336
|
-
case "end":
|
|
337
|
-
return _context5.stop();
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
}, _callee5);
|
|
341
|
-
}));
|
|
342
|
-
|
|
343
|
-
return function (_x5, _x6) {
|
|
344
|
-
return _ref7.apply(this, arguments);
|
|
345
|
-
};
|
|
346
|
-
}());
|
|
347
|
-
};
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
var _default = httpClient;
|
|
351
|
-
exports.default = _default;
|
|
352
|
-
module.exports = exports.default;
|
package/cjs/index.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
exports.__esModule = true;
|
|
6
|
-
exports.default = GraffyClient;
|
|
7
|
-
|
|
8
|
-
var _httpClient = _interopRequireDefault(require("./httpClient.js"));
|
|
9
|
-
|
|
10
|
-
var _wsClient = _interopRequireDefault(require("./wsClient.js"));
|
|
11
|
-
|
|
12
|
-
var WSRE = /^wss?:\/\//;
|
|
13
|
-
|
|
14
|
-
function GraffyClient(baseUrl, options) {
|
|
15
|
-
if (WSRE.test(baseUrl)) {
|
|
16
|
-
return (0, _wsClient.default)(baseUrl, options);
|
|
17
|
-
} else {
|
|
18
|
-
return (0, _httpClient.default)(baseUrl, options);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
module.exports = exports.default;
|
package/cjs/wsClient.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
exports.__esModule = true;
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
9
|
-
|
|
10
|
-
var _stream = require("@graffy/stream");
|
|
11
|
-
|
|
12
|
-
var _common = require("@graffy/common");
|
|
13
|
-
|
|
14
|
-
var _Socket = _interopRequireDefault(require("./Socket.js"));
|
|
15
|
-
|
|
16
|
-
var wsClient = function wsClient(url, _temp) {
|
|
17
|
-
var _ref = _temp === void 0 ? {} : _temp,
|
|
18
|
-
_ref$getOptions = _ref.getOptions,
|
|
19
|
-
getOptions = _ref$getOptions === void 0 ? function () {} : _ref$getOptions,
|
|
20
|
-
watch = _ref.watch,
|
|
21
|
-
_ref$connInfoPath = _ref.connInfoPath,
|
|
22
|
-
connInfoPath = _ref$connInfoPath === void 0 ? 'connection' : _ref$connInfoPath;
|
|
23
|
-
|
|
24
|
-
return function (store) {
|
|
25
|
-
if (!WebSocket) throw Error('client.websocket.unavailable');
|
|
26
|
-
var socket = new _Socket.default(url, {
|
|
27
|
-
onUnhandled: onUnhandled,
|
|
28
|
-
onStatusChange: onStatusChange
|
|
29
|
-
});
|
|
30
|
-
var status = false;
|
|
31
|
-
var statusWatcher = (0, _common.makeWatcher)();
|
|
32
|
-
|
|
33
|
-
function onUnhandled(id) {
|
|
34
|
-
socket.stop(id, ['unwatch']);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function onStatusChange(newStatus) {
|
|
38
|
-
status = newStatus;
|
|
39
|
-
statusWatcher.write({
|
|
40
|
-
status: status
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function once(op, payload, options) {
|
|
45
|
-
return new _promise.default(function (resolve, reject) {
|
|
46
|
-
var id = socket.start([op, payload, getOptions(op, options) || {}], function (error, result) {
|
|
47
|
-
socket.stop(id);
|
|
48
|
-
error ? reject(Error('server.' + error)) : resolve(result);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
store.onWrite(connInfoPath, function () {
|
|
54
|
-
status = socket.isAlive();
|
|
55
|
-
return {
|
|
56
|
-
status: status
|
|
57
|
-
};
|
|
58
|
-
});
|
|
59
|
-
store.onRead(connInfoPath, function () {
|
|
60
|
-
return {
|
|
61
|
-
status: status
|
|
62
|
-
};
|
|
63
|
-
});
|
|
64
|
-
store.onWatch(connInfoPath, function () {
|
|
65
|
-
return statusWatcher.watch({
|
|
66
|
-
status: status
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
store.on('read', function (query, options) {
|
|
70
|
-
return once('read', query, options);
|
|
71
|
-
});
|
|
72
|
-
store.on('write', function (change, options) {
|
|
73
|
-
return once('write', change, options);
|
|
74
|
-
});
|
|
75
|
-
store.on('watch', function (query, options) {
|
|
76
|
-
if (watch === 'none') throw Error('client.no_watch');
|
|
77
|
-
var op = 'watch';
|
|
78
|
-
return (0, _stream.makeStream)(function (push, end) {
|
|
79
|
-
var id = socket.start([op, query, getOptions(op, options) || {}], function (error, result) {
|
|
80
|
-
if (error) {
|
|
81
|
-
socket.stop(id);
|
|
82
|
-
end(Error('server.' + error));
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
push(result);
|
|
87
|
-
});
|
|
88
|
-
return function () {
|
|
89
|
-
socket.stop(id, ['unwatch']);
|
|
90
|
-
};
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
};
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
var _default = wsClient;
|
|
97
|
-
exports.default = _default;
|
|
98
|
-
module.exports = exports.default;
|
package/types/Socket.d.ts
DELETED
package/types/httpClient.d.ts
DELETED
package/types/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function GraffyClient(baseUrl: any, options: any): (store: any) => void;
|