@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/lib/schema.js DELETED
@@ -1,210 +0,0 @@
1
- #! /usr/bin/env node
2
- 'use strict'
3
-
4
- const { metrics, server, plugins, watch, clients, openApiBase, openApiDefs, graphqlBase } =
5
- require('@platformatic/service').schemas
6
- const telemetry = require('@platformatic/telemetry').schema
7
- const pkg = require('../package.json')
8
-
9
- const openApiService = {
10
- type: 'object',
11
- properties: {
12
- url: { type: 'string' },
13
- file: { type: 'string', resolvePath: true },
14
- prefix: { type: 'string' },
15
- config: { type: 'string', resolvePath: true }
16
- },
17
- anyOf: [{ required: ['url'] }, { required: ['file'] }],
18
- additionalProperties: false
19
- }
20
-
21
- const entityResolver = {
22
- type: 'object',
23
- properties: {
24
- name: { type: 'string' },
25
- argsAdapter: {
26
- anyOf: [{ typeof: 'function' }, { type: 'string' }]
27
- },
28
- partialResults: {
29
- anyOf: [{ typeof: 'function' }, { type: 'string' }]
30
- }
31
- },
32
- required: ['name'],
33
- additionalProperties: false
34
- }
35
-
36
- const entities = {
37
- type: 'object',
38
- patternProperties: {
39
- '^.*$': {
40
- type: 'object',
41
- properties: {
42
- pkey: { type: 'string' },
43
- resolver: entityResolver,
44
- fkeys: {
45
- type: 'array',
46
- items: {
47
- type: 'object',
48
- properties: {
49
- type: { type: 'string' },
50
- field: { type: 'string' },
51
- as: { type: 'string' },
52
- pkey: { type: 'string' },
53
- subgraph: { type: 'string' },
54
- resolver: entityResolver
55
- },
56
- required: ['type']
57
- }
58
- },
59
- many: {
60
- type: 'array',
61
- items: {
62
- type: 'object',
63
- properties: {
64
- type: { type: 'string' },
65
- fkey: { type: 'string' },
66
- as: { type: 'string' },
67
- pkey: { type: 'string' },
68
- subgraph: { type: 'string' },
69
- resolver: entityResolver
70
- },
71
- required: ['type', 'fkey', 'resolver']
72
- }
73
- }
74
- }
75
- }
76
- }
77
- }
78
-
79
- const graphqlService = {
80
- anyOf: [
81
- { type: 'boolean' },
82
- {
83
- type: 'object',
84
- properties: {
85
- host: { type: 'string' },
86
- name: { type: 'string' },
87
- graphqlEndpoint: { type: 'string', default: '/graphql' },
88
- composeEndpoint: { type: 'string', default: '/.well-known/graphql-composition' },
89
- entities
90
- },
91
- additionalProperties: false
92
- }
93
- ]
94
- }
95
-
96
- const graphqlComposerOptions = {
97
- type: 'object',
98
- properties: {
99
- ...graphqlBase.properties,
100
- // TODO support subscriptions, subscriptions: { type: 'boolean', default: false },
101
- onSubgraphError: { typeof: 'function' },
102
- defaultArgsAdapter: {
103
- oneOf: [{ typeof: 'function' }, { type: 'string' }]
104
- },
105
- entities,
106
- addEntitiesResolvers: { type: 'boolean', default: false }
107
- },
108
- additionalProperties: false
109
- }
110
-
111
- const composer = {
112
- type: 'object',
113
- properties: {
114
- services: {
115
- type: 'array',
116
- items: {
117
- type: 'object',
118
- properties: {
119
- id: { type: 'string' },
120
- origin: { type: 'string' },
121
- openapi: openApiService,
122
- graphql: graphqlService,
123
- proxy: {
124
- oneOf: [
125
- { type: 'boolean', const: false },
126
- {
127
- type: 'object',
128
- properties: {
129
- prefix: { type: 'string' }
130
- },
131
- required: [],
132
- additionalProperties: false
133
- }
134
- ]
135
- }
136
- },
137
- required: ['id'],
138
- additionalProperties: false
139
- }
140
- },
141
- openapi: openApiBase,
142
- graphql: graphqlComposerOptions,
143
- addEmptySchema: { type: 'boolean', default: false },
144
- refreshTimeout: { type: 'integer', minimum: 0, default: 1000 }
145
- },
146
- required: [],
147
- additionalProperties: false
148
- }
149
-
150
- const types = {
151
- type: 'object',
152
- properties: {
153
- autogenerate: {
154
- type: 'boolean'
155
- },
156
- dir: {
157
- description: 'The path to the directory the types should be generated in.',
158
- type: 'string',
159
- default: 'types',
160
- resolvePath: true
161
- }
162
- },
163
- additionalProperties: false
164
- }
165
-
166
- const platformaticComposerSchema = {
167
- $id: `https://schemas.platformatic.dev/@platformatic/composer/${pkg.version}.json`,
168
- $schema: 'http://json-schema.org/draft-07/schema#',
169
- title: 'Platformatic Composer',
170
- type: 'object',
171
- properties: {
172
- basePath: {
173
- type: 'string'
174
- },
175
- server,
176
- composer,
177
- metrics,
178
- types,
179
- plugins,
180
- clients,
181
- telemetry,
182
- watch: {
183
- anyOf: [
184
- watch,
185
- {
186
- type: 'boolean'
187
- },
188
- {
189
- type: 'string'
190
- }
191
- ]
192
- },
193
- $schema: {
194
- type: 'string'
195
- },
196
- module: {
197
- type: 'string'
198
- }
199
- },
200
- additionalProperties: false,
201
- required: ['composer'],
202
- $defs: openApiDefs
203
- }
204
-
205
- module.exports.schema = platformaticComposerSchema
206
-
207
- /* c8 ignore next 3 */
208
- if (require.main === module) {
209
- console.log(JSON.stringify(platformaticComposerSchema, null, 2))
210
- }
package/lib/stackable.js DELETED
@@ -1,59 +0,0 @@
1
- 'use strict'
2
-
3
- const { ServiceStackable } = require('@platformatic/service')
4
-
5
- class ComposerStackable extends ServiceStackable {
6
- #meta
7
-
8
- async getBootstrapDependencies () {
9
- // We do not call init() on purpose, as we don't want to load the up just yet.
10
-
11
- const composedServices = this.configManager.current.composer?.services
12
- const dependencies = []
13
-
14
- if (Array.isArray(composedServices)) {
15
- dependencies.push(
16
- ...(await Promise.all(
17
- composedServices.map(async service => {
18
- return this.#parseDependency(service.id, service.origin)
19
- })
20
- ))
21
- )
22
- }
23
-
24
- return dependencies
25
- }
26
-
27
- async #parseDependency (id, urlString) {
28
- let url = this.#getServiceUrl(id)
29
-
30
- if (urlString) {
31
- const remoteUrl = await this.configManager.replaceEnv(urlString)
32
-
33
- if (remoteUrl) {
34
- url = remoteUrl
35
- }
36
- }
37
-
38
- return { id, url, local: url.endsWith('.plt.local') }
39
- }
40
-
41
- registerMeta (meta) {
42
- this.#meta = Object.assign(this.#meta ?? {}, meta)
43
- }
44
-
45
- async getMeta () {
46
- const serviceMeta = super.getMeta()
47
- const composerMeta = this.#meta ? { composer: this.#meta } : undefined
48
-
49
- return {
50
- ...serviceMeta,
51
- ...composerMeta
52
- }
53
- }
54
-
55
- #getServiceUrl (id) {
56
- return `http://${id}.plt.local`
57
- }
58
- }
59
- module.exports = { ComposerStackable }
package/lib/upgrade.js DELETED
@@ -1,22 +0,0 @@
1
- 'use strict'
2
-
3
- const { join } = require('path')
4
-
5
- module.exports = async function upgrade (config, version) {
6
- const { semgrator } = await import('semgrator')
7
-
8
- const iterator = semgrator({
9
- version,
10
- path: join(__dirname, 'versions'),
11
- input: config,
12
- logger: this.logger.child({ name: '@platformatic/composer' }),
13
- })
14
-
15
- let result
16
-
17
- for await (const updated of iterator) {
18
- result = updated.result
19
- }
20
-
21
- return result
22
- }
package/lib/utils.js DELETED
@@ -1,27 +0,0 @@
1
- 'use strict'
2
-
3
- function prefixWithSlash (url) {
4
- if (typeof url === 'string') {
5
- return url.startsWith('/')
6
- ? url
7
- : `/${url}`
8
- }
9
- return ''
10
- }
11
-
12
- /**
13
- * detect if a service if fetchable, so if it has configuration to retrieve schema info (openapi or gql)
14
- * a service can have openapi and/or gql either from a remote service or from file
15
- * note service.origin is always been set if missing at index.js/platformaticComposer
16
- * @returns {boolean}
17
- */
18
- function isFetchable (service) {
19
- return Boolean(
20
- (service?.openapi && service.openapi.url) || service?.graphql
21
- )
22
- }
23
-
24
- module.exports = {
25
- prefixWithSlash,
26
- isFetchable,
27
- }
@@ -1,11 +0,0 @@
1
- 'use strict'
2
-
3
- const pkg = require('../../package.json')
4
-
5
- module.exports = {
6
- version: '2.0.0',
7
- up: function (config) {
8
- config.$schema = `https://schemas.platformatic.dev/@platformatic/composer/${pkg.version}.json`
9
- return config
10
- }
11
- }