@platformatic/service 2.27.1 → 2.28.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.
package/index.js CHANGED
@@ -2,8 +2,10 @@
2
2
 
3
3
  const { isKeyEnabled } = require('@platformatic/utils')
4
4
  const { loadConfig, ConfigManager } = require('@platformatic/config')
5
- const { readFile } = require('fs/promises')
6
- const { join } = require('path')
5
+ const { readFile } = require('node:fs/promises')
6
+ const { join } = require('node:path')
7
+ const { workerData } = require('node:worker_threads')
8
+ const jsonPatch = require('fast-json-patch')
7
9
 
8
10
  const setupCors = require('./lib/plugins/cors')
9
11
  const setupOpenAPI = require('./lib/plugins/openapi.js')
@@ -170,11 +172,22 @@ async function buildStackable (options, app = platformaticService, Stackable = S
170
172
  }
171
173
  }
172
174
 
175
+ const patch = workerData?.serviceConfig?.configPatch
176
+
177
+ if (Array.isArray(patch)) {
178
+ configManager.current = jsonPatch.applyPatch(configManager.current, patch).newDocument
179
+ }
180
+
173
181
  const stackable = new Stackable({
174
- init: () => buildServer({
175
- configManager,
176
- ...configManager.current,
177
- }, app, options.context),
182
+ init: () =>
183
+ buildServer(
184
+ {
185
+ configManager,
186
+ ...configManager.current
187
+ },
188
+ app,
189
+ options.context
190
+ ),
178
191
  stackable: app,
179
192
  configManager,
180
193
  context: options.context
package/lib/start.js CHANGED
@@ -2,7 +2,12 @@
2
2
 
3
3
  const { readFile } = require('fs/promises')
4
4
  const close = require('close-with-grace')
5
- const { loadConfig, ConfigManager, printConfigValidationErrors, printAndExitLoadConfigError } = require('@platformatic/config')
5
+ const {
6
+ loadConfig,
7
+ ConfigManager,
8
+ printConfigValidationErrors,
9
+ printAndExitLoadConfigError
10
+ } = require('@platformatic/config')
6
11
  const { addLoggerToTheConfig, isDocker } = require('./utils.js')
7
12
  const { randomUUID } = require('crypto')
8
13
  const { fastify } = require('fastify')
@@ -36,10 +41,15 @@ async function createServer (serverContext) {
36
41
  config.server.hostname = '0.0.0.0'
37
42
  }
38
43
  fastifyOptions = {
39
- ...config.server,
44
+ ...config.server
40
45
  }
41
46
  }
42
- fastifyOptions.genReqId = function (req) { return randomUUID() }
47
+
48
+ Object.assign(fastifyOptions, context?.fastifyOptions ?? {})
49
+
50
+ fastifyOptions.genReqId = function (req) {
51
+ return randomUUID()
52
+ }
43
53
  const root = fastify(fastifyOptions)
44
54
  root.decorate('platformatic', { configManager, config })
45
55
  await root.register(app, { context })
@@ -50,7 +60,7 @@ async function createServer (serverContext) {
50
60
  root.decorate('url', {
51
61
  getter () {
52
62
  return serverContext.url
53
- },
63
+ }
54
64
  })
55
65
 
56
66
  return root
@@ -106,7 +116,7 @@ async function buildServer (options, app, context) {
106
116
  handler.start = async function () {
107
117
  serverContext.url = await handler.listen({
108
118
  host: options.server?.hostname || '127.0.0.1',
109
- port: options.server?.port || 0,
119
+ port: options.server?.port || 0
110
120
  })
111
121
  return serverContext.url
112
122
  }
@@ -154,12 +164,15 @@ async function start (appType, _args) {
154
164
  close(async ({ signal, err }) => {
155
165
  // Windows does not support trapping signals
156
166
  if (err) {
157
- app.log.error({
158
- err: {
159
- message: err.message,
160
- stack: err.stack,
167
+ app.log.error(
168
+ {
169
+ err: {
170
+ message: err.message,
171
+ stack: err.stack
172
+ }
161
173
  },
162
- }, 'exiting')
174
+ 'exiting'
175
+ )
163
176
  } else if (signal) {
164
177
  app.log.info({ signal }, 'received signal')
165
178
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/service",
3
- "version": "2.27.1",
3
+ "version": "2.28.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -58,9 +58,10 @@
58
58
  "commist": "^3.2.0",
59
59
  "console-table-printer": "^2.12.0",
60
60
  "desm": "^1.3.1",
61
- "env-schema": "^5.2.1",
61
+ "env-schema": "^6.0.0",
62
62
  "es-main": "^1.3.0",
63
- "execa": "^8.0.1",
63
+ "execa": "^9.0.0",
64
+ "fast-json-patch": "^3.1.1",
64
65
  "fastify": "^5.0.0",
65
66
  "fastify-metrics": "^12.0.0",
66
67
  "fastify-plugin": "^5.0.0",
@@ -76,14 +77,14 @@
76
77
  "rfdc": "^1.3.1",
77
78
  "semgrator": "^0.3.0",
78
79
  "undici": "^7.0.0",
79
- "@platformatic/client": "2.27.1",
80
- "@platformatic/config": "2.27.1",
81
- "@platformatic/metrics": "2.27.1",
82
- "@platformatic/generators": "2.27.1",
83
- "@platformatic/scalar-theme": "2.27.1",
84
- "@platformatic/telemetry": "2.27.1",
85
- "@platformatic/ts-compiler": "2.27.1",
86
- "@platformatic/utils": "2.27.1"
80
+ "@platformatic/client": "2.28.0",
81
+ "@platformatic/config": "2.28.0",
82
+ "@platformatic/metrics": "2.28.0",
83
+ "@platformatic/scalar-theme": "2.28.0",
84
+ "@platformatic/telemetry": "2.28.0",
85
+ "@platformatic/ts-compiler": "2.28.0",
86
+ "@platformatic/utils": "2.28.0",
87
+ "@platformatic/generators": "2.28.0"
87
88
  },
88
89
  "scripts": {
89
90
  "test": "pnpm run lint && borp -T --concurrency=1 --timeout=300000 && tsd",
package/schema.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/service/2.27.1.json",
3
- "version": "2.27.1",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/service/2.28.0.json",
3
+ "version": "2.28.0",
4
4
  "title": "Platformatic Service",
5
5
  "type": "object",
6
6
  "properties": {