@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
|
@@ -1,23 +1,98 @@
|
|
|
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
|
+
ApplicationNotFound,
|
|
11
|
+
FailedToGetRuntimeAllLogs,
|
|
12
|
+
FailedToGetRuntimeApplicationConfig,
|
|
13
|
+
FailedToGetRuntimeApplicationEnv,
|
|
14
|
+
FailedToGetRuntimeApplications,
|
|
15
|
+
FailedToGetRuntimeConfig,
|
|
16
|
+
FailedToGetRuntimeEnv,
|
|
17
|
+
FailedToGetRuntimeHistoryLogs,
|
|
18
|
+
FailedToGetRuntimeLogIndexes,
|
|
19
|
+
FailedToGetRuntimeMetadata,
|
|
20
|
+
FailedToGetRuntimeMetrics,
|
|
21
|
+
FailedToGetRuntimeOpenapi,
|
|
22
|
+
FailedToReloadRuntime,
|
|
23
|
+
FailedToStartProfiling,
|
|
24
|
+
FailedToStopProfiling,
|
|
25
|
+
FailedToStopRuntime,
|
|
26
|
+
FailedToStreamRuntimeLogs,
|
|
27
|
+
ProfilingAlreadyStarted,
|
|
28
|
+
ProfilingNotStarted,
|
|
29
|
+
RuntimeNotFound
|
|
30
|
+
} from './errors.js'
|
|
12
31
|
|
|
13
32
|
const PLATFORMATIC_TMP_DIR = join(tmpdir(), 'platformatic', 'runtimes')
|
|
14
33
|
const PLATFORMATIC_PIPE_PREFIX = '\\\\.\\pipe\\platformatic-'
|
|
15
34
|
|
|
16
|
-
class
|
|
35
|
+
class WebSocketStream extends Readable {
|
|
36
|
+
constructor (url) {
|
|
37
|
+
super()
|
|
38
|
+
this.ws = new WebSocket(url)
|
|
39
|
+
|
|
40
|
+
this.ws.on('message', data => {
|
|
41
|
+
this.push(data)
|
|
42
|
+
})
|
|
43
|
+
this.ws.on('close', () => {
|
|
44
|
+
this.push(null)
|
|
45
|
+
})
|
|
46
|
+
this.ws.on('error', err => {
|
|
47
|
+
this.emit('error', new FailedToStreamRuntimeLogs(err.message))
|
|
48
|
+
})
|
|
49
|
+
this.on('close', () => {
|
|
50
|
+
this.ws.close()
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
_read () {}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export * from './errors.js'
|
|
58
|
+
|
|
59
|
+
export async function getMatchingRuntime (client, positionals) {
|
|
60
|
+
const runtimes = await client.getRuntimes()
|
|
61
|
+
const pidOrName = positionals[0]
|
|
62
|
+
let runtime
|
|
63
|
+
|
|
64
|
+
// We have an argument to match
|
|
65
|
+
if (pidOrName) {
|
|
66
|
+
if (pidOrName.match(/^\d+$/)) {
|
|
67
|
+
const pid = parseInt(pidOrName)
|
|
68
|
+
runtime = runtimes.find(runtime => runtime.pid === pid)
|
|
69
|
+
} else {
|
|
70
|
+
runtime = runtimes.find(runtime => runtime.packageName === pidOrName)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (runtime) {
|
|
74
|
+
return [runtime, positionals.slice(1)]
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// We found no match, find any runtime whose running directory is the current one
|
|
79
|
+
if (!runtime) {
|
|
80
|
+
runtime = runtimes.find(runtime => runtime.cwd === process.cwd())
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (!runtime) {
|
|
84
|
+
throw RuntimeNotFound()
|
|
85
|
+
}
|
|
86
|
+
/* c8 ignore next 2 */
|
|
87
|
+
|
|
88
|
+
return [runtime, positionals]
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export class RuntimeApiClient {
|
|
17
92
|
#undiciClients = new Map()
|
|
18
93
|
#webSockets = new Set()
|
|
19
94
|
|
|
20
|
-
async getMatchingRuntime (opts) {
|
|
95
|
+
async getMatchingRuntime (opts = {}) {
|
|
21
96
|
const runtimes = await this.getRuntimes()
|
|
22
97
|
|
|
23
98
|
let runtime = null
|
|
@@ -29,7 +104,7 @@ class RuntimeApiClient {
|
|
|
29
104
|
runtime = runtimes[0]
|
|
30
105
|
}
|
|
31
106
|
if (!runtime) {
|
|
32
|
-
throw
|
|
107
|
+
throw new RuntimeNotFound()
|
|
33
108
|
}
|
|
34
109
|
return runtime
|
|
35
110
|
}
|
|
@@ -62,33 +137,34 @@ class RuntimeApiClient {
|
|
|
62
137
|
|
|
63
138
|
const { statusCode, body } = await client.request({
|
|
64
139
|
path: '/api/v1/metadata',
|
|
65
|
-
method: 'GET'
|
|
140
|
+
method: 'GET',
|
|
141
|
+
headersTimeout: 10 * 1000
|
|
66
142
|
})
|
|
67
143
|
|
|
68
144
|
if (statusCode !== 200) {
|
|
69
145
|
const error = await body.text()
|
|
70
|
-
throw new
|
|
146
|
+
throw new FailedToGetRuntimeMetadata(error)
|
|
71
147
|
}
|
|
72
148
|
|
|
73
149
|
const metadata = await body.json()
|
|
74
150
|
return metadata
|
|
75
151
|
}
|
|
76
152
|
|
|
77
|
-
async
|
|
153
|
+
async getRuntimeApplications (pid) {
|
|
78
154
|
const client = this.#getUndiciClient(pid)
|
|
79
155
|
|
|
80
156
|
const { statusCode, body } = await client.request({
|
|
81
|
-
path: '/api/v1/
|
|
157
|
+
path: '/api/v1/applications',
|
|
82
158
|
method: 'GET'
|
|
83
159
|
})
|
|
84
160
|
|
|
85
161
|
if (statusCode !== 200) {
|
|
86
162
|
const error = await body.text()
|
|
87
|
-
throw new
|
|
163
|
+
throw new FailedToGetRuntimeApplications(error)
|
|
88
164
|
}
|
|
89
165
|
|
|
90
|
-
const
|
|
91
|
-
return
|
|
166
|
+
const runtimeApplications = await body.json()
|
|
167
|
+
return runtimeApplications
|
|
92
168
|
}
|
|
93
169
|
|
|
94
170
|
async getRuntimeConfig (pid) {
|
|
@@ -101,18 +177,18 @@ class RuntimeApiClient {
|
|
|
101
177
|
|
|
102
178
|
if (statusCode !== 200) {
|
|
103
179
|
const error = await body.text()
|
|
104
|
-
throw new
|
|
180
|
+
throw new FailedToGetRuntimeConfig(error)
|
|
105
181
|
}
|
|
106
182
|
|
|
107
183
|
const runtimeConfig = await body.json()
|
|
108
184
|
return runtimeConfig
|
|
109
185
|
}
|
|
110
186
|
|
|
111
|
-
async
|
|
187
|
+
async getRuntimeApplicationConfig (pid, applicationId) {
|
|
112
188
|
const client = this.#getUndiciClient(pid)
|
|
113
189
|
|
|
114
190
|
const { statusCode, body } = await client.request({
|
|
115
|
-
path: `/api/v1/
|
|
191
|
+
path: `/api/v1/applications/${applicationId}/config`,
|
|
116
192
|
method: 'GET'
|
|
117
193
|
})
|
|
118
194
|
|
|
@@ -125,15 +201,18 @@ class RuntimeApiClient {
|
|
|
125
201
|
// No-op
|
|
126
202
|
}
|
|
127
203
|
|
|
128
|
-
if (
|
|
129
|
-
|
|
204
|
+
if (
|
|
205
|
+
jsonError?.code === 'PLT_RUNTIME_APPLICATION_NOT_FOUND' ||
|
|
206
|
+
jsonError?.code === 'PLT_RUNTIME_APPLICATION_WORKER_NOT_FOUND'
|
|
207
|
+
) {
|
|
208
|
+
throw new ApplicationNotFound(error)
|
|
130
209
|
}
|
|
131
210
|
|
|
132
|
-
throw new
|
|
211
|
+
throw new FailedToGetRuntimeApplicationConfig(error)
|
|
133
212
|
}
|
|
134
213
|
|
|
135
|
-
const
|
|
136
|
-
return
|
|
214
|
+
const applicationConfig = await body.json()
|
|
215
|
+
return applicationConfig
|
|
137
216
|
}
|
|
138
217
|
|
|
139
218
|
async getRuntimeEnv (pid) {
|
|
@@ -146,21 +225,107 @@ class RuntimeApiClient {
|
|
|
146
225
|
|
|
147
226
|
if (statusCode !== 200) {
|
|
148
227
|
const error = await body.text()
|
|
149
|
-
throw new
|
|
228
|
+
throw new FailedToGetRuntimeEnv(error)
|
|
150
229
|
}
|
|
151
230
|
|
|
152
231
|
const runtimeEnv = await body.json()
|
|
153
232
|
return runtimeEnv
|
|
154
233
|
}
|
|
155
234
|
|
|
156
|
-
async
|
|
235
|
+
async getRuntimeOpenapi (pid, applicationId) {
|
|
157
236
|
const client = this.#getUndiciClient(pid)
|
|
158
237
|
|
|
159
238
|
const { statusCode, body } = await client.request({
|
|
160
|
-
path: `/api/v1/
|
|
239
|
+
path: `/api/v1/applications/${applicationId}/openapi-schema`,
|
|
161
240
|
method: 'GET'
|
|
162
241
|
})
|
|
163
242
|
|
|
243
|
+
if (statusCode !== 200) {
|
|
244
|
+
const error = await body.text()
|
|
245
|
+
throw new FailedToGetRuntimeOpenapi(error)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const openapi = await body.json()
|
|
249
|
+
return openapi
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
async getRuntimeApplicationEnv (pid, applicationId) {
|
|
253
|
+
const client = this.#getUndiciClient(pid)
|
|
254
|
+
|
|
255
|
+
const { statusCode, body } = await client.request({
|
|
256
|
+
path: `/api/v1/applications/${applicationId}/env`,
|
|
257
|
+
method: 'GET'
|
|
258
|
+
})
|
|
259
|
+
|
|
260
|
+
if (statusCode !== 200) {
|
|
261
|
+
const error = await body.text()
|
|
262
|
+
let jsonError
|
|
263
|
+
try {
|
|
264
|
+
jsonError = JSON.parse(error)
|
|
265
|
+
} catch {
|
|
266
|
+
// No-op
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (
|
|
270
|
+
jsonError?.code === 'PLT_RUNTIME_APPLICATION_NOT_FOUND' ||
|
|
271
|
+
jsonError?.code === 'PLT_RUNTIME_APPLICATION_WORKER_NOT_FOUND'
|
|
272
|
+
) {
|
|
273
|
+
throw new ApplicationNotFound(error)
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
throw new FailedToGetRuntimeApplicationEnv(error)
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const applicationConfig = await body.json()
|
|
280
|
+
return applicationConfig
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
async startApplicationProfiling (pid, applicationId, options = {}) {
|
|
284
|
+
const client = this.#getUndiciClient(pid)
|
|
285
|
+
|
|
286
|
+
const { statusCode, body } = await client.request({
|
|
287
|
+
path: `/api/v1/applications/${applicationId}/pprof/start`,
|
|
288
|
+
method: 'POST',
|
|
289
|
+
headers: {
|
|
290
|
+
'content-type': 'application/json'
|
|
291
|
+
},
|
|
292
|
+
body: JSON.stringify(options)
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
if (statusCode !== 200) {
|
|
296
|
+
const error = await body.text()
|
|
297
|
+
let jsonError
|
|
298
|
+
try {
|
|
299
|
+
jsonError = JSON.parse(error)
|
|
300
|
+
} catch {
|
|
301
|
+
// No-op
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const message = jsonError?.message || error
|
|
305
|
+
const code = jsonError?.code
|
|
306
|
+
|
|
307
|
+
if (code === 'PLT_RUNTIME_APPLICATION_NOT_FOUND' || code === 'PLT_RUNTIME_APPLICATION_WORKER_NOT_FOUND') {
|
|
308
|
+
throw new ApplicationNotFound(message)
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (code === 'PLT_PPROF_PROFILING_ALREADY_STARTED') {
|
|
312
|
+
throw new ProfilingAlreadyStarted(applicationId)
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
throw new FailedToStartProfiling(applicationId, message)
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return await body.json()
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
async stopApplicationProfiling (pid, applicationId) {
|
|
322
|
+
const client = this.#getUndiciClient(pid)
|
|
323
|
+
|
|
324
|
+
const { statusCode, body } = await client.request({
|
|
325
|
+
path: `/api/v1/applications/${applicationId}/pprof/stop`,
|
|
326
|
+
method: 'POST'
|
|
327
|
+
})
|
|
328
|
+
|
|
164
329
|
if (statusCode !== 200) {
|
|
165
330
|
const error = await body.text()
|
|
166
331
|
let jsonError
|
|
@@ -170,15 +335,22 @@ class RuntimeApiClient {
|
|
|
170
335
|
// No-op
|
|
171
336
|
}
|
|
172
337
|
|
|
173
|
-
|
|
174
|
-
|
|
338
|
+
const message = jsonError?.message || error
|
|
339
|
+
const code = jsonError?.code
|
|
340
|
+
|
|
341
|
+
if (code === 'PLT_RUNTIME_APPLICATION_NOT_FOUND' || code === 'PLT_RUNTIME_APPLICATION_WORKER_NOT_FOUND') {
|
|
342
|
+
throw new ApplicationNotFound(message)
|
|
175
343
|
}
|
|
176
344
|
|
|
177
|
-
|
|
345
|
+
if (code === 'PLT_PPROF_PROFILING_NOT_STARTED') {
|
|
346
|
+
throw new ProfilingNotStarted(applicationId)
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
throw new FailedToStopProfiling(applicationId, message)
|
|
178
350
|
}
|
|
179
351
|
|
|
180
|
-
|
|
181
|
-
return
|
|
352
|
+
// Return the binary profile data as ArrayBuffer
|
|
353
|
+
return await body.arrayBuffer()
|
|
182
354
|
}
|
|
183
355
|
|
|
184
356
|
async reloadRuntime (pid, options = {}) {
|
|
@@ -208,7 +380,7 @@ class RuntimeApiClient {
|
|
|
208
380
|
|
|
209
381
|
if (statusCode !== 200) {
|
|
210
382
|
const error = await body.text()
|
|
211
|
-
throw new
|
|
383
|
+
throw new FailedToReloadRuntime(error)
|
|
212
384
|
}
|
|
213
385
|
}
|
|
214
386
|
|
|
@@ -222,10 +394,38 @@ class RuntimeApiClient {
|
|
|
222
394
|
|
|
223
395
|
if (statusCode !== 200) {
|
|
224
396
|
const error = await body.text()
|
|
225
|
-
throw new
|
|
397
|
+
throw new FailedToStopRuntime(error)
|
|
226
398
|
}
|
|
227
399
|
}
|
|
228
400
|
|
|
401
|
+
async getRuntimeMetrics (pid, options = {}) {
|
|
402
|
+
const client = this.#getUndiciClient(pid)
|
|
403
|
+
|
|
404
|
+
const format = options.format ?? 'text'
|
|
405
|
+
const headers = {}
|
|
406
|
+
if (format === 'json') {
|
|
407
|
+
headers['accept'] = 'application/json'
|
|
408
|
+
}
|
|
409
|
+
if (format === 'text') {
|
|
410
|
+
headers['accept'] = 'text/plain'
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
const { statusCode, body } = await client.request({
|
|
414
|
+
path: '/api/v1/metrics',
|
|
415
|
+
method: 'GET',
|
|
416
|
+
headers
|
|
417
|
+
})
|
|
418
|
+
|
|
419
|
+
if (statusCode !== 200) {
|
|
420
|
+
const error = await body.text()
|
|
421
|
+
throw new FailedToGetRuntimeMetrics(error)
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const metrics = format === 'json' ? await body.json() : await body.text()
|
|
425
|
+
|
|
426
|
+
return metrics
|
|
427
|
+
}
|
|
428
|
+
|
|
229
429
|
getRuntimeLiveMetricsStream (pid) {
|
|
230
430
|
const socketPath = this.#getSocketPathFromPid(pid)
|
|
231
431
|
|
|
@@ -237,12 +437,12 @@ class RuntimeApiClient {
|
|
|
237
437
|
return webSocketStream
|
|
238
438
|
}
|
|
239
439
|
|
|
240
|
-
getRuntimeLiveLogsStream (pid
|
|
440
|
+
getRuntimeLiveLogsStream (pid) {
|
|
241
441
|
const socketPath = this.#getSocketPathFromPid(pid)
|
|
242
442
|
|
|
243
443
|
const protocol = platform() === 'win32' ? 'ws+unix:' : 'ws+unix://'
|
|
244
|
-
|
|
245
|
-
const webSocketUrl = protocol + socketPath + ':/api/v1/logs/live'
|
|
444
|
+
|
|
445
|
+
const webSocketUrl = protocol + socketPath + ':/api/v1/logs/live'
|
|
246
446
|
const webSocketStream = new WebSocketStream(webSocketUrl)
|
|
247
447
|
this.#webSockets.add(webSocketStream.ws)
|
|
248
448
|
|
|
@@ -261,7 +461,7 @@ class RuntimeApiClient {
|
|
|
261
461
|
|
|
262
462
|
if (statusCode !== 200) {
|
|
263
463
|
const error = await body.text()
|
|
264
|
-
throw new
|
|
464
|
+
throw new FailedToGetRuntimeHistoryLogs(error)
|
|
265
465
|
}
|
|
266
466
|
|
|
267
467
|
return body
|
|
@@ -279,7 +479,7 @@ class RuntimeApiClient {
|
|
|
279
479
|
|
|
280
480
|
if (statusCode !== 200) {
|
|
281
481
|
const error = await body.text()
|
|
282
|
-
throw new
|
|
482
|
+
throw new FailedToGetRuntimeAllLogs(error)
|
|
283
483
|
}
|
|
284
484
|
|
|
285
485
|
return body
|
|
@@ -297,7 +497,7 @@ class RuntimeApiClient {
|
|
|
297
497
|
|
|
298
498
|
if (statusCode !== 200) {
|
|
299
499
|
const error = await body.text()
|
|
300
|
-
throw new
|
|
500
|
+
throw new FailedToGetRuntimeLogIndexes(error)
|
|
301
501
|
}
|
|
302
502
|
|
|
303
503
|
const result = await body.json()
|
|
@@ -306,11 +506,11 @@ class RuntimeApiClient {
|
|
|
306
506
|
return result.indexes
|
|
307
507
|
}
|
|
308
508
|
|
|
309
|
-
async injectRuntime (pid,
|
|
509
|
+
async injectRuntime (pid, applicationId, options) {
|
|
310
510
|
const client = this.#getUndiciClient(pid)
|
|
311
511
|
|
|
312
512
|
const response = await client.request({
|
|
313
|
-
path: `/api/v1/
|
|
513
|
+
path: `/api/v1/applications/${applicationId}/proxy` + options.url,
|
|
314
514
|
method: options.method,
|
|
315
515
|
headers: options.headers,
|
|
316
516
|
query: options.query,
|
|
@@ -401,27 +601,3 @@ class RuntimeApiClient {
|
|
|
401
601
|
await safeRemove(runtimeDir)
|
|
402
602
|
}
|
|
403
603
|
}
|
|
404
|
-
|
|
405
|
-
class WebSocketStream extends Readable {
|
|
406
|
-
constructor (url) {
|
|
407
|
-
super()
|
|
408
|
-
this.ws = new WebSocket(url)
|
|
409
|
-
|
|
410
|
-
this.ws.on('message', data => {
|
|
411
|
-
this.push(data)
|
|
412
|
-
})
|
|
413
|
-
this.ws.on('close', () => {
|
|
414
|
-
this.push(null)
|
|
415
|
-
})
|
|
416
|
-
this.ws.on('error', err => {
|
|
417
|
-
this.emit('error', new errors.FailedToStreamRuntimeLogs(err.message))
|
|
418
|
-
})
|
|
419
|
-
this.on('close', () => {
|
|
420
|
-
this.ws.close()
|
|
421
|
-
})
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
_read () {}
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
module.exports = RuntimeApiClient
|
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/control",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "Platformatic Control",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"author": "Matteo Collina <hello@matteocollina.com>",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"author": "Platformatic Inc. <oss@platformatic.dev> (https://platformatic.dev)",
|
|
10
9
|
"repository": {
|
|
11
10
|
"type": "git",
|
|
12
11
|
"url": "git+https://github.com/platformatic/platformatic.git"
|
|
@@ -17,31 +16,32 @@
|
|
|
17
16
|
},
|
|
18
17
|
"homepage": "https://github.com/platformatic/platformatic#readme",
|
|
19
18
|
"devDependencies": {
|
|
20
|
-
"
|
|
21
|
-
"desm": "^1.3.1",
|
|
19
|
+
"cleaner-spec-reporter": "^0.5.0",
|
|
22
20
|
"eslint": "9",
|
|
23
|
-
"execa": "^
|
|
24
|
-
"neostandard": "^0.
|
|
21
|
+
"execa": "^9.0.0",
|
|
22
|
+
"neostandard": "^0.12.0",
|
|
25
23
|
"split2": "^4.2.0",
|
|
26
|
-
"tsd": "^0.
|
|
24
|
+
"tsd": "^0.33.0",
|
|
27
25
|
"typescript": "^5.5.4",
|
|
28
|
-
"@platformatic/runtime": "3.
|
|
29
|
-
"@platformatic/service": "3.
|
|
26
|
+
"@platformatic/runtime": "3.5.0",
|
|
27
|
+
"@platformatic/service": "3.5.0"
|
|
30
28
|
},
|
|
31
29
|
"dependencies": {
|
|
32
30
|
"@fastify/error": "^4.0.0",
|
|
33
|
-
"commist": "^3.2.0",
|
|
34
31
|
"help-me": "^5.0.0",
|
|
35
|
-
"pino": "^9.
|
|
36
|
-
"pino-pretty": "^
|
|
32
|
+
"pino": "^9.9.0",
|
|
33
|
+
"pino-pretty": "^13.0.0",
|
|
37
34
|
"table": "^6.8.1",
|
|
38
|
-
"undici": "^
|
|
35
|
+
"undici": "^7.0.0",
|
|
39
36
|
"ws": "^8.16.0",
|
|
40
|
-
"@platformatic/
|
|
37
|
+
"@platformatic/foundation": "3.5.0"
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=22.19.0"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
|
-
"test": "
|
|
44
|
-
"
|
|
43
|
+
"test": "node --test --test-reporter=cleaner-spec-reporter --test-concurrency=1 --test-timeout=2000000 test/*.test.js test/**/*.test.js",
|
|
44
|
+
"posttest": "tsd --files test/index.test-d.ts",
|
|
45
45
|
"lint": "eslint"
|
|
46
46
|
}
|
|
47
47
|
}
|
package/control.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const { join } = require('node:path')
|
|
4
|
-
const { parseArgs } = require('node:util')
|
|
5
|
-
const commist = require('commist')
|
|
6
|
-
const helpMe = require('help-me')
|
|
7
|
-
|
|
8
|
-
const getRuntimesCommand = require('./lib/ps')
|
|
9
|
-
const getRuntimesEnvCommand = require('./lib/env')
|
|
10
|
-
const getRuntimeServicesCommand = require('./lib/services')
|
|
11
|
-
const getRuntimeConfigCommand = require('./lib/config')
|
|
12
|
-
const stopRuntimeCommand = require('./lib/stop')
|
|
13
|
-
const reloadRuntimeCommand = require('./lib/reload')
|
|
14
|
-
const restartRuntimeCommand = require('./lib/restart')
|
|
15
|
-
const injectRuntimeCommand = require('./lib/inject')
|
|
16
|
-
const streamRuntimeLogsCommand = require('./lib/logs')
|
|
17
|
-
|
|
18
|
-
const help = helpMe({
|
|
19
|
-
dir: join(__dirname, 'help'),
|
|
20
|
-
ext: '.txt',
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
const program = commist({ maxDistance: 2 })
|
|
24
|
-
|
|
25
|
-
program.register('ps', wrapCommand(getRuntimesCommand))
|
|
26
|
-
program.register('stop', wrapCommand(stopRuntimeCommand))
|
|
27
|
-
program.register('reload', wrapCommand(reloadRuntimeCommand))
|
|
28
|
-
program.register('restart', wrapCommand(restartRuntimeCommand))
|
|
29
|
-
program.register('logs', wrapCommand(streamRuntimeLogsCommand))
|
|
30
|
-
program.register('env', wrapCommand(getRuntimesEnvCommand))
|
|
31
|
-
program.register('services', wrapCommand(getRuntimeServicesCommand))
|
|
32
|
-
program.register('config', wrapCommand(getRuntimeConfigCommand))
|
|
33
|
-
program.register('inject', wrapCommand(injectRuntimeCommand))
|
|
34
|
-
program.register('help', help.toStdout)
|
|
35
|
-
|
|
36
|
-
async function runControl (argv) {
|
|
37
|
-
if (argv.length === 0) {
|
|
38
|
-
help.toStdout()
|
|
39
|
-
return {}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const args = parseArgs({
|
|
43
|
-
args: argv,
|
|
44
|
-
options: {
|
|
45
|
-
version: { type: 'boolean', short: 'v' },
|
|
46
|
-
},
|
|
47
|
-
strict: false,
|
|
48
|
-
}).values
|
|
49
|
-
|
|
50
|
-
if (args.version && argv[0] !== 'inject') {
|
|
51
|
-
const packageJson = require(join(__dirname, 'package.json'))
|
|
52
|
-
console.log(packageJson.version)
|
|
53
|
-
process.exit(0)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const output = await program.parseAsync(argv)
|
|
57
|
-
return { output }
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (require.main === module) {
|
|
61
|
-
runControl(process.argv.slice(2))
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function wrapCommand (fn) {
|
|
65
|
-
return async function (...args) {
|
|
66
|
-
try {
|
|
67
|
-
return await fn(...args)
|
|
68
|
-
} catch (err) {
|
|
69
|
-
console.log(err.message)
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
module.exports = {
|
|
75
|
-
runControl,
|
|
76
|
-
getRuntimesCommand,
|
|
77
|
-
getRuntimesEnvCommand,
|
|
78
|
-
getRuntimeServicesCommand,
|
|
79
|
-
stopRuntimeCommand,
|
|
80
|
-
restartRuntimeCommand,
|
|
81
|
-
injectRuntimeCommand,
|
|
82
|
-
streamRuntimeLogsCommand,
|
|
83
|
-
}
|
package/help/config.txt
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
Prints runtime or runtime service config file
|
|
2
|
-
|
|
3
|
-
``` bash
|
|
4
|
-
$ platformatic ctl config -n runtime-name
|
|
5
|
-
```
|
|
6
|
-
|
|
7
|
-
Options:
|
|
8
|
-
|
|
9
|
-
* `-p, --pid <number>` - The process id of the runtime.
|
|
10
|
-
* `-n, --name <string>` - The name of the runtime.
|
|
11
|
-
|
|
12
|
-
The `config` command uses the Platformatic Runtime Management API. To enable it
|
|
13
|
-
set the `managementApi` option to `true` in the runtime configuration file.
|
|
14
|
-
|
|
15
|
-
To get the list of runtimes with enabled management API use the
|
|
16
|
-
`platformatic ctl ps` command.
|
package/help/env.txt
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
Lists platformatic runtime application environment variables
|
|
2
|
-
|
|
3
|
-
``` bash
|
|
4
|
-
$ platformatic ctl env -n runtime-name
|
|
5
|
-
```
|
|
6
|
-
|
|
7
|
-
Options:
|
|
8
|
-
|
|
9
|
-
* `-p, --pid <number>` - The process id of the runtime.
|
|
10
|
-
* `-n, --name <string>` - The name of the runtime.
|
|
11
|
-
|
|
12
|
-
The `env` command uses the Platformatic Runtime Management API. To enable it
|
|
13
|
-
set the `managementApi` option to `true` in the runtime configuration file.
|
|
14
|
-
|
|
15
|
-
To get the list of runtimes with enabled management API use the
|
|
16
|
-
`platformatic ctl ps` command.
|
package/help/help.txt
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
Available commands:
|
|
2
|
-
|
|
3
|
-
* `ps` - lists all platformatic runtime applications.
|
|
4
|
-
* `stop` - stops a platformatic runtime application.
|
|
5
|
-
* `restart` - restarts all platformatic runtime services.
|
|
6
|
-
* `reload` - reloads all platformatic runtime services.
|
|
7
|
-
* `services` - lists the runtime services.
|
|
8
|
-
* `config` - prints runtime or runtime service config file.
|
|
9
|
-
* `env` - lists the runtime environment variables.
|
|
10
|
-
* `logs` - shows the runtime logs.
|
|
11
|
-
* `inject` - injects a request to the runtime service.
|