@live-change/server 0.7.39 → 0.8.1

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/index.js CHANGED
@@ -1,20 +1,19 @@
1
- const Renderer = require('./lib/Renderer.js')
2
- const Services = require('./lib/Services.js')
3
- const SsrServer = require('./lib/SsrServer.js')
4
- const TestServer = require('./lib/TestServer.js')
1
+ import Renderer from './lib/Renderer.js'
2
+ import Services from './lib/Services.js'
3
+ import SsrServer from './lib/SsrServer.js'
4
+ import TestServer from './lib/TestServer.js'
5
5
 
6
- const createLoopbackDao = require('./lib/createLoopbackDao.js')
7
- const renderTemplate = require('./lib/renderTemplate.js')
8
- const setupApiServer = require('./lib/setupApiServer.js')
9
- const setupApiSockJs = require('./lib/setupApiSockJs.js')
10
- const setupApiWs = require('./lib/setupApiWs.js')
11
- const setupApiEndpoints = require('./lib/setupApiEndpoints.js')
12
- const setupDbServer = require('./lib/setupDbServer.js')
13
- const setupDbClient = require('./lib/setupDbClient.js')
14
- const setupApp = require('./lib/setupApp.js')
15
-
16
- module.exports = {
6
+ import createLoopbackDao from './lib/createLoopbackDao.js'
7
+ import renderTemplate from './lib/renderTemplate.js'
8
+ import setupApiServer from './lib/setupApiServer.js'
9
+ import setupApiSockJs from './lib/setupApiSockJs.js'
10
+ import setupApiWs from './lib/setupApiWs.js'
11
+ import setupApiEndpoints from './lib/setupApiEndpoints.js'
12
+ import setupDbServer from './lib/setupDbServer.js'
13
+ import setupDbClient from './lib/setupDbClient.js'
14
+ import setupApp from './lib/setupApp.js'
17
15
 
16
+ export {
18
17
  Renderer,
19
18
  Services,
20
19
  SsrServer,
@@ -29,5 +28,4 @@ module.exports = {
29
28
  setupDbServer,
30
29
  setupDbClient,
31
30
  setupApp
32
-
33
- }
31
+ }
package/lib/Renderer.js CHANGED
@@ -1,9 +1,9 @@
1
- const fs = require('fs')
2
- const path = require('path')
3
- const serialize = require('serialize-javascript')
4
- const renderTemplate = require('./renderTemplate.js')
5
-
6
- const { SitemapStream } = require('sitemap')
1
+ import fs from 'fs'
2
+ import path from 'path'
3
+ import * as vite from 'vite'
4
+ import serialize from 'serialize-javascript'
5
+ import renderTemplate from './renderTemplate.js'
6
+ import { SitemapStream } from 'sitemap'
7
7
 
8
8
  class Renderer {
9
9
  constructor(manifest, settings) {
@@ -16,7 +16,7 @@ class Renderer {
16
16
  if(this.settings.dev) {
17
17
  await this.setupVite()
18
18
  } else {
19
- const serverEntryPath = path.resolve(this.root, this.settings.serverEntry ?? './dist/server/entry-server.mjs')
19
+ const serverEntryPath = path.resolve(this.root, this.settings.serverEntry ?? './dist/server/entry-server.js')
20
20
  this.module = await import(serverEntryPath)
21
21
  this.renderer = this.module.render
22
22
  this.sitemap = this.module.sitemap
@@ -26,7 +26,7 @@ class Renderer {
26
26
  }
27
27
 
28
28
  async setupVite() {
29
- this.vite = await require('vite').createServer({
29
+ this.vite = await vite.createServer({
30
30
  root: this.root,
31
31
  mode: this.settings.mode,
32
32
  logLevel: 'info', //isTest ? 'error' : 'info',
@@ -174,4 +174,4 @@ class Renderer {
174
174
 
175
175
  }
176
176
 
177
- module.exports = Renderer
177
+ export default Renderer
package/lib/Services.js CHANGED
@@ -1,17 +1,26 @@
1
- const { def } = require('@vue/shared')
2
- const fs = require('fs')
3
- const path = require('path')
4
- const resolve = require('util').promisify(require('resolve'))
5
- const app = require("@live-change/framework").app()
1
+ import fs from 'fs'
2
+ import path from 'path'
3
+ import { promisify } from 'util'
4
+ import resolveCb from 'resolve'
5
+ const resolve = promisify(resolveCb)
6
+ import App from "@live-change/framework"
7
+ const app = App.app()
6
8
 
7
- const debug = require('debug')('framework')
9
+ import Debug from 'debug'
10
+ const debug = Debug('framework')
8
11
 
9
12
  class Services {
10
- constructor(configPath) {
11
- if(!configPath) throw new Error("services config parameter is required")
12
- this.configPath = path.resolve(configPath)
13
- this.config = require(path.resolve(this.configPath))
14
- this.servicesDir = path.dirname(this.configPath)
13
+ constructor(config) {
14
+ if(!config) throw new Error("services config parameter is required")
15
+ if(typeof config == 'string') {
16
+ this.configPath = path.resolve(config)
17
+ this.servicesDir = path.dirname(this.configPath)
18
+ this.configPromise = import(path.resolve(this.configPath)).then(x => x.default)
19
+ this.config = null
20
+ } else {
21
+ this.config = config
22
+ this.configPromise = Promise.resolve(config)
23
+ }
15
24
 
16
25
  this.plugins = []
17
26
  this.serviceDefinitions = []
@@ -29,32 +38,52 @@ class Services {
29
38
  return path
30
39
  }
31
40
 
32
- servicesList() {
41
+ async servicesList() {
42
+ this.config = await this.configPromise
33
43
  return this.config.services.map(s => s.name)
34
44
  }
35
- serviceConfig(serviceName) {
45
+ async serviceConfig(serviceName) {
46
+ this.config = await this.configPromise
36
47
  return this.config.services.find(s => s.name = serviceName)
37
48
  }
38
49
  async loadServices() {
50
+
51
+ this.config = await this.configPromise
39
52
  app.config.services = this.config.services
40
53
  app.config.plugins = this.config.plugins
54
+
41
55
  if(this.config.plugins) {
42
56
  for(const plugin of this.config.plugins) {
43
- const entryFile = await this.getServiceEntryFile(plugin)
44
- debug("PLUGIN", plugin, 'ENTRY FILE', entryFile)
45
- this.plugins.push((await import(entryFile)).default)
57
+ if(plugin.module) {
58
+ const module = plugin.module
59
+ const definition = module
60
+ this.plugins.push(definition)
61
+ } else {
62
+ const entryFile = await this.getServiceEntryFile(plugin)
63
+ debug("PLUGIN", plugin, 'ENTRY FILE', entryFile)
64
+ const module = await import(entryFile)
65
+ this.plugins.push(module.default)
66
+ }
46
67
  }
47
68
  }
48
69
  if(this.config.services) {
49
70
  for(const service of this.config.services) {
50
- const entryFile = await this.getServiceEntryFile(service)
51
- debug("SERVICE", service, 'ENTRY FILE', entryFile)
52
- const definition = (await import(entryFile)).default
53
- if(definition.name != service.name) {
54
- console.error("SERVICE", service, "NAME", service.name, "MISMATCH", definition.name)
55
- process.exit(1)
71
+ if(service.module) {
72
+ const module = service.module
73
+ const definition = module
74
+ this.serviceDefinitions.push(definition)
75
+ //console.log("SERVICE DEFINITION", definition, "OF", service)
76
+ } else {
77
+ const entryFile = await this.getServiceEntryFile(service)
78
+ debug("SERVICE", service, 'ENTRY FILE', entryFile)
79
+ const module = await import(entryFile)
80
+ const definition = module.default
81
+ if (definition.name != service.name) {
82
+ console.error("SERVICE", service, "NAME", service.name, "MISMATCH", definition.name)
83
+ process.exit(1)
84
+ }
85
+ this.serviceDefinitions.push(definition)
56
86
  }
57
- this.serviceDefinitions.push(definition)
58
87
  }
59
88
  }
60
89
 
@@ -139,16 +168,18 @@ class Services {
139
168
  // when starting all services at once remove triggerRoutes for cleanup
140
169
  await app.dao.request(['database', 'deleteTable'], app.databaseName, 'triggerRoutes').catch(e => 'ok')
141
170
  await Promise.all(this.plugins.map(plugin => plugin(app, this)))
142
- this.services = await Promise.all(this.serviceDefinitions.map(defn => {
171
+ this.servicesPromise = Promise.all(this.serviceDefinitions.map(defn => {
143
172
  if(!defn.processed) {
144
173
  app.processServiceDefinition(defn)
145
174
  defn.processed = true
146
175
  }
147
176
  return app.startService(defn, startOptions)
148
177
  }))
178
+ this.services = await this.servicesPromise
149
179
  }
150
180
 
151
- getServicesObject() {
181
+ async getServicesObject() {
182
+ await this.servicesPromise
152
183
  let object = {}
153
184
  for(const service of this.services) object[service.name] = service
154
185
  return object
@@ -156,4 +187,4 @@ class Services {
156
187
 
157
188
  }
158
189
 
159
- module.exports = Services
190
+ export default Services
package/lib/SsrServer.js CHANGED
@@ -1,16 +1,17 @@
1
- const cookie = require('cookie')
2
- const path = require('path')
3
- const serveStatic = require('serve-static')
4
- const crypto = require('crypto')
5
- const expressStaticGzip = require("express-static-gzip")
1
+ import cookie from 'cookie'
2
+ import path from 'path'
3
+ import crypto from 'crypto'
4
+ import os from 'os'
5
+ import expressStaticGzip from "express-static-gzip"
6
6
 
7
- const serverDao = require('./serverDao.js')
8
- const { hashCode, encodeNumber, uidGenerator } = require('@live-change/uid')
9
- const getIp = require('./getIp.js')
7
+ import serverDao from './serverDao.js'
8
+ import { hashCode, encodeNumber, uidGenerator } from '@live-change/uid'
9
+ import getIp from './getIp.js'
10
10
 
11
- const Renderer = require('./Renderer.js')
11
+ import Renderer from './Renderer.js'
12
+
13
+ import { fbRedirect } from './fbRedirect.js'
12
14
 
13
- const { fbRedirect } = require('./fbRedirect.js')
14
15
 
15
16
  class SsrServer {
16
17
  constructor(express, manifest, settings) {
@@ -24,7 +25,7 @@ class SsrServer {
24
25
  }
25
26
 
26
27
  this.instanceId = encodeNumber(hashCode(
27
- `ssr${process.pid}${require("os").hostname()} ${process.cwd()}/${process.argv.join(' ')}`))
28
+ `ssr${process.pid}${os.hostname()} ${process.cwd()}/${process.argv.join(' ')}`))
28
29
  this.uidGenerator = uidGenerator(this.instanceId, 1, this.settings.uidBorders)
29
30
 
30
31
  this.root = this.settings.root || process.cwd()
@@ -165,4 +166,4 @@ class SsrServer {
165
166
  }
166
167
  }
167
168
 
168
- module.exports = SsrServer
169
+ export default SsrServer
package/lib/TestServer.js CHANGED
@@ -1,17 +1,18 @@
1
- const path = require('path')
2
- const http = require('http')
3
- const express = require('express')
4
-
5
- const app = require('@live-change/framework').app()
6
-
7
- const { hashCode, encodeNumber, uidGenerator } = require('@live-change/uid')
8
-
9
- const setupApiServer = require('./setupApiServer.js')
10
- const setupApiSockJs = require('./setupApiSockJs.js')
11
- const setupApiWs = require('./setupApiWs.js')
12
- const setupDbServer = require('./setupDbServer.js')
13
- const createLoopbackDao = require('./createLoopbackDao.js')
14
- const SsrServer = require('./SsrServer.js')
1
+ import path from 'path'
2
+ import http from 'http'
3
+ import express from 'express'
4
+
5
+ import App from '@live-change/framework'
6
+ const app = App.app()
7
+
8
+ import { hashCode, encodeNumber, uidGenerator } from '@live-change/uid'
9
+ import setupApiServer from './setupApiServer.js'
10
+ import setupApiSockJs from './setupApiSockJs.js'
11
+ import setupApiWs from './setupApiWs.js'
12
+ import setupDbServer from './setupDbServer.js'
13
+ import createLoopbackDao from './createLoopbackDao.js'
14
+ import SsrServer from './SsrServer.js'
15
+ import fs from "fs";
15
16
 
16
17
  class TestServer {
17
18
  constructor(config) {
@@ -21,9 +22,9 @@ class TestServer {
21
22
  async start() {
22
23
  this.expressApp = express()
23
24
 
24
- this.manifest = this.config.dev ? null : require(
25
- path.resolve(this.config.ssrRoot, 'dist/client/ssr-manifest.json')
26
- )
25
+ const manifest = (dev || argv.spa)
26
+ ? null
27
+ : JSON.parse(fs.readFileSync((path.resolve(ssrRoot, 'dist/client/.vite/ssr-manifest.json'))))
27
28
 
28
29
  app.instanceId = encodeNumber(hashCode(
29
30
  `app${process.pid}${require("os").hostname()} ${process.cwd()}/${process.argv.join(' ')}`))
@@ -90,4 +91,4 @@ class TestServer {
90
91
  }
91
92
  }
92
93
 
93
- module.exports = TestServer
94
+ export default TestServer
@@ -1,4 +1,4 @@
1
- const Dao = require("@live-change/dao")
1
+ import Dao from "@live-change/dao"
2
2
 
3
3
  async function createLoopbackDao(credentials, daoFactory) {
4
4
  const server = new Dao.ReactiveServer(daoFactory)
@@ -24,4 +24,4 @@ async function createLoopbackDao(credentials, daoFactory) {
24
24
  return dao
25
25
  }
26
26
 
27
- module.exports = createLoopbackDao
27
+ export default createLoopbackDao
package/lib/fbRedirect.js CHANGED
@@ -30,7 +30,7 @@ function fbRedirect(req, res) {
30
30
  }
31
31
  }
32
32
 
33
- module.exports = {
33
+ export {
34
34
  isAppSpecificUserAgent,
35
35
  isIOs,
36
36
  fbRedirect
package/lib/getIp.js CHANGED
@@ -9,4 +9,4 @@ function getIp(connection) {
9
9
  return ip
10
10
  }
11
11
 
12
- module.exports = getIp
12
+ export default getIp
@@ -19,4 +19,4 @@ function renderTemplate(source, replacements) {
19
19
  return output.join('')
20
20
  }
21
21
 
22
- module.exports = renderTemplate
22
+ export default renderTemplate
package/lib/serverDao.js CHANGED
@@ -1,5 +1,5 @@
1
- const { Dao } = require("@live-change/dao")
2
- const DaoWebsocket = require("@live-change/dao-websocket")
1
+ import Dao from "@live-change/dao"
2
+ import { client as DaoWebsocket } from "@live-change/dao-websocket"
3
3
 
4
4
  function reactiveObservableListConstructor(reactive) {
5
5
  class ReactiveObservableList extends Dao.ObservableList {
@@ -53,4 +53,4 @@ function serverDao(credentials, ip, settings) {
53
53
  })
54
54
  }
55
55
 
56
- module.exports = serverDao
56
+ export default serverDao
@@ -1,5 +1,3 @@
1
- const { app } = require("@live-change/framework")
2
-
3
1
  async function setupApiEndpoints(expressApp, apiServer) {
4
2
  for(const serviceDefinition of apiServer.services.serviceDefinitions) {
5
3
  const { name, endpoints } = serviceDefinition
@@ -14,4 +12,4 @@ async function setupApiEndpoints(expressApp, apiServer) {
14
12
  }
15
13
  }
16
14
 
17
- module.exports = setupApiEndpoints
15
+ export default setupApiEndpoints
@@ -1,9 +1,8 @@
1
- const cookie = require("cookie")
2
- const Dao = require("@live-change/dao")
3
- const { connection } = require("websocket")
4
- const Services = require('../lib/Services.js')
5
- const app = require("@live-change/framework").app()
6
- const DaoWebsocket = require("@live-change/dao-websocket")
1
+ import Dao from "@live-change/dao"
2
+ import Services from '../lib/Services.js'
3
+ import App from "@live-change/framework"
4
+ const app = App.app()
5
+ import * as DaoWebsocket from "@live-change/dao-websocket"
7
6
 
8
7
  async function setupApiServer(settings) {
9
8
  const { services: config, withServices, updateServices } = settings
@@ -12,6 +11,7 @@ async function setupApiServer(settings) {
12
11
  const list = await app.dao.get(['database', 'databasesList'])
13
12
  console.log("existing databases:", list.join(', '))
14
13
  console.log("creating database", app.databaseName)
14
+
15
15
  await app.dao.request(['database', 'createDatabase'], app.databaseName, {
16
16
  storage: { noMetaSync: true, noSync: true }
17
17
  }).catch(err => 'exists')
@@ -20,14 +20,19 @@ async function setupApiServer(settings) {
20
20
  const services = new Services(config)
21
21
 
22
22
  await services.loadServices()
23
+
23
24
  if(updateServices) await services.update()
24
25
  await services.start(withServices
25
26
  ? { runCommands: true, handleEvents: true, indexSearch: true }
26
27
  : { runCommands: false, handleEvents: false, indexSearch: false })
27
28
 
28
29
  if(settings.initScript) {
29
- const initScript = await import(await services.resolve(settings.initScript))
30
- await (initScript.default || initScript)(services.getServicesObject())
30
+ if(config.init) {
31
+ config.init(await services.getServicesObject())
32
+ } else {
33
+ const initScript = await import(await services.resolve(settings.initScript))
34
+ await (initScript.default || initScript)(await services.getServicesObject())
35
+ }
31
36
  }
32
37
 
33
38
  const apiServerConfig = {
@@ -76,13 +81,7 @@ async function setupApiServer(settings) {
76
81
  shareDefinition: true,
77
82
  logErrors: true,
78
83
  createSessionOnUpdate: true, /// deprecated - moved to session-service settings
79
- fastAuth: settings.fastAuth /* && ((connection) => {
80
- const cookies = cookie.parse(connection.headers.cookie || '')
81
- return {
82
- sesionId: cookies.sessionId,
83
- sessionKey: cookies.sessionKey
84
- }
85
- }) */
84
+ fastAuth: settings.fastAuth
86
85
  }
87
86
 
88
87
  const apiServer = await app.createLiveApiServer(apiServerConfig)
@@ -92,4 +91,4 @@ async function setupApiServer(settings) {
92
91
  return apiServer
93
92
  }
94
93
 
95
- module.exports = setupApiServer
94
+ export default setupApiServer
@@ -1,4 +1,4 @@
1
- const sockjs = require('@live-change/sockjs')
1
+ import sockjs from '@live-change/sockjs'
2
2
 
3
3
  function setupApiSockJs(httpServer, apiServer) {
4
4
  const sockJsServer = sockjs.createServer({
@@ -18,4 +18,4 @@ function setupApiSockJs(httpServer, apiServer) {
18
18
  return sockJsServer
19
19
  }
20
20
 
21
- module.exports = setupApiSockJs
21
+ export default setupApiSockJs
package/lib/setupApiWs.js CHANGED
@@ -1,5 +1,5 @@
1
- const WebSocketServer = require('websocket').server
2
- const DaoWebsocket = require("@live-change/dao-websocket")
1
+ import { server as WebSocketServer} from 'websocket'
2
+ import * as DaoWebsocket from "@live-change/dao-websocket"
3
3
 
4
4
  function setupApiWs(httpServer, apiServer) {
5
5
  const wsServer = new WebSocketServer({ httpServer, autoAcceptConnections: false })
@@ -12,4 +12,4 @@ function setupApiWs(httpServer, apiServer) {
12
12
  return wsServer
13
13
  }
14
14
 
15
- module.exports = setupApiWs
15
+ export default setupApiWs
package/lib/setupApp.js CHANGED
@@ -1,15 +1,20 @@
1
- const { hashCode, encodeNumber, uidGenerator } = require('@live-change/uid')
1
+ import os from 'os'
2
2
 
3
- const setupDbServer = require('./setupDbServer.js')
4
- const setupDbClient = require('./setupDbClient.js')
5
- const createLoopbackDao = require('./createLoopbackDao.js')
3
+ import { hashCode, encodeNumber, uidGenerator }from '@live-change/uid'
6
4
 
7
- const debug = require('debug')('server:app')
5
+ import setupDbServer from './setupDbServer.js'
6
+ import setupDbClient from './setupDbClient.js'
7
+ import createLoopbackDao from './createLoopbackDao.js'
8
+
9
+ import Debug from 'debug'
10
+ const debug = Debug('server:app')
11
+
12
+ import App from "@live-change/framework"
8
13
 
9
14
  async function setupApp(settings, env = process.env) {
10
- const app = require("@live-change/framework").app()
15
+ const app = App.app()
11
16
  app.instanceId = encodeNumber(hashCode(
12
- `app${process.pid}${require("os").hostname()} ${process.cwd()}/${process.argv.join(' ')}`))
17
+ `app${process.pid}${os.hostname()} ${process.cwd()}/${process.argv.join(' ')}`))
13
18
  app.uidGenerator = uidGenerator(app.instanceId, 1, settings.uidBorders)
14
19
  debug("SETUP APP", settings)
15
20
  let dbServer
@@ -23,4 +28,4 @@ async function setupApp(settings, env = process.env) {
23
28
  app.databaseName = env.DB_NAME || 'test'
24
29
  }
25
30
 
26
- module.exports = setupApp
31
+ export default setupApp
@@ -1,6 +1,5 @@
1
-
2
- const ReactiveDao = require("@live-change/dao")
3
- const ReactiveDaoWebsocket = require("@live-change/dao-websocket")
1
+ import ReactiveDao from "@live-change/dao"
2
+ import * as ReactiveDaoWebsocket from "@live-change/dao-websocket"
4
3
 
5
4
  function setupDbClient(argv, env = process.env) {
6
5
  const config = {
@@ -38,4 +37,4 @@ function setupDbClient(argv, env = process.env) {
38
37
  return dbDao
39
38
  }
40
39
 
41
- module.exports = setupDbClient
40
+ export default setupDbClient
@@ -1,5 +1,5 @@
1
- const path = require('path')
2
- const DbServer = require('@live-change/db-server')
1
+ import path from 'path'
2
+ import DbServer from '@live-change/db-server'
3
3
 
4
4
  async function setupDbServer(settings) {
5
5
  const { dbRoot, dbBackend, dbBackendUrl, dbSlowStart } = settings
@@ -24,4 +24,4 @@ async function setupDbServer(settings) {
24
24
  return server
25
25
  }
26
26
 
27
- module.exports = setupDbServer
27
+ export default setupDbServer
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/server",
3
- "version": "0.7.39",
3
+ "version": "0.8.1",
4
4
  "description": "Live Change Framework - server",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -19,24 +19,25 @@
19
19
  "bugs": {
20
20
  "url": "https://github.com/live-change/live-change-framework/issues"
21
21
  },
22
+ "type": "module",
22
23
  "homepage": "https://github.com/live-change/live-change-framework",
23
24
  "dependencies": {
24
- "@live-change/dao": "0.5.22",
25
- "@live-change/dao-sockjs": "0.5.22",
26
- "@live-change/db-server": "0.6.23",
27
- "@live-change/framework": "^0.7.39",
25
+ "@live-change/dao": "0.6.0",
26
+ "@live-change/dao-sockjs": "0.6.0",
27
+ "@live-change/db-server": "0.7.3",
28
+ "@live-change/framework": "^0.8.1",
28
29
  "@live-change/sockjs": "0.4.1",
29
- "@live-change/uid": "^0.7.39",
30
- "dotenv": "^16.0.3",
30
+ "@live-change/uid": "^0.8.1",
31
+ "dotenv": "^16.4.4",
31
32
  "express": "^4.18.2",
32
33
  "express-static-gzip": "2.1.7",
33
34
  "http-proxy-middleware": "2.0.6",
34
- "resolve": "^1.22.1",
35
- "serialize-javascript": "^6.0.1",
35
+ "resolve": "^1.22.8",
36
+ "serialize-javascript": "^6.0.2",
36
37
  "sitemap": "^7.1.1",
37
- "vite": "^4.4.9",
38
+ "vite": "^5.1.1",
38
39
  "websocket": "^1.0.34",
39
- "yargs": "^17.5.1"
40
+ "yargs": "^17.7.2"
40
41
  },
41
- "gitHead": "9e9cd47f2fb1c3c82b20fdddbc5505c99e1e1c68"
42
+ "gitHead": "d26056b63edb7fecb98c6b9ee14eba859360f900"
42
43
  }