@platformatic/runtime 2.16.0-alpha.1 → 2.16.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/config.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * and run json-schema-to-typescript to regenerate this file.
6
6
  */
7
7
 
8
- export type HttpsSchemasPlatformaticDevPlatformaticRuntime2160Alpha1Json = {
8
+ export type HttpsSchemasPlatformaticDevPlatformaticRuntime2160Json = {
9
9
  [k: string]: unknown;
10
10
  } & {
11
11
  $schema?: string;
@@ -165,7 +165,6 @@ export type HttpsSchemasPlatformaticDevPlatformaticRuntime2160Alpha1Json = {
165
165
  [k: string]: unknown;
166
166
  };
167
167
  serviceTimeout?: number | string;
168
- resolvedServicesBasePath?: string;
169
168
  };
170
169
 
171
170
  export interface UndiciInterceptor {
package/lib/config.js CHANGED
@@ -87,9 +87,8 @@ async function _transformConfig (configManager, args) {
87
87
  for (let i = 0; i < services.length; ++i) {
88
88
  const service = services[i]
89
89
 
90
- // We need to have absolute paths here, ot the `loadConfig` will fail
91
- // Make sure we don't resolve if env var was not replaced
92
- if (service.path && !isAbsolute(service.path) && !service.path.match(/^\{.*\}$/)) {
90
+ // We need to have absolut paths here, ot the `loadConfig` will fail
91
+ if (!isAbsolute(service.path)) {
93
92
  service.path = pathResolve(configManager.dirname, service.path)
94
93
  }
95
94
 
package/lib/errors.js CHANGED
@@ -7,7 +7,6 @@ const ERROR_PREFIX = 'PLT_RUNTIME'
7
7
  module.exports = {
8
8
  AddressInUseError: createError(`${ERROR_PREFIX}_EADDR_IN_USE`, 'The current port is in use by another application'),
9
9
  RuntimeExitedError: createError(`${ERROR_PREFIX}_RUNTIME_EXIT`, 'The runtime exited before the operation completed'),
10
- RuntimeAbortedError: createError(`${ERROR_PREFIX}_RUNTIME_ABORT`, 'The runtime aborted the operation'),
11
10
  // The following two use the same code as we only need to differentiate the label
12
11
  ServiceExitedError: createError(`${ERROR_PREFIX}_SERVICE_EXIT`, 'The service "%s" exited prematurely with error code %d'),
13
12
  WorkerExitedError: createError(`${ERROR_PREFIX}_SERVICE_EXIT`, 'The worker %s of the service "%s" exited prematurely with error code %d'),
package/lib/runtime.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const { once, EventEmitter } = require('node:events')
4
- const { createReadStream, watch, existsSync } = require('node:fs')
4
+ const { createReadStream, watch } = require('node:fs')
5
5
  const { readdir, readFile, stat, access } = require('node:fs/promises')
6
6
  const { join } = require('node:path')
7
7
  const { setTimeout: sleep } = require('node:timers/promises')
@@ -111,33 +111,16 @@ class Runtime extends EventEmitter {
111
111
  this.#servicesIds = config.services.map(service => service.id)
112
112
  this.#workers.configure(config.services, this.#configManager.current.workers, this.#isProduction)
113
113
 
114
+ if (this.#isProduction) {
115
+ this.#env['PLT_DEV'] = 'false'
116
+ this.#env['PLT_ENVIRONMENT'] = 'production'
117
+ } else {
118
+ this.#env['PLT_DEV'] = 'true'
119
+ this.#env['PLT_ENVIRONMENT'] = 'development'
120
+ }
121
+
114
122
  // Create all services, each in is own worker thread
115
123
  for (const serviceConfig of config.services) {
116
- // If there is no service path, check if the service was resolved
117
- if (!serviceConfig.path) {
118
- if (serviceConfig.url) {
119
- // Try to backfill the path for external services
120
- serviceConfig.path = join(this.#configManager.dirname, config.resolvedServicesBasePath, serviceConfig.id)
121
-
122
- if (!existsSync(serviceConfig.path)) {
123
- const executable = globalThis.platformatic?.executable ?? 'platformatic'
124
- this.logger.error(
125
- `The path for service "%s" does not exist. Please run "${executable} resolve" and try again.`,
126
- serviceConfig.id
127
- )
128
-
129
- throw new errors.RuntimeAbortedError()
130
- }
131
- } else {
132
- this.logger.error(
133
- 'The service "%s" has no path defined. Please check your configuration and try again.',
134
- serviceConfig.id
135
- )
136
-
137
- throw new errors.RuntimeAbortedError()
138
- }
139
- }
140
-
141
124
  await this.#setupService(serviceConfig)
142
125
  }
143
126
 
@@ -287,7 +270,7 @@ class Runtime extends EventEmitter {
287
270
  this.#updateStatus('closed')
288
271
  }
289
272
 
290
- async startService (id, silent = false) {
273
+ async startService (id, silent) {
291
274
  // Since when a service is stopped the worker is deleted, we consider a service start if its first service
292
275
  // is no longer in the init phase
293
276
  const firstWorker = this.#workers.get(`${id}:0`)
@@ -309,7 +292,7 @@ class Runtime extends EventEmitter {
309
292
  }
310
293
  }
311
294
 
312
- async stopService (id, silent = false) {
295
+ async stopService (id, silent) {
313
296
  const config = this.#configManager.current
314
297
  const serviceConfig = config.services.find(s => s.id === id)
315
298
 
@@ -746,6 +729,21 @@ class Runtime extends EventEmitter {
746
729
  return createReadStream(filePath)
747
730
  }
748
731
 
732
+ async sendCommandToService (id, name, message) {
733
+ const service = await this.#getServiceById(id)
734
+
735
+ try {
736
+ return await sendViaITC(service, name, message)
737
+ } catch (e) {
738
+ // The service exports no meta, return an empty object
739
+ if (e.code === 'PLT_ITC_HANDLER_NOT_FOUND') {
740
+ return {}
741
+ }
742
+
743
+ throw e
744
+ }
745
+ }
746
+
749
747
  #updateStatus (status) {
750
748
  this.#status = status
751
749
  this.emit(status)
package/lib/schema.js CHANGED
@@ -27,8 +27,6 @@ const services = {
27
27
  },
28
28
  path: {
29
29
  type: 'string',
30
- // This is required for the resolve command to allow empty paths after environment variable replacement
31
- allowEmptyPaths: true,
32
30
  resolvePath: true
33
31
  },
34
32
  config: {
@@ -286,10 +284,6 @@ const platformaticRuntimeSchema = {
286
284
  { type: 'string' }
287
285
  ],
288
286
  default: 300000 // 5 minutes
289
- },
290
- resolvedServicesBasePath: {
291
- type: 'string',
292
- default: 'external'
293
287
  }
294
288
  },
295
289
  anyOf: [{ required: ['autoload'] }, { required: ['services'] }, { required: ['web'] }],
package/lib/start.js CHANGED
@@ -146,7 +146,7 @@ async function startCommand (args, throwAllErrors = false, returnRuntime = false
146
146
 
147
147
  return returnRuntime ? runtime : res
148
148
  } catch (err) {
149
- if (throwAllErrors && err.code !== 'PLT_RUNTIME_RUNTIME_ABORT') {
149
+ if (throwAllErrors) {
150
150
  throw err
151
151
  }
152
152
 
@@ -187,9 +187,7 @@ async function startCommand (args, throwAllErrors = false, returnRuntime = false
187
187
  process.exit(1)
188
188
  }
189
189
 
190
- if (err.code !== 'PLT_RUNTIME_RUNTIME_ABORT') {
191
- console.error(err)
192
- }
190
+ console.error(err)
193
191
 
194
192
  process.exit(1)
195
193
  }
@@ -13,6 +13,7 @@ const defaultStackable = {
13
13
  getEnv: () => null,
14
14
  getInfo: () => null,
15
15
  getDispatchFunc: () => null,
16
+ getDispatchTarget: () => null,
16
17
  getOpenapiSchema: () => null,
17
18
  getGraphqlSchema: () => null,
18
19
  getMeta: () => ({}),
package/lib/worker/itc.js CHANGED
@@ -72,12 +72,8 @@ function setupITC (app, service, dispatcher) {
72
72
  await app.listen()
73
73
  }
74
74
 
75
- const url = app.stackable.getUrl()
76
-
77
- const dispatchFunc = await app.stackable.getDispatchFunc()
78
- dispatcher.replaceServer(url ?? dispatchFunc)
79
-
80
- return service.entrypoint ? url : null
75
+ dispatcher.replaceServer(await app.stackable.getDispatchTarget())
76
+ return service.entrypoint ? app.stackable.getUrl() : null
81
77
  },
82
78
 
83
79
  async stop () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/runtime",
3
- "version": "2.16.0-alpha.1",
3
+ "version": "2.16.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -35,12 +35,12 @@
35
35
  "typescript": "^5.5.4",
36
36
  "undici-oidc-interceptor": "^0.5.0",
37
37
  "why-is-node-running": "^2.2.2",
38
- "@platformatic/composer": "2.16.0-alpha.1",
39
- "@platformatic/db": "2.16.0-alpha.1",
40
- "@platformatic/node": "2.16.0-alpha.1",
41
- "@platformatic/sql-graphql": "2.16.0-alpha.1",
42
- "@platformatic/sql-mapper": "2.16.0-alpha.1",
43
- "@platformatic/service": "2.16.0-alpha.1"
38
+ "@platformatic/composer": "2.16.0",
39
+ "@platformatic/db": "2.16.0",
40
+ "@platformatic/node": "2.16.0",
41
+ "@platformatic/sql-graphql": "2.16.0",
42
+ "@platformatic/sql-mapper": "2.16.0",
43
+ "@platformatic/service": "2.16.0"
44
44
  },
45
45
  "dependencies": {
46
46
  "@fastify/error": "^4.0.0",
@@ -70,13 +70,13 @@
70
70
  "undici": "^6.9.0",
71
71
  "undici-thread-interceptor": "^0.9.0",
72
72
  "ws": "^8.16.0",
73
- "@platformatic/config": "2.16.0-alpha.1",
74
- "@platformatic/basic": "2.16.0-alpha.1",
75
- "@platformatic/generators": "2.16.0-alpha.1",
76
- "@platformatic/itc": "2.16.0-alpha.1",
77
- "@platformatic/ts-compiler": "2.16.0-alpha.1",
78
- "@platformatic/telemetry": "2.16.0-alpha.1",
79
- "@platformatic/utils": "2.16.0-alpha.1"
73
+ "@platformatic/config": "2.16.0",
74
+ "@platformatic/basic": "2.16.0",
75
+ "@platformatic/generators": "2.16.0",
76
+ "@platformatic/ts-compiler": "2.16.0",
77
+ "@platformatic/itc": "2.16.0",
78
+ "@platformatic/telemetry": "2.16.0",
79
+ "@platformatic/utils": "2.16.0"
80
80
  },
81
81
  "scripts": {
82
82
  "test": "npm run lint && borp --concurrency=1 --timeout=300000 && tsd",
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/runtime/2.16.0-alpha.1.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/runtime/2.16.0.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "type": "object",
5
5
  "properties": {
@@ -183,7 +183,6 @@
183
183
  },
184
184
  "path": {
185
185
  "type": "string",
186
- "allowEmptyPaths": true,
187
186
  "resolvePath": true
188
187
  },
189
188
  "config": {
@@ -336,7 +335,6 @@
336
335
  },
337
336
  "path": {
338
337
  "type": "string",
339
- "allowEmptyPaths": true,
340
338
  "resolvePath": true
341
339
  },
342
340
  "config": {
@@ -1080,10 +1078,6 @@
1080
1078
  }
1081
1079
  ],
1082
1080
  "default": 300000
1083
- },
1084
- "resolvedServicesBasePath": {
1085
- "type": "string",
1086
- "default": "external"
1087
1081
  }
1088
1082
  },
1089
1083
  "anyOf": [