@platformatic/service 2.74.3 → 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 +2 -30
- package/eslint.config.js +4 -6
- package/index.d.ts +55 -47
- package/index.js +44 -199
- package/lib/application.js +35 -0
- package/lib/compile.js +1 -52
- package/lib/generator.js +424 -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 +40 -31
- package/lib/plugins/plugins.js +6 -53
- package/lib/{root-endpoint/index.js → plugins/root.js} +9 -8
- package/lib/plugins/sandbox-wrapper.js +62 -55
- package/lib/schema.js +1028 -203
- package/lib/stackable.js +171 -338
- package/lib/upgrade.js +6 -8
- package/lib/utils.js +30 -93
- 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 +18 -25
- package/schema.json +10 -155
- 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/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
|
@@ -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,26 +1,75 @@
|
|
|
1
|
-
|
|
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'
|
|
2
8
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Creates an object for pattern specific options. This ensures that
|
|
11
|
+
* only configurations that have been provided are included in the
|
|
12
|
+
* final result. This prevents 'cannot read properties of undefined'
|
|
13
|
+
* errors when undefined configs are provided to the underlying
|
|
14
|
+
* @fastify/autoload plugin.
|
|
15
|
+
*/
|
|
16
|
+
function patternOptionsFromPlugin (plugin) {
|
|
17
|
+
const config = {}
|
|
18
|
+
|
|
19
|
+
// Expected keys for autoload plugin options that expect regexp patterns
|
|
20
|
+
const patternOptionKeys = ['ignorePattern', 'indexPattern', 'autoHooksPattern']
|
|
9
21
|
|
|
10
|
-
|
|
22
|
+
for (const key of patternOptionKeys) {
|
|
23
|
+
const pattern = plugin[key]
|
|
24
|
+
|
|
25
|
+
// If pattern key not found in plugin object, move on
|
|
26
|
+
if (!pattern) {
|
|
27
|
+
continue
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Build an instance of a RegExp. If this comes back undefined,
|
|
31
|
+
// then an invalid value was provided. Move on.
|
|
32
|
+
const regExpPattern = stringPatternToRegExp(pattern)
|
|
33
|
+
if (!regExpPattern) {
|
|
34
|
+
continue
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// We have a valid RegExp so add the option to the config to pass along to
|
|
38
|
+
// autoload.
|
|
39
|
+
config[key] = regExpPattern
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return config
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function stringPatternToRegExp (stringPattern) {
|
|
46
|
+
try {
|
|
47
|
+
return new RegExp(stringPattern)
|
|
48
|
+
} catch (err) {
|
|
49
|
+
return undefined
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function sandboxWrapperPlugin (app, options) {
|
|
11
54
|
// fake require next to the configManager dirname
|
|
12
|
-
const
|
|
13
|
-
|
|
55
|
+
const require = createRequire(resolve(app.platformatic.config[kMetadata].root, 'noop.js'))
|
|
56
|
+
|
|
57
|
+
for (const plugin of options.packages || []) {
|
|
14
58
|
const name = typeof plugin === 'string' ? plugin : plugin.name
|
|
15
|
-
const url = pathToFileURL(
|
|
59
|
+
const url = pathToFileURL(require.resolve(name))
|
|
16
60
|
const loaded = await import(url)
|
|
17
61
|
await app.register(loaded, plugin.options)
|
|
18
62
|
}
|
|
19
63
|
|
|
20
|
-
for (let plugin of
|
|
64
|
+
for (let plugin of options.paths || []) {
|
|
21
65
|
if (typeof plugin === 'string') {
|
|
22
66
|
plugin = { path: plugin, encapsulate: true }
|
|
23
67
|
}
|
|
68
|
+
|
|
69
|
+
if (plugin.path && !isAbsolute(plugin.path)) {
|
|
70
|
+
plugin.path = resolve(app.platformatic.config[kMetadata].root, plugin.path)
|
|
71
|
+
}
|
|
72
|
+
|
|
24
73
|
if (plugin.path && (await stat(plugin.path)).isDirectory()) {
|
|
25
74
|
const patternOptions = patternOptionsFromPlugin(plugin)
|
|
26
75
|
|
|
@@ -55,48 +104,6 @@ module.exports = fp(async function (app, opts) {
|
|
|
55
104
|
}
|
|
56
105
|
}
|
|
57
106
|
}
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Creates an object for pattern specific options. This ensures that
|
|
62
|
-
* only configurations that have been provided are included in the
|
|
63
|
-
* final result. This prevents 'cannot read properties of undefined'
|
|
64
|
-
* errors when undefined configs are provided to the underlying
|
|
65
|
-
* @fastify/autoload plugin.
|
|
66
|
-
*/
|
|
67
|
-
function patternOptionsFromPlugin (plugin) {
|
|
68
|
-
const config = {}
|
|
69
|
-
|
|
70
|
-
// Expected keys for autoload plugin options that expect regexp patterns
|
|
71
|
-
const patternOptionKeys = ['ignorePattern', 'indexPattern', 'autoHooksPattern']
|
|
72
|
-
|
|
73
|
-
for (const key of patternOptionKeys) {
|
|
74
|
-
const pattern = plugin[key]
|
|
75
|
-
|
|
76
|
-
// If pattern key not found in plugin object, move on
|
|
77
|
-
if (!pattern) {
|
|
78
|
-
continue
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Build an instance of a RegExp. If this comes back undefined,
|
|
82
|
-
// then an invalid value was provided. Move on.
|
|
83
|
-
const regExpPattern = stringPatternToRegExp(pattern)
|
|
84
|
-
if (!regExpPattern) {
|
|
85
|
-
continue
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// We have a valid RegExp so add the option to the config to pass along to
|
|
89
|
-
// autoload.
|
|
90
|
-
config[key] = regExpPattern
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return config
|
|
94
107
|
}
|
|
95
108
|
|
|
96
|
-
|
|
97
|
-
try {
|
|
98
|
-
return new RegExp(stringPattern)
|
|
99
|
-
} catch (err) {
|
|
100
|
-
return undefined
|
|
101
|
-
}
|
|
102
|
-
}
|
|
109
|
+
export const sandboxWrapper = fp(sandboxWrapperPlugin)
|