@platformatic/service 0.17.1 → 0.18.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/help/schema.txt +1 -1
- package/index.js +21 -1
- package/lib/compile.js +2 -2
- package/lib/graphql.js +21 -0
- package/lib/load-config.js +6 -1
- package/lib/openapi-schema-defs.js +1140 -0
- package/lib/openapi.js +42 -0
- package/lib/schema.js +229 -25
- package/lib/utils.js +12 -1
- package/package.json +8 -4
- package/test/cli/compile.test.mjs +55 -33
- package/test/cli/gen-schema.test.mjs +1 -2
- package/test/cli/watch.test.mjs +13 -6
- package/test/config.test.js +2 -1
- package/test/fixtures/bad-typescript-plugin/dist/tsconfig.tsbuildinfo +1 -1
- package/test/fixtures/hello-world-resolver.js +16 -0
- package/test/fixtures/typescript-autoload/platformatic.service.json +13 -0
- package/test/fixtures/typescript-autoload/routes/plugin.ts +5 -0
- package/test/fixtures/typescript-autoload/tsconfig.json +22 -0
- package/test/graphql.test.js +154 -0
- package/test/helper.js +1 -2
- package/test/routes.test.js +123 -5
- package/test/tmp/typescript-plugin-clone-3/dist/tsconfig.tsbuildinfo +1 -1
- package/test/tmp/typescript-plugin-clone-4/dist/tsconfig.tsbuildinfo +1 -1
- package/test/tmp/typescript-plugin-clone-7/inner-folder/dist/plugin.js +18 -0
- package/test/tmp/typescript-plugin-clone-7/inner-folder/dist/plugin.js.map +1 -0
- package/test/tmp/typescript-plugin-clone-7/inner-folder/platformatic.service.json +13 -0
- package/test/tmp/typescript-plugin-clone-7/inner-folder/plugin.ts +5 -0
- package/test/tmp/typescript-plugin-clone-7/inner-folder/tsconfig.json +22 -0
- package/test/tmp/typescript-plugin-clone-8/dist/routes/plugin.js +7 -0
- package/test/tmp/typescript-plugin-clone-8/dist/routes/plugin.js.map +1 -0
- package/test/tmp/typescript-plugin-clone-8/dist/tsconfig.tsbuildinfo +1 -0
- package/test/tmp/typescript-plugin-clone-8/platformatic.service.json +13 -0
- package/test/tmp/typescript-plugin-clone-8/routes/plugin.ts +5 -0
- package/test/tmp/typescript-plugin-clone-8/tsconfig.json +22 -0
package/help/schema.txt
CHANGED
|
@@ -3,7 +3,7 @@ Update the config schema file:
|
|
|
3
3
|
* `schema config` - update the JSON schema config available on `platformatic.service.schema.json`
|
|
4
4
|
|
|
5
5
|
Your configuration on `platformatic.service.json` has a schema defined to improve the developer experience and avoid mistakes when updating the configuration of Platformatic Service.
|
|
6
|
-
When you
|
|
6
|
+
When you initialize a new Platformatic service (f.e. running `npm create platformatic@latest`), a new JSON `$schema` property is added in the `platformatic.service.json` config. This can allow your IDE to add suggestions (f.e. mandatory/missing fields, types, default values) by opening the config in `platformatic.service.json`.
|
|
7
7
|
Running `platformatic service schema config` you can update your schema so that it matches well the latest changes available on your config.
|
|
8
8
|
|
|
9
9
|
|
package/index.js
CHANGED
|
@@ -12,6 +12,8 @@ const compiler = require('./lib/compile')
|
|
|
12
12
|
const { join, dirname, resolve } = require('path')
|
|
13
13
|
const { readFile } = require('fs/promises')
|
|
14
14
|
const wrapperPath = join(__dirname, 'lib', 'sandbox-wrapper.js')
|
|
15
|
+
const setupOpenAPI = require('./lib/openapi.js')
|
|
16
|
+
const setupGraphQL = require('./lib/graphql.js')
|
|
15
17
|
|
|
16
18
|
function createServerConfig (config) {
|
|
17
19
|
// convert the config file to a new structure
|
|
@@ -49,6 +51,7 @@ async function platformaticService (app, opts, toLoad = []) {
|
|
|
49
51
|
{
|
|
50
52
|
const fileWatcher = opts.fileWatcher
|
|
51
53
|
const configManager = opts.configManager
|
|
54
|
+
/* c8 ignore next 3 */
|
|
52
55
|
if (fileWatcher !== undefined) {
|
|
53
56
|
app.platformatic.fileWatcher = fileWatcher
|
|
54
57
|
}
|
|
@@ -58,9 +61,25 @@ async function platformaticService (app, opts, toLoad = []) {
|
|
|
58
61
|
}
|
|
59
62
|
}
|
|
60
63
|
|
|
64
|
+
{
|
|
65
|
+
const serviceConfig = app.platformatic.config?.service
|
|
66
|
+
|
|
67
|
+
// for some unknown reason, c8 is not detecting any of this
|
|
68
|
+
// despite being covered by test/routes.test.js
|
|
69
|
+
/* c8 ignore next 3 */
|
|
70
|
+
if (serviceConfig?.openapi) {
|
|
71
|
+
await setupOpenAPI(app, app.platformatic.config?.service?.openapi)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* c8 ignore next 3 */
|
|
75
|
+
if (serviceConfig?.graphql) {
|
|
76
|
+
await setupGraphQL(app, app.platformatic.config?.service?.graphql)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
61
80
|
if (opts.plugins) {
|
|
62
81
|
// if we don't have a fullPath, let's assume we are in a test and we can use the current working directory
|
|
63
|
-
const configPath = app.platformatic.configManager.fullPath || process.cwd()
|
|
82
|
+
const configPath = app.platformatic.configManager.fullPath || join(process.cwd(), 'platformatic.db.json')
|
|
64
83
|
const tsConfigPath = join(dirname(configPath), 'tsconfig.json')
|
|
65
84
|
/* c8 ignore next 21 */
|
|
66
85
|
if (await isFileAccessible(tsConfigPath)) {
|
|
@@ -125,6 +144,7 @@ async function platformaticService (app, opts, toLoad = []) {
|
|
|
125
144
|
|
|
126
145
|
app.register(require('@fastify/cors'), opts.cors)
|
|
127
146
|
}
|
|
147
|
+
|
|
128
148
|
if (isKeyEnabled('healthCheck', opts)) {
|
|
129
149
|
app.register(underPressure, {
|
|
130
150
|
exposeStatusRoute: '/status',
|
package/lib/compile.js
CHANGED
|
@@ -64,7 +64,7 @@ async function compile (cwd) {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
try {
|
|
67
|
-
await execa(tscExecutablePath, ['--project', 'tsconfig.json'], { cwd })
|
|
67
|
+
await execa(tscExecutablePath, ['--project', 'tsconfig.json', '--rootDir', '.'], { cwd })
|
|
68
68
|
logger.info('Typescript compilation completed successfully.')
|
|
69
69
|
return true
|
|
70
70
|
} catch (error) {
|
|
@@ -83,7 +83,7 @@ async function compileWatch (cwd) {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
try {
|
|
86
|
-
await execa(tscExecutablePath, ['--project', 'tsconfig.json', '--incremental'], { cwd })
|
|
86
|
+
await execa(tscExecutablePath, ['--project', 'tsconfig.json', '--incremental', '--rootDir', '.'], { cwd })
|
|
87
87
|
logger.info('Typescript compilation completed successfully. Starting watch mode.')
|
|
88
88
|
} catch (error) {
|
|
89
89
|
throw new Error('Failed to compile typescript files: ' + error)
|
package/lib/graphql.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const mercurius = require('mercurius')
|
|
4
|
+
const deepmerge = require('@fastify/deepmerge')({ all: true })
|
|
5
|
+
const fp = require('fastify-plugin')
|
|
6
|
+
|
|
7
|
+
// For some unknown reason, c8 is not detecting any of this
|
|
8
|
+
// despite being covered by test/graphql.test.js
|
|
9
|
+
/* c8 ignore next 12 */
|
|
10
|
+
async function setupGraphQL (app, opts) {
|
|
11
|
+
if (typeof opts !== 'object') {
|
|
12
|
+
opts = {}
|
|
13
|
+
}
|
|
14
|
+
const graphqlOptions = deepmerge({
|
|
15
|
+
graphiql: true
|
|
16
|
+
}, opts)
|
|
17
|
+
|
|
18
|
+
app.register(mercurius, graphqlOptions)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = fp(setupGraphQL)
|
package/lib/load-config.js
CHANGED
|
@@ -37,7 +37,12 @@ async function loadConfig (minimistConfig, _args, configOpts = {}, Manager = Con
|
|
|
37
37
|
}
|
|
38
38
|
await access(args.config)
|
|
39
39
|
} catch (err) {
|
|
40
|
-
console.error(
|
|
40
|
+
console.error(`
|
|
41
|
+
Missing config file!
|
|
42
|
+
Be sure to have a config file with one of the following names: ${ourConfigFiles.join('\n')}
|
|
43
|
+
In alternative run "npm create platformatic@latest" to generate a basic plt service config.
|
|
44
|
+
Error: ${err}
|
|
45
|
+
`)
|
|
41
46
|
process.exit(1)
|
|
42
47
|
}
|
|
43
48
|
|