@platformatic/runtime 2.72.0 → 3.0.0-alpha.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/config.d.ts +1 -1
- package/index.d.ts +51 -23
- package/index.js +99 -17
- package/lib/config.js +159 -218
- package/lib/errors.js +150 -108
- package/lib/{generator/runtime-generator.js → generator.js} +37 -33
- package/lib/logger.js +2 -2
- package/lib/management-api.js +2 -2
- package/lib/prom-server.js +3 -7
- package/lib/runtime.js +209 -125
- package/lib/schema.js +1 -0
- package/lib/upgrade.js +6 -4
- package/lib/utils.js +1 -42
- package/lib/worker/app.js +39 -71
- package/lib/worker/itc.js +1 -5
- package/lib/worker/main.js +1 -11
- package/lib/worker/messaging.js +2 -2
- package/package.json +16 -23
- package/schema.json +2 -1
- package/help/compile.txt +0 -8
- package/help/help.txt +0 -5
- package/help/start.txt +0 -21
- package/index.test-d.ts +0 -41
- package/lib/build-server.js +0 -67
- package/lib/compile.js +0 -108
- package/lib/generator/README.md +0 -32
- package/lib/generator/errors.js +0 -10
- package/lib/generator/runtime-generator.d.ts +0 -37
- package/lib/start.js +0 -211
- package/lib/worker/default-stackable.js +0 -33
- package/lib/worker/shared-context.js +0 -26
- package/runtime.mjs +0 -54
package/lib/schema.js
CHANGED
|
@@ -21,6 +21,7 @@ schemaComponents.runtimeProperties.logger = runtimeLogger
|
|
|
21
21
|
const platformaticRuntimeSchema = {
|
|
22
22
|
$id: `https://schemas.platformatic.dev/@platformatic/runtime/${pkg.version}.json`,
|
|
23
23
|
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
24
|
+
title: 'Platformatic Runtime Config',
|
|
24
25
|
type: 'object',
|
|
25
26
|
properties: schemaComponents.runtimeProperties,
|
|
26
27
|
anyOf: [{ required: ['autoload'] }, { required: ['services'] }, { required: ['web'] }],
|
package/lib/upgrade.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const { abstractLogger } = require('@platformatic/utils')
|
|
3
4
|
const { join } = require('node:path')
|
|
5
|
+
const { semgrator } = require('semgrator')
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
const { semgrator } = await import('semgrator')
|
|
7
|
-
|
|
7
|
+
async function upgrade (logger, config, version) {
|
|
8
8
|
const iterator = semgrator({
|
|
9
9
|
version,
|
|
10
10
|
path: join(__dirname, 'versions'),
|
|
11
11
|
input: config,
|
|
12
|
-
logger:
|
|
12
|
+
logger: logger?.child({ name: '@platformatic/runtime' }) ?? abstractLogger
|
|
13
13
|
})
|
|
14
14
|
|
|
15
15
|
let result
|
|
@@ -20,3 +20,5 @@ module.exports = async function upgrade (config, version) {
|
|
|
20
20
|
|
|
21
21
|
return result
|
|
22
22
|
}
|
|
23
|
+
|
|
24
|
+
module.exports = { upgrade }
|
package/lib/utils.js
CHANGED
|
@@ -4,14 +4,6 @@ const { createHash } = require('node:crypto')
|
|
|
4
4
|
const { tmpdir } = require('node:os')
|
|
5
5
|
const { join } = require('node:path')
|
|
6
6
|
|
|
7
|
-
const {
|
|
8
|
-
Store,
|
|
9
|
-
loadConfig: pltConfigLoadConfig,
|
|
10
|
-
loadEmptyConfig: pltConfigLoadEmptyConfig
|
|
11
|
-
} = require('@platformatic/config')
|
|
12
|
-
|
|
13
|
-
const { platformaticRuntime } = require('./config')
|
|
14
|
-
|
|
15
7
|
function getArrayDifference (a, b) {
|
|
16
8
|
return a.filter(element => {
|
|
17
9
|
return !b.includes(element)
|
|
@@ -33,42 +25,9 @@ function getRuntimeLogsDir (runtimeDir, runtimePID) {
|
|
|
33
25
|
return join(runtimeTmpDir, runtimePID.toString(), 'logs')
|
|
34
26
|
}
|
|
35
27
|
|
|
36
|
-
async function loadConfig (minimistConfig, args, overrides, replaceEnv = true) {
|
|
37
|
-
const { default: platformaticBasic } = await import('@platformatic/basic')
|
|
38
|
-
const store = new Store()
|
|
39
|
-
store.add(platformaticRuntime)
|
|
40
|
-
|
|
41
|
-
const id = platformaticRuntime.schema.$id.replace('@platformatic/runtime', 'wattpm')
|
|
42
|
-
const schema = {
|
|
43
|
-
...platformaticRuntime.schema,
|
|
44
|
-
$id: id
|
|
45
|
-
}
|
|
46
|
-
const configManagerConfig = {
|
|
47
|
-
...platformaticRuntime.configManagerConfig,
|
|
48
|
-
schema
|
|
49
|
-
}
|
|
50
|
-
const wattpm = {
|
|
51
|
-
...platformaticRuntime,
|
|
52
|
-
schema,
|
|
53
|
-
configManagerConfig
|
|
54
|
-
}
|
|
55
|
-
store.add(wattpm)
|
|
56
|
-
store.add(platformaticBasic)
|
|
57
|
-
|
|
58
|
-
return pltConfigLoadConfig(minimistConfig, args, store, overrides, replaceEnv)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async function loadEmptyConfig (path, overrides, replaceEnv = true) {
|
|
62
|
-
const { default: platformaticBasic } = await import('@platformatic/basic')
|
|
63
|
-
|
|
64
|
-
return pltConfigLoadEmptyConfig(path, platformaticBasic, overrides, replaceEnv)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
28
|
module.exports = {
|
|
68
29
|
getArrayDifference,
|
|
69
30
|
getRuntimeLogsDir,
|
|
70
31
|
getRuntimeTmpDir,
|
|
71
|
-
getServiceUrl
|
|
72
|
-
loadConfig,
|
|
73
|
-
loadEmptyConfig
|
|
32
|
+
getServiceUrl
|
|
74
33
|
}
|
package/lib/worker/app.js
CHANGED
|
@@ -7,14 +7,27 @@ const {
|
|
|
7
7
|
performance: { eventLoopUtilization }
|
|
8
8
|
} = require('node:perf_hooks')
|
|
9
9
|
const { workerData } = require('node:worker_threads')
|
|
10
|
-
const {
|
|
11
|
-
|
|
10
|
+
const {
|
|
11
|
+
FileWatcher,
|
|
12
|
+
listRecognizedConfigurationFiles,
|
|
13
|
+
loadConfigurationModule,
|
|
14
|
+
loadConfiguration
|
|
15
|
+
} = require('@platformatic/utils')
|
|
12
16
|
const { getGlobalDispatcher, setGlobalDispatcher } = require('undici')
|
|
13
17
|
const debounce = require('debounce')
|
|
14
18
|
|
|
15
19
|
const errors = require('../errors')
|
|
16
|
-
const
|
|
17
|
-
|
|
20
|
+
const { getServiceUrl } = require('../utils')
|
|
21
|
+
|
|
22
|
+
function fetchServiceUrl (service, key) {
|
|
23
|
+
if (service.localServiceEnvVars.has(key)) {
|
|
24
|
+
return service.localServiceEnvVars.get(key)
|
|
25
|
+
} else if (!key.endsWith('_URL') || !service.id) {
|
|
26
|
+
return null
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return getServiceUrl(service.id)
|
|
30
|
+
}
|
|
18
31
|
|
|
19
32
|
class PlatformaticApp extends EventEmitter {
|
|
20
33
|
#starting
|
|
@@ -60,7 +73,8 @@ class PlatformaticApp extends EventEmitter {
|
|
|
60
73
|
serverConfig,
|
|
61
74
|
worker: workerData?.worker,
|
|
62
75
|
hasManagementApi: !!hasManagementApi,
|
|
63
|
-
localServiceEnvVars: this.appConfig.localServiceEnvVars
|
|
76
|
+
localServiceEnvVars: this.appConfig.localServiceEnvVars,
|
|
77
|
+
fetchServiceUrl: fetchServiceUrl.bind(null, appConfig)
|
|
64
78
|
}
|
|
65
79
|
}
|
|
66
80
|
|
|
@@ -73,63 +87,45 @@ class PlatformaticApp extends EventEmitter {
|
|
|
73
87
|
async updateContext (context) {
|
|
74
88
|
this.#context = { ...this.#context, ...context }
|
|
75
89
|
if (this.stackable) {
|
|
76
|
-
this.stackable.updateContext(context)
|
|
90
|
+
await this.stackable.updateContext(context)
|
|
77
91
|
}
|
|
78
92
|
}
|
|
79
93
|
|
|
80
94
|
async getBootstrapDependencies () {
|
|
81
|
-
return this.stackable.getBootstrapDependencies()
|
|
95
|
+
return this.stackable.getBootstrapDependencies?.() ?? []
|
|
82
96
|
}
|
|
83
97
|
|
|
84
98
|
async init () {
|
|
85
99
|
try {
|
|
86
100
|
const appConfig = this.appConfig
|
|
87
|
-
|
|
101
|
+
|
|
102
|
+
if (appConfig.isProduction && !process.env.NODE_ENV) {
|
|
103
|
+
process.env.NODE_ENV = 'production'
|
|
104
|
+
}
|
|
88
105
|
|
|
89
106
|
// Before returning the base application, check if there is any file we recognize
|
|
90
107
|
// and the user just forgot to specify in the configuration.
|
|
91
108
|
if (!appConfig.config) {
|
|
92
|
-
const candidate =
|
|
109
|
+
const candidate = listRecognizedConfigurationFiles().find(f => existsSync(resolve(appConfig.path, f)))
|
|
93
110
|
|
|
94
111
|
if (candidate) {
|
|
95
112
|
appConfig.config = resolve(appConfig.path, candidate)
|
|
96
113
|
}
|
|
97
114
|
}
|
|
98
115
|
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
)
|
|
116
|
+
if (appConfig.config) {
|
|
117
|
+
// Parse the configuration file the first time to obtain the schema
|
|
118
|
+
const unvalidatedConfig = await loadConfiguration(appConfig.config, null, {
|
|
119
|
+
onMissingEnv: this.#context.fetchServiceUrl
|
|
120
|
+
})
|
|
121
|
+
const pkg = await loadConfigurationModule(appConfig.path, unvalidatedConfig)
|
|
122
|
+
this.stackable = await pkg.create(appConfig.path, appConfig.config, this.#context)
|
|
123
|
+
// We could not find a configuration file, we use the bundle @platformatic/basic with the runtime to load it
|
|
108
124
|
} else {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
['-c', appConfig.config],
|
|
112
|
-
{
|
|
113
|
-
onMissingEnv: this.#fetchServiceUrl,
|
|
114
|
-
context: appConfig
|
|
115
|
-
},
|
|
116
|
-
true
|
|
117
|
-
)
|
|
125
|
+
const pkg = await loadConfigurationModule(resolve(__dirname, '../..'), {}, '@platformatic/basic')
|
|
126
|
+
this.stackable = await pkg.create(appConfig.path, {}, this.#context)
|
|
118
127
|
}
|
|
119
128
|
|
|
120
|
-
const app = loadedConfig.app
|
|
121
|
-
|
|
122
|
-
if (appConfig.isProduction && !process.env.NODE_ENV) {
|
|
123
|
-
process.env.NODE_ENV = 'production'
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const stackable = await app.buildStackable({
|
|
127
|
-
onMissingEnv: this.#fetchServiceUrl,
|
|
128
|
-
config: this.appConfig.config,
|
|
129
|
-
context: this.#context
|
|
130
|
-
})
|
|
131
|
-
this.stackable = this.#wrapStackable(stackable)
|
|
132
|
-
|
|
133
129
|
this.#updateDispatcher()
|
|
134
130
|
} catch (err) {
|
|
135
131
|
if (err.validationErrors) {
|
|
@@ -149,13 +145,14 @@ class PlatformaticApp extends EventEmitter {
|
|
|
149
145
|
this.#starting = true
|
|
150
146
|
|
|
151
147
|
try {
|
|
152
|
-
await this.stackable.init()
|
|
148
|
+
await this.stackable.init?.()
|
|
153
149
|
} catch (err) {
|
|
154
150
|
this.#logAndExit(err)
|
|
155
151
|
}
|
|
156
152
|
|
|
157
153
|
if (this.#watch) {
|
|
158
154
|
const watchConfig = await this.stackable.getWatchConfig()
|
|
155
|
+
|
|
159
156
|
if (watchConfig.enabled !== false) {
|
|
160
157
|
/* c8 ignore next 4 */
|
|
161
158
|
this.#debouncedRestart = debounce(() => {
|
|
@@ -168,6 +165,7 @@ class PlatformaticApp extends EventEmitter {
|
|
|
168
165
|
}
|
|
169
166
|
|
|
170
167
|
const listen = !!this.appConfig.useHttp
|
|
168
|
+
|
|
171
169
|
try {
|
|
172
170
|
await this.stackable.start({ listen })
|
|
173
171
|
this.#listening = listen
|
|
@@ -207,18 +205,6 @@ class PlatformaticApp extends EventEmitter {
|
|
|
207
205
|
}
|
|
208
206
|
|
|
209
207
|
async getMetrics ({ format }) {
|
|
210
|
-
const dispatcher = getGlobalDispatcher()
|
|
211
|
-
if (globalThis.platformatic?.onHttpStatsFree && dispatcher?.stats) {
|
|
212
|
-
for (const url in dispatcher.stats) {
|
|
213
|
-
const { free, connected, pending, queued, running, size } = dispatcher.stats[url]
|
|
214
|
-
globalThis.platformatic.onHttpStatsFree(url, free || 0)
|
|
215
|
-
globalThis.platformatic.onHttpStatsConnected(url, connected || 0)
|
|
216
|
-
globalThis.platformatic.onHttpStatsPending(url, pending || 0)
|
|
217
|
-
globalThis.platformatic.onHttpStatsQueued(url, queued || 0)
|
|
218
|
-
globalThis.platformatic.onHttpStatsRunning(url, running || 0)
|
|
219
|
-
globalThis.platformatic.onHttpStatsSize(url, size || 0)
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
208
|
return this.stackable.getMetrics({ format })
|
|
223
209
|
}
|
|
224
210
|
|
|
@@ -236,16 +222,6 @@ class PlatformaticApp extends EventEmitter {
|
|
|
236
222
|
}
|
|
237
223
|
}
|
|
238
224
|
|
|
239
|
-
#fetchServiceUrl (key, { parent, context: service }) {
|
|
240
|
-
if (service.localServiceEnvVars.has(key)) {
|
|
241
|
-
return service.localServiceEnvVars.get(key)
|
|
242
|
-
} else if (!key.endsWith('_URL') || !parent.serviceId) {
|
|
243
|
-
return null
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
return getServiceUrl(parent.serviceId)
|
|
247
|
-
}
|
|
248
|
-
|
|
249
225
|
#startFileWatching (watch) {
|
|
250
226
|
if (this.#fileWatcher) {
|
|
251
227
|
return
|
|
@@ -280,14 +256,6 @@ class PlatformaticApp extends EventEmitter {
|
|
|
280
256
|
process.exit(1)
|
|
281
257
|
}
|
|
282
258
|
|
|
283
|
-
#wrapStackable (stackable) {
|
|
284
|
-
const newStackable = {}
|
|
285
|
-
for (const method of Object.keys(defaultStackable)) {
|
|
286
|
-
newStackable[method] = stackable[method] ? stackable[method].bind(stackable) : defaultStackable[method]
|
|
287
|
-
}
|
|
288
|
-
return newStackable
|
|
289
|
-
}
|
|
290
|
-
|
|
291
259
|
#updateDispatcher () {
|
|
292
260
|
const telemetryConfig = this.#context.telemetryConfig
|
|
293
261
|
const telemetryId = telemetryConfig?.serviceName
|
package/lib/worker/itc.js
CHANGED
|
@@ -56,7 +56,7 @@ async function waitEventFromITC (worker, event) {
|
|
|
56
56
|
return safeHandleInITC(worker, () => once(worker[kITC], event))
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
function setupITC (app, service, dispatcher
|
|
59
|
+
function setupITC (app, service, dispatcher) {
|
|
60
60
|
const messaging = new MessagingITC(app.appConfig.id, workerData.config)
|
|
61
61
|
|
|
62
62
|
Object.assign(globalThis.platformatic ?? {}, {
|
|
@@ -210,10 +210,6 @@ function setupITC (app, service, dispatcher, sharedContext) {
|
|
|
210
210
|
}
|
|
211
211
|
},
|
|
212
212
|
|
|
213
|
-
setSharedContext (context) {
|
|
214
|
-
sharedContext._set(context)
|
|
215
|
-
},
|
|
216
|
-
|
|
217
213
|
saveMessagingChannel (channel) {
|
|
218
214
|
messaging.addSource(channel)
|
|
219
215
|
}
|
package/lib/worker/main.js
CHANGED
|
@@ -11,7 +11,6 @@ const { ServerResponse } = require('node:http')
|
|
|
11
11
|
|
|
12
12
|
const {
|
|
13
13
|
disablePinoDirectWrite,
|
|
14
|
-
ensureFlushedWorkerStdio,
|
|
15
14
|
executeWithTimeout,
|
|
16
15
|
ensureLoggableError,
|
|
17
16
|
getPrivateSymbol,
|
|
@@ -23,7 +22,6 @@ const pino = require('pino')
|
|
|
23
22
|
const { fetch } = require('undici')
|
|
24
23
|
|
|
25
24
|
const { PlatformaticApp } = require('./app')
|
|
26
|
-
const { SharedContext } = require('./shared-context')
|
|
27
25
|
const { setupITC } = require('./itc')
|
|
28
26
|
const { setDispatcher } = require('./interceptors')
|
|
29
27
|
const { kId, kITC, kStderrMarker } = require('./symbols')
|
|
@@ -45,7 +43,6 @@ function handleUnhandled (app, type, err) {
|
|
|
45
43
|
|
|
46
44
|
function patchLogging () {
|
|
47
45
|
disablePinoDirectWrite()
|
|
48
|
-
ensureFlushedWorkerStdio()
|
|
49
46
|
|
|
50
47
|
const kFormatForStderr = getPrivateSymbol(console, 'kFormatForStderr')
|
|
51
48
|
|
|
@@ -190,15 +187,8 @@ async function main () {
|
|
|
190
187
|
}
|
|
191
188
|
}
|
|
192
189
|
|
|
193
|
-
const sharedContext = new SharedContext()
|
|
194
|
-
// Limit the amount of methods a user can call
|
|
195
|
-
globalThis.platformatic.sharedContext = {
|
|
196
|
-
get: () => sharedContext.get(),
|
|
197
|
-
update: (...args) => sharedContext.update(...args)
|
|
198
|
-
}
|
|
199
|
-
|
|
200
190
|
// Setup interaction with parent port
|
|
201
|
-
const itc = setupITC(app, service, threadDispatcher
|
|
191
|
+
const itc = setupITC(app, service, threadDispatcher)
|
|
202
192
|
globalThis[kITC] = itc
|
|
203
193
|
|
|
204
194
|
// Get the dependencies
|
package/lib/worker/messaging.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { executeWithTimeout, kTimeout } = require('@platformatic/utils')
|
|
4
4
|
const { ITC, generateResponse, sanitize } = require('@platformatic/itc')
|
|
5
5
|
const errors = require('../errors')
|
|
6
6
|
const { RoundRobinMap } = require('./round-robin-map')
|
|
@@ -112,7 +112,7 @@ class MessagingITC extends ITC {
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
_createClosePromise () {
|
|
115
|
-
const { promise, resolve, reject } = withResolvers()
|
|
115
|
+
const { promise, resolve, reject } = Promise.withResolvers()
|
|
116
116
|
this.#closeResolvers = { resolve, reject }
|
|
117
117
|
return promise
|
|
118
118
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/runtime",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
|
-
"bin": {
|
|
7
|
-
"plt-runtime": "./runtime.mjs"
|
|
8
|
-
},
|
|
9
6
|
"author": "Platformatic Inc. <oss@platformatic.dev> (https://platformatic.dev)",
|
|
10
7
|
"repository": {
|
|
11
8
|
"type": "git",
|
|
@@ -33,16 +30,15 @@
|
|
|
33
30
|
"neostandard": "^0.12.0",
|
|
34
31
|
"pino-abstract-transport": "^2.0.0",
|
|
35
32
|
"split2": "^4.2.0",
|
|
36
|
-
"tsd": "^0.32.0",
|
|
37
33
|
"typescript": "^5.5.4",
|
|
38
34
|
"undici-oidc-interceptor": "^0.5.0",
|
|
39
35
|
"why-is-node-running": "^2.2.2",
|
|
40
|
-
"@platformatic/composer": "
|
|
41
|
-
"@platformatic/db": "
|
|
42
|
-
"@platformatic/node": "
|
|
43
|
-
"@platformatic/service": "
|
|
44
|
-
"@platformatic/sql-graphql": "
|
|
45
|
-
"@platformatic/sql-mapper": "
|
|
36
|
+
"@platformatic/composer": "3.0.0-alpha.1",
|
|
37
|
+
"@platformatic/db": "3.0.0-alpha.1",
|
|
38
|
+
"@platformatic/node": "3.0.0-alpha.1",
|
|
39
|
+
"@platformatic/service": "3.0.0-alpha.1",
|
|
40
|
+
"@platformatic/sql-graphql": "3.0.0-alpha.1",
|
|
41
|
+
"@platformatic/sql-mapper": "3.0.0-alpha.1"
|
|
46
42
|
},
|
|
47
43
|
"dependencies": {
|
|
48
44
|
"@fastify/accepts": "^5.0.0",
|
|
@@ -57,7 +53,6 @@
|
|
|
57
53
|
"commist": "^3.2.0",
|
|
58
54
|
"cron": "^4.1.0",
|
|
59
55
|
"debounce": "^2.0.0",
|
|
60
|
-
"desm": "^1.3.1",
|
|
61
56
|
"dotenv": "^16.4.5",
|
|
62
57
|
"dotenv-tool": "^0.1.1",
|
|
63
58
|
"es-main": "^1.3.0",
|
|
@@ -76,24 +71,22 @@
|
|
|
76
71
|
"undici": "^7.0.0",
|
|
77
72
|
"undici-thread-interceptor": "^0.14.0",
|
|
78
73
|
"ws": "^8.16.0",
|
|
79
|
-
"@platformatic/
|
|
80
|
-
"@platformatic/
|
|
81
|
-
"@platformatic/
|
|
82
|
-
"@platformatic/itc": "
|
|
83
|
-
"@platformatic/telemetry": "
|
|
84
|
-
"@platformatic/ts-compiler": "
|
|
85
|
-
"@platformatic/utils": "
|
|
86
|
-
"@platformatic/generators": "2.72.0"
|
|
74
|
+
"@platformatic/metrics": "3.0.0-alpha.1",
|
|
75
|
+
"@platformatic/basic": "3.0.0-alpha.1",
|
|
76
|
+
"@platformatic/generators": "3.0.0-alpha.1",
|
|
77
|
+
"@platformatic/itc": "3.0.0-alpha.1",
|
|
78
|
+
"@platformatic/telemetry": "3.0.0-alpha.1",
|
|
79
|
+
"@platformatic/ts-compiler": "3.0.0-alpha.1",
|
|
80
|
+
"@platformatic/utils": "3.0.0-alpha.1"
|
|
87
81
|
},
|
|
88
82
|
"scripts": {
|
|
89
|
-
"test": "pnpm run lint && borp --concurrency=1 --timeout=1200000
|
|
83
|
+
"test": "pnpm run lint && borp --concurrency=1 --timeout=1200000",
|
|
90
84
|
"test:main": "borp --concurrency=1 --timeout=1200000 test/*.test.js test/*.test.mjs test/versions/*.test.js test/versions/*.test.mjs",
|
|
91
85
|
"test:api": "borp --concurrency=1 --timeout=1200000 test/api/*.test.js test/api/*.test.mjs test/management-api/*.test.js test/management-api/*.test.mjs",
|
|
92
86
|
"test:cli": "borp --concurrency=1 --timeout=1200000 test/cli/*.test.js test/cli/*.test.mjs test/cli/**/*.test.js test/cli/**/*.test.mjs",
|
|
93
87
|
"test:start": "borp --concurrency=1 --timeout=1200000 test/start/*.test.js test/start/*.test.mjs",
|
|
94
88
|
"test:multiple-workers": "borp --concurrency=1 --timeout=1200000 test/multiple-workers/*.test.js test/multiple-workers/*.test.mjs",
|
|
95
|
-
"
|
|
96
|
-
"coverage": "pnpm run lint && borp -X fixtures -X test -C --concurrency=1 --timeout=1200000 && tsd",
|
|
89
|
+
"coverage": "pnpm run lint && borp -X fixtures -X test -C --concurrency=1 --timeout=1200000 ",
|
|
97
90
|
"gen-schema": "node lib/schema.js > schema.json",
|
|
98
91
|
"gen-types": "json2ts > config.d.ts < schema.json",
|
|
99
92
|
"build": "pnpm run gen-schema && pnpm run gen-types",
|
package/schema.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$id": "https://schemas.platformatic.dev/@platformatic/runtime/
|
|
2
|
+
"$id": "https://schemas.platformatic.dev/@platformatic/runtime/3.0.0-alpha.1.json",
|
|
3
3
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
4
|
+
"title": "Platformatic Runtime Config",
|
|
4
5
|
"type": "object",
|
|
5
6
|
"properties": {
|
|
6
7
|
"$schema": {
|
package/help/compile.txt
DELETED
package/help/help.txt
DELETED
package/help/start.txt
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
Start the Platformatic Runtime with the following command:
|
|
2
|
-
|
|
3
|
-
```bash
|
|
4
|
-
$ platformatic runtime start
|
|
5
|
-
```
|
|
6
|
-
|
|
7
|
-
You can also specify a custom routes file, for example:
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
$ platformatic runtime start routes.js
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
Where `routes.js` is:
|
|
14
|
-
|
|
15
|
-
```javascript
|
|
16
|
-
module.exports = async function (app) {
|
|
17
|
-
app.get('/hello', async () => {
|
|
18
|
-
return { hello: 'hello123' }
|
|
19
|
-
})
|
|
20
|
-
}
|
|
21
|
-
```
|
package/index.test-d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { expectError, expectType } from 'tsd'
|
|
2
|
-
import { LightMyRequestResponse } from 'fastify'
|
|
3
|
-
import { pltRuntimeBuildServer, errors } from '.'
|
|
4
|
-
import { FastifyError } from '@fastify/error'
|
|
5
|
-
|
|
6
|
-
const server: pltRuntimeBuildServer = {
|
|
7
|
-
address: 'localhost',
|
|
8
|
-
port: 3000,
|
|
9
|
-
restart: async () => { },
|
|
10
|
-
stop: async () => { },
|
|
11
|
-
inject: async () => ({} as LightMyRequestResponse),
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
expectType<pltRuntimeBuildServer>(server)
|
|
15
|
-
expectError<pltRuntimeBuildServer>({ ...server, address: 42 })
|
|
16
|
-
expectError<pltRuntimeBuildServer>({ ...server, port: 'WRONG' })
|
|
17
|
-
expectError<pltRuntimeBuildServer>({ ...server, restart: 'WRONG' })
|
|
18
|
-
expectError<pltRuntimeBuildServer>({ ...server, stop: 'WRONG' })
|
|
19
|
-
expectError<pltRuntimeBuildServer>({ ...server, inject: 'WRONG' })
|
|
20
|
-
|
|
21
|
-
// Errors
|
|
22
|
-
type ErrorWithNoParams = () => FastifyError
|
|
23
|
-
type ErrorWithOneParam = (param: string) => FastifyError
|
|
24
|
-
type ErrorWithTwoParams = (param1: string, param2: string) => FastifyError
|
|
25
|
-
|
|
26
|
-
expectType<ErrorWithNoParams>(errors.RuntimeExitedError)
|
|
27
|
-
expectType<ErrorWithOneParam>(errors.UnknownRuntimeAPICommandError)
|
|
28
|
-
expectType<ErrorWithOneParam>(errors.ServiceNotFoundError)
|
|
29
|
-
expectType<ErrorWithOneParam>(errors.ServiceNotStartedError)
|
|
30
|
-
expectType<ErrorWithTwoParams>(errors.FailedToRetrieveOpenAPISchemaError)
|
|
31
|
-
expectType<ErrorWithNoParams>(errors.ApplicationAlreadyStartedError)
|
|
32
|
-
expectType<ErrorWithNoParams>(errors.ApplicationNotStartedError)
|
|
33
|
-
expectType<ErrorWithNoParams>(errors.ConfigPathMustBeStringError)
|
|
34
|
-
expectType<ErrorWithOneParam>(errors.NoConfigFileFoundError)
|
|
35
|
-
expectType<ErrorWithOneParam>(errors.InvalidEntrypointError)
|
|
36
|
-
expectType<ErrorWithOneParam>(errors.MissingDependencyError)
|
|
37
|
-
expectType<ErrorWithNoParams>(errors.InspectAndInspectBrkError)
|
|
38
|
-
expectType<ErrorWithNoParams>(errors.InspectorPortError)
|
|
39
|
-
expectType<ErrorWithNoParams>(errors.InspectorHostError)
|
|
40
|
-
expectType<ErrorWithOneParam>(errors.CannotMapSpecifierToAbsolutePathError)
|
|
41
|
-
expectType<ErrorWithNoParams>(errors.NodeInspectorFlagsNotSupportedError)
|
package/lib/build-server.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { join } = require('node:path')
|
|
4
|
-
const { createRequire } = require('node:module')
|
|
5
|
-
const ConfigManager = require('@platformatic/config')
|
|
6
|
-
const { platformaticRuntime } = require('./config')
|
|
7
|
-
const { buildRuntime } = require('./start')
|
|
8
|
-
const { loadConfig } = require('./utils')
|
|
9
|
-
|
|
10
|
-
async function buildServerRuntime (options = {}, args = undefined) {
|
|
11
|
-
const { serviceMap } = options
|
|
12
|
-
|
|
13
|
-
if (!options.configManager) {
|
|
14
|
-
delete options.serviceMap
|
|
15
|
-
|
|
16
|
-
// Instantiate a new config manager from the current options.
|
|
17
|
-
const cm = new ConfigManager({
|
|
18
|
-
...platformaticRuntime.configManagerConfig,
|
|
19
|
-
source: options
|
|
20
|
-
})
|
|
21
|
-
await cm.parseAndValidate()
|
|
22
|
-
|
|
23
|
-
cm.current.serviceMap = serviceMap
|
|
24
|
-
|
|
25
|
-
if (typeof options === 'string') {
|
|
26
|
-
options = { configManager: cm }
|
|
27
|
-
} else {
|
|
28
|
-
options.configManager = cm
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (args) {
|
|
33
|
-
options.configManager.args = args
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return buildRuntime(options.configManager, options.env)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async function buildServer (options, args) {
|
|
40
|
-
if (typeof options === 'string') {
|
|
41
|
-
const config = await loadConfig({}, ['-c', options])
|
|
42
|
-
options = config.configManager.current
|
|
43
|
-
options.configManager = config.configManager
|
|
44
|
-
options.app = config.app
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const app = options.app
|
|
48
|
-
|
|
49
|
-
delete options.app
|
|
50
|
-
|
|
51
|
-
if (app === platformaticRuntime || !app) {
|
|
52
|
-
return buildServerRuntime(options, args)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (app.buildServer) {
|
|
56
|
-
return app.buildServer(options)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// App is a stackable. Hopefully we have `@platformatic/service` available.
|
|
60
|
-
const projectRoot = join(options.configManager.dirname, 'package.json')
|
|
61
|
-
const require = createRequire(projectRoot)
|
|
62
|
-
const { buildServer } = require('@platformatic/service')
|
|
63
|
-
|
|
64
|
-
return buildServer(options, app)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
module.exports = { buildServer }
|