@platformatic/control 3.0.0-alpha.1 → 3.0.0-alpha.2

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 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
- '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
- MissingRequestURL: createError(`${ERROR_PREFIX}_MISSING_REQUEST_URL`, 'Request URL is required.'),
11
- FailedToGetRuntimeMetadata: createError(`${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_METADATA`, 'Failed to get runtime metadata %s.'),
12
- FailedToGetRuntimeServices: createError(`${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_SERVICES`, 'Failed to get runtime services %s.'),
13
- FailedToGetRuntimeEnv: createError(`${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_ENV`, 'Failed to get runtime environment variables %s.'),
14
- FailedToGetRuntimeOpenapi: createError(`${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_OPENAPI`, 'Failed to get runtime OpenAPI schema %s.'),
15
- FailedToStreamRuntimeLogs: createError(`${ERROR_PREFIX}_FAILED_TO_STREAM_RUNTIME_LOGS`, 'Failed to stream runtime logs %s.'),
16
- FailedToStopRuntime: createError(`${ERROR_PREFIX}_FAILED_TO_STOP_RUNTIME`, 'Failed to stop the runtime %s.'),
17
- FailedToReloadRuntime: createError(`${ERROR_PREFIX}_FAILED_TO_RELOAD_RUNTIME`, 'Failed to reload the runtime %s.'),
18
- FailedToGetRuntimeConfig: createError(`${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_CONFIG`, 'Failed to get runtime config %s.'),
19
- FailedToGetRuntimeServiceEnv: createError(`${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_SERVICE_ENV`, 'Failed to get runtime service environment variables %s.'),
20
- FailedToGetRuntimeServiceConfig: createError(`${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_SERVICE_CONFIG`, 'Failed to get runtime service config %s.'),
21
- FailedToGetRuntimeHistoryLogs: createError(`${ERROR_PREFIX}_FAILED_TO_GET_HISTORY_LOGS`, 'Failed to get history logs %s.'),
22
- FailedToGetRuntimeAllLogs: createError(`${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_ALL_LOGS`, 'Failed to get runtime all logs %s.'),
23
- FailedToGetRuntimeLogIndexes: createError(`${ERROR_PREFIX}_FAILED_TO_GET_HISTORY_LOGS_COUNT`, 'Failed to get history logs count %s.'),
24
- FailedToGetRuntimeMetrics: createError(`${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_METRICS`, 'Failed to get runtime metrics %s.'),
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
- 'use strict'
2
-
3
- const { tmpdir, platform, EOL } = require('node:os')
4
- const { join } = require('node:path')
5
- const { exec, spawn } = require('node:child_process')
6
- const { readdir, access } = require('node:fs/promises')
7
- const { Readable } = require('node:stream')
8
- const { Client } = require('undici')
9
- const WebSocket = require('ws')
10
- const errors = require('./errors.js')
11
- const { safeRemove } = require('@platformatic/utils')
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 RuntimeApiClient {
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 errors.RuntimeNotFound()
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 errors.FailedToGetRuntimeMetadata(error)
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 errors.FailedToGetRuntimeServices(error)
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 errors.FailedToGetRuntimeConfig(error)
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 (jsonError?.code === 'PLT_RUNTIME_SERVICE_NOT_FOUND' || jsonError?.code === 'PLT_RUNTIME_SERVICE_WORKER_NOT_FOUND') {
132
- throw new errors.ServiceNotFound(error)
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 errors.FailedToGetRuntimeServiceConfig(error)
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 errors.FailedToGetRuntimeEnv(error)
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 errors.FailedToGetRuntimeOpenapi(error)
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 (jsonError?.code === 'PLT_RUNTIME_SERVICE_NOT_FOUND' || jsonError?.code === 'PLT_RUNTIME_SERVICE_WORKER_NOT_FOUND') {
194
- throw new errors.ServiceNotFound(error)
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 errors.FailedToGetRuntimeServiceEnv(error)
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 errors.FailedToReloadRuntime(error)
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 errors.FailedToStopRuntime(error)
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 errors.FailedToGetRuntimeMetrics(error)
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, startLogIndex) {
363
+ getRuntimeLiveLogsStream (pid) {
291
364
  const socketPath = this.#getSocketPathFromPid(pid)
292
365
 
293
366
  const protocol = platform() === 'win32' ? 'ws+unix:' : 'ws+unix://'
294
- const query = startLogIndex ? `?start=${startLogIndex}` : ''
295
- const webSocketUrl = protocol + socketPath + ':/api/v1/logs/live' + query
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 errors.FailedToGetRuntimeHistoryLogs(error)
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 errors.FailedToGetRuntimeAllLogs(error)
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 errors.FailedToGetRuntimeLogIndexes(error)
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.1",
3
+ "version": "3.0.0-alpha.2",
4
4
  "description": "Platformatic Control",
5
- "main": "index.js",
6
- "bin": {
7
- "plt-ctl": "./control.js"
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.1",
28
- "@platformatic/service": "3.0.0-alpha.1"
26
+ "@platformatic/runtime": "3.0.0-alpha.2",
27
+ "@platformatic/service": "3.0.0-alpha.2"
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.0.0",
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/utils": "3.0.0-alpha.1"
37
+ "@platformatic/foundation": "3.0.0-alpha.2"
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
  }