@live-change/vue3-ssr 0.1.4 → 0.1.8
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/clientApi.js +3 -3
- package/index.js +49 -9
- package/package.json +4 -3
- package/generateUuid.js +0 -21
- package/getIp.js +0 -12
- package/serverDao.js +0 -56
package/clientApi.js
CHANGED
|
@@ -2,7 +2,7 @@ import { createReactiveObject } from '@live-change/vue3-components'
|
|
|
2
2
|
import * as lcapi from '@live-change/vue-api'
|
|
3
3
|
import * as lcdao from '@live-change/dao'
|
|
4
4
|
import { reactiveMixin, reactivePrefetchMixin, ReactiveObservableList } from '@live-change/dao-vue3'
|
|
5
|
-
import
|
|
5
|
+
import SockJsConnection from '@live-change/dao-sockjs'
|
|
6
6
|
|
|
7
7
|
function clientApi(settings = {}) {
|
|
8
8
|
const dao = new lcdao.Dao(window.__CREDENTIALS__, {
|
|
@@ -13,9 +13,9 @@ function clientApi(settings = {}) {
|
|
|
13
13
|
|
|
14
14
|
...settings,
|
|
15
15
|
|
|
16
|
-
fastAuth: !window.hasOwnProperty('__CREDENTIALS__'),
|
|
17
|
-
|
|
18
16
|
connectionSettings: {
|
|
17
|
+
fastAuth: !window.hasOwnProperty('__CREDENTIALS__'),
|
|
18
|
+
|
|
19
19
|
queueRequestsWhenDisconnected: true,
|
|
20
20
|
requestSendTimeout: Infinity,
|
|
21
21
|
requestTimeout: Infinity,
|
package/index.js
CHANGED
|
@@ -1,35 +1,75 @@
|
|
|
1
|
-
import { getCurrentInstance } from 'vue'
|
|
2
|
-
import { live as d3live } from '@live-change/dao-vue3'
|
|
1
|
+
import { getCurrentInstance, onUnmounted } from 'vue'
|
|
2
|
+
import { live as d3live, RangeBuckets } from '@live-change/dao-vue3'
|
|
3
3
|
|
|
4
4
|
function path(app) {
|
|
5
5
|
app = app || getCurrentInstance()
|
|
6
|
-
return app.appContext.config.globalProperties.$fetch
|
|
6
|
+
return app.appContext.config.globalProperties.$lc.fetch
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
function api(app) {
|
|
10
10
|
app = app || getCurrentInstance()
|
|
11
|
-
return app.appContext.config.globalProperties.$
|
|
11
|
+
return app.appContext.config.globalProperties.$lc
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
function view(app) {
|
|
15
15
|
app = app || getCurrentInstance()
|
|
16
|
-
return app.appContext.config.globalProperties.$view
|
|
16
|
+
return app.appContext.config.globalProperties.$lc.view
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
function actions(app) {
|
|
20
20
|
app = app || getCurrentInstance()
|
|
21
|
-
return app.appContext.config.globalProperties.$actions
|
|
21
|
+
return app.appContext.config.globalProperties.$lc.actions
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
function live(path) {
|
|
25
25
|
const app = getCurrentInstance()
|
|
26
|
-
const api = app.appContext.config.globalProperties.$
|
|
26
|
+
const api = app.appContext.config.globalProperties.$lc
|
|
27
27
|
return d3live(api, path)
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
async function rangeBuckets(pathFunction, options, app) {
|
|
31
|
+
app = app || getCurrentInstance()
|
|
32
|
+
const api = app.appContext.config.globalProperties.$lc
|
|
33
|
+
const extendedPathFunction = (range) => pathFunction(range, api.fetch)
|
|
34
|
+
const buckets = new RangeBuckets(api, extendedPathFunction, options)
|
|
35
|
+
if(app) {
|
|
36
|
+
onUnmounted(() => {
|
|
37
|
+
buckets.dispose()
|
|
38
|
+
})
|
|
39
|
+
} else {
|
|
40
|
+
console.error("live fetch outside component instance - possible memory leak")
|
|
41
|
+
}
|
|
42
|
+
await buckets.wait()
|
|
43
|
+
return {
|
|
44
|
+
buckets: buckets.buckets,
|
|
45
|
+
loadTop: () => buckets.loadTop(),
|
|
46
|
+
loadBottom: () => buckets.loadBottom(),
|
|
47
|
+
dropTop: () => buckets.dropTop(),
|
|
48
|
+
dropBottom: () => buckets.dropBottom(),
|
|
49
|
+
canLoadTop: () => buckets.isTopLoadPossible(),
|
|
50
|
+
canLoadBottom: () => buckets.isBottomLoadPossible(),
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function reverseRange(range) {
|
|
55
|
+
return {
|
|
56
|
+
gt: range.lt,
|
|
57
|
+
gte: range.lte,
|
|
58
|
+
lt: range.gt == '' ? '\xFF\xFF\xFF\xFF' : range.gt,
|
|
59
|
+
lte: range.gte,
|
|
60
|
+
limit: range.limit,
|
|
61
|
+
reverse: !range.reverse
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
30
65
|
function client(app) {
|
|
31
66
|
app = app || getCurrentInstance()
|
|
32
|
-
return app.appContext.config.globalProperties.$client
|
|
67
|
+
return app.appContext.config.globalProperties.$lc.client
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function uid(app) {
|
|
71
|
+
app = app || getCurrentInstance()
|
|
72
|
+
return app.appContext.config.globalProperties.$lc.uid
|
|
33
73
|
}
|
|
34
74
|
|
|
35
|
-
export { path, api, view, actions, live, client }
|
|
75
|
+
export { path, api, view, actions, live, client, uid, rangeBuckets, reverseRange }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/vue3-ssr",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "Live Change Framework - vue components",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,8 +21,9 @@
|
|
|
21
21
|
},
|
|
22
22
|
"homepage": "https://github.com/live-change/vue3-ssr",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@vue/server-renderer": "^3.2.21",
|
|
25
24
|
"debug": "^4.3.2",
|
|
26
|
-
"vue": "^3.2.
|
|
25
|
+
"vue": "^3.2.21",
|
|
26
|
+
"@live-change/vue-api": "^0.1.10",
|
|
27
|
+
"@live-change/uid": "^0.1.3"
|
|
27
28
|
}
|
|
28
29
|
}
|
package/generateUuid.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
const crypto = require('crypto')
|
|
2
|
-
function uuidFromBytes(rnd) {
|
|
3
|
-
rnd[6] = (rnd[6] & 0x0f) | 0x40
|
|
4
|
-
rnd[8] = (rnd[8] & 0x3f) | 0x80
|
|
5
|
-
rnd = rnd.toString('hex').match(/(.{8})(.{4})(.{4})(.{4})(.{12})/)
|
|
6
|
-
rnd.shift()
|
|
7
|
-
return rnd.join('-')
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function genUuid(callback) {
|
|
11
|
-
if (typeof(callback) !== 'function') {
|
|
12
|
-
return uuidFromBytes(crypto.randomBytes(16))
|
|
13
|
-
}
|
|
14
|
-
crypto.randomBytes(16, function(err, rnd) {
|
|
15
|
-
if (err) return callback(err)
|
|
16
|
-
callback(null, uuidFromBytes(rnd))
|
|
17
|
-
})
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
module.exports = genUuid
|
|
21
|
-
|
package/getIp.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
function getIp(connection) {
|
|
2
|
-
let ip =
|
|
3
|
-
connection.headers['x-real-ip'] ||
|
|
4
|
-
connection.headers['x-forwarded-for'] ||
|
|
5
|
-
connection.remoteAddress ||
|
|
6
|
-
(connection.connection && connection.connection.remoteAddress)
|
|
7
|
-
ip = ip.split(',')[0]
|
|
8
|
-
ip = ip.split(':').slice(-1)[0] //in case the ip returned in a format: "::ffff:146.xxx.xxx.xxx"
|
|
9
|
-
return ip
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
module.exports = getIp
|
package/serverDao.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
const { Dao } = require("@live-change/dao")
|
|
2
|
-
const DaoWebsocket = require("@live-change/dao-websocket")
|
|
3
|
-
|
|
4
|
-
function reactiveObservableListConstructor(reactive) {
|
|
5
|
-
class ReactiveObservableList extends Dao.ObservableList {
|
|
6
|
-
constructor(value, what, dispose) {
|
|
7
|
-
super(value, what, dispose, (data) => {
|
|
8
|
-
if(data && typeof data == 'object') {
|
|
9
|
-
const activated = reactive(data)
|
|
10
|
-
return activated
|
|
11
|
-
}
|
|
12
|
-
return data
|
|
13
|
-
})
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return ReactiveObservableList
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function serverDao(credentials, ip, settings) {
|
|
20
|
-
const serverHost = settings.remoteUrl || process.env.API_SERVER || "localhost:" + (process.env.API_PORT || 8002)
|
|
21
|
-
const wsServer = `ws://${serverHost}/api/ws`
|
|
22
|
-
|
|
23
|
-
return new Dao(credentials, {
|
|
24
|
-
remoteUrl: wsServer,
|
|
25
|
-
protocols: {
|
|
26
|
-
'ws': DaoWebsocket.client
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
...settings,
|
|
30
|
-
|
|
31
|
-
connectionSettings: {
|
|
32
|
-
headers: {
|
|
33
|
-
'X-real-ip': ip,
|
|
34
|
-
'X-forwarded-for': ip
|
|
35
|
-
},
|
|
36
|
-
queueRequestsWhenDisconnected: true,
|
|
37
|
-
requestSendTimeout: 2300,
|
|
38
|
-
requestTimeout: 10000,
|
|
39
|
-
queueActiveRequestsOnDisconnect: false,
|
|
40
|
-
autoReconnectDelay: 200,
|
|
41
|
-
logLevel: 1,
|
|
42
|
-
/*connectionMonitorFactory: (connection) =>
|
|
43
|
-
new ReactiveDao.ConnectionMonitorPinger(connection, {
|
|
44
|
-
pingInterval: 50,
|
|
45
|
-
pongInterval: 200
|
|
46
|
-
})*/
|
|
47
|
-
...(settings && settings.connectionSettings)
|
|
48
|
-
},
|
|
49
|
-
defaultRoute: {
|
|
50
|
-
type: "remote",
|
|
51
|
-
generator: settings.reactive ? reactiveObservableListConstructor(settings.reactive) : Dao.ObservableList
|
|
52
|
-
}
|
|
53
|
-
})
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
module.exports = serverDao
|