@platformatic/runtime 0.36.0 → 0.37.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/lib/api.js CHANGED
@@ -193,7 +193,7 @@ class RuntimeApi {
193
193
  }
194
194
 
195
195
  if (typeof service.server.swagger !== 'function') {
196
- throw new Error(`Service with id '${id}' does not expose an OpenAPI schema`)
196
+ return null
197
197
  }
198
198
 
199
199
  try {
package/lib/app.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const { once } = require('node:events')
4
- const { dirname, basename } = require('node:path')
4
+ const { dirname } = require('node:path')
5
5
  const { FileWatcher } = require('@platformatic/utils')
6
6
  const debounce = require('debounce')
7
7
  const {
@@ -18,6 +18,7 @@ class PlatformaticApp {
18
18
  #fileWatcher
19
19
  #logger
20
20
  #telemetryConfig
21
+ #debouncedRestart
21
22
 
22
23
  constructor (appConfig, loaderPort, logger, telemetryConfig) {
23
24
  this.appConfig = appConfig
@@ -33,6 +34,12 @@ class PlatformaticApp {
33
34
  name: this.appConfig.id
34
35
  })
35
36
  this.#telemetryConfig = telemetryConfig
37
+
38
+ /* c8 ignore next 4 */
39
+ this.#debouncedRestart = debounce(() => {
40
+ this.server.log.info('files changed')
41
+ this.restart()
42
+ }, 100) // debounce restart for 100ms
36
43
  }
37
44
 
38
45
  getStatus () {
@@ -56,8 +63,9 @@ class PlatformaticApp {
56
63
  await once(this.#loaderPort, 'message')
57
64
  }
58
65
 
59
- this.#setuplogger(this.config.configManager)
60
66
  try {
67
+ await this.config.configManager.parseAndValidate()
68
+ this.#setuplogger(this.config.configManager)
61
69
  await this.server.restart()
62
70
  } catch (err) {
63
71
  this.#logAndExit(err)
@@ -159,7 +167,6 @@ class PlatformaticApp {
159
167
  let _config
160
168
  try {
161
169
  _config = await loadConfig({}, ['-c', appConfig.config], {
162
- watch: true,
163
170
  onMissingEnv (key) {
164
171
  return appConfig.localServiceEnvVars.get(key)
165
172
  }
@@ -173,30 +180,25 @@ class PlatformaticApp {
173
180
 
174
181
  function applyOverrides () {
175
182
  if (appConfig._configOverrides instanceof Map) {
176
- try {
177
- appConfig._configOverrides.forEach((value, key) => {
178
- if (typeof key !== 'string') {
179
- throw new Error('config path must be a string.')
180
- }
181
-
182
- const parts = key.split('.')
183
- let next = configManager.current
184
- let obj
185
- let i
186
-
187
- for (i = 0; next !== undefined && i < parts.length; ++i) {
188
- obj = next
189
- next = obj[parts[i]]
190
- }
191
-
192
- if (i === parts.length) {
193
- obj[parts.at(-1)] = value
194
- }
195
- })
196
- } catch (err) {
197
- configManager.stopWatching()
198
- throw err
199
- }
183
+ appConfig._configOverrides.forEach((value, key) => {
184
+ if (typeof key !== 'string') {
185
+ throw new Error('config path must be a string.')
186
+ }
187
+
188
+ const parts = key.split('.')
189
+ let next = configManager.current
190
+ let obj
191
+ let i
192
+
193
+ for (i = 0; next !== undefined && i < parts.length; ++i) {
194
+ obj = next
195
+ next = obj[parts[i]]
196
+ }
197
+
198
+ if (i === parts.length) {
199
+ obj[parts.at(-1)] = value
200
+ }
201
+ })
200
202
  }
201
203
  }
202
204
 
@@ -204,16 +206,6 @@ class PlatformaticApp {
204
206
 
205
207
  this.#hotReload = this.appConfig.hotReload
206
208
 
207
- configManager.on('update', async (newConfig) => {
208
- if (this.server) { // when we setup telemetry on config, we don't have a server yet
209
- this.server.platformatic.config = newConfig
210
- applyOverrides()
211
- this.server.log.debug('config changed')
212
- this.server.log.trace({ newConfig }, 'new config')
213
- await this.restart()
214
- }
215
- })
216
-
217
209
  configManager.on('error', (err) => {
218
210
  /* c8 ignore next */
219
211
  this.server.log.error({ err }, 'error reloading the configuration')
@@ -234,34 +226,22 @@ class PlatformaticApp {
234
226
  }
235
227
  const server = this.server
236
228
  const { configManager } = server.platformatic
237
- // TODO FileWatcher and ConfigManager both watch the configuration file
238
- // we should remove the watching from the ConfigManager
239
229
  const fileWatcher = new FileWatcher({
240
230
  path: dirname(configManager.fullPath),
241
231
  /* c8 ignore next 2 */
242
232
  allowToWatch: this.#originalWatch?.allow,
243
- watchIgnore: [...(this.#originalWatch?.ignore || []), basename(configManager.fullPath)]
233
+ watchIgnore: this.#originalWatch?.ignore || []
244
234
  })
245
235
 
246
- /* c8 ignore next 4 */
247
- const restart = debounce(() => {
248
- this.server.log.info('files changed')
249
- this.restart()
250
- }, 100) // debounce restart for 100ms
251
- fileWatcher.on('update', restart)
236
+ fileWatcher.on('update', this.#debouncedRestart)
252
237
 
253
238
  fileWatcher.startWatching()
254
239
  server.log.debug('start watching files')
255
240
  server.platformatic.fileWatcher = fileWatcher
256
- server.platformatic.configManager.startWatching()
257
241
  this.#fileWatcher = fileWatcher
258
242
  }
259
243
 
260
244
  async #stopFileWatching () {
261
- // The configManager automatically watches for the config file changes
262
- // therefore we need to stop it all the times.
263
- await this.config.configManager.stopWatching()
264
-
265
245
  const watcher = this.#fileWatcher
266
246
  if (watcher) {
267
247
  this.server.log.debug('stop watching files')
@@ -272,7 +252,6 @@ class PlatformaticApp {
272
252
  }
273
253
 
274
254
  #logAndExit (err) {
275
- this.config?.configManager?.stopWatching()
276
255
  this.#logger.error({ err })
277
256
  process.exit(1)
278
257
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/runtime",
3
- "version": "0.36.0",
3
+ "version": "0.37.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -24,8 +24,8 @@
24
24
  "standard": "^17.1.0",
25
25
  "tsd": "^0.28.1",
26
26
  "typescript": "^5.1.6",
27
- "@platformatic/sql-graphql": "0.36.0",
28
- "@platformatic/sql-mapper": "0.36.0"
27
+ "@platformatic/sql-mapper": "0.37.1",
28
+ "@platformatic/sql-graphql": "0.37.1"
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/composer": "0.36.0",
46
- "@platformatic/db": "0.36.0",
47
- "@platformatic/config": "0.36.0",
48
- "@platformatic/service": "0.36.0",
49
- "@platformatic/telemetry": "0.36.0",
50
- "@platformatic/utils": "0.36.0"
45
+ "@platformatic/composer": "0.37.1",
46
+ "@platformatic/config": "0.37.1",
47
+ "@platformatic/db": "0.37.1",
48
+ "@platformatic/service": "0.37.1",
49
+ "@platformatic/telemetry": "0.37.1",
50
+ "@platformatic/utils": "0.37.1"
51
51
  },
52
52
  "standard": {
53
53
  "ignore": [
package/test/api.test.js CHANGED
@@ -349,9 +349,6 @@ test('should fail to get a service openapi schema if service does not expose it'
349
349
  await app.close()
350
350
  })
351
351
 
352
- try {
353
- await app.getServiceOpenapiSchema('without-openapi')
354
- } catch (err) {
355
- assert.strictEqual(err.message, 'Service with id \'without-openapi\' does not expose an OpenAPI schema')
356
- }
352
+ const openapiSchema = await app.getServiceOpenapiSchema('without-openapi')
353
+ assert.strictEqual(openapiSchema, null)
357
354
  })
@@ -48,6 +48,10 @@ test('handles startup errors', async (t) => {
48
48
  }
49
49
 
50
50
  assert(found)
51
+
52
+ // if we do not await this, the test will crash because the event loop has nothing to do
53
+ // but there is still a promise waiting
54
+ await child.catch(() => {})
51
55
  })
52
56
 
53
57
  test('exits on error', async () => {