@platformatic/control 2.28.1-alpha.1 → 2.30.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/index.d.ts +80 -0
- package/index.test-d.ts +16 -0
- package/lib/errors.js +0 -3
- package/lib/metrics.js +1 -1
- package/package.json +5 -5
package/index.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { ChildProcess } from "node:child_process";
|
|
2
|
+
import BodyReadable from "undici/types/readable";
|
|
3
|
+
import { FastifyError } from "@fastify/error";
|
|
4
|
+
import { Readable } from "node:stream";
|
|
5
|
+
import WebSocket from "ws";
|
|
6
|
+
|
|
7
|
+
declare namespace control {
|
|
8
|
+
class WebSocketStream extends Readable {
|
|
9
|
+
constructor(url: string);
|
|
10
|
+
ws: WebSocket;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class RuntimeApiClient {
|
|
14
|
+
getMatchingRuntime(opts: { pid?: string; name?: string }): Promise<unknown>;
|
|
15
|
+
getRuntimes(): Promise<unknown[]>;
|
|
16
|
+
getRuntimeMetadata(pid: number): Promise<unknown>;
|
|
17
|
+
getRuntimeServices(pid: number): Promise<unknown>;
|
|
18
|
+
getRuntimeConfig(pid: number): Promise<void>;
|
|
19
|
+
getRuntimeServiceConfig(pid: number, serviceId?: string): Promise<void>;
|
|
20
|
+
getRuntimeEnv(pid: number): Promise<void>;
|
|
21
|
+
getRuntimeServiceEnv(pid: number, serviceId: string): Promise<unknown>;
|
|
22
|
+
reloadRuntime(pid: number, options?: object): Promise<ChildProcess>;
|
|
23
|
+
restartRuntime(pid: number): Promise<void>;
|
|
24
|
+
stopRuntime(pid: number): Promise<void>;
|
|
25
|
+
getRuntimeMetrics(
|
|
26
|
+
pid: number,
|
|
27
|
+
options?: { format?: "text" | "json" }
|
|
28
|
+
): Promise<unknown>;
|
|
29
|
+
getRuntimeLiveMetricsStream(pid: number): WebSocketStream;
|
|
30
|
+
getRuntimeLiveLogsStream(
|
|
31
|
+
pid: number,
|
|
32
|
+
startLogIndex?: number
|
|
33
|
+
): WebSocketStream;
|
|
34
|
+
getRuntimeLogsStream(
|
|
35
|
+
pid: number,
|
|
36
|
+
logsId: string,
|
|
37
|
+
options?: { runtimePID?: number }
|
|
38
|
+
): Promise<BodyReadable>;
|
|
39
|
+
getRuntimeAllLogsStream(
|
|
40
|
+
pid: number,
|
|
41
|
+
options?: { runtimePID?: number }
|
|
42
|
+
): Promise<BodyReadable>;
|
|
43
|
+
getRuntimeLogIndexes(
|
|
44
|
+
pid: number,
|
|
45
|
+
options?: { all?: boolean }
|
|
46
|
+
): Promise<unknown>;
|
|
47
|
+
injectRuntime(
|
|
48
|
+
pid: number,
|
|
49
|
+
serviceId: string,
|
|
50
|
+
options: {
|
|
51
|
+
url: string;
|
|
52
|
+
method: string;
|
|
53
|
+
headers: object;
|
|
54
|
+
body: unknown;
|
|
55
|
+
}
|
|
56
|
+
): Promise<unknown>;
|
|
57
|
+
close(): Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export module errors {
|
|
61
|
+
export const RuntimeNotFound: FastifyError;
|
|
62
|
+
export const ServiceNotFound: FastifyError;
|
|
63
|
+
export const MissingRequestURL: FastifyError;
|
|
64
|
+
export const FailedToGetRuntimeMetadata: FastifyError;
|
|
65
|
+
export const FailedToGetRuntimeServices: FastifyError;
|
|
66
|
+
export const FailedToGetRuntimeEnv: FastifyError;
|
|
67
|
+
export const FailedToStreamRuntimeLogs: FastifyError;
|
|
68
|
+
export const FailedToStopRuntime: FastifyError;
|
|
69
|
+
export const FailedToReloadRuntime: FastifyError;
|
|
70
|
+
export const FailedToGetRuntimeConfig: FastifyError;
|
|
71
|
+
export const FailedToGetRuntimeServiceEnv: FastifyError;
|
|
72
|
+
export const FailedToGetRuntimeServiceConfig: FastifyError;
|
|
73
|
+
export const FailedToGetRuntimeHistoryLogs: FastifyError;
|
|
74
|
+
export const FailedToGetRuntimeAllLogs: FastifyError;
|
|
75
|
+
export const FailedToGetRuntimeLogIndexes: FastifyError;
|
|
76
|
+
export const FailedToGetRuntimeMetrics: FastifyError;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export = control;
|
package/index.test-d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { expectError, expectType } from 'tsd'
|
|
2
|
+
import { errors, RuntimeApiClient } from '.'
|
|
3
|
+
import { FastifyError } from '@fastify/error'
|
|
4
|
+
|
|
5
|
+
// RuntimeApiClient
|
|
6
|
+
const api = new RuntimeApiClient()
|
|
7
|
+
expectType<Promise<unknown[]>>(api.getRuntimes())
|
|
8
|
+
expectType<Promise<void>>(api.close())
|
|
9
|
+
|
|
10
|
+
// errors
|
|
11
|
+
expectType<FastifyError>(errors.FailedToGetRuntimeAllLogs)
|
|
12
|
+
expectType<FastifyError>(errors.FailedToGetRuntimeConfig)
|
|
13
|
+
expectType<FastifyError>(errors.FailedToGetRuntimeEnv)
|
|
14
|
+
expectType<FastifyError>(errors.FailedToGetRuntimeHistoryLogs)
|
|
15
|
+
expectError<string>(errors.FailedToGetRuntimeHistoryLogs)
|
|
16
|
+
expectError<number>(errors.FailedToGetRuntimeHistoryLogs)
|
package/lib/errors.js
CHANGED
|
@@ -7,14 +7,11 @@ const ERROR_PREFIX = 'PLT_CTR'
|
|
|
7
7
|
module.exports = {
|
|
8
8
|
RuntimeNotFound: createError(`${ERROR_PREFIX}_RUNTIME_NOT_FOUND`, 'Runtime not found.'),
|
|
9
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
10
|
MissingRequestURL: createError(`${ERROR_PREFIX}_MISSING_REQUEST_URL`, 'Request URL is required.'),
|
|
12
11
|
FailedToGetRuntimeMetadata: createError(`${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_METADATA`, 'Failed to get runtime metadata %s.'),
|
|
13
12
|
FailedToGetRuntimeServices: createError(`${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_SERVICES`, 'Failed to get runtime services %s.'),
|
|
14
13
|
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
14
|
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
15
|
FailedToStopRuntime: createError(`${ERROR_PREFIX}_FAILED_TO_STOP_RUNTIME`, 'Failed to stop the runtime %s.'),
|
|
19
16
|
FailedToReloadRuntime: createError(`${ERROR_PREFIX}_FAILED_TO_RELOAD_RUNTIME`, 'Failed to reload the runtime %s.'),
|
|
20
17
|
FailedToGetRuntimeConfig: createError(`${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_CONFIG`, 'Failed to get runtime config %s.'),
|
package/lib/metrics.js
CHANGED
|
@@ -16,7 +16,7 @@ async function runtimeMetricsCommand (argv) {
|
|
|
16
16
|
|
|
17
17
|
const client = new RuntimeApiClient()
|
|
18
18
|
const runtimePid = args.pid || (await client.getMatchingRuntime([])).pid
|
|
19
|
-
const metrics = await client.getRuntimeMetrics(runtimePid, { format: args.format })
|
|
19
|
+
const metrics = await client.getRuntimeMetrics(parseInt(runtimePid), { format: args.format })
|
|
20
20
|
const result = args.format === 'text' ? metrics : JSON.stringify(metrics, null, 2)
|
|
21
21
|
console.log(result)
|
|
22
22
|
await client.close()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/control",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.30.0",
|
|
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/
|
|
29
|
-
"@platformatic/
|
|
28
|
+
"@platformatic/runtime": "2.30.0",
|
|
29
|
+
"@platformatic/service": "2.30.0"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@fastify/error": "^4.0.0",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"table": "^6.8.1",
|
|
38
38
|
"undici": "^7.0.0",
|
|
39
39
|
"ws": "^8.16.0",
|
|
40
|
-
"@platformatic/utils": "2.
|
|
40
|
+
"@platformatic/utils": "2.30.0"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
|
-
"test": "pnpm run lint && pnpm run unit",
|
|
43
|
+
"test": "pnpm run lint && pnpm run unit && tsd",
|
|
44
44
|
"unit": "borp --concurrency=1 --timeout=300000",
|
|
45
45
|
"lint": "eslint"
|
|
46
46
|
}
|