@platformatic/control 3.0.0-alpha.1 → 3.0.0-alpha.3
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 +79 -25
- package/lib/index.d.ts +129 -0
- package/lib/{runtime-api-client.js → index.js} +113 -64
- package/package.json +12 -11
- package/control.js +0 -85
- 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/metrics.txt +0 -14
- 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.d.ts +0 -151
- package/index.js +0 -9
- package/index.test-d.ts +0 -63
- 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/metrics.js +0 -25
- package/lib/ps.js +0 -96
- package/lib/reload.js +0 -25
- package/lib/restart.js +0 -32
- package/lib/services.js +0 -79
- 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 ServiceNotFound: (value: string) => FastifyError
|
|
7
|
+
export declare const MissingRequestURL: (value: string) => FastifyError
|
|
8
|
+
export declare const FailedToGetRuntimeMetadata: (value: string) => FastifyError
|
|
9
|
+
export declare const FailedToGetRuntimeServices: (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 FailedToGetRuntimeServiceEnv: (value: string) => FastifyError
|
|
17
|
+
export declare const FailedToGetRuntimeServiceConfig: (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,25 +1,79 @@
|
|
|
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
|
-
|
|
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 ServiceNotFound = createError(`${ERROR_PREFIX}_SERVICE_NOT_FOUND`, 'Service 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 FailedToGetRuntimeServices = createError(
|
|
17
|
+
`${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_SERVICES`,
|
|
18
|
+
'Failed to get runtime services %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 FailedToGetRuntimeServiceEnv = createError(
|
|
52
|
+
`${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_SERVICE_ENV`,
|
|
53
|
+
'Failed to get runtime service environment variables %s.'
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
export const FailedToGetRuntimeServiceConfig = createError(
|
|
57
|
+
`${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_SERVICE_CONFIG`,
|
|
58
|
+
'Failed to get runtime service 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
|
+
)
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
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 RuntimeServiceBase {
|
|
22
|
+
id: string
|
|
23
|
+
status: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface RuntimeService {
|
|
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
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface RuntimeServices {
|
|
53
|
+
entrypoint: string
|
|
54
|
+
production: boolean
|
|
55
|
+
services: (RuntimeService | RuntimeServiceBase)[]
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface MetricValue {
|
|
59
|
+
value: number
|
|
60
|
+
labels: {
|
|
61
|
+
route?: string
|
|
62
|
+
quantile?: number
|
|
63
|
+
method?: string
|
|
64
|
+
status_code?: number
|
|
65
|
+
telemetry_id?: string
|
|
66
|
+
type?: string
|
|
67
|
+
space?: string
|
|
68
|
+
version?: string
|
|
69
|
+
major?: number
|
|
70
|
+
minor?: number
|
|
71
|
+
patch?: number
|
|
72
|
+
le?: number | string
|
|
73
|
+
kind?: string
|
|
74
|
+
serviceId: string
|
|
75
|
+
workerId?: number
|
|
76
|
+
dispatcher_stats_url?: string
|
|
77
|
+
}
|
|
78
|
+
metricName?: string
|
|
79
|
+
exemplar?: unknown
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface Metric {
|
|
83
|
+
help: string
|
|
84
|
+
name: string
|
|
85
|
+
type: string
|
|
86
|
+
values: MetricValue[]
|
|
87
|
+
aggregator: string
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface LogIndexes {
|
|
91
|
+
pid: number
|
|
92
|
+
indexes: number[]
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export class RuntimeApiClient {
|
|
96
|
+
getMatchingRuntime (options?: { pid?: string; name?: string }): Promise<Runtime>
|
|
97
|
+
getRuntimes (): Promise<Runtime[]>
|
|
98
|
+
getRuntimeMetadata (pid: number): Promise<Runtime>
|
|
99
|
+
getRuntimeServices (pid: number): Promise<RuntimeServices>
|
|
100
|
+
getRuntimeConfig (pid: number): Promise<Record<string, unknown>>
|
|
101
|
+
getRuntimeServiceConfig (pid: number, serviceId?: string): Promise<Record<string, unknown>>
|
|
102
|
+
getRuntimeEnv (pid: number): Promise<Record<string, string>>
|
|
103
|
+
getRuntimeOpenapi (pid: number, serviceId: string): Promise<Record<string, unknown>>
|
|
104
|
+
getRuntimeServiceEnv (pid: number, serviceId: string): Promise<Record<string, string>>
|
|
105
|
+
reloadRuntime (pid: number, options?: object): Promise<ChildProcess>
|
|
106
|
+
restartRuntime (pid: number): Promise<void>
|
|
107
|
+
stopRuntime (pid: number): Promise<void>
|
|
108
|
+
getRuntimeMetrics<T extends { format?: 'text' | 'json' }> (
|
|
109
|
+
pid: number,
|
|
110
|
+
options?: T
|
|
111
|
+
): Promise<T extends { format: 'text' } ? string : Metric[]>
|
|
112
|
+
getRuntimeLiveMetricsStream (pid: number): WebSocketStream
|
|
113
|
+
getRuntimeLiveLogsStream (pid: number, startLogIndex?: number): WebSocketStream
|
|
114
|
+
getRuntimeLogsStream (pid: number, logsId: string, options?: { runtimePID?: number }): Promise<ReadableBody>
|
|
115
|
+
getRuntimeAllLogsStream (pid: number, options?: { runtimePID?: number }): Promise<ReadableBody>
|
|
116
|
+
getRuntimeLogIndexes (pid: number, options?: { all?: boolean }): Promise<LogIndexes[]>
|
|
117
|
+
injectRuntime (
|
|
118
|
+
pid: number,
|
|
119
|
+
serviceId: string,
|
|
120
|
+
options: {
|
|
121
|
+
url: string
|
|
122
|
+
method: string
|
|
123
|
+
headers?: Record<string, string>
|
|
124
|
+
query?: Record<string, any>
|
|
125
|
+
body?: any
|
|
126
|
+
}
|
|
127
|
+
): Promise<Dispatcher.ResponseData>
|
|
128
|
+
close (): Promise<void>
|
|
129
|
+
}
|
|
@@ -1,19 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { safeRemove } from '@platformatic/foundation'
|
|
2
|
+
import { exec, spawn } from 'node:child_process'
|
|
3
|
+
import { access, readdir } from 'node:fs/promises'
|
|
4
|
+
import { EOL, platform, tmpdir } from 'node:os'
|
|
5
|
+
import { join } from 'node:path'
|
|
6
|
+
import { Readable } from 'node:stream'
|
|
7
|
+
import { Client } from 'undici'
|
|
8
|
+
import WebSocket from 'ws'
|
|
9
|
+
import {
|
|
10
|
+
FailedToGetRuntimeAllLogs,
|
|
11
|
+
FailedToGetRuntimeConfig,
|
|
12
|
+
FailedToGetRuntimeEnv,
|
|
13
|
+
FailedToGetRuntimeHistoryLogs,
|
|
14
|
+
FailedToGetRuntimeLogIndexes,
|
|
15
|
+
FailedToGetRuntimeMetadata,
|
|
16
|
+
FailedToGetRuntimeMetrics,
|
|
17
|
+
FailedToGetRuntimeOpenapi,
|
|
18
|
+
FailedToGetRuntimeServiceConfig,
|
|
19
|
+
FailedToGetRuntimeServiceEnv,
|
|
20
|
+
FailedToGetRuntimeServices,
|
|
21
|
+
FailedToReloadRuntime,
|
|
22
|
+
FailedToStopRuntime,
|
|
23
|
+
FailedToStreamRuntimeLogs,
|
|
24
|
+
RuntimeNotFound,
|
|
25
|
+
ServiceNotFound
|
|
26
|
+
} from './errors.js'
|
|
12
27
|
|
|
13
28
|
const PLATFORMATIC_TMP_DIR = join(tmpdir(), 'platformatic', 'runtimes')
|
|
14
29
|
const PLATFORMATIC_PIPE_PREFIX = '\\\\.\\pipe\\platformatic-'
|
|
15
30
|
|
|
16
|
-
class
|
|
31
|
+
class WebSocketStream extends Readable {
|
|
32
|
+
constructor (url) {
|
|
33
|
+
super()
|
|
34
|
+
this.ws = new WebSocket(url)
|
|
35
|
+
|
|
36
|
+
this.ws.on('message', data => {
|
|
37
|
+
this.push(data)
|
|
38
|
+
})
|
|
39
|
+
this.ws.on('close', () => {
|
|
40
|
+
this.push(null)
|
|
41
|
+
})
|
|
42
|
+
this.ws.on('error', err => {
|
|
43
|
+
this.emit('error', new FailedToStreamRuntimeLogs(err.message))
|
|
44
|
+
})
|
|
45
|
+
this.on('close', () => {
|
|
46
|
+
this.ws.close()
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
_read () {}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export * from './errors.js'
|
|
54
|
+
|
|
55
|
+
export async function getMatchingRuntime (client, positionals) {
|
|
56
|
+
const runtimes = await client.getRuntimes()
|
|
57
|
+
const pidOrName = positionals[0]
|
|
58
|
+
let runtime
|
|
59
|
+
|
|
60
|
+
// We have an argument to match
|
|
61
|
+
if (pidOrName) {
|
|
62
|
+
if (pidOrName.match(/^\d+$/)) {
|
|
63
|
+
const pid = parseInt(pidOrName)
|
|
64
|
+
runtime = runtimes.find(runtime => runtime.pid === pid)
|
|
65
|
+
} else {
|
|
66
|
+
runtime = runtimes.find(runtime => runtime.packageName === pidOrName)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (runtime) {
|
|
70
|
+
return [runtime, positionals.slice(1)]
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// We found no match, find any runtime whose running directory is the current one
|
|
75
|
+
if (!runtime) {
|
|
76
|
+
runtime = runtimes.find(runtime => runtime.cwd === process.cwd())
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (!runtime) {
|
|
80
|
+
throw RuntimeNotFound()
|
|
81
|
+
}
|
|
82
|
+
/* c8 ignore next 2 */
|
|
83
|
+
|
|
84
|
+
return [runtime, positionals]
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export class RuntimeApiClient {
|
|
17
88
|
#undiciClients = new Map()
|
|
18
89
|
#webSockets = new Set()
|
|
19
90
|
|
|
@@ -29,15 +100,13 @@ class RuntimeApiClient {
|
|
|
29
100
|
runtime = runtimes[0]
|
|
30
101
|
}
|
|
31
102
|
if (!runtime) {
|
|
32
|
-
throw
|
|
103
|
+
throw new RuntimeNotFound()
|
|
33
104
|
}
|
|
34
105
|
return runtime
|
|
35
106
|
}
|
|
36
107
|
|
|
37
108
|
async getRuntimes () {
|
|
38
|
-
const runtimePIDs = platform() === 'win32'
|
|
39
|
-
? await this.#getWindowsRuntimePIDs()
|
|
40
|
-
: await this.#getUnixRuntimePIDs()
|
|
109
|
+
const runtimePIDs = platform() === 'win32' ? await this.#getWindowsRuntimePIDs() : await this.#getUnixRuntimePIDs()
|
|
41
110
|
|
|
42
111
|
const getMetadataRequests = await Promise.allSettled(
|
|
43
112
|
runtimePIDs.map(async runtimePID => {
|
|
@@ -65,12 +134,12 @@ class RuntimeApiClient {
|
|
|
65
134
|
const { statusCode, body } = await client.request({
|
|
66
135
|
path: '/api/v1/metadata',
|
|
67
136
|
method: 'GET',
|
|
68
|
-
headersTimeout: 10 * 1000
|
|
137
|
+
headersTimeout: 10 * 1000
|
|
69
138
|
})
|
|
70
139
|
|
|
71
140
|
if (statusCode !== 200) {
|
|
72
141
|
const error = await body.text()
|
|
73
|
-
throw new
|
|
142
|
+
throw new FailedToGetRuntimeMetadata(error)
|
|
74
143
|
}
|
|
75
144
|
|
|
76
145
|
const metadata = await body.json()
|
|
@@ -87,7 +156,7 @@ class RuntimeApiClient {
|
|
|
87
156
|
|
|
88
157
|
if (statusCode !== 200) {
|
|
89
158
|
const error = await body.text()
|
|
90
|
-
throw new
|
|
159
|
+
throw new FailedToGetRuntimeServices(error)
|
|
91
160
|
}
|
|
92
161
|
|
|
93
162
|
const runtimeServices = await body.json()
|
|
@@ -104,7 +173,7 @@ class RuntimeApiClient {
|
|
|
104
173
|
|
|
105
174
|
if (statusCode !== 200) {
|
|
106
175
|
const error = await body.text()
|
|
107
|
-
throw new
|
|
176
|
+
throw new FailedToGetRuntimeConfig(error)
|
|
108
177
|
}
|
|
109
178
|
|
|
110
179
|
const runtimeConfig = await body.json()
|
|
@@ -128,11 +197,14 @@ class RuntimeApiClient {
|
|
|
128
197
|
// No-op
|
|
129
198
|
}
|
|
130
199
|
|
|
131
|
-
if (
|
|
132
|
-
|
|
200
|
+
if (
|
|
201
|
+
jsonError?.code === 'PLT_RUNTIME_SERVICE_NOT_FOUND' ||
|
|
202
|
+
jsonError?.code === 'PLT_RUNTIME_SERVICE_WORKER_NOT_FOUND'
|
|
203
|
+
) {
|
|
204
|
+
throw new ServiceNotFound(error)
|
|
133
205
|
}
|
|
134
206
|
|
|
135
|
-
throw new
|
|
207
|
+
throw new FailedToGetRuntimeServiceConfig(error)
|
|
136
208
|
}
|
|
137
209
|
|
|
138
210
|
const serviceConfig = await body.json()
|
|
@@ -149,7 +221,7 @@ class RuntimeApiClient {
|
|
|
149
221
|
|
|
150
222
|
if (statusCode !== 200) {
|
|
151
223
|
const error = await body.text()
|
|
152
|
-
throw new
|
|
224
|
+
throw new FailedToGetRuntimeEnv(error)
|
|
153
225
|
}
|
|
154
226
|
|
|
155
227
|
const runtimeEnv = await body.json()
|
|
@@ -166,7 +238,7 @@ class RuntimeApiClient {
|
|
|
166
238
|
|
|
167
239
|
if (statusCode !== 200) {
|
|
168
240
|
const error = await body.text()
|
|
169
|
-
throw new
|
|
241
|
+
throw new FailedToGetRuntimeOpenapi(error)
|
|
170
242
|
}
|
|
171
243
|
|
|
172
244
|
const openapi = await body.json()
|
|
@@ -190,11 +262,14 @@ class RuntimeApiClient {
|
|
|
190
262
|
// No-op
|
|
191
263
|
}
|
|
192
264
|
|
|
193
|
-
if (
|
|
194
|
-
|
|
265
|
+
if (
|
|
266
|
+
jsonError?.code === 'PLT_RUNTIME_SERVICE_NOT_FOUND' ||
|
|
267
|
+
jsonError?.code === 'PLT_RUNTIME_SERVICE_WORKER_NOT_FOUND'
|
|
268
|
+
) {
|
|
269
|
+
throw new ServiceNotFound(error)
|
|
195
270
|
}
|
|
196
271
|
|
|
197
|
-
throw new
|
|
272
|
+
throw new FailedToGetRuntimeServiceEnv(error)
|
|
198
273
|
}
|
|
199
274
|
|
|
200
275
|
const serviceConfig = await body.json()
|
|
@@ -228,7 +303,7 @@ class RuntimeApiClient {
|
|
|
228
303
|
|
|
229
304
|
if (statusCode !== 200) {
|
|
230
305
|
const error = await body.text()
|
|
231
|
-
throw new
|
|
306
|
+
throw new FailedToReloadRuntime(error)
|
|
232
307
|
}
|
|
233
308
|
}
|
|
234
309
|
|
|
@@ -242,7 +317,7 @@ class RuntimeApiClient {
|
|
|
242
317
|
|
|
243
318
|
if (statusCode !== 200) {
|
|
244
319
|
const error = await body.text()
|
|
245
|
-
throw new
|
|
320
|
+
throw new FailedToStopRuntime(error)
|
|
246
321
|
}
|
|
247
322
|
}
|
|
248
323
|
|
|
@@ -266,12 +341,10 @@ class RuntimeApiClient {
|
|
|
266
341
|
|
|
267
342
|
if (statusCode !== 200) {
|
|
268
343
|
const error = await body.text()
|
|
269
|
-
throw new
|
|
344
|
+
throw new FailedToGetRuntimeMetrics(error)
|
|
270
345
|
}
|
|
271
346
|
|
|
272
|
-
const metrics = format === 'json'
|
|
273
|
-
? await body.json()
|
|
274
|
-
: await body.text()
|
|
347
|
+
const metrics = format === 'json' ? await body.json() : await body.text()
|
|
275
348
|
|
|
276
349
|
return metrics
|
|
277
350
|
}
|
|
@@ -287,12 +360,12 @@ class RuntimeApiClient {
|
|
|
287
360
|
return webSocketStream
|
|
288
361
|
}
|
|
289
362
|
|
|
290
|
-
getRuntimeLiveLogsStream (pid
|
|
363
|
+
getRuntimeLiveLogsStream (pid) {
|
|
291
364
|
const socketPath = this.#getSocketPathFromPid(pid)
|
|
292
365
|
|
|
293
366
|
const protocol = platform() === 'win32' ? 'ws+unix:' : 'ws+unix://'
|
|
294
|
-
|
|
295
|
-
const webSocketUrl = protocol + socketPath + ':/api/v1/logs/live'
|
|
367
|
+
|
|
368
|
+
const webSocketUrl = protocol + socketPath + ':/api/v1/logs/live'
|
|
296
369
|
const webSocketStream = new WebSocketStream(webSocketUrl)
|
|
297
370
|
this.#webSockets.add(webSocketStream.ws)
|
|
298
371
|
|
|
@@ -311,7 +384,7 @@ class RuntimeApiClient {
|
|
|
311
384
|
|
|
312
385
|
if (statusCode !== 200) {
|
|
313
386
|
const error = await body.text()
|
|
314
|
-
throw new
|
|
387
|
+
throw new FailedToGetRuntimeHistoryLogs(error)
|
|
315
388
|
}
|
|
316
389
|
|
|
317
390
|
return body
|
|
@@ -329,7 +402,7 @@ class RuntimeApiClient {
|
|
|
329
402
|
|
|
330
403
|
if (statusCode !== 200) {
|
|
331
404
|
const error = await body.text()
|
|
332
|
-
throw new
|
|
405
|
+
throw new FailedToGetRuntimeAllLogs(error)
|
|
333
406
|
}
|
|
334
407
|
|
|
335
408
|
return body
|
|
@@ -347,7 +420,7 @@ class RuntimeApiClient {
|
|
|
347
420
|
|
|
348
421
|
if (statusCode !== 200) {
|
|
349
422
|
const error = await body.text()
|
|
350
|
-
throw new
|
|
423
|
+
throw new FailedToGetRuntimeLogIndexes(error)
|
|
351
424
|
}
|
|
352
425
|
|
|
353
426
|
const result = await body.json()
|
|
@@ -451,27 +524,3 @@ class RuntimeApiClient {
|
|
|
451
524
|
await safeRemove(runtimeDir)
|
|
452
525
|
}
|
|
453
526
|
}
|
|
454
|
-
|
|
455
|
-
class WebSocketStream extends Readable {
|
|
456
|
-
constructor (url) {
|
|
457
|
-
super()
|
|
458
|
-
this.ws = new WebSocket(url)
|
|
459
|
-
|
|
460
|
-
this.ws.on('message', data => {
|
|
461
|
-
this.push(data)
|
|
462
|
-
})
|
|
463
|
-
this.ws.on('close', () => {
|
|
464
|
-
this.push(null)
|
|
465
|
-
})
|
|
466
|
-
this.ws.on('error', err => {
|
|
467
|
-
this.emit('error', new errors.FailedToStreamRuntimeLogs(err.message))
|
|
468
|
-
})
|
|
469
|
-
this.on('close', () => {
|
|
470
|
-
this.ws.close()
|
|
471
|
-
})
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
_read () {}
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
module.exports = RuntimeApiClient
|
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/control",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.3",
|
|
4
4
|
"description": "Platformatic Control",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
},
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
9
8
|
"author": "Platformatic Inc. <oss@platformatic.dev> (https://platformatic.dev)",
|
|
10
9
|
"repository": {
|
|
11
10
|
"type": "git",
|
|
@@ -24,22 +23,24 @@
|
|
|
24
23
|
"split2": "^4.2.0",
|
|
25
24
|
"tsd": "^0.32.0",
|
|
26
25
|
"typescript": "^5.5.4",
|
|
27
|
-
"@platformatic/runtime": "3.0.0-alpha.
|
|
28
|
-
"@platformatic/service": "3.0.0-alpha.
|
|
26
|
+
"@platformatic/runtime": "3.0.0-alpha.3",
|
|
27
|
+
"@platformatic/service": "3.0.0-alpha.3"
|
|
29
28
|
},
|
|
30
29
|
"dependencies": {
|
|
31
30
|
"@fastify/error": "^4.0.0",
|
|
32
|
-
"commist": "^3.2.0",
|
|
33
31
|
"help-me": "^5.0.0",
|
|
34
|
-
"pino": "^9.
|
|
32
|
+
"pino": "^9.9.0",
|
|
35
33
|
"pino-pretty": "^13.0.0",
|
|
36
34
|
"table": "^6.8.1",
|
|
37
35
|
"undici": "^7.0.0",
|
|
38
36
|
"ws": "^8.16.0",
|
|
39
|
-
"@platformatic/
|
|
37
|
+
"@platformatic/foundation": "3.0.0-alpha.3"
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=22.18.0"
|
|
40
41
|
},
|
|
41
42
|
"scripts": {
|
|
42
|
-
"test": "pnpm run lint && pnpm run unit && tsd",
|
|
43
|
+
"test": "pnpm run lint && pnpm run unit && tsd --files test/index.test-d.ts",
|
|
43
44
|
"unit": "borp --concurrency=1 --timeout=1200000",
|
|
44
45
|
"lint": "eslint"
|
|
45
46
|
}
|