@platformatic/service 3.0.0-alpha.1 → 3.0.0-alpha.2
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 -11
- package/index.d.ts +6 -2
- package/index.js +2 -2
- package/lib/application.js +1 -23
- package/lib/generator.js +345 -75
- package/lib/plugins/graphql.js +1 -1
- package/lib/plugins/openapi.js +1 -1
- package/lib/plugins/plugins.js +0 -44
- package/lib/plugins/sandbox-wrapper.js +1 -1
- package/lib/schema.js +4 -77
- package/lib/stackable.js +1 -11
- package/lib/upgrade.js +1 -1
- package/lib/utils.js +1 -29
- package/lib/versions/0.16.0.js +0 -1
- package/lib/versions/0.28.0.js +0 -1
- package/lib/versions/2.0.0.js +0 -1
- package/lib/versions/3.0.0.js +14 -0
- package/package.json +13 -15
- package/schema.json +9 -83
- package/lib/plugins/clients.js +0 -17
- package/lib/plugins/typescript.js +0 -17
package/config.d.ts
CHANGED
|
@@ -253,6 +253,7 @@ export interface PlatformaticServiceConfig {
|
|
|
253
253
|
| string;
|
|
254
254
|
$schema?: string;
|
|
255
255
|
module?: string;
|
|
256
|
+
application?: {};
|
|
256
257
|
service?: {
|
|
257
258
|
openapi?:
|
|
258
259
|
| {
|
|
@@ -306,17 +307,6 @@ export interface PlatformaticServiceConfig {
|
|
|
306
307
|
};
|
|
307
308
|
};
|
|
308
309
|
};
|
|
309
|
-
clients?: {
|
|
310
|
-
serviceId?: string;
|
|
311
|
-
name?: string;
|
|
312
|
-
type?: "openapi" | "graphql";
|
|
313
|
-
path?: string;
|
|
314
|
-
schema?: string;
|
|
315
|
-
url?: string;
|
|
316
|
-
fullResponse?: boolean;
|
|
317
|
-
fullRequest?: boolean;
|
|
318
|
-
validateResponse?: boolean;
|
|
319
|
-
}[];
|
|
320
310
|
runtime?: {
|
|
321
311
|
preload?: string | string[];
|
|
322
312
|
basePath?: string;
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseContext, BaseOptions, BaseStackable } from '@platformatic/basic'
|
|
2
|
+
import { Configuration, ConfigurationOptions } from '@platformatic/foundation'
|
|
2
3
|
import { BaseGenerator } from '@platformatic/generators'
|
|
3
|
-
import { Configuration, ConfigurationOptions } from '@platformatic/utils'
|
|
4
4
|
import { JSONSchemaType } from 'ajv'
|
|
5
5
|
import { FastifyInstance } from 'fastify'
|
|
6
6
|
import { PlatformaticServiceConfig } from './config'
|
|
@@ -41,6 +41,11 @@ export declare const skipTelemetryHooks: boolean
|
|
|
41
41
|
export declare function platformaticService (app: FastifyInstance, stackable: ServiceStackable): Promise<void>
|
|
42
42
|
|
|
43
43
|
export declare class Generator extends BaseGenerator.BaseGenerator {}
|
|
44
|
+
export declare function applyTestHelperCustomizations (
|
|
45
|
+
helper: string,
|
|
46
|
+
mod: string,
|
|
47
|
+
customizations: Record<string, string>
|
|
48
|
+
): string
|
|
44
49
|
|
|
45
50
|
export declare const packageJson: Record<string, unknown>
|
|
46
51
|
|
|
@@ -55,7 +60,6 @@ export declare const schemaComponents: {
|
|
|
55
60
|
graphqlBase: JSONSchemaType<object>
|
|
56
61
|
graphql: JSONSchemaType<object>
|
|
57
62
|
service: JSONSchemaType<object>
|
|
58
|
-
client: JSONSchemaType<object>
|
|
59
63
|
}
|
|
60
64
|
|
|
61
65
|
export declare const version: string
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { transform as basicTransform, resolve, validationOptions } from '@platformatic/basic'
|
|
2
|
-
import { kMetadata, loadConfiguration as utilsLoadConfiguration } from '@platformatic/
|
|
2
|
+
import { kMetadata, loadConfiguration as utilsLoadConfiguration } from '@platformatic/foundation'
|
|
3
3
|
import { readFile } from 'node:fs/promises'
|
|
4
4
|
import { join } from 'node:path'
|
|
5
5
|
import { schema } from './lib/schema.js'
|
|
@@ -58,6 +58,6 @@ export async function create (configOrRoot, sourceOrConfig, context) {
|
|
|
58
58
|
export const skipTelemetryHooks = true
|
|
59
59
|
|
|
60
60
|
export { platformaticService } from './lib/application.js'
|
|
61
|
-
export { Generator } from './lib/generator.js'
|
|
61
|
+
export { applyTestHelperCustomizations, Generator } from './lib/generator.js'
|
|
62
62
|
export { packageJson, schema, schemaComponents, version } from './lib/schema.js'
|
|
63
63
|
export { ServiceStackable } from './lib/stackable.js'
|
package/lib/application.js
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
import { isKeyEnabled } from '@platformatic/
|
|
2
|
-
import { setupClients } from './plugins/clients.js'
|
|
1
|
+
import { isKeyEnabled } from '@platformatic/foundation'
|
|
3
2
|
import { setupCors } from './plugins/cors.js'
|
|
4
3
|
import { setupGraphQL } from './plugins/graphql.js'
|
|
5
4
|
import { setupHealthCheck } from './plugins/health-check.js'
|
|
6
5
|
import { setupOpenAPI } from './plugins/openapi.js'
|
|
7
6
|
import { loadPlugins } from './plugins/plugins.js'
|
|
8
|
-
import { setupTsCompiler } from './plugins/typescript.js'
|
|
9
7
|
|
|
10
8
|
export async function platformaticService (app, stackable) {
|
|
11
9
|
const config = await stackable.getConfig()
|
|
12
10
|
|
|
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
11
|
const serviceConfig = config.service || {}
|
|
19
12
|
|
|
20
13
|
if (isKeyEnabled('openapi', serviceConfig)) {
|
|
@@ -27,21 +20,6 @@ export async function platformaticService (app, stackable) {
|
|
|
27
20
|
}
|
|
28
21
|
|
|
29
22
|
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
23
|
await app.register(loadPlugins, stackable.context)
|
|
46
24
|
}
|
|
47
25
|
|
package/lib/generator.js
CHANGED
|
@@ -1,51 +1,261 @@
|
|
|
1
1
|
import { BaseGenerator } from '@platformatic/generators'
|
|
2
|
+
import { join } from 'node:path'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const JS_PLUGIN_WITH_TYPES_SUPPORT = `\
|
|
5
|
+
'use strict'
|
|
6
|
+
|
|
7
|
+
/** @param {import('fastify').FastifyInstance} fastify */
|
|
8
|
+
module.exports = async function (fastify, opts) {
|
|
9
|
+
fastify.decorate('example', 'foobar')
|
|
10
|
+
}
|
|
11
|
+
`
|
|
12
|
+
|
|
13
|
+
const TS_PLUGIN_WITH_TYPES_SUPPORT = `\
|
|
14
|
+
import { type FastifyInstance, type FastifyPluginOptions } from 'fastify'
|
|
15
|
+
|
|
16
|
+
export default async function (fastify: FastifyInstance, opts: FastifyPluginOptions) {
|
|
17
|
+
fastify.decorate('example', 'foobar')
|
|
18
|
+
}
|
|
19
|
+
`
|
|
20
|
+
|
|
21
|
+
const JS_ROUTES_WITH_TYPES_SUPPORT = `\
|
|
22
|
+
'use strict'
|
|
23
|
+
|
|
24
|
+
/** @param {import('fastify').FastifyInstance} fastify */
|
|
25
|
+
module.exports = async function (fastify, opts) {
|
|
26
|
+
fastify.get('/example', async (request, reply) => {
|
|
27
|
+
return { hello: fastify.example }
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
`
|
|
31
|
+
|
|
32
|
+
const TS_ROUTES_WITH_TYPES_SUPPORT = `\
|
|
33
|
+
import { type FastifyInstance, type FastifyPluginOptions } from 'fastify'
|
|
34
|
+
|
|
35
|
+
declare module 'fastify' {
|
|
36
|
+
interface FastifyInstance {
|
|
37
|
+
example: string
|
|
9
38
|
}
|
|
39
|
+
}
|
|
10
40
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
41
|
+
export default async function (fastify: FastifyInstance, opts: FastifyPluginOptions) {
|
|
42
|
+
fastify.get('/example', async (request, reply) => {
|
|
43
|
+
return { hello: fastify.example }
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
`
|
|
47
|
+
|
|
48
|
+
const TEST_ROUTES_JS = `\
|
|
49
|
+
'use strict'
|
|
50
|
+
|
|
51
|
+
const test = require('node:test')
|
|
52
|
+
const assert = require('node:assert')
|
|
53
|
+
const { getServer } = require('../helper')
|
|
54
|
+
|
|
55
|
+
test('example', async (t) => {
|
|
56
|
+
const server = await getServer(t)
|
|
57
|
+
const res = await server.inject({
|
|
58
|
+
method: 'GET',
|
|
59
|
+
url: '/example'
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
assert.strictEqual(res.statusCode, 200)
|
|
63
|
+
assert.deepStrictEqual(res.json(), {
|
|
64
|
+
hello: 'foobar'
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
`
|
|
68
|
+
|
|
69
|
+
const TEST_PLUGIN_JS = `\
|
|
70
|
+
'use strict'
|
|
71
|
+
|
|
72
|
+
const test = require('node:test')
|
|
73
|
+
const assert = require('node:assert')
|
|
74
|
+
const { getServer } = require('../helper')
|
|
75
|
+
|
|
76
|
+
test('example decorator', async (t) => {
|
|
77
|
+
const server = await getServer(t)
|
|
78
|
+
|
|
79
|
+
assert.strictEqual(server.example, 'foobar')
|
|
80
|
+
})
|
|
81
|
+
`
|
|
82
|
+
|
|
83
|
+
const TEST_ROUTES_TS = `\
|
|
84
|
+
import test from 'node:test'
|
|
85
|
+
import assert from 'node:assert'
|
|
86
|
+
import { getServer } from '../helper'
|
|
87
|
+
|
|
88
|
+
test('root', async (t) => {
|
|
89
|
+
const server = await getServer(t)
|
|
90
|
+
const res = await server.inject({
|
|
91
|
+
method: 'GET',
|
|
92
|
+
url: '/example'
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
assert.strictEqual(res.statusCode, 200)
|
|
96
|
+
assert.deepStrictEqual(res.json(), {
|
|
97
|
+
hello: 'foobar'
|
|
98
|
+
})
|
|
99
|
+
})
|
|
100
|
+
`
|
|
101
|
+
|
|
102
|
+
const TEST_PLUGIN_TS = `\
|
|
103
|
+
import test from 'node:test'
|
|
104
|
+
import assert from 'node:assert'
|
|
105
|
+
import { getServer } from '../helper'
|
|
106
|
+
|
|
107
|
+
test('example decorator', async (t) => {
|
|
108
|
+
const server = await getServer(t)
|
|
109
|
+
|
|
110
|
+
assert.strictEqual(server.example, 'foobar')
|
|
111
|
+
})
|
|
112
|
+
`
|
|
113
|
+
|
|
114
|
+
const TEST_HELPER_JS = `
|
|
115
|
+
'use strict'
|
|
116
|
+
|
|
117
|
+
const { join } = require('node:path')
|
|
118
|
+
const { readFile } = require('node:fs/promises')
|
|
119
|
+
const { buildServer } = require('$__MOD__')
|
|
120
|
+
$__REQUIRES__
|
|
121
|
+
|
|
122
|
+
async function getServer (t) {
|
|
123
|
+
$__PRE__
|
|
124
|
+
const config = JSON.parse(await readFile(join(__dirname, '..', 'watt.json'), 'utf8'))
|
|
125
|
+
// Add your config customizations here. For example you want to set
|
|
126
|
+
// all things that are set in the config file to read from an env variable
|
|
127
|
+
config.server ||= {}
|
|
128
|
+
config.server.logger ||= {}
|
|
129
|
+
config.watch = false
|
|
130
|
+
$__CONFIG__
|
|
131
|
+
// Add your config customizations here
|
|
132
|
+
const server = await buildServer(config)
|
|
133
|
+
t.after(() => server.close())
|
|
134
|
+
$__POST__
|
|
135
|
+
return server
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
module.exports.getServer = getServer
|
|
139
|
+
`
|
|
140
|
+
|
|
141
|
+
const TEST_HELPER_TS = `
|
|
142
|
+
import { join } from 'node:path'
|
|
143
|
+
import { readFile } from 'node:fs/promises'
|
|
144
|
+
import { buildServer } from '$__MOD__'
|
|
145
|
+
import { test } from 'node:test'
|
|
146
|
+
$__REQUIRES__
|
|
147
|
+
|
|
148
|
+
type testfn = Parameters<typeof test>[0]
|
|
149
|
+
type TestContext = Parameters<Exclude<testfn, undefined>>[0]
|
|
150
|
+
|
|
151
|
+
export async function getServer (t: TestContext) {
|
|
152
|
+
$__PRE__
|
|
153
|
+
// We go up two folder because this files executes in the dist folder
|
|
154
|
+
const config = JSON.parse(await readFile(join(__dirname, '..', '..', 'watt.json'), 'utf8'))
|
|
155
|
+
// Add your config customizations here. For example you want to set
|
|
156
|
+
// all things that are set in the config file to read from an env variable
|
|
157
|
+
config.server ||= {}
|
|
158
|
+
config.server.logger ||= {}
|
|
159
|
+
config.server.logger.level = 'warn'
|
|
160
|
+
config.watch = false
|
|
161
|
+
$__CONFIG__
|
|
162
|
+
// Add your config customizations here
|
|
163
|
+
const server = await buildServer(config)
|
|
164
|
+
t.after(() => server.close())
|
|
165
|
+
$__POST__
|
|
166
|
+
return server
|
|
167
|
+
}
|
|
168
|
+
`
|
|
169
|
+
|
|
170
|
+
const TS_CONFIG = `
|
|
171
|
+
{
|
|
172
|
+
compilerOptions: {
|
|
173
|
+
module: 'commonjs',
|
|
174
|
+
esModuleInterop: true,
|
|
175
|
+
target: 'es2020',
|
|
176
|
+
sourceMap: true,
|
|
177
|
+
pretty: true,
|
|
178
|
+
noEmitOnError: true,
|
|
179
|
+
incremental: true,
|
|
180
|
+
strict: true,
|
|
181
|
+
outDir: 'dist',
|
|
182
|
+
skipLibCheck: true
|
|
183
|
+
},
|
|
184
|
+
watchOptions: {
|
|
185
|
+
watchFile: 'fixedPollingInterval',
|
|
186
|
+
watchDirectory: 'fixedPollingInterval',
|
|
187
|
+
fallbackPolling: 'dynamicPriority',
|
|
188
|
+
synchronousWatchDirectory: true,
|
|
189
|
+
excludeDirectories: ['**/node_modules', 'dist']
|
|
16
190
|
}
|
|
191
|
+
}
|
|
192
|
+
`
|
|
17
193
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (!this.config.isRuntimeContext) {
|
|
22
|
-
this.addEnvVars(
|
|
23
|
-
{
|
|
24
|
-
PLT_SERVER_HOSTNAME: this.config.hostname,
|
|
25
|
-
PLT_SERVER_LOGGER_LEVEL: 'info',
|
|
26
|
-
PORT: 3042
|
|
27
|
-
},
|
|
28
|
-
{ overwrite: false }
|
|
29
|
-
)
|
|
30
|
-
}
|
|
194
|
+
const PLT_ENVIRONMENT_TEMPLATE = `
|
|
195
|
+
import { type FastifyInstance } from 'fastify'
|
|
196
|
+
import { PlatformaticApplication, PlatformaticServiceConfig } from '@platformatic/service'
|
|
31
197
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
198
|
+
declare module 'fastify' {
|
|
199
|
+
interface FastifyInstance {
|
|
200
|
+
platformatic: PlatformaticApplication<PlatformaticServiceConfig>
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
`
|
|
38
204
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
205
|
+
const README = `
|
|
206
|
+
# Platformatic Service API
|
|
207
|
+
|
|
208
|
+
This is a generated [Platformatic Service](https://docs.platformatic.dev/docs/service/overview) application.
|
|
209
|
+
|
|
210
|
+
## Requirements
|
|
211
|
+
|
|
212
|
+
Platformatic supports macOS, Linux and Windows ([WSL](https://docs.microsoft.com/windows/wsl/) recommended).
|
|
213
|
+
You'll need to have [Node.js](https://nodejs.org/) >= v18.8.0 or >= v20.6.0
|
|
214
|
+
|
|
215
|
+
## Setup
|
|
216
|
+
|
|
217
|
+
Install dependencies:
|
|
218
|
+
|
|
219
|
+
\`\`\`bash
|
|
220
|
+
npm install
|
|
221
|
+
\`\`\`
|
|
222
|
+
|
|
223
|
+
## Usage
|
|
224
|
+
|
|
225
|
+
Run the API with:
|
|
226
|
+
|
|
227
|
+
\`\`\`bash
|
|
228
|
+
npm start
|
|
229
|
+
\`\`\`
|
|
230
|
+
|
|
231
|
+
### Explore
|
|
232
|
+
- ⚡ The Platformatic DB server is running at http://localhost:3042/
|
|
233
|
+
- 📔 View the REST API's Swagger documentation at http://localhost:3042/documentation/
|
|
234
|
+
- 🔍 Try out the GraphiQL web UI at http://localhost:3042/graphiql
|
|
235
|
+
`
|
|
236
|
+
|
|
237
|
+
export function applyTestHelperCustomizations (testHelper, mod, customizations) {
|
|
238
|
+
return testHelper
|
|
239
|
+
.replaceAll('$__MOD__', mod || '@platformatic/service')
|
|
240
|
+
.replaceAll('$__REQUIRES__', customizations.requires || '')
|
|
241
|
+
.replaceAll('$__PRE__', customizations.pre || '')
|
|
242
|
+
.replaceAll('$__CONFIG__', customizations.config || '')
|
|
243
|
+
.replaceAll('$__POST__', customizations.post || '')
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export class Generator extends BaseGenerator {
|
|
247
|
+
constructor (opts = {}) {
|
|
248
|
+
super({
|
|
249
|
+
module: '@platformatic/service',
|
|
250
|
+
...opts
|
|
251
|
+
})
|
|
43
252
|
}
|
|
44
253
|
|
|
45
254
|
getConfigFieldsDefinitions () {
|
|
46
255
|
if (this.config.isRuntimeContext) {
|
|
47
256
|
return []
|
|
48
257
|
}
|
|
258
|
+
|
|
49
259
|
return [
|
|
50
260
|
{
|
|
51
261
|
var: 'PLT_SERVER_HOSTNAME',
|
|
@@ -71,75 +281,135 @@ export class Generator extends BaseGenerator {
|
|
|
71
281
|
]
|
|
72
282
|
}
|
|
73
283
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (!this.config.isUpdating) {
|
|
77
|
-
const PLT_ENVIRONMENT_TEMPLATE = `
|
|
78
|
-
import { FastifyInstance } from 'fastify'
|
|
79
|
-
import { PlatformaticApplication, PlatformaticServiceConfig } from '@platformatic/service'
|
|
284
|
+
getDefaultConfig () {
|
|
285
|
+
const defaultBaseConfig = super.getDefaultConfig()
|
|
80
286
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
287
|
+
return {
|
|
288
|
+
...defaultBaseConfig,
|
|
289
|
+
plugin: true,
|
|
290
|
+
tests: true
|
|
291
|
+
}
|
|
84
292
|
}
|
|
85
|
-
}
|
|
86
|
-
`
|
|
87
293
|
|
|
88
|
-
|
|
89
|
-
|
|
294
|
+
async prepareQuestions () {
|
|
295
|
+
await super.prepareQuestions()
|
|
90
296
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
297
|
+
if (!this.config.skipTypescript) {
|
|
298
|
+
this.questions.push({
|
|
299
|
+
type: 'list',
|
|
300
|
+
name: 'typescript',
|
|
301
|
+
message: 'Do you want to use TypeScript?',
|
|
302
|
+
default: false,
|
|
303
|
+
choices: [
|
|
304
|
+
{ name: 'yes', value: true },
|
|
305
|
+
{ name: 'no', value: false }
|
|
306
|
+
]
|
|
307
|
+
})
|
|
308
|
+
}
|
|
309
|
+
}
|
|
94
310
|
|
|
95
|
-
|
|
96
|
-
|
|
311
|
+
async _beforePrepare () {
|
|
312
|
+
if (this.config.isUpdating) {
|
|
313
|
+
return
|
|
314
|
+
}
|
|
97
315
|
|
|
98
|
-
|
|
316
|
+
if (!this.config.isRuntimeContext) {
|
|
317
|
+
this.addEnvVars(
|
|
318
|
+
{
|
|
319
|
+
PLT_SERVER_HOSTNAME: this.config.hostname,
|
|
320
|
+
PLT_SERVER_LOGGER_LEVEL: 'info',
|
|
321
|
+
PORT: 3042
|
|
322
|
+
},
|
|
323
|
+
{ overwrite: false }
|
|
324
|
+
)
|
|
325
|
+
}
|
|
99
326
|
|
|
100
|
-
|
|
327
|
+
this.config.dependencies = {
|
|
328
|
+
'@platformatic/service': `^${this.platformaticVersion}`
|
|
329
|
+
}
|
|
330
|
+
}
|
|
101
331
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
332
|
+
async _afterPrepare () {
|
|
333
|
+
// if we are NOT updating, create env and files, otherwise leave as it is
|
|
334
|
+
if (this.config.isUpdating) {
|
|
335
|
+
return
|
|
336
|
+
}
|
|
105
337
|
|
|
106
|
-
|
|
338
|
+
if (this.config.typescript) {
|
|
339
|
+
this.addFile({ path: '', file: 'tsconfig.json', contents: TS_CONFIG })
|
|
340
|
+
}
|
|
107
341
|
|
|
108
|
-
|
|
342
|
+
this.addFile({ path: '', file: 'plt-env.d.ts', contents: PLT_ENVIRONMENT_TEMPLATE })
|
|
343
|
+
this.addFile({ path: '', file: 'README.md', contents: README })
|
|
109
344
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
345
|
+
if (this.config.plugin) {
|
|
346
|
+
// create plugin
|
|
347
|
+
this.files.push({
|
|
348
|
+
path: 'plugins',
|
|
349
|
+
file: this.config.typescript ? 'example.ts' : 'example.js',
|
|
350
|
+
contents: this.config.typescript ? TS_PLUGIN_WITH_TYPES_SUPPORT : JS_PLUGIN_WITH_TYPES_SUPPORT
|
|
351
|
+
})
|
|
113
352
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
353
|
+
this.files.push({
|
|
354
|
+
path: 'routes',
|
|
355
|
+
file: this.config.typescript ? 'root.ts' : 'root.js',
|
|
356
|
+
contents: this.config.typescript ? TS_ROUTES_WITH_TYPES_SUPPORT : JS_ROUTES_WITH_TYPES_SUPPORT
|
|
357
|
+
})
|
|
119
358
|
|
|
120
|
-
this.
|
|
121
|
-
|
|
359
|
+
if (this.config.tests) {
|
|
360
|
+
if (this.config.typescript) {
|
|
361
|
+
this.files.push({
|
|
362
|
+
path: 'test',
|
|
363
|
+
file: 'helper.ts',
|
|
364
|
+
contents: applyTestHelperCustomizations(TEST_HELPER_TS, this.module, this.testHelperCustomizations ?? {})
|
|
365
|
+
})
|
|
366
|
+
this.files.push({
|
|
367
|
+
path: join('test', 'plugins'),
|
|
368
|
+
file: 'example.test.ts',
|
|
369
|
+
contents: TEST_PLUGIN_TS
|
|
370
|
+
})
|
|
371
|
+
this.files.push({
|
|
372
|
+
path: join('test', 'routes'),
|
|
373
|
+
file: 'root.test.ts',
|
|
374
|
+
contents: TEST_ROUTES_TS
|
|
375
|
+
})
|
|
376
|
+
} else {
|
|
377
|
+
this.files.push({
|
|
378
|
+
path: 'test',
|
|
379
|
+
file: 'helper.js',
|
|
380
|
+
contents: applyTestHelperCustomizations(TEST_HELPER_JS, this.module, this.testHelperCustomizations ?? {})
|
|
381
|
+
})
|
|
382
|
+
this.files.push({
|
|
383
|
+
path: join('test', 'plugins'),
|
|
384
|
+
file: 'example.test.js',
|
|
385
|
+
contents: TEST_PLUGIN_JS
|
|
386
|
+
})
|
|
387
|
+
this.files.push({
|
|
388
|
+
path: join('test', 'routes'),
|
|
389
|
+
file: 'root.test.js',
|
|
390
|
+
contents: TEST_ROUTES_JS
|
|
391
|
+
})
|
|
392
|
+
}
|
|
393
|
+
}
|
|
122
394
|
}
|
|
123
395
|
}
|
|
124
396
|
|
|
125
397
|
async _getConfigFileContents () {
|
|
126
|
-
const { isRuntimeContext } = this.config
|
|
127
|
-
const version = this.platformaticVersion
|
|
128
398
|
const config = {
|
|
129
|
-
$schema: `https://schemas.platformatic.dev/@platformatic/service/${
|
|
399
|
+
$schema: `https://schemas.platformatic.dev/@platformatic/service/${this.platformaticVersion}.json`,
|
|
130
400
|
service: {
|
|
131
401
|
openapi: true
|
|
132
402
|
},
|
|
133
403
|
watch: true
|
|
134
404
|
}
|
|
405
|
+
|
|
135
406
|
if (this.config.plugin) {
|
|
136
407
|
config.plugins = {
|
|
137
|
-
paths: [{ path: './plugins', encapsulate: false }, './routes']
|
|
138
|
-
typescript: `{${this.getEnvVarName('PLT_TYPESCRIPT')}}`
|
|
408
|
+
paths: [{ path: './plugins', encapsulate: false }, './routes']
|
|
139
409
|
}
|
|
140
410
|
}
|
|
141
411
|
|
|
142
|
-
if (!isRuntimeContext) {
|
|
412
|
+
if (!this.config.isRuntimeContext) {
|
|
143
413
|
config.server = {
|
|
144
414
|
hostname: '{PLT_SERVER_HOSTNAME}',
|
|
145
415
|
port: '{PORT}',
|
package/lib/plugins/graphql.js
CHANGED
package/lib/plugins/openapi.js
CHANGED
package/lib/plugins/plugins.js
CHANGED
|
@@ -1,53 +1,9 @@
|
|
|
1
|
-
import { kMetadata } from '@platformatic/utils'
|
|
2
1
|
import fp from 'fastify-plugin'
|
|
3
|
-
import { readFile } from 'node:fs/promises'
|
|
4
|
-
import { join, resolve } from 'node:path'
|
|
5
|
-
import { getJSPluginPath, isFileAccessible } from '../utils.js'
|
|
6
2
|
import { sandboxWrapper } from './sandbox-wrapper.js'
|
|
7
3
|
|
|
8
4
|
async function loadPluginsPlugin (app, context) {
|
|
9
5
|
const config = app.platformatic.config
|
|
10
6
|
|
|
11
|
-
let isOutDirAccessible = false
|
|
12
|
-
let outDir = null
|
|
13
|
-
|
|
14
|
-
const workingDir = context?.directory ?? config[kMetadata].root
|
|
15
|
-
const tsConfigPath = config.plugins.typescript?.tsConfig || join(workingDir, 'tsconfig.json')
|
|
16
|
-
|
|
17
|
-
// If the tsconfig.json file exists, then we need to adjust the plugin paths
|
|
18
|
-
// to point to the compiled JS files.
|
|
19
|
-
const isTsConfigAccessible = await isFileAccessible(tsConfigPath)
|
|
20
|
-
if (isTsConfigAccessible) {
|
|
21
|
-
const tsConfig = JSON.parse(await readFile(tsConfigPath, 'utf8'))
|
|
22
|
-
outDir = resolve(workingDir, tsConfig.compilerOptions.outDir)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/* c8 ignore next 3 */
|
|
26
|
-
if (config.plugins.typescript?.outDir) {
|
|
27
|
-
outDir = config.plugins.typescript.outDir
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (outDir) {
|
|
31
|
-
isOutDirAccessible = await isFileAccessible(outDir)
|
|
32
|
-
|
|
33
|
-
if (context?.isProduction && !isOutDirAccessible) {
|
|
34
|
-
throw new Error(
|
|
35
|
-
`Cannot access directory '${outDir}'. Please run the 'build' command before running in production mode.`
|
|
36
|
-
)
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (config.plugins.paths && isOutDirAccessible) {
|
|
41
|
-
config.plugins.paths = config.plugins.paths.map(plugin => {
|
|
42
|
-
/* c8 ignore next 3 */
|
|
43
|
-
const tmp =
|
|
44
|
-
typeof plugin === 'string'
|
|
45
|
-
? getJSPluginPath(workingDir, plugin, outDir)
|
|
46
|
-
: { ...plugin, path: getJSPluginPath(workingDir, plugin.path, outDir) }
|
|
47
|
-
return tmp
|
|
48
|
-
})
|
|
49
|
-
}
|
|
50
|
-
|
|
51
7
|
await app.register(sandboxWrapper, { packages: config.plugins.packages, paths: config.plugins.paths })
|
|
52
8
|
}
|
|
53
9
|
|
package/lib/schema.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
2
|
|
|
3
|
+
import { schemaComponents as basicSchemaComponents } from '@platformatic/basic'
|
|
3
4
|
import {
|
|
4
5
|
fastifyServer as server,
|
|
5
6
|
schemaComponents as utilsSchemaComponents,
|
|
6
7
|
watch,
|
|
7
8
|
wrappedRuntime
|
|
8
|
-
} from '@platformatic/
|
|
9
|
+
} from '@platformatic/foundation'
|
|
9
10
|
import { readFileSync } from 'node:fs'
|
|
10
11
|
import { resolve } from 'node:path'
|
|
11
12
|
|
|
@@ -1091,45 +1092,6 @@ export const plugins = {
|
|
|
1091
1092
|
}
|
|
1092
1093
|
]
|
|
1093
1094
|
}
|
|
1094
|
-
},
|
|
1095
|
-
typescript: {
|
|
1096
|
-
anyOf: [
|
|
1097
|
-
{
|
|
1098
|
-
type: 'object',
|
|
1099
|
-
properties: {
|
|
1100
|
-
enabled: {
|
|
1101
|
-
anyOf: [
|
|
1102
|
-
{
|
|
1103
|
-
type: 'boolean'
|
|
1104
|
-
},
|
|
1105
|
-
{
|
|
1106
|
-
type: 'string'
|
|
1107
|
-
}
|
|
1108
|
-
]
|
|
1109
|
-
},
|
|
1110
|
-
tsConfig: {
|
|
1111
|
-
type: 'string',
|
|
1112
|
-
resolvePath: true
|
|
1113
|
-
},
|
|
1114
|
-
outDir: {
|
|
1115
|
-
type: 'string',
|
|
1116
|
-
resolvePath: true
|
|
1117
|
-
},
|
|
1118
|
-
flags: {
|
|
1119
|
-
type: 'array',
|
|
1120
|
-
items: {
|
|
1121
|
-
type: 'string'
|
|
1122
|
-
}
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
},
|
|
1126
|
-
{
|
|
1127
|
-
type: 'boolean'
|
|
1128
|
-
},
|
|
1129
|
-
{
|
|
1130
|
-
type: 'string'
|
|
1131
|
-
}
|
|
1132
|
-
]
|
|
1133
1095
|
}
|
|
1134
1096
|
},
|
|
1135
1097
|
additionalProperties: false,
|
|
@@ -1293,40 +1255,6 @@ export const service = {
|
|
|
1293
1255
|
additionalProperties: false
|
|
1294
1256
|
}
|
|
1295
1257
|
|
|
1296
|
-
export const clients = {
|
|
1297
|
-
type: 'array',
|
|
1298
|
-
items: {
|
|
1299
|
-
type: 'object',
|
|
1300
|
-
properties: {
|
|
1301
|
-
serviceId: {
|
|
1302
|
-
type: 'string'
|
|
1303
|
-
},
|
|
1304
|
-
name: {
|
|
1305
|
-
type: 'string'
|
|
1306
|
-
},
|
|
1307
|
-
type: {
|
|
1308
|
-
type: 'string',
|
|
1309
|
-
enum: ['openapi', 'graphql']
|
|
1310
|
-
},
|
|
1311
|
-
path: {
|
|
1312
|
-
type: 'string',
|
|
1313
|
-
resolvePath: true
|
|
1314
|
-
},
|
|
1315
|
-
schema: {
|
|
1316
|
-
type: 'string',
|
|
1317
|
-
resolvePath: true
|
|
1318
|
-
},
|
|
1319
|
-
url: {
|
|
1320
|
-
type: 'string'
|
|
1321
|
-
},
|
|
1322
|
-
fullResponse: { type: 'boolean' },
|
|
1323
|
-
fullRequest: { type: 'boolean' },
|
|
1324
|
-
validateResponse: { type: 'boolean' }
|
|
1325
|
-
},
|
|
1326
|
-
additionalProperties: false
|
|
1327
|
-
}
|
|
1328
|
-
}
|
|
1329
|
-
|
|
1330
1258
|
export const schemaComponents = {
|
|
1331
1259
|
$defs,
|
|
1332
1260
|
plugins,
|
|
@@ -1335,8 +1263,7 @@ export const schemaComponents = {
|
|
|
1335
1263
|
proxy,
|
|
1336
1264
|
graphqlBase,
|
|
1337
1265
|
graphql,
|
|
1338
|
-
service
|
|
1339
|
-
clients
|
|
1266
|
+
service
|
|
1340
1267
|
}
|
|
1341
1268
|
|
|
1342
1269
|
export const schema = {
|
|
@@ -1368,8 +1295,8 @@ export const schema = {
|
|
|
1368
1295
|
module: {
|
|
1369
1296
|
type: 'string'
|
|
1370
1297
|
},
|
|
1298
|
+
application: basicSchemaComponents.application,
|
|
1371
1299
|
service,
|
|
1372
|
-
clients,
|
|
1373
1300
|
runtime: wrappedRuntime
|
|
1374
1301
|
},
|
|
1375
1302
|
additionalProperties: false,
|
package/lib/stackable.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { BaseStackable, cleanBasePath, ensureTrailingSlash, getServerUrl } from '@platformatic/basic'
|
|
2
|
+
import { buildPinoFormatters, buildPinoTimestamp, deepmerge, features, isKeyEnabled } from '@platformatic/foundation'
|
|
2
3
|
import { telemetry } from '@platformatic/telemetry'
|
|
3
|
-
import { compile } from '@platformatic/ts-compiler'
|
|
4
|
-
import { buildPinoFormatters, buildPinoTimestamp, deepmerge, features, isKeyEnabled } from '@platformatic/utils'
|
|
5
4
|
import fastify from 'fastify'
|
|
6
5
|
import { printSchema } from 'graphql'
|
|
7
6
|
import { randomUUID } from 'node:crypto'
|
|
@@ -88,15 +87,6 @@ export class ServiceStackable extends BaseStackable {
|
|
|
88
87
|
return this.#app?.close()
|
|
89
88
|
}
|
|
90
89
|
|
|
91
|
-
async build () {
|
|
92
|
-
return compile({
|
|
93
|
-
tsConfig: this.config.plugins?.typescript?.tsConfig,
|
|
94
|
-
flags: this.config.plugins?.typescript?.flags,
|
|
95
|
-
cwd: this.root,
|
|
96
|
-
logger: this.logger
|
|
97
|
-
})
|
|
98
|
-
}
|
|
99
|
-
|
|
100
90
|
async inject (injectParams, onInject) {
|
|
101
91
|
const response = await this.#app.inject(injectParams, onInject)
|
|
102
92
|
|
package/lib/upgrade.js
CHANGED
package/lib/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { access, readFile, stat } from 'node:fs/promises'
|
|
2
|
-
import {
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
3
|
|
|
4
4
|
let _isDocker
|
|
5
5
|
|
|
@@ -38,34 +38,6 @@ export async function isFileAccessible (filename, directory) {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
export function getJSPluginPath (workingDir, tsPluginPath, compileDir) {
|
|
42
|
-
if (tsPluginPath.endsWith('js')) {
|
|
43
|
-
return tsPluginPath
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (tsPluginPath.indexOf(compileDir) === 0) {
|
|
47
|
-
// In this case, we passed through this function before and we have adjusted
|
|
48
|
-
// the path of the plugin to point to the dist/ folder. Then we restarted.
|
|
49
|
-
// Therefore, we can just return the path as is.
|
|
50
|
-
return tsPluginPath
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const isTs = tsPluginPath.endsWith('ts')
|
|
54
|
-
let newBaseName
|
|
55
|
-
|
|
56
|
-
/* c8 ignore next 5 */
|
|
57
|
-
if (isTs) {
|
|
58
|
-
newBaseName = basename(tsPluginPath, '.ts') + '.js'
|
|
59
|
-
} else {
|
|
60
|
-
newBaseName = basename(tsPluginPath)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const tsPluginRelativePath = relative(workingDir, tsPluginPath)
|
|
64
|
-
const jsPluginRelativePath = join(dirname(tsPluginRelativePath), newBaseName)
|
|
65
|
-
|
|
66
|
-
return join(compileDir, jsPluginRelativePath)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
41
|
export async function sanitizeHTTPSArgument (arg) {
|
|
70
42
|
if (typeof arg === 'string') {
|
|
71
43
|
return arg
|
package/lib/versions/0.16.0.js
CHANGED
package/lib/versions/0.28.0.js
CHANGED
package/lib/versions/2.0.0.js
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
version: '2.99.0',
|
|
3
|
+
up (config) {
|
|
4
|
+
if (typeof config.plugins?.typescript !== 'undefined') {
|
|
5
|
+
delete config.plugins.typescript
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (typeof config.clients !== 'undefined') {
|
|
9
|
+
delete config.clients
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return config
|
|
13
|
+
}
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/service",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -27,9 +27,8 @@
|
|
|
27
27
|
"pino-abstract-transport": "^2.0.0",
|
|
28
28
|
"self-cert": "^2.0.0",
|
|
29
29
|
"split2": "^4.2.0",
|
|
30
|
-
"strip-ansi": "^7.1.0",
|
|
31
30
|
"typescript": "^5.5.4",
|
|
32
|
-
"undici": "7.
|
|
31
|
+
"undici": "7.11.0",
|
|
33
32
|
"vscode-json-languageservice": "^5.3.9",
|
|
34
33
|
"why-is-node-running": "^2.2.2",
|
|
35
34
|
"yaml": "^2.4.1"
|
|
@@ -43,7 +42,7 @@
|
|
|
43
42
|
"@fastify/static": "^8.0.0",
|
|
44
43
|
"@fastify/swagger": "^9.0.0",
|
|
45
44
|
"@fastify/under-pressure": "^9.0.0",
|
|
46
|
-
"@scalar/fastify-api-reference": "1.
|
|
45
|
+
"@scalar/fastify-api-reference": "1.33.0",
|
|
47
46
|
"@types/node": "^22.10.6",
|
|
48
47
|
"@types/ws": "^8.5.10",
|
|
49
48
|
"ajv": "^8.12.0",
|
|
@@ -51,10 +50,8 @@
|
|
|
51
50
|
"close-with-grace": "^2.0.0",
|
|
52
51
|
"code-block-writer": "^13.0.1",
|
|
53
52
|
"colorette": "^2.0.20",
|
|
54
|
-
"commist": "^3.2.0",
|
|
55
53
|
"console-table-printer": "^2.12.0",
|
|
56
54
|
"env-schema": "^6.0.0",
|
|
57
|
-
"es-main": "^1.3.0",
|
|
58
55
|
"execa": "^9.0.0",
|
|
59
56
|
"fast-json-patch": "^3.1.1",
|
|
60
57
|
"fastify": "^5.0.0",
|
|
@@ -65,19 +62,20 @@
|
|
|
65
62
|
"minimist": "^1.2.8",
|
|
66
63
|
"my-ua-parser": "^2.0.2",
|
|
67
64
|
"ora": "^6.3.1",
|
|
68
|
-
"pino": "^9.
|
|
65
|
+
"pino": "^9.9.0",
|
|
69
66
|
"pino-pretty": "^13.0.0",
|
|
70
67
|
"rfdc": "^1.3.1",
|
|
71
68
|
"semgrator": "^0.3.0",
|
|
72
69
|
"undici": "^7.0.0",
|
|
73
|
-
"@platformatic/basic": "3.0.0-alpha.
|
|
74
|
-
"@platformatic/generators": "3.0.0-alpha.
|
|
75
|
-
"@platformatic/metrics": "3.0.0-alpha.
|
|
76
|
-
"@platformatic/
|
|
77
|
-
"@platformatic/
|
|
78
|
-
"@platformatic/
|
|
79
|
-
|
|
80
|
-
|
|
70
|
+
"@platformatic/basic": "3.0.0-alpha.2",
|
|
71
|
+
"@platformatic/generators": "3.0.0-alpha.2",
|
|
72
|
+
"@platformatic/metrics": "3.0.0-alpha.2",
|
|
73
|
+
"@platformatic/scalar-theme": "3.0.0-alpha.2",
|
|
74
|
+
"@platformatic/telemetry": "3.0.0-alpha.2",
|
|
75
|
+
"@platformatic/foundation": "3.0.0-alpha.2"
|
|
76
|
+
},
|
|
77
|
+
"engines": {
|
|
78
|
+
"node": ">=22.18.0"
|
|
81
79
|
},
|
|
82
80
|
"scripts": {
|
|
83
81
|
"test": "pnpm run lint && borp --concurrency=1 --timeout 1200000 --no-typescript",
|
package/schema.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$id": "https://schemas.platformatic.dev/@platformatic/service/3.0.0-alpha.
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
2
|
+
"$id": "https://schemas.platformatic.dev/@platformatic/service/3.0.0-alpha.2.json",
|
|
3
|
+
"version": "3.0.0-alpha.2",
|
|
4
4
|
"title": "Platformatic Service Config",
|
|
5
5
|
"type": "object",
|
|
6
6
|
"properties": {
|
|
@@ -629,45 +629,6 @@
|
|
|
629
629
|
}
|
|
630
630
|
]
|
|
631
631
|
}
|
|
632
|
-
},
|
|
633
|
-
"typescript": {
|
|
634
|
-
"anyOf": [
|
|
635
|
-
{
|
|
636
|
-
"type": "object",
|
|
637
|
-
"properties": {
|
|
638
|
-
"enabled": {
|
|
639
|
-
"anyOf": [
|
|
640
|
-
{
|
|
641
|
-
"type": "boolean"
|
|
642
|
-
},
|
|
643
|
-
{
|
|
644
|
-
"type": "string"
|
|
645
|
-
}
|
|
646
|
-
]
|
|
647
|
-
},
|
|
648
|
-
"tsConfig": {
|
|
649
|
-
"type": "string",
|
|
650
|
-
"resolvePath": true
|
|
651
|
-
},
|
|
652
|
-
"outDir": {
|
|
653
|
-
"type": "string",
|
|
654
|
-
"resolvePath": true
|
|
655
|
-
},
|
|
656
|
-
"flags": {
|
|
657
|
-
"type": "array",
|
|
658
|
-
"items": {
|
|
659
|
-
"type": "string"
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
},
|
|
664
|
-
{
|
|
665
|
-
"type": "boolean"
|
|
666
|
-
},
|
|
667
|
-
{
|
|
668
|
-
"type": "string"
|
|
669
|
-
}
|
|
670
|
-
]
|
|
671
632
|
}
|
|
672
633
|
},
|
|
673
634
|
"additionalProperties": false,
|
|
@@ -864,6 +825,13 @@
|
|
|
864
825
|
"module": {
|
|
865
826
|
"type": "string"
|
|
866
827
|
},
|
|
828
|
+
"application": {
|
|
829
|
+
"type": "object",
|
|
830
|
+
"properties": {},
|
|
831
|
+
"additionalProperties": false,
|
|
832
|
+
"required": [],
|
|
833
|
+
"default": {}
|
|
834
|
+
},
|
|
867
835
|
"service": {
|
|
868
836
|
"type": "object",
|
|
869
837
|
"properties": {
|
|
@@ -1025,48 +993,6 @@
|
|
|
1025
993
|
},
|
|
1026
994
|
"additionalProperties": false
|
|
1027
995
|
},
|
|
1028
|
-
"clients": {
|
|
1029
|
-
"type": "array",
|
|
1030
|
-
"items": {
|
|
1031
|
-
"type": "object",
|
|
1032
|
-
"properties": {
|
|
1033
|
-
"serviceId": {
|
|
1034
|
-
"type": "string"
|
|
1035
|
-
},
|
|
1036
|
-
"name": {
|
|
1037
|
-
"type": "string"
|
|
1038
|
-
},
|
|
1039
|
-
"type": {
|
|
1040
|
-
"type": "string",
|
|
1041
|
-
"enum": [
|
|
1042
|
-
"openapi",
|
|
1043
|
-
"graphql"
|
|
1044
|
-
]
|
|
1045
|
-
},
|
|
1046
|
-
"path": {
|
|
1047
|
-
"type": "string",
|
|
1048
|
-
"resolvePath": true
|
|
1049
|
-
},
|
|
1050
|
-
"schema": {
|
|
1051
|
-
"type": "string",
|
|
1052
|
-
"resolvePath": true
|
|
1053
|
-
},
|
|
1054
|
-
"url": {
|
|
1055
|
-
"type": "string"
|
|
1056
|
-
},
|
|
1057
|
-
"fullResponse": {
|
|
1058
|
-
"type": "boolean"
|
|
1059
|
-
},
|
|
1060
|
-
"fullRequest": {
|
|
1061
|
-
"type": "boolean"
|
|
1062
|
-
},
|
|
1063
|
-
"validateResponse": {
|
|
1064
|
-
"type": "boolean"
|
|
1065
|
-
}
|
|
1066
|
-
},
|
|
1067
|
-
"additionalProperties": false
|
|
1068
|
-
}
|
|
1069
|
-
},
|
|
1070
996
|
"runtime": {
|
|
1071
997
|
"type": "object",
|
|
1072
998
|
"properties": {
|
package/lib/plugins/clients.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import client from '@platformatic/client'
|
|
2
|
-
import { kMetadata } from '@platformatic/utils'
|
|
3
|
-
import fp from 'fastify-plugin'
|
|
4
|
-
import { createRequire } from 'node:module'
|
|
5
|
-
import { resolve } from 'node:path'
|
|
6
|
-
async function setupClientsPlugin (app, opts) {
|
|
7
|
-
for (const { path, url, serviceId, name, schema, type, fullRequest, fullResponse, validateResponse } of opts) {
|
|
8
|
-
if (path) {
|
|
9
|
-
const require = createRequire(resolve(app.platformatic.config[kMetadata].root, 'noop.js'))
|
|
10
|
-
app.register(await require(path), { url, serviceId })
|
|
11
|
-
} else {
|
|
12
|
-
app.register(client, { url, serviceId, name, path: schema, type, fullRequest, fullResponse, validateResponse })
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const setupClients = fp(setupClientsPlugin)
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import compiler from '@platformatic/ts-compiler'
|
|
2
|
-
import { kMetadata } from '@platformatic/utils'
|
|
3
|
-
import fp from 'fastify-plugin'
|
|
4
|
-
|
|
5
|
-
async function setupTsCompilerPlugin (app, context) {
|
|
6
|
-
const config = app.platformatic.config
|
|
7
|
-
|
|
8
|
-
await compiler.compile({
|
|
9
|
-
tsConfig: config.plugins?.typescript?.tsConfig,
|
|
10
|
-
flags: config.plugins?.typescript?.flags,
|
|
11
|
-
cwd: context?.directory ?? config[kMetadata].root,
|
|
12
|
-
clean: false,
|
|
13
|
-
logger: app.log
|
|
14
|
-
})
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const setupTsCompiler = fp(setupTsCompilerPlugin)
|