@platformatic/runtime 3.69.0 → 3.71.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
@@ -160,13 +160,10 @@ export type PlatformaticRuntimeConfig = {
160
160
  };
161
161
  workersRestartDelay?: number | string;
162
162
  logger?: {
163
- level?: (
164
- | ("fatal" | "error" | "warn" | "info" | "debug" | "trace" | "silent")
165
- | {
166
- [k: string]: unknown;
167
- }
168
- ) &
169
- string;
163
+ /**
164
+ * The log level. It must be one of the standard pino levels (fatal, error, warn, info, debug, trace, silent) or, when customLevels is set, one of the custom levels.
165
+ */
166
+ level?: string;
170
167
  transport?:
171
168
  | {
172
169
  target?: string;
@@ -199,6 +196,10 @@ export type PlatformaticRuntimeConfig = {
199
196
  redact?: {
200
197
  paths: string[];
201
198
  censor?: string;
199
+ /**
200
+ * Remove the redacted keys entirely instead of replacing their values with the censor. Defaults to false.
201
+ */
202
+ remove?: boolean;
202
203
  };
203
204
  base?: {
204
205
  [k: string]: unknown;
@@ -207,6 +208,46 @@ export type PlatformaticRuntimeConfig = {
207
208
  customLevels?: {
208
209
  [k: string]: unknown;
209
210
  };
211
+ /**
212
+ * The numeric value of the level defined in level, when it is not one of the standard pino levels.
213
+ */
214
+ levelVal?: number;
215
+ /**
216
+ * Only use the levels defined in customLevels and omit the standard pino ones.
217
+ */
218
+ useOnlyCustomLevels?: boolean;
219
+ /**
220
+ * How log levels are compared to the logger level. Use DESC when lower values are more severe. Defaults to ASC.
221
+ */
222
+ levelComparison?: "ASC" | "DESC";
223
+ /**
224
+ * A string prefixed to every message, including the ones of child loggers.
225
+ */
226
+ msgPrefix?: string;
227
+ /**
228
+ * The key under which any logged object is placed.
229
+ */
230
+ nestedKey?: string;
231
+ /**
232
+ * The key used for the serialized error in the log object. Defaults to err.
233
+ */
234
+ errorKey?: string;
235
+ /**
236
+ * The stringification limit at a specific nesting depth when logging circular objects. Defaults to 5.
237
+ */
238
+ depthLimit?: number;
239
+ /**
240
+ * The stringification limit of properties or elements when logging a circular object or array. Defaults to 100.
241
+ */
242
+ edgeLimit?: number;
243
+ /**
244
+ * Terminate each log line with \r\n instead of \n. Defaults to false.
245
+ */
246
+ crlf?: boolean;
247
+ /**
248
+ * Set to false to disable logging entirely. Defaults to true.
249
+ */
250
+ enabled?: boolean;
210
251
  openTelemetryExporter?: {
211
252
  protocol: "grpc" | "http";
212
253
  url: string;
package/lib/runtime.js CHANGED
@@ -8,7 +8,8 @@ import {
8
8
  kEnvFileFallbackKeys,
9
9
  kMetadata,
10
10
  kTimeout,
11
- parseMemorySize
11
+ parseMemorySize,
12
+ scheduleCompileCacheFlush
12
13
  } from '@platformatic/foundation'
13
14
  import { getExecutable } from '@platformatic/globals'
14
15
  import { ITC } from '@platformatic/itc'
@@ -449,6 +450,11 @@ export class Runtime extends EventEmitter {
449
450
 
450
451
  this.#updateStatus('started')
451
452
 
453
+ // The CLI enables the module compile cache for this process. Node.js would only write it when
454
+ // the process terminates, so flush it now that the boot is complete to not lose it when the
455
+ // process is killed abruptly. This is a no-op when the compile cache is not enabled.
456
+ scheduleCompileCacheFlush()
457
+
452
458
  // Start the global health metrics timer for all workers if needed
453
459
  this.#startHealthMetricsCollectionIfNeeded()
454
460
 
@@ -69,7 +69,11 @@ function handleUnhandled (app, event, listeners, timeout, err, ...args) {
69
69
  }
70
70
  }
71
71
 
72
- app.stop().catch()
72
+ // stop() rejects while the controller is not started. Left unobserved, that rejection re-enters
73
+ // this handler forever and starves the event loop, so the exit scheduled above never runs.
74
+ app.stop().catch(stopError => {
75
+ logger.debug({ err: ensureLoggableError(stopError) }, `Stopping the ${label} after the ${event} event failed.`)
76
+ })
73
77
  }
74
78
 
75
79
  export class Controller extends EventEmitter {
@@ -4,7 +4,8 @@ import {
4
4
  disablePinoDirectWrite,
5
5
  ensureLoggableError,
6
6
  getPrivateSymbol,
7
- parseMemorySize
7
+ parseMemorySize,
8
+ scheduleCompileCacheFlush
8
9
  } from '@platformatic/foundation'
9
10
  import { getITC, getLogger, updateGlobals } from '@platformatic/globals'
10
11
  import { addPinoInstrumentation } from '@platformatic/telemetry'
@@ -149,6 +150,9 @@ function setupDefaultHighWaterMark (runtimeConfig, applicationConfig, logger) {
149
150
  }
150
151
  }
151
152
 
153
+ // Whether the module compile cache has been enabled in this worker.
154
+ let compileCacheEnabled = false
155
+
152
156
  // Enable compile cache if configured (Node.js 22.1.0+)
153
157
  async function setupCompileCache (runtimeConfig, applicationConfig, logger) {
154
158
  // Normalize boolean shorthand: true -> { enabled: true }
@@ -187,8 +191,10 @@ async function setupCompileCache (runtimeConfig, applicationConfig, logger) {
187
191
  const { compileCacheStatus } = moduleApi.constants ?? {}
188
192
 
189
193
  if (result.status === compileCacheStatus?.ENABLED) {
194
+ compileCacheEnabled = true
190
195
  logger.debug({ directory: result.directory }, 'Module compile cache enabled')
191
196
  } else if (result.status === compileCacheStatus?.ALREADY_ENABLED) {
197
+ compileCacheEnabled = true
192
198
  logger.debug({ directory: result.directory }, 'Module compile cache already enabled')
193
199
  } else if (result.status === compileCacheStatus?.FAILED) {
194
200
  logger.warn({ message: result.message }, 'Failed to enable module compile cache')
@@ -319,6 +325,14 @@ async function main () {
319
325
 
320
326
  await controller.init(cleanup)
321
327
 
328
+ // Make the compile cache accumulated while booting durable, as Node.js would otherwise only write
329
+ // it when the worker terminates.
330
+ controller.on('started', () => {
331
+ if (compileCacheEnabled) {
332
+ scheduleCompileCacheFlush(logger)
333
+ }
334
+ })
335
+
322
336
  if (applicationConfig.entrypoint && runtimeConfig.basePath) {
323
337
  const meta = await controller.capability.getMeta()
324
338
  if (!meta.gateway.wantsAbsoluteUrls) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/runtime",
3
- "version": "3.69.0",
3
+ "version": "3.71.0",
4
4
  "description": "Platformatic runtime",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -39,14 +39,14 @@
39
39
  "typescript": "~6.0.3",
40
40
  "undici-oidc-interceptor": "^0.9.0",
41
41
  "why-is-node-running": "^2.2.2",
42
- "@platformatic/composer": "3.69.0",
43
- "@platformatic/db": "3.69.0",
44
- "@platformatic/gateway": "3.69.0",
45
- "@platformatic/node": "3.69.0",
46
- "@platformatic/service": "3.69.0",
47
- "@platformatic/sql-graphql": "3.69.0",
48
- "@platformatic/sql-mapper": "3.69.0",
49
- "@platformatic/wattpm-pprof-capture": "3.69.0"
42
+ "@platformatic/composer": "3.71.0",
43
+ "@platformatic/db": "3.71.0",
44
+ "@platformatic/gateway": "3.71.0",
45
+ "@platformatic/service": "3.71.0",
46
+ "@platformatic/node": "3.71.0",
47
+ "@platformatic/sql-graphql": "3.71.0",
48
+ "@platformatic/wattpm-pprof-capture": "3.71.0",
49
+ "@platformatic/sql-mapper": "3.71.0"
50
50
  },
51
51
  "dependencies": {
52
52
  "@fastify/accepts": "^5.0.0",
@@ -77,13 +77,13 @@
77
77
  "undici": "^7.27.2",
78
78
  "undici-thread-interceptor": "^1.3.1",
79
79
  "ws": "^8.16.0",
80
- "@platformatic/basic": "3.69.0",
81
- "@platformatic/foundation": "3.69.0",
82
- "@platformatic/globals": "3.69.0",
83
- "@platformatic/metrics": "3.69.0",
84
- "@platformatic/generators": "3.69.0",
85
- "@platformatic/telemetry": "3.69.0",
86
- "@platformatic/itc": "3.69.0"
80
+ "@platformatic/foundation": "3.71.0",
81
+ "@platformatic/generators": "3.71.0",
82
+ "@platformatic/basic": "3.71.0",
83
+ "@platformatic/globals": "3.71.0",
84
+ "@platformatic/metrics": "3.71.0",
85
+ "@platformatic/itc": "3.71.0",
86
+ "@platformatic/telemetry": "3.71.0"
87
87
  },
88
88
  "engines": {
89
89
  "node": ">=22.19.0"
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/runtime/3.69.0.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/runtime/3.71.0.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Runtime Config",
5
5
  "type": "object",
@@ -1894,22 +1894,7 @@
1894
1894
  "properties": {
1895
1895
  "level": {
1896
1896
  "type": "string",
1897
- "oneOf": [
1898
- {
1899
- "enum": [
1900
- "fatal",
1901
- "error",
1902
- "warn",
1903
- "info",
1904
- "debug",
1905
- "trace",
1906
- "silent"
1907
- ]
1908
- },
1909
- {
1910
- "pattern": "^\\{.+\\}$"
1911
- }
1912
- ]
1897
+ "description": "The log level. It must be one of the standard pino levels (fatal, error, warn, info, debug, trace, silent) or, when customLevels is set, one of the custom levels."
1913
1898
  },
1914
1899
  "transport": {
1915
1900
  "anyOf": [
@@ -2010,6 +1995,10 @@
2010
1995
  "censor": {
2011
1996
  "type": "string",
2012
1997
  "default": "[redacted]"
1998
+ },
1999
+ "remove": {
2000
+ "type": "boolean",
2001
+ "description": "Remove the redacted keys entirely instead of replacing their values with the censor. Defaults to false."
2013
2002
  }
2014
2003
  },
2015
2004
  "required": [
@@ -2035,6 +2024,50 @@
2035
2024
  "type": "object",
2036
2025
  "additionalProperties": true
2037
2026
  },
2027
+ "levelVal": {
2028
+ "type": "integer",
2029
+ "description": "The numeric value of the level defined in level, when it is not one of the standard pino levels."
2030
+ },
2031
+ "useOnlyCustomLevels": {
2032
+ "type": "boolean",
2033
+ "description": "Only use the levels defined in customLevels and omit the standard pino ones."
2034
+ },
2035
+ "levelComparison": {
2036
+ "type": "string",
2037
+ "enum": [
2038
+ "ASC",
2039
+ "DESC"
2040
+ ],
2041
+ "description": "How log levels are compared to the logger level. Use DESC when lower values are more severe. Defaults to ASC."
2042
+ },
2043
+ "msgPrefix": {
2044
+ "type": "string",
2045
+ "description": "A string prefixed to every message, including the ones of child loggers."
2046
+ },
2047
+ "nestedKey": {
2048
+ "type": "string",
2049
+ "description": "The key under which any logged object is placed."
2050
+ },
2051
+ "errorKey": {
2052
+ "type": "string",
2053
+ "description": "The key used for the serialized error in the log object. Defaults to err."
2054
+ },
2055
+ "depthLimit": {
2056
+ "type": "integer",
2057
+ "description": "The stringification limit at a specific nesting depth when logging circular objects. Defaults to 5."
2058
+ },
2059
+ "edgeLimit": {
2060
+ "type": "integer",
2061
+ "description": "The stringification limit of properties or elements when logging a circular object or array. Defaults to 100."
2062
+ },
2063
+ "crlf": {
2064
+ "type": "boolean",
2065
+ "description": "Terminate each log line with \\r\\n instead of \\n. Defaults to false."
2066
+ },
2067
+ "enabled": {
2068
+ "type": "boolean",
2069
+ "description": "Set to false to disable logging entirely. Defaults to true."
2070
+ },
2038
2071
  "openTelemetryExporter": {
2039
2072
  "type": "object",
2040
2073
  "properties": {
@@ -2079,6 +2112,35 @@
2079
2112
  "additionalProperties": false
2080
2113
  }
2081
2114
  },
2115
+ "if": {
2116
+ "not": {
2117
+ "required": [
2118
+ "customLevels"
2119
+ ]
2120
+ }
2121
+ },
2122
+ "then": {
2123
+ "properties": {
2124
+ "level": {
2125
+ "oneOf": [
2126
+ {
2127
+ "enum": [
2128
+ "fatal",
2129
+ "error",
2130
+ "warn",
2131
+ "info",
2132
+ "debug",
2133
+ "trace",
2134
+ "silent"
2135
+ ]
2136
+ },
2137
+ {
2138
+ "pattern": "^\\{.+\\}$"
2139
+ }
2140
+ ]
2141
+ }
2142
+ }
2143
+ },
2082
2144
  "default": {},
2083
2145
  "additionalProperties": true
2084
2146
  },