@platformatic/runtime 3.4.1 → 3.5.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/README.md +1 -1
- package/config.d.ts +224 -77
- package/eslint.config.js +3 -5
- package/index.d.ts +73 -24
- package/index.js +173 -29
- package/lib/config.js +279 -197
- package/lib/errors.js +126 -34
- package/lib/generator.js +640 -0
- package/lib/logger.js +43 -41
- package/lib/management-api.js +109 -118
- package/lib/prom-server.js +202 -16
- package/lib/runtime.js +1963 -585
- package/lib/scheduler.js +119 -0
- package/lib/schema.js +22 -234
- package/lib/shared-http-cache.js +43 -0
- package/lib/upgrade.js +6 -8
- package/lib/utils.js +6 -61
- package/lib/version.js +7 -0
- package/lib/versions/v1.36.0.js +2 -4
- package/lib/versions/v1.5.0.js +2 -4
- package/lib/versions/v2.0.0.js +3 -5
- package/lib/versions/v3.0.0.js +16 -0
- package/lib/worker/controller.js +302 -0
- package/lib/worker/http-cache.js +171 -0
- package/lib/worker/interceptors.js +190 -10
- package/lib/worker/itc.js +146 -59
- package/lib/worker/main.js +220 -81
- package/lib/worker/messaging.js +182 -0
- package/lib/worker/round-robin-map.js +62 -0
- package/lib/worker/shared-context.js +22 -0
- package/lib/worker/symbols.js +14 -5
- package/package.json +47 -38
- package/schema.json +1383 -55
- 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 -69
- package/lib/compile.js +0 -98
- package/lib/dependencies.js +0 -59
- 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/generator/runtime-generator.js +0 -498
- package/lib/start.js +0 -190
- package/lib/worker/app.js +0 -278
- package/lib/worker/default-stackable.js +0 -33
- package/lib/worker/metrics.js +0 -122
- package/runtime.mjs +0 -54
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,69 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { createRequire } = require('node:module')
|
|
4
|
-
const { join } = require('node:path')
|
|
5
|
-
|
|
6
|
-
const ConfigManager = require('@platformatic/config')
|
|
7
|
-
|
|
8
|
-
const { platformaticRuntime } = require('./config')
|
|
9
|
-
const { buildRuntime } = require('./start')
|
|
10
|
-
const { loadConfig } = require('./utils')
|
|
11
|
-
|
|
12
|
-
async function buildServerRuntime (options = {}, args = undefined) {
|
|
13
|
-
const { serviceMap } = options
|
|
14
|
-
|
|
15
|
-
if (!options.configManager) {
|
|
16
|
-
delete options.serviceMap
|
|
17
|
-
|
|
18
|
-
// Instantiate a new config manager from the current options.
|
|
19
|
-
const cm = new ConfigManager({
|
|
20
|
-
...platformaticRuntime.configManagerConfig,
|
|
21
|
-
source: options
|
|
22
|
-
})
|
|
23
|
-
await cm.parseAndValidate()
|
|
24
|
-
|
|
25
|
-
cm.current.serviceMap = serviceMap
|
|
26
|
-
|
|
27
|
-
if (typeof options === 'string') {
|
|
28
|
-
options = { configManager: cm }
|
|
29
|
-
} else {
|
|
30
|
-
options.configManager = cm
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (args) {
|
|
35
|
-
options.configManager.args = args
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return buildRuntime(options.configManager, options.env)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async function buildServer (options, args) {
|
|
42
|
-
if (typeof options === 'string') {
|
|
43
|
-
const config = await loadConfig({}, ['-c', options])
|
|
44
|
-
options = config.configManager.current
|
|
45
|
-
options.configManager = config.configManager
|
|
46
|
-
options.app = config.app
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const app = options.app
|
|
50
|
-
|
|
51
|
-
delete options.app
|
|
52
|
-
|
|
53
|
-
if (app === platformaticRuntime || !app) {
|
|
54
|
-
return buildServerRuntime(options, args)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (app.buildServer) {
|
|
58
|
-
return app.buildServer(options)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// App is a stackable. Hopefully we have `@platformatic/service` available.
|
|
62
|
-
const projectRoot = join(options.configManager.dirname, 'package.json')
|
|
63
|
-
const require = createRequire(projectRoot)
|
|
64
|
-
const { buildServer } = require('@platformatic/service')
|
|
65
|
-
|
|
66
|
-
return buildServer(options, app)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
module.exports = { buildServer }
|
package/lib/compile.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { createRequire } = require('node:module')
|
|
4
|
-
const { dirname, join } = require('node:path')
|
|
5
|
-
const { isatty } = require('node:tty')
|
|
6
|
-
const { pathToFileURL } = require('node:url')
|
|
7
|
-
|
|
8
|
-
const tsCompiler = require('@platformatic/ts-compiler')
|
|
9
|
-
const pino = require('pino')
|
|
10
|
-
const pretty = require('pino-pretty')
|
|
11
|
-
|
|
12
|
-
const { loadConfig } = require('./utils')
|
|
13
|
-
|
|
14
|
-
async function compile (argv, logger) {
|
|
15
|
-
const { configManager, configType, app } = await loadConfig({}, argv, {
|
|
16
|
-
watch: false,
|
|
17
|
-
}, false)
|
|
18
|
-
/* c8 ignore next */
|
|
19
|
-
if (!logger) {
|
|
20
|
-
let stream
|
|
21
|
-
|
|
22
|
-
if (isatty(process.stdout.fd)) {
|
|
23
|
-
stream = pretty({
|
|
24
|
-
translateTime: 'SYS:HH:MM:ss',
|
|
25
|
-
ignore: 'hostname,pid',
|
|
26
|
-
})
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
logger = pino(stream)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
let compiled = false
|
|
33
|
-
const compileOptions = {
|
|
34
|
-
clean: argv.includes('--clean'),
|
|
35
|
-
}
|
|
36
|
-
if (configType === 'runtime') {
|
|
37
|
-
for (const service of configManager.current.services) {
|
|
38
|
-
const childLogger = logger.child({ name: service.id })
|
|
39
|
-
|
|
40
|
-
const serviceConfigPath = service.config
|
|
41
|
-
const { configManager, app } = await loadConfig({}, ['-c', serviceConfigPath], {
|
|
42
|
-
onMissingEnv (key) {
|
|
43
|
-
return service.localServiceEnvVars.get(key)
|
|
44
|
-
},
|
|
45
|
-
watch: false,
|
|
46
|
-
}, false)
|
|
47
|
-
|
|
48
|
-
const tsOptions = await extract(configManager, app)
|
|
49
|
-
|
|
50
|
-
if (tsOptions) {
|
|
51
|
-
const serviceWasCompiled = await tsCompiler.compile({
|
|
52
|
-
...compileOptions,
|
|
53
|
-
...tsOptions,
|
|
54
|
-
cwd: service.path,
|
|
55
|
-
logger: childLogger,
|
|
56
|
-
})
|
|
57
|
-
compiled ||= serviceWasCompiled
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
} else {
|
|
61
|
-
const tsOptions = await extract(configManager, app)
|
|
62
|
-
if (tsOptions) {
|
|
63
|
-
compiled = await tsCompiler.compile({
|
|
64
|
-
...compileOptions,
|
|
65
|
-
...tsOptions,
|
|
66
|
-
cwd: dirname(configManager.fullPath),
|
|
67
|
-
logger,
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return compiled
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async function extract (configManager, app) {
|
|
76
|
-
let extractTypeScriptCompileOptionsFromConfig = app.extractTypeScriptCompileOptionsFromConfig
|
|
77
|
-
|
|
78
|
-
if (!extractTypeScriptCompileOptionsFromConfig) {
|
|
79
|
-
// This is a bit of a hack, but it is needed to avoid a circular dependency
|
|
80
|
-
// it also allow for customizations if needed
|
|
81
|
-
const _require = createRequire(join(configManager.dirname, 'package.json'))
|
|
82
|
-
const toLoad = _require.resolve('@platformatic/service')
|
|
83
|
-
try {
|
|
84
|
-
extractTypeScriptCompileOptionsFromConfig = (await import(pathToFileURL(toLoad))).extractTypeScriptCompileOptionsFromConfig
|
|
85
|
-
} catch {
|
|
86
|
-
}
|
|
87
|
-
// If we can't load `@platformatic/service` we just return null
|
|
88
|
-
// and we won't be compiling typescript
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (!extractTypeScriptCompileOptionsFromConfig) {
|
|
92
|
-
return null
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return extractTypeScriptCompileOptionsFromConfig(configManager.current)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
module.exports.compile = compile
|
package/lib/dependencies.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const Topo = require('@hapi/topo')
|
|
4
|
-
const { closest } = require('fastest-levenshtein')
|
|
5
|
-
|
|
6
|
-
const errors = require('./errors')
|
|
7
|
-
|
|
8
|
-
function missingDependencyErrorMessage (clientName, service, services) {
|
|
9
|
-
const closestName = closest(clientName, [...services.keys()])
|
|
10
|
-
let errorMsg = `service '${service.id}' has unknown dependency: '${clientName}'.`
|
|
11
|
-
if (closestName) {
|
|
12
|
-
errorMsg += ` Did you mean '${closestName}'?`
|
|
13
|
-
}
|
|
14
|
-
return errorMsg
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function checkDependencies (services) {
|
|
18
|
-
const allServices = new Set(services.map(s => s.id))
|
|
19
|
-
|
|
20
|
-
for (const service of services) {
|
|
21
|
-
for (const dependency of service.dependencies) {
|
|
22
|
-
if (dependency.local && !allServices.has(dependency.id)) {
|
|
23
|
-
throw new errors.MissingDependencyError(
|
|
24
|
-
missingDependencyErrorMessage(dependency.id, service, services)
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function topologicalSort (services, config) {
|
|
32
|
-
const topo = new Topo.Sorter()
|
|
33
|
-
|
|
34
|
-
for (const service of config.services) {
|
|
35
|
-
const localDependencyIds = Array.from(service.dependencies)
|
|
36
|
-
.filter(dep => dep.local)
|
|
37
|
-
.map(dep => dep.id)
|
|
38
|
-
|
|
39
|
-
topo.add(service, {
|
|
40
|
-
group: service.id,
|
|
41
|
-
after: localDependencyIds,
|
|
42
|
-
manual: true,
|
|
43
|
-
})
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
config.services = topo.sort()
|
|
47
|
-
|
|
48
|
-
return new Map(Array.from(services.entries()).sort((a, b) => {
|
|
49
|
-
if (a[0] === b[0]) {
|
|
50
|
-
return 0
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const aIndex = config.services.findIndex(s => s.id === a[0])
|
|
54
|
-
const bIndex = config.services.findIndex(s => s.id === b[0])
|
|
55
|
-
return aIndex - bIndex
|
|
56
|
-
}))
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
module.exports = { checkDependencies, topologicalSort }
|
package/lib/generator/README.md
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# Platformatic Runtime API
|
|
2
|
-
|
|
3
|
-
This is a generated [Platformatic Runtime](https://docs.platformatic.dev/docs/runtime/overview) application.
|
|
4
|
-
|
|
5
|
-
## Requirements
|
|
6
|
-
|
|
7
|
-
Platformatic supports macOS, Linux and Windows ([WSL](https://docs.microsoft.com/windows/wsl/) recommended).
|
|
8
|
-
You'll need to have [Node.js](https://nodejs.org/) >= v18.8.0 or >= v20.6.0
|
|
9
|
-
|
|
10
|
-
## Setup
|
|
11
|
-
|
|
12
|
-
1. Install dependencies:
|
|
13
|
-
|
|
14
|
-
```bash
|
|
15
|
-
npm install
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Usage
|
|
19
|
-
|
|
20
|
-
Run the API with:
|
|
21
|
-
|
|
22
|
-
```bash
|
|
23
|
-
npm start
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## Adding a Service
|
|
27
|
-
|
|
28
|
-
Adding a new service to this project is as simple as running `create-platformatic` again, like so:
|
|
29
|
-
|
|
30
|
-
```
|
|
31
|
-
npx create-platformatic
|
|
32
|
-
```
|
package/lib/generator/errors.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const createError = require('@fastify/error')
|
|
4
|
-
|
|
5
|
-
const ERROR_PREFIX = 'PLT_RUNTIME_GEN'
|
|
6
|
-
|
|
7
|
-
module.exports = {
|
|
8
|
-
NoServiceNamedError: createError(`${ERROR_PREFIX}_NO_SERVICE_FOUND`, 'No service named \'%s\' has been added to this runtime.'),
|
|
9
|
-
NoEntryPointError: createError(`${ERROR_PREFIX}_NO_ENTRYPOINT`, 'No entrypoint had been defined.'),
|
|
10
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { BaseGenerator } from '@platformatic/generators'
|
|
2
|
-
import { FileGenerator } from '@platformatic/generators/lib/file-generator'
|
|
3
|
-
|
|
4
|
-
type Service = {
|
|
5
|
-
config: FileGenerator.FileGenerator | BaseGenerator.BaseGenerator
|
|
6
|
-
}
|
|
7
|
-
type GeneratorMetadata = {
|
|
8
|
-
targetDirectory: string
|
|
9
|
-
env: KeyValue
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
type KeyValue = {
|
|
13
|
-
[key: string]: string
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
type RuntimeGeneratorOptions = BaseGenerator.BaseGeneratorOptions & {
|
|
17
|
-
logLevel: string
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export namespace RuntimeGenerator {
|
|
21
|
-
export class RuntimeGenerator extends BaseGenerator.BaseGenerator {
|
|
22
|
-
services: Service[]
|
|
23
|
-
entryPoint: Service
|
|
24
|
-
constructor (opts?: RuntimeGeneratorOptions)
|
|
25
|
-
|
|
26
|
-
addService (service: Service, name: string): Promise<void>
|
|
27
|
-
|
|
28
|
-
setEntryPoint (entryPoint: string): void
|
|
29
|
-
|
|
30
|
-
setServicesDirectory (): void
|
|
31
|
-
|
|
32
|
-
setServicesConfig (configToOverride: object): void
|
|
33
|
-
|
|
34
|
-
getRuntimeEnv (): KeyValue
|
|
35
|
-
writeServicesFiles (): Promise<GeneratorMetadata>
|
|
36
|
-
}
|
|
37
|
-
}
|