@platformatic/runtime 2.0.0-alpha.2 → 2.0.0-alpha.4
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/config.d.ts +285 -0
- package/eslint.config.js +8 -0
- package/fixtures/botched-start/platformatic.runtime.json +1 -1
- package/fixtures/botched-start/services/a/platformatic.service.json +1 -1
- package/fixtures/composerApp/platformatic.composer.json +1 -1
- package/fixtures/configs/invalid-autoload-with-services.json +1 -1
- package/fixtures/configs/invalid-entrypoint.json +1 -1
- package/fixtures/configs/invalid-schema-type.config.json +1 -1
- package/fixtures/configs/missing-property.config.json +1 -1
- package/fixtures/configs/missing-service-config.json +1 -1
- package/fixtures/configs/monorepo-composer-no-autoload.json +2 -2
- package/fixtures/configs/monorepo-composer.json +2 -2
- package/fixtures/configs/monorepo-create-cycle.json +2 -2
- package/fixtures/configs/monorepo-missing-dependencies.json +2 -2
- package/fixtures/configs/monorepo-no-cycles.json +2 -2
- package/fixtures/configs/monorepo-openapi.json +2 -2
- package/fixtures/configs/{monorepo-hotreload-env.json → monorepo-watch-env.json} +2 -2
- package/fixtures/configs/monorepo-watch-single.json +12 -0
- package/fixtures/configs/monorepo-watch.json +26 -9
- package/fixtures/configs/monorepo-with-dependencies.json +2 -2
- package/fixtures/configs/monorepo-with-management-api-without-metrics.json +21 -0
- package/fixtures/configs/monorepo-with-management-api.json +2 -2
- package/fixtures/configs/{monorepo-hotreload.json → monorepo-with-metrics.json} +5 -4
- package/fixtures/configs/monorepo.json +2 -2
- package/fixtures/configs/no-services.config.json +1 -1
- package/fixtures/configs/no-sources.config.json +1 -1
- package/fixtures/configs/service-throws-on-start.json +1 -1
- package/fixtures/configs/service-with-env-port.json +2 -2
- package/fixtures/configs/service-with-stdio.json +12 -0
- package/fixtures/configs/{hotreload.json → watch.json} +2 -2
- package/fixtures/crash-on-bootstrap/platformatic.runtime.json +15 -0
- package/fixtures/crash-on-bootstrap/services/service-1/platformatic.service.json +14 -0
- package/fixtures/crash-on-bootstrap/services/service-1/plugin.js +5 -0
- package/fixtures/crash-on-bootstrap/services/service-2/platformatic.service.json +14 -0
- package/fixtures/crash-on-bootstrap/services/service-2/plugin.js +5 -0
- package/fixtures/dbApp/platformatic.db.json +1 -1
- package/fixtures/dbAppNoName/platformatic.db.json +1 -1
- package/fixtures/dbAppNoPackageJson/platformatic.db.json +1 -1
- package/fixtures/dbAppWithMigrationError/platformatic.db.json +1 -1
- package/fixtures/do-not-reload-dependencies/platformatic.service.json +1 -1
- package/fixtures/do-not-restart-on-crash/platformatic.runtime.json +3 -2
- package/fixtures/do-not-restart-on-crash/services/a/platformatic.service.json +1 -1
- package/fixtures/express/platformatic.runtime.json +1 -1
- package/fixtures/express/services/a/platformatic.service.json +1 -1
- package/fixtures/express/services/b/platformatic.service.json +1 -1
- package/fixtures/external-client/platformatic.service.json +1 -1
- package/fixtures/interceptors/idp.js +2 -2
- package/fixtures/interceptors/platformatic.runtime.json +1 -1
- package/fixtures/interceptors/services/a/platformatic.service.json +1 -1
- package/fixtures/interceptors-2/platformatic.runtime.json +1 -1
- package/fixtures/interceptors-2/services/a/platformatic.service.json +1 -1
- package/fixtures/leven/platformatic.runtime.json +2 -2
- package/fixtures/leven/services/deeply-spittle/platformatic.service.json +1 -1
- package/fixtures/leven/services/rainy-empire/platformatic.composer.json +1 -1
- package/fixtures/management-api/platformatic.json +3 -3
- package/fixtures/management-api/services/service-1/platformatic.json +1 -1
- package/fixtures/management-api/services/service-1/plugin.js +4 -3
- package/fixtures/management-api/services/service-2/platformatic.json +1 -1
- package/fixtures/management-api/services/service-db/platformatic.db.json +1 -1
- package/fixtures/management-api-custom-labels/platformatic.json +2 -2
- package/fixtures/management-api-custom-labels/services/service-1/platformatic.json +1 -1
- package/fixtures/management-api-custom-labels/services/service-1/plugin.js +4 -3
- package/fixtures/management-api-custom-labels/services/service-2/platformatic.json +1 -1
- package/fixtures/management-api-custom-labels/services/service-db/platformatic.db.json +1 -1
- package/fixtures/management-api-without-metrics/platformatic.json +3 -2
- package/fixtures/management-api-without-metrics/services/service-1/platformatic.json +1 -1
- package/fixtures/monorepo/composerApp/platformatic.composer.json +1 -1
- package/fixtures/monorepo/dbApp/platformatic.db.json +1 -1
- package/fixtures/monorepo/serviceApp/platformatic.service.json +3 -2
- package/fixtures/monorepo/serviceApp/with-logger/with-logger.cjs +2 -2
- package/fixtures/monorepo/serviceApp/with-logger/with-logger.d.ts +7 -7
- package/fixtures/monorepo/serviceAppWithLogger/platformatic.service.json +1 -1
- package/fixtures/monorepo/serviceAppWithLogger/plugin.js +12 -0
- package/fixtures/monorepo/serviceAppWithMultiplePlugins/platformatic.service.json +3 -2
- package/fixtures/monorepo-missing-dependencies/composer/platformatic.json +1 -1
- package/fixtures/monorepo-openapi/serviceAppWithoutOpenapi/platformatic.service.json +1 -1
- package/fixtures/monorepo-watch/service1/platformatic.service.json +1 -1
- package/fixtures/monorepo-with-dependencies/main/platformatic.json +1 -1
- package/fixtures/monorepo-with-dependencies/service-1/platformatic.json +1 -1
- package/fixtures/monorepo-with-dependencies/service-2/platformatic.json +1 -1
- package/fixtures/no-env.service.json +1 -1
- package/fixtures/preload/platformatic.runtime.json +1 -1
- package/fixtures/preload/services/a/platformatic.service.json +1 -1
- package/fixtures/prom-server/platformatic.json +2 -2
- package/fixtures/prom-server/services/service-1/platformatic.json +1 -1
- package/fixtures/prom-server/services/service-2/platformatic.json +1 -1
- package/fixtures/restart-on-crash/platformatic.runtime.json +1 -1
- package/fixtures/restart-on-crash/services/a/platformatic.service.json +1 -1
- package/fixtures/sample-runtime/package.json +1 -1
- package/fixtures/sample-runtime/platformatic.json +2 -2
- package/fixtures/sample-runtime/services/rival/package.json +1 -1
- package/fixtures/sample-runtime/services/rival/platformatic.json +1 -1
- package/fixtures/sample-runtime-with-2-services/package.json +1 -1
- package/fixtures/sample-runtime-with-2-services/platformatic.json +2 -2
- package/fixtures/sample-runtime-with-2-services/services/foobar/package.json +1 -1
- package/fixtures/sample-runtime-with-2-services/services/foobar/platformatic.json +1 -1
- package/fixtures/sample-runtime-with-2-services/services/rival/package.json +1 -1
- package/fixtures/sample-runtime-with-2-services/services/rival/platformatic.json +1 -1
- package/fixtures/server/logger-transport/platformatic.runtime.json +2 -2
- package/fixtures/server/logger-transport/services/echo/platformatic.service.json +1 -1
- package/fixtures/server/overrides-service/platformatic.runtime.json +2 -2
- package/fixtures/server/overrides-service/services/echo/platformatic.service.json +1 -1
- package/fixtures/server/runtime-server/platformatic.runtime.json +2 -2
- package/fixtures/server/runtime-server/services/echo/platformatic.service.json +1 -1
- package/fixtures/serviceAppThrowsOnStart/platformatic.service.json +1 -1
- package/fixtures/stackables/node_modules/foo/foo.js +2 -1
- package/fixtures/start-command-in-runtime.js +1 -1
- package/fixtures/stdio/platformatic.service.json +6 -0
- package/fixtures/stdio/plugin.js +24 -0
- package/fixtures/telemetry/platformatic.runtime.json +2 -2
- package/fixtures/telemetry/services/echo/platformatic.service.json +1 -1
- package/fixtures/telemetry/services/echo/routes/span.js +16 -2
- package/fixtures/telemetry/services/service-1/platformatic.service.json +19 -0
- package/fixtures/telemetry/services/service-1/routes/echo.js +7 -0
- package/fixtures/typescript/platformatic.runtime.json +2 -2
- package/fixtures/typescript/services/composer/platformatic.composer.json +1 -1
- package/fixtures/typescript/services/movies/global.d.ts +2 -3
- package/fixtures/typescript/services/movies/platformatic.db.json +1 -1
- package/fixtures/typescript/services/movies/types/Movie.d.ts +3 -3
- package/fixtures/typescript/services/movies/types/index.d.ts +6 -6
- package/fixtures/typescript/services/titles/client/client.d.ts +35 -35
- package/fixtures/typescript/services/titles/platformatic.service.json +1 -1
- package/fixtures/typescript-custom-flags/platformatic.runtime.json +2 -2
- package/fixtures/typescript-custom-flags/services/composer/platformatic.composer.json +1 -1
- package/fixtures/typescript-custom-flags/services/movies/global.d.ts +2 -3
- package/fixtures/typescript-custom-flags/services/movies/platformatic.db.json +1 -1
- package/fixtures/typescript-custom-flags/services/movies/types/Movie.d.ts +3 -3
- package/fixtures/typescript-custom-flags/services/movies/types/index.d.ts +6 -6
- package/fixtures/typescript-custom-flags/services/titles/client/client.d.ts +35 -35
- package/fixtures/typescript-custom-flags/services/titles/platformatic.service.json +1 -1
- package/fixtures/typescript-no-env/platformatic.runtime.json +2 -2
- package/fixtures/typescript-no-env/services/composer/platformatic.composer.json +1 -1
- package/fixtures/typescript-no-env/services/movies/global.d.ts +2 -3
- package/fixtures/typescript-no-env/services/movies/platformatic.db.json +1 -1
- package/fixtures/typescript-no-env/services/movies/types/Movie.d.ts +3 -3
- package/fixtures/typescript-no-env/services/movies/types/index.d.ts +6 -6
- package/fixtures/typescript-no-env/services/titles/client/client.d.ts +35 -35
- package/fixtures/typescript-no-env/services/titles/platformatic.service.json +1 -1
- package/index.d.ts +7 -8
- package/index.js +14 -10
- package/index.test-d.ts +10 -12
- package/lib/build-server.js +5 -11
- package/lib/compile.js +11 -10
- package/lib/config.js +21 -14
- package/lib/dependencies.js +2 -1
- package/lib/errors.js +3 -2
- package/lib/generator/errors.js +1 -1
- package/lib/generator/runtime-generator.d.ts +15 -15
- package/lib/generator/runtime-generator.js +92 -63
- package/lib/logger.js +55 -0
- package/lib/management-api.js +29 -44
- package/lib/prom-server.js +5 -9
- package/lib/runtime.js +955 -0
- package/lib/schema.js +79 -76
- package/lib/start.js +35 -113
- package/lib/upgrade.js +4 -3
- package/lib/utils.js +49 -1
- package/lib/versions/v1.36.0.js +1 -1
- package/lib/versions/v1.5.0.js +1 -1
- package/lib/versions/v2.0.0.js +17 -0
- package/lib/worker/app.js +250 -0
- package/lib/worker/default-stackable.js +27 -0
- package/lib/worker/itc.js +128 -0
- package/lib/worker/main.js +127 -0
- package/lib/worker/symbols.js +7 -0
- package/package.json +25 -25
- package/runtime.mjs +4 -4
- package/schema.json +824 -0
- package/lib/api-client.js +0 -500
- package/lib/api.js +0 -420
- package/lib/app.js +0 -397
- package/lib/load-config.js +0 -12
- package/lib/loader.mjs +0 -103
- package/lib/message-port-writable.js +0 -50
- package/lib/worker.js +0 -182
- /package/lib/{interceptors.js → worker/interceptors.js} +0 -0
package/lib/worker.js
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const inspector = require('node:inspector')
|
|
4
|
-
const { register, createRequire } = require('node:module')
|
|
5
|
-
const { isatty } = require('node:tty')
|
|
6
|
-
const { join } = require('node:path')
|
|
7
|
-
const { pathToFileURL } = require('node:url')
|
|
8
|
-
const {
|
|
9
|
-
MessageChannel,
|
|
10
|
-
parentPort,
|
|
11
|
-
workerData
|
|
12
|
-
} = require('node:worker_threads')
|
|
13
|
-
const undici = require('undici')
|
|
14
|
-
const pino = require('pino')
|
|
15
|
-
const pretty = require('pino-pretty')
|
|
16
|
-
const { setGlobalDispatcher, Agent } = require('undici')
|
|
17
|
-
const RuntimeApi = require('./api')
|
|
18
|
-
const { MessagePortWritable } = require('./message-port-writable')
|
|
19
|
-
const loadInterceptors = require('./interceptors')
|
|
20
|
-
let loaderPort
|
|
21
|
-
|
|
22
|
-
if (typeof register === 'function' && workerData.config.loaderFile) {
|
|
23
|
-
const { port1, port2 } = new MessageChannel()
|
|
24
|
-
register(workerData.config.loaderFile, {
|
|
25
|
-
data: { port: port2 },
|
|
26
|
-
transferList: [port2]
|
|
27
|
-
})
|
|
28
|
-
loaderPort = port1
|
|
29
|
-
} else if (globalThis.LOADER_PORT) {
|
|
30
|
-
loaderPort = globalThis.LOADER_PORT
|
|
31
|
-
delete globalThis.LOADER_PORT
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
globalThis.fetch = undici.fetch
|
|
35
|
-
|
|
36
|
-
const config = workerData.config
|
|
37
|
-
|
|
38
|
-
function createLogger (config) {
|
|
39
|
-
const loggerConfig = { ...config.server?.logger }
|
|
40
|
-
const cliStream = isatty(1) ? pretty() : pino.destination(1)
|
|
41
|
-
|
|
42
|
-
if (!config.loggingPort && !config.managementApi) {
|
|
43
|
-
return pino(loggerConfig, cliStream)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const multiStream = pino.multistream([
|
|
47
|
-
{ stream: cliStream, level: loggerConfig.level || 'info' }
|
|
48
|
-
])
|
|
49
|
-
|
|
50
|
-
if (loggerConfig.transport) {
|
|
51
|
-
const transport = pino.transport(loggerConfig.transport)
|
|
52
|
-
multiStream.add({ level: loggerConfig.level || 'info', stream: transport })
|
|
53
|
-
}
|
|
54
|
-
if (config.loggingPort) {
|
|
55
|
-
const portStream = new MessagePortWritable({
|
|
56
|
-
metadata: config.loggingMetadata,
|
|
57
|
-
port: config.loggingPort
|
|
58
|
-
})
|
|
59
|
-
multiStream.add({ level: 'trace', stream: portStream })
|
|
60
|
-
}
|
|
61
|
-
if (config.managementApi) {
|
|
62
|
-
const logsFileMb = 5
|
|
63
|
-
const logsLimitMb = config.managementApi?.logs?.maxSize || 200
|
|
64
|
-
|
|
65
|
-
let logsLimitCount = Math.ceil(logsLimitMb / logsFileMb) - 1
|
|
66
|
-
if (logsLimitCount < 1) {
|
|
67
|
-
logsLimitCount = 1
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const logsPath = join(workerData.runtimeLogsDir, 'logs')
|
|
71
|
-
const pinoRoll = pino.transport({
|
|
72
|
-
target: 'pino-roll',
|
|
73
|
-
options: {
|
|
74
|
-
file: logsPath,
|
|
75
|
-
mode: 0o600,
|
|
76
|
-
size: logsFileMb + 'm',
|
|
77
|
-
mkdir: true,
|
|
78
|
-
fsync: true,
|
|
79
|
-
limit: {
|
|
80
|
-
count: logsLimitCount
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
})
|
|
84
|
-
multiStream.add({ level: 'trace', stream: pinoRoll })
|
|
85
|
-
}
|
|
86
|
-
return pino({ level: 'trace' }, multiStream)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const logger = createLogger(config)
|
|
90
|
-
if (config.server) {
|
|
91
|
-
config.server.logger = logger
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
let stop
|
|
95
|
-
|
|
96
|
-
/* c8 ignore next 4 */
|
|
97
|
-
process.on('uncaughtException', (err) => {
|
|
98
|
-
logger.error({ err }, 'runtime uncaught exception')
|
|
99
|
-
|
|
100
|
-
if (stop) {
|
|
101
|
-
stop().then(() => {
|
|
102
|
-
setImmediate(process.exit.bind(process), 1)
|
|
103
|
-
})
|
|
104
|
-
} else {
|
|
105
|
-
setImmediate(process.exit.bind(process), 1)
|
|
106
|
-
}
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
// Tested by test/cli/start.test.mjs by C8 does not see it.
|
|
110
|
-
/* c8 ignore next 4 */
|
|
111
|
-
process.on('unhandledRejection', (err) => {
|
|
112
|
-
logger.error({ err }, 'runtime unhandled rejection')
|
|
113
|
-
|
|
114
|
-
if (stop) {
|
|
115
|
-
stop().then(() => {
|
|
116
|
-
setImmediate(process.exit.bind(process), 1)
|
|
117
|
-
})
|
|
118
|
-
} else {
|
|
119
|
-
setImmediate(process.exit.bind(process), 1)
|
|
120
|
-
}
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
async function main () {
|
|
124
|
-
if (config.preload) {
|
|
125
|
-
await import(pathToFileURL(config.preload))
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const { inspectorOptions } = workerData.config
|
|
129
|
-
|
|
130
|
-
if (inspectorOptions) {
|
|
131
|
-
/* c8 ignore next 6 */
|
|
132
|
-
if (inspectorOptions.hotReloadDisabled) {
|
|
133
|
-
logger.info('debugging flags were detected. hot reloading has been disabled')
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
inspector.open(inspectorOptions.port, inspectorOptions.host, inspectorOptions.breakFirstLine)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const interceptors = {}
|
|
140
|
-
const composedInterceptors = []
|
|
141
|
-
if (config.undici?.interceptors) {
|
|
142
|
-
const _require = createRequire(join(workerData.dirname, 'package.json'))
|
|
143
|
-
for (const key of ['Agent', 'Pool', 'Client']) {
|
|
144
|
-
if (config.undici.interceptors[key]) {
|
|
145
|
-
interceptors[key] = await loadInterceptors(_require, config.undici.interceptors[key])
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (Array.isArray(config.undici.interceptors)) {
|
|
150
|
-
composedInterceptors.push(...await loadInterceptors(_require, config.undici.interceptors))
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const globalDispatcher = new Agent({
|
|
155
|
-
...config.undici,
|
|
156
|
-
interceptors
|
|
157
|
-
})
|
|
158
|
-
setGlobalDispatcher(globalDispatcher)
|
|
159
|
-
|
|
160
|
-
const runtime = new RuntimeApi(workerData.config, logger, loaderPort, composedInterceptors)
|
|
161
|
-
runtime.startListening(parentPort)
|
|
162
|
-
|
|
163
|
-
parentPort.postMessage('plt:init')
|
|
164
|
-
|
|
165
|
-
let stopping = false
|
|
166
|
-
|
|
167
|
-
stop = async function () {
|
|
168
|
-
if (stopping) {
|
|
169
|
-
return
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
stopping = true
|
|
173
|
-
try {
|
|
174
|
-
await runtime.stopServices()
|
|
175
|
-
} catch (err) {
|
|
176
|
-
logger.error({ err }, 'error while stopping services')
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// No need to catch this because there is the unhadledRejection handler on top.
|
|
182
|
-
main()
|
|
File without changes
|