@platformatic/runtime 1.5.2 → 1.6.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.
@@ -0,0 +1,15 @@
1
+ 'use strict'
2
+
3
+ const build = require('pino-abstract-transport')
4
+ const fs = require('fs')
5
+ const path = require('path')
6
+
7
+ module.exports = function (opts) {
8
+ const dest = opts.path || path.join(process.cwd(), 'transport.log')
9
+ return build(function (source) {
10
+ source.on('data', function (obj) {
11
+ obj.fromTransport = true
12
+ fs.appendFileSync(dest, JSON.stringify(obj) + '\n')
13
+ })
14
+ })
15
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "$schema": "https://platformatic.dev/schemas/v0.31.0/runtime",
3
+ "entrypoint": "echo",
4
+ "allowCycles": false,
5
+ "hotReload": true,
6
+ "autoload": {
7
+ "path": "services",
8
+ "exclude": [
9
+ "docs"
10
+ ]
11
+ },
12
+ "server": {
13
+ "hostname": "127.0.0.1",
14
+ "port": "14242",
15
+ "logger": {
16
+ "level": "info",
17
+ "transport": {
18
+ "target": "./custom-transport.js"
19
+ }
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "$schema": "https://platformatic.dev/schemas/v0.28.1/service",
3
+ "service": {
4
+ "openapi": true
5
+ },
6
+ "plugins": {
7
+ "paths": [
8
+ "./routes"
9
+ ],
10
+ "typescript": false
11
+ }
12
+ }
@@ -0,0 +1,6 @@
1
+ 'use strict'
2
+ module.exports = async function (fastify, opts) {
3
+ fastify.get('/', async (request, reply) => {
4
+ return { hello: 'world' }
5
+ })
6
+ }
@@ -9,7 +9,7 @@
9
9
  "docs"
10
10
  ]
11
11
  },
12
- "server": {
12
+ "server": {
13
13
  "hostname": "127.0.0.1",
14
14
  "port": "14242",
15
15
  "logger": {
@@ -0,0 +1,6 @@
1
+ 'use strict'
2
+ module.exports = async function (fastify, opts) {
3
+ fastify.get('/', async (request, reply) => {
4
+ return { hello: 'world' }
5
+ })
6
+ }
package/lib/worker.js CHANGED
@@ -28,26 +28,40 @@ if (typeof register === 'function' && workerData.config.loaderFile) {
28
28
 
29
29
  globalThis.fetch = undici.fetch
30
30
 
31
- let transport
31
+ const config = workerData.config
32
+
33
+ let loggerConfig = config.server?.logger
32
34
  let destination
33
35
 
36
+ if (loggerConfig) {
37
+ loggerConfig = { ...loggerConfig }
38
+ } else {
39
+ loggerConfig = {}
40
+ }
41
+
34
42
  /* c8 ignore next 10 */
35
- if (workerData.config.loggingPort) {
43
+ if (config.loggingPort) {
36
44
  destination = new MessagePortWritable({
37
- metadata: workerData.config.loggingMetadata,
38
- port: workerData.config.loggingPort
45
+ metadata: config.loggingMetadata,
46
+ port: config.loggingPort
39
47
  })
40
- } else if (isatty(1)) {
41
- transport = pino.transport({
48
+ delete loggerConfig.transport
49
+ } else if (!loggerConfig.transport && isatty(1)) {
50
+ loggerConfig.transport = {
42
51
  target: 'pino-pretty'
43
- })
52
+ }
44
53
  }
45
54
 
46
- const logger = pino(transport, destination)
55
+ const logger = pino(loggerConfig, destination)
56
+
57
+ if (config.server) {
58
+ config.server.logger = logger
59
+ }
47
60
 
48
61
  /* c8 ignore next 4 */
49
62
  process.once('uncaughtException', (err) => {
50
63
  logger.error({ err }, 'runtime error')
64
+ logger[pino.symbols.streamSym].flushSync?.()
51
65
  setImmediate(() => {
52
66
  process.exit(1)
53
67
  })
@@ -57,6 +71,7 @@ process.once('uncaughtException', (err) => {
57
71
  /* c8 ignore next 4 */
58
72
  process.once('unhandledRejection', (err) => {
59
73
  logger.error({ err }, 'runtime error')
74
+ logger[pino.symbols.streamSym].flushSync?.()
60
75
  setImmediate(() => {
61
76
  process.exit(1)
62
77
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/runtime",
3
- "version": "1.5.2",
3
+ "version": "1.6.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -22,13 +22,14 @@
22
22
  "execa": "^8.0.1",
23
23
  "express": "^4.18.2",
24
24
  "glob": "^10.3.10",
25
+ "pino-abstract-transport": "^1.1.0",
25
26
  "snazzy": "^9.0.0",
26
27
  "split2": "^4.2.0",
27
28
  "standard": "^17.1.0",
28
29
  "tsd": "^0.29.0",
29
30
  "typescript": "^5.2.2",
30
- "@platformatic/sql-graphql": "1.5.2",
31
- "@platformatic/sql-mapper": "1.5.2"
31
+ "@platformatic/sql-graphql": "1.6.1",
32
+ "@platformatic/sql-mapper": "1.6.1"
32
33
  },
33
34
  "dependencies": {
34
35
  "@fastify/error": "^3.4.0",
@@ -47,12 +48,12 @@
47
48
  "pino": "^8.16.0",
48
49
  "pino-pretty": "^10.2.3",
49
50
  "undici": "^5.26.3",
50
- "@platformatic/composer": "1.5.2",
51
- "@platformatic/config": "1.5.2",
52
- "@platformatic/db": "1.5.2",
53
- "@platformatic/service": "1.5.2",
54
- "@platformatic/telemetry": "1.5.2",
55
- "@platformatic/utils": "1.5.2"
51
+ "@platformatic/config": "1.6.1",
52
+ "@platformatic/composer": "1.6.1",
53
+ "@platformatic/db": "1.6.1",
54
+ "@platformatic/service": "1.6.1",
55
+ "@platformatic/telemetry": "1.6.1",
56
+ "@platformatic/utils": "1.6.1"
56
57
  },
57
58
  "standard": {
58
59
  "ignore": [
@@ -1,8 +0,0 @@
1
- 'use strict'
2
- module.exports = async function (fastify, opts) {
3
- // This returns the traceId set on the span by the service
4
- fastify.get('/', async (request, reply) => {
5
- const traceId = request.span.spanContext().traceId
6
- return { traceId }
7
- })
8
- }