@platformatic/service 2.0.0-alpha.5 → 2.0.0-alpha.7
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 +3 -3
- package/lib/plugins/plugins.js +2 -2
- package/lib/plugins/typescript.js +2 -2
- package/lib/stackable.js +54 -8
- package/lib/start.js +10 -9
- package/package.json +9 -8
- package/schema.json +2 -2
package/index.js
CHANGED
|
@@ -80,9 +80,9 @@ async function platformaticService (app, opts) {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
if (registerTsCompiler) {
|
|
83
|
-
app.register(setupTsCompiler)
|
|
83
|
+
app.register(setupTsCompiler, { context: opts.context })
|
|
84
84
|
}
|
|
85
|
-
app.register(loadPlugins)
|
|
85
|
+
app.register(loadPlugins, { context: opts.context })
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
if (isKeyEnabled('cors', config.server)) {
|
|
@@ -168,7 +168,7 @@ async function buildStackable (
|
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
const stackable = new Stackable({
|
|
171
|
-
init: () => buildServer(configManager.current, app),
|
|
171
|
+
init: () => buildServer(configManager.current, app, options.context),
|
|
172
172
|
stackable: app,
|
|
173
173
|
configManager,
|
|
174
174
|
context: options.context,
|
package/lib/plugins/plugins.js
CHANGED
|
@@ -7,14 +7,14 @@ const wrapper = require('./sandbox-wrapper')
|
|
|
7
7
|
|
|
8
8
|
const { getJSPluginPath, isFileAccessible } = require('../utils')
|
|
9
9
|
|
|
10
|
-
async function loadPlugins (app) {
|
|
10
|
+
async function loadPlugins (app, opts) {
|
|
11
11
|
const configManager = app.platformatic.configManager
|
|
12
12
|
const config = configManager.current
|
|
13
13
|
|
|
14
14
|
let isOutDirAccessible = false
|
|
15
15
|
let outDir = null
|
|
16
16
|
|
|
17
|
-
const workingDir = configManager.dirname
|
|
17
|
+
const workingDir = opts?.context?.directory ?? configManager.dirname
|
|
18
18
|
const tsConfigPath = configManager.current.plugins.typescript?.tsConfig || join(workingDir, 'tsconfig.json')
|
|
19
19
|
|
|
20
20
|
// If the tsconfig.json file exists, then we need to adjust the plugin paths
|
|
@@ -4,10 +4,10 @@ const fp = require('fastify-plugin')
|
|
|
4
4
|
const compiler = require('@platformatic/ts-compiler')
|
|
5
5
|
const { extractTypeScriptCompileOptionsFromConfig } = require('../compile')
|
|
6
6
|
|
|
7
|
-
async function setupTsCompiler (app) {
|
|
7
|
+
async function setupTsCompiler (app, opts) {
|
|
8
8
|
const configManager = app.platformatic.configManager
|
|
9
9
|
const config = configManager.current
|
|
10
|
-
const workingDir = configManager.dirname
|
|
10
|
+
const workingDir = opts?.context?.directory ?? configManager.dirname
|
|
11
11
|
|
|
12
12
|
await compiler.compile({
|
|
13
13
|
...extractTypeScriptCompileOptionsFromConfig(config),
|
package/lib/stackable.js
CHANGED
|
@@ -3,12 +3,14 @@
|
|
|
3
3
|
const { dirname } = require('node:path')
|
|
4
4
|
const { printSchema } = require('graphql')
|
|
5
5
|
const pino = require('pino')
|
|
6
|
+
const httpMetrics = require('@platformatic/fastify-http-metrics')
|
|
6
7
|
|
|
7
8
|
class ServiceStackable {
|
|
8
9
|
constructor (options) {
|
|
9
10
|
this.app = null
|
|
10
11
|
this._init = options.init
|
|
11
12
|
this.stackable = options.stackable
|
|
13
|
+
this.metricsRegistry = null
|
|
12
14
|
|
|
13
15
|
this.configManager = options.configManager
|
|
14
16
|
this.context = options.context
|
|
@@ -29,6 +31,10 @@ class ServiceStackable {
|
|
|
29
31
|
|
|
30
32
|
if (this.app === null) {
|
|
31
33
|
this.app = await this._init()
|
|
34
|
+
|
|
35
|
+
if (this.metricsRegistry) {
|
|
36
|
+
this.#setHttpMetrics()
|
|
37
|
+
}
|
|
32
38
|
}
|
|
33
39
|
return this.app
|
|
34
40
|
}
|
|
@@ -73,6 +79,14 @@ class ServiceStackable {
|
|
|
73
79
|
return config
|
|
74
80
|
}
|
|
75
81
|
|
|
82
|
+
getMeta () {
|
|
83
|
+
return {
|
|
84
|
+
deploy: {
|
|
85
|
+
buildCommand: 'platformatic compile'
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
76
90
|
async getWatchConfig () {
|
|
77
91
|
const config = this.configManager.current
|
|
78
92
|
|
|
@@ -105,15 +119,13 @@ class ServiceStackable {
|
|
|
105
119
|
return this.app.graphql ? printSchema(this.app.graphql.schema) : null
|
|
106
120
|
}
|
|
107
121
|
|
|
108
|
-
async
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const promRegister = this.app.metrics?.client?.register
|
|
112
|
-
if (!promRegister) return null
|
|
122
|
+
async collectMetrics ({ registry }) {
|
|
123
|
+
this.metricsRegistry = registry
|
|
113
124
|
|
|
114
|
-
return
|
|
115
|
-
|
|
116
|
-
:
|
|
125
|
+
return {
|
|
126
|
+
defaultMetrics: true,
|
|
127
|
+
httpMetrics: false
|
|
128
|
+
}
|
|
117
129
|
}
|
|
118
130
|
|
|
119
131
|
async inject (injectParams) {
|
|
@@ -139,6 +151,40 @@ class ServiceStackable {
|
|
|
139
151
|
this.#updateConfig()
|
|
140
152
|
}
|
|
141
153
|
|
|
154
|
+
#setHttpMetrics () {
|
|
155
|
+
this.app.register(httpMetrics, {
|
|
156
|
+
registry: this.metricsRegistry,
|
|
157
|
+
customLabels: ['telemetry_id'],
|
|
158
|
+
getCustomLabels: (req) => {
|
|
159
|
+
const telemetryId = req.headers['x-plt-telemetry-id'] ?? 'unknown'
|
|
160
|
+
return { telemetry_id: telemetryId }
|
|
161
|
+
},
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
this.app.register(httpMetrics, {
|
|
165
|
+
registry: this.metricsRegistry,
|
|
166
|
+
customLabels: ['telemetry_id'],
|
|
167
|
+
getCustomLabels: (req) => {
|
|
168
|
+
const telemetryId = req.headers['x-plt-telemetry-id'] ?? 'unknown'
|
|
169
|
+
return { telemetry_id: telemetryId }
|
|
170
|
+
},
|
|
171
|
+
histogram: {
|
|
172
|
+
name: 'http_request_all_duration_seconds',
|
|
173
|
+
help: 'request duration in seconds summary for all requests',
|
|
174
|
+
collect: function () {
|
|
175
|
+
process.nextTick(() => this.reset())
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
summary: {
|
|
179
|
+
name: 'http_request_all_summary_seconds',
|
|
180
|
+
help: 'request duration in seconds histogram for all requests',
|
|
181
|
+
collect: function () {
|
|
182
|
+
process.nextTick(() => this.reset())
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
})
|
|
186
|
+
}
|
|
187
|
+
|
|
142
188
|
#updateConfig () {
|
|
143
189
|
if (!this.context) return
|
|
144
190
|
|
package/lib/start.js
CHANGED
|
@@ -25,8 +25,8 @@ async function adjustHttpsKeyAndCert (arg) {
|
|
|
25
25
|
return arg
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
async function createServer (
|
|
29
|
-
const { app, configManager } =
|
|
28
|
+
async function createServer (serverContext) {
|
|
29
|
+
const { app, configManager, context } = serverContext
|
|
30
30
|
const config = configManager.current
|
|
31
31
|
let fastifyOptions = {}
|
|
32
32
|
|
|
@@ -42,14 +42,14 @@ async function createServer (context) {
|
|
|
42
42
|
fastifyOptions.genReqId = function (req) { return randomUUID() }
|
|
43
43
|
const root = fastify(fastifyOptions)
|
|
44
44
|
root.decorate('platformatic', { configManager, config })
|
|
45
|
-
await root.register(app)
|
|
45
|
+
await root.register(app, { context })
|
|
46
46
|
if (!root.hasRoute({ url: '/', method: 'GET' })) {
|
|
47
47
|
await root.register(require('./root-endpoint'))
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
root.decorate('url', {
|
|
51
51
|
getter () {
|
|
52
|
-
return
|
|
52
|
+
return serverContext.url
|
|
53
53
|
},
|
|
54
54
|
})
|
|
55
55
|
|
|
@@ -65,7 +65,7 @@ async function buildConfigManager (options, app) {
|
|
|
65
65
|
return configManager
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
async function buildServer (options, app) {
|
|
68
|
+
async function buildServer (options, app, context) {
|
|
69
69
|
const configManager = await buildConfigManager(options, app)
|
|
70
70
|
const config = configManager.current
|
|
71
71
|
|
|
@@ -84,17 +84,18 @@ async function buildServer (options, app) {
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
const
|
|
87
|
+
const serverContext = {
|
|
88
88
|
app: typeof app === 'function' ? app : app.app,
|
|
89
89
|
configManager,
|
|
90
|
+
context
|
|
90
91
|
}
|
|
91
|
-
const handler = await createServer(
|
|
92
|
+
const handler = await createServer(serverContext)
|
|
92
93
|
handler.decorate('start', async () => {
|
|
93
|
-
|
|
94
|
+
serverContext.url = await handler.listen({
|
|
94
95
|
host: options.server?.hostname || '127.0.0.1',
|
|
95
96
|
port: options.server?.port || 0,
|
|
96
97
|
})
|
|
97
|
-
return
|
|
98
|
+
return serverContext.url
|
|
98
99
|
})
|
|
99
100
|
configManager.on('error', function (err) {
|
|
100
101
|
/* c8 ignore next 1 */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/service",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"@fastify/swagger": "^8.14.0",
|
|
48
48
|
"@fastify/under-pressure": "^8.3.0",
|
|
49
49
|
"@mercuriusjs/federation": "^3.0.0",
|
|
50
|
+
"@platformatic/fastify-http-metrics": "^0.1.0",
|
|
50
51
|
"@scalar/fastify-api-reference": "^1.19.5",
|
|
51
52
|
"@types/ws": "^8.5.10",
|
|
52
53
|
"ajv": "^8.12.0",
|
|
@@ -76,13 +77,13 @@
|
|
|
76
77
|
"rfdc": "^1.3.1",
|
|
77
78
|
"semgrator": "^0.3.0",
|
|
78
79
|
"undici": "^6.9.0",
|
|
79
|
-
"@platformatic/client": "2.0.0-alpha.
|
|
80
|
-
"@platformatic/
|
|
81
|
-
"@platformatic/generators": "2.0.0-alpha.
|
|
82
|
-
"@platformatic/
|
|
83
|
-
"@platformatic/
|
|
84
|
-
"@platformatic/
|
|
85
|
-
"@platformatic/utils": "2.0.0-alpha.
|
|
80
|
+
"@platformatic/client": "2.0.0-alpha.7",
|
|
81
|
+
"@platformatic/scalar-theme": "2.0.0-alpha.7",
|
|
82
|
+
"@platformatic/generators": "2.0.0-alpha.7",
|
|
83
|
+
"@platformatic/config": "2.0.0-alpha.7",
|
|
84
|
+
"@platformatic/telemetry": "2.0.0-alpha.7",
|
|
85
|
+
"@platformatic/ts-compiler": "2.0.0-alpha.7",
|
|
86
|
+
"@platformatic/utils": "2.0.0-alpha.7"
|
|
86
87
|
},
|
|
87
88
|
"scripts": {
|
|
88
89
|
"test": "pnpm run lint && borp -T --concurrency=1 --timeout=180000 && tsd",
|
package/schema.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$id": "https://schemas.platformatic.dev/@platformatic/service/2.0.0-alpha.
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
2
|
+
"$id": "https://schemas.platformatic.dev/@platformatic/service/2.0.0-alpha.7.json",
|
|
3
|
+
"version": "2.0.0-alpha.7",
|
|
4
4
|
"title": "Platformatic Service",
|
|
5
5
|
"type": "object",
|
|
6
6
|
"properties": {
|