@platformatic/runtime 0.40.0 → 0.41.0

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.
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
  const assert = require('node:assert')
3
3
  const { request } = require('undici')
4
- const { startCommand } = require('../lib/unified-api')
4
+ const { startCommand } = require('..')
5
5
 
6
6
  async function main () {
7
7
  const entrypoint = await startCommand(['-c', process.argv[2]])
@@ -1,5 +1,5 @@
1
1
  'use strict'
2
- const { startCommand } = require('../lib/unified-api')
2
+ const { startCommand } = require('..')
3
3
 
4
4
  async function main () {
5
5
  await startCommand(['-c', process.argv[2]])
@@ -1,5 +1,5 @@
1
1
  'use strict'
2
- const { start } = require('../lib/unified-api')
2
+ const { start } = require('..')
3
3
 
4
4
  async function main () {
5
5
  await start(['-c', process.argv[2]])
package/index.js CHANGED
@@ -1,15 +1,16 @@
1
1
  'use strict'
2
2
  const { buildServer } = require('./lib/build-server')
3
3
  const { platformaticRuntime } = require('./lib/config')
4
- const { start } = require('./lib/start')
5
- const unifiedApi = require('./lib/unified-api')
4
+ const { start, startCommand } = require('./lib/start')
6
5
  const RuntimeApi = require('./lib/api')
7
6
  const { compile } = require('./lib/compile')
7
+ const { loadConfig } = require('./lib/load-config')
8
8
 
9
9
  module.exports.buildServer = buildServer
10
10
  module.exports.platformaticRuntime = platformaticRuntime
11
11
  module.exports.schema = platformaticRuntime.schema
12
12
  module.exports.RuntimeApi = RuntimeApi
13
13
  module.exports.start = start
14
- module.exports.unifiedApi = unifiedApi
14
+ module.exports.startCommand = startCommand
15
15
  module.exports.compile = compile
16
+ module.exports.loadConfig = loadConfig
package/lib/app.js CHANGED
@@ -4,10 +4,8 @@ const { once } = require('node:events')
4
4
  const { dirname } = require('node:path')
5
5
  const { FileWatcher } = require('@platformatic/utils')
6
6
  const debounce = require('debounce')
7
- const {
8
- buildServer,
9
- loadConfig
10
- } = require('./unified-api')
7
+ const { buildServer } = require('./build-server')
8
+ const { loadConfig } = require('./load-config')
11
9
 
12
10
  class PlatformaticApp {
13
11
  #hotReload
@@ -2,8 +2,10 @@
2
2
  const ConfigManager = require('@platformatic/config')
3
3
  const { platformaticRuntime } = require('./config')
4
4
  const { startWithConfig } = require('./start')
5
+ const { buildServer: buildServerService } = require('@platformatic/service')
6
+ const { loadConfig } = require('./load-config')
5
7
 
6
- async function buildServer (options = {}) {
8
+ async function buildServerRuntime (options = {}) {
7
9
  if (!options.configManager) {
8
10
  // Instantiate a new config manager from the current options.
9
11
  const cm = new ConfigManager({
@@ -19,10 +21,26 @@ async function buildServer (options = {}) {
19
21
  }
20
22
  }
21
23
 
22
- // The transformConfig() function can't be sent between threads.
23
- delete options.configManager._transformConfig
24
-
25
24
  return startWithConfig(options.configManager)
26
25
  }
27
26
 
27
+ async function buildServer (options) {
28
+ if (typeof options === 'string') {
29
+ const config = await loadConfig({}, ['-c', options])
30
+ options = config.configManager.current
31
+ options.configManager = config.configManager
32
+ options.app = config.app
33
+ }
34
+
35
+ const app = options.app
36
+
37
+ delete options.app
38
+
39
+ if (app === platformaticRuntime || !app) {
40
+ return buildServerRuntime(options)
41
+ }
42
+
43
+ return buildServerService(options, app)
44
+ }
45
+
28
46
  module.exports = { buildServer }
package/lib/compile.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const { tsCompiler } = require('@platformatic/service')
4
- const { loadConfig } = require('./unified-api')
4
+ const { loadConfig } = require('./load-config')
5
5
  const { dirname } = require('node:path')
6
6
 
7
7
  const pino = require('pino')
@@ -0,0 +1,20 @@
1
+ 'use strict'
2
+
3
+ const { Store, loadConfig } = require('@platformatic/config')
4
+
5
+ const { platformaticService } = require('@platformatic/service')
6
+ const { platformaticDB } = require('@platformatic/db')
7
+ const { platformaticComposer } = require('@platformatic/composer')
8
+ const { platformaticRuntime } = require('./config')
9
+
10
+ const store = new Store()
11
+ store.add(platformaticService)
12
+ store.add(platformaticDB)
13
+ store.add(platformaticComposer)
14
+ store.add(platformaticRuntime)
15
+
16
+ function _loadConfig (minimistConfig, args, overrides) {
17
+ return loadConfig(minimistConfig, args, store, overrides)
18
+ }
19
+
20
+ module.exports = { loadConfig: _loadConfig }
package/lib/start.js CHANGED
@@ -5,9 +5,12 @@ const { join } = require('node:path')
5
5
  const { pathToFileURL } = require('node:url')
6
6
  const { Worker } = require('node:worker_threads')
7
7
  const closeWithGrace = require('close-with-grace')
8
- const { loadConfig } = require('@platformatic/config')
9
- const { parseInspectorOptions, platformaticRuntime } = require('./config')
8
+ const { start: serviceStart } = require('@platformatic/service')
9
+ const { loadConfig } = require('./load-config')
10
+ const { parseInspectorOptions, wrapConfigInRuntimeConfig } = require('./config')
10
11
  const RuntimeApiClient = require('./api-client.js')
12
+ const { printConfigValidationErrors } = require('@platformatic/config')
13
+
11
14
  const kLoaderFile = pathToFileURL(join(__dirname, 'loader.mjs')).href
12
15
  const kWorkerFile = join(__dirname, 'worker.js')
13
16
  const kWorkerExecArgv = [
@@ -16,17 +19,6 @@ const kWorkerExecArgv = [
16
19
  kLoaderFile
17
20
  ]
18
21
 
19
- async function start (argv) {
20
- const config = await loadConfig({}, argv, platformaticRuntime, {
21
- watch: true
22
- })
23
-
24
- config.configManager.args = config.args
25
- const app = await startWithConfig(config.configManager)
26
- await app.start()
27
- return app
28
- }
29
-
30
22
  async function startWithConfig (configManager, env = process.env) {
31
23
  const config = configManager.current
32
24
 
@@ -41,6 +33,8 @@ async function startWithConfig (configManager, env = process.env) {
41
33
  if (config.hotReload) {
42
34
  config.loaderFile = kLoaderFile
43
35
  }
36
+ // The configManager cannot be transferred to the worker, so remove it.
37
+ delete config.configManager
44
38
 
45
39
  const worker = new Worker(kWorkerFile, {
46
40
  /* c8 ignore next */
@@ -90,4 +84,61 @@ async function startWithConfig (configManager, env = process.env) {
90
84
  return runtimeApiClient
91
85
  }
92
86
 
93
- module.exports = { start, startWithConfig }
87
+ async function start (args) {
88
+ const config = await loadConfig({}, args)
89
+
90
+ if (config.configType === 'runtime') {
91
+ config.configManager.args = config.args
92
+ const app = await startWithConfig(config.configManager)
93
+ await app.start()
94
+ return app
95
+ }
96
+
97
+ return serviceStart(config.app, args)
98
+ }
99
+
100
+ async function startCommand (args) {
101
+ try {
102
+ const config = await loadConfig({}, args)
103
+ let runtime
104
+
105
+ if (config.configType === 'runtime') {
106
+ config.configManager.args = config.args
107
+ runtime = await startWithConfig(config.configManager)
108
+ } else {
109
+ const wrappedConfig = await wrapConfigInRuntimeConfig(config)
110
+ wrappedConfig.args = config.args
111
+ runtime = await startWithConfig(wrappedConfig)
112
+ }
113
+
114
+ return await runtime.start()
115
+ } catch (err) {
116
+ logErrorAndExit(err)
117
+ }
118
+ }
119
+
120
+ function logErrorAndExit (err) {
121
+ if (err.filenames) {
122
+ console.error(`Missing config file!
123
+ Be sure to have a config file with one of the following names:
124
+
125
+ ${err.filenames.map((s) => ' * ' + s).join('\n')}
126
+
127
+ In alternative run "npm create platformatic@latest" to generate a basic plt service config.`)
128
+ process.exit(1)
129
+ } else if (err.validationErrors) {
130
+ printConfigValidationErrors(err)
131
+ process.exit(1)
132
+ }
133
+
134
+ delete err?.stack
135
+ console.error(err?.message)
136
+
137
+ if (err?.cause) {
138
+ console.error(`${err.cause}`)
139
+ }
140
+
141
+ process.exit(1)
142
+ }
143
+
144
+ module.exports = { start, startWithConfig, startCommand }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/runtime",
3
- "version": "0.40.0",
3
+ "version": "0.41.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -22,10 +22,10 @@
22
22
  "snazzy": "^9.0.0",
23
23
  "split2": "^4.2.0",
24
24
  "standard": "^17.1.0",
25
- "tsd": "^0.28.1",
25
+ "tsd": "^0.29.0",
26
26
  "typescript": "^5.1.6",
27
- "@platformatic/sql-graphql": "0.40.0",
28
- "@platformatic/sql-mapper": "0.40.0"
27
+ "@platformatic/sql-graphql": "0.41.0",
28
+ "@platformatic/sql-mapper": "0.41.0"
29
29
  },
30
30
  "dependencies": {
31
31
  "@hapi/topo": "^6.0.2",
@@ -42,12 +42,12 @@
42
42
  "pino": "^8.14.1",
43
43
  "pino-pretty": "^10.0.0",
44
44
  "undici": "^5.22.1",
45
- "@platformatic/config": "0.40.0",
46
- "@platformatic/composer": "0.40.0",
47
- "@platformatic/db": "0.40.0",
48
- "@platformatic/service": "0.40.0",
49
- "@platformatic/telemetry": "0.40.0",
50
- "@platformatic/utils": "0.40.0"
45
+ "@platformatic/composer": "0.41.0",
46
+ "@platformatic/config": "0.41.0",
47
+ "@platformatic/db": "0.41.0",
48
+ "@platformatic/service": "0.41.0",
49
+ "@platformatic/telemetry": "0.41.0",
50
+ "@platformatic/utils": "0.41.0"
51
51
  },
52
52
  "standard": {
53
53
  "ignore": [
package/runtime.mjs CHANGED
@@ -6,7 +6,7 @@ import { join } from 'desm'
6
6
  import isMain from 'es-main'
7
7
  import helpMe from 'help-me'
8
8
  import parseArgs from 'minimist'
9
- import { startCommand } from './lib/unified-api.js'
9
+ import { startCommand } from './index.js'
10
10
  import { compile as compileCmd } from './lib/compile.js'
11
11
 
12
12
  export const compile = compileCmd
@@ -7,7 +7,7 @@ const { test } = require('node:test')
7
7
  const {
8
8
  buildServer,
9
9
  loadConfig
10
- } = require('../lib/unified-api')
10
+ } = require('..')
11
11
  const fixturesDir = join(__dirname, '..', 'fixtures')
12
12
 
13
13
  test('loadConfig()', async (t) => {
@@ -1,110 +0,0 @@
1
- 'use strict'
2
- const { Store, loadConfig, printConfigValidationErrors } = require('@platformatic/config')
3
- const {
4
- platformaticService,
5
- buildServer,
6
- start
7
- } = require('@platformatic/service')
8
- const {
9
- platformaticDB
10
- } = require('@platformatic/db')
11
- const {
12
- platformaticComposer
13
- } = require('@platformatic/composer')
14
- const { buildServer: runtimeBuildServer } = require('./build-server')
15
- const { platformaticRuntime, wrapConfigInRuntimeConfig } = require('./config')
16
- const {
17
- start: runtimeStart,
18
- startWithConfig: runtimeStartWithConfig
19
- } = require('./start')
20
-
21
- const store = new Store()
22
- store.add(platformaticService)
23
- store.add(platformaticDB)
24
- store.add(platformaticComposer)
25
- store.add(platformaticRuntime)
26
-
27
- /* c8 ignore next 10 - for some reason c8 is not seeing this as covered. */
28
- async function _buildServer (options) {
29
- if (typeof options === 'string') {
30
- const config = await _loadConfig({}, ['-c', options])
31
- options = config.configManager.current
32
- options.configManager = config.configManager
33
- options.app = config.app
34
- }
35
-
36
- const app = options.app
37
-
38
- delete options.app
39
-
40
- if (app === platformaticRuntime) {
41
- return runtimeBuildServer(options)
42
- }
43
-
44
- return buildServer(options, app)
45
- }
46
-
47
- function _loadConfig (minimistConfig, args, overrides) {
48
- return loadConfig(minimistConfig, args, store, overrides)
49
- }
50
-
51
- async function _start (args) {
52
- const config = await _loadConfig({}, args)
53
-
54
- if (config.configType === 'runtime') {
55
- return runtimeStart(args)
56
- }
57
-
58
- return start(config.app, args)
59
- }
60
-
61
- async function startCommand (args) {
62
- try {
63
- const config = await _loadConfig({}, args)
64
- let runtime
65
-
66
- if (config.configType === 'runtime') {
67
- config.configManager.args = config.args
68
- runtime = await runtimeStartWithConfig(config.configManager)
69
- } else {
70
- const wrappedConfig = await wrapConfigInRuntimeConfig(config)
71
- wrappedConfig.args = config.args
72
- runtime = await runtimeStartWithConfig(wrappedConfig)
73
- }
74
-
75
- return await runtime.start()
76
- } catch (err) {
77
- logErrorAndExit(err)
78
- }
79
- }
80
-
81
- function logErrorAndExit (err) {
82
- if (err.filenames) {
83
- console.error(`Missing config file!
84
- Be sure to have a config file with one of the following names:
85
-
86
- ${err.filenames.map((s) => ' * ' + s).join('\n')}
87
-
88
- In alternative run "npm create platformatic@latest" to generate a basic plt service config.`)
89
- process.exit(1)
90
- } else if (err.validationErrors) {
91
- printConfigValidationErrors(err)
92
- process.exit(1)
93
- }
94
-
95
- delete err?.stack
96
- console.error(err?.message)
97
-
98
- if (err?.cause) {
99
- console.error(`${err.cause}`)
100
- }
101
-
102
- process.exit(1)
103
- }
104
-
105
- module.exports = {
106
- buildServer: _buildServer,
107
- loadConfig: _loadConfig,
108
- start: _start,
109
- startCommand
110
- }