@live-change/server 0.8.5 → 0.8.7
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/setupApiServer.js +33 -0
- package/lib/setupApp.js +12 -7
- package/lib/setupDbClient.js +19 -19
- package/lib/setupDbServer.js +30 -2
- package/package.json +7 -7
package/lib/setupApiServer.js
CHANGED
|
@@ -86,6 +86,39 @@ async function setupApiServer(settings) {
|
|
|
86
86
|
|
|
87
87
|
const apiServer = await app.createLiveApiServer(apiServerConfig)
|
|
88
88
|
|
|
89
|
+
const internalCredentials = { internal: true, roles: ['admin'] }
|
|
90
|
+
|
|
91
|
+
let serviceRemotes = {}
|
|
92
|
+
if(settings.withServices) {
|
|
93
|
+
const localServer = new Dao.ReactiveServer(
|
|
94
|
+
() => app.createDao(apiServerConfig, { ...internalCredentials, ignoreRemoteView: true })
|
|
95
|
+
)
|
|
96
|
+
const loopback = new Dao.LoopbackConnection('local', localServer, {})
|
|
97
|
+
const localConfig = {
|
|
98
|
+
type: 'remote',
|
|
99
|
+
generator: Dao.ObservableList,
|
|
100
|
+
protocol: 'local',
|
|
101
|
+
url: 'services'
|
|
102
|
+
}
|
|
103
|
+
app.dao.definition = {
|
|
104
|
+
...app.dao.definition,
|
|
105
|
+
protocols: { ...app.dao.definition.protocols, local: null },
|
|
106
|
+
...(typeof services.config.local === 'function' ? services.config.local(internalCredentials) : services.config.local),
|
|
107
|
+
...(typeof services.config.remote === 'function' ? services.config.remote(internalCredentials) : services.config.remote)
|
|
108
|
+
}
|
|
109
|
+
for(const service of services.services) {
|
|
110
|
+
app.dao.definition[service.name] = localConfig
|
|
111
|
+
}
|
|
112
|
+
app.dao.connections.set('local:services', loopback)
|
|
113
|
+
await loopback.initialize()
|
|
114
|
+
if(!loopback.connected) {
|
|
115
|
+
console.error("LOOPBACK NOT CONNECTED?!")
|
|
116
|
+
process.exit(1)
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
throw new Error("remote services not implemented")
|
|
120
|
+
}
|
|
121
|
+
|
|
89
122
|
apiServer.services = services
|
|
90
123
|
|
|
91
124
|
return apiServer
|
package/lib/setupApp.js
CHANGED
|
@@ -4,12 +4,12 @@ import { hashCode, encodeNumber, uidGenerator }from '@live-change/uid'
|
|
|
4
4
|
|
|
5
5
|
import setupDbServer from './setupDbServer.js'
|
|
6
6
|
import setupDbClient from './setupDbClient.js'
|
|
7
|
-
import createLoopbackDao from './createLoopbackDao.js'
|
|
8
7
|
|
|
9
8
|
import Debug from 'debug'
|
|
10
9
|
const debug = Debug('server:app')
|
|
11
10
|
|
|
12
11
|
import App from "@live-change/framework"
|
|
12
|
+
import Dao from "@live-change/dao"
|
|
13
13
|
|
|
14
14
|
async function setupApp(settings, env = process.env) {
|
|
15
15
|
const app = App.app()
|
|
@@ -17,15 +17,20 @@ async function setupApp(settings, env = process.env) {
|
|
|
17
17
|
`app${process.pid}${os.hostname()} ${process.cwd()}/${process.argv.join(' ')}`))
|
|
18
18
|
app.uidGenerator = uidGenerator(app.instanceId, 1, settings.uidBorders)
|
|
19
19
|
debug("SETUP APP", settings)
|
|
20
|
-
|
|
20
|
+
|
|
21
|
+
app.databaseName = env.DB_NAME || 'test'
|
|
22
|
+
|
|
23
|
+
await setupAppDao(settings)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function setupAppDao(settings, env = process.env) {
|
|
27
|
+
const app = App.app()
|
|
28
|
+
app.dao = new Dao('app', {})
|
|
21
29
|
if(settings.withDb) {
|
|
22
|
-
|
|
23
|
-
const loopbackDao = await createLoopbackDao('local', () => dbServer.createDao('local'))
|
|
24
|
-
app.dao = loopbackDao
|
|
30
|
+
await setupDbServer(settings)
|
|
25
31
|
} else {
|
|
26
|
-
|
|
32
|
+
await setupDbClient(settings)
|
|
27
33
|
}
|
|
28
|
-
app.databaseName = env.DB_NAME || 'test'
|
|
29
34
|
}
|
|
30
35
|
|
|
31
36
|
export default setupApp
|
package/lib/setupDbClient.js
CHANGED
|
@@ -1,20 +1,29 @@
|
|
|
1
1
|
import ReactiveDao from "@live-change/dao"
|
|
2
2
|
import * as ReactiveDaoWebsocket from "@live-change/dao-websocket"
|
|
3
|
+
import setupDbServer from "./setupDbServer.js"
|
|
4
|
+
import createLoopbackDao from "./createLoopbackDao.js"
|
|
5
|
+
import App from "@live-change/framework"
|
|
3
6
|
|
|
4
7
|
function setupDbClient(argv, env = process.env) {
|
|
5
8
|
const config = {
|
|
6
9
|
url: env.DB_URL,
|
|
7
10
|
name: env.DB_NAME,
|
|
8
11
|
requestTimeout: env.DB_REQUEST_TIMEOUT && +env.DB_REQUEST_TIMEOUT,
|
|
9
|
-
cache: env.DB_CACHE == "YES",
|
|
10
12
|
//unobserveDebug: env.UNOBSERVE_DEBUG == "YES",
|
|
11
13
|
}
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const app = App.app()
|
|
15
|
+
|
|
16
|
+
const remoteConfig = {
|
|
17
|
+
type: 'remote',
|
|
18
|
+
protocol: 'dbWs',
|
|
19
|
+
url: config?.url || "http://localhost:9417/api/ws",
|
|
20
|
+
generator: ReactiveDao.ObservableList,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
app.dao.definition = {
|
|
24
|
+
...app.dao.definition,
|
|
25
|
+
protocols: { ...app.dao.definition.protocols, dbWs: ReactiveDaoWebsocket.client },
|
|
26
|
+
connectionSettings: app.dao.definition.connectionSettings ?? {
|
|
18
27
|
queueRequestsWhenDisconnected: true,
|
|
19
28
|
requestSendTimeout: 2000,
|
|
20
29
|
requestTimeout: config.requestTimeout,
|
|
@@ -23,18 +32,9 @@ function setupDbClient(argv, env = process.env) {
|
|
|
23
32
|
logLevel: 1,
|
|
24
33
|
unobserveDebug: config?.unobserveDebug || false
|
|
25
34
|
},
|
|
26
|
-
database:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
},
|
|
30
|
-
store: {
|
|
31
|
-
type: 'remote',
|
|
32
|
-
generator: ReactiveDao.ObservableList
|
|
33
|
-
}
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
if(config?.cache) return new ReactiveDao.DaoCache(dbDao)
|
|
37
|
-
return dbDao
|
|
35
|
+
database: remoteConfig,
|
|
36
|
+
store: remoteConfig,
|
|
37
|
+
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
export default setupDbClient
|
package/lib/setupDbServer.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
2
|
import DbServer from '@live-change/db-server'
|
|
3
|
+
import App from "@live-change/framework"
|
|
4
|
+
import Dao from '@live-change/dao'
|
|
3
5
|
|
|
4
6
|
async function setupDbServer(settings) {
|
|
5
7
|
const { dbRoot, dbBackend, dbBackendUrl, dbSlowStart } = settings
|
|
6
|
-
console.info(`starting database in ${dbBackend
|
|
8
|
+
console.info(`starting database in ${dbBackend === 'mem' ? 'memory' : path.resolve(dbRoot)}`)
|
|
7
9
|
let server = new DbServer({
|
|
8
10
|
dbRoot,
|
|
9
11
|
backend: dbBackend,
|
|
10
12
|
backendUrl: dbBackendUrl,
|
|
11
13
|
slowStart: dbSlowStart,
|
|
12
|
-
temporary: dbBackend
|
|
14
|
+
temporary: dbBackend === "mem"
|
|
13
15
|
})
|
|
14
16
|
|
|
15
17
|
process.on('unhandledRejection', (reason, promise) => {
|
|
@@ -21,6 +23,32 @@ async function setupDbServer(settings) {
|
|
|
21
23
|
await server.initialize()
|
|
22
24
|
console.info(`database initialized!`)
|
|
23
25
|
|
|
26
|
+
const app = App.app()
|
|
27
|
+
|
|
28
|
+
const localServer = new Dao.ReactiveServer(() => server.createDao('local'))
|
|
29
|
+
const loopback = new Dao.LoopbackConnection('local', localServer, {})
|
|
30
|
+
const localConfig = {
|
|
31
|
+
type: 'remote',
|
|
32
|
+
generator: Dao.ObservableList,
|
|
33
|
+
protocol: 'local',
|
|
34
|
+
url: 'dao'
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
app.dao.definition = {
|
|
38
|
+
...app.dao.definition,
|
|
39
|
+
protocols: { ...app.dao.definition.protocols, local: null },
|
|
40
|
+
database: localConfig,
|
|
41
|
+
serverDatabase: localConfig,
|
|
42
|
+
store: localConfig,
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
app.dao.connections.set('local:dao', loopback)
|
|
46
|
+
await loopback.initialize()
|
|
47
|
+
if(!loopback.connected) {
|
|
48
|
+
console.error("LOOPBACK NOT CONNECTED?!")
|
|
49
|
+
process.exit(1)
|
|
50
|
+
}
|
|
51
|
+
|
|
24
52
|
return server
|
|
25
53
|
}
|
|
26
54
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/server",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.7",
|
|
4
4
|
"description": "Live Change Framework - server",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
"type": "module",
|
|
23
23
|
"homepage": "https://github.com/live-change/live-change-framework",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@live-change/dao": "^0.8.
|
|
26
|
-
"@live-change/dao-sockjs": "0.8.
|
|
27
|
-
"@live-change/db-server": "^0.8.
|
|
28
|
-
"@live-change/framework": "0.8.
|
|
25
|
+
"@live-change/dao": "^0.8.7",
|
|
26
|
+
"@live-change/dao-sockjs": "^0.8.7",
|
|
27
|
+
"@live-change/db-server": "^0.8.7",
|
|
28
|
+
"@live-change/framework": "^0.8.7",
|
|
29
29
|
"@live-change/sockjs": "0.4.1",
|
|
30
|
-
"@live-change/uid": "0.8.
|
|
30
|
+
"@live-change/uid": "^0.8.7",
|
|
31
31
|
"dotenv": "^16.4.4",
|
|
32
32
|
"express": "^4.18.2",
|
|
33
33
|
"express-static-gzip": "2.1.7",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"websocket": "^1.0.34",
|
|
40
40
|
"yargs": "^17.7.2"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "b00392ddc91b273e8e7b6d2bdf543f8fe0aec0ca"
|
|
43
43
|
}
|