@platformatic/runtime 1.5.1 → 1.6.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/fixtures/configs/monorepo.json +8 -1
- package/fixtures/monorepo/dbApp/platformatic.db.json +16 -0
- package/fixtures/server/logger-transport/custom-transport.js +15 -0
- package/fixtures/server/logger-transport/platformatic.runtime.json +22 -0
- package/fixtures/server/logger-transport/services/echo/platformatic.service.json +12 -0
- package/fixtures/server/logger-transport/services/echo/routes/hello.js +6 -0
- package/fixtures/server/runtime-server/platformatic.runtime.json +1 -1
- package/fixtures/server/runtime-server/services/echo/routes/hello.js +6 -0
- package/lib/api-client.js +4 -0
- package/lib/api.js +23 -0
- package/lib/errors.js +1 -0
- package/lib/worker.js +23 -8
- package/package.json +11 -9
- package/fixtures/server/runtime-server/services/echo/routes/span.js +0 -8
|
@@ -5,7 +5,10 @@
|
|
|
5
5
|
"hotReload": false,
|
|
6
6
|
"autoload": {
|
|
7
7
|
"path": "../monorepo",
|
|
8
|
-
"exclude": [
|
|
8
|
+
"exclude": [
|
|
9
|
+
"docs",
|
|
10
|
+
"composerApp"
|
|
11
|
+
],
|
|
9
12
|
"mappings": {
|
|
10
13
|
"serviceAppWithLogger": {
|
|
11
14
|
"id": "with-logger",
|
|
@@ -14,6 +17,10 @@
|
|
|
14
17
|
"serviceAppWithMultiplePlugins": {
|
|
15
18
|
"id": "multi-plugin-service",
|
|
16
19
|
"config": "platformatic.service.json"
|
|
20
|
+
},
|
|
21
|
+
"dbApp": {
|
|
22
|
+
"id": "db-app",
|
|
23
|
+
"config": "platformatic.db.json"
|
|
17
24
|
}
|
|
18
25
|
}
|
|
19
26
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://platformatic.dev/schemas/v0.22.0/db",
|
|
3
|
+
"server": {
|
|
4
|
+
"hostname": "127.0.0.1",
|
|
5
|
+
"port": 0
|
|
6
|
+
},
|
|
7
|
+
"db": {
|
|
8
|
+
"connectionString": "sqlite://db.sqlite",
|
|
9
|
+
"graphql": true,
|
|
10
|
+
"openapi": false,
|
|
11
|
+
"ignore": {
|
|
12
|
+
"versions": true
|
|
13
|
+
},
|
|
14
|
+
"events": false
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -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
|
+
}
|
package/lib/api-client.js
CHANGED
|
@@ -52,6 +52,10 @@ class RuntimeApiClient extends EventEmitter {
|
|
|
52
52
|
return this.#sendCommand('plt:get-service-openapi-schema', { id })
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
async getServiceGraphqlSchema (id) {
|
|
56
|
+
return this.#sendCommand('plt:get-service-graphql-schema', { id })
|
|
57
|
+
}
|
|
58
|
+
|
|
55
59
|
async startService (id) {
|
|
56
60
|
return this.#sendCommand('plt:start-service', { id })
|
|
57
61
|
}
|
package/lib/api.js
CHANGED
|
@@ -4,6 +4,7 @@ const FastifyUndiciDispatcher = require('fastify-undici-dispatcher')
|
|
|
4
4
|
const { Agent, setGlobalDispatcher } = require('undici')
|
|
5
5
|
const { PlatformaticApp } = require('./app')
|
|
6
6
|
const errors = require('./errors')
|
|
7
|
+
const { printSchema } = require('graphql')
|
|
7
8
|
|
|
8
9
|
class RuntimeApi {
|
|
9
10
|
#services
|
|
@@ -101,6 +102,8 @@ class RuntimeApi {
|
|
|
101
102
|
return this.#getServiceConfig(params)
|
|
102
103
|
case 'plt:get-service-openapi-schema':
|
|
103
104
|
return this.#getServiceOpenapiSchema(params)
|
|
105
|
+
case 'plt:get-service-graphql-schema':
|
|
106
|
+
return this.#getServiceGraphqlSchema(params)
|
|
104
107
|
case 'plt:start-service':
|
|
105
108
|
return this.#startService(params)
|
|
106
109
|
case 'plt:stop-service':
|
|
@@ -218,6 +221,26 @@ class RuntimeApi {
|
|
|
218
221
|
}
|
|
219
222
|
}
|
|
220
223
|
|
|
224
|
+
async #getServiceGraphqlSchema ({ id }) {
|
|
225
|
+
const service = this.#getServiceById(id)
|
|
226
|
+
|
|
227
|
+
if (!service.config) {
|
|
228
|
+
throw new errors.ServiceNotStartedError(id)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (typeof service.server.graphql !== 'function') {
|
|
232
|
+
return null
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
try {
|
|
236
|
+
await service.server.ready()
|
|
237
|
+
const graphqlSchema = printSchema(service.server.graphql.schema)
|
|
238
|
+
return graphqlSchema
|
|
239
|
+
} catch (err) {
|
|
240
|
+
throw new errors.FailedToRetrieveGraphQLSchemaError(id, err.message)
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
221
244
|
async #startService ({ id }) {
|
|
222
245
|
const service = this.#getServiceById(id)
|
|
223
246
|
await service.start()
|
package/lib/errors.js
CHANGED
|
@@ -10,6 +10,7 @@ module.exports = {
|
|
|
10
10
|
ServiceNotFoundError: createError(`${ERROR_PREFIX}_SERVICE_NOT_FOUND`, "Service with id '%s' not found"),
|
|
11
11
|
ServiceNotStartedError: createError(`${ERROR_PREFIX}_SERVICE_NOT_STARTED`, "Service with id '%s' is not started"),
|
|
12
12
|
FailedToRetrieveOpenAPISchemaError: createError(`${ERROR_PREFIX}_FAILED_TO_RETRIEVE_OPENAPI_SCHEMA`, 'Failed to retrieve OpenAPI schema for service with id "%s": %s'),
|
|
13
|
+
FailedToRetrieveGraphQLSchemaError: createError(`${ERROR_PREFIX}_FAILED_TO_RETRIEVE_GRAPHQL_SCHEMA`, 'Failed to retrieve GraphQL schema for service with id "%s": %s'),
|
|
13
14
|
ApplicationAlreadyStartedError: createError(`${ERROR_PREFIX}_APPLICATION_ALREADY_STARTED`, 'Application is already started'),
|
|
14
15
|
ApplicationNotStartedError: createError(`${ERROR_PREFIX}_APPLICATION_NOT_STARTED`, 'Application has not been started'),
|
|
15
16
|
ConfigPathMustBeStringError: createError(`${ERROR_PREFIX}_CONFIG_PATH_MUST_BE_STRING`, 'Config path must be a string'),
|
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
|
-
|
|
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 (
|
|
43
|
+
if (config.loggingPort) {
|
|
36
44
|
destination = new MessagePortWritable({
|
|
37
|
-
metadata:
|
|
38
|
-
port:
|
|
45
|
+
metadata: config.loggingMetadata,
|
|
46
|
+
port: config.loggingPort
|
|
39
47
|
})
|
|
40
|
-
|
|
41
|
-
|
|
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(
|
|
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.
|
|
3
|
+
"version": "1.6.0",
|
|
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.
|
|
31
|
-
"@platformatic/sql-mapper": "1.
|
|
31
|
+
"@platformatic/sql-graphql": "1.6.0",
|
|
32
|
+
"@platformatic/sql-mapper": "1.6.0"
|
|
32
33
|
},
|
|
33
34
|
"dependencies": {
|
|
34
35
|
"@fastify/error": "^3.4.0",
|
|
@@ -41,17 +42,18 @@
|
|
|
41
42
|
"fastest-levenshtein": "^1.0.16",
|
|
42
43
|
"fastify": "^4.24.1",
|
|
43
44
|
"fastify-undici-dispatcher": "^0.5.0",
|
|
45
|
+
"graphql": "^16.8.1",
|
|
44
46
|
"help-me": "^4.2.0",
|
|
45
47
|
"minimist": "^1.2.8",
|
|
46
48
|
"pino": "^8.16.0",
|
|
47
49
|
"pino-pretty": "^10.2.3",
|
|
48
50
|
"undici": "^5.26.3",
|
|
49
|
-
"@platformatic/composer": "1.
|
|
50
|
-
"@platformatic/
|
|
51
|
-
"@platformatic/
|
|
52
|
-
"@platformatic/service": "1.
|
|
53
|
-
"@platformatic/telemetry": "1.
|
|
54
|
-
"@platformatic/utils": "1.
|
|
51
|
+
"@platformatic/composer": "1.6.0",
|
|
52
|
+
"@platformatic/db": "1.6.0",
|
|
53
|
+
"@platformatic/config": "1.6.0",
|
|
54
|
+
"@platformatic/service": "1.6.0",
|
|
55
|
+
"@platformatic/telemetry": "1.6.0",
|
|
56
|
+
"@platformatic/utils": "1.6.0"
|
|
55
57
|
},
|
|
56
58
|
"standard": {
|
|
57
59
|
"ignore": [
|