@platformatic/composer 3.4.1 → 3.5.1

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 (46) hide show
  1. package/LICENSE +1 -1
  2. package/config.d.ts +482 -131
  3. package/eslint.config.js +4 -2
  4. package/index.d.ts +1 -17
  5. package/index.js +9 -210
  6. package/package.json +18 -59
  7. package/schema.json +2121 -843
  8. package/scripts/schema.js +12 -0
  9. package/.c8rc +0 -6
  10. package/composer.mjs +0 -54
  11. package/help/create.txt +0 -11
  12. package/help/help.txt +0 -7
  13. package/help/openapi schemas fetch.txt +0 -9
  14. package/help/start.txt +0 -54
  15. package/index.test-d.ts +0 -23
  16. package/lib/composer-hook.js +0 -60
  17. package/lib/create.mjs +0 -84
  18. package/lib/errors.js +0 -13
  19. package/lib/generator/README.md +0 -30
  20. package/lib/generator/composer-generator.d.ts +0 -11
  21. package/lib/generator/composer-generator.js +0 -128
  22. package/lib/graphql-fetch.js +0 -85
  23. package/lib/graphql-generator.js +0 -31
  24. package/lib/graphql.js +0 -20
  25. package/lib/openapi-composer.js +0 -81
  26. package/lib/openapi-config-schema.js +0 -93
  27. package/lib/openapi-fetch-schemas.mjs +0 -61
  28. package/lib/openapi-generator.js +0 -167
  29. package/lib/openapi-load-config.js +0 -31
  30. package/lib/openapi-modifier.js +0 -137
  31. package/lib/openapi.js +0 -49
  32. package/lib/proxy.js +0 -161
  33. package/lib/root-endpoint/index.js +0 -28
  34. package/lib/root-endpoint/public/images/dark_mode.svg +0 -3
  35. package/lib/root-endpoint/public/images/favicon.ico +0 -0
  36. package/lib/root-endpoint/public/images/light_mode.svg +0 -11
  37. package/lib/root-endpoint/public/images/platformatic-logo-dark.svg +0 -30
  38. package/lib/root-endpoint/public/images/platformatic-logo-light.svg +0 -30
  39. package/lib/root-endpoint/public/images/triangle_dark.svg +0 -3
  40. package/lib/root-endpoint/public/images/triangle_light.svg +0 -3
  41. package/lib/root-endpoint/public/index.html +0 -237
  42. package/lib/schema.js +0 -210
  43. package/lib/stackable.js +0 -59
  44. package/lib/upgrade.js +0 -22
  45. package/lib/utils.js +0 -27
  46. package/lib/versions/2.0.0.js +0 -11
package/index.js CHANGED
@@ -1,214 +1,13 @@
1
- 'use strict'
1
+ import { create as createGateway } from '@platformatic/gateway'
2
2
 
3
- const deepEqual = require('fast-deep-equal')
4
- const ConfigManager = require('@platformatic/config')
5
- const { platformaticService, buildServer, buildStackable } = require('@platformatic/service')
3
+ // eslint-disable-next-line import-x/export
4
+ export * from '@platformatic/gateway'
6
5
 
7
- const { schema } = require('./lib/schema')
8
- const serviceProxy = require('./lib/proxy')
9
- const openapi = require('./lib/openapi.js')
10
- const graphql = require('./lib/graphql')
11
- const composerHook = require('./lib/composer-hook')
12
- const openapiGenerator = require('./lib/openapi-generator')
13
- const graphqlGenerator = require('./lib/graphql-generator')
14
- const { isSameGraphqlSchema, fetchGraphqlSubgraphs } = require('./lib/graphql-fetch')
15
- const { isFetchable } = require('./lib/utils')
16
- const { ComposerStackable } = require('./lib/stackable')
17
- const errors = require('./lib/errors')
18
- const upgrade = require('./lib/upgrade')
6
+ // eslint-disable-next-line import-x/export
7
+ export async function create (configOrRoot, sourceOrConfig, context) {
8
+ globalThis.platformatic.logger.warn(
9
+ '@platformatic/composer is deprecated and it will be removed in version 4.0.0, please migrate to @platformatic/gateway.'
10
+ )
19
11
 
20
- const kITC = Symbol.for('plt.runtime.itc')
21
-
22
- const EXPERIMENTAL_GRAPHQL_COMPOSER_FEATURE_MESSAGE = 'graphql composer is an experimental feature'
23
-
24
- async function platformaticComposer (app, opts) {
25
- const configManager = app.platformatic.configManager
26
- const config = configManager.current
27
- let hasGraphqlServices, hasOpenapiServices
28
-
29
- // When no services are specified, get the list from the runtime.
30
- if (!configManager.current.composer.services?.length) {
31
- const itcResponse = await globalThis[kITC]?.send('getServices')
32
-
33
- if (itcResponse) {
34
- // Remove ourself from the services
35
- configManager.current.composer.services = itcResponse.services
36
- .map(service => {
37
- // Remove ourself
38
- if (service.id === opts.context.serviceId) {
39
- return null
40
- }
41
-
42
- return { id: service.id, proxy: {} }
43
- })
44
- .filter(f => f)
45
- }
46
- }
47
-
48
- const { services } = configManager.current.composer
49
-
50
- for (const service of services) {
51
- if (!service.origin) {
52
- service.origin = `http://${service.id}.plt.local`
53
- }
54
- if (service.openapi && !hasOpenapiServices) {
55
- hasOpenapiServices = true
56
- }
57
- if (service.graphql && !hasGraphqlServices) {
58
- hasGraphqlServices = true
59
- }
60
- }
61
-
62
- if (hasOpenapiServices) {
63
- app.register(openapi, config.composer)
64
- }
65
- app.register(serviceProxy, { ...config.composer, context: opts.context })
66
- app.register(composerHook)
67
- await app.register(platformaticService, { config, context: opts.context })
68
-
69
- if (hasOpenapiServices) {
70
- await app.register(openapiGenerator, config.composer)
71
- }
72
-
73
- if (hasGraphqlServices) {
74
- app.log.warn(EXPERIMENTAL_GRAPHQL_COMPOSER_FEATURE_MESSAGE)
75
- app.register(graphql, config.composer)
76
- await app.register(graphqlGenerator, config.composer)
77
- }
78
-
79
- if (!app.hasRoute({ url: '/', method: 'GET' })) {
80
- await app.register(require('./lib/root-endpoint'), config)
81
- }
82
-
83
- if (!opts.context?.isProduction) {
84
- await watchServices(app, config)
85
- }
12
+ return createGateway(configOrRoot, sourceOrConfig, context)
86
13
  }
87
-
88
- platformaticComposer[Symbol.for('skip-override')] = true
89
- platformaticComposer.schema = schema
90
- platformaticComposer.configType = 'composer'
91
- platformaticComposer.configManagerConfig = {
92
- version: require('./package.json').version,
93
- schema,
94
- allowToWatch: ['.env'],
95
- schemaOptions: {
96
- useDefaults: true,
97
- coerceTypes: true,
98
- allErrors: true,
99
- strict: false
100
- },
101
- transformConfig: platformaticService.configManagerConfig.transformConfig,
102
- upgrade
103
- }
104
-
105
- // TODO review no need to be async
106
- async function buildComposerServer (options) {
107
- // TODO ConfigManager is not been used, it's attached to platformaticComposer, can be removed
108
- return buildServer(options, platformaticComposer, ConfigManager)
109
- }
110
-
111
- async function detectServicesUpdate ({ app, services, fetchOpenApiSchema, fetchGraphqlSubgraphs }) {
112
- let changed
113
-
114
- const graphqlServices = []
115
- // assumes services here are fetchable
116
- for (const service of services) {
117
- const { id, origin, openapi, graphql } = service
118
-
119
- if (openapi) {
120
- const currentSchema = app.openApiSchemas.find(schema => schema.id === id)?.originSchema || null
121
-
122
- let fetchedSchema = null
123
- try {
124
- fetchedSchema = await fetchOpenApiSchema({ origin, openapi })
125
- } catch (err) {
126
- app.log.error({ err }, 'failed to fetch schema (watch) for service ' + id)
127
- }
128
-
129
- if (!changed && !deepEqual(fetchedSchema, currentSchema)) {
130
- changed = true
131
- // it stops at first schema difference since all the schemas will be updated on reload
132
- break
133
- }
134
- }
135
-
136
- if (graphql) {
137
- graphqlServices.push(service)
138
- }
139
- }
140
-
141
- if (!changed && graphqlServices.length > 0) {
142
- const graphqlSupergraph = await fetchGraphqlSubgraphs(graphqlServices, app.graphqlComposerOptions, app)
143
- if (!isSameGraphqlSchema(graphqlSupergraph, app.graphqlSupergraph)) {
144
- changed = true
145
- app.graphqlSupergraph = graphqlSupergraph
146
- }
147
- }
148
-
149
- return changed
150
- }
151
-
152
- /**
153
- * poll services to detect changes, every `opts.composer.refreshTimeout`
154
- * polling is disabled on refreshTimeout = 0
155
- * or there are no network openapi nor graphql remote services (the services are from file or they don't have a schema/graph to fetch)
156
- */
157
- async function watchServices (app, opts) {
158
- const { services, refreshTimeout } = opts.composer
159
- if (refreshTimeout < 1) {
160
- return
161
- }
162
-
163
- const watching = services.filter(isFetchable)
164
- if (watching.length < 1) {
165
- return
166
- }
167
-
168
- if (!globalThis[Symbol.for('plt.runtime.id')]) {
169
- app.log.warn('Watching services is only supported when running within a Platformatic Runtime.')
170
- return
171
- }
172
-
173
- const { fetchOpenApiSchema } = await import('./lib/openapi-fetch-schemas.mjs')
174
-
175
- app.log.info({ services: watching }, 'start watching services')
176
-
177
- const timer = setInterval(async () => {
178
- try {
179
- if (await detectServicesUpdate({ app, services: watching, fetchOpenApiSchema, fetchGraphqlSubgraphs })) {
180
- clearInterval(timer)
181
- app.log.info('detected services changes, restarting ...')
182
-
183
- globalThis[Symbol.for('plt.runtime.itc')].notify('changed')
184
- }
185
- } catch (error) {
186
- app.log.error(
187
- {
188
- err: {
189
- message: error.message,
190
- stack: error.stack
191
- }
192
- },
193
- 'failed to get services info'
194
- )
195
- }
196
- }, refreshTimeout).unref()
197
-
198
- app.addHook('onClose', async () => {
199
- clearInterval(timer)
200
- })
201
- }
202
-
203
- async function buildComposerStackable (options) {
204
- return buildStackable(options, platformaticComposer, ComposerStackable)
205
- }
206
-
207
- module.exports = platformaticComposer
208
- module.exports.schema = schema
209
- module.exports.platformaticComposer = platformaticComposer
210
- module.exports.buildServer = buildComposerServer
211
- module.exports.errors = errors
212
- module.exports.Generator = require('./lib/generator/composer-generator')
213
- module.exports.ConfigManager = ConfigManager
214
- module.exports.buildStackable = buildComposerStackable
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@platformatic/composer",
3
- "version": "3.4.1",
3
+ "version": "3.5.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
- "bin": {
7
- "plt-composer": "./composer.mjs"
8
- },
9
- "author": "Ivan Tymoshenko <ivan@tymoshenko.me>",
6
+ "types": "index.d.ts",
7
+ "type": "module",
8
+ "author": "Platformatic Inc. <oss@platformatic.dev> (https://platformatic.dev)",
10
9
  "repository": {
11
10
  "type": "git",
12
11
  "url": "git+https://github.com/platformatic/platformatic.git"
@@ -17,65 +16,25 @@
17
16
  },
18
17
  "homepage": "https://github.com/platformatic/platformatic#readme",
19
18
  "devDependencies": {
20
- "borp": "^0.17.0",
21
19
  "c8": "^10.0.0",
22
- "dedent": "^1.5.1",
20
+ "cleaner-spec-reporter": "^0.5.0",
23
21
  "eslint": "9",
24
- "json-schema-to-typescript": "^15.0.0",
25
- "neostandard": "^0.11.1",
26
- "openapi-schema-validator": "^12.1.3",
27
- "single-user-cache": "^1.0.1",
28
- "split2": "^4.2.0",
29
- "tsd": "^0.31.0",
30
- "typescript": "^5.5.4",
31
- "why-is-node-running": "2",
32
- "ws": "^8.16.0",
33
- "@platformatic/client": "3.4.1",
34
- "@platformatic/config": "3.4.1",
35
- "@platformatic/db": "3.4.1"
22
+ "neostandard": "^0.12.0",
23
+ "json-schema-to-typescript": "^15.0.0"
36
24
  },
37
25
  "dependencies": {
38
- "@fastify/error": "^4.0.0",
39
- "@fastify/http-proxy": "^10.0.0",
40
- "@fastify/reply-from": "^11.0.0",
41
- "@fastify/static": "^8.0.0",
42
- "@fastify/swagger": "^9.0.0",
43
- "@platformatic/graphql-composer": "^0.8.0",
44
- "@scalar/fastify-api-reference": "^1.19.5",
45
- "ajv": "^8.12.0",
46
- "commist": "^3.2.0",
47
- "console-table-printer": "^2.12.0",
48
- "desm": "^1.3.1",
49
- "es-main": "^1.3.0",
50
- "execa": "^8.0.1",
51
- "fast-deep-equal": "^3.1.3",
52
- "fastify": "^5.0.0",
53
- "fastify-openapi-glue": "^4.6.0",
54
- "fastify-plugin": "^5.0.0",
55
- "graphql": "^16.8.1",
56
- "help-me": "^5.0.0",
57
- "json-schema-traverse": "^1.0.0",
58
- "mercurius": "^15.0.0",
59
- "minimist": "^1.2.8",
60
- "my-ua-parser": "^2.0.2",
61
- "ora": "^6.3.1",
62
- "pino": "^8.19.0",
63
- "pino-pretty": "^11.0.0",
64
- "rfdc": "^1.3.1",
65
- "semgrator": "^0.3.0",
66
- "undici": "^6.9.0",
67
- "@platformatic/config": "3.4.1",
68
- "@platformatic/scalar-theme": "3.4.1",
69
- "@platformatic/generators": "3.4.1",
70
- "@platformatic/service": "3.4.1",
71
- "@platformatic/telemetry": "3.4.1",
72
- "@platformatic/utils": "^3.4.1"
26
+ "@platformatic/foundation": "3.5.1",
27
+ "@platformatic/gateway": "3.5.1"
28
+ },
29
+ "engines": {
30
+ "node": ">=22.19.0"
73
31
  },
74
32
  "scripts": {
75
- "test": "pnpm run lint && borp -T --timeout=180000 -c 1 && tsd",
76
- "gen-schema": "node lib/schema.js > schema.json",
77
- "gen-types": "json2ts > config.d.ts < schema.json",
78
- "build": "pnpm run gen-schema && pnpm run gen-types",
79
- "lint": "eslint"
33
+ "test": "node --test --test-reporter=cleaner-spec-reporter --test-concurrency=1 --test-timeout=2000000 test/*.test.js",
34
+ "prebuild": "cd ../gateway && npm run build",
35
+ "build": "node scripts/schema.js",
36
+ "lint": "eslint",
37
+ "gen-schema": "node scripts/schema.js > schema.json",
38
+ "gen-types": "json2ts > config.d.ts < schema.json"
80
39
  }
81
40
  }