@platformatic/service 2.0.0-alpha.7 → 2.0.0-alpha.9
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 +3 -0
- package/lib/plugins/metrics.js +1 -1
- package/lib/plugins/plugins.js +11 -4
- package/lib/schema.js +119 -119
- package/lib/stackable.js +41 -38
- package/lib/utils.js +12 -10
- package/package.json +24 -26
- package/schema.json +5 -2
package/config.d.ts
CHANGED
package/lib/plugins/metrics.js
CHANGED
|
@@ -170,7 +170,7 @@ async function createMetricsServer (app, hostname, port) {
|
|
|
170
170
|
httpServer.on('request', handler)
|
|
171
171
|
return httpServer
|
|
172
172
|
},
|
|
173
|
-
|
|
173
|
+
loggerInstance: app.log.child({ name: 'prometheus' }),
|
|
174
174
|
})
|
|
175
175
|
|
|
176
176
|
app.addHook('onClose', async () => {
|
package/lib/plugins/plugins.js
CHANGED
|
@@ -34,12 +34,19 @@ async function loadPlugins (app, opts) {
|
|
|
34
34
|
isOutDirAccessible = await isFileAccessible(outDir)
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
if (opts.context?.isProduction && !isOutDirAccessible) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
`Cannot access directory '${outDir}'. Please run the 'build' command before running in production mode.`
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
|
|
37
43
|
if (config.plugins.paths && isOutDirAccessible) {
|
|
38
|
-
config.plugins.paths = config.plugins.paths.map(
|
|
44
|
+
config.plugins.paths = config.plugins.paths.map(plugin => {
|
|
39
45
|
/* c8 ignore next 3 */
|
|
40
|
-
const tmp =
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
const tmp =
|
|
47
|
+
typeof plugin === 'string'
|
|
48
|
+
? getJSPluginPath(workingDir, plugin, outDir)
|
|
49
|
+
: { ...plugin, path: getJSPluginPath(workingDir, plugin.path, outDir) }
|
|
43
50
|
return tmp
|
|
44
51
|
})
|
|
45
52
|
}
|
package/lib/schema.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
const pkg = require('../package.json')
|
|
6
6
|
const openApiDefs = require('./openapi-schema-defs')
|
|
7
7
|
const telemetry = require('@platformatic/telemetry').schema
|
|
8
|
-
const { server, cors, watch } = require('@platformatic/utils').
|
|
8
|
+
const { server, cors, watch } = require('@platformatic/utils').schemaComponents
|
|
9
9
|
|
|
10
10
|
const plugins = {
|
|
11
11
|
type: 'object',
|
|
@@ -15,23 +15,23 @@ const plugins = {
|
|
|
15
15
|
items: {
|
|
16
16
|
anyOf: [
|
|
17
17
|
{
|
|
18
|
-
type: 'string'
|
|
18
|
+
type: 'string'
|
|
19
19
|
},
|
|
20
20
|
{
|
|
21
21
|
type: 'object',
|
|
22
22
|
properties: {
|
|
23
23
|
name: {
|
|
24
|
-
type: 'string'
|
|
24
|
+
type: 'string'
|
|
25
25
|
},
|
|
26
26
|
options: {
|
|
27
27
|
type: 'object',
|
|
28
|
-
additionalProperties: true
|
|
29
|
-
}
|
|
28
|
+
additionalProperties: true
|
|
29
|
+
}
|
|
30
30
|
},
|
|
31
|
-
required: ['name']
|
|
32
|
-
}
|
|
33
|
-
]
|
|
34
|
-
}
|
|
31
|
+
required: ['name']
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
35
|
},
|
|
36
36
|
paths: {
|
|
37
37
|
type: 'array',
|
|
@@ -39,63 +39,63 @@ const plugins = {
|
|
|
39
39
|
anyOf: [
|
|
40
40
|
{
|
|
41
41
|
type: 'string',
|
|
42
|
-
resolvePath: true
|
|
42
|
+
resolvePath: true
|
|
43
43
|
},
|
|
44
44
|
{
|
|
45
45
|
type: 'object',
|
|
46
46
|
properties: {
|
|
47
47
|
path: {
|
|
48
48
|
type: 'string',
|
|
49
|
-
resolvePath: true
|
|
49
|
+
resolvePath: true
|
|
50
50
|
},
|
|
51
51
|
encapsulate: {
|
|
52
52
|
type: 'boolean',
|
|
53
|
-
default: true
|
|
53
|
+
default: true
|
|
54
54
|
},
|
|
55
55
|
maxDepth: {
|
|
56
|
-
type: 'integer'
|
|
56
|
+
type: 'integer'
|
|
57
57
|
},
|
|
58
58
|
autoHooks: {
|
|
59
|
-
type: 'boolean'
|
|
59
|
+
type: 'boolean'
|
|
60
60
|
},
|
|
61
61
|
autoHooksPattern: {
|
|
62
|
-
type: 'string'
|
|
62
|
+
type: 'string'
|
|
63
63
|
},
|
|
64
64
|
cascadeHooks: {
|
|
65
|
-
type: 'boolean'
|
|
65
|
+
type: 'boolean'
|
|
66
66
|
},
|
|
67
67
|
overwriteHooks: {
|
|
68
|
-
type: 'boolean'
|
|
68
|
+
type: 'boolean'
|
|
69
69
|
},
|
|
70
70
|
routeParams: {
|
|
71
|
-
type: 'boolean'
|
|
71
|
+
type: 'boolean'
|
|
72
72
|
},
|
|
73
73
|
forceESM: {
|
|
74
|
-
type: 'boolean'
|
|
74
|
+
type: 'boolean'
|
|
75
75
|
},
|
|
76
76
|
ignoreFilter: {
|
|
77
|
-
type: 'string'
|
|
77
|
+
type: 'string'
|
|
78
78
|
},
|
|
79
79
|
matchFilter: {
|
|
80
|
-
type: 'string'
|
|
80
|
+
type: 'string'
|
|
81
81
|
},
|
|
82
82
|
ignorePattern: {
|
|
83
|
-
type: 'string'
|
|
83
|
+
type: 'string'
|
|
84
84
|
},
|
|
85
85
|
scriptPattern: {
|
|
86
|
-
type: 'string'
|
|
86
|
+
type: 'string'
|
|
87
87
|
},
|
|
88
88
|
indexPattern: {
|
|
89
|
-
type: 'string'
|
|
89
|
+
type: 'string'
|
|
90
90
|
},
|
|
91
91
|
options: {
|
|
92
92
|
type: 'object',
|
|
93
|
-
additionalProperties: true
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
]
|
|
98
|
-
}
|
|
93
|
+
additionalProperties: true
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
99
|
},
|
|
100
100
|
typescript: {
|
|
101
101
|
anyOf: [
|
|
@@ -105,47 +105,47 @@ const plugins = {
|
|
|
105
105
|
enabled: {
|
|
106
106
|
anyOf: [
|
|
107
107
|
{
|
|
108
|
-
type: 'boolean'
|
|
108
|
+
type: 'boolean'
|
|
109
109
|
},
|
|
110
110
|
{
|
|
111
|
-
type: 'string'
|
|
112
|
-
}
|
|
113
|
-
]
|
|
111
|
+
type: 'string'
|
|
112
|
+
}
|
|
113
|
+
]
|
|
114
114
|
},
|
|
115
115
|
tsConfig: {
|
|
116
116
|
type: 'string',
|
|
117
|
-
resolvePath: true
|
|
117
|
+
resolvePath: true
|
|
118
118
|
},
|
|
119
119
|
outDir: {
|
|
120
120
|
type: 'string',
|
|
121
|
-
resolvePath: true
|
|
121
|
+
resolvePath: true
|
|
122
122
|
},
|
|
123
123
|
flags: {
|
|
124
124
|
type: 'array',
|
|
125
125
|
items: {
|
|
126
|
-
type: 'string'
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
126
|
+
type: 'string'
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
130
|
},
|
|
131
131
|
{
|
|
132
|
-
type: 'boolean'
|
|
132
|
+
type: 'boolean'
|
|
133
133
|
},
|
|
134
134
|
{
|
|
135
|
-
type: 'string'
|
|
136
|
-
}
|
|
137
|
-
]
|
|
138
|
-
}
|
|
135
|
+
type: 'string'
|
|
136
|
+
}
|
|
137
|
+
]
|
|
138
|
+
}
|
|
139
139
|
},
|
|
140
140
|
additionalProperties: false,
|
|
141
141
|
anyOf: [
|
|
142
142
|
{
|
|
143
|
-
required: ['paths']
|
|
143
|
+
required: ['paths']
|
|
144
144
|
},
|
|
145
145
|
{
|
|
146
|
-
required: ['packages']
|
|
147
|
-
}
|
|
148
|
-
]
|
|
146
|
+
required: ['packages']
|
|
147
|
+
}
|
|
148
|
+
]
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
const metrics = {
|
|
@@ -155,143 +155,143 @@ const metrics = {
|
|
|
155
155
|
type: 'object',
|
|
156
156
|
properties: {
|
|
157
157
|
port: {
|
|
158
|
-
anyOf: [{ type: 'integer' }, { type: 'string' }]
|
|
158
|
+
anyOf: [{ type: 'integer' }, { type: 'string' }]
|
|
159
159
|
},
|
|
160
160
|
hostname: { type: 'string' },
|
|
161
161
|
endpoint: { type: 'string' },
|
|
162
162
|
server: {
|
|
163
163
|
type: 'string',
|
|
164
|
-
enum: ['own', 'parent', 'hide']
|
|
164
|
+
enum: ['own', 'parent', 'hide']
|
|
165
165
|
},
|
|
166
166
|
defaultMetrics: {
|
|
167
167
|
type: 'object',
|
|
168
168
|
properties: {
|
|
169
|
-
enabled: { type: 'boolean' }
|
|
169
|
+
enabled: { type: 'boolean' }
|
|
170
170
|
},
|
|
171
171
|
required: ['enabled'],
|
|
172
|
-
additionalProperties: false
|
|
172
|
+
additionalProperties: false
|
|
173
173
|
},
|
|
174
174
|
auth: {
|
|
175
175
|
type: 'object',
|
|
176
176
|
properties: {
|
|
177
177
|
username: { type: 'string' },
|
|
178
|
-
password: { type: 'string' }
|
|
178
|
+
password: { type: 'string' }
|
|
179
179
|
},
|
|
180
180
|
additionalProperties: false,
|
|
181
|
-
required: ['username', 'password']
|
|
181
|
+
required: ['username', 'password']
|
|
182
182
|
},
|
|
183
183
|
labels: {
|
|
184
184
|
type: 'object',
|
|
185
|
-
additionalProperties: { type: 'string' }
|
|
186
|
-
}
|
|
185
|
+
additionalProperties: { type: 'string' }
|
|
186
|
+
}
|
|
187
187
|
},
|
|
188
|
-
additionalProperties: false
|
|
189
|
-
}
|
|
190
|
-
]
|
|
188
|
+
additionalProperties: false
|
|
189
|
+
}
|
|
190
|
+
]
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
const openApiBase = {
|
|
194
194
|
type: 'object',
|
|
195
195
|
properties: {
|
|
196
196
|
info: {
|
|
197
|
-
$ref: '#/$defs/info'
|
|
197
|
+
$ref: '#/$defs/info'
|
|
198
198
|
},
|
|
199
199
|
jsonSchemaDialect: {
|
|
200
200
|
type: 'string',
|
|
201
201
|
|
|
202
|
-
default: 'https://spec.openapis.org/oas/3.1/dialect/base'
|
|
202
|
+
default: 'https://spec.openapis.org/oas/3.1/dialect/base'
|
|
203
203
|
},
|
|
204
204
|
servers: {
|
|
205
205
|
type: 'array',
|
|
206
206
|
items: {
|
|
207
|
-
$ref: '#/$defs/server'
|
|
207
|
+
$ref: '#/$defs/server'
|
|
208
208
|
},
|
|
209
209
|
default: [
|
|
210
210
|
{
|
|
211
|
-
url: '/'
|
|
212
|
-
}
|
|
213
|
-
]
|
|
211
|
+
url: '/'
|
|
212
|
+
}
|
|
213
|
+
]
|
|
214
214
|
},
|
|
215
215
|
paths: {
|
|
216
|
-
$ref: '#/$defs/paths'
|
|
216
|
+
$ref: '#/$defs/paths'
|
|
217
217
|
},
|
|
218
218
|
webhooks: {
|
|
219
219
|
type: 'object',
|
|
220
220
|
additionalProperties: {
|
|
221
|
-
$ref: '#/$defs/path-item-or-reference'
|
|
222
|
-
}
|
|
221
|
+
$ref: '#/$defs/path-item-or-reference'
|
|
222
|
+
}
|
|
223
223
|
},
|
|
224
224
|
components: {
|
|
225
|
-
$ref: '#/$defs/components'
|
|
225
|
+
$ref: '#/$defs/components'
|
|
226
226
|
},
|
|
227
227
|
security: {
|
|
228
228
|
type: 'array',
|
|
229
229
|
items: {
|
|
230
|
-
$ref: '#/$defs/security-requirement'
|
|
231
|
-
}
|
|
230
|
+
$ref: '#/$defs/security-requirement'
|
|
231
|
+
}
|
|
232
232
|
},
|
|
233
233
|
tags: {
|
|
234
234
|
type: 'array',
|
|
235
235
|
items: {
|
|
236
|
-
$ref: '#/$defs/tag'
|
|
237
|
-
}
|
|
236
|
+
$ref: '#/$defs/tag'
|
|
237
|
+
}
|
|
238
238
|
},
|
|
239
239
|
externalDocs: {
|
|
240
|
-
$ref: '#/$defs/external-documentation'
|
|
240
|
+
$ref: '#/$defs/external-documentation'
|
|
241
241
|
},
|
|
242
242
|
swaggerPrefix: {
|
|
243
243
|
type: 'string',
|
|
244
|
-
description: 'Base URL for the OpenAPI Swagger Documentation'
|
|
244
|
+
description: 'Base URL for the OpenAPI Swagger Documentation'
|
|
245
245
|
},
|
|
246
246
|
path: {
|
|
247
247
|
type: 'string',
|
|
248
248
|
description: 'Path to an OpenAPI spec file',
|
|
249
|
-
resolvePath: true
|
|
250
|
-
}
|
|
251
|
-
}
|
|
249
|
+
resolvePath: true
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
252
|
}
|
|
253
253
|
|
|
254
254
|
const openapi = {
|
|
255
255
|
anyOf: [
|
|
256
256
|
{
|
|
257
257
|
...openApiBase,
|
|
258
|
-
additionalProperties: false
|
|
258
|
+
additionalProperties: false
|
|
259
259
|
},
|
|
260
260
|
{
|
|
261
|
-
type: 'boolean'
|
|
262
|
-
}
|
|
263
|
-
]
|
|
261
|
+
type: 'boolean'
|
|
262
|
+
}
|
|
263
|
+
]
|
|
264
264
|
}
|
|
265
265
|
|
|
266
266
|
const graphqlBase = {
|
|
267
267
|
type: 'object',
|
|
268
268
|
properties: {
|
|
269
269
|
graphiql: {
|
|
270
|
-
type: 'boolean'
|
|
271
|
-
}
|
|
270
|
+
type: 'boolean'
|
|
271
|
+
}
|
|
272
272
|
},
|
|
273
|
-
additionalProperties: false
|
|
273
|
+
additionalProperties: false
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
const graphql = {
|
|
277
277
|
anyOf: [
|
|
278
278
|
{
|
|
279
279
|
...graphqlBase,
|
|
280
|
-
additionalProperties: false
|
|
280
|
+
additionalProperties: false
|
|
281
281
|
},
|
|
282
282
|
{
|
|
283
|
-
type: 'boolean'
|
|
284
|
-
}
|
|
285
|
-
]
|
|
283
|
+
type: 'boolean'
|
|
284
|
+
}
|
|
285
|
+
]
|
|
286
286
|
}
|
|
287
287
|
|
|
288
288
|
const service = {
|
|
289
289
|
type: 'object',
|
|
290
290
|
properties: {
|
|
291
291
|
openapi,
|
|
292
|
-
graphql
|
|
292
|
+
graphql
|
|
293
293
|
},
|
|
294
|
-
additionalProperties: false
|
|
294
|
+
additionalProperties: false
|
|
295
295
|
}
|
|
296
296
|
|
|
297
297
|
const clients = {
|
|
@@ -300,32 +300,32 @@ const clients = {
|
|
|
300
300
|
type: 'object',
|
|
301
301
|
properties: {
|
|
302
302
|
serviceId: {
|
|
303
|
-
type: 'string'
|
|
303
|
+
type: 'string'
|
|
304
304
|
},
|
|
305
305
|
name: {
|
|
306
|
-
type: 'string'
|
|
306
|
+
type: 'string'
|
|
307
307
|
},
|
|
308
308
|
type: {
|
|
309
309
|
type: 'string',
|
|
310
|
-
enum: ['openapi', 'graphql']
|
|
310
|
+
enum: ['openapi', 'graphql']
|
|
311
311
|
},
|
|
312
312
|
path: {
|
|
313
313
|
type: 'string',
|
|
314
|
-
resolvePath: true
|
|
314
|
+
resolvePath: true
|
|
315
315
|
},
|
|
316
316
|
schema: {
|
|
317
317
|
type: 'string',
|
|
318
|
-
resolvePath: true
|
|
318
|
+
resolvePath: true
|
|
319
319
|
},
|
|
320
320
|
url: {
|
|
321
|
-
type: 'string'
|
|
321
|
+
type: 'string'
|
|
322
322
|
},
|
|
323
323
|
fullResponse: { type: 'boolean' },
|
|
324
324
|
fullRequest: { type: 'boolean' },
|
|
325
|
-
validateResponse: { type: 'boolean' }
|
|
325
|
+
validateResponse: { type: 'boolean' }
|
|
326
326
|
},
|
|
327
|
-
additionalProperties: false
|
|
328
|
-
}
|
|
327
|
+
additionalProperties: false
|
|
328
|
+
}
|
|
329
329
|
}
|
|
330
330
|
|
|
331
331
|
const platformaticServiceSchema = {
|
|
@@ -342,24 +342,24 @@ const platformaticServiceSchema = {
|
|
|
342
342
|
anyOf: [
|
|
343
343
|
watch,
|
|
344
344
|
{
|
|
345
|
-
type: 'boolean'
|
|
345
|
+
type: 'boolean'
|
|
346
346
|
},
|
|
347
347
|
{
|
|
348
|
-
type: 'string'
|
|
349
|
-
}
|
|
350
|
-
]
|
|
348
|
+
type: 'string'
|
|
349
|
+
}
|
|
350
|
+
]
|
|
351
351
|
},
|
|
352
352
|
$schema: {
|
|
353
|
-
type: 'string'
|
|
353
|
+
type: 'string'
|
|
354
354
|
},
|
|
355
355
|
module: {
|
|
356
|
-
type: 'string'
|
|
356
|
+
type: 'string'
|
|
357
357
|
},
|
|
358
358
|
service,
|
|
359
|
-
clients
|
|
359
|
+
clients
|
|
360
360
|
},
|
|
361
361
|
additionalProperties: false,
|
|
362
|
-
$defs: openApiDefs
|
|
362
|
+
$defs: openApiDefs
|
|
363
363
|
}
|
|
364
364
|
|
|
365
365
|
/*
|
|
@@ -368,52 +368,52 @@ const platformaticServiceSchema = {
|
|
|
368
368
|
*/
|
|
369
369
|
Object.defineProperty(platformaticServiceSchema, 'schema', {
|
|
370
370
|
enumerable: false,
|
|
371
|
-
value: platformaticServiceSchema
|
|
371
|
+
value: platformaticServiceSchema
|
|
372
372
|
})
|
|
373
373
|
|
|
374
374
|
Object.defineProperty(platformaticServiceSchema, 'server', {
|
|
375
375
|
enumerable: false,
|
|
376
|
-
value: server
|
|
376
|
+
value: server
|
|
377
377
|
})
|
|
378
378
|
|
|
379
379
|
Object.defineProperty(platformaticServiceSchema, 'cors', {
|
|
380
380
|
enumerable: false,
|
|
381
|
-
value: cors
|
|
381
|
+
value: cors
|
|
382
382
|
})
|
|
383
383
|
|
|
384
384
|
Object.defineProperty(platformaticServiceSchema, 'metrics', {
|
|
385
385
|
enumerable: false,
|
|
386
|
-
value: metrics
|
|
386
|
+
value: metrics
|
|
387
387
|
})
|
|
388
388
|
|
|
389
389
|
Object.defineProperty(platformaticServiceSchema, 'plugins', {
|
|
390
390
|
enumerable: false,
|
|
391
|
-
value: plugins
|
|
391
|
+
value: plugins
|
|
392
392
|
})
|
|
393
393
|
|
|
394
394
|
Object.defineProperty(platformaticServiceSchema, 'watch', {
|
|
395
395
|
enumerable: false,
|
|
396
|
-
value: watch
|
|
396
|
+
value: watch
|
|
397
397
|
})
|
|
398
398
|
|
|
399
399
|
Object.defineProperty(platformaticServiceSchema, 'openApiDefs', {
|
|
400
400
|
enumerable: false,
|
|
401
|
-
value: openApiDefs
|
|
401
|
+
value: openApiDefs
|
|
402
402
|
})
|
|
403
403
|
|
|
404
404
|
Object.defineProperty(platformaticServiceSchema, 'openApiBase', {
|
|
405
405
|
enumerable: false,
|
|
406
|
-
value: openApiBase
|
|
406
|
+
value: openApiBase
|
|
407
407
|
})
|
|
408
408
|
|
|
409
409
|
Object.defineProperty(platformaticServiceSchema, 'graphqlBase', {
|
|
410
410
|
enumerable: false,
|
|
411
|
-
value: graphqlBase
|
|
411
|
+
value: graphqlBase
|
|
412
412
|
})
|
|
413
413
|
|
|
414
414
|
Object.defineProperty(platformaticServiceSchema, 'clients', {
|
|
415
415
|
enumerable: false,
|
|
416
|
-
value: clients
|
|
416
|
+
value: clients
|
|
417
417
|
})
|
|
418
418
|
|
|
419
419
|
/* end */
|
package/lib/stackable.js
CHANGED
|
@@ -4,6 +4,8 @@ const { dirname } = require('node:path')
|
|
|
4
4
|
const { printSchema } = require('graphql')
|
|
5
5
|
const pino = require('pino')
|
|
6
6
|
const httpMetrics = require('@platformatic/fastify-http-metrics')
|
|
7
|
+
const { extractTypeScriptCompileOptionsFromConfig } = require('./compile')
|
|
8
|
+
const { compile } = require('@platformatic/ts-compiler')
|
|
7
9
|
|
|
8
10
|
class ServiceStackable {
|
|
9
11
|
constructor (options) {
|
|
@@ -13,13 +15,14 @@ class ServiceStackable {
|
|
|
13
15
|
this.metricsRegistry = null
|
|
14
16
|
|
|
15
17
|
this.configManager = options.configManager
|
|
16
|
-
this.context = options.context
|
|
18
|
+
this.context = options.context ?? {}
|
|
19
|
+
this.context.stackable = this
|
|
17
20
|
|
|
18
|
-
this.configManager.on('error',
|
|
21
|
+
this.configManager.on('error', err => {
|
|
19
22
|
/* c8 ignore next */
|
|
20
23
|
this.stackable.log({
|
|
21
24
|
message: 'error reloading the configuration' + err,
|
|
22
|
-
level: 'error'
|
|
25
|
+
level: 'error'
|
|
23
26
|
})
|
|
24
27
|
})
|
|
25
28
|
|
|
@@ -54,6 +57,20 @@ class ServiceStackable {
|
|
|
54
57
|
await this.app.close()
|
|
55
58
|
}
|
|
56
59
|
|
|
60
|
+
async build () {
|
|
61
|
+
this.#initLogger()
|
|
62
|
+
const typeScriptCompileOptions = extractTypeScriptCompileOptionsFromConfig(this.configManager.current)
|
|
63
|
+
const cwd = dirname(this.configManager.fullPath)
|
|
64
|
+
const compileOptions = {
|
|
65
|
+
...typeScriptCompileOptions,
|
|
66
|
+
cwd,
|
|
67
|
+
logger: this.configManager.current.server.logger,
|
|
68
|
+
}
|
|
69
|
+
if (!await compile(compileOptions)) {
|
|
70
|
+
throw new Error(`Failed to compile ${cwd}`)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
57
74
|
getUrl () {
|
|
58
75
|
return this.app !== null ? this.app.url : null
|
|
59
76
|
}
|
|
@@ -65,8 +82,9 @@ class ServiceStackable {
|
|
|
65
82
|
}
|
|
66
83
|
|
|
67
84
|
async getConfig () {
|
|
68
|
-
const config = this.configManager.current
|
|
69
|
-
|
|
85
|
+
const config = Object.assign({}, this.configManager.current)
|
|
86
|
+
config.server = Object.assign({}, config.server)
|
|
87
|
+
const logger = config.server.loggerInstance
|
|
70
88
|
|
|
71
89
|
if (logger) {
|
|
72
90
|
config.server.logger = {}
|
|
@@ -76,29 +94,21 @@ class ServiceStackable {
|
|
|
76
94
|
}
|
|
77
95
|
}
|
|
78
96
|
|
|
79
|
-
|
|
80
|
-
}
|
|
97
|
+
delete config.server.loggerInstance
|
|
81
98
|
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
deploy: {
|
|
85
|
-
buildCommand: 'platformatic compile'
|
|
86
|
-
}
|
|
87
|
-
}
|
|
99
|
+
return config
|
|
88
100
|
}
|
|
89
101
|
|
|
90
102
|
async getWatchConfig () {
|
|
91
103
|
const config = this.configManager.current
|
|
92
104
|
|
|
93
|
-
const enabled =
|
|
94
|
-
config.watch?.enabled !== false &&
|
|
95
|
-
config.plugins !== undefined
|
|
105
|
+
const enabled = config.watch?.enabled !== false && config.plugins !== undefined
|
|
96
106
|
|
|
97
107
|
return {
|
|
98
108
|
enabled,
|
|
99
109
|
path: dirname(this.configManager.fullPath),
|
|
100
110
|
allow: config.watch?.allow,
|
|
101
|
-
ignore: config.watch?.ignore
|
|
111
|
+
ignore: config.watch?.ignore
|
|
102
112
|
}
|
|
103
113
|
}
|
|
104
114
|
|
|
@@ -155,16 +165,16 @@ class ServiceStackable {
|
|
|
155
165
|
this.app.register(httpMetrics, {
|
|
156
166
|
registry: this.metricsRegistry,
|
|
157
167
|
customLabels: ['telemetry_id'],
|
|
158
|
-
getCustomLabels:
|
|
168
|
+
getCustomLabels: req => {
|
|
159
169
|
const telemetryId = req.headers['x-plt-telemetry-id'] ?? 'unknown'
|
|
160
170
|
return { telemetry_id: telemetryId }
|
|
161
|
-
}
|
|
171
|
+
}
|
|
162
172
|
})
|
|
163
173
|
|
|
164
174
|
this.app.register(httpMetrics, {
|
|
165
175
|
registry: this.metricsRegistry,
|
|
166
176
|
customLabels: ['telemetry_id'],
|
|
167
|
-
getCustomLabels:
|
|
177
|
+
getCustomLabels: req => {
|
|
168
178
|
const telemetryId = req.headers['x-plt-telemetry-id'] ?? 'unknown'
|
|
169
179
|
return { telemetry_id: telemetryId }
|
|
170
180
|
},
|
|
@@ -173,30 +183,23 @@ class ServiceStackable {
|
|
|
173
183
|
help: 'request duration in seconds summary for all requests',
|
|
174
184
|
collect: function () {
|
|
175
185
|
process.nextTick(() => this.reset())
|
|
176
|
-
}
|
|
186
|
+
}
|
|
177
187
|
},
|
|
178
188
|
summary: {
|
|
179
189
|
name: 'http_request_all_summary_seconds',
|
|
180
190
|
help: 'request duration in seconds histogram for all requests',
|
|
181
191
|
collect: function () {
|
|
182
192
|
process.nextTick(() => this.reset())
|
|
183
|
-
}
|
|
184
|
-
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
185
195
|
})
|
|
186
196
|
}
|
|
187
197
|
|
|
188
198
|
#updateConfig () {
|
|
189
199
|
if (!this.context) return
|
|
190
200
|
|
|
191
|
-
const {
|
|
192
|
-
|
|
193
|
-
telemetryConfig,
|
|
194
|
-
metricsConfig,
|
|
195
|
-
serverConfig,
|
|
196
|
-
hasManagementApi,
|
|
197
|
-
isEntrypoint,
|
|
198
|
-
isProduction,
|
|
199
|
-
} = this.context
|
|
201
|
+
const { serviceId, telemetryConfig, metricsConfig, serverConfig, hasManagementApi, isEntrypoint, isProduction } =
|
|
202
|
+
this.context
|
|
200
203
|
|
|
201
204
|
const config = this.configManager.current
|
|
202
205
|
|
|
@@ -210,15 +213,13 @@ class ServiceStackable {
|
|
|
210
213
|
config.server = serverConfig
|
|
211
214
|
}
|
|
212
215
|
|
|
213
|
-
if (
|
|
214
|
-
(hasManagementApi && config.metrics === undefined) || config.metrics
|
|
215
|
-
) {
|
|
216
|
+
if ((hasManagementApi && config.metrics === undefined) || config.metrics) {
|
|
216
217
|
const labels = config.metrics?.labels || {}
|
|
217
218
|
config.metrics = {
|
|
218
219
|
server: 'hide',
|
|
219
220
|
defaultMetrics: { enabled: isEntrypoint },
|
|
220
221
|
...config.metrics,
|
|
221
|
-
labels: { serviceId, ...labels }
|
|
222
|
+
labels: { serviceId, ...labels }
|
|
222
223
|
}
|
|
223
224
|
}
|
|
224
225
|
|
|
@@ -242,14 +243,16 @@ class ServiceStackable {
|
|
|
242
243
|
const level = this.configManager.current.server.logger?.level
|
|
243
244
|
|
|
244
245
|
const pinoOptions = {
|
|
245
|
-
level: level ?? 'trace'
|
|
246
|
+
level: level ?? 'trace'
|
|
246
247
|
}
|
|
247
248
|
|
|
248
249
|
if (this.context?.serviceId) {
|
|
249
250
|
pinoOptions.name = this.context.serviceId
|
|
250
251
|
}
|
|
251
252
|
|
|
252
|
-
|
|
253
|
+
// Only one of logger and loggerInstance should be set
|
|
254
|
+
delete this.configManager.current.server.logger
|
|
255
|
+
this.configManager.current.server.loggerInstance = pino(pinoOptions)
|
|
253
256
|
}
|
|
254
257
|
}
|
|
255
258
|
|
package/lib/utils.js
CHANGED
|
@@ -21,17 +21,19 @@ function addLoggerToTheConfig (config) {
|
|
|
21
21
|
config.server = {}
|
|
22
22
|
}
|
|
23
23
|
// Set the logger if not present
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
if (!config.server.loggerInstance) {
|
|
25
|
+
let logger = config.server.logger
|
|
26
|
+
if (!logger) {
|
|
27
|
+
config.server.logger = { level: 'info' }
|
|
28
|
+
logger = config.server.logger
|
|
29
|
+
}
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
// If TTY use pino-pretty
|
|
32
|
+
if (isatty(1)) {
|
|
33
|
+
if (!logger.transport) {
|
|
34
|
+
logger.transport = {
|
|
35
|
+
target: 'pino-pretty',
|
|
36
|
+
}
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
}
|
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.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
"homepage": "https://github.com/platformatic/platformatic#readme",
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@fastify/aws-lambda": "^4.0.0",
|
|
21
|
-
"@fastify/compress": "^
|
|
21
|
+
"@fastify/compress": "^8.0.0",
|
|
22
22
|
"bindings": "^1.5.0",
|
|
23
23
|
"borp": "^0.17.0",
|
|
24
24
|
"eslint": "9",
|
|
25
25
|
"json-schema-to-typescript": "^15.0.0",
|
|
26
26
|
"neostandard": "^0.11.1",
|
|
27
27
|
"openapi-types": "^12.1.3",
|
|
28
|
-
"pino-abstract-transport": "^
|
|
28
|
+
"pino-abstract-transport": "^2.0.0",
|
|
29
29
|
"self-cert": "^2.0.0",
|
|
30
30
|
"split2": "^4.2.0",
|
|
31
31
|
"strip-ansi": "^7.1.0",
|
|
@@ -37,16 +37,16 @@
|
|
|
37
37
|
"yaml": "^2.4.1"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@fastify/accepts": "^
|
|
41
|
-
"@fastify/autoload": "^
|
|
42
|
-
"@fastify/basic-auth": "^
|
|
43
|
-
"@fastify/cors": "^
|
|
44
|
-
"@fastify/deepmerge": "^
|
|
45
|
-
"@fastify/error": "^
|
|
46
|
-
"@fastify/static": "^
|
|
47
|
-
"@fastify/swagger": "^
|
|
48
|
-
"@fastify/under-pressure": "^
|
|
49
|
-
"@mercuriusjs/federation": "^
|
|
40
|
+
"@fastify/accepts": "^5.0.0",
|
|
41
|
+
"@fastify/autoload": "^6.0.0",
|
|
42
|
+
"@fastify/basic-auth": "^6.0.0",
|
|
43
|
+
"@fastify/cors": "^10.0.0",
|
|
44
|
+
"@fastify/deepmerge": "^2.0.0",
|
|
45
|
+
"@fastify/error": "^4.0.0",
|
|
46
|
+
"@fastify/static": "^8.0.0",
|
|
47
|
+
"@fastify/swagger": "^9.0.0",
|
|
48
|
+
"@fastify/under-pressure": "^9.0.0",
|
|
49
|
+
"@mercuriusjs/federation": "^4.0.0",
|
|
50
50
|
"@platformatic/fastify-http-metrics": "^0.1.0",
|
|
51
51
|
"@scalar/fastify-api-reference": "^1.19.5",
|
|
52
52
|
"@types/ws": "^8.5.10",
|
|
@@ -61,29 +61,27 @@
|
|
|
61
61
|
"env-schema": "^5.2.1",
|
|
62
62
|
"es-main": "^1.3.0",
|
|
63
63
|
"execa": "^8.0.1",
|
|
64
|
-
"fastify": "
|
|
65
|
-
"fastify-
|
|
66
|
-
"fastify-openapi-glue": "^4.4.3",
|
|
67
|
-
"fastify-plugin": "^4.5.1",
|
|
64
|
+
"fastify": "5.0.0-alpha.4",
|
|
65
|
+
"fastify-plugin": "^5.0.0",
|
|
68
66
|
"graphql": "^16.9.0",
|
|
69
67
|
"help-me": "^5.0.0",
|
|
70
|
-
"mercurius": "^
|
|
68
|
+
"mercurius": "^15.0.0",
|
|
71
69
|
"minimist": "^1.2.8",
|
|
72
70
|
"my-ua-parser": "^2.0.2",
|
|
73
71
|
"ora": "^6.3.1",
|
|
74
|
-
"pino": "^
|
|
72
|
+
"pino": "^9.0.0",
|
|
75
73
|
"pino-pretty": "^11.0.0",
|
|
76
74
|
"prom-client": "^15.1.2",
|
|
77
75
|
"rfdc": "^1.3.1",
|
|
78
76
|
"semgrator": "^0.3.0",
|
|
79
77
|
"undici": "^6.9.0",
|
|
80
|
-
"@platformatic/client": "2.0.0-alpha.
|
|
81
|
-
"@platformatic/
|
|
82
|
-
"@platformatic/
|
|
83
|
-
"@platformatic/
|
|
84
|
-
"@platformatic/telemetry": "2.0.0-alpha.
|
|
85
|
-
"@platformatic/ts-compiler": "2.0.0-alpha.
|
|
86
|
-
"@platformatic/utils": "2.0.0-alpha.
|
|
78
|
+
"@platformatic/client": "2.0.0-alpha.9",
|
|
79
|
+
"@platformatic/generators": "2.0.0-alpha.9",
|
|
80
|
+
"@platformatic/config": "2.0.0-alpha.9",
|
|
81
|
+
"@platformatic/scalar-theme": "2.0.0-alpha.9",
|
|
82
|
+
"@platformatic/telemetry": "2.0.0-alpha.9",
|
|
83
|
+
"@platformatic/ts-compiler": "2.0.0-alpha.9",
|
|
84
|
+
"@platformatic/utils": "2.0.0-alpha.9"
|
|
87
85
|
},
|
|
88
86
|
"scripts": {
|
|
89
87
|
"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.9.json",
|
|
3
|
+
"version": "2.0.0-alpha.9",
|
|
4
4
|
"title": "Platformatic Service",
|
|
5
5
|
"type": "object",
|
|
6
6
|
"properties": {
|
|
@@ -158,6 +158,9 @@
|
|
|
158
158
|
}
|
|
159
159
|
]
|
|
160
160
|
},
|
|
161
|
+
"loggerInstance": {
|
|
162
|
+
"type": "object"
|
|
163
|
+
},
|
|
161
164
|
"serializerOpts": {
|
|
162
165
|
"type": "object",
|
|
163
166
|
"properties": {
|