@platformatic/service 3.4.1 → 3.5.0
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/LICENSE +1 -1
- package/config.d.ts +450 -94
- package/eslint.config.js +4 -6
- package/index.d.ts +55 -48
- package/index.js +44 -179
- package/lib/application.js +35 -0
- package/lib/capability.js +281 -0
- package/lib/compile.js +2 -52
- package/lib/generator.js +426 -0
- 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 +43 -32
- package/lib/plugins/plugins.js +6 -53
- package/lib/{root-endpoint/index.js → plugins/root.js} +9 -8
- package/lib/plugins/sandbox-wrapper.js +65 -63
- package/lib/schema.js +1075 -203
- package/lib/upgrade.js +6 -8
- package/lib/utils.js +30 -83
- package/lib/versions/0.16.0.js +14 -15
- package/lib/versions/{from-zero-twenty-eight-to-will-see.js → 0.28.0.js} +3 -6
- package/lib/versions/2.0.0.js +4 -7
- package/lib/versions/3.0.0.js +14 -0
- package/package.json +28 -36
- package/schema.json +1452 -165
- 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/clients.js +0 -16
- package/lib/plugins/metrics.js +0 -244
- package/lib/plugins/typescript.js +0 -20
- package/lib/stackable.js +0 -306
- package/lib/start.js +0 -175
- 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/lib/plugins/plugins.js
CHANGED
|
@@ -1,57 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import fp from 'fastify-plugin'
|
|
2
|
+
import { sandboxWrapper } from './sandbox-wrapper.js'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const fp = require('fastify-plugin')
|
|
6
|
-
const wrapper = require('./sandbox-wrapper')
|
|
4
|
+
async function loadPluginsPlugin (app, context) {
|
|
5
|
+
const config = app.platformatic.config
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
async function loadPlugins (app, opts) {
|
|
11
|
-
const configManager = app.platformatic.configManager
|
|
12
|
-
const config = configManager.current
|
|
13
|
-
|
|
14
|
-
let isOutDirAccessible = false
|
|
15
|
-
let outDir = null
|
|
16
|
-
|
|
17
|
-
const workingDir = opts?.context?.directory ?? configManager.dirname
|
|
18
|
-
const tsConfigPath = configManager.current.plugins.typescript?.tsConfig || join(workingDir, 'tsconfig.json')
|
|
19
|
-
|
|
20
|
-
// If the tsconfig.json file exists, then we need to adjust the plugin paths
|
|
21
|
-
// to point to the compiled JS files.
|
|
22
|
-
const isTsConfigAccessible = await isFileAccessible(tsConfigPath)
|
|
23
|
-
if (isTsConfigAccessible) {
|
|
24
|
-
const tsConfig = JSON.parse(await readFile(tsConfigPath, 'utf8'))
|
|
25
|
-
outDir = resolve(workingDir, tsConfig.compilerOptions.outDir)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/* c8 ignore next 3 */
|
|
29
|
-
if (configManager.current.plugins.typescript?.outDir) {
|
|
30
|
-
outDir = configManager.current.plugins.typescript.outDir
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (outDir) {
|
|
34
|
-
isOutDirAccessible = await isFileAccessible(outDir)
|
|
35
|
-
|
|
36
|
-
if (opts.context?.isProduction && !isOutDirAccessible) {
|
|
37
|
-
throw new Error(
|
|
38
|
-
`Cannot access directory '${outDir}'. Please run the 'build' command before running in production mode.`
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (config.plugins.paths && isOutDirAccessible) {
|
|
44
|
-
config.plugins.paths = config.plugins.paths.map(plugin => {
|
|
45
|
-
/* c8 ignore next 3 */
|
|
46
|
-
const tmp =
|
|
47
|
-
typeof plugin === 'string'
|
|
48
|
-
? getJSPluginPath(workingDir, plugin, outDir)
|
|
49
|
-
: { ...plugin, path: getJSPluginPath(workingDir, plugin.path, outDir) }
|
|
50
|
-
return tmp
|
|
51
|
-
})
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
await app.register(wrapper, { packages: config.plugins.packages, paths: config.plugins.paths })
|
|
7
|
+
await app.register(sandboxWrapper, { packages: config.plugins.packages, paths: config.plugins.paths })
|
|
55
8
|
}
|
|
56
9
|
|
|
57
|
-
|
|
10
|
+
export const loadPlugins = fp(loadPluginsPlugin)
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import fastifyStatic from '@fastify/static'
|
|
2
|
+
import fp from 'fastify-plugin'
|
|
3
|
+
import userAgentParser from 'my-ua-parser'
|
|
4
|
+
import { join } from 'node:path'
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
const fastifyStatic = require('@fastify/static')
|
|
5
|
-
const userAgentParser = require('my-ua-parser')
|
|
6
|
-
|
|
7
|
-
module.exports = async (app, opts) => {
|
|
6
|
+
async function setupRootPlugin (app) {
|
|
8
7
|
app.register(fastifyStatic, {
|
|
9
|
-
root:
|
|
8
|
+
root: join(import.meta.dirname, '../../public')
|
|
10
9
|
})
|
|
11
10
|
|
|
12
11
|
// root endpoint
|
|
@@ -23,6 +22,8 @@ module.exports = async (app, opts) => {
|
|
|
23
22
|
}
|
|
24
23
|
}
|
|
25
24
|
return { message: 'Welcome to Platformatic! Please visit https://docs.platformatic.dev' }
|
|
26
|
-
}
|
|
25
|
+
}
|
|
27
26
|
})
|
|
28
27
|
}
|
|
28
|
+
|
|
29
|
+
export const setupRoot = fp(setupRootPlugin)
|
|
@@ -1,61 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const { pathToFileURL } = require('node:url')
|
|
9
|
-
|
|
10
|
-
module.exports = fp(async function (app, opts) {
|
|
11
|
-
// fake require next to the configManager dirname
|
|
12
|
-
const _require = createRequire(join(app.platformatic.configManager.dirname, 'package.json'))
|
|
13
|
-
for (const plugin of opts.packages || []) {
|
|
14
|
-
const name = typeof plugin === 'string' ? plugin : plugin.name
|
|
15
|
-
const url = pathToFileURL(_require.resolve(name))
|
|
16
|
-
const loaded = await import(url)
|
|
17
|
-
await app.register(loaded, plugin.options)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
for (let plugin of opts.paths || []) {
|
|
21
|
-
if (typeof plugin === 'string') {
|
|
22
|
-
plugin = { path: plugin, encapsulate: true }
|
|
23
|
-
}
|
|
24
|
-
if (plugin.path && (await stat(plugin.path)).isDirectory()) {
|
|
25
|
-
const patternOptions = patternOptionsFromPlugin(plugin)
|
|
26
|
-
|
|
27
|
-
app.register(autoload, {
|
|
28
|
-
dir: plugin.path,
|
|
29
|
-
encapsulate: plugin.encapsulate !== false,
|
|
30
|
-
maxDepth: plugin.maxDepth,
|
|
31
|
-
options: plugin.options,
|
|
32
|
-
autoHooks: plugin.autoHooks,
|
|
33
|
-
cascadeHooks: plugin.cascadeHooks,
|
|
34
|
-
overwriteHooks: plugin.overwriteHooks,
|
|
35
|
-
routeParams: plugin.routeParams,
|
|
36
|
-
forceESM: plugin.forceESM,
|
|
37
|
-
ignoreFilter: plugin.ignoreFilter,
|
|
38
|
-
matchFilter: plugin.matchFilter,
|
|
39
|
-
...patternOptions,
|
|
40
|
-
})
|
|
41
|
-
} else {
|
|
42
|
-
let loaded = await import(pathToFileURL(plugin.path))
|
|
43
|
-
/* c8 ignore next 3 */
|
|
44
|
-
if (loaded.__esModule === true || typeof loaded.default === 'function') {
|
|
45
|
-
loaded = loaded.default
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (plugin.encapsulate === false) {
|
|
49
|
-
const skipOverride = loaded[Symbol.for('skip-override')]
|
|
50
|
-
loaded[Symbol.for('skip-override')] = true
|
|
51
|
-
await app.register(loaded, plugin.options)
|
|
52
|
-
loaded[Symbol.for('skip-override')] = skipOverride
|
|
53
|
-
} else {
|
|
54
|
-
await app.register(loaded, plugin.options)
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
})
|
|
1
|
+
import autoload from '@fastify/autoload'
|
|
2
|
+
import { kMetadata } from '@platformatic/foundation'
|
|
3
|
+
import fp from 'fastify-plugin'
|
|
4
|
+
import { stat } from 'node:fs/promises'
|
|
5
|
+
import { createRequire } from 'node:module'
|
|
6
|
+
import { isAbsolute, resolve } from 'node:path'
|
|
7
|
+
import { pathToFileURL } from 'node:url'
|
|
59
8
|
|
|
60
9
|
/**
|
|
61
10
|
* Creates an object for pattern specific options. This ensures that
|
|
@@ -68,11 +17,7 @@ function patternOptionsFromPlugin (plugin) {
|
|
|
68
17
|
const config = {}
|
|
69
18
|
|
|
70
19
|
// Expected keys for autoload plugin options that expect regexp patterns
|
|
71
|
-
const patternOptionKeys = [
|
|
72
|
-
'ignorePattern',
|
|
73
|
-
'indexPattern',
|
|
74
|
-
'autoHooksPattern',
|
|
75
|
-
]
|
|
20
|
+
const patternOptionKeys = ['ignorePattern', 'indexPattern', 'autoHooksPattern']
|
|
76
21
|
|
|
77
22
|
for (const key of patternOptionKeys) {
|
|
78
23
|
const pattern = plugin[key]
|
|
@@ -104,3 +49,60 @@ function stringPatternToRegExp (stringPattern) {
|
|
|
104
49
|
return undefined
|
|
105
50
|
}
|
|
106
51
|
}
|
|
52
|
+
|
|
53
|
+
async function sandboxWrapperPlugin (app, options) {
|
|
54
|
+
const require = createRequire(resolve(app.platformatic.config[kMetadata].root, 'noop.js'))
|
|
55
|
+
|
|
56
|
+
for (const plugin of options.packages || []) {
|
|
57
|
+
const name = typeof plugin === 'string' ? plugin : plugin.name
|
|
58
|
+
const url = pathToFileURL(require.resolve(name))
|
|
59
|
+
const loaded = await import(url)
|
|
60
|
+
await app.register(loaded, plugin.options)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
for (let plugin of options.paths || []) {
|
|
64
|
+
if (typeof plugin === 'string') {
|
|
65
|
+
plugin = { path: plugin, encapsulate: true }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (plugin.path && !isAbsolute(plugin.path)) {
|
|
69
|
+
plugin.path = resolve(app.platformatic.config[kMetadata].root, plugin.path)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (plugin.path && (await stat(plugin.path)).isDirectory()) {
|
|
73
|
+
const patternOptions = patternOptionsFromPlugin(plugin)
|
|
74
|
+
|
|
75
|
+
app.register(autoload, {
|
|
76
|
+
dir: plugin.path,
|
|
77
|
+
encapsulate: plugin.encapsulate !== false,
|
|
78
|
+
maxDepth: plugin.maxDepth,
|
|
79
|
+
options: plugin.options,
|
|
80
|
+
autoHooks: plugin.autoHooks,
|
|
81
|
+
cascadeHooks: plugin.cascadeHooks,
|
|
82
|
+
overwriteHooks: plugin.overwriteHooks,
|
|
83
|
+
routeParams: plugin.routeParams,
|
|
84
|
+
forceESM: plugin.forceESM,
|
|
85
|
+
ignoreFilter: plugin.ignoreFilter,
|
|
86
|
+
matchFilter: plugin.matchFilter,
|
|
87
|
+
...patternOptions
|
|
88
|
+
})
|
|
89
|
+
} else {
|
|
90
|
+
let loaded = await import(pathToFileURL(plugin.path))
|
|
91
|
+
/* c8 ignore next 3 */
|
|
92
|
+
if (loaded.__esModule === true || typeof loaded.default === 'function') {
|
|
93
|
+
loaded = loaded.default
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (plugin.encapsulate === false) {
|
|
97
|
+
const skipOverride = loaded[Symbol.for('skip-override')]
|
|
98
|
+
loaded[Symbol.for('skip-override')] = true
|
|
99
|
+
await app.register(loaded, plugin.options)
|
|
100
|
+
loaded[Symbol.for('skip-override')] = skipOverride
|
|
101
|
+
} else {
|
|
102
|
+
await app.register(loaded, plugin.options)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export const sandboxWrapper = fp(sandboxWrapperPlugin)
|