@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.
Files changed (52) hide show
  1. package/config.d.ts +2 -30
  2. package/eslint.config.js +4 -6
  3. package/index.d.ts +55 -47
  4. package/index.js +44 -199
  5. package/lib/application.js +35 -0
  6. package/lib/compile.js +1 -52
  7. package/lib/generator.js +424 -0
  8. package/lib/plugins/cors.js +5 -8
  9. package/lib/plugins/graphql.js +16 -14
  10. package/lib/plugins/health-check.js +6 -8
  11. package/lib/plugins/openapi.js +40 -31
  12. package/lib/plugins/plugins.js +6 -53
  13. package/lib/{root-endpoint/index.js → plugins/root.js} +9 -8
  14. package/lib/plugins/sandbox-wrapper.js +62 -55
  15. package/lib/schema.js +1028 -203
  16. package/lib/stackable.js +171 -338
  17. package/lib/upgrade.js +6 -8
  18. package/lib/utils.js +30 -93
  19. package/lib/versions/0.16.0.js +14 -15
  20. package/lib/versions/{from-zero-twenty-eight-to-will-see.js → 0.28.0.js} +3 -6
  21. package/lib/versions/2.0.0.js +4 -7
  22. package/lib/versions/3.0.0.js +14 -0
  23. package/package.json +18 -25
  24. package/schema.json +10 -155
  25. package/tsconfig.json +16 -6
  26. package/.c8rc +0 -6
  27. package/help/compile.txt +0 -19
  28. package/help/create.txt +0 -11
  29. package/help/help.txt +0 -8
  30. package/help/schema.txt +0 -9
  31. package/help/start.txt +0 -23
  32. package/index.test-d.ts +0 -107
  33. package/lib/create.mjs +0 -85
  34. package/lib/gen-schema.js +0 -15
  35. package/lib/gen-types.mjs +0 -38
  36. package/lib/generator/README.md +0 -31
  37. package/lib/generator/service-generator.d.ts +0 -11
  38. package/lib/generator/service-generator.js +0 -126
  39. package/lib/openapi-schema-defs.js +0 -1108
  40. package/lib/plugins/clients.js +0 -16
  41. package/lib/plugins/metrics.js +0 -244
  42. package/lib/plugins/typescript.js +0 -20
  43. package/lib/start.js +0 -190
  44. package/service.mjs +0 -71
  45. /package/{lib/root-endpoint/public → public}/images/dark_mode.svg +0 -0
  46. /package/{lib/root-endpoint/public → public}/images/favicon.ico +0 -0
  47. /package/{lib/root-endpoint/public → public}/images/light_mode.svg +0 -0
  48. /package/{lib/root-endpoint/public → public}/images/platformatic-logo-dark.svg +0 -0
  49. /package/{lib/root-endpoint/public → public}/images/platformatic-logo-light.svg +0 -0
  50. /package/{lib/root-endpoint/public → public}/images/triangle_dark.svg +0 -0
  51. /package/{lib/root-endpoint/public → public}/images/triangle_light.svg +0 -0
  52. /package/{lib/root-endpoint/public → public}/index.html +0 -0
@@ -1,12 +1,11 @@
1
- 'use strict'
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
- const path = require('path')
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: path.join(__dirname, 'public'),
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
- 'use strict'
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
- const fp = require('fastify-plugin')
4
- const autoload = require('@fastify/autoload')
5
- const { stat } = require('node:fs/promises')
6
- const { createRequire } = require('node:module')
7
- const { join } = require('node:path')
8
- const { pathToFileURL } = require('node:url')
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
- module.exports = fp(async function (app, opts) {
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 _require = createRequire(join(app.platformatic.configManager.dirname, 'package.json'))
13
- for (const plugin of opts.packages || []) {
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(_require.resolve(name))
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 opts.paths || []) {
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
- function stringPatternToRegExp (stringPattern) {
97
- try {
98
- return new RegExp(stringPattern)
99
- } catch (err) {
100
- return undefined
101
- }
102
- }
109
+ export const sandboxWrapper = fp(sandboxWrapperPlugin)