@platformatic/service 3.4.1 → 3.5.0
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/LICENSE +1 -1
- package/config.d.ts +450 -94
- package/eslint.config.js +4 -6
- package/index.d.ts +55 -48
- package/index.js +44 -179
- package/lib/application.js +35 -0
- package/lib/capability.js +281 -0
- package/lib/compile.js +2 -52
- package/lib/generator.js +426 -0
- package/lib/plugins/cors.js +5 -8
- package/lib/plugins/graphql.js +16 -14
- package/lib/plugins/health-check.js +6 -8
- package/lib/plugins/openapi.js +43 -32
- package/lib/plugins/plugins.js +6 -53
- package/lib/{root-endpoint/index.js → plugins/root.js} +9 -8
- package/lib/plugins/sandbox-wrapper.js +65 -63
- package/lib/schema.js +1075 -203
- package/lib/upgrade.js +6 -8
- package/lib/utils.js +30 -83
- package/lib/versions/0.16.0.js +14 -15
- package/lib/versions/{from-zero-twenty-eight-to-will-see.js → 0.28.0.js} +3 -6
- package/lib/versions/2.0.0.js +4 -7
- package/lib/versions/3.0.0.js +14 -0
- package/package.json +28 -36
- package/schema.json +1452 -165
- package/tsconfig.json +16 -6
- package/.c8rc +0 -6
- package/help/compile.txt +0 -19
- package/help/create.txt +0 -11
- package/help/help.txt +0 -8
- package/help/schema.txt +0 -9
- package/help/start.txt +0 -23
- package/index.test-d.ts +0 -107
- package/lib/create.mjs +0 -85
- package/lib/gen-schema.js +0 -15
- package/lib/gen-types.mjs +0 -38
- package/lib/generator/README.md +0 -31
- package/lib/generator/service-generator.d.ts +0 -11
- package/lib/generator/service-generator.js +0 -126
- package/lib/openapi-schema-defs.js +0 -1108
- package/lib/plugins/clients.js +0 -16
- package/lib/plugins/metrics.js +0 -244
- package/lib/plugins/typescript.js +0 -20
- package/lib/stackable.js +0 -306
- package/lib/start.js +0 -175
- package/service.mjs +0 -71
- /package/{lib/root-endpoint/public → public}/images/dark_mode.svg +0 -0
- /package/{lib/root-endpoint/public → public}/images/favicon.ico +0 -0
- /package/{lib/root-endpoint/public → public}/images/light_mode.svg +0 -0
- /package/{lib/root-endpoint/public → public}/images/platformatic-logo-dark.svg +0 -0
- /package/{lib/root-endpoint/public → public}/images/platformatic-logo-light.svg +0 -0
- /package/{lib/root-endpoint/public → public}/images/triangle_dark.svg +0 -0
- /package/{lib/root-endpoint/public → public}/images/triangle_light.svg +0 -0
- /package/{lib/root-endpoint/public → public}/index.html +0 -0
package/lib/start.js
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { readFile } = require('fs/promises')
|
|
4
|
-
const close = require('close-with-grace')
|
|
5
|
-
const { loadConfig, ConfigManager, printConfigValidationErrors, printAndExitLoadConfigError } = require('@platformatic/config')
|
|
6
|
-
const { addLoggerToTheConfig, isDocker } = require('./utils.js')
|
|
7
|
-
const { randomUUID } = require('crypto')
|
|
8
|
-
const { fastify } = require('fastify')
|
|
9
|
-
|
|
10
|
-
async function adjustHttpsKeyAndCert (arg) {
|
|
11
|
-
if (typeof arg === 'string') {
|
|
12
|
-
return arg
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (!Array.isArray(arg)) {
|
|
16
|
-
// { path: pathToKeyOrCert }
|
|
17
|
-
return readFile(arg.path)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Array of strings or objects.
|
|
21
|
-
for (let i = 0; i < arg.length; ++i) {
|
|
22
|
-
arg[i] = await adjustHttpsKeyAndCert(arg[i])
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return arg
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async function createServer (serverContext) {
|
|
29
|
-
const { app, configManager, context } = serverContext
|
|
30
|
-
const config = configManager.current
|
|
31
|
-
let fastifyOptions = {}
|
|
32
|
-
|
|
33
|
-
if (config.server) {
|
|
34
|
-
// override hostname if it's docker
|
|
35
|
-
if (await isDocker()) {
|
|
36
|
-
config.server.hostname = '0.0.0.0'
|
|
37
|
-
}
|
|
38
|
-
fastifyOptions = {
|
|
39
|
-
...config.server,
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
fastifyOptions.genReqId = function (req) { return randomUUID() }
|
|
43
|
-
const root = fastify(fastifyOptions)
|
|
44
|
-
root.decorate('platformatic', { configManager, config })
|
|
45
|
-
await root.register(app, { context })
|
|
46
|
-
if (!root.hasRoute({ url: '/', method: 'GET' })) {
|
|
47
|
-
await root.register(require('./root-endpoint'))
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
root.decorate('url', {
|
|
51
|
-
getter () {
|
|
52
|
-
return serverContext.url
|
|
53
|
-
},
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
return root
|
|
57
|
-
}
|
|
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
|
-
|
|
66
|
-
let configManager = options.configManager
|
|
67
|
-
if (!configManager) {
|
|
68
|
-
// instantiate a new config manager from current options
|
|
69
|
-
configManager = new ConfigManager({ ...app.configManagerConfig, source: options })
|
|
70
|
-
await configManager.parseAndValidate()
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (loggerInstance) {
|
|
74
|
-
configManager.current.server ||= {}
|
|
75
|
-
delete configManager.current.server.logger
|
|
76
|
-
configManager.current.server.loggerInstance = loggerInstance
|
|
77
|
-
}
|
|
78
|
-
return configManager
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async function buildServer (options, app, context) {
|
|
82
|
-
const configManager = await buildConfigManager(options, app)
|
|
83
|
-
const config = configManager.current
|
|
84
|
-
|
|
85
|
-
// The server now can be not present, so we might need to add logger
|
|
86
|
-
addLoggerToTheConfig(config)
|
|
87
|
-
|
|
88
|
-
// options is a path
|
|
89
|
-
if (typeof options === 'string') {
|
|
90
|
-
options = config
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (options.server) {
|
|
94
|
-
if (options.server.https) {
|
|
95
|
-
options.server.https.key = await adjustHttpsKeyAndCert(options.server.https.key)
|
|
96
|
-
options.server.https.cert = await adjustHttpsKeyAndCert(options.server.https.cert)
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const serverContext = {
|
|
101
|
-
app: typeof app === 'function' ? app : app.app,
|
|
102
|
-
configManager,
|
|
103
|
-
context
|
|
104
|
-
}
|
|
105
|
-
const handler = await createServer(serverContext)
|
|
106
|
-
handler.start = async function () {
|
|
107
|
-
serverContext.url = await handler.listen({
|
|
108
|
-
host: options.server?.hostname || '127.0.0.1',
|
|
109
|
-
port: options.server?.port || 0,
|
|
110
|
-
})
|
|
111
|
-
return serverContext.url
|
|
112
|
-
}
|
|
113
|
-
configManager.on('error', function (err) {
|
|
114
|
-
/* c8 ignore next 1 */
|
|
115
|
-
handler.log.error({ err }, 'error reloading the configuration')
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
return handler
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
async function start (appType, _args) {
|
|
122
|
-
/* c8 ignore next 55 */
|
|
123
|
-
let configManager = null
|
|
124
|
-
try {
|
|
125
|
-
configManager = (await loadConfig({}, _args, appType)).configManager
|
|
126
|
-
} catch (err) {
|
|
127
|
-
if (err.validationErrors) {
|
|
128
|
-
printConfigValidationErrors(err)
|
|
129
|
-
process.exit(1)
|
|
130
|
-
} else {
|
|
131
|
-
throw err
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const config = configManager.current
|
|
136
|
-
|
|
137
|
-
const _transformConfig = configManager._transformConfig.bind(configManager)
|
|
138
|
-
configManager._transformConfig = function () {
|
|
139
|
-
const config = configManager.current
|
|
140
|
-
addLoggerToTheConfig(config)
|
|
141
|
-
return _transformConfig(config)
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
let app = null
|
|
145
|
-
|
|
146
|
-
try {
|
|
147
|
-
// Set the location of the config
|
|
148
|
-
app = await buildServer({ ...config, configManager }, appType)
|
|
149
|
-
await app.start()
|
|
150
|
-
} catch (err) {
|
|
151
|
-
printAndExitLoadConfigError(err)
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
close(async ({ signal, err }) => {
|
|
155
|
-
// Windows does not support trapping signals
|
|
156
|
-
if (err) {
|
|
157
|
-
app.log.error({
|
|
158
|
-
err: {
|
|
159
|
-
message: err.message,
|
|
160
|
-
stack: err.stack,
|
|
161
|
-
},
|
|
162
|
-
}, 'exiting')
|
|
163
|
-
} else if (signal) {
|
|
164
|
-
app.log.info({ signal }, 'received signal')
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// Weird coverage issue in c8
|
|
168
|
-
/* c8 ignore next 2 */
|
|
169
|
-
await app.close()
|
|
170
|
-
})
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
module.exports.buildConfigManager = buildConfigManager
|
|
174
|
-
module.exports.buildServer = buildServer
|
|
175
|
-
module.exports.start = start
|
package/service.mjs
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import commist from 'commist'
|
|
4
|
-
import parseArgs from 'minimist'
|
|
5
|
-
import isMain from 'es-main'
|
|
6
|
-
import helpMe from 'help-me'
|
|
7
|
-
import { readFile } from 'fs/promises'
|
|
8
|
-
import { join } from 'desm'
|
|
9
|
-
import { printAndExitLoadConfigError } from '@platformatic/config'
|
|
10
|
-
import { buildCompileCmd } from './lib/compile.js'
|
|
11
|
-
import { generateJsonSchemaConfig } from './lib/gen-schema.js'
|
|
12
|
-
import { generateTypes } from './lib/gen-types.mjs'
|
|
13
|
-
import { createService } from './lib/create.mjs'
|
|
14
|
-
|
|
15
|
-
import platformaticService from './index.js'
|
|
16
|
-
|
|
17
|
-
const help = helpMe({
|
|
18
|
-
dir: join(import.meta.url, 'help'),
|
|
19
|
-
// the default
|
|
20
|
-
ext: '.txt',
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
function wrapCommand (fn) {
|
|
24
|
-
return async function (...args) {
|
|
25
|
-
try {
|
|
26
|
-
return await fn(...args)
|
|
27
|
-
/* c8 ignore next 3 */
|
|
28
|
-
} catch (err) {
|
|
29
|
-
printAndExitLoadConfigError(err)
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const program = commist({ maxDistance: 2 })
|
|
35
|
-
|
|
36
|
-
program.register('help', help.toStdout)
|
|
37
|
-
program.register('help start', help.toStdout.bind(null, ['start']))
|
|
38
|
-
|
|
39
|
-
program.register('start', (argv) => {
|
|
40
|
-
/* c8 ignore next 1 */
|
|
41
|
-
platformaticService.start(platformaticService, argv).catch(printAndExitLoadConfigError)
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
program.register('create', wrapCommand(createService))
|
|
45
|
-
program.register('compile', buildCompileCmd(platformaticService))
|
|
46
|
-
program.register('types', wrapCommand(generateTypes))
|
|
47
|
-
program.register('schema config', wrapCommand(generateJsonSchemaConfig))
|
|
48
|
-
program.register('schema', help.toStdout.bind(null, ['schema']))
|
|
49
|
-
|
|
50
|
-
export async function runService (argv) {
|
|
51
|
-
const args = parseArgs(argv, {
|
|
52
|
-
alias: {
|
|
53
|
-
v: 'version',
|
|
54
|
-
},
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
/* c8 ignore next 4 */
|
|
58
|
-
if (args.version) {
|
|
59
|
-
console.log('v' + JSON.parse(await readFile(join(import.meta.url, 'package.json'), 'utf-8')).version)
|
|
60
|
-
process.exit(0)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
output: await program.parseAsync(argv),
|
|
65
|
-
help,
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (isMain(import.meta)) {
|
|
70
|
-
await runService(process.argv.splice(2))
|
|
71
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|