@platformatic/service 2.0.0-alpha.14 → 2.0.0-alpha.16

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 CHANGED
@@ -31,7 +31,13 @@ export interface PlatformaticService {
31
31
  logger?:
32
32
  | boolean
33
33
  | {
34
- level?: string;
34
+ level: (
35
+ | ("fatal" | "error" | "warn" | "info" | "debug" | "trace" | "silent")
36
+ | {
37
+ [k: string]: unknown;
38
+ }
39
+ ) &
40
+ string;
35
41
  transport?:
36
42
  | {
37
43
  target?: string;
package/index.js CHANGED
@@ -104,7 +104,7 @@ module.exports.configManagerConfig = {
104
104
  useDefaults: true,
105
105
  coerceTypes: true,
106
106
  allErrors: true,
107
- strict: false,
107
+ strict: false
108
108
  },
109
109
  async transformConfig () {
110
110
  // Set watch to true by default. This is not possible
@@ -134,7 +134,7 @@ module.exports.configManagerConfig = {
134
134
  this.current.watch.ignore.push(outDir + '/**/*')
135
135
  }
136
136
  },
137
- upgrade,
137
+ upgrade
138
138
  }
139
139
 
140
140
  platformaticService.configType = 'service'
@@ -145,23 +145,26 @@ function _buildServer (options, app) {
145
145
  return buildServer(options, app || module.exports)
146
146
  }
147
147
 
148
- async function buildStackable (
149
- options,
150
- app = platformaticService,
151
- Stackable = ServiceStackable
152
- ) {
148
+ async function buildStackable (options, app = platformaticService, Stackable = ServiceStackable) {
153
149
  let configManager = options.configManager
154
150
 
155
151
  if (configManager === undefined) {
156
152
  if (typeof options.config === 'string') {
157
- ({ configManager } = await loadConfig({}, ['-c', options.config], app, {
158
- onMissingEnv: options.onMissingEnv,
159
- context: options.context,
160
- }, true))
153
+ ;({ configManager } = await loadConfig(
154
+ {},
155
+ ['-c', options.config],
156
+ app,
157
+ {
158
+ onMissingEnv: options.onMissingEnv,
159
+ context: options.context
160
+ },
161
+ true
162
+ ))
161
163
  } else {
162
164
  configManager = new ConfigManager({
163
165
  ...app.configManagerConfig,
164
166
  source: options.config,
167
+ dirname: options.context?.directory
165
168
  })
166
169
  await configManager.parseAndValidate()
167
170
  }
@@ -171,7 +174,7 @@ async function buildStackable (
171
174
  init: () => buildServer(configManager.current, app, options.context),
172
175
  stackable: app,
173
176
  configManager,
174
- context: options.context,
177
+ context: options.context
175
178
  })
176
179
 
177
180
  return stackable
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').schemaComponents
8
+ const { fastifyServer: server, cors, watch } = require('@platformatic/utils').schemaComponents
9
9
 
10
10
  const plugins = {
11
11
  type: 'object',
package/lib/stackable.js CHANGED
@@ -6,6 +6,7 @@ const pino = require('pino')
6
6
  const httpMetrics = require('@platformatic/fastify-http-metrics')
7
7
  const { extractTypeScriptCompileOptionsFromConfig } = require('./compile')
8
8
  const { compile } = require('@platformatic/ts-compiler')
9
+ const { deepmerge } = require('@platformatic/utils')
9
10
 
10
11
  class ServiceStackable {
11
12
  constructor (options) {
@@ -64,9 +65,9 @@ class ServiceStackable {
64
65
  const compileOptions = {
65
66
  ...typeScriptCompileOptions,
66
67
  cwd,
67
- logger: this.configManager.current.server.logger,
68
+ logger: this.logger
68
69
  }
69
- if (!await compile(compileOptions)) {
70
+ if (!(await compile(compileOptions))) {
70
71
  throw new Error(`Failed to compile ${cwd}`)
71
72
  }
72
73
  }
@@ -99,6 +100,10 @@ class ServiceStackable {
99
100
  return config
100
101
  }
101
102
 
103
+ async getEnv () {
104
+ return this.configManager.env
105
+ }
106
+
102
107
  async getWatchConfig () {
103
108
  const config = this.configManager.current
104
109
 
@@ -210,7 +215,7 @@ class ServiceStackable {
210
215
  config.metrics = metricsConfig
211
216
  }
212
217
  if (serverConfig) {
213
- config.server = serverConfig
218
+ config.server = deepmerge(config.server ?? {}, serverConfig ?? {})
214
219
  }
215
220
 
216
221
  if ((hasManagementApi && config.metrics === undefined) || config.metrics) {
@@ -239,20 +244,27 @@ class ServiceStackable {
239
244
  }
240
245
 
241
246
  #initLogger () {
242
- this.configManager.current.server = this.configManager.current.server || {}
243
- const level = this.configManager.current.server.logger?.level
247
+ if (this.configManager.current.server?.loggerInstance) {
248
+ this.logger = this.configManager.current.server?.loggerInstance
249
+ return
250
+ }
251
+
252
+ this.configManager.current.server ??= {}
253
+ this.loggerConfig = deepmerge(this.context.loggerConfig ?? {}, this.configManager.current.server?.logger ?? {})
244
254
 
245
255
  const pinoOptions = {
246
- level: level ?? 'trace'
256
+ level: this.loggerConfig?.level ?? 'trace'
247
257
  }
248
258
 
249
259
  if (this.context?.serviceId) {
250
260
  pinoOptions.name = this.context.serviceId
251
261
  }
252
262
 
263
+ this.logger = pino(pinoOptions)
264
+
253
265
  // Only one of logger and loggerInstance should be set
254
266
  delete this.configManager.current.server.logger
255
- this.configManager.current.server.loggerInstance = pino(pinoOptions)
267
+ this.configManager.current.server.loggerInstance = this.logger
256
268
  }
257
269
  }
258
270
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/service",
3
- "version": "2.0.0-alpha.14",
3
+ "version": "2.0.0-alpha.16",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -75,13 +75,13 @@
75
75
  "rfdc": "^1.3.1",
76
76
  "semgrator": "^0.3.0",
77
77
  "undici": "^6.9.0",
78
- "@platformatic/client": "2.0.0-alpha.14",
79
- "@platformatic/config": "2.0.0-alpha.14",
80
- "@platformatic/generators": "2.0.0-alpha.14",
81
- "@platformatic/scalar-theme": "2.0.0-alpha.14",
82
- "@platformatic/telemetry": "2.0.0-alpha.14",
83
- "@platformatic/utils": "2.0.0-alpha.14",
84
- "@platformatic/ts-compiler": "2.0.0-alpha.14"
78
+ "@platformatic/client": "2.0.0-alpha.16",
79
+ "@platformatic/config": "2.0.0-alpha.16",
80
+ "@platformatic/generators": "2.0.0-alpha.16",
81
+ "@platformatic/scalar-theme": "2.0.0-alpha.16",
82
+ "@platformatic/telemetry": "2.0.0-alpha.16",
83
+ "@platformatic/ts-compiler": "2.0.0-alpha.16",
84
+ "@platformatic/utils": "2.0.0-alpha.16"
85
85
  },
86
86
  "scripts": {
87
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.14.json",
3
- "version": "2.0.0-alpha.14",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/service/2.0.0-alpha.16.json",
3
+ "version": "2.0.0-alpha.16",
4
4
  "title": "Platformatic Service",
5
5
  "type": "object",
6
6
  "properties": {
@@ -93,7 +93,24 @@
93
93
  "type": "object",
94
94
  "properties": {
95
95
  "level": {
96
- "type": "string"
96
+ "type": "string",
97
+ "default": "info",
98
+ "oneOf": [
99
+ {
100
+ "enum": [
101
+ "fatal",
102
+ "error",
103
+ "warn",
104
+ "info",
105
+ "debug",
106
+ "trace",
107
+ "silent"
108
+ ]
109
+ },
110
+ {
111
+ "pattern": "^\\{.+\\}$"
112
+ }
113
+ ]
97
114
  },
98
115
  "transport": {
99
116
  "anyOf": [
@@ -154,6 +171,10 @@
154
171
  "additionalProperties": false
155
172
  }
156
173
  },
174
+ "required": [
175
+ "level"
176
+ ],
177
+ "default": {},
157
178
  "additionalProperties": true
158
179
  }
159
180
  ]