@platformatic/service 2.0.0-alpha.9 → 2.0.1

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,33 +145,39 @@ 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
  }
168
171
  }
169
172
 
170
173
  const stackable = new Stackable({
171
- init: () => buildServer(configManager.current, app, options.context),
174
+ init: () => buildServer({
175
+ configManager,
176
+ ...configManager.current,
177
+ }, app, options.context),
172
178
  stackable: app,
173
179
  configManager,
174
- context: options.context,
180
+ context: options.context
175
181
  })
176
182
 
177
183
  return stackable
@@ -60,6 +60,7 @@ async function setupOpenAPI (app, opts) {
60
60
  ...opts,
61
61
  ...openapi,
62
62
  routePrefix,
63
+ publicPath: './',
63
64
  configuration: {
64
65
  customCss: scalarTheme.theme,
65
66
  },
@@ -32,12 +32,12 @@ async function loadPlugins (app, opts) {
32
32
 
33
33
  if (outDir) {
34
34
  isOutDirAccessible = await isFileAccessible(outDir)
35
- }
36
35
 
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
- )
36
+ if (opts.context?.isProduction && !isOutDirAccessible) {
37
+ throw new Error(
38
+ `Cannot access directory '${outDir}'. Please run the 'build' command before running in production mode.`
39
+ )
40
+ }
41
41
  }
42
42
 
43
43
  if (config.plugins.paths && isOutDirAccessible) {
@@ -1,8 +1,30 @@
1
- <svg width="383" height="306" viewBox="0 0 383 306" fill="none" xmlns="http://www.w3.org/2000/svg">
2
- <path d="M108.854 224.267H323.497V224.199C331.631 223.82 339.576 221.624 346.748 217.771C353.919 213.918 360.134 208.508 364.935 201.938C369.735 195.367 372.999 187.805 374.487 179.808C375.974 171.811 375.646 163.582 373.528 155.728C371.41 147.874 367.555 140.594 362.247 134.426C356.939 128.257 350.314 123.357 342.859 120.085C335.404 116.814 327.309 115.254 319.171 115.522C311.032 115.79 303.058 117.878 295.834 121.632C291.376 111.352 284.629 102.223 276.107 94.94C267.584 87.6573 257.51 82.4129 246.653 79.606M62.8089 79.606C47.0036 83.6771 33.0019 92.8821 23.007 105.773C13.0121 118.663 7.59128 134.508 7.59757 150.813C7.60386 167.118 13.0369 182.958 23.0417 195.841C33.0466 208.724 47.0554 217.918 62.8638 221.977" stroke="white" stroke-width="14.1463" stroke-linecap="round" stroke-linejoin="round"/>
3
- <path d="M147.719 124.69L119.082 134.743L131.684 161.444" stroke="#21FA90" stroke-width="14.1463" stroke-linecap="round" stroke-linejoin="round"/>
4
- <path d="M119.727 135.216C132.785 142.886 148.015 146.031 163.047 144.161C178.08 142.291 192.072 135.51 202.848 124.875C213.624 114.239 220.58 100.344 222.632 85.3505C224.685 70.3574 221.721 55.1069 214.2 41.971C206.678 28.8352 195.023 18.5504 181.045 12.7164C167.067 6.88249 151.552 5.82641 136.911 9.71246C122.27 13.5985 109.326 22.2088 100.09 34.2042C90.8552 46.1995 85.8471 60.9074 85.8452 76.0401V178.408" stroke="#21FA90" stroke-width="14.1463" stroke-linecap="round" stroke-linejoin="round"/>
5
- <path opacity="0.2" d="M85.8452 286.631V298.589" stroke="#21FA90" stroke-width="14.1463" stroke-linecap="round" stroke-linejoin="round"/>
6
- <path opacity="0.4" d="M85.955 249V267.891" stroke="#21FA90" stroke-width="14.1463" stroke-linecap="round" stroke-linejoin="round"/>
7
- <path opacity="0.7" d="M85.8452 197.861V229.444" stroke="#21FA90" stroke-width="14.1463" stroke-linecap="round" stroke-linejoin="round"/>
8
- </svg>
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg id="Logo" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 568.18 568.18">
3
+ <defs>
4
+ <style>
5
+ .cls-1 {
6
+ stroke: #00fe84;
7
+ }
8
+
9
+ .cls-1, .cls-2 {
10
+ fill: none;
11
+ stroke-linecap: round;
12
+ stroke-linejoin: round;
13
+ stroke-width: 16.34px;
14
+ }
15
+
16
+ .cls-2 {
17
+ stroke: #fff;
18
+ }
19
+ </style>
20
+ </defs>
21
+ <g>
22
+ <line class="cls-1" x1="148.26" y1="317.46" x2="148.26" y2="389.92"/>
23
+ <polyline class="cls-1" points="176.75 303.19 234.68 336.63 321.11 286.74 321.11 186.94 234.68 137.04 148.26 186.94 148.26 273.55"/>
24
+ <polyline class="cls-1" points="176.75 334.87 176.75 303.19 205.15 285.91"/>
25
+ </g>
26
+ <polyline class="cls-2" points="466.14 259.75 501.19 280.47 501.19 301.18 466.14 321.89"/>
27
+ <polyline class="cls-2" points="106.23 210.58 66.98 233.24 66.98 334.38 105.4 356.56"/>
28
+ <polyline class="cls-2" points="176.75 376.88 176.75 399.34 234.33 431.14 278.53 405.35 278.17 358.41"/>
29
+ <polyline class="cls-2" points="321.66 332.06 321.66 356.76 363.05 380.98 423.55 344.88 423.55 246.39 364.01 212.25"/>
30
+ </svg>
@@ -1,8 +1,30 @@
1
- <svg width="383" height="306" viewBox="0 0 383 306" fill="none" xmlns="http://www.w3.org/2000/svg">
2
- <path d="M108.854 224.267H323.497V224.199C331.631 223.82 339.576 221.623 346.748 217.771C353.919 213.918 360.134 208.507 364.935 201.937C369.735 195.367 372.999 187.805 374.487 179.808C375.974 171.81 375.646 163.582 373.528 155.728C371.41 147.874 367.555 140.594 362.247 134.426C356.939 128.257 350.314 123.357 342.859 120.085C335.404 116.813 327.309 115.254 319.171 115.522C311.032 115.79 303.058 117.878 295.834 121.632C291.376 111.352 284.629 102.222 276.107 94.9397C267.584 87.657 257.51 82.4126 246.653 79.6057M62.8089 79.6057C47.0036 83.6768 33.0019 92.8819 23.007 105.772C13.0121 118.663 7.59128 134.507 7.59757 150.813C7.60386 167.118 13.0369 182.958 23.0417 195.841C33.0466 208.724 47.0554 217.918 62.8638 221.977" stroke="#00283D" stroke-width="14.1463" stroke-linecap="round" stroke-linejoin="round"/>
3
- <path d="M147.719 124.69L119.082 134.743L131.684 161.444" stroke="#21FA90" stroke-width="14.1463" stroke-linecap="round" stroke-linejoin="round"/>
4
- <path d="M119.727 135.216C132.785 142.886 148.015 146.031 163.047 144.161C178.08 142.291 192.072 135.51 202.848 124.875C213.624 114.239 220.58 100.344 222.632 85.3505C224.685 70.3574 221.721 55.1068 214.2 41.971C206.678 28.8351 195.023 18.5503 181.045 12.7164C167.067 6.88243 151.552 5.82634 136.911 9.7124C122.27 13.5985 109.326 22.2088 100.09 34.2041C90.8552 46.1995 85.8471 60.9073 85.8452 76.04V178.408" stroke="#21FA90" stroke-width="14.1463" stroke-linecap="round" stroke-linejoin="round"/>
5
- <path opacity="0.2" d="M85.8452 286.631V298.589" stroke="#21FA90" stroke-width="14.1463" stroke-linecap="round" stroke-linejoin="round"/>
6
- <path opacity="0.4" d="M85.955 249V267.891" stroke="#21FA90" stroke-width="14.1463" stroke-linecap="round" stroke-linejoin="round"/>
7
- <path opacity="0.7" d="M85.8452 197.861V229.444" stroke="#21FA90" stroke-width="14.1463" stroke-linecap="round" stroke-linejoin="round"/>
8
- </svg>
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg id="Logo" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 568.18 568.18">
3
+ <defs>
4
+ <style>
5
+ .cls-1 {
6
+ stroke: #00050b;
7
+ }
8
+
9
+ .cls-1, .cls-2 {
10
+ fill: none;
11
+ stroke-linecap: round;
12
+ stroke-linejoin: round;
13
+ stroke-width: 16.73px;
14
+ }
15
+
16
+ .cls-2 {
17
+ stroke: #00fe84;
18
+ }
19
+ </style>
20
+ </defs>
21
+ <g>
22
+ <line class="cls-2" x1="144.97" y1="318.27" x2="144.97" y2="392.48"/>
23
+ <polyline class="cls-2" points="174.15 303.65 233.49 337.91 322.01 286.8 322.01 184.58 233.49 133.48 144.97 184.58 144.97 273.29"/>
24
+ <polyline class="cls-2" points="174.15 336.1 174.15 303.66 203.24 285.96"/>
25
+ </g>
26
+ <polyline class="cls-1" points="470.56 259.16 506.46 280.38 506.46 301.59 470.56 322.81"/>
27
+ <polyline class="cls-1" points="101.92 208.8 61.72 232.01 61.72 335.6 101.07 358.32"/>
28
+ <polyline class="cls-1" points="174.15 379.13 174.15 402.14 233.12 434.7 278.4 408.29 278.03 360.22"/>
29
+ <polyline class="cls-1" points="322.57 333.23 322.57 358.53 364.96 383.33 426.93 346.35 426.93 245.48 365.94 210.51"/>
30
+ </svg>
@@ -2,7 +2,7 @@
2
2
  <html lang="en">
3
3
  <head>
4
4
  <meta charset="UTF-8" />
5
- <link rel="icon" type="image/svg+xml" href="/images/favicon.ico" />
5
+ <link rel="icon" type="image/svg+xml" href="./images/favicon.ico" />
6
6
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800&display=swap" rel="stylesheet">
7
7
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
8
8
  <title>Platformatic Service</title>
@@ -204,7 +204,11 @@
204
204
  </div>
205
205
 
206
206
  <script>
207
- const currentPath = window.location.pathname
207
+ let currentPath = window.location.pathname
208
+
209
+ if (!currentPath.endsWith('/')) {
210
+ currentPath += '/'
211
+ }
208
212
 
209
213
  const openApiLink = document.getElementById('openapi-link')
210
214
  openApiLink.href = currentPath + 'documentation'
@@ -215,18 +219,18 @@
215
219
  const prefersLightScheme = window.matchMedia('(prefers-color-scheme: light)');
216
220
  if (prefersLightScheme.matches) {
217
221
  document.body.classList.add('light-theme');
218
- document.getElementById('logo').src = 'images/platformatic-logo-light.svg'
222
+ document.getElementById('logo').src = currentPath + 'images/platformatic-logo-light.svg'
219
223
  } else {
220
224
  document.body.classList.remove('light-theme');
221
- document.getElementById('logo').src = 'images/platformatic-logo-dark.svg'
225
+ document.getElementById('logo').src = currentPath + 'images/platformatic-logo-dark.svg'
222
226
  }
223
227
 
224
228
  const toggleLightMode = function() {
225
229
  document.body.classList.toggle('light-theme');
226
230
  if (document.body.classList.contains('light-theme')) {
227
- document.getElementById('logo').src = 'images/platformatic-logo-light.svg'
231
+ document.getElementById('logo').src = currentPath + 'images/platformatic-logo-light.svg'
228
232
  } else {
229
- document.getElementById('logo').src = 'images/platformatic-logo-dark.svg'
233
+ document.getElementById('logo').src = currentPath + 'images/platformatic-logo-dark.svg'
230
234
  }
231
235
  }
232
236
  </script>
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/lib/start.js CHANGED
@@ -56,12 +56,25 @@ async function createServer (serverContext) {
56
56
  return root
57
57
  }
58
58
  async function buildConfigManager (options, app) {
59
+ const loggerInstance = options.server?.loggerInstance
60
+ if (loggerInstance) {
61
+ delete options.server.loggerInstance
62
+ options.server ||= {}
63
+ options.server.logger = { level: loggerInstance.level }
64
+ }
65
+
59
66
  let configManager = options.configManager
60
67
  if (!configManager) {
61
68
  // instantiate a new config manager from current options
62
69
  configManager = new ConfigManager({ ...app.configManagerConfig, source: options })
63
70
  await configManager.parseAndValidate()
64
71
  }
72
+
73
+ if (loggerInstance) {
74
+ configManager.current.server ||= {}
75
+ delete configManager.current.server.logger
76
+ configManager.current.server.loggerInstance = loggerInstance
77
+ }
65
78
  return configManager
66
79
  }
67
80
 
package/lib/upgrade.js CHANGED
@@ -1,7 +1,6 @@
1
1
  'use strict'
2
2
 
3
3
  const { join } = require('path')
4
- const pkg = require('../package.json')
5
4
 
6
5
  module.exports = async function upgrade (config, version) {
7
6
  const { semgrator } = await import('semgrator')
@@ -19,7 +18,5 @@ module.exports = async function upgrade (config, version) {
19
18
  result = updated.result
20
19
  }
21
20
 
22
- result.$schema = `https://schemas.platformatic.dev/@platformatic/service/${pkg.version}.json`
23
-
24
21
  return result
25
22
  }
@@ -0,0 +1,11 @@
1
+ 'use strict'
2
+
3
+ const pkg = require('../../package.json')
4
+
5
+ module.exports = {
6
+ version: '2.0.0',
7
+ up: function (config) {
8
+ config.$schema = `https://schemas.platformatic.dev/@platformatic/service/${pkg.version}.json`
9
+ return config
10
+ }
11
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/service",
3
- "version": "2.0.0-alpha.9",
3
+ "version": "2.0.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -17,7 +17,7 @@
17
17
  },
18
18
  "homepage": "https://github.com/platformatic/platformatic#readme",
19
19
  "devDependencies": {
20
- "@fastify/aws-lambda": "^4.0.0",
20
+ "@fastify/aws-lambda": "^5.0.0",
21
21
  "@fastify/compress": "^8.0.0",
22
22
  "bindings": "^1.5.0",
23
23
  "borp": "^0.17.0",
@@ -61,7 +61,8 @@
61
61
  "env-schema": "^5.2.1",
62
62
  "es-main": "^1.3.0",
63
63
  "execa": "^8.0.1",
64
- "fastify": "5.0.0-alpha.4",
64
+ "fastify": "^5.0.0",
65
+ "fastify-metrics": "^12.0.0",
65
66
  "fastify-plugin": "^5.0.0",
66
67
  "graphql": "^16.9.0",
67
68
  "help-me": "^5.0.0",
@@ -75,13 +76,13 @@
75
76
  "rfdc": "^1.3.1",
76
77
  "semgrator": "^0.3.0",
77
78
  "undici": "^6.9.0",
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"
79
+ "@platformatic/config": "2.0.1",
80
+ "@platformatic/client": "2.0.1",
81
+ "@platformatic/generators": "2.0.1",
82
+ "@platformatic/scalar-theme": "2.0.1",
83
+ "@platformatic/telemetry": "2.0.1",
84
+ "@platformatic/ts-compiler": "2.0.1",
85
+ "@platformatic/utils": "2.0.1"
85
86
  },
86
87
  "scripts": {
87
88
  "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.9.json",
3
- "version": "2.0.0-alpha.9",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/service/2.0.1.json",
3
+ "version": "2.0.1",
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
  ]