@platformatic/service 0.27.0 → 0.28.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/fixtures/hello/platformatic.service.json +1 -2
- package/fixtures/hello/warn-log.service.json +1 -2
- package/fixtures/hello-client/platformatic.service.json +2 -3
- package/fixtures/hello-client-ts/platformatic.service.json +2 -3
- package/index.d.ts +17 -11
- package/index.js +4 -21
- package/index.test-d.ts +14 -22
- package/lib/compile.js +0 -26
- package/lib/load-config.js +1 -2
- package/lib/plugins/plugins.js +1 -19
- package/lib/plugins/typescript.js +1 -31
- package/lib/root-endpoint/public/background_frame.svg +614 -0
- package/lib/root-endpoint/public/background_polygon_14.svg +3 -0
- package/lib/root-endpoint/public/background_polygon_28.svg +3 -0
- package/lib/root-endpoint/public/dark_mode.svg +3 -0
- package/lib/root-endpoint/public/index.html +164 -35
- package/lib/root-endpoint/public/light_mode.svg +11 -0
- package/lib/root-endpoint/public/platformatic-logo-dark.svg +8 -0
- package/lib/root-endpoint/public/platformatic-logo-light.svg +8 -0
- package/lib/schema.js +3 -10
- package/lib/start.js +2 -23
- package/package.json +17 -9
- package/test/autoload.test.js +0 -182
- package/test/cli/compile.test.mjs +1 -1
- package/test/fixtures/bad-typescript-plugin/platformatic.service.json +1 -1
- package/test/load-and-reload-files.test.js +7 -278
- package/tsconfig.json +12 -0
- package/lib/plugins/file-watcher.js +0 -44
- package/lib/root-endpoint/public/logo-512x512.png +0 -0
- package/test/cli/watch.test.mjs +0 -289
- package/test/watch.test.js +0 -248
package/index.d.ts
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/triple-slash-reference */
|
|
2
|
+
/// <reference types="@platformatic/types" />
|
|
3
|
+
/// <reference types="mercurius" />
|
|
4
|
+
/// <reference types="@fastify/swagger" />
|
|
5
|
+
import { FastifyInstance } from 'fastify'
|
|
6
|
+
import ConfigManager from '@platformatic/config'
|
|
2
7
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
listen: FastifyInstance['listen']
|
|
9
|
-
close: FastifyInstance['close']
|
|
10
|
-
inject: FastifyInstance['inject']
|
|
8
|
+
declare module '@platformatic/types' {
|
|
9
|
+
interface PlatformaticApp {
|
|
10
|
+
configManager: ConfigManager
|
|
11
|
+
config: object
|
|
12
|
+
}
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
export function buildServer (opts: object, app?: object, ConfigManagerContructor?: object): Promise<FastifyInstance>
|
|
16
|
+
|
|
17
|
+
declare module 'fastify' {
|
|
18
|
+
interface FastifyInstance {
|
|
19
|
+
restart: () => Promise<void>
|
|
20
|
+
}
|
|
15
21
|
}
|
package/index.js
CHANGED
|
@@ -9,7 +9,6 @@ const setupGraphQL = require('./lib/plugins/graphql.js')
|
|
|
9
9
|
const setupClients = require('./lib/plugins/clients')
|
|
10
10
|
const setupMetrics = require('./lib/plugins/metrics')
|
|
11
11
|
const setupTsCompiler = require('./lib/plugins/typescript')
|
|
12
|
-
const setupFileWatcher = require('./lib/plugins/file-watcher')
|
|
13
12
|
const setupHealthCheck = require('./lib/plugins/health-check')
|
|
14
13
|
const loadPlugins = require('./lib/plugins/plugins')
|
|
15
14
|
|
|
@@ -54,7 +53,10 @@ async function platformaticService (app, opts, toLoad = []) {
|
|
|
54
53
|
}
|
|
55
54
|
|
|
56
55
|
if (isKeyEnabled('watch', config)) {
|
|
57
|
-
|
|
56
|
+
// If file watching is enabled here, that means the service was started
|
|
57
|
+
// without the runtime because the runtime explicitly disables watching on
|
|
58
|
+
// services that it starts. Warn the user that things will not go as planned.
|
|
59
|
+
app.log.warn('service was started with file watching enabled but watching is only available via the runtime')
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
if (config.server.cors) {
|
|
@@ -70,25 +72,6 @@ async function platformaticService (app, opts, toLoad = []) {
|
|
|
70
72
|
}
|
|
71
73
|
}
|
|
72
74
|
|
|
73
|
-
async function onFilesUpdated (app) {
|
|
74
|
-
// Reload the config as well, otherwise we will have problems
|
|
75
|
-
// in case the files watcher triggers the config watcher too
|
|
76
|
-
const configManager = app.platformatic.configManager
|
|
77
|
-
try {
|
|
78
|
-
app.log.debug('files changed')
|
|
79
|
-
await configManager.parse()
|
|
80
|
-
await app.restart()
|
|
81
|
-
/* c8 ignore next 8 */
|
|
82
|
-
} catch (err) {
|
|
83
|
-
app.log.error({
|
|
84
|
-
err: {
|
|
85
|
-
message: err.message,
|
|
86
|
-
stack: err.stack
|
|
87
|
-
}
|
|
88
|
-
}, 'failed to reload server')
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
75
|
platformaticService[Symbol.for('skip-override')] = true
|
|
93
76
|
platformaticService.schema = schema
|
|
94
77
|
platformaticService.configType = 'service'
|
package/index.test-d.ts
CHANGED
|
@@ -1,24 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { FastifyInstance } from 'fastify'
|
|
3
|
-
import {
|
|
1
|
+
import { expectType } from 'tsd'
|
|
2
|
+
import { FastifyInstance } from 'fastify'
|
|
3
|
+
import { buildServer } from '.'
|
|
4
|
+
import ConfigManager from '@platformatic/config'
|
|
5
|
+
import { OpenAPI } from 'openapi-types'
|
|
6
|
+
import type { MercuriusPlugin } from 'mercurius'
|
|
4
7
|
|
|
5
|
-
const server
|
|
6
|
-
|
|
7
|
-
address: 'localhost',
|
|
8
|
-
port: 3000,
|
|
9
|
-
restart: async () => {},
|
|
10
|
-
listen: async () => '',
|
|
11
|
-
close: (async () => undefined) as unknown as FastifyInstance['close'],
|
|
12
|
-
inject: (async () => undefined) as unknown as FastifyInstance['inject']
|
|
13
|
-
};
|
|
8
|
+
const server = await buildServer({
|
|
9
|
+
})
|
|
14
10
|
|
|
15
|
-
expectType<
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
expectError<pltServiceHandlerBuildServer>({...server, listen: async () => ({ address: 42, port: 3000 }), });
|
|
22
|
-
expectError<pltServiceHandlerBuildServer>({...server, listen: async () => ({ address: 'localhost', port: 'WRONG' }), });
|
|
23
|
-
expectError<pltServiceHandlerBuildServer>({...server, stop: 'WRONG' });
|
|
24
|
-
expectError<pltServiceHandlerBuildServer>({...server, inject: 'WRONG' });
|
|
11
|
+
expectType<FastifyInstance>(server)
|
|
12
|
+
expectType<ConfigManager>(server.platformatic.configManager)
|
|
13
|
+
expectType<ConfigManager>(server.platformatic.configManager)
|
|
14
|
+
expectType<OpenAPI.Document>(server.swagger())
|
|
15
|
+
expectType<MercuriusPlugin>(server.graphql)
|
|
16
|
+
expectType<Promise<void>>(server.restart())
|
package/lib/compile.js
CHANGED
|
@@ -79,31 +79,6 @@ async function compile (cwd, config, originalLogger) {
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
// This path is tested but C8 does not see it that way given it needs to work
|
|
83
|
-
// through execa.
|
|
84
|
-
/* c8 ignore next 20 */
|
|
85
|
-
async function compileWatch (cwd, config, originalLogger) {
|
|
86
|
-
const { execa, logger, tscExecutablePath } = await setup(cwd, config, originalLogger)
|
|
87
|
-
if (!tscExecutablePath) {
|
|
88
|
-
return false
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
try {
|
|
92
|
-
await execa(tscExecutablePath, ['--project', 'tsconfig.json', '--incremental', '--rootDir', '.'], { cwd })
|
|
93
|
-
logger.info('Typescript compilation completed successfully. Starting watch mode.')
|
|
94
|
-
} catch (error) {
|
|
95
|
-
throw new Error('Failed to compile typescript files: ' + error)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const child = execa(tscExecutablePath, ['--project', 'tsconfig.json', '--watch', '--incremental'], { cwd })
|
|
99
|
-
child.stdout.resume()
|
|
100
|
-
child.stderr.on('data', (data) => {
|
|
101
|
-
logger.error(data.toString())
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
return { child }
|
|
105
|
-
}
|
|
106
|
-
|
|
107
82
|
function buildCompileCmd (app) {
|
|
108
83
|
return async function compileCmd (_args) {
|
|
109
84
|
let fullPath = null
|
|
@@ -126,5 +101,4 @@ function buildCompileCmd (app) {
|
|
|
126
101
|
}
|
|
127
102
|
|
|
128
103
|
module.exports.compile = compile
|
|
129
|
-
module.exports.compileWatch = compileWatch
|
|
130
104
|
module.exports.buildCompileCmd = buildCompileCmd
|
package/lib/load-config.js
CHANGED
|
@@ -18,8 +18,7 @@ async function loadConfig (minimistConfig, _args, app, overrides = {}) {
|
|
|
18
18
|
const args = parseArgs(_args, deepmerge({ all: true })({
|
|
19
19
|
string: ['allow-env'],
|
|
20
20
|
default: {
|
|
21
|
-
allowEnv: ''
|
|
22
|
-
hotReload: true
|
|
21
|
+
allowEnv: '' // The default is set in ConfigManager
|
|
23
22
|
},
|
|
24
23
|
alias: {
|
|
25
24
|
v: 'version',
|
package/lib/plugins/plugins.js
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
const { join, resolve } = require('path')
|
|
4
4
|
const { readFile } = require('fs/promises')
|
|
5
|
-
|
|
6
|
-
const sandbox = require('fastify-sandbox')
|
|
7
5
|
const fp = require('fastify-plugin')
|
|
8
6
|
|
|
9
7
|
const { getJSPluginPath, isFileAccessible } = require('../utils')
|
|
@@ -34,23 +32,7 @@ async function loadPlugins (app) {
|
|
|
34
32
|
})
|
|
35
33
|
}
|
|
36
34
|
|
|
37
|
-
|
|
38
|
-
await app.register(sandbox, {
|
|
39
|
-
path: wrapperPath,
|
|
40
|
-
options: { paths: config.plugins.paths },
|
|
41
|
-
customizeGlobalThis (_globalThis) {
|
|
42
|
-
// Taken from https://github.com/nodejs/undici/blob/fa9fd9066569b6357acacffb806aa804b688c9d8/lib/global.js#L5
|
|
43
|
-
const globalDispatcher = Symbol.for('undici.globalDispatcher.1')
|
|
44
|
-
const dispatcher = globalThis[globalDispatcher]
|
|
45
|
-
/* istanbul ignore else */
|
|
46
|
-
if (dispatcher) {
|
|
47
|
-
_globalThis[globalDispatcher] = dispatcher
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
})
|
|
51
|
-
} else {
|
|
52
|
-
await app.register(require(wrapperPath), { paths: config.plugins.paths })
|
|
53
|
-
}
|
|
35
|
+
await app.register(require(wrapperPath), { paths: config.plugins.paths })
|
|
54
36
|
}
|
|
55
37
|
|
|
56
38
|
module.exports = fp(loadPlugins)
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { isKeyEnabled } = require('@platformatic/utils')
|
|
4
3
|
const fp = require('fastify-plugin')
|
|
5
|
-
|
|
6
4
|
const compiler = require('../compile')
|
|
7
5
|
|
|
8
6
|
async function setupTsCompiler (app) {
|
|
@@ -10,37 +8,9 @@ async function setupTsCompiler (app) {
|
|
|
10
8
|
|
|
11
9
|
const configManager = app.platformatic.configManager
|
|
12
10
|
const config = configManager.current
|
|
13
|
-
|
|
14
|
-
const isRestartableApp = app.restarted !== undefined
|
|
15
|
-
|
|
16
|
-
// to run the plugin without restartable
|
|
17
|
-
/* c8 ignore next 1 */
|
|
18
|
-
const persistentRef = isRestartableApp ? app.persistentRef : app
|
|
19
|
-
|
|
20
11
|
const workingDir = configManager.dirname
|
|
21
12
|
|
|
22
|
-
|
|
23
|
-
let tsCompilerWatcher = persistentRef.tsCompilerWatcher
|
|
24
|
-
if (!tsCompilerWatcher) {
|
|
25
|
-
/* c8 ignore next 5 */
|
|
26
|
-
const { child } = await compiler.compileWatch(workingDir, config, app.log)
|
|
27
|
-
app.log.debug('start watching typescript files')
|
|
28
|
-
tsCompilerWatcher = child
|
|
29
|
-
}
|
|
30
|
-
app.decorate('tsCompilerWatcher', tsCompilerWatcher)
|
|
31
|
-
} else {
|
|
32
|
-
await compiler.compile(workingDir, config, app.log)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
app.addHook('onClose', async () => {
|
|
36
|
-
if (!isRestartableApp || app.closingRestartable) {
|
|
37
|
-
/* c8 ignore next 4 */
|
|
38
|
-
if (app.tsCompilerWatcher) {
|
|
39
|
-
app.tsCompilerWatcher.kill('SIGTERM')
|
|
40
|
-
app.log.debug('stop watching typescript files')
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
})
|
|
13
|
+
await compiler.compile(workingDir, config, app.log)
|
|
44
14
|
}
|
|
45
15
|
|
|
46
16
|
module.exports = fp(setupTsCompiler)
|