@platformatic/runtime 3.58.1 → 3.59.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/config.d.ts CHANGED
@@ -18,6 +18,12 @@ export type PlatformaticRuntimeConfig = {
18
18
  mappings?: {
19
19
  [k: string]: {
20
20
  id: string;
21
+ enabled?:
22
+ | boolean
23
+ | string
24
+ | {
25
+ [k: string]: boolean;
26
+ };
21
27
  config?: string;
22
28
  useHttp?: boolean;
23
29
  reuseTcpPorts?: boolean;
@@ -180,6 +186,11 @@ export type PlatformaticRuntimeConfig = {
180
186
  url: string;
181
187
  };
182
188
  captureStdio?: boolean;
189
+ pino?: {
190
+ level?: string;
191
+ time?: string;
192
+ message?: string;
193
+ };
183
194
  [k: string]: unknown;
184
195
  };
185
196
  server?: {
package/lib/config.js CHANGED
@@ -295,8 +295,27 @@ export async function prepareApplication (config, application, defaultWorkers) {
295
295
  return application
296
296
  }
297
297
 
298
+ function isApplicationEnabled (application, environment) {
299
+ const { enabled } = application
300
+
301
+ if (typeof enabled === 'undefined') {
302
+ return true
303
+ }
304
+
305
+ if (typeof enabled === 'string') {
306
+ return enabled !== 'false'
307
+ }
308
+
309
+ if (typeof enabled === 'object' && enabled !== null) {
310
+ return enabled[environment] ?? true
311
+ }
312
+
313
+ return enabled
314
+ }
315
+
298
316
  export async function transform (config, _, context) {
299
317
  const production = context?.isProduction ?? context?.production
318
+ const environment = production ? 'production' : 'development'
300
319
  const applications = [...(config.applications ?? []), ...(config.services ?? []), ...(config.web ?? [])]
301
320
 
302
321
  const watchType = typeof config.watch
@@ -391,6 +410,12 @@ export async function transform (config, _, context) {
391
410
  }
392
411
  }
393
412
 
413
+ for (let i = applications.length - 1; i >= 0; --i) {
414
+ if (!isApplicationEnabled(applications[i], environment)) {
415
+ applications.splice(i, 1)
416
+ }
417
+ }
418
+
394
419
  config.inspectorOptions = undefined
395
420
  parseInspectorOptions(config, context?.inspect, context?.inspectBreak)
396
421
 
package/lib/logger.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  buildPinoFormatters,
3
3
  buildPinoTimestamp,
4
+ kMetadata,
4
5
  } from '@platformatic/foundation'
5
6
  import { isatty } from 'node:tty'
6
7
  import pino from 'pino'
@@ -63,7 +64,8 @@ const colors = [
63
64
  226 // bright yellow
64
65
  ]
65
66
 
66
- function createLoggerContext () {
67
+ function createLoggerContext (config) {
68
+ const env = config[kMetadata].env
67
69
  const context = {
68
70
  colors: {},
69
71
  closeables: [],
@@ -76,7 +78,7 @@ function createLoggerContext () {
76
78
  context.maxLength = Math.max(context.maxLength, id.length)
77
79
  let hash = 0
78
80
 
79
- if (!pretty.isColorSupported && process.env.FORCE_COLOR !== 'true') {
81
+ if (!pretty.isColorSupported && env.FORCE_COLOR !== 'true') {
80
82
  context.colors[id] = ''
81
83
  continue
82
84
  }
@@ -151,7 +153,8 @@ function createPrettifier (context) {
151
153
 
152
154
  // Create the runtime logger
153
155
  export async function createLogger (config) {
154
- const context = createLoggerContext()
156
+ const env = config[kMetadata].env
157
+ const context = createLoggerContext(config)
155
158
 
156
159
  const loggerConfig = { ...config.logger, transport: undefined }
157
160
  if (config.logger.base === null) {
@@ -168,7 +171,7 @@ export async function createLogger (config) {
168
171
  }
169
172
 
170
173
  cliStream = pino.transport(config.logger.transport)
171
- } else if ((process.env.FORCE_TTY || isatty(1)) && process.env.PLT_PRETTY_PRINT !== 'false') {
174
+ } else if ((env.FORCE_TTY || isatty(1)) && env.PLT_PRETTY_PRINT !== 'false') {
172
175
  cliStream = createPrettifier(context)
173
176
  } else {
174
177
  cliStream = pino.destination(1)
package/lib/runtime.js CHANGED
@@ -116,6 +116,10 @@ export class Runtime extends EventEmitter {
116
116
  #root
117
117
  #config
118
118
  #env
119
+ #pinoLevelKey
120
+ #pinoTimeKey
121
+ #pinoMessageKey
122
+ #pinoCustomizedKeys
119
123
  #context
120
124
  #sharedContext
121
125
  #isProduction
@@ -159,6 +163,11 @@ export class Runtime extends EventEmitter {
159
163
  this.#config = config
160
164
  this.#root = config[kMetadata].root
161
165
  this.#env = config[kMetadata].env
166
+ this.#pinoLevelKey = config.logger.pino?.level ?? 'level'
167
+ this.#pinoTimeKey = config.logger.pino?.time ?? 'time'
168
+ this.#pinoMessageKey = config.logger.pino?.message ?? 'msg'
169
+ this.#pinoCustomizedKeys =
170
+ this.#pinoLevelKey !== 'level' || this.#pinoTimeKey !== 'time' || this.#pinoMessageKey !== 'msg'
162
171
  this.#context = context ?? {}
163
172
  this.#isProduction = this.#context.isProduction ?? this.#context.production ?? false
164
173
  this.#concurrency = Math.max(1, config.startupConcurrency ?? this.#context.concurrency ?? DEFAULT_CONCURRENCY)
@@ -2884,13 +2893,16 @@ export class Runtime extends EventEmitter {
2884
2893
  }
2885
2894
 
2886
2895
  let pinoLog
2896
+ let pinoLevel
2887
2897
 
2888
2898
  if (message !== null && typeof message === 'object') {
2899
+ pinoLevel = message[this.#pinoLevelKey]
2900
+
2889
2901
  pinoLog =
2890
- typeof message.level === 'number' &&
2902
+ (typeof pinoLevel === 'number' || (this.#pinoCustomizedKeys && typeof pinoLevel === 'string')) &&
2891
2903
  // We want to accept both pino raw time (number) and time as formatted string
2892
- (typeof message.time === 'number' || typeof message.time === 'string') &&
2893
- typeof message.msg === 'string'
2904
+ (typeof message[this.#pinoTimeKey] === 'number' || typeof message[this.#pinoTimeKey] === 'string') &&
2905
+ typeof message[this.#pinoMessageKey] === 'string'
2894
2906
  }
2895
2907
 
2896
2908
  // Directly write to the Pino destination
@@ -2899,9 +2911,14 @@ export class Runtime extends EventEmitter {
2899
2911
  continue
2900
2912
  }
2901
2913
 
2902
- this.#loggerDestination.lastLevel = message.level
2903
- this.#loggerDestination.lastTime = message.time
2904
- this.#loggerDestination.lastMsg = message.msg
2914
+ if (typeof pinoLevel === 'string') {
2915
+ pinoLevel =
2916
+ logger.levels.values[pinoLevel] ?? logger.levels.values[pinoLevel.toLowerCase()] ?? logger.levels.values[level]
2917
+ }
2918
+
2919
+ this.#loggerDestination.lastLevel = pinoLevel
2920
+ this.#loggerDestination.lastTime = message[this.#pinoTimeKey]
2921
+ this.#loggerDestination.lastMsg = message[this.#pinoMessageKey]
2905
2922
  this.#loggerDestination.lastObj = message
2906
2923
  this.#loggerDestination.lastLogger = logger
2907
2924
  this.#loggerDestination.write(raw + '\n')
package/lib/schema.js CHANGED
@@ -10,6 +10,25 @@ const runtimeLogger = {
10
10
  captureStdio: {
11
11
  type: 'boolean',
12
12
  default: true
13
+ },
14
+ pino: {
15
+ type: 'object',
16
+ default: {},
17
+ properties: {
18
+ level: {
19
+ type: 'string',
20
+ default: 'level'
21
+ },
22
+ time: {
23
+ type: 'string',
24
+ default: 'time'
25
+ },
26
+ message: {
27
+ type: 'string',
28
+ default: 'msg'
29
+ }
30
+ },
31
+ additionalProperties: false
13
32
  }
14
33
  }
15
34
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/runtime",
3
- "version": "3.58.1",
3
+ "version": "3.59.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -38,14 +38,14 @@
38
38
  "typescript": "^5.5.4",
39
39
  "undici-oidc-interceptor": "^0.9.0",
40
40
  "why-is-node-running": "^2.2.2",
41
- "@platformatic/composer": "3.58.1",
42
- "@platformatic/gateway": "3.58.1",
43
- "@platformatic/node": "3.58.1",
44
- "@platformatic/sql-graphql": "3.58.1",
45
- "@platformatic/sql-mapper": "3.58.1",
46
- "@platformatic/db": "3.58.1",
47
- "@platformatic/service": "3.58.1",
48
- "@platformatic/wattpm-pprof-capture": "3.58.1"
41
+ "@platformatic/composer": "3.59.0",
42
+ "@platformatic/db": "3.59.0",
43
+ "@platformatic/gateway": "3.59.0",
44
+ "@platformatic/node": "3.59.0",
45
+ "@platformatic/service": "3.59.0",
46
+ "@platformatic/sql-mapper": "3.59.0",
47
+ "@platformatic/sql-graphql": "3.59.0",
48
+ "@platformatic/wattpm-pprof-capture": "3.59.0"
49
49
  },
50
50
  "dependencies": {
51
51
  "@fastify/accepts": "^5.0.0",
@@ -75,13 +75,13 @@
75
75
  "undici": "^7.27.2",
76
76
  "undici-thread-interceptor": "^1.3.1",
77
77
  "ws": "^8.16.0",
78
- "@platformatic/basic": "3.58.1",
79
- "@platformatic/foundation": "3.58.1",
80
- "@platformatic/globals": "3.58.1",
81
- "@platformatic/generators": "3.58.1",
82
- "@platformatic/metrics": "3.58.1",
83
- "@platformatic/itc": "3.58.1",
84
- "@platformatic/telemetry": "3.58.1"
78
+ "@platformatic/basic": "3.59.0",
79
+ "@platformatic/generators": "3.59.0",
80
+ "@platformatic/globals": "3.59.0",
81
+ "@platformatic/metrics": "3.59.0",
82
+ "@platformatic/foundation": "3.59.0",
83
+ "@platformatic/telemetry": "3.59.0",
84
+ "@platformatic/itc": "3.59.0"
85
85
  },
86
86
  "engines": {
87
87
  "node": ">=22.19.0"
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/runtime/3.58.1.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/runtime/3.59.0.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Runtime Config",
5
5
  "type": "object",
@@ -58,6 +58,23 @@
58
58
  "id": {
59
59
  "type": "string"
60
60
  },
61
+ "enabled": {
62
+ "anyOf": [
63
+ {
64
+ "type": "boolean"
65
+ },
66
+ {
67
+ "type": "string"
68
+ },
69
+ {
70
+ "type": "object",
71
+ "additionalProperties": {
72
+ "type": "boolean"
73
+ }
74
+ }
75
+ ],
76
+ "default": true
77
+ },
61
78
  "config": {
62
79
  "type": "string"
63
80
  },
@@ -427,6 +444,23 @@
427
444
  "id": {
428
445
  "type": "string"
429
446
  },
447
+ "enabled": {
448
+ "anyOf": [
449
+ {
450
+ "type": "boolean"
451
+ },
452
+ {
453
+ "type": "string"
454
+ },
455
+ {
456
+ "type": "object",
457
+ "additionalProperties": {
458
+ "type": "boolean"
459
+ }
460
+ }
461
+ ],
462
+ "default": true
463
+ },
430
464
  "path": {
431
465
  "type": "string",
432
466
  "allowEmptyPaths": true,
@@ -806,6 +840,23 @@
806
840
  "id": {
807
841
  "type": "string"
808
842
  },
843
+ "enabled": {
844
+ "anyOf": [
845
+ {
846
+ "type": "boolean"
847
+ },
848
+ {
849
+ "type": "string"
850
+ },
851
+ {
852
+ "type": "object",
853
+ "additionalProperties": {
854
+ "type": "boolean"
855
+ }
856
+ }
857
+ ],
858
+ "default": true
859
+ },
809
860
  "path": {
810
861
  "type": "string",
811
862
  "allowEmptyPaths": true,
@@ -1185,6 +1236,23 @@
1185
1236
  "id": {
1186
1237
  "type": "string"
1187
1238
  },
1239
+ "enabled": {
1240
+ "anyOf": [
1241
+ {
1242
+ "type": "boolean"
1243
+ },
1244
+ {
1245
+ "type": "string"
1246
+ },
1247
+ {
1248
+ "type": "object",
1249
+ "additionalProperties": {
1250
+ "type": "boolean"
1251
+ }
1252
+ }
1253
+ ],
1254
+ "default": true
1255
+ },
1188
1256
  "path": {
1189
1257
  "type": "string",
1190
1258
  "allowEmptyPaths": true,
@@ -1781,6 +1849,25 @@
1781
1849
  "captureStdio": {
1782
1850
  "type": "boolean",
1783
1851
  "default": true
1852
+ },
1853
+ "pino": {
1854
+ "type": "object",
1855
+ "default": {},
1856
+ "properties": {
1857
+ "level": {
1858
+ "type": "string",
1859
+ "default": "level"
1860
+ },
1861
+ "time": {
1862
+ "type": "string",
1863
+ "default": "time"
1864
+ },
1865
+ "message": {
1866
+ "type": "string",
1867
+ "default": "msg"
1868
+ }
1869
+ },
1870
+ "additionalProperties": false
1784
1871
  }
1785
1872
  },
1786
1873
  "default": {},