@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
package/index.test-d.ts DELETED
@@ -1,107 +0,0 @@
1
- import { expectType, expectError } from 'tsd'
2
- import { FastifyInstance } from 'fastify'
3
- import ConfigManager, { StackableInterface } from '@platformatic/config'
4
- import { OpenAPI } from 'openapi-types'
5
- import type { MercuriusPlugin } from 'mercurius'
6
- import { PlatformaticService } from './config'
7
- import { BaseGenerator } from '@platformatic/generators'
8
- import {
9
- start,
10
- buildServer,
11
- PlatformaticApp,
12
- platformaticService,
13
- Stackable,
14
- Generator,
15
- PlatformaticServiceConfig,
16
- } from '.'
17
-
18
- declare module 'fastify' {
19
- interface FastifyInstance {
20
- platformatic: PlatformaticApp<PlatformaticService>
21
- }
22
- }
23
-
24
- const server = await buildServer({})
25
-
26
- expectType<FastifyInstance>(server)
27
- expectType<ConfigManager<PlatformaticService>>(server.platformatic.configManager)
28
- expectType<PlatformaticService>(server.platformatic.configManager.current)
29
- expectType<PlatformaticService>(server.platformatic.config)
30
- expectType<OpenAPI.Document>(server.swagger())
31
- expectType<MercuriusPlugin>(server.graphql)
32
- expectType<Promise<void>>(server.restart())
33
-
34
- function buildStackable (): Stackable<PlatformaticServiceConfig> {
35
- const myApp: Stackable<PlatformaticServiceConfig> = {
36
- async app (app: FastifyInstance, opts: object): Promise<void> {
37
- await platformaticService.app(app, opts)
38
- },
39
-
40
- schema: platformaticService.schema,
41
- configType: 'myApp',
42
- configManagerConfig: {
43
- version: platformaticService.configManagerConfig.version,
44
- ...platformaticService.configManagerConfig,
45
- async transformConfig (this: ConfigManager<PlatformaticServiceConfig>) {
46
- this.current.plugins = {
47
- paths: [{
48
- path: 'my-plugin',
49
- }],
50
- }
51
- },
52
- },
53
- async upgrade (config: PlatformaticServiceConfig, version: string) {
54
- const upgrade = platformaticService.configManagerConfig.upgrade
55
- if (typeof upgrade === 'function') {
56
- return upgrade.call(this, config, version)
57
- }
58
- return config
59
- },
60
- buildStackable: () => Promise.resolve({} as StackableInterface),
61
- }
62
-
63
- // configVersion is not part of ConfigManagerConfig
64
- expectError(myApp.configManagerConfig.configVersion)
65
-
66
- await start(myApp, ['--help'])
67
-
68
- return myApp
69
- }
70
-
71
- expectType<Stackable<PlatformaticServiceConfig>>(buildStackable())
72
-
73
- const generator = new Generator()
74
- expectType<Generator>(generator)
75
-
76
- class MyGenerator extends Generator {}
77
- const myGenerator = new MyGenerator()
78
-
79
- expectType<MyGenerator>(myGenerator)
80
- expectType<BaseGenerator.BaseGeneratorConfig>(myGenerator.config)
81
-
82
- function buildStackable2 (): Stackable<PlatformaticServiceConfig> {
83
- const myApp: Stackable<PlatformaticServiceConfig> = {
84
- async app (app: FastifyInstance, opts: object): Promise<void> {
85
- await platformaticService.app(app, opts)
86
- },
87
- schema: platformaticService.schema,
88
- configType: 'myApp',
89
- configManagerConfig: {
90
- ...platformaticService.configManagerConfig,
91
- async transformConfig (this: ConfigManager<PlatformaticServiceConfig>) {
92
- this.current.plugins = {
93
- paths: [{
94
- path: 'my-plugin',
95
- }],
96
- }
97
- },
98
- },
99
- buildStackable: () => Promise.resolve({} as StackableInterface),
100
- }
101
-
102
- await start(myApp, ['--help'])
103
-
104
- return myApp
105
- }
106
-
107
- expectType<Stackable<PlatformaticServiceConfig>>(buildStackable2())
package/lib/create.mjs DELETED
@@ -1,85 +0,0 @@
1
- 'use strict'
2
- import minimist from 'minimist'
3
- import { Generator } from '../lib/generator/service-generator.js'
4
- import { join } from 'node:path'
5
- import { getPkgManager } from '@platformatic/utils'
6
- import { execa } from 'execa'
7
- import ora from 'ora'
8
- import { Table } from 'console-table-printer'
9
- import pino from 'pino'
10
- import pinoPretty from 'pino-pretty'
11
-
12
- function printAppSummary (args, logger) {
13
- logger.info('Creating a Platformatic Service app with this config: ')
14
- const table = [
15
- { config: 'Directory', value: args.dir },
16
- { config: 'Language', value: args.typescript ? 'Typescript' : 'Javascript' },
17
- { config: 'Init Git Repository', value: args.git },
18
- { config: 'Install Dependencies', value: args.install },
19
- { config: 'Sample Plugin and Tests', value: args.plugin },
20
- ]
21
-
22
- const p = new Table({
23
- columns: [
24
- { name: 'config', alignment: 'right' },
25
- { name: 'value', alignment: 'left' },
26
- ],
27
- })
28
-
29
- p.addRows(table)
30
- p.printTable()
31
- }
32
- async function createService (_args) {
33
- const stream = pinoPretty({
34
- translateTime: 'SYS:HH:MM:ss',
35
- ignore: 'hostname,pid',
36
- minimumLevel: 'debug',
37
- sync: true,
38
- })
39
-
40
- const logger = pino(stream)
41
-
42
- const args = minimist(process.argv.slice(2), {
43
- string: ['dir', 'port', 'hostname'],
44
- boolean: ['typescript', 'install', 'plugin', 'git'],
45
- default: {
46
- dir: join(process.cwd(), 'platformatic-service'),
47
- port: 3042,
48
- hostname: '0.0.0.0',
49
- plugin: true,
50
- typescript: false,
51
- git: false,
52
- install: true,
53
- },
54
-
55
- })
56
-
57
- printAppSummary(args, logger)
58
-
59
- const gen = new Generator({})
60
- gen.setConfig({
61
- port: args.port,
62
- hostname: args.hostname,
63
- plugin: args.plugin,
64
- tests: args.plugin,
65
- typescript: args.typescript,
66
- initGitRepository: args.git,
67
- targetDirectory: args.dir,
68
- })
69
-
70
- try {
71
- await gen.run()
72
- if (args.install) {
73
- const pkgManager = getPkgManager()
74
- const spinner = ora('Installing dependencies...').start()
75
- await execa(pkgManager, ['install'], { cwd: args.dir })
76
- spinner.succeed()
77
- }
78
-
79
- logger.info('Done! 🎉')
80
- } catch (err) {
81
- logger.error(err.message)
82
- }
83
- }
84
-
85
- export { createService }
package/lib/gen-schema.js DELETED
@@ -1,15 +0,0 @@
1
- 'use strict'
2
-
3
- const { writeFile } = require('fs/promises')
4
- const { schema: platformaticServiceSchema } = require('./schema.js')
5
-
6
- const filenameConfigJsonSchema = 'platformatic.service.schema.json'
7
-
8
- async function generateJsonSchemaConfig () {
9
- await writeFile(filenameConfigJsonSchema, JSON.stringify(platformaticServiceSchema, null, 2))
10
- }
11
-
12
- module.exports = {
13
- generateJsonSchemaConfig,
14
- filenameConfigJsonSchema,
15
- }
package/lib/gen-types.mjs DELETED
@@ -1,38 +0,0 @@
1
- import { join, dirname } from 'path'
2
- import { createRequire } from 'module'
3
- import { writeFile } from 'fs/promises'
4
- import pino from 'pino'
5
- import pretty from 'pino-pretty'
6
- import { loadConfig } from '@platformatic/config'
7
- import platformaticService from '../index.js'
8
- import { checkForDependencies } from '@platformatic/utils'
9
-
10
- const GLOBAL_TYPES_TEMPLATE = `
11
- import { FastifyInstance } from 'fastify'
12
- import { PlatformaticApp, PlatformaticServiceConfig } from '@platformatic/service'
13
-
14
- declare module 'fastify' {
15
- interface FastifyInstance {
16
- platformatic: PlatformaticApp<PlatformaticServiceConfig>
17
- }
18
- }
19
- `
20
- async function execute ({ logger, configManager }) {
21
- const fileNameOrThen = join(dirname(configManager.fullPath), 'global.d.ts')
22
- await writeFile(fileNameOrThen, GLOBAL_TYPES_TEMPLATE)
23
- }
24
-
25
- async function generateTypes (_args) {
26
- const logger = pino(pretty({
27
- translateTime: 'SYS:HH:MM:ss',
28
- ignore: 'hostname,pid',
29
- }))
30
- const { configManager, args } = await loadConfig({}, _args, platformaticService)
31
- await configManager.parseAndValidate()
32
- const config = configManager.current
33
-
34
- await execute({ logger, configManager })
35
- await checkForDependencies(logger, args, createRequire(import.meta.url), config, ['@platformatic/service'])
36
- }
37
-
38
- export { execute, generateTypes }
@@ -1,31 +0,0 @@
1
- # Platformatic Service API
2
-
3
- This is a generated [Platformatic Service](https://docs.platformatic.dev/docs/service/overview) application.
4
-
5
- ## Requirements
6
-
7
- Platformatic supports macOS, Linux and Windows ([WSL](https://docs.microsoft.com/windows/wsl/) recommended).
8
- You'll need to have [Node.js](https://nodejs.org/) >= v18.8.0 or >= v20.6.0
9
-
10
- ## Setup
11
-
12
- Install dependencies:
13
-
14
- ```bash
15
- npm install
16
- ```
17
-
18
- ## Usage
19
-
20
- Run the API with:
21
-
22
- ```bash
23
- npm start
24
- ```
25
-
26
- ### Explore
27
- - ⚡ The Platformatic DB server is running at http://localhost:3042/
28
- - 📔 View the REST API's Swagger documentation at http://localhost:3042/documentation/
29
- - 🔍 Try out the GraphiQL web UI at http://localhost:3042/graphiql
30
-
31
-
@@ -1,11 +0,0 @@
1
- import { BaseGenerator } from '@platformatic/generators'
2
-
3
- interface KeyValue {
4
- [key: string]: string
5
- }
6
-
7
- export namespace ServiceGenerator {
8
- export class ServiceGenerator extends BaseGenerator.BaseGenerator {
9
- constructor (opts?: Omit<BaseGenerator.BaseGeneratorOptions, 'module'>)
10
- }
11
- }
@@ -1,126 +0,0 @@
1
- 'use strict'
2
-
3
- const { BaseGenerator } = require('@platformatic/generators')
4
- const { readFile } = require('node:fs/promises')
5
- const { join } = require('node:path')
6
-
7
- class ServiceGenerator extends BaseGenerator {
8
- constructor (opts = {}) {
9
- super({
10
- ...opts,
11
- module: '@platformatic/service',
12
- })
13
- }
14
-
15
- getDefaultConfig () {
16
- const config = super.getDefaultConfig()
17
- config.plugin = true
18
- config.tests = true
19
- return config
20
- }
21
-
22
- async _beforePrepare () {
23
- // if we are NOT updating, create env and files, otherwise leave as it is
24
- if (!this.config.isUpdating) {
25
- if (!this.config.isRuntimeContext) {
26
- this.addEnvVars({
27
- PLT_SERVER_HOSTNAME: this.config.hostname,
28
- PLT_SERVER_LOGGER_LEVEL: 'info',
29
- PORT: 3042,
30
- }, { overwrite: false })
31
- }
32
-
33
- this.addEnvVars({
34
- PLT_TYPESCRIPT: this.config.typescript,
35
- }, { overwrite: false, default: true })
36
-
37
- this.config.dependencies = {
38
- '@platformatic/service': `^${this.platformaticVersion}`,
39
- }
40
- }
41
- }
42
-
43
- getConfigFieldsDefinitions () {
44
- if (this.config.isRuntimeContext) {
45
- return []
46
- }
47
- return [
48
- {
49
- var: 'PLT_SERVER_HOSTNAME',
50
- label: 'What is the hostname?',
51
- default: '0.0.0.0',
52
- type: 'string',
53
- configValue: 'hostname',
54
- },
55
- {
56
- var: 'PLT_SERVER_LOGGER_LEVEL',
57
- label: 'What is the logger level?',
58
- default: 'info',
59
- type: 'string',
60
- configValue: '',
61
- },
62
- {
63
- label: 'Which port do you want to use?',
64
- var: 'PORT',
65
- default: 3042,
66
- type: 'number',
67
- configValue: 'port',
68
- },
69
- ]
70
- }
71
-
72
- async _afterPrepare () {
73
- // if we are NOT updating, create env and files, otherwise leave as it is
74
- if (!this.config.isUpdating) {
75
- const GLOBAL_TYPES_TEMPLATE = `
76
- import { FastifyInstance } from 'fastify'
77
- import { PlatformaticApp, PlatformaticServiceConfig } from '@platformatic/service'
78
-
79
- declare module 'fastify' {
80
- interface FastifyInstance {
81
- platformatic: PlatformaticApp<PlatformaticServiceConfig>
82
- }
83
- }
84
- `
85
- this.addFile({ path: '', file: 'global.d.ts', contents: GLOBAL_TYPES_TEMPLATE })
86
- this.addFile({ path: '', file: 'README.md', contents: await readFile(join(__dirname, 'README.md'), 'utf-8') })
87
- }
88
- }
89
-
90
- async _getConfigFileContents () {
91
- const { isRuntimeContext } = this.config
92
- const version = this.platformaticVersion
93
- const config = {
94
- $schema: `https://schemas.platformatic.dev/@platformatic/service/${version}.json`,
95
- service: {
96
- openapi: true,
97
- },
98
- watch: true,
99
- }
100
- if (this.config.plugin) {
101
- config.plugins = {
102
- paths: [
103
- { path: './plugins', encapsulate: false },
104
- './routes',
105
- ],
106
- typescript: `{${this.getEnvVarName('PLT_TYPESCRIPT')}}`,
107
- }
108
- }
109
-
110
- if (!isRuntimeContext) {
111
- config.server = {
112
- hostname: '{PLT_SERVER_HOSTNAME}',
113
- port: '{PORT}',
114
- logger: {
115
- level: '{PLT_SERVER_LOGGER_LEVEL}',
116
- },
117
- }
118
- }
119
-
120
- return config
121
- }
122
- }
123
-
124
- module.exports = ServiceGenerator
125
- module.exports.ServiceGenerator = ServiceGenerator
126
- module.exports.Generator = ServiceGenerator