@platformatic/service 1.13.7 → 1.14.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/lib/utils.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
- const { access } = require('fs/promises')
4
- const { resolve, join, relative, dirname, basename } = require('path')
3
+ const { access } = require('node:fs/promises')
4
+ const { resolve, join, relative, dirname, basename } = require('node:path')
5
5
  const { isatty } = require('tty')
6
6
 
7
7
  async function isFileAccessible (filename, directory) {
@@ -70,8 +70,131 @@ function getJSPluginPath (workingDir, tsPluginPath, compileDir) {
70
70
  return join(compileDir, jsPluginRelativePath)
71
71
  }
72
72
 
73
+ function convertOpenApiToFastifyPath (openApiPath) {
74
+ return openApiPath
75
+ .replace(/{wildcard}/g, '*')
76
+ .replace(/{(\w+)}/g, ':$1')
77
+ }
78
+
79
+ function updateOpenApiSchemaRefs (openapiSchema) {
80
+ const componentsPrefix = '#/components/schemas/'
81
+
82
+ for (const key of Object.keys(openapiSchema)) {
83
+ const value = openapiSchema[key]
84
+
85
+ if (key === '$ref' && value.startsWith(componentsPrefix)) {
86
+ openapiSchema.$ref = value
87
+ .replace(componentsPrefix, '')
88
+ .split('/', 1)
89
+ .join('#/')
90
+
91
+ continue
92
+ }
93
+
94
+ if (typeof value === 'object') {
95
+ updateOpenApiSchemaRefs(value)
96
+ }
97
+ }
98
+ }
99
+
100
+ function convertOpenApiToFastifyRouteSchema (openapiSchema) {
101
+ const routeSchema = {}
102
+
103
+ for (const openApiParam of openapiSchema.parameters ?? []) {
104
+ const name = openApiParam.name
105
+ const schema = openApiParam.schema
106
+
107
+ if (openApiParam.in === 'path') {
108
+ if (routeSchema.params === undefined) {
109
+ routeSchema.params = {
110
+ type: 'object',
111
+ properties: {},
112
+ required: []
113
+ }
114
+ }
115
+
116
+ routeSchema.params.properties[name] = schema
117
+ if (openApiParam.required) {
118
+ routeSchema.params.required.push(name)
119
+ }
120
+ }
121
+
122
+ if (openApiParam.in === 'header') {
123
+ if (routeSchema.headers === undefined) {
124
+ routeSchema.headers = {
125
+ type: 'object',
126
+ properties: {},
127
+ required: []
128
+ }
129
+ }
130
+
131
+ routeSchema.headers.properties[name] = schema
132
+ if (openApiParam.required) {
133
+ routeSchema.headers.required.push(name)
134
+ }
135
+ }
136
+
137
+ if (openApiParam.in === 'query') {
138
+ if (routeSchema.querystring === undefined) {
139
+ routeSchema.querystring = {
140
+ type: 'object',
141
+ properties: {},
142
+ required: []
143
+ }
144
+ }
145
+
146
+ routeSchema.querystring.properties[name] = schema
147
+ if (openApiParam.required) {
148
+ routeSchema.querystring.required.push(name)
149
+ }
150
+ }
151
+ }
152
+
153
+ if (openapiSchema.requestBody) {
154
+ const content = openapiSchema.requestBody.content
155
+ const contentType = Object.keys(content)[0]
156
+ routeSchema.body = content[contentType].schema
157
+ }
158
+
159
+ for (const statusCode of Object.keys(openapiSchema.responses ?? {})) {
160
+ const response = openapiSchema.responses[statusCode]
161
+ const responseSchema = response.content?.['application/json']?.schema
162
+ if (responseSchema) {
163
+ if (!routeSchema.response) {
164
+ routeSchema.response = {}
165
+ }
166
+ routeSchema.response[statusCode] = responseSchema
167
+ }
168
+ }
169
+
170
+ updateOpenApiSchemaRefs(routeSchema)
171
+
172
+ return routeSchema
173
+ }
174
+
175
+ function changeOpenapiSchemaPrefix (openapiSchema, oldVersionPrefix, newVersionPrefix) {
176
+ if (!oldVersionPrefix && !newVersionPrefix) return openapiSchema
177
+
178
+ const normalizedPaths = {}
179
+ for (const oldPath of Object.keys(openapiSchema.paths ?? {})) {
180
+ const newPath = oldVersionPrefix
181
+ ? oldPath.replace(oldVersionPrefix, newVersionPrefix)
182
+ : newVersionPrefix + oldPath
183
+
184
+ normalizedPaths[newPath] = openapiSchema.paths[oldPath]
185
+ }
186
+
187
+ return {
188
+ ...openapiSchema,
189
+ paths: normalizedPaths
190
+ }
191
+ }
192
+
73
193
  module.exports = {
74
194
  isFileAccessible,
75
195
  getJSPluginPath,
76
- addLoggerToTheConfig
196
+ addLoggerToTheConfig,
197
+ changeOpenapiSchemaPrefix,
198
+ convertOpenApiToFastifyPath,
199
+ convertOpenApiToFastifyRouteSchema
77
200
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/service",
3
- "version": "1.13.7",
3
+ "version": "1.14.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -33,7 +33,7 @@
33
33
  "ts-standard": "^12.0.2",
34
34
  "tsd": "^0.29.0",
35
35
  "typescript": "^5.2.2",
36
- "undici": "^5.25.4",
36
+ "undici": "^6.0.0",
37
37
  "vscode-json-languageservice": "^5.3.6",
38
38
  "why-is-node-running": "^2.2.2",
39
39
  "yaml": "^2.3.2"
@@ -44,6 +44,7 @@
44
44
  "@fastify/basic-auth": "^5.0.0",
45
45
  "@fastify/cors": "^8.4.0",
46
46
  "@fastify/deepmerge": "^1.3.0",
47
+ "@fastify/error": "^3.4.0",
47
48
  "@fastify/restartable": "^2.1.1",
48
49
  "@fastify/static": "^6.11.2",
49
50
  "@fastify/swagger": "^8.10.1",
@@ -53,28 +54,36 @@
53
54
  "@types/ws": "^8.5.6",
54
55
  "ajv": "^8.12.0",
55
56
  "close-with-grace": "^1.2.0",
57
+ "code-block-writer": "^12.0.0",
56
58
  "commist": "^3.2.0",
59
+ "colorette": "^2.0.20",
60
+ "cli-progress": "^3.12.0",
57
61
  "desm": "^1.3.0",
58
62
  "env-schema": "^5.2.0",
59
63
  "es-main": "^1.3.0",
60
64
  "execa": "^8.0.1",
61
65
  "fastify": "^4.23.2",
66
+ "fastify-openapi-glue": "^4.3.3",
62
67
  "fastify-metrics": "^10.3.2",
63
68
  "fastify-plugin": "^4.5.1",
64
69
  "graphql": "^16.8.1",
65
70
  "help-me": "^4.2.0",
66
71
  "mercurius": "^13.1.0",
67
72
  "minimist": "^1.2.8",
73
+ "openapi-schema-diff": "^0.0.1",
68
74
  "pino": "^8.15.3",
69
75
  "pino-pretty": "^10.2.0",
70
76
  "rfdc": "^1.3.0",
77
+ "undici": "^6.0.0",
71
78
  "ua-parser-js": "^1.0.36",
72
- "@platformatic/config": "1.13.7",
73
- "@platformatic/client": "1.13.7",
74
- "@platformatic/telemetry": "1.13.7",
75
- "@platformatic/utils": "1.13.7",
76
- "@platformatic/generators": "1.13.7",
77
- "@platformatic/swagger-ui-theme": "1.13.7"
79
+ "@platformatic/authenticate": "1.14.1",
80
+ "@platformatic/client": "1.14.1",
81
+ "@platformatic/generators": "1.14.1",
82
+ "@platformatic/swagger-ui-theme": "1.14.1",
83
+ "@platformatic/config": "1.14.1",
84
+ "@platformatic/telemetry": "1.14.1",
85
+ "@platformatic/metaconfig": "1.14.1",
86
+ "@platformatic/utils": "1.14.1"
78
87
  },
79
88
  "standard": {
80
89
  "ignore": [
package/service.mjs CHANGED
@@ -8,6 +8,8 @@ import { readFile } from 'fs/promises'
8
8
  import { join } from 'desm'
9
9
  import { printAndExitLoadConfigError } from '@platformatic/config'
10
10
  import { generateJsonSchemaConfig } from './lib/gen-schema.js'
11
+ import { bumpVersion } from './lib/bump-version.js'
12
+ import { updateVersion } from './lib/update-version.js'
11
13
  import { generateTypes } from './lib/gen-types.mjs'
12
14
 
13
15
  import { buildCompileCmd } from './lib/compile.js'
@@ -45,6 +47,8 @@ program.register('compile', buildCompileCmd(platformaticService))
45
47
  program.register('types', wrapCommand(generateTypes))
46
48
  program.register('schema config', wrapCommand(generateJsonSchemaConfig))
47
49
  program.register('schema', help.toStdout.bind(null, ['schema']))
50
+ program.register('versions bump', wrapCommand(bumpVersion))
51
+ program.register('versions update', wrapCommand(updateVersion))
48
52
 
49
53
  export async function runService (argv) {
50
54
  const args = parseArgs(argv, {
@@ -54,7 +58,7 @@ export async function runService (argv) {
54
58
  })
55
59
 
56
60
  /* c8 ignore next 4 */
57
- if (args.version) {
61
+ if (args.version && !args._.includes('versions')) {
58
62
  console.log('v' + JSON.parse(await readFile(join(import.meta.url, 'package.json'))).version)
59
63
  process.exit(0)
60
64
  }