@live-change/framework 0.8.6 → 0.8.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/lib/App.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { uidGenerator
|
|
1
|
+
import {randomString, uidGenerator} from '@live-change/uid'
|
|
2
2
|
|
|
3
3
|
import ReactiveDao from "@live-change/dao"
|
|
4
4
|
|
|
@@ -36,6 +36,7 @@ import SplitEmitQueue from "./utils/SplitEmitQueue.js"
|
|
|
36
36
|
import SingleEmitQueue from "./utils/SingleEmitQueue.js"
|
|
37
37
|
|
|
38
38
|
import Debug from 'debug'
|
|
39
|
+
|
|
39
40
|
const debug = Debug('framework')
|
|
40
41
|
|
|
41
42
|
class App {
|
|
@@ -86,6 +87,7 @@ class App {
|
|
|
86
87
|
|
|
87
88
|
this.startedServices = {}
|
|
88
89
|
this.triggerRoutes = {}
|
|
90
|
+
this.globalViews = {}
|
|
89
91
|
}
|
|
90
92
|
|
|
91
93
|
createServiceDefinition( definition ) {
|
|
@@ -177,9 +179,19 @@ class App {
|
|
|
177
179
|
console.log("service started", serviceDefinition.name, "!")
|
|
178
180
|
await this.profileLog.end(profileOp)
|
|
179
181
|
this.startedServices[serviceDefinition.name] = service
|
|
182
|
+
|
|
183
|
+
for(const viewName in serviceDefinition.views) {
|
|
184
|
+
const view = serviceDefinition.views[viewName]
|
|
185
|
+
if(view.global) this.globalViews[viewName] = view
|
|
186
|
+
}
|
|
187
|
+
|
|
180
188
|
return service
|
|
181
189
|
}
|
|
182
190
|
|
|
191
|
+
async createDao( config, clientData ) {
|
|
192
|
+
return new Dao(config, clientData)
|
|
193
|
+
}
|
|
194
|
+
|
|
183
195
|
async createReactiveDao( config, clientData ) {
|
|
184
196
|
return new Dao(config, clientData)
|
|
185
197
|
}
|
|
@@ -541,6 +553,35 @@ class App {
|
|
|
541
553
|
this.dao.dispose()
|
|
542
554
|
}
|
|
543
555
|
|
|
556
|
+
|
|
557
|
+
serviceViewObservable(serviceName, viewName, params) {
|
|
558
|
+
const service = this.startedServices[serviceName]
|
|
559
|
+
const view = service.views[viewName]
|
|
560
|
+
if(!view) throw new Error(`View ${viewName} not found in service ${serviceName}`)
|
|
561
|
+
const result = view.observable(params)
|
|
562
|
+
return result.then ? new LcDao.ObservablePromiseProxy(result) : result
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
async serviceViewGet(serviceName, viewName, params) {
|
|
566
|
+
const service = this.startedServices[serviceName]
|
|
567
|
+
const view = service.views[viewName]
|
|
568
|
+
if(!view) throw new Error(`View ${viewName} not found in service ${serviceName}`)
|
|
569
|
+
return await view.get(params)
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
viewObservable(viewName, params) {
|
|
573
|
+
const view = this.globalViews[viewName]
|
|
574
|
+
if(!view) throw new Error(`Global view ${viewName} not found`)
|
|
575
|
+
const result = view.observable(params)
|
|
576
|
+
return result.then ? new LcDao.ObservablePromiseProxy(result) : result
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
async viewGet(viewName, params) {
|
|
580
|
+
const view = this.globalViews[viewName]
|
|
581
|
+
if(!view) throw new Error(`Global view ${viewName} not found`)
|
|
582
|
+
return await view.get(params)
|
|
583
|
+
}
|
|
584
|
+
|
|
544
585
|
}
|
|
545
586
|
|
|
546
587
|
export default App
|
|
@@ -71,7 +71,6 @@ function createForeignIndexProxy(definition, model) {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
class ServiceDefinition {
|
|
74
|
-
|
|
75
74
|
constructor(definition) {
|
|
76
75
|
this.models = {}
|
|
77
76
|
this.foreignModels = {}
|
|
@@ -79,6 +78,7 @@ class ServiceDefinition {
|
|
|
79
78
|
this.foreignIndexes = {}
|
|
80
79
|
this.actions = {}
|
|
81
80
|
this.views = {}
|
|
81
|
+
this.internalViews = {}
|
|
82
82
|
this.events = {}
|
|
83
83
|
this.triggers = {}
|
|
84
84
|
this.use = []
|
|
@@ -3,10 +3,18 @@ export default function getAccessMethod(access) {
|
|
|
3
3
|
return access
|
|
4
4
|
} else if(Array.isArray(access)) {
|
|
5
5
|
return (params, { service, client }) => {
|
|
6
|
+
if(client.internal) return true
|
|
6
7
|
if(client.roles.includes('administrator')) return true
|
|
7
8
|
if(client.roles.includes('admin')) return true
|
|
8
9
|
for(let role of access) if(client.roles.includes(role)) return true
|
|
9
10
|
return false
|
|
10
11
|
}
|
|
11
|
-
} else
|
|
12
|
+
} else if(access === 'internal') {
|
|
13
|
+
return (params, { service, client }) => {
|
|
14
|
+
if(client.internal) return true
|
|
15
|
+
if(client.roles.includes('administrator')) return true
|
|
16
|
+
if(client.roles.includes('admin')) return true
|
|
17
|
+
return false
|
|
18
|
+
}
|
|
19
|
+
} else throw new Error("unknown view access definition " + access)
|
|
12
20
|
}
|
|
@@ -18,4 +18,21 @@ export default function(service, app) {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
+
for(let viewName in service.internalViews) {
|
|
22
|
+
const view = service.internalViews[viewName]
|
|
23
|
+
if(view.fetch) {
|
|
24
|
+
if(!view.observable) view.observable = async (...args) => {
|
|
25
|
+
try {
|
|
26
|
+
const data = await view.fetch(...args)
|
|
27
|
+
return new ReactiveDao.ObservableValue(data)
|
|
28
|
+
} catch(error) {
|
|
29
|
+
console.error(error)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if(!view.get) view.get = async (...args) => {
|
|
33
|
+
const path = await view.fetch(...args)
|
|
34
|
+
return path
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
21
38
|
}
|
package/lib/runtime/ApiServer.js
CHANGED
|
@@ -27,7 +27,7 @@ class ApiServer {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
async daoFactory(credentialsp, ip) {
|
|
30
|
-
let credentials = { ...credentialsp, ip, roles: [] }
|
|
30
|
+
let credentials = { ...credentialsp, ip, roles: [], ignoreRemoteViews: false }
|
|
31
31
|
const allAuthenticators = []
|
|
32
32
|
if(this.config.authenticators) {
|
|
33
33
|
const auth = Array.isArray(this.config.authenticators)
|
package/lib/runtime/View.js
CHANGED
|
@@ -10,6 +10,16 @@ class View {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
async observable(parameters, clientData) {
|
|
13
|
+
if(this.definition.remote) {
|
|
14
|
+
if(clientData?.ignoreRemoteView) {
|
|
15
|
+
return this.service.app.serviceViewObservable(this.service.name, this.name, {
|
|
16
|
+
...parameters,
|
|
17
|
+
___forwardedClientData: clientData
|
|
18
|
+
})
|
|
19
|
+
} else if(!this.definition.internal) {
|
|
20
|
+
clientData = parameters.___forwardedClientData ?? clientData
|
|
21
|
+
}
|
|
22
|
+
}
|
|
13
23
|
const context = {
|
|
14
24
|
service: this.service, client: clientData
|
|
15
25
|
}
|
|
@@ -20,6 +30,16 @@ class View {
|
|
|
20
30
|
}
|
|
21
31
|
|
|
22
32
|
async get(parameters, clientData) {
|
|
33
|
+
if(this.definition.remote) {
|
|
34
|
+
if(clientData?.ignoreRemoteView) {
|
|
35
|
+
return this.service.app.serviceViewGet(this.service.name, this.name, {
|
|
36
|
+
...parameters,
|
|
37
|
+
___forwardedClientData: clientData
|
|
38
|
+
})
|
|
39
|
+
} else if(!this.definition.internal) {
|
|
40
|
+
clientData = parameters.___forwardedClientData ?? clientData
|
|
41
|
+
}
|
|
42
|
+
}
|
|
23
43
|
const context = {
|
|
24
44
|
service: this.service, client: clientData
|
|
25
45
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/framework",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.8",
|
|
4
4
|
"description": "Live Change Framework - ultimate solution for real time mobile/web apps",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
},
|
|
23
23
|
"homepage": "https://github.com/live-change/live-change-framework",
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@live-change/dao": "^0.8.
|
|
26
|
-
"@live-change/uid": "^0.8.
|
|
25
|
+
"@live-change/dao": "^0.8.8",
|
|
26
|
+
"@live-change/uid": "^0.8.8"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "77eafa414e091c8d34ae63ee8927d53f3bde893d"
|
|
29
29
|
}
|