@platformatic/runtime 2.0.0-alpha.1 → 2.0.0-alpha.3
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/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/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 +885 -0
- package/lib/schema.js +79 -76
- package/lib/start.js +35 -113
- package/lib/streams/message-port-writable.js +44 -0
- package/lib/streams/pino-writable.js +30 -0
- 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 +224 -0
- package/lib/worker/default-stackable.js +27 -0
- package/lib/worker/itc.js +128 -0
- package/lib/worker/main.js +120 -0
- package/lib/worker/symbols.js +7 -0
- package/package.json +23 -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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Movie } from './Movie'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
|
|
3
|
+
interface EntityTypes {
|
|
4
|
+
Movie: Movie
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export { EntityTypes, Movie }
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { FastifyPluginAsync } from 'fastify'
|
|
2
2
|
|
|
3
3
|
interface GetMoviesRequest {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
limit?: number;
|
|
5
|
+
offset?: number;
|
|
6
|
+
totalCount?: boolean;
|
|
7
|
+
fields?: Array<string>;
|
|
8
8
|
'where.id.eq'?: number;
|
|
9
9
|
'where.id.neq'?: number;
|
|
10
10
|
'where.id.gt'?: number;
|
|
@@ -29,22 +29,22 @@ interface GetMoviesRequest {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
interface GetMoviesResponseOK {
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
id?: number;
|
|
33
|
+
title: string;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
interface CreateMovieRequest {
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
id?: number;
|
|
38
|
+
title: string;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
interface CreateMovieResponseOK {
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
id?: number;
|
|
43
|
+
title: string;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
interface UpdateMoviesRequest {
|
|
47
|
-
|
|
47
|
+
fields?: Array<string>;
|
|
48
48
|
'where.id.eq'?: number;
|
|
49
49
|
'where.id.neq'?: number;
|
|
50
50
|
'where.id.gt'?: number;
|
|
@@ -64,44 +64,44 @@ interface UpdateMoviesRequest {
|
|
|
64
64
|
'where.title.in'?: string;
|
|
65
65
|
'where.title.nin'?: string;
|
|
66
66
|
'where.or'?: Array<string>;
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
id?: number;
|
|
68
|
+
title: string;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
interface UpdateMoviesResponseOK {
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
id?: number;
|
|
73
|
+
title: string;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
interface GetMovieByIdRequest {
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
fields?: Array<string>;
|
|
78
|
+
id: number;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
interface GetMovieByIdResponseOK {
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
id?: number;
|
|
83
|
+
title: string;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
interface UpdateMovieRequest {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
fields?: Array<string>;
|
|
88
|
+
id: number;
|
|
89
|
+
title: string;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
interface UpdateMovieResponseOK {
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
id?: number;
|
|
94
|
+
title: string;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
interface DeleteMoviesRequest {
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
fields?: Array<string>;
|
|
99
|
+
id: number;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
interface DeleteMoviesResponseOK {
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
id?: number;
|
|
104
|
+
title: string;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
interface Client {
|
|
@@ -117,15 +117,15 @@ type ClientPlugin = FastifyPluginAsync<NonNullable<client.ClientOptions>>
|
|
|
117
117
|
|
|
118
118
|
declare module 'fastify' {
|
|
119
119
|
interface ConfigureClient {
|
|
120
|
-
getHeaders(req: FastifyRequest, reply: FastifyReply): Promise<Record<string,string>>;
|
|
120
|
+
getHeaders(req: FastifyRequest, reply: FastifyReply): Promise<Record<string, string>>;
|
|
121
121
|
}
|
|
122
122
|
interface FastifyInstance {
|
|
123
|
-
|
|
123
|
+
client: Client;
|
|
124
124
|
configureClient(opts: ConfigureClient): unknown
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
interface FastifyRequest {
|
|
128
|
-
|
|
128
|
+
client: Client;
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
|
|
@@ -133,9 +133,9 @@ declare namespace client {
|
|
|
133
133
|
export interface ClientOptions {
|
|
134
134
|
url: string
|
|
135
135
|
}
|
|
136
|
-
export const client: ClientPlugin
|
|
137
|
-
export { client as default }
|
|
136
|
+
export const client: ClientPlugin
|
|
137
|
+
export { client as default }
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
declare function client(...params: Parameters<ClientPlugin>): ReturnType<ClientPlugin
|
|
141
|
-
export = client
|
|
140
|
+
declare function client (...params: Parameters<ClientPlugin>): ReturnType<ClientPlugin>
|
|
141
|
+
export = client
|
package/index.d.ts
CHANGED
|
@@ -11,13 +11,13 @@ export type pltRuntimeBuildServer = {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
declare module '@platformatic/runtime' {
|
|
14
|
-
export function buildServer(opts: object): Promise<pltRuntimeBuildServer>
|
|
15
|
-
export function start(args: object): Promise<object>
|
|
16
|
-
export function startCommand(args: object): Promise<void>
|
|
17
|
-
export function loadConfig(minimistConfig: object, args: object, store: object, overrides: object, replaceEnv: boolean): void
|
|
18
|
-
export function compile(argv: string[], logger: BaseLogger): void
|
|
19
|
-
export function platformaticRuntime(): Promise<void>
|
|
20
|
-
export function wrapConfigInRuntimeConfig(args: object): object
|
|
14
|
+
export function buildServer (opts: object): Promise<pltRuntimeBuildServer>
|
|
15
|
+
export function start (args: object): Promise<object>
|
|
16
|
+
export function startCommand (args: object): Promise<void>
|
|
17
|
+
export function loadConfig (minimistConfig: object, args: object, store: object, overrides: object, replaceEnv: boolean): void
|
|
18
|
+
export function compile (argv: string[], logger: BaseLogger): void
|
|
19
|
+
export function platformaticRuntime (): Promise<void>
|
|
20
|
+
export function wrapConfigInRuntimeConfig (args: object): object
|
|
21
21
|
export const Generator: RuntimeGenerator.RuntimeGenerator
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -42,4 +42,3 @@ export module errors {
|
|
|
42
42
|
export const CannotMapSpecifierToAbsolutePathError: (specifier: string) => FastifyError
|
|
43
43
|
export const NodeInspectorFlagsNotSupportedError: () => FastifyError
|
|
44
44
|
}
|
|
45
|
-
|
package/index.js
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
+
|
|
2
3
|
const { buildServer } = require('./lib/build-server')
|
|
3
|
-
const { platformaticRuntime, wrapConfigInRuntimeConfig } = require('./lib/config')
|
|
4
|
-
const { start, startCommand } = require('./lib/start')
|
|
5
|
-
const RuntimeApi = require('./lib/api')
|
|
6
4
|
const { compile } = require('./lib/compile')
|
|
7
|
-
const { loadConfig } = require('./lib/load-config')
|
|
8
5
|
const errors = require('./lib/errors')
|
|
6
|
+
const { platformaticRuntime, wrapConfigInRuntimeConfig } = require('./lib/config')
|
|
9
7
|
const RuntimeGenerator = require('./lib/generator/runtime-generator')
|
|
8
|
+
const { Runtime } = require('./lib/runtime')
|
|
9
|
+
const { start, startCommand } = require('./lib/start')
|
|
10
|
+
const symbols = require('./lib/worker/symbols')
|
|
11
|
+
const { loadConfig, getRuntimeLogsDir } = require('./lib/utils')
|
|
10
12
|
|
|
11
13
|
module.exports.buildServer = buildServer
|
|
14
|
+
module.exports.compile = compile
|
|
15
|
+
module.exports.errors = errors
|
|
16
|
+
module.exports.Generator = RuntimeGenerator
|
|
17
|
+
module.exports.getRuntimeLogsDir = getRuntimeLogsDir
|
|
18
|
+
module.exports.loadConfig = loadConfig
|
|
12
19
|
module.exports.platformaticRuntime = platformaticRuntime
|
|
13
|
-
module.exports.wrapConfigInRuntimeConfig = wrapConfigInRuntimeConfig
|
|
14
20
|
module.exports.schema = platformaticRuntime.schema
|
|
15
|
-
module.exports.RuntimeApi = RuntimeApi
|
|
16
21
|
module.exports.start = start
|
|
17
22
|
module.exports.startCommand = startCommand
|
|
18
|
-
module.exports.
|
|
19
|
-
module.exports.
|
|
20
|
-
module.exports.
|
|
21
|
-
module.exports.Generator = RuntimeGenerator
|
|
23
|
+
module.exports.symbols = symbols
|
|
24
|
+
module.exports.Runtime = Runtime
|
|
25
|
+
module.exports.wrapConfigInRuntimeConfig = wrapConfigInRuntimeConfig
|
package/index.test-d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { expectError, expectType } from 'tsd'
|
|
2
|
-
import { LightMyRequestResponse } from 'fastify'
|
|
3
|
-
import { pltRuntimeBuildServer, errors } from '.'
|
|
1
|
+
import { expectError, expectType } from 'tsd'
|
|
2
|
+
import { LightMyRequestResponse } from 'fastify'
|
|
3
|
+
import { pltRuntimeBuildServer, errors } from '.'
|
|
4
4
|
import { FastifyError } from '@fastify/error'
|
|
5
5
|
|
|
6
6
|
const server: pltRuntimeBuildServer = {
|
|
@@ -9,19 +9,18 @@ const server: pltRuntimeBuildServer = {
|
|
|
9
9
|
restart: async () => { },
|
|
10
10
|
stop: async () => { },
|
|
11
11
|
inject: async () => ({} as LightMyRequestResponse),
|
|
12
|
-
}
|
|
12
|
+
}
|
|
13
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' })
|
|
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
20
|
|
|
21
21
|
// Errors
|
|
22
22
|
type ErrorWithNoParams = () => FastifyError
|
|
23
23
|
type ErrorWithOneParam = (param: string) => FastifyError
|
|
24
|
-
type ErrorWithOneAnyParam = (param: string) => FastifyError
|
|
25
24
|
type ErrorWithTwoParams = (param1: string, param2: string) => FastifyError
|
|
26
25
|
|
|
27
26
|
expectType<ErrorWithNoParams>(errors.RuntimeExitedError)
|
|
@@ -40,4 +39,3 @@ expectType<ErrorWithNoParams>(errors.InspectorPortError)
|
|
|
40
39
|
expectType<ErrorWithNoParams>(errors.InspectorHostError)
|
|
41
40
|
expectType<ErrorWithOneParam>(errors.CannotMapSpecifierToAbsolutePathError)
|
|
42
41
|
expectType<ErrorWithNoParams>(errors.NodeInspectorFlagsNotSupportedError)
|
|
43
|
-
|
package/lib/build-server.js
CHANGED
|
@@ -2,32 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
const { createRequire } = require('node:module')
|
|
4
4
|
const { join } = require('node:path')
|
|
5
|
+
|
|
5
6
|
const ConfigManager = require('@platformatic/config')
|
|
7
|
+
|
|
6
8
|
const { platformaticRuntime } = require('./config')
|
|
7
9
|
const { buildRuntime } = require('./start')
|
|
8
|
-
const { loadConfig } = require('./
|
|
10
|
+
const { loadConfig } = require('./utils')
|
|
9
11
|
|
|
10
12
|
async function buildServerRuntime (options = {}) {
|
|
11
|
-
const {
|
|
12
|
-
serviceMap,
|
|
13
|
-
loggingPort,
|
|
14
|
-
loggingMetadata
|
|
15
|
-
} = options
|
|
13
|
+
const { serviceMap } = options
|
|
16
14
|
|
|
17
15
|
if (!options.configManager) {
|
|
18
16
|
delete options.serviceMap
|
|
19
|
-
delete options.loggingPort
|
|
20
|
-
delete options.loggingMetadata
|
|
21
17
|
|
|
22
18
|
// Instantiate a new config manager from the current options.
|
|
23
19
|
const cm = new ConfigManager({
|
|
24
20
|
...platformaticRuntime.configManagerConfig,
|
|
25
|
-
source: options
|
|
21
|
+
source: options,
|
|
26
22
|
})
|
|
27
23
|
await cm.parseAndValidate()
|
|
28
24
|
|
|
29
|
-
cm.current.loggingPort = loggingPort
|
|
30
|
-
cm.current.loggingMetadata = loggingMetadata
|
|
31
25
|
cm.current.serviceMap = serviceMap
|
|
32
26
|
|
|
33
27
|
if (typeof options === 'string') {
|
package/lib/compile.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const tsCompiler = require('@platformatic/ts-compiler')
|
|
4
|
-
const { loadConfig } = require('./load-config')
|
|
5
|
-
const { dirname, join } = require('node:path')
|
|
6
3
|
const { createRequire } = require('node:module')
|
|
4
|
+
const { dirname, join } = require('node:path')
|
|
5
|
+
const { isatty } = require('node:tty')
|
|
7
6
|
const { pathToFileURL } = require('node:url')
|
|
8
7
|
|
|
8
|
+
const tsCompiler = require('@platformatic/ts-compiler')
|
|
9
9
|
const pino = require('pino')
|
|
10
10
|
const pretty = require('pino-pretty')
|
|
11
|
-
|
|
11
|
+
|
|
12
|
+
const { loadConfig } = require('./utils')
|
|
12
13
|
|
|
13
14
|
async function compile (argv, logger) {
|
|
14
15
|
const { configManager, configType, app } = await loadConfig({}, argv, {
|
|
15
|
-
watch: false
|
|
16
|
+
watch: false,
|
|
16
17
|
}, false)
|
|
17
18
|
/* c8 ignore next */
|
|
18
19
|
if (!logger) {
|
|
@@ -21,7 +22,7 @@ async function compile (argv, logger) {
|
|
|
21
22
|
if (isatty(process.stdout.fd)) {
|
|
22
23
|
stream = pretty({
|
|
23
24
|
translateTime: 'SYS:HH:MM:ss',
|
|
24
|
-
ignore: 'hostname,pid'
|
|
25
|
+
ignore: 'hostname,pid',
|
|
25
26
|
})
|
|
26
27
|
}
|
|
27
28
|
|
|
@@ -30,7 +31,7 @@ async function compile (argv, logger) {
|
|
|
30
31
|
|
|
31
32
|
let compiled = false
|
|
32
33
|
const compileOptions = {
|
|
33
|
-
clean: argv.includes('--clean')
|
|
34
|
+
clean: argv.includes('--clean'),
|
|
34
35
|
}
|
|
35
36
|
if (configType === 'runtime') {
|
|
36
37
|
for (const service of configManager.current.services) {
|
|
@@ -41,7 +42,7 @@ async function compile (argv, logger) {
|
|
|
41
42
|
onMissingEnv (key) {
|
|
42
43
|
return service.localServiceEnvVars.get(key)
|
|
43
44
|
},
|
|
44
|
-
watch: false
|
|
45
|
+
watch: false,
|
|
45
46
|
}, false)
|
|
46
47
|
|
|
47
48
|
const tsOptions = await extract(configManager, app)
|
|
@@ -51,7 +52,7 @@ async function compile (argv, logger) {
|
|
|
51
52
|
...compileOptions,
|
|
52
53
|
...tsOptions,
|
|
53
54
|
cwd: service.path,
|
|
54
|
-
logger: childLogger
|
|
55
|
+
logger: childLogger,
|
|
55
56
|
})
|
|
56
57
|
compiled ||= serviceWasCompiled
|
|
57
58
|
}
|
|
@@ -63,7 +64,7 @@ async function compile (argv, logger) {
|
|
|
63
64
|
...compileOptions,
|
|
64
65
|
...tsOptions,
|
|
65
66
|
cwd: dirname(configManager.fullPath),
|
|
66
|
-
logger
|
|
67
|
+
logger,
|
|
67
68
|
})
|
|
68
69
|
}
|
|
69
70
|
}
|
package/lib/config.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
+
|
|
2
3
|
const { readdir } = require('node:fs/promises')
|
|
3
4
|
const { join, resolve: pathResolve } = require('node:path')
|
|
5
|
+
|
|
4
6
|
const ConfigManager = require('@platformatic/config')
|
|
5
|
-
|
|
7
|
+
|
|
6
8
|
const errors = require('./errors')
|
|
9
|
+
const { schema } = require('./schema')
|
|
7
10
|
const upgrade = require('./upgrade')
|
|
8
11
|
|
|
9
12
|
const kServicesAutoloaded = Symbol('plt.servicesAutoloaded')
|
|
@@ -65,11 +68,11 @@ async function _transformConfig (configManager) {
|
|
|
65
68
|
for (let i = 0; i < services.length; ++i) {
|
|
66
69
|
const service = services[i]
|
|
67
70
|
|
|
68
|
-
if (configManager._fixPaths) {
|
|
71
|
+
if (configManager._fixPaths && service.config) {
|
|
69
72
|
service.config = pathResolve(service.path, service.config)
|
|
70
73
|
}
|
|
71
74
|
service.entrypoint = service.id === config.entrypoint
|
|
72
|
-
service.
|
|
75
|
+
service.watch = !!config.watch
|
|
73
76
|
service.dependencies = []
|
|
74
77
|
service.localServiceEnvVars = new Map()
|
|
75
78
|
service.localUrl = `http://${service.id}.plt.local`
|
|
@@ -87,6 +90,10 @@ async function _transformConfig (configManager) {
|
|
|
87
90
|
|
|
88
91
|
configManager.current.services = services
|
|
89
92
|
configManager.current.services[kServicesAutoloaded] = true
|
|
93
|
+
|
|
94
|
+
if (configManager.current.restartOnError === true) {
|
|
95
|
+
configManager.current.restartOnError = 5000
|
|
96
|
+
}
|
|
90
97
|
}
|
|
91
98
|
|
|
92
99
|
async function platformaticRuntime () {
|
|
@@ -104,12 +111,12 @@ platformaticRuntime.configManagerConfig = {
|
|
|
104
111
|
useDefaults: true,
|
|
105
112
|
coerceTypes: true,
|
|
106
113
|
allErrors: true,
|
|
107
|
-
strict: false
|
|
114
|
+
strict: false,
|
|
108
115
|
},
|
|
109
116
|
async transformConfig () {
|
|
110
117
|
await _transformConfig(this)
|
|
111
118
|
},
|
|
112
|
-
upgrade
|
|
119
|
+
upgrade,
|
|
113
120
|
}
|
|
114
121
|
|
|
115
122
|
async function wrapConfigInRuntimeConfig ({ configManager, args }) {
|
|
@@ -128,14 +135,14 @@ async function wrapConfigInRuntimeConfig ({ configManager, args }) {
|
|
|
128
135
|
const wrapperConfig = {
|
|
129
136
|
$schema: schema.$id,
|
|
130
137
|
entrypoint: serviceId,
|
|
131
|
-
|
|
138
|
+
watch: true,
|
|
132
139
|
services: [
|
|
133
140
|
{
|
|
134
141
|
id: serviceId,
|
|
135
142
|
path: configManager.dirname,
|
|
136
|
-
config: configManager.fullPath
|
|
137
|
-
}
|
|
138
|
-
]
|
|
143
|
+
config: configManager.fullPath,
|
|
144
|
+
},
|
|
145
|
+
],
|
|
139
146
|
}
|
|
140
147
|
const cm = new ConfigManager({
|
|
141
148
|
source: wrapperConfig,
|
|
@@ -144,9 +151,9 @@ async function wrapConfigInRuntimeConfig ({ configManager, args }) {
|
|
|
144
151
|
useDefaults: true,
|
|
145
152
|
coerceTypes: true,
|
|
146
153
|
allErrors: true,
|
|
147
|
-
strict: false
|
|
154
|
+
strict: false,
|
|
148
155
|
},
|
|
149
|
-
transformConfig () { return _transformConfig(this) }
|
|
156
|
+
transformConfig () { return _transformConfig(this) },
|
|
150
157
|
})
|
|
151
158
|
|
|
152
159
|
await cm.parseAndValidate()
|
|
@@ -198,15 +205,15 @@ function parseInspectorOptions (configManager) {
|
|
|
198
205
|
host,
|
|
199
206
|
port,
|
|
200
207
|
breakFirstLine: hasInspectBrk,
|
|
201
|
-
|
|
208
|
+
watchDisabled: !!current.watch,
|
|
202
209
|
}
|
|
203
210
|
|
|
204
|
-
current.
|
|
211
|
+
current.watch = false
|
|
205
212
|
}
|
|
206
213
|
}
|
|
207
214
|
|
|
208
215
|
module.exports = {
|
|
209
216
|
parseInspectorOptions,
|
|
210
217
|
platformaticRuntime,
|
|
211
|
-
wrapConfigInRuntimeConfig
|
|
218
|
+
wrapConfigInRuntimeConfig,
|
|
212
219
|
}
|
package/lib/dependencies.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const Topo = require('@hapi/topo')
|
|
4
4
|
const { closest } = require('fastest-levenshtein')
|
|
5
|
+
|
|
5
6
|
const errors = require('./errors')
|
|
6
7
|
|
|
7
8
|
function missingDependencyErrorMessage (clientName, service, services) {
|
|
@@ -38,7 +39,7 @@ function topologicalSort (services, config) {
|
|
|
38
39
|
topo.add(service, {
|
|
39
40
|
group: service.id,
|
|
40
41
|
after: localDependencyIds,
|
|
41
|
-
manual: true
|
|
42
|
+
manual: true,
|
|
42
43
|
})
|
|
43
44
|
}
|
|
44
45
|
|
package/lib/errors.js
CHANGED
|
@@ -7,8 +7,9 @@ const ERROR_PREFIX = 'PLT_RUNTIME'
|
|
|
7
7
|
module.exports = {
|
|
8
8
|
AddressInUseError: createError(`${ERROR_PREFIX}_EADDR_IN_USE`, 'The current port is in use by another application'),
|
|
9
9
|
RuntimeExitedError: createError(`${ERROR_PREFIX}_RUNTIME_EXIT`, 'The runtime exited before the operation completed'),
|
|
10
|
+
ServiceExitedError: createError(`${ERROR_PREFIX}_SERVICE_EXIT`, 'The service %s exited prematurely with error code %d'),
|
|
10
11
|
UnknownRuntimeAPICommandError: createError(`${ERROR_PREFIX}_UNKNOWN_RUNTIME_API_COMMAND`, 'Unknown Runtime API command "%s"'),
|
|
11
|
-
ServiceNotFoundError: createError(`${ERROR_PREFIX}_SERVICE_NOT_FOUND`, 'Service not found. Available services are: %s'),
|
|
12
|
+
ServiceNotFoundError: createError(`${ERROR_PREFIX}_SERVICE_NOT_FOUND`, 'Service %s not found. Available services are: %s'),
|
|
12
13
|
ServiceNotStartedError: createError(`${ERROR_PREFIX}_SERVICE_NOT_STARTED`, "Service with id '%s' is not started"),
|
|
13
14
|
FailedToRetrieveOpenAPISchemaError: createError(`${ERROR_PREFIX}_FAILED_TO_RETRIEVE_OPENAPI_SCHEMA`, 'Failed to retrieve OpenAPI schema for service with id "%s": %s'),
|
|
14
15
|
FailedToRetrieveGraphQLSchemaError: createError(`${ERROR_PREFIX}_FAILED_TO_RETRIEVE_GRAPHQL_SCHEMA`, 'Failed to retrieve GraphQL schema for service with id "%s": %s'),
|
|
@@ -29,5 +30,5 @@ module.exports = {
|
|
|
29
30
|
WorkerIsRequired: createError(`${ERROR_PREFIX}_REQUIRED_WORKER`, 'The worker parameter is required'),
|
|
30
31
|
|
|
31
32
|
// TODO: should remove next one as it's not used anymore
|
|
32
|
-
CannotRemoveServiceOnUpdateError: createError(`${ERROR_PREFIX}_CANNOT_REMOVE_SERVICE_ON_UPDATE`, 'Cannot remove service "%s" when updating a Runtime')
|
|
33
|
+
CannotRemoveServiceOnUpdateError: createError(`${ERROR_PREFIX}_CANNOT_REMOVE_SERVICE_ON_UPDATE`, 'Cannot remove service "%s" when updating a Runtime'),
|
|
33
34
|
}
|
package/lib/generator/errors.js
CHANGED
|
@@ -6,5 +6,5 @@ const ERROR_PREFIX = 'PLT_RUNTIME_GEN'
|
|
|
6
6
|
|
|
7
7
|
module.exports = {
|
|
8
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.')
|
|
9
|
+
NoEntryPointError: createError(`${ERROR_PREFIX}_NO_ENTRYPOINT`, 'No entrypoint had been defined.'),
|
|
10
10
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BaseGenerator } from
|
|
2
|
-
import { FileGenerator } from
|
|
1
|
+
import { BaseGenerator } from '@platformatic/generators'
|
|
2
|
+
import { FileGenerator } from '@platformatic/generators/lib/file-generator'
|
|
3
3
|
|
|
4
4
|
type Service = {
|
|
5
5
|
config: FileGenerator.FileGenerator | BaseGenerator.BaseGenerator
|
|
@@ -13,7 +13,7 @@ type KeyValue = {
|
|
|
13
13
|
[key: string]: string
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
type RuntimeGeneratorOptions =
|
|
16
|
+
type RuntimeGeneratorOptions = BaseGenerator.BaseGeneratorOptions & {
|
|
17
17
|
logLevel: string
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -21,17 +21,17 @@ export namespace RuntimeGenerator {
|
|
|
21
21
|
export class RuntimeGenerator extends BaseGenerator.BaseGenerator {
|
|
22
22
|
services: Service[]
|
|
23
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>
|
|
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
36
|
}
|
|
37
37
|
}
|