@platformatic/service 0.24.0 → 0.26.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/index.js +7 -0
- package/lib/load-config.js +4 -1
- package/lib/plugins/openapi.js +2 -0
- package/lib/root-endpoint/public/index.html +2 -0
- package/lib/utils.js +2 -1
- package/package.json +10 -9
- package/test/config.test.js +1 -0
- package/test/load-and-reload-files.test.js +2 -0
- package/test/watch.test.js +66 -0
package/index.js
CHANGED
|
@@ -112,6 +112,13 @@ platformaticService.configManagerConfig = {
|
|
|
112
112
|
coerceTypes: true,
|
|
113
113
|
allErrors: true,
|
|
114
114
|
strict: false
|
|
115
|
+
},
|
|
116
|
+
transformConfig () {
|
|
117
|
+
// Set watch to true by default. This is not possible
|
|
118
|
+
// to do in the schema, because it is uses an anyOf.
|
|
119
|
+
if (this.current.watch === undefined) {
|
|
120
|
+
this.current.watch = true
|
|
121
|
+
}
|
|
115
122
|
}
|
|
116
123
|
}
|
|
117
124
|
|
package/lib/load-config.js
CHANGED
|
@@ -37,7 +37,10 @@ async function loadConfig (minimistConfig, _args, app, overrides = {}) {
|
|
|
37
37
|
const configFiles = ConfigManager.listConfigFiles(configType)
|
|
38
38
|
console.error(`
|
|
39
39
|
Missing config file!
|
|
40
|
-
Be sure to have a config file with one of the following names:
|
|
40
|
+
Be sure to have a config file with one of the following names:
|
|
41
|
+
|
|
42
|
+
${configFiles.map((s) => ' * ' + s).join('\n')}
|
|
43
|
+
|
|
41
44
|
In alternative run "npm create platformatic@latest" to generate a basic plt service config.
|
|
42
45
|
Error: ${err}
|
|
43
46
|
`)
|
package/lib/plugins/openapi.js
CHANGED
|
@@ -94,6 +94,8 @@
|
|
|
94
94
|
<img height="256" src="logo-512x512.png"/>
|
|
95
95
|
<h1>Welcome to Platformatic Service</h1>
|
|
96
96
|
<h2><a href="https://oss.platformatic.dev" target="_blank">Documentation</a></h2>
|
|
97
|
+
<h2><a href="/documentation" target="_blank">OpenAPI Documentation</a></h2>
|
|
98
|
+
<h2><a href="/graphiql" target="_blank">GraphiQL</a></h2>
|
|
97
99
|
</div>
|
|
98
100
|
</body>
|
|
99
101
|
</html>
|
package/lib/utils.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { access } = require('fs/promises')
|
|
4
4
|
const { resolve, join, relative, dirname, basename } = require('path')
|
|
5
|
+
const { isatty } = require('tty')
|
|
5
6
|
|
|
6
7
|
async function isFileAccessible (filename, directory) {
|
|
7
8
|
try {
|
|
@@ -23,7 +24,7 @@ function addLoggerToTheConfig (config) {
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
// If TTY use pino-pretty
|
|
26
|
-
if (
|
|
27
|
+
if (isatty(1)) {
|
|
27
28
|
if (!logger.transport) {
|
|
28
29
|
logger.transport = {
|
|
29
30
|
target: 'pino-pretty'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/service",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"tap": "^16.3.4",
|
|
30
30
|
"tsd": "^0.28.1",
|
|
31
31
|
"typescript": "^5.0.4",
|
|
32
|
-
"undici": "^5.22.
|
|
33
|
-
"vscode-json-languageservice": "^5.3.
|
|
32
|
+
"undici": "^5.22.1",
|
|
33
|
+
"vscode-json-languageservice": "^5.3.5",
|
|
34
34
|
"why-is-node-running": "^2.2.2",
|
|
35
35
|
"yaml": "^2.2.2"
|
|
36
36
|
},
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@fastify/deepmerge": "^1.3.0",
|
|
43
43
|
"@fastify/restartable": "^2.1.0",
|
|
44
44
|
"@fastify/static": "^6.10.1",
|
|
45
|
-
"@fastify/swagger": "^8.
|
|
45
|
+
"@fastify/swagger": "^8.5.1",
|
|
46
46
|
"@fastify/swagger-ui": "^1.8.1",
|
|
47
47
|
"@fastify/under-pressure": "^8.2.0",
|
|
48
48
|
"@mercuriusjs/federation": "^2.0.0",
|
|
@@ -55,18 +55,19 @@
|
|
|
55
55
|
"fastify": "^4.17.0",
|
|
56
56
|
"fastify-metrics": "^10.3.0",
|
|
57
57
|
"fastify-plugin": "^4.5.0",
|
|
58
|
-
"fastify-sandbox": "^0.
|
|
58
|
+
"fastify-sandbox": "^0.13.0",
|
|
59
59
|
"graphql": "^16.6.0",
|
|
60
60
|
"help-me": "^4.2.0",
|
|
61
61
|
"mercurius": "^13.0.0",
|
|
62
62
|
"minimist": "^1.2.8",
|
|
63
|
-
"pino": "^8.
|
|
63
|
+
"pino": "^8.14.1",
|
|
64
64
|
"pino-pretty": "^10.0.0",
|
|
65
65
|
"rfdc": "^1.3.0",
|
|
66
66
|
"ua-parser-js": "^1.0.35",
|
|
67
|
-
"@platformatic/
|
|
68
|
-
"@platformatic/config": "0.
|
|
69
|
-
"@platformatic/utils": "0.
|
|
67
|
+
"@platformatic/swagger-ui-theme": "0.26.0",
|
|
68
|
+
"@platformatic/config": "0.26.0",
|
|
69
|
+
"@platformatic/utils": "0.26.0",
|
|
70
|
+
"@platformatic/client": "0.26.0"
|
|
70
71
|
},
|
|
71
72
|
"standard": {
|
|
72
73
|
"ignore": [
|
package/test/config.test.js
CHANGED
|
@@ -24,6 +24,7 @@ test('load and reload', async ({ teardown, equal, pass, same }) => {
|
|
|
24
24
|
plugins: {
|
|
25
25
|
paths: [file]
|
|
26
26
|
},
|
|
27
|
+
watch: false,
|
|
27
28
|
metrics: false
|
|
28
29
|
})
|
|
29
30
|
|
|
@@ -71,6 +72,7 @@ test('error', async ({ teardown, equal, pass, match }) => {
|
|
|
71
72
|
plugins: {
|
|
72
73
|
paths: [file]
|
|
73
74
|
},
|
|
75
|
+
watch: false,
|
|
74
76
|
metrics: false
|
|
75
77
|
})
|
|
76
78
|
|
package/test/watch.test.js
CHANGED
|
@@ -180,3 +180,69 @@ test('should stop watching typescript files after disabling watch option', async
|
|
|
180
180
|
same(await res.body.json(), { res: 'plugin, version 1' }, 'get rest plugin')
|
|
181
181
|
}
|
|
182
182
|
})
|
|
183
|
+
|
|
184
|
+
test('should watch files by default', async ({ teardown, equal, pass, same }) => {
|
|
185
|
+
const tmpDir = await mkdtemp(join(tmpdir(), 'platformatic.service.test-'))
|
|
186
|
+
const pathToPlugin = join(tmpDir, 'plugin.js')
|
|
187
|
+
const pathToConfig = join(tmpDir, 'platformatic.service.json')
|
|
188
|
+
|
|
189
|
+
teardown(async () => {
|
|
190
|
+
await rm(tmpDir, { recursive: true, force: true })
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
await writeFile(pathToPlugin, `
|
|
194
|
+
module.exports = async function plugin (app) {
|
|
195
|
+
app.get('/test', {}, async function (request, response) {
|
|
196
|
+
return { res: "plugin, version 1"}
|
|
197
|
+
})
|
|
198
|
+
}`)
|
|
199
|
+
|
|
200
|
+
const config = {
|
|
201
|
+
server: {
|
|
202
|
+
hostname: '127.0.0.1',
|
|
203
|
+
port: 0
|
|
204
|
+
},
|
|
205
|
+
plugins: {
|
|
206
|
+
paths: [pathToPlugin],
|
|
207
|
+
stopTimeout: 1000,
|
|
208
|
+
hotReload: true
|
|
209
|
+
},
|
|
210
|
+
metrics: false
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
await writeFile(pathToConfig, JSON.stringify(config, null, 2))
|
|
214
|
+
const app = await buildServer(pathToConfig)
|
|
215
|
+
|
|
216
|
+
teardown(async () => {
|
|
217
|
+
await app.close()
|
|
218
|
+
})
|
|
219
|
+
await app.start()
|
|
220
|
+
|
|
221
|
+
{
|
|
222
|
+
const res = await request(`${app.url}/test`, {
|
|
223
|
+
method: 'GET'
|
|
224
|
+
})
|
|
225
|
+
same(await res.body.json(), { res: 'plugin, version 1' }, 'get rest plugin')
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
equal(app.fileWatcher.isWatching, true)
|
|
229
|
+
|
|
230
|
+
await writeFile(pathToPlugin, `
|
|
231
|
+
module.exports = async function plugin (app) {
|
|
232
|
+
app.get('/test', {}, async function (request, response) {
|
|
233
|
+
return { res: "plugin, version 2"}
|
|
234
|
+
})
|
|
235
|
+
}`)
|
|
236
|
+
|
|
237
|
+
// wait to be sure that app is not watching files anymore
|
|
238
|
+
await new Promise((resolve) => setTimeout(resolve, 5000))
|
|
239
|
+
|
|
240
|
+
{
|
|
241
|
+
const res = await request(`${app.url}/test`, {
|
|
242
|
+
method: 'GET'
|
|
243
|
+
})
|
|
244
|
+
equal(res.statusCode, 200)
|
|
245
|
+
// must be unchanged
|
|
246
|
+
same(await res.body.json(), { res: 'plugin, version 2' })
|
|
247
|
+
}
|
|
248
|
+
})
|