@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 +1 -1
- package/eslint.config.js +2 -2
- package/lib/errors.d.ts +21 -0
- package/lib/errors.js +99 -26
- package/lib/index.d.ts +130 -0
- package/lib/{runtime-api-client.js → index.js} +247 -71
- package/package.json +20 -20
- package/control.js +0 -83
- package/help/config.txt +0 -16
- package/help/env.txt +0 -16
- package/help/help.txt +0 -11
- package/help/inject.txt +0 -30
- package/help/logs.txt +0 -21
- package/help/ps.txt +0 -10
- package/help/reload.txt +0 -19
- package/help/restart.txt +0 -16
- package/help/services.txt +0 -16
- package/help/stop.txt +0 -16
- package/index.js +0 -7
- package/lib/config.js +0 -29
- package/lib/env.js +0 -29
- package/lib/inject.js +0 -102
- package/lib/logs.js +0 -67
- package/lib/ps.js +0 -96
- package/lib/reload.js +0 -25
- package/lib/restart.js +0 -32
- package/lib/services.js +0 -73
- package/lib/stop.js +0 -25
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @platformatic/control
|
|
2
2
|
|
|
3
|
-
Check out the full documentation for Platformatic
|
|
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
|
-
|
|
1
|
+
import neostandard from 'neostandard'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export default neostandard()
|
package/lib/errors.d.ts
ADDED
|
@@ -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
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
+
}
|