@platformatic/service 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 -19
- package/eslint.config.js +4 -6
- package/index.d.ts +51 -47
- package/index.js +44 -199
- package/lib/application.js +57 -0
- package/lib/compile.js +1 -52
- package/lib/generator.js +154 -0
- package/lib/plugins/clients.js +9 -8
- package/lib/plugins/cors.js +5 -8
- package/lib/plugins/graphql.js +16 -14
- package/lib/plugins/health-check.js +6 -8
- package/lib/plugins/openapi.js +40 -31
- package/lib/plugins/plugins.js +15 -18
- package/lib/{root-endpoint/index.js → plugins/root.js} +9 -8
- package/lib/plugins/sandbox-wrapper.js +62 -55
- package/lib/plugins/typescript.js +10 -13
- package/lib/schema.js +1030 -132
- package/lib/stackable.js +180 -337
- package/lib/upgrade.js +6 -8
- package/lib/utils.js +39 -74
- package/lib/versions/0.16.0.js +14 -14
- package/lib/versions/{from-zero-twenty-eight-to-will-see.js → 0.28.0.js} +3 -5
- package/lib/versions/2.0.0.js +4 -6
- package/package.json +17 -22
- package/schema.json +3 -74
- package/tsconfig.json +16 -6
- package/.c8rc +0 -6
- package/help/compile.txt +0 -19
- package/help/create.txt +0 -11
- package/help/help.txt +0 -8
- package/help/schema.txt +0 -9
- package/help/start.txt +0 -23
- package/index.test-d.ts +0 -107
- package/lib/create.mjs +0 -85
- package/lib/gen-schema.js +0 -15
- package/lib/gen-types.mjs +0 -38
- package/lib/generator/README.md +0 -31
- package/lib/generator/service-generator.d.ts +0 -11
- package/lib/generator/service-generator.js +0 -126
- package/lib/openapi-schema-defs.js +0 -1108
- package/lib/plugins/metrics.js +0 -244
- package/lib/start.js +0 -190
- package/service.mjs +0 -71
- /package/{lib/root-endpoint/public → public}/images/dark_mode.svg +0 -0
- /package/{lib/root-endpoint/public → public}/images/favicon.ico +0 -0
- /package/{lib/root-endpoint/public → public}/images/light_mode.svg +0 -0
- /package/{lib/root-endpoint/public → public}/images/platformatic-logo-dark.svg +0 -0
- /package/{lib/root-endpoint/public → public}/images/platformatic-logo-light.svg +0 -0
- /package/{lib/root-endpoint/public → public}/images/triangle_dark.svg +0 -0
- /package/{lib/root-endpoint/public → public}/images/triangle_light.svg +0 -0
- /package/{lib/root-endpoint/public → public}/index.html +0 -0
package/config.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* and run json-schema-to-typescript to regenerate this file.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
export interface
|
|
8
|
+
export interface PlatformaticServiceConfig {
|
|
9
9
|
basePath?: string;
|
|
10
10
|
server?: {
|
|
11
11
|
hostname?: string;
|
|
@@ -164,24 +164,6 @@ export interface PlatformaticService {
|
|
|
164
164
|
plugins?: {
|
|
165
165
|
[k: string]: unknown;
|
|
166
166
|
};
|
|
167
|
-
metrics?:
|
|
168
|
-
| boolean
|
|
169
|
-
| {
|
|
170
|
-
port?: number | string;
|
|
171
|
-
hostname?: string;
|
|
172
|
-
endpoint?: string;
|
|
173
|
-
server?: "own" | "parent" | "hide";
|
|
174
|
-
defaultMetrics?: {
|
|
175
|
-
enabled: boolean;
|
|
176
|
-
};
|
|
177
|
-
auth?: {
|
|
178
|
-
username: string;
|
|
179
|
-
password: string;
|
|
180
|
-
};
|
|
181
|
-
labels?: {
|
|
182
|
-
[k: string]: string;
|
|
183
|
-
};
|
|
184
|
-
};
|
|
185
167
|
telemetry?: {
|
|
186
168
|
enabled?: boolean | string;
|
|
187
169
|
/**
|
package/eslint.config.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import neostandard from 'neostandard'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
module.exports = neostandard({
|
|
3
|
+
export default neostandard({
|
|
6
4
|
ts: true,
|
|
7
5
|
ignores: [
|
|
8
6
|
...neostandard.resolveIgnoresFromGitignore(),
|
|
9
7
|
'test/tmp/**/*',
|
|
10
8
|
'test/fixtures/*/dist/**/*',
|
|
11
9
|
'**/dist/*',
|
|
12
|
-
'
|
|
13
|
-
]
|
|
10
|
+
'tmp/**/*'
|
|
11
|
+
]
|
|
14
12
|
})
|
package/index.d.ts
CHANGED
|
@@ -1,65 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
/// <reference types="@fastify/swagger" />
|
|
3
|
-
import { FastifyInstance, FastifyBaseLogger } from 'fastify'
|
|
4
|
-
import ConfigManager from '@platformatic/config'
|
|
5
|
-
import type { Stackable as _Stackable, StackableInterface, ConfigManagerConfig } from '@platformatic/config'
|
|
1
|
+
import { BaseContext, BaseOptions, BaseStackable } from '@platformatic/basic'
|
|
6
2
|
import { BaseGenerator } from '@platformatic/generators'
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
3
|
+
import { Configuration, ConfigurationOptions } from '@platformatic/utils'
|
|
4
|
+
import { JSONSchemaType } from 'ajv'
|
|
5
|
+
import { FastifyInstance } from 'fastify'
|
|
6
|
+
import { PlatformaticServiceConfig } from './config'
|
|
10
7
|
|
|
11
|
-
export
|
|
8
|
+
export { PlatformaticServiceConfig } from './config'
|
|
12
9
|
|
|
13
|
-
export interface
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
export interface ServiceContext extends BaseContext {
|
|
11
|
+
applicationFactory?: typeof platformaticService
|
|
12
|
+
fastifyPlugins?: Function[]
|
|
16
13
|
}
|
|
17
14
|
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
export function start<ConfigType> (app: Stackable<ConfigType>, args: string[]): Promise<void>
|
|
15
|
+
export interface PlatformaticApplication<Config> {
|
|
16
|
+
config: Configuration<Config>
|
|
17
|
+
}
|
|
22
18
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
restart: () => Promise<void>
|
|
26
|
-
}
|
|
19
|
+
export type ServerInstance<Configuration = PlatformaticServiceConfig> = FastifyInstance & {
|
|
20
|
+
platformatic: PlatformaticApplication<Configuration>
|
|
27
21
|
}
|
|
28
22
|
|
|
29
|
-
type
|
|
23
|
+
export type ServiceConfiguration<T = {}> = Promise<Configuration<PlatformaticServiceConfig & T>>
|
|
30
24
|
|
|
31
|
-
export
|
|
32
|
-
app: (app: FastifyInstance, opts: object) => Promise<void>
|
|
33
|
-
Generator?: Generator
|
|
34
|
-
version?: string
|
|
35
|
-
upgrade?: (config: any, version: string) => Promise<any>
|
|
36
|
-
transformConfig?: (config: any) => Promise<any>
|
|
37
|
-
buildStackable: (opts: { config: string }, app?: object) => Promise<StackableInterface>
|
|
38
|
-
}
|
|
25
|
+
export declare function transform (config: ServiceConfiguration): Promise<ServiceConfiguration> | ServiceConfiguration
|
|
39
26
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
27
|
+
export declare function loadConfiguration (
|
|
28
|
+
root: string | PlatformaticServiceConfig,
|
|
29
|
+
source?: string | PlatformaticServiceConfig,
|
|
30
|
+
context?: ConfigurationOptions
|
|
31
|
+
): Promise<Configuration<PlatformaticServiceConfig>>
|
|
32
|
+
|
|
33
|
+
export declare function create (
|
|
34
|
+
root: string | PlatformaticServiceConfig,
|
|
35
|
+
source?: string | PlatformaticServiceConfig,
|
|
36
|
+
context?: ConfigurationOptions
|
|
37
|
+
): Promise<ServiceStackable>
|
|
46
38
|
|
|
47
|
-
export const
|
|
48
|
-
export const configManagerConfig: ConfigManagerConfig<PlatformaticServiceConfig>
|
|
39
|
+
export declare const skipTelemetryHooks: boolean
|
|
49
40
|
|
|
50
|
-
export declare
|
|
41
|
+
export declare function platformaticService (app: FastifyInstance, stackable: ServiceStackable): Promise<void>
|
|
51
42
|
|
|
52
|
-
export declare
|
|
43
|
+
export declare class Generator extends BaseGenerator.BaseGenerator {}
|
|
53
44
|
|
|
54
|
-
export const
|
|
45
|
+
export declare const packageJson: Record<string, unknown>
|
|
55
46
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
47
|
+
export declare const schema: JSONSchemaType<PlatformaticServiceConfig>
|
|
48
|
+
|
|
49
|
+
export declare const schemaComponents: {
|
|
50
|
+
$defs: JSONSchemaType<object>
|
|
51
|
+
plugins: JSONSchemaType<object>
|
|
52
|
+
openApiBase: JSONSchemaType<object>
|
|
53
|
+
openapi: JSONSchemaType<object>
|
|
54
|
+
proxy: JSONSchemaType<object>
|
|
55
|
+
graphqlBase: JSONSchemaType<object>
|
|
56
|
+
graphql: JSONSchemaType<object>
|
|
57
|
+
service: JSONSchemaType<object>
|
|
58
|
+
client: JSONSchemaType<object>
|
|
61
59
|
}
|
|
62
60
|
|
|
63
|
-
export
|
|
61
|
+
export declare const version: string
|
|
64
62
|
|
|
65
|
-
export
|
|
63
|
+
export declare class ServiceStackable<Config = PlatformaticServiceConfig> extends BaseStackable<
|
|
64
|
+
Config,
|
|
65
|
+
BaseOptions<ServiceContext>
|
|
66
|
+
> {
|
|
67
|
+
constructor (root: string, config: Config, context?: object)
|
|
68
|
+
getApplication (): FastifyInstance
|
|
69
|
+
}
|
package/index.js
CHANGED
|
@@ -1,218 +1,63 @@
|
|
|
1
|
-
|
|
1
|
+
import { transform as basicTransform, resolve, validationOptions } from '@platformatic/basic'
|
|
2
|
+
import { kMetadata, loadConfiguration as utilsLoadConfiguration } from '@platformatic/utils'
|
|
3
|
+
import { readFile } from 'node:fs/promises'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
import { schema } from './lib/schema.js'
|
|
6
|
+
import { ServiceStackable } from './lib/stackable.js'
|
|
7
|
+
import { upgrade } from './lib/upgrade.js'
|
|
8
|
+
import { isDocker } from './lib/utils.js'
|
|
2
9
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const { readFile } = require('node:fs/promises')
|
|
6
|
-
const { join } = require('node:path')
|
|
7
|
-
const { workerData } = require('node:worker_threads')
|
|
8
|
-
const jsonPatch = require('fast-json-patch')
|
|
10
|
+
export async function transform (config, schema, options) {
|
|
11
|
+
config = await basicTransform(config, schema, options)
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const setupGraphQL = require('./lib/plugins/graphql.js')
|
|
13
|
-
const setupClients = require('./lib/plugins/clients')
|
|
14
|
-
const setupMetrics = require('./lib/plugins/metrics')
|
|
15
|
-
const setupTsCompiler = require('./lib/plugins/typescript')
|
|
16
|
-
const setupHealthCheck = require('./lib/plugins/health-check')
|
|
17
|
-
const loadPlugins = require('./lib/plugins/plugins')
|
|
18
|
-
const upgrade = require('./lib/upgrade')
|
|
19
|
-
const { telemetry } = require('@platformatic/telemetry')
|
|
20
|
-
|
|
21
|
-
const { buildCompileCmd, extractTypeScriptCompileOptionsFromConfig } = require('./lib/compile')
|
|
22
|
-
const { schema } = require('./lib/schema')
|
|
23
|
-
const { addLoggerToTheConfig } = require('./lib/utils')
|
|
24
|
-
const { start, buildServer } = require('./lib/start')
|
|
25
|
-
const ServiceGenerator = require('./lib/generator/service-generator.js')
|
|
26
|
-
const { ServiceStackable } = require('./lib/stackable')
|
|
27
|
-
|
|
28
|
-
const { version } = require('./package.json')
|
|
29
|
-
|
|
30
|
-
// TODO(mcollina): arugments[2] is deprecated, remove it in the next major version.
|
|
31
|
-
async function platformaticService (app, opts) {
|
|
32
|
-
const configManager = app.platformatic.configManager
|
|
33
|
-
const config = configManager.current
|
|
34
|
-
const beforePlugins = opts.beforePlugins || arguments[2] || []
|
|
35
|
-
|
|
36
|
-
if (isKeyEnabled('metrics', config)) {
|
|
37
|
-
if (config.metrics.server === 'own' && parseInt(config.server.port) === parseInt(config.metrics.port)) {
|
|
38
|
-
app.log.warn('In order to serve metrics on the same port as the core applicaton, set metrics.server to "parent".')
|
|
39
|
-
config.metrics.server = 'parent'
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
app.register(setupMetrics, config.metrics)
|
|
13
|
+
if (config.server && (await isDocker())) {
|
|
14
|
+
config.server.hostname = '0.0.0.0'
|
|
43
15
|
}
|
|
44
16
|
|
|
45
|
-
|
|
46
|
-
// openTelemetry decorator exists and then configure accordingly.
|
|
47
|
-
if (isKeyEnabled('telemetry', config)) {
|
|
48
|
-
await app.register(telemetry, config.telemetry)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// This must be done before loading the plugins, so they can be
|
|
52
|
-
// configured accordingly
|
|
53
|
-
if (isKeyEnabled('clients', config)) {
|
|
54
|
-
app.register(setupClients, config.clients)
|
|
55
|
-
}
|
|
17
|
+
const typescript = config.plugins?.typescript
|
|
56
18
|
|
|
57
|
-
if (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
}
|
|
19
|
+
if (typescript) {
|
|
20
|
+
let { outDir, tsConfigFile } = typescript
|
|
21
|
+
tsConfigFile ??= 'tsconfig.json'
|
|
62
22
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (isKeyEnabled('graphql', serviceConfig)) {
|
|
71
|
-
app.register(setupGraphQL, serviceConfig.graphql)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (config.plugins) {
|
|
75
|
-
let registerTsCompiler = false
|
|
76
|
-
const typescript = config.plugins.paths && config.plugins.typescript
|
|
77
|
-
/* c8 ignore next 6 */
|
|
78
|
-
if (typescript === true) {
|
|
79
|
-
registerTsCompiler = true
|
|
80
|
-
} else if (typeof typescript === 'object') {
|
|
81
|
-
registerTsCompiler = typescript.enabled === true || typescript.enabled === undefined
|
|
82
|
-
}
|
|
23
|
+
if (typeof outDir === 'undefined') {
|
|
24
|
+
try {
|
|
25
|
+
outDir = JSON.parse(await readFile(join(this.dirname, tsConfigFile), 'utf8')).compilerOptions.outDir
|
|
26
|
+
} catch {
|
|
27
|
+
// No-op
|
|
28
|
+
}
|
|
83
29
|
|
|
84
|
-
|
|
85
|
-
app.register(setupTsCompiler, { context: opts.context })
|
|
30
|
+
outDir ||= 'dist'
|
|
86
31
|
}
|
|
87
|
-
app.register(loadPlugins, { context: opts.context })
|
|
88
|
-
}
|
|
89
32
|
|
|
90
|
-
|
|
91
|
-
|
|
33
|
+
config.watch.ignore ??= []
|
|
34
|
+
config.watch.ignore.push(outDir + '/**/*')
|
|
92
35
|
}
|
|
93
36
|
|
|
94
|
-
|
|
95
|
-
app.register(setupHealthCheck, config.server.healthCheck)
|
|
96
|
-
}
|
|
37
|
+
return config
|
|
97
38
|
}
|
|
98
39
|
|
|
99
|
-
|
|
40
|
+
export async function loadConfiguration (configOrRoot, sourceOrConfig, context) {
|
|
41
|
+
const { root, source } = await resolve(configOrRoot, sourceOrConfig, 'service')
|
|
100
42
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
strict: false
|
|
110
|
-
},
|
|
111
|
-
async transformConfig () {
|
|
112
|
-
// Set watch to true by default. This is not possible
|
|
113
|
-
// to do in the schema, because it is uses an anyOf.
|
|
114
|
-
if (this.current.watch === undefined) {
|
|
115
|
-
this.current.watch = { enabled: false }
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (typeof this.current.watch !== 'object') {
|
|
119
|
-
this.current.watch = { enabled: this.current.watch || false }
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const typescript = this.current.plugins?.typescript
|
|
123
|
-
if (typescript) {
|
|
124
|
-
let outDir = typescript.outDir
|
|
125
|
-
if (outDir === undefined) {
|
|
126
|
-
let tsConfigFile = typescript.tsConfigFile || 'tsconfig.json'
|
|
127
|
-
tsConfigFile = join(this.dirname, tsConfigFile)
|
|
128
|
-
try {
|
|
129
|
-
const tsConfig = JSON.parse(await readFile(tsConfigFile, 'utf8'))
|
|
130
|
-
outDir = tsConfig.compilerOptions.outDir
|
|
131
|
-
} catch {}
|
|
132
|
-
outDir ||= 'dist'
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
this.current.watch.ignore ||= []
|
|
136
|
-
this.current.watch.ignore.push(outDir + '/**/*')
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
upgrade
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
platformaticService.configType = 'service'
|
|
143
|
-
platformaticService.schema = schema
|
|
144
|
-
platformaticService.configManagerConfig = module.exports.configManagerConfig
|
|
145
|
-
|
|
146
|
-
function _buildServer (options, app, context) {
|
|
147
|
-
return buildServer(options, app || module.exports, context)
|
|
43
|
+
return utilsLoadConfiguration(source, context?.schema ?? schema, {
|
|
44
|
+
validationOptions,
|
|
45
|
+
transform,
|
|
46
|
+
upgrade,
|
|
47
|
+
replaceEnv: true,
|
|
48
|
+
root,
|
|
49
|
+
...context
|
|
50
|
+
})
|
|
148
51
|
}
|
|
149
52
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
return
|
|
53
|
+
export async function create (configOrRoot, sourceOrConfig, context) {
|
|
54
|
+
const config = await loadConfiguration(configOrRoot, sourceOrConfig, context)
|
|
55
|
+
return new ServiceStackable(config[kMetadata].root, config, context)
|
|
153
56
|
}
|
|
154
57
|
|
|
155
|
-
|
|
156
|
-
let configManager = options.configManager
|
|
157
|
-
|
|
158
|
-
if (configManager === undefined) {
|
|
159
|
-
if (typeof options.config === 'string') {
|
|
160
|
-
;({ configManager } = await loadConfig(
|
|
161
|
-
{},
|
|
162
|
-
['-c', options.config],
|
|
163
|
-
app,
|
|
164
|
-
{
|
|
165
|
-
onMissingEnv: options.onMissingEnv,
|
|
166
|
-
context: options.context
|
|
167
|
-
},
|
|
168
|
-
true
|
|
169
|
-
))
|
|
170
|
-
} else {
|
|
171
|
-
configManager = new ConfigManager({
|
|
172
|
-
...app.configManagerConfig,
|
|
173
|
-
source: options.config,
|
|
174
|
-
dirname: options.context?.directory
|
|
175
|
-
})
|
|
176
|
-
await configManager.parseAndValidate()
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const patch = workerData?.serviceConfig?.configPatch
|
|
181
|
-
|
|
182
|
-
if (Array.isArray(patch)) {
|
|
183
|
-
configManager.current = jsonPatch.applyPatch(configManager.current, patch).newDocument
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
const stackable = new Stackable({
|
|
187
|
-
init: () =>
|
|
188
|
-
buildServer(
|
|
189
|
-
{
|
|
190
|
-
configManager,
|
|
191
|
-
...configManager.current
|
|
192
|
-
},
|
|
193
|
-
app,
|
|
194
|
-
options.context
|
|
195
|
-
),
|
|
196
|
-
stackable: app,
|
|
197
|
-
configManager,
|
|
198
|
-
context: options.context
|
|
199
|
-
})
|
|
200
|
-
|
|
201
|
-
return stackable
|
|
202
|
-
}
|
|
58
|
+
export const skipTelemetryHooks = true
|
|
203
59
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
module.exports.buildServer = _buildServer
|
|
209
|
-
module.exports.buildStackable = buildStackable
|
|
210
|
-
module.exports.createDefaultConfig = createDefaultConfig
|
|
211
|
-
module.exports.schemas = require('./lib/schema')
|
|
212
|
-
module.exports.platformaticService = platformaticService
|
|
213
|
-
module.exports.addLoggerToTheConfig = addLoggerToTheConfig
|
|
214
|
-
module.exports.start = start
|
|
215
|
-
module.exports.Generator = ServiceGenerator
|
|
216
|
-
module.exports.ServiceStackable = ServiceStackable
|
|
217
|
-
module.exports.buildCompileCmd = buildCompileCmd
|
|
218
|
-
module.exports.extractTypeScriptCompileOptionsFromConfig = extractTypeScriptCompileOptionsFromConfig
|
|
60
|
+
export { platformaticService } from './lib/application.js'
|
|
61
|
+
export { Generator } from './lib/generator.js'
|
|
62
|
+
export { packageJson, schema, schemaComponents, version } from './lib/schema.js'
|
|
63
|
+
export { ServiceStackable } from './lib/stackable.js'
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { isKeyEnabled } from '@platformatic/utils'
|
|
2
|
+
import { setupClients } from './plugins/clients.js'
|
|
3
|
+
import { setupCors } from './plugins/cors.js'
|
|
4
|
+
import { setupGraphQL } from './plugins/graphql.js'
|
|
5
|
+
import { setupHealthCheck } from './plugins/health-check.js'
|
|
6
|
+
import { setupOpenAPI } from './plugins/openapi.js'
|
|
7
|
+
import { loadPlugins } from './plugins/plugins.js'
|
|
8
|
+
import { setupTsCompiler } from './plugins/typescript.js'
|
|
9
|
+
|
|
10
|
+
export async function platformaticService (app, stackable) {
|
|
11
|
+
const config = await stackable.getConfig()
|
|
12
|
+
|
|
13
|
+
// This must be done before loading the plugins, so they can be configured accordingly
|
|
14
|
+
if (isKeyEnabled('clients', config)) {
|
|
15
|
+
await app.register(setupClients, config.clients)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const serviceConfig = config.service || {}
|
|
19
|
+
|
|
20
|
+
if (isKeyEnabled('openapi', serviceConfig)) {
|
|
21
|
+
const openapi = serviceConfig.openapi
|
|
22
|
+
await app.register(setupOpenAPI, { openapi })
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (isKeyEnabled('graphql', serviceConfig)) {
|
|
26
|
+
await app.register(setupGraphQL, serviceConfig.graphql)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (config.plugins) {
|
|
30
|
+
let registerTsCompiler = false
|
|
31
|
+
|
|
32
|
+
const typescript = config.plugins.paths && config.plugins.typescript
|
|
33
|
+
|
|
34
|
+
/* c8 ignore next 6 */
|
|
35
|
+
if (typescript === true) {
|
|
36
|
+
registerTsCompiler = true
|
|
37
|
+
} else if (typeof typescript === 'object') {
|
|
38
|
+
registerTsCompiler = typescript.enabled === true || typescript.enabled === undefined
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (registerTsCompiler) {
|
|
42
|
+
await app.register(setupTsCompiler, stackable.context)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
await app.register(loadPlugins, stackable.context)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (isKeyEnabled('cors', config.server)) {
|
|
49
|
+
await app.register(setupCors, config.server.cors)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (isKeyEnabled('healthCheck', config.server)) {
|
|
53
|
+
await app.register(setupHealthCheck, config.server.healthCheck)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
platformaticService[Symbol.for('skip-override')] = true
|
package/lib/compile.js
CHANGED
|
@@ -1,57 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { compile } = require('@platformatic/ts-compiler')
|
|
4
|
-
const { loadConfig } = require('@platformatic/config')
|
|
5
|
-
const pino = require('pino')
|
|
6
|
-
const pretty = require('pino-pretty')
|
|
7
|
-
const { dirname } = require('path')
|
|
8
|
-
|
|
9
|
-
function buildCompileCmd (app) {
|
|
10
|
-
return async function compileCmd (_args) {
|
|
11
|
-
let fullPath = null
|
|
12
|
-
let config = null
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
const { configManager } = await loadConfig({}, _args, app, {
|
|
16
|
-
watch: false
|
|
17
|
-
})
|
|
18
|
-
await configManager.parseAndValidate()
|
|
19
|
-
config = configManager.current
|
|
20
|
-
fullPath = dirname(configManager.fullPath)
|
|
21
|
-
/* c8 ignore next 4 */
|
|
22
|
-
} catch (err) {
|
|
23
|
-
console.error(err)
|
|
24
|
-
process.exit(1)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const logger = pino(
|
|
28
|
-
pretty({
|
|
29
|
-
translateTime: 'SYS:HH:MM:ss',
|
|
30
|
-
ignore: 'hostname,pid'
|
|
31
|
-
})
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
await compile({
|
|
36
|
-
...extractTypeScriptCompileOptionsFromConfig(config),
|
|
37
|
-
cwd: fullPath,
|
|
38
|
-
logger,
|
|
39
|
-
clean: _args.includes('--clean')
|
|
40
|
-
})
|
|
41
|
-
} catch (e) {
|
|
42
|
-
logger.error(e.message)
|
|
43
|
-
process.exit(1)
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
module.exports.buildCompileCmd = buildCompileCmd
|
|
49
|
-
|
|
50
|
-
function extractTypeScriptCompileOptionsFromConfig (config) {
|
|
1
|
+
export function getTypescriptCompilationOptions (config) {
|
|
51
2
|
return {
|
|
52
3
|
tsConfig: config.plugins?.typescript?.tsConfig,
|
|
53
4
|
flags: config.plugins?.typescript?.flags
|
|
54
5
|
}
|
|
55
6
|
}
|
|
56
|
-
|
|
57
|
-
module.exports.extractTypeScriptCompileOptionsFromConfig = extractTypeScriptCompileOptionsFromConfig
|