Comparing version 0.0.10 to 0.0.11-0016abee966964da3f44d97929e2809db006e7a9
1520
dist/index.js
@@ -1,45 +0,26 @@ | ||
'use strict'; | ||
var $1662971556 = require('brisky-struct') | ||
;var $826337949 = require('stamp') | ||
; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var hash = _interopDefault(require('string-hash')); | ||
var briskyStruct = require('brisky-struct'); | ||
var bs = _interopDefault(require('brisky-stamp')); | ||
var WebSocket = _interopDefault(require('uws')); | ||
const uniq = process.pid; | ||
var id = hash(`b-${Date.now()}-${(Math.random() * 10000) | 0}-${uniq}`); | ||
const next = typeof window === 'undefined' | ||
const $1094503762_next = typeof window === 'undefined' | ||
? process.nextTick | ||
: global.requestAnimationFrame; | ||
: global.requestAnimationFrame | ||
const parse$1 = (stamp, hub, t) => { | ||
const src = bs.src(stamp); | ||
if (!src) { | ||
return bs.create(bs.type(stamp), hub.id, bs.val(stamp)) | ||
} else { | ||
const val = bs.val(stamp); | ||
if (!t[1]) t[1] = {}; | ||
const meta = t[1]; | ||
if (!meta.resolve) meta.resolve = {}; | ||
const resolve = meta.resolve[src]; | ||
if (!resolve || val < resolve) meta.resolve[src] = val; | ||
return stamp | ||
const $1094503762_serialize = (hub, t, struct, val, level) => { | ||
if (!struct.isHub || struct.key === 'clients' || (struct._p && struct._p.key === 'clients')) { | ||
return | ||
} | ||
}; | ||
const serialize = (hub, t, struct$$1, val, level) => { | ||
const path = struct$$1.path(); | ||
const len = path.length; | ||
const path = struct.path() // cached version (later) | ||
const len = path.length | ||
if (struct$$1.val !== void 0 || val === null) { | ||
var s = t[0] || (t[0] = {}); | ||
if (struct.val !== void 0 || val === null) { | ||
var s = t[0] || (t[0] = {}) | ||
for (let i = level; i < len; i++) { | ||
let t = s[path[i]]; | ||
let t = s[path[i]] | ||
if (!t) { | ||
s = s[path[i]] = {}; | ||
s = s[path[i]] = {} | ||
} else { | ||
s = t; | ||
s = t | ||
if (s.val === null) { return } | ||
@@ -49,3 +30,3 @@ } | ||
s.stamp = parse$1(struct$$1.stamp, hub, t); | ||
s.stamp = struct.stamp | ||
@@ -55,131 +36,148 @@ if (val === null) { | ||
if (key !== 'stamp') { | ||
delete s[key]; | ||
delete s[key] | ||
} | ||
} | ||
s.val = null; | ||
} else if (struct$$1.val && struct$$1.val.inherits) { | ||
s.val = struct$$1.val.path(); | ||
s.val.unshift('@', 'root'); | ||
serialize(hub, t, struct$$1.val, val, level); | ||
} else if (struct$$1.val !== void 0) { | ||
s.val = struct$$1.val; | ||
s.val = null | ||
} else if (struct.val && struct.val.inherits) { | ||
// make a bit more secure... | ||
// if (!s.val) { | ||
s.val = struct.val.path() | ||
s.val.unshift('@', 'root') | ||
// if allrdy serialized stop it! | ||
$1094503762_serialize(hub, t, struct.val, val, level) | ||
// } | ||
} else if (struct.val !== void 0) { | ||
s.val = struct.val | ||
} | ||
} | ||
}; | ||
} | ||
const meta = hub => { | ||
const store = inProgress(hub, bs.inProgress ? bs.on : next); | ||
if (!store[1]) store[1] = {}; | ||
store[1].context = hub.clientContext; | ||
store[1].id = hub.id; | ||
store[1].subscriptions = hub.upstreamSubscriptions; | ||
}; | ||
const $1094503762_meta = hub => { | ||
if (!hub.receiveOnly) { | ||
const store = $1094503762_inProgress(hub, $826337949.inProgress ? $826337949.on : $1094503762_next) | ||
if (!store[1]) store[1] = {} | ||
if (hub.context) { | ||
if (hub.context.keys().length > 0) { | ||
store[1].context = hub.context.compute() ? hub.context.serialize() : false | ||
} else { | ||
store[1].context = hub.context.compute() || false | ||
} | ||
} | ||
store[1].id = hub.client.key | ||
store[1].subscriptions = hub.upstreamSubscriptions | ||
} else if (hub.upstreamSubscriptions) { | ||
let override | ||
for (let key in hub.upstreamSubscriptions) { | ||
if (hub.upstreamSubscriptions[key].__force__) { | ||
if (!override) override = [] | ||
override.push(key) | ||
} | ||
} | ||
if (override) { | ||
const store = $1094503762_inProgress(hub, $826337949.inProgress ? $826337949.on : $1094503762_next) | ||
if (!store[1]) store[1] = {} | ||
const obj = {} | ||
let i = override.length | ||
while (i--) { | ||
obj[override[i]] = hub.upstreamSubscriptions[override[i]] | ||
} | ||
store[1].subscriptions = obj | ||
} | ||
} | ||
} | ||
const send = (val, stamp, struct$$1) => { | ||
if (bs.type(stamp) !== 'upstream') { | ||
let hub; | ||
let p = struct$$1; | ||
while (p) { | ||
if (p.url && !p._c) { hub = p; } | ||
p = p.parent(); // needs to walk over context (for multi server) | ||
} | ||
if (hub && !hub.receiveOnly && struct$$1.key !== 'clients') { | ||
if (struct$$1 === hub) { | ||
const $1094503762_send = (val, stamp, struct) => { | ||
// -1 means upsteam (floats for extra speed) | ||
let hub | ||
let p = struct | ||
while (p) { | ||
if (p._url_ && !p._c) hub = p | ||
p = p.parent() // needs to walk over context (for multi server) | ||
} | ||
if (hub) { | ||
if (!hub.receiveOnly) { | ||
if (struct === hub) { | ||
if (val === null) { | ||
return | ||
} | ||
} else if (struct$$1._p.key === 'clients') { | ||
if (struct$$1.key !== hub.id) { | ||
} else if (struct._p.key === 'clients') { | ||
if (struct.key !== hub.client.key) { | ||
return | ||
} | ||
} | ||
serialize(hub, inProgress(hub, bs.on), struct$$1, val, hub.urlIndex); | ||
$1094503762_serialize(hub, $1094503762_inProgress(hub, $826337949.on), struct, val, hub.urlIndex) | ||
} | ||
} | ||
}; | ||
} | ||
const inProgress = (hub, tick) => { | ||
const $1094503762_inProgress = (hub, tick) => { | ||
if (!hub.inProgress) { | ||
hub.inProgress = []; | ||
hub.inProgress = [] | ||
tick(() => { | ||
if (hub.connected.compute() === true) { | ||
out(hub); | ||
$1094503762_out(hub) | ||
} else { | ||
hub.connected.once(true, () => out(hub)); | ||
hub.connected.once(true, () => $1094503762_out(hub)) | ||
} | ||
}); | ||
}) | ||
} | ||
return hub.inProgress | ||
}; | ||
} | ||
const out = t => { | ||
t.socket.send(JSON.stringify(t.inProgress)); | ||
t.inProgress = false; | ||
}; | ||
const $1094503762_out = t => { | ||
t.socket.send(JSON.stringify(t.inProgress)) | ||
t.inProgress = false | ||
} | ||
const isEmpty = t => { | ||
var $1094503762_$ALL$ = { | ||
meta: $1094503762_meta, | ||
send: $1094503762_send | ||
} | ||
;var $1971361117 = require('uws') | ||
; | ||
var $1704955210 = $1971361117 | ||
// need to get this fixed on now! | ||
// import { w3cwebsocket } from 'websocket' | ||
// export default w3cwebsocket | ||
;const $3851780354_isEmpty = t => { | ||
for (let i in t) { return false } | ||
return true | ||
}; | ||
} | ||
// function merge (a, b) { | ||
// for (let i in b) { | ||
// if ((!a[i] || typeof a[i] !== 'object')) { | ||
// a[i] = b[i] | ||
// } else { | ||
// merge(a[i], b[i]) | ||
// } | ||
// } | ||
// } | ||
const parse$2 = (struct$$1, obj, key, root) => { | ||
const result = {}; | ||
if (!root) { root = result; } | ||
if (obj.type) result.type = obj.type; // need to be done before the rest of subs to sync correctly | ||
const $3851780354_parse = (struct, obj, key, root) => { | ||
const result = {} | ||
if (!root) { root = result } | ||
if (obj.type) result.type = $3851780354_parse(struct, obj.type, 'type') | ||
for (let i in obj) { | ||
if (i !== '_' && i !== 'type') { | ||
// @todo more resolve for parent and client | ||
// need more just use client (since milti hub) | ||
if (i === 'client') { // && (!key || key === 'root' || key === 'parent') | ||
// console.log('CLIENT NEED TO HANDLE MORE SPECIAL THEN JUST ROOT') | ||
// let id = state.id | ||
// if (!root.clients) { root.clients = {} } | ||
// if (!root.clients[id]) { root.clients[id] = {} } | ||
// merge(root.clients[id], parse(obj.client, i, root, state)) | ||
} else if (typeof obj[i] === 'function') { | ||
let val = obj[i].toString(); | ||
if (typeof obj[i] === 'function') { | ||
let val = obj[i].toString() | ||
if (!/^(function|\()/.test(val)) { | ||
// this can all be done on the hub itself of course | ||
// hash will also be used for sec purposes | ||
// this will just be send up and done on the hub -- not here! | ||
if (/^.+=>/.test(val)) { | ||
if (!/^(\(){0, 1}.+(\)){0, 1} +=>/.test(val)) { | ||
val = val.replace(/^(.*?)( +=>)/, '($1)$2'); | ||
val = val.replace(/^(.*?)( +=>)/, '($1)$2') | ||
} | ||
if (!/^(.*?)+=> +{(.*?)}$/.test(val) && val.indexOf('return ') === -1) { | ||
val = val.replace(/^(.+=> *?)(.*?)/, '$1 { return $2') + ' }'; | ||
val = val.replace(/^(.+=> *?)(.*?)/, '$1 { return $2') + ' }' | ||
} | ||
val = val.replace('=>', ''); | ||
val = val.replace('=>', '') | ||
} | ||
val = 'function ' + val; | ||
val = 'function ' + val | ||
} | ||
result['$fn|' + i] = val; | ||
result['$fn|' + i] = val | ||
// also here we need to rewrite client to use client id | ||
} else if (typeof obj[i] !== 'object') { | ||
// sync later! | ||
// if (obj._ && obj._.sync) { | ||
// if (obj._.sync !== true) { result[i] = obj._.sync } | ||
// } else { | ||
result[i] = obj[i]; | ||
// } | ||
result[i] = obj[i] | ||
} else { | ||
// empty objects are very uninteresetting maybe just skip them | ||
let parsed = parse$2(struct$$1, obj[i], i, root); | ||
// if (i === 'root' || i === 'parent') { | ||
// if (isEmpty(parsed)) { | ||
// parsed = void 0 | ||
// } | ||
// } | ||
// does disable the weird bla: {} construct | ||
if (parsed !== void 0) { result[i] = parsed; } | ||
let parsed = $3851780354_parse(struct, obj[i], i, root) | ||
if (parsed !== void 0) { result[i] = parsed } | ||
} | ||
@@ -189,126 +187,212 @@ } | ||
// if result is empty ignore -- may not be a good idea | ||
return isEmpty(result) ? void 0 : result | ||
}; | ||
return $3851780354_isEmpty(result) ? void 0 : result | ||
} | ||
const connect = (hub, url, reconnect) => { | ||
const socket = new WebSocket(url); | ||
const id = hub.id; | ||
var $3851780354 = $3851780354_parse | ||
hub.set({ clients: { [id]: { } } }, false); | ||
;var $2180032073 = require('string-hash') | ||
;var $3305006410 = require('vigour-ua') | ||
; | ||
const $1384736615_uniq = process.pid | ||
var $1384736615 = () => $2180032073(`b-${Date.now()}-${(Math.random() * 10000) | 0}-${$1384736615_uniq}`) | ||
const client = hub.clients[id]; | ||
; | ||
hub.set({ client }, false); | ||
hub.reconnect = null; | ||
var $2828932010 = (t, val, stamp, useragent, id) => { | ||
if (!id) id = t._uid_ || $1384736615() | ||
$3305006410(useragent, val) | ||
t.set({ clients: { [id]: val } }, stamp) | ||
return t.clients[id] | ||
} | ||
; | ||
const $3357289264_connect = (hub, url, reconnect) => { | ||
const socket = new $1704955210(url) | ||
const client = hub.client || $2828932010(hub, {}, false) | ||
hub.set({ client }, false) | ||
hub.reconnect = null | ||
const close = () => { | ||
const stamp = bs.create('disconnect', hub.id); | ||
hub.socket = false; | ||
hub.set({ connected: false }, stamp); | ||
bs.close(); | ||
if (!socket.blockReconnect && hub.url) { | ||
reconnect = Math.min((reconnect * 1.5), 2000); | ||
hub.reconnect = setTimeout(connect, reconnect, hub, url, reconnect); | ||
const stamp = $826337949.create() | ||
hub.socket = false | ||
hub.set({ connected: false }, stamp) | ||
$826337949.close() | ||
if (!socket.blockReconnect && hub._url_) { | ||
reconnect = Math.min((reconnect * 1.5), 2000) | ||
hub.reconnect = setTimeout($3357289264_connect, reconnect, hub, url, reconnect) | ||
} | ||
}; | ||
} | ||
socket.onclose = close; | ||
socket.onclose = close | ||
socket.onerror = () => { | ||
if (typeof window === 'undefined') { | ||
close(); | ||
} else { | ||
socket.close(); | ||
} | ||
}; | ||
socket.onerror = typeof window === 'undefined' | ||
? close | ||
: () => socket.close() | ||
socket.onopen = () => { | ||
const stamp = bs.create('connected', hub.id); | ||
hub.socket = socket; | ||
meta(hub); | ||
hub.set({ connected: true }, stamp); | ||
bs.close(); | ||
}; | ||
const stamp = $826337949.create() | ||
hub.socket = socket | ||
if (hub.emitters && hub.emitters.incoming) { | ||
$3357289264_enableIncomingListener(socket, hub) | ||
} | ||
$1094503762_meta(hub) | ||
hub.set({ connected: true }, stamp) | ||
$826337949.close() | ||
} | ||
socket.onmessage = ({ data }) => { | ||
const stamp = bs.create('upstream'); | ||
// console.log(JSON.stringify(JSON.parse(data), false, 2)) | ||
hub.set(JSON.parse(data), stamp); | ||
bs.close(stamp); | ||
}; | ||
}; | ||
// use outside function non anon since its slowe apprantly | ||
socket.onmessage = (data) => { | ||
data = data.data | ||
if (!hub.receiveOnly) { | ||
hub.receiveOnly = true | ||
hub.set(JSON.parse(data), false) | ||
hub.receiveOnly = null | ||
} else { | ||
hub.set(JSON.parse(data), false) | ||
} | ||
$826337949.close() | ||
} | ||
} | ||
const removeUrl = hub => { | ||
hub.url = null; | ||
hub.urlIndex = null; | ||
hub.emitters.set({ data: { url$: null } }, false); | ||
}; | ||
const $3357289264_removeUrl = hub => { | ||
hub.url = hub._url_ = hub.urlIndex = null | ||
hub.emitters.set({ data: { url$: null } }, false) | ||
} | ||
const removeSocket = hub => { | ||
const $3357289264_removeSocket = hub => { | ||
if (hub.reconnect) { | ||
clearTimeout(hub.reconnect); | ||
hub.reconnect = null; | ||
clearTimeout(hub.reconnect) | ||
hub.reconnect = null | ||
} | ||
if (hub.socket) { | ||
hub.socket.blockReconnect = true; | ||
hub.socket.close(); | ||
hub.socket.blockReconnect = true | ||
hub.socket.close() | ||
} | ||
}; | ||
hub.socket = false | ||
} | ||
const url = (hub, val, stamp) => { | ||
const $3357289264_url = (hub, val, key, stamp) => { | ||
hub.on((val, stamp, t) => { | ||
if (val === null && !t._c && t === hub) { | ||
hub.subscriptions = []; | ||
removeUrl(hub); | ||
removeSocket(hub); | ||
hub.subscriptions = [] | ||
$3357289264_removeUrl(hub) | ||
$3357289264_removeSocket(hub) | ||
} | ||
}, 'url$'); | ||
if (!val) val = null; | ||
if (val !== hub.url) { | ||
removeSocket(hub); | ||
hub.set({ connected: false }, stamp); | ||
}, 'url$') | ||
if (!val) val = null | ||
if ((!hub.url && val) || (hub.url.compute() !== val)) { | ||
$3357289264_removeSocket(hub) | ||
if (!val) { | ||
removeUrl(hub); | ||
hub.set({ connected: false }, stamp) | ||
hub._url_ = null | ||
if (hub.url) hub.url.set(null, stamp) | ||
} else { | ||
let i = -1; | ||
if (hub.key) i++; | ||
hub.parent(() => { i++; }); | ||
hub.urlIndex = i; | ||
hub.url = val; | ||
connect(hub, val, 50); | ||
if (!hub.url) { | ||
$1662971556.create({ | ||
on: { | ||
data: { | ||
url: (val, stamp, struct) => { | ||
val = struct.compute() | ||
if (val) { | ||
hub.set({ connected: false }, stamp) | ||
let i = -1 | ||
if (hub.key) i++ | ||
hub.parent(() => { i++ }) | ||
hub.urlIndex = i // use this for checks | ||
hub._url_ = val | ||
$3357289264_connect(hub, val, 50) | ||
} else { | ||
hub._url_ = null | ||
} | ||
} | ||
} | ||
} | ||
}, stamp, $1662971556.struct, hub, key) | ||
} | ||
if (/^https?/.test(val)) val = val.replace(/^http/, 'ws') | ||
hub.url.set(val, stamp) | ||
} | ||
} | ||
}; | ||
} | ||
// very context as well | ||
// const clients => (val, stamp) { | ||
// const hub = this.cParent() | ||
// if (this.compute() === false && hub.upstream) { | ||
// // put this in clients (the file) | ||
// const clients = hub.clients | ||
// if (clients && clients.keys().length > 1) { | ||
// clients.each((client) => { | ||
// if ( | ||
// client.val !== null && | ||
// !client.socket && | ||
// client.key != hub.id // eslint-disable-line | ||
// ) { | ||
// client.remove(stamp) | ||
// } | ||
// }) | ||
// } | ||
// } | ||
// } | ||
const $3357289264_removeClients = (hub, stamp) => { | ||
const clients = hub.clients | ||
if (clients && clients.keys().length > 1) { | ||
clients.forEach((client, key) => { | ||
if ( | ||
client.val !== null && | ||
client !== hub.client | ||
) { | ||
client.set(null, stamp) | ||
delete clients[key] | ||
} | ||
}) | ||
} | ||
} | ||
const connected = { type: 'struct' }; | ||
const $3357289264_connected = { | ||
type: 'struct', | ||
on: { | ||
data: { | ||
removeClients: (val, stamp, t) => { | ||
if (t.compute() === false) { | ||
// all instances! -- fix this | ||
$3357289264_removeClients(t._p, stamp) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
const context = (hub, val) => { | ||
if (val !== hub.clientContext) { | ||
hub.clientContext = val; | ||
if (hub.connected && hub.connected.compute() === true) meta(hub); | ||
const $3357289264_contextStruct = $1662971556.struct.create({ | ||
props: { | ||
default: { | ||
on: { | ||
data: { | ||
updateParent: (val, stamp, t) => { | ||
t.parent().emit('data', val, stamp) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
}) | ||
const props = { | ||
const $3357289264_contextIsNotEqual = (val, context) => { | ||
if (val && typeof val === 'object') { | ||
for (let field in val) { | ||
if (!context[field] || val[field] !== context[field].compute()) { | ||
console.log('😜', field) | ||
return true | ||
} | ||
} | ||
} else { | ||
return val !== context.compute() | ||
} | ||
} | ||
const $3357289264_context = (hub, val, key, stamp) => { | ||
if ((!hub.context && val) || (hub.context && $3357289264_contextIsNotEqual(val, hub.context))) { | ||
if (!hub.context) { | ||
$1662971556.create(val, stamp, $3357289264_contextStruct, hub, key) | ||
} else { | ||
$3357289264_removeClients(hub, stamp) | ||
hub.context.set(val, stamp) | ||
} | ||
if (hub.connected && hub.connected.compute() === true) $1094503762_meta(hub) | ||
} | ||
} | ||
const $3357289264_props = { | ||
reconnect: true, | ||
@@ -319,87 +403,148 @@ socket: true, | ||
receiveOnly: true, | ||
url, | ||
context, | ||
connected | ||
}; | ||
url: $3357289264_url, | ||
context: $3357289264_context, | ||
connected: $3357289264_connected | ||
} | ||
const stub = () => {}; | ||
const $3357289264_stub = () => {} | ||
const define = { | ||
subscribe (subs, cb, raw, tree) { | ||
if (!raw) subs = briskyStruct.parse(subs); | ||
const parsed = parse$2(this, subs); | ||
if (parsed) { | ||
const key = hash(JSON.stringify(parsed)); | ||
if (!this.upstreamSubscriptions) { | ||
this.upstreamSubscriptions = { [key]: parsed }; | ||
if (this.url) meta(this); | ||
} else if (!this.upstreamSubscriptions[key]) { | ||
this.upstreamSubscriptions[key] = parsed; | ||
if (this.url) meta(this); | ||
const $3357289264_define = { | ||
subscribe (subs, cb, raw, tree, forceUpstream) { | ||
if (!raw) subs = $1662971556.parse(subs) | ||
if (!this.receiveOnly || forceUpstream) { | ||
const parsed = $3851780354(this, subs) | ||
if (parsed) { | ||
if (forceUpstream) { | ||
parsed.__force__ = true | ||
} | ||
// why not keep it stringified? -- saves lots of speed | ||
const key = $2180032073(JSON.stringify(parsed)) | ||
if (!this.upstreamSubscriptions) { | ||
this.upstreamSubscriptions = {} | ||
this.upstreamSubscriptions[key] = parsed | ||
if (this.url) $1094503762_meta(this) | ||
} else if (!this.upstreamSubscriptions[key]) { | ||
this.upstreamSubscriptions[key] = parsed | ||
if (this.url) $1094503762_meta(this) | ||
} | ||
} | ||
} | ||
return briskyStruct.subscribe(this, subs, cb || stub, tree) | ||
return $1662971556.subscribe(this, subs, cb || $3357289264_stub, tree) | ||
} | ||
}; | ||
} | ||
const on = { data: { send } }; | ||
const $3357289264_enableIncomingListener = (socket, hub) => { | ||
if (!socket.incomingOverride) { | ||
socket.incomingOverride = true | ||
const field = typeof window === 'undefined' ? 'internalOnMessage' : 'onmessage' | ||
const msg = hub.socket[field] | ||
socket[field] = (data) => { | ||
hub.emit('incoming', data) | ||
msg(data) | ||
} | ||
} | ||
} | ||
const $3357289264_on = { | ||
data: { send: $1094503762_send }, | ||
props: { | ||
incoming: (t, val, key, stamp) => { | ||
const hub = t._p | ||
if (hub.socket) $3357289264_enableIncomingListener(hub.socket, hub) | ||
return $1662971556.emitterProperty(t, val, key, stamp) | ||
} | ||
} | ||
} | ||
var client = Object.freeze({ | ||
props: props, | ||
on: on, | ||
define: define | ||
}); | ||
var $3357289264_$ALL$ = { | ||
props: $3357289264_props, | ||
on: $3357289264_on, | ||
define: $3357289264_define | ||
} | ||
;var $2549126471 = { | ||
props: { | ||
contextKey: true, | ||
getContext: (t, fn) => { | ||
t.set({ | ||
define: { | ||
getContext (key, socket) { | ||
return fn(key, (key) => $2549126471_createContext(this, key), this, socket) | ||
} | ||
} | ||
}) | ||
} | ||
}, | ||
getContext: (key, context) => context() | ||
} | ||
const isFn = /^\$fn\|/; | ||
const dummy = () => false; | ||
// const client = (tree) => { | ||
// while (tree) { | ||
// if (tree._ && tree._.client) { | ||
// return tree._.client | ||
// } | ||
// tree = tree._p | ||
// } | ||
// } | ||
const $2549126471_createContext = (hub, val) => { | ||
var result = $2549126471_find(hub, val) | ||
if (!result) { | ||
result = hub.create({ contextKey: val }, false) | ||
} | ||
return result | ||
} | ||
// const clientContext = fn => (state, subs, tree, key) => { | ||
// if (state) { | ||
// const $root = state.root | ||
// const inContext = $root._client | ||
// var prev | ||
// if (inContext) { | ||
// $root._client = client(tree) | ||
// } else { | ||
// prev = $root.client | ||
// $root.client = client(tree) | ||
// } | ||
// const ret = fn(state, tree, subs, key) | ||
// if (inContext) { | ||
// $root._client = inContext | ||
// } else { | ||
// $root.client = prev | ||
// } | ||
// return ret | ||
// } else { | ||
// return fn(state, tree, subs, key) | ||
// } | ||
// } | ||
const $2549126471_find = (hub, val) => { | ||
const instances = hub.instances | ||
if (instances) { | ||
let i = instances.length | ||
while (i--) { | ||
if (instances[i].contextKey === val) return instances[i] | ||
} | ||
} | ||
} | ||
const parse$3 = (obj, state, key) => { | ||
const result = {}; | ||
;const $2381345089_isFn = /^\$fn\|/ | ||
const $2381345089_dummy = () => false | ||
function $2381345089_merge (a, b) { | ||
for (let i in b) { | ||
if ((!a[i] || typeof a[i] !== 'object')) { | ||
a[i] = b[i] | ||
} else { | ||
$2381345089_merge(a[i], b[i]) | ||
} | ||
} | ||
} | ||
// this will all be done with an ast later! | ||
const $2381345089_replaceClient = /\.client[^a-z0-9]/g | ||
// can also check for dangeorus stuff and maybe even allow some requires | ||
// needs hashing algo | ||
const $2381345089_clientContext = (val, client) => { | ||
const matches = val.match($2381345089_replaceClient) | ||
for (let i = 0, len = matches.length; i < len; i++) { | ||
val = val.replace(matches[i].slice(0, -1), '.clients.' + client.key) | ||
} | ||
return val | ||
} | ||
const $2381345089_parse = (obj, state, key, client, root) => { | ||
const result = {} | ||
if (!root) root = result | ||
for (let i in obj) { | ||
if (isFn.test(i)) { | ||
let val = obj[i]; | ||
i = i.slice(4); | ||
// need to fix bublé stuff in these fn creations -- prop need to add buble | ||
// runtime in a hub | ||
let pass; | ||
let block | ||
if (i === 'client' && (!key || key === 'root' || key === 'parent')) { | ||
block = true | ||
console.log('client subs parsing work in progress, missing parent and references') | ||
let id = client.key // wrong need to get client | ||
if (!root.clients) { root.clients = {} } | ||
if (!root.clients[id]) { root.clients[id] = {} } | ||
$2381345089_merge(root.clients[id], $2381345089_parse(obj.client, i, key, client, root)) | ||
} else if ($2381345089_isFn.test(i)) { | ||
let val = obj[i] | ||
i = i.slice(4) | ||
// need to fix bublé / babel stuff in these fn creations -- prop need to add buble | ||
// runtime in a hub, and ast | ||
// let pass | ||
try { | ||
obj[i] = new Function('return ' + val)(); // eslint-disable-line | ||
// if (/\.client|\[['"']client['"]\]/.test(val)) { // eslint-disable-line | ||
// obj[i] = clientContext(obj[i]) | ||
// } | ||
pass = true; | ||
if ($2381345089_replaceClient.test(val)) { // eslint-disable-line | ||
val = $2381345089_clientContext(val, client) | ||
} | ||
obj[i] = new Function('return ' + val)() // eslint-disable-line | ||
// pass = true | ||
// do dry run with your own key in a props object | ||
@@ -410,430 +555,492 @@ // 2 options for this ofcourse | ||
} catch (e) { | ||
let msg; | ||
if (!pass) { | ||
msg = `cannot parse function ${key}.exec\n${val}`; | ||
} else { | ||
msg = `cannot run function ${key}.exec\n${val}`; | ||
} | ||
state.emit('error', new Error(msg)); | ||
obj[i] = dummy; | ||
let msg | ||
// if (!pass) { | ||
msg = `cannot parse function ${key}.exec\n${val}` | ||
// } else { | ||
// msg = `cannot run function ${key}.exec\n${val}` | ||
// } | ||
state.emit('error', new Error(msg)) | ||
obj[i] = $2381345089_dummy | ||
} | ||
} | ||
if (typeof obj[i] !== 'object') { | ||
result[i] = obj[i]; | ||
} else { | ||
result[i] = parse$3(obj[i], state, i); | ||
// can go to client as well... | ||
if (!block && i !== '__force__') { | ||
if (i === 'clients' && result.clients) { | ||
$2381345089_merge(result[i], obj[i]) | ||
} else if (typeof obj[i] !== 'object') { | ||
result[i] = obj[i] | ||
} else { | ||
result[i] = $2381345089_parse(obj[i], state, i, client, root) | ||
} | ||
} | ||
} | ||
return result | ||
}; | ||
} | ||
const progress = (client) => { | ||
var $2381345089 = $2381345089_parse | ||
; | ||
const $2641472318_cache = (client, struct, stamp) => { | ||
if (!client.cache) client.cache = {} | ||
client.cache[$1662971556.puid(struct)] = stamp | ||
} | ||
const $2641472318_isCached = (client, struct, stamp) => client.cache && | ||
client.cache[$1662971556.puid(struct)] === stamp | ||
// const isCached = () => false | ||
var $2641472318_$ALL$ = { | ||
cache: $2641472318_cache, | ||
isCached: $2641472318_isCached | ||
} | ||
; | ||
const $727036942_isEmpty = obj => { | ||
for (let i in obj) { //eslint-disable-line | ||
return false | ||
} | ||
return true | ||
} | ||
// const size = str => { | ||
// // returns the byte length of an utf8 string | ||
// var s = str.length | ||
// for (var i= str.length - 1; i >= 0; i--) { | ||
// var code = str.charCodeAt(i) | ||
// if (code > 0x7f && code <= 0x7ff) { s++ } | ||
// else if (code > 0x7ff && code <= 0xffff) { s += 2 } | ||
// if (code >= 0xDC00 && code <= 0xDFFF) i-- // trail surrogate | ||
// } | ||
// return s | ||
// } | ||
const $727036942_progress = (client) => { | ||
if (!client.inProgress) { | ||
client.inProgress = {}; | ||
bs.on(() => { | ||
client.inProgress = {} | ||
$826337949.on(() => { | ||
if (client.val !== null) { | ||
var isEmpty = true; | ||
for (let i in client.inProgress) { //eslint-disable-line | ||
isEmpty = false; | ||
break | ||
} | ||
if (!isEmpty) { | ||
// bit hacky... | ||
if (!$727036942_isEmpty(client.inProgress)) { | ||
if (client.inProgress.types) { | ||
for (let i in client.inProgress) { | ||
// order is still important since setting types after the fact is still broken | ||
// this will be a big update | ||
if (i === 'types') { | ||
break | ||
} else { | ||
let tmp = client.inProgress[i]; | ||
delete client.inProgress[i]; | ||
client.inProgress[i] = tmp; | ||
let tmp = client.inProgress[i] | ||
delete client.inProgress[i] | ||
client.inProgress[i] = tmp | ||
} | ||
} | ||
} | ||
client.socket.send(JSON.stringify(client.inProgress)); | ||
const raw = JSON.stringify(client.inProgress) | ||
// console.log(size(raw)) | ||
client.socket.send(raw) | ||
} | ||
client.inProgress = false; | ||
client.inProgress = false | ||
} | ||
}); | ||
}) | ||
} | ||
return client.inProgress | ||
}; | ||
} | ||
const send$1 = (hub, client, t, type, subs, tree) => { | ||
var val; | ||
if (type === 'remove') { | ||
if (!t._p[t.key]) { | ||
val = null; | ||
if (bs.src(t._p.tStamp) === client.key) { | ||
return | ||
const $727036942_send = (hub, client, struct, type, subs, tree) => { | ||
if (struct.isHub && client.val !== null) { | ||
let isRemoved | ||
if (type === 'remove') { | ||
if (!struct._p || !struct._p[struct.key]) isRemoved = true | ||
} else if (type === 'update' && tree.$t !== struct) { | ||
if (tree.$t && tree.$t._p && !tree.$t._p[tree.$t.key]) { | ||
let previous = tree.$t | ||
let prop = previous | ||
while (previous) { | ||
if (previous._p && previous._p[previous.key]) { | ||
// think of something fast for level... | ||
$727036942_serialize(client, $727036942_progress(client), subs, prop, $1662971556.get(hub, 'serverIndex'), true) | ||
} | ||
prop = previous | ||
previous = previous._p | ||
} | ||
} | ||
} | ||
} else if (type === 'update' && tree.$t !== t) { | ||
if (tree.$t && tree.$t._p && !tree.$t._p[tree.$t.key]) { | ||
serialize$2(hub.id, client, progress(client), subs, tree.$t, null, briskyStruct.get(hub, 'serverIndex'), tree); | ||
} | ||
$727036942_serialize(client, $727036942_progress(client), subs, struct, $1662971556.get(hub, 'serverIndex'), isRemoved) | ||
} | ||
if (t.val !== void 0 || val === null || subs.val === true) { | ||
// opt this line (the get) just use a define or something | ||
serialize$2(hub.id, client, progress(client), subs, t, val, briskyStruct.get(hub, 'serverIndex'), tree); | ||
} | ||
}; | ||
} | ||
const cache = (client, struct$$1, stamp, level, val) => { | ||
if (!client.cache) client.cache = {}; | ||
client.cache[struct$$1.uid()] = stamp[0]; | ||
}; | ||
const $727036942_serialize = (client, t, subs, struct, level, isRemoved) => { | ||
const stamp = $1662971556.get(struct, 'stamp') || 1 // remove the need for this default (feels wrong) | ||
const val = isRemoved ? null : $1662971556.getVal(struct) | ||
const isCached = (client, struct$$1, stamp) => { | ||
return client.cache && client.cache[struct$$1.uid()] === stamp[0] | ||
}; | ||
const setStamp = (s, stamp, src, struct$$1, id, client, level) => { | ||
cache(client, struct$$1, stamp, level); | ||
s.stamp = !src | ||
? bs.create(bs.type(stamp), id, bs.val(stamp)) | ||
: stamp; | ||
}; | ||
// clean the cached up a bit | ||
const serialize$2 = (id, client, t, subs, struct$$1, val, level) => { | ||
const stamp = briskyStruct.get(struct$$1, 'stamp'); | ||
var cached, isType; | ||
if (stamp && (val === null || !(cached = isCached(client, struct$$1, stamp))) || subs.val === true) { | ||
const src = bs.src(stamp); | ||
if ( | ||
src !== client.key && bs.src(t.tStamp) !== client.key || | ||
(isType = struct$$1.key === 'type') | ||
) { | ||
if ( | ||
client.resolve && | ||
client.resolve[src] && | ||
bs.val(stamp) >= client.resolve[src] | ||
) { | ||
if (val !== null) { | ||
if (struct$$1.val !== void 0) cache(client, struct$$1, stamp, level); | ||
if (subs.val === true) { | ||
const keys = briskyStruct.getKeys(struct$$1); | ||
if (keys) deepSerialize(keys, id, client, t, subs, struct$$1, val, level); | ||
} | ||
} | ||
if (val !== void 0 && stamp && !$2641472318_isCached(client, struct, stamp)) { | ||
// val === null -- double chck if this is nessecary | ||
const path = struct.path() | ||
const len = path.length | ||
let s = t | ||
for (let i = level; i < len; i++) { | ||
let tt = s[path[i]] | ||
if (!tt) { | ||
s = s[path[i]] = {} | ||
} else { | ||
if (subs.type) { | ||
// simple but will make it better need more checks | ||
var p = struct$$1; | ||
while (p) { | ||
if (p.key === 'types') { | ||
return | ||
} | ||
p = p._p; | ||
} | ||
} | ||
s = tt | ||
if (s.val === null) return | ||
} | ||
} | ||
if (isType) { // means its blocked otherwise (could be a set form own client) | ||
typeSerialize(id, client, t, subs, struct$$1, val, level); | ||
} else if (!cached && (struct$$1.val !== void 0 || val === null)) { | ||
const path = struct$$1.path(); | ||
const len = path.length; | ||
var s = t; | ||
for (let i = level; i < len; i++) { | ||
let tt = s[path[i]]; | ||
if (!tt) { | ||
s = s[path[i]] = {}; | ||
} else { | ||
s = tt; | ||
if (s.val === null) return | ||
} | ||
} | ||
if (val === null) { | ||
setStamp(s, stamp, src, struct$$1, id, client, level, val); | ||
s.val = null; | ||
} else { | ||
if (struct$$1.key === 'type') { | ||
typeSerialize(id, client, t, subs, struct$$1, val, level); | ||
} | ||
setStamp(s, stamp, src, struct$$1, id, client, level); | ||
if (struct$$1.val && struct$$1.val.inherits) { | ||
s.val = struct$$1.val.path(); | ||
s.val.unshift('@', 'root'); | ||
serialize$2(id, client, t, subs, struct$$1.val, val, level); | ||
} else if (struct$$1.val !== void 0) { | ||
s.val = struct$$1.val; | ||
} | ||
} | ||
if (isRemoved) { | ||
$2641472318_cache(client, struct, stamp) | ||
s.stamp = stamp | ||
s.val = val | ||
} else { | ||
if (subs.type) { | ||
const type = $1662971556.get(struct, 'type') // make getType (fast) | ||
if ($1662971556.getVal(type) !== 'hub') { | ||
$727036942_serialize(client, t, subs.type, type, level) | ||
} | ||
} | ||
if (subs.val === true) { | ||
const keys = briskyStruct.getKeys(struct$$1); | ||
if (keys) deepSerialize(keys, id, client, t, subs, struct$$1, val, level); | ||
} | ||
$2641472318_cache(client, struct, stamp) | ||
s.stamp = stamp | ||
if (struct.key === 'type') { | ||
if (val === 'hub') return | ||
$727036942_serialize(client, t, subs, $1662971556.getType(struct.parent(2), val), level) | ||
// allways need a stamp! | ||
} | ||
if (typeof val === 'object' && val !== null && val.inherits) { | ||
s.val = val.path() | ||
s.val.unshift('@', 'root') | ||
$727036942_serialize(client, t, subs, val, level) | ||
} else if (val !== void 0) { | ||
s.val = val | ||
} | ||
} | ||
} else if (val && typeof val === 'object' && val.inherits) { | ||
// can send a bit too much data when val: true and overlapping keys | ||
$727036942_serialize(client, t, subs, val, level) | ||
} | ||
}; | ||
const typeSerialize = (id, client, t, subs, struct$$1, val, level) => { | ||
serialize$2(id, client, t, subs, briskyStruct.getType(struct$$1.parent(2), struct$$1.compute()), val, level); | ||
}; | ||
if (subs.val === true && !isRemoved) { | ||
$727036942_deepSerialize($1662971556.getKeys(struct), client, t, subs, struct, level) | ||
} | ||
} | ||
const deepSerialize = (keys, id, client, t, subs, struct$$1, val, level) => { | ||
const $727036942_deepSerialize = (keys, client, t, subs, struct, level) => { | ||
if (struct.get('type') && struct.get('type').compute() !== 'hub') { | ||
$727036942_serialize(client, t, subs, struct.get('type'), level) | ||
} | ||
if (keys) { | ||
for (let i = 0, len = keys.length; i < len; i++) { | ||
let prop = briskyStruct.get(struct$$1, keys[i]); | ||
if (prop && prop.isHub) serialize$2(id, client, t, subs, prop, val, level); | ||
let prop = $1662971556.get(struct, keys[i]) | ||
if (prop && prop.isHub) $727036942_serialize(client, t, subs, prop, level) | ||
} | ||
} | ||
// feels really shacky /w context :/ needs tests | ||
if (struct$$1._removed) { | ||
for (let i = 0, len = struct$$1._removed.length; i < len; i++) { | ||
let prop = struct$$1._removed[i]; | ||
if (prop && prop.isHub) serialize$2(id, client, t, subs, prop, null, level); | ||
if (struct._removed) { | ||
for (let i = 0, len = struct._removed.length; i < len; i++) { | ||
let prop = struct._removed[i] | ||
$727036942_serialize(client, t, subs, prop, level, true) | ||
} | ||
} | ||
}; | ||
} | ||
var incoming = (hub, socket, data) => { | ||
const payload = data[0]; | ||
const meta = data[1]; | ||
var client = socket.client; | ||
var t; | ||
var $727036942 = $727036942_send | ||
;const $1380346132_removeSubscriptions = (t, id) => { | ||
if (t.subscriptions) { | ||
let i = t.subscriptions.length | ||
while (i--) { // clean this up with unsubscribe in struct | ||
if (t.subscriptions[i]._uid_ == id) { //eslint-disable-line | ||
t.subscriptions.splice(i, 1) | ||
} | ||
} | ||
} | ||
} | ||
const $1380346132_removeClient = (client) => { | ||
const id = client.key | ||
client.val = null | ||
if (client.socket) { | ||
client.socket.client = null | ||
client.socket = null | ||
} | ||
const t = client.parent(2) | ||
$1380346132_removeSubscriptions(t, id) | ||
client.set(null) | ||
// if (client.context && t.clients.keys().length === (t.url ? 1 : 0)) { | ||
// t.set(null, stamp) | ||
// } | ||
} | ||
var $1380346132_$ALL$ = { | ||
removeSubscriptions: $1380346132_removeSubscriptions, | ||
removeClient: $1380346132_removeClient | ||
} | ||
; | ||
var $834150420 = (hub, socket, data) => { | ||
const payload = data[0] | ||
const meta = data[1] | ||
var client = socket.client | ||
if (meta) { | ||
let t | ||
if (client) { | ||
t = hub; | ||
if (client.context != meta.context) { // eslint-disable-line | ||
client.set(null); | ||
t = create$2(hub, socket, meta); | ||
client = socket.client; | ||
t = hub | ||
if ('context' in meta && client.context != meta.context) { // eslint-disable-line | ||
$834150420_create(hub, socket, meta, payload, client) | ||
} else if (meta.subscriptions) { | ||
incomingSubscriptions(t, client, meta, client.id); | ||
bs.close(); | ||
if (payload) $834150420_setPayload(t, payload, client) | ||
$834150420_incomingSubscriptions(t, client, meta, client.key) | ||
$826337949.close() | ||
} | ||
} else { | ||
t = create$2(hub, socket, meta); | ||
client = socket.client; | ||
$834150420_create(hub, socket, meta, payload) | ||
} | ||
} else { | ||
t = client.parent(2); | ||
$834150420_setPayload(client.parent(2), payload, client) | ||
$826337949.close() | ||
} | ||
} | ||
if (payload) { | ||
if (meta && meta.resolve) { | ||
client.resolve = meta.resolve; | ||
t.set(payload, false); | ||
bs.on(() => { client.resolve = false; }); | ||
} else { | ||
t.set(payload, false); | ||
const $834150420_addToCache = (client, hub, payload) => { | ||
if (typeof payload === 'object' && payload) { | ||
for (let key in payload) { | ||
if (key !== 'val' && key !== 'stamp') { | ||
let struct = hub[key] | ||
if (struct && struct.isHub) { | ||
$834150420_addToCache(client, hub[key], payload[key]) | ||
} | ||
} | ||
} | ||
bs.close(); | ||
if (payload.val !== void 0 && payload.stamp) { | ||
$2641472318_cache(client, hub, payload.stamp) | ||
} | ||
} | ||
}; | ||
} | ||
const create$2 = (hub, socket, meta) => { | ||
const stamp = bs.create('connect'); | ||
const id = meta.id; | ||
const t = meta.context ? hub.getContext(meta.context) : hub; | ||
t.set({ clients: { [id]: { socket, context: meta.context } } }, stamp); | ||
const client = socket.client = t.clients[id]; | ||
if (meta.subscriptions) incomingSubscriptions(t, client, meta, id); | ||
bs.close(stamp); | ||
return t | ||
}; | ||
const $834150420_setPayload = (hub, payload, client) => { | ||
hub.set(payload, false) | ||
$834150420_addToCache(client, hub, payload) | ||
} | ||
const incomingSubscriptions = (hub, client, meta, id) => { | ||
const update = (t, type, subs, tree) => send$1(hub, client, t, type, subs, tree); | ||
if (!client.upstreamSubscriptions) client.upstreamSubscriptions = {}; | ||
const $834150420_set = (meta, socket, t, payload) => { | ||
const stamp = $826337949.create() | ||
const id = meta.id | ||
const context = meta.context | ||
// const ip = socket._socket.remoteAddress | ||
const client = socket.client = $2828932010( | ||
t, { socket, context }, stamp, socket.useragent, id | ||
) | ||
if (payload) $834150420_setPayload(t, payload, client) | ||
if (meta.subscriptions) $834150420_incomingSubscriptions(t, client, meta, id) | ||
$826337949.close() | ||
} | ||
const $834150420_create = (hub, socket, meta, payload, client) => { | ||
const t = meta.context ? hub.getContext(meta.context, socket) : hub | ||
if (!t.inherits && t.then) { | ||
t.then((t) => { | ||
if (socket.external !== null) { | ||
console.log('client connected and found informations') | ||
if (client) $1380346132_removeClient(client) | ||
$834150420_set(meta, socket, t, payload) | ||
} else { | ||
console.log('client discconected when logging in') | ||
} | ||
}).catch(err => hub.emit('error', err)) | ||
} else { | ||
if (client) $1380346132_removeClient(client) | ||
$834150420_set(meta, socket, t, payload) | ||
} | ||
} | ||
const $834150420_incomingSubscriptions = (hub, client, meta, id) => { | ||
const update = (t, type, subs, tree) => $727036942(hub, client, t, type, subs, tree) | ||
if (!client.upstreamSubscriptions) client.upstreamSubscriptions = {} | ||
for (let key in meta.subscriptions) { | ||
let uid = key + '-' + id; | ||
const uid = key + '-' + id | ||
if (!client.upstreamSubscriptions[uid]) { | ||
let subs = parse$3(meta.subscriptions[key], hub); | ||
client.upstreamSubscriptions[uid] = subs; | ||
briskyStruct.subscribe(hub, subs, update); | ||
hub.subscriptions[hub.subscriptions.length - 1].id = id; | ||
const subs = $2381345089(meta.subscriptions[key], hub, void 0, client) | ||
client.upstreamSubscriptions[uid] = subs | ||
$1662971556.subscribe(hub, subs, update) | ||
hub.subscriptions[hub.subscriptions.length - 1]._uid_ = id | ||
} | ||
} | ||
}; | ||
} | ||
const Server = WebSocket.Server; | ||
; | ||
const removeSubscriptions = (t, id) => { | ||
if (t.subscriptions) { | ||
let i = t.subscriptions.length; | ||
while (i--) { // clean this up with unsubscribe in struct | ||
if (t.subscriptions[i].id === id) t.subscriptions.splice(i, 1); | ||
var $4215278899_removedInProgress | ||
const $4215278899_on = { | ||
data: { | ||
remove$: (val, stamp, struct) => { | ||
// just do a diff with the payload rly the best way for now... | ||
if (val === null && (!struct._c || struct._cLevel === 1)) { | ||
let p = struct | ||
let hub | ||
while (p) { | ||
if (p.port && !p._c) { hub = p } | ||
p = p.parent() | ||
} | ||
if (hub) { | ||
// probably not working correctly with context | ||
const target = struct.parent() | ||
if (target) { | ||
if (!target._removed) { | ||
target._removed = [] | ||
if (!$4215278899_removedInProgress) { | ||
$4215278899_removedInProgress = [] | ||
$826337949.on(() => { | ||
let i = $4215278899_removedInProgress.length | ||
while (i--) { | ||
delete $4215278899_removedInProgress[i]._removed | ||
} | ||
}) | ||
} | ||
$4215278899_removedInProgress.push(target) | ||
} | ||
target._removed.push(struct) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
const create$1 = (hub, port) => { | ||
const server = new Server({ port }); | ||
server.on('connection', (socket) => { | ||
var $4215278899 = $4215278899_on | ||
; | ||
const $899748844_Server = $1971361117.Server | ||
const $899748844_createServer = (hub, port) => { | ||
const server = new $899748844_Server({ port }) | ||
console.log(`💫 hub listening on ${port} 💫`) | ||
server.on('connection', socket => { | ||
socket.useragent = socket.upgradeReq && socket.upgradeReq.headers['user-agent'] | ||
// need to remove when done -- its the best thing todo (mem!!!) | ||
socket.on('message', (data) => { | ||
data = JSON.parse(data); | ||
if (data) { incoming(hub, socket, data); } | ||
}); | ||
data = JSON.parse(data) | ||
if (data) $834150420(hub, socket, data) | ||
}) | ||
const close = () => { | ||
const client = socket.client; | ||
if (client) { | ||
const stamp = bs.create('disconnect'); | ||
const id = client.key; | ||
const t = client.parent(2); | ||
removeSubscriptions(t, id); | ||
client.set(null, stamp); | ||
if (client.context && t.clients.keys().length === (t.url ? 1 : 0)) { | ||
t.set(null, stamp); | ||
} | ||
bs.close(); | ||
} | ||
}; | ||
if (socket.client) $1380346132_removeClient(socket.client) | ||
} | ||
socket.on('close', close); | ||
socket.on('close', close) | ||
// socket.on('error', () => close()) // need to do something here as well no leaks! | ||
}); | ||
}) | ||
return server | ||
}; | ||
} | ||
const removeServer = hub => { | ||
const server = hub.server; | ||
const instances = hub.instances; | ||
closeConnections(hub); | ||
const $899748844_removeServer = hub => { | ||
const server = hub._server_ | ||
const instances = hub.instances | ||
$899748844_closeConnections(hub) | ||
for (let i = 0, len = instances && instances.length; i < len; i++) { | ||
closeConnections(instances[i]); | ||
$899748844_closeConnections(instances[i]) | ||
} | ||
server.httpServer.close(); | ||
server.httpServer.close() | ||
// remove all clients subscriptions | ||
hub.server = null; | ||
}; | ||
hub._server_ = null | ||
} | ||
const closeConnections = hub => { | ||
const clients = hub.clients; | ||
const id = hub.id; // to exclude the client (not nessecary) | ||
const $899748844_closeConnections = hub => { | ||
const clients = hub.clients | ||
const id = hub._uid_ // to exclude the client (not nessecary) | ||
if (clients) { | ||
clients.forEach(client => { | ||
if (client.socket && client.key !== id) { | ||
client.val = null; | ||
removeSubscriptions(hub, client.key); | ||
client.socket.close(); | ||
client.val = null | ||
$1380346132_removeSubscriptions(hub, client.key) | ||
client.socket.close() | ||
} | ||
}); | ||
}) | ||
} | ||
}; | ||
} | ||
const removePort = hub => { | ||
hub.port = null; | ||
hub.serverIndex = null; | ||
hub.emitters.set({ data: { port$: null } }); | ||
}; | ||
const $899748844_removePort = hub => { | ||
hub.port = null | ||
hub.serverIndex = null | ||
hub.emitters.set({ data: { port$: null } }) | ||
} | ||
const port = (hub, val) => { | ||
const $899748844_port = (hub, val, key, stamp) => { | ||
// use remove | ||
hub.on((val, stamp, t) => { | ||
if (val === null && !t._c && t === hub) { | ||
removeServer(hub); | ||
removePort(hub); | ||
$899748844_removeServer(hub) | ||
$899748844_removePort(hub) | ||
} | ||
}, 'port$'); | ||
if (!val) val = null; | ||
if (val !== hub.port) { | ||
if (hub.server) { | ||
removeServer(hub); | ||
}, 'port$') | ||
if (!val) val = null | ||
if ((!hub.port && val) || (hub.port.compute() !== val)) { | ||
if (hub._server_) { | ||
$899748844_removeServer(hub) | ||
} | ||
if (!val) { | ||
removePort(hub); | ||
if (hub.port) hub.port.set(null, stamp) | ||
$899748844_removePort(hub) | ||
} else { | ||
hub.port = val; | ||
let i = -1; | ||
if (hub.key) i++; | ||
hub.parent(() => { i++; }); | ||
hub.serverIndex = i; | ||
hub.server = create$1(hub, val); | ||
} | ||
} | ||
}; | ||
const props$1 = { | ||
server: true, | ||
serverIndex: true, | ||
port | ||
}; | ||
var removedInProgress; | ||
const on$1 = { | ||
data: { | ||
remove$: (val, stamp, struct$$1) => { | ||
if (val === null && (!struct$$1._c || struct$$1._cLevel === 1)) { | ||
let p = struct$$1; | ||
let hub; | ||
while (p) { | ||
if (p.port && !p._c) { hub = p; } | ||
p = p.parent(); | ||
} | ||
if (hub) { | ||
const target = struct$$1.parent(); | ||
if (target) { | ||
if (!target._removed) { | ||
target._removed = []; | ||
if (!removedInProgress) { | ||
removedInProgress = []; | ||
bs.on(() => { | ||
let i = removedInProgress.length; | ||
while (i--) { | ||
delete removedInProgress[i]._removed; | ||
} | ||
}); | ||
if (!hub.port) { | ||
$1662971556.create({ | ||
on: { | ||
data: { | ||
port: (val, stamp, struct) => { | ||
val = struct.compute() | ||
if (val) { | ||
let i = -1 | ||
if (hub.key) i++ | ||
hub.parent(() => { i++ }) | ||
hub.serverIndex = i | ||
hub._server_ = $899748844_createServer(hub, val) | ||
} | ||
} | ||
removedInProgress.push(target); | ||
} | ||
struct$$1._p._removed.push(struct$$1); | ||
} | ||
} | ||
}, stamp, $1662971556.struct, hub, key) | ||
} | ||
hub.port.set(val, stamp) | ||
} | ||
} | ||
}; | ||
} | ||
const $899748844_props = { | ||
_server_: true, | ||
serverIndex: true, | ||
port: $899748844_port | ||
} | ||
var $899748844 = { props: $899748844_props, on: $4215278899 } | ||
var server = Object.freeze({ | ||
props: props$1, | ||
on: on$1 | ||
}); | ||
; | ||
const props$2 = { contextKey: true }; | ||
const define$1 = { | ||
getContext (val) { | ||
var result = find(this, val); | ||
if (!result) { | ||
result = this.create({ contextKey: val }, false); | ||
} | ||
return result | ||
} | ||
}; | ||
const find = (hub, val) => { | ||
const instances = hub.instances; | ||
if (instances) { | ||
let i = instances.length; | ||
while (i--) { | ||
if (instances[i].contextKey === val) { | ||
// console.log('found context --->', val, instances[i].clients.keys()) | ||
return instances[i] | ||
} | ||
} | ||
} | ||
}; | ||
const $4043401927_types = $1662971556.struct.props.types | ||
var context$1 = Object.freeze({ | ||
props: props$2, | ||
define: define$1 | ||
}); | ||
const types = briskyStruct.struct.props.types; | ||
const hub = briskyStruct.create({ | ||
const $4043401927_hub = $1662971556.create({ | ||
type: 'hub', | ||
@@ -844,56 +1051,63 @@ instances: false, | ||
default: 'self', | ||
id: (t, val) => { t.set({ define: { id: val } }); }, | ||
_uid_: (t, val) => { t.set({ define: { _uid_: val } }) }, | ||
types: $4043401927_types.bind(), // to not interfere with struct type | ||
type: $1662971556.struct.props.type.bind(), | ||
client: true | ||
} | ||
}) | ||
$4043401927_hub.props.types.struct = $4043401927_hub.create({ | ||
props: { default: $4043401927_types.struct.props.default.bind() } | ||
}, false) | ||
$4043401927_hub.props.types.struct.props.default.struct = $4043401927_hub.props.type.struct = $4043401927_hub | ||
$4043401927_hub.set({ | ||
types: { | ||
hub: 'self', | ||
clients: { | ||
type: 'struct', | ||
instances: false, | ||
props: { | ||
default: $4043401927_hub.create({ | ||
instances: false, | ||
props: { | ||
cache: true, | ||
upstreamSubscriptions: true, | ||
resolve: true, | ||
socket: true, | ||
context: true | ||
} | ||
}, false) | ||
} | ||
} | ||
}, | ||
props: { | ||
// why nto call this client id -- thats what it is | ||
clients: (t, val, key, stamp) => { | ||
if (!t.clients) { | ||
t.clients = briskyStruct.c(clients, val, stamp, t, key); | ||
const clients = $1662971556.getType(t, key) | ||
t.clients = $1662971556.create(val, stamp, clients, t, key) | ||
} else { | ||
briskyStruct.set(t.clients, val, stamp); | ||
$1662971556.set(t.clients, val, stamp) | ||
} | ||
}, | ||
types: types.bind(), // to not interfere with struct type | ||
type: briskyStruct.struct.props.type.bind(), | ||
client: true | ||
} | ||
}, | ||
id | ||
}); | ||
inject: [ $899748844, $3357289264_$ALL$, $2549126471 ] | ||
}, false) | ||
hub.props.types.struct = briskyStruct.c(hub, { | ||
props: { default: types.struct.props.default.bind() } | ||
}); | ||
$4043401927_hub.types._ks = void 0 | ||
hub.props.types.struct.props.default.struct = hub.props.type.struct = hub; | ||
var $4043401927 = $4043401927_hub | ||
hub.set({ types: { hub: 'self' }, inject: [ server, context$1, client ] }, false); | ||
; | ||
hub.types._ks = void 0; | ||
if (typeof __filename !== 'undefined') console.log('hub.js:', __filename) | ||
const clients = briskyStruct.create({ | ||
props: { | ||
default: hub.create({ | ||
props: { | ||
cache: true, | ||
upstreamSubscriptions: true, | ||
resolve: true, | ||
socket: true, | ||
context: true | ||
} | ||
}) | ||
} | ||
}); | ||
const $3474573222_fn = (val, stamp) => $4043401927.create(val, stamp) | ||
var $3474573222 = $3474573222_fn | ||
// import bs from 'brisky-stamp' | ||
// add uids to stamps else it sucks -- dont compromise for tests think of that as an after thought | ||
var index = (val, stamp) => { | ||
if (stamp === void 0) { | ||
const r = hub.create(val, bs.create()); | ||
bs.close(); | ||
return r | ||
} else { | ||
return hub.create(val, stamp) | ||
} | ||
}; | ||
// add uids to stamps else it sucks -- dont compromise for tests think of that as an after thought | ||
module.exports = index; | ||
//# sourceMappingURL=index.js.map | ||
module.exports = $3474573222 |
{ | ||
"name": "hub.js", | ||
"description": "Seamless realtime communcation", | ||
"version": "0.0.10", | ||
"version": "0.0.11-0016abee966964da3f44d97929e2809db006e7a9", | ||
"main": "dist/index.js", | ||
"module": "dist/index.es.js", | ||
"jsnext:main": "dist/index.es.js", | ||
"browser": { | ||
"./dist/index.js": "./dist/browser.js", | ||
"./dist/index.es.js": "./dist/browser.es.js", | ||
"./lib/uid/index.js": "./lib/uid/browser.js", | ||
"./lib/server/index.js": "./lib/server/browser.js", | ||
"./lib/client/websocket/index.js": "./lib/client/websocket/browser.js" | ||
"./dist/index.js": "./dist/index.browser.js", | ||
"./src/client/uid/index.js": "./src/client/uid/browser.js", | ||
"./src/server/index.js": "./src/server/browser.js", | ||
"./src/client/websocket/index.js": "./src/client/websocket/browser.js", | ||
"source-map-support": false | ||
}, | ||
"scripts": { | ||
"build": "node rollup/build", | ||
"pretest": "npm run build && standard", | ||
"build": "builder-boy src/index.js dist/index.js -r -t node -t browser", | ||
"watch": "builder-boy src/index.js dist/index.js -w -r -t node -t browser", | ||
"dev": "nodemon --watch dist --watch test --exec 'node test/index.js'", | ||
"pretest": "npm run build", | ||
"preversion": "npm run precommit", | ||
"precommit": "npm run test && standard --fix", | ||
"version-commit": "npm --no-git-tag-version version $(node -pe \"require('./package.json').version.split('-')[0]\")-$(git log -n 1 --pretty=format:'%H')", | ||
"publish-branch": "npm run version-commit && npm publish --tag $(git rev-parse --abbrev-ref HEAD | sed 's/\\//-/g')", | ||
"prepublish": "npm run build", | ||
"watch": "node rollup/watch", | ||
"postinstall": "[ -d dist ] || npm run build || ( mkdir dist && yarn && npm run build )", | ||
"test": "node test/index.js", | ||
"dev": "node rollup/watch & nodemon --harmony-async-await test/index.js", | ||
"cover": "nyc npm test", | ||
"travis": "nyc npm test && nyc report --reporter=text-lcov | coveralls" | ||
}, | ||
"precommit": "precommit", | ||
"repository": { | ||
@@ -43,7 +45,7 @@ "type": "git", | ||
"dependencies": { | ||
"brisky-stamp": "^3.0.12", | ||
"brisky-struct": "^1.1.7", | ||
"stamp": "^4.0.1", | ||
"brisky-struct": "^1.4.1", | ||
"string-hash": "^1.1.0", | ||
"uws": "0.12.0", | ||
"vigour-ua": "^2.2.3" | ||
"uws": "0.13.0", | ||
"vigour-ua": "^3.1.1" | ||
}, | ||
@@ -58,13 +60,7 @@ "nyc": { | ||
"devDependencies": { | ||
"source-map-support": "^0.4.7", | ||
"buble": "0.15.1", | ||
"builder-boy": "latest", | ||
"coveralls": "^2.11.9", | ||
"nodemon": "^1.11.0", | ||
"coveralls": "^2.11.9", | ||
"nyc": "^10.0.0", | ||
"pre-commit": "^1.1.3", | ||
"rollup": "^0.37.0", | ||
"rollup-plugin-commonjs": "^6.0.0", | ||
"rollup-plugin-istanbul": "^1.1.0", | ||
"rollup-plugin-node-resolve": "^2.0.0", | ||
"rollup-watch": "^2.5.0", | ||
"standard": "^8.1.0", | ||
@@ -71,0 +67,0 @@ "tape": "4.6.0" |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
475571
7
14
6796
0
3
+ Addedstamp@^4.0.1
+ Addedvigour-ua@3.1.6(transitive)
- Removedbrisky-stamp@^3.0.12
- Removedbrisky-stamp@3.0.12(transitive)
- Removeddom-walk@0.1.2(transitive)
- Removedglobal@4.4.0(transitive)
- Removedmin-document@2.19.0(transitive)
- Removedprocess@0.11.10(transitive)
- Removedvigour-ua@2.2.3(transitive)
Updatedbrisky-struct@^1.4.1
Updateduws@0.13.0
Updatedvigour-ua@^3.1.1