statebus 7.0.6 → 7.0.9

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/client-library.js CHANGED
@@ -661,7 +661,7 @@
661
661
  get: function (o, k) { return o[k] },
662
662
  set: function (o, k, v) {
663
663
  o[k] = v
664
- make_component(k, v)
664
+ window[k] = make_component(k, v)
665
665
  return true
666
666
  }
667
667
  })
@@ -713,7 +713,7 @@
713
713
 
714
714
  // ... or at least most of them -- there are just a few missing from
715
715
  // this list.
716
- var all_tags = 'a,abbr,address,area,article,aside,audio,b,base,bdi,bdo,blockquote,body,br,button,canvas,caption,cite,code,col,colgroup,data,datalist,dd,del,details,dfn,dialog,div,dl,dt,em,embed,fieldset,figcaption,figure,footer,form,h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,i,iframe,img,ins,kbd,label,legend,li,link,main,map,mark,menu,meta,meter,nav,noscript,object,ol,optgroup,option,output,p,param,picture,pre,progress,q,s,samp,script,section,select,slot,small,source,span,strong,style,sub,summary,sup,table,tbody,td,template,tfoot,th,thead,title,tr,u,ul,video,input'.split(',')
716
+ var all_tags = 'a,abbr,address,area,article,aside,audio,b,base,bdi,bdo,blockquote,br,button,canvas,caption,cite,code,col,colgroup,data,datalist,dd,del,details,dfn,dialog,div,dl,dt,em,embed,fieldset,figcaption,figure,footer,form,h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,i,iframe,img,ins,kbd,label,legend,li,link,main,map,mark,menu,meta,meter,nav,noscript,object,ol,optgroup,option,output,p,param,picture,pre,progress,q,s,samp,script,section,select,slot,small,source,span,strong,style,sub,summary,sup,svg,table,tbody,td,template,tfoot,th,thead,title,tr,u,ul,video,input,circle,ellipse,g,image,line,path,polygon,polyline,rect,switch,symbol,text,textPath,tspan,use'.split(',')
717
717
  all_tags.forEach((tagname) => {
718
718
  window[tagname.toUpperCase()] = function_for_tag(tagname)
719
719
  })
@@ -721,8 +721,8 @@
721
721
  // We create special functions for INPUT and TEXTAREA, because they
722
722
  // have to do extra work to maintain the cursor when we use statebus
723
723
  // instead of React's setState() for state updates.
724
- window.INPUT = function_for_tag(make_fixed_textbox('input'))
725
- window.TEXTAREA = function_for_tag(make_fixed_textbox('textarea'))
724
+ window.INPUT = function_for_tag(bus.libs.react17.input)
725
+ window.TEXTAREA = function_for_tag(bus.libs.react17.textarea)
726
726
 
727
727
 
728
728
  // Improve the functions ^^^ put this above
@@ -809,6 +809,12 @@
809
809
  })
810
810
  }
811
811
 
812
+ // We create special functions for INPUT and TEXTAREA, because they
813
+ // have to do extra work to maintain the cursor when we use statebus
814
+ // instead of React's setState() for state updates.
815
+ bus.libs.react17.input = make_fixed_textbox('input')
816
+ bus.libs.react17.textarea = make_fixed_textbox('textarea')
817
+
812
818
  function autodetect_args (func) {
813
819
  if (func.args) return
814
820
 
@@ -823,8 +829,7 @@
823
829
  var users_widgets = {}
824
830
  function make_component(name, func) {
825
831
  // Define the component
826
-
827
- window[name] = users_widgets[name] = create_react_class({
832
+ return users_widgets[name] = create_react_class({
828
833
  displayName: name,
829
834
  render: function () {
830
835
  var args = []
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "statebus",
3
- "version": "7.0.6",
3
+ "version": "7.0.9",
4
4
  "description": "Synchronize state.",
5
5
  "main": "statebus.js",
6
6
  "scripts": {
package/server-library.js CHANGED
@@ -145,8 +145,11 @@ function import_server (bus, make_statebus, options)
145
145
  // If this requests knows about Braid then we presume the programmer
146
146
  // knows that any client might make this cross-origin request.
147
147
  if (req.headers.version || req.headers.parents || req.headers.subscribe
148
+ || req.headers.peer || req.headers['put-order']
148
149
  || req.method === 'OPTIONS')
149
150
  free_the_cors(req, res)
151
+ if (req.method === 'OPTIONS')
152
+ return
150
153
 
151
154
  // Initialize new clients with an id. We put the client id on
152
155
  // req.client, and also in a cookie for the browser to see.
@@ -258,7 +261,7 @@ function import_server (bus, make_statebus, options)
258
261
  if (req.headers.peer) {
259
262
  let peer = req.headers.peer,
260
263
  key = obj.key
261
- var cb = cbus.http_callbacks[
264
+ var cb = cbus.http_callbacks && cbus.http_callbacks[
262
265
  JSON.stringify({peer, key})
263
266
  ]
264
267
  if (cb) cb.has_seen(cbus, key, t.version)
@@ -1691,6 +1694,11 @@ function import_server (bus, make_statebus, options)
1691
1694
  },
1692
1695
 
1693
1696
  serves_auth: function serves_auth (conn, master) {
1697
+ // Right now, we only support accounts at '@username', but in general
1698
+ // we could allow the prefix to be configurable. We just have to go
1699
+ // through this function and make all the regular expressions (like
1700
+ // /@*.../) parameterizable.
1701
+ var prefix = '@'
1694
1702
  var client = this // to keep me straight while programming
1695
1703
  function logout (user_key) {
1696
1704
  var clients = master.get('logged_in_clients')
@@ -1747,7 +1755,7 @@ function import_server (bus, make_statebus, options)
1747
1755
  master.auth_initialized = true
1748
1756
  master.get('users/passwords')
1749
1757
 
1750
- master('user/*').deleter = (key, t) => {
1758
+ master(prefix + '*').deleter = (key, t) => {
1751
1759
  master.log('Deleteinggg!!!', key)
1752
1760
  // Remove from users.all
1753
1761
  var users = master.get('users')
@@ -1820,11 +1828,11 @@ function import_server (bus, make_statebus, options)
1820
1828
  // might create it, even though the account hasn't been created
1821
1829
  // yet, and then this will rename it to some random ID.
1822
1830
  //
1823
- var key = 'user/' + params.name
1831
+ var key = prefix + params.name
1824
1832
  if (!params.name)
1825
- key = 'user/' + Math.random().toString(36).substring(7,13)
1833
+ key = prefix + Math.random().toString(36).substring(7,13)
1826
1834
  while (master.cache.hasOwnProperty(key))
1827
- key = 'user/' + Math.random().toString(36).substring(7,13)
1835
+ key = prefix + Math.random().toString(36).substring(7,13)
1828
1836
 
1829
1837
  // Make account object
1830
1838
  var new_account = {
@@ -1964,15 +1972,15 @@ function import_server (bus, make_statebus, options)
1964
1972
  }
1965
1973
  client('current_user').deleter = function () {}
1966
1974
 
1967
- // Users have closet space at /user/<name>/*
1968
- var closet_space_key = /^(user\/[^\/]+)\/.*/
1969
- var private_closet_space_key = /^user\/[^\/]+\/private.*/
1975
+ // Users have closet space at @<name>/*
1976
+ var closet_space_key = /^(@[^\/]+)\/.*/
1977
+ var private_closet_space_key = /^@[^\/]+\/private.*/
1970
1978
 
1971
1979
  // User
1972
- client('user/*').setter = function (o, t) {
1980
+ client(prefix + '*').setter = function (o, t) {
1973
1981
  var c = client.get('current_user')
1974
- var user_key = o.key.match(/^user\/([^\/]+)/)
1975
- user_key = user_key && ('user/' + user_key[1])
1982
+ var user_key = o.key.match(/^@([^\/]+)/)
1983
+ user_key = user_key && (prefix + user_key[1])
1976
1984
 
1977
1985
  // Only the current user can touch himself.
1978
1986
  if (!c.val.logged_in || c.val.user.link !== user_key) {
@@ -1985,7 +1993,7 @@ function import_server (bus, make_statebus, options)
1985
1993
  return
1986
1994
  }
1987
1995
 
1988
- // Users have closet space at /user/<name>/*
1996
+ // Users have closet space at @<name>/*
1989
1997
  if (o.key.match(closet_space_key)) {
1990
1998
  client.log('saving closet data')
1991
1999
  master.set(o, t)
@@ -1993,7 +2001,7 @@ function import_server (bus, make_statebus, options)
1993
2001
  }
1994
2002
 
1995
2003
  // Ok, then it must be a plain user
1996
- console.assert(o.key.match(/^user\/[^\/]+$/))
2004
+ console.assert(o.key.match(/^@[^\/]+$/))
1997
2005
 
1998
2006
  // Validate types
1999
2007
  if (!client.validate(o, {key: 'string',
@@ -2072,11 +2080,11 @@ function import_server (bus, make_statebus, options)
2072
2080
 
2073
2081
  master.set(u)
2074
2082
  }
2075
- client('user/*').getter = function user_getter (k) {
2083
+ client(prefix + '*').getter = function user_getter (k) {
2076
2084
  var c = client.get('current_user')
2077
2085
  client.log('* getting:', k, 'as', c.val.user)
2078
2086
 
2079
- // Users have closet space at /user/<name>/*
2087
+ // Users have closet space at @<name>/*
2080
2088
  if (k.match(closet_space_key)) {
2081
2089
  var obj_user = k.match(closet_space_key)[1]
2082
2090
  if (k.match(private_closet_space_key)
@@ -2091,10 +2099,10 @@ function import_server (bus, make_statebus, options)
2091
2099
  // Otherwise return the actual user
2092
2100
  return user_obj(k, c.val.logged_in && c.val.user.link === k)
2093
2101
  }
2094
- client('user/*').deleter = function () {}
2102
+ client(prefix + '*').deleter = function () {}
2095
2103
  function user_obj (k, logged_in) {
2096
2104
  var o = master.clone(master.get(k))
2097
- if (k.match(/^user\/([^\/]+)\/private\/(.*)$/))
2105
+ if (k.match(/^@([^\/]+)\/private\/(.*)$/))
2098
2106
  return logged_in ? o : {key: k}
2099
2107
 
2100
2108
  o.val = o.val || {}
@@ -2434,7 +2442,7 @@ function import_server (bus, make_statebus, options)
2434
2442
  path = path || 'client.js'
2435
2443
  bus.http.get('/' + path, (req, res) => {
2436
2444
  var files =
2437
- ['extras/coffee.js', 'extras/sockjs.js', 'extras/react.js',
2445
+ ['extras/coffee.js', 'extras/sockjs.js',
2438
2446
  'statebus.js', 'client.js'].map((f) => fs.readFileSync('node_modules/statebus/' + f))
2439
2447
  files.unshift(fs.readFileSync(
2440
2448
  'node_modules/braidify/braidify-client.js'
@@ -2530,7 +2538,7 @@ function free_the_cors (req, res, next) {
2530
2538
  var free_the_cors = {
2531
2539
  "Access-Control-Allow-Origin": "*",
2532
2540
  "Access-Control-Allow-Methods": "OPTIONS, HEAD, GET, PUT, UNSUBSCRIBE",
2533
- "Access-Control-Allow-Headers": "subscribe, peer, version, parents, merge-type, content-type, patches, cache-control"
2541
+ "Access-Control-Allow-Headers": "subscribe, peer, version, parents, merge-type, content-type, patches, cache-control, put-order"
2534
2542
  }
2535
2543
  Object.entries(free_the_cors).forEach(x => res.setHeader(x[0], x[1]))
2536
2544
  if (req.method === 'OPTIONS') {