@platformatic/control 3.4.1 → 3.5.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @platformatic/control
2
2
 
3
- Check out the full documentation for Platformatic Runtime on [our website](https://docs.platformatic.dev/docs/guides/runtime-cli-managing).
3
+ Check out the full documentation for Platformatic on [our website](https://docs.platformatic.dev).
4
4
 
5
5
  ## Install
6
6
 
package/eslint.config.js CHANGED
@@ -1,3 +1,3 @@
1
- 'use strict'
1
+ import neostandard from 'neostandard'
2
2
 
3
- module.exports = require('neostandard')({})
3
+ export default neostandard()
@@ -0,0 +1,21 @@
1
+ import { FastifyError } from '@fastify/error'
2
+
3
+ export declare const ERROR_PREFIX: string
4
+
5
+ export declare const RuntimeNotFound: (value: string) => FastifyError
6
+ export declare const ApplicationNotFound: (value: string) => FastifyError
7
+ export declare const MissingRequestURL: (value: string) => FastifyError
8
+ export declare const FailedToGetRuntimeMetadata: (value: string) => FastifyError
9
+ export declare const FailedToGetRuntimeApplications: (value: string) => FastifyError
10
+ export declare const FailedToGetRuntimeEnv: (value: string) => FastifyError
11
+ export declare const FailedToGetRuntimeOpenapi: (value: string) => FastifyError
12
+ export declare const FailedToStreamRuntimeLogs: (value: string) => FastifyError
13
+ export declare const FailedToStopRuntime: (value: string) => FastifyError
14
+ export declare const FailedToReloadRuntime: (value: string) => FastifyError
15
+ export declare const FailedToGetRuntimeConfig: (value: string) => FastifyError
16
+ export declare const FailedToGetRuntimeApplicationEnv: (value: string) => FastifyError
17
+ export declare const FailedToGetRuntimeApplicationConfig: (value: string) => FastifyError
18
+ export declare const FailedToGetRuntimeHistoryLogs: (value: string) => FastifyError
19
+ export declare const FailedToGetRuntimeAllLogs: (value: string) => FastifyError
20
+ export declare const FailedToGetRuntimeLogIndexes: (value: string) => FastifyError
21
+ export declare const FailedToGetRuntimeMetrics: (value: string) => FastifyError
package/lib/errors.js CHANGED
@@ -1,26 +1,99 @@
1
- 'use strict'
2
-
3
- const createError = require('@fastify/error')
4
-
5
- const ERROR_PREFIX = 'PLT_CTR'
6
-
7
- module.exports = {
8
- RuntimeNotFound: createError(`${ERROR_PREFIX}_RUNTIME_NOT_FOUND`, 'Runtime not found.'),
9
- ServiceNotFound: createError(`${ERROR_PREFIX}_SERVICE_NOT_FOUND`, 'Service not found.'),
10
- MissingRuntimeIdentifier: createError(`${ERROR_PREFIX}_MISSING_RUNTIME_IDENTIFIER`, 'Runtime name or PID is required.'),
11
- MissingRequestURL: createError(`${ERROR_PREFIX}_MISSING_REQUEST_URL`, 'Request URL is required.'),
12
- FailedToGetRuntimeMetadata: createError(`${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_METADATA`, 'Failed to get runtime metadata %s.'),
13
- FailedToGetRuntimeServices: createError(`${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_SERVICES`, 'Failed to get runtime services %s.'),
14
- FailedToGetRuntimeEnv: createError(`${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_ENV`, 'Failed to get runtime environment variables %s.'),
15
- FailedToInjectRuntime: createError(`${ERROR_PREFIX}_FAILED_TO_INJECT_RUNTIME`, 'Failed to inject runtime %s.'),
16
- FailedToStreamRuntimeLogs: createError(`${ERROR_PREFIX}_FAILED_TO_STREAM_RUNTIME_LOGS`, 'Failed to stream runtime logs %s.'),
17
- FailedToRestartRuntime: createError(`${ERROR_PREFIX}_FAILED_TO_RESTART_RUNTIME`, 'Failed to restart runtime %s.'),
18
- FailedToStopRuntime: createError(`${ERROR_PREFIX}_FAILED_TO_STOP_RUNTIME`, 'Failed to stop the runtime %s.'),
19
- FailedToReloadRuntime: createError(`${ERROR_PREFIX}_FAILED_TO_RELOAD_RUNTIME`, 'Failed to reload the runtime %s.'),
20
- FailedToGetRuntimeConfig: createError(`${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_CONFIG`, 'Failed to get runtime config %s.'),
21
- FailedToGetRuntimeServiceEnv: createError(`${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_SERVICE_ENV`, 'Failed to get runtime service environment variables %s.'),
22
- FailedToGetRuntimeServiceConfig: createError(`${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_SERVICE_CONFIG`, 'Failed to get runtime service config %s.'),
23
- FailedToGetRuntimeHistoryLogs: createError(`${ERROR_PREFIX}_FAILED_TO_GET_HISTORY_LOGS`, 'Failed to get history logs %s.'),
24
- FailedToGetRuntimeAllLogs: createError(`${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_ALL_LOGS`, 'Failed to get runtime all logs %s.'),
25
- FailedToGetRuntimeLogIndexes: createError(`${ERROR_PREFIX}_FAILED_TO_GET_HISTORY_LOGS_COUNT`, 'Failed to get history logs count %s.'),
26
- }
1
+ import createError from '@fastify/error'
2
+
3
+ export const ERROR_PREFIX = 'PLT_CTR'
4
+
5
+ export const RuntimeNotFound = createError(`${ERROR_PREFIX}_RUNTIME_NOT_FOUND`, 'Runtime not found.')
6
+
7
+ export const ApplicationNotFound = createError(`${ERROR_PREFIX}_APPLICATION_NOT_FOUND`, 'Application not found.')
8
+
9
+ export const MissingRequestURL = createError(`${ERROR_PREFIX}_MISSING_REQUEST_URL`, 'Request URL is required.')
10
+
11
+ export const FailedToGetRuntimeMetadata = createError(
12
+ `${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_METADATA`,
13
+ 'Failed to get runtime metadata %s.'
14
+ )
15
+
16
+ export const FailedToGetRuntimeApplications = createError(
17
+ `${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_APPLICATIONS`,
18
+ 'Failed to get runtime applications %s.'
19
+ )
20
+
21
+ export const FailedToGetRuntimeEnv = createError(
22
+ `${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_ENV`,
23
+ 'Failed to get runtime environment variables %s.'
24
+ )
25
+
26
+ export const FailedToGetRuntimeOpenapi = createError(
27
+ `${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_OPENAPI`,
28
+ 'Failed to get runtime OpenAPI schema %s.'
29
+ )
30
+
31
+ export const FailedToStreamRuntimeLogs = createError(
32
+ `${ERROR_PREFIX}_FAILED_TO_STREAM_RUNTIME_LOGS`,
33
+ 'Failed to stream runtime logs %s.'
34
+ )
35
+
36
+ export const FailedToStopRuntime = createError(
37
+ `${ERROR_PREFIX}_FAILED_TO_STOP_RUNTIME`,
38
+ 'Failed to stop the runtime %s.'
39
+ )
40
+
41
+ export const FailedToReloadRuntime = createError(
42
+ `${ERROR_PREFIX}_FAILED_TO_RELOAD_RUNTIME`,
43
+ 'Failed to reload the runtime %s.'
44
+ )
45
+
46
+ export const FailedToGetRuntimeConfig = createError(
47
+ `${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_CONFIG`,
48
+ 'Failed to get runtime config %s.'
49
+ )
50
+
51
+ export const FailedToGetRuntimeApplicationEnv = createError(
52
+ `${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_APPLICATION_ENV`,
53
+ 'Failed to get runtime application environment variables %s.'
54
+ )
55
+
56
+ export const FailedToGetRuntimeApplicationConfig = createError(
57
+ `${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_APPLICATION_CONFIG`,
58
+ 'Failed to get runtime application config %s.'
59
+ )
60
+
61
+ export const FailedToGetRuntimeHistoryLogs = createError(
62
+ `${ERROR_PREFIX}_FAILED_TO_GET_HISTORY_LOGS`,
63
+ 'Failed to get history logs %s.'
64
+ )
65
+
66
+ export const FailedToGetRuntimeAllLogs = createError(
67
+ `${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_ALL_LOGS`,
68
+ 'Failed to get runtime all logs %s.'
69
+ )
70
+
71
+ export const FailedToGetRuntimeLogIndexes = createError(
72
+ `${ERROR_PREFIX}_FAILED_TO_GET_HISTORY_LOGS_COUNT`,
73
+ 'Failed to get history logs count %s.'
74
+ )
75
+
76
+ export const FailedToGetRuntimeMetrics = createError(
77
+ `${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_METRICS`,
78
+ 'Failed to get runtime metrics %s.'
79
+ )
80
+
81
+ export const ProfilingAlreadyStarted = createError(
82
+ `${ERROR_PREFIX}_PROFILING_ALREADY_STARTED`,
83
+ 'Profiling is already started for service "%s".'
84
+ )
85
+
86
+ export const ProfilingNotStarted = createError(
87
+ `${ERROR_PREFIX}_PROFILING_NOT_STARTED`,
88
+ 'Profiling not started for service "%s".'
89
+ )
90
+
91
+ export const FailedToStartProfiling = createError(
92
+ `${ERROR_PREFIX}_FAILED_TO_START_PROFILING`,
93
+ 'Failed to start profiling for service "%s": %s'
94
+ )
95
+
96
+ export const FailedToStopProfiling = createError(
97
+ `${ERROR_PREFIX}_FAILED_TO_STOP_PROFILING`,
98
+ 'Failed to stop profiling for service "%s": %s'
99
+ )
package/lib/index.d.ts ADDED
@@ -0,0 +1,130 @@
1
+ import { ChildProcess } from 'node:child_process'
2
+ import { Readable } from 'node:stream'
3
+ import { Dispatcher } from 'undici'
4
+ import WebSocket from 'ws'
5
+
6
+ export * from './errors.js'
7
+
8
+ export type ReadableBody = Dispatcher.ResponseData['body']
9
+
10
+ export class WebSocketStream extends Readable {
11
+ constructor (url: string)
12
+ ws: WebSocket
13
+ }
14
+
15
+ export interface RuntimeDependency {
16
+ id: string
17
+ url: string
18
+ local: boolean
19
+ }
20
+
21
+ export interface RuntimeApplicationBase {
22
+ id: string
23
+ status: string
24
+ }
25
+
26
+ export interface RuntimeApplication {
27
+ id: string
28
+ type: string
29
+ status: string
30
+ version: string
31
+ localUrl: string
32
+ entrypoint: boolean
33
+ url?: string
34
+ workers?: number
35
+ dependencies: Runtime
36
+ }
37
+
38
+ export interface Runtime {
39
+ pid: number
40
+ cwd: string
41
+ argv: string[]
42
+ uptimeSeconds: number
43
+ execPath: string
44
+ nodeVersion: string
45
+ projectDir: string
46
+ packageName: string | null
47
+ packageVersion: string | null
48
+ url: string | null
49
+ platformaticVersion: string
50
+ startTime?: number
51
+ }
52
+
53
+ export interface RuntimeApplications {
54
+ entrypoint: string
55
+ production: boolean
56
+ applications: (RuntimeApplication | RuntimeApplicationBase)[]
57
+ }
58
+
59
+ export interface MetricValue {
60
+ value: number
61
+ labels: {
62
+ route?: string
63
+ quantile?: number
64
+ method?: string
65
+ status_code?: number
66
+ telemetry_id?: string
67
+ type?: string
68
+ space?: string
69
+ version?: string
70
+ major?: number
71
+ minor?: number
72
+ patch?: number
73
+ le?: number | string
74
+ kind?: string
75
+ applicationId: string
76
+ workerId?: number
77
+ dispatcher_stats_url?: string
78
+ }
79
+ metricName?: string
80
+ exemplar?: unknown
81
+ }
82
+
83
+ export interface Metric {
84
+ help: string
85
+ name: string
86
+ type: string
87
+ values: MetricValue[]
88
+ aggregator: string
89
+ }
90
+
91
+ export interface LogIndexes {
92
+ pid: number
93
+ indexes: number[]
94
+ }
95
+
96
+ export class RuntimeApiClient {
97
+ getMatchingRuntime (options?: { pid?: string; name?: string }): Promise<Runtime>
98
+ getRuntimes (): Promise<Runtime[]>
99
+ getRuntimeMetadata (pid: number): Promise<Runtime>
100
+ getRuntimeApplications (pid: number): Promise<RuntimeApplications>
101
+ getRuntimeConfig (pid: number): Promise<Record<string, unknown> & { path?: string, configFile?: string, configPath?: string, server?: { path?: string } }>
102
+ getRuntimeApplicationConfig (pid: number, applicationId?: string): Promise<Record<string, unknown>>
103
+ getRuntimeEnv (pid: number): Promise<Record<string, string>>
104
+ getRuntimeOpenapi (pid: number, applicationId: string): Promise<Record<string, unknown>>
105
+ getRuntimeApplicationEnv (pid: number, applicationId: string): Promise<Record<string, string>>
106
+ reloadRuntime (pid: number, options?: object): Promise<ChildProcess>
107
+ restartRuntime (pid: number): Promise<void>
108
+ stopRuntime (pid: number): Promise<void>
109
+ getRuntimeMetrics<T extends { format?: 'text' | 'json' }> (
110
+ pid: number,
111
+ options?: T
112
+ ): Promise<T extends { format: 'text' } ? string : Metric[]>
113
+ getRuntimeLiveMetricsStream (pid: number): WebSocketStream
114
+ getRuntimeLiveLogsStream (pid: number, startLogIndex?: number): WebSocketStream
115
+ getRuntimeLogsStream (pid: number, logsId: string, options?: { runtimePID?: number }): Promise<ReadableBody>
116
+ getRuntimeAllLogsStream (pid: number, options?: { runtimePID?: number }): Promise<ReadableBody>
117
+ getRuntimeLogIndexes (pid: number, options?: { all?: boolean }): Promise<LogIndexes[]>
118
+ injectRuntime (
119
+ pid: number,
120
+ applicationId: string,
121
+ options: {
122
+ url: string
123
+ method: string
124
+ headers?: Record<string, string>
125
+ query?: Record<string, any>
126
+ body?: any
127
+ }
128
+ ): Promise<Dispatcher.ResponseData>
129
+ close (): Promise<void>
130
+ }