@platformatic/control 2.30.1 → 2.30.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/index.d.ts CHANGED
@@ -24,7 +24,7 @@ declare namespace control {
24
24
  platformaticVersion: string
25
25
  }
26
26
 
27
- interface Services {
27
+ interface RuntimeServices {
28
28
  entrypoint: string,
29
29
  production: boolean,
30
30
  services: ({
@@ -45,11 +45,34 @@ declare namespace control {
45
45
  })[]
46
46
  }
47
47
 
48
+ interface MetricValue {
49
+ value: number,
50
+ labels: {
51
+ type?: string,
52
+ space?: string,
53
+ version?: string,
54
+ major?: number,
55
+ minor?: number,
56
+ patch?: number,
57
+ le?: number | string,
58
+ kind?: string,
59
+ serviceId: string
60
+ }
61
+ }
62
+
63
+ interface Metric {
64
+ help: string,
65
+ name: string,
66
+ type: string,
67
+ values: MetricValue[],
68
+ aggregator: string
69
+ }
70
+
48
71
  export class RuntimeApiClient {
49
- getMatchingRuntime(opts: { pid?: string; name?: string }): Promise<Runtime>;
72
+ getMatchingRuntime(options?: { pid?: string; name?: string }): Promise<Runtime>;
50
73
  getRuntimes(): Promise<Runtime[]>;
51
74
  getRuntimeMetadata(pid: number): Promise<Runtime>;
52
- getRuntimeServices(pid: number): Promise<Services>;
75
+ getRuntimeServices(pid: number): Promise<RuntimeServices>;
53
76
  getRuntimeConfig(pid: number): Promise<void>;
54
77
  getRuntimeServiceConfig(pid: number, serviceId?: string): Promise<void>;
55
78
  getRuntimeEnv(pid: number): Promise<void>;
@@ -57,10 +80,10 @@ declare namespace control {
57
80
  reloadRuntime(pid: number, options?: object): Promise<ChildProcess>;
58
81
  restartRuntime(pid: number): Promise<void>;
59
82
  stopRuntime(pid: number): Promise<void>;
60
- getRuntimeMetrics(
83
+ getRuntimeMetrics<T extends { format?: "text" | "json" }>(
61
84
  pid: number,
62
- options?: { format?: "text" | "json" }
63
- ): Promise<unknown>;
85
+ options?: T
86
+ ): Promise<T extends { format: "text" } ? string : Metric[]>;
64
87
  getRuntimeLiveMetricsStream(pid: number): WebSocketStream;
65
88
  getRuntimeLiveLogsStream(
66
89
  pid: number,
package/index.test-d.ts CHANGED
@@ -1,11 +1,17 @@
1
1
  import { expectError, expectType } from 'tsd'
2
- import { errors, Runtime, RuntimeApiClient, Services } from '.'
2
+ import { errors, Metric, Runtime, RuntimeApiClient, RuntimeServices } from '.'
3
3
  import { FastifyError } from '@fastify/error'
4
4
 
5
5
  // RuntimeApiClient
6
6
  let runtime = {} as Runtime
7
- let services = {} as Services
7
+ let service = {} as RuntimeServices
8
+ let metric = {} as Metric
8
9
  const api = new RuntimeApiClient()
10
+ expectType<Promise<Runtime>>(api.getMatchingRuntime())
11
+ expectType<Promise<Metric[]>>(api.getRuntimeMetrics(runtime.pid))
12
+ expectType<Promise<Metric[]>>(api.getRuntimeMetrics(runtime.pid, {}))
13
+ expectType<Promise<Metric[]>>(api.getRuntimeMetrics(runtime.pid, { format: 'json' }))
14
+ expectType<Promise<string>>(api.getRuntimeMetrics(runtime.pid, { format: 'text' }))
9
15
  expectType<Promise<Runtime[]>>(api.getRuntimes())
10
16
  expectType<string[]>(runtime.argv)
11
17
  expectType<number>(runtime.uptimeSeconds)
@@ -13,10 +19,12 @@ expectType<string | null>(runtime.packageVersion)
13
19
  expectType<Promise<{
14
20
  entrypoint: string,
15
21
  production: boolean,
16
- services: Services['services']
22
+ services: RuntimeServices['services']
17
23
  }>>(api.getRuntimeServices(45))
18
- expectType<string>(services.services[0].id)
19
- expectType<string>(services.services[0].status)
24
+ expectType<string>(service.services[0].id)
25
+ expectType<string>(service.services[0].status)
26
+ expectType<string>(metric.aggregator)
27
+ expectType<string>(metric.values[0].labels.serviceId)
20
28
  expectType<Promise<void>>(api.close())
21
29
 
22
30
  // errors
@@ -17,7 +17,7 @@ class RuntimeApiClient {
17
17
  #undiciClients = new Map()
18
18
  #webSockets = new Set()
19
19
 
20
- async getMatchingRuntime (opts) {
20
+ async getMatchingRuntime (opts = {}) {
21
21
  const runtimes = await this.getRuntimes()
22
22
 
23
23
  let runtime = null
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/control",
3
- "version": "2.30.1",
3
+ "version": "2.30.2",
4
4
  "description": "Platformatic Control",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -25,8 +25,8 @@
25
25
  "split2": "^4.2.0",
26
26
  "tsd": "^0.31.0",
27
27
  "typescript": "^5.5.4",
28
- "@platformatic/runtime": "2.30.1",
29
- "@platformatic/service": "2.30.1"
28
+ "@platformatic/service": "2.30.2",
29
+ "@platformatic/runtime": "2.30.2"
30
30
  },
31
31
  "dependencies": {
32
32
  "@fastify/error": "^4.0.0",
@@ -37,7 +37,7 @@
37
37
  "table": "^6.8.1",
38
38
  "undici": "^7.0.0",
39
39
  "ws": "^8.16.0",
40
- "@platformatic/utils": "2.30.1"
40
+ "@platformatic/utils": "2.30.2"
41
41
  },
42
42
  "scripts": {
43
43
  "test": "pnpm run lint && pnpm run unit && tsd",