@platformatic/service 1.51.8 → 2.0.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/schema.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
- "$id": "https://platformatic.dev/schemas/v1.51.8/service",
3
- "version": "1.51.8",
2
+ "$id": "https://platformatic.dev/schemas/v2.0.0-alpha.2/service",
3
+ "version": "2.0.0-alpha.2",
4
4
  "title": "Platformatic Service",
5
5
  "type": "object",
6
6
  "properties": {
@@ -953,196 +953,6 @@
953
953
  },
954
954
  "additionalProperties": false
955
955
  }
956
- },
957
- "versions": {
958
- "type": "object",
959
- "properties": {
960
- "dir": {
961
- "type": "string",
962
- "description": "The path to the directory containing the versions mappers",
963
- "resolvePath": true,
964
- "default": "versions"
965
- },
966
- "configs": {
967
- "type": "array",
968
- "items": {
969
- "type": "object",
970
- "properties": {
971
- "version": {
972
- "type": "string"
973
- },
974
- "openapi": {
975
- "type": "object",
976
- "properties": {
977
- "prefix": {
978
- "type": "string"
979
- },
980
- "path": {
981
- "type": "string",
982
- "resolvePath": true
983
- }
984
- },
985
- "additionalProperties": false
986
- },
987
- "plugins": {
988
- "type": "object",
989
- "properties": {
990
- "packages": {
991
- "type": "array",
992
- "items": {
993
- "anyOf": [
994
- {
995
- "type": "string"
996
- },
997
- {
998
- "type": "object",
999
- "properties": {
1000
- "name": {
1001
- "type": "string"
1002
- },
1003
- "options": {
1004
- "type": "object",
1005
- "additionalProperties": true
1006
- }
1007
- },
1008
- "required": [
1009
- "name"
1010
- ]
1011
- }
1012
- ]
1013
- }
1014
- },
1015
- "paths": {
1016
- "type": "array",
1017
- "items": {
1018
- "anyOf": [
1019
- {
1020
- "type": "string",
1021
- "resolvePath": true
1022
- },
1023
- {
1024
- "type": "object",
1025
- "properties": {
1026
- "path": {
1027
- "type": "string",
1028
- "resolvePath": true
1029
- },
1030
- "encapsulate": {
1031
- "type": "boolean",
1032
- "default": true
1033
- },
1034
- "maxDepth": {
1035
- "type": "integer"
1036
- },
1037
- "autoHooks": {
1038
- "type": "boolean"
1039
- },
1040
- "autoHooksPattern": {
1041
- "type": "string"
1042
- },
1043
- "cascadeHooks": {
1044
- "type": "boolean"
1045
- },
1046
- "overwriteHooks": {
1047
- "type": "boolean"
1048
- },
1049
- "routeParams": {
1050
- "type": "boolean"
1051
- },
1052
- "forceESM": {
1053
- "type": "boolean"
1054
- },
1055
- "ignoreFilter": {
1056
- "type": "string"
1057
- },
1058
- "matchFilter": {
1059
- "type": "string"
1060
- },
1061
- "ignorePattern": {
1062
- "type": "string"
1063
- },
1064
- "scriptPattern": {
1065
- "type": "string"
1066
- },
1067
- "indexPattern": {
1068
- "type": "string"
1069
- },
1070
- "options": {
1071
- "type": "object",
1072
- "additionalProperties": true
1073
- }
1074
- }
1075
- }
1076
- ]
1077
- }
1078
- },
1079
- "typescript": {
1080
- "anyOf": [
1081
- {
1082
- "type": "object",
1083
- "properties": {
1084
- "enabled": {
1085
- "anyOf": [
1086
- {
1087
- "type": "boolean"
1088
- },
1089
- {
1090
- "type": "string"
1091
- }
1092
- ]
1093
- },
1094
- "tsConfig": {
1095
- "type": "string",
1096
- "resolvePath": true
1097
- },
1098
- "outDir": {
1099
- "type": "string",
1100
- "resolvePath": true
1101
- },
1102
- "flags": {
1103
- "type": "array",
1104
- "items": {
1105
- "type": "string"
1106
- }
1107
- }
1108
- }
1109
- },
1110
- {
1111
- "type": "boolean"
1112
- },
1113
- {
1114
- "type": "string"
1115
- }
1116
- ]
1117
- }
1118
- },
1119
- "additionalProperties": false,
1120
- "anyOf": [
1121
- {
1122
- "required": [
1123
- "paths"
1124
- ]
1125
- },
1126
- {
1127
- "required": [
1128
- "packages"
1129
- ]
1130
- }
1131
- ]
1132
- }
1133
- },
1134
- "required": [
1135
- "version"
1136
- ],
1137
- "additionalProperties": false
1138
- }
1139
- }
1140
- },
1141
- "required": [
1142
- "dir",
1143
- "configs"
1144
- ],
1145
- "additionalProperties": false
1146
956
  }
1147
957
  },
1148
958
  "additionalProperties": false,
package/service.mjs CHANGED
@@ -7,12 +7,10 @@ import helpMe from 'help-me'
7
7
  import { readFile } from 'fs/promises'
8
8
  import { join } from 'desm'
9
9
  import { printAndExitLoadConfigError } from '@platformatic/config'
10
+ import { buildCompileCmd } from './lib/compile.js'
10
11
  import { generateJsonSchemaConfig } from './lib/gen-schema.js'
11
- import { bumpVersion } from './lib/bump-version.js'
12
- import { updateVersion } from './lib/update-version.js'
13
12
  import { generateTypes } from './lib/gen-types.mjs'
14
13
  import { createService } from './lib/create.mjs'
15
- import { buildCompileCmd } from './lib/compile.js'
16
14
 
17
15
  import { start, platformaticService } from './index.js'
18
16
 
@@ -48,8 +46,6 @@ program.register('compile', buildCompileCmd(platformaticService))
48
46
  program.register('types', wrapCommand(generateTypes))
49
47
  program.register('schema config', wrapCommand(generateJsonSchemaConfig))
50
48
  program.register('schema', help.toStdout.bind(null, ['schema']))
51
- program.register('versions bump', wrapCommand(bumpVersion))
52
- program.register('versions update', wrapCommand(updateVersion))
53
49
 
54
50
  export async function runService (argv) {
55
51
  const args = parseArgs(argv, {
@@ -59,7 +55,7 @@ export async function runService (argv) {
59
55
  })
60
56
 
61
57
  /* c8 ignore next 4 */
62
- if (args.version && !args._.includes('versions')) {
58
+ if (args.version) {
63
59
  console.log('v' + JSON.parse(await readFile(join(import.meta.url, 'package.json'))).version)
64
60
  process.exit(0)
65
61
  }
@@ -1,25 +0,0 @@
1
- Bump a new version of platformatic application API.
2
-
3
- ``` bash
4
- $ platformatic service versions bump
5
- ```
6
-
7
- As a result, a new application API version will be created, and mappers for the previous version will be generated.
8
-
9
- Options:
10
-
11
- * `-c, --config <path>` - Path to the configuration file.
12
- * `-v, --version <string>` - The name of the version to bump. Default: if first version, then `v1`, else `vX`.
13
- * `-p, --prefix <string>` - The prefix to use for the new version. Default: if first version, then `/v1`, else `/vX`.
14
- * `--openai` - Use OpenAI to generate the version mappers plugins. Default: false.
15
- * `--user-api-key <string>` - Platformatic user API key. If not specified, the key will be loaded from the `~/.platformatic/config` file.
16
-
17
- If not specified, the configuration will be loaded from any of the following, in the current directory.
18
-
19
- * `platformatic.json`, or
20
- * `platformatic.yml`, or
21
- * `platformatic.tml`
22
-
23
- You can find more details about the configuration format here:
24
- * [Platformatic DB Configuration](https://docs.platformatic.dev/docs/db/configuration)
25
-
@@ -1,23 +0,0 @@
1
- Update the latest version of platformatic application API.
2
-
3
- ``` bash
4
- $ platformatic service versions update
5
- ```
6
-
7
- As a result, the latest application API version will be updated, and mappers for the previous version will be generated.
8
-
9
- Options:
10
-
11
- * `-c, --config <path>` - Path to the configuration file.
12
- * `--openai <boolean>` - Use OpenAI to generate the version mappers plugins. Default: false.
13
- * `--user-api-key <string>` - Platformatic user API key. If not specified, the key will be loaded from the `~/.platformatic/config` file.
14
-
15
- If not specified, the configuration will be loaded from any of the following, in the current directory.
16
-
17
- * `platformatic.json`, or
18
- * `platformatic.yml`, or
19
- * `platformatic.tml`
20
-
21
- You can find more details about the configuration format here:
22
- * [Platformatic DB Configuration](https://docs.platformatic.dev/docs/db/configuration)
23
-
@@ -1,178 +0,0 @@
1
- 'use strict'
2
-
3
- const { join, relative } = require('node:path')
4
- const { mkdir, readFile, writeFile } = require('node:fs/promises')
5
- const pino = require('pino')
6
- const pretty = require('pino-pretty')
7
- const { loadConfig, getParser, getStringifier } = require('@platformatic/config')
8
- const { platformaticService } = require('../index.js')
9
- const { getOpenapiSchema } = require('./get-openapi-schema.js')
10
- const { createMappersPlugins } = require('./update-version.js')
11
- const { changeOpenapiSchemaPrefix } = require('./utils')
12
- const errors = require('./errors.js')
13
-
14
- async function execute ({
15
- logger,
16
- configManager,
17
- version,
18
- prefix,
19
- userApiKey,
20
- openai,
21
- openaiProxyHost
22
- }) {
23
- const config = configManager.current
24
-
25
- const parse = getParser(configManager.fullPath)
26
- const stringify = getStringifier(configManager.fullPath)
27
- const rawConfig = parse(await readFile(configManager.fullPath, 'utf8'))
28
-
29
- const versionsDirName = 'versions'
30
- const versionsDirPath = config.versions?.dir ??
31
- join(configManager.dirname, versionsDirName)
32
-
33
- let versionsConfigs = config.versions
34
- let rawVersionsConfigs = rawConfig.versions
35
-
36
- if (!config.versions) {
37
- versionsConfigs = { dir: versionsDirName, configs: [] }
38
- rawVersionsConfigs = { dir: versionsDirName, configs: [] }
39
- }
40
-
41
- let biggestVersion = 0
42
- for (const versionConfig of versionsConfigs.configs) {
43
- if (versionConfig.version === version) {
44
- throw new errors.VersionAlreadyExists(version)
45
- }
46
- const versionNumber = parseInt(versionConfig.version.slice(1))
47
- if (!isNaN(versionNumber)) {
48
- biggestVersion = Math.max(biggestVersion, versionNumber)
49
- }
50
- }
51
- version = version ?? `v${biggestVersion + 1}`
52
- prefix = prefix ?? `/${version}`
53
- prefix = prefix.charAt(0) === '/' ? prefix : `/${prefix}`
54
-
55
- const versionDir = join(versionsDirPath, version)
56
- await mkdir(versionDir, { recursive: true })
57
-
58
- const latestVersionConfig = versionsConfigs.configs.at(-1)
59
- const rawLatestVersionConfig = rawVersionsConfigs.configs.at(-1)
60
-
61
- const latestVersion = latestVersionConfig?.version ?? null
62
- const latestVersionPrefix = latestVersionConfig?.openapi?.prefix ?? ''
63
-
64
- logger.info('Loading the latest openapi schema.')
65
- const latestOpenapiSchema = await getOpenapiSchema({
66
- logger,
67
- configManager,
68
- version: latestVersion
69
- })
70
-
71
- const newOpenapiSchema = changeOpenapiSchemaPrefix(
72
- latestOpenapiSchema,
73
- latestVersionPrefix,
74
- prefix
75
- )
76
- const newOpenapiSchemaPath = join(versionDir, 'openapi.json')
77
-
78
- logger.info(`Writing "${version}" openapi schema file.`)
79
- await writeFile(newOpenapiSchemaPath, JSON.stringify(newOpenapiSchema, null, 2))
80
-
81
- const newVersionConfig = {
82
- version,
83
- openapi: {
84
- path: relative(configManager.dirname, newOpenapiSchemaPath),
85
- prefix
86
- }
87
- }
88
-
89
- if (latestVersionConfig) {
90
- newVersionConfig.plugins = rawLatestVersionConfig.plugins
91
- delete latestVersionConfig.plugins
92
- delete rawLatestVersionConfig.plugins
93
- } else if (config.plugins) {
94
- newVersionConfig.plugins = rawConfig.plugins
95
- delete config.plugins
96
- delete rawConfig.plugins
97
- }
98
-
99
- versionsConfigs.configs.push(newVersionConfig)
100
- rawVersionsConfigs.configs.push(newVersionConfig)
101
-
102
- config.versions = versionsConfigs
103
- rawConfig.versions = rawVersionsConfigs
104
-
105
- await Promise.all([configManager.update(), writeFile(configManager.fullPath, stringify(rawConfig))])
106
-
107
- if (latestVersionConfig) {
108
- logger.info(`Reading openapi schema for "${latestVersion}"`)
109
- const prevOpenapiSchemaPath = latestVersionConfig.openapi.path
110
- const prevOpenapiSchemaFile = await readFile(prevOpenapiSchemaPath, 'utf8')
111
- const prevOpenapiSchema = JSON.parse(prevOpenapiSchemaFile)
112
-
113
- await createMappersPlugins({
114
- logger,
115
- configManager,
116
- prevVersion: latestVersion,
117
- nextVersion: version,
118
- prevOpenapiSchema,
119
- nextOpenapiSchema: newOpenapiSchema,
120
- userApiKey,
121
- openai,
122
- openaiProxyHost
123
- })
124
- }
125
- }
126
-
127
- async function bumpVersion (_args) {
128
- const logger = pino(pretty({
129
- translateTime: 'SYS:HH:MM:ss',
130
- ignore: 'hostname,pid'
131
- }))
132
-
133
- try {
134
- const { configManager, args } = await loadConfig({
135
- string: ['version', 'prefix', 'openai-proxy-host', 'user-api-key'],
136
- boolean: ['openai'],
137
- alias: {
138
- v: 'version',
139
- p: 'prefix'
140
- }
141
- }, _args, platformaticService)
142
- await configManager.parseAndValidate()
143
-
144
- const version = args.version
145
- const prefix = args.prefix
146
-
147
- const openai = args.openai ?? false
148
- const openaiProxyHost = args['openai-proxy-host'] ?? null
149
-
150
- let userApiKey = args['user-api-key'] ?? null
151
- /* c8 ignore next 10 */
152
- if (!userApiKey && openai) {
153
- logger.info('Reading platformatic user api key')
154
- const { getUserApiKey } = await import('@platformatic/authenticate')
155
- try {
156
- userApiKey = await getUserApiKey()
157
- } catch (err) {
158
- logger.error('Failed to read user api key. Please run "plt login" command.')
159
- return
160
- }
161
- }
162
-
163
- await execute({
164
- logger,
165
- configManager,
166
- version,
167
- prefix,
168
- userApiKey,
169
- openai,
170
- openaiProxyHost
171
- })
172
- } catch (err) {
173
- logger.error(err.message)
174
- process.exit(1)
175
- }
176
- }
177
-
178
- module.exports = { bumpVersion, execute }
package/lib/errors.js DELETED
@@ -1,16 +0,0 @@
1
- 'use strict'
2
-
3
- const createError = require('@fastify/error')
4
-
5
- const ERROR_PREFIX = 'PLT_SERVICE'
6
-
7
- module.exports = {
8
- VersionNotSpecified: createError(
9
- `${ERROR_PREFIX}_VERSION_NOT_SPECIFIED_ERROR`,
10
- 'Version not specified. Use --version option to specify a version.'
11
- ),
12
- VersionAlreadyExists: createError(
13
- `${ERROR_PREFIX}_VERSION_EXISTS_ERROR`,
14
- 'Version %s already exists.'
15
- )
16
- }
@@ -1,47 +0,0 @@
1
- 'use strict'
2
-
3
- const { printAndExitLoadConfigError } = require('@platformatic/config')
4
- const { buildServer } = require('./start')
5
- const { platformaticService } = require('../index.js')
6
-
7
- async function getOpenapiSchema ({ logger, configManager, version }) {
8
- const config = configManager.current
9
-
10
- let app = null
11
- try {
12
- app = await buildServer({ ...config, configManager }, platformaticService)
13
- await app.ready()
14
- /* c8 ignore next 4 */
15
- } catch (err) {
16
- printAndExitLoadConfigError(err)
17
- process.exit(1)
18
- }
19
-
20
- if (!version) {
21
- return app.swagger()
22
- }
23
-
24
- if (!config.versions) {
25
- throw new Error('No versions configured')
26
- }
27
-
28
- const versionsConfigs = config.versions.configs ?? []
29
- const versionConfig = versionsConfigs.find(v => v.version === version)
30
- const versionPrefix = versionConfig.openapi.prefix ?? ''
31
-
32
- const openapiUrl = versionPrefix
33
- ? versionPrefix + '/documentation/json'
34
- : '/documentation/json'
35
-
36
- const { statusCode, body } = await app.inject({ method: 'GET', url: openapiUrl })
37
-
38
- /* c8 ignore next 3 */
39
- if (statusCode !== 200) {
40
- throw new Error(`Failed to get openapi schema for version ${version}`)
41
- }
42
-
43
- const openapiSchema = JSON.parse(body)
44
- return openapiSchema
45
- }
46
-
47
- module.exports = { getOpenapiSchema }