@platformatic/service 2.7.1-alpha.2 → 2.8.0-alpha.2
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/lib/stackable.js +26 -19
- package/package.json +11 -11
- package/schema.json +2 -2
package/lib/stackable.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const { hostname } = require('node:os')
|
|
3
4
|
const { dirname } = require('node:path')
|
|
5
|
+
const { pathToFileURL } = require('node:url')
|
|
4
6
|
const { printSchema } = require('graphql')
|
|
5
7
|
const pino = require('pino')
|
|
6
8
|
const { collectMetrics } = require('@platformatic/metrics')
|
|
@@ -9,8 +11,6 @@ const { extractTypeScriptCompileOptionsFromConfig } = require('./compile')
|
|
|
9
11
|
const { compile } = require('@platformatic/ts-compiler')
|
|
10
12
|
const { deepmerge } = require('@platformatic/utils')
|
|
11
13
|
|
|
12
|
-
const kITC = Symbol.for('plt.runtime.itc')
|
|
13
|
-
|
|
14
14
|
class ServiceStackable {
|
|
15
15
|
constructor (options) {
|
|
16
16
|
this.app = null
|
|
@@ -22,6 +22,10 @@ class ServiceStackable {
|
|
|
22
22
|
this.context = options.context ?? {}
|
|
23
23
|
this.context.stackable = this
|
|
24
24
|
|
|
25
|
+
this.serviceId = this.context.serviceId
|
|
26
|
+
this.context.worker ??= { count: 1, index: 0 }
|
|
27
|
+
this.workerId = this.context.worker.count > 1 ? this.context.worker.index : undefined
|
|
28
|
+
|
|
25
29
|
this.configManager.on('error', err => {
|
|
26
30
|
/* c8 ignore next */
|
|
27
31
|
this.stackable.log({
|
|
@@ -34,10 +38,13 @@ class ServiceStackable {
|
|
|
34
38
|
|
|
35
39
|
// Setup globals
|
|
36
40
|
this.registerGlobals({
|
|
41
|
+
serviceId: this.serviceId,
|
|
42
|
+
workerId: this.workerId,
|
|
43
|
+
// Always use URL to avoid serialization problem in Windows
|
|
44
|
+
root: this.context.directory ? pathToFileURL(this.context.directory).toString() : undefined,
|
|
37
45
|
setOpenapiSchema: this.setOpenapiSchema.bind(this),
|
|
38
46
|
setGraphqlSchema: this.setGraphqlSchema.bind(this),
|
|
39
|
-
setBasePath: this.setBasePath.bind(this)
|
|
40
|
-
invalidateHttpCache: this.#invalidateHttpCache.bind(this)
|
|
47
|
+
setBasePath: this.setBasePath.bind(this)
|
|
41
48
|
})
|
|
42
49
|
}
|
|
43
50
|
|
|
@@ -160,15 +167,13 @@ class ServiceStackable {
|
|
|
160
167
|
// fastify metrics before the server is started.
|
|
161
168
|
async #collectMetrics () {
|
|
162
169
|
const metricsConfig = this.context.metricsConfig
|
|
170
|
+
|
|
163
171
|
if (metricsConfig !== false) {
|
|
164
|
-
const { registry } = await collectMetrics(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
...metricsConfig
|
|
170
|
-
}
|
|
171
|
-
)
|
|
172
|
+
const { registry } = await collectMetrics(this.context.serviceId, this.context.worker.index, {
|
|
173
|
+
defaultMetrics: true,
|
|
174
|
+
httpMetrics: false,
|
|
175
|
+
...metricsConfig
|
|
176
|
+
})
|
|
172
177
|
this.metricsRegistry = registry
|
|
173
178
|
this.#setHttpMetrics()
|
|
174
179
|
}
|
|
@@ -177,9 +182,7 @@ class ServiceStackable {
|
|
|
177
182
|
async getMetrics ({ format }) {
|
|
178
183
|
if (!this.metricsRegistry) return null
|
|
179
184
|
|
|
180
|
-
return format === 'json'
|
|
181
|
-
? await this.metricsRegistry.getMetricsAsJSON()
|
|
182
|
-
: await this.metricsRegistry.metrics()
|
|
185
|
+
return format === 'json' ? await this.metricsRegistry.getMetricsAsJSON() : await this.metricsRegistry.metrics()
|
|
183
186
|
}
|
|
184
187
|
|
|
185
188
|
async inject (injectParams) {
|
|
@@ -221,10 +224,6 @@ class ServiceStackable {
|
|
|
221
224
|
globalThis.platformatic = Object.assign(globalThis.platformatic ?? {}, globals)
|
|
222
225
|
}
|
|
223
226
|
|
|
224
|
-
async #invalidateHttpCache (opts = {}) {
|
|
225
|
-
await globalThis[kITC].send('invalidateHttpCache', opts)
|
|
226
|
-
}
|
|
227
|
-
|
|
228
227
|
#setHttpMetrics () {
|
|
229
228
|
this.app.register(httpMetrics, {
|
|
230
229
|
registry: this.metricsRegistry,
|
|
@@ -315,10 +314,18 @@ class ServiceStackable {
|
|
|
315
314
|
level: this.loggerConfig?.level ?? 'trace'
|
|
316
315
|
}
|
|
317
316
|
|
|
317
|
+
this.registerGlobals({
|
|
318
|
+
logLevel: pinoOptions.level
|
|
319
|
+
})
|
|
320
|
+
|
|
318
321
|
if (this.context?.serviceId) {
|
|
319
322
|
pinoOptions.name = this.context.serviceId
|
|
320
323
|
}
|
|
321
324
|
|
|
325
|
+
if (typeof this.context?.worker?.index !== 'undefined') {
|
|
326
|
+
pinoOptions.base = { pid: process.pid, hostname: hostname(), worker: this.context.worker.index }
|
|
327
|
+
}
|
|
328
|
+
|
|
322
329
|
this.logger = pino(pinoOptions)
|
|
323
330
|
|
|
324
331
|
// Only one of logger and loggerInstance should be set
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/service",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0-alpha.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -76,18 +76,18 @@
|
|
|
76
76
|
"rfdc": "^1.3.1",
|
|
77
77
|
"semgrator": "^0.3.0",
|
|
78
78
|
"undici": "^6.9.0",
|
|
79
|
-
"@platformatic/client": "2.
|
|
80
|
-
"@platformatic/
|
|
81
|
-
"@platformatic/
|
|
82
|
-
"@platformatic/generators": "2.
|
|
83
|
-
"@platformatic/
|
|
84
|
-
"@platformatic/
|
|
85
|
-
"@platformatic/ts-compiler": "2.
|
|
86
|
-
"@platformatic/utils": "2.
|
|
79
|
+
"@platformatic/client": "2.8.0-alpha.2",
|
|
80
|
+
"@platformatic/metrics": "2.8.0-alpha.2",
|
|
81
|
+
"@platformatic/config": "2.8.0-alpha.2",
|
|
82
|
+
"@platformatic/generators": "2.8.0-alpha.2",
|
|
83
|
+
"@platformatic/telemetry": "2.8.0-alpha.2",
|
|
84
|
+
"@platformatic/scalar-theme": "2.8.0-alpha.2",
|
|
85
|
+
"@platformatic/ts-compiler": "2.8.0-alpha.2",
|
|
86
|
+
"@platformatic/utils": "2.8.0-alpha.2"
|
|
87
87
|
},
|
|
88
88
|
"scripts": {
|
|
89
|
-
"test": "pnpm run lint && borp -T --concurrency=1 --timeout=
|
|
90
|
-
"unit": "borp --pattern 'test/**/*.test.{js,mjs}' --ignore 'fixtures/**/*' --concurrency=1 --timeout=
|
|
89
|
+
"test": "pnpm run lint && borp -T --concurrency=1 --timeout=300000 && tsd",
|
|
90
|
+
"unit": "borp --pattern 'test/**/*.test.{js,mjs}' --ignore 'fixtures/**/*' --concurrency=1 --timeout=300000 --no-typescript",
|
|
91
91
|
"gen-schema": "node lib/schema.js > schema.json",
|
|
92
92
|
"gen-types": "json2ts > config.d.ts < schema.json",
|
|
93
93
|
"build": "pnpm run gen-schema && pnpm run gen-types",
|
package/schema.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$id": "https://schemas.platformatic.dev/@platformatic/service/2.
|
|
3
|
-
"version": "2.
|
|
2
|
+
"$id": "https://schemas.platformatic.dev/@platformatic/service/2.8.0-alpha.2.json",
|
|
3
|
+
"version": "2.8.0-alpha.2",
|
|
4
4
|
"title": "Platformatic Service",
|
|
5
5
|
"type": "object",
|
|
6
6
|
"properties": {
|