@platformatic/service 1.51.8 → 2.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/lib/schema.js CHANGED
@@ -5,391 +5,7 @@
5
5
  const pkg = require('../package.json')
6
6
  const openApiDefs = require('./openapi-schema-defs')
7
7
  const telemetry = require('@platformatic/telemetry').schema
8
-
9
- const cors = {
10
- type: 'object',
11
- $comment: 'See https://github.com/fastify/fastify-cors',
12
- properties: {
13
- origin: {
14
- anyOf: [
15
- { type: 'boolean' },
16
- { type: 'string' },
17
- {
18
- type: 'array',
19
- items: {
20
- anyOf: [{
21
- type: 'string'
22
- }, {
23
- type: 'object',
24
- properties: {
25
- regexp: {
26
- type: 'string'
27
- }
28
- },
29
- required: ['regexp']
30
- }]
31
- }
32
- },
33
- {
34
- type: 'object',
35
- properties: {
36
- regexp: {
37
- type: 'string'
38
- }
39
- },
40
- required: ['regexp']
41
- }
42
- ]
43
- },
44
- methods: {
45
- type: 'array',
46
- items: {
47
- type: 'string'
48
- }
49
- },
50
- allowedHeaders: {
51
- type: 'string',
52
- description: 'Comma separated string of allowed headers.'
53
- },
54
- exposedHeaders: {
55
- anyOf: [
56
- {
57
- type: 'array',
58
- items: {
59
- type: 'string'
60
- }
61
- },
62
- {
63
- type: 'string',
64
- description: 'Comma separated string of exposed headers.'
65
- }
66
- ]
67
- },
68
- credentials: {
69
- type: 'boolean'
70
- },
71
- maxAge: {
72
- type: 'integer'
73
- },
74
- preflightContinue: {
75
- type: 'boolean',
76
- default: false
77
- },
78
- optionsSuccessStatus: {
79
- type: 'integer',
80
- default: 204
81
- },
82
- preflight: {
83
- type: 'boolean',
84
- default: true
85
- },
86
- strictPreflight: {
87
- type: 'boolean',
88
- default: true
89
- },
90
- hideOptionsRoute: {
91
- type: 'boolean',
92
- default: true
93
- }
94
- },
95
- additionalProperties: false
96
- }
97
-
98
- const server = {
99
- type: 'object',
100
- properties: {
101
- // TODO add support for level
102
- hostname: {
103
- type: 'string'
104
- },
105
- port: {
106
- anyOf: [
107
- { type: 'integer' },
108
- { type: 'string' }
109
- ]
110
- },
111
- pluginTimeout: {
112
- type: 'integer'
113
- },
114
- healthCheck: {
115
- anyOf: [
116
- { type: 'boolean' },
117
- {
118
- type: 'object',
119
- properties: {
120
- enabled: { type: 'boolean' },
121
- interval: { type: 'integer' }
122
- },
123
- additionalProperties: true
124
- }
125
- ]
126
- },
127
- ignoreTrailingSlash: {
128
- type: 'boolean'
129
- },
130
- ignoreDuplicateSlashes: {
131
- type: 'boolean'
132
- },
133
- connectionTimeout: {
134
- type: 'integer'
135
- },
136
- keepAliveTimeout: {
137
- type: 'integer',
138
- default: 5000
139
- },
140
- maxRequestsPerSocket: {
141
- type: 'integer'
142
- },
143
- forceCloseConnections: {
144
- anyOf: [
145
- { type: 'boolean' },
146
- { type: 'string', pattern: '^idle$' }
147
- ]
148
- },
149
- requestTimeout: {
150
- type: 'integer'
151
- },
152
- bodyLimit: {
153
- type: 'integer'
154
- },
155
- maxParamLength: {
156
- type: 'integer'
157
- },
158
- disableRequestLogging: {
159
- type: 'boolean'
160
- },
161
- exposeHeadRoutes: {
162
- type: 'boolean'
163
- },
164
- logger: {
165
- anyOf: [
166
- { type: 'boolean' },
167
- {
168
- type: 'object',
169
- properties: {
170
- level: {
171
- type: 'string'
172
- },
173
- transport: {
174
- anyOf: [{
175
- type: 'object',
176
- properties: {
177
- target: {
178
- type: 'string',
179
- resolveModule: true
180
- },
181
- options: {
182
- type: 'object'
183
- }
184
- },
185
- additionalProperties: false
186
- }, {
187
- type: 'object',
188
- properties: {
189
- targets: {
190
- type: 'array',
191
- items: {
192
- type: 'object',
193
- properties: {
194
- target: {
195
- type: 'string',
196
- resolveModule: true
197
- },
198
- options: {
199
- type: 'object'
200
- },
201
- level: {
202
- type: 'string'
203
- },
204
- additionalProperties: false
205
- }
206
- }
207
- },
208
- options: {
209
- type: 'object'
210
- }
211
- },
212
- additionalProperties: false
213
- }]
214
- },
215
- pipeline: {
216
- type: 'object',
217
- properties: {
218
- target: {
219
- type: 'string',
220
- resolveModule: true
221
- },
222
- options: {
223
- type: 'object'
224
- }
225
- },
226
- additionalProperties: false
227
- }
228
- },
229
- additionalProperties: true
230
- }
231
- ]
232
- },
233
- serializerOpts: {
234
- type: 'object',
235
- properties: {
236
- schema: {
237
- type: 'object'
238
- },
239
- ajv: {
240
- type: 'object'
241
- },
242
- rounding: {
243
- type: 'string',
244
- enum: ['floor', 'ceil', 'round', 'trunc'],
245
- default: 'trunc'
246
- },
247
- debugMode: {
248
- type: 'boolean'
249
- },
250
- mode: {
251
- type: 'string',
252
- enum: ['debug', 'standalone']
253
- },
254
- largeArraySize: {
255
- anyOf: [
256
- { type: 'integer' },
257
- { type: 'string' }
258
- ],
259
- default: 20000
260
- },
261
- largeArrayMechanism: {
262
- type: 'string',
263
- enum: ['default', 'json-stringify'],
264
- default: 'default'
265
- }
266
- }
267
- },
268
- caseSensitive: {
269
- type: 'boolean'
270
- },
271
- requestIdHeader: {
272
- anyOf: [
273
- { type: 'string' },
274
- { type: 'boolean', const: false }
275
- ]
276
- },
277
- requestIdLogLabel: {
278
- type: 'string'
279
- },
280
- jsonShorthand: {
281
- type: 'boolean'
282
- },
283
- trustProxy: {
284
- anyOf: [
285
- { type: 'boolean' },
286
- { type: 'string' },
287
- {
288
- type: 'array',
289
- items: {
290
- type: 'string'
291
- }
292
- },
293
- { type: 'integer' }
294
- ]
295
- },
296
- http2: {
297
- type: 'boolean'
298
- },
299
- https: {
300
- type: 'object',
301
- properties: {
302
- allowHTTP1: {
303
- type: 'boolean'
304
- },
305
- key: {
306
- anyOf: [
307
- {
308
- type: 'string'
309
- },
310
- {
311
- type: 'object',
312
- properties: {
313
- path: {
314
- type: 'string',
315
- resolvePath: true
316
- }
317
- },
318
- additionalProperties: false
319
- },
320
- {
321
- type: 'array',
322
- items: {
323
- anyOf: [
324
- {
325
- type: 'string'
326
- },
327
- {
328
- type: 'object',
329
- properties: {
330
- path: {
331
- type: 'string',
332
- resolvePath: true
333
- }
334
- },
335
- additionalProperties: false
336
- }
337
- ]
338
- }
339
- }
340
- ]
341
- },
342
- cert: {
343
- anyOf: [
344
- {
345
- type: 'string'
346
- },
347
- {
348
- type: 'object',
349
- properties: {
350
- path: {
351
- type: 'string',
352
- resolvePath: true
353
- }
354
- },
355
- additionalProperties: false
356
- },
357
- {
358
- type: 'array',
359
- items: {
360
- anyOf: [
361
- {
362
- type: 'string'
363
- },
364
- {
365
- type: 'object',
366
- properties: {
367
- path: {
368
- type: 'string',
369
- resolvePath: true
370
- }
371
- },
372
- additionalProperties: false
373
- }
374
- ]
375
- }
376
- }
377
- ]
378
- },
379
- requestCert: {
380
- type: 'boolean'
381
- },
382
- rejectUnauthorized: {
383
- type: 'boolean'
384
- }
385
- },
386
- additionalProperties: false,
387
- required: ['key', 'cert']
388
- },
389
- cors
390
- },
391
- additionalProperties: false
392
- }
8
+ const { server, cors } = require('@platformatic/utils').schemas
393
9
 
394
10
  const watch = {
395
11
  type: 'object',
@@ -726,47 +342,6 @@ const clients = {
726
342
  }
727
343
  }
728
344
 
729
- const version = {
730
- type: 'object',
731
- properties: {
732
- version: { type: 'string' },
733
- openapi: {
734
- type: 'object',
735
- properties: {
736
- prefix: {
737
- type: 'string'
738
- },
739
- path: {
740
- type: 'string',
741
- resolvePath: true
742
- }
743
- },
744
- additionalProperties: false
745
- },
746
- plugins
747
- },
748
- required: ['version'],
749
- additionalProperties: false
750
- }
751
-
752
- const versions = {
753
- type: 'object',
754
- properties: {
755
- dir: {
756
- type: 'string',
757
- description: 'The path to the directory containing the versions mappers',
758
- resolvePath: true,
759
- default: 'versions'
760
- },
761
- configs: {
762
- type: 'array',
763
- items: version
764
- }
765
- },
766
- required: ['dir', 'configs'],
767
- additionalProperties: false
768
- }
769
-
770
345
  const platformaticServiceSchema = {
771
346
  $id: `https://platformatic.dev/schemas/v${pkg.version}/service`,
772
347
  version: pkg.version,
@@ -788,13 +363,68 @@ const platformaticServiceSchema = {
788
363
  type: 'string'
789
364
  },
790
365
  service,
791
- clients,
792
- versions
366
+ clients
793
367
  },
794
368
  additionalProperties: false,
795
369
  $defs: openApiDefs
796
370
  }
797
371
 
372
+ /*
373
+ * Legacy definitions for backwards compatibility.
374
+ * They are non/enumerable to avoid being included in the schema.
375
+ */
376
+ Object.defineProperty(platformaticServiceSchema, 'schema', {
377
+ enumerable: false,
378
+ value: platformaticServiceSchema
379
+ })
380
+
381
+ Object.defineProperty(platformaticServiceSchema, 'server', {
382
+ enumerable: false,
383
+ value: server
384
+ })
385
+
386
+ Object.defineProperty(platformaticServiceSchema, 'cors', {
387
+ enumerable: false,
388
+ value: cors
389
+ })
390
+
391
+ Object.defineProperty(platformaticServiceSchema, 'metrics', {
392
+ enumerable: false,
393
+ value: metrics
394
+ })
395
+
396
+ Object.defineProperty(platformaticServiceSchema, 'plugins', {
397
+ enumerable: false,
398
+ value: plugins
399
+ })
400
+
401
+ Object.defineProperty(platformaticServiceSchema, 'watch', {
402
+ enumerable: false,
403
+ value: watch
404
+ })
405
+
406
+ Object.defineProperty(platformaticServiceSchema, 'openApiDefs', {
407
+ enumerable: false,
408
+ value: openApiDefs
409
+ })
410
+
411
+ Object.defineProperty(platformaticServiceSchema, 'openApiBase', {
412
+ enumerable: false,
413
+ value: openApiBase
414
+ })
415
+
416
+ Object.defineProperty(platformaticServiceSchema, 'graphqlBase', {
417
+ enumerable: false,
418
+ value: graphqlBase
419
+ })
420
+
421
+ Object.defineProperty(platformaticServiceSchema, 'clients', {
422
+ enumerable: false,
423
+ value: clients
424
+ })
425
+
426
+ /* end */
427
+
798
428
  module.exports.schema = platformaticServiceSchema
799
429
  module.exports.metrics = metrics
800
430
  module.exports.cors = cors
package/lib/start.js CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  const { readFile } = require('fs/promises')
4
4
  const close = require('close-with-grace')
5
- const { Bus } = require('@platformatic/bus')
6
5
  const { loadConfig, ConfigManager, printConfigValidationErrors, printAndExitLoadConfigError } = require('@platformatic/config')
7
6
  const { addLoggerToTheConfig, isDocker } = require('./utils.js')
8
7
  const { restartable } = require('@fastify/restartable')
@@ -61,12 +60,10 @@ async function buildServer (options, app) {
61
60
  }
62
61
  fastifyOptions.genReqId = function (req) { return randomUUID() }
63
62
  const root = fastify(fastifyOptions)
64
- root.decorate('platformatic', { configManager, config, bus: new Bus(options.id) })
63
+ root.decorate('platformatic', { configManager, config })
65
64
  await root.register(app)
66
65
  if (!root.hasRoute({ url: '/', method: 'GET' })) {
67
- await root.register(require('./root-endpoint'), {
68
- versions: config.versions
69
- })
66
+ await root.register(require('./root-endpoint'))
70
67
  }
71
68
 
72
69
  root.decorate('url', {
package/lib/utils.js CHANGED
@@ -70,126 +70,6 @@ function getJSPluginPath (workingDir, tsPluginPath, compileDir) {
70
70
  return join(compileDir, jsPluginRelativePath)
71
71
  }
72
72
 
73
- function convertOpenApiToFastifyPath (openApiPath) {
74
- return openApiPath
75
- .replace(/{wildcard}/g, '*')
76
- .replace(/{(\w+)}/g, ':$1')
77
- }
78
-
79
- function updateOpenApiSchemaRefs (openapiSchema) {
80
- const componentsPrefix = '#/components/schemas/'
81
-
82
- for (const key of Object.keys(openapiSchema)) {
83
- const value = openapiSchema[key]
84
-
85
- if (key === '$ref' && value.startsWith(componentsPrefix)) {
86
- openapiSchema.$ref = value
87
- .replace(componentsPrefix, '')
88
- .split('/', 1)
89
- .join('#/')
90
-
91
- continue
92
- }
93
-
94
- if (typeof value === 'object') {
95
- updateOpenApiSchemaRefs(value)
96
- }
97
- }
98
- }
99
-
100
- function convertOpenApiToFastifyRouteSchema (openapiSchema) {
101
- const routeSchema = {}
102
-
103
- for (const openApiParam of openapiSchema.parameters ?? []) {
104
- const name = openApiParam.name
105
- const schema = openApiParam.schema
106
-
107
- if (openApiParam.in === 'path') {
108
- if (routeSchema.params === undefined) {
109
- routeSchema.params = {
110
- type: 'object',
111
- properties: {},
112
- required: []
113
- }
114
- }
115
-
116
- routeSchema.params.properties[name] = schema
117
- if (openApiParam.required) {
118
- routeSchema.params.required.push(name)
119
- }
120
- }
121
-
122
- if (openApiParam.in === 'header') {
123
- if (routeSchema.headers === undefined) {
124
- routeSchema.headers = {
125
- type: 'object',
126
- properties: {},
127
- required: []
128
- }
129
- }
130
-
131
- routeSchema.headers.properties[name] = schema
132
- if (openApiParam.required) {
133
- routeSchema.headers.required.push(name)
134
- }
135
- }
136
-
137
- if (openApiParam.in === 'query') {
138
- if (routeSchema.querystring === undefined) {
139
- routeSchema.querystring = {
140
- type: 'object',
141
- properties: {},
142
- required: []
143
- }
144
- }
145
-
146
- routeSchema.querystring.properties[name] = schema
147
- if (openApiParam.required) {
148
- routeSchema.querystring.required.push(name)
149
- }
150
- }
151
- }
152
-
153
- if (openapiSchema.requestBody) {
154
- const content = openapiSchema.requestBody.content
155
- const contentType = Object.keys(content)[0]
156
- routeSchema.body = content[contentType].schema
157
- }
158
-
159
- for (const statusCode of Object.keys(openapiSchema.responses ?? {})) {
160
- const response = openapiSchema.responses[statusCode]
161
- const responseSchema = response.content?.['application/json']?.schema
162
- if (responseSchema) {
163
- if (!routeSchema.response) {
164
- routeSchema.response = {}
165
- }
166
- routeSchema.response[statusCode] = responseSchema
167
- }
168
- }
169
-
170
- updateOpenApiSchemaRefs(routeSchema)
171
-
172
- return routeSchema
173
- }
174
-
175
- function changeOpenapiSchemaPrefix (openapiSchema, oldVersionPrefix, newVersionPrefix) {
176
- if (!oldVersionPrefix && !newVersionPrefix) return openapiSchema
177
-
178
- const normalizedPaths = {}
179
- for (const oldPath of Object.keys(openapiSchema.paths ?? {})) {
180
- const newPath = oldVersionPrefix
181
- ? oldPath.replace(oldVersionPrefix, newVersionPrefix)
182
- : newVersionPrefix + oldPath
183
-
184
- normalizedPaths[newPath] = openapiSchema.paths[oldPath]
185
- }
186
-
187
- return {
188
- ...openapiSchema,
189
- paths: normalizedPaths
190
- }
191
- }
192
-
193
73
  let isDockerCached
194
74
 
195
75
  async function isDocker () {
@@ -221,8 +101,5 @@ module.exports = {
221
101
  isDocker,
222
102
  isFileAccessible,
223
103
  getJSPluginPath,
224
- addLoggerToTheConfig,
225
- changeOpenapiSchemaPrefix,
226
- convertOpenApiToFastifyPath,
227
- convertOpenApiToFastifyRouteSchema
104
+ addLoggerToTheConfig
228
105
  }
@@ -0,0 +1,15 @@
1
+ 'use strict'
2
+
3
+ const { version } = require('../../package.json')
4
+
5
+ module.exports.migration = {
6
+ version: '2.0.0',
7
+ toVersion: version,
8
+ up: function (config) {
9
+ if (typeof config.allowCycles === 'boolean') {
10
+ delete config.allowCycles
11
+ }
12
+
13
+ return config
14
+ }
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/service",
3
- "version": "1.51.8",
3
+ "version": "2.0.0-alpha.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -71,7 +71,6 @@
71
71
  "mercurius": "^14.0.0",
72
72
  "minimist": "^1.2.8",
73
73
  "my-ua-parser": "^2.0.2",
74
- "openapi-schema-diff": "^0.0.1",
75
74
  "ora": "^6.3.1",
76
75
  "pino": "^8.19.0",
77
76
  "pino-pretty": "^11.0.0",
@@ -79,13 +78,13 @@
79
78
  "rfdc": "^1.3.1",
80
79
  "semgrator": "^0.3.0",
81
80
  "undici": "^6.9.0",
82
- "@platformatic/bus": "1.51.8",
83
- "@platformatic/config": "1.51.8",
84
- "@platformatic/client": "1.51.8",
85
- "@platformatic/generators": "1.51.8",
86
- "@platformatic/utils": "1.51.8",
87
- "@platformatic/scalar-theme": "1.51.8",
88
- "@platformatic/telemetry": "1.51.8"
81
+ "@platformatic/client": "2.0.0-alpha.2",
82
+ "@platformatic/config": "2.0.0-alpha.2",
83
+ "@platformatic/generators": "2.0.0-alpha.2",
84
+ "@platformatic/telemetry": "2.0.0-alpha.2",
85
+ "@platformatic/utils": "2.0.0-alpha.2",
86
+ "@platformatic/scalar-theme": "2.0.0-alpha.2",
87
+ "@platformatic/ts-compiler": "2.0.0-alpha.2"
89
88
  },
90
89
  "standard": {
91
90
  "ignore": [