@platformatic/gateway 3.0.0-alpha.6 → 3.0.0-alpha.8

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/capability.js CHANGED
@@ -8,7 +8,6 @@ const kITC = Symbol.for('plt.runtime.itc')
8
8
 
9
9
  export class GatewayCapability extends ServiceCapability {
10
10
  #meta
11
- #dependencies
12
11
 
13
12
  constructor (root, config, context) {
14
13
  super(root, config, context)
@@ -21,24 +20,19 @@ export class GatewayCapability extends ServiceCapability {
21
20
  this.fastifyOptions.routerOptions.constraints = { notHost: notHostConstraints }
22
21
  }
23
22
 
24
- async getBootstrapDependencies () {
25
- await ensureApplications(this.applicationId, this.config)
23
+ async init () {
24
+ if (this.status) {
25
+ return
26
+ }
26
27
 
28
+ await ensureApplications(this.applicationId, this.config)
27
29
  const composedApplications = this.config.gateway?.applications
28
- const dependencies = []
29
-
30
- if (Array.isArray(composedApplications)) {
31
- dependencies.push(
32
- ...(await Promise.all(
33
- composedApplications.map(async application => {
34
- return this.#parseDependency(application.id, application.origin)
35
- })
36
- ))
37
- )
38
- }
30
+ .filter(this.#isLocalApplication.bind(this))
31
+ .map(a => a.id)
32
+
33
+ this.dependencies = Array.from(new Set([...this.dependencies, ...composedApplications]))
39
34
 
40
- this.#dependencies = dependencies
41
- return this.#dependencies
35
+ await super.init()
42
36
  }
43
37
 
44
38
  registerMeta (meta) {
@@ -57,12 +51,18 @@ export class GatewayCapability extends ServiceCapability {
57
51
 
58
52
  async isHealthy () {
59
53
  // If no dependencies (still booting), assume healthy
60
- if (this.#dependencies) {
61
- const composedApplications = this.#dependencies.map(dep => dep.id)
54
+ if (this.dependencies) {
62
55
  const workers = await globalThis[kITC].send('getWorkers')
63
56
 
57
+ const started = new Set()
64
58
  for (const worker of Object.values(workers)) {
65
- if (composedApplications.includes(worker.application) && !worker.status.startsWith('start')) {
59
+ if (worker.status === 'started') {
60
+ started.add(worker.application)
61
+ }
62
+ }
63
+
64
+ for (const dependency of this.dependencies) {
65
+ if (!started.has(dependency)) {
66
66
  globalThis[kITC].notify('event', { event: 'unhealthy' })
67
67
  return false
68
68
  }
@@ -73,17 +73,11 @@ export class GatewayCapability extends ServiceCapability {
73
73
  return true
74
74
  }
75
75
 
76
- async #parseDependency (id, urlString) {
77
- let url = `http://${id}.plt.local`
78
-
79
- if (urlString) {
80
- const remoteUrl = await replaceEnv(urlString, this.config[kMetadata].env)
81
-
82
- if (remoteUrl) {
83
- url = remoteUrl
84
- }
76
+ #isLocalApplication (application) {
77
+ if (!application.origin) {
78
+ return true
85
79
  }
86
80
 
87
- return { id, url, local: url.endsWith('.plt.local') }
81
+ return replaceEnv(application.origin, this.config[kMetadata].env).endsWith('.plt.local')
88
82
  }
89
83
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/gateway",
3
- "version": "3.0.0-alpha.6",
3
+ "version": "3.0.0-alpha.8",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -32,8 +32,7 @@
32
32
  "typescript": "^5.5.4",
33
33
  "why-is-node-running": "2",
34
34
  "ws": "^8.16.0",
35
- "@platformatic/client": "3.0.0-alpha.6",
36
- "@platformatic/db": "3.0.0-alpha.6"
35
+ "@platformatic/db": "3.0.0-alpha.8"
37
36
  },
38
37
  "dependencies": {
39
38
  "@fastify/error": "^4.0.0",
@@ -64,11 +63,11 @@
64
63
  "rfdc": "^1.3.1",
65
64
  "semgrator": "^0.3.0",
66
65
  "undici": "^7.0.0",
67
- "@platformatic/basic": "3.0.0-alpha.6",
68
- "@platformatic/scalar-theme": "3.0.0-alpha.6",
69
- "@platformatic/service": "3.0.0-alpha.6",
70
- "@platformatic/foundation": "^3.0.0-alpha.6",
71
- "@platformatic/telemetry": "3.0.0-alpha.6"
66
+ "@platformatic/basic": "3.0.0-alpha.8",
67
+ "@platformatic/foundation": "^3.0.0-alpha.8",
68
+ "@platformatic/scalar-theme": "3.0.0-alpha.8",
69
+ "@platformatic/service": "3.0.0-alpha.8",
70
+ "@platformatic/telemetry": "3.0.0-alpha.8"
72
71
  },
73
72
  "engines": {
74
73
  "node": ">=22.18.0"
@@ -77,7 +76,7 @@
77
76
  "test": "node --test --test-reporter=cleaner-spec-reporter --test-concurrency=1 --test-timeout=2000000 test/*.test.js test/**/*.test.js",
78
77
  "gen-schema": "node lib/schema.js > schema.json",
79
78
  "gen-types": "json2ts > config.d.ts < schema.json",
80
- "build": "pnpm run gen-schema && pnpm run gen-types",
79
+ "build": "npm run gen-schema && npm run gen-types",
81
80
  "lint": "eslint"
82
81
  }
83
82
  }
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/gateway/3.0.0-alpha.6.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/gateway/3.0.0-alpha.8.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Gateway Config",
5
5
  "type": "object",
@@ -1412,6 +1412,13 @@
1412
1412
  },
1413
1413
  "additionalProperties": false
1414
1414
  },
1415
+ "dependencies": {
1416
+ "type": "array",
1417
+ "items": {
1418
+ "type": "string"
1419
+ },
1420
+ "default": []
1421
+ },
1415
1422
  "arguments": {
1416
1423
  "type": "array",
1417
1424
  "items": {