@platformatic/runtime 1.41.0 → 1.42.0

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/index.d.ts CHANGED
@@ -17,6 +17,7 @@ declare module '@platformatic/runtime' {
17
17
  export function loadConfig(minimistConfig: object, args: object, store: object, overrides: object, replaceEnv: boolean): void
18
18
  export function compile(argv: string[], logger: BaseLogger): void
19
19
  export function platformaticRuntime(): Promise<void>
20
+ export function wrapConfigInRuntimeConfig(args: object): object
20
21
  export const Generator: RuntimeGenerator.RuntimeGenerator
21
22
  }
22
23
 
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
  const { buildServer } = require('./lib/build-server')
3
- const { platformaticRuntime } = require('./lib/config')
3
+ const { platformaticRuntime, wrapConfigInRuntimeConfig } = require('./lib/config')
4
4
  const { start, startCommand } = require('./lib/start')
5
5
  const RuntimeApi = require('./lib/api')
6
6
  const { compile } = require('./lib/compile')
@@ -10,6 +10,7 @@ const RuntimeGenerator = require('./lib/generator/runtime-generator')
10
10
 
11
11
  module.exports.buildServer = buildServer
12
12
  module.exports.platformaticRuntime = platformaticRuntime
13
+ module.exports.wrapConfigInRuntimeConfig = wrapConfigInRuntimeConfig
13
14
  module.exports.schema = platformaticRuntime.schema
14
15
  module.exports.RuntimeApi = RuntimeApi
15
16
  module.exports.start = start
@@ -36,7 +36,7 @@ async function buildServerRuntime (options = {}) {
36
36
  }
37
37
  }
38
38
 
39
- return buildRuntime(options.configManager)
39
+ return buildRuntime(options.configManager, options.env)
40
40
  }
41
41
 
42
42
  async function buildServer (options) {
package/lib/errors.js CHANGED
@@ -24,7 +24,6 @@ module.exports = {
24
24
  NodeInspectorFlagsNotSupportedError: createError(`${ERROR_PREFIX}_NODE_INSPECTOR_FLAGS_NOT_SUPPORTED`, 'The Node.js inspector flags are not supported. Please use \'platformatic start --inspect\' instead.'),
25
25
  FailedToUnlinkManagementApiSocket: createError(`${ERROR_PREFIX}_FAILED_TO_UNLINK_MANAGEMENT_API_SOCKET`, 'Failed to unlink management API socket "%s"'),
26
26
  LogFileNotFound: createError(`${ERROR_PREFIX}_LOG_FILE_NOT_FOUND`, 'Log file with index %s not found', 404),
27
- CannotFindGeneratorForTemplateError: createError(`${ERROR_PREFIX}_CANNOT_FIND_GENERATOR_FOR_TEMPLATE`, 'Cannot find a generator for template "%s"'),
28
27
  WorkerIsRequired: createError(`${ERROR_PREFIX}_REQUIRED_WORKER`, 'The worker parameter is required'),
29
28
 
30
29
  // TODO: should remove next one as it's not used anymore
@@ -8,13 +8,11 @@ const { envObjectToString } = require('@platformatic/generators/lib/utils')
8
8
  const { readFile, readdir, stat, rm } = require('node:fs/promises')
9
9
  const { ConfigManager } = require('@platformatic/config')
10
10
  const { platformaticRuntime } = require('../config')
11
- const ServiceGenerator = require('@platformatic/service/lib/generator/service-generator')
12
- const DBGenerator = require('@platformatic/db/lib/generator/db-generator')
13
- const ComposerGenerator = require('@platformatic/composer/lib/generator/composer-generator')
14
- const { CannotFindGeneratorForTemplateError } = require('../errors')
15
11
  const { getServiceTemplateFromSchemaUrl } = require('@platformatic/generators/lib/utils')
16
12
  const { DotEnvTool } = require('dotenv-tool')
17
13
  const { getArrayDifference } = require('../utils')
14
+ const { createRequire } = require('node:module')
15
+ const { pathToFileURL } = require('node:url')
18
16
 
19
17
  class RuntimeGenerator extends BaseGenerator {
20
18
  constructor (opts) {
@@ -299,17 +297,10 @@ class RuntimeGenerator extends BaseGenerator {
299
297
  }
300
298
  }
301
299
 
302
- getGeneratorForTemplate (templateName) {
303
- switch (templateName) {
304
- case '@platformatic/service':
305
- return ServiceGenerator
306
- case '@platformatic/db':
307
- return DBGenerator
308
- case '@platformatic/composer':
309
- return ComposerGenerator
310
- default:
311
- throw new CannotFindGeneratorForTemplateError(templateName)
312
- }
300
+ async _getGeneratorForTemplate (dir, pkg) {
301
+ const _require = createRequire(dir)
302
+ const fileToImport = _require.resolve(pkg)
303
+ return (await import(pathToFileURL(fileToImport))).Generator
313
304
  }
314
305
 
315
306
  async loadFromDir () {
@@ -327,11 +318,13 @@ class RuntimeGenerator extends BaseGenerator {
327
318
  const dirStat = await stat(currentServicePath)
328
319
  if (dirStat.isDirectory()) {
329
320
  // load the package json file
330
- const servicePkgJson = JSON.parse(await readFile(join(currentServicePath, 'platformatic.json'), 'utf-8'))
331
- // get generator for this module
332
- const template = getServiceTemplateFromSchemaUrl(servicePkgJson.$schema)
333
- const Generator = this.getGeneratorForTemplate(template)
334
- const instance = new Generator()
321
+ const servicePltJson = JSON.parse(await readFile(join(currentServicePath, 'platformatic.json'), 'utf-8'))
322
+ // get module to load
323
+ const template = servicePltJson.module || getServiceTemplateFromSchemaUrl(servicePltJson.$schema)
324
+ const Generator = await this._getGeneratorForTemplate(currentServicePath, template)
325
+ const instance = new Generator({
326
+ logger: this.logger
327
+ })
335
328
  this.addService(instance, s)
336
329
  output.services.push(await instance.loadFromDir(s, this.targetDirectory))
337
330
  }
@@ -387,8 +380,10 @@ class RuntimeGenerator extends BaseGenerator {
387
380
  // handle new services
388
381
  for (const newService of newConfig.services) {
389
382
  // create generator for the service
390
- const ServiceGenerator = this.getGeneratorForTemplate(newService.template)
391
- const serviceInstance = new ServiceGenerator()
383
+ const ServiceGenerator = await this._getGeneratorForTemplate(join(this.targetDirectory, 'package.json'), newService.template)
384
+ const serviceInstance = new ServiceGenerator({
385
+ logger: this.logger
386
+ })
392
387
  const baseConfig = {
393
388
  isRuntimeContext: true,
394
389
  targetDirectory: join(this.targetDirectory, 'services', newService.name),
package/lib/start.js CHANGED
@@ -37,7 +37,8 @@ function startWorker ({ config, dirname, runtimeLogsDir }, env) {
37
37
  return worker
38
38
  }
39
39
 
40
- async function buildRuntime (configManager, env = process.env) {
40
+ async function buildRuntime (configManager, env) {
41
+ env = env || process.env
41
42
  const config = configManager.current
42
43
 
43
44
  if (inspector.url()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/runtime",
3
- "version": "1.41.0",
3
+ "version": "1.42.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -34,8 +34,8 @@
34
34
  "typescript": "^5.4.2",
35
35
  "undici-oidc-interceptor": "^0.5.0",
36
36
  "why-is-node-running": "^2.2.2",
37
- "@platformatic/sql-mapper": "1.41.0",
38
- "@platformatic/sql-graphql": "1.41.0"
37
+ "@platformatic/sql-graphql": "1.42.0",
38
+ "@platformatic/sql-mapper": "1.42.0"
39
39
  },
40
40
  "dependencies": {
41
41
  "@fastify/error": "^3.4.1",
@@ -63,13 +63,13 @@
63
63
  "undici": "^6.9.0",
64
64
  "why-is-node-running": "^2.2.2",
65
65
  "ws": "^8.16.0",
66
- "@platformatic/composer": "1.41.0",
67
- "@platformatic/config": "1.41.0",
68
- "@platformatic/db": "1.41.0",
69
- "@platformatic/generators": "1.41.0",
70
- "@platformatic/service": "1.41.0",
71
- "@platformatic/telemetry": "1.41.0",
72
- "@platformatic/utils": "1.41.0"
66
+ "@platformatic/composer": "1.42.0",
67
+ "@platformatic/db": "1.42.0",
68
+ "@platformatic/config": "1.42.0",
69
+ "@platformatic/service": "1.42.0",
70
+ "@platformatic/generators": "1.42.0",
71
+ "@platformatic/telemetry": "1.42.0",
72
+ "@platformatic/utils": "1.42.0"
73
73
  },
74
74
  "standard": {
75
75
  "ignore": [